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/kernel.h>
15 #include <linux/init.h>
19 #include <asm/nvram.h>
20 #include <asm/machdep.h>
22 static unsigned int nvram_size
;
24 static ssize_t
opal_nvram_size(void)
29 static ssize_t
opal_nvram_read(char *buf
, size_t count
, loff_t
*index
)
34 if (*index
>= nvram_size
)
37 if ((off
+ count
) > nvram_size
)
38 count
= nvram_size
- off
;
39 rc
= opal_read_nvram(__pa(buf
), count
, off
);
40 if (rc
!= OPAL_SUCCESS
)
46 static ssize_t
opal_nvram_write(char *buf
, size_t count
, loff_t
*index
)
51 if (*index
>= nvram_size
)
54 if ((off
+ count
) > nvram_size
)
55 count
= nvram_size
- off
;
57 while (rc
== OPAL_BUSY
|| rc
== OPAL_BUSY_EVENT
) {
58 rc
= opal_write_nvram(__pa(buf
), count
, off
);
59 if (rc
== OPAL_BUSY_EVENT
)
60 opal_poll_events(NULL
);
66 static int __init
opal_nvram_init_log_partitions(void)
68 /* Scan nvram for partitions */
69 nvram_scan_partitions();
70 nvram_init_oops_partition(0);
73 machine_arch_initcall(powernv
, opal_nvram_init_log_partitions
);
75 void __init
opal_nvram_init(void)
77 struct device_node
*np
;
78 const __be32
*nbytes_p
;
80 np
= of_find_compatible_node(NULL
, NULL
, "ibm,opal-nvram");
84 nbytes_p
= of_get_property(np
, "#bytes", NULL
);
89 nvram_size
= be32_to_cpup(nbytes_p
);
91 pr_info("OPAL nvram setup, %u bytes\n", nvram_size
);
94 ppc_md
.nvram_read
= opal_nvram_read
;
95 ppc_md
.nvram_write
= opal_nvram_write
;
96 ppc_md
.nvram_size
= opal_nvram_size
;