diff options
| author | Randy Dunlap <randy.dunlap@verizon.net> | 2003-02-23 18:49:30 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@home.transmeta.com> | 2003-02-23 18:49:30 -0800 |
| commit | 1f7859402b9fb3a5cf3445266beba3fad63ede26 (patch) | |
| tree | ba58114f9719e4f9ddfbd5ac5916f6d647f4ecba /kernel | |
| parent | b096c3f53d303daec0d88dade64377e373d8d104 (diff) | |
[PATCH] convert /proc/io{mem,ports} to seq_file
This converts /proc/io{mem,ports} to the seq_file interface
(single_open).
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/resource.c | 114 |
1 files changed, 89 insertions, 25 deletions
diff --git a/kernel/resource.c b/kernel/resource.c index 83d04826245d..ca82abf27fc9 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -7,61 +7,125 @@ * Arbitrary resource management. */ +#include <linux/config.h> #include <linux/sched.h> #include <linux/errno.h> #include <linux/ioport.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/fs.h> +#include <linux/proc_fs.h> +#include <linux/seq_file.h> #include <asm/io.h> + struct resource ioport_resource = { "PCI IO", 0x0000, IO_SPACE_LIMIT, IORESOURCE_IO }; struct resource iomem_resource = { "PCI mem", 0x00000000, 0xffffffff, IORESOURCE_MEM }; static rwlock_t resource_lock = RW_LOCK_UNLOCKED; +#ifdef CONFIG_PROC_FS + +#define MAX_IORES_LEVEL 5 + /* - * This generates reports for /proc/ioports and /proc/iomem + * do_resource_list(): + * for reports of /proc/ioports and /proc/iomem; + * do current entry, then children, then siblings; */ -static char * do_resource_list(struct resource *entry, const char *fmt, int offset, char *buf, char *end) +static int do_resource_list(struct seq_file *m, struct resource *res, const char *fmt, int level) { - if (offset < 0) - offset = 0; + while (res) { + const char *name; - while (entry) { - const char *name = entry->name; - unsigned long from, to; + name = res->name ? res->name : "<BAD>"; + if (level > MAX_IORES_LEVEL) + level = MAX_IORES_LEVEL; + seq_printf (m, fmt + 2 * MAX_IORES_LEVEL - 2 * level, + res->start, res->end, name); - if ((int) (end-buf) < 80) - return buf; + if (res->child) + do_resource_list(m, res->child, fmt, level + 1); - from = entry->start; - to = entry->end; - if (!name) - name = "<BAD>"; - - buf += sprintf(buf, fmt + offset, from, to, name); - if (entry->child) - buf = do_resource_list(entry->child, fmt, offset-2, buf, end); - entry = entry->sibling; + res = res->sibling; } - return buf; + return 0; } -int get_resource_list(struct resource *root, char *buf, int size) +static int ioresources_show(struct seq_file *m, void *v) { + struct resource *root = m->private; char *fmt; int retval; - fmt = " %08lx-%08lx : %s\n"; - if (root->end < 0x10000) - fmt = " %04lx-%04lx : %s\n"; + fmt = root->end < 0x10000 + ? " %04lx-%04lx : %s\n" + : " %08lx-%08lx : %s\n"; read_lock(&resource_lock); - retval = do_resource_list(root->child, fmt, 8, buf, buf + size) - buf; + retval = do_resource_list(m, root->child, fmt, 0); read_unlock(&resource_lock); return retval; -} +} + +static int ioresources_open(struct file *file, struct resource *root) +{ + char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); + struct seq_file *m; + int res; + + if (!buf) + return -ENOMEM; + res = single_open(file, ioresources_show, root); + if (!res) { + m = file->private_data; + m->buf = buf; + m->size = PAGE_SIZE; + } else + kfree(buf); + return res; +} + +static int ioports_open(struct inode *inode, struct file *file) +{ + return ioresources_open(file, &ioport_resource); +} + +static struct file_operations proc_ioports_operations = { + .open = ioports_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int iomem_open(struct inode *inode, struct file *file) +{ + return ioresources_open(file, &iomem_resource); +} + +static struct file_operations proc_iomem_operations = { + .open = iomem_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int __init ioresources_init(void) +{ + struct proc_dir_entry *entry; + + entry = create_proc_entry("ioports", 0, NULL); + if (entry) + entry->proc_fops = &proc_ioports_operations; + entry = create_proc_entry("iomem", 0, NULL); + if (entry) + entry->proc_fops = &proc_iomem_operations; + return 0; +} +__initcall(ioresources_init); + +#endif /* CONFIG_PROC_FS */ /* Return the conflict entry if you can't request it */ static struct resource * __request_resource(struct resource *root, struct resource *new) |
