aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorWim Van Sebroeck <wim@iguana.be>2008-11-11 04:56:00 -0500
committerWim Van Sebroeck <wim@iguana.be>2008-11-11 04:56:00 -0500
commit8587b33f4adee4e7614ea7f443346c3b6bb5427a (patch)
treeca1cdeb73e1f94a21f3171b76b788661e9275db4 /drivers/char
parent971ddcf8ad3aa88e0daee6799925858e9f820cb4 (diff)
[PATCH] nvram - convert PRINT_PROC to seq_file
Convert the /proc/drivers/nvram file from the old PRINT_PROC macro to the new seq_file filesystem. Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/nvram.c160
1 files changed, 82 insertions, 78 deletions
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 1a04f3df91ed..88cee4099be9 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -32,9 +32,10 @@
32 * added changelog 32 * added changelog
33 * 1.2 Erik Gilling: Cobalt Networks support 33 * 1.2 Erik Gilling: Cobalt Networks support
34 * Tim Hockin: general cleanup, Cobalt support 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#include <linux/module.h> 40#include <linux/module.h>
40#include <linux/smp_lock.h> 41#include <linux/smp_lock.h>
@@ -106,6 +107,7 @@
106#include <linux/mc146818rtc.h> 107#include <linux/mc146818rtc.h>
107#include <linux/init.h> 108#include <linux/init.h>
108#include <linux/proc_fs.h> 109#include <linux/proc_fs.h>
110#include <linux/seq_file.h>
109#include <linux/spinlock.h> 111#include <linux/spinlock.h>
110#include <linux/io.h> 112#include <linux/io.h>
111#include <linux/uaccess.h> 113#include <linux/uaccess.h>
@@ -122,8 +124,8 @@ static int mach_check_checksum(void);
122static void mach_set_checksum(void); 124static void mach_set_checksum(void);
123 125
124#ifdef CONFIG_PROC_FS 126#ifdef CONFIG_PROC_FS
125static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, 127static void mach_proc_infos(unsigned char *contents, struct seq_file *seq,
126 off_t *begin, off_t offset, int size); 128 void *offset);
127#endif 129#endif
128 130
129/* 131/*
@@ -370,46 +372,47 @@ static int nvram_release(struct inode *inode, struct file *file)
370} 372}
371 373
372#ifndef CONFIG_PROC_FS 374#ifndef CONFIG_PROC_FS
373static int nvram_read_proc(char *buffer, char **start, off_t offset, 375static int nvram_add_proc_fs(void)
374 int size, int *eof, void *data)
375{ 376{
376 return 0; 377 return 0;
377} 378}
379
378#else 380#else
379 381
380static int nvram_read_proc(char *buffer, char **start, off_t offset, 382static int nvram_proc_read(struct seq_file *seq, void *offset)
381 int size, int *eof, void *data)
382{ 383{
383 unsigned char contents[NVRAM_BYTES]; 384 unsigned char contents[NVRAM_BYTES];
384 int i, len = 0; 385 int i = 0;
385 off_t begin = 0;
386 386
387 spin_lock_irq(&rtc_lock); 387 spin_lock_irq(&rtc_lock);
388 for (i = 0; i < NVRAM_BYTES; ++i) 388 for (i = 0; i < NVRAM_BYTES; ++i)
389 contents[i] = __nvram_read_byte(i); 389 contents[i] = __nvram_read_byte(i);
390 spin_unlock_irq(&rtc_lock); 390 spin_unlock_irq(&rtc_lock);
391 391
392 *eof = mach_proc_infos(contents, buffer, &len, &begin, offset, size); 392 mach_proc_infos(contents, seq, offset);
393 393
394 if (offset >= begin + len) 394 return 0;
395 return 0; 395}
396 *start = buffer + (offset - begin);
397 return (size < begin + len - offset) ? size : begin + len - offset;
398 396
397static int nvram_proc_open(struct inode *inode, struct file *file)
398{
399 return single_open(file, nvram_proc_read, NULL);
399} 400}
400 401
401/* This macro frees the machine specific function from bounds checking and 402static const struct file_operations nvram_proc_fops = {
402 * this like that... */ 403 .owner = THIS_MODULE,
403#define PRINT_PROC(fmt,args...) \ 404 .open = nvram_proc_open,
404 do { \ 405 .read = seq_read,
405 *len += sprintf(buffer + *len, fmt, ##args); \ 406 .llseek = seq_lseek,
406 if (*begin + *len > offset + size) \ 407 .release = single_release,
407 return 0; \ 408};
408 if (*begin + *len < offset) { \ 409
409 *begin += *len; \ 410static int nvram_add_proc_fs(void)
410 *len = 0; \ 411{
411 } \ 412 if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops))
412 } while (0) 413 return -ENOMEM;
414 return 0;
415}
413 416
414#endif /* CONFIG_PROC_FS */ 417#endif /* CONFIG_PROC_FS */
415 418
@@ -443,10 +446,9 @@ static int __init nvram_init(void)
443 NVRAM_MINOR); 446 NVRAM_MINOR);
444 goto out; 447 goto out;
445 } 448 }
446 if (!create_proc_read_entry("driver/nvram", 0, NULL, nvram_read_proc, 449 ret = nvram_add_proc_fs();
447 NULL)) { 450 if (ret) {
448 printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n"); 451 printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n");
449 ret = -ENOMEM;
450 goto outmisc; 452 goto outmisc;
451 } 453 }
452 ret = 0; 454 ret = 0;
@@ -511,8 +513,8 @@ static char *gfx_types[] = {
511 "monochrome", 513 "monochrome",
512}; 514};
513 515
514static int pc_proc_infos(unsigned char *nvram, char *buffer, int *len, 516static void pc_proc_infos(unsigned char *nvram, struct seq_file *seq,
515 off_t *begin, off_t offset, int size) 517 void *offset)
516{ 518{
517 int checksum; 519 int checksum;
518 int type; 520 int type;
@@ -521,56 +523,57 @@ static int pc_proc_infos(unsigned char *nvram, char *buffer, int *len,
521 checksum = __nvram_check_checksum(); 523 checksum = __nvram_check_checksum();
522 spin_unlock_irq(&rtc_lock); 524 spin_unlock_irq(&rtc_lock);
523 525
524 PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not "); 526 seq_printf(seq, "Checksum status: %svalid\n", checksum ? "" : "not ");
525 527
526 PRINT_PROC("# floppies : %d\n", 528 seq_printf(seq, "# floppies : %d\n",
527 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0); 529 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0);
528 PRINT_PROC("Floppy 0 type : "); 530 seq_printf(seq, "Floppy 0 type : ");
529 type = nvram[2] >> 4; 531 type = nvram[2] >> 4;
530 if (type < ARRAY_SIZE(floppy_types)) 532 if (type < ARRAY_SIZE(floppy_types))
531 PRINT_PROC("%s\n", floppy_types[type]); 533 seq_printf(seq, "%s\n", floppy_types[type]);
532 else 534 else
533 PRINT_PROC("%d (unknown)\n", type); 535 seq_printf(seq, "%d (unknown)\n", type);
534 PRINT_PROC("Floppy 1 type : "); 536 seq_printf(seq, "Floppy 1 type : ");
535 type = nvram[2] & 0x0f; 537 type = nvram[2] & 0x0f;
536 if (type < ARRAY_SIZE(floppy_types)) 538 if (type < ARRAY_SIZE(floppy_types))
537 PRINT_PROC("%s\n", floppy_types[type]); 539 seq_printf(seq, "%s\n", floppy_types[type]);
538 else 540 else
539 PRINT_PROC("%d (unknown)\n", type); 541 seq_printf(seq, "%d (unknown)\n", type);
540 542
541 PRINT_PROC("HD 0 type : "); 543 seq_printf(seq, "HD 0 type : ");
542 type = nvram[4] >> 4; 544 type = nvram[4] >> 4;
543 if (type) 545 if (type)
544 PRINT_PROC("%02x\n", type == 0x0f ? nvram[11] : type); 546 seq_printf(seq, "%02x\n", type == 0x0f ? nvram[11] : type);
545 else 547 else
546 PRINT_PROC("none\n"); 548 seq_printf(seq, "none\n");
547 549
548 PRINT_PROC("HD 1 type : "); 550 seq_printf(seq, "HD 1 type : ");
549 type = nvram[4] & 0x0f; 551 type = nvram[4] & 0x0f;
550 if (type) 552 if (type)
551 PRINT_PROC("%02x\n", type == 0x0f ? nvram[12] : type); 553 seq_printf(seq, "%02x\n", type == 0x0f ? nvram[12] : type);
552 else 554 else
553 PRINT_PROC("none\n"); 555 seq_printf(seq, "none\n");
554 556
555 PRINT_PROC("HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 557 seq_printf(seq, "HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
556 nvram[18] | (nvram[19] << 8), 558 nvram[18] | (nvram[19] << 8),
557 nvram[20], nvram[25], 559 nvram[20], nvram[25],
558 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8)); 560 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8));
559 PRINT_PROC("HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 561 seq_printf(seq, "HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
560 nvram[39] | (nvram[40] << 8), 562 nvram[39] | (nvram[40] << 8),
561 nvram[41], nvram[46], 563 nvram[41], nvram[46],
562 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8)); 564 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8));
563 565
564 PRINT_PROC("DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); 566 seq_printf(seq, "DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8));
565 PRINT_PROC("Extended memory: %d kB (configured), %d kB (tested)\n", 567 seq_printf(seq, "Extended memory: %d kB (configured), %d kB (tested)\n",
566 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8)); 568 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8));
567 569
568 PRINT_PROC("Gfx adapter : %s\n", gfx_types[(nvram[6] >> 4) & 3]); 570 seq_printf(seq, "Gfx adapter : %s\n",
571 gfx_types[(nvram[6] >> 4) & 3]);
569 572
570 PRINT_PROC("FPU : %sinstalled\n", 573 seq_printf(seq, "FPU : %sinstalled\n",
571 (nvram[6] & 2) ? "" : "not "); 574 (nvram[6] & 2) ? "" : "not ");
572 575
573 return 1; 576 return;
574} 577}
575#endif 578#endif
576 579
@@ -640,70 +643,71 @@ static char *colors[] = {
640 "2", "4", "16", "256", "65536", "??", "??", "??" 643 "2", "4", "16", "256", "65536", "??", "??", "??"
641}; 644};
642 645
643static int atari_proc_infos(unsigned char *nvram, char *buffer, int *len, 646static void atari_proc_infos(unsigned char *nvram, struct seq_file *seq,
644 off_t *begin, off_t offset, int size) 647 void *offset)
645{ 648{
646 int checksum = nvram_check_checksum(); 649 int checksum = nvram_check_checksum();
647 int i; 650 int i;
648 unsigned vmode; 651 unsigned vmode;
649 652
650 PRINT_PROC("Checksum status : %svalid\n", checksum ? "" : "not "); 653 seq_printf(seq, "Checksum status : %svalid\n", checksum ? "" : "not ");
651 654
652 PRINT_PROC("Boot preference : "); 655 seq_printf(seq, "Boot preference : ");
653 for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) { 656 for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) {
654 if (nvram[1] == boot_prefs[i].val) { 657 if (nvram[1] == boot_prefs[i].val) {
655 PRINT_PROC("%s\n", boot_prefs[i].name); 658 seq_printf(seq, "%s\n", boot_prefs[i].name);
656 break; 659 break;
657 } 660 }
658 } 661 }
659 if (i < 0) 662 if (i < 0)
660 PRINT_PROC("0x%02x (undefined)\n", nvram[1]); 663 seq_printf(seq, "0x%02x (undefined)\n", nvram[1]);
661 664
662 PRINT_PROC("SCSI arbitration : %s\n", 665 seq_printf(seq, "SCSI arbitration : %s\n",
663 (nvram[16] & 0x80) ? "on" : "off"); 666 (nvram[16] & 0x80) ? "on" : "off");
664 PRINT_PROC("SCSI host ID : "); 667 seq_printf(seq, "SCSI host ID : ");
665 if (nvram[16] & 0x80) 668 if (nvram[16] & 0x80)
666 PRINT_PROC("%d\n", nvram[16] & 7); 669 seq_printf(seq, "%d\n", nvram[16] & 7);
667 else 670 else
668 PRINT_PROC("n/a\n"); 671 seq_printf(seq, "n/a\n");
669 672
670 /* the following entries are defined only for the Falcon */ 673 /* the following entries are defined only for the Falcon */
671 if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON) 674 if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON)
672 return 1; 675 return;
673 676
674 PRINT_PROC("OS language : "); 677 seq_printf(seq, "OS language : ");
675 if (nvram[6] < ARRAY_SIZE(languages)) 678 if (nvram[6] < ARRAY_SIZE(languages))
676 PRINT_PROC("%s\n", languages[nvram[6]]); 679 seq_printf(seq, "%s\n", languages[nvram[6]]);
677 else 680 else
678 PRINT_PROC("%u (undefined)\n", nvram[6]); 681 seq_printf(seq, "%u (undefined)\n", nvram[6]);
679 PRINT_PROC("Keyboard language: "); 682 seq_printf(seq, "Keyboard language: ");
680 if (nvram[7] < ARRAY_SIZE(languages)) 683 if (nvram[7] < ARRAY_SIZE(languages))
681 PRINT_PROC("%s\n", languages[nvram[7]]); 684 seq_printf(seq, "%s\n", languages[nvram[7]]);
682 else 685 else
683 PRINT_PROC("%u (undefined)\n", nvram[7]); 686 seq_printf(seq, "%u (undefined)\n", nvram[7]);
684 PRINT_PROC("Date format : "); 687 seq_printf(seq, "Date format : ");
685 PRINT_PROC(dateformat[nvram[8] & 7], 688 seq_printf(seq, dateformat[nvram[8] & 7],
686 nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/'); 689 nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/');
687 PRINT_PROC(", %dh clock\n", nvram[8] & 16 ? 24 : 12); 690 seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12);
688 PRINT_PROC("Boot delay : "); 691 seq_printf(seq, "Boot delay : ");
689 if (nvram[10] == 0) 692 if (nvram[10] == 0)
690 PRINT_PROC("default"); 693 seq_printf(seq, "default");
691 else 694 else
692 PRINT_PROC("%ds%s\n", nvram[10], 695 seq_printf(seq, "%ds%s\n", nvram[10],
693 nvram[10] < 8 ? ", no memory test" : ""); 696 nvram[10] < 8 ? ", no memory test" : "");
694 697
695 vmode = (nvram[14] << 8) || nvram[15]; 698 vmode = (nvram[14] << 8) || nvram[15];
696 PRINT_PROC("Video mode : %s colors, %d columns, %s %s monitor\n", 699 seq_printf(seq,
700 "Video mode : %s colors, %d columns, %s %s monitor\n",
697 colors[vmode & 7], 701 colors[vmode & 7],
698 vmode & 8 ? 80 : 40, 702 vmode & 8 ? 80 : 40,
699 vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC"); 703 vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC");
700 PRINT_PROC(" %soverscan, compat. mode %s%s\n", 704 seq_printf(seq, " %soverscan, compat. mode %s%s\n",
701 vmode & 64 ? "" : "no ", 705 vmode & 64 ? "" : "no ",
702 vmode & 128 ? "on" : "off", 706 vmode & 128 ? "on" : "off",
703 vmode & 256 ? 707 vmode & 256 ?
704 (vmode & 16 ? ", line doubling" : ", half screen") : ""); 708 (vmode & 16 ? ", line doubling" : ", half screen") : "");
705 709
706 return 1; 710 return;
707} 711}
708#endif 712#endif
709 713