amdgpu.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #ifndef __AMDGPU_H__
  29. #define __AMDGPU_H__
  30. #include "amdgpu_ctx.h"
  31. #include <linux/atomic.h>
  32. #include <linux/wait.h>
  33. #include <linux/list.h>
  34. #include <linux/kref.h>
  35. #include <linux/rbtree.h>
  36. #include <linux/hashtable.h>
  37. #include <linux/dma-fence.h>
  38. #include <drm/ttm/ttm_bo_api.h>
  39. #include <drm/ttm/ttm_bo_driver.h>
  40. #include <drm/ttm/ttm_placement.h>
  41. #include <drm/ttm/ttm_module.h>
  42. #include <drm/ttm/ttm_execbuf_util.h>
  43. #include <drm/drmP.h>
  44. #include <drm/drm_gem.h>
  45. #include <drm/amdgpu_drm.h>
  46. #include <drm/gpu_scheduler.h>
  47. #include <kgd_kfd_interface.h>
  48. #include "dm_pp_interface.h"
  49. #include "kgd_pp_interface.h"
  50. #include "amd_shared.h"
  51. #include "amdgpu_mode.h"
  52. #include "amdgpu_ih.h"
  53. #include "amdgpu_irq.h"
  54. #include "amdgpu_ucode.h"
  55. #include "amdgpu_ttm.h"
  56. #include "amdgpu_psp.h"
  57. #include "amdgpu_gds.h"
  58. #include "amdgpu_sync.h"
  59. #include "amdgpu_ring.h"
  60. #include "amdgpu_vm.h"
  61. #include "amdgpu_dpm.h"
  62. #include "amdgpu_acp.h"
  63. #include "amdgpu_uvd.h"
  64. #include "amdgpu_vce.h"
  65. #include "amdgpu_vcn.h"
  66. #include "amdgpu_mn.h"
  67. #include "amdgpu_gmc.h"
  68. #include "amdgpu_gfx.h"
  69. #include "amdgpu_sdma.h"
  70. #include "amdgpu_dm.h"
  71. #include "amdgpu_virt.h"
  72. #include "amdgpu_gart.h"
  73. #include "amdgpu_debugfs.h"
  74. #include "amdgpu_job.h"
  75. #include "amdgpu_bo_list.h"
  76. #include "amdgpu_gem.h"
  77. #define MAX_GPU_INSTANCE 16
  78. struct amdgpu_gpu_instance
  79. {
  80. struct amdgpu_device *adev;
  81. int mgpu_fan_enabled;
  82. };
  83. struct amdgpu_mgpu_info
  84. {
  85. struct amdgpu_gpu_instance gpu_ins[MAX_GPU_INSTANCE];
  86. struct mutex mutex;
  87. uint32_t num_gpu;
  88. uint32_t num_dgpu;
  89. uint32_t num_apu;
  90. };
  91. /*
  92. * Modules parameters.
  93. */
  94. extern int amdgpu_modeset;
  95. extern int amdgpu_vram_limit;
  96. extern int amdgpu_vis_vram_limit;
  97. extern int amdgpu_gart_size;
  98. extern int amdgpu_gtt_size;
  99. extern int amdgpu_moverate;
  100. extern int amdgpu_benchmarking;
  101. extern int amdgpu_testing;
  102. extern int amdgpu_audio;
  103. extern int amdgpu_disp_priority;
  104. extern int amdgpu_hw_i2c;
  105. extern int amdgpu_pcie_gen2;
  106. extern int amdgpu_msi;
  107. extern int amdgpu_lockup_timeout;
  108. extern int amdgpu_dpm;
  109. extern int amdgpu_fw_load_type;
  110. extern int amdgpu_aspm;
  111. extern int amdgpu_runtime_pm;
  112. extern uint amdgpu_ip_block_mask;
  113. extern int amdgpu_bapm;
  114. extern int amdgpu_deep_color;
  115. extern int amdgpu_vm_size;
  116. extern int amdgpu_vm_block_size;
  117. extern int amdgpu_vm_fragment_size;
  118. extern int amdgpu_vm_fault_stop;
  119. extern int amdgpu_vm_debug;
  120. extern int amdgpu_vm_update_mode;
  121. extern int amdgpu_dc;
  122. extern int amdgpu_sched_jobs;
  123. extern int amdgpu_sched_hw_submission;
  124. extern uint amdgpu_pcie_gen_cap;
  125. extern uint amdgpu_pcie_lane_cap;
  126. extern uint amdgpu_cg_mask;
  127. extern uint amdgpu_pg_mask;
  128. extern uint amdgpu_sdma_phase_quantum;
  129. extern char *amdgpu_disable_cu;
  130. extern char *amdgpu_virtual_display;
  131. extern uint amdgpu_pp_feature_mask;
  132. extern int amdgpu_vram_page_split;
  133. extern int amdgpu_ngg;
  134. extern int amdgpu_prim_buf_per_se;
  135. extern int amdgpu_pos_buf_per_se;
  136. extern int amdgpu_cntl_sb_buf_per_se;
  137. extern int amdgpu_param_buf_per_se;
  138. extern int amdgpu_job_hang_limit;
  139. extern int amdgpu_lbpw;
  140. extern int amdgpu_compute_multipipe;
  141. extern int amdgpu_gpu_recovery;
  142. extern int amdgpu_emu_mode;
  143. extern uint amdgpu_smu_memory_pool_size;
  144. extern struct amdgpu_mgpu_info mgpu_info;
  145. #ifdef CONFIG_DRM_AMDGPU_SI
  146. extern int amdgpu_si_support;
  147. #endif
  148. #ifdef CONFIG_DRM_AMDGPU_CIK
  149. extern int amdgpu_cik_support;
  150. #endif
  151. #define AMDGPU_SG_THRESHOLD (256*1024*1024)
  152. #define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */
  153. #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
  154. #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  155. #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  156. /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
  157. #define AMDGPU_IB_POOL_SIZE 16
  158. #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
  159. #define AMDGPUFB_CONN_LIMIT 4
  160. #define AMDGPU_BIOS_NUM_SCRATCH 16
  161. /* hard reset data */
  162. #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
  163. /* reset flags */
  164. #define AMDGPU_RESET_GFX (1 << 0)
  165. #define AMDGPU_RESET_COMPUTE (1 << 1)
  166. #define AMDGPU_RESET_DMA (1 << 2)
  167. #define AMDGPU_RESET_CP (1 << 3)
  168. #define AMDGPU_RESET_GRBM (1 << 4)
  169. #define AMDGPU_RESET_DMA1 (1 << 5)
  170. #define AMDGPU_RESET_RLC (1 << 6)
  171. #define AMDGPU_RESET_SEM (1 << 7)
  172. #define AMDGPU_RESET_IH (1 << 8)
  173. #define AMDGPU_RESET_VMC (1 << 9)
  174. #define AMDGPU_RESET_MC (1 << 10)
  175. #define AMDGPU_RESET_DISPLAY (1 << 11)
  176. #define AMDGPU_RESET_UVD (1 << 12)
  177. #define AMDGPU_RESET_VCE (1 << 13)
  178. #define AMDGPU_RESET_VCE1 (1 << 14)
  179. /* max cursor sizes (in pixels) */
  180. #define CIK_CURSOR_WIDTH 128
  181. #define CIK_CURSOR_HEIGHT 128
  182. struct amdgpu_device;
  183. struct amdgpu_ib;
  184. struct amdgpu_cs_parser;
  185. struct amdgpu_job;
  186. struct amdgpu_irq_src;
  187. struct amdgpu_fpriv;
  188. struct amdgpu_bo_va_mapping;
  189. struct amdgpu_atif;
  190. enum amdgpu_cp_irq {
  191. AMDGPU_CP_IRQ_GFX_EOP = 0,
  192. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
  193. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
  194. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
  195. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
  196. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
  197. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
  198. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
  199. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
  200. AMDGPU_CP_IRQ_LAST
  201. };
  202. enum amdgpu_thermal_irq {
  203. AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
  204. AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
  205. AMDGPU_THERMAL_IRQ_LAST
  206. };
  207. enum amdgpu_kiq_irq {
  208. AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
  209. AMDGPU_CP_KIQ_IRQ_LAST
  210. };
  211. #define MAX_KIQ_REG_WAIT 5000 /* in usecs, 5ms */
  212. #define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */
  213. #define MAX_KIQ_REG_TRY 20
  214. int amdgpu_device_ip_set_clockgating_state(void *dev,
  215. enum amd_ip_block_type block_type,
  216. enum amd_clockgating_state state);
  217. int amdgpu_device_ip_set_powergating_state(void *dev,
  218. enum amd_ip_block_type block_type,
  219. enum amd_powergating_state state);
  220. void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
  221. u32 *flags);
  222. int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
  223. enum amd_ip_block_type block_type);
  224. bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
  225. enum amd_ip_block_type block_type);
  226. #define AMDGPU_MAX_IP_NUM 16
  227. struct amdgpu_ip_block_status {
  228. bool valid;
  229. bool sw;
  230. bool hw;
  231. bool late_initialized;
  232. bool hang;
  233. };
  234. struct amdgpu_ip_block_version {
  235. const enum amd_ip_block_type type;
  236. const u32 major;
  237. const u32 minor;
  238. const u32 rev;
  239. const struct amd_ip_funcs *funcs;
  240. };
  241. struct amdgpu_ip_block {
  242. struct amdgpu_ip_block_status status;
  243. const struct amdgpu_ip_block_version *version;
  244. };
  245. int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
  246. enum amd_ip_block_type type,
  247. u32 major, u32 minor);
  248. struct amdgpu_ip_block *
  249. amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
  250. enum amd_ip_block_type type);
  251. int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
  252. const struct amdgpu_ip_block_version *ip_block_version);
  253. /*
  254. * BIOS.
  255. */
  256. bool amdgpu_get_bios(struct amdgpu_device *adev);
  257. bool amdgpu_read_bios(struct amdgpu_device *adev);
  258. /*
  259. * Clocks
  260. */
  261. #define AMDGPU_MAX_PPLL 3
  262. struct amdgpu_clock {
  263. struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
  264. struct amdgpu_pll spll;
  265. struct amdgpu_pll mpll;
  266. /* 10 Khz units */
  267. uint32_t default_mclk;
  268. uint32_t default_sclk;
  269. uint32_t default_dispclk;
  270. uint32_t current_dispclk;
  271. uint32_t dp_extclk;
  272. uint32_t max_pixel_clock;
  273. };
  274. /* sub-allocation manager, it has to be protected by another lock.
  275. * By conception this is an helper for other part of the driver
  276. * like the indirect buffer or semaphore, which both have their
  277. * locking.
  278. *
  279. * Principe is simple, we keep a list of sub allocation in offset
  280. * order (first entry has offset == 0, last entry has the highest
  281. * offset).
  282. *
  283. * When allocating new object we first check if there is room at
  284. * the end total_size - (last_object_offset + last_object_size) >=
  285. * alloc_size. If so we allocate new object there.
  286. *
  287. * When there is not enough room at the end, we start waiting for
  288. * each sub object until we reach object_offset+object_size >=
  289. * alloc_size, this object then become the sub object we return.
  290. *
  291. * Alignment can't be bigger than page size.
  292. *
  293. * Hole are not considered for allocation to keep things simple.
  294. * Assumption is that there won't be hole (all object on same
  295. * alignment).
  296. */
  297. #define AMDGPU_SA_NUM_FENCE_LISTS 32
  298. struct amdgpu_sa_manager {
  299. wait_queue_head_t wq;
  300. struct amdgpu_bo *bo;
  301. struct list_head *hole;
  302. struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
  303. struct list_head olist;
  304. unsigned size;
  305. uint64_t gpu_addr;
  306. void *cpu_ptr;
  307. uint32_t domain;
  308. uint32_t align;
  309. };
  310. /* sub-allocation buffer */
  311. struct amdgpu_sa_bo {
  312. struct list_head olist;
  313. struct list_head flist;
  314. struct amdgpu_sa_manager *manager;
  315. unsigned soffset;
  316. unsigned eoffset;
  317. struct dma_fence *fence;
  318. };
  319. int amdgpu_fence_slab_init(void);
  320. void amdgpu_fence_slab_fini(void);
  321. /*
  322. * GPU doorbell structures, functions & helpers
  323. */
  324. typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
  325. {
  326. AMDGPU_DOORBELL_KIQ = 0x000,
  327. AMDGPU_DOORBELL_HIQ = 0x001,
  328. AMDGPU_DOORBELL_DIQ = 0x002,
  329. AMDGPU_DOORBELL_MEC_RING0 = 0x010,
  330. AMDGPU_DOORBELL_MEC_RING1 = 0x011,
  331. AMDGPU_DOORBELL_MEC_RING2 = 0x012,
  332. AMDGPU_DOORBELL_MEC_RING3 = 0x013,
  333. AMDGPU_DOORBELL_MEC_RING4 = 0x014,
  334. AMDGPU_DOORBELL_MEC_RING5 = 0x015,
  335. AMDGPU_DOORBELL_MEC_RING6 = 0x016,
  336. AMDGPU_DOORBELL_MEC_RING7 = 0x017,
  337. AMDGPU_DOORBELL_GFX_RING0 = 0x020,
  338. AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
  339. AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
  340. AMDGPU_DOORBELL_IH = 0x1E8,
  341. AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
  342. AMDGPU_DOORBELL_INVALID = 0xFFFF
  343. } AMDGPU_DOORBELL_ASSIGNMENT;
  344. struct amdgpu_doorbell {
  345. /* doorbell mmio */
  346. resource_size_t base;
  347. resource_size_t size;
  348. u32 __iomem *ptr;
  349. u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
  350. };
  351. /*
  352. * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
  353. */
  354. typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
  355. {
  356. /*
  357. * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
  358. * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
  359. * Compute related doorbells are allocated from 0x00 to 0x8a
  360. */
  361. /* kernel scheduling */
  362. AMDGPU_DOORBELL64_KIQ = 0x00,
  363. /* HSA interface queue and debug queue */
  364. AMDGPU_DOORBELL64_HIQ = 0x01,
  365. AMDGPU_DOORBELL64_DIQ = 0x02,
  366. /* Compute engines */
  367. AMDGPU_DOORBELL64_MEC_RING0 = 0x03,
  368. AMDGPU_DOORBELL64_MEC_RING1 = 0x04,
  369. AMDGPU_DOORBELL64_MEC_RING2 = 0x05,
  370. AMDGPU_DOORBELL64_MEC_RING3 = 0x06,
  371. AMDGPU_DOORBELL64_MEC_RING4 = 0x07,
  372. AMDGPU_DOORBELL64_MEC_RING5 = 0x08,
  373. AMDGPU_DOORBELL64_MEC_RING6 = 0x09,
  374. AMDGPU_DOORBELL64_MEC_RING7 = 0x0a,
  375. /* User queue doorbell range (128 doorbells) */
  376. AMDGPU_DOORBELL64_USERQUEUE_START = 0x0b,
  377. AMDGPU_DOORBELL64_USERQUEUE_END = 0x8a,
  378. /* Graphics engine */
  379. AMDGPU_DOORBELL64_GFX_RING0 = 0x8b,
  380. /*
  381. * Other graphics doorbells can be allocated here: from 0x8c to 0xdf
  382. * Graphics voltage island aperture 1
  383. * default non-graphics QWORD index is 0xe0 - 0xFF inclusive
  384. */
  385. /* sDMA engines reserved from 0xe0 -oxef */
  386. AMDGPU_DOORBELL64_sDMA_ENGINE0 = 0xE0,
  387. AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xE1,
  388. AMDGPU_DOORBELL64_sDMA_ENGINE1 = 0xE8,
  389. AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xE9,
  390. /* For vega10 sriov, the sdma doorbell must be fixed as follow
  391. * to keep the same setting with host driver, or it will
  392. * happen conflicts
  393. */
  394. AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0 = 0xF0,
  395. AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
  396. AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1 = 0xF2,
  397. AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
  398. /* Interrupt handler */
  399. AMDGPU_DOORBELL64_IH = 0xF4, /* For legacy interrupt ring buffer */
  400. AMDGPU_DOORBELL64_IH_RING1 = 0xF5, /* For page migration request log */
  401. AMDGPU_DOORBELL64_IH_RING2 = 0xF6, /* For page migration translation/invalidation log */
  402. /* VCN engine use 32 bits doorbell */
  403. AMDGPU_DOORBELL64_VCN0_1 = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
  404. AMDGPU_DOORBELL64_VCN2_3 = 0xF9,
  405. AMDGPU_DOORBELL64_VCN4_5 = 0xFA,
  406. AMDGPU_DOORBELL64_VCN6_7 = 0xFB,
  407. /* overlap the doorbell assignment with VCN as they are mutually exclusive
  408. * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
  409. */
  410. AMDGPU_DOORBELL64_UVD_RING0_1 = 0xF8,
  411. AMDGPU_DOORBELL64_UVD_RING2_3 = 0xF9,
  412. AMDGPU_DOORBELL64_UVD_RING4_5 = 0xFA,
  413. AMDGPU_DOORBELL64_UVD_RING6_7 = 0xFB,
  414. AMDGPU_DOORBELL64_VCE_RING0_1 = 0xFC,
  415. AMDGPU_DOORBELL64_VCE_RING2_3 = 0xFD,
  416. AMDGPU_DOORBELL64_VCE_RING4_5 = 0xFE,
  417. AMDGPU_DOORBELL64_VCE_RING6_7 = 0xFF,
  418. AMDGPU_DOORBELL64_MAX_ASSIGNMENT = 0xFF,
  419. AMDGPU_DOORBELL64_INVALID = 0xFFFF
  420. } AMDGPU_DOORBELL64_ASSIGNMENT;
  421. /*
  422. * IRQS.
  423. */
  424. struct amdgpu_flip_work {
  425. struct delayed_work flip_work;
  426. struct work_struct unpin_work;
  427. struct amdgpu_device *adev;
  428. int crtc_id;
  429. u32 target_vblank;
  430. uint64_t base;
  431. struct drm_pending_vblank_event *event;
  432. struct amdgpu_bo *old_abo;
  433. struct dma_fence *excl;
  434. unsigned shared_count;
  435. struct dma_fence **shared;
  436. struct dma_fence_cb cb;
  437. bool async;
  438. };
  439. /*
  440. * CP & rings.
  441. */
  442. struct amdgpu_ib {
  443. struct amdgpu_sa_bo *sa_bo;
  444. uint32_t length_dw;
  445. uint64_t gpu_addr;
  446. uint32_t *ptr;
  447. uint32_t flags;
  448. };
  449. extern const struct drm_sched_backend_ops amdgpu_sched_ops;
  450. /*
  451. * file private structure
  452. */
  453. struct amdgpu_fpriv {
  454. struct amdgpu_vm vm;
  455. struct amdgpu_bo_va *prt_va;
  456. struct amdgpu_bo_va *csa_va;
  457. struct mutex bo_list_lock;
  458. struct idr bo_list_handles;
  459. struct amdgpu_ctx_mgr ctx_mgr;
  460. };
  461. int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  462. unsigned size, struct amdgpu_ib *ib);
  463. void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
  464. struct dma_fence *f);
  465. int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
  466. struct amdgpu_ib *ibs, struct amdgpu_job *job,
  467. struct dma_fence **f);
  468. int amdgpu_ib_pool_init(struct amdgpu_device *adev);
  469. void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
  470. int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
  471. /*
  472. * CS.
  473. */
  474. struct amdgpu_cs_chunk {
  475. uint32_t chunk_id;
  476. uint32_t length_dw;
  477. void *kdata;
  478. };
  479. struct amdgpu_cs_parser {
  480. struct amdgpu_device *adev;
  481. struct drm_file *filp;
  482. struct amdgpu_ctx *ctx;
  483. /* chunks */
  484. unsigned nchunks;
  485. struct amdgpu_cs_chunk *chunks;
  486. /* scheduler job object */
  487. struct amdgpu_job *job;
  488. struct drm_sched_entity *entity;
  489. /* buffer objects */
  490. struct ww_acquire_ctx ticket;
  491. struct amdgpu_bo_list *bo_list;
  492. struct amdgpu_mn *mn;
  493. struct amdgpu_bo_list_entry vm_pd;
  494. struct list_head validated;
  495. struct dma_fence *fence;
  496. uint64_t bytes_moved_threshold;
  497. uint64_t bytes_moved_vis_threshold;
  498. uint64_t bytes_moved;
  499. uint64_t bytes_moved_vis;
  500. struct amdgpu_bo_list_entry *evictable;
  501. /* user fence */
  502. struct amdgpu_bo_list_entry uf_entry;
  503. unsigned num_post_dep_syncobjs;
  504. struct drm_syncobj **post_dep_syncobjs;
  505. };
  506. static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
  507. uint32_t ib_idx, int idx)
  508. {
  509. return p->job->ibs[ib_idx].ptr[idx];
  510. }
  511. static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
  512. uint32_t ib_idx, int idx,
  513. uint32_t value)
  514. {
  515. p->job->ibs[ib_idx].ptr[idx] = value;
  516. }
  517. /*
  518. * Writeback
  519. */
  520. #define AMDGPU_MAX_WB 128 /* Reserve at most 128 WB slots for amdgpu-owned rings. */
  521. struct amdgpu_wb {
  522. struct amdgpu_bo *wb_obj;
  523. volatile uint32_t *wb;
  524. uint64_t gpu_addr;
  525. u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
  526. unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
  527. };
  528. int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
  529. void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
  530. /*
  531. * Benchmarking
  532. */
  533. void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
  534. /*
  535. * Testing
  536. */
  537. void amdgpu_test_moves(struct amdgpu_device *adev);
  538. /*
  539. * ASIC specific register table accessible by UMD
  540. */
  541. struct amdgpu_allowed_register_entry {
  542. uint32_t reg_offset;
  543. bool grbm_indexed;
  544. };
  545. /*
  546. * ASIC specific functions.
  547. */
  548. struct amdgpu_asic_funcs {
  549. bool (*read_disabled_bios)(struct amdgpu_device *adev);
  550. bool (*read_bios_from_rom)(struct amdgpu_device *adev,
  551. u8 *bios, u32 length_bytes);
  552. int (*read_register)(struct amdgpu_device *adev, u32 se_num,
  553. u32 sh_num, u32 reg_offset, u32 *value);
  554. void (*set_vga_state)(struct amdgpu_device *adev, bool state);
  555. int (*reset)(struct amdgpu_device *adev);
  556. /* get the reference clock */
  557. u32 (*get_xclk)(struct amdgpu_device *adev);
  558. /* MM block clocks */
  559. int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
  560. int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
  561. /* static power management */
  562. int (*get_pcie_lanes)(struct amdgpu_device *adev);
  563. void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
  564. /* get config memsize register */
  565. u32 (*get_config_memsize)(struct amdgpu_device *adev);
  566. /* flush hdp write queue */
  567. void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
  568. /* invalidate hdp read cache */
  569. void (*invalidate_hdp)(struct amdgpu_device *adev,
  570. struct amdgpu_ring *ring);
  571. /* check if the asic needs a full reset of if soft reset will work */
  572. bool (*need_full_reset)(struct amdgpu_device *adev);
  573. };
  574. /*
  575. * IOCTL.
  576. */
  577. int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
  578. struct drm_file *filp);
  579. int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  580. int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
  581. struct drm_file *filp);
  582. int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  583. int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
  584. struct drm_file *filp);
  585. /* VRAM scratch page for HDP bug, default vram page */
  586. struct amdgpu_vram_scratch {
  587. struct amdgpu_bo *robj;
  588. volatile uint32_t *ptr;
  589. u64 gpu_addr;
  590. };
  591. /*
  592. * ACPI
  593. */
  594. struct amdgpu_atcs_functions {
  595. bool get_ext_state;
  596. bool pcie_perf_req;
  597. bool pcie_dev_rdy;
  598. bool pcie_bus_width;
  599. };
  600. struct amdgpu_atcs {
  601. struct amdgpu_atcs_functions functions;
  602. };
  603. /*
  604. * Firmware VRAM reservation
  605. */
  606. struct amdgpu_fw_vram_usage {
  607. u64 start_offset;
  608. u64 size;
  609. struct amdgpu_bo *reserved_bo;
  610. void *va;
  611. };
  612. /*
  613. * CGS
  614. */
  615. struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
  616. void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
  617. /*
  618. * Core structure, functions and helpers.
  619. */
  620. typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
  621. typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  622. typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  623. typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
  624. /*
  625. * amdgpu nbio functions
  626. *
  627. */
  628. struct nbio_hdp_flush_reg {
  629. u32 ref_and_mask_cp0;
  630. u32 ref_and_mask_cp1;
  631. u32 ref_and_mask_cp2;
  632. u32 ref_and_mask_cp3;
  633. u32 ref_and_mask_cp4;
  634. u32 ref_and_mask_cp5;
  635. u32 ref_and_mask_cp6;
  636. u32 ref_and_mask_cp7;
  637. u32 ref_and_mask_cp8;
  638. u32 ref_and_mask_cp9;
  639. u32 ref_and_mask_sdma0;
  640. u32 ref_and_mask_sdma1;
  641. };
  642. struct amdgpu_nbio_funcs {
  643. const struct nbio_hdp_flush_reg *hdp_flush_reg;
  644. u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
  645. u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
  646. u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
  647. u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
  648. u32 (*get_rev_id)(struct amdgpu_device *adev);
  649. void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
  650. void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
  651. u32 (*get_memsize)(struct amdgpu_device *adev);
  652. void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
  653. bool use_doorbell, int doorbell_index);
  654. void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
  655. bool enable);
  656. void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
  657. bool enable);
  658. void (*ih_doorbell_range)(struct amdgpu_device *adev,
  659. bool use_doorbell, int doorbell_index);
  660. void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
  661. bool enable);
  662. void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
  663. bool enable);
  664. void (*get_clockgating_state)(struct amdgpu_device *adev,
  665. u32 *flags);
  666. void (*ih_control)(struct amdgpu_device *adev);
  667. void (*init_registers)(struct amdgpu_device *adev);
  668. void (*detect_hw_virt)(struct amdgpu_device *adev);
  669. };
  670. struct amdgpu_df_funcs {
  671. void (*init)(struct amdgpu_device *adev);
  672. void (*enable_broadcast_mode)(struct amdgpu_device *adev,
  673. bool enable);
  674. u32 (*get_fb_channel_number)(struct amdgpu_device *adev);
  675. u32 (*get_hbm_channel_number)(struct amdgpu_device *adev);
  676. void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
  677. bool enable);
  678. void (*get_clockgating_state)(struct amdgpu_device *adev,
  679. u32 *flags);
  680. void (*enable_ecc_force_par_wr_rmw)(struct amdgpu_device *adev,
  681. bool enable);
  682. };
  683. /* Define the HW IP blocks will be used in driver , add more if necessary */
  684. enum amd_hw_ip_block_type {
  685. GC_HWIP = 1,
  686. HDP_HWIP,
  687. SDMA0_HWIP,
  688. SDMA1_HWIP,
  689. MMHUB_HWIP,
  690. ATHUB_HWIP,
  691. NBIO_HWIP,
  692. MP0_HWIP,
  693. MP1_HWIP,
  694. UVD_HWIP,
  695. VCN_HWIP = UVD_HWIP,
  696. VCE_HWIP,
  697. DF_HWIP,
  698. DCE_HWIP,
  699. OSSSYS_HWIP,
  700. SMUIO_HWIP,
  701. PWR_HWIP,
  702. NBIF_HWIP,
  703. THM_HWIP,
  704. CLK_HWIP,
  705. MAX_HWIP
  706. };
  707. #define HWIP_MAX_INSTANCE 6
  708. struct amd_powerplay {
  709. void *pp_handle;
  710. const struct amd_pm_funcs *pp_funcs;
  711. uint32_t pp_feature;
  712. };
  713. #define AMDGPU_RESET_MAGIC_NUM 64
  714. struct amdgpu_device {
  715. struct device *dev;
  716. struct drm_device *ddev;
  717. struct pci_dev *pdev;
  718. #ifdef CONFIG_DRM_AMD_ACP
  719. struct amdgpu_acp acp;
  720. #endif
  721. /* ASIC */
  722. enum amd_asic_type asic_type;
  723. uint32_t family;
  724. uint32_t rev_id;
  725. uint32_t external_rev_id;
  726. unsigned long flags;
  727. int usec_timeout;
  728. const struct amdgpu_asic_funcs *asic_funcs;
  729. bool shutdown;
  730. bool need_dma32;
  731. bool need_swiotlb;
  732. bool accel_working;
  733. struct work_struct reset_work;
  734. struct notifier_block acpi_nb;
  735. struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
  736. struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  737. unsigned debugfs_count;
  738. #if defined(CONFIG_DEBUG_FS)
  739. struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  740. #endif
  741. struct amdgpu_atif *atif;
  742. struct amdgpu_atcs atcs;
  743. struct mutex srbm_mutex;
  744. /* GRBM index mutex. Protects concurrent access to GRBM index */
  745. struct mutex grbm_idx_mutex;
  746. struct dev_pm_domain vga_pm_domain;
  747. bool have_disp_power_ref;
  748. /* BIOS */
  749. bool is_atom_fw;
  750. uint8_t *bios;
  751. uint32_t bios_size;
  752. struct amdgpu_bo *stolen_vga_memory;
  753. uint32_t bios_scratch_reg_offset;
  754. uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
  755. /* Register/doorbell mmio */
  756. resource_size_t rmmio_base;
  757. resource_size_t rmmio_size;
  758. void __iomem *rmmio;
  759. /* protects concurrent MM_INDEX/DATA based register access */
  760. spinlock_t mmio_idx_lock;
  761. /* protects concurrent SMC based register access */
  762. spinlock_t smc_idx_lock;
  763. amdgpu_rreg_t smc_rreg;
  764. amdgpu_wreg_t smc_wreg;
  765. /* protects concurrent PCIE register access */
  766. spinlock_t pcie_idx_lock;
  767. amdgpu_rreg_t pcie_rreg;
  768. amdgpu_wreg_t pcie_wreg;
  769. amdgpu_rreg_t pciep_rreg;
  770. amdgpu_wreg_t pciep_wreg;
  771. /* protects concurrent UVD register access */
  772. spinlock_t uvd_ctx_idx_lock;
  773. amdgpu_rreg_t uvd_ctx_rreg;
  774. amdgpu_wreg_t uvd_ctx_wreg;
  775. /* protects concurrent DIDT register access */
  776. spinlock_t didt_idx_lock;
  777. amdgpu_rreg_t didt_rreg;
  778. amdgpu_wreg_t didt_wreg;
  779. /* protects concurrent gc_cac register access */
  780. spinlock_t gc_cac_idx_lock;
  781. amdgpu_rreg_t gc_cac_rreg;
  782. amdgpu_wreg_t gc_cac_wreg;
  783. /* protects concurrent se_cac register access */
  784. spinlock_t se_cac_idx_lock;
  785. amdgpu_rreg_t se_cac_rreg;
  786. amdgpu_wreg_t se_cac_wreg;
  787. /* protects concurrent ENDPOINT (audio) register access */
  788. spinlock_t audio_endpt_idx_lock;
  789. amdgpu_block_rreg_t audio_endpt_rreg;
  790. amdgpu_block_wreg_t audio_endpt_wreg;
  791. void __iomem *rio_mem;
  792. resource_size_t rio_mem_size;
  793. struct amdgpu_doorbell doorbell;
  794. /* clock/pll info */
  795. struct amdgpu_clock clock;
  796. /* MC */
  797. struct amdgpu_gmc gmc;
  798. struct amdgpu_gart gart;
  799. dma_addr_t dummy_page_addr;
  800. struct amdgpu_vm_manager vm_manager;
  801. struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS];
  802. /* memory management */
  803. struct amdgpu_mman mman;
  804. struct amdgpu_vram_scratch vram_scratch;
  805. struct amdgpu_wb wb;
  806. atomic64_t num_bytes_moved;
  807. atomic64_t num_evictions;
  808. atomic64_t num_vram_cpu_page_faults;
  809. atomic_t gpu_reset_counter;
  810. atomic_t vram_lost_counter;
  811. /* data for buffer migration throttling */
  812. struct {
  813. spinlock_t lock;
  814. s64 last_update_us;
  815. s64 accum_us; /* accumulated microseconds */
  816. s64 accum_us_vis; /* for visible VRAM */
  817. u32 log2_max_MBps;
  818. } mm_stats;
  819. /* display */
  820. bool enable_virtual_display;
  821. struct amdgpu_mode_info mode_info;
  822. /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
  823. struct work_struct hotplug_work;
  824. struct amdgpu_irq_src crtc_irq;
  825. struct amdgpu_irq_src pageflip_irq;
  826. struct amdgpu_irq_src hpd_irq;
  827. /* rings */
  828. u64 fence_context;
  829. unsigned num_rings;
  830. struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
  831. bool ib_pool_ready;
  832. struct amdgpu_sa_manager ring_tmp_bo;
  833. /* interrupts */
  834. struct amdgpu_irq irq;
  835. /* powerplay */
  836. struct amd_powerplay powerplay;
  837. bool pp_force_state_enabled;
  838. /* dpm */
  839. struct amdgpu_pm pm;
  840. u32 cg_flags;
  841. u32 pg_flags;
  842. /* gfx */
  843. struct amdgpu_gfx gfx;
  844. /* sdma */
  845. struct amdgpu_sdma sdma;
  846. /* uvd */
  847. struct amdgpu_uvd uvd;
  848. /* vce */
  849. struct amdgpu_vce vce;
  850. /* vcn */
  851. struct amdgpu_vcn vcn;
  852. /* firmwares */
  853. struct amdgpu_firmware firmware;
  854. /* PSP */
  855. struct psp_context psp;
  856. /* GDS */
  857. struct amdgpu_gds gds;
  858. /* display related functionality */
  859. struct amdgpu_display_manager dm;
  860. struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM];
  861. int num_ip_blocks;
  862. struct mutex mn_lock;
  863. DECLARE_HASHTABLE(mn_hash, 7);
  864. /* tracking pinned memory */
  865. atomic64_t vram_pin_size;
  866. atomic64_t visible_pin_size;
  867. atomic64_t gart_pin_size;
  868. /* amdkfd interface */
  869. struct kfd_dev *kfd;
  870. /* soc15 register offset based on ip, instance and segment */
  871. uint32_t *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
  872. const struct amdgpu_nbio_funcs *nbio_funcs;
  873. const struct amdgpu_df_funcs *df_funcs;
  874. /* delayed work_func for deferring clockgating during resume */
  875. struct delayed_work late_init_work;
  876. struct amdgpu_virt virt;
  877. /* firmware VRAM reservation */
  878. struct amdgpu_fw_vram_usage fw_vram_usage;
  879. /* link all shadow bo */
  880. struct list_head shadow_list;
  881. struct mutex shadow_list_lock;
  882. /* keep an lru list of rings by HW IP */
  883. struct list_head ring_lru_list;
  884. spinlock_t ring_lru_list_lock;
  885. /* record hw reset is performed */
  886. bool has_hw_reset;
  887. u8 reset_magic[AMDGPU_RESET_MAGIC_NUM];
  888. /* s3/s4 mask */
  889. bool in_suspend;
  890. /* record last mm index being written through WREG32*/
  891. unsigned long last_mm_index;
  892. bool in_gpu_reset;
  893. struct mutex lock_reset;
  894. };
  895. static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
  896. {
  897. return container_of(bdev, struct amdgpu_device, mman.bdev);
  898. }
  899. int amdgpu_device_init(struct amdgpu_device *adev,
  900. struct drm_device *ddev,
  901. struct pci_dev *pdev,
  902. uint32_t flags);
  903. void amdgpu_device_fini(struct amdgpu_device *adev);
  904. int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
  905. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  906. uint32_t acc_flags);
  907. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  908. uint32_t acc_flags);
  909. void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
  910. uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
  911. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
  912. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
  913. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
  914. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
  915. u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
  916. void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
  917. bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
  918. bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
  919. int emu_soc_asic_init(struct amdgpu_device *adev);
  920. /*
  921. * Registers read & write functions.
  922. */
  923. #define AMDGPU_REGS_IDX (1<<0)
  924. #define AMDGPU_REGS_NO_KIQ (1<<1)
  925. #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
  926. #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
  927. #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
  928. #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
  929. #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
  930. #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
  931. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
  932. #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
  933. #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
  934. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  935. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  936. #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
  937. #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
  938. #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
  939. #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
  940. #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
  941. #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
  942. #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
  943. #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
  944. #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
  945. #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
  946. #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
  947. #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
  948. #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
  949. #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
  950. #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
  951. #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
  952. #define WREG32_P(reg, val, mask) \
  953. do { \
  954. uint32_t tmp_ = RREG32(reg); \
  955. tmp_ &= (mask); \
  956. tmp_ |= ((val) & ~(mask)); \
  957. WREG32(reg, tmp_); \
  958. } while (0)
  959. #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
  960. #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
  961. #define WREG32_PLL_P(reg, val, mask) \
  962. do { \
  963. uint32_t tmp_ = RREG32_PLL(reg); \
  964. tmp_ &= (mask); \
  965. tmp_ |= ((val) & ~(mask)); \
  966. WREG32_PLL(reg, tmp_); \
  967. } while (0)
  968. #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
  969. #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
  970. #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
  971. #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
  972. #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
  973. #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
  974. #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
  975. #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  976. #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  977. #define REG_SET_FIELD(orig_val, reg, field, field_val) \
  978. (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
  979. (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
  980. #define REG_GET_FIELD(value, reg, field) \
  981. (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
  982. #define WREG32_FIELD(reg, field, val) \
  983. WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
  984. #define WREG32_FIELD_OFFSET(reg, offset, field, val) \
  985. WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
  986. /*
  987. * BIOS helpers.
  988. */
  989. #define RBIOS8(i) (adev->bios[i])
  990. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  991. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  992. /*
  993. * ASICs macro.
  994. */
  995. #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
  996. #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
  997. #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
  998. #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
  999. #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
  1000. #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
  1001. #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
  1002. #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
  1003. #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
  1004. #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
  1005. #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
  1006. #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
  1007. #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r))
  1008. #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))
  1009. #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev))
  1010. /* Common functions */
  1011. bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
  1012. int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  1013. struct amdgpu_job* job);
  1014. void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
  1015. bool amdgpu_device_need_post(struct amdgpu_device *adev);
  1016. void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
  1017. u64 num_vis_bytes);
  1018. int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
  1019. void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
  1020. const u32 *registers,
  1021. const u32 array_size);
  1022. bool amdgpu_device_is_px(struct drm_device *dev);
  1023. /* atpx handler */
  1024. #if defined(CONFIG_VGA_SWITCHEROO)
  1025. void amdgpu_register_atpx_handler(void);
  1026. void amdgpu_unregister_atpx_handler(void);
  1027. bool amdgpu_has_atpx_dgpu_power_cntl(void);
  1028. bool amdgpu_is_atpx_hybrid(void);
  1029. bool amdgpu_atpx_dgpu_req_power_for_displays(void);
  1030. bool amdgpu_has_atpx(void);
  1031. #else
  1032. static inline void amdgpu_register_atpx_handler(void) {}
  1033. static inline void amdgpu_unregister_atpx_handler(void) {}
  1034. static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
  1035. static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
  1036. static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
  1037. static inline bool amdgpu_has_atpx(void) { return false; }
  1038. #endif
  1039. #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
  1040. void *amdgpu_atpx_get_dhandle(void);
  1041. #else
  1042. static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
  1043. #endif
  1044. /*
  1045. * KMS
  1046. */
  1047. extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
  1048. extern const int amdgpu_max_kms_ioctl;
  1049. int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
  1050. void amdgpu_driver_unload_kms(struct drm_device *dev);
  1051. void amdgpu_driver_lastclose_kms(struct drm_device *dev);
  1052. int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
  1053. void amdgpu_driver_postclose_kms(struct drm_device *dev,
  1054. struct drm_file *file_priv);
  1055. int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
  1056. int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
  1057. int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
  1058. u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
  1059. int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  1060. void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  1061. long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
  1062. unsigned long arg);
  1063. /*
  1064. * functions used by amdgpu_xgmi.c
  1065. */
  1066. int amdgpu_xgmi_add_device(struct amdgpu_device *adev);
  1067. /*
  1068. * functions used by amdgpu_encoder.c
  1069. */
  1070. struct amdgpu_afmt_acr {
  1071. u32 clock;
  1072. int n_32khz;
  1073. int cts_32khz;
  1074. int n_44_1khz;
  1075. int cts_44_1khz;
  1076. int n_48khz;
  1077. int cts_48khz;
  1078. };
  1079. struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
  1080. /* amdgpu_acpi.c */
  1081. #if defined(CONFIG_ACPI)
  1082. int amdgpu_acpi_init(struct amdgpu_device *adev);
  1083. void amdgpu_acpi_fini(struct amdgpu_device *adev);
  1084. bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
  1085. int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
  1086. u8 perf_req, bool advertise);
  1087. int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
  1088. #else
  1089. static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
  1090. static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
  1091. #endif
  1092. int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
  1093. uint64_t addr, struct amdgpu_bo **bo,
  1094. struct amdgpu_bo_va_mapping **mapping);
  1095. #if defined(CONFIG_DRM_AMD_DC)
  1096. int amdgpu_dm_display_resume(struct amdgpu_device *adev );
  1097. #else
  1098. static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
  1099. #endif
  1100. #include "amdgpu_object.h"
  1101. #endif