32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/errno.h>
35 #include <linux/slab.h>
37 #include <linux/string.h>
41 #include <asm/oplib.h>
43 #include <asm/uaccess.h>
46 #include <linux/pci.h>
80 if (
get_user(bufsize, &info->oprom_size))
92 if (!(*opp_p = kzalloc(
sizeof(
int) + bufsize + 1,
GFP_KERNEL)))
96 &info->oprom_array, bufsize)) {
114 (*opp_p)->oprom_size = 0;
118 if (
get_user(c, &info->oprom_array[bufsize])) {
124 (*opp_p)->oprom_array[bufsize++] =
c;
136 static int copyout(
void __user *info,
struct openpromio *
opp,
int len)
150 len <= 0 || len > bufsize)
151 return copyout(argp, op,
sizeof(
int));
157 return copyout(argp, op,
sizeof(
int) + bufsize);
160 static int opromnxtprop(
void __user *argp,
struct device_node *dp,
struct openpromio *op,
int bufsize)
166 return copyout(argp, op,
sizeof(
int));
170 return copyout(argp, op,
sizeof(
int));
177 (len =
strlen(prop->
next->name)) + 1 > bufsize)
178 return copyout(argp, op,
sizeof(
int));
187 return copyout(argp, op,
sizeof(
int) + bufsize);
242 return copyout(argp, op, bufsize +
sizeof(
int));
249 if (bufsize >= 2*
sizeof(
int)) {
257 dp = pci_device_to_OF_node(pdev);
261 err = copyout(argp, op, bufsize +
sizeof(
int));
281 return copyout(argp, op, bufsize +
sizeof(
int));
284 static int opromgetbootargs(
void __user *argp,
struct openpromio *op,
int bufsize)
295 return copyout(argp, op, bufsize +
sizeof(
int));
301 static long openprom_sunos_ioctl(
struct file *
file,
302 unsigned int cmd,
unsigned long arg,
312 bufsize = getstrings(argp, &opp);
314 bufsize = copyin(argp, &opp);
324 error = opromgetprop(argp, dp, opp, bufsize);
329 error = opromnxtprop(argp, dp, opp, bufsize);
334 error = opromsetopt(dp, opp, bufsize);
340 error = opromnext(argp, cmd, dp, opp, bufsize, data);
344 error = oprompci2node(argp, dp, opp, bufsize, data);
348 error = oprompath2node(argp, dp, opp, bufsize, data);
352 error = opromgetbootargs(argp, opp, bufsize);
364 printk(
KERN_INFO "openprom_sunos_ioctl: cmd 0x%X, arg 0x%lX\n", cmd, arg);
386 static int copyin_string(
char __user *
user,
size_t len,
char **
ptr)
412 static int opiocget(
void __user *argp,
DATA *data)
423 dp = get_node(op.op_nodeid, data);
425 err = copyin_string(op.op_name, op.op_namelen, &str);
431 if (!pval || len > op.op_buflen) {
444 static int opiocnextprop(
void __user *argp,
DATA *data)
455 dp = get_node(op.op_nodeid, data);
459 err = copyin_string(op.op_name, op.op_namelen, &str);
463 if (str[0] ==
'\0') {
477 if (len > op.op_buflen)
490 static int opiocset(
void __user *argp,
DATA *data)
500 dp = get_node(op.op_nodeid, data);
504 err = copyin_string(op.op_name, op.op_namelen, &str);
508 err = copyin_string(op.op_buf, op.op_buflen, &tmp);
522 static int opiocgetnext(
unsigned int cmd,
void __user *argp)
554 static int openprom_bsd_ioctl(
struct file * file,
555 unsigned int cmd,
unsigned long arg)
564 err = opiocget(argp, data);
568 err = opiocnextprop(argp, data);
572 err = opiocset(argp, data);
585 err = opiocgetnext(cmd, argp);
601 static long openprom_ioctl(
struct file * file,
602 unsigned int cmd,
unsigned long arg)
611 return openprom_sunos_ioctl(file, cmd, arg,
618 return openprom_sunos_ioctl(file, cmd, arg,
627 return openprom_sunos_ioctl(file, cmd, arg,
639 return openprom_sunos_ioctl(file, cmd, arg,
NULL);
648 return openprom_bsd_ioctl(file,cmd,arg);
653 return openprom_bsd_ioctl(file,cmd,arg);
660 static long openprom_compat_ioctl(
struct file *file,
unsigned int cmd,
685 rval = openprom_ioctl(file, cmd, arg);
692 static int openprom_open(
struct inode *
inode,
struct file * file)
709 static int openprom_release(
struct inode * inode,
struct file * file)
718 .unlocked_ioctl = openprom_ioctl,
719 .compat_ioctl = openprom_compat_ioctl,
720 .open = openprom_open,
721 .release = openprom_release,
727 .fops = &openprom_fops,
730 static int __init openprom_init(
void)
756 static void __exit openprom_cleanup(
void)