vsprintf: Add support for IORESOURCE_UNSET in %pR
authorBjorn Helgaas <bhelgaas@google.com>
Wed, 26 Feb 2014 18:25:56 +0000 (11:25 -0700)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 26 Feb 2014 21:42:09 +0000 (14:42 -0700)
Sometimes we have a struct resource where we know the type (MEM/IO/etc.)
and the size, but we haven't assigned address space for it.  The
IORESOURCE_UNSET flag is a way to indicate this situation.  For these
"unset" resources, the start address is meaningless, so print only the
size, e.g.,

  - pci 0000:0c:00.0: reg 184: [mem 0x00000000-0x00001fff 64bit]
  + pci 0000:0c:00.0: reg 184: [mem size 0x2000 64bit]

For %pr (printing with raw flags), we still print the address range,
because %pr is mostly used for debugging anyway.

Thanks to Fengguang Wu <fengguang.wu@intel.com> for suggesting
resource_size().

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
include/linux/ioport.h
lib/vsprintf.c

index 9fcaac8..5e3a906 100644 (file)
@@ -51,7 +51,7 @@ struct resource {
 
 #define IORESOURCE_EXCLUSIVE   0x08000000      /* Userland may not map this resource */
 #define IORESOURCE_DISABLED    0x10000000
-#define IORESOURCE_UNSET       0x20000000
+#define IORESOURCE_UNSET       0x20000000      /* No address assigned yet */
 #define IORESOURCE_AUTO                0x40000000
 #define IORESOURCE_BUSY                0x80000000      /* Driver has marked this resource busy */
 
index 185b6d3..5e2cf6f 100644 (file)
@@ -719,10 +719,15 @@ char *resource_string(char *buf, char *end, struct resource *res,
                specp = &mem_spec;
                decode = 0;
        }
-       p = number(p, pend, res->start, *specp);
-       if (res->start != res->end) {
-               *p++ = '-';
-               p = number(p, pend, res->end, *specp);
+       if (decode && res->flags & IORESOURCE_UNSET) {
+               p = string(p, pend, "size ", str_spec);
+               p = number(p, pend, resource_size(res), *specp);
+       } else {
+               p = number(p, pend, res->start, *specp);
+               if (res->start != res->end) {
+                       *p++ = '-';
+                       p = number(p, pend, res->end, *specp);
+               }
        }
        if (decode) {
                if (res->flags & IORESOURCE_MEM_64)