LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] Implement %pR to print struct resource content
@ 2008-10-20  4:07 Benjamin Herrenschmidt
  2008-10-20  7:06 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2008-10-20  4:07 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: linux-kernel, David Miller, linux-pci, Ingo Molnar, yhlu.kernel,
	Andrew Morton, Jesse Barnes

From: Linus Torvalds <torvalds@linux-foundation.org>

Add a %pR option to the kernel vsnprintf that prints the range of
addresses inside a struct resource passed by pointer.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---

Padding now defaults to 4 digits for IO and 8 for MEM

 lib/vsprintf.c |   51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 7 deletions(-)

--- linux-work.orig/lib/vsprintf.c	2008-10-17 13:30:18.000000000 +1100
+++ linux-work/lib/vsprintf.c	2008-10-20 14:39:15.000000000 +1100
@@ -24,6 +24,7 @@
 #include <linux/kernel.h>
 #include <linux/kallsyms.h>
 #include <linux/uaccess.h>
+#include <linux/ioport.h>
 
 #include <asm/page.h>		/* for PAGE_SIZE */
 #include <asm/div64.h>
@@ -550,18 +551,51 @@ static char *symbol_string(char *buf, ch
 #endif
 }
 
+static char *resource_string(char *buf, char *end, struct resource *res, int field_width, int precision, int flags)
+{
+#ifndef IO_RSRC_PRINTK_SIZE
+#define IO_RSRC_PRINTK_SIZE	4
+#endif
+
+#ifndef MEM_RSRC_PRINTK_SIZE
+#define MEM_RSRC_PRINTK_SIZE	8
+#endif
+
+	/* room for the actual numbers, the two "0x", -, [, ] and the final zero */
+	char sym[4*sizeof(resource_size_t) + 8];
+	char *p = sym, *pend = sym + sizeof(sym);
+	int size = -1;
+
+	if (res->flags & IORESOURCE_IO)
+		size = IO_RSRC_PRINTK_SIZE;
+	else if (res->flags & IORESOURCE_MEM)
+		size = MEM_RSRC_PRINTK_SIZE;
+
+	*p++ = '[';
+	p = number(p, pend, res->start, 16, size, -1, SPECIAL | SMALL | ZEROPAD);
+	*p++ = '-';
+	p = number(p, pend, res->end, 16, size, -1, SPECIAL | SMALL | ZEROPAD);
+	*p++ = ']';
+	*p = 0;
+
+	return string(buf, end, sym, field_width, precision, flags);
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
  * specifiers.
  *
- * Right now we just handle 'F' (for symbolic Function descriptor pointers)
- * and 'S' (for Symbolic direct pointers), but this can easily be
- * extended in the future (network address types etc).
- *
- * The difference between 'S' and 'F' is that on ia64 and ppc64 function
- * pointers are really function descriptors, which contain a pointer the
- * real address. 
+ * Right now we handle:
+ *
+ * - 'F' For symbolic function descriptor pointers
+ * - 'S' For symbolic direct pointers
+ * - 'R' For a struct resource pointer, it prints the range of
+ *       addresses (not the name nor the flags)
+ *
+ * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
+ * function pointers are really function descriptors, which contain a
+ * pointer to the real address.
  */
 static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field_width, int precision, int flags)
 {
@@ -571,6 +605,8 @@ static char *pointer(const char *fmt, ch
 		/* Fallthrough */
 	case 'S':
 		return symbol_string(buf, end, ptr, field_width, precision, flags);
+	case 'R':
+		return resource_string(buf, end, ptr, field_width, precision, flags);
 	}
 	flags |= SMALL;
 	if (field_width == -1) {
@@ -590,6 +626,7 @@ static char *pointer(const char *fmt, ch
  * This function follows C99 vsnprintf, but has some extensions:
  * %pS output the name of a text symbol
  * %pF output the name of a function pointer
+ * %pR output the address range in a struct resource
  *
  * The return value is the number of characters which would
  * be generated for the given input, excluding the trailing

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

* Re: [PATCH 1/2] Implement %pR to print struct resource content
  2008-10-20  4:07 [PATCH 1/2] Implement %pR to print struct resource content Benjamin Herrenschmidt
@ 2008-10-20  7:06 ` Ingo Molnar
  2008-10-20  8:33   ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2008-10-20  7:06 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Linus Torvalds, linux-kernel, David Miller, linux-pci,
	yhlu.kernel, Andrew Morton, Jesse Barnes


* Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:

> + * - 'R' For a struct resource pointer, it prints the range of
> + *       addresses (not the name nor the flags)

> +	case 'R':
> +		return resource_string(buf, end, ptr, field_width, precision, flags);

small dtail: could you please also add the information that this is 
about the kernel-special resource_size_t integer type? That type is used 
more widely than just struct resource.

	Ingo

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

* Re: [PATCH 1/2] Implement %pR to print struct resource content
  2008-10-20  7:06 ` Ingo Molnar
@ 2008-10-20  8:33   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2008-10-20  8:33 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Linus Torvalds, linux-kernel, David Miller, linux-pci,
	yhlu.kernel, Andrew Morton, Jesse Barnes

On Mon, 2008-10-20 at 09:06 +0200, Ingo Molnar wrote:
> 
> > + * - 'R' For a struct resource pointer, it prints the range of
> > + *       addresses (not the name nor the flags)
> 
> > +     case 'R':
> > +             return resource_string(buf, end, ptr, field_width, precision, flags);
> 
> small dtail: could you please also add the information that this is 
> about the kernel-special resource_size_t integer type? That type is used 
> more widely than just struct resource.
> 

I'm not sure I understand ? It's a "struct resource" pointer, which is
what I wrote :-)

Cheers,
Ben.



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

end of thread, other threads:[~2008-10-20  8:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-20  4:07 [PATCH 1/2] Implement %pR to print struct resource content Benjamin Herrenschmidt
2008-10-20  7:06 ` Ingo Molnar
2008-10-20  8:33   ` Benjamin Herrenschmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).