public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] convert /proc/io{mem,ports} to seq_file
@ 2003-02-24  6:37 Randy.Dunlap
  2003-02-24  7:42 ` Anton Blanchard
  0 siblings, 1 reply; 2+ messages in thread
From: Randy.Dunlap @ 2003-02-24  6:37 UTC (permalink / raw)
  To: torvalds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

Hi,

This patch is to Linux 2.5.62.

This converts /proc/io{mem,ports} to the seq_file interface
(single_open).

Please apply.

Thanks,
~Randy

[-- Attachment #2: seq1-iorescom-2562.patch --]
[-- Type: text/plain, Size: 6510 bytes --]

patch_name:	seq1-iorescom-2562.patch
patch_version:	2003-02-23.22:27:41
author:		Randy.Dunlap <rddunlap@osdl.org>
description:	convert /proc/io{ports,mem} to seq_file (single_open)
product:	Linux
product_versions: linux-2562
changelog:	_
URL:		_
requires:	_
conflicts:	_
diffstat:	=
 fs/proc/proc_misc.c    |   16 ------
 include/linux/ioport.h |    3 -
 kernel/resource.c      |  118 +++++++++++++++++++++++++++++++++++++------------
 3 files changed, 91 insertions(+), 46 deletions(-)


diff -Naur ./include/linux/ioport.h%SEQIO ./include/linux/ioport.h
--- ./include/linux/ioport.h%SEQIO	Mon Feb 17 14:56:00 2003
+++ ./include/linux/ioport.h	Sat Feb 22 15:31:27 2003
@@ -111,7 +111,4 @@
 extern int __deprecated __check_region(struct resource *, unsigned long, unsigned long);
 extern void __release_region(struct resource *, unsigned long, unsigned long);
 
-#define get_ioport_list(buf)	get_resource_list(&ioport_resource, buf, PAGE_SIZE)
-#define get_mem_list(buf)	get_resource_list(&iomem_resource, buf, PAGE_SIZE)
-
 #endif	/* _LINUX_IOPORT_H */
diff -Naur ./fs/proc/proc_misc.c%SEQIO ./fs/proc/proc_misc.c
--- ./fs/proc/proc_misc.c%SEQIO	Mon Feb 17 14:55:56 2003
+++ ./fs/proc/proc_misc.c	Sat Feb 22 15:31:27 2003
@@ -424,13 +424,6 @@
 	return proc_calc_metrics(page, start, off, count, eof, len);
 }
 
-static int ioports_read_proc(char *page, char **start, off_t off,
-				 int count, int *eof, void *data)
-{
-	int len = get_ioport_list(page);
-	return proc_calc_metrics(page, start, off, count, eof, len);
-}
-
 static int cmdline_read_proc(char *page, char **start, off_t off,
 				 int count, int *eof, void *data)
 {
@@ -469,13 +462,6 @@
 	return proc_calc_metrics(page, start, off, count, eof, len);
 }
 
-static int memory_read_proc(char *page, char **start, off_t off,
-				 int count, int *eof, void *data)
-{
-	int len = get_mem_list(page);
-	return proc_calc_metrics(page, start, off, count, eof, len);
-}
-
 /*
  * This function accesses profiling information. The returned data is
  * binary: the sampling step and the actual contents of the profile
@@ -569,13 +555,11 @@
 		{"stat",	kstat_read_proc},
 		{"devices",	devices_read_proc},
 		{"filesystems",	filesystems_read_proc},
-		{"ioports",	ioports_read_proc},
 		{"cmdline",	cmdline_read_proc},
 #ifdef CONFIG_SGI_DS1286
 		{"rtc",		ds1286_read_proc},
 #endif
 		{"locks",	locks_read_proc},
-		{"iomem",	memory_read_proc},
 		{"execdomains",	execdomains_read_proc},
 		{NULL,}
 	};
diff -Naur ./kernel/resource.c%SEQIO ./kernel/resource.c
--- ./kernel/resource.c%SEQIO	Mon Feb 17 14:56:22 2003
+++ ./kernel/resource.c	Sun Feb 23 22:26:00 2003
@@ -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;
-
-		if ((int) (end-buf) < 80)
-			return buf;
-
-		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;
+		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 (res->child)
+			do_resource_list(m, res->child, fmt, level + 1);
+
+		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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] convert /proc/io{mem,ports} to seq_file
  2003-02-24  6:37 [PATCH] convert /proc/io{mem,ports} to seq_file Randy.Dunlap
@ 2003-02-24  7:42 ` Anton Blanchard
  0 siblings, 0 replies; 2+ messages in thread
From: Anton Blanchard @ 2003-02-24  7:42 UTC (permalink / raw)
  To: Randy.Dunlap; +Cc: torvalds, linux-kernel


> This patch is to Linux 2.5.62.
> 
> This converts /proc/io{mem,ports} to the seq_file interface
> (single_open).

Nice work! I have some machines that are very close to overflowing a
page:

4040 iomem
4082 ioports

Anton

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-02-24  7:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-24  6:37 [PATCH] convert /proc/io{mem,ports} to seq_file Randy.Dunlap
2003-02-24  7:42 ` Anton Blanchard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox