Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2016 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  * * Author: Monk.liu@amd.com
0023  */
0024 
0025 #include "amdgpu.h"
0026 
0027 uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
0028 {
0029     uint64_t addr = adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT;
0030 
0031     addr -= AMDGPU_VA_RESERVED_SIZE;
0032     addr = amdgpu_gmc_sign_extend(addr);
0033 
0034     return addr;
0035 }
0036 
0037 int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo **bo,
0038                 u32 domain, uint32_t size)
0039 {
0040     void *ptr;
0041 
0042     amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
0043                 domain, bo,
0044                 NULL, &ptr);
0045     if (!*bo)
0046         return -ENOMEM;
0047 
0048     memset(ptr, 0, size);
0049     adev->virt.csa_cpu_addr = ptr;
0050     return 0;
0051 }
0052 
0053 void amdgpu_free_static_csa(struct amdgpu_bo **bo)
0054 {
0055     amdgpu_bo_free_kernel(bo, NULL, NULL);
0056 }
0057 
0058 /*
0059  * amdgpu_map_static_csa should be called during amdgpu_vm_init
0060  * it maps virtual address amdgpu_csa_vaddr() to this VM, and each command
0061  * submission of GFX should use this virtual address within META_DATA init
0062  * package to support SRIOV gfx preemption.
0063  */
0064 int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
0065               struct amdgpu_bo *bo, struct amdgpu_bo_va **bo_va,
0066               uint64_t csa_addr, uint32_t size)
0067 {
0068     struct ww_acquire_ctx ticket;
0069     struct list_head list;
0070     struct amdgpu_bo_list_entry pd;
0071     struct ttm_validate_buffer csa_tv;
0072     int r;
0073 
0074     INIT_LIST_HEAD(&list);
0075     INIT_LIST_HEAD(&csa_tv.head);
0076     csa_tv.bo = &bo->tbo;
0077     csa_tv.num_shared = 1;
0078 
0079     list_add(&csa_tv.head, &list);
0080     amdgpu_vm_get_pd_bo(vm, &list, &pd);
0081 
0082     r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
0083     if (r) {
0084         DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);
0085         return r;
0086     }
0087 
0088     *bo_va = amdgpu_vm_bo_add(adev, vm, bo);
0089     if (!*bo_va) {
0090         ttm_eu_backoff_reservation(&ticket, &list);
0091         DRM_ERROR("failed to create bo_va for static CSA\n");
0092         return -ENOMEM;
0093     }
0094 
0095     r = amdgpu_vm_bo_map(adev, *bo_va, csa_addr, 0, size,
0096                  AMDGPU_PTE_READABLE | AMDGPU_PTE_WRITEABLE |
0097                  AMDGPU_PTE_EXECUTABLE);
0098 
0099     if (r) {
0100         DRM_ERROR("failed to do bo_map on static CSA, err=%d\n", r);
0101         amdgpu_vm_bo_del(adev, *bo_va);
0102         ttm_eu_backoff_reservation(&ticket, &list);
0103         return r;
0104     }
0105 
0106     ttm_eu_backoff_reservation(&ticket, &list);
0107     return 0;
0108 }