pci-info.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. PCI with Driver Model
  3. =====================
  4. How busses are scanned
  5. ----------------------
  6. Any config read will end up at pci_read_config(). This uses
  7. uclass_get_device_by_seq() to get the PCI bus for a particular bus number.
  8. Bus number 0 will need to be requested first, and the alias in the device
  9. tree file will point to the correct device::
  10. aliases {
  11. pci0 = &pcic;
  12. };
  13. pcic: pci@0 {
  14. compatible = "sandbox,pci";
  15. ...
  16. };
  17. If there is no alias the devices will be numbered sequentially in the device
  18. tree.
  19. The call to uclass_get_device() will cause the PCI bus to be probed.
  20. This does a scan of the bus to locate available devices. These devices are
  21. bound to their appropriate driver if available. If there is no driver, then
  22. they are bound to a generic PCI driver which does nothing.
  23. After probing a bus, the available devices will appear in the device tree
  24. under that bus.
  25. Note that this is all done on a lazy basis, as needed, so until something is
  26. touched on PCI (eg: a call to pci_find_devices()) it will not be probed.
  27. PCI devices can appear in the flattened device tree. If they do, their node
  28. often contains extra information which cannot be derived from the PCI IDs or
  29. PCI class of the device. Each PCI device node must have a <reg> property, as
  30. defined by the IEEE Std 1275-1994 PCI bus binding document v2.1. Compatible
  31. string list is optional and generally not needed, since PCI is discoverable
  32. bus, albeit there are justified exceptions. If the compatible string is
  33. present, matching on it takes precedence over PCI IDs and PCI classes.
  34. Note we must describe PCI devices with the same bus hierarchy as the
  35. hardware, otherwise driver model cannot detect the correct parent/children
  36. relationship during PCI bus enumeration thus PCI devices won't be bound to
  37. their drivers accordingly. A working example like below::
  38. pci {
  39. #address-cells = <3>;
  40. #size-cells = <2>;
  41. compatible = "pci-x86";
  42. u-boot,dm-pre-reloc;
  43. ranges = <0x02000000 0x0 0x40000000 0x40000000 0 0x80000000
  44. 0x42000000 0x0 0xc0000000 0xc0000000 0 0x20000000
  45. 0x01000000 0x0 0x2000 0x2000 0 0xe000>;
  46. pcie@17,0 {
  47. #address-cells = <3>;
  48. #size-cells = <2>;
  49. compatible = "pci-bridge";
  50. u-boot,dm-pre-reloc;
  51. reg = <0x0000b800 0x0 0x0 0x0 0x0>;
  52. topcliff@0,0 {
  53. #address-cells = <3>;
  54. #size-cells = <2>;
  55. compatible = "pci-bridge";
  56. u-boot,dm-pre-reloc;
  57. reg = <0x00010000 0x0 0x0 0x0 0x0>;
  58. pciuart0: uart@a,1 {
  59. compatible = "pci8086,8811.00",
  60. "pci8086,8811",
  61. "pciclass,070002",
  62. "pciclass,0700",
  63. "x86-uart";
  64. u-boot,dm-pre-reloc;
  65. reg = <0x00025100 0x0 0x0 0x0 0x0
  66. 0x01025110 0x0 0x0 0x0 0x0>;
  67. ......
  68. };
  69. ......
  70. };
  71. };
  72. ......
  73. };
  74. In this example, the root PCI bus node is the "/pci" which matches "pci-x86"
  75. driver. It has a subnode "pcie@17,0" with driver "pci-bridge". "pcie@17,0"
  76. also has subnode "topcliff@0,0" which is a "pci-bridge" too. Under that bridge,
  77. a PCI UART device "uart@a,1" is described. This exactly reflects the hardware
  78. bus hierarchy: on the root PCI bus, there is a PCIe root port which connects
  79. to a downstream device Topcliff chipset. Inside Topcliff chipset, it has a
  80. PCIe-to-PCI bridge and all the chipset integrated devices like the PCI UART
  81. device are on the PCI bus. Like other devices in the device tree, if we want
  82. to bind PCI devices before relocation, "u-boot,dm-pre-reloc" must be declared
  83. in each of these nodes.
  84. If PCI devices are not listed in the device tree, U_BOOT_PCI_DEVICE can be used
  85. to specify the driver to use for the device. The device tree takes precedence
  86. over U_BOOT_PCI_DEVICE. Please note with U_BOOT_PCI_DEVICE, only drivers with
  87. DM_FLAG_PRE_RELOC will be bound before relocation. If neither device tree nor
  88. U_BOOT_PCI_DEVICE is provided, the built-in driver (either pci_bridge_drv or
  89. pci_generic_drv) will be used.
  90. Sandbox
  91. -------
  92. With sandbox we need a device emulator for each device on the bus since there
  93. is no real PCI bus. This works by looking in the device tree node for an
  94. emulator driver. For example::
  95. pci@1f,0 {
  96. compatible = "pci-generic";
  97. reg = <0xf800 0 0 0 0>;
  98. sandbox,emul = <&emul_1f>;
  99. };
  100. pci-emul {
  101. compatible = "sandbox,pci-emul-parent";
  102. emul_1f: emul@1f,0 {
  103. compatible = "sandbox,swap-case";
  104. };
  105. };
  106. This means that there is a 'sandbox,swap-case' driver at that bus position.
  107. Note that the first cell in the 'reg' value is the bus/device/function. See
  108. PCI_BDF() for the encoding (it is also specified in the IEEE Std 1275-1994
  109. PCI bus binding document, v2.1)
  110. The pci-emul node should go outside the pci bus node, since otherwise it will
  111. be scanned as a PCI device, causing confusion.
  112. When this bus is scanned we will end up with something like this::
  113. `- * pci@0 @ 05c660c8, 0
  114. `- pci@1f,0 @ 05c661c8, 63488
  115. `- emul@1f,0 @ 05c662c8
  116. When accesses go to the pci@1f,0 device they are forwarded to its emulator.
  117. The sandbox PCI drivers also support dynamic driver binding, allowing device
  118. driver to declare the driver binding information via U_BOOT_PCI_DEVICE(),
  119. eliminating the need to provide any device tree node under the host controller
  120. node. It is required a "sandbox,dev-info" property must be provided in the
  121. host controller node for this functionality to work.
  122. .. code-block:: none
  123. pci1: pci@1 {
  124. compatible = "sandbox,pci";
  125. ...
  126. sandbox,dev-info = <0x08 0x00 0x1234 0x5678
  127. 0x0c 0x00 0x1234 0x5678>;
  128. };
  129. The "sandbox,dev-info" property specifies all dynamic PCI devices on this bus.
  130. Each dynamic PCI device is encoded as 4 cells a group. The first and second
  131. cells are PCI device number and function number respectively. The third and
  132. fourth cells are PCI vendor ID and device ID respectively.
  133. When this bus is scanned we will end up with something like this::
  134. pci [ + ] pci_sandbo |-- pci1
  135. pci_emul [ ] sandbox_sw | |-- sandbox_swap_case_emul
  136. pci_emul [ ] sandbox_sw | `-- sandbox_swap_case_emul