[Mesa-dev] [PATCH] loader: Get driver name from udev hwdb when available
Emil Velikov
emil.l.velikov at gmail.com
Mon Jan 27 04:22:28 PST 2014
Hi Kristian,
On 20/01/14 20:42, Kristian Høgsberg wrote:
> The udev hwdb is a mechanism for applying udev properties to devices at
> hotplug time. The hwdb text files are compiled into a binary database
> that lets udev efficiently look up and apply properties to devices that
> match a given modalias.
>
> This patch exports the mesa PCI ID tables as hwdb files and extends the
> loader code to try to look up the driver name from the DRI_DRIVER udev
> property. The benefits to this approach are:
>
> - No longer PCI specific, any device udev can match with a modalias can
> be assigned a DRI driver.
>
> - Available outside mesa; writing a DRI2 compatible generic DDX with
> glamor needs to know the DRI driver name to send to the client.
>
> - Can be overridden by custom udev rules.
>
> Signed-off-by: Kristian Høgsberg <krh at bitplanet.net>
> ---
> configure.ac | 14 ++++++++++++++
> src/loader/Makefile.am | 15 +++++++++++++++
> src/loader/dump-hwdb.c | 31 +++++++++++++++++++++++++++++++
> src/loader/loader.c | 33 +++++++++++++++++++++++++--------
> src/loader/loader.h | 2 +-
> 5 files changed, 86 insertions(+), 9 deletions(-)
> create mode 100644 src/loader/dump-hwdb.c
>
> diff --git a/configure.ac b/configure.ac
> index d9e1896..8670908 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -771,6 +771,20 @@ if test "x$have_libdrm" = xyes; then
> DEFINES="$DEFINES -DHAVE_LIBDRM"
> fi
>
> +# This /lib prefix does not change with 32/64 bits it's always /lib
> +case "$prefix" in
> +/usr) default_udevhwdbdir=/lib/udev/hwdb.d ;;
> +NONE) default_udevhwdbdir=${ac_default_prefix}/lib/udev/hwdb.d ;;
> +*) default_udevhwdbdir=$prefix/lib/udev/hwdb.d ;;
> +esac
> +
> +AC_ARG_WITH([udev-hwdb-dir],
> + [AS_HELP_STRING([--with-udev-hwdb-dir=DIR],
> + [directory for the udev hwdb @<:@/lib/udev/hwdb.d@:>@])],
> + [udevhwdbdir="$withval"],
> + [udevhwdbdir=$default_udevhwdbdir])
> +AC_SUBST([udevhwdbdir])
> +
> PKG_CHECK_MODULES([LIBUDEV], [libudev >= $LIBUDEV_REQUIRED],
> have_libudev=yes, have_libudev=no)
>
> diff --git a/src/loader/Makefile.am b/src/loader/Makefile.am
> index 371dd57..bf3918b 100644
> --- a/src/loader/Makefile.am
> +++ b/src/loader/Makefile.am
> @@ -44,3 +44,18 @@ libloader_la_LIBADD += \
> endif
>
> libloader_la_SOURCES = $(LOADER_C_FILES)
> +
> +
> +noinst_PROGRAMS = dump-hwdb
> +dump_hwdb_SOURCES = dump-hwdb.c
> +dump_hwdb_CPPFLAGS = -I$(top_srcdir)/include
> +
> +dist_udevhwdb_DATA = 20-dri-driver.hwdb
> +
> +# Update hwdb on installation. Do not bother if installing
> +# in DESTDIR, since this is likely for packaging purposes.
> +install-data-hook:
> + -test -n "$(DESTDIR)" || udevadm hwdb --update
> +
> +20-dri-driver.hwdb : dump-hwdb
> + $(builddir)/dump-hwdb > $@
> diff --git a/src/loader/dump-hwdb.c b/src/loader/dump-hwdb.c
> new file mode 100644
> index 0000000..d48452d
> --- /dev/null
> +++ b/src/loader/dump-hwdb.c
> @@ -0,0 +1,31 @@
> +#include <stdlib.h>
> +#include <stdio.h>
> +
> +#define DRIVER_MAP_DRI2_ONLY
Mesa does not need/make use of DRIVER_MAP* since the loader patches.
Feel free to drop the above define.
> +#define __IS_LOADER
> +
> +#include "loader.h"
> +#include "pci_ids/pci_id_driver_map.h"
> +
> +#define PROP_NAME "DRI_DRIVER"
> +
> +int main(int argc, char *argv[])
> +{
> + int i, j;
> +
> + for (i = 0; driver_map[i].driver; i++) {
> + if (driver_map[i].num_chips_ids == -1) {
> + /* Add a match for display base class (bc03) for drivers that don't
> + * export per-device IDs (nouveau) */
> + printf("pci:v%08x*bc03*\n " PROP_NAME "=%s\n\n",
> + driver_map[i].vendor_id, driver_map[i].driver);
> + continue;
> + }
> +
> + for (j = 0; j < driver_map[i].num_chips_ids; j++)
> + printf("pci:v%08xd%08x*\n " PROP_NAME "=%s\n\n",
> + driver_map[i].vendor_id,
> + driver_map[i].chip_ids[j],
> + driver_map[i].driver);
> + }
Can you please add a return 0; to silence compiler warnings.
Thanks
-Emil
More information about the mesa-dev
mailing list