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 **************************************************************************/
40 #include "target-helpers/drm_helper_public.h"
41 #include "state_tracker/drm_driver.h"
42 #include "pipe_loader_priv.h"
44 #include "util/u_memory.h"
45 #include "util/u_dl.h"
46 #include "util/u_debug.h"
48 #define DRM_RENDER_NODE_DEV_NAME_FORMAT "%s/renderD%d"
49 #define DRM_RENDER_NODE_MAX_NODES 63
50 #define DRM_RENDER_NODE_MIN_MINOR 128
51 #define DRM_RENDER_NODE_MAX_MINOR (DRM_RENDER_NODE_MIN_MINOR + DRM_RENDER_NODE_MAX_NODES)
53 struct pipe_loader_drm_device
{
54 struct pipe_loader_device base
;
55 const struct drm_driver_descriptor
*dd
;
56 #ifndef GALLIUM_STATIC_TARGETS
57 struct util_dl_library
*lib
;
62 #define pipe_loader_drm_device(dev) ((struct pipe_loader_drm_device *)dev)
64 static const struct pipe_loader_ops pipe_loader_drm_ops
;
66 #ifdef GALLIUM_STATIC_TARGETS
67 static const struct drm_driver_descriptor driver_descriptors
[] = {
69 .driver_name
= "i915",
70 .create_screen
= pipe_i915_create_screen
,
71 .configuration
= pipe_default_configuration_query
,
74 .driver_name
= "nouveau",
75 .create_screen
= pipe_nouveau_create_screen
,
76 .configuration
= pipe_default_configuration_query
,
79 .driver_name
= "r300",
80 .create_screen
= pipe_r300_create_screen
,
81 .configuration
= pipe_default_configuration_query
,
84 .driver_name
= "r600",
85 .create_screen
= pipe_r600_create_screen
,
86 .configuration
= pipe_default_configuration_query
,
89 .driver_name
= "radeonsi",
90 .create_screen
= pipe_radeonsi_create_screen
,
91 .configuration
= pipe_radeonsi_configuration_query
,
94 .driver_name
= "vmwgfx",
95 .create_screen
= pipe_vmwgfx_create_screen
,
96 .configuration
= pipe_default_configuration_query
,
99 .driver_name
= "kgsl",
100 .create_screen
= pipe_freedreno_create_screen
,
101 .configuration
= pipe_default_configuration_query
,
104 .driver_name
= "msm",
105 .create_screen
= pipe_freedreno_create_screen
,
106 .configuration
= pipe_default_configuration_query
,
109 .driver_name
= "pl111",
110 .create_screen
= pipe_pl111_create_screen
,
111 .configuration
= pipe_default_configuration_query
,
114 .driver_name
= "virtio_gpu",
115 .create_screen
= pipe_virgl_create_screen
,
116 .configuration
= pipe_default_configuration_query
,
119 .driver_name
= "vc4",
120 .create_screen
= pipe_vc4_create_screen
,
121 .configuration
= pipe_default_configuration_query
,
124 .driver_name
= "vc5",
125 .create_screen
= pipe_vc5_create_screen
,
126 .configuration
= pipe_default_configuration_query
,
129 .driver_name
= "etnaviv",
130 .create_screen
= pipe_etna_create_screen
,
131 .configuration
= pipe_default_configuration_query
,
134 .driver_name
= "imx-drm",
135 .create_screen
= pipe_imx_drm_create_screen
,
136 .configuration
= pipe_default_configuration_query
,
141 static const struct drm_driver_descriptor
*
142 get_driver_descriptor(const char *driver_name
, struct util_dl_library
**plib
)
144 #ifdef GALLIUM_STATIC_TARGETS
145 for (int i
= 0; i
< ARRAY_SIZE(driver_descriptors
); i
++) {
146 if (strcmp(driver_descriptors
[i
].driver_name
, driver_name
) == 0)
147 return &driver_descriptors
[i
];
150 *plib
= pipe_loader_find_module(driver_name
, PIPE_SEARCH_DIR
);
154 const struct drm_driver_descriptor
*dd
=
155 (const struct drm_driver_descriptor
*)
156 util_dl_get_proc_address(*plib
, "driver_descriptor");
158 /* sanity check on the driver name */
159 if (dd
&& strcmp(dd
->driver_name
, driver_name
) == 0)
167 pipe_loader_drm_probe_fd(struct pipe_loader_device
**dev
, int fd
)
169 struct pipe_loader_drm_device
*ddev
= CALLOC_STRUCT(pipe_loader_drm_device
);
170 int vendor_id
, chip_id
;
175 if (loader_get_pci_id_for_fd(fd
, &vendor_id
, &chip_id
)) {
176 ddev
->base
.type
= PIPE_LOADER_DEVICE_PCI
;
177 ddev
->base
.u
.pci
.vendor_id
= vendor_id
;
178 ddev
->base
.u
.pci
.chip_id
= chip_id
;
180 ddev
->base
.type
= PIPE_LOADER_DEVICE_PLATFORM
;
182 ddev
->base
.ops
= &pipe_loader_drm_ops
;
185 ddev
->base
.driver_name
= loader_get_driver_for_fd(fd
);
186 if (!ddev
->base
.driver_name
)
189 struct util_dl_library
**plib
= NULL
;
190 #ifndef GALLIUM_STATIC_TARGETS
193 ddev
->dd
= get_driver_descriptor(ddev
->base
.driver_name
, plib
);
201 #ifndef GALLIUM_STATIC_TARGETS
203 util_dl_close(ddev
->lib
);
210 open_drm_render_node_minor(int minor
)
213 snprintf(path
, sizeof(path
), DRM_RENDER_NODE_DEV_NAME_FORMAT
, DRM_DIR_NAME
,
215 return loader_open_device(path
);
219 pipe_loader_drm_probe(struct pipe_loader_device
**devs
, int ndev
)
223 for (i
= DRM_RENDER_NODE_MIN_MINOR
, j
= 0;
224 i
<= DRM_RENDER_NODE_MAX_MINOR
; i
++) {
225 struct pipe_loader_device
*dev
;
227 fd
= open_drm_render_node_minor(i
);
231 if (!pipe_loader_drm_probe_fd(&dev
, fd
)) {
240 dev
->ops
->release(&dev
);
249 pipe_loader_drm_release(struct pipe_loader_device
**dev
)
251 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(*dev
);
253 #ifndef GALLIUM_STATIC_TARGETS
255 util_dl_close(ddev
->lib
);
259 FREE(ddev
->base
.driver_name
);
260 pipe_loader_base_release(dev
);
263 static const struct drm_conf_ret
*
264 pipe_loader_drm_configuration(struct pipe_loader_device
*dev
,
267 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
269 if (!ddev
->dd
->configuration
)
272 return ddev
->dd
->configuration(conf
);
275 static struct pipe_screen
*
276 pipe_loader_drm_create_screen(struct pipe_loader_device
*dev
,
277 const struct pipe_screen_config
*config
)
279 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
281 return ddev
->dd
->create_screen(ddev
->fd
, config
);
285 pipe_loader_drm_get_driinfo_xml(const char *driver_name
)
288 struct util_dl_library
*lib
= NULL
;
289 const struct drm_driver_descriptor
*dd
=
290 get_driver_descriptor(driver_name
, &lib
);
294 const struct drm_conf_ret
*conf
= dd
->configuration(DRM_CONF_XML_OPTIONS
);
298 xml
= strdup((const char *)conf
->val
.val_pointer
);
306 static const struct pipe_loader_ops pipe_loader_drm_ops
= {
307 .create_screen
= pipe_loader_drm_create_screen
,
308 .configuration
= pipe_loader_drm_configuration
,
309 .release
= pipe_loader_drm_release