#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <unistd.h>
#include "lspci.h"
/* Options */
int verbose; /* Show detailed information */
-static int opt_buscentric; /* Show bus addresses/IRQ's instead of CPU-visible ones */
static int opt_hex; /* Show contents of config space as hexadecimal numbers */
struct pci_filter filter; /* Device filter */
static int opt_tree; /* Show bus tree */
static void
show_size(pciaddr_t x)
{
+ static const char suffix[][2] = { "", "K", "M", "G", "T" };
+ 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
struct pci_dev *p = d->dev;
word cmd = get_conf_word(d, PCI_COMMAND);
int i;
+ int virtual = 0;
for (i=0; i<cnt; i++)
{
{
printf("[virtual] ");
flg = pos;
+ virtual = 1;
}
if (flg & PCI_BASE_ADDRESS_SPACE_IO)
{
pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;
printf("I/O ports at ");
- if (a)
+ if (a || (cmd & PCI_COMMAND_IO))
printf(PCIADDR_PORT_FMT, a);
else if (flg & PCI_BASE_ADDRESS_IO_MASK)
printf("<ignored>");
else
printf("<unassigned>");
- if (!(cmd & PCI_COMMAND_IO))
+ if (!virtual && !(cmd & PCI_COMMAND_IO))
printf(" [disabled]");
}
else
{
i++;
z = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
- if (opt_buscentric)
- {
- u32 y = a & 0xffffffff;
- if (a || z)
- printf("%08x%08x", z, y);
- else
- printf("<unassigned>");
- done = 1;
- }
}
}
if (!done)
(t == PCI_BASE_ADDRESS_MEM_TYPE_64) ? "64-bit" :
(t == PCI_BASE_ADDRESS_MEM_TYPE_1M) ? "low-1M" : "type 3",
(flg & PCI_BASE_ADDRESS_MEM_PREFETCH) ? "" : "non-");
- if (!(cmd & PCI_COMMAND_MEMORY))
+ if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
printf(" [disabled]");
}
show_size(len);
pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
u32 flg = get_conf_long(d, reg);
word cmd = get_conf_word(d, PCI_COMMAND);
+ int virtual = 0;
if (!rom && !flg && !len)
return;
{
printf("[virtual] ");
flg = rom;
+ virtual = 1;
}
printf("Expansion ROM at ");
if (rom & PCI_ROM_ADDRESS_MASK)
printf("<unassigned>");
if (!(flg & PCI_ROM_ADDRESS_ENABLE))
printf(" [disabled]");
- else if (!(cmd & PCI_COMMAND_MEMORY))
+ else if (!virtual && !(cmd & PCI_COMMAND_MEMORY))
printf(" [disabled by cmd]");
show_size(len);
putchar('\n');
int p = 8*i;
u32 base = get_conf_long(d, PCI_CB_MEMORY_BASE_0 + p);
u32 limit = get_conf_long(d, PCI_CB_MEMORY_LIMIT_0 + p);
- if (limit > base || verb)
+ limit = limit + 0xfff;
+ if (base <= limit || verb)
printf("\tMemory window %d: %08x-%08x%s%s\n", i, base, limit,
(cmd & PCI_COMMAND_MEMORY) ? "" : " [disabled]",
(brc & (PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 << i)) ? " (prefetchable)" : "");
break;
case 'b':
pacc->buscentric = 1;
- opt_buscentric = 1;
break;
case 's':
if (msg = pci_filter_parse_slot(&filter, optarg))