1 /* 2 * Copyright © 2023 Intel Corporation 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 (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #pragma once 25 26 #include <stdint.h> 27 28 #include "vulkan/vulkan_core.h" 29 #include "vk_sync.h" 30 31 #include "dev/intel_device_info.h" 32 #include "dev/intel_kmd.h" 33 34 struct anv_bo; 35 enum anv_bo_alloc_flags; 36 struct anv_cmd_buffer; 37 struct anv_device; 38 struct anv_queue; 39 struct anv_query_pool; 40 struct anv_async_submit; 41 struct anv_utrace_submit; 42 struct anv_sparse_submission; 43 44 enum anv_vm_bind_op { 45 /* bind vma specified in anv_vm_bind */ 46 ANV_VM_BIND, 47 /* unbind vma specified in anv_vm_bind */ 48 ANV_VM_UNBIND, 49 /* unbind all vmas of anv_vm_bind::bo, address and size fields must be set to 0 */ 50 ANV_VM_UNBIND_ALL, 51 }; 52 53 struct anv_vm_bind { 54 struct anv_bo *bo; /* Or NULL in case of a NULL binding. */ 55 uint64_t address; /* Includes the resource offset. */ 56 uint64_t bo_offset; /* Also known as the memory offset. */ 57 uint64_t size; 58 enum anv_vm_bind_op op; 59 }; 60 61 /* These flags apply only to the vm_bind() ioctl backend operations, not to 62 * the higher-level concept of resource address binding. In other words: they 63 * don't apply to TR-TT, which also uses other structs with "vm_bind" in their 64 * names. 65 */ 66 enum anv_vm_bind_flags { 67 ANV_VM_BIND_FLAG_NONE = 0, 68 /* The most recent bind_timeline wait point is waited for during every 69 * command submission. This flag allows the vm_bind operation to create a 70 * new timeline point and signal it upon completion. 71 */ 72 ANV_VM_BIND_FLAG_SIGNAL_BIND_TIMELINE = 1 << 0, 73 }; 74 75 struct anv_kmd_backend { 76 /* 77 * Create a gem buffer. 78 * Return the gem handle in case of success otherwise returns 0. 79 */ 80 uint32_t (*gem_create)(struct anv_device *device, 81 const struct intel_memory_class_instance **regions, 82 uint16_t num_regions, uint64_t size, 83 enum anv_bo_alloc_flags alloc_flags, 84 uint64_t *actual_size); 85 uint32_t (*gem_create_userptr)(struct anv_device *device, void *mem, uint64_t size); 86 void (*gem_close)(struct anv_device *device, struct anv_bo *bo); 87 /* Returns MAP_FAILED on error */ 88 void *(*gem_mmap)(struct anv_device *device, struct anv_bo *bo, 89 uint64_t offset, uint64_t size, void *placed_addr); 90 91 /* 92 * Bind things however you want. 93 * This is intended for sparse resources, so it's a little lower level and 94 * the _bo variants. 95 */ 96 VkResult (*vm_bind)(struct anv_device *device, 97 struct anv_sparse_submission *submit, 98 enum anv_vm_bind_flags flags); 99 100 /* 101 * Fully bind or unbind a BO. 102 * This is intended for general buffer creation/destruction, so it creates 103 * a new point in the bind_timeline, which will be waited for the next time 104 * a batch is submitted. 105 */ 106 VkResult (*vm_bind_bo)(struct anv_device *device, struct anv_bo *bo); 107 VkResult (*vm_unbind_bo)(struct anv_device *device, struct anv_bo *bo); 108 109 /* The caller is expected to hold device->mutex when calling this vfunc. 110 */ 111 VkResult (*queue_exec_locked)(struct anv_queue *queue, 112 uint32_t wait_count, 113 const struct vk_sync_wait *waits, 114 uint32_t cmd_buffer_count, 115 struct anv_cmd_buffer **cmd_buffers, 116 uint32_t signal_count, 117 const struct vk_sync_signal *signals, 118 struct anv_query_pool *perf_query_pool, 119 uint32_t perf_query_pass, 120 struct anv_utrace_submit *utrace_submit); 121 /* The caller is not expected to hold device->mutex when calling this 122 * vfunc. 123 */ 124 VkResult (*queue_exec_async)(struct anv_async_submit *submit, 125 uint32_t wait_count, 126 const struct vk_sync_wait *waits, 127 uint32_t signal_count, 128 const struct vk_sync_signal *signals); 129 uint32_t (*bo_alloc_flags_to_bo_flags)(struct anv_device *device, 130 enum anv_bo_alloc_flags alloc_flags); 131 }; 132 133 const struct anv_kmd_backend *anv_kmd_backend_get(enum intel_kmd_type type); 134 135 /* Internal functions, should only be called by anv_kmd_backend_get() */ 136 const struct anv_kmd_backend *anv_i915_kmd_backend_get(void); 137 const struct anv_kmd_backend *anv_xe_kmd_backend_get(void); 138 const struct anv_kmd_backend *anv_stub_kmd_backend_get(void); 139