4 * Copyright 2011 IBM Corp.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
14 #include <linux/delay.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
20 #include <asm/nvram.h>
21 #include <asm/machdep.h>
23 static unsigned int nvram_size;
25 static ssize_t opal_nvram_size(void)
30 static ssize_t opal_nvram_read(char *buf, size_t count, loff_t *index)
35 if (*index >= nvram_size)
38 if ((off + count) > nvram_size)
39 count = nvram_size - off;
40 rc = opal_read_nvram(__pa(buf), count, off);
41 if (rc != OPAL_SUCCESS)
48 * This can be called in the panic path with interrupts off, so use
49 * mdelay in that case.
51 static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)
56 if (*index >= nvram_size)
59 if ((off + count) > nvram_size)
60 count = nvram_size - off;
62 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
63 rc = opal_write_nvram(__pa(buf), count, off);
64 if (rc == OPAL_BUSY_EVENT) {
65 if (in_interrupt() || irqs_disabled())
66 mdelay(OPAL_BUSY_DELAY_MS);
68 msleep(OPAL_BUSY_DELAY_MS);
69 opal_poll_events(NULL);
70 } else if (rc == OPAL_BUSY) {
71 if (in_interrupt() || irqs_disabled())
72 mdelay(OPAL_BUSY_DELAY_MS);
74 msleep(OPAL_BUSY_DELAY_MS);
85 static int __init opal_nvram_init_log_partitions(void)
87 /* Scan nvram for partitions */
88 nvram_scan_partitions();
89 nvram_init_oops_partition(0);
92 machine_arch_initcall(powernv, opal_nvram_init_log_partitions);
94 void __init opal_nvram_init(void)
96 struct device_node *np;
97 const __be32 *nbytes_p;
99 np = of_find_compatible_node(NULL, NULL, "ibm,opal-nvram");
103 nbytes_p = of_get_property(np, "#bytes", NULL);
108 nvram_size = be32_to_cpup(nbytes_p);
110 pr_info("OPAL nvram setup, %u bytes\n", nvram_size);
113 ppc_md.nvram_read = opal_nvram_read;
114 ppc_md.nvram_write = opal_nvram_write;
115 ppc_md.nvram_size = opal_nvram_size;