Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4320492imu; Mon, 14 Jan 2019 20:26:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN5zn1hX3pHMqMH/BsWHdFHbhJFYuoNIxPTCfwuJBI+edOnCQVB5cpWXWmihFEbG/pLKF1pu X-Received: by 2002:a17:902:3181:: with SMTP id x1mr2123001plb.58.1547526386791; Mon, 14 Jan 2019 20:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547526386; cv=none; d=google.com; s=arc-20160816; b=gygxfAknauArvCETmLDDDzbUDvrKo4zP8JHCGM2tBYGAf32T7VtT2MVhq+xQ79PcCy xeMnqh669VYgIx5gwJxDVI//nPNSOj+5ektbjpYscikQILXpvvF1ZZu/CDxkrIuQT3Ff gymlVEPSv6Uc307nKC2A4Oilq33vJyP5Wjc58qgMYfGxTu/ObWlZvqdiKD2cGBjNyD/J 2NlLYEe/4BBq3qGFdqdh1lEvhz2AoFq24bPOz8r6grEZyaYreI0JUsRO8Q3xa6uTP+6A E2Mnmkm9WttvkI3skTfv0s8snNZ5RVdK4nPRqVVY3T9LG9SUp1vLtzKZJ6pJZqlzp4F2 HLFA== 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=cW1O+/ZlaNEaKmKBqnyyx4qc8SZW9dyVqCJHlQE+TnU=; b=0kDsFVP1RGFEo+InFZ/03J1kCci9aaimm6KpXUyBXMHd8W0k2TR8MKegEbpG5VWMH7 MWvmPDc5wIpCSBmUe9ygxN0v1eYSBE9FQHgAvU0g1VGPkA1brJB7JIltBLmDMyfhE0h6 wjFBWTIvCMpsVgPBcRSN5igeM9dSqgDq6xoPIKg9KvkKWgzCRtRQ0G3CpymrxdGO1EdZ Ft0vLATEZy6SK99TJ83xYycqOletYUZvSoMnDZ2ZR6mLC1hymT7WVZxj8gMl2xDrImfR acJqbEzk4QVsP6sULWbKzH3fe27foPr7HO4Y/mGi+53WittB2heJWpIOUMGuxu7RD/v/ oGXQ== 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 d82si2169505pfj.124.2019.01.14.20.26.11; Mon, 14 Jan 2019 20:26:26 -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 S1728207AbfAOEWw (ORCPT + 99 others); Mon, 14 Jan 2019 23:22:52 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:37574 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728215AbfAOEW3 (ORCPT ); Mon, 14 Jan 2019 23:22:29 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 9136929E7F; Mon, 14 Jan 2019 23:22:24 -0500 (EST) To: Arnd Bergmann , Greg Kroah-Hartman , Geert Uytterhoeven , Joshua Thompson 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 15/22] m68k: Dispatch nvram_ops calls to Atari or Mac functions 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 A multi-platform kernel binary has to decide at run-time how to dispatch the arch_nvram_ops calls. Add a platform-independent arch_nvram_ops struct for this, to replace the atari-specific one. Enable CONFIG_HAVE_ARCH_NVRAM_OPS for Macs. Acked-by: Geert Uytterhoeven Tested-by: Stan Johnson Signed-off-by: Finn Thain --- Changed since v8: - Adopted nvram_read_bytes() and nvram_write_bytes() where possible. --- arch/m68k/Kconfig.machine | 1 + arch/m68k/atari/nvram.c | 21 ++------ arch/m68k/include/asm/atarihw.h | 6 +++ arch/m68k/include/asm/macintosh.h | 4 ++ arch/m68k/kernel/setup_mm.c | 82 ++++++++++++++++++++++++++++++- arch/m68k/mac/misc.c | 11 +++++ 6 files changed, 108 insertions(+), 17 deletions(-) diff --git a/arch/m68k/Kconfig.machine b/arch/m68k/Kconfig.machine index ad584e3eb8f7..c01e103492fd 100644 --- a/arch/m68k/Kconfig.machine +++ b/arch/m68k/Kconfig.machine @@ -27,6 +27,7 @@ config MAC bool "Macintosh support" depends on MMU select MMU_MOTOROLA if MMU + select HAVE_ARCH_NVRAM_OPS help This option enables support for the Apple Macintosh series of computers (yes, there is experimental support now, at least for part diff --git a/arch/m68k/atari/nvram.c b/arch/m68k/atari/nvram.c index c347fd206ddf..7000d2443aa3 100644 --- a/arch/m68k/atari/nvram.c +++ b/arch/m68k/atari/nvram.c @@ -74,7 +74,7 @@ static void __nvram_set_checksum(void) __nvram_write_byte(sum, ATARI_CKS_LOC + 1); } -static long atari_nvram_set_checksum(void) +long atari_nvram_set_checksum(void) { spin_lock_irq(&rtc_lock); __nvram_set_checksum(); @@ -82,7 +82,7 @@ static long atari_nvram_set_checksum(void) return 0; } -static long atari_nvram_initialize(void) +long atari_nvram_initialize(void) { loff_t i; @@ -94,7 +94,7 @@ static long atari_nvram_initialize(void) return 0; } -static ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos) +ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos) { char *p = buf; loff_t i; @@ -112,7 +112,7 @@ static ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos) return p - buf; } -static ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos) +ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos) { char *p = buf; loff_t i; @@ -131,22 +131,11 @@ static ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos) return p - buf; } -static ssize_t atari_nvram_get_size(void) +ssize_t atari_nvram_get_size(void) { - if (!MACH_IS_ATARI) - return -ENODEV; return NVRAM_BYTES; } -const struct nvram_ops arch_nvram_ops = { - .read = atari_nvram_read, - .write = atari_nvram_write, - .get_size = atari_nvram_get_size, - .set_checksum = atari_nvram_set_checksum, - .initialize = atari_nvram_initialize, -}; -EXPORT_SYMBOL(arch_nvram_ops); - #ifdef CONFIG_PROC_FS static struct { unsigned char val; diff --git a/arch/m68k/include/asm/atarihw.h b/arch/m68k/include/asm/atarihw.h index 9000b249d225..533008262b69 100644 --- a/arch/m68k/include/asm/atarihw.h +++ b/arch/m68k/include/asm/atarihw.h @@ -33,6 +33,12 @@ extern int atari_dont_touch_floppy_select; extern int atari_SCC_reset_done; +extern ssize_t atari_nvram_read(char *, size_t, loff_t *); +extern ssize_t atari_nvram_write(char *, size_t, loff_t *); +extern ssize_t atari_nvram_get_size(void); +extern long atari_nvram_set_checksum(void); +extern long atari_nvram_initialize(void); + /* convenience macros for testing machine type */ #define MACH_IS_ST ((atari_mch_cookie >> 16) == ATARI_MCH_ST) #define MACH_IS_STE ((atari_mch_cookie >> 16) == ATARI_MCH_STE && \ diff --git a/arch/m68k/include/asm/macintosh.h b/arch/m68k/include/asm/macintosh.h index 08cee11180e6..d9a08bed4b12 100644 --- a/arch/m68k/include/asm/macintosh.h +++ b/arch/m68k/include/asm/macintosh.h @@ -19,6 +19,10 @@ extern void mac_init_IRQ(void); extern void mac_irq_enable(struct irq_data *data); extern void mac_irq_disable(struct irq_data *data); +extern unsigned char mac_pram_read_byte(int); +extern void mac_pram_write_byte(unsigned char, int); +extern ssize_t mac_pram_get_size(void); + /* * Macintosh Table */ diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c index ad0195cbe042..528484feff80 100644 --- a/arch/m68k/kernel/setup_mm.c +++ b/arch/m68k/kernel/setup_mm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -37,13 +38,14 @@ #ifdef CONFIG_AMIGA #include #endif -#ifdef CONFIG_ATARI #include +#ifdef CONFIG_ATARI #include #endif #ifdef CONFIG_SUN3X #include #endif +#include #include #if !FPSTATESIZE || !NR_IRQS @@ -547,3 +549,81 @@ static int __init adb_probe_sync_enable (char *str) { __setup("adb_sync", adb_probe_sync_enable); #endif /* CONFIG_ADB */ + +#if IS_ENABLED(CONFIG_NVRAM) +#ifdef CONFIG_MAC +static unsigned char m68k_nvram_read_byte(int addr) +{ + if (MACH_IS_MAC) + return mac_pram_read_byte(addr); + return 0xff; +} + +static void m68k_nvram_write_byte(unsigned char val, int addr) +{ + if (MACH_IS_MAC) + mac_pram_write_byte(val, addr); +} +#endif /* CONFIG_MAC */ + +#ifdef CONFIG_ATARI +static ssize_t m68k_nvram_read(char *buf, size_t count, loff_t *ppos) +{ + if (MACH_IS_ATARI) + return atari_nvram_read(buf, count, ppos); + else if (MACH_IS_MAC) + return nvram_read_bytes(buf, count, ppos); + return -EINVAL; +} + +static ssize_t m68k_nvram_write(char *buf, size_t count, loff_t *ppos) +{ + if (MACH_IS_ATARI) + return atari_nvram_write(buf, count, ppos); + else if (MACH_IS_MAC) + return nvram_write_bytes(buf, count, ppos); + return -EINVAL; +} + +static long m68k_nvram_set_checksum(void) +{ + if (MACH_IS_ATARI) + return atari_nvram_set_checksum(); + return -EINVAL; +} + +static long m68k_nvram_initialize(void) +{ + if (MACH_IS_ATARI) + return atari_nvram_initialize(); + return -EINVAL; +} +#endif /* CONFIG_ATARI */ + +static ssize_t m68k_nvram_get_size(void) +{ + if (MACH_IS_ATARI) + return atari_nvram_get_size(); + else if (MACH_IS_MAC) + return mac_pram_get_size(); + return -ENODEV; +} + +/* Atari device drivers call .read (to get checksum validation) whereas + * Mac and PowerMac device drivers just use .read_byte. + */ +const struct nvram_ops arch_nvram_ops = { +#ifdef CONFIG_MAC + .read_byte = m68k_nvram_read_byte, + .write_byte = m68k_nvram_write_byte, +#endif +#ifdef CONFIG_ATARI + .read = m68k_nvram_read, + .write = m68k_nvram_write, + .set_checksum = m68k_nvram_set_checksum, + .initialize = m68k_nvram_initialize, +#endif + .get_size = m68k_nvram_get_size, +}; +EXPORT_SYMBOL(arch_nvram_ops); +#endif /* CONFIG_NVRAM */ diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c index d016ca2e0d10..5dc8d1e985e7 100644 --- a/arch/m68k/mac/misc.c +++ b/arch/m68k/mac/misc.c @@ -36,6 +36,7 @@ static void (*rom_reset)(void); +#if IS_ENABLED(CONFIG_NVRAM) #ifdef CONFIG_ADB_CUDA static unsigned char cuda_pram_read_byte(int offset) { @@ -84,6 +85,7 @@ static void pmu_pram_write_byte(unsigned char data, int offset) pmu_wait_complete(&req); } #endif /* CONFIG_ADB_PMU */ +#endif /* CONFIG_NVRAM */ /* * VIA PRAM/RTC access routines @@ -205,6 +207,7 @@ static void via_rtc_command(int command, __u8 *data) local_irq_restore(flags); } +#if IS_ENABLED(CONFIG_NVRAM) static unsigned char via_pram_read_byte(int offset) { unsigned char temp; @@ -227,6 +230,7 @@ static void via_pram_write_byte(unsigned char data, int offset) temp = 0x55 | RTC_FLG_WRITE_PROTECT; via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp); } +#endif /* CONFIG_NVRAM */ /* * Return the current time in seconds since January 1, 1904. @@ -372,6 +376,7 @@ static void cuda_shutdown(void) *------------------------------------------------------------------- */ +#if IS_ENABLED(CONFIG_NVRAM) unsigned char mac_pram_read_byte(int addr) { switch (macintosh_config->adb_type) { @@ -417,6 +422,12 @@ void mac_pram_write_byte(unsigned char val, int addr) } } +ssize_t mac_pram_get_size(void) +{ + return 256; +} +#endif /* CONFIG_NVRAM */ + void mac_poweroff(void) { if (oss_present) { -- 2.19.2