1 /*
2 * Copyright © 2023 Google, Inc.
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 /*
25 * A simple header that either gives you the real libdrm or a no-op shim,
26 * depending on whether HAVE_LIBDRM is defined. This is intended to avoid
27 * the proliferation of #ifdef'ery to support environments without libdrm.
28 */
29
30 #ifdef HAVE_LIBDRM
31 #include <xf86drm.h>
32 #else
33
34 #include <errno.h>
35 #include <stdint.h>
36 #include <sys/types.h>
37
38 #define DRM_NODE_PRIMARY 0
39 #define DRM_NODE_CONTROL 1
40 #define DRM_NODE_RENDER 2
41 #define DRM_NODE_MAX 3
42
43 #define DRM_BUS_PCI 0
44 #define DRM_BUS_USB 1
45 #define DRM_BUS_PLATFORM 2
46 #define DRM_BUS_HOST1X 3
47
48 typedef struct _drmPciDeviceInfo {
49 uint16_t vendor_id;
50 uint16_t device_id;
51 uint16_t subvendor_id;
52 uint16_t subdevice_id;
53 uint8_t revision_id;
54 } drmPciDeviceInfo, *drmPciDeviceInfoPtr;
55
56 #define DRM_PLATFORM_DEVICE_NAME_LEN 512
57
58 typedef struct _drmPlatformBusInfo {
59 char fullname[DRM_PLATFORM_DEVICE_NAME_LEN];
60 } drmPlatformBusInfo, *drmPlatformBusInfoPtr;
61
62 typedef struct _drmPlatformDeviceInfo {
63 char **compatible; /* NULL terminated list of compatible strings */
64 } drmPlatformDeviceInfo, *drmPlatformDeviceInfoPtr;
65
66 #define DRM_HOST1X_DEVICE_NAME_LEN 512
67
68 typedef struct _drmHost1xBusInfo {
69 char fullname[DRM_HOST1X_DEVICE_NAME_LEN];
70 } drmHost1xBusInfo, *drmHost1xBusInfoPtr;
71
72 typedef struct _drmPciBusInfo {
73 uint16_t domain;
74 uint8_t bus;
75 uint8_t dev;
76 uint8_t func;
77 } drmPciBusInfo, *drmPciBusInfoPtr;
78
79 typedef struct _drmDevice {
80 char **nodes; /* DRM_NODE_MAX sized array */
81 int available_nodes; /* DRM_NODE_* bitmask */
82 int bustype;
83 union {
84 drmPciBusInfoPtr pci;
85 drmPlatformBusInfoPtr platform;
86 drmHost1xBusInfoPtr host1x;
87 } businfo;
88 union {
89 drmPciDeviceInfoPtr pci;
90 } deviceinfo;
91 /* ... */
92 } drmDevice, *drmDevicePtr;
93
94 #define DRM_DEVICE_GET_PCI_REVISION (1 << 0)
95 static inline int
drmGetDevice2(int fd,uint32_t flags,drmDevicePtr * device)96 drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
97 {
98 return -ENOENT;
99 }
100
101 static inline int
drmGetDevices2(uint32_t flags,drmDevicePtr devices[],int max_devices)102 drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
103 {
104 return -ENOENT;
105 }
106
107 static inline int
drmGetDeviceFromDevId(dev_t dev_id,uint32_t flags,drmDevicePtr * device)108 drmGetDeviceFromDevId(dev_t dev_id, uint32_t flags, drmDevicePtr *device)
109 {
110 return -ENOENT;
111 }
112
113 static inline void
drmFreeDevice(drmDevicePtr * device)114 drmFreeDevice(drmDevicePtr *device) {}
115
116 static inline void
drmFreeDevices(drmDevicePtr devices[],int count)117 drmFreeDevices(drmDevicePtr devices[], int count) {}
118
119 static inline char*
drmGetDeviceNameFromFd2(int fd)120 drmGetDeviceNameFromFd2(int fd) { return NULL;}
121
122 typedef struct _drmVersion {
123 int version_major; /**< Major version */
124 int version_minor; /**< Minor version */
125 int version_patchlevel; /**< Patch level */
126 int name_len; /**< Length of name buffer */
127 char *name; /**< Name of driver */
128 int date_len; /**< Length of date buffer */
129 char *date; /**< User-space buffer to hold date */
130 int desc_len; /**< Length of desc buffer */
131 char *desc; /**< User-space buffer to hold desc */
132 } drmVersion, *drmVersionPtr;
133
134 static inline struct _drmVersion *
drmGetVersion(int fd)135 drmGetVersion(int fd) { return NULL; }
136
137 static inline void
drmFreeVersion(struct _drmVersion * v)138 drmFreeVersion(struct _drmVersion *v) {}
139
140 #endif
141