xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision 63fbf42f)
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 
45d03846afSChunming Zhou #include <drm/drmP.h>
4697b2e202SAlex Deucher #include <drm/drm_gem.h>
477e5a547fSChunming Zhou #include <drm/amdgpu_drm.h>
4897b2e202SAlex Deucher 
495fc3aeebSyanyang1 #include "amd_shared.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"
551f7371b2SAlex Deucher #include "amd_powerplay.h"
56a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h"
5797b2e202SAlex Deucher 
58b80d8475SAlex Deucher #include "gpu_scheduler.h"
59b80d8475SAlex Deucher 
6097b2e202SAlex Deucher /*
6197b2e202SAlex Deucher  * Modules parameters.
6297b2e202SAlex Deucher  */
6397b2e202SAlex Deucher extern int amdgpu_modeset;
6497b2e202SAlex Deucher extern int amdgpu_vram_limit;
6597b2e202SAlex Deucher extern int amdgpu_gart_size;
6697b2e202SAlex Deucher extern int amdgpu_benchmarking;
6797b2e202SAlex Deucher extern int amdgpu_testing;
6897b2e202SAlex Deucher extern int amdgpu_audio;
6997b2e202SAlex Deucher extern int amdgpu_disp_priority;
7097b2e202SAlex Deucher extern int amdgpu_hw_i2c;
7197b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
7297b2e202SAlex Deucher extern int amdgpu_msi;
7397b2e202SAlex Deucher extern int amdgpu_lockup_timeout;
7497b2e202SAlex Deucher extern int amdgpu_dpm;
7597b2e202SAlex Deucher extern int amdgpu_smc_load_fw;
7697b2e202SAlex Deucher extern int amdgpu_aspm;
7797b2e202SAlex Deucher extern int amdgpu_runtime_pm;
7897b2e202SAlex Deucher extern unsigned amdgpu_ip_block_mask;
7997b2e202SAlex Deucher extern int amdgpu_bapm;
8097b2e202SAlex Deucher extern int amdgpu_deep_color;
8197b2e202SAlex Deucher extern int amdgpu_vm_size;
8297b2e202SAlex Deucher extern int amdgpu_vm_block_size;
83d9c13156SChristian König extern int amdgpu_vm_fault_stop;
84b495bd3aSChristian König extern int amdgpu_vm_debug;
851333f723SJammy Zhou extern int amdgpu_sched_jobs;
864afcb303SJammy Zhou extern int amdgpu_sched_hw_submission;
871f7371b2SAlex Deucher extern int amdgpu_powerplay;
886bb6b297SHuang Rui extern int amdgpu_powercontainment;
89cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_gen_cap;
90cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_lane_cap;
91395d1fb9SNicolai Hähnle extern unsigned amdgpu_cg_mask;
92395d1fb9SNicolai Hähnle extern unsigned amdgpu_pg_mask;
936f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu;
9497b2e202SAlex Deucher 
954b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
9697b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
9797b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
9897b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
9997b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
10097b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
10197b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
10297b2e202SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			8
10397b2e202SAlex Deucher 
10497b2e202SAlex Deucher /* max number of rings */
10597b2e202SAlex Deucher #define AMDGPU_MAX_RINGS			16
10697b2e202SAlex Deucher #define AMDGPU_MAX_GFX_RINGS			1
10797b2e202SAlex Deucher #define AMDGPU_MAX_COMPUTE_RINGS		8
10897b2e202SAlex Deucher #define AMDGPU_MAX_VCE_RINGS			2
10997b2e202SAlex Deucher 
11036f523a7SJammy Zhou /* max number of IP instances */
11136f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES		2
11236f523a7SJammy Zhou 
11397b2e202SAlex Deucher /* hardcode that limit for now */
11497b2e202SAlex Deucher #define AMDGPU_VA_RESERVED_SIZE			(8 << 20)
11597b2e202SAlex Deucher 
11697b2e202SAlex Deucher /* hard reset data */
11797b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
11897b2e202SAlex Deucher 
11997b2e202SAlex Deucher /* reset flags */
12097b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
12197b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
12297b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
12397b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
12497b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
12597b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
12697b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
12797b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
12897b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
12997b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
13097b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
13197b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
13297b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
13397b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
13497b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
13597b2e202SAlex Deucher 
13697b2e202SAlex Deucher /* GFX current status */
13797b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
13897b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE			0x00000001L
13997b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
14097b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
14197b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
14297b2e202SAlex Deucher 
14397b2e202SAlex Deucher /* max cursor sizes (in pixels) */
14497b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
14597b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
14697b2e202SAlex Deucher 
14797b2e202SAlex Deucher struct amdgpu_device;
14897b2e202SAlex Deucher struct amdgpu_ib;
14997b2e202SAlex Deucher struct amdgpu_vm;
15097b2e202SAlex Deucher struct amdgpu_ring;
15197b2e202SAlex Deucher struct amdgpu_cs_parser;
152bb977d37SChunming Zhou struct amdgpu_job;
15397b2e202SAlex Deucher struct amdgpu_irq_src;
1540b492a4cSAlex Deucher struct amdgpu_fpriv;
15597b2e202SAlex Deucher 
15697b2e202SAlex Deucher enum amdgpu_cp_irq {
15797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_GFX_EOP = 0,
15897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
15997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
16097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
16197b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
16297b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
16397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
16497b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
16597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
16697b2e202SAlex Deucher 
16797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
16897b2e202SAlex Deucher };
16997b2e202SAlex Deucher 
17097b2e202SAlex Deucher enum amdgpu_sdma_irq {
17197b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
17297b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP1,
17397b2e202SAlex Deucher 
17497b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_LAST
17597b2e202SAlex Deucher };
17697b2e202SAlex Deucher 
17797b2e202SAlex Deucher enum amdgpu_thermal_irq {
17897b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
17997b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
18097b2e202SAlex Deucher 
18197b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
18297b2e202SAlex Deucher };
18397b2e202SAlex Deucher 
18497b2e202SAlex Deucher int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
1855fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
1865fc3aeebSyanyang1 				  enum amd_clockgating_state state);
18797b2e202SAlex Deucher int amdgpu_set_powergating_state(struct amdgpu_device *adev,
1885fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
1895fc3aeebSyanyang1 				  enum amd_powergating_state state);
1905dbbb60bSAlex Deucher int amdgpu_wait_for_idle(struct amdgpu_device *adev,
1915dbbb60bSAlex Deucher 			 enum amd_ip_block_type block_type);
1925dbbb60bSAlex Deucher bool amdgpu_is_idle(struct amdgpu_device *adev,
1935dbbb60bSAlex Deucher 		    enum amd_ip_block_type block_type);
19497b2e202SAlex Deucher 
19597b2e202SAlex Deucher struct amdgpu_ip_block_version {
1965fc3aeebSyanyang1 	enum amd_ip_block_type type;
19797b2e202SAlex Deucher 	u32 major;
19897b2e202SAlex Deucher 	u32 minor;
19997b2e202SAlex Deucher 	u32 rev;
2005fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
20197b2e202SAlex Deucher };
20297b2e202SAlex Deucher 
20397b2e202SAlex Deucher int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
2045fc3aeebSyanyang1 				enum amd_ip_block_type type,
20597b2e202SAlex Deucher 				u32 major, u32 minor);
20697b2e202SAlex Deucher 
20797b2e202SAlex Deucher const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
20897b2e202SAlex Deucher 					struct amdgpu_device *adev,
2095fc3aeebSyanyang1 					enum amd_ip_block_type type);
21097b2e202SAlex Deucher 
21197b2e202SAlex Deucher /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
21297b2e202SAlex Deucher struct amdgpu_buffer_funcs {
21397b2e202SAlex Deucher 	/* maximum bytes in a single operation */
21497b2e202SAlex Deucher 	uint32_t	copy_max_bytes;
21597b2e202SAlex Deucher 
21697b2e202SAlex Deucher 	/* number of dw to reserve per operation */
21797b2e202SAlex Deucher 	unsigned	copy_num_dw;
21897b2e202SAlex Deucher 
21997b2e202SAlex Deucher 	/* used for buffer migration */
220c7ae72c0SChunming Zhou 	void (*emit_copy_buffer)(struct amdgpu_ib *ib,
22197b2e202SAlex Deucher 				 /* src addr in bytes */
22297b2e202SAlex Deucher 				 uint64_t src_offset,
22397b2e202SAlex Deucher 				 /* dst addr in bytes */
22497b2e202SAlex Deucher 				 uint64_t dst_offset,
22597b2e202SAlex Deucher 				 /* number of byte to transfer */
22697b2e202SAlex Deucher 				 uint32_t byte_count);
22797b2e202SAlex Deucher 
22897b2e202SAlex Deucher 	/* maximum bytes in a single operation */
22997b2e202SAlex Deucher 	uint32_t	fill_max_bytes;
23097b2e202SAlex Deucher 
23197b2e202SAlex Deucher 	/* number of dw to reserve per operation */
23297b2e202SAlex Deucher 	unsigned	fill_num_dw;
23397b2e202SAlex Deucher 
23497b2e202SAlex Deucher 	/* used for buffer clearing */
2356e7a3840SChunming Zhou 	void (*emit_fill_buffer)(struct amdgpu_ib *ib,
23697b2e202SAlex Deucher 				 /* value to write to memory */
23797b2e202SAlex Deucher 				 uint32_t src_data,
23897b2e202SAlex Deucher 				 /* dst addr in bytes */
23997b2e202SAlex Deucher 				 uint64_t dst_offset,
24097b2e202SAlex Deucher 				 /* number of byte to fill */
24197b2e202SAlex Deucher 				 uint32_t byte_count);
24297b2e202SAlex Deucher };
24397b2e202SAlex Deucher 
24497b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */
24597b2e202SAlex Deucher struct amdgpu_vm_pte_funcs {
24697b2e202SAlex Deucher 	/* copy pte entries from GART */
24797b2e202SAlex Deucher 	void (*copy_pte)(struct amdgpu_ib *ib,
24897b2e202SAlex Deucher 			 uint64_t pe, uint64_t src,
24997b2e202SAlex Deucher 			 unsigned count);
25097b2e202SAlex Deucher 	/* write pte one entry at a time with addr mapping */
25197b2e202SAlex Deucher 	void (*write_pte)(struct amdgpu_ib *ib,
252b07c9d2aSChristian König 			  const dma_addr_t *pages_addr, uint64_t pe,
25397b2e202SAlex Deucher 			  uint64_t addr, unsigned count,
25497b2e202SAlex Deucher 			  uint32_t incr, uint32_t flags);
25597b2e202SAlex Deucher 	/* for linear pte/pde updates without addr mapping */
25697b2e202SAlex Deucher 	void (*set_pte_pde)(struct amdgpu_ib *ib,
25797b2e202SAlex Deucher 			    uint64_t pe,
25897b2e202SAlex Deucher 			    uint64_t addr, unsigned count,
25997b2e202SAlex Deucher 			    uint32_t incr, uint32_t flags);
26097b2e202SAlex Deucher };
26197b2e202SAlex Deucher 
26297b2e202SAlex Deucher /* provided by the gmc block */
26397b2e202SAlex Deucher struct amdgpu_gart_funcs {
26497b2e202SAlex Deucher 	/* flush the vm tlb via mmio */
26597b2e202SAlex Deucher 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
26697b2e202SAlex Deucher 			      uint32_t vmid);
26797b2e202SAlex Deucher 	/* write pte/pde updates using the cpu */
26897b2e202SAlex Deucher 	int (*set_pte_pde)(struct amdgpu_device *adev,
26997b2e202SAlex Deucher 			   void *cpu_pt_addr, /* cpu addr of page table */
27097b2e202SAlex Deucher 			   uint32_t gpu_page_idx, /* pte/pde to update */
27197b2e202SAlex Deucher 			   uint64_t addr, /* addr to write into pte/pde */
27297b2e202SAlex Deucher 			   uint32_t flags); /* access flags */
27397b2e202SAlex Deucher };
27497b2e202SAlex Deucher 
27597b2e202SAlex Deucher /* provided by the ih block */
27697b2e202SAlex Deucher struct amdgpu_ih_funcs {
27797b2e202SAlex Deucher 	/* ring read/write ptr handling, called from interrupt context */
27897b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_device *adev);
27997b2e202SAlex Deucher 	void (*decode_iv)(struct amdgpu_device *adev,
28097b2e202SAlex Deucher 			  struct amdgpu_iv_entry *entry);
28197b2e202SAlex Deucher 	void (*set_rptr)(struct amdgpu_device *adev);
28297b2e202SAlex Deucher };
28397b2e202SAlex Deucher 
28497b2e202SAlex Deucher /* provided by hw blocks that expose a ring buffer for commands */
28597b2e202SAlex Deucher struct amdgpu_ring_funcs {
28697b2e202SAlex Deucher 	/* ring read/write ptr handling */
28797b2e202SAlex Deucher 	u32 (*get_rptr)(struct amdgpu_ring *ring);
28897b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_ring *ring);
28997b2e202SAlex Deucher 	void (*set_wptr)(struct amdgpu_ring *ring);
29097b2e202SAlex Deucher 	/* validating and patching of IBs */
29197b2e202SAlex Deucher 	int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
29297b2e202SAlex Deucher 	/* command emit functions */
29397b2e202SAlex Deucher 	void (*emit_ib)(struct amdgpu_ring *ring,
294d88bf583SChristian König 			struct amdgpu_ib *ib,
295d88bf583SChristian König 			unsigned vm_id, bool ctx_switch);
29697b2e202SAlex Deucher 	void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
297890ee23fSChunming Zhou 			   uint64_t seq, unsigned flags);
298b8c7b39eSChristian König 	void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
29997b2e202SAlex Deucher 	void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
30097b2e202SAlex Deucher 			      uint64_t pd_addr);
301d2edb07bSChristian König 	void (*emit_hdp_flush)(struct amdgpu_ring *ring);
30211afbde8SChunming Zhou 	void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
30397b2e202SAlex Deucher 	void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
30497b2e202SAlex Deucher 				uint32_t gds_base, uint32_t gds_size,
30597b2e202SAlex Deucher 				uint32_t gws_base, uint32_t gws_size,
30697b2e202SAlex Deucher 				uint32_t oa_base, uint32_t oa_size);
30797b2e202SAlex Deucher 	/* testing functions */
30897b2e202SAlex Deucher 	int (*test_ring)(struct amdgpu_ring *ring);
309bbec97aaSChristian König 	int (*test_ib)(struct amdgpu_ring *ring, long timeout);
310edff0e28SJammy Zhou 	/* insert NOP packets */
311edff0e28SJammy Zhou 	void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
3129e5d5309SChristian König 	/* pad the indirect buffer to the necessary number of dw */
3139e5d5309SChristian König 	void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
31403ccf481SMonk Liu 	unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
31503ccf481SMonk Liu 	void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
316f06505b8SChristian König 	/* note usage for clock and power gating */
317f06505b8SChristian König 	void (*begin_use)(struct amdgpu_ring *ring);
318f06505b8SChristian König 	void (*end_use)(struct amdgpu_ring *ring);
31997b2e202SAlex Deucher };
32097b2e202SAlex Deucher 
32197b2e202SAlex Deucher /*
32297b2e202SAlex Deucher  * BIOS.
32397b2e202SAlex Deucher  */
32497b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
32597b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
32697b2e202SAlex Deucher 
32797b2e202SAlex Deucher /*
32897b2e202SAlex Deucher  * Dummy page
32997b2e202SAlex Deucher  */
33097b2e202SAlex Deucher struct amdgpu_dummy_page {
33197b2e202SAlex Deucher 	struct page	*page;
33297b2e202SAlex Deucher 	dma_addr_t	addr;
33397b2e202SAlex Deucher };
33497b2e202SAlex Deucher int amdgpu_dummy_page_init(struct amdgpu_device *adev);
33597b2e202SAlex Deucher void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
33697b2e202SAlex Deucher 
33797b2e202SAlex Deucher 
33897b2e202SAlex Deucher /*
33997b2e202SAlex Deucher  * Clocks
34097b2e202SAlex Deucher  */
34197b2e202SAlex Deucher 
34297b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
34397b2e202SAlex Deucher 
34497b2e202SAlex Deucher struct amdgpu_clock {
34597b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
34697b2e202SAlex Deucher 	struct amdgpu_pll spll;
34797b2e202SAlex Deucher 	struct amdgpu_pll mpll;
34897b2e202SAlex Deucher 	/* 10 Khz units */
34997b2e202SAlex Deucher 	uint32_t default_mclk;
35097b2e202SAlex Deucher 	uint32_t default_sclk;
35197b2e202SAlex Deucher 	uint32_t default_dispclk;
35297b2e202SAlex Deucher 	uint32_t current_dispclk;
35397b2e202SAlex Deucher 	uint32_t dp_extclk;
35497b2e202SAlex Deucher 	uint32_t max_pixel_clock;
35597b2e202SAlex Deucher };
35697b2e202SAlex Deucher 
35797b2e202SAlex Deucher /*
35897b2e202SAlex Deucher  * Fences.
35997b2e202SAlex Deucher  */
36097b2e202SAlex Deucher struct amdgpu_fence_driver {
36197b2e202SAlex Deucher 	uint64_t			gpu_addr;
36297b2e202SAlex Deucher 	volatile uint32_t		*cpu_addr;
36397b2e202SAlex Deucher 	/* sync_seq is protected by ring emission lock */
364742c085fSChristian König 	uint32_t			sync_seq;
365742c085fSChristian König 	atomic_t			last_seq;
36697b2e202SAlex Deucher 	bool				initialized;
36797b2e202SAlex Deucher 	struct amdgpu_irq_src		*irq_src;
36897b2e202SAlex Deucher 	unsigned			irq_type;
369c2776afeSChristian König 	struct timer_list		fallback_timer;
370c89377d1SChristian König 	unsigned			num_fences_mask;
3714a7d74f1SChristian König 	spinlock_t			lock;
372c89377d1SChristian König 	struct fence			**fences;
37397b2e202SAlex Deucher };
37497b2e202SAlex Deucher 
37597b2e202SAlex Deucher /* some special values for the owner field */
37697b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_UNDEFINED	((void*)0ul)
37797b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_VM		((void*)1ul)
37897b2e202SAlex Deucher 
379890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_64BIT         (1 << 0)
380890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_INT           (1 << 1)
381890ee23fSChunming Zhou 
38297b2e202SAlex Deucher int amdgpu_fence_driver_init(struct amdgpu_device *adev);
38397b2e202SAlex Deucher void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
38497b2e202SAlex Deucher void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
38597b2e202SAlex Deucher 
386e6151a08SChristian König int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
387e6151a08SChristian König 				  unsigned num_hw_submission);
38897b2e202SAlex Deucher int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
38997b2e202SAlex Deucher 				   struct amdgpu_irq_src *irq_src,
39097b2e202SAlex Deucher 				   unsigned irq_type);
3915ceb54c6SAlex Deucher void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
3925ceb54c6SAlex Deucher void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
393364beb2cSChristian König int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
39497b2e202SAlex Deucher void amdgpu_fence_process(struct amdgpu_ring *ring);
39597b2e202SAlex Deucher int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
39697b2e202SAlex Deucher unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
39797b2e202SAlex Deucher 
39897b2e202SAlex Deucher /*
39997b2e202SAlex Deucher  * TTM.
40097b2e202SAlex Deucher  */
40129b3259aSChristian König 
40229b3259aSChristian König #define AMDGPU_TTM_LRU_SIZE	20
40329b3259aSChristian König 
40429b3259aSChristian König struct amdgpu_mman_lru {
40529b3259aSChristian König 	struct list_head		*lru[TTM_NUM_MEM_TYPES];
40629b3259aSChristian König 	struct list_head		*swap_lru;
40729b3259aSChristian König };
40829b3259aSChristian König 
40997b2e202SAlex Deucher struct amdgpu_mman {
41097b2e202SAlex Deucher 	struct ttm_bo_global_ref        bo_global_ref;
41197b2e202SAlex Deucher 	struct drm_global_reference	mem_global_ref;
41297b2e202SAlex Deucher 	struct ttm_bo_device		bdev;
41397b2e202SAlex Deucher 	bool				mem_global_referenced;
41497b2e202SAlex Deucher 	bool				initialized;
41597b2e202SAlex Deucher 
41697b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
41797b2e202SAlex Deucher 	struct dentry			*vram;
41897b2e202SAlex Deucher 	struct dentry			*gtt;
41997b2e202SAlex Deucher #endif
42097b2e202SAlex Deucher 
42197b2e202SAlex Deucher 	/* buffer handling */
42297b2e202SAlex Deucher 	const struct amdgpu_buffer_funcs	*buffer_funcs;
42397b2e202SAlex Deucher 	struct amdgpu_ring			*buffer_funcs_ring;
424703297c1SChristian König 	/* Scheduler entity for buffer moves */
425703297c1SChristian König 	struct amd_sched_entity			entity;
42629b3259aSChristian König 
42729b3259aSChristian König 	/* custom LRU management */
42829b3259aSChristian König 	struct amdgpu_mman_lru			log2_size[AMDGPU_TTM_LRU_SIZE];
42997b2e202SAlex Deucher };
43097b2e202SAlex Deucher 
43197b2e202SAlex Deucher int amdgpu_copy_buffer(struct amdgpu_ring *ring,
43297b2e202SAlex Deucher 		       uint64_t src_offset,
43397b2e202SAlex Deucher 		       uint64_t dst_offset,
43497b2e202SAlex Deucher 		       uint32_t byte_count,
43597b2e202SAlex Deucher 		       struct reservation_object *resv,
436c7ae72c0SChunming Zhou 		       struct fence **fence);
43797b2e202SAlex Deucher int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
43897b2e202SAlex Deucher 
43997b2e202SAlex Deucher struct amdgpu_bo_list_entry {
44097b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
44197b2e202SAlex Deucher 	struct ttm_validate_buffer	tv;
44297b2e202SAlex Deucher 	struct amdgpu_bo_va		*bo_va;
44397b2e202SAlex Deucher 	uint32_t			priority;
4442f568dbdSChristian König 	struct page			**user_pages;
4452f568dbdSChristian König 	int				user_invalidated;
44697b2e202SAlex Deucher };
44797b2e202SAlex Deucher 
44897b2e202SAlex Deucher struct amdgpu_bo_va_mapping {
44997b2e202SAlex Deucher 	struct list_head		list;
45097b2e202SAlex Deucher 	struct interval_tree_node	it;
45197b2e202SAlex Deucher 	uint64_t			offset;
45297b2e202SAlex Deucher 	uint32_t			flags;
45397b2e202SAlex Deucher };
45497b2e202SAlex Deucher 
45597b2e202SAlex Deucher /* bo virtual addresses in a specific vm */
45697b2e202SAlex Deucher struct amdgpu_bo_va {
45797b2e202SAlex Deucher 	/* protected by bo being reserved */
45897b2e202SAlex Deucher 	struct list_head		bo_list;
459bb1e38a4SChunming Zhou 	struct fence		        *last_pt_update;
46097b2e202SAlex Deucher 	unsigned			ref_count;
46197b2e202SAlex Deucher 
4627fc11959SChristian König 	/* protected by vm mutex and spinlock */
46397b2e202SAlex Deucher 	struct list_head		vm_status;
46497b2e202SAlex Deucher 
4657fc11959SChristian König 	/* mappings for this bo_va */
4667fc11959SChristian König 	struct list_head		invalids;
4677fc11959SChristian König 	struct list_head		valids;
4687fc11959SChristian König 
46997b2e202SAlex Deucher 	/* constant after initialization */
47097b2e202SAlex Deucher 	struct amdgpu_vm		*vm;
47197b2e202SAlex Deucher 	struct amdgpu_bo		*bo;
47297b2e202SAlex Deucher };
47397b2e202SAlex Deucher 
4747e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX		0x3
4757e5a547fSChunming Zhou 
47697b2e202SAlex Deucher struct amdgpu_bo {
47797b2e202SAlex Deucher 	/* Protected by gem.mutex */
47897b2e202SAlex Deucher 	struct list_head		list;
47997b2e202SAlex Deucher 	/* Protected by tbo.reserved */
4801ea863fdSChristian König 	u32				prefered_domains;
4811ea863fdSChristian König 	u32				allowed_domains;
4827e5a547fSChunming Zhou 	struct ttm_place		placements[AMDGPU_GEM_DOMAIN_MAX + 1];
48397b2e202SAlex Deucher 	struct ttm_placement		placement;
48497b2e202SAlex Deucher 	struct ttm_buffer_object	tbo;
48597b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		kmap;
48697b2e202SAlex Deucher 	u64				flags;
48797b2e202SAlex Deucher 	unsigned			pin_count;
48897b2e202SAlex Deucher 	void				*kptr;
48997b2e202SAlex Deucher 	u64				tiling_flags;
49097b2e202SAlex Deucher 	u64				metadata_flags;
49197b2e202SAlex Deucher 	void				*metadata;
49297b2e202SAlex Deucher 	u32				metadata_size;
49397b2e202SAlex Deucher 	/* list of all virtual address to which this bo
49497b2e202SAlex Deucher 	 * is associated to
49597b2e202SAlex Deucher 	 */
49697b2e202SAlex Deucher 	struct list_head		va;
49797b2e202SAlex Deucher 	/* Constant after initialization */
49897b2e202SAlex Deucher 	struct amdgpu_device		*adev;
49997b2e202SAlex Deucher 	struct drm_gem_object		gem_base;
50082b9c55bSChristian König 	struct amdgpu_bo		*parent;
50197b2e202SAlex Deucher 
50297b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		dma_buf_vmap;
50397b2e202SAlex Deucher 	struct amdgpu_mn		*mn;
50497b2e202SAlex Deucher 	struct list_head		mn_list;
50597b2e202SAlex Deucher };
50697b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
50797b2e202SAlex Deucher 
50897b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj);
50997b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj,
51097b2e202SAlex Deucher 				struct drm_file *file_priv);
51197b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj,
51297b2e202SAlex Deucher 				struct drm_file *file_priv);
51397b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
51497b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
5154d9c514dSChristian König struct drm_gem_object *
5164d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
51797b2e202SAlex Deucher 				 struct dma_buf_attachment *attach,
51897b2e202SAlex Deucher 				 struct sg_table *sg);
51997b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
52097b2e202SAlex Deucher 					struct drm_gem_object *gobj,
52197b2e202SAlex Deucher 					int flags);
52297b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
52397b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
52497b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
52597b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
52697b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
52797b2e202SAlex Deucher int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
52897b2e202SAlex Deucher 
52997b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
53097b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
53197b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
53297b2e202SAlex Deucher  * locking.
53397b2e202SAlex Deucher  *
53497b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
53597b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
53697b2e202SAlex Deucher  * offset).
53797b2e202SAlex Deucher  *
53897b2e202SAlex Deucher  * When allocating new object we first check if there is room at
53997b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
54097b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
54197b2e202SAlex Deucher  *
54297b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
54397b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
54497b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
54597b2e202SAlex Deucher  *
54697b2e202SAlex Deucher  * Alignment can't be bigger than page size.
54797b2e202SAlex Deucher  *
54897b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
54997b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
55097b2e202SAlex Deucher  * alignment).
55197b2e202SAlex Deucher  */
5526ba60b89SChristian König 
5536ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS	32
5546ba60b89SChristian König 
55597b2e202SAlex Deucher struct amdgpu_sa_manager {
55697b2e202SAlex Deucher 	wait_queue_head_t	wq;
55797b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
55897b2e202SAlex Deucher 	struct list_head	*hole;
5596ba60b89SChristian König 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
56097b2e202SAlex Deucher 	struct list_head	olist;
56197b2e202SAlex Deucher 	unsigned		size;
56297b2e202SAlex Deucher 	uint64_t		gpu_addr;
56397b2e202SAlex Deucher 	void			*cpu_ptr;
56497b2e202SAlex Deucher 	uint32_t		domain;
56597b2e202SAlex Deucher 	uint32_t		align;
56697b2e202SAlex Deucher };
56797b2e202SAlex Deucher 
56897b2e202SAlex Deucher /* sub-allocation buffer */
56997b2e202SAlex Deucher struct amdgpu_sa_bo {
57097b2e202SAlex Deucher 	struct list_head		olist;
57197b2e202SAlex Deucher 	struct list_head		flist;
57297b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
57397b2e202SAlex Deucher 	unsigned			soffset;
57497b2e202SAlex Deucher 	unsigned			eoffset;
5754ce9891eSChunming Zhou 	struct fence		        *fence;
57697b2e202SAlex Deucher };
57797b2e202SAlex Deucher 
57897b2e202SAlex Deucher /*
57997b2e202SAlex Deucher  * GEM objects.
58097b2e202SAlex Deucher  */
581418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev);
58297b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
58397b2e202SAlex Deucher 				int alignment, u32 initial_domain,
58497b2e202SAlex Deucher 				u64 flags, bool kernel,
58597b2e202SAlex Deucher 				struct drm_gem_object **obj);
58697b2e202SAlex Deucher 
58797b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv,
58897b2e202SAlex Deucher 			    struct drm_device *dev,
58997b2e202SAlex Deucher 			    struct drm_mode_create_dumb *args);
59097b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp,
59197b2e202SAlex Deucher 			  struct drm_device *dev,
59297b2e202SAlex Deucher 			  uint32_t handle, uint64_t *offset_p);
59397b2e202SAlex Deucher /*
59497b2e202SAlex Deucher  * Synchronization
59597b2e202SAlex Deucher  */
59697b2e202SAlex Deucher struct amdgpu_sync {
597f91b3a69SChristian König 	DECLARE_HASHTABLE(fences, 4);
5983c62338cSChunming Zhou 	struct fence	        *last_vm_update;
59997b2e202SAlex Deucher };
60097b2e202SAlex Deucher 
60197b2e202SAlex Deucher void amdgpu_sync_create(struct amdgpu_sync *sync);
60291e1a520SChristian König int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
60391e1a520SChristian König 		      struct fence *f);
60497b2e202SAlex Deucher int amdgpu_sync_resv(struct amdgpu_device *adev,
60597b2e202SAlex Deucher 		     struct amdgpu_sync *sync,
60697b2e202SAlex Deucher 		     struct reservation_object *resv,
60797b2e202SAlex Deucher 		     void *owner);
6081fbb2e92SChristian König struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
60935420238SChristian König 				     struct amdgpu_ring *ring);
610e61235dbSChristian König struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
6118a8f0b48SChristian König void amdgpu_sync_free(struct amdgpu_sync *sync);
612257bf15aSChristian König int amdgpu_sync_init(void);
613257bf15aSChristian König void amdgpu_sync_fini(void);
614d573de2dSRex Zhu int amdgpu_fence_slab_init(void);
615d573de2dSRex Zhu void amdgpu_fence_slab_fini(void);
61697b2e202SAlex Deucher 
61797b2e202SAlex Deucher /*
61897b2e202SAlex Deucher  * GART structures, functions & helpers
61997b2e202SAlex Deucher  */
62097b2e202SAlex Deucher struct amdgpu_mc;
62197b2e202SAlex Deucher 
62297b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SIZE 4096
62397b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
62497b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SHIFT 12
62597b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
62697b2e202SAlex Deucher 
62797b2e202SAlex Deucher struct amdgpu_gart {
62897b2e202SAlex Deucher 	dma_addr_t			table_addr;
62997b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
63097b2e202SAlex Deucher 	void				*ptr;
63197b2e202SAlex Deucher 	unsigned			num_gpu_pages;
63297b2e202SAlex Deucher 	unsigned			num_cpu_pages;
63397b2e202SAlex Deucher 	unsigned			table_size;
634a1d29476SChristian König #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
63597b2e202SAlex Deucher 	struct page			**pages;
636a1d29476SChristian König #endif
63797b2e202SAlex Deucher 	bool				ready;
63897b2e202SAlex Deucher 	const struct amdgpu_gart_funcs *gart_funcs;
63997b2e202SAlex Deucher };
64097b2e202SAlex Deucher 
64197b2e202SAlex Deucher int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
64297b2e202SAlex Deucher void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
64397b2e202SAlex Deucher int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
64497b2e202SAlex Deucher void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
64597b2e202SAlex Deucher int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
64697b2e202SAlex Deucher void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
64797b2e202SAlex Deucher int amdgpu_gart_init(struct amdgpu_device *adev);
64897b2e202SAlex Deucher void amdgpu_gart_fini(struct amdgpu_device *adev);
64997b2e202SAlex Deucher void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
65097b2e202SAlex Deucher 			int pages);
65197b2e202SAlex Deucher int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
65297b2e202SAlex Deucher 		     int pages, struct page **pagelist,
65397b2e202SAlex Deucher 		     dma_addr_t *dma_addr, uint32_t flags);
65497b2e202SAlex Deucher 
65597b2e202SAlex Deucher /*
65697b2e202SAlex Deucher  * GPU MC structures, functions & helpers
65797b2e202SAlex Deucher  */
65897b2e202SAlex Deucher struct amdgpu_mc {
65997b2e202SAlex Deucher 	resource_size_t		aper_size;
66097b2e202SAlex Deucher 	resource_size_t		aper_base;
66197b2e202SAlex Deucher 	resource_size_t		agp_base;
66297b2e202SAlex Deucher 	/* for some chips with <= 32MB we need to lie
66397b2e202SAlex Deucher 	 * about vram size near mc fb location */
66497b2e202SAlex Deucher 	u64			mc_vram_size;
66597b2e202SAlex Deucher 	u64			visible_vram_size;
66697b2e202SAlex Deucher 	u64			gtt_size;
66797b2e202SAlex Deucher 	u64			gtt_start;
66897b2e202SAlex Deucher 	u64			gtt_end;
66997b2e202SAlex Deucher 	u64			vram_start;
67097b2e202SAlex Deucher 	u64			vram_end;
67197b2e202SAlex Deucher 	unsigned		vram_width;
67297b2e202SAlex Deucher 	u64			real_vram_size;
67397b2e202SAlex Deucher 	int			vram_mtrr;
67497b2e202SAlex Deucher 	u64                     gtt_base_align;
67597b2e202SAlex Deucher 	u64                     mc_mask;
67697b2e202SAlex Deucher 	const struct firmware   *fw;	/* MC firmware */
67797b2e202SAlex Deucher 	uint32_t                fw_version;
67897b2e202SAlex Deucher 	struct amdgpu_irq_src	vm_fault;
67981c59f54SKen Wang 	uint32_t		vram_type;
68097b2e202SAlex Deucher };
68197b2e202SAlex Deucher 
68297b2e202SAlex Deucher /*
68397b2e202SAlex Deucher  * GPU doorbell structures, functions & helpers
68497b2e202SAlex Deucher  */
68597b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
68697b2e202SAlex Deucher {
68797b2e202SAlex Deucher 	AMDGPU_DOORBELL_KIQ                     = 0x000,
68897b2e202SAlex Deucher 	AMDGPU_DOORBELL_HIQ                     = 0x001,
68997b2e202SAlex Deucher 	AMDGPU_DOORBELL_DIQ                     = 0x002,
69097b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
69197b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
69297b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
69397b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
69497b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
69597b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
69697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
69797b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
69897b2e202SAlex Deucher 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
69997b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
70097b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
70197b2e202SAlex Deucher 	AMDGPU_DOORBELL_IH                      = 0x1E8,
70297b2e202SAlex Deucher 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
70397b2e202SAlex Deucher 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
70497b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT;
70597b2e202SAlex Deucher 
70697b2e202SAlex Deucher struct amdgpu_doorbell {
70797b2e202SAlex Deucher 	/* doorbell mmio */
70897b2e202SAlex Deucher 	resource_size_t		base;
70997b2e202SAlex Deucher 	resource_size_t		size;
71097b2e202SAlex Deucher 	u32 __iomem		*ptr;
71197b2e202SAlex Deucher 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
71297b2e202SAlex Deucher };
71397b2e202SAlex Deucher 
71497b2e202SAlex Deucher void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
71597b2e202SAlex Deucher 				phys_addr_t *aperture_base,
71697b2e202SAlex Deucher 				size_t *aperture_size,
71797b2e202SAlex Deucher 				size_t *start_offset);
71897b2e202SAlex Deucher 
71997b2e202SAlex Deucher /*
72097b2e202SAlex Deucher  * IRQS.
72197b2e202SAlex Deucher  */
72297b2e202SAlex Deucher 
72397b2e202SAlex Deucher struct amdgpu_flip_work {
72497b2e202SAlex Deucher 	struct work_struct		flip_work;
72597b2e202SAlex Deucher 	struct work_struct		unpin_work;
72697b2e202SAlex Deucher 	struct amdgpu_device		*adev;
72797b2e202SAlex Deucher 	int				crtc_id;
72897b2e202SAlex Deucher 	uint64_t			base;
72997b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
73097b2e202SAlex Deucher 	struct amdgpu_bo		*old_rbo;
7311ffd2652SChristian König 	struct fence			*excl;
7321ffd2652SChristian König 	unsigned			shared_count;
7331ffd2652SChristian König 	struct fence			**shared;
734c3874b75SChristian König 	struct fence_cb			cb;
735cb9e59d7SAlex Deucher 	bool				async;
73697b2e202SAlex Deucher };
73797b2e202SAlex Deucher 
73897b2e202SAlex Deucher 
73997b2e202SAlex Deucher /*
74097b2e202SAlex Deucher  * CP & rings.
74197b2e202SAlex Deucher  */
74297b2e202SAlex Deucher 
74397b2e202SAlex Deucher struct amdgpu_ib {
74497b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
74597b2e202SAlex Deucher 	uint32_t			length_dw;
74697b2e202SAlex Deucher 	uint64_t			gpu_addr;
74797b2e202SAlex Deucher 	uint32_t			*ptr;
748de807f81SJammy Zhou 	uint32_t			flags;
74997b2e202SAlex Deucher };
75097b2e202SAlex Deucher 
75197b2e202SAlex Deucher enum amdgpu_ring_type {
75297b2e202SAlex Deucher 	AMDGPU_RING_TYPE_GFX,
75397b2e202SAlex Deucher 	AMDGPU_RING_TYPE_COMPUTE,
75497b2e202SAlex Deucher 	AMDGPU_RING_TYPE_SDMA,
75597b2e202SAlex Deucher 	AMDGPU_RING_TYPE_UVD,
75697b2e202SAlex Deucher 	AMDGPU_RING_TYPE_VCE
75797b2e202SAlex Deucher };
75897b2e202SAlex Deucher 
75962250a91SNils Wallménius extern const struct amd_sched_backend_ops amdgpu_sched_ops;
760c1b69ed0SChunming Zhou 
76150838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
762c5637837SMonk Liu 		     struct amdgpu_job **job, struct amdgpu_vm *vm);
763d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
764d71518b5SChristian König 			     struct amdgpu_job **job);
765b6723c8dSMonk Liu 
766a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job);
76750838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job);
768d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
7692bd9ccfaSChristian König 		      struct amd_sched_entity *entity, void *owner,
7702bd9ccfaSChristian König 		      struct fence **f);
7713c704e93SChunming Zhou 
77297b2e202SAlex Deucher struct amdgpu_ring {
77397b2e202SAlex Deucher 	struct amdgpu_device		*adev;
77497b2e202SAlex Deucher 	const struct amdgpu_ring_funcs	*funcs;
77597b2e202SAlex Deucher 	struct amdgpu_fence_driver	fence_drv;
7764f839a24SChristian König 	struct amd_gpu_scheduler	sched;
77797b2e202SAlex Deucher 
77897b2e202SAlex Deucher 	struct amdgpu_bo	*ring_obj;
77997b2e202SAlex Deucher 	volatile uint32_t	*ring;
78097b2e202SAlex Deucher 	unsigned		rptr_offs;
78197b2e202SAlex Deucher 	unsigned		wptr;
78297b2e202SAlex Deucher 	unsigned		wptr_old;
78397b2e202SAlex Deucher 	unsigned		ring_size;
784c7e6be23SChristian König 	unsigned		max_dw;
78597b2e202SAlex Deucher 	int			count_dw;
78697b2e202SAlex Deucher 	uint64_t		gpu_addr;
78797b2e202SAlex Deucher 	uint32_t		align_mask;
78897b2e202SAlex Deucher 	uint32_t		ptr_mask;
78997b2e202SAlex Deucher 	bool			ready;
79097b2e202SAlex Deucher 	u32			nop;
79197b2e202SAlex Deucher 	u32			idx;
79297b2e202SAlex Deucher 	u32			me;
79397b2e202SAlex Deucher 	u32			pipe;
79497b2e202SAlex Deucher 	u32			queue;
79597b2e202SAlex Deucher 	struct amdgpu_bo	*mqd_obj;
79697b2e202SAlex Deucher 	u32			doorbell_index;
79797b2e202SAlex Deucher 	bool			use_doorbell;
79897b2e202SAlex Deucher 	unsigned		wptr_offs;
79997b2e202SAlex Deucher 	unsigned		fence_offs;
800aa3b73f6SChristian König 	uint64_t		current_ctx;
80197b2e202SAlex Deucher 	enum amdgpu_ring_type	type;
80297b2e202SAlex Deucher 	char			name[16];
803128cff1aSMonk Liu 	unsigned		cond_exe_offs;
804128cff1aSMonk Liu 	u64			cond_exe_gpu_addr;
805128cff1aSMonk Liu 	volatile u32		*cond_exe_cpu_addr;
806a909c6bdSMonk Liu #if defined(CONFIG_DEBUG_FS)
807a909c6bdSMonk Liu 	struct dentry *ent;
808a909c6bdSMonk Liu #endif
80997b2e202SAlex Deucher };
81097b2e202SAlex Deucher 
81197b2e202SAlex Deucher /*
81297b2e202SAlex Deucher  * VM
81397b2e202SAlex Deucher  */
81497b2e202SAlex Deucher 
81597b2e202SAlex Deucher /* maximum number of VMIDs */
81697b2e202SAlex Deucher #define AMDGPU_NUM_VM	16
81797b2e202SAlex Deucher 
81897b2e202SAlex Deucher /* number of entries in page table */
81997b2e202SAlex Deucher #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
82097b2e202SAlex Deucher 
82197b2e202SAlex Deucher /* PTBs (Page Table Blocks) need to be aligned to 32K */
82297b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_SIZE   32768
82397b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
82497b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
82597b2e202SAlex Deucher 
82697b2e202SAlex Deucher #define AMDGPU_PTE_VALID	(1 << 0)
82797b2e202SAlex Deucher #define AMDGPU_PTE_SYSTEM	(1 << 1)
82897b2e202SAlex Deucher #define AMDGPU_PTE_SNOOPED	(1 << 2)
82997b2e202SAlex Deucher 
83097b2e202SAlex Deucher /* VI only */
83197b2e202SAlex Deucher #define AMDGPU_PTE_EXECUTABLE	(1 << 4)
83297b2e202SAlex Deucher 
83397b2e202SAlex Deucher #define AMDGPU_PTE_READABLE	(1 << 5)
83497b2e202SAlex Deucher #define AMDGPU_PTE_WRITEABLE	(1 << 6)
83597b2e202SAlex Deucher 
83697b2e202SAlex Deucher /* PTE (Page Table Entry) fragment field for different page sizes */
83797b2e202SAlex Deucher #define AMDGPU_PTE_FRAG_4KB	(0 << 7)
83897b2e202SAlex Deucher #define AMDGPU_PTE_FRAG_64KB	(4 << 7)
83997b2e202SAlex Deucher #define AMDGPU_LOG2_PAGES_PER_FRAG 4
84097b2e202SAlex Deucher 
841d9c13156SChristian König /* How to programm VM fault handling */
842d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_NEVER	0
843d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_FIRST	1
844d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_ALWAYS	2
845d9c13156SChristian König 
84697b2e202SAlex Deucher struct amdgpu_vm_pt {
847ee1782c3SChristian König 	struct amdgpu_bo_list_entry	entry;
84897b2e202SAlex Deucher 	uint64_t			addr;
84997b2e202SAlex Deucher };
85097b2e202SAlex Deucher 
85197b2e202SAlex Deucher struct amdgpu_vm {
85225cfc3c2SChristian König 	/* tree of virtual addresses mapped */
85397b2e202SAlex Deucher 	struct rb_root		va;
85497b2e202SAlex Deucher 
8557fc11959SChristian König 	/* protecting invalidated */
85697b2e202SAlex Deucher 	spinlock_t		status_lock;
85797b2e202SAlex Deucher 
85897b2e202SAlex Deucher 	/* BOs moved, but not yet updated in the PT */
85997b2e202SAlex Deucher 	struct list_head	invalidated;
86097b2e202SAlex Deucher 
8617fc11959SChristian König 	/* BOs cleared in the PT because of a move */
8627fc11959SChristian König 	struct list_head	cleared;
8637fc11959SChristian König 
8647fc11959SChristian König 	/* BO mappings freed, but not yet updated in the PT */
86597b2e202SAlex Deucher 	struct list_head	freed;
86697b2e202SAlex Deucher 
86797b2e202SAlex Deucher 	/* contains the page directory */
86897b2e202SAlex Deucher 	struct amdgpu_bo	*page_directory;
86997b2e202SAlex Deucher 	unsigned		max_pde_used;
87005906decSBas Nieuwenhuizen 	struct fence		*page_directory_fence;
8715a712a87SChristian König 	uint64_t		last_eviction_counter;
87297b2e202SAlex Deucher 
87397b2e202SAlex Deucher 	/* array of page tables, one for each page directory entry */
87497b2e202SAlex Deucher 	struct amdgpu_vm_pt	*page_tables;
87597b2e202SAlex Deucher 
87697b2e202SAlex Deucher 	/* for id and flush management per ring */
877bcb1ba35SChristian König 	struct amdgpu_vm_id	*ids[AMDGPU_MAX_RINGS];
87825cfc3c2SChristian König 
87981d75a30Sjimqu 	/* protecting freed */
88081d75a30Sjimqu 	spinlock_t		freed_lock;
8812bd9ccfaSChristian König 
8822bd9ccfaSChristian König 	/* Scheduler entity for page table updates */
8832bd9ccfaSChristian König 	struct amd_sched_entity	entity;
884031e2983SChunming Zhou 
885031e2983SChunming Zhou 	/* client id */
886031e2983SChunming Zhou 	u64                     client_id;
88797b2e202SAlex Deucher };
88897b2e202SAlex Deucher 
889bcb1ba35SChristian König struct amdgpu_vm_id {
890a9a78b32SChristian König 	struct list_head	list;
891832a902fSChristian König 	struct fence		*first;
892832a902fSChristian König 	struct amdgpu_sync	active;
89341d9eb2cSChristian König 	struct fence		*last_flush;
8940ea54b9bSChristian König 	atomic64_t		owner;
895971fe9a9SChristian König 
896bcb1ba35SChristian König 	uint64_t		pd_gpu_addr;
897bcb1ba35SChristian König 	/* last flushed PD/PT update */
898bcb1ba35SChristian König 	struct fence		*flushed_updates;
899bcb1ba35SChristian König 
9006adb0513SChunming Zhou 	uint32_t                current_gpu_reset_count;
9016adb0513SChunming Zhou 
902971fe9a9SChristian König 	uint32_t		gds_base;
903971fe9a9SChristian König 	uint32_t		gds_size;
904971fe9a9SChristian König 	uint32_t		gws_base;
905971fe9a9SChristian König 	uint32_t		gws_size;
906971fe9a9SChristian König 	uint32_t		oa_base;
907971fe9a9SChristian König 	uint32_t		oa_size;
908a9a78b32SChristian König };
909a9a78b32SChristian König 
910a9a78b32SChristian König struct amdgpu_vm_manager {
911a9a78b32SChristian König 	/* Handling of VMIDs */
912a9a78b32SChristian König 	struct mutex				lock;
913a9a78b32SChristian König 	unsigned				num_ids;
914a9a78b32SChristian König 	struct list_head			ids_lru;
915bcb1ba35SChristian König 	struct amdgpu_vm_id			ids[AMDGPU_NUM_VM];
9161c16c0a7SChristian König 
9171fbb2e92SChristian König 	/* Handling of VM fences */
9181fbb2e92SChristian König 	u64					fence_context;
9191fbb2e92SChristian König 	unsigned				seqno[AMDGPU_MAX_RINGS];
9201fbb2e92SChristian König 
92197b2e202SAlex Deucher 	uint32_t				max_pfn;
92297b2e202SAlex Deucher 	/* vram base address for page table entry  */
92397b2e202SAlex Deucher 	u64					vram_base_offset;
92497b2e202SAlex Deucher 	/* is vm enabled? */
92597b2e202SAlex Deucher 	bool					enabled;
92697b2e202SAlex Deucher 	/* vm pte handling */
92797b2e202SAlex Deucher 	const struct amdgpu_vm_pte_funcs        *vm_pte_funcs;
9282d55e45aSChristian König 	struct amdgpu_ring                      *vm_pte_rings[AMDGPU_MAX_RINGS];
9292d55e45aSChristian König 	unsigned				vm_pte_num_rings;
9302d55e45aSChristian König 	atomic_t				vm_pte_next_ring;
931031e2983SChunming Zhou 	/* client id counter */
932031e2983SChunming Zhou 	atomic64_t				client_counter;
93397b2e202SAlex Deucher };
93497b2e202SAlex Deucher 
935a9a78b32SChristian König void amdgpu_vm_manager_init(struct amdgpu_device *adev);
936ea89f8c9SChristian König void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
9378b4fb00bSChristian König int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
9388b4fb00bSChristian König void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
93956467ebfSChristian König void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
9403c0eea6cSChristian König 			 struct list_head *validated,
94156467ebfSChristian König 			 struct amdgpu_bo_list_entry *entry);
9425a712a87SChristian König void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
9435a712a87SChristian König 			  struct list_head *duplicates);
944eceb8a15SChristian König void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
945eceb8a15SChristian König 				  struct amdgpu_vm *vm);
9468b4fb00bSChristian König int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
9474ff37a83SChristian König 		      struct amdgpu_sync *sync, struct fence *fence,
948fd53be30SChunming Zhou 		      struct amdgpu_job *job);
949fd53be30SChunming Zhou int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
950971fe9a9SChristian König void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
951b07c9d2aSChristian König uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
9528b4fb00bSChristian König int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
9538b4fb00bSChristian König 				    struct amdgpu_vm *vm);
9548b4fb00bSChristian König int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
9558b4fb00bSChristian König 			  struct amdgpu_vm *vm);
9568b4fb00bSChristian König int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
9578b4fb00bSChristian König 			     struct amdgpu_sync *sync);
9588b4fb00bSChristian König int amdgpu_vm_bo_update(struct amdgpu_device *adev,
9598b4fb00bSChristian König 			struct amdgpu_bo_va *bo_va,
9608b4fb00bSChristian König 			struct ttm_mem_reg *mem);
9618b4fb00bSChristian König void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
9628b4fb00bSChristian König 			     struct amdgpu_bo *bo);
9638b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
9648b4fb00bSChristian König 				       struct amdgpu_bo *bo);
9658b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
9668b4fb00bSChristian König 				      struct amdgpu_vm *vm,
9678b4fb00bSChristian König 				      struct amdgpu_bo *bo);
9688b4fb00bSChristian König int amdgpu_vm_bo_map(struct amdgpu_device *adev,
9698b4fb00bSChristian König 		     struct amdgpu_bo_va *bo_va,
9708b4fb00bSChristian König 		     uint64_t addr, uint64_t offset,
9718b4fb00bSChristian König 		     uint64_t size, uint32_t flags);
9728b4fb00bSChristian König int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
9738b4fb00bSChristian König 		       struct amdgpu_bo_va *bo_va,
9748b4fb00bSChristian König 		       uint64_t addr);
9758b4fb00bSChristian König void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
9768b4fb00bSChristian König 		      struct amdgpu_bo_va *bo_va);
9778b4fb00bSChristian König 
97897b2e202SAlex Deucher /*
97997b2e202SAlex Deucher  * context related structures
98097b2e202SAlex Deucher  */
98197b2e202SAlex Deucher 
98221c16bf6SChristian König struct amdgpu_ctx_ring {
98321c16bf6SChristian König 	uint64_t		sequence;
98437cd0ca2SChunming Zhou 	struct fence		**fences;
98591404fb2SChristian König 	struct amd_sched_entity	entity;
98621c16bf6SChristian König };
98721c16bf6SChristian König 
98897b2e202SAlex Deucher struct amdgpu_ctx {
98997b2e202SAlex Deucher 	struct kref		refcount;
9909cb7e5a9SChunming Zhou 	struct amdgpu_device    *adev;
991d94aed5aSMarek Olšák 	unsigned		reset_counter;
99221c16bf6SChristian König 	spinlock_t		ring_lock;
99337cd0ca2SChunming Zhou 	struct fence            **fences;
99421c16bf6SChristian König 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
99597b2e202SAlex Deucher };
99697b2e202SAlex Deucher 
99797b2e202SAlex Deucher struct amdgpu_ctx_mgr {
99897b2e202SAlex Deucher 	struct amdgpu_device	*adev;
9990147ee0fSMarek Olšák 	struct mutex		lock;
10000b492a4cSAlex Deucher 	/* protected by lock */
10010b492a4cSAlex Deucher 	struct idr		ctx_handles;
100297b2e202SAlex Deucher };
100397b2e202SAlex Deucher 
10040b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
10050b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
10060b492a4cSAlex Deucher 
100721c16bf6SChristian König uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
1008ce882e6dSChristian König 			      struct fence *fence);
100921c16bf6SChristian König struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
101021c16bf6SChristian König 				   struct amdgpu_ring *ring, uint64_t seq);
101121c16bf6SChristian König 
10120b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
10130b492a4cSAlex Deucher 		     struct drm_file *filp);
10140b492a4cSAlex Deucher 
1015efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1016efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
10170b492a4cSAlex Deucher 
101897b2e202SAlex Deucher /*
101997b2e202SAlex Deucher  * file private structure
102097b2e202SAlex Deucher  */
102197b2e202SAlex Deucher 
102297b2e202SAlex Deucher struct amdgpu_fpriv {
102397b2e202SAlex Deucher 	struct amdgpu_vm	vm;
102497b2e202SAlex Deucher 	struct mutex		bo_list_lock;
102597b2e202SAlex Deucher 	struct idr		bo_list_handles;
102697b2e202SAlex Deucher 	struct amdgpu_ctx_mgr	ctx_mgr;
102797b2e202SAlex Deucher };
102897b2e202SAlex Deucher 
102997b2e202SAlex Deucher /*
103097b2e202SAlex Deucher  * residency list
103197b2e202SAlex Deucher  */
103297b2e202SAlex Deucher 
103397b2e202SAlex Deucher struct amdgpu_bo_list {
103497b2e202SAlex Deucher 	struct mutex lock;
103597b2e202SAlex Deucher 	struct amdgpu_bo *gds_obj;
103697b2e202SAlex Deucher 	struct amdgpu_bo *gws_obj;
103797b2e202SAlex Deucher 	struct amdgpu_bo *oa_obj;
1038211dff55SChristian König 	unsigned first_userptr;
103997b2e202SAlex Deucher 	unsigned num_entries;
104097b2e202SAlex Deucher 	struct amdgpu_bo_list_entry *array;
104197b2e202SAlex Deucher };
104297b2e202SAlex Deucher 
104397b2e202SAlex Deucher struct amdgpu_bo_list *
104497b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
1045636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1046636ce25cSChristian König 			     struct list_head *validated);
104797b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
104897b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
104997b2e202SAlex Deucher 
105097b2e202SAlex Deucher /*
105197b2e202SAlex Deucher  * GFX stuff
105297b2e202SAlex Deucher  */
105397b2e202SAlex Deucher #include "clearstate_defs.h"
105497b2e202SAlex Deucher 
105579e5412cSAlex Deucher struct amdgpu_rlc_funcs {
105679e5412cSAlex Deucher 	void (*enter_safe_mode)(struct amdgpu_device *adev);
105779e5412cSAlex Deucher 	void (*exit_safe_mode)(struct amdgpu_device *adev);
105879e5412cSAlex Deucher };
105979e5412cSAlex Deucher 
106097b2e202SAlex Deucher struct amdgpu_rlc {
106197b2e202SAlex Deucher 	/* for power gating */
106297b2e202SAlex Deucher 	struct amdgpu_bo	*save_restore_obj;
106397b2e202SAlex Deucher 	uint64_t		save_restore_gpu_addr;
106497b2e202SAlex Deucher 	volatile uint32_t	*sr_ptr;
106597b2e202SAlex Deucher 	const u32               *reg_list;
106697b2e202SAlex Deucher 	u32                     reg_list_size;
106797b2e202SAlex Deucher 	/* for clear state */
106897b2e202SAlex Deucher 	struct amdgpu_bo	*clear_state_obj;
106997b2e202SAlex Deucher 	uint64_t		clear_state_gpu_addr;
107097b2e202SAlex Deucher 	volatile uint32_t	*cs_ptr;
107197b2e202SAlex Deucher 	const struct cs_section_def   *cs_data;
107297b2e202SAlex Deucher 	u32                     clear_state_size;
107397b2e202SAlex Deucher 	/* for cp tables */
107497b2e202SAlex Deucher 	struct amdgpu_bo	*cp_table_obj;
107597b2e202SAlex Deucher 	uint64_t		cp_table_gpu_addr;
107697b2e202SAlex Deucher 	volatile uint32_t	*cp_table_ptr;
107797b2e202SAlex Deucher 	u32                     cp_table_size;
107879e5412cSAlex Deucher 
107979e5412cSAlex Deucher 	/* safe mode for updating CG/PG state */
108079e5412cSAlex Deucher 	bool in_safe_mode;
108179e5412cSAlex Deucher 	const struct amdgpu_rlc_funcs *funcs;
10822b6cd977SEric Huang 
10832b6cd977SEric Huang 	/* for firmware data */
10842b6cd977SEric Huang 	u32 save_and_restore_offset;
10852b6cd977SEric Huang 	u32 clear_state_descriptor_offset;
10862b6cd977SEric Huang 	u32 avail_scratch_ram_locations;
10872b6cd977SEric Huang 	u32 reg_restore_list_size;
10882b6cd977SEric Huang 	u32 reg_list_format_start;
10892b6cd977SEric Huang 	u32 reg_list_format_separate_start;
10902b6cd977SEric Huang 	u32 starting_offsets_start;
10912b6cd977SEric Huang 	u32 reg_list_format_size_bytes;
10922b6cd977SEric Huang 	u32 reg_list_size_bytes;
10932b6cd977SEric Huang 
10942b6cd977SEric Huang 	u32 *register_list_format;
10952b6cd977SEric Huang 	u32 *register_restore;
109697b2e202SAlex Deucher };
109797b2e202SAlex Deucher 
109897b2e202SAlex Deucher struct amdgpu_mec {
109997b2e202SAlex Deucher 	struct amdgpu_bo	*hpd_eop_obj;
110097b2e202SAlex Deucher 	u64			hpd_eop_gpu_addr;
110197b2e202SAlex Deucher 	u32 num_pipe;
110297b2e202SAlex Deucher 	u32 num_mec;
110397b2e202SAlex Deucher 	u32 num_queue;
110497b2e202SAlex Deucher };
110597b2e202SAlex Deucher 
110697b2e202SAlex Deucher /*
110797b2e202SAlex Deucher  * GPU scratch registers structures, functions & helpers
110897b2e202SAlex Deucher  */
110997b2e202SAlex Deucher struct amdgpu_scratch {
111097b2e202SAlex Deucher 	unsigned		num_reg;
111197b2e202SAlex Deucher 	uint32_t                reg_base;
111297b2e202SAlex Deucher 	bool			free[32];
111397b2e202SAlex Deucher 	uint32_t		reg[32];
111497b2e202SAlex Deucher };
111597b2e202SAlex Deucher 
111697b2e202SAlex Deucher /*
111797b2e202SAlex Deucher  * GFX configurations
111897b2e202SAlex Deucher  */
111997b2e202SAlex Deucher struct amdgpu_gca_config {
112097b2e202SAlex Deucher 	unsigned max_shader_engines;
112197b2e202SAlex Deucher 	unsigned max_tile_pipes;
112297b2e202SAlex Deucher 	unsigned max_cu_per_sh;
112397b2e202SAlex Deucher 	unsigned max_sh_per_se;
112497b2e202SAlex Deucher 	unsigned max_backends_per_se;
112597b2e202SAlex Deucher 	unsigned max_texture_channel_caches;
112697b2e202SAlex Deucher 	unsigned max_gprs;
112797b2e202SAlex Deucher 	unsigned max_gs_threads;
112897b2e202SAlex Deucher 	unsigned max_hw_contexts;
112997b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_frontend;
113097b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_backend;
113197b2e202SAlex Deucher 	unsigned sc_hiz_tile_fifo_size;
113297b2e202SAlex Deucher 	unsigned sc_earlyz_tile_fifo_size;
113397b2e202SAlex Deucher 
113497b2e202SAlex Deucher 	unsigned num_tile_pipes;
113597b2e202SAlex Deucher 	unsigned backend_enable_mask;
113697b2e202SAlex Deucher 	unsigned mem_max_burst_length_bytes;
113797b2e202SAlex Deucher 	unsigned mem_row_size_in_kb;
113897b2e202SAlex Deucher 	unsigned shader_engine_tile_size;
113997b2e202SAlex Deucher 	unsigned num_gpus;
114097b2e202SAlex Deucher 	unsigned multi_gpu_tile_size;
114197b2e202SAlex Deucher 	unsigned mc_arb_ramcfg;
114297b2e202SAlex Deucher 	unsigned gb_addr_config;
11438f8e00c1SAlex Deucher 	unsigned num_rbs;
114497b2e202SAlex Deucher 
114597b2e202SAlex Deucher 	uint32_t tile_mode_array[32];
114697b2e202SAlex Deucher 	uint32_t macrotile_mode_array[16];
114797b2e202SAlex Deucher };
114897b2e202SAlex Deucher 
11497dae69a2SAlex Deucher struct amdgpu_cu_info {
11507dae69a2SAlex Deucher 	uint32_t number; /* total active CU number */
11517dae69a2SAlex Deucher 	uint32_t ao_cu_mask;
11527dae69a2SAlex Deucher 	uint32_t bitmap[4][4];
11537dae69a2SAlex Deucher };
11547dae69a2SAlex Deucher 
1155b95e31fdSAlex Deucher struct amdgpu_gfx_funcs {
1156b95e31fdSAlex Deucher 	/* get the gpu clock counter */
1157b95e31fdSAlex Deucher 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
11589559ef5bSTom St Denis 	void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
1159b95e31fdSAlex Deucher };
1160b95e31fdSAlex Deucher 
116197b2e202SAlex Deucher struct amdgpu_gfx {
116297b2e202SAlex Deucher 	struct mutex			gpu_clock_mutex;
116397b2e202SAlex Deucher 	struct amdgpu_gca_config	config;
116497b2e202SAlex Deucher 	struct amdgpu_rlc		rlc;
116597b2e202SAlex Deucher 	struct amdgpu_mec		mec;
116697b2e202SAlex Deucher 	struct amdgpu_scratch		scratch;
116797b2e202SAlex Deucher 	const struct firmware		*me_fw;	/* ME firmware */
116897b2e202SAlex Deucher 	uint32_t			me_fw_version;
116997b2e202SAlex Deucher 	const struct firmware		*pfp_fw; /* PFP firmware */
117097b2e202SAlex Deucher 	uint32_t			pfp_fw_version;
117197b2e202SAlex Deucher 	const struct firmware		*ce_fw;	/* CE firmware */
117297b2e202SAlex Deucher 	uint32_t			ce_fw_version;
117397b2e202SAlex Deucher 	const struct firmware		*rlc_fw; /* RLC firmware */
117497b2e202SAlex Deucher 	uint32_t			rlc_fw_version;
117597b2e202SAlex Deucher 	const struct firmware		*mec_fw; /* MEC firmware */
117697b2e202SAlex Deucher 	uint32_t			mec_fw_version;
117797b2e202SAlex Deucher 	const struct firmware		*mec2_fw; /* MEC2 firmware */
117897b2e202SAlex Deucher 	uint32_t			mec2_fw_version;
117902558a00SKen Wang 	uint32_t			me_feature_version;
118002558a00SKen Wang 	uint32_t			ce_feature_version;
118102558a00SKen Wang 	uint32_t			pfp_feature_version;
1182351643d7SJammy Zhou 	uint32_t			rlc_feature_version;
1183351643d7SJammy Zhou 	uint32_t			mec_feature_version;
1184351643d7SJammy Zhou 	uint32_t			mec2_feature_version;
118597b2e202SAlex Deucher 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
118697b2e202SAlex Deucher 	unsigned			num_gfx_rings;
118797b2e202SAlex Deucher 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
118897b2e202SAlex Deucher 	unsigned			num_compute_rings;
118997b2e202SAlex Deucher 	struct amdgpu_irq_src		eop_irq;
119097b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_reg_irq;
119197b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_inst_irq;
119297b2e202SAlex Deucher 	/* gfx status */
119397b2e202SAlex Deucher 	uint32_t			gfx_current_status;
1194a101a899SKen Wang 	/* ce ram size*/
1195a101a899SKen Wang 	unsigned			ce_ram_size;
11967dae69a2SAlex Deucher 	struct amdgpu_cu_info		cu_info;
1197b95e31fdSAlex Deucher 	const struct amdgpu_gfx_funcs	*funcs;
119897b2e202SAlex Deucher };
119997b2e202SAlex Deucher 
1200b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
120197b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
12024d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
12034d9c514dSChristian König 		    struct fence *f);
1204b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
1205336d1f5eSChristian König 		       struct amdgpu_ib *ib, struct fence *last_vm_update,
1206c5637837SMonk Liu 		       struct amdgpu_job *job, struct fence **f);
120797b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
120897b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
120997b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
121097b2e202SAlex Deucher int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
1211edff0e28SJammy Zhou void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
12129e5d5309SChristian König void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
121397b2e202SAlex Deucher void amdgpu_ring_commit(struct amdgpu_ring *ring);
121497b2e202SAlex Deucher void amdgpu_ring_undo(struct amdgpu_ring *ring);
121597b2e202SAlex Deucher int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
121697b2e202SAlex Deucher 		     unsigned ring_size, u32 nop, u32 align_mask,
121797b2e202SAlex Deucher 		     struct amdgpu_irq_src *irq_src, unsigned irq_type,
121897b2e202SAlex Deucher 		     enum amdgpu_ring_type ring_type);
121997b2e202SAlex Deucher void amdgpu_ring_fini(struct amdgpu_ring *ring);
122097b2e202SAlex Deucher 
122197b2e202SAlex Deucher /*
122297b2e202SAlex Deucher  * CS.
122397b2e202SAlex Deucher  */
122497b2e202SAlex Deucher struct amdgpu_cs_chunk {
122597b2e202SAlex Deucher 	uint32_t		chunk_id;
122697b2e202SAlex Deucher 	uint32_t		length_dw;
1227758ac17fSChristian König 	void			*kdata;
122897b2e202SAlex Deucher };
122997b2e202SAlex Deucher 
123097b2e202SAlex Deucher struct amdgpu_cs_parser {
123197b2e202SAlex Deucher 	struct amdgpu_device	*adev;
123297b2e202SAlex Deucher 	struct drm_file		*filp;
12333cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
1234c3cca41eSChristian König 
123597b2e202SAlex Deucher 	/* chunks */
123697b2e202SAlex Deucher 	unsigned		nchunks;
123797b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
1238c3cca41eSChristian König 
123950838c8cSChristian König 	/* scheduler job object */
124050838c8cSChristian König 	struct amdgpu_job	*job;
1241c3cca41eSChristian König 
1242c3cca41eSChristian König 	/* buffer objects */
1243c3cca41eSChristian König 	struct ww_acquire_ctx		ticket;
1244c3cca41eSChristian König 	struct amdgpu_bo_list		*bo_list;
124556467ebfSChristian König 	struct amdgpu_bo_list_entry	vm_pd;
124697b2e202SAlex Deucher 	struct list_head		validated;
1247984810fcSChristian König 	struct fence			*fence;
1248f69f90a1SChristian König 	uint64_t			bytes_moved_threshold;
1249f69f90a1SChristian König 	uint64_t			bytes_moved;
125097b2e202SAlex Deucher 
125197b2e202SAlex Deucher 	/* user fence */
125291acbeb6SChristian König 	struct amdgpu_bo_list_entry	uf_entry;
125397b2e202SAlex Deucher };
125497b2e202SAlex Deucher 
1255bb977d37SChunming Zhou struct amdgpu_job {
1256bb977d37SChunming Zhou 	struct amd_sched_job    base;
1257bb977d37SChunming Zhou 	struct amdgpu_device	*adev;
1258c5637837SMonk Liu 	struct amdgpu_vm	*vm;
1259b07c60c0SChristian König 	struct amdgpu_ring	*ring;
1260e86f9ceeSChristian König 	struct amdgpu_sync	sync;
1261bb977d37SChunming Zhou 	struct amdgpu_ib	*ibs;
126273cfa5f5SMonk Liu 	struct fence		*fence; /* the hw fence */
1263bb977d37SChunming Zhou 	uint32_t		num_ibs;
1264e2840221SChristian König 	void			*owner;
126592f25098SChristian König 	uint64_t		ctx;
1266fd53be30SChunming Zhou 	bool                    vm_needs_flush;
1267d88bf583SChristian König 	unsigned		vm_id;
1268d88bf583SChristian König 	uint64_t		vm_pd_addr;
1269d88bf583SChristian König 	uint32_t		gds_base, gds_size;
1270d88bf583SChristian König 	uint32_t		gws_base, gws_size;
1271d88bf583SChristian König 	uint32_t		oa_base, oa_size;
1272758ac17fSChristian König 
1273758ac17fSChristian König 	/* user fence handling */
1274b5f5acbcSChristian König 	uint64_t		uf_addr;
1275758ac17fSChristian König 	uint64_t		uf_sequence;
1276758ac17fSChristian König 
1277bb977d37SChunming Zhou };
1278a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job)		\
1279a6db8a33SJunwei Zhang 		container_of((sched_job), struct amdgpu_job, base)
1280bb977d37SChunming Zhou 
12817270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
12827270f839SChristian König 				      uint32_t ib_idx, int idx)
128397b2e202SAlex Deucher {
128450838c8cSChristian König 	return p->job->ibs[ib_idx].ptr[idx];
128597b2e202SAlex Deucher }
128697b2e202SAlex Deucher 
12877270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
12887270f839SChristian König 				       uint32_t ib_idx, int idx,
12897270f839SChristian König 				       uint32_t value)
12907270f839SChristian König {
129150838c8cSChristian König 	p->job->ibs[ib_idx].ptr[idx] = value;
12927270f839SChristian König }
12937270f839SChristian König 
129497b2e202SAlex Deucher /*
129597b2e202SAlex Deucher  * Writeback
129697b2e202SAlex Deucher  */
129797b2e202SAlex Deucher #define AMDGPU_MAX_WB 1024	/* Reserve at most 1024 WB slots for amdgpu-owned rings. */
129897b2e202SAlex Deucher 
129997b2e202SAlex Deucher struct amdgpu_wb {
130097b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
130197b2e202SAlex Deucher 	volatile uint32_t	*wb;
130297b2e202SAlex Deucher 	uint64_t		gpu_addr;
130397b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
130497b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
130597b2e202SAlex Deucher };
130697b2e202SAlex Deucher 
130797b2e202SAlex Deucher int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
130897b2e202SAlex Deucher void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
130997b2e202SAlex Deucher 
131097b2e202SAlex Deucher 
131197b2e202SAlex Deucher 
131297b2e202SAlex Deucher enum amdgpu_int_thermal_type {
131397b2e202SAlex Deucher 	THERMAL_TYPE_NONE,
131497b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL,
131597b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL_GPIO,
131697b2e202SAlex Deucher 	THERMAL_TYPE_RV6XX,
131797b2e202SAlex Deucher 	THERMAL_TYPE_RV770,
131897b2e202SAlex Deucher 	THERMAL_TYPE_ADT7473_WITH_INTERNAL,
131997b2e202SAlex Deucher 	THERMAL_TYPE_EVERGREEN,
132097b2e202SAlex Deucher 	THERMAL_TYPE_SUMO,
132197b2e202SAlex Deucher 	THERMAL_TYPE_NI,
132297b2e202SAlex Deucher 	THERMAL_TYPE_SI,
132397b2e202SAlex Deucher 	THERMAL_TYPE_EMC2103_WITH_INTERNAL,
132497b2e202SAlex Deucher 	THERMAL_TYPE_CI,
132597b2e202SAlex Deucher 	THERMAL_TYPE_KV,
132697b2e202SAlex Deucher };
132797b2e202SAlex Deucher 
132897b2e202SAlex Deucher enum amdgpu_dpm_auto_throttle_src {
132997b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
133097b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
133197b2e202SAlex Deucher };
133297b2e202SAlex Deucher 
133397b2e202SAlex Deucher enum amdgpu_dpm_event_src {
133497b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
133597b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
133697b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
133797b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
133897b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
133997b2e202SAlex Deucher };
134097b2e202SAlex Deucher 
134197b2e202SAlex Deucher #define AMDGPU_MAX_VCE_LEVELS 6
134297b2e202SAlex Deucher 
134397b2e202SAlex Deucher enum amdgpu_vce_level {
134497b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_AC_ALL = 0,     /* AC, All cases */
134597b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_EE = 1,      /* DC, entropy encoding */
134697b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_LOW = 2,  /* DC, low latency queue, res <= 720 */
134797b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
134897b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_LOW = 4,  /* DC, general purpose queue, res <= 720 */
134997b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
135097b2e202SAlex Deucher };
135197b2e202SAlex Deucher 
135297b2e202SAlex Deucher struct amdgpu_ps {
135397b2e202SAlex Deucher 	u32 caps; /* vbios flags */
135497b2e202SAlex Deucher 	u32 class; /* vbios flags */
135597b2e202SAlex Deucher 	u32 class2; /* vbios flags */
135697b2e202SAlex Deucher 	/* UVD clocks */
135797b2e202SAlex Deucher 	u32 vclk;
135897b2e202SAlex Deucher 	u32 dclk;
135997b2e202SAlex Deucher 	/* VCE clocks */
136097b2e202SAlex Deucher 	u32 evclk;
136197b2e202SAlex Deucher 	u32 ecclk;
136297b2e202SAlex Deucher 	bool vce_active;
136397b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
136497b2e202SAlex Deucher 	/* asic priv */
136597b2e202SAlex Deucher 	void *ps_priv;
136697b2e202SAlex Deucher };
136797b2e202SAlex Deucher 
136897b2e202SAlex Deucher struct amdgpu_dpm_thermal {
136997b2e202SAlex Deucher 	/* thermal interrupt work */
137097b2e202SAlex Deucher 	struct work_struct work;
137197b2e202SAlex Deucher 	/* low temperature threshold */
137297b2e202SAlex Deucher 	int                min_temp;
137397b2e202SAlex Deucher 	/* high temperature threshold */
137497b2e202SAlex Deucher 	int                max_temp;
137597b2e202SAlex Deucher 	/* was last interrupt low to high or high to low */
137697b2e202SAlex Deucher 	bool               high_to_low;
137797b2e202SAlex Deucher 	/* interrupt source */
137897b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
137997b2e202SAlex Deucher };
138097b2e202SAlex Deucher 
138197b2e202SAlex Deucher enum amdgpu_clk_action
138297b2e202SAlex Deucher {
138397b2e202SAlex Deucher 	AMDGPU_SCLK_UP = 1,
138497b2e202SAlex Deucher 	AMDGPU_SCLK_DOWN
138597b2e202SAlex Deucher };
138697b2e202SAlex Deucher 
138797b2e202SAlex Deucher struct amdgpu_blacklist_clocks
138897b2e202SAlex Deucher {
138997b2e202SAlex Deucher 	u32 sclk;
139097b2e202SAlex Deucher 	u32 mclk;
139197b2e202SAlex Deucher 	enum amdgpu_clk_action action;
139297b2e202SAlex Deucher };
139397b2e202SAlex Deucher 
139497b2e202SAlex Deucher struct amdgpu_clock_and_voltage_limits {
139597b2e202SAlex Deucher 	u32 sclk;
139697b2e202SAlex Deucher 	u32 mclk;
139797b2e202SAlex Deucher 	u16 vddc;
139897b2e202SAlex Deucher 	u16 vddci;
139997b2e202SAlex Deucher };
140097b2e202SAlex Deucher 
140197b2e202SAlex Deucher struct amdgpu_clock_array {
140297b2e202SAlex Deucher 	u32 count;
140397b2e202SAlex Deucher 	u32 *values;
140497b2e202SAlex Deucher };
140597b2e202SAlex Deucher 
140697b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_entry {
140797b2e202SAlex Deucher 	u32 clk;
140897b2e202SAlex Deucher 	u16 v;
140997b2e202SAlex Deucher };
141097b2e202SAlex Deucher 
141197b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table {
141297b2e202SAlex Deucher 	u32 count;
141397b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_entry *entries;
141497b2e202SAlex Deucher };
141597b2e202SAlex Deucher 
141697b2e202SAlex Deucher union amdgpu_cac_leakage_entry {
141797b2e202SAlex Deucher 	struct {
141897b2e202SAlex Deucher 		u16 vddc;
141997b2e202SAlex Deucher 		u32 leakage;
142097b2e202SAlex Deucher 	};
142197b2e202SAlex Deucher 	struct {
142297b2e202SAlex Deucher 		u16 vddc1;
142397b2e202SAlex Deucher 		u16 vddc2;
142497b2e202SAlex Deucher 		u16 vddc3;
142597b2e202SAlex Deucher 	};
142697b2e202SAlex Deucher };
142797b2e202SAlex Deucher 
142897b2e202SAlex Deucher struct amdgpu_cac_leakage_table {
142997b2e202SAlex Deucher 	u32 count;
143097b2e202SAlex Deucher 	union amdgpu_cac_leakage_entry *entries;
143197b2e202SAlex Deucher };
143297b2e202SAlex Deucher 
143397b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_entry {
143497b2e202SAlex Deucher 	u16 voltage;
143597b2e202SAlex Deucher 	u32 sclk;
143697b2e202SAlex Deucher 	u32 mclk;
143797b2e202SAlex Deucher };
143897b2e202SAlex Deucher 
143997b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_table {
144097b2e202SAlex Deucher 	u32 count;
144197b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_entry *entries;
144297b2e202SAlex Deucher };
144397b2e202SAlex Deucher 
144497b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_entry {
144597b2e202SAlex Deucher 	u32 vclk;
144697b2e202SAlex Deucher 	u32 dclk;
144797b2e202SAlex Deucher 	u16 v;
144897b2e202SAlex Deucher };
144997b2e202SAlex Deucher 
145097b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_table {
145197b2e202SAlex Deucher 	u8 count;
145297b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
145397b2e202SAlex Deucher };
145497b2e202SAlex Deucher 
145597b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_entry {
145697b2e202SAlex Deucher 	u32 ecclk;
145797b2e202SAlex Deucher 	u32 evclk;
145897b2e202SAlex Deucher 	u16 v;
145997b2e202SAlex Deucher };
146097b2e202SAlex Deucher 
146197b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_table {
146297b2e202SAlex Deucher 	u8 count;
146397b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_entry *entries;
146497b2e202SAlex Deucher };
146597b2e202SAlex Deucher 
146697b2e202SAlex Deucher struct amdgpu_ppm_table {
146797b2e202SAlex Deucher 	u8 ppm_design;
146897b2e202SAlex Deucher 	u16 cpu_core_number;
146997b2e202SAlex Deucher 	u32 platform_tdp;
147097b2e202SAlex Deucher 	u32 small_ac_platform_tdp;
147197b2e202SAlex Deucher 	u32 platform_tdc;
147297b2e202SAlex Deucher 	u32 small_ac_platform_tdc;
147397b2e202SAlex Deucher 	u32 apu_tdp;
147497b2e202SAlex Deucher 	u32 dgpu_tdp;
147597b2e202SAlex Deucher 	u32 dgpu_ulv_power;
147697b2e202SAlex Deucher 	u32 tj_max;
147797b2e202SAlex Deucher };
147897b2e202SAlex Deucher 
147997b2e202SAlex Deucher struct amdgpu_cac_tdp_table {
148097b2e202SAlex Deucher 	u16 tdp;
148197b2e202SAlex Deucher 	u16 configurable_tdp;
148297b2e202SAlex Deucher 	u16 tdc;
148397b2e202SAlex Deucher 	u16 battery_power_limit;
148497b2e202SAlex Deucher 	u16 small_power_limit;
148597b2e202SAlex Deucher 	u16 low_cac_leakage;
148697b2e202SAlex Deucher 	u16 high_cac_leakage;
148797b2e202SAlex Deucher 	u16 maximum_power_delivery_limit;
148897b2e202SAlex Deucher };
148997b2e202SAlex Deucher 
149097b2e202SAlex Deucher struct amdgpu_dpm_dynamic_state {
149197b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
149297b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
149397b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
149497b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
149597b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
149697b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
149797b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
149897b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
149997b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
150097b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
150197b2e202SAlex Deucher 	struct amdgpu_clock_array valid_sclk_values;
150297b2e202SAlex Deucher 	struct amdgpu_clock_array valid_mclk_values;
150397b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
150497b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
150597b2e202SAlex Deucher 	u32 mclk_sclk_ratio;
150697b2e202SAlex Deucher 	u32 sclk_mclk_delta;
150797b2e202SAlex Deucher 	u16 vddc_vddci_delta;
150897b2e202SAlex Deucher 	u16 min_vddc_for_pcie_gen2;
150997b2e202SAlex Deucher 	struct amdgpu_cac_leakage_table cac_leakage_table;
151097b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
151197b2e202SAlex Deucher 	struct amdgpu_ppm_table *ppm_table;
151297b2e202SAlex Deucher 	struct amdgpu_cac_tdp_table *cac_tdp_table;
151397b2e202SAlex Deucher };
151497b2e202SAlex Deucher 
151597b2e202SAlex Deucher struct amdgpu_dpm_fan {
151697b2e202SAlex Deucher 	u16 t_min;
151797b2e202SAlex Deucher 	u16 t_med;
151897b2e202SAlex Deucher 	u16 t_high;
151997b2e202SAlex Deucher 	u16 pwm_min;
152097b2e202SAlex Deucher 	u16 pwm_med;
152197b2e202SAlex Deucher 	u16 pwm_high;
152297b2e202SAlex Deucher 	u8 t_hyst;
152397b2e202SAlex Deucher 	u32 cycle_delay;
152497b2e202SAlex Deucher 	u16 t_max;
152597b2e202SAlex Deucher 	u8 control_mode;
152697b2e202SAlex Deucher 	u16 default_max_fan_pwm;
152797b2e202SAlex Deucher 	u16 default_fan_output_sensitivity;
152897b2e202SAlex Deucher 	u16 fan_output_sensitivity;
152997b2e202SAlex Deucher 	bool ucode_fan_control;
153097b2e202SAlex Deucher };
153197b2e202SAlex Deucher 
153297b2e202SAlex Deucher enum amdgpu_pcie_gen {
153397b2e202SAlex Deucher 	AMDGPU_PCIE_GEN1 = 0,
153497b2e202SAlex Deucher 	AMDGPU_PCIE_GEN2 = 1,
153597b2e202SAlex Deucher 	AMDGPU_PCIE_GEN3 = 2,
153697b2e202SAlex Deucher 	AMDGPU_PCIE_GEN_INVALID = 0xffff
153797b2e202SAlex Deucher };
153897b2e202SAlex Deucher 
153997b2e202SAlex Deucher enum amdgpu_dpm_forced_level {
154097b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
154197b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
154297b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
1543f3898ea1SEric Huang 	AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
154497b2e202SAlex Deucher };
154597b2e202SAlex Deucher 
154697b2e202SAlex Deucher struct amdgpu_vce_state {
154797b2e202SAlex Deucher 	/* vce clocks */
154897b2e202SAlex Deucher 	u32 evclk;
154997b2e202SAlex Deucher 	u32 ecclk;
155097b2e202SAlex Deucher 	/* gpu clocks */
155197b2e202SAlex Deucher 	u32 sclk;
155297b2e202SAlex Deucher 	u32 mclk;
155397b2e202SAlex Deucher 	u8 clk_idx;
155497b2e202SAlex Deucher 	u8 pstate;
155597b2e202SAlex Deucher };
155697b2e202SAlex Deucher 
155797b2e202SAlex Deucher struct amdgpu_dpm_funcs {
155897b2e202SAlex Deucher 	int (*get_temperature)(struct amdgpu_device *adev);
155997b2e202SAlex Deucher 	int (*pre_set_power_state)(struct amdgpu_device *adev);
156097b2e202SAlex Deucher 	int (*set_power_state)(struct amdgpu_device *adev);
156197b2e202SAlex Deucher 	void (*post_set_power_state)(struct amdgpu_device *adev);
156297b2e202SAlex Deucher 	void (*display_configuration_changed)(struct amdgpu_device *adev);
156397b2e202SAlex Deucher 	u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
156497b2e202SAlex Deucher 	u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
156597b2e202SAlex Deucher 	void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
156697b2e202SAlex Deucher 	void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
156797b2e202SAlex Deucher 	int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
156897b2e202SAlex Deucher 	bool (*vblank_too_short)(struct amdgpu_device *adev);
156997b2e202SAlex Deucher 	void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
1570b7a07769SSonny Jiang 	void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
157197b2e202SAlex Deucher 	void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
157297b2e202SAlex Deucher 	void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
157397b2e202SAlex Deucher 	u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
157497b2e202SAlex Deucher 	int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
157597b2e202SAlex Deucher 	int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1576c85e299fSEric Huang 	int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1577c85e299fSEric Huang 	int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
15788b2e574dSEric Huang 	int (*get_sclk_od)(struct amdgpu_device *adev);
15798b2e574dSEric Huang 	int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
1580f2bdc05fSEric Huang 	int (*get_mclk_od)(struct amdgpu_device *adev);
1581f2bdc05fSEric Huang 	int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
158297b2e202SAlex Deucher };
158397b2e202SAlex Deucher 
158497b2e202SAlex Deucher struct amdgpu_dpm {
158597b2e202SAlex Deucher 	struct amdgpu_ps        *ps;
158697b2e202SAlex Deucher 	/* number of valid power states */
158797b2e202SAlex Deucher 	int                     num_ps;
158897b2e202SAlex Deucher 	/* current power state that is active */
158997b2e202SAlex Deucher 	struct amdgpu_ps        *current_ps;
159097b2e202SAlex Deucher 	/* requested power state */
159197b2e202SAlex Deucher 	struct amdgpu_ps        *requested_ps;
159297b2e202SAlex Deucher 	/* boot up power state */
159397b2e202SAlex Deucher 	struct amdgpu_ps        *boot_ps;
159497b2e202SAlex Deucher 	/* default uvd power state */
159597b2e202SAlex Deucher 	struct amdgpu_ps        *uvd_ps;
159697b2e202SAlex Deucher 	/* vce requirements */
159797b2e202SAlex Deucher 	struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
159897b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
15993a2c788dSRex Zhu 	enum amd_pm_state_type state;
16003a2c788dSRex Zhu 	enum amd_pm_state_type user_state;
160197b2e202SAlex Deucher 	u32                     platform_caps;
160297b2e202SAlex Deucher 	u32                     voltage_response_time;
160397b2e202SAlex Deucher 	u32                     backbias_response_time;
160497b2e202SAlex Deucher 	void                    *priv;
160597b2e202SAlex Deucher 	u32			new_active_crtcs;
160697b2e202SAlex Deucher 	int			new_active_crtc_count;
160797b2e202SAlex Deucher 	u32			current_active_crtcs;
160897b2e202SAlex Deucher 	int			current_active_crtc_count;
160997b2e202SAlex Deucher 	struct amdgpu_dpm_dynamic_state dyn_state;
161097b2e202SAlex Deucher 	struct amdgpu_dpm_fan fan;
161197b2e202SAlex Deucher 	u32 tdp_limit;
161297b2e202SAlex Deucher 	u32 near_tdp_limit;
161397b2e202SAlex Deucher 	u32 near_tdp_limit_adjusted;
161497b2e202SAlex Deucher 	u32 sq_ramping_threshold;
161597b2e202SAlex Deucher 	u32 cac_leakage;
161697b2e202SAlex Deucher 	u16 tdp_od_limit;
161797b2e202SAlex Deucher 	u32 tdp_adjustment;
161897b2e202SAlex Deucher 	u16 load_line_slope;
161997b2e202SAlex Deucher 	bool power_control;
162097b2e202SAlex Deucher 	bool ac_power;
162197b2e202SAlex Deucher 	/* special states active */
162297b2e202SAlex Deucher 	bool                    thermal_active;
162397b2e202SAlex Deucher 	bool                    uvd_active;
162497b2e202SAlex Deucher 	bool                    vce_active;
162597b2e202SAlex Deucher 	/* thermal handling */
162697b2e202SAlex Deucher 	struct amdgpu_dpm_thermal thermal;
162797b2e202SAlex Deucher 	/* forced levels */
162897b2e202SAlex Deucher 	enum amdgpu_dpm_forced_level forced_level;
162997b2e202SAlex Deucher };
163097b2e202SAlex Deucher 
163197b2e202SAlex Deucher struct amdgpu_pm {
163297b2e202SAlex Deucher 	struct mutex		mutex;
163397b2e202SAlex Deucher 	u32                     current_sclk;
163497b2e202SAlex Deucher 	u32                     current_mclk;
163597b2e202SAlex Deucher 	u32                     default_sclk;
163697b2e202SAlex Deucher 	u32                     default_mclk;
163797b2e202SAlex Deucher 	struct amdgpu_i2c_chan *i2c_bus;
163897b2e202SAlex Deucher 	/* internal thermal controller on rv6xx+ */
163997b2e202SAlex Deucher 	enum amdgpu_int_thermal_type int_thermal_type;
164097b2e202SAlex Deucher 	struct device	        *int_hwmon_dev;
164197b2e202SAlex Deucher 	/* fan control parameters */
164297b2e202SAlex Deucher 	bool                    no_fan;
164397b2e202SAlex Deucher 	u8                      fan_pulses_per_revolution;
164497b2e202SAlex Deucher 	u8                      fan_min_rpm;
164597b2e202SAlex Deucher 	u8                      fan_max_rpm;
164697b2e202SAlex Deucher 	/* dpm */
164797b2e202SAlex Deucher 	bool                    dpm_enabled;
1648c86f5ebfSAlex Deucher 	bool                    sysfs_initialized;
164997b2e202SAlex Deucher 	struct amdgpu_dpm       dpm;
165097b2e202SAlex Deucher 	const struct firmware	*fw;	/* SMC firmware */
165197b2e202SAlex Deucher 	uint32_t                fw_version;
165297b2e202SAlex Deucher 	const struct amdgpu_dpm_funcs *funcs;
1653d0dd7f0cSAlex Deucher 	uint32_t                pcie_gen_mask;
1654d0dd7f0cSAlex Deucher 	uint32_t                pcie_mlw_mask;
16557fb72a1fSRex Zhu 	struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
165697b2e202SAlex Deucher };
165797b2e202SAlex Deucher 
1658d0dd7f0cSAlex Deucher void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1659d0dd7f0cSAlex Deucher 
166097b2e202SAlex Deucher /*
166197b2e202SAlex Deucher  * UVD
166297b2e202SAlex Deucher  */
1663c0365541SArindam Nath #define AMDGPU_DEFAULT_UVD_HANDLES	10
1664c0365541SArindam Nath #define AMDGPU_MAX_UVD_HANDLES		40
1665c0365541SArindam Nath #define AMDGPU_UVD_STACK_SIZE		(200*1024)
1666c0365541SArindam Nath #define AMDGPU_UVD_HEAP_SIZE		(256*1024)
1667c0365541SArindam Nath #define AMDGPU_UVD_SESSION_SIZE		(50*1024)
166897b2e202SAlex Deucher #define AMDGPU_UVD_FIRMWARE_OFFSET	256
166997b2e202SAlex Deucher 
167097b2e202SAlex Deucher struct amdgpu_uvd {
167197b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
167297b2e202SAlex Deucher 	void			*cpu_addr;
167397b2e202SAlex Deucher 	uint64_t		gpu_addr;
1674562e2689SSonny Jiang 	unsigned		fw_version;
16753f99dd81SLeo Liu 	void			*saved_bo;
1676c0365541SArindam Nath 	unsigned		max_handles;
167797b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_UVD_HANDLES];
167897b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_UVD_HANDLES];
167997b2e202SAlex Deucher 	struct delayed_work	idle_work;
168097b2e202SAlex Deucher 	const struct firmware	*fw;	/* UVD firmware */
168197b2e202SAlex Deucher 	struct amdgpu_ring	ring;
168297b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
168397b2e202SAlex Deucher 	bool			address_64_bit;
16844cb5877cSChristian König 	bool			use_ctx_buf;
1685ead833ecSChristian König 	struct amd_sched_entity entity;
168697b2e202SAlex Deucher };
168797b2e202SAlex Deucher 
168897b2e202SAlex Deucher /*
168997b2e202SAlex Deucher  * VCE
169097b2e202SAlex Deucher  */
169197b2e202SAlex Deucher #define AMDGPU_MAX_VCE_HANDLES	16
169297b2e202SAlex Deucher #define AMDGPU_VCE_FIRMWARE_OFFSET 256
169397b2e202SAlex Deucher 
16946a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
16956a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
16966a585777SAlex Deucher 
169797b2e202SAlex Deucher struct amdgpu_vce {
169897b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
169997b2e202SAlex Deucher 	uint64_t		gpu_addr;
170097b2e202SAlex Deucher 	unsigned		fw_version;
170197b2e202SAlex Deucher 	unsigned		fb_version;
170297b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
170397b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_VCE_HANDLES];
1704f1689ec1SChristian König 	uint32_t		img_size[AMDGPU_MAX_VCE_HANDLES];
170597b2e202SAlex Deucher 	struct delayed_work	idle_work;
1706ebff485eSChristian König 	struct mutex		idle_mutex;
170797b2e202SAlex Deucher 	const struct firmware	*fw;	/* VCE firmware */
170897b2e202SAlex Deucher 	struct amdgpu_ring	ring[AMDGPU_MAX_VCE_RINGS];
170997b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
17106a585777SAlex Deucher 	unsigned		harvest_config;
1711c594989cSChristian König 	struct amd_sched_entity	entity;
171297b2e202SAlex Deucher };
171397b2e202SAlex Deucher 
171497b2e202SAlex Deucher /*
171597b2e202SAlex Deucher  * SDMA
171697b2e202SAlex Deucher  */
1717c113ea1cSAlex Deucher struct amdgpu_sdma_instance {
171897b2e202SAlex Deucher 	/* SDMA firmware */
171997b2e202SAlex Deucher 	const struct firmware	*fw;
172097b2e202SAlex Deucher 	uint32_t		fw_version;
1721cfa2104fSJammy Zhou 	uint32_t		feature_version;
172297b2e202SAlex Deucher 
172397b2e202SAlex Deucher 	struct amdgpu_ring	ring;
172418111de0SJammy Zhou 	bool			burst_nop;
172597b2e202SAlex Deucher };
172697b2e202SAlex Deucher 
1727c113ea1cSAlex Deucher struct amdgpu_sdma {
1728c113ea1cSAlex Deucher 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1729c113ea1cSAlex Deucher 	struct amdgpu_irq_src	trap_irq;
1730c113ea1cSAlex Deucher 	struct amdgpu_irq_src	illegal_inst_irq;
1731c113ea1cSAlex Deucher 	int			num_instances;
1732c113ea1cSAlex Deucher };
1733c113ea1cSAlex Deucher 
173497b2e202SAlex Deucher /*
173597b2e202SAlex Deucher  * Firmware
173697b2e202SAlex Deucher  */
173797b2e202SAlex Deucher struct amdgpu_firmware {
173897b2e202SAlex Deucher 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
173997b2e202SAlex Deucher 	bool smu_load;
174097b2e202SAlex Deucher 	struct amdgpu_bo *fw_buf;
174197b2e202SAlex Deucher 	unsigned int fw_size;
174297b2e202SAlex Deucher };
174397b2e202SAlex Deucher 
174497b2e202SAlex Deucher /*
174597b2e202SAlex Deucher  * Benchmarking
174697b2e202SAlex Deucher  */
174797b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
174897b2e202SAlex Deucher 
174997b2e202SAlex Deucher 
175097b2e202SAlex Deucher /*
175197b2e202SAlex Deucher  * Testing
175297b2e202SAlex Deucher  */
175397b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
175497b2e202SAlex Deucher void amdgpu_test_ring_sync(struct amdgpu_device *adev,
175597b2e202SAlex Deucher 			   struct amdgpu_ring *cpA,
175697b2e202SAlex Deucher 			   struct amdgpu_ring *cpB);
175797b2e202SAlex Deucher void amdgpu_test_syncing(struct amdgpu_device *adev);
175897b2e202SAlex Deucher 
175997b2e202SAlex Deucher /*
176097b2e202SAlex Deucher  * MMU Notifier
176197b2e202SAlex Deucher  */
176297b2e202SAlex Deucher #if defined(CONFIG_MMU_NOTIFIER)
176397b2e202SAlex Deucher int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
176497b2e202SAlex Deucher void amdgpu_mn_unregister(struct amdgpu_bo *bo);
176597b2e202SAlex Deucher #else
17661d1106b0SHarry Wentland static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
176797b2e202SAlex Deucher {
176897b2e202SAlex Deucher 	return -ENODEV;
176997b2e202SAlex Deucher }
17701d1106b0SHarry Wentland static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
177197b2e202SAlex Deucher #endif
177297b2e202SAlex Deucher 
177397b2e202SAlex Deucher /*
177497b2e202SAlex Deucher  * Debugfs
177597b2e202SAlex Deucher  */
177697b2e202SAlex Deucher struct amdgpu_debugfs {
177706ab6832SNils Wallménius 	const struct drm_info_list	*files;
177897b2e202SAlex Deucher 	unsigned		num_files;
177997b2e202SAlex Deucher };
178097b2e202SAlex Deucher 
178197b2e202SAlex Deucher int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
178206ab6832SNils Wallménius 			     const struct drm_info_list *files,
178397b2e202SAlex Deucher 			     unsigned nfiles);
178497b2e202SAlex Deucher int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
178597b2e202SAlex Deucher 
178697b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
178797b2e202SAlex Deucher int amdgpu_debugfs_init(struct drm_minor *minor);
178897b2e202SAlex Deucher void amdgpu_debugfs_cleanup(struct drm_minor *minor);
178997b2e202SAlex Deucher #endif
179097b2e202SAlex Deucher 
179150ab2533SHuang Rui int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
179250ab2533SHuang Rui 
179397b2e202SAlex Deucher /*
179497b2e202SAlex Deucher  * amdgpu smumgr functions
179597b2e202SAlex Deucher  */
179697b2e202SAlex Deucher struct amdgpu_smumgr_funcs {
179797b2e202SAlex Deucher 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
179897b2e202SAlex Deucher 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
179997b2e202SAlex Deucher 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
180097b2e202SAlex Deucher };
180197b2e202SAlex Deucher 
180297b2e202SAlex Deucher /*
180397b2e202SAlex Deucher  * amdgpu smumgr
180497b2e202SAlex Deucher  */
180597b2e202SAlex Deucher struct amdgpu_smumgr {
180697b2e202SAlex Deucher 	struct amdgpu_bo *toc_buf;
180797b2e202SAlex Deucher 	struct amdgpu_bo *smu_buf;
180897b2e202SAlex Deucher 	/* asic priv smu data */
180997b2e202SAlex Deucher 	void *priv;
181097b2e202SAlex Deucher 	spinlock_t smu_lock;
181197b2e202SAlex Deucher 	/* smumgr functions */
181297b2e202SAlex Deucher 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
181397b2e202SAlex Deucher 	/* ucode loading complete flag */
181497b2e202SAlex Deucher 	uint32_t fw_flags;
181597b2e202SAlex Deucher };
181697b2e202SAlex Deucher 
181797b2e202SAlex Deucher /*
181897b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
181997b2e202SAlex Deucher  */
182097b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
182197b2e202SAlex Deucher 	uint32_t reg_offset;
182297b2e202SAlex Deucher 	bool untouched;
182397b2e202SAlex Deucher 	bool grbm_indexed;
182497b2e202SAlex Deucher };
182597b2e202SAlex Deucher 
182697b2e202SAlex Deucher /*
182797b2e202SAlex Deucher  * ASIC specific functions.
182897b2e202SAlex Deucher  */
182997b2e202SAlex Deucher struct amdgpu_asic_funcs {
183097b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
18317946b878SAlex Deucher 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
18327946b878SAlex Deucher 				   u8 *bios, u32 length_bytes);
183397b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
183497b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
183597b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
183697b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
183797b2e202SAlex Deucher 	/* get the reference clock */
183897b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
183997b2e202SAlex Deucher 	/* MM block clocks */
184097b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
184197b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1842048765adSAndres Rodriguez 	/* query virtual capabilities */
1843048765adSAndres Rodriguez 	u32 (*get_virtual_caps)(struct amdgpu_device *adev);
184497b2e202SAlex Deucher };
184597b2e202SAlex Deucher 
184697b2e202SAlex Deucher /*
184797b2e202SAlex Deucher  * IOCTL.
184897b2e202SAlex Deucher  */
184997b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
185097b2e202SAlex Deucher 			    struct drm_file *filp);
185197b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
185297b2e202SAlex Deucher 				struct drm_file *filp);
185397b2e202SAlex Deucher 
185497b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
185597b2e202SAlex Deucher 			  struct drm_file *filp);
185697b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
185797b2e202SAlex Deucher 			struct drm_file *filp);
185897b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
185997b2e202SAlex Deucher 			  struct drm_file *filp);
186097b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
186197b2e202SAlex Deucher 			      struct drm_file *filp);
186297b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
186397b2e202SAlex Deucher 			  struct drm_file *filp);
186497b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
186597b2e202SAlex Deucher 			struct drm_file *filp);
186697b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
186797b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
186897b2e202SAlex Deucher 
186997b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
187097b2e202SAlex Deucher 				struct drm_file *filp);
187197b2e202SAlex Deucher 
187297b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
187397b2e202SAlex Deucher struct amdgpu_vram_scratch {
187497b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
187597b2e202SAlex Deucher 	volatile uint32_t		*ptr;
187697b2e202SAlex Deucher 	u64				gpu_addr;
187797b2e202SAlex Deucher };
187897b2e202SAlex Deucher 
187997b2e202SAlex Deucher /*
188097b2e202SAlex Deucher  * ACPI
188197b2e202SAlex Deucher  */
188297b2e202SAlex Deucher struct amdgpu_atif_notification_cfg {
188397b2e202SAlex Deucher 	bool enabled;
188497b2e202SAlex Deucher 	int command_code;
188597b2e202SAlex Deucher };
188697b2e202SAlex Deucher 
188797b2e202SAlex Deucher struct amdgpu_atif_notifications {
188897b2e202SAlex Deucher 	bool display_switch;
188997b2e202SAlex Deucher 	bool expansion_mode_change;
189097b2e202SAlex Deucher 	bool thermal_state;
189197b2e202SAlex Deucher 	bool forced_power_state;
189297b2e202SAlex Deucher 	bool system_power_state;
189397b2e202SAlex Deucher 	bool display_conf_change;
189497b2e202SAlex Deucher 	bool px_gfx_switch;
189597b2e202SAlex Deucher 	bool brightness_change;
189697b2e202SAlex Deucher 	bool dgpu_display_event;
189797b2e202SAlex Deucher };
189897b2e202SAlex Deucher 
189997b2e202SAlex Deucher struct amdgpu_atif_functions {
190097b2e202SAlex Deucher 	bool system_params;
190197b2e202SAlex Deucher 	bool sbios_requests;
190297b2e202SAlex Deucher 	bool select_active_disp;
190397b2e202SAlex Deucher 	bool lid_state;
190497b2e202SAlex Deucher 	bool get_tv_standard;
190597b2e202SAlex Deucher 	bool set_tv_standard;
190697b2e202SAlex Deucher 	bool get_panel_expansion_mode;
190797b2e202SAlex Deucher 	bool set_panel_expansion_mode;
190897b2e202SAlex Deucher 	bool temperature_change;
190997b2e202SAlex Deucher 	bool graphics_device_types;
191097b2e202SAlex Deucher };
191197b2e202SAlex Deucher 
191297b2e202SAlex Deucher struct amdgpu_atif {
191397b2e202SAlex Deucher 	struct amdgpu_atif_notifications notifications;
191497b2e202SAlex Deucher 	struct amdgpu_atif_functions functions;
191597b2e202SAlex Deucher 	struct amdgpu_atif_notification_cfg notification_cfg;
191697b2e202SAlex Deucher 	struct amdgpu_encoder *encoder_for_bl;
191797b2e202SAlex Deucher };
191897b2e202SAlex Deucher 
191997b2e202SAlex Deucher struct amdgpu_atcs_functions {
192097b2e202SAlex Deucher 	bool get_ext_state;
192197b2e202SAlex Deucher 	bool pcie_perf_req;
192297b2e202SAlex Deucher 	bool pcie_dev_rdy;
192397b2e202SAlex Deucher 	bool pcie_bus_width;
192497b2e202SAlex Deucher };
192597b2e202SAlex Deucher 
192697b2e202SAlex Deucher struct amdgpu_atcs {
192797b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
192897b2e202SAlex Deucher };
192997b2e202SAlex Deucher 
193097b2e202SAlex Deucher /*
1931d03846afSChunming Zhou  * CGS
1932d03846afSChunming Zhou  */
1933110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1934110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1935a8fe58ceSMaruthi Bayyavarapu 
1936a8fe58ceSMaruthi Bayyavarapu 
19377e471e6fSAlex Deucher /* GPU virtualization */
1938048765adSAndres Rodriguez #define AMDGPU_VIRT_CAPS_SRIOV_EN       (1 << 0)
1939048765adSAndres Rodriguez #define AMDGPU_VIRT_CAPS_IS_VF          (1 << 1)
19407e471e6fSAlex Deucher struct amdgpu_virtualization {
19417e471e6fSAlex Deucher 	bool supports_sr_iov;
1942048765adSAndres Rodriguez 	bool is_virtual;
1943048765adSAndres Rodriguez 	u32 caps;
19447e471e6fSAlex Deucher };
19457e471e6fSAlex Deucher 
1946a8fe58ceSMaruthi Bayyavarapu /*
194797b2e202SAlex Deucher  * Core structure, functions and helpers.
194897b2e202SAlex Deucher  */
194997b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
195097b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
195197b2e202SAlex Deucher 
195297b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
195397b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
195497b2e202SAlex Deucher 
19558faf0e08SAlex Deucher struct amdgpu_ip_block_status {
19568faf0e08SAlex Deucher 	bool valid;
19578faf0e08SAlex Deucher 	bool sw;
19588faf0e08SAlex Deucher 	bool hw;
195963fbf42fSChunming Zhou 	bool hang;
19608faf0e08SAlex Deucher };
19618faf0e08SAlex Deucher 
196297b2e202SAlex Deucher struct amdgpu_device {
196397b2e202SAlex Deucher 	struct device			*dev;
196497b2e202SAlex Deucher 	struct drm_device		*ddev;
196597b2e202SAlex Deucher 	struct pci_dev			*pdev;
196697b2e202SAlex Deucher 
1967a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP
1968a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_acp		acp;
1969a8fe58ceSMaruthi Bayyavarapu #endif
1970a8fe58ceSMaruthi Bayyavarapu 
197197b2e202SAlex Deucher 	/* ASIC */
19722f7d10b3SJammy Zhou 	enum amd_asic_type		asic_type;
197397b2e202SAlex Deucher 	uint32_t			family;
197497b2e202SAlex Deucher 	uint32_t			rev_id;
197597b2e202SAlex Deucher 	uint32_t			external_rev_id;
197697b2e202SAlex Deucher 	unsigned long			flags;
197797b2e202SAlex Deucher 	int				usec_timeout;
197897b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
197997b2e202SAlex Deucher 	bool				shutdown;
198097b2e202SAlex Deucher 	bool				need_dma32;
198197b2e202SAlex Deucher 	bool				accel_working;
198297b2e202SAlex Deucher 	struct work_struct		reset_work;
198397b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
198497b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
198597b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
198697b2e202SAlex Deucher 	unsigned			debugfs_count;
198797b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
1988adcec288STom St Denis 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
198997b2e202SAlex Deucher #endif
199097b2e202SAlex Deucher 	struct amdgpu_atif		atif;
199197b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
199297b2e202SAlex Deucher 	struct mutex			srbm_mutex;
199397b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
199497b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
199597b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
199697b2e202SAlex Deucher 	bool				have_disp_power_ref;
199797b2e202SAlex Deucher 
199897b2e202SAlex Deucher 	/* BIOS */
199997b2e202SAlex Deucher 	uint8_t				*bios;
200097b2e202SAlex Deucher 	bool				is_atom_bios;
200197b2e202SAlex Deucher 	struct amdgpu_bo		*stollen_vga_memory;
200297b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
200397b2e202SAlex Deucher 
200497b2e202SAlex Deucher 	/* Register/doorbell mmio */
200597b2e202SAlex Deucher 	resource_size_t			rmmio_base;
200697b2e202SAlex Deucher 	resource_size_t			rmmio_size;
200797b2e202SAlex Deucher 	void __iomem			*rmmio;
200897b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
200997b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
201097b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
201197b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
201297b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
201397b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
201497b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
201597b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
201697b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
201797b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
201897b2e202SAlex Deucher 	/* protects concurrent UVD register access */
201997b2e202SAlex Deucher 	spinlock_t uvd_ctx_idx_lock;
202097b2e202SAlex Deucher 	amdgpu_rreg_t			uvd_ctx_rreg;
202197b2e202SAlex Deucher 	amdgpu_wreg_t			uvd_ctx_wreg;
202297b2e202SAlex Deucher 	/* protects concurrent DIDT register access */
202397b2e202SAlex Deucher 	spinlock_t didt_idx_lock;
202497b2e202SAlex Deucher 	amdgpu_rreg_t			didt_rreg;
202597b2e202SAlex Deucher 	amdgpu_wreg_t			didt_wreg;
2026ccdbb20aSRex Zhu 	/* protects concurrent gc_cac register access */
2027ccdbb20aSRex Zhu 	spinlock_t gc_cac_idx_lock;
2028ccdbb20aSRex Zhu 	amdgpu_rreg_t			gc_cac_rreg;
2029ccdbb20aSRex Zhu 	amdgpu_wreg_t			gc_cac_wreg;
203097b2e202SAlex Deucher 	/* protects concurrent ENDPOINT (audio) register access */
203197b2e202SAlex Deucher 	spinlock_t audio_endpt_idx_lock;
203297b2e202SAlex Deucher 	amdgpu_block_rreg_t		audio_endpt_rreg;
203397b2e202SAlex Deucher 	amdgpu_block_wreg_t		audio_endpt_wreg;
203497b2e202SAlex Deucher 	void __iomem                    *rio_mem;
203597b2e202SAlex Deucher 	resource_size_t			rio_mem_size;
203697b2e202SAlex Deucher 	struct amdgpu_doorbell		doorbell;
203797b2e202SAlex Deucher 
203897b2e202SAlex Deucher 	/* clock/pll info */
203997b2e202SAlex Deucher 	struct amdgpu_clock            clock;
204097b2e202SAlex Deucher 
204197b2e202SAlex Deucher 	/* MC */
204297b2e202SAlex Deucher 	struct amdgpu_mc		mc;
204397b2e202SAlex Deucher 	struct amdgpu_gart		gart;
204497b2e202SAlex Deucher 	struct amdgpu_dummy_page	dummy_page;
204597b2e202SAlex Deucher 	struct amdgpu_vm_manager	vm_manager;
204697b2e202SAlex Deucher 
204797b2e202SAlex Deucher 	/* memory management */
204897b2e202SAlex Deucher 	struct amdgpu_mman		mman;
204997b2e202SAlex Deucher 	struct amdgpu_vram_scratch	vram_scratch;
205097b2e202SAlex Deucher 	struct amdgpu_wb		wb;
205197b2e202SAlex Deucher 	atomic64_t			vram_usage;
205297b2e202SAlex Deucher 	atomic64_t			vram_vis_usage;
205397b2e202SAlex Deucher 	atomic64_t			gtt_usage;
205497b2e202SAlex Deucher 	atomic64_t			num_bytes_moved;
2055dbd5ed60SChristian König 	atomic64_t			num_evictions;
2056d94aed5aSMarek Olšák 	atomic_t			gpu_reset_counter;
205797b2e202SAlex Deucher 
205897b2e202SAlex Deucher 	/* display */
205997b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
206097b2e202SAlex Deucher 	struct work_struct		hotplug_work;
206197b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
206297b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
206397b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
206497b2e202SAlex Deucher 
206597b2e202SAlex Deucher 	/* rings */
206676bf0db5SChristian König 	u64				fence_context;
206797b2e202SAlex Deucher 	unsigned			num_rings;
206897b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
206997b2e202SAlex Deucher 	bool				ib_pool_ready;
207097b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
207197b2e202SAlex Deucher 
207297b2e202SAlex Deucher 	/* interrupts */
207397b2e202SAlex Deucher 	struct amdgpu_irq		irq;
207497b2e202SAlex Deucher 
20751f7371b2SAlex Deucher 	/* powerplay */
20761f7371b2SAlex Deucher 	struct amd_powerplay		powerplay;
2077e61710c5SJammy Zhou 	bool				pp_enabled;
2078f3898ea1SEric Huang 	bool				pp_force_state_enabled;
20791f7371b2SAlex Deucher 
208097b2e202SAlex Deucher 	/* dpm */
208197b2e202SAlex Deucher 	struct amdgpu_pm		pm;
208297b2e202SAlex Deucher 	u32				cg_flags;
208397b2e202SAlex Deucher 	u32				pg_flags;
208497b2e202SAlex Deucher 
208597b2e202SAlex Deucher 	/* amdgpu smumgr */
208697b2e202SAlex Deucher 	struct amdgpu_smumgr smu;
208797b2e202SAlex Deucher 
208897b2e202SAlex Deucher 	/* gfx */
208997b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
209097b2e202SAlex Deucher 
209197b2e202SAlex Deucher 	/* sdma */
2092c113ea1cSAlex Deucher 	struct amdgpu_sdma		sdma;
209397b2e202SAlex Deucher 
209497b2e202SAlex Deucher 	/* uvd */
209597b2e202SAlex Deucher 	struct amdgpu_uvd		uvd;
209697b2e202SAlex Deucher 
209797b2e202SAlex Deucher 	/* vce */
209897b2e202SAlex Deucher 	struct amdgpu_vce		vce;
209997b2e202SAlex Deucher 
210097b2e202SAlex Deucher 	/* firmwares */
210197b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
210297b2e202SAlex Deucher 
210397b2e202SAlex Deucher 	/* GDS */
210497b2e202SAlex Deucher 	struct amdgpu_gds		gds;
210597b2e202SAlex Deucher 
210697b2e202SAlex Deucher 	const struct amdgpu_ip_block_version *ip_blocks;
210797b2e202SAlex Deucher 	int				num_ip_blocks;
21088faf0e08SAlex Deucher 	struct amdgpu_ip_block_status	*ip_block_status;
210997b2e202SAlex Deucher 	struct mutex	mn_lock;
211097b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
211197b2e202SAlex Deucher 
211297b2e202SAlex Deucher 	/* tracking pinned memory */
211397b2e202SAlex Deucher 	u64 vram_pin_size;
2114e131b914SChunming Zhou 	u64 invisible_pin_size;
211597b2e202SAlex Deucher 	u64 gart_pin_size;
2116130e0371SOded Gabbay 
2117130e0371SOded Gabbay 	/* amdkfd interface */
2118130e0371SOded Gabbay 	struct kfd_dev          *kfd;
211923ca0e4eSChunming Zhou 
21207e471e6fSAlex Deucher 	struct amdgpu_virtualization virtualization;
212197b2e202SAlex Deucher };
212297b2e202SAlex Deucher 
212397b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
212497b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
212597b2e202SAlex Deucher 		       struct drm_device *ddev,
212697b2e202SAlex Deucher 		       struct pci_dev *pdev,
212797b2e202SAlex Deucher 		       uint32_t flags);
212897b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
212997b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
213097b2e202SAlex Deucher 
213197b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
213297b2e202SAlex Deucher 			bool always_indirect);
213397b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
213497b2e202SAlex Deucher 		    bool always_indirect);
213597b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
213697b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
213797b2e202SAlex Deucher 
213897b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
213997b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
214097b2e202SAlex Deucher 
214197b2e202SAlex Deucher /*
214297b2e202SAlex Deucher  * Registers read & write functions.
214397b2e202SAlex Deucher  */
214497b2e202SAlex Deucher #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
214597b2e202SAlex Deucher #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
214697b2e202SAlex Deucher #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
214797b2e202SAlex Deucher #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
214897b2e202SAlex Deucher #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
214997b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
215097b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
215197b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
215297b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
215397b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
215497b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
215597b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
215697b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
215797b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
215897b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2159ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
2160ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
216197b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
216297b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
216397b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
216497b2e202SAlex Deucher 	do {							\
216597b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
216697b2e202SAlex Deucher 		tmp_ &= (mask);					\
216797b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
216897b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
216997b2e202SAlex Deucher 	} while (0)
217097b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
217197b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
217297b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
217397b2e202SAlex Deucher 	do {							\
217497b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
217597b2e202SAlex Deucher 		tmp_ &= (mask);					\
217697b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
217797b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
217897b2e202SAlex Deucher 	} while (0)
217997b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
218097b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
218197b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
218297b2e202SAlex Deucher 
218397b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
218497b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
218597b2e202SAlex Deucher 
218697b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
218797b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
218897b2e202SAlex Deucher 
218997b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
219097b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
219197b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
219297b2e202SAlex Deucher 
219397b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
219497b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
219597b2e202SAlex Deucher 
219697b2e202SAlex Deucher /*
219797b2e202SAlex Deucher  * BIOS helpers.
219897b2e202SAlex Deucher  */
219997b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
220097b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
220197b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
220297b2e202SAlex Deucher 
220397b2e202SAlex Deucher /*
220497b2e202SAlex Deucher  * RING helpers.
220597b2e202SAlex Deucher  */
220697b2e202SAlex Deucher static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
220797b2e202SAlex Deucher {
220897b2e202SAlex Deucher 	if (ring->count_dw <= 0)
220986c2b790SJammy Zhou 		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
221097b2e202SAlex Deucher 	ring->ring[ring->wptr++] = v;
221197b2e202SAlex Deucher 	ring->wptr &= ring->ptr_mask;
221297b2e202SAlex Deucher 	ring->count_dw--;
221397b2e202SAlex Deucher }
221497b2e202SAlex Deucher 
2215c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance *
2216c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
22174b2f7e2cSJammy Zhou {
22184b2f7e2cSJammy Zhou 	struct amdgpu_device *adev = ring->adev;
22194b2f7e2cSJammy Zhou 	int i;
22204b2f7e2cSJammy Zhou 
2221c113ea1cSAlex Deucher 	for (i = 0; i < adev->sdma.num_instances; i++)
2222c113ea1cSAlex Deucher 		if (&adev->sdma.instance[i].ring == ring)
22234b2f7e2cSJammy Zhou 			break;
22244b2f7e2cSJammy Zhou 
22254b2f7e2cSJammy Zhou 	if (i < AMDGPU_MAX_SDMA_INSTANCES)
2226c113ea1cSAlex Deucher 		return &adev->sdma.instance[i];
22274b2f7e2cSJammy Zhou 	else
22284b2f7e2cSJammy Zhou 		return NULL;
22294b2f7e2cSJammy Zhou }
22304b2f7e2cSJammy Zhou 
223197b2e202SAlex Deucher /*
223297b2e202SAlex Deucher  * ASICs macro.
223397b2e202SAlex Deucher  */
223497b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
223597b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
223697b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
223797b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
223897b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2239048765adSAndres Rodriguez #define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
224097b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
22417946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
224297b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
224397b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
224497b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
224597b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
2246b07c9d2aSChristian König #define amdgpu_vm_write_pte(adev, ib, pa, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pa), (pe), (addr), (count), (incr), (flags)))
224797b2e202SAlex 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)))
224897b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
224997b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2250bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
225197b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
225297b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
225397b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2254d88bf583SChristian König #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
2255b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
225697b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
2257890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
225897b2e202SAlex 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))
2259d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
226011afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
22619e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
226203ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
226303ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
226497b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
226597b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
226697b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
226797b2e202SAlex Deucher #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
226897b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
226997b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
227097b2e202SAlex Deucher #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
227197b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
227297b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
227397b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
227497b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
227597b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
227697b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2277cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
227897b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
227997b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
228097b2e202SAlex 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))
228197b2e202SAlex Deucher #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
228297b2e202SAlex Deucher #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
2283c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b))
22846e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
228597b2e202SAlex Deucher #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
228697b2e202SAlex Deucher #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
228797b2e202SAlex Deucher #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
228897b2e202SAlex Deucher #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
228997b2e202SAlex Deucher #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
229097b2e202SAlex Deucher #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
229197b2e202SAlex Deucher #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
2292b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
22939559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
22943af76f23SRex Zhu 
22953af76f23SRex Zhu #define amdgpu_dpm_get_temperature(adev) \
22964b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22973af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
22984b5ece24SEric Huang 	      (adev)->pm.funcs->get_temperature((adev)))
22993af76f23SRex Zhu 
23003af76f23SRex Zhu #define amdgpu_dpm_set_fan_control_mode(adev, m) \
23014b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23023af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
23034b5ece24SEric Huang 	      (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
23043af76f23SRex Zhu 
23053af76f23SRex Zhu #define amdgpu_dpm_get_fan_control_mode(adev) \
23064b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23073af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
23084b5ece24SEric Huang 	      (adev)->pm.funcs->get_fan_control_mode((adev)))
23093af76f23SRex Zhu 
23103af76f23SRex Zhu #define amdgpu_dpm_set_fan_speed_percent(adev, s) \
23114b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23123af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
23134b5ece24SEric Huang 	      (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
23143af76f23SRex Zhu 
23153af76f23SRex Zhu #define amdgpu_dpm_get_fan_speed_percent(adev, s) \
23164b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23173af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
23184b5ece24SEric Huang 	      (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
231997b2e202SAlex Deucher 
23201b5708ffSRex Zhu #define amdgpu_dpm_get_sclk(adev, l) \
23214b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23221b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
23234b5ece24SEric Huang 		(adev)->pm.funcs->get_sclk((adev), (l)))
23241b5708ffSRex Zhu 
23251b5708ffSRex Zhu #define amdgpu_dpm_get_mclk(adev, l)  \
23264b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23271b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
23284b5ece24SEric Huang 	      (adev)->pm.funcs->get_mclk((adev), (l)))
23291b5708ffSRex Zhu 
23301b5708ffSRex Zhu 
23311b5708ffSRex Zhu #define amdgpu_dpm_force_performance_level(adev, l) \
23324b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23331b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
23344b5ece24SEric Huang 	      (adev)->pm.funcs->force_performance_level((adev), (l)))
23351b5708ffSRex Zhu 
23361b5708ffSRex Zhu #define amdgpu_dpm_powergate_uvd(adev, g) \
23374b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23381b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
23394b5ece24SEric Huang 	      (adev)->pm.funcs->powergate_uvd((adev), (g)))
23401b5708ffSRex Zhu 
23411b5708ffSRex Zhu #define amdgpu_dpm_powergate_vce(adev, g) \
23424b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23431b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
23444b5ece24SEric Huang 	      (adev)->pm.funcs->powergate_vce((adev), (g)))
23451b5708ffSRex Zhu 
23461b5708ffSRex Zhu #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
23474b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23481b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
23494b5ece24SEric Huang 	      (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
23501b5708ffSRex Zhu 
23511b5708ffSRex Zhu #define amdgpu_dpm_get_current_power_state(adev) \
23521b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
23531b5708ffSRex Zhu 
23541b5708ffSRex Zhu #define amdgpu_dpm_get_performance_level(adev) \
23551b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
23561b5708ffSRex Zhu 
2357f3898ea1SEric Huang #define amdgpu_dpm_get_pp_num_states(adev, data) \
2358f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2359f3898ea1SEric Huang 
2360f3898ea1SEric Huang #define amdgpu_dpm_get_pp_table(adev, table) \
2361f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2362f3898ea1SEric Huang 
2363f3898ea1SEric Huang #define amdgpu_dpm_set_pp_table(adev, buf, size) \
2364f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2365f3898ea1SEric Huang 
2366f3898ea1SEric Huang #define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2367f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2368f3898ea1SEric Huang 
2369f3898ea1SEric Huang #define amdgpu_dpm_force_clock_level(adev, type, level) \
2370f3898ea1SEric Huang 		(adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2371f3898ea1SEric Huang 
2372428bafa8SEric Huang #define amdgpu_dpm_get_sclk_od(adev) \
2373428bafa8SEric Huang 	(adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2374428bafa8SEric Huang 
2375428bafa8SEric Huang #define amdgpu_dpm_set_sclk_od(adev, value) \
2376428bafa8SEric Huang 	(adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2377428bafa8SEric Huang 
2378f2bdc05fSEric Huang #define amdgpu_dpm_get_mclk_od(adev) \
2379f2bdc05fSEric Huang 	((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2380f2bdc05fSEric Huang 
2381f2bdc05fSEric Huang #define amdgpu_dpm_set_mclk_od(adev, value) \
2382f2bdc05fSEric Huang 	((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2383f2bdc05fSEric Huang 
23841b5708ffSRex Zhu #define amdgpu_dpm_dispatch_task(adev, event_id, input, output)		\
23851b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
238697b2e202SAlex Deucher 
238797b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
238897b2e202SAlex Deucher 
238997b2e202SAlex Deucher /* Common functions */
239097b2e202SAlex Deucher int amdgpu_gpu_reset(struct amdgpu_device *adev);
239197b2e202SAlex Deucher void amdgpu_pci_config_reset(struct amdgpu_device *adev);
239297b2e202SAlex Deucher bool amdgpu_card_posted(struct amdgpu_device *adev);
239397b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev);
2394d5fc5e82SChunming Zhou 
239597b2e202SAlex Deucher int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
239697b2e202SAlex Deucher int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
239797b2e202SAlex Deucher 		       u32 ip_instance, u32 ring,
239897b2e202SAlex Deucher 		       struct amdgpu_ring **out_ring);
239997b2e202SAlex Deucher void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
240097b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
24012f568dbdSChristian König int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
240297b2e202SAlex Deucher int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
240397b2e202SAlex Deucher 				     uint32_t flags);
240497b2e202SAlex Deucher bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
2405cc325d19SChristian König struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
2406d7006964SChristian König bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2407d7006964SChristian König 				  unsigned long end);
24082f568dbdSChristian König bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
24092f568dbdSChristian König 				       int *last_invalidated);
241097b2e202SAlex Deucher bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
241197b2e202SAlex Deucher uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
241297b2e202SAlex Deucher 				 struct ttm_mem_reg *mem);
241397b2e202SAlex Deucher void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
241497b2e202SAlex Deucher void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
241597b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
241697b2e202SAlex Deucher void amdgpu_program_register_sequence(struct amdgpu_device *adev,
241797b2e202SAlex Deucher 					     const u32 *registers,
241897b2e202SAlex Deucher 					     const u32 array_size);
241997b2e202SAlex Deucher 
242097b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
242197b2e202SAlex Deucher /* atpx handler */
242297b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
242397b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
242497b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
2425a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void);
24262f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void);
242797b2e202SAlex Deucher #else
242897b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
242997b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
2430a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
24312f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
243297b2e202SAlex Deucher #endif
243397b2e202SAlex Deucher 
243497b2e202SAlex Deucher /*
243597b2e202SAlex Deucher  * KMS
243697b2e202SAlex Deucher  */
243797b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2438f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl;
243997b2e202SAlex Deucher 
244097b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
244197b2e202SAlex Deucher int amdgpu_driver_unload_kms(struct drm_device *dev);
244297b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
244397b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
244497b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
244597b2e202SAlex Deucher 				 struct drm_file *file_priv);
244697b2e202SAlex Deucher void amdgpu_driver_preclose_kms(struct drm_device *dev,
244797b2e202SAlex Deucher 				struct drm_file *file_priv);
244897b2e202SAlex Deucher int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
244997b2e202SAlex Deucher int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
245088e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
245188e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
245288e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
245388e72717SThierry Reding int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
245497b2e202SAlex Deucher 				    int *max_error,
245597b2e202SAlex Deucher 				    struct timeval *vblank_time,
245697b2e202SAlex Deucher 				    unsigned flags);
245797b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
245897b2e202SAlex Deucher 			     unsigned long arg);
245997b2e202SAlex Deucher 
246097b2e202SAlex Deucher /*
246197b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
246297b2e202SAlex Deucher  */
246397b2e202SAlex Deucher struct amdgpu_afmt_acr {
246497b2e202SAlex Deucher 	u32 clock;
246597b2e202SAlex Deucher 
246697b2e202SAlex Deucher 	int n_32khz;
246797b2e202SAlex Deucher 	int cts_32khz;
246897b2e202SAlex Deucher 
246997b2e202SAlex Deucher 	int n_44_1khz;
247097b2e202SAlex Deucher 	int cts_44_1khz;
247197b2e202SAlex Deucher 
247297b2e202SAlex Deucher 	int n_48khz;
247397b2e202SAlex Deucher 	int cts_48khz;
247497b2e202SAlex Deucher 
247597b2e202SAlex Deucher };
247697b2e202SAlex Deucher 
247797b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
247897b2e202SAlex Deucher 
247997b2e202SAlex Deucher /* amdgpu_acpi.c */
248097b2e202SAlex Deucher #if defined(CONFIG_ACPI)
248197b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
248297b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
248397b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
248497b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
248597b2e202SAlex Deucher 						u8 perf_req, bool advertise);
248697b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
248797b2e202SAlex Deucher #else
248897b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
248997b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
249097b2e202SAlex Deucher #endif
249197b2e202SAlex Deucher 
249297b2e202SAlex Deucher struct amdgpu_bo_va_mapping *
249397b2e202SAlex Deucher amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
249497b2e202SAlex Deucher 		       uint64_t addr, struct amdgpu_bo **bo);
249597b2e202SAlex Deucher 
249697b2e202SAlex Deucher #include "amdgpu_object.h"
249797b2e202SAlex Deucher #endif
2498