egl_dri2: Use external driver pci list
[mesa.git] / src / egl / drivers / dri2 / platform_drm.c
1 /*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Kristian Høgsberg <krh@bitplanet.net>
26 */
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <xf86drm.h>
32
33 #include "egl_dri2.h"
34
35 static int
36 dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id)
37 {
38 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
39
40 return drmAuthMagic(dri2_dpy->fd, id);
41 }
42
43 EGLBoolean
44 dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
45 {
46 struct dri2_egl_display *dri2_dpy;
47 int i;
48
49 dri2_dpy = malloc(sizeof *dri2_dpy);
50 if (!dri2_dpy)
51 return _eglError(EGL_BAD_ALLOC, "eglInitialize");
52
53 memset(dri2_dpy, 0, sizeof *dri2_dpy);
54
55 disp->DriverData = (void *) dri2_dpy;
56 dri2_dpy->fd = (int) (intptr_t) disp->PlatformDisplay;
57
58 dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
59 if (dri2_dpy->driver_name == NULL)
60 return _eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name");
61
62 dri2_dpy->device_name = dri2_get_device_name_for_fd(dri2_dpy->fd);
63 if (dri2_dpy->device_name == NULL) {
64 _eglError(EGL_BAD_ALLOC, "DRI2: failed to get device name");
65 goto cleanup_driver_name;
66 }
67
68 if (!dri2_load_driver(disp))
69 goto cleanup_device_name;
70
71 dri2_dpy->extensions[0] = &image_lookup_extension.base;
72 dri2_dpy->extensions[1] = &use_invalidate.base;
73 dri2_dpy->extensions[2] = NULL;
74
75 if (!dri2_create_screen(disp))
76 goto cleanup_driver;
77
78 for (i = 0; dri2_dpy->driver_configs[i]; i++)
79 dri2_add_config(disp, dri2_dpy->driver_configs[i], i + 1, 0, 0, NULL);
80
81 #ifdef HAVE_WAYLAND_PLATFORM
82 disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
83 #endif
84 dri2_dpy->authenticate = dri2_drm_authenticate;
85
86 /* we're supporting EGL 1.4 */
87 disp->VersionMajor = 1;
88 disp->VersionMinor = 4;
89
90 return EGL_TRUE;
91
92 cleanup_driver:
93 dlclose(dri2_dpy->driver);
94 cleanup_device_name:
95 free(dri2_dpy->device_name);
96 cleanup_driver_name:
97 free(dri2_dpy->driver_name);
98
99 return EGL_FALSE;
100 }