1 /*
2 * Copyright © 2015 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 #include <sys/mman.h>
25 #include <sys/syscall.h>
26
27 #include "util/anon_file.h"
28 #include "anv_private.h"
29
30 static void
stub_gem_close(struct anv_device * device,struct anv_bo * bo)31 stub_gem_close(struct anv_device *device, struct anv_bo *bo)
32 {
33 close(bo->gem_handle);
34 }
35
36 static uint32_t
stub_gem_create(struct anv_device * device,const struct intel_memory_class_instance ** regions,uint16_t num_regions,uint64_t size,enum anv_bo_alloc_flags alloc_flags,uint64_t * actual_size)37 stub_gem_create(struct anv_device *device,
38 const struct intel_memory_class_instance **regions,
39 uint16_t num_regions, uint64_t size,
40 enum anv_bo_alloc_flags alloc_flags,
41 uint64_t *actual_size)
42 {
43 int fd = os_create_anonymous_file(size, "fake bo");
44 if (fd == -1)
45 return 0;
46
47 assert(fd != 0);
48
49 *actual_size = size;
50 return fd;
51 }
52
53 static void *
stub_gem_mmap(struct anv_device * device,struct anv_bo * bo,uint64_t offset,uint64_t size,void * placed_addr)54 stub_gem_mmap(struct anv_device *device, struct anv_bo *bo, uint64_t offset,
55 uint64_t size, void *placed_addr)
56 {
57 return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->gem_handle,
58 offset);
59 }
60
61 static VkResult
stub_queue_exec_locked(struct anv_queue * queue,uint32_t wait_count,const struct vk_sync_wait * waits,uint32_t cmd_buffer_count,struct anv_cmd_buffer ** cmd_buffers,uint32_t signal_count,const struct vk_sync_signal * signals,struct anv_query_pool * perf_query_pool,uint32_t perf_query_pass,struct anv_utrace_submit * utrace_submit)62 stub_queue_exec_locked(struct anv_queue *queue,
63 uint32_t wait_count,
64 const struct vk_sync_wait *waits,
65 uint32_t cmd_buffer_count,
66 struct anv_cmd_buffer **cmd_buffers,
67 uint32_t signal_count,
68 const struct vk_sync_signal *signals,
69 struct anv_query_pool *perf_query_pool,
70 uint32_t perf_query_pass,
71 struct anv_utrace_submit *utrace_submit)
72 {
73 return VK_ERROR_UNKNOWN;
74 }
75
76 static VkResult
stub_queue_exec_async(struct anv_async_submit * submit,uint32_t wait_count,const struct vk_sync_wait * waits,uint32_t signal_count,const struct vk_sync_signal * signals)77 stub_queue_exec_async(struct anv_async_submit *submit,
78 uint32_t wait_count,
79 const struct vk_sync_wait *waits,
80 uint32_t signal_count,
81 const struct vk_sync_signal *signals)
82 {
83 return VK_ERROR_UNKNOWN;
84 }
85
86 static uint32_t
stub_bo_alloc_flags_to_bo_flags(struct anv_device * device,enum anv_bo_alloc_flags alloc_flags)87 stub_bo_alloc_flags_to_bo_flags(struct anv_device *device,
88 enum anv_bo_alloc_flags alloc_flags)
89 {
90 return 0;
91 }
92
93 static uint32_t
stub_gem_create_userptr(struct anv_device * device,void * mem,uint64_t size)94 stub_gem_create_userptr(struct anv_device *device, void *mem, uint64_t size)
95 {
96 int fd = os_create_anonymous_file(size, "fake bo");
97 if (fd == -1)
98 return 0;
99
100 assert(fd != 0);
101
102 return fd;
103 }
104
105 int
anv_gem_wait(struct anv_device * device,uint32_t gem_handle,int64_t * timeout_ns)106 anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns)
107 {
108 return 0;
109 }
110
111 int
anv_gem_set_tiling(struct anv_device * device,uint32_t gem_handle,uint32_t stride,uint32_t tiling)112 anv_gem_set_tiling(struct anv_device *device,
113 uint32_t gem_handle, uint32_t stride, uint32_t tiling)
114 {
115 return 0;
116 }
117
118 int
anv_gem_get_tiling(struct anv_device * device,uint32_t gem_handle)119 anv_gem_get_tiling(struct anv_device *device, uint32_t gem_handle)
120 {
121 return 0;
122 }
123
124 int
anv_gem_handle_to_fd(struct anv_device * device,uint32_t gem_handle)125 anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle)
126 {
127 unreachable("Unused");
128 }
129
130 uint32_t
anv_gem_fd_to_handle(struct anv_device * device,int fd)131 anv_gem_fd_to_handle(struct anv_device *device, int fd)
132 {
133 unreachable("Unused");
134 }
135
136 VkResult
anv_gem_import_bo_alloc_flags_to_bo_flags(struct anv_device * device,struct anv_bo * bo,enum anv_bo_alloc_flags alloc_flags,uint32_t * bo_flags)137 anv_gem_import_bo_alloc_flags_to_bo_flags(struct anv_device *device,
138 struct anv_bo *bo,
139 enum anv_bo_alloc_flags alloc_flags,
140 uint32_t *bo_flags)
141 {
142 return VK_SUCCESS;
143 }
144
145 static VkResult
stub_vm_bind(struct anv_device * device,struct anv_sparse_submission * submit,enum anv_vm_bind_flags flags)146 stub_vm_bind(struct anv_device *device, struct anv_sparse_submission *submit,
147 enum anv_vm_bind_flags flags)
148 {
149 return VK_SUCCESS;
150 }
151
152 static VkResult
stub_vm_bind_bo(struct anv_device * device,struct anv_bo * bo)153 stub_vm_bind_bo(struct anv_device *device, struct anv_bo *bo)
154 {
155 return VK_SUCCESS;
156 }
157
anv_stub_kmd_backend_get(void)158 const struct anv_kmd_backend *anv_stub_kmd_backend_get(void)
159 {
160 static const struct anv_kmd_backend stub_backend = {
161 .gem_create = stub_gem_create,
162 .gem_create_userptr = stub_gem_create_userptr,
163 .gem_close = stub_gem_close,
164 .gem_mmap = stub_gem_mmap,
165 .vm_bind = stub_vm_bind,
166 .vm_bind_bo = stub_vm_bind_bo,
167 .vm_unbind_bo = stub_vm_bind_bo,
168 .queue_exec_locked = stub_queue_exec_locked,
169 .queue_exec_async = stub_queue_exec_async,
170 .bo_alloc_flags_to_bo_flags = stub_bo_alloc_flags_to_bo_flags,
171 };
172 return &stub_backend;
173 }
174