1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "radeon.h"
26#include "radeon_asic.h"
27#include "rv770d.h"
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42struct 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 dma_resv *resv)
46{
47 struct radeon_fence *fence;
48 struct radeon_sync sync;
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 radeon_sync_create(&sync);
56
57 size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
58 num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFF);
59 r = radeon_ring_lock(rdev, ring, num_loops * 5 + 8);
60 if (r) {
61 DRM_ERROR("radeon: moving bo (%d).\n", r);
62 radeon_sync_free(rdev, &sync, NULL);
63 return ERR_PTR(r);
64 }
65
66 radeon_sync_resv(rdev, &sync, resv, false);
67 radeon_sync_rings(rdev, &sync, ring->idx);
68
69 for (i = 0; i < num_loops; i++) {
70 cur_size_in_dw = size_in_dw;
71 if (cur_size_in_dw > 0xFFFF)
72 cur_size_in_dw = 0xFFFF;
73 size_in_dw -= cur_size_in_dw;
74 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw));
75 radeon_ring_write(ring, dst_offset & 0xfffffffc);
76 radeon_ring_write(ring, src_offset & 0xfffffffc);
77 radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
78 radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
79 src_offset += cur_size_in_dw * 4;
80 dst_offset += cur_size_in_dw * 4;
81 }
82
83 r = radeon_fence_emit(rdev, &fence, ring->idx);
84 if (r) {
85 radeon_ring_unlock_undo(rdev, ring);
86 radeon_sync_free(rdev, &sync, NULL);
87 return ERR_PTR(r);
88 }
89
90 radeon_ring_unlock_commit(rdev, ring, false);
91 radeon_sync_free(rdev, &sync, fence);
92
93 return fence;
94}
95