mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-02 13:50:09 +01:00
egl_dri2: use loader util lib
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Kristian Høgsberg <krh@bitplanet.net> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
parent
a0a1c60fb0
commit
8d4357b5ba
7 changed files with 15 additions and 259 deletions
|
|
@ -40,9 +40,7 @@ LOCAL_C_INCLUDES := \
|
|||
$(MESA_TOP)/src/mapi \
|
||||
$(MESA_TOP)/src/egl/main \
|
||||
$(MESA_TOP)/src/loader \
|
||||
$(DRM_GRALLOC_TOP) \
|
||||
$(DRM_TOP) \
|
||||
$(DRM_TOP)/include/drm
|
||||
$(DRM_GRALLOC_TOP)
|
||||
|
||||
LOCAL_MODULE := libmesa_egl_dri2
|
||||
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ AM_CFLAGS = \
|
|||
noinst_LTLIBRARIES = libegl_dri2.la
|
||||
|
||||
libegl_dri2_la_SOURCES = \
|
||||
egl_dri2.c \
|
||||
common.c
|
||||
egl_dri2.c
|
||||
|
||||
libegl_dri2_la_LIBADD = \
|
||||
$(top_builddir)/src/loader/libloader.la \
|
||||
$(EGL_LIB_DEPS)
|
||||
|
||||
if HAVE_SHARED_GLAPI
|
||||
|
|
|
|||
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2011 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Kristian Høgsberg <krh@bitplanet.net>
|
||||
* Benjamin Franzke <benjaminfranzke@googlemail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "egl_dri2.h"
|
||||
|
||||
#ifdef HAVE_LIBUDEV
|
||||
|
||||
#define DRIVER_MAP_DRI2_ONLY
|
||||
#include "pci_ids/pci_id_driver_map.h"
|
||||
|
||||
#include <libudev.h>
|
||||
|
||||
static struct udev_device *
|
||||
dri2_udev_device_new_from_fd(struct udev *udev, int fd)
|
||||
{
|
||||
struct udev_device *device;
|
||||
struct stat buf;
|
||||
|
||||
if (fstat(fd, &buf) < 0) {
|
||||
_eglLog(_EGL_WARNING, "EGL-DRI2: failed to stat fd %d", fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
|
||||
if (device == NULL) {
|
||||
_eglLog(_EGL_WARNING,
|
||||
"EGL-DRI2: could not create udev device for fd %d", fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
char *
|
||||
dri2_get_device_name_for_fd(int fd)
|
||||
{
|
||||
struct udev *udev;
|
||||
struct udev_device *device;
|
||||
const char *const_device_name;
|
||||
char *device_name = NULL;
|
||||
|
||||
udev = udev_new();
|
||||
device = dri2_udev_device_new_from_fd(udev, fd);
|
||||
if (device == NULL)
|
||||
return NULL;
|
||||
|
||||
const_device_name = udev_device_get_devnode(device);
|
||||
if (!const_device_name)
|
||||
goto out;
|
||||
device_name = strdup(const_device_name);
|
||||
|
||||
out:
|
||||
udev_device_unref(device);
|
||||
udev_unref(udev);
|
||||
|
||||
return device_name;
|
||||
}
|
||||
|
||||
char *
|
||||
dri2_get_driver_for_fd(int fd)
|
||||
{
|
||||
struct udev *udev;
|
||||
struct udev_device *device, *parent;
|
||||
const char *pci_id;
|
||||
char *driver = NULL;
|
||||
int vendor_id, chip_id, i, j;
|
||||
|
||||
udev = udev_new();
|
||||
device = dri2_udev_device_new_from_fd(udev, fd);
|
||||
if (device == NULL)
|
||||
return NULL;
|
||||
|
||||
parent = udev_device_get_parent(device);
|
||||
if (parent == NULL) {
|
||||
_eglLog(_EGL_WARNING, "DRI2: could not get parent device");
|
||||
goto out;
|
||||
}
|
||||
|
||||
pci_id = udev_device_get_property_value(parent, "PCI_ID");
|
||||
if (pci_id == NULL ||
|
||||
sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) {
|
||||
_eglLog(_EGL_WARNING, "EGL-DRI2: malformed or no PCI ID");
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; driver_map[i].driver; i++) {
|
||||
if (vendor_id != driver_map[i].vendor_id)
|
||||
continue;
|
||||
if (driver_map[i].num_chips_ids == -1) {
|
||||
driver = strdup(driver_map[i].driver);
|
||||
_eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s",
|
||||
fd, vendor_id, chip_id, driver);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (j = 0; j < driver_map[i].num_chips_ids; j++)
|
||||
if (driver_map[i].chip_ids[j] == chip_id) {
|
||||
driver = strdup(driver_map[i].driver);
|
||||
_eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s",
|
||||
fd, vendor_id, chip_id, driver);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
udev_device_unref(device);
|
||||
udev_unref(udev);
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBUDEV */
|
||||
|
|
@ -271,9 +271,4 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
|
|||
EGLBoolean
|
||||
dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
|
||||
|
||||
char *
|
||||
dri2_get_driver_for_fd(int fd);
|
||||
char *
|
||||
dri2_get_device_name_for_fd(int fd);
|
||||
|
||||
#endif /* EGL_DRI2_INCLUDED */
|
||||
|
|
|
|||
|
|
@ -34,11 +34,7 @@
|
|||
#include <sync/sync.h>
|
||||
#endif
|
||||
|
||||
/* for droid_get_pci_id */
|
||||
#include <xf86drm.h>
|
||||
#include <i915_drm.h>
|
||||
#include <radeon_drm.h>
|
||||
|
||||
#include "loader.h"
|
||||
#include "egl_dri2.h"
|
||||
#include "gralloc_drm.h"
|
||||
|
||||
|
|
@ -602,103 +598,6 @@ droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
|
|||
return (count != 0);
|
||||
}
|
||||
|
||||
static EGLBoolean
|
||||
droid_get_pci_id(int fd, int *vendor_id, int *chip_id)
|
||||
{
|
||||
drmVersionPtr version;
|
||||
|
||||
*chip_id = -1;
|
||||
|
||||
version = drmGetVersion(fd);
|
||||
if (!version) {
|
||||
_eglLog(_EGL_WARNING, "invalid drm fd");
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (!version->name) {
|
||||
_eglLog(_EGL_WARNING, "unable to determine the driver name");
|
||||
drmFreeVersion(version);
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
if (strcmp(version->name, "i915") == 0) {
|
||||
struct drm_i915_getparam gp;
|
||||
int ret;
|
||||
|
||||
*vendor_id = 0x8086;
|
||||
|
||||
memset(&gp, 0, sizeof(gp));
|
||||
gp.param = I915_PARAM_CHIPSET_ID;
|
||||
gp.value = chip_id;
|
||||
ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
|
||||
if (ret) {
|
||||
_eglLog(_EGL_WARNING, "failed to get param for i915");
|
||||
*chip_id = -1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(version->name, "radeon") == 0) {
|
||||
struct drm_radeon_info info;
|
||||
int ret;
|
||||
|
||||
*vendor_id = 0x1002;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.request = RADEON_INFO_DEVICE_ID;
|
||||
info.value = (unsigned long) chip_id;
|
||||
ret = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
|
||||
if (ret) {
|
||||
_eglLog(_EGL_WARNING, "failed to get info for radeon");
|
||||
*chip_id = -1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(version->name, "nouveau") == 0) {
|
||||
*vendor_id = 0x10de;
|
||||
/* not used */
|
||||
*chip_id = 0;
|
||||
}
|
||||
else if (strcmp(version->name, "vmwgfx") == 0) {
|
||||
*vendor_id = 0x15ad;
|
||||
/* assume SVGA II */
|
||||
*chip_id = 0x0405;
|
||||
}
|
||||
|
||||
drmFreeVersion(version);
|
||||
|
||||
return (*chip_id >= 0);
|
||||
}
|
||||
|
||||
#define DRIVER_MAP_DRI2_ONLY
|
||||
#include "pci_ids/pci_id_driver_map.h"
|
||||
static const char *
|
||||
droid_get_driver_name(int fd)
|
||||
{
|
||||
int vendor_id = -1, chip_id = -1;
|
||||
int idx, i;
|
||||
char *name;
|
||||
|
||||
if (!droid_get_pci_id(fd, &vendor_id, &chip_id))
|
||||
return NULL;
|
||||
|
||||
for (idx = 0; driver_map[idx].driver; idx++) {
|
||||
if (vendor_id != driver_map[idx].vendor_id)
|
||||
continue;
|
||||
|
||||
if (driver_map[idx].num_chips_ids == -1)
|
||||
break;
|
||||
|
||||
for (i = 0; i < driver_map[idx].num_chips_ids; i++) {
|
||||
if (driver_map[idx].chip_ids[i] == chip_id)
|
||||
break;
|
||||
}
|
||||
if (i < driver_map[idx].num_chips_ids)
|
||||
break;
|
||||
}
|
||||
|
||||
_eglLog(_EGL_INFO, "pci id for fd %d: %04x:%04x, driver %s",
|
||||
fd, vendor_id, chip_id, driver_map[idx].driver);
|
||||
|
||||
return driver_map[idx].driver;
|
||||
}
|
||||
|
||||
static int
|
||||
droid_open_device(void)
|
||||
{
|
||||
|
|
@ -761,6 +660,8 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
|
|||
|
||||
_eglSetLogProc(droid_log);
|
||||
|
||||
loader_set_logger(_eglLog);
|
||||
|
||||
dri2_dpy = calloc(1, sizeof(*dri2_dpy));
|
||||
if (!dri2_dpy)
|
||||
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
|
||||
|
|
@ -773,7 +674,7 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
|
|||
goto cleanup_display;
|
||||
}
|
||||
|
||||
dri2_dpy->driver_name = (char *) droid_get_driver_name(dri2_dpy->fd);
|
||||
dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);
|
||||
if (dri2_dpy->driver_name == NULL) {
|
||||
err = "DRI2: failed to get driver name";
|
||||
goto cleanup_device;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "egl_dri2.h"
|
||||
#include "loader.h"
|
||||
|
||||
static struct gbm_bo *
|
||||
lock_front_buffer(struct gbm_surface *_surf)
|
||||
|
|
@ -447,6 +448,8 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
|
|||
int fd = -1;
|
||||
int i;
|
||||
|
||||
loader_set_logger(_eglLog);
|
||||
|
||||
dri2_dpy = calloc(1, sizeof *dri2_dpy);
|
||||
if (!dri2_dpy)
|
||||
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
|
||||
|
|
@ -482,7 +485,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
|
|||
}
|
||||
|
||||
dri2_dpy->fd = fd;
|
||||
dri2_dpy->device_name = dri2_get_device_name_for_fd(dri2_dpy->fd);
|
||||
dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd);
|
||||
dri2_dpy->driver_name = dri2_dpy->gbm_dri->base.driver_name;
|
||||
|
||||
dri2_dpy->dri_screen = dri2_dpy->gbm_dri->screen;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include <xf86drm.h>
|
||||
|
||||
#include "egl_dri2.h"
|
||||
#include "loader.h"
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include "wayland-drm-client-protocol.h"
|
||||
|
|
@ -962,6 +963,8 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
|
|||
static const unsigned int rgb_masks[4] = { 0xff0000, 0xff00, 0xff, 0 };
|
||||
static const unsigned int rgb565_masks[4] = { 0xf800, 0x07e0, 0x001f, 0 };
|
||||
|
||||
loader_set_logger(_eglLog);
|
||||
|
||||
drv->API.CreateWindowSurface = dri2_create_window_surface;
|
||||
drv->API.DestroySurface = dri2_destroy_surface;
|
||||
drv->API.SwapBuffers = dri2_swap_buffers;
|
||||
|
|
@ -1006,7 +1009,7 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
|
|||
if (roundtrip(dri2_dpy) < 0 || !dri2_dpy->authenticated)
|
||||
goto cleanup_fd;
|
||||
|
||||
dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
|
||||
dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);
|
||||
if (dri2_dpy->driver_name == NULL) {
|
||||
_eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name");
|
||||
goto cleanup_fd;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue