xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu.h (revision 0de2479c)
197b2e202SAlex Deucher /*
297b2e202SAlex Deucher  * Copyright 2008 Advanced Micro Devices, Inc.
397b2e202SAlex Deucher  * Copyright 2008 Red Hat Inc.
497b2e202SAlex Deucher  * Copyright 2009 Jerome Glisse.
597b2e202SAlex Deucher  *
697b2e202SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
797b2e202SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
897b2e202SAlex Deucher  * to deal in the Software without restriction, including without limitation
997b2e202SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1097b2e202SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
1197b2e202SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
1297b2e202SAlex Deucher  *
1397b2e202SAlex Deucher  * The above copyright notice and this permission notice shall be included in
1497b2e202SAlex Deucher  * all copies or substantial portions of the Software.
1597b2e202SAlex Deucher  *
1697b2e202SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1797b2e202SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1897b2e202SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1997b2e202SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
2097b2e202SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2197b2e202SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2297b2e202SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
2397b2e202SAlex Deucher  *
2497b2e202SAlex Deucher  * Authors: Dave Airlie
2597b2e202SAlex Deucher  *          Alex Deucher
2697b2e202SAlex Deucher  *          Jerome Glisse
2797b2e202SAlex Deucher  */
2897b2e202SAlex Deucher #ifndef __AMDGPU_H__
2997b2e202SAlex Deucher #define __AMDGPU_H__
3097b2e202SAlex Deucher 
3197b2e202SAlex Deucher #include <linux/atomic.h>
3297b2e202SAlex Deucher #include <linux/wait.h>
3397b2e202SAlex Deucher #include <linux/list.h>
3497b2e202SAlex Deucher #include <linux/kref.h>
3597b2e202SAlex Deucher #include <linux/interval_tree.h>
3697b2e202SAlex Deucher #include <linux/hashtable.h>
3797b2e202SAlex Deucher #include <linux/fence.h>
3897b2e202SAlex Deucher 
3997b2e202SAlex Deucher #include <ttm/ttm_bo_api.h>
4097b2e202SAlex Deucher #include <ttm/ttm_bo_driver.h>
4197b2e202SAlex Deucher #include <ttm/ttm_placement.h>
4297b2e202SAlex Deucher #include <ttm/ttm_module.h>
4397b2e202SAlex Deucher #include <ttm/ttm_execbuf_util.h>
4497b2e202SAlex Deucher 
45d03846afSChunming Zhou #include <drm/drmP.h>
4697b2e202SAlex Deucher #include <drm/drm_gem.h>
477e5a547fSChunming Zhou #include <drm/amdgpu_drm.h>
4897b2e202SAlex Deucher 
495fc3aeebSyanyang1 #include "amd_shared.h"
5097b2e202SAlex Deucher #include "amdgpu_mode.h"
5197b2e202SAlex Deucher #include "amdgpu_ih.h"
5297b2e202SAlex Deucher #include "amdgpu_irq.h"
5397b2e202SAlex Deucher #include "amdgpu_ucode.h"
5497b2e202SAlex Deucher #include "amdgpu_gds.h"
551f7371b2SAlex Deucher #include "amd_powerplay.h"
56a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h"
5797b2e202SAlex Deucher 
58b80d8475SAlex Deucher #include "gpu_scheduler.h"
59b80d8475SAlex Deucher 
6097b2e202SAlex Deucher /*
6197b2e202SAlex Deucher  * Modules parameters.
6297b2e202SAlex Deucher  */
6397b2e202SAlex Deucher extern int amdgpu_modeset;
6497b2e202SAlex Deucher extern int amdgpu_vram_limit;
6597b2e202SAlex Deucher extern int amdgpu_gart_size;
6697b2e202SAlex Deucher extern int amdgpu_benchmarking;
6797b2e202SAlex Deucher extern int amdgpu_testing;
6897b2e202SAlex Deucher extern int amdgpu_audio;
6997b2e202SAlex Deucher extern int amdgpu_disp_priority;
7097b2e202SAlex Deucher extern int amdgpu_hw_i2c;
7197b2e202SAlex Deucher extern int amdgpu_pcie_gen2;
7297b2e202SAlex Deucher extern int amdgpu_msi;
7397b2e202SAlex Deucher extern int amdgpu_lockup_timeout;
7497b2e202SAlex Deucher extern int amdgpu_dpm;
7597b2e202SAlex Deucher extern int amdgpu_smc_load_fw;
7697b2e202SAlex Deucher extern int amdgpu_aspm;
7797b2e202SAlex Deucher extern int amdgpu_runtime_pm;
7897b2e202SAlex Deucher extern unsigned amdgpu_ip_block_mask;
7997b2e202SAlex Deucher extern int amdgpu_bapm;
8097b2e202SAlex Deucher extern int amdgpu_deep_color;
8197b2e202SAlex Deucher extern int amdgpu_vm_size;
8297b2e202SAlex Deucher extern int amdgpu_vm_block_size;
83d9c13156SChristian König extern int amdgpu_vm_fault_stop;
84b495bd3aSChristian König extern int amdgpu_vm_debug;
851333f723SJammy Zhou extern int amdgpu_sched_jobs;
864afcb303SJammy Zhou extern int amdgpu_sched_hw_submission;
871f7371b2SAlex Deucher extern int amdgpu_powerplay;
88cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_gen_cap;
89cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_lane_cap;
9097b2e202SAlex Deucher 
914b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
9297b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
9397b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
9497b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
9597b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE			16
9697b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
9797b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT			4
9897b2e202SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH			8
9997b2e202SAlex Deucher 
10097b2e202SAlex Deucher /* max number of rings */
10197b2e202SAlex Deucher #define AMDGPU_MAX_RINGS			16
10297b2e202SAlex Deucher #define AMDGPU_MAX_GFX_RINGS			1
10397b2e202SAlex Deucher #define AMDGPU_MAX_COMPUTE_RINGS		8
10497b2e202SAlex Deucher #define AMDGPU_MAX_VCE_RINGS			2
10597b2e202SAlex Deucher 
10636f523a7SJammy Zhou /* max number of IP instances */
10736f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES		2
10836f523a7SJammy Zhou 
10997b2e202SAlex Deucher /* hardcode that limit for now */
11097b2e202SAlex Deucher #define AMDGPU_VA_RESERVED_SIZE			(8 << 20)
11197b2e202SAlex Deucher 
11297b2e202SAlex Deucher /* hard reset data */
11397b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
11497b2e202SAlex Deucher 
11597b2e202SAlex Deucher /* reset flags */
11697b2e202SAlex Deucher #define AMDGPU_RESET_GFX			(1 << 0)
11797b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE			(1 << 1)
11897b2e202SAlex Deucher #define AMDGPU_RESET_DMA			(1 << 2)
11997b2e202SAlex Deucher #define AMDGPU_RESET_CP				(1 << 3)
12097b2e202SAlex Deucher #define AMDGPU_RESET_GRBM			(1 << 4)
12197b2e202SAlex Deucher #define AMDGPU_RESET_DMA1			(1 << 5)
12297b2e202SAlex Deucher #define AMDGPU_RESET_RLC			(1 << 6)
12397b2e202SAlex Deucher #define AMDGPU_RESET_SEM			(1 << 7)
12497b2e202SAlex Deucher #define AMDGPU_RESET_IH				(1 << 8)
12597b2e202SAlex Deucher #define AMDGPU_RESET_VMC			(1 << 9)
12697b2e202SAlex Deucher #define AMDGPU_RESET_MC				(1 << 10)
12797b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY			(1 << 11)
12897b2e202SAlex Deucher #define AMDGPU_RESET_UVD			(1 << 12)
12997b2e202SAlex Deucher #define AMDGPU_RESET_VCE			(1 << 13)
13097b2e202SAlex Deucher #define AMDGPU_RESET_VCE1			(1 << 14)
13197b2e202SAlex Deucher 
13297b2e202SAlex Deucher /* GFX current status */
13397b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
13497b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE			0x00000001L
13597b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
13697b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
13797b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
13897b2e202SAlex Deucher 
13997b2e202SAlex Deucher /* max cursor sizes (in pixels) */
14097b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128
14197b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128
14297b2e202SAlex Deucher 
14397b2e202SAlex Deucher struct amdgpu_device;
14497b2e202SAlex Deucher struct amdgpu_ib;
14597b2e202SAlex Deucher struct amdgpu_vm;
14697b2e202SAlex Deucher struct amdgpu_ring;
14797b2e202SAlex Deucher struct amdgpu_cs_parser;
148bb977d37SChunming Zhou struct amdgpu_job;
14997b2e202SAlex Deucher struct amdgpu_irq_src;
1500b492a4cSAlex Deucher struct amdgpu_fpriv;
15197b2e202SAlex Deucher 
15297b2e202SAlex Deucher enum amdgpu_cp_irq {
15397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_GFX_EOP = 0,
15497b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
15597b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
15697b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
15797b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
15897b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
15997b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
16097b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
16197b2e202SAlex Deucher 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
16297b2e202SAlex Deucher 
16397b2e202SAlex Deucher 	AMDGPU_CP_IRQ_LAST
16497b2e202SAlex Deucher };
16597b2e202SAlex Deucher 
16697b2e202SAlex Deucher enum amdgpu_sdma_irq {
16797b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
16897b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_TRAP1,
16997b2e202SAlex Deucher 
17097b2e202SAlex Deucher 	AMDGPU_SDMA_IRQ_LAST
17197b2e202SAlex Deucher };
17297b2e202SAlex Deucher 
17397b2e202SAlex Deucher enum amdgpu_thermal_irq {
17497b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
17597b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
17697b2e202SAlex Deucher 
17797b2e202SAlex Deucher 	AMDGPU_THERMAL_IRQ_LAST
17897b2e202SAlex Deucher };
17997b2e202SAlex Deucher 
18097b2e202SAlex Deucher int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
1815fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
1825fc3aeebSyanyang1 				  enum amd_clockgating_state state);
18397b2e202SAlex Deucher int amdgpu_set_powergating_state(struct amdgpu_device *adev,
1845fc3aeebSyanyang1 				  enum amd_ip_block_type block_type,
1855fc3aeebSyanyang1 				  enum amd_powergating_state state);
18697b2e202SAlex Deucher 
18797b2e202SAlex Deucher struct amdgpu_ip_block_version {
1885fc3aeebSyanyang1 	enum amd_ip_block_type type;
18997b2e202SAlex Deucher 	u32 major;
19097b2e202SAlex Deucher 	u32 minor;
19197b2e202SAlex Deucher 	u32 rev;
1925fc3aeebSyanyang1 	const struct amd_ip_funcs *funcs;
19397b2e202SAlex Deucher };
19497b2e202SAlex Deucher 
19597b2e202SAlex Deucher int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
1965fc3aeebSyanyang1 				enum amd_ip_block_type type,
19797b2e202SAlex Deucher 				u32 major, u32 minor);
19897b2e202SAlex Deucher 
19997b2e202SAlex Deucher const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
20097b2e202SAlex Deucher 					struct amdgpu_device *adev,
2015fc3aeebSyanyang1 					enum amd_ip_block_type type);
20297b2e202SAlex Deucher 
20397b2e202SAlex Deucher /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
20497b2e202SAlex Deucher struct amdgpu_buffer_funcs {
20597b2e202SAlex Deucher 	/* maximum bytes in a single operation */
20697b2e202SAlex Deucher 	uint32_t	copy_max_bytes;
20797b2e202SAlex Deucher 
20897b2e202SAlex Deucher 	/* number of dw to reserve per operation */
20997b2e202SAlex Deucher 	unsigned	copy_num_dw;
21097b2e202SAlex Deucher 
21197b2e202SAlex Deucher 	/* used for buffer migration */
212c7ae72c0SChunming Zhou 	void (*emit_copy_buffer)(struct amdgpu_ib *ib,
21397b2e202SAlex Deucher 				 /* src addr in bytes */
21497b2e202SAlex Deucher 				 uint64_t src_offset,
21597b2e202SAlex Deucher 				 /* dst addr in bytes */
21697b2e202SAlex Deucher 				 uint64_t dst_offset,
21797b2e202SAlex Deucher 				 /* number of byte to transfer */
21897b2e202SAlex Deucher 				 uint32_t byte_count);
21997b2e202SAlex Deucher 
22097b2e202SAlex Deucher 	/* maximum bytes in a single operation */
22197b2e202SAlex Deucher 	uint32_t	fill_max_bytes;
22297b2e202SAlex Deucher 
22397b2e202SAlex Deucher 	/* number of dw to reserve per operation */
22497b2e202SAlex Deucher 	unsigned	fill_num_dw;
22597b2e202SAlex Deucher 
22697b2e202SAlex Deucher 	/* used for buffer clearing */
2276e7a3840SChunming Zhou 	void (*emit_fill_buffer)(struct amdgpu_ib *ib,
22897b2e202SAlex Deucher 				 /* value to write to memory */
22997b2e202SAlex Deucher 				 uint32_t src_data,
23097b2e202SAlex Deucher 				 /* dst addr in bytes */
23197b2e202SAlex Deucher 				 uint64_t dst_offset,
23297b2e202SAlex Deucher 				 /* number of byte to fill */
23397b2e202SAlex Deucher 				 uint32_t byte_count);
23497b2e202SAlex Deucher };
23597b2e202SAlex Deucher 
23697b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */
23797b2e202SAlex Deucher struct amdgpu_vm_pte_funcs {
23897b2e202SAlex Deucher 	/* copy pte entries from GART */
23997b2e202SAlex Deucher 	void (*copy_pte)(struct amdgpu_ib *ib,
24097b2e202SAlex Deucher 			 uint64_t pe, uint64_t src,
24197b2e202SAlex Deucher 			 unsigned count);
24297b2e202SAlex Deucher 	/* write pte one entry at a time with addr mapping */
24397b2e202SAlex Deucher 	void (*write_pte)(struct amdgpu_ib *ib,
244b07c9d2aSChristian König 			  const dma_addr_t *pages_addr, uint64_t pe,
24597b2e202SAlex Deucher 			  uint64_t addr, unsigned count,
24697b2e202SAlex Deucher 			  uint32_t incr, uint32_t flags);
24797b2e202SAlex Deucher 	/* for linear pte/pde updates without addr mapping */
24897b2e202SAlex Deucher 	void (*set_pte_pde)(struct amdgpu_ib *ib,
24997b2e202SAlex Deucher 			    uint64_t pe,
25097b2e202SAlex Deucher 			    uint64_t addr, unsigned count,
25197b2e202SAlex Deucher 			    uint32_t incr, uint32_t flags);
25297b2e202SAlex Deucher };
25397b2e202SAlex Deucher 
25497b2e202SAlex Deucher /* provided by the gmc block */
25597b2e202SAlex Deucher struct amdgpu_gart_funcs {
25697b2e202SAlex Deucher 	/* flush the vm tlb via mmio */
25797b2e202SAlex Deucher 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
25897b2e202SAlex Deucher 			      uint32_t vmid);
25997b2e202SAlex Deucher 	/* write pte/pde updates using the cpu */
26097b2e202SAlex Deucher 	int (*set_pte_pde)(struct amdgpu_device *adev,
26197b2e202SAlex Deucher 			   void *cpu_pt_addr, /* cpu addr of page table */
26297b2e202SAlex Deucher 			   uint32_t gpu_page_idx, /* pte/pde to update */
26397b2e202SAlex Deucher 			   uint64_t addr, /* addr to write into pte/pde */
26497b2e202SAlex Deucher 			   uint32_t flags); /* access flags */
26597b2e202SAlex Deucher };
26697b2e202SAlex Deucher 
26797b2e202SAlex Deucher /* provided by the ih block */
26897b2e202SAlex Deucher struct amdgpu_ih_funcs {
26997b2e202SAlex Deucher 	/* ring read/write ptr handling, called from interrupt context */
27097b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_device *adev);
27197b2e202SAlex Deucher 	void (*decode_iv)(struct amdgpu_device *adev,
27297b2e202SAlex Deucher 			  struct amdgpu_iv_entry *entry);
27397b2e202SAlex Deucher 	void (*set_rptr)(struct amdgpu_device *adev);
27497b2e202SAlex Deucher };
27597b2e202SAlex Deucher 
27697b2e202SAlex Deucher /* provided by hw blocks that expose a ring buffer for commands */
27797b2e202SAlex Deucher struct amdgpu_ring_funcs {
27897b2e202SAlex Deucher 	/* ring read/write ptr handling */
27997b2e202SAlex Deucher 	u32 (*get_rptr)(struct amdgpu_ring *ring);
28097b2e202SAlex Deucher 	u32 (*get_wptr)(struct amdgpu_ring *ring);
28197b2e202SAlex Deucher 	void (*set_wptr)(struct amdgpu_ring *ring);
28297b2e202SAlex Deucher 	/* validating and patching of IBs */
28397b2e202SAlex Deucher 	int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
28497b2e202SAlex Deucher 	/* command emit functions */
28597b2e202SAlex Deucher 	void (*emit_ib)(struct amdgpu_ring *ring,
28697b2e202SAlex Deucher 			struct amdgpu_ib *ib);
28797b2e202SAlex Deucher 	void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
288890ee23fSChunming Zhou 			   uint64_t seq, unsigned flags);
289b8c7b39eSChristian König 	void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
29097b2e202SAlex Deucher 	void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
29197b2e202SAlex Deucher 			      uint64_t pd_addr);
292d2edb07bSChristian König 	void (*emit_hdp_flush)(struct amdgpu_ring *ring);
29311afbde8SChunming Zhou 	void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
29497b2e202SAlex Deucher 	void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
29597b2e202SAlex Deucher 				uint32_t gds_base, uint32_t gds_size,
29697b2e202SAlex Deucher 				uint32_t gws_base, uint32_t gws_size,
29797b2e202SAlex Deucher 				uint32_t oa_base, uint32_t oa_size);
29897b2e202SAlex Deucher 	/* testing functions */
29997b2e202SAlex Deucher 	int (*test_ring)(struct amdgpu_ring *ring);
30097b2e202SAlex Deucher 	int (*test_ib)(struct amdgpu_ring *ring);
301edff0e28SJammy Zhou 	/* insert NOP packets */
302edff0e28SJammy Zhou 	void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
3039e5d5309SChristian König 	/* pad the indirect buffer to the necessary number of dw */
3049e5d5309SChristian König 	void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
30503ccf481SMonk Liu 	unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
30603ccf481SMonk Liu 	void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
30797b2e202SAlex Deucher };
30897b2e202SAlex Deucher 
30997b2e202SAlex Deucher /*
31097b2e202SAlex Deucher  * BIOS.
31197b2e202SAlex Deucher  */
31297b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev);
31397b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev);
31497b2e202SAlex Deucher 
31597b2e202SAlex Deucher /*
31697b2e202SAlex Deucher  * Dummy page
31797b2e202SAlex Deucher  */
31897b2e202SAlex Deucher struct amdgpu_dummy_page {
31997b2e202SAlex Deucher 	struct page	*page;
32097b2e202SAlex Deucher 	dma_addr_t	addr;
32197b2e202SAlex Deucher };
32297b2e202SAlex Deucher int amdgpu_dummy_page_init(struct amdgpu_device *adev);
32397b2e202SAlex Deucher void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
32497b2e202SAlex Deucher 
32597b2e202SAlex Deucher 
32697b2e202SAlex Deucher /*
32797b2e202SAlex Deucher  * Clocks
32897b2e202SAlex Deucher  */
32997b2e202SAlex Deucher 
33097b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3
33197b2e202SAlex Deucher 
33297b2e202SAlex Deucher struct amdgpu_clock {
33397b2e202SAlex Deucher 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
33497b2e202SAlex Deucher 	struct amdgpu_pll spll;
33597b2e202SAlex Deucher 	struct amdgpu_pll mpll;
33697b2e202SAlex Deucher 	/* 10 Khz units */
33797b2e202SAlex Deucher 	uint32_t default_mclk;
33897b2e202SAlex Deucher 	uint32_t default_sclk;
33997b2e202SAlex Deucher 	uint32_t default_dispclk;
34097b2e202SAlex Deucher 	uint32_t current_dispclk;
34197b2e202SAlex Deucher 	uint32_t dp_extclk;
34297b2e202SAlex Deucher 	uint32_t max_pixel_clock;
34397b2e202SAlex Deucher };
34497b2e202SAlex Deucher 
34597b2e202SAlex Deucher /*
34697b2e202SAlex Deucher  * Fences.
34797b2e202SAlex Deucher  */
34897b2e202SAlex Deucher struct amdgpu_fence_driver {
34997b2e202SAlex Deucher 	uint64_t			gpu_addr;
35097b2e202SAlex Deucher 	volatile uint32_t		*cpu_addr;
35197b2e202SAlex Deucher 	/* sync_seq is protected by ring emission lock */
352742c085fSChristian König 	uint32_t			sync_seq;
353742c085fSChristian König 	atomic_t			last_seq;
35497b2e202SAlex Deucher 	bool				initialized;
35597b2e202SAlex Deucher 	struct amdgpu_irq_src		*irq_src;
35697b2e202SAlex Deucher 	unsigned			irq_type;
357c2776afeSChristian König 	struct timer_list		fallback_timer;
358c89377d1SChristian König 	unsigned			num_fences_mask;
3594a7d74f1SChristian König 	spinlock_t			lock;
360c89377d1SChristian König 	struct fence			**fences;
36197b2e202SAlex Deucher };
36297b2e202SAlex Deucher 
36397b2e202SAlex Deucher /* some special values for the owner field */
36497b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_UNDEFINED	((void*)0ul)
36597b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_VM		((void*)1ul)
36697b2e202SAlex Deucher 
367890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_64BIT         (1 << 0)
368890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_INT           (1 << 1)
369890ee23fSChunming Zhou 
37097b2e202SAlex Deucher struct amdgpu_user_fence {
37197b2e202SAlex Deucher 	/* write-back bo */
37297b2e202SAlex Deucher 	struct amdgpu_bo 	*bo;
37397b2e202SAlex Deucher 	/* write-back address offset to bo start */
37497b2e202SAlex Deucher 	uint32_t                offset;
37597b2e202SAlex Deucher };
37697b2e202SAlex Deucher 
37797b2e202SAlex Deucher int amdgpu_fence_driver_init(struct amdgpu_device *adev);
37897b2e202SAlex Deucher void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
37997b2e202SAlex Deucher void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
38097b2e202SAlex Deucher 
381e6151a08SChristian König int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
382e6151a08SChristian König 				  unsigned num_hw_submission);
38397b2e202SAlex Deucher int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
38497b2e202SAlex Deucher 				   struct amdgpu_irq_src *irq_src,
38597b2e202SAlex Deucher 				   unsigned irq_type);
3865ceb54c6SAlex Deucher void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
3875ceb54c6SAlex Deucher void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
388364beb2cSChristian König int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
38997b2e202SAlex Deucher void amdgpu_fence_process(struct amdgpu_ring *ring);
39097b2e202SAlex Deucher int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
39197b2e202SAlex Deucher unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
39297b2e202SAlex Deucher 
39397b2e202SAlex Deucher /*
39497b2e202SAlex Deucher  * TTM.
39597b2e202SAlex Deucher  */
39697b2e202SAlex Deucher struct amdgpu_mman {
39797b2e202SAlex Deucher 	struct ttm_bo_global_ref        bo_global_ref;
39897b2e202SAlex Deucher 	struct drm_global_reference	mem_global_ref;
39997b2e202SAlex Deucher 	struct ttm_bo_device		bdev;
40097b2e202SAlex Deucher 	bool				mem_global_referenced;
40197b2e202SAlex Deucher 	bool				initialized;
40297b2e202SAlex Deucher 
40397b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
40497b2e202SAlex Deucher 	struct dentry			*vram;
40597b2e202SAlex Deucher 	struct dentry			*gtt;
40697b2e202SAlex Deucher #endif
40797b2e202SAlex Deucher 
40897b2e202SAlex Deucher 	/* buffer handling */
40997b2e202SAlex Deucher 	const struct amdgpu_buffer_funcs	*buffer_funcs;
41097b2e202SAlex Deucher 	struct amdgpu_ring			*buffer_funcs_ring;
411703297c1SChristian König 	/* Scheduler entity for buffer moves */
412703297c1SChristian König 	struct amd_sched_entity			entity;
41397b2e202SAlex Deucher };
41497b2e202SAlex Deucher 
41597b2e202SAlex Deucher int amdgpu_copy_buffer(struct amdgpu_ring *ring,
41697b2e202SAlex Deucher 		       uint64_t src_offset,
41797b2e202SAlex Deucher 		       uint64_t dst_offset,
41897b2e202SAlex Deucher 		       uint32_t byte_count,
41997b2e202SAlex Deucher 		       struct reservation_object *resv,
420c7ae72c0SChunming Zhou 		       struct fence **fence);
42197b2e202SAlex Deucher int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
42297b2e202SAlex Deucher 
42397b2e202SAlex Deucher struct amdgpu_bo_list_entry {
42497b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
42597b2e202SAlex Deucher 	struct ttm_validate_buffer	tv;
42697b2e202SAlex Deucher 	struct amdgpu_bo_va		*bo_va;
42797b2e202SAlex Deucher 	uint32_t			priority;
4282f568dbdSChristian König 	struct page			**user_pages;
4292f568dbdSChristian König 	int				user_invalidated;
43097b2e202SAlex Deucher };
43197b2e202SAlex Deucher 
43297b2e202SAlex Deucher struct amdgpu_bo_va_mapping {
43397b2e202SAlex Deucher 	struct list_head		list;
43497b2e202SAlex Deucher 	struct interval_tree_node	it;
43597b2e202SAlex Deucher 	uint64_t			offset;
43697b2e202SAlex Deucher 	uint32_t			flags;
43797b2e202SAlex Deucher };
43897b2e202SAlex Deucher 
43997b2e202SAlex Deucher /* bo virtual addresses in a specific vm */
44097b2e202SAlex Deucher struct amdgpu_bo_va {
44197b2e202SAlex Deucher 	/* protected by bo being reserved */
44297b2e202SAlex Deucher 	struct list_head		bo_list;
443bb1e38a4SChunming Zhou 	struct fence		        *last_pt_update;
44497b2e202SAlex Deucher 	unsigned			ref_count;
44597b2e202SAlex Deucher 
4467fc11959SChristian König 	/* protected by vm mutex and spinlock */
44797b2e202SAlex Deucher 	struct list_head		vm_status;
44897b2e202SAlex Deucher 
4497fc11959SChristian König 	/* mappings for this bo_va */
4507fc11959SChristian König 	struct list_head		invalids;
4517fc11959SChristian König 	struct list_head		valids;
4527fc11959SChristian König 
45397b2e202SAlex Deucher 	/* constant after initialization */
45497b2e202SAlex Deucher 	struct amdgpu_vm		*vm;
45597b2e202SAlex Deucher 	struct amdgpu_bo		*bo;
45697b2e202SAlex Deucher };
45797b2e202SAlex Deucher 
4587e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX		0x3
4597e5a547fSChunming Zhou 
46097b2e202SAlex Deucher struct amdgpu_bo {
46197b2e202SAlex Deucher 	/* Protected by gem.mutex */
46297b2e202SAlex Deucher 	struct list_head		list;
46397b2e202SAlex Deucher 	/* Protected by tbo.reserved */
4641ea863fdSChristian König 	u32				prefered_domains;
4651ea863fdSChristian König 	u32				allowed_domains;
4667e5a547fSChunming Zhou 	struct ttm_place		placements[AMDGPU_GEM_DOMAIN_MAX + 1];
46797b2e202SAlex Deucher 	struct ttm_placement		placement;
46897b2e202SAlex Deucher 	struct ttm_buffer_object	tbo;
46997b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		kmap;
47097b2e202SAlex Deucher 	u64				flags;
47197b2e202SAlex Deucher 	unsigned			pin_count;
47297b2e202SAlex Deucher 	void				*kptr;
47397b2e202SAlex Deucher 	u64				tiling_flags;
47497b2e202SAlex Deucher 	u64				metadata_flags;
47597b2e202SAlex Deucher 	void				*metadata;
47697b2e202SAlex Deucher 	u32				metadata_size;
47797b2e202SAlex Deucher 	/* list of all virtual address to which this bo
47897b2e202SAlex Deucher 	 * is associated to
47997b2e202SAlex Deucher 	 */
48097b2e202SAlex Deucher 	struct list_head		va;
48197b2e202SAlex Deucher 	/* Constant after initialization */
48297b2e202SAlex Deucher 	struct amdgpu_device		*adev;
48397b2e202SAlex Deucher 	struct drm_gem_object		gem_base;
48482b9c55bSChristian König 	struct amdgpu_bo		*parent;
48597b2e202SAlex Deucher 
48697b2e202SAlex Deucher 	struct ttm_bo_kmap_obj		dma_buf_vmap;
48797b2e202SAlex Deucher 	struct amdgpu_mn		*mn;
48897b2e202SAlex Deucher 	struct list_head		mn_list;
48997b2e202SAlex Deucher };
49097b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
49197b2e202SAlex Deucher 
49297b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj);
49397b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj,
49497b2e202SAlex Deucher 				struct drm_file *file_priv);
49597b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj,
49697b2e202SAlex Deucher 				struct drm_file *file_priv);
49797b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
49897b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
49997b2e202SAlex Deucher struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
50097b2e202SAlex Deucher 							struct dma_buf_attachment *attach,
50197b2e202SAlex Deucher 							struct sg_table *sg);
50297b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
50397b2e202SAlex Deucher 					struct drm_gem_object *gobj,
50497b2e202SAlex Deucher 					int flags);
50597b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
50697b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
50797b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
50897b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
50997b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
51097b2e202SAlex Deucher int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
51197b2e202SAlex Deucher 
51297b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock.
51397b2e202SAlex Deucher  * By conception this is an helper for other part of the driver
51497b2e202SAlex Deucher  * like the indirect buffer or semaphore, which both have their
51597b2e202SAlex Deucher  * locking.
51697b2e202SAlex Deucher  *
51797b2e202SAlex Deucher  * Principe is simple, we keep a list of sub allocation in offset
51897b2e202SAlex Deucher  * order (first entry has offset == 0, last entry has the highest
51997b2e202SAlex Deucher  * offset).
52097b2e202SAlex Deucher  *
52197b2e202SAlex Deucher  * When allocating new object we first check if there is room at
52297b2e202SAlex Deucher  * the end total_size - (last_object_offset + last_object_size) >=
52397b2e202SAlex Deucher  * alloc_size. If so we allocate new object there.
52497b2e202SAlex Deucher  *
52597b2e202SAlex Deucher  * When there is not enough room at the end, we start waiting for
52697b2e202SAlex Deucher  * each sub object until we reach object_offset+object_size >=
52797b2e202SAlex Deucher  * alloc_size, this object then become the sub object we return.
52897b2e202SAlex Deucher  *
52997b2e202SAlex Deucher  * Alignment can't be bigger than page size.
53097b2e202SAlex Deucher  *
53197b2e202SAlex Deucher  * Hole are not considered for allocation to keep things simple.
53297b2e202SAlex Deucher  * Assumption is that there won't be hole (all object on same
53397b2e202SAlex Deucher  * alignment).
53497b2e202SAlex Deucher  */
5356ba60b89SChristian König 
5366ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS	32
5376ba60b89SChristian König 
53897b2e202SAlex Deucher struct amdgpu_sa_manager {
53997b2e202SAlex Deucher 	wait_queue_head_t	wq;
54097b2e202SAlex Deucher 	struct amdgpu_bo	*bo;
54197b2e202SAlex Deucher 	struct list_head	*hole;
5426ba60b89SChristian König 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
54397b2e202SAlex Deucher 	struct list_head	olist;
54497b2e202SAlex Deucher 	unsigned		size;
54597b2e202SAlex Deucher 	uint64_t		gpu_addr;
54697b2e202SAlex Deucher 	void			*cpu_ptr;
54797b2e202SAlex Deucher 	uint32_t		domain;
54897b2e202SAlex Deucher 	uint32_t		align;
54997b2e202SAlex Deucher };
55097b2e202SAlex Deucher 
55197b2e202SAlex Deucher /* sub-allocation buffer */
55297b2e202SAlex Deucher struct amdgpu_sa_bo {
55397b2e202SAlex Deucher 	struct list_head		olist;
55497b2e202SAlex Deucher 	struct list_head		flist;
55597b2e202SAlex Deucher 	struct amdgpu_sa_manager	*manager;
55697b2e202SAlex Deucher 	unsigned			soffset;
55797b2e202SAlex Deucher 	unsigned			eoffset;
5584ce9891eSChunming Zhou 	struct fence		        *fence;
55997b2e202SAlex Deucher };
56097b2e202SAlex Deucher 
56197b2e202SAlex Deucher /*
56297b2e202SAlex Deucher  * GEM objects.
56397b2e202SAlex Deucher  */
564418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev);
56597b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
56697b2e202SAlex Deucher 				int alignment, u32 initial_domain,
56797b2e202SAlex Deucher 				u64 flags, bool kernel,
56897b2e202SAlex Deucher 				struct drm_gem_object **obj);
56997b2e202SAlex Deucher 
57097b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv,
57197b2e202SAlex Deucher 			    struct drm_device *dev,
57297b2e202SAlex Deucher 			    struct drm_mode_create_dumb *args);
57397b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp,
57497b2e202SAlex Deucher 			  struct drm_device *dev,
57597b2e202SAlex Deucher 			  uint32_t handle, uint64_t *offset_p);
57697b2e202SAlex Deucher /*
57797b2e202SAlex Deucher  * Synchronization
57897b2e202SAlex Deucher  */
57997b2e202SAlex Deucher struct amdgpu_sync {
580f91b3a69SChristian König 	DECLARE_HASHTABLE(fences, 4);
5813c62338cSChunming Zhou 	struct fence	        *last_vm_update;
58297b2e202SAlex Deucher };
58397b2e202SAlex Deucher 
58497b2e202SAlex Deucher void amdgpu_sync_create(struct amdgpu_sync *sync);
58591e1a520SChristian König int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
58691e1a520SChristian König 		      struct fence *f);
58797b2e202SAlex Deucher int amdgpu_sync_resv(struct amdgpu_device *adev,
58897b2e202SAlex Deucher 		     struct amdgpu_sync *sync,
58997b2e202SAlex Deucher 		     struct reservation_object *resv,
59097b2e202SAlex Deucher 		     void *owner);
591e61235dbSChristian König struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
592f91b3a69SChristian König int amdgpu_sync_wait(struct amdgpu_sync *sync);
5938a8f0b48SChristian König void amdgpu_sync_free(struct amdgpu_sync *sync);
594257bf15aSChristian König int amdgpu_sync_init(void);
595257bf15aSChristian König void amdgpu_sync_fini(void);
59697b2e202SAlex Deucher 
59797b2e202SAlex Deucher /*
59897b2e202SAlex Deucher  * GART structures, functions & helpers
59997b2e202SAlex Deucher  */
60097b2e202SAlex Deucher struct amdgpu_mc;
60197b2e202SAlex Deucher 
60297b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SIZE 4096
60397b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
60497b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SHIFT 12
60597b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
60697b2e202SAlex Deucher 
60797b2e202SAlex Deucher struct amdgpu_gart {
60897b2e202SAlex Deucher 	dma_addr_t			table_addr;
60997b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
61097b2e202SAlex Deucher 	void				*ptr;
61197b2e202SAlex Deucher 	unsigned			num_gpu_pages;
61297b2e202SAlex Deucher 	unsigned			num_cpu_pages;
61397b2e202SAlex Deucher 	unsigned			table_size;
61497b2e202SAlex Deucher 	struct page			**pages;
61597b2e202SAlex Deucher 	dma_addr_t			*pages_addr;
61697b2e202SAlex Deucher 	bool				ready;
61797b2e202SAlex Deucher 	const struct amdgpu_gart_funcs *gart_funcs;
61897b2e202SAlex Deucher };
61997b2e202SAlex Deucher 
62097b2e202SAlex Deucher int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
62197b2e202SAlex Deucher void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
62297b2e202SAlex Deucher int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
62397b2e202SAlex Deucher void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
62497b2e202SAlex Deucher int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
62597b2e202SAlex Deucher void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
62697b2e202SAlex Deucher int amdgpu_gart_init(struct amdgpu_device *adev);
62797b2e202SAlex Deucher void amdgpu_gart_fini(struct amdgpu_device *adev);
62897b2e202SAlex Deucher void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
62997b2e202SAlex Deucher 			int pages);
63097b2e202SAlex Deucher int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
63197b2e202SAlex Deucher 		     int pages, struct page **pagelist,
63297b2e202SAlex Deucher 		     dma_addr_t *dma_addr, uint32_t flags);
63397b2e202SAlex Deucher 
63497b2e202SAlex Deucher /*
63597b2e202SAlex Deucher  * GPU MC structures, functions & helpers
63697b2e202SAlex Deucher  */
63797b2e202SAlex Deucher struct amdgpu_mc {
63897b2e202SAlex Deucher 	resource_size_t		aper_size;
63997b2e202SAlex Deucher 	resource_size_t		aper_base;
64097b2e202SAlex Deucher 	resource_size_t		agp_base;
64197b2e202SAlex Deucher 	/* for some chips with <= 32MB we need to lie
64297b2e202SAlex Deucher 	 * about vram size near mc fb location */
64397b2e202SAlex Deucher 	u64			mc_vram_size;
64497b2e202SAlex Deucher 	u64			visible_vram_size;
64597b2e202SAlex Deucher 	u64			gtt_size;
64697b2e202SAlex Deucher 	u64			gtt_start;
64797b2e202SAlex Deucher 	u64			gtt_end;
64897b2e202SAlex Deucher 	u64			vram_start;
64997b2e202SAlex Deucher 	u64			vram_end;
65097b2e202SAlex Deucher 	unsigned		vram_width;
65197b2e202SAlex Deucher 	u64			real_vram_size;
65297b2e202SAlex Deucher 	int			vram_mtrr;
65397b2e202SAlex Deucher 	u64                     gtt_base_align;
65497b2e202SAlex Deucher 	u64                     mc_mask;
65597b2e202SAlex Deucher 	const struct firmware   *fw;	/* MC firmware */
65697b2e202SAlex Deucher 	uint32_t                fw_version;
65797b2e202SAlex Deucher 	struct amdgpu_irq_src	vm_fault;
65881c59f54SKen Wang 	uint32_t		vram_type;
65997b2e202SAlex Deucher };
66097b2e202SAlex Deucher 
66197b2e202SAlex Deucher /*
66297b2e202SAlex Deucher  * GPU doorbell structures, functions & helpers
66397b2e202SAlex Deucher  */
66497b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
66597b2e202SAlex Deucher {
66697b2e202SAlex Deucher 	AMDGPU_DOORBELL_KIQ                     = 0x000,
66797b2e202SAlex Deucher 	AMDGPU_DOORBELL_HIQ                     = 0x001,
66897b2e202SAlex Deucher 	AMDGPU_DOORBELL_DIQ                     = 0x002,
66997b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
67097b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
67197b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
67297b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
67397b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
67497b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
67597b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
67697b2e202SAlex Deucher 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
67797b2e202SAlex Deucher 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
67897b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
67997b2e202SAlex Deucher 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
68097b2e202SAlex Deucher 	AMDGPU_DOORBELL_IH                      = 0x1E8,
68197b2e202SAlex Deucher 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
68297b2e202SAlex Deucher 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
68397b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT;
68497b2e202SAlex Deucher 
68597b2e202SAlex Deucher struct amdgpu_doorbell {
68697b2e202SAlex Deucher 	/* doorbell mmio */
68797b2e202SAlex Deucher 	resource_size_t		base;
68897b2e202SAlex Deucher 	resource_size_t		size;
68997b2e202SAlex Deucher 	u32 __iomem		*ptr;
69097b2e202SAlex Deucher 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
69197b2e202SAlex Deucher };
69297b2e202SAlex Deucher 
69397b2e202SAlex Deucher void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
69497b2e202SAlex Deucher 				phys_addr_t *aperture_base,
69597b2e202SAlex Deucher 				size_t *aperture_size,
69697b2e202SAlex Deucher 				size_t *start_offset);
69797b2e202SAlex Deucher 
69897b2e202SAlex Deucher /*
69997b2e202SAlex Deucher  * IRQS.
70097b2e202SAlex Deucher  */
70197b2e202SAlex Deucher 
70297b2e202SAlex Deucher struct amdgpu_flip_work {
70397b2e202SAlex Deucher 	struct work_struct		flip_work;
70497b2e202SAlex Deucher 	struct work_struct		unpin_work;
70597b2e202SAlex Deucher 	struct amdgpu_device		*adev;
70697b2e202SAlex Deucher 	int				crtc_id;
70797b2e202SAlex Deucher 	uint64_t			base;
70897b2e202SAlex Deucher 	struct drm_pending_vblank_event *event;
70997b2e202SAlex Deucher 	struct amdgpu_bo		*old_rbo;
7101ffd2652SChristian König 	struct fence			*excl;
7111ffd2652SChristian König 	unsigned			shared_count;
7121ffd2652SChristian König 	struct fence			**shared;
713c3874b75SChristian König 	struct fence_cb			cb;
71497b2e202SAlex Deucher };
71597b2e202SAlex Deucher 
71697b2e202SAlex Deucher 
71797b2e202SAlex Deucher /*
71897b2e202SAlex Deucher  * CP & rings.
71997b2e202SAlex Deucher  */
72097b2e202SAlex Deucher 
72197b2e202SAlex Deucher struct amdgpu_ib {
72297b2e202SAlex Deucher 	struct amdgpu_sa_bo		*sa_bo;
72397b2e202SAlex Deucher 	uint32_t			length_dw;
72497b2e202SAlex Deucher 	uint64_t			gpu_addr;
72597b2e202SAlex Deucher 	uint32_t			*ptr;
72697b2e202SAlex Deucher 	struct amdgpu_user_fence        *user;
72797b2e202SAlex Deucher 	struct amdgpu_vm		*vm;
7284ff37a83SChristian König 	unsigned			vm_id;
7294ff37a83SChristian König 	uint64_t			vm_pd_addr;
7303cb485f3SChristian König 	struct amdgpu_ctx		*ctx;
73197b2e202SAlex Deucher 	uint32_t			gds_base, gds_size;
73297b2e202SAlex Deucher 	uint32_t			gws_base, gws_size;
73397b2e202SAlex Deucher 	uint32_t			oa_base, oa_size;
734de807f81SJammy Zhou 	uint32_t			flags;
7355430a3ffSChristian König 	/* resulting sequence number */
7365430a3ffSChristian König 	uint64_t			sequence;
73797b2e202SAlex Deucher };
73897b2e202SAlex Deucher 
73997b2e202SAlex Deucher enum amdgpu_ring_type {
74097b2e202SAlex Deucher 	AMDGPU_RING_TYPE_GFX,
74197b2e202SAlex Deucher 	AMDGPU_RING_TYPE_COMPUTE,
74297b2e202SAlex Deucher 	AMDGPU_RING_TYPE_SDMA,
74397b2e202SAlex Deucher 	AMDGPU_RING_TYPE_UVD,
74497b2e202SAlex Deucher 	AMDGPU_RING_TYPE_VCE
74597b2e202SAlex Deucher };
74697b2e202SAlex Deucher 
747c1b69ed0SChunming Zhou extern struct amd_sched_backend_ops amdgpu_sched_ops;
748c1b69ed0SChunming Zhou 
74950838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
75050838c8cSChristian König 		     struct amdgpu_job **job);
751d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
752d71518b5SChristian König 			     struct amdgpu_job **job);
75350838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job);
754d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
7552bd9ccfaSChristian König 		      struct amd_sched_entity *entity, void *owner,
7562bd9ccfaSChristian König 		      struct fence **f);
7570de2479cSMonk Liu void amdgpu_job_timeout_func(struct work_struct *work);
7583c704e93SChunming Zhou 
75997b2e202SAlex Deucher struct amdgpu_ring {
76097b2e202SAlex Deucher 	struct amdgpu_device		*adev;
76197b2e202SAlex Deucher 	const struct amdgpu_ring_funcs	*funcs;
76297b2e202SAlex Deucher 	struct amdgpu_fence_driver	fence_drv;
7634f839a24SChristian König 	struct amd_gpu_scheduler 	sched;
76497b2e202SAlex Deucher 
765176e1ab1SChunming Zhou 	spinlock_t              fence_lock;
76697b2e202SAlex Deucher 	struct amdgpu_bo	*ring_obj;
76797b2e202SAlex Deucher 	volatile uint32_t	*ring;
76897b2e202SAlex Deucher 	unsigned		rptr_offs;
76997b2e202SAlex Deucher 	u64			next_rptr_gpu_addr;
77097b2e202SAlex Deucher 	volatile u32		*next_rptr_cpu_addr;
77197b2e202SAlex Deucher 	unsigned		wptr;
77297b2e202SAlex Deucher 	unsigned		wptr_old;
77397b2e202SAlex Deucher 	unsigned		ring_size;
774c7e6be23SChristian König 	unsigned		max_dw;
77597b2e202SAlex Deucher 	int			count_dw;
77697b2e202SAlex Deucher 	uint64_t		gpu_addr;
77797b2e202SAlex Deucher 	uint32_t		align_mask;
77897b2e202SAlex Deucher 	uint32_t		ptr_mask;
77997b2e202SAlex Deucher 	bool			ready;
78097b2e202SAlex Deucher 	u32			nop;
78197b2e202SAlex Deucher 	u32			idx;
78297b2e202SAlex Deucher 	u32			me;
78397b2e202SAlex Deucher 	u32			pipe;
78497b2e202SAlex Deucher 	u32			queue;
78597b2e202SAlex Deucher 	struct amdgpu_bo	*mqd_obj;
78697b2e202SAlex Deucher 	u32			doorbell_index;
78797b2e202SAlex Deucher 	bool			use_doorbell;
78897b2e202SAlex Deucher 	unsigned		wptr_offs;
78997b2e202SAlex Deucher 	unsigned		next_rptr_offs;
79097b2e202SAlex Deucher 	unsigned		fence_offs;
7913cb485f3SChristian König 	struct amdgpu_ctx	*current_ctx;
79297b2e202SAlex Deucher 	enum amdgpu_ring_type	type;
79397b2e202SAlex Deucher 	char			name[16];
794128cff1aSMonk Liu 	unsigned		cond_exe_offs;
795128cff1aSMonk Liu 	u64				cond_exe_gpu_addr;
796128cff1aSMonk Liu 	volatile u32	*cond_exe_cpu_addr;
79797b2e202SAlex Deucher };
79897b2e202SAlex Deucher 
79997b2e202SAlex Deucher /*
80097b2e202SAlex Deucher  * VM
80197b2e202SAlex Deucher  */
80297b2e202SAlex Deucher 
80397b2e202SAlex Deucher /* maximum number of VMIDs */
80497b2e202SAlex Deucher #define AMDGPU_NUM_VM	16
80597b2e202SAlex Deucher 
80697b2e202SAlex Deucher /* number of entries in page table */
80797b2e202SAlex Deucher #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
80897b2e202SAlex Deucher 
80997b2e202SAlex Deucher /* PTBs (Page Table Blocks) need to be aligned to 32K */
81097b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_SIZE   32768
81197b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
81297b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
81397b2e202SAlex Deucher 
81497b2e202SAlex Deucher #define AMDGPU_PTE_VALID	(1 << 0)
81597b2e202SAlex Deucher #define AMDGPU_PTE_SYSTEM	(1 << 1)
81697b2e202SAlex Deucher #define AMDGPU_PTE_SNOOPED	(1 << 2)
81797b2e202SAlex Deucher 
81897b2e202SAlex Deucher /* VI only */
81997b2e202SAlex Deucher #define AMDGPU_PTE_EXECUTABLE	(1 << 4)
82097b2e202SAlex Deucher 
82197b2e202SAlex Deucher #define AMDGPU_PTE_READABLE	(1 << 5)
82297b2e202SAlex Deucher #define AMDGPU_PTE_WRITEABLE	(1 << 6)
82397b2e202SAlex Deucher 
82497b2e202SAlex Deucher /* PTE (Page Table Entry) fragment field for different page sizes */
82597b2e202SAlex Deucher #define AMDGPU_PTE_FRAG_4KB	(0 << 7)
82697b2e202SAlex Deucher #define AMDGPU_PTE_FRAG_64KB	(4 << 7)
82797b2e202SAlex Deucher #define AMDGPU_LOG2_PAGES_PER_FRAG 4
82897b2e202SAlex Deucher 
829d9c13156SChristian König /* How to programm VM fault handling */
830d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_NEVER	0
831d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_FIRST	1
832d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_ALWAYS	2
833d9c13156SChristian König 
83497b2e202SAlex Deucher struct amdgpu_vm_pt {
835ee1782c3SChristian König 	struct amdgpu_bo_list_entry	entry;
83697b2e202SAlex Deucher 	uint64_t			addr;
83797b2e202SAlex Deucher };
83897b2e202SAlex Deucher 
83997b2e202SAlex Deucher struct amdgpu_vm_id {
8404ff37a83SChristian König 	struct amdgpu_vm_manager_id	*mgr_id;
84197b2e202SAlex Deucher 	uint64_t			pd_gpu_addr;
84297b2e202SAlex Deucher 	/* last flushed PD/PT update */
8433c62338cSChunming Zhou 	struct fence			*flushed_updates;
84497b2e202SAlex Deucher };
84597b2e202SAlex Deucher 
84697b2e202SAlex Deucher struct amdgpu_vm {
84725cfc3c2SChristian König 	/* tree of virtual addresses mapped */
84897b2e202SAlex Deucher 	struct rb_root		va;
84997b2e202SAlex Deucher 
8507fc11959SChristian König 	/* protecting invalidated */
85197b2e202SAlex Deucher 	spinlock_t		status_lock;
85297b2e202SAlex Deucher 
85397b2e202SAlex Deucher 	/* BOs moved, but not yet updated in the PT */
85497b2e202SAlex Deucher 	struct list_head	invalidated;
85597b2e202SAlex Deucher 
8567fc11959SChristian König 	/* BOs cleared in the PT because of a move */
8577fc11959SChristian König 	struct list_head	cleared;
8587fc11959SChristian König 
8597fc11959SChristian König 	/* BO mappings freed, but not yet updated in the PT */
86097b2e202SAlex Deucher 	struct list_head	freed;
86197b2e202SAlex Deucher 
86297b2e202SAlex Deucher 	/* contains the page directory */
86397b2e202SAlex Deucher 	struct amdgpu_bo	*page_directory;
86497b2e202SAlex Deucher 	unsigned		max_pde_used;
86505906decSBas Nieuwenhuizen 	struct fence		*page_directory_fence;
86697b2e202SAlex Deucher 
86797b2e202SAlex Deucher 	/* array of page tables, one for each page directory entry */
86897b2e202SAlex Deucher 	struct amdgpu_vm_pt	*page_tables;
86997b2e202SAlex Deucher 
87097b2e202SAlex Deucher 	/* for id and flush management per ring */
87197b2e202SAlex Deucher 	struct amdgpu_vm_id	ids[AMDGPU_MAX_RINGS];
87225cfc3c2SChristian König 
87381d75a30Sjimqu 	/* protecting freed */
87481d75a30Sjimqu 	spinlock_t		freed_lock;
8752bd9ccfaSChristian König 
8762bd9ccfaSChristian König 	/* Scheduler entity for page table updates */
8772bd9ccfaSChristian König 	struct amd_sched_entity	entity;
87897b2e202SAlex Deucher };
87997b2e202SAlex Deucher 
880a9a78b32SChristian König struct amdgpu_vm_manager_id {
881a9a78b32SChristian König 	struct list_head	list;
8821c16c0a7SChristian König 	struct fence		*active;
8831c16c0a7SChristian König 	atomic_long_t		owner;
884971fe9a9SChristian König 
885971fe9a9SChristian König 	uint32_t		gds_base;
886971fe9a9SChristian König 	uint32_t		gds_size;
887971fe9a9SChristian König 	uint32_t		gws_base;
888971fe9a9SChristian König 	uint32_t		gws_size;
889971fe9a9SChristian König 	uint32_t		oa_base;
890971fe9a9SChristian König 	uint32_t		oa_size;
891a9a78b32SChristian König };
892a9a78b32SChristian König 
893a9a78b32SChristian König struct amdgpu_vm_manager {
894a9a78b32SChristian König 	/* Handling of VMIDs */
895a9a78b32SChristian König 	struct mutex				lock;
896a9a78b32SChristian König 	unsigned				num_ids;
897a9a78b32SChristian König 	struct list_head			ids_lru;
898a9a78b32SChristian König 	struct amdgpu_vm_manager_id		ids[AMDGPU_NUM_VM];
8991c16c0a7SChristian König 
90097b2e202SAlex Deucher 	uint32_t				max_pfn;
90197b2e202SAlex Deucher 	/* vram base address for page table entry  */
90297b2e202SAlex Deucher 	u64					vram_base_offset;
90397b2e202SAlex Deucher 	/* is vm enabled? */
90497b2e202SAlex Deucher 	bool					enabled;
90597b2e202SAlex Deucher 	/* vm pte handling */
90697b2e202SAlex Deucher 	const struct amdgpu_vm_pte_funcs        *vm_pte_funcs;
9072d55e45aSChristian König 	struct amdgpu_ring                      *vm_pte_rings[AMDGPU_MAX_RINGS];
9082d55e45aSChristian König 	unsigned				vm_pte_num_rings;
9092d55e45aSChristian König 	atomic_t				vm_pte_next_ring;
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);
919ee1782c3SChristian König void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
920eceb8a15SChristian König void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
921eceb8a15SChristian König 				  struct amdgpu_vm *vm);
9228b4fb00bSChristian König int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
9234ff37a83SChristian König 		      struct amdgpu_sync *sync, struct fence *fence,
9244ff37a83SChristian König 		      unsigned *vm_id, uint64_t *vm_pd_addr);
9258b4fb00bSChristian König void amdgpu_vm_flush(struct amdgpu_ring *ring,
926cffadc83SChristian König 		     unsigned vm_id, uint64_t pd_addr,
927cffadc83SChristian König 		     uint32_t gds_base, uint32_t gds_size,
928cffadc83SChristian König 		     uint32_t gws_base, uint32_t gws_size,
929cffadc83SChristian König 		     uint32_t oa_base, uint32_t oa_size);
930971fe9a9SChristian König void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
931b07c9d2aSChristian König uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
9328b4fb00bSChristian König int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
9338b4fb00bSChristian König 				    struct amdgpu_vm *vm);
9348b4fb00bSChristian König int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
9358b4fb00bSChristian König 			  struct amdgpu_vm *vm);
9368b4fb00bSChristian König int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
9378b4fb00bSChristian König 			     struct amdgpu_sync *sync);
9388b4fb00bSChristian König int amdgpu_vm_bo_update(struct amdgpu_device *adev,
9398b4fb00bSChristian König 			struct amdgpu_bo_va *bo_va,
9408b4fb00bSChristian König 			struct ttm_mem_reg *mem);
9418b4fb00bSChristian König void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
9428b4fb00bSChristian König 			     struct amdgpu_bo *bo);
9438b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
9448b4fb00bSChristian König 				       struct amdgpu_bo *bo);
9458b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
9468b4fb00bSChristian König 				      struct amdgpu_vm *vm,
9478b4fb00bSChristian König 				      struct amdgpu_bo *bo);
9488b4fb00bSChristian König int amdgpu_vm_bo_map(struct amdgpu_device *adev,
9498b4fb00bSChristian König 		     struct amdgpu_bo_va *bo_va,
9508b4fb00bSChristian König 		     uint64_t addr, uint64_t offset,
9518b4fb00bSChristian König 		     uint64_t size, uint32_t flags);
9528b4fb00bSChristian König int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
9538b4fb00bSChristian König 		       struct amdgpu_bo_va *bo_va,
9548b4fb00bSChristian König 		       uint64_t addr);
9558b4fb00bSChristian König void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
9568b4fb00bSChristian König 		      struct amdgpu_bo_va *bo_va);
9578b4fb00bSChristian König 
95897b2e202SAlex Deucher /*
95997b2e202SAlex Deucher  * context related structures
96097b2e202SAlex Deucher  */
96197b2e202SAlex Deucher 
96221c16bf6SChristian König struct amdgpu_ctx_ring {
96321c16bf6SChristian König 	uint64_t		sequence;
96437cd0ca2SChunming Zhou 	struct fence		**fences;
96591404fb2SChristian König 	struct amd_sched_entity	entity;
96621c16bf6SChristian König };
96721c16bf6SChristian König 
96897b2e202SAlex Deucher struct amdgpu_ctx {
96997b2e202SAlex Deucher 	struct kref		refcount;
9709cb7e5a9SChunming Zhou 	struct amdgpu_device    *adev;
971d94aed5aSMarek Olšák 	unsigned		reset_counter;
97221c16bf6SChristian König 	spinlock_t		ring_lock;
97337cd0ca2SChunming Zhou 	struct fence            **fences;
97421c16bf6SChristian König 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
97597b2e202SAlex Deucher };
97697b2e202SAlex Deucher 
97797b2e202SAlex Deucher struct amdgpu_ctx_mgr {
97897b2e202SAlex Deucher 	struct amdgpu_device	*adev;
9790147ee0fSMarek Olšák 	struct mutex		lock;
9800b492a4cSAlex Deucher 	/* protected by lock */
9810b492a4cSAlex Deucher 	struct idr		ctx_handles;
98297b2e202SAlex Deucher };
98397b2e202SAlex Deucher 
9840b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
9850b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
9860b492a4cSAlex Deucher 
98721c16bf6SChristian König uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
988ce882e6dSChristian König 			      struct fence *fence);
98921c16bf6SChristian König struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
99021c16bf6SChristian König 				   struct amdgpu_ring *ring, uint64_t seq);
99121c16bf6SChristian König 
9920b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
9930b492a4cSAlex Deucher 		     struct drm_file *filp);
9940b492a4cSAlex Deucher 
995efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
996efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
9970b492a4cSAlex Deucher 
99897b2e202SAlex Deucher /*
99997b2e202SAlex Deucher  * file private structure
100097b2e202SAlex Deucher  */
100197b2e202SAlex Deucher 
100297b2e202SAlex Deucher struct amdgpu_fpriv {
100397b2e202SAlex Deucher 	struct amdgpu_vm	vm;
100497b2e202SAlex Deucher 	struct mutex		bo_list_lock;
100597b2e202SAlex Deucher 	struct idr		bo_list_handles;
100697b2e202SAlex Deucher 	struct amdgpu_ctx_mgr	ctx_mgr;
100797b2e202SAlex Deucher };
100897b2e202SAlex Deucher 
100997b2e202SAlex Deucher /*
101097b2e202SAlex Deucher  * residency list
101197b2e202SAlex Deucher  */
101297b2e202SAlex Deucher 
101397b2e202SAlex Deucher struct amdgpu_bo_list {
101497b2e202SAlex Deucher 	struct mutex lock;
101597b2e202SAlex Deucher 	struct amdgpu_bo *gds_obj;
101697b2e202SAlex Deucher 	struct amdgpu_bo *gws_obj;
101797b2e202SAlex Deucher 	struct amdgpu_bo *oa_obj;
1018211dff55SChristian König 	unsigned first_userptr;
101997b2e202SAlex Deucher 	unsigned num_entries;
102097b2e202SAlex Deucher 	struct amdgpu_bo_list_entry *array;
102197b2e202SAlex Deucher };
102297b2e202SAlex Deucher 
102397b2e202SAlex Deucher struct amdgpu_bo_list *
102497b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
1025636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1026636ce25cSChristian König 			     struct list_head *validated);
102797b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
102897b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
102997b2e202SAlex Deucher 
103097b2e202SAlex Deucher /*
103197b2e202SAlex Deucher  * GFX stuff
103297b2e202SAlex Deucher  */
103397b2e202SAlex Deucher #include "clearstate_defs.h"
103497b2e202SAlex Deucher 
103597b2e202SAlex Deucher struct amdgpu_rlc {
103697b2e202SAlex Deucher 	/* for power gating */
103797b2e202SAlex Deucher 	struct amdgpu_bo	*save_restore_obj;
103897b2e202SAlex Deucher 	uint64_t		save_restore_gpu_addr;
103997b2e202SAlex Deucher 	volatile uint32_t	*sr_ptr;
104097b2e202SAlex Deucher 	const u32               *reg_list;
104197b2e202SAlex Deucher 	u32                     reg_list_size;
104297b2e202SAlex Deucher 	/* for clear state */
104397b2e202SAlex Deucher 	struct amdgpu_bo	*clear_state_obj;
104497b2e202SAlex Deucher 	uint64_t		clear_state_gpu_addr;
104597b2e202SAlex Deucher 	volatile uint32_t	*cs_ptr;
104697b2e202SAlex Deucher 	const struct cs_section_def   *cs_data;
104797b2e202SAlex Deucher 	u32                     clear_state_size;
104897b2e202SAlex Deucher 	/* for cp tables */
104997b2e202SAlex Deucher 	struct amdgpu_bo	*cp_table_obj;
105097b2e202SAlex Deucher 	uint64_t		cp_table_gpu_addr;
105197b2e202SAlex Deucher 	volatile uint32_t	*cp_table_ptr;
105297b2e202SAlex Deucher 	u32                     cp_table_size;
105397b2e202SAlex Deucher };
105497b2e202SAlex Deucher 
105597b2e202SAlex Deucher struct amdgpu_mec {
105697b2e202SAlex Deucher 	struct amdgpu_bo	*hpd_eop_obj;
105797b2e202SAlex Deucher 	u64			hpd_eop_gpu_addr;
105897b2e202SAlex Deucher 	u32 num_pipe;
105997b2e202SAlex Deucher 	u32 num_mec;
106097b2e202SAlex Deucher 	u32 num_queue;
106197b2e202SAlex Deucher };
106297b2e202SAlex Deucher 
106397b2e202SAlex Deucher /*
106497b2e202SAlex Deucher  * GPU scratch registers structures, functions & helpers
106597b2e202SAlex Deucher  */
106697b2e202SAlex Deucher struct amdgpu_scratch {
106797b2e202SAlex Deucher 	unsigned		num_reg;
106897b2e202SAlex Deucher 	uint32_t                reg_base;
106997b2e202SAlex Deucher 	bool			free[32];
107097b2e202SAlex Deucher 	uint32_t		reg[32];
107197b2e202SAlex Deucher };
107297b2e202SAlex Deucher 
107397b2e202SAlex Deucher /*
107497b2e202SAlex Deucher  * GFX configurations
107597b2e202SAlex Deucher  */
107697b2e202SAlex Deucher struct amdgpu_gca_config {
107797b2e202SAlex Deucher 	unsigned max_shader_engines;
107897b2e202SAlex Deucher 	unsigned max_tile_pipes;
107997b2e202SAlex Deucher 	unsigned max_cu_per_sh;
108097b2e202SAlex Deucher 	unsigned max_sh_per_se;
108197b2e202SAlex Deucher 	unsigned max_backends_per_se;
108297b2e202SAlex Deucher 	unsigned max_texture_channel_caches;
108397b2e202SAlex Deucher 	unsigned max_gprs;
108497b2e202SAlex Deucher 	unsigned max_gs_threads;
108597b2e202SAlex Deucher 	unsigned max_hw_contexts;
108697b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_frontend;
108797b2e202SAlex Deucher 	unsigned sc_prim_fifo_size_backend;
108897b2e202SAlex Deucher 	unsigned sc_hiz_tile_fifo_size;
108997b2e202SAlex Deucher 	unsigned sc_earlyz_tile_fifo_size;
109097b2e202SAlex Deucher 
109197b2e202SAlex Deucher 	unsigned num_tile_pipes;
109297b2e202SAlex Deucher 	unsigned backend_enable_mask;
109397b2e202SAlex Deucher 	unsigned mem_max_burst_length_bytes;
109497b2e202SAlex Deucher 	unsigned mem_row_size_in_kb;
109597b2e202SAlex Deucher 	unsigned shader_engine_tile_size;
109697b2e202SAlex Deucher 	unsigned num_gpus;
109797b2e202SAlex Deucher 	unsigned multi_gpu_tile_size;
109897b2e202SAlex Deucher 	unsigned mc_arb_ramcfg;
109997b2e202SAlex Deucher 	unsigned gb_addr_config;
11008f8e00c1SAlex Deucher 	unsigned num_rbs;
110197b2e202SAlex Deucher 
110297b2e202SAlex Deucher 	uint32_t tile_mode_array[32];
110397b2e202SAlex Deucher 	uint32_t macrotile_mode_array[16];
110497b2e202SAlex Deucher };
110597b2e202SAlex Deucher 
110697b2e202SAlex Deucher struct amdgpu_gfx {
110797b2e202SAlex Deucher 	struct mutex			gpu_clock_mutex;
110897b2e202SAlex Deucher 	struct amdgpu_gca_config	config;
110997b2e202SAlex Deucher 	struct amdgpu_rlc		rlc;
111097b2e202SAlex Deucher 	struct amdgpu_mec		mec;
111197b2e202SAlex Deucher 	struct amdgpu_scratch		scratch;
111297b2e202SAlex Deucher 	const struct firmware		*me_fw;	/* ME firmware */
111397b2e202SAlex Deucher 	uint32_t			me_fw_version;
111497b2e202SAlex Deucher 	const struct firmware		*pfp_fw; /* PFP firmware */
111597b2e202SAlex Deucher 	uint32_t			pfp_fw_version;
111697b2e202SAlex Deucher 	const struct firmware		*ce_fw;	/* CE firmware */
111797b2e202SAlex Deucher 	uint32_t			ce_fw_version;
111897b2e202SAlex Deucher 	const struct firmware		*rlc_fw; /* RLC firmware */
111997b2e202SAlex Deucher 	uint32_t			rlc_fw_version;
112097b2e202SAlex Deucher 	const struct firmware		*mec_fw; /* MEC firmware */
112197b2e202SAlex Deucher 	uint32_t			mec_fw_version;
112297b2e202SAlex Deucher 	const struct firmware		*mec2_fw; /* MEC2 firmware */
112397b2e202SAlex Deucher 	uint32_t			mec2_fw_version;
112402558a00SKen Wang 	uint32_t			me_feature_version;
112502558a00SKen Wang 	uint32_t			ce_feature_version;
112602558a00SKen Wang 	uint32_t			pfp_feature_version;
1127351643d7SJammy Zhou 	uint32_t			rlc_feature_version;
1128351643d7SJammy Zhou 	uint32_t			mec_feature_version;
1129351643d7SJammy Zhou 	uint32_t			mec2_feature_version;
113097b2e202SAlex Deucher 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
113197b2e202SAlex Deucher 	unsigned			num_gfx_rings;
113297b2e202SAlex Deucher 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
113397b2e202SAlex Deucher 	unsigned			num_compute_rings;
113497b2e202SAlex Deucher 	struct amdgpu_irq_src		eop_irq;
113597b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_reg_irq;
113697b2e202SAlex Deucher 	struct amdgpu_irq_src		priv_inst_irq;
113797b2e202SAlex Deucher 	/* gfx status */
113897b2e202SAlex Deucher 	uint32_t gfx_current_status;
1139a101a899SKen Wang 	/* ce ram size*/
1140a101a899SKen Wang 	unsigned ce_ram_size;
114197b2e202SAlex Deucher };
114297b2e202SAlex Deucher 
1143b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
114497b2e202SAlex Deucher 		  unsigned size, struct amdgpu_ib *ib);
1145cc55c45dSMonk Liu void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, struct fence *f);
1146b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
1147336d1f5eSChristian König 		       struct amdgpu_ib *ib, struct fence *last_vm_update,
1148ec72b800SChristian König 		       struct fence **f);
114997b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev);
115097b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
115197b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
115297b2e202SAlex Deucher int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
1153edff0e28SJammy Zhou void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
11549e5d5309SChristian König void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
115597b2e202SAlex Deucher void amdgpu_ring_commit(struct amdgpu_ring *ring);
115697b2e202SAlex Deucher void amdgpu_ring_undo(struct amdgpu_ring *ring);
115797b2e202SAlex Deucher unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
115897b2e202SAlex Deucher 			    uint32_t **data);
115997b2e202SAlex Deucher int amdgpu_ring_restore(struct amdgpu_ring *ring,
116097b2e202SAlex Deucher 			unsigned size, uint32_t *data);
116197b2e202SAlex Deucher int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
116297b2e202SAlex Deucher 		     unsigned ring_size, u32 nop, u32 align_mask,
116397b2e202SAlex Deucher 		     struct amdgpu_irq_src *irq_src, unsigned irq_type,
116497b2e202SAlex Deucher 		     enum amdgpu_ring_type ring_type);
116597b2e202SAlex Deucher void amdgpu_ring_fini(struct amdgpu_ring *ring);
116697b2e202SAlex Deucher 
116797b2e202SAlex Deucher /*
116897b2e202SAlex Deucher  * CS.
116997b2e202SAlex Deucher  */
117097b2e202SAlex Deucher struct amdgpu_cs_chunk {
117197b2e202SAlex Deucher 	uint32_t		chunk_id;
117297b2e202SAlex Deucher 	uint32_t		length_dw;
117397b2e202SAlex Deucher 	uint32_t		*kdata;
117497b2e202SAlex Deucher };
117597b2e202SAlex Deucher 
117697b2e202SAlex Deucher struct amdgpu_cs_parser {
117797b2e202SAlex Deucher 	struct amdgpu_device	*adev;
117897b2e202SAlex Deucher 	struct drm_file		*filp;
11793cb485f3SChristian König 	struct amdgpu_ctx	*ctx;
1180c3cca41eSChristian König 
118197b2e202SAlex Deucher 	/* chunks */
118297b2e202SAlex Deucher 	unsigned		nchunks;
118397b2e202SAlex Deucher 	struct amdgpu_cs_chunk	*chunks;
1184c3cca41eSChristian König 
118550838c8cSChristian König 	/* scheduler job object */
118650838c8cSChristian König 	struct amdgpu_job	*job;
1187c3cca41eSChristian König 
1188c3cca41eSChristian König 	/* buffer objects */
1189c3cca41eSChristian König 	struct ww_acquire_ctx		ticket;
1190c3cca41eSChristian König 	struct amdgpu_bo_list		*bo_list;
119156467ebfSChristian König 	struct amdgpu_bo_list_entry	vm_pd;
119297b2e202SAlex Deucher 	struct list_head		validated;
1193984810fcSChristian König 	struct fence			*fence;
1194f69f90a1SChristian König 	uint64_t			bytes_moved_threshold;
1195f69f90a1SChristian König 	uint64_t			bytes_moved;
119697b2e202SAlex Deucher 
119797b2e202SAlex Deucher 	/* user fence */
119891acbeb6SChristian König 	struct amdgpu_bo_list_entry	uf_entry;
119997b2e202SAlex Deucher };
120097b2e202SAlex Deucher 
1201bb977d37SChunming Zhou struct amdgpu_job {
1202bb977d37SChunming Zhou 	struct amd_sched_job    base;
1203bb977d37SChunming Zhou 	struct amdgpu_device	*adev;
1204b07c60c0SChristian König 	struct amdgpu_ring	*ring;
1205e86f9ceeSChristian König 	struct amdgpu_sync	sync;
1206bb977d37SChunming Zhou 	struct amdgpu_ib	*ibs;
120773cfa5f5SMonk Liu 	struct fence		*fence; /* the hw fence */
1208bb977d37SChunming Zhou 	uint32_t		num_ibs;
1209e2840221SChristian König 	void			*owner;
1210bb977d37SChunming Zhou 	struct amdgpu_user_fence uf;
1211bb977d37SChunming Zhou };
1212a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job)		\
1213a6db8a33SJunwei Zhang 		container_of((sched_job), struct amdgpu_job, base)
1214bb977d37SChunming Zhou 
12157270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
12167270f839SChristian König 				      uint32_t ib_idx, int idx)
121797b2e202SAlex Deucher {
121850838c8cSChristian König 	return p->job->ibs[ib_idx].ptr[idx];
121997b2e202SAlex Deucher }
122097b2e202SAlex Deucher 
12217270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
12227270f839SChristian König 				       uint32_t ib_idx, int idx,
12237270f839SChristian König 				       uint32_t value)
12247270f839SChristian König {
122550838c8cSChristian König 	p->job->ibs[ib_idx].ptr[idx] = value;
12267270f839SChristian König }
12277270f839SChristian König 
122897b2e202SAlex Deucher /*
122997b2e202SAlex Deucher  * Writeback
123097b2e202SAlex Deucher  */
123197b2e202SAlex Deucher #define AMDGPU_MAX_WB 1024	/* Reserve at most 1024 WB slots for amdgpu-owned rings. */
123297b2e202SAlex Deucher 
123397b2e202SAlex Deucher struct amdgpu_wb {
123497b2e202SAlex Deucher 	struct amdgpu_bo	*wb_obj;
123597b2e202SAlex Deucher 	volatile uint32_t	*wb;
123697b2e202SAlex Deucher 	uint64_t		gpu_addr;
123797b2e202SAlex Deucher 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
123897b2e202SAlex Deucher 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
123997b2e202SAlex Deucher };
124097b2e202SAlex Deucher 
124197b2e202SAlex Deucher int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
124297b2e202SAlex Deucher void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
124397b2e202SAlex Deucher 
124497b2e202SAlex Deucher 
124597b2e202SAlex Deucher 
124697b2e202SAlex Deucher enum amdgpu_int_thermal_type {
124797b2e202SAlex Deucher 	THERMAL_TYPE_NONE,
124897b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL,
124997b2e202SAlex Deucher 	THERMAL_TYPE_EXTERNAL_GPIO,
125097b2e202SAlex Deucher 	THERMAL_TYPE_RV6XX,
125197b2e202SAlex Deucher 	THERMAL_TYPE_RV770,
125297b2e202SAlex Deucher 	THERMAL_TYPE_ADT7473_WITH_INTERNAL,
125397b2e202SAlex Deucher 	THERMAL_TYPE_EVERGREEN,
125497b2e202SAlex Deucher 	THERMAL_TYPE_SUMO,
125597b2e202SAlex Deucher 	THERMAL_TYPE_NI,
125697b2e202SAlex Deucher 	THERMAL_TYPE_SI,
125797b2e202SAlex Deucher 	THERMAL_TYPE_EMC2103_WITH_INTERNAL,
125897b2e202SAlex Deucher 	THERMAL_TYPE_CI,
125997b2e202SAlex Deucher 	THERMAL_TYPE_KV,
126097b2e202SAlex Deucher };
126197b2e202SAlex Deucher 
126297b2e202SAlex Deucher enum amdgpu_dpm_auto_throttle_src {
126397b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
126497b2e202SAlex Deucher 	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
126597b2e202SAlex Deucher };
126697b2e202SAlex Deucher 
126797b2e202SAlex Deucher enum amdgpu_dpm_event_src {
126897b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
126997b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
127097b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
127197b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
127297b2e202SAlex Deucher 	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
127397b2e202SAlex Deucher };
127497b2e202SAlex Deucher 
127597b2e202SAlex Deucher #define AMDGPU_MAX_VCE_LEVELS 6
127697b2e202SAlex Deucher 
127797b2e202SAlex Deucher enum amdgpu_vce_level {
127897b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_AC_ALL = 0,     /* AC, All cases */
127997b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_EE = 1,      /* DC, entropy encoding */
128097b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_LOW = 2,  /* DC, low latency queue, res <= 720 */
128197b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
128297b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_LOW = 4,  /* DC, general purpose queue, res <= 720 */
128397b2e202SAlex Deucher 	AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
128497b2e202SAlex Deucher };
128597b2e202SAlex Deucher 
128697b2e202SAlex Deucher struct amdgpu_ps {
128797b2e202SAlex Deucher 	u32 caps; /* vbios flags */
128897b2e202SAlex Deucher 	u32 class; /* vbios flags */
128997b2e202SAlex Deucher 	u32 class2; /* vbios flags */
129097b2e202SAlex Deucher 	/* UVD clocks */
129197b2e202SAlex Deucher 	u32 vclk;
129297b2e202SAlex Deucher 	u32 dclk;
129397b2e202SAlex Deucher 	/* VCE clocks */
129497b2e202SAlex Deucher 	u32 evclk;
129597b2e202SAlex Deucher 	u32 ecclk;
129697b2e202SAlex Deucher 	bool vce_active;
129797b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
129897b2e202SAlex Deucher 	/* asic priv */
129997b2e202SAlex Deucher 	void *ps_priv;
130097b2e202SAlex Deucher };
130197b2e202SAlex Deucher 
130297b2e202SAlex Deucher struct amdgpu_dpm_thermal {
130397b2e202SAlex Deucher 	/* thermal interrupt work */
130497b2e202SAlex Deucher 	struct work_struct work;
130597b2e202SAlex Deucher 	/* low temperature threshold */
130697b2e202SAlex Deucher 	int                min_temp;
130797b2e202SAlex Deucher 	/* high temperature threshold */
130897b2e202SAlex Deucher 	int                max_temp;
130997b2e202SAlex Deucher 	/* was last interrupt low to high or high to low */
131097b2e202SAlex Deucher 	bool               high_to_low;
131197b2e202SAlex Deucher 	/* interrupt source */
131297b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
131397b2e202SAlex Deucher };
131497b2e202SAlex Deucher 
131597b2e202SAlex Deucher enum amdgpu_clk_action
131697b2e202SAlex Deucher {
131797b2e202SAlex Deucher 	AMDGPU_SCLK_UP = 1,
131897b2e202SAlex Deucher 	AMDGPU_SCLK_DOWN
131997b2e202SAlex Deucher };
132097b2e202SAlex Deucher 
132197b2e202SAlex Deucher struct amdgpu_blacklist_clocks
132297b2e202SAlex Deucher {
132397b2e202SAlex Deucher 	u32 sclk;
132497b2e202SAlex Deucher 	u32 mclk;
132597b2e202SAlex Deucher 	enum amdgpu_clk_action action;
132697b2e202SAlex Deucher };
132797b2e202SAlex Deucher 
132897b2e202SAlex Deucher struct amdgpu_clock_and_voltage_limits {
132997b2e202SAlex Deucher 	u32 sclk;
133097b2e202SAlex Deucher 	u32 mclk;
133197b2e202SAlex Deucher 	u16 vddc;
133297b2e202SAlex Deucher 	u16 vddci;
133397b2e202SAlex Deucher };
133497b2e202SAlex Deucher 
133597b2e202SAlex Deucher struct amdgpu_clock_array {
133697b2e202SAlex Deucher 	u32 count;
133797b2e202SAlex Deucher 	u32 *values;
133897b2e202SAlex Deucher };
133997b2e202SAlex Deucher 
134097b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_entry {
134197b2e202SAlex Deucher 	u32 clk;
134297b2e202SAlex Deucher 	u16 v;
134397b2e202SAlex Deucher };
134497b2e202SAlex Deucher 
134597b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table {
134697b2e202SAlex Deucher 	u32 count;
134797b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_entry *entries;
134897b2e202SAlex Deucher };
134997b2e202SAlex Deucher 
135097b2e202SAlex Deucher union amdgpu_cac_leakage_entry {
135197b2e202SAlex Deucher 	struct {
135297b2e202SAlex Deucher 		u16 vddc;
135397b2e202SAlex Deucher 		u32 leakage;
135497b2e202SAlex Deucher 	};
135597b2e202SAlex Deucher 	struct {
135697b2e202SAlex Deucher 		u16 vddc1;
135797b2e202SAlex Deucher 		u16 vddc2;
135897b2e202SAlex Deucher 		u16 vddc3;
135997b2e202SAlex Deucher 	};
136097b2e202SAlex Deucher };
136197b2e202SAlex Deucher 
136297b2e202SAlex Deucher struct amdgpu_cac_leakage_table {
136397b2e202SAlex Deucher 	u32 count;
136497b2e202SAlex Deucher 	union amdgpu_cac_leakage_entry *entries;
136597b2e202SAlex Deucher };
136697b2e202SAlex Deucher 
136797b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_entry {
136897b2e202SAlex Deucher 	u16 voltage;
136997b2e202SAlex Deucher 	u32 sclk;
137097b2e202SAlex Deucher 	u32 mclk;
137197b2e202SAlex Deucher };
137297b2e202SAlex Deucher 
137397b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_table {
137497b2e202SAlex Deucher 	u32 count;
137597b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_entry *entries;
137697b2e202SAlex Deucher };
137797b2e202SAlex Deucher 
137897b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_entry {
137997b2e202SAlex Deucher 	u32 vclk;
138097b2e202SAlex Deucher 	u32 dclk;
138197b2e202SAlex Deucher 	u16 v;
138297b2e202SAlex Deucher };
138397b2e202SAlex Deucher 
138497b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_table {
138597b2e202SAlex Deucher 	u8 count;
138697b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
138797b2e202SAlex Deucher };
138897b2e202SAlex Deucher 
138997b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_entry {
139097b2e202SAlex Deucher 	u32 ecclk;
139197b2e202SAlex Deucher 	u32 evclk;
139297b2e202SAlex Deucher 	u16 v;
139397b2e202SAlex Deucher };
139497b2e202SAlex Deucher 
139597b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_table {
139697b2e202SAlex Deucher 	u8 count;
139797b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_entry *entries;
139897b2e202SAlex Deucher };
139997b2e202SAlex Deucher 
140097b2e202SAlex Deucher struct amdgpu_ppm_table {
140197b2e202SAlex Deucher 	u8 ppm_design;
140297b2e202SAlex Deucher 	u16 cpu_core_number;
140397b2e202SAlex Deucher 	u32 platform_tdp;
140497b2e202SAlex Deucher 	u32 small_ac_platform_tdp;
140597b2e202SAlex Deucher 	u32 platform_tdc;
140697b2e202SAlex Deucher 	u32 small_ac_platform_tdc;
140797b2e202SAlex Deucher 	u32 apu_tdp;
140897b2e202SAlex Deucher 	u32 dgpu_tdp;
140997b2e202SAlex Deucher 	u32 dgpu_ulv_power;
141097b2e202SAlex Deucher 	u32 tj_max;
141197b2e202SAlex Deucher };
141297b2e202SAlex Deucher 
141397b2e202SAlex Deucher struct amdgpu_cac_tdp_table {
141497b2e202SAlex Deucher 	u16 tdp;
141597b2e202SAlex Deucher 	u16 configurable_tdp;
141697b2e202SAlex Deucher 	u16 tdc;
141797b2e202SAlex Deucher 	u16 battery_power_limit;
141897b2e202SAlex Deucher 	u16 small_power_limit;
141997b2e202SAlex Deucher 	u16 low_cac_leakage;
142097b2e202SAlex Deucher 	u16 high_cac_leakage;
142197b2e202SAlex Deucher 	u16 maximum_power_delivery_limit;
142297b2e202SAlex Deucher };
142397b2e202SAlex Deucher 
142497b2e202SAlex Deucher struct amdgpu_dpm_dynamic_state {
142597b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
142697b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
142797b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
142897b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
142997b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
143097b2e202SAlex Deucher 	struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
143197b2e202SAlex Deucher 	struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
143297b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
143397b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
143497b2e202SAlex Deucher 	struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
143597b2e202SAlex Deucher 	struct amdgpu_clock_array valid_sclk_values;
143697b2e202SAlex Deucher 	struct amdgpu_clock_array valid_mclk_values;
143797b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
143897b2e202SAlex Deucher 	struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
143997b2e202SAlex Deucher 	u32 mclk_sclk_ratio;
144097b2e202SAlex Deucher 	u32 sclk_mclk_delta;
144197b2e202SAlex Deucher 	u16 vddc_vddci_delta;
144297b2e202SAlex Deucher 	u16 min_vddc_for_pcie_gen2;
144397b2e202SAlex Deucher 	struct amdgpu_cac_leakage_table cac_leakage_table;
144497b2e202SAlex Deucher 	struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
144597b2e202SAlex Deucher 	struct amdgpu_ppm_table *ppm_table;
144697b2e202SAlex Deucher 	struct amdgpu_cac_tdp_table *cac_tdp_table;
144797b2e202SAlex Deucher };
144897b2e202SAlex Deucher 
144997b2e202SAlex Deucher struct amdgpu_dpm_fan {
145097b2e202SAlex Deucher 	u16 t_min;
145197b2e202SAlex Deucher 	u16 t_med;
145297b2e202SAlex Deucher 	u16 t_high;
145397b2e202SAlex Deucher 	u16 pwm_min;
145497b2e202SAlex Deucher 	u16 pwm_med;
145597b2e202SAlex Deucher 	u16 pwm_high;
145697b2e202SAlex Deucher 	u8 t_hyst;
145797b2e202SAlex Deucher 	u32 cycle_delay;
145897b2e202SAlex Deucher 	u16 t_max;
145997b2e202SAlex Deucher 	u8 control_mode;
146097b2e202SAlex Deucher 	u16 default_max_fan_pwm;
146197b2e202SAlex Deucher 	u16 default_fan_output_sensitivity;
146297b2e202SAlex Deucher 	u16 fan_output_sensitivity;
146397b2e202SAlex Deucher 	bool ucode_fan_control;
146497b2e202SAlex Deucher };
146597b2e202SAlex Deucher 
146697b2e202SAlex Deucher enum amdgpu_pcie_gen {
146797b2e202SAlex Deucher 	AMDGPU_PCIE_GEN1 = 0,
146897b2e202SAlex Deucher 	AMDGPU_PCIE_GEN2 = 1,
146997b2e202SAlex Deucher 	AMDGPU_PCIE_GEN3 = 2,
147097b2e202SAlex Deucher 	AMDGPU_PCIE_GEN_INVALID = 0xffff
147197b2e202SAlex Deucher };
147297b2e202SAlex Deucher 
147397b2e202SAlex Deucher enum amdgpu_dpm_forced_level {
147497b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
147597b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
147697b2e202SAlex Deucher 	AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
1477f3898ea1SEric Huang 	AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
147897b2e202SAlex Deucher };
147997b2e202SAlex Deucher 
148097b2e202SAlex Deucher struct amdgpu_vce_state {
148197b2e202SAlex Deucher 	/* vce clocks */
148297b2e202SAlex Deucher 	u32 evclk;
148397b2e202SAlex Deucher 	u32 ecclk;
148497b2e202SAlex Deucher 	/* gpu clocks */
148597b2e202SAlex Deucher 	u32 sclk;
148697b2e202SAlex Deucher 	u32 mclk;
148797b2e202SAlex Deucher 	u8 clk_idx;
148897b2e202SAlex Deucher 	u8 pstate;
148997b2e202SAlex Deucher };
149097b2e202SAlex Deucher 
149197b2e202SAlex Deucher struct amdgpu_dpm_funcs {
149297b2e202SAlex Deucher 	int (*get_temperature)(struct amdgpu_device *adev);
149397b2e202SAlex Deucher 	int (*pre_set_power_state)(struct amdgpu_device *adev);
149497b2e202SAlex Deucher 	int (*set_power_state)(struct amdgpu_device *adev);
149597b2e202SAlex Deucher 	void (*post_set_power_state)(struct amdgpu_device *adev);
149697b2e202SAlex Deucher 	void (*display_configuration_changed)(struct amdgpu_device *adev);
149797b2e202SAlex Deucher 	u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
149897b2e202SAlex Deucher 	u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
149997b2e202SAlex Deucher 	void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
150097b2e202SAlex Deucher 	void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
150197b2e202SAlex Deucher 	int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
150297b2e202SAlex Deucher 	bool (*vblank_too_short)(struct amdgpu_device *adev);
150397b2e202SAlex Deucher 	void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
1504b7a07769SSonny Jiang 	void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
150597b2e202SAlex Deucher 	void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
150697b2e202SAlex Deucher 	void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
150797b2e202SAlex Deucher 	u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
150897b2e202SAlex Deucher 	int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
150997b2e202SAlex Deucher 	int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
151097b2e202SAlex Deucher };
151197b2e202SAlex Deucher 
151297b2e202SAlex Deucher struct amdgpu_dpm {
151397b2e202SAlex Deucher 	struct amdgpu_ps        *ps;
151497b2e202SAlex Deucher 	/* number of valid power states */
151597b2e202SAlex Deucher 	int                     num_ps;
151697b2e202SAlex Deucher 	/* current power state that is active */
151797b2e202SAlex Deucher 	struct amdgpu_ps        *current_ps;
151897b2e202SAlex Deucher 	/* requested power state */
151997b2e202SAlex Deucher 	struct amdgpu_ps        *requested_ps;
152097b2e202SAlex Deucher 	/* boot up power state */
152197b2e202SAlex Deucher 	struct amdgpu_ps        *boot_ps;
152297b2e202SAlex Deucher 	/* default uvd power state */
152397b2e202SAlex Deucher 	struct amdgpu_ps        *uvd_ps;
152497b2e202SAlex Deucher 	/* vce requirements */
152597b2e202SAlex Deucher 	struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
152697b2e202SAlex Deucher 	enum amdgpu_vce_level vce_level;
15273a2c788dSRex Zhu 	enum amd_pm_state_type state;
15283a2c788dSRex Zhu 	enum amd_pm_state_type user_state;
152997b2e202SAlex Deucher 	u32                     platform_caps;
153097b2e202SAlex Deucher 	u32                     voltage_response_time;
153197b2e202SAlex Deucher 	u32                     backbias_response_time;
153297b2e202SAlex Deucher 	void                    *priv;
153397b2e202SAlex Deucher 	u32			new_active_crtcs;
153497b2e202SAlex Deucher 	int			new_active_crtc_count;
153597b2e202SAlex Deucher 	u32			current_active_crtcs;
153697b2e202SAlex Deucher 	int			current_active_crtc_count;
153797b2e202SAlex Deucher 	struct amdgpu_dpm_dynamic_state dyn_state;
153897b2e202SAlex Deucher 	struct amdgpu_dpm_fan fan;
153997b2e202SAlex Deucher 	u32 tdp_limit;
154097b2e202SAlex Deucher 	u32 near_tdp_limit;
154197b2e202SAlex Deucher 	u32 near_tdp_limit_adjusted;
154297b2e202SAlex Deucher 	u32 sq_ramping_threshold;
154397b2e202SAlex Deucher 	u32 cac_leakage;
154497b2e202SAlex Deucher 	u16 tdp_od_limit;
154597b2e202SAlex Deucher 	u32 tdp_adjustment;
154697b2e202SAlex Deucher 	u16 load_line_slope;
154797b2e202SAlex Deucher 	bool power_control;
154897b2e202SAlex Deucher 	bool ac_power;
154997b2e202SAlex Deucher 	/* special states active */
155097b2e202SAlex Deucher 	bool                    thermal_active;
155197b2e202SAlex Deucher 	bool                    uvd_active;
155297b2e202SAlex Deucher 	bool                    vce_active;
155397b2e202SAlex Deucher 	/* thermal handling */
155497b2e202SAlex Deucher 	struct amdgpu_dpm_thermal thermal;
155597b2e202SAlex Deucher 	/* forced levels */
155697b2e202SAlex Deucher 	enum amdgpu_dpm_forced_level forced_level;
155797b2e202SAlex Deucher };
155897b2e202SAlex Deucher 
155997b2e202SAlex Deucher struct amdgpu_pm {
156097b2e202SAlex Deucher 	struct mutex		mutex;
156197b2e202SAlex Deucher 	u32                     current_sclk;
156297b2e202SAlex Deucher 	u32                     current_mclk;
156397b2e202SAlex Deucher 	u32                     default_sclk;
156497b2e202SAlex Deucher 	u32                     default_mclk;
156597b2e202SAlex Deucher 	struct amdgpu_i2c_chan *i2c_bus;
156697b2e202SAlex Deucher 	/* internal thermal controller on rv6xx+ */
156797b2e202SAlex Deucher 	enum amdgpu_int_thermal_type int_thermal_type;
156897b2e202SAlex Deucher 	struct device	        *int_hwmon_dev;
156997b2e202SAlex Deucher 	/* fan control parameters */
157097b2e202SAlex Deucher 	bool                    no_fan;
157197b2e202SAlex Deucher 	u8                      fan_pulses_per_revolution;
157297b2e202SAlex Deucher 	u8                      fan_min_rpm;
157397b2e202SAlex Deucher 	u8                      fan_max_rpm;
157497b2e202SAlex Deucher 	/* dpm */
157597b2e202SAlex Deucher 	bool                    dpm_enabled;
1576c86f5ebfSAlex Deucher 	bool                    sysfs_initialized;
157797b2e202SAlex Deucher 	struct amdgpu_dpm       dpm;
157897b2e202SAlex Deucher 	const struct firmware	*fw;	/* SMC firmware */
157997b2e202SAlex Deucher 	uint32_t                fw_version;
158097b2e202SAlex Deucher 	const struct amdgpu_dpm_funcs *funcs;
1581d0dd7f0cSAlex Deucher 	uint32_t                pcie_gen_mask;
1582d0dd7f0cSAlex Deucher 	uint32_t                pcie_mlw_mask;
15837fb72a1fSRex Zhu 	struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
158497b2e202SAlex Deucher };
158597b2e202SAlex Deucher 
1586d0dd7f0cSAlex Deucher void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1587d0dd7f0cSAlex Deucher 
158897b2e202SAlex Deucher /*
158997b2e202SAlex Deucher  * UVD
159097b2e202SAlex Deucher  */
159197b2e202SAlex Deucher #define AMDGPU_MAX_UVD_HANDLES	10
159297b2e202SAlex Deucher #define AMDGPU_UVD_STACK_SIZE	(1024*1024)
159397b2e202SAlex Deucher #define AMDGPU_UVD_HEAP_SIZE	(1024*1024)
159497b2e202SAlex Deucher #define AMDGPU_UVD_FIRMWARE_OFFSET 256
159597b2e202SAlex Deucher 
159697b2e202SAlex Deucher struct amdgpu_uvd {
159797b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
159897b2e202SAlex Deucher 	void			*cpu_addr;
159997b2e202SAlex Deucher 	uint64_t		gpu_addr;
16003f99dd81SLeo Liu 	void			*saved_bo;
160197b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_UVD_HANDLES];
160297b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_UVD_HANDLES];
160397b2e202SAlex Deucher 	struct delayed_work	idle_work;
160497b2e202SAlex Deucher 	const struct firmware	*fw;	/* UVD firmware */
160597b2e202SAlex Deucher 	struct amdgpu_ring	ring;
160697b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
160797b2e202SAlex Deucher 	bool			address_64_bit;
1608ead833ecSChristian König 	struct amd_sched_entity entity;
160997b2e202SAlex Deucher };
161097b2e202SAlex Deucher 
161197b2e202SAlex Deucher /*
161297b2e202SAlex Deucher  * VCE
161397b2e202SAlex Deucher  */
161497b2e202SAlex Deucher #define AMDGPU_MAX_VCE_HANDLES	16
161597b2e202SAlex Deucher #define AMDGPU_VCE_FIRMWARE_OFFSET 256
161697b2e202SAlex Deucher 
16176a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
16186a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
16196a585777SAlex Deucher 
162097b2e202SAlex Deucher struct amdgpu_vce {
162197b2e202SAlex Deucher 	struct amdgpu_bo	*vcpu_bo;
162297b2e202SAlex Deucher 	uint64_t		gpu_addr;
162397b2e202SAlex Deucher 	unsigned		fw_version;
162497b2e202SAlex Deucher 	unsigned		fb_version;
162597b2e202SAlex Deucher 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
162697b2e202SAlex Deucher 	struct drm_file		*filp[AMDGPU_MAX_VCE_HANDLES];
1627f1689ec1SChristian König 	uint32_t		img_size[AMDGPU_MAX_VCE_HANDLES];
162897b2e202SAlex Deucher 	struct delayed_work	idle_work;
162997b2e202SAlex Deucher 	const struct firmware	*fw;	/* VCE firmware */
163097b2e202SAlex Deucher 	struct amdgpu_ring	ring[AMDGPU_MAX_VCE_RINGS];
163197b2e202SAlex Deucher 	struct amdgpu_irq_src	irq;
16326a585777SAlex Deucher 	unsigned		harvest_config;
1633c594989cSChristian König 	struct amd_sched_entity	entity;
163497b2e202SAlex Deucher };
163597b2e202SAlex Deucher 
163697b2e202SAlex Deucher /*
163797b2e202SAlex Deucher  * SDMA
163897b2e202SAlex Deucher  */
1639c113ea1cSAlex Deucher struct amdgpu_sdma_instance {
164097b2e202SAlex Deucher 	/* SDMA firmware */
164197b2e202SAlex Deucher 	const struct firmware	*fw;
164297b2e202SAlex Deucher 	uint32_t		fw_version;
1643cfa2104fSJammy Zhou 	uint32_t		feature_version;
164497b2e202SAlex Deucher 
164597b2e202SAlex Deucher 	struct amdgpu_ring	ring;
164618111de0SJammy Zhou 	bool			burst_nop;
164797b2e202SAlex Deucher };
164897b2e202SAlex Deucher 
1649c113ea1cSAlex Deucher struct amdgpu_sdma {
1650c113ea1cSAlex Deucher 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1651c113ea1cSAlex Deucher 	struct amdgpu_irq_src	trap_irq;
1652c113ea1cSAlex Deucher 	struct amdgpu_irq_src	illegal_inst_irq;
1653c113ea1cSAlex Deucher 	int 			num_instances;
1654c113ea1cSAlex Deucher };
1655c113ea1cSAlex Deucher 
165697b2e202SAlex Deucher /*
165797b2e202SAlex Deucher  * Firmware
165897b2e202SAlex Deucher  */
165997b2e202SAlex Deucher struct amdgpu_firmware {
166097b2e202SAlex Deucher 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
166197b2e202SAlex Deucher 	bool smu_load;
166297b2e202SAlex Deucher 	struct amdgpu_bo *fw_buf;
166397b2e202SAlex Deucher 	unsigned int fw_size;
166497b2e202SAlex Deucher };
166597b2e202SAlex Deucher 
166697b2e202SAlex Deucher /*
166797b2e202SAlex Deucher  * Benchmarking
166897b2e202SAlex Deucher  */
166997b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
167097b2e202SAlex Deucher 
167197b2e202SAlex Deucher 
167297b2e202SAlex Deucher /*
167397b2e202SAlex Deucher  * Testing
167497b2e202SAlex Deucher  */
167597b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev);
167697b2e202SAlex Deucher void amdgpu_test_ring_sync(struct amdgpu_device *adev,
167797b2e202SAlex Deucher 			   struct amdgpu_ring *cpA,
167897b2e202SAlex Deucher 			   struct amdgpu_ring *cpB);
167997b2e202SAlex Deucher void amdgpu_test_syncing(struct amdgpu_device *adev);
168097b2e202SAlex Deucher 
168197b2e202SAlex Deucher /*
168297b2e202SAlex Deucher  * MMU Notifier
168397b2e202SAlex Deucher  */
168497b2e202SAlex Deucher #if defined(CONFIG_MMU_NOTIFIER)
168597b2e202SAlex Deucher int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
168697b2e202SAlex Deucher void amdgpu_mn_unregister(struct amdgpu_bo *bo);
168797b2e202SAlex Deucher #else
16881d1106b0SHarry Wentland static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
168997b2e202SAlex Deucher {
169097b2e202SAlex Deucher 	return -ENODEV;
169197b2e202SAlex Deucher }
16921d1106b0SHarry Wentland static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
169397b2e202SAlex Deucher #endif
169497b2e202SAlex Deucher 
169597b2e202SAlex Deucher /*
169697b2e202SAlex Deucher  * Debugfs
169797b2e202SAlex Deucher  */
169897b2e202SAlex Deucher struct amdgpu_debugfs {
169997b2e202SAlex Deucher 	struct drm_info_list	*files;
170097b2e202SAlex Deucher 	unsigned		num_files;
170197b2e202SAlex Deucher };
170297b2e202SAlex Deucher 
170397b2e202SAlex Deucher int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
170497b2e202SAlex Deucher 			     struct drm_info_list *files,
170597b2e202SAlex Deucher 			     unsigned nfiles);
170697b2e202SAlex Deucher int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
170797b2e202SAlex Deucher 
170897b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
170997b2e202SAlex Deucher int amdgpu_debugfs_init(struct drm_minor *minor);
171097b2e202SAlex Deucher void amdgpu_debugfs_cleanup(struct drm_minor *minor);
171197b2e202SAlex Deucher #endif
171297b2e202SAlex Deucher 
171397b2e202SAlex Deucher /*
171497b2e202SAlex Deucher  * amdgpu smumgr functions
171597b2e202SAlex Deucher  */
171697b2e202SAlex Deucher struct amdgpu_smumgr_funcs {
171797b2e202SAlex Deucher 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
171897b2e202SAlex Deucher 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
171997b2e202SAlex Deucher 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
172097b2e202SAlex Deucher };
172197b2e202SAlex Deucher 
172297b2e202SAlex Deucher /*
172397b2e202SAlex Deucher  * amdgpu smumgr
172497b2e202SAlex Deucher  */
172597b2e202SAlex Deucher struct amdgpu_smumgr {
172697b2e202SAlex Deucher 	struct amdgpu_bo *toc_buf;
172797b2e202SAlex Deucher 	struct amdgpu_bo *smu_buf;
172897b2e202SAlex Deucher 	/* asic priv smu data */
172997b2e202SAlex Deucher 	void *priv;
173097b2e202SAlex Deucher 	spinlock_t smu_lock;
173197b2e202SAlex Deucher 	/* smumgr functions */
173297b2e202SAlex Deucher 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
173397b2e202SAlex Deucher 	/* ucode loading complete flag */
173497b2e202SAlex Deucher 	uint32_t fw_flags;
173597b2e202SAlex Deucher };
173697b2e202SAlex Deucher 
173797b2e202SAlex Deucher /*
173897b2e202SAlex Deucher  * ASIC specific register table accessible by UMD
173997b2e202SAlex Deucher  */
174097b2e202SAlex Deucher struct amdgpu_allowed_register_entry {
174197b2e202SAlex Deucher 	uint32_t reg_offset;
174297b2e202SAlex Deucher 	bool untouched;
174397b2e202SAlex Deucher 	bool grbm_indexed;
174497b2e202SAlex Deucher };
174597b2e202SAlex Deucher 
174697b2e202SAlex Deucher struct amdgpu_cu_info {
174797b2e202SAlex Deucher 	uint32_t number; /* total active CU number */
174897b2e202SAlex Deucher 	uint32_t ao_cu_mask;
174997b2e202SAlex Deucher 	uint32_t bitmap[4][4];
175097b2e202SAlex Deucher };
175197b2e202SAlex Deucher 
175297b2e202SAlex Deucher 
175397b2e202SAlex Deucher /*
175497b2e202SAlex Deucher  * ASIC specific functions.
175597b2e202SAlex Deucher  */
175697b2e202SAlex Deucher struct amdgpu_asic_funcs {
175797b2e202SAlex Deucher 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
17587946b878SAlex Deucher 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
17597946b878SAlex Deucher 				   u8 *bios, u32 length_bytes);
176097b2e202SAlex Deucher 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
176197b2e202SAlex Deucher 			     u32 sh_num, u32 reg_offset, u32 *value);
176297b2e202SAlex Deucher 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
176397b2e202SAlex Deucher 	int (*reset)(struct amdgpu_device *adev);
176497b2e202SAlex Deucher 	/* wait for mc_idle */
176597b2e202SAlex Deucher 	int (*wait_for_mc_idle)(struct amdgpu_device *adev);
176697b2e202SAlex Deucher 	/* get the reference clock */
176797b2e202SAlex Deucher 	u32 (*get_xclk)(struct amdgpu_device *adev);
176897b2e202SAlex Deucher 	/* get the gpu clock counter */
176997b2e202SAlex Deucher 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
177097b2e202SAlex Deucher 	int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
177197b2e202SAlex Deucher 	/* MM block clocks */
177297b2e202SAlex Deucher 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
177397b2e202SAlex Deucher 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
177497b2e202SAlex Deucher };
177597b2e202SAlex Deucher 
177697b2e202SAlex Deucher /*
177797b2e202SAlex Deucher  * IOCTL.
177897b2e202SAlex Deucher  */
177997b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
178097b2e202SAlex Deucher 			    struct drm_file *filp);
178197b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
178297b2e202SAlex Deucher 				struct drm_file *filp);
178397b2e202SAlex Deucher 
178497b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
178597b2e202SAlex Deucher 			  struct drm_file *filp);
178697b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
178797b2e202SAlex Deucher 			struct drm_file *filp);
178897b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
178997b2e202SAlex Deucher 			  struct drm_file *filp);
179097b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
179197b2e202SAlex Deucher 			      struct drm_file *filp);
179297b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
179397b2e202SAlex Deucher 			  struct drm_file *filp);
179497b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
179597b2e202SAlex Deucher 			struct drm_file *filp);
179697b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
179797b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
179897b2e202SAlex Deucher 
179997b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
180097b2e202SAlex Deucher 				struct drm_file *filp);
180197b2e202SAlex Deucher 
180297b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */
180397b2e202SAlex Deucher struct amdgpu_vram_scratch {
180497b2e202SAlex Deucher 	struct amdgpu_bo		*robj;
180597b2e202SAlex Deucher 	volatile uint32_t		*ptr;
180697b2e202SAlex Deucher 	u64				gpu_addr;
180797b2e202SAlex Deucher };
180897b2e202SAlex Deucher 
180997b2e202SAlex Deucher /*
181097b2e202SAlex Deucher  * ACPI
181197b2e202SAlex Deucher  */
181297b2e202SAlex Deucher struct amdgpu_atif_notification_cfg {
181397b2e202SAlex Deucher 	bool enabled;
181497b2e202SAlex Deucher 	int command_code;
181597b2e202SAlex Deucher };
181697b2e202SAlex Deucher 
181797b2e202SAlex Deucher struct amdgpu_atif_notifications {
181897b2e202SAlex Deucher 	bool display_switch;
181997b2e202SAlex Deucher 	bool expansion_mode_change;
182097b2e202SAlex Deucher 	bool thermal_state;
182197b2e202SAlex Deucher 	bool forced_power_state;
182297b2e202SAlex Deucher 	bool system_power_state;
182397b2e202SAlex Deucher 	bool display_conf_change;
182497b2e202SAlex Deucher 	bool px_gfx_switch;
182597b2e202SAlex Deucher 	bool brightness_change;
182697b2e202SAlex Deucher 	bool dgpu_display_event;
182797b2e202SAlex Deucher };
182897b2e202SAlex Deucher 
182997b2e202SAlex Deucher struct amdgpu_atif_functions {
183097b2e202SAlex Deucher 	bool system_params;
183197b2e202SAlex Deucher 	bool sbios_requests;
183297b2e202SAlex Deucher 	bool select_active_disp;
183397b2e202SAlex Deucher 	bool lid_state;
183497b2e202SAlex Deucher 	bool get_tv_standard;
183597b2e202SAlex Deucher 	bool set_tv_standard;
183697b2e202SAlex Deucher 	bool get_panel_expansion_mode;
183797b2e202SAlex Deucher 	bool set_panel_expansion_mode;
183897b2e202SAlex Deucher 	bool temperature_change;
183997b2e202SAlex Deucher 	bool graphics_device_types;
184097b2e202SAlex Deucher };
184197b2e202SAlex Deucher 
184297b2e202SAlex Deucher struct amdgpu_atif {
184397b2e202SAlex Deucher 	struct amdgpu_atif_notifications notifications;
184497b2e202SAlex Deucher 	struct amdgpu_atif_functions functions;
184597b2e202SAlex Deucher 	struct amdgpu_atif_notification_cfg notification_cfg;
184697b2e202SAlex Deucher 	struct amdgpu_encoder *encoder_for_bl;
184797b2e202SAlex Deucher };
184897b2e202SAlex Deucher 
184997b2e202SAlex Deucher struct amdgpu_atcs_functions {
185097b2e202SAlex Deucher 	bool get_ext_state;
185197b2e202SAlex Deucher 	bool pcie_perf_req;
185297b2e202SAlex Deucher 	bool pcie_dev_rdy;
185397b2e202SAlex Deucher 	bool pcie_bus_width;
185497b2e202SAlex Deucher };
185597b2e202SAlex Deucher 
185697b2e202SAlex Deucher struct amdgpu_atcs {
185797b2e202SAlex Deucher 	struct amdgpu_atcs_functions functions;
185897b2e202SAlex Deucher };
185997b2e202SAlex Deucher 
186097b2e202SAlex Deucher /*
1861d03846afSChunming Zhou  * CGS
1862d03846afSChunming Zhou  */
1863d03846afSChunming Zhou void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1864d03846afSChunming Zhou void amdgpu_cgs_destroy_device(void *cgs_device);
1865d03846afSChunming Zhou 
1866d03846afSChunming Zhou 
1867d03846afSChunming Zhou /*
1868a8fe58ceSMaruthi Bayyavarapu  * CGS
1869a8fe58ceSMaruthi Bayyavarapu  */
1870a8fe58ceSMaruthi Bayyavarapu void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1871a8fe58ceSMaruthi Bayyavarapu void amdgpu_cgs_destroy_device(void *cgs_device);
1872a8fe58ceSMaruthi Bayyavarapu 
1873a8fe58ceSMaruthi Bayyavarapu 
18747e471e6fSAlex Deucher /* GPU virtualization */
18757e471e6fSAlex Deucher struct amdgpu_virtualization {
18767e471e6fSAlex Deucher 	bool supports_sr_iov;
18777e471e6fSAlex Deucher };
18787e471e6fSAlex Deucher 
1879a8fe58ceSMaruthi Bayyavarapu /*
188097b2e202SAlex Deucher  * Core structure, functions and helpers.
188197b2e202SAlex Deucher  */
188297b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
188397b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
188497b2e202SAlex Deucher 
188597b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
188697b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
188797b2e202SAlex Deucher 
18888faf0e08SAlex Deucher struct amdgpu_ip_block_status {
18898faf0e08SAlex Deucher 	bool valid;
18908faf0e08SAlex Deucher 	bool sw;
18918faf0e08SAlex Deucher 	bool hw;
18928faf0e08SAlex Deucher };
18938faf0e08SAlex Deucher 
189497b2e202SAlex Deucher struct amdgpu_device {
189597b2e202SAlex Deucher 	struct device			*dev;
189697b2e202SAlex Deucher 	struct drm_device		*ddev;
189797b2e202SAlex Deucher 	struct pci_dev			*pdev;
189897b2e202SAlex Deucher 
1899a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP
1900a8fe58ceSMaruthi Bayyavarapu 	struct amdgpu_acp		acp;
1901a8fe58ceSMaruthi Bayyavarapu #endif
1902a8fe58ceSMaruthi Bayyavarapu 
190397b2e202SAlex Deucher 	/* ASIC */
19042f7d10b3SJammy Zhou 	enum amd_asic_type		asic_type;
190597b2e202SAlex Deucher 	uint32_t			family;
190697b2e202SAlex Deucher 	uint32_t			rev_id;
190797b2e202SAlex Deucher 	uint32_t			external_rev_id;
190897b2e202SAlex Deucher 	unsigned long			flags;
190997b2e202SAlex Deucher 	int				usec_timeout;
191097b2e202SAlex Deucher 	const struct amdgpu_asic_funcs	*asic_funcs;
191197b2e202SAlex Deucher 	bool				shutdown;
191297b2e202SAlex Deucher 	bool				need_dma32;
191397b2e202SAlex Deucher 	bool				accel_working;
191497b2e202SAlex Deucher 	struct work_struct 		reset_work;
191597b2e202SAlex Deucher 	struct notifier_block		acpi_nb;
191697b2e202SAlex Deucher 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
191797b2e202SAlex Deucher 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
191897b2e202SAlex Deucher 	unsigned 			debugfs_count;
191997b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS)
192097b2e202SAlex Deucher 	struct dentry			*debugfs_regs;
192197b2e202SAlex Deucher #endif
192297b2e202SAlex Deucher 	struct amdgpu_atif		atif;
192397b2e202SAlex Deucher 	struct amdgpu_atcs		atcs;
192497b2e202SAlex Deucher 	struct mutex			srbm_mutex;
192597b2e202SAlex Deucher 	/* GRBM index mutex. Protects concurrent access to GRBM index */
192697b2e202SAlex Deucher 	struct mutex                    grbm_idx_mutex;
192797b2e202SAlex Deucher 	struct dev_pm_domain		vga_pm_domain;
192897b2e202SAlex Deucher 	bool				have_disp_power_ref;
192997b2e202SAlex Deucher 
193097b2e202SAlex Deucher 	/* BIOS */
193197b2e202SAlex Deucher 	uint8_t				*bios;
193297b2e202SAlex Deucher 	bool				is_atom_bios;
193397b2e202SAlex Deucher 	struct amdgpu_bo		*stollen_vga_memory;
193497b2e202SAlex Deucher 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
193597b2e202SAlex Deucher 
193697b2e202SAlex Deucher 	/* Register/doorbell mmio */
193797b2e202SAlex Deucher 	resource_size_t			rmmio_base;
193897b2e202SAlex Deucher 	resource_size_t			rmmio_size;
193997b2e202SAlex Deucher 	void __iomem			*rmmio;
194097b2e202SAlex Deucher 	/* protects concurrent MM_INDEX/DATA based register access */
194197b2e202SAlex Deucher 	spinlock_t mmio_idx_lock;
194297b2e202SAlex Deucher 	/* protects concurrent SMC based register access */
194397b2e202SAlex Deucher 	spinlock_t smc_idx_lock;
194497b2e202SAlex Deucher 	amdgpu_rreg_t			smc_rreg;
194597b2e202SAlex Deucher 	amdgpu_wreg_t			smc_wreg;
194697b2e202SAlex Deucher 	/* protects concurrent PCIE register access */
194797b2e202SAlex Deucher 	spinlock_t pcie_idx_lock;
194897b2e202SAlex Deucher 	amdgpu_rreg_t			pcie_rreg;
194997b2e202SAlex Deucher 	amdgpu_wreg_t			pcie_wreg;
195097b2e202SAlex Deucher 	/* protects concurrent UVD register access */
195197b2e202SAlex Deucher 	spinlock_t uvd_ctx_idx_lock;
195297b2e202SAlex Deucher 	amdgpu_rreg_t			uvd_ctx_rreg;
195397b2e202SAlex Deucher 	amdgpu_wreg_t			uvd_ctx_wreg;
195497b2e202SAlex Deucher 	/* protects concurrent DIDT register access */
195597b2e202SAlex Deucher 	spinlock_t didt_idx_lock;
195697b2e202SAlex Deucher 	amdgpu_rreg_t			didt_rreg;
195797b2e202SAlex Deucher 	amdgpu_wreg_t			didt_wreg;
195897b2e202SAlex Deucher 	/* protects concurrent ENDPOINT (audio) register access */
195997b2e202SAlex Deucher 	spinlock_t audio_endpt_idx_lock;
196097b2e202SAlex Deucher 	amdgpu_block_rreg_t		audio_endpt_rreg;
196197b2e202SAlex Deucher 	amdgpu_block_wreg_t		audio_endpt_wreg;
196297b2e202SAlex Deucher 	void __iomem                    *rio_mem;
196397b2e202SAlex Deucher 	resource_size_t			rio_mem_size;
196497b2e202SAlex Deucher 	struct amdgpu_doorbell		doorbell;
196597b2e202SAlex Deucher 
196697b2e202SAlex Deucher 	/* clock/pll info */
196797b2e202SAlex Deucher 	struct amdgpu_clock            clock;
196897b2e202SAlex Deucher 
196997b2e202SAlex Deucher 	/* MC */
197097b2e202SAlex Deucher 	struct amdgpu_mc		mc;
197197b2e202SAlex Deucher 	struct amdgpu_gart		gart;
197297b2e202SAlex Deucher 	struct amdgpu_dummy_page	dummy_page;
197397b2e202SAlex Deucher 	struct amdgpu_vm_manager	vm_manager;
197497b2e202SAlex Deucher 
197597b2e202SAlex Deucher 	/* memory management */
197697b2e202SAlex Deucher 	struct amdgpu_mman		mman;
197797b2e202SAlex Deucher 	struct amdgpu_vram_scratch	vram_scratch;
197897b2e202SAlex Deucher 	struct amdgpu_wb		wb;
197997b2e202SAlex Deucher 	atomic64_t			vram_usage;
198097b2e202SAlex Deucher 	atomic64_t			vram_vis_usage;
198197b2e202SAlex Deucher 	atomic64_t			gtt_usage;
198297b2e202SAlex Deucher 	atomic64_t			num_bytes_moved;
1983d94aed5aSMarek Olšák 	atomic_t			gpu_reset_counter;
198497b2e202SAlex Deucher 
198597b2e202SAlex Deucher 	/* display */
198697b2e202SAlex Deucher 	struct amdgpu_mode_info		mode_info;
198797b2e202SAlex Deucher 	struct work_struct		hotplug_work;
198897b2e202SAlex Deucher 	struct amdgpu_irq_src		crtc_irq;
198997b2e202SAlex Deucher 	struct amdgpu_irq_src		pageflip_irq;
199097b2e202SAlex Deucher 	struct amdgpu_irq_src		hpd_irq;
199197b2e202SAlex Deucher 
199297b2e202SAlex Deucher 	/* rings */
199397b2e202SAlex Deucher 	unsigned			fence_context;
199497b2e202SAlex Deucher 	unsigned			num_rings;
199597b2e202SAlex Deucher 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
199697b2e202SAlex Deucher 	bool				ib_pool_ready;
199797b2e202SAlex Deucher 	struct amdgpu_sa_manager	ring_tmp_bo;
199897b2e202SAlex Deucher 
199997b2e202SAlex Deucher 	/* interrupts */
200097b2e202SAlex Deucher 	struct amdgpu_irq		irq;
200197b2e202SAlex Deucher 
20021f7371b2SAlex Deucher 	/* powerplay */
20031f7371b2SAlex Deucher 	struct amd_powerplay		powerplay;
2004e61710c5SJammy Zhou 	bool				pp_enabled;
2005f3898ea1SEric Huang 	bool				pp_force_state_enabled;
20061f7371b2SAlex Deucher 
200797b2e202SAlex Deucher 	/* dpm */
200897b2e202SAlex Deucher 	struct amdgpu_pm		pm;
200997b2e202SAlex Deucher 	u32				cg_flags;
201097b2e202SAlex Deucher 	u32				pg_flags;
201197b2e202SAlex Deucher 
201297b2e202SAlex Deucher 	/* amdgpu smumgr */
201397b2e202SAlex Deucher 	struct amdgpu_smumgr smu;
201497b2e202SAlex Deucher 
201597b2e202SAlex Deucher 	/* gfx */
201697b2e202SAlex Deucher 	struct amdgpu_gfx		gfx;
201797b2e202SAlex Deucher 
201897b2e202SAlex Deucher 	/* sdma */
2019c113ea1cSAlex Deucher 	struct amdgpu_sdma		sdma;
202097b2e202SAlex Deucher 
202197b2e202SAlex Deucher 	/* uvd */
202297b2e202SAlex Deucher 	struct amdgpu_uvd		uvd;
202397b2e202SAlex Deucher 
202497b2e202SAlex Deucher 	/* vce */
202597b2e202SAlex Deucher 	struct amdgpu_vce		vce;
202697b2e202SAlex Deucher 
202797b2e202SAlex Deucher 	/* firmwares */
202897b2e202SAlex Deucher 	struct amdgpu_firmware		firmware;
202997b2e202SAlex Deucher 
203097b2e202SAlex Deucher 	/* GDS */
203197b2e202SAlex Deucher 	struct amdgpu_gds		gds;
203297b2e202SAlex Deucher 
203397b2e202SAlex Deucher 	const struct amdgpu_ip_block_version *ip_blocks;
203497b2e202SAlex Deucher 	int				num_ip_blocks;
20358faf0e08SAlex Deucher 	struct amdgpu_ip_block_status	*ip_block_status;
203697b2e202SAlex Deucher 	struct mutex	mn_lock;
203797b2e202SAlex Deucher 	DECLARE_HASHTABLE(mn_hash, 7);
203897b2e202SAlex Deucher 
203997b2e202SAlex Deucher 	/* tracking pinned memory */
204097b2e202SAlex Deucher 	u64 vram_pin_size;
204197b2e202SAlex Deucher 	u64 gart_pin_size;
2042130e0371SOded Gabbay 
2043130e0371SOded Gabbay 	/* amdkfd interface */
2044130e0371SOded Gabbay 	struct kfd_dev          *kfd;
204523ca0e4eSChunming Zhou 
20467e471e6fSAlex Deucher 	struct amdgpu_virtualization virtualization;
204797b2e202SAlex Deucher };
204897b2e202SAlex Deucher 
204997b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
205097b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev,
205197b2e202SAlex Deucher 		       struct drm_device *ddev,
205297b2e202SAlex Deucher 		       struct pci_dev *pdev,
205397b2e202SAlex Deucher 		       uint32_t flags);
205497b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev);
205597b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
205697b2e202SAlex Deucher 
205797b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
205897b2e202SAlex Deucher 			bool always_indirect);
205997b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
206097b2e202SAlex Deucher 		    bool always_indirect);
206197b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
206297b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
206397b2e202SAlex Deucher 
206497b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
206597b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
206697b2e202SAlex Deucher 
206797b2e202SAlex Deucher /*
206897b2e202SAlex Deucher  * Registers read & write functions.
206997b2e202SAlex Deucher  */
207097b2e202SAlex Deucher #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
207197b2e202SAlex Deucher #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
207297b2e202SAlex Deucher #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
207397b2e202SAlex Deucher #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
207497b2e202SAlex Deucher #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
207597b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
207697b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
207797b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
207897b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
207997b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
208097b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
208197b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
208297b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
208397b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
208497b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
208597b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
208697b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
208797b2e202SAlex Deucher #define WREG32_P(reg, val, mask)				\
208897b2e202SAlex Deucher 	do {							\
208997b2e202SAlex Deucher 		uint32_t tmp_ = RREG32(reg);			\
209097b2e202SAlex Deucher 		tmp_ &= (mask);					\
209197b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
209297b2e202SAlex Deucher 		WREG32(reg, tmp_);				\
209397b2e202SAlex Deucher 	} while (0)
209497b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
209597b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
209697b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask)				\
209797b2e202SAlex Deucher 	do {							\
209897b2e202SAlex Deucher 		uint32_t tmp_ = RREG32_PLL(reg);		\
209997b2e202SAlex Deucher 		tmp_ &= (mask);					\
210097b2e202SAlex Deucher 		tmp_ |= ((val) & ~(mask));			\
210197b2e202SAlex Deucher 		WREG32_PLL(reg, tmp_);				\
210297b2e202SAlex Deucher 	} while (0)
210397b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
210497b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
210597b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
210697b2e202SAlex Deucher 
210797b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
210897b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
210997b2e202SAlex Deucher 
211097b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
211197b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
211297b2e202SAlex Deucher 
211397b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
211497b2e202SAlex Deucher 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
211597b2e202SAlex Deucher 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
211697b2e202SAlex Deucher 
211797b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field)				\
211897b2e202SAlex Deucher 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
211997b2e202SAlex Deucher 
212097b2e202SAlex Deucher /*
212197b2e202SAlex Deucher  * BIOS helpers.
212297b2e202SAlex Deucher  */
212397b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i])
212497b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
212597b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
212697b2e202SAlex Deucher 
212797b2e202SAlex Deucher /*
212897b2e202SAlex Deucher  * RING helpers.
212997b2e202SAlex Deucher  */
213097b2e202SAlex Deucher static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
213197b2e202SAlex Deucher {
213297b2e202SAlex Deucher 	if (ring->count_dw <= 0)
213386c2b790SJammy Zhou 		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
213497b2e202SAlex Deucher 	ring->ring[ring->wptr++] = v;
213597b2e202SAlex Deucher 	ring->wptr &= ring->ptr_mask;
213697b2e202SAlex Deucher 	ring->count_dw--;
213797b2e202SAlex Deucher }
213897b2e202SAlex Deucher 
2139c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance *
2140c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
21414b2f7e2cSJammy Zhou {
21424b2f7e2cSJammy Zhou 	struct amdgpu_device *adev = ring->adev;
21434b2f7e2cSJammy Zhou 	int i;
21444b2f7e2cSJammy Zhou 
2145c113ea1cSAlex Deucher 	for (i = 0; i < adev->sdma.num_instances; i++)
2146c113ea1cSAlex Deucher 		if (&adev->sdma.instance[i].ring == ring)
21474b2f7e2cSJammy Zhou 			break;
21484b2f7e2cSJammy Zhou 
21494b2f7e2cSJammy Zhou 	if (i < AMDGPU_MAX_SDMA_INSTANCES)
2150c113ea1cSAlex Deucher 		return &adev->sdma.instance[i];
21514b2f7e2cSJammy Zhou 	else
21524b2f7e2cSJammy Zhou 		return NULL;
21534b2f7e2cSJammy Zhou }
21544b2f7e2cSJammy Zhou 
215597b2e202SAlex Deucher /*
215697b2e202SAlex Deucher  * ASICs macro.
215797b2e202SAlex Deucher  */
215897b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
215997b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
216097b2e202SAlex Deucher #define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
216197b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
216297b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
216397b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
216497b2e202SAlex Deucher #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
216597b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
21667946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
216797b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
216897b2e202SAlex Deucher #define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
216997b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
217097b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
217197b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
2172b07c9d2aSChristian König #define amdgpu_vm_write_pte(adev, ib, pa, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pa), (pe), (addr), (count), (incr), (flags)))
217397b2e202SAlex 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)))
217497b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
217597b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
217697b2e202SAlex Deucher #define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
217797b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
217897b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
217997b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
218097b2e202SAlex Deucher #define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
2181b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
218297b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
2183890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
218497b2e202SAlex 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))
2185d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
218611afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
21879e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
218803ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
218903ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
219097b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
219197b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
219297b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
219397b2e202SAlex Deucher #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
219497b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
219597b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
219697b2e202SAlex Deucher #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
219797b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
219897b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
219997b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
220097b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
220197b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
220297b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
220397b2e202SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
220497b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
220597b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
220697b2e202SAlex 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))
220797b2e202SAlex Deucher #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
220897b2e202SAlex Deucher #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
2209c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b))
22106e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
221197b2e202SAlex Deucher #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
221297b2e202SAlex Deucher #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
221397b2e202SAlex Deucher #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
221497b2e202SAlex Deucher #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
221597b2e202SAlex Deucher #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
221697b2e202SAlex Deucher #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
221797b2e202SAlex Deucher #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
22183af76f23SRex Zhu 
22193af76f23SRex Zhu #define amdgpu_dpm_get_temperature(adev) \
22204b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22213af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
22224b5ece24SEric Huang 	      (adev)->pm.funcs->get_temperature((adev)))
22233af76f23SRex Zhu 
22243af76f23SRex Zhu #define amdgpu_dpm_set_fan_control_mode(adev, m) \
22254b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22263af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
22274b5ece24SEric Huang 	      (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
22283af76f23SRex Zhu 
22293af76f23SRex Zhu #define amdgpu_dpm_get_fan_control_mode(adev) \
22304b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22313af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
22324b5ece24SEric Huang 	      (adev)->pm.funcs->get_fan_control_mode((adev)))
22333af76f23SRex Zhu 
22343af76f23SRex Zhu #define amdgpu_dpm_set_fan_speed_percent(adev, s) \
22354b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22363af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
22374b5ece24SEric Huang 	      (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
22383af76f23SRex Zhu 
22393af76f23SRex Zhu #define amdgpu_dpm_get_fan_speed_percent(adev, s) \
22404b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22413af76f23SRex Zhu 	      (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
22424b5ece24SEric Huang 	      (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
224397b2e202SAlex Deucher 
22441b5708ffSRex Zhu #define amdgpu_dpm_get_sclk(adev, l) \
22454b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22461b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
22474b5ece24SEric Huang 		(adev)->pm.funcs->get_sclk((adev), (l)))
22481b5708ffSRex Zhu 
22491b5708ffSRex Zhu #define amdgpu_dpm_get_mclk(adev, l)  \
22504b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22511b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
22524b5ece24SEric Huang 	      (adev)->pm.funcs->get_mclk((adev), (l)))
22531b5708ffSRex Zhu 
22541b5708ffSRex Zhu 
22551b5708ffSRex Zhu #define amdgpu_dpm_force_performance_level(adev, l) \
22564b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22571b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
22584b5ece24SEric Huang 	      (adev)->pm.funcs->force_performance_level((adev), (l)))
22591b5708ffSRex Zhu 
22601b5708ffSRex Zhu #define amdgpu_dpm_powergate_uvd(adev, g) \
22614b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22621b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
22634b5ece24SEric Huang 	      (adev)->pm.funcs->powergate_uvd((adev), (g)))
22641b5708ffSRex Zhu 
22651b5708ffSRex Zhu #define amdgpu_dpm_powergate_vce(adev, g) \
22664b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22671b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
22684b5ece24SEric Huang 	      (adev)->pm.funcs->powergate_vce((adev), (g)))
22691b5708ffSRex Zhu 
22701b5708ffSRex Zhu #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
22714b5ece24SEric Huang 	((adev)->pp_enabled ?						\
22721b5708ffSRex Zhu 	      (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
22734b5ece24SEric Huang 	      (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
22741b5708ffSRex Zhu 
22751b5708ffSRex Zhu #define amdgpu_dpm_get_current_power_state(adev) \
22761b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
22771b5708ffSRex Zhu 
22781b5708ffSRex Zhu #define amdgpu_dpm_get_performance_level(adev) \
22791b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
22801b5708ffSRex Zhu 
2281f3898ea1SEric Huang #define amdgpu_dpm_get_pp_num_states(adev, data) \
2282f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2283f3898ea1SEric Huang 
2284f3898ea1SEric Huang #define amdgpu_dpm_get_pp_table(adev, table) \
2285f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2286f3898ea1SEric Huang 
2287f3898ea1SEric Huang #define amdgpu_dpm_set_pp_table(adev, buf, size) \
2288f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2289f3898ea1SEric Huang 
2290f3898ea1SEric Huang #define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2291f3898ea1SEric Huang 	(adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2292f3898ea1SEric Huang 
2293f3898ea1SEric Huang #define amdgpu_dpm_force_clock_level(adev, type, level) \
2294f3898ea1SEric Huang 		(adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2295f3898ea1SEric Huang 
22961b5708ffSRex Zhu #define amdgpu_dpm_dispatch_task(adev, event_id, input, output)		\
22971b5708ffSRex Zhu 	(adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
229897b2e202SAlex Deucher 
229997b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
230097b2e202SAlex Deucher 
230197b2e202SAlex Deucher /* Common functions */
230297b2e202SAlex Deucher int amdgpu_gpu_reset(struct amdgpu_device *adev);
230397b2e202SAlex Deucher void amdgpu_pci_config_reset(struct amdgpu_device *adev);
230497b2e202SAlex Deucher bool amdgpu_card_posted(struct amdgpu_device *adev);
230597b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev);
2306d5fc5e82SChunming Zhou 
230797b2e202SAlex Deucher int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
230897b2e202SAlex Deucher int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
230997b2e202SAlex Deucher 		       u32 ip_instance, u32 ring,
231097b2e202SAlex Deucher 		       struct amdgpu_ring **out_ring);
231197b2e202SAlex Deucher void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
231297b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
23132f568dbdSChristian König int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
231497b2e202SAlex Deucher int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
231597b2e202SAlex Deucher 				     uint32_t flags);
231697b2e202SAlex Deucher bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
2317cc325d19SChristian König struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
2318d7006964SChristian König bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2319d7006964SChristian König 				  unsigned long end);
23202f568dbdSChristian König bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
23212f568dbdSChristian König 				       int *last_invalidated);
232297b2e202SAlex Deucher bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
232397b2e202SAlex Deucher uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
232497b2e202SAlex Deucher 				 struct ttm_mem_reg *mem);
232597b2e202SAlex Deucher void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
232697b2e202SAlex Deucher void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
232797b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
232897b2e202SAlex Deucher void amdgpu_program_register_sequence(struct amdgpu_device *adev,
232997b2e202SAlex Deucher 					     const u32 *registers,
233097b2e202SAlex Deucher 					     const u32 array_size);
233197b2e202SAlex Deucher 
233297b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev);
233397b2e202SAlex Deucher /* atpx handler */
233497b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO)
233597b2e202SAlex Deucher void amdgpu_register_atpx_handler(void);
233697b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void);
233797b2e202SAlex Deucher #else
233897b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {}
233997b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {}
234097b2e202SAlex Deucher #endif
234197b2e202SAlex Deucher 
234297b2e202SAlex Deucher /*
234397b2e202SAlex Deucher  * KMS
234497b2e202SAlex Deucher  */
234597b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
234697b2e202SAlex Deucher extern int amdgpu_max_kms_ioctl;
234797b2e202SAlex Deucher 
234897b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
234997b2e202SAlex Deucher int amdgpu_driver_unload_kms(struct drm_device *dev);
235097b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev);
235197b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
235297b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev,
235397b2e202SAlex Deucher 				 struct drm_file *file_priv);
235497b2e202SAlex Deucher void amdgpu_driver_preclose_kms(struct drm_device *dev,
235597b2e202SAlex Deucher 				struct drm_file *file_priv);
235697b2e202SAlex Deucher int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
235797b2e202SAlex Deucher int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
235888e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
235988e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
236088e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
236188e72717SThierry Reding int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
236297b2e202SAlex Deucher 				    int *max_error,
236397b2e202SAlex Deucher 				    struct timeval *vblank_time,
236497b2e202SAlex Deucher 				    unsigned flags);
236597b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
236697b2e202SAlex Deucher 			     unsigned long arg);
236797b2e202SAlex Deucher 
236897b2e202SAlex Deucher /*
236997b2e202SAlex Deucher  * functions used by amdgpu_encoder.c
237097b2e202SAlex Deucher  */
237197b2e202SAlex Deucher struct amdgpu_afmt_acr {
237297b2e202SAlex Deucher 	u32 clock;
237397b2e202SAlex Deucher 
237497b2e202SAlex Deucher 	int n_32khz;
237597b2e202SAlex Deucher 	int cts_32khz;
237697b2e202SAlex Deucher 
237797b2e202SAlex Deucher 	int n_44_1khz;
237897b2e202SAlex Deucher 	int cts_44_1khz;
237997b2e202SAlex Deucher 
238097b2e202SAlex Deucher 	int n_48khz;
238197b2e202SAlex Deucher 	int cts_48khz;
238297b2e202SAlex Deucher 
238397b2e202SAlex Deucher };
238497b2e202SAlex Deucher 
238597b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
238697b2e202SAlex Deucher 
238797b2e202SAlex Deucher /* amdgpu_acpi.c */
238897b2e202SAlex Deucher #if defined(CONFIG_ACPI)
238997b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev);
239097b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev);
239197b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
239297b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
239397b2e202SAlex Deucher 						u8 perf_req, bool advertise);
239497b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
239597b2e202SAlex Deucher #else
239697b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
239797b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
239897b2e202SAlex Deucher #endif
239997b2e202SAlex Deucher 
240097b2e202SAlex Deucher struct amdgpu_bo_va_mapping *
240197b2e202SAlex Deucher amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
240297b2e202SAlex Deucher 		       uint64_t addr, struct amdgpu_bo **bo);
240397b2e202SAlex Deucher 
240497b2e202SAlex Deucher #include "amdgpu_object.h"
240597b2e202SAlex Deucher #endif
2406