2 * Copyright 2013 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 "bif/bif_4_1_d.h"
33 #include "bif/bif_4_1_sh_mask.h"
35 #include "gca/gfx_7_2_d.h"
36 #include "gca/gfx_7_2_enum.h"
37 #include "gca/gfx_7_2_sh_mask.h"
39 #include "gmc/gmc_7_1_d.h"
40 #include "gmc/gmc_7_1_sh_mask.h"
42 #include "oss/oss_2_0_d.h"
43 #include "oss/oss_2_0_sh_mask.h"
45 static const u32 sdma_offsets
[SDMA_MAX_INSTANCE
] =
47 SDMA0_REGISTER_OFFSET
,
51 static void cik_sdma_set_ring_funcs(struct amdgpu_device
*adev
);
52 static void cik_sdma_set_irq_funcs(struct amdgpu_device
*adev
);
53 static void cik_sdma_set_buffer_funcs(struct amdgpu_device
*adev
);
54 static void cik_sdma_set_vm_pte_funcs(struct amdgpu_device
*adev
);
56 MODULE_FIRMWARE("radeon/bonaire_sdma.bin");
57 MODULE_FIRMWARE("radeon/bonaire_sdma1.bin");
58 MODULE_FIRMWARE("radeon/hawaii_sdma.bin");
59 MODULE_FIRMWARE("radeon/hawaii_sdma1.bin");
60 MODULE_FIRMWARE("radeon/kaveri_sdma.bin");
61 MODULE_FIRMWARE("radeon/kaveri_sdma1.bin");
62 MODULE_FIRMWARE("radeon/kabini_sdma.bin");
63 MODULE_FIRMWARE("radeon/kabini_sdma1.bin");
64 MODULE_FIRMWARE("radeon/mullins_sdma.bin");
65 MODULE_FIRMWARE("radeon/mullins_sdma1.bin");
67 u32
amdgpu_cik_gpu_check_soft_reset(struct amdgpu_device
*adev
);
71 * Starting with CIK, the GPU has new asynchronous
72 * DMA engines. These engines are used for compute
73 * and gfx. There are two DMA engines (SDMA0, SDMA1)
74 * and each one supports 1 ring buffer used for gfx
75 * and 2 queues used for compute.
77 * The programming model is very similar to the CP
78 * (ring buffer, IBs, etc.), but sDMA has it's own
79 * packet format that is different from the PM4 format
80 * used by the CP. sDMA supports copying data, writing
81 * embedded data, solid fills, and a number of other
82 * things. It also has support for tiling/detiling of
87 * cik_sdma_init_microcode - load ucode images from disk
89 * @adev: amdgpu_device pointer
91 * Use the firmware interface to load the ucode images into
92 * the driver (not loaded into hw).
93 * Returns 0 on success, error on failure.
95 static int cik_sdma_init_microcode(struct amdgpu_device
*adev
)
97 const char *chip_name
;
103 switch (adev
->asic_type
) {
105 chip_name
= "bonaire";
108 chip_name
= "hawaii";
111 chip_name
= "kaveri";
114 chip_name
= "kabini";
117 chip_name
= "mullins";
122 for (i
= 0; i
< SDMA_MAX_INSTANCE
; i
++) {
124 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_sdma.bin", chip_name
);
126 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_sdma1.bin", chip_name
);
127 err
= request_firmware(&adev
->sdma
[i
].fw
, fw_name
, adev
->dev
);
130 err
= amdgpu_ucode_validate(adev
->sdma
[i
].fw
);
135 "cik_sdma: Failed to load firmware \"%s\"\n",
137 for (i
= 0; i
< SDMA_MAX_INSTANCE
; i
++) {
138 release_firmware(adev
->sdma
[i
].fw
);
139 adev
->sdma
[i
].fw
= NULL
;
146 * cik_sdma_ring_get_rptr - get the current read pointer
148 * @ring: amdgpu ring pointer
150 * Get the current rptr from the hardware (CIK+).
152 static uint32_t cik_sdma_ring_get_rptr(struct amdgpu_ring
*ring
)
156 rptr
= ring
->adev
->wb
.wb
[ring
->rptr_offs
];
158 return (rptr
& 0x3fffc) >> 2;
162 * cik_sdma_ring_get_wptr - get the current write pointer
164 * @ring: amdgpu ring pointer
166 * Get the current wptr from the hardware (CIK+).
168 static uint32_t cik_sdma_ring_get_wptr(struct amdgpu_ring
*ring
)
170 struct amdgpu_device
*adev
= ring
->adev
;
171 u32 me
= (ring
== &adev
->sdma
[0].ring
) ? 0 : 1;
173 return (RREG32(mmSDMA0_GFX_RB_WPTR
+ sdma_offsets
[me
]) & 0x3fffc) >> 2;
177 * cik_sdma_ring_set_wptr - commit the write pointer
179 * @ring: amdgpu ring pointer
181 * Write the wptr back to the hardware (CIK+).
183 static void cik_sdma_ring_set_wptr(struct amdgpu_ring
*ring
)
185 struct amdgpu_device
*adev
= ring
->adev
;
186 u32 me
= (ring
== &adev
->sdma
[0].ring
) ? 0 : 1;
188 WREG32(mmSDMA0_GFX_RB_WPTR
+ sdma_offsets
[me
], (ring
->wptr
<< 2) & 0x3fffc);
192 * cik_sdma_ring_emit_ib - Schedule an IB on the DMA engine
194 * @ring: amdgpu ring pointer
195 * @ib: IB object to schedule
197 * Schedule an IB in the DMA ring (CIK).
199 static void cik_sdma_ring_emit_ib(struct amdgpu_ring
*ring
,
200 struct amdgpu_ib
*ib
)
202 u32 extra_bits
= (ib
->vm
? ib
->vm
->ids
[ring
->idx
].id
: 0) & 0xf;
203 u32 next_rptr
= ring
->wptr
+ 5;
205 while ((next_rptr
& 7) != 4)
209 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_WRITE
, SDMA_WRITE_SUB_OPCODE_LINEAR
, 0));
210 amdgpu_ring_write(ring
, ring
->next_rptr_gpu_addr
& 0xfffffffc);
211 amdgpu_ring_write(ring
, upper_32_bits(ring
->next_rptr_gpu_addr
) & 0xffffffff);
212 amdgpu_ring_write(ring
, 1); /* number of DWs to follow */
213 amdgpu_ring_write(ring
, next_rptr
);
215 /* IB packet must end on a 8 DW boundary */
216 while ((ring
->wptr
& 7) != 4)
217 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_NOP
, 0, 0));
218 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_INDIRECT_BUFFER
, 0, extra_bits
));
219 amdgpu_ring_write(ring
, ib
->gpu_addr
& 0xffffffe0); /* base must be 32 byte aligned */
220 amdgpu_ring_write(ring
, upper_32_bits(ib
->gpu_addr
) & 0xffffffff);
221 amdgpu_ring_write(ring
, ib
->length_dw
);
226 * cik_sdma_ring_emit_hdp_flush - emit an hdp flush on the DMA ring
228 * @ring: amdgpu ring pointer
230 * Emit an hdp flush packet on the requested DMA ring.
232 static void cik_sdma_ring_emit_hdp_flush(struct amdgpu_ring
*ring
)
234 u32 extra_bits
= (SDMA_POLL_REG_MEM_EXTRA_OP(1) |
235 SDMA_POLL_REG_MEM_EXTRA_FUNC(3)); /* == */
238 if (ring
== &ring
->adev
->sdma
[0].ring
)
239 ref_and_mask
= GPU_HDP_FLUSH_DONE__SDMA0_MASK
;
241 ref_and_mask
= GPU_HDP_FLUSH_DONE__SDMA1_MASK
;
243 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_POLL_REG_MEM
, 0, extra_bits
));
244 amdgpu_ring_write(ring
, mmGPU_HDP_FLUSH_DONE
<< 2);
245 amdgpu_ring_write(ring
, mmGPU_HDP_FLUSH_REQ
<< 2);
246 amdgpu_ring_write(ring
, ref_and_mask
); /* reference */
247 amdgpu_ring_write(ring
, ref_and_mask
); /* mask */
248 amdgpu_ring_write(ring
, (0xfff << 16) | 10); /* retry count, poll interval */
252 * cik_sdma_ring_emit_fence - emit a fence on the DMA ring
254 * @ring: amdgpu ring pointer
255 * @fence: amdgpu fence object
257 * Add a DMA fence packet to the ring to write
258 * the fence seq number and DMA trap packet to generate
259 * an interrupt if needed (CIK).
261 static void cik_sdma_ring_emit_fence(struct amdgpu_ring
*ring
, u64 addr
, u64 seq
,
264 bool write64bit
= flags
& AMDGPU_FENCE_FLAG_64BIT
;
265 /* write the fence */
266 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_FENCE
, 0, 0));
267 amdgpu_ring_write(ring
, lower_32_bits(addr
));
268 amdgpu_ring_write(ring
, upper_32_bits(addr
));
269 amdgpu_ring_write(ring
, lower_32_bits(seq
));
271 /* optionally write high bits as well */
274 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_FENCE
, 0, 0));
275 amdgpu_ring_write(ring
, lower_32_bits(addr
));
276 amdgpu_ring_write(ring
, upper_32_bits(addr
));
277 amdgpu_ring_write(ring
, upper_32_bits(seq
));
280 /* generate an interrupt */
281 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_TRAP
, 0, 0));
285 * cik_sdma_ring_emit_semaphore - emit a semaphore on the dma ring
287 * @ring: amdgpu_ring structure holding ring information
288 * @semaphore: amdgpu semaphore object
289 * @emit_wait: wait or signal semaphore
291 * Add a DMA semaphore packet to the ring wait on or signal
294 static bool cik_sdma_ring_emit_semaphore(struct amdgpu_ring
*ring
,
295 struct amdgpu_semaphore
*semaphore
,
298 u64 addr
= semaphore
->gpu_addr
;
299 u32 extra_bits
= emit_wait
? 0 : SDMA_SEMAPHORE_EXTRA_S
;
301 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_SEMAPHORE
, 0, extra_bits
));
302 amdgpu_ring_write(ring
, addr
& 0xfffffff8);
303 amdgpu_ring_write(ring
, upper_32_bits(addr
) & 0xffffffff);
309 * cik_sdma_gfx_stop - stop the gfx async dma engines
311 * @adev: amdgpu_device pointer
313 * Stop the gfx async dma ring buffers (CIK).
315 static void cik_sdma_gfx_stop(struct amdgpu_device
*adev
)
317 struct amdgpu_ring
*sdma0
= &adev
->sdma
[0].ring
;
318 struct amdgpu_ring
*sdma1
= &adev
->sdma
[1].ring
;
322 if ((adev
->mman
.buffer_funcs_ring
== sdma0
) ||
323 (adev
->mman
.buffer_funcs_ring
== sdma1
))
324 amdgpu_ttm_set_active_vram_size(adev
, adev
->mc
.visible_vram_size
);
326 for (i
= 0; i
< SDMA_MAX_INSTANCE
; i
++) {
327 rb_cntl
= RREG32(mmSDMA0_GFX_RB_CNTL
+ sdma_offsets
[i
]);
328 rb_cntl
&= ~SDMA0_GFX_RB_CNTL__RB_ENABLE_MASK
;
329 WREG32(mmSDMA0_GFX_RB_CNTL
+ sdma_offsets
[i
], rb_cntl
);
330 WREG32(mmSDMA0_GFX_IB_CNTL
+ sdma_offsets
[i
], 0);
332 sdma0
->ready
= false;
333 sdma1
->ready
= false;
337 * cik_sdma_rlc_stop - stop the compute async dma engines
339 * @adev: amdgpu_device pointer
341 * Stop the compute async dma queues (CIK).
343 static void cik_sdma_rlc_stop(struct amdgpu_device
*adev
)
349 * cik_sdma_enable - stop the async dma engines
351 * @adev: amdgpu_device pointer
352 * @enable: enable/disable the DMA MEs.
354 * Halt or unhalt the async dma engines (CIK).
356 static void cik_sdma_enable(struct amdgpu_device
*adev
, bool enable
)
361 if (enable
== false) {
362 cik_sdma_gfx_stop(adev
);
363 cik_sdma_rlc_stop(adev
);
366 for (i
= 0; i
< SDMA_MAX_INSTANCE
; i
++) {
367 me_cntl
= RREG32(mmSDMA0_F32_CNTL
+ sdma_offsets
[i
]);
369 me_cntl
&= ~SDMA0_F32_CNTL__HALT_MASK
;
371 me_cntl
|= SDMA0_F32_CNTL__HALT_MASK
;
372 WREG32(mmSDMA0_F32_CNTL
+ sdma_offsets
[i
], me_cntl
);
377 * cik_sdma_gfx_resume - setup and start the async dma engines
379 * @adev: amdgpu_device pointer
381 * Set up the gfx DMA ring buffers and enable them (CIK).
382 * Returns 0 for success, error for failure.
384 static int cik_sdma_gfx_resume(struct amdgpu_device
*adev
)
386 struct amdgpu_ring
*ring
;
387 u32 rb_cntl
, ib_cntl
;
392 for (i
= 0; i
< SDMA_MAX_INSTANCE
; i
++) {
393 ring
= &adev
->sdma
[i
].ring
;
394 wb_offset
= (ring
->rptr_offs
* 4);
396 mutex_lock(&adev
->srbm_mutex
);
397 for (j
= 0; j
< 16; j
++) {
398 cik_srbm_select(adev
, 0, 0, 0, j
);
400 WREG32(mmSDMA0_GFX_VIRTUAL_ADDR
+ sdma_offsets
[i
], 0);
401 WREG32(mmSDMA0_GFX_APE1_CNTL
+ sdma_offsets
[i
], 0);
402 /* XXX SDMA RLC - todo */
404 cik_srbm_select(adev
, 0, 0, 0, 0);
405 mutex_unlock(&adev
->srbm_mutex
);
407 WREG32(mmSDMA0_SEM_INCOMPLETE_TIMER_CNTL
+ sdma_offsets
[i
], 0);
408 WREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL
+ sdma_offsets
[i
], 0);
410 /* Set ring buffer size in dwords */
411 rb_bufsz
= order_base_2(ring
->ring_size
/ 4);
412 rb_cntl
= rb_bufsz
<< 1;
414 rb_cntl
|= SDMA0_GFX_RB_CNTL__RB_SWAP_ENABLE_MASK
|
415 SDMA0_GFX_RB_CNTL__RPTR_WRITEBACK_SWAP_ENABLE_MASK
;
417 WREG32(mmSDMA0_GFX_RB_CNTL
+ sdma_offsets
[i
], rb_cntl
);
419 /* Initialize the ring buffer's read and write pointers */
420 WREG32(mmSDMA0_GFX_RB_RPTR
+ sdma_offsets
[i
], 0);
421 WREG32(mmSDMA0_GFX_RB_WPTR
+ sdma_offsets
[i
], 0);
423 /* set the wb address whether it's enabled or not */
424 WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI
+ sdma_offsets
[i
],
425 upper_32_bits(adev
->wb
.gpu_addr
+ wb_offset
) & 0xFFFFFFFF);
426 WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO
+ sdma_offsets
[i
],
427 ((adev
->wb
.gpu_addr
+ wb_offset
) & 0xFFFFFFFC));
429 rb_cntl
|= SDMA0_GFX_RB_CNTL__RPTR_WRITEBACK_ENABLE_MASK
;
431 WREG32(mmSDMA0_GFX_RB_BASE
+ sdma_offsets
[i
], ring
->gpu_addr
>> 8);
432 WREG32(mmSDMA0_GFX_RB_BASE_HI
+ sdma_offsets
[i
], ring
->gpu_addr
>> 40);
435 WREG32(mmSDMA0_GFX_RB_WPTR
+ sdma_offsets
[i
], ring
->wptr
<< 2);
438 WREG32(mmSDMA0_GFX_RB_CNTL
+ sdma_offsets
[i
],
439 rb_cntl
| SDMA0_GFX_RB_CNTL__RB_ENABLE_MASK
);
441 ib_cntl
= SDMA0_GFX_IB_CNTL__IB_ENABLE_MASK
;
443 ib_cntl
|= SDMA0_GFX_IB_CNTL__IB_SWAP_ENABLE_MASK
;
446 WREG32(mmSDMA0_GFX_IB_CNTL
+ sdma_offsets
[i
], ib_cntl
);
450 r
= amdgpu_ring_test_ring(ring
);
456 if (adev
->mman
.buffer_funcs_ring
== ring
)
457 amdgpu_ttm_set_active_vram_size(adev
, adev
->mc
.real_vram_size
);
464 * cik_sdma_rlc_resume - setup and start the async dma engines
466 * @adev: amdgpu_device pointer
468 * Set up the compute DMA queues and enable them (CIK).
469 * Returns 0 for success, error for failure.
471 static int cik_sdma_rlc_resume(struct amdgpu_device
*adev
)
478 * cik_sdma_load_microcode - load the sDMA ME ucode
480 * @adev: amdgpu_device pointer
482 * Loads the sDMA0/1 ucode.
483 * Returns 0 for success, -EINVAL if the ucode is not available.
485 static int cik_sdma_load_microcode(struct amdgpu_device
*adev
)
487 const struct sdma_firmware_header_v1_0
*hdr
;
488 const __le32
*fw_data
;
492 if (!adev
->sdma
[0].fw
|| !adev
->sdma
[1].fw
)
496 cik_sdma_enable(adev
, false);
498 for (i
= 0; i
< SDMA_MAX_INSTANCE
; i
++) {
499 hdr
= (const struct sdma_firmware_header_v1_0
*)adev
->sdma
[i
].fw
->data
;
500 amdgpu_ucode_print_sdma_hdr(&hdr
->header
);
501 fw_size
= le32_to_cpu(hdr
->header
.ucode_size_bytes
) / 4;
502 adev
->sdma
[i
].fw_version
= le32_to_cpu(hdr
->header
.ucode_version
);
503 adev
->sdma
[i
].feature_version
= le32_to_cpu(hdr
->ucode_feature_version
);
504 fw_data
= (const __le32
*)
505 (adev
->sdma
[i
].fw
->data
+ le32_to_cpu(hdr
->header
.ucode_array_offset_bytes
));
506 WREG32(mmSDMA0_UCODE_ADDR
+ sdma_offsets
[i
], 0);
507 for (j
= 0; j
< fw_size
; j
++)
508 WREG32(mmSDMA0_UCODE_DATA
+ sdma_offsets
[i
], le32_to_cpup(fw_data
++));
509 WREG32(mmSDMA0_UCODE_ADDR
+ sdma_offsets
[i
], adev
->sdma
[i
].fw_version
);
516 * cik_sdma_start - setup and start the async dma engines
518 * @adev: amdgpu_device pointer
520 * Set up the DMA engines and enable them (CIK).
521 * Returns 0 for success, error for failure.
523 static int cik_sdma_start(struct amdgpu_device
*adev
)
527 r
= cik_sdma_load_microcode(adev
);
532 cik_sdma_enable(adev
, true);
534 /* start the gfx rings and rlc compute queues */
535 r
= cik_sdma_gfx_resume(adev
);
538 r
= cik_sdma_rlc_resume(adev
);
546 * cik_sdma_ring_test_ring - simple async dma engine test
548 * @ring: amdgpu_ring structure holding ring information
550 * Test the DMA engine by writing using it to write an
551 * value to memory. (CIK).
552 * Returns 0 for success, error for failure.
554 static int cik_sdma_ring_test_ring(struct amdgpu_ring
*ring
)
556 struct amdgpu_device
*adev
= ring
->adev
;
563 r
= amdgpu_wb_get(adev
, &index
);
565 dev_err(adev
->dev
, "(%d) failed to allocate wb slot\n", r
);
569 gpu_addr
= adev
->wb
.gpu_addr
+ (index
* 4);
571 adev
->wb
.wb
[index
] = cpu_to_le32(tmp
);
573 r
= amdgpu_ring_lock(ring
, 5);
575 DRM_ERROR("amdgpu: dma failed to lock ring %d (%d).\n", ring
->idx
, r
);
576 amdgpu_wb_free(adev
, index
);
579 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_WRITE
, SDMA_WRITE_SUB_OPCODE_LINEAR
, 0));
580 amdgpu_ring_write(ring
, lower_32_bits(gpu_addr
));
581 amdgpu_ring_write(ring
, upper_32_bits(gpu_addr
));
582 amdgpu_ring_write(ring
, 1); /* number of DWs to follow */
583 amdgpu_ring_write(ring
, 0xDEADBEEF);
584 amdgpu_ring_unlock_commit(ring
);
586 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
587 tmp
= le32_to_cpu(adev
->wb
.wb
[index
]);
588 if (tmp
== 0xDEADBEEF)
593 if (i
< adev
->usec_timeout
) {
594 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring
->idx
, i
);
596 DRM_ERROR("amdgpu: ring %d test failed (0x%08X)\n",
600 amdgpu_wb_free(adev
, index
);
606 * cik_sdma_ring_test_ib - test an IB on the DMA engine
608 * @ring: amdgpu_ring structure holding ring information
610 * Test a simple IB in the DMA ring (CIK).
611 * Returns 0 on success, error on failure.
613 static int cik_sdma_ring_test_ib(struct amdgpu_ring
*ring
)
615 struct amdgpu_device
*adev
= ring
->adev
;
623 r
= amdgpu_wb_get(adev
, &index
);
625 dev_err(adev
->dev
, "(%d) failed to allocate wb slot\n", r
);
629 gpu_addr
= adev
->wb
.gpu_addr
+ (index
* 4);
631 adev
->wb
.wb
[index
] = cpu_to_le32(tmp
);
633 r
= amdgpu_ib_get(ring
, NULL
, 256, &ib
);
635 amdgpu_wb_free(adev
, index
);
636 DRM_ERROR("amdgpu: failed to get ib (%d).\n", r
);
640 ib
.ptr
[0] = SDMA_PACKET(SDMA_OPCODE_WRITE
, SDMA_WRITE_SUB_OPCODE_LINEAR
, 0);
641 ib
.ptr
[1] = lower_32_bits(gpu_addr
);
642 ib
.ptr
[2] = upper_32_bits(gpu_addr
);
644 ib
.ptr
[4] = 0xDEADBEEF;
647 r
= amdgpu_ib_schedule(adev
, 1, &ib
, AMDGPU_FENCE_OWNER_UNDEFINED
);
649 amdgpu_ib_free(adev
, &ib
);
650 amdgpu_wb_free(adev
, index
);
651 DRM_ERROR("amdgpu: failed to schedule ib (%d).\n", r
);
654 r
= amdgpu_fence_wait(ib
.fence
, false);
656 amdgpu_ib_free(adev
, &ib
);
657 amdgpu_wb_free(adev
, index
);
658 DRM_ERROR("amdgpu: fence wait failed (%d).\n", r
);
661 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
662 tmp
= le32_to_cpu(adev
->wb
.wb
[index
]);
663 if (tmp
== 0xDEADBEEF)
667 if (i
< adev
->usec_timeout
) {
668 DRM_INFO("ib test on ring %d succeeded in %u usecs\n",
669 ib
.fence
->ring
->idx
, i
);
671 DRM_ERROR("amdgpu: ib test failed (0x%08X)\n", tmp
);
674 amdgpu_ib_free(adev
, &ib
);
675 amdgpu_wb_free(adev
, index
);
680 * cik_sdma_vm_copy_pages - update PTEs by copying them from the GART
682 * @ib: indirect buffer to fill with commands
683 * @pe: addr of the page entry
684 * @src: src addr to copy from
685 * @count: number of page entries to update
687 * Update PTEs by copying them from the GART using sDMA (CIK).
689 static void cik_sdma_vm_copy_pte(struct amdgpu_ib
*ib
,
690 uint64_t pe
, uint64_t src
,
694 unsigned bytes
= count
* 8;
695 if (bytes
> 0x1FFFF8)
698 ib
->ptr
[ib
->length_dw
++] = SDMA_PACKET(SDMA_OPCODE_COPY
,
699 SDMA_WRITE_SUB_OPCODE_LINEAR
, 0);
700 ib
->ptr
[ib
->length_dw
++] = bytes
;
701 ib
->ptr
[ib
->length_dw
++] = 0; /* src/dst endian swap */
702 ib
->ptr
[ib
->length_dw
++] = lower_32_bits(src
);
703 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(src
);
704 ib
->ptr
[ib
->length_dw
++] = lower_32_bits(pe
);
705 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(pe
);
714 * cik_sdma_vm_write_pages - update PTEs by writing them manually
716 * @ib: indirect buffer to fill with commands
717 * @pe: addr of the page entry
718 * @addr: dst addr to write into pe
719 * @count: number of page entries to update
720 * @incr: increase next addr by incr bytes
721 * @flags: access flags
723 * Update PTEs by writing them manually using sDMA (CIK).
725 static void cik_sdma_vm_write_pte(struct amdgpu_ib
*ib
,
727 uint64_t addr
, unsigned count
,
728 uint32_t incr
, uint32_t flags
)
738 /* for non-physically contiguous pages (system) */
739 ib
->ptr
[ib
->length_dw
++] = SDMA_PACKET(SDMA_OPCODE_WRITE
,
740 SDMA_WRITE_SUB_OPCODE_LINEAR
, 0);
741 ib
->ptr
[ib
->length_dw
++] = pe
;
742 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(pe
);
743 ib
->ptr
[ib
->length_dw
++] = ndw
;
744 for (; ndw
> 0; ndw
-= 2, --count
, pe
+= 8) {
745 if (flags
& AMDGPU_PTE_SYSTEM
) {
746 value
= amdgpu_vm_map_gart(ib
->ring
->adev
, addr
);
747 value
&= 0xFFFFFFFFFFFFF000ULL
;
748 } else if (flags
& AMDGPU_PTE_VALID
) {
755 ib
->ptr
[ib
->length_dw
++] = value
;
756 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(value
);
762 * cik_sdma_vm_set_pages - update the page tables using sDMA
764 * @ib: indirect buffer to fill with commands
765 * @pe: addr of the page entry
766 * @addr: dst addr to write into pe
767 * @count: number of page entries to update
768 * @incr: increase next addr by incr bytes
769 * @flags: access flags
771 * Update the page tables using sDMA (CIK).
773 static void cik_sdma_vm_set_pte_pde(struct amdgpu_ib
*ib
,
775 uint64_t addr
, unsigned count
,
776 uint32_t incr
, uint32_t flags
)
786 if (flags
& AMDGPU_PTE_VALID
)
791 /* for physically contiguous pages (vram) */
792 ib
->ptr
[ib
->length_dw
++] = SDMA_PACKET(SDMA_OPCODE_GENERATE_PTE_PDE
, 0, 0);
793 ib
->ptr
[ib
->length_dw
++] = pe
; /* dst addr */
794 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(pe
);
795 ib
->ptr
[ib
->length_dw
++] = flags
; /* mask */
796 ib
->ptr
[ib
->length_dw
++] = 0;
797 ib
->ptr
[ib
->length_dw
++] = value
; /* value */
798 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(value
);
799 ib
->ptr
[ib
->length_dw
++] = incr
; /* increment size */
800 ib
->ptr
[ib
->length_dw
++] = 0;
801 ib
->ptr
[ib
->length_dw
++] = ndw
; /* number of entries */
810 * cik_sdma_vm_pad_ib - pad the IB to the required number of dw
812 * @ib: indirect buffer to fill with padding
815 static void cik_sdma_vm_pad_ib(struct amdgpu_ib
*ib
)
817 while (ib
->length_dw
& 0x7)
818 ib
->ptr
[ib
->length_dw
++] = SDMA_PACKET(SDMA_OPCODE_NOP
, 0, 0);
822 * cik_sdma_ring_emit_vm_flush - cik vm flush using sDMA
824 * @ring: amdgpu_ring pointer
825 * @vm: amdgpu_vm pointer
827 * Update the page table base and flush the VM TLB
830 static void cik_sdma_ring_emit_vm_flush(struct amdgpu_ring
*ring
,
831 unsigned vm_id
, uint64_t pd_addr
)
833 u32 extra_bits
= (SDMA_POLL_REG_MEM_EXTRA_OP(0) |
834 SDMA_POLL_REG_MEM_EXTRA_FUNC(0)); /* always */
836 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE
, 0, 0xf000));
838 amdgpu_ring_write(ring
, (mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR
+ vm_id
));
840 amdgpu_ring_write(ring
, (mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR
+ vm_id
- 8));
842 amdgpu_ring_write(ring
, pd_addr
>> 12);
845 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE
, 0, 0xf000));
846 amdgpu_ring_write(ring
, mmVM_INVALIDATE_REQUEST
);
847 amdgpu_ring_write(ring
, 1 << vm_id
);
849 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_POLL_REG_MEM
, 0, extra_bits
));
850 amdgpu_ring_write(ring
, mmVM_INVALIDATE_REQUEST
<< 2);
851 amdgpu_ring_write(ring
, 0);
852 amdgpu_ring_write(ring
, 0); /* reference */
853 amdgpu_ring_write(ring
, 0); /* mask */
854 amdgpu_ring_write(ring
, (0xfff << 16) | 10); /* retry count, poll interval */
857 static void cik_enable_sdma_mgcg(struct amdgpu_device
*adev
,
862 if (enable
&& (adev
->cg_flags
& AMDGPU_CG_SUPPORT_SDMA_MGCG
)) {
863 WREG32(mmSDMA0_CLK_CTRL
+ SDMA0_REGISTER_OFFSET
, 0x00000100);
864 WREG32(mmSDMA0_CLK_CTRL
+ SDMA1_REGISTER_OFFSET
, 0x00000100);
866 orig
= data
= RREG32(mmSDMA0_CLK_CTRL
+ SDMA0_REGISTER_OFFSET
);
869 WREG32(mmSDMA0_CLK_CTRL
+ SDMA0_REGISTER_OFFSET
, data
);
871 orig
= data
= RREG32(mmSDMA0_CLK_CTRL
+ SDMA1_REGISTER_OFFSET
);
874 WREG32(mmSDMA0_CLK_CTRL
+ SDMA1_REGISTER_OFFSET
, data
);
878 static void cik_enable_sdma_mgls(struct amdgpu_device
*adev
,
883 if (enable
&& (adev
->cg_flags
& AMDGPU_CG_SUPPORT_SDMA_LS
)) {
884 orig
= data
= RREG32(mmSDMA0_POWER_CNTL
+ SDMA0_REGISTER_OFFSET
);
887 WREG32(mmSDMA0_POWER_CNTL
+ SDMA0_REGISTER_OFFSET
, data
);
889 orig
= data
= RREG32(mmSDMA0_POWER_CNTL
+ SDMA1_REGISTER_OFFSET
);
892 WREG32(mmSDMA0_POWER_CNTL
+ SDMA1_REGISTER_OFFSET
, data
);
894 orig
= data
= RREG32(mmSDMA0_POWER_CNTL
+ SDMA0_REGISTER_OFFSET
);
897 WREG32(mmSDMA0_POWER_CNTL
+ SDMA0_REGISTER_OFFSET
, data
);
899 orig
= data
= RREG32(mmSDMA0_POWER_CNTL
+ SDMA1_REGISTER_OFFSET
);
902 WREG32(mmSDMA0_POWER_CNTL
+ SDMA1_REGISTER_OFFSET
, data
);
906 static int cik_sdma_early_init(void *handle
)
908 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
910 cik_sdma_set_ring_funcs(adev
);
911 cik_sdma_set_irq_funcs(adev
);
912 cik_sdma_set_buffer_funcs(adev
);
913 cik_sdma_set_vm_pte_funcs(adev
);
918 static int cik_sdma_sw_init(void *handle
)
920 struct amdgpu_ring
*ring
;
921 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
924 r
= cik_sdma_init_microcode(adev
);
926 DRM_ERROR("Failed to load sdma firmware!\n");
930 /* SDMA trap event */
931 r
= amdgpu_irq_add_id(adev
, 224, &adev
->sdma_trap_irq
);
935 /* SDMA Privileged inst */
936 r
= amdgpu_irq_add_id(adev
, 241, &adev
->sdma_illegal_inst_irq
);
940 /* SDMA Privileged inst */
941 r
= amdgpu_irq_add_id(adev
, 247, &adev
->sdma_illegal_inst_irq
);
945 ring
= &adev
->sdma
[0].ring
;
946 ring
->ring_obj
= NULL
;
948 ring
= &adev
->sdma
[1].ring
;
949 ring
->ring_obj
= NULL
;
951 ring
= &adev
->sdma
[0].ring
;
952 sprintf(ring
->name
, "sdma0");
953 r
= amdgpu_ring_init(adev
, ring
, 256 * 1024,
954 SDMA_PACKET(SDMA_OPCODE_NOP
, 0, 0), 0xf,
955 &adev
->sdma_trap_irq
, AMDGPU_SDMA_IRQ_TRAP0
,
956 AMDGPU_RING_TYPE_SDMA
);
960 ring
= &adev
->sdma
[1].ring
;
961 sprintf(ring
->name
, "sdma1");
962 r
= amdgpu_ring_init(adev
, ring
, 256 * 1024,
963 SDMA_PACKET(SDMA_OPCODE_NOP
, 0, 0), 0xf,
964 &adev
->sdma_trap_irq
, AMDGPU_SDMA_IRQ_TRAP1
,
965 AMDGPU_RING_TYPE_SDMA
);
972 static int cik_sdma_sw_fini(void *handle
)
974 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
976 amdgpu_ring_fini(&adev
->sdma
[0].ring
);
977 amdgpu_ring_fini(&adev
->sdma
[1].ring
);
982 static int cik_sdma_hw_init(void *handle
)
985 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
987 r
= cik_sdma_start(adev
);
994 static int cik_sdma_hw_fini(void *handle
)
996 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
998 cik_sdma_enable(adev
, false);
1003 static int cik_sdma_suspend(void *handle
)
1005 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1007 return cik_sdma_hw_fini(adev
);
1010 static int cik_sdma_resume(void *handle
)
1012 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1014 return cik_sdma_hw_init(adev
);
1017 static bool cik_sdma_is_idle(void *handle
)
1019 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1020 u32 tmp
= RREG32(mmSRBM_STATUS2
);
1022 if (tmp
& (SRBM_STATUS2__SDMA_BUSY_MASK
|
1023 SRBM_STATUS2__SDMA1_BUSY_MASK
))
1029 static int cik_sdma_wait_for_idle(void *handle
)
1033 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1035 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
1036 tmp
= RREG32(mmSRBM_STATUS2
) & (SRBM_STATUS2__SDMA_BUSY_MASK
|
1037 SRBM_STATUS2__SDMA1_BUSY_MASK
);
1046 static void cik_sdma_print_status(void *handle
)
1049 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1051 dev_info(adev
->dev
, "CIK SDMA registers\n");
1052 dev_info(adev
->dev
, " SRBM_STATUS2=0x%08X\n",
1053 RREG32(mmSRBM_STATUS2
));
1054 for (i
= 0; i
< SDMA_MAX_INSTANCE
; i
++) {
1055 dev_info(adev
->dev
, " SDMA%d_STATUS_REG=0x%08X\n",
1056 i
, RREG32(mmSDMA0_STATUS_REG
+ sdma_offsets
[i
]));
1057 dev_info(adev
->dev
, " SDMA%d_ME_CNTL=0x%08X\n",
1058 i
, RREG32(mmSDMA0_F32_CNTL
+ sdma_offsets
[i
]));
1059 dev_info(adev
->dev
, " SDMA%d_CNTL=0x%08X\n",
1060 i
, RREG32(mmSDMA0_CNTL
+ sdma_offsets
[i
]));
1061 dev_info(adev
->dev
, " SDMA%d_SEM_INCOMPLETE_TIMER_CNTL=0x%08X\n",
1062 i
, RREG32(mmSDMA0_SEM_INCOMPLETE_TIMER_CNTL
+ sdma_offsets
[i
]));
1063 dev_info(adev
->dev
, " SDMA%d_SEM_WAIT_FAIL_TIMER_CNTL=0x%08X\n",
1064 i
, RREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL
+ sdma_offsets
[i
]));
1065 dev_info(adev
->dev
, " SDMA%d_GFX_IB_CNTL=0x%08X\n",
1066 i
, RREG32(mmSDMA0_GFX_IB_CNTL
+ sdma_offsets
[i
]));
1067 dev_info(adev
->dev
, " SDMA%d_GFX_RB_CNTL=0x%08X\n",
1068 i
, RREG32(mmSDMA0_GFX_RB_CNTL
+ sdma_offsets
[i
]));
1069 dev_info(adev
->dev
, " SDMA%d_GFX_RB_RPTR=0x%08X\n",
1070 i
, RREG32(mmSDMA0_GFX_RB_RPTR
+ sdma_offsets
[i
]));
1071 dev_info(adev
->dev
, " SDMA%d_GFX_RB_WPTR=0x%08X\n",
1072 i
, RREG32(mmSDMA0_GFX_RB_WPTR
+ sdma_offsets
[i
]));
1073 dev_info(adev
->dev
, " SDMA%d_GFX_RB_RPTR_ADDR_HI=0x%08X\n",
1074 i
, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI
+ sdma_offsets
[i
]));
1075 dev_info(adev
->dev
, " SDMA%d_GFX_RB_RPTR_ADDR_LO=0x%08X\n",
1076 i
, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO
+ sdma_offsets
[i
]));
1077 dev_info(adev
->dev
, " SDMA%d_GFX_RB_BASE=0x%08X\n",
1078 i
, RREG32(mmSDMA0_GFX_RB_BASE
+ sdma_offsets
[i
]));
1079 dev_info(adev
->dev
, " SDMA%d_GFX_RB_BASE_HI=0x%08X\n",
1080 i
, RREG32(mmSDMA0_GFX_RB_BASE_HI
+ sdma_offsets
[i
]));
1081 mutex_lock(&adev
->srbm_mutex
);
1082 for (j
= 0; j
< 16; j
++) {
1083 cik_srbm_select(adev
, 0, 0, 0, j
);
1084 dev_info(adev
->dev
, " VM %d:\n", j
);
1085 dev_info(adev
->dev
, " SDMA0_GFX_VIRTUAL_ADDR=0x%08X\n",
1086 RREG32(mmSDMA0_GFX_VIRTUAL_ADDR
+ sdma_offsets
[i
]));
1087 dev_info(adev
->dev
, " SDMA0_GFX_APE1_CNTL=0x%08X\n",
1088 RREG32(mmSDMA0_GFX_APE1_CNTL
+ sdma_offsets
[i
]));
1090 cik_srbm_select(adev
, 0, 0, 0, 0);
1091 mutex_unlock(&adev
->srbm_mutex
);
1095 static int cik_sdma_soft_reset(void *handle
)
1097 u32 srbm_soft_reset
= 0;
1098 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1099 u32 tmp
= RREG32(mmSRBM_STATUS2
);
1101 if (tmp
& SRBM_STATUS2__SDMA_BUSY_MASK
) {
1103 tmp
= RREG32(mmSDMA0_F32_CNTL
+ SDMA0_REGISTER_OFFSET
);
1104 tmp
|= SDMA0_F32_CNTL__HALT_MASK
;
1105 WREG32(mmSDMA0_F32_CNTL
+ SDMA0_REGISTER_OFFSET
, tmp
);
1106 srbm_soft_reset
|= SRBM_SOFT_RESET__SOFT_RESET_SDMA_MASK
;
1108 if (tmp
& SRBM_STATUS2__SDMA1_BUSY_MASK
) {
1110 tmp
= RREG32(mmSDMA0_F32_CNTL
+ SDMA1_REGISTER_OFFSET
);
1111 tmp
|= SDMA0_F32_CNTL__HALT_MASK
;
1112 WREG32(mmSDMA0_F32_CNTL
+ SDMA1_REGISTER_OFFSET
, tmp
);
1113 srbm_soft_reset
|= SRBM_SOFT_RESET__SOFT_RESET_SDMA1_MASK
;
1116 if (srbm_soft_reset
) {
1117 cik_sdma_print_status((void *)adev
);
1119 tmp
= RREG32(mmSRBM_SOFT_RESET
);
1120 tmp
|= srbm_soft_reset
;
1121 dev_info(adev
->dev
, "SRBM_SOFT_RESET=0x%08X\n", tmp
);
1122 WREG32(mmSRBM_SOFT_RESET
, tmp
);
1123 tmp
= RREG32(mmSRBM_SOFT_RESET
);
1127 tmp
&= ~srbm_soft_reset
;
1128 WREG32(mmSRBM_SOFT_RESET
, tmp
);
1129 tmp
= RREG32(mmSRBM_SOFT_RESET
);
1131 /* Wait a little for things to settle down */
1134 cik_sdma_print_status((void *)adev
);
1140 static int cik_sdma_set_trap_irq_state(struct amdgpu_device
*adev
,
1141 struct amdgpu_irq_src
*src
,
1143 enum amdgpu_interrupt_state state
)
1148 case AMDGPU_SDMA_IRQ_TRAP0
:
1150 case AMDGPU_IRQ_STATE_DISABLE
:
1151 sdma_cntl
= RREG32(mmSDMA0_CNTL
+ SDMA0_REGISTER_OFFSET
);
1152 sdma_cntl
&= ~SDMA0_CNTL__TRAP_ENABLE_MASK
;
1153 WREG32(mmSDMA0_CNTL
+ SDMA0_REGISTER_OFFSET
, sdma_cntl
);
1155 case AMDGPU_IRQ_STATE_ENABLE
:
1156 sdma_cntl
= RREG32(mmSDMA0_CNTL
+ SDMA0_REGISTER_OFFSET
);
1157 sdma_cntl
|= SDMA0_CNTL__TRAP_ENABLE_MASK
;
1158 WREG32(mmSDMA0_CNTL
+ SDMA0_REGISTER_OFFSET
, sdma_cntl
);
1164 case AMDGPU_SDMA_IRQ_TRAP1
:
1166 case AMDGPU_IRQ_STATE_DISABLE
:
1167 sdma_cntl
= RREG32(mmSDMA0_CNTL
+ SDMA1_REGISTER_OFFSET
);
1168 sdma_cntl
&= ~SDMA0_CNTL__TRAP_ENABLE_MASK
;
1169 WREG32(mmSDMA0_CNTL
+ SDMA1_REGISTER_OFFSET
, sdma_cntl
);
1171 case AMDGPU_IRQ_STATE_ENABLE
:
1172 sdma_cntl
= RREG32(mmSDMA0_CNTL
+ SDMA1_REGISTER_OFFSET
);
1173 sdma_cntl
|= SDMA0_CNTL__TRAP_ENABLE_MASK
;
1174 WREG32(mmSDMA0_CNTL
+ SDMA1_REGISTER_OFFSET
, sdma_cntl
);
1186 static int cik_sdma_process_trap_irq(struct amdgpu_device
*adev
,
1187 struct amdgpu_irq_src
*source
,
1188 struct amdgpu_iv_entry
*entry
)
1190 u8 instance_id
, queue_id
;
1192 instance_id
= (entry
->ring_id
& 0x3) >> 0;
1193 queue_id
= (entry
->ring_id
& 0xc) >> 2;
1194 DRM_DEBUG("IH: SDMA trap\n");
1195 switch (instance_id
) {
1199 amdgpu_fence_process(&adev
->sdma
[0].ring
);
1212 amdgpu_fence_process(&adev
->sdma
[1].ring
);
1227 static int cik_sdma_process_illegal_inst_irq(struct amdgpu_device
*adev
,
1228 struct amdgpu_irq_src
*source
,
1229 struct amdgpu_iv_entry
*entry
)
1231 DRM_ERROR("Illegal instruction in SDMA command stream\n");
1232 schedule_work(&adev
->reset_work
);
1236 static int cik_sdma_set_clockgating_state(void *handle
,
1237 enum amd_clockgating_state state
)
1240 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1242 if (state
== AMD_CG_STATE_GATE
)
1245 cik_enable_sdma_mgcg(adev
, gate
);
1246 cik_enable_sdma_mgls(adev
, gate
);
1251 static int cik_sdma_set_powergating_state(void *handle
,
1252 enum amd_powergating_state state
)
1257 const struct amd_ip_funcs cik_sdma_ip_funcs
= {
1258 .early_init
= cik_sdma_early_init
,
1260 .sw_init
= cik_sdma_sw_init
,
1261 .sw_fini
= cik_sdma_sw_fini
,
1262 .hw_init
= cik_sdma_hw_init
,
1263 .hw_fini
= cik_sdma_hw_fini
,
1264 .suspend
= cik_sdma_suspend
,
1265 .resume
= cik_sdma_resume
,
1266 .is_idle
= cik_sdma_is_idle
,
1267 .wait_for_idle
= cik_sdma_wait_for_idle
,
1268 .soft_reset
= cik_sdma_soft_reset
,
1269 .print_status
= cik_sdma_print_status
,
1270 .set_clockgating_state
= cik_sdma_set_clockgating_state
,
1271 .set_powergating_state
= cik_sdma_set_powergating_state
,
1275 * cik_sdma_ring_is_lockup - Check if the DMA engine is locked up
1277 * @ring: amdgpu_ring structure holding ring information
1279 * Check if the async DMA engine is locked up (CIK).
1280 * Returns true if the engine appears to be locked up, false if not.
1282 static bool cik_sdma_ring_is_lockup(struct amdgpu_ring
*ring
)
1285 if (cik_sdma_is_idle(ring
->adev
)) {
1286 amdgpu_ring_lockup_update(ring
);
1289 return amdgpu_ring_test_lockup(ring
);
1292 static const struct amdgpu_ring_funcs cik_sdma_ring_funcs
= {
1293 .get_rptr
= cik_sdma_ring_get_rptr
,
1294 .get_wptr
= cik_sdma_ring_get_wptr
,
1295 .set_wptr
= cik_sdma_ring_set_wptr
,
1297 .emit_ib
= cik_sdma_ring_emit_ib
,
1298 .emit_fence
= cik_sdma_ring_emit_fence
,
1299 .emit_semaphore
= cik_sdma_ring_emit_semaphore
,
1300 .emit_vm_flush
= cik_sdma_ring_emit_vm_flush
,
1301 .emit_hdp_flush
= cik_sdma_ring_emit_hdp_flush
,
1302 .test_ring
= cik_sdma_ring_test_ring
,
1303 .test_ib
= cik_sdma_ring_test_ib
,
1304 .is_lockup
= cik_sdma_ring_is_lockup
,
1307 static void cik_sdma_set_ring_funcs(struct amdgpu_device
*adev
)
1309 adev
->sdma
[0].ring
.funcs
= &cik_sdma_ring_funcs
;
1310 adev
->sdma
[1].ring
.funcs
= &cik_sdma_ring_funcs
;
1313 static const struct amdgpu_irq_src_funcs cik_sdma_trap_irq_funcs
= {
1314 .set
= cik_sdma_set_trap_irq_state
,
1315 .process
= cik_sdma_process_trap_irq
,
1318 static const struct amdgpu_irq_src_funcs cik_sdma_illegal_inst_irq_funcs
= {
1319 .process
= cik_sdma_process_illegal_inst_irq
,
1322 static void cik_sdma_set_irq_funcs(struct amdgpu_device
*adev
)
1324 adev
->sdma_trap_irq
.num_types
= AMDGPU_SDMA_IRQ_LAST
;
1325 adev
->sdma_trap_irq
.funcs
= &cik_sdma_trap_irq_funcs
;
1326 adev
->sdma_illegal_inst_irq
.funcs
= &cik_sdma_illegal_inst_irq_funcs
;
1330 * cik_sdma_emit_copy_buffer - copy buffer using the sDMA engine
1332 * @ring: amdgpu_ring structure holding ring information
1333 * @src_offset: src GPU address
1334 * @dst_offset: dst GPU address
1335 * @byte_count: number of bytes to xfer
1337 * Copy GPU buffers using the DMA engine (CIK).
1338 * Used by the amdgpu ttm implementation to move pages if
1339 * registered as the asic copy callback.
1341 static void cik_sdma_emit_copy_buffer(struct amdgpu_ring
*ring
,
1342 uint64_t src_offset
,
1343 uint64_t dst_offset
,
1344 uint32_t byte_count
)
1346 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_COPY
, SDMA_COPY_SUB_OPCODE_LINEAR
, 0));
1347 amdgpu_ring_write(ring
, byte_count
);
1348 amdgpu_ring_write(ring
, 0); /* src/dst endian swap */
1349 amdgpu_ring_write(ring
, lower_32_bits(src_offset
));
1350 amdgpu_ring_write(ring
, upper_32_bits(src_offset
));
1351 amdgpu_ring_write(ring
, lower_32_bits(dst_offset
));
1352 amdgpu_ring_write(ring
, upper_32_bits(dst_offset
));
1356 * cik_sdma_emit_fill_buffer - fill buffer using the sDMA engine
1358 * @ring: amdgpu_ring structure holding ring information
1359 * @src_data: value to write to buffer
1360 * @dst_offset: dst GPU address
1361 * @byte_count: number of bytes to xfer
1363 * Fill GPU buffers using the DMA engine (CIK).
1365 static void cik_sdma_emit_fill_buffer(struct amdgpu_ring
*ring
,
1367 uint64_t dst_offset
,
1368 uint32_t byte_count
)
1370 amdgpu_ring_write(ring
, SDMA_PACKET(SDMA_OPCODE_CONSTANT_FILL
, 0, 0));
1371 amdgpu_ring_write(ring
, lower_32_bits(dst_offset
));
1372 amdgpu_ring_write(ring
, upper_32_bits(dst_offset
));
1373 amdgpu_ring_write(ring
, src_data
);
1374 amdgpu_ring_write(ring
, byte_count
);
1377 static const struct amdgpu_buffer_funcs cik_sdma_buffer_funcs
= {
1378 .copy_max_bytes
= 0x1fffff,
1380 .emit_copy_buffer
= cik_sdma_emit_copy_buffer
,
1382 .fill_max_bytes
= 0x1fffff,
1384 .emit_fill_buffer
= cik_sdma_emit_fill_buffer
,
1387 static void cik_sdma_set_buffer_funcs(struct amdgpu_device
*adev
)
1389 if (adev
->mman
.buffer_funcs
== NULL
) {
1390 adev
->mman
.buffer_funcs
= &cik_sdma_buffer_funcs
;
1391 adev
->mman
.buffer_funcs_ring
= &adev
->sdma
[0].ring
;
1395 static const struct amdgpu_vm_pte_funcs cik_sdma_vm_pte_funcs
= {
1396 .copy_pte
= cik_sdma_vm_copy_pte
,
1397 .write_pte
= cik_sdma_vm_write_pte
,
1398 .set_pte_pde
= cik_sdma_vm_set_pte_pde
,
1399 .pad_ib
= cik_sdma_vm_pad_ib
,
1402 static void cik_sdma_set_vm_pte_funcs(struct amdgpu_device
*adev
)
1404 if (adev
->vm_manager
.vm_pte_funcs
== NULL
) {
1405 adev
->vm_manager
.vm_pte_funcs
= &cik_sdma_vm_pte_funcs
;
1406 adev
->vm_manager
.vm_pte_funcs_ring
= &adev
->sdma
[0].ring
;