lspci currently displays anything larger than 2GB as a raw number.
I have a device with a larger BAR and wanted to see that reported as
a multiple of a GB.
I took the opportunity to rewrite this routine to make it easier to add
higher powers in the future. It's also slightly shorter, which is nice.
I also changed it to use the binary prefixes, much as I dislike them
personally.
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
static void
show_size(pciaddr_t x)
{
+ static const char suffix[][4] = { "", "KiB", "MiB", "GiB", "TiB" };
+ unsigned i;
if (!x)
return;
- printf(" [size=");
- if (x < 1024)
- printf("%d", (int) x);
- else if (x < 1048576)
- printf("%dK", (int)(x / 1024));
- else if (x < 0x80000000)
- printf("%dM", (int)(x / 1048576));
- else
- printf(PCIADDR_T_FMT, x);
- putchar(']');
+ for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) {
+ if (x < 1024)
+ break;
+ x /= 1024;
+ }
+ printf(" [size=%u%s]", (unsigned)x, suffix[i]);
}
static void