[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Enabling access to the full nvram memory



This patch adds a CONFIG_NVRAM_BYTES config-time option and a nvram_bytes
runtime option to drivers/char/nvram.c, to allow one to access the full nvram
without needing extra patching.

The config option appears even when it's not applicable (no problem, since
CONFIG_NVRAM has the same problem). Patches to fix that would be useful.

This patch has not been tested. It might even not compile.


diff -Naur linux-2.4.0-test7-pre5.orig/drivers/char/Config.in linux-2.4.0-test7-pre5/drivers/char/Config.in
--- linux-2.4.0-test7-pre5.orig/drivers/char/Config.in	Sat Aug 19 19:54:49 2000
+++ linux-2.4.0-test7-pre5/drivers/char/Config.in	Sat Aug 19 20:16:53 2000
@@ -156,6 +156,9 @@
 
 dep_tristate 'Intel i8x0 Random Number Generator support' CONFIG_INTEL_RNG $CONFIG_PCI
 tristate '/dev/nvram support' CONFIG_NVRAM
+if [ "$CONFIG_NVRAM" != "n" ]; then
+   int '  default nvram size (bytes)' CONFIG_NVRAM_BYTES 50
+fi
 tristate 'Enhanced Real Time Clock Support' CONFIG_RTC
 if [ "$CONFIG_IA64" = "y" ]; then
    bool 'EFI Real Time Clock Services' CONFIG_EFI_RTC
diff -Naur linux-2.4.0-test7-pre5.orig/drivers/char/nvram.c linux-2.4.0-test7-pre5/drivers/char/nvram.c
--- linux-2.4.0-test7-pre5.orig/drivers/char/nvram.c	Sat Aug 19 19:53:28 2000
+++ linux-2.4.0-test7-pre5/drivers/char/nvram.c	Sat Aug 19 20:19:57 2000
@@ -26,11 +26,12 @@
  * drivers, this is the case on the Atari.
  *
  *
+ * 	1.2	Cesar Barros: added nvram_bytes parameter
  * 	1.1	Cesar Barros: SMP locking fixes
  * 		added changelog
  */
 
-#define NVRAM_VERSION		"1.1"
+#define NVRAM_VERSION		"1.2"
 
 #include <linux/module.h>
 #include <linux/config.h>
@@ -115,8 +116,21 @@
 #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 */
 
+#if MACH == PC
+#define NVRAM_DEFAULT_BYTES	CONFIG_NVRAM_BYTES	/* default number of NVRAM bytes */
+#define NVRAM_MIN_BYTES		14	/* minimum number of NVRAM bytes */
+#define NVRAM_MAX_BYTES		128	/* maximum number of NVRAM bytes */
+
+static int nvram_bytes = NVRAM_DEFAULT_BYTES;
+#else
+#define NVRAM_DEFAULT_BYTES	50	/* ignore CONFIG_NVRAM_BYTES */
+#define NVRAM_MIN_BYTES		NVRAM_DEFAULT_BYTES
+#define NVRAM_MAX_BYTES		NVRAM_DEFAULT_BYTES
+
+#define nvram_bytes	NVRAM_DEFAULT_BYTES
+#define NVRAM_BYTES_FIXED
+#endif
 
 static int mach_check_checksum( void );
 static void mach_set_checksum( void );
@@ -223,7 +237,7 @@
 		offset += file->f_pos;
 		break;
 	  case 2:
-		offset += NVRAM_BYTES;
+		offset += nvram_bytes;
 		break;
 	}
 	return( (offset >= 0) ? (file->f_pos = offset) : -EINVAL );
@@ -232,7 +246,7 @@
 static ssize_t nvram_read(struct file * file,
 	char * buf, size_t count, loff_t *ppos )
 {
-	char contents [NVRAM_BYTES];
+	char contents [NVRAM_MAX_BYTES];
 	unsigned i = *ppos;
 	char *tmp;
 
@@ -241,7 +255,7 @@
 	if (!nvram_check_checksum_int())
 		goto checksum_err;
 
-	for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
+	for (tmp = contents; count-- > 0 && i < nvram_bytes; ++i, ++tmp)
 		*tmp = nvram_read_int(i);
 
 	spin_unlock_irq (&rtc_lock);
@@ -260,13 +274,13 @@
 static ssize_t nvram_write(struct file * file,
 		const char * buf, size_t count, loff_t *ppos )
 {
-	char contents [NVRAM_BYTES];
+	char contents [NVRAM_MAX_BYTES];
 	unsigned i = *ppos;
 	char * tmp;
 
 	/* could comebody please help me indent this better? */
-	copy_from_user_ret (contents, buf, (NVRAM_BYTES - i) < count ?
-						(NVRAM_BYTES - i) : count,
+	copy_from_user_ret (contents, buf, (nvram_bytes - i) < count ?
+						(nvram_bytes - i) : count,
 				-EFAULT);
 
 	spin_lock_irq (&rtc_lock);
@@ -274,7 +288,7 @@
 	if (!nvram_check_checksum_int())
 		goto checksum_err;
 
-	for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
+	for (tmp = contents; count-- > 0 && i < nvram_bytes; ++i, ++tmp)
 		nvram_write_int (*tmp, i);
 
 	nvram_set_checksum_int();
@@ -303,7 +317,7 @@
 
 		spin_lock_irq (&rtc_lock);
 
-		for( i = 0; i < NVRAM_BYTES; ++i )
+		for( i = 0; i < nvram_bytes; ++i )
 			nvram_write_int( 0, i );
 		nvram_set_checksum_int();
 		
@@ -363,12 +377,12 @@
 static int nvram_read_proc( char *buffer, char **start, off_t offset,
 							int size, int *eof, void *data )
 {
-	unsigned char contents[NVRAM_BYTES];
+	unsigned char contents[NVRAM_MAX_BYTES];
     int i, len = 0;
     off_t begin = 0;
 
 	spin_lock_irq (&rtc_lock);
-	for( i = 0; i < NVRAM_BYTES; ++i )
+	for( i = 0; i < nvram_bytes; ++i )
 		contents[i] = nvram_read_int( i );
 	spin_unlock_irq (&rtc_lock);
 	
@@ -412,9 +426,36 @@
 	&nvram_fops
 };
 
+#ifndef NVRAM_BYTES_FIXED
+/* Why is module that easier? */
+#ifdef MODULE
+MODULE_PARM(nvram_bytes,"i");
+#else
+static int __init nvram_bytes_setup (char *str)
+{
+	int opt;
+
+	get_option (&str, &opt);
+
+	if (opt >= NVRAM_MIN_BYTES && opt <= NVRAM_MAX_BYTES)
+		nvram_bytes = opt;
+	else
+		printk (KERN_ERR "nvram: nvram_bytes out of bounds, using default of %d\n", NVRAM_BYTES_DEFAULT);
+
+	return 1;
+}
+
+__setup("nvram_bytes=", nvram_bytes_setup);
+#endif
+#endif
 
 static int __init nvram_init(void)
 {
+#if defined (MODULE) && !defined (NVRAM_BYTES_FIXED)
+	if (nvram_bytes < NVRAM_MIN_BYTES || nvram_bytes > NVRAM_MAX_BYTES)
+		goto out_of_bounds;
+#endif
+
 	/* First test whether the driver should init at all */
 	if (!CHECK_DRIVER_INIT())
 	    return( -ENXIO );
@@ -423,6 +464,12 @@
 	misc_register( &nvram_dev );
 	create_proc_read_entry("driver/nvram",0,0,nvram_read_proc,NULL);
 	return( 0 );
+
+#if defined (MODULE) && !defined (NVRAM_BYTES_FIXED)
+out_of_bounds:
+	printk (KERN_ERR "nvram: nvram_bytes out of bounds\n");
+	return -EINVAL;
+#endif
 }
 
 static void __exit nvram_cleanup_module (void)

-- 
Cesar Eduardo Barros
cesarb _at_ nitnet.com.br
cesarb _at_ dcc.ufrj.br
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo _at_ vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

この情報があなたの探していたものかどうか選択してください。
yes/まさにこれだ!   no/違うなぁ   part/一部見つかった   try/これで試してみる

あなたが探していた情報はどのようなことか、ご自由に記入下さい。特に「まさにこれだ!」と言う場合は記入をお願いします。
例:「複数のマシンからCATV経由でipmasqueradeを利用してWebを参照したい場合の設定について」
Follow-Ups: