2 * Mesa 3-D graphics library
5 * Copyright (C) 2010-2011 LunarG Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Chia-I Wu <olv@lunarg.com>
29 #include "common/egl_g3d_loader.h"
30 #include "egldriver.h"
36 #define DRIVER_MAP_GALLIUM_ONLY
37 #include "pci_ids/pci_id_driver_map.h"
43 static struct egl_g3d_loader egl_g3d_loader
;
45 static struct st_module
{
48 } st_modules
[ST_API_COUNT
];
50 static struct st_api
*
51 get_st_api(enum st_api_type api
)
53 struct st_module
*stmod
= &st_modules
[api
];
55 if (!stmod
->initialized
) {
56 stmod
->stapi
= egl_st_create_api(api
);
57 stmod
->initialized
= TRUE
;
63 #if !defined(PIPE_OS_AROS)
65 drm_fd_get_screen_name(int fd
)
69 struct udev_device
*device
, *parent
;
72 int vendor_id
, chip_id
, idx
= -1, i
;
75 if (fstat(fd
, &buf
) < 0) {
76 _eglLog(_EGL_WARNING
, "failed to stat fd %d", fd
);
80 device
= udev_device_new_from_devnum(udev
, 'c', buf
.st_rdev
);
83 "could not create udev device for fd %d", fd
);
87 parent
= udev_device_get_parent(device
);
89 _eglLog(_EGL_WARNING
, "could not get parent device");
93 pci_id
= udev_device_get_property_value(parent
, "PCI_ID");
95 sscanf(pci_id
, "%x:%x", &vendor_id
, &chip_id
) != 2) {
96 _eglLog(_EGL_WARNING
, "malformed or no PCI ID");
100 /* find the driver index */
101 for (idx
= 0; driver_map
[idx
].driver
; idx
++) {
102 if (vendor_id
!= driver_map
[idx
].vendor_id
)
105 if (driver_map
[idx
].num_chips_ids
== -1)
108 for (i
= 0; i
< driver_map
[idx
].num_chips_ids
; i
++) {
109 if (driver_map
[idx
].chip_ids
[i
] == chip_id
)
115 udev_device_unref(device
);
119 _eglLog((driver_map
[idx
].driver
) ? _EGL_INFO
: _EGL_WARNING
,
120 "pci id for fd %d: %04x:%04x, driver %s",
121 fd
, vendor_id
, chip_id
, driver_map
[idx
].driver
);
123 return driver_map
[idx
].driver
;
127 _eglLog(_EGL_WARNING
, "failed to get driver name for fd %d", fd
);
132 static struct pipe_screen
*
133 create_drm_screen(const char *name
, int fd
)
136 name
= drm_fd_get_screen_name(fd
);
141 return egl_pipe_create_drm_screen(name
, fd
);
144 static struct pipe_screen
*
145 create_sw_screen(struct sw_winsys
*ws
)
147 return egl_pipe_create_swrast_screen(ws
);
151 static const struct egl_g3d_loader
*
156 for (i
= 0; i
< ST_API_COUNT
; i
++)
157 egl_g3d_loader
.profile_masks
[i
] = egl_st_get_profile_mask(i
);
159 egl_g3d_loader
.get_st_api
= get_st_api
;
160 #if !defined(PIPE_OS_AROS)
161 egl_g3d_loader
.create_drm_screen
= create_drm_screen
;
162 egl_g3d_loader
.create_sw_screen
= create_sw_screen
;
165 return &egl_g3d_loader
;
173 for (i
= 0; i
< ST_API_COUNT
; i
++) {
174 struct st_module
*stmod
= &st_modules
[i
];
177 egl_st_destroy_api(stmod
->stapi
);
180 stmod
->initialized
= FALSE
;
185 egl_g3d_unload(_EGLDriver
*drv
)
187 egl_g3d_destroy_driver(drv
);
192 _EGL_MAIN(const char *args
)
194 const struct egl_g3d_loader
*loader
;
197 loader
= loader_init();
198 drv
= egl_g3d_create_driver(loader
);
204 drv
->Name
= "Gallium";
205 drv
->Unload
= egl_g3d_unload
;