2 * Copyright © 2018 Broadcom
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:
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
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
21 * DEALINGS IN THE SOFTWARE.
24 #include <c11/threads.h>
26 #include "util/macros.h"
27 #include "util/hash_table.h"
36 typedef int (*ioctl_fn_t
)(int fd
, unsigned long request
, void *arg
);
41 /* Mapping from int fd to struct shim_fd *. */
42 struct hash_table
*fd_map
;
45 /* Heap from which shim_bo are allocated */
46 struct util_vma_heap mem_heap
;
50 int (**driver_ioctls
)(int fd
, unsigned long request
, void *arg
);
51 int driver_ioctl_count
;
53 void (*driver_bo_free
)(struct shim_bo
*bo
);
55 /* Returned by drmGetVersion(). */
56 const char *driver_name
;
57 int version_major
, version_minor
, version_patchlevel
;
61 extern struct shim_device shim_device
;
66 /* mapping from int gem handle to struct shim_bo *. */
67 struct hash_table
*handles
;
78 extern int render_node_minor
;
79 void drm_shim_device_init(void);
80 void drm_shim_override_file(const char *contents
,
81 const char *path_format
, ...) PRINTFLIKE(2, 3);
82 void drm_shim_fd_register(int fd
, struct shim_fd
*shim_fd
);
83 struct shim_fd
*drm_shim_fd_lookup(int fd
);
84 int drm_shim_ioctl(int fd
, unsigned long request
, void *arg
);
85 void *drm_shim_mmap(struct shim_fd
*shim_fd
, size_t length
, int prot
, int flags
,
86 int fd
, off_t offset
);
88 void drm_shim_bo_init(struct shim_bo
*bo
, size_t size
);
89 void drm_shim_bo_get(struct shim_bo
*bo
);
90 void drm_shim_bo_put(struct shim_bo
*bo
);
91 struct shim_bo
*drm_shim_bo_lookup(struct shim_fd
*shim_fd
, int handle
);
92 int drm_shim_bo_get_handle(struct shim_fd
*shim_fd
, struct shim_bo
*bo
);
93 uint64_t drm_shim_bo_get_mmap_offset(struct shim_fd
*shim_fd
,
96 /* driver-specific hooks. */
97 void drm_shim_driver_init(void);
98 extern bool drm_shim_driver_prefers_new_render_node
;