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 <asm/uaccess.h>
17 #include <asm/nvram.h>
19 #define NVRAM_SIZE 8192
21 static loff_t
nvram_llseek(struct file
*file
, loff_t offset
, int origin
)
25 offset
+= file
->f_pos
;
38 static ssize_t
read_nvram(struct file
*file
, char __user
*buf
,
39 size_t count
, loff_t
*ppos
)
44 if (!access_ok(VERIFY_WRITE
, buf
, count
))
46 if (*ppos
>= NVRAM_SIZE
)
48 for (i
= *ppos
; count
> 0 && i
< NVRAM_SIZE
; ++i
, ++p
, --count
)
49 if (__put_user(nvram_read_byte(i
), p
))
55 static ssize_t
write_nvram(struct file
*file
, const char __user
*buf
,
56 size_t count
, loff_t
*ppos
)
59 const char __user
*p
= buf
;
62 if (!access_ok(VERIFY_READ
, buf
, count
))
64 if (*ppos
>= NVRAM_SIZE
)
66 for (i
= *ppos
; count
> 0 && i
< NVRAM_SIZE
; ++i
, ++p
, --count
) {
69 nvram_write_byte(c
, i
);
75 static long nvram_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
78 case PMAC_NVRAM_GET_OFFSET
:
81 if (copy_from_user(&part
, (void __user
*)arg
, sizeof(part
)) != 0)
83 if (part
< pmac_nvram_OF
|| part
> pmac_nvram_NR
)
85 offset
= pmac_get_partition(part
);
86 if (copy_to_user((void __user
*)arg
, &offset
, sizeof(offset
)) != 0)
98 const struct file_operations nvram_fops
= {
100 .llseek
= nvram_llseek
,
102 .write
= write_nvram
,
103 .ioctl
= nvram_ioctl
,
106 static struct miscdevice nvram_dev
= {
112 int __init
nvram_init(void)
114 printk(KERN_INFO
"Macintosh non-volatile memory driver v%s\n",
116 return misc_register(&nvram_dev
);
119 void __exit
nvram_cleanup(void)
121 misc_deregister( &nvram_dev
);
124 module_init(nvram_init
);
125 module_exit(nvram_cleanup
);
126 MODULE_LICENSE("GPL");