amdgpu.h 44 KB

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