~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/chrp/nvram.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  *  c 2001 PPC 64 Team, IBM Corp
  4  *
  5  * /dev/nvram driver for PPC
  6  */
  7 
  8 #include <linux/kernel.h>
  9 #include <linux/module.h>
 10 #include <linux/init.h>
 11 #include <linux/spinlock.h>
 12 #include <linux/uaccess.h>
 13 #include <linux/of.h>
 14 #include <asm/machdep.h>
 15 #include <asm/rtas.h>
 16 #include "chrp.h"
 17 
 18 static unsigned int nvram_size;
 19 static unsigned char nvram_buf[4];
 20 static DEFINE_SPINLOCK(nvram_lock);
 21 
 22 static unsigned char chrp_nvram_read_val(int addr)
 23 {
 24         unsigned int done;
 25         unsigned long flags;
 26         unsigned char ret;
 27 
 28         if (addr >= nvram_size) {
 29                 printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n",
 30                        current->comm, addr, nvram_size);
 31                 return 0xff;
 32         }
 33         spin_lock_irqsave(&nvram_lock, flags);
 34         if ((rtas_call(rtas_function_token(RTAS_FN_NVRAM_FETCH), 3, 2, &done, addr,
 35                        __pa(nvram_buf), 1) != 0) || 1 != done)
 36                 ret = 0xff;
 37         else
 38                 ret = nvram_buf[0];
 39         spin_unlock_irqrestore(&nvram_lock, flags);
 40 
 41         return ret;
 42 }
 43 
 44 static void chrp_nvram_write_val(int addr, unsigned char val)
 45 {
 46         unsigned int done;
 47         unsigned long 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 ((rtas_call(rtas_function_token(RTAS_FN_NVRAM_STORE), 3, 2, &done, addr,
 57                        __pa(nvram_buf), 1) != 0) || 1 != done)
 58                 printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr);
 59         spin_unlock_irqrestore(&nvram_lock, flags);
 60 }
 61 
 62 static ssize_t chrp_nvram_size(void)
 63 {
 64         return nvram_size;
 65 }
 66 
 67 void __init chrp_nvram_init(void)
 68 {
 69         struct device_node *nvram;
 70         const __be32 *nbytes_p;
 71         unsigned int proplen;
 72 
 73         nvram = of_find_node_by_type(NULL, "nvram");
 74         if (nvram == NULL)
 75                 return;
 76 
 77         nbytes_p = of_get_property(nvram, "#bytes", &proplen);
 78         if (nbytes_p == NULL || proplen != sizeof(unsigned int)) {
 79                 of_node_put(nvram);
 80                 return;
 81         }
 82 
 83         nvram_size = be32_to_cpup(nbytes_p);
 84 
 85         printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);
 86         of_node_put(nvram);
 87 
 88         ppc_md.nvram_read_val  = chrp_nvram_read_val;
 89         ppc_md.nvram_write_val = chrp_nvram_write_val;
 90         ppc_md.nvram_size      = chrp_nvram_size;
 91 
 92         return;
 93 }
 94 
 95 MODULE_DESCRIPTION("PPC NVRAM device driver");
 96 MODULE_LICENSE("GPL v2");
 97 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php