amdgpu.h 54 KB

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