driver-core.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. ============================
  2. Core Driver Infrastructure
  3. ============================
  4. GPU Hardware Structure
  5. ======================
  6. Each ASIC is a collection of hardware blocks. We refer to them as
  7. "IPs" (Intellectual Property blocks). Each IP encapsulates certain
  8. functionality. IPs are versioned and can also be mixed and matched.
  9. E.g., you might have two different ASICs that both have System DMA (SDMA) 5.x IPs.
  10. The driver is arranged by IPs. There are driver components to handle
  11. the initialization and operation of each IP. There are also a bunch
  12. of smaller IPs that don't really need much if any driver interaction.
  13. Those end up getting lumped into the common stuff in the soc files.
  14. The soc files (e.g., vi.c, soc15.c nv.c) contain code for aspects of
  15. the SoC itself rather than specific IPs. E.g., things like GPU resets
  16. and register access functions are SoC dependent.
  17. An APU contains more than just CPU and GPU, it also contains all of
  18. the platform stuff (audio, usb, gpio, etc.). Also, a lot of
  19. components are shared between the CPU, platform, and the GPU (e.g.,
  20. SMU, PSP, etc.). Specific components (CPU, GPU, etc.) usually have
  21. their interface to interact with those common components. For things
  22. like S0i3 there is a ton of coordination required across all the
  23. components, but that is probably a bit beyond the scope of this
  24. section.
  25. With respect to the GPU, we have the following major IPs:
  26. GMC (Graphics Memory Controller)
  27. This was a dedicated IP on older pre-vega chips, but has since
  28. become somewhat decentralized on vega and newer chips. They now
  29. have dedicated memory hubs for specific IPs or groups of IPs. We
  30. still treat it as a single component in the driver however since
  31. the programming model is still pretty similar. This is how the
  32. different IPs on the GPU get the memory (VRAM or system memory).
  33. It also provides the support for per process GPU virtual address
  34. spaces.
  35. IH (Interrupt Handler)
  36. This is the interrupt controller on the GPU. All of the IPs feed
  37. their interrupts into this IP and it aggregates them into a set of
  38. ring buffers that the driver can parse to handle interrupts from
  39. different IPs.
  40. PSP (Platform Security Processor)
  41. This handles security policy for the SoC and executes trusted
  42. applications, and validates and loads firmwares for other blocks.
  43. SMU (System Management Unit)
  44. This is the power management microcontroller. It manages the entire
  45. SoC. The driver interacts with it to control power management
  46. features like clocks, voltages, power rails, etc.
  47. DCN (Display Controller Next)
  48. This is the display controller. It handles the display hardware.
  49. It is described in more details in :ref:`Display Core <amdgpu-display-core>`.
  50. SDMA (System DMA)
  51. This is a multi-purpose DMA engine. The kernel driver uses it for
  52. various things including paging and GPU page table updates. It's also
  53. exposed to userspace for use by user mode drivers (OpenGL, Vulkan,
  54. etc.)
  55. GC (Graphics and Compute)
  56. This is the graphics and compute engine, i.e., the block that
  57. encompasses the 3D pipeline and shader blocks. This is by far the
  58. largest block on the GPU. The 3D pipeline has tons of sub-blocks. In
  59. addition to that, it also contains the CP microcontrollers (ME, PFP, CE,
  60. MEC) and the RLC microcontroller. It's exposed to userspace for user mode
  61. drivers (OpenGL, Vulkan, OpenCL, etc.). More details in :ref:`Graphics (GFX)
  62. and Compute <amdgpu-gc>`.
  63. VCN (Video Core Next)
  64. This is the multi-media engine. It handles video and image encode and
  65. decode. It's exposed to userspace for user mode drivers (VA-API,
  66. OpenMAX, etc.)
  67. It is important to note that these blocks can interact with each other. The
  68. picture below illustrates some of the components and their interconnection:
  69. .. kernel-figure:: amd_overview_block.svg
  70. In the diagram, memory-related blocks are shown in green. Notice that specific
  71. IPs have a green square that represents a small hardware block named 'hub',
  72. which is responsible for interfacing with memory. All memory hubs are connected
  73. in the UMCs, which in turn are connected to memory blocks. As a note,
  74. pre-vega devices have a dedicated block for the Graphic Memory Controller
  75. (GMC), which was replaced by UMC and hubs in new architectures. In the driver
  76. code, you can identify this component by looking for the suffix hub, for
  77. example: gfxhub, dchub, mmhub, vmhub, etc. Keep in mind that the component's
  78. interaction with the memory block may vary across architectures. For example,
  79. on Navi and newer, GC and SDMA are both attached to GCHUB; on pre-Navi, SDMA
  80. goes through MMHUB; VCN, JPEG, and VPE go through MMHUB; DCN goes through
  81. DCHUB.
  82. There is some protection for certain memory elements, and the PSP plays an
  83. essential role in this area. When a specific firmware is loaded into memory,
  84. the PSP takes steps to ensure it has a valid signature. It also stores firmware
  85. images in a protected memory area named Trusted Memory Area (TMR), so the OS or
  86. driver can't corrupt them at runtime. Another use of PSP is to support Trusted
  87. Applications (TA), which are basically small applications that run on the
  88. trusted processor and handles a trusted operation (e.g., HDCP). PSP is also
  89. used for encrypted memory for content protection via Trusted Memory Zone (TMZ).
  90. Another critical IP is the SMU. It handles reset distribution, as well as
  91. clock, thermal, and power management for all IPs on the SoC. SMU also helps to
  92. balance performance and power consumption.
  93. .. _pipes-and-queues-description:
  94. GFX, Compute, and SDMA Overall Behavior
  95. =======================================
  96. .. note:: For simplicity, whenever the term block is used in this section, it
  97. means GFX, Compute, and SDMA.
  98. GFX, Compute and SDMA share a similar form of operation that can be abstracted
  99. to facilitate understanding of the behavior of these blocks. See the figure
  100. below illustrating the common components of these blocks:
  101. .. kernel-figure:: pipe_and_queue_abstraction.svg
  102. In the central part of this figure, you can see two hardware elements, one called
  103. **Pipes** and another called **Queues**; it is important to highlight that Queues
  104. must be associated with a Pipe and vice-versa. Every specific hardware IP may have
  105. a different number of Pipes and, in turn, a different number of Queues; for
  106. example, GFX 11 has two Pipes and two Queues per Pipe for the GFX front end.
  107. Pipe is the hardware that processes the instructions available in the Queues;
  108. in other words, it is a thread executing the operations inserted in the Queue.
  109. One crucial characteristic of Pipes is that they can only execute one Queue at
  110. a time; no matter if the hardware has multiple Queues in the Pipe, it only runs
  111. one Queue per Pipe.
  112. Pipes have the mechanics of swapping between queues at the hardware level.
  113. Nonetheless, they only make use of Queues that are considered mapped. Pipes can
  114. switch between queues based on any of the following inputs:
  115. 1. Command Stream;
  116. 2. Packet by Packet;
  117. 3. Other hardware requests the change (e.g., MES).
  118. Queues within Pipes are defined by the Hardware Queue Descriptors (HQD).
  119. Associated with the HQD concept, we have the Memory Queue Descriptor (MQD),
  120. which is responsible for storing information about the state of each of the
  121. available Queues in the memory. The state of a Queue contains information such
  122. as the GPU virtual address of the queue itself, save areas, doorbell, etc. The
  123. MQD also stores the HQD registers, which are vital for activating or
  124. deactivating a given Queue. The scheduling firmware (e.g., MES) is responsible
  125. for loading HQDs from MQDs and vice versa.
  126. The Queue-switching process can also happen with the firmware requesting the
  127. preemption or unmapping of a Queue. The firmware waits for the HQD_ACTIVE bit
  128. to change to low before saving the state into the MQD. To make a different
  129. Queue become active, the firmware copies the MQD state into the HQD registers
  130. and loads any additional state. Finally, it sets the HQD_ACTIVE bit to high to
  131. indicate that the queue is active. The Pipe will then execute work from active
  132. Queues.
  133. Driver Structure
  134. ================
  135. In general, the driver has a list of all of the IPs on a particular
  136. SoC and for things like init/fini/suspend/resume, more or less just
  137. walks the list and handles each IP.
  138. Some useful constructs:
  139. KIQ (Kernel Interface Queue)
  140. This is a control queue used by the kernel driver to manage other gfx
  141. and compute queues on the GFX/compute engine. You can use it to
  142. map/unmap additional queues, etc. This is replaced by MES on
  143. GFX 11 and newer hardware.
  144. IB (Indirect Buffer)
  145. A command buffer for a particular engine. Rather than writing
  146. commands directly to the queue, you can write the commands into a
  147. piece of memory and then put a pointer to the memory into the queue.
  148. The hardware will then follow the pointer and execute the commands in
  149. the memory, then returning to the rest of the commands in the ring.
  150. .. _amdgpu_memory_domains:
  151. Memory Domains
  152. ==============
  153. .. kernel-doc:: include/uapi/drm/amdgpu_drm.h
  154. :doc: memory domains
  155. Buffer Objects
  156. ==============
  157. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
  158. :doc: amdgpu_object
  159. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
  160. :internal:
  161. PRIME Buffer Sharing
  162. ====================
  163. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
  164. :doc: PRIME Buffer Sharing
  165. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
  166. :internal:
  167. MMU Notifier
  168. ============
  169. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c
  170. :doc: MMU Notifier
  171. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c
  172. :internal:
  173. AMDGPU Virtual Memory
  174. =====================
  175. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
  176. :doc: GPUVM
  177. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
  178. :internal:
  179. Interrupt Handling
  180. ==================
  181. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
  182. :doc: Interrupt Handling
  183. .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
  184. :internal:
  185. IP Blocks
  186. =========
  187. .. kernel-doc:: drivers/gpu/drm/amd/include/amd_shared.h
  188. :doc: IP Blocks
  189. .. kernel-doc:: drivers/gpu/drm/amd/include/amd_shared.h
  190. :identifiers: amd_ip_block_type amd_ip_funcs DC_FEATURE_MASK DC_DEBUG_MASK