Commit e578b92cdb378df0f09065e3222fe8620867a57a

Authored by Stephen Warren
Committed by Simon Glass
1 parent be1df82656

Implement "pci enum" command for CONFIG_DM_PCI

With CONFIG_DM_PCI enabled, PCI buses are not enumerated at boot, as they
are without that config option enabled. No command exists to enumerate the
PCI buses. Hence, unless some board-specific code causes PCI enumeration,
PCI-based Ethernet devices are not detected, and network access is not
available.

This patch implements "pci enum" in the CONFIG_DM_PCI case, thus giving a
mechanism whereby PCI can be enumerated.

do_pci()'s handling of case 'e' is moved into a single location before the
dev variable is assigned, in order to skip calculation of dev. The enum
sub-command doesn't need the dev value, and skipping its calculation
avoids an irrelevant error being printed.

Using a command to initialize PCI like this has a disadvantage relative to
enumerating PCI at boot. In particular, Ethernet devices are not probed
during PCI enumeration, but only when used. This defers setting variables
such as ethact, ethaddr, etc. until the first network-related command is
executed. Hopefully this will not cause further issues. Perhaps in the
long term, we need a "net start/enum" command too?

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Showing 2 changed files with 20 additions and 13 deletions Side-by-side Diff

... ... @@ -578,9 +578,10 @@
578 578 if ((bdf = get_pci_dev(argv[2])) == -1)
579 579 return 1;
580 580 break;
581   -#ifdef CONFIG_CMD_PCI_ENUM
  581 +#if defined(CONFIG_CMD_PCI_ENUM) || defined(CONFIG_DM_PCI)
582 582 case 'e':
583   - break;
  583 + pci_init();
  584 + return 0;
584 585 #endif
585 586 default: /* scan bus */
586 587 value = 1; /* short listing */
... ... @@ -621,15 +622,6 @@
621 622 break;
622 623 case 'd': /* display */
623 624 return pci_cfg_display(dev, addr, size, value);
624   -#ifdef CONFIG_CMD_PCI_ENUM
625   - case 'e':
626   -# ifdef CONFIG_DM_PCI
627   - printf("This command is not yet supported with driver model\n");
628   -# else
629   - pci_init();
630   -# endif
631   - break;
632   -#endif
633 625 case 'n': /* next */
634 626 if (argc < 4)
635 627 goto usage;
636 628  
... ... @@ -665,9 +657,9 @@
665 657 static char pci_help_text[] =
666 658 "[bus] [long]\n"
667 659 " - short or long list of PCI devices on bus 'bus'\n"
668   -#ifdef CONFIG_CMD_PCI_ENUM
  660 +#if defined(CONFIG_CMD_PCI_ENUM) || defined(CONFIG_DM_PCI)
669 661 "pci enum\n"
670   - " - re-enumerate PCI buses\n"
  662 + " - Enumerate PCI buses\n"
671 663 #endif
672 664 "pci header b.d.f\n"
673 665 " - show header of PCI device 'bus.device.function'\n"
drivers/pci/pci-uclass.c
... ... @@ -1241,4 +1241,19 @@
1241 1241 .id = UCLASS_PCI_GENERIC,
1242 1242 .of_match = pci_generic_ids,
1243 1243 };
  1244 +
  1245 +void pci_init(void)
  1246 +{
  1247 + struct udevice *bus;
  1248 +
  1249 + /*
  1250 + * Enumerate all known controller devices. Enumeration has the side-
  1251 + * effect of probing them, so PCIe devices will be enumerated too.
  1252 + */
  1253 + for (uclass_first_device(UCLASS_PCI, &bus);
  1254 + bus;
  1255 + uclass_next_device(&bus)) {
  1256 + ;
  1257 + }
  1258 +}