amdgpu.h 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419
  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/interval_tree.h>
  35. #include <linux/hashtable.h>
  36. #include <linux/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 "amd_shared.h"
  46. #include "amdgpu_mode.h"
  47. #include "amdgpu_ih.h"
  48. #include "amdgpu_irq.h"
  49. #include "amdgpu_ucode.h"
  50. #include "amdgpu_gds.h"
  51. #include "amd_powerplay.h"
  52. #include "gpu_scheduler.h"
  53. /*
  54. * Modules parameters.
  55. */
  56. extern int amdgpu_modeset;
  57. extern int amdgpu_vram_limit;
  58. extern int amdgpu_gart_size;
  59. extern int amdgpu_benchmarking;
  60. extern int amdgpu_testing;
  61. extern int amdgpu_audio;
  62. extern int amdgpu_disp_priority;
  63. extern int amdgpu_hw_i2c;
  64. extern int amdgpu_pcie_gen2;
  65. extern int amdgpu_msi;
  66. extern int amdgpu_lockup_timeout;
  67. extern int amdgpu_dpm;
  68. extern int amdgpu_smc_load_fw;
  69. extern int amdgpu_aspm;
  70. extern int amdgpu_runtime_pm;
  71. extern unsigned amdgpu_ip_block_mask;
  72. extern int amdgpu_bapm;
  73. extern int amdgpu_deep_color;
  74. extern int amdgpu_vm_size;
  75. extern int amdgpu_vm_block_size;
  76. extern int amdgpu_vm_fault_stop;
  77. extern int amdgpu_vm_debug;
  78. extern int amdgpu_sched_jobs;
  79. extern int amdgpu_sched_hw_submission;
  80. extern int amdgpu_powerplay;
  81. #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
  82. #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  83. #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  84. /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
  85. #define AMDGPU_IB_POOL_SIZE 16
  86. #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
  87. #define AMDGPUFB_CONN_LIMIT 4
  88. #define AMDGPU_BIOS_NUM_SCRATCH 8
  89. /* max number of rings */
  90. #define AMDGPU_MAX_RINGS 16
  91. #define AMDGPU_MAX_GFX_RINGS 1
  92. #define AMDGPU_MAX_COMPUTE_RINGS 8
  93. #define AMDGPU_MAX_VCE_RINGS 2
  94. /* max number of IP instances */
  95. #define AMDGPU_MAX_SDMA_INSTANCES 2
  96. /* number of hw syncs before falling back on blocking */
  97. #define AMDGPU_NUM_SYNCS 4
  98. /* hardcode that limit for now */
  99. #define AMDGPU_VA_RESERVED_SIZE (8 << 20)
  100. /* hard reset data */
  101. #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
  102. /* reset flags */
  103. #define AMDGPU_RESET_GFX (1 << 0)
  104. #define AMDGPU_RESET_COMPUTE (1 << 1)
  105. #define AMDGPU_RESET_DMA (1 << 2)
  106. #define AMDGPU_RESET_CP (1 << 3)
  107. #define AMDGPU_RESET_GRBM (1 << 4)
  108. #define AMDGPU_RESET_DMA1 (1 << 5)
  109. #define AMDGPU_RESET_RLC (1 << 6)
  110. #define AMDGPU_RESET_SEM (1 << 7)
  111. #define AMDGPU_RESET_IH (1 << 8)
  112. #define AMDGPU_RESET_VMC (1 << 9)
  113. #define AMDGPU_RESET_MC (1 << 10)
  114. #define AMDGPU_RESET_DISPLAY (1 << 11)
  115. #define AMDGPU_RESET_UVD (1 << 12)
  116. #define AMDGPU_RESET_VCE (1 << 13)
  117. #define AMDGPU_RESET_VCE1 (1 << 14)
  118. /* CG block flags */
  119. #define AMDGPU_CG_BLOCK_GFX (1 << 0)
  120. #define AMDGPU_CG_BLOCK_MC (1 << 1)
  121. #define AMDGPU_CG_BLOCK_SDMA (1 << 2)
  122. #define AMDGPU_CG_BLOCK_UVD (1 << 3)
  123. #define AMDGPU_CG_BLOCK_VCE (1 << 4)
  124. #define AMDGPU_CG_BLOCK_HDP (1 << 5)
  125. #define AMDGPU_CG_BLOCK_BIF (1 << 6)
  126. /* CG flags */
  127. #define AMDGPU_CG_SUPPORT_GFX_MGCG (1 << 0)
  128. #define AMDGPU_CG_SUPPORT_GFX_MGLS (1 << 1)
  129. #define AMDGPU_CG_SUPPORT_GFX_CGCG (1 << 2)
  130. #define AMDGPU_CG_SUPPORT_GFX_CGLS (1 << 3)
  131. #define AMDGPU_CG_SUPPORT_GFX_CGTS (1 << 4)
  132. #define AMDGPU_CG_SUPPORT_GFX_CGTS_LS (1 << 5)
  133. #define AMDGPU_CG_SUPPORT_GFX_CP_LS (1 << 6)
  134. #define AMDGPU_CG_SUPPORT_GFX_RLC_LS (1 << 7)
  135. #define AMDGPU_CG_SUPPORT_MC_LS (1 << 8)
  136. #define AMDGPU_CG_SUPPORT_MC_MGCG (1 << 9)
  137. #define AMDGPU_CG_SUPPORT_SDMA_LS (1 << 10)
  138. #define AMDGPU_CG_SUPPORT_SDMA_MGCG (1 << 11)
  139. #define AMDGPU_CG_SUPPORT_BIF_LS (1 << 12)
  140. #define AMDGPU_CG_SUPPORT_UVD_MGCG (1 << 13)
  141. #define AMDGPU_CG_SUPPORT_VCE_MGCG (1 << 14)
  142. #define AMDGPU_CG_SUPPORT_HDP_LS (1 << 15)
  143. #define AMDGPU_CG_SUPPORT_HDP_MGCG (1 << 16)
  144. /* PG flags */
  145. #define AMDGPU_PG_SUPPORT_GFX_PG (1 << 0)
  146. #define AMDGPU_PG_SUPPORT_GFX_SMG (1 << 1)
  147. #define AMDGPU_PG_SUPPORT_GFX_DMG (1 << 2)
  148. #define AMDGPU_PG_SUPPORT_UVD (1 << 3)
  149. #define AMDGPU_PG_SUPPORT_VCE (1 << 4)
  150. #define AMDGPU_PG_SUPPORT_CP (1 << 5)
  151. #define AMDGPU_PG_SUPPORT_GDS (1 << 6)
  152. #define AMDGPU_PG_SUPPORT_RLC_SMU_HS (1 << 7)
  153. #define AMDGPU_PG_SUPPORT_SDMA (1 << 8)
  154. #define AMDGPU_PG_SUPPORT_ACP (1 << 9)
  155. #define AMDGPU_PG_SUPPORT_SAMU (1 << 10)
  156. /* GFX current status */
  157. #define AMDGPU_GFX_NORMAL_MODE 0x00000000L
  158. #define AMDGPU_GFX_SAFE_MODE 0x00000001L
  159. #define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
  160. #define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
  161. #define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
  162. /* max cursor sizes (in pixels) */
  163. #define CIK_CURSOR_WIDTH 128
  164. #define CIK_CURSOR_HEIGHT 128
  165. struct amdgpu_device;
  166. struct amdgpu_fence;
  167. struct amdgpu_ib;
  168. struct amdgpu_vm;
  169. struct amdgpu_ring;
  170. struct amdgpu_cs_parser;
  171. struct amdgpu_job;
  172. struct amdgpu_irq_src;
  173. struct amdgpu_fpriv;
  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. int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
  197. enum amd_ip_block_type block_type,
  198. enum amd_clockgating_state state);
  199. int amdgpu_set_powergating_state(struct amdgpu_device *adev,
  200. enum amd_ip_block_type block_type,
  201. enum amd_powergating_state state);
  202. struct amdgpu_ip_block_version {
  203. enum amd_ip_block_type type;
  204. u32 major;
  205. u32 minor;
  206. u32 rev;
  207. const struct amd_ip_funcs *funcs;
  208. };
  209. int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
  210. enum amd_ip_block_type type,
  211. u32 major, u32 minor);
  212. const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
  213. struct amdgpu_device *adev,
  214. enum amd_ip_block_type type);
  215. /* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
  216. struct amdgpu_buffer_funcs {
  217. /* maximum bytes in a single operation */
  218. uint32_t copy_max_bytes;
  219. /* number of dw to reserve per operation */
  220. unsigned copy_num_dw;
  221. /* used for buffer migration */
  222. void (*emit_copy_buffer)(struct amdgpu_ib *ib,
  223. /* src addr in bytes */
  224. uint64_t src_offset,
  225. /* dst addr in bytes */
  226. uint64_t dst_offset,
  227. /* number of byte to transfer */
  228. uint32_t byte_count);
  229. /* maximum bytes in a single operation */
  230. uint32_t fill_max_bytes;
  231. /* number of dw to reserve per operation */
  232. unsigned fill_num_dw;
  233. /* used for buffer clearing */
  234. void (*emit_fill_buffer)(struct amdgpu_ib *ib,
  235. /* value to write to memory */
  236. uint32_t src_data,
  237. /* dst addr in bytes */
  238. uint64_t dst_offset,
  239. /* number of byte to fill */
  240. uint32_t byte_count);
  241. };
  242. /* provided by hw blocks that can write ptes, e.g., sdma */
  243. struct amdgpu_vm_pte_funcs {
  244. /* copy pte entries from GART */
  245. void (*copy_pte)(struct amdgpu_ib *ib,
  246. uint64_t pe, uint64_t src,
  247. unsigned count);
  248. /* write pte one entry at a time with addr mapping */
  249. void (*write_pte)(struct amdgpu_ib *ib,
  250. uint64_t pe,
  251. uint64_t addr, unsigned count,
  252. uint32_t incr, uint32_t flags);
  253. /* for linear pte/pde updates without addr mapping */
  254. void (*set_pte_pde)(struct amdgpu_ib *ib,
  255. uint64_t pe,
  256. uint64_t addr, unsigned count,
  257. uint32_t incr, uint32_t flags);
  258. /* pad the indirect buffer to the necessary number of dw */
  259. void (*pad_ib)(struct amdgpu_ib *ib);
  260. };
  261. /* provided by the gmc block */
  262. struct amdgpu_gart_funcs {
  263. /* flush the vm tlb via mmio */
  264. void (*flush_gpu_tlb)(struct amdgpu_device *adev,
  265. uint32_t vmid);
  266. /* write pte/pde updates using the cpu */
  267. int (*set_pte_pde)(struct amdgpu_device *adev,
  268. void *cpu_pt_addr, /* cpu addr of page table */
  269. uint32_t gpu_page_idx, /* pte/pde to update */
  270. uint64_t addr, /* addr to write into pte/pde */
  271. uint32_t flags); /* access flags */
  272. };
  273. /* provided by the ih block */
  274. struct amdgpu_ih_funcs {
  275. /* ring read/write ptr handling, called from interrupt context */
  276. u32 (*get_wptr)(struct amdgpu_device *adev);
  277. void (*decode_iv)(struct amdgpu_device *adev,
  278. struct amdgpu_iv_entry *entry);
  279. void (*set_rptr)(struct amdgpu_device *adev);
  280. };
  281. /* provided by hw blocks that expose a ring buffer for commands */
  282. struct amdgpu_ring_funcs {
  283. /* ring read/write ptr handling */
  284. u32 (*get_rptr)(struct amdgpu_ring *ring);
  285. u32 (*get_wptr)(struct amdgpu_ring *ring);
  286. void (*set_wptr)(struct amdgpu_ring *ring);
  287. /* validating and patching of IBs */
  288. int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
  289. /* command emit functions */
  290. void (*emit_ib)(struct amdgpu_ring *ring,
  291. struct amdgpu_ib *ib);
  292. void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
  293. uint64_t seq, unsigned flags);
  294. void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
  295. uint64_t pd_addr);
  296. void (*emit_hdp_flush)(struct amdgpu_ring *ring);
  297. void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
  298. uint32_t gds_base, uint32_t gds_size,
  299. uint32_t gws_base, uint32_t gws_size,
  300. uint32_t oa_base, uint32_t oa_size);
  301. /* testing functions */
  302. int (*test_ring)(struct amdgpu_ring *ring);
  303. int (*test_ib)(struct amdgpu_ring *ring);
  304. /* insert NOP packets */
  305. void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
  306. };
  307. /*
  308. * BIOS.
  309. */
  310. bool amdgpu_get_bios(struct amdgpu_device *adev);
  311. bool amdgpu_read_bios(struct amdgpu_device *adev);
  312. /*
  313. * Dummy page
  314. */
  315. struct amdgpu_dummy_page {
  316. struct page *page;
  317. dma_addr_t addr;
  318. };
  319. int amdgpu_dummy_page_init(struct amdgpu_device *adev);
  320. void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
  321. /*
  322. * Clocks
  323. */
  324. #define AMDGPU_MAX_PPLL 3
  325. struct amdgpu_clock {
  326. struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
  327. struct amdgpu_pll spll;
  328. struct amdgpu_pll mpll;
  329. /* 10 Khz units */
  330. uint32_t default_mclk;
  331. uint32_t default_sclk;
  332. uint32_t default_dispclk;
  333. uint32_t current_dispclk;
  334. uint32_t dp_extclk;
  335. uint32_t max_pixel_clock;
  336. };
  337. /*
  338. * Fences.
  339. */
  340. struct amdgpu_fence_driver {
  341. uint64_t gpu_addr;
  342. volatile uint32_t *cpu_addr;
  343. /* sync_seq is protected by ring emission lock */
  344. uint64_t sync_seq;
  345. atomic64_t last_seq;
  346. bool initialized;
  347. struct amdgpu_irq_src *irq_src;
  348. unsigned irq_type;
  349. struct timer_list fallback_timer;
  350. wait_queue_head_t fence_queue;
  351. };
  352. /* some special values for the owner field */
  353. #define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
  354. #define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
  355. #define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
  356. #define AMDGPU_FENCE_FLAG_INT (1 << 1)
  357. struct amdgpu_fence {
  358. struct fence base;
  359. /* RB, DMA, etc. */
  360. struct amdgpu_ring *ring;
  361. uint64_t seq;
  362. /* filp or special value for fence creator */
  363. void *owner;
  364. wait_queue_t fence_wake;
  365. };
  366. struct amdgpu_user_fence {
  367. /* write-back bo */
  368. struct amdgpu_bo *bo;
  369. /* write-back address offset to bo start */
  370. uint32_t offset;
  371. };
  372. int amdgpu_fence_driver_init(struct amdgpu_device *adev);
  373. void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
  374. void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
  375. int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
  376. int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
  377. struct amdgpu_irq_src *irq_src,
  378. unsigned irq_type);
  379. void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
  380. void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
  381. int amdgpu_fence_emit(struct amdgpu_ring *ring, void *owner,
  382. struct amdgpu_fence **fence);
  383. void amdgpu_fence_process(struct amdgpu_ring *ring);
  384. int amdgpu_fence_wait_next(struct amdgpu_ring *ring);
  385. int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
  386. unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
  387. /*
  388. * TTM.
  389. */
  390. struct amdgpu_mman {
  391. struct ttm_bo_global_ref bo_global_ref;
  392. struct drm_global_reference mem_global_ref;
  393. struct ttm_bo_device bdev;
  394. bool mem_global_referenced;
  395. bool initialized;
  396. #if defined(CONFIG_DEBUG_FS)
  397. struct dentry *vram;
  398. struct dentry *gtt;
  399. #endif
  400. /* buffer handling */
  401. const struct amdgpu_buffer_funcs *buffer_funcs;
  402. struct amdgpu_ring *buffer_funcs_ring;
  403. };
  404. int amdgpu_copy_buffer(struct amdgpu_ring *ring,
  405. uint64_t src_offset,
  406. uint64_t dst_offset,
  407. uint32_t byte_count,
  408. struct reservation_object *resv,
  409. struct fence **fence);
  410. int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
  411. struct amdgpu_bo_list_entry {
  412. struct amdgpu_bo *robj;
  413. struct ttm_validate_buffer tv;
  414. struct amdgpu_bo_va *bo_va;
  415. uint32_t priority;
  416. };
  417. struct amdgpu_bo_va_mapping {
  418. struct list_head list;
  419. struct interval_tree_node it;
  420. uint64_t offset;
  421. uint32_t flags;
  422. };
  423. /* bo virtual addresses in a specific vm */
  424. struct amdgpu_bo_va {
  425. struct mutex mutex;
  426. /* protected by bo being reserved */
  427. struct list_head bo_list;
  428. struct fence *last_pt_update;
  429. unsigned ref_count;
  430. /* protected by vm mutex and spinlock */
  431. struct list_head vm_status;
  432. /* mappings for this bo_va */
  433. struct list_head invalids;
  434. struct list_head valids;
  435. /* constant after initialization */
  436. struct amdgpu_vm *vm;
  437. struct amdgpu_bo *bo;
  438. };
  439. #define AMDGPU_GEM_DOMAIN_MAX 0x3
  440. struct amdgpu_bo {
  441. /* Protected by gem.mutex */
  442. struct list_head list;
  443. /* Protected by tbo.reserved */
  444. u32 prefered_domains;
  445. u32 allowed_domains;
  446. struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
  447. struct ttm_placement placement;
  448. struct ttm_buffer_object tbo;
  449. struct ttm_bo_kmap_obj kmap;
  450. u64 flags;
  451. unsigned pin_count;
  452. void *kptr;
  453. u64 tiling_flags;
  454. u64 metadata_flags;
  455. void *metadata;
  456. u32 metadata_size;
  457. /* list of all virtual address to which this bo
  458. * is associated to
  459. */
  460. struct list_head va;
  461. /* Constant after initialization */
  462. struct amdgpu_device *adev;
  463. struct drm_gem_object gem_base;
  464. struct amdgpu_bo *parent;
  465. struct ttm_bo_kmap_obj dma_buf_vmap;
  466. pid_t pid;
  467. struct amdgpu_mn *mn;
  468. struct list_head mn_list;
  469. };
  470. #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
  471. void amdgpu_gem_object_free(struct drm_gem_object *obj);
  472. int amdgpu_gem_object_open(struct drm_gem_object *obj,
  473. struct drm_file *file_priv);
  474. void amdgpu_gem_object_close(struct drm_gem_object *obj,
  475. struct drm_file *file_priv);
  476. unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
  477. struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
  478. struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
  479. struct dma_buf_attachment *attach,
  480. struct sg_table *sg);
  481. struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
  482. struct drm_gem_object *gobj,
  483. int flags);
  484. int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
  485. void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
  486. struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
  487. void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
  488. void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  489. int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
  490. /* sub-allocation manager, it has to be protected by another lock.
  491. * By conception this is an helper for other part of the driver
  492. * like the indirect buffer or semaphore, which both have their
  493. * locking.
  494. *
  495. * Principe is simple, we keep a list of sub allocation in offset
  496. * order (first entry has offset == 0, last entry has the highest
  497. * offset).
  498. *
  499. * When allocating new object we first check if there is room at
  500. * the end total_size - (last_object_offset + last_object_size) >=
  501. * alloc_size. If so we allocate new object there.
  502. *
  503. * When there is not enough room at the end, we start waiting for
  504. * each sub object until we reach object_offset+object_size >=
  505. * alloc_size, this object then become the sub object we return.
  506. *
  507. * Alignment can't be bigger than page size.
  508. *
  509. * Hole are not considered for allocation to keep things simple.
  510. * Assumption is that there won't be hole (all object on same
  511. * alignment).
  512. */
  513. struct amdgpu_sa_manager {
  514. wait_queue_head_t wq;
  515. struct amdgpu_bo *bo;
  516. struct list_head *hole;
  517. struct list_head flist[AMDGPU_MAX_RINGS];
  518. struct list_head olist;
  519. unsigned size;
  520. uint64_t gpu_addr;
  521. void *cpu_ptr;
  522. uint32_t domain;
  523. uint32_t align;
  524. };
  525. struct amdgpu_sa_bo;
  526. /* sub-allocation buffer */
  527. struct amdgpu_sa_bo {
  528. struct list_head olist;
  529. struct list_head flist;
  530. struct amdgpu_sa_manager *manager;
  531. unsigned soffset;
  532. unsigned eoffset;
  533. struct fence *fence;
  534. };
  535. /*
  536. * GEM objects.
  537. */
  538. struct amdgpu_gem {
  539. struct mutex mutex;
  540. struct list_head objects;
  541. };
  542. int amdgpu_gem_init(struct amdgpu_device *adev);
  543. void amdgpu_gem_fini(struct amdgpu_device *adev);
  544. int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  545. int alignment, u32 initial_domain,
  546. u64 flags, bool kernel,
  547. struct drm_gem_object **obj);
  548. int amdgpu_mode_dumb_create(struct drm_file *file_priv,
  549. struct drm_device *dev,
  550. struct drm_mode_create_dumb *args);
  551. int amdgpu_mode_dumb_mmap(struct drm_file *filp,
  552. struct drm_device *dev,
  553. uint32_t handle, uint64_t *offset_p);
  554. /*
  555. * Synchronization
  556. */
  557. struct amdgpu_sync {
  558. DECLARE_HASHTABLE(fences, 4);
  559. struct fence *last_vm_update;
  560. };
  561. void amdgpu_sync_create(struct amdgpu_sync *sync);
  562. int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
  563. struct fence *f);
  564. int amdgpu_sync_resv(struct amdgpu_device *adev,
  565. struct amdgpu_sync *sync,
  566. struct reservation_object *resv,
  567. void *owner);
  568. struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
  569. int amdgpu_sync_wait(struct amdgpu_sync *sync);
  570. void amdgpu_sync_free(struct amdgpu_device *adev, struct amdgpu_sync *sync,
  571. struct fence *fence);
  572. /*
  573. * GART structures, functions & helpers
  574. */
  575. struct amdgpu_mc;
  576. #define AMDGPU_GPU_PAGE_SIZE 4096
  577. #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
  578. #define AMDGPU_GPU_PAGE_SHIFT 12
  579. #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
  580. struct amdgpu_gart {
  581. dma_addr_t table_addr;
  582. struct amdgpu_bo *robj;
  583. void *ptr;
  584. unsigned num_gpu_pages;
  585. unsigned num_cpu_pages;
  586. unsigned table_size;
  587. struct page **pages;
  588. dma_addr_t *pages_addr;
  589. bool ready;
  590. const struct amdgpu_gart_funcs *gart_funcs;
  591. };
  592. int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
  593. void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
  594. int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
  595. void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
  596. int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
  597. void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
  598. int amdgpu_gart_init(struct amdgpu_device *adev);
  599. void amdgpu_gart_fini(struct amdgpu_device *adev);
  600. void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
  601. int pages);
  602. int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
  603. int pages, struct page **pagelist,
  604. dma_addr_t *dma_addr, uint32_t flags);
  605. /*
  606. * GPU MC structures, functions & helpers
  607. */
  608. struct amdgpu_mc {
  609. resource_size_t aper_size;
  610. resource_size_t aper_base;
  611. resource_size_t agp_base;
  612. /* for some chips with <= 32MB we need to lie
  613. * about vram size near mc fb location */
  614. u64 mc_vram_size;
  615. u64 visible_vram_size;
  616. u64 gtt_size;
  617. u64 gtt_start;
  618. u64 gtt_end;
  619. u64 vram_start;
  620. u64 vram_end;
  621. unsigned vram_width;
  622. u64 real_vram_size;
  623. int vram_mtrr;
  624. u64 gtt_base_align;
  625. u64 mc_mask;
  626. const struct firmware *fw; /* MC firmware */
  627. uint32_t fw_version;
  628. struct amdgpu_irq_src vm_fault;
  629. uint32_t vram_type;
  630. };
  631. /*
  632. * GPU doorbell structures, functions & helpers
  633. */
  634. typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
  635. {
  636. AMDGPU_DOORBELL_KIQ = 0x000,
  637. AMDGPU_DOORBELL_HIQ = 0x001,
  638. AMDGPU_DOORBELL_DIQ = 0x002,
  639. AMDGPU_DOORBELL_MEC_RING0 = 0x010,
  640. AMDGPU_DOORBELL_MEC_RING1 = 0x011,
  641. AMDGPU_DOORBELL_MEC_RING2 = 0x012,
  642. AMDGPU_DOORBELL_MEC_RING3 = 0x013,
  643. AMDGPU_DOORBELL_MEC_RING4 = 0x014,
  644. AMDGPU_DOORBELL_MEC_RING5 = 0x015,
  645. AMDGPU_DOORBELL_MEC_RING6 = 0x016,
  646. AMDGPU_DOORBELL_MEC_RING7 = 0x017,
  647. AMDGPU_DOORBELL_GFX_RING0 = 0x020,
  648. AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
  649. AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
  650. AMDGPU_DOORBELL_IH = 0x1E8,
  651. AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
  652. AMDGPU_DOORBELL_INVALID = 0xFFFF
  653. } AMDGPU_DOORBELL_ASSIGNMENT;
  654. struct amdgpu_doorbell {
  655. /* doorbell mmio */
  656. resource_size_t base;
  657. resource_size_t size;
  658. u32 __iomem *ptr;
  659. u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
  660. };
  661. void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
  662. phys_addr_t *aperture_base,
  663. size_t *aperture_size,
  664. size_t *start_offset);
  665. /*
  666. * IRQS.
  667. */
  668. struct amdgpu_flip_work {
  669. struct work_struct flip_work;
  670. struct work_struct unpin_work;
  671. struct amdgpu_device *adev;
  672. int crtc_id;
  673. uint64_t base;
  674. struct drm_pending_vblank_event *event;
  675. struct amdgpu_bo *old_rbo;
  676. struct fence *excl;
  677. unsigned shared_count;
  678. struct fence **shared;
  679. };
  680. /*
  681. * CP & rings.
  682. */
  683. struct amdgpu_ib {
  684. struct amdgpu_sa_bo *sa_bo;
  685. uint32_t length_dw;
  686. uint64_t gpu_addr;
  687. uint32_t *ptr;
  688. struct amdgpu_ring *ring;
  689. struct amdgpu_fence *fence;
  690. struct amdgpu_user_fence *user;
  691. bool grabbed_vmid;
  692. struct amdgpu_vm *vm;
  693. struct amdgpu_ctx *ctx;
  694. struct amdgpu_sync sync;
  695. uint32_t gds_base, gds_size;
  696. uint32_t gws_base, gws_size;
  697. uint32_t oa_base, oa_size;
  698. uint32_t flags;
  699. /* resulting sequence number */
  700. uint64_t sequence;
  701. };
  702. enum amdgpu_ring_type {
  703. AMDGPU_RING_TYPE_GFX,
  704. AMDGPU_RING_TYPE_COMPUTE,
  705. AMDGPU_RING_TYPE_SDMA,
  706. AMDGPU_RING_TYPE_UVD,
  707. AMDGPU_RING_TYPE_VCE
  708. };
  709. extern struct amd_sched_backend_ops amdgpu_sched_ops;
  710. int amdgpu_sched_ib_submit_kernel_helper(struct amdgpu_device *adev,
  711. struct amdgpu_ring *ring,
  712. struct amdgpu_ib *ibs,
  713. unsigned num_ibs,
  714. int (*free_job)(struct amdgpu_job *),
  715. void *owner,
  716. struct fence **fence);
  717. struct amdgpu_ring {
  718. struct amdgpu_device *adev;
  719. const struct amdgpu_ring_funcs *funcs;
  720. struct amdgpu_fence_driver fence_drv;
  721. struct amd_gpu_scheduler sched;
  722. spinlock_t fence_lock;
  723. struct mutex *ring_lock;
  724. struct amdgpu_bo *ring_obj;
  725. volatile uint32_t *ring;
  726. unsigned rptr_offs;
  727. u64 next_rptr_gpu_addr;
  728. volatile u32 *next_rptr_cpu_addr;
  729. unsigned wptr;
  730. unsigned wptr_old;
  731. unsigned ring_size;
  732. unsigned ring_free_dw;
  733. int count_dw;
  734. uint64_t gpu_addr;
  735. uint32_t align_mask;
  736. uint32_t ptr_mask;
  737. bool ready;
  738. u32 nop;
  739. u32 idx;
  740. u32 me;
  741. u32 pipe;
  742. u32 queue;
  743. struct amdgpu_bo *mqd_obj;
  744. u32 doorbell_index;
  745. bool use_doorbell;
  746. unsigned wptr_offs;
  747. unsigned next_rptr_offs;
  748. unsigned fence_offs;
  749. struct amdgpu_ctx *current_ctx;
  750. enum amdgpu_ring_type type;
  751. char name[16];
  752. bool is_pte_ring;
  753. };
  754. /*
  755. * VM
  756. */
  757. /* maximum number of VMIDs */
  758. #define AMDGPU_NUM_VM 16
  759. /* number of entries in page table */
  760. #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
  761. /* PTBs (Page Table Blocks) need to be aligned to 32K */
  762. #define AMDGPU_VM_PTB_ALIGN_SIZE 32768
  763. #define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
  764. #define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
  765. #define AMDGPU_PTE_VALID (1 << 0)
  766. #define AMDGPU_PTE_SYSTEM (1 << 1)
  767. #define AMDGPU_PTE_SNOOPED (1 << 2)
  768. /* VI only */
  769. #define AMDGPU_PTE_EXECUTABLE (1 << 4)
  770. #define AMDGPU_PTE_READABLE (1 << 5)
  771. #define AMDGPU_PTE_WRITEABLE (1 << 6)
  772. /* PTE (Page Table Entry) fragment field for different page sizes */
  773. #define AMDGPU_PTE_FRAG_4KB (0 << 7)
  774. #define AMDGPU_PTE_FRAG_64KB (4 << 7)
  775. #define AMDGPU_LOG2_PAGES_PER_FRAG 4
  776. /* How to programm VM fault handling */
  777. #define AMDGPU_VM_FAULT_STOP_NEVER 0
  778. #define AMDGPU_VM_FAULT_STOP_FIRST 1
  779. #define AMDGPU_VM_FAULT_STOP_ALWAYS 2
  780. struct amdgpu_vm_pt {
  781. struct amdgpu_bo_list_entry entry;
  782. uint64_t addr;
  783. };
  784. struct amdgpu_vm_id {
  785. unsigned id;
  786. uint64_t pd_gpu_addr;
  787. /* last flushed PD/PT update */
  788. struct fence *flushed_updates;
  789. };
  790. struct amdgpu_vm {
  791. /* tree of virtual addresses mapped */
  792. spinlock_t it_lock;
  793. struct rb_root va;
  794. /* protecting invalidated */
  795. spinlock_t status_lock;
  796. /* BOs moved, but not yet updated in the PT */
  797. struct list_head invalidated;
  798. /* BOs cleared in the PT because of a move */
  799. struct list_head cleared;
  800. /* BO mappings freed, but not yet updated in the PT */
  801. struct list_head freed;
  802. /* contains the page directory */
  803. struct amdgpu_bo *page_directory;
  804. unsigned max_pde_used;
  805. struct fence *page_directory_fence;
  806. /* array of page tables, one for each page directory entry */
  807. struct amdgpu_vm_pt *page_tables;
  808. /* for id and flush management per ring */
  809. struct amdgpu_vm_id ids[AMDGPU_MAX_RINGS];
  810. /* protecting freed */
  811. spinlock_t freed_lock;
  812. };
  813. struct amdgpu_vm_manager {
  814. /* protecting IDs */
  815. struct mutex lock;
  816. struct {
  817. struct fence *active;
  818. atomic_long_t owner;
  819. } ids[AMDGPU_NUM_VM];
  820. uint32_t max_pfn;
  821. /* number of VMIDs */
  822. unsigned nvm;
  823. /* vram base address for page table entry */
  824. u64 vram_base_offset;
  825. /* is vm enabled? */
  826. bool enabled;
  827. /* vm pte handling */
  828. const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
  829. struct amdgpu_ring *vm_pte_funcs_ring;
  830. };
  831. void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
  832. int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
  833. void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
  834. void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
  835. struct list_head *validated,
  836. struct amdgpu_bo_list_entry *entry);
  837. void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
  838. void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
  839. struct amdgpu_vm *vm);
  840. int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
  841. struct amdgpu_sync *sync);
  842. void amdgpu_vm_flush(struct amdgpu_ring *ring,
  843. struct amdgpu_vm *vm,
  844. struct fence *updates);
  845. void amdgpu_vm_fence(struct amdgpu_device *adev,
  846. struct amdgpu_vm *vm,
  847. struct fence *fence);
  848. uint64_t amdgpu_vm_map_gart(struct amdgpu_device *adev, uint64_t addr);
  849. int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
  850. struct amdgpu_vm *vm);
  851. int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
  852. struct amdgpu_vm *vm);
  853. int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  854. struct amdgpu_sync *sync);
  855. int amdgpu_vm_bo_update(struct amdgpu_device *adev,
  856. struct amdgpu_bo_va *bo_va,
  857. struct ttm_mem_reg *mem);
  858. void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
  859. struct amdgpu_bo *bo);
  860. struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
  861. struct amdgpu_bo *bo);
  862. struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
  863. struct amdgpu_vm *vm,
  864. struct amdgpu_bo *bo);
  865. int amdgpu_vm_bo_map(struct amdgpu_device *adev,
  866. struct amdgpu_bo_va *bo_va,
  867. uint64_t addr, uint64_t offset,
  868. uint64_t size, uint32_t flags);
  869. int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
  870. struct amdgpu_bo_va *bo_va,
  871. uint64_t addr);
  872. void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
  873. struct amdgpu_bo_va *bo_va);
  874. int amdgpu_vm_free_job(struct amdgpu_job *job);
  875. /*
  876. * context related structures
  877. */
  878. struct amdgpu_ctx_ring {
  879. uint64_t sequence;
  880. struct fence **fences;
  881. struct amd_sched_entity entity;
  882. };
  883. struct amdgpu_ctx {
  884. struct kref refcount;
  885. struct amdgpu_device *adev;
  886. unsigned reset_counter;
  887. spinlock_t ring_lock;
  888. struct fence **fences;
  889. struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
  890. };
  891. struct amdgpu_ctx_mgr {
  892. struct amdgpu_device *adev;
  893. struct mutex lock;
  894. /* protected by lock */
  895. struct idr ctx_handles;
  896. };
  897. int amdgpu_ctx_init(struct amdgpu_device *adev, enum amd_sched_priority pri,
  898. struct amdgpu_ctx *ctx);
  899. void amdgpu_ctx_fini(struct amdgpu_ctx *ctx);
  900. struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
  901. int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
  902. uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
  903. struct fence *fence);
  904. struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
  905. struct amdgpu_ring *ring, uint64_t seq);
  906. int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
  907. struct drm_file *filp);
  908. void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
  909. void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
  910. /*
  911. * file private structure
  912. */
  913. struct amdgpu_fpriv {
  914. struct amdgpu_vm vm;
  915. struct mutex bo_list_lock;
  916. struct idr bo_list_handles;
  917. struct amdgpu_ctx_mgr ctx_mgr;
  918. };
  919. /*
  920. * residency list
  921. */
  922. struct amdgpu_bo_list {
  923. struct mutex lock;
  924. struct amdgpu_bo *gds_obj;
  925. struct amdgpu_bo *gws_obj;
  926. struct amdgpu_bo *oa_obj;
  927. bool has_userptr;
  928. unsigned num_entries;
  929. struct amdgpu_bo_list_entry *array;
  930. };
  931. struct amdgpu_bo_list *
  932. amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
  933. void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
  934. struct list_head *validated);
  935. void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
  936. void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
  937. /*
  938. * GFX stuff
  939. */
  940. #include "clearstate_defs.h"
  941. struct amdgpu_rlc {
  942. /* for power gating */
  943. struct amdgpu_bo *save_restore_obj;
  944. uint64_t save_restore_gpu_addr;
  945. volatile uint32_t *sr_ptr;
  946. const u32 *reg_list;
  947. u32 reg_list_size;
  948. /* for clear state */
  949. struct amdgpu_bo *clear_state_obj;
  950. uint64_t clear_state_gpu_addr;
  951. volatile uint32_t *cs_ptr;
  952. const struct cs_section_def *cs_data;
  953. u32 clear_state_size;
  954. /* for cp tables */
  955. struct amdgpu_bo *cp_table_obj;
  956. uint64_t cp_table_gpu_addr;
  957. volatile uint32_t *cp_table_ptr;
  958. u32 cp_table_size;
  959. };
  960. struct amdgpu_mec {
  961. struct amdgpu_bo *hpd_eop_obj;
  962. u64 hpd_eop_gpu_addr;
  963. u32 num_pipe;
  964. u32 num_mec;
  965. u32 num_queue;
  966. };
  967. /*
  968. * GPU scratch registers structures, functions & helpers
  969. */
  970. struct amdgpu_scratch {
  971. unsigned num_reg;
  972. uint32_t reg_base;
  973. bool free[32];
  974. uint32_t reg[32];
  975. };
  976. /*
  977. * GFX configurations
  978. */
  979. struct amdgpu_gca_config {
  980. unsigned max_shader_engines;
  981. unsigned max_tile_pipes;
  982. unsigned max_cu_per_sh;
  983. unsigned max_sh_per_se;
  984. unsigned max_backends_per_se;
  985. unsigned max_texture_channel_caches;
  986. unsigned max_gprs;
  987. unsigned max_gs_threads;
  988. unsigned max_hw_contexts;
  989. unsigned sc_prim_fifo_size_frontend;
  990. unsigned sc_prim_fifo_size_backend;
  991. unsigned sc_hiz_tile_fifo_size;
  992. unsigned sc_earlyz_tile_fifo_size;
  993. unsigned num_tile_pipes;
  994. unsigned backend_enable_mask;
  995. unsigned mem_max_burst_length_bytes;
  996. unsigned mem_row_size_in_kb;
  997. unsigned shader_engine_tile_size;
  998. unsigned num_gpus;
  999. unsigned multi_gpu_tile_size;
  1000. unsigned mc_arb_ramcfg;
  1001. unsigned gb_addr_config;
  1002. uint32_t tile_mode_array[32];
  1003. uint32_t macrotile_mode_array[16];
  1004. };
  1005. struct amdgpu_gfx {
  1006. struct mutex gpu_clock_mutex;
  1007. struct amdgpu_gca_config config;
  1008. struct amdgpu_rlc rlc;
  1009. struct amdgpu_mec mec;
  1010. struct amdgpu_scratch scratch;
  1011. const struct firmware *me_fw; /* ME firmware */
  1012. uint32_t me_fw_version;
  1013. const struct firmware *pfp_fw; /* PFP firmware */
  1014. uint32_t pfp_fw_version;
  1015. const struct firmware *ce_fw; /* CE firmware */
  1016. uint32_t ce_fw_version;
  1017. const struct firmware *rlc_fw; /* RLC firmware */
  1018. uint32_t rlc_fw_version;
  1019. const struct firmware *mec_fw; /* MEC firmware */
  1020. uint32_t mec_fw_version;
  1021. const struct firmware *mec2_fw; /* MEC2 firmware */
  1022. uint32_t mec2_fw_version;
  1023. uint32_t me_feature_version;
  1024. uint32_t ce_feature_version;
  1025. uint32_t pfp_feature_version;
  1026. uint32_t rlc_feature_version;
  1027. uint32_t mec_feature_version;
  1028. uint32_t mec2_feature_version;
  1029. struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
  1030. unsigned num_gfx_rings;
  1031. struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
  1032. unsigned num_compute_rings;
  1033. struct amdgpu_irq_src eop_irq;
  1034. struct amdgpu_irq_src priv_reg_irq;
  1035. struct amdgpu_irq_src priv_inst_irq;
  1036. /* gfx status */
  1037. uint32_t gfx_current_status;
  1038. /* ce ram size*/
  1039. unsigned ce_ram_size;
  1040. };
  1041. int amdgpu_ib_get(struct amdgpu_ring *ring, struct amdgpu_vm *vm,
  1042. unsigned size, struct amdgpu_ib *ib);
  1043. void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib);
  1044. int amdgpu_ib_schedule(struct amdgpu_device *adev, unsigned num_ibs,
  1045. struct amdgpu_ib *ib, void *owner);
  1046. int amdgpu_ib_pool_init(struct amdgpu_device *adev);
  1047. void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
  1048. int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
  1049. /* Ring access between begin & end cannot sleep */
  1050. void amdgpu_ring_free_size(struct amdgpu_ring *ring);
  1051. int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
  1052. int amdgpu_ring_lock(struct amdgpu_ring *ring, unsigned ndw);
  1053. void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
  1054. void amdgpu_ring_commit(struct amdgpu_ring *ring);
  1055. void amdgpu_ring_unlock_commit(struct amdgpu_ring *ring);
  1056. void amdgpu_ring_undo(struct amdgpu_ring *ring);
  1057. void amdgpu_ring_unlock_undo(struct amdgpu_ring *ring);
  1058. unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
  1059. uint32_t **data);
  1060. int amdgpu_ring_restore(struct amdgpu_ring *ring,
  1061. unsigned size, uint32_t *data);
  1062. int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
  1063. unsigned ring_size, u32 nop, u32 align_mask,
  1064. struct amdgpu_irq_src *irq_src, unsigned irq_type,
  1065. enum amdgpu_ring_type ring_type);
  1066. void amdgpu_ring_fini(struct amdgpu_ring *ring);
  1067. struct amdgpu_ring *amdgpu_ring_from_fence(struct fence *f);
  1068. /*
  1069. * CS.
  1070. */
  1071. struct amdgpu_cs_chunk {
  1072. uint32_t chunk_id;
  1073. uint32_t length_dw;
  1074. uint32_t *kdata;
  1075. };
  1076. struct amdgpu_cs_parser {
  1077. struct amdgpu_device *adev;
  1078. struct drm_file *filp;
  1079. struct amdgpu_ctx *ctx;
  1080. /* chunks */
  1081. unsigned nchunks;
  1082. struct amdgpu_cs_chunk *chunks;
  1083. /* indirect buffers */
  1084. uint32_t num_ibs;
  1085. struct amdgpu_ib *ibs;
  1086. /* buffer objects */
  1087. struct ww_acquire_ctx ticket;
  1088. struct amdgpu_bo_list *bo_list;
  1089. struct amdgpu_bo_list_entry vm_pd;
  1090. struct list_head validated;
  1091. struct fence *fence;
  1092. uint64_t bytes_moved_threshold;
  1093. uint64_t bytes_moved;
  1094. /* user fence */
  1095. struct amdgpu_user_fence uf;
  1096. struct amdgpu_bo_list_entry uf_entry;
  1097. };
  1098. struct amdgpu_job {
  1099. struct amd_sched_job base;
  1100. struct amdgpu_device *adev;
  1101. struct amdgpu_ib *ibs;
  1102. uint32_t num_ibs;
  1103. void *owner;
  1104. struct amdgpu_user_fence uf;
  1105. int (*free_job)(struct amdgpu_job *job);
  1106. };
  1107. #define to_amdgpu_job(sched_job) \
  1108. container_of((sched_job), struct amdgpu_job, base)
  1109. static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, uint32_t ib_idx, int idx)
  1110. {
  1111. return p->ibs[ib_idx].ptr[idx];
  1112. }
  1113. /*
  1114. * Writeback
  1115. */
  1116. #define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
  1117. struct amdgpu_wb {
  1118. struct amdgpu_bo *wb_obj;
  1119. volatile uint32_t *wb;
  1120. uint64_t gpu_addr;
  1121. u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
  1122. unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
  1123. };
  1124. int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
  1125. void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
  1126. enum amdgpu_int_thermal_type {
  1127. THERMAL_TYPE_NONE,
  1128. THERMAL_TYPE_EXTERNAL,
  1129. THERMAL_TYPE_EXTERNAL_GPIO,
  1130. THERMAL_TYPE_RV6XX,
  1131. THERMAL_TYPE_RV770,
  1132. THERMAL_TYPE_ADT7473_WITH_INTERNAL,
  1133. THERMAL_TYPE_EVERGREEN,
  1134. THERMAL_TYPE_SUMO,
  1135. THERMAL_TYPE_NI,
  1136. THERMAL_TYPE_SI,
  1137. THERMAL_TYPE_EMC2103_WITH_INTERNAL,
  1138. THERMAL_TYPE_CI,
  1139. THERMAL_TYPE_KV,
  1140. };
  1141. enum amdgpu_dpm_auto_throttle_src {
  1142. AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
  1143. AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
  1144. };
  1145. enum amdgpu_dpm_event_src {
  1146. AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
  1147. AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
  1148. AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
  1149. AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
  1150. AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
  1151. };
  1152. #define AMDGPU_MAX_VCE_LEVELS 6
  1153. enum amdgpu_vce_level {
  1154. AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
  1155. AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
  1156. AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
  1157. AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
  1158. AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
  1159. AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
  1160. };
  1161. struct amdgpu_ps {
  1162. u32 caps; /* vbios flags */
  1163. u32 class; /* vbios flags */
  1164. u32 class2; /* vbios flags */
  1165. /* UVD clocks */
  1166. u32 vclk;
  1167. u32 dclk;
  1168. /* VCE clocks */
  1169. u32 evclk;
  1170. u32 ecclk;
  1171. bool vce_active;
  1172. enum amdgpu_vce_level vce_level;
  1173. /* asic priv */
  1174. void *ps_priv;
  1175. };
  1176. struct amdgpu_dpm_thermal {
  1177. /* thermal interrupt work */
  1178. struct work_struct work;
  1179. /* low temperature threshold */
  1180. int min_temp;
  1181. /* high temperature threshold */
  1182. int max_temp;
  1183. /* was last interrupt low to high or high to low */
  1184. bool high_to_low;
  1185. /* interrupt source */
  1186. struct amdgpu_irq_src irq;
  1187. };
  1188. enum amdgpu_clk_action
  1189. {
  1190. AMDGPU_SCLK_UP = 1,
  1191. AMDGPU_SCLK_DOWN
  1192. };
  1193. struct amdgpu_blacklist_clocks
  1194. {
  1195. u32 sclk;
  1196. u32 mclk;
  1197. enum amdgpu_clk_action action;
  1198. };
  1199. struct amdgpu_clock_and_voltage_limits {
  1200. u32 sclk;
  1201. u32 mclk;
  1202. u16 vddc;
  1203. u16 vddci;
  1204. };
  1205. struct amdgpu_clock_array {
  1206. u32 count;
  1207. u32 *values;
  1208. };
  1209. struct amdgpu_clock_voltage_dependency_entry {
  1210. u32 clk;
  1211. u16 v;
  1212. };
  1213. struct amdgpu_clock_voltage_dependency_table {
  1214. u32 count;
  1215. struct amdgpu_clock_voltage_dependency_entry *entries;
  1216. };
  1217. union amdgpu_cac_leakage_entry {
  1218. struct {
  1219. u16 vddc;
  1220. u32 leakage;
  1221. };
  1222. struct {
  1223. u16 vddc1;
  1224. u16 vddc2;
  1225. u16 vddc3;
  1226. };
  1227. };
  1228. struct amdgpu_cac_leakage_table {
  1229. u32 count;
  1230. union amdgpu_cac_leakage_entry *entries;
  1231. };
  1232. struct amdgpu_phase_shedding_limits_entry {
  1233. u16 voltage;
  1234. u32 sclk;
  1235. u32 mclk;
  1236. };
  1237. struct amdgpu_phase_shedding_limits_table {
  1238. u32 count;
  1239. struct amdgpu_phase_shedding_limits_entry *entries;
  1240. };
  1241. struct amdgpu_uvd_clock_voltage_dependency_entry {
  1242. u32 vclk;
  1243. u32 dclk;
  1244. u16 v;
  1245. };
  1246. struct amdgpu_uvd_clock_voltage_dependency_table {
  1247. u8 count;
  1248. struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
  1249. };
  1250. struct amdgpu_vce_clock_voltage_dependency_entry {
  1251. u32 ecclk;
  1252. u32 evclk;
  1253. u16 v;
  1254. };
  1255. struct amdgpu_vce_clock_voltage_dependency_table {
  1256. u8 count;
  1257. struct amdgpu_vce_clock_voltage_dependency_entry *entries;
  1258. };
  1259. struct amdgpu_ppm_table {
  1260. u8 ppm_design;
  1261. u16 cpu_core_number;
  1262. u32 platform_tdp;
  1263. u32 small_ac_platform_tdp;
  1264. u32 platform_tdc;
  1265. u32 small_ac_platform_tdc;
  1266. u32 apu_tdp;
  1267. u32 dgpu_tdp;
  1268. u32 dgpu_ulv_power;
  1269. u32 tj_max;
  1270. };
  1271. struct amdgpu_cac_tdp_table {
  1272. u16 tdp;
  1273. u16 configurable_tdp;
  1274. u16 tdc;
  1275. u16 battery_power_limit;
  1276. u16 small_power_limit;
  1277. u16 low_cac_leakage;
  1278. u16 high_cac_leakage;
  1279. u16 maximum_power_delivery_limit;
  1280. };
  1281. struct amdgpu_dpm_dynamic_state {
  1282. struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
  1283. struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
  1284. struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
  1285. struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
  1286. struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
  1287. struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
  1288. struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
  1289. struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
  1290. struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
  1291. struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
  1292. struct amdgpu_clock_array valid_sclk_values;
  1293. struct amdgpu_clock_array valid_mclk_values;
  1294. struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
  1295. struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
  1296. u32 mclk_sclk_ratio;
  1297. u32 sclk_mclk_delta;
  1298. u16 vddc_vddci_delta;
  1299. u16 min_vddc_for_pcie_gen2;
  1300. struct amdgpu_cac_leakage_table cac_leakage_table;
  1301. struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
  1302. struct amdgpu_ppm_table *ppm_table;
  1303. struct amdgpu_cac_tdp_table *cac_tdp_table;
  1304. };
  1305. struct amdgpu_dpm_fan {
  1306. u16 t_min;
  1307. u16 t_med;
  1308. u16 t_high;
  1309. u16 pwm_min;
  1310. u16 pwm_med;
  1311. u16 pwm_high;
  1312. u8 t_hyst;
  1313. u32 cycle_delay;
  1314. u16 t_max;
  1315. u8 control_mode;
  1316. u16 default_max_fan_pwm;
  1317. u16 default_fan_output_sensitivity;
  1318. u16 fan_output_sensitivity;
  1319. bool ucode_fan_control;
  1320. };
  1321. enum amdgpu_pcie_gen {
  1322. AMDGPU_PCIE_GEN1 = 0,
  1323. AMDGPU_PCIE_GEN2 = 1,
  1324. AMDGPU_PCIE_GEN3 = 2,
  1325. AMDGPU_PCIE_GEN_INVALID = 0xffff
  1326. };
  1327. enum amdgpu_dpm_forced_level {
  1328. AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
  1329. AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
  1330. AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
  1331. };
  1332. struct amdgpu_vce_state {
  1333. /* vce clocks */
  1334. u32 evclk;
  1335. u32 ecclk;
  1336. /* gpu clocks */
  1337. u32 sclk;
  1338. u32 mclk;
  1339. u8 clk_idx;
  1340. u8 pstate;
  1341. };
  1342. struct amdgpu_dpm_funcs {
  1343. int (*get_temperature)(struct amdgpu_device *adev);
  1344. int (*pre_set_power_state)(struct amdgpu_device *adev);
  1345. int (*set_power_state)(struct amdgpu_device *adev);
  1346. void (*post_set_power_state)(struct amdgpu_device *adev);
  1347. void (*display_configuration_changed)(struct amdgpu_device *adev);
  1348. u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
  1349. u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
  1350. void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
  1351. void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
  1352. int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
  1353. bool (*vblank_too_short)(struct amdgpu_device *adev);
  1354. void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
  1355. void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
  1356. void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
  1357. void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
  1358. u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
  1359. int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
  1360. int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
  1361. };
  1362. struct amdgpu_dpm {
  1363. struct amdgpu_ps *ps;
  1364. /* number of valid power states */
  1365. int num_ps;
  1366. /* current power state that is active */
  1367. struct amdgpu_ps *current_ps;
  1368. /* requested power state */
  1369. struct amdgpu_ps *requested_ps;
  1370. /* boot up power state */
  1371. struct amdgpu_ps *boot_ps;
  1372. /* default uvd power state */
  1373. struct amdgpu_ps *uvd_ps;
  1374. /* vce requirements */
  1375. struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
  1376. enum amdgpu_vce_level vce_level;
  1377. enum amd_pm_state_type state;
  1378. enum amd_pm_state_type user_state;
  1379. u32 platform_caps;
  1380. u32 voltage_response_time;
  1381. u32 backbias_response_time;
  1382. void *priv;
  1383. u32 new_active_crtcs;
  1384. int new_active_crtc_count;
  1385. u32 current_active_crtcs;
  1386. int current_active_crtc_count;
  1387. struct amdgpu_dpm_dynamic_state dyn_state;
  1388. struct amdgpu_dpm_fan fan;
  1389. u32 tdp_limit;
  1390. u32 near_tdp_limit;
  1391. u32 near_tdp_limit_adjusted;
  1392. u32 sq_ramping_threshold;
  1393. u32 cac_leakage;
  1394. u16 tdp_od_limit;
  1395. u32 tdp_adjustment;
  1396. u16 load_line_slope;
  1397. bool power_control;
  1398. bool ac_power;
  1399. /* special states active */
  1400. bool thermal_active;
  1401. bool uvd_active;
  1402. bool vce_active;
  1403. /* thermal handling */
  1404. struct amdgpu_dpm_thermal thermal;
  1405. /* forced levels */
  1406. enum amdgpu_dpm_forced_level forced_level;
  1407. };
  1408. struct amdgpu_pm {
  1409. struct mutex mutex;
  1410. u32 current_sclk;
  1411. u32 current_mclk;
  1412. u32 default_sclk;
  1413. u32 default_mclk;
  1414. struct amdgpu_i2c_chan *i2c_bus;
  1415. /* internal thermal controller on rv6xx+ */
  1416. enum amdgpu_int_thermal_type int_thermal_type;
  1417. struct device *int_hwmon_dev;
  1418. /* fan control parameters */
  1419. bool no_fan;
  1420. u8 fan_pulses_per_revolution;
  1421. u8 fan_min_rpm;
  1422. u8 fan_max_rpm;
  1423. /* dpm */
  1424. bool dpm_enabled;
  1425. bool sysfs_initialized;
  1426. struct amdgpu_dpm dpm;
  1427. const struct firmware *fw; /* SMC firmware */
  1428. uint32_t fw_version;
  1429. const struct amdgpu_dpm_funcs *funcs;
  1430. uint32_t pcie_gen_mask;
  1431. uint32_t pcie_mlw_mask;
  1432. struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
  1433. };
  1434. void amdgpu_get_pcie_info(struct amdgpu_device *adev);
  1435. /*
  1436. * UVD
  1437. */
  1438. #define AMDGPU_MAX_UVD_HANDLES 10
  1439. #define AMDGPU_UVD_STACK_SIZE (1024*1024)
  1440. #define AMDGPU_UVD_HEAP_SIZE (1024*1024)
  1441. #define AMDGPU_UVD_FIRMWARE_OFFSET 256
  1442. struct amdgpu_uvd {
  1443. struct amdgpu_bo *vcpu_bo;
  1444. void *cpu_addr;
  1445. uint64_t gpu_addr;
  1446. atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
  1447. struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
  1448. struct delayed_work idle_work;
  1449. const struct firmware *fw; /* UVD firmware */
  1450. struct amdgpu_ring ring;
  1451. struct amdgpu_irq_src irq;
  1452. bool address_64_bit;
  1453. };
  1454. /*
  1455. * VCE
  1456. */
  1457. #define AMDGPU_MAX_VCE_HANDLES 16
  1458. #define AMDGPU_VCE_FIRMWARE_OFFSET 256
  1459. #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
  1460. #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
  1461. struct amdgpu_vce {
  1462. struct amdgpu_bo *vcpu_bo;
  1463. uint64_t gpu_addr;
  1464. unsigned fw_version;
  1465. unsigned fb_version;
  1466. atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
  1467. struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
  1468. uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
  1469. struct delayed_work idle_work;
  1470. const struct firmware *fw; /* VCE firmware */
  1471. struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
  1472. struct amdgpu_irq_src irq;
  1473. unsigned harvest_config;
  1474. };
  1475. /*
  1476. * SDMA
  1477. */
  1478. struct amdgpu_sdma_instance {
  1479. /* SDMA firmware */
  1480. const struct firmware *fw;
  1481. uint32_t fw_version;
  1482. uint32_t feature_version;
  1483. struct amdgpu_ring ring;
  1484. bool burst_nop;
  1485. };
  1486. struct amdgpu_sdma {
  1487. struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
  1488. struct amdgpu_irq_src trap_irq;
  1489. struct amdgpu_irq_src illegal_inst_irq;
  1490. int num_instances;
  1491. };
  1492. /*
  1493. * Firmware
  1494. */
  1495. struct amdgpu_firmware {
  1496. struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
  1497. bool smu_load;
  1498. struct amdgpu_bo *fw_buf;
  1499. unsigned int fw_size;
  1500. };
  1501. /*
  1502. * Benchmarking
  1503. */
  1504. void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
  1505. /*
  1506. * Testing
  1507. */
  1508. void amdgpu_test_moves(struct amdgpu_device *adev);
  1509. void amdgpu_test_ring_sync(struct amdgpu_device *adev,
  1510. struct amdgpu_ring *cpA,
  1511. struct amdgpu_ring *cpB);
  1512. void amdgpu_test_syncing(struct amdgpu_device *adev);
  1513. /*
  1514. * MMU Notifier
  1515. */
  1516. #if defined(CONFIG_MMU_NOTIFIER)
  1517. int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
  1518. void amdgpu_mn_unregister(struct amdgpu_bo *bo);
  1519. #else
  1520. static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
  1521. {
  1522. return -ENODEV;
  1523. }
  1524. static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
  1525. #endif
  1526. /*
  1527. * Debugfs
  1528. */
  1529. struct amdgpu_debugfs {
  1530. struct drm_info_list *files;
  1531. unsigned num_files;
  1532. };
  1533. int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
  1534. struct drm_info_list *files,
  1535. unsigned nfiles);
  1536. int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
  1537. #if defined(CONFIG_DEBUG_FS)
  1538. int amdgpu_debugfs_init(struct drm_minor *minor);
  1539. void amdgpu_debugfs_cleanup(struct drm_minor *minor);
  1540. #endif
  1541. /*
  1542. * amdgpu smumgr functions
  1543. */
  1544. struct amdgpu_smumgr_funcs {
  1545. int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
  1546. int (*request_smu_load_fw)(struct amdgpu_device *adev);
  1547. int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
  1548. };
  1549. /*
  1550. * amdgpu smumgr
  1551. */
  1552. struct amdgpu_smumgr {
  1553. struct amdgpu_bo *toc_buf;
  1554. struct amdgpu_bo *smu_buf;
  1555. /* asic priv smu data */
  1556. void *priv;
  1557. spinlock_t smu_lock;
  1558. /* smumgr functions */
  1559. const struct amdgpu_smumgr_funcs *smumgr_funcs;
  1560. /* ucode loading complete flag */
  1561. uint32_t fw_flags;
  1562. };
  1563. /*
  1564. * ASIC specific register table accessible by UMD
  1565. */
  1566. struct amdgpu_allowed_register_entry {
  1567. uint32_t reg_offset;
  1568. bool untouched;
  1569. bool grbm_indexed;
  1570. };
  1571. struct amdgpu_cu_info {
  1572. uint32_t number; /* total active CU number */
  1573. uint32_t ao_cu_mask;
  1574. uint32_t bitmap[4][4];
  1575. };
  1576. /*
  1577. * ASIC specific functions.
  1578. */
  1579. struct amdgpu_asic_funcs {
  1580. bool (*read_disabled_bios)(struct amdgpu_device *adev);
  1581. bool (*read_bios_from_rom)(struct amdgpu_device *adev,
  1582. u8 *bios, u32 length_bytes);
  1583. int (*read_register)(struct amdgpu_device *adev, u32 se_num,
  1584. u32 sh_num, u32 reg_offset, u32 *value);
  1585. void (*set_vga_state)(struct amdgpu_device *adev, bool state);
  1586. int (*reset)(struct amdgpu_device *adev);
  1587. /* wait for mc_idle */
  1588. int (*wait_for_mc_idle)(struct amdgpu_device *adev);
  1589. /* get the reference clock */
  1590. u32 (*get_xclk)(struct amdgpu_device *adev);
  1591. /* get the gpu clock counter */
  1592. uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
  1593. int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
  1594. /* MM block clocks */
  1595. int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
  1596. int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
  1597. };
  1598. /*
  1599. * IOCTL.
  1600. */
  1601. int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
  1602. struct drm_file *filp);
  1603. int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
  1604. struct drm_file *filp);
  1605. int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
  1606. struct drm_file *filp);
  1607. int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
  1608. struct drm_file *filp);
  1609. int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1610. struct drm_file *filp);
  1611. int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1612. struct drm_file *filp);
  1613. int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
  1614. struct drm_file *filp);
  1615. int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
  1616. struct drm_file *filp);
  1617. int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1618. int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1619. int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
  1620. struct drm_file *filp);
  1621. /* VRAM scratch page for HDP bug, default vram page */
  1622. struct amdgpu_vram_scratch {
  1623. struct amdgpu_bo *robj;
  1624. volatile uint32_t *ptr;
  1625. u64 gpu_addr;
  1626. };
  1627. /*
  1628. * ACPI
  1629. */
  1630. struct amdgpu_atif_notification_cfg {
  1631. bool enabled;
  1632. int command_code;
  1633. };
  1634. struct amdgpu_atif_notifications {
  1635. bool display_switch;
  1636. bool expansion_mode_change;
  1637. bool thermal_state;
  1638. bool forced_power_state;
  1639. bool system_power_state;
  1640. bool display_conf_change;
  1641. bool px_gfx_switch;
  1642. bool brightness_change;
  1643. bool dgpu_display_event;
  1644. };
  1645. struct amdgpu_atif_functions {
  1646. bool system_params;
  1647. bool sbios_requests;
  1648. bool select_active_disp;
  1649. bool lid_state;
  1650. bool get_tv_standard;
  1651. bool set_tv_standard;
  1652. bool get_panel_expansion_mode;
  1653. bool set_panel_expansion_mode;
  1654. bool temperature_change;
  1655. bool graphics_device_types;
  1656. };
  1657. struct amdgpu_atif {
  1658. struct amdgpu_atif_notifications notifications;
  1659. struct amdgpu_atif_functions functions;
  1660. struct amdgpu_atif_notification_cfg notification_cfg;
  1661. struct amdgpu_encoder *encoder_for_bl;
  1662. };
  1663. struct amdgpu_atcs_functions {
  1664. bool get_ext_state;
  1665. bool pcie_perf_req;
  1666. bool pcie_dev_rdy;
  1667. bool pcie_bus_width;
  1668. };
  1669. struct amdgpu_atcs {
  1670. struct amdgpu_atcs_functions functions;
  1671. };
  1672. /*
  1673. * CGS
  1674. */
  1675. void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
  1676. void amdgpu_cgs_destroy_device(void *cgs_device);
  1677. /*
  1678. * Core structure, functions and helpers.
  1679. */
  1680. typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
  1681. typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  1682. typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  1683. typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
  1684. struct amdgpu_ip_block_status {
  1685. bool valid;
  1686. bool sw;
  1687. bool hw;
  1688. };
  1689. struct amdgpu_device {
  1690. struct device *dev;
  1691. struct drm_device *ddev;
  1692. struct pci_dev *pdev;
  1693. /* ASIC */
  1694. enum amd_asic_type asic_type;
  1695. uint32_t family;
  1696. uint32_t rev_id;
  1697. uint32_t external_rev_id;
  1698. unsigned long flags;
  1699. int usec_timeout;
  1700. const struct amdgpu_asic_funcs *asic_funcs;
  1701. bool shutdown;
  1702. bool suspend;
  1703. bool need_dma32;
  1704. bool accel_working;
  1705. struct work_struct reset_work;
  1706. struct notifier_block acpi_nb;
  1707. struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
  1708. struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  1709. unsigned debugfs_count;
  1710. #if defined(CONFIG_DEBUG_FS)
  1711. struct dentry *debugfs_regs;
  1712. #endif
  1713. struct amdgpu_atif atif;
  1714. struct amdgpu_atcs atcs;
  1715. struct mutex srbm_mutex;
  1716. /* GRBM index mutex. Protects concurrent access to GRBM index */
  1717. struct mutex grbm_idx_mutex;
  1718. struct dev_pm_domain vga_pm_domain;
  1719. bool have_disp_power_ref;
  1720. /* BIOS */
  1721. uint8_t *bios;
  1722. bool is_atom_bios;
  1723. uint16_t bios_header_start;
  1724. struct amdgpu_bo *stollen_vga_memory;
  1725. uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
  1726. /* Register/doorbell mmio */
  1727. resource_size_t rmmio_base;
  1728. resource_size_t rmmio_size;
  1729. void __iomem *rmmio;
  1730. /* protects concurrent MM_INDEX/DATA based register access */
  1731. spinlock_t mmio_idx_lock;
  1732. /* protects concurrent SMC based register access */
  1733. spinlock_t smc_idx_lock;
  1734. amdgpu_rreg_t smc_rreg;
  1735. amdgpu_wreg_t smc_wreg;
  1736. /* protects concurrent PCIE register access */
  1737. spinlock_t pcie_idx_lock;
  1738. amdgpu_rreg_t pcie_rreg;
  1739. amdgpu_wreg_t pcie_wreg;
  1740. /* protects concurrent UVD register access */
  1741. spinlock_t uvd_ctx_idx_lock;
  1742. amdgpu_rreg_t uvd_ctx_rreg;
  1743. amdgpu_wreg_t uvd_ctx_wreg;
  1744. /* protects concurrent DIDT register access */
  1745. spinlock_t didt_idx_lock;
  1746. amdgpu_rreg_t didt_rreg;
  1747. amdgpu_wreg_t didt_wreg;
  1748. /* protects concurrent ENDPOINT (audio) register access */
  1749. spinlock_t audio_endpt_idx_lock;
  1750. amdgpu_block_rreg_t audio_endpt_rreg;
  1751. amdgpu_block_wreg_t audio_endpt_wreg;
  1752. void __iomem *rio_mem;
  1753. resource_size_t rio_mem_size;
  1754. struct amdgpu_doorbell doorbell;
  1755. /* clock/pll info */
  1756. struct amdgpu_clock clock;
  1757. /* MC */
  1758. struct amdgpu_mc mc;
  1759. struct amdgpu_gart gart;
  1760. struct amdgpu_dummy_page dummy_page;
  1761. struct amdgpu_vm_manager vm_manager;
  1762. /* memory management */
  1763. struct amdgpu_mman mman;
  1764. struct amdgpu_gem gem;
  1765. struct amdgpu_vram_scratch vram_scratch;
  1766. struct amdgpu_wb wb;
  1767. atomic64_t vram_usage;
  1768. atomic64_t vram_vis_usage;
  1769. atomic64_t gtt_usage;
  1770. atomic64_t num_bytes_moved;
  1771. atomic_t gpu_reset_counter;
  1772. /* display */
  1773. struct amdgpu_mode_info mode_info;
  1774. struct work_struct hotplug_work;
  1775. struct amdgpu_irq_src crtc_irq;
  1776. struct amdgpu_irq_src pageflip_irq;
  1777. struct amdgpu_irq_src hpd_irq;
  1778. /* rings */
  1779. unsigned fence_context;
  1780. struct mutex ring_lock;
  1781. unsigned num_rings;
  1782. struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
  1783. bool ib_pool_ready;
  1784. struct amdgpu_sa_manager ring_tmp_bo;
  1785. /* interrupts */
  1786. struct amdgpu_irq irq;
  1787. /* powerplay */
  1788. struct amd_powerplay powerplay;
  1789. bool pp_enabled;
  1790. /* dpm */
  1791. struct amdgpu_pm pm;
  1792. u32 cg_flags;
  1793. u32 pg_flags;
  1794. /* amdgpu smumgr */
  1795. struct amdgpu_smumgr smu;
  1796. /* gfx */
  1797. struct amdgpu_gfx gfx;
  1798. /* sdma */
  1799. struct amdgpu_sdma sdma;
  1800. /* uvd */
  1801. bool has_uvd;
  1802. struct amdgpu_uvd uvd;
  1803. /* vce */
  1804. struct amdgpu_vce vce;
  1805. /* firmwares */
  1806. struct amdgpu_firmware firmware;
  1807. /* GDS */
  1808. struct amdgpu_gds gds;
  1809. const struct amdgpu_ip_block_version *ip_blocks;
  1810. int num_ip_blocks;
  1811. struct amdgpu_ip_block_status *ip_block_status;
  1812. struct mutex mn_lock;
  1813. DECLARE_HASHTABLE(mn_hash, 7);
  1814. /* tracking pinned memory */
  1815. u64 vram_pin_size;
  1816. u64 gart_pin_size;
  1817. /* amdkfd interface */
  1818. struct kfd_dev *kfd;
  1819. /* kernel conext for IB submission */
  1820. struct amdgpu_ctx kernel_ctx;
  1821. };
  1822. bool amdgpu_device_is_px(struct drm_device *dev);
  1823. int amdgpu_device_init(struct amdgpu_device *adev,
  1824. struct drm_device *ddev,
  1825. struct pci_dev *pdev,
  1826. uint32_t flags);
  1827. void amdgpu_device_fini(struct amdgpu_device *adev);
  1828. int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
  1829. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  1830. bool always_indirect);
  1831. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  1832. bool always_indirect);
  1833. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
  1834. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
  1835. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
  1836. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
  1837. /*
  1838. * Cast helper
  1839. */
  1840. extern const struct fence_ops amdgpu_fence_ops;
  1841. static inline struct amdgpu_fence *to_amdgpu_fence(struct fence *f)
  1842. {
  1843. struct amdgpu_fence *__f = container_of(f, struct amdgpu_fence, base);
  1844. if (__f->base.ops == &amdgpu_fence_ops)
  1845. return __f;
  1846. return NULL;
  1847. }
  1848. /*
  1849. * Registers read & write functions.
  1850. */
  1851. #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
  1852. #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
  1853. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
  1854. #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
  1855. #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
  1856. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1857. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1858. #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
  1859. #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
  1860. #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
  1861. #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
  1862. #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
  1863. #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
  1864. #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
  1865. #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
  1866. #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
  1867. #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
  1868. #define WREG32_P(reg, val, mask) \
  1869. do { \
  1870. uint32_t tmp_ = RREG32(reg); \
  1871. tmp_ &= (mask); \
  1872. tmp_ |= ((val) & ~(mask)); \
  1873. WREG32(reg, tmp_); \
  1874. } while (0)
  1875. #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
  1876. #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
  1877. #define WREG32_PLL_P(reg, val, mask) \
  1878. do { \
  1879. uint32_t tmp_ = RREG32_PLL(reg); \
  1880. tmp_ &= (mask); \
  1881. tmp_ |= ((val) & ~(mask)); \
  1882. WREG32_PLL(reg, tmp_); \
  1883. } while (0)
  1884. #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
  1885. #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
  1886. #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
  1887. #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
  1888. #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
  1889. #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  1890. #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  1891. #define REG_SET_FIELD(orig_val, reg, field, field_val) \
  1892. (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
  1893. (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
  1894. #define REG_GET_FIELD(value, reg, field) \
  1895. (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
  1896. /*
  1897. * BIOS helpers.
  1898. */
  1899. #define RBIOS8(i) (adev->bios[i])
  1900. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1901. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1902. /*
  1903. * RING helpers.
  1904. */
  1905. static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
  1906. {
  1907. if (ring->count_dw <= 0)
  1908. DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
  1909. ring->ring[ring->wptr++] = v;
  1910. ring->wptr &= ring->ptr_mask;
  1911. ring->count_dw--;
  1912. ring->ring_free_dw--;
  1913. }
  1914. static inline struct amdgpu_sdma_instance *
  1915. amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
  1916. {
  1917. struct amdgpu_device *adev = ring->adev;
  1918. int i;
  1919. for (i = 0; i < adev->sdma.num_instances; i++)
  1920. if (&adev->sdma.instance[i].ring == ring)
  1921. break;
  1922. if (i < AMDGPU_MAX_SDMA_INSTANCES)
  1923. return &adev->sdma.instance[i];
  1924. else
  1925. return NULL;
  1926. }
  1927. /*
  1928. * ASICs macro.
  1929. */
  1930. #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
  1931. #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
  1932. #define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
  1933. #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
  1934. #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
  1935. #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
  1936. #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
  1937. #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
  1938. #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
  1939. #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
  1940. #define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
  1941. #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
  1942. #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
  1943. #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
  1944. #define amdgpu_vm_write_pte(adev, ib, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (addr), (count), (incr), (flags)))
  1945. #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)))
  1946. #define amdgpu_vm_pad_ib(adev, ib) ((adev)->vm_manager.vm_pte_funcs->pad_ib((ib)))
  1947. #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
  1948. #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
  1949. #define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
  1950. #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
  1951. #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
  1952. #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
  1953. #define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
  1954. #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
  1955. #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
  1956. #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))
  1957. #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
  1958. #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
  1959. #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
  1960. #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
  1961. #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
  1962. #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
  1963. #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
  1964. #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
  1965. #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
  1966. #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
  1967. #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
  1968. #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
  1969. #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
  1970. #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
  1971. #define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
  1972. #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
  1973. #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
  1974. #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))
  1975. #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
  1976. #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
  1977. #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b))
  1978. #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
  1979. #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
  1980. #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
  1981. #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
  1982. #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
  1983. #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
  1984. #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
  1985. #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
  1986. #define amdgpu_dpm_get_temperature(adev) \
  1987. ((adev)->pp_enabled ? \
  1988. (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
  1989. (adev)->pm.funcs->get_temperature((adev)))
  1990. #define amdgpu_dpm_set_fan_control_mode(adev, m) \
  1991. ((adev)->pp_enabled ? \
  1992. (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
  1993. (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
  1994. #define amdgpu_dpm_get_fan_control_mode(adev) \
  1995. ((adev)->pp_enabled ? \
  1996. (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
  1997. (adev)->pm.funcs->get_fan_control_mode((adev)))
  1998. #define amdgpu_dpm_set_fan_speed_percent(adev, s) \
  1999. ((adev)->pp_enabled ? \
  2000. (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
  2001. (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
  2002. #define amdgpu_dpm_get_fan_speed_percent(adev, s) \
  2003. ((adev)->pp_enabled ? \
  2004. (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
  2005. (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
  2006. #define amdgpu_dpm_get_sclk(adev, l) \
  2007. ((adev)->pp_enabled ? \
  2008. (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
  2009. (adev)->pm.funcs->get_sclk((adev), (l)))
  2010. #define amdgpu_dpm_get_mclk(adev, l) \
  2011. ((adev)->pp_enabled ? \
  2012. (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
  2013. (adev)->pm.funcs->get_mclk((adev), (l)))
  2014. #define amdgpu_dpm_force_performance_level(adev, l) \
  2015. ((adev)->pp_enabled ? \
  2016. (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
  2017. (adev)->pm.funcs->force_performance_level((adev), (l)))
  2018. #define amdgpu_dpm_powergate_uvd(adev, g) \
  2019. ((adev)->pp_enabled ? \
  2020. (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
  2021. (adev)->pm.funcs->powergate_uvd((adev), (g)))
  2022. #define amdgpu_dpm_powergate_vce(adev, g) \
  2023. ((adev)->pp_enabled ? \
  2024. (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
  2025. (adev)->pm.funcs->powergate_vce((adev), (g)))
  2026. #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
  2027. ((adev)->pp_enabled ? \
  2028. (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
  2029. (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
  2030. #define amdgpu_dpm_get_current_power_state(adev) \
  2031. (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
  2032. #define amdgpu_dpm_get_performance_level(adev) \
  2033. (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
  2034. #define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
  2035. (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
  2036. #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
  2037. /* Common functions */
  2038. int amdgpu_gpu_reset(struct amdgpu_device *adev);
  2039. void amdgpu_pci_config_reset(struct amdgpu_device *adev);
  2040. bool amdgpu_card_posted(struct amdgpu_device *adev);
  2041. void amdgpu_update_display_priority(struct amdgpu_device *adev);
  2042. bool amdgpu_boot_test_post_card(struct amdgpu_device *adev);
  2043. int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
  2044. int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
  2045. u32 ip_instance, u32 ring,
  2046. struct amdgpu_ring **out_ring);
  2047. void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
  2048. bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
  2049. int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
  2050. uint32_t flags);
  2051. bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
  2052. bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
  2053. unsigned long end);
  2054. bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
  2055. uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
  2056. struct ttm_mem_reg *mem);
  2057. void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
  2058. void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
  2059. void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
  2060. void amdgpu_program_register_sequence(struct amdgpu_device *adev,
  2061. const u32 *registers,
  2062. const u32 array_size);
  2063. bool amdgpu_device_is_px(struct drm_device *dev);
  2064. /* atpx handler */
  2065. #if defined(CONFIG_VGA_SWITCHEROO)
  2066. void amdgpu_register_atpx_handler(void);
  2067. void amdgpu_unregister_atpx_handler(void);
  2068. #else
  2069. static inline void amdgpu_register_atpx_handler(void) {}
  2070. static inline void amdgpu_unregister_atpx_handler(void) {}
  2071. #endif
  2072. /*
  2073. * KMS
  2074. */
  2075. extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
  2076. extern int amdgpu_max_kms_ioctl;
  2077. int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
  2078. int amdgpu_driver_unload_kms(struct drm_device *dev);
  2079. void amdgpu_driver_lastclose_kms(struct drm_device *dev);
  2080. int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
  2081. void amdgpu_driver_postclose_kms(struct drm_device *dev,
  2082. struct drm_file *file_priv);
  2083. void amdgpu_driver_preclose_kms(struct drm_device *dev,
  2084. struct drm_file *file_priv);
  2085. int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
  2086. int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
  2087. u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
  2088. int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  2089. void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  2090. int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
  2091. int *max_error,
  2092. struct timeval *vblank_time,
  2093. unsigned flags);
  2094. long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
  2095. unsigned long arg);
  2096. /*
  2097. * functions used by amdgpu_encoder.c
  2098. */
  2099. struct amdgpu_afmt_acr {
  2100. u32 clock;
  2101. int n_32khz;
  2102. int cts_32khz;
  2103. int n_44_1khz;
  2104. int cts_44_1khz;
  2105. int n_48khz;
  2106. int cts_48khz;
  2107. };
  2108. struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
  2109. /* amdgpu_acpi.c */
  2110. #if defined(CONFIG_ACPI)
  2111. int amdgpu_acpi_init(struct amdgpu_device *adev);
  2112. void amdgpu_acpi_fini(struct amdgpu_device *adev);
  2113. bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
  2114. int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
  2115. u8 perf_req, bool advertise);
  2116. int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
  2117. #else
  2118. static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
  2119. static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
  2120. #endif
  2121. struct amdgpu_bo_va_mapping *
  2122. amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
  2123. uint64_t addr, struct amdgpu_bo **bo);
  2124. #include "amdgpu_object.h"
  2125. #endif