Unlike pSeries, we don't want to use rtas for accessing nvram
(Bbecause the nvram device is rather large and it already is
(Bmapped into the physical address space, which makes a much
(Bsimpler and faster design possible.
(B
(BThe firmware provides the location and size of the nvram
(Bin the device tree, so it does not really contain any
(Bhardware specific bits and could be used on other
(Bmachines as well.
(B 
(BFrom: Utz Bacher <[EMAIL PROTECTED]>
(BSigned-off-by: Arnd Bergmann <[EMAIL PROTECTED]>
(B
(BIndex: linus-2.5/arch/ppc64/kernel/bpa_nvram.c
(B===================================================================
(B--- /dev/null   1970-01-01 00:00:00.000000000 +0000
(B+++ linus-2.5/arch/ppc64/kernel/bpa_nvram.c     2005-04-20 01:55:36.000000000 
(B+0200
(B@@ -0,0 +1,118 @@
(B+/*
(B+ * NVRAM for CPBW
(B+ *
(B+ * (C) Copyright IBM Corp. 2005
(B+ *
(B+ * Authors : Utz Bacher <[EMAIL PROTECTED]>
(B+ *
(B+ * This program is free software; you can redistribute it and/or modify
(B+ * it under the terms of the GNU General Public License as published by
(B+ * the Free Software Foundation; either version 2, or (at your option)
(B+ * any later version.
(B+ *
(B+ * This program is distributed in the hope that it will be useful,
(B+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
(B+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
(B+ * GNU General Public License for more details.
(B+ *
(B+ * You should have received a copy of the GNU General Public License
(B+ * along with this program; if not, write to the Free Software
(B+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
(B+ */
(B+
(B+#include <linux/fs.h>
(B+#include <linux/init.h>
(B+#include <linux/kernel.h>
(B+#include <linux/spinlock.h>
(B+#include <linux/types.h>
(B+
(B+#include <asm/machdep.h>
(B+#include <asm/nvram.h>
(B+#include <asm/prom.h>
(B+
(B+static void __iomem *bpa_nvram_start;
(B+static long bpa_nvram_len;
(B+static spinlock_t bpa_nvram_lock = SPIN_LOCK_UNLOCKED;
(B+
(B+static ssize_t bpa_nvram_read(char *buf, size_t count, loff_t *index)
(B+{
(B+       unsigned long flags;
(B+
(B+       if (*index >= bpa_nvram_len)
(B+               return 0;
(B+       if (*index + count > bpa_nvram_len)
(B+               count = bpa_nvram_len - *index;
(B+
(B+       spin_lock_irqsave(&bpa_nvram_lock, flags);
(B+
(B+       memcpy_fromio(buf, bpa_nvram_start + *index, count);
(B+
(B+       spin_unlock_irqrestore(&bpa_nvram_lock, flags);
(B+       
(B+       *index += count;
(B+       return count;
(B+}
(B+
(B+static ssize_t bpa_nvram_write(char *buf, size_t count, loff_t *index)
(B+{
(B+       unsigned long flags;
(B+
(B+       if (*index >= bpa_nvram_len)
(B+               return 0;
(B+       if (*index + count > bpa_nvram_len)
(B+               count = bpa_nvram_len - *index;
(B+
(B+       spin_lock_irqsave(&bpa_nvram_lock, flags);
(B+
(B+       memcpy_toio(bpa_nvram_start + *index, buf, count);
(B+
(B+       spin_unlock_irqrestore(&bpa_nvram_lock, flags);
(B+       
(B+       *index += count;
(B+       return count;
(B+}
(B+
(B+static ssize_t bpa_nvram_get_size(void)
(B+{
(B+       return bpa_nvram_len;
(B+}
(B+
(B+int __init bpa_nvram_init(void)
(B+{
(B+       struct device_node *nvram_node;
(B+       unsigned long *buffer;
(B+       int proplen;
(B+       unsigned long nvram_addr;
(B+       int ret;
(B+
(B+       ret = -ENODEV;
(B+       nvram_node = of_find_node_by_type(NULL, "nvram");
(B+       if (!nvram_node)
(B+               goto out;
(B+
(B+       ret = -EIO;
(B+       buffer = (unsigned long *)get_property(nvram_node, "reg", &proplen);
(B+       if (proplen != 2*sizeof(unsigned long))
(B+               goto out;
(B+
(B+       ret = -ENODEV;
(B+       nvram_addr = buffer[0];
(B+       bpa_nvram_len = buffer[1];
(B+       if ( (!bpa_nvram_len) || (!nvram_addr) )
(B+               goto out;
(B+
(B+       bpa_nvram_start = ioremap(nvram_addr, bpa_nvram_len);
(B+       if (!bpa_nvram_start)
(B+               goto out;
(B+
(B+       printk(KERN_INFO "BPA NVRAM, %luk mapped to %p\n",
(B+              bpa_nvram_len >> 10, bpa_nvram_start);
(B+
(B+       ppc_md.nvram_read       = bpa_nvram_read;
(B+       ppc_md.nvram_write      = bpa_nvram_write;
(B+       ppc_md.nvram_size       = bpa_nvram_get_size;
(B+
(B+out:
(B+       of_node_put(nvram_node);
(B+       return ret;
(B+}
(BIndex: linus-2.5/include/asm-ppc64/nvram.h
(B===================================================================
(B--- linus-2.5.orig/include/asm-ppc64/nvram.h    2005-04-20 01:54:03.000000000 
(B+0200
(B+++ linus-2.5/include/asm-ppc64/nvram.h 2005-04-20 01:55:36.000000000 +0200
(B@@ -70,6 +70,7 @@
(B 
(B extern int pSeries_nvram_init(void);
(B extern int pmac_nvram_init(void);
(B+extern int bpa_nvram_init(void);
(B 
(B /* PowerMac specific nvram stuffs */
(B 
(B
(B-
(BTo unsubscribe from this list: send the line "unsubscribe linux-kernel" in
(Bthe body of a message to [EMAIL PROTECTED]
(BMore majordomo info at  http://vger.kernel.org/majordomo-info.html
(BPlease read the FAQ at  http://www.tux.org/lkml/

Reply via email to