Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1260130 > unrolled thread
| Started by | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| First post | 2015-11-01 12:00 +0100 |
| Last post | 2015-11-01 12:00 +0100 |
| Articles | 14 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH v7 00/26] Re-use nvram module Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 07/26] char/nvram: Allow the set_checksum and initialize ioctls to be omitted Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 23/26] m68k/mac: Adopt naming and calling conventions for PRAM routines Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 24/26] m68k/mac: Use macros for RTC accesses not magic numbers Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 21/26] powerpc: Adopt nvram module for PPC64 Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 13/26] powerpc: Add missing ppc_md.nvram_size for CHRP and PowerMac Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 16/26] powerpc, fbdev: Use NV_CMODE and NV_VMODE only when CONFIG_PPC32 and CONFIG_PPC_PMAC and CONFIG_NVRAM Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 09/26] char/nvram: Use generic fixed_size_llseek() Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 10/26] m68k/atari: Implement arch_nvram_ops methods and enable CONFIG_HAVE_ARCH_NVRAM_OPS Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 05/26] char/nvram: Adopt arch_nvram_ops Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 02/26] m68k/atari: Move Atari-specific code out of drivers/char/nvram.c Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 03/26] m68k/atari: Replace nvram_{read,write}_byte with arch_nvram_ops Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 18/26] nvram: Drop nvram_* symbol exports and prototypes Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
[PATCH v7 08/26] char/nvram: Implement NVRAM read/write methods Finn Thain <fthain@telegraphics.com.au> - 2015-11-01 12:00 +0100
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 00/26] Re-use nvram module |
| Message-ID | <qpYmZ-76K-3@gated-at.bofh.it> |
The generic NVRAM module, drivers/char/generic_nvram, implements a /dev/nvram misc device. It is used only by 32-bit PowerPC platforms and isn't generic enough to be more widely used. The RTC NVRAM module, drivers/char/nvram, also implements a /dev/nvram misc device. It is used by x86, ARM and m68k. The former module cannot be used on x86, ARM or m68k because it cannot co-exist with the latter module, partly due to the Kconfig logic. It is possible to modify the modules so that one kernel binary could have either, neither or both. However, automatically loading the appropriate module is then impossible; if both provide the char-major-10-144 alias then the wrong module will end up being loaded. Hence a multi-platform kernel binary needs a single generic nvram module with alias char-major-10-144. Therefore, drivers/char/nvram.c should be made more generic and the arch-specific code therein should be moved to a more appropriate place under arch/. Also, drivers/char/generic_nvram.c should be removed to reduce code duplication. In this patch series, Atari-specific code is moved from the nvram module to arch/m68k/atari. More arch-specific code in the nvram module could be moved, probably to arch/x86, but it is difficult to determine just what code is relevant to ARM platforms and what code is x86-only. In addressing code duplication, v1 of this patch series removes three inconsistent /dev/nvram misc device implementations. One of these, drivers/macintosh/nvram.c is entirely unused already. The other two, drivers/char/generic_nvram.c and the misc device implementation in arch/powerpc/kernel/nvram_64.c, are replaced by drivers/char/nvram.c. A benefit of this work is better consistency -- between PPC32 and PPC64 as well as between PPC_PMAC and MAC. This new uniformity does have implications for userspace, that is, some error codes for some ioctl calls become consistent on all PowerPC platforms. The drivers/char/nvram module becomes sufficiently generic to be useful to other platforms and architectures, besides those with "CMOS" RTC. At the end of this patch series the module is adopted by the m68k Mac port, which already has PRAM access functions but lacks the /dev/nvram misc device. This patch series has been compile-tested for arm, m68k, powerpc and x86. The nvram and thinkpad_acpi modules were regression tested on a ThinkPad T43. The /dev/nvram functionality was also regression tested on a G3 PowerMac. The nvram module was also tested on a PowerBook 520, Quadra 650 and Atari Falcon. The PPC64 changes were tested on a G5 PowerMac. Changes since v1: - Minor changes to patches 7, 15 and 20 as described in commit logs. - Revised patches 21 and 24 to address comments from Geert. Changes since v2: - Dropped patch 1, "macintosh/nvram: Remove as unused", because it has since been merged. - Inserted a new patch, "m68k/mac: Use macros for RTC accesses not magic numbers". - Revised patches 21 and 23 to address comments from Geert. Changes since v3: - Split the patch, "m68k/atari: Move Atari-specific code out of drivers/char/nvram.c", as suggested by Geert. - Revised patches 11 and 25 to address comments from Geert. - Minor change to patch 21 as described in commit log. Changes since v4: - Split the patch, "powerpc, fbdev: Use arch_nvram_ops methods instead of nvram_read_byte() and nvram_write_byte()", so as to separately address inconsistent use of Kconfig symbols in PowerMac fbdev drivers. - Fix possible git bisect build failure with CONFIG_PPC_PMAC=n. Changes since v5: - Dropped patch 2, "char/nvram: Use bitwise OR to obtain Atari video mode data", since it has been added to Greg Kroah-Hartman's char-misc-next queue. - In patch 15, error codes from the IOC_NVRAM_GET_OFFSET ioctl are now consistent with the old generic_nvram module. Changes since v6: - In patch 21, the '#ifdef CONFIG_NVRAM' conditional was changed to '#if defined(CONFIG_NVRAM) && defined(CONFIG_PPC32)' to avoid changing behaviour as CONFIG_NVRAM becomes available to PPC64. - Added a new patch (22) in response to Ben's comment about XPRAM accessors. The patch replaces the calls to pmac_xpram_read() with calls to arch_nvram_ops.read_byte() --- arch/m68k/Kconfig | 3 arch/m68k/Kconfig.machine | 2 arch/m68k/atari/Makefile | 2 arch/m68k/atari/nvram.c | 291 +++++++++++ arch/m68k/include/asm/atarihw.h | 6 arch/m68k/include/asm/macintosh.h | 4 arch/m68k/kernel/setup_mm.c | 100 +++ arch/m68k/mac/misc.c | 207 +++++--- arch/powerpc/Kconfig | 5 arch/powerpc/include/asm/nvram.h | 13 arch/powerpc/kernel/nvram_64.c | 206 +------- arch/powerpc/kernel/setup_32.c | 30 - arch/powerpc/platforms/chrp/Makefile | 2 arch/powerpc/platforms/chrp/nvram.c | 14 arch/powerpc/platforms/chrp/setup.c | 2 arch/powerpc/platforms/powermac/Makefile | 5 arch/powerpc/platforms/powermac/nvram.c | 37 - arch/powerpc/platforms/powermac/setup.c | 3 arch/powerpc/platforms/powermac/time.c | 19 arch/powerpc/platforms/pseries/nvram.c | 2 drivers/char/Kconfig | 13 drivers/char/Makefile | 6 drivers/char/generic_nvram.c | 174 ------ drivers/char/nvram.c | 740 ++++++++++++----------------- drivers/platform/x86/thinkpad_acpi.c | 20 drivers/scsi/Kconfig | 6 drivers/scsi/atari_scsi.c | 16 drivers/video/fbdev/Kconfig | 2 drivers/video/fbdev/controlfb.c | 4 drivers/video/fbdev/imsttfb.c | 17 drivers/video/fbdev/matrox/matroxfb_base.c | 6 drivers/video/fbdev/platinumfb.c | 4 drivers/video/fbdev/valkyriefb.c | 18 include/linux/nvram.h | 24 include/uapi/linux/pmu.h | 2 35 files changed, 1020 insertions(+), 985 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 07/26] char/nvram: Allow the set_checksum and initialize ioctls to be omitted |
| Message-ID | <qpYwG-7a6-21@gated-at.bofh.it> |
| In reply to | #1260130 |
The drivers/char/nvram module has previously only supported RTC "CMOS"
NVRAM, for which it provides appropriate checksum ioctls. Make these
ioctls optional so the module can be re-used with other kinds of NVRAM.
The ops struct methods that implement the ioctls now return error
codes so that a multi-platform kernel binary can do the right thing when
running on hardware without suitable NVRAM.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
Changed since v1:
- Don't bother acquiring the mutex for unimplemented ioctls.
---
drivers/char/nvram.c | 71 ++++++++++++++++++++++++++++----------------------
include/linux/nvram.h | 2 +
2 files changed, 43 insertions(+), 30 deletions(-)
Index: linux/drivers/char/nvram.c
===================================================================
--- linux.orig/drivers/char/nvram.c 2015-11-01 21:41:30.000000000 +1100
+++ linux/drivers/char/nvram.c 2015-11-01 21:41:32.000000000 +1100
@@ -153,16 +153,25 @@ static void __nvram_set_checksum(void)
__nvram_write_byte(sum & 0xff, PC_CKS_LOC + 1);
}
-#if 0
-void nvram_set_checksum(void)
+static long nvram_set_checksum(void)
{
- unsigned long flags;
+ spin_lock_irq(&rtc_lock);
+ __nvram_set_checksum();
+ spin_unlock_irq(&rtc_lock);
+ return 0;
+}
+
+static long nvram_initialize(void)
+{
+ ssize_t i;
- spin_lock_irqsave(&rtc_lock, flags);
+ spin_lock_irq(&rtc_lock);
+ for (i = 0; i < NVRAM_BYTES; ++i)
+ __nvram_write_byte(0, i);
__nvram_set_checksum();
- spin_unlock_irqrestore(&rtc_lock, flags);
+ spin_unlock_irq(&rtc_lock);
+ return 0;
}
-#endif /* 0 */
static ssize_t nvram_get_size(void)
{
@@ -173,6 +182,8 @@ const struct nvram_ops arch_nvram_ops =
.read_byte = nvram_read_byte,
.write_byte = nvram_write_byte,
.get_size = nvram_get_size,
+ .set_checksum = nvram_set_checksum,
+ .initialize = nvram_initialize,
};
EXPORT_SYMBOL(arch_nvram_ops);
@@ -272,51 +283,51 @@ checksum_err:
static long nvram_misc_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
- int i;
+ long ret = -ENOTTY;
switch (cmd) {
-
case NVRAM_INIT:
/* initialize NVRAM contents and checksum */
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
- mutex_lock(&nvram_mutex);
- spin_lock_irq(&rtc_lock);
-
- for (i = 0; i < NVRAM_BYTES; ++i)
- __nvram_write_byte(0, i);
- __nvram_set_checksum();
-
- spin_unlock_irq(&rtc_lock);
- mutex_unlock(&nvram_mutex);
- return 0;
-
+ if (arch_nvram_ops.initialize != NULL) {
+ mutex_lock(&nvram_mutex);
+ ret = arch_nvram_ops.initialize();
+ mutex_unlock(&nvram_mutex);
+ }
+ break;
case NVRAM_SETCKS:
/* just set checksum, contents unchanged (maybe useful after
* checksum garbaged somehow...) */
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
- mutex_lock(&nvram_mutex);
- spin_lock_irq(&rtc_lock);
- __nvram_set_checksum();
- spin_unlock_irq(&rtc_lock);
- mutex_unlock(&nvram_mutex);
- return 0;
-
- default:
- return -ENOTTY;
+ if (arch_nvram_ops.set_checksum != NULL) {
+ mutex_lock(&nvram_mutex);
+ ret = arch_nvram_ops.set_checksum();
+ mutex_unlock(&nvram_mutex);
+ }
+ break;
}
+ return ret;
}
static int nvram_misc_open(struct inode *inode, struct file *file)
{
spin_lock(&nvram_state_lock);
+ /* Prevent multiple readers/writers if desired. */
if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
- (nvram_open_mode & NVRAM_EXCL) ||
- ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) {
+ (nvram_open_mode & NVRAM_EXCL)) {
+ spin_unlock(&nvram_state_lock);
+ return -EBUSY;
+ }
+
+ /* Prevent multiple writers if the set_checksum ioctl is implemented. */
+ if ((arch_nvram_ops.set_checksum != NULL) &&
+ (file->f_mode & FMODE_WRITE) &&
+ (nvram_open_mode & NVRAM_WRITE)) {
spin_unlock(&nvram_state_lock);
return -EBUSY;
}
Index: linux/include/linux/nvram.h
===================================================================
--- linux.orig/include/linux/nvram.h 2015-11-01 21:41:30.000000000 +1100
+++ linux/include/linux/nvram.h 2015-11-01 21:41:32.000000000 +1100
@@ -17,6 +17,8 @@ struct nvram_ops {
unsigned char (*read_byte)(int);
void (*write_byte)(unsigned char, int);
ssize_t (*get_size)(void);
+ long (*set_checksum)(void);
+ long (*initialize)(void);
};
extern const struct nvram_ops arch_nvram_ops;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 23/26] m68k/mac: Adopt naming and calling conventions for PRAM routines |
| Message-ID | <qpYwH-7a6-27@gated-at.bofh.it> |
| In reply to | #1260130 |
Adopt the existing *_read_byte and *_write_byte naming convention.
Rename via_pram_readbyte and via_pram_writebyte to avoid confusion.
Adjust calling conventions of mac_pram_* functions to match the
arch_nvram_ops struct methods.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Changes since v1:
- Don't introduce the arch_nvram_ops struct in this patch, even if it
would form a logical progression. Since the struct would get replaced
later on, some might see it as churn.
Changes since v2:
- Rename via_pram_send() and via_pram_recv() as
via_rtc_send() and via_rtc_recv() resp.
---
arch/m68k/mac/misc.c | 91 +++++++++++++++++++++++++--------------------------
1 file changed, 46 insertions(+), 45 deletions(-)
Index: linux/arch/m68k/mac/misc.c
===================================================================
--- linux.orig/arch/m68k/mac/misc.c 2015-11-01 21:41:23.000000000 +1100
+++ linux/arch/m68k/mac/misc.c 2015-11-01 21:41:55.000000000 +1100
@@ -61,7 +61,7 @@ static void cuda_write_time(long data)
cuda_poll();
}
-static __u8 cuda_read_pram(int offset)
+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 +72,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,
@@ -84,8 +84,8 @@ static void cuda_write_pram(int offset,
#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 +116,7 @@ static void pmu_write_time(long data)
pmu_poll();
}
-static __u8 pmu_read_pram(int offset)
+static unsigned char pmu_pram_read_byte(int offset)
{
struct adb_request req;
if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM,
@@ -127,7 +127,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,
@@ -139,8 +139,8 @@ static void pmu_write_pram(int offset, _
#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 +169,7 @@ static void maciisi_write_time(long data
(data >> 8) & 0xFF, data & 0xFF);
}
-static __u8 maciisi_read_pram(int offset)
+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,7 +178,7 @@ 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,
@@ -187,8 +187,8 @@ static void maciisi_write_pram(int offse
#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 +198,7 @@ static void maciisi_write_pram(int offse
* the RTC should be enabled.
*/
-static __u8 via_pram_readbyte(void)
+static __u8 via_rtc_recv(void)
{
int i,reg;
__u8 data;
@@ -225,7 +225,7 @@ static __u8 via_pram_readbyte(void)
return data;
}
-static void via_pram_writebyte(__u8 data)
+static void via_rtc_send(__u8 data)
{
int i,reg,bit;
@@ -262,17 +262,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_rtc_send((command & 0xFF00) >> 8);
+ via_rtc_send(command & 0xFF);
is_read = command & 0x8000;
} else { /* one-byte command */
- via_pram_writebyte(command);
+ via_rtc_send(command);
is_read = command & 0x80;
}
if (is_read) {
- *data = via_pram_readbyte();
+ *data = via_rtc_recv();
} else {
- via_pram_writebyte(*data);
+ via_rtc_send(*data);
}
/* All done, disable the RTC */
@@ -282,12 +282,12 @@ static void via_pram_command(int command
local_irq_restore(flags);
}
-static __u8 via_read_pram(int offset)
+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)
{
}
@@ -453,50 +453,51 @@ void pmu_shutdown(void)
*-------------------------------------------------------------------
*/
-void mac_pram_read(int offset, __u8 *buffer, int len)
+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)
+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);
}
void mac_poweroff(void)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 24/26] m68k/mac: Use macros for RTC accesses not magic numbers |
| Message-ID | <qpYwH-7a6-23@gated-at.bofh.it> |
| In reply to | #1260130 |
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
This is intended to improve code style and not affect code behaviour.
I've tested this on a Quadra 650.
I don't know the meanings of the 4 undocumented write protect register
bits 0x55, so I decided against defining 4 macros for those bits.
---
arch/m68k/mac/misc.c | 59 +++++++++++++++++++++++++++++++++++----------------
1 file changed, 41 insertions(+), 18 deletions(-)
Index: linux/arch/m68k/mac/misc.c
===================================================================
--- linux.orig/arch/m68k/mac/misc.c 2015-11-01 21:41:55.000000000 +1100
+++ linux/arch/m68k/mac/misc.c 2015-11-01 21:41:56.000000000 +1100
@@ -242,6 +242,21 @@ static void via_rtc_send(__u8 data)
}
/*
+ * These values can be found in Inside Macintosh vol. III ch. 2
+ * which has a description of the RTC chip in the original Mac.
+ */
+
+#define RTC_FLG_READ BIT(7)
+#define RTC_FLG_WRITE_PROTECT BIT(7)
+#define RTC_CMD_READ(r) (RTC_FLG_READ | (r << 2))
+#define RTC_CMD_WRITE(r) (r << 2)
+#define RTC_REG_SECONDS_0 0
+#define RTC_REG_SECONDS_1 1
+#define RTC_REG_SECONDS_2 2
+#define RTC_REG_SECONDS_3 3
+#define RTC_REG_WRITE_PROTECT 13
+
+/*
* Execute a VIA PRAM/RTC command. For read commands
* data should point to a one-byte buffer for the
* resulting data. For write commands it should point
@@ -250,13 +265,17 @@ static void via_rtc_send(__u8 data)
* This function disables all interrupts while running.
*/
-static void via_pram_command(int command, __u8 *data)
+static void via_rtc_command(int command, __u8 *data)
{
unsigned long flags;
int is_read;
local_irq_save(flags);
+ /* The least significant bits must be 0b01 according to Inside Mac */
+
+ command = (command & ~3) | 1;
+
/* Enable the RTC and make sure the strobe line is high */
via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb;
@@ -264,10 +283,10 @@ static void via_pram_command(int command
if (command & 0xFF00) { /* extended (two-byte) command */
via_rtc_send((command & 0xFF00) >> 8);
via_rtc_send(command & 0xFF);
- is_read = command & 0x8000;
+ is_read = command & (RTC_FLG_READ << 8);
} else { /* one-byte command */
via_rtc_send(command);
- is_read = command & 0x80;
+ is_read = command & RTC_FLG_READ;
}
if (is_read) {
*data = via_rtc_recv();
@@ -306,10 +325,10 @@ static long via_read_time(void)
} result, last_result;
int count = 1;
- via_pram_command(0x81, &last_result.cdata[3]);
- via_pram_command(0x85, &last_result.cdata[2]);
- via_pram_command(0x89, &last_result.cdata[1]);
- via_pram_command(0x8D, &last_result.cdata[0]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), &last_result.cdata[3]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), &last_result.cdata[2]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), &last_result.cdata[1]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3), &last_result.cdata[0]);
/*
* The NetBSD guys say to loop until you get the same reading
@@ -317,10 +336,14 @@ static long via_read_time(void)
*/
while (1) {
- via_pram_command(0x81, &result.cdata[3]);
- via_pram_command(0x85, &result.cdata[2]);
- via_pram_command(0x89, &result.cdata[1]);
- via_pram_command(0x8D, &result.cdata[0]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0),
+ &result.cdata[3]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1),
+ &result.cdata[2]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2),
+ &result.cdata[1]);
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3),
+ &result.cdata[0]);
if (result.idata == last_result.idata)
return result.idata - RTC_OFFSET;
@@ -356,18 +379,18 @@ static void via_write_time(long time)
/* Clear the write protect bit */
temp = 0x55;
- via_pram_command(0x35, &temp);
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
data.idata = time + RTC_OFFSET;
- via_pram_command(0x01, &data.cdata[3]);
- via_pram_command(0x05, &data.cdata[2]);
- via_pram_command(0x09, &data.cdata[1]);
- via_pram_command(0x0D, &data.cdata[0]);
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_0), &data.cdata[3]);
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_1), &data.cdata[2]);
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_2), &data.cdata[1]);
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_3), &data.cdata[0]);
/* Set the write protect bit */
- temp = 0xD5;
- via_pram_command(0x35, &temp);
+ temp = 0x55 | RTC_FLG_WRITE_PROTECT;
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
}
static void via_shutdown(void)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 21/26] powerpc: Adopt nvram module for PPC64 |
| Message-ID | <qpYwH-7a6-37@gated-at.bofh.it> |
| In reply to | #1260130 |
Adopt nvram module to reduce code duplication. This means CONFIG_NVRAM
becomes available to CONFIG_PPC64 builds (until now it was only PPC32).
The IOC_NVRAM_GET_OFFSET ioctl as implemented on PPC64 validates the offset
returned by pmac_get_partition(). Add this test to the nvram module.
Note that the old PPC32 generic_nvram module lacked this test.
So when CONFIG_PPC32 && CONFIG_PPC_PMAC, the IOC_NVRAM_GET_OFFSET ioctl
would have returned 0 (always). But when CONFIG_PPC64 && CONFIG_PPC_PMAC,
the IOC_NVRAM_GET_OFFSET ioctl would have returned -1 (which is -EPERM)
when the requested partition was not found.
With this patch, the result is now -EINVAL on both PPC32 and PPC64 when
the requested PowerMac NVRAM partition is not found.
This is a userspace-visible change, in the non-existent partition case,
which would be in an error path for an IOC_NVRAM_GET_OFFSET ioctl syscall.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Tested-by: Laurent Vivier <lvivier@redhat.com>
---
BTW, the IOC_NVRAM_SYNC ioctl call returns -EINVAL on PPC64. This patch
retains this behaviour though it might be better to actually perform a sync.
Both PPC64 and PPC32 kernels implement ppc_md.nvram_sync() for Core99,
but on PPC64 the ioctl is unimplemented (unlike PPC32).
---
Changed since v1:
- The -ENOENT that appeared in v1 was changed to -EINVAL, to be
consistent with existing logic, that is,
if (part < pmac_nvram_OF || part > pmac_nvram_NR)
return -EINVAL;
Changed since v3:
- Fixed comment in powerpc/platforms/pseries/nvram.c
Changed since v6:
- Changed #ifdef condition in pmac_time_init() to be consistent with
that used in fbdev drivers. This avoids any change in behaviour as
CONFIG_NVRAM is made available on PPC64.
---
arch/powerpc/Kconfig | 3
arch/powerpc/kernel/nvram_64.c | 203 ++++---------------------------
arch/powerpc/platforms/powermac/Makefile | 5
arch/powerpc/platforms/powermac/setup.c | 2
arch/powerpc/platforms/powermac/time.c | 2
arch/powerpc/platforms/pseries/nvram.c | 2
drivers/char/nvram.c | 2
7 files changed, 37 insertions(+), 182 deletions(-)
Index: linux/arch/powerpc/Kconfig
===================================================================
--- linux.orig/arch/powerpc/Kconfig 2015-11-01 21:41:48.000000000 +1100
+++ linux/arch/powerpc/Kconfig 2015-11-01 21:41:51.000000000 +1100
@@ -184,10 +184,9 @@ config SYSVIPC_COMPAT
depends on COMPAT && SYSVIPC
default y
-# All PPC32s use generic nvram driver through ppc_md
config HAVE_ARCH_NVRAM_OPS
bool
- default y if PPC32
+ default y
config SCHED_OMIT_FRAME_POINTER
bool
Index: linux/arch/powerpc/kernel/nvram_64.c
===================================================================
--- linux.orig/arch/powerpc/kernel/nvram_64.c 2015-11-01 21:41:23.000000000 +1100
+++ linux/arch/powerpc/kernel/nvram_64.c 2015-11-01 21:41:51.000000000 +1100
@@ -7,12 +7,6 @@
* 2 of the License, or (at your option) any later version.
*
* /dev/nvram driver for PPC64
- *
- * This perhaps should live in drivers/char
- *
- * TODO: Split the /dev/nvram part (that one can use
- * drivers/char/generic_nvram.c) from the arch & partition
- * parsing code.
*/
#include <linux/module.h>
@@ -731,153 +725,6 @@ static void oops_to_nvram(struct kmsg_du
spin_unlock_irqrestore(&lock, flags);
}
-static loff_t dev_nvram_llseek(struct file *file, loff_t offset, int origin)
-{
- int size;
-
- if (ppc_md.nvram_size == NULL)
- return -ENODEV;
- size = ppc_md.nvram_size();
-
- switch (origin) {
- case 1:
- offset += file->f_pos;
- break;
- case 2:
- offset += size;
- break;
- }
- if (offset < 0)
- return -EINVAL;
- file->f_pos = offset;
- return file->f_pos;
-}
-
-
-static ssize_t dev_nvram_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
-{
- ssize_t ret;
- char *tmp = NULL;
- ssize_t size;
-
- if (!ppc_md.nvram_size) {
- ret = -ENODEV;
- goto out;
- }
-
- size = ppc_md.nvram_size();
- if (size < 0) {
- ret = size;
- goto out;
- }
-
- if (*ppos >= size) {
- ret = 0;
- goto out;
- }
-
- count = min_t(size_t, count, size - *ppos);
- count = min(count, PAGE_SIZE);
-
- tmp = kmalloc(count, GFP_KERNEL);
- if (!tmp) {
- ret = -ENOMEM;
- goto out;
- }
-
- ret = ppc_md.nvram_read(tmp, count, ppos);
- if (ret <= 0)
- goto out;
-
- if (copy_to_user(buf, tmp, ret))
- ret = -EFAULT;
-
-out:
- kfree(tmp);
- return ret;
-
-}
-
-static ssize_t dev_nvram_write(struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
-{
- ssize_t ret;
- char *tmp = NULL;
- ssize_t size;
-
- ret = -ENODEV;
- if (!ppc_md.nvram_size)
- goto out;
-
- ret = 0;
- size = ppc_md.nvram_size();
- if (*ppos >= size || size < 0)
- goto out;
-
- count = min_t(size_t, count, size - *ppos);
- count = min(count, PAGE_SIZE);
-
- ret = -ENOMEM;
- tmp = kmalloc(count, GFP_KERNEL);
- if (!tmp)
- goto out;
-
- ret = -EFAULT;
- if (copy_from_user(tmp, buf, count))
- goto out;
-
- ret = ppc_md.nvram_write(tmp, count, ppos);
-
-out:
- kfree(tmp);
- return ret;
-
-}
-
-static long dev_nvram_ioctl(struct file *file, unsigned int cmd,
- unsigned long arg)
-{
- switch(cmd) {
-#ifdef CONFIG_PPC_PMAC
- case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
- printk(KERN_WARNING "nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n");
- case IOC_NVRAM_GET_OFFSET: {
- int part, offset;
-
- if (!machine_is(powermac))
- return -EINVAL;
- if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
- return -EFAULT;
- if (part < pmac_nvram_OF || part > pmac_nvram_NR)
- return -EINVAL;
- offset = pmac_get_partition(part);
- if (offset < 0)
- return offset;
- if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0)
- return -EFAULT;
- return 0;
- }
-#endif /* CONFIG_PPC_PMAC */
- default:
- return -EINVAL;
- }
-}
-
-const struct file_operations nvram_fops = {
- .owner = THIS_MODULE,
- .llseek = dev_nvram_llseek,
- .read = dev_nvram_read,
- .write = dev_nvram_write,
- .unlocked_ioctl = dev_nvram_ioctl,
-};
-
-static struct miscdevice nvram_dev = {
- NVRAM_MINOR,
- "nvram",
- &nvram_fops
-};
-
#ifdef DEBUG_NVRAM
static void __init nvram_print_partitions(char * label)
@@ -1026,6 +873,8 @@ loff_t __init nvram_create_partition(con
long size = 0;
int rc;
+ BUILD_BUG_ON(NVRAM_BLOCK_LEN != 16);
+
/* Convert sizes from bytes to blocks */
req_size = _ALIGN_UP(req_size, NVRAM_BLOCK_LEN) / NVRAM_BLOCK_LEN;
min_size = _ALIGN_UP(min_size, NVRAM_BLOCK_LEN) / NVRAM_BLOCK_LEN;
@@ -1226,29 +1075,41 @@ int __init nvram_scan_partitions(void)
return err;
}
-static int __init nvram_init(void)
+
+#if IS_ENABLED(CONFIG_NVRAM)
+
+static ssize_t ppc_nvram_read(char *buf, size_t count, loff_t *index)
{
- int rc;
-
- BUILD_BUG_ON(NVRAM_BLOCK_LEN != 16);
+ if (ppc_md.nvram_read)
+ return ppc_md.nvram_read(buf, count, index);
+ return -EINVAL;
+}
- if (ppc_md.nvram_size == NULL || ppc_md.nvram_size() <= 0)
- return -ENODEV;
+static ssize_t ppc_nvram_write(char *buf, size_t count, loff_t *index)
+{
+ if (ppc_md.nvram_write)
+ return ppc_md.nvram_write(buf, count, index);
+ return -EINVAL;
+}
- rc = misc_register(&nvram_dev);
- if (rc != 0) {
- printk(KERN_ERR "nvram_init: failed to register device\n");
- return rc;
- }
-
- return rc;
+static ssize_t ppc_nvram_get_size(void)
+{
+ if (ppc_md.nvram_size)
+ return ppc_md.nvram_size();
+ return -ENODEV;
}
-static void __exit nvram_cleanup(void)
+static long ppc_nvram_sync(void)
{
- misc_deregister( &nvram_dev );
+ return -EINVAL;
}
-module_init(nvram_init);
-module_exit(nvram_cleanup);
-MODULE_LICENSE("GPL");
+const struct nvram_ops arch_nvram_ops = {
+ .read = ppc_nvram_read,
+ .write = ppc_nvram_write,
+ .get_size = ppc_nvram_get_size,
+ .sync = ppc_nvram_sync,
+};
+EXPORT_SYMBOL(arch_nvram_ops);
+
+#endif /* CONFIG_NVRAM */
Index: linux/arch/powerpc/platforms/powermac/Makefile
===================================================================
--- linux.orig/arch/powerpc/platforms/powermac/Makefile 2015-11-01 21:41:23.000000000 +1100
+++ linux/arch/powerpc/platforms/powermac/Makefile 2015-11-01 21:41:51.000000000 +1100
@@ -9,11 +9,6 @@ obj-y += pic.o setup.o time.o feature
sleep.o low_i2c.o cache.o pfunc_core.o \
pfunc_base.o udbg_scc.o udbg_adb.o
obj-$(CONFIG_PMAC_BACKLIGHT) += backlight.o
-# CONFIG_NVRAM is an arch. independent tristate symbol, for pmac32 we really
-# need this to be a bool. Cheat here and pretend CONFIG_NVRAM=m is really
-# CONFIG_NVRAM=y
obj-$(CONFIG_NVRAM:m=y) += nvram.o
-# ppc64 pmac doesn't define CONFIG_NVRAM but needs nvram stuff
-obj-$(CONFIG_PPC64) += nvram.o
obj-$(CONFIG_PPC32) += bootx_init.o
obj-$(CONFIG_SMP) += smp.o
Index: linux/arch/powerpc/platforms/powermac/setup.c
===================================================================
--- linux.orig/arch/powerpc/platforms/powermac/setup.c 2015-11-01 21:41:48.000000000 +1100
+++ linux/arch/powerpc/platforms/powermac/setup.c 2015-11-01 21:41:51.000000000 +1100
@@ -321,7 +321,7 @@ static void __init pmac_setup_arch(void)
find_via_pmu();
smu_init();
-#if IS_ENABLED(CONFIG_NVRAM) || defined(CONFIG_PPC64)
+#if IS_ENABLED(CONFIG_NVRAM)
pmac_nvram_init();
#endif
Index: linux/drivers/char/nvram.c
===================================================================
--- linux.orig/drivers/char/nvram.c 2015-11-01 21:41:47.000000000 +1100
+++ linux/drivers/char/nvram.c 2015-11-01 21:41:51.000000000 +1100
@@ -342,6 +342,8 @@ static long nvram_misc_ioctl(struct file
if (part < pmac_nvram_OF || part > pmac_nvram_NR)
return -EINVAL;
offset = pmac_get_partition(part);
+ if (offset < 0)
+ return -EINVAL;
if (copy_to_user((void __user *)arg,
&offset, sizeof(offset)) != 0)
return -EFAULT;
Index: linux/arch/powerpc/platforms/pseries/nvram.c
===================================================================
--- linux.orig/arch/powerpc/platforms/pseries/nvram.c 2015-11-01 21:41:23.000000000 +1100
+++ linux/arch/powerpc/platforms/pseries/nvram.c 2015-11-01 21:41:51.000000000 +1100
@@ -7,8 +7,6 @@
* 2 of the License, or (at your option) any later version.
*
* /dev/nvram driver for PPC64
- *
- * This perhaps should live in drivers/char
*/
Index: linux/arch/powerpc/platforms/powermac/time.c
===================================================================
--- linux.orig/arch/powerpc/platforms/powermac/time.c 2015-11-01 21:41:23.000000000 +1100
+++ linux/arch/powerpc/platforms/powermac/time.c 2015-11-01 21:41:51.000000000 +1100
@@ -68,7 +68,7 @@
long __init pmac_time_init(void)
{
s32 delta = 0;
-#ifdef CONFIG_NVRAM
+#if defined(CONFIG_NVRAM) && defined(CONFIG_PPC32)
int dst;
delta = ((s32)pmac_xpram_read(PMAC_XPRAM_MACHINE_LOC + 0x9)) << 16;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 13/26] powerpc: Add missing ppc_md.nvram_size for CHRP and PowerMac |
| Message-ID | <qpYwH-7a6-39@gated-at.bofh.it> |
| In reply to | #1260130 |
Add the nvram_size() function to those PowerPC platforms that don't already
have one: CHRP and PowerMac. This means that the ppc_md.nvram_size()
function can be used to implement arch_nvram_ops.get_size()
Since we are addressing inconsistencies here, also rename chrp_nvram_read
and chrp_nvram_write, which break the naming convention used across
PowerPC platforms for NVRAM accessor functions.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
arch/powerpc/platforms/chrp/nvram.c | 14 ++++++++++----
arch/powerpc/platforms/powermac/nvram.c | 9 +++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
Index: linux/arch/powerpc/platforms/chrp/nvram.c
===================================================================
--- linux.orig/arch/powerpc/platforms/chrp/nvram.c 2015-11-01 21:41:24.000000000 +1100
+++ linux/arch/powerpc/platforms/chrp/nvram.c 2015-11-01 21:41:39.000000000 +1100
@@ -23,7 +23,7 @@ static unsigned int nvram_size;
static unsigned char nvram_buf[4];
static DEFINE_SPINLOCK(nvram_lock);
-static unsigned char chrp_nvram_read(int addr)
+static unsigned char chrp_nvram_read_byte(int addr)
{
unsigned int done;
unsigned long flags;
@@ -45,7 +45,7 @@ static unsigned char chrp_nvram_read(int
return ret;
}
-static void chrp_nvram_write(int addr, unsigned char val)
+static void chrp_nvram_write_byte(int addr, unsigned char val)
{
unsigned int done;
unsigned long flags;
@@ -63,6 +63,11 @@ static void chrp_nvram_write(int addr, u
spin_unlock_irqrestore(&nvram_lock, flags);
}
+static ssize_t chrp_nvram_size(void)
+{
+ return nvram_size;
+}
+
void __init chrp_nvram_init(void)
{
struct device_node *nvram;
@@ -84,8 +89,9 @@ void __init chrp_nvram_init(void)
printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);
of_node_put(nvram);
- ppc_md.nvram_read_val = chrp_nvram_read;
- ppc_md.nvram_write_val = chrp_nvram_write;
+ ppc_md.nvram_read_val = chrp_nvram_read_byte;
+ ppc_md.nvram_write_val = chrp_nvram_write_byte;
+ ppc_md.nvram_size = chrp_nvram_size;
return;
}
Index: linux/arch/powerpc/platforms/powermac/nvram.c
===================================================================
--- linux.orig/arch/powerpc/platforms/powermac/nvram.c 2015-11-01 21:41:24.000000000 +1100
+++ linux/arch/powerpc/platforms/powermac/nvram.c 2015-11-01 21:41:39.000000000 +1100
@@ -147,6 +147,11 @@ static ssize_t core99_nvram_size(void)
static volatile unsigned char __iomem *nvram_addr;
static int nvram_mult;
+static ssize_t ppc32_nvram_size(void)
+{
+ return NVRAM_SIZE;
+}
+
static unsigned char direct_nvram_read_byte(int addr)
{
return in_8(&nvram_data[(addr & (NVRAM_SIZE - 1)) * nvram_mult]);
@@ -590,21 +595,25 @@ int __init pmac_nvram_init(void)
nvram_mult = 1;
ppc_md.nvram_read_val = direct_nvram_read_byte;
ppc_md.nvram_write_val = direct_nvram_write_byte;
+ ppc_md.nvram_size = ppc32_nvram_size;
} else if (nvram_naddrs == 1) {
nvram_data = ioremap(r1.start, s1);
nvram_mult = (s1 + NVRAM_SIZE - 1) / NVRAM_SIZE;
ppc_md.nvram_read_val = direct_nvram_read_byte;
ppc_md.nvram_write_val = direct_nvram_write_byte;
+ ppc_md.nvram_size = ppc32_nvram_size;
} else if (nvram_naddrs == 2) {
nvram_addr = ioremap(r1.start, s1);
nvram_data = ioremap(r2.start, s2);
ppc_md.nvram_read_val = indirect_nvram_read_byte;
ppc_md.nvram_write_val = indirect_nvram_write_byte;
+ ppc_md.nvram_size = ppc32_nvram_size;
} else if (nvram_naddrs == 0 && sys_ctrler == SYS_CTRLER_PMU) {
#ifdef CONFIG_ADB_PMU
nvram_naddrs = -1;
ppc_md.nvram_read_val = pmu_nvram_read_byte;
ppc_md.nvram_write_val = pmu_nvram_write_byte;
+ ppc_md.nvram_size = ppc32_nvram_size;
#endif /* CONFIG_ADB_PMU */
} else {
printk(KERN_ERR "Incompatible type of NVRAM\n");
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 16/26] powerpc, fbdev: Use NV_CMODE and NV_VMODE only when CONFIG_PPC32 and CONFIG_PPC_PMAC and CONFIG_NVRAM |
| Message-ID | <qpYwH-7a6-25@gated-at.bofh.it> |
| In reply to | #1260130 |
This patch addresses inconsistencies in Mac framebuffer drivers and their
use of Kconfig symbols relating to NVRAM, so PPC64 can use CONFIG_NVRAM.
Macintosh framebuffer drivers use default settings for color mode and
video mode that are found in NVRAM. On PCI Macs, MacOS stores display
settings in the Name Registry (NR) partition in NVRAM*. On NuBus Macs,
there is no NR partition and MacOS stores display mode settings in PRAM**.
Early model Macs are the ones most likely to benefit from these settings,
since they are more likely to have one display: a fixed-frequency monitor
connected to the built-in framebuffer device. Moreover, a single NV_CMODE
value and a single NV_VMODE value provide for only one display.
The NV_CMODE and NV_VMODE constants are apparently offsets into the NR
partition for Old World machines and not New World, which also suggests
that these defaults are not useful on later models.
All this argues for limiting NVRAM support in PowerMac fbdev drivers to
PPC32 and indeed this is already the case, since CONFIG_NVRAM cannot be
enabled on PPC64 at present.
For matroxfb, make the CONFIG_PPC32 condition explicit. That way the
driver won't crash on PPC64 when CONFIG_NVRAM becomes available there.
In imsttfb, add the missing CONFIG_NVRAM test to prevent a build failure,
since PPC64 does not implement nvram_read_byte(). Also add a missing
machine_is(powermac) check. Change the inconsistent CONFIG_PPC dependency
and the matching #ifdef tests to CONFIG_PPC_PMAC. Drop unused #includes.
In valkyriefb, for clarity and consistency with the other PowerMac fbdev
drivers, test for CONFIG_PPC_PMAC instead of !CONFIG_MAC. Remove a
bogus comment regarding PRAM.
* See GetPreferredConfiguration and SavePreferredConfiguration in
"Designing PCI Cards and Drivers for Power Macintosh Computers".
** See SetDefaultMode and GetDefaultMode in "Designing Cards and Drivers
for the Macintosh Family".
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
drivers/video/fbdev/Kconfig | 2 +-
drivers/video/fbdev/imsttfb.c | 13 +++++--------
drivers/video/fbdev/matrox/matroxfb_base.c | 2 +-
drivers/video/fbdev/valkyriefb.c | 14 ++++++--------
4 files changed, 13 insertions(+), 18 deletions(-)
Index: linux/drivers/video/fbdev/Kconfig
===================================================================
--- linux.orig/drivers/video/fbdev/Kconfig 2015-11-01 21:41:23.000000000 +1100
+++ linux/drivers/video/fbdev/Kconfig 2015-11-01 21:41:43.000000000 +1100
@@ -544,7 +544,7 @@ config FB_IMSTT
bool "IMS Twin Turbo display support"
depends on (FB = y) && PCI
select FB_CFB_IMAGEBLIT
- select FB_MACMODES if PPC
+ select FB_MACMODES if PPC_PMAC
help
The IMS Twin Turbo is a PCI-based frame buffer card bundled with
many Macintosh and compatible computers.
Index: linux/drivers/video/fbdev/imsttfb.c
===================================================================
--- linux.orig/drivers/video/fbdev/imsttfb.c 2015-11-01 21:41:23.000000000 +1100
+++ linux/drivers/video/fbdev/imsttfb.c 2015-11-01 21:41:43.000000000 +1100
@@ -30,10 +30,8 @@
#include <asm/io.h>
#include <linux/uaccess.h>
-#if defined(CONFIG_PPC)
+#if defined(CONFIG_PPC_PMAC)
#include <linux/nvram.h>
-#include <asm/prom.h>
-#include <asm/pci-bridge.h>
#include "macmodes.h"
#endif
@@ -328,14 +326,13 @@ enum {
TVP = 1
};
-#define USE_NV_MODES 1
#define INIT_BPP 8
#define INIT_XRES 640
#define INIT_YRES 480
static int inverse = 0;
static char fontname[40] __initdata = { 0 };
-#if defined(CONFIG_PPC)
+#if defined(CONFIG_PPC_PMAC)
static signed char init_vmode = -1, init_cmode = -1;
#endif
@@ -1391,8 +1388,8 @@ static void init_imstt(struct fb_info *i
}
}
-#if USE_NV_MODES && defined(CONFIG_PPC32)
- {
+#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) && defined(CONFIG_NVRAM)
+ if (machine_is(powermac)) {
int vmode = init_vmode, cmode = init_cmode;
if (vmode == -1) {
@@ -1566,7 +1563,7 @@ imsttfb_setup(char *options)
inverse = 1;
fb_invert_cmaps();
}
-#if defined(CONFIG_PPC)
+#if defined(CONFIG_PPC_PMAC)
else if (!strncmp(this_opt, "vmode:", 6)) {
int vmode = simple_strtoul(this_opt+6, NULL, 0);
if (vmode > 0 && vmode <= VMODE_MAX)
Index: linux/drivers/video/fbdev/matrox/matroxfb_base.c
===================================================================
--- linux.orig/drivers/video/fbdev/matrox/matroxfb_base.c 2015-11-01 21:41:38.000000000 +1100
+++ linux/drivers/video/fbdev/matrox/matroxfb_base.c 2015-11-01 21:41:43.000000000 +1100
@@ -1876,7 +1876,7 @@ static int initMatrox2(struct matrox_fb_
struct fb_var_screeninfo var;
if (default_vmode <= 0 || default_vmode > VMODE_MAX)
default_vmode = VMODE_640_480_60;
-#ifdef CONFIG_NVRAM
+#if defined(CONFIG_PPC32) && defined(CONFIG_NVRAM)
if (default_cmode == CMODE_NVRAM)
default_cmode = nvram_read_byte(NV_CMODE);
#endif
Index: linux/drivers/video/fbdev/valkyriefb.c
===================================================================
--- linux.orig/drivers/video/fbdev/valkyriefb.c 2015-11-01 21:41:23.000000000 +1100
+++ linux/drivers/video/fbdev/valkyriefb.c 2015-11-01 21:41:43.000000000 +1100
@@ -65,14 +65,12 @@
#include "macmodes.h"
#include "valkyriefb.h"
-#ifdef CONFIG_MAC
-/* We don't yet have functions to read the PRAM... perhaps we can
- adapt them from the PPC code? */
-static int default_vmode = VMODE_CHOOSE;
-static int default_cmode = CMODE_8;
-#else
+#ifdef CONFIG_PPC_PMAC
static int default_vmode = VMODE_NVRAM;
static int default_cmode = CMODE_NVRAM;
+#else
+static int default_vmode = VMODE_CHOOSE;
+static int default_cmode = CMODE_8;
#endif
struct fb_par_valkyrie {
@@ -285,7 +283,7 @@ static void __init valkyrie_choose_mode(
printk(KERN_INFO "Monitor sense value = 0x%x\n", p->sense);
/* Try to pick a video mode out of NVRAM if we have one. */
-#if !defined(CONFIG_MAC) && defined(CONFIG_NVRAM)
+#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_NVRAM)
if (default_vmode == VMODE_NVRAM) {
default_vmode = nvram_read_byte(NV_VMODE);
if (default_vmode <= 0
@@ -298,7 +296,7 @@ static void __init valkyrie_choose_mode(
default_vmode = mac_map_monitor_sense(p->sense);
if (!valkyrie_reg_init[default_vmode - 1])
default_vmode = VMODE_640_480_67;
-#if !defined(CONFIG_MAC) && defined(CONFIG_NVRAM)
+#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_NVRAM)
if (default_cmode == CMODE_NVRAM)
default_cmode = nvram_read_byte(NV_CMODE);
#endif
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 09/26] char/nvram: Use generic fixed_size_llseek() |
| Message-ID | <qpYwH-7a6-41@gated-at.bofh.it> |
| In reply to | #1260130 |
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
drivers/char/nvram.c | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
Index: linux/drivers/char/nvram.c
===================================================================
--- linux.orig/drivers/char/nvram.c 2015-11-01 21:41:34.000000000 +1100
+++ linux/drivers/char/nvram.c 2015-11-01 21:41:35.000000000 +1100
@@ -235,21 +235,7 @@ EXPORT_SYMBOL(arch_nvram_ops);
static loff_t nvram_misc_llseek(struct file *file, loff_t offset, int origin)
{
- switch (origin) {
- case 0:
- /* nothing to do */
- break;
- case 1:
- offset += file->f_pos;
- break;
- case 2:
- offset += NVRAM_BYTES;
- break;
- default:
- return -EINVAL;
- }
-
- return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
+ return fixed_size_llseek(file, offset, origin, nvram_size);
}
static ssize_t nvram_misc_read(struct file *file, char __user *buf,
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 10/26] m68k/atari: Implement arch_nvram_ops methods and enable CONFIG_HAVE_ARCH_NVRAM_OPS |
| Message-ID | <qpYwH-7a6-43@gated-at.bofh.it> |
| In reply to | #1260130 |
Atari RTC NVRAM has a checksum so implement the remaining arch_nvram_ops
methods for the set_checksum and initialize ioctls. Enable
CONFIG_HAVE_ARCH_NVRAM_OPS.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
This re-enables the nvram module for Atari.
Changes since v3:
- Use bool (and select) instead of def_bool in the definition of the
HAVE_ARCH_NVRAM_OPS Kconfig symbol, as requested by Geert.
---
arch/m68k/Kconfig | 3 +++
arch/m68k/Kconfig.machine | 1 +
arch/m68k/atari/nvram.c | 24 ++++++++++++++++++++++++
drivers/char/Kconfig | 2 +-
4 files changed, 29 insertions(+), 1 deletion(-)
Index: linux/arch/m68k/atari/nvram.c
===================================================================
--- linux.orig/arch/m68k/atari/nvram.c 2015-11-01 21:41:27.000000000 +1100
+++ linux/arch/m68k/atari/nvram.c 2015-11-01 21:41:36.000000000 +1100
@@ -73,6 +73,26 @@ static void __nvram_set_checksum(void)
__nvram_write_byte(sum, ATARI_CKS_LOC + 1);
}
+static long nvram_set_checksum(void)
+{
+ spin_lock_irq(&rtc_lock);
+ __nvram_set_checksum();
+ spin_unlock_irq(&rtc_lock);
+ return 0;
+}
+
+static long nvram_initialize(void)
+{
+ loff_t i;
+
+ spin_lock_irq(&rtc_lock);
+ for (i = 0; i < NVRAM_BYTES; ++i)
+ __nvram_write_byte(0, i);
+ __nvram_set_checksum();
+ spin_unlock_irq(&rtc_lock);
+ return 0;
+}
+
static ssize_t nvram_read(char *buf, size_t count, loff_t *ppos)
{
char *p = buf;
@@ -119,6 +139,8 @@ static ssize_t nvram_write(char *buf, si
static ssize_t nvram_get_size(void)
{
+ if (!MACH_IS_ATARI)
+ return -ENODEV;
return NVRAM_BYTES;
}
@@ -126,6 +148,8 @@ 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,
};
EXPORT_SYMBOL(arch_nvram_ops);
Index: linux/drivers/char/Kconfig
===================================================================
--- linux.orig/drivers/char/Kconfig 2015-11-01 21:41:24.000000000 +1100
+++ linux/drivers/char/Kconfig 2015-11-01 21:41:36.000000000 +1100
@@ -247,7 +247,7 @@ source "drivers/char/hw_random/Kconfig"
config NVRAM
tristate "/dev/nvram support"
- depends on X86 || (ARM && RTC_DRV_CMOS) || GENERIC_NVRAM
+ depends on X86 || (ARM && RTC_DRV_CMOS) || GENERIC_NVRAM || HAVE_ARCH_NVRAM_OPS
---help---
If you say Y here and create a character special file /dev/nvram
with major number 10 and minor number 144 using mknod ("man mknod"),
Index: linux/arch/m68k/Kconfig
===================================================================
--- linux.orig/arch/m68k/Kconfig 2015-11-01 21:41:24.000000000 +1100
+++ linux/arch/m68k/Kconfig 2015-11-01 21:41:36.000000000 +1100
@@ -71,6 +71,9 @@ config PGTABLE_LEVELS
default 2 if SUN3 || COLDFIRE
default 3
+config HAVE_ARCH_NVRAM_OPS
+ bool
+
source "init/Kconfig"
source "kernel/Kconfig.freezer"
Index: linux/arch/m68k/Kconfig.machine
===================================================================
--- linux.orig/arch/m68k/Kconfig.machine 2015-11-01 21:41:24.000000000 +1100
+++ linux/arch/m68k/Kconfig.machine 2015-11-01 21:41:36.000000000 +1100
@@ -15,6 +15,7 @@ config ATARI
bool "Atari support"
depends on MMU
select MMU_MOTOROLA if MMU
+ select HAVE_ARCH_NVRAM_OPS
help
This option enables support for the 68000-based Atari series of
computers (including the TT, Falcon and Medusa). If you plan to use
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 05/26] char/nvram: Adopt arch_nvram_ops |
| Message-ID | <qpYwH-7a6-45@gated-at.bofh.it> |
| In reply to | #1260130 |
Different platforms and architectures offer different NVRAM sizes and
access methods. E.g. PPC32 has byte-at-a-time read/write functions whereas
PPC64 has byte-range read/write functions. Adopt the nvram_ops struct so
the nvram module can call such functions as are defined by the various
platforms and architectures.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
The #ifdefs here restrict the procfs and checksumming code to those
architectures with PC-style RTC NVRAM. There may be a better place for
that code but it's an open question. See https://lkml.org/lkml/2015/2/3/22
The procfs code here, unless relevant to an ARM platform, could be moved to
arch/x86 (like the earlier patch does for m68k code) and the nvram ops
could be implemented and exported by the rtc-cmos driver instead. This
would eliminate these #ifdefs and almost eliminate the arch-specific code.
---
drivers/char/nvram.c | 30 +++++++++++++++++++++++++++---
include/linux/nvram.h | 2 ++
2 files changed, 29 insertions(+), 3 deletions(-)
Index: linux/drivers/char/nvram.c
===================================================================
--- linux.orig/drivers/char/nvram.c 2015-11-01 21:41:29.000000000 +1100
+++ linux/drivers/char/nvram.c 2015-11-01 21:41:30.000000000 +1100
@@ -51,9 +51,12 @@ static DEFINE_MUTEX(nvram_mutex);
static DEFINE_SPINLOCK(nvram_state_lock);
static int nvram_open_cnt; /* #times opened */
static int nvram_open_mode; /* special open modes */
+static ssize_t nvram_size;
#define NVRAM_WRITE 1 /* opened for writing (exclusive) */
#define NVRAM_EXCL 2 /* opened with O_EXCL */
+#if defined(CONFIG_X86) || defined(CONFIG_ARM)
+
/*
* These functions are provided to be called internally or by other parts of
* the kernel. It's up to the caller to ensure correct checksum before reading
@@ -161,6 +164,20 @@ void nvram_set_checksum(void)
}
#endif /* 0 */
+static ssize_t nvram_get_size(void)
+{
+ return NVRAM_BYTES;
+}
+
+const struct nvram_ops arch_nvram_ops = {
+ .read_byte = nvram_read_byte,
+ .write_byte = nvram_write_byte,
+ .get_size = nvram_get_size,
+};
+EXPORT_SYMBOL(arch_nvram_ops);
+
+#endif /* CONFIG_X86 || CONFIG_ARM */
+
/*
* The are the file operation function for user access to /dev/nvram
*/
@@ -332,7 +349,7 @@ static int nvram_misc_release(struct ino
return 0;
}
-#ifdef CONFIG_PROC_FS
+#if defined(CONFIG_PROC_FS) && (defined(CONFIG_X86) || defined(CONFIG_ARM))
static char *floppy_types[] = {
"none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M",
@@ -459,13 +476,20 @@ static int __init nvram_module_init(void
{
int ret;
+ if (arch_nvram_ops.get_size == NULL)
+ return -ENODEV;
+
+ nvram_size = arch_nvram_ops.get_size();
+ if (nvram_size < 0)
+ return nvram_size;
+
ret = misc_register(&nvram_misc);
if (ret) {
pr_err("nvram: can't misc_register on minor=%d\n", NVRAM_MINOR);
return ret;
}
-#ifdef CONFIG_PROC_FS
+#if defined(CONFIG_PROC_FS) && (defined(CONFIG_X86) || defined(CONFIG_ARM))
if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops)) {
pr_err("nvram: can't create /proc/driver/nvram\n");
misc_deregister(&nvram_misc);
@@ -479,7 +503,7 @@ static int __init nvram_module_init(void
static void __exit nvram_module_exit(void)
{
-#ifdef CONFIG_PROC_FS
+#if defined(CONFIG_PROC_FS) && (defined(CONFIG_X86) || defined(CONFIG_ARM))
remove_proc_entry("driver/nvram", NULL);
#endif
misc_deregister(&nvram_misc);
Index: linux/include/linux/nvram.h
===================================================================
--- linux.orig/include/linux/nvram.h 2015-11-01 21:41:27.000000000 +1100
+++ linux/include/linux/nvram.h 2015-11-01 21:41:30.000000000 +1100
@@ -14,6 +14,8 @@ extern int nvram_check_checksum(void);
struct nvram_ops {
ssize_t (*read)(char *, size_t, loff_t *);
ssize_t (*write)(char *, size_t, loff_t *);
+ unsigned char (*read_byte)(int);
+ void (*write_byte)(unsigned char, int);
ssize_t (*get_size)(void);
};
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 02/26] m68k/atari: Move Atari-specific code out of drivers/char/nvram.c |
| Message-ID | <qpYwH-7a6-29@gated-at.bofh.it> |
| In reply to | #1260130 |
Move the m68k-specific code elsewhere to make the driver generic.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Tested-by: Christian T. Steigies <cts@debian.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Changes since v3:
- Move the vmode fix to a separate patch as requested by Geert.
---
arch/m68k/atari/Makefile | 2
arch/m68k/atari/nvram.c | 255 ++++++++++++++++++++++++++++++++++++++++++
drivers/char/nvram.c | 280 +++++------------------------------------------
3 files changed, 292 insertions(+), 245 deletions(-)
Index: linux/arch/m68k/atari/nvram.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux/arch/m68k/atari/nvram.c 2015-11-01 21:41:25.000000000 +1100
@@ -0,0 +1,255 @@
+/*
+ * CMOS/NV-RAM driver for Atari. Adapted from drivers/char/nvram.c.
+ * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
+ * idea by and with help from Richard Jelinek <rj@suse.de>
+ * Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com)
+ * Further contributions from Cesar Barros, Erik Gilling, Tim Hockin and
+ * Wim Van Sebroeck.
+ */
+
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/mc146818rtc.h>
+#include <linux/module.h>
+#include <linux/nvram.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
+#include <asm/atarihw.h>
+#include <asm/atariints.h>
+
+#define NVRAM_BYTES 50
+
+/* It is worth noting that these functions all access bytes of general
+ * purpose memory in the NVRAM - that is to say, they all add the
+ * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not
+ * know about the RTC cruft.
+ */
+
+/* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
+ * rtc_lock held. Due to the index-port/data-port design of the RTC, we
+ * don't want two different things trying to get to it at once. (e.g. the
+ * periodic 11 min sync from kernel/time/ntp.c vs. this driver.)
+ */
+
+unsigned char __nvram_read_byte(int i)
+{
+ return CMOS_READ(NVRAM_FIRST_BYTE + i);
+}
+
+unsigned char nvram_read_byte(int i)
+{
+ unsigned long flags;
+ unsigned char c;
+
+ spin_lock_irqsave(&rtc_lock, flags);
+ c = __nvram_read_byte(i);
+ spin_unlock_irqrestore(&rtc_lock, flags);
+ return c;
+}
+EXPORT_SYMBOL(nvram_read_byte);
+
+/* This races nicely with trying to read with checksum checking */
+void __nvram_write_byte(unsigned char c, int i)
+{
+ CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
+}
+
+void nvram_write_byte(unsigned char c, int i)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&rtc_lock, flags);
+ __nvram_write_byte(c, i);
+ spin_unlock_irqrestore(&rtc_lock, flags);
+}
+
+/* On Ataris, the checksum is over all bytes except the checksum bytes
+ * themselves; these are at the very end.
+ */
+#define ATARI_CKS_RANGE_START 0
+#define ATARI_CKS_RANGE_END 47
+#define ATARI_CKS_LOC 48
+
+int __nvram_check_checksum(void)
+{
+ int i;
+ unsigned char sum = 0;
+
+ for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
+ sum += __nvram_read_byte(i);
+ return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff)) &&
+ (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff));
+}
+
+int nvram_check_checksum(void)
+{
+ unsigned long flags;
+ int rv;
+
+ spin_lock_irqsave(&rtc_lock, flags);
+ rv = __nvram_check_checksum();
+ spin_unlock_irqrestore(&rtc_lock, flags);
+ return rv;
+}
+EXPORT_SYMBOL(nvram_check_checksum);
+
+static void __nvram_set_checksum(void)
+{
+ int i;
+ unsigned char sum = 0;
+
+ for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
+ sum += __nvram_read_byte(i);
+ __nvram_write_byte(~sum, ATARI_CKS_LOC);
+ __nvram_write_byte(sum, ATARI_CKS_LOC + 1);
+}
+
+#ifdef CONFIG_PROC_FS
+static struct {
+ unsigned char val;
+ char *name;
+} boot_prefs[] = {
+ { 0x80, "TOS" },
+ { 0x40, "ASV" },
+ { 0x20, "NetBSD (?)" },
+ { 0x10, "Linux" },
+ { 0x00, "unspecified" },
+};
+
+static char *languages[] = {
+ "English (US)",
+ "German",
+ "French",
+ "English (UK)",
+ "Spanish",
+ "Italian",
+ "6 (undefined)",
+ "Swiss (French)",
+ "Swiss (German)",
+};
+
+static char *dateformat[] = {
+ "MM%cDD%cYY",
+ "DD%cMM%cYY",
+ "YY%cMM%cDD",
+ "YY%cDD%cMM",
+ "4 (undefined)",
+ "5 (undefined)",
+ "6 (undefined)",
+ "7 (undefined)",
+};
+
+static char *colors[] = {
+ "2", "4", "16", "256", "65536", "??", "??", "??"
+};
+
+static void atari_nvram_proc_read(unsigned char *nvram, struct seq_file *seq,
+ void *offset)
+{
+ int checksum;
+ int i;
+ unsigned vmode;
+
+ spin_lock_irq(&rtc_lock);
+ checksum = __nvram_check_checksum();
+ spin_unlock_irq(&rtc_lock);
+
+ seq_printf(seq, "Checksum status : %svalid\n", checksum ? "" : "not ");
+
+ seq_puts(seq, "Boot preference : ");
+ for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i)
+ if (nvram[1] == boot_prefs[i].val) {
+ seq_printf(seq, "%s\n", boot_prefs[i].name);
+ break;
+ }
+ if (i < 0)
+ seq_printf(seq, "0x%02x (undefined)\n", nvram[1]);
+
+ seq_printf(seq, "SCSI arbitration : %s\n",
+ (nvram[16] & 0x80) ? "on" : "off");
+ seq_puts(seq, "SCSI host ID : ");
+ if (nvram[16] & 0x80)
+ seq_printf(seq, "%d\n", nvram[16] & 7);
+ else
+ seq_puts(seq, "n/a\n");
+
+ if (!MACH_IS_FALCON)
+ return;
+
+ seq_puts(seq, "OS language : ");
+ if (nvram[6] < ARRAY_SIZE(languages))
+ seq_printf(seq, "%s\n", languages[nvram[6]]);
+ else
+ seq_printf(seq, "%u (undefined)\n", nvram[6]);
+ seq_puts(seq, "Keyboard language: ");
+ if (nvram[7] < ARRAY_SIZE(languages))
+ seq_printf(seq, "%s\n", languages[nvram[7]]);
+ else
+ seq_printf(seq, "%u (undefined)\n", nvram[7]);
+ seq_puts(seq, "Date format : ");
+ seq_printf(seq, dateformat[nvram[8] & 7],
+ nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/');
+ seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12);
+ seq_puts(seq, "Boot delay : ");
+ if (nvram[10] == 0)
+ seq_puts(seq, "default");
+ else
+ seq_printf(seq, "%ds%s\n", nvram[10],
+ nvram[10] < 8 ? ", no memory test" : "");
+
+ vmode = (nvram[14] << 8) | nvram[15];
+ seq_printf(seq,
+ "Video mode : %s colors, %d columns, %s %s monitor\n",
+ colors[vmode & 7], vmode & 8 ? 80 : 40,
+ vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC");
+ seq_printf(seq,
+ " %soverscan, compat. mode %s%s\n",
+ vmode & 64 ? "" : "no ", vmode & 128 ? "on" : "off",
+ vmode & 256 ?
+ (vmode & 16 ? ", line doubling" : ", half screen") : "");
+}
+
+static int nvram_proc_read(struct seq_file *seq, void *offset)
+{
+ unsigned char contents[NVRAM_BYTES];
+ int i;
+
+ spin_lock_irq(&rtc_lock);
+ for (i = 0; i < NVRAM_BYTES; ++i)
+ contents[i] = __nvram_read_byte(i);
+ spin_unlock_irq(&rtc_lock);
+
+ atari_nvram_proc_read(contents, seq, offset);
+
+ return 0;
+}
+
+static int nvram_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, nvram_proc_read, NULL);
+}
+
+static const struct file_operations nvram_proc_fops = {
+ .owner = THIS_MODULE,
+ .open = nvram_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int __init atari_nvram_init(void)
+{
+ if (!(MACH_IS_ATARI && ATARIHW_PRESENT(TT_CLK)))
+ return -ENODEV;
+
+ if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops)) {
+ pr_err("nvram: can't create /proc/driver/nvram\n");
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+device_initcall(atari_nvram_init);
+#endif /* CONFIG_PROC_FS */
Index: linux/arch/m68k/atari/Makefile
===================================================================
--- linux.orig/arch/m68k/atari/Makefile 2015-11-01 21:41:24.000000000 +1100
+++ linux/arch/m68k/atari/Makefile 2015-11-01 21:41:25.000000000 +1100
@@ -6,3 +6,5 @@ obj-y := config.o time.o debug.o ataint
atasound.o stram.o
obj-$(CONFIG_ATARI_KBD_CORE) += atakeyb.o
+
+obj-$(CONFIG_NVRAM:m=y) += nvram.o
Index: linux/drivers/char/nvram.c
===================================================================
--- linux.orig/drivers/char/nvram.c 2015-11-01 21:41:24.000000000 +1100
+++ linux/drivers/char/nvram.c 2015-11-01 21:41:25.000000000 +1100
@@ -21,13 +21,6 @@
* ioctl(NVRAM_SETCKS) (doesn't change contents, just makes checksum valid
* again; use with care!)
*
- * This file also provides some functions for other parts of the kernel that
- * want to access the NVRAM: nvram_{read,write,check_checksum,set_checksum}.
- * Obviously this can be used only if this driver is always configured into
- * the kernel and is not a module. Since the functions are used by some Atari
- * drivers, this is the case on the Atari.
- *
- *
* 1.1 Cesar Barros: SMP locking fixes
* added changelog
* 1.2 Erik Gilling: Cobalt Networks support
@@ -39,64 +32,6 @@
#include <linux/module.h>
#include <linux/nvram.h>
-
-#define PC 1
-#define ATARI 2
-
-/* select machine configuration */
-#if defined(CONFIG_ATARI)
-# define MACH ATARI
-#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and ?? */
-# define MACH PC
-#else
-# error Cannot build nvram driver for this machine configuration.
-#endif
-
-#if MACH == PC
-
-/* RTC in a PC */
-#define CHECK_DRIVER_INIT() 1
-
-/* On PCs, the checksum is built only over bytes 2..31 */
-#define PC_CKS_RANGE_START 2
-#define PC_CKS_RANGE_END 31
-#define PC_CKS_LOC 32
-#define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
-
-#define mach_check_checksum pc_check_checksum
-#define mach_set_checksum pc_set_checksum
-#define mach_proc_infos pc_proc_infos
-
-#endif
-
-#if MACH == ATARI
-
-/* Special parameters for RTC in Atari machines */
-#include <asm/atarihw.h>
-#include <asm/atariints.h>
-#define RTC_PORT(x) (TT_RTC_BAS + 2*(x))
-#define CHECK_DRIVER_INIT() (MACH_IS_ATARI && ATARIHW_PRESENT(TT_CLK))
-
-#define NVRAM_BYTES 50
-
-/* On Ataris, the checksum is over all bytes except the checksum bytes
- * themselves; these are at the very end */
-#define ATARI_CKS_RANGE_START 0
-#define ATARI_CKS_RANGE_END 47
-#define ATARI_CKS_LOC 48
-
-#define mach_check_checksum atari_check_checksum
-#define mach_set_checksum atari_set_checksum
-#define mach_proc_infos atari_proc_infos
-
-#endif
-
-/* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
- * rtc_lock held. Due to the index-port/data-port design of the RTC, we
- * don't want two different things trying to get to it at once. (e.g. the
- * periodic 11 min sync from kernel/time/ntp.c vs. this driver.)
- */
-
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
@@ -119,12 +54,9 @@ static int nvram_open_mode; /* special o
#define NVRAM_WRITE 1 /* opened for writing (exclusive) */
#define NVRAM_EXCL 2 /* opened with O_EXCL */
-static int mach_check_checksum(void);
-static void mach_set_checksum(void);
-
#ifdef CONFIG_PROC_FS
-static void mach_proc_infos(unsigned char *contents, struct seq_file *seq,
- void *offset);
+static void pc_nvram_proc_read(unsigned char *contents, struct seq_file *seq,
+ void *offset);
#endif
/*
@@ -138,6 +70,14 @@ static void mach_proc_infos(unsigned cha
* know about the RTC cruft.
*/
+#define NVRAM_BYTES (128 - NVRAM_FIRST_BYTE)
+
+/* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
+ * rtc_lock held. Due to the index-port/data-port design of the RTC, we
+ * don't want two different things trying to get to it at once. (e.g. the
+ * periodic 11 min sync from kernel/time/ntp.c vs. this driver.)
+ */
+
unsigned char __nvram_read_byte(int i)
{
return CMOS_READ(NVRAM_FIRST_BYTE + i);
@@ -173,9 +113,22 @@ void nvram_write_byte(unsigned char c, i
}
EXPORT_SYMBOL(nvram_write_byte);
+/* On PCs, the checksum is built only over bytes 2..31 */
+#define PC_CKS_RANGE_START 2
+#define PC_CKS_RANGE_END 31
+#define PC_CKS_LOC 32
+
int __nvram_check_checksum(void)
{
- return mach_check_checksum();
+ int i;
+ unsigned short sum = 0;
+ unsigned short expect;
+
+ for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i)
+ sum += __nvram_read_byte(i);
+ expect = __nvram_read_byte(PC_CKS_LOC)<<8 |
+ __nvram_read_byte(PC_CKS_LOC+1);
+ return (sum & 0xffff) == expect;
}
EXPORT_SYMBOL(__nvram_check_checksum);
@@ -193,7 +146,13 @@ EXPORT_SYMBOL(nvram_check_checksum);
static void __nvram_set_checksum(void)
{
- mach_set_checksum();
+ int i;
+ unsigned short sum = 0;
+
+ for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i)
+ sum += __nvram_read_byte(i);
+ __nvram_write_byte(sum >> 8, PC_CKS_LOC);
+ __nvram_write_byte(sum & 0xff, PC_CKS_LOC + 1);
}
#if 0
@@ -396,7 +355,7 @@ static int nvram_proc_read(struct seq_fi
contents[i] = __nvram_read_byte(i);
spin_unlock_irq(&rtc_lock);
- mach_proc_infos(contents, seq, offset);
+ pc_nvram_proc_read(contents, seq, offset);
return 0;
}
@@ -443,10 +402,6 @@ static int __init nvram_init(void)
{
int ret;
- /* First test whether the driver should init at all */
- if (!CHECK_DRIVER_INIT())
- return -ENODEV;
-
ret = misc_register(&nvram_dev);
if (ret) {
printk(KERN_ERR "nvram: can't misc_register on minor=%d\n",
@@ -476,36 +431,6 @@ static void __exit nvram_cleanup_module(
module_init(nvram_init);
module_exit(nvram_cleanup_module);
-/*
- * Machine specific functions
- */
-
-#if MACH == PC
-
-static int pc_check_checksum(void)
-{
- int i;
- unsigned short sum = 0;
- unsigned short expect;
-
- for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i)
- sum += __nvram_read_byte(i);
- expect = __nvram_read_byte(PC_CKS_LOC)<<8 |
- __nvram_read_byte(PC_CKS_LOC+1);
- return (sum & 0xffff) == expect;
-}
-
-static void pc_set_checksum(void)
-{
- int i;
- unsigned short sum = 0;
-
- for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i)
- sum += __nvram_read_byte(i);
- __nvram_write_byte(sum >> 8, PC_CKS_LOC);
- __nvram_write_byte(sum & 0xff, PC_CKS_LOC + 1);
-}
-
#ifdef CONFIG_PROC_FS
static char *floppy_types[] = {
@@ -520,8 +445,8 @@ static char *gfx_types[] = {
"monochrome",
};
-static void pc_proc_infos(unsigned char *nvram, struct seq_file *seq,
- void *offset)
+static void pc_nvram_proc_read(unsigned char *nvram, struct seq_file *seq,
+ void *offset)
{
int checksum;
int type;
@@ -582,143 +507,8 @@ static void pc_proc_infos(unsigned char
return;
}
-#endif
-
-#endif /* MACH == PC */
-
-#if MACH == ATARI
-
-static int atari_check_checksum(void)
-{
- int i;
- unsigned char sum = 0;
-
- for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
- sum += __nvram_read_byte(i);
- return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff)) &&
- (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff));
-}
-
-static void atari_set_checksum(void)
-{
- int i;
- unsigned char sum = 0;
- for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
- sum += __nvram_read_byte(i);
- __nvram_write_byte(~sum, ATARI_CKS_LOC);
- __nvram_write_byte(sum, ATARI_CKS_LOC + 1);
-}
-
-#ifdef CONFIG_PROC_FS
-
-static struct {
- unsigned char val;
- char *name;
-} boot_prefs[] = {
- { 0x80, "TOS" },
- { 0x40, "ASV" },
- { 0x20, "NetBSD (?)" },
- { 0x10, "Linux" },
- { 0x00, "unspecified" }
-};
-
-static char *languages[] = {
- "English (US)",
- "German",
- "French",
- "English (UK)",
- "Spanish",
- "Italian",
- "6 (undefined)",
- "Swiss (French)",
- "Swiss (German)"
-};
-
-static char *dateformat[] = {
- "MM%cDD%cYY",
- "DD%cMM%cYY",
- "YY%cMM%cDD",
- "YY%cDD%cMM",
- "4 (undefined)",
- "5 (undefined)",
- "6 (undefined)",
- "7 (undefined)"
-};
-
-static char *colors[] = {
- "2", "4", "16", "256", "65536", "??", "??", "??"
-};
-
-static void atari_proc_infos(unsigned char *nvram, struct seq_file *seq,
- void *offset)
-{
- int checksum = nvram_check_checksum();
- int i;
- unsigned vmode;
-
- seq_printf(seq, "Checksum status : %svalid\n", checksum ? "" : "not ");
-
- seq_printf(seq, "Boot preference : ");
- for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) {
- if (nvram[1] == boot_prefs[i].val) {
- seq_printf(seq, "%s\n", boot_prefs[i].name);
- break;
- }
- }
- if (i < 0)
- seq_printf(seq, "0x%02x (undefined)\n", nvram[1]);
-
- seq_printf(seq, "SCSI arbitration : %s\n",
- (nvram[16] & 0x80) ? "on" : "off");
- seq_printf(seq, "SCSI host ID : ");
- if (nvram[16] & 0x80)
- seq_printf(seq, "%d\n", nvram[16] & 7);
- else
- seq_printf(seq, "n/a\n");
-
- /* the following entries are defined only for the Falcon */
- if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON)
- return;
-
- seq_printf(seq, "OS language : ");
- if (nvram[6] < ARRAY_SIZE(languages))
- seq_printf(seq, "%s\n", languages[nvram[6]]);
- else
- seq_printf(seq, "%u (undefined)\n", nvram[6]);
- seq_printf(seq, "Keyboard language: ");
- if (nvram[7] < ARRAY_SIZE(languages))
- seq_printf(seq, "%s\n", languages[nvram[7]]);
- else
- seq_printf(seq, "%u (undefined)\n", nvram[7]);
- seq_printf(seq, "Date format : ");
- seq_printf(seq, dateformat[nvram[8] & 7],
- nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/');
- seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12);
- seq_printf(seq, "Boot delay : ");
- if (nvram[10] == 0)
- seq_printf(seq, "default");
- else
- seq_printf(seq, "%ds%s\n", nvram[10],
- nvram[10] < 8 ? ", no memory test" : "");
-
- vmode = (nvram[14] << 8) | nvram[15];
- seq_printf(seq,
- "Video mode : %s colors, %d columns, %s %s monitor\n",
- colors[vmode & 7],
- vmode & 8 ? 80 : 40,
- vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC");
- seq_printf(seq, " %soverscan, compat. mode %s%s\n",
- vmode & 64 ? "" : "no ",
- vmode & 128 ? "on" : "off",
- vmode & 256 ?
- (vmode & 16 ? ", line doubling" : ", half screen") : "");
-
- return;
-}
-#endif
-
-#endif /* MACH == ATARI */
+#endif /* CONFIG_PROC_FS */
MODULE_LICENSE("GPL");
MODULE_ALIAS_MISCDEV(NVRAM_MINOR);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 03/26] m68k/atari: Replace nvram_{read,write}_byte with arch_nvram_ops |
| Message-ID | <qpYwH-7a6-31@gated-at.bofh.it> |
| In reply to | #1260130 |
By implementing an arch_nvram_ops struct, any platform can re-use the
drivers/char/nvram module without needing any arch-specific code
in that module. Atari does so here.
Atari has one user of nvram_check_checksum() whereas the other platforms
(i.e. x86 and ARM platforms) have none at all. Replace this
validate-checksum-and-read-byte sequence with the equivalent
rtc_nvram_ops.read() call and remove the now unused functions.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Tested-by: Christian T. Steigies <cts@debian.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
The advantage of the new ops struct over the old global nvram_* functions
is that the misc device module can be shared by different platforms
without requiring every platform to implement every nvram_* function.
E.g. only RTC "CMOS" NVRAMs have a checksum for the entire NVRAM
and only PowerPC platforms have a "sync" ioctl.
---
arch/m68k/atari/nvram.c | 89 ++++++++++++++++++++++++++++------------------
drivers/scsi/atari_scsi.c | 8 ++--
include/linux/nvram.h | 9 ++++
3 files changed, 70 insertions(+), 36 deletions(-)
Index: linux/arch/m68k/atari/nvram.c
===================================================================
--- linux.orig/arch/m68k/atari/nvram.c 2015-11-01 21:41:25.000000000 +1100
+++ linux/arch/m68k/atari/nvram.c 2015-11-01 21:41:27.000000000 +1100
@@ -38,33 +38,12 @@ unsigned char __nvram_read_byte(int i)
return CMOS_READ(NVRAM_FIRST_BYTE + i);
}
-unsigned char nvram_read_byte(int i)
-{
- unsigned long flags;
- unsigned char c;
-
- spin_lock_irqsave(&rtc_lock, flags);
- c = __nvram_read_byte(i);
- spin_unlock_irqrestore(&rtc_lock, flags);
- return c;
-}
-EXPORT_SYMBOL(nvram_read_byte);
-
/* This races nicely with trying to read with checksum checking */
void __nvram_write_byte(unsigned char c, int i)
{
CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
}
-void nvram_write_byte(unsigned char c, int i)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&rtc_lock, flags);
- __nvram_write_byte(c, i);
- spin_unlock_irqrestore(&rtc_lock, flags);
-}
-
/* On Ataris, the checksum is over all bytes except the checksum bytes
* themselves; these are at the very end.
*/
@@ -83,18 +62,6 @@ int __nvram_check_checksum(void)
(__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff));
}
-int nvram_check_checksum(void)
-{
- unsigned long flags;
- int rv;
-
- spin_lock_irqsave(&rtc_lock, flags);
- rv = __nvram_check_checksum();
- spin_unlock_irqrestore(&rtc_lock, flags);
- return rv;
-}
-EXPORT_SYMBOL(nvram_check_checksum);
-
static void __nvram_set_checksum(void)
{
int i;
@@ -106,6 +73,62 @@ static void __nvram_set_checksum(void)
__nvram_write_byte(sum, ATARI_CKS_LOC + 1);
}
+static ssize_t 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 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 nvram_get_size(void)
+{
+ return NVRAM_BYTES;
+}
+
+const struct nvram_ops arch_nvram_ops = {
+ .read = nvram_read,
+ .write = nvram_write,
+ .get_size = nvram_get_size,
+};
+EXPORT_SYMBOL(arch_nvram_ops);
+
#ifdef CONFIG_PROC_FS
static struct {
unsigned char val;
Index: linux/drivers/scsi/atari_scsi.c
===================================================================
--- linux.orig/drivers/scsi/atari_scsi.c 2015-11-01 21:41:24.000000000 +1100
+++ linux/drivers/scsi/atari_scsi.c 2015-11-01 21:41:27.000000000 +1100
@@ -880,13 +880,15 @@ static int __init atari_scsi_probe(struc
#ifdef CONFIG_NVRAM
else
/* Test if a host id is set in the NVRam */
- if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) {
- unsigned char b = nvram_read_byte(14);
+ if (ATARIHW_PRESENT(TT_CLK)) {
+ unsigned char b;
+ loff_t offset = 14;
+ ssize_t count = arch_nvram_ops.read(&b, 1, &offset);
/* Arbitration enabled? (for TOS)
* If yes, use configured host ID
*/
- if (b & 0x80)
+ if ((count == 1) && (b & 0x80))
atari_scsi_template.this_id = b & 7;
}
#endif
Index: linux/include/linux/nvram.h
===================================================================
--- linux.orig/include/linux/nvram.h 2015-11-01 21:41:24.000000000 +1100
+++ linux/include/linux/nvram.h 2015-11-01 21:41:27.000000000 +1100
@@ -10,4 +10,13 @@ extern void __nvram_write_byte(unsigned
extern void nvram_write_byte(unsigned char c, int i);
extern int __nvram_check_checksum(void);
extern int nvram_check_checksum(void);
+
+struct nvram_ops {
+ ssize_t (*read)(char *, size_t, loff_t *);
+ ssize_t (*write)(char *, size_t, loff_t *);
+ ssize_t (*get_size)(void);
+};
+
+extern const struct nvram_ops arch_nvram_ops;
+
#endif /* _LINUX_NVRAM_H */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 18/26] nvram: Drop nvram_* symbol exports and prototypes |
| Message-ID | <qpYwH-7a6-33@gated-at.bofh.it> |
| In reply to | #1260130 |
Drivers now use the arch_nvram_ops calls so remove the function exports and
prototypes. nvram_check_checksum() is unused so remove it.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
arch/m68k/atari/nvram.c | 6 +++---
drivers/char/nvram.c | 27 +++++----------------------
include/linux/nvram.h | 8 --------
3 files changed, 8 insertions(+), 33 deletions(-)
Index: linux/drivers/char/nvram.c
===================================================================
--- linux.orig/drivers/char/nvram.c 2015-11-01 21:41:42.000000000 +1100
+++ linux/drivers/char/nvram.c 2015-11-01 21:41:47.000000000 +1100
@@ -82,13 +82,12 @@ static ssize_t nvram_size;
* periodic 11 min sync from kernel/time/ntp.c vs. this driver.)
*/
-unsigned char __nvram_read_byte(int i)
+static unsigned char __nvram_read_byte(int i)
{
return CMOS_READ(NVRAM_FIRST_BYTE + i);
}
-EXPORT_SYMBOL(__nvram_read_byte);
-unsigned char nvram_read_byte(int i)
+static unsigned char nvram_read_byte(int i)
{
unsigned long flags;
unsigned char c;
@@ -98,16 +97,14 @@ unsigned char nvram_read_byte(int i)
spin_unlock_irqrestore(&rtc_lock, flags);
return c;
}
-EXPORT_SYMBOL(nvram_read_byte);
/* This races nicely with trying to read with checksum checking (nvram_read) */
-void __nvram_write_byte(unsigned char c, int i)
+static void __nvram_write_byte(unsigned char c, int i)
{
CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
}
-EXPORT_SYMBOL(__nvram_write_byte);
-void nvram_write_byte(unsigned char c, int i)
+static void nvram_write_byte(unsigned char c, int i)
{
unsigned long flags;
@@ -115,14 +112,13 @@ void nvram_write_byte(unsigned char c, i
__nvram_write_byte(c, i);
spin_unlock_irqrestore(&rtc_lock, flags);
}
-EXPORT_SYMBOL(nvram_write_byte);
/* On PCs, the checksum is built only over bytes 2..31 */
#define PC_CKS_RANGE_START 2
#define PC_CKS_RANGE_END 31
#define PC_CKS_LOC 32
-int __nvram_check_checksum(void)
+static int __nvram_check_checksum(void)
{
int i;
unsigned short sum = 0;
@@ -134,19 +130,6 @@ int __nvram_check_checksum(void)
__nvram_read_byte(PC_CKS_LOC+1);
return (sum & 0xffff) == expect;
}
-EXPORT_SYMBOL(__nvram_check_checksum);
-
-int nvram_check_checksum(void)
-{
- unsigned long flags;
- int rv;
-
- spin_lock_irqsave(&rtc_lock, flags);
- rv = __nvram_check_checksum();
- spin_unlock_irqrestore(&rtc_lock, flags);
- return rv;
-}
-EXPORT_SYMBOL(nvram_check_checksum);
static void __nvram_set_checksum(void)
{
Index: linux/include/linux/nvram.h
===================================================================
--- linux.orig/include/linux/nvram.h 2015-11-01 21:41:42.000000000 +1100
+++ linux/include/linux/nvram.h 2015-11-01 21:41:47.000000000 +1100
@@ -3,14 +3,6 @@
#include <uapi/linux/nvram.h>
-/* __foo is foo without grabbing the rtc_lock - get it yourself */
-extern unsigned char __nvram_read_byte(int i);
-extern unsigned char nvram_read_byte(int i);
-extern void __nvram_write_byte(unsigned char c, int i);
-extern void nvram_write_byte(unsigned char c, int i);
-extern int __nvram_check_checksum(void);
-extern int nvram_check_checksum(void);
-
struct nvram_ops {
ssize_t (*read)(char *, size_t, loff_t *);
ssize_t (*write)(char *, size_t, loff_t *);
Index: linux/arch/m68k/atari/nvram.c
===================================================================
--- linux.orig/arch/m68k/atari/nvram.c 2015-11-01 21:41:36.000000000 +1100
+++ linux/arch/m68k/atari/nvram.c 2015-11-01 21:41:47.000000000 +1100
@@ -33,13 +33,13 @@
* periodic 11 min sync from kernel/time/ntp.c vs. this driver.)
*/
-unsigned char __nvram_read_byte(int i)
+static unsigned char __nvram_read_byte(int i)
{
return CMOS_READ(NVRAM_FIRST_BYTE + i);
}
/* This races nicely with trying to read with checksum checking */
-void __nvram_write_byte(unsigned char c, int i)
+static void __nvram_write_byte(unsigned char c, int i)
{
CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
}
@@ -51,7 +51,7 @@ void __nvram_write_byte(unsigned char c,
#define ATARI_CKS_RANGE_END 47
#define ATARI_CKS_LOC 48
-int __nvram_check_checksum(void)
+static int __nvram_check_checksum(void)
{
int i;
unsigned char sum = 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Finn Thain <fthain@telegraphics.com.au> |
|---|---|
| Date | 2015-11-01 12:00 +0100 |
| Subject | [PATCH v7 08/26] char/nvram: Implement NVRAM read/write methods |
| Message-ID | <qpYwH-7a6-35@gated-at.bofh.it> |
| In reply to | #1260130 |
Refactor the RTC "CMOS" NVRAM functions so that they can be used as
arch_nvram_ops methods. Checksumming logic is moved from the misc device
operations to the nvram read/write operations.
This makes the misc device implementation more generic. This also
preserves the locking semantics such that "read if checksum valid" and
"write and update checksum" remain atomic operations.
PPC64 implements byte-range read/write methods which are similar to
file_operations struct methods. Other platforms provide only
byte-at-a-time functions. So the misc device prefers the former but
will fall back on the latter.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
drivers/char/nvram.c | 162 +++++++++++++++++++++++++++++++++++----------------
1 file changed, 114 insertions(+), 48 deletions(-)
Index: linux/drivers/char/nvram.c
===================================================================
--- linux.orig/drivers/char/nvram.c 2015-11-01 21:41:32.000000000 +1100
+++ linux/drivers/char/nvram.c 2015-11-01 21:41:34.000000000 +1100
@@ -41,6 +41,7 @@
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
+#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/io.h>
#include <linux/uaccess.h>
@@ -178,9 +179,48 @@ static ssize_t nvram_get_size(void)
return NVRAM_BYTES;
}
+static ssize_t 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 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;
+}
+
const struct nvram_ops arch_nvram_ops = {
.read_byte = nvram_read_byte,
.write_byte = nvram_write_byte,
+ .read = nvram_read,
+ .write = nvram_write,
.get_size = nvram_get_size,
.set_checksum = nvram_set_checksum,
.initialize = nvram_initialize,
@@ -215,69 +255,95 @@ static loff_t nvram_misc_llseek(struct f
static ssize_t nvram_misc_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
- unsigned char contents[NVRAM_BYTES];
- unsigned i = *ppos;
- unsigned char *tmp;
-
- spin_lock_irq(&rtc_lock);
+ loff_t i;
+ char __user *p = buf;
- if (!__nvram_check_checksum())
- goto checksum_err;
-
- for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
- *tmp = __nvram_read_byte(i);
-
- spin_unlock_irq(&rtc_lock);
-
- if (copy_to_user(buf, contents, tmp - contents))
+ if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
+ if (*ppos >= nvram_size)
+ return 0;
- *ppos = i;
-
- return tmp - contents;
+ /* If the arch provided a byte range read op, use it. Otherwise
+ * fall back on the byte-at-a-time accessor.
+ */
+ if (arch_nvram_ops.read != NULL) {
+ char *tmp;
+ ssize_t ret;
+
+ count = min_t(size_t, count, nvram_size - *ppos);
+ count = min_t(size_t, count, PAGE_SIZE);
+
+ tmp = kmalloc(count, GFP_KERNEL);
+ if (!tmp)
+ return -ENOMEM;
+
+ ret = arch_nvram_ops.read(tmp, count, ppos);
+ if (ret <= 0)
+ goto out;
+
+ if (copy_to_user(buf, tmp, ret)) {
+ *ppos -= ret;
+ ret = -EFAULT;
+ }
+
+out:
+ kfree(tmp);
+ return ret;
+ }
-checksum_err:
- spin_unlock_irq(&rtc_lock);
- return -EIO;
+ for (i = *ppos; count > 0 && i < nvram_size; ++i, ++p, --count)
+ if (__put_user(arch_nvram_ops.read_byte(i), p))
+ return -EFAULT;
+ *ppos = i;
+ return p - buf;
}
static ssize_t nvram_misc_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
- unsigned char contents[NVRAM_BYTES];
- unsigned i = *ppos;
- unsigned char *tmp;
-
- if (i >= NVRAM_BYTES)
- return 0; /* Past EOF */
-
- if (count > NVRAM_BYTES - i)
- count = NVRAM_BYTES - i;
- if (count > NVRAM_BYTES)
- return -EFAULT; /* Can't happen, but prove it to gcc */
+ loff_t i;
+ const char __user *p = buf;
- if (copy_from_user(contents, buf, count))
+ if (!access_ok(VERIFY_READ, buf, count))
return -EFAULT;
+ if (*ppos >= nvram_size)
+ return 0;
- spin_lock_irq(&rtc_lock);
-
- if (!__nvram_check_checksum())
- goto checksum_err;
-
- for (tmp = contents; count--; ++i, ++tmp)
- __nvram_write_byte(*tmp, i);
-
- __nvram_set_checksum();
+ /* If the arch provided a byte range write op, use it. Otherwise
+ * fall back on the byte-at-a-time accessor.
+ */
+ if (arch_nvram_ops.write != NULL) {
+ char *tmp;
+ ssize_t ret;
+
+ count = min_t(size_t, count, nvram_size - *ppos);
+ count = min_t(size_t, count, PAGE_SIZE);
+
+ tmp = kmalloc(count, GFP_KERNEL);
+ if (!tmp)
+ return -ENOMEM;
+
+ if (copy_from_user(tmp, buf, count)) {
+ ret = -EFAULT;
+ goto out;
+ }
+
+ ret = arch_nvram_ops.write(tmp, count, ppos);
+
+out:
+ kfree(tmp);
+ return ret;
+ }
- spin_unlock_irq(&rtc_lock);
+ for (i = *ppos; count > 0 && i < nvram_size; ++i, ++p, --count) {
+ char c;
+ if (__get_user(c, p))
+ return -EFAULT;
+ arch_nvram_ops.write_byte(c, i);
+ }
*ppos = i;
-
- return tmp - contents;
-
-checksum_err:
- spin_unlock_irq(&rtc_lock);
- return -EIO;
+ return p - buf;
}
static long nvram_misc_ioctl(struct file *file, unsigned int cmd,
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web