1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev * Copyright 2014 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev *
4b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
5b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"),
6b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation
7b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the
9b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions:
10b843c749SSergey Zigachev *
11b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in
12b843c749SSergey Zigachev * all copies or substantial portions of the Software.
13b843c749SSergey Zigachev *
14b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE.
21b843c749SSergey Zigachev *
22b843c749SSergey Zigachev * Authors: Alex Deucher
23b843c749SSergey Zigachev */
24b843c749SSergey Zigachev #include <linux/firmware.h>
25b843c749SSergey Zigachev #include <drm/drmP.h>
26b843c749SSergey Zigachev #include "amdgpu.h"
27b843c749SSergey Zigachev #include "amdgpu_ucode.h"
28b843c749SSergey Zigachev #include "amdgpu_trace.h"
29b843c749SSergey Zigachev #include "vi.h"
30b843c749SSergey Zigachev #include "vid.h"
31b843c749SSergey Zigachev
32b843c749SSergey Zigachev #include "oss/oss_2_4_d.h"
33b843c749SSergey Zigachev #include "oss/oss_2_4_sh_mask.h"
34b843c749SSergey Zigachev
35b843c749SSergey Zigachev #include "gmc/gmc_7_1_d.h"
36b843c749SSergey Zigachev #include "gmc/gmc_7_1_sh_mask.h"
37b843c749SSergey Zigachev
38b843c749SSergey Zigachev #include "gca/gfx_8_0_d.h"
39b843c749SSergey Zigachev #include "gca/gfx_8_0_enum.h"
40b843c749SSergey Zigachev #include "gca/gfx_8_0_sh_mask.h"
41b843c749SSergey Zigachev
42b843c749SSergey Zigachev #include "bif/bif_5_0_d.h"
43b843c749SSergey Zigachev #include "bif/bif_5_0_sh_mask.h"
44b843c749SSergey Zigachev
45b843c749SSergey Zigachev #include "iceland_sdma_pkt_open.h"
46b843c749SSergey Zigachev
47b843c749SSergey Zigachev #include "ivsrcid/ivsrcid_vislands30.h"
48b843c749SSergey Zigachev
49b843c749SSergey Zigachev static void sdma_v2_4_set_ring_funcs(struct amdgpu_device *adev);
50b843c749SSergey Zigachev static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev);
51b843c749SSergey Zigachev static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev);
52b843c749SSergey Zigachev static void sdma_v2_4_set_irq_funcs(struct amdgpu_device *adev);
53b843c749SSergey Zigachev
54*809f3802SSergey Zigachev MODULE_FIRMWARE("amdgpufw_topaz_sdma");
55*809f3802SSergey Zigachev MODULE_FIRMWARE("amdgpufw_topaz_sdma1");
56b843c749SSergey Zigachev
57b843c749SSergey Zigachev static const u32 sdma_offsets[SDMA_MAX_INSTANCE] =
58b843c749SSergey Zigachev {
59b843c749SSergey Zigachev SDMA0_REGISTER_OFFSET,
60b843c749SSergey Zigachev SDMA1_REGISTER_OFFSET
61b843c749SSergey Zigachev };
62b843c749SSergey Zigachev
63b843c749SSergey Zigachev static const u32 golden_settings_iceland_a11[] =
64b843c749SSergey Zigachev {
65b843c749SSergey Zigachev mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007,
66b843c749SSergey Zigachev mmSDMA0_CLK_CTRL, 0xff000fff, 0x00000000,
67b843c749SSergey Zigachev mmSDMA1_CHICKEN_BITS, 0xfc910007, 0x00810007,
68b843c749SSergey Zigachev mmSDMA1_CLK_CTRL, 0xff000fff, 0x00000000,
69b843c749SSergey Zigachev };
70b843c749SSergey Zigachev
71b843c749SSergey Zigachev static const u32 iceland_mgcg_cgcg_init[] =
72b843c749SSergey Zigachev {
73b843c749SSergey Zigachev mmSDMA0_CLK_CTRL, 0xff000ff0, 0x00000100,
74b843c749SSergey Zigachev mmSDMA1_CLK_CTRL, 0xff000ff0, 0x00000100
75b843c749SSergey Zigachev };
76b843c749SSergey Zigachev
77b843c749SSergey Zigachev /*
78b843c749SSergey Zigachev * sDMA - System DMA
79b843c749SSergey Zigachev * Starting with CIK, the GPU has new asynchronous
80b843c749SSergey Zigachev * DMA engines. These engines are used for compute
81b843c749SSergey Zigachev * and gfx. There are two DMA engines (SDMA0, SDMA1)
82b843c749SSergey Zigachev * and each one supports 1 ring buffer used for gfx
83b843c749SSergey Zigachev * and 2 queues used for compute.
84b843c749SSergey Zigachev *
85b843c749SSergey Zigachev * The programming model is very similar to the CP
86b843c749SSergey Zigachev * (ring buffer, IBs, etc.), but sDMA has it's own
87b843c749SSergey Zigachev * packet format that is different from the PM4 format
88b843c749SSergey Zigachev * used by the CP. sDMA supports copying data, writing
89b843c749SSergey Zigachev * embedded data, solid fills, and a number of other
90b843c749SSergey Zigachev * things. It also has support for tiling/detiling of
91b843c749SSergey Zigachev * buffers.
92b843c749SSergey Zigachev */
93b843c749SSergey Zigachev
sdma_v2_4_init_golden_registers(struct amdgpu_device * adev)94b843c749SSergey Zigachev static void sdma_v2_4_init_golden_registers(struct amdgpu_device *adev)
95b843c749SSergey Zigachev {
96b843c749SSergey Zigachev switch (adev->asic_type) {
97b843c749SSergey Zigachev case CHIP_TOPAZ:
98b843c749SSergey Zigachev amdgpu_device_program_register_sequence(adev,
99b843c749SSergey Zigachev iceland_mgcg_cgcg_init,
100b843c749SSergey Zigachev ARRAY_SIZE(iceland_mgcg_cgcg_init));
101b843c749SSergey Zigachev amdgpu_device_program_register_sequence(adev,
102b843c749SSergey Zigachev golden_settings_iceland_a11,
103b843c749SSergey Zigachev ARRAY_SIZE(golden_settings_iceland_a11));
104b843c749SSergey Zigachev break;
105b843c749SSergey Zigachev default:
106b843c749SSergey Zigachev break;
107b843c749SSergey Zigachev }
108b843c749SSergey Zigachev }
109b843c749SSergey Zigachev
sdma_v2_4_free_microcode(struct amdgpu_device * adev)110b843c749SSergey Zigachev static void sdma_v2_4_free_microcode(struct amdgpu_device *adev)
111b843c749SSergey Zigachev {
112b843c749SSergey Zigachev int i;
113b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
114b843c749SSergey Zigachev release_firmware(adev->sdma.instance[i].fw);
115b843c749SSergey Zigachev adev->sdma.instance[i].fw = NULL;
116b843c749SSergey Zigachev }
117b843c749SSergey Zigachev }
118b843c749SSergey Zigachev
119b843c749SSergey Zigachev /**
120b843c749SSergey Zigachev * sdma_v2_4_init_microcode - load ucode images from disk
121b843c749SSergey Zigachev *
122b843c749SSergey Zigachev * @adev: amdgpu_device pointer
123b843c749SSergey Zigachev *
124b843c749SSergey Zigachev * Use the firmware interface to load the ucode images into
125b843c749SSergey Zigachev * the driver (not loaded into hw).
126b843c749SSergey Zigachev * Returns 0 on success, error on failure.
127b843c749SSergey Zigachev */
sdma_v2_4_init_microcode(struct amdgpu_device * adev)128b843c749SSergey Zigachev static int sdma_v2_4_init_microcode(struct amdgpu_device *adev)
129b843c749SSergey Zigachev {
130b843c749SSergey Zigachev const char *chip_name;
131b843c749SSergey Zigachev char fw_name[30];
132b843c749SSergey Zigachev int err = 0, i;
133b843c749SSergey Zigachev struct amdgpu_firmware_info *info = NULL;
134b843c749SSergey Zigachev const struct common_firmware_header *header = NULL;
135b843c749SSergey Zigachev const struct sdma_firmware_header_v1_0 *hdr;
136b843c749SSergey Zigachev
137b843c749SSergey Zigachev DRM_DEBUG("\n");
138b843c749SSergey Zigachev
139b843c749SSergey Zigachev switch (adev->asic_type) {
140b843c749SSergey Zigachev case CHIP_TOPAZ:
141b843c749SSergey Zigachev chip_name = "topaz";
142b843c749SSergey Zigachev break;
143b843c749SSergey Zigachev default: BUG();
144b843c749SSergey Zigachev }
145b843c749SSergey Zigachev
146b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
147b843c749SSergey Zigachev if (i == 0)
148*809f3802SSergey Zigachev snprintf(fw_name, sizeof(fw_name), "amdgpufw_%s_sdma", chip_name);
149b843c749SSergey Zigachev else
150*809f3802SSergey Zigachev snprintf(fw_name, sizeof(fw_name), "amdgpufw_%s_sdma1", chip_name);
151b843c749SSergey Zigachev err = request_firmware(&adev->sdma.instance[i].fw, fw_name, adev->dev);
152b843c749SSergey Zigachev if (err)
153b843c749SSergey Zigachev goto out;
154b843c749SSergey Zigachev err = amdgpu_ucode_validate(adev->sdma.instance[i].fw);
155b843c749SSergey Zigachev if (err)
156b843c749SSergey Zigachev goto out;
157b843c749SSergey Zigachev hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
158b843c749SSergey Zigachev adev->sdma.instance[i].fw_version = le32_to_cpu(hdr->header.ucode_version);
159b843c749SSergey Zigachev adev->sdma.instance[i].feature_version = le32_to_cpu(hdr->ucode_feature_version);
160b843c749SSergey Zigachev if (adev->sdma.instance[i].feature_version >= 20)
161b843c749SSergey Zigachev adev->sdma.instance[i].burst_nop = true;
162b843c749SSergey Zigachev
163b843c749SSergey Zigachev if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) {
164b843c749SSergey Zigachev info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i];
165b843c749SSergey Zigachev info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i;
166b843c749SSergey Zigachev info->fw = adev->sdma.instance[i].fw;
167b843c749SSergey Zigachev header = (const struct common_firmware_header *)info->fw->data;
168b843c749SSergey Zigachev adev->firmware.fw_size +=
169b843c749SSergey Zigachev ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
170b843c749SSergey Zigachev }
171b843c749SSergey Zigachev }
172b843c749SSergey Zigachev
173b843c749SSergey Zigachev out:
174b843c749SSergey Zigachev if (err) {
175b843c749SSergey Zigachev pr_err("sdma_v2_4: Failed to load firmware \"%s\"\n", fw_name);
176b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
177b843c749SSergey Zigachev release_firmware(adev->sdma.instance[i].fw);
178b843c749SSergey Zigachev adev->sdma.instance[i].fw = NULL;
179b843c749SSergey Zigachev }
180b843c749SSergey Zigachev }
181b843c749SSergey Zigachev return err;
182b843c749SSergey Zigachev }
183b843c749SSergey Zigachev
184b843c749SSergey Zigachev /**
185b843c749SSergey Zigachev * sdma_v2_4_ring_get_rptr - get the current read pointer
186b843c749SSergey Zigachev *
187b843c749SSergey Zigachev * @ring: amdgpu ring pointer
188b843c749SSergey Zigachev *
189b843c749SSergey Zigachev * Get the current rptr from the hardware (VI+).
190b843c749SSergey Zigachev */
sdma_v2_4_ring_get_rptr(struct amdgpu_ring * ring)191b843c749SSergey Zigachev static uint64_t sdma_v2_4_ring_get_rptr(struct amdgpu_ring *ring)
192b843c749SSergey Zigachev {
193b843c749SSergey Zigachev /* XXX check if swapping is necessary on BE */
194b843c749SSergey Zigachev return ring->adev->wb.wb[ring->rptr_offs] >> 2;
195b843c749SSergey Zigachev }
196b843c749SSergey Zigachev
197b843c749SSergey Zigachev /**
198b843c749SSergey Zigachev * sdma_v2_4_ring_get_wptr - get the current write pointer
199b843c749SSergey Zigachev *
200b843c749SSergey Zigachev * @ring: amdgpu ring pointer
201b843c749SSergey Zigachev *
202b843c749SSergey Zigachev * Get the current wptr from the hardware (VI+).
203b843c749SSergey Zigachev */
sdma_v2_4_ring_get_wptr(struct amdgpu_ring * ring)204b843c749SSergey Zigachev static uint64_t sdma_v2_4_ring_get_wptr(struct amdgpu_ring *ring)
205b843c749SSergey Zigachev {
206b843c749SSergey Zigachev struct amdgpu_device *adev = ring->adev;
207b843c749SSergey Zigachev u32 wptr = RREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[ring->me]) >> 2;
208b843c749SSergey Zigachev
209b843c749SSergey Zigachev return wptr;
210b843c749SSergey Zigachev }
211b843c749SSergey Zigachev
212b843c749SSergey Zigachev /**
213b843c749SSergey Zigachev * sdma_v2_4_ring_set_wptr - commit the write pointer
214b843c749SSergey Zigachev *
215b843c749SSergey Zigachev * @ring: amdgpu ring pointer
216b843c749SSergey Zigachev *
217b843c749SSergey Zigachev * Write the wptr back to the hardware (VI+).
218b843c749SSergey Zigachev */
sdma_v2_4_ring_set_wptr(struct amdgpu_ring * ring)219b843c749SSergey Zigachev static void sdma_v2_4_ring_set_wptr(struct amdgpu_ring *ring)
220b843c749SSergey Zigachev {
221b843c749SSergey Zigachev struct amdgpu_device *adev = ring->adev;
222b843c749SSergey Zigachev
223b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[ring->me], lower_32_bits(ring->wptr) << 2);
224b843c749SSergey Zigachev }
225b843c749SSergey Zigachev
sdma_v2_4_ring_insert_nop(struct amdgpu_ring * ring,uint32_t count)226b843c749SSergey Zigachev static void sdma_v2_4_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)
227b843c749SSergey Zigachev {
228b843c749SSergey Zigachev struct amdgpu_sdma_instance *sdma = amdgpu_get_sdma_instance(ring);
229b843c749SSergey Zigachev int i;
230b843c749SSergey Zigachev
231b843c749SSergey Zigachev for (i = 0; i < count; i++)
232b843c749SSergey Zigachev if (sdma && sdma->burst_nop && (i == 0))
233b843c749SSergey Zigachev amdgpu_ring_write(ring, ring->funcs->nop |
234b843c749SSergey Zigachev SDMA_PKT_NOP_HEADER_COUNT(count - 1));
235b843c749SSergey Zigachev else
236b843c749SSergey Zigachev amdgpu_ring_write(ring, ring->funcs->nop);
237b843c749SSergey Zigachev }
238b843c749SSergey Zigachev
239b843c749SSergey Zigachev /**
240b843c749SSergey Zigachev * sdma_v2_4_ring_emit_ib - Schedule an IB on the DMA engine
241b843c749SSergey Zigachev *
242b843c749SSergey Zigachev * @ring: amdgpu ring pointer
243b843c749SSergey Zigachev * @ib: IB object to schedule
244b843c749SSergey Zigachev *
245b843c749SSergey Zigachev * Schedule an IB in the DMA ring (VI).
246b843c749SSergey Zigachev */
sdma_v2_4_ring_emit_ib(struct amdgpu_ring * ring,struct amdgpu_ib * ib,unsigned vmid,bool ctx_switch)247b843c749SSergey Zigachev static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,
248b843c749SSergey Zigachev struct amdgpu_ib *ib,
249b843c749SSergey Zigachev unsigned vmid, bool ctx_switch)
250b843c749SSergey Zigachev {
251b843c749SSergey Zigachev /* IB packet must end on a 8 DW boundary */
252b843c749SSergey Zigachev sdma_v2_4_ring_insert_nop(ring, (10 - (lower_32_bits(ring->wptr) & 7)) % 8);
253b843c749SSergey Zigachev
254b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_INDIRECT) |
255b843c749SSergey Zigachev SDMA_PKT_INDIRECT_HEADER_VMID(vmid & 0xf));
256b843c749SSergey Zigachev /* base must be 32 byte aligned */
257b843c749SSergey Zigachev amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr) & 0xffffffe0);
258b843c749SSergey Zigachev amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
259b843c749SSergey Zigachev amdgpu_ring_write(ring, ib->length_dw);
260b843c749SSergey Zigachev amdgpu_ring_write(ring, 0);
261b843c749SSergey Zigachev amdgpu_ring_write(ring, 0);
262b843c749SSergey Zigachev
263b843c749SSergey Zigachev }
264b843c749SSergey Zigachev
265b843c749SSergey Zigachev /**
266b843c749SSergey Zigachev * sdma_v2_4_hdp_flush_ring_emit - emit an hdp flush on the DMA ring
267b843c749SSergey Zigachev *
268b843c749SSergey Zigachev * @ring: amdgpu ring pointer
269b843c749SSergey Zigachev *
270b843c749SSergey Zigachev * Emit an hdp flush packet on the requested DMA ring.
271b843c749SSergey Zigachev */
sdma_v2_4_ring_emit_hdp_flush(struct amdgpu_ring * ring)272b843c749SSergey Zigachev static void sdma_v2_4_ring_emit_hdp_flush(struct amdgpu_ring *ring)
273b843c749SSergey Zigachev {
274b843c749SSergey Zigachev u32 ref_and_mask = 0;
275b843c749SSergey Zigachev
276b843c749SSergey Zigachev if (ring->me == 0)
277b843c749SSergey Zigachev ref_and_mask = REG_SET_FIELD(ref_and_mask, GPU_HDP_FLUSH_DONE, SDMA0, 1);
278b843c749SSergey Zigachev else
279b843c749SSergey Zigachev ref_and_mask = REG_SET_FIELD(ref_and_mask, GPU_HDP_FLUSH_DONE, SDMA1, 1);
280b843c749SSergey Zigachev
281b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
282b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(1) |
283b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3)); /* == */
284b843c749SSergey Zigachev amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE << 2);
285b843c749SSergey Zigachev amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ << 2);
286b843c749SSergey Zigachev amdgpu_ring_write(ring, ref_and_mask); /* reference */
287b843c749SSergey Zigachev amdgpu_ring_write(ring, ref_and_mask); /* mask */
288b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
289b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10)); /* retry count, poll interval */
290b843c749SSergey Zigachev }
291b843c749SSergey Zigachev
292b843c749SSergey Zigachev /**
293b843c749SSergey Zigachev * sdma_v2_4_ring_emit_fence - emit a fence on the DMA ring
294b843c749SSergey Zigachev *
295b843c749SSergey Zigachev * @ring: amdgpu ring pointer
296b843c749SSergey Zigachev * @fence: amdgpu fence object
297b843c749SSergey Zigachev *
298b843c749SSergey Zigachev * Add a DMA fence packet to the ring to write
299b843c749SSergey Zigachev * the fence seq number and DMA trap packet to generate
300b843c749SSergey Zigachev * an interrupt if needed (VI).
301b843c749SSergey Zigachev */
sdma_v2_4_ring_emit_fence(struct amdgpu_ring * ring,uint64_t addr,uint64_t seq,unsigned flags)30278973132SSergey Zigachev static void sdma_v2_4_ring_emit_fence(struct amdgpu_ring *ring, uint64_t addr, uint64_t seq,
303b843c749SSergey Zigachev unsigned flags)
304b843c749SSergey Zigachev {
305b843c749SSergey Zigachev bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
306b843c749SSergey Zigachev /* write the fence */
307b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
308b843c749SSergey Zigachev amdgpu_ring_write(ring, lower_32_bits(addr));
309b843c749SSergey Zigachev amdgpu_ring_write(ring, upper_32_bits(addr));
310b843c749SSergey Zigachev amdgpu_ring_write(ring, lower_32_bits(seq));
311b843c749SSergey Zigachev
312b843c749SSergey Zigachev /* optionally write high bits as well */
313b843c749SSergey Zigachev if (write64bit) {
314b843c749SSergey Zigachev addr += 4;
315b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
316b843c749SSergey Zigachev amdgpu_ring_write(ring, lower_32_bits(addr));
317b843c749SSergey Zigachev amdgpu_ring_write(ring, upper_32_bits(addr));
318b843c749SSergey Zigachev amdgpu_ring_write(ring, upper_32_bits(seq));
319b843c749SSergey Zigachev }
320b843c749SSergey Zigachev
321b843c749SSergey Zigachev /* generate an interrupt */
322b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_TRAP));
323b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_TRAP_INT_CONTEXT_INT_CONTEXT(0));
324b843c749SSergey Zigachev }
325b843c749SSergey Zigachev
326b843c749SSergey Zigachev /**
327b843c749SSergey Zigachev * sdma_v2_4_gfx_stop - stop the gfx async dma engines
328b843c749SSergey Zigachev *
329b843c749SSergey Zigachev * @adev: amdgpu_device pointer
330b843c749SSergey Zigachev *
331b843c749SSergey Zigachev * Stop the gfx async dma ring buffers (VI).
332b843c749SSergey Zigachev */
sdma_v2_4_gfx_stop(struct amdgpu_device * adev)333b843c749SSergey Zigachev static void sdma_v2_4_gfx_stop(struct amdgpu_device *adev)
334b843c749SSergey Zigachev {
335b843c749SSergey Zigachev struct amdgpu_ring *sdma0 = &adev->sdma.instance[0].ring;
336b843c749SSergey Zigachev struct amdgpu_ring *sdma1 = &adev->sdma.instance[1].ring;
337b843c749SSergey Zigachev u32 rb_cntl, ib_cntl;
338b843c749SSergey Zigachev int i;
339b843c749SSergey Zigachev
340b843c749SSergey Zigachev if ((adev->mman.buffer_funcs_ring == sdma0) ||
341b843c749SSergey Zigachev (adev->mman.buffer_funcs_ring == sdma1))
342b843c749SSergey Zigachev amdgpu_ttm_set_buffer_funcs_status(adev, false);
343b843c749SSergey Zigachev
344b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
345b843c749SSergey Zigachev rb_cntl = RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]);
346b843c749SSergey Zigachev rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
347b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl);
348b843c749SSergey Zigachev ib_cntl = RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]);
349b843c749SSergey Zigachev ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0);
350b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl);
351b843c749SSergey Zigachev }
352b843c749SSergey Zigachev sdma0->ready = false;
353b843c749SSergey Zigachev sdma1->ready = false;
354b843c749SSergey Zigachev }
355b843c749SSergey Zigachev
356b843c749SSergey Zigachev /**
357b843c749SSergey Zigachev * sdma_v2_4_rlc_stop - stop the compute async dma engines
358b843c749SSergey Zigachev *
359b843c749SSergey Zigachev * @adev: amdgpu_device pointer
360b843c749SSergey Zigachev *
361b843c749SSergey Zigachev * Stop the compute async dma queues (VI).
362b843c749SSergey Zigachev */
sdma_v2_4_rlc_stop(struct amdgpu_device * adev)363b843c749SSergey Zigachev static void sdma_v2_4_rlc_stop(struct amdgpu_device *adev)
364b843c749SSergey Zigachev {
365b843c749SSergey Zigachev /* XXX todo */
366b843c749SSergey Zigachev }
367b843c749SSergey Zigachev
368b843c749SSergey Zigachev /**
369b843c749SSergey Zigachev * sdma_v2_4_enable - stop the async dma engines
370b843c749SSergey Zigachev *
371b843c749SSergey Zigachev * @adev: amdgpu_device pointer
372b843c749SSergey Zigachev * @enable: enable/disable the DMA MEs.
373b843c749SSergey Zigachev *
374b843c749SSergey Zigachev * Halt or unhalt the async dma engines (VI).
375b843c749SSergey Zigachev */
sdma_v2_4_enable(struct amdgpu_device * adev,bool enable)376b843c749SSergey Zigachev static void sdma_v2_4_enable(struct amdgpu_device *adev, bool enable)
377b843c749SSergey Zigachev {
378b843c749SSergey Zigachev u32 f32_cntl;
379b843c749SSergey Zigachev int i;
380b843c749SSergey Zigachev
381b843c749SSergey Zigachev if (!enable) {
382b843c749SSergey Zigachev sdma_v2_4_gfx_stop(adev);
383b843c749SSergey Zigachev sdma_v2_4_rlc_stop(adev);
384b843c749SSergey Zigachev }
385b843c749SSergey Zigachev
386b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
387b843c749SSergey Zigachev f32_cntl = RREG32(mmSDMA0_F32_CNTL + sdma_offsets[i]);
388b843c749SSergey Zigachev if (enable)
389b843c749SSergey Zigachev f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 0);
390b843c749SSergey Zigachev else
391b843c749SSergey Zigachev f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 1);
392b843c749SSergey Zigachev WREG32(mmSDMA0_F32_CNTL + sdma_offsets[i], f32_cntl);
393b843c749SSergey Zigachev }
394b843c749SSergey Zigachev }
395b843c749SSergey Zigachev
396b843c749SSergey Zigachev /**
397b843c749SSergey Zigachev * sdma_v2_4_gfx_resume - setup and start the async dma engines
398b843c749SSergey Zigachev *
399b843c749SSergey Zigachev * @adev: amdgpu_device pointer
400b843c749SSergey Zigachev *
401b843c749SSergey Zigachev * Set up the gfx DMA ring buffers and enable them (VI).
402b843c749SSergey Zigachev * Returns 0 for success, error for failure.
403b843c749SSergey Zigachev */
sdma_v2_4_gfx_resume(struct amdgpu_device * adev)404b843c749SSergey Zigachev static int sdma_v2_4_gfx_resume(struct amdgpu_device *adev)
405b843c749SSergey Zigachev {
406b843c749SSergey Zigachev struct amdgpu_ring *ring;
407b843c749SSergey Zigachev u32 rb_cntl, ib_cntl;
408b843c749SSergey Zigachev u32 rb_bufsz;
409b843c749SSergey Zigachev u32 wb_offset;
410b843c749SSergey Zigachev int i, j, r;
411b843c749SSergey Zigachev
412b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
413b843c749SSergey Zigachev ring = &adev->sdma.instance[i].ring;
414b843c749SSergey Zigachev wb_offset = (ring->rptr_offs * 4);
415b843c749SSergey Zigachev
416b843c749SSergey Zigachev mutex_lock(&adev->srbm_mutex);
417b843c749SSergey Zigachev for (j = 0; j < 16; j++) {
418b843c749SSergey Zigachev vi_srbm_select(adev, 0, 0, 0, j);
419b843c749SSergey Zigachev /* SDMA GFX */
420b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_VIRTUAL_ADDR + sdma_offsets[i], 0);
421b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_APE1_CNTL + sdma_offsets[i], 0);
422b843c749SSergey Zigachev }
423b843c749SSergey Zigachev vi_srbm_select(adev, 0, 0, 0, 0);
424b843c749SSergey Zigachev mutex_unlock(&adev->srbm_mutex);
425b843c749SSergey Zigachev
426b843c749SSergey Zigachev WREG32(mmSDMA0_TILING_CONFIG + sdma_offsets[i],
427b843c749SSergey Zigachev adev->gfx.config.gb_addr_config & 0x70);
428b843c749SSergey Zigachev
429b843c749SSergey Zigachev WREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL + sdma_offsets[i], 0);
430b843c749SSergey Zigachev
431b843c749SSergey Zigachev /* Set ring buffer size in dwords */
432b843c749SSergey Zigachev rb_bufsz = order_base_2(ring->ring_size / 4);
433b843c749SSergey Zigachev rb_cntl = RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]);
434b843c749SSergey Zigachev rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SIZE, rb_bufsz);
435b843c749SSergey Zigachev #ifdef __BIG_ENDIAN
436b843c749SSergey Zigachev rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SWAP_ENABLE, 1);
437b843c749SSergey Zigachev rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL,
438b843c749SSergey Zigachev RPTR_WRITEBACK_SWAP_ENABLE, 1);
439b843c749SSergey Zigachev #endif
440b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl);
441b843c749SSergey Zigachev
442b843c749SSergey Zigachev /* Initialize the ring buffer's read and write pointers */
443b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i], 0);
444b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], 0);
445b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_IB_RPTR + sdma_offsets[i], 0);
446b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_IB_OFFSET + sdma_offsets[i], 0);
447b843c749SSergey Zigachev
448b843c749SSergey Zigachev /* set the wb address whether it's enabled or not */
449b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i],
450b843c749SSergey Zigachev upper_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFF);
451b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO + sdma_offsets[i],
452b843c749SSergey Zigachev lower_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC);
453b843c749SSergey Zigachev
454b843c749SSergey Zigachev rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RPTR_WRITEBACK_ENABLE, 1);
455b843c749SSergey Zigachev
456b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_BASE + sdma_offsets[i], ring->gpu_addr >> 8);
457b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_BASE_HI + sdma_offsets[i], ring->gpu_addr >> 40);
458b843c749SSergey Zigachev
459b843c749SSergey Zigachev ring->wptr = 0;
460b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], lower_32_bits(ring->wptr) << 2);
461b843c749SSergey Zigachev
462b843c749SSergey Zigachev /* enable DMA RB */
463b843c749SSergey Zigachev rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 1);
464b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl);
465b843c749SSergey Zigachev
466b843c749SSergey Zigachev ib_cntl = RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]);
467b843c749SSergey Zigachev ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 1);
468b843c749SSergey Zigachev #ifdef __BIG_ENDIAN
469b843c749SSergey Zigachev ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_SWAP_ENABLE, 1);
470b843c749SSergey Zigachev #endif
471b843c749SSergey Zigachev /* enable DMA IBs */
472b843c749SSergey Zigachev WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl);
473b843c749SSergey Zigachev
474b843c749SSergey Zigachev ring->ready = true;
475b843c749SSergey Zigachev }
476b843c749SSergey Zigachev
477b843c749SSergey Zigachev sdma_v2_4_enable(adev, true);
478b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
479b843c749SSergey Zigachev ring = &adev->sdma.instance[i].ring;
480b843c749SSergey Zigachev r = amdgpu_ring_test_ring(ring);
481b843c749SSergey Zigachev if (r) {
482b843c749SSergey Zigachev ring->ready = false;
483b843c749SSergey Zigachev return r;
484b843c749SSergey Zigachev }
485b843c749SSergey Zigachev
486b843c749SSergey Zigachev if (adev->mman.buffer_funcs_ring == ring)
487b843c749SSergey Zigachev amdgpu_ttm_set_buffer_funcs_status(adev, true);
488b843c749SSergey Zigachev }
489b843c749SSergey Zigachev
490b843c749SSergey Zigachev return 0;
491b843c749SSergey Zigachev }
492b843c749SSergey Zigachev
493b843c749SSergey Zigachev /**
494b843c749SSergey Zigachev * sdma_v2_4_rlc_resume - setup and start the async dma engines
495b843c749SSergey Zigachev *
496b843c749SSergey Zigachev * @adev: amdgpu_device pointer
497b843c749SSergey Zigachev *
498b843c749SSergey Zigachev * Set up the compute DMA queues and enable them (VI).
499b843c749SSergey Zigachev * Returns 0 for success, error for failure.
500b843c749SSergey Zigachev */
sdma_v2_4_rlc_resume(struct amdgpu_device * adev)501b843c749SSergey Zigachev static int sdma_v2_4_rlc_resume(struct amdgpu_device *adev)
502b843c749SSergey Zigachev {
503b843c749SSergey Zigachev /* XXX todo */
504b843c749SSergey Zigachev return 0;
505b843c749SSergey Zigachev }
506b843c749SSergey Zigachev
507b843c749SSergey Zigachev /**
508b843c749SSergey Zigachev * sdma_v2_4_load_microcode - load the sDMA ME ucode
509b843c749SSergey Zigachev *
510b843c749SSergey Zigachev * @adev: amdgpu_device pointer
511b843c749SSergey Zigachev *
512b843c749SSergey Zigachev * Loads the sDMA0/1 ucode.
513b843c749SSergey Zigachev * Returns 0 for success, -EINVAL if the ucode is not available.
514b843c749SSergey Zigachev */
sdma_v2_4_load_microcode(struct amdgpu_device * adev)515b843c749SSergey Zigachev static int sdma_v2_4_load_microcode(struct amdgpu_device *adev)
516b843c749SSergey Zigachev {
517b843c749SSergey Zigachev const struct sdma_firmware_header_v1_0 *hdr;
518b843c749SSergey Zigachev const __le32 *fw_data;
519b843c749SSergey Zigachev u32 fw_size;
520b843c749SSergey Zigachev int i, j;
521b843c749SSergey Zigachev
522b843c749SSergey Zigachev /* halt the MEs */
523b843c749SSergey Zigachev sdma_v2_4_enable(adev, false);
524b843c749SSergey Zigachev
525b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
526b843c749SSergey Zigachev if (!adev->sdma.instance[i].fw)
527b843c749SSergey Zigachev return -EINVAL;
528b843c749SSergey Zigachev hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
529b843c749SSergey Zigachev amdgpu_ucode_print_sdma_hdr(&hdr->header);
530b843c749SSergey Zigachev fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
531b843c749SSergey Zigachev fw_data = (const __le32 *)
532b843c749SSergey Zigachev (adev->sdma.instance[i].fw->data +
533b843c749SSergey Zigachev le32_to_cpu(hdr->header.ucode_array_offset_bytes));
534b843c749SSergey Zigachev WREG32(mmSDMA0_UCODE_ADDR + sdma_offsets[i], 0);
535b843c749SSergey Zigachev for (j = 0; j < fw_size; j++)
536b843c749SSergey Zigachev WREG32(mmSDMA0_UCODE_DATA + sdma_offsets[i], le32_to_cpup(fw_data++));
537b843c749SSergey Zigachev WREG32(mmSDMA0_UCODE_ADDR + sdma_offsets[i], adev->sdma.instance[i].fw_version);
538b843c749SSergey Zigachev }
539b843c749SSergey Zigachev
540b843c749SSergey Zigachev return 0;
541b843c749SSergey Zigachev }
542b843c749SSergey Zigachev
543b843c749SSergey Zigachev /**
544b843c749SSergey Zigachev * sdma_v2_4_start - setup and start the async dma engines
545b843c749SSergey Zigachev *
546b843c749SSergey Zigachev * @adev: amdgpu_device pointer
547b843c749SSergey Zigachev *
548b843c749SSergey Zigachev * Set up the DMA engines and enable them (VI).
549b843c749SSergey Zigachev * Returns 0 for success, error for failure.
550b843c749SSergey Zigachev */
sdma_v2_4_start(struct amdgpu_device * adev)551b843c749SSergey Zigachev static int sdma_v2_4_start(struct amdgpu_device *adev)
552b843c749SSergey Zigachev {
553b843c749SSergey Zigachev int r;
554b843c749SSergey Zigachev
555b843c749SSergey Zigachev
556b843c749SSergey Zigachev if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
557b843c749SSergey Zigachev r = sdma_v2_4_load_microcode(adev);
558b843c749SSergey Zigachev if (r)
559b843c749SSergey Zigachev return r;
560b843c749SSergey Zigachev }
561b843c749SSergey Zigachev
562b843c749SSergey Zigachev /* halt the engine before programing */
563b843c749SSergey Zigachev sdma_v2_4_enable(adev, false);
564b843c749SSergey Zigachev
565b843c749SSergey Zigachev /* start the gfx rings and rlc compute queues */
566b843c749SSergey Zigachev r = sdma_v2_4_gfx_resume(adev);
567b843c749SSergey Zigachev if (r)
568b843c749SSergey Zigachev return r;
569b843c749SSergey Zigachev r = sdma_v2_4_rlc_resume(adev);
570b843c749SSergey Zigachev if (r)
571b843c749SSergey Zigachev return r;
572b843c749SSergey Zigachev
573b843c749SSergey Zigachev return 0;
574b843c749SSergey Zigachev }
575b843c749SSergey Zigachev
576b843c749SSergey Zigachev /**
577b843c749SSergey Zigachev * sdma_v2_4_ring_test_ring - simple async dma engine test
578b843c749SSergey Zigachev *
579b843c749SSergey Zigachev * @ring: amdgpu_ring structure holding ring information
580b843c749SSergey Zigachev *
581b843c749SSergey Zigachev * Test the DMA engine by writing using it to write an
582b843c749SSergey Zigachev * value to memory. (VI).
583b843c749SSergey Zigachev * Returns 0 for success, error for failure.
584b843c749SSergey Zigachev */
sdma_v2_4_ring_test_ring(struct amdgpu_ring * ring)585b843c749SSergey Zigachev static int sdma_v2_4_ring_test_ring(struct amdgpu_ring *ring)
586b843c749SSergey Zigachev {
587b843c749SSergey Zigachev struct amdgpu_device *adev = ring->adev;
588b843c749SSergey Zigachev unsigned i;
589b843c749SSergey Zigachev unsigned index;
590b843c749SSergey Zigachev int r;
591b843c749SSergey Zigachev u32 tmp;
592b843c749SSergey Zigachev u64 gpu_addr;
593b843c749SSergey Zigachev
594b843c749SSergey Zigachev r = amdgpu_device_wb_get(adev, &index);
595b843c749SSergey Zigachev if (r) {
596b843c749SSergey Zigachev dev_err(adev->dev, "(%d) failed to allocate wb slot\n", r);
597b843c749SSergey Zigachev return r;
598b843c749SSergey Zigachev }
599b843c749SSergey Zigachev
600b843c749SSergey Zigachev gpu_addr = adev->wb.gpu_addr + (index * 4);
601b843c749SSergey Zigachev tmp = 0xCAFEDEAD;
602b843c749SSergey Zigachev adev->wb.wb[index] = cpu_to_le32(tmp);
603b843c749SSergey Zigachev
604b843c749SSergey Zigachev r = amdgpu_ring_alloc(ring, 5);
605b843c749SSergey Zigachev if (r) {
606b843c749SSergey Zigachev DRM_ERROR("amdgpu: dma failed to lock ring %d (%d).\n", ring->idx, r);
607b843c749SSergey Zigachev amdgpu_device_wb_free(adev, index);
608b843c749SSergey Zigachev return r;
609b843c749SSergey Zigachev }
610b843c749SSergey Zigachev
611b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
612b843c749SSergey Zigachev SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR));
613b843c749SSergey Zigachev amdgpu_ring_write(ring, lower_32_bits(gpu_addr));
614b843c749SSergey Zigachev amdgpu_ring_write(ring, upper_32_bits(gpu_addr));
615b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(1));
616b843c749SSergey Zigachev amdgpu_ring_write(ring, 0xDEADBEEF);
617b843c749SSergey Zigachev amdgpu_ring_commit(ring);
618b843c749SSergey Zigachev
619b843c749SSergey Zigachev for (i = 0; i < adev->usec_timeout; i++) {
620b843c749SSergey Zigachev tmp = le32_to_cpu(adev->wb.wb[index]);
621b843c749SSergey Zigachev if (tmp == 0xDEADBEEF)
622b843c749SSergey Zigachev break;
623b843c749SSergey Zigachev DRM_UDELAY(1);
624b843c749SSergey Zigachev }
625b843c749SSergey Zigachev
626b843c749SSergey Zigachev if (i < adev->usec_timeout) {
627b843c749SSergey Zigachev DRM_DEBUG("ring test on %d succeeded in %d usecs\n", ring->idx, i);
628b843c749SSergey Zigachev } else {
629b843c749SSergey Zigachev DRM_ERROR("amdgpu: ring %d test failed (0x%08X)\n",
630b843c749SSergey Zigachev ring->idx, tmp);
631b843c749SSergey Zigachev r = -EINVAL;
632b843c749SSergey Zigachev }
633b843c749SSergey Zigachev amdgpu_device_wb_free(adev, index);
634b843c749SSergey Zigachev
635b843c749SSergey Zigachev return r;
636b843c749SSergey Zigachev }
637b843c749SSergey Zigachev
638b843c749SSergey Zigachev /**
639b843c749SSergey Zigachev * sdma_v2_4_ring_test_ib - test an IB on the DMA engine
640b843c749SSergey Zigachev *
641b843c749SSergey Zigachev * @ring: amdgpu_ring structure holding ring information
642b843c749SSergey Zigachev *
643b843c749SSergey Zigachev * Test a simple IB in the DMA ring (VI).
644b843c749SSergey Zigachev * Returns 0 on success, error on failure.
645b843c749SSergey Zigachev */
sdma_v2_4_ring_test_ib(struct amdgpu_ring * ring,long timeout)646b843c749SSergey Zigachev static int sdma_v2_4_ring_test_ib(struct amdgpu_ring *ring, long timeout)
647b843c749SSergey Zigachev {
648b843c749SSergey Zigachev struct amdgpu_device *adev = ring->adev;
649b843c749SSergey Zigachev struct amdgpu_ib ib;
650b843c749SSergey Zigachev struct dma_fence *f = NULL;
651b843c749SSergey Zigachev unsigned index;
652b843c749SSergey Zigachev u32 tmp = 0;
653b843c749SSergey Zigachev u64 gpu_addr;
654b843c749SSergey Zigachev long r;
655b843c749SSergey Zigachev
656b843c749SSergey Zigachev r = amdgpu_device_wb_get(adev, &index);
657b843c749SSergey Zigachev if (r) {
658b843c749SSergey Zigachev dev_err(adev->dev, "(%ld) failed to allocate wb slot\n", r);
659b843c749SSergey Zigachev return r;
660b843c749SSergey Zigachev }
661b843c749SSergey Zigachev
662b843c749SSergey Zigachev gpu_addr = adev->wb.gpu_addr + (index * 4);
663b843c749SSergey Zigachev tmp = 0xCAFEDEAD;
664b843c749SSergey Zigachev adev->wb.wb[index] = cpu_to_le32(tmp);
665b843c749SSergey Zigachev memset(&ib, 0, sizeof(ib));
666b843c749SSergey Zigachev r = amdgpu_ib_get(adev, NULL, 256, &ib);
667b843c749SSergey Zigachev if (r) {
668b843c749SSergey Zigachev DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
669b843c749SSergey Zigachev goto err0;
670b843c749SSergey Zigachev }
671b843c749SSergey Zigachev
672b843c749SSergey Zigachev ib.ptr[0] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
673b843c749SSergey Zigachev SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
674b843c749SSergey Zigachev ib.ptr[1] = lower_32_bits(gpu_addr);
675b843c749SSergey Zigachev ib.ptr[2] = upper_32_bits(gpu_addr);
676b843c749SSergey Zigachev ib.ptr[3] = SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(1);
677b843c749SSergey Zigachev ib.ptr[4] = 0xDEADBEEF;
678b843c749SSergey Zigachev ib.ptr[5] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
679b843c749SSergey Zigachev ib.ptr[6] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
680b843c749SSergey Zigachev ib.ptr[7] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
681b843c749SSergey Zigachev ib.length_dw = 8;
682b843c749SSergey Zigachev
683b843c749SSergey Zigachev r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
684b843c749SSergey Zigachev if (r)
685b843c749SSergey Zigachev goto err1;
686b843c749SSergey Zigachev
687b843c749SSergey Zigachev r = dma_fence_wait_timeout(f, false, timeout);
688b843c749SSergey Zigachev if (r == 0) {
689b843c749SSergey Zigachev DRM_ERROR("amdgpu: IB test timed out\n");
690b843c749SSergey Zigachev r = -ETIMEDOUT;
691b843c749SSergey Zigachev goto err1;
692b843c749SSergey Zigachev } else if (r < 0) {
693b843c749SSergey Zigachev DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
694b843c749SSergey Zigachev goto err1;
695b843c749SSergey Zigachev }
696b843c749SSergey Zigachev tmp = le32_to_cpu(adev->wb.wb[index]);
697b843c749SSergey Zigachev if (tmp == 0xDEADBEEF) {
698b843c749SSergey Zigachev DRM_DEBUG("ib test on ring %d succeeded\n", ring->idx);
699b843c749SSergey Zigachev r = 0;
700b843c749SSergey Zigachev } else {
701b843c749SSergey Zigachev DRM_ERROR("amdgpu: ib test failed (0x%08X)\n", tmp);
702b843c749SSergey Zigachev r = -EINVAL;
703b843c749SSergey Zigachev }
704b843c749SSergey Zigachev
705b843c749SSergey Zigachev err1:
706b843c749SSergey Zigachev amdgpu_ib_free(adev, &ib, NULL);
707b843c749SSergey Zigachev dma_fence_put(f);
708b843c749SSergey Zigachev err0:
709b843c749SSergey Zigachev amdgpu_device_wb_free(adev, index);
710b843c749SSergey Zigachev return r;
711b843c749SSergey Zigachev }
712b843c749SSergey Zigachev
713b843c749SSergey Zigachev /**
714b843c749SSergey Zigachev * sdma_v2_4_vm_copy_pte - update PTEs by copying them from the GART
715b843c749SSergey Zigachev *
716b843c749SSergey Zigachev * @ib: indirect buffer to fill with commands
717b843c749SSergey Zigachev * @pe: addr of the page entry
718b843c749SSergey Zigachev * @src: src addr to copy from
719b843c749SSergey Zigachev * @count: number of page entries to update
720b843c749SSergey Zigachev *
721b843c749SSergey Zigachev * Update PTEs by copying them from the GART using sDMA (CIK).
722b843c749SSergey Zigachev */
sdma_v2_4_vm_copy_pte(struct amdgpu_ib * ib,uint64_t pe,uint64_t src,unsigned count)723b843c749SSergey Zigachev static void sdma_v2_4_vm_copy_pte(struct amdgpu_ib *ib,
724b843c749SSergey Zigachev uint64_t pe, uint64_t src,
725b843c749SSergey Zigachev unsigned count)
726b843c749SSergey Zigachev {
727b843c749SSergey Zigachev unsigned bytes = count * 8;
728b843c749SSergey Zigachev
729b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
730b843c749SSergey Zigachev SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
731b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = bytes;
732b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
733b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(src);
734b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(src);
735b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(pe);
736b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(pe);
737b843c749SSergey Zigachev }
738b843c749SSergey Zigachev
739b843c749SSergey Zigachev /**
740b843c749SSergey Zigachev * sdma_v2_4_vm_write_pte - update PTEs by writing them manually
741b843c749SSergey Zigachev *
742b843c749SSergey Zigachev * @ib: indirect buffer to fill with commands
743b843c749SSergey Zigachev * @pe: addr of the page entry
744b843c749SSergey Zigachev * @value: dst addr to write into pe
745b843c749SSergey Zigachev * @count: number of page entries to update
746b843c749SSergey Zigachev * @incr: increase next addr by incr bytes
747b843c749SSergey Zigachev *
748b843c749SSergey Zigachev * Update PTEs by writing them manually using sDMA (CIK).
749b843c749SSergey Zigachev */
sdma_v2_4_vm_write_pte(struct amdgpu_ib * ib,uint64_t pe,uint64_t value,unsigned count,uint32_t incr)750b843c749SSergey Zigachev static void sdma_v2_4_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
751b843c749SSergey Zigachev uint64_t value, unsigned count,
752b843c749SSergey Zigachev uint32_t incr)
753b843c749SSergey Zigachev {
754b843c749SSergey Zigachev unsigned ndw = count * 2;
755b843c749SSergey Zigachev
756b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
757b843c749SSergey Zigachev SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
758b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = pe;
759b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(pe);
760b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = ndw;
761b843c749SSergey Zigachev for (; ndw > 0; ndw -= 2) {
762b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(value);
763b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(value);
764b843c749SSergey Zigachev value += incr;
765b843c749SSergey Zigachev }
766b843c749SSergey Zigachev }
767b843c749SSergey Zigachev
768b843c749SSergey Zigachev /**
769b843c749SSergey Zigachev * sdma_v2_4_vm_set_pte_pde - update the page tables using sDMA
770b843c749SSergey Zigachev *
771b843c749SSergey Zigachev * @ib: indirect buffer to fill with commands
772b843c749SSergey Zigachev * @pe: addr of the page entry
773b843c749SSergey Zigachev * @addr: dst addr to write into pe
774b843c749SSergey Zigachev * @count: number of page entries to update
775b843c749SSergey Zigachev * @incr: increase next addr by incr bytes
776b843c749SSergey Zigachev * @flags: access flags
777b843c749SSergey Zigachev *
778b843c749SSergey Zigachev * Update the page tables using sDMA (CIK).
779b843c749SSergey Zigachev */
sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib * ib,uint64_t pe,uint64_t addr,unsigned count,uint32_t incr,uint64_t flags)780b843c749SSergey Zigachev static void sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,
781b843c749SSergey Zigachev uint64_t addr, unsigned count,
782b843c749SSergey Zigachev uint32_t incr, uint64_t flags)
783b843c749SSergey Zigachev {
784b843c749SSergey Zigachev /* for physically contiguous pages (vram) */
785b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE);
786b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
787b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(pe);
788b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
789b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(flags);
790b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
791b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(addr);
792b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = incr; /* increment size */
793b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = 0;
794b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = count; /* number of entries */
795b843c749SSergey Zigachev }
796b843c749SSergey Zigachev
797b843c749SSergey Zigachev /**
798b843c749SSergey Zigachev * sdma_v2_4_ring_pad_ib - pad the IB to the required number of dw
799b843c749SSergey Zigachev *
800b843c749SSergey Zigachev * @ib: indirect buffer to fill with padding
801b843c749SSergey Zigachev *
802b843c749SSergey Zigachev */
sdma_v2_4_ring_pad_ib(struct amdgpu_ring * ring,struct amdgpu_ib * ib)803b843c749SSergey Zigachev static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
804b843c749SSergey Zigachev {
805b843c749SSergey Zigachev struct amdgpu_sdma_instance *sdma = amdgpu_get_sdma_instance(ring);
806b843c749SSergey Zigachev u32 pad_count;
807b843c749SSergey Zigachev int i;
808b843c749SSergey Zigachev
809b843c749SSergey Zigachev pad_count = (8 - (ib->length_dw & 0x7)) % 8;
810b843c749SSergey Zigachev for (i = 0; i < pad_count; i++)
811b843c749SSergey Zigachev if (sdma && sdma->burst_nop && (i == 0))
812b843c749SSergey Zigachev ib->ptr[ib->length_dw++] =
813b843c749SSergey Zigachev SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
814b843c749SSergey Zigachev SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
815b843c749SSergey Zigachev else
816b843c749SSergey Zigachev ib->ptr[ib->length_dw++] =
817b843c749SSergey Zigachev SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
818b843c749SSergey Zigachev }
819b843c749SSergey Zigachev
820b843c749SSergey Zigachev /**
821b843c749SSergey Zigachev * sdma_v2_4_ring_emit_pipeline_sync - sync the pipeline
822b843c749SSergey Zigachev *
823b843c749SSergey Zigachev * @ring: amdgpu_ring pointer
824b843c749SSergey Zigachev *
825b843c749SSergey Zigachev * Make sure all previous operations are completed (CIK).
826b843c749SSergey Zigachev */
sdma_v2_4_ring_emit_pipeline_sync(struct amdgpu_ring * ring)827b843c749SSergey Zigachev static void sdma_v2_4_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
828b843c749SSergey Zigachev {
829b843c749SSergey Zigachev uint32_t seq = ring->fence_drv.sync_seq;
830b843c749SSergey Zigachev uint64_t addr = ring->fence_drv.gpu_addr;
831b843c749SSergey Zigachev
832b843c749SSergey Zigachev /* wait for idle */
833b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
834b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
835b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3) | /* equal */
836b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_HEADER_MEM_POLL(1));
837b843c749SSergey Zigachev amdgpu_ring_write(ring, addr & 0xfffffffc);
838b843c749SSergey Zigachev amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
839b843c749SSergey Zigachev amdgpu_ring_write(ring, seq); /* reference */
840b843c749SSergey Zigachev amdgpu_ring_write(ring, 0xffffffff); /* mask */
841b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
842b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
843b843c749SSergey Zigachev }
844b843c749SSergey Zigachev
845b843c749SSergey Zigachev /**
846b843c749SSergey Zigachev * sdma_v2_4_ring_emit_vm_flush - cik vm flush using sDMA
847b843c749SSergey Zigachev *
848b843c749SSergey Zigachev * @ring: amdgpu_ring pointer
849b843c749SSergey Zigachev * @vm: amdgpu_vm pointer
850b843c749SSergey Zigachev *
851b843c749SSergey Zigachev * Update the page table base and flush the VM TLB
852b843c749SSergey Zigachev * using sDMA (VI).
853b843c749SSergey Zigachev */
sdma_v2_4_ring_emit_vm_flush(struct amdgpu_ring * ring,unsigned vmid,uint64_t pd_addr)854b843c749SSergey Zigachev static void sdma_v2_4_ring_emit_vm_flush(struct amdgpu_ring *ring,
855b843c749SSergey Zigachev unsigned vmid, uint64_t pd_addr)
856b843c749SSergey Zigachev {
857b843c749SSergey Zigachev amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
858b843c749SSergey Zigachev
859b843c749SSergey Zigachev /* wait for flush */
860b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
861b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
862b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_HEADER_FUNC(0)); /* always */
863b843c749SSergey Zigachev amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST << 2);
864b843c749SSergey Zigachev amdgpu_ring_write(ring, 0);
865b843c749SSergey Zigachev amdgpu_ring_write(ring, 0); /* reference */
866b843c749SSergey Zigachev amdgpu_ring_write(ring, 0); /* mask */
867b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
868b843c749SSergey Zigachev SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10)); /* retry count, poll interval */
869b843c749SSergey Zigachev }
870b843c749SSergey Zigachev
sdma_v2_4_ring_emit_wreg(struct amdgpu_ring * ring,uint32_t reg,uint32_t val)871b843c749SSergey Zigachev static void sdma_v2_4_ring_emit_wreg(struct amdgpu_ring *ring,
872b843c749SSergey Zigachev uint32_t reg, uint32_t val)
873b843c749SSergey Zigachev {
874b843c749SSergey Zigachev amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) |
875b843c749SSergey Zigachev SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf));
876b843c749SSergey Zigachev amdgpu_ring_write(ring, reg);
877b843c749SSergey Zigachev amdgpu_ring_write(ring, val);
878b843c749SSergey Zigachev }
879b843c749SSergey Zigachev
sdma_v2_4_early_init(void * handle)880b843c749SSergey Zigachev static int sdma_v2_4_early_init(void *handle)
881b843c749SSergey Zigachev {
882b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
883b843c749SSergey Zigachev
884b843c749SSergey Zigachev adev->sdma.num_instances = SDMA_MAX_INSTANCE;
885b843c749SSergey Zigachev
886b843c749SSergey Zigachev sdma_v2_4_set_ring_funcs(adev);
887b843c749SSergey Zigachev sdma_v2_4_set_buffer_funcs(adev);
888b843c749SSergey Zigachev sdma_v2_4_set_vm_pte_funcs(adev);
889b843c749SSergey Zigachev sdma_v2_4_set_irq_funcs(adev);
890b843c749SSergey Zigachev
891b843c749SSergey Zigachev return 0;
892b843c749SSergey Zigachev }
893b843c749SSergey Zigachev
sdma_v2_4_sw_init(void * handle)894b843c749SSergey Zigachev static int sdma_v2_4_sw_init(void *handle)
895b843c749SSergey Zigachev {
896b843c749SSergey Zigachev struct amdgpu_ring *ring;
897b843c749SSergey Zigachev int r, i;
898b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
899b843c749SSergey Zigachev
900b843c749SSergey Zigachev /* SDMA trap event */
901b843c749SSergey Zigachev r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_SDMA_TRAP,
902b843c749SSergey Zigachev &adev->sdma.trap_irq);
903b843c749SSergey Zigachev if (r)
904b843c749SSergey Zigachev return r;
905b843c749SSergey Zigachev
906b843c749SSergey Zigachev /* SDMA Privileged inst */
907b843c749SSergey Zigachev r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 241,
908b843c749SSergey Zigachev &adev->sdma.illegal_inst_irq);
909b843c749SSergey Zigachev if (r)
910b843c749SSergey Zigachev return r;
911b843c749SSergey Zigachev
912b843c749SSergey Zigachev /* SDMA Privileged inst */
913b843c749SSergey Zigachev r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_SDMA_SRBM_WRITE,
914b843c749SSergey Zigachev &adev->sdma.illegal_inst_irq);
915b843c749SSergey Zigachev if (r)
916b843c749SSergey Zigachev return r;
917b843c749SSergey Zigachev
918b843c749SSergey Zigachev r = sdma_v2_4_init_microcode(adev);
919b843c749SSergey Zigachev if (r) {
920b843c749SSergey Zigachev DRM_ERROR("Failed to load sdma firmware!\n");
921b843c749SSergey Zigachev return r;
922b843c749SSergey Zigachev }
923b843c749SSergey Zigachev
924b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
925b843c749SSergey Zigachev ring = &adev->sdma.instance[i].ring;
926b843c749SSergey Zigachev ring->ring_obj = NULL;
927b843c749SSergey Zigachev ring->use_doorbell = false;
92878973132SSergey Zigachev ksprintf(ring->name, "sdma%d", i);
929b843c749SSergey Zigachev r = amdgpu_ring_init(adev, ring, 1024,
930b843c749SSergey Zigachev &adev->sdma.trap_irq,
931b843c749SSergey Zigachev (i == 0) ?
932b843c749SSergey Zigachev AMDGPU_SDMA_IRQ_TRAP0 :
933b843c749SSergey Zigachev AMDGPU_SDMA_IRQ_TRAP1);
934b843c749SSergey Zigachev if (r)
935b843c749SSergey Zigachev return r;
936b843c749SSergey Zigachev }
937b843c749SSergey Zigachev
938b843c749SSergey Zigachev return r;
939b843c749SSergey Zigachev }
940b843c749SSergey Zigachev
sdma_v2_4_sw_fini(void * handle)941b843c749SSergey Zigachev static int sdma_v2_4_sw_fini(void *handle)
942b843c749SSergey Zigachev {
943b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
944b843c749SSergey Zigachev int i;
945b843c749SSergey Zigachev
946b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++)
947b843c749SSergey Zigachev amdgpu_ring_fini(&adev->sdma.instance[i].ring);
948b843c749SSergey Zigachev
949b843c749SSergey Zigachev sdma_v2_4_free_microcode(adev);
950b843c749SSergey Zigachev return 0;
951b843c749SSergey Zigachev }
952b843c749SSergey Zigachev
sdma_v2_4_hw_init(void * handle)953b843c749SSergey Zigachev static int sdma_v2_4_hw_init(void *handle)
954b843c749SSergey Zigachev {
955b843c749SSergey Zigachev int r;
956b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
957b843c749SSergey Zigachev
958b843c749SSergey Zigachev sdma_v2_4_init_golden_registers(adev);
959b843c749SSergey Zigachev
960b843c749SSergey Zigachev r = sdma_v2_4_start(adev);
961b843c749SSergey Zigachev if (r)
962b843c749SSergey Zigachev return r;
963b843c749SSergey Zigachev
964b843c749SSergey Zigachev return r;
965b843c749SSergey Zigachev }
966b843c749SSergey Zigachev
sdma_v2_4_hw_fini(void * handle)967b843c749SSergey Zigachev static int sdma_v2_4_hw_fini(void *handle)
968b843c749SSergey Zigachev {
969b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
970b843c749SSergey Zigachev
971b843c749SSergey Zigachev sdma_v2_4_enable(adev, false);
972b843c749SSergey Zigachev
973b843c749SSergey Zigachev return 0;
974b843c749SSergey Zigachev }
975b843c749SSergey Zigachev
sdma_v2_4_suspend(void * handle)976b843c749SSergey Zigachev static int sdma_v2_4_suspend(void *handle)
977b843c749SSergey Zigachev {
978b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
979b843c749SSergey Zigachev
980b843c749SSergey Zigachev return sdma_v2_4_hw_fini(adev);
981b843c749SSergey Zigachev }
982b843c749SSergey Zigachev
sdma_v2_4_resume(void * handle)983b843c749SSergey Zigachev static int sdma_v2_4_resume(void *handle)
984b843c749SSergey Zigachev {
985b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
986b843c749SSergey Zigachev
987b843c749SSergey Zigachev return sdma_v2_4_hw_init(adev);
988b843c749SSergey Zigachev }
989b843c749SSergey Zigachev
sdma_v2_4_is_idle(void * handle)990b843c749SSergey Zigachev static bool sdma_v2_4_is_idle(void *handle)
991b843c749SSergey Zigachev {
992b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
993b843c749SSergey Zigachev u32 tmp = RREG32(mmSRBM_STATUS2);
994b843c749SSergey Zigachev
995b843c749SSergey Zigachev if (tmp & (SRBM_STATUS2__SDMA_BUSY_MASK |
996b843c749SSergey Zigachev SRBM_STATUS2__SDMA1_BUSY_MASK))
997b843c749SSergey Zigachev return false;
998b843c749SSergey Zigachev
999b843c749SSergey Zigachev return true;
1000b843c749SSergey Zigachev }
1001b843c749SSergey Zigachev
sdma_v2_4_wait_for_idle(void * handle)1002b843c749SSergey Zigachev static int sdma_v2_4_wait_for_idle(void *handle)
1003b843c749SSergey Zigachev {
1004b843c749SSergey Zigachev unsigned i;
1005b843c749SSergey Zigachev u32 tmp;
1006b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1007b843c749SSergey Zigachev
1008b843c749SSergey Zigachev for (i = 0; i < adev->usec_timeout; i++) {
1009b843c749SSergey Zigachev tmp = RREG32(mmSRBM_STATUS2) & (SRBM_STATUS2__SDMA_BUSY_MASK |
1010b843c749SSergey Zigachev SRBM_STATUS2__SDMA1_BUSY_MASK);
1011b843c749SSergey Zigachev
1012b843c749SSergey Zigachev if (!tmp)
1013b843c749SSergey Zigachev return 0;
1014b843c749SSergey Zigachev udelay(1);
1015b843c749SSergey Zigachev }
1016b843c749SSergey Zigachev return -ETIMEDOUT;
1017b843c749SSergey Zigachev }
1018b843c749SSergey Zigachev
sdma_v2_4_soft_reset(void * handle)1019b843c749SSergey Zigachev static int sdma_v2_4_soft_reset(void *handle)
1020b843c749SSergey Zigachev {
1021b843c749SSergey Zigachev u32 srbm_soft_reset = 0;
1022b843c749SSergey Zigachev struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1023b843c749SSergey Zigachev u32 tmp = RREG32(mmSRBM_STATUS2);
1024b843c749SSergey Zigachev
1025b843c749SSergey Zigachev if (tmp & SRBM_STATUS2__SDMA_BUSY_MASK) {
1026b843c749SSergey Zigachev /* sdma0 */
1027b843c749SSergey Zigachev tmp = RREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET);
1028b843c749SSergey Zigachev tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 0);
1029b843c749SSergey Zigachev WREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET, tmp);
1030b843c749SSergey Zigachev srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA_MASK;
1031b843c749SSergey Zigachev }
1032b843c749SSergey Zigachev if (tmp & SRBM_STATUS2__SDMA1_BUSY_MASK) {
1033b843c749SSergey Zigachev /* sdma1 */
1034b843c749SSergey Zigachev tmp = RREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET);
1035b843c749SSergey Zigachev tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 0);
1036b843c749SSergey Zigachev WREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET, tmp);
1037b843c749SSergey Zigachev srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA1_MASK;
1038b843c749SSergey Zigachev }
1039b843c749SSergey Zigachev
1040b843c749SSergey Zigachev if (srbm_soft_reset) {
1041b843c749SSergey Zigachev tmp = RREG32(mmSRBM_SOFT_RESET);
1042b843c749SSergey Zigachev tmp |= srbm_soft_reset;
1043b843c749SSergey Zigachev dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
1044b843c749SSergey Zigachev WREG32(mmSRBM_SOFT_RESET, tmp);
1045b843c749SSergey Zigachev tmp = RREG32(mmSRBM_SOFT_RESET);
1046b843c749SSergey Zigachev
1047b843c749SSergey Zigachev udelay(50);
1048b843c749SSergey Zigachev
1049b843c749SSergey Zigachev tmp &= ~srbm_soft_reset;
1050b843c749SSergey Zigachev WREG32(mmSRBM_SOFT_RESET, tmp);
1051b843c749SSergey Zigachev tmp = RREG32(mmSRBM_SOFT_RESET);
1052b843c749SSergey Zigachev
1053b843c749SSergey Zigachev /* Wait a little for things to settle down */
1054b843c749SSergey Zigachev udelay(50);
1055b843c749SSergey Zigachev }
1056b843c749SSergey Zigachev
1057b843c749SSergey Zigachev return 0;
1058b843c749SSergey Zigachev }
1059b843c749SSergey Zigachev
sdma_v2_4_set_trap_irq_state(struct amdgpu_device * adev,struct amdgpu_irq_src * src,unsigned type,enum amdgpu_interrupt_state state)1060b843c749SSergey Zigachev static int sdma_v2_4_set_trap_irq_state(struct amdgpu_device *adev,
1061b843c749SSergey Zigachev struct amdgpu_irq_src *src,
1062b843c749SSergey Zigachev unsigned type,
1063b843c749SSergey Zigachev enum amdgpu_interrupt_state state)
1064b843c749SSergey Zigachev {
1065b843c749SSergey Zigachev u32 sdma_cntl;
1066b843c749SSergey Zigachev
1067b843c749SSergey Zigachev switch (type) {
1068b843c749SSergey Zigachev case AMDGPU_SDMA_IRQ_TRAP0:
1069b843c749SSergey Zigachev switch (state) {
1070b843c749SSergey Zigachev case AMDGPU_IRQ_STATE_DISABLE:
1071b843c749SSergey Zigachev sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET);
1072b843c749SSergey Zigachev sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 0);
1073b843c749SSergey Zigachev WREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET, sdma_cntl);
1074b843c749SSergey Zigachev break;
1075b843c749SSergey Zigachev case AMDGPU_IRQ_STATE_ENABLE:
1076b843c749SSergey Zigachev sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET);
1077b843c749SSergey Zigachev sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 1);
1078b843c749SSergey Zigachev WREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET, sdma_cntl);
1079b843c749SSergey Zigachev break;
1080b843c749SSergey Zigachev default:
1081b843c749SSergey Zigachev break;
1082b843c749SSergey Zigachev }
1083b843c749SSergey Zigachev break;
1084b843c749SSergey Zigachev case AMDGPU_SDMA_IRQ_TRAP1:
1085b843c749SSergey Zigachev switch (state) {
1086b843c749SSergey Zigachev case AMDGPU_IRQ_STATE_DISABLE:
1087b843c749SSergey Zigachev sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET);
1088b843c749SSergey Zigachev sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 0);
1089b843c749SSergey Zigachev WREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET, sdma_cntl);
1090b843c749SSergey Zigachev break;
1091b843c749SSergey Zigachev case AMDGPU_IRQ_STATE_ENABLE:
1092b843c749SSergey Zigachev sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET);
1093b843c749SSergey Zigachev sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 1);
1094b843c749SSergey Zigachev WREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET, sdma_cntl);
1095b843c749SSergey Zigachev break;
1096b843c749SSergey Zigachev default:
1097b843c749SSergey Zigachev break;
1098b843c749SSergey Zigachev }
1099b843c749SSergey Zigachev break;
1100b843c749SSergey Zigachev default:
1101b843c749SSergey Zigachev break;
1102b843c749SSergey Zigachev }
1103b843c749SSergey Zigachev return 0;
1104b843c749SSergey Zigachev }
1105b843c749SSergey Zigachev
sdma_v2_4_process_trap_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)1106b843c749SSergey Zigachev static int sdma_v2_4_process_trap_irq(struct amdgpu_device *adev,
1107b843c749SSergey Zigachev struct amdgpu_irq_src *source,
1108b843c749SSergey Zigachev struct amdgpu_iv_entry *entry)
1109b843c749SSergey Zigachev {
1110b843c749SSergey Zigachev u8 instance_id, queue_id;
1111b843c749SSergey Zigachev
1112b843c749SSergey Zigachev instance_id = (entry->ring_id & 0x3) >> 0;
1113b843c749SSergey Zigachev queue_id = (entry->ring_id & 0xc) >> 2;
1114b843c749SSergey Zigachev DRM_DEBUG("IH: SDMA trap\n");
1115b843c749SSergey Zigachev switch (instance_id) {
1116b843c749SSergey Zigachev case 0:
1117b843c749SSergey Zigachev switch (queue_id) {
1118b843c749SSergey Zigachev case 0:
1119b843c749SSergey Zigachev amdgpu_fence_process(&adev->sdma.instance[0].ring);
1120b843c749SSergey Zigachev break;
1121b843c749SSergey Zigachev case 1:
1122b843c749SSergey Zigachev /* XXX compute */
1123b843c749SSergey Zigachev break;
1124b843c749SSergey Zigachev case 2:
1125b843c749SSergey Zigachev /* XXX compute */
1126b843c749SSergey Zigachev break;
1127b843c749SSergey Zigachev }
1128b843c749SSergey Zigachev break;
1129b843c749SSergey Zigachev case 1:
1130b843c749SSergey Zigachev switch (queue_id) {
1131b843c749SSergey Zigachev case 0:
1132b843c749SSergey Zigachev amdgpu_fence_process(&adev->sdma.instance[1].ring);
1133b843c749SSergey Zigachev break;
1134b843c749SSergey Zigachev case 1:
1135b843c749SSergey Zigachev /* XXX compute */
1136b843c749SSergey Zigachev break;
1137b843c749SSergey Zigachev case 2:
1138b843c749SSergey Zigachev /* XXX compute */
1139b843c749SSergey Zigachev break;
1140b843c749SSergey Zigachev }
1141b843c749SSergey Zigachev break;
1142b843c749SSergey Zigachev }
1143b843c749SSergey Zigachev return 0;
1144b843c749SSergey Zigachev }
1145b843c749SSergey Zigachev
sdma_v2_4_process_illegal_inst_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)1146b843c749SSergey Zigachev static int sdma_v2_4_process_illegal_inst_irq(struct amdgpu_device *adev,
1147b843c749SSergey Zigachev struct amdgpu_irq_src *source,
1148b843c749SSergey Zigachev struct amdgpu_iv_entry *entry)
1149b843c749SSergey Zigachev {
1150b843c749SSergey Zigachev DRM_ERROR("Illegal instruction in SDMA command stream\n");
1151b843c749SSergey Zigachev schedule_work(&adev->reset_work);
1152b843c749SSergey Zigachev return 0;
1153b843c749SSergey Zigachev }
1154b843c749SSergey Zigachev
sdma_v2_4_set_clockgating_state(void * handle,enum amd_clockgating_state state)1155b843c749SSergey Zigachev static int sdma_v2_4_set_clockgating_state(void *handle,
1156b843c749SSergey Zigachev enum amd_clockgating_state state)
1157b843c749SSergey Zigachev {
1158b843c749SSergey Zigachev /* XXX handled via the smc on VI */
1159b843c749SSergey Zigachev return 0;
1160b843c749SSergey Zigachev }
1161b843c749SSergey Zigachev
sdma_v2_4_set_powergating_state(void * handle,enum amd_powergating_state state)1162b843c749SSergey Zigachev static int sdma_v2_4_set_powergating_state(void *handle,
1163b843c749SSergey Zigachev enum amd_powergating_state state)
1164b843c749SSergey Zigachev {
1165b843c749SSergey Zigachev return 0;
1166b843c749SSergey Zigachev }
1167b843c749SSergey Zigachev
1168b843c749SSergey Zigachev static const struct amd_ip_funcs sdma_v2_4_ip_funcs = {
1169b843c749SSergey Zigachev .name = "sdma_v2_4",
1170b843c749SSergey Zigachev .early_init = sdma_v2_4_early_init,
1171b843c749SSergey Zigachev .late_init = NULL,
1172b843c749SSergey Zigachev .sw_init = sdma_v2_4_sw_init,
1173b843c749SSergey Zigachev .sw_fini = sdma_v2_4_sw_fini,
1174b843c749SSergey Zigachev .hw_init = sdma_v2_4_hw_init,
1175b843c749SSergey Zigachev .hw_fini = sdma_v2_4_hw_fini,
1176b843c749SSergey Zigachev .suspend = sdma_v2_4_suspend,
1177b843c749SSergey Zigachev .resume = sdma_v2_4_resume,
1178b843c749SSergey Zigachev .is_idle = sdma_v2_4_is_idle,
1179b843c749SSergey Zigachev .wait_for_idle = sdma_v2_4_wait_for_idle,
1180b843c749SSergey Zigachev .soft_reset = sdma_v2_4_soft_reset,
1181b843c749SSergey Zigachev .set_clockgating_state = sdma_v2_4_set_clockgating_state,
1182b843c749SSergey Zigachev .set_powergating_state = sdma_v2_4_set_powergating_state,
1183b843c749SSergey Zigachev };
1184b843c749SSergey Zigachev
1185b843c749SSergey Zigachev static const struct amdgpu_ring_funcs sdma_v2_4_ring_funcs = {
1186b843c749SSergey Zigachev .type = AMDGPU_RING_TYPE_SDMA,
1187b843c749SSergey Zigachev .align_mask = 0xf,
1188b843c749SSergey Zigachev .nop = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP),
1189b843c749SSergey Zigachev .support_64bit_ptrs = false,
1190b843c749SSergey Zigachev .get_rptr = sdma_v2_4_ring_get_rptr,
1191b843c749SSergey Zigachev .get_wptr = sdma_v2_4_ring_get_wptr,
1192b843c749SSergey Zigachev .set_wptr = sdma_v2_4_ring_set_wptr,
1193b843c749SSergey Zigachev .emit_frame_size =
1194b843c749SSergey Zigachev 6 + /* sdma_v2_4_ring_emit_hdp_flush */
1195b843c749SSergey Zigachev 3 + /* hdp invalidate */
1196b843c749SSergey Zigachev 6 + /* sdma_v2_4_ring_emit_pipeline_sync */
1197b843c749SSergey Zigachev VI_FLUSH_GPU_TLB_NUM_WREG * 3 + 6 + /* sdma_v2_4_ring_emit_vm_flush */
1198b843c749SSergey Zigachev 10 + 10 + 10, /* sdma_v2_4_ring_emit_fence x3 for user fence, vm fence */
1199b843c749SSergey Zigachev .emit_ib_size = 7 + 6, /* sdma_v2_4_ring_emit_ib */
1200b843c749SSergey Zigachev .emit_ib = sdma_v2_4_ring_emit_ib,
1201b843c749SSergey Zigachev .emit_fence = sdma_v2_4_ring_emit_fence,
1202b843c749SSergey Zigachev .emit_pipeline_sync = sdma_v2_4_ring_emit_pipeline_sync,
1203b843c749SSergey Zigachev .emit_vm_flush = sdma_v2_4_ring_emit_vm_flush,
1204b843c749SSergey Zigachev .emit_hdp_flush = sdma_v2_4_ring_emit_hdp_flush,
1205b843c749SSergey Zigachev .test_ring = sdma_v2_4_ring_test_ring,
1206b843c749SSergey Zigachev .test_ib = sdma_v2_4_ring_test_ib,
1207b843c749SSergey Zigachev .insert_nop = sdma_v2_4_ring_insert_nop,
1208b843c749SSergey Zigachev .pad_ib = sdma_v2_4_ring_pad_ib,
1209b843c749SSergey Zigachev .emit_wreg = sdma_v2_4_ring_emit_wreg,
1210b843c749SSergey Zigachev };
1211b843c749SSergey Zigachev
sdma_v2_4_set_ring_funcs(struct amdgpu_device * adev)1212b843c749SSergey Zigachev static void sdma_v2_4_set_ring_funcs(struct amdgpu_device *adev)
1213b843c749SSergey Zigachev {
1214b843c749SSergey Zigachev int i;
1215b843c749SSergey Zigachev
1216b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) {
1217b843c749SSergey Zigachev adev->sdma.instance[i].ring.funcs = &sdma_v2_4_ring_funcs;
1218b843c749SSergey Zigachev adev->sdma.instance[i].ring.me = i;
1219b843c749SSergey Zigachev }
1220b843c749SSergey Zigachev }
1221b843c749SSergey Zigachev
1222b843c749SSergey Zigachev static const struct amdgpu_irq_src_funcs sdma_v2_4_trap_irq_funcs = {
1223b843c749SSergey Zigachev .set = sdma_v2_4_set_trap_irq_state,
1224b843c749SSergey Zigachev .process = sdma_v2_4_process_trap_irq,
1225b843c749SSergey Zigachev };
1226b843c749SSergey Zigachev
1227b843c749SSergey Zigachev static const struct amdgpu_irq_src_funcs sdma_v2_4_illegal_inst_irq_funcs = {
1228b843c749SSergey Zigachev .process = sdma_v2_4_process_illegal_inst_irq,
1229b843c749SSergey Zigachev };
1230b843c749SSergey Zigachev
sdma_v2_4_set_irq_funcs(struct amdgpu_device * adev)1231b843c749SSergey Zigachev static void sdma_v2_4_set_irq_funcs(struct amdgpu_device *adev)
1232b843c749SSergey Zigachev {
1233b843c749SSergey Zigachev adev->sdma.trap_irq.num_types = AMDGPU_SDMA_IRQ_LAST;
1234b843c749SSergey Zigachev adev->sdma.trap_irq.funcs = &sdma_v2_4_trap_irq_funcs;
1235b843c749SSergey Zigachev adev->sdma.illegal_inst_irq.funcs = &sdma_v2_4_illegal_inst_irq_funcs;
1236b843c749SSergey Zigachev }
1237b843c749SSergey Zigachev
1238b843c749SSergey Zigachev /**
1239b843c749SSergey Zigachev * sdma_v2_4_emit_copy_buffer - copy buffer using the sDMA engine
1240b843c749SSergey Zigachev *
1241b843c749SSergey Zigachev * @ring: amdgpu_ring structure holding ring information
1242b843c749SSergey Zigachev * @src_offset: src GPU address
1243b843c749SSergey Zigachev * @dst_offset: dst GPU address
1244b843c749SSergey Zigachev * @byte_count: number of bytes to xfer
1245b843c749SSergey Zigachev *
1246b843c749SSergey Zigachev * Copy GPU buffers using the DMA engine (VI).
1247b843c749SSergey Zigachev * Used by the amdgpu ttm implementation to move pages if
1248b843c749SSergey Zigachev * registered as the asic copy callback.
1249b843c749SSergey Zigachev */
sdma_v2_4_emit_copy_buffer(struct amdgpu_ib * ib,uint64_t src_offset,uint64_t dst_offset,uint32_t byte_count)1250b843c749SSergey Zigachev static void sdma_v2_4_emit_copy_buffer(struct amdgpu_ib *ib,
1251b843c749SSergey Zigachev uint64_t src_offset,
1252b843c749SSergey Zigachev uint64_t dst_offset,
1253b843c749SSergey Zigachev uint32_t byte_count)
1254b843c749SSergey Zigachev {
1255b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
1256b843c749SSergey Zigachev SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
1257b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = byte_count;
1258b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
1259b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
1260b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
1261b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
1262b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
1263b843c749SSergey Zigachev }
1264b843c749SSergey Zigachev
1265b843c749SSergey Zigachev /**
1266b843c749SSergey Zigachev * sdma_v2_4_emit_fill_buffer - fill buffer using the sDMA engine
1267b843c749SSergey Zigachev *
1268b843c749SSergey Zigachev * @ring: amdgpu_ring structure holding ring information
1269b843c749SSergey Zigachev * @src_data: value to write to buffer
1270b843c749SSergey Zigachev * @dst_offset: dst GPU address
1271b843c749SSergey Zigachev * @byte_count: number of bytes to xfer
1272b843c749SSergey Zigachev *
1273b843c749SSergey Zigachev * Fill GPU buffers using the DMA engine (VI).
1274b843c749SSergey Zigachev */
sdma_v2_4_emit_fill_buffer(struct amdgpu_ib * ib,uint32_t src_data,uint64_t dst_offset,uint32_t byte_count)1275b843c749SSergey Zigachev static void sdma_v2_4_emit_fill_buffer(struct amdgpu_ib *ib,
1276b843c749SSergey Zigachev uint32_t src_data,
1277b843c749SSergey Zigachev uint64_t dst_offset,
1278b843c749SSergey Zigachev uint32_t byte_count)
1279b843c749SSergey Zigachev {
1280b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
1281b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
1282b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
1283b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = src_data;
1284b843c749SSergey Zigachev ib->ptr[ib->length_dw++] = byte_count;
1285b843c749SSergey Zigachev }
1286b843c749SSergey Zigachev
1287b843c749SSergey Zigachev static const struct amdgpu_buffer_funcs sdma_v2_4_buffer_funcs = {
1288b843c749SSergey Zigachev .copy_max_bytes = 0x1fffff,
1289b843c749SSergey Zigachev .copy_num_dw = 7,
1290b843c749SSergey Zigachev .emit_copy_buffer = sdma_v2_4_emit_copy_buffer,
1291b843c749SSergey Zigachev
1292b843c749SSergey Zigachev .fill_max_bytes = 0x1fffff,
1293b843c749SSergey Zigachev .fill_num_dw = 7,
1294b843c749SSergey Zigachev .emit_fill_buffer = sdma_v2_4_emit_fill_buffer,
1295b843c749SSergey Zigachev };
1296b843c749SSergey Zigachev
sdma_v2_4_set_buffer_funcs(struct amdgpu_device * adev)1297b843c749SSergey Zigachev static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev)
1298b843c749SSergey Zigachev {
1299b843c749SSergey Zigachev if (adev->mman.buffer_funcs == NULL) {
1300b843c749SSergey Zigachev adev->mman.buffer_funcs = &sdma_v2_4_buffer_funcs;
1301b843c749SSergey Zigachev adev->mman.buffer_funcs_ring = &adev->sdma.instance[0].ring;
1302b843c749SSergey Zigachev }
1303b843c749SSergey Zigachev }
1304b843c749SSergey Zigachev
1305b843c749SSergey Zigachev static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = {
1306b843c749SSergey Zigachev .copy_pte_num_dw = 7,
1307b843c749SSergey Zigachev .copy_pte = sdma_v2_4_vm_copy_pte,
1308b843c749SSergey Zigachev
1309b843c749SSergey Zigachev .write_pte = sdma_v2_4_vm_write_pte,
1310b843c749SSergey Zigachev .set_pte_pde = sdma_v2_4_vm_set_pte_pde,
1311b843c749SSergey Zigachev };
1312b843c749SSergey Zigachev
sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device * adev)1313b843c749SSergey Zigachev static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev)
1314b843c749SSergey Zigachev {
1315b843c749SSergey Zigachev unsigned i;
1316b843c749SSergey Zigachev
1317b843c749SSergey Zigachev if (adev->vm_manager.vm_pte_funcs == NULL) {
1318b843c749SSergey Zigachev adev->vm_manager.vm_pte_funcs = &sdma_v2_4_vm_pte_funcs;
1319b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++)
1320b843c749SSergey Zigachev adev->vm_manager.vm_pte_rings[i] =
1321b843c749SSergey Zigachev &adev->sdma.instance[i].ring;
1322b843c749SSergey Zigachev
1323b843c749SSergey Zigachev adev->vm_manager.vm_pte_num_rings = adev->sdma.num_instances;
1324b843c749SSergey Zigachev }
1325b843c749SSergey Zigachev }
1326b843c749SSergey Zigachev
1327b843c749SSergey Zigachev const struct amdgpu_ip_block_version sdma_v2_4_ip_block =
1328b843c749SSergey Zigachev {
1329b843c749SSergey Zigachev .type = AMD_IP_BLOCK_TYPE_SDMA,
1330b843c749SSergey Zigachev .major = 2,
1331b843c749SSergey Zigachev .minor = 4,
1332b843c749SSergey Zigachev .rev = 0,
1333b843c749SSergey Zigachev .funcs = &sdma_v2_4_ip_funcs,
1334b843c749SSergey Zigachev };
1335