xref: /dflybsd-src/sys/dev/drm/amd/amdgpu/amdgpu.h (revision 789731325bde747251c28a37e0a00ed4efb88c46)
1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2008 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev  * Copyright 2008 Red Hat Inc.
4b843c749SSergey Zigachev  * Copyright 2009 Jerome Glisse.
5b843c749SSergey Zigachev  *
6b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
7b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
8b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
9b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
11b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
12b843c749SSergey Zigachev  *
13b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
14b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
15b843c749SSergey Zigachev  *
16b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
23b843c749SSergey Zigachev  *
24b843c749SSergey Zigachev  * Authors: Dave Airlie
25b843c749SSergey Zigachev  *          Alex Deucher
26b843c749SSergey Zigachev  *          Jerome Glisse
27b843c749SSergey Zigachev  */
28b843c749SSergey Zigachev #ifndef __AMDGPU_H__
29b843c749SSergey Zigachev #define __AMDGPU_H__
30b843c749SSergey Zigachev 
31b843c749SSergey Zigachev #include <linux/atomic.h>
32b843c749SSergey Zigachev #include <linux/wait.h>
33b843c749SSergey Zigachev #include <linux/list.h>
34b843c749SSergey Zigachev #include <linux/kref.h>
35b843c749SSergey Zigachev #include <linux/rbtree.h>
36b843c749SSergey Zigachev #include <linux/hashtable.h>
37b843c749SSergey Zigachev #include <linux/dma-fence.h>
38b843c749SSergey Zigachev 
39*78973132SSergey Zigachev #include <asm/cpufeature.h>
40*78973132SSergey Zigachev 
41b843c749SSergey Zigachev #include <drm/ttm/ttm_bo_api.h>
42b843c749SSergey Zigachev #include <drm/ttm/ttm_bo_driver.h>
43b843c749SSergey Zigachev #include <drm/ttm/ttm_placement.h>
44b843c749SSergey Zigachev #include <drm/ttm/ttm_module.h>
45b843c749SSergey Zigachev #include <drm/ttm/ttm_execbuf_util.h>
46b843c749SSergey Zigachev 
47b843c749SSergey Zigachev #include <drm/drmP.h>
48b843c749SSergey Zigachev #include <drm/drm_gem.h>
49b843c749SSergey Zigachev #include <drm/amdgpu_drm.h>
50b843c749SSergey Zigachev #include <drm/gpu_scheduler.h>
51b843c749SSergey Zigachev 
52b843c749SSergey Zigachev #include <kgd_kfd_interface.h>
53b843c749SSergey Zigachev #include "dm_pp_interface.h"
54b843c749SSergey Zigachev #include "kgd_pp_interface.h"
55b843c749SSergey Zigachev 
56b843c749SSergey Zigachev #include "amd_shared.h"
57b843c749SSergey Zigachev #include "amdgpu_mode.h"
58b843c749SSergey Zigachev #include "amdgpu_ih.h"
59b843c749SSergey Zigachev #include "amdgpu_irq.h"
60b843c749SSergey Zigachev #include "amdgpu_ucode.h"
61b843c749SSergey Zigachev #include "amdgpu_ttm.h"
62b843c749SSergey Zigachev #include "amdgpu_psp.h"
63b843c749SSergey Zigachev #include "amdgpu_gds.h"
64b843c749SSergey Zigachev #include "amdgpu_sync.h"
65b843c749SSergey Zigachev #include "amdgpu_ring.h"
66b843c749SSergey Zigachev #include "amdgpu_vm.h"
67b843c749SSergey Zigachev #include "amdgpu_dpm.h"
68b843c749SSergey Zigachev #include "amdgpu_acp.h"
69b843c749SSergey Zigachev #include "amdgpu_uvd.h"
70b843c749SSergey Zigachev #include "amdgpu_vce.h"
71b843c749SSergey Zigachev #include "amdgpu_vcn.h"
72b843c749SSergey Zigachev #include "amdgpu_mn.h"
73b843c749SSergey Zigachev #include "amdgpu_gmc.h"
74b843c749SSergey Zigachev #include "amdgpu_dm.h"
75b843c749SSergey Zigachev #include "amdgpu_virt.h"
76b843c749SSergey Zigachev #include "amdgpu_gart.h"
77b843c749SSergey Zigachev #include "amdgpu_debugfs.h"
78b843c749SSergey Zigachev #include "amdgpu_job.h"
79b843c749SSergey Zigachev #include "amdgpu_bo_list.h"
80b843c749SSergey Zigachev 
81*78973132SSergey Zigachev #include <contrib/dev/acpica/source/include/acpi.h>
82*78973132SSergey Zigachev #include <dev/acpica/acpivar.h>
83*78973132SSergey Zigachev 
84b843c749SSergey Zigachev /*
85b843c749SSergey Zigachev  * Modules parameters.
86b843c749SSergey Zigachev  */
87b843c749SSergey Zigachev extern int amdgpu_modeset;
88b843c749SSergey Zigachev extern int amdgpu_vram_limit;
89b843c749SSergey Zigachev extern int amdgpu_vis_vram_limit;
90b843c749SSergey Zigachev extern int amdgpu_gart_size;
91b843c749SSergey Zigachev extern int amdgpu_gtt_size;
92b843c749SSergey Zigachev extern int amdgpu_moverate;
93b843c749SSergey Zigachev extern int amdgpu_benchmarking;
94b843c749SSergey Zigachev extern int amdgpu_testing;
95b843c749SSergey Zigachev extern int amdgpu_audio;
96b843c749SSergey Zigachev extern int amdgpu_disp_priority;
97b843c749SSergey Zigachev extern int amdgpu_hw_i2c;
98b843c749SSergey Zigachev extern int amdgpu_pcie_gen2;
99b843c749SSergey Zigachev extern int amdgpu_msi;
100b843c749SSergey Zigachev extern int amdgpu_lockup_timeout;
101b843c749SSergey Zigachev extern int amdgpu_dpm;
102b843c749SSergey Zigachev extern int amdgpu_fw_load_type;
103b843c749SSergey Zigachev extern int amdgpu_aspm;
104b843c749SSergey Zigachev extern int amdgpu_runtime_pm;
105b843c749SSergey Zigachev extern uint amdgpu_ip_block_mask;
106b843c749SSergey Zigachev extern int amdgpu_bapm;
107b843c749SSergey Zigachev extern int amdgpu_deep_color;
108b843c749SSergey Zigachev extern int amdgpu_vm_size;
109b843c749SSergey Zigachev extern int amdgpu_vm_block_size;
110b843c749SSergey Zigachev extern int amdgpu_vm_fragment_size;
111b843c749SSergey Zigachev extern int amdgpu_vm_fault_stop;
112b843c749SSergey Zigachev extern int amdgpu_vm_debug;
113b843c749SSergey Zigachev extern int amdgpu_vm_update_mode;
114b843c749SSergey Zigachev extern int amdgpu_dc;
115b843c749SSergey Zigachev extern int amdgpu_sched_jobs;
116b843c749SSergey Zigachev extern int amdgpu_sched_hw_submission;
117b843c749SSergey Zigachev extern uint amdgpu_pcie_gen_cap;
118b843c749SSergey Zigachev extern uint amdgpu_pcie_lane_cap;
119b843c749SSergey Zigachev extern uint amdgpu_cg_mask;
120b843c749SSergey Zigachev extern uint amdgpu_pg_mask;
121b843c749SSergey Zigachev extern uint amdgpu_sdma_phase_quantum;
122b843c749SSergey Zigachev extern char *amdgpu_disable_cu;
123b843c749SSergey Zigachev extern char *amdgpu_virtual_display;
124b843c749SSergey Zigachev extern uint amdgpu_pp_feature_mask;
125b843c749SSergey Zigachev extern int amdgpu_vram_page_split;
126b843c749SSergey Zigachev extern int amdgpu_ngg;
127b843c749SSergey Zigachev extern int amdgpu_prim_buf_per_se;
128b843c749SSergey Zigachev extern int amdgpu_pos_buf_per_se;
129b843c749SSergey Zigachev extern int amdgpu_cntl_sb_buf_per_se;
130b843c749SSergey Zigachev extern int amdgpu_param_buf_per_se;
131b843c749SSergey Zigachev extern int amdgpu_job_hang_limit;
132b843c749SSergey Zigachev extern int amdgpu_lbpw;
133b843c749SSergey Zigachev extern int amdgpu_compute_multipipe;
134b843c749SSergey Zigachev extern int amdgpu_gpu_recovery;
135b843c749SSergey Zigachev extern int amdgpu_emu_mode;
136b843c749SSergey Zigachev extern uint amdgpu_smu_memory_pool_size;
137b843c749SSergey Zigachev 
138b843c749SSergey Zigachev #ifdef CONFIG_DRM_AMDGPU_SI
139b843c749SSergey Zigachev extern int amdgpu_si_support;
140b843c749SSergey Zigachev #endif
141b843c749SSergey Zigachev #ifdef CONFIG_DRM_AMDGPU_CIK
142b843c749SSergey Zigachev extern int amdgpu_cik_support;
143b843c749SSergey Zigachev #endif
144b843c749SSergey Zigachev 
145b843c749SSergey Zigachev #define AMDGPU_SG_THRESHOLD			(256*1024*1024)
146b843c749SSergey Zigachev #define AMDGPU_DEFAULT_GTT_SIZE_MB		3072ULL /* 3GB by default */
147b843c749SSergey Zigachev #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
148b843c749SSergey Zigachev #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
149b843c749SSergey Zigachev #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
150b843c749SSergey Zigachev /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
151b843c749SSergey Zigachev #define AMDGPU_IB_POOL_SIZE			16
152b843c749SSergey Zigachev #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
153b843c749SSergey Zigachev #define AMDGPUFB_CONN_LIMIT			4
154b843c749SSergey Zigachev #define AMDGPU_BIOS_NUM_SCRATCH			16
155b843c749SSergey Zigachev 
156b843c749SSergey Zigachev /* max number of IP instances */
157b843c749SSergey Zigachev #define AMDGPU_MAX_SDMA_INSTANCES		2
158b843c749SSergey Zigachev 
159b843c749SSergey Zigachev /* hard reset data */
160b843c749SSergey Zigachev #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
161b843c749SSergey Zigachev 
162b843c749SSergey Zigachev /* reset flags */
163b843c749SSergey Zigachev #define AMDGPU_RESET_GFX			(1 << 0)
164b843c749SSergey Zigachev #define AMDGPU_RESET_COMPUTE			(1 << 1)
165b843c749SSergey Zigachev #define AMDGPU_RESET_DMA			(1 << 2)
166b843c749SSergey Zigachev #define AMDGPU_RESET_CP				(1 << 3)
167b843c749SSergey Zigachev #define AMDGPU_RESET_GRBM			(1 << 4)
168b843c749SSergey Zigachev #define AMDGPU_RESET_DMA1			(1 << 5)
169b843c749SSergey Zigachev #define AMDGPU_RESET_RLC			(1 << 6)
170b843c749SSergey Zigachev #define AMDGPU_RESET_SEM			(1 << 7)
171b843c749SSergey Zigachev #define AMDGPU_RESET_IH				(1 << 8)
172b843c749SSergey Zigachev #define AMDGPU_RESET_VMC			(1 << 9)
173b843c749SSergey Zigachev #define AMDGPU_RESET_MC				(1 << 10)
174b843c749SSergey Zigachev #define AMDGPU_RESET_DISPLAY			(1 << 11)
175b843c749SSergey Zigachev #define AMDGPU_RESET_UVD			(1 << 12)
176b843c749SSergey Zigachev #define AMDGPU_RESET_VCE			(1 << 13)
177b843c749SSergey Zigachev #define AMDGPU_RESET_VCE1			(1 << 14)
178b843c749SSergey Zigachev 
179b843c749SSergey Zigachev /* GFX current status */
180b843c749SSergey Zigachev #define AMDGPU_GFX_NORMAL_MODE			0x00000000L
181b843c749SSergey Zigachev #define AMDGPU_GFX_SAFE_MODE			0x00000001L
182b843c749SSergey Zigachev #define AMDGPU_GFX_PG_DISABLED_MODE		0x00000002L
183b843c749SSergey Zigachev #define AMDGPU_GFX_CG_DISABLED_MODE		0x00000004L
184b843c749SSergey Zigachev #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
185b843c749SSergey Zigachev 
186b843c749SSergey Zigachev /* max cursor sizes (in pixels) */
187b843c749SSergey Zigachev #define CIK_CURSOR_WIDTH 128
188b843c749SSergey Zigachev #define CIK_CURSOR_HEIGHT 128
189b843c749SSergey Zigachev 
190b843c749SSergey Zigachev struct amdgpu_device;
191b843c749SSergey Zigachev struct amdgpu_ib;
192b843c749SSergey Zigachev struct amdgpu_cs_parser;
193b843c749SSergey Zigachev struct amdgpu_job;
194b843c749SSergey Zigachev struct amdgpu_irq_src;
195b843c749SSergey Zigachev struct amdgpu_fpriv;
196b843c749SSergey Zigachev struct amdgpu_bo_va_mapping;
197b843c749SSergey Zigachev struct amdgpu_atif;
198b843c749SSergey Zigachev 
199b843c749SSergey Zigachev enum amdgpu_cp_irq {
200b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_GFX_EOP = 0,
201b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
202b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
203b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
204b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
205b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
206b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
207b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
208b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
209b843c749SSergey Zigachev 
210b843c749SSergey Zigachev 	AMDGPU_CP_IRQ_LAST
211b843c749SSergey Zigachev };
212b843c749SSergey Zigachev 
213b843c749SSergey Zigachev enum amdgpu_sdma_irq {
214b843c749SSergey Zigachev 	AMDGPU_SDMA_IRQ_TRAP0 = 0,
215b843c749SSergey Zigachev 	AMDGPU_SDMA_IRQ_TRAP1,
216b843c749SSergey Zigachev 
217b843c749SSergey Zigachev 	AMDGPU_SDMA_IRQ_LAST
218b843c749SSergey Zigachev };
219b843c749SSergey Zigachev 
220b843c749SSergey Zigachev enum amdgpu_thermal_irq {
221b843c749SSergey Zigachev 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
222b843c749SSergey Zigachev 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
223b843c749SSergey Zigachev 
224b843c749SSergey Zigachev 	AMDGPU_THERMAL_IRQ_LAST
225b843c749SSergey Zigachev };
226b843c749SSergey Zigachev 
227b843c749SSergey Zigachev enum amdgpu_kiq_irq {
228b843c749SSergey Zigachev 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
229b843c749SSergey Zigachev 	AMDGPU_CP_KIQ_IRQ_LAST
230b843c749SSergey Zigachev };
231b843c749SSergey Zigachev 
232b843c749SSergey Zigachev int amdgpu_device_ip_set_clockgating_state(void *dev,
233b843c749SSergey Zigachev 					   enum amd_ip_block_type block_type,
234b843c749SSergey Zigachev 					   enum amd_clockgating_state state);
235b843c749SSergey Zigachev int amdgpu_device_ip_set_powergating_state(void *dev,
236b843c749SSergey Zigachev 					   enum amd_ip_block_type block_type,
237b843c749SSergey Zigachev 					   enum amd_powergating_state state);
238b843c749SSergey Zigachev void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
239b843c749SSergey Zigachev 					    u32 *flags);
240b843c749SSergey Zigachev int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
241b843c749SSergey Zigachev 				   enum amd_ip_block_type block_type);
242b843c749SSergey Zigachev bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
243b843c749SSergey Zigachev 			      enum amd_ip_block_type block_type);
244b843c749SSergey Zigachev 
245b843c749SSergey Zigachev #define AMDGPU_MAX_IP_NUM 16
246b843c749SSergey Zigachev 
247b843c749SSergey Zigachev struct amdgpu_ip_block_status {
248b843c749SSergey Zigachev 	bool valid;
249b843c749SSergey Zigachev 	bool sw;
250b843c749SSergey Zigachev 	bool hw;
251b843c749SSergey Zigachev 	bool late_initialized;
252b843c749SSergey Zigachev 	bool hang;
253b843c749SSergey Zigachev };
254b843c749SSergey Zigachev 
255b843c749SSergey Zigachev struct amdgpu_ip_block_version {
256b843c749SSergey Zigachev 	const enum amd_ip_block_type type;
257b843c749SSergey Zigachev 	const u32 major;
258b843c749SSergey Zigachev 	const u32 minor;
259b843c749SSergey Zigachev 	const u32 rev;
260b843c749SSergey Zigachev 	const struct amd_ip_funcs *funcs;
261b843c749SSergey Zigachev };
262b843c749SSergey Zigachev 
263b843c749SSergey Zigachev struct amdgpu_ip_block {
264b843c749SSergey Zigachev 	struct amdgpu_ip_block_status status;
265b843c749SSergey Zigachev 	const struct amdgpu_ip_block_version *version;
266b843c749SSergey Zigachev };
267b843c749SSergey Zigachev 
268b843c749SSergey Zigachev int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
269b843c749SSergey Zigachev 				       enum amd_ip_block_type type,
270b843c749SSergey Zigachev 				       u32 major, u32 minor);
271b843c749SSergey Zigachev 
272b843c749SSergey Zigachev struct amdgpu_ip_block *
273b843c749SSergey Zigachev amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
274b843c749SSergey Zigachev 			      enum amd_ip_block_type type);
275b843c749SSergey Zigachev 
276b843c749SSergey Zigachev int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
277b843c749SSergey Zigachev 			       const struct amdgpu_ip_block_version *ip_block_version);
278b843c749SSergey Zigachev 
279b843c749SSergey Zigachev /* provided by hw blocks that can move/clear data.  e.g., gfx or sdma */
280b843c749SSergey Zigachev struct amdgpu_buffer_funcs {
281b843c749SSergey Zigachev 	/* maximum bytes in a single operation */
282b843c749SSergey Zigachev 	uint32_t	copy_max_bytes;
283b843c749SSergey Zigachev 
284b843c749SSergey Zigachev 	/* number of dw to reserve per operation */
285b843c749SSergey Zigachev 	unsigned	copy_num_dw;
286b843c749SSergey Zigachev 
287b843c749SSergey Zigachev 	/* used for buffer migration */
288b843c749SSergey Zigachev 	void (*emit_copy_buffer)(struct amdgpu_ib *ib,
289b843c749SSergey Zigachev 				 /* src addr in bytes */
290b843c749SSergey Zigachev 				 uint64_t src_offset,
291b843c749SSergey Zigachev 				 /* dst addr in bytes */
292b843c749SSergey Zigachev 				 uint64_t dst_offset,
293b843c749SSergey Zigachev 				 /* number of byte to transfer */
294b843c749SSergey Zigachev 				 uint32_t byte_count);
295b843c749SSergey Zigachev 
296b843c749SSergey Zigachev 	/* maximum bytes in a single operation */
297b843c749SSergey Zigachev 	uint32_t	fill_max_bytes;
298b843c749SSergey Zigachev 
299b843c749SSergey Zigachev 	/* number of dw to reserve per operation */
300b843c749SSergey Zigachev 	unsigned	fill_num_dw;
301b843c749SSergey Zigachev 
302b843c749SSergey Zigachev 	/* used for buffer clearing */
303b843c749SSergey Zigachev 	void (*emit_fill_buffer)(struct amdgpu_ib *ib,
304b843c749SSergey Zigachev 				 /* value to write to memory */
305b843c749SSergey Zigachev 				 uint32_t src_data,
306b843c749SSergey Zigachev 				 /* dst addr in bytes */
307b843c749SSergey Zigachev 				 uint64_t dst_offset,
308b843c749SSergey Zigachev 				 /* number of byte to fill */
309b843c749SSergey Zigachev 				 uint32_t byte_count);
310b843c749SSergey Zigachev };
311b843c749SSergey Zigachev 
312b843c749SSergey Zigachev /* provided by hw blocks that can write ptes, e.g., sdma */
313b843c749SSergey Zigachev struct amdgpu_vm_pte_funcs {
314b843c749SSergey Zigachev 	/* number of dw to reserve per operation */
315b843c749SSergey Zigachev 	unsigned	copy_pte_num_dw;
316b843c749SSergey Zigachev 
317b843c749SSergey Zigachev 	/* copy pte entries from GART */
318b843c749SSergey Zigachev 	void (*copy_pte)(struct amdgpu_ib *ib,
319b843c749SSergey Zigachev 			 uint64_t pe, uint64_t src,
320b843c749SSergey Zigachev 			 unsigned count);
321b843c749SSergey Zigachev 
322b843c749SSergey Zigachev 	/* write pte one entry at a time with addr mapping */
323b843c749SSergey Zigachev 	void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
324b843c749SSergey Zigachev 			  uint64_t value, unsigned count,
325b843c749SSergey Zigachev 			  uint32_t incr);
326b843c749SSergey Zigachev 	/* for linear pte/pde updates without addr mapping */
327b843c749SSergey Zigachev 	void (*set_pte_pde)(struct amdgpu_ib *ib,
328b843c749SSergey Zigachev 			    uint64_t pe,
329b843c749SSergey Zigachev 			    uint64_t addr, unsigned count,
330b843c749SSergey Zigachev 			    uint32_t incr, uint64_t flags);
331b843c749SSergey Zigachev };
332b843c749SSergey Zigachev 
333b843c749SSergey Zigachev /* provided by the ih block */
334b843c749SSergey Zigachev struct amdgpu_ih_funcs {
335b843c749SSergey Zigachev 	/* ring read/write ptr handling, called from interrupt context */
336b843c749SSergey Zigachev 	u32 (*get_wptr)(struct amdgpu_device *adev);
337b843c749SSergey Zigachev 	bool (*prescreen_iv)(struct amdgpu_device *adev);
338b843c749SSergey Zigachev 	void (*decode_iv)(struct amdgpu_device *adev,
339b843c749SSergey Zigachev 			  struct amdgpu_iv_entry *entry);
340b843c749SSergey Zigachev 	void (*set_rptr)(struct amdgpu_device *adev);
341b843c749SSergey Zigachev };
342b843c749SSergey Zigachev 
343b843c749SSergey Zigachev /*
344b843c749SSergey Zigachev  * BIOS.
345b843c749SSergey Zigachev  */
346b843c749SSergey Zigachev bool amdgpu_get_bios(struct amdgpu_device *adev);
347b843c749SSergey Zigachev bool amdgpu_read_bios(struct amdgpu_device *adev);
348b843c749SSergey Zigachev 
349b843c749SSergey Zigachev /*
350b843c749SSergey Zigachev  * Clocks
351b843c749SSergey Zigachev  */
352b843c749SSergey Zigachev 
353b843c749SSergey Zigachev #define AMDGPU_MAX_PPLL 3
354b843c749SSergey Zigachev 
355b843c749SSergey Zigachev struct amdgpu_clock {
356b843c749SSergey Zigachev 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
357b843c749SSergey Zigachev 	struct amdgpu_pll spll;
358b843c749SSergey Zigachev 	struct amdgpu_pll mpll;
359b843c749SSergey Zigachev 	/* 10 Khz units */
360b843c749SSergey Zigachev 	uint32_t default_mclk;
361b843c749SSergey Zigachev 	uint32_t default_sclk;
362b843c749SSergey Zigachev 	uint32_t default_dispclk;
363b843c749SSergey Zigachev 	uint32_t current_dispclk;
364b843c749SSergey Zigachev 	uint32_t dp_extclk;
365b843c749SSergey Zigachev 	uint32_t max_pixel_clock;
366b843c749SSergey Zigachev };
367b843c749SSergey Zigachev 
368b843c749SSergey Zigachev /*
369b843c749SSergey Zigachev  * GEM.
370b843c749SSergey Zigachev  */
371b843c749SSergey Zigachev 
372b843c749SSergey Zigachev #define AMDGPU_GEM_DOMAIN_MAX		0x3
373b843c749SSergey Zigachev #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
374b843c749SSergey Zigachev 
375b843c749SSergey Zigachev void amdgpu_gem_object_free(struct drm_gem_object *obj);
376b843c749SSergey Zigachev int amdgpu_gem_object_open(struct drm_gem_object *obj,
377b843c749SSergey Zigachev 				struct drm_file *file_priv);
378b843c749SSergey Zigachev void amdgpu_gem_object_close(struct drm_gem_object *obj,
379b843c749SSergey Zigachev 				struct drm_file *file_priv);
380b843c749SSergey Zigachev unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
381b843c749SSergey Zigachev struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
382b843c749SSergey Zigachev struct drm_gem_object *
383b843c749SSergey Zigachev amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
384b843c749SSergey Zigachev 				 struct dma_buf_attachment *attach,
385b843c749SSergey Zigachev 				 struct sg_table *sg);
386b843c749SSergey Zigachev struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
387b843c749SSergey Zigachev 					struct drm_gem_object *gobj,
388b843c749SSergey Zigachev 					int flags);
389b843c749SSergey Zigachev struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
390b843c749SSergey Zigachev 					    struct dma_buf *dma_buf);
391b843c749SSergey Zigachev struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
392b843c749SSergey Zigachev void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
393b843c749SSergey Zigachev void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
394b843c749SSergey Zigachev int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
395b843c749SSergey Zigachev 
396b843c749SSergey Zigachev /* sub-allocation manager, it has to be protected by another lock.
397b843c749SSergey Zigachev  * By conception this is an helper for other part of the driver
398b843c749SSergey Zigachev  * like the indirect buffer or semaphore, which both have their
399b843c749SSergey Zigachev  * locking.
400b843c749SSergey Zigachev  *
401b843c749SSergey Zigachev  * Principe is simple, we keep a list of sub allocation in offset
402b843c749SSergey Zigachev  * order (first entry has offset == 0, last entry has the highest
403b843c749SSergey Zigachev  * offset).
404b843c749SSergey Zigachev  *
405b843c749SSergey Zigachev  * When allocating new object we first check if there is room at
406b843c749SSergey Zigachev  * the end total_size - (last_object_offset + last_object_size) >=
407b843c749SSergey Zigachev  * alloc_size. If so we allocate new object there.
408b843c749SSergey Zigachev  *
409b843c749SSergey Zigachev  * When there is not enough room at the end, we start waiting for
410b843c749SSergey Zigachev  * each sub object until we reach object_offset+object_size >=
411b843c749SSergey Zigachev  * alloc_size, this object then become the sub object we return.
412b843c749SSergey Zigachev  *
413b843c749SSergey Zigachev  * Alignment can't be bigger than page size.
414b843c749SSergey Zigachev  *
415b843c749SSergey Zigachev  * Hole are not considered for allocation to keep things simple.
416b843c749SSergey Zigachev  * Assumption is that there won't be hole (all object on same
417b843c749SSergey Zigachev  * alignment).
418b843c749SSergey Zigachev  */
419b843c749SSergey Zigachev 
420b843c749SSergey Zigachev #define AMDGPU_SA_NUM_FENCE_LISTS	32
421b843c749SSergey Zigachev 
422b843c749SSergey Zigachev struct amdgpu_sa_manager {
423b843c749SSergey Zigachev 	wait_queue_head_t	wq;
424b843c749SSergey Zigachev 	struct amdgpu_bo	*bo;
425b843c749SSergey Zigachev 	struct list_head	*hole;
426b843c749SSergey Zigachev 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
427b843c749SSergey Zigachev 	struct list_head	olist;
428b843c749SSergey Zigachev 	unsigned		size;
429b843c749SSergey Zigachev 	uint64_t		gpu_addr;
430b843c749SSergey Zigachev 	void			*cpu_ptr;
431b843c749SSergey Zigachev 	uint32_t		domain;
432b843c749SSergey Zigachev 	uint32_t		align;
433b843c749SSergey Zigachev };
434b843c749SSergey Zigachev 
435b843c749SSergey Zigachev /* sub-allocation buffer */
436b843c749SSergey Zigachev struct amdgpu_sa_bo {
437b843c749SSergey Zigachev 	struct list_head		olist;
438b843c749SSergey Zigachev 	struct list_head		flist;
439b843c749SSergey Zigachev 	struct amdgpu_sa_manager	*manager;
440b843c749SSergey Zigachev 	unsigned			soffset;
441b843c749SSergey Zigachev 	unsigned			eoffset;
442b843c749SSergey Zigachev 	struct dma_fence	        *fence;
443b843c749SSergey Zigachev };
444b843c749SSergey Zigachev 
445b843c749SSergey Zigachev /*
446b843c749SSergey Zigachev  * GEM objects.
447b843c749SSergey Zigachev  */
448b843c749SSergey Zigachev void amdgpu_gem_force_release(struct amdgpu_device *adev);
449b843c749SSergey Zigachev int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
450b843c749SSergey Zigachev 			     int alignment, u32 initial_domain,
451b843c749SSergey Zigachev 			     u64 flags, enum ttm_bo_type type,
452b843c749SSergey Zigachev 			     struct reservation_object *resv,
453b843c749SSergey Zigachev 			     struct drm_gem_object **obj);
454b843c749SSergey Zigachev 
455b843c749SSergey Zigachev int amdgpu_mode_dumb_create(struct drm_file *file_priv,
456b843c749SSergey Zigachev 			    struct drm_device *dev,
457b843c749SSergey Zigachev 			    struct drm_mode_create_dumb *args);
458b843c749SSergey Zigachev int amdgpu_mode_dumb_mmap(struct drm_file *filp,
459b843c749SSergey Zigachev 			  struct drm_device *dev,
460b843c749SSergey Zigachev 			  uint32_t handle, uint64_t *offset_p);
461b843c749SSergey Zigachev int amdgpu_fence_slab_init(void);
462b843c749SSergey Zigachev void amdgpu_fence_slab_fini(void);
463b843c749SSergey Zigachev 
464b843c749SSergey Zigachev /*
465b843c749SSergey Zigachev  * GPU doorbell structures, functions & helpers
466b843c749SSergey Zigachev  */
467b843c749SSergey Zigachev typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
468b843c749SSergey Zigachev {
469b843c749SSergey Zigachev 	AMDGPU_DOORBELL_KIQ                     = 0x000,
470b843c749SSergey Zigachev 	AMDGPU_DOORBELL_HIQ                     = 0x001,
471b843c749SSergey Zigachev 	AMDGPU_DOORBELL_DIQ                     = 0x002,
472b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING0               = 0x010,
473b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING1               = 0x011,
474b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING2               = 0x012,
475b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING3               = 0x013,
476b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING4               = 0x014,
477b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING5               = 0x015,
478b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING6               = 0x016,
479b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MEC_RING7               = 0x017,
480b843c749SSergey Zigachev 	AMDGPU_DOORBELL_GFX_RING0               = 0x020,
481b843c749SSergey Zigachev 	AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
482b843c749SSergey Zigachev 	AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
483b843c749SSergey Zigachev 	AMDGPU_DOORBELL_IH                      = 0x1E8,
484b843c749SSergey Zigachev 	AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
485b843c749SSergey Zigachev 	AMDGPU_DOORBELL_INVALID                 = 0xFFFF
486b843c749SSergey Zigachev } AMDGPU_DOORBELL_ASSIGNMENT;
487b843c749SSergey Zigachev 
488b843c749SSergey Zigachev struct amdgpu_doorbell {
489b843c749SSergey Zigachev 	/* doorbell mmio */
490b843c749SSergey Zigachev 	resource_size_t		base;
491b843c749SSergey Zigachev 	resource_size_t		size;
492b843c749SSergey Zigachev 	u32 __iomem		*ptr;
493b843c749SSergey Zigachev 	u32			num_doorbells;	/* Number of doorbells actually reserved for amdgpu. */
494b843c749SSergey Zigachev };
495b843c749SSergey Zigachev 
496b843c749SSergey Zigachev /*
497b843c749SSergey Zigachev  * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
498b843c749SSergey Zigachev  */
499b843c749SSergey Zigachev typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
500b843c749SSergey Zigachev {
501b843c749SSergey Zigachev 	/*
502b843c749SSergey Zigachev 	 * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
503b843c749SSergey Zigachev 	 * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
504b843c749SSergey Zigachev 	 *  Compute related doorbells are allocated from 0x00 to 0x8a
505b843c749SSergey Zigachev 	 */
506b843c749SSergey Zigachev 
507b843c749SSergey Zigachev 
508b843c749SSergey Zigachev 	/* kernel scheduling */
509b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_KIQ                     = 0x00,
510b843c749SSergey Zigachev 
511b843c749SSergey Zigachev 	/* HSA interface queue and debug queue */
512b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_HIQ                     = 0x01,
513b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_DIQ                     = 0x02,
514b843c749SSergey Zigachev 
515b843c749SSergey Zigachev 	/* Compute engines */
516b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING0               = 0x03,
517b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING1               = 0x04,
518b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING2               = 0x05,
519b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING3               = 0x06,
520b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING4               = 0x07,
521b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING5               = 0x08,
522b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING6               = 0x09,
523b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MEC_RING7               = 0x0a,
524b843c749SSergey Zigachev 
525b843c749SSergey Zigachev 	/* User queue doorbell range (128 doorbells) */
526b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_USERQUEUE_START         = 0x0b,
527b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_USERQUEUE_END           = 0x8a,
528b843c749SSergey Zigachev 
529b843c749SSergey Zigachev 	/* Graphics engine */
530b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_GFX_RING0               = 0x8b,
531b843c749SSergey Zigachev 
532b843c749SSergey Zigachev 	/*
533b843c749SSergey Zigachev 	 * Other graphics doorbells can be allocated here: from 0x8c to 0xef
534b843c749SSergey Zigachev 	 * Graphics voltage island aperture 1
535b843c749SSergey Zigachev 	 * default non-graphics QWORD index is 0xF0 - 0xFF inclusive
536b843c749SSergey Zigachev 	 */
537b843c749SSergey Zigachev 
538b843c749SSergey Zigachev 	/* sDMA engines */
539b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_sDMA_ENGINE0            = 0xF0,
540b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0     = 0xF1,
541b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_sDMA_ENGINE1            = 0xF2,
542b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1     = 0xF3,
543b843c749SSergey Zigachev 
544b843c749SSergey Zigachev 	/* Interrupt handler */
545b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_IH                      = 0xF4,  /* For legacy interrupt ring buffer */
546b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_IH_RING1                = 0xF5,  /* For page migration request log */
547b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_IH_RING2                = 0xF6,  /* For page migration translation/invalidation log */
548b843c749SSergey Zigachev 
549b843c749SSergey Zigachev 	/* VCN engine use 32 bits doorbell  */
550b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCN0_1                  = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
551b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCN2_3                  = 0xF9,
552b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCN4_5                  = 0xFA,
553b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCN6_7                  = 0xFB,
554b843c749SSergey Zigachev 
555b843c749SSergey Zigachev 	/* overlap the doorbell assignment with VCN as they are  mutually exclusive
556b843c749SSergey Zigachev 	 * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
557b843c749SSergey Zigachev 	 */
558b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_UVD_RING0_1             = 0xF8,
559b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_UVD_RING2_3             = 0xF9,
560b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_UVD_RING4_5             = 0xFA,
561b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_UVD_RING6_7             = 0xFB,
562b843c749SSergey Zigachev 
563b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCE_RING0_1             = 0xFC,
564b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCE_RING2_3             = 0xFD,
565b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCE_RING4_5             = 0xFE,
566b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_VCE_RING6_7             = 0xFF,
567b843c749SSergey Zigachev 
568b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
569b843c749SSergey Zigachev 	AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
570b843c749SSergey Zigachev } AMDGPU_DOORBELL64_ASSIGNMENT;
571b843c749SSergey Zigachev 
572b843c749SSergey Zigachev /*
573b843c749SSergey Zigachev  * IRQS.
574b843c749SSergey Zigachev  */
575b843c749SSergey Zigachev 
576b843c749SSergey Zigachev struct amdgpu_flip_work {
577b843c749SSergey Zigachev 	struct delayed_work		flip_work;
578b843c749SSergey Zigachev 	struct work_struct		unpin_work;
579b843c749SSergey Zigachev 	struct amdgpu_device		*adev;
580b843c749SSergey Zigachev 	int				crtc_id;
581b843c749SSergey Zigachev 	u32				target_vblank;
582b843c749SSergey Zigachev 	uint64_t			base;
583b843c749SSergey Zigachev 	struct drm_pending_vblank_event *event;
584b843c749SSergey Zigachev 	struct amdgpu_bo		*old_abo;
585b843c749SSergey Zigachev 	struct dma_fence		*excl;
586b843c749SSergey Zigachev 	unsigned			shared_count;
587b843c749SSergey Zigachev 	struct dma_fence		**shared;
588b843c749SSergey Zigachev 	struct dma_fence_cb		cb;
589b843c749SSergey Zigachev 	bool				async;
590b843c749SSergey Zigachev };
591b843c749SSergey Zigachev 
592b843c749SSergey Zigachev 
593b843c749SSergey Zigachev /*
594b843c749SSergey Zigachev  * CP & rings.
595b843c749SSergey Zigachev  */
596b843c749SSergey Zigachev 
597b843c749SSergey Zigachev struct amdgpu_ib {
598b843c749SSergey Zigachev 	struct amdgpu_sa_bo		*sa_bo;
599b843c749SSergey Zigachev 	uint32_t			length_dw;
600b843c749SSergey Zigachev 	uint64_t			gpu_addr;
601b843c749SSergey Zigachev 	uint32_t			*ptr;
602b843c749SSergey Zigachev 	uint32_t			flags;
603b843c749SSergey Zigachev };
604b843c749SSergey Zigachev 
605b843c749SSergey Zigachev extern const struct drm_sched_backend_ops amdgpu_sched_ops;
606b843c749SSergey Zigachev 
607b843c749SSergey Zigachev /*
608b843c749SSergey Zigachev  * Queue manager
609b843c749SSergey Zigachev  */
610b843c749SSergey Zigachev struct amdgpu_queue_mapper {
611b843c749SSergey Zigachev 	int 		hw_ip;
612*78973132SSergey Zigachev 	struct lock	lock;
613b843c749SSergey Zigachev 	/* protected by lock */
614b843c749SSergey Zigachev 	struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
615b843c749SSergey Zigachev };
616b843c749SSergey Zigachev 
617b843c749SSergey Zigachev struct amdgpu_queue_mgr {
618b843c749SSergey Zigachev 	struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
619b843c749SSergey Zigachev };
620b843c749SSergey Zigachev 
621b843c749SSergey Zigachev int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
622b843c749SSergey Zigachev 			  struct amdgpu_queue_mgr *mgr);
623b843c749SSergey Zigachev int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
624b843c749SSergey Zigachev 			  struct amdgpu_queue_mgr *mgr);
625b843c749SSergey Zigachev int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
626b843c749SSergey Zigachev 			 struct amdgpu_queue_mgr *mgr,
627b843c749SSergey Zigachev 			 u32 hw_ip, u32 instance, u32 ring,
628b843c749SSergey Zigachev 			 struct amdgpu_ring **out_ring);
629b843c749SSergey Zigachev 
630b843c749SSergey Zigachev /*
631b843c749SSergey Zigachev  * context related structures
632b843c749SSergey Zigachev  */
633b843c749SSergey Zigachev 
634b843c749SSergey Zigachev struct amdgpu_ctx_ring {
635b843c749SSergey Zigachev 	uint64_t		sequence;
636b843c749SSergey Zigachev 	struct dma_fence	**fences;
637b843c749SSergey Zigachev 	struct drm_sched_entity	entity;
638b843c749SSergey Zigachev };
639b843c749SSergey Zigachev 
640b843c749SSergey Zigachev struct amdgpu_ctx {
641b843c749SSergey Zigachev 	struct kref		refcount;
642b843c749SSergey Zigachev 	struct amdgpu_device    *adev;
643b843c749SSergey Zigachev 	struct amdgpu_queue_mgr queue_mgr;
644b843c749SSergey Zigachev 	unsigned		reset_counter;
645b843c749SSergey Zigachev 	unsigned        reset_counter_query;
646b843c749SSergey Zigachev 	uint32_t		vram_lost_counter;
647*78973132SSergey Zigachev 	struct spinlock		ring_lock;
648b843c749SSergey Zigachev 	struct dma_fence	**fences;
649b843c749SSergey Zigachev 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
650b843c749SSergey Zigachev 	bool			preamble_presented;
651b843c749SSergey Zigachev 	enum drm_sched_priority init_priority;
652b843c749SSergey Zigachev 	enum drm_sched_priority override_priority;
653*78973132SSergey Zigachev 	struct lock            lock;
654b843c749SSergey Zigachev 	atomic_t	guilty;
655b843c749SSergey Zigachev };
656b843c749SSergey Zigachev 
657b843c749SSergey Zigachev struct amdgpu_ctx_mgr {
658b843c749SSergey Zigachev 	struct amdgpu_device	*adev;
659*78973132SSergey Zigachev 	struct lock		lock;
660b843c749SSergey Zigachev 	/* protected by lock */
661b843c749SSergey Zigachev 	struct idr		ctx_handles;
662b843c749SSergey Zigachev };
663b843c749SSergey Zigachev 
664b843c749SSergey Zigachev struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
665b843c749SSergey Zigachev int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
666b843c749SSergey Zigachev 
667b843c749SSergey Zigachev int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
668b843c749SSergey Zigachev 			      struct dma_fence *fence, uint64_t *seq);
669b843c749SSergey Zigachev struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
670b843c749SSergey Zigachev 				   struct amdgpu_ring *ring, uint64_t seq);
671b843c749SSergey Zigachev void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
672b843c749SSergey Zigachev 				  enum drm_sched_priority priority);
673b843c749SSergey Zigachev 
674b843c749SSergey Zigachev int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
675b843c749SSergey Zigachev 		     struct drm_file *filp);
676b843c749SSergey Zigachev 
677b843c749SSergey Zigachev int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id);
678b843c749SSergey Zigachev 
679b843c749SSergey Zigachev void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
680b843c749SSergey Zigachev void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);
681b843c749SSergey Zigachev void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr);
682b843c749SSergey Zigachev void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
683b843c749SSergey Zigachev 
684b843c749SSergey Zigachev 
685b843c749SSergey Zigachev /*
686b843c749SSergey Zigachev  * file private structure
687b843c749SSergey Zigachev  */
688b843c749SSergey Zigachev 
689b843c749SSergey Zigachev struct amdgpu_fpriv {
690b843c749SSergey Zigachev 	struct amdgpu_vm	vm;
691b843c749SSergey Zigachev 	struct amdgpu_bo_va	*prt_va;
692b843c749SSergey Zigachev 	struct amdgpu_bo_va	*csa_va;
693*78973132SSergey Zigachev 	struct lock		bo_list_lock;
694b843c749SSergey Zigachev 	struct idr		bo_list_handles;
695b843c749SSergey Zigachev 	struct amdgpu_ctx_mgr	ctx_mgr;
696b843c749SSergey Zigachev };
697b843c749SSergey Zigachev 
698b843c749SSergey Zigachev /*
699b843c749SSergey Zigachev  * GFX stuff
700b843c749SSergey Zigachev  */
701b843c749SSergey Zigachev #include "clearstate_defs.h"
702b843c749SSergey Zigachev 
703b843c749SSergey Zigachev struct amdgpu_rlc_funcs {
704b843c749SSergey Zigachev 	void (*enter_safe_mode)(struct amdgpu_device *adev);
705b843c749SSergey Zigachev 	void (*exit_safe_mode)(struct amdgpu_device *adev);
706b843c749SSergey Zigachev };
707b843c749SSergey Zigachev 
708b843c749SSergey Zigachev struct amdgpu_rlc {
709b843c749SSergey Zigachev 	/* for power gating */
710b843c749SSergey Zigachev 	struct amdgpu_bo	*save_restore_obj;
711b843c749SSergey Zigachev 	uint64_t		save_restore_gpu_addr;
712b843c749SSergey Zigachev 	volatile uint32_t	*sr_ptr;
713b843c749SSergey Zigachev 	const u32               *reg_list;
714b843c749SSergey Zigachev 	u32                     reg_list_size;
715b843c749SSergey Zigachev 	/* for clear state */
716b843c749SSergey Zigachev 	struct amdgpu_bo	*clear_state_obj;
717b843c749SSergey Zigachev 	uint64_t		clear_state_gpu_addr;
718b843c749SSergey Zigachev 	volatile uint32_t	*cs_ptr;
719b843c749SSergey Zigachev 	const struct cs_section_def   *cs_data;
720b843c749SSergey Zigachev 	u32                     clear_state_size;
721b843c749SSergey Zigachev 	/* for cp tables */
722b843c749SSergey Zigachev 	struct amdgpu_bo	*cp_table_obj;
723b843c749SSergey Zigachev 	uint64_t		cp_table_gpu_addr;
724b843c749SSergey Zigachev 	volatile uint32_t	*cp_table_ptr;
725b843c749SSergey Zigachev 	u32                     cp_table_size;
726b843c749SSergey Zigachev 
727b843c749SSergey Zigachev 	/* safe mode for updating CG/PG state */
728b843c749SSergey Zigachev 	bool in_safe_mode;
729b843c749SSergey Zigachev 	const struct amdgpu_rlc_funcs *funcs;
730b843c749SSergey Zigachev 
731b843c749SSergey Zigachev 	/* for firmware data */
732b843c749SSergey Zigachev 	u32 save_and_restore_offset;
733b843c749SSergey Zigachev 	u32 clear_state_descriptor_offset;
734b843c749SSergey Zigachev 	u32 avail_scratch_ram_locations;
735b843c749SSergey Zigachev 	u32 reg_restore_list_size;
736b843c749SSergey Zigachev 	u32 reg_list_format_start;
737b843c749SSergey Zigachev 	u32 reg_list_format_separate_start;
738b843c749SSergey Zigachev 	u32 starting_offsets_start;
739b843c749SSergey Zigachev 	u32 reg_list_format_size_bytes;
740b843c749SSergey Zigachev 	u32 reg_list_size_bytes;
741b843c749SSergey Zigachev 	u32 reg_list_format_direct_reg_list_length;
742b843c749SSergey Zigachev 	u32 save_restore_list_cntl_size_bytes;
743b843c749SSergey Zigachev 	u32 save_restore_list_gpm_size_bytes;
744b843c749SSergey Zigachev 	u32 save_restore_list_srm_size_bytes;
745b843c749SSergey Zigachev 
746b843c749SSergey Zigachev 	u32 *register_list_format;
747b843c749SSergey Zigachev 	u32 *register_restore;
748b843c749SSergey Zigachev 	u8 *save_restore_list_cntl;
749b843c749SSergey Zigachev 	u8 *save_restore_list_gpm;
750b843c749SSergey Zigachev 	u8 *save_restore_list_srm;
751b843c749SSergey Zigachev 
752b843c749SSergey Zigachev 	bool is_rlc_v2_1;
753b843c749SSergey Zigachev };
754b843c749SSergey Zigachev 
755b843c749SSergey Zigachev #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
756b843c749SSergey Zigachev 
757b843c749SSergey Zigachev struct amdgpu_mec {
758b843c749SSergey Zigachev 	struct amdgpu_bo	*hpd_eop_obj;
759b843c749SSergey Zigachev 	u64			hpd_eop_gpu_addr;
760b843c749SSergey Zigachev 	struct amdgpu_bo	*mec_fw_obj;
761b843c749SSergey Zigachev 	u64			mec_fw_gpu_addr;
762b843c749SSergey Zigachev 	u32 num_mec;
763b843c749SSergey Zigachev 	u32 num_pipe_per_mec;
764b843c749SSergey Zigachev 	u32 num_queue_per_pipe;
765b843c749SSergey Zigachev 	void			*mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
766b843c749SSergey Zigachev 
767b843c749SSergey Zigachev 	/* These are the resources for which amdgpu takes ownership */
768b843c749SSergey Zigachev 	DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
769b843c749SSergey Zigachev };
770b843c749SSergey Zigachev 
771b843c749SSergey Zigachev struct amdgpu_kiq {
772b843c749SSergey Zigachev 	u64			eop_gpu_addr;
773b843c749SSergey Zigachev 	struct amdgpu_bo	*eop_obj;
774b843c749SSergey Zigachev 	spinlock_t              ring_lock;
775b843c749SSergey Zigachev 	struct amdgpu_ring	ring;
776b843c749SSergey Zigachev 	struct amdgpu_irq_src	irq;
777b843c749SSergey Zigachev };
778b843c749SSergey Zigachev 
779b843c749SSergey Zigachev /*
780b843c749SSergey Zigachev  * GPU scratch registers structures, functions & helpers
781b843c749SSergey Zigachev  */
782b843c749SSergey Zigachev struct amdgpu_scratch {
783b843c749SSergey Zigachev 	unsigned		num_reg;
784b843c749SSergey Zigachev 	uint32_t                reg_base;
785b843c749SSergey Zigachev 	uint32_t		free_mask;
786b843c749SSergey Zigachev };
787b843c749SSergey Zigachev 
788b843c749SSergey Zigachev /*
789b843c749SSergey Zigachev  * GFX configurations
790b843c749SSergey Zigachev  */
791b843c749SSergey Zigachev #define AMDGPU_GFX_MAX_SE 4
792b843c749SSergey Zigachev #define AMDGPU_GFX_MAX_SH_PER_SE 2
793b843c749SSergey Zigachev 
794b843c749SSergey Zigachev struct amdgpu_rb_config {
795b843c749SSergey Zigachev 	uint32_t rb_backend_disable;
796b843c749SSergey Zigachev 	uint32_t user_rb_backend_disable;
797b843c749SSergey Zigachev 	uint32_t raster_config;
798b843c749SSergey Zigachev 	uint32_t raster_config_1;
799b843c749SSergey Zigachev };
800b843c749SSergey Zigachev 
801b843c749SSergey Zigachev struct gb_addr_config {
802b843c749SSergey Zigachev 	uint16_t pipe_interleave_size;
803b843c749SSergey Zigachev 	uint8_t num_pipes;
804b843c749SSergey Zigachev 	uint8_t max_compress_frags;
805b843c749SSergey Zigachev 	uint8_t num_banks;
806b843c749SSergey Zigachev 	uint8_t num_se;
807b843c749SSergey Zigachev 	uint8_t num_rb_per_se;
808b843c749SSergey Zigachev };
809b843c749SSergey Zigachev 
810b843c749SSergey Zigachev struct amdgpu_gfx_config {
811b843c749SSergey Zigachev 	unsigned max_shader_engines;
812b843c749SSergey Zigachev 	unsigned max_tile_pipes;
813b843c749SSergey Zigachev 	unsigned max_cu_per_sh;
814b843c749SSergey Zigachev 	unsigned max_sh_per_se;
815b843c749SSergey Zigachev 	unsigned max_backends_per_se;
816b843c749SSergey Zigachev 	unsigned max_texture_channel_caches;
817b843c749SSergey Zigachev 	unsigned max_gprs;
818b843c749SSergey Zigachev 	unsigned max_gs_threads;
819b843c749SSergey Zigachev 	unsigned max_hw_contexts;
820b843c749SSergey Zigachev 	unsigned sc_prim_fifo_size_frontend;
821b843c749SSergey Zigachev 	unsigned sc_prim_fifo_size_backend;
822b843c749SSergey Zigachev 	unsigned sc_hiz_tile_fifo_size;
823b843c749SSergey Zigachev 	unsigned sc_earlyz_tile_fifo_size;
824b843c749SSergey Zigachev 
825b843c749SSergey Zigachev 	unsigned num_tile_pipes;
826b843c749SSergey Zigachev 	unsigned backend_enable_mask;
827b843c749SSergey Zigachev 	unsigned mem_max_burst_length_bytes;
828b843c749SSergey Zigachev 	unsigned mem_row_size_in_kb;
829b843c749SSergey Zigachev 	unsigned shader_engine_tile_size;
830b843c749SSergey Zigachev 	unsigned num_gpus;
831b843c749SSergey Zigachev 	unsigned multi_gpu_tile_size;
832b843c749SSergey Zigachev 	unsigned mc_arb_ramcfg;
833b843c749SSergey Zigachev 	unsigned gb_addr_config;
834b843c749SSergey Zigachev 	unsigned num_rbs;
835b843c749SSergey Zigachev 	unsigned gs_vgt_table_depth;
836b843c749SSergey Zigachev 	unsigned gs_prim_buffer_depth;
837b843c749SSergey Zigachev 
838b843c749SSergey Zigachev 	uint32_t tile_mode_array[32];
839b843c749SSergey Zigachev 	uint32_t macrotile_mode_array[16];
840b843c749SSergey Zigachev 
841b843c749SSergey Zigachev 	struct gb_addr_config gb_addr_config_fields;
842b843c749SSergey Zigachev 	struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
843b843c749SSergey Zigachev 
844b843c749SSergey Zigachev 	/* gfx configure feature */
845b843c749SSergey Zigachev 	uint32_t double_offchip_lds_buf;
846b843c749SSergey Zigachev 	/* cached value of DB_DEBUG2 */
847b843c749SSergey Zigachev 	uint32_t db_debug2;
848b843c749SSergey Zigachev };
849b843c749SSergey Zigachev 
850b843c749SSergey Zigachev struct amdgpu_cu_info {
851b843c749SSergey Zigachev 	uint32_t simd_per_cu;
852b843c749SSergey Zigachev 	uint32_t max_waves_per_simd;
853b843c749SSergey Zigachev 	uint32_t wave_front_size;
854b843c749SSergey Zigachev 	uint32_t max_scratch_slots_per_cu;
855b843c749SSergey Zigachev 	uint32_t lds_size;
856b843c749SSergey Zigachev 
857b843c749SSergey Zigachev 	/* total active CU number */
858b843c749SSergey Zigachev 	uint32_t number;
859b843c749SSergey Zigachev 	uint32_t ao_cu_mask;
860b843c749SSergey Zigachev 	uint32_t ao_cu_bitmap[4][4];
861b843c749SSergey Zigachev 	uint32_t bitmap[4][4];
862b843c749SSergey Zigachev };
863b843c749SSergey Zigachev 
864b843c749SSergey Zigachev struct amdgpu_gfx_funcs {
865b843c749SSergey Zigachev 	/* get the gpu clock counter */
866b843c749SSergey Zigachev 	uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
867b843c749SSergey Zigachev 	void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
868b843c749SSergey Zigachev 	void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);
869b843c749SSergey Zigachev 	void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t thread, uint32_t start, uint32_t size, uint32_t *dst);
870b843c749SSergey Zigachev 	void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst);
871b843c749SSergey Zigachev 	void (*select_me_pipe_q)(struct amdgpu_device *adev, u32 me, u32 pipe, u32 queue);
872b843c749SSergey Zigachev };
873b843c749SSergey Zigachev 
874b843c749SSergey Zigachev struct amdgpu_ngg_buf {
875b843c749SSergey Zigachev 	struct amdgpu_bo	*bo;
876b843c749SSergey Zigachev 	uint64_t		gpu_addr;
877b843c749SSergey Zigachev 	uint32_t		size;
878b843c749SSergey Zigachev 	uint32_t		bo_size;
879b843c749SSergey Zigachev };
880b843c749SSergey Zigachev 
881b843c749SSergey Zigachev enum {
882b843c749SSergey Zigachev 	NGG_PRIM = 0,
883b843c749SSergey Zigachev 	NGG_POS,
884b843c749SSergey Zigachev 	NGG_CNTL,
885b843c749SSergey Zigachev 	NGG_PARAM,
886b843c749SSergey Zigachev 	NGG_BUF_MAX
887b843c749SSergey Zigachev };
888b843c749SSergey Zigachev 
889b843c749SSergey Zigachev struct amdgpu_ngg {
890b843c749SSergey Zigachev 	struct amdgpu_ngg_buf	buf[NGG_BUF_MAX];
891b843c749SSergey Zigachev 	uint32_t		gds_reserve_addr;
892b843c749SSergey Zigachev 	uint32_t		gds_reserve_size;
893b843c749SSergey Zigachev 	bool			init;
894b843c749SSergey Zigachev };
895b843c749SSergey Zigachev 
896b843c749SSergey Zigachev struct sq_work {
897b843c749SSergey Zigachev 	struct work_struct	work;
898b843c749SSergey Zigachev 	unsigned ih_data;
899b843c749SSergey Zigachev };
900b843c749SSergey Zigachev 
901b843c749SSergey Zigachev struct amdgpu_gfx {
902*78973132SSergey Zigachev 	struct lock			gpu_clock_mutex;
903b843c749SSergey Zigachev 	struct amdgpu_gfx_config	config;
904b843c749SSergey Zigachev 	struct amdgpu_rlc		rlc;
905b843c749SSergey Zigachev 	struct amdgpu_mec		mec;
906b843c749SSergey Zigachev 	struct amdgpu_kiq		kiq;
907b843c749SSergey Zigachev 	struct amdgpu_scratch		scratch;
908b843c749SSergey Zigachev 	const struct firmware		*me_fw;	/* ME firmware */
909b843c749SSergey Zigachev 	uint32_t			me_fw_version;
910b843c749SSergey Zigachev 	const struct firmware		*pfp_fw; /* PFP firmware */
911b843c749SSergey Zigachev 	uint32_t			pfp_fw_version;
912b843c749SSergey Zigachev 	const struct firmware		*ce_fw;	/* CE firmware */
913b843c749SSergey Zigachev 	uint32_t			ce_fw_version;
914b843c749SSergey Zigachev 	const struct firmware		*rlc_fw; /* RLC firmware */
915b843c749SSergey Zigachev 	uint32_t			rlc_fw_version;
916b843c749SSergey Zigachev 	const struct firmware		*mec_fw; /* MEC firmware */
917b843c749SSergey Zigachev 	uint32_t			mec_fw_version;
918b843c749SSergey Zigachev 	const struct firmware		*mec2_fw; /* MEC2 firmware */
919b843c749SSergey Zigachev 	uint32_t			mec2_fw_version;
920b843c749SSergey Zigachev 	uint32_t			me_feature_version;
921b843c749SSergey Zigachev 	uint32_t			ce_feature_version;
922b843c749SSergey Zigachev 	uint32_t			pfp_feature_version;
923b843c749SSergey Zigachev 	uint32_t			rlc_feature_version;
924b843c749SSergey Zigachev 	uint32_t			rlc_srlc_fw_version;
925b843c749SSergey Zigachev 	uint32_t			rlc_srlc_feature_version;
926b843c749SSergey Zigachev 	uint32_t			rlc_srlg_fw_version;
927b843c749SSergey Zigachev 	uint32_t			rlc_srlg_feature_version;
928b843c749SSergey Zigachev 	uint32_t			rlc_srls_fw_version;
929b843c749SSergey Zigachev 	uint32_t			rlc_srls_feature_version;
930b843c749SSergey Zigachev 	uint32_t			mec_feature_version;
931b843c749SSergey Zigachev 	uint32_t			mec2_feature_version;
932b843c749SSergey Zigachev 	struct amdgpu_ring		gfx_ring[AMDGPU_MAX_GFX_RINGS];
933b843c749SSergey Zigachev 	unsigned			num_gfx_rings;
934b843c749SSergey Zigachev 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
935b843c749SSergey Zigachev 	unsigned			num_compute_rings;
936b843c749SSergey Zigachev 	struct amdgpu_irq_src		eop_irq;
937b843c749SSergey Zigachev 	struct amdgpu_irq_src		priv_reg_irq;
938b843c749SSergey Zigachev 	struct amdgpu_irq_src		priv_inst_irq;
939b843c749SSergey Zigachev 	struct amdgpu_irq_src		cp_ecc_error_irq;
940b843c749SSergey Zigachev 	struct amdgpu_irq_src		sq_irq;
941b843c749SSergey Zigachev 	struct sq_work			sq_work;
942b843c749SSergey Zigachev 
943b843c749SSergey Zigachev 	/* gfx status */
944b843c749SSergey Zigachev 	uint32_t			gfx_current_status;
945b843c749SSergey Zigachev 	/* ce ram size*/
946b843c749SSergey Zigachev 	unsigned			ce_ram_size;
947b843c749SSergey Zigachev 	struct amdgpu_cu_info		cu_info;
948b843c749SSergey Zigachev 	const struct amdgpu_gfx_funcs	*funcs;
949b843c749SSergey Zigachev 
950b843c749SSergey Zigachev 	/* reset mask */
951b843c749SSergey Zigachev 	uint32_t                        grbm_soft_reset;
952b843c749SSergey Zigachev 	uint32_t                        srbm_soft_reset;
953b843c749SSergey Zigachev 	/* s3/s4 mask */
954b843c749SSergey Zigachev 	bool                            in_suspend;
955b843c749SSergey Zigachev 	/* NGG */
956b843c749SSergey Zigachev 	struct amdgpu_ngg		ngg;
957b843c749SSergey Zigachev 
958b843c749SSergey Zigachev 	/* pipe reservation */
959*78973132SSergey Zigachev 	struct lock			pipe_reserve_mutex;
960b843c749SSergey Zigachev 	DECLARE_BITMAP			(pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
961b843c749SSergey Zigachev };
962b843c749SSergey Zigachev 
963b843c749SSergey Zigachev int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
964b843c749SSergey Zigachev 		  unsigned size, struct amdgpu_ib *ib);
965b843c749SSergey Zigachev void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
966b843c749SSergey Zigachev 		    struct dma_fence *f);
967b843c749SSergey Zigachev int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
968b843c749SSergey Zigachev 		       struct amdgpu_ib *ibs, struct amdgpu_job *job,
969b843c749SSergey Zigachev 		       struct dma_fence **f);
970b843c749SSergey Zigachev int amdgpu_ib_pool_init(struct amdgpu_device *adev);
971b843c749SSergey Zigachev void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
972b843c749SSergey Zigachev int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
973b843c749SSergey Zigachev 
974b843c749SSergey Zigachev /*
975b843c749SSergey Zigachev  * CS.
976b843c749SSergey Zigachev  */
977b843c749SSergey Zigachev struct amdgpu_cs_chunk {
978b843c749SSergey Zigachev 	uint32_t		chunk_id;
979b843c749SSergey Zigachev 	uint32_t		length_dw;
980b843c749SSergey Zigachev 	void			*kdata;
981b843c749SSergey Zigachev };
982b843c749SSergey Zigachev 
983b843c749SSergey Zigachev struct amdgpu_cs_parser {
984b843c749SSergey Zigachev 	struct amdgpu_device	*adev;
985b843c749SSergey Zigachev 	struct drm_file		*filp;
986b843c749SSergey Zigachev 	struct amdgpu_ctx	*ctx;
987b843c749SSergey Zigachev 
988b843c749SSergey Zigachev 	/* chunks */
989b843c749SSergey Zigachev 	unsigned		nchunks;
990b843c749SSergey Zigachev 	struct amdgpu_cs_chunk	*chunks;
991b843c749SSergey Zigachev 
992b843c749SSergey Zigachev 	/* scheduler job object */
993b843c749SSergey Zigachev 	struct amdgpu_job	*job;
994b843c749SSergey Zigachev 	struct amdgpu_ring	*ring;
995b843c749SSergey Zigachev 
996b843c749SSergey Zigachev 	/* buffer objects */
997b843c749SSergey Zigachev 	struct ww_acquire_ctx		ticket;
998b843c749SSergey Zigachev 	struct amdgpu_bo_list		*bo_list;
999b843c749SSergey Zigachev 	struct amdgpu_mn		*mn;
1000b843c749SSergey Zigachev 	struct amdgpu_bo_list_entry	vm_pd;
1001b843c749SSergey Zigachev 	struct list_head		validated;
1002b843c749SSergey Zigachev 	struct dma_fence		*fence;
1003b843c749SSergey Zigachev 	uint64_t			bytes_moved_threshold;
1004b843c749SSergey Zigachev 	uint64_t			bytes_moved_vis_threshold;
1005b843c749SSergey Zigachev 	uint64_t			bytes_moved;
1006b843c749SSergey Zigachev 	uint64_t			bytes_moved_vis;
1007b843c749SSergey Zigachev 	struct amdgpu_bo_list_entry	*evictable;
1008b843c749SSergey Zigachev 
1009b843c749SSergey Zigachev 	/* user fence */
1010b843c749SSergey Zigachev 	struct amdgpu_bo_list_entry	uf_entry;
1011b843c749SSergey Zigachev 
1012b843c749SSergey Zigachev 	unsigned num_post_dep_syncobjs;
1013b843c749SSergey Zigachev 	struct drm_syncobj **post_dep_syncobjs;
1014b843c749SSergey Zigachev };
1015b843c749SSergey Zigachev 
amdgpu_get_ib_value(struct amdgpu_cs_parser * p,uint32_t ib_idx,int idx)1016b843c749SSergey Zigachev static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1017b843c749SSergey Zigachev 				      uint32_t ib_idx, int idx)
1018b843c749SSergey Zigachev {
1019b843c749SSergey Zigachev 	return p->job->ibs[ib_idx].ptr[idx];
1020b843c749SSergey Zigachev }
1021b843c749SSergey Zigachev 
amdgpu_set_ib_value(struct amdgpu_cs_parser * p,uint32_t ib_idx,int idx,uint32_t value)1022b843c749SSergey Zigachev static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1023b843c749SSergey Zigachev 				       uint32_t ib_idx, int idx,
1024b843c749SSergey Zigachev 				       uint32_t value)
1025b843c749SSergey Zigachev {
1026b843c749SSergey Zigachev 	p->job->ibs[ib_idx].ptr[idx] = value;
1027b843c749SSergey Zigachev }
1028b843c749SSergey Zigachev 
1029b843c749SSergey Zigachev /*
1030b843c749SSergey Zigachev  * Writeback
1031b843c749SSergey Zigachev  */
1032b843c749SSergey Zigachev #define AMDGPU_MAX_WB 128	/* Reserve at most 128 WB slots for amdgpu-owned rings. */
1033b843c749SSergey Zigachev 
1034b843c749SSergey Zigachev struct amdgpu_wb {
1035b843c749SSergey Zigachev 	struct amdgpu_bo	*wb_obj;
1036b843c749SSergey Zigachev 	volatile uint32_t	*wb;
1037b843c749SSergey Zigachev 	uint64_t		gpu_addr;
1038b843c749SSergey Zigachev 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
1039b843c749SSergey Zigachev 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1040b843c749SSergey Zigachev };
1041b843c749SSergey Zigachev 
1042b843c749SSergey Zigachev int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
1043b843c749SSergey Zigachev void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
1044b843c749SSergey Zigachev 
1045b843c749SSergey Zigachev /*
1046b843c749SSergey Zigachev  * SDMA
1047b843c749SSergey Zigachev  */
1048b843c749SSergey Zigachev struct amdgpu_sdma_instance {
1049b843c749SSergey Zigachev 	/* SDMA firmware */
1050b843c749SSergey Zigachev 	const struct firmware	*fw;
1051b843c749SSergey Zigachev 	uint32_t		fw_version;
1052b843c749SSergey Zigachev 	uint32_t		feature_version;
1053b843c749SSergey Zigachev 
1054b843c749SSergey Zigachev 	struct amdgpu_ring	ring;
1055b843c749SSergey Zigachev 	bool			burst_nop;
1056b843c749SSergey Zigachev };
1057b843c749SSergey Zigachev 
1058b843c749SSergey Zigachev struct amdgpu_sdma {
1059b843c749SSergey Zigachev 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1060b843c749SSergey Zigachev #ifdef CONFIG_DRM_AMDGPU_SI
1061b843c749SSergey Zigachev 	//SI DMA has a difference trap irq number for the second engine
1062b843c749SSergey Zigachev 	struct amdgpu_irq_src	trap_irq_1;
1063b843c749SSergey Zigachev #endif
1064b843c749SSergey Zigachev 	struct amdgpu_irq_src	trap_irq;
1065b843c749SSergey Zigachev 	struct amdgpu_irq_src	illegal_inst_irq;
1066b843c749SSergey Zigachev 	int			num_instances;
1067b843c749SSergey Zigachev 	uint32_t                    srbm_soft_reset;
1068b843c749SSergey Zigachev };
1069b843c749SSergey Zigachev 
1070b843c749SSergey Zigachev /*
1071b843c749SSergey Zigachev  * Firmware
1072b843c749SSergey Zigachev  */
1073b843c749SSergey Zigachev enum amdgpu_firmware_load_type {
1074b843c749SSergey Zigachev 	AMDGPU_FW_LOAD_DIRECT = 0,
1075b843c749SSergey Zigachev 	AMDGPU_FW_LOAD_SMU,
1076b843c749SSergey Zigachev 	AMDGPU_FW_LOAD_PSP,
1077b843c749SSergey Zigachev };
1078b843c749SSergey Zigachev 
1079b843c749SSergey Zigachev struct amdgpu_firmware {
1080b843c749SSergey Zigachev 	struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1081b843c749SSergey Zigachev 	enum amdgpu_firmware_load_type load_type;
1082b843c749SSergey Zigachev 	struct amdgpu_bo *fw_buf;
1083b843c749SSergey Zigachev 	unsigned int fw_size;
1084b843c749SSergey Zigachev 	unsigned int max_ucodes;
1085b843c749SSergey Zigachev 	/* firmwares are loaded by psp instead of smu from vega10 */
1086b843c749SSergey Zigachev 	const struct amdgpu_psp_funcs *funcs;
1087b843c749SSergey Zigachev 	struct amdgpu_bo *rbuf;
1088*78973132SSergey Zigachev 	struct lock mutex;
1089b843c749SSergey Zigachev 
1090b843c749SSergey Zigachev 	/* gpu info firmware data pointer */
1091b843c749SSergey Zigachev 	const struct firmware *gpu_info_fw;
1092b843c749SSergey Zigachev 
1093b843c749SSergey Zigachev 	void *fw_buf_ptr;
1094b843c749SSergey Zigachev 	uint64_t fw_buf_mc;
1095b843c749SSergey Zigachev };
1096b843c749SSergey Zigachev 
1097b843c749SSergey Zigachev /*
1098b843c749SSergey Zigachev  * Benchmarking
1099b843c749SSergey Zigachev  */
1100b843c749SSergey Zigachev void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1101b843c749SSergey Zigachev 
1102b843c749SSergey Zigachev 
1103b843c749SSergey Zigachev /*
1104b843c749SSergey Zigachev  * Testing
1105b843c749SSergey Zigachev  */
1106b843c749SSergey Zigachev void amdgpu_test_moves(struct amdgpu_device *adev);
1107b843c749SSergey Zigachev 
1108b843c749SSergey Zigachev 
1109b843c749SSergey Zigachev /*
1110b843c749SSergey Zigachev  * amdgpu smumgr functions
1111b843c749SSergey Zigachev  */
1112b843c749SSergey Zigachev struct amdgpu_smumgr_funcs {
1113b843c749SSergey Zigachev 	int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1114b843c749SSergey Zigachev 	int (*request_smu_load_fw)(struct amdgpu_device *adev);
1115b843c749SSergey Zigachev 	int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1116b843c749SSergey Zigachev };
1117b843c749SSergey Zigachev 
1118b843c749SSergey Zigachev /*
1119b843c749SSergey Zigachev  * amdgpu smumgr
1120b843c749SSergey Zigachev  */
1121b843c749SSergey Zigachev struct amdgpu_smumgr {
1122b843c749SSergey Zigachev 	struct amdgpu_bo *toc_buf;
1123b843c749SSergey Zigachev 	struct amdgpu_bo *smu_buf;
1124b843c749SSergey Zigachev 	/* asic priv smu data */
1125b843c749SSergey Zigachev 	void *priv;
1126b843c749SSergey Zigachev 	spinlock_t smu_lock;
1127b843c749SSergey Zigachev 	/* smumgr functions */
1128b843c749SSergey Zigachev 	const struct amdgpu_smumgr_funcs *smumgr_funcs;
1129b843c749SSergey Zigachev 	/* ucode loading complete flag */
1130b843c749SSergey Zigachev 	uint32_t fw_flags;
1131b843c749SSergey Zigachev };
1132b843c749SSergey Zigachev 
1133b843c749SSergey Zigachev /*
1134b843c749SSergey Zigachev  * ASIC specific register table accessible by UMD
1135b843c749SSergey Zigachev  */
1136b843c749SSergey Zigachev struct amdgpu_allowed_register_entry {
1137b843c749SSergey Zigachev 	uint32_t reg_offset;
1138b843c749SSergey Zigachev 	bool grbm_indexed;
1139b843c749SSergey Zigachev };
1140b843c749SSergey Zigachev 
1141b843c749SSergey Zigachev /*
1142b843c749SSergey Zigachev  * ASIC specific functions.
1143b843c749SSergey Zigachev  */
1144b843c749SSergey Zigachev struct amdgpu_asic_funcs {
1145b843c749SSergey Zigachev 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
1146b843c749SSergey Zigachev 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1147b843c749SSergey Zigachev 				   u8 *bios, u32 length_bytes);
1148b843c749SSergey Zigachev 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1149b843c749SSergey Zigachev 			     u32 sh_num, u32 reg_offset, u32 *value);
1150b843c749SSergey Zigachev 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1151b843c749SSergey Zigachev 	int (*reset)(struct amdgpu_device *adev);
1152b843c749SSergey Zigachev 	/* get the reference clock */
1153b843c749SSergey Zigachev 	u32 (*get_xclk)(struct amdgpu_device *adev);
1154b843c749SSergey Zigachev 	/* MM block clocks */
1155b843c749SSergey Zigachev 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1156b843c749SSergey Zigachev 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1157b843c749SSergey Zigachev 	/* static power management */
1158b843c749SSergey Zigachev 	int (*get_pcie_lanes)(struct amdgpu_device *adev);
1159b843c749SSergey Zigachev 	void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
1160b843c749SSergey Zigachev 	/* get config memsize register */
1161b843c749SSergey Zigachev 	u32 (*get_config_memsize)(struct amdgpu_device *adev);
1162b843c749SSergey Zigachev 	/* flush hdp write queue */
1163b843c749SSergey Zigachev 	void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
1164b843c749SSergey Zigachev 	/* invalidate hdp read cache */
1165b843c749SSergey Zigachev 	void (*invalidate_hdp)(struct amdgpu_device *adev,
1166b843c749SSergey Zigachev 			       struct amdgpu_ring *ring);
1167b843c749SSergey Zigachev 	/* check if the asic needs a full reset of if soft reset will work */
1168b843c749SSergey Zigachev 	bool (*need_full_reset)(struct amdgpu_device *adev);
1169b843c749SSergey Zigachev };
1170b843c749SSergey Zigachev 
1171b843c749SSergey Zigachev /*
1172b843c749SSergey Zigachev  * IOCTL.
1173b843c749SSergey Zigachev  */
1174b843c749SSergey Zigachev int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1175b843c749SSergey Zigachev 			    struct drm_file *filp);
1176b843c749SSergey Zigachev int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1177b843c749SSergey Zigachev 				struct drm_file *filp);
1178b843c749SSergey Zigachev 
1179b843c749SSergey Zigachev int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1180b843c749SSergey Zigachev 			  struct drm_file *filp);
1181b843c749SSergey Zigachev int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1182b843c749SSergey Zigachev 			struct drm_file *filp);
1183b843c749SSergey Zigachev int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1184b843c749SSergey Zigachev 			  struct drm_file *filp);
1185b843c749SSergey Zigachev int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1186b843c749SSergey Zigachev 			      struct drm_file *filp);
1187b843c749SSergey Zigachev int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1188b843c749SSergey Zigachev 			  struct drm_file *filp);
1189b843c749SSergey Zigachev int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1190b843c749SSergey Zigachev 			struct drm_file *filp);
1191b843c749SSergey Zigachev int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1192b843c749SSergey Zigachev int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
1193b843c749SSergey Zigachev 				    struct drm_file *filp);
1194b843c749SSergey Zigachev int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1195b843c749SSergey Zigachev int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
1196b843c749SSergey Zigachev 				struct drm_file *filp);
1197b843c749SSergey Zigachev 
1198b843c749SSergey Zigachev int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1199b843c749SSergey Zigachev 				struct drm_file *filp);
1200b843c749SSergey Zigachev 
1201b843c749SSergey Zigachev /* VRAM scratch page for HDP bug, default vram page */
1202b843c749SSergey Zigachev struct amdgpu_vram_scratch {
1203b843c749SSergey Zigachev 	struct amdgpu_bo		*robj;
1204b843c749SSergey Zigachev 	volatile uint32_t		*ptr;
1205b843c749SSergey Zigachev 	u64				gpu_addr;
1206b843c749SSergey Zigachev };
1207b843c749SSergey Zigachev 
1208b843c749SSergey Zigachev /*
1209b843c749SSergey Zigachev  * ACPI
1210b843c749SSergey Zigachev  */
1211b843c749SSergey Zigachev struct amdgpu_atcs_functions {
1212b843c749SSergey Zigachev 	bool get_ext_state;
1213b843c749SSergey Zigachev 	bool pcie_perf_req;
1214b843c749SSergey Zigachev 	bool pcie_dev_rdy;
1215b843c749SSergey Zigachev 	bool pcie_bus_width;
1216b843c749SSergey Zigachev };
1217b843c749SSergey Zigachev 
1218b843c749SSergey Zigachev struct amdgpu_atcs {
1219b843c749SSergey Zigachev 	struct amdgpu_atcs_functions functions;
1220b843c749SSergey Zigachev };
1221b843c749SSergey Zigachev 
1222b843c749SSergey Zigachev /*
1223b843c749SSergey Zigachev  * Firmware VRAM reservation
1224b843c749SSergey Zigachev  */
1225b843c749SSergey Zigachev struct amdgpu_fw_vram_usage {
1226b843c749SSergey Zigachev 	u64 start_offset;
1227b843c749SSergey Zigachev 	u64 size;
1228b843c749SSergey Zigachev 	struct amdgpu_bo *reserved_bo;
1229b843c749SSergey Zigachev 	void *va;
1230b843c749SSergey Zigachev };
1231b843c749SSergey Zigachev 
1232b843c749SSergey Zigachev /*
1233b843c749SSergey Zigachev  * CGS
1234b843c749SSergey Zigachev  */
1235b843c749SSergey Zigachev struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1236b843c749SSergey Zigachev void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1237b843c749SSergey Zigachev 
1238b843c749SSergey Zigachev /*
1239b843c749SSergey Zigachev  * Core structure, functions and helpers.
1240b843c749SSergey Zigachev  */
1241b843c749SSergey Zigachev typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1242b843c749SSergey Zigachev typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1243b843c749SSergey Zigachev 
1244b843c749SSergey Zigachev typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1245b843c749SSergey Zigachev typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1246b843c749SSergey Zigachev 
1247b843c749SSergey Zigachev 
1248b843c749SSergey Zigachev /*
1249b843c749SSergey Zigachev  * amdgpu nbio functions
1250b843c749SSergey Zigachev  *
1251b843c749SSergey Zigachev  */
1252b843c749SSergey Zigachev struct nbio_hdp_flush_reg {
1253b843c749SSergey Zigachev 	u32 ref_and_mask_cp0;
1254b843c749SSergey Zigachev 	u32 ref_and_mask_cp1;
1255b843c749SSergey Zigachev 	u32 ref_and_mask_cp2;
1256b843c749SSergey Zigachev 	u32 ref_and_mask_cp3;
1257b843c749SSergey Zigachev 	u32 ref_and_mask_cp4;
1258b843c749SSergey Zigachev 	u32 ref_and_mask_cp5;
1259b843c749SSergey Zigachev 	u32 ref_and_mask_cp6;
1260b843c749SSergey Zigachev 	u32 ref_and_mask_cp7;
1261b843c749SSergey Zigachev 	u32 ref_and_mask_cp8;
1262b843c749SSergey Zigachev 	u32 ref_and_mask_cp9;
1263b843c749SSergey Zigachev 	u32 ref_and_mask_sdma0;
1264b843c749SSergey Zigachev 	u32 ref_and_mask_sdma1;
1265b843c749SSergey Zigachev };
1266b843c749SSergey Zigachev 
1267b843c749SSergey Zigachev struct amdgpu_nbio_funcs {
1268b843c749SSergey Zigachev 	const struct nbio_hdp_flush_reg *hdp_flush_reg;
1269b843c749SSergey Zigachev 	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
1270b843c749SSergey Zigachev 	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
1271b843c749SSergey Zigachev 	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
1272b843c749SSergey Zigachev 	u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
1273b843c749SSergey Zigachev 	u32 (*get_rev_id)(struct amdgpu_device *adev);
1274b843c749SSergey Zigachev 	void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
1275b843c749SSergey Zigachev 	void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
1276b843c749SSergey Zigachev 	u32 (*get_memsize)(struct amdgpu_device *adev);
1277b843c749SSergey Zigachev 	void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
1278b843c749SSergey Zigachev 				    bool use_doorbell, int doorbell_index);
1279b843c749SSergey Zigachev 	void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
1280b843c749SSergey Zigachev 					 bool enable);
1281b843c749SSergey Zigachev 	void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
1282b843c749SSergey Zigachev 						  bool enable);
1283b843c749SSergey Zigachev 	void (*ih_doorbell_range)(struct amdgpu_device *adev,
1284b843c749SSergey Zigachev 				  bool use_doorbell, int doorbell_index);
1285b843c749SSergey Zigachev 	void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
1286b843c749SSergey Zigachev 						 bool enable);
1287b843c749SSergey Zigachev 	void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
1288b843c749SSergey Zigachev 						bool enable);
1289b843c749SSergey Zigachev 	void (*get_clockgating_state)(struct amdgpu_device *adev,
1290b843c749SSergey Zigachev 				      u32 *flags);
1291b843c749SSergey Zigachev 	void (*ih_control)(struct amdgpu_device *adev);
1292b843c749SSergey Zigachev 	void (*init_registers)(struct amdgpu_device *adev);
1293b843c749SSergey Zigachev 	void (*detect_hw_virt)(struct amdgpu_device *adev);
1294b843c749SSergey Zigachev };
1295b843c749SSergey Zigachev 
1296b843c749SSergey Zigachev struct amdgpu_df_funcs {
1297b843c749SSergey Zigachev 	void (*init)(struct amdgpu_device *adev);
1298b843c749SSergey Zigachev 	void (*enable_broadcast_mode)(struct amdgpu_device *adev,
1299b843c749SSergey Zigachev 				      bool enable);
1300b843c749SSergey Zigachev 	u32 (*get_fb_channel_number)(struct amdgpu_device *adev);
1301b843c749SSergey Zigachev 	u32 (*get_hbm_channel_number)(struct amdgpu_device *adev);
1302b843c749SSergey Zigachev 	void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
1303b843c749SSergey Zigachev 						 bool enable);
1304b843c749SSergey Zigachev 	void (*get_clockgating_state)(struct amdgpu_device *adev,
1305b843c749SSergey Zigachev 				      u32 *flags);
1306b843c749SSergey Zigachev 	void (*enable_ecc_force_par_wr_rmw)(struct amdgpu_device *adev,
1307b843c749SSergey Zigachev 					    bool enable);
1308b843c749SSergey Zigachev };
1309b843c749SSergey Zigachev /* Define the HW IP blocks will be used in driver , add more if necessary */
1310b843c749SSergey Zigachev enum amd_hw_ip_block_type {
1311b843c749SSergey Zigachev 	GC_HWIP = 1,
1312b843c749SSergey Zigachev 	HDP_HWIP,
1313b843c749SSergey Zigachev 	SDMA0_HWIP,
1314b843c749SSergey Zigachev 	SDMA1_HWIP,
1315b843c749SSergey Zigachev 	MMHUB_HWIP,
1316b843c749SSergey Zigachev 	ATHUB_HWIP,
1317b843c749SSergey Zigachev 	NBIO_HWIP,
1318b843c749SSergey Zigachev 	MP0_HWIP,
1319b843c749SSergey Zigachev 	MP1_HWIP,
1320b843c749SSergey Zigachev 	UVD_HWIP,
1321b843c749SSergey Zigachev 	VCN_HWIP = UVD_HWIP,
1322b843c749SSergey Zigachev 	VCE_HWIP,
1323b843c749SSergey Zigachev 	DF_HWIP,
1324b843c749SSergey Zigachev 	DCE_HWIP,
1325b843c749SSergey Zigachev 	OSSSYS_HWIP,
1326b843c749SSergey Zigachev 	SMUIO_HWIP,
1327b843c749SSergey Zigachev 	PWR_HWIP,
1328b843c749SSergey Zigachev 	NBIF_HWIP,
1329b843c749SSergey Zigachev 	THM_HWIP,
1330b843c749SSergey Zigachev 	CLK_HWIP,
1331b843c749SSergey Zigachev 	MAX_HWIP
1332b843c749SSergey Zigachev };
1333b843c749SSergey Zigachev 
1334b843c749SSergey Zigachev #define HWIP_MAX_INSTANCE	6
1335b843c749SSergey Zigachev 
1336b843c749SSergey Zigachev struct amd_powerplay {
1337b843c749SSergey Zigachev 	void *pp_handle;
1338b843c749SSergey Zigachev 	const struct amd_pm_funcs *pp_funcs;
1339b843c749SSergey Zigachev 	uint32_t pp_feature;
1340b843c749SSergey Zigachev };
1341b843c749SSergey Zigachev 
1342b843c749SSergey Zigachev #define AMDGPU_RESET_MAGIC_NUM 64
1343b843c749SSergey Zigachev struct amdgpu_device {
1344b843c749SSergey Zigachev 	struct device			*dev;
1345b843c749SSergey Zigachev 	struct drm_device		*ddev;
1346b843c749SSergey Zigachev 	struct pci_dev			*pdev;
1347b843c749SSergey Zigachev 
1348b843c749SSergey Zigachev #ifdef CONFIG_DRM_AMD_ACP
1349b843c749SSergey Zigachev 	struct amdgpu_acp		acp;
1350b843c749SSergey Zigachev #endif
1351b843c749SSergey Zigachev 
1352b843c749SSergey Zigachev 	/* ASIC */
1353b843c749SSergey Zigachev 	enum amd_asic_type		asic_type;
1354b843c749SSergey Zigachev 	uint32_t			family;
1355b843c749SSergey Zigachev 	uint32_t			rev_id;
1356b843c749SSergey Zigachev 	uint32_t			external_rev_id;
1357b843c749SSergey Zigachev 	unsigned long			flags;
1358b843c749SSergey Zigachev 	int				usec_timeout;
1359b843c749SSergey Zigachev 	const struct amdgpu_asic_funcs	*asic_funcs;
1360b843c749SSergey Zigachev 	bool				shutdown;
1361b843c749SSergey Zigachev 	bool				need_dma32;
1362b843c749SSergey Zigachev 	bool				need_swiotlb;
1363b843c749SSergey Zigachev 	bool				accel_working;
1364b843c749SSergey Zigachev 	struct work_struct		reset_work;
1365b843c749SSergey Zigachev 	struct notifier_block		acpi_nb;
1366b843c749SSergey Zigachev 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
1367b843c749SSergey Zigachev 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1368b843c749SSergey Zigachev 	unsigned			debugfs_count;
1369b843c749SSergey Zigachev #if defined(CONFIG_DEBUG_FS)
1370b843c749SSergey Zigachev 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1371b843c749SSergey Zigachev #endif
1372b843c749SSergey Zigachev 	struct amdgpu_atif		*atif;
1373b843c749SSergey Zigachev 	struct amdgpu_atcs		atcs;
1374*78973132SSergey Zigachev 	struct lock			srbm_mutex;
1375b843c749SSergey Zigachev 	/* GRBM index mutex. Protects concurrent access to GRBM index */
1376*78973132SSergey Zigachev 	struct lock                    grbm_idx_mutex;
1377*78973132SSergey Zigachev #if 0
1378b843c749SSergey Zigachev 	struct dev_pm_domain		vga_pm_domain;
1379*78973132SSergey Zigachev #endif
1380b843c749SSergey Zigachev 	bool				have_disp_power_ref;
1381b843c749SSergey Zigachev 
1382b843c749SSergey Zigachev 	/* BIOS */
1383b843c749SSergey Zigachev 	bool				is_atom_fw;
1384b843c749SSergey Zigachev 	uint8_t				*bios;
1385b843c749SSergey Zigachev 	uint32_t			bios_size;
1386b843c749SSergey Zigachev 	struct amdgpu_bo		*stolen_vga_memory;
1387b843c749SSergey Zigachev 	uint32_t			bios_scratch_reg_offset;
1388b843c749SSergey Zigachev 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1389b843c749SSergey Zigachev 
1390b843c749SSergey Zigachev 	/* Register/doorbell mmio */
1391b843c749SSergey Zigachev 	resource_size_t			rmmio_base;
1392b843c749SSergey Zigachev 	resource_size_t			rmmio_size;
1393*78973132SSergey Zigachev #if 0
1394b843c749SSergey Zigachev 	void __iomem			*rmmio;
1395*78973132SSergey Zigachev #endif
1396*78973132SSergey Zigachev #ifdef __DragonFly__
1397*78973132SSergey Zigachev 	int				rmmio_rid;
1398*78973132SSergey Zigachev 	struct resource			*rmmio;
1399*78973132SSergey Zigachev #endif
1400b843c749SSergey Zigachev 	/* protects concurrent MM_INDEX/DATA based register access */
1401b843c749SSergey Zigachev 	spinlock_t mmio_idx_lock;
1402b843c749SSergey Zigachev 	/* protects concurrent SMC based register access */
1403b843c749SSergey Zigachev 	spinlock_t smc_idx_lock;
1404b843c749SSergey Zigachev 	amdgpu_rreg_t			smc_rreg;
1405b843c749SSergey Zigachev 	amdgpu_wreg_t			smc_wreg;
1406b843c749SSergey Zigachev 	/* protects concurrent PCIE register access */
1407b843c749SSergey Zigachev 	spinlock_t pcie_idx_lock;
1408b843c749SSergey Zigachev 	amdgpu_rreg_t			pcie_rreg;
1409b843c749SSergey Zigachev 	amdgpu_wreg_t			pcie_wreg;
1410b843c749SSergey Zigachev 	amdgpu_rreg_t			pciep_rreg;
1411b843c749SSergey Zigachev 	amdgpu_wreg_t			pciep_wreg;
1412b843c749SSergey Zigachev 	/* protects concurrent UVD register access */
1413b843c749SSergey Zigachev 	spinlock_t uvd_ctx_idx_lock;
1414b843c749SSergey Zigachev 	amdgpu_rreg_t			uvd_ctx_rreg;
1415b843c749SSergey Zigachev 	amdgpu_wreg_t			uvd_ctx_wreg;
1416b843c749SSergey Zigachev 	/* protects concurrent DIDT register access */
1417b843c749SSergey Zigachev 	spinlock_t didt_idx_lock;
1418b843c749SSergey Zigachev 	amdgpu_rreg_t			didt_rreg;
1419b843c749SSergey Zigachev 	amdgpu_wreg_t			didt_wreg;
1420b843c749SSergey Zigachev 	/* protects concurrent gc_cac register access */
1421b843c749SSergey Zigachev 	spinlock_t gc_cac_idx_lock;
1422b843c749SSergey Zigachev 	amdgpu_rreg_t			gc_cac_rreg;
1423b843c749SSergey Zigachev 	amdgpu_wreg_t			gc_cac_wreg;
1424b843c749SSergey Zigachev 	/* protects concurrent se_cac register access */
1425b843c749SSergey Zigachev 	spinlock_t se_cac_idx_lock;
1426b843c749SSergey Zigachev 	amdgpu_rreg_t			se_cac_rreg;
1427b843c749SSergey Zigachev 	amdgpu_wreg_t			se_cac_wreg;
1428b843c749SSergey Zigachev 	/* protects concurrent ENDPOINT (audio) register access */
1429b843c749SSergey Zigachev 	spinlock_t audio_endpt_idx_lock;
1430b843c749SSergey Zigachev 	amdgpu_block_rreg_t		audio_endpt_rreg;
1431b843c749SSergey Zigachev 	amdgpu_block_wreg_t		audio_endpt_wreg;
1432*78973132SSergey Zigachev #if 0
1433b843c749SSergey Zigachev 	void __iomem                    *rio_mem;
1434*78973132SSergey Zigachev #endif
1435*78973132SSergey Zigachev #ifdef __DragonFly__
1436*78973132SSergey Zigachev 	int				rio_rid;
1437*78973132SSergey Zigachev 	struct resource			*rio_mem;
1438*78973132SSergey Zigachev #endif
1439b843c749SSergey Zigachev 	resource_size_t			rio_mem_size;
1440b843c749SSergey Zigachev 	struct amdgpu_doorbell		doorbell;
1441b843c749SSergey Zigachev 
1442b843c749SSergey Zigachev 	/* clock/pll info */
1443b843c749SSergey Zigachev 	struct amdgpu_clock            clock;
1444b843c749SSergey Zigachev 
1445b843c749SSergey Zigachev 	/* MC */
1446b843c749SSergey Zigachev 	struct amdgpu_gmc		gmc;
1447b843c749SSergey Zigachev 	struct amdgpu_gart		gart;
1448b843c749SSergey Zigachev 	dma_addr_t			dummy_page_addr;
1449b843c749SSergey Zigachev 	struct amdgpu_vm_manager	vm_manager;
1450b843c749SSergey Zigachev 	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
1451b843c749SSergey Zigachev 
1452b843c749SSergey Zigachev 	/* memory management */
1453b843c749SSergey Zigachev 	struct amdgpu_mman		mman;
1454b843c749SSergey Zigachev 	struct amdgpu_vram_scratch	vram_scratch;
1455b843c749SSergey Zigachev 	struct amdgpu_wb		wb;
1456b843c749SSergey Zigachev 	atomic64_t			num_bytes_moved;
1457b843c749SSergey Zigachev 	atomic64_t			num_evictions;
1458b843c749SSergey Zigachev 	atomic64_t			num_vram_cpu_page_faults;
1459b843c749SSergey Zigachev 	atomic_t			gpu_reset_counter;
1460b843c749SSergey Zigachev 	atomic_t			vram_lost_counter;
1461b843c749SSergey Zigachev 
1462b843c749SSergey Zigachev 	/* data for buffer migration throttling */
1463b843c749SSergey Zigachev 	struct {
1464*78973132SSergey Zigachev 		struct spinlock		lock;
1465b843c749SSergey Zigachev 		s64			last_update_us;
1466b843c749SSergey Zigachev 		s64			accum_us; /* accumulated microseconds */
1467b843c749SSergey Zigachev 		s64			accum_us_vis; /* for visible VRAM */
1468b843c749SSergey Zigachev 		u32			log2_max_MBps;
1469b843c749SSergey Zigachev 	} mm_stats;
1470b843c749SSergey Zigachev 
1471b843c749SSergey Zigachev 	/* display */
1472b843c749SSergey Zigachev 	bool				enable_virtual_display;
1473b843c749SSergey Zigachev 	struct amdgpu_mode_info		mode_info;
1474b843c749SSergey Zigachev 	/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
1475b843c749SSergey Zigachev 	struct work_struct		hotplug_work;
1476b843c749SSergey Zigachev 	struct amdgpu_irq_src		crtc_irq;
1477b843c749SSergey Zigachev 	struct amdgpu_irq_src		pageflip_irq;
1478b843c749SSergey Zigachev 	struct amdgpu_irq_src		hpd_irq;
1479b843c749SSergey Zigachev 
1480b843c749SSergey Zigachev 	/* rings */
1481b843c749SSergey Zigachev 	u64				fence_context;
1482b843c749SSergey Zigachev 	unsigned			num_rings;
1483b843c749SSergey Zigachev 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
1484b843c749SSergey Zigachev 	bool				ib_pool_ready;
1485b843c749SSergey Zigachev 	struct amdgpu_sa_manager	ring_tmp_bo;
1486b843c749SSergey Zigachev 
1487b843c749SSergey Zigachev 	/* interrupts */
1488b843c749SSergey Zigachev 	struct amdgpu_irq		irq;
1489b843c749SSergey Zigachev 
1490b843c749SSergey Zigachev 	/* powerplay */
1491b843c749SSergey Zigachev 	struct amd_powerplay		powerplay;
1492b843c749SSergey Zigachev 	bool				pp_force_state_enabled;
1493b843c749SSergey Zigachev 
1494b843c749SSergey Zigachev 	/* dpm */
1495b843c749SSergey Zigachev 	struct amdgpu_pm		pm;
1496b843c749SSergey Zigachev 	u32				cg_flags;
1497b843c749SSergey Zigachev 	u32				pg_flags;
1498b843c749SSergey Zigachev 
1499b843c749SSergey Zigachev 	/* amdgpu smumgr */
1500b843c749SSergey Zigachev 	struct amdgpu_smumgr smu;
1501b843c749SSergey Zigachev 
1502b843c749SSergey Zigachev 	/* gfx */
1503b843c749SSergey Zigachev 	struct amdgpu_gfx		gfx;
1504b843c749SSergey Zigachev 
1505b843c749SSergey Zigachev 	/* sdma */
1506b843c749SSergey Zigachev 	struct amdgpu_sdma		sdma;
1507b843c749SSergey Zigachev 
1508b843c749SSergey Zigachev 	/* uvd */
1509b843c749SSergey Zigachev 	struct amdgpu_uvd		uvd;
1510b843c749SSergey Zigachev 
1511b843c749SSergey Zigachev 	/* vce */
1512b843c749SSergey Zigachev 	struct amdgpu_vce		vce;
1513b843c749SSergey Zigachev 
1514b843c749SSergey Zigachev 	/* vcn */
1515b843c749SSergey Zigachev 	struct amdgpu_vcn		vcn;
1516b843c749SSergey Zigachev 
1517b843c749SSergey Zigachev 	/* firmwares */
1518b843c749SSergey Zigachev 	struct amdgpu_firmware		firmware;
1519b843c749SSergey Zigachev 
1520b843c749SSergey Zigachev 	/* PSP */
1521b843c749SSergey Zigachev 	struct psp_context		psp;
1522b843c749SSergey Zigachev 
1523b843c749SSergey Zigachev 	/* GDS */
1524b843c749SSergey Zigachev 	struct amdgpu_gds		gds;
1525b843c749SSergey Zigachev 
1526b843c749SSergey Zigachev 	/* display related functionality */
1527b843c749SSergey Zigachev 	struct amdgpu_display_manager dm;
1528b843c749SSergey Zigachev 
1529b843c749SSergey Zigachev 	struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
1530b843c749SSergey Zigachev 	int				num_ip_blocks;
1531*78973132SSergey Zigachev 	struct lock	mn_lock;
1532b843c749SSergey Zigachev 	DECLARE_HASHTABLE(mn_hash, 7);
1533b843c749SSergey Zigachev 
1534b843c749SSergey Zigachev 	/* tracking pinned memory */
1535b843c749SSergey Zigachev 	atomic64_t vram_pin_size;
1536b843c749SSergey Zigachev 	atomic64_t visible_pin_size;
1537b843c749SSergey Zigachev 	atomic64_t gart_pin_size;
1538b843c749SSergey Zigachev 
1539b843c749SSergey Zigachev 	/* amdkfd interface */
1540b843c749SSergey Zigachev 	struct kfd_dev          *kfd;
1541b843c749SSergey Zigachev 
1542b843c749SSergey Zigachev 	/* soc15 register offset based on ip, instance and  segment */
1543b843c749SSergey Zigachev 	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
1544b843c749SSergey Zigachev 
1545b843c749SSergey Zigachev 	const struct amdgpu_nbio_funcs	*nbio_funcs;
1546b843c749SSergey Zigachev 	const struct amdgpu_df_funcs	*df_funcs;
1547b843c749SSergey Zigachev 
1548b843c749SSergey Zigachev 	/* delayed work_func for deferring clockgating during resume */
1549b843c749SSergey Zigachev 	struct delayed_work     late_init_work;
1550b843c749SSergey Zigachev 
1551b843c749SSergey Zigachev 	struct amdgpu_virt	virt;
1552b843c749SSergey Zigachev 	/* firmware VRAM reservation */
1553b843c749SSergey Zigachev 	struct amdgpu_fw_vram_usage fw_vram_usage;
1554b843c749SSergey Zigachev 
1555b843c749SSergey Zigachev 	/* link all shadow bo */
1556b843c749SSergey Zigachev 	struct list_head                shadow_list;
1557*78973132SSergey Zigachev 	struct lock                    shadow_list_lock;
1558b843c749SSergey Zigachev 	/* keep an lru list of rings by HW IP */
1559b843c749SSergey Zigachev 	struct list_head		ring_lru_list;
1560*78973132SSergey Zigachev 	struct spinlock			ring_lru_list_lock;
1561b843c749SSergey Zigachev 
1562b843c749SSergey Zigachev 	/* record hw reset is performed */
1563b843c749SSergey Zigachev 	bool has_hw_reset;
1564b843c749SSergey Zigachev 	u8				reset_magic[AMDGPU_RESET_MAGIC_NUM];
1565b843c749SSergey Zigachev 
1566b843c749SSergey Zigachev 	/* record last mm index being written through WREG32*/
1567b843c749SSergey Zigachev 	unsigned long last_mm_index;
1568b843c749SSergey Zigachev 	bool                            in_gpu_reset;
1569*78973132SSergey Zigachev 	struct lock  lock_reset;
1570*78973132SSergey Zigachev #ifdef __DragonFly__
1571*78973132SSergey Zigachev 	struct {
1572*78973132SSergey Zigachev 		ACPI_HANDLE		handle;
1573*78973132SSergey Zigachev 		ACPI_NOTIFY_HANDLER	notifier_call;
1574*78973132SSergey Zigachev 	} acpi;
1575*78973132SSergey Zigachev 	bool				fictitious_range_registered;
1576*78973132SSergey Zigachev #endif
1577b843c749SSergey Zigachev };
1578b843c749SSergey Zigachev 
amdgpu_ttm_adev(struct ttm_bo_device * bdev)1579b843c749SSergey Zigachev static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1580b843c749SSergey Zigachev {
1581b843c749SSergey Zigachev 	return container_of(bdev, struct amdgpu_device, mman.bdev);
1582b843c749SSergey Zigachev }
1583b843c749SSergey Zigachev 
1584b843c749SSergey Zigachev int amdgpu_device_init(struct amdgpu_device *adev,
1585b843c749SSergey Zigachev 		       struct drm_device *ddev,
1586b843c749SSergey Zigachev 		       struct pci_dev *pdev,
1587b843c749SSergey Zigachev 		       uint32_t flags);
1588b843c749SSergey Zigachev void amdgpu_device_fini(struct amdgpu_device *adev);
1589b843c749SSergey Zigachev int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1590b843c749SSergey Zigachev 
1591b843c749SSergey Zigachev uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
1592b843c749SSergey Zigachev 			uint32_t acc_flags);
1593b843c749SSergey Zigachev void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
1594b843c749SSergey Zigachev 		    uint32_t acc_flags);
1595b843c749SSergey Zigachev void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
1596b843c749SSergey Zigachev uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
1597b843c749SSergey Zigachev 
1598b843c749SSergey Zigachev u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1599b843c749SSergey Zigachev void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1600b843c749SSergey Zigachev 
1601b843c749SSergey Zigachev u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1602b843c749SSergey Zigachev void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1603b843c749SSergey Zigachev u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1604b843c749SSergey Zigachev void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
1605b843c749SSergey Zigachev 
1606b843c749SSergey Zigachev bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
1607b843c749SSergey Zigachev bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
1608b843c749SSergey Zigachev 
1609b843c749SSergey Zigachev int emu_soc_asic_init(struct amdgpu_device *adev);
1610b843c749SSergey Zigachev 
1611b843c749SSergey Zigachev /*
1612b843c749SSergey Zigachev  * Registers read & write functions.
1613b843c749SSergey Zigachev  */
1614b843c749SSergey Zigachev 
1615b843c749SSergey Zigachev #define AMDGPU_REGS_IDX       (1<<0)
1616b843c749SSergey Zigachev #define AMDGPU_REGS_NO_KIQ    (1<<1)
1617b843c749SSergey Zigachev 
1618b843c749SSergey Zigachev #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
1619b843c749SSergey Zigachev #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
1620b843c749SSergey Zigachev 
1621b843c749SSergey Zigachev #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
1622b843c749SSergey Zigachev #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
1623b843c749SSergey Zigachev 
1624b843c749SSergey Zigachev #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
1625b843c749SSergey Zigachev #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
1626b843c749SSergey Zigachev #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
1627b843c749SSergey Zigachev #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
1628b843c749SSergey Zigachev #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
1629b843c749SSergey Zigachev #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1630b843c749SSergey Zigachev #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1631b843c749SSergey Zigachev #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1632b843c749SSergey Zigachev #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
1633b843c749SSergey Zigachev #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
1634b843c749SSergey Zigachev #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
1635b843c749SSergey Zigachev #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
1636b843c749SSergey Zigachev #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
1637b843c749SSergey Zigachev #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
1638b843c749SSergey Zigachev #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
1639b843c749SSergey Zigachev #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
1640b843c749SSergey Zigachev #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
1641b843c749SSergey Zigachev #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1642b843c749SSergey Zigachev #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
1643b843c749SSergey Zigachev #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
1644b843c749SSergey Zigachev #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
1645b843c749SSergey Zigachev #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
1646b843c749SSergey Zigachev #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
1647b843c749SSergey Zigachev #define WREG32_P(reg, val, mask)				\
1648b843c749SSergey Zigachev 	do {							\
1649b843c749SSergey Zigachev 		uint32_t tmp_ = RREG32(reg);			\
1650b843c749SSergey Zigachev 		tmp_ &= (mask);					\
1651b843c749SSergey Zigachev 		tmp_ |= ((val) & ~(mask));			\
1652b843c749SSergey Zigachev 		WREG32(reg, tmp_);				\
1653b843c749SSergey Zigachev 	} while (0)
1654b843c749SSergey Zigachev #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1655b843c749SSergey Zigachev #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1656b843c749SSergey Zigachev #define WREG32_PLL_P(reg, val, mask)				\
1657b843c749SSergey Zigachev 	do {							\
1658b843c749SSergey Zigachev 		uint32_t tmp_ = RREG32_PLL(reg);		\
1659b843c749SSergey Zigachev 		tmp_ &= (mask);					\
1660b843c749SSergey Zigachev 		tmp_ |= ((val) & ~(mask));			\
1661b843c749SSergey Zigachev 		WREG32_PLL(reg, tmp_);				\
1662b843c749SSergey Zigachev 	} while (0)
1663b843c749SSergey Zigachev #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
1664b843c749SSergey Zigachev #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1665b843c749SSergey Zigachev #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1666b843c749SSergey Zigachev 
1667b843c749SSergey Zigachev #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
1668b843c749SSergey Zigachev #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1669b843c749SSergey Zigachev #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1670b843c749SSergey Zigachev #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
1671b843c749SSergey Zigachev 
1672b843c749SSergey Zigachev #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1673b843c749SSergey Zigachev #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1674b843c749SSergey Zigachev 
1675b843c749SSergey Zigachev #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
1676b843c749SSergey Zigachev 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
1677b843c749SSergey Zigachev 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1678b843c749SSergey Zigachev 
1679b843c749SSergey Zigachev #define REG_GET_FIELD(value, reg, field)				\
1680b843c749SSergey Zigachev 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1681b843c749SSergey Zigachev 
1682b843c749SSergey Zigachev #define WREG32_FIELD(reg, field, val)	\
1683b843c749SSergey Zigachev 	WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1684b843c749SSergey Zigachev 
1685b843c749SSergey Zigachev #define WREG32_FIELD_OFFSET(reg, offset, field, val)	\
1686b843c749SSergey Zigachev 	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1687b843c749SSergey Zigachev 
1688b843c749SSergey Zigachev /*
1689b843c749SSergey Zigachev  * BIOS helpers.
1690b843c749SSergey Zigachev  */
1691b843c749SSergey Zigachev #define RBIOS8(i) (adev->bios[i])
1692b843c749SSergey Zigachev #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1693b843c749SSergey Zigachev #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1694b843c749SSergey Zigachev 
1695b843c749SSergey Zigachev static inline struct amdgpu_sdma_instance *
amdgpu_get_sdma_instance(struct amdgpu_ring * ring)1696b843c749SSergey Zigachev amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
1697b843c749SSergey Zigachev {
1698b843c749SSergey Zigachev 	struct amdgpu_device *adev = ring->adev;
1699b843c749SSergey Zigachev 	int i;
1700b843c749SSergey Zigachev 
1701b843c749SSergey Zigachev 	for (i = 0; i < adev->sdma.num_instances; i++)
1702b843c749SSergey Zigachev 		if (&adev->sdma.instance[i].ring == ring)
1703b843c749SSergey Zigachev 			break;
1704b843c749SSergey Zigachev 
1705b843c749SSergey Zigachev 	if (i < AMDGPU_MAX_SDMA_INSTANCES)
1706b843c749SSergey Zigachev 		return &adev->sdma.instance[i];
1707b843c749SSergey Zigachev 	else
1708b843c749SSergey Zigachev 		return NULL;
1709b843c749SSergey Zigachev }
1710b843c749SSergey Zigachev 
1711b843c749SSergey Zigachev /*
1712b843c749SSergey Zigachev  * ASICs macro.
1713b843c749SSergey Zigachev  */
1714b843c749SSergey Zigachev #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1715b843c749SSergey Zigachev #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
1716b843c749SSergey Zigachev #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1717b843c749SSergey Zigachev #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1718b843c749SSergey Zigachev #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1719b843c749SSergey Zigachev #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1720b843c749SSergey Zigachev #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1721b843c749SSergey Zigachev #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
1722b843c749SSergey Zigachev #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
1723b843c749SSergey Zigachev #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
1724b843c749SSergey Zigachev #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1725b843c749SSergey Zigachev #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
1726b843c749SSergey Zigachev #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r))
1727b843c749SSergey Zigachev #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))
1728b843c749SSergey Zigachev #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev))
1729b843c749SSergey Zigachev #define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
1730b843c749SSergey Zigachev #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
1731b843c749SSergey Zigachev #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
1732b843c749SSergey Zigachev #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
1733b843c749SSergey Zigachev #define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) (adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags))
1734b843c749SSergey Zigachev #define amdgpu_gmc_get_pte_flags(adev, flags) (adev)->gmc.gmc_funcs->get_vm_pte_flags((adev),(flags))
1735b843c749SSergey Zigachev #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
1736b843c749SSergey Zigachev #define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
1737b843c749SSergey Zigachev #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)))
1738b843c749SSergey Zigachev #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
1739b843c749SSergey Zigachev #define amdgpu_ring_patch_cs_in_place(r, p, ib) ((r)->funcs->patch_cs_in_place((p), (ib)))
1740b843c749SSergey Zigachev #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
1741b843c749SSergey Zigachev #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
1742b843c749SSergey Zigachev #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
1743b843c749SSergey Zigachev #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
1744b843c749SSergey Zigachev #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
1745b843c749SSergey Zigachev #define amdgpu_ring_emit_ib(r, ib, vmid, c) (r)->funcs->emit_ib((r), (ib), (vmid), (c))
1746b843c749SSergey Zigachev #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
1747b843c749SSergey Zigachev #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
1748b843c749SSergey Zigachev #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
1749b843c749SSergey Zigachev #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))
1750b843c749SSergey Zigachev #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
1751b843c749SSergey Zigachev #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
1752b843c749SSergey Zigachev #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
1753b843c749SSergey Zigachev #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
1754b843c749SSergey Zigachev #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
1755b843c749SSergey Zigachev #define amdgpu_ring_emit_reg_wait(r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m))
1756b843c749SSergey Zigachev #define amdgpu_ring_emit_reg_write_reg_wait(r, d0, d1, v, m) (r)->funcs->emit_reg_write_reg_wait((r), (d0), (d1), (v), (m))
1757b843c749SSergey Zigachev #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
1758b843c749SSergey Zigachev #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
1759b843c749SSergey Zigachev #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
1760b843c749SSergey Zigachev #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
1761b843c749SSergey Zigachev #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
1762b843c749SSergey Zigachev #define amdgpu_ih_prescreen_iv(adev) (adev)->irq.ih_funcs->prescreen_iv((adev))
1763b843c749SSergey Zigachev #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
1764b843c749SSergey Zigachev #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
1765b843c749SSergey Zigachev #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
1766b843c749SSergey Zigachev #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
1767b843c749SSergey Zigachev #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
1768b843c749SSergey Zigachev #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
1769b843c749SSergey Zigachev #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
1770b843c749SSergey Zigachev #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
1771b843c749SSergey Zigachev #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
1772b843c749SSergey Zigachev #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
1773b843c749SSergey Zigachev #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
1774b843c749SSergey Zigachev #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
1775b843c749SSergey Zigachev #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))
1776b843c749SSergey Zigachev #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b))
1777b843c749SSergey Zigachev #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
1778b843c749SSergey Zigachev #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
1779b843c749SSergey Zigachev #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
1780b843c749SSergey Zigachev #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
1781b843c749SSergey Zigachev #define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
1782b843c749SSergey Zigachev #define amdgpu_gfx_select_me_pipe_q(adev, me, pipe, q) (adev)->gfx.funcs->select_me_pipe_q((adev), (me), (pipe), (q))
1783b843c749SSergey Zigachev 
1784b843c749SSergey Zigachev /* Common functions */
1785b843c749SSergey Zigachev int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
1786b843c749SSergey Zigachev 			      struct amdgpu_job* job, bool force);
1787b843c749SSergey Zigachev void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
1788b843c749SSergey Zigachev bool amdgpu_device_need_post(struct amdgpu_device *adev);
1789b843c749SSergey Zigachev void amdgpu_display_update_priority(struct amdgpu_device *adev);
1790b843c749SSergey Zigachev 
1791b843c749SSergey Zigachev void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
1792b843c749SSergey Zigachev 				  u64 num_vis_bytes);
1793b843c749SSergey Zigachev void amdgpu_device_vram_location(struct amdgpu_device *adev,
1794b843c749SSergey Zigachev 				 struct amdgpu_gmc *mc, u64 base);
1795b843c749SSergey Zigachev void amdgpu_device_gart_location(struct amdgpu_device *adev,
1796b843c749SSergey Zigachev 				 struct amdgpu_gmc *mc);
1797b843c749SSergey Zigachev int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
1798b843c749SSergey Zigachev void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
1799b843c749SSergey Zigachev 					     const u32 *registers,
1800b843c749SSergey Zigachev 					     const u32 array_size);
1801b843c749SSergey Zigachev 
1802b843c749SSergey Zigachev bool amdgpu_device_is_px(struct drm_device *dev);
1803b843c749SSergey Zigachev /* atpx handler */
1804b843c749SSergey Zigachev #if defined(CONFIG_VGA_SWITCHEROO)
1805b843c749SSergey Zigachev void amdgpu_register_atpx_handler(void);
1806b843c749SSergey Zigachev void amdgpu_unregister_atpx_handler(void);
1807b843c749SSergey Zigachev bool amdgpu_has_atpx_dgpu_power_cntl(void);
1808b843c749SSergey Zigachev bool amdgpu_is_atpx_hybrid(void);
1809b843c749SSergey Zigachev bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1810b843c749SSergey Zigachev bool amdgpu_has_atpx(void);
1811b843c749SSergey Zigachev #else
amdgpu_register_atpx_handler(void)1812b843c749SSergey Zigachev static inline void amdgpu_register_atpx_handler(void) {}
amdgpu_unregister_atpx_handler(void)1813b843c749SSergey Zigachev static inline void amdgpu_unregister_atpx_handler(void) {}
amdgpu_has_atpx_dgpu_power_cntl(void)1814b843c749SSergey Zigachev static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
amdgpu_is_atpx_hybrid(void)1815b843c749SSergey Zigachev static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
amdgpu_atpx_dgpu_req_power_for_displays(void)1816b843c749SSergey Zigachev static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
amdgpu_has_atpx(void)1817b843c749SSergey Zigachev static inline bool amdgpu_has_atpx(void) { return false; }
1818b843c749SSergey Zigachev #endif
1819b843c749SSergey Zigachev 
1820b843c749SSergey Zigachev #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
1821b843c749SSergey Zigachev void *amdgpu_atpx_get_dhandle(void);
1822b843c749SSergey Zigachev #else
amdgpu_atpx_get_dhandle(void)1823b843c749SSergey Zigachev static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
1824b843c749SSergey Zigachev #endif
1825b843c749SSergey Zigachev 
1826b843c749SSergey Zigachev /*
1827b843c749SSergey Zigachev  * KMS
1828b843c749SSergey Zigachev  */
1829b843c749SSergey Zigachev extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1830b843c749SSergey Zigachev extern const int amdgpu_max_kms_ioctl;
1831b843c749SSergey Zigachev 
1832b843c749SSergey Zigachev int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
1833b843c749SSergey Zigachev void amdgpu_driver_unload_kms(struct drm_device *dev);
1834b843c749SSergey Zigachev void amdgpu_driver_lastclose_kms(struct drm_device *dev);
1835b843c749SSergey Zigachev int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
1836b843c749SSergey Zigachev void amdgpu_driver_postclose_kms(struct drm_device *dev,
1837b843c749SSergey Zigachev 				 struct drm_file *file_priv);
1838b843c749SSergey Zigachev int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
1839b843c749SSergey Zigachev int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1840b843c749SSergey Zigachev int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
1841b843c749SSergey Zigachev u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
1842b843c749SSergey Zigachev int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1843b843c749SSergey Zigachev void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1844b843c749SSergey Zigachev long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
1845b843c749SSergey Zigachev 			     unsigned long arg);
1846b843c749SSergey Zigachev 
1847b843c749SSergey Zigachev /*
1848b843c749SSergey Zigachev  * functions used by amdgpu_encoder.c
1849b843c749SSergey Zigachev  */
1850b843c749SSergey Zigachev struct amdgpu_afmt_acr {
1851b843c749SSergey Zigachev 	u32 clock;
1852b843c749SSergey Zigachev 
1853b843c749SSergey Zigachev 	int n_32khz;
1854b843c749SSergey Zigachev 	int cts_32khz;
1855b843c749SSergey Zigachev 
1856b843c749SSergey Zigachev 	int n_44_1khz;
1857b843c749SSergey Zigachev 	int cts_44_1khz;
1858b843c749SSergey Zigachev 
1859b843c749SSergey Zigachev 	int n_48khz;
1860b843c749SSergey Zigachev 	int cts_48khz;
1861b843c749SSergey Zigachev 
1862b843c749SSergey Zigachev };
1863b843c749SSergey Zigachev 
1864b843c749SSergey Zigachev struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
1865b843c749SSergey Zigachev 
1866b843c749SSergey Zigachev /* amdgpu_acpi.c */
1867b843c749SSergey Zigachev #if defined(CONFIG_ACPI)
1868b843c749SSergey Zigachev int amdgpu_acpi_init(struct amdgpu_device *adev);
1869b843c749SSergey Zigachev void amdgpu_acpi_fini(struct amdgpu_device *adev);
1870b843c749SSergey Zigachev bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
1871b843c749SSergey Zigachev int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
1872b843c749SSergey Zigachev 						u8 perf_req, bool advertise);
1873b843c749SSergey Zigachev int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
1874b843c749SSergey Zigachev #else
amdgpu_acpi_init(struct amdgpu_device * adev)1875b843c749SSergey Zigachev static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
amdgpu_acpi_fini(struct amdgpu_device * adev)1876b843c749SSergey Zigachev static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
1877b843c749SSergey Zigachev #endif
1878b843c749SSergey Zigachev 
1879b843c749SSergey Zigachev int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
1880b843c749SSergey Zigachev 			   uint64_t addr, struct amdgpu_bo **bo,
1881b843c749SSergey Zigachev 			   struct amdgpu_bo_va_mapping **mapping);
1882b843c749SSergey Zigachev 
1883b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_DC)
1884b843c749SSergey Zigachev int amdgpu_dm_display_resume(struct amdgpu_device *adev );
1885b843c749SSergey Zigachev #else
amdgpu_dm_display_resume(struct amdgpu_device * adev)1886b843c749SSergey Zigachev static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
1887b843c749SSergey Zigachev #endif
1888b843c749SSergey Zigachev 
1889b843c749SSergey Zigachev #include "amdgpu_object.h"
1890b843c749SSergey Zigachev #endif
1891