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 22/24] m68k/mac: Adopt nvram module
Date: Sun, 31 May 2015 11:01:54 +1000 [thread overview]
Message-ID: <20150531010137.819515570@telegraphics.com.au> (raw)
In-Reply-To: 20150531010132.289674310@telegraphics.com.au
[-- Attachment #1: mac68k-introduce-arch_nvram_ops --]
[-- Type: text/plain, Size: 7919 bytes --]
Implement arch_nvram_ops and adjust calling conventions of mac_pram_*
functions to match the ops struct methods. Rename via_pram_readbyte and
via_pram_writebyte to avoid confusion and follow the existing
nvram_*_read_byte and nvram_*_write_byte naming convention.
Enable CONFIG_HAVE_ARCH_NVRAM_OPS on Macs.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
The arch_nvram_ops struct can only be defined once, of course, so the
Mac and Atari ops structs are mutually exclusive. The final patch will
allow the two implementations to co-exist in a multi-platform kernel binary.
---
arch/m68k/Kconfig | 2
arch/m68k/mac/misc.c | 120 +++++++++++++++++++++++++++++++--------------------
2 files changed, 76 insertions(+), 46 deletions(-)
Index: linux/arch/m68k/Kconfig
===================================================================
--- linux.orig/arch/m68k/Kconfig 2015-05-31 11:01:11.000000000 +1000
+++ linux/arch/m68k/Kconfig 2015-05-31 11:01:26.000000000 +1000
@@ -72,7 +72,7 @@ config PGTABLE_LEVELS
default 3
config HAVE_ARCH_NVRAM_OPS
- def_bool ATARI
+ def_bool (ATARI && !MAC) || (MAC && !ATARI)
source "init/Kconfig"
Index: linux/arch/m68k/mac/misc.c
===================================================================
--- linux.orig/arch/m68k/mac/misc.c 2015-05-31 11:00:59.000000000 +1000
+++ linux/arch/m68k/mac/misc.c 2015-05-31 11:01:26.000000000 +1000
@@ -11,6 +11,7 @@
#include <linux/time.h>
#include <linux/rtc.h>
#include <linux/mm.h>
+#include <linux/nvram.h>
#include <linux/adb.h>
#include <linux/cuda.h>
@@ -61,7 +62,8 @@ static void cuda_write_time(long data)
cuda_poll();
}
-static __u8 cuda_read_pram(int offset)
+#if IS_ENABLED(CONFIG_NVRAM)
+static unsigned char cuda_pram_read_byte(int offset)
{
struct adb_request req;
if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
@@ -72,7 +74,7 @@ static __u8 cuda_read_pram(int offset)
return req.reply[3];
}
-static void cuda_write_pram(int offset, __u8 data)
+static void cuda_pram_write_byte(unsigned char data, int offset)
{
struct adb_request req;
if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
@@ -81,11 +83,13 @@ static void cuda_write_pram(int offset,
while (!req.complete)
cuda_poll();
}
+#endif /* CONFIG_NVRAM */
+
#else
#define cuda_read_time() 0
#define cuda_write_time(n)
-#define cuda_read_pram NULL
-#define cuda_write_pram NULL
+#define cuda_pram_read_byte NULL
+#define cuda_pram_write_byte NULL
#endif
#ifdef CONFIG_ADB_PMU68K
@@ -116,7 +120,8 @@ static void pmu_write_time(long data)
pmu_poll();
}
-static __u8 pmu_read_pram(int offset)
+#if IS_ENABLED(CONFIG_NVRAM)
+static unsigned char pmu_pram_read_byte(int offset)
{
struct adb_request req;
if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM,
@@ -127,7 +132,7 @@ static __u8 pmu_read_pram(int offset)
return req.reply[3];
}
-static void pmu_write_pram(int offset, __u8 data)
+static void pmu_pram_write_byte(unsigned char data, int offset)
{
struct adb_request req;
if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM,
@@ -136,11 +141,13 @@ static void pmu_write_pram(int offset, _
while (!req.complete)
pmu_poll();
}
+#endif /* CONFIG_NVRAM */
+
#else
#define pmu_read_time() 0
#define pmu_write_time(n)
-#define pmu_read_pram NULL
-#define pmu_write_pram NULL
+#define pmu_pram_read_byte NULL
+#define pmu_pram_write_byte NULL
#endif
#if 0 /* def CONFIG_ADB_MACIISI */
@@ -169,7 +176,8 @@ static void maciisi_write_time(long data
(data >> 8) & 0xFF, data & 0xFF);
}
-static __u8 maciisi_read_pram(int offset)
+#if IS_ENABLED(CONFIG_NVRAM)
+static unsigned char maciisi_pram_read_byte(int offset)
{
struct adb_request req;
if (maciisi_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
@@ -178,17 +186,19 @@ static __u8 maciisi_read_pram(int offset
return req.reply[3];
}
-static void maciisi_write_pram(int offset, __u8 data)
+static void maciisi_pram_write_byte(unsigned char data, int offset)
{
struct adb_request req;
maciisi_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
(offset >> 8) & 0xFF, offset & 0xFF, data);
}
+#endif /* CONFIG_NVRAM */
+
#else
#define maciisi_read_time() 0
#define maciisi_write_time(n)
-#define maciisi_read_pram NULL
-#define maciisi_write_pram NULL
+#define maciisi_pram_read_byte NULL
+#define maciisi_pram_write_byte NULL
#endif
/*
@@ -198,7 +208,7 @@ static void maciisi_write_pram(int offse
* the RTC should be enabled.
*/
-static __u8 via_pram_readbyte(void)
+static __u8 via_pram_recv(void)
{
int i,reg;
__u8 data;
@@ -225,7 +235,7 @@ static __u8 via_pram_readbyte(void)
return data;
}
-static void via_pram_writebyte(__u8 data)
+static void via_pram_send(__u8 data)
{
int i,reg,bit;
@@ -262,17 +272,17 @@ static void via_pram_command(int command
via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb;
if (command & 0xFF00) { /* extended (two-byte) command */
- via_pram_writebyte((command & 0xFF00) >> 8);
- via_pram_writebyte(command & 0xFF);
+ via_pram_send((command & 0xFF00) >> 8);
+ via_pram_send(command & 0xFF);
is_read = command & 0x8000;
} else { /* one-byte command */
- via_pram_writebyte(command);
+ via_pram_send(command);
is_read = command & 0x80;
}
if (is_read) {
- *data = via_pram_readbyte();
+ *data = via_pram_recv();
} else {
- via_pram_writebyte(*data);
+ via_pram_send(*data);
}
/* All done, disable the RTC */
@@ -282,14 +292,16 @@ static void via_pram_command(int command
local_irq_restore(flags);
}
-static __u8 via_read_pram(int offset)
+#if IS_ENABLED(CONFIG_NVRAM)
+static unsigned char via_pram_read_byte(int offset)
{
return 0;
}
-static void via_write_pram(int offset, __u8 data)
+static void via_pram_write_byte(unsigned char data, int offset)
{
}
+#endif /* CONFIG_NVRAM */
/*
* Return the current time in seconds since January 1, 1904.
@@ -453,52 +465,70 @@ void pmu_shutdown(void)
*-------------------------------------------------------------------
*/
-void mac_pram_read(int offset, __u8 *buffer, int len)
+#if IS_ENABLED(CONFIG_NVRAM)
+static unsigned char mac_pram_read_byte(int addr)
{
- __u8 (*func)(int);
- int i;
+ unsigned char (*func)(int);
switch(macintosh_config->adb_type) {
case MAC_ADB_IISI:
- func = maciisi_read_pram; break;
+ func = maciisi_pram_read_byte;
+ break;
case MAC_ADB_PB1:
case MAC_ADB_PB2:
- func = pmu_read_pram; break;
+ func = pmu_pram_read_byte;
+ break;
case MAC_ADB_CUDA:
- func = cuda_read_pram; break;
+ func = cuda_pram_read_byte;
+ break;
default:
- func = via_read_pram;
- }
- if (!func)
- return;
- for (i = 0 ; i < len ; i++) {
- buffer[i] = (*func)(offset++);
+ func = via_pram_read_byte;
}
+
+ if (func)
+ return (*func)(addr);
+ return 0xff;
}
-void mac_pram_write(int offset, __u8 *buffer, int len)
+static void mac_pram_write_byte(unsigned char val, int addr)
{
- void (*func)(int, __u8);
- int i;
+ void (*func)(unsigned char, int);
switch(macintosh_config->adb_type) {
case MAC_ADB_IISI:
- func = maciisi_write_pram; break;
+ func = maciisi_pram_write_byte;
+ break;
case MAC_ADB_PB1:
case MAC_ADB_PB2:
- func = pmu_write_pram; break;
+ func = pmu_pram_write_byte;
+ break;
case MAC_ADB_CUDA:
- func = cuda_write_pram; break;
+ func = cuda_pram_write_byte;
+ break;
default:
- func = via_write_pram;
- }
- if (!func)
- return;
- for (i = 0 ; i < len ; i++) {
- (*func)(offset++, buffer[i]);
+ func = via_pram_write_byte;
}
+
+ if (func)
+ (*func)(val, addr);
}
+static ssize_t mac_pram_get_size(void)
+{
+ if (!MACH_IS_MAC)
+ return -ENODEV;
+ return 256;
+}
+
+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 /* CONFIG_NVRAM */
+
+
void mac_poweroff(void)
{
/*
next prev parent reply other threads:[~2015-05-31 1:17 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 ` Finn Thain [this message]
2015-05-31 1:01 ` [RFC 23/24] m68k/mac: Fix PRAM accessors Finn Thain
2015-05-31 1:01 ` [RFC 24/24] m68k: Dispatch nvram_ops calls to Atari or Mac functions Finn Thain
2015-06-01 8:31 ` 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=20150531010137.819515570@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