amdgpu.h 56 KB

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