xref: /aosp_15_r20/external/mesa3d/src/util/libdrm.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 <stddef.h>
36 #include <stdint.h>
37 #include <sys/types.h>
38 
39 #define DRM_NODE_PRIMARY 0
40 #define DRM_NODE_CONTROL 1
41 #define DRM_NODE_RENDER  2
42 #define DRM_NODE_MAX     3
43 
44 #define DRM_BUS_PCI       0
45 #define DRM_BUS_USB       1
46 #define DRM_BUS_PLATFORM  2
47 #define DRM_BUS_HOST1X    3
48 
49 typedef unsigned int drm_magic_t;
50 
51 static int
drmGetMagic(int fd,drm_magic_t * magic)52 drmGetMagic(int fd, drm_magic_t * magic)
53 {
54   return -EINVAL;
55 }
56 
57 typedef struct _drmPciDeviceInfo {
58     uint16_t vendor_id;
59     uint16_t device_id;
60     uint16_t subvendor_id;
61     uint16_t subdevice_id;
62     uint8_t revision_id;
63 } drmPciDeviceInfo, *drmPciDeviceInfoPtr;
64 
65 #define DRM_PLATFORM_DEVICE_NAME_LEN 512
66 
67 typedef struct _drmPlatformBusInfo {
68     char fullname[DRM_PLATFORM_DEVICE_NAME_LEN];
69 } drmPlatformBusInfo, *drmPlatformBusInfoPtr;
70 
71 typedef struct _drmPlatformDeviceInfo {
72     char **compatible; /* NULL terminated list of compatible strings */
73 } drmPlatformDeviceInfo, *drmPlatformDeviceInfoPtr;
74 
75 #define DRM_HOST1X_DEVICE_NAME_LEN 512
76 
77 typedef struct _drmHost1xBusInfo {
78     char fullname[DRM_HOST1X_DEVICE_NAME_LEN];
79 } drmHost1xBusInfo, *drmHost1xBusInfoPtr;
80 
81 typedef struct _drmPciBusInfo {
82    uint16_t domain;
83    uint8_t bus;
84    uint8_t dev;
85    uint8_t func;
86 } drmPciBusInfo, *drmPciBusInfoPtr;
87 
88 typedef struct _drmDevice {
89     char **nodes; /* DRM_NODE_MAX sized array */
90     int available_nodes; /* DRM_NODE_* bitmask */
91     int bustype;
92     union {
93        drmPciBusInfoPtr pci;
94        drmPlatformBusInfoPtr platform;
95        drmHost1xBusInfoPtr host1x;
96     } businfo;
97     union {
98         drmPciDeviceInfoPtr pci;
99     } deviceinfo;
100     /* ... */
101 } drmDevice, *drmDevicePtr;
102 
103 #define DRM_DEVICE_GET_PCI_REVISION (1 << 0)
104 static inline int
drmGetDevice2(int fd,uint32_t flags,drmDevicePtr * device)105 drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
106 {
107    return -ENOENT;
108 }
109 
110 static inline int
drmGetDevices2(uint32_t flags,drmDevicePtr devices[],int max_devices)111 drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
112 {
113    return -ENOENT;
114 }
115 
116 static inline int
drmGetDeviceFromDevId(dev_t dev_id,uint32_t flags,drmDevicePtr * device)117 drmGetDeviceFromDevId(dev_t dev_id, uint32_t flags, drmDevicePtr *device)
118 {
119    return -ENOENT;
120 }
121 
122 static inline void
drmFreeDevice(drmDevicePtr * device)123 drmFreeDevice(drmDevicePtr *device) {}
124 
125 static inline void
drmFreeDevices(drmDevicePtr devices[],int count)126 drmFreeDevices(drmDevicePtr devices[], int count) {}
127 
128 static inline char*
drmGetDeviceNameFromFd2(int fd)129 drmGetDeviceNameFromFd2(int fd) { return NULL;}
130 
131 typedef struct _drmVersion {
132     int     version_major;        /**< Major version */
133     int     version_minor;        /**< Minor version */
134     int     version_patchlevel;   /**< Patch level */
135     int     name_len;             /**< Length of name buffer */
136     char    *name;                /**< Name of driver */
137     int     date_len;             /**< Length of date buffer */
138     char    *date;                /**< User-space buffer to hold date */
139     int     desc_len;             /**< Length of desc buffer */
140     char    *desc;                /**< User-space buffer to hold desc */
141 } drmVersion, *drmVersionPtr;
142 
143 static inline struct _drmVersion *
drmGetVersion(int fd)144 drmGetVersion(int fd) { return NULL; }
145 
146 static inline void
drmFreeVersion(struct _drmVersion * v)147 drmFreeVersion(struct _drmVersion *v) {}
148 
149 #endif
150