lkml.org 
[lkml]   [1997]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectAutoprobing nvram (CMOS Ram) size
Date
Hi...

since many of the modern PCs have 128 instead of 64 bytes of non
volatile (CMOS),
it might be very useful to be able to read the other 64 bytes of memory,
too.

The following patch contains some simple autoprobe mechanism with works
Ok on all PCs
available here... Could you please test this out and maybe report any
ideas/bugs to me?
Is there especially someone out who could try how this patch behaves on
an Atari?

The patch is against a clean 2.1.64 (mainstream)

Stefan


--
.signature: No such file or directory


--- linux/drivers/char/nvram.c.old Mon Nov 17 16:02:52 1997
+++ linux/drivers/char/nvram.c Tue Nov 18 01:27:40 1997
@@ -12,7 +12,7 @@
* 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
@@ -27,12 +27,21 @@
*
*/

-#define NVRAM_VERSION "1.0"
+/*
+ * Most modern X86 machines have a 128 byte buffer. I don´t know wether there´s
+ * a correct way to check for the size. If you try to read the second 64 bytes
+ * of a 64 byte nvram, you´ll get the first 64 byte mirrored, if you have 128
+ * bytes, the 1. and 129. byte are the same. Size probing uses this "feature"
+ * <stepan@linux.de>, Stefan Reinauer 97/11/18
+ */
+
+
+#define NVRAM_VERSION "1.1"

#include <linux/module.h>
#include <linux/config.h>

-#define PC 1
+#define PC 1
#define ATARI 2

/* select machine configuration */
@@ -52,7 +61,7 @@
/* 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 PC_CKS_LOC 32

#define mach_check_checksum pc_check_checksum
#define mach_set_checksum pc_set_checksum
@@ -103,18 +112,19 @@
#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 */

+int NVRAM_BYTES;

static int mach_check_checksum( void );
static void mach_set_checksum( void );
+static int nvram_probe( 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 );
@@ -413,6 +423,9 @@

printk( "Non-volatile memory driver v%s\n", NVRAM_VERSION );
misc_register( &nvram_dev );
+
+ NVRAM_BYTES=nvram_probe()-RTC_FIRST_BYTE;
+
#ifdef CONFIG_PROC_FS
if ((proc_nvram = create_proc_entry( "nvram", 0, 0 )))
proc_nvram->read_proc = nvram_read_proc;
@@ -471,7 +484,7 @@
#ifdef CONFIG_PROC_FS

static char *floppy_types[] = {
- "none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M"
+ "none", "5.25\" 360k", "5.25\" 1.2M", "3.5'' 720k", "3.5\" 1.44M"
};

static char *gfx_types[] = {
@@ -493,58 +506,59 @@
checksum = nvram_check_checksum_int();
restore_flags(flags);

- PRINT_PROC( "Checksum status: %svalid\n", checksum ? "" : "not " );
+ PRINT_PROC( "NV-RAM size : %d bytes\n", NVRAM_BYTES+RTC_FIRST_BYTE );

- PRINT_PROC( "# floppies : %d\n",
+ PRINT_PROC( "Checksum status : %svalid\n", checksum ? "" : "in" );
+
+ PRINT_PROC( "# floppies : %d\n",
(nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0 );
- PRINT_PROC( "Floppy 0 type : " );
+ 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 : " );
+ 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 : " );
+ PRINT_PROC( "HD 0 type : " );
type = nvram[4] >> 4;
if (type)
- PRINT_PROC( " %02x\n", type == 0x0f ? nvram[11] : type );
+ PRINT_PROC( "0x%02x\n", type == 0x0f ? nvram[11] : type );
else
PRINT_PROC( "none\n" );

- PRINT_PROC( "HD 1 type : " );
+ PRINT_PROC( "HD 1 type : " );
type = nvram[4] & 0x0f;
if (type)
- PRINT_PROC( " %02x\n", type == 0x0f ? nvram[12] : type );
+ PRINT_PROC( "0x%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",
+ 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",
+ 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",
+ 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( "Gfx adapter : %s\n", gfx_types[ (nvram[6] >> 4)&3 ] );

- PRINT_PROC( "FPU : %sinstalled\n",
+ PRINT_PROC( "FPU : %sinstalled\n",
(nvram[6] & 2) ? "" : "not " );
-
return( 1 );
}
#endif
@@ -685,6 +699,22 @@
#endif

#endif /* MACH == ATARI */
+
+static int nvram_probe()
+{
+ int size=64, i;
+ printk("Probing nvram size... ");
+
+ for (i=RTC_FIRST_BYTE;i<size;i++)
+ if (CMOS_READ(i) != CMOS_READ(i+size)) {
+ size+=size;
+ i=RTC_FIRST_BYTE;
+ }
+
+ printk (" found %d bytes\n", size);
+
+ return (size);
+}

/*
* Local variables:
\
 
 \ /
  Last update: 2005-03-22 13:40    [W:0.398 / U:0.492 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site