amdgpu.h 55 KB

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