diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2009-10-06 17:33:39 -0400 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2009-11-04 11:47:17 -0500 |
commit | fd95541e23e2c9acb1e38cd41fc0c7cc37fceb53 (patch) | |
tree | b23aae11e5649a47a08b2ae20603e377ca16f3be /lib/vsprintf.c | |
parent | c91d3376e5f4277173a22f0ef9989125c318bacb (diff) |
vsprintf: add %pRt, %pRf to print struct resource details
This adds support for printing struct resource type and flag information.
For example, "%pRt" looks like "[mem 0x80080000000-0x8008001ffff 64bit pref]",
and "%pRf" looks like "[mem 0xff5e2000-0xff5e2007 pref flags 0x1]".
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 1b60aedab44d..a6e195163eb3 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -595,7 +595,7 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
595 | } | 595 | } |
596 | 596 | ||
597 | static char *resource_string(char *buf, char *end, struct resource *res, | 597 | static char *resource_string(char *buf, char *end, struct resource *res, |
598 | struct printf_spec spec) | 598 | struct printf_spec spec, const char *fmt) |
599 | { | 599 | { |
600 | #ifndef IO_RSRC_PRINTK_SIZE | 600 | #ifndef IO_RSRC_PRINTK_SIZE |
601 | #define IO_RSRC_PRINTK_SIZE 6 | 601 | #define IO_RSRC_PRINTK_SIZE 6 |
@@ -614,9 +614,21 @@ static char *resource_string(char *buf, char *end, struct resource *res, | |||
614 | .precision = -1, | 614 | .precision = -1, |
615 | .flags = 0, | 615 | .flags = 0, |
616 | }; | 616 | }; |
617 | /* room for two actual numbers (decimal or hex), the two "0x", -, [, ] | 617 | struct printf_spec str_spec = { |
618 | * and the final zero */ | 618 | .field_width = -1, |
619 | char sym[2*3*sizeof(resource_size_t) + 8]; | 619 | .precision = 10, |
620 | .flags = LEFT, | ||
621 | }; | ||
622 | struct printf_spec flag_spec = { | ||
623 | .base = 16, | ||
624 | .precision = -1, | ||
625 | .flags = SPECIAL | SMALL, | ||
626 | }; | ||
627 | /* | ||
628 | * room for three actual numbers (decimal or hex), plus | ||
629 | * "[mem 0x-0x 64bit pref disabled flags 0x]\0" | ||
630 | */ | ||
631 | char sym[3*3*sizeof(resource_size_t) + 41]; | ||
620 | char *p = sym, *pend = sym + sizeof(sym); | 632 | char *p = sym, *pend = sym + sizeof(sym); |
621 | int size = -1, addr = 0; | 633 | int size = -1, addr = 0; |
622 | 634 | ||
@@ -629,12 +641,35 @@ static char *resource_string(char *buf, char *end, struct resource *res, | |||
629 | } | 641 | } |
630 | 642 | ||
631 | *p++ = '['; | 643 | *p++ = '['; |
644 | if (fmt[1] == 't' || fmt[1] == 'f') { | ||
645 | if (res->flags & IORESOURCE_IO) | ||
646 | p = string(p, pend, "io ", str_spec); | ||
647 | else if (res->flags & IORESOURCE_MEM) | ||
648 | p = string(p, pend, "mem ", str_spec); | ||
649 | else if (res->flags & IORESOURCE_IRQ) | ||
650 | p = string(p, pend, "irq ", str_spec); | ||
651 | else if (res->flags & IORESOURCE_DMA) | ||
652 | p = string(p, pend, "dma ", str_spec); | ||
653 | } | ||
632 | hex_spec.field_width = size; | 654 | hex_spec.field_width = size; |
633 | p = number(p, pend, res->start, addr ? hex_spec : dec_spec); | 655 | p = number(p, pend, res->start, addr ? hex_spec : dec_spec); |
634 | if (res->start != res->end) { | 656 | if (res->start != res->end) { |
635 | *p++ = '-'; | 657 | *p++ = '-'; |
636 | p = number(p, pend, res->end, addr ? hex_spec : dec_spec); | 658 | p = number(p, pend, res->end, addr ? hex_spec : dec_spec); |
637 | } | 659 | } |
660 | if (fmt[1] == 't' || fmt[1] == 'f') { | ||
661 | if (res->flags & IORESOURCE_MEM_64) | ||
662 | p = string(p, pend, " 64bit", str_spec); | ||
663 | if (res->flags & IORESOURCE_PREFETCH) | ||
664 | p = string(p, pend, " pref", str_spec); | ||
665 | if (res->flags & IORESOURCE_DISABLED) | ||
666 | p = string(p, pend, " disabled", str_spec); | ||
667 | if (fmt[1] == 'f') { | ||
668 | p = string(p, pend, " flags ", str_spec); | ||
669 | p = number(p, pend, res->flags & ~IORESOURCE_TYPE_BITS, | ||
670 | flag_spec); | ||
671 | } | ||
672 | } | ||
638 | *p++ = ']'; | 673 | *p++ = ']'; |
639 | *p = 0; | 674 | *p = 0; |
640 | 675 | ||
@@ -812,8 +847,10 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
812 | * - 'f' For simple symbolic function names without offset | 847 | * - 'f' For simple symbolic function names without offset |
813 | * - 'S' For symbolic direct pointers with offset | 848 | * - 'S' For symbolic direct pointers with offset |
814 | * - 's' For symbolic direct pointers without offset | 849 | * - 's' For symbolic direct pointers without offset |
815 | * - 'R' For a struct resource pointer, it prints the range of | 850 | * - 'R' For a struct resource pointer, print: |
816 | * addresses (not the name nor the flags) | 851 | * R address range only ([0x0-0x1f]) |
852 | * Rt type and range ([mem 0x0-0x1f 64bit pref]) | ||
853 | * Rf type, range, and flags ([mem 0x0-0x1f 64bit pref flags 0x1]) | ||
817 | * - 'M' For a 6-byte MAC address, it prints the address in the | 854 | * - 'M' For a 6-byte MAC address, it prints the address in the |
818 | * usual colon-separated hex notation | 855 | * usual colon-separated hex notation |
819 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons | 856 | * - 'm' For a 6-byte MAC address, it prints the hex address without colons |
@@ -844,7 +881,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
844 | case 'S': | 881 | case 'S': |
845 | return symbol_string(buf, end, ptr, spec, *fmt); | 882 | return symbol_string(buf, end, ptr, spec, *fmt); |
846 | case 'R': | 883 | case 'R': |
847 | return resource_string(buf, end, ptr, spec); | 884 | return resource_string(buf, end, ptr, spec, fmt); |
848 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ | 885 | case 'M': /* Colon separated: 00:01:02:03:04:05 */ |
849 | case 'm': /* Contiguous: 000102030405 */ | 886 | case 'm': /* Contiguous: 000102030405 */ |
850 | return mac_address_string(buf, end, ptr, spec, fmt); | 887 | return mac_address_string(buf, end, ptr, spec, fmt); |