Path: blob/master/arch/powerpc/platforms/chrp/nvram.c
10820 views
/*1* c 2001 PPC 64 Team, IBM Corp2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation; either version6* 2 of the License, or (at your option) any later version.7*8* /dev/nvram driver for PPC9*10*/1112#include <linux/kernel.h>13#include <linux/init.h>14#include <linux/spinlock.h>15#include <asm/uaccess.h>16#include <asm/prom.h>17#include <asm/machdep.h>18#include <asm/rtas.h>19#include "chrp.h"2021static unsigned int nvram_size;22static unsigned char nvram_buf[4];23static DEFINE_SPINLOCK(nvram_lock);2425static unsigned char chrp_nvram_read(int addr)26{27unsigned int done;28unsigned long flags;29unsigned char ret;3031if (addr >= nvram_size) {32printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n",33current->comm, addr, nvram_size);34return 0xff;35}36spin_lock_irqsave(&nvram_lock, flags);37if ((rtas_call(rtas_token("nvram-fetch"), 3, 2, &done, addr,38__pa(nvram_buf), 1) != 0) || 1 != done)39ret = 0xff;40else41ret = nvram_buf[0];42spin_unlock_irqrestore(&nvram_lock, flags);4344return ret;45}4647static void chrp_nvram_write(int addr, unsigned char val)48{49unsigned int done;50unsigned long flags;5152if (addr >= nvram_size) {53printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n",54current->comm, addr, nvram_size);55return;56}57spin_lock_irqsave(&nvram_lock, flags);58nvram_buf[0] = val;59if ((rtas_call(rtas_token("nvram-store"), 3, 2, &done, addr,60__pa(nvram_buf), 1) != 0) || 1 != done)61printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr);62spin_unlock_irqrestore(&nvram_lock, flags);63}6465void __init chrp_nvram_init(void)66{67struct device_node *nvram;68const unsigned int *nbytes_p;69unsigned int proplen;7071nvram = of_find_node_by_type(NULL, "nvram");72if (nvram == NULL)73return;7475nbytes_p = of_get_property(nvram, "#bytes", &proplen);76if (nbytes_p == NULL || proplen != sizeof(unsigned int)) {77of_node_put(nvram);78return;79}8081nvram_size = *nbytes_p;8283printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);84of_node_put(nvram);8586ppc_md.nvram_read_val = chrp_nvram_read;87ppc_md.nvram_write_val = chrp_nvram_write;8889return;90}919293