amdgpu.h 38 KB

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