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

TOMOYO Linux Cross Reference
Linux/arch/ppc64/kernel/nvram.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.12 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.55 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.136 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.191 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 PPC64
 10  *
 11  * This perhaps should live in drivers/char
 12  */
 13 
 14 #include <linux/module.h>
 15 
 16 #include <linux/types.h>
 17 #include <linux/errno.h>
 18 #include <linux/fs.h>
 19 #include <linux/miscdevice.h>
 20 #include <linux/fcntl.h>
 21 #include <linux/nvram.h>
 22 #include <linux/init.h>
 23 #include <asm/uaccess.h>
 24 #include <asm/nvram.h>
 25 #include <asm/rtas.h>
 26 #include <asm/prom.h>
 27 
 28 static unsigned int rtas_nvram_size;
 29 static unsigned int nvram_fetch, nvram_store;
 30 static char nvram_buf[4];       /* assume this is in the first 4GB */
 31 
 32 static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
 33 {
 34         switch (origin) {
 35         case 1:
 36                 offset += file->f_pos;
 37                 break;
 38         case 2:
 39                 offset += rtas_nvram_size;
 40                 break;
 41         }
 42         if (offset < 0)
 43                 return -EINVAL;
 44         file->f_pos = offset;
 45         return file->f_pos;
 46 }
 47 
 48 
 49 static ssize_t read_nvram(struct file *file, char *buf,
 50                           size_t count, loff_t *ppos)
 51 {
 52         unsigned int i;
 53         unsigned long len;
 54         char *p = buf;
 55 
 56         if (verify_area(VERIFY_WRITE, buf, count))
 57                 return -EFAULT;
 58         if (*ppos >= rtas_nvram_size)
 59                 return 0;
 60         for (i = *ppos; count > 0 && i < rtas_nvram_size; ++i, ++p, --count) {
 61                 if ((rtas_call(nvram_fetch, 3, 2, &len, i, __pa(nvram_buf), 1) != 0) ||
 62                     len != 1)
 63                         return -EIO;
 64                 if (__put_user(nvram_buf[0], p))
 65                         return -EFAULT;
 66         }
 67         *ppos = i;
 68         return p - buf;
 69 }
 70 
 71 static ssize_t write_nvram(struct file *file, const char *buf,
 72                            size_t count, loff_t *ppos)
 73 {
 74         unsigned int i;
 75         unsigned long len;
 76         const char *p = buf;
 77         char c;
 78 
 79         if (verify_area(VERIFY_READ, buf, count))
 80                 return -EFAULT;
 81         if (*ppos >= rtas_nvram_size)
 82                 return 0;
 83         for (i = *ppos; count > 0 && i < rtas_nvram_size; ++i, ++p, --count) {
 84                 if (__get_user(c, p))
 85                         return -EFAULT;
 86                 nvram_buf[0] = c;
 87                 if ((rtas_call(nvram_store, 3, 2, &len, i, __pa(nvram_buf), 1) != 0) ||
 88                     len != 1)
 89                         return -EIO;
 90         }
 91         *ppos = i;
 92         return p - buf;
 93 }
 94 
 95 static int nvram_ioctl(struct inode *inode, struct file *file,
 96         unsigned int cmd, unsigned long arg)
 97 {
 98         return -EINVAL;
 99 }
100 
101 struct file_operations nvram_fops = {
102         .owner =        THIS_MODULE,
103         .llseek =       nvram_llseek,
104         .read =         read_nvram,
105         .write =        write_nvram,
106         .ioctl =        nvram_ioctl,
107 };
108 
109 static struct miscdevice nvram_dev = {
110         NVRAM_MINOR,
111         "nvram",
112         &nvram_fops
113 };
114 
115 int __init nvram_init(void)
116 {
117         struct device_node *nvram;
118         unsigned int *nbytes_p, proplen;
119         if ((nvram = find_type_devices("nvram")) != NULL) {
120                 nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen);
121                 if (nbytes_p && proplen == sizeof(unsigned int)) {
122                         rtas_nvram_size = *nbytes_p;
123                 }
124         }
125         nvram_fetch = rtas_token("nvram-fetch");
126         nvram_store = rtas_token("nvram-store");
127         printk(KERN_INFO "PPC64 nvram contains %d bytes\n", rtas_nvram_size);
128 
129         return misc_register(&nvram_dev);
130 }
131 
132 void __exit nvram_cleanup(void)
133 {
134         misc_deregister( &nvram_dev );
135 }
136 
137 module_init(nvram_init);
138 module_exit(nvram_cleanup);
139 MODULE_LICENSE("GPL");
140 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp