aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh/nvram.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/macintosh/nvram.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/macintosh/nvram.c')
-rw-r--r--drivers/macintosh/nvram.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/drivers/macintosh/nvram.c b/drivers/macintosh/nvram.c
new file mode 100644
index 000000000000..30791875fc97
--- /dev/null
+++ b/drivers/macintosh/nvram.c
@@ -0,0 +1,131 @@
1/*
2 * /dev/nvram driver for Power Macintosh.
3 */
4
5#define NVRAM_VERSION "1.0"
6
7#include <linux/module.h>
8
9#include <linux/types.h>
10#include <linux/errno.h>
11#include <linux/fs.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>
19
20#define NVRAM_SIZE 8192
21
22static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
23{
24 lock_kernel();
25 switch (origin) {
26 case 1:
27 offset += file->f_pos;
28 break;
29 case 2:
30 offset += NVRAM_SIZE;
31 break;
32 }
33 if (offset < 0) {
34 unlock_kernel();
35 return -EINVAL;
36 }
37 file->f_pos = offset;
38 unlock_kernel();
39 return file->f_pos;
40}
41
42static ssize_t read_nvram(struct file *file, char __user *buf,
43 size_t count, loff_t *ppos)
44{
45 unsigned int i;
46 char __user *p = buf;
47
48 if (!access_ok(VERIFY_WRITE, buf, count))
49 return -EFAULT;
50 if (*ppos >= NVRAM_SIZE)
51 return 0;
52 for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count)
53 if (__put_user(nvram_read_byte(i), p))
54 return -EFAULT;
55 *ppos = i;
56 return p - buf;
57}
58
59static ssize_t write_nvram(struct file *file, const char __user *buf,
60 size_t count, loff_t *ppos)
61{
62 unsigned int i;
63 const char __user *p = buf;
64 char c;
65
66 if (!access_ok(VERIFY_READ, buf, count))
67 return -EFAULT;
68 if (*ppos >= NVRAM_SIZE)
69 return 0;
70 for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count) {
71 if (__get_user(c, p))
72 return -EFAULT;
73 nvram_write_byte(c, i);
74 }
75 *ppos = i;
76 return p - buf;
77}
78
79static int nvram_ioctl(struct inode *inode, struct file *file,
80 unsigned int cmd, unsigned long arg)
81{
82 switch(cmd) {
83 case PMAC_NVRAM_GET_OFFSET:
84 {
85 int part, offset;
86 if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
87 return -EFAULT;
88 if (part < pmac_nvram_OF || part > pmac_nvram_NR)
89 return -EINVAL;
90 offset = pmac_get_partition(part);
91 if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0)
92 return -EFAULT;
93 break;
94 }
95
96 default:
97 return -EINVAL;
98 }
99
100 return 0;
101}
102
103struct file_operations nvram_fops = {
104 .owner = THIS_MODULE,
105 .llseek = nvram_llseek,
106 .read = read_nvram,
107 .write = write_nvram,
108 .ioctl = nvram_ioctl,
109};
110
111static struct miscdevice nvram_dev = {
112 NVRAM_MINOR,
113 "nvram",
114 &nvram_fops
115};
116
117int __init nvram_init(void)
118{
119 printk(KERN_INFO "Macintosh non-volatile memory driver v%s\n",
120 NVRAM_VERSION);
121 return misc_register(&nvram_dev);
122}
123
124void __exit nvram_cleanup(void)
125{
126 misc_deregister( &nvram_dev );
127}
128
129module_init(nvram_init);
130module_exit(nvram_cleanup);
131MODULE_LICENSE("GPL");