amdgpu.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  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. #endif
  998. int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
  999. /*
  1000. * amdgpu smumgr functions
  1001. */
  1002. struct amdgpu_smumgr_funcs {
  1003. int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
  1004. int (*request_smu_load_fw)(struct amdgpu_device *adev);
  1005. int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
  1006. };
  1007. /*
  1008. * amdgpu smumgr
  1009. */
  1010. struct amdgpu_smumgr {
  1011. struct amdgpu_bo *toc_buf;
  1012. struct amdgpu_bo *smu_buf;
  1013. /* asic priv smu data */
  1014. void *priv;
  1015. spinlock_t smu_lock;
  1016. /* smumgr functions */
  1017. const struct amdgpu_smumgr_funcs *smumgr_funcs;
  1018. /* ucode loading complete flag */
  1019. uint32_t fw_flags;
  1020. };
  1021. /*
  1022. * ASIC specific register table accessible by UMD
  1023. */
  1024. struct amdgpu_allowed_register_entry {
  1025. uint32_t reg_offset;
  1026. bool untouched;
  1027. bool grbm_indexed;
  1028. };
  1029. /*
  1030. * ASIC specific functions.
  1031. */
  1032. struct amdgpu_asic_funcs {
  1033. bool (*read_disabled_bios)(struct amdgpu_device *adev);
  1034. bool (*read_bios_from_rom)(struct amdgpu_device *adev,
  1035. u8 *bios, u32 length_bytes);
  1036. void (*detect_hw_virtualization) (struct amdgpu_device *adev);
  1037. int (*read_register)(struct amdgpu_device *adev, u32 se_num,
  1038. u32 sh_num, u32 reg_offset, u32 *value);
  1039. void (*set_vga_state)(struct amdgpu_device *adev, bool state);
  1040. int (*reset)(struct amdgpu_device *adev);
  1041. /* get the reference clock */
  1042. u32 (*get_xclk)(struct amdgpu_device *adev);
  1043. /* MM block clocks */
  1044. int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
  1045. int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
  1046. /* static power management */
  1047. int (*get_pcie_lanes)(struct amdgpu_device *adev);
  1048. void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
  1049. };
  1050. /*
  1051. * IOCTL.
  1052. */
  1053. int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
  1054. struct drm_file *filp);
  1055. int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
  1056. struct drm_file *filp);
  1057. int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
  1058. struct drm_file *filp);
  1059. int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
  1060. struct drm_file *filp);
  1061. int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1062. struct drm_file *filp);
  1063. int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1064. struct drm_file *filp);
  1065. int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
  1066. struct drm_file *filp);
  1067. int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
  1068. struct drm_file *filp);
  1069. int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1070. int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1071. int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
  1072. struct drm_file *filp);
  1073. int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
  1074. struct drm_file *filp);
  1075. /* VRAM scratch page for HDP bug, default vram page */
  1076. struct amdgpu_vram_scratch {
  1077. struct amdgpu_bo *robj;
  1078. volatile uint32_t *ptr;
  1079. u64 gpu_addr;
  1080. };
  1081. /*
  1082. * ACPI
  1083. */
  1084. struct amdgpu_atif_notification_cfg {
  1085. bool enabled;
  1086. int command_code;
  1087. };
  1088. struct amdgpu_atif_notifications {
  1089. bool display_switch;
  1090. bool expansion_mode_change;
  1091. bool thermal_state;
  1092. bool forced_power_state;
  1093. bool system_power_state;
  1094. bool display_conf_change;
  1095. bool px_gfx_switch;
  1096. bool brightness_change;
  1097. bool dgpu_display_event;
  1098. };
  1099. struct amdgpu_atif_functions {
  1100. bool system_params;
  1101. bool sbios_requests;
  1102. bool select_active_disp;
  1103. bool lid_state;
  1104. bool get_tv_standard;
  1105. bool set_tv_standard;
  1106. bool get_panel_expansion_mode;
  1107. bool set_panel_expansion_mode;
  1108. bool temperature_change;
  1109. bool graphics_device_types;
  1110. };
  1111. struct amdgpu_atif {
  1112. struct amdgpu_atif_notifications notifications;
  1113. struct amdgpu_atif_functions functions;
  1114. struct amdgpu_atif_notification_cfg notification_cfg;
  1115. struct amdgpu_encoder *encoder_for_bl;
  1116. };
  1117. struct amdgpu_atcs_functions {
  1118. bool get_ext_state;
  1119. bool pcie_perf_req;
  1120. bool pcie_dev_rdy;
  1121. bool pcie_bus_width;
  1122. };
  1123. struct amdgpu_atcs {
  1124. struct amdgpu_atcs_functions functions;
  1125. };
  1126. /*
  1127. * CGS
  1128. */
  1129. struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
  1130. void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
  1131. /*
  1132. * Core structure, functions and helpers.
  1133. */
  1134. typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
  1135. typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  1136. typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  1137. typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
  1138. struct amdgpu_device {
  1139. struct device *dev;
  1140. struct drm_device *ddev;
  1141. struct pci_dev *pdev;
  1142. #ifdef CONFIG_DRM_AMD_ACP
  1143. struct amdgpu_acp acp;
  1144. #endif
  1145. /* ASIC */
  1146. enum amd_asic_type asic_type;
  1147. uint32_t family;
  1148. uint32_t rev_id;
  1149. uint32_t external_rev_id;
  1150. unsigned long flags;
  1151. int usec_timeout;
  1152. const struct amdgpu_asic_funcs *asic_funcs;
  1153. bool shutdown;
  1154. bool need_dma32;
  1155. bool accel_working;
  1156. struct work_struct reset_work;
  1157. struct notifier_block acpi_nb;
  1158. struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
  1159. struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  1160. unsigned debugfs_count;
  1161. #if defined(CONFIG_DEBUG_FS)
  1162. struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
  1163. #endif
  1164. struct amdgpu_atif atif;
  1165. struct amdgpu_atcs atcs;
  1166. struct mutex srbm_mutex;
  1167. /* GRBM index mutex. Protects concurrent access to GRBM index */
  1168. struct mutex grbm_idx_mutex;
  1169. struct dev_pm_domain vga_pm_domain;
  1170. bool have_disp_power_ref;
  1171. /* BIOS */
  1172. uint8_t *bios;
  1173. uint32_t bios_size;
  1174. bool is_atom_bios;
  1175. struct amdgpu_bo *stollen_vga_memory;
  1176. uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
  1177. /* Register/doorbell mmio */
  1178. resource_size_t rmmio_base;
  1179. resource_size_t rmmio_size;
  1180. void __iomem *rmmio;
  1181. /* protects concurrent MM_INDEX/DATA based register access */
  1182. spinlock_t mmio_idx_lock;
  1183. /* protects concurrent SMC based register access */
  1184. spinlock_t smc_idx_lock;
  1185. amdgpu_rreg_t smc_rreg;
  1186. amdgpu_wreg_t smc_wreg;
  1187. /* protects concurrent PCIE register access */
  1188. spinlock_t pcie_idx_lock;
  1189. amdgpu_rreg_t pcie_rreg;
  1190. amdgpu_wreg_t pcie_wreg;
  1191. amdgpu_rreg_t pciep_rreg;
  1192. amdgpu_wreg_t pciep_wreg;
  1193. /* protects concurrent UVD register access */
  1194. spinlock_t uvd_ctx_idx_lock;
  1195. amdgpu_rreg_t uvd_ctx_rreg;
  1196. amdgpu_wreg_t uvd_ctx_wreg;
  1197. /* protects concurrent DIDT register access */
  1198. spinlock_t didt_idx_lock;
  1199. amdgpu_rreg_t didt_rreg;
  1200. amdgpu_wreg_t didt_wreg;
  1201. /* protects concurrent gc_cac register access */
  1202. spinlock_t gc_cac_idx_lock;
  1203. amdgpu_rreg_t gc_cac_rreg;
  1204. amdgpu_wreg_t gc_cac_wreg;
  1205. /* protects concurrent ENDPOINT (audio) register access */
  1206. spinlock_t audio_endpt_idx_lock;
  1207. amdgpu_block_rreg_t audio_endpt_rreg;
  1208. amdgpu_block_wreg_t audio_endpt_wreg;
  1209. void __iomem *rio_mem;
  1210. resource_size_t rio_mem_size;
  1211. struct amdgpu_doorbell doorbell;
  1212. /* clock/pll info */
  1213. struct amdgpu_clock clock;
  1214. /* MC */
  1215. struct amdgpu_mc mc;
  1216. struct amdgpu_gart gart;
  1217. struct amdgpu_dummy_page dummy_page;
  1218. struct amdgpu_vm_manager vm_manager;
  1219. /* memory management */
  1220. struct amdgpu_mman mman;
  1221. struct amdgpu_vram_scratch vram_scratch;
  1222. struct amdgpu_wb wb;
  1223. atomic64_t vram_usage;
  1224. atomic64_t vram_vis_usage;
  1225. atomic64_t gtt_usage;
  1226. atomic64_t num_bytes_moved;
  1227. atomic64_t num_evictions;
  1228. atomic_t gpu_reset_counter;
  1229. /* data for buffer migration throttling */
  1230. struct {
  1231. spinlock_t lock;
  1232. s64 last_update_us;
  1233. s64 accum_us; /* accumulated microseconds */
  1234. u32 log2_max_MBps;
  1235. } mm_stats;
  1236. /* display */
  1237. bool enable_virtual_display;
  1238. struct amdgpu_mode_info mode_info;
  1239. struct work_struct hotplug_work;
  1240. struct amdgpu_irq_src crtc_irq;
  1241. struct amdgpu_irq_src pageflip_irq;
  1242. struct amdgpu_irq_src hpd_irq;
  1243. /* rings */
  1244. u64 fence_context;
  1245. unsigned num_rings;
  1246. struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
  1247. bool ib_pool_ready;
  1248. struct amdgpu_sa_manager ring_tmp_bo;
  1249. /* interrupts */
  1250. struct amdgpu_irq irq;
  1251. /* powerplay */
  1252. struct amd_powerplay powerplay;
  1253. bool pp_enabled;
  1254. bool pp_force_state_enabled;
  1255. /* dpm */
  1256. struct amdgpu_pm pm;
  1257. u32 cg_flags;
  1258. u32 pg_flags;
  1259. /* amdgpu smumgr */
  1260. struct amdgpu_smumgr smu;
  1261. /* gfx */
  1262. struct amdgpu_gfx gfx;
  1263. /* sdma */
  1264. struct amdgpu_sdma sdma;
  1265. /* uvd */
  1266. struct amdgpu_uvd uvd;
  1267. /* vce */
  1268. struct amdgpu_vce vce;
  1269. /* firmwares */
  1270. struct amdgpu_firmware firmware;
  1271. /* GDS */
  1272. struct amdgpu_gds gds;
  1273. struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM];
  1274. int num_ip_blocks;
  1275. struct mutex mn_lock;
  1276. DECLARE_HASHTABLE(mn_hash, 7);
  1277. /* tracking pinned memory */
  1278. u64 vram_pin_size;
  1279. u64 invisible_pin_size;
  1280. u64 gart_pin_size;
  1281. /* amdkfd interface */
  1282. struct kfd_dev *kfd;
  1283. struct amdgpu_virtualization virtualization;
  1284. /* link all shadow bo */
  1285. struct list_head shadow_list;
  1286. struct mutex shadow_list_lock;
  1287. /* link all gtt */
  1288. spinlock_t gtt_list_lock;
  1289. struct list_head gtt_list;
  1290. };
  1291. static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
  1292. {
  1293. return container_of(bdev, struct amdgpu_device, mman.bdev);
  1294. }
  1295. bool amdgpu_device_is_px(struct drm_device *dev);
  1296. int amdgpu_device_init(struct amdgpu_device *adev,
  1297. struct drm_device *ddev,
  1298. struct pci_dev *pdev,
  1299. uint32_t flags);
  1300. void amdgpu_device_fini(struct amdgpu_device *adev);
  1301. int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
  1302. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  1303. bool always_indirect);
  1304. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  1305. bool always_indirect);
  1306. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
  1307. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
  1308. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
  1309. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
  1310. /*
  1311. * Registers read & write functions.
  1312. */
  1313. #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
  1314. #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
  1315. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
  1316. #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
  1317. #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
  1318. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1319. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1320. #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
  1321. #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
  1322. #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
  1323. #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
  1324. #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
  1325. #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
  1326. #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
  1327. #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
  1328. #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
  1329. #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
  1330. #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
  1331. #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
  1332. #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
  1333. #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
  1334. #define WREG32_P(reg, val, mask) \
  1335. do { \
  1336. uint32_t tmp_ = RREG32(reg); \
  1337. tmp_ &= (mask); \
  1338. tmp_ |= ((val) & ~(mask)); \
  1339. WREG32(reg, tmp_); \
  1340. } while (0)
  1341. #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
  1342. #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
  1343. #define WREG32_PLL_P(reg, val, mask) \
  1344. do { \
  1345. uint32_t tmp_ = RREG32_PLL(reg); \
  1346. tmp_ &= (mask); \
  1347. tmp_ |= ((val) & ~(mask)); \
  1348. WREG32_PLL(reg, tmp_); \
  1349. } while (0)
  1350. #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
  1351. #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
  1352. #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
  1353. #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
  1354. #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
  1355. #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  1356. #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  1357. #define REG_SET_FIELD(orig_val, reg, field, field_val) \
  1358. (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
  1359. (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
  1360. #define REG_GET_FIELD(value, reg, field) \
  1361. (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
  1362. #define WREG32_FIELD(reg, field, val) \
  1363. WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
  1364. /*
  1365. * BIOS helpers.
  1366. */
  1367. #define RBIOS8(i) (adev->bios[i])
  1368. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1369. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1370. /*
  1371. * RING helpers.
  1372. */
  1373. static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
  1374. {
  1375. if (ring->count_dw <= 0)
  1376. DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
  1377. ring->ring[ring->wptr++] = v;
  1378. ring->wptr &= ring->ptr_mask;
  1379. ring->count_dw--;
  1380. }
  1381. static inline struct amdgpu_sdma_instance *
  1382. amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
  1383. {
  1384. struct amdgpu_device *adev = ring->adev;
  1385. int i;
  1386. for (i = 0; i < adev->sdma.num_instances; i++)
  1387. if (&adev->sdma.instance[i].ring == ring)
  1388. break;
  1389. if (i < AMDGPU_MAX_SDMA_INSTANCES)
  1390. return &adev->sdma.instance[i];
  1391. else
  1392. return NULL;
  1393. }
  1394. /*
  1395. * ASICs macro.
  1396. */
  1397. #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
  1398. #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
  1399. #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
  1400. #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
  1401. #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
  1402. #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
  1403. #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
  1404. #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
  1405. #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
  1406. #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
  1407. #define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev))
  1408. #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
  1409. #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
  1410. #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
  1411. #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
  1412. #define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
  1413. #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)))
  1414. #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
  1415. #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
  1416. #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
  1417. #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
  1418. #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
  1419. #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
  1420. #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
  1421. #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
  1422. #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
  1423. #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
  1424. #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))
  1425. #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
  1426. #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
  1427. #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
  1428. #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
  1429. #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
  1430. #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
  1431. #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
  1432. #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
  1433. #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
  1434. #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
  1435. #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
  1436. #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
  1437. #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
  1438. #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
  1439. #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
  1440. #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
  1441. #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
  1442. #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
  1443. #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
  1444. #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
  1445. #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
  1446. #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
  1447. #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))
  1448. #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
  1449. #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
  1450. #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b))
  1451. #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
  1452. #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
  1453. #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
  1454. #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
  1455. /* Common functions */
  1456. int amdgpu_gpu_reset(struct amdgpu_device *adev);
  1457. bool amdgpu_need_backup(struct amdgpu_device *adev);
  1458. void amdgpu_pci_config_reset(struct amdgpu_device *adev);
  1459. bool amdgpu_card_posted(struct amdgpu_device *adev);
  1460. void amdgpu_update_display_priority(struct amdgpu_device *adev);
  1461. int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
  1462. int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
  1463. u32 ip_instance, u32 ring,
  1464. struct amdgpu_ring **out_ring);
  1465. void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
  1466. bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
  1467. int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
  1468. int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
  1469. uint32_t flags);
  1470. bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
  1471. struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
  1472. bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
  1473. unsigned long end);
  1474. bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
  1475. int *last_invalidated);
  1476. bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
  1477. uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
  1478. struct ttm_mem_reg *mem);
  1479. void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
  1480. void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
  1481. void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
  1482. int amdgpu_ttm_init(struct amdgpu_device *adev);
  1483. void amdgpu_ttm_fini(struct amdgpu_device *adev);
  1484. void amdgpu_program_register_sequence(struct amdgpu_device *adev,
  1485. const u32 *registers,
  1486. const u32 array_size);
  1487. bool amdgpu_device_is_px(struct drm_device *dev);
  1488. /* atpx handler */
  1489. #if defined(CONFIG_VGA_SWITCHEROO)
  1490. void amdgpu_register_atpx_handler(void);
  1491. void amdgpu_unregister_atpx_handler(void);
  1492. bool amdgpu_has_atpx_dgpu_power_cntl(void);
  1493. bool amdgpu_is_atpx_hybrid(void);
  1494. bool amdgpu_atpx_dgpu_req_power_for_displays(void);
  1495. #else
  1496. static inline void amdgpu_register_atpx_handler(void) {}
  1497. static inline void amdgpu_unregister_atpx_handler(void) {}
  1498. static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
  1499. static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
  1500. static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
  1501. #endif
  1502. /*
  1503. * KMS
  1504. */
  1505. extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
  1506. extern const int amdgpu_max_kms_ioctl;
  1507. int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
  1508. void amdgpu_driver_unload_kms(struct drm_device *dev);
  1509. void amdgpu_driver_lastclose_kms(struct drm_device *dev);
  1510. int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
  1511. void amdgpu_driver_postclose_kms(struct drm_device *dev,
  1512. struct drm_file *file_priv);
  1513. void amdgpu_driver_preclose_kms(struct drm_device *dev,
  1514. struct drm_file *file_priv);
  1515. int amdgpu_suspend(struct amdgpu_device *adev);
  1516. int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
  1517. int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
  1518. u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
  1519. int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  1520. void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
  1521. int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
  1522. int *max_error,
  1523. struct timeval *vblank_time,
  1524. unsigned flags);
  1525. long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
  1526. unsigned long arg);
  1527. /*
  1528. * functions used by amdgpu_encoder.c
  1529. */
  1530. struct amdgpu_afmt_acr {
  1531. u32 clock;
  1532. int n_32khz;
  1533. int cts_32khz;
  1534. int n_44_1khz;
  1535. int cts_44_1khz;
  1536. int n_48khz;
  1537. int cts_48khz;
  1538. };
  1539. struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
  1540. /* amdgpu_acpi.c */
  1541. #if defined(CONFIG_ACPI)
  1542. int amdgpu_acpi_init(struct amdgpu_device *adev);
  1543. void amdgpu_acpi_fini(struct amdgpu_device *adev);
  1544. bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
  1545. int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
  1546. u8 perf_req, bool advertise);
  1547. int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
  1548. #else
  1549. static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
  1550. static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
  1551. #endif
  1552. struct amdgpu_bo_va_mapping *
  1553. amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
  1554. uint64_t addr, struct amdgpu_bo **bo);
  1555. int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
  1556. #include "amdgpu_object.h"
  1557. #endif