Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.kernel.org/pub/scm/linux/kernel/git/wim/linux-2.6-nvram

* git://git.kernel.org/pub/scm/linux/kernel/git/wim/linux-2.6-nvram:
[PATCH] nvram - convert PRINT_PROC to seq_file
[PATCH] nvram - CodingStyle

+124 -142
+124 -142
drivers/char/nvram.c
··· 32 32 * added changelog 33 33 * 1.2 Erik Gilling: Cobalt Networks support 34 34 * Tim Hockin: general cleanup, Cobalt support 35 + * 1.3 Wim Van Sebroeck: convert PRINT_PROC to seq_file 35 36 */ 36 37 37 - #define NVRAM_VERSION "1.2" 38 + #define NVRAM_VERSION "1.3" 38 39 39 40 #include <linux/module.h> 40 41 #include <linux/smp_lock.h> ··· 47 46 /* select machine configuration */ 48 47 #if defined(CONFIG_ATARI) 49 48 # define MACH ATARI 50 - #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and others?? */ 49 + #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and ?? */ 51 50 # define MACH PC 52 51 #else 53 52 # error Cannot build nvram driver for this machine configuration. ··· 107 106 #include <linux/mc146818rtc.h> 108 107 #include <linux/init.h> 109 108 #include <linux/proc_fs.h> 109 + #include <linux/seq_file.h> 110 110 #include <linux/spinlock.h> 111 + #include <linux/io.h> 112 + #include <linux/uaccess.h> 111 113 112 - #include <asm/io.h> 113 - #include <asm/uaccess.h> 114 114 #include <asm/system.h> 115 115 116 116 static DEFINE_SPINLOCK(nvram_state_lock); ··· 124 122 static void mach_set_checksum(void); 125 123 126 124 #ifdef CONFIG_PROC_FS 127 - static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, 128 - off_t *begin, off_t offset, int size); 125 + static void mach_proc_infos(unsigned char *contents, struct seq_file *seq, 126 + void *offset); 129 127 #endif 130 128 131 129 /* ··· 135 133 * 136 134 * It is worth noting that these functions all access bytes of general 137 135 * purpose memory in the NVRAM - that is to say, they all add the 138 - * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not 136 + * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not 139 137 * know about the RTC cruft. 140 138 */ 141 139 142 - unsigned char 143 - __nvram_read_byte(int i) 140 + unsigned char __nvram_read_byte(int i) 144 141 { 145 142 return CMOS_READ(NVRAM_FIRST_BYTE + i); 146 143 } 144 + EXPORT_SYMBOL(__nvram_read_byte); 147 145 148 - unsigned char 149 - nvram_read_byte(int i) 146 + unsigned char nvram_read_byte(int i) 150 147 { 151 148 unsigned long flags; 152 149 unsigned char c; ··· 155 154 spin_unlock_irqrestore(&rtc_lock, flags); 156 155 return c; 157 156 } 157 + EXPORT_SYMBOL(nvram_read_byte); 158 158 159 159 /* This races nicely with trying to read with checksum checking (nvram_read) */ 160 - void 161 - __nvram_write_byte(unsigned char c, int i) 160 + void __nvram_write_byte(unsigned char c, int i) 162 161 { 163 162 CMOS_WRITE(c, NVRAM_FIRST_BYTE + i); 164 163 } 164 + EXPORT_SYMBOL(__nvram_write_byte); 165 165 166 - void 167 - nvram_write_byte(unsigned char c, int i) 166 + void nvram_write_byte(unsigned char c, int i) 168 167 { 169 168 unsigned long flags; 170 169 ··· 172 171 __nvram_write_byte(c, i); 173 172 spin_unlock_irqrestore(&rtc_lock, flags); 174 173 } 174 + EXPORT_SYMBOL(nvram_write_byte); 175 175 176 - int 177 - __nvram_check_checksum(void) 176 + int __nvram_check_checksum(void) 178 177 { 179 178 return mach_check_checksum(); 180 179 } 180 + EXPORT_SYMBOL(__nvram_check_checksum); 181 181 182 - int 183 - nvram_check_checksum(void) 182 + int nvram_check_checksum(void) 184 183 { 185 184 unsigned long flags; 186 185 int rv; ··· 190 189 spin_unlock_irqrestore(&rtc_lock, flags); 191 190 return rv; 192 191 } 192 + EXPORT_SYMBOL(nvram_check_checksum); 193 193 194 - static void 195 - __nvram_set_checksum(void) 194 + static void __nvram_set_checksum(void) 196 195 { 197 196 mach_set_checksum(); 198 197 } 199 198 200 199 #if 0 201 - void 202 - nvram_set_checksum(void) 200 + void nvram_set_checksum(void) 203 201 { 204 202 unsigned long flags; 205 203 ··· 212 212 * The are the file operation function for user access to /dev/nvram 213 213 */ 214 214 215 - static loff_t nvram_llseek(struct file *file,loff_t offset, int origin ) 215 + static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 216 216 { 217 217 lock_kernel(); 218 218 switch (origin) { ··· 230 230 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL; 231 231 } 232 232 233 - static ssize_t 234 - nvram_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 233 + static ssize_t nvram_read(struct file *file, char __user *buf, 234 + size_t count, loff_t *ppos) 235 235 { 236 236 unsigned char contents[NVRAM_BYTES]; 237 237 unsigned i = *ppos; ··· 254 254 255 255 return tmp - contents; 256 256 257 - checksum_err: 257 + checksum_err: 258 258 spin_unlock_irq(&rtc_lock); 259 259 return -EIO; 260 260 } 261 261 262 - static ssize_t 263 - nvram_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 262 + static ssize_t nvram_write(struct file *file, const char __user *buf, 263 + size_t count, loff_t *ppos) 264 264 { 265 265 unsigned char contents[NVRAM_BYTES]; 266 266 unsigned i = *ppos; ··· 287 287 288 288 return tmp - contents; 289 289 290 - checksum_err: 290 + checksum_err: 291 291 spin_unlock_irq(&rtc_lock); 292 292 return -EIO; 293 293 } 294 294 295 - static int 296 - nvram_ioctl(struct inode *inode, struct file *file, 297 - unsigned int cmd, unsigned long arg) 295 + static int nvram_ioctl(struct inode *inode, struct file *file, 296 + unsigned int cmd, unsigned long arg) 298 297 { 299 298 int i; 300 299 ··· 314 315 return 0; 315 316 316 317 case NVRAM_SETCKS: 317 - /* just set checksum, contents unchanged (maybe useful after 318 + /* just set checksum, contents unchanged (maybe useful after 318 319 * checksum garbaged somehow...) */ 319 320 if (!capable(CAP_SYS_ADMIN)) 320 321 return -EACCES; ··· 329 330 } 330 331 } 331 332 332 - static int 333 - nvram_open(struct inode *inode, struct file *file) 333 + static int nvram_open(struct inode *inode, struct file *file) 334 334 { 335 335 lock_kernel(); 336 336 spin_lock(&nvram_state_lock); ··· 354 356 return 0; 355 357 } 356 358 357 - static int 358 - nvram_release(struct inode *inode, struct file *file) 359 + static int nvram_release(struct inode *inode, struct file *file) 359 360 { 360 361 spin_lock(&nvram_state_lock); 361 362 ··· 372 375 } 373 376 374 377 #ifndef CONFIG_PROC_FS 375 - static int 376 - nvram_read_proc(char *buffer, char **start, off_t offset, 377 - int size, int *eof, void *data) 378 + static int nvram_add_proc_fs(void) 378 379 { 379 380 return 0; 380 381 } 382 + 381 383 #else 382 384 383 - static int 384 - nvram_read_proc(char *buffer, char **start, off_t offset, 385 - int size, int *eof, void *data) 385 + static int nvram_proc_read(struct seq_file *seq, void *offset) 386 386 { 387 387 unsigned char contents[NVRAM_BYTES]; 388 - int i, len = 0; 389 - off_t begin = 0; 388 + int i = 0; 390 389 391 390 spin_lock_irq(&rtc_lock); 392 391 for (i = 0; i < NVRAM_BYTES; ++i) 393 392 contents[i] = __nvram_read_byte(i); 394 393 spin_unlock_irq(&rtc_lock); 395 394 396 - *eof = mach_proc_infos(contents, buffer, &len, &begin, offset, size); 395 + mach_proc_infos(contents, seq, offset); 397 396 398 - if (offset >= begin + len) 399 - return 0; 400 - *start = buffer + (offset - begin); 401 - return (size < begin + len - offset) ? size : begin + len - offset; 402 - 397 + return 0; 403 398 } 404 399 405 - /* This macro frees the machine specific function from bounds checking and 406 - * this like that... */ 407 - #define PRINT_PROC(fmt,args...) \ 408 - do { \ 409 - *len += sprintf(buffer+*len, fmt, ##args); \ 410 - if (*begin + *len > offset + size) \ 411 - return 0; \ 412 - if (*begin + *len < offset) { \ 413 - *begin += *len; \ 414 - *len = 0; \ 415 - } \ 416 - } while(0) 400 + static int nvram_proc_open(struct inode *inode, struct file *file) 401 + { 402 + return single_open(file, nvram_proc_read, NULL); 403 + } 404 + 405 + static const struct file_operations nvram_proc_fops = { 406 + .owner = THIS_MODULE, 407 + .open = nvram_proc_open, 408 + .read = seq_read, 409 + .llseek = seq_lseek, 410 + .release = single_release, 411 + }; 412 + 413 + static int nvram_add_proc_fs(void) 414 + { 415 + if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops)) 416 + return -ENOMEM; 417 + return 0; 418 + } 417 419 418 420 #endif /* CONFIG_PROC_FS */ 419 421 ··· 432 436 &nvram_fops 433 437 }; 434 438 435 - static int __init 436 - nvram_init(void) 439 + static int __init nvram_init(void) 437 440 { 438 441 int ret; 439 442 ··· 446 451 NVRAM_MINOR); 447 452 goto out; 448 453 } 449 - if (!create_proc_read_entry("driver/nvram", 0, NULL, nvram_read_proc, 450 - NULL)) { 454 + ret = nvram_add_proc_fs(); 455 + if (ret) { 451 456 printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n"); 452 - ret = -ENOMEM; 453 457 goto outmisc; 454 458 } 455 459 ret = 0; 456 460 printk(KERN_INFO "Non-volatile memory driver v" NVRAM_VERSION "\n"); 457 - out: 461 + out: 458 462 return ret; 459 - outmisc: 463 + outmisc: 460 464 misc_deregister(&nvram_dev); 461 465 goto out; 462 466 } 463 467 464 - static void __exit 465 - nvram_cleanup_module(void) 468 + static void __exit nvram_cleanup_module(void) 466 469 { 467 470 remove_proc_entry("driver/nvram", NULL); 468 471 misc_deregister(&nvram_dev); ··· 475 482 476 483 #if MACH == PC 477 484 478 - static int 479 - pc_check_checksum(void) 485 + static int pc_check_checksum(void) 480 486 { 481 487 int i; 482 488 unsigned short sum = 0; ··· 485 493 sum += __nvram_read_byte(i); 486 494 expect = __nvram_read_byte(PC_CKS_LOC)<<8 | 487 495 __nvram_read_byte(PC_CKS_LOC+1); 488 - return ((sum & 0xffff) == expect); 496 + return (sum & 0xffff) == expect; 489 497 } 490 498 491 - static void 492 - pc_set_checksum(void) 499 + static void pc_set_checksum(void) 493 500 { 494 501 int i; 495 502 unsigned short sum = 0; ··· 513 522 "monochrome", 514 523 }; 515 524 516 - static int 517 - pc_proc_infos(unsigned char *nvram, char *buffer, int *len, 518 - off_t *begin, off_t offset, int size) 525 + static void pc_proc_infos(unsigned char *nvram, struct seq_file *seq, 526 + void *offset) 519 527 { 520 528 int checksum; 521 529 int type; ··· 523 533 checksum = __nvram_check_checksum(); 524 534 spin_unlock_irq(&rtc_lock); 525 535 526 - PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not "); 536 + seq_printf(seq, "Checksum status: %svalid\n", checksum ? "" : "not "); 527 537 528 - PRINT_PROC("# floppies : %d\n", 538 + seq_printf(seq, "# floppies : %d\n", 529 539 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0); 530 - PRINT_PROC("Floppy 0 type : "); 540 + seq_printf(seq, "Floppy 0 type : "); 531 541 type = nvram[2] >> 4; 532 542 if (type < ARRAY_SIZE(floppy_types)) 533 - PRINT_PROC("%s\n", floppy_types[type]); 543 + seq_printf(seq, "%s\n", floppy_types[type]); 534 544 else 535 - PRINT_PROC("%d (unknown)\n", type); 536 - PRINT_PROC("Floppy 1 type : "); 545 + seq_printf(seq, "%d (unknown)\n", type); 546 + seq_printf(seq, "Floppy 1 type : "); 537 547 type = nvram[2] & 0x0f; 538 548 if (type < ARRAY_SIZE(floppy_types)) 539 - PRINT_PROC("%s\n", floppy_types[type]); 549 + seq_printf(seq, "%s\n", floppy_types[type]); 540 550 else 541 - PRINT_PROC("%d (unknown)\n", type); 551 + seq_printf(seq, "%d (unknown)\n", type); 542 552 543 - PRINT_PROC("HD 0 type : "); 553 + seq_printf(seq, "HD 0 type : "); 544 554 type = nvram[4] >> 4; 545 555 if (type) 546 - PRINT_PROC("%02x\n", type == 0x0f ? nvram[11] : type); 556 + seq_printf(seq, "%02x\n", type == 0x0f ? nvram[11] : type); 547 557 else 548 - PRINT_PROC("none\n"); 558 + seq_printf(seq, "none\n"); 549 559 550 - PRINT_PROC("HD 1 type : "); 560 + seq_printf(seq, "HD 1 type : "); 551 561 type = nvram[4] & 0x0f; 552 562 if (type) 553 - PRINT_PROC("%02x\n", type == 0x0f ? nvram[12] : type); 563 + seq_printf(seq, "%02x\n", type == 0x0f ? nvram[12] : type); 554 564 else 555 - PRINT_PROC("none\n"); 565 + seq_printf(seq, "none\n"); 556 566 557 - PRINT_PROC("HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 567 + seq_printf(seq, "HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 558 568 nvram[18] | (nvram[19] << 8), 559 569 nvram[20], nvram[25], 560 570 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8)); 561 - PRINT_PROC("HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 571 + seq_printf(seq, "HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 562 572 nvram[39] | (nvram[40] << 8), 563 573 nvram[41], nvram[46], 564 574 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8)); 565 575 566 - PRINT_PROC("DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); 567 - PRINT_PROC("Extended memory: %d kB (configured), %d kB (tested)\n", 576 + seq_printf(seq, "DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); 577 + seq_printf(seq, "Extended memory: %d kB (configured), %d kB (tested)\n", 568 578 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8)); 569 579 570 - PRINT_PROC("Gfx adapter : %s\n", gfx_types[(nvram[6] >> 4) & 3]); 580 + seq_printf(seq, "Gfx adapter : %s\n", 581 + gfx_types[(nvram[6] >> 4) & 3]); 571 582 572 - PRINT_PROC("FPU : %sinstalled\n", 583 + seq_printf(seq, "FPU : %sinstalled\n", 573 584 (nvram[6] & 2) ? "" : "not "); 574 585 575 - return 1; 586 + return; 576 587 } 577 588 #endif 578 589 ··· 581 590 582 591 #if MACH == ATARI 583 592 584 - static int 585 - atari_check_checksum(void) 593 + static int atari_check_checksum(void) 586 594 { 587 595 int i; 588 596 unsigned char sum = 0; 589 597 590 598 for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i) 591 599 sum += __nvram_read_byte(i); 592 - return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff) && 593 - __nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff)); 600 + return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff)) && 601 + (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff)); 594 602 } 595 603 596 - static void 597 - atari_set_checksum(void) 604 + static void atari_set_checksum(void) 598 605 { 599 606 int i; 600 607 unsigned char sum = 0; ··· 643 654 "2", "4", "16", "256", "65536", "??", "??", "??" 644 655 }; 645 656 646 - static int 647 - atari_proc_infos(unsigned char *nvram, char *buffer, int *len, 648 - off_t *begin, off_t offset, int size) 657 + static void atari_proc_infos(unsigned char *nvram, struct seq_file *seq, 658 + void *offset) 649 659 { 650 660 int checksum = nvram_check_checksum(); 651 661 int i; 652 662 unsigned vmode; 653 663 654 - PRINT_PROC("Checksum status : %svalid\n", checksum ? "" : "not "); 664 + seq_printf(seq, "Checksum status : %svalid\n", checksum ? "" : "not "); 655 665 656 - PRINT_PROC("Boot preference : "); 666 + seq_printf(seq, "Boot preference : "); 657 667 for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) { 658 668 if (nvram[1] == boot_prefs[i].val) { 659 - PRINT_PROC("%s\n", boot_prefs[i].name); 669 + seq_printf(seq, "%s\n", boot_prefs[i].name); 660 670 break; 661 671 } 662 672 } 663 673 if (i < 0) 664 - PRINT_PROC("0x%02x (undefined)\n", nvram[1]); 674 + seq_printf(seq, "0x%02x (undefined)\n", nvram[1]); 665 675 666 - PRINT_PROC("SCSI arbitration : %s\n", 676 + seq_printf(seq, "SCSI arbitration : %s\n", 667 677 (nvram[16] & 0x80) ? "on" : "off"); 668 - PRINT_PROC("SCSI host ID : "); 678 + seq_printf(seq, "SCSI host ID : "); 669 679 if (nvram[16] & 0x80) 670 - PRINT_PROC("%d\n", nvram[16] & 7); 680 + seq_printf(seq, "%d\n", nvram[16] & 7); 671 681 else 672 - PRINT_PROC("n/a\n"); 682 + seq_printf(seq, "n/a\n"); 673 683 674 684 /* the following entries are defined only for the Falcon */ 675 685 if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON) 676 - return 1; 686 + return; 677 687 678 - PRINT_PROC("OS language : "); 688 + seq_printf(seq, "OS language : "); 679 689 if (nvram[6] < ARRAY_SIZE(languages)) 680 - PRINT_PROC("%s\n", languages[nvram[6]]); 690 + seq_printf(seq, "%s\n", languages[nvram[6]]); 681 691 else 682 - PRINT_PROC("%u (undefined)\n", nvram[6]); 683 - PRINT_PROC("Keyboard language: "); 692 + seq_printf(seq, "%u (undefined)\n", nvram[6]); 693 + seq_printf(seq, "Keyboard language: "); 684 694 if (nvram[7] < ARRAY_SIZE(languages)) 685 - PRINT_PROC("%s\n", languages[nvram[7]]); 695 + seq_printf(seq, "%s\n", languages[nvram[7]]); 686 696 else 687 - PRINT_PROC("%u (undefined)\n", nvram[7]); 688 - PRINT_PROC("Date format : "); 689 - PRINT_PROC(dateformat[nvram[8] & 7], 697 + seq_printf(seq, "%u (undefined)\n", nvram[7]); 698 + seq_printf(seq, "Date format : "); 699 + seq_printf(seq, dateformat[nvram[8] & 7], 690 700 nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/'); 691 - PRINT_PROC(", %dh clock\n", nvram[8] & 16 ? 24 : 12); 692 - PRINT_PROC("Boot delay : "); 701 + seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12); 702 + seq_printf(seq, "Boot delay : "); 693 703 if (nvram[10] == 0) 694 - PRINT_PROC("default"); 704 + seq_printf(seq, "default"); 695 705 else 696 - PRINT_PROC("%ds%s\n", nvram[10], 706 + seq_printf(seq, "%ds%s\n", nvram[10], 697 707 nvram[10] < 8 ? ", no memory test" : ""); 698 708 699 709 vmode = (nvram[14] << 8) || nvram[15]; 700 - PRINT_PROC("Video mode : %s colors, %d columns, %s %s monitor\n", 710 + seq_printf(seq, 711 + "Video mode : %s colors, %d columns, %s %s monitor\n", 701 712 colors[vmode & 7], 702 713 vmode & 8 ? 80 : 40, 703 714 vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC"); 704 - PRINT_PROC(" %soverscan, compat. mode %s%s\n", 715 + seq_printf(seq, " %soverscan, compat. mode %s%s\n", 705 716 vmode & 64 ? "" : "no ", 706 717 vmode & 128 ? "on" : "off", 707 718 vmode & 256 ? 708 719 (vmode & 16 ? ", line doubling" : ", half screen") : ""); 709 720 710 - return 1; 721 + return; 711 722 } 712 723 #endif 713 724 714 725 #endif /* MACH == ATARI */ 715 726 716 727 MODULE_LICENSE("GPL"); 717 - 718 - EXPORT_SYMBOL(__nvram_read_byte); 719 - EXPORT_SYMBOL(nvram_read_byte); 720 - EXPORT_SYMBOL(__nvram_write_byte); 721 - EXPORT_SYMBOL(nvram_write_byte); 722 - EXPORT_SYMBOL(__nvram_check_checksum); 723 - EXPORT_SYMBOL(nvram_check_checksum); 724 728 MODULE_ALIAS_MISCDEV(NVRAM_MINOR);