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
= "v3d",
120 .create_screen
= pipe_v3d_create_screen
,
121 .configuration
= pipe_default_configuration_query
,
124 .driver_name
= "vc4",
125 .create_screen
= pipe_vc4_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
,
139 .driver_name
= "tegra",
140 .create_screen
= pipe_tegra_create_screen
,
141 .configuration
= pipe_default_configuration_query
,
146 static const struct drm_driver_descriptor
*
147 get_driver_descriptor(const char *driver_name
, struct util_dl_library
**plib
)
149 #ifdef GALLIUM_STATIC_TARGETS
150 for (int i
= 0; i
< ARRAY_SIZE(driver_descriptors
); i
++) {
151 if (strcmp(driver_descriptors
[i
].driver_name
, driver_name
) == 0)
152 return &driver_descriptors
[i
];
155 *plib
= pipe_loader_find_module(driver_name
, PIPE_SEARCH_DIR
);
159 const struct drm_driver_descriptor
*dd
=
160 (const struct drm_driver_descriptor
*)
161 util_dl_get_proc_address(*plib
, "driver_descriptor");
163 /* sanity check on the driver name */
164 if (dd
&& strcmp(dd
->driver_name
, driver_name
) == 0)
172 pipe_loader_drm_probe_fd(struct pipe_loader_device
**dev
, int fd
)
174 struct pipe_loader_drm_device
*ddev
= CALLOC_STRUCT(pipe_loader_drm_device
);
175 int vendor_id
, chip_id
;
180 if (loader_get_pci_id_for_fd(fd
, &vendor_id
, &chip_id
)) {
181 ddev
->base
.type
= PIPE_LOADER_DEVICE_PCI
;
182 ddev
->base
.u
.pci
.vendor_id
= vendor_id
;
183 ddev
->base
.u
.pci
.chip_id
= chip_id
;
185 ddev
->base
.type
= PIPE_LOADER_DEVICE_PLATFORM
;
187 ddev
->base
.ops
= &pipe_loader_drm_ops
;
190 ddev
->base
.driver_name
= loader_get_driver_for_fd(fd
);
191 if (!ddev
->base
.driver_name
)
194 struct util_dl_library
**plib
= NULL
;
195 #ifndef GALLIUM_STATIC_TARGETS
198 ddev
->dd
= get_driver_descriptor(ddev
->base
.driver_name
, plib
);
206 #ifndef GALLIUM_STATIC_TARGETS
208 util_dl_close(ddev
->lib
);
210 FREE(ddev
->base
.driver_name
);
216 open_drm_render_node_minor(int minor
)
219 snprintf(path
, sizeof(path
), DRM_RENDER_NODE_DEV_NAME_FORMAT
, DRM_DIR_NAME
,
221 return loader_open_device(path
);
225 pipe_loader_drm_probe(struct pipe_loader_device
**devs
, int ndev
)
229 for (i
= DRM_RENDER_NODE_MIN_MINOR
, j
= 0;
230 i
<= DRM_RENDER_NODE_MAX_MINOR
; i
++) {
231 struct pipe_loader_device
*dev
;
233 fd
= open_drm_render_node_minor(i
);
237 if (!pipe_loader_drm_probe_fd(&dev
, fd
)) {
246 dev
->ops
->release(&dev
);
255 pipe_loader_drm_release(struct pipe_loader_device
**dev
)
257 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(*dev
);
259 #ifndef GALLIUM_STATIC_TARGETS
261 util_dl_close(ddev
->lib
);
265 FREE(ddev
->base
.driver_name
);
266 pipe_loader_base_release(dev
);
269 static const struct drm_conf_ret
*
270 pipe_loader_drm_configuration(struct pipe_loader_device
*dev
,
273 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
275 if (!ddev
->dd
->configuration
)
278 return ddev
->dd
->configuration(conf
);
281 static struct pipe_screen
*
282 pipe_loader_drm_create_screen(struct pipe_loader_device
*dev
,
283 const struct pipe_screen_config
*config
)
285 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
287 return ddev
->dd
->create_screen(ddev
->fd
, config
);
291 pipe_loader_drm_get_driinfo_xml(const char *driver_name
)
294 struct util_dl_library
*lib
= NULL
;
295 const struct drm_driver_descriptor
*dd
=
296 get_driver_descriptor(driver_name
, &lib
);
300 const struct drm_conf_ret
*conf
= dd
->configuration(DRM_CONF_XML_OPTIONS
);
304 xml
= strdup((const char *)conf
->val
.val_pointer
);
312 static const struct pipe_loader_ops pipe_loader_drm_ops
= {
313 .create_screen
= pipe_loader_drm_create_screen
,
314 .configuration
= pipe_loader_drm_configuration
,
315 .release
= pipe_loader_drm_release