11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * CMOS/NV-RAM driver for Linux 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> 51da177e4SLinus Torvalds * idea by and with help from Richard Jelinek <rj@suse.de> 61da177e4SLinus Torvalds * Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com) 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This driver allows you to access the contents of the non-volatile memory in 91da177e4SLinus Torvalds * the mc146818rtc.h real-time clock. This chip is built into all PCs and into 101da177e4SLinus Torvalds * many Atari machines. In the former it's called "CMOS-RAM", in the latter 111da177e4SLinus Torvalds * "NVRAM" (NV stands for non-volatile). 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * The data are supplied as a (seekable) character device, /dev/nvram. The 141da177e4SLinus Torvalds * size of this file is dependent on the controller. The usual size is 114, 151da177e4SLinus Torvalds * the number of freely available bytes in the memory (i.e., not used by the 161da177e4SLinus Torvalds * RTC itself). 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * Checksums over the NVRAM contents are managed by this driver. In case of a 191da177e4SLinus Torvalds * bad checksum, reads and writes return -EIO. The checksum can be initialized 201da177e4SLinus Torvalds * to a sane state either by ioctl(NVRAM_INIT) (clear whole NVRAM) or 211da177e4SLinus Torvalds * ioctl(NVRAM_SETCKS) (doesn't change contents, just makes checksum valid 221da177e4SLinus Torvalds * again; use with care!) 231da177e4SLinus Torvalds * 241da177e4SLinus Torvalds * 1.1 Cesar Barros: SMP locking fixes 251da177e4SLinus Torvalds * added changelog 261da177e4SLinus Torvalds * 1.2 Erik Gilling: Cobalt Networks support 271da177e4SLinus Torvalds * Tim Hockin: general cleanup, Cobalt support 288587b33fSWim Van Sebroeck * 1.3 Wim Van Sebroeck: convert PRINT_PROC to seq_file 291da177e4SLinus Torvalds */ 301da177e4SLinus Torvalds 318587b33fSWim Van Sebroeck #define NVRAM_VERSION "1.3" 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds #include <linux/module.h> 341da177e4SLinus Torvalds #include <linux/nvram.h> 351da177e4SLinus Torvalds #include <linux/types.h> 361da177e4SLinus Torvalds #include <linux/errno.h> 371da177e4SLinus Torvalds #include <linux/miscdevice.h> 381da177e4SLinus Torvalds #include <linux/ioport.h> 391da177e4SLinus Torvalds #include <linux/fcntl.h> 401da177e4SLinus Torvalds #include <linux/mc146818rtc.h> 411da177e4SLinus Torvalds #include <linux/init.h> 421da177e4SLinus Torvalds #include <linux/proc_fs.h> 438587b33fSWim Van Sebroeck #include <linux/seq_file.h> 441da177e4SLinus Torvalds #include <linux/spinlock.h> 45971ddcf8SWim Van Sebroeck #include <linux/io.h> 46971ddcf8SWim Van Sebroeck #include <linux/uaccess.h> 47613655faSArnd Bergmann #include <linux/mutex.h> 48b808b1d6SAl Viro #include <linux/pagemap.h> 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds 51613655faSArnd Bergmann static DEFINE_MUTEX(nvram_mutex); 521da177e4SLinus Torvalds static DEFINE_SPINLOCK(nvram_state_lock); 531da177e4SLinus Torvalds static int nvram_open_cnt; /* #times opened */ 541da177e4SLinus Torvalds static int nvram_open_mode; /* special open modes */ 55d5bbb502SFinn Thain static ssize_t nvram_size; 561da177e4SLinus Torvalds #define NVRAM_WRITE 1 /* opened for writing (exclusive) */ 571da177e4SLinus Torvalds #define NVRAM_EXCL 2 /* opened with O_EXCL */ 581da177e4SLinus Torvalds 59d5bbb502SFinn Thain #ifdef CONFIG_X86 601da177e4SLinus Torvalds /* 611da177e4SLinus Torvalds * These functions are provided to be called internally or by other parts of 621da177e4SLinus Torvalds * the kernel. It's up to the caller to ensure correct checksum before reading 631da177e4SLinus Torvalds * or after writing (needs to be done only once). 641da177e4SLinus Torvalds * 651da177e4SLinus Torvalds * It is worth noting that these functions all access bytes of general 661da177e4SLinus Torvalds * purpose memory in the NVRAM - that is to say, they all add the 671da177e4SLinus Torvalds * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not 681da177e4SLinus Torvalds * know about the RTC cruft. 691da177e4SLinus Torvalds */ 701da177e4SLinus Torvalds 71437ace37SFinn Thain #define NVRAM_BYTES (128 - NVRAM_FIRST_BYTE) 72437ace37SFinn Thain 73437ace37SFinn Thain /* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with 74437ace37SFinn Thain * rtc_lock held. Due to the index-port/data-port design of the RTC, we 75437ace37SFinn Thain * don't want two different things trying to get to it at once. (e.g. the 76437ace37SFinn Thain * periodic 11 min sync from kernel/time/ntp.c vs. this driver.) 77437ace37SFinn Thain */ 78437ace37SFinn Thain 791278cf66SFinn Thain static unsigned char __nvram_read_byte(int i) 801da177e4SLinus Torvalds { 811da177e4SLinus Torvalds return CMOS_READ(NVRAM_FIRST_BYTE + i); 821da177e4SLinus Torvalds } 831da177e4SLinus Torvalds 841278cf66SFinn Thain static unsigned char pc_nvram_read_byte(int i) 851da177e4SLinus Torvalds { 861da177e4SLinus Torvalds unsigned long flags; 871da177e4SLinus Torvalds unsigned char c; 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds spin_lock_irqsave(&rtc_lock, flags); 901da177e4SLinus Torvalds c = __nvram_read_byte(i); 911da177e4SLinus Torvalds spin_unlock_irqrestore(&rtc_lock, flags); 921da177e4SLinus Torvalds return c; 931da177e4SLinus Torvalds } 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* This races nicely with trying to read with checksum checking (nvram_read) */ 961278cf66SFinn Thain static void __nvram_write_byte(unsigned char c, int i) 971da177e4SLinus Torvalds { 981da177e4SLinus Torvalds CMOS_WRITE(c, NVRAM_FIRST_BYTE + i); 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds 1011278cf66SFinn Thain static void pc_nvram_write_byte(unsigned char c, int i) 1021da177e4SLinus Torvalds { 1031da177e4SLinus Torvalds unsigned long flags; 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds spin_lock_irqsave(&rtc_lock, flags); 1061da177e4SLinus Torvalds __nvram_write_byte(c, i); 1071da177e4SLinus Torvalds spin_unlock_irqrestore(&rtc_lock, flags); 1081da177e4SLinus Torvalds } 1091da177e4SLinus Torvalds 110437ace37SFinn Thain /* On PCs, the checksum is built only over bytes 2..31 */ 111437ace37SFinn Thain #define PC_CKS_RANGE_START 2 112437ace37SFinn Thain #define PC_CKS_RANGE_END 31 113437ace37SFinn Thain #define PC_CKS_LOC 32 114437ace37SFinn Thain 1151278cf66SFinn Thain static int __nvram_check_checksum(void) 1161da177e4SLinus Torvalds { 117437ace37SFinn Thain int i; 118437ace37SFinn Thain unsigned short sum = 0; 119437ace37SFinn Thain unsigned short expect; 120437ace37SFinn Thain 121437ace37SFinn Thain for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i) 122437ace37SFinn Thain sum += __nvram_read_byte(i); 123437ace37SFinn Thain expect = __nvram_read_byte(PC_CKS_LOC)<<8 | 124437ace37SFinn Thain __nvram_read_byte(PC_CKS_LOC+1); 125437ace37SFinn Thain return (sum & 0xffff) == expect; 1261da177e4SLinus Torvalds } 1271da177e4SLinus Torvalds 128971ddcf8SWim Van Sebroeck static void __nvram_set_checksum(void) 1291da177e4SLinus Torvalds { 130437ace37SFinn Thain int i; 131437ace37SFinn Thain unsigned short sum = 0; 132437ace37SFinn Thain 133437ace37SFinn Thain for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i) 134437ace37SFinn Thain sum += __nvram_read_byte(i); 135437ace37SFinn Thain __nvram_write_byte(sum >> 8, PC_CKS_LOC); 136437ace37SFinn Thain __nvram_write_byte(sum & 0xff, PC_CKS_LOC + 1); 1371da177e4SLinus Torvalds } 1381da177e4SLinus Torvalds 139*2d58636eSFinn Thain static long pc_nvram_set_checksum(void) 1401da177e4SLinus Torvalds { 141*2d58636eSFinn Thain spin_lock_irq(&rtc_lock); 1421da177e4SLinus Torvalds __nvram_set_checksum(); 143*2d58636eSFinn Thain spin_unlock_irq(&rtc_lock); 144*2d58636eSFinn Thain return 0; 1451da177e4SLinus Torvalds } 146*2d58636eSFinn Thain 147*2d58636eSFinn Thain static long pc_nvram_initialize(void) 148*2d58636eSFinn Thain { 149*2d58636eSFinn Thain ssize_t i; 150*2d58636eSFinn Thain 151*2d58636eSFinn Thain spin_lock_irq(&rtc_lock); 152*2d58636eSFinn Thain for (i = 0; i < NVRAM_BYTES; ++i) 153*2d58636eSFinn Thain __nvram_write_byte(0, i); 154*2d58636eSFinn Thain __nvram_set_checksum(); 155*2d58636eSFinn Thain spin_unlock_irq(&rtc_lock); 156*2d58636eSFinn Thain return 0; 157*2d58636eSFinn Thain } 1581da177e4SLinus Torvalds 159d5bbb502SFinn Thain static ssize_t pc_nvram_get_size(void) 160d5bbb502SFinn Thain { 161d5bbb502SFinn Thain return NVRAM_BYTES; 162d5bbb502SFinn Thain } 163d5bbb502SFinn Thain 164d5bbb502SFinn Thain const struct nvram_ops arch_nvram_ops = { 165d5bbb502SFinn Thain .read_byte = pc_nvram_read_byte, 166d5bbb502SFinn Thain .write_byte = pc_nvram_write_byte, 167d5bbb502SFinn Thain .get_size = pc_nvram_get_size, 168*2d58636eSFinn Thain .set_checksum = pc_nvram_set_checksum, 169*2d58636eSFinn Thain .initialize = pc_nvram_initialize, 170d5bbb502SFinn Thain }; 171d5bbb502SFinn Thain EXPORT_SYMBOL(arch_nvram_ops); 172d5bbb502SFinn Thain #endif /* CONFIG_X86 */ 173d5bbb502SFinn Thain 1741da177e4SLinus Torvalds /* 1751da177e4SLinus Torvalds * The are the file operation function for user access to /dev/nvram 1761da177e4SLinus Torvalds */ 1771da177e4SLinus Torvalds 178cb8d8006SFinn Thain static loff_t nvram_misc_llseek(struct file *file, loff_t offset, int origin) 1791da177e4SLinus Torvalds { 180b808b1d6SAl Viro return generic_file_llseek_size(file, offset, origin, MAX_LFS_FILESIZE, 181d5bbb502SFinn Thain nvram_size); 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds 184cb8d8006SFinn Thain static ssize_t nvram_misc_read(struct file *file, char __user *buf, 185971ddcf8SWim Van Sebroeck size_t count, loff_t *ppos) 1861da177e4SLinus Torvalds { 1871da177e4SLinus Torvalds unsigned char contents[NVRAM_BYTES]; 1881da177e4SLinus Torvalds unsigned i = *ppos; 1891da177e4SLinus Torvalds unsigned char *tmp; 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds spin_lock_irq(&rtc_lock); 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds if (!__nvram_check_checksum()) 1941da177e4SLinus Torvalds goto checksum_err; 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp) 1971da177e4SLinus Torvalds *tmp = __nvram_read_byte(i); 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds spin_unlock_irq(&rtc_lock); 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds if (copy_to_user(buf, contents, tmp - contents)) 2021da177e4SLinus Torvalds return -EFAULT; 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds *ppos = i; 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds return tmp - contents; 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds checksum_err: 2091da177e4SLinus Torvalds spin_unlock_irq(&rtc_lock); 2101da177e4SLinus Torvalds return -EIO; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 213cb8d8006SFinn Thain static ssize_t nvram_misc_write(struct file *file, const char __user *buf, 214971ddcf8SWim Van Sebroeck size_t count, loff_t *ppos) 2151da177e4SLinus Torvalds { 2161da177e4SLinus Torvalds unsigned char contents[NVRAM_BYTES]; 2171da177e4SLinus Torvalds unsigned i = *ppos; 2181da177e4SLinus Torvalds unsigned char *tmp; 2191da177e4SLinus Torvalds 220a01c7800SH. Peter Anvin if (i >= NVRAM_BYTES) 221a01c7800SH. Peter Anvin return 0; /* Past EOF */ 222a01c7800SH. Peter Anvin 223a01c7800SH. Peter Anvin if (count > NVRAM_BYTES - i) 224a01c7800SH. Peter Anvin count = NVRAM_BYTES - i; 225a01c7800SH. Peter Anvin if (count > NVRAM_BYTES) 226a01c7800SH. Peter Anvin return -EFAULT; /* Can't happen, but prove it to gcc */ 227a01c7800SH. Peter Anvin 228a01c7800SH. Peter Anvin if (copy_from_user(contents, buf, count)) 2291da177e4SLinus Torvalds return -EFAULT; 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds spin_lock_irq(&rtc_lock); 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds if (!__nvram_check_checksum()) 2341da177e4SLinus Torvalds goto checksum_err; 2351da177e4SLinus Torvalds 236a01c7800SH. Peter Anvin for (tmp = contents; count--; ++i, ++tmp) 2371da177e4SLinus Torvalds __nvram_write_byte(*tmp, i); 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds __nvram_set_checksum(); 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds spin_unlock_irq(&rtc_lock); 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds *ppos = i; 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds return tmp - contents; 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds checksum_err: 2481da177e4SLinus Torvalds spin_unlock_irq(&rtc_lock); 2491da177e4SLinus Torvalds return -EIO; 2501da177e4SLinus Torvalds } 2511da177e4SLinus Torvalds 252cb8d8006SFinn Thain static long nvram_misc_ioctl(struct file *file, unsigned int cmd, 25355929332SArnd Bergmann unsigned long arg) 2541da177e4SLinus Torvalds { 255*2d58636eSFinn Thain long ret = -ENOTTY; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds switch (cmd) { 2581da177e4SLinus Torvalds case NVRAM_INIT: 2591da177e4SLinus Torvalds /* initialize NVRAM contents and checksum */ 2601da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) 2611da177e4SLinus Torvalds return -EACCES; 2621da177e4SLinus Torvalds 263*2d58636eSFinn Thain if (arch_nvram_ops.initialize != NULL) { 264613655faSArnd Bergmann mutex_lock(&nvram_mutex); 265*2d58636eSFinn Thain ret = arch_nvram_ops.initialize(); 266613655faSArnd Bergmann mutex_unlock(&nvram_mutex); 267*2d58636eSFinn Thain } 268*2d58636eSFinn Thain break; 2691da177e4SLinus Torvalds case NVRAM_SETCKS: 2701da177e4SLinus Torvalds /* just set checksum, contents unchanged (maybe useful after 2711da177e4SLinus Torvalds * checksum garbaged somehow...) */ 2721da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) 2731da177e4SLinus Torvalds return -EACCES; 2741da177e4SLinus Torvalds 275*2d58636eSFinn Thain if (arch_nvram_ops.set_checksum != NULL) { 276613655faSArnd Bergmann mutex_lock(&nvram_mutex); 277*2d58636eSFinn Thain ret = arch_nvram_ops.set_checksum(); 278613655faSArnd Bergmann mutex_unlock(&nvram_mutex); 2791da177e4SLinus Torvalds } 280*2d58636eSFinn Thain break; 281*2d58636eSFinn Thain } 282*2d58636eSFinn Thain return ret; 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds 285cb8d8006SFinn Thain static int nvram_misc_open(struct inode *inode, struct file *file) 2861da177e4SLinus Torvalds { 2871da177e4SLinus Torvalds spin_lock(&nvram_state_lock); 2881da177e4SLinus Torvalds 289*2d58636eSFinn Thain /* Prevent multiple readers/writers if desired. */ 2901da177e4SLinus Torvalds if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || 291*2d58636eSFinn Thain (nvram_open_mode & NVRAM_EXCL)) { 292*2d58636eSFinn Thain spin_unlock(&nvram_state_lock); 293*2d58636eSFinn Thain return -EBUSY; 294*2d58636eSFinn Thain } 295*2d58636eSFinn Thain 296*2d58636eSFinn Thain /* Prevent multiple writers if the set_checksum ioctl is implemented. */ 297*2d58636eSFinn Thain if ((arch_nvram_ops.set_checksum != NULL) && 298*2d58636eSFinn Thain (file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE)) { 2991da177e4SLinus Torvalds spin_unlock(&nvram_state_lock); 3001da177e4SLinus Torvalds return -EBUSY; 3011da177e4SLinus Torvalds } 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvalds if (file->f_flags & O_EXCL) 3041da177e4SLinus Torvalds nvram_open_mode |= NVRAM_EXCL; 305aeb5d727SAl Viro if (file->f_mode & FMODE_WRITE) 3061da177e4SLinus Torvalds nvram_open_mode |= NVRAM_WRITE; 3071da177e4SLinus Torvalds nvram_open_cnt++; 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds spin_unlock(&nvram_state_lock); 3101da177e4SLinus Torvalds 3111da177e4SLinus Torvalds return 0; 3121da177e4SLinus Torvalds } 3131da177e4SLinus Torvalds 314cb8d8006SFinn Thain static int nvram_misc_release(struct inode *inode, struct file *file) 3151da177e4SLinus Torvalds { 3161da177e4SLinus Torvalds spin_lock(&nvram_state_lock); 3171da177e4SLinus Torvalds 3181da177e4SLinus Torvalds nvram_open_cnt--; 3191da177e4SLinus Torvalds 3201da177e4SLinus Torvalds /* if only one instance is open, clear the EXCL bit */ 3211da177e4SLinus Torvalds if (nvram_open_mode & NVRAM_EXCL) 3221da177e4SLinus Torvalds nvram_open_mode &= ~NVRAM_EXCL; 323aeb5d727SAl Viro if (file->f_mode & FMODE_WRITE) 3241da177e4SLinus Torvalds nvram_open_mode &= ~NVRAM_WRITE; 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds spin_unlock(&nvram_state_lock); 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds return 0; 3291da177e4SLinus Torvalds } 3301da177e4SLinus Torvalds 331d5bbb502SFinn Thain #if defined(CONFIG_X86) && defined(CONFIG_PROC_FS) 332a116eaf1SLABBE Corentin static const char * const floppy_types[] = { 3331da177e4SLinus Torvalds "none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M", 3341da177e4SLinus Torvalds "3.5'' 2.88M", "3.5'' 2.88M" 3351da177e4SLinus Torvalds }; 3361da177e4SLinus Torvalds 337a116eaf1SLABBE Corentin static const char * const gfx_types[] = { 3381da177e4SLinus Torvalds "EGA, VGA, ... (with BIOS)", 3391da177e4SLinus Torvalds "CGA (40 cols)", 3401da177e4SLinus Torvalds "CGA (80 cols)", 3411da177e4SLinus Torvalds "monochrome", 3421da177e4SLinus Torvalds }; 3431da177e4SLinus Torvalds 344437ace37SFinn Thain static void pc_nvram_proc_read(unsigned char *nvram, struct seq_file *seq, 3458587b33fSWim Van Sebroeck void *offset) 3461da177e4SLinus Torvalds { 3471da177e4SLinus Torvalds int checksum; 3481da177e4SLinus Torvalds int type; 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds spin_lock_irq(&rtc_lock); 3511da177e4SLinus Torvalds checksum = __nvram_check_checksum(); 3521da177e4SLinus Torvalds spin_unlock_irq(&rtc_lock); 3531da177e4SLinus Torvalds 3548587b33fSWim Van Sebroeck seq_printf(seq, "Checksum status: %svalid\n", checksum ? "" : "not "); 3551da177e4SLinus Torvalds 3568587b33fSWim Van Sebroeck seq_printf(seq, "# floppies : %d\n", 3571da177e4SLinus Torvalds (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0); 3588587b33fSWim Van Sebroeck seq_printf(seq, "Floppy 0 type : "); 3591da177e4SLinus Torvalds type = nvram[2] >> 4; 360fe971071STobias Klauser if (type < ARRAY_SIZE(floppy_types)) 3618587b33fSWim Van Sebroeck seq_printf(seq, "%s\n", floppy_types[type]); 3621da177e4SLinus Torvalds else 3638587b33fSWim Van Sebroeck seq_printf(seq, "%d (unknown)\n", type); 3648587b33fSWim Van Sebroeck seq_printf(seq, "Floppy 1 type : "); 3651da177e4SLinus Torvalds type = nvram[2] & 0x0f; 366fe971071STobias Klauser if (type < ARRAY_SIZE(floppy_types)) 3678587b33fSWim Van Sebroeck seq_printf(seq, "%s\n", floppy_types[type]); 3681da177e4SLinus Torvalds else 3698587b33fSWim Van Sebroeck seq_printf(seq, "%d (unknown)\n", type); 3701da177e4SLinus Torvalds 3718587b33fSWim Van Sebroeck seq_printf(seq, "HD 0 type : "); 3721da177e4SLinus Torvalds type = nvram[4] >> 4; 3731da177e4SLinus Torvalds if (type) 3748587b33fSWim Van Sebroeck seq_printf(seq, "%02x\n", type == 0x0f ? nvram[11] : type); 3751da177e4SLinus Torvalds else 3768587b33fSWim Van Sebroeck seq_printf(seq, "none\n"); 3771da177e4SLinus Torvalds 3788587b33fSWim Van Sebroeck seq_printf(seq, "HD 1 type : "); 3791da177e4SLinus Torvalds type = nvram[4] & 0x0f; 3801da177e4SLinus Torvalds if (type) 3818587b33fSWim Van Sebroeck seq_printf(seq, "%02x\n", type == 0x0f ? nvram[12] : type); 3821da177e4SLinus Torvalds else 3838587b33fSWim Van Sebroeck seq_printf(seq, "none\n"); 3841da177e4SLinus Torvalds 3858587b33fSWim Van Sebroeck seq_printf(seq, "HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 3861da177e4SLinus Torvalds nvram[18] | (nvram[19] << 8), 3871da177e4SLinus Torvalds nvram[20], nvram[25], 3881da177e4SLinus Torvalds nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8)); 3898587b33fSWim Van Sebroeck seq_printf(seq, "HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 3901da177e4SLinus Torvalds nvram[39] | (nvram[40] << 8), 3911da177e4SLinus Torvalds nvram[41], nvram[46], 3921da177e4SLinus Torvalds nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8)); 3931da177e4SLinus Torvalds 3948587b33fSWim Van Sebroeck seq_printf(seq, "DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); 3958587b33fSWim Van Sebroeck seq_printf(seq, "Extended memory: %d kB (configured), %d kB (tested)\n", 3961da177e4SLinus Torvalds nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8)); 3971da177e4SLinus Torvalds 3988587b33fSWim Van Sebroeck seq_printf(seq, "Gfx adapter : %s\n", 3998587b33fSWim Van Sebroeck gfx_types[(nvram[6] >> 4) & 3]); 4001da177e4SLinus Torvalds 4018587b33fSWim Van Sebroeck seq_printf(seq, "FPU : %sinstalled\n", 4021da177e4SLinus Torvalds (nvram[6] & 2) ? "" : "not "); 4031da177e4SLinus Torvalds 4048587b33fSWim Van Sebroeck return; 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds 407cb8d8006SFinn Thain static int nvram_proc_read(struct seq_file *seq, void *offset) 408cb8d8006SFinn Thain { 409cb8d8006SFinn Thain unsigned char contents[NVRAM_BYTES]; 410cb8d8006SFinn Thain int i = 0; 411cb8d8006SFinn Thain 412cb8d8006SFinn Thain spin_lock_irq(&rtc_lock); 413cb8d8006SFinn Thain for (i = 0; i < NVRAM_BYTES; ++i) 414cb8d8006SFinn Thain contents[i] = __nvram_read_byte(i); 415cb8d8006SFinn Thain spin_unlock_irq(&rtc_lock); 416cb8d8006SFinn Thain 417cb8d8006SFinn Thain pc_nvram_proc_read(contents, seq, offset); 418cb8d8006SFinn Thain 419cb8d8006SFinn Thain return 0; 420cb8d8006SFinn Thain } 421d5bbb502SFinn Thain #endif /* CONFIG_X86 && CONFIG_PROC_FS */ 4221da177e4SLinus Torvalds 423cb8d8006SFinn Thain static const struct file_operations nvram_misc_fops = { 424cb8d8006SFinn Thain .owner = THIS_MODULE, 425cb8d8006SFinn Thain .llseek = nvram_misc_llseek, 426cb8d8006SFinn Thain .read = nvram_misc_read, 427cb8d8006SFinn Thain .write = nvram_misc_write, 428cb8d8006SFinn Thain .unlocked_ioctl = nvram_misc_ioctl, 429cb8d8006SFinn Thain .open = nvram_misc_open, 430cb8d8006SFinn Thain .release = nvram_misc_release, 431cb8d8006SFinn Thain }; 432cb8d8006SFinn Thain 433cb8d8006SFinn Thain static struct miscdevice nvram_misc = { 434cb8d8006SFinn Thain NVRAM_MINOR, 435cb8d8006SFinn Thain "nvram", 436cb8d8006SFinn Thain &nvram_misc_fops, 437cb8d8006SFinn Thain }; 438cb8d8006SFinn Thain 439cb8d8006SFinn Thain static int __init nvram_module_init(void) 440cb8d8006SFinn Thain { 441cb8d8006SFinn Thain int ret; 442cb8d8006SFinn Thain 443d5bbb502SFinn Thain nvram_size = nvram_get_size(); 444d5bbb502SFinn Thain if (nvram_size < 0) 445d5bbb502SFinn Thain return nvram_size; 446d5bbb502SFinn Thain 447cb8d8006SFinn Thain ret = misc_register(&nvram_misc); 448cb8d8006SFinn Thain if (ret) { 449cb8d8006SFinn Thain pr_err("nvram: can't misc_register on minor=%d\n", NVRAM_MINOR); 450cb8d8006SFinn Thain return ret; 451cb8d8006SFinn Thain } 452cb8d8006SFinn Thain 453d5bbb502SFinn Thain #if defined(CONFIG_X86) && defined(CONFIG_PROC_FS) 454cb8d8006SFinn Thain if (!proc_create_single("driver/nvram", 0, NULL, nvram_proc_read)) { 455cb8d8006SFinn Thain pr_err("nvram: can't create /proc/driver/nvram\n"); 456cb8d8006SFinn Thain misc_deregister(&nvram_misc); 457cb8d8006SFinn Thain return -ENOMEM; 458cb8d8006SFinn Thain } 459cb8d8006SFinn Thain #endif 460cb8d8006SFinn Thain 461cb8d8006SFinn Thain pr_info("Non-volatile memory driver v" NVRAM_VERSION "\n"); 462cb8d8006SFinn Thain return 0; 463cb8d8006SFinn Thain } 464cb8d8006SFinn Thain 465cb8d8006SFinn Thain static void __exit nvram_module_exit(void) 466cb8d8006SFinn Thain { 467d5bbb502SFinn Thain #if defined(CONFIG_X86) && defined(CONFIG_PROC_FS) 468cb8d8006SFinn Thain remove_proc_entry("driver/nvram", NULL); 469cb8d8006SFinn Thain #endif 470cb8d8006SFinn Thain misc_deregister(&nvram_misc); 471cb8d8006SFinn Thain } 472cb8d8006SFinn Thain 473cb8d8006SFinn Thain module_init(nvram_module_init); 474cb8d8006SFinn Thain module_exit(nvram_module_exit); 475cb8d8006SFinn Thain 4761da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 4771da177e4SLinus Torvalds MODULE_ALIAS_MISCDEV(NVRAM_MINOR); 478