amdgpu_gfx.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. #ifndef __AMDGPU_GFX_H__
  24. #define __AMDGPU_GFX_H__
  25. /*
  26. * GFX stuff
  27. */
  28. #include "clearstate_defs.h"
  29. #include "amdgpu_ring.h"
  30. /* GFX current status */
  31. #define AMDGPU_GFX_NORMAL_MODE 0x00000000L
  32. #define AMDGPU_GFX_SAFE_MODE 0x00000001L
  33. #define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
  34. #define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
  35. #define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
  36. struct amdgpu_rlc_funcs {
  37. void (*enter_safe_mode)(struct amdgpu_device *adev);
  38. void (*exit_safe_mode)(struct amdgpu_device *adev);
  39. };
  40. struct amdgpu_rlc {
  41. /* for power gating */
  42. struct amdgpu_bo *save_restore_obj;
  43. uint64_t save_restore_gpu_addr;
  44. volatile uint32_t *sr_ptr;
  45. const u32 *reg_list;
  46. u32 reg_list_size;
  47. /* for clear state */
  48. struct amdgpu_bo *clear_state_obj;
  49. uint64_t clear_state_gpu_addr;
  50. volatile uint32_t *cs_ptr;
  51. const struct cs_section_def *cs_data;
  52. u32 clear_state_size;
  53. /* for cp tables */
  54. struct amdgpu_bo *cp_table_obj;
  55. uint64_t cp_table_gpu_addr;
  56. volatile uint32_t *cp_table_ptr;
  57. u32 cp_table_size;
  58. /* safe mode for updating CG/PG state */
  59. bool in_safe_mode;
  60. const struct amdgpu_rlc_funcs *funcs;
  61. /* for firmware data */
  62. u32 save_and_restore_offset;
  63. u32 clear_state_descriptor_offset;
  64. u32 avail_scratch_ram_locations;
  65. u32 reg_restore_list_size;
  66. u32 reg_list_format_start;
  67. u32 reg_list_format_separate_start;
  68. u32 starting_offsets_start;
  69. u32 reg_list_format_size_bytes;
  70. u32 reg_list_size_bytes;
  71. u32 reg_list_format_direct_reg_list_length;
  72. u32 save_restore_list_cntl_size_bytes;
  73. u32 save_restore_list_gpm_size_bytes;
  74. u32 save_restore_list_srm_size_bytes;
  75. u32 *register_list_format;
  76. u32 *register_restore;
  77. u8 *save_restore_list_cntl;
  78. u8 *save_restore_list_gpm;
  79. u8 *save_restore_list_srm;
  80. bool is_rlc_v2_1;
  81. };
  82. #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
  83. struct amdgpu_mec {
  84. struct amdgpu_bo *hpd_eop_obj;
  85. u64 hpd_eop_gpu_addr;
  86. struct amdgpu_bo *mec_fw_obj;
  87. u64 mec_fw_gpu_addr;
  88. u32 num_mec;
  89. u32 num_pipe_per_mec;
  90. u32 num_queue_per_pipe;
  91. void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
  92. /* These are the resources for which amdgpu takes ownership */
  93. DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  94. };
  95. struct amdgpu_kiq {
  96. u64 eop_gpu_addr;
  97. struct amdgpu_bo *eop_obj;
  98. spinlock_t ring_lock;
  99. struct amdgpu_ring ring;
  100. struct amdgpu_irq_src irq;
  101. };
  102. /*
  103. * GPU scratch registers structures, functions & helpers
  104. */
  105. struct amdgpu_scratch {
  106. unsigned num_reg;
  107. uint32_t reg_base;
  108. uint32_t free_mask;
  109. };
  110. /*
  111. * GFX configurations
  112. */
  113. #define AMDGPU_GFX_MAX_SE 4
  114. #define AMDGPU_GFX_MAX_SH_PER_SE 2
  115. struct amdgpu_rb_config {
  116. uint32_t rb_backend_disable;
  117. uint32_t user_rb_backend_disable;
  118. uint32_t raster_config;
  119. uint32_t raster_config_1;
  120. };
  121. struct gb_addr_config {
  122. uint16_t pipe_interleave_size;
  123. uint8_t num_pipes;
  124. uint8_t max_compress_frags;
  125. uint8_t num_banks;
  126. uint8_t num_se;
  127. uint8_t num_rb_per_se;
  128. };
  129. struct amdgpu_gfx_config {
  130. unsigned max_shader_engines;
  131. unsigned max_tile_pipes;
  132. unsigned max_cu_per_sh;
  133. unsigned max_sh_per_se;
  134. unsigned max_backends_per_se;
  135. unsigned max_texture_channel_caches;
  136. unsigned max_gprs;
  137. unsigned max_gs_threads;
  138. unsigned max_hw_contexts;
  139. unsigned sc_prim_fifo_size_frontend;
  140. unsigned sc_prim_fifo_size_backend;
  141. unsigned sc_hiz_tile_fifo_size;
  142. unsigned sc_earlyz_tile_fifo_size;
  143. unsigned num_tile_pipes;
  144. unsigned backend_enable_mask;
  145. unsigned mem_max_burst_length_bytes;
  146. unsigned mem_row_size_in_kb;
  147. unsigned shader_engine_tile_size;
  148. unsigned num_gpus;
  149. unsigned multi_gpu_tile_size;
  150. unsigned mc_arb_ramcfg;
  151. unsigned gb_addr_config;
  152. unsigned num_rbs;
  153. unsigned gs_vgt_table_depth;
  154. unsigned gs_prim_buffer_depth;
  155. uint32_t tile_mode_array[32];
  156. uint32_t macrotile_mode_array[16];
  157. struct gb_addr_config gb_addr_config_fields;
  158. struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
  159. /* gfx configure feature */
  160. uint32_t double_offchip_lds_buf;
  161. /* cached value of DB_DEBUG2 */
  162. uint32_t db_debug2;
  163. };
  164. struct amdgpu_cu_info {
  165. uint32_t simd_per_cu;
  166. uint32_t max_waves_per_simd;
  167. uint32_t wave_front_size;
  168. uint32_t max_scratch_slots_per_cu;
  169. uint32_t lds_size;
  170. /* total active CU number */
  171. uint32_t number;
  172. uint32_t ao_cu_mask;
  173. uint32_t ao_cu_bitmap[4][4];
  174. uint32_t bitmap[4][4];
  175. };
  176. struct amdgpu_gfx_funcs {
  177. /* get the gpu clock counter */
  178. uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
  179. void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num,
  180. u32 sh_num, u32 instance);
  181. void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd,
  182. uint32_t wave, uint32_t *dst, int *no_fields);
  183. void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd,
  184. uint32_t wave, uint32_t thread, uint32_t start,
  185. uint32_t size, uint32_t *dst);
  186. void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd,
  187. uint32_t wave, uint32_t start, uint32_t size,
  188. uint32_t *dst);
  189. void (*select_me_pipe_q)(struct amdgpu_device *adev, u32 me, u32 pipe,
  190. u32 queue);
  191. };
  192. struct amdgpu_ngg_buf {
  193. struct amdgpu_bo *bo;
  194. uint64_t gpu_addr;
  195. uint32_t size;
  196. uint32_t bo_size;
  197. };
  198. enum {
  199. NGG_PRIM = 0,
  200. NGG_POS,
  201. NGG_CNTL,
  202. NGG_PARAM,
  203. NGG_BUF_MAX
  204. };
  205. struct amdgpu_ngg {
  206. struct amdgpu_ngg_buf buf[NGG_BUF_MAX];
  207. uint32_t gds_reserve_addr;
  208. uint32_t gds_reserve_size;
  209. bool init;
  210. };
  211. struct sq_work {
  212. struct work_struct work;
  213. unsigned ih_data;
  214. };
  215. struct amdgpu_gfx {
  216. struct mutex gpu_clock_mutex;
  217. struct amdgpu_gfx_config config;
  218. struct amdgpu_rlc rlc;
  219. struct amdgpu_mec mec;
  220. struct amdgpu_kiq kiq;
  221. struct amdgpu_scratch scratch;
  222. const struct firmware *me_fw; /* ME firmware */
  223. uint32_t me_fw_version;
  224. const struct firmware *pfp_fw; /* PFP firmware */
  225. uint32_t pfp_fw_version;
  226. const struct firmware *ce_fw; /* CE firmware */
  227. uint32_t ce_fw_version;
  228. const struct firmware *rlc_fw; /* RLC firmware */
  229. uint32_t rlc_fw_version;
  230. const struct firmware *mec_fw; /* MEC firmware */
  231. uint32_t mec_fw_version;
  232. const struct firmware *mec2_fw; /* MEC2 firmware */
  233. uint32_t mec2_fw_version;
  234. uint32_t me_feature_version;
  235. uint32_t ce_feature_version;
  236. uint32_t pfp_feature_version;
  237. uint32_t rlc_feature_version;
  238. uint32_t rlc_srlc_fw_version;
  239. uint32_t rlc_srlc_feature_version;
  240. uint32_t rlc_srlg_fw_version;
  241. uint32_t rlc_srlg_feature_version;
  242. uint32_t rlc_srls_fw_version;
  243. uint32_t rlc_srls_feature_version;
  244. uint32_t mec_feature_version;
  245. uint32_t mec2_feature_version;
  246. bool mec_fw_write_wait;
  247. bool me_fw_write_wait;
  248. struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
  249. unsigned num_gfx_rings;
  250. struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
  251. unsigned num_compute_rings;
  252. struct amdgpu_irq_src eop_irq;
  253. struct amdgpu_irq_src priv_reg_irq;
  254. struct amdgpu_irq_src priv_inst_irq;
  255. struct amdgpu_irq_src cp_ecc_error_irq;
  256. struct amdgpu_irq_src sq_irq;
  257. struct sq_work sq_work;
  258. /* gfx status */
  259. uint32_t gfx_current_status;
  260. /* ce ram size*/
  261. unsigned ce_ram_size;
  262. struct amdgpu_cu_info cu_info;
  263. const struct amdgpu_gfx_funcs *funcs;
  264. /* reset mask */
  265. uint32_t grbm_soft_reset;
  266. uint32_t srbm_soft_reset;
  267. /* NGG */
  268. struct amdgpu_ngg ngg;
  269. /* gfx off */
  270. bool gfx_off_state; /* true: enabled, false: disabled */
  271. struct mutex gfx_off_mutex;
  272. uint32_t gfx_off_req_count; /* default 1, enable gfx off: dec 1, disable gfx off: add 1 */
  273. struct delayed_work gfx_off_delay_work;
  274. /* pipe reservation */
  275. struct mutex pipe_reserve_mutex;
  276. DECLARE_BITMAP (pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  277. };
  278. #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
  279. #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
  280. #define amdgpu_gfx_select_me_pipe_q(adev, me, pipe, q) (adev)->gfx.funcs->select_me_pipe_q((adev), (me), (pipe), (q))
  281. /**
  282. * amdgpu_gfx_create_bitmask - create a bitmask
  283. *
  284. * @bit_width: length of the mask
  285. *
  286. * create a variable length bit mask.
  287. * Returns the bitmask.
  288. */
  289. static inline u32 amdgpu_gfx_create_bitmask(u32 bit_width)
  290. {
  291. return (u32)((1ULL << bit_width) - 1);
  292. }
  293. int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg);
  294. void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg);
  295. void amdgpu_gfx_parse_disable_cu(unsigned *mask, unsigned max_se,
  296. unsigned max_sh);
  297. int amdgpu_gfx_kiq_init_ring(struct amdgpu_device *adev,
  298. struct amdgpu_ring *ring,
  299. struct amdgpu_irq_src *irq);
  300. void amdgpu_gfx_kiq_free_ring(struct amdgpu_ring *ring,
  301. struct amdgpu_irq_src *irq);
  302. void amdgpu_gfx_kiq_fini(struct amdgpu_device *adev);
  303. int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,
  304. unsigned hpd_size);
  305. int amdgpu_gfx_compute_mqd_sw_init(struct amdgpu_device *adev,
  306. unsigned mqd_size);
  307. void amdgpu_gfx_compute_mqd_sw_fini(struct amdgpu_device *adev);
  308. void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev);
  309. int amdgpu_gfx_queue_to_bit(struct amdgpu_device *adev, int mec,
  310. int pipe, int queue);
  311. void amdgpu_gfx_bit_to_queue(struct amdgpu_device *adev, int bit,
  312. int *mec, int *pipe, int *queue);
  313. bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int mec,
  314. int pipe, int queue);
  315. void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev, bool enable);
  316. #endif