Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2022 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  */
0023 
0024 #include "amdgpu.h"
0025 #include "amdgpu_lsdma.h"
0026 
0027 #define AMDGPU_LSDMA_MAX_SIZE   0x2000000ULL
0028 
0029 int amdgpu_lsdma_wait_for(struct amdgpu_device *adev,
0030               uint32_t reg_index, uint32_t reg_val,
0031               uint32_t mask)
0032 {
0033     uint32_t val;
0034     int i;
0035 
0036     for (i = 0; i < adev->usec_timeout; i++) {
0037         val = RREG32(reg_index);
0038         if ((val & mask) == reg_val)
0039             return 0;
0040         udelay(1);
0041     }
0042 
0043     return -ETIME;
0044 }
0045 
0046 int amdgpu_lsdma_copy_mem(struct amdgpu_device *adev,
0047               uint64_t src_addr,
0048               uint64_t dst_addr,
0049               uint64_t mem_size)
0050 {
0051     int ret;
0052 
0053     if (mem_size == 0)
0054         return -EINVAL;
0055 
0056     while (mem_size > 0) {
0057         uint64_t current_copy_size = min(mem_size, AMDGPU_LSDMA_MAX_SIZE);
0058 
0059         ret = adev->lsdma.funcs->copy_mem(adev, src_addr, dst_addr, current_copy_size);
0060         if (ret)
0061             return ret;
0062         src_addr += current_copy_size;
0063         dst_addr += current_copy_size;
0064         mem_size -= current_copy_size;
0065     }
0066 
0067     return 0;
0068 }
0069 
0070 int amdgpu_lsdma_fill_mem(struct amdgpu_device *adev,
0071               uint64_t dst_addr,
0072               uint32_t data,
0073               uint64_t mem_size)
0074 {
0075     int ret;
0076 
0077     if (mem_size == 0)
0078         return -EINVAL;
0079 
0080     while (mem_size > 0) {
0081         uint64_t current_fill_size = min(mem_size, AMDGPU_LSDMA_MAX_SIZE);
0082 
0083         ret = adev->lsdma.funcs->fill_mem(adev, dst_addr, data, current_fill_size);
0084         if (ret)
0085             return ret;
0086         dst_addr += current_fill_size;
0087         mem_size -= current_fill_size;
0088     }
0089 
0090     return 0;
0091 }