]> git.ipfire.org Git - thirdparty/pciutils.git/blobdiff - lspci.c
Updated pci.ids to today's snapshot
[thirdparty/pciutils.git] / lspci.c
diff --git a/lspci.c b/lspci.c
index 9958ef6b7b12061778208c017d6d616faeae3716..a67a516840ea0e6e8d9cf454e243f7c9725089f4 100644 (file)
--- a/lspci.c
+++ b/lspci.c
 #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 */
@@ -331,18 +329,16 @@ show_terse(struct device *d)
 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
@@ -351,6 +347,7 @@ show_bases(struct device *d, int cnt)
   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++)
     {
@@ -369,18 +366,19 @@ show_bases(struct device *d, int cnt)
        {
          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
@@ -402,15 +400,6 @@ show_bases(struct device *d, int cnt)
                {
                  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)
@@ -425,7 +414,7 @@ show_bases(struct device *d, int cnt)
                 (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);
@@ -441,6 +430,7 @@ show_rom(struct device *d, int reg)
   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;
@@ -449,6 +439,7 @@ show_rom(struct device *d, int reg)
     {
       printf("[virtual] ");
       flg = rom;
+      virtual = 1;
     }
   printf("Expansion ROM at ");
   if (rom & PCI_ROM_ADDRESS_MASK)
@@ -459,7 +450,7 @@ show_rom(struct device *d, int reg)
     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');
@@ -599,7 +590,8 @@ show_htype2(struct device *d)
       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)" : "");
@@ -943,7 +935,6 @@ main(int argc, char **argv)
        break;
       case 'b':
        pacc->buscentric = 1;
-       opt_buscentric = 1;
        break;
       case 's':
        if (msg = pci_filter_parse_slot(&filter, optarg))