ia64/linux-2.6.18-xen.hg

annotate drivers/char/nvram.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:32:57 2009 +0100 (2009-06-04)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * CMOS/NV-RAM driver for Linux
ian@0 3 *
ian@0 4 * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
ian@0 5 * idea by and with help from Richard Jelinek <rj@suse.de>
ian@0 6 * Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com)
ian@0 7 *
ian@0 8 * This driver allows you to access the contents of the non-volatile memory in
ian@0 9 * the mc146818rtc.h real-time clock. This chip is built into all PCs and into
ian@0 10 * many Atari machines. In the former it's called "CMOS-RAM", in the latter
ian@0 11 * "NVRAM" (NV stands for non-volatile).
ian@0 12 *
ian@0 13 * The data are supplied as a (seekable) character device, /dev/nvram. The
ian@0 14 * size of this file is dependent on the controller. The usual size is 114,
ian@0 15 * the number of freely available bytes in the memory (i.e., not used by the
ian@0 16 * RTC itself).
ian@0 17 *
ian@0 18 * Checksums over the NVRAM contents are managed by this driver. In case of a
ian@0 19 * bad checksum, reads and writes return -EIO. The checksum can be initialized
ian@0 20 * to a sane state either by ioctl(NVRAM_INIT) (clear whole NVRAM) or
ian@0 21 * ioctl(NVRAM_SETCKS) (doesn't change contents, just makes checksum valid
ian@0 22 * again; use with care!)
ian@0 23 *
ian@0 24 * This file also provides some functions for other parts of the kernel that
ian@0 25 * want to access the NVRAM: nvram_{read,write,check_checksum,set_checksum}.
ian@0 26 * Obviously this can be used only if this driver is always configured into
ian@0 27 * the kernel and is not a module. Since the functions are used by some Atari
ian@0 28 * drivers, this is the case on the Atari.
ian@0 29 *
ian@0 30 *
ian@0 31 * 1.1 Cesar Barros: SMP locking fixes
ian@0 32 * added changelog
ian@0 33 * 1.2 Erik Gilling: Cobalt Networks support
ian@0 34 * Tim Hockin: general cleanup, Cobalt support
ian@0 35 */
ian@0 36
ian@0 37 #define NVRAM_VERSION "1.2"
ian@0 38
ian@0 39 #include <linux/module.h>
ian@0 40 #include <linux/sched.h>
ian@0 41 #include <linux/smp_lock.h>
ian@0 42 #include <linux/nvram.h>
ian@0 43
ian@0 44 #define PC 1
ian@0 45 #define ATARI 2
ian@0 46 #define COBALT 3
ian@0 47
ian@0 48 /* select machine configuration */
ian@0 49 #if defined(CONFIG_ATARI)
ian@0 50 # define MACH ATARI
ian@0 51 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and others?? */
ian@0 52 #define MACH PC
ian@0 53 # if defined(CONFIG_COBALT)
ian@0 54 # include <linux/cobalt-nvram.h>
ian@0 55 # define MACH COBALT
ian@0 56 # else
ian@0 57 # define MACH PC
ian@0 58 # endif
ian@0 59 #else
ian@0 60 # error Cannot build nvram driver for this machine configuration.
ian@0 61 #endif
ian@0 62
ian@0 63 #if MACH == PC
ian@0 64
ian@0 65 /* RTC in a PC */
ian@0 66 #define CHECK_DRIVER_INIT() 1
ian@0 67
ian@0 68 /* On PCs, the checksum is built only over bytes 2..31 */
ian@0 69 #define PC_CKS_RANGE_START 2
ian@0 70 #define PC_CKS_RANGE_END 31
ian@0 71 #define PC_CKS_LOC 32
ian@0 72 #define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
ian@0 73
ian@0 74 #define mach_check_checksum pc_check_checksum
ian@0 75 #define mach_set_checksum pc_set_checksum
ian@0 76 #define mach_proc_infos pc_proc_infos
ian@0 77
ian@0 78 #endif
ian@0 79
ian@0 80 #if MACH == COBALT
ian@0 81
ian@0 82 #define CHECK_DRIVER_INIT() 1
ian@0 83
ian@0 84 #define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
ian@0 85
ian@0 86 #define mach_check_checksum cobalt_check_checksum
ian@0 87 #define mach_set_checksum cobalt_set_checksum
ian@0 88 #define mach_proc_infos cobalt_proc_infos
ian@0 89
ian@0 90 #endif
ian@0 91
ian@0 92 #if MACH == ATARI
ian@0 93
ian@0 94 /* Special parameters for RTC in Atari machines */
ian@0 95 #include <asm/atarihw.h>
ian@0 96 #include <asm/atariints.h>
ian@0 97 #define RTC_PORT(x) (TT_RTC_BAS + 2*(x))
ian@0 98 #define CHECK_DRIVER_INIT() (MACH_IS_ATARI && ATARIHW_PRESENT(TT_CLK))
ian@0 99
ian@0 100 #define NVRAM_BYTES 50
ian@0 101
ian@0 102 /* On Ataris, the checksum is over all bytes except the checksum bytes
ian@0 103 * themselves; these are at the very end */
ian@0 104 #define ATARI_CKS_RANGE_START 0
ian@0 105 #define ATARI_CKS_RANGE_END 47
ian@0 106 #define ATARI_CKS_LOC 48
ian@0 107
ian@0 108 #define mach_check_checksum atari_check_checksum
ian@0 109 #define mach_set_checksum atari_set_checksum
ian@0 110 #define mach_proc_infos atari_proc_infos
ian@0 111
ian@0 112 #endif
ian@0 113
ian@0 114 /* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
ian@0 115 * rtc_lock held. Due to the index-port/data-port design of the RTC, we
ian@0 116 * don't want two different things trying to get to it at once. (e.g. the
ian@0 117 * periodic 11 min sync from time.c vs. this driver.)
ian@0 118 */
ian@0 119
ian@0 120 #include <linux/types.h>
ian@0 121 #include <linux/errno.h>
ian@0 122 #include <linux/miscdevice.h>
ian@0 123 #include <linux/slab.h>
ian@0 124 #include <linux/ioport.h>
ian@0 125 #include <linux/fcntl.h>
ian@0 126 #include <linux/mc146818rtc.h>
ian@0 127 #include <linux/init.h>
ian@0 128 #include <linux/proc_fs.h>
ian@0 129 #include <linux/spinlock.h>
ian@0 130
ian@0 131 #include <asm/io.h>
ian@0 132 #include <asm/uaccess.h>
ian@0 133 #include <asm/system.h>
ian@0 134
ian@0 135 static DEFINE_SPINLOCK(nvram_state_lock);
ian@0 136 static int nvram_open_cnt; /* #times opened */
ian@0 137 static int nvram_open_mode; /* special open modes */
ian@0 138 #define NVRAM_WRITE 1 /* opened for writing (exclusive) */
ian@0 139 #define NVRAM_EXCL 2 /* opened with O_EXCL */
ian@0 140
ian@0 141 static int mach_check_checksum(void);
ian@0 142 static void mach_set_checksum(void);
ian@0 143
ian@0 144 #ifdef CONFIG_PROC_FS
ian@0 145 static int mach_proc_infos(unsigned char *contents, char *buffer, int *len,
ian@0 146 off_t *begin, off_t offset, int size);
ian@0 147 #endif
ian@0 148
ian@0 149 /*
ian@0 150 * These functions are provided to be called internally or by other parts of
ian@0 151 * the kernel. It's up to the caller to ensure correct checksum before reading
ian@0 152 * or after writing (needs to be done only once).
ian@0 153 *
ian@0 154 * It is worth noting that these functions all access bytes of general
ian@0 155 * purpose memory in the NVRAM - that is to say, they all add the
ian@0 156 * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not
ian@0 157 * know about the RTC cruft.
ian@0 158 */
ian@0 159
ian@0 160 unsigned char
ian@0 161 __nvram_read_byte(int i)
ian@0 162 {
ian@0 163 return CMOS_READ(NVRAM_FIRST_BYTE + i);
ian@0 164 }
ian@0 165
ian@0 166 unsigned char
ian@0 167 nvram_read_byte(int i)
ian@0 168 {
ian@0 169 unsigned long flags;
ian@0 170 unsigned char c;
ian@0 171
ian@0 172 spin_lock_irqsave(&rtc_lock, flags);
ian@0 173 c = __nvram_read_byte(i);
ian@0 174 spin_unlock_irqrestore(&rtc_lock, flags);
ian@0 175 return c;
ian@0 176 }
ian@0 177
ian@0 178 /* This races nicely with trying to read with checksum checking (nvram_read) */
ian@0 179 void
ian@0 180 __nvram_write_byte(unsigned char c, int i)
ian@0 181 {
ian@0 182 CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
ian@0 183 }
ian@0 184
ian@0 185 void
ian@0 186 nvram_write_byte(unsigned char c, int i)
ian@0 187 {
ian@0 188 unsigned long flags;
ian@0 189
ian@0 190 spin_lock_irqsave(&rtc_lock, flags);
ian@0 191 __nvram_write_byte(c, i);
ian@0 192 spin_unlock_irqrestore(&rtc_lock, flags);
ian@0 193 }
ian@0 194
ian@0 195 int
ian@0 196 __nvram_check_checksum(void)
ian@0 197 {
ian@0 198 return mach_check_checksum();
ian@0 199 }
ian@0 200
ian@0 201 int
ian@0 202 nvram_check_checksum(void)
ian@0 203 {
ian@0 204 unsigned long flags;
ian@0 205 int rv;
ian@0 206
ian@0 207 spin_lock_irqsave(&rtc_lock, flags);
ian@0 208 rv = __nvram_check_checksum();
ian@0 209 spin_unlock_irqrestore(&rtc_lock, flags);
ian@0 210 return rv;
ian@0 211 }
ian@0 212
ian@0 213 static void
ian@0 214 __nvram_set_checksum(void)
ian@0 215 {
ian@0 216 mach_set_checksum();
ian@0 217 }
ian@0 218
ian@0 219 #if 0
ian@0 220 void
ian@0 221 nvram_set_checksum(void)
ian@0 222 {
ian@0 223 unsigned long flags;
ian@0 224
ian@0 225 spin_lock_irqsave(&rtc_lock, flags);
ian@0 226 __nvram_set_checksum();
ian@0 227 spin_unlock_irqrestore(&rtc_lock, flags);
ian@0 228 }
ian@0 229 #endif /* 0 */
ian@0 230
ian@0 231 /*
ian@0 232 * The are the file operation function for user access to /dev/nvram
ian@0 233 */
ian@0 234
ian@0 235 static loff_t nvram_llseek(struct file *file,loff_t offset, int origin )
ian@0 236 {
ian@0 237 lock_kernel();
ian@0 238 switch (origin) {
ian@0 239 case 0:
ian@0 240 /* nothing to do */
ian@0 241 break;
ian@0 242 case 1:
ian@0 243 offset += file->f_pos;
ian@0 244 break;
ian@0 245 case 2:
ian@0 246 offset += NVRAM_BYTES;
ian@0 247 break;
ian@0 248 }
ian@0 249 unlock_kernel();
ian@0 250 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
ian@0 251 }
ian@0 252
ian@0 253 static ssize_t
ian@0 254 nvram_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
ian@0 255 {
ian@0 256 unsigned char contents[NVRAM_BYTES];
ian@0 257 unsigned i = *ppos;
ian@0 258 unsigned char *tmp;
ian@0 259
ian@0 260 spin_lock_irq(&rtc_lock);
ian@0 261
ian@0 262 if (!__nvram_check_checksum())
ian@0 263 goto checksum_err;
ian@0 264
ian@0 265 for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
ian@0 266 *tmp = __nvram_read_byte(i);
ian@0 267
ian@0 268 spin_unlock_irq(&rtc_lock);
ian@0 269
ian@0 270 if (copy_to_user(buf, contents, tmp - contents))
ian@0 271 return -EFAULT;
ian@0 272
ian@0 273 *ppos = i;
ian@0 274
ian@0 275 return tmp - contents;
ian@0 276
ian@0 277 checksum_err:
ian@0 278 spin_unlock_irq(&rtc_lock);
ian@0 279 return -EIO;
ian@0 280 }
ian@0 281
ian@0 282 static ssize_t
ian@0 283 nvram_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
ian@0 284 {
ian@0 285 unsigned char contents[NVRAM_BYTES];
ian@0 286 unsigned i = *ppos;
ian@0 287 unsigned char *tmp;
ian@0 288 int len;
ian@0 289
ian@0 290 len = (NVRAM_BYTES - i) < count ? (NVRAM_BYTES - i) : count;
ian@0 291 if (copy_from_user(contents, buf, len))
ian@0 292 return -EFAULT;
ian@0 293
ian@0 294 spin_lock_irq(&rtc_lock);
ian@0 295
ian@0 296 if (!__nvram_check_checksum())
ian@0 297 goto checksum_err;
ian@0 298
ian@0 299 for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
ian@0 300 __nvram_write_byte(*tmp, i);
ian@0 301
ian@0 302 __nvram_set_checksum();
ian@0 303
ian@0 304 spin_unlock_irq(&rtc_lock);
ian@0 305
ian@0 306 *ppos = i;
ian@0 307
ian@0 308 return tmp - contents;
ian@0 309
ian@0 310 checksum_err:
ian@0 311 spin_unlock_irq(&rtc_lock);
ian@0 312 return -EIO;
ian@0 313 }
ian@0 314
ian@0 315 static int
ian@0 316 nvram_ioctl(struct inode *inode, struct file *file,
ian@0 317 unsigned int cmd, unsigned long arg)
ian@0 318 {
ian@0 319 int i;
ian@0 320
ian@0 321 switch (cmd) {
ian@0 322
ian@0 323 case NVRAM_INIT:
ian@0 324 /* initialize NVRAM contents and checksum */
ian@0 325 if (!capable(CAP_SYS_ADMIN))
ian@0 326 return -EACCES;
ian@0 327
ian@0 328 spin_lock_irq(&rtc_lock);
ian@0 329
ian@0 330 for (i = 0; i < NVRAM_BYTES; ++i)
ian@0 331 __nvram_write_byte(0, i);
ian@0 332 __nvram_set_checksum();
ian@0 333
ian@0 334 spin_unlock_irq(&rtc_lock);
ian@0 335 return 0;
ian@0 336
ian@0 337 case NVRAM_SETCKS:
ian@0 338 /* just set checksum, contents unchanged (maybe useful after
ian@0 339 * checksum garbaged somehow...) */
ian@0 340 if (!capable(CAP_SYS_ADMIN))
ian@0 341 return -EACCES;
ian@0 342
ian@0 343 spin_lock_irq(&rtc_lock);
ian@0 344 __nvram_set_checksum();
ian@0 345 spin_unlock_irq(&rtc_lock);
ian@0 346 return 0;
ian@0 347
ian@0 348 default:
ian@0 349 return -ENOTTY;
ian@0 350 }
ian@0 351 }
ian@0 352
ian@0 353 static int
ian@0 354 nvram_open(struct inode *inode, struct file *file)
ian@0 355 {
ian@0 356 spin_lock(&nvram_state_lock);
ian@0 357
ian@0 358 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
ian@0 359 (nvram_open_mode & NVRAM_EXCL) ||
ian@0 360 ((file->f_mode & 2) && (nvram_open_mode & NVRAM_WRITE))) {
ian@0 361 spin_unlock(&nvram_state_lock);
ian@0 362 return -EBUSY;
ian@0 363 }
ian@0 364
ian@0 365 if (file->f_flags & O_EXCL)
ian@0 366 nvram_open_mode |= NVRAM_EXCL;
ian@0 367 if (file->f_mode & 2)
ian@0 368 nvram_open_mode |= NVRAM_WRITE;
ian@0 369 nvram_open_cnt++;
ian@0 370
ian@0 371 spin_unlock(&nvram_state_lock);
ian@0 372
ian@0 373 return 0;
ian@0 374 }
ian@0 375
ian@0 376 static int
ian@0 377 nvram_release(struct inode *inode, struct file *file)
ian@0 378 {
ian@0 379 spin_lock(&nvram_state_lock);
ian@0 380
ian@0 381 nvram_open_cnt--;
ian@0 382
ian@0 383 /* if only one instance is open, clear the EXCL bit */
ian@0 384 if (nvram_open_mode & NVRAM_EXCL)
ian@0 385 nvram_open_mode &= ~NVRAM_EXCL;
ian@0 386 if (file->f_mode & 2)
ian@0 387 nvram_open_mode &= ~NVRAM_WRITE;
ian@0 388
ian@0 389 spin_unlock(&nvram_state_lock);
ian@0 390
ian@0 391 return 0;
ian@0 392 }
ian@0 393
ian@0 394 #ifndef CONFIG_PROC_FS
ian@0 395 static int
ian@0 396 nvram_read_proc(char *buffer, char **start, off_t offset,
ian@0 397 int size, int *eof, void *data)
ian@0 398 {
ian@0 399 return 0;
ian@0 400 }
ian@0 401 #else
ian@0 402
ian@0 403 static int
ian@0 404 nvram_read_proc(char *buffer, char **start, off_t offset,
ian@0 405 int size, int *eof, void *data)
ian@0 406 {
ian@0 407 unsigned char contents[NVRAM_BYTES];
ian@0 408 int i, len = 0;
ian@0 409 off_t begin = 0;
ian@0 410
ian@0 411 spin_lock_irq(&rtc_lock);
ian@0 412 for (i = 0; i < NVRAM_BYTES; ++i)
ian@0 413 contents[i] = __nvram_read_byte(i);
ian@0 414 spin_unlock_irq(&rtc_lock);
ian@0 415
ian@0 416 *eof = mach_proc_infos(contents, buffer, &len, &begin, offset, size);
ian@0 417
ian@0 418 if (offset >= begin + len)
ian@0 419 return 0;
ian@0 420 *start = buffer + (offset - begin);
ian@0 421 return (size < begin + len - offset) ? size : begin + len - offset;
ian@0 422
ian@0 423 }
ian@0 424
ian@0 425 /* This macro frees the machine specific function from bounds checking and
ian@0 426 * this like that... */
ian@0 427 #define PRINT_PROC(fmt,args...) \
ian@0 428 do { \
ian@0 429 *len += sprintf(buffer+*len, fmt, ##args); \
ian@0 430 if (*begin + *len > offset + size) \
ian@0 431 return 0; \
ian@0 432 if (*begin + *len < offset) { \
ian@0 433 *begin += *len; \
ian@0 434 *len = 0; \
ian@0 435 } \
ian@0 436 } while(0)
ian@0 437
ian@0 438 #endif /* CONFIG_PROC_FS */
ian@0 439
ian@0 440 static const struct file_operations nvram_fops = {
ian@0 441 .owner = THIS_MODULE,
ian@0 442 .llseek = nvram_llseek,
ian@0 443 .read = nvram_read,
ian@0 444 .write = nvram_write,
ian@0 445 .ioctl = nvram_ioctl,
ian@0 446 .open = nvram_open,
ian@0 447 .release = nvram_release,
ian@0 448 };
ian@0 449
ian@0 450 static struct miscdevice nvram_dev = {
ian@0 451 NVRAM_MINOR,
ian@0 452 "nvram",
ian@0 453 &nvram_fops
ian@0 454 };
ian@0 455
ian@0 456 static int __init
ian@0 457 nvram_init(void)
ian@0 458 {
ian@0 459 int ret;
ian@0 460
ian@0 461 /* First test whether the driver should init at all */
ian@0 462 if (!CHECK_DRIVER_INIT())
ian@0 463 return -ENXIO;
ian@0 464
ian@0 465 ret = misc_register(&nvram_dev);
ian@0 466 if (ret) {
ian@0 467 printk(KERN_ERR "nvram: can't misc_register on minor=%d\n",
ian@0 468 NVRAM_MINOR);
ian@0 469 goto out;
ian@0 470 }
ian@0 471 if (!create_proc_read_entry("driver/nvram", 0, NULL, nvram_read_proc,
ian@0 472 NULL)) {
ian@0 473 printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n");
ian@0 474 ret = -ENOMEM;
ian@0 475 goto outmisc;
ian@0 476 }
ian@0 477 ret = 0;
ian@0 478 printk(KERN_INFO "Non-volatile memory driver v" NVRAM_VERSION "\n");
ian@0 479 out:
ian@0 480 return ret;
ian@0 481 outmisc:
ian@0 482 misc_deregister(&nvram_dev);
ian@0 483 goto out;
ian@0 484 }
ian@0 485
ian@0 486 static void __exit
ian@0 487 nvram_cleanup_module(void)
ian@0 488 {
ian@0 489 remove_proc_entry("driver/nvram", NULL);
ian@0 490 misc_deregister(&nvram_dev);
ian@0 491 }
ian@0 492
ian@0 493 module_init(nvram_init);
ian@0 494 module_exit(nvram_cleanup_module);
ian@0 495
ian@0 496 /*
ian@0 497 * Machine specific functions
ian@0 498 */
ian@0 499
ian@0 500 #if MACH == PC
ian@0 501
ian@0 502 static int
ian@0 503 pc_check_checksum(void)
ian@0 504 {
ian@0 505 int i;
ian@0 506 unsigned short sum = 0;
ian@0 507 unsigned short expect;
ian@0 508
ian@0 509 for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i)
ian@0 510 sum += __nvram_read_byte(i);
ian@0 511 expect = __nvram_read_byte(PC_CKS_LOC)<<8 |
ian@0 512 __nvram_read_byte(PC_CKS_LOC+1);
ian@0 513 return ((sum & 0xffff) == expect);
ian@0 514 }
ian@0 515
ian@0 516 static void
ian@0 517 pc_set_checksum(void)
ian@0 518 {
ian@0 519 int i;
ian@0 520 unsigned short sum = 0;
ian@0 521
ian@0 522 for (i = PC_CKS_RANGE_START; i <= PC_CKS_RANGE_END; ++i)
ian@0 523 sum += __nvram_read_byte(i);
ian@0 524 __nvram_write_byte(sum >> 8, PC_CKS_LOC);
ian@0 525 __nvram_write_byte(sum & 0xff, PC_CKS_LOC + 1);
ian@0 526 }
ian@0 527
ian@0 528 #ifdef CONFIG_PROC_FS
ian@0 529
ian@0 530 static char *floppy_types[] = {
ian@0 531 "none", "5.25'' 360k", "5.25'' 1.2M", "3.5'' 720k", "3.5'' 1.44M",
ian@0 532 "3.5'' 2.88M", "3.5'' 2.88M"
ian@0 533 };
ian@0 534
ian@0 535 static char *gfx_types[] = {
ian@0 536 "EGA, VGA, ... (with BIOS)",
ian@0 537 "CGA (40 cols)",
ian@0 538 "CGA (80 cols)",
ian@0 539 "monochrome",
ian@0 540 };
ian@0 541
ian@0 542 static int
ian@0 543 pc_proc_infos(unsigned char *nvram, char *buffer, int *len,
ian@0 544 off_t *begin, off_t offset, int size)
ian@0 545 {
ian@0 546 int checksum;
ian@0 547 int type;
ian@0 548
ian@0 549 spin_lock_irq(&rtc_lock);
ian@0 550 checksum = __nvram_check_checksum();
ian@0 551 spin_unlock_irq(&rtc_lock);
ian@0 552
ian@0 553 PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not ");
ian@0 554
ian@0 555 PRINT_PROC("# floppies : %d\n",
ian@0 556 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0);
ian@0 557 PRINT_PROC("Floppy 0 type : ");
ian@0 558 type = nvram[2] >> 4;
ian@0 559 if (type < ARRAY_SIZE(floppy_types))
ian@0 560 PRINT_PROC("%s\n", floppy_types[type]);
ian@0 561 else
ian@0 562 PRINT_PROC("%d (unknown)\n", type);
ian@0 563 PRINT_PROC("Floppy 1 type : ");
ian@0 564 type = nvram[2] & 0x0f;
ian@0 565 if (type < ARRAY_SIZE(floppy_types))
ian@0 566 PRINT_PROC("%s\n", floppy_types[type]);
ian@0 567 else
ian@0 568 PRINT_PROC("%d (unknown)\n", type);
ian@0 569
ian@0 570 PRINT_PROC("HD 0 type : ");
ian@0 571 type = nvram[4] >> 4;
ian@0 572 if (type)
ian@0 573 PRINT_PROC("%02x\n", type == 0x0f ? nvram[11] : type);
ian@0 574 else
ian@0 575 PRINT_PROC("none\n");
ian@0 576
ian@0 577 PRINT_PROC("HD 1 type : ");
ian@0 578 type = nvram[4] & 0x0f;
ian@0 579 if (type)
ian@0 580 PRINT_PROC("%02x\n", type == 0x0f ? nvram[12] : type);
ian@0 581 else
ian@0 582 PRINT_PROC("none\n");
ian@0 583
ian@0 584 PRINT_PROC("HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
ian@0 585 nvram[18] | (nvram[19] << 8),
ian@0 586 nvram[20], nvram[25],
ian@0 587 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8));
ian@0 588 PRINT_PROC("HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
ian@0 589 nvram[39] | (nvram[40] << 8),
ian@0 590 nvram[41], nvram[46],
ian@0 591 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8));
ian@0 592
ian@0 593 PRINT_PROC("DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8));
ian@0 594 PRINT_PROC("Extended memory: %d kB (configured), %d kB (tested)\n",
ian@0 595 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8));
ian@0 596
ian@0 597 PRINT_PROC("Gfx adapter : %s\n", gfx_types[(nvram[6] >> 4) & 3]);
ian@0 598
ian@0 599 PRINT_PROC("FPU : %sinstalled\n",
ian@0 600 (nvram[6] & 2) ? "" : "not ");
ian@0 601
ian@0 602 return 1;
ian@0 603 }
ian@0 604 #endif
ian@0 605
ian@0 606 #endif /* MACH == PC */
ian@0 607
ian@0 608 #if MACH == COBALT
ian@0 609
ian@0 610 /* the cobalt CMOS has a wider range of its checksum */
ian@0 611 static int cobalt_check_checksum(void)
ian@0 612 {
ian@0 613 int i;
ian@0 614 unsigned short sum = 0;
ian@0 615 unsigned short expect;
ian@0 616
ian@0 617 for (i = COBT_CMOS_CKS_START; i <= COBT_CMOS_CKS_END; ++i) {
ian@0 618 if ((i == COBT_CMOS_CHECKSUM) || (i == (COBT_CMOS_CHECKSUM+1)))
ian@0 619 continue;
ian@0 620
ian@0 621 sum += __nvram_read_byte(i);
ian@0 622 }
ian@0 623 expect = __nvram_read_byte(COBT_CMOS_CHECKSUM) << 8 |
ian@0 624 __nvram_read_byte(COBT_CMOS_CHECKSUM+1);
ian@0 625 return ((sum & 0xffff) == expect);
ian@0 626 }
ian@0 627
ian@0 628 static void cobalt_set_checksum(void)
ian@0 629 {
ian@0 630 int i;
ian@0 631 unsigned short sum = 0;
ian@0 632
ian@0 633 for (i = COBT_CMOS_CKS_START; i <= COBT_CMOS_CKS_END; ++i) {
ian@0 634 if ((i == COBT_CMOS_CHECKSUM) || (i == (COBT_CMOS_CHECKSUM+1)))
ian@0 635 continue;
ian@0 636
ian@0 637 sum += __nvram_read_byte(i);
ian@0 638 }
ian@0 639
ian@0 640 __nvram_write_byte(sum >> 8, COBT_CMOS_CHECKSUM);
ian@0 641 __nvram_write_byte(sum & 0xff, COBT_CMOS_CHECKSUM+1);
ian@0 642 }
ian@0 643
ian@0 644 #ifdef CONFIG_PROC_FS
ian@0 645
ian@0 646 static int cobalt_proc_infos(unsigned char *nvram, char *buffer, int *len,
ian@0 647 off_t *begin, off_t offset, int size)
ian@0 648 {
ian@0 649 int i;
ian@0 650 unsigned int checksum;
ian@0 651 unsigned int flags;
ian@0 652 char sernum[14];
ian@0 653 char *key = "cNoEbTaWlOtR!";
ian@0 654 unsigned char bto_csum;
ian@0 655
ian@0 656 spin_lock_irq(&rtc_lock);
ian@0 657 checksum = __nvram_check_checksum();
ian@0 658 spin_unlock_irq(&rtc_lock);
ian@0 659
ian@0 660 PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not ");
ian@0 661
ian@0 662 flags = nvram[COBT_CMOS_FLAG_BYTE_0] << 8
ian@0 663 | nvram[COBT_CMOS_FLAG_BYTE_1];
ian@0 664
ian@0 665 PRINT_PROC("Console: %s\n",
ian@0 666 flags & COBT_CMOS_CONSOLE_FLAG ? "on": "off");
ian@0 667
ian@0 668 PRINT_PROC("Firmware Debug Messages: %s\n",
ian@0 669 flags & COBT_CMOS_DEBUG_FLAG ? "on": "off");
ian@0 670
ian@0 671 PRINT_PROC("Auto Prompt: %s\n",
ian@0 672 flags & COBT_CMOS_AUTO_PROMPT_FLAG ? "on": "off");
ian@0 673
ian@0 674 PRINT_PROC("Shutdown Status: %s\n",
ian@0 675 flags & COBT_CMOS_CLEAN_BOOT_FLAG ? "clean": "dirty");
ian@0 676
ian@0 677 PRINT_PROC("Hardware Probe: %s\n",
ian@0 678 flags & COBT_CMOS_HW_NOPROBE_FLAG ? "partial": "full");
ian@0 679
ian@0 680 PRINT_PROC("System Fault: %sdetected\n",
ian@0 681 flags & COBT_CMOS_SYSFAULT_FLAG ? "": "not ");
ian@0 682
ian@0 683 PRINT_PROC("Panic on OOPS: %s\n",
ian@0 684 flags & COBT_CMOS_OOPSPANIC_FLAG ? "yes": "no");
ian@0 685
ian@0 686 PRINT_PROC("Delayed Cache Initialization: %s\n",
ian@0 687 flags & COBT_CMOS_DELAY_CACHE_FLAG ? "yes": "no");
ian@0 688
ian@0 689 PRINT_PROC("Show Logo at Boot: %s\n",
ian@0 690 flags & COBT_CMOS_NOLOGO_FLAG ? "no": "yes");
ian@0 691
ian@0 692 PRINT_PROC("Boot Method: ");
ian@0 693 switch (nvram[COBT_CMOS_BOOT_METHOD]) {
ian@0 694 case COBT_CMOS_BOOT_METHOD_DISK:
ian@0 695 PRINT_PROC("disk\n");
ian@0 696 break;
ian@0 697
ian@0 698 case COBT_CMOS_BOOT_METHOD_ROM:
ian@0 699 PRINT_PROC("rom\n");
ian@0 700 break;
ian@0 701
ian@0 702 case COBT_CMOS_BOOT_METHOD_NET:
ian@0 703 PRINT_PROC("net\n");
ian@0 704 break;
ian@0 705
ian@0 706 default:
ian@0 707 PRINT_PROC("unknown\n");
ian@0 708 break;
ian@0 709 }
ian@0 710
ian@0 711 PRINT_PROC("Primary Boot Device: %d:%d\n",
ian@0 712 nvram[COBT_CMOS_BOOT_DEV0_MAJ],
ian@0 713 nvram[COBT_CMOS_BOOT_DEV0_MIN] );
ian@0 714 PRINT_PROC("Secondary Boot Device: %d:%d\n",
ian@0 715 nvram[COBT_CMOS_BOOT_DEV1_MAJ],
ian@0 716 nvram[COBT_CMOS_BOOT_DEV1_MIN] );
ian@0 717 PRINT_PROC("Tertiary Boot Device: %d:%d\n",
ian@0 718 nvram[COBT_CMOS_BOOT_DEV2_MAJ],
ian@0 719 nvram[COBT_CMOS_BOOT_DEV2_MIN] );
ian@0 720
ian@0 721 PRINT_PROC("Uptime: %d\n",
ian@0 722 nvram[COBT_CMOS_UPTIME_0] << 24 |
ian@0 723 nvram[COBT_CMOS_UPTIME_1] << 16 |
ian@0 724 nvram[COBT_CMOS_UPTIME_2] << 8 |
ian@0 725 nvram[COBT_CMOS_UPTIME_3]);
ian@0 726
ian@0 727 PRINT_PROC("Boot Count: %d\n",
ian@0 728 nvram[COBT_CMOS_BOOTCOUNT_0] << 24 |
ian@0 729 nvram[COBT_CMOS_BOOTCOUNT_1] << 16 |
ian@0 730 nvram[COBT_CMOS_BOOTCOUNT_2] << 8 |
ian@0 731 nvram[COBT_CMOS_BOOTCOUNT_3]);
ian@0 732
ian@0 733 /* 13 bytes of serial num */
ian@0 734 for (i=0 ; i<13 ; i++) {
ian@0 735 sernum[i] = nvram[COBT_CMOS_SYS_SERNUM_0 + i];
ian@0 736 }
ian@0 737 sernum[13] = '\0';
ian@0 738
ian@0 739 checksum = 0;
ian@0 740 for (i=0 ; i<13 ; i++) {
ian@0 741 checksum += sernum[i] ^ key[i];
ian@0 742 }
ian@0 743 checksum = ((checksum & 0x7f) ^ (0xd6)) & 0xff;
ian@0 744
ian@0 745 PRINT_PROC("Serial Number: %s", sernum);
ian@0 746 if (checksum != nvram[COBT_CMOS_SYS_SERNUM_CSUM]) {
ian@0 747 PRINT_PROC(" (invalid checksum)");
ian@0 748 }
ian@0 749 PRINT_PROC("\n");
ian@0 750
ian@0 751 PRINT_PROC("Rom Revison: %d.%d.%d\n", nvram[COBT_CMOS_ROM_REV_MAJ],
ian@0 752 nvram[COBT_CMOS_ROM_REV_MIN], nvram[COBT_CMOS_ROM_REV_REV]);
ian@0 753
ian@0 754 PRINT_PROC("BTO Server: %d.%d.%d.%d", nvram[COBT_CMOS_BTO_IP_0],
ian@0 755 nvram[COBT_CMOS_BTO_IP_1], nvram[COBT_CMOS_BTO_IP_2],
ian@0 756 nvram[COBT_CMOS_BTO_IP_3]);
ian@0 757 bto_csum = nvram[COBT_CMOS_BTO_IP_0] + nvram[COBT_CMOS_BTO_IP_1]
ian@0 758 + nvram[COBT_CMOS_BTO_IP_2] + nvram[COBT_CMOS_BTO_IP_3];
ian@0 759 if (bto_csum != nvram[COBT_CMOS_BTO_IP_CSUM]) {
ian@0 760 PRINT_PROC(" (invalid checksum)");
ian@0 761 }
ian@0 762 PRINT_PROC("\n");
ian@0 763
ian@0 764 if (flags & COBT_CMOS_VERSION_FLAG
ian@0 765 && nvram[COBT_CMOS_VERSION] >= COBT_CMOS_VER_BTOCODE) {
ian@0 766 PRINT_PROC("BTO Code: 0x%x\n",
ian@0 767 nvram[COBT_CMOS_BTO_CODE_0] << 24 |
ian@0 768 nvram[COBT_CMOS_BTO_CODE_1] << 16 |
ian@0 769 nvram[COBT_CMOS_BTO_CODE_2] << 8 |
ian@0 770 nvram[COBT_CMOS_BTO_CODE_3]);
ian@0 771 }
ian@0 772
ian@0 773 return 1;
ian@0 774 }
ian@0 775 #endif /* CONFIG_PROC_FS */
ian@0 776
ian@0 777 #endif /* MACH == COBALT */
ian@0 778
ian@0 779 #if MACH == ATARI
ian@0 780
ian@0 781 static int
ian@0 782 atari_check_checksum(void)
ian@0 783 {
ian@0 784 int i;
ian@0 785 unsigned char sum = 0;
ian@0 786
ian@0 787 for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
ian@0 788 sum += __nvram_read_byte(i);
ian@0 789 return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff) &&
ian@0 790 __nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff));
ian@0 791 }
ian@0 792
ian@0 793 static void
ian@0 794 atari_set_checksum(void)
ian@0 795 {
ian@0 796 int i;
ian@0 797 unsigned char sum = 0;
ian@0 798
ian@0 799 for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
ian@0 800 sum += __nvram_read_byte(i);
ian@0 801 __nvram_write_byte(~sum, ATARI_CKS_LOC);
ian@0 802 __nvram_write_byte(sum, ATARI_CKS_LOC + 1);
ian@0 803 }
ian@0 804
ian@0 805 #ifdef CONFIG_PROC_FS
ian@0 806
ian@0 807 static struct {
ian@0 808 unsigned char val;
ian@0 809 char *name;
ian@0 810 } boot_prefs[] = {
ian@0 811 { 0x80, "TOS" },
ian@0 812 { 0x40, "ASV" },
ian@0 813 { 0x20, "NetBSD (?)" },
ian@0 814 { 0x10, "Linux" },
ian@0 815 { 0x00, "unspecified" }
ian@0 816 };
ian@0 817
ian@0 818 static char *languages[] = {
ian@0 819 "English (US)",
ian@0 820 "German",
ian@0 821 "French",
ian@0 822 "English (UK)",
ian@0 823 "Spanish",
ian@0 824 "Italian",
ian@0 825 "6 (undefined)",
ian@0 826 "Swiss (French)",
ian@0 827 "Swiss (German)"
ian@0 828 };
ian@0 829
ian@0 830 static char *dateformat[] = {
ian@0 831 "MM%cDD%cYY",
ian@0 832 "DD%cMM%cYY",
ian@0 833 "YY%cMM%cDD",
ian@0 834 "YY%cDD%cMM",
ian@0 835 "4 (undefined)",
ian@0 836 "5 (undefined)",
ian@0 837 "6 (undefined)",
ian@0 838 "7 (undefined)"
ian@0 839 };
ian@0 840
ian@0 841 static char *colors[] = {
ian@0 842 "2", "4", "16", "256", "65536", "??", "??", "??"
ian@0 843 };
ian@0 844
ian@0 845 static int
ian@0 846 atari_proc_infos(unsigned char *nvram, char *buffer, int *len,
ian@0 847 off_t *begin, off_t offset, int size)
ian@0 848 {
ian@0 849 int checksum = nvram_check_checksum();
ian@0 850 int i;
ian@0 851 unsigned vmode;
ian@0 852
ian@0 853 PRINT_PROC("Checksum status : %svalid\n", checksum ? "" : "not ");
ian@0 854
ian@0 855 PRINT_PROC("Boot preference : ");
ian@0 856 for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) {
ian@0 857 if (nvram[1] == boot_prefs[i].val) {
ian@0 858 PRINT_PROC("%s\n", boot_prefs[i].name);
ian@0 859 break;
ian@0 860 }
ian@0 861 }
ian@0 862 if (i < 0)
ian@0 863 PRINT_PROC("0x%02x (undefined)\n", nvram[1]);
ian@0 864
ian@0 865 PRINT_PROC("SCSI arbitration : %s\n",
ian@0 866 (nvram[16] & 0x80) ? "on" : "off");
ian@0 867 PRINT_PROC("SCSI host ID : ");
ian@0 868 if (nvram[16] & 0x80)
ian@0 869 PRINT_PROC("%d\n", nvram[16] & 7);
ian@0 870 else
ian@0 871 PRINT_PROC("n/a\n");
ian@0 872
ian@0 873 /* the following entries are defined only for the Falcon */
ian@0 874 if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON)
ian@0 875 return 1;
ian@0 876
ian@0 877 PRINT_PROC("OS language : ");
ian@0 878 if (nvram[6] < ARRAY_SIZE(languages))
ian@0 879 PRINT_PROC("%s\n", languages[nvram[6]]);
ian@0 880 else
ian@0 881 PRINT_PROC("%u (undefined)\n", nvram[6]);
ian@0 882 PRINT_PROC("Keyboard language: ");
ian@0 883 if (nvram[7] < ARRAY_SIZE(languages))
ian@0 884 PRINT_PROC("%s\n", languages[nvram[7]]);
ian@0 885 else
ian@0 886 PRINT_PROC("%u (undefined)\n", nvram[7]);
ian@0 887 PRINT_PROC("Date format : ");
ian@0 888 PRINT_PROC(dateformat[nvram[8] & 7],
ian@0 889 nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/');
ian@0 890 PRINT_PROC(", %dh clock\n", nvram[8] & 16 ? 24 : 12);
ian@0 891 PRINT_PROC("Boot delay : ");
ian@0 892 if (nvram[10] == 0)
ian@0 893 PRINT_PROC("default");
ian@0 894 else
ian@0 895 PRINT_PROC("%ds%s\n", nvram[10],
ian@0 896 nvram[10] < 8 ? ", no memory test" : "");
ian@0 897
ian@0 898 vmode = (nvram[14] << 8) || nvram[15];
ian@0 899 PRINT_PROC("Video mode : %s colors, %d columns, %s %s monitor\n",
ian@0 900 colors[vmode & 7],
ian@0 901 vmode & 8 ? 80 : 40,
ian@0 902 vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC");
ian@0 903 PRINT_PROC(" %soverscan, compat. mode %s%s\n",
ian@0 904 vmode & 64 ? "" : "no ",
ian@0 905 vmode & 128 ? "on" : "off",
ian@0 906 vmode & 256 ?
ian@0 907 (vmode & 16 ? ", line doubling" : ", half screen") : "");
ian@0 908
ian@0 909 return 1;
ian@0 910 }
ian@0 911 #endif
ian@0 912
ian@0 913 #endif /* MACH == ATARI */
ian@0 914
ian@0 915 MODULE_LICENSE("GPL");
ian@0 916
ian@0 917 EXPORT_SYMBOL(__nvram_read_byte);
ian@0 918 EXPORT_SYMBOL(nvram_read_byte);
ian@0 919 EXPORT_SYMBOL(__nvram_write_byte);
ian@0 920 EXPORT_SYMBOL(nvram_write_byte);
ian@0 921 EXPORT_SYMBOL(__nvram_check_checksum);
ian@0 922 EXPORT_SYMBOL(nvram_check_checksum);
ian@0 923 MODULE_ALIAS_MISCDEV(NVRAM_MINOR);