Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Advanced Micro Devices, Inc. |
| 3 | * |
| 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: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 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. |
| 21 | * |
| 22 | * Authors: Alex Deucher |
| 23 | */ |
| 24 | #include <drm/drmP.h> |
| 25 | #include "radeon.h" |
| 26 | #include "radeon_asic.h" |
| 27 | #include "rv770d.h" |
| 28 | |
| 29 | /** |
| 30 | * rv770_copy_dma - copy pages using the DMA engine |
| 31 | * |
| 32 | * @rdev: radeon_device pointer |
| 33 | * @src_offset: src GPU address |
| 34 | * @dst_offset: dst GPU address |
| 35 | * @num_gpu_pages: number of GPU pages to xfer |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 36 | * @resv: reservation object to sync to |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 37 | * |
| 38 | * Copy GPU paging using the DMA engine (r7xx). |
| 39 | * Used by the radeon ttm implementation to move pages if |
| 40 | * registered as the asic copy callback. |
| 41 | */ |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 42 | struct radeon_fence *rv770_copy_dma(struct radeon_device *rdev, |
| 43 | uint64_t src_offset, uint64_t dst_offset, |
| 44 | unsigned num_gpu_pages, |
| 45 | struct reservation_object *resv) |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 46 | { |
| 47 | struct radeon_semaphore *sem = NULL; |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 48 | struct radeon_fence *fence; |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 49 | int ring_index = rdev->asic->copy.dma_ring_index; |
| 50 | struct radeon_ring *ring = &rdev->ring[ring_index]; |
| 51 | u32 size_in_dw, cur_size_in_dw; |
| 52 | int i, num_loops; |
| 53 | int r = 0; |
| 54 | |
| 55 | r = radeon_semaphore_create(rdev, &sem); |
| 56 | if (r) { |
| 57 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 58 | return ERR_PTR(r); |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4; |
| 62 | num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFF); |
| 63 | r = radeon_ring_lock(rdev, ring, num_loops * 5 + 8); |
| 64 | if (r) { |
| 65 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
| 66 | radeon_semaphore_free(rdev, &sem, NULL); |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 67 | return ERR_PTR(r); |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Maarten Lankhorst | 392a250 | 2014-09-25 12:39:38 +0200 | [diff] [blame] | 70 | radeon_semaphore_sync_resv(rdev, sem, resv, false); |
Christian König | 1654b81 | 2013-11-12 12:58:05 +0100 | [diff] [blame] | 71 | radeon_semaphore_sync_rings(rdev, sem, ring->idx); |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 72 | |
| 73 | for (i = 0; i < num_loops; i++) { |
| 74 | cur_size_in_dw = size_in_dw; |
| 75 | if (cur_size_in_dw > 0xFFFF) |
| 76 | cur_size_in_dw = 0xFFFF; |
| 77 | size_in_dw -= cur_size_in_dw; |
| 78 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw)); |
| 79 | radeon_ring_write(ring, dst_offset & 0xfffffffc); |
| 80 | radeon_ring_write(ring, src_offset & 0xfffffffc); |
| 81 | radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff); |
| 82 | radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff); |
| 83 | src_offset += cur_size_in_dw * 4; |
| 84 | dst_offset += cur_size_in_dw * 4; |
| 85 | } |
| 86 | |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 87 | r = radeon_fence_emit(rdev, &fence, ring->idx); |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 88 | if (r) { |
| 89 | radeon_ring_unlock_undo(rdev, ring); |
Maarten Lankhorst | aa4c8b3 | 2014-04-24 13:29:14 +0200 | [diff] [blame] | 90 | radeon_semaphore_free(rdev, &sem, NULL); |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 91 | return ERR_PTR(r); |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Michel Dänzer | 1538a9e | 2014-08-18 17:34:55 +0900 | [diff] [blame] | 94 | radeon_ring_unlock_commit(rdev, ring, false); |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 95 | radeon_semaphore_free(rdev, &sem, fence); |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 96 | |
Christian König | 57d20a4 | 2014-09-04 20:01:53 +0200 | [diff] [blame] | 97 | return fence; |
Christian König | 2483b4e | 2013-08-13 11:56:54 +0200 | [diff] [blame] | 98 | } |