2 * c 2001 PPC 64 Team, IBM Corp
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.
9 * /dev/nvram driver for PPC
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>
19 #include <asm/machdep.h>
23 static unsigned int nvram_size;
24 static unsigned char nvram_buf[4];
25 static DEFINE_SPINLOCK(nvram_lock);
27 static unsigned char chrp_nvram_read(int addr)
33 if (addr >= nvram_size) {
34 printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n",
35 current->comm, addr, nvram_size);
38 spin_lock_irqsave(&nvram_lock, flags);
39 if ((rtas_call(rtas_token("nvram-fetch"), 3, 2, &done, addr,
40 __pa(nvram_buf), 1) != 0) || 1 != done)
44 spin_unlock_irqrestore(&nvram_lock, flags);
49 static void chrp_nvram_write(int addr, unsigned char val)
54 if (addr >= nvram_size) {
55 printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n",
56 current->comm, addr, nvram_size);
59 spin_lock_irqsave(&nvram_lock, flags);
61 if ((rtas_call(rtas_token("nvram-store"), 3, 2, &done, addr,
62 __pa(nvram_buf), 1) != 0) || 1 != done)
63 printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr);
64 spin_unlock_irqrestore(&nvram_lock, flags);
67 void __init chrp_nvram_init(void)
69 struct device_node *nvram;
70 unsigned int *nbytes_p, proplen;
72 nvram = of_find_node_by_type(NULL, "nvram");
76 nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen);
77 if (nbytes_p == NULL || proplen != sizeof(unsigned int))
80 nvram_size = *nbytes_p;
82 printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);
85 ppc_md.nvram_read_val = chrp_nvram_read;
86 ppc_md.nvram_write_val = chrp_nvram_write;