amdgpu.h 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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. #ifdef pr_fmt
  31. #undef pr_fmt
  32. #endif
  33. #define pr_fmt(fmt) "amdgpu: " fmt
  34. #ifdef dev_fmt
  35. #undef dev_fmt
  36. #endif
  37. #define dev_fmt(fmt) "amdgpu: " fmt
  38. #include "amdgpu_ctx.h"
  39. #include <linux/atomic.h>
  40. #include <linux/wait.h>
  41. #include <linux/list.h>
  42. #include <linux/kref.h>
  43. #include <linux/rbtree.h>
  44. #include <linux/hashtable.h>
  45. #include <linux/dma-fence.h>
  46. #include <linux/pci.h>
  47. #include <linux/aer.h>
  48. #include <drm/ttm/ttm_bo_api.h>
  49. #include <drm/ttm/ttm_bo_driver.h>
  50. #include <drm/ttm/ttm_placement.h>
  51. #include <drm/ttm/ttm_execbuf_util.h>
  52. #include <drm/amdgpu_drm.h>
  53. #include <drm/drm_gem.h>
  54. #include <drm/drm_ioctl.h>
  55. #include <kgd_kfd_interface.h>
  56. #include "dm_pp_interface.h"
  57. #include "kgd_pp_interface.h"
  58. #include "amd_shared.h"
  59. #include "amdgpu_mode.h"
  60. #include "amdgpu_ih.h"
  61. #include "amdgpu_irq.h"
  62. #include "amdgpu_ucode.h"
  63. #include "amdgpu_ttm.h"
  64. #include "amdgpu_psp.h"
  65. #include "amdgpu_gds.h"
  66. #include "amdgpu_sync.h"
  67. #include "amdgpu_ring.h"
  68. #include "amdgpu_vm.h"
  69. #include "amdgpu_dpm.h"
  70. #include "amdgpu_acp.h"
  71. #include "amdgpu_uvd.h"
  72. #include "amdgpu_vce.h"
  73. #include "amdgpu_vcn.h"
  74. #include "amdgpu_jpeg.h"
  75. #include "amdgpu_mn.h"
  76. #include "amdgpu_gmc.h"
  77. #include "amdgpu_gfx.h"
  78. #include "amdgpu_sdma.h"
  79. #include "amdgpu_lsdma.h"
  80. #include "amdgpu_nbio.h"
  81. #include "amdgpu_hdp.h"
  82. #include "amdgpu_dm.h"
  83. #include "amdgpu_virt.h"
  84. #include "amdgpu_csa.h"
  85. #include "amdgpu_mes_ctx.h"
  86. #include "amdgpu_gart.h"
  87. #include "amdgpu_debugfs.h"
  88. #include "amdgpu_job.h"
  89. #include "amdgpu_bo_list.h"
  90. #include "amdgpu_gem.h"
  91. #include "amdgpu_doorbell.h"
  92. #include "amdgpu_amdkfd.h"
  93. #include "amdgpu_discovery.h"
  94. #include "amdgpu_mes.h"
  95. #include "amdgpu_umc.h"
  96. #include "amdgpu_mmhub.h"
  97. #include "amdgpu_gfxhub.h"
  98. #include "amdgpu_df.h"
  99. #include "amdgpu_smuio.h"
  100. #include "amdgpu_fdinfo.h"
  101. #include "amdgpu_mca.h"
  102. #include "amdgpu_ras.h"
  103. #define MAX_GPU_INSTANCE 16
  104. struct amdgpu_gpu_instance
  105. {
  106. struct amdgpu_device *adev;
  107. int mgpu_fan_enabled;
  108. };
  109. struct amdgpu_mgpu_info
  110. {
  111. struct amdgpu_gpu_instance gpu_ins[MAX_GPU_INSTANCE];
  112. struct mutex mutex;
  113. uint32_t num_gpu;
  114. uint32_t num_dgpu;
  115. uint32_t num_apu;
  116. /* delayed reset_func for XGMI configuration if necessary */
  117. struct delayed_work delayed_reset_work;
  118. bool pending_reset;
  119. };
  120. enum amdgpu_ss {
  121. AMDGPU_SS_DRV_LOAD,
  122. AMDGPU_SS_DEV_D0,
  123. AMDGPU_SS_DEV_D3,
  124. AMDGPU_SS_DRV_UNLOAD
  125. };
  126. struct amdgpu_watchdog_timer
  127. {
  128. bool timeout_fatal_disable;
  129. uint32_t period; /* maxCycles = (1 << period), the number of cycles before a timeout */
  130. };
  131. #define AMDGPU_MAX_TIMEOUT_PARAM_LENGTH 256
  132. /*
  133. * Modules parameters.
  134. */
  135. extern int amdgpu_modeset;
  136. extern int amdgpu_vram_limit;
  137. extern int amdgpu_vis_vram_limit;
  138. extern int amdgpu_gart_size;
  139. extern int amdgpu_gtt_size;
  140. extern int amdgpu_moverate;
  141. extern int amdgpu_audio;
  142. extern int amdgpu_disp_priority;
  143. extern int amdgpu_hw_i2c;
  144. extern int amdgpu_pcie_gen2;
  145. extern int amdgpu_msi;
  146. extern char amdgpu_lockup_timeout[AMDGPU_MAX_TIMEOUT_PARAM_LENGTH];
  147. extern int amdgpu_dpm;
  148. extern int amdgpu_fw_load_type;
  149. extern int amdgpu_aspm;
  150. extern int amdgpu_runtime_pm;
  151. extern uint amdgpu_ip_block_mask;
  152. extern int amdgpu_bapm;
  153. extern int amdgpu_deep_color;
  154. extern int amdgpu_vm_size;
  155. extern int amdgpu_vm_block_size;
  156. extern int amdgpu_vm_fragment_size;
  157. extern int amdgpu_vm_fault_stop;
  158. extern int amdgpu_vm_debug;
  159. extern int amdgpu_vm_update_mode;
  160. extern int amdgpu_exp_hw_support;
  161. extern int amdgpu_dc;
  162. extern int amdgpu_sched_jobs;
  163. extern int amdgpu_sched_hw_submission;
  164. extern uint amdgpu_pcie_gen_cap;
  165. extern uint amdgpu_pcie_lane_cap;
  166. extern u64 amdgpu_cg_mask;
  167. extern uint amdgpu_pg_mask;
  168. extern uint amdgpu_sdma_phase_quantum;
  169. extern char *amdgpu_disable_cu;
  170. extern char *amdgpu_virtual_display;
  171. extern uint amdgpu_pp_feature_mask;
  172. extern uint amdgpu_force_long_training;
  173. extern int amdgpu_job_hang_limit;
  174. extern int amdgpu_lbpw;
  175. extern int amdgpu_compute_multipipe;
  176. extern int amdgpu_gpu_recovery;
  177. extern int amdgpu_emu_mode;
  178. extern uint amdgpu_smu_memory_pool_size;
  179. extern int amdgpu_smu_pptable_id;
  180. extern uint amdgpu_dc_feature_mask;
  181. extern uint amdgpu_freesync_vid_mode;
  182. extern uint amdgpu_dc_debug_mask;
  183. extern uint amdgpu_dc_visual_confirm;
  184. extern uint amdgpu_dm_abm_level;
  185. extern int amdgpu_backlight;
  186. extern struct amdgpu_mgpu_info mgpu_info;
  187. extern int amdgpu_ras_enable;
  188. extern uint amdgpu_ras_mask;
  189. extern int amdgpu_bad_page_threshold;
  190. extern bool amdgpu_ignore_bad_page_threshold;
  191. extern struct amdgpu_watchdog_timer amdgpu_watchdog_timer;
  192. extern int amdgpu_async_gfx_ring;
  193. extern int amdgpu_mcbp;
  194. extern int amdgpu_discovery;
  195. extern int amdgpu_mes;
  196. extern int amdgpu_mes_kiq;
  197. extern int amdgpu_noretry;
  198. extern int amdgpu_force_asic_type;
  199. extern int amdgpu_smartshift_bias;
  200. extern int amdgpu_use_xgmi_p2p;
  201. #ifdef CONFIG_HSA_AMD
  202. extern int sched_policy;
  203. extern bool debug_evictions;
  204. extern bool no_system_mem_limit;
  205. #else
  206. static const int __maybe_unused sched_policy = KFD_SCHED_POLICY_HWS;
  207. static const bool __maybe_unused debug_evictions; /* = false */
  208. static const bool __maybe_unused no_system_mem_limit;
  209. #endif
  210. #ifdef CONFIG_HSA_AMD_P2P
  211. extern bool pcie_p2p;
  212. #endif
  213. extern int amdgpu_tmz;
  214. extern int amdgpu_reset_method;
  215. #ifdef CONFIG_DRM_AMDGPU_SI
  216. extern int amdgpu_si_support;
  217. #endif
  218. #ifdef CONFIG_DRM_AMDGPU_CIK
  219. extern int amdgpu_cik_support;
  220. #endif
  221. extern int amdgpu_num_kcq;
  222. #define AMDGPU_VCNFW_LOG_SIZE (32 * 1024)
  223. extern int amdgpu_vcnfw_log;
  224. extern int amdgpu_sg_display;
  225. #define AMDGPU_VM_MAX_NUM_CTX 4096
  226. #define AMDGPU_SG_THRESHOLD (256*1024*1024)
  227. #define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */
  228. #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
  229. #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  230. #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  231. #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
  232. #define AMDGPUFB_CONN_LIMIT 4
  233. #define AMDGPU_BIOS_NUM_SCRATCH 16
  234. #define AMDGPU_VBIOS_VGA_ALLOCATION (9 * 1024 * 1024) /* reserve 8MB for vga emulator and 1 MB for FB */
  235. /* hard reset data */
  236. #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
  237. /* reset flags */
  238. #define AMDGPU_RESET_GFX (1 << 0)
  239. #define AMDGPU_RESET_COMPUTE (1 << 1)
  240. #define AMDGPU_RESET_DMA (1 << 2)
  241. #define AMDGPU_RESET_CP (1 << 3)
  242. #define AMDGPU_RESET_GRBM (1 << 4)
  243. #define AMDGPU_RESET_DMA1 (1 << 5)
  244. #define AMDGPU_RESET_RLC (1 << 6)
  245. #define AMDGPU_RESET_SEM (1 << 7)
  246. #define AMDGPU_RESET_IH (1 << 8)
  247. #define AMDGPU_RESET_VMC (1 << 9)
  248. #define AMDGPU_RESET_MC (1 << 10)
  249. #define AMDGPU_RESET_DISPLAY (1 << 11)
  250. #define AMDGPU_RESET_UVD (1 << 12)
  251. #define AMDGPU_RESET_VCE (1 << 13)
  252. #define AMDGPU_RESET_VCE1 (1 << 14)
  253. /* max cursor sizes (in pixels) */
  254. #define CIK_CURSOR_WIDTH 128
  255. #define CIK_CURSOR_HEIGHT 128
  256. /* smart shift bias level limits */
  257. #define AMDGPU_SMARTSHIFT_MAX_BIAS (100)
  258. #define AMDGPU_SMARTSHIFT_MIN_BIAS (-100)
  259. /* Extra time delay(in ms) to eliminate the influence of temperature momentary fluctuation */
  260. #define AMDGPU_SWCTF_EXTRA_DELAY 50
  261. struct amdgpu_device;
  262. struct amdgpu_irq_src;
  263. struct amdgpu_fpriv;
  264. struct amdgpu_bo_va_mapping;
  265. struct kfd_vm_fault_info;
  266. struct amdgpu_hive_info;
  267. struct amdgpu_reset_context;
  268. struct amdgpu_reset_control;
  269. enum amdgpu_cp_irq {
  270. AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP = 0,
  271. AMDGPU_CP_IRQ_GFX_ME0_PIPE1_EOP,
  272. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
  273. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
  274. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
  275. AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
  276. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
  277. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
  278. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
  279. AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
  280. AMDGPU_CP_IRQ_LAST
  281. };
  282. enum amdgpu_thermal_irq {
  283. AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
  284. AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
  285. AMDGPU_THERMAL_IRQ_LAST
  286. };
  287. enum amdgpu_kiq_irq {
  288. AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
  289. AMDGPU_CP_KIQ_IRQ_LAST
  290. };
  291. #define SRIOV_USEC_TIMEOUT 1200000 /* wait 12 * 100ms for SRIOV */
  292. #define MAX_KIQ_REG_WAIT 5000 /* in usecs, 5ms */
  293. #define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */
  294. #define MAX_KIQ_REG_TRY 1000
  295. int amdgpu_device_ip_set_clockgating_state(void *dev,
  296. enum amd_ip_block_type block_type,
  297. enum amd_clockgating_state state);
  298. int amdgpu_device_ip_set_powergating_state(void *dev,
  299. enum amd_ip_block_type block_type,
  300. enum amd_powergating_state state);
  301. void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
  302. u64 *flags);
  303. int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
  304. enum amd_ip_block_type block_type);
  305. bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
  306. enum amd_ip_block_type block_type);
  307. #define AMDGPU_MAX_IP_NUM 16
  308. struct amdgpu_ip_block_status {
  309. bool valid;
  310. bool sw;
  311. bool hw;
  312. bool late_initialized;
  313. bool hang;
  314. };
  315. struct amdgpu_ip_block_version {
  316. const enum amd_ip_block_type type;
  317. const u32 major;
  318. const u32 minor;
  319. const u32 rev;
  320. const struct amd_ip_funcs *funcs;
  321. };
  322. #define HW_REV(_Major, _Minor, _Rev) \
  323. ((((uint32_t) (_Major)) << 16) | ((uint32_t) (_Minor) << 8) | ((uint32_t) (_Rev)))
  324. struct amdgpu_ip_block {
  325. struct amdgpu_ip_block_status status;
  326. const struct amdgpu_ip_block_version *version;
  327. };
  328. int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
  329. enum amd_ip_block_type type,
  330. u32 major, u32 minor);
  331. struct amdgpu_ip_block *
  332. amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
  333. enum amd_ip_block_type type);
  334. int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
  335. const struct amdgpu_ip_block_version *ip_block_version);
  336. /*
  337. * BIOS.
  338. */
  339. bool amdgpu_get_bios(struct amdgpu_device *adev);
  340. bool amdgpu_read_bios(struct amdgpu_device *adev);
  341. bool amdgpu_soc15_read_bios_from_rom(struct amdgpu_device *adev,
  342. u8 *bios, u32 length_bytes);
  343. /*
  344. * Clocks
  345. */
  346. #define AMDGPU_MAX_PPLL 3
  347. struct amdgpu_clock {
  348. struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
  349. struct amdgpu_pll spll;
  350. struct amdgpu_pll mpll;
  351. /* 10 Khz units */
  352. uint32_t default_mclk;
  353. uint32_t default_sclk;
  354. uint32_t default_dispclk;
  355. uint32_t current_dispclk;
  356. uint32_t dp_extclk;
  357. uint32_t max_pixel_clock;
  358. };
  359. /* sub-allocation manager, it has to be protected by another lock.
  360. * By conception this is an helper for other part of the driver
  361. * like the indirect buffer or semaphore, which both have their
  362. * locking.
  363. *
  364. * Principe is simple, we keep a list of sub allocation in offset
  365. * order (first entry has offset == 0, last entry has the highest
  366. * offset).
  367. *
  368. * When allocating new object we first check if there is room at
  369. * the end total_size - (last_object_offset + last_object_size) >=
  370. * alloc_size. If so we allocate new object there.
  371. *
  372. * When there is not enough room at the end, we start waiting for
  373. * each sub object until we reach object_offset+object_size >=
  374. * alloc_size, this object then become the sub object we return.
  375. *
  376. * Alignment can't be bigger than page size.
  377. *
  378. * Hole are not considered for allocation to keep things simple.
  379. * Assumption is that there won't be hole (all object on same
  380. * alignment).
  381. */
  382. #define AMDGPU_SA_NUM_FENCE_LISTS 32
  383. struct amdgpu_sa_manager {
  384. wait_queue_head_t wq;
  385. struct amdgpu_bo *bo;
  386. struct list_head *hole;
  387. struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
  388. struct list_head olist;
  389. unsigned size;
  390. uint64_t gpu_addr;
  391. void *cpu_ptr;
  392. uint32_t domain;
  393. uint32_t align;
  394. };
  395. /* sub-allocation buffer */
  396. struct amdgpu_sa_bo {
  397. struct list_head olist;
  398. struct list_head flist;
  399. struct amdgpu_sa_manager *manager;
  400. unsigned soffset;
  401. unsigned eoffset;
  402. struct dma_fence *fence;
  403. };
  404. int amdgpu_fence_slab_init(void);
  405. void amdgpu_fence_slab_fini(void);
  406. /*
  407. * IRQS.
  408. */
  409. struct amdgpu_flip_work {
  410. struct delayed_work flip_work;
  411. struct work_struct unpin_work;
  412. struct amdgpu_device *adev;
  413. int crtc_id;
  414. u32 target_vblank;
  415. uint64_t base;
  416. struct drm_pending_vblank_event *event;
  417. struct amdgpu_bo *old_abo;
  418. unsigned shared_count;
  419. struct dma_fence **shared;
  420. struct dma_fence_cb cb;
  421. bool async;
  422. };
  423. /*
  424. * file private structure
  425. */
  426. struct amdgpu_fpriv {
  427. struct amdgpu_vm vm;
  428. struct amdgpu_bo_va *prt_va;
  429. struct amdgpu_bo_va *csa_va;
  430. struct mutex bo_list_lock;
  431. struct idr bo_list_handles;
  432. struct amdgpu_ctx_mgr ctx_mgr;
  433. };
  434. int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
  435. /*
  436. * Writeback
  437. */
  438. #define AMDGPU_MAX_WB 256 /* Reserve at most 256 WB slots for amdgpu-owned rings. */
  439. struct amdgpu_wb {
  440. struct amdgpu_bo *wb_obj;
  441. volatile uint32_t *wb;
  442. uint64_t gpu_addr;
  443. u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
  444. unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
  445. };
  446. int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
  447. void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
  448. /*
  449. * Benchmarking
  450. */
  451. int amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
  452. /*
  453. * ASIC specific register table accessible by UMD
  454. */
  455. struct amdgpu_allowed_register_entry {
  456. uint32_t reg_offset;
  457. bool grbm_indexed;
  458. };
  459. enum amd_reset_method {
  460. AMD_RESET_METHOD_NONE = -1,
  461. AMD_RESET_METHOD_LEGACY = 0,
  462. AMD_RESET_METHOD_MODE0,
  463. AMD_RESET_METHOD_MODE1,
  464. AMD_RESET_METHOD_MODE2,
  465. AMD_RESET_METHOD_BACO,
  466. AMD_RESET_METHOD_PCI,
  467. };
  468. struct amdgpu_video_codec_info {
  469. u32 codec_type;
  470. u32 max_width;
  471. u32 max_height;
  472. u32 max_pixels_per_frame;
  473. u32 max_level;
  474. };
  475. #define codec_info_build(type, width, height, level) \
  476. .codec_type = type,\
  477. .max_width = width,\
  478. .max_height = height,\
  479. .max_pixels_per_frame = height * width,\
  480. .max_level = level,
  481. struct amdgpu_video_codecs {
  482. const u32 codec_count;
  483. const struct amdgpu_video_codec_info *codec_array;
  484. };
  485. /*
  486. * ASIC specific functions.
  487. */
  488. struct amdgpu_asic_funcs {
  489. bool (*read_disabled_bios)(struct amdgpu_device *adev);
  490. bool (*read_bios_from_rom)(struct amdgpu_device *adev,
  491. u8 *bios, u32 length_bytes);
  492. int (*read_register)(struct amdgpu_device *adev, u32 se_num,
  493. u32 sh_num, u32 reg_offset, u32 *value);
  494. void (*set_vga_state)(struct amdgpu_device *adev, bool state);
  495. int (*reset)(struct amdgpu_device *adev);
  496. enum amd_reset_method (*reset_method)(struct amdgpu_device *adev);
  497. /* get the reference clock */
  498. u32 (*get_xclk)(struct amdgpu_device *adev);
  499. /* MM block clocks */
  500. int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
  501. int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
  502. /* static power management */
  503. int (*get_pcie_lanes)(struct amdgpu_device *adev);
  504. void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
  505. /* get config memsize register */
  506. u32 (*get_config_memsize)(struct amdgpu_device *adev);
  507. /* flush hdp write queue */
  508. void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
  509. /* invalidate hdp read cache */
  510. void (*invalidate_hdp)(struct amdgpu_device *adev,
  511. struct amdgpu_ring *ring);
  512. /* check if the asic needs a full reset of if soft reset will work */
  513. bool (*need_full_reset)(struct amdgpu_device *adev);
  514. /* initialize doorbell layout for specific asic*/
  515. void (*init_doorbell_index)(struct amdgpu_device *adev);
  516. /* PCIe bandwidth usage */
  517. void (*get_pcie_usage)(struct amdgpu_device *adev, uint64_t *count0,
  518. uint64_t *count1);
  519. /* do we need to reset the asic at init time (e.g., kexec) */
  520. bool (*need_reset_on_init)(struct amdgpu_device *adev);
  521. /* PCIe replay counter */
  522. uint64_t (*get_pcie_replay_count)(struct amdgpu_device *adev);
  523. /* device supports BACO */
  524. bool (*supports_baco)(struct amdgpu_device *adev);
  525. /* pre asic_init quirks */
  526. void (*pre_asic_init)(struct amdgpu_device *adev);
  527. /* enter/exit umd stable pstate */
  528. int (*update_umd_stable_pstate)(struct amdgpu_device *adev, bool enter);
  529. /* query video codecs */
  530. int (*query_video_codecs)(struct amdgpu_device *adev, bool encode,
  531. const struct amdgpu_video_codecs **codecs);
  532. };
  533. /*
  534. * IOCTL.
  535. */
  536. int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
  537. struct drm_file *filp);
  538. int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  539. int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
  540. struct drm_file *filp);
  541. int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  542. int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
  543. struct drm_file *filp);
  544. /* VRAM scratch page for HDP bug, default vram page */
  545. struct amdgpu_vram_scratch {
  546. struct amdgpu_bo *robj;
  547. volatile uint32_t *ptr;
  548. u64 gpu_addr;
  549. };
  550. /*
  551. * CGS
  552. */
  553. struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
  554. void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
  555. /*
  556. * Core structure, functions and helpers.
  557. */
  558. typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
  559. typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  560. typedef uint64_t (*amdgpu_rreg64_t)(struct amdgpu_device*, uint32_t);
  561. typedef void (*amdgpu_wreg64_t)(struct amdgpu_device*, uint32_t, uint64_t);
  562. typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
  563. typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
  564. struct amdgpu_mmio_remap {
  565. u32 reg_offset;
  566. resource_size_t bus_addr;
  567. };
  568. /* Define the HW IP blocks will be used in driver , add more if necessary */
  569. enum amd_hw_ip_block_type {
  570. GC_HWIP = 1,
  571. HDP_HWIP,
  572. SDMA0_HWIP,
  573. SDMA1_HWIP,
  574. SDMA2_HWIP,
  575. SDMA3_HWIP,
  576. SDMA4_HWIP,
  577. SDMA5_HWIP,
  578. SDMA6_HWIP,
  579. SDMA7_HWIP,
  580. LSDMA_HWIP,
  581. MMHUB_HWIP,
  582. ATHUB_HWIP,
  583. NBIO_HWIP,
  584. MP0_HWIP,
  585. MP1_HWIP,
  586. UVD_HWIP,
  587. VCN_HWIP = UVD_HWIP,
  588. JPEG_HWIP = VCN_HWIP,
  589. VCN1_HWIP,
  590. VCE_HWIP,
  591. DF_HWIP,
  592. DCE_HWIP,
  593. OSSSYS_HWIP,
  594. SMUIO_HWIP,
  595. PWR_HWIP,
  596. NBIF_HWIP,
  597. THM_HWIP,
  598. CLK_HWIP,
  599. UMC_HWIP,
  600. RSMU_HWIP,
  601. XGMI_HWIP,
  602. DCI_HWIP,
  603. PCIE_HWIP,
  604. MAX_HWIP
  605. };
  606. #define HWIP_MAX_INSTANCE 11
  607. #define HW_ID_MAX 300
  608. #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) | (rv))
  609. #define IP_VERSION_MAJ(ver) ((ver) >> 16)
  610. #define IP_VERSION_MIN(ver) (((ver) >> 8) & 0xFF)
  611. #define IP_VERSION_REV(ver) ((ver) & 0xFF)
  612. struct amd_powerplay {
  613. void *pp_handle;
  614. const struct amd_pm_funcs *pp_funcs;
  615. };
  616. struct ip_discovery_top;
  617. /* polaris10 kickers */
  618. #define ASICID_IS_P20(did, rid) (((did == 0x67DF) && \
  619. ((rid == 0xE3) || \
  620. (rid == 0xE4) || \
  621. (rid == 0xE5) || \
  622. (rid == 0xE7) || \
  623. (rid == 0xEF))) || \
  624. ((did == 0x6FDF) && \
  625. ((rid == 0xE7) || \
  626. (rid == 0xEF) || \
  627. (rid == 0xFF))))
  628. #define ASICID_IS_P30(did, rid) ((did == 0x67DF) && \
  629. ((rid == 0xE1) || \
  630. (rid == 0xF7)))
  631. /* polaris11 kickers */
  632. #define ASICID_IS_P21(did, rid) (((did == 0x67EF) && \
  633. ((rid == 0xE0) || \
  634. (rid == 0xE5))) || \
  635. ((did == 0x67FF) && \
  636. ((rid == 0xCF) || \
  637. (rid == 0xEF) || \
  638. (rid == 0xFF))))
  639. #define ASICID_IS_P31(did, rid) ((did == 0x67EF) && \
  640. ((rid == 0xE2)))
  641. /* polaris12 kickers */
  642. #define ASICID_IS_P23(did, rid) (((did == 0x6987) && \
  643. ((rid == 0xC0) || \
  644. (rid == 0xC1) || \
  645. (rid == 0xC3) || \
  646. (rid == 0xC7))) || \
  647. ((did == 0x6981) && \
  648. ((rid == 0x00) || \
  649. (rid == 0x01) || \
  650. (rid == 0x10))))
  651. struct amdgpu_mqd_prop {
  652. uint64_t mqd_gpu_addr;
  653. uint64_t hqd_base_gpu_addr;
  654. uint64_t rptr_gpu_addr;
  655. uint64_t wptr_gpu_addr;
  656. uint32_t queue_size;
  657. bool use_doorbell;
  658. uint32_t doorbell_index;
  659. uint64_t eop_gpu_addr;
  660. uint32_t hqd_pipe_priority;
  661. uint32_t hqd_queue_priority;
  662. bool hqd_active;
  663. };
  664. struct amdgpu_mqd {
  665. unsigned mqd_size;
  666. int (*init_mqd)(struct amdgpu_device *adev, void *mqd,
  667. struct amdgpu_mqd_prop *p);
  668. };
  669. #define AMDGPU_RESET_MAGIC_NUM 64
  670. #define AMDGPU_MAX_DF_PERFMONS 4
  671. #define AMDGPU_PRODUCT_NAME_LEN 64
  672. struct amdgpu_reset_domain;
  673. struct amdgpu_device {
  674. struct device *dev;
  675. struct pci_dev *pdev;
  676. struct drm_device ddev;
  677. #ifdef CONFIG_DRM_AMD_ACP
  678. struct amdgpu_acp acp;
  679. #endif
  680. struct amdgpu_hive_info *hive;
  681. /* ASIC */
  682. enum amd_asic_type asic_type;
  683. uint32_t family;
  684. uint32_t rev_id;
  685. uint32_t external_rev_id;
  686. unsigned long flags;
  687. unsigned long apu_flags;
  688. int usec_timeout;
  689. const struct amdgpu_asic_funcs *asic_funcs;
  690. bool shutdown;
  691. bool need_swiotlb;
  692. bool accel_working;
  693. struct notifier_block acpi_nb;
  694. struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
  695. struct debugfs_blob_wrapper debugfs_vbios_blob;
  696. struct debugfs_blob_wrapper debugfs_discovery_blob;
  697. struct mutex srbm_mutex;
  698. /* GRBM index mutex. Protects concurrent access to GRBM index */
  699. struct mutex grbm_idx_mutex;
  700. struct dev_pm_domain vga_pm_domain;
  701. bool have_disp_power_ref;
  702. bool have_atomics_support;
  703. /* BIOS */
  704. bool is_atom_fw;
  705. uint8_t *bios;
  706. uint32_t bios_size;
  707. uint32_t bios_scratch_reg_offset;
  708. uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
  709. /* Register/doorbell mmio */
  710. resource_size_t rmmio_base;
  711. resource_size_t rmmio_size;
  712. void __iomem *rmmio;
  713. /* protects concurrent MM_INDEX/DATA based register access */
  714. spinlock_t mmio_idx_lock;
  715. struct amdgpu_mmio_remap rmmio_remap;
  716. /* protects concurrent SMC based register access */
  717. spinlock_t smc_idx_lock;
  718. amdgpu_rreg_t smc_rreg;
  719. amdgpu_wreg_t smc_wreg;
  720. /* protects concurrent PCIE register access */
  721. spinlock_t pcie_idx_lock;
  722. amdgpu_rreg_t pcie_rreg;
  723. amdgpu_wreg_t pcie_wreg;
  724. amdgpu_rreg_t pciep_rreg;
  725. amdgpu_wreg_t pciep_wreg;
  726. amdgpu_rreg64_t pcie_rreg64;
  727. amdgpu_wreg64_t pcie_wreg64;
  728. /* protects concurrent UVD register access */
  729. spinlock_t uvd_ctx_idx_lock;
  730. amdgpu_rreg_t uvd_ctx_rreg;
  731. amdgpu_wreg_t uvd_ctx_wreg;
  732. /* protects concurrent DIDT register access */
  733. spinlock_t didt_idx_lock;
  734. amdgpu_rreg_t didt_rreg;
  735. amdgpu_wreg_t didt_wreg;
  736. /* protects concurrent gc_cac register access */
  737. spinlock_t gc_cac_idx_lock;
  738. amdgpu_rreg_t gc_cac_rreg;
  739. amdgpu_wreg_t gc_cac_wreg;
  740. /* protects concurrent se_cac register access */
  741. spinlock_t se_cac_idx_lock;
  742. amdgpu_rreg_t se_cac_rreg;
  743. amdgpu_wreg_t se_cac_wreg;
  744. /* protects concurrent ENDPOINT (audio) register access */
  745. spinlock_t audio_endpt_idx_lock;
  746. amdgpu_block_rreg_t audio_endpt_rreg;
  747. amdgpu_block_wreg_t audio_endpt_wreg;
  748. struct amdgpu_doorbell doorbell;
  749. /* clock/pll info */
  750. struct amdgpu_clock clock;
  751. /* MC */
  752. struct amdgpu_gmc gmc;
  753. struct amdgpu_gart gart;
  754. dma_addr_t dummy_page_addr;
  755. struct amdgpu_vm_manager vm_manager;
  756. struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS];
  757. unsigned num_vmhubs;
  758. /* memory management */
  759. struct amdgpu_mman mman;
  760. struct amdgpu_vram_scratch vram_scratch;
  761. struct amdgpu_wb wb;
  762. atomic64_t num_bytes_moved;
  763. atomic64_t num_evictions;
  764. atomic64_t num_vram_cpu_page_faults;
  765. atomic_t gpu_reset_counter;
  766. atomic_t vram_lost_counter;
  767. /* data for buffer migration throttling */
  768. struct {
  769. spinlock_t lock;
  770. s64 last_update_us;
  771. s64 accum_us; /* accumulated microseconds */
  772. s64 accum_us_vis; /* for visible VRAM */
  773. u32 log2_max_MBps;
  774. } mm_stats;
  775. /* display */
  776. bool enable_virtual_display;
  777. struct amdgpu_vkms_output *amdgpu_vkms_output;
  778. struct amdgpu_mode_info mode_info;
  779. /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
  780. struct work_struct hotplug_work;
  781. struct amdgpu_irq_src crtc_irq;
  782. struct amdgpu_irq_src vline0_irq;
  783. struct amdgpu_irq_src vupdate_irq;
  784. struct amdgpu_irq_src pageflip_irq;
  785. struct amdgpu_irq_src hpd_irq;
  786. struct amdgpu_irq_src dmub_trace_irq;
  787. struct amdgpu_irq_src dmub_outbox_irq;
  788. /* rings */
  789. u64 fence_context;
  790. unsigned num_rings;
  791. struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
  792. struct dma_fence __rcu *gang_submit;
  793. bool ib_pool_ready;
  794. struct amdgpu_sa_manager ib_pools[AMDGPU_IB_POOL_MAX];
  795. struct amdgpu_sched gpu_sched[AMDGPU_HW_IP_NUM][AMDGPU_RING_PRIO_MAX];
  796. /* interrupts */
  797. struct amdgpu_irq irq;
  798. /* powerplay */
  799. struct amd_powerplay powerplay;
  800. struct amdgpu_pm pm;
  801. u64 cg_flags;
  802. u32 pg_flags;
  803. /* nbio */
  804. struct amdgpu_nbio nbio;
  805. /* hdp */
  806. struct amdgpu_hdp hdp;
  807. /* smuio */
  808. struct amdgpu_smuio smuio;
  809. /* mmhub */
  810. struct amdgpu_mmhub mmhub;
  811. /* gfxhub */
  812. struct amdgpu_gfxhub gfxhub;
  813. /* gfx */
  814. struct amdgpu_gfx gfx;
  815. /* sdma */
  816. struct amdgpu_sdma sdma;
  817. /* lsdma */
  818. struct amdgpu_lsdma lsdma;
  819. /* uvd */
  820. struct amdgpu_uvd uvd;
  821. /* vce */
  822. struct amdgpu_vce vce;
  823. /* vcn */
  824. struct amdgpu_vcn vcn;
  825. /* jpeg */
  826. struct amdgpu_jpeg jpeg;
  827. /* firmwares */
  828. struct amdgpu_firmware firmware;
  829. /* PSP */
  830. struct psp_context psp;
  831. /* GDS */
  832. struct amdgpu_gds gds;
  833. /* KFD */
  834. struct amdgpu_kfd_dev kfd;
  835. /* UMC */
  836. struct amdgpu_umc umc;
  837. /* display related functionality */
  838. struct amdgpu_display_manager dm;
  839. /* mes */
  840. bool enable_mes;
  841. bool enable_mes_kiq;
  842. struct amdgpu_mes mes;
  843. struct amdgpu_mqd mqds[AMDGPU_HW_IP_NUM];
  844. /* df */
  845. struct amdgpu_df df;
  846. /* MCA */
  847. struct amdgpu_mca mca;
  848. struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM];
  849. uint32_t harvest_ip_mask;
  850. int num_ip_blocks;
  851. struct mutex mn_lock;
  852. DECLARE_HASHTABLE(mn_hash, 7);
  853. /* tracking pinned memory */
  854. atomic64_t vram_pin_size;
  855. atomic64_t visible_pin_size;
  856. atomic64_t gart_pin_size;
  857. /* soc15 register offset based on ip, instance and segment */
  858. uint32_t *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
  859. /* delayed work_func for deferring clockgating during resume */
  860. struct delayed_work delayed_init_work;
  861. struct amdgpu_virt virt;
  862. /* link all shadow bo */
  863. struct list_head shadow_list;
  864. struct mutex shadow_list_lock;
  865. /* record hw reset is performed */
  866. bool has_hw_reset;
  867. u8 reset_magic[AMDGPU_RESET_MAGIC_NUM];
  868. /* s3/s4 mask */
  869. bool in_suspend;
  870. bool in_s3;
  871. bool in_s4;
  872. bool in_s0ix;
  873. enum pp_mp1_state mp1_state;
  874. struct amdgpu_doorbell_index doorbell_index;
  875. struct mutex notifier_lock;
  876. int asic_reset_res;
  877. struct work_struct xgmi_reset_work;
  878. struct list_head reset_list;
  879. long gfx_timeout;
  880. long sdma_timeout;
  881. long video_timeout;
  882. long compute_timeout;
  883. uint64_t unique_id;
  884. uint64_t df_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS];
  885. /* enable runtime pm on the device */
  886. bool in_runpm;
  887. bool has_pr3;
  888. bool pm_sysfs_en;
  889. bool ucode_sysfs_en;
  890. bool psp_sysfs_en;
  891. /* Chip product information */
  892. char product_number[20];
  893. char product_name[AMDGPU_PRODUCT_NAME_LEN];
  894. char serial[20];
  895. atomic_t throttling_logging_enabled;
  896. struct ratelimit_state throttling_logging_rs;
  897. uint32_t ras_hw_enabled;
  898. uint32_t ras_enabled;
  899. bool no_hw_access;
  900. struct pci_saved_state *pci_state;
  901. pci_channel_state_t pci_channel_state;
  902. struct amdgpu_reset_control *reset_cntl;
  903. uint32_t ip_versions[MAX_HWIP][HWIP_MAX_INSTANCE];
  904. bool ram_is_direct_mapped;
  905. struct list_head ras_list;
  906. struct ip_discovery_top *ip_top;
  907. struct amdgpu_reset_domain *reset_domain;
  908. struct mutex benchmark_mutex;
  909. /* reset dump register */
  910. uint32_t *reset_dump_reg_list;
  911. uint32_t *reset_dump_reg_value;
  912. int num_regs;
  913. #ifdef CONFIG_DEV_COREDUMP
  914. struct amdgpu_task_info reset_task_info;
  915. bool reset_vram_lost;
  916. struct timespec64 reset_time;
  917. #endif
  918. bool scpm_enabled;
  919. uint32_t scpm_status;
  920. struct work_struct reset_work;
  921. bool job_hang;
  922. };
  923. static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
  924. {
  925. return container_of(ddev, struct amdgpu_device, ddev);
  926. }
  927. static inline struct drm_device *adev_to_drm(struct amdgpu_device *adev)
  928. {
  929. return &adev->ddev;
  930. }
  931. static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_device *bdev)
  932. {
  933. return container_of(bdev, struct amdgpu_device, mman.bdev);
  934. }
  935. int amdgpu_device_init(struct amdgpu_device *adev,
  936. uint32_t flags);
  937. void amdgpu_device_fini_hw(struct amdgpu_device *adev);
  938. void amdgpu_device_fini_sw(struct amdgpu_device *adev);
  939. int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
  940. void amdgpu_device_mm_access(struct amdgpu_device *adev, loff_t pos,
  941. void *buf, size_t size, bool write);
  942. size_t amdgpu_device_aper_access(struct amdgpu_device *adev, loff_t pos,
  943. void *buf, size_t size, bool write);
  944. void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos,
  945. void *buf, size_t size, bool write);
  946. uint32_t amdgpu_device_rreg(struct amdgpu_device *adev,
  947. uint32_t reg, uint32_t acc_flags);
  948. void amdgpu_device_wreg(struct amdgpu_device *adev,
  949. uint32_t reg, uint32_t v,
  950. uint32_t acc_flags);
  951. void amdgpu_mm_wreg_mmio_rlc(struct amdgpu_device *adev,
  952. uint32_t reg, uint32_t v);
  953. void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
  954. uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
  955. u32 amdgpu_device_indirect_rreg(struct amdgpu_device *adev,
  956. u32 pcie_index, u32 pcie_data,
  957. u32 reg_addr);
  958. u64 amdgpu_device_indirect_rreg64(struct amdgpu_device *adev,
  959. u32 pcie_index, u32 pcie_data,
  960. u32 reg_addr);
  961. void amdgpu_device_indirect_wreg(struct amdgpu_device *adev,
  962. u32 pcie_index, u32 pcie_data,
  963. u32 reg_addr, u32 reg_data);
  964. void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev,
  965. u32 pcie_index, u32 pcie_data,
  966. u32 reg_addr, u64 reg_data);
  967. bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
  968. bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
  969. int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
  970. struct amdgpu_reset_context *reset_context);
  971. int amdgpu_do_asic_reset(struct list_head *device_list_handle,
  972. struct amdgpu_reset_context *reset_context);
  973. int emu_soc_asic_init(struct amdgpu_device *adev);
  974. /*
  975. * Registers read & write functions.
  976. */
  977. #define AMDGPU_REGS_NO_KIQ (1<<1)
  978. #define AMDGPU_REGS_RLC (1<<2)
  979. #define RREG32_NO_KIQ(reg) amdgpu_device_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
  980. #define WREG32_NO_KIQ(reg, v) amdgpu_device_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
  981. #define RREG32_KIQ(reg) amdgpu_kiq_rreg(adev, (reg))
  982. #define WREG32_KIQ(reg, v) amdgpu_kiq_wreg(adev, (reg), (v))
  983. #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
  984. #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
  985. #define RREG32(reg) amdgpu_device_rreg(adev, (reg), 0)
  986. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_device_rreg(adev, (reg), 0))
  987. #define WREG32(reg, v) amdgpu_device_wreg(adev, (reg), (v), 0)
  988. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  989. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  990. #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
  991. #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
  992. #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
  993. #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
  994. #define RREG64_PCIE(reg) adev->pcie_rreg64(adev, (reg))
  995. #define WREG64_PCIE(reg, v) adev->pcie_wreg64(adev, (reg), (v))
  996. #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
  997. #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
  998. #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
  999. #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
  1000. #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
  1001. #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
  1002. #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
  1003. #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
  1004. #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
  1005. #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
  1006. #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
  1007. #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
  1008. #define WREG32_P(reg, val, mask) \
  1009. do { \
  1010. uint32_t tmp_ = RREG32(reg); \
  1011. tmp_ &= (mask); \
  1012. tmp_ |= ((val) & ~(mask)); \
  1013. WREG32(reg, tmp_); \
  1014. } while (0)
  1015. #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
  1016. #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
  1017. #define WREG32_PLL_P(reg, val, mask) \
  1018. do { \
  1019. uint32_t tmp_ = RREG32_PLL(reg); \
  1020. tmp_ &= (mask); \
  1021. tmp_ |= ((val) & ~(mask)); \
  1022. WREG32_PLL(reg, tmp_); \
  1023. } while (0)
  1024. #define WREG32_SMC_P(_Reg, _Val, _Mask) \
  1025. do { \
  1026. u32 tmp = RREG32_SMC(_Reg); \
  1027. tmp &= (_Mask); \
  1028. tmp |= ((_Val) & ~(_Mask)); \
  1029. WREG32_SMC(_Reg, tmp); \
  1030. } while (0)
  1031. #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_device_rreg((adev), (reg), false))
  1032. #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  1033. #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  1034. #define REG_SET_FIELD(orig_val, reg, field, field_val) \
  1035. (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
  1036. (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
  1037. #define REG_GET_FIELD(value, reg, field) \
  1038. (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
  1039. #define WREG32_FIELD(reg, field, val) \
  1040. WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
  1041. #define WREG32_FIELD_OFFSET(reg, offset, field, val) \
  1042. WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
  1043. /*
  1044. * BIOS helpers.
  1045. */
  1046. #define RBIOS8(i) (adev->bios[i])
  1047. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1048. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1049. /*
  1050. * ASICs macro.
  1051. */
  1052. #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
  1053. #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
  1054. #define amdgpu_asic_reset_method(adev) (adev)->asic_funcs->reset_method((adev))
  1055. #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
  1056. #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
  1057. #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
  1058. #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
  1059. #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
  1060. #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
  1061. #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
  1062. #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
  1063. #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
  1064. #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
  1065. #define amdgpu_asic_flush_hdp(adev, r) \
  1066. ((adev)->asic_funcs->flush_hdp ? (adev)->asic_funcs->flush_hdp((adev), (r)) : (adev)->hdp.funcs->flush_hdp((adev), (r)))
  1067. #define amdgpu_asic_invalidate_hdp(adev, r) \
  1068. ((adev)->asic_funcs->invalidate_hdp ? (adev)->asic_funcs->invalidate_hdp((adev), (r)) : \
  1069. ((adev)->hdp.funcs->invalidate_hdp ? (adev)->hdp.funcs->invalidate_hdp((adev), (r)) : 0))
  1070. #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev))
  1071. #define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev))
  1072. #define amdgpu_asic_get_pcie_usage(adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))
  1073. #define amdgpu_asic_need_reset_on_init(adev) (adev)->asic_funcs->need_reset_on_init((adev))
  1074. #define amdgpu_asic_get_pcie_replay_count(adev) ((adev)->asic_funcs->get_pcie_replay_count((adev)))
  1075. #define amdgpu_asic_supports_baco(adev) (adev)->asic_funcs->supports_baco((adev))
  1076. #define amdgpu_asic_pre_asic_init(adev) (adev)->asic_funcs->pre_asic_init((adev))
  1077. #define amdgpu_asic_update_umd_stable_pstate(adev, enter) \
  1078. ((adev)->asic_funcs->update_umd_stable_pstate ? (adev)->asic_funcs->update_umd_stable_pstate((adev), (enter)) : 0)
  1079. #define amdgpu_asic_query_video_codecs(adev, e, c) (adev)->asic_funcs->query_video_codecs((adev), (e), (c))
  1080. #define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter));
  1081. #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
  1082. /* Common functions */
  1083. bool amdgpu_device_has_job_running(struct amdgpu_device *adev);
  1084. bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
  1085. int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  1086. struct amdgpu_job *job,
  1087. struct amdgpu_reset_context *reset_context);
  1088. void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
  1089. int amdgpu_device_pci_reset(struct amdgpu_device *adev);
  1090. bool amdgpu_device_need_post(struct amdgpu_device *adev);
  1091. bool amdgpu_device_pcie_dynamic_switching_supported(void);
  1092. bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev);
  1093. bool amdgpu_device_aspm_support_quirk(void);
  1094. void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
  1095. u64 num_vis_bytes);
  1096. int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
  1097. void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
  1098. const u32 *registers,
  1099. const u32 array_size);
  1100. int amdgpu_device_mode1_reset(struct amdgpu_device *adev);
  1101. bool amdgpu_device_supports_atpx(struct drm_device *dev);
  1102. bool amdgpu_device_supports_px(struct drm_device *dev);
  1103. bool amdgpu_device_supports_boco(struct drm_device *dev);
  1104. bool amdgpu_device_supports_smart_shift(struct drm_device *dev);
  1105. bool amdgpu_device_supports_baco(struct drm_device *dev);
  1106. bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
  1107. struct amdgpu_device *peer_adev);
  1108. int amdgpu_device_baco_enter(struct drm_device *dev);
  1109. int amdgpu_device_baco_exit(struct drm_device *dev);
  1110. void amdgpu_device_flush_hdp(struct amdgpu_device *adev,
  1111. struct amdgpu_ring *ring);
  1112. void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev,
  1113. struct amdgpu_ring *ring);
  1114. void amdgpu_device_halt(struct amdgpu_device *adev);
  1115. u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device *adev,
  1116. u32 reg);
  1117. void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev,
  1118. u32 reg, u32 v);
  1119. struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
  1120. struct dma_fence *gang);
  1121. bool amdgpu_device_has_display_hardware(struct amdgpu_device *adev);
  1122. /* atpx handler */
  1123. #if defined(CONFIG_VGA_SWITCHEROO)
  1124. void amdgpu_register_atpx_handler(void);
  1125. void amdgpu_unregister_atpx_handler(void);
  1126. bool amdgpu_has_atpx_dgpu_power_cntl(void);
  1127. bool amdgpu_is_atpx_hybrid(void);
  1128. bool amdgpu_atpx_dgpu_req_power_for_displays(void);
  1129. bool amdgpu_has_atpx(void);
  1130. #else
  1131. static inline void amdgpu_register_atpx_handler(void) {}
  1132. static inline void amdgpu_unregister_atpx_handler(void) {}
  1133. static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
  1134. static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
  1135. static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
  1136. static inline bool amdgpu_has_atpx(void) { return false; }
  1137. #endif
  1138. #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
  1139. void *amdgpu_atpx_get_dhandle(void);
  1140. #else
  1141. static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
  1142. #endif
  1143. /*
  1144. * KMS
  1145. */
  1146. extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
  1147. extern const int amdgpu_max_kms_ioctl;
  1148. int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags);
  1149. void amdgpu_driver_unload_kms(struct drm_device *dev);
  1150. void amdgpu_driver_lastclose_kms(struct drm_device *dev);
  1151. int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
  1152. void amdgpu_driver_postclose_kms(struct drm_device *dev,
  1153. struct drm_file *file_priv);
  1154. void amdgpu_driver_release_kms(struct drm_device *dev);
  1155. int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
  1156. int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
  1157. int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
  1158. u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc);
  1159. int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
  1160. void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
  1161. int amdgpu_info_ioctl(struct drm_device *dev, void *data,
  1162. struct drm_file *filp);
  1163. /*
  1164. * functions used by amdgpu_encoder.c
  1165. */
  1166. struct amdgpu_afmt_acr {
  1167. u32 clock;
  1168. int n_32khz;
  1169. int cts_32khz;
  1170. int n_44_1khz;
  1171. int cts_44_1khz;
  1172. int n_48khz;
  1173. int cts_48khz;
  1174. };
  1175. struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
  1176. /* amdgpu_acpi.c */
  1177. /* ATCS Device/Driver State */
  1178. #define AMDGPU_ATCS_PSC_DEV_STATE_D0 0
  1179. #define AMDGPU_ATCS_PSC_DEV_STATE_D3_HOT 3
  1180. #define AMDGPU_ATCS_PSC_DRV_STATE_OPR 0
  1181. #define AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR 1
  1182. #if defined(CONFIG_ACPI)
  1183. int amdgpu_acpi_init(struct amdgpu_device *adev);
  1184. void amdgpu_acpi_fini(struct amdgpu_device *adev);
  1185. bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
  1186. bool amdgpu_acpi_is_power_shift_control_supported(void);
  1187. int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
  1188. u8 perf_req, bool advertise);
  1189. int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
  1190. u8 dev_state, bool drv_state);
  1191. int amdgpu_acpi_smart_shift_update(struct drm_device *dev, enum amdgpu_ss ss_state);
  1192. int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
  1193. void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps);
  1194. bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev);
  1195. void amdgpu_acpi_detect(void);
  1196. #else
  1197. static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
  1198. static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
  1199. static inline bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev) { return false; }
  1200. static inline void amdgpu_acpi_detect(void) { }
  1201. static inline bool amdgpu_acpi_is_power_shift_control_supported(void) { return false; }
  1202. static inline int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
  1203. u8 dev_state, bool drv_state) { return 0; }
  1204. static inline int amdgpu_acpi_smart_shift_update(struct drm_device *dev,
  1205. enum amdgpu_ss ss_state) { return 0; }
  1206. #endif
  1207. #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
  1208. bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
  1209. bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
  1210. #else
  1211. static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { return false; }
  1212. static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { return false; }
  1213. #endif
  1214. #if defined(CONFIG_DRM_AMD_DC)
  1215. int amdgpu_dm_display_resume(struct amdgpu_device *adev );
  1216. #else
  1217. static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
  1218. #endif
  1219. void amdgpu_register_gpu_instance(struct amdgpu_device *adev);
  1220. void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev);
  1221. pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev,
  1222. pci_channel_state_t state);
  1223. pci_ers_result_t amdgpu_pci_mmio_enabled(struct pci_dev *pdev);
  1224. pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev);
  1225. void amdgpu_pci_resume(struct pci_dev *pdev);
  1226. bool amdgpu_device_cache_pci_state(struct pci_dev *pdev);
  1227. bool amdgpu_device_load_pci_state(struct pci_dev *pdev);
  1228. bool amdgpu_device_skip_hw_access(struct amdgpu_device *adev);
  1229. int amdgpu_device_set_cg_state(struct amdgpu_device *adev,
  1230. enum amd_clockgating_state state);
  1231. int amdgpu_device_set_pg_state(struct amdgpu_device *adev,
  1232. enum amd_powergating_state state);
  1233. static inline bool amdgpu_device_has_timeouts_enabled(struct amdgpu_device *adev)
  1234. {
  1235. return amdgpu_gpu_recovery != 0 &&
  1236. adev->gfx_timeout != MAX_SCHEDULE_TIMEOUT &&
  1237. adev->compute_timeout != MAX_SCHEDULE_TIMEOUT &&
  1238. adev->sdma_timeout != MAX_SCHEDULE_TIMEOUT &&
  1239. adev->video_timeout != MAX_SCHEDULE_TIMEOUT;
  1240. }
  1241. #include "amdgpu_object.h"
  1242. static inline bool amdgpu_is_tmz(struct amdgpu_device *adev)
  1243. {
  1244. return adev->gmc.tmz_enabled;
  1245. }
  1246. int amdgpu_in_reset(struct amdgpu_device *adev);
  1247. #endif