Home | History | Annotate | Line # | Download | only in radeon
      1  1.1  riastrad /*	$NetBSD: radeon_rv770_dma.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2013 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  * Authors: Alex Deucher
     25  1.1  riastrad  */
     26  1.2  riastrad 
     27  1.1  riastrad #include <sys/cdefs.h>
     28  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_rv770_dma.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $");
     29  1.1  riastrad 
     30  1.1  riastrad #include "radeon.h"
     31  1.1  riastrad #include "radeon_asic.h"
     32  1.1  riastrad #include "rv770d.h"
     33  1.1  riastrad 
     34  1.1  riastrad /**
     35  1.1  riastrad  * rv770_copy_dma - copy pages using the DMA engine
     36  1.1  riastrad  *
     37  1.1  riastrad  * @rdev: radeon_device pointer
     38  1.1  riastrad  * @src_offset: src GPU address
     39  1.1  riastrad  * @dst_offset: dst GPU address
     40  1.1  riastrad  * @num_gpu_pages: number of GPU pages to xfer
     41  1.1  riastrad  * @resv: reservation object to sync to
     42  1.1  riastrad  *
     43  1.1  riastrad  * Copy GPU paging using the DMA engine (r7xx).
     44  1.1  riastrad  * Used by the radeon ttm implementation to move pages if
     45  1.1  riastrad  * registered as the asic copy callback.
     46  1.1  riastrad  */
     47  1.1  riastrad struct radeon_fence *rv770_copy_dma(struct radeon_device *rdev,
     48  1.1  riastrad 				    uint64_t src_offset, uint64_t dst_offset,
     49  1.1  riastrad 				    unsigned num_gpu_pages,
     50  1.2  riastrad 				    struct dma_resv *resv)
     51  1.1  riastrad {
     52  1.1  riastrad 	struct radeon_fence *fence;
     53  1.1  riastrad 	struct radeon_sync sync;
     54  1.1  riastrad 	int ring_index = rdev->asic->copy.dma_ring_index;
     55  1.1  riastrad 	struct radeon_ring *ring = &rdev->ring[ring_index];
     56  1.1  riastrad 	u32 size_in_dw, cur_size_in_dw;
     57  1.1  riastrad 	int i, num_loops;
     58  1.1  riastrad 	int r = 0;
     59  1.1  riastrad 
     60  1.1  riastrad 	radeon_sync_create(&sync);
     61  1.1  riastrad 
     62  1.1  riastrad 	size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
     63  1.1  riastrad 	num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFF);
     64  1.1  riastrad 	r = radeon_ring_lock(rdev, ring, num_loops * 5 + 8);
     65  1.1  riastrad 	if (r) {
     66  1.1  riastrad 		DRM_ERROR("radeon: moving bo (%d).\n", r);
     67  1.1  riastrad 		radeon_sync_free(rdev, &sync, NULL);
     68  1.1  riastrad 		return ERR_PTR(r);
     69  1.1  riastrad 	}
     70  1.1  riastrad 
     71  1.1  riastrad 	radeon_sync_resv(rdev, &sync, resv, false);
     72  1.1  riastrad 	radeon_sync_rings(rdev, &sync, ring->idx);
     73  1.1  riastrad 
     74  1.1  riastrad 	for (i = 0; i < num_loops; i++) {
     75  1.1  riastrad 		cur_size_in_dw = size_in_dw;
     76  1.1  riastrad 		if (cur_size_in_dw > 0xFFFF)
     77  1.1  riastrad 			cur_size_in_dw = 0xFFFF;
     78  1.1  riastrad 		size_in_dw -= cur_size_in_dw;
     79  1.1  riastrad 		radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw));
     80  1.1  riastrad 		radeon_ring_write(ring, dst_offset & 0xfffffffc);
     81  1.1  riastrad 		radeon_ring_write(ring, src_offset & 0xfffffffc);
     82  1.1  riastrad 		radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
     83  1.1  riastrad 		radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
     84  1.1  riastrad 		src_offset += cur_size_in_dw * 4;
     85  1.1  riastrad 		dst_offset += cur_size_in_dw * 4;
     86  1.1  riastrad 	}
     87  1.1  riastrad 
     88  1.1  riastrad 	r = radeon_fence_emit(rdev, &fence, ring->idx);
     89  1.1  riastrad 	if (r) {
     90  1.1  riastrad 		radeon_ring_unlock_undo(rdev, ring);
     91  1.1  riastrad 		radeon_sync_free(rdev, &sync, NULL);
     92  1.1  riastrad 		return ERR_PTR(r);
     93  1.1  riastrad 	}
     94  1.1  riastrad 
     95  1.1  riastrad 	radeon_ring_unlock_commit(rdev, ring, false);
     96  1.1  riastrad 	radeon_sync_free(rdev, &sync, fence);
     97  1.1  riastrad 
     98  1.1  riastrad 	return fence;
     99  1.1  riastrad }
    100