This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / ppc / platforms / chrp_nvram.c
1 /*
2  *  c 2001 PPC 64 Team, IBM Corp
3  *
4  *      This program is free software; you can redistribute it and/or
5  *      modify it under the terms of the GNU General Public License
6  *      as published by the Free Software Foundation; either version
7  *      2 of the License, or (at your option) any later version.
8  *
9  * /dev/nvram driver for PPC
10  *
11  */
12
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/spinlock.h>
17 #include <asm/uaccess.h>
18 #include <asm/prom.h>
19 #include <asm/machdep.h>
20
21 static unsigned int nvram_size;
22 static unsigned char nvram_buf[4];
23 static DEFINE_SPINLOCK(nvram_lock);
24
25 static unsigned char chrp_nvram_read(int addr)
26 {
27         unsigned long done, flags;
28         unsigned char ret;
29
30         if (addr >= nvram_size) {
31                 printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n",
32                        current->comm, addr, nvram_size);
33                 return 0xff;
34         }
35         spin_lock_irqsave(&nvram_lock, flags);
36         if ((call_rtas("nvram-fetch", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done)
37                 ret = 0xff;
38         else
39                 ret = nvram_buf[0];
40         spin_unlock_irqrestore(&nvram_lock, flags);
41
42         return ret;
43 }
44
45 static void chrp_nvram_write(int addr, unsigned char val)
46 {
47         unsigned long done, flags;
48
49         if (addr >= nvram_size) {
50                 printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n",
51                        current->comm, addr, nvram_size);
52                 return;
53         }
54         spin_lock_irqsave(&nvram_lock, flags);
55         nvram_buf[0] = val;
56         if ((call_rtas("nvram-store", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done)
57                 printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr);
58         spin_unlock_irqrestore(&nvram_lock, flags);
59 }
60
61 void __init chrp_nvram_init(void)
62 {
63         struct device_node *nvram;
64         unsigned int *nbytes_p, proplen;
65
66         nvram = of_find_node_by_type(NULL, "nvram");
67         if (nvram == NULL)
68                 return;
69
70         nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen);
71         if (nbytes_p == NULL || proplen != sizeof(unsigned int))
72                 return;
73
74         nvram_size = *nbytes_p;
75
76         printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);
77         of_node_put(nvram);
78
79         ppc_md.nvram_read_val = chrp_nvram_read;
80         ppc_md.nvram_write_val = chrp_nvram_write;
81
82         return;
83 }