amdgpu.h 74 KB

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