xref: /openbsd/sys/dev/pci/drm/amd/amdgpu/sdma_v5_2.c (revision f61f9b4d)
1ad8b1aafSjsg /*
2ad8b1aafSjsg  * Copyright 2019 Advanced Micro Devices, Inc.
3ad8b1aafSjsg  *
4ad8b1aafSjsg  * Permission is hereby granted, free of charge, to any person obtaining a
5ad8b1aafSjsg  * copy of this software and associated documentation files (the "Software"),
6ad8b1aafSjsg  * to deal in the Software without restriction, including without limitation
7ad8b1aafSjsg  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8ad8b1aafSjsg  * and/or sell copies of the Software, and to permit persons to whom the
9ad8b1aafSjsg  * Software is furnished to do so, subject to the following conditions:
10ad8b1aafSjsg  *
11ad8b1aafSjsg  * The above copyright notice and this permission notice shall be included in
12ad8b1aafSjsg  * all copies or substantial portions of the Software.
13ad8b1aafSjsg  *
14ad8b1aafSjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15ad8b1aafSjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16ad8b1aafSjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17ad8b1aafSjsg  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18ad8b1aafSjsg  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ad8b1aafSjsg  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20ad8b1aafSjsg  * OTHER DEALINGS IN THE SOFTWARE.
21ad8b1aafSjsg  *
22ad8b1aafSjsg  */
23ad8b1aafSjsg 
24ad8b1aafSjsg #include <linux/delay.h>
25ad8b1aafSjsg #include <linux/firmware.h>
26ad8b1aafSjsg #include <linux/module.h>
27ad8b1aafSjsg #include <linux/pci.h>
28ad8b1aafSjsg 
29ad8b1aafSjsg #include "amdgpu.h"
30ad8b1aafSjsg #include "amdgpu_ucode.h"
31ad8b1aafSjsg #include "amdgpu_trace.h"
32ad8b1aafSjsg 
33ad8b1aafSjsg #include "gc/gc_10_3_0_offset.h"
34ad8b1aafSjsg #include "gc/gc_10_3_0_sh_mask.h"
35ad8b1aafSjsg #include "ivsrcid/sdma0/irqsrcs_sdma0_5_0.h"
36ad8b1aafSjsg #include "ivsrcid/sdma1/irqsrcs_sdma1_5_0.h"
37ad8b1aafSjsg #include "ivsrcid/sdma2/irqsrcs_sdma2_5_0.h"
38ad8b1aafSjsg #include "ivsrcid/sdma3/irqsrcs_sdma3_5_0.h"
39ad8b1aafSjsg 
40ad8b1aafSjsg #include "soc15_common.h"
41ad8b1aafSjsg #include "soc15.h"
42ad8b1aafSjsg #include "navi10_sdma_pkt_open.h"
43ad8b1aafSjsg #include "nbio_v2_3.h"
44ad8b1aafSjsg #include "sdma_common.h"
45ad8b1aafSjsg #include "sdma_v5_2.h"
46ad8b1aafSjsg 
47ad8b1aafSjsg MODULE_FIRMWARE("amdgpu/sienna_cichlid_sdma.bin");
48ad8b1aafSjsg MODULE_FIRMWARE("amdgpu/navy_flounder_sdma.bin");
495ca02815Sjsg MODULE_FIRMWARE("amdgpu/dimgrey_cavefish_sdma.bin");
505ca02815Sjsg MODULE_FIRMWARE("amdgpu/beige_goby_sdma.bin");
515ca02815Sjsg 
525ca02815Sjsg MODULE_FIRMWARE("amdgpu/vangogh_sdma.bin");
535ca02815Sjsg MODULE_FIRMWARE("amdgpu/yellow_carp_sdma.bin");
541bb76ff1Sjsg MODULE_FIRMWARE("amdgpu/sdma_5_2_6.bin");
551bb76ff1Sjsg MODULE_FIRMWARE("amdgpu/sdma_5_2_7.bin");
56ad8b1aafSjsg 
57ad8b1aafSjsg #define SDMA1_REG_OFFSET 0x600
58ad8b1aafSjsg #define SDMA3_REG_OFFSET 0x400
59ad8b1aafSjsg #define SDMA0_HYP_DEC_REG_START 0x5880
60ad8b1aafSjsg #define SDMA0_HYP_DEC_REG_END 0x5893
61ad8b1aafSjsg #define SDMA1_HYP_DEC_REG_OFFSET 0x20
62ad8b1aafSjsg 
63ad8b1aafSjsg static void sdma_v5_2_set_ring_funcs(struct amdgpu_device *adev);
64ad8b1aafSjsg static void sdma_v5_2_set_buffer_funcs(struct amdgpu_device *adev);
65ad8b1aafSjsg static void sdma_v5_2_set_vm_pte_funcs(struct amdgpu_device *adev);
66ad8b1aafSjsg static void sdma_v5_2_set_irq_funcs(struct amdgpu_device *adev);
67ad8b1aafSjsg 
sdma_v5_2_get_reg_offset(struct amdgpu_device * adev,u32 instance,u32 internal_offset)68ad8b1aafSjsg static u32 sdma_v5_2_get_reg_offset(struct amdgpu_device *adev, u32 instance, u32 internal_offset)
69ad8b1aafSjsg {
70ad8b1aafSjsg 	u32 base;
71ad8b1aafSjsg 
72ad8b1aafSjsg 	if (internal_offset >= SDMA0_HYP_DEC_REG_START &&
73ad8b1aafSjsg 	    internal_offset <= SDMA0_HYP_DEC_REG_END) {
74ad8b1aafSjsg 		base = adev->reg_offset[GC_HWIP][0][1];
75ad8b1aafSjsg 		if (instance != 0)
76ad8b1aafSjsg 			internal_offset += SDMA1_HYP_DEC_REG_OFFSET * instance;
77ad8b1aafSjsg 	} else {
78ad8b1aafSjsg 		if (instance < 2) {
79ad8b1aafSjsg 			base = adev->reg_offset[GC_HWIP][0][0];
80ad8b1aafSjsg 			if (instance == 1)
81ad8b1aafSjsg 				internal_offset += SDMA1_REG_OFFSET;
82ad8b1aafSjsg 		} else {
83ad8b1aafSjsg 			base = adev->reg_offset[GC_HWIP][0][2];
84ad8b1aafSjsg 			if (instance == 3)
85ad8b1aafSjsg 				internal_offset += SDMA3_REG_OFFSET;
86ad8b1aafSjsg 		}
87ad8b1aafSjsg 	}
88ad8b1aafSjsg 
89ad8b1aafSjsg 	return base + internal_offset;
90ad8b1aafSjsg }
91ad8b1aafSjsg 
sdma_v5_2_ring_init_cond_exec(struct amdgpu_ring * ring)92ad8b1aafSjsg static unsigned sdma_v5_2_ring_init_cond_exec(struct amdgpu_ring *ring)
93ad8b1aafSjsg {
94ad8b1aafSjsg 	unsigned ret;
95ad8b1aafSjsg 
96ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_COND_EXE));
97ad8b1aafSjsg 	amdgpu_ring_write(ring, lower_32_bits(ring->cond_exe_gpu_addr));
98ad8b1aafSjsg 	amdgpu_ring_write(ring, upper_32_bits(ring->cond_exe_gpu_addr));
99ad8b1aafSjsg 	amdgpu_ring_write(ring, 1);
100ad8b1aafSjsg 	ret = ring->wptr & ring->buf_mask;/* this is the offset we need patch later */
101ad8b1aafSjsg 	amdgpu_ring_write(ring, 0x55aa55aa);/* insert dummy here and patch it later */
102ad8b1aafSjsg 
103ad8b1aafSjsg 	return ret;
104ad8b1aafSjsg }
105ad8b1aafSjsg 
sdma_v5_2_ring_patch_cond_exec(struct amdgpu_ring * ring,unsigned offset)106ad8b1aafSjsg static void sdma_v5_2_ring_patch_cond_exec(struct amdgpu_ring *ring,
107ad8b1aafSjsg 					   unsigned offset)
108ad8b1aafSjsg {
109ad8b1aafSjsg 	unsigned cur;
110ad8b1aafSjsg 
111ad8b1aafSjsg 	BUG_ON(offset > ring->buf_mask);
112ad8b1aafSjsg 	BUG_ON(ring->ring[offset] != 0x55aa55aa);
113ad8b1aafSjsg 
114ad8b1aafSjsg 	cur = (ring->wptr - 1) & ring->buf_mask;
115ad8b1aafSjsg 	if (cur > offset)
116ad8b1aafSjsg 		ring->ring[offset] = cur - offset;
117ad8b1aafSjsg 	else
118ad8b1aafSjsg 		ring->ring[offset] = (ring->buf_mask + 1) - offset + cur;
119ad8b1aafSjsg }
120ad8b1aafSjsg 
121ad8b1aafSjsg /**
122ad8b1aafSjsg  * sdma_v5_2_ring_get_rptr - get the current read pointer
123ad8b1aafSjsg  *
124ad8b1aafSjsg  * @ring: amdgpu ring pointer
125ad8b1aafSjsg  *
126ad8b1aafSjsg  * Get the current rptr from the hardware (NAVI10+).
127ad8b1aafSjsg  */
sdma_v5_2_ring_get_rptr(struct amdgpu_ring * ring)128ad8b1aafSjsg static uint64_t sdma_v5_2_ring_get_rptr(struct amdgpu_ring *ring)
129ad8b1aafSjsg {
130ad8b1aafSjsg 	u64 *rptr;
131ad8b1aafSjsg 
132ad8b1aafSjsg 	/* XXX check if swapping is necessary on BE */
1331bb76ff1Sjsg 	rptr = (u64 *)ring->rptr_cpu_addr;
134ad8b1aafSjsg 
135ad8b1aafSjsg 	DRM_DEBUG("rptr before shift == 0x%016llx\n", *rptr);
136ad8b1aafSjsg 	return ((*rptr) >> 2);
137ad8b1aafSjsg }
138ad8b1aafSjsg 
139ad8b1aafSjsg /**
140ad8b1aafSjsg  * sdma_v5_2_ring_get_wptr - get the current write pointer
141ad8b1aafSjsg  *
142ad8b1aafSjsg  * @ring: amdgpu ring pointer
143ad8b1aafSjsg  *
144ad8b1aafSjsg  * Get the current wptr from the hardware (NAVI10+).
145ad8b1aafSjsg  */
sdma_v5_2_ring_get_wptr(struct amdgpu_ring * ring)146ad8b1aafSjsg static uint64_t sdma_v5_2_ring_get_wptr(struct amdgpu_ring *ring)
147ad8b1aafSjsg {
148ad8b1aafSjsg 	struct amdgpu_device *adev = ring->adev;
149ad8b1aafSjsg 	u64 wptr;
150ad8b1aafSjsg 
151ad8b1aafSjsg 	if (ring->use_doorbell) {
152ad8b1aafSjsg 		/* XXX check if swapping is necessary on BE */
1531bb76ff1Sjsg 		wptr = READ_ONCE(*((u64 *)ring->wptr_cpu_addr));
154ad8b1aafSjsg 		DRM_DEBUG("wptr/doorbell before shift == 0x%016llx\n", wptr);
155ad8b1aafSjsg 	} else {
156ad8b1aafSjsg 		wptr = RREG32(sdma_v5_2_get_reg_offset(adev, ring->me, mmSDMA0_GFX_RB_WPTR_HI));
157ad8b1aafSjsg 		wptr = wptr << 32;
158ad8b1aafSjsg 		wptr |= RREG32(sdma_v5_2_get_reg_offset(adev, ring->me, mmSDMA0_GFX_RB_WPTR));
159ad8b1aafSjsg 		DRM_DEBUG("wptr before shift [%i] wptr == 0x%016llx\n", ring->me, wptr);
160ad8b1aafSjsg 	}
161ad8b1aafSjsg 
162ad8b1aafSjsg 	return wptr >> 2;
163ad8b1aafSjsg }
164ad8b1aafSjsg 
165ad8b1aafSjsg /**
166ad8b1aafSjsg  * sdma_v5_2_ring_set_wptr - commit the write pointer
167ad8b1aafSjsg  *
168ad8b1aafSjsg  * @ring: amdgpu ring pointer
169ad8b1aafSjsg  *
170ad8b1aafSjsg  * Write the wptr back to the hardware (NAVI10+).
171ad8b1aafSjsg  */
sdma_v5_2_ring_set_wptr(struct amdgpu_ring * ring)172ad8b1aafSjsg static void sdma_v5_2_ring_set_wptr(struct amdgpu_ring *ring)
173ad8b1aafSjsg {
174ad8b1aafSjsg 	struct amdgpu_device *adev = ring->adev;
175ad8b1aafSjsg 
176ad8b1aafSjsg 	DRM_DEBUG("Setting write pointer\n");
177ad8b1aafSjsg 	if (ring->use_doorbell) {
178ad8b1aafSjsg 		DRM_DEBUG("Using doorbell -- "
179ad8b1aafSjsg 				"wptr_offs == 0x%08x "
1805decb207Sjsg 				"lower_32_bits(ring->wptr << 2) == 0x%08x "
1815decb207Sjsg 				"upper_32_bits(ring->wptr << 2) == 0x%08x\n",
182ad8b1aafSjsg 				ring->wptr_offs,
183ad8b1aafSjsg 				lower_32_bits(ring->wptr << 2),
184ad8b1aafSjsg 				upper_32_bits(ring->wptr << 2));
185ad8b1aafSjsg 		/* XXX check if swapping is necessary on BE */
1861bb76ff1Sjsg 		atomic64_set((atomic64_t *)ring->wptr_cpu_addr,
1871bb76ff1Sjsg 			     ring->wptr << 2);
188ad8b1aafSjsg 		DRM_DEBUG("calling WDOORBELL64(0x%08x, 0x%016llx)\n",
189ad8b1aafSjsg 				ring->doorbell_index, ring->wptr << 2);
190ad8b1aafSjsg 		WDOORBELL64(ring->doorbell_index, ring->wptr << 2);
191*f61f9b4dSjsg 		/* SDMA seems to miss doorbells sometimes when powergating kicks in.
192*f61f9b4dSjsg 		 * Updating the wptr directly will wake it. This is only safe because
193*f61f9b4dSjsg 		 * we disallow gfxoff in begin_use() and then allow it again in end_use().
194*f61f9b4dSjsg 		 */
195*f61f9b4dSjsg 		WREG32(sdma_v5_2_get_reg_offset(adev, ring->me, mmSDMA0_GFX_RB_WPTR),
196*f61f9b4dSjsg 		       lower_32_bits(ring->wptr << 2));
197*f61f9b4dSjsg 		WREG32(sdma_v5_2_get_reg_offset(adev, ring->me, mmSDMA0_GFX_RB_WPTR_HI),
198*f61f9b4dSjsg 		       upper_32_bits(ring->wptr << 2));
199ad8b1aafSjsg 	} else {
200ad8b1aafSjsg 		DRM_DEBUG("Not using doorbell -- "
201ad8b1aafSjsg 				"mmSDMA%i_GFX_RB_WPTR == 0x%08x "
202ad8b1aafSjsg 				"mmSDMA%i_GFX_RB_WPTR_HI == 0x%08x\n",
203ad8b1aafSjsg 				ring->me,
204ad8b1aafSjsg 				lower_32_bits(ring->wptr << 2),
205ad8b1aafSjsg 				ring->me,
206ad8b1aafSjsg 				upper_32_bits(ring->wptr << 2));
207ad8b1aafSjsg 		WREG32(sdma_v5_2_get_reg_offset(adev, ring->me, mmSDMA0_GFX_RB_WPTR),
208ad8b1aafSjsg 			lower_32_bits(ring->wptr << 2));
209ad8b1aafSjsg 		WREG32(sdma_v5_2_get_reg_offset(adev, ring->me, mmSDMA0_GFX_RB_WPTR_HI),
210ad8b1aafSjsg 			upper_32_bits(ring->wptr << 2));
211ad8b1aafSjsg 	}
212ad8b1aafSjsg }
213ad8b1aafSjsg 
sdma_v5_2_ring_insert_nop(struct amdgpu_ring * ring,uint32_t count)214ad8b1aafSjsg static void sdma_v5_2_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)
215ad8b1aafSjsg {
216ad8b1aafSjsg 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
217ad8b1aafSjsg 	int i;
218ad8b1aafSjsg 
219ad8b1aafSjsg 	for (i = 0; i < count; i++)
220ad8b1aafSjsg 		if (sdma && sdma->burst_nop && (i == 0))
221ad8b1aafSjsg 			amdgpu_ring_write(ring, ring->funcs->nop |
222ad8b1aafSjsg 				SDMA_PKT_NOP_HEADER_COUNT(count - 1));
223ad8b1aafSjsg 		else
224ad8b1aafSjsg 			amdgpu_ring_write(ring, ring->funcs->nop);
225ad8b1aafSjsg }
226ad8b1aafSjsg 
227ad8b1aafSjsg /**
228ad8b1aafSjsg  * sdma_v5_2_ring_emit_ib - Schedule an IB on the DMA engine
229ad8b1aafSjsg  *
230ad8b1aafSjsg  * @ring: amdgpu ring pointer
2315ca02815Sjsg  * @job: job to retrieve vmid from
232ad8b1aafSjsg  * @ib: IB object to schedule
2335ca02815Sjsg  * @flags: unused
234ad8b1aafSjsg  *
235ad8b1aafSjsg  * Schedule an IB in the DMA ring.
236ad8b1aafSjsg  */
sdma_v5_2_ring_emit_ib(struct amdgpu_ring * ring,struct amdgpu_job * job,struct amdgpu_ib * ib,uint32_t flags)237ad8b1aafSjsg static void sdma_v5_2_ring_emit_ib(struct amdgpu_ring *ring,
238ad8b1aafSjsg 				   struct amdgpu_job *job,
239ad8b1aafSjsg 				   struct amdgpu_ib *ib,
240ad8b1aafSjsg 				   uint32_t flags)
241ad8b1aafSjsg {
242ad8b1aafSjsg 	unsigned vmid = AMDGPU_JOB_GET_VMID(job);
243ad8b1aafSjsg 	uint64_t csa_mc_addr = amdgpu_sdma_get_csa_mc_addr(ring, vmid);
244ad8b1aafSjsg 
245ad8b1aafSjsg 	/* An IB packet must end on a 8 DW boundary--the next dword
246ad8b1aafSjsg 	 * must be on a 8-dword boundary. Our IB packet below is 6
247ad8b1aafSjsg 	 * dwords long, thus add x number of NOPs, such that, in
248ad8b1aafSjsg 	 * modular arithmetic,
249ad8b1aafSjsg 	 * wptr + 6 + x = 8k, k >= 0, which in C is,
250ad8b1aafSjsg 	 * (wptr + 6 + x) % 8 = 0.
251ad8b1aafSjsg 	 * The expression below, is a solution of x.
252ad8b1aafSjsg 	 */
253ad8b1aafSjsg 	sdma_v5_2_ring_insert_nop(ring, (2 - lower_32_bits(ring->wptr)) & 7);
254ad8b1aafSjsg 
255ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_INDIRECT) |
256ad8b1aafSjsg 			  SDMA_PKT_INDIRECT_HEADER_VMID(vmid & 0xf));
257ad8b1aafSjsg 	/* base must be 32 byte aligned */
258ad8b1aafSjsg 	amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr) & 0xffffffe0);
259ad8b1aafSjsg 	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
260ad8b1aafSjsg 	amdgpu_ring_write(ring, ib->length_dw);
261ad8b1aafSjsg 	amdgpu_ring_write(ring, lower_32_bits(csa_mc_addr));
262ad8b1aafSjsg 	amdgpu_ring_write(ring, upper_32_bits(csa_mc_addr));
263ad8b1aafSjsg }
264ad8b1aafSjsg 
265ad8b1aafSjsg /**
2665ca02815Sjsg  * sdma_v5_2_ring_emit_mem_sync - flush the IB by graphics cache rinse
2675ca02815Sjsg  *
2685ca02815Sjsg  * @ring: amdgpu ring pointer
2695ca02815Sjsg  *
2705ca02815Sjsg  * flush the IB by graphics cache rinse.
2715ca02815Sjsg  */
sdma_v5_2_ring_emit_mem_sync(struct amdgpu_ring * ring)2725ca02815Sjsg static void sdma_v5_2_ring_emit_mem_sync(struct amdgpu_ring *ring)
2735ca02815Sjsg {
2741bb76ff1Sjsg 	uint32_t gcr_cntl = SDMA_GCR_GL2_INV | SDMA_GCR_GL2_WB |
2751bb76ff1Sjsg 			    SDMA_GCR_GLM_INV | SDMA_GCR_GL1_INV |
2761bb76ff1Sjsg 			    SDMA_GCR_GLV_INV | SDMA_GCR_GLK_INV |
2775ca02815Sjsg 			    SDMA_GCR_GLI_INV(1);
2785ca02815Sjsg 
2795ca02815Sjsg 	/* flush entire cache L0/L1/L2, this can be optimized by performance requirement */
2805ca02815Sjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_GCR_REQ));
2815ca02815Sjsg 	amdgpu_ring_write(ring, SDMA_PKT_GCR_REQ_PAYLOAD1_BASE_VA_31_7(0));
2825ca02815Sjsg 	amdgpu_ring_write(ring, SDMA_PKT_GCR_REQ_PAYLOAD2_GCR_CONTROL_15_0(gcr_cntl) |
2835ca02815Sjsg 			SDMA_PKT_GCR_REQ_PAYLOAD2_BASE_VA_47_32(0));
2845ca02815Sjsg 	amdgpu_ring_write(ring, SDMA_PKT_GCR_REQ_PAYLOAD3_LIMIT_VA_31_7(0) |
2855ca02815Sjsg 			SDMA_PKT_GCR_REQ_PAYLOAD3_GCR_CONTROL_18_16(gcr_cntl >> 16));
2865ca02815Sjsg 	amdgpu_ring_write(ring, SDMA_PKT_GCR_REQ_PAYLOAD4_LIMIT_VA_47_32(0) |
2875ca02815Sjsg 			SDMA_PKT_GCR_REQ_PAYLOAD4_VMID(0));
2885ca02815Sjsg }
2895ca02815Sjsg 
2905ca02815Sjsg /**
291ad8b1aafSjsg  * sdma_v5_2_ring_emit_hdp_flush - emit an hdp flush on the DMA ring
292ad8b1aafSjsg  *
293ad8b1aafSjsg  * @ring: amdgpu ring pointer
294ad8b1aafSjsg  *
295ad8b1aafSjsg  * Emit an hdp flush packet on the requested DMA ring.
296ad8b1aafSjsg  */
sdma_v5_2_ring_emit_hdp_flush(struct amdgpu_ring * ring)297ad8b1aafSjsg static void sdma_v5_2_ring_emit_hdp_flush(struct amdgpu_ring *ring)
298ad8b1aafSjsg {
299ad8b1aafSjsg 	struct amdgpu_device *adev = ring->adev;
300ad8b1aafSjsg 	u32 ref_and_mask = 0;
301ad8b1aafSjsg 	const struct nbio_hdp_flush_reg *nbio_hf_reg = adev->nbio.hdp_flush_reg;
302ad8b1aafSjsg 
3037e01100fSjsg 	if (ring->me > 1) {
3047e01100fSjsg 		amdgpu_asic_flush_hdp(adev, ring);
3057e01100fSjsg 	} else {
306ad8b1aafSjsg 		ref_and_mask = nbio_hf_reg->ref_and_mask_sdma0 << ring->me;
307ad8b1aafSjsg 
308ad8b1aafSjsg 		amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
309ad8b1aafSjsg 				  SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(1) |
310ad8b1aafSjsg 				  SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3)); /* == */
311ad8b1aafSjsg 		amdgpu_ring_write(ring, (adev->nbio.funcs->get_hdp_flush_done_offset(adev)) << 2);
312ad8b1aafSjsg 		amdgpu_ring_write(ring, (adev->nbio.funcs->get_hdp_flush_req_offset(adev)) << 2);
313ad8b1aafSjsg 		amdgpu_ring_write(ring, ref_and_mask); /* reference */
314ad8b1aafSjsg 		amdgpu_ring_write(ring, ref_and_mask); /* mask */
315ad8b1aafSjsg 		amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
316ad8b1aafSjsg 				  SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10)); /* retry count, poll interval */
317ad8b1aafSjsg 	}
3187e01100fSjsg }
319ad8b1aafSjsg 
320ad8b1aafSjsg /**
321ad8b1aafSjsg  * sdma_v5_2_ring_emit_fence - emit a fence on the DMA ring
322ad8b1aafSjsg  *
323ad8b1aafSjsg  * @ring: amdgpu ring pointer
3245ca02815Sjsg  * @addr: address
3255ca02815Sjsg  * @seq: sequence number
3265ca02815Sjsg  * @flags: fence related flags
327ad8b1aafSjsg  *
328ad8b1aafSjsg  * Add a DMA fence packet to the ring to write
329ad8b1aafSjsg  * the fence seq number and DMA trap packet to generate
330ad8b1aafSjsg  * an interrupt if needed.
331ad8b1aafSjsg  */
sdma_v5_2_ring_emit_fence(struct amdgpu_ring * ring,u64 addr,u64 seq,unsigned flags)332ad8b1aafSjsg static void sdma_v5_2_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
333ad8b1aafSjsg 				      unsigned flags)
334ad8b1aafSjsg {
335ad8b1aafSjsg 	bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
336ad8b1aafSjsg 	/* write the fence */
337ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE) |
338ad8b1aafSjsg 			  SDMA_PKT_FENCE_HEADER_MTYPE(0x3)); /* Ucached(UC) */
339ad8b1aafSjsg 	/* zero in first two bits */
340ad8b1aafSjsg 	BUG_ON(addr & 0x3);
341ad8b1aafSjsg 	amdgpu_ring_write(ring, lower_32_bits(addr));
342ad8b1aafSjsg 	amdgpu_ring_write(ring, upper_32_bits(addr));
343ad8b1aafSjsg 	amdgpu_ring_write(ring, lower_32_bits(seq));
344ad8b1aafSjsg 
345ad8b1aafSjsg 	/* optionally write high bits as well */
346ad8b1aafSjsg 	if (write64bit) {
347ad8b1aafSjsg 		addr += 4;
348ad8b1aafSjsg 		amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE) |
349ad8b1aafSjsg 				  SDMA_PKT_FENCE_HEADER_MTYPE(0x3));
350ad8b1aafSjsg 		/* zero in first two bits */
351ad8b1aafSjsg 		BUG_ON(addr & 0x3);
352ad8b1aafSjsg 		amdgpu_ring_write(ring, lower_32_bits(addr));
353ad8b1aafSjsg 		amdgpu_ring_write(ring, upper_32_bits(addr));
354ad8b1aafSjsg 		amdgpu_ring_write(ring, upper_32_bits(seq));
355ad8b1aafSjsg 	}
356ad8b1aafSjsg 
3571bb76ff1Sjsg 	if ((flags & AMDGPU_FENCE_FLAG_INT)) {
3581bb76ff1Sjsg 		uint32_t ctx = ring->is_mes_queue ?
3591bb76ff1Sjsg 			(ring->hw_queue_id | AMDGPU_FENCE_MES_QUEUE_FLAG) : 0;
360ad8b1aafSjsg 		/* generate an interrupt */
361ad8b1aafSjsg 		amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_TRAP));
3621bb76ff1Sjsg 		amdgpu_ring_write(ring, SDMA_PKT_TRAP_INT_CONTEXT_INT_CONTEXT(ctx));
363ad8b1aafSjsg 	}
364ad8b1aafSjsg }
365ad8b1aafSjsg 
366ad8b1aafSjsg 
367ad8b1aafSjsg /**
368ad8b1aafSjsg  * sdma_v5_2_gfx_stop - stop the gfx async dma engines
369ad8b1aafSjsg  *
370ad8b1aafSjsg  * @adev: amdgpu_device pointer
371ad8b1aafSjsg  *
372ad8b1aafSjsg  * Stop the gfx async dma ring buffers.
373ad8b1aafSjsg  */
sdma_v5_2_gfx_stop(struct amdgpu_device * adev)374ad8b1aafSjsg static void sdma_v5_2_gfx_stop(struct amdgpu_device *adev)
375ad8b1aafSjsg {
376ad8b1aafSjsg 	u32 rb_cntl, ib_cntl;
377ad8b1aafSjsg 	int i;
378ad8b1aafSjsg 
3791bb76ff1Sjsg 	amdgpu_sdma_unset_buffer_funcs_helper(adev);
380ad8b1aafSjsg 
381ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
3825ca02815Sjsg 		rb_cntl = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL));
383ad8b1aafSjsg 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
3845ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl);
3855ca02815Sjsg 		ib_cntl = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL));
386ad8b1aafSjsg 		ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0);
3875ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl);
388ad8b1aafSjsg 	}
389ad8b1aafSjsg }
390ad8b1aafSjsg 
391ad8b1aafSjsg /**
392ad8b1aafSjsg  * sdma_v5_2_rlc_stop - stop the compute async dma engines
393ad8b1aafSjsg  *
394ad8b1aafSjsg  * @adev: amdgpu_device pointer
395ad8b1aafSjsg  *
396ad8b1aafSjsg  * Stop the compute async dma queues.
397ad8b1aafSjsg  */
sdma_v5_2_rlc_stop(struct amdgpu_device * adev)398ad8b1aafSjsg static void sdma_v5_2_rlc_stop(struct amdgpu_device *adev)
399ad8b1aafSjsg {
400ad8b1aafSjsg 	/* XXX todo */
401ad8b1aafSjsg }
402ad8b1aafSjsg 
403ad8b1aafSjsg /**
4045ca02815Sjsg  * sdma_v5_2_ctx_switch_enable - stop the async dma engines context switch
405ad8b1aafSjsg  *
406ad8b1aafSjsg  * @adev: amdgpu_device pointer
407ad8b1aafSjsg  * @enable: enable/disable the DMA MEs context switch.
408ad8b1aafSjsg  *
409ad8b1aafSjsg  * Halt or unhalt the async dma engines context switch.
410ad8b1aafSjsg  */
sdma_v5_2_ctx_switch_enable(struct amdgpu_device * adev,bool enable)411ad8b1aafSjsg static void sdma_v5_2_ctx_switch_enable(struct amdgpu_device *adev, bool enable)
412ad8b1aafSjsg {
413ad8b1aafSjsg 	u32 f32_cntl, phase_quantum = 0;
414ad8b1aafSjsg 	int i;
415ad8b1aafSjsg 
416ad8b1aafSjsg 	if (amdgpu_sdma_phase_quantum) {
417ad8b1aafSjsg 		unsigned value = amdgpu_sdma_phase_quantum;
418ad8b1aafSjsg 		unsigned unit = 0;
419ad8b1aafSjsg 
420ad8b1aafSjsg 		while (value > (SDMA0_PHASE0_QUANTUM__VALUE_MASK >>
421ad8b1aafSjsg 				SDMA0_PHASE0_QUANTUM__VALUE__SHIFT)) {
422ad8b1aafSjsg 			value = (value + 1) >> 1;
423ad8b1aafSjsg 			unit++;
424ad8b1aafSjsg 		}
425ad8b1aafSjsg 		if (unit > (SDMA0_PHASE0_QUANTUM__UNIT_MASK >>
426ad8b1aafSjsg 			    SDMA0_PHASE0_QUANTUM__UNIT__SHIFT)) {
427ad8b1aafSjsg 			value = (SDMA0_PHASE0_QUANTUM__VALUE_MASK >>
428ad8b1aafSjsg 				 SDMA0_PHASE0_QUANTUM__VALUE__SHIFT);
429ad8b1aafSjsg 			unit = (SDMA0_PHASE0_QUANTUM__UNIT_MASK >>
430ad8b1aafSjsg 				SDMA0_PHASE0_QUANTUM__UNIT__SHIFT);
431ad8b1aafSjsg 			WARN_ONCE(1,
432ad8b1aafSjsg 			"clamping sdma_phase_quantum to %uK clock cycles\n",
433ad8b1aafSjsg 				  value << unit);
434ad8b1aafSjsg 		}
435ad8b1aafSjsg 		phase_quantum =
436ad8b1aafSjsg 			value << SDMA0_PHASE0_QUANTUM__VALUE__SHIFT |
437ad8b1aafSjsg 			unit  << SDMA0_PHASE0_QUANTUM__UNIT__SHIFT;
438ad8b1aafSjsg 	}
439ad8b1aafSjsg 
440ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
441ad8b1aafSjsg 		if (enable && amdgpu_sdma_phase_quantum) {
4425ca02815Sjsg 			WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_PHASE0_QUANTUM),
443ad8b1aafSjsg 			       phase_quantum);
4445ca02815Sjsg 			WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_PHASE1_QUANTUM),
445ad8b1aafSjsg 			       phase_quantum);
4465ca02815Sjsg 			WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_PHASE2_QUANTUM),
447ad8b1aafSjsg 			       phase_quantum);
448ad8b1aafSjsg 		}
4491bb76ff1Sjsg 
4501bb76ff1Sjsg 		if (!amdgpu_sriov_vf(adev)) {
4511bb76ff1Sjsg 			f32_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CNTL));
4521bb76ff1Sjsg 			f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_CNTL,
4531bb76ff1Sjsg 					AUTO_CTXSW_ENABLE, enable ? 1 : 0);
454ad8b1aafSjsg 			WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CNTL), f32_cntl);
455ad8b1aafSjsg 		}
4561bb76ff1Sjsg 	}
457ad8b1aafSjsg 
458ad8b1aafSjsg }
459ad8b1aafSjsg 
460ad8b1aafSjsg /**
461ad8b1aafSjsg  * sdma_v5_2_enable - stop the async dma engines
462ad8b1aafSjsg  *
463ad8b1aafSjsg  * @adev: amdgpu_device pointer
464ad8b1aafSjsg  * @enable: enable/disable the DMA MEs.
465ad8b1aafSjsg  *
466ad8b1aafSjsg  * Halt or unhalt the async dma engines.
467ad8b1aafSjsg  */
sdma_v5_2_enable(struct amdgpu_device * adev,bool enable)468ad8b1aafSjsg static void sdma_v5_2_enable(struct amdgpu_device *adev, bool enable)
469ad8b1aafSjsg {
470ad8b1aafSjsg 	u32 f32_cntl;
471ad8b1aafSjsg 	int i;
472ad8b1aafSjsg 
473ad8b1aafSjsg 	if (!enable) {
474ad8b1aafSjsg 		sdma_v5_2_gfx_stop(adev);
475ad8b1aafSjsg 		sdma_v5_2_rlc_stop(adev);
476ad8b1aafSjsg 	}
477ad8b1aafSjsg 
4781bb76ff1Sjsg 	if (!amdgpu_sriov_vf(adev)) {
479ad8b1aafSjsg 		for (i = 0; i < adev->sdma.num_instances; i++) {
480ad8b1aafSjsg 			f32_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_F32_CNTL));
481ad8b1aafSjsg 			f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, enable ? 0 : 1);
482ad8b1aafSjsg 			WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_F32_CNTL), f32_cntl);
483ad8b1aafSjsg 		}
484ad8b1aafSjsg 	}
4851bb76ff1Sjsg }
486ad8b1aafSjsg 
487ad8b1aafSjsg /**
488ad8b1aafSjsg  * sdma_v5_2_gfx_resume - setup and start the async dma engines
489ad8b1aafSjsg  *
490ad8b1aafSjsg  * @adev: amdgpu_device pointer
491ad8b1aafSjsg  *
492ad8b1aafSjsg  * Set up the gfx DMA ring buffers and enable them.
493ad8b1aafSjsg  * Returns 0 for success, error for failure.
494ad8b1aafSjsg  */
sdma_v5_2_gfx_resume(struct amdgpu_device * adev)495ad8b1aafSjsg static int sdma_v5_2_gfx_resume(struct amdgpu_device *adev)
496ad8b1aafSjsg {
497ad8b1aafSjsg 	struct amdgpu_ring *ring;
498ad8b1aafSjsg 	u32 rb_cntl, ib_cntl;
499ad8b1aafSjsg 	u32 rb_bufsz;
500ad8b1aafSjsg 	u32 doorbell;
501ad8b1aafSjsg 	u32 doorbell_offset;
502ad8b1aafSjsg 	u32 temp;
503ad8b1aafSjsg 	u32 wptr_poll_cntl;
504ad8b1aafSjsg 	u64 wptr_gpu_addr;
505ad8b1aafSjsg 	int i, r;
506ad8b1aafSjsg 
507ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
508ad8b1aafSjsg 		ring = &adev->sdma.instance[i].ring;
509ad8b1aafSjsg 
5101bb76ff1Sjsg 		if (!amdgpu_sriov_vf(adev))
5115ca02815Sjsg 			WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL), 0);
512ad8b1aafSjsg 
513ad8b1aafSjsg 		/* Set ring buffer size in dwords */
514ad8b1aafSjsg 		rb_bufsz = order_base_2(ring->ring_size / 4);
5155ca02815Sjsg 		rb_cntl = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL));
516ad8b1aafSjsg 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SIZE, rb_bufsz);
517ad8b1aafSjsg #ifdef __BIG_ENDIAN
518ad8b1aafSjsg 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SWAP_ENABLE, 1);
519ad8b1aafSjsg 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL,
520ad8b1aafSjsg 					RPTR_WRITEBACK_SWAP_ENABLE, 1);
521ad8b1aafSjsg #endif
5225ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl);
523ad8b1aafSjsg 
524ad8b1aafSjsg 		/* Initialize the ring buffer's read and write pointers */
5255ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_RPTR), 0);
5265ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_RPTR_HI), 0);
5275ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_WPTR), 0);
5285ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_WPTR_HI), 0);
529ad8b1aafSjsg 
530ad8b1aafSjsg 		/* setup the wptr shadow polling */
5311bb76ff1Sjsg 		wptr_gpu_addr = ring->wptr_gpu_addr;
5325ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_LO),
533ad8b1aafSjsg 		       lower_32_bits(wptr_gpu_addr));
5345ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_HI),
535ad8b1aafSjsg 		       upper_32_bits(wptr_gpu_addr));
5365ca02815Sjsg 		wptr_poll_cntl = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i,
537ad8b1aafSjsg 							 mmSDMA0_GFX_RB_WPTR_POLL_CNTL));
538ad8b1aafSjsg 		wptr_poll_cntl = REG_SET_FIELD(wptr_poll_cntl,
539ad8b1aafSjsg 					       SDMA0_GFX_RB_WPTR_POLL_CNTL,
540ad8b1aafSjsg 					       F32_POLL_ENABLE, 1);
5415ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_WPTR_POLL_CNTL),
542ad8b1aafSjsg 		       wptr_poll_cntl);
543ad8b1aafSjsg 
544ad8b1aafSjsg 		/* set the wb address whether it's enabled or not */
5455ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_HI),
5461bb76ff1Sjsg 		       upper_32_bits(ring->rptr_gpu_addr) & 0xFFFFFFFF);
5475ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_RPTR_ADDR_LO),
5481bb76ff1Sjsg 		       lower_32_bits(ring->rptr_gpu_addr) & 0xFFFFFFFC);
549ad8b1aafSjsg 
550ad8b1aafSjsg 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RPTR_WRITEBACK_ENABLE, 1);
551ad8b1aafSjsg 
5525ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_BASE), ring->gpu_addr >> 8);
5535ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_BASE_HI), ring->gpu_addr >> 40);
554ad8b1aafSjsg 
555ad8b1aafSjsg 		ring->wptr = 0;
556ad8b1aafSjsg 
557ad8b1aafSjsg 		/* before programing wptr to a less value, need set minor_ptr_update first */
5585ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE), 1);
559ad8b1aafSjsg 
560ad8b1aafSjsg 		if (!amdgpu_sriov_vf(adev)) { /* only bare-metal use register write for wptr */
5615decb207Sjsg 			WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_WPTR), lower_32_bits(ring->wptr << 2));
5625decb207Sjsg 			WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_WPTR_HI), upper_32_bits(ring->wptr << 2));
563ad8b1aafSjsg 		}
564ad8b1aafSjsg 
5655ca02815Sjsg 		doorbell = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_DOORBELL));
5665ca02815Sjsg 		doorbell_offset = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_DOORBELL_OFFSET));
567ad8b1aafSjsg 
568ad8b1aafSjsg 		if (ring->use_doorbell) {
569ad8b1aafSjsg 			doorbell = REG_SET_FIELD(doorbell, SDMA0_GFX_DOORBELL, ENABLE, 1);
570ad8b1aafSjsg 			doorbell_offset = REG_SET_FIELD(doorbell_offset, SDMA0_GFX_DOORBELL_OFFSET,
571ad8b1aafSjsg 					OFFSET, ring->doorbell_index);
572ad8b1aafSjsg 		} else {
573ad8b1aafSjsg 			doorbell = REG_SET_FIELD(doorbell, SDMA0_GFX_DOORBELL, ENABLE, 0);
574ad8b1aafSjsg 		}
5755ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_DOORBELL), doorbell);
5765ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_DOORBELL_OFFSET), doorbell_offset);
577ad8b1aafSjsg 
578ad8b1aafSjsg 		adev->nbio.funcs->sdma_doorbell_range(adev, i, ring->use_doorbell,
579ad8b1aafSjsg 						      ring->doorbell_index,
580ad8b1aafSjsg 						      adev->doorbell_index.sdma_doorbell_range);
581ad8b1aafSjsg 
582ad8b1aafSjsg 		if (amdgpu_sriov_vf(adev))
583ad8b1aafSjsg 			sdma_v5_2_ring_set_wptr(ring);
584ad8b1aafSjsg 
585ad8b1aafSjsg 		/* set minor_ptr_update to 0 after wptr programed */
5861bb76ff1Sjsg 
5875ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_MINOR_PTR_UPDATE), 0);
588ad8b1aafSjsg 
5891bb76ff1Sjsg 		/* SRIOV VF has no control of any of registers below */
5901bb76ff1Sjsg 		if (!amdgpu_sriov_vf(adev)) {
591ad8b1aafSjsg 			/* set utc l1 enable flag always to 1 */
592ad8b1aafSjsg 			temp = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CNTL));
593ad8b1aafSjsg 			temp = REG_SET_FIELD(temp, SDMA0_CNTL, UTC_L1_ENABLE, 1);
594ad8b1aafSjsg 
595ad8b1aafSjsg 			/* enable MCBP */
596ad8b1aafSjsg 			temp = REG_SET_FIELD(temp, SDMA0_CNTL, MIDCMD_PREEMPT_ENABLE, 1);
597ad8b1aafSjsg 			WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CNTL), temp);
598ad8b1aafSjsg 
599ad8b1aafSjsg 			/* Set up RESP_MODE to non-copy addresses */
6005ca02815Sjsg 			temp = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_UTCL1_CNTL));
601ad8b1aafSjsg 			temp = REG_SET_FIELD(temp, SDMA0_UTCL1_CNTL, RESP_MODE, 3);
602ad8b1aafSjsg 			temp = REG_SET_FIELD(temp, SDMA0_UTCL1_CNTL, REDO_DELAY, 9);
6035ca02815Sjsg 			WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_UTCL1_CNTL), temp);
604ad8b1aafSjsg 
605ad8b1aafSjsg 			/* program default cache read and write policy */
6065ca02815Sjsg 			temp = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_UTCL1_PAGE));
607ad8b1aafSjsg 			/* clean read policy and write policy bits */
608ad8b1aafSjsg 			temp &= 0xFF0FFF;
609ad8b1aafSjsg 			temp |= ((CACHE_READ_POLICY_L2__DEFAULT << 12) |
610ad8b1aafSjsg 				 (CACHE_WRITE_POLICY_L2__DEFAULT << 14) |
6115ca02815Sjsg 				 SDMA0_UTCL1_PAGE__LLC_NOALLOC_MASK);
6125ca02815Sjsg 			WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_UTCL1_PAGE), temp);
613ad8b1aafSjsg 
614ad8b1aafSjsg 			/* unhalt engine */
615ad8b1aafSjsg 			temp = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_F32_CNTL));
616ad8b1aafSjsg 			temp = REG_SET_FIELD(temp, SDMA0_F32_CNTL, HALT, 0);
617ad8b1aafSjsg 			WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_F32_CNTL), temp);
618ad8b1aafSjsg 		}
619ad8b1aafSjsg 
620ad8b1aafSjsg 		/* enable DMA RB */
621ad8b1aafSjsg 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 1);
6225ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl);
623ad8b1aafSjsg 
6245ca02815Sjsg 		ib_cntl = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL));
625ad8b1aafSjsg 		ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 1);
626ad8b1aafSjsg #ifdef __BIG_ENDIAN
627ad8b1aafSjsg 		ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_SWAP_ENABLE, 1);
628ad8b1aafSjsg #endif
629ad8b1aafSjsg 		/* enable DMA IBs */
6305ca02815Sjsg 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl);
631ad8b1aafSjsg 
632ad8b1aafSjsg 		if (amdgpu_sriov_vf(adev)) { /* bare-metal sequence doesn't need below to lines */
633ad8b1aafSjsg 			sdma_v5_2_ctx_switch_enable(adev, true);
634ad8b1aafSjsg 			sdma_v5_2_enable(adev, true);
635ad8b1aafSjsg 		}
636ad8b1aafSjsg 
637f005ef32Sjsg 		r = amdgpu_ring_test_helper(ring);
638f005ef32Sjsg 		if (r)
639ad8b1aafSjsg 			return r;
640ad8b1aafSjsg 
641ad8b1aafSjsg 		if (adev->mman.buffer_funcs_ring == ring)
642ad8b1aafSjsg 			amdgpu_ttm_set_buffer_funcs_status(adev, true);
643ad8b1aafSjsg 	}
644ad8b1aafSjsg 
645ad8b1aafSjsg 	return 0;
646ad8b1aafSjsg }
647ad8b1aafSjsg 
648ad8b1aafSjsg /**
649ad8b1aafSjsg  * sdma_v5_2_rlc_resume - setup and start the async dma engines
650ad8b1aafSjsg  *
651ad8b1aafSjsg  * @adev: amdgpu_device pointer
652ad8b1aafSjsg  *
653ad8b1aafSjsg  * Set up the compute DMA queues and enable them.
654ad8b1aafSjsg  * Returns 0 for success, error for failure.
655ad8b1aafSjsg  */
sdma_v5_2_rlc_resume(struct amdgpu_device * adev)656ad8b1aafSjsg static int sdma_v5_2_rlc_resume(struct amdgpu_device *adev)
657ad8b1aafSjsg {
658ad8b1aafSjsg 	return 0;
659ad8b1aafSjsg }
660ad8b1aafSjsg 
661ad8b1aafSjsg /**
662ad8b1aafSjsg  * sdma_v5_2_load_microcode - load the sDMA ME ucode
663ad8b1aafSjsg  *
664ad8b1aafSjsg  * @adev: amdgpu_device pointer
665ad8b1aafSjsg  *
666ad8b1aafSjsg  * Loads the sDMA0/1/2/3 ucode.
667ad8b1aafSjsg  * Returns 0 for success, -EINVAL if the ucode is not available.
668ad8b1aafSjsg  */
sdma_v5_2_load_microcode(struct amdgpu_device * adev)669ad8b1aafSjsg static int sdma_v5_2_load_microcode(struct amdgpu_device *adev)
670ad8b1aafSjsg {
671ad8b1aafSjsg 	const struct sdma_firmware_header_v1_0 *hdr;
672ad8b1aafSjsg 	const __le32 *fw_data;
673ad8b1aafSjsg 	u32 fw_size;
674ad8b1aafSjsg 	int i, j;
675ad8b1aafSjsg 
676ad8b1aafSjsg 	/* halt the MEs */
677ad8b1aafSjsg 	sdma_v5_2_enable(adev, false);
678ad8b1aafSjsg 
679ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
680ad8b1aafSjsg 		if (!adev->sdma.instance[i].fw)
681ad8b1aafSjsg 			return -EINVAL;
682ad8b1aafSjsg 
683ad8b1aafSjsg 		hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
684ad8b1aafSjsg 		amdgpu_ucode_print_sdma_hdr(&hdr->header);
685ad8b1aafSjsg 		fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
686ad8b1aafSjsg 
687ad8b1aafSjsg 		fw_data = (const __le32 *)
688ad8b1aafSjsg 			(adev->sdma.instance[i].fw->data +
689ad8b1aafSjsg 				le32_to_cpu(hdr->header.ucode_array_offset_bytes));
690ad8b1aafSjsg 
691ad8b1aafSjsg 		WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_UCODE_ADDR), 0);
692ad8b1aafSjsg 
693ad8b1aafSjsg 		for (j = 0; j < fw_size; j++) {
694ad8b1aafSjsg 			if (amdgpu_emu_mode == 1 && j % 500 == 0)
695ad8b1aafSjsg 				drm_msleep(1);
696ad8b1aafSjsg 			WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_UCODE_DATA), le32_to_cpup(fw_data++));
697ad8b1aafSjsg 		}
698ad8b1aafSjsg 
699ad8b1aafSjsg 		WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_UCODE_ADDR), adev->sdma.instance[i].fw_version);
700ad8b1aafSjsg 	}
701ad8b1aafSjsg 
702ad8b1aafSjsg 	return 0;
703ad8b1aafSjsg }
704ad8b1aafSjsg 
sdma_v5_2_soft_reset(void * handle)7055ca02815Sjsg static int sdma_v5_2_soft_reset(void *handle)
7065ca02815Sjsg {
7075ca02815Sjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7085ca02815Sjsg 	u32 grbm_soft_reset;
7095ca02815Sjsg 	u32 tmp;
7105ca02815Sjsg 	int i;
7115ca02815Sjsg 
7125ca02815Sjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
7135ca02815Sjsg 		grbm_soft_reset = REG_SET_FIELD(0,
7145ca02815Sjsg 						GRBM_SOFT_RESET, SOFT_RESET_SDMA0,
7155ca02815Sjsg 						1);
7165ca02815Sjsg 		grbm_soft_reset <<= i;
7175ca02815Sjsg 
7185ca02815Sjsg 		tmp = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
7195ca02815Sjsg 		tmp |= grbm_soft_reset;
7205ca02815Sjsg 		DRM_DEBUG("GRBM_SOFT_RESET=0x%08X\n", tmp);
7215ca02815Sjsg 		WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, tmp);
7225ca02815Sjsg 		tmp = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
7235ca02815Sjsg 
7245ca02815Sjsg 		udelay(50);
7255ca02815Sjsg 
7265ca02815Sjsg 		tmp &= ~grbm_soft_reset;
7275ca02815Sjsg 		WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, tmp);
7285ca02815Sjsg 		tmp = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
7295ca02815Sjsg 
7305ca02815Sjsg 		udelay(50);
7315ca02815Sjsg 	}
7325ca02815Sjsg 
7335ca02815Sjsg 	return 0;
7345ca02815Sjsg }
7355ca02815Sjsg 
736ad8b1aafSjsg /**
737ad8b1aafSjsg  * sdma_v5_2_start - setup and start the async dma engines
738ad8b1aafSjsg  *
739ad8b1aafSjsg  * @adev: amdgpu_device pointer
740ad8b1aafSjsg  *
741ad8b1aafSjsg  * Set up the DMA engines and enable them.
742ad8b1aafSjsg  * Returns 0 for success, error for failure.
743ad8b1aafSjsg  */
sdma_v5_2_start(struct amdgpu_device * adev)744ad8b1aafSjsg static int sdma_v5_2_start(struct amdgpu_device *adev)
745ad8b1aafSjsg {
746ad8b1aafSjsg 	int r = 0;
747ad8b1aafSjsg 
748ad8b1aafSjsg 	if (amdgpu_sriov_vf(adev)) {
749ad8b1aafSjsg 		sdma_v5_2_ctx_switch_enable(adev, false);
750ad8b1aafSjsg 		sdma_v5_2_enable(adev, false);
751ad8b1aafSjsg 
752ad8b1aafSjsg 		/* set RB registers */
753ad8b1aafSjsg 		r = sdma_v5_2_gfx_resume(adev);
754ad8b1aafSjsg 		return r;
755ad8b1aafSjsg 	}
756ad8b1aafSjsg 
757ad8b1aafSjsg 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
758ad8b1aafSjsg 		r = sdma_v5_2_load_microcode(adev);
759ad8b1aafSjsg 		if (r)
760ad8b1aafSjsg 			return r;
761ad8b1aafSjsg 
762ad8b1aafSjsg 		/* The value of mmSDMA_F32_CNTL is invalid the moment after loading fw */
763ad8b1aafSjsg 		if (amdgpu_emu_mode == 1)
764ad8b1aafSjsg 			drm_msleep(1000);
765ad8b1aafSjsg 	}
766ad8b1aafSjsg 
7675ca02815Sjsg 	sdma_v5_2_soft_reset(adev);
768ad8b1aafSjsg 	/* unhalt the MEs */
769ad8b1aafSjsg 	sdma_v5_2_enable(adev, true);
770ad8b1aafSjsg 	/* enable sdma ring preemption */
771ad8b1aafSjsg 	sdma_v5_2_ctx_switch_enable(adev, true);
772ad8b1aafSjsg 
773ad8b1aafSjsg 	/* start the gfx rings and rlc compute queues */
774ad8b1aafSjsg 	r = sdma_v5_2_gfx_resume(adev);
775ad8b1aafSjsg 	if (r)
776ad8b1aafSjsg 		return r;
777ad8b1aafSjsg 	r = sdma_v5_2_rlc_resume(adev);
778ad8b1aafSjsg 
779ad8b1aafSjsg 	return r;
780ad8b1aafSjsg }
781ad8b1aafSjsg 
sdma_v5_2_mqd_init(struct amdgpu_device * adev,void * mqd,struct amdgpu_mqd_prop * prop)7821bb76ff1Sjsg static int sdma_v5_2_mqd_init(struct amdgpu_device *adev, void *mqd,
7831bb76ff1Sjsg 			      struct amdgpu_mqd_prop *prop)
7841bb76ff1Sjsg {
7851bb76ff1Sjsg 	struct v10_sdma_mqd *m = mqd;
7861bb76ff1Sjsg 	uint64_t wb_gpu_addr;
7871bb76ff1Sjsg 
7881bb76ff1Sjsg 	m->sdmax_rlcx_rb_cntl =
7891bb76ff1Sjsg 		order_base_2(prop->queue_size / 4) << SDMA0_RLC0_RB_CNTL__RB_SIZE__SHIFT |
7901bb76ff1Sjsg 		1 << SDMA0_RLC0_RB_CNTL__RPTR_WRITEBACK_ENABLE__SHIFT |
7911bb76ff1Sjsg 		6 << SDMA0_RLC0_RB_CNTL__RPTR_WRITEBACK_TIMER__SHIFT |
7921bb76ff1Sjsg 		1 << SDMA0_RLC0_RB_CNTL__RB_PRIV__SHIFT;
7931bb76ff1Sjsg 
7941bb76ff1Sjsg 	m->sdmax_rlcx_rb_base = lower_32_bits(prop->hqd_base_gpu_addr >> 8);
7951bb76ff1Sjsg 	m->sdmax_rlcx_rb_base_hi = upper_32_bits(prop->hqd_base_gpu_addr >> 8);
7961bb76ff1Sjsg 
7971bb76ff1Sjsg 	m->sdmax_rlcx_rb_wptr_poll_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, 0,
7981bb76ff1Sjsg 						  mmSDMA0_GFX_RB_WPTR_POLL_CNTL));
7991bb76ff1Sjsg 
8001bb76ff1Sjsg 	wb_gpu_addr = prop->wptr_gpu_addr;
8011bb76ff1Sjsg 	m->sdmax_rlcx_rb_wptr_poll_addr_lo = lower_32_bits(wb_gpu_addr);
8021bb76ff1Sjsg 	m->sdmax_rlcx_rb_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr);
8031bb76ff1Sjsg 
8041bb76ff1Sjsg 	wb_gpu_addr = prop->rptr_gpu_addr;
8051bb76ff1Sjsg 	m->sdmax_rlcx_rb_rptr_addr_lo = lower_32_bits(wb_gpu_addr);
8061bb76ff1Sjsg 	m->sdmax_rlcx_rb_rptr_addr_hi = upper_32_bits(wb_gpu_addr);
8071bb76ff1Sjsg 
8081bb76ff1Sjsg 	m->sdmax_rlcx_ib_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, 0,
8091bb76ff1Sjsg 							mmSDMA0_GFX_IB_CNTL));
8101bb76ff1Sjsg 
8111bb76ff1Sjsg 	m->sdmax_rlcx_doorbell_offset =
8121bb76ff1Sjsg 		prop->doorbell_index << SDMA0_RLC0_DOORBELL_OFFSET__OFFSET__SHIFT;
8131bb76ff1Sjsg 
8141bb76ff1Sjsg 	m->sdmax_rlcx_doorbell = REG_SET_FIELD(0, SDMA0_RLC0_DOORBELL, ENABLE, 1);
8151bb76ff1Sjsg 
8161bb76ff1Sjsg 	return 0;
8171bb76ff1Sjsg }
8181bb76ff1Sjsg 
sdma_v5_2_set_mqd_funcs(struct amdgpu_device * adev)8191bb76ff1Sjsg static void sdma_v5_2_set_mqd_funcs(struct amdgpu_device *adev)
8201bb76ff1Sjsg {
8211bb76ff1Sjsg 	adev->mqds[AMDGPU_HW_IP_DMA].mqd_size = sizeof(struct v10_sdma_mqd);
8221bb76ff1Sjsg 	adev->mqds[AMDGPU_HW_IP_DMA].init_mqd = sdma_v5_2_mqd_init;
8231bb76ff1Sjsg }
8241bb76ff1Sjsg 
825ad8b1aafSjsg /**
826ad8b1aafSjsg  * sdma_v5_2_ring_test_ring - simple async dma engine test
827ad8b1aafSjsg  *
828ad8b1aafSjsg  * @ring: amdgpu_ring structure holding ring information
829ad8b1aafSjsg  *
830ad8b1aafSjsg  * Test the DMA engine by writing using it to write an
831ad8b1aafSjsg  * value to memory.
832ad8b1aafSjsg  * Returns 0 for success, error for failure.
833ad8b1aafSjsg  */
sdma_v5_2_ring_test_ring(struct amdgpu_ring * ring)834ad8b1aafSjsg static int sdma_v5_2_ring_test_ring(struct amdgpu_ring *ring)
835ad8b1aafSjsg {
836ad8b1aafSjsg 	struct amdgpu_device *adev = ring->adev;
837ad8b1aafSjsg 	unsigned i;
838ad8b1aafSjsg 	unsigned index;
839ad8b1aafSjsg 	int r;
840ad8b1aafSjsg 	u32 tmp;
841ad8b1aafSjsg 	u64 gpu_addr;
8421bb76ff1Sjsg 	volatile uint32_t *cpu_ptr = NULL;
843ad8b1aafSjsg 
8441bb76ff1Sjsg 	tmp = 0xCAFEDEAD;
8451bb76ff1Sjsg 
8461bb76ff1Sjsg 	if (ring->is_mes_queue) {
8471bb76ff1Sjsg 		uint32_t offset = 0;
8481bb76ff1Sjsg 		offset = amdgpu_mes_ctx_get_offs(ring,
8491bb76ff1Sjsg 					 AMDGPU_MES_CTX_PADDING_OFFS);
8501bb76ff1Sjsg 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
8511bb76ff1Sjsg 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
8521bb76ff1Sjsg 		*cpu_ptr = tmp;
8531bb76ff1Sjsg 	} else {
854ad8b1aafSjsg 		r = amdgpu_device_wb_get(adev, &index);
855ad8b1aafSjsg 		if (r) {
856ad8b1aafSjsg 			dev_err(adev->dev, "(%d) failed to allocate wb slot\n", r);
857ad8b1aafSjsg 			return r;
858ad8b1aafSjsg 		}
859ad8b1aafSjsg 
860ad8b1aafSjsg 		gpu_addr = adev->wb.gpu_addr + (index * 4);
861ad8b1aafSjsg 		adev->wb.wb[index] = cpu_to_le32(tmp);
8621bb76ff1Sjsg 	}
863ad8b1aafSjsg 
8641bb76ff1Sjsg 	r = amdgpu_ring_alloc(ring, 20);
865ad8b1aafSjsg 	if (r) {
866ad8b1aafSjsg 		DRM_ERROR("amdgpu: dma failed to lock ring %d (%d).\n", ring->idx, r);
867ad8b1aafSjsg 		amdgpu_device_wb_free(adev, index);
868ad8b1aafSjsg 		return r;
869ad8b1aafSjsg 	}
870ad8b1aafSjsg 
871ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
872ad8b1aafSjsg 			  SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR));
873ad8b1aafSjsg 	amdgpu_ring_write(ring, lower_32_bits(gpu_addr));
874ad8b1aafSjsg 	amdgpu_ring_write(ring, upper_32_bits(gpu_addr));
875ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(0));
876ad8b1aafSjsg 	amdgpu_ring_write(ring, 0xDEADBEEF);
877ad8b1aafSjsg 	amdgpu_ring_commit(ring);
878ad8b1aafSjsg 
879ad8b1aafSjsg 	for (i = 0; i < adev->usec_timeout; i++) {
8801bb76ff1Sjsg 		if (ring->is_mes_queue)
8811bb76ff1Sjsg 			tmp = le32_to_cpu(*cpu_ptr);
8821bb76ff1Sjsg 		else
883ad8b1aafSjsg 			tmp = le32_to_cpu(adev->wb.wb[index]);
884ad8b1aafSjsg 		if (tmp == 0xDEADBEEF)
885ad8b1aafSjsg 			break;
886ad8b1aafSjsg 		if (amdgpu_emu_mode == 1)
887ad8b1aafSjsg 			drm_msleep(1);
888ad8b1aafSjsg 		else
889ad8b1aafSjsg 			udelay(1);
890ad8b1aafSjsg 	}
891ad8b1aafSjsg 
892ad8b1aafSjsg 	if (i >= adev->usec_timeout)
893ad8b1aafSjsg 		r = -ETIMEDOUT;
894ad8b1aafSjsg 
8951bb76ff1Sjsg 	if (!ring->is_mes_queue)
896ad8b1aafSjsg 		amdgpu_device_wb_free(adev, index);
897ad8b1aafSjsg 
898ad8b1aafSjsg 	return r;
899ad8b1aafSjsg }
900ad8b1aafSjsg 
901ad8b1aafSjsg /**
902ad8b1aafSjsg  * sdma_v5_2_ring_test_ib - test an IB on the DMA engine
903ad8b1aafSjsg  *
904ad8b1aafSjsg  * @ring: amdgpu_ring structure holding ring information
9055ca02815Sjsg  * @timeout: timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT
906ad8b1aafSjsg  *
907ad8b1aafSjsg  * Test a simple IB in the DMA ring.
908ad8b1aafSjsg  * Returns 0 on success, error on failure.
909ad8b1aafSjsg  */
sdma_v5_2_ring_test_ib(struct amdgpu_ring * ring,long timeout)910ad8b1aafSjsg static int sdma_v5_2_ring_test_ib(struct amdgpu_ring *ring, long timeout)
911ad8b1aafSjsg {
912ad8b1aafSjsg 	struct amdgpu_device *adev = ring->adev;
913ad8b1aafSjsg 	struct amdgpu_ib ib;
914ad8b1aafSjsg 	struct dma_fence *f = NULL;
915ad8b1aafSjsg 	unsigned index;
916ad8b1aafSjsg 	long r;
917ad8b1aafSjsg 	u32 tmp = 0;
918ad8b1aafSjsg 	u64 gpu_addr;
9191bb76ff1Sjsg 	volatile uint32_t *cpu_ptr = NULL;
920ad8b1aafSjsg 
9211bb76ff1Sjsg 	tmp = 0xCAFEDEAD;
9221bb76ff1Sjsg 	memset(&ib, 0, sizeof(ib));
9231bb76ff1Sjsg 
9241bb76ff1Sjsg 	if (ring->is_mes_queue) {
9251bb76ff1Sjsg 		uint32_t offset = 0;
9261bb76ff1Sjsg 		offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_IB_OFFS);
9271bb76ff1Sjsg 		ib.gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
9281bb76ff1Sjsg 		ib.ptr = (void *)amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
9291bb76ff1Sjsg 
9301bb76ff1Sjsg 		offset = amdgpu_mes_ctx_get_offs(ring,
9311bb76ff1Sjsg 					 AMDGPU_MES_CTX_PADDING_OFFS);
9321bb76ff1Sjsg 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
9331bb76ff1Sjsg 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
9341bb76ff1Sjsg 		*cpu_ptr = tmp;
9351bb76ff1Sjsg 	} else {
936ad8b1aafSjsg 		r = amdgpu_device_wb_get(adev, &index);
937ad8b1aafSjsg 		if (r) {
938ad8b1aafSjsg 			dev_err(adev->dev, "(%ld) failed to allocate wb slot\n", r);
939ad8b1aafSjsg 			return r;
940ad8b1aafSjsg 		}
941ad8b1aafSjsg 
942ad8b1aafSjsg 		gpu_addr = adev->wb.gpu_addr + (index * 4);
943ad8b1aafSjsg 		adev->wb.wb[index] = cpu_to_le32(tmp);
9441bb76ff1Sjsg 
945ad8b1aafSjsg 		r = amdgpu_ib_get(adev, NULL, 256, AMDGPU_IB_POOL_DIRECT, &ib);
946ad8b1aafSjsg 		if (r) {
947ad8b1aafSjsg 			DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
948ad8b1aafSjsg 			goto err0;
949ad8b1aafSjsg 		}
9501bb76ff1Sjsg 	}
951ad8b1aafSjsg 
952ad8b1aafSjsg 	ib.ptr[0] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
953ad8b1aafSjsg 		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
954ad8b1aafSjsg 	ib.ptr[1] = lower_32_bits(gpu_addr);
955ad8b1aafSjsg 	ib.ptr[2] = upper_32_bits(gpu_addr);
956ad8b1aafSjsg 	ib.ptr[3] = SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(0);
957ad8b1aafSjsg 	ib.ptr[4] = 0xDEADBEEF;
958ad8b1aafSjsg 	ib.ptr[5] = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP);
959ad8b1aafSjsg 	ib.ptr[6] = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP);
960ad8b1aafSjsg 	ib.ptr[7] = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP);
961ad8b1aafSjsg 	ib.length_dw = 8;
962ad8b1aafSjsg 
963ad8b1aafSjsg 	r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
964ad8b1aafSjsg 	if (r)
965ad8b1aafSjsg 		goto err1;
966ad8b1aafSjsg 
967ad8b1aafSjsg 	r = dma_fence_wait_timeout(f, false, timeout);
968ad8b1aafSjsg 	if (r == 0) {
969ad8b1aafSjsg 		DRM_ERROR("amdgpu: IB test timed out\n");
970ad8b1aafSjsg 		r = -ETIMEDOUT;
971ad8b1aafSjsg 		goto err1;
972ad8b1aafSjsg 	} else if (r < 0) {
973ad8b1aafSjsg 		DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
974ad8b1aafSjsg 		goto err1;
975ad8b1aafSjsg 	}
9761bb76ff1Sjsg 
9771bb76ff1Sjsg 	if (ring->is_mes_queue)
9781bb76ff1Sjsg 		tmp = le32_to_cpu(*cpu_ptr);
9791bb76ff1Sjsg 	else
980ad8b1aafSjsg 		tmp = le32_to_cpu(adev->wb.wb[index]);
9811bb76ff1Sjsg 
982ad8b1aafSjsg 	if (tmp == 0xDEADBEEF)
983ad8b1aafSjsg 		r = 0;
984ad8b1aafSjsg 	else
985ad8b1aafSjsg 		r = -EINVAL;
986ad8b1aafSjsg 
987ad8b1aafSjsg err1:
988ad8b1aafSjsg 	amdgpu_ib_free(adev, &ib, NULL);
989ad8b1aafSjsg 	dma_fence_put(f);
990ad8b1aafSjsg err0:
9911bb76ff1Sjsg 	if (!ring->is_mes_queue)
992ad8b1aafSjsg 		amdgpu_device_wb_free(adev, index);
993ad8b1aafSjsg 	return r;
994ad8b1aafSjsg }
995ad8b1aafSjsg 
996ad8b1aafSjsg 
997ad8b1aafSjsg /**
998ad8b1aafSjsg  * sdma_v5_2_vm_copy_pte - update PTEs by copying them from the GART
999ad8b1aafSjsg  *
1000ad8b1aafSjsg  * @ib: indirect buffer to fill with commands
1001ad8b1aafSjsg  * @pe: addr of the page entry
1002ad8b1aafSjsg  * @src: src addr to copy from
1003ad8b1aafSjsg  * @count: number of page entries to update
1004ad8b1aafSjsg  *
1005ad8b1aafSjsg  * Update PTEs by copying them from the GART using sDMA.
1006ad8b1aafSjsg  */
sdma_v5_2_vm_copy_pte(struct amdgpu_ib * ib,uint64_t pe,uint64_t src,unsigned count)1007ad8b1aafSjsg static void sdma_v5_2_vm_copy_pte(struct amdgpu_ib *ib,
1008ad8b1aafSjsg 				  uint64_t pe, uint64_t src,
1009ad8b1aafSjsg 				  unsigned count)
1010ad8b1aafSjsg {
1011ad8b1aafSjsg 	unsigned bytes = count * 8;
1012ad8b1aafSjsg 
1013ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
1014ad8b1aafSjsg 		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
1015ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = bytes - 1;
1016ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
1017ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(src);
1018ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(src);
1019ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
1020ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
1021ad8b1aafSjsg 
1022ad8b1aafSjsg }
1023ad8b1aafSjsg 
1024ad8b1aafSjsg /**
1025ad8b1aafSjsg  * sdma_v5_2_vm_write_pte - update PTEs by writing them manually
1026ad8b1aafSjsg  *
1027ad8b1aafSjsg  * @ib: indirect buffer to fill with commands
1028ad8b1aafSjsg  * @pe: addr of the page entry
10295ca02815Sjsg  * @value: dst addr to write into pe
1030ad8b1aafSjsg  * @count: number of page entries to update
1031ad8b1aafSjsg  * @incr: increase next addr by incr bytes
1032ad8b1aafSjsg  *
1033ad8b1aafSjsg  * Update PTEs by writing them manually using sDMA.
1034ad8b1aafSjsg  */
sdma_v5_2_vm_write_pte(struct amdgpu_ib * ib,uint64_t pe,uint64_t value,unsigned count,uint32_t incr)1035ad8b1aafSjsg static void sdma_v5_2_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
1036ad8b1aafSjsg 				   uint64_t value, unsigned count,
1037ad8b1aafSjsg 				   uint32_t incr)
1038ad8b1aafSjsg {
1039ad8b1aafSjsg 	unsigned ndw = count * 2;
1040ad8b1aafSjsg 
1041ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
1042ad8b1aafSjsg 		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
1043ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
1044ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
1045ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = ndw - 1;
1046ad8b1aafSjsg 	for (; ndw > 0; ndw -= 2) {
1047ad8b1aafSjsg 		ib->ptr[ib->length_dw++] = lower_32_bits(value);
1048ad8b1aafSjsg 		ib->ptr[ib->length_dw++] = upper_32_bits(value);
1049ad8b1aafSjsg 		value += incr;
1050ad8b1aafSjsg 	}
1051ad8b1aafSjsg }
1052ad8b1aafSjsg 
1053ad8b1aafSjsg /**
1054ad8b1aafSjsg  * sdma_v5_2_vm_set_pte_pde - update the page tables using sDMA
1055ad8b1aafSjsg  *
1056ad8b1aafSjsg  * @ib: indirect buffer to fill with commands
1057ad8b1aafSjsg  * @pe: addr of the page entry
1058ad8b1aafSjsg  * @addr: dst addr to write into pe
1059ad8b1aafSjsg  * @count: number of page entries to update
1060ad8b1aafSjsg  * @incr: increase next addr by incr bytes
1061ad8b1aafSjsg  * @flags: access flags
1062ad8b1aafSjsg  *
1063ad8b1aafSjsg  * Update the page tables using sDMA.
1064ad8b1aafSjsg  */
sdma_v5_2_vm_set_pte_pde(struct amdgpu_ib * ib,uint64_t pe,uint64_t addr,unsigned count,uint32_t incr,uint64_t flags)1065ad8b1aafSjsg static void sdma_v5_2_vm_set_pte_pde(struct amdgpu_ib *ib,
1066ad8b1aafSjsg 				     uint64_t pe,
1067ad8b1aafSjsg 				     uint64_t addr, unsigned count,
1068ad8b1aafSjsg 				     uint32_t incr, uint64_t flags)
1069ad8b1aafSjsg {
1070ad8b1aafSjsg 	/* for physically contiguous pages (vram) */
1071ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
1072ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
1073ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
1074ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
1075ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
1076ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
1077ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
1078ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = incr; /* increment size */
1079ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = 0;
1080ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
1081ad8b1aafSjsg }
1082ad8b1aafSjsg 
1083ad8b1aafSjsg /**
1084ad8b1aafSjsg  * sdma_v5_2_ring_pad_ib - pad the IB
1085ad8b1aafSjsg  *
1086ad8b1aafSjsg  * @ib: indirect buffer to fill with padding
10875ca02815Sjsg  * @ring: amdgpu_ring structure holding ring information
1088ad8b1aafSjsg  *
1089ad8b1aafSjsg  * Pad the IB with NOPs to a boundary multiple of 8.
1090ad8b1aafSjsg  */
sdma_v5_2_ring_pad_ib(struct amdgpu_ring * ring,struct amdgpu_ib * ib)1091ad8b1aafSjsg static void sdma_v5_2_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
1092ad8b1aafSjsg {
1093ad8b1aafSjsg 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
1094ad8b1aafSjsg 	u32 pad_count;
1095ad8b1aafSjsg 	int i;
1096ad8b1aafSjsg 
1097ad8b1aafSjsg 	pad_count = (-ib->length_dw) & 0x7;
1098ad8b1aafSjsg 	for (i = 0; i < pad_count; i++)
1099ad8b1aafSjsg 		if (sdma && sdma->burst_nop && (i == 0))
1100ad8b1aafSjsg 			ib->ptr[ib->length_dw++] =
1101ad8b1aafSjsg 				SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
1102ad8b1aafSjsg 				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
1103ad8b1aafSjsg 		else
1104ad8b1aafSjsg 			ib->ptr[ib->length_dw++] =
1105ad8b1aafSjsg 				SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
1106ad8b1aafSjsg }
1107ad8b1aafSjsg 
1108ad8b1aafSjsg 
1109ad8b1aafSjsg /**
1110ad8b1aafSjsg  * sdma_v5_2_ring_emit_pipeline_sync - sync the pipeline
1111ad8b1aafSjsg  *
1112ad8b1aafSjsg  * @ring: amdgpu_ring pointer
1113ad8b1aafSjsg  *
1114ad8b1aafSjsg  * Make sure all previous operations are completed (CIK).
1115ad8b1aafSjsg  */
sdma_v5_2_ring_emit_pipeline_sync(struct amdgpu_ring * ring)1116ad8b1aafSjsg static void sdma_v5_2_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1117ad8b1aafSjsg {
1118ad8b1aafSjsg 	uint32_t seq = ring->fence_drv.sync_seq;
1119ad8b1aafSjsg 	uint64_t addr = ring->fence_drv.gpu_addr;
1120ad8b1aafSjsg 
1121ad8b1aafSjsg 	/* wait for idle */
1122ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
1123ad8b1aafSjsg 			  SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
1124ad8b1aafSjsg 			  SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3) | /* equal */
1125ad8b1aafSjsg 			  SDMA_PKT_POLL_REGMEM_HEADER_MEM_POLL(1));
1126ad8b1aafSjsg 	amdgpu_ring_write(ring, addr & 0xfffffffc);
1127ad8b1aafSjsg 	amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1128ad8b1aafSjsg 	amdgpu_ring_write(ring, seq); /* reference */
1129ad8b1aafSjsg 	amdgpu_ring_write(ring, 0xffffffff); /* mask */
1130ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1131ad8b1aafSjsg 			  SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1132ad8b1aafSjsg }
1133ad8b1aafSjsg 
1134ad8b1aafSjsg 
1135ad8b1aafSjsg /**
1136ad8b1aafSjsg  * sdma_v5_2_ring_emit_vm_flush - vm flush using sDMA
1137ad8b1aafSjsg  *
1138ad8b1aafSjsg  * @ring: amdgpu_ring pointer
11395ca02815Sjsg  * @vmid: vmid number to use
11405ca02815Sjsg  * @pd_addr: address
1141ad8b1aafSjsg  *
1142ad8b1aafSjsg  * Update the page table base and flush the VM TLB
1143ad8b1aafSjsg  * using sDMA.
1144ad8b1aafSjsg  */
sdma_v5_2_ring_emit_vm_flush(struct amdgpu_ring * ring,unsigned vmid,uint64_t pd_addr)1145ad8b1aafSjsg static void sdma_v5_2_ring_emit_vm_flush(struct amdgpu_ring *ring,
1146ad8b1aafSjsg 					 unsigned vmid, uint64_t pd_addr)
1147ad8b1aafSjsg {
1148ad8b1aafSjsg 	amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
1149ad8b1aafSjsg }
1150ad8b1aafSjsg 
sdma_v5_2_ring_emit_wreg(struct amdgpu_ring * ring,uint32_t reg,uint32_t val)1151ad8b1aafSjsg static void sdma_v5_2_ring_emit_wreg(struct amdgpu_ring *ring,
1152ad8b1aafSjsg 				     uint32_t reg, uint32_t val)
1153ad8b1aafSjsg {
1154ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) |
1155ad8b1aafSjsg 			  SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf));
1156ad8b1aafSjsg 	amdgpu_ring_write(ring, reg);
1157ad8b1aafSjsg 	amdgpu_ring_write(ring, val);
1158ad8b1aafSjsg }
1159ad8b1aafSjsg 
sdma_v5_2_ring_emit_reg_wait(struct amdgpu_ring * ring,uint32_t reg,uint32_t val,uint32_t mask)1160ad8b1aafSjsg static void sdma_v5_2_ring_emit_reg_wait(struct amdgpu_ring *ring, uint32_t reg,
1161ad8b1aafSjsg 					 uint32_t val, uint32_t mask)
1162ad8b1aafSjsg {
1163ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
1164ad8b1aafSjsg 			  SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
1165ad8b1aafSjsg 			  SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3)); /* equal */
1166ad8b1aafSjsg 	amdgpu_ring_write(ring, reg << 2);
1167ad8b1aafSjsg 	amdgpu_ring_write(ring, 0);
1168ad8b1aafSjsg 	amdgpu_ring_write(ring, val); /* reference */
1169ad8b1aafSjsg 	amdgpu_ring_write(ring, mask); /* mask */
1170ad8b1aafSjsg 	amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1171ad8b1aafSjsg 			  SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10));
1172ad8b1aafSjsg }
1173ad8b1aafSjsg 
sdma_v5_2_ring_emit_reg_write_reg_wait(struct amdgpu_ring * ring,uint32_t reg0,uint32_t reg1,uint32_t ref,uint32_t mask)1174ad8b1aafSjsg static void sdma_v5_2_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
1175ad8b1aafSjsg 						   uint32_t reg0, uint32_t reg1,
1176ad8b1aafSjsg 						   uint32_t ref, uint32_t mask)
1177ad8b1aafSjsg {
1178ad8b1aafSjsg 	amdgpu_ring_emit_wreg(ring, reg0, ref);
1179ad8b1aafSjsg 	/* wait for a cycle to reset vm_inv_eng*_ack */
1180ad8b1aafSjsg 	amdgpu_ring_emit_reg_wait(ring, reg0, 0, 0);
1181ad8b1aafSjsg 	amdgpu_ring_emit_reg_wait(ring, reg1, mask, mask);
1182ad8b1aafSjsg }
1183ad8b1aafSjsg 
sdma_v5_2_early_init(void * handle)1184ad8b1aafSjsg static int sdma_v5_2_early_init(void *handle)
1185ad8b1aafSjsg {
1186ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1187ad8b1aafSjsg 
1188ad8b1aafSjsg 	sdma_v5_2_set_ring_funcs(adev);
1189ad8b1aafSjsg 	sdma_v5_2_set_buffer_funcs(adev);
1190ad8b1aafSjsg 	sdma_v5_2_set_vm_pte_funcs(adev);
1191ad8b1aafSjsg 	sdma_v5_2_set_irq_funcs(adev);
11921bb76ff1Sjsg 	sdma_v5_2_set_mqd_funcs(adev);
1193ad8b1aafSjsg 
1194ad8b1aafSjsg 	return 0;
1195ad8b1aafSjsg }
1196ad8b1aafSjsg 
sdma_v5_2_seq_to_irq_id(int seq_num)1197ad8b1aafSjsg static unsigned sdma_v5_2_seq_to_irq_id(int seq_num)
1198ad8b1aafSjsg {
1199ad8b1aafSjsg 	switch (seq_num) {
1200ad8b1aafSjsg 	case 0:
1201ad8b1aafSjsg 		return SOC15_IH_CLIENTID_SDMA0;
1202ad8b1aafSjsg 	case 1:
1203ad8b1aafSjsg 		return SOC15_IH_CLIENTID_SDMA1;
1204ad8b1aafSjsg 	case 2:
1205ad8b1aafSjsg 		return SOC15_IH_CLIENTID_SDMA2;
1206ad8b1aafSjsg 	case 3:
1207ad8b1aafSjsg 		return SOC15_IH_CLIENTID_SDMA3_Sienna_Cichlid;
1208ad8b1aafSjsg 	default:
1209ad8b1aafSjsg 		break;
1210ad8b1aafSjsg 	}
1211ad8b1aafSjsg 	return -EINVAL;
1212ad8b1aafSjsg }
1213ad8b1aafSjsg 
sdma_v5_2_seq_to_trap_id(int seq_num)1214ad8b1aafSjsg static unsigned sdma_v5_2_seq_to_trap_id(int seq_num)
1215ad8b1aafSjsg {
1216ad8b1aafSjsg 	switch (seq_num) {
1217ad8b1aafSjsg 	case 0:
1218ad8b1aafSjsg 		return SDMA0_5_0__SRCID__SDMA_TRAP;
1219ad8b1aafSjsg 	case 1:
1220ad8b1aafSjsg 		return SDMA1_5_0__SRCID__SDMA_TRAP;
1221ad8b1aafSjsg 	case 2:
1222ad8b1aafSjsg 		return SDMA2_5_0__SRCID__SDMA_TRAP;
1223ad8b1aafSjsg 	case 3:
1224ad8b1aafSjsg 		return SDMA3_5_0__SRCID__SDMA_TRAP;
1225ad8b1aafSjsg 	default:
1226ad8b1aafSjsg 		break;
1227ad8b1aafSjsg 	}
1228ad8b1aafSjsg 	return -EINVAL;
1229ad8b1aafSjsg }
1230ad8b1aafSjsg 
sdma_v5_2_sw_init(void * handle)1231ad8b1aafSjsg static int sdma_v5_2_sw_init(void *handle)
1232ad8b1aafSjsg {
1233ad8b1aafSjsg 	struct amdgpu_ring *ring;
1234ad8b1aafSjsg 	int r, i;
1235ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1236ad8b1aafSjsg 
1237ad8b1aafSjsg 	/* SDMA trap event */
1238ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
1239ad8b1aafSjsg 		r = amdgpu_irq_add_id(adev, sdma_v5_2_seq_to_irq_id(i),
1240ad8b1aafSjsg 				      sdma_v5_2_seq_to_trap_id(i),
1241ad8b1aafSjsg 				      &adev->sdma.trap_irq);
1242ad8b1aafSjsg 		if (r)
1243ad8b1aafSjsg 			return r;
1244ad8b1aafSjsg 	}
1245ad8b1aafSjsg 
1246f005ef32Sjsg 	r = amdgpu_sdma_init_microcode(adev, 0, true);
1247ad8b1aafSjsg 	if (r) {
1248ad8b1aafSjsg 		DRM_ERROR("Failed to load sdma firmware!\n");
1249ad8b1aafSjsg 		return r;
1250ad8b1aafSjsg 	}
1251ad8b1aafSjsg 
1252ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
1253ad8b1aafSjsg 		ring = &adev->sdma.instance[i].ring;
1254ad8b1aafSjsg 		ring->ring_obj = NULL;
1255ad8b1aafSjsg 		ring->use_doorbell = true;
1256ad8b1aafSjsg 		ring->me = i;
1257ad8b1aafSjsg 
1258ad8b1aafSjsg 		DRM_INFO("use_doorbell being set to: [%s]\n",
1259ad8b1aafSjsg 				ring->use_doorbell?"true":"false");
1260ad8b1aafSjsg 
1261ad8b1aafSjsg 		ring->doorbell_index =
1262ad8b1aafSjsg 			(adev->doorbell_index.sdma_engine[i] << 1); //get DWORD offset
1263ad8b1aafSjsg 
1264f005ef32Sjsg 		ring->vm_hub = AMDGPU_GFXHUB(0);
1265ad8b1aafSjsg 		snprintf(ring->name, sizeof(ring->name), "sdma%d", i);
12665ca02815Sjsg 		r = amdgpu_ring_init(adev, ring, 1024, &adev->sdma.trap_irq,
1267ad8b1aafSjsg 				     AMDGPU_SDMA_IRQ_INSTANCE0 + i,
12685ca02815Sjsg 				     AMDGPU_RING_PRIO_DEFAULT, NULL);
1269ad8b1aafSjsg 		if (r)
1270ad8b1aafSjsg 			return r;
1271ad8b1aafSjsg 	}
1272ad8b1aafSjsg 
1273ad8b1aafSjsg 	return r;
1274ad8b1aafSjsg }
1275ad8b1aafSjsg 
sdma_v5_2_sw_fini(void * handle)1276ad8b1aafSjsg static int sdma_v5_2_sw_fini(void *handle)
1277ad8b1aafSjsg {
1278ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1279ad8b1aafSjsg 	int i;
1280ad8b1aafSjsg 
1281ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++)
1282ad8b1aafSjsg 		amdgpu_ring_fini(&adev->sdma.instance[i].ring);
1283ad8b1aafSjsg 
12841bb76ff1Sjsg 	amdgpu_sdma_destroy_inst_ctx(adev, true);
1285ad8b1aafSjsg 
1286ad8b1aafSjsg 	return 0;
1287ad8b1aafSjsg }
1288ad8b1aafSjsg 
sdma_v5_2_hw_init(void * handle)1289ad8b1aafSjsg static int sdma_v5_2_hw_init(void *handle)
1290ad8b1aafSjsg {
1291ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1292ad8b1aafSjsg 
12931bb76ff1Sjsg 	return sdma_v5_2_start(adev);
1294ad8b1aafSjsg }
1295ad8b1aafSjsg 
sdma_v5_2_hw_fini(void * handle)1296ad8b1aafSjsg static int sdma_v5_2_hw_fini(void *handle)
1297ad8b1aafSjsg {
1298ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1299ad8b1aafSjsg 
13001bb76ff1Sjsg 	if (amdgpu_sriov_vf(adev)) {
13011bb76ff1Sjsg 		/* disable the scheduler for SDMA */
13021bb76ff1Sjsg 		amdgpu_sdma_unset_buffer_funcs_helper(adev);
1303ad8b1aafSjsg 		return 0;
13041bb76ff1Sjsg 	}
1305ad8b1aafSjsg 
1306ad8b1aafSjsg 	sdma_v5_2_ctx_switch_enable(adev, false);
1307ad8b1aafSjsg 	sdma_v5_2_enable(adev, false);
1308ad8b1aafSjsg 
1309ad8b1aafSjsg 	return 0;
1310ad8b1aafSjsg }
1311ad8b1aafSjsg 
sdma_v5_2_suspend(void * handle)1312ad8b1aafSjsg static int sdma_v5_2_suspend(void *handle)
1313ad8b1aafSjsg {
1314ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1315ad8b1aafSjsg 
1316ad8b1aafSjsg 	return sdma_v5_2_hw_fini(adev);
1317ad8b1aafSjsg }
1318ad8b1aafSjsg 
sdma_v5_2_resume(void * handle)1319ad8b1aafSjsg static int sdma_v5_2_resume(void *handle)
1320ad8b1aafSjsg {
1321ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1322ad8b1aafSjsg 
1323ad8b1aafSjsg 	return sdma_v5_2_hw_init(adev);
1324ad8b1aafSjsg }
1325ad8b1aafSjsg 
sdma_v5_2_is_idle(void * handle)1326ad8b1aafSjsg static bool sdma_v5_2_is_idle(void *handle)
1327ad8b1aafSjsg {
1328ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1329ad8b1aafSjsg 	u32 i;
1330ad8b1aafSjsg 
1331ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
1332ad8b1aafSjsg 		u32 tmp = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_STATUS_REG));
1333ad8b1aafSjsg 
1334ad8b1aafSjsg 		if (!(tmp & SDMA0_STATUS_REG__IDLE_MASK))
1335ad8b1aafSjsg 			return false;
1336ad8b1aafSjsg 	}
1337ad8b1aafSjsg 
1338ad8b1aafSjsg 	return true;
1339ad8b1aafSjsg }
1340ad8b1aafSjsg 
sdma_v5_2_wait_for_idle(void * handle)1341ad8b1aafSjsg static int sdma_v5_2_wait_for_idle(void *handle)
1342ad8b1aafSjsg {
1343ad8b1aafSjsg 	unsigned i;
1344ad8b1aafSjsg 	u32 sdma0, sdma1, sdma2, sdma3;
1345ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1346ad8b1aafSjsg 
1347ad8b1aafSjsg 	for (i = 0; i < adev->usec_timeout; i++) {
1348ad8b1aafSjsg 		sdma0 = RREG32(sdma_v5_2_get_reg_offset(adev, 0, mmSDMA0_STATUS_REG));
1349ad8b1aafSjsg 		sdma1 = RREG32(sdma_v5_2_get_reg_offset(adev, 1, mmSDMA0_STATUS_REG));
1350ad8b1aafSjsg 		sdma2 = RREG32(sdma_v5_2_get_reg_offset(adev, 2, mmSDMA0_STATUS_REG));
1351ad8b1aafSjsg 		sdma3 = RREG32(sdma_v5_2_get_reg_offset(adev, 3, mmSDMA0_STATUS_REG));
1352ad8b1aafSjsg 
1353ad8b1aafSjsg 		if (sdma0 & sdma1 & sdma2 & sdma3 & SDMA0_STATUS_REG__IDLE_MASK)
1354ad8b1aafSjsg 			return 0;
1355ad8b1aafSjsg 		udelay(1);
1356ad8b1aafSjsg 	}
1357ad8b1aafSjsg 	return -ETIMEDOUT;
1358ad8b1aafSjsg }
1359ad8b1aafSjsg 
sdma_v5_2_ring_preempt_ib(struct amdgpu_ring * ring)1360ad8b1aafSjsg static int sdma_v5_2_ring_preempt_ib(struct amdgpu_ring *ring)
1361ad8b1aafSjsg {
1362ad8b1aafSjsg 	int i, r = 0;
1363ad8b1aafSjsg 	struct amdgpu_device *adev = ring->adev;
1364ad8b1aafSjsg 	u32 index = 0;
1365ad8b1aafSjsg 	u64 sdma_gfx_preempt;
1366ad8b1aafSjsg 
1367ad8b1aafSjsg 	amdgpu_sdma_get_index_from_ring(ring, &index);
1368ad8b1aafSjsg 	sdma_gfx_preempt =
1369ad8b1aafSjsg 		sdma_v5_2_get_reg_offset(adev, index, mmSDMA0_GFX_PREEMPT);
1370ad8b1aafSjsg 
1371ad8b1aafSjsg 	/* assert preemption condition */
1372ad8b1aafSjsg 	amdgpu_ring_set_preempt_cond_exec(ring, false);
1373ad8b1aafSjsg 
1374ad8b1aafSjsg 	/* emit the trailing fence */
1375ad8b1aafSjsg 	ring->trail_seq += 1;
1376ad8b1aafSjsg 	amdgpu_ring_alloc(ring, 10);
1377ad8b1aafSjsg 	sdma_v5_2_ring_emit_fence(ring, ring->trail_fence_gpu_addr,
1378ad8b1aafSjsg 				  ring->trail_seq, 0);
1379ad8b1aafSjsg 	amdgpu_ring_commit(ring);
1380ad8b1aafSjsg 
1381ad8b1aafSjsg 	/* assert IB preemption */
1382ad8b1aafSjsg 	WREG32(sdma_gfx_preempt, 1);
1383ad8b1aafSjsg 
1384ad8b1aafSjsg 	/* poll the trailing fence */
1385ad8b1aafSjsg 	for (i = 0; i < adev->usec_timeout; i++) {
1386ad8b1aafSjsg 		if (ring->trail_seq ==
1387ad8b1aafSjsg 		    le32_to_cpu(*(ring->trail_fence_cpu_addr)))
1388ad8b1aafSjsg 			break;
1389ad8b1aafSjsg 		udelay(1);
1390ad8b1aafSjsg 	}
1391ad8b1aafSjsg 
1392ad8b1aafSjsg 	if (i >= adev->usec_timeout) {
1393ad8b1aafSjsg 		r = -EINVAL;
1394ad8b1aafSjsg 		DRM_ERROR("ring %d failed to be preempted\n", ring->idx);
1395ad8b1aafSjsg 	}
1396ad8b1aafSjsg 
1397ad8b1aafSjsg 	/* deassert IB preemption */
1398ad8b1aafSjsg 	WREG32(sdma_gfx_preempt, 0);
1399ad8b1aafSjsg 
1400ad8b1aafSjsg 	/* deassert the preemption condition */
1401ad8b1aafSjsg 	amdgpu_ring_set_preempt_cond_exec(ring, true);
1402ad8b1aafSjsg 	return r;
1403ad8b1aafSjsg }
1404ad8b1aafSjsg 
sdma_v5_2_set_trap_irq_state(struct amdgpu_device * adev,struct amdgpu_irq_src * source,unsigned type,enum amdgpu_interrupt_state state)1405ad8b1aafSjsg static int sdma_v5_2_set_trap_irq_state(struct amdgpu_device *adev,
1406ad8b1aafSjsg 					struct amdgpu_irq_src *source,
1407ad8b1aafSjsg 					unsigned type,
1408ad8b1aafSjsg 					enum amdgpu_interrupt_state state)
1409ad8b1aafSjsg {
1410ad8b1aafSjsg 	u32 sdma_cntl;
1411ad8b1aafSjsg 	u32 reg_offset = sdma_v5_2_get_reg_offset(adev, type, mmSDMA0_CNTL);
1412ad8b1aafSjsg 
14131bb76ff1Sjsg 	if (!amdgpu_sriov_vf(adev)) {
1414ad8b1aafSjsg 		sdma_cntl = RREG32(reg_offset);
1415ad8b1aafSjsg 		sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE,
1416ad8b1aafSjsg 			       state == AMDGPU_IRQ_STATE_ENABLE ? 1 : 0);
1417ad8b1aafSjsg 		WREG32(reg_offset, sdma_cntl);
14181bb76ff1Sjsg 	}
1419ad8b1aafSjsg 
1420ad8b1aafSjsg 	return 0;
1421ad8b1aafSjsg }
1422ad8b1aafSjsg 
sdma_v5_2_process_trap_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)1423ad8b1aafSjsg static int sdma_v5_2_process_trap_irq(struct amdgpu_device *adev,
1424ad8b1aafSjsg 				      struct amdgpu_irq_src *source,
1425ad8b1aafSjsg 				      struct amdgpu_iv_entry *entry)
1426ad8b1aafSjsg {
14271bb76ff1Sjsg 	uint32_t mes_queue_id = entry->src_data[0];
14281bb76ff1Sjsg 
1429ad8b1aafSjsg 	DRM_DEBUG("IH: SDMA trap\n");
14301bb76ff1Sjsg 
14311bb76ff1Sjsg 	if (adev->enable_mes && (mes_queue_id & AMDGPU_FENCE_MES_QUEUE_FLAG)) {
14321bb76ff1Sjsg 		struct amdgpu_mes_queue *queue;
14331bb76ff1Sjsg 
14341bb76ff1Sjsg 		mes_queue_id &= AMDGPU_FENCE_MES_QUEUE_ID_MASK;
14351bb76ff1Sjsg 
14361bb76ff1Sjsg 		spin_lock(&adev->mes.queue_id_lock);
14371bb76ff1Sjsg 		queue = idr_find(&adev->mes.queue_id_idr, mes_queue_id);
14381bb76ff1Sjsg 		if (queue) {
14391bb76ff1Sjsg 			DRM_DEBUG("process smda queue id = %d\n", mes_queue_id);
14401bb76ff1Sjsg 			amdgpu_fence_process(queue->ring);
14411bb76ff1Sjsg 		}
14421bb76ff1Sjsg 		spin_unlock(&adev->mes.queue_id_lock);
14431bb76ff1Sjsg 		return 0;
14441bb76ff1Sjsg 	}
14451bb76ff1Sjsg 
1446ad8b1aafSjsg 	switch (entry->client_id) {
1447ad8b1aafSjsg 	case SOC15_IH_CLIENTID_SDMA0:
1448ad8b1aafSjsg 		switch (entry->ring_id) {
1449ad8b1aafSjsg 		case 0:
1450ad8b1aafSjsg 			amdgpu_fence_process(&adev->sdma.instance[0].ring);
1451ad8b1aafSjsg 			break;
1452ad8b1aafSjsg 		case 1:
1453ad8b1aafSjsg 			/* XXX compute */
1454ad8b1aafSjsg 			break;
1455ad8b1aafSjsg 		case 2:
1456ad8b1aafSjsg 			/* XXX compute */
1457ad8b1aafSjsg 			break;
1458ad8b1aafSjsg 		case 3:
1459ad8b1aafSjsg 			/* XXX page queue*/
1460ad8b1aafSjsg 			break;
1461ad8b1aafSjsg 		}
1462ad8b1aafSjsg 		break;
1463ad8b1aafSjsg 	case SOC15_IH_CLIENTID_SDMA1:
1464ad8b1aafSjsg 		switch (entry->ring_id) {
1465ad8b1aafSjsg 		case 0:
1466ad8b1aafSjsg 			amdgpu_fence_process(&adev->sdma.instance[1].ring);
1467ad8b1aafSjsg 			break;
1468ad8b1aafSjsg 		case 1:
1469ad8b1aafSjsg 			/* XXX compute */
1470ad8b1aafSjsg 			break;
1471ad8b1aafSjsg 		case 2:
1472ad8b1aafSjsg 			/* XXX compute */
1473ad8b1aafSjsg 			break;
1474ad8b1aafSjsg 		case 3:
1475ad8b1aafSjsg 			/* XXX page queue*/
1476ad8b1aafSjsg 			break;
1477ad8b1aafSjsg 		}
1478ad8b1aafSjsg 		break;
1479ad8b1aafSjsg 	case SOC15_IH_CLIENTID_SDMA2:
1480ad8b1aafSjsg 		switch (entry->ring_id) {
1481ad8b1aafSjsg 		case 0:
1482ad8b1aafSjsg 			amdgpu_fence_process(&adev->sdma.instance[2].ring);
1483ad8b1aafSjsg 			break;
1484ad8b1aafSjsg 		case 1:
1485ad8b1aafSjsg 			/* XXX compute */
1486ad8b1aafSjsg 			break;
1487ad8b1aafSjsg 		case 2:
1488ad8b1aafSjsg 			/* XXX compute */
1489ad8b1aafSjsg 			break;
1490ad8b1aafSjsg 		case 3:
1491ad8b1aafSjsg 			/* XXX page queue*/
1492ad8b1aafSjsg 			break;
1493ad8b1aafSjsg 		}
1494ad8b1aafSjsg 		break;
1495ad8b1aafSjsg 	case SOC15_IH_CLIENTID_SDMA3_Sienna_Cichlid:
1496ad8b1aafSjsg 		switch (entry->ring_id) {
1497ad8b1aafSjsg 		case 0:
1498ad8b1aafSjsg 			amdgpu_fence_process(&adev->sdma.instance[3].ring);
1499ad8b1aafSjsg 			break;
1500ad8b1aafSjsg 		case 1:
1501ad8b1aafSjsg 			/* XXX compute */
1502ad8b1aafSjsg 			break;
1503ad8b1aafSjsg 		case 2:
1504ad8b1aafSjsg 			/* XXX compute */
1505ad8b1aafSjsg 			break;
1506ad8b1aafSjsg 		case 3:
1507ad8b1aafSjsg 			/* XXX page queue*/
1508ad8b1aafSjsg 			break;
1509ad8b1aafSjsg 		}
1510ad8b1aafSjsg 		break;
1511ad8b1aafSjsg 	}
1512ad8b1aafSjsg 	return 0;
1513ad8b1aafSjsg }
1514ad8b1aafSjsg 
sdma_v5_2_process_illegal_inst_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)1515ad8b1aafSjsg static int sdma_v5_2_process_illegal_inst_irq(struct amdgpu_device *adev,
1516ad8b1aafSjsg 					      struct amdgpu_irq_src *source,
1517ad8b1aafSjsg 					      struct amdgpu_iv_entry *entry)
1518ad8b1aafSjsg {
1519ad8b1aafSjsg 	return 0;
1520ad8b1aafSjsg }
1521ad8b1aafSjsg 
sdma_v5_2_firmware_mgcg_support(struct amdgpu_device * adev,int i)1522f005ef32Sjsg static bool sdma_v5_2_firmware_mgcg_support(struct amdgpu_device *adev,
1523f005ef32Sjsg 						     int i)
1524f005ef32Sjsg {
1525f005ef32Sjsg 	switch (adev->ip_versions[SDMA0_HWIP][0]) {
1526f005ef32Sjsg 	case IP_VERSION(5, 2, 1):
1527f005ef32Sjsg 		if (adev->sdma.instance[i].fw_version < 70)
1528f005ef32Sjsg 			return false;
1529f005ef32Sjsg 		break;
1530f005ef32Sjsg 	case IP_VERSION(5, 2, 3):
1531f005ef32Sjsg 		if (adev->sdma.instance[i].fw_version < 47)
1532f005ef32Sjsg 			return false;
1533f005ef32Sjsg 		break;
1534f005ef32Sjsg 	case IP_VERSION(5, 2, 7):
1535f005ef32Sjsg 		if (adev->sdma.instance[i].fw_version < 9)
1536f005ef32Sjsg 			return false;
1537f005ef32Sjsg 		break;
1538f005ef32Sjsg 	default:
1539f005ef32Sjsg 		return true;
1540f005ef32Sjsg 	}
1541f005ef32Sjsg 
1542f005ef32Sjsg 	return true;
1543f005ef32Sjsg 
1544f005ef32Sjsg }
1545f005ef32Sjsg 
sdma_v5_2_update_medium_grain_clock_gating(struct amdgpu_device * adev,bool enable)1546ad8b1aafSjsg static void sdma_v5_2_update_medium_grain_clock_gating(struct amdgpu_device *adev,
1547ad8b1aafSjsg 						       bool enable)
1548ad8b1aafSjsg {
1549ad8b1aafSjsg 	uint32_t data, def;
1550ad8b1aafSjsg 	int i;
1551ad8b1aafSjsg 
1552ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
15535ca02815Sjsg 
1554f005ef32Sjsg 		if (!sdma_v5_2_firmware_mgcg_support(adev, i))
15555ca02815Sjsg 			adev->cg_flags &= ~AMD_CG_SUPPORT_SDMA_MGCG;
15565ca02815Sjsg 
1557ad8b1aafSjsg 		if (enable && (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG)) {
1558ad8b1aafSjsg 			/* Enable sdma clock gating */
1559ad8b1aafSjsg 			def = data = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CLK_CTRL));
1560ad8b1aafSjsg 			data &= ~(SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1561ad8b1aafSjsg 				  SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1562ad8b1aafSjsg 				  SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1563ad8b1aafSjsg 				  SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1564ad8b1aafSjsg 				  SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK |
1565ad8b1aafSjsg 				  SDMA0_CLK_CTRL__SOFT_OVERRIDER_REG_MASK);
1566ad8b1aafSjsg 			if (def != data)
1567ad8b1aafSjsg 				WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CLK_CTRL), data);
1568ad8b1aafSjsg 		} else {
1569ad8b1aafSjsg 			/* Disable sdma clock gating */
1570ad8b1aafSjsg 			def = data = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CLK_CTRL));
1571ad8b1aafSjsg 			data |= (SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1572ad8b1aafSjsg 				 SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1573ad8b1aafSjsg 				 SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1574ad8b1aafSjsg 				 SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1575ad8b1aafSjsg 				 SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK |
1576ad8b1aafSjsg 				 SDMA0_CLK_CTRL__SOFT_OVERRIDER_REG_MASK);
1577ad8b1aafSjsg 			if (def != data)
1578ad8b1aafSjsg 				WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CLK_CTRL), data);
1579ad8b1aafSjsg 		}
1580ad8b1aafSjsg 	}
1581ad8b1aafSjsg }
1582ad8b1aafSjsg 
sdma_v5_2_update_medium_grain_light_sleep(struct amdgpu_device * adev,bool enable)1583ad8b1aafSjsg static void sdma_v5_2_update_medium_grain_light_sleep(struct amdgpu_device *adev,
1584ad8b1aafSjsg 						      bool enable)
1585ad8b1aafSjsg {
1586ad8b1aafSjsg 	uint32_t data, def;
1587ad8b1aafSjsg 	int i;
1588ad8b1aafSjsg 
1589ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
15905ca02815Sjsg 
15911bb76ff1Sjsg 		if (adev->sdma.instance[i].fw_version < 70 && adev->ip_versions[SDMA0_HWIP][0] == IP_VERSION(5, 2, 1))
15925ca02815Sjsg 			adev->cg_flags &= ~AMD_CG_SUPPORT_SDMA_LS;
15935ca02815Sjsg 
1594ad8b1aafSjsg 		if (enable && (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS)) {
1595ad8b1aafSjsg 			/* Enable sdma mem light sleep */
1596ad8b1aafSjsg 			def = data = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_POWER_CNTL));
1597ad8b1aafSjsg 			data |= SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1598ad8b1aafSjsg 			if (def != data)
1599ad8b1aafSjsg 				WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_POWER_CNTL), data);
1600ad8b1aafSjsg 
1601ad8b1aafSjsg 		} else {
1602ad8b1aafSjsg 			/* Disable sdma mem light sleep */
1603ad8b1aafSjsg 			def = data = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_POWER_CNTL));
1604ad8b1aafSjsg 			data &= ~SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1605ad8b1aafSjsg 			if (def != data)
1606ad8b1aafSjsg 				WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_POWER_CNTL), data);
1607ad8b1aafSjsg 
1608ad8b1aafSjsg 		}
1609ad8b1aafSjsg 	}
1610ad8b1aafSjsg }
1611ad8b1aafSjsg 
sdma_v5_2_set_clockgating_state(void * handle,enum amd_clockgating_state state)1612ad8b1aafSjsg static int sdma_v5_2_set_clockgating_state(void *handle,
1613ad8b1aafSjsg 					   enum amd_clockgating_state state)
1614ad8b1aafSjsg {
1615ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1616ad8b1aafSjsg 
1617ad8b1aafSjsg 	if (amdgpu_sriov_vf(adev))
1618ad8b1aafSjsg 		return 0;
1619ad8b1aafSjsg 
16201bb76ff1Sjsg 	switch (adev->ip_versions[SDMA0_HWIP][0]) {
16211bb76ff1Sjsg 	case IP_VERSION(5, 2, 0):
16221bb76ff1Sjsg 	case IP_VERSION(5, 2, 2):
16231bb76ff1Sjsg 	case IP_VERSION(5, 2, 1):
16241bb76ff1Sjsg 	case IP_VERSION(5, 2, 4):
16251bb76ff1Sjsg 	case IP_VERSION(5, 2, 5):
16261bb76ff1Sjsg 	case IP_VERSION(5, 2, 6):
16271bb76ff1Sjsg 	case IP_VERSION(5, 2, 3):
1628f005ef32Sjsg 	case IP_VERSION(5, 2, 7):
1629ad8b1aafSjsg 		sdma_v5_2_update_medium_grain_clock_gating(adev,
16305ca02815Sjsg 				state == AMD_CG_STATE_GATE);
1631ad8b1aafSjsg 		sdma_v5_2_update_medium_grain_light_sleep(adev,
16325ca02815Sjsg 				state == AMD_CG_STATE_GATE);
1633ad8b1aafSjsg 		break;
1634ad8b1aafSjsg 	default:
1635ad8b1aafSjsg 		break;
1636ad8b1aafSjsg 	}
1637ad8b1aafSjsg 
1638ad8b1aafSjsg 	return 0;
1639ad8b1aafSjsg }
1640ad8b1aafSjsg 
sdma_v5_2_set_powergating_state(void * handle,enum amd_powergating_state state)1641ad8b1aafSjsg static int sdma_v5_2_set_powergating_state(void *handle,
1642ad8b1aafSjsg 					  enum amd_powergating_state state)
1643ad8b1aafSjsg {
1644ad8b1aafSjsg 	return 0;
1645ad8b1aafSjsg }
1646ad8b1aafSjsg 
sdma_v5_2_get_clockgating_state(void * handle,u64 * flags)16471bb76ff1Sjsg static void sdma_v5_2_get_clockgating_state(void *handle, u64 *flags)
1648ad8b1aafSjsg {
1649ad8b1aafSjsg 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1650ad8b1aafSjsg 	int data;
1651ad8b1aafSjsg 
1652ad8b1aafSjsg 	if (amdgpu_sriov_vf(adev))
1653ad8b1aafSjsg 		*flags = 0;
1654ad8b1aafSjsg 
16551bb76ff1Sjsg 	/* AMD_CG_SUPPORT_SDMA_MGCG */
16561bb76ff1Sjsg 	data = RREG32(sdma_v5_2_get_reg_offset(adev, 0, mmSDMA0_CLK_CTRL));
16571bb76ff1Sjsg 	if (!(data & SDMA0_CLK_CTRL__CGCG_EN_OVERRIDE_MASK))
16581bb76ff1Sjsg 		*flags |= AMD_CG_SUPPORT_SDMA_MGCG;
16591bb76ff1Sjsg 
1660ad8b1aafSjsg 	/* AMD_CG_SUPPORT_SDMA_LS */
1661ad8b1aafSjsg 	data = RREG32_KIQ(sdma_v5_2_get_reg_offset(adev, 0, mmSDMA0_POWER_CNTL));
1662ad8b1aafSjsg 	if (data & SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK)
1663ad8b1aafSjsg 		*flags |= AMD_CG_SUPPORT_SDMA_LS;
1664ad8b1aafSjsg }
1665ad8b1aafSjsg 
sdma_v5_2_ring_begin_use(struct amdgpu_ring * ring)166604bcdf75Sjsg static void sdma_v5_2_ring_begin_use(struct amdgpu_ring *ring)
166704bcdf75Sjsg {
166804bcdf75Sjsg 	struct amdgpu_device *adev = ring->adev;
166904bcdf75Sjsg 
167004bcdf75Sjsg 	/* SDMA 5.2.3 (RMB) FW doesn't seem to properly
167104bcdf75Sjsg 	 * disallow GFXOFF in some cases leading to
167204bcdf75Sjsg 	 * hangs in SDMA.  Disallow GFXOFF while SDMA is active.
167304bcdf75Sjsg 	 * We can probably just limit this to 5.2.3,
167404bcdf75Sjsg 	 * but it shouldn't hurt for other parts since
167504bcdf75Sjsg 	 * this GFXOFF will be disallowed anyway when SDMA is
167604bcdf75Sjsg 	 * active, this just makes it explicit.
1677*f61f9b4dSjsg 	 * sdma_v5_2_ring_set_wptr() takes advantage of this
1678*f61f9b4dSjsg 	 * to update the wptr because sometimes SDMA seems to miss
1679*f61f9b4dSjsg 	 * doorbells when entering PG.  If you remove this, update
1680*f61f9b4dSjsg 	 * sdma_v5_2_ring_set_wptr() as well!
168104bcdf75Sjsg 	 */
168204bcdf75Sjsg 	amdgpu_gfx_off_ctrl(adev, false);
168304bcdf75Sjsg }
168404bcdf75Sjsg 
sdma_v5_2_ring_end_use(struct amdgpu_ring * ring)168504bcdf75Sjsg static void sdma_v5_2_ring_end_use(struct amdgpu_ring *ring)
168604bcdf75Sjsg {
168704bcdf75Sjsg 	struct amdgpu_device *adev = ring->adev;
168804bcdf75Sjsg 
168904bcdf75Sjsg 	/* SDMA 5.2.3 (RMB) FW doesn't seem to properly
169004bcdf75Sjsg 	 * disallow GFXOFF in some cases leading to
169104bcdf75Sjsg 	 * hangs in SDMA.  Allow GFXOFF when SDMA is complete.
169204bcdf75Sjsg 	 */
169304bcdf75Sjsg 	amdgpu_gfx_off_ctrl(adev, true);
169404bcdf75Sjsg }
169504bcdf75Sjsg 
1696ad8b1aafSjsg const struct amd_ip_funcs sdma_v5_2_ip_funcs = {
1697ad8b1aafSjsg 	.name = "sdma_v5_2",
1698ad8b1aafSjsg 	.early_init = sdma_v5_2_early_init,
1699ad8b1aafSjsg 	.late_init = NULL,
1700ad8b1aafSjsg 	.sw_init = sdma_v5_2_sw_init,
1701ad8b1aafSjsg 	.sw_fini = sdma_v5_2_sw_fini,
1702ad8b1aafSjsg 	.hw_init = sdma_v5_2_hw_init,
1703ad8b1aafSjsg 	.hw_fini = sdma_v5_2_hw_fini,
1704ad8b1aafSjsg 	.suspend = sdma_v5_2_suspend,
1705ad8b1aafSjsg 	.resume = sdma_v5_2_resume,
1706ad8b1aafSjsg 	.is_idle = sdma_v5_2_is_idle,
1707ad8b1aafSjsg 	.wait_for_idle = sdma_v5_2_wait_for_idle,
1708ad8b1aafSjsg 	.soft_reset = sdma_v5_2_soft_reset,
1709ad8b1aafSjsg 	.set_clockgating_state = sdma_v5_2_set_clockgating_state,
1710ad8b1aafSjsg 	.set_powergating_state = sdma_v5_2_set_powergating_state,
1711ad8b1aafSjsg 	.get_clockgating_state = sdma_v5_2_get_clockgating_state,
1712ad8b1aafSjsg };
1713ad8b1aafSjsg 
1714ad8b1aafSjsg static const struct amdgpu_ring_funcs sdma_v5_2_ring_funcs = {
1715ad8b1aafSjsg 	.type = AMDGPU_RING_TYPE_SDMA,
1716ad8b1aafSjsg 	.align_mask = 0xf,
1717ad8b1aafSjsg 	.nop = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP),
1718ad8b1aafSjsg 	.support_64bit_ptrs = true,
17191bb76ff1Sjsg 	.secure_submission_supported = true,
1720ad8b1aafSjsg 	.get_rptr = sdma_v5_2_ring_get_rptr,
1721ad8b1aafSjsg 	.get_wptr = sdma_v5_2_ring_get_wptr,
1722ad8b1aafSjsg 	.set_wptr = sdma_v5_2_ring_set_wptr,
1723ad8b1aafSjsg 	.emit_frame_size =
1724ad8b1aafSjsg 		5 + /* sdma_v5_2_ring_init_cond_exec */
1725ad8b1aafSjsg 		6 + /* sdma_v5_2_ring_emit_hdp_flush */
1726ad8b1aafSjsg 		3 + /* hdp_invalidate */
1727ad8b1aafSjsg 		6 + /* sdma_v5_2_ring_emit_pipeline_sync */
1728ad8b1aafSjsg 		/* sdma_v5_2_ring_emit_vm_flush */
1729ad8b1aafSjsg 		SOC15_FLUSH_GPU_TLB_NUM_WREG * 3 +
1730ad8b1aafSjsg 		SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 6 +
1731ad8b1aafSjsg 		10 + 10 + 10, /* sdma_v5_2_ring_emit_fence x3 for user fence, vm fence */
1732ad8b1aafSjsg 	.emit_ib_size = 7 + 6, /* sdma_v5_2_ring_emit_ib */
1733ad8b1aafSjsg 	.emit_ib = sdma_v5_2_ring_emit_ib,
17345ca02815Sjsg 	.emit_mem_sync = sdma_v5_2_ring_emit_mem_sync,
1735ad8b1aafSjsg 	.emit_fence = sdma_v5_2_ring_emit_fence,
1736ad8b1aafSjsg 	.emit_pipeline_sync = sdma_v5_2_ring_emit_pipeline_sync,
1737ad8b1aafSjsg 	.emit_vm_flush = sdma_v5_2_ring_emit_vm_flush,
1738ad8b1aafSjsg 	.emit_hdp_flush = sdma_v5_2_ring_emit_hdp_flush,
1739ad8b1aafSjsg 	.test_ring = sdma_v5_2_ring_test_ring,
1740ad8b1aafSjsg 	.test_ib = sdma_v5_2_ring_test_ib,
1741ad8b1aafSjsg 	.insert_nop = sdma_v5_2_ring_insert_nop,
1742ad8b1aafSjsg 	.pad_ib = sdma_v5_2_ring_pad_ib,
174304bcdf75Sjsg 	.begin_use = sdma_v5_2_ring_begin_use,
174404bcdf75Sjsg 	.end_use = sdma_v5_2_ring_end_use,
1745ad8b1aafSjsg 	.emit_wreg = sdma_v5_2_ring_emit_wreg,
1746ad8b1aafSjsg 	.emit_reg_wait = sdma_v5_2_ring_emit_reg_wait,
1747ad8b1aafSjsg 	.emit_reg_write_reg_wait = sdma_v5_2_ring_emit_reg_write_reg_wait,
1748ad8b1aafSjsg 	.init_cond_exec = sdma_v5_2_ring_init_cond_exec,
1749ad8b1aafSjsg 	.patch_cond_exec = sdma_v5_2_ring_patch_cond_exec,
1750ad8b1aafSjsg 	.preempt_ib = sdma_v5_2_ring_preempt_ib,
1751ad8b1aafSjsg };
1752ad8b1aafSjsg 
sdma_v5_2_set_ring_funcs(struct amdgpu_device * adev)1753ad8b1aafSjsg static void sdma_v5_2_set_ring_funcs(struct amdgpu_device *adev)
1754ad8b1aafSjsg {
1755ad8b1aafSjsg 	int i;
1756ad8b1aafSjsg 
1757ad8b1aafSjsg 	for (i = 0; i < adev->sdma.num_instances; i++) {
1758ad8b1aafSjsg 		adev->sdma.instance[i].ring.funcs = &sdma_v5_2_ring_funcs;
1759ad8b1aafSjsg 		adev->sdma.instance[i].ring.me = i;
1760ad8b1aafSjsg 	}
1761ad8b1aafSjsg }
1762ad8b1aafSjsg 
1763ad8b1aafSjsg static const struct amdgpu_irq_src_funcs sdma_v5_2_trap_irq_funcs = {
1764ad8b1aafSjsg 	.set = sdma_v5_2_set_trap_irq_state,
1765ad8b1aafSjsg 	.process = sdma_v5_2_process_trap_irq,
1766ad8b1aafSjsg };
1767ad8b1aafSjsg 
1768ad8b1aafSjsg static const struct amdgpu_irq_src_funcs sdma_v5_2_illegal_inst_irq_funcs = {
1769ad8b1aafSjsg 	.process = sdma_v5_2_process_illegal_inst_irq,
1770ad8b1aafSjsg };
1771ad8b1aafSjsg 
sdma_v5_2_set_irq_funcs(struct amdgpu_device * adev)1772ad8b1aafSjsg static void sdma_v5_2_set_irq_funcs(struct amdgpu_device *adev)
1773ad8b1aafSjsg {
1774ad8b1aafSjsg 	adev->sdma.trap_irq.num_types = AMDGPU_SDMA_IRQ_INSTANCE0 +
1775ad8b1aafSjsg 					adev->sdma.num_instances;
1776ad8b1aafSjsg 	adev->sdma.trap_irq.funcs = &sdma_v5_2_trap_irq_funcs;
1777ad8b1aafSjsg 	adev->sdma.illegal_inst_irq.funcs = &sdma_v5_2_illegal_inst_irq_funcs;
1778ad8b1aafSjsg }
1779ad8b1aafSjsg 
1780ad8b1aafSjsg /**
1781ad8b1aafSjsg  * sdma_v5_2_emit_copy_buffer - copy buffer using the sDMA engine
1782ad8b1aafSjsg  *
17835ca02815Sjsg  * @ib: indirect buffer to copy to
1784ad8b1aafSjsg  * @src_offset: src GPU address
1785ad8b1aafSjsg  * @dst_offset: dst GPU address
1786ad8b1aafSjsg  * @byte_count: number of bytes to xfer
17875ca02815Sjsg  * @tmz: if a secure copy should be used
1788ad8b1aafSjsg  *
1789ad8b1aafSjsg  * Copy GPU buffers using the DMA engine.
1790ad8b1aafSjsg  * Used by the amdgpu ttm implementation to move pages if
1791ad8b1aafSjsg  * registered as the asic copy callback.
1792ad8b1aafSjsg  */
sdma_v5_2_emit_copy_buffer(struct amdgpu_ib * ib,uint64_t src_offset,uint64_t dst_offset,uint32_t byte_count,bool tmz)1793ad8b1aafSjsg static void sdma_v5_2_emit_copy_buffer(struct amdgpu_ib *ib,
1794ad8b1aafSjsg 				       uint64_t src_offset,
1795ad8b1aafSjsg 				       uint64_t dst_offset,
1796ad8b1aafSjsg 				       uint32_t byte_count,
1797ad8b1aafSjsg 				       bool tmz)
1798ad8b1aafSjsg {
1799ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
1800ad8b1aafSjsg 		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
1801ad8b1aafSjsg 		SDMA_PKT_COPY_LINEAR_HEADER_TMZ(tmz ? 1 : 0);
1802ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = byte_count - 1;
1803ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
1804ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
1805ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
1806ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
1807ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
1808ad8b1aafSjsg }
1809ad8b1aafSjsg 
1810ad8b1aafSjsg /**
1811ad8b1aafSjsg  * sdma_v5_2_emit_fill_buffer - fill buffer using the sDMA engine
1812ad8b1aafSjsg  *
18135ca02815Sjsg  * @ib: indirect buffer to fill
1814ad8b1aafSjsg  * @src_data: value to write to buffer
1815ad8b1aafSjsg  * @dst_offset: dst GPU address
1816ad8b1aafSjsg  * @byte_count: number of bytes to xfer
1817ad8b1aafSjsg  *
1818ad8b1aafSjsg  * Fill GPU buffers using the DMA engine.
1819ad8b1aafSjsg  */
sdma_v5_2_emit_fill_buffer(struct amdgpu_ib * ib,uint32_t src_data,uint64_t dst_offset,uint32_t byte_count)1820ad8b1aafSjsg static void sdma_v5_2_emit_fill_buffer(struct amdgpu_ib *ib,
1821ad8b1aafSjsg 				       uint32_t src_data,
1822ad8b1aafSjsg 				       uint64_t dst_offset,
1823ad8b1aafSjsg 				       uint32_t byte_count)
1824ad8b1aafSjsg {
1825ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
1826ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
1827ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
1828ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = src_data;
1829ad8b1aafSjsg 	ib->ptr[ib->length_dw++] = byte_count - 1;
1830ad8b1aafSjsg }
1831ad8b1aafSjsg 
1832ad8b1aafSjsg static const struct amdgpu_buffer_funcs sdma_v5_2_buffer_funcs = {
1833ad8b1aafSjsg 	.copy_max_bytes = 0x400000,
1834ad8b1aafSjsg 	.copy_num_dw = 7,
1835ad8b1aafSjsg 	.emit_copy_buffer = sdma_v5_2_emit_copy_buffer,
1836ad8b1aafSjsg 
1837ad8b1aafSjsg 	.fill_max_bytes = 0x400000,
1838ad8b1aafSjsg 	.fill_num_dw = 5,
1839ad8b1aafSjsg 	.emit_fill_buffer = sdma_v5_2_emit_fill_buffer,
1840ad8b1aafSjsg };
1841ad8b1aafSjsg 
sdma_v5_2_set_buffer_funcs(struct amdgpu_device * adev)1842ad8b1aafSjsg static void sdma_v5_2_set_buffer_funcs(struct amdgpu_device *adev)
1843ad8b1aafSjsg {
1844ad8b1aafSjsg 	if (adev->mman.buffer_funcs == NULL) {
1845ad8b1aafSjsg 		adev->mman.buffer_funcs = &sdma_v5_2_buffer_funcs;
1846ad8b1aafSjsg 		adev->mman.buffer_funcs_ring = &adev->sdma.instance[0].ring;
1847ad8b1aafSjsg 	}
1848ad8b1aafSjsg }
1849ad8b1aafSjsg 
1850ad8b1aafSjsg static const struct amdgpu_vm_pte_funcs sdma_v5_2_vm_pte_funcs = {
1851ad8b1aafSjsg 	.copy_pte_num_dw = 7,
1852ad8b1aafSjsg 	.copy_pte = sdma_v5_2_vm_copy_pte,
1853ad8b1aafSjsg 	.write_pte = sdma_v5_2_vm_write_pte,
1854ad8b1aafSjsg 	.set_pte_pde = sdma_v5_2_vm_set_pte_pde,
1855ad8b1aafSjsg };
1856ad8b1aafSjsg 
sdma_v5_2_set_vm_pte_funcs(struct amdgpu_device * adev)1857ad8b1aafSjsg static void sdma_v5_2_set_vm_pte_funcs(struct amdgpu_device *adev)
1858ad8b1aafSjsg {
1859ad8b1aafSjsg 	unsigned i;
1860ad8b1aafSjsg 
1861ad8b1aafSjsg 	if (adev->vm_manager.vm_pte_funcs == NULL) {
1862ad8b1aafSjsg 		adev->vm_manager.vm_pte_funcs = &sdma_v5_2_vm_pte_funcs;
1863ad8b1aafSjsg 		for (i = 0; i < adev->sdma.num_instances; i++) {
1864ad8b1aafSjsg 			adev->vm_manager.vm_pte_scheds[i] =
1865ad8b1aafSjsg 				&adev->sdma.instance[i].ring.sched;
1866ad8b1aafSjsg 		}
1867ad8b1aafSjsg 		adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances;
1868ad8b1aafSjsg 	}
1869ad8b1aafSjsg }
1870ad8b1aafSjsg 
1871ad8b1aafSjsg const struct amdgpu_ip_block_version sdma_v5_2_ip_block = {
1872ad8b1aafSjsg 	.type = AMD_IP_BLOCK_TYPE_SDMA,
1873ad8b1aafSjsg 	.major = 5,
1874ad8b1aafSjsg 	.minor = 2,
1875ad8b1aafSjsg 	.rev = 0,
1876ad8b1aafSjsg 	.funcs = &sdma_v5_2_ip_funcs,
1877ad8b1aafSjsg };
1878