2 * /dev/nvram driver for Power Macintosh.
5 #define NVRAM_VERSION "1.0"
7 #include <linux/module.h>
9 #include <linux/types.h>
10 #include <linux/errno.h>
12 #include <linux/miscdevice.h>
13 #include <linux/fcntl.h>
14 #include <linux/nvram.h>
15 #include <linux/init.h>
16 #include <linux/smp_lock.h>
17 #include <asm/uaccess.h>
18 #include <asm/nvram.h>
20 #define NVRAM_SIZE 8192
22 static loff_t
nvram_llseek(struct file
*file
, loff_t offset
, int origin
)
27 offset
+= file
->f_pos
;
42 static ssize_t
read_nvram(struct file
*file
, char __user
*buf
,
43 size_t count
, loff_t
*ppos
)
48 if (verify_area(VERIFY_WRITE
, buf
, count
))
50 if (*ppos
>= NVRAM_SIZE
)
52 for (i
= *ppos
; count
> 0 && i
< NVRAM_SIZE
; ++i
, ++p
, --count
)
53 if (__put_user(nvram_read_byte(i
), p
))
59 static ssize_t
write_nvram(struct file
*file
, const char __user
*buf
,
60 size_t count
, loff_t
*ppos
)
63 const char __user
*p
= buf
;
66 if (verify_area(VERIFY_READ
, buf
, count
))
68 if (*ppos
>= NVRAM_SIZE
)
70 for (i
= *ppos
; count
> 0 && i
< NVRAM_SIZE
; ++i
, ++p
, --count
) {
73 nvram_write_byte(c
, i
);
79 static int nvram_ioctl(struct inode
*inode
, struct file
*file
,
80 unsigned int cmd
, unsigned long arg
)
83 case PMAC_NVRAM_GET_OFFSET
:
86 if (copy_from_user(&part
, (void __user
*)arg
, sizeof(part
)) != 0)
88 if (part
< pmac_nvram_OF
|| part
> pmac_nvram_NR
)
90 offset
= pmac_get_partition(part
);
91 if (copy_to_user((void __user
*)arg
, &offset
, sizeof(offset
)) != 0)
103 struct file_operations nvram_fops
= {
104 .owner
= THIS_MODULE
,
105 .llseek
= nvram_llseek
,
107 .write
= write_nvram
,
108 .ioctl
= nvram_ioctl
,
111 static struct miscdevice nvram_dev
= {
117 int __init
nvram_init(void)
119 printk(KERN_INFO
"Macintosh non-volatile memory driver v%s\n",
121 return misc_register(&nvram_dev
);
124 void __exit
nvram_cleanup(void)
126 misc_deregister( &nvram_dev
);
129 module_init(nvram_init
);
130 module_exit(nvram_cleanup
);
131 MODULE_LICENSE("GPL");