m68k: Dispatch nvram_ops calls to Atari or Mac functions
authorFinn Thain <fthain@telegraphics.com.au>
Tue, 15 Jan 2019 04:18:56 +0000 (15:18 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Jan 2019 09:21:45 +0000 (10:21 +0100)
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 <geert@linux-m68k.org>
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/m68k/Kconfig.machine
arch/m68k/atari/nvram.c
arch/m68k/include/asm/atarihw.h
arch/m68k/include/asm/macintosh.h
arch/m68k/kernel/setup_mm.c
arch/m68k/mac/misc.c

index ad584e3eb8f7d32fd12094e5c6dd48ebd3d67a5e..c01e103492fdc2e8b3edf92d71090b327e862f54 100644 (file)
@@ -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
index c347fd206ddfc155b572b3a4ec4c2bd27c4a9e5e..7000d2443aa3880bab5cdc9f804c4760bf73b313 100644 (file)
@@ -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;
index 9000b249d225e97bbc1cd4af21c50f327493e624..533008262b691ad9cd7800e14b676a916a72b4b1 100644 (file)
@@ -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 && \
index 08cee11180e6998d2069b1591e78ad57288f9134..d9a08bed4b128872cbe999ebfabe2479ccb9f317 100644 (file)
@@ -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
  */
index ad0195cbe04255eada56bc8cff364086dc38642e..528484feff80017e88582615a608edd8c2c65e12 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/module.h>
+#include <linux/nvram.h>
 #include <linux/initrd.h>
 
 #include <asm/bootinfo.h>
 #ifdef CONFIG_AMIGA
 #include <asm/amigahw.h>
 #endif
-#ifdef CONFIG_ATARI
 #include <asm/atarihw.h>
+#ifdef CONFIG_ATARI
 #include <asm/atari_stram.h>
 #endif
 #ifdef CONFIG_SUN3X
 #include <asm/dvma.h>
 #endif
+#include <asm/macintosh.h>
 #include <asm/natfeat.h>
 
 #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 */
index d016ca2e0d1038724f196b173dac1fb58b0ba0b8..5dc8d1e985e79ea3a040c283d233b1c0c8cd8545 100644 (file)
@@ -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) {