38 #define NVRAM_VERSION "1.3"
40 #include <linux/module.h>
41 #include <linux/nvram.h>
47 #if defined(CONFIG_ATARI)
49 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__)
52 # error Cannot build nvram driver for this machine configuration.
58 #define CHECK_DRIVER_INIT() 1
61 #define PC_CKS_RANGE_START 2
62 #define PC_CKS_RANGE_END 31
64 #define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
66 #define mach_check_checksum pc_check_checksum
67 #define mach_set_checksum pc_set_checksum
68 #define mach_proc_infos pc_proc_infos
77 #define RTC_PORT(x) (TT_RTC_BAS + 2*(x))
78 #define CHECK_DRIVER_INIT() (MACH_IS_ATARI && ATARIHW_PRESENT(TT_CLK))
80 #define NVRAM_BYTES 50
84 #define ATARI_CKS_RANGE_START 0
85 #define ATARI_CKS_RANGE_END 47
86 #define ATARI_CKS_LOC 48
88 #define mach_check_checksum atari_check_checksum
89 #define mach_set_checksum atari_set_checksum
90 #define mach_proc_infos atari_proc_infos
100 #include <linux/types.h>
101 #include <linux/errno.h>
104 #include <linux/fcntl.h>
117 static int nvram_open_cnt;
118 static int nvram_open_mode;
119 #define NVRAM_WRITE 1
122 static int mach_check_checksum(
void);
123 static void mach_set_checksum(
void);
125 #ifdef CONFIG_PROC_FS
126 static void mach_proc_infos(
unsigned char *contents,
struct seq_file *seq,
154 spin_unlock_irqrestore(&
rtc_lock, flags);
172 spin_unlock_irqrestore(&
rtc_lock, flags);
178 return mach_check_checksum();
189 spin_unlock_irqrestore(&
rtc_lock, flags);
194 static void __nvram_set_checksum(
void)
200 void nvram_set_checksum(
void)
205 __nvram_set_checksum();
206 spin_unlock_irqrestore(&rtc_lock, flags);
221 offset += file->
f_pos;
224 offset += NVRAM_BYTES;
233 static ssize_t nvram_read(
struct file *file,
char __user *
buf,
234 size_t count, loff_t *ppos)
236 unsigned char contents[NVRAM_BYTES];
240 spin_lock_irq(&rtc_lock);
245 for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++
i, ++
tmp)
248 spin_unlock_irq(&rtc_lock);
255 return tmp - contents;
258 spin_unlock_irq(&rtc_lock);
262 static ssize_t nvram_write(
struct file *file,
const char __user *buf,
263 size_t count, loff_t *ppos)
265 unsigned char contents[NVRAM_BYTES];
269 if (i >= NVRAM_BYTES)
272 if (count > NVRAM_BYTES - i)
273 count = NVRAM_BYTES -
i;
274 if (count > NVRAM_BYTES)
280 spin_lock_irq(&rtc_lock);
285 for (tmp = contents; count--; ++
i, ++
tmp)
288 __nvram_set_checksum();
290 spin_unlock_irq(&rtc_lock);
294 return tmp - contents;
297 spin_unlock_irq(&rtc_lock);
301 static long nvram_ioctl(
struct file *file,
unsigned int cmd,
314 spin_lock_irq(&rtc_lock);
316 for (i = 0; i < NVRAM_BYTES; ++
i)
318 __nvram_set_checksum();
320 spin_unlock_irq(&rtc_lock);
331 spin_lock_irq(&rtc_lock);
332 __nvram_set_checksum();
333 spin_unlock_irq(&rtc_lock);
342 static int nvram_open(
struct inode *
inode,
struct file *file)
344 spin_lock(&nvram_state_lock);
349 spin_unlock(&nvram_state_lock);
359 spin_unlock(&nvram_state_lock);
364 static int nvram_release(
struct inode *inode,
struct file *file)
366 spin_lock(&nvram_state_lock);
371 if (nvram_open_mode & NVRAM_EXCL)
372 nvram_open_mode &= ~NVRAM_EXCL;
374 nvram_open_mode &= ~NVRAM_WRITE;
376 spin_unlock(&nvram_state_lock);
381 #ifndef CONFIG_PROC_FS
382 static int nvram_add_proc_fs(
void)
389 static int nvram_proc_read(
struct seq_file *seq,
void *offset)
391 unsigned char contents[NVRAM_BYTES];
394 spin_lock_irq(&rtc_lock);
395 for (i = 0; i < NVRAM_BYTES; ++
i)
397 spin_unlock_irq(&rtc_lock);
399 mach_proc_infos(contents, seq, offset);
404 static int nvram_proc_open(
struct inode *inode,
struct file *file)
411 .open = nvram_proc_open,
417 static int nvram_add_proc_fs(
void)
419 if (!proc_create(
"driver/nvram", 0,
NULL, &nvram_proc_fops))
428 .llseek = nvram_llseek,
430 .write = nvram_write,
431 .unlocked_ioctl = nvram_ioctl,
433 .release = nvram_release,
447 if (!CHECK_DRIVER_INIT())
456 ret = nvram_add_proc_fs();
470 static void __exit nvram_cleanup_module(
void)
485 static int pc_check_checksum(
void)
488 unsigned short sum = 0;
489 unsigned short expect;
491 for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++
i)
495 return (sum & 0xffff) == expect;
498 static void pc_set_checksum(
void)
501 unsigned short sum = 0;
503 for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++
i)
509 #ifdef CONFIG_PROC_FS
511 static char *floppy_types[] = {
512 "none",
"5.25'' 360k",
"5.25'' 1.2M",
"3.5'' 720k",
"3.5'' 1.44M",
513 "3.5'' 2.88M",
"3.5'' 2.88M"
516 static char *gfx_types[] = {
517 "EGA, VGA, ... (with BIOS)",
523 static void pc_proc_infos(
unsigned char *
nvram,
struct seq_file *seq,
529 spin_lock_irq(&rtc_lock);
531 spin_unlock_irq(&rtc_lock);
533 seq_printf(seq,
"Checksum status: %svalid\n", checksum ?
"" :
"not ");
536 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0);
538 type = nvram[2] >> 4;
544 type = nvram[2] & 0x0f;
551 type = nvram[4] >> 4;
553 seq_printf(seq,
"%02x\n", type == 0x0f ? nvram[11] : type);
558 type = nvram[4] & 0x0f;
560 seq_printf(seq,
"%02x\n", type == 0x0f ? nvram[12] : type);
564 seq_printf(seq,
"HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
565 nvram[18] | (nvram[19] << 8),
566 nvram[20], nvram[25],
567 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8));
568 seq_printf(seq,
"HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
569 nvram[39] | (nvram[40] << 8),
570 nvram[41], nvram[46],
571 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8));
573 seq_printf(seq,
"DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8));
574 seq_printf(seq,
"Extended memory: %d kB (configured), %d kB (tested)\n",
575 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8));
578 gfx_types[(nvram[6] >> 4) & 3]);
581 (nvram[6] & 2) ?
"" :
"not ");
591 static int atari_check_checksum(
void)
594 unsigned char sum = 0;
596 for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++
i)
602 static void atari_set_checksum(
void)
605 unsigned char sum = 0;
607 for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++
i)
613 #ifdef CONFIG_PROC_FS
621 { 0x20,
"NetBSD (?)" },
623 { 0x00,
"unspecified" }
626 static char *languages[] = {
638 static char *dateformat[] = {
650 "2",
"4",
"16",
"256",
"65536",
"??",
"??",
"??"
653 static void atari_proc_infos(
unsigned char *nvram,
struct seq_file *seq,
660 seq_printf(seq,
"Checksum status : %svalid\n", checksum ?
"" :
"not ");
663 for (i =
ARRAY_SIZE(boot_prefs) - 1; i >= 0; --
i) {
664 if (nvram[1] == boot_prefs[i].
val) {
670 seq_printf(seq,
"0x%02x (undefined)\n", nvram[1]);
673 (nvram[16] & 0x80) ?
"on" :
"off");
675 if (nvram[16] & 0x80)
688 seq_printf(seq,
"%u (undefined)\n", nvram[6]);
693 seq_printf(seq,
"%u (undefined)\n", nvram[7]);
696 nvram[9] ? nvram[9] :
'/', nvram[9] ? nvram[9] :
'/');
697 seq_printf(seq,
", %dh clock\n", nvram[8] & 16 ? 24 : 12);
703 nvram[10] < 8 ?
", no memory test" :
"");
705 vmode = (nvram[14] << 8) || nvram[15];
707 "Video mode : %s colors, %d columns, %s %s monitor\n",
710 vmode & 16 ?
"VGA" :
"TV", vmode & 32 ?
"PAL" :
"NTSC");
711 seq_printf(seq,
" %soverscan, compat. mode %s%s\n",
712 vmode & 64 ?
"" :
"no ",
713 vmode & 128 ?
"on" :
"off",
715 (vmode & 16 ?
", line doubling" :
", half screen") :
"");