From patchwork Sun Jul 12 10:25:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Finn Thain X-Patchwork-Id: 494079 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0F5AC1402A5 for ; Sun, 12 Jul 2015 20:48:30 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id E82B31A2B47 for ; Sun, 12 Jul 2015 20:48:29 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from kvm5.telegraphics.com.au (kvm5.telegraphics.com.au [98.124.60.144]) by lists.ozlabs.org (Postfix) with ESMTP id CE6AE1A0216 for ; Sun, 12 Jul 2015 20:40:40 +1000 (AEST) Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id CC6E927FEE; Sun, 12 Jul 2015 06:40:34 -0400 (EDT) Message-Id: <20150712102528.835913476@telegraphics.com.au> User-Agent: quilt/0.50-1 Date: Sun, 12 Jul 2015 20:25:33 +1000 From: Finn Thain To: , , , Arnd Bergmann , Greg Kroah-Hartman Subject: [RFC v4 06/25] char/nvram: Adopt arch_nvram_ops References: <20150712102527.356151908@telegraphics.com.au> Content-Disposition: inline; filename=nvram-adopt-nvram_ops X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Different platforms and architectures offer different NVRAM sizes and access methods. E.g. PPC32 has byte-at-a-time read/write functions whereas PPC64 has byte-range read/write functions. Adopt the nvram_ops struct so the nvram module can call such functions as are defined by the various platforms and architectures. Signed-off-by: Finn Thain --- The #ifdefs here restrict the procfs and checksumming code to those architectures with PC-style RTC NVRAM. There may be a better place for that code but it's an open question. See https://lkml.org/lkml/2015/2/3/22 The procfs code here, unless relevant to an ARM platform, could be moved to arch/x86 (like the earlier patch does for m68k code) and the nvram ops could be implemented and exported by the rtc-cmos driver instead. This would eliminate these #ifdefs and almost eliminate the arch-specific code. --- drivers/char/nvram.c | 30 +++++++++++++++++++++++++++--- include/linux/nvram.h | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-) Index: linux/drivers/char/nvram.c =================================================================== --- linux.orig/drivers/char/nvram.c 2015-07-12 20:24:59.000000000 +1000 +++ linux/drivers/char/nvram.c 2015-07-12 20:25:00.000000000 +1000 @@ -51,9 +51,12 @@ static DEFINE_MUTEX(nvram_mutex); static DEFINE_SPINLOCK(nvram_state_lock); static int nvram_open_cnt; /* #times opened */ static int nvram_open_mode; /* special open modes */ +static ssize_t nvram_size; #define NVRAM_WRITE 1 /* opened for writing (exclusive) */ #define NVRAM_EXCL 2 /* opened with O_EXCL */ +#if defined(CONFIG_X86) || defined(CONFIG_ARM) + /* * These functions are provided to be called internally or by other parts of * the kernel. It's up to the caller to ensure correct checksum before reading @@ -161,6 +164,20 @@ void nvram_set_checksum(void) } #endif /* 0 */ +static ssize_t nvram_get_size(void) +{ + return NVRAM_BYTES; +} + +const struct nvram_ops arch_nvram_ops = { + .read_byte = nvram_read_byte, + .write_byte = nvram_write_byte, + .get_size = nvram_get_size, +}; +EXPORT_SYMBOL(arch_nvram_ops); + +#endif /* CONFIG_X86 || CONFIG_ARM */ + /* * The are the file operation function for user access to /dev/nvram */ @@ -332,7 +349,7 @@ static int nvram_misc_release(struct ino return 0; } -#ifdef CONFIG_PROC_FS +#if defined(CONFIG_PROC_FS) && (defined(CONFIG_X86) || defined(CONFIG_ARM)) static char *floppy_types[] = { "none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M", @@ -459,13 +476,20 @@ static int __init nvram_module_init(void { int ret; + if (arch_nvram_ops.get_size == NULL) + return -ENODEV; + + nvram_size = arch_nvram_ops.get_size(); + if (nvram_size < 0) + return nvram_size; + ret = misc_register(&nvram_misc); if (ret) { pr_err("nvram: can't misc_register on minor=%d\n", NVRAM_MINOR); return ret; } -#ifdef CONFIG_PROC_FS +#if defined(CONFIG_PROC_FS) && (defined(CONFIG_X86) || defined(CONFIG_ARM)) if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops)) { pr_err("nvram: can't create /proc/driver/nvram\n"); misc_deregister(&nvram_misc); @@ -479,7 +503,7 @@ static int __init nvram_module_init(void static void __exit nvram_module_exit(void) { -#ifdef CONFIG_PROC_FS +#if defined(CONFIG_PROC_FS) && (defined(CONFIG_X86) || defined(CONFIG_ARM)) remove_proc_entry("driver/nvram", NULL); #endif misc_deregister(&nvram_misc); Index: linux/include/linux/nvram.h =================================================================== --- linux.orig/include/linux/nvram.h 2015-07-12 20:24:58.000000000 +1000 +++ linux/include/linux/nvram.h 2015-07-12 20:25:00.000000000 +1000 @@ -14,6 +14,8 @@ extern int nvram_check_checksum(void); struct nvram_ops { ssize_t (*read)(char *, size_t, loff_t *); ssize_t (*write)(char *, size_t, loff_t *); + unsigned char (*read_byte)(int); + void (*write_byte)(unsigned char, int); ssize_t (*get_size)(void); };