Path: blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
26517 views
/*1* Copyright 2016 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.2021* * Author: [email protected]22*/2324#include <drm/drm_exec.h>2526#include "amdgpu.h"2728uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)29{30uint64_t addr = AMDGPU_VA_RESERVED_CSA_START(adev);3132addr = amdgpu_gmc_sign_extend(addr);3334return addr;35}3637int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo **bo,38u32 domain, uint32_t size)39{40void *ptr;4142amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,43domain, bo,44NULL, &ptr);45if (!*bo)46return -ENOMEM;4748memset(ptr, 0, size);49adev->virt.csa_cpu_addr = ptr;50return 0;51}5253void amdgpu_free_static_csa(struct amdgpu_bo **bo)54{55amdgpu_bo_free_kernel(bo, NULL, NULL);56}5758/*59* amdgpu_map_static_csa should be called during amdgpu_vm_init60* it maps virtual address amdgpu_csa_vaddr() to this VM, and each command61* submission of GFX should use this virtual address within META_DATA init62* package to support SRIOV gfx preemption.63*/64int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,65struct amdgpu_bo *bo, struct amdgpu_bo_va **bo_va,66uint64_t csa_addr, uint32_t size)67{68struct drm_exec exec;69int r;7071drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);72drm_exec_until_all_locked(&exec) {73r = amdgpu_vm_lock_pd(vm, &exec, 0);74if (likely(!r))75r = drm_exec_lock_obj(&exec, &bo->tbo.base);76drm_exec_retry_on_contention(&exec);77if (unlikely(r)) {78DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);79goto error;80}81}8283*bo_va = amdgpu_vm_bo_add(adev, vm, bo);84if (!*bo_va) {85r = -ENOMEM;86goto error;87}8889r = amdgpu_vm_bo_map(adev, *bo_va, csa_addr, 0, size,90AMDGPU_PTE_READABLE | AMDGPU_PTE_WRITEABLE |91AMDGPU_PTE_EXECUTABLE);9293if (r) {94DRM_ERROR("failed to do bo_map on static CSA, err=%d\n", r);95amdgpu_vm_bo_del(adev, *bo_va);96goto error;97}9899error:100drm_exec_fini(&exec);101return r;102}103104int amdgpu_unmap_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,105struct amdgpu_bo *bo, struct amdgpu_bo_va *bo_va,106uint64_t csa_addr)107{108struct drm_exec exec;109int r;110111drm_exec_init(&exec, 0, 0);112drm_exec_until_all_locked(&exec) {113r = amdgpu_vm_lock_pd(vm, &exec, 0);114if (likely(!r))115r = drm_exec_lock_obj(&exec, &bo->tbo.base);116drm_exec_retry_on_contention(&exec);117if (unlikely(r)) {118DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r);119goto error;120}121}122123r = amdgpu_vm_bo_unmap(adev, bo_va, csa_addr);124if (r) {125DRM_ERROR("failed to do bo_unmap on static CSA, err=%d\n", r);126goto error;127}128129amdgpu_vm_bo_del(adev, bo_va);130131error:132drm_exec_fini(&exec);133return r;134}135136137