From f9aff8b22b09ca22c8958987ae3cdd6c2a37018d Mon Sep 17 00:00:00 2001
From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Date: Tue, 13 Mar 2012 19:08:10 +0900
Subject: [PATCH 3/4] Add kmem -r and -R options

By -r option, /proc/iomem is displayed.

By -R option, /proc/ioport is displayed.

Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
---
 help.c   |    2 ++
 memory.c |   25 +++++++++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/help.c b/help.c
index 23e23aa..159418e 100755
--- a/help.c
+++ b/help.c
@@ -4450,6 +4450,8 @@ char *help_kmem[] = {
 "            of name \"slab\".  If the slab argument is \"list\", then",
 "            all slab cache names and addresses are listed.",
 "        -P  declares that the following address argument is a physical address.",
+"        -r  displays iomem resources shown by /proc/iomem.",
+"        -R  displays ioport resources shown by /proc/ioport.",
 "   address  when used without any flag, the address can be a kernel virtual,",
 "            or physical address; a search is made through the symbol table,",
 "            the kmalloc() slab subsystem, the free list, the page_hash_table,",
diff --git a/memory.c b/memory.c
index a102c6b..a19e19e 100755
--- a/memory.c
+++ b/memory.c
@@ -3889,6 +3889,8 @@ get_task_mem_usage(ulong task, struct task_mem_usage *tm)
  *      -c  displays the number of pages in the page_hash_table.
  *      -C  displays all entries in the page_hash_table.
  *      -i  displays informational data shown by /proc/meminfo.
+ *      -r  displays iomem resources shown by /proc/iomem.
+ *      -R  displays ioport resources shown by /proc/ioport.
  *
  *      -P  forces address to be defined as a physical address
  * address  when used with -f, the address can be either a page pointer
@@ -3935,7 +3937,8 @@ cmd_kmem(void)
 	int i;
 	int c;
 	int sflag, Sflag, pflag, fflag, Fflag, vflag, zflag, oflag, gflag; 
-	int nflag, cflag, Cflag, iflag, lflag, Lflag, Pflag, Vflag;
+	int nflag, cflag, Cflag, iflag, lflag, Lflag, Pflag, Vflag, rflag;
+	int Rflag;
 	struct meminfo meminfo;
 	ulonglong value[MAXARGS];
 	char buf[BUFSIZE];
@@ -3945,12 +3948,12 @@ cmd_kmem(void)
 	spec_addr = 0;
         sflag =	Sflag = pflag = fflag = Fflag = Pflag = zflag = oflag = 0;
 	vflag = Cflag = cflag = iflag = nflag = lflag = Lflag = Vflag = 0;
-	gflag = 0;
+	gflag = rflag = Rflag = 0;
 	escape = FALSE;
 	BZERO(&meminfo, sizeof(struct meminfo));
 	BZERO(&value[0], sizeof(ulonglong)*MAXARGS);
 
-        while ((c = getopt(argcnt, args, "gI:sSFfpvczCinl:L:PVo")) != EOF) {
+        while ((c = getopt(argcnt, args, "gI:sSFfpvczCinl:L:PVorR")) != EOF) {
                 switch(c)
 		{
 		case 'V':
@@ -4051,6 +4054,14 @@ cmd_kmem(void)
 			gflag = 1;
 			break;
 
+		case 'r':
+			rflag = 1;
+			break;
+
+		case 'R':
+			Rflag = 1;
+			break;
+
 		default:
 			argerrs++;
 			break;
@@ -4289,9 +4300,15 @@ cmd_kmem(void)
 	if (gflag == 1)
 		dump_page_flags(0);
 
+	if (rflag == 1)
+		dump_iomem();
+
+	if (Rflag == 1)
+		dump_ioport();
+
 	if (!(sflag + Sflag + pflag + fflag + Fflag + vflag + 
 	      Vflag + zflag + oflag + cflag + Cflag + iflag + 
-	      nflag + lflag + Lflag + gflag + meminfo.calls))
+	      nflag + lflag + Lflag + gflag + rflag + Rflag + meminfo.calls))
 		cmd_usage(pc->curcmd, SYNOPSIS);
 
 }
-- 
1.7.4.4

