2 * Copyright 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Alex Deucher
24 #include <linux/firmware.h>
27 #include "amdgpu_ucode.h"
28 #include "amdgpu_trace.h"
32 #include "oss/oss_2_4_d.h"
33 #include "oss/oss_2_4_sh_mask.h"
35 #include "gmc/gmc_7_1_d.h"
36 #include "gmc/gmc_7_1_sh_mask.h"
38 #include "gca/gfx_8_0_d.h"
39 #include "gca/gfx_8_0_enum.h"
40 #include "gca/gfx_8_0_sh_mask.h"
42 #include "bif/bif_5_0_d.h"
43 #include "bif/bif_5_0_sh_mask.h"
45 #include "iceland_sdma_pkt_open.h"
47 static void sdma_v2_4_set_ring_funcs(struct amdgpu_device *adev);
48 static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev);
49 static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev);
50 static void sdma_v2_4_set_irq_funcs(struct amdgpu_device *adev);
52 MODULE_FIRMWARE("amdgpu/topaz_sdma.bin");
53 MODULE_FIRMWARE("amdgpu/topaz_sdma1.bin");
55 static const u32 sdma_offsets[SDMA_MAX_INSTANCE] =
57 SDMA0_REGISTER_OFFSET,
61 static const u32 golden_settings_iceland_a11[] =
63 mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007,
64 mmSDMA0_CLK_CTRL, 0xff000fff, 0x00000000,
65 mmSDMA1_CHICKEN_BITS, 0xfc910007, 0x00810007,
66 mmSDMA1_CLK_CTRL, 0xff000fff, 0x00000000,
69 static const u32 iceland_mgcg_cgcg_init[] =
71 mmSDMA0_CLK_CTRL, 0xff000ff0, 0x00000100,
72 mmSDMA1_CLK_CTRL, 0xff000ff0, 0x00000100
77 * Starting with CIK, the GPU has new asynchronous
78 * DMA engines. These engines are used for compute
79 * and gfx. There are two DMA engines (SDMA0, SDMA1)
80 * and each one supports 1 ring buffer used for gfx
81 * and 2 queues used for compute.
83 * The programming model is very similar to the CP
84 * (ring buffer, IBs, etc.), but sDMA has it's own
85 * packet format that is different from the PM4 format
86 * used by the CP. sDMA supports copying data, writing
87 * embedded data, solid fills, and a number of other
88 * things. It also has support for tiling/detiling of
92 static void sdma_v2_4_init_golden_registers(struct amdgpu_device *adev)
94 switch (adev->asic_type) {
96 amdgpu_program_register_sequence(adev,
97 iceland_mgcg_cgcg_init,
98 (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
99 amdgpu_program_register_sequence(adev,
100 golden_settings_iceland_a11,
101 (const u32)ARRAY_SIZE(golden_settings_iceland_a11));
108 static void sdma_v2_4_free_microcode(struct amdgpu_device *adev)
111 for (i = 0; i < adev->sdma.num_instances; i++) {
112 release_firmware(adev->sdma.instance[i].fw);
113 adev->sdma.instance[i].fw = NULL;
118 * sdma_v2_4_init_microcode - load ucode images from disk
120 * @adev: amdgpu_device pointer
122 * Use the firmware interface to load the ucode images into
123 * the driver (not loaded into hw).
124 * Returns 0 on success, error on failure.
126 static int sdma_v2_4_init_microcode(struct amdgpu_device *adev)
128 const char *chip_name;
131 struct amdgpu_firmware_info *info = NULL;
132 const struct common_firmware_header *header = NULL;
133 const struct sdma_firmware_header_v1_0 *hdr;
137 switch (adev->asic_type) {
144 for (i = 0; i < adev->sdma.num_instances; i++) {
146 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma.bin", chip_name);
148 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma1.bin", chip_name);
149 err = request_firmware(&adev->sdma.instance[i].fw, fw_name, adev->dev);
152 err = amdgpu_ucode_validate(adev->sdma.instance[i].fw);
155 hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
156 adev->sdma.instance[i].fw_version = le32_to_cpu(hdr->header.ucode_version);
157 adev->sdma.instance[i].feature_version = le32_to_cpu(hdr->ucode_feature_version);
158 if (adev->sdma.instance[i].feature_version >= 20)
159 adev->sdma.instance[i].burst_nop = true;
161 if (adev->firmware.smu_load) {
162 info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i];
163 info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i;
164 info->fw = adev->sdma.instance[i].fw;
165 header = (const struct common_firmware_header *)info->fw->data;
166 adev->firmware.fw_size +=
167 ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
174 "sdma_v2_4: Failed to load firmware \"%s\"\n",
176 for (i = 0; i < adev->sdma.num_instances; i++) {
177 release_firmware(adev->sdma.instance[i].fw);
178 adev->sdma.instance[i].fw = NULL;
185 * sdma_v2_4_ring_get_rptr - get the current read pointer
187 * @ring: amdgpu ring pointer
189 * Get the current rptr from the hardware (VI+).
191 static uint32_t sdma_v2_4_ring_get_rptr(struct amdgpu_ring *ring)
195 /* XXX check if swapping is necessary on BE */
196 rptr = ring->adev->wb.wb[ring->rptr_offs] >> 2;
202 * sdma_v2_4_ring_get_wptr - get the current write pointer
204 * @ring: amdgpu ring pointer
206 * Get the current wptr from the hardware (VI+).
208 static uint32_t sdma_v2_4_ring_get_wptr(struct amdgpu_ring *ring)
210 struct amdgpu_device *adev = ring->adev;
211 int me = (ring == &ring->adev->sdma.instance[0].ring) ? 0 : 1;
212 u32 wptr = RREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[me]) >> 2;
218 * sdma_v2_4_ring_set_wptr - commit the write pointer
220 * @ring: amdgpu ring pointer
222 * Write the wptr back to the hardware (VI+).
224 static void sdma_v2_4_ring_set_wptr(struct amdgpu_ring *ring)
226 struct amdgpu_device *adev = ring->adev;
227 int me = (ring == &ring->adev->sdma.instance[0].ring) ? 0 : 1;
229 WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[me], ring->wptr << 2);
232 static void sdma_v2_4_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)
234 struct amdgpu_sdma_instance *sdma = amdgpu_get_sdma_instance(ring);
237 for (i = 0; i < count; i++)
238 if (sdma && sdma->burst_nop && (i == 0))
239 amdgpu_ring_write(ring, ring->nop |
240 SDMA_PKT_NOP_HEADER_COUNT(count - 1));
242 amdgpu_ring_write(ring, ring->nop);
246 * sdma_v2_4_ring_emit_ib - Schedule an IB on the DMA engine
248 * @ring: amdgpu ring pointer
249 * @ib: IB object to schedule
251 * Schedule an IB in the DMA ring (VI).
253 static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,
254 struct amdgpu_ib *ib,
255 unsigned vm_id, bool ctx_switch)
257 u32 vmid = vm_id & 0xf;
259 /* IB packet must end on a 8 DW boundary */
260 sdma_v2_4_ring_insert_nop(ring, (10 - (ring->wptr & 7)) % 8);
262 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_INDIRECT) |
263 SDMA_PKT_INDIRECT_HEADER_VMID(vmid));
264 /* base must be 32 byte aligned */
265 amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr) & 0xffffffe0);
266 amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
267 amdgpu_ring_write(ring, ib->length_dw);
268 amdgpu_ring_write(ring, 0);
269 amdgpu_ring_write(ring, 0);
274 * sdma_v2_4_hdp_flush_ring_emit - emit an hdp flush on the DMA ring
276 * @ring: amdgpu ring pointer
278 * Emit an hdp flush packet on the requested DMA ring.
280 static void sdma_v2_4_ring_emit_hdp_flush(struct amdgpu_ring *ring)
282 u32 ref_and_mask = 0;
284 if (ring == &ring->adev->sdma.instance[0].ring)
285 ref_and_mask = REG_SET_FIELD(ref_and_mask, GPU_HDP_FLUSH_DONE, SDMA0, 1);
287 ref_and_mask = REG_SET_FIELD(ref_and_mask, GPU_HDP_FLUSH_DONE, SDMA1, 1);
289 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
290 SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(1) |
291 SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3)); /* == */
292 amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE << 2);
293 amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ << 2);
294 amdgpu_ring_write(ring, ref_and_mask); /* reference */
295 amdgpu_ring_write(ring, ref_and_mask); /* mask */
296 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
297 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10)); /* retry count, poll interval */
300 static void sdma_v2_4_ring_emit_hdp_invalidate(struct amdgpu_ring *ring)
302 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) |
303 SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf));
304 amdgpu_ring_write(ring, mmHDP_DEBUG0);
305 amdgpu_ring_write(ring, 1);
308 * sdma_v2_4_ring_emit_fence - emit a fence on the DMA ring
310 * @ring: amdgpu ring pointer
311 * @fence: amdgpu fence object
313 * Add a DMA fence packet to the ring to write
314 * the fence seq number and DMA trap packet to generate
315 * an interrupt if needed (VI).
317 static void sdma_v2_4_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
320 bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
321 /* write the fence */
322 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
323 amdgpu_ring_write(ring, lower_32_bits(addr));
324 amdgpu_ring_write(ring, upper_32_bits(addr));
325 amdgpu_ring_write(ring, lower_32_bits(seq));
327 /* optionally write high bits as well */
330 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
331 amdgpu_ring_write(ring, lower_32_bits(addr));
332 amdgpu_ring_write(ring, upper_32_bits(addr));
333 amdgpu_ring_write(ring, upper_32_bits(seq));
336 /* generate an interrupt */
337 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_TRAP));
338 amdgpu_ring_write(ring, SDMA_PKT_TRAP_INT_CONTEXT_INT_CONTEXT(0));
342 * sdma_v2_4_gfx_stop - stop the gfx async dma engines
344 * @adev: amdgpu_device pointer
346 * Stop the gfx async dma ring buffers (VI).
348 static void sdma_v2_4_gfx_stop(struct amdgpu_device *adev)
350 struct amdgpu_ring *sdma0 = &adev->sdma.instance[0].ring;
351 struct amdgpu_ring *sdma1 = &adev->sdma.instance[1].ring;
352 u32 rb_cntl, ib_cntl;
355 if ((adev->mman.buffer_funcs_ring == sdma0) ||
356 (adev->mman.buffer_funcs_ring == sdma1))
357 amdgpu_ttm_set_active_vram_size(adev, adev->mc.visible_vram_size);
359 for (i = 0; i < adev->sdma.num_instances; i++) {
360 rb_cntl = RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]);
361 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
362 WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl);
363 ib_cntl = RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]);
364 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0);
365 WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl);
367 sdma0->ready = false;
368 sdma1->ready = false;
372 * sdma_v2_4_rlc_stop - stop the compute async dma engines
374 * @adev: amdgpu_device pointer
376 * Stop the compute async dma queues (VI).
378 static void sdma_v2_4_rlc_stop(struct amdgpu_device *adev)
384 * sdma_v2_4_enable - stop the async dma engines
386 * @adev: amdgpu_device pointer
387 * @enable: enable/disable the DMA MEs.
389 * Halt or unhalt the async dma engines (VI).
391 static void sdma_v2_4_enable(struct amdgpu_device *adev, bool enable)
397 sdma_v2_4_gfx_stop(adev);
398 sdma_v2_4_rlc_stop(adev);
401 for (i = 0; i < adev->sdma.num_instances; i++) {
402 f32_cntl = RREG32(mmSDMA0_F32_CNTL + sdma_offsets[i]);
404 f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 0);
406 f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 1);
407 WREG32(mmSDMA0_F32_CNTL + sdma_offsets[i], f32_cntl);
412 * sdma_v2_4_gfx_resume - setup and start the async dma engines
414 * @adev: amdgpu_device pointer
416 * Set up the gfx DMA ring buffers and enable them (VI).
417 * Returns 0 for success, error for failure.
419 static int sdma_v2_4_gfx_resume(struct amdgpu_device *adev)
421 struct amdgpu_ring *ring;
422 u32 rb_cntl, ib_cntl;
427 for (i = 0; i < adev->sdma.num_instances; i++) {
428 ring = &adev->sdma.instance[i].ring;
429 wb_offset = (ring->rptr_offs * 4);
431 mutex_lock(&adev->srbm_mutex);
432 for (j = 0; j < 16; j++) {
433 vi_srbm_select(adev, 0, 0, 0, j);
435 WREG32(mmSDMA0_GFX_VIRTUAL_ADDR + sdma_offsets[i], 0);
436 WREG32(mmSDMA0_GFX_APE1_CNTL + sdma_offsets[i], 0);
438 vi_srbm_select(adev, 0, 0, 0, 0);
439 mutex_unlock(&adev->srbm_mutex);
441 WREG32(mmSDMA0_TILING_CONFIG + sdma_offsets[i],
442 adev->gfx.config.gb_addr_config & 0x70);
444 WREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL + sdma_offsets[i], 0);
446 /* Set ring buffer size in dwords */
447 rb_bufsz = order_base_2(ring->ring_size / 4);
448 rb_cntl = RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]);
449 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SIZE, rb_bufsz);
451 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SWAP_ENABLE, 1);
452 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL,
453 RPTR_WRITEBACK_SWAP_ENABLE, 1);
455 WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl);
457 /* Initialize the ring buffer's read and write pointers */
458 WREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i], 0);
459 WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], 0);
460 WREG32(mmSDMA0_GFX_IB_RPTR + sdma_offsets[i], 0);
461 WREG32(mmSDMA0_GFX_IB_OFFSET + sdma_offsets[i], 0);
463 /* set the wb address whether it's enabled or not */
464 WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i],
465 upper_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFF);
466 WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO + sdma_offsets[i],
467 lower_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC);
469 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RPTR_WRITEBACK_ENABLE, 1);
471 WREG32(mmSDMA0_GFX_RB_BASE + sdma_offsets[i], ring->gpu_addr >> 8);
472 WREG32(mmSDMA0_GFX_RB_BASE_HI + sdma_offsets[i], ring->gpu_addr >> 40);
475 WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], ring->wptr << 2);
478 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 1);
479 WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl);
481 ib_cntl = RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]);
482 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 1);
484 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_SWAP_ENABLE, 1);
487 WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl);
492 sdma_v2_4_enable(adev, true);
493 for (i = 0; i < adev->sdma.num_instances; i++) {
494 ring = &adev->sdma.instance[i].ring;
495 r = amdgpu_ring_test_ring(ring);
501 if (adev->mman.buffer_funcs_ring == ring)
502 amdgpu_ttm_set_active_vram_size(adev, adev->mc.real_vram_size);
509 * sdma_v2_4_rlc_resume - setup and start the async dma engines
511 * @adev: amdgpu_device pointer
513 * Set up the compute DMA queues and enable them (VI).
514 * Returns 0 for success, error for failure.
516 static int sdma_v2_4_rlc_resume(struct amdgpu_device *adev)
523 * sdma_v2_4_load_microcode - load the sDMA ME ucode
525 * @adev: amdgpu_device pointer
527 * Loads the sDMA0/1 ucode.
528 * Returns 0 for success, -EINVAL if the ucode is not available.
530 static int sdma_v2_4_load_microcode(struct amdgpu_device *adev)
532 const struct sdma_firmware_header_v1_0 *hdr;
533 const __le32 *fw_data;
538 sdma_v2_4_enable(adev, false);
540 for (i = 0; i < adev->sdma.num_instances; i++) {
541 if (!adev->sdma.instance[i].fw)
543 hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
544 amdgpu_ucode_print_sdma_hdr(&hdr->header);
545 fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
546 fw_data = (const __le32 *)
547 (adev->sdma.instance[i].fw->data +
548 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
549 WREG32(mmSDMA0_UCODE_ADDR + sdma_offsets[i], 0);
550 for (j = 0; j < fw_size; j++)
551 WREG32(mmSDMA0_UCODE_DATA + sdma_offsets[i], le32_to_cpup(fw_data++));
552 WREG32(mmSDMA0_UCODE_ADDR + sdma_offsets[i], adev->sdma.instance[i].fw_version);
559 * sdma_v2_4_start - setup and start the async dma engines
561 * @adev: amdgpu_device pointer
563 * Set up the DMA engines and enable them (VI).
564 * Returns 0 for success, error for failure.
566 static int sdma_v2_4_start(struct amdgpu_device *adev)
570 if (!adev->pp_enabled) {
571 if (!adev->firmware.smu_load) {
572 r = sdma_v2_4_load_microcode(adev);
576 r = adev->smu.smumgr_funcs->check_fw_load_finish(adev,
577 AMDGPU_UCODE_ID_SDMA0);
580 r = adev->smu.smumgr_funcs->check_fw_load_finish(adev,
581 AMDGPU_UCODE_ID_SDMA1);
587 /* halt the engine before programing */
588 sdma_v2_4_enable(adev, false);
590 /* start the gfx rings and rlc compute queues */
591 r = sdma_v2_4_gfx_resume(adev);
594 r = sdma_v2_4_rlc_resume(adev);
602 * sdma_v2_4_ring_test_ring - simple async dma engine test
604 * @ring: amdgpu_ring structure holding ring information
606 * Test the DMA engine by writing using it to write an
607 * value to memory. (VI).
608 * Returns 0 for success, error for failure.
610 static int sdma_v2_4_ring_test_ring(struct amdgpu_ring *ring)
612 struct amdgpu_device *adev = ring->adev;
619 r = amdgpu_wb_get(adev, &index);
621 dev_err(adev->dev, "(%d) failed to allocate wb slot\n", r);
625 gpu_addr = adev->wb.gpu_addr + (index * 4);
627 adev->wb.wb[index] = cpu_to_le32(tmp);
629 r = amdgpu_ring_alloc(ring, 5);
631 DRM_ERROR("amdgpu: dma failed to lock ring %d (%d).\n", ring->idx, r);
632 amdgpu_wb_free(adev, index);
636 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
637 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR));
638 amdgpu_ring_write(ring, lower_32_bits(gpu_addr));
639 amdgpu_ring_write(ring, upper_32_bits(gpu_addr));
640 amdgpu_ring_write(ring, SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(1));
641 amdgpu_ring_write(ring, 0xDEADBEEF);
642 amdgpu_ring_commit(ring);
644 for (i = 0; i < adev->usec_timeout; i++) {
645 tmp = le32_to_cpu(adev->wb.wb[index]);
646 if (tmp == 0xDEADBEEF)
651 if (i < adev->usec_timeout) {
652 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
654 DRM_ERROR("amdgpu: ring %d test failed (0x%08X)\n",
658 amdgpu_wb_free(adev, index);
664 * sdma_v2_4_ring_test_ib - test an IB on the DMA engine
666 * @ring: amdgpu_ring structure holding ring information
668 * Test a simple IB in the DMA ring (VI).
669 * Returns 0 on success, error on failure.
671 static int sdma_v2_4_ring_test_ib(struct amdgpu_ring *ring, long timeout)
673 struct amdgpu_device *adev = ring->adev;
675 struct fence *f = NULL;
681 r = amdgpu_wb_get(adev, &index);
683 dev_err(adev->dev, "(%ld) failed to allocate wb slot\n", r);
687 gpu_addr = adev->wb.gpu_addr + (index * 4);
689 adev->wb.wb[index] = cpu_to_le32(tmp);
690 memset(&ib, 0, sizeof(ib));
691 r = amdgpu_ib_get(adev, NULL, 256, &ib);
693 DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
697 ib.ptr[0] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
698 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
699 ib.ptr[1] = lower_32_bits(gpu_addr);
700 ib.ptr[2] = upper_32_bits(gpu_addr);
701 ib.ptr[3] = SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(1);
702 ib.ptr[4] = 0xDEADBEEF;
703 ib.ptr[5] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
704 ib.ptr[6] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
705 ib.ptr[7] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
708 r = amdgpu_ib_schedule(ring, 1, &ib, NULL, NULL, &f);
712 r = fence_wait_timeout(f, false, timeout);
714 DRM_ERROR("amdgpu: IB test timed out\n");
718 DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
721 tmp = le32_to_cpu(adev->wb.wb[index]);
722 if (tmp == 0xDEADBEEF) {
723 DRM_INFO("ib test on ring %d succeeded\n", ring->idx);
726 DRM_ERROR("amdgpu: ib test failed (0x%08X)\n", tmp);
731 amdgpu_ib_free(adev, &ib, NULL);
734 amdgpu_wb_free(adev, index);
739 * sdma_v2_4_vm_copy_pte - update PTEs by copying them from the GART
741 * @ib: indirect buffer to fill with commands
742 * @pe: addr of the page entry
743 * @src: src addr to copy from
744 * @count: number of page entries to update
746 * Update PTEs by copying them from the GART using sDMA (CIK).
748 static void sdma_v2_4_vm_copy_pte(struct amdgpu_ib *ib,
749 uint64_t pe, uint64_t src,
753 unsigned bytes = count * 8;
754 if (bytes > 0x1FFFF8)
757 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
758 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
759 ib->ptr[ib->length_dw++] = bytes;
760 ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
761 ib->ptr[ib->length_dw++] = lower_32_bits(src);
762 ib->ptr[ib->length_dw++] = upper_32_bits(src);
763 ib->ptr[ib->length_dw++] = lower_32_bits(pe);
764 ib->ptr[ib->length_dw++] = upper_32_bits(pe);
773 * sdma_v2_4_vm_write_pte - update PTEs by writing them manually
775 * @ib: indirect buffer to fill with commands
776 * @pe: addr of the page entry
777 * @addr: dst addr to write into pe
778 * @count: number of page entries to update
779 * @incr: increase next addr by incr bytes
780 * @flags: access flags
782 * Update PTEs by writing them manually using sDMA (CIK).
784 static void sdma_v2_4_vm_write_pte(struct amdgpu_ib *ib,
785 const dma_addr_t *pages_addr, uint64_t pe,
786 uint64_t addr, unsigned count,
787 uint32_t incr, uint32_t flags)
797 /* for non-physically contiguous pages (system) */
798 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
799 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
800 ib->ptr[ib->length_dw++] = pe;
801 ib->ptr[ib->length_dw++] = upper_32_bits(pe);
802 ib->ptr[ib->length_dw++] = ndw;
803 for (; ndw > 0; ndw -= 2, --count, pe += 8) {
804 value = amdgpu_vm_map_gart(pages_addr, addr);
807 ib->ptr[ib->length_dw++] = value;
808 ib->ptr[ib->length_dw++] = upper_32_bits(value);
814 * sdma_v2_4_vm_set_pte_pde - update the page tables using sDMA
816 * @ib: indirect buffer to fill with commands
817 * @pe: addr of the page entry
818 * @addr: dst addr to write into pe
819 * @count: number of page entries to update
820 * @incr: increase next addr by incr bytes
821 * @flags: access flags
823 * Update the page tables using sDMA (CIK).
825 static void sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib *ib,
827 uint64_t addr, unsigned count,
828 uint32_t incr, uint32_t flags)
838 if (flags & AMDGPU_PTE_VALID)
843 /* for physically contiguous pages (vram) */
844 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE);
845 ib->ptr[ib->length_dw++] = pe; /* dst addr */
846 ib->ptr[ib->length_dw++] = upper_32_bits(pe);
847 ib->ptr[ib->length_dw++] = flags; /* mask */
848 ib->ptr[ib->length_dw++] = 0;
849 ib->ptr[ib->length_dw++] = value; /* value */
850 ib->ptr[ib->length_dw++] = upper_32_bits(value);
851 ib->ptr[ib->length_dw++] = incr; /* increment size */
852 ib->ptr[ib->length_dw++] = 0;
853 ib->ptr[ib->length_dw++] = ndw; /* number of entries */
862 * sdma_v2_4_ring_pad_ib - pad the IB to the required number of dw
864 * @ib: indirect buffer to fill with padding
867 static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
869 struct amdgpu_sdma_instance *sdma = amdgpu_get_sdma_instance(ring);
873 pad_count = (8 - (ib->length_dw & 0x7)) % 8;
874 for (i = 0; i < pad_count; i++)
875 if (sdma && sdma->burst_nop && (i == 0))
876 ib->ptr[ib->length_dw++] =
877 SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
878 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
880 ib->ptr[ib->length_dw++] =
881 SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
885 * sdma_v2_4_ring_emit_pipeline_sync - sync the pipeline
887 * @ring: amdgpu_ring pointer
889 * Make sure all previous operations are completed (CIK).
891 static void sdma_v2_4_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
893 uint32_t seq = ring->fence_drv.sync_seq;
894 uint64_t addr = ring->fence_drv.gpu_addr;
897 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
898 SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
899 SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3) | /* equal */
900 SDMA_PKT_POLL_REGMEM_HEADER_MEM_POLL(1));
901 amdgpu_ring_write(ring, addr & 0xfffffffc);
902 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
903 amdgpu_ring_write(ring, seq); /* reference */
904 amdgpu_ring_write(ring, 0xfffffff); /* mask */
905 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
906 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
910 * sdma_v2_4_ring_emit_vm_flush - cik vm flush using sDMA
912 * @ring: amdgpu_ring pointer
913 * @vm: amdgpu_vm pointer
915 * Update the page table base and flush the VM TLB
918 static void sdma_v2_4_ring_emit_vm_flush(struct amdgpu_ring *ring,
919 unsigned vm_id, uint64_t pd_addr)
921 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) |
922 SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf));
924 amdgpu_ring_write(ring, (mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR + vm_id));
926 amdgpu_ring_write(ring, (mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR + vm_id - 8));
928 amdgpu_ring_write(ring, pd_addr >> 12);
931 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) |
932 SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf));
933 amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
934 amdgpu_ring_write(ring, 1 << vm_id);
937 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
938 SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
939 SDMA_PKT_POLL_REGMEM_HEADER_FUNC(0)); /* always */
940 amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST << 2);
941 amdgpu_ring_write(ring, 0);
942 amdgpu_ring_write(ring, 0); /* reference */
943 amdgpu_ring_write(ring, 0); /* mask */
944 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
945 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10)); /* retry count, poll interval */
948 static int sdma_v2_4_early_init(void *handle)
950 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
952 adev->sdma.num_instances = SDMA_MAX_INSTANCE;
954 sdma_v2_4_set_ring_funcs(adev);
955 sdma_v2_4_set_buffer_funcs(adev);
956 sdma_v2_4_set_vm_pte_funcs(adev);
957 sdma_v2_4_set_irq_funcs(adev);
962 static int sdma_v2_4_sw_init(void *handle)
964 struct amdgpu_ring *ring;
966 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
968 /* SDMA trap event */
969 r = amdgpu_irq_add_id(adev, 224, &adev->sdma.trap_irq);
973 /* SDMA Privileged inst */
974 r = amdgpu_irq_add_id(adev, 241, &adev->sdma.illegal_inst_irq);
978 /* SDMA Privileged inst */
979 r = amdgpu_irq_add_id(adev, 247, &adev->sdma.illegal_inst_irq);
983 r = sdma_v2_4_init_microcode(adev);
985 DRM_ERROR("Failed to load sdma firmware!\n");
989 for (i = 0; i < adev->sdma.num_instances; i++) {
990 ring = &adev->sdma.instance[i].ring;
991 ring->ring_obj = NULL;
992 ring->use_doorbell = false;
993 sprintf(ring->name, "sdma%d", i);
994 r = amdgpu_ring_init(adev, ring, 1024,
995 SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP), 0xf,
996 &adev->sdma.trap_irq,
998 AMDGPU_SDMA_IRQ_TRAP0 : AMDGPU_SDMA_IRQ_TRAP1,
999 AMDGPU_RING_TYPE_SDMA);
1007 static int sdma_v2_4_sw_fini(void *handle)
1009 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1012 for (i = 0; i < adev->sdma.num_instances; i++)
1013 amdgpu_ring_fini(&adev->sdma.instance[i].ring);
1015 sdma_v2_4_free_microcode(adev);
1019 static int sdma_v2_4_hw_init(void *handle)
1022 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1024 sdma_v2_4_init_golden_registers(adev);
1026 r = sdma_v2_4_start(adev);
1033 static int sdma_v2_4_hw_fini(void *handle)
1035 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1037 sdma_v2_4_enable(adev, false);
1042 static int sdma_v2_4_suspend(void *handle)
1044 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1046 return sdma_v2_4_hw_fini(adev);
1049 static int sdma_v2_4_resume(void *handle)
1051 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1053 return sdma_v2_4_hw_init(adev);
1056 static bool sdma_v2_4_is_idle(void *handle)
1058 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1059 u32 tmp = RREG32(mmSRBM_STATUS2);
1061 if (tmp & (SRBM_STATUS2__SDMA_BUSY_MASK |
1062 SRBM_STATUS2__SDMA1_BUSY_MASK))
1068 static int sdma_v2_4_wait_for_idle(void *handle)
1072 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1074 for (i = 0; i < adev->usec_timeout; i++) {
1075 tmp = RREG32(mmSRBM_STATUS2) & (SRBM_STATUS2__SDMA_BUSY_MASK |
1076 SRBM_STATUS2__SDMA1_BUSY_MASK);
1085 static int sdma_v2_4_soft_reset(void *handle)
1087 u32 srbm_soft_reset = 0;
1088 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1089 u32 tmp = RREG32(mmSRBM_STATUS2);
1091 if (tmp & SRBM_STATUS2__SDMA_BUSY_MASK) {
1093 tmp = RREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET);
1094 tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 0);
1095 WREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET, tmp);
1096 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA_MASK;
1098 if (tmp & SRBM_STATUS2__SDMA1_BUSY_MASK) {
1100 tmp = RREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET);
1101 tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 0);
1102 WREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET, tmp);
1103 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA1_MASK;
1106 if (srbm_soft_reset) {
1107 tmp = RREG32(mmSRBM_SOFT_RESET);
1108 tmp |= srbm_soft_reset;
1109 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
1110 WREG32(mmSRBM_SOFT_RESET, tmp);
1111 tmp = RREG32(mmSRBM_SOFT_RESET);
1115 tmp &= ~srbm_soft_reset;
1116 WREG32(mmSRBM_SOFT_RESET, tmp);
1117 tmp = RREG32(mmSRBM_SOFT_RESET);
1119 /* Wait a little for things to settle down */
1126 static int sdma_v2_4_set_trap_irq_state(struct amdgpu_device *adev,
1127 struct amdgpu_irq_src *src,
1129 enum amdgpu_interrupt_state state)
1134 case AMDGPU_SDMA_IRQ_TRAP0:
1136 case AMDGPU_IRQ_STATE_DISABLE:
1137 sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET);
1138 sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 0);
1139 WREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET, sdma_cntl);
1141 case AMDGPU_IRQ_STATE_ENABLE:
1142 sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET);
1143 sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 1);
1144 WREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET, sdma_cntl);
1150 case AMDGPU_SDMA_IRQ_TRAP1:
1152 case AMDGPU_IRQ_STATE_DISABLE:
1153 sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET);
1154 sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 0);
1155 WREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET, sdma_cntl);
1157 case AMDGPU_IRQ_STATE_ENABLE:
1158 sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET);
1159 sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 1);
1160 WREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET, sdma_cntl);
1172 static int sdma_v2_4_process_trap_irq(struct amdgpu_device *adev,
1173 struct amdgpu_irq_src *source,
1174 struct amdgpu_iv_entry *entry)
1176 u8 instance_id, queue_id;
1178 instance_id = (entry->ring_id & 0x3) >> 0;
1179 queue_id = (entry->ring_id & 0xc) >> 2;
1180 DRM_DEBUG("IH: SDMA trap\n");
1181 switch (instance_id) {
1185 amdgpu_fence_process(&adev->sdma.instance[0].ring);
1198 amdgpu_fence_process(&adev->sdma.instance[1].ring);
1212 static int sdma_v2_4_process_illegal_inst_irq(struct amdgpu_device *adev,
1213 struct amdgpu_irq_src *source,
1214 struct amdgpu_iv_entry *entry)
1216 DRM_ERROR("Illegal instruction in SDMA command stream\n");
1217 schedule_work(&adev->reset_work);
1221 static int sdma_v2_4_set_clockgating_state(void *handle,
1222 enum amd_clockgating_state state)
1224 /* XXX handled via the smc on VI */
1228 static int sdma_v2_4_set_powergating_state(void *handle,
1229 enum amd_powergating_state state)
1234 const struct amd_ip_funcs sdma_v2_4_ip_funcs = {
1235 .name = "sdma_v2_4",
1236 .early_init = sdma_v2_4_early_init,
1238 .sw_init = sdma_v2_4_sw_init,
1239 .sw_fini = sdma_v2_4_sw_fini,
1240 .hw_init = sdma_v2_4_hw_init,
1241 .hw_fini = sdma_v2_4_hw_fini,
1242 .suspend = sdma_v2_4_suspend,
1243 .resume = sdma_v2_4_resume,
1244 .is_idle = sdma_v2_4_is_idle,
1245 .wait_for_idle = sdma_v2_4_wait_for_idle,
1246 .soft_reset = sdma_v2_4_soft_reset,
1247 .set_clockgating_state = sdma_v2_4_set_clockgating_state,
1248 .set_powergating_state = sdma_v2_4_set_powergating_state,
1251 static const struct amdgpu_ring_funcs sdma_v2_4_ring_funcs = {
1252 .get_rptr = sdma_v2_4_ring_get_rptr,
1253 .get_wptr = sdma_v2_4_ring_get_wptr,
1254 .set_wptr = sdma_v2_4_ring_set_wptr,
1256 .emit_ib = sdma_v2_4_ring_emit_ib,
1257 .emit_fence = sdma_v2_4_ring_emit_fence,
1258 .emit_pipeline_sync = sdma_v2_4_ring_emit_pipeline_sync,
1259 .emit_vm_flush = sdma_v2_4_ring_emit_vm_flush,
1260 .emit_hdp_flush = sdma_v2_4_ring_emit_hdp_flush,
1261 .emit_hdp_invalidate = sdma_v2_4_ring_emit_hdp_invalidate,
1262 .test_ring = sdma_v2_4_ring_test_ring,
1263 .test_ib = sdma_v2_4_ring_test_ib,
1264 .insert_nop = sdma_v2_4_ring_insert_nop,
1265 .pad_ib = sdma_v2_4_ring_pad_ib,
1268 static void sdma_v2_4_set_ring_funcs(struct amdgpu_device *adev)
1272 for (i = 0; i < adev->sdma.num_instances; i++)
1273 adev->sdma.instance[i].ring.funcs = &sdma_v2_4_ring_funcs;
1276 static const struct amdgpu_irq_src_funcs sdma_v2_4_trap_irq_funcs = {
1277 .set = sdma_v2_4_set_trap_irq_state,
1278 .process = sdma_v2_4_process_trap_irq,
1281 static const struct amdgpu_irq_src_funcs sdma_v2_4_illegal_inst_irq_funcs = {
1282 .process = sdma_v2_4_process_illegal_inst_irq,
1285 static void sdma_v2_4_set_irq_funcs(struct amdgpu_device *adev)
1287 adev->sdma.trap_irq.num_types = AMDGPU_SDMA_IRQ_LAST;
1288 adev->sdma.trap_irq.funcs = &sdma_v2_4_trap_irq_funcs;
1289 adev->sdma.illegal_inst_irq.funcs = &sdma_v2_4_illegal_inst_irq_funcs;
1293 * sdma_v2_4_emit_copy_buffer - copy buffer using the sDMA engine
1295 * @ring: amdgpu_ring structure holding ring information
1296 * @src_offset: src GPU address
1297 * @dst_offset: dst GPU address
1298 * @byte_count: number of bytes to xfer
1300 * Copy GPU buffers using the DMA engine (VI).
1301 * Used by the amdgpu ttm implementation to move pages if
1302 * registered as the asic copy callback.
1304 static void sdma_v2_4_emit_copy_buffer(struct amdgpu_ib *ib,
1305 uint64_t src_offset,
1306 uint64_t dst_offset,
1307 uint32_t byte_count)
1309 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
1310 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
1311 ib->ptr[ib->length_dw++] = byte_count;
1312 ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
1313 ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
1314 ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
1315 ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
1316 ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
1320 * sdma_v2_4_emit_fill_buffer - fill buffer using the sDMA engine
1322 * @ring: amdgpu_ring structure holding ring information
1323 * @src_data: value to write to buffer
1324 * @dst_offset: dst GPU address
1325 * @byte_count: number of bytes to xfer
1327 * Fill GPU buffers using the DMA engine (VI).
1329 static void sdma_v2_4_emit_fill_buffer(struct amdgpu_ib *ib,
1331 uint64_t dst_offset,
1332 uint32_t byte_count)
1334 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
1335 ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
1336 ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
1337 ib->ptr[ib->length_dw++] = src_data;
1338 ib->ptr[ib->length_dw++] = byte_count;
1341 static const struct amdgpu_buffer_funcs sdma_v2_4_buffer_funcs = {
1342 .copy_max_bytes = 0x1fffff,
1344 .emit_copy_buffer = sdma_v2_4_emit_copy_buffer,
1346 .fill_max_bytes = 0x1fffff,
1348 .emit_fill_buffer = sdma_v2_4_emit_fill_buffer,
1351 static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev)
1353 if (adev->mman.buffer_funcs == NULL) {
1354 adev->mman.buffer_funcs = &sdma_v2_4_buffer_funcs;
1355 adev->mman.buffer_funcs_ring = &adev->sdma.instance[0].ring;
1359 static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = {
1360 .copy_pte = sdma_v2_4_vm_copy_pte,
1361 .write_pte = sdma_v2_4_vm_write_pte,
1362 .set_pte_pde = sdma_v2_4_vm_set_pte_pde,
1365 static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev)
1369 if (adev->vm_manager.vm_pte_funcs == NULL) {
1370 adev->vm_manager.vm_pte_funcs = &sdma_v2_4_vm_pte_funcs;
1371 for (i = 0; i < adev->sdma.num_instances; i++)
1372 adev->vm_manager.vm_pte_rings[i] =
1373 &adev->sdma.instance[i].ring;
1375 adev->vm_manager.vm_pte_num_rings = adev->sdma.num_instances;