Import 2.1.118
[davej-history.git] / drivers / macintosh / nvram.c
blob33297e3f28af6ea5e009fa9b004d40f23eb26b9b
1 /*
2 * /dev/nvram driver for Power Macintosh.
3 */
4 #include <linux/types.h>
5 #include <linux/errno.h>
6 #include <linux/fs.h>
7 #include <linux/miscdevice.h>
8 #include <linux/fcntl.h>
9 #include <linux/nvram.h>
10 #include <linux/init.h>
11 #include <asm/uaccess.h>
12 #include <asm/init.h>
14 #define NVRAM_SIZE 8192
16 __openfirmware
18 static long long nvram_llseek(struct file *file, loff_t offset, int origin)
20 switch (origin) {
21 case 1:
22 offset += file->f_pos;
23 break;
24 case 2:
25 offset += NVRAM_SIZE;
26 break;
28 if (offset < 0)
29 return -EINVAL;
30 file->f_pos = offset;
31 return file->f_pos;
34 static ssize_t read_nvram(struct file *file, char *buf,
35 size_t count, loff_t *ppos)
37 unsigned int i;
38 char *p = buf;
40 if (verify_area(VERIFY_WRITE, buf, count))
41 return -EFAULT;
42 if (*ppos >= NVRAM_SIZE)
43 return 0;
44 for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count)
45 if (__put_user(nvram_read_byte(i), p))
46 return -EFAULT;
47 *ppos = i;
48 return p - buf;
51 static ssize_t write_nvram(struct file *file, const char *buf,
52 size_t count, loff_t *ppos)
54 unsigned int i;
55 const char *p = buf;
56 char c;
58 if (verify_area(VERIFY_READ, buf, count))
59 return -EFAULT;
60 if (*ppos >= NVRAM_SIZE)
61 return 0;
62 for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count) {
63 if (__get_user(c, p))
64 return -EFAULT;
65 nvram_write_byte(c, i);
67 *ppos = i;
68 return p - buf;
71 static int nvram_open(struct inode *inode, struct file *file)
73 return 0;
76 struct file_operations nvram_fops = {
77 nvram_llseek,
78 read_nvram,
79 write_nvram,
80 NULL, /* nvram_readdir */
81 NULL, /* nvram_select */
82 NULL, /* nvram_ioctl */
83 NULL, /* nvram_mmap */
84 nvram_open,
85 NULL, /* flush */
86 NULL, /* no special release code */
87 NULL /* fsync */
90 static struct miscdevice nvram_dev = {
91 NVRAM_MINOR,
92 "nvram",
93 &nvram_fops
96 __initfunc(int nvram_init(void))
98 misc_register(&nvram_dev);
99 return 0;