Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4322759imu; Mon, 14 Jan 2019 20:30:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN7BOl/KEX6UIk2QfLYut+1cgvZlN9Eq+MW4YsJGf2iv+llx82p0V/lcHMSVCDWK8O+sXaDB X-Received: by 2002:a65:4ccb:: with SMTP id n11mr2016658pgt.257.1547526610206; Mon, 14 Jan 2019 20:30:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547526610; cv=none; d=google.com; s=arc-20160816; b=U1UriviAWPlJl11iUjatf8f66uPRAOOU3lpUqJ+Uo95CN97qV5t7xBxJIzU66273/n ZfQjEFkx+7Svi8hKZCOX7jAWVBkbjOd2v/vRCPXF3RG3ELKsKPv68oyHZB2Zp2UtHjus JAs1vz7oJf7BOEEamuMWZeWoh+QOBAq87IGyQDb13TLL1m55NHAQ/OENddzxmovlnUQT vekJvnLt8+KgQ3fXOXRE+Vuzxk3JTtpCU4pHtE1C92Ijkzg9FcYBzQaeyCU0H+YB7QyC hGSYJR1ICLg/1cIYtqALDhmeRruKIThHMxHc2aGaZPEDUsAI8AgE2C/VhHu+VojxPJNf PBRw== 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=0UGENO5AAWjrPBnLaBgCIp2Hnpdqd3r4o5gSbDccy+I=; b=Afl7ewCIgSGJ+0jDTQcWa5eEHapYDbCw65ZnDAmrFs/e/sGLIIWBVz5+IL8pA+ep07 cScIXZtiCLvsKaVHnjNABfTuLtNSIKeur3Z4E36aqCza+y507WqBkBzkDdOrnFMLENWQ c/u//qitqpmG6Uq49XFO96xDkSxP7mb9CtPGseUaAA2kpwiM4xLZrS0UH1Emu3bKeZ1r 1+WH21twbEcQKdEmAjFYheYazf9SXH1b4602BiXKCzLFpGsPewW2aSmK4g8nr2WghXSj ClqA3Bkl3Se4nW+ynC7vK0PPo0adkaIictf4CoxXLLHO9LmRpJ+i834Yi0HOGX6TRxLj d0Zg== 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 s24si2189660plq.41.2019.01.14.20.29.54; Mon, 14 Jan 2019 20:30:10 -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 S1727289AbfAOEYX (ORCPT + 99 others); Mon, 14 Jan 2019 23:24:23 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:37460 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbfAOEWZ (ORCPT ); Mon, 14 Jan 2019 23:22:25 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 08A7129E65; Mon, 14 Jan 2019 23:22:24 -0500 (EST) To: Arnd Bergmann , Greg Kroah-Hartman , Geert Uytterhoeven Cc: linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linuxppc-dev@lists.ozlabs.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v9 05/22] m68k/atari: Implement arch_nvram_ops struct Date: Tue, 15 Jan 2019 15:18:56 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By implementing an arch_nvram_ops struct, a platform can re-use the drivers/char/nvram.c module without needing any arch-specific code in that module. Atari does so here. Acked-by: Geert Uytterhoeven Signed-off-by: Finn Thain --- Changed since v8: - Added static inline wrapper functions to nvram.h. - Removed excess whitespace. - Renamed functions to avoid collisions with nvram.h wrapper functions. - Moved nvram_check_checksum() changes to the preceding patch. --- arch/m68k/atari/nvram.c | 49 +++++++++++++++++++++++++++++++++++++++++ include/linux/nvram.h | 14 ++++++++++++ 2 files changed, 63 insertions(+) diff --git a/arch/m68k/atari/nvram.c b/arch/m68k/atari/nvram.c index 1d767847ffa6..e75adebe6e7d 100644 --- a/arch/m68k/atari/nvram.c +++ b/arch/m68k/atari/nvram.c @@ -74,6 +74,55 @@ static void __nvram_set_checksum(void) __nvram_write_byte(sum, ATARI_CKS_LOC + 1); } +static ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos) +{ + char *p = buf; + loff_t i; + + spin_lock_irq(&rtc_lock); + if (!__nvram_check_checksum()) { + spin_unlock_irq(&rtc_lock); + return -EIO; + } + for (i = *ppos; count > 0 && i < NVRAM_BYTES; --count, ++i, ++p) + *p = __nvram_read_byte(i); + spin_unlock_irq(&rtc_lock); + + *ppos = i; + return p - buf; +} + +static ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos) +{ + char *p = buf; + loff_t i; + + spin_lock_irq(&rtc_lock); + if (!__nvram_check_checksum()) { + spin_unlock_irq(&rtc_lock); + return -EIO; + } + for (i = *ppos; count > 0 && i < NVRAM_BYTES; --count, ++i, ++p) + __nvram_write_byte(*p, i); + __nvram_set_checksum(); + spin_unlock_irq(&rtc_lock); + + *ppos = i; + return p - buf; +} + +static ssize_t atari_nvram_get_size(void) +{ + return NVRAM_BYTES; +} + +const struct nvram_ops arch_nvram_ops = { + .read = atari_nvram_read, + .write = atari_nvram_write, + .get_size = atari_nvram_get_size, +}; +EXPORT_SYMBOL(arch_nvram_ops); + #ifdef CONFIG_PROC_FS static struct { unsigned char val; diff --git a/include/linux/nvram.h b/include/linux/nvram.h index eb5b52a9a747..a1e01dc89759 100644 --- a/include/linux/nvram.h +++ b/include/linux/nvram.h @@ -5,8 +5,18 @@ #include #include +struct nvram_ops { + ssize_t (*get_size)(void); + ssize_t (*read)(char *, size_t, loff_t *); + ssize_t (*write)(char *, size_t, loff_t *); +}; + +extern const struct nvram_ops arch_nvram_ops; + static inline ssize_t nvram_get_size(void) { + if (arch_nvram_ops.get_size) + return arch_nvram_ops.get_size(); return -ENODEV; } @@ -21,11 +31,15 @@ static inline void nvram_write_byte(unsigned char val, int addr) static inline ssize_t nvram_read(char *buf, size_t count, loff_t *ppos) { + if (arch_nvram_ops.read) + return arch_nvram_ops.read(buf, count, ppos); return -ENODEV; } static inline ssize_t nvram_write(char *buf, size_t count, loff_t *ppos) { + if (arch_nvram_ops.write) + return arch_nvram_ops.write(buf, count, ppos); return -ENODEV; } -- 2.19.2