amdgpu.h 39 KB

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