From: Keith Packard <keithp@keithp.com>
To: mesa-dev@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH 03/18] Don't use libudev for glx/dri3
Date: Fri, 13 Dec 2013 17:25:15 -0800 [thread overview]
Message-ID: <1386984330-26074-4-git-send-email-keithp@keithp.com> (raw)
In-Reply-To: <1386984330-26074-1-git-send-email-keithp@keithp.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=a, Size: 4934 bytes --]
libudev doesn't have a stable API/ABI, and if the application wants to use one
version, we'd best not load another into libGL.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
configure.ac | 8 -----
src/glx/dri3_common.c | 85 ++++++++++++++++++++++++++++++---------------------
2 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/configure.ac b/configure.ac
index c14d39a..1193cff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -824,9 +824,6 @@ xyesno)
PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED])
GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV libdrm >= $LIBDRM_REQUIRED"
if test x"$enable_dri3" = xyes; then
- if test x"$have_libudev" != xyes; then
- AC_MSG_ERROR([DRI3 requires libudev >= $LIBUDEV_REQUIRED])
- fi
PKG_CHECK_MODULES([DRI3PROTO], [dri3proto >= $DRI3PROTO_REQUIRED])
PKG_CHECK_MODULES([PRESENTPROTO], [presentproto >= $PRESENTPROTO_REQUIRED])
fi
@@ -850,11 +847,6 @@ xyesno)
X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS"
GL_LIB_DEPS="$DRIGL_LIBS"
- if test x"$enable_dri3$have_libudev" = xyesyes; then
- X11_INCLUDES="$X11_INCLUDES $LIBUDEV_CFLAGS"
- GL_LIB_DEPS="$GL_LIB_DEPS $LIBUDEV_LIBS"
- fi
-
# need DRM libs, $PTHREAD_LIBS, etc.
GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
GL_PC_LIB_PRIV="-lm $PTHREAD_LIBS $DLOPEN_LIBS"
diff --git a/src/glx/dri3_common.c b/src/glx/dri3_common.c
index c758f96..511fbc8 100644
--- a/src/glx/dri3_common.c
+++ b/src/glx/dri3_common.c
@@ -23,7 +23,7 @@
/*
* This code is derived from src/egl/drivers/dri2/common.c which
* carries the following copyright:
- *
+ *
* Copyright © 2011 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -67,62 +67,80 @@
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/time.h>
+#include <stdbool.h>
#include "xf86drm.h"
#include "dri_common.h"
#include "dri3_priv.h"
#define DRIVER_MAP_DRI3_ONLY
-#include "pci_ids/pci_id_driver_map.h"
-#include <libudev.h>
+#include "pci_ids/pci_id_driver_map.h"
-static struct udev_device *
-dri3_udev_device_new_from_fd(struct udev *udev, int fd)
+static dev_t
+dri3_rdev_from_fd(int fd)
{
- struct udev_device *device;
struct stat buf;
if (fstat(fd, &buf) < 0) {
ErrorMessageF("DRI3: failed to stat fd %d", fd);
- return NULL;
+ return 0;
}
+ return buf.st_rdev;
+}
- device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
- if (device == NULL) {
- ErrorMessageF("DRI3: could not create udev device for fd %d", fd);
- return NULL;
- }
+/*
+ * There are multiple udev library versions, and they aren't polite about
+ * symbols, so just avoid using it until some glorious future when the udev
+ * developers figure out how to not break things
+ */
- return device;
+#define SYS_PATH_MAX 256
+
+static bool
+dri3_read_hex(dev_t rdev, char *entry, int *value)
+{
+ char path[SYS_PATH_MAX];
+ FILE *f;
+ int r;
+
+ snprintf(path, sizeof (path), "/sys/dev/char/%u:%u/device/%s",
+ major(rdev), minor(rdev), entry);
+
+ f = fopen(path,"r");
+ if (f == NULL)
+ return false;
+
+ r = fscanf(f, "0x%x\n", value);
+ fclose(f);
+ if (r != 1)
+ return false;
+ return true;
+}
+
+static bool
+dri3_get_pci_id_from_fd(int fd, int *vendorp, int *chipp)
+{
+ dev_t rdev = dri3_rdev_from_fd(fd);
+
+ if (!rdev)
+ return false;
+
+ if (!dri3_read_hex(rdev, "vendor", vendorp))
+ return false;
+ if (!dri3_read_hex(rdev, "device", chipp))
+ return false;
+ return true;
}
char *
dri3_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 = dri3_udev_device_new_from_fd(udev, fd);
- if (device == NULL)
+ if (!dri3_get_pci_id_from_fd(fd, &vendor_id, &chip_id))
return NULL;
- parent = udev_device_get_parent(device);
- if (parent == NULL) {
- ErrorMessageF("DRI3: 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) {
- ErrorMessageF("DRI3: malformed or no PCI ID");
- goto out;
- }
-
for (i = 0; driver_map[i].driver; i++) {
if (vendor_id != driver_map[i].vendor_id)
continue;
@@ -139,8 +157,5 @@ dri3_get_driver_for_fd(int fd)
}
out:
- udev_device_unref(device);
- udev_unref(udev);
-
return driver;
}
--
1.8.4.4
[-- Attachment #2: Type: text/plain, Size: 156 bytes --]
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev
next prev parent reply other threads:[~2013-12-14 1:25 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-14 1:25 [PATCH 00/18] dri3+gallium patch series Keith Packard
2013-12-14 1:25 ` [PATCH 01/18] Remove glBlendColor and glBlendEquations decls from glext.h Keith Packard
2013-12-14 2:28 ` [Mesa-dev] " Kenneth Graunke
2013-12-14 6:56 ` Keith Packard
2013-12-20 18:24 ` Ian Romanick
2013-12-14 1:25 ` [PATCH 02/18] dri/swrast: Passing dri_context * instead of gl_context* to driContextSetFlags Keith Packard
2013-12-14 1:25 ` Keith Packard [this message]
2013-12-14 1:25 ` [PATCH 04/18] dri3: Switch to libxshmfence version 1.1 Keith Packard
2013-12-14 2:35 ` [Mesa-dev] " Kenneth Graunke
2013-12-14 7:00 ` Keith Packard
2013-12-14 1:25 ` [PATCH 05/18] dri3: Free resources when drawable is destroyed Keith Packard
2013-12-14 1:25 ` [PATCH 06/18] dri3: Clean up struct dri3_drawable Keith Packard
2013-12-14 1:25 ` [PATCH 07/18] dri3: Track full 64-bit SBC numbers, instead of just 32-bits Keith Packard
2013-12-14 1:25 ` [PATCH 08/18] dri3: Fix dri3_wait_for_sbc to wait for completion of requested SBC Keith Packard
2013-12-14 1:25 ` [PATCH 09/18] dri3: Enable GLX_INTEL_swap_event Keith Packard
2013-12-14 1:25 ` [PATCH 10/18] i965: Correct check for re-bound buffer in intel_update_image_buffer Keith Packard
2013-12-14 1:25 ` [PATCH 11/18] i965: Set fast color clear mcs_state on newly allocated image miptrees Keith Packard
2013-12-14 1:25 ` [PATCH 12/18] dri3: Rename DRI3_MAX_BACK to DRI3_NUM_BACK Keith Packard
2013-12-14 1:25 ` [PATCH 13/18] dri3: Flush XCB before blocking for special events Keith Packard
2013-12-14 1:25 ` [PATCH 14/18] dri3, i915, i965: Add __DRI_IMAGE_FOURCC_SARGB8888 Keith Packard
2013-12-14 1:25 ` [PATCH 15/18] gallium: Add __DRIimageDriverExtension support to gallium Keith Packard
2013-12-14 11:27 ` Marek Olšák
2013-12-27 20:27 ` Keith Packard
2014-01-03 20:03 ` Marek Olšák
2013-12-14 1:25 ` [PATCH 16/18] gallium/dri: fix unsetting of format when encountering depth/stencil Keith Packard
2013-12-14 1:25 ` [PATCH 17/18] nvc0: fix segfault if nv50_miptree_from_handle() fails Keith Packard
2013-12-14 1:25 ` [PATCH 18/18] gallium: Use base.stamp for all drawable invalidation checks Keith Packard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386984330-26074-4-git-send-email-keithp@keithp.com \
--to=keithp@keithp.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=mesa-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).