Lines Matching +full:drm +full:- +full:shim
27 * wrappers, and calls into the driver-specific code as necessary.
40 #include "drm-uapi/drm.h"
57 /* Global state for the shim shared between libc, core, and driver. */
75 * Called when the first libc shim is called, to initialize GEM simulation
89 shim_device.mem_fd = memfd_create("shim mem", MFD_CLOEXEC); in drm_shim_device_init()
90 assert(shim_device.mem_fd != -1); in drm_shim_device_init()
102 * are offsets are page-size aligned as required. Otherwise, mmap will fail in drm_shim_device_init()
109 SHIM_MEM_SIZE - shim_page_size); in drm_shim_device_init()
119 shim_fd->fd = fd; in drm_shim_file_create()
120 p_atomic_set(&shim_fd->refcount, 1); in drm_shim_file_create()
121 mtx_init(&shim_fd->handle_lock, mtx_plain); in drm_shim_file_create()
122 shim_fd->handles = _mesa_hash_table_create(NULL, in drm_shim_file_create()
131 * DRM device.
138 p_atomic_inc(&shim_fd->refcount); in drm_shim_fd_register()
145 drm_shim_bo_put(entry->data); in handle_delete_fxn()
150 if (fd == -1) in drm_shim_fd_unregister()
157 struct shim_fd *shim_fd = entry->data; in drm_shim_fd_unregister()
160 if (!p_atomic_dec_zero(&shim_fd->refcount)) in drm_shim_fd_unregister()
163 _mesa_hash_table_destroy(shim_fd->handles, handle_delete_fxn); in drm_shim_fd_unregister()
170 if (fd == -1) in drm_shim_fd_lookup()
178 return entry->data; in drm_shim_fd_lookup()
187 const char *desc = "shim"; in drm_shim_ioctl_version()
189 args->version_major = shim_device.version_major; in drm_shim_ioctl_version()
190 args->version_minor = shim_device.version_minor; in drm_shim_ioctl_version()
191 args->version_patchlevel = shim_device.version_patchlevel; in drm_shim_ioctl_version()
193 if (args->name) in drm_shim_ioctl_version()
194 strncpy(args->name, shim_device.driver_name, args->name_len); in drm_shim_ioctl_version()
195 if (args->date) in drm_shim_ioctl_version()
196 strncpy(args->date, date, args->date_len); in drm_shim_ioctl_version()
197 if (args->desc) in drm_shim_ioctl_version()
198 strncpy(args->desc, desc, args->desc_len); in drm_shim_ioctl_version()
199 args->name_len = strlen(shim_device.driver_name); in drm_shim_ioctl_version()
200 args->date_len = strlen(date); in drm_shim_ioctl_version()
201 args->desc_len = strlen(desc); in drm_shim_ioctl_version()
211 if (gu->unique && shim_device.unique) in drm_shim_ioctl_get_unique()
212 strncpy(gu->unique, shim_device.unique, gu->unique_len); in drm_shim_ioctl_get_unique()
213 gu->unique_len = shim_device.unique ? strlen(shim_device.unique) : 0; in drm_shim_ioctl_get_unique()
223 switch (gc->capability) { in drm_shim_ioctl_get_cap()
227 gc->value = 1; in drm_shim_ioctl_get_cap()
232 (int)gc->capability); in drm_shim_ioctl_get_cap()
233 return -1; in drm_shim_ioctl_get_cap()
243 if (!c->handle) in drm_shim_ioctl_gem_close()
246 mtx_lock(&shim_fd->handle_lock); in drm_shim_ioctl_gem_close()
248 _mesa_hash_table_search(shim_fd->handles, (void *)(uintptr_t)c->handle); in drm_shim_ioctl_gem_close()
250 mtx_unlock(&shim_fd->handle_lock); in drm_shim_ioctl_gem_close()
251 return -EINVAL; in drm_shim_ioctl_gem_close()
254 struct shim_bo *bo = entry->data; in drm_shim_ioctl_gem_close()
255 _mesa_hash_table_remove(shim_fd->handles, entry); in drm_shim_ioctl_gem_close()
257 mtx_unlock(&shim_fd->handle_lock); in drm_shim_ioctl_gem_close()
266 create->handle = 1; /* 0 is invalid */ in drm_shim_ioctl_syncobj_create()
295 * Implements the GEM core ioctls, and calls into driver-specific ioctls.
306 int driver_nr = nr - DRM_COMMAND_BASE; in drm_shim_ioctl()
320 "DRM_SHIM: unhandled driver DRM ioctl %d (0x%08lx)\n", in drm_shim_ioctl()
321 nr - DRM_COMMAND_BASE, request); in drm_shim_ioctl()
324 "DRM_SHIM: unhandled core DRM ioctl 0x%X (0x%08lx)\n", in drm_shim_ioctl()
328 return -EINVAL; in drm_shim_ioctl()
336 bo->mem_addr = util_vma_heap_alloc(&shim_device.mem_heap, size, shim_page_size); in drm_shim_bo_init()
339 if (!bo->mem_addr) in drm_shim_bo_init()
340 return -ENOMEM; in drm_shim_bo_init()
342 bo->size = size; in drm_shim_bo_init()
353 mtx_lock(&shim_fd->handle_lock); in drm_shim_bo_lookup()
355 _mesa_hash_table_search(shim_fd->handles, (void *)(uintptr_t)handle); in drm_shim_bo_lookup()
356 struct shim_bo *bo = entry ? entry->data : NULL; in drm_shim_bo_lookup()
357 mtx_unlock(&shim_fd->handle_lock); in drm_shim_bo_lookup()
360 p_atomic_inc(&bo->refcount); in drm_shim_bo_lookup()
368 p_atomic_inc(&bo->refcount); in drm_shim_bo_get()
374 if (p_atomic_dec_return(&bo->refcount) == 0) in drm_shim_bo_put()
381 util_vma_heap_free(&shim_device.mem_heap, bo->mem_addr, bo->size); in drm_shim_bo_put()
392 mtx_lock(&shim_fd->handle_lock); in drm_shim_bo_get_handle()
395 if (!_mesa_hash_table_search(shim_fd->handles, key)) { in drm_shim_bo_get_handle()
397 _mesa_hash_table_insert(shim_fd->handles, key, bo); in drm_shim_bo_get_handle()
398 mtx_unlock(&shim_fd->handle_lock); in drm_shim_bo_get_handle()
402 mtx_unlock(&shim_fd->handle_lock); in drm_shim_bo_get_handle()
407 /* Creates an mmap offset for the BO in the DRM fd.
413 _mesa_hash_table_u64_insert(shim_device.offset_map, bo->mem_addr, bo); in drm_shim_bo_get_mmap_offset()
417 return bo->mem_addr; in drm_shim_bo_get_mmap_offset()
429 /* For mmap() on the DRM fd, look up the BO from the "offset" and map the BO's
449 if (length > bo->size) in drm_shim_mmap()
453 assert((bo->mem_addr & (shim_page_size - 1)) == 0); in drm_shim_mmap()
455 return mmap(NULL, length, prot, flags, shim_device.mem_fd, bo->mem_addr); in drm_shim_mmap()