summaryrefslogtreecommitdiff
path: root/src/drm-shim/drm_shim.h
blob: 2cd053f6d652e2cdbef6cd914580c4eb87c2a3d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright © 2018 Broadcom
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "util/macros.h"
#include "util/hash_table.h"

#ifdef __linux__
#define DRM_MAJOR 226
#endif

typedef int (*ioctl_fn_t)(int fd, unsigned long request, void *arg);

struct shim_bo;

struct shim_device {
   /* Mapping from int fd to struct shim_fd *. */
   struct hash_table *fd_map;

   int (**driver_ioctls)(int fd, unsigned long request, void *arg);
   int driver_ioctl_count;

   void (*driver_bo_free)(struct shim_bo *bo);

   /* Returned by drmGetVersion(). */
   const char *driver_name;
   int version_major, version_minor, version_patchlevel;
};

extern struct shim_device shim_device;

struct shim_fd {
   int fd;
   /* mapping from int gem handle to struct shim_bo *. */
   struct hash_table *handles;
};

struct shim_bo {
   int fd;
   void *map;
   int refcount;
   uint32_t size;
};

/* Core support. */
extern int render_node_minor;
void drm_shim_device_init(void);
void drm_shim_override_file(const char *contents,
                            const char *path_format, ...) PRINTFLIKE(2, 3);
void drm_shim_fd_register(int fd, struct shim_fd *shim_fd);
struct shim_fd *drm_shim_fd_lookup(int fd);
int drm_shim_ioctl(int fd, unsigned long request, void *arg);
void *drm_shim_mmap(struct shim_fd *shim_fd, size_t length, int prot, int flags,
                    int fd, off_t offset);

void drm_shim_bo_init(struct shim_bo *bo, size_t size);
void drm_shim_bo_get(struct shim_bo *bo);
void drm_shim_bo_put(struct shim_bo *bo);
struct shim_bo *drm_shim_bo_lookup(struct shim_fd *shim_fd, int handle);
int drm_shim_bo_get_handle(struct shim_fd *shim_fd, struct shim_bo *bo);
uint64_t drm_shim_bo_get_mmap_offset(struct shim_fd *shim_fd,
                                     struct shim_bo *bo);

/* driver-specific hooks. */
void drm_shim_driver_init(void);