kgd_kfd_interface.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. /*
  23. * This file defines the private interface between the
  24. * AMD kernel graphics drivers and the AMD KFD.
  25. */
  26. #ifndef KGD_KFD_INTERFACE_H_INCLUDED
  27. #define KGD_KFD_INTERFACE_H_INCLUDED
  28. #include <linux/types.h>
  29. #include <linux/bitmap.h>
  30. #include <linux/dma-fence.h>
  31. #include "amdgpu_irq.h"
  32. #include "amdgpu_gfx.h"
  33. struct pci_dev;
  34. struct amdgpu_device;
  35. struct kfd_dev;
  36. struct kgd_mem;
  37. enum kfd_preempt_type {
  38. KFD_PREEMPT_TYPE_WAVEFRONT_DRAIN = 0,
  39. KFD_PREEMPT_TYPE_WAVEFRONT_RESET,
  40. KFD_PREEMPT_TYPE_WAVEFRONT_SAVE
  41. };
  42. struct kfd_vm_fault_info {
  43. uint64_t page_addr;
  44. uint32_t vmid;
  45. uint32_t mc_id;
  46. uint32_t status;
  47. bool prot_valid;
  48. bool prot_read;
  49. bool prot_write;
  50. bool prot_exec;
  51. };
  52. /* For getting GPU local memory information from KGD */
  53. struct kfd_local_mem_info {
  54. uint64_t local_mem_size_private;
  55. uint64_t local_mem_size_public;
  56. uint32_t vram_width;
  57. uint32_t mem_clk_max;
  58. };
  59. enum kgd_memory_pool {
  60. KGD_POOL_SYSTEM_CACHEABLE = 1,
  61. KGD_POOL_SYSTEM_WRITECOMBINE = 2,
  62. KGD_POOL_FRAMEBUFFER = 3,
  63. };
  64. struct kfd_cu_occupancy {
  65. u32 wave_cnt;
  66. u32 doorbell_off;
  67. };
  68. /**
  69. * enum kfd_sched_policy
  70. *
  71. * @KFD_SCHED_POLICY_HWS: H/W scheduling policy known as command processor (cp)
  72. * scheduling. In this scheduling mode we're using the firmware code to
  73. * schedule the user mode queues and kernel queues such as HIQ and DIQ.
  74. * the HIQ queue is used as a special queue that dispatches the configuration
  75. * to the cp and the user mode queues list that are currently running.
  76. * the DIQ queue is a debugging queue that dispatches debugging commands to the
  77. * firmware.
  78. * in this scheduling mode user mode queues over subscription feature is
  79. * enabled.
  80. *
  81. * @KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: The same as above but the over
  82. * subscription feature disabled.
  83. *
  84. * @KFD_SCHED_POLICY_NO_HWS: no H/W scheduling policy is a mode which directly
  85. * set the command processor registers and sets the queues "manually". This
  86. * mode is used *ONLY* for debugging proposes.
  87. *
  88. */
  89. enum kfd_sched_policy {
  90. KFD_SCHED_POLICY_HWS = 0,
  91. KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION,
  92. KFD_SCHED_POLICY_NO_HWS
  93. };
  94. struct kgd2kfd_shared_resources {
  95. /* Bit n == 1 means VMID n is available for KFD. */
  96. unsigned int compute_vmid_bitmap;
  97. /* number of pipes per mec */
  98. uint32_t num_pipe_per_mec;
  99. /* number of queues per pipe */
  100. uint32_t num_queue_per_pipe;
  101. /* Bit n == 1 means Queue n is available for KFD */
  102. DECLARE_BITMAP(cp_queue_bitmap, AMDGPU_MAX_QUEUES);
  103. /* SDMA doorbell assignments (SOC15 and later chips only). Only
  104. * specific doorbells are routed to each SDMA engine. Others
  105. * are routed to IH and VCN. They are not usable by the CP.
  106. */
  107. uint32_t *sdma_doorbell_idx;
  108. /* From SOC15 onward, the doorbell index range not usable for CP
  109. * queues.
  110. */
  111. uint32_t non_cp_doorbells_start;
  112. uint32_t non_cp_doorbells_end;
  113. /* Base address of doorbell aperture. */
  114. phys_addr_t doorbell_physical_address;
  115. /* Size in bytes of doorbell aperture. */
  116. size_t doorbell_aperture_size;
  117. /* Number of bytes at start of aperture reserved for KGD. */
  118. size_t doorbell_start_offset;
  119. /* GPUVM address space size in bytes */
  120. uint64_t gpuvm_size;
  121. /* Minor device number of the render node */
  122. int drm_render_minor;
  123. bool enable_mes;
  124. };
  125. struct tile_config {
  126. uint32_t *tile_config_ptr;
  127. uint32_t *macro_tile_config_ptr;
  128. uint32_t num_tile_configs;
  129. uint32_t num_macro_tile_configs;
  130. uint32_t gb_addr_config;
  131. uint32_t num_banks;
  132. uint32_t num_ranks;
  133. };
  134. #define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT 4096
  135. /**
  136. * struct kfd2kgd_calls
  137. *
  138. * @program_sh_mem_settings: A function that should initiate the memory
  139. * properties such as main aperture memory type (cache / non cached) and
  140. * secondary aperture base address, size and memory type.
  141. * This function is used only for no cp scheduling mode.
  142. *
  143. * @set_pasid_vmid_mapping: Exposes pasid/vmid pair to the H/W for no cp
  144. * scheduling mode. Only used for no cp scheduling mode.
  145. *
  146. * @hqd_load: Loads the mqd structure to a H/W hqd slot. used only for no cp
  147. * sceduling mode.
  148. *
  149. * @hqd_sdma_load: Loads the SDMA mqd structure to a H/W SDMA hqd slot.
  150. * used only for no HWS mode.
  151. *
  152. * @hqd_dump: Dumps CPC HQD registers to an array of address-value pairs.
  153. * Array is allocated with kmalloc, needs to be freed with kfree by caller.
  154. *
  155. * @hqd_sdma_dump: Dumps SDMA HQD registers to an array of address-value pairs.
  156. * Array is allocated with kmalloc, needs to be freed with kfree by caller.
  157. *
  158. * @hqd_is_occupies: Checks if a hqd slot is occupied.
  159. *
  160. * @hqd_destroy: Destructs and preempts the queue assigned to that hqd slot.
  161. *
  162. * @hqd_sdma_is_occupied: Checks if an SDMA hqd slot is occupied.
  163. *
  164. * @hqd_sdma_destroy: Destructs and preempts the SDMA queue assigned to that
  165. * SDMA hqd slot.
  166. *
  167. * @set_scratch_backing_va: Sets VA for scratch backing memory of a VMID.
  168. * Only used for no cp scheduling mode
  169. *
  170. * @set_vm_context_page_table_base: Program page table base for a VMID
  171. *
  172. * @invalidate_tlbs: Invalidate TLBs for a specific PASID
  173. *
  174. * @invalidate_tlbs_vmid: Invalidate TLBs for a specific VMID
  175. *
  176. * @read_vmid_from_vmfault_reg: On Hawaii the VMID is not set in the
  177. * IH ring entry. This function allows the KFD ISR to get the VMID
  178. * from the fault status register as early as possible.
  179. *
  180. * @get_cu_occupancy: Function pointer that returns to caller the number
  181. * of wave fronts that are in flight for all of the queues of a process
  182. * as identified by its pasid. It is important to note that the value
  183. * returned by this function is a snapshot of current moment and cannot
  184. * guarantee any minimum for the number of waves in-flight. This function
  185. * is defined for devices that belong to GFX9 and later GFX families. Care
  186. * must be taken in calling this function as it is not defined for devices
  187. * that belong to GFX8 and below GFX families.
  188. *
  189. * This structure contains function pointers to services that the kgd driver
  190. * provides to amdkfd driver.
  191. *
  192. */
  193. struct kfd2kgd_calls {
  194. /* Register access functions */
  195. void (*program_sh_mem_settings)(struct amdgpu_device *adev, uint32_t vmid,
  196. uint32_t sh_mem_config, uint32_t sh_mem_ape1_base,
  197. uint32_t sh_mem_ape1_limit, uint32_t sh_mem_bases,
  198. uint32_t inst);
  199. int (*set_pasid_vmid_mapping)(struct amdgpu_device *adev, u32 pasid,
  200. unsigned int vmid, uint32_t inst);
  201. int (*init_interrupts)(struct amdgpu_device *adev, uint32_t pipe_id,
  202. uint32_t inst);
  203. int (*hqd_load)(struct amdgpu_device *adev, void *mqd, uint32_t pipe_id,
  204. uint32_t queue_id, uint32_t __user *wptr,
  205. uint32_t wptr_shift, uint32_t wptr_mask,
  206. struct mm_struct *mm, uint32_t inst);
  207. int (*hiq_mqd_load)(struct amdgpu_device *adev, void *mqd,
  208. uint32_t pipe_id, uint32_t queue_id,
  209. uint32_t doorbell_off, uint32_t inst);
  210. int (*hqd_sdma_load)(struct amdgpu_device *adev, void *mqd,
  211. uint32_t __user *wptr, struct mm_struct *mm);
  212. int (*hqd_dump)(struct amdgpu_device *adev,
  213. uint32_t pipe_id, uint32_t queue_id,
  214. uint32_t (**dump)[2], uint32_t *n_regs, uint32_t inst);
  215. int (*hqd_sdma_dump)(struct amdgpu_device *adev,
  216. uint32_t engine_id, uint32_t queue_id,
  217. uint32_t (**dump)[2], uint32_t *n_regs);
  218. bool (*hqd_is_occupied)(struct amdgpu_device *adev,
  219. uint64_t queue_address, uint32_t pipe_id,
  220. uint32_t queue_id, uint32_t inst);
  221. int (*hqd_destroy)(struct amdgpu_device *adev, void *mqd,
  222. enum kfd_preempt_type reset_type,
  223. unsigned int timeout, uint32_t pipe_id,
  224. uint32_t queue_id, uint32_t inst);
  225. bool (*hqd_sdma_is_occupied)(struct amdgpu_device *adev, void *mqd);
  226. int (*hqd_sdma_destroy)(struct amdgpu_device *adev, void *mqd,
  227. unsigned int timeout);
  228. int (*wave_control_execute)(struct amdgpu_device *adev,
  229. uint32_t gfx_index_val,
  230. uint32_t sq_cmd, uint32_t inst);
  231. bool (*get_atc_vmid_pasid_mapping_info)(struct amdgpu_device *adev,
  232. uint8_t vmid,
  233. uint16_t *p_pasid);
  234. /* No longer needed from GFXv9 onward. The scratch base address is
  235. * passed to the shader by the CP. It's the user mode driver's
  236. * responsibility.
  237. */
  238. void (*set_scratch_backing_va)(struct amdgpu_device *adev,
  239. uint64_t va, uint32_t vmid);
  240. void (*set_vm_context_page_table_base)(struct amdgpu_device *adev,
  241. uint32_t vmid, uint64_t page_table_base);
  242. uint32_t (*read_vmid_from_vmfault_reg)(struct amdgpu_device *adev);
  243. uint32_t (*enable_debug_trap)(struct amdgpu_device *adev,
  244. bool restore_dbg_registers,
  245. uint32_t vmid);
  246. uint32_t (*disable_debug_trap)(struct amdgpu_device *adev,
  247. bool keep_trap_enabled,
  248. uint32_t vmid);
  249. int (*validate_trap_override_request)(struct amdgpu_device *adev,
  250. uint32_t trap_override,
  251. uint32_t *trap_mask_supported);
  252. uint32_t (*set_wave_launch_trap_override)(struct amdgpu_device *adev,
  253. uint32_t vmid,
  254. uint32_t trap_override,
  255. uint32_t trap_mask_bits,
  256. uint32_t trap_mask_request,
  257. uint32_t *trap_mask_prev,
  258. uint32_t kfd_dbg_trap_cntl_prev);
  259. uint32_t (*set_wave_launch_mode)(struct amdgpu_device *adev,
  260. uint8_t wave_launch_mode,
  261. uint32_t vmid);
  262. uint32_t (*set_address_watch)(struct amdgpu_device *adev,
  263. uint64_t watch_address,
  264. uint32_t watch_address_mask,
  265. uint32_t watch_id,
  266. uint32_t watch_mode,
  267. uint32_t debug_vmid,
  268. uint32_t inst);
  269. uint32_t (*clear_address_watch)(struct amdgpu_device *adev,
  270. uint32_t watch_id);
  271. void (*get_iq_wait_times)(struct amdgpu_device *adev,
  272. uint32_t *wait_times,
  273. uint32_t inst);
  274. void (*build_grace_period_packet_info)(struct amdgpu_device *adev,
  275. uint32_t wait_times,
  276. uint32_t grace_period,
  277. uint32_t *reg_offset,
  278. uint32_t *reg_data);
  279. void (*get_cu_occupancy)(struct amdgpu_device *adev,
  280. struct kfd_cu_occupancy *cu_occupancy,
  281. int *max_waves_per_cu, uint32_t inst);
  282. void (*program_trap_handler_settings)(struct amdgpu_device *adev,
  283. uint32_t vmid, uint64_t tba_addr, uint64_t tma_addr,
  284. uint32_t inst);
  285. uint64_t (*hqd_get_pq_addr)(struct amdgpu_device *adev,
  286. uint32_t pipe_id, uint32_t queue_id,
  287. uint32_t inst);
  288. uint64_t (*hqd_reset)(struct amdgpu_device *adev,
  289. uint32_t pipe_id, uint32_t queue_id,
  290. uint32_t inst, unsigned int utimeout);
  291. };
  292. #endif /* KGD_KFD_INTERFACE_H_INCLUDED */