amdgpu.h 51 KB

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