Commit 1a4942f1d90f3fe883db27fcad11f21e5698d46c

Authored by Pali Rohár
Committed by Tom Rini
1 parent 6850a5a8e2
Exists in emb_lf_v2022.04

pci: Extend 'pci' command with bus option '*'

Allow to call 'pci' and 'pci regions' commands with bus option '*' which
cause pci to process all buses.

PCIe is point-to-point HW and so on each bus is maximally one physical
device. Therefore for PCIe it is common to have multiple buses.

This change allows to easily print all available PCIe devices in system.

Make '*' as default option when no bus argument is specified.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>

Showing 1 changed file with 35 additions and 10 deletions Side-by-side Diff

... ... @@ -256,10 +256,8 @@
256 256 }
257 257 }
258 258  
259   -static void pciinfo_header(int busnum, bool short_listing)
  259 +static void pciinfo_header(bool short_listing)
260 260 {
261   - printf("Scanning PCI devices on bus %d\n", busnum);
262   -
263 261 if (short_listing) {
264 262 printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n");
265 263 printf("_____________________________________________________________\n");
266 264  
267 265  
... ... @@ -288,12 +286,16 @@
288 286 pci_class_str(class), subclass);
289 287 }
290 288  
291   -static void pciinfo(struct udevice *bus, bool short_listing)
  289 +static void pciinfo(struct udevice *bus, bool short_listing, bool multi)
292 290 {
293 291 struct udevice *dev;
294 292  
295   - pciinfo_header(dev_seq(bus), short_listing);
  293 + if (!multi)
  294 + printf("Scanning PCI devices on bus %d\n", dev_seq(bus));
296 295  
  296 + if (!multi || dev_seq(bus) == 0)
  297 + pciinfo_header(short_listing);
  298 +
297 299 for (device_find_first_child(bus, &dev);
298 300 dev;
299 301 device_find_next_child(&dev)) {
300 302  
... ... @@ -483,10 +485,11 @@
483 485 ulong addr = 0, value = 0, cmd_size = 0;
484 486 enum pci_size_t size = PCI_SIZE_32;
485 487 struct udevice *dev, *bus;
486   - int busnum = 0;
  488 + int busnum = -1;
487 489 pci_dev_t bdf = 0;
488 490 char cmd = 's';
489 491 int ret = 0;
  492 + char *endp;
490 493  
491 494 if (argc > 1)
492 495 cmd = argv[1][0];
... ... @@ -522,7 +525,11 @@
522 525 argc--;
523 526 }
524 527 if (argc > 2 || (argc > 1 && cmd != 'r' && argv[1][0] != 's')) {
525   - busnum = hextoul(argv[argc - 1], NULL);
  528 + if (argv[argc - 1][0] != '*') {
  529 + busnum = hextoul(argv[argc - 1], &endp);
  530 + if (*endp)
  531 + goto usage;
  532 + }
526 533 argc--;
527 534 }
528 535 if (cmd == 'r' && argc > 2)
... ... @@ -530,6 +537,24 @@
530 537 else if (cmd != 'r' && (argc > 2 || (argc == 2 && argv[1][0] != 's')))
531 538 goto usage;
532 539 }
  540 + if (busnum == -1) {
  541 + if (cmd != 'r') {
  542 + for (busnum = 0;
  543 + uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0;
  544 + busnum++)
  545 + pciinfo(bus, value, true);
  546 + } else {
  547 + for (busnum = 0;
  548 + uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0;
  549 + busnum++) {
  550 + /* Regions are controller specific so skip non-root buses */
  551 + if (device_is_on_pci_bus(bus))
  552 + continue;
  553 + pci_show_regions(bus);
  554 + }
  555 + }
  556 + return 0;
  557 + }
533 558 ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus);
534 559 if (ret) {
535 560 printf("No such bus\n");
... ... @@ -538,7 +563,7 @@
538 563 if (cmd == 'r')
539 564 pci_show_regions(bus);
540 565 else
541   - pciinfo(bus, value);
  566 + pciinfo(bus, value, false);
542 567 return 0;
543 568 }
544 569  
... ... @@ -585,7 +610,7 @@
585 610  
586 611 #ifdef CONFIG_SYS_LONGHELP
587 612 static char pci_help_text[] =
588   - "[bus] [long]\n"
  613 + "[bus|*] [long]\n"
589 614 " - short or long list of PCI devices on bus 'bus'\n"
590 615 "pci enum\n"
591 616 " - Enumerate PCI buses\n"
... ... @@ -593,7 +618,7 @@
593 618 " - show header of PCI device 'bus.device.function'\n"
594 619 "pci bar b.d.f\n"
595 620 " - show BARs base and size for device b.d.f'\n"
596   - "pci regions [bus]\n"
  621 + "pci regions [bus|*]\n"
597 622 " - show PCI regions\n"
598 623 "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n"
599 624 " - display PCI configuration space (CFG)\n"