[SPARC64]: constify of_get_property return: arch/sparc64
[deliverable/linux.git] / drivers / sbus / char / openprom.c
CommitLineData
1da177e4
LT
1/*
2 * Linux/SPARC PROM Configuration Driver
3 * Copyright (C) 1996 Thomas K. Dyas (tdyas@noc.rutgers.edu)
4 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
5 *
6 * This character device driver allows user programs to access the
7 * PROM device tree. It is compatible with the SunOS /dev/openprom
8 * driver and the NetBSD /dev/openprom driver. The SunOS eeprom
9 * utility works without any modifications.
10 *
11 * The driver uses a minor number under the misc device major. The
12 * file read/write mode determines the type of access to the PROM.
13 * Interrupts are disabled whenever the driver calls into the PROM for
14 * sanity's sake.
15 */
16
17/* This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of the
20 * License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
1da177e4
LT
32#include <linux/module.h>
33#include <linux/kernel.h>
1da177e4
LT
34#include <linux/errno.h>
35#include <linux/slab.h>
36#include <linux/string.h>
37#include <linux/miscdevice.h>
38#include <linux/init.h>
39#include <linux/fs.h>
40#include <asm/oplib.h>
8e48aec7 41#include <asm/prom.h>
1da177e4
LT
42#include <asm/system.h>
43#include <asm/uaccess.h>
44#include <asm/openpromio.h>
45#ifdef CONFIG_PCI
46#include <linux/pci.h>
47#include <asm/pbm.h>
48#endif
49
8e48aec7
DM
50MODULE_AUTHOR("Thomas K. Dyas (tdyas@noc.rutgers.edu) and Eddie C. Dost (ecd@skynet.be)");
51MODULE_DESCRIPTION("OPENPROM Configuration Driver");
52MODULE_LICENSE("GPL");
53MODULE_VERSION("1.0");
54
1da177e4
LT
55/* Private data kept by the driver for each descriptor. */
56typedef struct openprom_private_data
57{
8e48aec7
DM
58 struct device_node *current_node; /* Current node for SunOS ioctls. */
59 struct device_node *lastnode; /* Last valid node used by BSD ioctls. */
1da177e4
LT
60} DATA;
61
62/* ID of the PROM node containing all of the EEPROM options. */
8e48aec7 63static struct device_node *options_node;
1da177e4
LT
64
65/*
66 * Copy an openpromio structure into kernel space from user space.
67 * This routine does error checking to make sure that all memory
68 * accesses are within bounds. A pointer to the allocated openpromio
69 * structure will be placed in "*opp_p". Return value is the length
70 * of the user supplied buffer.
71 */
72static int copyin(struct openpromio __user *info, struct openpromio **opp_p)
73{
74 unsigned int bufsize;
75
76 if (!info || !opp_p)
77 return -EFAULT;
78
79 if (get_user(bufsize, &info->oprom_size))
80 return -EFAULT;
81
82 if (bufsize == 0)
83 return -EINVAL;
84
85 /* If the bufsize is too large, just limit it.
86 * Fix from Jason Rappleye.
87 */
88 if (bufsize > OPROMMAXPARAM)
89 bufsize = OPROMMAXPARAM;
90
8e48aec7 91 if (!(*opp_p = kzalloc(sizeof(int) + bufsize + 1, GFP_KERNEL)))
1da177e4 92 return -ENOMEM;
1da177e4
LT
93
94 if (copy_from_user(&(*opp_p)->oprom_array,
95 &info->oprom_array, bufsize)) {
96 kfree(*opp_p);
97 return -EFAULT;
98 }
99 return bufsize;
100}
101
102static int getstrings(struct openpromio __user *info, struct openpromio **opp_p)
103{
104 int n, bufsize;
105 char c;
106
107 if (!info || !opp_p)
108 return -EFAULT;
109
8e48aec7 110 if (!(*opp_p = kzalloc(sizeof(int) + OPROMMAXPARAM + 1, GFP_KERNEL)))
1da177e4
LT
111 return -ENOMEM;
112
1da177e4
LT
113 (*opp_p)->oprom_size = 0;
114
115 n = bufsize = 0;
116 while ((n < 2) && (bufsize < OPROMMAXPARAM)) {
117 if (get_user(c, &info->oprom_array[bufsize])) {
118 kfree(*opp_p);
119 return -EFAULT;
120 }
121 if (c == '\0')
122 n++;
123 (*opp_p)->oprom_array[bufsize++] = c;
124 }
125 if (!n) {
126 kfree(*opp_p);
127 return -EINVAL;
128 }
129 return bufsize;
130}
131
132/*
133 * Copy an openpromio structure in kernel space back to user space.
134 */
135static int copyout(void __user *info, struct openpromio *opp, int len)
136{
137 if (copy_to_user(info, opp, len))
138 return -EFAULT;
139 return 0;
140}
141
8e48aec7
DM
142static int opromgetprop(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize)
143{
144 void *pval;
145 int len;
146
b9b64e6e
DM
147 if (!dp ||
148 !(pval = of_get_property(dp, op->oprom_array, &len)) ||
149 len <= 0 || len > bufsize)
8e48aec7
DM
150 return copyout(argp, op, sizeof(int));
151
152 memcpy(op->oprom_array, pval, len);
153 op->oprom_array[len] = '\0';
154 op->oprom_size = len;
155
156 return copyout(argp, op, sizeof(int) + bufsize);
157}
158
159static int opromnxtprop(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize)
160{
161 struct property *prop;
162 int len;
163
b9b64e6e
DM
164 if (!dp)
165 return copyout(argp, op, sizeof(int));
8e48aec7
DM
166 if (op->oprom_array[0] == '\0') {
167 prop = dp->properties;
168 if (!prop)
169 return copyout(argp, op, sizeof(int));
170 len = strlen(prop->name);
171 } else {
172 prop = of_find_property(dp, op->oprom_array, NULL);
173
174 if (!prop ||
175 !prop->next ||
176 (len = strlen(prop->next->name)) + 1 > bufsize)
177 return copyout(argp, op, sizeof(int));
178
179 prop = prop->next;
180 }
181
182 memcpy(op->oprom_array, prop->name, len);
183 op->oprom_array[len] = '\0';
184 op->oprom_size = ++len;
185
186 return copyout(argp, op, sizeof(int) + bufsize);
187}
188
189static int opromsetopt(struct device_node *dp, struct openpromio *op, int bufsize)
190{
191 char *buf = op->oprom_array + strlen(op->oprom_array) + 1;
192 int len = op->oprom_array + bufsize - buf;
193
194 return of_set_property(options_node, op->oprom_array, buf, len);
195}
196
197static int opromnext(void __user *argp, unsigned int cmd, struct device_node *dp, struct openpromio *op, int bufsize, DATA *data)
198{
199 phandle ph;
200
201 BUILD_BUG_ON(sizeof(phandle) != sizeof(int));
202
203 if (bufsize < sizeof(phandle))
204 return -EINVAL;
205
206 ph = *((int *) op->oprom_array);
207 if (ph) {
208 dp = of_find_node_by_phandle(ph);
209 if (!dp)
210 return -EINVAL;
211
212 switch (cmd) {
213 case OPROMNEXT:
214 dp = dp->sibling;
215 break;
216
217 case OPROMCHILD:
218 dp = dp->child;
219 break;
220
221 case OPROMSETCUR:
222 default:
223 break;
224 };
225 } else {
226 /* Sibling of node zero is the root node. */
227 if (cmd != OPROMNEXT)
228 return -EINVAL;
229
230 dp = of_find_node_by_path("/");
231 }
232
233 ph = 0;
234 if (dp)
235 ph = dp->node;
236
237 data->current_node = dp;
238 *((int *) op->oprom_array) = ph;
239 op->oprom_size = sizeof(phandle);
240
241 return copyout(argp, op, bufsize + sizeof(int));
242}
243
244static int oprompci2node(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize, DATA *data)
245{
246 int err = -EINVAL;
247
248 if (bufsize >= 2*sizeof(int)) {
249#ifdef CONFIG_PCI
250 struct pci_dev *pdev;
251 struct pcidev_cookie *pcp;
7e9f3346 252 pdev = pci_get_bus_and_slot (((int *) op->oprom_array)[0],
8e48aec7
DM
253 ((int *) op->oprom_array)[1]);
254
255 pcp = pdev->sysdata;
256 if (pcp != NULL) {
257 dp = pcp->prom_node;
258 data->current_node = dp;
259 *((int *)op->oprom_array) = dp->node;
260 op->oprom_size = sizeof(int);
261 err = copyout(argp, op, bufsize + sizeof(int));
262 }
7e9f3346 263 pci_dev_put(pdev);
8e48aec7
DM
264#endif
265 }
266
267 return err;
268}
269
270static int oprompath2node(void __user *argp, struct device_node *dp, struct openpromio *op, int bufsize, DATA *data)
271{
b9b64e6e
DM
272 phandle ph = 0;
273
8e48aec7 274 dp = of_find_node_by_path(op->oprom_array);
b9b64e6e
DM
275 if (dp)
276 ph = dp->node;
8e48aec7 277 data->current_node = dp;
b9b64e6e 278 *((int *)op->oprom_array) = ph;
8e48aec7
DM
279 op->oprom_size = sizeof(int);
280
281 return copyout(argp, op, bufsize + sizeof(int));
282}
283
284static int opromgetbootargs(void __user *argp, struct openpromio *op, int bufsize)
285{
286 char *buf = saved_command_line;
287 int len = strlen(buf);
288
289 if (len > bufsize)
290 return -EINVAL;
291
292 strcpy(op->oprom_array, buf);
293 op->oprom_size = len;
294
295 return copyout(argp, op, bufsize + sizeof(int));
296}
297
1da177e4
LT
298/*
299 * SunOS and Solaris /dev/openprom ioctl calls.
300 */
301static int openprom_sunos_ioctl(struct inode * inode, struct file * file,
8e48aec7
DM
302 unsigned int cmd, unsigned long arg,
303 struct device_node *dp)
1da177e4 304{
8e48aec7 305 DATA *data = file->private_data;
1da177e4 306 struct openpromio *opp;
8e48aec7 307 int bufsize, error = 0;
1da177e4
LT
308 static int cnt;
309 void __user *argp = (void __user *)arg;
310
311 if (cmd == OPROMSETOPT)
312 bufsize = getstrings(argp, &opp);
313 else
314 bufsize = copyin(argp, &opp);
315
316 if (bufsize < 0)
317 return bufsize;
318
319 switch (cmd) {
320 case OPROMGETOPT:
321 case OPROMGETPROP:
8e48aec7 322 error = opromgetprop(argp, dp, opp, bufsize);
1da177e4
LT
323 break;
324
325 case OPROMNXTOPT:
326 case OPROMNXTPROP:
8e48aec7 327 error = opromnxtprop(argp, dp, opp, bufsize);
1da177e4
LT
328 break;
329
330 case OPROMSETOPT:
331 case OPROMSETOPT2:
8e48aec7 332 error = opromsetopt(dp, opp, bufsize);
1da177e4
LT
333 break;
334
335 case OPROMNEXT:
336 case OPROMCHILD:
337 case OPROMSETCUR:
8e48aec7 338 error = opromnext(argp, cmd, dp, opp, bufsize, data);
1da177e4
LT
339 break;
340
341 case OPROMPCI2NODE:
8e48aec7 342 error = oprompci2node(argp, dp, opp, bufsize, data);
1da177e4
LT
343 break;
344
345 case OPROMPATH2NODE:
8e48aec7 346 error = oprompath2node(argp, dp, opp, bufsize, data);
1da177e4
LT
347 break;
348
349 case OPROMGETBOOTARGS:
8e48aec7 350 error = opromgetbootargs(argp, opp, bufsize);
1da177e4
LT
351 break;
352
353 case OPROMU2P:
354 case OPROMGETCONS:
355 case OPROMGETFBNAME:
356 if (cnt++ < 10)
357 printk(KERN_INFO "openprom_sunos_ioctl: unimplemented ioctl\n");
358 error = -EINVAL;
359 break;
360 default:
361 if (cnt++ < 10)
362 printk(KERN_INFO "openprom_sunos_ioctl: cmd 0x%X, arg 0x%lX\n", cmd, arg);
363 error = -EINVAL;
364 break;
365 }
366
367 kfree(opp);
368 return error;
369}
370
8e48aec7 371static struct device_node *get_node(phandle n, DATA *data)
1da177e4 372{
8e48aec7 373 struct device_node *dp = of_find_node_by_phandle(n);
1da177e4 374
8e48aec7
DM
375 if (dp)
376 data->lastnode = dp;
377
378 return dp;
1da177e4
LT
379}
380
381/* Copy in a whole string from userspace into kernelspace. */
382static int copyin_string(char __user *user, size_t len, char **ptr)
383{
384 char *tmp;
385
386 if ((ssize_t)len < 0 || (ssize_t)(len + 1) < 0)
387 return -EINVAL;
388
389 tmp = kmalloc(len + 1, GFP_KERNEL);
390 if (!tmp)
391 return -ENOMEM;
392
8e48aec7 393 if (copy_from_user(tmp, user, len)) {
1da177e4
LT
394 kfree(tmp);
395 return -EFAULT;
396 }
397
398 tmp[len] = '\0';
399
400 *ptr = tmp;
401
402 return 0;
403}
404
405/*
406 * NetBSD /dev/openprom ioctl calls.
407 */
8e48aec7 408static int opiocget(void __user *argp, DATA *data)
1da177e4 409{
1da177e4 410 struct opiocdesc op;
8e48aec7
DM
411 struct device_node *dp;
412 char *str;
413 void *pval;
414 int err, len;
1da177e4 415
8e48aec7
DM
416 if (copy_from_user(&op, argp, sizeof(op)))
417 return -EFAULT;
1da177e4 418
8e48aec7 419 dp = get_node(op.op_nodeid, data);
1da177e4 420
8e48aec7
DM
421 err = copyin_string(op.op_name, op.op_namelen, &str);
422 if (err)
423 return err;
1da177e4 424
8e48aec7
DM
425 pval = of_get_property(dp, str, &len);
426 err = 0;
427 if (!pval || len > op.op_buflen) {
428 err = -EINVAL;
429 } else {
1da177e4 430 op.op_buflen = len;
8e48aec7
DM
431 if (copy_to_user(argp, &op, sizeof(op)) ||
432 copy_to_user(op.op_buf, pval, len))
433 err = -EFAULT;
434 }
435 kfree(str);
1da177e4 436
8e48aec7
DM
437 return err;
438}
1da177e4 439
8e48aec7
DM
440static int opiocnextprop(void __user *argp, DATA *data)
441{
442 struct opiocdesc op;
443 struct device_node *dp;
444 struct property *prop;
445 char *str;
446 int err, len;
1da177e4 447
8e48aec7
DM
448 if (copy_from_user(&op, argp, sizeof(op)))
449 return -EFAULT;
1da177e4 450
8e48aec7
DM
451 dp = get_node(op.op_nodeid, data);
452 if (!dp)
453 return -EINVAL;
1da177e4 454
8e48aec7
DM
455 err = copyin_string(op.op_name, op.op_namelen, &str);
456 if (err)
457 return err;
1da177e4 458
8e48aec7
DM
459 if (str[0] == '\0') {
460 prop = dp->properties;
461 } else {
462 prop = of_find_property(dp, str, NULL);
463 if (prop)
464 prop = prop->next;
465 }
466 kfree(str);
1da177e4 467
8e48aec7
DM
468 if (!prop)
469 len = 0;
470 else
471 len = prop->length;
1da177e4 472
8e48aec7
DM
473 if (len > op.op_buflen)
474 len = op.op_buflen;
1da177e4 475
8e48aec7
DM
476 if (copy_to_user(argp, &op, sizeof(op)))
477 return -EFAULT;
1da177e4 478
8e48aec7
DM
479 if (len &&
480 copy_to_user(op.op_buf, prop->value, len))
481 return -EFAULT;
1da177e4 482
8e48aec7
DM
483 return 0;
484}
1da177e4 485
8e48aec7
DM
486static int opiocset(void __user *argp, DATA *data)
487{
488 struct opiocdesc op;
489 struct device_node *dp;
490 char *str, *tmp;
491 int err;
1da177e4 492
8e48aec7
DM
493 if (copy_from_user(&op, argp, sizeof(op)))
494 return -EFAULT;
495
496 dp = get_node(op.op_nodeid, data);
497 if (!dp)
498 return -EINVAL;
1da177e4 499
8e48aec7
DM
500 err = copyin_string(op.op_name, op.op_namelen, &str);
501 if (err)
502 return err;
1da177e4 503
8e48aec7
DM
504 err = copyin_string(op.op_buf, op.op_buflen, &tmp);
505 if (err) {
1da177e4 506 kfree(str);
8e48aec7
DM
507 return err;
508 }
1da177e4 509
8e48aec7 510 err = of_set_property(dp, str, tmp, op.op_buflen);
1da177e4 511
8e48aec7
DM
512 kfree(str);
513 kfree(tmp);
1da177e4 514
8e48aec7
DM
515 return err;
516}
1da177e4 517
8e48aec7
DM
518static int opiocgetnext(unsigned int cmd, void __user *argp)
519{
520 struct device_node *dp;
521 phandle nd;
1da177e4 522
8e48aec7 523 BUILD_BUG_ON(sizeof(phandle) != sizeof(int));
1da177e4 524
8e48aec7
DM
525 if (copy_from_user(&nd, argp, sizeof(phandle)))
526 return -EFAULT;
1da177e4 527
8e48aec7
DM
528 if (nd == 0) {
529 if (cmd != OPIOCGETNEXT)
1da177e4 530 return -EINVAL;
8e48aec7
DM
531 dp = of_find_node_by_path("/");
532 } else {
533 dp = of_find_node_by_phandle(nd);
534 nd = 0;
535 if (dp) {
536 if (cmd == OPIOCGETNEXT)
537 dp = dp->sibling;
538 else
539 dp = dp->child;
540 }
541 }
542 if (dp)
543 nd = dp->node;
544 if (copy_to_user(argp, &nd, sizeof(phandle)))
545 return -EFAULT;
1da177e4 546
8e48aec7
DM
547 return 0;
548}
1da177e4 549
8e48aec7
DM
550static int openprom_bsd_ioctl(struct inode * inode, struct file * file,
551 unsigned int cmd, unsigned long arg)
552{
553 DATA *data = (DATA *) file->private_data;
554 void __user *argp = (void __user *)arg;
555 int err;
1da177e4 556
8e48aec7
DM
557 switch (cmd) {
558 case OPIOCGET:
559 err = opiocget(argp, data);
560 break;
1da177e4 561
8e48aec7
DM
562 case OPIOCNEXTPROP:
563 err = opiocnextprop(argp, data);
564 break;
1da177e4 565
8e48aec7
DM
566 case OPIOCSET:
567 err = opiocset(argp, data);
568 break;
569
570 case OPIOCGETOPTNODE:
571 BUILD_BUG_ON(sizeof(phandle) != sizeof(int));
1da177e4 572
8e48aec7 573 if (copy_to_user(argp, &options_node->node, sizeof(phandle)))
1da177e4
LT
574 return -EFAULT;
575
576 return 0;
577
8e48aec7
DM
578 case OPIOCGETNEXT:
579 case OPIOCGETCHILD:
580 err = opiocgetnext(cmd, argp);
581 break;
582
1da177e4 583 default:
1da177e4
LT
584 return -EINVAL;
585
8e48aec7
DM
586 };
587
588 return err;
1da177e4
LT
589}
590
591
592/*
593 * Handoff control to the correct ioctl handler.
594 */
595static int openprom_ioctl(struct inode * inode, struct file * file,
596 unsigned int cmd, unsigned long arg)
597{
598 DATA *data = (DATA *) file->private_data;
1da177e4
LT
599
600 switch (cmd) {
601 case OPROMGETOPT:
602 case OPROMNXTOPT:
603 if ((file->f_mode & FMODE_READ) == 0)
604 return -EPERM;
605 return openprom_sunos_ioctl(inode, file, cmd, arg,
606 options_node);
607
608 case OPROMSETOPT:
609 case OPROMSETOPT2:
610 if ((file->f_mode & FMODE_WRITE) == 0)
611 return -EPERM;
612 return openprom_sunos_ioctl(inode, file, cmd, arg,
613 options_node);
614
615 case OPROMNEXT:
616 case OPROMCHILD:
617 case OPROMGETPROP:
618 case OPROMNXTPROP:
619 if ((file->f_mode & FMODE_READ) == 0)
620 return -EPERM;
621 return openprom_sunos_ioctl(inode, file, cmd, arg,
622 data->current_node);
623
624 case OPROMU2P:
625 case OPROMGETCONS:
626 case OPROMGETFBNAME:
627 case OPROMGETBOOTARGS:
628 case OPROMSETCUR:
629 case OPROMPCI2NODE:
630 case OPROMPATH2NODE:
631 if ((file->f_mode & FMODE_READ) == 0)
632 return -EPERM;
a6ded1b0 633 return openprom_sunos_ioctl(inode, file, cmd, arg, NULL);
1da177e4
LT
634
635 case OPIOCGET:
636 case OPIOCNEXTPROP:
637 case OPIOCGETOPTNODE:
638 case OPIOCGETNEXT:
639 case OPIOCGETCHILD:
640 if ((file->f_mode & FMODE_READ) == 0)
641 return -EBADF;
642 return openprom_bsd_ioctl(inode,file,cmd,arg);
643
644 case OPIOCSET:
645 if ((file->f_mode & FMODE_WRITE) == 0)
646 return -EBADF;
647 return openprom_bsd_ioctl(inode,file,cmd,arg);
648
649 default:
1da177e4 650 return -EINVAL;
8e48aec7 651 };
1da177e4
LT
652}
653
b31023fc
CH
654static long openprom_compat_ioctl(struct file *file, unsigned int cmd,
655 unsigned long arg)
656{
657 long rval = -ENOTTY;
658
659 /*
660 * SunOS/Solaris only, the NetBSD one's have embedded pointers in
661 * the arg which we'd need to clean up...
662 */
663 switch (cmd) {
664 case OPROMGETOPT:
665 case OPROMSETOPT:
666 case OPROMNXTOPT:
667 case OPROMSETOPT2:
668 case OPROMNEXT:
669 case OPROMCHILD:
670 case OPROMGETPROP:
671 case OPROMNXTPROP:
672 case OPROMU2P:
673 case OPROMGETCONS:
674 case OPROMGETFBNAME:
675 case OPROMGETBOOTARGS:
676 case OPROMSETCUR:
677 case OPROMPCI2NODE:
678 case OPROMPATH2NODE:
7fa95f72 679 rval = openprom_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
b31023fc
CH
680 break;
681 }
d5a858bc
DM
682
683 return rval;
b31023fc
CH
684}
685
1da177e4
LT
686static int openprom_open(struct inode * inode, struct file * file)
687{
688 DATA *data;
689
8e48aec7 690 data = kmalloc(sizeof(DATA), GFP_KERNEL);
1da177e4
LT
691 if (!data)
692 return -ENOMEM;
693
8e48aec7
DM
694 data->current_node = of_find_node_by_path("/");
695 data->lastnode = data->current_node;
696 file->private_data = (void *) data;
1da177e4
LT
697
698 return 0;
699}
700
701static int openprom_release(struct inode * inode, struct file * file)
702{
703 kfree(file->private_data);
704 return 0;
705}
706
00977a59 707static const struct file_operations openprom_fops = {
1da177e4
LT
708 .owner = THIS_MODULE,
709 .llseek = no_llseek,
710 .ioctl = openprom_ioctl,
d5a858bc 711 .compat_ioctl = openprom_compat_ioctl,
1da177e4
LT
712 .open = openprom_open,
713 .release = openprom_release,
714};
715
716static struct miscdevice openprom_dev = {
8e48aec7
DM
717 .minor = SUN_OPENPROM_MINOR,
718 .name = "openprom",
719 .fops = &openprom_fops,
1da177e4
LT
720};
721
722static int __init openprom_init(void)
723{
8e48aec7
DM
724 struct device_node *dp;
725 int err;
1da177e4 726
8e48aec7
DM
727 err = misc_register(&openprom_dev);
728 if (err)
729 return err;
1da177e4 730
8e48aec7
DM
731 dp = of_find_node_by_path("/");
732 dp = dp->child;
733 while (dp) {
734 if (!strcmp(dp->name, "options"))
735 break;
736 dp = dp->sibling;
737 }
738 options_node = dp;
1da177e4 739
8e48aec7 740 if (!options_node) {
1da177e4
LT
741 misc_deregister(&openprom_dev);
742 return -EIO;
743 }
744
745 return 0;
746}
747
748static void __exit openprom_cleanup(void)
749{
750 misc_deregister(&openprom_dev);
751}
752
753module_init(openprom_init);
754module_exit(openprom_cleanup);
This page took 0.244836 seconds and 5 git commands to generate.