From: Finn Thain <fthain@telegraphics.com.au>
To: <linux-kernel@vger.kernel.org>, <linux-m68k@vger.kernel.org>,
<linuxppc-dev@lists.ozlabs.org>,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [RFC 24/24] m68k: Dispatch nvram_ops calls to Atari or Mac functions
Date: Sun, 31 May 2015 11:01:56 +1000 [thread overview]
Message-ID: <20150531010138.309478365@telegraphics.com.au> (raw)
In-Reply-To: 20150531010132.289674310@telegraphics.com.au
[-- Attachment #1: m68k-introduce-arch_nvram_ops --]
[-- Type: text/plain, Size: 8256 bytes --]
A multi-platform kernel binary needs to decide at run-time how to dispatch
the arch_nvram_ops calls. Add platform-independent arch_nvram_ops, for use
when multiple platform-specific NVRAM ops implementations are needed.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
arch/m68k/Kconfig | 2
arch/m68k/atari/nvram.c | 22 +++++----
arch/m68k/include/asm/atarihw.h | 6 ++
arch/m68k/include/asm/macintosh.h | 4 +
arch/m68k/kernel/setup_mm.c | 89 ++++++++++++++++++++++++++++++++++++++
arch/m68k/mac/misc.c | 8 ++-
6 files changed, 117 insertions(+), 14 deletions(-)
Index: linux/arch/m68k/atari/nvram.c
===================================================================
--- linux.orig/arch/m68k/atari/nvram.c 2015-05-31 11:01:21.000000000 +1000
+++ linux/arch/m68k/atari/nvram.c 2015-05-31 11:01:29.000000000 +1000
@@ -73,7 +73,7 @@ static void __nvram_set_checksum(void)
__nvram_write_byte(sum, ATARI_CKS_LOC + 1);
}
-static long nvram_set_checksum(void)
+long atari_nvram_set_checksum(void)
{
spin_lock_irq(&rtc_lock);
__nvram_set_checksum();
@@ -81,7 +81,7 @@ static long nvram_set_checksum(void)
return 0;
}
-static long nvram_initialize(void)
+long atari_nvram_initialize(void)
{
loff_t i;
@@ -93,7 +93,7 @@ static long nvram_initialize(void)
return 0;
}
-static ssize_t 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;
@@ -114,7 +114,7 @@ static ssize_t nvram_read(char *buf, siz
return p - buf;
}
-static ssize_t 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;
@@ -137,21 +137,23 @@ static ssize_t nvram_write(char *buf, si
return p - buf;
}
-static ssize_t nvram_get_size(void)
+ssize_t atari_nvram_get_size(void)
{
if (!MACH_IS_ATARI)
return -ENODEV;
return NVRAM_BYTES;
}
+#ifndef CONFIG_MAC
const struct nvram_ops arch_nvram_ops = {
- .read = nvram_read,
- .write = nvram_write,
- .get_size = nvram_get_size,
- .set_checksum = nvram_set_checksum,
- .initialize = nvram_initialize,
+ .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);
+#endif
#ifdef CONFIG_PROC_FS
static struct {
Index: linux/arch/m68k/mac/misc.c
===================================================================
--- linux.orig/arch/m68k/mac/misc.c 2015-05-31 11:01:28.000000000 +1000
+++ linux/arch/m68k/mac/misc.c 2015-05-31 11:01:29.000000000 +1000
@@ -489,7 +489,7 @@ void pmu_shutdown(void)
*/
#if IS_ENABLED(CONFIG_NVRAM)
-static unsigned char mac_pram_read_byte(int addr)
+unsigned char mac_pram_read_byte(int addr)
{
unsigned char (*func)(int);
@@ -513,7 +513,7 @@ static unsigned char mac_pram_read_byte(
return 0xff;
}
-static void mac_pram_write_byte(unsigned char val, int addr)
+void mac_pram_write_byte(unsigned char val, int addr)
{
void (*func)(unsigned char, int);
@@ -536,19 +536,21 @@ static void mac_pram_write_byte(unsigned
(*func)(val, addr);
}
-static ssize_t mac_pram_get_size(void)
+ssize_t mac_pram_get_size(void)
{
if (!MACH_IS_MAC)
return -ENODEV;
return 256;
}
+#ifndef CONFIG_ATARI
const struct nvram_ops arch_nvram_ops = {
.read_byte = mac_pram_read_byte,
.write_byte = mac_pram_write_byte,
.get_size = mac_pram_get_size,
};
EXPORT_SYMBOL(arch_nvram_ops);
+#endif
#endif /* CONFIG_NVRAM */
Index: linux/arch/m68k/kernel/setup_mm.c
===================================================================
--- linux.orig/arch/m68k/kernel/setup_mm.c 2015-05-31 11:00:59.000000000 +1000
+++ linux/arch/m68k/kernel/setup_mm.c 2015-05-31 11:01:29.000000000 +1000
@@ -23,6 +23,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>
@@ -40,6 +41,9 @@
#include <asm/atarihw.h>
#include <asm/atari_stram.h>
#endif
+#ifdef CONFIG_MAC
+#include <asm/macintosh.h>
+#endif
#ifdef CONFIG_SUN3X
#include <asm/dvma.h>
#endif
@@ -568,3 +572,88 @@ static int __init adb_probe_sync_enable
__setup("adb_sync", adb_probe_sync_enable);
#endif /* CONFIG_ADB */
+
+#if IS_ENABLED(CONFIG_NVRAM) && defined(CONFIG_ATARI) && defined(CONFIG_MAC)
+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) {
+ ssize_t size = mac_pram_get_size();
+ char *p = buf;
+ loff_t i;
+
+ for (i = *ppos; count > 0 && i < size; --count, ++i, ++p)
+ *p = mac_pram_read_byte(i);
+
+ *ppos = i;
+ return p - buf;
+ }
+ 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) {
+ ssize_t size = mac_pram_get_size();
+ char *p = buf;
+ loff_t i;
+
+ for (i = *ppos; count > 0 && i < size; --count, ++i, ++p)
+ mac_pram_write_byte(*p, i);
+
+ *ppos = i;
+ return p - buf;
+ }
+ return -EINVAL;
+}
+
+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);
+}
+
+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;
+}
+
+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;
+}
+
+const struct nvram_ops arch_nvram_ops = {
+ .read = m68k_nvram_read,
+ .write = m68k_nvram_write,
+ .read_byte = m68k_nvram_read_byte,
+ .write_byte = m68k_nvram_write_byte,
+ .get_size = m68k_nvram_get_size,
+ .set_checksum = m68k_nvram_set_checksum,
+ .initialize = m68k_nvram_initialize,
+};
+EXPORT_SYMBOL(arch_nvram_ops);
+#endif
Index: linux/arch/m68k/Kconfig
===================================================================
--- linux.orig/arch/m68k/Kconfig 2015-05-31 11:01:26.000000000 +1000
+++ linux/arch/m68k/Kconfig 2015-05-31 11:01:29.000000000 +1000
@@ -72,7 +72,7 @@ config PGTABLE_LEVELS
default 3
config HAVE_ARCH_NVRAM_OPS
- def_bool (ATARI && !MAC) || (MAC && !ATARI)
+ def_bool ATARI || MAC
source "init/Kconfig"
Index: linux/arch/m68k/include/asm/atarihw.h
===================================================================
--- linux.orig/arch/m68k/include/asm/atarihw.h 2015-05-31 11:00:59.000000000 +1000
+++ linux/arch/m68k/include/asm/atarihw.h 2015-05-31 11:01:29.000000000 +1000
@@ -32,6 +32,12 @@ extern int atari_dont_touch_floppy_selec
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: linux/arch/m68k/include/asm/macintosh.h
===================================================================
--- linux.orig/arch/m68k/include/asm/macintosh.h 2015-05-31 11:00:59.000000000 +1000
+++ linux/arch/m68k/include/asm/macintosh.h 2015-05-31 11:01:29.000000000 +1000
@@ -18,6 +18,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
*/
next prev parent reply other threads:[~2015-05-31 1:21 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-31 1:01 [RFC 00/24] Re-use nvram module Finn Thain
2015-05-31 1:01 ` [RFC 01/24] macintosh/nvram: Remove as unused Finn Thain
2015-06-01 7:40 ` Geert Uytterhoeven
2015-05-31 1:01 ` [RFC 02/24] scsi/atari_scsi: Dont select CONFIG_NVRAM Finn Thain
2015-05-31 1:01 ` [RFC 03/24] m68k/atari: Move Atari-specific code out of drivers/char/nvram.c Finn Thain
2015-05-31 1:01 ` [RFC 04/24] m68k/atari: Replace nvram_{read,write}_byte with arch_nvram_ops Finn Thain
2015-05-31 1:01 ` [RFC 05/24] char/nvram: Re-order functions to remove forward declarations and #ifdefs Finn Thain
2015-05-31 1:01 ` [RFC 06/24] char/nvram: Adopt arch_nvram_ops Finn Thain
2015-05-31 1:01 ` [RFC 07/24] x86/thinkpad_acpi: Use arch_nvram_ops methods instead of nvram_read_byte() and nvram_write_byte() Finn Thain
2015-05-31 4:11 ` Henrique de Moraes Holschuh
2015-05-31 6:15 ` Finn Thain
2015-05-31 14:34 ` Henrique de Moraes Holschuh
2015-06-02 10:09 ` Henrique de Moraes Holschuh
2015-06-03 3:34 ` Darren Hart
2015-06-03 7:38 ` Finn Thain
2015-06-03 10:37 ` Henrique de Moraes Holschuh
2015-06-04 5:14 ` Darren Hart
2015-05-31 1:01 ` [RFC 08/24] char/nvram: Allow the set_checksum and initialize ioctls to be omitted Finn Thain
2015-05-31 1:01 ` [RFC 09/24] char/nvram: Implement NVRAM read/write methods Finn Thain
2015-05-31 1:01 ` [RFC 10/24] char/nvram: Use generic fixed_size_llseek() Finn Thain
2015-05-31 1:01 ` [RFC 11/24] m68k/atari: Implement arch_nvram_ops methods and enable CONFIG_HAVE_ARCH_NVRAM_OPS Finn Thain
2015-05-31 1:01 ` [RFC 12/24] char/nvram: Add "devname:nvram" module alias Finn Thain
2015-05-31 1:01 ` [RFC 13/24] powerpc: Cleanup nvram includes Finn Thain
2015-05-31 1:01 ` [RFC 14/24] powerpc: Add missing ppc_md.nvram_size for CHRP and PowerMac Finn Thain
2015-05-31 1:01 ` [RFC 15/24] powerpc: Implement arch_nvram_ops.get_size() and remove old nvram_* exports Finn Thain
2015-05-31 1:01 ` [RFC 16/24] powerpc: Implement nvram sync ioctl Finn Thain
2015-05-31 1:01 ` [RFC 17/24] powerpc, fbdev: Use arch_nvram_ops methods instead of nvram_read_byte() and nvram_write_byte() Finn Thain
2015-05-31 1:01 ` [RFC 18/24] nvram: Drop nvram_* symbol exports and prototypes Finn Thain
2015-05-31 1:01 ` [RFC 19/24] powerpc: Remove CONFIG_GENERIC_NVRAM and adopt CONFIG_HAVE_ARCH_NVRAM_OPS Finn Thain
2015-05-31 1:01 ` [RFC 20/24] char/generic_nvram: Remove as unused Finn Thain
2015-05-31 1:01 ` [RFC 21/24] powerpc: Adopt nvram module for PPC64 Finn Thain
2015-05-31 1:01 ` [RFC 22/24] m68k/mac: Adopt nvram module Finn Thain
2015-05-31 1:01 ` [RFC 23/24] m68k/mac: Fix PRAM accessors Finn Thain
2015-05-31 1:01 ` Finn Thain [this message]
2015-06-01 8:31 ` [RFC 24/24] m68k: Dispatch nvram_ops calls to Atari or Mac functions Geert Uytterhoeven
2015-06-02 7:21 ` Finn Thain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150531010138.309478365@telegraphics.com.au \
--to=fthain@telegraphics.com.au \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox