amdgpu.h 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  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 <ttm/ttm_bo_api.h>
  38. #include <ttm/ttm_bo_driver.h>
  39. #include <ttm/ttm_placement.h>
  40. #include <ttm/ttm_module.h>
  41. #include <ttm/ttm_execbuf_util.h>
  42. #include <drm/drmP.h>
  43. #include <drm/drm_gem.h>
  44. #include <drm/amdgpu_drm.h>
  45. #include <kgd_kfd_interface.h>
  46. #include "amd_shared.h"
  47. #include "amdgpu_mode.h"
  48. #include "amdgpu_ih.h"
  49. #include "amdgpu_irq.h"
  50. #include "amdgpu_ucode.h"
  51. #include "amdgpu_ttm.h"
  52. #include "amdgpu_psp.h"
  53. #include "amdgpu_gds.h"
  54. #include "amdgpu_sync.h"
  55. #include "amdgpu_ring.h"
  56. #include "amdgpu_vm.h"
  57. #include "amd_powerplay.h"
  58. #include "amdgpu_dpm.h"
  59. #include "amdgpu_acp.h"
  60. #include "amdgpu_uvd.h"
  61. #include "amdgpu_vce.h"
  62. #include "amdgpu_vcn.h"
  63. #include "gpu_scheduler.h"
  64. #include "amdgpu_virt.h"
  65. /*
  66. * Modules parameters.
  67. */
  68. extern int amdgpu_modeset;
  69. extern int amdgpu_vram_limit;
  70. extern int amdgpu_gart_size;
  71. extern int amdgpu_moverate;
  72. extern int amdgpu_benchmarking;
  73. extern int amdgpu_testing;
  74. extern int amdgpu_audio;
  75. extern int amdgpu_disp_priority;
  76. extern int amdgpu_hw_i2c;
  77. extern int amdgpu_pcie_gen2;
  78. extern int amdgpu_msi;
  79. extern int amdgpu_lockup_timeout;
  80. extern int amdgpu_dpm;
  81. extern int amdgpu_fw_load_type;
  82. extern int amdgpu_aspm;
  83. extern int amdgpu_runtime_pm;
  84. extern unsigned amdgpu_ip_block_mask;
  85. extern int amdgpu_bapm;
  86. extern int amdgpu_deep_color;
  87. extern int amdgpu_vm_size;
  88. extern int amdgpu_vm_block_size;
  89. extern int amdgpu_vm_fault_stop;
  90. extern int amdgpu_vm_debug;
  91. extern int amdgpu_vm_update_mode;
  92. extern int amdgpu_sched_jobs;
  93. extern int amdgpu_sched_hw_submission;
  94. extern int amdgpu_no_evict;
  95. extern int amdgpu_direct_gma_size;
  96. extern unsigned amdgpu_pcie_gen_cap;
  97. extern unsigned amdgpu_pcie_lane_cap;
  98. extern unsigned amdgpu_cg_mask;
  99. extern unsigned amdgpu_pg_mask;
  100. extern char *amdgpu_disable_cu;
  101. extern char *amdgpu_virtual_display;
  102. extern unsigned amdgpu_pp_feature_mask;
  103. extern int amdgpu_vram_page_split;
  104. extern int amdgpu_ngg;
  105. extern int amdgpu_prim_buf_per_se;
  106. extern int amdgpu_pos_buf_per_se;
  107. extern int amdgpu_cntl_sb_buf_per_se;
  108. extern int amdgpu_param_buf_per_se;
  109. extern int amdgpu_job_hang_limit;
  110. extern int amdgpu_lbpw;
  111. #ifdef CONFIG_DRM_AMDGPU_SI
  112. extern int amdgpu_si_support;
  113. #endif
  114. #ifdef CONFIG_DRM_AMDGPU_CIK
  115. extern int amdgpu_cik_support;
  116. #endif
  117. #define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */
  118. #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
  119. #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  120. #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  121. /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
  122. #define AMDGPU_IB_POOL_SIZE 16
  123. #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
  124. #define AMDGPUFB_CONN_LIMIT 4
  125. #define AMDGPU_BIOS_NUM_SCRATCH 16
  126. /* max number of IP instances */
  127. #define AMDGPU_MAX_SDMA_INSTANCES 2
  128. /* hard reset data */
  129. #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
  130. /* reset flags */
  131. #define AMDGPU_RESET_GFX (1 << 0)
  132. #define AMDGPU_RESET_COMPUTE (1 << 1)
  133. #define AMDGPU_RESET_DMA (1 << 2)
  134. #define AMDGPU_RESET_CP (1 << 3)
  135. #define AMDGPU_RESET_GRBM (1 << 4)
  136. #define AMDGPU_RESET_DMA1 (1 << 5)
  137. #define AMDGPU_RESET_RLC (1 << 6)
  138. #define AMDGPU_RESET_SEM (1 << 7)
  139. #define AMDGPU_RESET_IH (1 << 8)
  140. #define AMDGPU_RESET_VMC (1 << 9)
  141. #define AMDGPU_RESET_MC (1 << 10)
  142. #define AMDGPU_RESET_DISPLAY (1 << 11)
  143. #define AMDGPU_RESET_UVD (1 << 12)
  144. #define AMDGPU_RESET_VCE (1 << 13)
  145. #define AMDGPU_RESET_VCE1 (1 << 14)
  146. /* GFX current status */
  147. #define AMDGPU_GFX_NORMAL_MODE 0x00000000L
  148. #define AMDGPU_GFX_SAFE_MODE 0x00000001L
  149. #define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
  150. #define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
  151. #define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
  152. /* max cursor sizes (in pixels) */
  153. #define CIK_CURSOR_WIDTH 128
  154. #define CIK_CURSOR_HEIGHT 128
  155. struct amdgpu_device;
  156. struct amdgpu_ib;
  157. struct amdgpu_cs_parser;
  158. struct amdgpu_job;
  159. struct amdgpu_irq_src;
  160. struct amdgpu_fpriv;
  161. enum amdgpu_cp_irq {
  162. AMDGPU_CP_IRQ_GFX_EOP = 0,
  163. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
  164. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
  165. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
  166. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
  167. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
  168. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
  169. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
  170. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
  171. AMDGPU_CP_IRQ_LAST
  172. };
  173. enum amdgpu_sdma_irq {
  174. AMDGPU_SDMA_IRQ_TRAP0 = 0,
  175. AMDGPU_SDMA_IRQ_TRAP1,
  176. AMDGPU_SDMA_IRQ_LAST
  177. };
  178. enum amdgpu_thermal_irq {
  179. AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
  180. AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
  181. AMDGPU_THERMAL_IRQ_LAST
  182. };
  183. enum amdgpu_kiq_irq {
  184. AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
  185. AMDGPU_CP_KIQ_IRQ_LAST
  186. };
  187. int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
  188. enum amd_ip_block_type block_type,
  189. enum amd_clockgating_state state);
  190. int amdgpu_set_powergating_state(struct amdgpu_device *adev,
  191. enum amd_ip_block_type block_type,
  192. enum amd_powergating_state state);
  193. void amdgpu_get_clockgating_state(struct amdgpu_device *adev, u32 *flags);
  194. int amdgpu_wait_for_idle(struct amdgpu_device *adev,
  195. enum amd_ip_block_type block_type);
  196. bool amdgpu_is_idle(struct amdgpu_device *adev,
  197. enum amd_ip_block_type block_type);
  198. #define AMDGPU_MAX_IP_NUM 16
  199. struct amdgpu_ip_block_status {
  200. bool valid;
  201. bool sw;
  202. bool hw;
  203. bool late_initialized;
  204. bool hang;
  205. };
  206. struct amdgpu_ip_block_version {
  207. const enum amd_ip_block_type type;
  208. const u32 major;
  209. const u32 minor;
  210. const u32 rev;
  211. const struct amd_ip_funcs *funcs;
  212. };
  213. struct amdgpu_ip_block {
  214. struct amdgpu_ip_block_status status;
  215. const struct amdgpu_ip_block_version *version;
  216. };
  217. int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
  218. enum amd_ip_block_type type,
  219. u32 major, u32 minor);
  220. struct amdgpu_ip_block * amdgpu_get_ip_block(struct amdgpu_device *adev,
  221. enum amd_ip_block_type type);
  222. int amdgpu_ip_block_add(struct amdgpu_device *adev,
  223. const struct amdgpu_ip_block_version *ip_block_version);
  224. /* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
  225. struct amdgpu_buffer_funcs {
  226. /* maximum bytes in a single operation */
  227. uint32_t copy_max_bytes;
  228. /* number of dw to reserve per operation */
  229. unsigned copy_num_dw;
  230. /* used for buffer migration */
  231. void (*emit_copy_buffer)(struct amdgpu_ib *ib,
  232. /* src addr in bytes */
  233. uint64_t src_offset,
  234. /* dst addr in bytes */
  235. uint64_t dst_offset,
  236. /* number of byte to transfer */
  237. uint32_t byte_count);
  238. /* maximum bytes in a single operation */
  239. uint32_t fill_max_bytes;
  240. /* number of dw to reserve per operation */
  241. unsigned fill_num_dw;
  242. /* used for buffer clearing */
  243. void (*emit_fill_buffer)(struct amdgpu_ib *ib,
  244. /* value to write to memory */
  245. uint32_t src_data,
  246. /* dst addr in bytes */
  247. uint64_t dst_offset,
  248. /* number of byte to fill */
  249. uint32_t byte_count);
  250. };
  251. /* provided by hw blocks that can write ptes, e.g., sdma */
  252. struct amdgpu_vm_pte_funcs {
  253. /* copy pte entries from GART */
  254. void (*copy_pte)(struct amdgpu_ib *ib,
  255. uint64_t pe, uint64_t src,
  256. unsigned count);
  257. /* write pte one entry at a time with addr mapping */
  258. void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
  259. uint64_t value, unsigned count,
  260. uint32_t incr);
  261. /* for linear pte/pde updates without addr mapping */
  262. void (*set_pte_pde)(struct amdgpu_ib *ib,
  263. uint64_t pe,
  264. uint64_t addr, unsigned count,
  265. uint32_t incr, uint64_t flags);
  266. };
  267. /* provided by the gmc block */
  268. struct amdgpu_gart_funcs {
  269. /* flush the vm tlb via mmio */
  270. void (*flush_gpu_tlb)(struct amdgpu_device *adev,
  271. uint32_t vmid);
  272. /* write pte/pde updates using the cpu */
  273. int (*set_pte_pde)(struct amdgpu_device *adev,
  274. void *cpu_pt_addr, /* cpu addr of page table */
  275. uint32_t gpu_page_idx, /* pte/pde to update */
  276. uint64_t addr, /* addr to write into pte/pde */
  277. uint64_t flags); /* access flags */
  278. /* enable/disable PRT support */
  279. void (*set_prt)(struct amdgpu_device *adev, bool enable);
  280. /* set pte flags based per asic */
  281. uint64_t (*get_vm_pte_flags)(struct amdgpu_device *adev,
  282. uint32_t flags);
  283. /* get the pde for a given mc addr */
  284. u64 (*get_vm_pde)(struct amdgpu_device *adev, u64 addr);
  285. uint32_t (*get_invalidate_req)(unsigned int vm_id);
  286. };
  287. /* provided by the ih block */
  288. struct amdgpu_ih_funcs {
  289. /* ring read/write ptr handling, called from interrupt context */
  290. u32 (*get_wptr)(struct amdgpu_device *adev);
  291. void (*decode_iv)(struct amdgpu_device *adev,
  292. struct amdgpu_iv_entry *entry);
  293. void (*set_rptr)(struct amdgpu_device *adev);
  294. };
  295. /*
  296. * BIOS.
  297. */
  298. bool amdgpu_get_bios(struct amdgpu_device *adev);
  299. bool amdgpu_read_bios(struct amdgpu_device *adev);
  300. /*
  301. * Dummy page
  302. */
  303. struct amdgpu_dummy_page {
  304. struct page *page;
  305. dma_addr_t addr;
  306. };
  307. int amdgpu_dummy_page_init(struct amdgpu_device *adev);
  308. void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
  309. /*
  310. * Clocks
  311. */
  312. #define AMDGPU_MAX_PPLL 3
  313. struct amdgpu_clock {
  314. struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
  315. struct amdgpu_pll spll;
  316. struct amdgpu_pll mpll;
  317. /* 10 Khz units */
  318. uint32_t default_mclk;
  319. uint32_t default_sclk;
  320. uint32_t default_dispclk;
  321. uint32_t current_dispclk;
  322. uint32_t dp_extclk;
  323. uint32_t max_pixel_clock;
  324. };
  325. /*
  326. * BO.
  327. */
  328. struct amdgpu_bo_list_entry {
  329. struct amdgpu_bo *robj;
  330. struct ttm_validate_buffer tv;
  331. struct amdgpu_bo_va *bo_va;
  332. uint32_t priority;
  333. struct page **user_pages;
  334. int user_invalidated;
  335. };
  336. struct amdgpu_bo_va_mapping {
  337. struct list_head list;
  338. struct rb_node rb;
  339. uint64_t start;
  340. uint64_t last;
  341. uint64_t __subtree_last;
  342. uint64_t offset;
  343. uint64_t flags;
  344. };
  345. /* bo virtual addresses in a specific vm */
  346. struct amdgpu_bo_va {
  347. /* protected by bo being reserved */
  348. struct list_head bo_list;
  349. struct dma_fence *last_pt_update;
  350. unsigned ref_count;
  351. /* protected by vm mutex and spinlock */
  352. struct list_head vm_status;
  353. /* mappings for this bo_va */
  354. struct list_head invalids;
  355. struct list_head valids;
  356. /* constant after initialization */
  357. struct amdgpu_vm *vm;
  358. struct amdgpu_bo *bo;
  359. };
  360. #define AMDGPU_GEM_DOMAIN_MAX 0x3
  361. struct amdgpu_bo {
  362. /* Protected by tbo.reserved */
  363. u32 prefered_domains;
  364. u32 allowed_domains;
  365. struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
  366. struct ttm_placement placement;
  367. struct ttm_buffer_object tbo;
  368. struct ttm_bo_kmap_obj kmap;
  369. u64 flags;
  370. unsigned pin_count;
  371. void *kptr;
  372. u64 tiling_flags;
  373. u64 metadata_flags;
  374. void *metadata;
  375. u32 metadata_size;
  376. unsigned prime_shared_count;
  377. /* list of all virtual address to which this bo
  378. * is associated to
  379. */
  380. struct list_head va;
  381. /* Constant after initialization */
  382. struct drm_gem_object gem_base;
  383. struct amdgpu_bo *parent;
  384. struct amdgpu_bo *shadow;
  385. struct ttm_bo_kmap_obj dma_buf_vmap;
  386. struct amdgpu_mn *mn;
  387. struct list_head mn_list;
  388. struct list_head shadow_list;
  389. };
  390. #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
  391. void amdgpu_gem_object_free(struct drm_gem_object *obj);
  392. int amdgpu_gem_object_open(struct drm_gem_object *obj,
  393. struct drm_file *file_priv);
  394. void amdgpu_gem_object_close(struct drm_gem_object *obj,
  395. struct drm_file *file_priv);
  396. unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
  397. struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
  398. struct drm_gem_object *
  399. amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
  400. struct dma_buf_attachment *attach,
  401. struct sg_table *sg);
  402. struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
  403. struct drm_gem_object *gobj,
  404. int flags);
  405. int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
  406. void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
  407. struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
  408. void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
  409. void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  410. int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
  411. /* sub-allocation manager, it has to be protected by another lock.
  412. * By conception this is an helper for other part of the driver
  413. * like the indirect buffer or semaphore, which both have their
  414. * locking.
  415. *
  416. * Principe is simple, we keep a list of sub allocation in offset
  417. * order (first entry has offset == 0, last entry has the highest
  418. * offset).
  419. *
  420. * When allocating new object we first check if there is room at
  421. * the end total_size - (last_object_offset + last_object_size) >=
  422. * alloc_size. If so we allocate new object there.
  423. *
  424. * When there is not enough room at the end, we start waiting for
  425. * each sub object until we reach object_offset+object_size >=
  426. * alloc_size, this object then become the sub object we return.
  427. *
  428. * Alignment can't be bigger than page size.
  429. *
  430. * Hole are not considered for allocation to keep things simple.
  431. * Assumption is that there won't be hole (all object on same
  432. * alignment).
  433. */
  434. #define AMDGPU_SA_NUM_FENCE_LISTS 32
  435. struct amdgpu_sa_manager {
  436. wait_queue_head_t wq;
  437. struct amdgpu_bo *bo;
  438. struct list_head *hole;
  439. struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
  440. struct list_head olist;
  441. unsigned size;
  442. uint64_t gpu_addr;
  443. void *cpu_ptr;
  444. uint32_t domain;
  445. uint32_t align;
  446. };
  447. /* sub-allocation buffer */
  448. struct amdgpu_sa_bo {
  449. struct list_head olist;
  450. struct list_head flist;
  451. struct amdgpu_sa_manager *manager;
  452. unsigned soffset;
  453. unsigned eoffset;
  454. struct dma_fence *fence;
  455. };
  456. /*
  457. * GEM objects.
  458. */
  459. void amdgpu_gem_force_release(struct amdgpu_device *adev);
  460. int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  461. int alignment, u32 initial_domain,
  462. u64 flags, bool kernel,
  463. struct drm_gem_object **obj);
  464. int amdgpu_mode_dumb_create(struct drm_file *file_priv,
  465. struct drm_device *dev,
  466. struct drm_mode_create_dumb *args);
  467. int amdgpu_mode_dumb_mmap(struct drm_file *filp,
  468. struct drm_device *dev,
  469. uint32_t handle, uint64_t *offset_p);
  470. int amdgpu_fence_slab_init(void);
  471. void amdgpu_fence_slab_fini(void);
  472. /*
  473. * GART structures, functions & helpers
  474. */
  475. struct amdgpu_mc;
  476. #define AMDGPU_GPU_PAGE_SIZE 4096
  477. #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
  478. #define AMDGPU_GPU_PAGE_SHIFT 12
  479. #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
  480. struct amdgpu_gart {
  481. dma_addr_t table_addr;
  482. struct amdgpu_bo *robj;
  483. void *ptr;
  484. unsigned num_gpu_pages;
  485. unsigned num_cpu_pages;
  486. unsigned table_size;
  487. #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
  488. struct page **pages;
  489. #endif
  490. bool ready;
  491. /* Asic default pte flags */
  492. uint64_t gart_pte_flags;
  493. const struct amdgpu_gart_funcs *gart_funcs;
  494. };
  495. int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
  496. void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
  497. int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
  498. void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
  499. int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
  500. void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
  501. int amdgpu_gart_init(struct amdgpu_device *adev);
  502. void amdgpu_gart_fini(struct amdgpu_device *adev);
  503. int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
  504. int pages);
  505. int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
  506. int pages, struct page **pagelist,
  507. dma_addr_t *dma_addr, uint64_t flags);
  508. int amdgpu_ttm_recover_gart(struct amdgpu_device *adev);
  509. /*
  510. * VMHUB structures, functions & helpers
  511. */
  512. struct amdgpu_vmhub {
  513. uint32_t ctx0_ptb_addr_lo32;
  514. uint32_t ctx0_ptb_addr_hi32;
  515. uint32_t vm_inv_eng0_req;
  516. uint32_t vm_inv_eng0_ack;
  517. uint32_t vm_context0_cntl;
  518. uint32_t vm_l2_pro_fault_status;
  519. uint32_t vm_l2_pro_fault_cntl;
  520. };
  521. /*
  522. * GPU MC structures, functions & helpers
  523. */
  524. struct amdgpu_mc {
  525. resource_size_t aper_size;
  526. resource_size_t aper_base;
  527. resource_size_t agp_base;
  528. /* for some chips with <= 32MB we need to lie
  529. * about vram size near mc fb location */
  530. u64 mc_vram_size;
  531. u64 visible_vram_size;
  532. u64 gtt_size;
  533. u64 gtt_start;
  534. u64 gtt_end;
  535. u64 vram_start;
  536. u64 vram_end;
  537. unsigned vram_width;
  538. u64 real_vram_size;
  539. int vram_mtrr;
  540. u64 gtt_base_align;
  541. u64 mc_mask;
  542. const struct firmware *fw; /* MC firmware */
  543. uint32_t fw_version;
  544. struct amdgpu_irq_src vm_fault;
  545. uint32_t vram_type;
  546. uint32_t srbm_soft_reset;
  547. struct amdgpu_mode_mc_save save;
  548. bool prt_warning;
  549. uint64_t stolen_size;
  550. /* apertures */
  551. u64 shared_aperture_start;
  552. u64 shared_aperture_end;
  553. u64 private_aperture_start;
  554. u64 private_aperture_end;
  555. /* protects concurrent invalidation */
  556. spinlock_t invalidate_lock;
  557. };
  558. /*
  559. * GPU doorbell structures, functions & helpers
  560. */
  561. typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
  562. {
  563. AMDGPU_DOORBELL_KIQ = 0x000,
  564. AMDGPU_DOORBELL_HIQ = 0x001,
  565. AMDGPU_DOORBELL_DIQ = 0x002,
  566. AMDGPU_DOORBELL_MEC_RING0 = 0x010,
  567. AMDGPU_DOORBELL_MEC_RING1 = 0x011,
  568. AMDGPU_DOORBELL_MEC_RING2 = 0x012,
  569. AMDGPU_DOORBELL_MEC_RING3 = 0x013,
  570. AMDGPU_DOORBELL_MEC_RING4 = 0x014,
  571. AMDGPU_DOORBELL_MEC_RING5 = 0x015,
  572. AMDGPU_DOORBELL_MEC_RING6 = 0x016,
  573. AMDGPU_DOORBELL_MEC_RING7 = 0x017,
  574. AMDGPU_DOORBELL_GFX_RING0 = 0x020,
  575. AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
  576. AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
  577. AMDGPU_DOORBELL_IH = 0x1E8,
  578. AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
  579. AMDGPU_DOORBELL_INVALID = 0xFFFF
  580. } AMDGPU_DOORBELL_ASSIGNMENT;
  581. struct amdgpu_doorbell {
  582. /* doorbell mmio */
  583. resource_size_t base;
  584. resource_size_t size;
  585. u32 __iomem *ptr;
  586. u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
  587. };
  588. /*
  589. * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
  590. */
  591. typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
  592. {
  593. /*
  594. * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
  595. * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
  596. * Compute related doorbells are allocated from 0x00 to 0x8a
  597. */
  598. /* kernel scheduling */
  599. AMDGPU_DOORBELL64_KIQ = 0x00,
  600. /* HSA interface queue and debug queue */
  601. AMDGPU_DOORBELL64_HIQ = 0x01,
  602. AMDGPU_DOORBELL64_DIQ = 0x02,
  603. /* Compute engines */
  604. AMDGPU_DOORBELL64_MEC_RING0 = 0x03,
  605. AMDGPU_DOORBELL64_MEC_RING1 = 0x04,
  606. AMDGPU_DOORBELL64_MEC_RING2 = 0x05,
  607. AMDGPU_DOORBELL64_MEC_RING3 = 0x06,
  608. AMDGPU_DOORBELL64_MEC_RING4 = 0x07,
  609. AMDGPU_DOORBELL64_MEC_RING5 = 0x08,
  610. AMDGPU_DOORBELL64_MEC_RING6 = 0x09,
  611. AMDGPU_DOORBELL64_MEC_RING7 = 0x0a,
  612. /* User queue doorbell range (128 doorbells) */
  613. AMDGPU_DOORBELL64_USERQUEUE_START = 0x0b,
  614. AMDGPU_DOORBELL64_USERQUEUE_END = 0x8a,
  615. /* Graphics engine */
  616. AMDGPU_DOORBELL64_GFX_RING0 = 0x8b,
  617. /*
  618. * Other graphics doorbells can be allocated here: from 0x8c to 0xef
  619. * Graphics voltage island aperture 1
  620. * default non-graphics QWORD index is 0xF0 - 0xFF inclusive
  621. */
  622. /* sDMA engines */
  623. AMDGPU_DOORBELL64_sDMA_ENGINE0 = 0xF0,
  624. AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
  625. AMDGPU_DOORBELL64_sDMA_ENGINE1 = 0xF2,
  626. AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
  627. /* Interrupt handler */
  628. AMDGPU_DOORBELL64_IH = 0xF4, /* For legacy interrupt ring buffer */
  629. AMDGPU_DOORBELL64_IH_RING1 = 0xF5, /* For page migration request log */
  630. AMDGPU_DOORBELL64_IH_RING2 = 0xF6, /* For page migration translation/invalidation log */
  631. /* VCN engine use 32 bits doorbell */
  632. AMDGPU_DOORBELL64_VCN0_1 = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
  633. AMDGPU_DOORBELL64_VCN2_3 = 0xF9,
  634. AMDGPU_DOORBELL64_VCN4_5 = 0xFA,
  635. AMDGPU_DOORBELL64_VCN6_7 = 0xFB,
  636. /* overlap the doorbell assignment with VCN as they are mutually exclusive
  637. * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
  638. */
  639. AMDGPU_DOORBELL64_RING0_1 = 0xF8,
  640. AMDGPU_DOORBELL64_RING2_3 = 0xF9,
  641. AMDGPU_DOORBELL64_RING4_5 = 0xFA,
  642. AMDGPU_DOORBELL64_RING6_7 = 0xFB,
  643. AMDGPU_DOORBELL64_UVD_RING0_1 = 0xFC,
  644. AMDGPU_DOORBELL64_UVD_RING2_3 = 0xFD,
  645. AMDGPU_DOORBELL64_UVD_RING4_5 = 0xFE,
  646. AMDGPU_DOORBELL64_UVD_RING6_7 = 0xFF,
  647. AMDGPU_DOORBELL64_MAX_ASSIGNMENT = 0xFF,
  648. AMDGPU_DOORBELL64_INVALID = 0xFFFF
  649. } AMDGPU_DOORBELL64_ASSIGNMENT;
  650. void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
  651. phys_addr_t *aperture_base,
  652. size_t *aperture_size,
  653. size_t *start_offset);
  654. /*
  655. * IRQS.
  656. */
  657. struct amdgpu_flip_work {
  658. struct delayed_work flip_work;
  659. struct work_struct unpin_work;
  660. struct amdgpu_device *adev;
  661. int crtc_id;
  662. u32 target_vblank;
  663. uint64_t base;
  664. struct drm_pending_vblank_event *event;
  665. struct amdgpu_bo *old_abo;
  666. struct dma_fence *excl;
  667. unsigned shared_count;
  668. struct dma_fence **shared;
  669. struct dma_fence_cb cb;
  670. bool async;
  671. };
  672. /*
  673. * CP & rings.
  674. */
  675. struct amdgpu_ib {
  676. struct amdgpu_sa_bo *sa_bo;
  677. uint32_t length_dw;
  678. uint64_t gpu_addr;
  679. uint32_t *ptr;
  680. uint32_t flags;
  681. };
  682. extern const struct amd_sched_backend_ops amdgpu_sched_ops;
  683. int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
  684. struct amdgpu_job **job, struct amdgpu_vm *vm);
  685. int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
  686. struct amdgpu_job **job);
  687. void amdgpu_job_free_resources(struct amdgpu_job *job);
  688. void amdgpu_job_free(struct amdgpu_job *job);
  689. int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
  690. struct amd_sched_entity *entity, void *owner,
  691. struct dma_fence **f);
  692. /*
  693. * Queue manager
  694. */
  695. struct amdgpu_queue_mapper {
  696. int hw_ip;
  697. struct mutex lock;
  698. /* protected by lock */
  699. struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
  700. };
  701. struct amdgpu_queue_mgr {
  702. struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
  703. };
  704. int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
  705. struct amdgpu_queue_mgr *mgr);
  706. int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
  707. struct amdgpu_queue_mgr *mgr);
  708. int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
  709. struct amdgpu_queue_mgr *mgr,
  710. int hw_ip, int instance, int ring,
  711. struct amdgpu_ring **out_ring);
  712. /*
  713. * context related structures
  714. */
  715. struct amdgpu_ctx_ring {
  716. uint64_t sequence;
  717. struct dma_fence **fences;
  718. struct amd_sched_entity entity;
  719. };
  720. struct amdgpu_ctx {
  721. struct kref refcount;
  722. struct amdgpu_device *adev;
  723. struct amdgpu_queue_mgr queue_mgr;
  724. unsigned reset_counter;
  725. spinlock_t ring_lock;
  726. struct dma_fence **fences;
  727. struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
  728. bool preamble_presented;
  729. };
  730. struct amdgpu_ctx_mgr {
  731. struct amdgpu_device *adev;
  732. struct mutex lock;
  733. /* protected by lock */
  734. struct idr ctx_handles;
  735. };
  736. struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
  737. int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
  738. uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
  739. struct dma_fence *fence);
  740. struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
  741. struct amdgpu_ring *ring, uint64_t seq);
  742. int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
  743. struct drm_file *filp);
  744. void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
  745. void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
  746. /*
  747. * file private structure
  748. */
  749. struct amdgpu_fpriv {
  750. struct amdgpu_vm vm;
  751. struct amdgpu_bo_va *prt_va;
  752. struct mutex bo_list_lock;
  753. struct idr bo_list_handles;
  754. struct amdgpu_ctx_mgr ctx_mgr;
  755. u32 vram_lost_counter;
  756. };
  757. /*
  758. * residency list
  759. */
  760. struct amdgpu_bo_list {
  761. struct mutex lock;
  762. struct amdgpu_bo *gds_obj;
  763. struct amdgpu_bo *gws_obj;
  764. struct amdgpu_bo *oa_obj;
  765. unsigned first_userptr;
  766. unsigned num_entries;
  767. struct amdgpu_bo_list_entry *array;
  768. };
  769. struct amdgpu_bo_list *
  770. amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
  771. void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
  772. struct list_head *validated);
  773. void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
  774. void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
  775. /*
  776. * GFX stuff
  777. */
  778. #include "clearstate_defs.h"
  779. struct amdgpu_rlc_funcs {
  780. void (*enter_safe_mode)(struct amdgpu_device *adev);
  781. void (*exit_safe_mode)(struct amdgpu_device *adev);
  782. };
  783. struct amdgpu_rlc {
  784. /* for power gating */
  785. struct amdgpu_bo *save_restore_obj;
  786. uint64_t save_restore_gpu_addr;
  787. volatile uint32_t *sr_ptr;
  788. const u32 *reg_list;
  789. u32 reg_list_size;
  790. /* for clear state */
  791. struct amdgpu_bo *clear_state_obj;
  792. uint64_t clear_state_gpu_addr;
  793. volatile uint32_t *cs_ptr;
  794. const struct cs_section_def *cs_data;
  795. u32 clear_state_size;
  796. /* for cp tables */
  797. struct amdgpu_bo *cp_table_obj;
  798. uint64_t cp_table_gpu_addr;
  799. volatile uint32_t *cp_table_ptr;
  800. u32 cp_table_size;
  801. /* safe mode for updating CG/PG state */
  802. bool in_safe_mode;
  803. const struct amdgpu_rlc_funcs *funcs;
  804. /* for firmware data */
  805. u32 save_and_restore_offset;
  806. u32 clear_state_descriptor_offset;
  807. u32 avail_scratch_ram_locations;
  808. u32 reg_restore_list_size;
  809. u32 reg_list_format_start;
  810. u32 reg_list_format_separate_start;
  811. u32 starting_offsets_start;
  812. u32 reg_list_format_size_bytes;
  813. u32 reg_list_size_bytes;
  814. u32 *register_list_format;
  815. u32 *register_restore;
  816. };
  817. #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
  818. struct amdgpu_mec {
  819. struct amdgpu_bo *hpd_eop_obj;
  820. u64 hpd_eop_gpu_addr;
  821. struct amdgpu_bo *mec_fw_obj;
  822. u64 mec_fw_gpu_addr;
  823. u32 num_mec;
  824. u32 num_pipe_per_mec;
  825. u32 num_queue_per_pipe;
  826. void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
  827. /* These are the resources for which amdgpu takes ownership */
  828. DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  829. };
  830. struct amdgpu_kiq {
  831. u64 eop_gpu_addr;
  832. struct amdgpu_bo *eop_obj;
  833. struct mutex ring_mutex;
  834. struct amdgpu_ring ring;
  835. struct amdgpu_irq_src irq;
  836. };
  837. /*
  838. * GPU scratch registers structures, functions & helpers
  839. */
  840. struct amdgpu_scratch {
  841. unsigned num_reg;
  842. uint32_t reg_base;
  843. uint32_t free_mask;
  844. };
  845. /*
  846. * GFX configurations
  847. */
  848. #define AMDGPU_GFX_MAX_SE 4
  849. #define AMDGPU_GFX_MAX_SH_PER_SE 2
  850. struct amdgpu_rb_config {
  851. uint32_t rb_backend_disable;
  852. uint32_t user_rb_backend_disable;
  853. uint32_t raster_config;
  854. uint32_t raster_config_1;
  855. };
  856. struct gb_addr_config {
  857. uint16_t pipe_interleave_size;
  858. uint8_t num_pipes;
  859. uint8_t max_compress_frags;
  860. uint8_t num_banks;
  861. uint8_t num_se;
  862. uint8_t num_rb_per_se;
  863. };
  864. struct amdgpu_gfx_config {
  865. unsigned max_shader_engines;
  866. unsigned max_tile_pipes;
  867. unsigned max_cu_per_sh;
  868. unsigned max_sh_per_se;
  869. unsigned max_backends_per_se;
  870. unsigned max_texture_channel_caches;
  871. unsigned max_gprs;
  872. unsigned max_gs_threads;
  873. unsigned max_hw_contexts;
  874. unsigned sc_prim_fifo_size_frontend;
  875. unsigned sc_prim_fifo_size_backend;
  876. unsigned sc_hiz_tile_fifo_size;
  877. unsigned sc_earlyz_tile_fifo_size;
  878. unsigned num_tile_pipes;
  879. unsigned backend_enable_mask;
  880. unsigned mem_max_burst_length_bytes;
  881. unsigned mem_row_size_in_kb;
  882. unsigned shader_engine_tile_size;
  883. unsigned num_gpus;
  884. unsigned multi_gpu_tile_size;
  885. unsigned mc_arb_ramcfg;
  886. unsigned gb_addr_config;
  887. unsigned num_rbs;
  888. unsigned gs_vgt_table_depth;
  889. unsigned gs_prim_buffer_depth;
  890. uint32_t tile_mode_array[32];
  891. uint32_t macrotile_mode_array[16];
  892. struct gb_addr_config gb_addr_config_fields;
  893. struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
  894. /* gfx configure feature */
  895. uint32_t double_offchip_lds_buf;
  896. };
  897. struct amdgpu_cu_info {
  898. uint32_t number; /* total active CU number */
  899. uint32_t ao_cu_mask;
  900. uint32_t wave_front_size;
  901. uint32_t bitmap[4][4];
  902. };
  903. struct amdgpu_gfx_funcs {
  904. /* get the gpu clock counter */
  905. uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
  906. void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
  907. void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);
  908. void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t thread, uint32_t start, uint32_t size, uint32_t *dst);
  909. void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst);
  910. };
  911. struct amdgpu_ngg_buf {
  912. struct amdgpu_bo *bo;
  913. uint64_t gpu_addr;
  914. uint32_t size;
  915. uint32_t bo_size;
  916. };
  917. enum {
  918. NGG_PRIM = 0,
  919. NGG_POS,
  920. NGG_CNTL,
  921. NGG_PARAM,
  922. NGG_BUF_MAX
  923. };
  924. struct amdgpu_ngg {
  925. struct amdgpu_ngg_buf buf[NGG_BUF_MAX];
  926. uint32_t gds_reserve_addr;
  927. uint32_t gds_reserve_size;
  928. bool init;
  929. };
  930. struct amdgpu_gfx {
  931. struct mutex gpu_clock_mutex;
  932. struct amdgpu_gfx_config config;
  933. struct amdgpu_rlc rlc;
  934. struct amdgpu_mec mec;
  935. struct amdgpu_kiq kiq;
  936. struct amdgpu_scratch scratch;
  937. const struct firmware *me_fw; /* ME firmware */
  938. uint32_t me_fw_version;
  939. const struct firmware *pfp_fw; /* PFP firmware */
  940. uint32_t pfp_fw_version;
  941. const struct firmware *ce_fw; /* CE firmware */
  942. uint32_t ce_fw_version;
  943. const struct firmware *rlc_fw; /* RLC firmware */
  944. uint32_t rlc_fw_version;
  945. const struct firmware *mec_fw; /* MEC firmware */
  946. uint32_t mec_fw_version;
  947. const struct firmware *mec2_fw; /* MEC2 firmware */
  948. uint32_t mec2_fw_version;
  949. uint32_t me_feature_version;
  950. uint32_t ce_feature_version;
  951. uint32_t pfp_feature_version;
  952. uint32_t rlc_feature_version;
  953. uint32_t mec_feature_version;
  954. uint32_t mec2_feature_version;
  955. struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
  956. unsigned num_gfx_rings;
  957. struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
  958. unsigned num_compute_rings;
  959. struct amdgpu_irq_src eop_irq;
  960. struct amdgpu_irq_src priv_reg_irq;
  961. struct amdgpu_irq_src priv_inst_irq;
  962. /* gfx status */
  963. uint32_t gfx_current_status;
  964. /* ce ram size*/
  965. unsigned ce_ram_size;
  966. struct amdgpu_cu_info cu_info;
  967. const struct amdgpu_gfx_funcs *funcs;
  968. /* reset mask */
  969. uint32_t grbm_soft_reset;
  970. uint32_t srbm_soft_reset;
  971. bool in_reset;
  972. /* s3/s4 mask */
  973. bool in_suspend;
  974. /* NGG */
  975. struct amdgpu_ngg ngg;
  976. };
  977. int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  978. unsigned size, struct amdgpu_ib *ib);
  979. void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
  980. struct dma_fence *f);
  981. int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
  982. struct amdgpu_ib *ibs, struct amdgpu_job *job,
  983. struct dma_fence **f);
  984. int amdgpu_ib_pool_init(struct amdgpu_device *adev);
  985. void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
  986. int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
  987. /*
  988. * CS.
  989. */
  990. struct amdgpu_cs_chunk {
  991. uint32_t chunk_id;
  992. uint32_t length_dw;
  993. void *kdata;
  994. };
  995. struct amdgpu_cs_parser {
  996. struct amdgpu_device *adev;
  997. struct drm_file *filp;
  998. struct amdgpu_ctx *ctx;
  999. /* chunks */
  1000. unsigned nchunks;
  1001. struct amdgpu_cs_chunk *chunks;
  1002. /* scheduler job object */
  1003. struct amdgpu_job *job;
  1004. /* buffer objects */
  1005. struct ww_acquire_ctx ticket;
  1006. struct amdgpu_bo_list *bo_list;
  1007. struct amdgpu_bo_list_entry vm_pd;
  1008. struct list_head validated;
  1009. struct dma_fence *fence;
  1010. uint64_t bytes_moved_threshold;
  1011. uint64_t bytes_moved;
  1012. struct amdgpu_bo_list_entry *evictable;
  1013. /* user fence */
  1014. struct amdgpu_bo_list_entry uf_entry;
  1015. };
  1016. #define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */
  1017. #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */
  1018. #define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */
  1019. struct amdgpu_job {
  1020. struct amd_sched_job base;
  1021. struct amdgpu_device *adev;
  1022. struct amdgpu_vm *vm;
  1023. struct amdgpu_ring *ring;
  1024. struct amdgpu_sync sync;
  1025. struct amdgpu_sync dep_sync;
  1026. struct amdgpu_sync sched_sync;
  1027. struct amdgpu_ib *ibs;
  1028. struct dma_fence *fence; /* the hw fence */
  1029. uint32_t preamble_status;
  1030. uint32_t num_ibs;
  1031. void *owner;
  1032. uint64_t fence_ctx; /* the fence_context this job uses */
  1033. bool vm_needs_flush;
  1034. unsigned vm_id;
  1035. uint64_t vm_pd_addr;
  1036. uint32_t gds_base, gds_size;
  1037. uint32_t gws_base, gws_size;
  1038. uint32_t oa_base, oa_size;
  1039. /* user fence handling */
  1040. uint64_t uf_addr;
  1041. uint64_t uf_sequence;
  1042. };
  1043. #define to_amdgpu_job(sched_job) \
  1044. container_of((sched_job), struct amdgpu_job, base)
  1045. static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
  1046. uint32_t ib_idx, int idx)
  1047. {
  1048. return p->job->ibs[ib_idx].ptr[idx];
  1049. }
  1050. static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
  1051. uint32_t ib_idx, int idx,
  1052. uint32_t value)
  1053. {
  1054. p->job->ibs[ib_idx].ptr[idx] = value;
  1055. }
  1056. /*
  1057. * Writeback
  1058. */
  1059. #define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
  1060. struct amdgpu_wb {
  1061. struct amdgpu_bo *wb_obj;
  1062. volatile uint32_t *wb;
  1063. uint64_t gpu_addr;
  1064. u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
  1065. unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
  1066. };
  1067. int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
  1068. void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
  1069. int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);
  1070. void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);
  1071. void amdgpu_get_pcie_info(struct amdgpu_device *adev);
  1072. /*
  1073. * SDMA
  1074. */
  1075. struct amdgpu_sdma_instance {
  1076. /* SDMA firmware */
  1077. const struct firmware *fw;
  1078. uint32_t fw_version;
  1079. uint32_t feature_version;
  1080. struct amdgpu_ring ring;
  1081. bool burst_nop;
  1082. };
  1083. struct amdgpu_sdma {
  1084. struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
  1085. #ifdef CONFIG_DRM_AMDGPU_SI
  1086. //SI DMA has a difference trap irq number for the second engine
  1087. struct amdgpu_irq_src trap_irq_1;
  1088. #endif
  1089. struct amdgpu_irq_src trap_irq;
  1090. struct amdgpu_irq_src illegal_inst_irq;
  1091. int num_instances;
  1092. uint32_t srbm_soft_reset;
  1093. };
  1094. /*
  1095. * Firmware
  1096. */
  1097. enum amdgpu_firmware_load_type {
  1098. AMDGPU_FW_LOAD_DIRECT = 0,
  1099. AMDGPU_FW_LOAD_SMU,
  1100. AMDGPU_FW_LOAD_PSP,
  1101. };
  1102. struct amdgpu_firmware {
  1103. struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
  1104. enum amdgpu_firmware_load_type load_type;
  1105. struct amdgpu_bo *fw_buf;
  1106. unsigned int fw_size;
  1107. unsigned int max_ucodes;
  1108. /* firmwares are loaded by psp instead of smu from vega10 */
  1109. const struct amdgpu_psp_funcs *funcs;
  1110. struct amdgpu_bo *rbuf;
  1111. struct mutex mutex;
  1112. };
  1113. /*
  1114. * Benchmarking
  1115. */
  1116. void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
  1117. /*
  1118. * Testing
  1119. */
  1120. void amdgpu_test_moves(struct amdgpu_device *adev);
  1121. /*
  1122. * MMU Notifier
  1123. */
  1124. #if defined(CONFIG_MMU_NOTIFIER)
  1125. int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
  1126. void amdgpu_mn_unregister(struct amdgpu_bo *bo);
  1127. #else
  1128. static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
  1129. {
  1130. return -ENODEV;
  1131. }
  1132. static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
  1133. #endif
  1134. /*
  1135. * Debugfs
  1136. */
  1137. struct amdgpu_debugfs {
  1138. const struct drm_info_list *files;
  1139. unsigned num_files;
  1140. };
  1141. int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
  1142. const struct drm_info_list *files,
  1143. unsigned nfiles);
  1144. int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
  1145. #if defined(CONFIG_DEBUG_FS)
  1146. int amdgpu_debugfs_init(struct drm_minor *minor);
  1147. #endif
  1148. int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
  1149. /*
  1150. * amdgpu smumgr functions
  1151. */
  1152. struct amdgpu_smumgr_funcs {
  1153. int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
  1154. int (*request_smu_load_fw)(struct amdgpu_device *adev);
  1155. int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
  1156. };
  1157. /*
  1158. * amdgpu smumgr
  1159. */
  1160. struct amdgpu_smumgr {
  1161. struct amdgpu_bo *toc_buf;
  1162. struct amdgpu_bo *smu_buf;
  1163. /* asic priv smu data */
  1164. void *priv;
  1165. spinlock_t smu_lock;
  1166. /* smumgr functions */
  1167. const struct amdgpu_smumgr_funcs *smumgr_funcs;
  1168. /* ucode loading complete flag */
  1169. uint32_t fw_flags;
  1170. };
  1171. /*
  1172. * ASIC specific register table accessible by UMD
  1173. */
  1174. struct amdgpu_allowed_register_entry {
  1175. uint32_t reg_offset;
  1176. bool grbm_indexed;
  1177. };
  1178. /*
  1179. * ASIC specific functions.
  1180. */
  1181. struct amdgpu_asic_funcs {
  1182. bool (*read_disabled_bios)(struct amdgpu_device *adev);
  1183. bool (*read_bios_from_rom)(struct amdgpu_device *adev,
  1184. u8 *bios, u32 length_bytes);
  1185. int (*read_register)(struct amdgpu_device *adev, u32 se_num,
  1186. u32 sh_num, u32 reg_offset, u32 *value);
  1187. void (*set_vga_state)(struct amdgpu_device *adev, bool state);
  1188. int (*reset)(struct amdgpu_device *adev);
  1189. /* get the reference clock */
  1190. u32 (*get_xclk)(struct amdgpu_device *adev);
  1191. /* MM block clocks */
  1192. int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
  1193. int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
  1194. /* static power management */
  1195. int (*get_pcie_lanes)(struct amdgpu_device *adev);
  1196. void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
  1197. /* get config memsize register */
  1198. u32 (*get_config_memsize)(struct amdgpu_device *adev);
  1199. };
  1200. /*
  1201. * IOCTL.
  1202. */
  1203. int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
  1204. struct drm_file *filp);
  1205. int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
  1206. struct drm_file *filp);
  1207. int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
  1208. struct drm_file *filp);
  1209. int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
  1210. struct drm_file *filp);
  1211. int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1212. struct drm_file *filp);
  1213. int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1214. struct drm_file *filp);
  1215. int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
  1216. struct drm_file *filp);
  1217. int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
  1218. struct drm_file *filp);
  1219. int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1220. int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1221. int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
  1222. struct drm_file *filp);
  1223. int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
  1224. struct drm_file *filp);
  1225. /* VRAM scratch page for HDP bug, default vram page */
  1226. struct amdgpu_vram_scratch {
  1227. struct amdgpu_bo *robj;
  1228. volatile uint32_t *ptr;
  1229. u64 gpu_addr;
  1230. };
  1231. /*
  1232. * ACPI
  1233. */
  1234. struct amdgpu_atif_notification_cfg {
  1235. bool enabled;
  1236. int command_code;
  1237. };
  1238. struct amdgpu_atif_notifications {
  1239. bool display_switch;
  1240. bool expansion_mode_change;
  1241. bool thermal_state;
  1242. bool forced_power_state;
  1243. bool system_power_state;
  1244. bool display_conf_change;
  1245. bool px_gfx_switch;
  1246. bool brightness_change;
  1247. bool dgpu_display_event;
  1248. };
  1249. struct amdgpu_atif_functions {
  1250. bool system_params;
  1251. bool sbios_requests;
  1252. bool select_active_disp;
  1253. bool lid_state;
  1254. bool get_tv_standard;
  1255. bool set_tv_standard;
  1256. bool get_panel_expansion_mode;
  1257. bool set_panel_expansion_mode;
  1258. bool temperature_change;
  1259. bool graphics_device_types;
  1260. };
  1261. struct amdgpu_atif {
  1262. struct amdgpu_atif_notifications notifications;
  1263. struct amdgpu_atif_functions functions;
  1264. struct amdgpu_atif_notification_cfg notification_cfg;
  1265. struct amdgpu_encoder *encoder_for_bl;
  1266. };
  1267. struct amdgpu_atcs_functions {
  1268. bool get_ext_state;
  1269. bool pcie_perf_req;
  1270. bool pcie_dev_rdy;
  1271. bool pcie_bus_width;
  1272. };
  1273. struct amdgpu_atcs {
  1274. struct amdgpu_atcs_functions functions;
  1275. };
  1276. /*
  1277. * CGS
  1278. */
  1279. struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
  1280. void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
  1281. /*
  1282. * Core structure, functions and helpers.
  1283. */
  1284. typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
  1285. typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  1286. typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  1287. typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
  1288. #define AMDGPU_RESET_MAGIC_NUM 64
  1289. struct amdgpu_device {
  1290. struct device *dev;
  1291. struct drm_device *ddev;
  1292. struct pci_dev *pdev;
  1293. #ifdef CONFIG_DRM_AMD_ACP
  1294. struct amdgpu_acp acp;
  1295. #endif
  1296. /* ASIC */
  1297. enum amd_asic_type asic_type;
  1298. uint32_t family;
  1299. uint32_t rev_id;
  1300. uint32_t external_rev_id;
  1301. unsigned long flags;
  1302. int usec_timeout;
  1303. const struct amdgpu_asic_funcs *asic_funcs;
  1304. bool shutdown;
  1305. bool need_dma32;
  1306. bool accel_working;
  1307. struct work_struct reset_work;
  1308. struct notifier_block acpi_nb;
  1309. struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
  1310. struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  1311. unsigned debugfs_count;
  1312. #if defined(CONFIG_DEBUG_FS)
  1313. struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  1314. #endif
  1315. struct amdgpu_atif atif;
  1316. struct amdgpu_atcs atcs;
  1317. struct mutex srbm_mutex;
  1318. /* GRBM index mutex. Protects concurrent access to GRBM index */
  1319. struct mutex grbm_idx_mutex;
  1320. struct dev_pm_domain vga_pm_domain;
  1321. bool have_disp_power_ref;
  1322. /* BIOS */
  1323. bool is_atom_fw;
  1324. uint8_t *bios;
  1325. uint32_t bios_size;
  1326. struct amdgpu_bo *stollen_vga_memory;
  1327. uint32_t bios_scratch_reg_offset;
  1328. uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
  1329. /* Register/doorbell mmio */
  1330. resource_size_t rmmio_base;
  1331. resource_size_t rmmio_size;
  1332. void __iomem *rmmio;
  1333. /* protects concurrent MM_INDEX/DATA based register access */
  1334. spinlock_t mmio_idx_lock;
  1335. /* protects concurrent SMC based register access */
  1336. spinlock_t smc_idx_lock;
  1337. amdgpu_rreg_t smc_rreg;
  1338. amdgpu_wreg_t smc_wreg;
  1339. /* protects concurrent PCIE register access */
  1340. spinlock_t pcie_idx_lock;
  1341. amdgpu_rreg_t pcie_rreg;
  1342. amdgpu_wreg_t pcie_wreg;
  1343. amdgpu_rreg_t pciep_rreg;
  1344. amdgpu_wreg_t pciep_wreg;
  1345. /* protects concurrent UVD register access */
  1346. spinlock_t uvd_ctx_idx_lock;
  1347. amdgpu_rreg_t uvd_ctx_rreg;
  1348. amdgpu_wreg_t uvd_ctx_wreg;
  1349. /* protects concurrent DIDT register access */
  1350. spinlock_t didt_idx_lock;
  1351. amdgpu_rreg_t didt_rreg;
  1352. amdgpu_wreg_t didt_wreg;
  1353. /* protects concurrent gc_cac register access */
  1354. spinlock_t gc_cac_idx_lock;
  1355. amdgpu_rreg_t gc_cac_rreg;
  1356. amdgpu_wreg_t gc_cac_wreg;
  1357. /* protects concurrent ENDPOINT (audio) register access */
  1358. spinlock_t audio_endpt_idx_lock;
  1359. amdgpu_block_rreg_t audio_endpt_rreg;
  1360. amdgpu_block_wreg_t audio_endpt_wreg;
  1361. void __iomem *rio_mem;
  1362. resource_size_t rio_mem_size;
  1363. struct amdgpu_doorbell doorbell;
  1364. /* clock/pll info */
  1365. struct amdgpu_clock clock;
  1366. /* MC */
  1367. struct amdgpu_mc mc;
  1368. struct amdgpu_gart gart;
  1369. struct amdgpu_dummy_page dummy_page;
  1370. struct amdgpu_vm_manager vm_manager;
  1371. struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS];
  1372. /* memory management */
  1373. struct amdgpu_mman mman;
  1374. struct amdgpu_vram_scratch vram_scratch;
  1375. struct amdgpu_wb wb;
  1376. atomic64_t vram_usage;
  1377. atomic64_t vram_vis_usage;
  1378. atomic64_t gtt_usage;
  1379. atomic64_t num_bytes_moved;
  1380. atomic64_t num_evictions;
  1381. atomic64_t num_vram_cpu_page_faults;
  1382. atomic_t gpu_reset_counter;
  1383. atomic_t vram_lost_counter;
  1384. /* data for buffer migration throttling */
  1385. struct {
  1386. spinlock_t lock;
  1387. s64 last_update_us;
  1388. s64 accum_us; /* accumulated microseconds */
  1389. u32 log2_max_MBps;
  1390. } mm_stats;
  1391. /* display */
  1392. bool enable_virtual_display;
  1393. struct amdgpu_mode_info mode_info;
  1394. struct work_struct hotplug_work;
  1395. struct amdgpu_irq_src crtc_irq;
  1396. struct amdgpu_irq_src pageflip_irq;
  1397. struct amdgpu_irq_src hpd_irq;
  1398. /* rings */
  1399. u64 fence_context;
  1400. unsigned num_rings;
  1401. struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
  1402. bool ib_pool_ready;
  1403. struct amdgpu_sa_manager ring_tmp_bo;
  1404. /* interrupts */
  1405. struct amdgpu_irq irq;
  1406. /* powerplay */
  1407. struct amd_powerplay powerplay;
  1408. bool pp_enabled;
  1409. bool pp_force_state_enabled;
  1410. /* dpm */
  1411. struct amdgpu_pm pm;
  1412. u32 cg_flags;
  1413. u32 pg_flags;
  1414. /* amdgpu smumgr */
  1415. struct amdgpu_smumgr smu;
  1416. /* gfx */
  1417. struct amdgpu_gfx gfx;
  1418. /* sdma */
  1419. struct amdgpu_sdma sdma;
  1420. union {
  1421. struct {
  1422. /* uvd */
  1423. struct amdgpu_uvd uvd;
  1424. /* vce */
  1425. struct amdgpu_vce vce;
  1426. };
  1427. /* vcn */
  1428. struct amdgpu_vcn vcn;
  1429. };
  1430. /* firmwares */
  1431. struct amdgpu_firmware firmware;
  1432. /* PSP */
  1433. struct psp_context psp;
  1434. /* GDS */
  1435. struct amdgpu_gds gds;
  1436. struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM];
  1437. int num_ip_blocks;
  1438. struct mutex mn_lock;
  1439. DECLARE_HASHTABLE(mn_hash, 7);
  1440. /* tracking pinned memory */
  1441. u64 vram_pin_size;
  1442. u64 invisible_pin_size;
  1443. u64 gart_pin_size;
  1444. /* amdkfd interface */
  1445. struct kfd_dev *kfd;
  1446. /* delayed work_func for deferring clockgating during resume */
  1447. struct delayed_work late_init_work;
  1448. struct amdgpu_virt virt;
  1449. /* link all shadow bo */
  1450. struct list_head shadow_list;
  1451. struct mutex shadow_list_lock;
  1452. /* link all gtt */
  1453. spinlock_t gtt_list_lock;
  1454. struct list_head gtt_list;
  1455. /* keep an lru list of rings by HW IP */
  1456. struct list_head ring_lru_list;
  1457. spinlock_t ring_lru_list_lock;
  1458. /* record hw reset is performed */
  1459. bool has_hw_reset;
  1460. u8 reset_magic[AMDGPU_RESET_MAGIC_NUM];
  1461. };
  1462. static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
  1463. {
  1464. return container_of(bdev, struct amdgpu_device, mman.bdev);
  1465. }
  1466. int amdgpu_device_init(struct amdgpu_device *adev,
  1467. struct drm_device *ddev,
  1468. struct pci_dev *pdev,
  1469. uint32_t flags);
  1470. void amdgpu_device_fini(struct amdgpu_device *adev);
  1471. int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
  1472. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  1473. uint32_t acc_flags);
  1474. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  1475. uint32_t acc_flags);
  1476. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
  1477. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
  1478. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
  1479. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
  1480. u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
  1481. void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
  1482. /*
  1483. * Registers read & write functions.
  1484. */
  1485. #define AMDGPU_REGS_IDX (1<<0)
  1486. #define AMDGPU_REGS_NO_KIQ (1<<1)
  1487. #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
  1488. #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
  1489. #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
  1490. #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
  1491. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
  1492. #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
  1493. #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
  1494. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1495. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1496. #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
  1497. #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
  1498. #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
  1499. #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
  1500. #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
  1501. #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
  1502. #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
  1503. #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
  1504. #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
  1505. #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
  1506. #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
  1507. #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
  1508. #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
  1509. #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
  1510. #define WREG32_P(reg, val, mask) \
  1511. do { \
  1512. uint32_t tmp_ = RREG32(reg); \
  1513. tmp_ &= (mask); \
  1514. tmp_ |= ((val) & ~(mask)); \
  1515. WREG32(reg, tmp_); \
  1516. } while (0)
  1517. #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
  1518. #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
  1519. #define WREG32_PLL_P(reg, val, mask) \
  1520. do { \
  1521. uint32_t tmp_ = RREG32_PLL(reg); \
  1522. tmp_ &= (mask); \
  1523. tmp_ |= ((val) & ~(mask)); \
  1524. WREG32_PLL(reg, tmp_); \
  1525. } while (0)
  1526. #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
  1527. #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
  1528. #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
  1529. #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
  1530. #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
  1531. #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
  1532. #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
  1533. #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  1534. #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  1535. #define REG_SET_FIELD(orig_val, reg, field, field_val) \
  1536. (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
  1537. (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
  1538. #define REG_GET_FIELD(value, reg, field) \
  1539. (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
  1540. #define WREG32_FIELD(reg, field, val) \
  1541. WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
  1542. #define WREG32_FIELD_OFFSET(reg, offset, field, val) \
  1543. WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
  1544. /*
  1545. * BIOS helpers.
  1546. */
  1547. #define RBIOS8(i) (adev->bios[i])
  1548. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1549. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1550. /*
  1551. * RING helpers.
  1552. */
  1553. static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
  1554. {
  1555. if (ring->count_dw <= 0)
  1556. DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
  1557. ring->ring[ring->wptr++ & ring->buf_mask] = v;
  1558. ring->wptr &= ring->ptr_mask;
  1559. ring->count_dw--;
  1560. }
  1561. static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *src, int count_dw)
  1562. {
  1563. unsigned occupied, chunk1, chunk2;
  1564. void *dst;
  1565. if (unlikely(ring->count_dw < count_dw)) {
  1566. DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
  1567. return;
  1568. }
  1569. occupied = ring->wptr & ring->buf_mask;
  1570. dst = (void *)&ring->ring[occupied];
  1571. chunk1 = ring->buf_mask + 1 - occupied;
  1572. chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
  1573. chunk2 = count_dw - chunk1;
  1574. chunk1 <<= 2;
  1575. chunk2 <<= 2;
  1576. if (chunk1)
  1577. memcpy(dst, src, chunk1);
  1578. if (chunk2) {
  1579. src += chunk1;
  1580. dst = (void *)ring->ring;
  1581. memcpy(dst, src, chunk2);
  1582. }
  1583. ring->wptr += count_dw;
  1584. ring->wptr &= ring->ptr_mask;
  1585. ring->count_dw -= count_dw;
  1586. }
  1587. static inline struct amdgpu_sdma_instance *
  1588. amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
  1589. {
  1590. struct amdgpu_device *adev = ring->adev;
  1591. int i;
  1592. for (i = 0; i < adev->sdma.num_instances; i++)
  1593. if (&adev->sdma.instance[i].ring == ring)
  1594. break;
  1595. if (i < AMDGPU_MAX_SDMA_INSTANCES)
  1596. return &adev->sdma.instance[i];
  1597. else
  1598. return NULL;
  1599. }
  1600. /*
  1601. * ASICs macro.
  1602. */
  1603. #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
  1604. #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
  1605. #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
  1606. #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
  1607. #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
  1608. #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
  1609. #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
  1610. #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
  1611. #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
  1612. #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
  1613. #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
  1614. #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
  1615. #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
  1616. #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
  1617. #define amdgpu_gart_get_vm_pde(adev, addr) (adev)->gart.gart_funcs->get_vm_pde((adev), (addr))
  1618. #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
  1619. #define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
  1620. #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)))
  1621. #define amdgpu_vm_get_pte_flags(adev, flags) (adev)->gart.gart_funcs->get_vm_pte_flags((adev),(flags))
  1622. #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
  1623. #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
  1624. #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
  1625. #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
  1626. #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
  1627. #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
  1628. #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
  1629. #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
  1630. #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
  1631. #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
  1632. #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))
  1633. #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
  1634. #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
  1635. #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
  1636. #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
  1637. #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
  1638. #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
  1639. #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
  1640. #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
  1641. #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
  1642. #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
  1643. #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
  1644. #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
  1645. #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
  1646. #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
  1647. #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
  1648. #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
  1649. #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
  1650. #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
  1651. #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
  1652. #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
  1653. #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
  1654. #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
  1655. #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
  1656. #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
  1657. #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
  1658. #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))
  1659. #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
  1660. #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
  1661. #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b))
  1662. #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
  1663. #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
  1664. #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
  1665. #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
  1666. #define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
  1667. /* Common functions */
  1668. int amdgpu_gpu_reset(struct amdgpu_device *adev);
  1669. bool amdgpu_need_backup(struct amdgpu_device *adev);
  1670. void amdgpu_pci_config_reset(struct amdgpu_device *adev);
  1671. bool amdgpu_need_post(struct amdgpu_device *adev);
  1672. void amdgpu_update_display_priority(struct amdgpu_device *adev);
  1673. int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
  1674. void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes);
  1675. void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
  1676. bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
  1677. int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
  1678. int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
  1679. uint32_t flags);
  1680. bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
  1681. struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
  1682. bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
  1683. unsigned long end);
  1684. bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
  1685. int *last_invalidated);
  1686. bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
  1687. uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
  1688. struct ttm_mem_reg *mem);
  1689. void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
  1690. void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
  1691. void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
  1692. int amdgpu_ttm_init(struct amdgpu_device *adev);
  1693. void amdgpu_ttm_fini(struct amdgpu_device *adev);
  1694. void amdgpu_program_register_sequence(struct amdgpu_device *adev,
  1695. const u32 *registers,
  1696. const u32 array_size);
  1697. bool amdgpu_device_is_px(struct drm_device *dev);
  1698. /* atpx handler */
  1699. #if defined(CONFIG_VGA_SWITCHEROO)
  1700. void amdgpu_register_atpx_handler(void);
  1701. void amdgpu_unregister_atpx_handler(void);
  1702. bool amdgpu_has_atpx_dgpu_power_cntl(void);
  1703. bool amdgpu_is_atpx_hybrid(void);
  1704. bool amdgpu_atpx_dgpu_req_power_for_displays(void);
  1705. bool amdgpu_has_atpx(void);
  1706. #else
  1707. static inline void amdgpu_register_atpx_handler(void) {}
  1708. static inline void amdgpu_unregister_atpx_handler(void) {}
  1709. static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
  1710. static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
  1711. static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
  1712. static inline bool amdgpu_has_atpx(void) { return false; }
  1713. #endif
  1714. /*
  1715. * KMS
  1716. */
  1717. extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
  1718. extern const int amdgpu_max_kms_ioctl;
  1719. bool amdgpu_kms_vram_lost(struct amdgpu_device *adev,
  1720. struct amdgpu_fpriv *fpriv);
  1721. int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
  1722. void amdgpu_driver_unload_kms(struct drm_device *dev);
  1723. void amdgpu_driver_lastclose_kms(struct drm_device *dev);
  1724. int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
  1725. void amdgpu_driver_postclose_kms(struct drm_device *dev,
  1726. struct drm_file *file_priv);
  1727. int amdgpu_suspend(struct amdgpu_device *adev);
  1728. int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
  1729. int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
  1730. u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
  1731. int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  1732. void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  1733. long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
  1734. unsigned long arg);
  1735. /*
  1736. * functions used by amdgpu_encoder.c
  1737. */
  1738. struct amdgpu_afmt_acr {
  1739. u32 clock;
  1740. int n_32khz;
  1741. int cts_32khz;
  1742. int n_44_1khz;
  1743. int cts_44_1khz;
  1744. int n_48khz;
  1745. int cts_48khz;
  1746. };
  1747. struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
  1748. /* amdgpu_acpi.c */
  1749. #if defined(CONFIG_ACPI)
  1750. int amdgpu_acpi_init(struct amdgpu_device *adev);
  1751. void amdgpu_acpi_fini(struct amdgpu_device *adev);
  1752. bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
  1753. int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
  1754. u8 perf_req, bool advertise);
  1755. int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
  1756. #else
  1757. static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
  1758. static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
  1759. #endif
  1760. struct amdgpu_bo_va_mapping *
  1761. amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
  1762. uint64_t addr, struct amdgpu_bo **bo);
  1763. int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
  1764. #include "amdgpu_object.h"
  1765. #endif