[PATCH v8 17/25] powerpc: Implement arch_nvram_ops.get_size() and remove old nvram_* exports

From: Finn Thain
Date: Tue Dec 25 2018 - 19:45:34 EST


Implement arch_nvram_ops for PPC32 and make use of it in the generic_nvram
misc device module so that the nvram_* function exports can be removed.

Signed-off-by: Finn Thain <fthain@xxxxxxxxxxxxxxxxxxx>
Tested-by: Stan Johnson <userm57@xxxxxxxxx>
---
arch/powerpc/include/asm/nvram.h | 3 ---
arch/powerpc/kernel/setup_32.c | 10 +++++++---
drivers/char/generic_nvram.c | 24 ++++++++++++------------
3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/include/asm/nvram.h b/arch/powerpc/include/asm/nvram.h
index 1443b40f44b9..56a388da9c4f 100644
--- a/arch/powerpc/include/asm/nvram.h
+++ b/arch/powerpc/include/asm/nvram.h
@@ -98,7 +98,4 @@ extern int nvram_write_os_partition(struct nvram_os_partition *part,
unsigned int err_type,
unsigned int error_log_cnt);

-/* Determine NVRAM size */
-extern ssize_t nvram_get_size(void);
-
#endif /* _ASM_POWERPC_NVRAM_H */
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 04c0315cfe46..ee91bba0805d 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -168,13 +168,12 @@ void nvram_write_byte(unsigned char val, int addr)
}
EXPORT_SYMBOL(nvram_write_byte);

-ssize_t nvram_get_size(void)
+static ssize_t ppc_nvram_get_size(void)
{
if (ppc_md.nvram_size)
return ppc_md.nvram_size();
- return -1;
+ return -ENODEV;
}
-EXPORT_SYMBOL(nvram_get_size);

void nvram_sync(void)
{
@@ -183,6 +182,11 @@ void nvram_sync(void)
}
EXPORT_SYMBOL(nvram_sync);

+const struct nvram_ops arch_nvram_ops = {
+ .get_size = ppc_nvram_get_size,
+};
+EXPORT_SYMBOL(arch_nvram_ops);
+
#endif /* CONFIG_NVRAM */

static int __init ppc_init(void)
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index 0381af638fe3..a7dfde734897 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -28,8 +28,6 @@
#include <asm/machdep.h>
#endif

-#define NVRAM_SIZE 8192
-
static DEFINE_MUTEX(nvram_mutex);
static ssize_t nvram_len;

@@ -134,20 +132,22 @@ static struct miscdevice nvram_dev = {

int __init nvram_init(void)
{
- int ret = 0;
+ int ret;

- printk(KERN_INFO "Generic non-volatile memory driver v%s\n",
- NVRAM_VERSION);
- ret = misc_register(&nvram_dev);
- if (ret != 0)
- goto out;
+ if (arch_nvram_ops.get_size == NULL)
+ return -ENODEV;

- nvram_len = nvram_get_size();
+ nvram_len = arch_nvram_ops.get_size();
if (nvram_len < 0)
- nvram_len = NVRAM_SIZE;
+ return nvram_len;

-out:
- return ret;
+ ret = misc_register(&nvram_dev);
+ if (ret)
+ return ret;
+
+ pr_info("Generic non-volatile memory driver v%s\n", NVRAM_VERSION);
+
+ return 0;
}

void __exit nvram_cleanup(void)
--
2.19.2