]> mj.ucw.cz Git - pciutils.git/blobdiff - lspci.c
lspci: Add ability to filter by class code
[pciutils.git] / lspci.c
diff --git a/lspci.c b/lspci.c
index 5456c5a8acfb0d7992f37262249cd108c233ac61..6f161421d64766dbda934491645d22d23c1ba592 100644 (file)
--- a/lspci.c
+++ b/lspci.c
@@ -10,7 +10,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdarg.h>
-#include <unistd.h>
 
 #include "lspci.h"
 
@@ -61,7 +60,7 @@ static char help_msg[] =
 "\n"
 "Selection of devices:\n"
 "-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]\tShow only devices in selected slots\n"
-"-d [<vendor>]:[<device>]\t\t\tShow only devices with specified ID's\n"
+"-d [<vendor>]:[<device>][:<class>]\t\tShow only devices with specified ID's\n"
 "\n"
 "Other options:\n"
 "-i <file>\tUse specified ID database instead of %s\n"
@@ -139,7 +138,7 @@ scan_device(struct pci_dev *p)
        d->config_cached += 64;
     }
   pci_setup_cache(p, d->config, d->config_cached);
-  pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES | PCI_FILL_PHYS_SLOT);
+  pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES | PCI_FILL_PHYS_SLOT | PCI_FILL_LABEL);
   return d;
 }
 
@@ -316,6 +315,8 @@ show_terse(struct device *d)
       word subsys_v, subsys_d;
       char ssnamebuf[256];
 
+      if (p->label)
+        printf("\tDeviceName: %s", p->label);
       get_subid(d, &subsys_v, &subsys_d);
       if (subsys_v && subsys_v != 0xffff)
        printf("\tSubsystem: %s\n",
@@ -330,18 +331,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
@@ -350,6 +349,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++)
     {
@@ -368,18 +368,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
@@ -415,7 +416,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);
@@ -431,6 +432,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;
@@ -439,6 +441,7 @@ show_rom(struct device *d, int reg)
     {
       printf("[virtual] ");
       flg = rom;
+      virtual = 1;
     }
   printf("Expansion ROM at ");
   if (rom & PCI_ROM_ADDRESS_MASK)
@@ -449,7 +452,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');
@@ -460,7 +463,7 @@ show_htype0(struct device *d)
 {
   show_bases(d, 6);
   show_rom(d, PCI_ROM_ADDRESS);
-  show_caps(d);
+  show_caps(d, PCI_CAPABILITY_LIST);
 }
 
 static void
@@ -566,7 +569,7 @@ show_htype1(struct device *d)
        FLAG(brc, PCI_BRIDGE_CTL_DISCARD_TIMER_SERR_EN));
     }
 
-  show_caps(d);
+  show_caps(d, PCI_CAPABILITY_LIST);
 }
 
 static void
@@ -589,7 +592,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)" : "");
@@ -633,6 +637,7 @@ show_htype2(struct device *d)
   exca = get_conf_word(d, PCI_CB_LEGACY_MODE_BASE);
   if (exca)
     printf("\t16-bit legacy interface ports at %04x\n", exca);
+  show_caps(d, PCI_CB_CAPABILITY_LIST);
 }
 
 static void
@@ -663,7 +668,7 @@ show_verbose(struct device *d)
     case PCI_HEADER_TYPE_BRIDGE:
       if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
        printf("\t!!! Invalid class %04x for header type %02x\n", class, htype);
-      irq = int_pin = min_gnt = max_lat = 0;
+      min_gnt = max_lat = 0;
       break;
     case PCI_HEADER_TYPE_CARDBUS:
       if ((class >> 8) != PCI_BASE_CLASS_BRIDGE)
@@ -1011,6 +1016,7 @@ main(int argc, char **argv)
       else
        show();
     }
+  show_kernel_cleanup();
   pci_cleanup(pacc);
 
   return (seen_errors ? 2 : 0);