xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision 1daa2bfa)
197b2e202SAlex Deucher /*
297b2e202SAlex Deucher  * Copyright 2008 Advanced Micro Devices, Inc.
397b2e202SAlex Deucher  * Copyright 2008 Red Hat Inc.
497b2e202SAlex Deucher  * Copyright 2009 Jerome Glisse.
597b2e202SAlex Deucher  *
697b2e202SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
797b2e202SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
897b2e202SAlex Deucher  * to deal in the Software without restriction, including without limitation
997b2e202SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1097b2e202SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
1197b2e202SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
1297b2e202SAlex Deucher  *
1397b2e202SAlex Deucher  * The above copyright notice and this permission notice shall be included in
1497b2e202SAlex Deucher  * all copies or substantial portions of the Software.
1597b2e202SAlex Deucher  *
1697b2e202SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1797b2e202SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1897b2e202SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1997b2e202SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
2097b2e202SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2197b2e202SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2297b2e202SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
2397b2e202SAlex Deucher  *
2497b2e202SAlex Deucher  * Authors: Dave Airlie
2597b2e202SAlex Deucher  *          Alex Deucher
2697b2e202SAlex Deucher  *          Jerome Glisse
2797b2e202SAlex Deucher  */
2897b2e202SAlex Deucher #ifndef __AMDGPU_H__
2997b2e202SAlex Deucher #define __AMDGPU_H__
3097b2e202SAlex Deucher 
318290268fSChristian König #include "amdgpu_ctx.h"
328290268fSChristian König 
3397b2e202SAlex Deucher #include <linux/atomic.h>
3497b2e202SAlex Deucher #include <linux/wait.h>
3597b2e202SAlex Deucher #include <linux/list.h>
3697b2e202SAlex Deucher #include <linux/kref.h>
37a9f87f64SChristian König #include <linux/rbtree.h>
3897b2e202SAlex Deucher #include <linux/hashtable.h>
39f54d1867SChris Wilson #include <linux/dma-fence.h>
4097b2e202SAlex Deucher 
41248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_api.h>
42248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_driver.h>
43248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_placement.h>
44248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_module.h>
45248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_execbuf_util.h>
4697b2e202SAlex Deucher 
477e5a547fSChunming Zhou #include <drm/amdgpu_drm.h>
48f867723bSSam Ravnborg #include <drm/drm_gem.h>
49f867723bSSam Ravnborg #include <drm/drm_ioctl.h>
501b1f42d8SLucas Stach #include <drm/gpu_scheduler.h>
5197b2e202SAlex Deucher 
5278c16834SAndres Rodriguez #include <kgd_kfd_interface.h>
53c79563a3SRex Zhu #include "dm_pp_interface.h"
54c79563a3SRex Zhu #include "kgd_pp_interface.h"
5578c16834SAndres Rodriguez 
565fc3aeebSyanyang1 #include "amd_shared.h"
5797b2e202SAlex Deucher #include "amdgpu_mode.h"
5897b2e202SAlex Deucher #include "amdgpu_ih.h"
5997b2e202SAlex Deucher #include "amdgpu_irq.h"
6097b2e202SAlex Deucher #include "amdgpu_ucode.h"
61c632d799SFlora Cui #include "amdgpu_ttm.h"
620e5ca0d1SHuang Rui #include "amdgpu_psp.h"
6397b2e202SAlex Deucher #include "amdgpu_gds.h"
6456113504SChristian König #include "amdgpu_sync.h"
6578023016SChristian König #include "amdgpu_ring.h"
66073440d2SChristian König #include "amdgpu_vm.h"
67cf097881SAlex Deucher #include "amdgpu_dpm.h"
68a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h"
694df654d2SLeo Liu #include "amdgpu_uvd.h"
705e568178SLeo Liu #include "amdgpu_vce.h"
7195aa13f6SLeo Liu #include "amdgpu_vcn.h"
729a189996SChristian König #include "amdgpu_mn.h"
73770d13b1SChristian König #include "amdgpu_gmc.h"
74448fe192SHuang Rui #include "amdgpu_gfx.h"
75bb7743bcSHuang Rui #include "amdgpu_sdma.h"
764562236bSHarry Wentland #include "amdgpu_dm.h"
77ceeb50edSMonk Liu #include "amdgpu_virt.h"
787946340fSRex Zhu #include "amdgpu_csa.h"
793490bdb5SChristian König #include "amdgpu_gart.h"
8075758255SAlex Deucher #include "amdgpu_debugfs.h"
81050d9d43SChristian König #include "amdgpu_job.h"
824a8c21a1SChristian König #include "amdgpu_bo_list.h"
832cddc50eSHuang Rui #include "amdgpu_gem.h"
84cde577bdSOak Zeng #include "amdgpu_doorbell.h"
85611736d8SFelix Kuehling #include "amdgpu_amdkfd.h"
86137d63abSHuang Rui #include "amdgpu_smu.h"
87f39f5bb1SXiaojie Yuan #include "amdgpu_discovery.h"
88a538bbe7SJack Xiao #include "amdgpu_mes.h"
89c79563a3SRex Zhu 
9062d73fbcSEvan Quan #define MAX_GPU_INSTANCE		16
9162d73fbcSEvan Quan 
9262d73fbcSEvan Quan struct amdgpu_gpu_instance
9362d73fbcSEvan Quan {
9462d73fbcSEvan Quan 	struct amdgpu_device		*adev;
9562d73fbcSEvan Quan 	int				mgpu_fan_enabled;
9662d73fbcSEvan Quan };
9762d73fbcSEvan Quan 
9862d73fbcSEvan Quan struct amdgpu_mgpu_info
9962d73fbcSEvan Quan {
10062d73fbcSEvan Quan 	struct amdgpu_gpu_instance	gpu_ins[MAX_GPU_INSTANCE];
10162d73fbcSEvan Quan 	struct mutex			mutex;
10262d73fbcSEvan Quan 	uint32_t			num_gpu;
10362d73fbcSEvan Quan 	uint32_t			num_dgpu;
10462d73fbcSEvan Quan 	uint32_t			num_apu;
10562d73fbcSEvan Quan };
10662d73fbcSEvan Quan 
10797b2e202SAlex Deucher /*
10897b2e202SAlex Deucher  * Modules parameters.
10997b2e202SAlex Deucher  */
11097b2e202SAlex Deucher extern int amdgpu_modeset;
11197b2e202SAlex Deucher extern int amdgpu_vram_limit;
112218b5dcdSJohn Brooks extern int amdgpu_vis_vram_limit;
11383e74db6SAlex Deucher extern int amdgpu_gart_size;
11436d38372SChristian König extern int amdgpu_gtt_size;
11595844d20SMarek Olšák extern int amdgpu_moverate;
11697b2e202SAlex Deucher extern int amdgpu_benchmarking;
11797b2e202SAlex Deucher extern int amdgpu_testing;
11897b2e202SAlex Deucher extern int amdgpu_audio;
11997b2e202SAlex Deucher extern int amdgpu_disp_priority;
12097b2e202SAlex Deucher extern int amdgpu_hw_i2c;
12197b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
12297b2e202SAlex Deucher extern int amdgpu_msi;
12397b2e202SAlex Deucher extern int amdgpu_dpm;
124e635ee07SHuang Rui extern int amdgpu_fw_load_type;
12597b2e202SAlex Deucher extern int amdgpu_aspm;
12697b2e202SAlex Deucher extern int amdgpu_runtime_pm;
1270b693f0bSRex Zhu extern uint amdgpu_ip_block_mask;
12897b2e202SAlex Deucher extern int amdgpu_bapm;
12997b2e202SAlex Deucher extern int amdgpu_deep_color;
13097b2e202SAlex Deucher extern int amdgpu_vm_size;
13197b2e202SAlex Deucher extern int amdgpu_vm_block_size;
132d07f14beSRoger He extern int amdgpu_vm_fragment_size;
133d9c13156SChristian König extern int amdgpu_vm_fault_stop;
134b495bd3aSChristian König extern int amdgpu_vm_debug;
1359a4b7d4cSHarish Kasiviswanathan extern int amdgpu_vm_update_mode;
1364562236bSHarry Wentland extern int amdgpu_dc;
1371333f723SJammy Zhou extern int amdgpu_sched_jobs;
1384afcb303SJammy Zhou extern int amdgpu_sched_hw_submission;
1390b693f0bSRex Zhu extern uint amdgpu_pcie_gen_cap;
1400b693f0bSRex Zhu extern uint amdgpu_pcie_lane_cap;
1410b693f0bSRex Zhu extern uint amdgpu_cg_mask;
1420b693f0bSRex Zhu extern uint amdgpu_pg_mask;
1430b693f0bSRex Zhu extern uint amdgpu_sdma_phase_quantum;
1446f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu;
1459accf2fdSEmily Deng extern char *amdgpu_virtual_display;
1460b693f0bSRex Zhu extern uint amdgpu_pp_feature_mask;
147bce23e00SAlex Deucher extern int amdgpu_ngg;
148bce23e00SAlex Deucher extern int amdgpu_prim_buf_per_se;
149bce23e00SAlex Deucher extern int amdgpu_pos_buf_per_se;
150bce23e00SAlex Deucher extern int amdgpu_cntl_sb_buf_per_se;
151bce23e00SAlex Deucher extern int amdgpu_param_buf_per_se;
15265781c78SMonk Liu extern int amdgpu_job_hang_limit;
153e8835e0eSHawking Zhang extern int amdgpu_lbpw;
1544a75aefeSAndres Rodriguez extern int amdgpu_compute_multipipe;
155dcebf026SAndrey Grodzovsky extern int amdgpu_gpu_recovery;
156bfca0289SShaoyun Liu extern int amdgpu_emu_mode;
1577951e376SRex Zhu extern uint amdgpu_smu_memory_pool_size;
1587875a226SAlex Deucher extern uint amdgpu_dc_feature_mask;
159ad4de27fSNicholas Kazlauskas extern uint amdgpu_dm_abm_level;
16062d73fbcSEvan Quan extern struct amdgpu_mgpu_info mgpu_info;
1611218252fSxinhui pan extern int amdgpu_ras_enable;
1621218252fSxinhui pan extern uint amdgpu_ras_mask;
16351bcce46SHawking Zhang extern int amdgpu_async_gfx_ring;
164b239c017SJack Xiao extern int amdgpu_mcbp;
165a190d1c7SXiaojie Yuan extern int amdgpu_discovery;
16638487284SJack Xiao extern int amdgpu_mes;
16775ee6487SFelix Kuehling extern int amdgpu_noretry;
16897b2e202SAlex Deucher 
1696dd13096SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_SI
1706dd13096SFelix Kuehling extern int amdgpu_si_support;
1716dd13096SFelix Kuehling #endif
1727df28986SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_CIK
1737df28986SFelix Kuehling extern int amdgpu_cik_support;
1747df28986SFelix Kuehling #endif
17597b2e202SAlex Deucher 
17608d1bdd4SRex Zhu #define AMDGPU_VM_MAX_NUM_CTX			4096
1776c8d74caSSamuel Li #define AMDGPU_SG_THRESHOLD			(256*1024*1024)
17855ed8cafSChunming Zhou #define AMDGPU_DEFAULT_GTT_SIZE_MB		3072ULL /* 3GB by default */
1794b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
18097b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
1818c5e13ecSAndrey Grodzovsky #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
18297b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
18397b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
18497b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
18597b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
186a5bde2f9SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			16
18797b2e202SAlex Deucher 
18897b2e202SAlex Deucher /* hard reset data */
18997b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
19097b2e202SAlex Deucher 
19197b2e202SAlex Deucher /* reset flags */
19297b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
19397b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
19497b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
19597b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
19697b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
19797b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
19897b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
19997b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
20097b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
20197b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
20297b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
20397b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
20497b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
20597b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
20697b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
20797b2e202SAlex Deucher 
20897b2e202SAlex Deucher /* max cursor sizes (in pixels) */
20997b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
21097b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
21197b2e202SAlex Deucher 
21297b2e202SAlex Deucher struct amdgpu_device;
21397b2e202SAlex Deucher struct amdgpu_ib;
21497b2e202SAlex Deucher struct amdgpu_cs_parser;
215bb977d37SChunming Zhou struct amdgpu_job;
21697b2e202SAlex Deucher struct amdgpu_irq_src;
2170b492a4cSAlex Deucher struct amdgpu_fpriv;
2189cca0b8eSChristian König struct amdgpu_bo_va_mapping;
219102c16a0SLyude Paul struct amdgpu_atif;
220992af942SJonathan Kim struct kfd_vm_fault_info;
22197b2e202SAlex Deucher 
22297b2e202SAlex Deucher enum amdgpu_cp_irq {
22353b2fe41SHawking Zhang 	AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP = 0,
22453b2fe41SHawking Zhang 	AMDGPU_CP_IRQ_GFX_ME0_PIPE1_EOP,
22597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
22697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
22797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
22897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
22997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
23097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
23197b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
23297b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
23397b2e202SAlex Deucher 
23497b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
23597b2e202SAlex Deucher };
23697b2e202SAlex Deucher 
23797b2e202SAlex Deucher enum amdgpu_thermal_irq {
23897b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
23997b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
24097b2e202SAlex Deucher 
24197b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
24297b2e202SAlex Deucher };
24397b2e202SAlex Deucher 
2444e638ae9SXiangliang Yu enum amdgpu_kiq_irq {
2454e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
2464e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_LAST
2474e638ae9SXiangliang Yu };
2484e638ae9SXiangliang Yu 
2493890d111SEmily Deng #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
2503890d111SEmily Deng #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
2514944af67Swentalou #define MAX_KIQ_REG_TRY 80 /* 20 -> 80 */
2523890d111SEmily Deng 
25343fa561fSRex Zhu int amdgpu_device_ip_set_clockgating_state(void *dev,
2545fc3aeebSyanyang1 					   enum amd_ip_block_type block_type,
2555fc3aeebSyanyang1 					   enum amd_clockgating_state state);
25643fa561fSRex Zhu int amdgpu_device_ip_set_powergating_state(void *dev,
2575fc3aeebSyanyang1 					   enum amd_ip_block_type block_type,
2585fc3aeebSyanyang1 					   enum amd_powergating_state state);
2592990a1fcSAlex Deucher void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
2602990a1fcSAlex Deucher 					    u32 *flags);
2612990a1fcSAlex Deucher int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
2625dbbb60bSAlex Deucher 				   enum amd_ip_block_type block_type);
2632990a1fcSAlex Deucher bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
2645dbbb60bSAlex Deucher 			      enum amd_ip_block_type block_type);
26597b2e202SAlex Deucher 
266a1255107SAlex Deucher #define AMDGPU_MAX_IP_NUM 16
267a1255107SAlex Deucher 
268a1255107SAlex Deucher struct amdgpu_ip_block_status {
269a1255107SAlex Deucher 	bool valid;
270a1255107SAlex Deucher 	bool sw;
271a1255107SAlex Deucher 	bool hw;
272a1255107SAlex Deucher 	bool late_initialized;
273a1255107SAlex Deucher 	bool hang;
274a1255107SAlex Deucher };
275a1255107SAlex Deucher 
27697b2e202SAlex Deucher struct amdgpu_ip_block_version {
277a1255107SAlex Deucher 	const enum amd_ip_block_type type;
278a1255107SAlex Deucher 	const u32 major;
279a1255107SAlex Deucher 	const u32 minor;
280a1255107SAlex Deucher 	const u32 rev;
2815fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
28297b2e202SAlex Deucher };
28397b2e202SAlex Deucher 
284a1255107SAlex Deucher struct amdgpu_ip_block {
285a1255107SAlex Deucher 	struct amdgpu_ip_block_status status;
286a1255107SAlex Deucher 	const struct amdgpu_ip_block_version *version;
287a1255107SAlex Deucher };
288a1255107SAlex Deucher 
2892990a1fcSAlex Deucher int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
2905fc3aeebSyanyang1 				       enum amd_ip_block_type type,
29197b2e202SAlex Deucher 				       u32 major, u32 minor);
29297b2e202SAlex Deucher 
2932990a1fcSAlex Deucher struct amdgpu_ip_block *
2942990a1fcSAlex Deucher amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
2955fc3aeebSyanyang1 			      enum amd_ip_block_type type);
29697b2e202SAlex Deucher 
2972990a1fcSAlex Deucher int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
298a1255107SAlex Deucher 			       const struct amdgpu_ip_block_version *ip_block_version);
299a1255107SAlex Deucher 
30097b2e202SAlex Deucher /*
30197b2e202SAlex Deucher  * BIOS.
30297b2e202SAlex Deucher  */
30397b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
30497b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
30597b2e202SAlex Deucher 
30697b2e202SAlex Deucher /*
30797b2e202SAlex Deucher  * Clocks
30897b2e202SAlex Deucher  */
30997b2e202SAlex Deucher 
31097b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
31197b2e202SAlex Deucher 
31297b2e202SAlex Deucher struct amdgpu_clock {
31397b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
31497b2e202SAlex Deucher 	struct amdgpu_pll spll;
31597b2e202SAlex Deucher 	struct amdgpu_pll mpll;
31697b2e202SAlex Deucher 	/* 10 Khz units */
31797b2e202SAlex Deucher 	uint32_t default_mclk;
31897b2e202SAlex Deucher 	uint32_t default_sclk;
31997b2e202SAlex Deucher 	uint32_t default_dispclk;
32097b2e202SAlex Deucher 	uint32_t current_dispclk;
32197b2e202SAlex Deucher 	uint32_t dp_extclk;
32297b2e202SAlex Deucher 	uint32_t max_pixel_clock;
32397b2e202SAlex Deucher };
32497b2e202SAlex Deucher 
32597b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
32697b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
32797b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
32897b2e202SAlex Deucher  * locking.
32997b2e202SAlex Deucher  *
33097b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
33197b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
33297b2e202SAlex Deucher  * offset).
33397b2e202SAlex Deucher  *
33497b2e202SAlex Deucher  * When allocating new object we first check if there is room at
33597b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
33697b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
33797b2e202SAlex Deucher  *
33897b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
33997b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
34097b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
34197b2e202SAlex Deucher  *
34297b2e202SAlex Deucher  * Alignment can't be bigger than page size.
34397b2e202SAlex Deucher  *
34497b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
34597b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
34697b2e202SAlex Deucher  * alignment).
34797b2e202SAlex Deucher  */
3486ba60b89SChristian König 
3496ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS	32
3506ba60b89SChristian König 
35197b2e202SAlex Deucher struct amdgpu_sa_manager {
35297b2e202SAlex Deucher 	wait_queue_head_t	wq;
35397b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
35497b2e202SAlex Deucher 	struct list_head	*hole;
3556ba60b89SChristian König 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
35697b2e202SAlex Deucher 	struct list_head	olist;
35797b2e202SAlex Deucher 	unsigned		size;
35897b2e202SAlex Deucher 	uint64_t		gpu_addr;
35997b2e202SAlex Deucher 	void			*cpu_ptr;
36097b2e202SAlex Deucher 	uint32_t		domain;
36197b2e202SAlex Deucher 	uint32_t		align;
36297b2e202SAlex Deucher };
36397b2e202SAlex Deucher 
36497b2e202SAlex Deucher /* sub-allocation buffer */
36597b2e202SAlex Deucher struct amdgpu_sa_bo {
36697b2e202SAlex Deucher 	struct list_head		olist;
36797b2e202SAlex Deucher 	struct list_head		flist;
36897b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
36997b2e202SAlex Deucher 	unsigned			soffset;
37097b2e202SAlex Deucher 	unsigned			eoffset;
371f54d1867SChris Wilson 	struct dma_fence	        *fence;
37297b2e202SAlex Deucher };
37397b2e202SAlex Deucher 
374d573de2dSRex Zhu int amdgpu_fence_slab_init(void);
375d573de2dSRex Zhu void amdgpu_fence_slab_fini(void);
37697b2e202SAlex Deucher 
37797b2e202SAlex Deucher /*
37897b2e202SAlex Deucher  * IRQS.
37997b2e202SAlex Deucher  */
38097b2e202SAlex Deucher 
38197b2e202SAlex Deucher struct amdgpu_flip_work {
382325cbba1SMichel Dänzer 	struct delayed_work		flip_work;
38397b2e202SAlex Deucher 	struct work_struct		unpin_work;
38497b2e202SAlex Deucher 	struct amdgpu_device		*adev;
38597b2e202SAlex Deucher 	int				crtc_id;
386325cbba1SMichel Dänzer 	u32				target_vblank;
38797b2e202SAlex Deucher 	uint64_t			base;
38897b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
389765e7fbfSChristian König 	struct amdgpu_bo		*old_abo;
390f54d1867SChris Wilson 	struct dma_fence		*excl;
3911ffd2652SChristian König 	unsigned			shared_count;
392f54d1867SChris Wilson 	struct dma_fence		**shared;
393f54d1867SChris Wilson 	struct dma_fence_cb		cb;
394cb9e59d7SAlex Deucher 	bool				async;
39597b2e202SAlex Deucher };
39697b2e202SAlex Deucher 
39797b2e202SAlex Deucher 
39897b2e202SAlex Deucher /*
39997b2e202SAlex Deucher  * CP & rings.
40097b2e202SAlex Deucher  */
40197b2e202SAlex Deucher 
40297b2e202SAlex Deucher struct amdgpu_ib {
40397b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
40497b2e202SAlex Deucher 	uint32_t			length_dw;
40597b2e202SAlex Deucher 	uint64_t			gpu_addr;
40697b2e202SAlex Deucher 	uint32_t			*ptr;
407de807f81SJammy Zhou 	uint32_t			flags;
40897b2e202SAlex Deucher };
40997b2e202SAlex Deucher 
4101b1f42d8SLucas Stach extern const struct drm_sched_backend_ops amdgpu_sched_ops;
411c1b69ed0SChunming Zhou 
41297b2e202SAlex Deucher /*
41397b2e202SAlex Deucher  * file private structure
41497b2e202SAlex Deucher  */
41597b2e202SAlex Deucher 
41697b2e202SAlex Deucher struct amdgpu_fpriv {
41797b2e202SAlex Deucher 	struct amdgpu_vm	vm;
418b85891bdSJunwei Zhang 	struct amdgpu_bo_va	*prt_va;
4190f4b3c68SChristian König 	struct amdgpu_bo_va	*csa_va;
42097b2e202SAlex Deucher 	struct mutex		bo_list_lock;
42197b2e202SAlex Deucher 	struct idr		bo_list_handles;
42297b2e202SAlex Deucher 	struct amdgpu_ctx_mgr	ctx_mgr;
42397b2e202SAlex Deucher };
42497b2e202SAlex Deucher 
425021830d2SBas Nieuwenhuizen int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
426912dfc84SEvan Quan int amdgpu_device_get_job_timeout_settings(struct amdgpu_device *adev);
427021830d2SBas Nieuwenhuizen 
428b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
42997b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
4304d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
431f54d1867SChris Wilson 		    struct dma_fence *f);
432b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
43350ddc75eSJunwei Zhang 		       struct amdgpu_ib *ibs, struct amdgpu_job *job,
43450ddc75eSJunwei Zhang 		       struct dma_fence **f);
43597b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
43697b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
43797b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
43897b2e202SAlex Deucher 
43997b2e202SAlex Deucher /*
44097b2e202SAlex Deucher  * CS.
44197b2e202SAlex Deucher  */
44297b2e202SAlex Deucher struct amdgpu_cs_chunk {
44397b2e202SAlex Deucher 	uint32_t		chunk_id;
44497b2e202SAlex Deucher 	uint32_t		length_dw;
445758ac17fSChristian König 	void			*kdata;
44697b2e202SAlex Deucher };
44797b2e202SAlex Deucher 
4482624dd15SChunming Zhou struct amdgpu_cs_post_dep {
4492624dd15SChunming Zhou 	struct drm_syncobj *syncobj;
4502624dd15SChunming Zhou 	struct dma_fence_chain *chain;
4512624dd15SChunming Zhou 	u64 point;
4522624dd15SChunming Zhou };
4532624dd15SChunming Zhou 
45497b2e202SAlex Deucher struct amdgpu_cs_parser {
45597b2e202SAlex Deucher 	struct amdgpu_device	*adev;
45697b2e202SAlex Deucher 	struct drm_file		*filp;
4573cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
458c3cca41eSChristian König 
45997b2e202SAlex Deucher 	/* chunks */
46097b2e202SAlex Deucher 	unsigned		nchunks;
46197b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
462c3cca41eSChristian König 
46350838c8cSChristian König 	/* scheduler job object */
46450838c8cSChristian König 	struct amdgpu_job	*job;
4650d346a14SChristian König 	struct drm_sched_entity	*entity;
466c3cca41eSChristian König 
467c3cca41eSChristian König 	/* buffer objects */
468c3cca41eSChristian König 	struct ww_acquire_ctx		ticket;
469c3cca41eSChristian König 	struct amdgpu_bo_list		*bo_list;
4703fe89771SChristian König 	struct amdgpu_mn		*mn;
47156467ebfSChristian König 	struct amdgpu_bo_list_entry	vm_pd;
47297b2e202SAlex Deucher 	struct list_head		validated;
473f54d1867SChris Wilson 	struct dma_fence		*fence;
474f69f90a1SChristian König 	uint64_t			bytes_moved_threshold;
47500f06b24SJohn Brooks 	uint64_t			bytes_moved_vis_threshold;
476f69f90a1SChristian König 	uint64_t			bytes_moved;
47700f06b24SJohn Brooks 	uint64_t			bytes_moved_vis;
478662bfa61SChristian König 	struct amdgpu_bo_list_entry	*evictable;
47997b2e202SAlex Deucher 
48097b2e202SAlex Deucher 	/* user fence */
48191acbeb6SChristian König 	struct amdgpu_bo_list_entry	uf_entry;
482660e8558SDave Airlie 
4832624dd15SChunming Zhou 	unsigned			num_post_deps;
4842624dd15SChunming Zhou 	struct amdgpu_cs_post_dep	*post_deps;
48597b2e202SAlex Deucher };
48697b2e202SAlex Deucher 
4877270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
4887270f839SChristian König 				      uint32_t ib_idx, int idx)
48997b2e202SAlex Deucher {
49050838c8cSChristian König 	return p->job->ibs[ib_idx].ptr[idx];
49197b2e202SAlex Deucher }
49297b2e202SAlex Deucher 
4937270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
4947270f839SChristian König 				       uint32_t ib_idx, int idx,
4957270f839SChristian König 				       uint32_t value)
4967270f839SChristian König {
49750838c8cSChristian König 	p->job->ibs[ib_idx].ptr[idx] = value;
4987270f839SChristian König }
4997270f839SChristian König 
50097b2e202SAlex Deucher /*
50197b2e202SAlex Deucher  * Writeback
50297b2e202SAlex Deucher  */
50373469585SMonk Liu #define AMDGPU_MAX_WB 128	/* Reserve at most 128 WB slots for amdgpu-owned rings. */
50497b2e202SAlex Deucher 
50597b2e202SAlex Deucher struct amdgpu_wb {
50697b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
50797b2e202SAlex Deucher 	volatile uint32_t	*wb;
50897b2e202SAlex Deucher 	uint64_t		gpu_addr;
50997b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
51097b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
51197b2e202SAlex Deucher };
51297b2e202SAlex Deucher 
513131b4b36SAlex Deucher int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
514131b4b36SAlex Deucher void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
51597b2e202SAlex Deucher 
51697b2e202SAlex Deucher /*
51797b2e202SAlex Deucher  * Benchmarking
51897b2e202SAlex Deucher  */
51997b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
52097b2e202SAlex Deucher 
52197b2e202SAlex Deucher 
52297b2e202SAlex Deucher /*
52397b2e202SAlex Deucher  * Testing
52497b2e202SAlex Deucher  */
52597b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
52697b2e202SAlex Deucher 
52797b2e202SAlex Deucher /*
52897b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
52997b2e202SAlex Deucher  */
53097b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
53197b2e202SAlex Deucher 	uint32_t reg_offset;
53297b2e202SAlex Deucher 	bool grbm_indexed;
53397b2e202SAlex Deucher };
53497b2e202SAlex Deucher 
53597b2e202SAlex Deucher /*
53697b2e202SAlex Deucher  * ASIC specific functions.
53797b2e202SAlex Deucher  */
53897b2e202SAlex Deucher struct amdgpu_asic_funcs {
53997b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
5407946b878SAlex Deucher 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
5417946b878SAlex Deucher 				   u8 *bios, u32 length_bytes);
54297b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
54397b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
54497b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
54597b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
54697b2e202SAlex Deucher 	/* get the reference clock */
54797b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
54897b2e202SAlex Deucher 	/* MM block clocks */
54997b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
55097b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
551841686dfSMaruthi Bayyavarapu 	/* static power management */
552841686dfSMaruthi Bayyavarapu 	int (*get_pcie_lanes)(struct amdgpu_device *adev);
553841686dfSMaruthi Bayyavarapu 	void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
554bbf282d8SAlex Deucher 	/* get config memsize register */
555bbf282d8SAlex Deucher 	u32 (*get_config_memsize)(struct amdgpu_device *adev);
5562df1b8b6SAlex Deucher 	/* flush hdp write queue */
55769882565SChristian König 	void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
5582df1b8b6SAlex Deucher 	/* invalidate hdp read cache */
55969882565SChristian König 	void (*invalidate_hdp)(struct amdgpu_device *adev,
56069882565SChristian König 			       struct amdgpu_ring *ring);
56169070690SAlex Deucher 	/* check if the asic needs a full reset of if soft reset will work */
56269070690SAlex Deucher 	bool (*need_full_reset)(struct amdgpu_device *adev);
5635253163aSOak Zeng 	/* initialize doorbell layout for specific asic*/
5645253163aSOak Zeng 	void (*init_doorbell_index)(struct amdgpu_device *adev);
565b45e18acSKent Russell 	/* PCIe bandwidth usage */
566b45e18acSKent Russell 	void (*get_pcie_usage)(struct amdgpu_device *adev, uint64_t *count0,
567b45e18acSKent Russell 			       uint64_t *count1);
56844401889SAlex Deucher 	/* do we need to reset the asic at init time (e.g., kexec) */
56944401889SAlex Deucher 	bool (*need_reset_on_init)(struct amdgpu_device *adev);
570dcea6e65SKent Russell 	/* PCIe replay counter */
571dcea6e65SKent Russell 	uint64_t (*get_pcie_replay_count)(struct amdgpu_device *adev);
57297b2e202SAlex Deucher };
57397b2e202SAlex Deucher 
57497b2e202SAlex Deucher /*
57597b2e202SAlex Deucher  * IOCTL.
57697b2e202SAlex Deucher  */
57797b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
57897b2e202SAlex Deucher 				struct drm_file *filp);
57997b2e202SAlex Deucher 
58097b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
5817ca24cf2SMarek Olšák int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
5827ca24cf2SMarek Olšák 				    struct drm_file *filp);
58397b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
584eef18a82SJunwei Zhang int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
585eef18a82SJunwei Zhang 				struct drm_file *filp);
58697b2e202SAlex Deucher 
58797b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
58897b2e202SAlex Deucher struct amdgpu_vram_scratch {
58997b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
59097b2e202SAlex Deucher 	volatile uint32_t		*ptr;
59197b2e202SAlex Deucher 	u64				gpu_addr;
59297b2e202SAlex Deucher };
59397b2e202SAlex Deucher 
59497b2e202SAlex Deucher /*
59597b2e202SAlex Deucher  * ACPI
59697b2e202SAlex Deucher  */
59797b2e202SAlex Deucher struct amdgpu_atcs_functions {
59897b2e202SAlex Deucher 	bool get_ext_state;
59997b2e202SAlex Deucher 	bool pcie_perf_req;
60097b2e202SAlex Deucher 	bool pcie_dev_rdy;
60197b2e202SAlex Deucher 	bool pcie_bus_width;
60297b2e202SAlex Deucher };
60397b2e202SAlex Deucher 
60497b2e202SAlex Deucher struct amdgpu_atcs {
60597b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
60697b2e202SAlex Deucher };
60797b2e202SAlex Deucher 
60897b2e202SAlex Deucher /*
609a05502e5SHorace Chen  * Firmware VRAM reservation
610a05502e5SHorace Chen  */
611a05502e5SHorace Chen struct amdgpu_fw_vram_usage {
612a05502e5SHorace Chen 	u64 start_offset;
613a05502e5SHorace Chen 	u64 size;
614a05502e5SHorace Chen 	struct amdgpu_bo *reserved_bo;
615a05502e5SHorace Chen 	void *va;
616a05502e5SHorace Chen };
617a05502e5SHorace Chen 
618a05502e5SHorace Chen /*
619d03846afSChunming Zhou  * CGS
620d03846afSChunming Zhou  */
621110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
622110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
623a8fe58ceSMaruthi Bayyavarapu 
624a8fe58ceSMaruthi Bayyavarapu /*
62597b2e202SAlex Deucher  * Core structure, functions and helpers.
62697b2e202SAlex Deucher  */
62797b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
62897b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
62997b2e202SAlex Deucher 
63097b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
63197b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
63297b2e202SAlex Deucher 
633946a4d5bSShaoyun Liu 
634946a4d5bSShaoyun Liu /*
635946a4d5bSShaoyun Liu  * amdgpu nbio functions
636946a4d5bSShaoyun Liu  *
637946a4d5bSShaoyun Liu  */
638bf383fb6SAlex Deucher struct nbio_hdp_flush_reg {
639bf383fb6SAlex Deucher 	u32 ref_and_mask_cp0;
640bf383fb6SAlex Deucher 	u32 ref_and_mask_cp1;
641bf383fb6SAlex Deucher 	u32 ref_and_mask_cp2;
642bf383fb6SAlex Deucher 	u32 ref_and_mask_cp3;
643bf383fb6SAlex Deucher 	u32 ref_and_mask_cp4;
644bf383fb6SAlex Deucher 	u32 ref_and_mask_cp5;
645bf383fb6SAlex Deucher 	u32 ref_and_mask_cp6;
646bf383fb6SAlex Deucher 	u32 ref_and_mask_cp7;
647bf383fb6SAlex Deucher 	u32 ref_and_mask_cp8;
648bf383fb6SAlex Deucher 	u32 ref_and_mask_cp9;
649bf383fb6SAlex Deucher 	u32 ref_and_mask_sdma0;
650bf383fb6SAlex Deucher 	u32 ref_and_mask_sdma1;
651bf383fb6SAlex Deucher };
652946a4d5bSShaoyun Liu 
65388807dc8SOak Zeng struct amdgpu_mmio_remap {
65488807dc8SOak Zeng 	u32 reg_offset;
65588807dc8SOak Zeng 	resource_size_t bus_addr;
65688807dc8SOak Zeng };
65788807dc8SOak Zeng 
658946a4d5bSShaoyun Liu struct amdgpu_nbio_funcs {
659bf383fb6SAlex Deucher 	const struct nbio_hdp_flush_reg *hdp_flush_reg;
660bf383fb6SAlex Deucher 	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
661bf383fb6SAlex Deucher 	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
662bf383fb6SAlex Deucher 	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
663bf383fb6SAlex Deucher 	u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
664bf383fb6SAlex Deucher 	u32 (*get_rev_id)(struct amdgpu_device *adev);
665bf383fb6SAlex Deucher 	void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
66669882565SChristian König 	void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
667bf383fb6SAlex Deucher 	u32 (*get_memsize)(struct amdgpu_device *adev);
668bf383fb6SAlex Deucher 	void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
6698987e2e2SOak Zeng 			bool use_doorbell, int doorbell_index, int doorbell_size);
670b45ddfe8SLeo Liu 	void (*vcn_doorbell_range)(struct amdgpu_device *adev, bool use_doorbell,
671b45ddfe8SLeo Liu 			int doorbell_index);
672bf383fb6SAlex Deucher 	void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
673bf383fb6SAlex Deucher 					 bool enable);
674bf383fb6SAlex Deucher 	void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
675bf383fb6SAlex Deucher 						  bool enable);
676bf383fb6SAlex Deucher 	void (*ih_doorbell_range)(struct amdgpu_device *adev,
677bf383fb6SAlex Deucher 				  bool use_doorbell, int doorbell_index);
678bf383fb6SAlex Deucher 	void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
679bf383fb6SAlex Deucher 						 bool enable);
680bf383fb6SAlex Deucher 	void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
681bf383fb6SAlex Deucher 						bool enable);
682bf383fb6SAlex Deucher 	void (*get_clockgating_state)(struct amdgpu_device *adev,
683bf383fb6SAlex Deucher 				      u32 *flags);
684bf383fb6SAlex Deucher 	void (*ih_control)(struct amdgpu_device *adev);
685bf383fb6SAlex Deucher 	void (*init_registers)(struct amdgpu_device *adev);
686bf383fb6SAlex Deucher 	void (*detect_hw_virt)(struct amdgpu_device *adev);
68788807dc8SOak Zeng 	void (*remap_hdp_registers)(struct amdgpu_device *adev);
688946a4d5bSShaoyun Liu };
689946a4d5bSShaoyun Liu 
690634c96e3SHawking Zhang struct amdgpu_df_funcs {
691e4cf4bf5SJonathan Kim 	void (*sw_init)(struct amdgpu_device *adev);
692634c96e3SHawking Zhang 	void (*enable_broadcast_mode)(struct amdgpu_device *adev,
693634c96e3SHawking Zhang 				      bool enable);
694634c96e3SHawking Zhang 	u32 (*get_fb_channel_number)(struct amdgpu_device *adev);
695634c96e3SHawking Zhang 	u32 (*get_hbm_channel_number)(struct amdgpu_device *adev);
696634c96e3SHawking Zhang 	void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
697634c96e3SHawking Zhang 						 bool enable);
698634c96e3SHawking Zhang 	void (*get_clockgating_state)(struct amdgpu_device *adev,
699634c96e3SHawking Zhang 				      u32 *flags);
7008f9b2e50SAlex Deucher 	void (*enable_ecc_force_par_wr_rmw)(struct amdgpu_device *adev,
7018f9b2e50SAlex Deucher 					    bool enable);
702992af942SJonathan Kim 	int (*pmc_start)(struct amdgpu_device *adev, uint64_t config,
703992af942SJonathan Kim 					 int is_enable);
704992af942SJonathan Kim 	int (*pmc_stop)(struct amdgpu_device *adev, uint64_t config,
705992af942SJonathan Kim 					 int is_disable);
706992af942SJonathan Kim 	void (*pmc_get_count)(struct amdgpu_device *adev, uint64_t config,
707992af942SJonathan Kim 					 uint64_t *count);
708634c96e3SHawking Zhang };
7094522824cSShaoyun Liu /* Define the HW IP blocks will be used in driver , add more if necessary */
7104522824cSShaoyun Liu enum amd_hw_ip_block_type {
7114522824cSShaoyun Liu 	GC_HWIP = 1,
7124522824cSShaoyun Liu 	HDP_HWIP,
7134522824cSShaoyun Liu 	SDMA0_HWIP,
7144522824cSShaoyun Liu 	SDMA1_HWIP,
7154522824cSShaoyun Liu 	MMHUB_HWIP,
7164522824cSShaoyun Liu 	ATHUB_HWIP,
7174522824cSShaoyun Liu 	NBIO_HWIP,
7184522824cSShaoyun Liu 	MP0_HWIP,
719e6636ae1SEvan Quan 	MP1_HWIP,
7204522824cSShaoyun Liu 	UVD_HWIP,
7214522824cSShaoyun Liu 	VCN_HWIP = UVD_HWIP,
7224522824cSShaoyun Liu 	VCE_HWIP,
7234522824cSShaoyun Liu 	DF_HWIP,
7244522824cSShaoyun Liu 	DCE_HWIP,
7254522824cSShaoyun Liu 	OSSSYS_HWIP,
7264522824cSShaoyun Liu 	SMUIO_HWIP,
7274522824cSShaoyun Liu 	PWR_HWIP,
7284522824cSShaoyun Liu 	NBIF_HWIP,
729e6636ae1SEvan Quan 	THM_HWIP,
73073b19174SRex Zhu 	CLK_HWIP,
7314522824cSShaoyun Liu 	MAX_HWIP
7324522824cSShaoyun Liu };
7334522824cSShaoyun Liu 
734c8ff09bfSXiaojie Yuan #define HWIP_MAX_INSTANCE	7
7354522824cSShaoyun Liu 
73611dc9364SRex Zhu struct amd_powerplay {
73711dc9364SRex Zhu 	void *pp_handle;
73811dc9364SRex Zhu 	const struct amd_pm_funcs *pp_funcs;
73911dc9364SRex Zhu };
74011dc9364SRex Zhu 
7410c49e0b8SChunming Zhou #define AMDGPU_RESET_MAGIC_NUM 64
742e4cf4bf5SJonathan Kim #define AMDGPU_MAX_DF_PERFMONS 4
74397b2e202SAlex Deucher struct amdgpu_device {
74497b2e202SAlex Deucher 	struct device			*dev;
74597b2e202SAlex Deucher 	struct drm_device		*ddev;
74697b2e202SAlex Deucher 	struct pci_dev			*pdev;
74797b2e202SAlex Deucher 
748a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP
749a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_acp		acp;
750a8fe58ceSMaruthi Bayyavarapu #endif
751a8fe58ceSMaruthi Bayyavarapu 
75297b2e202SAlex Deucher 	/* ASIC */
7532f7d10b3SJammy Zhou 	enum amd_asic_type		asic_type;
75497b2e202SAlex Deucher 	uint32_t			family;
75597b2e202SAlex Deucher 	uint32_t			rev_id;
75697b2e202SAlex Deucher 	uint32_t			external_rev_id;
75797b2e202SAlex Deucher 	unsigned long			flags;
75897b2e202SAlex Deucher 	int				usec_timeout;
75997b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
76097b2e202SAlex Deucher 	bool				shutdown;
76197b2e202SAlex Deucher 	bool				need_dma32;
762fd5fd480SChunming Zhou 	bool				need_swiotlb;
76397b2e202SAlex Deucher 	bool				accel_working;
76497b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
76597b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
76697b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
76797b2e202SAlex Deucher 	unsigned			debugfs_count;
76897b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
7696698a3d0SJack Xiao 	struct dentry                   *debugfs_preempt;
770adcec288STom St Denis 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
77197b2e202SAlex Deucher #endif
772102c16a0SLyude Paul 	struct amdgpu_atif		*atif;
77397b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
77497b2e202SAlex Deucher 	struct mutex			srbm_mutex;
77597b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
77697b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
77797b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
77897b2e202SAlex Deucher 	bool				have_disp_power_ref;
779bae17d2aSJack Xiao 	bool                            have_atomics_support;
78097b2e202SAlex Deucher 
78197b2e202SAlex Deucher 	/* BIOS */
7820cdd5005SAlex Deucher 	bool				is_atom_fw;
78397b2e202SAlex Deucher 	uint8_t				*bios;
784a9f5db9cSEvan Quan 	uint32_t			bios_size;
7855af2c10dSKent Russell 	struct amdgpu_bo		*stolen_vga_memory;
786a5bde2f9SAlex Deucher 	uint32_t			bios_scratch_reg_offset;
78797b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
78897b2e202SAlex Deucher 
78997b2e202SAlex Deucher 	/* Register/doorbell mmio */
79097b2e202SAlex Deucher 	resource_size_t			rmmio_base;
79197b2e202SAlex Deucher 	resource_size_t			rmmio_size;
79297b2e202SAlex Deucher 	void __iomem			*rmmio;
79397b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
79497b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
79588807dc8SOak Zeng 	struct amdgpu_mmio_remap        rmmio_remap;
79697b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
79797b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
79897b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
79997b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
80097b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
80197b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
80297b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
80397b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
80436b9a952SHuang Rui 	amdgpu_rreg_t			pciep_rreg;
80536b9a952SHuang Rui 	amdgpu_wreg_t			pciep_wreg;
80697b2e202SAlex Deucher 	/* protects concurrent UVD register access */
80797b2e202SAlex Deucher 	spinlock_t uvd_ctx_idx_lock;
80897b2e202SAlex Deucher 	amdgpu_rreg_t			uvd_ctx_rreg;
80997b2e202SAlex Deucher 	amdgpu_wreg_t			uvd_ctx_wreg;
81097b2e202SAlex Deucher 	/* protects concurrent DIDT register access */
81197b2e202SAlex Deucher 	spinlock_t didt_idx_lock;
81297b2e202SAlex Deucher 	amdgpu_rreg_t			didt_rreg;
81397b2e202SAlex Deucher 	amdgpu_wreg_t			didt_wreg;
814ccdbb20aSRex Zhu 	/* protects concurrent gc_cac register access */
815ccdbb20aSRex Zhu 	spinlock_t gc_cac_idx_lock;
816ccdbb20aSRex Zhu 	amdgpu_rreg_t			gc_cac_rreg;
817ccdbb20aSRex Zhu 	amdgpu_wreg_t			gc_cac_wreg;
81816abb5d2SEvan Quan 	/* protects concurrent se_cac register access */
81916abb5d2SEvan Quan 	spinlock_t se_cac_idx_lock;
82016abb5d2SEvan Quan 	amdgpu_rreg_t			se_cac_rreg;
82116abb5d2SEvan Quan 	amdgpu_wreg_t			se_cac_wreg;
82297b2e202SAlex Deucher 	/* protects concurrent ENDPOINT (audio) register access */
82397b2e202SAlex Deucher 	spinlock_t audio_endpt_idx_lock;
82497b2e202SAlex Deucher 	amdgpu_block_rreg_t		audio_endpt_rreg;
82597b2e202SAlex Deucher 	amdgpu_block_wreg_t		audio_endpt_wreg;
82697b2e202SAlex Deucher 	void __iomem                    *rio_mem;
82797b2e202SAlex Deucher 	resource_size_t			rio_mem_size;
82897b2e202SAlex Deucher 	struct amdgpu_doorbell		doorbell;
82997b2e202SAlex Deucher 
83097b2e202SAlex Deucher 	/* clock/pll info */
83197b2e202SAlex Deucher 	struct amdgpu_clock            clock;
83297b2e202SAlex Deucher 
83397b2e202SAlex Deucher 	/* MC */
834770d13b1SChristian König 	struct amdgpu_gmc		gmc;
83597b2e202SAlex Deucher 	struct amdgpu_gart		gart;
83692e71b06SChristian König 	dma_addr_t			dummy_page_addr;
83797b2e202SAlex Deucher 	struct amdgpu_vm_manager	vm_manager;
838e60f8db5SAlex Xie 	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
8391daa2bfaSLe Ma 	unsigned			num_vmhubs;
84097b2e202SAlex Deucher 
84197b2e202SAlex Deucher 	/* memory management */
84297b2e202SAlex Deucher 	struct amdgpu_mman		mman;
84397b2e202SAlex Deucher 	struct amdgpu_vram_scratch	vram_scratch;
84497b2e202SAlex Deucher 	struct amdgpu_wb		wb;
84597b2e202SAlex Deucher 	atomic64_t			num_bytes_moved;
846dbd5ed60SChristian König 	atomic64_t			num_evictions;
84768e2c5ffSMarek Olšák 	atomic64_t			num_vram_cpu_page_faults;
848d94aed5aSMarek Olšák 	atomic_t			gpu_reset_counter;
849f1892138SChunming Zhou 	atomic_t			vram_lost_counter;
85097b2e202SAlex Deucher 
85195844d20SMarek Olšák 	/* data for buffer migration throttling */
85295844d20SMarek Olšák 	struct {
85395844d20SMarek Olšák 		spinlock_t		lock;
85495844d20SMarek Olšák 		s64			last_update_us;
85595844d20SMarek Olšák 		s64			accum_us; /* accumulated microseconds */
85600f06b24SJohn Brooks 		s64			accum_us_vis; /* for visible VRAM */
85795844d20SMarek Olšák 		u32			log2_max_MBps;
85895844d20SMarek Olšák 	} mm_stats;
85995844d20SMarek Olšák 
86097b2e202SAlex Deucher 	/* display */
8619accf2fdSEmily Deng 	bool				enable_virtual_display;
86297b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
8634562236bSHarry Wentland 	/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
86497b2e202SAlex Deucher 	struct work_struct		hotplug_work;
86597b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
866d2574c33SMario Kleiner 	struct amdgpu_irq_src		vupdate_irq;
86797b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
86897b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
86997b2e202SAlex Deucher 
87097b2e202SAlex Deucher 	/* rings */
87176bf0db5SChristian König 	u64				fence_context;
87297b2e202SAlex Deucher 	unsigned			num_rings;
87397b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
87497b2e202SAlex Deucher 	bool				ib_pool_ready;
87597b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
87697b2e202SAlex Deucher 
87797b2e202SAlex Deucher 	/* interrupts */
87897b2e202SAlex Deucher 	struct amdgpu_irq		irq;
87997b2e202SAlex Deucher 
8801f7371b2SAlex Deucher 	/* powerplay */
8811f7371b2SAlex Deucher 	struct amd_powerplay		powerplay;
882f3898ea1SEric Huang 	bool				pp_force_state_enabled;
8831f7371b2SAlex Deucher 
884137d63abSHuang Rui 	/* smu */
885137d63abSHuang Rui 	struct smu_context		smu;
886137d63abSHuang Rui 
88797b2e202SAlex Deucher 	/* dpm */
88897b2e202SAlex Deucher 	struct amdgpu_pm		pm;
88997b2e202SAlex Deucher 	u32				cg_flags;
89097b2e202SAlex Deucher 	u32				pg_flags;
89197b2e202SAlex Deucher 
89297b2e202SAlex Deucher 	/* gfx */
89397b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
89497b2e202SAlex Deucher 
89597b2e202SAlex Deucher 	/* sdma */
896c113ea1cSAlex Deucher 	struct amdgpu_sdma		sdma;
89797b2e202SAlex Deucher 
89897b2e202SAlex Deucher 	/* uvd */
89997b2e202SAlex Deucher 	struct amdgpu_uvd		uvd;
90097b2e202SAlex Deucher 
90197b2e202SAlex Deucher 	/* vce */
90297b2e202SAlex Deucher 	struct amdgpu_vce		vce;
90395d0906fSLeo Liu 
90495d0906fSLeo Liu 	/* vcn */
90595d0906fSLeo Liu 	struct amdgpu_vcn		vcn;
90697b2e202SAlex Deucher 
90797b2e202SAlex Deucher 	/* firmwares */
90897b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
90997b2e202SAlex Deucher 
9100e5ca0d1SHuang Rui 	/* PSP */
9110e5ca0d1SHuang Rui 	struct psp_context		psp;
9120e5ca0d1SHuang Rui 
91397b2e202SAlex Deucher 	/* GDS */
91497b2e202SAlex Deucher 	struct amdgpu_gds		gds;
91597b2e202SAlex Deucher 
916611736d8SFelix Kuehling 	/* KFD */
917611736d8SFelix Kuehling 	struct amdgpu_kfd_dev		kfd;
918611736d8SFelix Kuehling 
9194562236bSHarry Wentland 	/* display related functionality */
9204562236bSHarry Wentland 	struct amdgpu_display_manager dm;
9214562236bSHarry Wentland 
922f39f5bb1SXiaojie Yuan 	/* discovery */
923f39f5bb1SXiaojie Yuan 	uint8_t				*discovery;
924f39f5bb1SXiaojie Yuan 
925a538bbe7SJack Xiao 	/* mes */
926a538bbe7SJack Xiao 	bool                            enable_mes;
927a538bbe7SJack Xiao 	struct amdgpu_mes               mes;
928a538bbe7SJack Xiao 
929a1255107SAlex Deucher 	struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
93097b2e202SAlex Deucher 	int				num_ip_blocks;
93197b2e202SAlex Deucher 	struct mutex	mn_lock;
93297b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
93397b2e202SAlex Deucher 
93497b2e202SAlex Deucher 	/* tracking pinned memory */
935a5ccfe5cSMichel Dänzer 	atomic64_t vram_pin_size;
936a5ccfe5cSMichel Dänzer 	atomic64_t visible_pin_size;
937a5ccfe5cSMichel Dänzer 	atomic64_t gart_pin_size;
938130e0371SOded Gabbay 
9394522824cSShaoyun Liu 	/* soc15 register offset based on ip, instance and  segment */
9404522824cSShaoyun Liu 	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
9414522824cSShaoyun Liu 
942946a4d5bSShaoyun Liu 	const struct amdgpu_nbio_funcs	*nbio_funcs;
943634c96e3SHawking Zhang 	const struct amdgpu_df_funcs	*df_funcs;
944946a4d5bSShaoyun Liu 
9452dc80b00SShirish S 	/* delayed work_func for deferring clockgating during resume */
946beff74bcSAlex Deucher 	struct delayed_work     delayed_init_work;
9472dc80b00SShirish S 
9485a5099cbSXiangliang Yu 	struct amdgpu_virt	virt;
949a05502e5SHorace Chen 	/* firmware VRAM reservation */
950a05502e5SHorace Chen 	struct amdgpu_fw_vram_usage fw_vram_usage;
9510c4e7fa5SChunming Zhou 
9520c4e7fa5SChunming Zhou 	/* link all shadow bo */
9530c4e7fa5SChunming Zhou 	struct list_head                shadow_list;
9540c4e7fa5SChunming Zhou 	struct mutex                    shadow_list_lock;
955795f2813SAndres Rodriguez 	/* keep an lru list of rings by HW IP */
956795f2813SAndres Rodriguez 	struct list_head		ring_lru_list;
957795f2813SAndres Rodriguez 	spinlock_t			ring_lru_list_lock;
9585c1354bdSChunming Zhou 
959c836fec5SJim Qu 	/* record hw reset is performed */
960c836fec5SJim Qu 	bool has_hw_reset;
9610c49e0b8SChunming Zhou 	u8				reset_magic[AMDGPU_RESET_MAGIC_NUM];
962c836fec5SJim Qu 
96344779b43SRex Zhu 	/* s3/s4 mask */
96444779b43SRex Zhu 	bool                            in_suspend;
96544779b43SRex Zhu 
96647ed4e1cSKen Wang 	/* record last mm index being written through WREG32*/
96747ed4e1cSKen Wang 	unsigned long last_mm_index;
96813a752e3SMonk Liu 	bool                            in_gpu_reset;
96913a752e3SMonk Liu 	struct mutex  lock_reset;
970409c5191SOak Zeng 	struct amdgpu_doorbell_index doorbell_index;
971d4535e2cSAndrey Grodzovsky 
97226bc5340SAndrey Grodzovsky 	int asic_reset_res;
973d4535e2cSAndrey Grodzovsky 	struct work_struct		xgmi_reset_work;
9749b638f97Sshaoyunl 
9750c5ccf14SEvan Quan 	bool                            in_baco_reset;
976912dfc84SEvan Quan 
977912dfc84SEvan Quan 	long				gfx_timeout;
978912dfc84SEvan Quan 	long				sdma_timeout;
979912dfc84SEvan Quan 	long				video_timeout;
980912dfc84SEvan Quan 	long				compute_timeout;
981fb2dbfd2SKent Russell 
982fb2dbfd2SKent Russell 	uint64_t			unique_id;
983e4cf4bf5SJonathan Kim 	uint64_t	df_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS];
98497b2e202SAlex Deucher };
98597b2e202SAlex Deucher 
986a7d64de6SChristian König static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
987a7d64de6SChristian König {
988a7d64de6SChristian König 	return container_of(bdev, struct amdgpu_device, mman.bdev);
989a7d64de6SChristian König }
990a7d64de6SChristian König 
99197b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
99297b2e202SAlex Deucher 		       struct drm_device *ddev,
99397b2e202SAlex Deucher 		       struct pci_dev *pdev,
99497b2e202SAlex Deucher 		       uint32_t flags);
99597b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
99697b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
99797b2e202SAlex Deucher 
99897b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
99915d72fd7SMonk Liu 			uint32_t acc_flags);
100097b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
100115d72fd7SMonk Liu 		    uint32_t acc_flags);
1002421a2a30SMonk Liu void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
1003421a2a30SMonk Liu uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
1004421a2a30SMonk Liu 
100597b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
100697b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
100797b2e202SAlex Deucher 
10084562236bSHarry Wentland bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
10094562236bSHarry Wentland bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
10104562236bSHarry Wentland 
10119475a943SShaoyun Liu int emu_soc_asic_init(struct amdgpu_device *adev);
10129475a943SShaoyun Liu 
101397b2e202SAlex Deucher /*
101497b2e202SAlex Deucher  * Registers read & write functions.
101597b2e202SAlex Deucher  */
101615d72fd7SMonk Liu 
101715d72fd7SMonk Liu #define AMDGPU_REGS_IDX       (1<<0)
101815d72fd7SMonk Liu #define AMDGPU_REGS_NO_KIQ    (1<<1)
101915d72fd7SMonk Liu 
102015d72fd7SMonk Liu #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
102115d72fd7SMonk Liu #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
102215d72fd7SMonk Liu 
1023421a2a30SMonk Liu #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
1024421a2a30SMonk Liu #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
1025421a2a30SMonk Liu 
102615d72fd7SMonk Liu #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
102715d72fd7SMonk Liu #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
102815d72fd7SMonk Liu #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
102915d72fd7SMonk Liu #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
103015d72fd7SMonk Liu #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
103197b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
103297b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
103397b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
103497b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
103536b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
103636b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
103797b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
103897b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
103997b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
104097b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
104197b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
104297b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
1043ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1044ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
104516abb5d2SEvan Quan #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
104616abb5d2SEvan Quan #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
104797b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
104897b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
104997b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
105097b2e202SAlex Deucher 	do {							\
105197b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
105297b2e202SAlex Deucher 		tmp_ &= (mask);					\
105397b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
105497b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
105597b2e202SAlex Deucher 	} while (0)
105697b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
105797b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
105897b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
105997b2e202SAlex Deucher 	do {							\
106097b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
106197b2e202SAlex Deucher 		tmp_ &= (mask);					\
106297b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
106397b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
106497b2e202SAlex Deucher 	} while (0)
106597b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
106697b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
106797b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
106897b2e202SAlex Deucher 
106997b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
107097b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
107197b2e202SAlex Deucher 
107297b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
107397b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
107497b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
107597b2e202SAlex Deucher 
107697b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
107797b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
107897b2e202SAlex Deucher 
107961cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val)	\
108061cb8cefSTom St Denis 	WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
108161cb8cefSTom St Denis 
1082ccaf3574STom St Denis #define WREG32_FIELD_OFFSET(reg, offset, field, val)	\
1083ccaf3574STom St Denis 	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1084ccaf3574STom St Denis 
108597b2e202SAlex Deucher /*
108697b2e202SAlex Deucher  * BIOS helpers.
108797b2e202SAlex Deucher  */
108897b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
108997b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
109097b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
109197b2e202SAlex Deucher 
109297b2e202SAlex Deucher /*
109397b2e202SAlex Deucher  * ASICs macro.
109497b2e202SAlex Deucher  */
109597b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
109697b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
109797b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
109897b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
109997b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1100841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1101841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1102841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
110397b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
11047946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
110597b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1106bbf282d8SAlex Deucher #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
110769882565SChristian König #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r))
110869882565SChristian König #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))
110969070690SAlex Deucher #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev))
11105253163aSOak Zeng #define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev))
1111b45e18acSKent Russell #define amdgpu_asic_get_pcie_usage(adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))
111244401889SAlex Deucher #define amdgpu_asic_need_reset_on_init(adev) (adev)->asic_funcs->need_reset_on_init((adev))
1113dcea6e65SKent Russell #define amdgpu_asic_get_pcie_replay_count(adev) ((adev)->asic_funcs->get_pcie_replay_count((adev)))
111497b2e202SAlex Deucher 
111597b2e202SAlex Deucher /* Common functions */
111612938fadSChristian König bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
11175f152b5eSAlex Deucher int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
111812938fadSChristian König 			      struct amdgpu_job* job);
11198111c387SAlex Deucher void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
112039c640c0SAlex Deucher bool amdgpu_device_need_post(struct amdgpu_device *adev);
1121d5fc5e82SChunming Zhou 
112200f06b24SJohn Brooks void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
112300f06b24SJohn Brooks 				  u64 num_vis_bytes);
1124d6895ad3SChristian König int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
11259c3f2b54SAlex Deucher void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
112697b2e202SAlex Deucher 					     const u32 *registers,
112797b2e202SAlex Deucher 					     const u32 array_size);
112897b2e202SAlex Deucher 
112997b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
1130992af942SJonathan Kim bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
1131992af942SJonathan Kim 				      struct amdgpu_device *peer_adev);
1132992af942SJonathan Kim 
113397b2e202SAlex Deucher /* atpx handler */
113497b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
113597b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
113697b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
1137a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void);
11382f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void);
1139efc83cf4SAlex Deucher bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1140714f88e0SAlex Xie bool amdgpu_has_atpx(void);
114197b2e202SAlex Deucher #else
114297b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
114397b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
1144a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
11452f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
1146efc83cf4SAlex Deucher static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
1147714f88e0SAlex Xie static inline bool amdgpu_has_atpx(void) { return false; }
114897b2e202SAlex Deucher #endif
114997b2e202SAlex Deucher 
115024aeefcdSLyude Paul #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
115124aeefcdSLyude Paul void *amdgpu_atpx_get_dhandle(void);
115224aeefcdSLyude Paul #else
115324aeefcdSLyude Paul static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
115424aeefcdSLyude Paul #endif
115524aeefcdSLyude Paul 
115697b2e202SAlex Deucher /*
115797b2e202SAlex Deucher  * KMS
115897b2e202SAlex Deucher  */
115997b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1160f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl;
116197b2e202SAlex Deucher 
116297b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
116311b3c20bSGabriel Krisman Bertazi void amdgpu_driver_unload_kms(struct drm_device *dev);
116497b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
116597b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
116697b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
116797b2e202SAlex Deucher 				 struct drm_file *file_priv);
1168cdd61df6SAlex Deucher int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
1169810ddc3aSAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1170810ddc3aSAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
117188e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
117288e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
117388e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
117497b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
117597b2e202SAlex Deucher 			     unsigned long arg);
117697b2e202SAlex Deucher 
117797b2e202SAlex Deucher /*
117897b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
117997b2e202SAlex Deucher  */
118097b2e202SAlex Deucher struct amdgpu_afmt_acr {
118197b2e202SAlex Deucher 	u32 clock;
118297b2e202SAlex Deucher 
118397b2e202SAlex Deucher 	int n_32khz;
118497b2e202SAlex Deucher 	int cts_32khz;
118597b2e202SAlex Deucher 
118697b2e202SAlex Deucher 	int n_44_1khz;
118797b2e202SAlex Deucher 	int cts_44_1khz;
118897b2e202SAlex Deucher 
118997b2e202SAlex Deucher 	int n_48khz;
119097b2e202SAlex Deucher 	int cts_48khz;
119197b2e202SAlex Deucher 
119297b2e202SAlex Deucher };
119397b2e202SAlex Deucher 
119497b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
119597b2e202SAlex Deucher 
119697b2e202SAlex Deucher /* amdgpu_acpi.c */
119797b2e202SAlex Deucher #if defined(CONFIG_ACPI)
119897b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
119997b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
120097b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
120197b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
120297b2e202SAlex Deucher 						u8 perf_req, bool advertise);
120397b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
1204206bbafeSDavid Francis 
1205206bbafeSDavid Francis void amdgpu_acpi_get_backlight_caps(struct amdgpu_device *adev,
1206206bbafeSDavid Francis 		struct amdgpu_dm_backlight_caps *caps);
120797b2e202SAlex Deucher #else
120897b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
120997b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
121097b2e202SAlex Deucher #endif
121197b2e202SAlex Deucher 
12129cca0b8eSChristian König int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
12139cca0b8eSChristian König 			   uint64_t addr, struct amdgpu_bo **bo,
12149cca0b8eSChristian König 			   struct amdgpu_bo_va_mapping **mapping);
121597b2e202SAlex Deucher 
12164562236bSHarry Wentland #if defined(CONFIG_DRM_AMD_DC)
12174562236bSHarry Wentland int amdgpu_dm_display_resume(struct amdgpu_device *adev );
12184562236bSHarry Wentland #else
12194562236bSHarry Wentland static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
12204562236bSHarry Wentland #endif
12214562236bSHarry Wentland 
1222fdafb359SEvan Quan 
1223fdafb359SEvan Quan void amdgpu_register_gpu_instance(struct amdgpu_device *adev);
1224fdafb359SEvan Quan void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev);
1225fdafb359SEvan Quan 
122697b2e202SAlex Deucher #include "amdgpu_object.h"
1227e4cf4bf5SJonathan Kim 
1228e4cf4bf5SJonathan Kim /* used by df_v3_6.c and amdgpu_pmu.c */
1229e4cf4bf5SJonathan Kim #define AMDGPU_PMU_ATTR(_name, _object)					\
1230e4cf4bf5SJonathan Kim static ssize_t								\
1231e4cf4bf5SJonathan Kim _name##_show(struct device *dev,					\
1232e4cf4bf5SJonathan Kim 			       struct device_attribute *attr,		\
1233e4cf4bf5SJonathan Kim 			       char *page)				\
1234e4cf4bf5SJonathan Kim {									\
1235e4cf4bf5SJonathan Kim 	BUILD_BUG_ON(sizeof(_object) >= PAGE_SIZE - 1);			\
1236e4cf4bf5SJonathan Kim 	return sprintf(page, _object "\n");				\
1237e4cf4bf5SJonathan Kim }									\
1238e4cf4bf5SJonathan Kim 									\
1239e4cf4bf5SJonathan Kim static struct device_attribute pmu_attr_##_name = __ATTR_RO(_name)
1240e4cf4bf5SJonathan Kim 
124197b2e202SAlex Deucher #endif
1242e4cf4bf5SJonathan Kim 
1243