2 * Generic /dev/nvram driver for architectures providing some
3 * "generic" hooks, that is :
5 * nvram_read_byte, nvram_write_byte, nvram_sync
7 * Note that an additional hook is supported for PowerMac only
8 * for getting the nvram "partition" informations
12 #define NVRAM_VERSION "1.1"
14 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/errno.h>
19 #include <linux/miscdevice.h>
20 #include <linux/fcntl.h>
21 #include <linux/init.h>
22 #include <linux/smp_lock.h>
23 #include <asm/uaccess.h>
24 #include <asm/nvram.h>
26 #define NVRAM_SIZE 8192
28 static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
33 offset += file->f_pos;
48 static ssize_t read_nvram(struct file *file, char __user *buf,
49 size_t count, loff_t *ppos)
54 if (!access_ok(VERIFY_WRITE, buf, count))
56 if (*ppos >= NVRAM_SIZE)
58 for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count)
59 if (__put_user(nvram_read_byte(i), p))
65 static ssize_t write_nvram(struct file *file, const char __user *buf,
66 size_t count, loff_t *ppos)
69 const char __user *p = buf;
72 if (!access_ok(VERIFY_READ, buf, count))
74 if (*ppos >= NVRAM_SIZE)
76 for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count) {
79 nvram_write_byte(c, i);
85 static int nvram_ioctl(struct inode *inode, struct file *file,
86 unsigned int cmd, unsigned long arg)
89 #ifdef CONFIG_PPC_PMAC
90 case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
91 printk(KERN_WARNING "nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n");
92 case IOC_NVRAM_GET_OFFSET: {
95 if (_machine != _MACH_Pmac)
97 if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
99 if (part < pmac_nvram_OF || part > pmac_nvram_NR)
101 offset = pmac_get_partition(part);
102 if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0)
106 #endif /* CONFIG_PPC_PMAC */
117 struct file_operations nvram_fops = {
118 .owner = THIS_MODULE,
119 .llseek = nvram_llseek,
121 .write = write_nvram,
122 .ioctl = nvram_ioctl,
125 static struct miscdevice nvram_dev = {
131 int __init nvram_init(void)
133 printk(KERN_INFO "Macintosh non-volatile memory driver v%s\n",
135 return misc_register(&nvram_dev);
138 void __exit nvram_cleanup(void)
140 misc_deregister( &nvram_dev );
143 module_init(nvram_init);
144 module_exit(nvram_cleanup);
145 MODULE_LICENSE("GPL");