pci-endpoint.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. PCI ENDPOINT FRAMEWORK
  2. Kishon Vijay Abraham I <kishon@ti.com>
  3. This document is a guide to use the PCI Endpoint Framework in order to create
  4. endpoint controller driver, endpoint function driver and using configfs
  5. interface to bind the function driver to the controller driver.
  6. 1. Introduction
  7. *Linux* has a comprehensive PCI subsystem to support PCI controllers that
  8. operates in Root Complex mode. The subsystem has capability to scan PCI bus,
  9. assign memory resources and irq resources, load PCI driver (based on
  10. vendorid, deviceid), support other services like hot-plug, power management,
  11. advanced error reporting and virtual channels.
  12. However PCI controller IPs integrated in certain SoC is capable of operating
  13. either in Root Complex mode or Endpoint mode. PCI Endpoint Framework will
  14. add endpoint mode support in *Linux*. This will help to run Linux in an
  15. EP system which can have a wide variety of use cases from testing or
  16. validation, co-processor accelerator etc..
  17. 2. PCI Endpoint Core
  18. The PCI Endpoint Core layer comprises of 3 components: the Endpoint Controller
  19. library, the Endpoint Function library and the configfs layer to bind the
  20. endpoint function with the endpoint controller.
  21. 2.1 PCI Endpoint Controller(EPC) Library
  22. The EPC library provides APIs to be used by the controller that can operate
  23. in endpoint mode. It also provides APIs to be used by function driver/library
  24. in order to implement a particular endpoint function.
  25. 2.1.1 APIs for the PCI controller Driver
  26. This section lists the APIs that the PCI Endpoint core provides to be used
  27. by the PCI controller driver.
  28. *) devm_pci_epc_create()/pci_epc_create()
  29. The PCI controller driver should implement the following ops:
  30. * write_header: ops to populate configuration space header
  31. * set_bar: ops to configure the BAR
  32. * clear_bar: ops to reset the BAR
  33. * alloc_addr_space: ops to allocate *in* PCI controller address space
  34. * free_addr_space: ops to free the allocated address space
  35. * raise_irq: ops to raise a legacy or MSI interrupt
  36. * start: ops to start the PCI link
  37. * stop: ops to stop the PCI link
  38. The PCI controller driver can then create a new EPC device by invoking
  39. devm_pci_epc_create/pci_epc_create.
  40. *) devm_pci_epc_destroy()/pci_epc_destroy()
  41. The PCI controller driver can destroy the EPC device created by either
  42. devm_pci_epc_create or pci_epc_create using devm_pci_epc_destroy() or
  43. /pci_epc_destroy()
  44. 2.1.2 APIs for the PCI Endpoint Function Driver
  45. This section lists the APIs that the PCI Endpoint core provides to be used
  46. by the PCI endpoint function driver.
  47. *) pci_epc_write_header()
  48. The PCI endpoint function driver should use pci_epc_write_header() to
  49. write the standard configuration header to the endpoint controller.
  50. *) pci_epc_set_bar()
  51. The PCI endpoint function driver should use pci_epc_set_bar() to configure
  52. the Base Address Register in order for the host to assign PCI addr space.
  53. Register space of the function driver is usually configured
  54. using this API.
  55. *) pci_epc_clear_bar()
  56. The PCI endpoint function driver should use pci_epc_clear_bar() to reset
  57. the BAR.
  58. *) pci_epc_raise_irq()
  59. The PCI endpoint function driver should use pci_epc_raise_irq() to raise
  60. Legacy Interrupt or MSI Interrupt.
  61. *) pci_epc_start()
  62. The PCI endpoint function driver should invoke pci_epc_start() once it
  63. has configured the endpoint function and wants to start the PCI link.
  64. *) pci_epc_stop()
  65. The PCI endpoint function driver should invoke pci_epc_stop() to stop
  66. the PCI LINK.
  67. 2.1.3 Other APIs
  68. There are other APIs provided by the EPC library. These are used for binding
  69. the epf device with epc device. pci-ep-cfs.c can be used as reference for
  70. using these APIs.
  71. *) pci_epc_get()
  72. Get a reference to the pci endpoint controller based on the device name of
  73. the controller.
  74. *) pci_epc_put()
  75. Release the reference to the pci endpoint controller obtained using
  76. pci_epc_get()
  77. *) pci_epc_add_epf()
  78. Add a pci endpoint function to a pci endpoint controller. A pcie device
  79. can have upto 8 functions according to the specification.
  80. *) pci_epc_remove_epf()
  81. Remove the pci endpoint function from pci endpoint controller.
  82. 2.2 PCI Endpoint Function(EPF) Library
  83. The EPF library provides APIs to be used by the function driver and the EPC
  84. library in order to provide endpoint mode functionality.
  85. 2.2.1 APIs for the PCI Endpoint Function Driver
  86. This section lists the APIs that the PCI Endpoint core provides to be used
  87. by the PCI endpoint function driver.
  88. *) pci_epf_register_driver()
  89. The PCI Endpoint Function driver should implement the following ops:
  90. * bind: ops to perform when a EPC device has been bound to EPF device
  91. * unbind: ops to perform when a binding has been lost between a EPC
  92. device and EPF device
  93. * linkup: ops to perform when the EPC device has established a
  94. connection with a host system
  95. The PCI Function driver can then register the PCI EPF driver by using
  96. pci_epf_register_driver().
  97. *) pci_epf_unregister_driver()
  98. The PCI Function driver can unregister the PCI EPF driver by using
  99. pci_epf_unregister_driver().
  100. *) pci_epf_alloc_space()
  101. The PCI Function driver can allocate space for a particular BAR using
  102. pci_epf_alloc_space().
  103. *) pci_epf_free_space()
  104. The PCI Function driver can free the allocated space
  105. (using pci_epf_alloc_space) by invoking pci_epf_free_space().
  106. 2.2.2 APIs for the PCI Endpoint Controller Library
  107. This section lists the APIs that the PCI Endpoint core provides to be used
  108. by the PCI endpoint controller library.
  109. *) pci_epf_linkup()
  110. The PCI endpoint controller library invokes pci_epf_linkup() when the
  111. EPC device has established the connection to the host.
  112. 2.2.2 Other APIs
  113. There are other APIs provided by the EPF library. These are used to notify
  114. the function driver when the EPF device is bound to the EPC device.
  115. pci-ep-cfs.c can be used as reference for using these APIs.
  116. *) pci_epf_create()
  117. Create a new PCI EPF device by passing the name of the PCI EPF device.
  118. This name will be used to bind the the EPF device to a EPF driver.
  119. *) pci_epf_destroy()
  120. Destroy the created PCI EPF device.
  121. *) pci_epf_bind()
  122. pci_epf_bind() should be invoked when the EPF device has been bound to
  123. a EPC device.
  124. *) pci_epf_unbind()
  125. pci_epf_unbind() should be invoked when the binding between EPC device
  126. and EPF device is lost.