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 const struct drm_driver_descriptor
*dd
;
54 struct util_dl_library
*lib
;
58 #define pipe_loader_drm_device(dev) ((struct pipe_loader_drm_device *)dev)
60 static const struct pipe_loader_ops pipe_loader_drm_ops
;
63 pipe_loader_drm_probe_fd(struct pipe_loader_device
**dev
, int fd
)
65 struct pipe_loader_drm_device
*ddev
= CALLOC_STRUCT(pipe_loader_drm_device
);
66 int vendor_id
, chip_id
;
71 if (loader_get_pci_id_for_fd(fd
, &vendor_id
, &chip_id
)) {
72 ddev
->base
.type
= PIPE_LOADER_DEVICE_PCI
;
73 ddev
->base
.u
.pci
.vendor_id
= vendor_id
;
74 ddev
->base
.u
.pci
.chip_id
= chip_id
;
76 ddev
->base
.type
= PIPE_LOADER_DEVICE_PLATFORM
;
78 ddev
->base
.ops
= &pipe_loader_drm_ops
;
81 ddev
->base
.driver_name
= loader_get_driver_for_fd(fd
, _LOADER_GALLIUM
);
82 if (!ddev
->base
.driver_name
)
85 ddev
->lib
= pipe_loader_find_module(dev
, PIPE_SEARCH_DIR
);
89 ddev
->dd
= (const struct drm_driver_descriptor
*)
90 util_dl_get_proc_address(ddev
->lib
, "driver_descriptor");
92 /* sanity check on the name */
93 if (!ddev
->dd
|| strcmp(ddev
->dd
->name
, ddev
->base
.driver_name
) != 0)
101 util_dl_close(ddev
->lib
);
107 open_drm_render_node_minor(int minor
)
110 snprintf(path
, sizeof(path
), DRM_RENDER_NODE_DEV_NAME_FORMAT
, DRM_DIR_NAME
,
112 return loader_open_device(path
);
116 pipe_loader_drm_probe(struct pipe_loader_device
**devs
, int ndev
)
120 for (i
= DRM_RENDER_NODE_MIN_MINOR
, j
= 0;
121 i
<= DRM_RENDER_NODE_MAX_MINOR
; i
++) {
122 fd
= open_drm_render_node_minor(i
);
123 struct pipe_loader_device
*dev
;
127 if (!pipe_loader_drm_probe_fd(&dev
, fd
)) {
136 dev
->ops
->release(&dev
);
145 pipe_loader_drm_release(struct pipe_loader_device
**dev
)
147 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(*dev
);
150 util_dl_close(ddev
->lib
);
153 FREE(ddev
->base
.driver_name
);
158 static const struct drm_conf_ret
*
159 pipe_loader_drm_configuration(struct pipe_loader_device
*dev
,
162 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
164 if (!ddev
->dd
->configuration
)
167 return ddev
->dd
->configuration(conf
);
170 static struct pipe_screen
*
171 pipe_loader_drm_create_screen(struct pipe_loader_device
*dev
)
173 struct pipe_loader_drm_device
*ddev
= pipe_loader_drm_device(dev
);
175 return ddev
->dd
->create_screen(ddev
->fd
);
178 static const struct pipe_loader_ops pipe_loader_drm_ops
= {
179 .create_screen
= pipe_loader_drm_create_screen
,
180 .configuration
= pipe_loader_drm_configuration
,
181 .release
= pipe_loader_drm_release