xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision 5a4633c4)
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"
71770d13b1SChristian König #include "amdgpu_gmc.h"
724562236bSHarry Wentland #include "amdgpu_dm.h"
73ceeb50edSMonk Liu #include "amdgpu_virt.h"
743490bdb5SChristian König #include "amdgpu_gart.h"
7575758255SAlex Deucher #include "amdgpu_debugfs.h"
76c79563a3SRex Zhu 
7797b2e202SAlex Deucher /*
7897b2e202SAlex Deucher  * Modules parameters.
7997b2e202SAlex Deucher  */
8097b2e202SAlex Deucher extern int amdgpu_modeset;
8197b2e202SAlex Deucher extern int amdgpu_vram_limit;
82218b5dcdSJohn Brooks extern int amdgpu_vis_vram_limit;
8383e74db6SAlex Deucher extern int amdgpu_gart_size;
8436d38372SChristian König extern int amdgpu_gtt_size;
8595844d20SMarek Olšák extern int amdgpu_moverate;
8697b2e202SAlex Deucher extern int amdgpu_benchmarking;
8797b2e202SAlex Deucher extern int amdgpu_testing;
8897b2e202SAlex Deucher extern int amdgpu_audio;
8997b2e202SAlex Deucher extern int amdgpu_disp_priority;
9097b2e202SAlex Deucher extern int amdgpu_hw_i2c;
9197b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
9297b2e202SAlex Deucher extern int amdgpu_msi;
9397b2e202SAlex Deucher extern int amdgpu_lockup_timeout;
9497b2e202SAlex Deucher extern int amdgpu_dpm;
95e635ee07SHuang Rui extern int amdgpu_fw_load_type;
9697b2e202SAlex Deucher extern int amdgpu_aspm;
9797b2e202SAlex Deucher extern int amdgpu_runtime_pm;
980b693f0bSRex Zhu extern uint amdgpu_ip_block_mask;
9997b2e202SAlex Deucher extern int amdgpu_bapm;
10097b2e202SAlex Deucher extern int amdgpu_deep_color;
10197b2e202SAlex Deucher extern int amdgpu_vm_size;
10297b2e202SAlex Deucher extern int amdgpu_vm_block_size;
103d07f14beSRoger He extern int amdgpu_vm_fragment_size;
104d9c13156SChristian König extern int amdgpu_vm_fault_stop;
105b495bd3aSChristian König extern int amdgpu_vm_debug;
1069a4b7d4cSHarish Kasiviswanathan extern int amdgpu_vm_update_mode;
1074562236bSHarry Wentland extern int amdgpu_dc;
10802e749dcSHarry Wentland extern int amdgpu_dc_log;
1091333f723SJammy Zhou extern int amdgpu_sched_jobs;
1104afcb303SJammy Zhou extern int amdgpu_sched_hw_submission;
1113ca67300SRex Zhu extern int amdgpu_no_evict;
1123ca67300SRex Zhu extern int amdgpu_direct_gma_size;
1130b693f0bSRex Zhu extern uint amdgpu_pcie_gen_cap;
1140b693f0bSRex Zhu extern uint amdgpu_pcie_lane_cap;
1150b693f0bSRex Zhu extern uint amdgpu_cg_mask;
1160b693f0bSRex Zhu extern uint amdgpu_pg_mask;
1170b693f0bSRex Zhu extern uint amdgpu_sdma_phase_quantum;
1186f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu;
1199accf2fdSEmily Deng extern char *amdgpu_virtual_display;
1200b693f0bSRex Zhu extern uint amdgpu_pp_feature_mask;
1216a7f76e7SChristian König extern int amdgpu_vram_page_split;
122bce23e00SAlex Deucher extern int amdgpu_ngg;
123bce23e00SAlex Deucher extern int amdgpu_prim_buf_per_se;
124bce23e00SAlex Deucher extern int amdgpu_pos_buf_per_se;
125bce23e00SAlex Deucher extern int amdgpu_cntl_sb_buf_per_se;
126bce23e00SAlex Deucher extern int amdgpu_param_buf_per_se;
12765781c78SMonk Liu extern int amdgpu_job_hang_limit;
128e8835e0eSHawking Zhang extern int amdgpu_lbpw;
1294a75aefeSAndres Rodriguez extern int amdgpu_compute_multipipe;
130dcebf026SAndrey Grodzovsky extern int amdgpu_gpu_recovery;
13197b2e202SAlex Deucher 
1326dd13096SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_SI
1336dd13096SFelix Kuehling extern int amdgpu_si_support;
1346dd13096SFelix Kuehling #endif
1357df28986SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_CIK
1367df28986SFelix Kuehling extern int amdgpu_cik_support;
1377df28986SFelix Kuehling #endif
13897b2e202SAlex Deucher 
13955ed8cafSChunming Zhou #define AMDGPU_DEFAULT_GTT_SIZE_MB		3072ULL /* 3GB by default */
1404b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
14197b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
14297b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
14397b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
14497b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
14597b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
14697b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
147a5bde2f9SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			16
14897b2e202SAlex Deucher 
14936f523a7SJammy Zhou /* max number of IP instances */
15036f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES		2
15136f523a7SJammy Zhou 
15297b2e202SAlex Deucher /* hard reset data */
15397b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
15497b2e202SAlex Deucher 
15597b2e202SAlex Deucher /* reset flags */
15697b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
15797b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
15897b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
15997b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
16097b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
16197b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
16297b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
16397b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
16497b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
16597b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
16697b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
16797b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
16897b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
16997b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
17097b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
17197b2e202SAlex Deucher 
17297b2e202SAlex Deucher /* GFX current status */
17397b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
17497b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE			0x00000001L
17597b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
17697b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
17797b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
17897b2e202SAlex Deucher 
17997b2e202SAlex Deucher /* max cursor sizes (in pixels) */
18097b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
18197b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
18297b2e202SAlex Deucher 
1835740682eSMonk Liu /* GPU RESET flags */
1845740682eSMonk Liu #define AMDGPU_RESET_INFO_VRAM_LOST  (1 << 0)
1855740682eSMonk Liu #define AMDGPU_RESET_INFO_FULLRESET  (1 << 1)
1865740682eSMonk Liu 
18797b2e202SAlex Deucher struct amdgpu_device;
18897b2e202SAlex Deucher struct amdgpu_ib;
18997b2e202SAlex Deucher struct amdgpu_cs_parser;
190bb977d37SChunming Zhou struct amdgpu_job;
19197b2e202SAlex Deucher struct amdgpu_irq_src;
1920b492a4cSAlex Deucher struct amdgpu_fpriv;
1939cca0b8eSChristian König struct amdgpu_bo_va_mapping;
19497b2e202SAlex Deucher 
19597b2e202SAlex Deucher enum amdgpu_cp_irq {
19697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_GFX_EOP = 0,
19797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
19897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
19997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
20097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
20197b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
20297b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
20397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
20497b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
20597b2e202SAlex Deucher 
20697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
20797b2e202SAlex Deucher };
20897b2e202SAlex Deucher 
20997b2e202SAlex Deucher enum amdgpu_sdma_irq {
21097b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
21197b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP1,
21297b2e202SAlex Deucher 
21397b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_LAST
21497b2e202SAlex Deucher };
21597b2e202SAlex Deucher 
21697b2e202SAlex Deucher enum amdgpu_thermal_irq {
21797b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
21897b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
21997b2e202SAlex Deucher 
22097b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
22197b2e202SAlex Deucher };
22297b2e202SAlex Deucher 
2234e638ae9SXiangliang Yu enum amdgpu_kiq_irq {
2244e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
2254e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_LAST
2264e638ae9SXiangliang Yu };
2274e638ae9SXiangliang Yu 
2282990a1fcSAlex Deucher int amdgpu_device_ip_set_clockgating_state(struct amdgpu_device *adev,
2295fc3aeebSyanyang1 					   enum amd_ip_block_type block_type,
2305fc3aeebSyanyang1 					   enum amd_clockgating_state state);
2312990a1fcSAlex Deucher int amdgpu_device_ip_set_powergating_state(struct amdgpu_device *adev,
2325fc3aeebSyanyang1 					   enum amd_ip_block_type block_type,
2335fc3aeebSyanyang1 					   enum amd_powergating_state state);
2342990a1fcSAlex Deucher void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
2352990a1fcSAlex Deucher 					    u32 *flags);
2362990a1fcSAlex Deucher int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
2375dbbb60bSAlex Deucher 				   enum amd_ip_block_type block_type);
2382990a1fcSAlex Deucher bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
2395dbbb60bSAlex Deucher 			      enum amd_ip_block_type block_type);
24097b2e202SAlex Deucher 
241a1255107SAlex Deucher #define AMDGPU_MAX_IP_NUM 16
242a1255107SAlex Deucher 
243a1255107SAlex Deucher struct amdgpu_ip_block_status {
244a1255107SAlex Deucher 	bool valid;
245a1255107SAlex Deucher 	bool sw;
246a1255107SAlex Deucher 	bool hw;
247a1255107SAlex Deucher 	bool late_initialized;
248a1255107SAlex Deucher 	bool hang;
249a1255107SAlex Deucher };
250a1255107SAlex Deucher 
25197b2e202SAlex Deucher struct amdgpu_ip_block_version {
252a1255107SAlex Deucher 	const enum amd_ip_block_type type;
253a1255107SAlex Deucher 	const u32 major;
254a1255107SAlex Deucher 	const u32 minor;
255a1255107SAlex Deucher 	const u32 rev;
2565fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
25797b2e202SAlex Deucher };
25897b2e202SAlex Deucher 
259a1255107SAlex Deucher struct amdgpu_ip_block {
260a1255107SAlex Deucher 	struct amdgpu_ip_block_status status;
261a1255107SAlex Deucher 	const struct amdgpu_ip_block_version *version;
262a1255107SAlex Deucher };
263a1255107SAlex Deucher 
2642990a1fcSAlex Deucher int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
2655fc3aeebSyanyang1 				       enum amd_ip_block_type type,
26697b2e202SAlex Deucher 				       u32 major, u32 minor);
26797b2e202SAlex Deucher 
2682990a1fcSAlex Deucher struct amdgpu_ip_block *
2692990a1fcSAlex Deucher amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
2705fc3aeebSyanyang1 			      enum amd_ip_block_type type);
27197b2e202SAlex Deucher 
2722990a1fcSAlex Deucher int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
273a1255107SAlex Deucher 			       const struct amdgpu_ip_block_version *ip_block_version);
274a1255107SAlex Deucher 
27597b2e202SAlex Deucher /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
27697b2e202SAlex Deucher struct amdgpu_buffer_funcs {
27797b2e202SAlex Deucher 	/* maximum bytes in a single operation */
27897b2e202SAlex Deucher 	uint32_t	copy_max_bytes;
27997b2e202SAlex Deucher 
28097b2e202SAlex Deucher 	/* number of dw to reserve per operation */
28197b2e202SAlex Deucher 	unsigned	copy_num_dw;
28297b2e202SAlex Deucher 
28397b2e202SAlex Deucher 	/* used for buffer migration */
284c7ae72c0SChunming Zhou 	void (*emit_copy_buffer)(struct amdgpu_ib *ib,
28597b2e202SAlex Deucher 				 /* src addr in bytes */
28697b2e202SAlex Deucher 				 uint64_t src_offset,
28797b2e202SAlex Deucher 				 /* dst addr in bytes */
28897b2e202SAlex Deucher 				 uint64_t dst_offset,
28997b2e202SAlex Deucher 				 /* number of byte to transfer */
29097b2e202SAlex Deucher 				 uint32_t byte_count);
29197b2e202SAlex Deucher 
29297b2e202SAlex Deucher 	/* maximum bytes in a single operation */
29397b2e202SAlex Deucher 	uint32_t	fill_max_bytes;
29497b2e202SAlex Deucher 
29597b2e202SAlex Deucher 	/* number of dw to reserve per operation */
29697b2e202SAlex Deucher 	unsigned	fill_num_dw;
29797b2e202SAlex Deucher 
29897b2e202SAlex Deucher 	/* used for buffer clearing */
2996e7a3840SChunming Zhou 	void (*emit_fill_buffer)(struct amdgpu_ib *ib,
30097b2e202SAlex Deucher 				 /* value to write to memory */
30197b2e202SAlex Deucher 				 uint32_t src_data,
30297b2e202SAlex Deucher 				 /* dst addr in bytes */
30397b2e202SAlex Deucher 				 uint64_t dst_offset,
30497b2e202SAlex Deucher 				 /* number of byte to fill */
30597b2e202SAlex Deucher 				 uint32_t byte_count);
30697b2e202SAlex Deucher };
30797b2e202SAlex Deucher 
30897b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */
30997b2e202SAlex Deucher struct amdgpu_vm_pte_funcs {
310e6d92197SYong Zhao 	/* number of dw to reserve per operation */
311e6d92197SYong Zhao 	unsigned	copy_pte_num_dw;
312e6d92197SYong Zhao 
31397b2e202SAlex Deucher 	/* copy pte entries from GART */
31497b2e202SAlex Deucher 	void (*copy_pte)(struct amdgpu_ib *ib,
31597b2e202SAlex Deucher 			 uint64_t pe, uint64_t src,
31697b2e202SAlex Deucher 			 unsigned count);
317e6d92197SYong Zhao 
31897b2e202SAlex Deucher 	/* write pte one entry at a time with addr mapping */
319de9ea7bdSChristian König 	void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
320de9ea7bdSChristian König 			  uint64_t value, unsigned count,
321de9ea7bdSChristian König 			  uint32_t incr);
3227bdc53f9SYong Zhao 
3237bdc53f9SYong Zhao 	/* maximum nums of PTEs/PDEs in a single operation */
3247bdc53f9SYong Zhao 	uint32_t	set_max_nums_pte_pde;
3257bdc53f9SYong Zhao 
3267bdc53f9SYong Zhao 	/* number of dw to reserve per operation */
3277bdc53f9SYong Zhao 	unsigned	set_pte_pde_num_dw;
3287bdc53f9SYong Zhao 
32997b2e202SAlex Deucher 	/* for linear pte/pde updates without addr mapping */
33097b2e202SAlex Deucher 	void (*set_pte_pde)(struct amdgpu_ib *ib,
33197b2e202SAlex Deucher 			    uint64_t pe,
33297b2e202SAlex Deucher 			    uint64_t addr, unsigned count,
3336b777607SChunming Zhou 			    uint32_t incr, uint64_t flags);
33497b2e202SAlex Deucher };
33597b2e202SAlex Deucher 
33697b2e202SAlex Deucher /* provided by the ih block */
33797b2e202SAlex Deucher struct amdgpu_ih_funcs {
33897b2e202SAlex Deucher 	/* ring read/write ptr handling, called from interrupt context */
33997b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_device *adev);
34000ecd8a2SFelix Kuehling 	bool (*prescreen_iv)(struct amdgpu_device *adev);
34197b2e202SAlex Deucher 	void (*decode_iv)(struct amdgpu_device *adev,
34297b2e202SAlex Deucher 			  struct amdgpu_iv_entry *entry);
34397b2e202SAlex Deucher 	void (*set_rptr)(struct amdgpu_device *adev);
34497b2e202SAlex Deucher };
34597b2e202SAlex Deucher 
34697b2e202SAlex Deucher /*
34797b2e202SAlex Deucher  * BIOS.
34897b2e202SAlex Deucher  */
34997b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
35097b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
35197b2e202SAlex Deucher 
35297b2e202SAlex Deucher /*
35397b2e202SAlex Deucher  * Dummy page
35497b2e202SAlex Deucher  */
35597b2e202SAlex Deucher struct amdgpu_dummy_page {
35697b2e202SAlex Deucher 	struct page	*page;
35797b2e202SAlex Deucher 	dma_addr_t	addr;
35897b2e202SAlex Deucher };
35997b2e202SAlex Deucher 
36097b2e202SAlex Deucher /*
36197b2e202SAlex Deucher  * Clocks
36297b2e202SAlex Deucher  */
36397b2e202SAlex Deucher 
36497b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
36597b2e202SAlex Deucher 
36697b2e202SAlex Deucher struct amdgpu_clock {
36797b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
36897b2e202SAlex Deucher 	struct amdgpu_pll spll;
36997b2e202SAlex Deucher 	struct amdgpu_pll mpll;
37097b2e202SAlex Deucher 	/* 10 Khz units */
37197b2e202SAlex Deucher 	uint32_t default_mclk;
37297b2e202SAlex Deucher 	uint32_t default_sclk;
37397b2e202SAlex Deucher 	uint32_t default_dispclk;
37497b2e202SAlex Deucher 	uint32_t current_dispclk;
37597b2e202SAlex Deucher 	uint32_t dp_extclk;
37697b2e202SAlex Deucher 	uint32_t max_pixel_clock;
37797b2e202SAlex Deucher };
37897b2e202SAlex Deucher 
37997b2e202SAlex Deucher /*
3809124a398SChristian König  * GEM.
38197b2e202SAlex Deucher  */
38297b2e202SAlex Deucher 
3837e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX		0x3
38497b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
38597b2e202SAlex Deucher 
38697b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj);
38797b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj,
38897b2e202SAlex Deucher 				struct drm_file *file_priv);
38997b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj,
39097b2e202SAlex Deucher 				struct drm_file *file_priv);
39197b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
39297b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
3934d9c514dSChristian König struct drm_gem_object *
3944d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
39597b2e202SAlex Deucher 				 struct dma_buf_attachment *attach,
39697b2e202SAlex Deucher 				 struct sg_table *sg);
39797b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
39897b2e202SAlex Deucher 					struct drm_gem_object *gobj,
39997b2e202SAlex Deucher 					int flags);
40009052fc3SSamuel Li struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
40109052fc3SSamuel Li 					    struct dma_buf *dma_buf);
40297b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
40397b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
40497b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
40597b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
40697b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
407dfced2e4SSamuel Li int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
40897b2e202SAlex Deucher 
40997b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
41097b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
41197b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
41297b2e202SAlex Deucher  * locking.
41397b2e202SAlex Deucher  *
41497b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
41597b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
41697b2e202SAlex Deucher  * offset).
41797b2e202SAlex Deucher  *
41897b2e202SAlex Deucher  * When allocating new object we first check if there is room at
41997b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
42097b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
42197b2e202SAlex Deucher  *
42297b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
42397b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
42497b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
42597b2e202SAlex Deucher  *
42697b2e202SAlex Deucher  * Alignment can't be bigger than page size.
42797b2e202SAlex Deucher  *
42897b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
42997b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
43097b2e202SAlex Deucher  * alignment).
43197b2e202SAlex Deucher  */
4326ba60b89SChristian König 
4336ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS	32
4346ba60b89SChristian König 
43597b2e202SAlex Deucher struct amdgpu_sa_manager {
43697b2e202SAlex Deucher 	wait_queue_head_t	wq;
43797b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
43897b2e202SAlex Deucher 	struct list_head	*hole;
4396ba60b89SChristian König 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
44097b2e202SAlex Deucher 	struct list_head	olist;
44197b2e202SAlex Deucher 	unsigned		size;
44297b2e202SAlex Deucher 	uint64_t		gpu_addr;
44397b2e202SAlex Deucher 	void			*cpu_ptr;
44497b2e202SAlex Deucher 	uint32_t		domain;
44597b2e202SAlex Deucher 	uint32_t		align;
44697b2e202SAlex Deucher };
44797b2e202SAlex Deucher 
44897b2e202SAlex Deucher /* sub-allocation buffer */
44997b2e202SAlex Deucher struct amdgpu_sa_bo {
45097b2e202SAlex Deucher 	struct list_head		olist;
45197b2e202SAlex Deucher 	struct list_head		flist;
45297b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
45397b2e202SAlex Deucher 	unsigned			soffset;
45497b2e202SAlex Deucher 	unsigned			eoffset;
455f54d1867SChris Wilson 	struct dma_fence	        *fence;
45697b2e202SAlex Deucher };
45797b2e202SAlex Deucher 
45897b2e202SAlex Deucher /*
45997b2e202SAlex Deucher  * GEM objects.
46097b2e202SAlex Deucher  */
461418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev);
46297b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
46397b2e202SAlex Deucher 			     int alignment, u32 initial_domain,
46497b2e202SAlex Deucher 			     u64 flags, bool kernel,
465e1eb899bSChristian König 			     struct reservation_object *resv,
46697b2e202SAlex Deucher 			     struct drm_gem_object **obj);
46797b2e202SAlex Deucher 
46897b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv,
46997b2e202SAlex Deucher 			    struct drm_device *dev,
47097b2e202SAlex Deucher 			    struct drm_mode_create_dumb *args);
47197b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp,
47297b2e202SAlex Deucher 			  struct drm_device *dev,
47397b2e202SAlex Deucher 			  uint32_t handle, uint64_t *offset_p);
474d573de2dSRex Zhu int amdgpu_fence_slab_init(void);
475d573de2dSRex Zhu void amdgpu_fence_slab_fini(void);
47697b2e202SAlex Deucher 
47797b2e202SAlex Deucher /*
47897b2e202SAlex Deucher  * GPU doorbell structures, functions & helpers
47997b2e202SAlex Deucher  */
48097b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
48197b2e202SAlex Deucher {
48297b2e202SAlex Deucher 	AMDGPU_DOORBELL_KIQ                     = 0x000,
48397b2e202SAlex Deucher 	AMDGPU_DOORBELL_HIQ                     = 0x001,
48497b2e202SAlex Deucher 	AMDGPU_DOORBELL_DIQ                     = 0x002,
48597b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
48697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
48797b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
48897b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
48997b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
49097b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
49197b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
49297b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
49397b2e202SAlex Deucher 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
49497b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
49597b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
49697b2e202SAlex Deucher 	AMDGPU_DOORBELL_IH                      = 0x1E8,
49797b2e202SAlex Deucher 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
49897b2e202SAlex Deucher 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
49997b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT;
50097b2e202SAlex Deucher 
50197b2e202SAlex Deucher struct amdgpu_doorbell {
50297b2e202SAlex Deucher 	/* doorbell mmio */
50397b2e202SAlex Deucher 	resource_size_t		base;
50497b2e202SAlex Deucher 	resource_size_t		size;
50597b2e202SAlex Deucher 	u32 __iomem		*ptr;
50697b2e202SAlex Deucher 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
50797b2e202SAlex Deucher };
50897b2e202SAlex Deucher 
50939807b93SKen Wang /*
51039807b93SKen Wang  * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
51139807b93SKen Wang  */
51239807b93SKen Wang typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
51339807b93SKen Wang {
51439807b93SKen Wang 	/*
51539807b93SKen Wang 	 * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
51639807b93SKen Wang 	 * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
51739807b93SKen Wang 	 *  Compute related doorbells are allocated from 0x00 to 0x8a
51839807b93SKen Wang 	 */
51939807b93SKen Wang 
52039807b93SKen Wang 
52139807b93SKen Wang 	/* kernel scheduling */
52239807b93SKen Wang 	AMDGPU_DOORBELL64_KIQ                     = 0x00,
52339807b93SKen Wang 
52439807b93SKen Wang 	/* HSA interface queue and debug queue */
52539807b93SKen Wang 	AMDGPU_DOORBELL64_HIQ                     = 0x01,
52639807b93SKen Wang 	AMDGPU_DOORBELL64_DIQ                     = 0x02,
52739807b93SKen Wang 
52839807b93SKen Wang 	/* Compute engines */
52939807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING0               = 0x03,
53039807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING1               = 0x04,
53139807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING2               = 0x05,
53239807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING3               = 0x06,
53339807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING4               = 0x07,
53439807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING5               = 0x08,
53539807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING6               = 0x09,
53639807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING7               = 0x0a,
53739807b93SKen Wang 
53839807b93SKen Wang 	/* User queue doorbell range (128 doorbells) */
53939807b93SKen Wang 	AMDGPU_DOORBELL64_USERQUEUE_START         = 0x0b,
54039807b93SKen Wang 	AMDGPU_DOORBELL64_USERQUEUE_END           = 0x8a,
54139807b93SKen Wang 
54239807b93SKen Wang 	/* Graphics engine */
54339807b93SKen Wang 	AMDGPU_DOORBELL64_GFX_RING0               = 0x8b,
54439807b93SKen Wang 
54539807b93SKen Wang 	/*
54639807b93SKen Wang 	 * Other graphics doorbells can be allocated here: from 0x8c to 0xef
54739807b93SKen Wang 	 * Graphics voltage island aperture 1
54839807b93SKen Wang 	 * default non-graphics QWORD index is 0xF0 - 0xFF inclusive
54939807b93SKen Wang 	 */
55039807b93SKen Wang 
55139807b93SKen Wang 	/* sDMA engines */
55239807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_ENGINE0            = 0xF0,
55339807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0     = 0xF1,
55439807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_ENGINE1            = 0xF2,
55539807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1     = 0xF3,
55639807b93SKen Wang 
55739807b93SKen Wang 	/* Interrupt handler */
55839807b93SKen Wang 	AMDGPU_DOORBELL64_IH                      = 0xF4,  /* For legacy interrupt ring buffer */
55939807b93SKen Wang 	AMDGPU_DOORBELL64_IH_RING1                = 0xF5,  /* For page migration request log */
56039807b93SKen Wang 	AMDGPU_DOORBELL64_IH_RING2                = 0xF6,  /* For page migration translation/invalidation log */
56139807b93SKen Wang 
562e6b3ecb4SMonk Liu 	/* VCN engine use 32 bits doorbell  */
563e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN0_1                  = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
564e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN2_3                  = 0xF9,
565e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN4_5                  = 0xFA,
566e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN6_7                  = 0xFB,
567e6b3ecb4SMonk Liu 
568e6b3ecb4SMonk Liu 	/* overlap the doorbell assignment with VCN as they are  mutually exclusive
569e6b3ecb4SMonk Liu 	 * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
570e6b3ecb4SMonk Liu 	 */
5714ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING0_1             = 0xF8,
5724ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING2_3             = 0xF9,
5734ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING4_5             = 0xFA,
5744ed11d79SFrank Min 	AMDGPU_DOORBELL64_UVD_RING6_7             = 0xFB,
575e6b3ecb4SMonk Liu 
5764ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING0_1             = 0xFC,
5774ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING2_3             = 0xFD,
5784ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING4_5             = 0xFE,
5794ed11d79SFrank Min 	AMDGPU_DOORBELL64_VCE_RING6_7             = 0xFF,
58039807b93SKen Wang 
58139807b93SKen Wang 	AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
58239807b93SKen Wang 	AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
58339807b93SKen Wang } AMDGPU_DOORBELL64_ASSIGNMENT;
58439807b93SKen Wang 
58597b2e202SAlex Deucher /*
58697b2e202SAlex Deucher  * IRQS.
58797b2e202SAlex Deucher  */
58897b2e202SAlex Deucher 
58997b2e202SAlex Deucher struct amdgpu_flip_work {
590325cbba1SMichel Dänzer 	struct delayed_work		flip_work;
59197b2e202SAlex Deucher 	struct work_struct		unpin_work;
59297b2e202SAlex Deucher 	struct amdgpu_device		*adev;
59397b2e202SAlex Deucher 	int				crtc_id;
594325cbba1SMichel Dänzer 	u32				target_vblank;
59597b2e202SAlex Deucher 	uint64_t			base;
59697b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
597765e7fbfSChristian König 	struct amdgpu_bo		*old_abo;
598f54d1867SChris Wilson 	struct dma_fence		*excl;
5991ffd2652SChristian König 	unsigned			shared_count;
600f54d1867SChris Wilson 	struct dma_fence		**shared;
601f54d1867SChris Wilson 	struct dma_fence_cb		cb;
602cb9e59d7SAlex Deucher 	bool				async;
60397b2e202SAlex Deucher };
60497b2e202SAlex Deucher 
60597b2e202SAlex Deucher 
60697b2e202SAlex Deucher /*
60797b2e202SAlex Deucher  * CP & rings.
60897b2e202SAlex Deucher  */
60997b2e202SAlex Deucher 
61097b2e202SAlex Deucher struct amdgpu_ib {
61197b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
61297b2e202SAlex Deucher 	uint32_t			length_dw;
61397b2e202SAlex Deucher 	uint64_t			gpu_addr;
61497b2e202SAlex Deucher 	uint32_t			*ptr;
615de807f81SJammy Zhou 	uint32_t			flags;
61697b2e202SAlex Deucher };
61797b2e202SAlex Deucher 
6181b1f42d8SLucas Stach extern const struct drm_sched_backend_ops amdgpu_sched_ops;
619c1b69ed0SChunming Zhou 
62050838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
621c5637837SMonk Liu 		     struct amdgpu_job **job, struct amdgpu_vm *vm);
622d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
623d71518b5SChristian König 			     struct amdgpu_job **job);
624b6723c8dSMonk Liu 
625a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job);
62650838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job);
627d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
6281b1f42d8SLucas Stach 		      struct drm_sched_entity *entity, void *owner,
629f54d1867SChris Wilson 		      struct dma_fence **f);
6308b4fb00bSChristian König 
63197b2e202SAlex Deucher /*
632effd924dSAndres Rodriguez  * Queue manager
633effd924dSAndres Rodriguez  */
634effd924dSAndres Rodriguez struct amdgpu_queue_mapper {
635effd924dSAndres Rodriguez 	int 		hw_ip;
636effd924dSAndres Rodriguez 	struct mutex	lock;
637effd924dSAndres Rodriguez 	/* protected by lock */
638effd924dSAndres Rodriguez 	struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
639effd924dSAndres Rodriguez };
640effd924dSAndres Rodriguez 
641effd924dSAndres Rodriguez struct amdgpu_queue_mgr {
642effd924dSAndres Rodriguez 	struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
643effd924dSAndres Rodriguez };
644effd924dSAndres Rodriguez 
645effd924dSAndres Rodriguez int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
646effd924dSAndres Rodriguez 			  struct amdgpu_queue_mgr *mgr);
647effd924dSAndres Rodriguez int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
648effd924dSAndres Rodriguez 			  struct amdgpu_queue_mgr *mgr);
649effd924dSAndres Rodriguez int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
650effd924dSAndres Rodriguez 			 struct amdgpu_queue_mgr *mgr,
651fa7c7939SMichel Dänzer 			 u32 hw_ip, u32 instance, u32 ring,
652effd924dSAndres Rodriguez 			 struct amdgpu_ring **out_ring);
653effd924dSAndres Rodriguez 
654effd924dSAndres Rodriguez /*
65597b2e202SAlex Deucher  * context related structures
65697b2e202SAlex Deucher  */
65797b2e202SAlex Deucher 
65821c16bf6SChristian König struct amdgpu_ctx_ring {
65921c16bf6SChristian König 	uint64_t		sequence;
660f54d1867SChris Wilson 	struct dma_fence	**fences;
6611b1f42d8SLucas Stach 	struct drm_sched_entity	entity;
66221c16bf6SChristian König };
66321c16bf6SChristian König 
66497b2e202SAlex Deucher struct amdgpu_ctx {
66597b2e202SAlex Deucher 	struct kref		refcount;
6669cb7e5a9SChunming Zhou 	struct amdgpu_device    *adev;
667effd924dSAndres Rodriguez 	struct amdgpu_queue_mgr queue_mgr;
668d94aed5aSMarek Olšák 	unsigned		reset_counter;
669668ca1b4SMonk Liu 	unsigned        reset_counter_query;
670e55f2b64SChristian König 	uint32_t		vram_lost_counter;
67121c16bf6SChristian König 	spinlock_t		ring_lock;
672f54d1867SChris Wilson 	struct dma_fence	**fences;
67321c16bf6SChristian König 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
674753ad49cSMonk Liu 	bool			preamble_presented;
6751b1f42d8SLucas Stach 	enum drm_sched_priority init_priority;
6761b1f42d8SLucas Stach 	enum drm_sched_priority override_priority;
6770ae94444SAndrey Grodzovsky 	struct mutex            lock;
6781102900dSMonk Liu 	atomic_t	guilty;
67997b2e202SAlex Deucher };
68097b2e202SAlex Deucher 
68197b2e202SAlex Deucher struct amdgpu_ctx_mgr {
68297b2e202SAlex Deucher 	struct amdgpu_device	*adev;
6830147ee0fSMarek Olšák 	struct mutex		lock;
6840b492a4cSAlex Deucher 	/* protected by lock */
6850b492a4cSAlex Deucher 	struct idr		ctx_handles;
68697b2e202SAlex Deucher };
68797b2e202SAlex Deucher 
6880b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
6890b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
6900b492a4cSAlex Deucher 
691eb01abc7SMonk Liu int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
692eb01abc7SMonk Liu 			      struct dma_fence *fence, uint64_t *seq);
693f54d1867SChris Wilson struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
69421c16bf6SChristian König 				   struct amdgpu_ring *ring, uint64_t seq);
695c23be4aeSAndres Rodriguez void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
6961b1f42d8SLucas Stach 				  enum drm_sched_priority priority);
69721c16bf6SChristian König 
6980b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
6990b492a4cSAlex Deucher 		     struct drm_file *filp);
7000b492a4cSAlex Deucher 
7010ae94444SAndrey Grodzovsky int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id);
7020ae94444SAndrey Grodzovsky 
703efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
704efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
7050b492a4cSAlex Deucher 
7060ae94444SAndrey Grodzovsky 
70797b2e202SAlex Deucher /*
70897b2e202SAlex Deucher  * file private structure
70997b2e202SAlex Deucher  */
71097b2e202SAlex Deucher 
71197b2e202SAlex Deucher struct amdgpu_fpriv {
71297b2e202SAlex Deucher 	struct amdgpu_vm	vm;
713b85891bdSJunwei Zhang 	struct amdgpu_bo_va	*prt_va;
7140f4b3c68SChristian König 	struct amdgpu_bo_va	*csa_va;
71597b2e202SAlex Deucher 	struct mutex		bo_list_lock;
71697b2e202SAlex Deucher 	struct idr		bo_list_handles;
71797b2e202SAlex Deucher 	struct amdgpu_ctx_mgr	ctx_mgr;
71897b2e202SAlex Deucher };
71997b2e202SAlex Deucher 
72097b2e202SAlex Deucher /*
72197b2e202SAlex Deucher  * residency list
72297b2e202SAlex Deucher  */
7239124a398SChristian König struct amdgpu_bo_list_entry {
7249124a398SChristian König 	struct amdgpu_bo		*robj;
7259124a398SChristian König 	struct ttm_validate_buffer	tv;
7269124a398SChristian König 	struct amdgpu_bo_va		*bo_va;
7279124a398SChristian König 	uint32_t			priority;
7289124a398SChristian König 	struct page			**user_pages;
7299124a398SChristian König 	int				user_invalidated;
7309124a398SChristian König };
73197b2e202SAlex Deucher 
73297b2e202SAlex Deucher struct amdgpu_bo_list {
73397b2e202SAlex Deucher 	struct mutex lock;
7345ac55629SAlex Xie 	struct rcu_head rhead;
7355ac55629SAlex Xie 	struct kref refcount;
73697b2e202SAlex Deucher 	struct amdgpu_bo *gds_obj;
73797b2e202SAlex Deucher 	struct amdgpu_bo *gws_obj;
73897b2e202SAlex Deucher 	struct amdgpu_bo *oa_obj;
739211dff55SChristian König 	unsigned first_userptr;
74097b2e202SAlex Deucher 	unsigned num_entries;
74197b2e202SAlex Deucher 	struct amdgpu_bo_list_entry *array;
74297b2e202SAlex Deucher };
74397b2e202SAlex Deucher 
74497b2e202SAlex Deucher struct amdgpu_bo_list *
74597b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
746636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
747636ce25cSChristian König 			     struct list_head *validated);
74897b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
74997b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
75097b2e202SAlex Deucher 
75197b2e202SAlex Deucher /*
75297b2e202SAlex Deucher  * GFX stuff
75397b2e202SAlex Deucher  */
75497b2e202SAlex Deucher #include "clearstate_defs.h"
75597b2e202SAlex Deucher 
75679e5412cSAlex Deucher struct amdgpu_rlc_funcs {
75779e5412cSAlex Deucher 	void (*enter_safe_mode)(struct amdgpu_device *adev);
75879e5412cSAlex Deucher 	void (*exit_safe_mode)(struct amdgpu_device *adev);
75979e5412cSAlex Deucher };
76079e5412cSAlex Deucher 
76197b2e202SAlex Deucher struct amdgpu_rlc {
76297b2e202SAlex Deucher 	/* for power gating */
76397b2e202SAlex Deucher 	struct amdgpu_bo	*save_restore_obj;
76497b2e202SAlex Deucher 	uint64_t		save_restore_gpu_addr;
76597b2e202SAlex Deucher 	volatile uint32_t	*sr_ptr;
76697b2e202SAlex Deucher 	const u32               *reg_list;
76797b2e202SAlex Deucher 	u32                     reg_list_size;
76897b2e202SAlex Deucher 	/* for clear state */
76997b2e202SAlex Deucher 	struct amdgpu_bo	*clear_state_obj;
77097b2e202SAlex Deucher 	uint64_t		clear_state_gpu_addr;
77197b2e202SAlex Deucher 	volatile uint32_t	*cs_ptr;
77297b2e202SAlex Deucher 	const struct cs_section_def   *cs_data;
77397b2e202SAlex Deucher 	u32                     clear_state_size;
77497b2e202SAlex Deucher 	/* for cp tables */
77597b2e202SAlex Deucher 	struct amdgpu_bo	*cp_table_obj;
77697b2e202SAlex Deucher 	uint64_t		cp_table_gpu_addr;
77797b2e202SAlex Deucher 	volatile uint32_t	*cp_table_ptr;
77897b2e202SAlex Deucher 	u32                     cp_table_size;
77979e5412cSAlex Deucher 
78079e5412cSAlex Deucher 	/* safe mode for updating CG/PG state */
78179e5412cSAlex Deucher 	bool in_safe_mode;
78279e5412cSAlex Deucher 	const struct amdgpu_rlc_funcs *funcs;
7832b6cd977SEric Huang 
7842b6cd977SEric Huang 	/* for firmware data */
7852b6cd977SEric Huang 	u32 save_and_restore_offset;
7862b6cd977SEric Huang 	u32 clear_state_descriptor_offset;
7872b6cd977SEric Huang 	u32 avail_scratch_ram_locations;
7882b6cd977SEric Huang 	u32 reg_restore_list_size;
7892b6cd977SEric Huang 	u32 reg_list_format_start;
7902b6cd977SEric Huang 	u32 reg_list_format_separate_start;
7912b6cd977SEric Huang 	u32 starting_offsets_start;
7922b6cd977SEric Huang 	u32 reg_list_format_size_bytes;
7932b6cd977SEric Huang 	u32 reg_list_size_bytes;
7942b6cd977SEric Huang 
7952b6cd977SEric Huang 	u32 *register_list_format;
7962b6cd977SEric Huang 	u32 *register_restore;
79797b2e202SAlex Deucher };
79897b2e202SAlex Deucher 
79978c16834SAndres Rodriguez #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
80078c16834SAndres Rodriguez 
80197b2e202SAlex Deucher struct amdgpu_mec {
80297b2e202SAlex Deucher 	struct amdgpu_bo	*hpd_eop_obj;
80397b2e202SAlex Deucher 	u64			hpd_eop_gpu_addr;
804b1023571SKen Wang 	struct amdgpu_bo	*mec_fw_obj;
805b1023571SKen Wang 	u64			mec_fw_gpu_addr;
80697b2e202SAlex Deucher 	u32 num_mec;
80742794b27SAndres Rodriguez 	u32 num_pipe_per_mec;
80842794b27SAndres Rodriguez 	u32 num_queue_per_pipe;
80959a82d7dSXiangliang Yu 	void			*mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
81078c16834SAndres Rodriguez 
81178c16834SAndres Rodriguez 	/* These are the resources for which amdgpu takes ownership */
81278c16834SAndres Rodriguez 	DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
81397b2e202SAlex Deucher };
81497b2e202SAlex Deucher 
8154e638ae9SXiangliang Yu struct amdgpu_kiq {
8164e638ae9SXiangliang Yu 	u64			eop_gpu_addr;
8174e638ae9SXiangliang Yu 	struct amdgpu_bo	*eop_obj;
81843ca8efaSpding 	spinlock_t              ring_lock;
8194e638ae9SXiangliang Yu 	struct amdgpu_ring	ring;
8204e638ae9SXiangliang Yu 	struct amdgpu_irq_src	irq;
8214e638ae9SXiangliang Yu };
8224e638ae9SXiangliang Yu 
82397b2e202SAlex Deucher /*
82497b2e202SAlex Deucher  * GPU scratch registers structures, functions & helpers
82597b2e202SAlex Deucher  */
82697b2e202SAlex Deucher struct amdgpu_scratch {
82797b2e202SAlex Deucher 	unsigned		num_reg;
82897b2e202SAlex Deucher 	uint32_t                reg_base;
82950261151SNils Wallménius 	uint32_t		free_mask;
83097b2e202SAlex Deucher };
83197b2e202SAlex Deucher 
83297b2e202SAlex Deucher /*
83397b2e202SAlex Deucher  * GFX configurations
83497b2e202SAlex Deucher  */
835e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SE 4
836e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SH_PER_SE 2
837e3fa7630SAlex Deucher 
838e3fa7630SAlex Deucher struct amdgpu_rb_config {
839e3fa7630SAlex Deucher 	uint32_t rb_backend_disable;
840e3fa7630SAlex Deucher 	uint32_t user_rb_backend_disable;
841e3fa7630SAlex Deucher 	uint32_t raster_config;
842e3fa7630SAlex Deucher 	uint32_t raster_config_1;
843e3fa7630SAlex Deucher };
844e3fa7630SAlex Deucher 
845d0e95758SAndrey Grodzovsky struct gb_addr_config {
846d0e95758SAndrey Grodzovsky 	uint16_t pipe_interleave_size;
847d0e95758SAndrey Grodzovsky 	uint8_t num_pipes;
848d0e95758SAndrey Grodzovsky 	uint8_t max_compress_frags;
849d0e95758SAndrey Grodzovsky 	uint8_t num_banks;
850d0e95758SAndrey Grodzovsky 	uint8_t num_se;
851d0e95758SAndrey Grodzovsky 	uint8_t num_rb_per_se;
852d0e95758SAndrey Grodzovsky };
853d0e95758SAndrey Grodzovsky 
854ea323f88SJunwei Zhang struct amdgpu_gfx_config {
85597b2e202SAlex Deucher 	unsigned max_shader_engines;
85697b2e202SAlex Deucher 	unsigned max_tile_pipes;
85797b2e202SAlex Deucher 	unsigned max_cu_per_sh;
85897b2e202SAlex Deucher 	unsigned max_sh_per_se;
85997b2e202SAlex Deucher 	unsigned max_backends_per_se;
86097b2e202SAlex Deucher 	unsigned max_texture_channel_caches;
86197b2e202SAlex Deucher 	unsigned max_gprs;
86297b2e202SAlex Deucher 	unsigned max_gs_threads;
86397b2e202SAlex Deucher 	unsigned max_hw_contexts;
86497b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_frontend;
86597b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_backend;
86697b2e202SAlex Deucher 	unsigned sc_hiz_tile_fifo_size;
86797b2e202SAlex Deucher 	unsigned sc_earlyz_tile_fifo_size;
86897b2e202SAlex Deucher 
86997b2e202SAlex Deucher 	unsigned num_tile_pipes;
87097b2e202SAlex Deucher 	unsigned backend_enable_mask;
87197b2e202SAlex Deucher 	unsigned mem_max_burst_length_bytes;
87297b2e202SAlex Deucher 	unsigned mem_row_size_in_kb;
87397b2e202SAlex Deucher 	unsigned shader_engine_tile_size;
87497b2e202SAlex Deucher 	unsigned num_gpus;
87597b2e202SAlex Deucher 	unsigned multi_gpu_tile_size;
87697b2e202SAlex Deucher 	unsigned mc_arb_ramcfg;
87797b2e202SAlex Deucher 	unsigned gb_addr_config;
8788f8e00c1SAlex Deucher 	unsigned num_rbs;
879408bfe7cSJunwei Zhang 	unsigned gs_vgt_table_depth;
880408bfe7cSJunwei Zhang 	unsigned gs_prim_buffer_depth;
88197b2e202SAlex Deucher 
88297b2e202SAlex Deucher 	uint32_t tile_mode_array[32];
88397b2e202SAlex Deucher 	uint32_t macrotile_mode_array[16];
884e3fa7630SAlex Deucher 
885d0e95758SAndrey Grodzovsky 	struct gb_addr_config gb_addr_config_fields;
886e3fa7630SAlex Deucher 	struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
887df6e2c4aSJunwei Zhang 
888df6e2c4aSJunwei Zhang 	/* gfx configure feature */
889df6e2c4aSJunwei Zhang 	uint32_t double_offchip_lds_buf;
89097b2e202SAlex Deucher };
89197b2e202SAlex Deucher 
8927dae69a2SAlex Deucher struct amdgpu_cu_info {
893ebdebf42SFlora Cui 	uint32_t simd_per_cu;
89451fd0370SHawking Zhang 	uint32_t max_waves_per_simd;
895408bfe7cSJunwei Zhang 	uint32_t wave_front_size;
89651fd0370SHawking Zhang 	uint32_t max_scratch_slots_per_cu;
89751fd0370SHawking Zhang 	uint32_t lds_size;
898dbfe85eaSFlora Cui 
899dbfe85eaSFlora Cui 	/* total active CU number */
900dbfe85eaSFlora Cui 	uint32_t number;
901dbfe85eaSFlora Cui 	uint32_t ao_cu_mask;
902dbfe85eaSFlora Cui 	uint32_t ao_cu_bitmap[4][4];
9037dae69a2SAlex Deucher 	uint32_t bitmap[4][4];
9047dae69a2SAlex Deucher };
9057dae69a2SAlex Deucher 
906b95e31fdSAlex Deucher struct amdgpu_gfx_funcs {
907b95e31fdSAlex Deucher 	/* get the gpu clock counter */
908b95e31fdSAlex Deucher 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
9099559ef5bSTom St Denis 	void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
910472259f0STom St Denis 	void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);
911c5a60ce8STom 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);
912c5a60ce8STom 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);
913b95e31fdSAlex Deucher };
914b95e31fdSAlex Deucher 
915bce23e00SAlex Deucher struct amdgpu_ngg_buf {
916bce23e00SAlex Deucher 	struct amdgpu_bo	*bo;
917bce23e00SAlex Deucher 	uint64_t		gpu_addr;
918bce23e00SAlex Deucher 	uint32_t		size;
919bce23e00SAlex Deucher 	uint32_t		bo_size;
920bce23e00SAlex Deucher };
921bce23e00SAlex Deucher 
922bce23e00SAlex Deucher enum {
923af8baf15SGuenter Roeck 	NGG_PRIM = 0,
924af8baf15SGuenter Roeck 	NGG_POS,
925af8baf15SGuenter Roeck 	NGG_CNTL,
926af8baf15SGuenter Roeck 	NGG_PARAM,
927bce23e00SAlex Deucher 	NGG_BUF_MAX
928bce23e00SAlex Deucher };
929bce23e00SAlex Deucher 
930bce23e00SAlex Deucher struct amdgpu_ngg {
931bce23e00SAlex Deucher 	struct amdgpu_ngg_buf	buf[NGG_BUF_MAX];
932bce23e00SAlex Deucher 	uint32_t		gds_reserve_addr;
933bce23e00SAlex Deucher 	uint32_t		gds_reserve_size;
934bce23e00SAlex Deucher 	bool			init;
935bce23e00SAlex Deucher };
936bce23e00SAlex Deucher 
93797b2e202SAlex Deucher struct amdgpu_gfx {
93897b2e202SAlex Deucher 	struct mutex			gpu_clock_mutex;
939ea323f88SJunwei Zhang 	struct amdgpu_gfx_config	config;
94097b2e202SAlex Deucher 	struct amdgpu_rlc		rlc;
94197b2e202SAlex Deucher 	struct amdgpu_mec		mec;
9424e638ae9SXiangliang Yu 	struct amdgpu_kiq		kiq;
94397b2e202SAlex Deucher 	struct amdgpu_scratch		scratch;
94497b2e202SAlex Deucher 	const struct firmware		*me_fw;	/* ME firmware */
94597b2e202SAlex Deucher 	uint32_t			me_fw_version;
94697b2e202SAlex Deucher 	const struct firmware		*pfp_fw; /* PFP firmware */
94797b2e202SAlex Deucher 	uint32_t			pfp_fw_version;
94897b2e202SAlex Deucher 	const struct firmware		*ce_fw;	/* CE firmware */
94997b2e202SAlex Deucher 	uint32_t			ce_fw_version;
95097b2e202SAlex Deucher 	const struct firmware		*rlc_fw; /* RLC firmware */
95197b2e202SAlex Deucher 	uint32_t			rlc_fw_version;
95297b2e202SAlex Deucher 	const struct firmware		*mec_fw; /* MEC firmware */
95397b2e202SAlex Deucher 	uint32_t			mec_fw_version;
95497b2e202SAlex Deucher 	const struct firmware		*mec2_fw; /* MEC2 firmware */
95597b2e202SAlex Deucher 	uint32_t			mec2_fw_version;
95602558a00SKen Wang 	uint32_t			me_feature_version;
95702558a00SKen Wang 	uint32_t			ce_feature_version;
95802558a00SKen Wang 	uint32_t			pfp_feature_version;
959351643d7SJammy Zhou 	uint32_t			rlc_feature_version;
960351643d7SJammy Zhou 	uint32_t			mec_feature_version;
961351643d7SJammy Zhou 	uint32_t			mec2_feature_version;
96297b2e202SAlex Deucher 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
96397b2e202SAlex Deucher 	unsigned			num_gfx_rings;
96497b2e202SAlex Deucher 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
96597b2e202SAlex Deucher 	unsigned			num_compute_rings;
96697b2e202SAlex Deucher 	struct amdgpu_irq_src		eop_irq;
96797b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_reg_irq;
96897b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_inst_irq;
96997b2e202SAlex Deucher 	/* gfx status */
97097b2e202SAlex Deucher 	uint32_t			gfx_current_status;
971a101a899SKen Wang 	/* ce ram size*/
972a101a899SKen Wang 	unsigned			ce_ram_size;
9737dae69a2SAlex Deucher 	struct amdgpu_cu_info		cu_info;
974b95e31fdSAlex Deucher 	const struct amdgpu_gfx_funcs	*funcs;
9753d7c6384SChunming Zhou 
9763d7c6384SChunming Zhou 	/* reset mask */
9773d7c6384SChunming Zhou 	uint32_t                        grbm_soft_reset;
9783d7c6384SChunming Zhou 	uint32_t                        srbm_soft_reset;
979b4e40676SDavid Panariti 	/* s3/s4 mask */
980b4e40676SDavid Panariti 	bool                            in_suspend;
981bce23e00SAlex Deucher 	/* NGG */
982bce23e00SAlex Deucher 	struct amdgpu_ngg		ngg;
983b8866c26SAndres Rodriguez 
984b8866c26SAndres Rodriguez 	/* pipe reservation */
985b8866c26SAndres Rodriguez 	struct mutex			pipe_reserve_mutex;
986b8866c26SAndres Rodriguez 	DECLARE_BITMAP			(pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
98797b2e202SAlex Deucher };
98897b2e202SAlex Deucher 
989b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
99097b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
9914d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
992f54d1867SChris Wilson 		    struct dma_fence *f);
993b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
99450ddc75eSJunwei Zhang 		       struct amdgpu_ib *ibs, struct amdgpu_job *job,
99550ddc75eSJunwei Zhang 		       struct dma_fence **f);
99697b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
99797b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
99897b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
99997b2e202SAlex Deucher 
100097b2e202SAlex Deucher /*
100197b2e202SAlex Deucher  * CS.
100297b2e202SAlex Deucher  */
100397b2e202SAlex Deucher struct amdgpu_cs_chunk {
100497b2e202SAlex Deucher 	uint32_t		chunk_id;
100597b2e202SAlex Deucher 	uint32_t		length_dw;
1006758ac17fSChristian König 	void			*kdata;
100797b2e202SAlex Deucher };
100897b2e202SAlex Deucher 
100997b2e202SAlex Deucher struct amdgpu_cs_parser {
101097b2e202SAlex Deucher 	struct amdgpu_device	*adev;
101197b2e202SAlex Deucher 	struct drm_file		*filp;
10123cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
1013c3cca41eSChristian König 
101497b2e202SAlex Deucher 	/* chunks */
101597b2e202SAlex Deucher 	unsigned		nchunks;
101697b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
1017c3cca41eSChristian König 
101850838c8cSChristian König 	/* scheduler job object */
101950838c8cSChristian König 	struct amdgpu_job	*job;
1020c3cca41eSChristian König 
1021c3cca41eSChristian König 	/* buffer objects */
1022c3cca41eSChristian König 	struct ww_acquire_ctx		ticket;
1023c3cca41eSChristian König 	struct amdgpu_bo_list		*bo_list;
10243fe89771SChristian König 	struct amdgpu_mn		*mn;
102556467ebfSChristian König 	struct amdgpu_bo_list_entry	vm_pd;
102697b2e202SAlex Deucher 	struct list_head		validated;
1027f54d1867SChris Wilson 	struct dma_fence		*fence;
1028f69f90a1SChristian König 	uint64_t			bytes_moved_threshold;
102900f06b24SJohn Brooks 	uint64_t			bytes_moved_vis_threshold;
1030f69f90a1SChristian König 	uint64_t			bytes_moved;
103100f06b24SJohn Brooks 	uint64_t			bytes_moved_vis;
1032662bfa61SChristian König 	struct amdgpu_bo_list_entry	*evictable;
103397b2e202SAlex Deucher 
103497b2e202SAlex Deucher 	/* user fence */
103591acbeb6SChristian König 	struct amdgpu_bo_list_entry	uf_entry;
1036660e8558SDave Airlie 
1037660e8558SDave Airlie 	unsigned num_post_dep_syncobjs;
1038660e8558SDave Airlie 	struct drm_syncobj **post_dep_syncobjs;
103997b2e202SAlex Deucher };
104097b2e202SAlex Deucher 
1041753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT          (1 << 0) /* bit set means command submit involves a preamble IB */
1042753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST    (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1043753ad49cSMonk Liu #define AMDGPU_HAVE_CTX_SWITCH              (1 << 2) /* bit set means context switch occured */
1044753ad49cSMonk Liu 
1045bb977d37SChunming Zhou struct amdgpu_job {
10461b1f42d8SLucas Stach 	struct drm_sched_job    base;
1047bb977d37SChunming Zhou 	struct amdgpu_device	*adev;
1048c5637837SMonk Liu 	struct amdgpu_vm	*vm;
1049b07c60c0SChristian König 	struct amdgpu_ring	*ring;
1050e86f9ceeSChristian König 	struct amdgpu_sync	sync;
1051df83d1ebSChunming Zhou 	struct amdgpu_sync	sched_sync;
1052bb977d37SChunming Zhou 	struct amdgpu_ib	*ibs;
1053f54d1867SChris Wilson 	struct dma_fence	*fence; /* the hw fence */
1054753ad49cSMonk Liu 	uint32_t		preamble_status;
1055bb977d37SChunming Zhou 	uint32_t		num_ibs;
1056e2840221SChristian König 	void			*owner;
10573aecd24cSMonk Liu 	uint64_t		fence_ctx; /* the fence_context this job uses */
1058fd53be30SChunming Zhou 	bool                    vm_needs_flush;
1059d88bf583SChristian König 	uint64_t		vm_pd_addr;
10605a4633c4SChristian König 	unsigned		vmid;
10615a4633c4SChristian König 	unsigned		pasid;
1062d88bf583SChristian König 	uint32_t		gds_base, gds_size;
1063d88bf583SChristian König 	uint32_t		gws_base, gws_size;
1064d88bf583SChristian König 	uint32_t		oa_base, oa_size;
106514e47f93SChristian König 	uint32_t		vram_lost_counter;
1066758ac17fSChristian König 
1067758ac17fSChristian König 	/* user fence handling */
1068b5f5acbcSChristian König 	uint64_t		uf_addr;
1069758ac17fSChristian König 	uint64_t		uf_sequence;
1070758ac17fSChristian König 
1071bb977d37SChunming Zhou };
1072a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job)		\
1073a6db8a33SJunwei Zhang 		container_of((sched_job), struct amdgpu_job, base)
1074bb977d37SChunming Zhou 
10757270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
10767270f839SChristian König 				      uint32_t ib_idx, int idx)
107797b2e202SAlex Deucher {
107850838c8cSChristian König 	return p->job->ibs[ib_idx].ptr[idx];
107997b2e202SAlex Deucher }
108097b2e202SAlex Deucher 
10817270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
10827270f839SChristian König 				       uint32_t ib_idx, int idx,
10837270f839SChristian König 				       uint32_t value)
10847270f839SChristian König {
108550838c8cSChristian König 	p->job->ibs[ib_idx].ptr[idx] = value;
10867270f839SChristian König }
10877270f839SChristian König 
108897b2e202SAlex Deucher /*
108997b2e202SAlex Deucher  * Writeback
109097b2e202SAlex Deucher  */
1091896a664cSMonk Liu #define AMDGPU_MAX_WB 512	/* Reserve at most 512 WB slots for amdgpu-owned rings. */
109297b2e202SAlex Deucher 
109397b2e202SAlex Deucher struct amdgpu_wb {
109497b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
109597b2e202SAlex Deucher 	volatile uint32_t	*wb;
109697b2e202SAlex Deucher 	uint64_t		gpu_addr;
109797b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
109897b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
109997b2e202SAlex Deucher };
110097b2e202SAlex Deucher 
1101131b4b36SAlex Deucher int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
1102131b4b36SAlex Deucher void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
110397b2e202SAlex Deucher 
1104041d9d93SAlex Deucher void amdgpu_device_get_pcie_info(struct amdgpu_device *adev);
1105d0dd7f0cSAlex Deucher 
110697b2e202SAlex Deucher /*
110797b2e202SAlex Deucher  * SDMA
110897b2e202SAlex Deucher  */
1109c113ea1cSAlex Deucher struct amdgpu_sdma_instance {
111097b2e202SAlex Deucher 	/* SDMA firmware */
111197b2e202SAlex Deucher 	const struct firmware	*fw;
111297b2e202SAlex Deucher 	uint32_t		fw_version;
1113cfa2104fSJammy Zhou 	uint32_t		feature_version;
111497b2e202SAlex Deucher 
111597b2e202SAlex Deucher 	struct amdgpu_ring	ring;
111618111de0SJammy Zhou 	bool			burst_nop;
111797b2e202SAlex Deucher };
111897b2e202SAlex Deucher 
1119c113ea1cSAlex Deucher struct amdgpu_sdma {
1120c113ea1cSAlex Deucher 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
112130d1574fSKen Wang #ifdef CONFIG_DRM_AMDGPU_SI
112230d1574fSKen Wang 	//SI DMA has a difference trap irq number for the second engine
112330d1574fSKen Wang 	struct amdgpu_irq_src	trap_irq_1;
112430d1574fSKen Wang #endif
1125c113ea1cSAlex Deucher 	struct amdgpu_irq_src	trap_irq;
1126c113ea1cSAlex Deucher 	struct amdgpu_irq_src	illegal_inst_irq;
1127c113ea1cSAlex Deucher 	int			num_instances;
1128e702a680SChunming Zhou 	uint32_t                    srbm_soft_reset;
1129c113ea1cSAlex Deucher };
1130c113ea1cSAlex Deucher 
113197b2e202SAlex Deucher /*
113297b2e202SAlex Deucher  * Firmware
113397b2e202SAlex Deucher  */
1134e635ee07SHuang Rui enum amdgpu_firmware_load_type {
1135e635ee07SHuang Rui 	AMDGPU_FW_LOAD_DIRECT = 0,
1136e635ee07SHuang Rui 	AMDGPU_FW_LOAD_SMU,
1137e635ee07SHuang Rui 	AMDGPU_FW_LOAD_PSP,
1138e635ee07SHuang Rui };
1139e635ee07SHuang Rui 
114097b2e202SAlex Deucher struct amdgpu_firmware {
114197b2e202SAlex Deucher 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1142e635ee07SHuang Rui 	enum amdgpu_firmware_load_type load_type;
114397b2e202SAlex Deucher 	struct amdgpu_bo *fw_buf;
114497b2e202SAlex Deucher 	unsigned int fw_size;
11452445b227SHuang Rui 	unsigned int max_ucodes;
11460e5ca0d1SHuang Rui 	/* firmwares are loaded by psp instead of smu from vega10 */
11470e5ca0d1SHuang Rui 	const struct amdgpu_psp_funcs *funcs;
11480e5ca0d1SHuang Rui 	struct amdgpu_bo *rbuf;
11490e5ca0d1SHuang Rui 	struct mutex mutex;
1150ab4fe3e1SHuang Rui 
1151ab4fe3e1SHuang Rui 	/* gpu info firmware data pointer */
1152ab4fe3e1SHuang Rui 	const struct firmware *gpu_info_fw;
1153d59c026bSMonk Liu 
1154d59c026bSMonk Liu 	void *fw_buf_ptr;
1155d59c026bSMonk Liu 	uint64_t fw_buf_mc;
115697b2e202SAlex Deucher };
115797b2e202SAlex Deucher 
115897b2e202SAlex Deucher /*
115997b2e202SAlex Deucher  * Benchmarking
116097b2e202SAlex Deucher  */
116197b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
116297b2e202SAlex Deucher 
116397b2e202SAlex Deucher 
116497b2e202SAlex Deucher /*
116597b2e202SAlex Deucher  * Testing
116697b2e202SAlex Deucher  */
116797b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
116897b2e202SAlex Deucher 
116950ab2533SHuang Rui 
117097b2e202SAlex Deucher /*
117197b2e202SAlex Deucher  * amdgpu smumgr functions
117297b2e202SAlex Deucher  */
117397b2e202SAlex Deucher struct amdgpu_smumgr_funcs {
117497b2e202SAlex Deucher 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
117597b2e202SAlex Deucher 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
117697b2e202SAlex Deucher 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
117797b2e202SAlex Deucher };
117897b2e202SAlex Deucher 
117997b2e202SAlex Deucher /*
118097b2e202SAlex Deucher  * amdgpu smumgr
118197b2e202SAlex Deucher  */
118297b2e202SAlex Deucher struct amdgpu_smumgr {
118397b2e202SAlex Deucher 	struct amdgpu_bo *toc_buf;
118497b2e202SAlex Deucher 	struct amdgpu_bo *smu_buf;
118597b2e202SAlex Deucher 	/* asic priv smu data */
118697b2e202SAlex Deucher 	void *priv;
118797b2e202SAlex Deucher 	spinlock_t smu_lock;
118897b2e202SAlex Deucher 	/* smumgr functions */
118997b2e202SAlex Deucher 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
119097b2e202SAlex Deucher 	/* ucode loading complete flag */
119197b2e202SAlex Deucher 	uint32_t fw_flags;
119297b2e202SAlex Deucher };
119397b2e202SAlex Deucher 
119497b2e202SAlex Deucher /*
119597b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
119697b2e202SAlex Deucher  */
119797b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
119897b2e202SAlex Deucher 	uint32_t reg_offset;
119997b2e202SAlex Deucher 	bool grbm_indexed;
120097b2e202SAlex Deucher };
120197b2e202SAlex Deucher 
120297b2e202SAlex Deucher /*
120397b2e202SAlex Deucher  * ASIC specific functions.
120497b2e202SAlex Deucher  */
120597b2e202SAlex Deucher struct amdgpu_asic_funcs {
120697b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
12077946b878SAlex Deucher 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
12087946b878SAlex Deucher 				   u8 *bios, u32 length_bytes);
120997b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
121097b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
121197b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
121297b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
121397b2e202SAlex Deucher 	/* get the reference clock */
121497b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
121597b2e202SAlex Deucher 	/* MM block clocks */
121697b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
121797b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1218841686dfSMaruthi Bayyavarapu 	/* static power management */
1219841686dfSMaruthi Bayyavarapu 	int (*get_pcie_lanes)(struct amdgpu_device *adev);
1220841686dfSMaruthi Bayyavarapu 	void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
1221bbf282d8SAlex Deucher 	/* get config memsize register */
1222bbf282d8SAlex Deucher 	u32 (*get_config_memsize)(struct amdgpu_device *adev);
12232df1b8b6SAlex Deucher 	/* flush hdp write queue */
12242df1b8b6SAlex Deucher 	void (*flush_hdp)(struct amdgpu_device *adev);
12252df1b8b6SAlex Deucher 	/* invalidate hdp read cache */
12262df1b8b6SAlex Deucher 	void (*invalidate_hdp)(struct amdgpu_device *adev);
122797b2e202SAlex Deucher };
122897b2e202SAlex Deucher 
122997b2e202SAlex Deucher /*
123097b2e202SAlex Deucher  * IOCTL.
123197b2e202SAlex Deucher  */
123297b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
123397b2e202SAlex Deucher 			    struct drm_file *filp);
123497b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
123597b2e202SAlex Deucher 				struct drm_file *filp);
123697b2e202SAlex Deucher 
123797b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
123897b2e202SAlex Deucher 			  struct drm_file *filp);
123997b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
124097b2e202SAlex Deucher 			struct drm_file *filp);
124197b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
124297b2e202SAlex Deucher 			  struct drm_file *filp);
124397b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
124497b2e202SAlex Deucher 			      struct drm_file *filp);
124597b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
124697b2e202SAlex Deucher 			  struct drm_file *filp);
124797b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
124897b2e202SAlex Deucher 			struct drm_file *filp);
124997b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
12507ca24cf2SMarek Olšák int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
12517ca24cf2SMarek Olšák 				    struct drm_file *filp);
125297b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1253eef18a82SJunwei Zhang int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
1254eef18a82SJunwei Zhang 				struct drm_file *filp);
125597b2e202SAlex Deucher 
125697b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
125797b2e202SAlex Deucher 				struct drm_file *filp);
125897b2e202SAlex Deucher 
125997b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
126097b2e202SAlex Deucher struct amdgpu_vram_scratch {
126197b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
126297b2e202SAlex Deucher 	volatile uint32_t		*ptr;
126397b2e202SAlex Deucher 	u64				gpu_addr;
126497b2e202SAlex Deucher };
126597b2e202SAlex Deucher 
126697b2e202SAlex Deucher /*
126797b2e202SAlex Deucher  * ACPI
126897b2e202SAlex Deucher  */
126997b2e202SAlex Deucher struct amdgpu_atif_notification_cfg {
127097b2e202SAlex Deucher 	bool enabled;
127197b2e202SAlex Deucher 	int command_code;
127297b2e202SAlex Deucher };
127397b2e202SAlex Deucher 
127497b2e202SAlex Deucher struct amdgpu_atif_notifications {
127597b2e202SAlex Deucher 	bool display_switch;
127697b2e202SAlex Deucher 	bool expansion_mode_change;
127797b2e202SAlex Deucher 	bool thermal_state;
127897b2e202SAlex Deucher 	bool forced_power_state;
127997b2e202SAlex Deucher 	bool system_power_state;
128097b2e202SAlex Deucher 	bool display_conf_change;
128197b2e202SAlex Deucher 	bool px_gfx_switch;
128297b2e202SAlex Deucher 	bool brightness_change;
128397b2e202SAlex Deucher 	bool dgpu_display_event;
128497b2e202SAlex Deucher };
128597b2e202SAlex Deucher 
128697b2e202SAlex Deucher struct amdgpu_atif_functions {
128797b2e202SAlex Deucher 	bool system_params;
128897b2e202SAlex Deucher 	bool sbios_requests;
128997b2e202SAlex Deucher 	bool select_active_disp;
129097b2e202SAlex Deucher 	bool lid_state;
129197b2e202SAlex Deucher 	bool get_tv_standard;
129297b2e202SAlex Deucher 	bool set_tv_standard;
129397b2e202SAlex Deucher 	bool get_panel_expansion_mode;
129497b2e202SAlex Deucher 	bool set_panel_expansion_mode;
129597b2e202SAlex Deucher 	bool temperature_change;
129697b2e202SAlex Deucher 	bool graphics_device_types;
129797b2e202SAlex Deucher };
129897b2e202SAlex Deucher 
129997b2e202SAlex Deucher struct amdgpu_atif {
130097b2e202SAlex Deucher 	struct amdgpu_atif_notifications notifications;
130197b2e202SAlex Deucher 	struct amdgpu_atif_functions functions;
130297b2e202SAlex Deucher 	struct amdgpu_atif_notification_cfg notification_cfg;
130397b2e202SAlex Deucher 	struct amdgpu_encoder *encoder_for_bl;
130497b2e202SAlex Deucher };
130597b2e202SAlex Deucher 
130697b2e202SAlex Deucher struct amdgpu_atcs_functions {
130797b2e202SAlex Deucher 	bool get_ext_state;
130897b2e202SAlex Deucher 	bool pcie_perf_req;
130997b2e202SAlex Deucher 	bool pcie_dev_rdy;
131097b2e202SAlex Deucher 	bool pcie_bus_width;
131197b2e202SAlex Deucher };
131297b2e202SAlex Deucher 
131397b2e202SAlex Deucher struct amdgpu_atcs {
131497b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
131597b2e202SAlex Deucher };
131697b2e202SAlex Deucher 
131797b2e202SAlex Deucher /*
1318a05502e5SHorace Chen  * Firmware VRAM reservation
1319a05502e5SHorace Chen  */
1320a05502e5SHorace Chen struct amdgpu_fw_vram_usage {
1321a05502e5SHorace Chen 	u64 start_offset;
1322a05502e5SHorace Chen 	u64 size;
1323a05502e5SHorace Chen 	struct amdgpu_bo *reserved_bo;
1324a05502e5SHorace Chen 	void *va;
1325a05502e5SHorace Chen };
1326a05502e5SHorace Chen 
1327a05502e5SHorace Chen /*
1328d03846afSChunming Zhou  * CGS
1329d03846afSChunming Zhou  */
1330110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1331110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1332a8fe58ceSMaruthi Bayyavarapu 
1333a8fe58ceSMaruthi Bayyavarapu /*
133497b2e202SAlex Deucher  * Core structure, functions and helpers.
133597b2e202SAlex Deucher  */
133697b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
133797b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
133897b2e202SAlex Deucher 
133997b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
134097b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
134197b2e202SAlex Deucher 
1342946a4d5bSShaoyun Liu 
1343946a4d5bSShaoyun Liu /*
1344946a4d5bSShaoyun Liu  * amdgpu nbio functions
1345946a4d5bSShaoyun Liu  *
1346946a4d5bSShaoyun Liu  */
1347bf383fb6SAlex Deucher struct nbio_hdp_flush_reg {
1348bf383fb6SAlex Deucher 	u32 ref_and_mask_cp0;
1349bf383fb6SAlex Deucher 	u32 ref_and_mask_cp1;
1350bf383fb6SAlex Deucher 	u32 ref_and_mask_cp2;
1351bf383fb6SAlex Deucher 	u32 ref_and_mask_cp3;
1352bf383fb6SAlex Deucher 	u32 ref_and_mask_cp4;
1353bf383fb6SAlex Deucher 	u32 ref_and_mask_cp5;
1354bf383fb6SAlex Deucher 	u32 ref_and_mask_cp6;
1355bf383fb6SAlex Deucher 	u32 ref_and_mask_cp7;
1356bf383fb6SAlex Deucher 	u32 ref_and_mask_cp8;
1357bf383fb6SAlex Deucher 	u32 ref_and_mask_cp9;
1358bf383fb6SAlex Deucher 	u32 ref_and_mask_sdma0;
1359bf383fb6SAlex Deucher 	u32 ref_and_mask_sdma1;
1360bf383fb6SAlex Deucher };
1361946a4d5bSShaoyun Liu 
1362946a4d5bSShaoyun Liu struct amdgpu_nbio_funcs {
1363bf383fb6SAlex Deucher 	const struct nbio_hdp_flush_reg *hdp_flush_reg;
1364bf383fb6SAlex Deucher 	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
1365bf383fb6SAlex Deucher 	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
1366bf383fb6SAlex Deucher 	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
1367bf383fb6SAlex Deucher 	u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
1368bf383fb6SAlex Deucher 	u32 (*get_rev_id)(struct amdgpu_device *adev);
1369bf383fb6SAlex Deucher 	void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
1370bf383fb6SAlex Deucher 	void (*hdp_flush)(struct amdgpu_device *adev);
1371bf383fb6SAlex Deucher 	u32 (*get_memsize)(struct amdgpu_device *adev);
1372bf383fb6SAlex Deucher 	void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
1373bf383fb6SAlex Deucher 				    bool use_doorbell, int doorbell_index);
1374bf383fb6SAlex Deucher 	void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
1375bf383fb6SAlex Deucher 					 bool enable);
1376bf383fb6SAlex Deucher 	void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
1377bf383fb6SAlex Deucher 						  bool enable);
1378bf383fb6SAlex Deucher 	void (*ih_doorbell_range)(struct amdgpu_device *adev,
1379bf383fb6SAlex Deucher 				  bool use_doorbell, int doorbell_index);
1380bf383fb6SAlex Deucher 	void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
1381bf383fb6SAlex Deucher 						 bool enable);
1382bf383fb6SAlex Deucher 	void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
1383bf383fb6SAlex Deucher 						bool enable);
1384bf383fb6SAlex Deucher 	void (*get_clockgating_state)(struct amdgpu_device *adev,
1385bf383fb6SAlex Deucher 				      u32 *flags);
1386bf383fb6SAlex Deucher 	void (*ih_control)(struct amdgpu_device *adev);
1387bf383fb6SAlex Deucher 	void (*init_registers)(struct amdgpu_device *adev);
1388bf383fb6SAlex Deucher 	void (*detect_hw_virt)(struct amdgpu_device *adev);
1389946a4d5bSShaoyun Liu };
1390946a4d5bSShaoyun Liu 
1391946a4d5bSShaoyun Liu 
13924522824cSShaoyun Liu /* Define the HW IP blocks will be used in driver , add more if necessary */
13934522824cSShaoyun Liu enum amd_hw_ip_block_type {
13944522824cSShaoyun Liu 	GC_HWIP = 1,
13954522824cSShaoyun Liu 	HDP_HWIP,
13964522824cSShaoyun Liu 	SDMA0_HWIP,
13974522824cSShaoyun Liu 	SDMA1_HWIP,
13984522824cSShaoyun Liu 	MMHUB_HWIP,
13994522824cSShaoyun Liu 	ATHUB_HWIP,
14004522824cSShaoyun Liu 	NBIO_HWIP,
14014522824cSShaoyun Liu 	MP0_HWIP,
14024522824cSShaoyun Liu 	UVD_HWIP,
14034522824cSShaoyun Liu 	VCN_HWIP = UVD_HWIP,
14044522824cSShaoyun Liu 	VCE_HWIP,
14054522824cSShaoyun Liu 	DF_HWIP,
14064522824cSShaoyun Liu 	DCE_HWIP,
14074522824cSShaoyun Liu 	OSSSYS_HWIP,
14084522824cSShaoyun Liu 	SMUIO_HWIP,
14094522824cSShaoyun Liu 	PWR_HWIP,
14104522824cSShaoyun Liu 	NBIF_HWIP,
14114522824cSShaoyun Liu 	MAX_HWIP
14124522824cSShaoyun Liu };
14134522824cSShaoyun Liu 
14144522824cSShaoyun Liu #define HWIP_MAX_INSTANCE	6
14154522824cSShaoyun Liu 
141611dc9364SRex Zhu struct amd_powerplay {
141711dc9364SRex Zhu 	struct cgs_device *cgs_device;
141811dc9364SRex Zhu 	void *pp_handle;
141911dc9364SRex Zhu 	const struct amd_ip_funcs *ip_funcs;
142011dc9364SRex Zhu 	const struct amd_pm_funcs *pp_funcs;
142111dc9364SRex Zhu };
142211dc9364SRex Zhu 
14230c49e0b8SChunming Zhou #define AMDGPU_RESET_MAGIC_NUM 64
142497b2e202SAlex Deucher struct amdgpu_device {
142597b2e202SAlex Deucher 	struct device			*dev;
142697b2e202SAlex Deucher 	struct drm_device		*ddev;
142797b2e202SAlex Deucher 	struct pci_dev			*pdev;
142897b2e202SAlex Deucher 
1429a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP
1430a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_acp		acp;
1431a8fe58ceSMaruthi Bayyavarapu #endif
1432a8fe58ceSMaruthi Bayyavarapu 
143397b2e202SAlex Deucher 	/* ASIC */
14342f7d10b3SJammy Zhou 	enum amd_asic_type		asic_type;
143597b2e202SAlex Deucher 	uint32_t			family;
143697b2e202SAlex Deucher 	uint32_t			rev_id;
143797b2e202SAlex Deucher 	uint32_t			external_rev_id;
143897b2e202SAlex Deucher 	unsigned long			flags;
143997b2e202SAlex Deucher 	int				usec_timeout;
144097b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
144197b2e202SAlex Deucher 	bool				shutdown;
144297b2e202SAlex Deucher 	bool				need_dma32;
1443fd5fd480SChunming Zhou 	bool				need_swiotlb;
144497b2e202SAlex Deucher 	bool				accel_working;
144597b2e202SAlex Deucher 	struct work_struct		reset_work;
144697b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
144797b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
144897b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
144997b2e202SAlex Deucher 	unsigned			debugfs_count;
145097b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
1451adcec288STom St Denis 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
145297b2e202SAlex Deucher #endif
145397b2e202SAlex Deucher 	struct amdgpu_atif		atif;
145497b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
145597b2e202SAlex Deucher 	struct mutex			srbm_mutex;
145697b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
145797b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
145897b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
145997b2e202SAlex Deucher 	bool				have_disp_power_ref;
146097b2e202SAlex Deucher 
146197b2e202SAlex Deucher 	/* BIOS */
14620cdd5005SAlex Deucher 	bool				is_atom_fw;
146397b2e202SAlex Deucher 	uint8_t				*bios;
1464a9f5db9cSEvan Quan 	uint32_t			bios_size;
14655af2c10dSKent Russell 	struct amdgpu_bo		*stolen_vga_memory;
1466a5bde2f9SAlex Deucher 	uint32_t			bios_scratch_reg_offset;
146797b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
146897b2e202SAlex Deucher 
146997b2e202SAlex Deucher 	/* Register/doorbell mmio */
147097b2e202SAlex Deucher 	resource_size_t			rmmio_base;
147197b2e202SAlex Deucher 	resource_size_t			rmmio_size;
147297b2e202SAlex Deucher 	void __iomem			*rmmio;
147397b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
147497b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
147597b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
147697b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
147797b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
147897b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
147997b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
148097b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
148197b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
148297b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
148336b9a952SHuang Rui 	amdgpu_rreg_t			pciep_rreg;
148436b9a952SHuang Rui 	amdgpu_wreg_t			pciep_wreg;
148597b2e202SAlex Deucher 	/* protects concurrent UVD register access */
148697b2e202SAlex Deucher 	spinlock_t uvd_ctx_idx_lock;
148797b2e202SAlex Deucher 	amdgpu_rreg_t			uvd_ctx_rreg;
148897b2e202SAlex Deucher 	amdgpu_wreg_t			uvd_ctx_wreg;
148997b2e202SAlex Deucher 	/* protects concurrent DIDT register access */
149097b2e202SAlex Deucher 	spinlock_t didt_idx_lock;
149197b2e202SAlex Deucher 	amdgpu_rreg_t			didt_rreg;
149297b2e202SAlex Deucher 	amdgpu_wreg_t			didt_wreg;
1493ccdbb20aSRex Zhu 	/* protects concurrent gc_cac register access */
1494ccdbb20aSRex Zhu 	spinlock_t gc_cac_idx_lock;
1495ccdbb20aSRex Zhu 	amdgpu_rreg_t			gc_cac_rreg;
1496ccdbb20aSRex Zhu 	amdgpu_wreg_t			gc_cac_wreg;
149716abb5d2SEvan Quan 	/* protects concurrent se_cac register access */
149816abb5d2SEvan Quan 	spinlock_t se_cac_idx_lock;
149916abb5d2SEvan Quan 	amdgpu_rreg_t			se_cac_rreg;
150016abb5d2SEvan Quan 	amdgpu_wreg_t			se_cac_wreg;
150197b2e202SAlex Deucher 	/* protects concurrent ENDPOINT (audio) register access */
150297b2e202SAlex Deucher 	spinlock_t audio_endpt_idx_lock;
150397b2e202SAlex Deucher 	amdgpu_block_rreg_t		audio_endpt_rreg;
150497b2e202SAlex Deucher 	amdgpu_block_wreg_t		audio_endpt_wreg;
150597b2e202SAlex Deucher 	void __iomem                    *rio_mem;
150697b2e202SAlex Deucher 	resource_size_t			rio_mem_size;
150797b2e202SAlex Deucher 	struct amdgpu_doorbell		doorbell;
150897b2e202SAlex Deucher 
150997b2e202SAlex Deucher 	/* clock/pll info */
151097b2e202SAlex Deucher 	struct amdgpu_clock            clock;
151197b2e202SAlex Deucher 
151297b2e202SAlex Deucher 	/* MC */
1513770d13b1SChristian König 	struct amdgpu_gmc		gmc;
151497b2e202SAlex Deucher 	struct amdgpu_gart		gart;
151597b2e202SAlex Deucher 	struct amdgpu_dummy_page	dummy_page;
151697b2e202SAlex Deucher 	struct amdgpu_vm_manager	vm_manager;
1517e60f8db5SAlex Xie 	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
151897b2e202SAlex Deucher 
151997b2e202SAlex Deucher 	/* memory management */
152097b2e202SAlex Deucher 	struct amdgpu_mman		mman;
152197b2e202SAlex Deucher 	struct amdgpu_vram_scratch	vram_scratch;
152297b2e202SAlex Deucher 	struct amdgpu_wb		wb;
152397b2e202SAlex Deucher 	atomic64_t			num_bytes_moved;
1524dbd5ed60SChristian König 	atomic64_t			num_evictions;
152568e2c5ffSMarek Olšák 	atomic64_t			num_vram_cpu_page_faults;
1526d94aed5aSMarek Olšák 	atomic_t			gpu_reset_counter;
1527f1892138SChunming Zhou 	atomic_t			vram_lost_counter;
152897b2e202SAlex Deucher 
152995844d20SMarek Olšák 	/* data for buffer migration throttling */
153095844d20SMarek Olšák 	struct {
153195844d20SMarek Olšák 		spinlock_t		lock;
153295844d20SMarek Olšák 		s64			last_update_us;
153395844d20SMarek Olšák 		s64			accum_us; /* accumulated microseconds */
153400f06b24SJohn Brooks 		s64			accum_us_vis; /* for visible VRAM */
153595844d20SMarek Olšák 		u32			log2_max_MBps;
153695844d20SMarek Olšák 	} mm_stats;
153795844d20SMarek Olšák 
153897b2e202SAlex Deucher 	/* display */
15399accf2fdSEmily Deng 	bool				enable_virtual_display;
154097b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
15414562236bSHarry Wentland 	/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
154297b2e202SAlex Deucher 	struct work_struct		hotplug_work;
154397b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
154497b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
154597b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
154697b2e202SAlex Deucher 
154797b2e202SAlex Deucher 	/* rings */
154876bf0db5SChristian König 	u64				fence_context;
154997b2e202SAlex Deucher 	unsigned			num_rings;
155097b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
155197b2e202SAlex Deucher 	bool				ib_pool_ready;
155297b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
155397b2e202SAlex Deucher 
155497b2e202SAlex Deucher 	/* interrupts */
155597b2e202SAlex Deucher 	struct amdgpu_irq		irq;
155697b2e202SAlex Deucher 
15571f7371b2SAlex Deucher 	/* powerplay */
15581f7371b2SAlex Deucher 	struct amd_powerplay		powerplay;
1559f3898ea1SEric Huang 	bool				pp_force_state_enabled;
15601f7371b2SAlex Deucher 
156197b2e202SAlex Deucher 	/* dpm */
156297b2e202SAlex Deucher 	struct amdgpu_pm		pm;
156397b2e202SAlex Deucher 	u32				cg_flags;
156497b2e202SAlex Deucher 	u32				pg_flags;
156597b2e202SAlex Deucher 
156697b2e202SAlex Deucher 	/* amdgpu smumgr */
156797b2e202SAlex Deucher 	struct amdgpu_smumgr smu;
156897b2e202SAlex Deucher 
156997b2e202SAlex Deucher 	/* gfx */
157097b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
157197b2e202SAlex Deucher 
157297b2e202SAlex Deucher 	/* sdma */
1573c113ea1cSAlex Deucher 	struct amdgpu_sdma		sdma;
157497b2e202SAlex Deucher 
157597b2e202SAlex Deucher 	/* uvd */
157697b2e202SAlex Deucher 	struct amdgpu_uvd		uvd;
157797b2e202SAlex Deucher 
157897b2e202SAlex Deucher 	/* vce */
157997b2e202SAlex Deucher 	struct amdgpu_vce		vce;
158095d0906fSLeo Liu 
158195d0906fSLeo Liu 	/* vcn */
158295d0906fSLeo Liu 	struct amdgpu_vcn		vcn;
158397b2e202SAlex Deucher 
158497b2e202SAlex Deucher 	/* firmwares */
158597b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
158697b2e202SAlex Deucher 
15870e5ca0d1SHuang Rui 	/* PSP */
15880e5ca0d1SHuang Rui 	struct psp_context		psp;
15890e5ca0d1SHuang Rui 
159097b2e202SAlex Deucher 	/* GDS */
159197b2e202SAlex Deucher 	struct amdgpu_gds		gds;
159297b2e202SAlex Deucher 
15934562236bSHarry Wentland 	/* display related functionality */
15944562236bSHarry Wentland 	struct amdgpu_display_manager dm;
15954562236bSHarry Wentland 
1596a1255107SAlex Deucher 	struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
159797b2e202SAlex Deucher 	int				num_ip_blocks;
159897b2e202SAlex Deucher 	struct mutex	mn_lock;
159997b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
160097b2e202SAlex Deucher 
160197b2e202SAlex Deucher 	/* tracking pinned memory */
160297b2e202SAlex Deucher 	u64 vram_pin_size;
1603e131b914SChunming Zhou 	u64 invisible_pin_size;
160497b2e202SAlex Deucher 	u64 gart_pin_size;
1605130e0371SOded Gabbay 
1606130e0371SOded Gabbay 	/* amdkfd interface */
1607130e0371SOded Gabbay 	struct kfd_dev          *kfd;
160823ca0e4eSChunming Zhou 
16094522824cSShaoyun Liu 	/* soc15 register offset based on ip, instance and  segment */
16104522824cSShaoyun Liu 	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
16114522824cSShaoyun Liu 
1612946a4d5bSShaoyun Liu 	const struct amdgpu_nbio_funcs	*nbio_funcs;
1613946a4d5bSShaoyun Liu 
16142dc80b00SShirish S 	/* delayed work_func for deferring clockgating during resume */
16152dc80b00SShirish S 	struct delayed_work     late_init_work;
16162dc80b00SShirish S 
16175a5099cbSXiangliang Yu 	struct amdgpu_virt	virt;
1618a05502e5SHorace Chen 	/* firmware VRAM reservation */
1619a05502e5SHorace Chen 	struct amdgpu_fw_vram_usage fw_vram_usage;
16200c4e7fa5SChunming Zhou 
16210c4e7fa5SChunming Zhou 	/* link all shadow bo */
16220c4e7fa5SChunming Zhou 	struct list_head                shadow_list;
16230c4e7fa5SChunming Zhou 	struct mutex                    shadow_list_lock;
1624795f2813SAndres Rodriguez 	/* keep an lru list of rings by HW IP */
1625795f2813SAndres Rodriguez 	struct list_head		ring_lru_list;
1626795f2813SAndres Rodriguez 	spinlock_t			ring_lru_list_lock;
16275c1354bdSChunming Zhou 
1628c836fec5SJim Qu 	/* record hw reset is performed */
1629c836fec5SJim Qu 	bool has_hw_reset;
16300c49e0b8SChunming Zhou 	u8				reset_magic[AMDGPU_RESET_MAGIC_NUM];
1631c836fec5SJim Qu 
163247ed4e1cSKen Wang 	/* record last mm index being written through WREG32*/
163347ed4e1cSKen Wang 	unsigned long last_mm_index;
163413a752e3SMonk Liu 	bool                            in_gpu_reset;
163513a752e3SMonk Liu 	struct mutex  lock_reset;
163697b2e202SAlex Deucher };
163797b2e202SAlex Deucher 
1638a7d64de6SChristian König static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1639a7d64de6SChristian König {
1640a7d64de6SChristian König 	return container_of(bdev, struct amdgpu_device, mman.bdev);
1641a7d64de6SChristian König }
1642a7d64de6SChristian König 
164397b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
164497b2e202SAlex Deucher 		       struct drm_device *ddev,
164597b2e202SAlex Deucher 		       struct pci_dev *pdev,
164697b2e202SAlex Deucher 		       uint32_t flags);
164797b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
164897b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
164997b2e202SAlex Deucher 
165097b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
165115d72fd7SMonk Liu 			uint32_t acc_flags);
165297b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
165315d72fd7SMonk Liu 		    uint32_t acc_flags);
165497b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
165597b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
165697b2e202SAlex Deucher 
165797b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
165897b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1659832be404SKen Wang u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1660832be404SKen Wang void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
166197b2e202SAlex Deucher 
16624562236bSHarry Wentland bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
16634562236bSHarry Wentland bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
16644562236bSHarry Wentland 
166597b2e202SAlex Deucher /*
166697b2e202SAlex Deucher  * Registers read & write functions.
166797b2e202SAlex Deucher  */
166815d72fd7SMonk Liu 
166915d72fd7SMonk Liu #define AMDGPU_REGS_IDX       (1<<0)
167015d72fd7SMonk Liu #define AMDGPU_REGS_NO_KIQ    (1<<1)
167115d72fd7SMonk Liu 
167215d72fd7SMonk Liu #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
167315d72fd7SMonk Liu #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
167415d72fd7SMonk Liu 
167515d72fd7SMonk Liu #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
167615d72fd7SMonk Liu #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
167715d72fd7SMonk Liu #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
167815d72fd7SMonk Liu #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
167915d72fd7SMonk Liu #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
168097b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
168197b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
168297b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
168397b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
168436b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
168536b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
168697b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
168797b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
168897b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
168997b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
169097b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
169197b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
1692ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1693ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
169416abb5d2SEvan Quan #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
169516abb5d2SEvan Quan #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
169697b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
169797b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
169897b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
169997b2e202SAlex Deucher 	do {							\
170097b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
170197b2e202SAlex Deucher 		tmp_ &= (mask);					\
170297b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
170397b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
170497b2e202SAlex Deucher 	} while (0)
170597b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
170697b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
170797b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
170897b2e202SAlex Deucher 	do {							\
170997b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
171097b2e202SAlex Deucher 		tmp_ &= (mask);					\
171197b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
171297b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
171397b2e202SAlex Deucher 	} while (0)
171497b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
171597b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
171697b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
171797b2e202SAlex Deucher 
171897b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
171997b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1720832be404SKen Wang #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1721832be404SKen Wang #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
172297b2e202SAlex Deucher 
172397b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
172497b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
172597b2e202SAlex Deucher 
172697b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
172797b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
172897b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
172997b2e202SAlex Deucher 
173097b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
173197b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
173297b2e202SAlex Deucher 
173361cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val)	\
173461cb8cefSTom St Denis 	WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
173561cb8cefSTom St Denis 
1736ccaf3574STom St Denis #define WREG32_FIELD_OFFSET(reg, offset, field, val)	\
1737ccaf3574STom St Denis 	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1738ccaf3574STom St Denis 
173997b2e202SAlex Deucher /*
174097b2e202SAlex Deucher  * BIOS helpers.
174197b2e202SAlex Deucher  */
174297b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
174397b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
174497b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
174597b2e202SAlex Deucher 
1746c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance *
1747c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
17484b2f7e2cSJammy Zhou {
17494b2f7e2cSJammy Zhou 	struct amdgpu_device *adev = ring->adev;
17504b2f7e2cSJammy Zhou 	int i;
17514b2f7e2cSJammy Zhou 
1752c113ea1cSAlex Deucher 	for (i = 0; i < adev->sdma.num_instances; i++)
1753c113ea1cSAlex Deucher 		if (&adev->sdma.instance[i].ring == ring)
17544b2f7e2cSJammy Zhou 			break;
17554b2f7e2cSJammy Zhou 
17564b2f7e2cSJammy Zhou 	if (i < AMDGPU_MAX_SDMA_INSTANCES)
1757c113ea1cSAlex Deucher 		return &adev->sdma.instance[i];
17584b2f7e2cSJammy Zhou 	else
17594b2f7e2cSJammy Zhou 		return NULL;
17604b2f7e2cSJammy Zhou }
17614b2f7e2cSJammy Zhou 
176297b2e202SAlex Deucher /*
176397b2e202SAlex Deucher  * ASICs macro.
176497b2e202SAlex Deucher  */
176597b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
176697b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
176797b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
176897b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
176997b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1770841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1771841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1772841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
177397b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
17747946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
177597b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1776bbf282d8SAlex Deucher #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
17772df1b8b6SAlex Deucher #define amdgpu_asic_flush_hdp(adev) (adev)->asic_funcs->flush_hdp((adev))
17782df1b8b6SAlex Deucher #define amdgpu_asic_invalidate_hdp(adev) (adev)->asic_funcs->invalidate_hdp((adev))
1779132f34e4SChristian König #define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
1780132f34e4SChristian König #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
1781132f34e4SChristian König #define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) (adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags))
1782132f34e4SChristian König #define amdgpu_gmc_get_pte_flags(adev, flags) (adev)->gmc.gmc_funcs->get_vm_pte_flags((adev),(flags))
178397b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
1784de9ea7bdSChristian 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)))
178597b2e202SAlex 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)))
178697b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
178797b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
1788bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
178997b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
179097b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
179197b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
1792c4f46f22SChristian König #define amdgpu_ring_emit_ib(r, ib, vmid, c) (r)->funcs->emit_ib((r), (ib), (vmid), (c))
1793b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
17945a4633c4SChristian König #define amdgpu_ring_emit_vm_flush(r, vmid, pasid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (pasid), (addr))
1795890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
179697b2e202SAlex 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))
1797d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
179811afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
1799c2167a65SMonk Liu #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
1800753ad49cSMonk Liu #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
1801b6091c12SXiangliang Yu #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
1802b6091c12SXiangliang Yu #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
18033b4d68e9SMonk Liu #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
18049e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
180503ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
180603ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
180797b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
180800ecd8a2SFelix Kuehling #define amdgpu_ih_prescreen_iv(adev) (adev)->irq.ih_funcs->prescreen_iv((adev))
180997b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
181097b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
181197b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
181297b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
181397b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
181497b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
181597b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
181697b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
181797b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
181897b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
1819cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
182097b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
182197b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
182297b2e202SAlex 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))
1823c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b))
18246e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
1825b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
18269559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
182797b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
18280e5ca0d1SHuang Rui #define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
182997b2e202SAlex Deucher 
183097b2e202SAlex Deucher /* Common functions */
18315f152b5eSAlex Deucher int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
18325f152b5eSAlex Deucher 			      struct amdgpu_job* job, bool force);
18338111c387SAlex Deucher void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
183439c640c0SAlex Deucher bool amdgpu_device_need_post(struct amdgpu_device *adev);
183597b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev);
1836d5fc5e82SChunming Zhou 
183700f06b24SJohn Brooks void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
183800f06b24SJohn Brooks 				  u64 num_vis_bytes);
1839765e7fbfSChristian König void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
184097b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
18412543e28aSAlex Deucher void amdgpu_device_vram_location(struct amdgpu_device *adev,
1842770d13b1SChristian König 				 struct amdgpu_gmc *mc, u64 base);
18432543e28aSAlex Deucher void amdgpu_device_gart_location(struct amdgpu_device *adev,
1844770d13b1SChristian König 				 struct amdgpu_gmc *mc);
1845d6895ad3SChristian König int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
184697b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
18479f31a0b0SBaoyou Xie int amdgpu_ttm_init(struct amdgpu_device *adev);
18489f31a0b0SBaoyou Xie void amdgpu_ttm_fini(struct amdgpu_device *adev);
18499c3f2b54SAlex Deucher void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
185097b2e202SAlex Deucher 					     const u32 *registers,
185197b2e202SAlex Deucher 					     const u32 array_size);
185297b2e202SAlex Deucher 
185397b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
185497b2e202SAlex Deucher /* atpx handler */
185597b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
185697b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
185797b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
1858a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void);
18592f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void);
1860efc83cf4SAlex Deucher bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1861714f88e0SAlex Xie bool amdgpu_has_atpx(void);
186297b2e202SAlex Deucher #else
186397b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
186497b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
1865a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
18662f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
1867efc83cf4SAlex Deucher static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
1868714f88e0SAlex Xie static inline bool amdgpu_has_atpx(void) { return false; }
186997b2e202SAlex Deucher #endif
187097b2e202SAlex Deucher 
187197b2e202SAlex Deucher /*
187297b2e202SAlex Deucher  * KMS
187397b2e202SAlex Deucher  */
187497b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1875f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl;
187697b2e202SAlex Deucher 
187797b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
187811b3c20bSGabriel Krisman Bertazi void amdgpu_driver_unload_kms(struct drm_device *dev);
187997b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
188097b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
188197b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
188297b2e202SAlex Deucher 				 struct drm_file *file_priv);
1883cdd61df6SAlex Deucher int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
1884810ddc3aSAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1885810ddc3aSAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
188688e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
188788e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
188888e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
188997b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
189097b2e202SAlex Deucher 			     unsigned long arg);
189197b2e202SAlex Deucher 
189297b2e202SAlex Deucher /*
189397b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
189497b2e202SAlex Deucher  */
189597b2e202SAlex Deucher struct amdgpu_afmt_acr {
189697b2e202SAlex Deucher 	u32 clock;
189797b2e202SAlex Deucher 
189897b2e202SAlex Deucher 	int n_32khz;
189997b2e202SAlex Deucher 	int cts_32khz;
190097b2e202SAlex Deucher 
190197b2e202SAlex Deucher 	int n_44_1khz;
190297b2e202SAlex Deucher 	int cts_44_1khz;
190397b2e202SAlex Deucher 
190497b2e202SAlex Deucher 	int n_48khz;
190597b2e202SAlex Deucher 	int cts_48khz;
190697b2e202SAlex Deucher 
190797b2e202SAlex Deucher };
190897b2e202SAlex Deucher 
190997b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
191097b2e202SAlex Deucher 
191197b2e202SAlex Deucher /* amdgpu_acpi.c */
191297b2e202SAlex Deucher #if defined(CONFIG_ACPI)
191397b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
191497b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
191597b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
191697b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
191797b2e202SAlex Deucher 						u8 perf_req, bool advertise);
191897b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
191997b2e202SAlex Deucher #else
192097b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
192197b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
192297b2e202SAlex Deucher #endif
192397b2e202SAlex Deucher 
19249cca0b8eSChristian König int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
19259cca0b8eSChristian König 			   uint64_t addr, struct amdgpu_bo **bo,
19269cca0b8eSChristian König 			   struct amdgpu_bo_va_mapping **mapping);
192797b2e202SAlex Deucher 
19284562236bSHarry Wentland #if defined(CONFIG_DRM_AMD_DC)
19294562236bSHarry Wentland int amdgpu_dm_display_resume(struct amdgpu_device *adev );
19304562236bSHarry Wentland #else
19314562236bSHarry Wentland static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
19324562236bSHarry Wentland #endif
19334562236bSHarry Wentland 
193497b2e202SAlex Deucher #include "amdgpu_object.h"
193597b2e202SAlex Deucher #endif
1936