xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision 5141e9d2)
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"
54c632d799SFlora Cui #include "amdgpu_ttm.h"
5597b2e202SAlex Deucher #include "amdgpu_gds.h"
561f7371b2SAlex Deucher #include "amd_powerplay.h"
57a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h"
5897b2e202SAlex Deucher 
59b80d8475SAlex Deucher #include "gpu_scheduler.h"
60b80d8475SAlex Deucher 
6197b2e202SAlex Deucher /*
6297b2e202SAlex Deucher  * Modules parameters.
6397b2e202SAlex Deucher  */
6497b2e202SAlex Deucher extern int amdgpu_modeset;
6597b2e202SAlex Deucher extern int amdgpu_vram_limit;
6697b2e202SAlex Deucher extern int amdgpu_gart_size;
6795844d20SMarek Olšák extern int amdgpu_moverate;
6897b2e202SAlex Deucher extern int amdgpu_benchmarking;
6997b2e202SAlex Deucher extern int amdgpu_testing;
7097b2e202SAlex Deucher extern int amdgpu_audio;
7197b2e202SAlex Deucher extern int amdgpu_disp_priority;
7297b2e202SAlex Deucher extern int amdgpu_hw_i2c;
7397b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
7497b2e202SAlex Deucher extern int amdgpu_msi;
7597b2e202SAlex Deucher extern int amdgpu_lockup_timeout;
7697b2e202SAlex Deucher extern int amdgpu_dpm;
7797b2e202SAlex Deucher extern int amdgpu_smc_load_fw;
7897b2e202SAlex Deucher extern int amdgpu_aspm;
7997b2e202SAlex Deucher extern int amdgpu_runtime_pm;
8097b2e202SAlex Deucher extern unsigned amdgpu_ip_block_mask;
8197b2e202SAlex Deucher extern int amdgpu_bapm;
8297b2e202SAlex Deucher extern int amdgpu_deep_color;
8397b2e202SAlex Deucher extern int amdgpu_vm_size;
8497b2e202SAlex Deucher extern int amdgpu_vm_block_size;
85d9c13156SChristian König extern int amdgpu_vm_fault_stop;
86b495bd3aSChristian König extern int amdgpu_vm_debug;
871333f723SJammy Zhou extern int amdgpu_sched_jobs;
884afcb303SJammy Zhou extern int amdgpu_sched_hw_submission;
891f7371b2SAlex Deucher extern int amdgpu_powerplay;
906bb6b297SHuang Rui extern int amdgpu_powercontainment;
91cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_gen_cap;
92cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_lane_cap;
93395d1fb9SNicolai Hähnle extern unsigned amdgpu_cg_mask;
94395d1fb9SNicolai Hähnle extern unsigned amdgpu_pg_mask;
956f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu;
9666bc3f7fSRex Zhu extern int amdgpu_sclk_deep_sleep_en;
979accf2fdSEmily Deng extern char *amdgpu_virtual_display;
985141e9d2SRex Zhu extern unsigned amdgpu_pp_feature_mask;
9997b2e202SAlex Deucher 
1004b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
10197b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
10297b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
10397b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
10497b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
10597b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
10697b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
10797b2e202SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			8
10897b2e202SAlex Deucher 
10997b2e202SAlex Deucher /* max number of rings */
11097b2e202SAlex Deucher #define AMDGPU_MAX_RINGS			16
11197b2e202SAlex Deucher #define AMDGPU_MAX_GFX_RINGS			1
11297b2e202SAlex Deucher #define AMDGPU_MAX_COMPUTE_RINGS		8
1136f0359ffSAlex Deucher #define AMDGPU_MAX_VCE_RINGS			3
11497b2e202SAlex Deucher 
11536f523a7SJammy Zhou /* max number of IP instances */
11636f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES		2
11736f523a7SJammy Zhou 
11897b2e202SAlex Deucher /* hardcode that limit for now */
11997b2e202SAlex Deucher #define AMDGPU_VA_RESERVED_SIZE			(8 << 20)
12097b2e202SAlex Deucher 
12197b2e202SAlex Deucher /* hard reset data */
12297b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
12397b2e202SAlex Deucher 
12497b2e202SAlex Deucher /* reset flags */
12597b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
12697b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
12797b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
12897b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
12997b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
13097b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
13197b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
13297b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
13397b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
13497b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
13597b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
13697b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
13797b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
13897b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
13997b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
14097b2e202SAlex Deucher 
14197b2e202SAlex Deucher /* GFX current status */
14297b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
14397b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE			0x00000001L
14497b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
14597b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
14697b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
14797b2e202SAlex Deucher 
14897b2e202SAlex Deucher /* max cursor sizes (in pixels) */
14997b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
15097b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
15197b2e202SAlex Deucher 
15297b2e202SAlex Deucher struct amdgpu_device;
15397b2e202SAlex Deucher struct amdgpu_ib;
15497b2e202SAlex Deucher struct amdgpu_vm;
15597b2e202SAlex Deucher struct amdgpu_ring;
15697b2e202SAlex Deucher struct amdgpu_cs_parser;
157bb977d37SChunming Zhou struct amdgpu_job;
15897b2e202SAlex Deucher struct amdgpu_irq_src;
1590b492a4cSAlex Deucher struct amdgpu_fpriv;
16097b2e202SAlex Deucher 
16197b2e202SAlex Deucher enum amdgpu_cp_irq {
16297b2e202SAlex Deucher 	AMDGPU_CP_IRQ_GFX_EOP = 0,
16397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
16497b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
16597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
16697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
16797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
16897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
16997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
17097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
17197b2e202SAlex Deucher 
17297b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
17397b2e202SAlex Deucher };
17497b2e202SAlex Deucher 
17597b2e202SAlex Deucher enum amdgpu_sdma_irq {
17697b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
17797b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP1,
17897b2e202SAlex Deucher 
17997b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_LAST
18097b2e202SAlex Deucher };
18197b2e202SAlex Deucher 
18297b2e202SAlex Deucher enum amdgpu_thermal_irq {
18397b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
18497b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
18597b2e202SAlex Deucher 
18697b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
18797b2e202SAlex Deucher };
18897b2e202SAlex Deucher 
18997b2e202SAlex Deucher int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
1905fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
1915fc3aeebSyanyang1 				  enum amd_clockgating_state state);
19297b2e202SAlex Deucher int amdgpu_set_powergating_state(struct amdgpu_device *adev,
1935fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
1945fc3aeebSyanyang1 				  enum amd_powergating_state state);
1955dbbb60bSAlex Deucher int amdgpu_wait_for_idle(struct amdgpu_device *adev,
1965dbbb60bSAlex Deucher 			 enum amd_ip_block_type block_type);
1975dbbb60bSAlex Deucher bool amdgpu_is_idle(struct amdgpu_device *adev,
1985dbbb60bSAlex Deucher 		    enum amd_ip_block_type block_type);
19997b2e202SAlex Deucher 
20097b2e202SAlex Deucher struct amdgpu_ip_block_version {
2015fc3aeebSyanyang1 	enum amd_ip_block_type type;
20297b2e202SAlex Deucher 	u32 major;
20397b2e202SAlex Deucher 	u32 minor;
20497b2e202SAlex Deucher 	u32 rev;
2055fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
20697b2e202SAlex Deucher };
20797b2e202SAlex Deucher 
20897b2e202SAlex Deucher int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
2095fc3aeebSyanyang1 				enum amd_ip_block_type type,
21097b2e202SAlex Deucher 				u32 major, u32 minor);
21197b2e202SAlex Deucher 
21297b2e202SAlex Deucher const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
21397b2e202SAlex Deucher 					struct amdgpu_device *adev,
2145fc3aeebSyanyang1 					enum amd_ip_block_type type);
21597b2e202SAlex Deucher 
21697b2e202SAlex Deucher /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
21797b2e202SAlex Deucher struct amdgpu_buffer_funcs {
21897b2e202SAlex Deucher 	/* maximum bytes in a single operation */
21997b2e202SAlex Deucher 	uint32_t	copy_max_bytes;
22097b2e202SAlex Deucher 
22197b2e202SAlex Deucher 	/* number of dw to reserve per operation */
22297b2e202SAlex Deucher 	unsigned	copy_num_dw;
22397b2e202SAlex Deucher 
22497b2e202SAlex Deucher 	/* used for buffer migration */
225c7ae72c0SChunming Zhou 	void (*emit_copy_buffer)(struct amdgpu_ib *ib,
22697b2e202SAlex Deucher 				 /* src addr in bytes */
22797b2e202SAlex Deucher 				 uint64_t src_offset,
22897b2e202SAlex Deucher 				 /* dst addr in bytes */
22997b2e202SAlex Deucher 				 uint64_t dst_offset,
23097b2e202SAlex Deucher 				 /* number of byte to transfer */
23197b2e202SAlex Deucher 				 uint32_t byte_count);
23297b2e202SAlex Deucher 
23397b2e202SAlex Deucher 	/* maximum bytes in a single operation */
23497b2e202SAlex Deucher 	uint32_t	fill_max_bytes;
23597b2e202SAlex Deucher 
23697b2e202SAlex Deucher 	/* number of dw to reserve per operation */
23797b2e202SAlex Deucher 	unsigned	fill_num_dw;
23897b2e202SAlex Deucher 
23997b2e202SAlex Deucher 	/* used for buffer clearing */
2406e7a3840SChunming Zhou 	void (*emit_fill_buffer)(struct amdgpu_ib *ib,
24197b2e202SAlex Deucher 				 /* value to write to memory */
24297b2e202SAlex Deucher 				 uint32_t src_data,
24397b2e202SAlex Deucher 				 /* dst addr in bytes */
24497b2e202SAlex Deucher 				 uint64_t dst_offset,
24597b2e202SAlex Deucher 				 /* number of byte to fill */
24697b2e202SAlex Deucher 				 uint32_t byte_count);
24797b2e202SAlex Deucher };
24897b2e202SAlex Deucher 
24997b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */
25097b2e202SAlex Deucher struct amdgpu_vm_pte_funcs {
25197b2e202SAlex Deucher 	/* copy pte entries from GART */
25297b2e202SAlex Deucher 	void (*copy_pte)(struct amdgpu_ib *ib,
25397b2e202SAlex Deucher 			 uint64_t pe, uint64_t src,
25497b2e202SAlex Deucher 			 unsigned count);
25597b2e202SAlex Deucher 	/* write pte one entry at a time with addr mapping */
256de9ea7bdSChristian König 	void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
257de9ea7bdSChristian König 			  uint64_t value, unsigned count,
258de9ea7bdSChristian König 			  uint32_t incr);
25997b2e202SAlex Deucher 	/* for linear pte/pde updates without addr mapping */
26097b2e202SAlex Deucher 	void (*set_pte_pde)(struct amdgpu_ib *ib,
26197b2e202SAlex Deucher 			    uint64_t pe,
26297b2e202SAlex Deucher 			    uint64_t addr, unsigned count,
26397b2e202SAlex Deucher 			    uint32_t incr, uint32_t flags);
26497b2e202SAlex Deucher };
26597b2e202SAlex Deucher 
26697b2e202SAlex Deucher /* provided by the gmc block */
26797b2e202SAlex Deucher struct amdgpu_gart_funcs {
26897b2e202SAlex Deucher 	/* flush the vm tlb via mmio */
26997b2e202SAlex Deucher 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
27097b2e202SAlex Deucher 			      uint32_t vmid);
27197b2e202SAlex Deucher 	/* write pte/pde updates using the cpu */
27297b2e202SAlex Deucher 	int (*set_pte_pde)(struct amdgpu_device *adev,
27397b2e202SAlex Deucher 			   void *cpu_pt_addr, /* cpu addr of page table */
27497b2e202SAlex Deucher 			   uint32_t gpu_page_idx, /* pte/pde to update */
27597b2e202SAlex Deucher 			   uint64_t addr, /* addr to write into pte/pde */
27697b2e202SAlex Deucher 			   uint32_t flags); /* access flags */
27797b2e202SAlex Deucher };
27897b2e202SAlex Deucher 
27997b2e202SAlex Deucher /* provided by the ih block */
28097b2e202SAlex Deucher struct amdgpu_ih_funcs {
28197b2e202SAlex Deucher 	/* ring read/write ptr handling, called from interrupt context */
28297b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_device *adev);
28397b2e202SAlex Deucher 	void (*decode_iv)(struct amdgpu_device *adev,
28497b2e202SAlex Deucher 			  struct amdgpu_iv_entry *entry);
28597b2e202SAlex Deucher 	void (*set_rptr)(struct amdgpu_device *adev);
28697b2e202SAlex Deucher };
28797b2e202SAlex Deucher 
28897b2e202SAlex Deucher /* provided by hw blocks that expose a ring buffer for commands */
28997b2e202SAlex Deucher struct amdgpu_ring_funcs {
29097b2e202SAlex Deucher 	/* ring read/write ptr handling */
29197b2e202SAlex Deucher 	u32 (*get_rptr)(struct amdgpu_ring *ring);
29297b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_ring *ring);
29397b2e202SAlex Deucher 	void (*set_wptr)(struct amdgpu_ring *ring);
29497b2e202SAlex Deucher 	/* validating and patching of IBs */
29597b2e202SAlex Deucher 	int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
29697b2e202SAlex Deucher 	/* command emit functions */
29797b2e202SAlex Deucher 	void (*emit_ib)(struct amdgpu_ring *ring,
298d88bf583SChristian König 			struct amdgpu_ib *ib,
299d88bf583SChristian König 			unsigned vm_id, bool ctx_switch);
30097b2e202SAlex Deucher 	void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
301890ee23fSChunming Zhou 			   uint64_t seq, unsigned flags);
302b8c7b39eSChristian König 	void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
30397b2e202SAlex Deucher 	void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
30497b2e202SAlex Deucher 			      uint64_t pd_addr);
305d2edb07bSChristian König 	void (*emit_hdp_flush)(struct amdgpu_ring *ring);
30611afbde8SChunming Zhou 	void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
30797b2e202SAlex Deucher 	void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
30897b2e202SAlex Deucher 				uint32_t gds_base, uint32_t gds_size,
30997b2e202SAlex Deucher 				uint32_t gws_base, uint32_t gws_size,
31097b2e202SAlex Deucher 				uint32_t oa_base, uint32_t oa_size);
31197b2e202SAlex Deucher 	/* testing functions */
31297b2e202SAlex Deucher 	int (*test_ring)(struct amdgpu_ring *ring);
313bbec97aaSChristian König 	int (*test_ib)(struct amdgpu_ring *ring, long timeout);
314edff0e28SJammy Zhou 	/* insert NOP packets */
315edff0e28SJammy Zhou 	void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
3169e5d5309SChristian König 	/* pad the indirect buffer to the necessary number of dw */
3179e5d5309SChristian König 	void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
31803ccf481SMonk Liu 	unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
31903ccf481SMonk Liu 	void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
320f06505b8SChristian König 	/* note usage for clock and power gating */
321f06505b8SChristian König 	void (*begin_use)(struct amdgpu_ring *ring);
322f06505b8SChristian König 	void (*end_use)(struct amdgpu_ring *ring);
323c2167a65SMonk Liu 	void (*emit_switch_buffer) (struct amdgpu_ring *ring);
324753ad49cSMonk Liu 	void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
32597b2e202SAlex Deucher };
32697b2e202SAlex Deucher 
32797b2e202SAlex Deucher /*
32897b2e202SAlex Deucher  * BIOS.
32997b2e202SAlex Deucher  */
33097b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
33197b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
33297b2e202SAlex Deucher 
33397b2e202SAlex Deucher /*
33497b2e202SAlex Deucher  * Dummy page
33597b2e202SAlex Deucher  */
33697b2e202SAlex Deucher struct amdgpu_dummy_page {
33797b2e202SAlex Deucher 	struct page	*page;
33897b2e202SAlex Deucher 	dma_addr_t	addr;
33997b2e202SAlex Deucher };
34097b2e202SAlex Deucher int amdgpu_dummy_page_init(struct amdgpu_device *adev);
34197b2e202SAlex Deucher void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
34297b2e202SAlex Deucher 
34397b2e202SAlex Deucher 
34497b2e202SAlex Deucher /*
34597b2e202SAlex Deucher  * Clocks
34697b2e202SAlex Deucher  */
34797b2e202SAlex Deucher 
34897b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
34997b2e202SAlex Deucher 
35097b2e202SAlex Deucher struct amdgpu_clock {
35197b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
35297b2e202SAlex Deucher 	struct amdgpu_pll spll;
35397b2e202SAlex Deucher 	struct amdgpu_pll mpll;
35497b2e202SAlex Deucher 	/* 10 Khz units */
35597b2e202SAlex Deucher 	uint32_t default_mclk;
35697b2e202SAlex Deucher 	uint32_t default_sclk;
35797b2e202SAlex Deucher 	uint32_t default_dispclk;
35897b2e202SAlex Deucher 	uint32_t current_dispclk;
35997b2e202SAlex Deucher 	uint32_t dp_extclk;
36097b2e202SAlex Deucher 	uint32_t max_pixel_clock;
36197b2e202SAlex Deucher };
36297b2e202SAlex Deucher 
36397b2e202SAlex Deucher /*
36497b2e202SAlex Deucher  * Fences.
36597b2e202SAlex Deucher  */
36697b2e202SAlex Deucher struct amdgpu_fence_driver {
36797b2e202SAlex Deucher 	uint64_t			gpu_addr;
36897b2e202SAlex Deucher 	volatile uint32_t		*cpu_addr;
36997b2e202SAlex Deucher 	/* sync_seq is protected by ring emission lock */
370742c085fSChristian König 	uint32_t			sync_seq;
371742c085fSChristian König 	atomic_t			last_seq;
37297b2e202SAlex Deucher 	bool				initialized;
37397b2e202SAlex Deucher 	struct amdgpu_irq_src		*irq_src;
37497b2e202SAlex Deucher 	unsigned			irq_type;
375c2776afeSChristian König 	struct timer_list		fallback_timer;
376c89377d1SChristian König 	unsigned			num_fences_mask;
3774a7d74f1SChristian König 	spinlock_t			lock;
378c89377d1SChristian König 	struct fence			**fences;
37997b2e202SAlex Deucher };
38097b2e202SAlex Deucher 
38197b2e202SAlex Deucher /* some special values for the owner field */
38297b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_UNDEFINED	((void*)0ul)
38397b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_VM		((void*)1ul)
38497b2e202SAlex Deucher 
385890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_64BIT         (1 << 0)
386890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_INT           (1 << 1)
387890ee23fSChunming Zhou 
38897b2e202SAlex Deucher int amdgpu_fence_driver_init(struct amdgpu_device *adev);
38997b2e202SAlex Deucher void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
39097b2e202SAlex Deucher void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
39197b2e202SAlex Deucher 
392e6151a08SChristian König int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
393e6151a08SChristian König 				  unsigned num_hw_submission);
39497b2e202SAlex Deucher int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
39597b2e202SAlex Deucher 				   struct amdgpu_irq_src *irq_src,
39697b2e202SAlex Deucher 				   unsigned irq_type);
3975ceb54c6SAlex Deucher void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
3985ceb54c6SAlex Deucher void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
399364beb2cSChristian König int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
40097b2e202SAlex Deucher void amdgpu_fence_process(struct amdgpu_ring *ring);
40197b2e202SAlex Deucher int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
40297b2e202SAlex Deucher unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
40397b2e202SAlex Deucher 
40497b2e202SAlex Deucher /*
405c632d799SFlora Cui  * BO.
40697b2e202SAlex Deucher  */
40729b3259aSChristian König 
40897b2e202SAlex Deucher struct amdgpu_bo_list_entry {
40997b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
41097b2e202SAlex Deucher 	struct ttm_validate_buffer	tv;
41197b2e202SAlex Deucher 	struct amdgpu_bo_va		*bo_va;
41297b2e202SAlex Deucher 	uint32_t			priority;
4132f568dbdSChristian König 	struct page			**user_pages;
4142f568dbdSChristian König 	int				user_invalidated;
41597b2e202SAlex Deucher };
41697b2e202SAlex Deucher 
41797b2e202SAlex Deucher struct amdgpu_bo_va_mapping {
41897b2e202SAlex Deucher 	struct list_head		list;
41997b2e202SAlex Deucher 	struct interval_tree_node	it;
42097b2e202SAlex Deucher 	uint64_t			offset;
42197b2e202SAlex Deucher 	uint32_t			flags;
42297b2e202SAlex Deucher };
42397b2e202SAlex Deucher 
42497b2e202SAlex Deucher /* bo virtual addresses in a specific vm */
42597b2e202SAlex Deucher struct amdgpu_bo_va {
42697b2e202SAlex Deucher 	/* protected by bo being reserved */
42797b2e202SAlex Deucher 	struct list_head		bo_list;
428bb1e38a4SChunming Zhou 	struct fence		        *last_pt_update;
42997b2e202SAlex Deucher 	unsigned			ref_count;
43097b2e202SAlex Deucher 
4317fc11959SChristian König 	/* protected by vm mutex and spinlock */
43297b2e202SAlex Deucher 	struct list_head		vm_status;
43397b2e202SAlex Deucher 
4347fc11959SChristian König 	/* mappings for this bo_va */
4357fc11959SChristian König 	struct list_head		invalids;
4367fc11959SChristian König 	struct list_head		valids;
4377fc11959SChristian König 
43897b2e202SAlex Deucher 	/* constant after initialization */
43997b2e202SAlex Deucher 	struct amdgpu_vm		*vm;
44097b2e202SAlex Deucher 	struct amdgpu_bo		*bo;
44197b2e202SAlex Deucher };
44297b2e202SAlex Deucher 
4437e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX		0x3
4447e5a547fSChunming Zhou 
44597b2e202SAlex Deucher struct amdgpu_bo {
44697b2e202SAlex Deucher 	/* Protected by gem.mutex */
44797b2e202SAlex Deucher 	struct list_head		list;
44897b2e202SAlex Deucher 	/* Protected by tbo.reserved */
4491ea863fdSChristian König 	u32				prefered_domains;
4501ea863fdSChristian König 	u32				allowed_domains;
4517e5a547fSChunming Zhou 	struct ttm_place		placements[AMDGPU_GEM_DOMAIN_MAX + 1];
45297b2e202SAlex Deucher 	struct ttm_placement		placement;
45397b2e202SAlex Deucher 	struct ttm_buffer_object	tbo;
45497b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		kmap;
45597b2e202SAlex Deucher 	u64				flags;
45697b2e202SAlex Deucher 	unsigned			pin_count;
45797b2e202SAlex Deucher 	void				*kptr;
45897b2e202SAlex Deucher 	u64				tiling_flags;
45997b2e202SAlex Deucher 	u64				metadata_flags;
46097b2e202SAlex Deucher 	void				*metadata;
46197b2e202SAlex Deucher 	u32				metadata_size;
46297b2e202SAlex Deucher 	/* list of all virtual address to which this bo
46397b2e202SAlex Deucher 	 * is associated to
46497b2e202SAlex Deucher 	 */
46597b2e202SAlex Deucher 	struct list_head		va;
46697b2e202SAlex Deucher 	/* Constant after initialization */
46797b2e202SAlex Deucher 	struct amdgpu_device		*adev;
46897b2e202SAlex Deucher 	struct drm_gem_object		gem_base;
46982b9c55bSChristian König 	struct amdgpu_bo		*parent;
470e7893c4bSChunming Zhou 	struct amdgpu_bo		*shadow;
47197b2e202SAlex Deucher 
47297b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		dma_buf_vmap;
47397b2e202SAlex Deucher 	struct amdgpu_mn		*mn;
47497b2e202SAlex Deucher 	struct list_head		mn_list;
4750c4e7fa5SChunming Zhou 	struct list_head		shadow_list;
47697b2e202SAlex Deucher };
47797b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
47897b2e202SAlex Deucher 
47997b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj);
48097b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj,
48197b2e202SAlex Deucher 				struct drm_file *file_priv);
48297b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj,
48397b2e202SAlex Deucher 				struct drm_file *file_priv);
48497b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
48597b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
4864d9c514dSChristian König struct drm_gem_object *
4874d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
48897b2e202SAlex Deucher 				 struct dma_buf_attachment *attach,
48997b2e202SAlex Deucher 				 struct sg_table *sg);
49097b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
49197b2e202SAlex Deucher 					struct drm_gem_object *gobj,
49297b2e202SAlex Deucher 					int flags);
49397b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
49497b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
49597b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
49697b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
49797b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
49897b2e202SAlex Deucher int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
49997b2e202SAlex Deucher 
50097b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
50197b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
50297b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
50397b2e202SAlex Deucher  * locking.
50497b2e202SAlex Deucher  *
50597b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
50697b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
50797b2e202SAlex Deucher  * offset).
50897b2e202SAlex Deucher  *
50997b2e202SAlex Deucher  * When allocating new object we first check if there is room at
51097b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
51197b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
51297b2e202SAlex Deucher  *
51397b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
51497b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
51597b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
51697b2e202SAlex Deucher  *
51797b2e202SAlex Deucher  * Alignment can't be bigger than page size.
51897b2e202SAlex Deucher  *
51997b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
52097b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
52197b2e202SAlex Deucher  * alignment).
52297b2e202SAlex Deucher  */
5236ba60b89SChristian König 
5246ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS	32
5256ba60b89SChristian König 
52697b2e202SAlex Deucher struct amdgpu_sa_manager {
52797b2e202SAlex Deucher 	wait_queue_head_t	wq;
52897b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
52997b2e202SAlex Deucher 	struct list_head	*hole;
5306ba60b89SChristian König 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
53197b2e202SAlex Deucher 	struct list_head	olist;
53297b2e202SAlex Deucher 	unsigned		size;
53397b2e202SAlex Deucher 	uint64_t		gpu_addr;
53497b2e202SAlex Deucher 	void			*cpu_ptr;
53597b2e202SAlex Deucher 	uint32_t		domain;
53697b2e202SAlex Deucher 	uint32_t		align;
53797b2e202SAlex Deucher };
53897b2e202SAlex Deucher 
53997b2e202SAlex Deucher /* sub-allocation buffer */
54097b2e202SAlex Deucher struct amdgpu_sa_bo {
54197b2e202SAlex Deucher 	struct list_head		olist;
54297b2e202SAlex Deucher 	struct list_head		flist;
54397b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
54497b2e202SAlex Deucher 	unsigned			soffset;
54597b2e202SAlex Deucher 	unsigned			eoffset;
5464ce9891eSChunming Zhou 	struct fence		        *fence;
54797b2e202SAlex Deucher };
54897b2e202SAlex Deucher 
54997b2e202SAlex Deucher /*
55097b2e202SAlex Deucher  * GEM objects.
55197b2e202SAlex Deucher  */
552418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev);
55397b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
55497b2e202SAlex Deucher 				int alignment, u32 initial_domain,
55597b2e202SAlex Deucher 				u64 flags, bool kernel,
55697b2e202SAlex Deucher 				struct drm_gem_object **obj);
55797b2e202SAlex Deucher 
55897b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv,
55997b2e202SAlex Deucher 			    struct drm_device *dev,
56097b2e202SAlex Deucher 			    struct drm_mode_create_dumb *args);
56197b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp,
56297b2e202SAlex Deucher 			  struct drm_device *dev,
56397b2e202SAlex Deucher 			  uint32_t handle, uint64_t *offset_p);
56497b2e202SAlex Deucher /*
56597b2e202SAlex Deucher  * Synchronization
56697b2e202SAlex Deucher  */
56797b2e202SAlex Deucher struct amdgpu_sync {
568f91b3a69SChristian König 	DECLARE_HASHTABLE(fences, 4);
5693c62338cSChunming Zhou 	struct fence	        *last_vm_update;
57097b2e202SAlex Deucher };
57197b2e202SAlex Deucher 
57297b2e202SAlex Deucher void amdgpu_sync_create(struct amdgpu_sync *sync);
57391e1a520SChristian König int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
57491e1a520SChristian König 		      struct fence *f);
57597b2e202SAlex Deucher int amdgpu_sync_resv(struct amdgpu_device *adev,
57697b2e202SAlex Deucher 		     struct amdgpu_sync *sync,
57797b2e202SAlex Deucher 		     struct reservation_object *resv,
57897b2e202SAlex Deucher 		     void *owner);
5791fbb2e92SChristian König struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
58035420238SChristian König 				     struct amdgpu_ring *ring);
581e61235dbSChristian König struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
5828a8f0b48SChristian König void amdgpu_sync_free(struct amdgpu_sync *sync);
583257bf15aSChristian König int amdgpu_sync_init(void);
584257bf15aSChristian König void amdgpu_sync_fini(void);
585d573de2dSRex Zhu int amdgpu_fence_slab_init(void);
586d573de2dSRex Zhu void amdgpu_fence_slab_fini(void);
58797b2e202SAlex Deucher 
58897b2e202SAlex Deucher /*
58997b2e202SAlex Deucher  * GART structures, functions & helpers
59097b2e202SAlex Deucher  */
59197b2e202SAlex Deucher struct amdgpu_mc;
59297b2e202SAlex Deucher 
59397b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SIZE 4096
59497b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
59597b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SHIFT 12
59697b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
59797b2e202SAlex Deucher 
59897b2e202SAlex Deucher struct amdgpu_gart {
59997b2e202SAlex Deucher 	dma_addr_t			table_addr;
60097b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
60197b2e202SAlex Deucher 	void				*ptr;
60297b2e202SAlex Deucher 	unsigned			num_gpu_pages;
60397b2e202SAlex Deucher 	unsigned			num_cpu_pages;
60497b2e202SAlex Deucher 	unsigned			table_size;
605a1d29476SChristian König #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
60697b2e202SAlex Deucher 	struct page			**pages;
607a1d29476SChristian König #endif
60897b2e202SAlex Deucher 	bool				ready;
60997b2e202SAlex Deucher 	const struct amdgpu_gart_funcs *gart_funcs;
61097b2e202SAlex Deucher };
61197b2e202SAlex Deucher 
61297b2e202SAlex Deucher int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
61397b2e202SAlex Deucher void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
61497b2e202SAlex Deucher int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
61597b2e202SAlex Deucher void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
61697b2e202SAlex Deucher int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
61797b2e202SAlex Deucher void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
61897b2e202SAlex Deucher int amdgpu_gart_init(struct amdgpu_device *adev);
61997b2e202SAlex Deucher void amdgpu_gart_fini(struct amdgpu_device *adev);
62097b2e202SAlex Deucher void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
62197b2e202SAlex Deucher 			int pages);
62297b2e202SAlex Deucher int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
62397b2e202SAlex Deucher 		     int pages, struct page **pagelist,
62497b2e202SAlex Deucher 		     dma_addr_t *dma_addr, uint32_t flags);
6252c0d7318SChunming Zhou int amdgpu_ttm_recover_gart(struct amdgpu_device *adev);
62697b2e202SAlex Deucher 
62797b2e202SAlex Deucher /*
62897b2e202SAlex Deucher  * GPU MC structures, functions & helpers
62997b2e202SAlex Deucher  */
63097b2e202SAlex Deucher struct amdgpu_mc {
63197b2e202SAlex Deucher 	resource_size_t		aper_size;
63297b2e202SAlex Deucher 	resource_size_t		aper_base;
63397b2e202SAlex Deucher 	resource_size_t		agp_base;
63497b2e202SAlex Deucher 	/* for some chips with <= 32MB we need to lie
63597b2e202SAlex Deucher 	 * about vram size near mc fb location */
63697b2e202SAlex Deucher 	u64			mc_vram_size;
63797b2e202SAlex Deucher 	u64			visible_vram_size;
63897b2e202SAlex Deucher 	u64			gtt_size;
63997b2e202SAlex Deucher 	u64			gtt_start;
64097b2e202SAlex Deucher 	u64			gtt_end;
64197b2e202SAlex Deucher 	u64			vram_start;
64297b2e202SAlex Deucher 	u64			vram_end;
64397b2e202SAlex Deucher 	unsigned		vram_width;
64497b2e202SAlex Deucher 	u64			real_vram_size;
64597b2e202SAlex Deucher 	int			vram_mtrr;
64697b2e202SAlex Deucher 	u64                     gtt_base_align;
64797b2e202SAlex Deucher 	u64                     mc_mask;
64897b2e202SAlex Deucher 	const struct firmware   *fw;	/* MC firmware */
64997b2e202SAlex Deucher 	uint32_t                fw_version;
65097b2e202SAlex Deucher 	struct amdgpu_irq_src	vm_fault;
65181c59f54SKen Wang 	uint32_t		vram_type;
65250b0197aSChunming Zhou 	uint32_t                srbm_soft_reset;
65350b0197aSChunming Zhou 	struct amdgpu_mode_mc_save save;
65497b2e202SAlex Deucher };
65597b2e202SAlex Deucher 
65697b2e202SAlex Deucher /*
65797b2e202SAlex Deucher  * GPU doorbell structures, functions & helpers
65897b2e202SAlex Deucher  */
65997b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
66097b2e202SAlex Deucher {
66197b2e202SAlex Deucher 	AMDGPU_DOORBELL_KIQ                     = 0x000,
66297b2e202SAlex Deucher 	AMDGPU_DOORBELL_HIQ                     = 0x001,
66397b2e202SAlex Deucher 	AMDGPU_DOORBELL_DIQ                     = 0x002,
66497b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
66597b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
66697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
66797b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
66897b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
66997b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
67097b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
67197b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
67297b2e202SAlex Deucher 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
67397b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
67497b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
67597b2e202SAlex Deucher 	AMDGPU_DOORBELL_IH                      = 0x1E8,
67697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
67797b2e202SAlex Deucher 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
67897b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT;
67997b2e202SAlex Deucher 
68097b2e202SAlex Deucher struct amdgpu_doorbell {
68197b2e202SAlex Deucher 	/* doorbell mmio */
68297b2e202SAlex Deucher 	resource_size_t		base;
68397b2e202SAlex Deucher 	resource_size_t		size;
68497b2e202SAlex Deucher 	u32 __iomem		*ptr;
68597b2e202SAlex Deucher 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
68697b2e202SAlex Deucher };
68797b2e202SAlex Deucher 
68897b2e202SAlex Deucher void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
68997b2e202SAlex Deucher 				phys_addr_t *aperture_base,
69097b2e202SAlex Deucher 				size_t *aperture_size,
69197b2e202SAlex Deucher 				size_t *start_offset);
69297b2e202SAlex Deucher 
69397b2e202SAlex Deucher /*
69497b2e202SAlex Deucher  * IRQS.
69597b2e202SAlex Deucher  */
69697b2e202SAlex Deucher 
69797b2e202SAlex Deucher struct amdgpu_flip_work {
698325cbba1SMichel Dänzer 	struct delayed_work		flip_work;
69997b2e202SAlex Deucher 	struct work_struct		unpin_work;
70097b2e202SAlex Deucher 	struct amdgpu_device		*adev;
70197b2e202SAlex Deucher 	int				crtc_id;
702325cbba1SMichel Dänzer 	u32				target_vblank;
70397b2e202SAlex Deucher 	uint64_t			base;
70497b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
70597b2e202SAlex Deucher 	struct amdgpu_bo		*old_rbo;
7061ffd2652SChristian König 	struct fence			*excl;
7071ffd2652SChristian König 	unsigned			shared_count;
7081ffd2652SChristian König 	struct fence			**shared;
709c3874b75SChristian König 	struct fence_cb			cb;
710cb9e59d7SAlex Deucher 	bool				async;
71197b2e202SAlex Deucher };
71297b2e202SAlex Deucher 
71397b2e202SAlex Deucher 
71497b2e202SAlex Deucher /*
71597b2e202SAlex Deucher  * CP & rings.
71697b2e202SAlex Deucher  */
71797b2e202SAlex Deucher 
71897b2e202SAlex Deucher struct amdgpu_ib {
71997b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
72097b2e202SAlex Deucher 	uint32_t			length_dw;
72197b2e202SAlex Deucher 	uint64_t			gpu_addr;
72297b2e202SAlex Deucher 	uint32_t			*ptr;
723de807f81SJammy Zhou 	uint32_t			flags;
72497b2e202SAlex Deucher };
72597b2e202SAlex Deucher 
72697b2e202SAlex Deucher enum amdgpu_ring_type {
72797b2e202SAlex Deucher 	AMDGPU_RING_TYPE_GFX,
72897b2e202SAlex Deucher 	AMDGPU_RING_TYPE_COMPUTE,
72997b2e202SAlex Deucher 	AMDGPU_RING_TYPE_SDMA,
73097b2e202SAlex Deucher 	AMDGPU_RING_TYPE_UVD,
73197b2e202SAlex Deucher 	AMDGPU_RING_TYPE_VCE
73297b2e202SAlex Deucher };
73397b2e202SAlex Deucher 
73462250a91SNils Wallménius extern const struct amd_sched_backend_ops amdgpu_sched_ops;
735c1b69ed0SChunming Zhou 
73650838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
737c5637837SMonk Liu 		     struct amdgpu_job **job, struct amdgpu_vm *vm);
738d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
739d71518b5SChristian König 			     struct amdgpu_job **job);
740b6723c8dSMonk Liu 
741a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job);
74250838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job);
743d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
7442bd9ccfaSChristian König 		      struct amd_sched_entity *entity, void *owner,
7452bd9ccfaSChristian König 		      struct fence **f);
7463c704e93SChunming Zhou 
74797b2e202SAlex Deucher struct amdgpu_ring {
74897b2e202SAlex Deucher 	struct amdgpu_device		*adev;
74997b2e202SAlex Deucher 	const struct amdgpu_ring_funcs	*funcs;
75097b2e202SAlex Deucher 	struct amdgpu_fence_driver	fence_drv;
7514f839a24SChristian König 	struct amd_gpu_scheduler	sched;
75297b2e202SAlex Deucher 
75397b2e202SAlex Deucher 	struct amdgpu_bo	*ring_obj;
75497b2e202SAlex Deucher 	volatile uint32_t	*ring;
75597b2e202SAlex Deucher 	unsigned		rptr_offs;
75697b2e202SAlex Deucher 	unsigned		wptr;
75797b2e202SAlex Deucher 	unsigned		wptr_old;
75897b2e202SAlex Deucher 	unsigned		ring_size;
759c7e6be23SChristian König 	unsigned		max_dw;
76097b2e202SAlex Deucher 	int			count_dw;
76197b2e202SAlex Deucher 	uint64_t		gpu_addr;
76297b2e202SAlex Deucher 	uint32_t		align_mask;
76397b2e202SAlex Deucher 	uint32_t		ptr_mask;
76497b2e202SAlex Deucher 	bool			ready;
76597b2e202SAlex Deucher 	u32			nop;
76697b2e202SAlex Deucher 	u32			idx;
76797b2e202SAlex Deucher 	u32			me;
76897b2e202SAlex Deucher 	u32			pipe;
76997b2e202SAlex Deucher 	u32			queue;
77097b2e202SAlex Deucher 	struct amdgpu_bo	*mqd_obj;
77197b2e202SAlex Deucher 	u32			doorbell_index;
77297b2e202SAlex Deucher 	bool			use_doorbell;
77397b2e202SAlex Deucher 	unsigned		wptr_offs;
77497b2e202SAlex Deucher 	unsigned		fence_offs;
775aa3b73f6SChristian König 	uint64_t		current_ctx;
77697b2e202SAlex Deucher 	enum amdgpu_ring_type	type;
77797b2e202SAlex Deucher 	char			name[16];
778128cff1aSMonk Liu 	unsigned		cond_exe_offs;
779128cff1aSMonk Liu 	u64			cond_exe_gpu_addr;
780128cff1aSMonk Liu 	volatile u32		*cond_exe_cpu_addr;
781a909c6bdSMonk Liu #if defined(CONFIG_DEBUG_FS)
782a909c6bdSMonk Liu 	struct dentry *ent;
783a909c6bdSMonk Liu #endif
78497b2e202SAlex Deucher };
78597b2e202SAlex Deucher 
78697b2e202SAlex Deucher /*
78797b2e202SAlex Deucher  * VM
78897b2e202SAlex Deucher  */
78997b2e202SAlex Deucher 
79097b2e202SAlex Deucher /* maximum number of VMIDs */
79197b2e202SAlex Deucher #define AMDGPU_NUM_VM	16
79297b2e202SAlex Deucher 
79396105e53SChristian König /* Maximum number of PTEs the hardware can write with one command */
79496105e53SChristian König #define AMDGPU_VM_MAX_UPDATE_SIZE	0x3FFFF
79596105e53SChristian König 
79697b2e202SAlex Deucher /* number of entries in page table */
79797b2e202SAlex Deucher #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
79897b2e202SAlex Deucher 
79997b2e202SAlex Deucher /* PTBs (Page Table Blocks) need to be aligned to 32K */
80097b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_SIZE   32768
80197b2e202SAlex Deucher 
8021303c73cSChristian König /* LOG2 number of continuous pages for the fragment field */
8031303c73cSChristian König #define AMDGPU_LOG2_PAGES_PER_FRAG 4
8041303c73cSChristian König 
80597b2e202SAlex Deucher #define AMDGPU_PTE_VALID	(1 << 0)
80697b2e202SAlex Deucher #define AMDGPU_PTE_SYSTEM	(1 << 1)
80797b2e202SAlex Deucher #define AMDGPU_PTE_SNOOPED	(1 << 2)
80897b2e202SAlex Deucher 
80997b2e202SAlex Deucher /* VI only */
81097b2e202SAlex Deucher #define AMDGPU_PTE_EXECUTABLE	(1 << 4)
81197b2e202SAlex Deucher 
81297b2e202SAlex Deucher #define AMDGPU_PTE_READABLE	(1 << 5)
81397b2e202SAlex Deucher #define AMDGPU_PTE_WRITEABLE	(1 << 6)
81497b2e202SAlex Deucher 
8151303c73cSChristian König #define AMDGPU_PTE_FRAG(x)	((x & 0x1f) << 7)
81697b2e202SAlex Deucher 
817d9c13156SChristian König /* How to programm VM fault handling */
818d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_NEVER	0
819d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_FIRST	1
820d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_ALWAYS	2
821d9c13156SChristian König 
82297b2e202SAlex Deucher struct amdgpu_vm_pt {
823ee1782c3SChristian König 	struct amdgpu_bo_list_entry	entry;
82497b2e202SAlex Deucher 	uint64_t			addr;
8256557e3d2SChunming Zhou 	uint64_t			shadow_addr;
82697b2e202SAlex Deucher };
82797b2e202SAlex Deucher 
82897b2e202SAlex Deucher struct amdgpu_vm {
82925cfc3c2SChristian König 	/* tree of virtual addresses mapped */
83097b2e202SAlex Deucher 	struct rb_root		va;
83197b2e202SAlex Deucher 
8327fc11959SChristian König 	/* protecting invalidated */
83397b2e202SAlex Deucher 	spinlock_t		status_lock;
83497b2e202SAlex Deucher 
83597b2e202SAlex Deucher 	/* BOs moved, but not yet updated in the PT */
83697b2e202SAlex Deucher 	struct list_head	invalidated;
83797b2e202SAlex Deucher 
8387fc11959SChristian König 	/* BOs cleared in the PT because of a move */
8397fc11959SChristian König 	struct list_head	cleared;
8407fc11959SChristian König 
8417fc11959SChristian König 	/* BO mappings freed, but not yet updated in the PT */
84297b2e202SAlex Deucher 	struct list_head	freed;
84397b2e202SAlex Deucher 
84497b2e202SAlex Deucher 	/* contains the page directory */
84597b2e202SAlex Deucher 	struct amdgpu_bo	*page_directory;
84697b2e202SAlex Deucher 	unsigned		max_pde_used;
84705906decSBas Nieuwenhuizen 	struct fence		*page_directory_fence;
8485a712a87SChristian König 	uint64_t		last_eviction_counter;
84997b2e202SAlex Deucher 
85097b2e202SAlex Deucher 	/* array of page tables, one for each page directory entry */
85197b2e202SAlex Deucher 	struct amdgpu_vm_pt	*page_tables;
85297b2e202SAlex Deucher 
85397b2e202SAlex Deucher 	/* for id and flush management per ring */
854bcb1ba35SChristian König 	struct amdgpu_vm_id	*ids[AMDGPU_MAX_RINGS];
85525cfc3c2SChristian König 
85681d75a30Sjimqu 	/* protecting freed */
85781d75a30Sjimqu 	spinlock_t		freed_lock;
8582bd9ccfaSChristian König 
8592bd9ccfaSChristian König 	/* Scheduler entity for page table updates */
8602bd9ccfaSChristian König 	struct amd_sched_entity	entity;
861031e2983SChunming Zhou 
862031e2983SChunming Zhou 	/* client id */
863031e2983SChunming Zhou 	u64                     client_id;
86497b2e202SAlex Deucher };
86597b2e202SAlex Deucher 
866bcb1ba35SChristian König struct amdgpu_vm_id {
867a9a78b32SChristian König 	struct list_head	list;
868832a902fSChristian König 	struct fence		*first;
869832a902fSChristian König 	struct amdgpu_sync	active;
87041d9eb2cSChristian König 	struct fence		*last_flush;
8710ea54b9bSChristian König 	atomic64_t		owner;
872971fe9a9SChristian König 
873bcb1ba35SChristian König 	uint64_t		pd_gpu_addr;
874bcb1ba35SChristian König 	/* last flushed PD/PT update */
875bcb1ba35SChristian König 	struct fence		*flushed_updates;
876bcb1ba35SChristian König 
8776adb0513SChunming Zhou 	uint32_t                current_gpu_reset_count;
8786adb0513SChunming Zhou 
879971fe9a9SChristian König 	uint32_t		gds_base;
880971fe9a9SChristian König 	uint32_t		gds_size;
881971fe9a9SChristian König 	uint32_t		gws_base;
882971fe9a9SChristian König 	uint32_t		gws_size;
883971fe9a9SChristian König 	uint32_t		oa_base;
884971fe9a9SChristian König 	uint32_t		oa_size;
885a9a78b32SChristian König };
886a9a78b32SChristian König 
887a9a78b32SChristian König struct amdgpu_vm_manager {
888a9a78b32SChristian König 	/* Handling of VMIDs */
889a9a78b32SChristian König 	struct mutex				lock;
890a9a78b32SChristian König 	unsigned				num_ids;
891a9a78b32SChristian König 	struct list_head			ids_lru;
892bcb1ba35SChristian König 	struct amdgpu_vm_id			ids[AMDGPU_NUM_VM];
8931c16c0a7SChristian König 
8941fbb2e92SChristian König 	/* Handling of VM fences */
8951fbb2e92SChristian König 	u64					fence_context;
8961fbb2e92SChristian König 	unsigned				seqno[AMDGPU_MAX_RINGS];
8971fbb2e92SChristian König 
89897b2e202SAlex Deucher 	uint32_t				max_pfn;
89997b2e202SAlex Deucher 	/* vram base address for page table entry  */
90097b2e202SAlex Deucher 	u64					vram_base_offset;
90197b2e202SAlex Deucher 	/* is vm enabled? */
90297b2e202SAlex Deucher 	bool					enabled;
90397b2e202SAlex Deucher 	/* vm pte handling */
90497b2e202SAlex Deucher 	const struct amdgpu_vm_pte_funcs        *vm_pte_funcs;
9052d55e45aSChristian König 	struct amdgpu_ring                      *vm_pte_rings[AMDGPU_MAX_RINGS];
9062d55e45aSChristian König 	unsigned				vm_pte_num_rings;
9072d55e45aSChristian König 	atomic_t				vm_pte_next_ring;
908031e2983SChunming Zhou 	/* client id counter */
909031e2983SChunming Zhou 	atomic64_t				client_counter;
91097b2e202SAlex Deucher };
91197b2e202SAlex Deucher 
912a9a78b32SChristian König void amdgpu_vm_manager_init(struct amdgpu_device *adev);
913ea89f8c9SChristian König void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
9148b4fb00bSChristian König int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
9158b4fb00bSChristian König void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
91656467ebfSChristian König void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
9173c0eea6cSChristian König 			 struct list_head *validated,
91856467ebfSChristian König 			 struct amdgpu_bo_list_entry *entry);
9195a712a87SChristian König void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
9205a712a87SChristian König 			  struct list_head *duplicates);
921eceb8a15SChristian König void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
922eceb8a15SChristian König 				  struct amdgpu_vm *vm);
9238b4fb00bSChristian König int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
9244ff37a83SChristian König 		      struct amdgpu_sync *sync, struct fence *fence,
925fd53be30SChunming Zhou 		      struct amdgpu_job *job);
926fd53be30SChunming Zhou int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
927971fe9a9SChristian König void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
9288b4fb00bSChristian König int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
9298b4fb00bSChristian König 				    struct amdgpu_vm *vm);
9308b4fb00bSChristian König int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
9318b4fb00bSChristian König 			  struct amdgpu_vm *vm);
9328b4fb00bSChristian König int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
9338b4fb00bSChristian König 			     struct amdgpu_sync *sync);
9348b4fb00bSChristian König int amdgpu_vm_bo_update(struct amdgpu_device *adev,
9358b4fb00bSChristian König 			struct amdgpu_bo_va *bo_va,
93699e124f4SChristian König 			bool clear);
9378b4fb00bSChristian König void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
9388b4fb00bSChristian König 			     struct amdgpu_bo *bo);
9398b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
9408b4fb00bSChristian König 				       struct amdgpu_bo *bo);
9418b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
9428b4fb00bSChristian König 				      struct amdgpu_vm *vm,
9438b4fb00bSChristian König 				      struct amdgpu_bo *bo);
9448b4fb00bSChristian König int amdgpu_vm_bo_map(struct amdgpu_device *adev,
9458b4fb00bSChristian König 		     struct amdgpu_bo_va *bo_va,
9468b4fb00bSChristian König 		     uint64_t addr, uint64_t offset,
9478b4fb00bSChristian König 		     uint64_t size, uint32_t flags);
9488b4fb00bSChristian König int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
9498b4fb00bSChristian König 		       struct amdgpu_bo_va *bo_va,
9508b4fb00bSChristian König 		       uint64_t addr);
9518b4fb00bSChristian König void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
9528b4fb00bSChristian König 		      struct amdgpu_bo_va *bo_va);
9538b4fb00bSChristian König 
95497b2e202SAlex Deucher /*
95597b2e202SAlex Deucher  * context related structures
95697b2e202SAlex Deucher  */
95797b2e202SAlex Deucher 
95821c16bf6SChristian König struct amdgpu_ctx_ring {
95921c16bf6SChristian König 	uint64_t		sequence;
96037cd0ca2SChunming Zhou 	struct fence		**fences;
96191404fb2SChristian König 	struct amd_sched_entity	entity;
96221c16bf6SChristian König };
96321c16bf6SChristian König 
96497b2e202SAlex Deucher struct amdgpu_ctx {
96597b2e202SAlex Deucher 	struct kref		refcount;
9669cb7e5a9SChunming Zhou 	struct amdgpu_device    *adev;
967d94aed5aSMarek Olšák 	unsigned		reset_counter;
96821c16bf6SChristian König 	spinlock_t		ring_lock;
96937cd0ca2SChunming Zhou 	struct fence            **fences;
97021c16bf6SChristian König 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
971753ad49cSMonk Liu 	bool preamble_presented;
97297b2e202SAlex Deucher };
97397b2e202SAlex Deucher 
97497b2e202SAlex Deucher struct amdgpu_ctx_mgr {
97597b2e202SAlex Deucher 	struct amdgpu_device	*adev;
9760147ee0fSMarek Olšák 	struct mutex		lock;
9770b492a4cSAlex Deucher 	/* protected by lock */
9780b492a4cSAlex Deucher 	struct idr		ctx_handles;
97997b2e202SAlex Deucher };
98097b2e202SAlex Deucher 
9810b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
9820b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
9830b492a4cSAlex Deucher 
98421c16bf6SChristian König uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
985ce882e6dSChristian König 			      struct fence *fence);
98621c16bf6SChristian König struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
98721c16bf6SChristian König 				   struct amdgpu_ring *ring, uint64_t seq);
98821c16bf6SChristian König 
9890b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
9900b492a4cSAlex Deucher 		     struct drm_file *filp);
9910b492a4cSAlex Deucher 
992efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
993efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
9940b492a4cSAlex Deucher 
99597b2e202SAlex Deucher /*
99697b2e202SAlex Deucher  * file private structure
99797b2e202SAlex Deucher  */
99897b2e202SAlex Deucher 
99997b2e202SAlex Deucher struct amdgpu_fpriv {
100097b2e202SAlex Deucher 	struct amdgpu_vm	vm;
100197b2e202SAlex Deucher 	struct mutex		bo_list_lock;
100297b2e202SAlex Deucher 	struct idr		bo_list_handles;
100397b2e202SAlex Deucher 	struct amdgpu_ctx_mgr	ctx_mgr;
100497b2e202SAlex Deucher };
100597b2e202SAlex Deucher 
100697b2e202SAlex Deucher /*
100797b2e202SAlex Deucher  * residency list
100897b2e202SAlex Deucher  */
100997b2e202SAlex Deucher 
101097b2e202SAlex Deucher struct amdgpu_bo_list {
101197b2e202SAlex Deucher 	struct mutex lock;
101297b2e202SAlex Deucher 	struct amdgpu_bo *gds_obj;
101397b2e202SAlex Deucher 	struct amdgpu_bo *gws_obj;
101497b2e202SAlex Deucher 	struct amdgpu_bo *oa_obj;
1015211dff55SChristian König 	unsigned first_userptr;
101697b2e202SAlex Deucher 	unsigned num_entries;
101797b2e202SAlex Deucher 	struct amdgpu_bo_list_entry *array;
101897b2e202SAlex Deucher };
101997b2e202SAlex Deucher 
102097b2e202SAlex Deucher struct amdgpu_bo_list *
102197b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
1022636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1023636ce25cSChristian König 			     struct list_head *validated);
102497b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
102597b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
102697b2e202SAlex Deucher 
102797b2e202SAlex Deucher /*
102897b2e202SAlex Deucher  * GFX stuff
102997b2e202SAlex Deucher  */
103097b2e202SAlex Deucher #include "clearstate_defs.h"
103197b2e202SAlex Deucher 
103279e5412cSAlex Deucher struct amdgpu_rlc_funcs {
103379e5412cSAlex Deucher 	void (*enter_safe_mode)(struct amdgpu_device *adev);
103479e5412cSAlex Deucher 	void (*exit_safe_mode)(struct amdgpu_device *adev);
103579e5412cSAlex Deucher };
103679e5412cSAlex Deucher 
103797b2e202SAlex Deucher struct amdgpu_rlc {
103897b2e202SAlex Deucher 	/* for power gating */
103997b2e202SAlex Deucher 	struct amdgpu_bo	*save_restore_obj;
104097b2e202SAlex Deucher 	uint64_t		save_restore_gpu_addr;
104197b2e202SAlex Deucher 	volatile uint32_t	*sr_ptr;
104297b2e202SAlex Deucher 	const u32               *reg_list;
104397b2e202SAlex Deucher 	u32                     reg_list_size;
104497b2e202SAlex Deucher 	/* for clear state */
104597b2e202SAlex Deucher 	struct amdgpu_bo	*clear_state_obj;
104697b2e202SAlex Deucher 	uint64_t		clear_state_gpu_addr;
104797b2e202SAlex Deucher 	volatile uint32_t	*cs_ptr;
104897b2e202SAlex Deucher 	const struct cs_section_def   *cs_data;
104997b2e202SAlex Deucher 	u32                     clear_state_size;
105097b2e202SAlex Deucher 	/* for cp tables */
105197b2e202SAlex Deucher 	struct amdgpu_bo	*cp_table_obj;
105297b2e202SAlex Deucher 	uint64_t		cp_table_gpu_addr;
105397b2e202SAlex Deucher 	volatile uint32_t	*cp_table_ptr;
105497b2e202SAlex Deucher 	u32                     cp_table_size;
105579e5412cSAlex Deucher 
105679e5412cSAlex Deucher 	/* safe mode for updating CG/PG state */
105779e5412cSAlex Deucher 	bool in_safe_mode;
105879e5412cSAlex Deucher 	const struct amdgpu_rlc_funcs *funcs;
10592b6cd977SEric Huang 
10602b6cd977SEric Huang 	/* for firmware data */
10612b6cd977SEric Huang 	u32 save_and_restore_offset;
10622b6cd977SEric Huang 	u32 clear_state_descriptor_offset;
10632b6cd977SEric Huang 	u32 avail_scratch_ram_locations;
10642b6cd977SEric Huang 	u32 reg_restore_list_size;
10652b6cd977SEric Huang 	u32 reg_list_format_start;
10662b6cd977SEric Huang 	u32 reg_list_format_separate_start;
10672b6cd977SEric Huang 	u32 starting_offsets_start;
10682b6cd977SEric Huang 	u32 reg_list_format_size_bytes;
10692b6cd977SEric Huang 	u32 reg_list_size_bytes;
10702b6cd977SEric Huang 
10712b6cd977SEric Huang 	u32 *register_list_format;
10722b6cd977SEric Huang 	u32 *register_restore;
107397b2e202SAlex Deucher };
107497b2e202SAlex Deucher 
107597b2e202SAlex Deucher struct amdgpu_mec {
107697b2e202SAlex Deucher 	struct amdgpu_bo	*hpd_eop_obj;
107797b2e202SAlex Deucher 	u64			hpd_eop_gpu_addr;
107897b2e202SAlex Deucher 	u32 num_pipe;
107997b2e202SAlex Deucher 	u32 num_mec;
108097b2e202SAlex Deucher 	u32 num_queue;
108197b2e202SAlex Deucher };
108297b2e202SAlex Deucher 
108397b2e202SAlex Deucher /*
108497b2e202SAlex Deucher  * GPU scratch registers structures, functions & helpers
108597b2e202SAlex Deucher  */
108697b2e202SAlex Deucher struct amdgpu_scratch {
108797b2e202SAlex Deucher 	unsigned		num_reg;
108897b2e202SAlex Deucher 	uint32_t                reg_base;
108997b2e202SAlex Deucher 	bool			free[32];
109097b2e202SAlex Deucher 	uint32_t		reg[32];
109197b2e202SAlex Deucher };
109297b2e202SAlex Deucher 
109397b2e202SAlex Deucher /*
109497b2e202SAlex Deucher  * GFX configurations
109597b2e202SAlex Deucher  */
109697b2e202SAlex Deucher struct amdgpu_gca_config {
109797b2e202SAlex Deucher 	unsigned max_shader_engines;
109897b2e202SAlex Deucher 	unsigned max_tile_pipes;
109997b2e202SAlex Deucher 	unsigned max_cu_per_sh;
110097b2e202SAlex Deucher 	unsigned max_sh_per_se;
110197b2e202SAlex Deucher 	unsigned max_backends_per_se;
110297b2e202SAlex Deucher 	unsigned max_texture_channel_caches;
110397b2e202SAlex Deucher 	unsigned max_gprs;
110497b2e202SAlex Deucher 	unsigned max_gs_threads;
110597b2e202SAlex Deucher 	unsigned max_hw_contexts;
110697b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_frontend;
110797b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_backend;
110897b2e202SAlex Deucher 	unsigned sc_hiz_tile_fifo_size;
110997b2e202SAlex Deucher 	unsigned sc_earlyz_tile_fifo_size;
111097b2e202SAlex Deucher 
111197b2e202SAlex Deucher 	unsigned num_tile_pipes;
111297b2e202SAlex Deucher 	unsigned backend_enable_mask;
111397b2e202SAlex Deucher 	unsigned mem_max_burst_length_bytes;
111497b2e202SAlex Deucher 	unsigned mem_row_size_in_kb;
111597b2e202SAlex Deucher 	unsigned shader_engine_tile_size;
111697b2e202SAlex Deucher 	unsigned num_gpus;
111797b2e202SAlex Deucher 	unsigned multi_gpu_tile_size;
111897b2e202SAlex Deucher 	unsigned mc_arb_ramcfg;
111997b2e202SAlex Deucher 	unsigned gb_addr_config;
11208f8e00c1SAlex Deucher 	unsigned num_rbs;
112197b2e202SAlex Deucher 
112297b2e202SAlex Deucher 	uint32_t tile_mode_array[32];
112397b2e202SAlex Deucher 	uint32_t macrotile_mode_array[16];
112497b2e202SAlex Deucher };
112597b2e202SAlex Deucher 
11267dae69a2SAlex Deucher struct amdgpu_cu_info {
11277dae69a2SAlex Deucher 	uint32_t number; /* total active CU number */
11287dae69a2SAlex Deucher 	uint32_t ao_cu_mask;
11297dae69a2SAlex Deucher 	uint32_t bitmap[4][4];
11307dae69a2SAlex Deucher };
11317dae69a2SAlex Deucher 
1132b95e31fdSAlex Deucher struct amdgpu_gfx_funcs {
1133b95e31fdSAlex Deucher 	/* get the gpu clock counter */
1134b95e31fdSAlex Deucher 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
11359559ef5bSTom St Denis 	void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
1136b95e31fdSAlex Deucher };
1137b95e31fdSAlex Deucher 
113897b2e202SAlex Deucher struct amdgpu_gfx {
113997b2e202SAlex Deucher 	struct mutex			gpu_clock_mutex;
114097b2e202SAlex Deucher 	struct amdgpu_gca_config	config;
114197b2e202SAlex Deucher 	struct amdgpu_rlc		rlc;
114297b2e202SAlex Deucher 	struct amdgpu_mec		mec;
114397b2e202SAlex Deucher 	struct amdgpu_scratch		scratch;
114497b2e202SAlex Deucher 	const struct firmware		*me_fw;	/* ME firmware */
114597b2e202SAlex Deucher 	uint32_t			me_fw_version;
114697b2e202SAlex Deucher 	const struct firmware		*pfp_fw; /* PFP firmware */
114797b2e202SAlex Deucher 	uint32_t			pfp_fw_version;
114897b2e202SAlex Deucher 	const struct firmware		*ce_fw;	/* CE firmware */
114997b2e202SAlex Deucher 	uint32_t			ce_fw_version;
115097b2e202SAlex Deucher 	const struct firmware		*rlc_fw; /* RLC firmware */
115197b2e202SAlex Deucher 	uint32_t			rlc_fw_version;
115297b2e202SAlex Deucher 	const struct firmware		*mec_fw; /* MEC firmware */
115397b2e202SAlex Deucher 	uint32_t			mec_fw_version;
115497b2e202SAlex Deucher 	const struct firmware		*mec2_fw; /* MEC2 firmware */
115597b2e202SAlex Deucher 	uint32_t			mec2_fw_version;
115602558a00SKen Wang 	uint32_t			me_feature_version;
115702558a00SKen Wang 	uint32_t			ce_feature_version;
115802558a00SKen Wang 	uint32_t			pfp_feature_version;
1159351643d7SJammy Zhou 	uint32_t			rlc_feature_version;
1160351643d7SJammy Zhou 	uint32_t			mec_feature_version;
1161351643d7SJammy Zhou 	uint32_t			mec2_feature_version;
116297b2e202SAlex Deucher 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
116397b2e202SAlex Deucher 	unsigned			num_gfx_rings;
116497b2e202SAlex Deucher 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
116597b2e202SAlex Deucher 	unsigned			num_compute_rings;
116697b2e202SAlex Deucher 	struct amdgpu_irq_src		eop_irq;
116797b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_reg_irq;
116897b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_inst_irq;
116997b2e202SAlex Deucher 	/* gfx status */
117097b2e202SAlex Deucher 	uint32_t			gfx_current_status;
1171a101a899SKen Wang 	/* ce ram size*/
1172a101a899SKen Wang 	unsigned			ce_ram_size;
11737dae69a2SAlex Deucher 	struct amdgpu_cu_info		cu_info;
1174b95e31fdSAlex Deucher 	const struct amdgpu_gfx_funcs	*funcs;
11753d7c6384SChunming Zhou 
11763d7c6384SChunming Zhou 	/* reset mask */
11773d7c6384SChunming Zhou 	uint32_t                        grbm_soft_reset;
11783d7c6384SChunming Zhou 	uint32_t                        srbm_soft_reset;
117997b2e202SAlex Deucher };
118097b2e202SAlex Deucher 
1181b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
118297b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
11834d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
11844d9c514dSChristian König 		    struct fence *f);
1185b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
1186336d1f5eSChristian König 		       struct amdgpu_ib *ib, struct fence *last_vm_update,
1187c5637837SMonk Liu 		       struct amdgpu_job *job, struct fence **f);
118897b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
118997b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
119097b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
119197b2e202SAlex Deucher int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
1192edff0e28SJammy Zhou void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
11939e5d5309SChristian König void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
119497b2e202SAlex Deucher void amdgpu_ring_commit(struct amdgpu_ring *ring);
119597b2e202SAlex Deucher void amdgpu_ring_undo(struct amdgpu_ring *ring);
119697b2e202SAlex Deucher int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
119797b2e202SAlex Deucher 		     unsigned ring_size, u32 nop, u32 align_mask,
119897b2e202SAlex Deucher 		     struct amdgpu_irq_src *irq_src, unsigned irq_type,
119997b2e202SAlex Deucher 		     enum amdgpu_ring_type ring_type);
120097b2e202SAlex Deucher void amdgpu_ring_fini(struct amdgpu_ring *ring);
120197b2e202SAlex Deucher 
120297b2e202SAlex Deucher /*
120397b2e202SAlex Deucher  * CS.
120497b2e202SAlex Deucher  */
120597b2e202SAlex Deucher struct amdgpu_cs_chunk {
120697b2e202SAlex Deucher 	uint32_t		chunk_id;
120797b2e202SAlex Deucher 	uint32_t		length_dw;
1208758ac17fSChristian König 	void			*kdata;
120997b2e202SAlex Deucher };
121097b2e202SAlex Deucher 
121197b2e202SAlex Deucher struct amdgpu_cs_parser {
121297b2e202SAlex Deucher 	struct amdgpu_device	*adev;
121397b2e202SAlex Deucher 	struct drm_file		*filp;
12143cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
1215c3cca41eSChristian König 
121697b2e202SAlex Deucher 	/* chunks */
121797b2e202SAlex Deucher 	unsigned		nchunks;
121897b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
1219c3cca41eSChristian König 
122050838c8cSChristian König 	/* scheduler job object */
122150838c8cSChristian König 	struct amdgpu_job	*job;
1222c3cca41eSChristian König 
1223c3cca41eSChristian König 	/* buffer objects */
1224c3cca41eSChristian König 	struct ww_acquire_ctx		ticket;
1225c3cca41eSChristian König 	struct amdgpu_bo_list		*bo_list;
122656467ebfSChristian König 	struct amdgpu_bo_list_entry	vm_pd;
122797b2e202SAlex Deucher 	struct list_head		validated;
1228984810fcSChristian König 	struct fence			*fence;
1229f69f90a1SChristian König 	uint64_t			bytes_moved_threshold;
1230f69f90a1SChristian König 	uint64_t			bytes_moved;
1231662bfa61SChristian König 	struct amdgpu_bo_list_entry	*evictable;
123297b2e202SAlex Deucher 
123397b2e202SAlex Deucher 	/* user fence */
123491acbeb6SChristian König 	struct amdgpu_bo_list_entry	uf_entry;
123597b2e202SAlex Deucher };
123697b2e202SAlex Deucher 
1237753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT          (1 << 0) /* bit set means command submit involves a preamble IB */
1238753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST    (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1239753ad49cSMonk Liu #define AMDGPU_HAVE_CTX_SWITCH              (1 << 2) /* bit set means context switch occured */
1240753ad49cSMonk Liu 
1241bb977d37SChunming Zhou struct amdgpu_job {
1242bb977d37SChunming Zhou 	struct amd_sched_job    base;
1243bb977d37SChunming Zhou 	struct amdgpu_device	*adev;
1244c5637837SMonk Liu 	struct amdgpu_vm	*vm;
1245b07c60c0SChristian König 	struct amdgpu_ring	*ring;
1246e86f9ceeSChristian König 	struct amdgpu_sync	sync;
1247bb977d37SChunming Zhou 	struct amdgpu_ib	*ibs;
124873cfa5f5SMonk Liu 	struct fence		*fence; /* the hw fence */
1249753ad49cSMonk Liu 	uint32_t		preamble_status;
1250bb977d37SChunming Zhou 	uint32_t		num_ibs;
1251e2840221SChristian König 	void			*owner;
12523aecd24cSMonk Liu 	uint64_t		fence_ctx; /* the fence_context this job uses */
1253fd53be30SChunming Zhou 	bool                    vm_needs_flush;
1254d88bf583SChristian König 	unsigned		vm_id;
1255d88bf583SChristian König 	uint64_t		vm_pd_addr;
1256d88bf583SChristian König 	uint32_t		gds_base, gds_size;
1257d88bf583SChristian König 	uint32_t		gws_base, gws_size;
1258d88bf583SChristian König 	uint32_t		oa_base, oa_size;
1259758ac17fSChristian König 
1260758ac17fSChristian König 	/* user fence handling */
1261b5f5acbcSChristian König 	uint64_t		uf_addr;
1262758ac17fSChristian König 	uint64_t		uf_sequence;
1263758ac17fSChristian König 
1264bb977d37SChunming Zhou };
1265a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job)		\
1266a6db8a33SJunwei Zhang 		container_of((sched_job), struct amdgpu_job, base)
1267bb977d37SChunming Zhou 
12687270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
12697270f839SChristian König 				      uint32_t ib_idx, int idx)
127097b2e202SAlex Deucher {
127150838c8cSChristian König 	return p->job->ibs[ib_idx].ptr[idx];
127297b2e202SAlex Deucher }
127397b2e202SAlex Deucher 
12747270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
12757270f839SChristian König 				       uint32_t ib_idx, int idx,
12767270f839SChristian König 				       uint32_t value)
12777270f839SChristian König {
127850838c8cSChristian König 	p->job->ibs[ib_idx].ptr[idx] = value;
12797270f839SChristian König }
12807270f839SChristian König 
128197b2e202SAlex Deucher /*
128297b2e202SAlex Deucher  * Writeback
128397b2e202SAlex Deucher  */
128497b2e202SAlex Deucher #define AMDGPU_MAX_WB 1024	/* Reserve at most 1024 WB slots for amdgpu-owned rings. */
128597b2e202SAlex Deucher 
128697b2e202SAlex Deucher struct amdgpu_wb {
128797b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
128897b2e202SAlex Deucher 	volatile uint32_t	*wb;
128997b2e202SAlex Deucher 	uint64_t		gpu_addr;
129097b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
129197b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
129297b2e202SAlex Deucher };
129397b2e202SAlex Deucher 
129497b2e202SAlex Deucher int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
129597b2e202SAlex Deucher void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
129697b2e202SAlex Deucher 
129797b2e202SAlex Deucher 
129897b2e202SAlex Deucher 
129997b2e202SAlex Deucher enum amdgpu_int_thermal_type {
130097b2e202SAlex Deucher 	THERMAL_TYPE_NONE,
130197b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL,
130297b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL_GPIO,
130397b2e202SAlex Deucher 	THERMAL_TYPE_RV6XX,
130497b2e202SAlex Deucher 	THERMAL_TYPE_RV770,
130597b2e202SAlex Deucher 	THERMAL_TYPE_ADT7473_WITH_INTERNAL,
130697b2e202SAlex Deucher 	THERMAL_TYPE_EVERGREEN,
130797b2e202SAlex Deucher 	THERMAL_TYPE_SUMO,
130897b2e202SAlex Deucher 	THERMAL_TYPE_NI,
130997b2e202SAlex Deucher 	THERMAL_TYPE_SI,
131097b2e202SAlex Deucher 	THERMAL_TYPE_EMC2103_WITH_INTERNAL,
131197b2e202SAlex Deucher 	THERMAL_TYPE_CI,
131297b2e202SAlex Deucher 	THERMAL_TYPE_KV,
131397b2e202SAlex Deucher };
131497b2e202SAlex Deucher 
131597b2e202SAlex Deucher enum amdgpu_dpm_auto_throttle_src {
131697b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
131797b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
131897b2e202SAlex Deucher };
131997b2e202SAlex Deucher 
132097b2e202SAlex Deucher enum amdgpu_dpm_event_src {
132197b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
132297b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
132397b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
132497b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
132597b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
132697b2e202SAlex Deucher };
132797b2e202SAlex Deucher 
132897b2e202SAlex Deucher #define AMDGPU_MAX_VCE_LEVELS 6
132997b2e202SAlex Deucher 
133097b2e202SAlex Deucher enum amdgpu_vce_level {
133197b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_AC_ALL = 0,     /* AC, All cases */
133297b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_EE = 1,      /* DC, entropy encoding */
133397b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_LOW = 2,  /* DC, low latency queue, res <= 720 */
133497b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
133597b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_LOW = 4,  /* DC, general purpose queue, res <= 720 */
133697b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
133797b2e202SAlex Deucher };
133897b2e202SAlex Deucher 
133997b2e202SAlex Deucher struct amdgpu_ps {
134097b2e202SAlex Deucher 	u32 caps; /* vbios flags */
134197b2e202SAlex Deucher 	u32 class; /* vbios flags */
134297b2e202SAlex Deucher 	u32 class2; /* vbios flags */
134397b2e202SAlex Deucher 	/* UVD clocks */
134497b2e202SAlex Deucher 	u32 vclk;
134597b2e202SAlex Deucher 	u32 dclk;
134697b2e202SAlex Deucher 	/* VCE clocks */
134797b2e202SAlex Deucher 	u32 evclk;
134897b2e202SAlex Deucher 	u32 ecclk;
134997b2e202SAlex Deucher 	bool vce_active;
135097b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
135197b2e202SAlex Deucher 	/* asic priv */
135297b2e202SAlex Deucher 	void *ps_priv;
135397b2e202SAlex Deucher };
135497b2e202SAlex Deucher 
135597b2e202SAlex Deucher struct amdgpu_dpm_thermal {
135697b2e202SAlex Deucher 	/* thermal interrupt work */
135797b2e202SAlex Deucher 	struct work_struct work;
135897b2e202SAlex Deucher 	/* low temperature threshold */
135997b2e202SAlex Deucher 	int                min_temp;
136097b2e202SAlex Deucher 	/* high temperature threshold */
136197b2e202SAlex Deucher 	int                max_temp;
136297b2e202SAlex Deucher 	/* was last interrupt low to high or high to low */
136397b2e202SAlex Deucher 	bool               high_to_low;
136497b2e202SAlex Deucher 	/* interrupt source */
136597b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
136697b2e202SAlex Deucher };
136797b2e202SAlex Deucher 
136897b2e202SAlex Deucher enum amdgpu_clk_action
136997b2e202SAlex Deucher {
137097b2e202SAlex Deucher 	AMDGPU_SCLK_UP = 1,
137197b2e202SAlex Deucher 	AMDGPU_SCLK_DOWN
137297b2e202SAlex Deucher };
137397b2e202SAlex Deucher 
137497b2e202SAlex Deucher struct amdgpu_blacklist_clocks
137597b2e202SAlex Deucher {
137697b2e202SAlex Deucher 	u32 sclk;
137797b2e202SAlex Deucher 	u32 mclk;
137897b2e202SAlex Deucher 	enum amdgpu_clk_action action;
137997b2e202SAlex Deucher };
138097b2e202SAlex Deucher 
138197b2e202SAlex Deucher struct amdgpu_clock_and_voltage_limits {
138297b2e202SAlex Deucher 	u32 sclk;
138397b2e202SAlex Deucher 	u32 mclk;
138497b2e202SAlex Deucher 	u16 vddc;
138597b2e202SAlex Deucher 	u16 vddci;
138697b2e202SAlex Deucher };
138797b2e202SAlex Deucher 
138897b2e202SAlex Deucher struct amdgpu_clock_array {
138997b2e202SAlex Deucher 	u32 count;
139097b2e202SAlex Deucher 	u32 *values;
139197b2e202SAlex Deucher };
139297b2e202SAlex Deucher 
139397b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_entry {
139497b2e202SAlex Deucher 	u32 clk;
139597b2e202SAlex Deucher 	u16 v;
139697b2e202SAlex Deucher };
139797b2e202SAlex Deucher 
139897b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table {
139997b2e202SAlex Deucher 	u32 count;
140097b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_entry *entries;
140197b2e202SAlex Deucher };
140297b2e202SAlex Deucher 
140397b2e202SAlex Deucher union amdgpu_cac_leakage_entry {
140497b2e202SAlex Deucher 	struct {
140597b2e202SAlex Deucher 		u16 vddc;
140697b2e202SAlex Deucher 		u32 leakage;
140797b2e202SAlex Deucher 	};
140897b2e202SAlex Deucher 	struct {
140997b2e202SAlex Deucher 		u16 vddc1;
141097b2e202SAlex Deucher 		u16 vddc2;
141197b2e202SAlex Deucher 		u16 vddc3;
141297b2e202SAlex Deucher 	};
141397b2e202SAlex Deucher };
141497b2e202SAlex Deucher 
141597b2e202SAlex Deucher struct amdgpu_cac_leakage_table {
141697b2e202SAlex Deucher 	u32 count;
141797b2e202SAlex Deucher 	union amdgpu_cac_leakage_entry *entries;
141897b2e202SAlex Deucher };
141997b2e202SAlex Deucher 
142097b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_entry {
142197b2e202SAlex Deucher 	u16 voltage;
142297b2e202SAlex Deucher 	u32 sclk;
142397b2e202SAlex Deucher 	u32 mclk;
142497b2e202SAlex Deucher };
142597b2e202SAlex Deucher 
142697b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_table {
142797b2e202SAlex Deucher 	u32 count;
142897b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_entry *entries;
142997b2e202SAlex Deucher };
143097b2e202SAlex Deucher 
143197b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_entry {
143297b2e202SAlex Deucher 	u32 vclk;
143397b2e202SAlex Deucher 	u32 dclk;
143497b2e202SAlex Deucher 	u16 v;
143597b2e202SAlex Deucher };
143697b2e202SAlex Deucher 
143797b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_table {
143897b2e202SAlex Deucher 	u8 count;
143997b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
144097b2e202SAlex Deucher };
144197b2e202SAlex Deucher 
144297b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_entry {
144397b2e202SAlex Deucher 	u32 ecclk;
144497b2e202SAlex Deucher 	u32 evclk;
144597b2e202SAlex Deucher 	u16 v;
144697b2e202SAlex Deucher };
144797b2e202SAlex Deucher 
144897b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_table {
144997b2e202SAlex Deucher 	u8 count;
145097b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_entry *entries;
145197b2e202SAlex Deucher };
145297b2e202SAlex Deucher 
145397b2e202SAlex Deucher struct amdgpu_ppm_table {
145497b2e202SAlex Deucher 	u8 ppm_design;
145597b2e202SAlex Deucher 	u16 cpu_core_number;
145697b2e202SAlex Deucher 	u32 platform_tdp;
145797b2e202SAlex Deucher 	u32 small_ac_platform_tdp;
145897b2e202SAlex Deucher 	u32 platform_tdc;
145997b2e202SAlex Deucher 	u32 small_ac_platform_tdc;
146097b2e202SAlex Deucher 	u32 apu_tdp;
146197b2e202SAlex Deucher 	u32 dgpu_tdp;
146297b2e202SAlex Deucher 	u32 dgpu_ulv_power;
146397b2e202SAlex Deucher 	u32 tj_max;
146497b2e202SAlex Deucher };
146597b2e202SAlex Deucher 
146697b2e202SAlex Deucher struct amdgpu_cac_tdp_table {
146797b2e202SAlex Deucher 	u16 tdp;
146897b2e202SAlex Deucher 	u16 configurable_tdp;
146997b2e202SAlex Deucher 	u16 tdc;
147097b2e202SAlex Deucher 	u16 battery_power_limit;
147197b2e202SAlex Deucher 	u16 small_power_limit;
147297b2e202SAlex Deucher 	u16 low_cac_leakage;
147397b2e202SAlex Deucher 	u16 high_cac_leakage;
147497b2e202SAlex Deucher 	u16 maximum_power_delivery_limit;
147597b2e202SAlex Deucher };
147697b2e202SAlex Deucher 
147797b2e202SAlex Deucher struct amdgpu_dpm_dynamic_state {
147897b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
147997b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
148097b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
148197b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
148297b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
148397b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
148497b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
148597b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
148697b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
148797b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
148897b2e202SAlex Deucher 	struct amdgpu_clock_array valid_sclk_values;
148997b2e202SAlex Deucher 	struct amdgpu_clock_array valid_mclk_values;
149097b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
149197b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
149297b2e202SAlex Deucher 	u32 mclk_sclk_ratio;
149397b2e202SAlex Deucher 	u32 sclk_mclk_delta;
149497b2e202SAlex Deucher 	u16 vddc_vddci_delta;
149597b2e202SAlex Deucher 	u16 min_vddc_for_pcie_gen2;
149697b2e202SAlex Deucher 	struct amdgpu_cac_leakage_table cac_leakage_table;
149797b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
149897b2e202SAlex Deucher 	struct amdgpu_ppm_table *ppm_table;
149997b2e202SAlex Deucher 	struct amdgpu_cac_tdp_table *cac_tdp_table;
150097b2e202SAlex Deucher };
150197b2e202SAlex Deucher 
150297b2e202SAlex Deucher struct amdgpu_dpm_fan {
150397b2e202SAlex Deucher 	u16 t_min;
150497b2e202SAlex Deucher 	u16 t_med;
150597b2e202SAlex Deucher 	u16 t_high;
150697b2e202SAlex Deucher 	u16 pwm_min;
150797b2e202SAlex Deucher 	u16 pwm_med;
150897b2e202SAlex Deucher 	u16 pwm_high;
150997b2e202SAlex Deucher 	u8 t_hyst;
151097b2e202SAlex Deucher 	u32 cycle_delay;
151197b2e202SAlex Deucher 	u16 t_max;
151297b2e202SAlex Deucher 	u8 control_mode;
151397b2e202SAlex Deucher 	u16 default_max_fan_pwm;
151497b2e202SAlex Deucher 	u16 default_fan_output_sensitivity;
151597b2e202SAlex Deucher 	u16 fan_output_sensitivity;
151697b2e202SAlex Deucher 	bool ucode_fan_control;
151797b2e202SAlex Deucher };
151897b2e202SAlex Deucher 
151997b2e202SAlex Deucher enum amdgpu_pcie_gen {
152097b2e202SAlex Deucher 	AMDGPU_PCIE_GEN1 = 0,
152197b2e202SAlex Deucher 	AMDGPU_PCIE_GEN2 = 1,
152297b2e202SAlex Deucher 	AMDGPU_PCIE_GEN3 = 2,
152397b2e202SAlex Deucher 	AMDGPU_PCIE_GEN_INVALID = 0xffff
152497b2e202SAlex Deucher };
152597b2e202SAlex Deucher 
152697b2e202SAlex Deucher enum amdgpu_dpm_forced_level {
152797b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
152897b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
152997b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
1530f3898ea1SEric Huang 	AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
153197b2e202SAlex Deucher };
153297b2e202SAlex Deucher 
153397b2e202SAlex Deucher struct amdgpu_vce_state {
153497b2e202SAlex Deucher 	/* vce clocks */
153597b2e202SAlex Deucher 	u32 evclk;
153697b2e202SAlex Deucher 	u32 ecclk;
153797b2e202SAlex Deucher 	/* gpu clocks */
153897b2e202SAlex Deucher 	u32 sclk;
153997b2e202SAlex Deucher 	u32 mclk;
154097b2e202SAlex Deucher 	u8 clk_idx;
154197b2e202SAlex Deucher 	u8 pstate;
154297b2e202SAlex Deucher };
154397b2e202SAlex Deucher 
154497b2e202SAlex Deucher struct amdgpu_dpm_funcs {
154597b2e202SAlex Deucher 	int (*get_temperature)(struct amdgpu_device *adev);
154697b2e202SAlex Deucher 	int (*pre_set_power_state)(struct amdgpu_device *adev);
154797b2e202SAlex Deucher 	int (*set_power_state)(struct amdgpu_device *adev);
154897b2e202SAlex Deucher 	void (*post_set_power_state)(struct amdgpu_device *adev);
154997b2e202SAlex Deucher 	void (*display_configuration_changed)(struct amdgpu_device *adev);
155097b2e202SAlex Deucher 	u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
155197b2e202SAlex Deucher 	u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
155297b2e202SAlex Deucher 	void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
155397b2e202SAlex Deucher 	void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
155497b2e202SAlex Deucher 	int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
155597b2e202SAlex Deucher 	bool (*vblank_too_short)(struct amdgpu_device *adev);
155697b2e202SAlex Deucher 	void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
1557b7a07769SSonny Jiang 	void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
155897b2e202SAlex Deucher 	void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
155997b2e202SAlex Deucher 	void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
156097b2e202SAlex Deucher 	u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
156197b2e202SAlex Deucher 	int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
156297b2e202SAlex Deucher 	int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1563c85e299fSEric Huang 	int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1564c85e299fSEric Huang 	int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
15658b2e574dSEric Huang 	int (*get_sclk_od)(struct amdgpu_device *adev);
15668b2e574dSEric Huang 	int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
1567f2bdc05fSEric Huang 	int (*get_mclk_od)(struct amdgpu_device *adev);
1568f2bdc05fSEric Huang 	int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
156997b2e202SAlex Deucher };
157097b2e202SAlex Deucher 
157197b2e202SAlex Deucher struct amdgpu_dpm {
157297b2e202SAlex Deucher 	struct amdgpu_ps        *ps;
157397b2e202SAlex Deucher 	/* number of valid power states */
157497b2e202SAlex Deucher 	int                     num_ps;
157597b2e202SAlex Deucher 	/* current power state that is active */
157697b2e202SAlex Deucher 	struct amdgpu_ps        *current_ps;
157797b2e202SAlex Deucher 	/* requested power state */
157897b2e202SAlex Deucher 	struct amdgpu_ps        *requested_ps;
157997b2e202SAlex Deucher 	/* boot up power state */
158097b2e202SAlex Deucher 	struct amdgpu_ps        *boot_ps;
158197b2e202SAlex Deucher 	/* default uvd power state */
158297b2e202SAlex Deucher 	struct amdgpu_ps        *uvd_ps;
158397b2e202SAlex Deucher 	/* vce requirements */
158497b2e202SAlex Deucher 	struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
158597b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
15863a2c788dSRex Zhu 	enum amd_pm_state_type state;
15873a2c788dSRex Zhu 	enum amd_pm_state_type user_state;
158897b2e202SAlex Deucher 	u32                     platform_caps;
158997b2e202SAlex Deucher 	u32                     voltage_response_time;
159097b2e202SAlex Deucher 	u32                     backbias_response_time;
159197b2e202SAlex Deucher 	void                    *priv;
159297b2e202SAlex Deucher 	u32			new_active_crtcs;
159397b2e202SAlex Deucher 	int			new_active_crtc_count;
159497b2e202SAlex Deucher 	u32			current_active_crtcs;
159597b2e202SAlex Deucher 	int			current_active_crtc_count;
159697b2e202SAlex Deucher 	struct amdgpu_dpm_dynamic_state dyn_state;
159797b2e202SAlex Deucher 	struct amdgpu_dpm_fan fan;
159897b2e202SAlex Deucher 	u32 tdp_limit;
159997b2e202SAlex Deucher 	u32 near_tdp_limit;
160097b2e202SAlex Deucher 	u32 near_tdp_limit_adjusted;
160197b2e202SAlex Deucher 	u32 sq_ramping_threshold;
160297b2e202SAlex Deucher 	u32 cac_leakage;
160397b2e202SAlex Deucher 	u16 tdp_od_limit;
160497b2e202SAlex Deucher 	u32 tdp_adjustment;
160597b2e202SAlex Deucher 	u16 load_line_slope;
160697b2e202SAlex Deucher 	bool power_control;
160797b2e202SAlex Deucher 	bool ac_power;
160897b2e202SAlex Deucher 	/* special states active */
160997b2e202SAlex Deucher 	bool                    thermal_active;
161097b2e202SAlex Deucher 	bool                    uvd_active;
161197b2e202SAlex Deucher 	bool                    vce_active;
161297b2e202SAlex Deucher 	/* thermal handling */
161397b2e202SAlex Deucher 	struct amdgpu_dpm_thermal thermal;
161497b2e202SAlex Deucher 	/* forced levels */
161597b2e202SAlex Deucher 	enum amdgpu_dpm_forced_level forced_level;
161697b2e202SAlex Deucher };
161797b2e202SAlex Deucher 
161897b2e202SAlex Deucher struct amdgpu_pm {
161997b2e202SAlex Deucher 	struct mutex		mutex;
162097b2e202SAlex Deucher 	u32                     current_sclk;
162197b2e202SAlex Deucher 	u32                     current_mclk;
162297b2e202SAlex Deucher 	u32                     default_sclk;
162397b2e202SAlex Deucher 	u32                     default_mclk;
162497b2e202SAlex Deucher 	struct amdgpu_i2c_chan *i2c_bus;
162597b2e202SAlex Deucher 	/* internal thermal controller on rv6xx+ */
162697b2e202SAlex Deucher 	enum amdgpu_int_thermal_type int_thermal_type;
162797b2e202SAlex Deucher 	struct device	        *int_hwmon_dev;
162897b2e202SAlex Deucher 	/* fan control parameters */
162997b2e202SAlex Deucher 	bool                    no_fan;
163097b2e202SAlex Deucher 	u8                      fan_pulses_per_revolution;
163197b2e202SAlex Deucher 	u8                      fan_min_rpm;
163297b2e202SAlex Deucher 	u8                      fan_max_rpm;
163397b2e202SAlex Deucher 	/* dpm */
163497b2e202SAlex Deucher 	bool                    dpm_enabled;
1635c86f5ebfSAlex Deucher 	bool                    sysfs_initialized;
163697b2e202SAlex Deucher 	struct amdgpu_dpm       dpm;
163797b2e202SAlex Deucher 	const struct firmware	*fw;	/* SMC firmware */
163897b2e202SAlex Deucher 	uint32_t                fw_version;
163997b2e202SAlex Deucher 	const struct amdgpu_dpm_funcs *funcs;
1640d0dd7f0cSAlex Deucher 	uint32_t                pcie_gen_mask;
1641d0dd7f0cSAlex Deucher 	uint32_t                pcie_mlw_mask;
16427fb72a1fSRex Zhu 	struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
164397b2e202SAlex Deucher };
164497b2e202SAlex Deucher 
1645d0dd7f0cSAlex Deucher void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1646d0dd7f0cSAlex Deucher 
164797b2e202SAlex Deucher /*
164897b2e202SAlex Deucher  * UVD
164997b2e202SAlex Deucher  */
1650c0365541SArindam Nath #define AMDGPU_DEFAULT_UVD_HANDLES	10
1651c0365541SArindam Nath #define AMDGPU_MAX_UVD_HANDLES		40
1652c0365541SArindam Nath #define AMDGPU_UVD_STACK_SIZE		(200*1024)
1653c0365541SArindam Nath #define AMDGPU_UVD_HEAP_SIZE		(256*1024)
1654c0365541SArindam Nath #define AMDGPU_UVD_SESSION_SIZE		(50*1024)
165597b2e202SAlex Deucher #define AMDGPU_UVD_FIRMWARE_OFFSET	256
165697b2e202SAlex Deucher 
165797b2e202SAlex Deucher struct amdgpu_uvd {
165897b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
165997b2e202SAlex Deucher 	void			*cpu_addr;
166097b2e202SAlex Deucher 	uint64_t		gpu_addr;
1661562e2689SSonny Jiang 	unsigned		fw_version;
16623f99dd81SLeo Liu 	void			*saved_bo;
1663c0365541SArindam Nath 	unsigned		max_handles;
166497b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_UVD_HANDLES];
166597b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_UVD_HANDLES];
166697b2e202SAlex Deucher 	struct delayed_work	idle_work;
166797b2e202SAlex Deucher 	const struct firmware	*fw;	/* UVD firmware */
166897b2e202SAlex Deucher 	struct amdgpu_ring	ring;
166997b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
167097b2e202SAlex Deucher 	bool			address_64_bit;
16714cb5877cSChristian König 	bool			use_ctx_buf;
1672ead833ecSChristian König 	struct amd_sched_entity entity;
1673fc0b3b90SChunming Zhou 	uint32_t                srbm_soft_reset;
167497b2e202SAlex Deucher };
167597b2e202SAlex Deucher 
167697b2e202SAlex Deucher /*
167797b2e202SAlex Deucher  * VCE
167897b2e202SAlex Deucher  */
167997b2e202SAlex Deucher #define AMDGPU_MAX_VCE_HANDLES	16
168097b2e202SAlex Deucher #define AMDGPU_VCE_FIRMWARE_OFFSET 256
168197b2e202SAlex Deucher 
16826a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
16836a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
16846a585777SAlex Deucher 
168597b2e202SAlex Deucher struct amdgpu_vce {
168697b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
168797b2e202SAlex Deucher 	uint64_t		gpu_addr;
168897b2e202SAlex Deucher 	unsigned		fw_version;
168997b2e202SAlex Deucher 	unsigned		fb_version;
169097b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
169197b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_VCE_HANDLES];
1692f1689ec1SChristian König 	uint32_t		img_size[AMDGPU_MAX_VCE_HANDLES];
169397b2e202SAlex Deucher 	struct delayed_work	idle_work;
1694ebff485eSChristian König 	struct mutex		idle_mutex;
169597b2e202SAlex Deucher 	const struct firmware	*fw;	/* VCE firmware */
169697b2e202SAlex Deucher 	struct amdgpu_ring	ring[AMDGPU_MAX_VCE_RINGS];
169797b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
16986a585777SAlex Deucher 	unsigned		harvest_config;
1699c594989cSChristian König 	struct amd_sched_entity	entity;
1700115933a5SChunming Zhou 	uint32_t                srbm_soft_reset;
170175c65480SAlex Deucher 	unsigned		num_rings;
170297b2e202SAlex Deucher };
170397b2e202SAlex Deucher 
170497b2e202SAlex Deucher /*
170597b2e202SAlex Deucher  * SDMA
170697b2e202SAlex Deucher  */
1707c113ea1cSAlex Deucher struct amdgpu_sdma_instance {
170897b2e202SAlex Deucher 	/* SDMA firmware */
170997b2e202SAlex Deucher 	const struct firmware	*fw;
171097b2e202SAlex Deucher 	uint32_t		fw_version;
1711cfa2104fSJammy Zhou 	uint32_t		feature_version;
171297b2e202SAlex Deucher 
171397b2e202SAlex Deucher 	struct amdgpu_ring	ring;
171418111de0SJammy Zhou 	bool			burst_nop;
171597b2e202SAlex Deucher };
171697b2e202SAlex Deucher 
1717c113ea1cSAlex Deucher struct amdgpu_sdma {
1718c113ea1cSAlex Deucher 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
171930d1574fSKen Wang #ifdef CONFIG_DRM_AMDGPU_SI
172030d1574fSKen Wang 	//SI DMA has a difference trap irq number for the second engine
172130d1574fSKen Wang 	struct amdgpu_irq_src	trap_irq_1;
172230d1574fSKen Wang #endif
1723c113ea1cSAlex Deucher 	struct amdgpu_irq_src	trap_irq;
1724c113ea1cSAlex Deucher 	struct amdgpu_irq_src	illegal_inst_irq;
1725c113ea1cSAlex Deucher 	int			num_instances;
1726e702a680SChunming Zhou 	uint32_t                    srbm_soft_reset;
1727c113ea1cSAlex Deucher };
1728c113ea1cSAlex Deucher 
172997b2e202SAlex Deucher /*
173097b2e202SAlex Deucher  * Firmware
173197b2e202SAlex Deucher  */
173297b2e202SAlex Deucher struct amdgpu_firmware {
173397b2e202SAlex Deucher 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
173497b2e202SAlex Deucher 	bool smu_load;
173597b2e202SAlex Deucher 	struct amdgpu_bo *fw_buf;
173697b2e202SAlex Deucher 	unsigned int fw_size;
173797b2e202SAlex Deucher };
173897b2e202SAlex Deucher 
173997b2e202SAlex Deucher /*
174097b2e202SAlex Deucher  * Benchmarking
174197b2e202SAlex Deucher  */
174297b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
174397b2e202SAlex Deucher 
174497b2e202SAlex Deucher 
174597b2e202SAlex Deucher /*
174697b2e202SAlex Deucher  * Testing
174797b2e202SAlex Deucher  */
174897b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
174997b2e202SAlex Deucher void amdgpu_test_ring_sync(struct amdgpu_device *adev,
175097b2e202SAlex Deucher 			   struct amdgpu_ring *cpA,
175197b2e202SAlex Deucher 			   struct amdgpu_ring *cpB);
175297b2e202SAlex Deucher void amdgpu_test_syncing(struct amdgpu_device *adev);
175397b2e202SAlex Deucher 
175497b2e202SAlex Deucher /*
175597b2e202SAlex Deucher  * MMU Notifier
175697b2e202SAlex Deucher  */
175797b2e202SAlex Deucher #if defined(CONFIG_MMU_NOTIFIER)
175897b2e202SAlex Deucher int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
175997b2e202SAlex Deucher void amdgpu_mn_unregister(struct amdgpu_bo *bo);
176097b2e202SAlex Deucher #else
17611d1106b0SHarry Wentland static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
176297b2e202SAlex Deucher {
176397b2e202SAlex Deucher 	return -ENODEV;
176497b2e202SAlex Deucher }
17651d1106b0SHarry Wentland static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
176697b2e202SAlex Deucher #endif
176797b2e202SAlex Deucher 
176897b2e202SAlex Deucher /*
176997b2e202SAlex Deucher  * Debugfs
177097b2e202SAlex Deucher  */
177197b2e202SAlex Deucher struct amdgpu_debugfs {
177206ab6832SNils Wallménius 	const struct drm_info_list	*files;
177397b2e202SAlex Deucher 	unsigned		num_files;
177497b2e202SAlex Deucher };
177597b2e202SAlex Deucher 
177697b2e202SAlex Deucher int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
177706ab6832SNils Wallménius 			     const struct drm_info_list *files,
177897b2e202SAlex Deucher 			     unsigned nfiles);
177997b2e202SAlex Deucher int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
178097b2e202SAlex Deucher 
178197b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
178297b2e202SAlex Deucher int amdgpu_debugfs_init(struct drm_minor *minor);
178397b2e202SAlex Deucher void amdgpu_debugfs_cleanup(struct drm_minor *minor);
178497b2e202SAlex Deucher #endif
178597b2e202SAlex Deucher 
178650ab2533SHuang Rui int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
178750ab2533SHuang Rui 
178897b2e202SAlex Deucher /*
178997b2e202SAlex Deucher  * amdgpu smumgr functions
179097b2e202SAlex Deucher  */
179197b2e202SAlex Deucher struct amdgpu_smumgr_funcs {
179297b2e202SAlex Deucher 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
179397b2e202SAlex Deucher 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
179497b2e202SAlex Deucher 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
179597b2e202SAlex Deucher };
179697b2e202SAlex Deucher 
179797b2e202SAlex Deucher /*
179897b2e202SAlex Deucher  * amdgpu smumgr
179997b2e202SAlex Deucher  */
180097b2e202SAlex Deucher struct amdgpu_smumgr {
180197b2e202SAlex Deucher 	struct amdgpu_bo *toc_buf;
180297b2e202SAlex Deucher 	struct amdgpu_bo *smu_buf;
180397b2e202SAlex Deucher 	/* asic priv smu data */
180497b2e202SAlex Deucher 	void *priv;
180597b2e202SAlex Deucher 	spinlock_t smu_lock;
180697b2e202SAlex Deucher 	/* smumgr functions */
180797b2e202SAlex Deucher 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
180897b2e202SAlex Deucher 	/* ucode loading complete flag */
180997b2e202SAlex Deucher 	uint32_t fw_flags;
181097b2e202SAlex Deucher };
181197b2e202SAlex Deucher 
181297b2e202SAlex Deucher /*
181397b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
181497b2e202SAlex Deucher  */
181597b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
181697b2e202SAlex Deucher 	uint32_t reg_offset;
181797b2e202SAlex Deucher 	bool untouched;
181897b2e202SAlex Deucher 	bool grbm_indexed;
181997b2e202SAlex Deucher };
182097b2e202SAlex Deucher 
182197b2e202SAlex Deucher /*
182297b2e202SAlex Deucher  * ASIC specific functions.
182397b2e202SAlex Deucher  */
182497b2e202SAlex Deucher struct amdgpu_asic_funcs {
182597b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
18267946b878SAlex Deucher 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
18277946b878SAlex Deucher 				   u8 *bios, u32 length_bytes);
182897b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
182997b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
183097b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
183197b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
183297b2e202SAlex Deucher 	/* get the reference clock */
183397b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
183497b2e202SAlex Deucher 	/* MM block clocks */
183597b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
183697b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1837048765adSAndres Rodriguez 	/* query virtual capabilities */
1838048765adSAndres Rodriguez 	u32 (*get_virtual_caps)(struct amdgpu_device *adev);
1839841686dfSMaruthi Bayyavarapu 	/* static power management */
1840841686dfSMaruthi Bayyavarapu 	int (*get_pcie_lanes)(struct amdgpu_device *adev);
1841841686dfSMaruthi Bayyavarapu 	void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
184297b2e202SAlex Deucher };
184397b2e202SAlex Deucher 
184497b2e202SAlex Deucher /*
184597b2e202SAlex Deucher  * IOCTL.
184697b2e202SAlex Deucher  */
184797b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
184897b2e202SAlex Deucher 			    struct drm_file *filp);
184997b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
185097b2e202SAlex Deucher 				struct drm_file *filp);
185197b2e202SAlex Deucher 
185297b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
185397b2e202SAlex Deucher 			  struct drm_file *filp);
185497b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
185597b2e202SAlex Deucher 			struct drm_file *filp);
185697b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
185797b2e202SAlex Deucher 			  struct drm_file *filp);
185897b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
185997b2e202SAlex Deucher 			      struct drm_file *filp);
186097b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
186197b2e202SAlex Deucher 			  struct drm_file *filp);
186297b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
186397b2e202SAlex Deucher 			struct drm_file *filp);
186497b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
186597b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
186697b2e202SAlex Deucher 
186797b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
186897b2e202SAlex Deucher 				struct drm_file *filp);
186997b2e202SAlex Deucher 
187097b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
187197b2e202SAlex Deucher struct amdgpu_vram_scratch {
187297b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
187397b2e202SAlex Deucher 	volatile uint32_t		*ptr;
187497b2e202SAlex Deucher 	u64				gpu_addr;
187597b2e202SAlex Deucher };
187697b2e202SAlex Deucher 
187797b2e202SAlex Deucher /*
187897b2e202SAlex Deucher  * ACPI
187997b2e202SAlex Deucher  */
188097b2e202SAlex Deucher struct amdgpu_atif_notification_cfg {
188197b2e202SAlex Deucher 	bool enabled;
188297b2e202SAlex Deucher 	int command_code;
188397b2e202SAlex Deucher };
188497b2e202SAlex Deucher 
188597b2e202SAlex Deucher struct amdgpu_atif_notifications {
188697b2e202SAlex Deucher 	bool display_switch;
188797b2e202SAlex Deucher 	bool expansion_mode_change;
188897b2e202SAlex Deucher 	bool thermal_state;
188997b2e202SAlex Deucher 	bool forced_power_state;
189097b2e202SAlex Deucher 	bool system_power_state;
189197b2e202SAlex Deucher 	bool display_conf_change;
189297b2e202SAlex Deucher 	bool px_gfx_switch;
189397b2e202SAlex Deucher 	bool brightness_change;
189497b2e202SAlex Deucher 	bool dgpu_display_event;
189597b2e202SAlex Deucher };
189697b2e202SAlex Deucher 
189797b2e202SAlex Deucher struct amdgpu_atif_functions {
189897b2e202SAlex Deucher 	bool system_params;
189997b2e202SAlex Deucher 	bool sbios_requests;
190097b2e202SAlex Deucher 	bool select_active_disp;
190197b2e202SAlex Deucher 	bool lid_state;
190297b2e202SAlex Deucher 	bool get_tv_standard;
190397b2e202SAlex Deucher 	bool set_tv_standard;
190497b2e202SAlex Deucher 	bool get_panel_expansion_mode;
190597b2e202SAlex Deucher 	bool set_panel_expansion_mode;
190697b2e202SAlex Deucher 	bool temperature_change;
190797b2e202SAlex Deucher 	bool graphics_device_types;
190897b2e202SAlex Deucher };
190997b2e202SAlex Deucher 
191097b2e202SAlex Deucher struct amdgpu_atif {
191197b2e202SAlex Deucher 	struct amdgpu_atif_notifications notifications;
191297b2e202SAlex Deucher 	struct amdgpu_atif_functions functions;
191397b2e202SAlex Deucher 	struct amdgpu_atif_notification_cfg notification_cfg;
191497b2e202SAlex Deucher 	struct amdgpu_encoder *encoder_for_bl;
191597b2e202SAlex Deucher };
191697b2e202SAlex Deucher 
191797b2e202SAlex Deucher struct amdgpu_atcs_functions {
191897b2e202SAlex Deucher 	bool get_ext_state;
191997b2e202SAlex Deucher 	bool pcie_perf_req;
192097b2e202SAlex Deucher 	bool pcie_dev_rdy;
192197b2e202SAlex Deucher 	bool pcie_bus_width;
192297b2e202SAlex Deucher };
192397b2e202SAlex Deucher 
192497b2e202SAlex Deucher struct amdgpu_atcs {
192597b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
192697b2e202SAlex Deucher };
192797b2e202SAlex Deucher 
192897b2e202SAlex Deucher /*
1929d03846afSChunming Zhou  * CGS
1930d03846afSChunming Zhou  */
1931110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1932110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1933a8fe58ceSMaruthi Bayyavarapu 
1934a8fe58ceSMaruthi Bayyavarapu 
19357e471e6fSAlex Deucher /* GPU virtualization */
1936048765adSAndres Rodriguez #define AMDGPU_VIRT_CAPS_SRIOV_EN       (1 << 0)
1937048765adSAndres Rodriguez #define AMDGPU_VIRT_CAPS_IS_VF          (1 << 1)
19387e471e6fSAlex Deucher struct amdgpu_virtualization {
19397e471e6fSAlex Deucher 	bool supports_sr_iov;
1940048765adSAndres Rodriguez 	bool is_virtual;
1941048765adSAndres Rodriguez 	u32 caps;
19427e471e6fSAlex Deucher };
19437e471e6fSAlex Deucher 
1944a8fe58ceSMaruthi Bayyavarapu /*
194597b2e202SAlex Deucher  * Core structure, functions and helpers.
194697b2e202SAlex Deucher  */
194797b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
194897b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
194997b2e202SAlex Deucher 
195097b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
195197b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
195297b2e202SAlex Deucher 
19538faf0e08SAlex Deucher struct amdgpu_ip_block_status {
19548faf0e08SAlex Deucher 	bool valid;
19558faf0e08SAlex Deucher 	bool sw;
19568faf0e08SAlex Deucher 	bool hw;
195763fbf42fSChunming Zhou 	bool hang;
19588faf0e08SAlex Deucher };
19598faf0e08SAlex Deucher 
196097b2e202SAlex Deucher struct amdgpu_device {
196197b2e202SAlex Deucher 	struct device			*dev;
196297b2e202SAlex Deucher 	struct drm_device		*ddev;
196397b2e202SAlex Deucher 	struct pci_dev			*pdev;
196497b2e202SAlex Deucher 
1965a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP
1966a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_acp		acp;
1967a8fe58ceSMaruthi Bayyavarapu #endif
1968a8fe58ceSMaruthi Bayyavarapu 
196997b2e202SAlex Deucher 	/* ASIC */
19702f7d10b3SJammy Zhou 	enum amd_asic_type		asic_type;
197197b2e202SAlex Deucher 	uint32_t			family;
197297b2e202SAlex Deucher 	uint32_t			rev_id;
197397b2e202SAlex Deucher 	uint32_t			external_rev_id;
197497b2e202SAlex Deucher 	unsigned long			flags;
197597b2e202SAlex Deucher 	int				usec_timeout;
197697b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
197797b2e202SAlex Deucher 	bool				shutdown;
197897b2e202SAlex Deucher 	bool				need_dma32;
197997b2e202SAlex Deucher 	bool				accel_working;
198097b2e202SAlex Deucher 	struct work_struct		reset_work;
198197b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
198297b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
198397b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
198497b2e202SAlex Deucher 	unsigned			debugfs_count;
198597b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
1986adcec288STom St Denis 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
198797b2e202SAlex Deucher #endif
198897b2e202SAlex Deucher 	struct amdgpu_atif		atif;
198997b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
199097b2e202SAlex Deucher 	struct mutex			srbm_mutex;
199197b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
199297b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
199397b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
199497b2e202SAlex Deucher 	bool				have_disp_power_ref;
199597b2e202SAlex Deucher 
199697b2e202SAlex Deucher 	/* BIOS */
199797b2e202SAlex Deucher 	uint8_t				*bios;
199897b2e202SAlex Deucher 	bool				is_atom_bios;
199997b2e202SAlex Deucher 	struct amdgpu_bo		*stollen_vga_memory;
200097b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
200197b2e202SAlex Deucher 
200297b2e202SAlex Deucher 	/* Register/doorbell mmio */
200397b2e202SAlex Deucher 	resource_size_t			rmmio_base;
200497b2e202SAlex Deucher 	resource_size_t			rmmio_size;
200597b2e202SAlex Deucher 	void __iomem			*rmmio;
200697b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
200797b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
200897b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
200997b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
201097b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
201197b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
201297b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
201397b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
201497b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
201597b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
201636b9a952SHuang Rui 	amdgpu_rreg_t			pciep_rreg;
201736b9a952SHuang Rui 	amdgpu_wreg_t			pciep_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 
205895844d20SMarek Olšák 	/* data for buffer migration throttling */
205995844d20SMarek Olšák 	struct {
206095844d20SMarek Olšák 		spinlock_t		lock;
206195844d20SMarek Olšák 		s64			last_update_us;
206295844d20SMarek Olšák 		s64			accum_us; /* accumulated microseconds */
206395844d20SMarek Olšák 		u32			log2_max_MBps;
206495844d20SMarek Olšák 	} mm_stats;
206595844d20SMarek Olšák 
206697b2e202SAlex Deucher 	/* display */
20679accf2fdSEmily Deng 	bool				enable_virtual_display;
206897b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
206997b2e202SAlex Deucher 	struct work_struct		hotplug_work;
207097b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
207197b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
207297b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
207397b2e202SAlex Deucher 
207497b2e202SAlex Deucher 	/* rings */
207576bf0db5SChristian König 	u64				fence_context;
207697b2e202SAlex Deucher 	unsigned			num_rings;
207797b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
207897b2e202SAlex Deucher 	bool				ib_pool_ready;
207997b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
208097b2e202SAlex Deucher 
208197b2e202SAlex Deucher 	/* interrupts */
208297b2e202SAlex Deucher 	struct amdgpu_irq		irq;
208397b2e202SAlex Deucher 
20841f7371b2SAlex Deucher 	/* powerplay */
20851f7371b2SAlex Deucher 	struct amd_powerplay		powerplay;
2086e61710c5SJammy Zhou 	bool				pp_enabled;
2087f3898ea1SEric Huang 	bool				pp_force_state_enabled;
20881f7371b2SAlex Deucher 
208997b2e202SAlex Deucher 	/* dpm */
209097b2e202SAlex Deucher 	struct amdgpu_pm		pm;
209197b2e202SAlex Deucher 	u32				cg_flags;
209297b2e202SAlex Deucher 	u32				pg_flags;
209397b2e202SAlex Deucher 
209497b2e202SAlex Deucher 	/* amdgpu smumgr */
209597b2e202SAlex Deucher 	struct amdgpu_smumgr smu;
209697b2e202SAlex Deucher 
209797b2e202SAlex Deucher 	/* gfx */
209897b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
209997b2e202SAlex Deucher 
210097b2e202SAlex Deucher 	/* sdma */
2101c113ea1cSAlex Deucher 	struct amdgpu_sdma		sdma;
210297b2e202SAlex Deucher 
210397b2e202SAlex Deucher 	/* uvd */
210497b2e202SAlex Deucher 	struct amdgpu_uvd		uvd;
210597b2e202SAlex Deucher 
210697b2e202SAlex Deucher 	/* vce */
210797b2e202SAlex Deucher 	struct amdgpu_vce		vce;
210897b2e202SAlex Deucher 
210997b2e202SAlex Deucher 	/* firmwares */
211097b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
211197b2e202SAlex Deucher 
211297b2e202SAlex Deucher 	/* GDS */
211397b2e202SAlex Deucher 	struct amdgpu_gds		gds;
211497b2e202SAlex Deucher 
211597b2e202SAlex Deucher 	const struct amdgpu_ip_block_version *ip_blocks;
211697b2e202SAlex Deucher 	int				num_ip_blocks;
21178faf0e08SAlex Deucher 	struct amdgpu_ip_block_status	*ip_block_status;
211897b2e202SAlex Deucher 	struct mutex	mn_lock;
211997b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
212097b2e202SAlex Deucher 
212197b2e202SAlex Deucher 	/* tracking pinned memory */
212297b2e202SAlex Deucher 	u64 vram_pin_size;
2123e131b914SChunming Zhou 	u64 invisible_pin_size;
212497b2e202SAlex Deucher 	u64 gart_pin_size;
2125130e0371SOded Gabbay 
2126130e0371SOded Gabbay 	/* amdkfd interface */
2127130e0371SOded Gabbay 	struct kfd_dev          *kfd;
212823ca0e4eSChunming Zhou 
21297e471e6fSAlex Deucher 	struct amdgpu_virtualization virtualization;
21300c4e7fa5SChunming Zhou 
21310c4e7fa5SChunming Zhou 	/* link all shadow bo */
21320c4e7fa5SChunming Zhou 	struct list_head                shadow_list;
21330c4e7fa5SChunming Zhou 	struct mutex                    shadow_list_lock;
21345c1354bdSChunming Zhou 	/* link all gtt */
21355c1354bdSChunming Zhou 	spinlock_t			gtt_list_lock;
21365c1354bdSChunming Zhou 	struct list_head                gtt_list;
21375c1354bdSChunming Zhou 
213897b2e202SAlex Deucher };
213997b2e202SAlex Deucher 
214097b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
214197b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
214297b2e202SAlex Deucher 		       struct drm_device *ddev,
214397b2e202SAlex Deucher 		       struct pci_dev *pdev,
214497b2e202SAlex Deucher 		       uint32_t flags);
214597b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
214697b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
214797b2e202SAlex Deucher 
214897b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
214997b2e202SAlex Deucher 			bool always_indirect);
215097b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
215197b2e202SAlex Deucher 		    bool always_indirect);
215297b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
215397b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
215497b2e202SAlex Deucher 
215597b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
215697b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
215797b2e202SAlex Deucher 
215897b2e202SAlex Deucher /*
215997b2e202SAlex Deucher  * Registers read & write functions.
216097b2e202SAlex Deucher  */
216197b2e202SAlex Deucher #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
216297b2e202SAlex Deucher #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
216397b2e202SAlex Deucher #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
216497b2e202SAlex Deucher #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
216597b2e202SAlex Deucher #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
216697b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
216797b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
216897b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
216997b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
217036b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
217136b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
217297b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
217397b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
217497b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
217597b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
217697b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
217797b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2178ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
2179ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
218097b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
218197b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
218297b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
218397b2e202SAlex Deucher 	do {							\
218497b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
218597b2e202SAlex Deucher 		tmp_ &= (mask);					\
218697b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
218797b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
218897b2e202SAlex Deucher 	} while (0)
218997b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
219097b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
219197b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
219297b2e202SAlex Deucher 	do {							\
219397b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
219497b2e202SAlex Deucher 		tmp_ &= (mask);					\
219597b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
219697b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
219797b2e202SAlex Deucher 	} while (0)
219897b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
219997b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
220097b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
220197b2e202SAlex Deucher 
220297b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
220397b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
220497b2e202SAlex Deucher 
220597b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
220697b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
220797b2e202SAlex Deucher 
220897b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
220997b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
221097b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
221197b2e202SAlex Deucher 
221297b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
221397b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
221497b2e202SAlex Deucher 
221561cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val)	\
221661cb8cefSTom St Denis 	WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
221761cb8cefSTom St Denis 
221897b2e202SAlex Deucher /*
221997b2e202SAlex Deucher  * BIOS helpers.
222097b2e202SAlex Deucher  */
222197b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
222297b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
222397b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
222497b2e202SAlex Deucher 
222597b2e202SAlex Deucher /*
222697b2e202SAlex Deucher  * RING helpers.
222797b2e202SAlex Deucher  */
222897b2e202SAlex Deucher static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
222997b2e202SAlex Deucher {
223097b2e202SAlex Deucher 	if (ring->count_dw <= 0)
223186c2b790SJammy Zhou 		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
223297b2e202SAlex Deucher 	ring->ring[ring->wptr++] = v;
223397b2e202SAlex Deucher 	ring->wptr &= ring->ptr_mask;
223497b2e202SAlex Deucher 	ring->count_dw--;
223597b2e202SAlex Deucher }
223697b2e202SAlex Deucher 
2237c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance *
2238c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
22394b2f7e2cSJammy Zhou {
22404b2f7e2cSJammy Zhou 	struct amdgpu_device *adev = ring->adev;
22414b2f7e2cSJammy Zhou 	int i;
22424b2f7e2cSJammy Zhou 
2243c113ea1cSAlex Deucher 	for (i = 0; i < adev->sdma.num_instances; i++)
2244c113ea1cSAlex Deucher 		if (&adev->sdma.instance[i].ring == ring)
22454b2f7e2cSJammy Zhou 			break;
22464b2f7e2cSJammy Zhou 
22474b2f7e2cSJammy Zhou 	if (i < AMDGPU_MAX_SDMA_INSTANCES)
2248c113ea1cSAlex Deucher 		return &adev->sdma.instance[i];
22494b2f7e2cSJammy Zhou 	else
22504b2f7e2cSJammy Zhou 		return NULL;
22514b2f7e2cSJammy Zhou }
22524b2f7e2cSJammy Zhou 
225397b2e202SAlex Deucher /*
225497b2e202SAlex Deucher  * ASICs macro.
225597b2e202SAlex Deucher  */
225697b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
225797b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
225897b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
225997b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
226097b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2261048765adSAndres Rodriguez #define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
2262841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
2263841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
2264841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
226597b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
22667946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
226797b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
226897b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
226997b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
227097b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
2271de9ea7bdSChristian König #define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
227297b2e202SAlex 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)))
227397b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
227497b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2275bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
227697b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
227797b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
227897b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2279d88bf583SChristian König #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
2280b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
228197b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
2282890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
228397b2e202SAlex 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))
2284d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
228511afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
2286c2167a65SMonk Liu #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
2287753ad49cSMonk Liu #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
22889e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
228903ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
229003ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
229197b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
229297b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
229397b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
229497b2e202SAlex Deucher #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
229597b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
229697b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
229797b2e202SAlex Deucher #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
229897b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
229997b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
230097b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
230197b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
230297b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
230397b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2304cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
230597b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
230697b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
230797b2e202SAlex 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))
230897b2e202SAlex Deucher #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
230997b2e202SAlex Deucher #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
2310c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b))
23116e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
231297b2e202SAlex Deucher #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
231397b2e202SAlex Deucher #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
231497b2e202SAlex Deucher #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
231597b2e202SAlex Deucher #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
231697b2e202SAlex Deucher #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
231797b2e202SAlex Deucher #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
231897b2e202SAlex Deucher #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
2319b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
23209559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
23213af76f23SRex Zhu 
23223af76f23SRex Zhu #define amdgpu_dpm_get_temperature(adev) \
23234b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23243af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
23254b5ece24SEric Huang 	      (adev)->pm.funcs->get_temperature((adev)))
23263af76f23SRex Zhu 
23273af76f23SRex Zhu #define amdgpu_dpm_set_fan_control_mode(adev, m) \
23284b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23293af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
23304b5ece24SEric Huang 	      (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
23313af76f23SRex Zhu 
23323af76f23SRex Zhu #define amdgpu_dpm_get_fan_control_mode(adev) \
23334b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23343af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
23354b5ece24SEric Huang 	      (adev)->pm.funcs->get_fan_control_mode((adev)))
23363af76f23SRex Zhu 
23373af76f23SRex Zhu #define amdgpu_dpm_set_fan_speed_percent(adev, s) \
23384b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23393af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
23404b5ece24SEric Huang 	      (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
23413af76f23SRex Zhu 
23423af76f23SRex Zhu #define amdgpu_dpm_get_fan_speed_percent(adev, s) \
23434b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23443af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
23454b5ece24SEric Huang 	      (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
234697b2e202SAlex Deucher 
23471b5708ffSRex Zhu #define amdgpu_dpm_get_sclk(adev, l) \
23484b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23491b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
23504b5ece24SEric Huang 		(adev)->pm.funcs->get_sclk((adev), (l)))
23511b5708ffSRex Zhu 
23521b5708ffSRex Zhu #define amdgpu_dpm_get_mclk(adev, l)  \
23534b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23541b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
23554b5ece24SEric Huang 	      (adev)->pm.funcs->get_mclk((adev), (l)))
23561b5708ffSRex Zhu 
23571b5708ffSRex Zhu 
23581b5708ffSRex Zhu #define amdgpu_dpm_force_performance_level(adev, l) \
23594b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23601b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
23614b5ece24SEric Huang 	      (adev)->pm.funcs->force_performance_level((adev), (l)))
23621b5708ffSRex Zhu 
23631b5708ffSRex Zhu #define amdgpu_dpm_powergate_uvd(adev, g) \
23644b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23651b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
23664b5ece24SEric Huang 	      (adev)->pm.funcs->powergate_uvd((adev), (g)))
23671b5708ffSRex Zhu 
23681b5708ffSRex Zhu #define amdgpu_dpm_powergate_vce(adev, g) \
23694b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23701b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
23714b5ece24SEric Huang 	      (adev)->pm.funcs->powergate_vce((adev), (g)))
23721b5708ffSRex Zhu 
23731b5708ffSRex Zhu #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
23744b5ece24SEric Huang 	((adev)->pp_enabled ?						\
23751b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
23764b5ece24SEric Huang 	      (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
23771b5708ffSRex Zhu 
23781b5708ffSRex Zhu #define amdgpu_dpm_get_current_power_state(adev) \
23791b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
23801b5708ffSRex Zhu 
23811b5708ffSRex Zhu #define amdgpu_dpm_get_performance_level(adev) \
23821b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
23831b5708ffSRex Zhu 
2384f3898ea1SEric Huang #define amdgpu_dpm_get_pp_num_states(adev, data) \
2385f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2386f3898ea1SEric Huang 
2387f3898ea1SEric Huang #define amdgpu_dpm_get_pp_table(adev, table) \
2388f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2389f3898ea1SEric Huang 
2390f3898ea1SEric Huang #define amdgpu_dpm_set_pp_table(adev, buf, size) \
2391f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2392f3898ea1SEric Huang 
2393f3898ea1SEric Huang #define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2394f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2395f3898ea1SEric Huang 
2396f3898ea1SEric Huang #define amdgpu_dpm_force_clock_level(adev, type, level) \
2397f3898ea1SEric Huang 		(adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2398f3898ea1SEric Huang 
2399428bafa8SEric Huang #define amdgpu_dpm_get_sclk_od(adev) \
2400428bafa8SEric Huang 	(adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2401428bafa8SEric Huang 
2402428bafa8SEric Huang #define amdgpu_dpm_set_sclk_od(adev, value) \
2403428bafa8SEric Huang 	(adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2404428bafa8SEric Huang 
2405f2bdc05fSEric Huang #define amdgpu_dpm_get_mclk_od(adev) \
2406f2bdc05fSEric Huang 	((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2407f2bdc05fSEric Huang 
2408f2bdc05fSEric Huang #define amdgpu_dpm_set_mclk_od(adev, value) \
2409f2bdc05fSEric Huang 	((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2410f2bdc05fSEric Huang 
24111b5708ffSRex Zhu #define amdgpu_dpm_dispatch_task(adev, event_id, input, output)		\
24121b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
241397b2e202SAlex Deucher 
241497b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
241597b2e202SAlex Deucher 
241697b2e202SAlex Deucher /* Common functions */
241797b2e202SAlex Deucher int amdgpu_gpu_reset(struct amdgpu_device *adev);
24183ad81f16SChunming Zhou bool amdgpu_need_backup(struct amdgpu_device *adev);
241997b2e202SAlex Deucher void amdgpu_pci_config_reset(struct amdgpu_device *adev);
242097b2e202SAlex Deucher bool amdgpu_card_posted(struct amdgpu_device *adev);
242197b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev);
2422d5fc5e82SChunming Zhou 
242397b2e202SAlex Deucher int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
242497b2e202SAlex Deucher int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
242597b2e202SAlex Deucher 		       u32 ip_instance, u32 ring,
242697b2e202SAlex Deucher 		       struct amdgpu_ring **out_ring);
242797b2e202SAlex Deucher void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
242897b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
24292f568dbdSChristian König int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
243097b2e202SAlex Deucher int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
243197b2e202SAlex Deucher 				     uint32_t flags);
243297b2e202SAlex Deucher bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
2433cc325d19SChristian König struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
2434d7006964SChristian König bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2435d7006964SChristian König 				  unsigned long end);
24362f568dbdSChristian König bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
24372f568dbdSChristian König 				       int *last_invalidated);
243897b2e202SAlex Deucher bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
243997b2e202SAlex Deucher uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
244097b2e202SAlex Deucher 				 struct ttm_mem_reg *mem);
244197b2e202SAlex Deucher void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
244297b2e202SAlex Deucher void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
244397b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2444a693e050SKen Wang u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2445a693e050SKen Wang int amdgpu_ttm_global_init(struct amdgpu_device *adev);
244697b2e202SAlex Deucher void amdgpu_program_register_sequence(struct amdgpu_device *adev,
244797b2e202SAlex Deucher 					     const u32 *registers,
244897b2e202SAlex Deucher 					     const u32 array_size);
244997b2e202SAlex Deucher 
245097b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
245197b2e202SAlex Deucher /* atpx handler */
245297b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
245397b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
245497b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
2455a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void);
24562f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void);
245797b2e202SAlex Deucher #else
245897b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
245997b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
2460a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
24612f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
246297b2e202SAlex Deucher #endif
246397b2e202SAlex Deucher 
246497b2e202SAlex Deucher /*
246597b2e202SAlex Deucher  * KMS
246697b2e202SAlex Deucher  */
246797b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2468f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl;
246997b2e202SAlex Deucher 
247097b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
247197b2e202SAlex Deucher int amdgpu_driver_unload_kms(struct drm_device *dev);
247297b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
247397b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
247497b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
247597b2e202SAlex Deucher 				 struct drm_file *file_priv);
247697b2e202SAlex Deucher void amdgpu_driver_preclose_kms(struct drm_device *dev,
247797b2e202SAlex Deucher 				struct drm_file *file_priv);
2478810ddc3aSAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
2479810ddc3aSAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
248088e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
248188e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
248288e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
248388e72717SThierry Reding int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
248497b2e202SAlex Deucher 				    int *max_error,
248597b2e202SAlex Deucher 				    struct timeval *vblank_time,
248697b2e202SAlex Deucher 				    unsigned flags);
248797b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
248897b2e202SAlex Deucher 			     unsigned long arg);
248997b2e202SAlex Deucher 
249097b2e202SAlex Deucher /*
249197b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
249297b2e202SAlex Deucher  */
249397b2e202SAlex Deucher struct amdgpu_afmt_acr {
249497b2e202SAlex Deucher 	u32 clock;
249597b2e202SAlex Deucher 
249697b2e202SAlex Deucher 	int n_32khz;
249797b2e202SAlex Deucher 	int cts_32khz;
249897b2e202SAlex Deucher 
249997b2e202SAlex Deucher 	int n_44_1khz;
250097b2e202SAlex Deucher 	int cts_44_1khz;
250197b2e202SAlex Deucher 
250297b2e202SAlex Deucher 	int n_48khz;
250397b2e202SAlex Deucher 	int cts_48khz;
250497b2e202SAlex Deucher 
250597b2e202SAlex Deucher };
250697b2e202SAlex Deucher 
250797b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
250897b2e202SAlex Deucher 
250997b2e202SAlex Deucher /* amdgpu_acpi.c */
251097b2e202SAlex Deucher #if defined(CONFIG_ACPI)
251197b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
251297b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
251397b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
251497b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
251597b2e202SAlex Deucher 						u8 perf_req, bool advertise);
251697b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
251797b2e202SAlex Deucher #else
251897b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
251997b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
252097b2e202SAlex Deucher #endif
252197b2e202SAlex Deucher 
252297b2e202SAlex Deucher struct amdgpu_bo_va_mapping *
252397b2e202SAlex Deucher amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
252497b2e202SAlex Deucher 		       uint64_t addr, struct amdgpu_bo **bo);
2525c855e250SChristian König int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
252697b2e202SAlex Deucher 
252797b2e202SAlex Deucher #include "amdgpu_object.h"
252897b2e202SAlex Deucher #endif
2529