xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision a101a899)
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>
3597b2e202SAlex Deucher #include <linux/interval_tree.h>
3697b2e202SAlex Deucher #include <linux/hashtable.h>
3797b2e202SAlex Deucher #include <linux/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 
4597b2e202SAlex Deucher #include <drm/drm_gem.h>
467e5a547fSChunming Zhou #include <drm/amdgpu_drm.h>
4797b2e202SAlex Deucher 
485fc3aeebSyanyang1 #include "amd_shared.h"
4997b2e202SAlex Deucher #include "amdgpu_family.h"
5097b2e202SAlex Deucher #include "amdgpu_mode.h"
5197b2e202SAlex Deucher #include "amdgpu_ih.h"
5297b2e202SAlex Deucher #include "amdgpu_irq.h"
5397b2e202SAlex Deucher #include "amdgpu_ucode.h"
5497b2e202SAlex Deucher #include "amdgpu_gds.h"
5597b2e202SAlex Deucher 
5697b2e202SAlex Deucher /*
5797b2e202SAlex Deucher  * Modules parameters.
5897b2e202SAlex Deucher  */
5997b2e202SAlex Deucher extern int amdgpu_modeset;
6097b2e202SAlex Deucher extern int amdgpu_vram_limit;
6197b2e202SAlex Deucher extern int amdgpu_gart_size;
6297b2e202SAlex Deucher extern int amdgpu_benchmarking;
6397b2e202SAlex Deucher extern int amdgpu_testing;
6497b2e202SAlex Deucher extern int amdgpu_audio;
6597b2e202SAlex Deucher extern int amdgpu_disp_priority;
6697b2e202SAlex Deucher extern int amdgpu_hw_i2c;
6797b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
6897b2e202SAlex Deucher extern int amdgpu_msi;
6997b2e202SAlex Deucher extern int amdgpu_lockup_timeout;
7097b2e202SAlex Deucher extern int amdgpu_dpm;
7197b2e202SAlex Deucher extern int amdgpu_smc_load_fw;
7297b2e202SAlex Deucher extern int amdgpu_aspm;
7397b2e202SAlex Deucher extern int amdgpu_runtime_pm;
7497b2e202SAlex Deucher extern int amdgpu_hard_reset;
7597b2e202SAlex Deucher extern unsigned amdgpu_ip_block_mask;
7697b2e202SAlex Deucher extern int amdgpu_bapm;
7797b2e202SAlex Deucher extern int amdgpu_deep_color;
7897b2e202SAlex Deucher extern int amdgpu_vm_size;
7997b2e202SAlex Deucher extern int amdgpu_vm_block_size;
8097b2e202SAlex Deucher 
8197b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
8297b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
8397b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
8497b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
8597b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
8697b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
8797b2e202SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			8
8897b2e202SAlex Deucher 
8997b2e202SAlex Deucher /* max number of rings */
9097b2e202SAlex Deucher #define AMDGPU_MAX_RINGS			16
9197b2e202SAlex Deucher #define AMDGPU_MAX_GFX_RINGS			1
9297b2e202SAlex Deucher #define AMDGPU_MAX_COMPUTE_RINGS		8
9397b2e202SAlex Deucher #define AMDGPU_MAX_VCE_RINGS			2
9497b2e202SAlex Deucher 
9597b2e202SAlex Deucher /* number of hw syncs before falling back on blocking */
9697b2e202SAlex Deucher #define AMDGPU_NUM_SYNCS			4
9797b2e202SAlex Deucher 
9897b2e202SAlex Deucher /* hardcode that limit for now */
9997b2e202SAlex Deucher #define AMDGPU_VA_RESERVED_SIZE			(8 << 20)
10097b2e202SAlex Deucher 
10197b2e202SAlex Deucher /* hard reset data */
10297b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
10397b2e202SAlex Deucher 
10497b2e202SAlex Deucher /* reset flags */
10597b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
10697b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
10797b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
10897b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
10997b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
11097b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
11197b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
11297b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
11397b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
11497b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
11597b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
11697b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
11797b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
11897b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
11997b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
12097b2e202SAlex Deucher 
12197b2e202SAlex Deucher /* CG block flags */
12297b2e202SAlex Deucher #define AMDGPU_CG_BLOCK_GFX			(1 << 0)
12397b2e202SAlex Deucher #define AMDGPU_CG_BLOCK_MC			(1 << 1)
12497b2e202SAlex Deucher #define AMDGPU_CG_BLOCK_SDMA			(1 << 2)
12597b2e202SAlex Deucher #define AMDGPU_CG_BLOCK_UVD			(1 << 3)
12697b2e202SAlex Deucher #define AMDGPU_CG_BLOCK_VCE			(1 << 4)
12797b2e202SAlex Deucher #define AMDGPU_CG_BLOCK_HDP			(1 << 5)
12897b2e202SAlex Deucher #define AMDGPU_CG_BLOCK_BIF			(1 << 6)
12997b2e202SAlex Deucher 
13097b2e202SAlex Deucher /* CG flags */
13197b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_MGCG		(1 << 0)
13297b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_MGLS		(1 << 1)
13397b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_CGCG		(1 << 2)
13497b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_CGLS		(1 << 3)
13597b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_CGTS		(1 << 4)
13697b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_CGTS_LS		(1 << 5)
13797b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_CP_LS		(1 << 6)
13897b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_GFX_RLC_LS		(1 << 7)
13997b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_MC_LS			(1 << 8)
14097b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_MC_MGCG		(1 << 9)
14197b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_SDMA_LS		(1 << 10)
14297b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_SDMA_MGCG		(1 << 11)
14397b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_BIF_LS		(1 << 12)
14497b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_UVD_MGCG		(1 << 13)
14597b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_VCE_MGCG		(1 << 14)
14697b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_HDP_LS		(1 << 15)
14797b2e202SAlex Deucher #define AMDGPU_CG_SUPPORT_HDP_MGCG		(1 << 16)
14897b2e202SAlex Deucher 
14997b2e202SAlex Deucher /* PG flags */
15097b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_GFX_PG		(1 << 0)
15197b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_GFX_SMG		(1 << 1)
15297b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_GFX_DMG		(1 << 2)
15397b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_UVD			(1 << 3)
15497b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_VCE			(1 << 4)
15597b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_CP			(1 << 5)
15697b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_GDS			(1 << 6)
15797b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_RLC_SMU_HS		(1 << 7)
15897b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_SDMA			(1 << 8)
15997b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_ACP			(1 << 9)
16097b2e202SAlex Deucher #define AMDGPU_PG_SUPPORT_SAMU			(1 << 10)
16197b2e202SAlex Deucher 
16297b2e202SAlex Deucher /* GFX current status */
16397b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
16497b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE			0x00000001L
16597b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
16697b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
16797b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
16897b2e202SAlex Deucher 
16997b2e202SAlex Deucher /* max cursor sizes (in pixels) */
17097b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
17197b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
17297b2e202SAlex Deucher 
17397b2e202SAlex Deucher struct amdgpu_device;
17497b2e202SAlex Deucher struct amdgpu_fence;
17597b2e202SAlex Deucher struct amdgpu_ib;
17697b2e202SAlex Deucher struct amdgpu_vm;
17797b2e202SAlex Deucher struct amdgpu_ring;
17897b2e202SAlex Deucher struct amdgpu_semaphore;
17997b2e202SAlex Deucher struct amdgpu_cs_parser;
18097b2e202SAlex Deucher struct amdgpu_irq_src;
18197b2e202SAlex Deucher 
18297b2e202SAlex Deucher enum amdgpu_cp_irq {
18397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_GFX_EOP = 0,
18497b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
18597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
18697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
18797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
18897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
18997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
19097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
19197b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
19297b2e202SAlex Deucher 
19397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
19497b2e202SAlex Deucher };
19597b2e202SAlex Deucher 
19697b2e202SAlex Deucher enum amdgpu_sdma_irq {
19797b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
19897b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP1,
19997b2e202SAlex Deucher 
20097b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_LAST
20197b2e202SAlex Deucher };
20297b2e202SAlex Deucher 
20397b2e202SAlex Deucher enum amdgpu_thermal_irq {
20497b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
20597b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
20697b2e202SAlex Deucher 
20797b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
20897b2e202SAlex Deucher };
20997b2e202SAlex Deucher 
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);
21697b2e202SAlex Deucher 
21797b2e202SAlex Deucher struct amdgpu_ip_block_version {
2185fc3aeebSyanyang1 	enum amd_ip_block_type type;
21997b2e202SAlex Deucher 	u32 major;
22097b2e202SAlex Deucher 	u32 minor;
22197b2e202SAlex Deucher 	u32 rev;
2225fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
22397b2e202SAlex Deucher };
22497b2e202SAlex Deucher 
22597b2e202SAlex Deucher int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
2265fc3aeebSyanyang1 				enum amd_ip_block_type type,
22797b2e202SAlex Deucher 				u32 major, u32 minor);
22897b2e202SAlex Deucher 
22997b2e202SAlex Deucher const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
23097b2e202SAlex Deucher 					struct amdgpu_device *adev,
2315fc3aeebSyanyang1 					enum amd_ip_block_type type);
23297b2e202SAlex Deucher 
23397b2e202SAlex Deucher /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
23497b2e202SAlex Deucher struct amdgpu_buffer_funcs {
23597b2e202SAlex Deucher 	/* maximum bytes in a single operation */
23697b2e202SAlex Deucher 	uint32_t	copy_max_bytes;
23797b2e202SAlex Deucher 
23897b2e202SAlex Deucher 	/* number of dw to reserve per operation */
23997b2e202SAlex Deucher 	unsigned	copy_num_dw;
24097b2e202SAlex Deucher 
24197b2e202SAlex Deucher 	/* used for buffer migration */
24297b2e202SAlex Deucher 	void (*emit_copy_buffer)(struct amdgpu_ring *ring,
24397b2e202SAlex Deucher 				 /* src addr in bytes */
24497b2e202SAlex Deucher 				 uint64_t src_offset,
24597b2e202SAlex Deucher 				 /* dst addr in bytes */
24697b2e202SAlex Deucher 				 uint64_t dst_offset,
24797b2e202SAlex Deucher 				 /* number of byte to transfer */
24897b2e202SAlex Deucher 				 uint32_t byte_count);
24997b2e202SAlex Deucher 
25097b2e202SAlex Deucher 	/* maximum bytes in a single operation */
25197b2e202SAlex Deucher 	uint32_t	fill_max_bytes;
25297b2e202SAlex Deucher 
25397b2e202SAlex Deucher 	/* number of dw to reserve per operation */
25497b2e202SAlex Deucher 	unsigned	fill_num_dw;
25597b2e202SAlex Deucher 
25697b2e202SAlex Deucher 	/* used for buffer clearing */
25797b2e202SAlex Deucher 	void (*emit_fill_buffer)(struct amdgpu_ring *ring,
25897b2e202SAlex Deucher 				 /* value to write to memory */
25997b2e202SAlex Deucher 				 uint32_t src_data,
26097b2e202SAlex Deucher 				 /* dst addr in bytes */
26197b2e202SAlex Deucher 				 uint64_t dst_offset,
26297b2e202SAlex Deucher 				 /* number of byte to fill */
26397b2e202SAlex Deucher 				 uint32_t byte_count);
26497b2e202SAlex Deucher };
26597b2e202SAlex Deucher 
26697b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */
26797b2e202SAlex Deucher struct amdgpu_vm_pte_funcs {
26897b2e202SAlex Deucher 	/* copy pte entries from GART */
26997b2e202SAlex Deucher 	void (*copy_pte)(struct amdgpu_ib *ib,
27097b2e202SAlex Deucher 			 uint64_t pe, uint64_t src,
27197b2e202SAlex Deucher 			 unsigned count);
27297b2e202SAlex Deucher 	/* write pte one entry at a time with addr mapping */
27397b2e202SAlex Deucher 	void (*write_pte)(struct amdgpu_ib *ib,
27497b2e202SAlex Deucher 			  uint64_t pe,
27597b2e202SAlex Deucher 			  uint64_t addr, unsigned count,
27697b2e202SAlex Deucher 			  uint32_t incr, uint32_t flags);
27797b2e202SAlex Deucher 	/* for linear pte/pde updates without addr mapping */
27897b2e202SAlex Deucher 	void (*set_pte_pde)(struct amdgpu_ib *ib,
27997b2e202SAlex Deucher 			    uint64_t pe,
28097b2e202SAlex Deucher 			    uint64_t addr, unsigned count,
28197b2e202SAlex Deucher 			    uint32_t incr, uint32_t flags);
28297b2e202SAlex Deucher 	/* pad the indirect buffer to the necessary number of dw */
28397b2e202SAlex Deucher 	void (*pad_ib)(struct amdgpu_ib *ib);
28497b2e202SAlex Deucher };
28597b2e202SAlex Deucher 
28697b2e202SAlex Deucher /* provided by the gmc block */
28797b2e202SAlex Deucher struct amdgpu_gart_funcs {
28897b2e202SAlex Deucher 	/* flush the vm tlb via mmio */
28997b2e202SAlex Deucher 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
29097b2e202SAlex Deucher 			      uint32_t vmid);
29197b2e202SAlex Deucher 	/* write pte/pde updates using the cpu */
29297b2e202SAlex Deucher 	int (*set_pte_pde)(struct amdgpu_device *adev,
29397b2e202SAlex Deucher 			   void *cpu_pt_addr, /* cpu addr of page table */
29497b2e202SAlex Deucher 			   uint32_t gpu_page_idx, /* pte/pde to update */
29597b2e202SAlex Deucher 			   uint64_t addr, /* addr to write into pte/pde */
29697b2e202SAlex Deucher 			   uint32_t flags); /* access flags */
29797b2e202SAlex Deucher };
29897b2e202SAlex Deucher 
29997b2e202SAlex Deucher /* provided by the ih block */
30097b2e202SAlex Deucher struct amdgpu_ih_funcs {
30197b2e202SAlex Deucher 	/* ring read/write ptr handling, called from interrupt context */
30297b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_device *adev);
30397b2e202SAlex Deucher 	void (*decode_iv)(struct amdgpu_device *adev,
30497b2e202SAlex Deucher 			  struct amdgpu_iv_entry *entry);
30597b2e202SAlex Deucher 	void (*set_rptr)(struct amdgpu_device *adev);
30697b2e202SAlex Deucher };
30797b2e202SAlex Deucher 
30897b2e202SAlex Deucher /* provided by hw blocks that expose a ring buffer for commands */
30997b2e202SAlex Deucher struct amdgpu_ring_funcs {
31097b2e202SAlex Deucher 	/* ring read/write ptr handling */
31197b2e202SAlex Deucher 	u32 (*get_rptr)(struct amdgpu_ring *ring);
31297b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_ring *ring);
31397b2e202SAlex Deucher 	void (*set_wptr)(struct amdgpu_ring *ring);
31497b2e202SAlex Deucher 	/* validating and patching of IBs */
31597b2e202SAlex Deucher 	int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
31697b2e202SAlex Deucher 	/* command emit functions */
31797b2e202SAlex Deucher 	void (*emit_ib)(struct amdgpu_ring *ring,
31897b2e202SAlex Deucher 			struct amdgpu_ib *ib);
31997b2e202SAlex Deucher 	void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
32097b2e202SAlex Deucher 			   uint64_t seq, bool write64bit);
32197b2e202SAlex Deucher 	bool (*emit_semaphore)(struct amdgpu_ring *ring,
32297b2e202SAlex Deucher 			       struct amdgpu_semaphore *semaphore,
32397b2e202SAlex Deucher 			       bool emit_wait);
32497b2e202SAlex Deucher 	void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
32597b2e202SAlex Deucher 			      uint64_t pd_addr);
326d2edb07bSChristian König 	void (*emit_hdp_flush)(struct amdgpu_ring *ring);
32797b2e202SAlex Deucher 	void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
32897b2e202SAlex Deucher 				uint32_t gds_base, uint32_t gds_size,
32997b2e202SAlex Deucher 				uint32_t gws_base, uint32_t gws_size,
33097b2e202SAlex Deucher 				uint32_t oa_base, uint32_t oa_size);
33197b2e202SAlex Deucher 	/* testing functions */
33297b2e202SAlex Deucher 	int (*test_ring)(struct amdgpu_ring *ring);
33397b2e202SAlex Deucher 	int (*test_ib)(struct amdgpu_ring *ring);
33497b2e202SAlex Deucher 	bool (*is_lockup)(struct amdgpu_ring *ring);
33597b2e202SAlex Deucher };
33697b2e202SAlex Deucher 
33797b2e202SAlex Deucher /*
33897b2e202SAlex Deucher  * BIOS.
33997b2e202SAlex Deucher  */
34097b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
34197b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
34297b2e202SAlex Deucher 
34397b2e202SAlex Deucher /*
34497b2e202SAlex Deucher  * Dummy page
34597b2e202SAlex Deucher  */
34697b2e202SAlex Deucher struct amdgpu_dummy_page {
34797b2e202SAlex Deucher 	struct page	*page;
34897b2e202SAlex Deucher 	dma_addr_t	addr;
34997b2e202SAlex Deucher };
35097b2e202SAlex Deucher int amdgpu_dummy_page_init(struct amdgpu_device *adev);
35197b2e202SAlex Deucher void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
35297b2e202SAlex Deucher 
35397b2e202SAlex Deucher 
35497b2e202SAlex Deucher /*
35597b2e202SAlex Deucher  * Clocks
35697b2e202SAlex Deucher  */
35797b2e202SAlex Deucher 
35897b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
35997b2e202SAlex Deucher 
36097b2e202SAlex Deucher struct amdgpu_clock {
36197b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
36297b2e202SAlex Deucher 	struct amdgpu_pll spll;
36397b2e202SAlex Deucher 	struct amdgpu_pll mpll;
36497b2e202SAlex Deucher 	/* 10 Khz units */
36597b2e202SAlex Deucher 	uint32_t default_mclk;
36697b2e202SAlex Deucher 	uint32_t default_sclk;
36797b2e202SAlex Deucher 	uint32_t default_dispclk;
36897b2e202SAlex Deucher 	uint32_t current_dispclk;
36997b2e202SAlex Deucher 	uint32_t dp_extclk;
37097b2e202SAlex Deucher 	uint32_t max_pixel_clock;
37197b2e202SAlex Deucher };
37297b2e202SAlex Deucher 
37397b2e202SAlex Deucher /*
37497b2e202SAlex Deucher  * Fences.
37597b2e202SAlex Deucher  */
37697b2e202SAlex Deucher struct amdgpu_fence_driver {
37797b2e202SAlex Deucher 	struct amdgpu_ring		*ring;
37897b2e202SAlex Deucher 	uint64_t			gpu_addr;
37997b2e202SAlex Deucher 	volatile uint32_t		*cpu_addr;
38097b2e202SAlex Deucher 	/* sync_seq is protected by ring emission lock */
38197b2e202SAlex Deucher 	uint64_t			sync_seq[AMDGPU_MAX_RINGS];
38297b2e202SAlex Deucher 	atomic64_t			last_seq;
38397b2e202SAlex Deucher 	bool				initialized;
38497b2e202SAlex Deucher 	bool				delayed_irq;
38597b2e202SAlex Deucher 	struct amdgpu_irq_src		*irq_src;
38697b2e202SAlex Deucher 	unsigned			irq_type;
38797b2e202SAlex Deucher 	struct delayed_work             lockup_work;
38897b2e202SAlex Deucher };
38997b2e202SAlex Deucher 
39097b2e202SAlex Deucher /* some special values for the owner field */
39197b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_UNDEFINED	((void*)0ul)
39297b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_VM		((void*)1ul)
39397b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_MOVE		((void*)2ul)
39497b2e202SAlex Deucher 
39597b2e202SAlex Deucher struct amdgpu_fence {
39697b2e202SAlex Deucher 	struct fence base;
39797b2e202SAlex Deucher 
39897b2e202SAlex Deucher 	/* RB, DMA, etc. */
39997b2e202SAlex Deucher 	struct amdgpu_ring		*ring;
40097b2e202SAlex Deucher 	uint64_t			seq;
40197b2e202SAlex Deucher 
40297b2e202SAlex Deucher 	/* filp or special value for fence creator */
40397b2e202SAlex Deucher 	void				*owner;
40497b2e202SAlex Deucher 
40597b2e202SAlex Deucher 	wait_queue_t			fence_wake;
40697b2e202SAlex Deucher };
40797b2e202SAlex Deucher 
40897b2e202SAlex Deucher struct amdgpu_user_fence {
40997b2e202SAlex Deucher 	/* write-back bo */
41097b2e202SAlex Deucher 	struct amdgpu_bo 	*bo;
41197b2e202SAlex Deucher 	/* write-back address offset to bo start */
41297b2e202SAlex Deucher 	uint32_t                offset;
41397b2e202SAlex Deucher };
41497b2e202SAlex Deucher 
41597b2e202SAlex Deucher int amdgpu_fence_driver_init(struct amdgpu_device *adev);
41697b2e202SAlex Deucher void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
41797b2e202SAlex Deucher void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
41897b2e202SAlex Deucher 
41997b2e202SAlex Deucher void amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
42097b2e202SAlex Deucher int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
42197b2e202SAlex Deucher 				   struct amdgpu_irq_src *irq_src,
42297b2e202SAlex Deucher 				   unsigned irq_type);
42397b2e202SAlex Deucher int amdgpu_fence_emit(struct amdgpu_ring *ring, void *owner,
42497b2e202SAlex Deucher 		      struct amdgpu_fence **fence);
42597b2e202SAlex Deucher void amdgpu_fence_process(struct amdgpu_ring *ring);
42697b2e202SAlex Deucher int amdgpu_fence_wait_next(struct amdgpu_ring *ring);
42797b2e202SAlex Deucher int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
42897b2e202SAlex Deucher unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
42997b2e202SAlex Deucher 
43097b2e202SAlex Deucher bool amdgpu_fence_signaled(struct amdgpu_fence *fence);
43197b2e202SAlex Deucher int amdgpu_fence_wait(struct amdgpu_fence *fence, bool interruptible);
43297b2e202SAlex Deucher int amdgpu_fence_wait_any(struct amdgpu_device *adev,
43397b2e202SAlex Deucher 			  struct amdgpu_fence **fences,
43497b2e202SAlex Deucher 			  bool intr);
43597b2e202SAlex Deucher long amdgpu_fence_wait_seq_timeout(struct amdgpu_device *adev,
43697b2e202SAlex Deucher 				   u64 *target_seq, bool intr,
43797b2e202SAlex Deucher 				   long timeout);
43897b2e202SAlex Deucher struct amdgpu_fence *amdgpu_fence_ref(struct amdgpu_fence *fence);
43997b2e202SAlex Deucher void amdgpu_fence_unref(struct amdgpu_fence **fence);
44097b2e202SAlex Deucher 
44197b2e202SAlex Deucher bool amdgpu_fence_need_sync(struct amdgpu_fence *fence,
44297b2e202SAlex Deucher 			    struct amdgpu_ring *ring);
44397b2e202SAlex Deucher void amdgpu_fence_note_sync(struct amdgpu_fence *fence,
44497b2e202SAlex Deucher 			    struct amdgpu_ring *ring);
44597b2e202SAlex Deucher 
44697b2e202SAlex Deucher static inline struct amdgpu_fence *amdgpu_fence_later(struct amdgpu_fence *a,
44797b2e202SAlex Deucher 						      struct amdgpu_fence *b)
44897b2e202SAlex Deucher {
44997b2e202SAlex Deucher 	if (!a) {
45097b2e202SAlex Deucher 		return b;
45197b2e202SAlex Deucher 	}
45297b2e202SAlex Deucher 
45397b2e202SAlex Deucher 	if (!b) {
45497b2e202SAlex Deucher 		return a;
45597b2e202SAlex Deucher 	}
45697b2e202SAlex Deucher 
45797b2e202SAlex Deucher 	BUG_ON(a->ring != b->ring);
45897b2e202SAlex Deucher 
45997b2e202SAlex Deucher 	if (a->seq > b->seq) {
46097b2e202SAlex Deucher 		return a;
46197b2e202SAlex Deucher 	} else {
46297b2e202SAlex Deucher 		return b;
46397b2e202SAlex Deucher 	}
46497b2e202SAlex Deucher }
46597b2e202SAlex Deucher 
46697b2e202SAlex Deucher static inline bool amdgpu_fence_is_earlier(struct amdgpu_fence *a,
46797b2e202SAlex Deucher 					   struct amdgpu_fence *b)
46897b2e202SAlex Deucher {
46997b2e202SAlex Deucher 	if (!a) {
47097b2e202SAlex Deucher 		return false;
47197b2e202SAlex Deucher 	}
47297b2e202SAlex Deucher 
47397b2e202SAlex Deucher 	if (!b) {
47497b2e202SAlex Deucher 		return true;
47597b2e202SAlex Deucher 	}
47697b2e202SAlex Deucher 
47797b2e202SAlex Deucher 	BUG_ON(a->ring != b->ring);
47897b2e202SAlex Deucher 
47997b2e202SAlex Deucher 	return a->seq < b->seq;
48097b2e202SAlex Deucher }
48197b2e202SAlex Deucher 
48297b2e202SAlex Deucher int amdgpu_user_fence_emit(struct amdgpu_ring *ring, struct amdgpu_user_fence *user,
48397b2e202SAlex Deucher 			   void *owner, struct amdgpu_fence **fence);
48497b2e202SAlex Deucher 
48597b2e202SAlex Deucher /*
48697b2e202SAlex Deucher  * TTM.
48797b2e202SAlex Deucher  */
48897b2e202SAlex Deucher struct amdgpu_mman {
48997b2e202SAlex Deucher 	struct ttm_bo_global_ref        bo_global_ref;
49097b2e202SAlex Deucher 	struct drm_global_reference	mem_global_ref;
49197b2e202SAlex Deucher 	struct ttm_bo_device		bdev;
49297b2e202SAlex Deucher 	bool				mem_global_referenced;
49397b2e202SAlex Deucher 	bool				initialized;
49497b2e202SAlex Deucher 
49597b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
49697b2e202SAlex Deucher 	struct dentry			*vram;
49797b2e202SAlex Deucher 	struct dentry			*gtt;
49897b2e202SAlex Deucher #endif
49997b2e202SAlex Deucher 
50097b2e202SAlex Deucher 	/* buffer handling */
50197b2e202SAlex Deucher 	const struct amdgpu_buffer_funcs	*buffer_funcs;
50297b2e202SAlex Deucher 	struct amdgpu_ring			*buffer_funcs_ring;
50397b2e202SAlex Deucher };
50497b2e202SAlex Deucher 
50597b2e202SAlex Deucher int amdgpu_copy_buffer(struct amdgpu_ring *ring,
50697b2e202SAlex Deucher 		       uint64_t src_offset,
50797b2e202SAlex Deucher 		       uint64_t dst_offset,
50897b2e202SAlex Deucher 		       uint32_t byte_count,
50997b2e202SAlex Deucher 		       struct reservation_object *resv,
51097b2e202SAlex Deucher 		       struct amdgpu_fence **fence);
51197b2e202SAlex Deucher int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
51297b2e202SAlex Deucher 
51397b2e202SAlex Deucher struct amdgpu_bo_list_entry {
51497b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
51597b2e202SAlex Deucher 	struct ttm_validate_buffer	tv;
51697b2e202SAlex Deucher 	struct amdgpu_bo_va		*bo_va;
51797b2e202SAlex Deucher 	unsigned			prefered_domains;
51897b2e202SAlex Deucher 	unsigned			allowed_domains;
51997b2e202SAlex Deucher 	uint32_t			priority;
52097b2e202SAlex Deucher };
52197b2e202SAlex Deucher 
52297b2e202SAlex Deucher struct amdgpu_bo_va_mapping {
52397b2e202SAlex Deucher 	struct list_head		list;
52497b2e202SAlex Deucher 	struct interval_tree_node	it;
52597b2e202SAlex Deucher 	uint64_t			offset;
52697b2e202SAlex Deucher 	uint32_t			flags;
52797b2e202SAlex Deucher };
52897b2e202SAlex Deucher 
52997b2e202SAlex Deucher /* bo virtual addresses in a specific vm */
53097b2e202SAlex Deucher struct amdgpu_bo_va {
53197b2e202SAlex Deucher 	/* protected by bo being reserved */
53297b2e202SAlex Deucher 	struct list_head		bo_list;
53397b2e202SAlex Deucher 	uint64_t			addr;
53497b2e202SAlex Deucher 	struct amdgpu_fence		*last_pt_update;
53597b2e202SAlex Deucher 	unsigned			ref_count;
53697b2e202SAlex Deucher 
53797b2e202SAlex Deucher 	/* protected by vm mutex */
53897b2e202SAlex Deucher 	struct list_head		mappings;
53997b2e202SAlex Deucher 	struct list_head		vm_status;
54097b2e202SAlex Deucher 
54197b2e202SAlex Deucher 	/* constant after initialization */
54297b2e202SAlex Deucher 	struct amdgpu_vm		*vm;
54397b2e202SAlex Deucher 	struct amdgpu_bo		*bo;
54497b2e202SAlex Deucher };
54597b2e202SAlex Deucher 
5467e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX		0x3
5477e5a547fSChunming Zhou 
54897b2e202SAlex Deucher struct amdgpu_bo {
54997b2e202SAlex Deucher 	/* Protected by gem.mutex */
55097b2e202SAlex Deucher 	struct list_head		list;
55197b2e202SAlex Deucher 	/* Protected by tbo.reserved */
55297b2e202SAlex Deucher 	u32				initial_domain;
5537e5a547fSChunming Zhou 	struct ttm_place		placements[AMDGPU_GEM_DOMAIN_MAX + 1];
55497b2e202SAlex Deucher 	struct ttm_placement		placement;
55597b2e202SAlex Deucher 	struct ttm_buffer_object	tbo;
55697b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		kmap;
55797b2e202SAlex Deucher 	u64				flags;
55897b2e202SAlex Deucher 	unsigned			pin_count;
55997b2e202SAlex Deucher 	void				*kptr;
56097b2e202SAlex Deucher 	u64				tiling_flags;
56197b2e202SAlex Deucher 	u64				metadata_flags;
56297b2e202SAlex Deucher 	void				*metadata;
56397b2e202SAlex Deucher 	u32				metadata_size;
56497b2e202SAlex Deucher 	/* list of all virtual address to which this bo
56597b2e202SAlex Deucher 	 * is associated to
56697b2e202SAlex Deucher 	 */
56797b2e202SAlex Deucher 	struct list_head		va;
56897b2e202SAlex Deucher 	/* Constant after initialization */
56997b2e202SAlex Deucher 	struct amdgpu_device		*adev;
57097b2e202SAlex Deucher 	struct drm_gem_object		gem_base;
57197b2e202SAlex Deucher 
57297b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		dma_buf_vmap;
57397b2e202SAlex Deucher 	pid_t				pid;
57497b2e202SAlex Deucher 	struct amdgpu_mn		*mn;
57597b2e202SAlex Deucher 	struct list_head		mn_list;
57697b2e202SAlex Deucher };
57797b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
57897b2e202SAlex Deucher 
57997b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj);
58097b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj,
58197b2e202SAlex Deucher 				struct drm_file *file_priv);
58297b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj,
58397b2e202SAlex Deucher 				struct drm_file *file_priv);
58497b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
58597b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
58697b2e202SAlex Deucher struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
58797b2e202SAlex Deucher 							struct dma_buf_attachment *attach,
58897b2e202SAlex Deucher 							struct sg_table *sg);
58997b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
59097b2e202SAlex Deucher 					struct drm_gem_object *gobj,
59197b2e202SAlex Deucher 					int flags);
59297b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
59397b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
59497b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
59597b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
59697b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
59797b2e202SAlex Deucher int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
59897b2e202SAlex Deucher 
59997b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
60097b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
60197b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
60297b2e202SAlex Deucher  * locking.
60397b2e202SAlex Deucher  *
60497b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
60597b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
60697b2e202SAlex Deucher  * offset).
60797b2e202SAlex Deucher  *
60897b2e202SAlex Deucher  * When allocating new object we first check if there is room at
60997b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
61097b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
61197b2e202SAlex Deucher  *
61297b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
61397b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
61497b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
61597b2e202SAlex Deucher  *
61697b2e202SAlex Deucher  * Alignment can't be bigger than page size.
61797b2e202SAlex Deucher  *
61897b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
61997b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
62097b2e202SAlex Deucher  * alignment).
62197b2e202SAlex Deucher  */
62297b2e202SAlex Deucher struct amdgpu_sa_manager {
62397b2e202SAlex Deucher 	wait_queue_head_t	wq;
62497b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
62597b2e202SAlex Deucher 	struct list_head	*hole;
62697b2e202SAlex Deucher 	struct list_head	flist[AMDGPU_MAX_RINGS];
62797b2e202SAlex Deucher 	struct list_head	olist;
62897b2e202SAlex Deucher 	unsigned		size;
62997b2e202SAlex Deucher 	uint64_t		gpu_addr;
63097b2e202SAlex Deucher 	void			*cpu_ptr;
63197b2e202SAlex Deucher 	uint32_t		domain;
63297b2e202SAlex Deucher 	uint32_t		align;
63397b2e202SAlex Deucher };
63497b2e202SAlex Deucher 
63597b2e202SAlex Deucher struct amdgpu_sa_bo;
63697b2e202SAlex Deucher 
63797b2e202SAlex Deucher /* sub-allocation buffer */
63897b2e202SAlex Deucher struct amdgpu_sa_bo {
63997b2e202SAlex Deucher 	struct list_head		olist;
64097b2e202SAlex Deucher 	struct list_head		flist;
64197b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
64297b2e202SAlex Deucher 	unsigned			soffset;
64397b2e202SAlex Deucher 	unsigned			eoffset;
64497b2e202SAlex Deucher 	struct amdgpu_fence		*fence;
64597b2e202SAlex Deucher };
64697b2e202SAlex Deucher 
64797b2e202SAlex Deucher /*
64897b2e202SAlex Deucher  * GEM objects.
64997b2e202SAlex Deucher  */
65097b2e202SAlex Deucher struct amdgpu_gem {
65197b2e202SAlex Deucher 	struct mutex		mutex;
65297b2e202SAlex Deucher 	struct list_head	objects;
65397b2e202SAlex Deucher };
65497b2e202SAlex Deucher 
65597b2e202SAlex Deucher int amdgpu_gem_init(struct amdgpu_device *adev);
65697b2e202SAlex Deucher void amdgpu_gem_fini(struct amdgpu_device *adev);
65797b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
65897b2e202SAlex Deucher 				int alignment, u32 initial_domain,
65997b2e202SAlex Deucher 				u64 flags, bool kernel,
66097b2e202SAlex Deucher 				struct drm_gem_object **obj);
66197b2e202SAlex Deucher 
66297b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv,
66397b2e202SAlex Deucher 			    struct drm_device *dev,
66497b2e202SAlex Deucher 			    struct drm_mode_create_dumb *args);
66597b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp,
66697b2e202SAlex Deucher 			  struct drm_device *dev,
66797b2e202SAlex Deucher 			  uint32_t handle, uint64_t *offset_p);
66897b2e202SAlex Deucher 
66997b2e202SAlex Deucher /*
67097b2e202SAlex Deucher  * Semaphores.
67197b2e202SAlex Deucher  */
67297b2e202SAlex Deucher struct amdgpu_semaphore {
67397b2e202SAlex Deucher 	struct amdgpu_sa_bo	*sa_bo;
67497b2e202SAlex Deucher 	signed			waiters;
67597b2e202SAlex Deucher 	uint64_t		gpu_addr;
67697b2e202SAlex Deucher };
67797b2e202SAlex Deucher 
67897b2e202SAlex Deucher int amdgpu_semaphore_create(struct amdgpu_device *adev,
67997b2e202SAlex Deucher 			    struct amdgpu_semaphore **semaphore);
68097b2e202SAlex Deucher bool amdgpu_semaphore_emit_signal(struct amdgpu_ring *ring,
68197b2e202SAlex Deucher 				  struct amdgpu_semaphore *semaphore);
68297b2e202SAlex Deucher bool amdgpu_semaphore_emit_wait(struct amdgpu_ring *ring,
68397b2e202SAlex Deucher 				struct amdgpu_semaphore *semaphore);
68497b2e202SAlex Deucher void amdgpu_semaphore_free(struct amdgpu_device *adev,
68597b2e202SAlex Deucher 			   struct amdgpu_semaphore **semaphore,
68697b2e202SAlex Deucher 			   struct amdgpu_fence *fence);
68797b2e202SAlex Deucher 
68897b2e202SAlex Deucher /*
68997b2e202SAlex Deucher  * Synchronization
69097b2e202SAlex Deucher  */
69197b2e202SAlex Deucher struct amdgpu_sync {
69297b2e202SAlex Deucher 	struct amdgpu_semaphore *semaphores[AMDGPU_NUM_SYNCS];
69397b2e202SAlex Deucher 	struct amdgpu_fence	*sync_to[AMDGPU_MAX_RINGS];
69497b2e202SAlex Deucher 	struct amdgpu_fence	*last_vm_update;
69597b2e202SAlex Deucher };
69697b2e202SAlex Deucher 
69797b2e202SAlex Deucher void amdgpu_sync_create(struct amdgpu_sync *sync);
69897b2e202SAlex Deucher void amdgpu_sync_fence(struct amdgpu_sync *sync,
69997b2e202SAlex Deucher 		       struct amdgpu_fence *fence);
70097b2e202SAlex Deucher int amdgpu_sync_resv(struct amdgpu_device *adev,
70197b2e202SAlex Deucher 		     struct amdgpu_sync *sync,
70297b2e202SAlex Deucher 		     struct reservation_object *resv,
70397b2e202SAlex Deucher 		     void *owner);
70497b2e202SAlex Deucher int amdgpu_sync_rings(struct amdgpu_sync *sync,
70597b2e202SAlex Deucher 		      struct amdgpu_ring *ring);
70697b2e202SAlex Deucher void amdgpu_sync_free(struct amdgpu_device *adev, struct amdgpu_sync *sync,
70797b2e202SAlex Deucher 		      struct amdgpu_fence *fence);
70897b2e202SAlex Deucher 
70997b2e202SAlex Deucher /*
71097b2e202SAlex Deucher  * GART structures, functions & helpers
71197b2e202SAlex Deucher  */
71297b2e202SAlex Deucher struct amdgpu_mc;
71397b2e202SAlex Deucher 
71497b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SIZE 4096
71597b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
71697b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SHIFT 12
71797b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
71897b2e202SAlex Deucher 
71997b2e202SAlex Deucher struct amdgpu_gart {
72097b2e202SAlex Deucher 	dma_addr_t			table_addr;
72197b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
72297b2e202SAlex Deucher 	void				*ptr;
72397b2e202SAlex Deucher 	unsigned			num_gpu_pages;
72497b2e202SAlex Deucher 	unsigned			num_cpu_pages;
72597b2e202SAlex Deucher 	unsigned			table_size;
72697b2e202SAlex Deucher 	struct page			**pages;
72797b2e202SAlex Deucher 	dma_addr_t			*pages_addr;
72897b2e202SAlex Deucher 	bool				ready;
72997b2e202SAlex Deucher 	const struct amdgpu_gart_funcs *gart_funcs;
73097b2e202SAlex Deucher };
73197b2e202SAlex Deucher 
73297b2e202SAlex Deucher int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
73397b2e202SAlex Deucher void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
73497b2e202SAlex Deucher int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
73597b2e202SAlex Deucher void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
73697b2e202SAlex Deucher int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
73797b2e202SAlex Deucher void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
73897b2e202SAlex Deucher int amdgpu_gart_init(struct amdgpu_device *adev);
73997b2e202SAlex Deucher void amdgpu_gart_fini(struct amdgpu_device *adev);
74097b2e202SAlex Deucher void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
74197b2e202SAlex Deucher 			int pages);
74297b2e202SAlex Deucher int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
74397b2e202SAlex Deucher 		     int pages, struct page **pagelist,
74497b2e202SAlex Deucher 		     dma_addr_t *dma_addr, uint32_t flags);
74597b2e202SAlex Deucher 
74697b2e202SAlex Deucher /*
74797b2e202SAlex Deucher  * GPU MC structures, functions & helpers
74897b2e202SAlex Deucher  */
74997b2e202SAlex Deucher struct amdgpu_mc {
75097b2e202SAlex Deucher 	resource_size_t		aper_size;
75197b2e202SAlex Deucher 	resource_size_t		aper_base;
75297b2e202SAlex Deucher 	resource_size_t		agp_base;
75397b2e202SAlex Deucher 	/* for some chips with <= 32MB we need to lie
75497b2e202SAlex Deucher 	 * about vram size near mc fb location */
75597b2e202SAlex Deucher 	u64			mc_vram_size;
75697b2e202SAlex Deucher 	u64			visible_vram_size;
75797b2e202SAlex Deucher 	u64			gtt_size;
75897b2e202SAlex Deucher 	u64			gtt_start;
75997b2e202SAlex Deucher 	u64			gtt_end;
76097b2e202SAlex Deucher 	u64			vram_start;
76197b2e202SAlex Deucher 	u64			vram_end;
76297b2e202SAlex Deucher 	unsigned		vram_width;
76397b2e202SAlex Deucher 	u64			real_vram_size;
76497b2e202SAlex Deucher 	int			vram_mtrr;
76597b2e202SAlex Deucher 	u64                     gtt_base_align;
76697b2e202SAlex Deucher 	u64                     mc_mask;
76797b2e202SAlex Deucher 	const struct firmware   *fw;	/* MC firmware */
76897b2e202SAlex Deucher 	uint32_t                fw_version;
76997b2e202SAlex Deucher 	struct amdgpu_irq_src	vm_fault;
77097b2e202SAlex Deucher 	bool                    is_gddr5;
77197b2e202SAlex Deucher };
77297b2e202SAlex Deucher 
77397b2e202SAlex Deucher /*
77497b2e202SAlex Deucher  * GPU doorbell structures, functions & helpers
77597b2e202SAlex Deucher  */
77697b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
77797b2e202SAlex Deucher {
77897b2e202SAlex Deucher 	AMDGPU_DOORBELL_KIQ                     = 0x000,
77997b2e202SAlex Deucher 	AMDGPU_DOORBELL_HIQ                     = 0x001,
78097b2e202SAlex Deucher 	AMDGPU_DOORBELL_DIQ                     = 0x002,
78197b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
78297b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
78397b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
78497b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
78597b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
78697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
78797b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
78897b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
78997b2e202SAlex Deucher 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
79097b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
79197b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
79297b2e202SAlex Deucher 	AMDGPU_DOORBELL_IH                      = 0x1E8,
79397b2e202SAlex Deucher 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
79497b2e202SAlex Deucher 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
79597b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT;
79697b2e202SAlex Deucher 
79797b2e202SAlex Deucher struct amdgpu_doorbell {
79897b2e202SAlex Deucher 	/* doorbell mmio */
79997b2e202SAlex Deucher 	resource_size_t		base;
80097b2e202SAlex Deucher 	resource_size_t		size;
80197b2e202SAlex Deucher 	u32 __iomem		*ptr;
80297b2e202SAlex Deucher 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
80397b2e202SAlex Deucher };
80497b2e202SAlex Deucher 
80597b2e202SAlex Deucher void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
80697b2e202SAlex Deucher 				phys_addr_t *aperture_base,
80797b2e202SAlex Deucher 				size_t *aperture_size,
80897b2e202SAlex Deucher 				size_t *start_offset);
80997b2e202SAlex Deucher 
81097b2e202SAlex Deucher /*
81197b2e202SAlex Deucher  * IRQS.
81297b2e202SAlex Deucher  */
81397b2e202SAlex Deucher 
81497b2e202SAlex Deucher struct amdgpu_flip_work {
81597b2e202SAlex Deucher 	struct work_struct		flip_work;
81697b2e202SAlex Deucher 	struct work_struct		unpin_work;
81797b2e202SAlex Deucher 	struct amdgpu_device		*adev;
81897b2e202SAlex Deucher 	int				crtc_id;
81997b2e202SAlex Deucher 	uint64_t			base;
82097b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
82197b2e202SAlex Deucher 	struct amdgpu_bo		*old_rbo;
82297b2e202SAlex Deucher 	struct fence			*fence;
82397b2e202SAlex Deucher };
82497b2e202SAlex Deucher 
82597b2e202SAlex Deucher 
82697b2e202SAlex Deucher /*
82797b2e202SAlex Deucher  * CP & rings.
82897b2e202SAlex Deucher  */
82997b2e202SAlex Deucher 
83097b2e202SAlex Deucher struct amdgpu_ib {
83197b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
83297b2e202SAlex Deucher 	uint32_t			length_dw;
83397b2e202SAlex Deucher 	uint64_t			gpu_addr;
83497b2e202SAlex Deucher 	uint32_t			*ptr;
83597b2e202SAlex Deucher 	struct amdgpu_ring		*ring;
83697b2e202SAlex Deucher 	struct amdgpu_fence		*fence;
83797b2e202SAlex Deucher 	struct amdgpu_user_fence        *user;
83897b2e202SAlex Deucher 	struct amdgpu_vm		*vm;
8393cb485f3SChristian König 	struct amdgpu_ctx		*ctx;
84097b2e202SAlex Deucher 	struct amdgpu_sync		sync;
84197b2e202SAlex Deucher 	uint32_t			gds_base, gds_size;
84297b2e202SAlex Deucher 	uint32_t			gws_base, gws_size;
84397b2e202SAlex Deucher 	uint32_t			oa_base, oa_size;
844de807f81SJammy Zhou 	uint32_t			flags;
84597b2e202SAlex Deucher };
84697b2e202SAlex Deucher 
84797b2e202SAlex Deucher enum amdgpu_ring_type {
84897b2e202SAlex Deucher 	AMDGPU_RING_TYPE_GFX,
84997b2e202SAlex Deucher 	AMDGPU_RING_TYPE_COMPUTE,
85097b2e202SAlex Deucher 	AMDGPU_RING_TYPE_SDMA,
85197b2e202SAlex Deucher 	AMDGPU_RING_TYPE_UVD,
85297b2e202SAlex Deucher 	AMDGPU_RING_TYPE_VCE
85397b2e202SAlex Deucher };
85497b2e202SAlex Deucher 
85597b2e202SAlex Deucher struct amdgpu_ring {
85697b2e202SAlex Deucher 	struct amdgpu_device		*adev;
85797b2e202SAlex Deucher 	const struct amdgpu_ring_funcs	*funcs;
85897b2e202SAlex Deucher 	struct amdgpu_fence_driver	fence_drv;
85997b2e202SAlex Deucher 
86097b2e202SAlex Deucher 	struct mutex		*ring_lock;
86197b2e202SAlex Deucher 	struct amdgpu_bo	*ring_obj;
86297b2e202SAlex Deucher 	volatile uint32_t	*ring;
86397b2e202SAlex Deucher 	unsigned		rptr_offs;
86497b2e202SAlex Deucher 	u64			next_rptr_gpu_addr;
86597b2e202SAlex Deucher 	volatile u32		*next_rptr_cpu_addr;
86697b2e202SAlex Deucher 	unsigned		wptr;
86797b2e202SAlex Deucher 	unsigned		wptr_old;
86897b2e202SAlex Deucher 	unsigned		ring_size;
86997b2e202SAlex Deucher 	unsigned		ring_free_dw;
87097b2e202SAlex Deucher 	int			count_dw;
87197b2e202SAlex Deucher 	atomic_t		last_rptr;
87297b2e202SAlex Deucher 	atomic64_t		last_activity;
87397b2e202SAlex Deucher 	uint64_t		gpu_addr;
87497b2e202SAlex Deucher 	uint32_t		align_mask;
87597b2e202SAlex Deucher 	uint32_t		ptr_mask;
87697b2e202SAlex Deucher 	bool			ready;
87797b2e202SAlex Deucher 	u32			nop;
87897b2e202SAlex Deucher 	u32			idx;
87997b2e202SAlex Deucher 	u64			last_semaphore_signal_addr;
88097b2e202SAlex Deucher 	u64			last_semaphore_wait_addr;
88197b2e202SAlex Deucher 	u32			me;
88297b2e202SAlex Deucher 	u32			pipe;
88397b2e202SAlex Deucher 	u32			queue;
88497b2e202SAlex Deucher 	struct amdgpu_bo	*mqd_obj;
88597b2e202SAlex Deucher 	u32			doorbell_index;
88697b2e202SAlex Deucher 	bool			use_doorbell;
88797b2e202SAlex Deucher 	unsigned		wptr_offs;
88897b2e202SAlex Deucher 	unsigned		next_rptr_offs;
88997b2e202SAlex Deucher 	unsigned		fence_offs;
8903cb485f3SChristian König 	struct amdgpu_ctx	*current_ctx;
89197b2e202SAlex Deucher 	enum amdgpu_ring_type	type;
89297b2e202SAlex Deucher 	char			name[16];
89397b2e202SAlex Deucher };
89497b2e202SAlex Deucher 
89597b2e202SAlex Deucher /*
89697b2e202SAlex Deucher  * VM
89797b2e202SAlex Deucher  */
89897b2e202SAlex Deucher 
89997b2e202SAlex Deucher /* maximum number of VMIDs */
90097b2e202SAlex Deucher #define AMDGPU_NUM_VM	16
90197b2e202SAlex Deucher 
90297b2e202SAlex Deucher /* number of entries in page table */
90397b2e202SAlex Deucher #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
90497b2e202SAlex Deucher 
90597b2e202SAlex Deucher /* PTBs (Page Table Blocks) need to be aligned to 32K */
90697b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_SIZE   32768
90797b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
90897b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
90997b2e202SAlex Deucher 
91097b2e202SAlex Deucher #define AMDGPU_PTE_VALID	(1 << 0)
91197b2e202SAlex Deucher #define AMDGPU_PTE_SYSTEM	(1 << 1)
91297b2e202SAlex Deucher #define AMDGPU_PTE_SNOOPED	(1 << 2)
91397b2e202SAlex Deucher 
91497b2e202SAlex Deucher /* VI only */
91597b2e202SAlex Deucher #define AMDGPU_PTE_EXECUTABLE	(1 << 4)
91697b2e202SAlex Deucher 
91797b2e202SAlex Deucher #define AMDGPU_PTE_READABLE	(1 << 5)
91897b2e202SAlex Deucher #define AMDGPU_PTE_WRITEABLE	(1 << 6)
91997b2e202SAlex Deucher 
92097b2e202SAlex Deucher /* PTE (Page Table Entry) fragment field for different page sizes */
92197b2e202SAlex Deucher #define AMDGPU_PTE_FRAG_4KB	(0 << 7)
92297b2e202SAlex Deucher #define AMDGPU_PTE_FRAG_64KB	(4 << 7)
92397b2e202SAlex Deucher #define AMDGPU_LOG2_PAGES_PER_FRAG 4
92497b2e202SAlex Deucher 
92597b2e202SAlex Deucher struct amdgpu_vm_pt {
92697b2e202SAlex Deucher 	struct amdgpu_bo		*bo;
92797b2e202SAlex Deucher 	uint64_t			addr;
92897b2e202SAlex Deucher };
92997b2e202SAlex Deucher 
93097b2e202SAlex Deucher struct amdgpu_vm_id {
93197b2e202SAlex Deucher 	unsigned		id;
93297b2e202SAlex Deucher 	uint64_t		pd_gpu_addr;
93397b2e202SAlex Deucher 	/* last flushed PD/PT update */
93497b2e202SAlex Deucher 	struct amdgpu_fence	*flushed_updates;
93597b2e202SAlex Deucher 	/* last use of vmid */
93697b2e202SAlex Deucher 	struct amdgpu_fence	*last_id_use;
93797b2e202SAlex Deucher };
93897b2e202SAlex Deucher 
93997b2e202SAlex Deucher struct amdgpu_vm {
94097b2e202SAlex Deucher 	struct mutex		mutex;
94197b2e202SAlex Deucher 
94297b2e202SAlex Deucher 	struct rb_root		va;
94397b2e202SAlex Deucher 
94497b2e202SAlex Deucher 	/* protecting invalidated and freed */
94597b2e202SAlex Deucher 	spinlock_t		status_lock;
94697b2e202SAlex Deucher 
94797b2e202SAlex Deucher 	/* BOs moved, but not yet updated in the PT */
94897b2e202SAlex Deucher 	struct list_head	invalidated;
94997b2e202SAlex Deucher 
95097b2e202SAlex Deucher 	/* BOs freed, but not yet updated in the PT */
95197b2e202SAlex Deucher 	struct list_head	freed;
95297b2e202SAlex Deucher 
95397b2e202SAlex Deucher 	/* contains the page directory */
95497b2e202SAlex Deucher 	struct amdgpu_bo	*page_directory;
95597b2e202SAlex Deucher 	unsigned		max_pde_used;
95697b2e202SAlex Deucher 
95797b2e202SAlex Deucher 	/* array of page tables, one for each page directory entry */
95897b2e202SAlex Deucher 	struct amdgpu_vm_pt	*page_tables;
95997b2e202SAlex Deucher 
96097b2e202SAlex Deucher 	/* for id and flush management per ring */
96197b2e202SAlex Deucher 	struct amdgpu_vm_id	ids[AMDGPU_MAX_RINGS];
96297b2e202SAlex Deucher };
96397b2e202SAlex Deucher 
96497b2e202SAlex Deucher struct amdgpu_vm_manager {
96597b2e202SAlex Deucher 	struct amdgpu_fence		*active[AMDGPU_NUM_VM];
96697b2e202SAlex Deucher 	uint32_t			max_pfn;
96797b2e202SAlex Deucher 	/* number of VMIDs */
96897b2e202SAlex Deucher 	unsigned			nvm;
96997b2e202SAlex Deucher 	/* vram base address for page table entry  */
97097b2e202SAlex Deucher 	u64				vram_base_offset;
97197b2e202SAlex Deucher 	/* is vm enabled? */
97297b2e202SAlex Deucher 	bool				enabled;
97397b2e202SAlex Deucher 	/* for hw to save the PD addr on suspend/resume */
97497b2e202SAlex Deucher 	uint32_t			saved_table_addr[AMDGPU_NUM_VM];
97597b2e202SAlex Deucher 	/* vm pte handling */
97697b2e202SAlex Deucher 	const struct amdgpu_vm_pte_funcs        *vm_pte_funcs;
97797b2e202SAlex Deucher 	struct amdgpu_ring                      *vm_pte_funcs_ring;
97897b2e202SAlex Deucher };
97997b2e202SAlex Deucher 
98097b2e202SAlex Deucher /*
98197b2e202SAlex Deucher  * context related structures
98297b2e202SAlex Deucher  */
98397b2e202SAlex Deucher 
98497b2e202SAlex Deucher struct amdgpu_ctx_state {
98597b2e202SAlex Deucher 	uint64_t flags;
986d94aed5aSMarek Olšák 	uint32_t hangs;
98797b2e202SAlex Deucher };
98897b2e202SAlex Deucher 
98997b2e202SAlex Deucher struct amdgpu_ctx {
99097b2e202SAlex Deucher 	/* call kref_get()before CS start and kref_put() after CS fence signaled */
99197b2e202SAlex Deucher 	struct kref refcount;
99297b2e202SAlex Deucher 	struct amdgpu_fpriv *fpriv;
99397b2e202SAlex Deucher 	struct amdgpu_ctx_state state;
99497b2e202SAlex Deucher 	uint32_t id;
995d94aed5aSMarek Olšák 	unsigned reset_counter;
99697b2e202SAlex Deucher };
99797b2e202SAlex Deucher 
99897b2e202SAlex Deucher struct amdgpu_ctx_mgr {
99997b2e202SAlex Deucher 	struct amdgpu_device *adev;
100097b2e202SAlex Deucher 	struct idr ctx_handles;
100197b2e202SAlex Deucher 	/* lock for IDR system */
10020147ee0fSMarek Olšák 	struct mutex lock;
100397b2e202SAlex Deucher };
100497b2e202SAlex Deucher 
100597b2e202SAlex Deucher /*
100697b2e202SAlex Deucher  * file private structure
100797b2e202SAlex Deucher  */
100897b2e202SAlex Deucher 
100997b2e202SAlex Deucher struct amdgpu_fpriv {
101097b2e202SAlex Deucher 	struct amdgpu_vm	vm;
101197b2e202SAlex Deucher 	struct mutex		bo_list_lock;
101297b2e202SAlex Deucher 	struct idr		bo_list_handles;
101397b2e202SAlex Deucher 	struct amdgpu_ctx_mgr ctx_mgr;
101497b2e202SAlex Deucher };
101597b2e202SAlex Deucher 
101697b2e202SAlex Deucher /*
101797b2e202SAlex Deucher  * residency list
101897b2e202SAlex Deucher  */
101997b2e202SAlex Deucher 
102097b2e202SAlex Deucher struct amdgpu_bo_list {
102197b2e202SAlex Deucher 	struct mutex lock;
102297b2e202SAlex Deucher 	struct amdgpu_bo *gds_obj;
102397b2e202SAlex Deucher 	struct amdgpu_bo *gws_obj;
102497b2e202SAlex Deucher 	struct amdgpu_bo *oa_obj;
102597b2e202SAlex Deucher 	bool has_userptr;
102697b2e202SAlex Deucher 	unsigned num_entries;
102797b2e202SAlex Deucher 	struct amdgpu_bo_list_entry *array;
102897b2e202SAlex Deucher };
102997b2e202SAlex Deucher 
103097b2e202SAlex Deucher struct amdgpu_bo_list *
103197b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
103297b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
103397b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
103497b2e202SAlex Deucher 
103597b2e202SAlex Deucher /*
103697b2e202SAlex Deucher  * GFX stuff
103797b2e202SAlex Deucher  */
103897b2e202SAlex Deucher #include "clearstate_defs.h"
103997b2e202SAlex Deucher 
104097b2e202SAlex Deucher struct amdgpu_rlc {
104197b2e202SAlex Deucher 	/* for power gating */
104297b2e202SAlex Deucher 	struct amdgpu_bo	*save_restore_obj;
104397b2e202SAlex Deucher 	uint64_t		save_restore_gpu_addr;
104497b2e202SAlex Deucher 	volatile uint32_t	*sr_ptr;
104597b2e202SAlex Deucher 	const u32               *reg_list;
104697b2e202SAlex Deucher 	u32                     reg_list_size;
104797b2e202SAlex Deucher 	/* for clear state */
104897b2e202SAlex Deucher 	struct amdgpu_bo	*clear_state_obj;
104997b2e202SAlex Deucher 	uint64_t		clear_state_gpu_addr;
105097b2e202SAlex Deucher 	volatile uint32_t	*cs_ptr;
105197b2e202SAlex Deucher 	const struct cs_section_def   *cs_data;
105297b2e202SAlex Deucher 	u32                     clear_state_size;
105397b2e202SAlex Deucher 	/* for cp tables */
105497b2e202SAlex Deucher 	struct amdgpu_bo	*cp_table_obj;
105597b2e202SAlex Deucher 	uint64_t		cp_table_gpu_addr;
105697b2e202SAlex Deucher 	volatile uint32_t	*cp_table_ptr;
105797b2e202SAlex Deucher 	u32                     cp_table_size;
105897b2e202SAlex Deucher };
105997b2e202SAlex Deucher 
106097b2e202SAlex Deucher struct amdgpu_mec {
106197b2e202SAlex Deucher 	struct amdgpu_bo	*hpd_eop_obj;
106297b2e202SAlex Deucher 	u64			hpd_eop_gpu_addr;
106397b2e202SAlex Deucher 	u32 num_pipe;
106497b2e202SAlex Deucher 	u32 num_mec;
106597b2e202SAlex Deucher 	u32 num_queue;
106697b2e202SAlex Deucher };
106797b2e202SAlex Deucher 
106897b2e202SAlex Deucher /*
106997b2e202SAlex Deucher  * GPU scratch registers structures, functions & helpers
107097b2e202SAlex Deucher  */
107197b2e202SAlex Deucher struct amdgpu_scratch {
107297b2e202SAlex Deucher 	unsigned		num_reg;
107397b2e202SAlex Deucher 	uint32_t                reg_base;
107497b2e202SAlex Deucher 	bool			free[32];
107597b2e202SAlex Deucher 	uint32_t		reg[32];
107697b2e202SAlex Deucher };
107797b2e202SAlex Deucher 
107897b2e202SAlex Deucher /*
107997b2e202SAlex Deucher  * GFX configurations
108097b2e202SAlex Deucher  */
108197b2e202SAlex Deucher struct amdgpu_gca_config {
108297b2e202SAlex Deucher 	unsigned max_shader_engines;
108397b2e202SAlex Deucher 	unsigned max_tile_pipes;
108497b2e202SAlex Deucher 	unsigned max_cu_per_sh;
108597b2e202SAlex Deucher 	unsigned max_sh_per_se;
108697b2e202SAlex Deucher 	unsigned max_backends_per_se;
108797b2e202SAlex Deucher 	unsigned max_texture_channel_caches;
108897b2e202SAlex Deucher 	unsigned max_gprs;
108997b2e202SAlex Deucher 	unsigned max_gs_threads;
109097b2e202SAlex Deucher 	unsigned max_hw_contexts;
109197b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_frontend;
109297b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_backend;
109397b2e202SAlex Deucher 	unsigned sc_hiz_tile_fifo_size;
109497b2e202SAlex Deucher 	unsigned sc_earlyz_tile_fifo_size;
109597b2e202SAlex Deucher 
109697b2e202SAlex Deucher 	unsigned num_tile_pipes;
109797b2e202SAlex Deucher 	unsigned backend_enable_mask;
109897b2e202SAlex Deucher 	unsigned mem_max_burst_length_bytes;
109997b2e202SAlex Deucher 	unsigned mem_row_size_in_kb;
110097b2e202SAlex Deucher 	unsigned shader_engine_tile_size;
110197b2e202SAlex Deucher 	unsigned num_gpus;
110297b2e202SAlex Deucher 	unsigned multi_gpu_tile_size;
110397b2e202SAlex Deucher 	unsigned mc_arb_ramcfg;
110497b2e202SAlex Deucher 	unsigned gb_addr_config;
110597b2e202SAlex Deucher 
110697b2e202SAlex Deucher 	uint32_t tile_mode_array[32];
110797b2e202SAlex Deucher 	uint32_t macrotile_mode_array[16];
110897b2e202SAlex Deucher };
110997b2e202SAlex Deucher 
111097b2e202SAlex Deucher struct amdgpu_gfx {
111197b2e202SAlex Deucher 	struct mutex			gpu_clock_mutex;
111297b2e202SAlex Deucher 	struct amdgpu_gca_config	config;
111397b2e202SAlex Deucher 	struct amdgpu_rlc		rlc;
111497b2e202SAlex Deucher 	struct amdgpu_mec		mec;
111597b2e202SAlex Deucher 	struct amdgpu_scratch		scratch;
111697b2e202SAlex Deucher 	const struct firmware		*me_fw;	/* ME firmware */
111797b2e202SAlex Deucher 	uint32_t			me_fw_version;
111897b2e202SAlex Deucher 	const struct firmware		*pfp_fw; /* PFP firmware */
111997b2e202SAlex Deucher 	uint32_t			pfp_fw_version;
112097b2e202SAlex Deucher 	const struct firmware		*ce_fw;	/* CE firmware */
112197b2e202SAlex Deucher 	uint32_t			ce_fw_version;
112297b2e202SAlex Deucher 	const struct firmware		*rlc_fw; /* RLC firmware */
112397b2e202SAlex Deucher 	uint32_t			rlc_fw_version;
112497b2e202SAlex Deucher 	const struct firmware		*mec_fw; /* MEC firmware */
112597b2e202SAlex Deucher 	uint32_t			mec_fw_version;
112697b2e202SAlex Deucher 	const struct firmware		*mec2_fw; /* MEC2 firmware */
112797b2e202SAlex Deucher 	uint32_t			mec2_fw_version;
112897b2e202SAlex Deucher 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
112997b2e202SAlex Deucher 	unsigned			num_gfx_rings;
113097b2e202SAlex Deucher 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
113197b2e202SAlex Deucher 	unsigned			num_compute_rings;
113297b2e202SAlex Deucher 	struct amdgpu_irq_src		eop_irq;
113397b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_reg_irq;
113497b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_inst_irq;
113597b2e202SAlex Deucher 	/* gfx status */
113697b2e202SAlex Deucher 	uint32_t gfx_current_status;
113797b2e202SAlex Deucher 	/* sync signal for const engine */
113897b2e202SAlex Deucher 	unsigned ce_sync_offs;
1139a101a899SKen Wang 	/* ce ram size*/
1140a101a899SKen Wang 	unsigned ce_ram_size;
114197b2e202SAlex Deucher };
114297b2e202SAlex Deucher 
114397b2e202SAlex Deucher int amdgpu_ib_get(struct amdgpu_ring *ring, struct amdgpu_vm *vm,
114497b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
114597b2e202SAlex Deucher void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib);
114697b2e202SAlex Deucher int amdgpu_ib_schedule(struct amdgpu_device *adev, unsigned num_ibs,
114797b2e202SAlex Deucher 		       struct amdgpu_ib *ib, void *owner);
114897b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
114997b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
115097b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
115197b2e202SAlex Deucher /* Ring access between begin & end cannot sleep */
115297b2e202SAlex Deucher void amdgpu_ring_free_size(struct amdgpu_ring *ring);
115397b2e202SAlex Deucher int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
115497b2e202SAlex Deucher int amdgpu_ring_lock(struct amdgpu_ring *ring, unsigned ndw);
115597b2e202SAlex Deucher void amdgpu_ring_commit(struct amdgpu_ring *ring);
115697b2e202SAlex Deucher void amdgpu_ring_unlock_commit(struct amdgpu_ring *ring);
115797b2e202SAlex Deucher void amdgpu_ring_undo(struct amdgpu_ring *ring);
115897b2e202SAlex Deucher void amdgpu_ring_unlock_undo(struct amdgpu_ring *ring);
115997b2e202SAlex Deucher void amdgpu_ring_lockup_update(struct amdgpu_ring *ring);
116097b2e202SAlex Deucher bool amdgpu_ring_test_lockup(struct amdgpu_ring *ring);
116197b2e202SAlex Deucher unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
116297b2e202SAlex Deucher 			    uint32_t **data);
116397b2e202SAlex Deucher int amdgpu_ring_restore(struct amdgpu_ring *ring,
116497b2e202SAlex Deucher 			unsigned size, uint32_t *data);
116597b2e202SAlex Deucher int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
116697b2e202SAlex Deucher 		     unsigned ring_size, u32 nop, u32 align_mask,
116797b2e202SAlex Deucher 		     struct amdgpu_irq_src *irq_src, unsigned irq_type,
116897b2e202SAlex Deucher 		     enum amdgpu_ring_type ring_type);
116997b2e202SAlex Deucher void amdgpu_ring_fini(struct amdgpu_ring *ring);
117097b2e202SAlex Deucher 
117197b2e202SAlex Deucher /*
117297b2e202SAlex Deucher  * CS.
117397b2e202SAlex Deucher  */
117497b2e202SAlex Deucher struct amdgpu_cs_chunk {
117597b2e202SAlex Deucher 	uint32_t		chunk_id;
117697b2e202SAlex Deucher 	uint32_t		length_dw;
117797b2e202SAlex Deucher 	uint32_t		*kdata;
117897b2e202SAlex Deucher 	void __user		*user_ptr;
117997b2e202SAlex Deucher };
118097b2e202SAlex Deucher 
118197b2e202SAlex Deucher struct amdgpu_cs_parser {
118297b2e202SAlex Deucher 	struct amdgpu_device	*adev;
118397b2e202SAlex Deucher 	struct drm_file		*filp;
11843cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
118597b2e202SAlex Deucher 	struct amdgpu_bo_list *bo_list;
118697b2e202SAlex Deucher 	/* chunks */
118797b2e202SAlex Deucher 	unsigned		nchunks;
118897b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
118997b2e202SAlex Deucher 	/* relocations */
119097b2e202SAlex Deucher 	struct amdgpu_bo_list_entry	*vm_bos;
119197b2e202SAlex Deucher 	struct amdgpu_bo_list_entry	*ib_bos;
119297b2e202SAlex Deucher 	struct list_head	validated;
119397b2e202SAlex Deucher 
119497b2e202SAlex Deucher 	struct amdgpu_ib	*ibs;
119597b2e202SAlex Deucher 	uint32_t		num_ibs;
119697b2e202SAlex Deucher 
119797b2e202SAlex Deucher 	struct ww_acquire_ctx	ticket;
119897b2e202SAlex Deucher 
119997b2e202SAlex Deucher 	/* user fence */
120097b2e202SAlex Deucher 	struct amdgpu_user_fence uf;
120197b2e202SAlex Deucher };
120297b2e202SAlex Deucher 
120397b2e202SAlex Deucher static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, uint32_t ib_idx, int idx)
120497b2e202SAlex Deucher {
120597b2e202SAlex Deucher 	return p->ibs[ib_idx].ptr[idx];
120697b2e202SAlex Deucher }
120797b2e202SAlex Deucher 
120897b2e202SAlex Deucher /*
120997b2e202SAlex Deucher  * Writeback
121097b2e202SAlex Deucher  */
121197b2e202SAlex Deucher #define AMDGPU_MAX_WB 1024	/* Reserve at most 1024 WB slots for amdgpu-owned rings. */
121297b2e202SAlex Deucher 
121397b2e202SAlex Deucher struct amdgpu_wb {
121497b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
121597b2e202SAlex Deucher 	volatile uint32_t	*wb;
121697b2e202SAlex Deucher 	uint64_t		gpu_addr;
121797b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
121897b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
121997b2e202SAlex Deucher };
122097b2e202SAlex Deucher 
122197b2e202SAlex Deucher int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
122297b2e202SAlex Deucher void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
122397b2e202SAlex Deucher 
122497b2e202SAlex Deucher /**
122597b2e202SAlex Deucher  * struct amdgpu_pm - power management datas
122697b2e202SAlex Deucher  * It keeps track of various data needed to take powermanagement decision.
122797b2e202SAlex Deucher  */
122897b2e202SAlex Deucher 
122997b2e202SAlex Deucher enum amdgpu_pm_state_type {
123097b2e202SAlex Deucher 	/* not used for dpm */
123197b2e202SAlex Deucher 	POWER_STATE_TYPE_DEFAULT,
123297b2e202SAlex Deucher 	POWER_STATE_TYPE_POWERSAVE,
123397b2e202SAlex Deucher 	/* user selectable states */
123497b2e202SAlex Deucher 	POWER_STATE_TYPE_BATTERY,
123597b2e202SAlex Deucher 	POWER_STATE_TYPE_BALANCED,
123697b2e202SAlex Deucher 	POWER_STATE_TYPE_PERFORMANCE,
123797b2e202SAlex Deucher 	/* internal states */
123897b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_UVD,
123997b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_UVD_SD,
124097b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_UVD_HD,
124197b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_UVD_HD2,
124297b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_UVD_MVC,
124397b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_BOOT,
124497b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_THERMAL,
124597b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_ACPI,
124697b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_ULV,
124797b2e202SAlex Deucher 	POWER_STATE_TYPE_INTERNAL_3DPERF,
124897b2e202SAlex Deucher };
124997b2e202SAlex Deucher 
125097b2e202SAlex Deucher enum amdgpu_int_thermal_type {
125197b2e202SAlex Deucher 	THERMAL_TYPE_NONE,
125297b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL,
125397b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL_GPIO,
125497b2e202SAlex Deucher 	THERMAL_TYPE_RV6XX,
125597b2e202SAlex Deucher 	THERMAL_TYPE_RV770,
125697b2e202SAlex Deucher 	THERMAL_TYPE_ADT7473_WITH_INTERNAL,
125797b2e202SAlex Deucher 	THERMAL_TYPE_EVERGREEN,
125897b2e202SAlex Deucher 	THERMAL_TYPE_SUMO,
125997b2e202SAlex Deucher 	THERMAL_TYPE_NI,
126097b2e202SAlex Deucher 	THERMAL_TYPE_SI,
126197b2e202SAlex Deucher 	THERMAL_TYPE_EMC2103_WITH_INTERNAL,
126297b2e202SAlex Deucher 	THERMAL_TYPE_CI,
126397b2e202SAlex Deucher 	THERMAL_TYPE_KV,
126497b2e202SAlex Deucher };
126597b2e202SAlex Deucher 
126697b2e202SAlex Deucher enum amdgpu_dpm_auto_throttle_src {
126797b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
126897b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
126997b2e202SAlex Deucher };
127097b2e202SAlex Deucher 
127197b2e202SAlex Deucher enum amdgpu_dpm_event_src {
127297b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
127397b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
127497b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
127597b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
127697b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
127797b2e202SAlex Deucher };
127897b2e202SAlex Deucher 
127997b2e202SAlex Deucher #define AMDGPU_MAX_VCE_LEVELS 6
128097b2e202SAlex Deucher 
128197b2e202SAlex Deucher enum amdgpu_vce_level {
128297b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_AC_ALL = 0,     /* AC, All cases */
128397b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_EE = 1,      /* DC, entropy encoding */
128497b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_LOW = 2,  /* DC, low latency queue, res <= 720 */
128597b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
128697b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_LOW = 4,  /* DC, general purpose queue, res <= 720 */
128797b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
128897b2e202SAlex Deucher };
128997b2e202SAlex Deucher 
129097b2e202SAlex Deucher struct amdgpu_ps {
129197b2e202SAlex Deucher 	u32 caps; /* vbios flags */
129297b2e202SAlex Deucher 	u32 class; /* vbios flags */
129397b2e202SAlex Deucher 	u32 class2; /* vbios flags */
129497b2e202SAlex Deucher 	/* UVD clocks */
129597b2e202SAlex Deucher 	u32 vclk;
129697b2e202SAlex Deucher 	u32 dclk;
129797b2e202SAlex Deucher 	/* VCE clocks */
129897b2e202SAlex Deucher 	u32 evclk;
129997b2e202SAlex Deucher 	u32 ecclk;
130097b2e202SAlex Deucher 	bool vce_active;
130197b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
130297b2e202SAlex Deucher 	/* asic priv */
130397b2e202SAlex Deucher 	void *ps_priv;
130497b2e202SAlex Deucher };
130597b2e202SAlex Deucher 
130697b2e202SAlex Deucher struct amdgpu_dpm_thermal {
130797b2e202SAlex Deucher 	/* thermal interrupt work */
130897b2e202SAlex Deucher 	struct work_struct work;
130997b2e202SAlex Deucher 	/* low temperature threshold */
131097b2e202SAlex Deucher 	int                min_temp;
131197b2e202SAlex Deucher 	/* high temperature threshold */
131297b2e202SAlex Deucher 	int                max_temp;
131397b2e202SAlex Deucher 	/* was last interrupt low to high or high to low */
131497b2e202SAlex Deucher 	bool               high_to_low;
131597b2e202SAlex Deucher 	/* interrupt source */
131697b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
131797b2e202SAlex Deucher };
131897b2e202SAlex Deucher 
131997b2e202SAlex Deucher enum amdgpu_clk_action
132097b2e202SAlex Deucher {
132197b2e202SAlex Deucher 	AMDGPU_SCLK_UP = 1,
132297b2e202SAlex Deucher 	AMDGPU_SCLK_DOWN
132397b2e202SAlex Deucher };
132497b2e202SAlex Deucher 
132597b2e202SAlex Deucher struct amdgpu_blacklist_clocks
132697b2e202SAlex Deucher {
132797b2e202SAlex Deucher 	u32 sclk;
132897b2e202SAlex Deucher 	u32 mclk;
132997b2e202SAlex Deucher 	enum amdgpu_clk_action action;
133097b2e202SAlex Deucher };
133197b2e202SAlex Deucher 
133297b2e202SAlex Deucher struct amdgpu_clock_and_voltage_limits {
133397b2e202SAlex Deucher 	u32 sclk;
133497b2e202SAlex Deucher 	u32 mclk;
133597b2e202SAlex Deucher 	u16 vddc;
133697b2e202SAlex Deucher 	u16 vddci;
133797b2e202SAlex Deucher };
133897b2e202SAlex Deucher 
133997b2e202SAlex Deucher struct amdgpu_clock_array {
134097b2e202SAlex Deucher 	u32 count;
134197b2e202SAlex Deucher 	u32 *values;
134297b2e202SAlex Deucher };
134397b2e202SAlex Deucher 
134497b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_entry {
134597b2e202SAlex Deucher 	u32 clk;
134697b2e202SAlex Deucher 	u16 v;
134797b2e202SAlex Deucher };
134897b2e202SAlex Deucher 
134997b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table {
135097b2e202SAlex Deucher 	u32 count;
135197b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_entry *entries;
135297b2e202SAlex Deucher };
135397b2e202SAlex Deucher 
135497b2e202SAlex Deucher union amdgpu_cac_leakage_entry {
135597b2e202SAlex Deucher 	struct {
135697b2e202SAlex Deucher 		u16 vddc;
135797b2e202SAlex Deucher 		u32 leakage;
135897b2e202SAlex Deucher 	};
135997b2e202SAlex Deucher 	struct {
136097b2e202SAlex Deucher 		u16 vddc1;
136197b2e202SAlex Deucher 		u16 vddc2;
136297b2e202SAlex Deucher 		u16 vddc3;
136397b2e202SAlex Deucher 	};
136497b2e202SAlex Deucher };
136597b2e202SAlex Deucher 
136697b2e202SAlex Deucher struct amdgpu_cac_leakage_table {
136797b2e202SAlex Deucher 	u32 count;
136897b2e202SAlex Deucher 	union amdgpu_cac_leakage_entry *entries;
136997b2e202SAlex Deucher };
137097b2e202SAlex Deucher 
137197b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_entry {
137297b2e202SAlex Deucher 	u16 voltage;
137397b2e202SAlex Deucher 	u32 sclk;
137497b2e202SAlex Deucher 	u32 mclk;
137597b2e202SAlex Deucher };
137697b2e202SAlex Deucher 
137797b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_table {
137897b2e202SAlex Deucher 	u32 count;
137997b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_entry *entries;
138097b2e202SAlex Deucher };
138197b2e202SAlex Deucher 
138297b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_entry {
138397b2e202SAlex Deucher 	u32 vclk;
138497b2e202SAlex Deucher 	u32 dclk;
138597b2e202SAlex Deucher 	u16 v;
138697b2e202SAlex Deucher };
138797b2e202SAlex Deucher 
138897b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_table {
138997b2e202SAlex Deucher 	u8 count;
139097b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
139197b2e202SAlex Deucher };
139297b2e202SAlex Deucher 
139397b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_entry {
139497b2e202SAlex Deucher 	u32 ecclk;
139597b2e202SAlex Deucher 	u32 evclk;
139697b2e202SAlex Deucher 	u16 v;
139797b2e202SAlex Deucher };
139897b2e202SAlex Deucher 
139997b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_table {
140097b2e202SAlex Deucher 	u8 count;
140197b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_entry *entries;
140297b2e202SAlex Deucher };
140397b2e202SAlex Deucher 
140497b2e202SAlex Deucher struct amdgpu_ppm_table {
140597b2e202SAlex Deucher 	u8 ppm_design;
140697b2e202SAlex Deucher 	u16 cpu_core_number;
140797b2e202SAlex Deucher 	u32 platform_tdp;
140897b2e202SAlex Deucher 	u32 small_ac_platform_tdp;
140997b2e202SAlex Deucher 	u32 platform_tdc;
141097b2e202SAlex Deucher 	u32 small_ac_platform_tdc;
141197b2e202SAlex Deucher 	u32 apu_tdp;
141297b2e202SAlex Deucher 	u32 dgpu_tdp;
141397b2e202SAlex Deucher 	u32 dgpu_ulv_power;
141497b2e202SAlex Deucher 	u32 tj_max;
141597b2e202SAlex Deucher };
141697b2e202SAlex Deucher 
141797b2e202SAlex Deucher struct amdgpu_cac_tdp_table {
141897b2e202SAlex Deucher 	u16 tdp;
141997b2e202SAlex Deucher 	u16 configurable_tdp;
142097b2e202SAlex Deucher 	u16 tdc;
142197b2e202SAlex Deucher 	u16 battery_power_limit;
142297b2e202SAlex Deucher 	u16 small_power_limit;
142397b2e202SAlex Deucher 	u16 low_cac_leakage;
142497b2e202SAlex Deucher 	u16 high_cac_leakage;
142597b2e202SAlex Deucher 	u16 maximum_power_delivery_limit;
142697b2e202SAlex Deucher };
142797b2e202SAlex Deucher 
142897b2e202SAlex Deucher struct amdgpu_dpm_dynamic_state {
142997b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
143097b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
143197b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
143297b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
143397b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
143497b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
143597b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
143697b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
143797b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
143897b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
143997b2e202SAlex Deucher 	struct amdgpu_clock_array valid_sclk_values;
144097b2e202SAlex Deucher 	struct amdgpu_clock_array valid_mclk_values;
144197b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
144297b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
144397b2e202SAlex Deucher 	u32 mclk_sclk_ratio;
144497b2e202SAlex Deucher 	u32 sclk_mclk_delta;
144597b2e202SAlex Deucher 	u16 vddc_vddci_delta;
144697b2e202SAlex Deucher 	u16 min_vddc_for_pcie_gen2;
144797b2e202SAlex Deucher 	struct amdgpu_cac_leakage_table cac_leakage_table;
144897b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
144997b2e202SAlex Deucher 	struct amdgpu_ppm_table *ppm_table;
145097b2e202SAlex Deucher 	struct amdgpu_cac_tdp_table *cac_tdp_table;
145197b2e202SAlex Deucher };
145297b2e202SAlex Deucher 
145397b2e202SAlex Deucher struct amdgpu_dpm_fan {
145497b2e202SAlex Deucher 	u16 t_min;
145597b2e202SAlex Deucher 	u16 t_med;
145697b2e202SAlex Deucher 	u16 t_high;
145797b2e202SAlex Deucher 	u16 pwm_min;
145897b2e202SAlex Deucher 	u16 pwm_med;
145997b2e202SAlex Deucher 	u16 pwm_high;
146097b2e202SAlex Deucher 	u8 t_hyst;
146197b2e202SAlex Deucher 	u32 cycle_delay;
146297b2e202SAlex Deucher 	u16 t_max;
146397b2e202SAlex Deucher 	u8 control_mode;
146497b2e202SAlex Deucher 	u16 default_max_fan_pwm;
146597b2e202SAlex Deucher 	u16 default_fan_output_sensitivity;
146697b2e202SAlex Deucher 	u16 fan_output_sensitivity;
146797b2e202SAlex Deucher 	bool ucode_fan_control;
146897b2e202SAlex Deucher };
146997b2e202SAlex Deucher 
147097b2e202SAlex Deucher enum amdgpu_pcie_gen {
147197b2e202SAlex Deucher 	AMDGPU_PCIE_GEN1 = 0,
147297b2e202SAlex Deucher 	AMDGPU_PCIE_GEN2 = 1,
147397b2e202SAlex Deucher 	AMDGPU_PCIE_GEN3 = 2,
147497b2e202SAlex Deucher 	AMDGPU_PCIE_GEN_INVALID = 0xffff
147597b2e202SAlex Deucher };
147697b2e202SAlex Deucher 
147797b2e202SAlex Deucher enum amdgpu_dpm_forced_level {
147897b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
147997b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
148097b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
148197b2e202SAlex Deucher };
148297b2e202SAlex Deucher 
148397b2e202SAlex Deucher struct amdgpu_vce_state {
148497b2e202SAlex Deucher 	/* vce clocks */
148597b2e202SAlex Deucher 	u32 evclk;
148697b2e202SAlex Deucher 	u32 ecclk;
148797b2e202SAlex Deucher 	/* gpu clocks */
148897b2e202SAlex Deucher 	u32 sclk;
148997b2e202SAlex Deucher 	u32 mclk;
149097b2e202SAlex Deucher 	u8 clk_idx;
149197b2e202SAlex Deucher 	u8 pstate;
149297b2e202SAlex Deucher };
149397b2e202SAlex Deucher 
149497b2e202SAlex Deucher struct amdgpu_dpm_funcs {
149597b2e202SAlex Deucher 	int (*get_temperature)(struct amdgpu_device *adev);
149697b2e202SAlex Deucher 	int (*pre_set_power_state)(struct amdgpu_device *adev);
149797b2e202SAlex Deucher 	int (*set_power_state)(struct amdgpu_device *adev);
149897b2e202SAlex Deucher 	void (*post_set_power_state)(struct amdgpu_device *adev);
149997b2e202SAlex Deucher 	void (*display_configuration_changed)(struct amdgpu_device *adev);
150097b2e202SAlex Deucher 	u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
150197b2e202SAlex Deucher 	u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
150297b2e202SAlex Deucher 	void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
150397b2e202SAlex Deucher 	void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
150497b2e202SAlex Deucher 	int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
150597b2e202SAlex Deucher 	bool (*vblank_too_short)(struct amdgpu_device *adev);
150697b2e202SAlex Deucher 	void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
150797b2e202SAlex Deucher 	void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
150897b2e202SAlex Deucher 	void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
150997b2e202SAlex Deucher 	u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
151097b2e202SAlex Deucher 	int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
151197b2e202SAlex Deucher 	int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
151297b2e202SAlex Deucher };
151397b2e202SAlex Deucher 
151497b2e202SAlex Deucher struct amdgpu_dpm {
151597b2e202SAlex Deucher 	struct amdgpu_ps        *ps;
151697b2e202SAlex Deucher 	/* number of valid power states */
151797b2e202SAlex Deucher 	int                     num_ps;
151897b2e202SAlex Deucher 	/* current power state that is active */
151997b2e202SAlex Deucher 	struct amdgpu_ps        *current_ps;
152097b2e202SAlex Deucher 	/* requested power state */
152197b2e202SAlex Deucher 	struct amdgpu_ps        *requested_ps;
152297b2e202SAlex Deucher 	/* boot up power state */
152397b2e202SAlex Deucher 	struct amdgpu_ps        *boot_ps;
152497b2e202SAlex Deucher 	/* default uvd power state */
152597b2e202SAlex Deucher 	struct amdgpu_ps        *uvd_ps;
152697b2e202SAlex Deucher 	/* vce requirements */
152797b2e202SAlex Deucher 	struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
152897b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
152997b2e202SAlex Deucher 	enum amdgpu_pm_state_type state;
153097b2e202SAlex Deucher 	enum amdgpu_pm_state_type user_state;
153197b2e202SAlex Deucher 	u32                     platform_caps;
153297b2e202SAlex Deucher 	u32                     voltage_response_time;
153397b2e202SAlex Deucher 	u32                     backbias_response_time;
153497b2e202SAlex Deucher 	void                    *priv;
153597b2e202SAlex Deucher 	u32			new_active_crtcs;
153697b2e202SAlex Deucher 	int			new_active_crtc_count;
153797b2e202SAlex Deucher 	u32			current_active_crtcs;
153897b2e202SAlex Deucher 	int			current_active_crtc_count;
153997b2e202SAlex Deucher 	struct amdgpu_dpm_dynamic_state dyn_state;
154097b2e202SAlex Deucher 	struct amdgpu_dpm_fan fan;
154197b2e202SAlex Deucher 	u32 tdp_limit;
154297b2e202SAlex Deucher 	u32 near_tdp_limit;
154397b2e202SAlex Deucher 	u32 near_tdp_limit_adjusted;
154497b2e202SAlex Deucher 	u32 sq_ramping_threshold;
154597b2e202SAlex Deucher 	u32 cac_leakage;
154697b2e202SAlex Deucher 	u16 tdp_od_limit;
154797b2e202SAlex Deucher 	u32 tdp_adjustment;
154897b2e202SAlex Deucher 	u16 load_line_slope;
154997b2e202SAlex Deucher 	bool power_control;
155097b2e202SAlex Deucher 	bool ac_power;
155197b2e202SAlex Deucher 	/* special states active */
155297b2e202SAlex Deucher 	bool                    thermal_active;
155397b2e202SAlex Deucher 	bool                    uvd_active;
155497b2e202SAlex Deucher 	bool                    vce_active;
155597b2e202SAlex Deucher 	/* thermal handling */
155697b2e202SAlex Deucher 	struct amdgpu_dpm_thermal thermal;
155797b2e202SAlex Deucher 	/* forced levels */
155897b2e202SAlex Deucher 	enum amdgpu_dpm_forced_level forced_level;
155997b2e202SAlex Deucher };
156097b2e202SAlex Deucher 
156197b2e202SAlex Deucher struct amdgpu_pm {
156297b2e202SAlex Deucher 	struct mutex		mutex;
156397b2e202SAlex Deucher 	u32                     current_sclk;
156497b2e202SAlex Deucher 	u32                     current_mclk;
156597b2e202SAlex Deucher 	u32                     default_sclk;
156697b2e202SAlex Deucher 	u32                     default_mclk;
156797b2e202SAlex Deucher 	struct amdgpu_i2c_chan *i2c_bus;
156897b2e202SAlex Deucher 	/* internal thermal controller on rv6xx+ */
156997b2e202SAlex Deucher 	enum amdgpu_int_thermal_type int_thermal_type;
157097b2e202SAlex Deucher 	struct device	        *int_hwmon_dev;
157197b2e202SAlex Deucher 	/* fan control parameters */
157297b2e202SAlex Deucher 	bool                    no_fan;
157397b2e202SAlex Deucher 	u8                      fan_pulses_per_revolution;
157497b2e202SAlex Deucher 	u8                      fan_min_rpm;
157597b2e202SAlex Deucher 	u8                      fan_max_rpm;
157697b2e202SAlex Deucher 	/* dpm */
157797b2e202SAlex Deucher 	bool                    dpm_enabled;
157897b2e202SAlex Deucher 	struct amdgpu_dpm       dpm;
157997b2e202SAlex Deucher 	const struct firmware	*fw;	/* SMC firmware */
158097b2e202SAlex Deucher 	uint32_t                fw_version;
158197b2e202SAlex Deucher 	const struct amdgpu_dpm_funcs *funcs;
158297b2e202SAlex Deucher };
158397b2e202SAlex Deucher 
158497b2e202SAlex Deucher /*
158597b2e202SAlex Deucher  * UVD
158697b2e202SAlex Deucher  */
158797b2e202SAlex Deucher #define AMDGPU_MAX_UVD_HANDLES	10
158897b2e202SAlex Deucher #define AMDGPU_UVD_STACK_SIZE	(1024*1024)
158997b2e202SAlex Deucher #define AMDGPU_UVD_HEAP_SIZE	(1024*1024)
159097b2e202SAlex Deucher #define AMDGPU_UVD_FIRMWARE_OFFSET 256
159197b2e202SAlex Deucher 
159297b2e202SAlex Deucher struct amdgpu_uvd {
159397b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
159497b2e202SAlex Deucher 	void			*cpu_addr;
159597b2e202SAlex Deucher 	uint64_t		gpu_addr;
159697b2e202SAlex Deucher 	void			*saved_bo;
159797b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_UVD_HANDLES];
159897b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_UVD_HANDLES];
159997b2e202SAlex Deucher 	struct delayed_work	idle_work;
160097b2e202SAlex Deucher 	const struct firmware	*fw;	/* UVD firmware */
160197b2e202SAlex Deucher 	struct amdgpu_ring	ring;
160297b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
160397b2e202SAlex Deucher 	bool			address_64_bit;
160497b2e202SAlex Deucher };
160597b2e202SAlex Deucher 
160697b2e202SAlex Deucher /*
160797b2e202SAlex Deucher  * VCE
160897b2e202SAlex Deucher  */
160997b2e202SAlex Deucher #define AMDGPU_MAX_VCE_HANDLES	16
161097b2e202SAlex Deucher #define AMDGPU_VCE_FIRMWARE_OFFSET 256
161197b2e202SAlex Deucher 
161297b2e202SAlex Deucher struct amdgpu_vce {
161397b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
161497b2e202SAlex Deucher 	uint64_t		gpu_addr;
161597b2e202SAlex Deucher 	unsigned		fw_version;
161697b2e202SAlex Deucher 	unsigned		fb_version;
161797b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
161897b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_VCE_HANDLES];
161997b2e202SAlex Deucher 	struct delayed_work	idle_work;
162097b2e202SAlex Deucher 	const struct firmware	*fw;	/* VCE firmware */
162197b2e202SAlex Deucher 	struct amdgpu_ring	ring[AMDGPU_MAX_VCE_RINGS];
162297b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
162397b2e202SAlex Deucher };
162497b2e202SAlex Deucher 
162597b2e202SAlex Deucher /*
162697b2e202SAlex Deucher  * SDMA
162797b2e202SAlex Deucher  */
162897b2e202SAlex Deucher struct amdgpu_sdma {
162997b2e202SAlex Deucher 	/* SDMA firmware */
163097b2e202SAlex Deucher 	const struct firmware	*fw;
163197b2e202SAlex Deucher 	uint32_t		fw_version;
163297b2e202SAlex Deucher 
163397b2e202SAlex Deucher 	struct amdgpu_ring	ring;
163497b2e202SAlex Deucher };
163597b2e202SAlex Deucher 
163697b2e202SAlex Deucher /*
163797b2e202SAlex Deucher  * Firmware
163897b2e202SAlex Deucher  */
163997b2e202SAlex Deucher struct amdgpu_firmware {
164097b2e202SAlex Deucher 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
164197b2e202SAlex Deucher 	bool smu_load;
164297b2e202SAlex Deucher 	struct amdgpu_bo *fw_buf;
164397b2e202SAlex Deucher 	unsigned int fw_size;
164497b2e202SAlex Deucher };
164597b2e202SAlex Deucher 
164697b2e202SAlex Deucher /*
164797b2e202SAlex Deucher  * Benchmarking
164897b2e202SAlex Deucher  */
164997b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
165097b2e202SAlex Deucher 
165197b2e202SAlex Deucher 
165297b2e202SAlex Deucher /*
165397b2e202SAlex Deucher  * Testing
165497b2e202SAlex Deucher  */
165597b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
165697b2e202SAlex Deucher void amdgpu_test_ring_sync(struct amdgpu_device *adev,
165797b2e202SAlex Deucher 			   struct amdgpu_ring *cpA,
165897b2e202SAlex Deucher 			   struct amdgpu_ring *cpB);
165997b2e202SAlex Deucher void amdgpu_test_syncing(struct amdgpu_device *adev);
166097b2e202SAlex Deucher 
166197b2e202SAlex Deucher /*
166297b2e202SAlex Deucher  * MMU Notifier
166397b2e202SAlex Deucher  */
166497b2e202SAlex Deucher #if defined(CONFIG_MMU_NOTIFIER)
166597b2e202SAlex Deucher int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
166697b2e202SAlex Deucher void amdgpu_mn_unregister(struct amdgpu_bo *bo);
166797b2e202SAlex Deucher #else
166897b2e202SAlex Deucher static int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
166997b2e202SAlex Deucher {
167097b2e202SAlex Deucher 	return -ENODEV;
167197b2e202SAlex Deucher }
167297b2e202SAlex Deucher static void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
167397b2e202SAlex Deucher #endif
167497b2e202SAlex Deucher 
167597b2e202SAlex Deucher /*
167697b2e202SAlex Deucher  * Debugfs
167797b2e202SAlex Deucher  */
167897b2e202SAlex Deucher struct amdgpu_debugfs {
167997b2e202SAlex Deucher 	struct drm_info_list	*files;
168097b2e202SAlex Deucher 	unsigned		num_files;
168197b2e202SAlex Deucher };
168297b2e202SAlex Deucher 
168397b2e202SAlex Deucher int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
168497b2e202SAlex Deucher 			     struct drm_info_list *files,
168597b2e202SAlex Deucher 			     unsigned nfiles);
168697b2e202SAlex Deucher int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
168797b2e202SAlex Deucher 
168897b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
168997b2e202SAlex Deucher int amdgpu_debugfs_init(struct drm_minor *minor);
169097b2e202SAlex Deucher void amdgpu_debugfs_cleanup(struct drm_minor *minor);
169197b2e202SAlex Deucher #endif
169297b2e202SAlex Deucher 
169397b2e202SAlex Deucher /*
169497b2e202SAlex Deucher  * amdgpu smumgr functions
169597b2e202SAlex Deucher  */
169697b2e202SAlex Deucher struct amdgpu_smumgr_funcs {
169797b2e202SAlex Deucher 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
169897b2e202SAlex Deucher 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
169997b2e202SAlex Deucher 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
170097b2e202SAlex Deucher };
170197b2e202SAlex Deucher 
170297b2e202SAlex Deucher /*
170397b2e202SAlex Deucher  * amdgpu smumgr
170497b2e202SAlex Deucher  */
170597b2e202SAlex Deucher struct amdgpu_smumgr {
170697b2e202SAlex Deucher 	struct amdgpu_bo *toc_buf;
170797b2e202SAlex Deucher 	struct amdgpu_bo *smu_buf;
170897b2e202SAlex Deucher 	/* asic priv smu data */
170997b2e202SAlex Deucher 	void *priv;
171097b2e202SAlex Deucher 	spinlock_t smu_lock;
171197b2e202SAlex Deucher 	/* smumgr functions */
171297b2e202SAlex Deucher 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
171397b2e202SAlex Deucher 	/* ucode loading complete flag */
171497b2e202SAlex Deucher 	uint32_t fw_flags;
171597b2e202SAlex Deucher };
171697b2e202SAlex Deucher 
171797b2e202SAlex Deucher /*
171897b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
171997b2e202SAlex Deucher  */
172097b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
172197b2e202SAlex Deucher 	uint32_t reg_offset;
172297b2e202SAlex Deucher 	bool untouched;
172397b2e202SAlex Deucher 	bool grbm_indexed;
172497b2e202SAlex Deucher };
172597b2e202SAlex Deucher 
172697b2e202SAlex Deucher struct amdgpu_cu_info {
172797b2e202SAlex Deucher 	uint32_t number; /* total active CU number */
172897b2e202SAlex Deucher 	uint32_t ao_cu_mask;
172997b2e202SAlex Deucher 	uint32_t bitmap[4][4];
173097b2e202SAlex Deucher };
173197b2e202SAlex Deucher 
173297b2e202SAlex Deucher 
173397b2e202SAlex Deucher /*
173497b2e202SAlex Deucher  * ASIC specific functions.
173597b2e202SAlex Deucher  */
173697b2e202SAlex Deucher struct amdgpu_asic_funcs {
173797b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
173897b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
173997b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
174097b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
174197b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
174297b2e202SAlex Deucher 	/* wait for mc_idle */
174397b2e202SAlex Deucher 	int (*wait_for_mc_idle)(struct amdgpu_device *adev);
174497b2e202SAlex Deucher 	/* get the reference clock */
174597b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
174697b2e202SAlex Deucher 	/* get the gpu clock counter */
174797b2e202SAlex Deucher 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
174897b2e202SAlex Deucher 	int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
174997b2e202SAlex Deucher 	/* MM block clocks */
175097b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
175197b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
175297b2e202SAlex Deucher };
175397b2e202SAlex Deucher 
175497b2e202SAlex Deucher /*
175597b2e202SAlex Deucher  * IOCTL.
175697b2e202SAlex Deucher  */
175797b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
175897b2e202SAlex Deucher 			    struct drm_file *filp);
175997b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
176097b2e202SAlex Deucher 				struct drm_file *filp);
176197b2e202SAlex Deucher 
176297b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
176397b2e202SAlex Deucher 			  struct drm_file *filp);
176497b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
176597b2e202SAlex Deucher 			struct drm_file *filp);
176697b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
176797b2e202SAlex Deucher 			  struct drm_file *filp);
176897b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
176997b2e202SAlex Deucher 			      struct drm_file *filp);
177097b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
177197b2e202SAlex Deucher 			  struct drm_file *filp);
177297b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
177397b2e202SAlex Deucher 			struct drm_file *filp);
177497b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
177597b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
177697b2e202SAlex Deucher 
177797b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
177897b2e202SAlex Deucher 				struct drm_file *filp);
177997b2e202SAlex Deucher 
178097b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
178197b2e202SAlex Deucher struct amdgpu_vram_scratch {
178297b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
178397b2e202SAlex Deucher 	volatile uint32_t		*ptr;
178497b2e202SAlex Deucher 	u64				gpu_addr;
178597b2e202SAlex Deucher };
178697b2e202SAlex Deucher 
178797b2e202SAlex Deucher /*
178897b2e202SAlex Deucher  * ACPI
178997b2e202SAlex Deucher  */
179097b2e202SAlex Deucher struct amdgpu_atif_notification_cfg {
179197b2e202SAlex Deucher 	bool enabled;
179297b2e202SAlex Deucher 	int command_code;
179397b2e202SAlex Deucher };
179497b2e202SAlex Deucher 
179597b2e202SAlex Deucher struct amdgpu_atif_notifications {
179697b2e202SAlex Deucher 	bool display_switch;
179797b2e202SAlex Deucher 	bool expansion_mode_change;
179897b2e202SAlex Deucher 	bool thermal_state;
179997b2e202SAlex Deucher 	bool forced_power_state;
180097b2e202SAlex Deucher 	bool system_power_state;
180197b2e202SAlex Deucher 	bool display_conf_change;
180297b2e202SAlex Deucher 	bool px_gfx_switch;
180397b2e202SAlex Deucher 	bool brightness_change;
180497b2e202SAlex Deucher 	bool dgpu_display_event;
180597b2e202SAlex Deucher };
180697b2e202SAlex Deucher 
180797b2e202SAlex Deucher struct amdgpu_atif_functions {
180897b2e202SAlex Deucher 	bool system_params;
180997b2e202SAlex Deucher 	bool sbios_requests;
181097b2e202SAlex Deucher 	bool select_active_disp;
181197b2e202SAlex Deucher 	bool lid_state;
181297b2e202SAlex Deucher 	bool get_tv_standard;
181397b2e202SAlex Deucher 	bool set_tv_standard;
181497b2e202SAlex Deucher 	bool get_panel_expansion_mode;
181597b2e202SAlex Deucher 	bool set_panel_expansion_mode;
181697b2e202SAlex Deucher 	bool temperature_change;
181797b2e202SAlex Deucher 	bool graphics_device_types;
181897b2e202SAlex Deucher };
181997b2e202SAlex Deucher 
182097b2e202SAlex Deucher struct amdgpu_atif {
182197b2e202SAlex Deucher 	struct amdgpu_atif_notifications notifications;
182297b2e202SAlex Deucher 	struct amdgpu_atif_functions functions;
182397b2e202SAlex Deucher 	struct amdgpu_atif_notification_cfg notification_cfg;
182497b2e202SAlex Deucher 	struct amdgpu_encoder *encoder_for_bl;
182597b2e202SAlex Deucher };
182697b2e202SAlex Deucher 
182797b2e202SAlex Deucher struct amdgpu_atcs_functions {
182897b2e202SAlex Deucher 	bool get_ext_state;
182997b2e202SAlex Deucher 	bool pcie_perf_req;
183097b2e202SAlex Deucher 	bool pcie_dev_rdy;
183197b2e202SAlex Deucher 	bool pcie_bus_width;
183297b2e202SAlex Deucher };
183397b2e202SAlex Deucher 
183497b2e202SAlex Deucher struct amdgpu_atcs {
183597b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
183697b2e202SAlex Deucher };
183797b2e202SAlex Deucher 
183897b2e202SAlex Deucher int amdgpu_ctx_alloc(struct amdgpu_device *adev,struct amdgpu_fpriv *fpriv,
183997b2e202SAlex Deucher 							uint32_t *id,uint32_t flags);
184097b2e202SAlex Deucher int amdgpu_ctx_free(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv,
184197b2e202SAlex Deucher 						  uint32_t id);
184297b2e202SAlex Deucher 
184397b2e202SAlex Deucher void amdgpu_ctx_fini(struct amdgpu_fpriv *fpriv);
184466b3cf2aSJammy Zhou struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
184566b3cf2aSJammy Zhou int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
184697b2e202SAlex Deucher 
184797b2e202SAlex Deucher extern int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
184897b2e202SAlex Deucher 						 struct drm_file *filp);
184997b2e202SAlex Deucher 
185097b2e202SAlex Deucher /*
185197b2e202SAlex Deucher  * Core structure, functions and helpers.
185297b2e202SAlex Deucher  */
185397b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
185497b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
185597b2e202SAlex Deucher 
185697b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
185797b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
185897b2e202SAlex Deucher 
185997b2e202SAlex Deucher struct amdgpu_device {
186097b2e202SAlex Deucher 	struct device			*dev;
186197b2e202SAlex Deucher 	struct drm_device		*ddev;
186297b2e202SAlex Deucher 	struct pci_dev			*pdev;
186397b2e202SAlex Deucher 	struct rw_semaphore		exclusive_lock;
186497b2e202SAlex Deucher 
186597b2e202SAlex Deucher 	/* ASIC */
186697b2e202SAlex Deucher 	enum amdgpu_asic_type           asic_type;
186797b2e202SAlex Deucher 	uint32_t			family;
186897b2e202SAlex Deucher 	uint32_t			rev_id;
186997b2e202SAlex Deucher 	uint32_t			external_rev_id;
187097b2e202SAlex Deucher 	unsigned long			flags;
187197b2e202SAlex Deucher 	int				usec_timeout;
187297b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
187397b2e202SAlex Deucher 	bool				shutdown;
187497b2e202SAlex Deucher 	bool				suspend;
187597b2e202SAlex Deucher 	bool				need_dma32;
187697b2e202SAlex Deucher 	bool				accel_working;
187797b2e202SAlex Deucher 	bool				needs_reset;
187897b2e202SAlex Deucher 	struct work_struct 		reset_work;
187997b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
188097b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
188197b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
188297b2e202SAlex Deucher 	unsigned 			debugfs_count;
188397b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
188497b2e202SAlex Deucher 	struct dentry			*debugfs_regs;
188597b2e202SAlex Deucher #endif
188697b2e202SAlex Deucher 	struct amdgpu_atif		atif;
188797b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
188897b2e202SAlex Deucher 	struct mutex			srbm_mutex;
188997b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
189097b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
189197b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
189297b2e202SAlex Deucher 	bool				have_disp_power_ref;
189397b2e202SAlex Deucher 
189497b2e202SAlex Deucher 	/* BIOS */
189597b2e202SAlex Deucher 	uint8_t				*bios;
189697b2e202SAlex Deucher 	bool				is_atom_bios;
189797b2e202SAlex Deucher 	uint16_t			bios_header_start;
189897b2e202SAlex Deucher 	struct amdgpu_bo		*stollen_vga_memory;
189997b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
190097b2e202SAlex Deucher 
190197b2e202SAlex Deucher 	/* Register/doorbell mmio */
190297b2e202SAlex Deucher 	resource_size_t			rmmio_base;
190397b2e202SAlex Deucher 	resource_size_t			rmmio_size;
190497b2e202SAlex Deucher 	void __iomem			*rmmio;
190597b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
190697b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
190797b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
190897b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
190997b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
191097b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
191197b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
191297b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
191397b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
191497b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
191597b2e202SAlex Deucher 	/* protects concurrent UVD register access */
191697b2e202SAlex Deucher 	spinlock_t uvd_ctx_idx_lock;
191797b2e202SAlex Deucher 	amdgpu_rreg_t			uvd_ctx_rreg;
191897b2e202SAlex Deucher 	amdgpu_wreg_t			uvd_ctx_wreg;
191997b2e202SAlex Deucher 	/* protects concurrent DIDT register access */
192097b2e202SAlex Deucher 	spinlock_t didt_idx_lock;
192197b2e202SAlex Deucher 	amdgpu_rreg_t			didt_rreg;
192297b2e202SAlex Deucher 	amdgpu_wreg_t			didt_wreg;
192397b2e202SAlex Deucher 	/* protects concurrent ENDPOINT (audio) register access */
192497b2e202SAlex Deucher 	spinlock_t audio_endpt_idx_lock;
192597b2e202SAlex Deucher 	amdgpu_block_rreg_t		audio_endpt_rreg;
192697b2e202SAlex Deucher 	amdgpu_block_wreg_t		audio_endpt_wreg;
192797b2e202SAlex Deucher 	void __iomem                    *rio_mem;
192897b2e202SAlex Deucher 	resource_size_t			rio_mem_size;
192997b2e202SAlex Deucher 	struct amdgpu_doorbell		doorbell;
193097b2e202SAlex Deucher 
193197b2e202SAlex Deucher 	/* clock/pll info */
193297b2e202SAlex Deucher 	struct amdgpu_clock            clock;
193397b2e202SAlex Deucher 
193497b2e202SAlex Deucher 	/* MC */
193597b2e202SAlex Deucher 	struct amdgpu_mc		mc;
193697b2e202SAlex Deucher 	struct amdgpu_gart		gart;
193797b2e202SAlex Deucher 	struct amdgpu_dummy_page	dummy_page;
193897b2e202SAlex Deucher 	struct amdgpu_vm_manager	vm_manager;
193997b2e202SAlex Deucher 
194097b2e202SAlex Deucher 	/* memory management */
194197b2e202SAlex Deucher 	struct amdgpu_mman		mman;
194297b2e202SAlex Deucher 	struct amdgpu_gem		gem;
194397b2e202SAlex Deucher 	struct amdgpu_vram_scratch	vram_scratch;
194497b2e202SAlex Deucher 	struct amdgpu_wb		wb;
194597b2e202SAlex Deucher 	atomic64_t			vram_usage;
194697b2e202SAlex Deucher 	atomic64_t			vram_vis_usage;
194797b2e202SAlex Deucher 	atomic64_t			gtt_usage;
194897b2e202SAlex Deucher 	atomic64_t			num_bytes_moved;
1949d94aed5aSMarek Olšák 	atomic_t			gpu_reset_counter;
195097b2e202SAlex Deucher 
195197b2e202SAlex Deucher 	/* display */
195297b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
195397b2e202SAlex Deucher 	struct work_struct		hotplug_work;
195497b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
195597b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
195697b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
195797b2e202SAlex Deucher 
195897b2e202SAlex Deucher 	/* rings */
195997b2e202SAlex Deucher 	wait_queue_head_t		fence_queue;
196097b2e202SAlex Deucher 	unsigned			fence_context;
196197b2e202SAlex Deucher 	struct mutex			ring_lock;
196297b2e202SAlex Deucher 	unsigned			num_rings;
196397b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
196497b2e202SAlex Deucher 	bool				ib_pool_ready;
196597b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
196697b2e202SAlex Deucher 
196797b2e202SAlex Deucher 	/* interrupts */
196897b2e202SAlex Deucher 	struct amdgpu_irq		irq;
196997b2e202SAlex Deucher 
197097b2e202SAlex Deucher 	/* dpm */
197197b2e202SAlex Deucher 	struct amdgpu_pm		pm;
197297b2e202SAlex Deucher 	u32				cg_flags;
197397b2e202SAlex Deucher 	u32				pg_flags;
197497b2e202SAlex Deucher 
197597b2e202SAlex Deucher 	/* amdgpu smumgr */
197697b2e202SAlex Deucher 	struct amdgpu_smumgr smu;
197797b2e202SAlex Deucher 
197897b2e202SAlex Deucher 	/* gfx */
197997b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
198097b2e202SAlex Deucher 
198197b2e202SAlex Deucher 	/* sdma */
198297b2e202SAlex Deucher 	struct amdgpu_sdma		sdma[2];
198397b2e202SAlex Deucher 	struct amdgpu_irq_src		sdma_trap_irq;
198497b2e202SAlex Deucher 	struct amdgpu_irq_src		sdma_illegal_inst_irq;
198597b2e202SAlex Deucher 
198697b2e202SAlex Deucher 	/* uvd */
198797b2e202SAlex Deucher 	bool				has_uvd;
198897b2e202SAlex Deucher 	struct amdgpu_uvd		uvd;
198997b2e202SAlex Deucher 
199097b2e202SAlex Deucher 	/* vce */
199197b2e202SAlex Deucher 	struct amdgpu_vce		vce;
199297b2e202SAlex Deucher 
199397b2e202SAlex Deucher 	/* firmwares */
199497b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
199597b2e202SAlex Deucher 
199697b2e202SAlex Deucher 	/* GDS */
199797b2e202SAlex Deucher 	struct amdgpu_gds		gds;
199897b2e202SAlex Deucher 
199997b2e202SAlex Deucher 	const struct amdgpu_ip_block_version *ip_blocks;
200097b2e202SAlex Deucher 	int				num_ip_blocks;
200197b2e202SAlex Deucher 	bool				*ip_block_enabled;
200297b2e202SAlex Deucher 	struct mutex	mn_lock;
200397b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
200497b2e202SAlex Deucher 
200597b2e202SAlex Deucher 	/* tracking pinned memory */
200697b2e202SAlex Deucher 	u64 vram_pin_size;
200797b2e202SAlex Deucher 	u64 gart_pin_size;
200897b2e202SAlex Deucher };
200997b2e202SAlex Deucher 
201097b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
201197b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
201297b2e202SAlex Deucher 		       struct drm_device *ddev,
201397b2e202SAlex Deucher 		       struct pci_dev *pdev,
201497b2e202SAlex Deucher 		       uint32_t flags);
201597b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
201697b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
201797b2e202SAlex Deucher 
201897b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
201997b2e202SAlex Deucher 			bool always_indirect);
202097b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
202197b2e202SAlex Deucher 		    bool always_indirect);
202297b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
202397b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
202497b2e202SAlex Deucher 
202597b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
202697b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
202797b2e202SAlex Deucher 
202897b2e202SAlex Deucher /*
202997b2e202SAlex Deucher  * Cast helper
203097b2e202SAlex Deucher  */
203197b2e202SAlex Deucher extern const struct fence_ops amdgpu_fence_ops;
203297b2e202SAlex Deucher static inline struct amdgpu_fence *to_amdgpu_fence(struct fence *f)
203397b2e202SAlex Deucher {
203497b2e202SAlex Deucher 	struct amdgpu_fence *__f = container_of(f, struct amdgpu_fence, base);
203597b2e202SAlex Deucher 
203697b2e202SAlex Deucher 	if (__f->base.ops == &amdgpu_fence_ops)
203797b2e202SAlex Deucher 		return __f;
203897b2e202SAlex Deucher 
203997b2e202SAlex Deucher 	return NULL;
204097b2e202SAlex Deucher }
204197b2e202SAlex Deucher 
204297b2e202SAlex Deucher /*
204397b2e202SAlex Deucher  * Registers read & write functions.
204497b2e202SAlex Deucher  */
204597b2e202SAlex Deucher #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
204697b2e202SAlex Deucher #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
204797b2e202SAlex Deucher #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
204897b2e202SAlex Deucher #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
204997b2e202SAlex Deucher #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
205097b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
205197b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
205297b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
205397b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
205497b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
205597b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
205697b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
205797b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
205897b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
205997b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
206097b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
206197b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
206297b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
206397b2e202SAlex Deucher 	do {							\
206497b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
206597b2e202SAlex Deucher 		tmp_ &= (mask);					\
206697b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
206797b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
206897b2e202SAlex Deucher 	} while (0)
206997b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
207097b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
207197b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
207297b2e202SAlex Deucher 	do {							\
207397b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
207497b2e202SAlex Deucher 		tmp_ &= (mask);					\
207597b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
207697b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
207797b2e202SAlex Deucher 	} while (0)
207897b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
207997b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
208097b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
208197b2e202SAlex Deucher 
208297b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
208397b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
208497b2e202SAlex Deucher 
208597b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
208697b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
208797b2e202SAlex Deucher 
208897b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
208997b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
209097b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
209197b2e202SAlex Deucher 
209297b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
209397b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
209497b2e202SAlex Deucher 
209597b2e202SAlex Deucher /*
209697b2e202SAlex Deucher  * BIOS helpers.
209797b2e202SAlex Deucher  */
209897b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
209997b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
210097b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
210197b2e202SAlex Deucher 
210297b2e202SAlex Deucher /*
210397b2e202SAlex Deucher  * RING helpers.
210497b2e202SAlex Deucher  */
210597b2e202SAlex Deucher static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
210697b2e202SAlex Deucher {
210797b2e202SAlex Deucher 	if (ring->count_dw <= 0)
210886c2b790SJammy Zhou 		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
210997b2e202SAlex Deucher 	ring->ring[ring->wptr++] = v;
211097b2e202SAlex Deucher 	ring->wptr &= ring->ptr_mask;
211197b2e202SAlex Deucher 	ring->count_dw--;
211297b2e202SAlex Deucher 	ring->ring_free_dw--;
211397b2e202SAlex Deucher }
211497b2e202SAlex Deucher 
211597b2e202SAlex Deucher /*
211697b2e202SAlex Deucher  * ASICs macro.
211797b2e202SAlex Deucher  */
211897b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
211997b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
212097b2e202SAlex Deucher #define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
212197b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
212297b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
212397b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
212497b2e202SAlex Deucher #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
212597b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
212697b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
212797b2e202SAlex Deucher #define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
212897b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
212997b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
213097b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
213197b2e202SAlex Deucher #define amdgpu_vm_write_pte(adev, ib, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (addr), (count), (incr), (flags)))
213297b2e202SAlex 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)))
213397b2e202SAlex Deucher #define amdgpu_vm_pad_ib(adev, ib) ((adev)->vm_manager.vm_pte_funcs->pad_ib((ib)))
213497b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
213597b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
213697b2e202SAlex Deucher #define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
213797b2e202SAlex Deucher #define amdgpu_ring_is_lockup(r) (r)->funcs->is_lockup((r))
213897b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
213997b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
214097b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
214197b2e202SAlex Deucher #define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
214297b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
214397b2e202SAlex Deucher #define amdgpu_ring_emit_fence(r, addr, seq, write64bit) (r)->funcs->emit_fence((r), (addr), (seq), (write64bit))
214497b2e202SAlex Deucher #define amdgpu_ring_emit_semaphore(r, semaphore, emit_wait) (r)->funcs->emit_semaphore((r), (semaphore), (emit_wait))
214597b2e202SAlex 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))
2146d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
214797b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
214897b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
214997b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
215097b2e202SAlex Deucher #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
215197b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
215297b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
215397b2e202SAlex Deucher #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
215497b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
215597b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
215697b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
215797b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
215897b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
215997b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
216097b2e202SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
216197b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
216297b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
216397b2e202SAlex 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))
216497b2e202SAlex Deucher #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
216597b2e202SAlex Deucher #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
216697b2e202SAlex Deucher #define amdgpu_emit_copy_buffer(adev, r, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((r), (s), (d), (b))
216797b2e202SAlex Deucher #define amdgpu_emit_fill_buffer(adev, r, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((r), (s), (d), (b))
216897b2e202SAlex Deucher #define amdgpu_dpm_get_temperature(adev) (adev)->pm.funcs->get_temperature((adev))
216997b2e202SAlex Deucher #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
217097b2e202SAlex Deucher #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
217197b2e202SAlex Deucher #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
217297b2e202SAlex Deucher #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
217397b2e202SAlex Deucher #define amdgpu_dpm_get_sclk(adev, l) (adev)->pm.funcs->get_sclk((adev), (l))
217497b2e202SAlex Deucher #define amdgpu_dpm_get_mclk(adev, l) (adev)->pm.funcs->get_mclk((adev), (l))
217597b2e202SAlex Deucher #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
217697b2e202SAlex Deucher #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m))
217797b2e202SAlex Deucher #define amdgpu_dpm_force_performance_level(adev, l) (adev)->pm.funcs->force_performance_level((adev), (l))
217897b2e202SAlex Deucher #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
217997b2e202SAlex Deucher #define amdgpu_dpm_powergate_uvd(adev, g) (adev)->pm.funcs->powergate_uvd((adev), (g))
218097b2e202SAlex Deucher #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
218197b2e202SAlex Deucher #define amdgpu_dpm_set_fan_control_mode(adev, m) (adev)->pm.funcs->set_fan_control_mode((adev), (m))
218297b2e202SAlex Deucher #define amdgpu_dpm_get_fan_control_mode(adev) (adev)->pm.funcs->get_fan_control_mode((adev))
218397b2e202SAlex Deucher #define amdgpu_dpm_set_fan_speed_percent(adev, s) (adev)->pm.funcs->set_fan_speed_percent((adev), (s))
218497b2e202SAlex Deucher #define amdgpu_dpm_get_fan_speed_percent(adev, s) (adev)->pm.funcs->get_fan_speed_percent((adev), (s))
218597b2e202SAlex Deucher 
218697b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
218797b2e202SAlex Deucher 
218897b2e202SAlex Deucher /* Common functions */
218997b2e202SAlex Deucher int amdgpu_gpu_reset(struct amdgpu_device *adev);
219097b2e202SAlex Deucher void amdgpu_pci_config_reset(struct amdgpu_device *adev);
219197b2e202SAlex Deucher bool amdgpu_card_posted(struct amdgpu_device *adev);
219297b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev);
219397b2e202SAlex Deucher bool amdgpu_boot_test_post_card(struct amdgpu_device *adev);
219497b2e202SAlex Deucher int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
219597b2e202SAlex Deucher int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
219697b2e202SAlex Deucher 		       u32 ip_instance, u32 ring,
219797b2e202SAlex Deucher 		       struct amdgpu_ring **out_ring);
219897b2e202SAlex Deucher void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
219997b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
220097b2e202SAlex Deucher int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
220197b2e202SAlex Deucher 				     uint32_t flags);
220297b2e202SAlex Deucher bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
220397b2e202SAlex Deucher bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
220497b2e202SAlex Deucher uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
220597b2e202SAlex Deucher 				 struct ttm_mem_reg *mem);
220697b2e202SAlex Deucher void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
220797b2e202SAlex Deucher void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
220897b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
220997b2e202SAlex Deucher void amdgpu_program_register_sequence(struct amdgpu_device *adev,
221097b2e202SAlex Deucher 					     const u32 *registers,
221197b2e202SAlex Deucher 					     const u32 array_size);
221297b2e202SAlex Deucher 
221397b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
221497b2e202SAlex Deucher /* atpx handler */
221597b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
221697b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
221797b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
221897b2e202SAlex Deucher #else
221997b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
222097b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
222197b2e202SAlex Deucher #endif
222297b2e202SAlex Deucher 
222397b2e202SAlex Deucher /*
222497b2e202SAlex Deucher  * KMS
222597b2e202SAlex Deucher  */
222697b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
222797b2e202SAlex Deucher extern int amdgpu_max_kms_ioctl;
222897b2e202SAlex Deucher 
222997b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
223097b2e202SAlex Deucher int amdgpu_driver_unload_kms(struct drm_device *dev);
223197b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
223297b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
223397b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
223497b2e202SAlex Deucher 				 struct drm_file *file_priv);
223597b2e202SAlex Deucher void amdgpu_driver_preclose_kms(struct drm_device *dev,
223697b2e202SAlex Deucher 				struct drm_file *file_priv);
223797b2e202SAlex Deucher int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
223897b2e202SAlex Deucher int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
223997b2e202SAlex Deucher u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, int crtc);
224097b2e202SAlex Deucher int amdgpu_enable_vblank_kms(struct drm_device *dev, int crtc);
224197b2e202SAlex Deucher void amdgpu_disable_vblank_kms(struct drm_device *dev, int crtc);
224297b2e202SAlex Deucher int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
224397b2e202SAlex Deucher 				    int *max_error,
224497b2e202SAlex Deucher 				    struct timeval *vblank_time,
224597b2e202SAlex Deucher 				    unsigned flags);
224697b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
224797b2e202SAlex Deucher 			     unsigned long arg);
224897b2e202SAlex Deucher 
224997b2e202SAlex Deucher /*
225097b2e202SAlex Deucher  * vm
225197b2e202SAlex Deucher  */
225297b2e202SAlex Deucher int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
225397b2e202SAlex Deucher void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
225497b2e202SAlex Deucher struct amdgpu_bo_list_entry *amdgpu_vm_get_bos(struct amdgpu_device *adev,
225597b2e202SAlex Deucher 					  struct amdgpu_vm *vm,
225697b2e202SAlex Deucher 					  struct list_head *head);
225797b2e202SAlex Deucher struct amdgpu_fence *amdgpu_vm_grab_id(struct amdgpu_ring *ring,
225897b2e202SAlex Deucher 				       struct amdgpu_vm *vm);
225997b2e202SAlex Deucher void amdgpu_vm_flush(struct amdgpu_ring *ring,
226097b2e202SAlex Deucher 		     struct amdgpu_vm *vm,
226197b2e202SAlex Deucher 		     struct amdgpu_fence *updates);
226297b2e202SAlex Deucher void amdgpu_vm_fence(struct amdgpu_device *adev,
226397b2e202SAlex Deucher 		     struct amdgpu_vm *vm,
226497b2e202SAlex Deucher 		     struct amdgpu_fence *fence);
226597b2e202SAlex Deucher uint64_t amdgpu_vm_map_gart(struct amdgpu_device *adev, uint64_t addr);
226697b2e202SAlex Deucher int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
226797b2e202SAlex Deucher 				    struct amdgpu_vm *vm);
226897b2e202SAlex Deucher int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
226997b2e202SAlex Deucher 				struct amdgpu_vm *vm);
227097b2e202SAlex Deucher int amdgpu_vm_clear_invalids(struct amdgpu_device *adev,
2271cfe2c978Smonk.liu 				struct amdgpu_vm *vm, struct amdgpu_sync *sync);
227297b2e202SAlex Deucher int amdgpu_vm_bo_update(struct amdgpu_device *adev,
227397b2e202SAlex Deucher 			struct amdgpu_bo_va *bo_va,
227497b2e202SAlex Deucher 			struct ttm_mem_reg *mem);
227597b2e202SAlex Deucher void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
227697b2e202SAlex Deucher 			     struct amdgpu_bo *bo);
227797b2e202SAlex Deucher struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
227897b2e202SAlex Deucher 				       struct amdgpu_bo *bo);
227997b2e202SAlex Deucher struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
228097b2e202SAlex Deucher 				      struct amdgpu_vm *vm,
228197b2e202SAlex Deucher 				      struct amdgpu_bo *bo);
228297b2e202SAlex Deucher int amdgpu_vm_bo_map(struct amdgpu_device *adev,
228397b2e202SAlex Deucher 		     struct amdgpu_bo_va *bo_va,
228497b2e202SAlex Deucher 		     uint64_t addr, uint64_t offset,
228597b2e202SAlex Deucher 		     uint64_t size, uint32_t flags);
228697b2e202SAlex Deucher int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
228797b2e202SAlex Deucher 		       struct amdgpu_bo_va *bo_va,
228897b2e202SAlex Deucher 		       uint64_t addr);
228997b2e202SAlex Deucher void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
229097b2e202SAlex Deucher 		      struct amdgpu_bo_va *bo_va);
229197b2e202SAlex Deucher 
229297b2e202SAlex Deucher /*
229397b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
229497b2e202SAlex Deucher  */
229597b2e202SAlex Deucher struct amdgpu_afmt_acr {
229697b2e202SAlex Deucher 	u32 clock;
229797b2e202SAlex Deucher 
229897b2e202SAlex Deucher 	int n_32khz;
229997b2e202SAlex Deucher 	int cts_32khz;
230097b2e202SAlex Deucher 
230197b2e202SAlex Deucher 	int n_44_1khz;
230297b2e202SAlex Deucher 	int cts_44_1khz;
230397b2e202SAlex Deucher 
230497b2e202SAlex Deucher 	int n_48khz;
230597b2e202SAlex Deucher 	int cts_48khz;
230697b2e202SAlex Deucher 
230797b2e202SAlex Deucher };
230897b2e202SAlex Deucher 
230997b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
231097b2e202SAlex Deucher 
231197b2e202SAlex Deucher /* amdgpu_acpi.c */
231297b2e202SAlex Deucher #if defined(CONFIG_ACPI)
231397b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
231497b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
231597b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
231697b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
231797b2e202SAlex Deucher 						u8 perf_req, bool advertise);
231897b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
231997b2e202SAlex Deucher #else
232097b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
232197b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
232297b2e202SAlex Deucher #endif
232397b2e202SAlex Deucher 
232497b2e202SAlex Deucher struct amdgpu_bo_va_mapping *
232597b2e202SAlex Deucher amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
232697b2e202SAlex Deucher 		       uint64_t addr, struct amdgpu_bo **bo);
232797b2e202SAlex Deucher 
232897b2e202SAlex Deucher #include "amdgpu_object.h"
232997b2e202SAlex Deucher 
233097b2e202SAlex Deucher #endif
2331