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 "state_tracker/drm_driver.h"
40 #include "pipe_loader_priv.h"
42 #include "util/u_memory.h"
43 #include "util/u_dl.h"
44 #include "util/u_debug.h"
46 #define DRM_RENDER_NODE_DEV_NAME_FORMAT "%s/renderD%d"
47 #define DRM_RENDER_NODE_MAX_NODES 63
48 #define DRM_RENDER_NODE_MIN_MINOR 128
49 #define DRM_RENDER_NODE_MAX_MINOR (DRM_RENDER_NODE_MIN_MINOR + DRM_RENDER_NODE_MAX_NODES)
51 struct pipe_loader_drm_device
{
52 struct pipe_loader_device base
;
53 struct util_dl_library
*lib
;
57 #define pipe_loader_drm_device(dev) ((struct pipe_loader_drm_device *)dev)
59 static struct pipe_loader_ops pipe_loader_drm_ops
;
62 pipe_loader_drm_probe_fd(struct pipe_loader_device
**dev
, int fd
)
64 struct pipe_loader_drm_device
*ddev
= CALLOC_STRUCT(pipe_loader_drm_device
);
65 int vendor_id
, chip_id
;
70 if (loader_get_pci_id_for_fd(fd
, &vendor_id
, &chip_id
)) {
71 ddev
->base
.type
= PIPE_LOADER_DEVICE_PCI
;
72 ddev
->base
.u
.pci
.vendor_id
= vendor_id
;
73 ddev
->base
.u
.pci
.chip_id
= chip_id
;
75 ddev
->base
.type
= PIPE_LOADER_DEVICE_PLATFORM
;
77 ddev
->base
.ops
= &pipe_loader_drm_ops
;
80 ddev
->base
.driver_name
= loader_get_driver_for_fd(fd
, _LOADER_GALLIUM
);
81 if (!ddev
->base
.driver_name
)
93 open_drm_render_node_minor(int minor
)
96 snprintf(path
, sizeof(path
), DRM_RENDER_NODE_DEV_NAME_FORMAT
, DRM_DIR_NAME
,
98 return loader_open_device(path
);
102 pipe_loader_drm_probe(struct pipe_loader_device
**devs
, int ndev
)
106 for (i
= DRM_RENDER_NODE_MIN_MINOR
, j
= 0;
107 i
<= DRM_RENDER_NODE_MAX_MINOR
; i
++) {
108 fd
= open_drm_render_node_minor(i
);
109 struct pipe_loader_device
*dev
;
113 if (!pipe_loader_drm_probe_fd(&dev
, fd
)) {
122 dev
->ops
->release(&dev
);
131 pipe_loader_drm_release(struct pipe_loader_device
**dev
)
133 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(*dev
);
136 util_dl_close(ddev
->lib
);
139 FREE(ddev
->base
.driver_name
);
144 static const struct drm_conf_ret
*
145 pipe_loader_drm_configuration(struct pipe_loader_device
*dev
,
148 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
149 const struct drm_driver_descriptor
*dd
;
154 dd
= (const struct drm_driver_descriptor
*)
155 util_dl_get_proc_address(ddev
->lib
, "driver_descriptor");
157 /* sanity check on the name */
158 if (!dd
|| strcmp(dd
->name
, ddev
->base
.driver_name
) != 0)
161 if (!dd
->configuration
)
164 return dd
->configuration(conf
);
167 static struct pipe_screen
*
168 pipe_loader_drm_create_screen(struct pipe_loader_device
*dev
,
169 const char *library_paths
)
171 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
172 const struct drm_driver_descriptor
*dd
;
175 ddev
->lib
= pipe_loader_find_module(dev
, library_paths
);
179 dd
= (const struct drm_driver_descriptor
*)
180 util_dl_get_proc_address(ddev
->lib
, "driver_descriptor");
182 /* sanity check on the name */
183 if (!dd
|| strcmp(dd
->name
, ddev
->base
.driver_name
) != 0)
186 return dd
->create_screen(ddev
->fd
);
189 static struct pipe_loader_ops pipe_loader_drm_ops
= {
190 .create_screen
= pipe_loader_drm_create_screen
,
191 .configuration
= pipe_loader_drm_configuration
,
192 .release
= pipe_loader_drm_release