1 /**************************************************************************
3 * Copyright 2011 Intel Corporation
4 * Copyright 2012 Francisco Jerez
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Kristian Høgsberg <krh@bitplanet.net>
29 * Benjamin Franzke <benjaminfranzke@googlemail.com>
31 **************************************************************************/
41 #include "target-helpers/drm_helper_public.h"
42 #include "state_tracker/drm_driver.h"
43 #include "pipe_loader_priv.h"
45 #include "util/u_memory.h"
46 #include "util/u_dl.h"
47 #include "util/u_debug.h"
49 #define DRM_RENDER_NODE_DEV_NAME_FORMAT "%s/renderD%d"
50 #define DRM_RENDER_NODE_MAX_NODES 63
51 #define DRM_RENDER_NODE_MIN_MINOR 128
52 #define DRM_RENDER_NODE_MAX_MINOR (DRM_RENDER_NODE_MIN_MINOR + DRM_RENDER_NODE_MAX_NODES)
54 struct pipe_loader_drm_device
{
55 struct pipe_loader_device base
;
56 const struct drm_driver_descriptor
*dd
;
57 #ifndef GALLIUM_STATIC_TARGETS
58 struct util_dl_library
*lib
;
63 #define pipe_loader_drm_device(dev) ((struct pipe_loader_drm_device *)dev)
65 static const struct pipe_loader_ops pipe_loader_drm_ops
;
67 #ifdef GALLIUM_STATIC_TARGETS
68 static const struct drm_driver_descriptor driver_descriptors
[] = {
70 .driver_name
= "i915",
71 .create_screen
= pipe_i915_create_screen
,
72 .configuration
= pipe_default_configuration_query
,
75 .driver_name
= "iris",
76 .create_screen
= pipe_iris_create_screen
,
77 .configuration
= pipe_default_configuration_query
,
80 .driver_name
= "nouveau",
81 .create_screen
= pipe_nouveau_create_screen
,
82 .configuration
= pipe_default_configuration_query
,
85 .driver_name
= "r300",
86 .create_screen
= pipe_r300_create_screen
,
87 .configuration
= pipe_default_configuration_query
,
90 .driver_name
= "r600",
91 .create_screen
= pipe_r600_create_screen
,
92 .configuration
= pipe_default_configuration_query
,
95 .driver_name
= "radeonsi",
96 .create_screen
= pipe_radeonsi_create_screen
,
97 .configuration
= pipe_radeonsi_configuration_query
,
100 .driver_name
= "vmwgfx",
101 .create_screen
= pipe_vmwgfx_create_screen
,
102 .configuration
= pipe_default_configuration_query
,
105 .driver_name
= "kgsl",
106 .create_screen
= pipe_freedreno_create_screen
,
107 .configuration
= pipe_default_configuration_query
,
110 .driver_name
= "msm",
111 .create_screen
= pipe_freedreno_create_screen
,
112 .configuration
= pipe_default_configuration_query
,
115 .driver_name
= "virtio_gpu",
116 .create_screen
= pipe_virgl_create_screen
,
117 .configuration
= pipe_default_configuration_query
,
120 .driver_name
= "v3d",
121 .create_screen
= pipe_v3d_create_screen
,
122 .configuration
= pipe_default_configuration_query
,
125 .driver_name
= "vc4",
126 .create_screen
= pipe_vc4_create_screen
,
127 .configuration
= pipe_default_configuration_query
,
130 .driver_name
= "panfrost",
131 .create_screen
= pipe_panfrost_create_screen
,
132 .configuration
= pipe_default_configuration_query
,
135 .driver_name
= "etnaviv",
136 .create_screen
= pipe_etna_create_screen
,
137 .configuration
= pipe_default_configuration_query
,
140 .driver_name
= "tegra",
141 .create_screen
= pipe_tegra_create_screen
,
142 .configuration
= pipe_default_configuration_query
,
145 .driver_name
= "lima",
146 .create_screen
= pipe_lima_create_screen
,
147 .configuration
= pipe_default_configuration_query
,
151 static const struct drm_driver_descriptor default_driver_descriptor
= {
152 .driver_name
= "kmsro",
153 .create_screen
= pipe_kmsro_create_screen
,
154 .configuration
= pipe_default_configuration_query
,
159 static const struct drm_driver_descriptor
*
160 get_driver_descriptor(const char *driver_name
, struct util_dl_library
**plib
)
162 #ifdef GALLIUM_STATIC_TARGETS
163 for (int i
= 0; i
< ARRAY_SIZE(driver_descriptors
); i
++) {
164 if (strcmp(driver_descriptors
[i
].driver_name
, driver_name
) == 0)
165 return &driver_descriptors
[i
];
167 return &default_driver_descriptor
;
169 *plib
= pipe_loader_find_module(driver_name
, PIPE_SEARCH_DIR
);
173 const struct drm_driver_descriptor
*dd
=
174 (const struct drm_driver_descriptor
*)
175 util_dl_get_proc_address(*plib
, "driver_descriptor");
177 /* sanity check on the driver name */
178 if (dd
&& strcmp(dd
->driver_name
, driver_name
) == 0)
186 pipe_loader_drm_probe_fd_nodup(struct pipe_loader_device
**dev
, int fd
)
188 struct pipe_loader_drm_device
*ddev
= CALLOC_STRUCT(pipe_loader_drm_device
);
189 int vendor_id
, chip_id
;
194 if (loader_get_pci_id_for_fd(fd
, &vendor_id
, &chip_id
)) {
195 ddev
->base
.type
= PIPE_LOADER_DEVICE_PCI
;
196 ddev
->base
.u
.pci
.vendor_id
= vendor_id
;
197 ddev
->base
.u
.pci
.chip_id
= chip_id
;
199 ddev
->base
.type
= PIPE_LOADER_DEVICE_PLATFORM
;
201 ddev
->base
.ops
= &pipe_loader_drm_ops
;
204 ddev
->base
.driver_name
= loader_get_driver_for_fd(fd
);
205 if (!ddev
->base
.driver_name
)
208 struct util_dl_library
**plib
= NULL
;
209 #ifndef GALLIUM_STATIC_TARGETS
212 ddev
->dd
= get_driver_descriptor(ddev
->base
.driver_name
, plib
);
220 #ifndef GALLIUM_STATIC_TARGETS
222 util_dl_close(ddev
->lib
);
224 FREE(ddev
->base
.driver_name
);
230 pipe_loader_drm_probe_fd(struct pipe_loader_device
**dev
, int fd
)
235 if (fd
< 0 || (new_fd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
238 ret
= pipe_loader_drm_probe_fd_nodup(dev
, new_fd
);
246 open_drm_render_node_minor(int minor
)
249 snprintf(path
, sizeof(path
), DRM_RENDER_NODE_DEV_NAME_FORMAT
, DRM_DIR_NAME
,
251 return loader_open_device(path
);
255 pipe_loader_drm_probe(struct pipe_loader_device
**devs
, int ndev
)
259 for (i
= DRM_RENDER_NODE_MIN_MINOR
, j
= 0;
260 i
<= DRM_RENDER_NODE_MAX_MINOR
; i
++) {
261 struct pipe_loader_device
*dev
;
263 fd
= open_drm_render_node_minor(i
);
267 if (!pipe_loader_drm_probe_fd_nodup(&dev
, fd
)) {
276 dev
->ops
->release(&dev
);
285 pipe_loader_drm_release(struct pipe_loader_device
**dev
)
287 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(*dev
);
289 #ifndef GALLIUM_STATIC_TARGETS
291 util_dl_close(ddev
->lib
);
295 FREE(ddev
->base
.driver_name
);
296 pipe_loader_base_release(dev
);
299 static const struct drm_conf_ret
*
300 pipe_loader_drm_configuration(struct pipe_loader_device
*dev
,
303 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
305 if (!ddev
->dd
->configuration
)
308 return ddev
->dd
->configuration(conf
);
311 static struct pipe_screen
*
312 pipe_loader_drm_create_screen(struct pipe_loader_device
*dev
,
313 const struct pipe_screen_config
*config
)
315 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
317 return ddev
->dd
->create_screen(ddev
->fd
, config
);
321 pipe_loader_drm_get_driinfo_xml(const char *driver_name
)
324 struct util_dl_library
*lib
= NULL
;
325 const struct drm_driver_descriptor
*dd
=
326 get_driver_descriptor(driver_name
, &lib
);
330 const struct drm_conf_ret
*conf
= dd
->configuration(DRM_CONF_XML_OPTIONS
);
334 xml
= strdup((const char *)conf
->val
.val_pointer
);
342 static const struct pipe_loader_ops pipe_loader_drm_ops
= {
343 .create_screen
= pipe_loader_drm_create_screen
,
344 .configuration
= pipe_loader_drm_configuration
,
345 .release
= pipe_loader_drm_release