amdgpu.h 71 KB

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