/dev/nvram driver for PC and Atari

Roman Hodek (rnhodek@faui22c.informatik.uni-erlangen.de)
Mon, 23 Jun 1997 10:56:47 +0200


Appended below is a driver for a /dev/nvram device for both PC and
Atari machines (both have the same RTC chip and thus the same NV-RAM
(or CMOS-RAM, as it is called sometimes on PCs)).

/dev/nvram is a simple seekable character device (c 10 144, which is
already registered for a while now...), that is 50 bytes long and its
contents represent the contents of the NV-RAM. This device can be used
for reading your machine's configuration information, or to change it.
(So better restrict write access to root :-) Another application would
be to save a few bits of critical data, that need to survive power-off
cycles and for which writing to disk would be to insecure (time until
disk-flush...)

NV-RAM checksums are handeled automatically by /dev/nvram. Each access
fails if the checksum is bad. Writes update the checksum. And there
are two ioctls to initialize NV-RAM and its checksum: The one also
clears the contents, the other just recalculates the checksum based on
the current contents (in case the correct checkum got lost).

The idea of the /dev/nvram driver is courtesy of Richard Jelinek
<rj@suse.de>. I just implemented it, because 1) I'm more used to
kernel internals and 2) I need access to one NVRAM byte for a tool
related to Atari lilo.

Richard will also write a user-level tools (for PCs) to access
/dev/nvram more user-friendly. It will also have a config file
/dev/nvram.conf, where special entries of your board can be
configured.

There's also a read-only /proc/nvram file. It contains some infos from
the NV-RAM, depending on the machine type (PC/Atari), but in both
cases includes the checksum status. Since not all bytes are
universally defined on PCs, this /proc file can output only some
standard entries. For board-specific entries, Richard's tool will be
needed.

Roman

PS to the linux-kernel people: Please Cc: comments to me, as I'm not
on that list.

------------------------------------------------------------------------------
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/Documentation/Configure.help linux-2.1.42/Documentation/Configure.help
--- linux-2.1.42-orig/Documentation/Configure.help Fri May 30 12:37:30 1997
+++ linux-2.1.42/Documentation/Configure.help Fri Jun 20 16:08:39 1997
@@ -4462,6 +4462,18 @@
have a use for such a device (such as periodic data sampling), then
say Y here, and go read the file Documentation/rtc.txt for details.

+/dev/nvram support
+CONFIG_NVRAM
+ 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"),
+ you get access to the non-volatile memory in the real time clock
+ (RTC). This is conventionally called "CMOS RAM" on PCs and "NVRAM"
+ on Ataris. /dev/nvram may be used to view settings there, or to
+ change them (with some utility). It could also be used to frequently
+ save a few bits of very important data, that may not be lost over
+ power-off and for which writing to disk is too insecure. On Atari
+ machines, /dev/nvram is always configured and needs not be selected.
+
ARC console time
CONFIG_RTC_ARC
If you boot your Alpha using the ARC firmware, say Y here. This option
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/drivers/char/Config.in linux-2.1.42/drivers/char/Config.in
--- linux-2.1.42-orig/drivers/char/Config.in Fri May 16 14:44:50 1997
+++ linux-2.1.42/drivers/char/Config.in Fri Jun 20 15:53:25 1997
@@ -97,4 +97,7 @@
tristate ' Berkshire Products PC Watchdog' CONFIG_PCWATCHDOG
fi
bool 'Enhanced Real Time Clock Support' CONFIG_RTC
+if [ "$CONFIG_ATARI" != "y" ]; then
+ tristate '/dev/nvram support' CONFIG_NVRAM
+fi
endmenu
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/drivers/char/Makefile linux-2.1.42/drivers/char/Makefile
--- linux-2.1.42-orig/drivers/char/Makefile Thu May 22 18:03:21 1997
+++ linux-2.1.42/drivers/char/Makefile Fri Jun 20 15:52:29 1997
@@ -369,6 +369,22 @@
L_OBJS += rtc.o
endif

+ifeq ($(CONFIG_ATARI),y)
+# on Atari, include nvram.c unconditionally
+M = y
+L_OBJS += nvram.o
+else
+ ifeq ($(CONFIG_NVRAM),y)
+ M = y
+ L_OBJS += nvram.o
+ else
+ ifeq ($(CONFIG_NVRAM),m)
+ M_OBJS += nvram.o
+ MM = m
+ endif
+ endif
+endif
+
ifeq ($(CONFIG_QIC02_TAPE),y)
L_OBJS += tpqic02.o
else
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/drivers/char/misc.c linux-2.1.42/drivers/char/misc.c
--- linux-2.1.42-orig/drivers/char/misc.c Fri May 16 11:07:44 1997
+++ linux-2.1.42/drivers/char/misc.c Fri Jun 20 17:19:06 1997
@@ -74,6 +74,7 @@
extern void pcwatchdog_init(void);
extern int rtc_init(void);
extern int dsp56k_init(void);
+extern int nvram_init(void);

#ifdef CONFIG_PROC_FS
static int misc_read_proc(char *buf, char **start, off_t offset,
@@ -238,6 +239,9 @@
#endif
#ifdef CONFIG_ATARI_DSP56K
dsp56k_init();
+#endif
+#if defined(CONFIG_ATARI) || defined(CONFIG_NVRAM)
+ nvram_init();
#endif
#endif /* !MODULE */
if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/drivers/char/nvram.c linux-2.1.42/drivers/char/nvram.c
--- linux-2.1.42-orig/drivers/char/nvram.c Thu Jan 1 01:00:00 1970
+++ linux-2.1.42/drivers/char/nvram.c Fri Jun 20 23:19:36 1997
@@ -0,0 +1,629 @@
+/*
+ * CMOS/NV-RAM driver for Linux
+ *
+ * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
+ * idea by and with help from Richard Jelinek <rj@suse.de>
+ *
+ * This driver allows you to access the contents of the non-volatile memory in
+ * the mc146818rtc.h real-time clock. This chip is built into all PCs and into
+ * many Atari machines. In the former it's called "CMOS-RAM", in the latter
+ * "NVRAM" (NV stands for non-volatile).
+ *
+ * The data are supplied as a (seekable) character device, /dev/nvram. The
+ * size of this file is 50, the number of freely available bytes in the memory
+ * (i.e., not used by the RTC itself).
+ *
+ * Checksums over the NVRAM contents are managed by this driver. In case of a
+ * bad checksum, reads and writes return -EIO. The checksum can be initialized
+ * to a sane state either by ioctl(NVRAM_INIT) (clear whole NVRAM) or
+ * 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.
+ *
+ */
+
+#define NVRAM_VERSION "1.0"
+
+#include <linux/module.h>
+#include <linux/config.h>
+
+#define PC 1
+#define ATARI 2
+
+/* select machine configuration */
+#if defined(CONFIG_ATARI)
+#define MACH ATARI
+#elif defined(__i386__) /* and others?? */
+#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 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))
+
+/* 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
+ * interrupts disabled. 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 time.c vs. this driver.)
+ */
+
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/miscdevice.h>
+#include <linux/malloc.h>
+#include <linux/ioport.h>
+#include <linux/fcntl.h>
+#include <linux/mc146818rtc.h>
+#include <linux/nvram.h>
+#include <linux/init.h>
+#ifdef CONFIG_PROC_FS
+#include <linux/proc_fs.h>
+#endif
+
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+
+
+static int nvram_open_cnt = 0; /* #times opened */
+static int nvram_open_mode; /* special open modes */
+#define NVRAM_WRITE 1 /* opened for writing (exclusive) */
+#define NVRAM_EXCL 2 /* opened with O_EXCL */
+
+#define RTC_FIRST_BYTE 14 /* RTC register number of first NVRAM byte */
+#define NVRAM_BYTES 50 /* number of NVRAM bytes */
+
+
+static int mach_check_checksum( void );
+static void mach_set_checksum( void );
+#ifdef CONFIG_PROC_FS
+static int mach_proc_infos( unsigned char *contents, char *buffer, int *len,
+ off_t *begin, off_t offset, int size );
+#endif
+
+
+/*
+ * These are the internal NVRAM access functions, which do NOT disable
+ * interrupts and do not check the checksum. Both tasks are left to higher
+ * level function, so they need to be done only once per syscall.
+ */
+
+static __inline__ unsigned char nvram_read_int( int i )
+{
+ return( CMOS_READ( RTC_FIRST_BYTE+i ) );
+}
+
+static __inline__ void nvram_write_int( unsigned char c, int i )
+{
+ CMOS_WRITE( c, RTC_FIRST_BYTE+i );
+}
+
+static __inline__ int nvram_check_checksum_int( void )
+{
+ return( mach_check_checksum() );
+}
+
+static __inline__ void nvram_set_checksum_int( void )
+{
+ mach_set_checksum();
+}
+
+#if MACH == ATARI
+
+/*
+ * These non-internal functions are provided to be called by other parts of
+ * the kernel. It's up to the caller to ensure correct checksum before reading
+ * or after writing (needs to be done only once).
+ *
+ * They're only built if CONFIG_ATARI is defined, because Atari drivers use
+ * them. For other configurations (PC), the rest of the kernel can't rely on
+ * them being present (this driver couldn't be configured at all, or as a
+ * module), so they access config information themselves.
+ */
+
+unsigned char nvram_read_byte( int i )
+{
+ unsigned long flags;
+ unsigned char c;
+
+ save_flags(flags);
+ cli();
+ c = nvram_read_int( i );
+ restore_flags(flags);
+ return( c );
+}
+
+void nvram_write_byte( unsigned char c, int i )
+{
+ unsigned long flags;
+
+ save_flags(flags);
+ cli();
+ nvram_write_int( c, i );
+ restore_flags(flags);
+}
+
+int nvram_check_checksum( void )
+{
+ unsigned long flags;
+ int rv;
+
+ save_flags(flags);
+ cli();
+ rv = nvram_check_checksum_int();
+ restore_flags(flags);
+ return( rv );
+}
+
+void nvram_set_checksum( void )
+{
+ unsigned long flags;
+
+ save_flags(flags);
+ cli();
+ nvram_set_checksum_int();
+ restore_flags(flags);
+}
+
+#endif /* MACH == ATARI */
+
+
+/*
+ * The are the file operation function for user access to /dev/nvram
+ */
+
+static long long nvram_llseek( struct inode *inode, 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;
+ }
+ return( (offset >= 0) ? (file->f_pos = offset) : -EINVAL );
+}
+
+static long nvram_read( struct inode * inode, struct file * file,
+ char * buf, unsigned long count )
+{
+ unsigned long flags;
+ unsigned i = file->f_pos;
+ char *tmp = buf;
+
+ save_flags(flags);
+ cli();
+
+ if (!nvram_check_checksum_int()) {
+ restore_flags(flags);
+ return( -EIO );
+ }
+
+ for( ; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp )
+ put_user( nvram_read_int(i), tmp );
+ file->f_pos = i;
+
+ restore_flags(flags);
+ return( tmp - buf );
+}
+
+static long nvram_write( struct inode * inode, struct file * file,
+ const char * buf, unsigned long count )
+{
+ unsigned long flags;
+ unsigned i = file->f_pos;
+ const char *tmp = buf;
+ char c;
+
+ save_flags(flags);
+ cli();
+
+ if (!nvram_check_checksum_int()) {
+ restore_flags(flags);
+ return( -EIO );
+ }
+
+ for( ; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp ) {
+ get_user( c, tmp );
+ nvram_write_int( c, i );
+ }
+ nvram_set_checksum_int();
+ file->f_pos = i;
+
+ restore_flags(flags);
+ return( tmp - buf );
+}
+
+static int nvram_ioctl( struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg )
+{
+ unsigned long flags;
+ int i;
+
+ switch( cmd ) {
+
+ case NVRAM_INIT: /* initialize NVRAM contents and checksum */
+ if (!suser())
+ return( -EACCES );
+
+ save_flags(flags);
+ cli();
+
+ for( i = 0; i < NVRAM_BYTES; ++i )
+ nvram_write_int( 0, i );
+ nvram_set_checksum_int();
+
+ restore_flags(flags);
+ return( 0 );
+
+ case NVRAM_SETCKS: /* just set checksum, contents unchanged
+ * (maybe useful after checksum garbaged
+ * somehow...) */
+ if (!suser())
+ return( -EACCES );
+
+ save_flags(flags);
+ cli();
+ nvram_set_checksum_int();
+ restore_flags(flags);
+ return( 0 );
+
+ default:
+ return( -EINVAL );
+ }
+}
+
+static int nvram_open( struct inode *inode, struct file *file )
+{
+ if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
+ (nvram_open_mode & NVRAM_EXCL) ||
+ ((file->f_mode & 2) && (nvram_open_mode & NVRAM_WRITE)))
+ return( -EBUSY );
+
+ if (file->f_flags & O_EXCL)
+ nvram_open_mode |= NVRAM_EXCL;
+ if (file->f_mode & 2)
+ nvram_open_mode |= NVRAM_WRITE;
+ nvram_open_cnt++;
+ MOD_INC_USE_COUNT;
+ return( 0 );
+}
+
+static int nvram_release( struct inode *inode, struct file *file )
+{
+ nvram_open_cnt--;
+ if (file->f_flags & O_EXCL)
+ nvram_open_mode &= ~NVRAM_EXCL;
+ if (file->f_mode & 2)
+ nvram_open_mode &= ~NVRAM_WRITE;
+
+ MOD_DEC_USE_COUNT;
+ return( 0 );
+}
+
+
+#ifdef CONFIG_PROC_FS
+
+struct proc_dir_entry *proc_nvram;
+
+static int nvram_read_proc( char *buffer, char **start, off_t offset,
+ int size, int *eof, void *data )
+{
+ unsigned long flags;
+ unsigned char contents[NVRAM_BYTES];
+ int i, len = 0;
+ off_t begin = 0;
+
+ save_flags(flags);
+ cli();
+ for( i = 0; i < NVRAM_BYTES; ++i )
+ contents[i] = nvram_read_int( i );
+ restore_flags(flags);
+
+ *eof = mach_proc_infos( contents, buffer, &len, &begin, offset, size );
+
+ if (offset >= begin + len)
+ return( 0 );
+ *start = buffer + (begin - offset);
+ return( size < begin + len - offset ? size : begin + len - offset );
+
+}
+
+/* This macro frees the machine specific function from bounds checking and
+ * this like that... */
+#define PRINT_PROC(fmt,args...) \
+ do { \
+ *len += sprintf( buffer+*len, fmt, ##args ); \
+ if (*begin + *len > offset + size) \
+ return( 0 ); \
+ if (*begin + *len < offset) { \
+ *begin += *len; \
+ *len = 0; \
+ } \
+ } while(0)
+
+#endif
+
+static struct file_operations nvram_fops = {
+ nvram_llseek,
+ nvram_read,
+ nvram_write,
+ NULL, /* No readdir */
+ NULL, /* No poll */
+ nvram_ioctl,
+ NULL, /* No mmap */
+ nvram_open,
+ nvram_release
+};
+
+static struct miscdevice nvram_dev = {
+ NVRAM_MINOR,
+ "nvram",
+ &nvram_fops
+};
+
+
+__initfunc(int nvram_init(void))
+{
+ /* First test whether the driver should init at all */
+ if (!CHECK_DRIVER_INIT())
+ return( -ENXIO );
+
+ printk( "Non-volatile memory driver v%s\n", NVRAM_VERSION );
+ misc_register( &nvram_dev );
+#ifdef CONFIG_PROC_FS
+ if ((proc_nvram = create_proc_entry( "nvram", 0, 0 )))
+ proc_nvram->read_proc = nvram_read_proc;
+#endif
+
+ return( 0 );
+}
+
+#ifdef MODULE
+int init_module (void)
+{
+ return( nvram_init() );
+}
+
+void cleanup_module (void)
+{
+#ifdef CONFIG_PROC_FS
+ if (proc_nvram)
+ remove_proc_entry( "nvram", 0 );
+#endif
+ misc_deregister( &nvram_dev );
+}
+#endif
+
+
+/*
+ * Machine specific functions
+ */
+
+
+#if MACH == PC
+
+static int pc_check_checksum( void )
+{
+ int i;
+ unsigned short sum = 0;
+
+ for( i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i )
+ sum += nvram_read_int( i );
+ return( (sum & 0xffff) ==
+ ((nvram_read_int(PC_CKS_LOC) << 8) |
+ nvram_read_int(PC_CKS_LOC+1)) );
+}
+
+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_int( i );
+ nvram_write_int( sum >> 8, PC_CKS_LOC );
+ nvram_write_int( sum & 0xff, PC_CKS_LOC+1 );
+}
+
+#ifdef CONFIG_PROC_FS
+
+static char *floppy_types[] = {
+ "none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M"
+};
+
+static char *gfx_types[] = {
+ "EGA, VGA, ... (with BIOS)",
+ "CGA (40 cols)",
+ "CGA (80 cols)",
+ "monochrome",
+};
+
+static int pc_proc_infos( unsigned char *nvram, char *buffer, int *len,
+ off_t *begin, off_t offset, int size )
+{
+ unsigned long flags;
+ int checksum;
+ int type;
+
+ save_flags(flags);
+ cli();
+ checksum = nvram_check_checksum_int();
+ restore_flags(flags);
+
+ PRINT_PROC( "Checksum status: %svalid\n", checksum ? "" : "not " );
+
+ PRINT_PROC( "# floppies : %d\n",
+ (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0 );
+ PRINT_PROC( "Floppy 0 type : " );
+ type = nvram[2] >> 4;
+ if (type < sizeof(floppy_types)/sizeof(*floppy_types))
+ PRINT_PROC( "%s\n", floppy_types[type] );
+ else
+ PRINT_PROC( "%d (unknown)\n", type );
+ PRINT_PROC( "Floppy 1 type : " );
+ type = nvram[2] & 0x0f;
+ if (type < sizeof(floppy_types)/sizeof(*floppy_types))
+ PRINT_PROC( "%s\n", floppy_types[type] );
+ else
+ PRINT_PROC( "%d (unknown)\n", type );
+
+ PRINT_PROC( "HD 0 type : " );
+ type = nvram[4] >> 4;
+ if (type)
+ PRINT_PROC( " %02x\n", type == 0x0f ? nvram[11] : type );
+ else
+ PRINT_PROC( "none\n" );
+
+ PRINT_PROC( "HD 1 type : " );
+ type = nvram[4] & 0x0f;
+ if (type)
+ PRINT_PROC( " %02x\n", type == 0x0f ? nvram[12] : type );
+ else
+ PRINT_PROC( "none\n" );
+
+ PRINT_PROC( "HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
+ nvram[18] | (nvram[19] << 8),
+ nvram[20], nvram[25],
+ nvram[21] | (nvram[22] << 8),
+ nvram[23] | (nvram[24] << 8) );
+ PRINT_PROC( "HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
+ nvram[39] | (nvram[40] << 8),
+ nvram[41], nvram[46],
+ nvram[42] | (nvram[43] << 8),
+ nvram[44] | (nvram[45] << 8) );
+
+ PRINT_PROC( "DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8) );
+ PRINT_PROC( "Extended memory: %d kB (configured), %d kB (tested)\n",
+ nvram[9] | (nvram[10] << 8),
+ nvram[34] | (nvram[35] << 8) );
+
+ PRINT_PROC( "Gfx adapter : %s\n", gfx_types[ (nvram[6] >> 4)&3 ] );
+
+ PRINT_PROC( "FPU : %sinstalled\n",
+ (nvram[6] & 2) ? "" : "not " );
+
+ return( 1 );
+}
+#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_int( i );
+ return( nvram_read_int( ATARI_CKS_LOC ) == (~sum & 0xff) &&
+ nvram_read_int( 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_int( i );
+ nvram_write_int( ~sum, ATARI_CKS_LOC );
+ nvram_write_int( 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 int atari_proc_infos( unsigned char *nvram, char *buffer, int *len,
+ off_t *begin, off_t offset, int size )
+{
+ int checksum = nvram_check_checksum();
+ int i;
+
+ PRINT_PROC( "Checksum status : %svalid\n", checksum ? "" : "not " );
+
+ PRINT_PROC( "Boot preference : " );
+ for( i = sizeof(boot_prefs)/sizeof(*boot_prefs)-1; i >= 0; --i ) {
+ if (nvram[1] == boot_prefs[i].val) {
+ PRINT_PROC( "%s\n", boot_prefs[i].name );
+ break;
+ }
+ }
+ if (i < 0)
+ PRINT_PROC( "0x%02x (undefined)\n", nvram[1] );
+
+ PRINT_PROC( "SCSI arbitration: %s\n", (nvram[16] & 0x80) ? "on" : "off" );
+ PRINT_PROC( "SCSI host ID : " );
+ if (nvram[16] & 0x80)
+ PRINT_PROC( "%d\n", nvram[16] & 7 );
+ else
+ PRINT_PROC( "n/a\n" );
+
+ return( 1 );
+}
+#endif
+
+#endif /* MACH == ATARI */
+
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * tab-width: 4
+ * End:
+ */
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/drivers/scsi/atari_scsi.c linux-2.1.42/drivers/scsi/atari_scsi.c
--- linux-2.1.42-orig/drivers/scsi/atari_scsi.c Fri May 16 19:47:42 1997
+++ linux-2.1.42/drivers/scsi/atari_scsi.c Fri Jun 20 23:11:37 1997
@@ -90,6 +90,7 @@
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/init.h>
+#include <linux/nvram.h>

#include <asm/setup.h>
#include <asm/atarihw.h>
@@ -596,20 +597,6 @@
#endif


-#define RTC_READ(reg) \
- ({ unsigned char __val; \
- outb(reg,&tt_rtc.regsel); \
- __val = tt_rtc.data; \
- __val; \
- })
-
-#define RTC_WRITE(reg,val) \
- do { \
- outb(reg,&tt_rtc.regsel); \
- tt_rtc.data = (val); \
- } while(0)
-
-
int atari_scsi_detect (Scsi_Host_Template *host)
{
static int called = 0;
@@ -645,20 +632,11 @@
/* use 7 as default */
host->this_id = 7;
/* Test if a host id is set in the NVRam */
- if (ATARIHW_PRESENT(TT_CLK)) {
- unsigned char sum = 0, b;
- int i;
-
- /* Make checksum */
- for( i = 14; i < 62; ++i )
- sum += RTC_READ(i);
-
- if (/* NV-Ram checksum valid? */
- RTC_READ(62) == sum && RTC_READ(63) == ~sum &&
- /* Arbitration enabled? (for TOS) */
- (b = RTC_READ( 30 )) & 0x80) {
+ if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) {
+ unsigned char b = nvram_read_byte( 14 );
+ /* Arbitration enabled? (for TOS) If yes, use configured host ID */
+ if (b & 0x80)
host->this_id = b & 7;
- }
}
}

diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/include/linux/miscdevice.h linux-2.1.42/include/linux/miscdevice.h
--- linux-2.1.42-orig/include/linux/miscdevice.h Sat Dec 28 22:47:23 1996
+++ linux-2.1.42/include/linux/miscdevice.h Fri Jun 20 15:53:53 1997
@@ -10,6 +10,7 @@
#define SUN_MOUSE_MINOR 6
#define RTC_MINOR 135
#define SUN_OPENPROM_MINOR 139
+#define NVRAM_MINOR 144
#define MISC_DYNAMIC_MINOR 255

extern int misc_init(void);
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.42-orig/include/linux/nvram.h linux-2.1.42/include/linux/nvram.h
--- linux-2.1.42-orig/include/linux/nvram.h Thu Jan 1 01:00:00 1970
+++ linux-2.1.42/include/linux/nvram.h Fri Jun 20 20:39:15 1997
@@ -0,0 +1,18 @@
+#ifndef _LINUX_NVRAM_H
+#define _LINUX_NVRAM_H
+
+#include <linux/ioctl.h>
+
+/* /dev/nvram ioctls */
+#define NVRAM_INIT _IO('p', 0x40) /* initialize NVRAM and set checksum */
+#define NVRAM_SETCKS _IO('p', 0x41) /* recalculate checksum */
+
+#ifdef __KERNEL__
+extern unsigned char nvram_read_byte( int i );
+extern void nvram_write_byte( unsigned char c, int i );
+extern int nvram_check_checksum( void );
+extern void nvram_set_checksum( void );
+extern int nvram_init( void );
+#endif
+
+#endif /* _LINUX_NVRAM_H */