Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5061855imu; Tue, 25 Dec 2018 16:52:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Gse9GGiK5N7j9ztwH7IZlVJDm/DfM0LYWqAl7D0PYb0xcX+S9mZsBNqeCKMrsFcJzgOlP X-Received: by 2002:a17:902:5588:: with SMTP id g8mr18009103pli.22.1545785523813; Tue, 25 Dec 2018 16:52:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545785523; cv=none; d=google.com; s=arc-20160816; b=G/PH3LrMAdSUaI8MQnqo/esNPNsVZADY++X9t2bRIOvZSb14DAssteZ362kU8aZ/tc gMSPa+eCeFXFxqX5NtLDZEd65NTobUZF58apVsYOBwfywJUfgUtzqEXkEJTcVnI/EDIz Oy/EVgN7q86yfWUa1xYVKIaYWXD4U4cZCwXoKkXOC8J9Do+TXpmdiU4lTzqIPFrayYsS XputdpkitxwPI1XEp47m5eHLeMJdjAHHzGkZJyV/7HoL6lYfw5xwHywQR7DZAtvWxQqJ mhHQN8nXuPu0abGwLj4m+dHdfYYx2536vPCY3Ffkz10aeiYMNZAKIXOXh9jIFkegjh9w XEgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:from:references:in-reply-to :message-id:cc:to; bh=fvfxEW9ZIMxYM4raOJwDxpWXssGmDvmazpK/WoFgBJM=; b=Vy+514HAoX8FpmDCm3Xyjz4fQVhySv2Vj5Wvx9UoS8HeNefQu6uEHCSiEop3+hsViu t2/Zh42HeB+ky17t9jqrnTqYilTdetCxzPxqbN9roQqeN1BKEk/WyFGjkcPkeVTIR6xt qiGqe91UV6Y70KyAV/9EQQSW3pXmNOU9i4ft24hKyZrKfQme27PHwEmZIOW4h9UkGw+l dUOZFNPcLG+SSXpuoppyewzjUrOXfaVDT1bNsiNsDwn7tBSCVCnn4EFTKbcdlQ7j66OH EiqbpmY1NxCf6p5VDJ6lcs/zP0/tkw3Ww07i/H1YthV310X0IYLkupaQs0WSsN1O+qqL 2p6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v61si9092270plb.54.2018.12.25.16.51.49; Tue, 25 Dec 2018 16:52:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729601AbeLZAoC (ORCPT + 99 others); Tue, 25 Dec 2018 19:44:02 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:57326 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725981AbeLZAoA (ORCPT ); Tue, 25 Dec 2018 19:44:00 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id CF53A29515; Tue, 25 Dec 2018 19:43:55 -0500 (EST) To: Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linuxppc-dev@lists.ozlabs.org Message-Id: <66ed571883695314ace53080df8f6dfb132a8b4d.1545784679.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v8 05/25] char/nvram: Adopt arch_nvram_ops Date: Wed, 26 Dec 2018 11:37:59 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Different platforms and architectures offer different NVRAM sizes and access methods. E.g. PPC32 has byte-at-a-time accessor functions whereas PPC64 has byte-range accessor 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 procfs code here could be moved to arch/x86 (like the earlier patch did for m68k code that was here). The nvram_ops struct could be implemented and exported by the rtc-cmos driver instead, to eliminate the remaining #ifdefs. --- drivers/char/nvram.c | 33 +++++++++++++++++++++++++++------ include/linux/nvram.h | 2 ++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index c660cff9faf4..00897daa0643 100644 --- a/drivers/char/nvram.c +++ b/drivers/char/nvram.c @@ -52,9 +52,11 @@ 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 */ +#ifdef CONFIG_X86 /* * 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 @@ -162,6 +164,19 @@ 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 */ + /* * The are the file operation function for user access to /dev/nvram */ @@ -169,7 +184,7 @@ void nvram_set_checksum(void) static loff_t nvram_misc_llseek(struct file *file, loff_t offset, int origin) { return generic_file_llseek_size(file, offset, origin, MAX_LFS_FILESIZE, - NVRAM_BYTES); + nvram_size); } static ssize_t nvram_misc_read(struct file *file, char __user *buf, @@ -320,8 +335,7 @@ static int nvram_misc_release(struct inode *inode, struct file *file) return 0; } -#ifdef CONFIG_PROC_FS - +#if defined(CONFIG_X86) && defined(CONFIG_PROC_FS) static const char * const floppy_types[] = { "none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M", "3.5'' 2.88M", "3.5'' 2.88M" @@ -411,7 +425,7 @@ static int nvram_proc_read(struct seq_file *seq, void *offset) return 0; } -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_X86 && CONFIG_PROC_FS */ static const struct file_operations nvram_misc_fops = { .owner = THIS_MODULE, @@ -433,13 +447,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_X86) && defined(CONFIG_PROC_FS) if (!proc_create_single("driver/nvram", 0, NULL, nvram_proc_read)) { pr_err("nvram: can't create /proc/driver/nvram\n"); misc_deregister(&nvram_misc); @@ -453,7 +474,7 @@ static int __init nvram_module_init(void) static void __exit nvram_module_exit(void) { -#ifdef CONFIG_PROC_FS +#if defined(CONFIG_X86) && defined(CONFIG_PROC_FS) remove_proc_entry("driver/nvram", NULL); #endif misc_deregister(&nvram_misc); diff --git a/include/linux/nvram.h b/include/linux/nvram.h index 4f78147e74d9..d1bdee50d6a8 100644 --- a/include/linux/nvram.h +++ b/include/linux/nvram.h @@ -15,6 +15,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); }; -- 2.19.2