anv: provide required gem stubs for the tests
[mesa.git] / src / intel / vulkan / anv_gem_stubs.c
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 <linux/memfd.h>
25 #include <sys/mman.h>
26 #include <sys/syscall.h>
27
28 #include "anv_private.h"
29
30 static inline int
31 memfd_create(const char *name, unsigned int flags)
32 {
33 return syscall(SYS_memfd_create, name, flags);
34 }
35
36 uint32_t
37 anv_gem_create(struct anv_device *device, size_t size)
38 {
39 int fd = memfd_create("fake bo", MFD_CLOEXEC);
40 if (fd == -1)
41 return 0;
42
43 assert(fd != 0);
44
45 if (ftruncate(fd, size) == -1)
46 return 0;
47
48 return fd;
49 }
50
51 void
52 anv_gem_close(struct anv_device *device, uint32_t gem_handle)
53 {
54 close(gem_handle);
55 }
56
57 void*
58 anv_gem_mmap(struct anv_device *device, uint32_t gem_handle,
59 uint64_t offset, uint64_t size, uint32_t flags)
60 {
61 /* Ignore flags, as they're specific to I915_GEM_MMAP. */
62 (void) flags;
63
64 return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
65 gem_handle, offset);
66 }
67
68 /* This is just a wrapper around munmap, but it also notifies valgrind that
69 * this map is no longer valid. Pair this with anv_gem_mmap().
70 */
71 void
72 anv_gem_munmap(void *p, uint64_t size)
73 {
74 munmap(p, size);
75 }
76
77 uint32_t
78 anv_gem_userptr(struct anv_device *device, void *mem, size_t size)
79 {
80 return -1;
81 }
82
83 int
84 anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns)
85 {
86 return 0;
87 }
88
89 int
90 anv_gem_execbuffer(struct anv_device *device,
91 struct drm_i915_gem_execbuffer2 *execbuf)
92 {
93 return 0;
94 }
95
96 int
97 anv_gem_set_tiling(struct anv_device *device,
98 uint32_t gem_handle, uint32_t stride, uint32_t tiling)
99 {
100 return 0;
101 }
102
103 int
104 anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle,
105 uint32_t caching)
106 {
107 return 0;
108 }
109
110 int
111 anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
112 uint32_t read_domains, uint32_t write_domain)
113 {
114 return 0;
115 }
116
117 int
118 anv_gem_get_param(int fd, uint32_t param)
119 {
120 unreachable("Unused");
121 }
122
123 bool
124 anv_gem_get_bit6_swizzle(int fd, uint32_t tiling)
125 {
126 unreachable("Unused");
127 }
128
129 int
130 anv_gem_create_context(struct anv_device *device)
131 {
132 unreachable("Unused");
133 }
134
135 int
136 anv_gem_destroy_context(struct anv_device *device, int context)
137 {
138 unreachable("Unused");
139 }
140
141 int
142 anv_gem_get_context_param(int fd, int context, uint32_t param, uint64_t *value)
143 {
144 unreachable("Unused");
145 }
146
147 int
148 anv_gem_get_aperture(int fd, uint64_t *size)
149 {
150 unreachable("Unused");
151 }
152
153 bool
154 anv_gem_supports_48b_addresses(int fd)
155 {
156 unreachable("Unused");
157 }
158
159 int
160 anv_gem_gpu_get_reset_stats(struct anv_device *device,
161 uint32_t *active, uint32_t *pending)
162 {
163 unreachable("Unused");
164 }
165
166 int
167 anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle)
168 {
169 unreachable("Unused");
170 }
171
172 uint32_t
173 anv_gem_fd_to_handle(struct anv_device *device, int fd)
174 {
175 unreachable("Unused");
176 }