2 * CMOS/NV-RAM driver for Linux
4 * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 * idea by and with help from Richard Jelinek <rj@suse.de>
6 * Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com)
8 * This driver allows you to access the contents of the non-volatile memory in
9 * the mc146818rtc.h real-time clock. This chip is built into all PCs and into
10 * many Atari machines. In the former it's called "CMOS-RAM", in the latter
11 * "NVRAM" (NV stands for non-volatile).
13 * The data are supplied as a (seekable) character device, /dev/nvram. The
14 * size of this file is dependent on the controller. The usual size is 114,
15 * the number of freely available bytes in the memory (i.e., not used by the
18 * Checksums over the NVRAM contents are managed by this driver. In case of a
19 * bad checksum, reads and writes return -EIO. The checksum can be initialized
20 * to a sane state either by ioctl(NVRAM_INIT) (clear whole NVRAM) or
21 * ioctl(NVRAM_SETCKS) (doesn't change contents, just makes checksum valid
22 * again; use with care!)
24 * This file also provides some functions for other parts of the kernel that
25 * want to access the NVRAM: nvram_{read,write,check_checksum,set_checksum}.
26 * Obviously this can be used only if this driver is always configured into
27 * the kernel and is not a module. Since the functions are used by some Atari
28 * drivers, this is the case on the Atari.
31 * 1.1 Cesar Barros: SMP locking fixes
33 * 1.2 Erik Gilling: Cobalt Networks support
34 * Tim Hockin: general cleanup, Cobalt support
35 * 1.3 Jon Ringle: Comdial MP1000 support
39 #define NVRAM_VERSION "1.3"
41 #include <linux/module.h>
42 #include <linux/config.h>
43 #include <linux/sched.h>
44 #include <linux/smp_lock.h>
45 #include <linux/nvram.h>
52 /* select machine configuration */
53 #if defined(CONFIG_ATARI)
55 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and others?? */
57 # if defined(CONFIG_COBALT)
58 # include <linux/cobalt-nvram.h>
60 # elif defined(CONFIG_MACH_MP1000)
67 # error Cannot build nvram driver for this machine configuration.
73 #define CHECK_DRIVER_INIT() 1
75 /* On PCs, the checksum is built only over bytes 2..31 */
76 #define PC_CKS_RANGE_START 2
77 #define PC_CKS_RANGE_END 31
79 #define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
81 #define mach_check_checksum pc_check_checksum
82 #define mach_set_checksum pc_set_checksum
83 #define mach_proc_infos pc_proc_infos
89 #define CHECK_DRIVER_INIT() 1
91 #define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
93 #define mach_check_checksum cobalt_check_checksum
94 #define mach_set_checksum cobalt_set_checksum
95 #define mach_proc_infos cobalt_proc_infos
101 /* Special parameters for RTC in Atari machines */
102 #include <asm/atarihw.h>
103 #include <asm/atariints.h>
104 #define RTC_PORT(x) (TT_RTC_BAS + 2*(x))
105 #define CHECK_DRIVER_INIT() (MACH_IS_ATARI && ATARIHW_PRESENT(TT_CLK))
107 #define NVRAM_BYTES 50
109 /* On Ataris, the checksum is over all bytes except the checksum bytes
110 * themselves; these are at the very end */
111 #define ATARI_CKS_RANGE_START 0
112 #define ATARI_CKS_RANGE_END 47
113 #define ATARI_CKS_LOC 48
115 #define mach_check_checksum atari_check_checksum
116 #define mach_set_checksum atari_set_checksum
117 #define mach_proc_infos atari_proc_infos
123 /* RTC in a MP1000 */
124 #define CHECK_DRIVER_INIT() 1
126 #define MP1000_CKS_RANGE_START 0
127 #define MP1000_CKS_RANGE_END 111
128 #define MP1000_CKS_LOC 112
130 #define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
132 #define mach_check_checksum mp1000_check_checksum
133 #define mach_set_checksum mp1000_set_checksum
134 #define mach_proc_infos mp1000_proc_infos
138 /* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
139 * rtc_lock held. Due to the index-port/data-port design of the RTC, we
140 * don't want two different things trying to get to it at once. (e.g. the
141 * periodic 11 min sync from time.c vs. this driver.)
144 #include <linux/types.h>
145 #include <linux/errno.h>
146 #include <linux/miscdevice.h>
147 #include <linux/slab.h>
148 #include <linux/ioport.h>
149 #include <linux/fcntl.h>
150 #include <linux/mc146818rtc.h>
151 #include <linux/init.h>
152 #include <linux/proc_fs.h>
153 #include <linux/spinlock.h>
156 #include <asm/uaccess.h>
157 #include <asm/system.h>
159 static DEFINE_SPINLOCK(nvram_state_lock
);
160 static int nvram_open_cnt
; /* #times opened */
161 static int nvram_open_mode
; /* special open modes */
162 #define NVRAM_WRITE 1 /* opened for writing (exclusive) */
163 #define NVRAM_EXCL 2 /* opened with O_EXCL */
165 static int mach_check_checksum(void);
166 static void mach_set_checksum(void);
168 #ifdef CONFIG_PROC_FS
169 static int mach_proc_infos(unsigned char *contents
, char *buffer
, int *len
,
170 off_t
*begin
, off_t offset
, int size
);
174 * These functions are provided to be called internally or by other parts of
175 * the kernel. It's up to the caller to ensure correct checksum before reading
176 * or after writing (needs to be done only once).
178 * It is worth noting that these functions all access bytes of general
179 * purpose memory in the NVRAM - that is to say, they all add the
180 * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not
181 * know about the RTC cruft.
185 __nvram_read_byte(int i
)
187 return CMOS_READ(NVRAM_FIRST_BYTE
+ i
);
191 nvram_read_byte(int i
)
196 spin_lock_irqsave(&rtc_lock
, flags
);
197 c
= __nvram_read_byte(i
);
198 spin_unlock_irqrestore(&rtc_lock
, flags
);
202 /* This races nicely with trying to read with checksum checking (nvram_read) */
204 __nvram_write_byte(unsigned char c
, int i
)
206 CMOS_WRITE(c
, NVRAM_FIRST_BYTE
+ i
);
210 nvram_write_byte(unsigned char c
, int i
)
214 spin_lock_irqsave(&rtc_lock
, flags
);
215 __nvram_write_byte(c
, i
);
216 spin_unlock_irqrestore(&rtc_lock
, flags
);
220 __nvram_check_checksum(void)
222 return mach_check_checksum();
226 nvram_check_checksum(void)
231 spin_lock_irqsave(&rtc_lock
, flags
);
232 rv
= __nvram_check_checksum();
233 spin_unlock_irqrestore(&rtc_lock
, flags
);
238 __nvram_set_checksum(void)
245 nvram_set_checksum(void)
249 spin_lock_irqsave(&rtc_lock
, flags
);
250 __nvram_set_checksum();
251 spin_unlock_irqrestore(&rtc_lock
, flags
);
256 * The are the file operation function for user access to /dev/nvram
259 static loff_t
nvram_llseek(struct file
*file
,loff_t offset
, int origin
)
267 offset
+= file
->f_pos
;
270 offset
+= NVRAM_BYTES
;
274 return (offset
>= 0) ? (file
->f_pos
= offset
) : -EINVAL
;
278 nvram_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*ppos
)
280 unsigned char contents
[NVRAM_BYTES
];
284 spin_lock_irq(&rtc_lock
);
286 if (!__nvram_check_checksum())
289 for (tmp
= contents
; count
-- > 0 && i
< NVRAM_BYTES
; ++i
, ++tmp
)
290 *tmp
= __nvram_read_byte(i
);
292 spin_unlock_irq(&rtc_lock
);
294 if (copy_to_user(buf
, contents
, tmp
- contents
))
299 return tmp
- contents
;
302 spin_unlock_irq(&rtc_lock
);
307 nvram_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
309 unsigned char contents
[NVRAM_BYTES
];
314 len
= (NVRAM_BYTES
- i
) < count
? (NVRAM_BYTES
- i
) : count
;
315 if (copy_from_user(contents
, buf
, len
))
318 spin_lock_irq(&rtc_lock
);
320 if (!__nvram_check_checksum())
323 for (tmp
= contents
; count
-- > 0 && i
< NVRAM_BYTES
; ++i
, ++tmp
)
324 __nvram_write_byte(*tmp
, i
);
326 __nvram_set_checksum();
328 spin_unlock_irq(&rtc_lock
);
332 return tmp
- contents
;
335 spin_unlock_irq(&rtc_lock
);
340 nvram_ioctl(struct inode
*inode
, struct file
*file
,
341 unsigned int cmd
, unsigned long arg
)
348 /* initialize NVRAM contents and checksum */
349 if (!capable(CAP_SYS_ADMIN
))
352 spin_lock_irq(&rtc_lock
);
354 for (i
= 0; i
< NVRAM_BYTES
; ++i
)
355 __nvram_write_byte(0, i
);
356 __nvram_set_checksum();
358 spin_unlock_irq(&rtc_lock
);
362 /* just set checksum, contents unchanged (maybe useful after
363 * checksum garbaged somehow...) */
364 if (!capable(CAP_SYS_ADMIN
))
367 spin_lock_irq(&rtc_lock
);
368 __nvram_set_checksum();
369 spin_unlock_irq(&rtc_lock
);
378 nvram_open(struct inode
*inode
, struct file
*file
)
380 spin_lock(&nvram_state_lock
);
382 if ((nvram_open_cnt
&& (file
->f_flags
& O_EXCL
)) ||
383 (nvram_open_mode
& NVRAM_EXCL
) ||
384 ((file
->f_mode
& 2) && (nvram_open_mode
& NVRAM_WRITE
))) {
385 spin_unlock(&nvram_state_lock
);
389 if (file
->f_flags
& O_EXCL
)
390 nvram_open_mode
|= NVRAM_EXCL
;
391 if (file
->f_mode
& 2)
392 nvram_open_mode
|= NVRAM_WRITE
;
395 spin_unlock(&nvram_state_lock
);
401 nvram_release(struct inode
*inode
, struct file
*file
)
403 spin_lock(&nvram_state_lock
);
407 /* if only one instance is open, clear the EXCL bit */
408 if (nvram_open_mode
& NVRAM_EXCL
)
409 nvram_open_mode
&= ~NVRAM_EXCL
;
410 if (file
->f_mode
& 2)
411 nvram_open_mode
&= ~NVRAM_WRITE
;
413 spin_unlock(&nvram_state_lock
);
418 #ifndef CONFIG_PROC_FS
420 nvram_read_proc(char *buffer
, char **start
, off_t offset
,
421 int size
, int *eof
, void *data
)
428 nvram_read_proc(char *buffer
, char **start
, off_t offset
,
429 int size
, int *eof
, void *data
)
431 unsigned char contents
[NVRAM_BYTES
];
435 spin_lock_irq(&rtc_lock
);
436 for (i
= 0; i
< NVRAM_BYTES
; ++i
)
437 contents
[i
] = __nvram_read_byte(i
);
438 spin_unlock_irq(&rtc_lock
);
440 *eof
= mach_proc_infos(contents
, buffer
, &len
, &begin
, offset
, size
);
442 if (offset
>= begin
+ len
)
444 *start
= buffer
+ (offset
- begin
);
445 return (size
< begin
+ len
- offset
) ? size
: begin
+ len
- offset
;
449 /* This macro frees the machine specific function from bounds checking and
450 * this like that... */
451 #define PRINT_PROC(fmt,args...) \
453 *len += sprintf(buffer+*len, fmt, ##args); \
454 if (*begin + *len > offset + size) \
456 if (*begin + *len < offset) { \
462 #endif /* CONFIG_PROC_FS */
464 static struct file_operations nvram_fops
= {
465 .owner
= THIS_MODULE
,
466 .llseek
= nvram_llseek
,
468 .write
= nvram_write
,
469 .ioctl
= nvram_ioctl
,
471 .release
= nvram_release
,
474 static struct miscdevice nvram_dev
= {
485 /* First test whether the driver should init at all */
486 if (!CHECK_DRIVER_INIT())
489 ret
= misc_register(&nvram_dev
);
491 printk(KERN_ERR
"nvram: can't misc_register on minor=%d\n",
495 if (!create_proc_read_entry("driver/nvram", 0, NULL
, nvram_read_proc
,
497 printk(KERN_ERR
"nvram: can't create /proc/driver/nvram\n");
502 printk(KERN_INFO
"Non-volatile memory driver v" NVRAM_VERSION
"\n");
506 misc_deregister(&nvram_dev
);
511 nvram_cleanup_module(void)
513 remove_proc_entry("driver/nvram", NULL
);
514 misc_deregister(&nvram_dev
);
517 module_init(nvram_init
);
518 module_exit(nvram_cleanup_module
);
521 * Machine specific functions
527 pc_check_checksum(void)
530 unsigned short sum
= 0;
531 unsigned short expect
;
533 for (i
= PC_CKS_RANGE_START
; i
<= PC_CKS_RANGE_END
; ++i
)
534 sum
+= __nvram_read_byte(i
);
535 expect
= __nvram_read_byte(PC_CKS_LOC
)<<8 |
536 __nvram_read_byte(PC_CKS_LOC
+1);
537 return ((sum
& 0xffff) == expect
);
541 pc_set_checksum(void)
544 unsigned short sum
= 0;
546 for (i
= PC_CKS_RANGE_START
; i
<= PC_CKS_RANGE_END
; ++i
)
547 sum
+= __nvram_read_byte(i
);
548 __nvram_write_byte(sum
>> 8, PC_CKS_LOC
);
549 __nvram_write_byte(sum
& 0xff, PC_CKS_LOC
+ 1);
552 #ifdef CONFIG_PROC_FS
554 static char *floppy_types
[] = {
555 "none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M",
556 "3.5'' 2.88M", "3.5'' 2.88M"
559 static char *gfx_types
[] = {
560 "EGA, VGA, ... (with BIOS)",
567 pc_proc_infos(unsigned char *nvram
, char *buffer
, int *len
,
568 off_t
*begin
, off_t offset
, int size
)
573 spin_lock_irq(&rtc_lock
);
574 checksum
= __nvram_check_checksum();
575 spin_unlock_irq(&rtc_lock
);
577 PRINT_PROC("Checksum status: %svalid\n", checksum
? "" : "not ");
579 PRINT_PROC("# floppies : %d\n",
580 (nvram
[6] & 1) ? (nvram
[6] >> 6) + 1 : 0);
581 PRINT_PROC("Floppy 0 type : ");
582 type
= nvram
[2] >> 4;
583 if (type
< sizeof (floppy_types
) / sizeof (*floppy_types
))
584 PRINT_PROC("%s\n", floppy_types
[type
]);
586 PRINT_PROC("%d (unknown)\n", type
);
587 PRINT_PROC("Floppy 1 type : ");
588 type
= nvram
[2] & 0x0f;
589 if (type
< sizeof (floppy_types
) / sizeof (*floppy_types
))
590 PRINT_PROC("%s\n", floppy_types
[type
]);
592 PRINT_PROC("%d (unknown)\n", type
);
594 PRINT_PROC("HD 0 type : ");
595 type
= nvram
[4] >> 4;
597 PRINT_PROC("%02x\n", type
== 0x0f ? nvram
[11] : type
);
599 PRINT_PROC("none\n");
601 PRINT_PROC("HD 1 type : ");
602 type
= nvram
[4] & 0x0f;
604 PRINT_PROC("%02x\n", type
== 0x0f ? nvram
[12] : type
);
606 PRINT_PROC("none\n");
608 PRINT_PROC("HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
609 nvram
[18] | (nvram
[19] << 8),
610 nvram
[20], nvram
[25],
611 nvram
[21] | (nvram
[22] << 8), nvram
[23] | (nvram
[24] << 8));
612 PRINT_PROC("HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
613 nvram
[39] | (nvram
[40] << 8),
614 nvram
[41], nvram
[46],
615 nvram
[42] | (nvram
[43] << 8), nvram
[44] | (nvram
[45] << 8));
617 PRINT_PROC("DOS base memory: %d kB\n", nvram
[7] | (nvram
[8] << 8));
618 PRINT_PROC("Extended memory: %d kB (configured), %d kB (tested)\n",
619 nvram
[9] | (nvram
[10] << 8), nvram
[34] | (nvram
[35] << 8));
621 PRINT_PROC("Gfx adapter : %s\n", gfx_types
[(nvram
[6] >> 4) & 3]);
623 PRINT_PROC("FPU : %sinstalled\n",
624 (nvram
[6] & 2) ? "" : "not ");
630 #endif /* MACH == PC */
634 /* the cobalt CMOS has a wider range of its checksum */
635 static int cobalt_check_checksum(void)
638 unsigned short sum
= 0;
639 unsigned short expect
;
641 for (i
= COBT_CMOS_CKS_START
; i
<= COBT_CMOS_CKS_END
; ++i
) {
642 if ((i
== COBT_CMOS_CHECKSUM
) || (i
== (COBT_CMOS_CHECKSUM
+1)))
645 sum
+= __nvram_read_byte(i
);
647 expect
= __nvram_read_byte(COBT_CMOS_CHECKSUM
) << 8 |
648 __nvram_read_byte(COBT_CMOS_CHECKSUM
+1);
649 return ((sum
& 0xffff) == expect
);
652 static void cobalt_set_checksum(void)
655 unsigned short sum
= 0;
657 for (i
= COBT_CMOS_CKS_START
; i
<= COBT_CMOS_CKS_END
; ++i
) {
658 if ((i
== COBT_CMOS_CHECKSUM
) || (i
== (COBT_CMOS_CHECKSUM
+1)))
661 sum
+= __nvram_read_byte(i
);
664 __nvram_write_byte(sum
>> 8, COBT_CMOS_CHECKSUM
);
665 __nvram_write_byte(sum
& 0xff, COBT_CMOS_CHECKSUM
+1);
668 #ifdef CONFIG_PROC_FS
670 static int cobalt_proc_infos(unsigned char *nvram
, char *buffer
, int *len
,
671 off_t
*begin
, off_t offset
, int size
)
674 unsigned int checksum
;
677 char *key
= "cNoEbTaWlOtR!";
678 unsigned char bto_csum
;
680 spin_lock_irq(&rtc_lock
);
681 checksum
= __nvram_check_checksum();
682 spin_unlock_irq(&rtc_lock
);
684 PRINT_PROC("Checksum status: %svalid\n", checksum
? "" : "not ");
686 flags
= nvram
[COBT_CMOS_FLAG_BYTE_0
] << 8
687 | nvram
[COBT_CMOS_FLAG_BYTE_1
];
689 PRINT_PROC("Console: %s\n",
690 flags
& COBT_CMOS_CONSOLE_FLAG
? "on": "off");
692 PRINT_PROC("Firmware Debug Messages: %s\n",
693 flags
& COBT_CMOS_DEBUG_FLAG
? "on": "off");
695 PRINT_PROC("Auto Prompt: %s\n",
696 flags
& COBT_CMOS_AUTO_PROMPT_FLAG
? "on": "off");
698 PRINT_PROC("Shutdown Status: %s\n",
699 flags
& COBT_CMOS_CLEAN_BOOT_FLAG
? "clean": "dirty");
701 PRINT_PROC("Hardware Probe: %s\n",
702 flags
& COBT_CMOS_HW_NOPROBE_FLAG
? "partial": "full");
704 PRINT_PROC("System Fault: %sdetected\n",
705 flags
& COBT_CMOS_SYSFAULT_FLAG
? "": "not ");
707 PRINT_PROC("Panic on OOPS: %s\n",
708 flags
& COBT_CMOS_OOPSPANIC_FLAG
? "yes": "no");
710 PRINT_PROC("Delayed Cache Initialization: %s\n",
711 flags
& COBT_CMOS_DELAY_CACHE_FLAG
? "yes": "no");
713 PRINT_PROC("Show Logo at Boot: %s\n",
714 flags
& COBT_CMOS_NOLOGO_FLAG
? "no": "yes");
716 PRINT_PROC("Boot Method: ");
717 switch (nvram
[COBT_CMOS_BOOT_METHOD
]) {
718 case COBT_CMOS_BOOT_METHOD_DISK
:
719 PRINT_PROC("disk\n");
722 case COBT_CMOS_BOOT_METHOD_ROM
:
726 case COBT_CMOS_BOOT_METHOD_NET
:
731 PRINT_PROC("unknown\n");
735 PRINT_PROC("Primary Boot Device: %d:%d\n",
736 nvram
[COBT_CMOS_BOOT_DEV0_MAJ
],
737 nvram
[COBT_CMOS_BOOT_DEV0_MIN
] );
738 PRINT_PROC("Secondary Boot Device: %d:%d\n",
739 nvram
[COBT_CMOS_BOOT_DEV1_MAJ
],
740 nvram
[COBT_CMOS_BOOT_DEV1_MIN
] );
741 PRINT_PROC("Tertiary Boot Device: %d:%d\n",
742 nvram
[COBT_CMOS_BOOT_DEV2_MAJ
],
743 nvram
[COBT_CMOS_BOOT_DEV2_MIN
] );
745 PRINT_PROC("Uptime: %d\n",
746 nvram
[COBT_CMOS_UPTIME_0
] << 24 |
747 nvram
[COBT_CMOS_UPTIME_1
] << 16 |
748 nvram
[COBT_CMOS_UPTIME_2
] << 8 |
749 nvram
[COBT_CMOS_UPTIME_3
]);
751 PRINT_PROC("Boot Count: %d\n",
752 nvram
[COBT_CMOS_BOOTCOUNT_0
] << 24 |
753 nvram
[COBT_CMOS_BOOTCOUNT_1
] << 16 |
754 nvram
[COBT_CMOS_BOOTCOUNT_2
] << 8 |
755 nvram
[COBT_CMOS_BOOTCOUNT_3
]);
757 /* 13 bytes of serial num */
758 for (i
=0 ; i
<13 ; i
++) {
759 sernum
[i
] = nvram
[COBT_CMOS_SYS_SERNUM_0
+ i
];
764 for (i
=0 ; i
<13 ; i
++) {
765 checksum
+= sernum
[i
] ^ key
[i
];
767 checksum
= ((checksum
& 0x7f) ^ (0xd6)) & 0xff;
769 PRINT_PROC("Serial Number: %s", sernum
);
770 if (checksum
!= nvram
[COBT_CMOS_SYS_SERNUM_CSUM
]) {
771 PRINT_PROC(" (invalid checksum)");
775 PRINT_PROC("Rom Revison: %d.%d.%d\n", nvram
[COBT_CMOS_ROM_REV_MAJ
],
776 nvram
[COBT_CMOS_ROM_REV_MIN
], nvram
[COBT_CMOS_ROM_REV_REV
]);
778 PRINT_PROC("BTO Server: %d.%d.%d.%d", nvram
[COBT_CMOS_BTO_IP_0
],
779 nvram
[COBT_CMOS_BTO_IP_1
], nvram
[COBT_CMOS_BTO_IP_2
],
780 nvram
[COBT_CMOS_BTO_IP_3
]);
781 bto_csum
= nvram
[COBT_CMOS_BTO_IP_0
] + nvram
[COBT_CMOS_BTO_IP_1
]
782 + nvram
[COBT_CMOS_BTO_IP_2
] + nvram
[COBT_CMOS_BTO_IP_3
];
783 if (bto_csum
!= nvram
[COBT_CMOS_BTO_IP_CSUM
]) {
784 PRINT_PROC(" (invalid checksum)");
788 if (flags
& COBT_CMOS_VERSION_FLAG
789 && nvram
[COBT_CMOS_VERSION
] >= COBT_CMOS_VER_BTOCODE
) {
790 PRINT_PROC("BTO Code: 0x%x\n",
791 nvram
[COBT_CMOS_BTO_CODE_0
] << 24 |
792 nvram
[COBT_CMOS_BTO_CODE_1
] << 16 |
793 nvram
[COBT_CMOS_BTO_CODE_2
] << 8 |
794 nvram
[COBT_CMOS_BTO_CODE_3
]);
799 #endif /* CONFIG_PROC_FS */
801 #endif /* MACH == COBALT */
806 atari_check_checksum(void)
809 unsigned char sum
= 0;
811 for (i
= ATARI_CKS_RANGE_START
; i
<= ATARI_CKS_RANGE_END
; ++i
)
812 sum
+= __nvram_read_byte(i
);
813 return (__nvram_read_byte(ATARI_CKS_LOC
) == (~sum
& 0xff) &&
814 __nvram_read_byte(ATARI_CKS_LOC
+ 1) == (sum
& 0xff));
818 atari_set_checksum(void)
821 unsigned char sum
= 0;
823 for (i
= ATARI_CKS_RANGE_START
; i
<= ATARI_CKS_RANGE_END
; ++i
)
824 sum
+= __nvram_read_byte(i
);
825 __nvram_write_byte(~sum
, ATARI_CKS_LOC
);
826 __nvram_write_byte(sum
, ATARI_CKS_LOC
+ 1);
829 #ifdef CONFIG_PROC_FS
837 { 0x20, "NetBSD (?)" },
839 { 0x00, "unspecified" }
842 static char *languages
[] = {
854 static char *dateformat
[] = {
865 static char *colors
[] = {
866 "2", "4", "16", "256", "65536", "??", "??", "??"
869 #define fieldsize(a) (sizeof(a)/sizeof(*a))
872 atari_proc_infos(unsigned char *nvram
, char *buffer
, int *len
,
873 off_t
*begin
, off_t offset
, int size
)
875 int checksum
= nvram_check_checksum();
879 PRINT_PROC("Checksum status : %svalid\n", checksum
? "" : "not ");
881 PRINT_PROC("Boot preference : ");
882 for (i
= fieldsize(boot_prefs
) - 1; i
>= 0; --i
) {
883 if (nvram
[1] == boot_prefs
[i
].val
) {
884 PRINT_PROC("%s\n", boot_prefs
[i
].name
);
889 PRINT_PROC("0x%02x (undefined)\n", nvram
[1]);
891 PRINT_PROC("SCSI arbitration : %s\n",
892 (nvram
[16] & 0x80) ? "on" : "off");
893 PRINT_PROC("SCSI host ID : ");
894 if (nvram
[16] & 0x80)
895 PRINT_PROC("%d\n", nvram
[16] & 7);
899 /* the following entries are defined only for the Falcon */
900 if ((atari_mch_cookie
>> 16) != ATARI_MCH_FALCON
)
903 PRINT_PROC("OS language : ");
904 if (nvram
[6] < fieldsize(languages
))
905 PRINT_PROC("%s\n", languages
[nvram
[6]]);
907 PRINT_PROC("%u (undefined)\n", nvram
[6]);
908 PRINT_PROC("Keyboard language: ");
909 if (nvram
[7] < fieldsize(languages
))
910 PRINT_PROC("%s\n", languages
[nvram
[7]]);
912 PRINT_PROC("%u (undefined)\n", nvram
[7]);
913 PRINT_PROC("Date format : ");
914 PRINT_PROC(dateformat
[nvram
[8] & 7],
915 nvram
[9] ? nvram
[9] : '/', nvram
[9] ? nvram
[9] : '/');
916 PRINT_PROC(", %dh clock\n", nvram
[8] & 16 ? 24 : 12);
917 PRINT_PROC("Boot delay : ");
919 PRINT_PROC("default");
921 PRINT_PROC("%ds%s\n", nvram
[10],
922 nvram
[10] < 8 ? ", no memory test" : "");
924 vmode
= (nvram
[14] << 8) || nvram
[15];
925 PRINT_PROC("Video mode : %s colors, %d columns, %s %s monitor\n",
928 vmode
& 16 ? "VGA" : "TV", vmode
& 32 ? "PAL" : "NTSC");
929 PRINT_PROC(" %soverscan, compat. mode %s%s\n",
930 vmode
& 64 ? "" : "no ",
931 vmode
& 128 ? "on" : "off",
933 (vmode
& 16 ? ", line doubling" : ", half screen") : "");
939 #endif /* MACH == ATARI */
944 mp1000_check_checksum(void)
947 unsigned short sum
= 0;
948 unsigned short expect
;
950 for (i
= MP1000_CKS_RANGE_START
; i
<= MP1000_CKS_RANGE_END
; ++i
)
951 sum
+= __nvram_read_byte(i
);
953 expect
= __nvram_read_byte(MP1000_CKS_LOC
+1)<<8 |
954 __nvram_read_byte(MP1000_CKS_LOC
);
955 return ((sum
& 0xffff) == expect
);
959 mp1000_set_checksum(void)
962 unsigned short sum
= 0;
964 for (i
= MP1000_CKS_RANGE_START
; i
<= MP1000_CKS_RANGE_END
; ++i
)
965 sum
+= __nvram_read_byte(i
);
966 __nvram_write_byte(sum
>> 8, MP1000_CKS_LOC
+ 1);
967 __nvram_write_byte(sum
& 0xff, MP1000_CKS_LOC
);
970 #ifdef CONFIG_PROC_FS
972 #define SERVER_N_LEN 32
973 #define PATH_N_LEN 32
974 #define FILE_N_LEN 32
975 #define NVRAM_MAGIC_SIG 0xdead
977 typedef struct NvRamImage
979 unsigned short int magic
;
980 unsigned short int mode
;
981 char fname
[FILE_N_LEN
];
982 char path
[PATH_N_LEN
];
983 char server
[SERVER_N_LEN
];
988 mp1000_proc_infos(unsigned char *nvram
, char *buffer
, int *len
,
989 off_t
*begin
, off_t offset
, int size
)
992 NvRam
* nv
= (NvRam
*)nvram
;
994 spin_lock_irq(&rtc_lock
);
995 checksum
= __nvram_check_checksum();
996 spin_unlock_irq(&rtc_lock
);
998 PRINT_PROC("Checksum status: %svalid\n", checksum
? "" : "not ");
1003 PRINT_PROC( "\tMode 0, tftp prompt\n" );
1006 PRINT_PROC( "\tMode 1, booting from disk\n" );
1009 PRINT_PROC( "\tMode 2, Alternate boot from disk /boot/%s\n", nv
->fname
);
1012 PRINT_PROC( "\tMode 3, Booting from net:\n" );
1013 PRINT_PROC( "\t\t%s:%s%s\n",nv
->server
, nv
->path
, nv
->fname
);
1016 PRINT_PROC( "\tInconsistant nvram?\n" );
1024 #endif /* MACH == MP1000 */
1026 MODULE_LICENSE("GPL");
1028 EXPORT_SYMBOL(__nvram_read_byte
);
1029 EXPORT_SYMBOL(nvram_read_byte
);
1030 EXPORT_SYMBOL(__nvram_write_byte
);
1031 EXPORT_SYMBOL(nvram_write_byte
);
1032 EXPORT_SYMBOL(__nvram_check_checksum
);
1033 EXPORT_SYMBOL(nvram_check_checksum
);
1034 MODULE_ALIAS_MISCDEV(NVRAM_MINOR
);