legacy.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * legacy.c - traditional, old school PCI bus probing
  4. */
  5. #include <linux/init.h>
  6. #include <linux/export.h>
  7. #include <linux/pci.h>
  8. #include <asm/jailhouse_para.h>
  9. #include <asm/pci_x86.h>
  10. /*
  11. * Discover remaining PCI buses in case there are peer host bridges.
  12. * We use the number of last PCI bus provided by the PCI BIOS.
  13. */
  14. static void pcibios_fixup_peer_bridges(void)
  15. {
  16. int n;
  17. if (pcibios_last_bus <= 0 || pcibios_last_bus > 0xff)
  18. return;
  19. DBG("PCI: Peer bridge fixup\n");
  20. for (n=0; n <= pcibios_last_bus; n++)
  21. pcibios_scan_specific_bus(n);
  22. }
  23. int __init pci_legacy_init(void)
  24. {
  25. if (!raw_pci_ops)
  26. return 1;
  27. pr_info("PCI: Probing PCI hardware\n");
  28. pcibios_scan_root(0);
  29. return 0;
  30. }
  31. void pcibios_scan_specific_bus(int busn)
  32. {
  33. int stride = jailhouse_paravirt() ? 1 : 8;
  34. int devfn;
  35. u32 l;
  36. if (pci_find_bus(0, busn))
  37. return;
  38. for (devfn = 0; devfn < 256; devfn += stride) {
  39. if (!raw_pci_read(0, busn, devfn, PCI_VENDOR_ID, 2, &l) &&
  40. l != 0x0000 && l != 0xffff) {
  41. DBG("Found device at %02x:%02x [%04x]\n", busn, devfn, l);
  42. pr_info("PCI: Discovered peer bus %02x\n", busn);
  43. pcibios_scan_root(busn);
  44. return;
  45. }
  46. }
  47. }
  48. EXPORT_SYMBOL_GPL(pcibios_scan_specific_bus);
  49. static int __init pci_subsys_init(void)
  50. {
  51. /*
  52. * The init function returns an non zero value when
  53. * pci_legacy_init should be invoked.
  54. */
  55. if (x86_init.pci.init()) {
  56. if (pci_legacy_init()) {
  57. pr_info("PCI: System does not support PCI\n");
  58. return -ENODEV;
  59. }
  60. }
  61. pcibios_fixup_peer_bridges();
  62. x86_init.pci.init_irq();
  63. pcibios_init();
  64. return 0;
  65. }
  66. subsys_initcall(pci_subsys_init);