Monk Liu | 4e4bbe7 | 2017-01-09 15:21:13 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Advanced Micro Devices, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "amdgpu.h" |
| 25 | |
| 26 | int amdgpu_allocate_static_csa(struct amdgpu_device *adev) |
| 27 | { |
| 28 | int r; |
| 29 | void *ptr; |
| 30 | |
| 31 | r = amdgpu_bo_create_kernel(adev, AMDGPU_CSA_SIZE, PAGE_SIZE, |
| 32 | AMDGPU_GEM_DOMAIN_VRAM, &adev->virt.csa_obj, |
| 33 | &adev->virt.csa_vmid0_addr, &ptr); |
| 34 | if (r) |
| 35 | return r; |
| 36 | |
| 37 | memset(ptr, 0, AMDGPU_CSA_SIZE); |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * amdgpu_map_static_csa should be called during amdgpu_vm_init |
| 43 | * it maps virtual address "AMDGPU_VA_RESERVED_SIZE - AMDGPU_CSA_SIZE" |
| 44 | * to this VM, and each command submission of GFX should use this virtual |
| 45 | * address within META_DATA init package to support SRIOV gfx preemption. |
| 46 | */ |
| 47 | |
| 48 | int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm) |
| 49 | { |
| 50 | int r; |
| 51 | struct amdgpu_bo_va *bo_va; |
| 52 | struct ww_acquire_ctx ticket; |
| 53 | struct list_head list; |
| 54 | struct amdgpu_bo_list_entry pd; |
| 55 | struct ttm_validate_buffer csa_tv; |
| 56 | |
| 57 | INIT_LIST_HEAD(&list); |
| 58 | INIT_LIST_HEAD(&csa_tv.head); |
| 59 | csa_tv.bo = &adev->virt.csa_obj->tbo; |
| 60 | csa_tv.shared = true; |
| 61 | |
| 62 | list_add(&csa_tv.head, &list); |
| 63 | amdgpu_vm_get_pd_bo(vm, &list, &pd); |
| 64 | |
| 65 | r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL); |
| 66 | if (r) { |
| 67 | DRM_ERROR("failed to reserve CSA,PD BOs: err=%d\n", r); |
| 68 | return r; |
| 69 | } |
| 70 | |
| 71 | bo_va = amdgpu_vm_bo_add(adev, vm, adev->virt.csa_obj); |
| 72 | if (!bo_va) { |
| 73 | ttm_eu_backoff_reservation(&ticket, &list); |
| 74 | DRM_ERROR("failed to create bo_va for static CSA\n"); |
| 75 | return -ENOMEM; |
| 76 | } |
| 77 | |
| 78 | r = amdgpu_vm_bo_map(adev, bo_va, AMDGPU_CSA_VADDR, 0,AMDGPU_CSA_SIZE, |
| 79 | AMDGPU_PTE_READABLE | AMDGPU_PTE_WRITEABLE | |
| 80 | AMDGPU_PTE_EXECUTABLE); |
| 81 | |
| 82 | if (r) { |
| 83 | DRM_ERROR("failed to do bo_map on static CSA, err=%d\n", r); |
| 84 | amdgpu_vm_bo_rmv(adev, bo_va); |
| 85 | ttm_eu_backoff_reservation(&ticket, &list); |
| 86 | kfree(bo_va); |
| 87 | return r; |
| 88 | } |
| 89 | |
| 90 | vm->csa_bo_va = bo_va; |
| 91 | ttm_eu_backoff_reservation(&ticket, &list); |
| 92 | return 0; |
| 93 | } |