Skip to content

Commit

Permalink
m68k: Dispatch nvram_ops calls to Atari or Mac functions
Browse files Browse the repository at this point in the history
A multi-platform kernel binary has to decide at run-time how to dispatch
the arch_nvram_ops calls. Add a platform-independent arch_nvram_ops
struct for this, to replace the atari-specific one.

Enable CONFIG_HAVE_ARCH_NVRAM_OPS for Macs.

Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Finn Thain authored and gregkh committed Jan 22, 2019
1 parent 458c77f commit d3b41b6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 17 deletions.
1 change: 1 addition & 0 deletions arch/m68k/Kconfig.machine
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ config MAC
bool "Macintosh support"
depends on MMU
select MMU_MOTOROLA if MMU
select HAVE_ARCH_NVRAM_OPS
help
This option enables support for the Apple Macintosh series of
computers (yes, there is experimental support now, at least for part
Expand Down
21 changes: 5 additions & 16 deletions arch/m68k/atari/nvram.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ static void __nvram_set_checksum(void)
__nvram_write_byte(sum, ATARI_CKS_LOC + 1);
}

static long atari_nvram_set_checksum(void)
long atari_nvram_set_checksum(void)
{
spin_lock_irq(&rtc_lock);
__nvram_set_checksum();
spin_unlock_irq(&rtc_lock);
return 0;
}

static long atari_nvram_initialize(void)
long atari_nvram_initialize(void)
{
loff_t i;

Expand All @@ -94,7 +94,7 @@ static long atari_nvram_initialize(void)
return 0;
}

static ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos)
ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos)
{
char *p = buf;
loff_t i;
Expand All @@ -112,7 +112,7 @@ static ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos)
return p - buf;
}

static ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos)
ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos)
{
char *p = buf;
loff_t i;
Expand All @@ -131,22 +131,11 @@ static ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos)
return p - buf;
}

static ssize_t atari_nvram_get_size(void)
ssize_t atari_nvram_get_size(void)
{
if (!MACH_IS_ATARI)
return -ENODEV;
return NVRAM_BYTES;
}

const struct nvram_ops arch_nvram_ops = {
.read = atari_nvram_read,
.write = atari_nvram_write,
.get_size = atari_nvram_get_size,
.set_checksum = atari_nvram_set_checksum,
.initialize = atari_nvram_initialize,
};
EXPORT_SYMBOL(arch_nvram_ops);

#ifdef CONFIG_PROC_FS
static struct {
unsigned char val;
Expand Down
6 changes: 6 additions & 0 deletions arch/m68k/include/asm/atarihw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ extern int atari_dont_touch_floppy_select;

extern int atari_SCC_reset_done;

extern ssize_t atari_nvram_read(char *, size_t, loff_t *);
extern ssize_t atari_nvram_write(char *, size_t, loff_t *);
extern ssize_t atari_nvram_get_size(void);
extern long atari_nvram_set_checksum(void);
extern long atari_nvram_initialize(void);

/* convenience macros for testing machine type */
#define MACH_IS_ST ((atari_mch_cookie >> 16) == ATARI_MCH_ST)
#define MACH_IS_STE ((atari_mch_cookie >> 16) == ATARI_MCH_STE && \
Expand Down
4 changes: 4 additions & 0 deletions arch/m68k/include/asm/macintosh.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ extern void mac_init_IRQ(void);
extern void mac_irq_enable(struct irq_data *data);
extern void mac_irq_disable(struct irq_data *data);

extern unsigned char mac_pram_read_byte(int);
extern void mac_pram_write_byte(unsigned char, int);
extern ssize_t mac_pram_get_size(void);

/*
* Macintosh Table
*/
Expand Down
82 changes: 81 additions & 1 deletion arch/m68k/kernel/setup_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/module.h>
#include <linux/nvram.h>
#include <linux/initrd.h>

#include <asm/bootinfo.h>
Expand All @@ -37,13 +38,14 @@
#ifdef CONFIG_AMIGA
#include <asm/amigahw.h>
#endif
#ifdef CONFIG_ATARI
#include <asm/atarihw.h>
#ifdef CONFIG_ATARI
#include <asm/atari_stram.h>
#endif
#ifdef CONFIG_SUN3X
#include <asm/dvma.h>
#endif
#include <asm/macintosh.h>
#include <asm/natfeat.h>

#if !FPSTATESIZE || !NR_IRQS
Expand Down Expand Up @@ -547,3 +549,81 @@ static int __init adb_probe_sync_enable (char *str) {

__setup("adb_sync", adb_probe_sync_enable);
#endif /* CONFIG_ADB */

#if IS_ENABLED(CONFIG_NVRAM)
#ifdef CONFIG_MAC
static unsigned char m68k_nvram_read_byte(int addr)
{
if (MACH_IS_MAC)
return mac_pram_read_byte(addr);
return 0xff;
}

static void m68k_nvram_write_byte(unsigned char val, int addr)
{
if (MACH_IS_MAC)
mac_pram_write_byte(val, addr);
}
#endif /* CONFIG_MAC */

#ifdef CONFIG_ATARI
static ssize_t m68k_nvram_read(char *buf, size_t count, loff_t *ppos)
{
if (MACH_IS_ATARI)
return atari_nvram_read(buf, count, ppos);
else if (MACH_IS_MAC)
return nvram_read_bytes(buf, count, ppos);
return -EINVAL;
}

static ssize_t m68k_nvram_write(char *buf, size_t count, loff_t *ppos)
{
if (MACH_IS_ATARI)
return atari_nvram_write(buf, count, ppos);
else if (MACH_IS_MAC)
return nvram_write_bytes(buf, count, ppos);
return -EINVAL;
}

static long m68k_nvram_set_checksum(void)
{
if (MACH_IS_ATARI)
return atari_nvram_set_checksum();
return -EINVAL;
}

static long m68k_nvram_initialize(void)
{
if (MACH_IS_ATARI)
return atari_nvram_initialize();
return -EINVAL;
}
#endif /* CONFIG_ATARI */

static ssize_t m68k_nvram_get_size(void)
{
if (MACH_IS_ATARI)
return atari_nvram_get_size();
else if (MACH_IS_MAC)
return mac_pram_get_size();
return -ENODEV;
}

/* Atari device drivers call .read (to get checksum validation) whereas
* Mac and PowerMac device drivers just use .read_byte.
*/
const struct nvram_ops arch_nvram_ops = {
#ifdef CONFIG_MAC
.read_byte = m68k_nvram_read_byte,
.write_byte = m68k_nvram_write_byte,
#endif
#ifdef CONFIG_ATARI
.read = m68k_nvram_read,
.write = m68k_nvram_write,
.set_checksum = m68k_nvram_set_checksum,
.initialize = m68k_nvram_initialize,
#endif
.get_size = m68k_nvram_get_size,
};
EXPORT_SYMBOL(arch_nvram_ops);
#endif /* CONFIG_NVRAM */
11 changes: 11 additions & 0 deletions arch/m68k/mac/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

static void (*rom_reset)(void);

#if IS_ENABLED(CONFIG_NVRAM)
#ifdef CONFIG_ADB_CUDA
static unsigned char cuda_pram_read_byte(int offset)
{
Expand Down Expand Up @@ -84,6 +85,7 @@ static void pmu_pram_write_byte(unsigned char data, int offset)
pmu_wait_complete(&req);
}
#endif /* CONFIG_ADB_PMU */
#endif /* CONFIG_NVRAM */

/*
* VIA PRAM/RTC access routines
Expand Down Expand Up @@ -205,6 +207,7 @@ static void via_rtc_command(int command, __u8 *data)
local_irq_restore(flags);
}

#if IS_ENABLED(CONFIG_NVRAM)
static unsigned char via_pram_read_byte(int offset)
{
unsigned char temp;
Expand All @@ -227,6 +230,7 @@ static void via_pram_write_byte(unsigned char data, int offset)
temp = 0x55 | RTC_FLG_WRITE_PROTECT;
via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
}
#endif /* CONFIG_NVRAM */

/*
* Return the current time in seconds since January 1, 1904.
Expand Down Expand Up @@ -372,6 +376,7 @@ static void cuda_shutdown(void)
*-------------------------------------------------------------------
*/

#if IS_ENABLED(CONFIG_NVRAM)
unsigned char mac_pram_read_byte(int addr)
{
switch (macintosh_config->adb_type) {
Expand Down Expand Up @@ -417,6 +422,12 @@ void mac_pram_write_byte(unsigned char val, int addr)
}
}

ssize_t mac_pram_get_size(void)
{
return 256;
}
#endif /* CONFIG_NVRAM */

void mac_poweroff(void)
{
if (oss_present) {
Expand Down

0 comments on commit d3b41b6

Please sign in to comment.