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 **************************************************************************/
39 #include "target-helpers/drm_helper_public.h"
40 #include "state_tracker/drm_driver.h"
41 #include "pipe_loader_priv.h"
43 #include "util/u_memory.h"
44 #include "util/u_dl.h"
45 #include "util/u_debug.h"
47 #define DRM_RENDER_NODE_DEV_NAME_FORMAT "%s/renderD%d"
48 #define DRM_RENDER_NODE_MAX_NODES 63
49 #define DRM_RENDER_NODE_MIN_MINOR 128
50 #define DRM_RENDER_NODE_MAX_MINOR (DRM_RENDER_NODE_MIN_MINOR + DRM_RENDER_NODE_MAX_NODES)
52 struct pipe_loader_drm_device
{
53 struct pipe_loader_device base
;
54 const struct drm_driver_descriptor
*dd
;
55 #ifndef GALLIUM_STATIC_TARGETS
56 struct util_dl_library
*lib
;
61 #define pipe_loader_drm_device(dev) ((struct pipe_loader_drm_device *)dev)
63 static const struct pipe_loader_ops pipe_loader_drm_ops
;
65 #ifdef GALLIUM_STATIC_TARGETS
66 static const struct drm_conf_ret throttle_ret
= {
71 static const struct drm_conf_ret share_fd_ret
= {
76 static inline const struct drm_conf_ret
*
77 configuration_query(enum drm_conf conf
)
80 case DRM_CONF_THROTTLE
:
82 case DRM_CONF_SHARE_FD
:
90 static const struct drm_driver_descriptor driver_descriptors
[] = {
93 .driver_name
= "i915",
94 .create_screen
= pipe_i915_create_screen
,
95 .configuration
= configuration_query
,
99 .driver_name
= "i915",
100 .create_screen
= pipe_ilo_create_screen
,
101 .configuration
= configuration_query
,
105 .driver_name
= "nouveau",
106 .create_screen
= pipe_nouveau_create_screen
,
107 .configuration
= configuration_query
,
111 .driver_name
= "radeon",
112 .create_screen
= pipe_r300_create_screen
,
113 .configuration
= configuration_query
,
117 .driver_name
= "radeon",
118 .create_screen
= pipe_r600_create_screen
,
119 .configuration
= configuration_query
,
123 .driver_name
= "radeon",
124 .create_screen
= pipe_radeonsi_create_screen
,
125 .configuration
= configuration_query
,
129 .driver_name
= "vmwgfx",
130 .create_screen
= pipe_vmwgfx_create_screen
,
131 .configuration
= configuration_query
,
135 .driver_name
= "freedreno",
136 .create_screen
= pipe_freedreno_create_screen
,
137 .configuration
= configuration_query
,
141 .driver_name
= "freedreno",
142 .create_screen
= pipe_freedreno_create_screen
,
143 .configuration
= configuration_query
,
146 .name
= "virtio_gpu",
147 .driver_name
= "virtio-gpu",
148 .create_screen
= pipe_virgl_create_screen
,
149 .configuration
= configuration_query
,
153 .driver_name
= "vc4",
154 .create_screen
= pipe_vc4_create_screen
,
155 .configuration
= configuration_query
,
157 #ifdef USE_VC4_SIMULATOR
160 .driver_name
= "vc4",
161 .create_screen
= pipe_vc4_create_screen
,
162 .configuration
= configuration_query
,
169 pipe_loader_drm_probe_fd(struct pipe_loader_device
**dev
, int fd
)
171 struct pipe_loader_drm_device
*ddev
= CALLOC_STRUCT(pipe_loader_drm_device
);
172 int vendor_id
, chip_id
;
177 if (loader_get_pci_id_for_fd(fd
, &vendor_id
, &chip_id
)) {
178 ddev
->base
.type
= PIPE_LOADER_DEVICE_PCI
;
179 ddev
->base
.u
.pci
.vendor_id
= vendor_id
;
180 ddev
->base
.u
.pci
.chip_id
= chip_id
;
182 ddev
->base
.type
= PIPE_LOADER_DEVICE_PLATFORM
;
184 ddev
->base
.ops
= &pipe_loader_drm_ops
;
187 ddev
->base
.driver_name
= loader_get_driver_for_fd(fd
, _LOADER_GALLIUM
);
188 if (!ddev
->base
.driver_name
)
191 #ifdef GALLIUM_STATIC_TARGETS
192 for (int i
= 0; i
< ARRAY_SIZE(driver_descriptors
); i
++) {
193 if (strcmp(driver_descriptors
[i
].name
, ddev
->base
.driver_name
) == 0) {
194 ddev
->dd
= &driver_descriptors
[i
];
201 ddev
->lib
= pipe_loader_find_module(&ddev
->base
, PIPE_SEARCH_DIR
);
205 ddev
->dd
= (const struct drm_driver_descriptor
*)
206 util_dl_get_proc_address(ddev
->lib
, "driver_descriptor");
208 /* sanity check on the name */
209 if (!ddev
->dd
|| strcmp(ddev
->dd
->name
, ddev
->base
.driver_name
) != 0)
217 #ifndef GALLIUM_STATIC_TARGETS
219 util_dl_close(ddev
->lib
);
226 open_drm_render_node_minor(int minor
)
229 snprintf(path
, sizeof(path
), DRM_RENDER_NODE_DEV_NAME_FORMAT
, DRM_DIR_NAME
,
231 return loader_open_device(path
);
235 pipe_loader_drm_probe(struct pipe_loader_device
**devs
, int ndev
)
239 for (i
= DRM_RENDER_NODE_MIN_MINOR
, j
= 0;
240 i
<= DRM_RENDER_NODE_MAX_MINOR
; i
++) {
241 struct pipe_loader_device
*dev
;
243 fd
= open_drm_render_node_minor(i
);
247 if (!pipe_loader_drm_probe_fd(&dev
, fd
)) {
256 dev
->ops
->release(&dev
);
265 pipe_loader_drm_release(struct pipe_loader_device
**dev
)
267 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(*dev
);
269 #ifndef GALLIUM_STATIC_TARGETS
271 util_dl_close(ddev
->lib
);
275 FREE(ddev
->base
.driver_name
);
280 static const struct drm_conf_ret
*
281 pipe_loader_drm_configuration(struct pipe_loader_device
*dev
,
284 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
286 if (!ddev
->dd
->configuration
)
289 return ddev
->dd
->configuration(conf
);
292 static struct pipe_screen
*
293 pipe_loader_drm_create_screen(struct pipe_loader_device
*dev
)
295 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
297 return ddev
->dd
->create_screen(ddev
->fd
);
300 static const struct pipe_loader_ops pipe_loader_drm_ops
= {
301 .create_screen
= pipe_loader_drm_create_screen
,
302 .configuration
= pipe_loader_drm_configuration
,
303 .release
= pipe_loader_drm_release