/* * Copyright 2010 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Alex Deucher
*/
/* * DMA * Starting with R600, the GPU has an asynchronous * DMA engine. The programming model is very similar * to the 3D engine (ring buffer, IBs, etc.), but the * DMA controller has it's own packet format that is * different form the PM4 format used by the 3D engine. * It supports copying data, writing embedded data, * solid fills, and a number of other things. It also * has support for tiling/detiling of buffers. * Cayman and newer support two asynchronous DMA engines.
*/
/** * cayman_dma_get_rptr - get the current read pointer * * @rdev: radeon_device pointer * @ring: radeon ring pointer * * Get the current rptr from the hardware (cayman+).
*/
uint32_t cayman_dma_get_rptr(struct radeon_device *rdev, struct radeon_ring *ring)
{
u32 rptr, reg;
/** * cayman_dma_get_wptr - get the current write pointer * * @rdev: radeon_device pointer * @ring: radeon ring pointer * * Get the current wptr from the hardware (cayman+).
*/
uint32_t cayman_dma_get_wptr(struct radeon_device *rdev, struct radeon_ring *ring)
{
u32 reg;
/* The indirect buffer packet must end on an 8 DW boundary in the DMA ring. * Pad as necessary with NOPs.
*/ while ((ring->wptr & 7) != 5)
radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
radeon_ring_write(ring, DMA_IB_PACKET(DMA_PACKET_INDIRECT_BUFFER, vm_id, 0));
radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF));
/** * cayman_dma_resume - setup and start the async dma engines * * @rdev: radeon_device pointer * * Set up the DMA ring buffers and enable them. (cayman-SI). * Returns 0 for success, error for failure.
*/ int cayman_dma_resume(struct radeon_device *rdev)
{ struct radeon_ring *ring;
u32 rb_cntl, dma_cntl, ib_cntl;
u32 rb_bufsz;
u32 reg_offset, wb_offset; int i, r;
for (i = 0; i < 2; i++) { if (i == 0) {
ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
reg_offset = DMA0_REGISTER_OFFSET;
wb_offset = R600_WB_DMA_RPTR_OFFSET;
} else {
ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
reg_offset = DMA1_REGISTER_OFFSET;
wb_offset = CAYMAN_WB_DMA1_RPTR_OFFSET;
}
r = radeon_ring_test(rdev, ring->idx, ring); if (r) {
ring->ready = false; return r;
}
}
if ((rdev->asic->copy.copy_ring_index == R600_RING_TYPE_DMA_INDEX) ||
(rdev->asic->copy.copy_ring_index == CAYMAN_RING_TYPE_DMA1_INDEX))
radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
return 0;
}
/** * cayman_dma_fini - tear down the async dma engines * * @rdev: radeon_device pointer * * Stop the async dma engines and free the rings (cayman-SI).
*/ void cayman_dma_fini(struct radeon_device *rdev)
{
cayman_dma_stop(rdev);
radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
radeon_ring_fini(rdev, &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX]);
}
/** * cayman_dma_is_lockup - Check if the DMA engine is locked up * * @rdev: radeon_device pointer * @ring: radeon_ring structure holding ring information * * Check if the async DMA engine is locked up. * Returns true if the engine appears to be locked up, false if not.
*/ bool cayman_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
{
u32 reset_mask = cayman_gpu_check_soft_reset(rdev);
u32 mask;
/** * cayman_dma_vm_copy_pages - update PTEs by copying them from the GART * * @rdev: radeon_device pointer * @ib: indirect buffer to fill with commands * @pe: addr of the page entry * @src: src addr where to copy from * @count: number of page entries to update * * Update PTEs by copying them from the GART using the DMA (cayman/TN).
*/ void cayman_dma_vm_copy_pages(struct radeon_device *rdev, struct radeon_ib *ib,
uint64_t pe, uint64_t src, unsigned count)
{ unsigned ndw;
while (count) {
ndw = count * 2; if (ndw > 0xFFFFE)
ndw = 0xFFFFE;
/** * cayman_dma_vm_write_pages - update PTEs by writing them manually * * @rdev: radeon_device pointer * @ib: indirect buffer to fill with commands * @pe: addr of the page entry * @addr: dst addr to write into pe * @count: number of page entries to update * @incr: increase next addr by incr bytes * @flags: hw access flags * * Update PTEs by writing them manually using the DMA (cayman/TN).
*/ void cayman_dma_vm_write_pages(struct radeon_device *rdev, struct radeon_ib *ib,
uint64_t pe,
uint64_t addr, unsigned count,
uint32_t incr, uint32_t flags)
{
uint64_t value; unsigned ndw;
while (count) {
ndw = count * 2; if (ndw > 0xFFFFE)
ndw = 0xFFFFE;
/* for non-physically contiguous pages (system) */
ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_WRITE,
0, 0, ndw);
ib->ptr[ib->length_dw++] = pe;
ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff; for (; ndw > 0; ndw -= 2, --count, pe += 8) { if (flags & R600_PTE_SYSTEM) {
value = radeon_vm_map_gart(rdev, addr);
} elseif (flags & R600_PTE_VALID) {
value = addr;
} else {
value = 0;
}
addr += incr;
value |= flags;
ib->ptr[ib->length_dw++] = value;
ib->ptr[ib->length_dw++] = upper_32_bits(value);
}
}
}
/** * cayman_dma_vm_set_pages - update the page tables using the DMA * * @rdev: radeon_device pointer * @ib: indirect buffer to fill with commands * @pe: addr of the page entry * @addr: dst addr to write into pe * @count: number of page entries to update * @incr: increase next addr by incr bytes * @flags: hw access flags * * Update the page tables using the DMA (cayman/TN).
*/ void cayman_dma_vm_set_pages(struct radeon_device *rdev, struct radeon_ib *ib,
uint64_t pe,
uint64_t addr, unsigned count,
uint32_t incr, uint32_t flags)
{
uint64_t value; unsigned ndw;
while (count) {
ndw = count * 2; if (ndw > 0xFFFFE)
ndw = 0xFFFFE;
if (flags & R600_PTE_VALID)
value = addr; else
value = 0;
/** * cayman_dma_vm_pad_ib - pad the IB to the required number of dw * * @ib: indirect buffer to fill with padding *
*/ void cayman_dma_vm_pad_ib(struct radeon_ib *ib)
{ while (ib->length_dw & 0x7)
ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.