aboutsummaryrefslogtreecommitdiffstats
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
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>
-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] |