xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision 041d9d93)
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 
3197b2e202SAlex Deucher #include <linux/atomic.h>
3297b2e202SAlex Deucher #include <linux/wait.h>
3397b2e202SAlex Deucher #include <linux/list.h>
3497b2e202SAlex Deucher #include <linux/kref.h>
35a9f87f64SChristian König #include <linux/rbtree.h>
3697b2e202SAlex Deucher #include <linux/hashtable.h>
37f54d1867SChris Wilson #include <linux/dma-fence.h>
3897b2e202SAlex Deucher 
39248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_api.h>
40248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_driver.h>
41248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_placement.h>
42248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_module.h>
43248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_execbuf_util.h>
4497b2e202SAlex Deucher 
45d03846afSChunming Zhou #include <drm/drmP.h>
4697b2e202SAlex Deucher #include <drm/drm_gem.h>
477e5a547fSChunming Zhou #include <drm/amdgpu_drm.h>
481b1f42d8SLucas Stach #include <drm/gpu_scheduler.h>
4997b2e202SAlex Deucher 
5078c16834SAndres Rodriguez #include <kgd_kfd_interface.h>
51c79563a3SRex Zhu #include "dm_pp_interface.h"
52c79563a3SRex Zhu #include "kgd_pp_interface.h"
5378c16834SAndres Rodriguez 
545fc3aeebSyanyang1 #include "amd_shared.h"
5597b2e202SAlex Deucher #include "amdgpu_mode.h"
5697b2e202SAlex Deucher #include "amdgpu_ih.h"
5797b2e202SAlex Deucher #include "amdgpu_irq.h"
5897b2e202SAlex Deucher #include "amdgpu_ucode.h"
59c632d799SFlora Cui #include "amdgpu_ttm.h"
600e5ca0d1SHuang Rui #include "amdgpu_psp.h"
6197b2e202SAlex Deucher #include "amdgpu_gds.h"
6256113504SChristian König #include "amdgpu_sync.h"
6378023016SChristian König #include "amdgpu_ring.h"
64073440d2SChristian König #include "amdgpu_vm.h"
65cf097881SAlex Deucher #include "amdgpu_dpm.h"
66a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h"
674df654d2SLeo Liu #include "amdgpu_uvd.h"
685e568178SLeo Liu #include "amdgpu_vce.h"
6995aa13f6SLeo Liu #include "amdgpu_vcn.h"
709a189996SChristian König #include "amdgpu_mn.h"
714562236bSHarry Wentland #include "amdgpu_dm.h"
72ceeb50edSMonk Liu #include "amdgpu_virt.h"
733490bdb5SChristian König #include "amdgpu_gart.h"
7475758255SAlex Deucher #include "amdgpu_debugfs.h"
75c79563a3SRex Zhu 
7697b2e202SAlex Deucher /*
7797b2e202SAlex Deucher  * Modules parameters.
7897b2e202SAlex Deucher  */
7997b2e202SAlex Deucher extern int amdgpu_modeset;
8097b2e202SAlex Deucher extern int amdgpu_vram_limit;
81218b5dcdSJohn Brooks extern int amdgpu_vis_vram_limit;
8283e74db6SAlex Deucher extern int amdgpu_gart_size;
8336d38372SChristian König extern int amdgpu_gtt_size;
8495844d20SMarek Olšák extern int amdgpu_moverate;
8597b2e202SAlex Deucher extern int amdgpu_benchmarking;
8697b2e202SAlex Deucher extern int amdgpu_testing;
8797b2e202SAlex Deucher extern int amdgpu_audio;
8897b2e202SAlex Deucher extern int amdgpu_disp_priority;
8997b2e202SAlex Deucher extern int amdgpu_hw_i2c;
9097b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
9197b2e202SAlex Deucher extern int amdgpu_msi;
9297b2e202SAlex Deucher extern int amdgpu_lockup_timeout;
9397b2e202SAlex Deucher extern int amdgpu_dpm;
94e635ee07SHuang Rui extern int amdgpu_fw_load_type;
9597b2e202SAlex Deucher extern int amdgpu_aspm;
9697b2e202SAlex Deucher extern int amdgpu_runtime_pm;
970b693f0bSRex Zhu extern uint amdgpu_ip_block_mask;
9897b2e202SAlex Deucher extern int amdgpu_bapm;
9997b2e202SAlex Deucher extern int amdgpu_deep_color;
10097b2e202SAlex Deucher extern int amdgpu_vm_size;
10197b2e202SAlex Deucher extern int amdgpu_vm_block_size;
102d07f14beSRoger He extern int amdgpu_vm_fragment_size;
103d9c13156SChristian König extern int amdgpu_vm_fault_stop;
104b495bd3aSChristian König extern int amdgpu_vm_debug;
1059a4b7d4cSHarish Kasiviswanathan extern int amdgpu_vm_update_mode;
1064562236bSHarry Wentland extern int amdgpu_dc;
10702e749dcSHarry Wentland extern int amdgpu_dc_log;
1081333f723SJammy Zhou extern int amdgpu_sched_jobs;
1094afcb303SJammy Zhou extern int amdgpu_sched_hw_submission;
1103ca67300SRex Zhu extern int amdgpu_no_evict;
1113ca67300SRex Zhu extern int amdgpu_direct_gma_size;
1120b693f0bSRex Zhu extern uint amdgpu_pcie_gen_cap;
1130b693f0bSRex Zhu extern uint amdgpu_pcie_lane_cap;
1140b693f0bSRex Zhu extern uint amdgpu_cg_mask;
1150b693f0bSRex Zhu extern uint amdgpu_pg_mask;
1160b693f0bSRex Zhu extern uint amdgpu_sdma_phase_quantum;
1176f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu;
1189accf2fdSEmily Deng extern char *amdgpu_virtual_display;
1190b693f0bSRex Zhu extern uint amdgpu_pp_feature_mask;
1206a7f76e7SChristian König extern int amdgpu_vram_page_split;
121bce23e00SAlex Deucher extern int amdgpu_ngg;
122bce23e00SAlex Deucher extern int amdgpu_prim_buf_per_se;
123bce23e00SAlex Deucher extern int amdgpu_pos_buf_per_se;
124bce23e00SAlex Deucher extern int amdgpu_cntl_sb_buf_per_se;
125bce23e00SAlex Deucher extern int amdgpu_param_buf_per_se;
12665781c78SMonk Liu extern int amdgpu_job_hang_limit;
127e8835e0eSHawking Zhang extern int amdgpu_lbpw;
1284a75aefeSAndres Rodriguez extern int amdgpu_compute_multipipe;
129dcebf026SAndrey Grodzovsky extern int amdgpu_gpu_recovery;
13097b2e202SAlex Deucher 
1316dd13096SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_SI
1326dd13096SFelix Kuehling extern int amdgpu_si_support;
1336dd13096SFelix Kuehling #endif
1347df28986SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_CIK
1357df28986SFelix Kuehling extern int amdgpu_cik_support;
1367df28986SFelix Kuehling #endif
13797b2e202SAlex Deucher 
13855ed8cafSChunming Zhou #define AMDGPU_DEFAULT_GTT_SIZE_MB		3072ULL /* 3GB by default */
1394b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
14097b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
14197b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
14297b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
14397b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
14497b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
14597b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
146a5bde2f9SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			16
14797b2e202SAlex Deucher 
14836f523a7SJammy Zhou /* max number of IP instances */
14936f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES		2
15036f523a7SJammy Zhou 
15197b2e202SAlex Deucher /* hard reset data */
15297b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
15397b2e202SAlex Deucher 
15497b2e202SAlex Deucher /* reset flags */
15597b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
15697b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
15797b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
15897b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
15997b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
16097b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
16197b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
16297b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
16397b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
16497b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
16597b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
16697b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
16797b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
16897b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
16997b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
17097b2e202SAlex Deucher 
17197b2e202SAlex Deucher /* GFX current status */
17297b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
17397b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE			0x00000001L
17497b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
17597b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
17697b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
17797b2e202SAlex Deucher 
17897b2e202SAlex Deucher /* max cursor sizes (in pixels) */
17997b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
18097b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
18197b2e202SAlex Deucher 
1825740682eSMonk Liu /* GPU RESET flags */
1835740682eSMonk Liu #define AMDGPU_RESET_INFO_VRAM_LOST  (1 << 0)
1845740682eSMonk Liu #define AMDGPU_RESET_INFO_FULLRESET  (1 << 1)
1855740682eSMonk Liu 
18697b2e202SAlex Deucher struct amdgpu_device;
18797b2e202SAlex Deucher struct amdgpu_ib;
18897b2e202SAlex Deucher struct amdgpu_cs_parser;
189bb977d37SChunming Zhou struct amdgpu_job;
19097b2e202SAlex Deucher struct amdgpu_irq_src;
1910b492a4cSAlex Deucher struct amdgpu_fpriv;
1929cca0b8eSChristian König struct amdgpu_bo_va_mapping;
19397b2e202SAlex Deucher 
19497b2e202SAlex Deucher enum amdgpu_cp_irq {
19597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_GFX_EOP = 0,
19697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
19797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
19897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
19997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
20097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
20197b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
20297b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
20397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
20497b2e202SAlex Deucher 
20597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
20697b2e202SAlex Deucher };
20797b2e202SAlex Deucher 
20897b2e202SAlex Deucher enum amdgpu_sdma_irq {
20997b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
21097b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP1,
21197b2e202SAlex Deucher 
21297b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_LAST
21397b2e202SAlex Deucher };
21497b2e202SAlex Deucher 
21597b2e202SAlex Deucher enum amdgpu_thermal_irq {
21697b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
21797b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
21897b2e202SAlex Deucher 
21997b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
22097b2e202SAlex Deucher };
22197b2e202SAlex Deucher 
2224e638ae9SXiangliang Yu enum amdgpu_kiq_irq {
2234e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
2244e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_LAST
2254e638ae9SXiangliang Yu };
2264e638ae9SXiangliang Yu 
2272990a1fcSAlex Deucher int amdgpu_device_ip_set_clockgating_state(struct amdgpu_device *adev,
2285fc3aeebSyanyang1 					   enum amd_ip_block_type block_type,
2295fc3aeebSyanyang1 					   enum amd_clockgating_state state);
2302990a1fcSAlex Deucher int amdgpu_device_ip_set_powergating_state(struct amdgpu_device *adev,
2315fc3aeebSyanyang1 					   enum amd_ip_block_type block_type,
2325fc3aeebSyanyang1 					   enum amd_powergating_state state);
2332990a1fcSAlex Deucher void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
2342990a1fcSAlex Deucher 					    u32 *flags);
2352990a1fcSAlex Deucher int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
2365dbbb60bSAlex Deucher 				   enum amd_ip_block_type block_type);
2372990a1fcSAlex Deucher bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
2385dbbb60bSAlex Deucher 			      enum amd_ip_block_type block_type);
23997b2e202SAlex Deucher 
240a1255107SAlex Deucher #define AMDGPU_MAX_IP_NUM 16
241a1255107SAlex Deucher 
242a1255107SAlex Deucher struct amdgpu_ip_block_status {
243a1255107SAlex Deucher 	bool valid;
244a1255107SAlex Deucher 	bool sw;
245a1255107SAlex Deucher 	bool hw;
246a1255107SAlex Deucher 	bool late_initialized;
247a1255107SAlex Deucher 	bool hang;
248a1255107SAlex Deucher };
249a1255107SAlex Deucher 
25097b2e202SAlex Deucher struct amdgpu_ip_block_version {
251a1255107SAlex Deucher 	const enum amd_ip_block_type type;
252a1255107SAlex Deucher 	const u32 major;
253a1255107SAlex Deucher 	const u32 minor;
254a1255107SAlex Deucher 	const u32 rev;
2555fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
25697b2e202SAlex Deucher };
25797b2e202SAlex Deucher 
258a1255107SAlex Deucher struct amdgpu_ip_block {
259a1255107SAlex Deucher 	struct amdgpu_ip_block_status status;
260a1255107SAlex Deucher 	const struct amdgpu_ip_block_version *version;
261a1255107SAlex Deucher };
262a1255107SAlex Deucher 
2632990a1fcSAlex Deucher int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
2645fc3aeebSyanyang1 				       enum amd_ip_block_type type,
26597b2e202SAlex Deucher 				       u32 major, u32 minor);
26697b2e202SAlex Deucher 
2672990a1fcSAlex Deucher struct amdgpu_ip_block *
2682990a1fcSAlex Deucher amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
2695fc3aeebSyanyang1 			      enum amd_ip_block_type type);
27097b2e202SAlex Deucher 
2712990a1fcSAlex Deucher int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
272a1255107SAlex Deucher 			       const struct amdgpu_ip_block_version *ip_block_version);
273a1255107SAlex Deucher 
27497b2e202SAlex Deucher /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
27597b2e202SAlex Deucher struct amdgpu_buffer_funcs {
27697b2e202SAlex Deucher 	/* maximum bytes in a single operation */
27797b2e202SAlex Deucher 	uint32_t	copy_max_bytes;
27897b2e202SAlex Deucher 
27997b2e202SAlex Deucher 	/* number of dw to reserve per operation */
28097b2e202SAlex Deucher 	unsigned	copy_num_dw;
28197b2e202SAlex Deucher 
28297b2e202SAlex Deucher 	/* used for buffer migration */
283c7ae72c0SChunming Zhou 	void (*emit_copy_buffer)(struct amdgpu_ib *ib,
28497b2e202SAlex Deucher 				 /* src addr in bytes */
28597b2e202SAlex Deucher 				 uint64_t src_offset,
28697b2e202SAlex Deucher 				 /* dst addr in bytes */
28797b2e202SAlex Deucher 				 uint64_t dst_offset,
28897b2e202SAlex Deucher 				 /* number of byte to transfer */
28997b2e202SAlex Deucher 				 uint32_t byte_count);
29097b2e202SAlex Deucher 
29197b2e202SAlex Deucher 	/* maximum bytes in a single operation */
29297b2e202SAlex Deucher 	uint32_t	fill_max_bytes;
29397b2e202SAlex Deucher 
29497b2e202SAlex Deucher 	/* number of dw to reserve per operation */
29597b2e202SAlex Deucher 	unsigned	fill_num_dw;
29697b2e202SAlex Deucher 
29797b2e202SAlex Deucher 	/* used for buffer clearing */
2986e7a3840SChunming Zhou 	void (*emit_fill_buffer)(struct amdgpu_ib *ib,
29997b2e202SAlex Deucher 				 /* value to write to memory */
30097b2e202SAlex Deucher 				 uint32_t src_data,
30197b2e202SAlex Deucher 				 /* dst addr in bytes */
30297b2e202SAlex Deucher 				 uint64_t dst_offset,
30397b2e202SAlex Deucher 				 /* number of byte to fill */
30497b2e202SAlex Deucher 				 uint32_t byte_count);
30597b2e202SAlex Deucher };
30697b2e202SAlex Deucher 
30797b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */
30897b2e202SAlex Deucher struct amdgpu_vm_pte_funcs {
309e6d92197SYong Zhao 	/* number of dw to reserve per operation */
310e6d92197SYong Zhao 	unsigned	copy_pte_num_dw;
311e6d92197SYong Zhao 
31297b2e202SAlex Deucher 	/* copy pte entries from GART */
31397b2e202SAlex Deucher 	void (*copy_pte)(struct amdgpu_ib *ib,
31497b2e202SAlex Deucher 			 uint64_t pe, uint64_t src,
31597b2e202SAlex Deucher 			 unsigned count);
316e6d92197SYong Zhao 
31797b2e202SAlex Deucher 	/* write pte one entry at a time with addr mapping */
318de9ea7bdSChristian König 	void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
319de9ea7bdSChristian König 			  uint64_t value, unsigned count,
320de9ea7bdSChristian König 			  uint32_t incr);
3217bdc53f9SYong Zhao 
3227bdc53f9SYong Zhao 	/* maximum nums of PTEs/PDEs in a single operation */
3237bdc53f9SYong Zhao 	uint32_t	set_max_nums_pte_pde;
3247bdc53f9SYong Zhao 
3257bdc53f9SYong Zhao 	/* number of dw to reserve per operation */
3267bdc53f9SYong Zhao 	unsigned	set_pte_pde_num_dw;
3277bdc53f9SYong Zhao 
32897b2e202SAlex Deucher 	/* for linear pte/pde updates without addr mapping */
32997b2e202SAlex Deucher 	void (*set_pte_pde)(struct amdgpu_ib *ib,
33097b2e202SAlex Deucher 			    uint64_t pe,
33197b2e202SAlex Deucher 			    uint64_t addr, unsigned count,
3326b777607SChunming Zhou 			    uint32_t incr, uint64_t flags);
33397b2e202SAlex Deucher };
33497b2e202SAlex Deucher 
33597b2e202SAlex Deucher /* provided by the gmc block */
33697b2e202SAlex Deucher struct amdgpu_gart_funcs {
33797b2e202SAlex Deucher 	/* flush the vm tlb via mmio */
33897b2e202SAlex Deucher 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
33997b2e202SAlex Deucher 			      uint32_t vmid);
34097b2e202SAlex Deucher 	/* write pte/pde updates using the cpu */
34197b2e202SAlex Deucher 	int (*set_pte_pde)(struct amdgpu_device *adev,
34297b2e202SAlex Deucher 			   void *cpu_pt_addr, /* cpu addr of page table */
34397b2e202SAlex Deucher 			   uint32_t gpu_page_idx, /* pte/pde to update */
34497b2e202SAlex Deucher 			   uint64_t addr, /* addr to write into pte/pde */
3456b777607SChunming Zhou 			   uint64_t flags); /* access flags */
346284710faSChristian König 	/* enable/disable PRT support */
347284710faSChristian König 	void (*set_prt)(struct amdgpu_device *adev, bool enable);
3485463545bSAlex Xie 	/* set pte flags based per asic */
3495463545bSAlex Xie 	uint64_t (*get_vm_pte_flags)(struct amdgpu_device *adev,
3505463545bSAlex Xie 				     uint32_t flags);
351b1166325SChristian König 	/* get the pde for a given mc addr */
3523de676d8SChristian König 	void (*get_vm_pde)(struct amdgpu_device *adev, int level,
3533de676d8SChristian König 			   u64 *dst, u64 *flags);
35403f89febSChristian König 	uint32_t (*get_invalidate_req)(unsigned int vm_id);
355e60f8db5SAlex Xie };
356e60f8db5SAlex Xie 
35797b2e202SAlex Deucher /* provided by the ih block */
35897b2e202SAlex Deucher struct amdgpu_ih_funcs {
35997b2e202SAlex Deucher 	/* ring read/write ptr handling, called from interrupt context */
36097b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_device *adev);
36100ecd8a2SFelix Kuehling 	bool (*prescreen_iv)(struct amdgpu_device *adev);
36297b2e202SAlex Deucher 	void (*decode_iv)(struct amdgpu_device *adev,
36397b2e202SAlex Deucher 			  struct amdgpu_iv_entry *entry);
36497b2e202SAlex Deucher 	void (*set_rptr)(struct amdgpu_device *adev);
36597b2e202SAlex Deucher };
36697b2e202SAlex Deucher 
36797b2e202SAlex Deucher /*
36897b2e202SAlex Deucher  * BIOS.
36997b2e202SAlex Deucher  */
37097b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
37197b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
37297b2e202SAlex Deucher 
37397b2e202SAlex Deucher /*
37497b2e202SAlex Deucher  * Dummy page
37597b2e202SAlex Deucher  */
37697b2e202SAlex Deucher struct amdgpu_dummy_page {
37797b2e202SAlex Deucher 	struct page	*page;
37897b2e202SAlex Deucher 	dma_addr_t	addr;
37997b2e202SAlex Deucher };
38097b2e202SAlex Deucher 
38197b2e202SAlex Deucher /*
38297b2e202SAlex Deucher  * Clocks
38397b2e202SAlex Deucher  */
38497b2e202SAlex Deucher 
38597b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
38697b2e202SAlex Deucher 
38797b2e202SAlex Deucher struct amdgpu_clock {
38897b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
38997b2e202SAlex Deucher 	struct amdgpu_pll spll;
39097b2e202SAlex Deucher 	struct amdgpu_pll mpll;
39197b2e202SAlex Deucher 	/* 10 Khz units */
39297b2e202SAlex Deucher 	uint32_t default_mclk;
39397b2e202SAlex Deucher 	uint32_t default_sclk;
39497b2e202SAlex Deucher 	uint32_t default_dispclk;
39597b2e202SAlex Deucher 	uint32_t current_dispclk;
39697b2e202SAlex Deucher 	uint32_t dp_extclk;
39797b2e202SAlex Deucher 	uint32_t max_pixel_clock;
39897b2e202SAlex Deucher };
39997b2e202SAlex Deucher 
40097b2e202SAlex Deucher /*
4019124a398SChristian König  * GEM.
40297b2e202SAlex Deucher  */
40397b2e202SAlex Deucher 
4047e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX		0x3
40597b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
40697b2e202SAlex Deucher 
40797b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj);
40897b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj,
40997b2e202SAlex Deucher 				struct drm_file *file_priv);
41097b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj,
41197b2e202SAlex Deucher 				struct drm_file *file_priv);
41297b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
41397b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
4144d9c514dSChristian König struct drm_gem_object *
4154d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
41697b2e202SAlex Deucher 				 struct dma_buf_attachment *attach,
41797b2e202SAlex Deucher 				 struct sg_table *sg);
41897b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
41997b2e202SAlex Deucher 					struct drm_gem_object *gobj,
42097b2e202SAlex Deucher 					int flags);
42197b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
42297b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
42397b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
42497b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
42597b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
426dfced2e4SSamuel Li int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
42797b2e202SAlex Deucher 
42897b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
42997b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
43097b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
43197b2e202SAlex Deucher  * locking.
43297b2e202SAlex Deucher  *
43397b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
43497b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
43597b2e202SAlex Deucher  * offset).
43697b2e202SAlex Deucher  *
43797b2e202SAlex Deucher  * When allocating new object we first check if there is room at
43897b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
43997b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
44097b2e202SAlex Deucher  *
44197b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
44297b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
44397b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
44497b2e202SAlex Deucher  *
44597b2e202SAlex Deucher  * Alignment can't be bigger than page size.
44697b2e202SAlex Deucher  *
44797b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
44897b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
44997b2e202SAlex Deucher  * alignment).
45097b2e202SAlex Deucher  */
4516ba60b89SChristian König 
4526ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS	32
4536ba60b89SChristian König 
45497b2e202SAlex Deucher struct amdgpu_sa_manager {
45597b2e202SAlex Deucher 	wait_queue_head_t	wq;
45697b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
45797b2e202SAlex Deucher 	struct list_head	*hole;
4586ba60b89SChristian König 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
45997b2e202SAlex Deucher 	struct list_head	olist;
46097b2e202SAlex Deucher 	unsigned		size;
46197b2e202SAlex Deucher 	uint64_t		gpu_addr;
46297b2e202SAlex Deucher 	void			*cpu_ptr;
46397b2e202SAlex Deucher 	uint32_t		domain;
46497b2e202SAlex Deucher 	uint32_t		align;
46597b2e202SAlex Deucher };
46697b2e202SAlex Deucher 
46797b2e202SAlex Deucher /* sub-allocation buffer */
46897b2e202SAlex Deucher struct amdgpu_sa_bo {
46997b2e202SAlex Deucher 	struct list_head		olist;
47097b2e202SAlex Deucher 	struct list_head		flist;
47197b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
47297b2e202SAlex Deucher 	unsigned			soffset;
47397b2e202SAlex Deucher 	unsigned			eoffset;
474f54d1867SChris Wilson 	struct dma_fence	        *fence;
47597b2e202SAlex Deucher };
47697b2e202SAlex Deucher 
47797b2e202SAlex Deucher /*
47897b2e202SAlex Deucher  * GEM objects.
47997b2e202SAlex Deucher  */
480418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev);
48197b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
48297b2e202SAlex Deucher 			     int alignment, u32 initial_domain,
48397b2e202SAlex Deucher 			     u64 flags, bool kernel,
484e1eb899bSChristian König 			     struct reservation_object *resv,
48597b2e202SAlex Deucher 			     struct drm_gem_object **obj);
48697b2e202SAlex Deucher 
48797b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv,
48897b2e202SAlex Deucher 			    struct drm_device *dev,
48997b2e202SAlex Deucher 			    struct drm_mode_create_dumb *args);
49097b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp,
49197b2e202SAlex Deucher 			  struct drm_device *dev,
49297b2e202SAlex Deucher 			  uint32_t handle, uint64_t *offset_p);
493d573de2dSRex Zhu int amdgpu_fence_slab_init(void);
494d573de2dSRex Zhu void amdgpu_fence_slab_fini(void);
49597b2e202SAlex Deucher 
49697b2e202SAlex Deucher /*
497e60f8db5SAlex Xie  * VMHUB structures, functions & helpers
498e60f8db5SAlex Xie  */
499e60f8db5SAlex Xie struct amdgpu_vmhub {
500e60f8db5SAlex Xie 	uint32_t	ctx0_ptb_addr_lo32;
501e60f8db5SAlex Xie 	uint32_t	ctx0_ptb_addr_hi32;
502e60f8db5SAlex Xie 	uint32_t	vm_inv_eng0_req;
503e60f8db5SAlex Xie 	uint32_t	vm_inv_eng0_ack;
504e60f8db5SAlex Xie 	uint32_t	vm_context0_cntl;
505e60f8db5SAlex Xie 	uint32_t	vm_l2_pro_fault_status;
506e60f8db5SAlex Xie 	uint32_t	vm_l2_pro_fault_cntl;
507e60f8db5SAlex Xie };
508e60f8db5SAlex Xie 
509e60f8db5SAlex Xie /*
51097b2e202SAlex Deucher  * GPU MC structures, functions & helpers
51197b2e202SAlex Deucher  */
51297b2e202SAlex Deucher struct amdgpu_mc {
51397b2e202SAlex Deucher 	resource_size_t		aper_size;
51497b2e202SAlex Deucher 	resource_size_t		aper_base;
51597b2e202SAlex Deucher 	resource_size_t		agp_base;
51697b2e202SAlex Deucher 	/* for some chips with <= 32MB we need to lie
51797b2e202SAlex Deucher 	 * about vram size near mc fb location */
51897b2e202SAlex Deucher 	u64			mc_vram_size;
51997b2e202SAlex Deucher 	u64			visible_vram_size;
5206f02a696SChristian König 	u64			gart_size;
5216f02a696SChristian König 	u64			gart_start;
5226f02a696SChristian König 	u64			gart_end;
52397b2e202SAlex Deucher 	u64			vram_start;
52497b2e202SAlex Deucher 	u64			vram_end;
52597b2e202SAlex Deucher 	unsigned		vram_width;
52697b2e202SAlex Deucher 	u64			real_vram_size;
52797b2e202SAlex Deucher 	int			vram_mtrr;
52897b2e202SAlex Deucher 	u64                     mc_mask;
52997b2e202SAlex Deucher 	const struct firmware   *fw;	/* MC firmware */
53097b2e202SAlex Deucher 	uint32_t                fw_version;
53197b2e202SAlex Deucher 	struct amdgpu_irq_src	vm_fault;
53281c59f54SKen Wang 	uint32_t		vram_type;
53350b0197aSChunming Zhou 	uint32_t                srbm_soft_reset;
534f7c35abeSChristian König 	bool			prt_warning;
535916910adSHuang Rui 	uint64_t		stolen_size;
5368fe73328SJunwei Zhang 	/* apertures */
5378fe73328SJunwei Zhang 	u64					shared_aperture_start;
5388fe73328SJunwei Zhang 	u64					shared_aperture_end;
5398fe73328SJunwei Zhang 	u64					private_aperture_start;
5408fe73328SJunwei Zhang 	u64					private_aperture_end;
541e60f8db5SAlex Xie 	/* protects concurrent invalidation */
542e60f8db5SAlex Xie 	spinlock_t		invalidate_lock;
54397b2e202SAlex Deucher };
54497b2e202SAlex Deucher 
54597b2e202SAlex Deucher /*
54697b2e202SAlex Deucher  * GPU doorbell structures, functions & helpers
54797b2e202SAlex Deucher  */
54897b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
54997b2e202SAlex Deucher {
55097b2e202SAlex Deucher 	AMDGPU_DOORBELL_KIQ                     = 0x000,
55197b2e202SAlex Deucher 	AMDGPU_DOORBELL_HIQ                     = 0x001,
55297b2e202SAlex Deucher 	AMDGPU_DOORBELL_DIQ                     = 0x002,
55397b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
55497b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
55597b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
55697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
55797b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
55897b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
55997b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
56097b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
56197b2e202SAlex Deucher 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
56297b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
56397b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
56497b2e202SAlex Deucher 	AMDGPU_DOORBELL_IH                      = 0x1E8,
56597b2e202SAlex Deucher 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
56697b2e202SAlex Deucher 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
56797b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT;
56897b2e202SAlex Deucher 
56997b2e202SAlex Deucher struct amdgpu_doorbell {
57097b2e202SAlex Deucher 	/* doorbell mmio */
57197b2e202SAlex Deucher 	resource_size_t		base;
57297b2e202SAlex Deucher 	resource_size_t		size;
57397b2e202SAlex Deucher 	u32 __iomem		*ptr;
57497b2e202SAlex Deucher 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
57597b2e202SAlex Deucher };
57697b2e202SAlex Deucher 
57739807b93SKen Wang /*
57839807b93SKen Wang  * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
57939807b93SKen Wang  */
58039807b93SKen Wang typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
58139807b93SKen Wang {
58239807b93SKen Wang 	/*
58339807b93SKen Wang 	 * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
58439807b93SKen Wang 	 * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
58539807b93SKen Wang 	 *  Compute related doorbells are allocated from 0x00 to 0x8a
58639807b93SKen Wang 	 */
58739807b93SKen Wang 
58839807b93SKen Wang 
58939807b93SKen Wang 	/* kernel scheduling */
59039807b93SKen Wang 	AMDGPU_DOORBELL64_KIQ                     = 0x00,
59139807b93SKen Wang 
59239807b93SKen Wang 	/* HSA interface queue and debug queue */
59339807b93SKen Wang 	AMDGPU_DOORBELL64_HIQ                     = 0x01,
59439807b93SKen Wang 	AMDGPU_DOORBELL64_DIQ                     = 0x02,
59539807b93SKen Wang 
59639807b93SKen Wang 	/* Compute engines */
59739807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING0               = 0x03,
59839807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING1               = 0x04,
59939807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING2               = 0x05,
60039807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING3               = 0x06,
60139807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING4               = 0x07,
60239807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING5               = 0x08,
60339807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING6               = 0x09,
60439807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING7               = 0x0a,
60539807b93SKen Wang 
60639807b93SKen Wang 	/* User queue doorbell range (128 doorbells) */
60739807b93SKen Wang 	AMDGPU_DOORBELL64_USERQUEUE_START         = 0x0b,
60839807b93SKen Wang 	AMDGPU_DOORBELL64_USERQUEUE_END           = 0x8a,
60939807b93SKen Wang 
61039807b93SKen Wang 	/* Graphics engine */
61139807b93SKen Wang 	AMDGPU_DOORBELL64_GFX_RING0               = 0x8b,
61239807b93SKen Wang 
61339807b93SKen Wang 	/*
61439807b93SKen Wang 	 * Other graphics doorbells can be allocated here: from 0x8c to 0xef
61539807b93SKen Wang 	 * Graphics voltage island aperture 1
61639807b93SKen Wang 	 * default non-graphics QWORD index is 0xF0 - 0xFF inclusive
61739807b93SKen Wang 	 */
61839807b93SKen Wang 
61939807b93SKen Wang 	/* sDMA engines */
62039807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_ENGINE0            = 0xF0,
62139807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0     = 0xF1,
62239807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_ENGINE1            = 0xF2,
62339807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1     = 0xF3,
62439807b93SKen Wang 
62539807b93SKen Wang 	/* Interrupt handler */
62639807b93SKen Wang 	AMDGPU_DOORBELL64_IH                      = 0xF4,  /* For legacy interrupt ring buffer */
62739807b93SKen Wang 	AMDGPU_DOORBELL64_IH_RING1                = 0xF5,  /* For page migration request log */
62839807b93SKen Wang 	AMDGPU_DOORBELL64_IH_RING2                = 0xF6,  /* For page migration translation/invalidation log */
62939807b93SKen Wang 
630e6b3ecb4SMonk Liu 	/* VCN engine use 32 bits doorbell  */
631e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN0_1                  = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
632e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN2_3                  = 0xF9,
633e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN4_5                  = 0xFA,
634e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN6_7                  = 0xFB,
635e6b3ecb4SMonk Liu 
636e6b3ecb4SMonk Liu 	/* overlap the doorbell assignment with VCN as they are  mutually exclusive
637e6b3ecb4SMonk Liu 	 * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
638e6b3ecb4SMonk Liu 	 */
6394ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING0_1             = 0xF8,
6404ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING2_3             = 0xF9,
6414ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING4_5             = 0xFA,
6424ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING6_7             = 0xFB,
643e6b3ecb4SMonk Liu 
6444ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING0_1             = 0xFC,
6454ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING2_3             = 0xFD,
6464ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING4_5             = 0xFE,
6474ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING6_7             = 0xFF,
64839807b93SKen Wang 
64939807b93SKen Wang 	AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
65039807b93SKen Wang 	AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
65139807b93SKen Wang } AMDGPU_DOORBELL64_ASSIGNMENT;
65239807b93SKen Wang 
65397b2e202SAlex Deucher /*
65497b2e202SAlex Deucher  * IRQS.
65597b2e202SAlex Deucher  */
65697b2e202SAlex Deucher 
65797b2e202SAlex Deucher struct amdgpu_flip_work {
658325cbba1SMichel Dänzer 	struct delayed_work		flip_work;
65997b2e202SAlex Deucher 	struct work_struct		unpin_work;
66097b2e202SAlex Deucher 	struct amdgpu_device		*adev;
66197b2e202SAlex Deucher 	int				crtc_id;
662325cbba1SMichel Dänzer 	u32				target_vblank;
66397b2e202SAlex Deucher 	uint64_t			base;
66497b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
665765e7fbfSChristian König 	struct amdgpu_bo		*old_abo;
666f54d1867SChris Wilson 	struct dma_fence		*excl;
6671ffd2652SChristian König 	unsigned			shared_count;
668f54d1867SChris Wilson 	struct dma_fence		**shared;
669f54d1867SChris Wilson 	struct dma_fence_cb		cb;
670cb9e59d7SAlex Deucher 	bool				async;
67197b2e202SAlex Deucher };
67297b2e202SAlex Deucher 
67397b2e202SAlex Deucher 
67497b2e202SAlex Deucher /*
67597b2e202SAlex Deucher  * CP & rings.
67697b2e202SAlex Deucher  */
67797b2e202SAlex Deucher 
67897b2e202SAlex Deucher struct amdgpu_ib {
67997b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
68097b2e202SAlex Deucher 	uint32_t			length_dw;
68197b2e202SAlex Deucher 	uint64_t			gpu_addr;
68297b2e202SAlex Deucher 	uint32_t			*ptr;
683de807f81SJammy Zhou 	uint32_t			flags;
68497b2e202SAlex Deucher };
68597b2e202SAlex Deucher 
6861b1f42d8SLucas Stach extern const struct drm_sched_backend_ops amdgpu_sched_ops;
687c1b69ed0SChunming Zhou 
68850838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
689c5637837SMonk Liu 		     struct amdgpu_job **job, struct amdgpu_vm *vm);
690d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
691d71518b5SChristian König 			     struct amdgpu_job **job);
692b6723c8dSMonk Liu 
693a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job);
69450838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job);
695d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
6961b1f42d8SLucas Stach 		      struct drm_sched_entity *entity, void *owner,
697f54d1867SChris Wilson 		      struct dma_fence **f);
6988b4fb00bSChristian König 
69997b2e202SAlex Deucher /*
700effd924dSAndres Rodriguez  * Queue manager
701effd924dSAndres Rodriguez  */
702effd924dSAndres Rodriguez struct amdgpu_queue_mapper {
703effd924dSAndres Rodriguez 	int 		hw_ip;
704effd924dSAndres Rodriguez 	struct mutex	lock;
705effd924dSAndres Rodriguez 	/* protected by lock */
706effd924dSAndres Rodriguez 	struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
707effd924dSAndres Rodriguez };
708effd924dSAndres Rodriguez 
709effd924dSAndres Rodriguez struct amdgpu_queue_mgr {
710effd924dSAndres Rodriguez 	struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
711effd924dSAndres Rodriguez };
712effd924dSAndres Rodriguez 
713effd924dSAndres Rodriguez int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
714effd924dSAndres Rodriguez 			  struct amdgpu_queue_mgr *mgr);
715effd924dSAndres Rodriguez int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
716effd924dSAndres Rodriguez 			  struct amdgpu_queue_mgr *mgr);
717effd924dSAndres Rodriguez int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
718effd924dSAndres Rodriguez 			 struct amdgpu_queue_mgr *mgr,
719fa7c7939SMichel Dänzer 			 u32 hw_ip, u32 instance, u32 ring,
720effd924dSAndres Rodriguez 			 struct amdgpu_ring **out_ring);
721effd924dSAndres Rodriguez 
722effd924dSAndres Rodriguez /*
72397b2e202SAlex Deucher  * context related structures
72497b2e202SAlex Deucher  */
72597b2e202SAlex Deucher 
72621c16bf6SChristian König struct amdgpu_ctx_ring {
72721c16bf6SChristian König 	uint64_t		sequence;
728f54d1867SChris Wilson 	struct dma_fence	**fences;
7291b1f42d8SLucas Stach 	struct drm_sched_entity	entity;
73021c16bf6SChristian König };
73121c16bf6SChristian König 
73297b2e202SAlex Deucher struct amdgpu_ctx {
73397b2e202SAlex Deucher 	struct kref		refcount;
7349cb7e5a9SChunming Zhou 	struct amdgpu_device    *adev;
735effd924dSAndres Rodriguez 	struct amdgpu_queue_mgr queue_mgr;
736d94aed5aSMarek Olšák 	unsigned		reset_counter;
737668ca1b4SMonk Liu 	unsigned        reset_counter_query;
738e55f2b64SChristian König 	uint32_t		vram_lost_counter;
73921c16bf6SChristian König 	spinlock_t		ring_lock;
740f54d1867SChris Wilson 	struct dma_fence	**fences;
74121c16bf6SChristian König 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
742753ad49cSMonk Liu 	bool			preamble_presented;
7431b1f42d8SLucas Stach 	enum drm_sched_priority init_priority;
7441b1f42d8SLucas Stach 	enum drm_sched_priority override_priority;
7450ae94444SAndrey Grodzovsky 	struct mutex            lock;
7461102900dSMonk Liu 	atomic_t	guilty;
74797b2e202SAlex Deucher };
74897b2e202SAlex Deucher 
74997b2e202SAlex Deucher struct amdgpu_ctx_mgr {
75097b2e202SAlex Deucher 	struct amdgpu_device	*adev;
7510147ee0fSMarek Olšák 	struct mutex		lock;
7520b492a4cSAlex Deucher 	/* protected by lock */
7530b492a4cSAlex Deucher 	struct idr		ctx_handles;
75497b2e202SAlex Deucher };
75597b2e202SAlex Deucher 
7560b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
7570b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
7580b492a4cSAlex Deucher 
759eb01abc7SMonk Liu int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
760eb01abc7SMonk Liu 			      struct dma_fence *fence, uint64_t *seq);
761f54d1867SChris Wilson struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
76221c16bf6SChristian König 				   struct amdgpu_ring *ring, uint64_t seq);
763c23be4aeSAndres Rodriguez void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
7641b1f42d8SLucas Stach 				  enum drm_sched_priority priority);
76521c16bf6SChristian König 
7660b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
7670b492a4cSAlex Deucher 		     struct drm_file *filp);
7680b492a4cSAlex Deucher 
7690ae94444SAndrey Grodzovsky int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id);
7700ae94444SAndrey Grodzovsky 
771efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
772efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
7730b492a4cSAlex Deucher 
7740ae94444SAndrey Grodzovsky 
77597b2e202SAlex Deucher /*
77697b2e202SAlex Deucher  * file private structure
77797b2e202SAlex Deucher  */
77897b2e202SAlex Deucher 
77997b2e202SAlex Deucher struct amdgpu_fpriv {
78097b2e202SAlex Deucher 	struct amdgpu_vm	vm;
781b85891bdSJunwei Zhang 	struct amdgpu_bo_va	*prt_va;
7820f4b3c68SChristian König 	struct amdgpu_bo_va	*csa_va;
78397b2e202SAlex Deucher 	struct mutex		bo_list_lock;
78497b2e202SAlex Deucher 	struct idr		bo_list_handles;
78597b2e202SAlex Deucher 	struct amdgpu_ctx_mgr	ctx_mgr;
78697b2e202SAlex Deucher };
78797b2e202SAlex Deucher 
78897b2e202SAlex Deucher /*
78997b2e202SAlex Deucher  * residency list
79097b2e202SAlex Deucher  */
7919124a398SChristian König struct amdgpu_bo_list_entry {
7929124a398SChristian König 	struct amdgpu_bo		*robj;
7939124a398SChristian König 	struct ttm_validate_buffer	tv;
7949124a398SChristian König 	struct amdgpu_bo_va		*bo_va;
7959124a398SChristian König 	uint32_t			priority;
7969124a398SChristian König 	struct page			**user_pages;
7979124a398SChristian König 	int				user_invalidated;
7989124a398SChristian König };
79997b2e202SAlex Deucher 
80097b2e202SAlex Deucher struct amdgpu_bo_list {
80197b2e202SAlex Deucher 	struct mutex lock;
8025ac55629SAlex Xie 	struct rcu_head rhead;
8035ac55629SAlex Xie 	struct kref refcount;
80497b2e202SAlex Deucher 	struct amdgpu_bo *gds_obj;
80597b2e202SAlex Deucher 	struct amdgpu_bo *gws_obj;
80697b2e202SAlex Deucher 	struct amdgpu_bo *oa_obj;
807211dff55SChristian König 	unsigned first_userptr;
80897b2e202SAlex Deucher 	unsigned num_entries;
80997b2e202SAlex Deucher 	struct amdgpu_bo_list_entry *array;
81097b2e202SAlex Deucher };
81197b2e202SAlex Deucher 
81297b2e202SAlex Deucher struct amdgpu_bo_list *
81397b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
814636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
815636ce25cSChristian König 			     struct list_head *validated);
81697b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
81797b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
81897b2e202SAlex Deucher 
81997b2e202SAlex Deucher /*
82097b2e202SAlex Deucher  * GFX stuff
82197b2e202SAlex Deucher  */
82297b2e202SAlex Deucher #include "clearstate_defs.h"
82397b2e202SAlex Deucher 
82479e5412cSAlex Deucher struct amdgpu_rlc_funcs {
82579e5412cSAlex Deucher 	void (*enter_safe_mode)(struct amdgpu_device *adev);
82679e5412cSAlex Deucher 	void (*exit_safe_mode)(struct amdgpu_device *adev);
82779e5412cSAlex Deucher };
82879e5412cSAlex Deucher 
82997b2e202SAlex Deucher struct amdgpu_rlc {
83097b2e202SAlex Deucher 	/* for power gating */
83197b2e202SAlex Deucher 	struct amdgpu_bo	*save_restore_obj;
83297b2e202SAlex Deucher 	uint64_t		save_restore_gpu_addr;
83397b2e202SAlex Deucher 	volatile uint32_t	*sr_ptr;
83497b2e202SAlex Deucher 	const u32               *reg_list;
83597b2e202SAlex Deucher 	u32                     reg_list_size;
83697b2e202SAlex Deucher 	/* for clear state */
83797b2e202SAlex Deucher 	struct amdgpu_bo	*clear_state_obj;
83897b2e202SAlex Deucher 	uint64_t		clear_state_gpu_addr;
83997b2e202SAlex Deucher 	volatile uint32_t	*cs_ptr;
84097b2e202SAlex Deucher 	const struct cs_section_def   *cs_data;
84197b2e202SAlex Deucher 	u32                     clear_state_size;
84297b2e202SAlex Deucher 	/* for cp tables */
84397b2e202SAlex Deucher 	struct amdgpu_bo	*cp_table_obj;
84497b2e202SAlex Deucher 	uint64_t		cp_table_gpu_addr;
84597b2e202SAlex Deucher 	volatile uint32_t	*cp_table_ptr;
84697b2e202SAlex Deucher 	u32                     cp_table_size;
84779e5412cSAlex Deucher 
84879e5412cSAlex Deucher 	/* safe mode for updating CG/PG state */
84979e5412cSAlex Deucher 	bool in_safe_mode;
85079e5412cSAlex Deucher 	const struct amdgpu_rlc_funcs *funcs;
8512b6cd977SEric Huang 
8522b6cd977SEric Huang 	/* for firmware data */
8532b6cd977SEric Huang 	u32 save_and_restore_offset;
8542b6cd977SEric Huang 	u32 clear_state_descriptor_offset;
8552b6cd977SEric Huang 	u32 avail_scratch_ram_locations;
8562b6cd977SEric Huang 	u32 reg_restore_list_size;
8572b6cd977SEric Huang 	u32 reg_list_format_start;
8582b6cd977SEric Huang 	u32 reg_list_format_separate_start;
8592b6cd977SEric Huang 	u32 starting_offsets_start;
8602b6cd977SEric Huang 	u32 reg_list_format_size_bytes;
8612b6cd977SEric Huang 	u32 reg_list_size_bytes;
8622b6cd977SEric Huang 
8632b6cd977SEric Huang 	u32 *register_list_format;
8642b6cd977SEric Huang 	u32 *register_restore;
86597b2e202SAlex Deucher };
86697b2e202SAlex Deucher 
86778c16834SAndres Rodriguez #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
86878c16834SAndres Rodriguez 
86997b2e202SAlex Deucher struct amdgpu_mec {
87097b2e202SAlex Deucher 	struct amdgpu_bo	*hpd_eop_obj;
87197b2e202SAlex Deucher 	u64			hpd_eop_gpu_addr;
872b1023571SKen Wang 	struct amdgpu_bo	*mec_fw_obj;
873b1023571SKen Wang 	u64			mec_fw_gpu_addr;
87497b2e202SAlex Deucher 	u32 num_mec;
87542794b27SAndres Rodriguez 	u32 num_pipe_per_mec;
87642794b27SAndres Rodriguez 	u32 num_queue_per_pipe;
87759a82d7dSXiangliang Yu 	void			*mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
87878c16834SAndres Rodriguez 
87978c16834SAndres Rodriguez 	/* These are the resources for which amdgpu takes ownership */
88078c16834SAndres Rodriguez 	DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
88197b2e202SAlex Deucher };
88297b2e202SAlex Deucher 
8834e638ae9SXiangliang Yu struct amdgpu_kiq {
8844e638ae9SXiangliang Yu 	u64			eop_gpu_addr;
8854e638ae9SXiangliang Yu 	struct amdgpu_bo	*eop_obj;
88643ca8efaSpding 	spinlock_t              ring_lock;
8874e638ae9SXiangliang Yu 	struct amdgpu_ring	ring;
8884e638ae9SXiangliang Yu 	struct amdgpu_irq_src	irq;
8894e638ae9SXiangliang Yu };
8904e638ae9SXiangliang Yu 
89197b2e202SAlex Deucher /*
89297b2e202SAlex Deucher  * GPU scratch registers structures, functions & helpers
89397b2e202SAlex Deucher  */
89497b2e202SAlex Deucher struct amdgpu_scratch {
89597b2e202SAlex Deucher 	unsigned		num_reg;
89697b2e202SAlex Deucher 	uint32_t                reg_base;
89750261151SNils Wallménius 	uint32_t		free_mask;
89897b2e202SAlex Deucher };
89997b2e202SAlex Deucher 
90097b2e202SAlex Deucher /*
90197b2e202SAlex Deucher  * GFX configurations
90297b2e202SAlex Deucher  */
903e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SE 4
904e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SH_PER_SE 2
905e3fa7630SAlex Deucher 
906e3fa7630SAlex Deucher struct amdgpu_rb_config {
907e3fa7630SAlex Deucher 	uint32_t rb_backend_disable;
908e3fa7630SAlex Deucher 	uint32_t user_rb_backend_disable;
909e3fa7630SAlex Deucher 	uint32_t raster_config;
910e3fa7630SAlex Deucher 	uint32_t raster_config_1;
911e3fa7630SAlex Deucher };
912e3fa7630SAlex Deucher 
913d0e95758SAndrey Grodzovsky struct gb_addr_config {
914d0e95758SAndrey Grodzovsky 	uint16_t pipe_interleave_size;
915d0e95758SAndrey Grodzovsky 	uint8_t num_pipes;
916d0e95758SAndrey Grodzovsky 	uint8_t max_compress_frags;
917d0e95758SAndrey Grodzovsky 	uint8_t num_banks;
918d0e95758SAndrey Grodzovsky 	uint8_t num_se;
919d0e95758SAndrey Grodzovsky 	uint8_t num_rb_per_se;
920d0e95758SAndrey Grodzovsky };
921d0e95758SAndrey Grodzovsky 
922ea323f88SJunwei Zhang struct amdgpu_gfx_config {
92397b2e202SAlex Deucher 	unsigned max_shader_engines;
92497b2e202SAlex Deucher 	unsigned max_tile_pipes;
92597b2e202SAlex Deucher 	unsigned max_cu_per_sh;
92697b2e202SAlex Deucher 	unsigned max_sh_per_se;
92797b2e202SAlex Deucher 	unsigned max_backends_per_se;
92897b2e202SAlex Deucher 	unsigned max_texture_channel_caches;
92997b2e202SAlex Deucher 	unsigned max_gprs;
93097b2e202SAlex Deucher 	unsigned max_gs_threads;
93197b2e202SAlex Deucher 	unsigned max_hw_contexts;
93297b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_frontend;
93397b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_backend;
93497b2e202SAlex Deucher 	unsigned sc_hiz_tile_fifo_size;
93597b2e202SAlex Deucher 	unsigned sc_earlyz_tile_fifo_size;
93697b2e202SAlex Deucher 
93797b2e202SAlex Deucher 	unsigned num_tile_pipes;
93897b2e202SAlex Deucher 	unsigned backend_enable_mask;
93997b2e202SAlex Deucher 	unsigned mem_max_burst_length_bytes;
94097b2e202SAlex Deucher 	unsigned mem_row_size_in_kb;
94197b2e202SAlex Deucher 	unsigned shader_engine_tile_size;
94297b2e202SAlex Deucher 	unsigned num_gpus;
94397b2e202SAlex Deucher 	unsigned multi_gpu_tile_size;
94497b2e202SAlex Deucher 	unsigned mc_arb_ramcfg;
94597b2e202SAlex Deucher 	unsigned gb_addr_config;
9468f8e00c1SAlex Deucher 	unsigned num_rbs;
947408bfe7cSJunwei Zhang 	unsigned gs_vgt_table_depth;
948408bfe7cSJunwei Zhang 	unsigned gs_prim_buffer_depth;
94997b2e202SAlex Deucher 
95097b2e202SAlex Deucher 	uint32_t tile_mode_array[32];
95197b2e202SAlex Deucher 	uint32_t macrotile_mode_array[16];
952e3fa7630SAlex Deucher 
953d0e95758SAndrey Grodzovsky 	struct gb_addr_config gb_addr_config_fields;
954e3fa7630SAlex Deucher 	struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
955df6e2c4aSJunwei Zhang 
956df6e2c4aSJunwei Zhang 	/* gfx configure feature */
957df6e2c4aSJunwei Zhang 	uint32_t double_offchip_lds_buf;
95897b2e202SAlex Deucher };
95997b2e202SAlex Deucher 
9607dae69a2SAlex Deucher struct amdgpu_cu_info {
96151fd0370SHawking Zhang 	uint32_t max_waves_per_simd;
962408bfe7cSJunwei Zhang 	uint32_t wave_front_size;
96351fd0370SHawking Zhang 	uint32_t max_scratch_slots_per_cu;
96451fd0370SHawking Zhang 	uint32_t lds_size;
965dbfe85eaSFlora Cui 
966dbfe85eaSFlora Cui 	/* total active CU number */
967dbfe85eaSFlora Cui 	uint32_t number;
968dbfe85eaSFlora Cui 	uint32_t ao_cu_mask;
969dbfe85eaSFlora Cui 	uint32_t ao_cu_bitmap[4][4];
9707dae69a2SAlex Deucher 	uint32_t bitmap[4][4];
9717dae69a2SAlex Deucher };
9727dae69a2SAlex Deucher 
973b95e31fdSAlex Deucher struct amdgpu_gfx_funcs {
974b95e31fdSAlex Deucher 	/* get the gpu clock counter */
975b95e31fdSAlex Deucher 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
9769559ef5bSTom St Denis 	void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
977472259f0STom St Denis 	void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);
978c5a60ce8STom St Denis 	void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t thread, uint32_t start, uint32_t size, uint32_t *dst);
979c5a60ce8STom St Denis 	void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst);
980b95e31fdSAlex Deucher };
981b95e31fdSAlex Deucher 
982bce23e00SAlex Deucher struct amdgpu_ngg_buf {
983bce23e00SAlex Deucher 	struct amdgpu_bo	*bo;
984bce23e00SAlex Deucher 	uint64_t		gpu_addr;
985bce23e00SAlex Deucher 	uint32_t		size;
986bce23e00SAlex Deucher 	uint32_t		bo_size;
987bce23e00SAlex Deucher };
988bce23e00SAlex Deucher 
989bce23e00SAlex Deucher enum {
990af8baf15SGuenter Roeck 	NGG_PRIM = 0,
991af8baf15SGuenter Roeck 	NGG_POS,
992af8baf15SGuenter Roeck 	NGG_CNTL,
993af8baf15SGuenter Roeck 	NGG_PARAM,
994bce23e00SAlex Deucher 	NGG_BUF_MAX
995bce23e00SAlex Deucher };
996bce23e00SAlex Deucher 
997bce23e00SAlex Deucher struct amdgpu_ngg {
998bce23e00SAlex Deucher 	struct amdgpu_ngg_buf	buf[NGG_BUF_MAX];
999bce23e00SAlex Deucher 	uint32_t		gds_reserve_addr;
1000bce23e00SAlex Deucher 	uint32_t		gds_reserve_size;
1001bce23e00SAlex Deucher 	bool			init;
1002bce23e00SAlex Deucher };
1003bce23e00SAlex Deucher 
100497b2e202SAlex Deucher struct amdgpu_gfx {
100597b2e202SAlex Deucher 	struct mutex			gpu_clock_mutex;
1006ea323f88SJunwei Zhang 	struct amdgpu_gfx_config	config;
100797b2e202SAlex Deucher 	struct amdgpu_rlc		rlc;
100897b2e202SAlex Deucher 	struct amdgpu_mec		mec;
10094e638ae9SXiangliang Yu 	struct amdgpu_kiq		kiq;
101097b2e202SAlex Deucher 	struct amdgpu_scratch		scratch;
101197b2e202SAlex Deucher 	const struct firmware		*me_fw;	/* ME firmware */
101297b2e202SAlex Deucher 	uint32_t			me_fw_version;
101397b2e202SAlex Deucher 	const struct firmware		*pfp_fw; /* PFP firmware */
101497b2e202SAlex Deucher 	uint32_t			pfp_fw_version;
101597b2e202SAlex Deucher 	const struct firmware		*ce_fw;	/* CE firmware */
101697b2e202SAlex Deucher 	uint32_t			ce_fw_version;
101797b2e202SAlex Deucher 	const struct firmware		*rlc_fw; /* RLC firmware */
101897b2e202SAlex Deucher 	uint32_t			rlc_fw_version;
101997b2e202SAlex Deucher 	const struct firmware		*mec_fw; /* MEC firmware */
102097b2e202SAlex Deucher 	uint32_t			mec_fw_version;
102197b2e202SAlex Deucher 	const struct firmware		*mec2_fw; /* MEC2 firmware */
102297b2e202SAlex Deucher 	uint32_t			mec2_fw_version;
102302558a00SKen Wang 	uint32_t			me_feature_version;
102402558a00SKen Wang 	uint32_t			ce_feature_version;
102502558a00SKen Wang 	uint32_t			pfp_feature_version;
1026351643d7SJammy Zhou 	uint32_t			rlc_feature_version;
1027351643d7SJammy Zhou 	uint32_t			mec_feature_version;
1028351643d7SJammy Zhou 	uint32_t			mec2_feature_version;
102997b2e202SAlex Deucher 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
103097b2e202SAlex Deucher 	unsigned			num_gfx_rings;
103197b2e202SAlex Deucher 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
103297b2e202SAlex Deucher 	unsigned			num_compute_rings;
103397b2e202SAlex Deucher 	struct amdgpu_irq_src		eop_irq;
103497b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_reg_irq;
103597b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_inst_irq;
103697b2e202SAlex Deucher 	/* gfx status */
103797b2e202SAlex Deucher 	uint32_t			gfx_current_status;
1038a101a899SKen Wang 	/* ce ram size*/
1039a101a899SKen Wang 	unsigned			ce_ram_size;
10407dae69a2SAlex Deucher 	struct amdgpu_cu_info		cu_info;
1041b95e31fdSAlex Deucher 	const struct amdgpu_gfx_funcs	*funcs;
10423d7c6384SChunming Zhou 
10433d7c6384SChunming Zhou 	/* reset mask */
10443d7c6384SChunming Zhou 	uint32_t                        grbm_soft_reset;
10453d7c6384SChunming Zhou 	uint32_t                        srbm_soft_reset;
1046b4e40676SDavid Panariti 	/* s3/s4 mask */
1047b4e40676SDavid Panariti 	bool                            in_suspend;
1048bce23e00SAlex Deucher 	/* NGG */
1049bce23e00SAlex Deucher 	struct amdgpu_ngg		ngg;
1050b8866c26SAndres Rodriguez 
1051b8866c26SAndres Rodriguez 	/* pipe reservation */
1052b8866c26SAndres Rodriguez 	struct mutex			pipe_reserve_mutex;
1053b8866c26SAndres Rodriguez 	DECLARE_BITMAP			(pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
105497b2e202SAlex Deucher };
105597b2e202SAlex Deucher 
1056b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
105797b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
10584d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1059f54d1867SChris Wilson 		    struct dma_fence *f);
1060b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
106150ddc75eSJunwei Zhang 		       struct amdgpu_ib *ibs, struct amdgpu_job *job,
106250ddc75eSJunwei Zhang 		       struct dma_fence **f);
106397b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
106497b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
106597b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
106697b2e202SAlex Deucher 
106797b2e202SAlex Deucher /*
106897b2e202SAlex Deucher  * CS.
106997b2e202SAlex Deucher  */
107097b2e202SAlex Deucher struct amdgpu_cs_chunk {
107197b2e202SAlex Deucher 	uint32_t		chunk_id;
107297b2e202SAlex Deucher 	uint32_t		length_dw;
1073758ac17fSChristian König 	void			*kdata;
107497b2e202SAlex Deucher };
107597b2e202SAlex Deucher 
107697b2e202SAlex Deucher struct amdgpu_cs_parser {
107797b2e202SAlex Deucher 	struct amdgpu_device	*adev;
107897b2e202SAlex Deucher 	struct drm_file		*filp;
10793cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
1080c3cca41eSChristian König 
108197b2e202SAlex Deucher 	/* chunks */
108297b2e202SAlex Deucher 	unsigned		nchunks;
108397b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
1084c3cca41eSChristian König 
108550838c8cSChristian König 	/* scheduler job object */
108650838c8cSChristian König 	struct amdgpu_job	*job;
1087c3cca41eSChristian König 
1088c3cca41eSChristian König 	/* buffer objects */
1089c3cca41eSChristian König 	struct ww_acquire_ctx		ticket;
1090c3cca41eSChristian König 	struct amdgpu_bo_list		*bo_list;
10913fe89771SChristian König 	struct amdgpu_mn		*mn;
109256467ebfSChristian König 	struct amdgpu_bo_list_entry	vm_pd;
109397b2e202SAlex Deucher 	struct list_head		validated;
1094f54d1867SChris Wilson 	struct dma_fence		*fence;
1095f69f90a1SChristian König 	uint64_t			bytes_moved_threshold;
109600f06b24SJohn Brooks 	uint64_t			bytes_moved_vis_threshold;
1097f69f90a1SChristian König 	uint64_t			bytes_moved;
109800f06b24SJohn Brooks 	uint64_t			bytes_moved_vis;
1099662bfa61SChristian König 	struct amdgpu_bo_list_entry	*evictable;
110097b2e202SAlex Deucher 
110197b2e202SAlex Deucher 	/* user fence */
110291acbeb6SChristian König 	struct amdgpu_bo_list_entry	uf_entry;
1103660e8558SDave Airlie 
1104660e8558SDave Airlie 	unsigned num_post_dep_syncobjs;
1105660e8558SDave Airlie 	struct drm_syncobj **post_dep_syncobjs;
110697b2e202SAlex Deucher };
110797b2e202SAlex Deucher 
1108753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT          (1 << 0) /* bit set means command submit involves a preamble IB */
1109753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST    (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1110753ad49cSMonk Liu #define AMDGPU_HAVE_CTX_SWITCH              (1 << 2) /* bit set means context switch occured */
1111753ad49cSMonk Liu 
1112bb977d37SChunming Zhou struct amdgpu_job {
11131b1f42d8SLucas Stach 	struct drm_sched_job    base;
1114bb977d37SChunming Zhou 	struct amdgpu_device	*adev;
1115c5637837SMonk Liu 	struct amdgpu_vm	*vm;
1116b07c60c0SChristian König 	struct amdgpu_ring	*ring;
1117e86f9ceeSChristian König 	struct amdgpu_sync	sync;
1118df83d1ebSChunming Zhou 	struct amdgpu_sync	sched_sync;
1119bb977d37SChunming Zhou 	struct amdgpu_ib	*ibs;
1120f54d1867SChris Wilson 	struct dma_fence	*fence; /* the hw fence */
1121753ad49cSMonk Liu 	uint32_t		preamble_status;
1122bb977d37SChunming Zhou 	uint32_t		num_ibs;
1123e2840221SChristian König 	void			*owner;
11243aecd24cSMonk Liu 	uint64_t		fence_ctx; /* the fence_context this job uses */
1125fd53be30SChunming Zhou 	bool                    vm_needs_flush;
1126d88bf583SChristian König 	unsigned		vm_id;
1127d88bf583SChristian König 	uint64_t		vm_pd_addr;
1128d88bf583SChristian König 	uint32_t		gds_base, gds_size;
1129d88bf583SChristian König 	uint32_t		gws_base, gws_size;
1130d88bf583SChristian König 	uint32_t		oa_base, oa_size;
113114e47f93SChristian König 	uint32_t		vram_lost_counter;
1132758ac17fSChristian König 
1133758ac17fSChristian König 	/* user fence handling */
1134b5f5acbcSChristian König 	uint64_t		uf_addr;
1135758ac17fSChristian König 	uint64_t		uf_sequence;
1136758ac17fSChristian König 
1137bb977d37SChunming Zhou };
1138a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job)		\
1139a6db8a33SJunwei Zhang 		container_of((sched_job), struct amdgpu_job, base)
1140bb977d37SChunming Zhou 
11417270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
11427270f839SChristian König 				      uint32_t ib_idx, int idx)
114397b2e202SAlex Deucher {
114450838c8cSChristian König 	return p->job->ibs[ib_idx].ptr[idx];
114597b2e202SAlex Deucher }
114697b2e202SAlex Deucher 
11477270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
11487270f839SChristian König 				       uint32_t ib_idx, int idx,
11497270f839SChristian König 				       uint32_t value)
11507270f839SChristian König {
115150838c8cSChristian König 	p->job->ibs[ib_idx].ptr[idx] = value;
11527270f839SChristian König }
11537270f839SChristian König 
115497b2e202SAlex Deucher /*
115597b2e202SAlex Deucher  * Writeback
115697b2e202SAlex Deucher  */
1157896a664cSMonk Liu #define AMDGPU_MAX_WB 512	/* Reserve at most 512 WB slots for amdgpu-owned rings. */
115897b2e202SAlex Deucher 
115997b2e202SAlex Deucher struct amdgpu_wb {
116097b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
116197b2e202SAlex Deucher 	volatile uint32_t	*wb;
116297b2e202SAlex Deucher 	uint64_t		gpu_addr;
116397b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
116497b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
116597b2e202SAlex Deucher };
116697b2e202SAlex Deucher 
1167131b4b36SAlex Deucher int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
1168131b4b36SAlex Deucher void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
116997b2e202SAlex Deucher 
1170041d9d93SAlex Deucher void amdgpu_device_get_pcie_info(struct amdgpu_device *adev);
1171d0dd7f0cSAlex Deucher 
117297b2e202SAlex Deucher /*
117397b2e202SAlex Deucher  * SDMA
117497b2e202SAlex Deucher  */
1175c113ea1cSAlex Deucher struct amdgpu_sdma_instance {
117697b2e202SAlex Deucher 	/* SDMA firmware */
117797b2e202SAlex Deucher 	const struct firmware	*fw;
117897b2e202SAlex Deucher 	uint32_t		fw_version;
1179cfa2104fSJammy Zhou 	uint32_t		feature_version;
118097b2e202SAlex Deucher 
118197b2e202SAlex Deucher 	struct amdgpu_ring	ring;
118218111de0SJammy Zhou 	bool			burst_nop;
118397b2e202SAlex Deucher };
118497b2e202SAlex Deucher 
1185c113ea1cSAlex Deucher struct amdgpu_sdma {
1186c113ea1cSAlex Deucher 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
118730d1574fSKen Wang #ifdef CONFIG_DRM_AMDGPU_SI
118830d1574fSKen Wang 	//SI DMA has a difference trap irq number for the second engine
118930d1574fSKen Wang 	struct amdgpu_irq_src	trap_irq_1;
119030d1574fSKen Wang #endif
1191c113ea1cSAlex Deucher 	struct amdgpu_irq_src	trap_irq;
1192c113ea1cSAlex Deucher 	struct amdgpu_irq_src	illegal_inst_irq;
1193c113ea1cSAlex Deucher 	int			num_instances;
1194e702a680SChunming Zhou 	uint32_t                    srbm_soft_reset;
1195c113ea1cSAlex Deucher };
1196c113ea1cSAlex Deucher 
119797b2e202SAlex Deucher /*
119897b2e202SAlex Deucher  * Firmware
119997b2e202SAlex Deucher  */
1200e635ee07SHuang Rui enum amdgpu_firmware_load_type {
1201e635ee07SHuang Rui 	AMDGPU_FW_LOAD_DIRECT = 0,
1202e635ee07SHuang Rui 	AMDGPU_FW_LOAD_SMU,
1203e635ee07SHuang Rui 	AMDGPU_FW_LOAD_PSP,
1204e635ee07SHuang Rui };
1205e635ee07SHuang Rui 
120697b2e202SAlex Deucher struct amdgpu_firmware {
120797b2e202SAlex Deucher 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1208e635ee07SHuang Rui 	enum amdgpu_firmware_load_type load_type;
120997b2e202SAlex Deucher 	struct amdgpu_bo *fw_buf;
121097b2e202SAlex Deucher 	unsigned int fw_size;
12112445b227SHuang Rui 	unsigned int max_ucodes;
12120e5ca0d1SHuang Rui 	/* firmwares are loaded by psp instead of smu from vega10 */
12130e5ca0d1SHuang Rui 	const struct amdgpu_psp_funcs *funcs;
12140e5ca0d1SHuang Rui 	struct amdgpu_bo *rbuf;
12150e5ca0d1SHuang Rui 	struct mutex mutex;
1216ab4fe3e1SHuang Rui 
1217ab4fe3e1SHuang Rui 	/* gpu info firmware data pointer */
1218ab4fe3e1SHuang Rui 	const struct firmware *gpu_info_fw;
1219d59c026bSMonk Liu 
1220d59c026bSMonk Liu 	void *fw_buf_ptr;
1221d59c026bSMonk Liu 	uint64_t fw_buf_mc;
122297b2e202SAlex Deucher };
122397b2e202SAlex Deucher 
122497b2e202SAlex Deucher /*
122597b2e202SAlex Deucher  * Benchmarking
122697b2e202SAlex Deucher  */
122797b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
122897b2e202SAlex Deucher 
122997b2e202SAlex Deucher 
123097b2e202SAlex Deucher /*
123197b2e202SAlex Deucher  * Testing
123297b2e202SAlex Deucher  */
123397b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
123497b2e202SAlex Deucher 
123550ab2533SHuang Rui 
123697b2e202SAlex Deucher /*
123797b2e202SAlex Deucher  * amdgpu smumgr functions
123897b2e202SAlex Deucher  */
123997b2e202SAlex Deucher struct amdgpu_smumgr_funcs {
124097b2e202SAlex Deucher 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
124197b2e202SAlex Deucher 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
124297b2e202SAlex Deucher 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
124397b2e202SAlex Deucher };
124497b2e202SAlex Deucher 
124597b2e202SAlex Deucher /*
124697b2e202SAlex Deucher  * amdgpu smumgr
124797b2e202SAlex Deucher  */
124897b2e202SAlex Deucher struct amdgpu_smumgr {
124997b2e202SAlex Deucher 	struct amdgpu_bo *toc_buf;
125097b2e202SAlex Deucher 	struct amdgpu_bo *smu_buf;
125197b2e202SAlex Deucher 	/* asic priv smu data */
125297b2e202SAlex Deucher 	void *priv;
125397b2e202SAlex Deucher 	spinlock_t smu_lock;
125497b2e202SAlex Deucher 	/* smumgr functions */
125597b2e202SAlex Deucher 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
125697b2e202SAlex Deucher 	/* ucode loading complete flag */
125797b2e202SAlex Deucher 	uint32_t fw_flags;
125897b2e202SAlex Deucher };
125997b2e202SAlex Deucher 
126097b2e202SAlex Deucher /*
126197b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
126297b2e202SAlex Deucher  */
126397b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
126497b2e202SAlex Deucher 	uint32_t reg_offset;
126597b2e202SAlex Deucher 	bool grbm_indexed;
126697b2e202SAlex Deucher };
126797b2e202SAlex Deucher 
126897b2e202SAlex Deucher /*
126997b2e202SAlex Deucher  * ASIC specific functions.
127097b2e202SAlex Deucher  */
127197b2e202SAlex Deucher struct amdgpu_asic_funcs {
127297b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
12737946b878SAlex Deucher 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
12747946b878SAlex Deucher 				   u8 *bios, u32 length_bytes);
127597b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
127697b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
127797b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
127897b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
127997b2e202SAlex Deucher 	/* get the reference clock */
128097b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
128197b2e202SAlex Deucher 	/* MM block clocks */
128297b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
128397b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1284841686dfSMaruthi Bayyavarapu 	/* static power management */
1285841686dfSMaruthi Bayyavarapu 	int (*get_pcie_lanes)(struct amdgpu_device *adev);
1286841686dfSMaruthi Bayyavarapu 	void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
1287bbf282d8SAlex Deucher 	/* get config memsize register */
1288bbf282d8SAlex Deucher 	u32 (*get_config_memsize)(struct amdgpu_device *adev);
128997b2e202SAlex Deucher };
129097b2e202SAlex Deucher 
129197b2e202SAlex Deucher /*
129297b2e202SAlex Deucher  * IOCTL.
129397b2e202SAlex Deucher  */
129497b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
129597b2e202SAlex Deucher 			    struct drm_file *filp);
129697b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
129797b2e202SAlex Deucher 				struct drm_file *filp);
129897b2e202SAlex Deucher 
129997b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
130097b2e202SAlex Deucher 			  struct drm_file *filp);
130197b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
130297b2e202SAlex Deucher 			struct drm_file *filp);
130397b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
130497b2e202SAlex Deucher 			  struct drm_file *filp);
130597b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
130697b2e202SAlex Deucher 			      struct drm_file *filp);
130797b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
130897b2e202SAlex Deucher 			  struct drm_file *filp);
130997b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
131097b2e202SAlex Deucher 			struct drm_file *filp);
131197b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
13127ca24cf2SMarek Olšák int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
13137ca24cf2SMarek Olšák 				    struct drm_file *filp);
131497b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1315eef18a82SJunwei Zhang int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
1316eef18a82SJunwei Zhang 				struct drm_file *filp);
131797b2e202SAlex Deucher 
131897b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
131997b2e202SAlex Deucher 				struct drm_file *filp);
132097b2e202SAlex Deucher 
132197b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
132297b2e202SAlex Deucher struct amdgpu_vram_scratch {
132397b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
132497b2e202SAlex Deucher 	volatile uint32_t		*ptr;
132597b2e202SAlex Deucher 	u64				gpu_addr;
132697b2e202SAlex Deucher };
132797b2e202SAlex Deucher 
132897b2e202SAlex Deucher /*
132997b2e202SAlex Deucher  * ACPI
133097b2e202SAlex Deucher  */
133197b2e202SAlex Deucher struct amdgpu_atif_notification_cfg {
133297b2e202SAlex Deucher 	bool enabled;
133397b2e202SAlex Deucher 	int command_code;
133497b2e202SAlex Deucher };
133597b2e202SAlex Deucher 
133697b2e202SAlex Deucher struct amdgpu_atif_notifications {
133797b2e202SAlex Deucher 	bool display_switch;
133897b2e202SAlex Deucher 	bool expansion_mode_change;
133997b2e202SAlex Deucher 	bool thermal_state;
134097b2e202SAlex Deucher 	bool forced_power_state;
134197b2e202SAlex Deucher 	bool system_power_state;
134297b2e202SAlex Deucher 	bool display_conf_change;
134397b2e202SAlex Deucher 	bool px_gfx_switch;
134497b2e202SAlex Deucher 	bool brightness_change;
134597b2e202SAlex Deucher 	bool dgpu_display_event;
134697b2e202SAlex Deucher };
134797b2e202SAlex Deucher 
134897b2e202SAlex Deucher struct amdgpu_atif_functions {
134997b2e202SAlex Deucher 	bool system_params;
135097b2e202SAlex Deucher 	bool sbios_requests;
135197b2e202SAlex Deucher 	bool select_active_disp;
135297b2e202SAlex Deucher 	bool lid_state;
135397b2e202SAlex Deucher 	bool get_tv_standard;
135497b2e202SAlex Deucher 	bool set_tv_standard;
135597b2e202SAlex Deucher 	bool get_panel_expansion_mode;
135697b2e202SAlex Deucher 	bool set_panel_expansion_mode;
135797b2e202SAlex Deucher 	bool temperature_change;
135897b2e202SAlex Deucher 	bool graphics_device_types;
135997b2e202SAlex Deucher };
136097b2e202SAlex Deucher 
136197b2e202SAlex Deucher struct amdgpu_atif {
136297b2e202SAlex Deucher 	struct amdgpu_atif_notifications notifications;
136397b2e202SAlex Deucher 	struct amdgpu_atif_functions functions;
136497b2e202SAlex Deucher 	struct amdgpu_atif_notification_cfg notification_cfg;
136597b2e202SAlex Deucher 	struct amdgpu_encoder *encoder_for_bl;
136697b2e202SAlex Deucher };
136797b2e202SAlex Deucher 
136897b2e202SAlex Deucher struct amdgpu_atcs_functions {
136997b2e202SAlex Deucher 	bool get_ext_state;
137097b2e202SAlex Deucher 	bool pcie_perf_req;
137197b2e202SAlex Deucher 	bool pcie_dev_rdy;
137297b2e202SAlex Deucher 	bool pcie_bus_width;
137397b2e202SAlex Deucher };
137497b2e202SAlex Deucher 
137597b2e202SAlex Deucher struct amdgpu_atcs {
137697b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
137797b2e202SAlex Deucher };
137897b2e202SAlex Deucher 
137997b2e202SAlex Deucher /*
1380a05502e5SHorace Chen  * Firmware VRAM reservation
1381a05502e5SHorace Chen  */
1382a05502e5SHorace Chen struct amdgpu_fw_vram_usage {
1383a05502e5SHorace Chen 	u64 start_offset;
1384a05502e5SHorace Chen 	u64 size;
1385a05502e5SHorace Chen 	struct amdgpu_bo *reserved_bo;
1386a05502e5SHorace Chen 	void *va;
1387a05502e5SHorace Chen };
1388a05502e5SHorace Chen 
1389a05502e5SHorace Chen /*
1390d03846afSChunming Zhou  * CGS
1391d03846afSChunming Zhou  */
1392110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1393110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1394a8fe58ceSMaruthi Bayyavarapu 
1395a8fe58ceSMaruthi Bayyavarapu /*
139697b2e202SAlex Deucher  * Core structure, functions and helpers.
139797b2e202SAlex Deucher  */
139897b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
139997b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
140097b2e202SAlex Deucher 
140197b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
140297b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
140397b2e202SAlex Deucher 
1404946a4d5bSShaoyun Liu 
1405946a4d5bSShaoyun Liu /*
1406946a4d5bSShaoyun Liu  * amdgpu nbio functions
1407946a4d5bSShaoyun Liu  *
1408946a4d5bSShaoyun Liu  */
1409bf383fb6SAlex Deucher struct nbio_hdp_flush_reg {
1410bf383fb6SAlex Deucher 	u32 ref_and_mask_cp0;
1411bf383fb6SAlex Deucher 	u32 ref_and_mask_cp1;
1412bf383fb6SAlex Deucher 	u32 ref_and_mask_cp2;
1413bf383fb6SAlex Deucher 	u32 ref_and_mask_cp3;
1414bf383fb6SAlex Deucher 	u32 ref_and_mask_cp4;
1415bf383fb6SAlex Deucher 	u32 ref_and_mask_cp5;
1416bf383fb6SAlex Deucher 	u32 ref_and_mask_cp6;
1417bf383fb6SAlex Deucher 	u32 ref_and_mask_cp7;
1418bf383fb6SAlex Deucher 	u32 ref_and_mask_cp8;
1419bf383fb6SAlex Deucher 	u32 ref_and_mask_cp9;
1420bf383fb6SAlex Deucher 	u32 ref_and_mask_sdma0;
1421bf383fb6SAlex Deucher 	u32 ref_and_mask_sdma1;
1422bf383fb6SAlex Deucher };
1423946a4d5bSShaoyun Liu 
1424946a4d5bSShaoyun Liu struct amdgpu_nbio_funcs {
1425bf383fb6SAlex Deucher 	const struct nbio_hdp_flush_reg *hdp_flush_reg;
1426bf383fb6SAlex Deucher 	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
1427bf383fb6SAlex Deucher 	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
1428bf383fb6SAlex Deucher 	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
1429bf383fb6SAlex Deucher 	u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
1430bf383fb6SAlex Deucher 	u32 (*get_rev_id)(struct amdgpu_device *adev);
1431bf383fb6SAlex Deucher 	void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
1432bf383fb6SAlex Deucher 	void (*hdp_flush)(struct amdgpu_device *adev);
1433bf383fb6SAlex Deucher 	u32 (*get_memsize)(struct amdgpu_device *adev);
1434bf383fb6SAlex Deucher 	void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
1435bf383fb6SAlex Deucher 				    bool use_doorbell, int doorbell_index);
1436bf383fb6SAlex Deucher 	void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
1437bf383fb6SAlex Deucher 					 bool enable);
1438bf383fb6SAlex Deucher 	void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
1439bf383fb6SAlex Deucher 						  bool enable);
1440bf383fb6SAlex Deucher 	void (*ih_doorbell_range)(struct amdgpu_device *adev,
1441bf383fb6SAlex Deucher 				  bool use_doorbell, int doorbell_index);
1442bf383fb6SAlex Deucher 	void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
1443bf383fb6SAlex Deucher 						 bool enable);
1444bf383fb6SAlex Deucher 	void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
1445bf383fb6SAlex Deucher 						bool enable);
1446bf383fb6SAlex Deucher 	void (*get_clockgating_state)(struct amdgpu_device *adev,
1447bf383fb6SAlex Deucher 				      u32 *flags);
1448bf383fb6SAlex Deucher 	void (*ih_control)(struct amdgpu_device *adev);
1449bf383fb6SAlex Deucher 	void (*init_registers)(struct amdgpu_device *adev);
1450bf383fb6SAlex Deucher 	void (*detect_hw_virt)(struct amdgpu_device *adev);
1451946a4d5bSShaoyun Liu };
1452946a4d5bSShaoyun Liu 
1453946a4d5bSShaoyun Liu 
14544522824cSShaoyun Liu /* Define the HW IP blocks will be used in driver , add more if necessary */
14554522824cSShaoyun Liu enum amd_hw_ip_block_type {
14564522824cSShaoyun Liu 	GC_HWIP = 1,
14574522824cSShaoyun Liu 	HDP_HWIP,
14584522824cSShaoyun Liu 	SDMA0_HWIP,
14594522824cSShaoyun Liu 	SDMA1_HWIP,
14604522824cSShaoyun Liu 	MMHUB_HWIP,
14614522824cSShaoyun Liu 	ATHUB_HWIP,
14624522824cSShaoyun Liu 	NBIO_HWIP,
14634522824cSShaoyun Liu 	MP0_HWIP,
14644522824cSShaoyun Liu 	UVD_HWIP,
14654522824cSShaoyun Liu 	VCN_HWIP = UVD_HWIP,
14664522824cSShaoyun Liu 	VCE_HWIP,
14674522824cSShaoyun Liu 	DF_HWIP,
14684522824cSShaoyun Liu 	DCE_HWIP,
14694522824cSShaoyun Liu 	OSSSYS_HWIP,
14704522824cSShaoyun Liu 	SMUIO_HWIP,
14714522824cSShaoyun Liu 	PWR_HWIP,
14724522824cSShaoyun Liu 	NBIF_HWIP,
14734522824cSShaoyun Liu 	MAX_HWIP
14744522824cSShaoyun Liu };
14754522824cSShaoyun Liu 
14764522824cSShaoyun Liu #define HWIP_MAX_INSTANCE	6
14774522824cSShaoyun Liu 
147811dc9364SRex Zhu struct amd_powerplay {
147911dc9364SRex Zhu 	struct cgs_device *cgs_device;
148011dc9364SRex Zhu 	void *pp_handle;
148111dc9364SRex Zhu 	const struct amd_ip_funcs *ip_funcs;
148211dc9364SRex Zhu 	const struct amd_pm_funcs *pp_funcs;
148311dc9364SRex Zhu };
148411dc9364SRex Zhu 
14850c49e0b8SChunming Zhou #define AMDGPU_RESET_MAGIC_NUM 64
148697b2e202SAlex Deucher struct amdgpu_device {
148797b2e202SAlex Deucher 	struct device			*dev;
148897b2e202SAlex Deucher 	struct drm_device		*ddev;
148997b2e202SAlex Deucher 	struct pci_dev			*pdev;
149097b2e202SAlex Deucher 
1491a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP
1492a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_acp		acp;
1493a8fe58ceSMaruthi Bayyavarapu #endif
1494a8fe58ceSMaruthi Bayyavarapu 
149597b2e202SAlex Deucher 	/* ASIC */
14962f7d10b3SJammy Zhou 	enum amd_asic_type		asic_type;
149797b2e202SAlex Deucher 	uint32_t			family;
149897b2e202SAlex Deucher 	uint32_t			rev_id;
149997b2e202SAlex Deucher 	uint32_t			external_rev_id;
150097b2e202SAlex Deucher 	unsigned long			flags;
150197b2e202SAlex Deucher 	int				usec_timeout;
150297b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
150397b2e202SAlex Deucher 	bool				shutdown;
150497b2e202SAlex Deucher 	bool				need_dma32;
150597b2e202SAlex Deucher 	bool				accel_working;
150697b2e202SAlex Deucher 	struct work_struct		reset_work;
150797b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
150897b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
150997b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
151097b2e202SAlex Deucher 	unsigned			debugfs_count;
151197b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
1512adcec288STom St Denis 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
151397b2e202SAlex Deucher #endif
151497b2e202SAlex Deucher 	struct amdgpu_atif		atif;
151597b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
151697b2e202SAlex Deucher 	struct mutex			srbm_mutex;
151797b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
151897b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
151997b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
152097b2e202SAlex Deucher 	bool				have_disp_power_ref;
152197b2e202SAlex Deucher 
152297b2e202SAlex Deucher 	/* BIOS */
15230cdd5005SAlex Deucher 	bool				is_atom_fw;
152497b2e202SAlex Deucher 	uint8_t				*bios;
1525a9f5db9cSEvan Quan 	uint32_t			bios_size;
15265af2c10dSKent Russell 	struct amdgpu_bo		*stolen_vga_memory;
1527a5bde2f9SAlex Deucher 	uint32_t			bios_scratch_reg_offset;
152897b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
152997b2e202SAlex Deucher 
153097b2e202SAlex Deucher 	/* Register/doorbell mmio */
153197b2e202SAlex Deucher 	resource_size_t			rmmio_base;
153297b2e202SAlex Deucher 	resource_size_t			rmmio_size;
153397b2e202SAlex Deucher 	void __iomem			*rmmio;
153497b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
153597b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
153697b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
153797b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
153897b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
153997b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
154097b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
154197b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
154297b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
154397b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
154436b9a952SHuang Rui 	amdgpu_rreg_t			pciep_rreg;
154536b9a952SHuang Rui 	amdgpu_wreg_t			pciep_wreg;
154697b2e202SAlex Deucher 	/* protects concurrent UVD register access */
154797b2e202SAlex Deucher 	spinlock_t uvd_ctx_idx_lock;
154897b2e202SAlex Deucher 	amdgpu_rreg_t			uvd_ctx_rreg;
154997b2e202SAlex Deucher 	amdgpu_wreg_t			uvd_ctx_wreg;
155097b2e202SAlex Deucher 	/* protects concurrent DIDT register access */
155197b2e202SAlex Deucher 	spinlock_t didt_idx_lock;
155297b2e202SAlex Deucher 	amdgpu_rreg_t			didt_rreg;
155397b2e202SAlex Deucher 	amdgpu_wreg_t			didt_wreg;
1554ccdbb20aSRex Zhu 	/* protects concurrent gc_cac register access */
1555ccdbb20aSRex Zhu 	spinlock_t gc_cac_idx_lock;
1556ccdbb20aSRex Zhu 	amdgpu_rreg_t			gc_cac_rreg;
1557ccdbb20aSRex Zhu 	amdgpu_wreg_t			gc_cac_wreg;
155816abb5d2SEvan Quan 	/* protects concurrent se_cac register access */
155916abb5d2SEvan Quan 	spinlock_t se_cac_idx_lock;
156016abb5d2SEvan Quan 	amdgpu_rreg_t			se_cac_rreg;
156116abb5d2SEvan Quan 	amdgpu_wreg_t			se_cac_wreg;
156297b2e202SAlex Deucher 	/* protects concurrent ENDPOINT (audio) register access */
156397b2e202SAlex Deucher 	spinlock_t audio_endpt_idx_lock;
156497b2e202SAlex Deucher 	amdgpu_block_rreg_t		audio_endpt_rreg;
156597b2e202SAlex Deucher 	amdgpu_block_wreg_t		audio_endpt_wreg;
156697b2e202SAlex Deucher 	void __iomem                    *rio_mem;
156797b2e202SAlex Deucher 	resource_size_t			rio_mem_size;
156897b2e202SAlex Deucher 	struct amdgpu_doorbell		doorbell;
156997b2e202SAlex Deucher 
157097b2e202SAlex Deucher 	/* clock/pll info */
157197b2e202SAlex Deucher 	struct amdgpu_clock            clock;
157297b2e202SAlex Deucher 
157397b2e202SAlex Deucher 	/* MC */
157497b2e202SAlex Deucher 	struct amdgpu_mc		mc;
157597b2e202SAlex Deucher 	struct amdgpu_gart		gart;
157697b2e202SAlex Deucher 	struct amdgpu_dummy_page	dummy_page;
157797b2e202SAlex Deucher 	struct amdgpu_vm_manager	vm_manager;
1578e60f8db5SAlex Xie 	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
157997b2e202SAlex Deucher 
158097b2e202SAlex Deucher 	/* memory management */
158197b2e202SAlex Deucher 	struct amdgpu_mman		mman;
158297b2e202SAlex Deucher 	struct amdgpu_vram_scratch	vram_scratch;
158397b2e202SAlex Deucher 	struct amdgpu_wb		wb;
158497b2e202SAlex Deucher 	atomic64_t			num_bytes_moved;
1585dbd5ed60SChristian König 	atomic64_t			num_evictions;
158668e2c5ffSMarek Olšák 	atomic64_t			num_vram_cpu_page_faults;
1587d94aed5aSMarek Olšák 	atomic_t			gpu_reset_counter;
1588f1892138SChunming Zhou 	atomic_t			vram_lost_counter;
158997b2e202SAlex Deucher 
159095844d20SMarek Olšák 	/* data for buffer migration throttling */
159195844d20SMarek Olšák 	struct {
159295844d20SMarek Olšák 		spinlock_t		lock;
159395844d20SMarek Olšák 		s64			last_update_us;
159495844d20SMarek Olšák 		s64			accum_us; /* accumulated microseconds */
159500f06b24SJohn Brooks 		s64			accum_us_vis; /* for visible VRAM */
159695844d20SMarek Olšák 		u32			log2_max_MBps;
159795844d20SMarek Olšák 	} mm_stats;
159895844d20SMarek Olšák 
159997b2e202SAlex Deucher 	/* display */
16009accf2fdSEmily Deng 	bool				enable_virtual_display;
160197b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
16024562236bSHarry Wentland 	/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
160397b2e202SAlex Deucher 	struct work_struct		hotplug_work;
160497b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
160597b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
160697b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
160797b2e202SAlex Deucher 
160897b2e202SAlex Deucher 	/* rings */
160976bf0db5SChristian König 	u64				fence_context;
161097b2e202SAlex Deucher 	unsigned			num_rings;
161197b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
161297b2e202SAlex Deucher 	bool				ib_pool_ready;
161397b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
161497b2e202SAlex Deucher 
161597b2e202SAlex Deucher 	/* interrupts */
161697b2e202SAlex Deucher 	struct amdgpu_irq		irq;
161797b2e202SAlex Deucher 
16181f7371b2SAlex Deucher 	/* powerplay */
16191f7371b2SAlex Deucher 	struct amd_powerplay		powerplay;
1620f3898ea1SEric Huang 	bool				pp_force_state_enabled;
16211f7371b2SAlex Deucher 
162297b2e202SAlex Deucher 	/* dpm */
162397b2e202SAlex Deucher 	struct amdgpu_pm		pm;
162497b2e202SAlex Deucher 	u32				cg_flags;
162597b2e202SAlex Deucher 	u32				pg_flags;
162697b2e202SAlex Deucher 
162797b2e202SAlex Deucher 	/* amdgpu smumgr */
162897b2e202SAlex Deucher 	struct amdgpu_smumgr smu;
162997b2e202SAlex Deucher 
163097b2e202SAlex Deucher 	/* gfx */
163197b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
163297b2e202SAlex Deucher 
163397b2e202SAlex Deucher 	/* sdma */
1634c113ea1cSAlex Deucher 	struct amdgpu_sdma		sdma;
163597b2e202SAlex Deucher 
163697b2e202SAlex Deucher 	/* uvd */
163797b2e202SAlex Deucher 	struct amdgpu_uvd		uvd;
163897b2e202SAlex Deucher 
163997b2e202SAlex Deucher 	/* vce */
164097b2e202SAlex Deucher 	struct amdgpu_vce		vce;
164195d0906fSLeo Liu 
164295d0906fSLeo Liu 	/* vcn */
164395d0906fSLeo Liu 	struct amdgpu_vcn		vcn;
164497b2e202SAlex Deucher 
164597b2e202SAlex Deucher 	/* firmwares */
164697b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
164797b2e202SAlex Deucher 
16480e5ca0d1SHuang Rui 	/* PSP */
16490e5ca0d1SHuang Rui 	struct psp_context		psp;
16500e5ca0d1SHuang Rui 
165197b2e202SAlex Deucher 	/* GDS */
165297b2e202SAlex Deucher 	struct amdgpu_gds		gds;
165397b2e202SAlex Deucher 
16544562236bSHarry Wentland 	/* display related functionality */
16554562236bSHarry Wentland 	struct amdgpu_display_manager dm;
16564562236bSHarry Wentland 
1657a1255107SAlex Deucher 	struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
165897b2e202SAlex Deucher 	int				num_ip_blocks;
165997b2e202SAlex Deucher 	struct mutex	mn_lock;
166097b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
166197b2e202SAlex Deucher 
166297b2e202SAlex Deucher 	/* tracking pinned memory */
166397b2e202SAlex Deucher 	u64 vram_pin_size;
1664e131b914SChunming Zhou 	u64 invisible_pin_size;
166597b2e202SAlex Deucher 	u64 gart_pin_size;
1666130e0371SOded Gabbay 
1667130e0371SOded Gabbay 	/* amdkfd interface */
1668130e0371SOded Gabbay 	struct kfd_dev          *kfd;
166923ca0e4eSChunming Zhou 
16704522824cSShaoyun Liu 	/* soc15 register offset based on ip, instance and  segment */
16714522824cSShaoyun Liu 	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
16724522824cSShaoyun Liu 
1673946a4d5bSShaoyun Liu 	const struct amdgpu_nbio_funcs	*nbio_funcs;
1674946a4d5bSShaoyun Liu 
16752dc80b00SShirish S 	/* delayed work_func for deferring clockgating during resume */
16762dc80b00SShirish S 	struct delayed_work     late_init_work;
16772dc80b00SShirish S 
16785a5099cbSXiangliang Yu 	struct amdgpu_virt	virt;
1679a05502e5SHorace Chen 	/* firmware VRAM reservation */
1680a05502e5SHorace Chen 	struct amdgpu_fw_vram_usage fw_vram_usage;
16810c4e7fa5SChunming Zhou 
16820c4e7fa5SChunming Zhou 	/* link all shadow bo */
16830c4e7fa5SChunming Zhou 	struct list_head                shadow_list;
16840c4e7fa5SChunming Zhou 	struct mutex                    shadow_list_lock;
1685795f2813SAndres Rodriguez 	/* keep an lru list of rings by HW IP */
1686795f2813SAndres Rodriguez 	struct list_head		ring_lru_list;
1687795f2813SAndres Rodriguez 	spinlock_t			ring_lru_list_lock;
16885c1354bdSChunming Zhou 
1689c836fec5SJim Qu 	/* record hw reset is performed */
1690c836fec5SJim Qu 	bool has_hw_reset;
16910c49e0b8SChunming Zhou 	u8				reset_magic[AMDGPU_RESET_MAGIC_NUM];
1692c836fec5SJim Qu 
169347ed4e1cSKen Wang 	/* record last mm index being written through WREG32*/
169447ed4e1cSKen Wang 	unsigned long last_mm_index;
169513a752e3SMonk Liu 	bool                            in_gpu_reset;
169613a752e3SMonk Liu 	struct mutex  lock_reset;
169797b2e202SAlex Deucher };
169897b2e202SAlex Deucher 
1699a7d64de6SChristian König static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1700a7d64de6SChristian König {
1701a7d64de6SChristian König 	return container_of(bdev, struct amdgpu_device, mman.bdev);
1702a7d64de6SChristian König }
1703a7d64de6SChristian König 
170497b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
170597b2e202SAlex Deucher 		       struct drm_device *ddev,
170697b2e202SAlex Deucher 		       struct pci_dev *pdev,
170797b2e202SAlex Deucher 		       uint32_t flags);
170897b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
170997b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
171097b2e202SAlex Deucher 
171197b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
171215d72fd7SMonk Liu 			uint32_t acc_flags);
171397b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
171415d72fd7SMonk Liu 		    uint32_t acc_flags);
171597b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
171697b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
171797b2e202SAlex Deucher 
171897b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
171997b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1720832be404SKen Wang u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1721832be404SKen Wang void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
172297b2e202SAlex Deucher 
17234562236bSHarry Wentland bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
17244562236bSHarry Wentland bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
17254562236bSHarry Wentland 
172697b2e202SAlex Deucher /*
172797b2e202SAlex Deucher  * Registers read & write functions.
172897b2e202SAlex Deucher  */
172915d72fd7SMonk Liu 
173015d72fd7SMonk Liu #define AMDGPU_REGS_IDX       (1<<0)
173115d72fd7SMonk Liu #define AMDGPU_REGS_NO_KIQ    (1<<1)
173215d72fd7SMonk Liu 
173315d72fd7SMonk Liu #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
173415d72fd7SMonk Liu #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
173515d72fd7SMonk Liu 
173615d72fd7SMonk Liu #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
173715d72fd7SMonk Liu #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
173815d72fd7SMonk Liu #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
173915d72fd7SMonk Liu #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
174015d72fd7SMonk Liu #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
174197b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
174297b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
174397b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
174497b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
174536b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
174636b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
174797b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
174897b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
174997b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
175097b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
175197b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
175297b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
1753ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1754ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
175516abb5d2SEvan Quan #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
175616abb5d2SEvan Quan #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
175797b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
175897b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
175997b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
176097b2e202SAlex Deucher 	do {							\
176197b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
176297b2e202SAlex Deucher 		tmp_ &= (mask);					\
176397b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
176497b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
176597b2e202SAlex Deucher 	} while (0)
176697b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
176797b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
176897b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
176997b2e202SAlex Deucher 	do {							\
177097b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
177197b2e202SAlex Deucher 		tmp_ &= (mask);					\
177297b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
177397b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
177497b2e202SAlex Deucher 	} while (0)
177597b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
177697b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
177797b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
177897b2e202SAlex Deucher 
177997b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
178097b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1781832be404SKen Wang #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1782832be404SKen Wang #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
178397b2e202SAlex Deucher 
178497b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
178597b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
178697b2e202SAlex Deucher 
178797b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
178897b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
178997b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
179097b2e202SAlex Deucher 
179197b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
179297b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
179397b2e202SAlex Deucher 
179461cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val)	\
179561cb8cefSTom St Denis 	WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
179661cb8cefSTom St Denis 
1797ccaf3574STom St Denis #define WREG32_FIELD_OFFSET(reg, offset, field, val)	\
1798ccaf3574STom St Denis 	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1799ccaf3574STom St Denis 
180097b2e202SAlex Deucher /*
180197b2e202SAlex Deucher  * BIOS helpers.
180297b2e202SAlex Deucher  */
180397b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
180497b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
180597b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
180697b2e202SAlex Deucher 
1807c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance *
1808c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
18094b2f7e2cSJammy Zhou {
18104b2f7e2cSJammy Zhou 	struct amdgpu_device *adev = ring->adev;
18114b2f7e2cSJammy Zhou 	int i;
18124b2f7e2cSJammy Zhou 
1813c113ea1cSAlex Deucher 	for (i = 0; i < adev->sdma.num_instances; i++)
1814c113ea1cSAlex Deucher 		if (&adev->sdma.instance[i].ring == ring)
18154b2f7e2cSJammy Zhou 			break;
18164b2f7e2cSJammy Zhou 
18174b2f7e2cSJammy Zhou 	if (i < AMDGPU_MAX_SDMA_INSTANCES)
1818c113ea1cSAlex Deucher 		return &adev->sdma.instance[i];
18194b2f7e2cSJammy Zhou 	else
18204b2f7e2cSJammy Zhou 		return NULL;
18214b2f7e2cSJammy Zhou }
18224b2f7e2cSJammy Zhou 
182397b2e202SAlex Deucher /*
182497b2e202SAlex Deucher  * ASICs macro.
182597b2e202SAlex Deucher  */
182697b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
182797b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
182897b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
182997b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
183097b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1831841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1832841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1833841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
183497b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
18357946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
183697b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1837bbf282d8SAlex Deucher #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
183897b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
183997b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
18403de676d8SChristian König #define amdgpu_gart_get_vm_pde(adev, level, dst, flags) (adev)->gart.gart_funcs->get_vm_pde((adev), (level), (dst), (flags))
184197b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
1842de9ea7bdSChristian König #define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
184397b2e202SAlex Deucher #define amdgpu_vm_set_pte_pde(adev, ib, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->set_pte_pde((ib), (pe), (addr), (count), (incr), (flags)))
18445463545bSAlex Xie #define amdgpu_vm_get_pte_flags(adev, flags) (adev)->gart.gart_funcs->get_vm_pte_flags((adev),(flags))
184597b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
184697b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
1847bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
184897b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
184997b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
185097b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
1851d88bf583SChristian König #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
1852b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
185397b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
1854890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
185597b2e202SAlex Deucher #define amdgpu_ring_emit_gds_switch(r, v, db, ds, wb, ws, ab, as) (r)->funcs->emit_gds_switch((r), (v), (db), (ds), (wb), (ws), (ab), (as))
1856d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
185711afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
1858c2167a65SMonk Liu #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
1859753ad49cSMonk Liu #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
1860b6091c12SXiangliang Yu #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
1861b6091c12SXiangliang Yu #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
18623b4d68e9SMonk Liu #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
18639e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
186403ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
186503ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
186697b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
186700ecd8a2SFelix Kuehling #define amdgpu_ih_prescreen_iv(adev) (adev)->irq.ih_funcs->prescreen_iv((adev))
186897b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
186997b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
187097b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
187197b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
187297b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
187397b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
187497b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
187597b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
187697b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
187797b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
1878cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
187997b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
188097b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
188197b2e202SAlex Deucher #define amdgpu_display_add_connector(adev, ci, sd, ct, ib, coi, h, r) (adev)->mode_info.funcs->add_connector((adev), (ci), (sd), (ct), (ib), (coi), (h), (r))
1882c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b))
18836e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
1884b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
18859559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
188697b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
18870e5ca0d1SHuang Rui #define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
188897b2e202SAlex Deucher 
188997b2e202SAlex Deucher /* Common functions */
18905f152b5eSAlex Deucher int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
18915f152b5eSAlex Deucher 			      struct amdgpu_job* job, bool force);
18928111c387SAlex Deucher void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
189339c640c0SAlex Deucher bool amdgpu_device_need_post(struct amdgpu_device *adev);
189497b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev);
1895d5fc5e82SChunming Zhou 
189600f06b24SJohn Brooks void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
189700f06b24SJohn Brooks 				  u64 num_vis_bytes);
1898765e7fbfSChristian König void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
189997b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
19002543e28aSAlex Deucher void amdgpu_device_vram_location(struct amdgpu_device *adev,
19012543e28aSAlex Deucher 				 struct amdgpu_mc *mc, u64 base);
19022543e28aSAlex Deucher void amdgpu_device_gart_location(struct amdgpu_device *adev,
19032543e28aSAlex Deucher 				 struct amdgpu_mc *mc);
1904d6895ad3SChristian König int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
190597b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
19069f31a0b0SBaoyou Xie int amdgpu_ttm_init(struct amdgpu_device *adev);
19079f31a0b0SBaoyou Xie void amdgpu_ttm_fini(struct amdgpu_device *adev);
19089c3f2b54SAlex Deucher void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
190997b2e202SAlex Deucher 					     const u32 *registers,
191097b2e202SAlex Deucher 					     const u32 array_size);
191197b2e202SAlex Deucher 
191297b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
191397b2e202SAlex Deucher /* atpx handler */
191497b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
191597b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
191697b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
1917a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void);
19182f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void);
1919efc83cf4SAlex Deucher bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1920714f88e0SAlex Xie bool amdgpu_has_atpx(void);
192197b2e202SAlex Deucher #else
192297b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
192397b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
1924a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
19252f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
1926efc83cf4SAlex Deucher static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
1927714f88e0SAlex Xie static inline bool amdgpu_has_atpx(void) { return false; }
192897b2e202SAlex Deucher #endif
192997b2e202SAlex Deucher 
193097b2e202SAlex Deucher /*
193197b2e202SAlex Deucher  * KMS
193297b2e202SAlex Deucher  */
193397b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1934f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl;
193597b2e202SAlex Deucher 
193697b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
193711b3c20bSGabriel Krisman Bertazi void amdgpu_driver_unload_kms(struct drm_device *dev);
193897b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
193997b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
194097b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
194197b2e202SAlex Deucher 				 struct drm_file *file_priv);
1942cdd61df6SAlex Deucher int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
1943810ddc3aSAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1944810ddc3aSAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
194588e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
194688e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
194788e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
194897b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
194997b2e202SAlex Deucher 			     unsigned long arg);
195097b2e202SAlex Deucher 
195197b2e202SAlex Deucher /*
195297b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
195397b2e202SAlex Deucher  */
195497b2e202SAlex Deucher struct amdgpu_afmt_acr {
195597b2e202SAlex Deucher 	u32 clock;
195697b2e202SAlex Deucher 
195797b2e202SAlex Deucher 	int n_32khz;
195897b2e202SAlex Deucher 	int cts_32khz;
195997b2e202SAlex Deucher 
196097b2e202SAlex Deucher 	int n_44_1khz;
196197b2e202SAlex Deucher 	int cts_44_1khz;
196297b2e202SAlex Deucher 
196397b2e202SAlex Deucher 	int n_48khz;
196497b2e202SAlex Deucher 	int cts_48khz;
196597b2e202SAlex Deucher 
196697b2e202SAlex Deucher };
196797b2e202SAlex Deucher 
196897b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
196997b2e202SAlex Deucher 
197097b2e202SAlex Deucher /* amdgpu_acpi.c */
197197b2e202SAlex Deucher #if defined(CONFIG_ACPI)
197297b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
197397b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
197497b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
197597b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
197697b2e202SAlex Deucher 						u8 perf_req, bool advertise);
197797b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
197897b2e202SAlex Deucher #else
197997b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
198097b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
198197b2e202SAlex Deucher #endif
198297b2e202SAlex Deucher 
19839cca0b8eSChristian König int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
19849cca0b8eSChristian König 			   uint64_t addr, struct amdgpu_bo **bo,
19859cca0b8eSChristian König 			   struct amdgpu_bo_va_mapping **mapping);
198697b2e202SAlex Deucher 
19874562236bSHarry Wentland #if defined(CONFIG_DRM_AMD_DC)
19884562236bSHarry Wentland int amdgpu_dm_display_resume(struct amdgpu_device *adev );
19894562236bSHarry Wentland #else
19904562236bSHarry Wentland static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
19914562236bSHarry Wentland #endif
19924562236bSHarry Wentland 
199397b2e202SAlex Deucher #include "amdgpu_object.h"
199497b2e202SAlex Deucher #endif
1995