]> git.ipfire.org Git - thirdparty/pciutils.git/commitdiff
Topology now works in combination with filters
authorMartin Mares <mj@ucw.cz>
Sun, 12 Aug 2018 09:24:06 +0000 (11:24 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 12 Aug 2018 10:46:16 +0000 (12:46 +0200)
If bus topology is needed, we scan all devices regardless of filters,
and apply the filters later when showing devices.

Also, we forbid several impossible combinations of options: tree mode
with filters, bus mapping mode with anything requiring topology.

ls-tree.c
lspci.c

index 8ce9b4faf40272b6724a9188f4dd8eb9c64349a7..8d60ea2b417c96c1e534c53193b1e78dccd12734 100644 (file)
--- a/ls-tree.c
+++ b/ls-tree.c
@@ -237,7 +237,5 @@ void
 show_forest(void)
 {
   char line[256];
-
-  grow_tree();
   show_tree_bridge(&host_bridge, line, line);
 }
diff --git a/lspci.c b/lspci.c
index 46310598948be38c6ad75036d67e64ddaeb2d204..3dabbdeda711560049ccd677c6e59998c4e379ba 100644 (file)
--- a/lspci.c
+++ b/lspci.c
@@ -18,6 +18,7 @@
 int verbose;                           /* Show detailed information */
 static int opt_hex;                    /* Show contents of config space as hexadecimal numbers */
 struct pci_filter filter;              /* Device filter */
+static int opt_filter;                 /* Any filter was given */
 static int opt_tree;                   /* Show bus tree */
 static int opt_path;                   /* Show bridge path */
 static int opt_machine;                        /* Generate machine-readable output */
@@ -81,6 +82,7 @@ GENERIC_HELP
 struct pci_access *pacc;
 struct device *first_dev;
 static int seen_errors;
+static int need_topology;
 
 int
 config_fetch(struct device *d, unsigned int pos, unsigned int len)
@@ -117,7 +119,7 @@ scan_device(struct pci_dev *p)
 
   if (p->domain && !opt_domains)
     opt_domains = 1;
-  if (!pci_filter_match(&filter, p))
+  if (!pci_filter_match(&filter, p) && !need_topology)
     return NULL;
   d = xmalloc(sizeof(struct device));
   memset(d, 0, sizeof(*d));
@@ -977,10 +979,9 @@ show(void)
 {
   struct device *d;
 
-  if (opt_path)
-    grow_tree();
   for (d=first_dev; d; d=d->next)
-    show_device(d);
+    if (pci_filter_match(&filter, d->dev))
+      show_device(d);
 }
 
 /* Main */
@@ -1016,19 +1017,23 @@ main(int argc, char **argv)
       case 's':
        if (msg = pci_filter_parse_slot(&filter, optarg))
          die("-s: %s", msg);
+       opt_filter = 1;
        break;
       case 'd':
        if (msg = pci_filter_parse_id(&filter, optarg))
          die("-d: %s", msg);
+       opt_filter = 1;
        break;
       case 'x':
        opt_hex++;
        break;
       case 'P':
        opt_path++;
+       need_topology = 1;
        break;
       case 't':
        opt_tree++;
+       need_topology = 1;
        break;
       case 'i':
         pci_set_name_list_path(pacc, optarg, 0);
@@ -1072,6 +1077,9 @@ main(int argc, char **argv)
   if (optind < argc)
     goto bad;
 
+  if (opt_tree && opt_filter)
+    die("Tree mode does not support filtering");
+
   if (opt_query_dns)
     {
       pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK;
@@ -1084,14 +1092,16 @@ main(int argc, char **argv)
   pci_init(pacc);
   if (opt_map_mode)
     {
-      if (opt_path)
-       die("Bus paths cannot be shown in bus mapping mode");
+      if (need_topology)
+       die("Bus mapping mode does not recognize bus topology");
       map_the_bus();
     }
   else
     {
       scan_devices();
       sort_them();
+      if (need_topology)
+       grow_tree();
       if (opt_tree)
        show_forest();
       else