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

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/powernv/opal-nvram.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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  * PowerNV nvram code.
  4  *
  5  * Copyright 2011 IBM Corp.
  6  */
  7 
  8 #define DEBUG
  9 
 10 #include <linux/delay.h>
 11 #include <linux/kernel.h>
 12 #include <linux/init.h>
 13 #include <linux/of.h>
 14 
 15 #include <asm/opal.h>
 16 #include <asm/nvram.h>
 17 #include <asm/machdep.h>
 18 
 19 static unsigned int nvram_size;
 20 
 21 static ssize_t opal_nvram_size(void)
 22 {
 23         return nvram_size;
 24 }
 25 
 26 static ssize_t opal_nvram_read(char *buf, size_t count, loff_t *index)
 27 {
 28         s64 rc;
 29         int off;
 30 
 31         if (*index >= nvram_size)
 32                 return 0;
 33         off = *index;
 34         if ((off + count) > nvram_size)
 35                 count = nvram_size - off;
 36         rc = opal_read_nvram(__pa(buf), count, off);
 37         if (rc != OPAL_SUCCESS)
 38                 return -EIO;
 39         *index += count;
 40         return count;
 41 }
 42 
 43 /*
 44  * This can be called in the panic path with interrupts off, so use
 45  * mdelay in that case.
 46  */
 47 static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)
 48 {
 49         s64 rc = OPAL_BUSY;
 50         int off;
 51 
 52         if (*index >= nvram_size)
 53                 return 0;
 54         off = *index;
 55         if ((off + count) > nvram_size)
 56                 count = nvram_size - off;
 57 
 58         while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
 59                 rc = opal_write_nvram(__pa(buf), count, off);
 60                 if (rc == OPAL_BUSY_EVENT) {
 61                         if (in_interrupt() || irqs_disabled())
 62                                 mdelay(OPAL_BUSY_DELAY_MS);
 63                         else
 64                                 msleep(OPAL_BUSY_DELAY_MS);
 65                         opal_poll_events(NULL);
 66                 } else if (rc == OPAL_BUSY) {
 67                         if (in_interrupt() || irqs_disabled())
 68                                 mdelay(OPAL_BUSY_DELAY_MS);
 69                         else
 70                                 msleep(OPAL_BUSY_DELAY_MS);
 71                 }
 72         }
 73 
 74         if (rc)
 75                 return -EIO;
 76 
 77         *index += count;
 78         return count;
 79 }
 80 
 81 static int __init opal_nvram_init_log_partitions(void)
 82 {
 83         /* Scan nvram for partitions */
 84         nvram_scan_partitions();
 85         nvram_init_oops_partition(0);
 86         return 0;
 87 }
 88 machine_arch_initcall(powernv, opal_nvram_init_log_partitions);
 89 
 90 void __init opal_nvram_init(void)
 91 {
 92         struct device_node *np;
 93         const __be32 *nbytes_p;
 94 
 95         np = of_find_compatible_node(NULL, NULL, "ibm,opal-nvram");
 96         if (np == NULL)
 97                 return;
 98 
 99         nbytes_p = of_get_property(np, "#bytes", NULL);
100         if (!nbytes_p) {
101                 of_node_put(np);
102                 return;
103         }
104         nvram_size = be32_to_cpup(nbytes_p);
105 
106         pr_info("OPAL nvram setup, %u bytes\n", nvram_size);
107         of_node_put(np);
108 
109         ppc_md.nvram_read = opal_nvram_read;
110         ppc_md.nvram_write = opal_nvram_write;
111         ppc_md.nvram_size = opal_nvram_size;
112 }
113 
114 

~ [ 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