xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision 51fd0370)
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 
3997b2e202SAlex Deucher #include <ttm/ttm_bo_api.h>
4097b2e202SAlex Deucher #include <ttm/ttm_bo_driver.h>
4197b2e202SAlex Deucher #include <ttm/ttm_placement.h>
4297b2e202SAlex Deucher #include <ttm/ttm_module.h>
4397b2e202SAlex Deucher #include <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>
4897b2e202SAlex Deucher 
4978c16834SAndres Rodriguez #include <kgd_kfd_interface.h>
5078c16834SAndres Rodriguez 
515fc3aeebSyanyang1 #include "amd_shared.h"
5297b2e202SAlex Deucher #include "amdgpu_mode.h"
5397b2e202SAlex Deucher #include "amdgpu_ih.h"
5497b2e202SAlex Deucher #include "amdgpu_irq.h"
5597b2e202SAlex Deucher #include "amdgpu_ucode.h"
56c632d799SFlora Cui #include "amdgpu_ttm.h"
570e5ca0d1SHuang Rui #include "amdgpu_psp.h"
5897b2e202SAlex Deucher #include "amdgpu_gds.h"
5956113504SChristian König #include "amdgpu_sync.h"
6078023016SChristian König #include "amdgpu_ring.h"
61073440d2SChristian König #include "amdgpu_vm.h"
621f7371b2SAlex Deucher #include "amd_powerplay.h"
63cf097881SAlex Deucher #include "amdgpu_dpm.h"
64a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h"
654df654d2SLeo Liu #include "amdgpu_uvd.h"
665e568178SLeo Liu #include "amdgpu_vce.h"
6795aa13f6SLeo Liu #include "amdgpu_vcn.h"
6897b2e202SAlex Deucher 
69b80d8475SAlex Deucher #include "gpu_scheduler.h"
70ceeb50edSMonk Liu #include "amdgpu_virt.h"
71b80d8475SAlex Deucher 
7297b2e202SAlex Deucher /*
7397b2e202SAlex Deucher  * Modules parameters.
7497b2e202SAlex Deucher  */
7597b2e202SAlex Deucher extern int amdgpu_modeset;
7697b2e202SAlex Deucher extern int amdgpu_vram_limit;
7797b2e202SAlex Deucher extern int amdgpu_gart_size;
7895844d20SMarek Olšák extern int amdgpu_moverate;
7997b2e202SAlex Deucher extern int amdgpu_benchmarking;
8097b2e202SAlex Deucher extern int amdgpu_testing;
8197b2e202SAlex Deucher extern int amdgpu_audio;
8297b2e202SAlex Deucher extern int amdgpu_disp_priority;
8397b2e202SAlex Deucher extern int amdgpu_hw_i2c;
8497b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
8597b2e202SAlex Deucher extern int amdgpu_msi;
8697b2e202SAlex Deucher extern int amdgpu_lockup_timeout;
8797b2e202SAlex Deucher extern int amdgpu_dpm;
88e635ee07SHuang Rui extern int amdgpu_fw_load_type;
8997b2e202SAlex Deucher extern int amdgpu_aspm;
9097b2e202SAlex Deucher extern int amdgpu_runtime_pm;
9197b2e202SAlex Deucher extern unsigned amdgpu_ip_block_mask;
9297b2e202SAlex Deucher extern int amdgpu_bapm;
9397b2e202SAlex Deucher extern int amdgpu_deep_color;
9497b2e202SAlex Deucher extern int amdgpu_vm_size;
9597b2e202SAlex Deucher extern int amdgpu_vm_block_size;
96d9c13156SChristian König extern int amdgpu_vm_fault_stop;
97b495bd3aSChristian König extern int amdgpu_vm_debug;
989a4b7d4cSHarish Kasiviswanathan extern int amdgpu_vm_update_mode;
991333f723SJammy Zhou extern int amdgpu_sched_jobs;
1004afcb303SJammy Zhou extern int amdgpu_sched_hw_submission;
1013ca67300SRex Zhu extern int amdgpu_no_evict;
1023ca67300SRex Zhu extern int amdgpu_direct_gma_size;
103cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_gen_cap;
104cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_lane_cap;
105395d1fb9SNicolai Hähnle extern unsigned amdgpu_cg_mask;
106395d1fb9SNicolai Hähnle extern unsigned amdgpu_pg_mask;
1076f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu;
1089accf2fdSEmily Deng extern char *amdgpu_virtual_display;
1095141e9d2SRex Zhu extern unsigned amdgpu_pp_feature_mask;
1106a7f76e7SChristian König extern int amdgpu_vram_page_split;
111bce23e00SAlex Deucher extern int amdgpu_ngg;
112bce23e00SAlex Deucher extern int amdgpu_prim_buf_per_se;
113bce23e00SAlex Deucher extern int amdgpu_pos_buf_per_se;
114bce23e00SAlex Deucher extern int amdgpu_cntl_sb_buf_per_se;
115bce23e00SAlex Deucher extern int amdgpu_param_buf_per_se;
11665781c78SMonk Liu extern int amdgpu_job_hang_limit;
117e8835e0eSHawking Zhang extern int amdgpu_lbpw;
11897b2e202SAlex Deucher 
1196dd13096SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_SI
1206dd13096SFelix Kuehling extern int amdgpu_si_support;
1216dd13096SFelix Kuehling #endif
1227df28986SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_CIK
1237df28986SFelix Kuehling extern int amdgpu_cik_support;
1247df28986SFelix Kuehling #endif
1257df28986SFelix Kuehling 
12655ed8cafSChunming Zhou #define AMDGPU_DEFAULT_GTT_SIZE_MB		3072ULL /* 3GB by default */
1274b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
12897b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
12997b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
13097b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
13197b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
13297b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
13397b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
134a5bde2f9SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			16
13597b2e202SAlex Deucher 
13636f523a7SJammy Zhou /* max number of IP instances */
13736f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES		2
13836f523a7SJammy Zhou 
13997b2e202SAlex Deucher /* hard reset data */
14097b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
14197b2e202SAlex Deucher 
14297b2e202SAlex Deucher /* reset flags */
14397b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
14497b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
14597b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
14697b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
14797b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
14897b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
14997b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
15097b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
15197b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
15297b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
15397b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
15497b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
15597b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
15697b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
15797b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
15897b2e202SAlex Deucher 
15997b2e202SAlex Deucher /* GFX current status */
16097b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
16197b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE			0x00000001L
16297b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
16397b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
16497b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
16597b2e202SAlex Deucher 
16697b2e202SAlex Deucher /* max cursor sizes (in pixels) */
16797b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
16897b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
16997b2e202SAlex Deucher 
17097b2e202SAlex Deucher struct amdgpu_device;
17197b2e202SAlex Deucher struct amdgpu_ib;
17297b2e202SAlex Deucher struct amdgpu_cs_parser;
173bb977d37SChunming Zhou struct amdgpu_job;
17497b2e202SAlex Deucher struct amdgpu_irq_src;
1750b492a4cSAlex Deucher struct amdgpu_fpriv;
17697b2e202SAlex Deucher 
17797b2e202SAlex Deucher enum amdgpu_cp_irq {
17897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_GFX_EOP = 0,
17997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
18097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
18197b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
18297b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
18397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
18497b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
18597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
18697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
18797b2e202SAlex Deucher 
18897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
18997b2e202SAlex Deucher };
19097b2e202SAlex Deucher 
19197b2e202SAlex Deucher enum amdgpu_sdma_irq {
19297b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
19397b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP1,
19497b2e202SAlex Deucher 
19597b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_LAST
19697b2e202SAlex Deucher };
19797b2e202SAlex Deucher 
19897b2e202SAlex Deucher enum amdgpu_thermal_irq {
19997b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
20097b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
20197b2e202SAlex Deucher 
20297b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
20397b2e202SAlex Deucher };
20497b2e202SAlex Deucher 
2054e638ae9SXiangliang Yu enum amdgpu_kiq_irq {
2064e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
2074e638ae9SXiangliang Yu 	AMDGPU_CP_KIQ_IRQ_LAST
2084e638ae9SXiangliang Yu };
2094e638ae9SXiangliang Yu 
21097b2e202SAlex Deucher int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
2115fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
2125fc3aeebSyanyang1 				  enum amd_clockgating_state state);
21397b2e202SAlex Deucher int amdgpu_set_powergating_state(struct amdgpu_device *adev,
2145fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
2155fc3aeebSyanyang1 				  enum amd_powergating_state state);
2166cb2d4e4SHuang Rui void amdgpu_get_clockgating_state(struct amdgpu_device *adev, u32 *flags);
2175dbbb60bSAlex Deucher int amdgpu_wait_for_idle(struct amdgpu_device *adev,
2185dbbb60bSAlex Deucher 			 enum amd_ip_block_type block_type);
2195dbbb60bSAlex Deucher bool amdgpu_is_idle(struct amdgpu_device *adev,
2205dbbb60bSAlex Deucher 		    enum amd_ip_block_type block_type);
22197b2e202SAlex Deucher 
222a1255107SAlex Deucher #define AMDGPU_MAX_IP_NUM 16
223a1255107SAlex Deucher 
224a1255107SAlex Deucher struct amdgpu_ip_block_status {
225a1255107SAlex Deucher 	bool valid;
226a1255107SAlex Deucher 	bool sw;
227a1255107SAlex Deucher 	bool hw;
228a1255107SAlex Deucher 	bool late_initialized;
229a1255107SAlex Deucher 	bool hang;
230a1255107SAlex Deucher };
231a1255107SAlex Deucher 
23297b2e202SAlex Deucher struct amdgpu_ip_block_version {
233a1255107SAlex Deucher 	const enum amd_ip_block_type type;
234a1255107SAlex Deucher 	const u32 major;
235a1255107SAlex Deucher 	const u32 minor;
236a1255107SAlex Deucher 	const u32 rev;
2375fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
23897b2e202SAlex Deucher };
23997b2e202SAlex Deucher 
240a1255107SAlex Deucher struct amdgpu_ip_block {
241a1255107SAlex Deucher 	struct amdgpu_ip_block_status status;
242a1255107SAlex Deucher 	const struct amdgpu_ip_block_version *version;
243a1255107SAlex Deucher };
244a1255107SAlex Deucher 
24597b2e202SAlex Deucher int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
2465fc3aeebSyanyang1 				enum amd_ip_block_type type,
24797b2e202SAlex Deucher 				u32 major, u32 minor);
24897b2e202SAlex Deucher 
249a1255107SAlex Deucher struct amdgpu_ip_block * amdgpu_get_ip_block(struct amdgpu_device *adev,
2505fc3aeebSyanyang1 					     enum amd_ip_block_type type);
25197b2e202SAlex Deucher 
252a1255107SAlex Deucher int amdgpu_ip_block_add(struct amdgpu_device *adev,
253a1255107SAlex Deucher 			const struct amdgpu_ip_block_version *ip_block_version);
254a1255107SAlex Deucher 
25597b2e202SAlex Deucher /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
25697b2e202SAlex Deucher struct amdgpu_buffer_funcs {
25797b2e202SAlex Deucher 	/* maximum bytes in a single operation */
25897b2e202SAlex Deucher 	uint32_t	copy_max_bytes;
25997b2e202SAlex Deucher 
26097b2e202SAlex Deucher 	/* number of dw to reserve per operation */
26197b2e202SAlex Deucher 	unsigned	copy_num_dw;
26297b2e202SAlex Deucher 
26397b2e202SAlex Deucher 	/* used for buffer migration */
264c7ae72c0SChunming Zhou 	void (*emit_copy_buffer)(struct amdgpu_ib *ib,
26597b2e202SAlex Deucher 				 /* src addr in bytes */
26697b2e202SAlex Deucher 				 uint64_t src_offset,
26797b2e202SAlex Deucher 				 /* dst addr in bytes */
26897b2e202SAlex Deucher 				 uint64_t dst_offset,
26997b2e202SAlex Deucher 				 /* number of byte to transfer */
27097b2e202SAlex Deucher 				 uint32_t byte_count);
27197b2e202SAlex Deucher 
27297b2e202SAlex Deucher 	/* maximum bytes in a single operation */
27397b2e202SAlex Deucher 	uint32_t	fill_max_bytes;
27497b2e202SAlex Deucher 
27597b2e202SAlex Deucher 	/* number of dw to reserve per operation */
27697b2e202SAlex Deucher 	unsigned	fill_num_dw;
27797b2e202SAlex Deucher 
27897b2e202SAlex Deucher 	/* used for buffer clearing */
2796e7a3840SChunming Zhou 	void (*emit_fill_buffer)(struct amdgpu_ib *ib,
28097b2e202SAlex Deucher 				 /* value to write to memory */
28197b2e202SAlex Deucher 				 uint32_t src_data,
28297b2e202SAlex Deucher 				 /* dst addr in bytes */
28397b2e202SAlex Deucher 				 uint64_t dst_offset,
28497b2e202SAlex Deucher 				 /* number of byte to fill */
28597b2e202SAlex Deucher 				 uint32_t byte_count);
28697b2e202SAlex Deucher };
28797b2e202SAlex Deucher 
28897b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */
28997b2e202SAlex Deucher struct amdgpu_vm_pte_funcs {
29097b2e202SAlex Deucher 	/* copy pte entries from GART */
29197b2e202SAlex Deucher 	void (*copy_pte)(struct amdgpu_ib *ib,
29297b2e202SAlex Deucher 			 uint64_t pe, uint64_t src,
29397b2e202SAlex Deucher 			 unsigned count);
29497b2e202SAlex Deucher 	/* write pte one entry at a time with addr mapping */
295de9ea7bdSChristian König 	void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
296de9ea7bdSChristian König 			  uint64_t value, unsigned count,
297de9ea7bdSChristian König 			  uint32_t incr);
29897b2e202SAlex Deucher 	/* for linear pte/pde updates without addr mapping */
29997b2e202SAlex Deucher 	void (*set_pte_pde)(struct amdgpu_ib *ib,
30097b2e202SAlex Deucher 			    uint64_t pe,
30197b2e202SAlex Deucher 			    uint64_t addr, unsigned count,
3026b777607SChunming Zhou 			    uint32_t incr, uint64_t flags);
30397b2e202SAlex Deucher };
30497b2e202SAlex Deucher 
30597b2e202SAlex Deucher /* provided by the gmc block */
30697b2e202SAlex Deucher struct amdgpu_gart_funcs {
30797b2e202SAlex Deucher 	/* flush the vm tlb via mmio */
30897b2e202SAlex Deucher 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
30997b2e202SAlex Deucher 			      uint32_t vmid);
31097b2e202SAlex Deucher 	/* write pte/pde updates using the cpu */
31197b2e202SAlex Deucher 	int (*set_pte_pde)(struct amdgpu_device *adev,
31297b2e202SAlex Deucher 			   void *cpu_pt_addr, /* cpu addr of page table */
31397b2e202SAlex Deucher 			   uint32_t gpu_page_idx, /* pte/pde to update */
31497b2e202SAlex Deucher 			   uint64_t addr, /* addr to write into pte/pde */
3156b777607SChunming Zhou 			   uint64_t flags); /* access flags */
316284710faSChristian König 	/* enable/disable PRT support */
317284710faSChristian König 	void (*set_prt)(struct amdgpu_device *adev, bool enable);
3185463545bSAlex Xie 	/* set pte flags based per asic */
3195463545bSAlex Xie 	uint64_t (*get_vm_pte_flags)(struct amdgpu_device *adev,
3205463545bSAlex Xie 				     uint32_t flags);
321b1166325SChristian König 	/* get the pde for a given mc addr */
322b1166325SChristian König 	u64 (*get_vm_pde)(struct amdgpu_device *adev, u64 addr);
32303f89febSChristian König 	uint32_t (*get_invalidate_req)(unsigned int vm_id);
324e60f8db5SAlex Xie };
325e60f8db5SAlex Xie 
32697b2e202SAlex Deucher /* provided by the ih block */
32797b2e202SAlex Deucher struct amdgpu_ih_funcs {
32897b2e202SAlex Deucher 	/* ring read/write ptr handling, called from interrupt context */
32997b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_device *adev);
33097b2e202SAlex Deucher 	void (*decode_iv)(struct amdgpu_device *adev,
33197b2e202SAlex Deucher 			  struct amdgpu_iv_entry *entry);
33297b2e202SAlex Deucher 	void (*set_rptr)(struct amdgpu_device *adev);
33397b2e202SAlex Deucher };
33497b2e202SAlex Deucher 
33597b2e202SAlex Deucher /*
33697b2e202SAlex Deucher  * BIOS.
33797b2e202SAlex Deucher  */
33897b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
33997b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
34097b2e202SAlex Deucher 
34197b2e202SAlex Deucher /*
34297b2e202SAlex Deucher  * Dummy page
34397b2e202SAlex Deucher  */
34497b2e202SAlex Deucher struct amdgpu_dummy_page {
34597b2e202SAlex Deucher 	struct page	*page;
34697b2e202SAlex Deucher 	dma_addr_t	addr;
34797b2e202SAlex Deucher };
34897b2e202SAlex Deucher int amdgpu_dummy_page_init(struct amdgpu_device *adev);
34997b2e202SAlex Deucher void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
35097b2e202SAlex Deucher 
35197b2e202SAlex Deucher 
35297b2e202SAlex Deucher /*
35397b2e202SAlex Deucher  * Clocks
35497b2e202SAlex Deucher  */
35597b2e202SAlex Deucher 
35697b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
35797b2e202SAlex Deucher 
35897b2e202SAlex Deucher struct amdgpu_clock {
35997b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
36097b2e202SAlex Deucher 	struct amdgpu_pll spll;
36197b2e202SAlex Deucher 	struct amdgpu_pll mpll;
36297b2e202SAlex Deucher 	/* 10 Khz units */
36397b2e202SAlex Deucher 	uint32_t default_mclk;
36497b2e202SAlex Deucher 	uint32_t default_sclk;
36597b2e202SAlex Deucher 	uint32_t default_dispclk;
36697b2e202SAlex Deucher 	uint32_t current_dispclk;
36797b2e202SAlex Deucher 	uint32_t dp_extclk;
36897b2e202SAlex Deucher 	uint32_t max_pixel_clock;
36997b2e202SAlex Deucher };
37097b2e202SAlex Deucher 
37197b2e202SAlex Deucher /*
372c632d799SFlora Cui  * BO.
37397b2e202SAlex Deucher  */
37497b2e202SAlex Deucher struct amdgpu_bo_list_entry {
37597b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
37697b2e202SAlex Deucher 	struct ttm_validate_buffer	tv;
37797b2e202SAlex Deucher 	struct amdgpu_bo_va		*bo_va;
37897b2e202SAlex Deucher 	uint32_t			priority;
3792f568dbdSChristian König 	struct page			**user_pages;
3802f568dbdSChristian König 	int				user_invalidated;
38197b2e202SAlex Deucher };
38297b2e202SAlex Deucher 
38397b2e202SAlex Deucher struct amdgpu_bo_va_mapping {
38497b2e202SAlex Deucher 	struct list_head		list;
385a9f87f64SChristian König 	struct rb_node			rb;
386a9f87f64SChristian König 	uint64_t			start;
387a9f87f64SChristian König 	uint64_t			last;
388a9f87f64SChristian König 	uint64_t			__subtree_last;
38997b2e202SAlex Deucher 	uint64_t			offset;
390268c3001SChristian König 	uint64_t			flags;
39197b2e202SAlex Deucher };
39297b2e202SAlex Deucher 
39397b2e202SAlex Deucher /* bo virtual addresses in a specific vm */
39497b2e202SAlex Deucher struct amdgpu_bo_va {
39597b2e202SAlex Deucher 	/* protected by bo being reserved */
39697b2e202SAlex Deucher 	struct list_head		bo_list;
397f54d1867SChris Wilson 	struct dma_fence	        *last_pt_update;
39897b2e202SAlex Deucher 	unsigned			ref_count;
39997b2e202SAlex Deucher 
4007fc11959SChristian König 	/* protected by vm mutex and spinlock */
40197b2e202SAlex Deucher 	struct list_head		vm_status;
40297b2e202SAlex Deucher 
4037fc11959SChristian König 	/* mappings for this bo_va */
4047fc11959SChristian König 	struct list_head		invalids;
4057fc11959SChristian König 	struct list_head		valids;
4067fc11959SChristian König 
40797b2e202SAlex Deucher 	/* constant after initialization */
40897b2e202SAlex Deucher 	struct amdgpu_vm		*vm;
40997b2e202SAlex Deucher 	struct amdgpu_bo		*bo;
41097b2e202SAlex Deucher };
41197b2e202SAlex Deucher 
4127e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX		0x3
4137e5a547fSChunming Zhou 
41497b2e202SAlex Deucher struct amdgpu_bo {
41597b2e202SAlex Deucher 	/* Protected by tbo.reserved */
4161ea863fdSChristian König 	u32				prefered_domains;
4171ea863fdSChristian König 	u32				allowed_domains;
4187e5a547fSChunming Zhou 	struct ttm_place		placements[AMDGPU_GEM_DOMAIN_MAX + 1];
41997b2e202SAlex Deucher 	struct ttm_placement		placement;
42097b2e202SAlex Deucher 	struct ttm_buffer_object	tbo;
42197b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		kmap;
42297b2e202SAlex Deucher 	u64				flags;
42397b2e202SAlex Deucher 	unsigned			pin_count;
42497b2e202SAlex Deucher 	void				*kptr;
42597b2e202SAlex Deucher 	u64				tiling_flags;
42697b2e202SAlex Deucher 	u64				metadata_flags;
42797b2e202SAlex Deucher 	void				*metadata;
42897b2e202SAlex Deucher 	u32				metadata_size;
4298e94a46cSMario Kleiner 	unsigned			prime_shared_count;
43097b2e202SAlex Deucher 	/* list of all virtual address to which this bo
43197b2e202SAlex Deucher 	 * is associated to
43297b2e202SAlex Deucher 	 */
43397b2e202SAlex Deucher 	struct list_head		va;
43497b2e202SAlex Deucher 	/* Constant after initialization */
43597b2e202SAlex Deucher 	struct drm_gem_object		gem_base;
43682b9c55bSChristian König 	struct amdgpu_bo		*parent;
437e7893c4bSChunming Zhou 	struct amdgpu_bo		*shadow;
43897b2e202SAlex Deucher 
43997b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		dma_buf_vmap;
44097b2e202SAlex Deucher 	struct amdgpu_mn		*mn;
44197b2e202SAlex Deucher 	struct list_head		mn_list;
4420c4e7fa5SChunming Zhou 	struct list_head		shadow_list;
44397b2e202SAlex Deucher };
44497b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
44597b2e202SAlex Deucher 
44697b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj);
44797b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj,
44897b2e202SAlex Deucher 				struct drm_file *file_priv);
44997b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj,
45097b2e202SAlex Deucher 				struct drm_file *file_priv);
45197b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
45297b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
4534d9c514dSChristian König struct drm_gem_object *
4544d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
45597b2e202SAlex Deucher 				 struct dma_buf_attachment *attach,
45697b2e202SAlex Deucher 				 struct sg_table *sg);
45797b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
45897b2e202SAlex Deucher 					struct drm_gem_object *gobj,
45997b2e202SAlex Deucher 					int flags);
46097b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
46197b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
46297b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
46397b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
46497b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
46597b2e202SAlex Deucher int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
46697b2e202SAlex Deucher 
46797b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
46897b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
46997b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
47097b2e202SAlex Deucher  * locking.
47197b2e202SAlex Deucher  *
47297b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
47397b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
47497b2e202SAlex Deucher  * offset).
47597b2e202SAlex Deucher  *
47697b2e202SAlex Deucher  * When allocating new object we first check if there is room at
47797b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
47897b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
47997b2e202SAlex Deucher  *
48097b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
48197b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
48297b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
48397b2e202SAlex Deucher  *
48497b2e202SAlex Deucher  * Alignment can't be bigger than page size.
48597b2e202SAlex Deucher  *
48697b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
48797b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
48897b2e202SAlex Deucher  * alignment).
48997b2e202SAlex Deucher  */
4906ba60b89SChristian König 
4916ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS	32
4926ba60b89SChristian König 
49397b2e202SAlex Deucher struct amdgpu_sa_manager {
49497b2e202SAlex Deucher 	wait_queue_head_t	wq;
49597b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
49697b2e202SAlex Deucher 	struct list_head	*hole;
4976ba60b89SChristian König 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
49897b2e202SAlex Deucher 	struct list_head	olist;
49997b2e202SAlex Deucher 	unsigned		size;
50097b2e202SAlex Deucher 	uint64_t		gpu_addr;
50197b2e202SAlex Deucher 	void			*cpu_ptr;
50297b2e202SAlex Deucher 	uint32_t		domain;
50397b2e202SAlex Deucher 	uint32_t		align;
50497b2e202SAlex Deucher };
50597b2e202SAlex Deucher 
50697b2e202SAlex Deucher /* sub-allocation buffer */
50797b2e202SAlex Deucher struct amdgpu_sa_bo {
50897b2e202SAlex Deucher 	struct list_head		olist;
50997b2e202SAlex Deucher 	struct list_head		flist;
51097b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
51197b2e202SAlex Deucher 	unsigned			soffset;
51297b2e202SAlex Deucher 	unsigned			eoffset;
513f54d1867SChris Wilson 	struct dma_fence	        *fence;
51497b2e202SAlex Deucher };
51597b2e202SAlex Deucher 
51697b2e202SAlex Deucher /*
51797b2e202SAlex Deucher  * GEM objects.
51897b2e202SAlex Deucher  */
519418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev);
52097b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
52197b2e202SAlex Deucher 				int alignment, u32 initial_domain,
52297b2e202SAlex Deucher 				u64 flags, bool kernel,
52397b2e202SAlex Deucher 				struct drm_gem_object **obj);
52497b2e202SAlex Deucher 
52597b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv,
52697b2e202SAlex Deucher 			    struct drm_device *dev,
52797b2e202SAlex Deucher 			    struct drm_mode_create_dumb *args);
52897b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp,
52997b2e202SAlex Deucher 			  struct drm_device *dev,
53097b2e202SAlex Deucher 			  uint32_t handle, uint64_t *offset_p);
531d573de2dSRex Zhu int amdgpu_fence_slab_init(void);
532d573de2dSRex Zhu void amdgpu_fence_slab_fini(void);
53397b2e202SAlex Deucher 
53497b2e202SAlex Deucher /*
53597b2e202SAlex Deucher  * GART structures, functions & helpers
53697b2e202SAlex Deucher  */
53797b2e202SAlex Deucher struct amdgpu_mc;
53897b2e202SAlex Deucher 
53997b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SIZE 4096
54097b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
54197b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SHIFT 12
54297b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
54397b2e202SAlex Deucher 
54497b2e202SAlex Deucher struct amdgpu_gart {
54597b2e202SAlex Deucher 	dma_addr_t			table_addr;
54697b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
54797b2e202SAlex Deucher 	void				*ptr;
54897b2e202SAlex Deucher 	unsigned			num_gpu_pages;
54997b2e202SAlex Deucher 	unsigned			num_cpu_pages;
55097b2e202SAlex Deucher 	unsigned			table_size;
551a1d29476SChristian König #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
55297b2e202SAlex Deucher 	struct page			**pages;
553a1d29476SChristian König #endif
55497b2e202SAlex Deucher 	bool				ready;
5554b98e0c4SAlex Xie 
5564b98e0c4SAlex Xie 	/* Asic default pte flags */
5574b98e0c4SAlex Xie 	uint64_t			gart_pte_flags;
5584b98e0c4SAlex Xie 
55997b2e202SAlex Deucher 	const struct amdgpu_gart_funcs *gart_funcs;
56097b2e202SAlex Deucher };
56197b2e202SAlex Deucher 
56297b2e202SAlex Deucher int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
56397b2e202SAlex Deucher void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
56497b2e202SAlex Deucher int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
56597b2e202SAlex Deucher void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
56697b2e202SAlex Deucher int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
56797b2e202SAlex Deucher void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
56897b2e202SAlex Deucher int amdgpu_gart_init(struct amdgpu_device *adev);
56997b2e202SAlex Deucher void amdgpu_gart_fini(struct amdgpu_device *adev);
570738f64ccSRoger.He int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
57197b2e202SAlex Deucher 			int pages);
572cab0b8d5SFelix Kuehling int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
57397b2e202SAlex Deucher 		     int pages, struct page **pagelist,
5746b777607SChunming Zhou 		     dma_addr_t *dma_addr, uint64_t flags);
5752c0d7318SChunming Zhou int amdgpu_ttm_recover_gart(struct amdgpu_device *adev);
57697b2e202SAlex Deucher 
57797b2e202SAlex Deucher /*
578e60f8db5SAlex Xie  * VMHUB structures, functions & helpers
579e60f8db5SAlex Xie  */
580e60f8db5SAlex Xie struct amdgpu_vmhub {
581e60f8db5SAlex Xie 	uint32_t	ctx0_ptb_addr_lo32;
582e60f8db5SAlex Xie 	uint32_t	ctx0_ptb_addr_hi32;
583e60f8db5SAlex Xie 	uint32_t	vm_inv_eng0_req;
584e60f8db5SAlex Xie 	uint32_t	vm_inv_eng0_ack;
585e60f8db5SAlex Xie 	uint32_t	vm_context0_cntl;
586e60f8db5SAlex Xie 	uint32_t	vm_l2_pro_fault_status;
587e60f8db5SAlex Xie 	uint32_t	vm_l2_pro_fault_cntl;
588e60f8db5SAlex Xie };
589e60f8db5SAlex Xie 
590e60f8db5SAlex Xie /*
59197b2e202SAlex Deucher  * GPU MC structures, functions & helpers
59297b2e202SAlex Deucher  */
59397b2e202SAlex Deucher struct amdgpu_mc {
59497b2e202SAlex Deucher 	resource_size_t		aper_size;
59597b2e202SAlex Deucher 	resource_size_t		aper_base;
59697b2e202SAlex Deucher 	resource_size_t		agp_base;
59797b2e202SAlex Deucher 	/* for some chips with <= 32MB we need to lie
59897b2e202SAlex Deucher 	 * about vram size near mc fb location */
59997b2e202SAlex Deucher 	u64			mc_vram_size;
60097b2e202SAlex Deucher 	u64			visible_vram_size;
60197b2e202SAlex Deucher 	u64			gtt_size;
60297b2e202SAlex Deucher 	u64			gtt_start;
60397b2e202SAlex Deucher 	u64			gtt_end;
60497b2e202SAlex Deucher 	u64			vram_start;
60597b2e202SAlex Deucher 	u64			vram_end;
60697b2e202SAlex Deucher 	unsigned		vram_width;
60797b2e202SAlex Deucher 	u64			real_vram_size;
60897b2e202SAlex Deucher 	int			vram_mtrr;
60997b2e202SAlex Deucher 	u64                     gtt_base_align;
61097b2e202SAlex Deucher 	u64                     mc_mask;
61197b2e202SAlex Deucher 	const struct firmware   *fw;	/* MC firmware */
61297b2e202SAlex Deucher 	uint32_t                fw_version;
61397b2e202SAlex Deucher 	struct amdgpu_irq_src	vm_fault;
61481c59f54SKen Wang 	uint32_t		vram_type;
61550b0197aSChunming Zhou 	uint32_t                srbm_soft_reset;
61650b0197aSChunming Zhou 	struct amdgpu_mode_mc_save save;
617f7c35abeSChristian König 	bool			prt_warning;
618916910adSHuang Rui 	uint64_t		stolen_size;
6198fe73328SJunwei Zhang 	/* apertures */
6208fe73328SJunwei Zhang 	u64					shared_aperture_start;
6218fe73328SJunwei Zhang 	u64					shared_aperture_end;
6228fe73328SJunwei Zhang 	u64					private_aperture_start;
6238fe73328SJunwei Zhang 	u64					private_aperture_end;
624e60f8db5SAlex Xie 	/* protects concurrent invalidation */
625e60f8db5SAlex Xie 	spinlock_t		invalidate_lock;
62697b2e202SAlex Deucher };
62797b2e202SAlex Deucher 
62897b2e202SAlex Deucher /*
62997b2e202SAlex Deucher  * GPU doorbell structures, functions & helpers
63097b2e202SAlex Deucher  */
63197b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
63297b2e202SAlex Deucher {
63397b2e202SAlex Deucher 	AMDGPU_DOORBELL_KIQ                     = 0x000,
63497b2e202SAlex Deucher 	AMDGPU_DOORBELL_HIQ                     = 0x001,
63597b2e202SAlex Deucher 	AMDGPU_DOORBELL_DIQ                     = 0x002,
63697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
63797b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
63897b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
63997b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
64097b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
64197b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
64297b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
64397b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
64497b2e202SAlex Deucher 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
64597b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
64697b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
64797b2e202SAlex Deucher 	AMDGPU_DOORBELL_IH                      = 0x1E8,
64897b2e202SAlex Deucher 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
64997b2e202SAlex Deucher 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
65097b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT;
65197b2e202SAlex Deucher 
65297b2e202SAlex Deucher struct amdgpu_doorbell {
65397b2e202SAlex Deucher 	/* doorbell mmio */
65497b2e202SAlex Deucher 	resource_size_t		base;
65597b2e202SAlex Deucher 	resource_size_t		size;
65697b2e202SAlex Deucher 	u32 __iomem		*ptr;
65797b2e202SAlex Deucher 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
65897b2e202SAlex Deucher };
65997b2e202SAlex Deucher 
66039807b93SKen Wang /*
66139807b93SKen Wang  * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
66239807b93SKen Wang  */
66339807b93SKen Wang typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
66439807b93SKen Wang {
66539807b93SKen Wang 	/*
66639807b93SKen Wang 	 * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
66739807b93SKen Wang 	 * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
66839807b93SKen Wang 	 *  Compute related doorbells are allocated from 0x00 to 0x8a
66939807b93SKen Wang 	 */
67039807b93SKen Wang 
67139807b93SKen Wang 
67239807b93SKen Wang 	/* kernel scheduling */
67339807b93SKen Wang 	AMDGPU_DOORBELL64_KIQ                     = 0x00,
67439807b93SKen Wang 
67539807b93SKen Wang 	/* HSA interface queue and debug queue */
67639807b93SKen Wang 	AMDGPU_DOORBELL64_HIQ                     = 0x01,
67739807b93SKen Wang 	AMDGPU_DOORBELL64_DIQ                     = 0x02,
67839807b93SKen Wang 
67939807b93SKen Wang 	/* Compute engines */
68039807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING0               = 0x03,
68139807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING1               = 0x04,
68239807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING2               = 0x05,
68339807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING3               = 0x06,
68439807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING4               = 0x07,
68539807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING5               = 0x08,
68639807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING6               = 0x09,
68739807b93SKen Wang 	AMDGPU_DOORBELL64_MEC_RING7               = 0x0a,
68839807b93SKen Wang 
68939807b93SKen Wang 	/* User queue doorbell range (128 doorbells) */
69039807b93SKen Wang 	AMDGPU_DOORBELL64_USERQUEUE_START         = 0x0b,
69139807b93SKen Wang 	AMDGPU_DOORBELL64_USERQUEUE_END           = 0x8a,
69239807b93SKen Wang 
69339807b93SKen Wang 	/* Graphics engine */
69439807b93SKen Wang 	AMDGPU_DOORBELL64_GFX_RING0               = 0x8b,
69539807b93SKen Wang 
69639807b93SKen Wang 	/*
69739807b93SKen Wang 	 * Other graphics doorbells can be allocated here: from 0x8c to 0xef
69839807b93SKen Wang 	 * Graphics voltage island aperture 1
69939807b93SKen Wang 	 * default non-graphics QWORD index is 0xF0 - 0xFF inclusive
70039807b93SKen Wang 	 */
70139807b93SKen Wang 
70239807b93SKen Wang 	/* sDMA engines */
70339807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_ENGINE0            = 0xF0,
70439807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0     = 0xF1,
70539807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_ENGINE1            = 0xF2,
70639807b93SKen Wang 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1     = 0xF3,
70739807b93SKen Wang 
70839807b93SKen Wang 	/* Interrupt handler */
70939807b93SKen Wang 	AMDGPU_DOORBELL64_IH                      = 0xF4,  /* For legacy interrupt ring buffer */
71039807b93SKen Wang 	AMDGPU_DOORBELL64_IH_RING1                = 0xF5,  /* For page migration request log */
71139807b93SKen Wang 	AMDGPU_DOORBELL64_IH_RING2                = 0xF6,  /* For page migration translation/invalidation log */
71239807b93SKen Wang 
713e6b3ecb4SMonk Liu 	/* VCN engine use 32 bits doorbell  */
714e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN0_1                  = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
715e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN2_3                  = 0xF9,
716e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN4_5                  = 0xFA,
717e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_VCN6_7                  = 0xFB,
718e6b3ecb4SMonk Liu 
719e6b3ecb4SMonk Liu 	/* overlap the doorbell assignment with VCN as they are  mutually exclusive
720e6b3ecb4SMonk Liu 	 * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
721e6b3ecb4SMonk Liu 	 */
722e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_RING0_1                 = 0xF8,
723e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_RING2_3                 = 0xF9,
724e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_RING4_5                 = 0xFA,
725e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_RING6_7                 = 0xFB,
726e6b3ecb4SMonk Liu 
727e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_UVD_RING0_1             = 0xFC,
728e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_UVD_RING2_3             = 0xFD,
729e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_UVD_RING4_5             = 0xFE,
730e6b3ecb4SMonk Liu 	AMDGPU_DOORBELL64_UVD_RING6_7             = 0xFF,
73139807b93SKen Wang 
73239807b93SKen Wang 	AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
73339807b93SKen Wang 	AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
73439807b93SKen Wang } AMDGPU_DOORBELL64_ASSIGNMENT;
73539807b93SKen Wang 
73639807b93SKen Wang 
73797b2e202SAlex Deucher void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
73897b2e202SAlex Deucher 				phys_addr_t *aperture_base,
73997b2e202SAlex Deucher 				size_t *aperture_size,
74097b2e202SAlex Deucher 				size_t *start_offset);
74197b2e202SAlex Deucher 
74297b2e202SAlex Deucher /*
74397b2e202SAlex Deucher  * IRQS.
74497b2e202SAlex Deucher  */
74597b2e202SAlex Deucher 
74697b2e202SAlex Deucher struct amdgpu_flip_work {
747325cbba1SMichel Dänzer 	struct delayed_work		flip_work;
74897b2e202SAlex Deucher 	struct work_struct		unpin_work;
74997b2e202SAlex Deucher 	struct amdgpu_device		*adev;
75097b2e202SAlex Deucher 	int				crtc_id;
751325cbba1SMichel Dänzer 	u32				target_vblank;
75297b2e202SAlex Deucher 	uint64_t			base;
75397b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
754765e7fbfSChristian König 	struct amdgpu_bo		*old_abo;
755f54d1867SChris Wilson 	struct dma_fence		*excl;
7561ffd2652SChristian König 	unsigned			shared_count;
757f54d1867SChris Wilson 	struct dma_fence		**shared;
758f54d1867SChris Wilson 	struct dma_fence_cb		cb;
759cb9e59d7SAlex Deucher 	bool				async;
76097b2e202SAlex Deucher };
76197b2e202SAlex Deucher 
76297b2e202SAlex Deucher 
76397b2e202SAlex Deucher /*
76497b2e202SAlex Deucher  * CP & rings.
76597b2e202SAlex Deucher  */
76697b2e202SAlex Deucher 
76797b2e202SAlex Deucher struct amdgpu_ib {
76897b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
76997b2e202SAlex Deucher 	uint32_t			length_dw;
77097b2e202SAlex Deucher 	uint64_t			gpu_addr;
77197b2e202SAlex Deucher 	uint32_t			*ptr;
772de807f81SJammy Zhou 	uint32_t			flags;
77397b2e202SAlex Deucher };
77497b2e202SAlex Deucher 
77562250a91SNils Wallménius extern const struct amd_sched_backend_ops amdgpu_sched_ops;
776c1b69ed0SChunming Zhou 
77750838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
778c5637837SMonk Liu 		     struct amdgpu_job **job, struct amdgpu_vm *vm);
779d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
780d71518b5SChristian König 			     struct amdgpu_job **job);
781b6723c8dSMonk Liu 
782a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job);
78350838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job);
784d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
7852bd9ccfaSChristian König 		      struct amd_sched_entity *entity, void *owner,
786f54d1867SChris Wilson 		      struct dma_fence **f);
7878b4fb00bSChristian König 
78897b2e202SAlex Deucher /*
789effd924dSAndres Rodriguez  * Queue manager
790effd924dSAndres Rodriguez  */
791effd924dSAndres Rodriguez struct amdgpu_queue_mapper {
792effd924dSAndres Rodriguez 	int 		hw_ip;
793effd924dSAndres Rodriguez 	struct mutex	lock;
794effd924dSAndres Rodriguez 	/* protected by lock */
795effd924dSAndres Rodriguez 	struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
796effd924dSAndres Rodriguez };
797effd924dSAndres Rodriguez 
798effd924dSAndres Rodriguez struct amdgpu_queue_mgr {
799effd924dSAndres Rodriguez 	struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
800effd924dSAndres Rodriguez };
801effd924dSAndres Rodriguez 
802effd924dSAndres Rodriguez int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
803effd924dSAndres Rodriguez 			  struct amdgpu_queue_mgr *mgr);
804effd924dSAndres Rodriguez int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
805effd924dSAndres Rodriguez 			  struct amdgpu_queue_mgr *mgr);
806effd924dSAndres Rodriguez int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
807effd924dSAndres Rodriguez 			 struct amdgpu_queue_mgr *mgr,
808effd924dSAndres Rodriguez 			 int hw_ip, int instance, int ring,
809effd924dSAndres Rodriguez 			 struct amdgpu_ring **out_ring);
810effd924dSAndres Rodriguez 
811effd924dSAndres Rodriguez /*
81297b2e202SAlex Deucher  * context related structures
81397b2e202SAlex Deucher  */
81497b2e202SAlex Deucher 
81521c16bf6SChristian König struct amdgpu_ctx_ring {
81621c16bf6SChristian König 	uint64_t		sequence;
817f54d1867SChris Wilson 	struct dma_fence	**fences;
81891404fb2SChristian König 	struct amd_sched_entity	entity;
81921c16bf6SChristian König };
82021c16bf6SChristian König 
82197b2e202SAlex Deucher struct amdgpu_ctx {
82297b2e202SAlex Deucher 	struct kref		refcount;
8239cb7e5a9SChunming Zhou 	struct amdgpu_device    *adev;
824effd924dSAndres Rodriguez 	struct amdgpu_queue_mgr queue_mgr;
825d94aed5aSMarek Olšák 	unsigned		reset_counter;
82621c16bf6SChristian König 	spinlock_t		ring_lock;
827f54d1867SChris Wilson 	struct dma_fence	**fences;
82821c16bf6SChristian König 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
829753ad49cSMonk Liu 	bool preamble_presented;
83097b2e202SAlex Deucher };
83197b2e202SAlex Deucher 
83297b2e202SAlex Deucher struct amdgpu_ctx_mgr {
83397b2e202SAlex Deucher 	struct amdgpu_device	*adev;
8340147ee0fSMarek Olšák 	struct mutex		lock;
8350b492a4cSAlex Deucher 	/* protected by lock */
8360b492a4cSAlex Deucher 	struct idr		ctx_handles;
83797b2e202SAlex Deucher };
83897b2e202SAlex Deucher 
8390b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
8400b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
8410b492a4cSAlex Deucher 
84221c16bf6SChristian König uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
843f54d1867SChris Wilson 			      struct dma_fence *fence);
844f54d1867SChris Wilson struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
84521c16bf6SChristian König 				   struct amdgpu_ring *ring, uint64_t seq);
84621c16bf6SChristian König 
8470b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
8480b492a4cSAlex Deucher 		     struct drm_file *filp);
8490b492a4cSAlex Deucher 
850efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
851efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
8520b492a4cSAlex Deucher 
85397b2e202SAlex Deucher /*
85497b2e202SAlex Deucher  * file private structure
85597b2e202SAlex Deucher  */
85697b2e202SAlex Deucher 
85797b2e202SAlex Deucher struct amdgpu_fpriv {
85897b2e202SAlex Deucher 	struct amdgpu_vm	vm;
859b85891bdSJunwei Zhang 	struct amdgpu_bo_va	*prt_va;
86097b2e202SAlex Deucher 	struct mutex		bo_list_lock;
86197b2e202SAlex Deucher 	struct idr		bo_list_handles;
86297b2e202SAlex Deucher 	struct amdgpu_ctx_mgr	ctx_mgr;
863f1892138SChunming Zhou 	u32			vram_lost_counter;
86497b2e202SAlex Deucher };
86597b2e202SAlex Deucher 
86697b2e202SAlex Deucher /*
86797b2e202SAlex Deucher  * residency list
86897b2e202SAlex Deucher  */
86997b2e202SAlex Deucher 
87097b2e202SAlex Deucher struct amdgpu_bo_list {
87197b2e202SAlex Deucher 	struct mutex lock;
87297b2e202SAlex Deucher 	struct amdgpu_bo *gds_obj;
87397b2e202SAlex Deucher 	struct amdgpu_bo *gws_obj;
87497b2e202SAlex Deucher 	struct amdgpu_bo *oa_obj;
875211dff55SChristian König 	unsigned first_userptr;
87697b2e202SAlex Deucher 	unsigned num_entries;
87797b2e202SAlex Deucher 	struct amdgpu_bo_list_entry *array;
87897b2e202SAlex Deucher };
87997b2e202SAlex Deucher 
88097b2e202SAlex Deucher struct amdgpu_bo_list *
88197b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
882636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
883636ce25cSChristian König 			     struct list_head *validated);
88497b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
88597b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
88697b2e202SAlex Deucher 
88797b2e202SAlex Deucher /*
88897b2e202SAlex Deucher  * GFX stuff
88997b2e202SAlex Deucher  */
89097b2e202SAlex Deucher #include "clearstate_defs.h"
89197b2e202SAlex Deucher 
89279e5412cSAlex Deucher struct amdgpu_rlc_funcs {
89379e5412cSAlex Deucher 	void (*enter_safe_mode)(struct amdgpu_device *adev);
89479e5412cSAlex Deucher 	void (*exit_safe_mode)(struct amdgpu_device *adev);
89579e5412cSAlex Deucher };
89679e5412cSAlex Deucher 
89797b2e202SAlex Deucher struct amdgpu_rlc {
89897b2e202SAlex Deucher 	/* for power gating */
89997b2e202SAlex Deucher 	struct amdgpu_bo	*save_restore_obj;
90097b2e202SAlex Deucher 	uint64_t		save_restore_gpu_addr;
90197b2e202SAlex Deucher 	volatile uint32_t	*sr_ptr;
90297b2e202SAlex Deucher 	const u32               *reg_list;
90397b2e202SAlex Deucher 	u32                     reg_list_size;
90497b2e202SAlex Deucher 	/* for clear state */
90597b2e202SAlex Deucher 	struct amdgpu_bo	*clear_state_obj;
90697b2e202SAlex Deucher 	uint64_t		clear_state_gpu_addr;
90797b2e202SAlex Deucher 	volatile uint32_t	*cs_ptr;
90897b2e202SAlex Deucher 	const struct cs_section_def   *cs_data;
90997b2e202SAlex Deucher 	u32                     clear_state_size;
91097b2e202SAlex Deucher 	/* for cp tables */
91197b2e202SAlex Deucher 	struct amdgpu_bo	*cp_table_obj;
91297b2e202SAlex Deucher 	uint64_t		cp_table_gpu_addr;
91397b2e202SAlex Deucher 	volatile uint32_t	*cp_table_ptr;
91497b2e202SAlex Deucher 	u32                     cp_table_size;
91579e5412cSAlex Deucher 
91679e5412cSAlex Deucher 	/* safe mode for updating CG/PG state */
91779e5412cSAlex Deucher 	bool in_safe_mode;
91879e5412cSAlex Deucher 	const struct amdgpu_rlc_funcs *funcs;
9192b6cd977SEric Huang 
9202b6cd977SEric Huang 	/* for firmware data */
9212b6cd977SEric Huang 	u32 save_and_restore_offset;
9222b6cd977SEric Huang 	u32 clear_state_descriptor_offset;
9232b6cd977SEric Huang 	u32 avail_scratch_ram_locations;
9242b6cd977SEric Huang 	u32 reg_restore_list_size;
9252b6cd977SEric Huang 	u32 reg_list_format_start;
9262b6cd977SEric Huang 	u32 reg_list_format_separate_start;
9272b6cd977SEric Huang 	u32 starting_offsets_start;
9282b6cd977SEric Huang 	u32 reg_list_format_size_bytes;
9292b6cd977SEric Huang 	u32 reg_list_size_bytes;
9302b6cd977SEric Huang 
9312b6cd977SEric Huang 	u32 *register_list_format;
9322b6cd977SEric Huang 	u32 *register_restore;
93397b2e202SAlex Deucher };
93497b2e202SAlex Deucher 
93578c16834SAndres Rodriguez #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
93678c16834SAndres Rodriguez 
93797b2e202SAlex Deucher struct amdgpu_mec {
93897b2e202SAlex Deucher 	struct amdgpu_bo	*hpd_eop_obj;
93997b2e202SAlex Deucher 	u64			hpd_eop_gpu_addr;
940b1023571SKen Wang 	struct amdgpu_bo	*mec_fw_obj;
941b1023571SKen Wang 	u64			mec_fw_gpu_addr;
94297b2e202SAlex Deucher 	u32 num_mec;
94342794b27SAndres Rodriguez 	u32 num_pipe_per_mec;
94442794b27SAndres Rodriguez 	u32 num_queue_per_pipe;
94559a82d7dSXiangliang Yu 	void			*mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
94678c16834SAndres Rodriguez 
94778c16834SAndres Rodriguez 	/* These are the resources for which amdgpu takes ownership */
94878c16834SAndres Rodriguez 	DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
94997b2e202SAlex Deucher };
95097b2e202SAlex Deucher 
9514e638ae9SXiangliang Yu struct amdgpu_kiq {
9524e638ae9SXiangliang Yu 	u64			eop_gpu_addr;
9534e638ae9SXiangliang Yu 	struct amdgpu_bo	*eop_obj;
954cdf6adb2SShaoyun Liu 	struct mutex		ring_mutex;
9554e638ae9SXiangliang Yu 	struct amdgpu_ring	ring;
9564e638ae9SXiangliang Yu 	struct amdgpu_irq_src	irq;
9574e638ae9SXiangliang Yu };
9584e638ae9SXiangliang Yu 
95997b2e202SAlex Deucher /*
96097b2e202SAlex Deucher  * GPU scratch registers structures, functions & helpers
96197b2e202SAlex Deucher  */
96297b2e202SAlex Deucher struct amdgpu_scratch {
96397b2e202SAlex Deucher 	unsigned		num_reg;
96497b2e202SAlex Deucher 	uint32_t                reg_base;
96550261151SNils Wallménius 	uint32_t		free_mask;
96697b2e202SAlex Deucher };
96797b2e202SAlex Deucher 
96897b2e202SAlex Deucher /*
96997b2e202SAlex Deucher  * GFX configurations
97097b2e202SAlex Deucher  */
971e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SE 4
972e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SH_PER_SE 2
973e3fa7630SAlex Deucher 
974e3fa7630SAlex Deucher struct amdgpu_rb_config {
975e3fa7630SAlex Deucher 	uint32_t rb_backend_disable;
976e3fa7630SAlex Deucher 	uint32_t user_rb_backend_disable;
977e3fa7630SAlex Deucher 	uint32_t raster_config;
978e3fa7630SAlex Deucher 	uint32_t raster_config_1;
979e3fa7630SAlex Deucher };
980e3fa7630SAlex Deucher 
981d0e95758SAndrey Grodzovsky struct gb_addr_config {
982d0e95758SAndrey Grodzovsky 	uint16_t pipe_interleave_size;
983d0e95758SAndrey Grodzovsky 	uint8_t num_pipes;
984d0e95758SAndrey Grodzovsky 	uint8_t max_compress_frags;
985d0e95758SAndrey Grodzovsky 	uint8_t num_banks;
986d0e95758SAndrey Grodzovsky 	uint8_t num_se;
987d0e95758SAndrey Grodzovsky 	uint8_t num_rb_per_se;
988d0e95758SAndrey Grodzovsky };
989d0e95758SAndrey Grodzovsky 
990ea323f88SJunwei Zhang struct amdgpu_gfx_config {
99197b2e202SAlex Deucher 	unsigned max_shader_engines;
99297b2e202SAlex Deucher 	unsigned max_tile_pipes;
99397b2e202SAlex Deucher 	unsigned max_cu_per_sh;
99497b2e202SAlex Deucher 	unsigned max_sh_per_se;
99597b2e202SAlex Deucher 	unsigned max_backends_per_se;
99697b2e202SAlex Deucher 	unsigned max_texture_channel_caches;
99797b2e202SAlex Deucher 	unsigned max_gprs;
99897b2e202SAlex Deucher 	unsigned max_gs_threads;
99997b2e202SAlex Deucher 	unsigned max_hw_contexts;
100097b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_frontend;
100197b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_backend;
100297b2e202SAlex Deucher 	unsigned sc_hiz_tile_fifo_size;
100397b2e202SAlex Deucher 	unsigned sc_earlyz_tile_fifo_size;
100497b2e202SAlex Deucher 
100597b2e202SAlex Deucher 	unsigned num_tile_pipes;
100697b2e202SAlex Deucher 	unsigned backend_enable_mask;
100797b2e202SAlex Deucher 	unsigned mem_max_burst_length_bytes;
100897b2e202SAlex Deucher 	unsigned mem_row_size_in_kb;
100997b2e202SAlex Deucher 	unsigned shader_engine_tile_size;
101097b2e202SAlex Deucher 	unsigned num_gpus;
101197b2e202SAlex Deucher 	unsigned multi_gpu_tile_size;
101297b2e202SAlex Deucher 	unsigned mc_arb_ramcfg;
101397b2e202SAlex Deucher 	unsigned gb_addr_config;
10148f8e00c1SAlex Deucher 	unsigned num_rbs;
1015408bfe7cSJunwei Zhang 	unsigned gs_vgt_table_depth;
1016408bfe7cSJunwei Zhang 	unsigned gs_prim_buffer_depth;
101797b2e202SAlex Deucher 
101897b2e202SAlex Deucher 	uint32_t tile_mode_array[32];
101997b2e202SAlex Deucher 	uint32_t macrotile_mode_array[16];
1020e3fa7630SAlex Deucher 
1021d0e95758SAndrey Grodzovsky 	struct gb_addr_config gb_addr_config_fields;
1022e3fa7630SAlex Deucher 	struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
1023df6e2c4aSJunwei Zhang 
1024df6e2c4aSJunwei Zhang 	/* gfx configure feature */
1025df6e2c4aSJunwei Zhang 	uint32_t double_offchip_lds_buf;
102697b2e202SAlex Deucher };
102797b2e202SAlex Deucher 
10287dae69a2SAlex Deucher struct amdgpu_cu_info {
10297dae69a2SAlex Deucher 	uint32_t number; /* total active CU number */
10307dae69a2SAlex Deucher 	uint32_t ao_cu_mask;
103151fd0370SHawking Zhang 	uint32_t max_waves_per_simd;
1032408bfe7cSJunwei Zhang 	uint32_t wave_front_size;
103351fd0370SHawking Zhang 	uint32_t max_scratch_slots_per_cu;
103451fd0370SHawking Zhang 	uint32_t lds_size;
10357dae69a2SAlex Deucher 	uint32_t bitmap[4][4];
10367dae69a2SAlex Deucher };
10377dae69a2SAlex Deucher 
1038b95e31fdSAlex Deucher struct amdgpu_gfx_funcs {
1039b95e31fdSAlex Deucher 	/* get the gpu clock counter */
1040b95e31fdSAlex Deucher 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
10419559ef5bSTom St Denis 	void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
1042472259f0STom St Denis 	void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);
1043c5a60ce8STom 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);
1044c5a60ce8STom 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);
1045b95e31fdSAlex Deucher };
1046b95e31fdSAlex Deucher 
1047bce23e00SAlex Deucher struct amdgpu_ngg_buf {
1048bce23e00SAlex Deucher 	struct amdgpu_bo	*bo;
1049bce23e00SAlex Deucher 	uint64_t		gpu_addr;
1050bce23e00SAlex Deucher 	uint32_t		size;
1051bce23e00SAlex Deucher 	uint32_t		bo_size;
1052bce23e00SAlex Deucher };
1053bce23e00SAlex Deucher 
1054bce23e00SAlex Deucher enum {
1055af8baf15SGuenter Roeck 	NGG_PRIM = 0,
1056af8baf15SGuenter Roeck 	NGG_POS,
1057af8baf15SGuenter Roeck 	NGG_CNTL,
1058af8baf15SGuenter Roeck 	NGG_PARAM,
1059bce23e00SAlex Deucher 	NGG_BUF_MAX
1060bce23e00SAlex Deucher };
1061bce23e00SAlex Deucher 
1062bce23e00SAlex Deucher struct amdgpu_ngg {
1063bce23e00SAlex Deucher 	struct amdgpu_ngg_buf	buf[NGG_BUF_MAX];
1064bce23e00SAlex Deucher 	uint32_t		gds_reserve_addr;
1065bce23e00SAlex Deucher 	uint32_t		gds_reserve_size;
1066bce23e00SAlex Deucher 	bool			init;
1067bce23e00SAlex Deucher };
1068bce23e00SAlex Deucher 
106997b2e202SAlex Deucher struct amdgpu_gfx {
107097b2e202SAlex Deucher 	struct mutex			gpu_clock_mutex;
1071ea323f88SJunwei Zhang 	struct amdgpu_gfx_config	config;
107297b2e202SAlex Deucher 	struct amdgpu_rlc		rlc;
107397b2e202SAlex Deucher 	struct amdgpu_mec		mec;
10744e638ae9SXiangliang Yu 	struct amdgpu_kiq		kiq;
107597b2e202SAlex Deucher 	struct amdgpu_scratch		scratch;
107697b2e202SAlex Deucher 	const struct firmware		*me_fw;	/* ME firmware */
107797b2e202SAlex Deucher 	uint32_t			me_fw_version;
107897b2e202SAlex Deucher 	const struct firmware		*pfp_fw; /* PFP firmware */
107997b2e202SAlex Deucher 	uint32_t			pfp_fw_version;
108097b2e202SAlex Deucher 	const struct firmware		*ce_fw;	/* CE firmware */
108197b2e202SAlex Deucher 	uint32_t			ce_fw_version;
108297b2e202SAlex Deucher 	const struct firmware		*rlc_fw; /* RLC firmware */
108397b2e202SAlex Deucher 	uint32_t			rlc_fw_version;
108497b2e202SAlex Deucher 	const struct firmware		*mec_fw; /* MEC firmware */
108597b2e202SAlex Deucher 	uint32_t			mec_fw_version;
108697b2e202SAlex Deucher 	const struct firmware		*mec2_fw; /* MEC2 firmware */
108797b2e202SAlex Deucher 	uint32_t			mec2_fw_version;
108802558a00SKen Wang 	uint32_t			me_feature_version;
108902558a00SKen Wang 	uint32_t			ce_feature_version;
109002558a00SKen Wang 	uint32_t			pfp_feature_version;
1091351643d7SJammy Zhou 	uint32_t			rlc_feature_version;
1092351643d7SJammy Zhou 	uint32_t			mec_feature_version;
1093351643d7SJammy Zhou 	uint32_t			mec2_feature_version;
109497b2e202SAlex Deucher 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
109597b2e202SAlex Deucher 	unsigned			num_gfx_rings;
109697b2e202SAlex Deucher 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
109797b2e202SAlex Deucher 	unsigned			num_compute_rings;
109897b2e202SAlex Deucher 	struct amdgpu_irq_src		eop_irq;
109997b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_reg_irq;
110097b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_inst_irq;
110197b2e202SAlex Deucher 	/* gfx status */
110297b2e202SAlex Deucher 	uint32_t			gfx_current_status;
1103a101a899SKen Wang 	/* ce ram size*/
1104a101a899SKen Wang 	unsigned			ce_ram_size;
11057dae69a2SAlex Deucher 	struct amdgpu_cu_info		cu_info;
1106b95e31fdSAlex Deucher 	const struct amdgpu_gfx_funcs	*funcs;
11073d7c6384SChunming Zhou 
11083d7c6384SChunming Zhou 	/* reset mask */
11093d7c6384SChunming Zhou 	uint32_t                        grbm_soft_reset;
11103d7c6384SChunming Zhou 	uint32_t                        srbm_soft_reset;
1111223049cdSMonk Liu 	bool                            in_reset;
1112b4e40676SDavid Panariti 	/* s3/s4 mask */
1113b4e40676SDavid Panariti 	bool                            in_suspend;
1114bce23e00SAlex Deucher 	/* NGG */
1115bce23e00SAlex Deucher 	struct amdgpu_ngg		ngg;
111697b2e202SAlex Deucher };
111797b2e202SAlex Deucher 
1118b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
111997b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
11204d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1121f54d1867SChris Wilson 		    struct dma_fence *f);
1122b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
112350ddc75eSJunwei Zhang 		       struct amdgpu_ib *ibs, struct amdgpu_job *job,
112450ddc75eSJunwei Zhang 		       struct dma_fence **f);
112597b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
112697b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
112797b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
112897b2e202SAlex Deucher 
112997b2e202SAlex Deucher /*
113097b2e202SAlex Deucher  * CS.
113197b2e202SAlex Deucher  */
113297b2e202SAlex Deucher struct amdgpu_cs_chunk {
113397b2e202SAlex Deucher 	uint32_t		chunk_id;
113497b2e202SAlex Deucher 	uint32_t		length_dw;
1135758ac17fSChristian König 	void			*kdata;
113697b2e202SAlex Deucher };
113797b2e202SAlex Deucher 
113897b2e202SAlex Deucher struct amdgpu_cs_parser {
113997b2e202SAlex Deucher 	struct amdgpu_device	*adev;
114097b2e202SAlex Deucher 	struct drm_file		*filp;
11413cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
1142c3cca41eSChristian König 
114397b2e202SAlex Deucher 	/* chunks */
114497b2e202SAlex Deucher 	unsigned		nchunks;
114597b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
1146c3cca41eSChristian König 
114750838c8cSChristian König 	/* scheduler job object */
114850838c8cSChristian König 	struct amdgpu_job	*job;
1149c3cca41eSChristian König 
1150c3cca41eSChristian König 	/* buffer objects */
1151c3cca41eSChristian König 	struct ww_acquire_ctx		ticket;
1152c3cca41eSChristian König 	struct amdgpu_bo_list		*bo_list;
115356467ebfSChristian König 	struct amdgpu_bo_list_entry	vm_pd;
115497b2e202SAlex Deucher 	struct list_head		validated;
1155f54d1867SChris Wilson 	struct dma_fence		*fence;
1156f69f90a1SChristian König 	uint64_t			bytes_moved_threshold;
1157f69f90a1SChristian König 	uint64_t			bytes_moved;
1158662bfa61SChristian König 	struct amdgpu_bo_list_entry	*evictable;
115997b2e202SAlex Deucher 
116097b2e202SAlex Deucher 	/* user fence */
116191acbeb6SChristian König 	struct amdgpu_bo_list_entry	uf_entry;
116297b2e202SAlex Deucher };
116397b2e202SAlex Deucher 
1164753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT          (1 << 0) /* bit set means command submit involves a preamble IB */
1165753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST    (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1166753ad49cSMonk Liu #define AMDGPU_HAVE_CTX_SWITCH              (1 << 2) /* bit set means context switch occured */
1167753ad49cSMonk Liu 
1168bb977d37SChunming Zhou struct amdgpu_job {
1169bb977d37SChunming Zhou 	struct amd_sched_job    base;
1170bb977d37SChunming Zhou 	struct amdgpu_device	*adev;
1171c5637837SMonk Liu 	struct amdgpu_vm	*vm;
1172b07c60c0SChristian König 	struct amdgpu_ring	*ring;
1173e86f9ceeSChristian König 	struct amdgpu_sync	sync;
1174a340c7bcSChunming Zhou 	struct amdgpu_sync	dep_sync;
1175df83d1ebSChunming Zhou 	struct amdgpu_sync	sched_sync;
1176bb977d37SChunming Zhou 	struct amdgpu_ib	*ibs;
1177f54d1867SChris Wilson 	struct dma_fence	*fence; /* the hw fence */
1178753ad49cSMonk Liu 	uint32_t		preamble_status;
1179bb977d37SChunming Zhou 	uint32_t		num_ibs;
1180e2840221SChristian König 	void			*owner;
11813aecd24cSMonk Liu 	uint64_t		fence_ctx; /* the fence_context this job uses */
1182fd53be30SChunming Zhou 	bool                    vm_needs_flush;
1183d88bf583SChristian König 	unsigned		vm_id;
1184d88bf583SChristian König 	uint64_t		vm_pd_addr;
1185d88bf583SChristian König 	uint32_t		gds_base, gds_size;
1186d88bf583SChristian König 	uint32_t		gws_base, gws_size;
1187d88bf583SChristian König 	uint32_t		oa_base, oa_size;
1188758ac17fSChristian König 
1189758ac17fSChristian König 	/* user fence handling */
1190b5f5acbcSChristian König 	uint64_t		uf_addr;
1191758ac17fSChristian König 	uint64_t		uf_sequence;
1192758ac17fSChristian König 
1193bb977d37SChunming Zhou };
1194a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job)		\
1195a6db8a33SJunwei Zhang 		container_of((sched_job), struct amdgpu_job, base)
1196bb977d37SChunming Zhou 
11977270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
11987270f839SChristian König 				      uint32_t ib_idx, int idx)
119997b2e202SAlex Deucher {
120050838c8cSChristian König 	return p->job->ibs[ib_idx].ptr[idx];
120197b2e202SAlex Deucher }
120297b2e202SAlex Deucher 
12037270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
12047270f839SChristian König 				       uint32_t ib_idx, int idx,
12057270f839SChristian König 				       uint32_t value)
12067270f839SChristian König {
120750838c8cSChristian König 	p->job->ibs[ib_idx].ptr[idx] = value;
12087270f839SChristian König }
12097270f839SChristian König 
121097b2e202SAlex Deucher /*
121197b2e202SAlex Deucher  * Writeback
121297b2e202SAlex Deucher  */
121397b2e202SAlex Deucher #define AMDGPU_MAX_WB 1024	/* Reserve at most 1024 WB slots for amdgpu-owned rings. */
121497b2e202SAlex Deucher 
121597b2e202SAlex Deucher struct amdgpu_wb {
121697b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
121797b2e202SAlex Deucher 	volatile uint32_t	*wb;
121897b2e202SAlex Deucher 	uint64_t		gpu_addr;
121997b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
122097b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
122197b2e202SAlex Deucher };
122297b2e202SAlex Deucher 
122397b2e202SAlex Deucher int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
122497b2e202SAlex Deucher void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
12257014285aSKen Wang int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);
12267014285aSKen Wang void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);
122797b2e202SAlex Deucher 
1228d0dd7f0cSAlex Deucher void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1229d0dd7f0cSAlex Deucher 
123097b2e202SAlex Deucher /*
123197b2e202SAlex Deucher  * SDMA
123297b2e202SAlex Deucher  */
1233c113ea1cSAlex Deucher struct amdgpu_sdma_instance {
123497b2e202SAlex Deucher 	/* SDMA firmware */
123597b2e202SAlex Deucher 	const struct firmware	*fw;
123697b2e202SAlex Deucher 	uint32_t		fw_version;
1237cfa2104fSJammy Zhou 	uint32_t		feature_version;
123897b2e202SAlex Deucher 
123997b2e202SAlex Deucher 	struct amdgpu_ring	ring;
124018111de0SJammy Zhou 	bool			burst_nop;
124197b2e202SAlex Deucher };
124297b2e202SAlex Deucher 
1243c113ea1cSAlex Deucher struct amdgpu_sdma {
1244c113ea1cSAlex Deucher 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
124530d1574fSKen Wang #ifdef CONFIG_DRM_AMDGPU_SI
124630d1574fSKen Wang 	//SI DMA has a difference trap irq number for the second engine
124730d1574fSKen Wang 	struct amdgpu_irq_src	trap_irq_1;
124830d1574fSKen Wang #endif
1249c113ea1cSAlex Deucher 	struct amdgpu_irq_src	trap_irq;
1250c113ea1cSAlex Deucher 	struct amdgpu_irq_src	illegal_inst_irq;
1251c113ea1cSAlex Deucher 	int			num_instances;
1252e702a680SChunming Zhou 	uint32_t                    srbm_soft_reset;
1253c113ea1cSAlex Deucher };
1254c113ea1cSAlex Deucher 
125597b2e202SAlex Deucher /*
125697b2e202SAlex Deucher  * Firmware
125797b2e202SAlex Deucher  */
1258e635ee07SHuang Rui enum amdgpu_firmware_load_type {
1259e635ee07SHuang Rui 	AMDGPU_FW_LOAD_DIRECT = 0,
1260e635ee07SHuang Rui 	AMDGPU_FW_LOAD_SMU,
1261e635ee07SHuang Rui 	AMDGPU_FW_LOAD_PSP,
1262e635ee07SHuang Rui };
1263e635ee07SHuang Rui 
126497b2e202SAlex Deucher struct amdgpu_firmware {
126597b2e202SAlex Deucher 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1266e635ee07SHuang Rui 	enum amdgpu_firmware_load_type load_type;
126797b2e202SAlex Deucher 	struct amdgpu_bo *fw_buf;
126897b2e202SAlex Deucher 	unsigned int fw_size;
12692445b227SHuang Rui 	unsigned int max_ucodes;
12700e5ca0d1SHuang Rui 	/* firmwares are loaded by psp instead of smu from vega10 */
12710e5ca0d1SHuang Rui 	const struct amdgpu_psp_funcs *funcs;
12720e5ca0d1SHuang Rui 	struct amdgpu_bo *rbuf;
12730e5ca0d1SHuang Rui 	struct mutex mutex;
127497b2e202SAlex Deucher };
127597b2e202SAlex Deucher 
127697b2e202SAlex Deucher /*
127797b2e202SAlex Deucher  * Benchmarking
127897b2e202SAlex Deucher  */
127997b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
128097b2e202SAlex Deucher 
128197b2e202SAlex Deucher 
128297b2e202SAlex Deucher /*
128397b2e202SAlex Deucher  * Testing
128497b2e202SAlex Deucher  */
128597b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
128697b2e202SAlex Deucher 
128797b2e202SAlex Deucher /*
128897b2e202SAlex Deucher  * MMU Notifier
128997b2e202SAlex Deucher  */
129097b2e202SAlex Deucher #if defined(CONFIG_MMU_NOTIFIER)
129197b2e202SAlex Deucher int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
129297b2e202SAlex Deucher void amdgpu_mn_unregister(struct amdgpu_bo *bo);
129397b2e202SAlex Deucher #else
12941d1106b0SHarry Wentland static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
129597b2e202SAlex Deucher {
129697b2e202SAlex Deucher 	return -ENODEV;
129797b2e202SAlex Deucher }
12981d1106b0SHarry Wentland static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
129997b2e202SAlex Deucher #endif
130097b2e202SAlex Deucher 
130197b2e202SAlex Deucher /*
130297b2e202SAlex Deucher  * Debugfs
130397b2e202SAlex Deucher  */
130497b2e202SAlex Deucher struct amdgpu_debugfs {
130506ab6832SNils Wallménius 	const struct drm_info_list	*files;
130697b2e202SAlex Deucher 	unsigned		num_files;
130797b2e202SAlex Deucher };
130897b2e202SAlex Deucher 
130997b2e202SAlex Deucher int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
131006ab6832SNils Wallménius 			     const struct drm_info_list *files,
131197b2e202SAlex Deucher 			     unsigned nfiles);
131297b2e202SAlex Deucher int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
131397b2e202SAlex Deucher 
131497b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
131597b2e202SAlex Deucher int amdgpu_debugfs_init(struct drm_minor *minor);
131697b2e202SAlex Deucher #endif
131797b2e202SAlex Deucher 
131850ab2533SHuang Rui int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
131950ab2533SHuang Rui 
132097b2e202SAlex Deucher /*
132197b2e202SAlex Deucher  * amdgpu smumgr functions
132297b2e202SAlex Deucher  */
132397b2e202SAlex Deucher struct amdgpu_smumgr_funcs {
132497b2e202SAlex Deucher 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
132597b2e202SAlex Deucher 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
132697b2e202SAlex Deucher 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
132797b2e202SAlex Deucher };
132897b2e202SAlex Deucher 
132997b2e202SAlex Deucher /*
133097b2e202SAlex Deucher  * amdgpu smumgr
133197b2e202SAlex Deucher  */
133297b2e202SAlex Deucher struct amdgpu_smumgr {
133397b2e202SAlex Deucher 	struct amdgpu_bo *toc_buf;
133497b2e202SAlex Deucher 	struct amdgpu_bo *smu_buf;
133597b2e202SAlex Deucher 	/* asic priv smu data */
133697b2e202SAlex Deucher 	void *priv;
133797b2e202SAlex Deucher 	spinlock_t smu_lock;
133897b2e202SAlex Deucher 	/* smumgr functions */
133997b2e202SAlex Deucher 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
134097b2e202SAlex Deucher 	/* ucode loading complete flag */
134197b2e202SAlex Deucher 	uint32_t fw_flags;
134297b2e202SAlex Deucher };
134397b2e202SAlex Deucher 
134497b2e202SAlex Deucher /*
134597b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
134697b2e202SAlex Deucher  */
134797b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
134897b2e202SAlex Deucher 	uint32_t reg_offset;
134997b2e202SAlex Deucher 	bool grbm_indexed;
135097b2e202SAlex Deucher };
135197b2e202SAlex Deucher 
135297b2e202SAlex Deucher /*
135397b2e202SAlex Deucher  * ASIC specific functions.
135497b2e202SAlex Deucher  */
135597b2e202SAlex Deucher struct amdgpu_asic_funcs {
135697b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
13577946b878SAlex Deucher 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
13587946b878SAlex Deucher 				   u8 *bios, u32 length_bytes);
135997b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
136097b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
136197b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
136297b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
136397b2e202SAlex Deucher 	/* get the reference clock */
136497b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
136597b2e202SAlex Deucher 	/* MM block clocks */
136697b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
136797b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1368841686dfSMaruthi Bayyavarapu 	/* static power management */
1369841686dfSMaruthi Bayyavarapu 	int (*get_pcie_lanes)(struct amdgpu_device *adev);
1370841686dfSMaruthi Bayyavarapu 	void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
1371bbf282d8SAlex Deucher 	/* get config memsize register */
1372bbf282d8SAlex Deucher 	u32 (*get_config_memsize)(struct amdgpu_device *adev);
137397b2e202SAlex Deucher };
137497b2e202SAlex Deucher 
137597b2e202SAlex Deucher /*
137697b2e202SAlex Deucher  * IOCTL.
137797b2e202SAlex Deucher  */
137897b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
137997b2e202SAlex Deucher 			    struct drm_file *filp);
138097b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
138197b2e202SAlex Deucher 				struct drm_file *filp);
138297b2e202SAlex Deucher 
138397b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
138497b2e202SAlex Deucher 			  struct drm_file *filp);
138597b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
138697b2e202SAlex Deucher 			struct drm_file *filp);
138797b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
138897b2e202SAlex Deucher 			  struct drm_file *filp);
138997b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
139097b2e202SAlex Deucher 			      struct drm_file *filp);
139197b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
139297b2e202SAlex Deucher 			  struct drm_file *filp);
139397b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
139497b2e202SAlex Deucher 			struct drm_file *filp);
139597b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
139697b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1397eef18a82SJunwei Zhang int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
1398eef18a82SJunwei Zhang 				struct drm_file *filp);
139997b2e202SAlex Deucher 
140097b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
140197b2e202SAlex Deucher 				struct drm_file *filp);
140297b2e202SAlex Deucher 
140397b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
140497b2e202SAlex Deucher struct amdgpu_vram_scratch {
140597b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
140697b2e202SAlex Deucher 	volatile uint32_t		*ptr;
140797b2e202SAlex Deucher 	u64				gpu_addr;
140897b2e202SAlex Deucher };
140997b2e202SAlex Deucher 
141097b2e202SAlex Deucher /*
141197b2e202SAlex Deucher  * ACPI
141297b2e202SAlex Deucher  */
141397b2e202SAlex Deucher struct amdgpu_atif_notification_cfg {
141497b2e202SAlex Deucher 	bool enabled;
141597b2e202SAlex Deucher 	int command_code;
141697b2e202SAlex Deucher };
141797b2e202SAlex Deucher 
141897b2e202SAlex Deucher struct amdgpu_atif_notifications {
141997b2e202SAlex Deucher 	bool display_switch;
142097b2e202SAlex Deucher 	bool expansion_mode_change;
142197b2e202SAlex Deucher 	bool thermal_state;
142297b2e202SAlex Deucher 	bool forced_power_state;
142397b2e202SAlex Deucher 	bool system_power_state;
142497b2e202SAlex Deucher 	bool display_conf_change;
142597b2e202SAlex Deucher 	bool px_gfx_switch;
142697b2e202SAlex Deucher 	bool brightness_change;
142797b2e202SAlex Deucher 	bool dgpu_display_event;
142897b2e202SAlex Deucher };
142997b2e202SAlex Deucher 
143097b2e202SAlex Deucher struct amdgpu_atif_functions {
143197b2e202SAlex Deucher 	bool system_params;
143297b2e202SAlex Deucher 	bool sbios_requests;
143397b2e202SAlex Deucher 	bool select_active_disp;
143497b2e202SAlex Deucher 	bool lid_state;
143597b2e202SAlex Deucher 	bool get_tv_standard;
143697b2e202SAlex Deucher 	bool set_tv_standard;
143797b2e202SAlex Deucher 	bool get_panel_expansion_mode;
143897b2e202SAlex Deucher 	bool set_panel_expansion_mode;
143997b2e202SAlex Deucher 	bool temperature_change;
144097b2e202SAlex Deucher 	bool graphics_device_types;
144197b2e202SAlex Deucher };
144297b2e202SAlex Deucher 
144397b2e202SAlex Deucher struct amdgpu_atif {
144497b2e202SAlex Deucher 	struct amdgpu_atif_notifications notifications;
144597b2e202SAlex Deucher 	struct amdgpu_atif_functions functions;
144697b2e202SAlex Deucher 	struct amdgpu_atif_notification_cfg notification_cfg;
144797b2e202SAlex Deucher 	struct amdgpu_encoder *encoder_for_bl;
144897b2e202SAlex Deucher };
144997b2e202SAlex Deucher 
145097b2e202SAlex Deucher struct amdgpu_atcs_functions {
145197b2e202SAlex Deucher 	bool get_ext_state;
145297b2e202SAlex Deucher 	bool pcie_perf_req;
145397b2e202SAlex Deucher 	bool pcie_dev_rdy;
145497b2e202SAlex Deucher 	bool pcie_bus_width;
145597b2e202SAlex Deucher };
145697b2e202SAlex Deucher 
145797b2e202SAlex Deucher struct amdgpu_atcs {
145897b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
145997b2e202SAlex Deucher };
146097b2e202SAlex Deucher 
146197b2e202SAlex Deucher /*
1462d03846afSChunming Zhou  * CGS
1463d03846afSChunming Zhou  */
1464110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1465110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1466a8fe58ceSMaruthi Bayyavarapu 
1467a8fe58ceSMaruthi Bayyavarapu /*
146897b2e202SAlex Deucher  * Core structure, functions and helpers.
146997b2e202SAlex Deucher  */
147097b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
147197b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
147297b2e202SAlex Deucher 
147397b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
147497b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
147597b2e202SAlex Deucher 
14760c49e0b8SChunming Zhou #define AMDGPU_RESET_MAGIC_NUM 64
147797b2e202SAlex Deucher struct amdgpu_device {
147897b2e202SAlex Deucher 	struct device			*dev;
147997b2e202SAlex Deucher 	struct drm_device		*ddev;
148097b2e202SAlex Deucher 	struct pci_dev			*pdev;
148197b2e202SAlex Deucher 
1482a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP
1483a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_acp		acp;
1484a8fe58ceSMaruthi Bayyavarapu #endif
1485a8fe58ceSMaruthi Bayyavarapu 
148697b2e202SAlex Deucher 	/* ASIC */
14872f7d10b3SJammy Zhou 	enum amd_asic_type		asic_type;
148897b2e202SAlex Deucher 	uint32_t			family;
148997b2e202SAlex Deucher 	uint32_t			rev_id;
149097b2e202SAlex Deucher 	uint32_t			external_rev_id;
149197b2e202SAlex Deucher 	unsigned long			flags;
149297b2e202SAlex Deucher 	int				usec_timeout;
149397b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
149497b2e202SAlex Deucher 	bool				shutdown;
149597b2e202SAlex Deucher 	bool				need_dma32;
149697b2e202SAlex Deucher 	bool				accel_working;
149797b2e202SAlex Deucher 	struct work_struct		reset_work;
149897b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
149997b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
150097b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
150197b2e202SAlex Deucher 	unsigned			debugfs_count;
150297b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
1503adcec288STom St Denis 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
150497b2e202SAlex Deucher #endif
150597b2e202SAlex Deucher 	struct amdgpu_atif		atif;
150697b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
150797b2e202SAlex Deucher 	struct mutex			srbm_mutex;
150897b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
150997b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
151097b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
151197b2e202SAlex Deucher 	bool				have_disp_power_ref;
151297b2e202SAlex Deucher 
151397b2e202SAlex Deucher 	/* BIOS */
15140cdd5005SAlex Deucher 	bool				is_atom_fw;
151597b2e202SAlex Deucher 	uint8_t				*bios;
1516a9f5db9cSEvan Quan 	uint32_t			bios_size;
151797b2e202SAlex Deucher 	struct amdgpu_bo		*stollen_vga_memory;
1518a5bde2f9SAlex Deucher 	uint32_t			bios_scratch_reg_offset;
151997b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
152097b2e202SAlex Deucher 
152197b2e202SAlex Deucher 	/* Register/doorbell mmio */
152297b2e202SAlex Deucher 	resource_size_t			rmmio_base;
152397b2e202SAlex Deucher 	resource_size_t			rmmio_size;
152497b2e202SAlex Deucher 	void __iomem			*rmmio;
152597b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
152697b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
152797b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
152897b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
152997b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
153097b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
153197b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
153297b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
153397b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
153497b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
153536b9a952SHuang Rui 	amdgpu_rreg_t			pciep_rreg;
153636b9a952SHuang Rui 	amdgpu_wreg_t			pciep_wreg;
153797b2e202SAlex Deucher 	/* protects concurrent UVD register access */
153897b2e202SAlex Deucher 	spinlock_t uvd_ctx_idx_lock;
153997b2e202SAlex Deucher 	amdgpu_rreg_t			uvd_ctx_rreg;
154097b2e202SAlex Deucher 	amdgpu_wreg_t			uvd_ctx_wreg;
154197b2e202SAlex Deucher 	/* protects concurrent DIDT register access */
154297b2e202SAlex Deucher 	spinlock_t didt_idx_lock;
154397b2e202SAlex Deucher 	amdgpu_rreg_t			didt_rreg;
154497b2e202SAlex Deucher 	amdgpu_wreg_t			didt_wreg;
1545ccdbb20aSRex Zhu 	/* protects concurrent gc_cac register access */
1546ccdbb20aSRex Zhu 	spinlock_t gc_cac_idx_lock;
1547ccdbb20aSRex Zhu 	amdgpu_rreg_t			gc_cac_rreg;
1548ccdbb20aSRex Zhu 	amdgpu_wreg_t			gc_cac_wreg;
154997b2e202SAlex Deucher 	/* protects concurrent ENDPOINT (audio) register access */
155097b2e202SAlex Deucher 	spinlock_t audio_endpt_idx_lock;
155197b2e202SAlex Deucher 	amdgpu_block_rreg_t		audio_endpt_rreg;
155297b2e202SAlex Deucher 	amdgpu_block_wreg_t		audio_endpt_wreg;
155397b2e202SAlex Deucher 	void __iomem                    *rio_mem;
155497b2e202SAlex Deucher 	resource_size_t			rio_mem_size;
155597b2e202SAlex Deucher 	struct amdgpu_doorbell		doorbell;
155697b2e202SAlex Deucher 
155797b2e202SAlex Deucher 	/* clock/pll info */
155897b2e202SAlex Deucher 	struct amdgpu_clock            clock;
155997b2e202SAlex Deucher 
156097b2e202SAlex Deucher 	/* MC */
156197b2e202SAlex Deucher 	struct amdgpu_mc		mc;
156297b2e202SAlex Deucher 	struct amdgpu_gart		gart;
156397b2e202SAlex Deucher 	struct amdgpu_dummy_page	dummy_page;
156497b2e202SAlex Deucher 	struct amdgpu_vm_manager	vm_manager;
1565e60f8db5SAlex Xie 	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
156697b2e202SAlex Deucher 
156797b2e202SAlex Deucher 	/* memory management */
156897b2e202SAlex Deucher 	struct amdgpu_mman		mman;
156997b2e202SAlex Deucher 	struct amdgpu_vram_scratch	vram_scratch;
157097b2e202SAlex Deucher 	struct amdgpu_wb		wb;
157197b2e202SAlex Deucher 	atomic64_t			vram_usage;
157297b2e202SAlex Deucher 	atomic64_t			vram_vis_usage;
157397b2e202SAlex Deucher 	atomic64_t			gtt_usage;
157497b2e202SAlex Deucher 	atomic64_t			num_bytes_moved;
1575dbd5ed60SChristian König 	atomic64_t			num_evictions;
157668e2c5ffSMarek Olšák 	atomic64_t			num_vram_cpu_page_faults;
1577d94aed5aSMarek Olšák 	atomic_t			gpu_reset_counter;
1578f1892138SChunming Zhou 	atomic_t			vram_lost_counter;
157997b2e202SAlex Deucher 
158095844d20SMarek Olšák 	/* data for buffer migration throttling */
158195844d20SMarek Olšák 	struct {
158295844d20SMarek Olšák 		spinlock_t		lock;
158395844d20SMarek Olšák 		s64			last_update_us;
158495844d20SMarek Olšák 		s64			accum_us; /* accumulated microseconds */
158595844d20SMarek Olšák 		u32			log2_max_MBps;
158695844d20SMarek Olšák 	} mm_stats;
158795844d20SMarek Olšák 
158897b2e202SAlex Deucher 	/* display */
15899accf2fdSEmily Deng 	bool				enable_virtual_display;
159097b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
159197b2e202SAlex Deucher 	struct work_struct		hotplug_work;
159297b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
159397b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
159497b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
159597b2e202SAlex Deucher 
159697b2e202SAlex Deucher 	/* rings */
159776bf0db5SChristian König 	u64				fence_context;
159897b2e202SAlex Deucher 	unsigned			num_rings;
159997b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
160097b2e202SAlex Deucher 	bool				ib_pool_ready;
160197b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
160297b2e202SAlex Deucher 
160397b2e202SAlex Deucher 	/* interrupts */
160497b2e202SAlex Deucher 	struct amdgpu_irq		irq;
160597b2e202SAlex Deucher 
16061f7371b2SAlex Deucher 	/* powerplay */
16071f7371b2SAlex Deucher 	struct amd_powerplay		powerplay;
1608e61710c5SJammy Zhou 	bool				pp_enabled;
1609f3898ea1SEric Huang 	bool				pp_force_state_enabled;
16101f7371b2SAlex Deucher 
161197b2e202SAlex Deucher 	/* dpm */
161297b2e202SAlex Deucher 	struct amdgpu_pm		pm;
161397b2e202SAlex Deucher 	u32				cg_flags;
161497b2e202SAlex Deucher 	u32				pg_flags;
161597b2e202SAlex Deucher 
161697b2e202SAlex Deucher 	/* amdgpu smumgr */
161797b2e202SAlex Deucher 	struct amdgpu_smumgr smu;
161897b2e202SAlex Deucher 
161997b2e202SAlex Deucher 	/* gfx */
162097b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
162197b2e202SAlex Deucher 
162297b2e202SAlex Deucher 	/* sdma */
1623c113ea1cSAlex Deucher 	struct amdgpu_sdma		sdma;
162497b2e202SAlex Deucher 
162595d0906fSLeo Liu 	union {
162695d0906fSLeo Liu 		struct {
162797b2e202SAlex Deucher 			/* uvd */
162897b2e202SAlex Deucher 			struct amdgpu_uvd		uvd;
162997b2e202SAlex Deucher 
163097b2e202SAlex Deucher 			/* vce */
163197b2e202SAlex Deucher 			struct amdgpu_vce		vce;
163295d0906fSLeo Liu 		};
163395d0906fSLeo Liu 
163495d0906fSLeo Liu 		/* vcn */
163595d0906fSLeo Liu 		struct amdgpu_vcn		vcn;
163695d0906fSLeo Liu 	};
163797b2e202SAlex Deucher 
163897b2e202SAlex Deucher 	/* firmwares */
163997b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
164097b2e202SAlex Deucher 
16410e5ca0d1SHuang Rui 	/* PSP */
16420e5ca0d1SHuang Rui 	struct psp_context		psp;
16430e5ca0d1SHuang Rui 
164497b2e202SAlex Deucher 	/* GDS */
164597b2e202SAlex Deucher 	struct amdgpu_gds		gds;
164697b2e202SAlex Deucher 
1647a1255107SAlex Deucher 	struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
164897b2e202SAlex Deucher 	int				num_ip_blocks;
164997b2e202SAlex Deucher 	struct mutex	mn_lock;
165097b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
165197b2e202SAlex Deucher 
165297b2e202SAlex Deucher 	/* tracking pinned memory */
165397b2e202SAlex Deucher 	u64 vram_pin_size;
1654e131b914SChunming Zhou 	u64 invisible_pin_size;
165597b2e202SAlex Deucher 	u64 gart_pin_size;
1656130e0371SOded Gabbay 
1657130e0371SOded Gabbay 	/* amdkfd interface */
1658130e0371SOded Gabbay 	struct kfd_dev          *kfd;
165923ca0e4eSChunming Zhou 
16602dc80b00SShirish S 	/* delayed work_func for deferring clockgating during resume */
16612dc80b00SShirish S 	struct delayed_work     late_init_work;
16622dc80b00SShirish S 
16635a5099cbSXiangliang Yu 	struct amdgpu_virt	virt;
16640c4e7fa5SChunming Zhou 
16650c4e7fa5SChunming Zhou 	/* link all shadow bo */
16660c4e7fa5SChunming Zhou 	struct list_head                shadow_list;
16670c4e7fa5SChunming Zhou 	struct mutex                    shadow_list_lock;
16685c1354bdSChunming Zhou 	/* link all gtt */
16695c1354bdSChunming Zhou 	spinlock_t			gtt_list_lock;
16705c1354bdSChunming Zhou 	struct list_head                gtt_list;
1671795f2813SAndres Rodriguez 	/* keep an lru list of rings by HW IP */
1672795f2813SAndres Rodriguez 	struct list_head		ring_lru_list;
1673795f2813SAndres Rodriguez 	spinlock_t			ring_lru_list_lock;
16745c1354bdSChunming Zhou 
1675c836fec5SJim Qu 	/* record hw reset is performed */
1676c836fec5SJim Qu 	bool has_hw_reset;
16770c49e0b8SChunming Zhou 	u8				reset_magic[AMDGPU_RESET_MAGIC_NUM];
1678c836fec5SJim Qu 
167997b2e202SAlex Deucher };
168097b2e202SAlex Deucher 
1681a7d64de6SChristian König static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1682a7d64de6SChristian König {
1683a7d64de6SChristian König 	return container_of(bdev, struct amdgpu_device, mman.bdev);
1684a7d64de6SChristian König }
1685a7d64de6SChristian König 
168697b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
168797b2e202SAlex Deucher 		       struct drm_device *ddev,
168897b2e202SAlex Deucher 		       struct pci_dev *pdev,
168997b2e202SAlex Deucher 		       uint32_t flags);
169097b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
169197b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
169297b2e202SAlex Deucher 
169397b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
169415d72fd7SMonk Liu 			uint32_t acc_flags);
169597b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
169615d72fd7SMonk Liu 		    uint32_t acc_flags);
169797b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
169897b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
169997b2e202SAlex Deucher 
170097b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
170197b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1702832be404SKen Wang u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1703832be404SKen Wang void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
170497b2e202SAlex Deucher 
170597b2e202SAlex Deucher /*
170697b2e202SAlex Deucher  * Registers read & write functions.
170797b2e202SAlex Deucher  */
170815d72fd7SMonk Liu 
170915d72fd7SMonk Liu #define AMDGPU_REGS_IDX       (1<<0)
171015d72fd7SMonk Liu #define AMDGPU_REGS_NO_KIQ    (1<<1)
171115d72fd7SMonk Liu 
171215d72fd7SMonk Liu #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
171315d72fd7SMonk Liu #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
171415d72fd7SMonk Liu 
171515d72fd7SMonk Liu #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
171615d72fd7SMonk Liu #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
171715d72fd7SMonk Liu #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
171815d72fd7SMonk Liu #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
171915d72fd7SMonk Liu #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
172097b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
172197b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
172297b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
172397b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
172436b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
172536b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
172697b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
172797b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
172897b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
172997b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
173097b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
173197b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
1732ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1733ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
173497b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
173597b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
173697b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
173797b2e202SAlex Deucher 	do {							\
173897b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
173997b2e202SAlex Deucher 		tmp_ &= (mask);					\
174097b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
174197b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
174297b2e202SAlex Deucher 	} while (0)
174397b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
174497b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
174597b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
174697b2e202SAlex Deucher 	do {							\
174797b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
174897b2e202SAlex Deucher 		tmp_ &= (mask);					\
174997b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
175097b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
175197b2e202SAlex Deucher 	} while (0)
175297b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
175397b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
175497b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
175597b2e202SAlex Deucher 
175697b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
175797b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1758832be404SKen Wang #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1759832be404SKen Wang #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
176097b2e202SAlex Deucher 
176197b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
176297b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
176397b2e202SAlex Deucher 
176497b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
176597b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
176697b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
176797b2e202SAlex Deucher 
176897b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
176997b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
177097b2e202SAlex Deucher 
177161cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val)	\
177261cb8cefSTom St Denis 	WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
177361cb8cefSTom St Denis 
1774ccaf3574STom St Denis #define WREG32_FIELD_OFFSET(reg, offset, field, val)	\
1775ccaf3574STom St Denis 	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1776ccaf3574STom St Denis 
177797b2e202SAlex Deucher /*
177897b2e202SAlex Deucher  * BIOS helpers.
177997b2e202SAlex Deucher  */
178097b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
178197b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
178297b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
178397b2e202SAlex Deucher 
178497b2e202SAlex Deucher /*
178597b2e202SAlex Deucher  * RING helpers.
178697b2e202SAlex Deucher  */
178797b2e202SAlex Deucher static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
178897b2e202SAlex Deucher {
178997b2e202SAlex Deucher 	if (ring->count_dw <= 0)
179086c2b790SJammy Zhou 		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
1791536fbf94SKen Wang 	ring->ring[ring->wptr++ & ring->buf_mask] = v;
179297b2e202SAlex Deucher 	ring->wptr &= ring->ptr_mask;
179397b2e202SAlex Deucher 	ring->count_dw--;
179497b2e202SAlex Deucher }
179597b2e202SAlex Deucher 
17960a8e1473SMonk Liu static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *src, int count_dw)
17970a8e1473SMonk Liu {
17980a8e1473SMonk Liu 	unsigned occupied, chunk1, chunk2;
17990a8e1473SMonk Liu 	void *dst;
18000a8e1473SMonk Liu 
18015b9c58f9SNikola Pajkovsky 	if (unlikely(ring->count_dw < count_dw)) {
18020a8e1473SMonk Liu 		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
18035b9c58f9SNikola Pajkovsky 		return;
18045b9c58f9SNikola Pajkovsky 	}
18055b9c58f9SNikola Pajkovsky 
18065846e355SMonk Liu 	occupied = ring->wptr & ring->buf_mask;
18070a8e1473SMonk Liu 	dst = (void *)&ring->ring[occupied];
18085846e355SMonk Liu 	chunk1 = ring->buf_mask + 1 - occupied;
18090a8e1473SMonk Liu 	chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
18100a8e1473SMonk Liu 	chunk2 = count_dw - chunk1;
18110a8e1473SMonk Liu 	chunk1 <<= 2;
18120a8e1473SMonk Liu 	chunk2 <<= 2;
18130a8e1473SMonk Liu 
18140a8e1473SMonk Liu 	if (chunk1)
18150a8e1473SMonk Liu 		memcpy(dst, src, chunk1);
18160a8e1473SMonk Liu 
18170a8e1473SMonk Liu 	if (chunk2) {
18180a8e1473SMonk Liu 		src += chunk1;
18190a8e1473SMonk Liu 		dst = (void *)ring->ring;
18200a8e1473SMonk Liu 		memcpy(dst, src, chunk2);
18210a8e1473SMonk Liu 	}
18220a8e1473SMonk Liu 
18230a8e1473SMonk Liu 	ring->wptr += count_dw;
18240a8e1473SMonk Liu 	ring->wptr &= ring->ptr_mask;
18250a8e1473SMonk Liu 	ring->count_dw -= count_dw;
18260a8e1473SMonk Liu }
18270a8e1473SMonk Liu 
1828c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance *
1829c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
18304b2f7e2cSJammy Zhou {
18314b2f7e2cSJammy Zhou 	struct amdgpu_device *adev = ring->adev;
18324b2f7e2cSJammy Zhou 	int i;
18334b2f7e2cSJammy Zhou 
1834c113ea1cSAlex Deucher 	for (i = 0; i < adev->sdma.num_instances; i++)
1835c113ea1cSAlex Deucher 		if (&adev->sdma.instance[i].ring == ring)
18364b2f7e2cSJammy Zhou 			break;
18374b2f7e2cSJammy Zhou 
18384b2f7e2cSJammy Zhou 	if (i < AMDGPU_MAX_SDMA_INSTANCES)
1839c113ea1cSAlex Deucher 		return &adev->sdma.instance[i];
18404b2f7e2cSJammy Zhou 	else
18414b2f7e2cSJammy Zhou 		return NULL;
18424b2f7e2cSJammy Zhou }
18434b2f7e2cSJammy Zhou 
184497b2e202SAlex Deucher /*
184597b2e202SAlex Deucher  * ASICs macro.
184697b2e202SAlex Deucher  */
184797b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
184897b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
184997b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
185097b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
185197b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1852841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1853841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1854841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
185597b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
18567946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
185797b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1858bbf282d8SAlex Deucher #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
185997b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
186097b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
1861b1166325SChristian König #define amdgpu_gart_get_vm_pde(adev, addr) (adev)->gart.gart_funcs->get_vm_pde((adev), (addr))
186297b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
1863de9ea7bdSChristian 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)))
186497b2e202SAlex 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)))
18655463545bSAlex Xie #define amdgpu_vm_get_pte_flags(adev, flags) (adev)->gart.gart_funcs->get_vm_pte_flags((adev),(flags))
186697b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
186797b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
1868bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
186997b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
187097b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
187197b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
1872d88bf583SChristian König #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
1873b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
187497b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
1875890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
187697b2e202SAlex 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))
1877d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
187811afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
1879c2167a65SMonk Liu #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
1880753ad49cSMonk Liu #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
1881b6091c12SXiangliang Yu #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
1882b6091c12SXiangliang Yu #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
18833b4d68e9SMonk Liu #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
18849e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
188503ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
188603ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
188797b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
188897b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
188997b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
189097b2e202SAlex Deucher #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
189197b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
189297b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
189397b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
189497b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
189597b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
189697b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
189797b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
189897b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
1899cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
190097b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
190197b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
190297b2e202SAlex 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))
190397b2e202SAlex Deucher #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
190497b2e202SAlex Deucher #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
1905c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b))
19066e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
1907b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
19089559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
190997b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
19100e5ca0d1SHuang Rui #define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
191197b2e202SAlex Deucher 
191297b2e202SAlex Deucher /* Common functions */
191397b2e202SAlex Deucher int amdgpu_gpu_reset(struct amdgpu_device *adev);
19143ad81f16SChunming Zhou bool amdgpu_need_backup(struct amdgpu_device *adev);
191597b2e202SAlex Deucher void amdgpu_pci_config_reset(struct amdgpu_device *adev);
1916c836fec5SJim Qu bool amdgpu_need_post(struct amdgpu_device *adev);
191797b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev);
1918d5fc5e82SChunming Zhou 
191997b2e202SAlex Deucher int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
1920fad06127SSamuel Pitoiset void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes);
1921765e7fbfSChristian König void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
192297b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
19232f568dbdSChristian König int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
192497b2e202SAlex Deucher int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
192597b2e202SAlex Deucher 				     uint32_t flags);
192697b2e202SAlex Deucher bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
1927cc325d19SChristian König struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
1928d7006964SChristian König bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
1929d7006964SChristian König 				  unsigned long end);
19302f568dbdSChristian König bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
19312f568dbdSChristian König 				       int *last_invalidated);
193297b2e202SAlex Deucher bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
19336b777607SChunming Zhou uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
193497b2e202SAlex Deucher 				 struct ttm_mem_reg *mem);
193597b2e202SAlex Deucher void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
193697b2e202SAlex Deucher void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
193797b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
19389f31a0b0SBaoyou Xie int amdgpu_ttm_init(struct amdgpu_device *adev);
19399f31a0b0SBaoyou Xie void amdgpu_ttm_fini(struct amdgpu_device *adev);
194097b2e202SAlex Deucher void amdgpu_program_register_sequence(struct amdgpu_device *adev,
194197b2e202SAlex Deucher 					     const u32 *registers,
194297b2e202SAlex Deucher 					     const u32 array_size);
194397b2e202SAlex Deucher 
194497b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
194597b2e202SAlex Deucher /* atpx handler */
194697b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
194797b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
194897b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
1949a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void);
19502f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void);
1951efc83cf4SAlex Deucher bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1952714f88e0SAlex Xie bool amdgpu_has_atpx(void);
195397b2e202SAlex Deucher #else
195497b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
195597b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
1956a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
19572f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
1958efc83cf4SAlex Deucher static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
1959714f88e0SAlex Xie static inline bool amdgpu_has_atpx(void) { return false; }
196097b2e202SAlex Deucher #endif
196197b2e202SAlex Deucher 
196297b2e202SAlex Deucher /*
196397b2e202SAlex Deucher  * KMS
196497b2e202SAlex Deucher  */
196597b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1966f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl;
196797b2e202SAlex Deucher 
1968f1892138SChunming Zhou bool amdgpu_kms_vram_lost(struct amdgpu_device *adev,
1969f1892138SChunming Zhou 			  struct amdgpu_fpriv *fpriv);
197097b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
197111b3c20bSGabriel Krisman Bertazi void amdgpu_driver_unload_kms(struct drm_device *dev);
197297b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
197397b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
197497b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
197597b2e202SAlex Deucher 				 struct drm_file *file_priv);
1976faefba95SAlex Deucher int amdgpu_suspend(struct amdgpu_device *adev);
1977810ddc3aSAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1978810ddc3aSAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
197988e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
198088e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
198188e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
198297b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
198397b2e202SAlex Deucher 			     unsigned long arg);
198497b2e202SAlex Deucher 
198597b2e202SAlex Deucher /*
198697b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
198797b2e202SAlex Deucher  */
198897b2e202SAlex Deucher struct amdgpu_afmt_acr {
198997b2e202SAlex Deucher 	u32 clock;
199097b2e202SAlex Deucher 
199197b2e202SAlex Deucher 	int n_32khz;
199297b2e202SAlex Deucher 	int cts_32khz;
199397b2e202SAlex Deucher 
199497b2e202SAlex Deucher 	int n_44_1khz;
199597b2e202SAlex Deucher 	int cts_44_1khz;
199697b2e202SAlex Deucher 
199797b2e202SAlex Deucher 	int n_48khz;
199897b2e202SAlex Deucher 	int cts_48khz;
199997b2e202SAlex Deucher 
200097b2e202SAlex Deucher };
200197b2e202SAlex Deucher 
200297b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
200397b2e202SAlex Deucher 
200497b2e202SAlex Deucher /* amdgpu_acpi.c */
200597b2e202SAlex Deucher #if defined(CONFIG_ACPI)
200697b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
200797b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
200897b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
200997b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
201097b2e202SAlex Deucher 						u8 perf_req, bool advertise);
201197b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
201297b2e202SAlex Deucher #else
201397b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
201497b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
201597b2e202SAlex Deucher #endif
201697b2e202SAlex Deucher 
201797b2e202SAlex Deucher struct amdgpu_bo_va_mapping *
201897b2e202SAlex Deucher amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
201997b2e202SAlex Deucher 		       uint64_t addr, struct amdgpu_bo **bo);
2020c855e250SChristian König int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
202197b2e202SAlex Deucher 
202297b2e202SAlex Deucher #include "amdgpu_object.h"
202397b2e202SAlex Deucher #endif
2024