UDM-pci.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. The U-Boot Driver Model Project
  2. ===============================
  3. PCI subsystem analysis
  4. ======================
  5. Pavel Herrmann <morpheus.ibis@gmail.com>
  6. 2012-03-17
  7. I) Overview
  8. -----------
  9. U-Boot already supports multiple PCI busses, stored in a linked-list of
  10. pci_controller structures. This structure contains generic driver data, bus
  11. interface operations and private data for the driver.
  12. Bus interface operations for PCI are (names are self-explanatory):
  13. read_byte()
  14. read_word()
  15. read_dword()
  16. write_byte()
  17. write_word()
  18. write_dword()
  19. Each driver has to implement dword operations, and either implement word and
  20. byte operations, or use shared $operation_config_$type_via_dword (eg.
  21. read_config_byte_via_dword and similar) function. These functions are used
  22. for config space I/O (read_config_dword and similar functions of the PCI
  23. subsystem), which is used to configure the connected devices for standard MMIO
  24. operations. All data transfers by respective device drivers are then done by
  25. MMIO
  26. Each driver also defines a separate init function, which has unique symbol
  27. name, and thus more drivers can be compiled in without colliding. This init
  28. function is typically called from pci_init_board(), different for each
  29. particular board.
  30. Some boards also define a function called fixup_irq, which gets called after
  31. scanning the PCI bus for devices, and should dismiss any interrupts.
  32. Several drivers are also located in arch/ and should be moved to drivers/pci.
  33. II) Approach
  34. ------------
  35. The pci_controller structure needs to be broken down to fit the new driver
  36. model. Due to a large number of members, this will be done through three
  37. distinct accessors, one for memory regions, one for config table and one for
  38. everything else. That will make the pci_ops structure look like this:
  39. struct pci_ops {
  40. int (*read_byte)(struct instance *bus, pci_dev_t *dev, int addr,
  41. u8 *buf);
  42. int (*read_word)(struct instance *bus, pci_dev_t *dev, int addr,
  43. u16 *buf);
  44. int (*read_dword)(struct instance *bus, pci_dev_t *dev, int addr,
  45. u32 *buf);
  46. int (*write_byte)(struct instance *bus, pci_dev_t *dev, int addr,
  47. u8 val);
  48. int (*write_byte)(struct instance *bus, pci_dev_t *dev, int addr,
  49. u8 val);
  50. int (*write_dword)(struct instance *bus, pci_dev_t *dev, int addr,
  51. u32 val);
  52. void (*fixup_irq)(struct instance *bus, pci_dev_t *dev);
  53. struct pci_region* (*get_region)(struct instance *, uint num);
  54. struct pci_config_table* (*get_cfg_table)(struct instance *bus);
  55. uint (*get_option)(struct instance * bus, enum pci_option_code op);
  56. }
  57. enum pci_option_code {
  58. PCI_OPT_BUS_NUMBER=0,
  59. PCI_OPT_REGION_COUNT,
  60. PCI_OPT_INDIRECT_TYPE,
  61. PCI_OPT_AUTO_MEM,
  62. PCI_OPT_AUTO_IO,
  63. PCI_OPT_AUTO_PREFETCH,
  64. PCI_OPT_AUTO_FB,
  65. PCI_OPT_CURRENT_BUS,
  66. PCI_OPT_CFG_ADDR,
  67. }
  68. The return value for get_option will be an unsigned integer value for any
  69. option code. If the option currently is a pointer to pci_region, it will
  70. return an index for get_region function. Special case has to be made for
  71. PCI_OPT_CFG_ADDR, which should be interpreted as a pointer, but it is only
  72. used for equality in find_hose_by_cfg_addr, and thus can be returned as an
  73. uint. Other function using cfg_addr value are read/write functions for
  74. specific drivers (especially ops for indirect bridges), and thus have access
  75. to private_data of the driver instance.
  76. The config table accessor will return a pointer to a NULL-terminated array of
  77. pci_config_table, which is supplied by the board in platform_data, or NULL if
  78. the board didn't specify one. This table is used to override PnP
  79. auto-initialization, or to specific initialization functions for non-PNP
  80. devices.
  81. Transparent PCI-PCI bridges will get their own driver, and will forward all
  82. operations to operations of their parent bus. This however makes it
  83. impossible to use instances to identify devices, as not all devices will be
  84. directly visible to the respective bus driver.
  85. Init functions of controller drivers will be moved to their respective
  86. probe() functions, in accordance to the driver model.
  87. The PCI core will handle all mapping functions currently found in pci.c, as
  88. well as proxy functions for read/write operations of the drivers. The PCI
  89. core will also handle bus scanning and device configuration.
  90. The PnP helper functions currently in pci_auto.c will also be a part of PCI
  91. core, but they will be exposed only to PCI controller drivers, not to other
  92. device drivers.
  93. The PCI API for device drivers will remain largely unchanged, most drivers
  94. will require no changes at all, and all modifications will be limited to
  95. changing the pci_controlle into instance*.
  96. III) Analysis of in-tree drivers
  97. --------------------------------
  98. A) drivers in drivers/pci/
  99. --------------------------
  100. 1) pci_indirect.c
  101. -----------------
  102. Shared driver for indirect PCI bridges, several CONFIG macros - will
  103. require significant cleanup.
  104. 2) pci_ixp.c
  105. ------------
  106. Standard driver, specifies all read/write functions separately.
  107. 3) pci_sh4.c
  108. ------------
  109. Shared init function for SH4 drivers, uses dword for read/write ops.
  110. 4) pci_sh7751.c
  111. ---------------
  112. Standard driver, uses SH4 shared init.
  113. 5) pci_sh7780.c
  114. ---------------
  115. Standard driver, uses SH4 shared init.
  116. 6) tsi108_pci.c
  117. ---------------
  118. Standard driver, uses dword for read/write ops.
  119. 7) fsl_pci_init.c
  120. -----------------
  121. Driver for PCI and PCI-e, uses indirect functions.
  122. 8) pci_ftpci100.c
  123. -----------------
  124. Standard driver, uses indirect functions, has separate scan/setup
  125. functions.
  126. B) driver in arch/
  127. ------------------
  128. 1) x86/lib/pci_type1.c
  129. ----------------------
  130. Standard driver, specifies all read/write functions separately.
  131. 2) m68k/cpu/mcf5445x/pci.c
  132. --------------------------
  133. Standard driver, specifies all read/write functions separately.
  134. 3) m68k/cpu/mcf547x_8x/pci.c
  135. ----------------------------
  136. Standard driver, specifies all read/write functions separately.
  137. 4) powerpc/cpu/mpc824x/pci.c
  138. ----------------------------
  139. Standard driver, uses indirect functions, does not setup HW.
  140. 5) powerpc/cpu/mpc8260/pci.c
  141. ----------------------------
  142. Standard driver, uses indirect functions.
  143. 6) powerpc/cpu/ppc4xx/4xx_pci.c
  144. -------------------------------
  145. Standard driver, uses indirect functions.
  146. 7) powerpc/cpu/ppc4xx/4xx_pcie.c
  147. --------------------------------
  148. PCI-e driver, specifies all read/write functions separately.
  149. 8) powerpc/cpu/mpc83xx/pci.c
  150. ----------------------------
  151. Standard driver, uses indirect functions.
  152. 9) powerpc/cpu/mpc83xx/pcie.c
  153. -----------------------------
  154. PCI-e driver, specifies all read/write functions separately.
  155. 10) powerpc/cpu/mpc5xxx/pci_mpc5200.c
  156. -------------------------------------
  157. Standard driver, uses dword for read/write ops.
  158. 11) powerpc/cpu/mpc512x/pci.c
  159. -----------------------------
  160. Standard driver, uses indirect functions.
  161. 12) powerpc/cpu/mpc85xx/pci.c
  162. -----------------------------
  163. Standard driver, uses indirect functions, has two busses.
  164. C) drivers in board/
  165. --------------------
  166. 1) eltec/elppc/pci.c
  167. --------------------
  168. Standard driver, uses indirect functions.
  169. 2) amirix/ap1000/pci.c
  170. ----------------------
  171. Standard driver, specifies all read/write functions separately.
  172. 3) prodrive/p3mx/pci.c
  173. ----------------------
  174. Standard driver, uses dword for read/write ops, has two busses.
  175. 4) esd/cpci750/pci.c
  176. --------------------
  177. Standard driver, uses dword for read/write ops, has two busses.
  178. 5) esd/common/pci.c
  179. -------------------
  180. Standard driver, uses dword for read/write ops.
  181. 6) dave/common/pci.c
  182. --------------------
  183. Standard driver, uses dword for read/write ops.
  184. 7) ppmc7xx/pci.c
  185. ----------------
  186. Standard driver, uses indirect functions.
  187. 9) Marvell/db64360/pci.c
  188. ------------------------
  189. Standard driver, uses dword for read/write ops, has two busses.
  190. 10) Marvell/db64460/pci.c
  191. -------------------------
  192. Standard driver, uses dword for read/write ops, has two busses.
  193. 11) evb64260/pci.c
  194. ------------------
  195. Standard driver, uses dword for read/write ops, has two busses.
  196. 12) armltd/integrator/pci.c
  197. ---------------------------
  198. Standard driver, specifies all read/write functions separately.
  199. All drivers will be moved to drivers/pci. Several drivers seem
  200. similar/identical, especially those located under board, and may be merged
  201. into one.