amdgpu.h 55 KB

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