diff options
-rw-r--r-- | .gitlab-ci.yml | 1 | ||||
-rw-r--r-- | common/Makefile.am | 3 | ||||
-rw-r--r-- | common/meson.build | 2 | ||||
-rw-r--r-- | common/udev.c | 78 | ||||
-rw-r--r-- | common/udev.h | 33 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | m4/spice-deps.m4 | 12 | ||||
-rw-r--r-- | meson.build | 7 |
8 files changed, 137 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cfa6e72..4e4de75 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,4 +48,5 @@ make-win: LDFLAGS='-fsanitize=address -lasan' mingw64-configure --enable-extra-checks - make + - export LANG=en_US.UTF-8 - make LOG_COMPILER=wine check || (cat tests/test-suite.log && exit 1) diff --git a/common/Makefile.am b/common/Makefile.am index 1318400..4f75428 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -52,6 +52,8 @@ libspice_common_la_SOURCES = \ rop3.h \ snd_codec.c \ snd_codec.h \ + udev.c \ + udev.h \ utils.c \ utils.h \ verify.h \ @@ -108,6 +110,7 @@ AM_CPPFLAGS = \ libspice_common_la_LIBADD = \ $(SPICE_COMMON_LIBS) \ + $(UDEV_LIBS) \ $(NULL) MARSHALLERS_DEPS = \ diff --git a/common/meson.build b/common/meson.build index 09e3ea7..63bd2db 100644 --- a/common/meson.build +++ b/common/meson.build @@ -39,6 +39,8 @@ spice_common_sources = [ 'snd_codec.h', 'utils.c', 'utils.h', + 'udev.c', + 'udev.h', 'verify.h', 'recorder.h' ] diff --git a/common/udev.c b/common/udev.c new file mode 100644 index 0000000..800a4ab --- /dev/null +++ b/common/udev.c @@ -0,0 +1,78 @@ +/* + Copyright (C) 2023 Intel Corporation. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> +#include "udev.h" + +#ifdef HAVE_UDEV +#include <libudev.h> +#include <stdbool.h> +#include <stdlib.h> + +GpuVendor spice_udev_detect_gpu(int gpu_vendor) +{ + struct udev *udev; + struct udev_device *drm_dev, *pci_dev; + struct udev_enumerate *udev_enum; + struct udev_list_entry *entry, *devices; + const char *path, *vendor_id; + GpuVendor vendor = VENDOR_GPU_NOTDETECTED; + + udev = udev_new(); + if (!udev) { + return VENDOR_GPU_UNKNOWN; + } + + udev_enum = udev_enumerate_new(udev); + if (udev_enum) { + udev_enumerate_add_match_subsystem(udev_enum, "drm"); + udev_enumerate_add_match_sysname(udev_enum, "card[0-9]"); + udev_enumerate_scan_devices(udev_enum); + devices = udev_enumerate_get_list_entry(udev_enum); + + udev_list_entry_foreach(entry, devices) { + path = udev_list_entry_get_name(entry); + drm_dev = udev_device_new_from_syspath(udev, path); + if (!drm_dev) { + continue; + } + + pci_dev = udev_device_get_parent_with_subsystem_devtype(drm_dev, + "pci", NULL); + if (pci_dev) { + vendor_id = udev_device_get_sysattr_value(pci_dev, "vendor"); + if (vendor_id && strtol(vendor_id, NULL, 16) == gpu_vendor) { + vendor = VENDOR_GPU_DETECTED; + udev_device_unref(drm_dev); + break; + } + } + udev_device_unref(drm_dev); + } + udev_enumerate_unref(udev_enum); + } + udev_unref(udev); + + return vendor; +} +#else +GpuVendor spice_udev_detect_gpu(int gpu_vendor) +{ + return VENDOR_GPU_UNKNOWN; +} +#endif + diff --git a/common/udev.h b/common/udev.h new file mode 100644 index 0000000..389bb3f --- /dev/null +++ b/common/udev.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2023 Intel Corporation. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include <spice/macros.h> + +#define INTEL_VENDOR_ID 0x8086 + +typedef enum { + VENDOR_GPU_UNKNOWN, + VENDOR_GPU_DETECTED, + VENDOR_GPU_NOTDETECTED, +} GpuVendor; + +SPICE_BEGIN_DECLS + +GpuVendor spice_udev_detect_gpu(int gpu_vendor); + +SPICE_END_DECLS diff --git a/configure.ac b/configure.ac index 0d4c22b..42e873d 100644 --- a/configure.ac +++ b/configure.ac @@ -61,6 +61,7 @@ SPICE_CHECK_GLIB2 SPICE_CHECK_OPUS SPICE_CHECK_OPENSSL SPICE_CHECK_GDK_PIXBUF +SPICE_CHECK_UDEV SPICE_COMMON_CFLAGS='$(PIXMAN_CFLAGS) $(SMARTCARD_CFLAGS) $(GLIB2_CFLAGS) $(OPUS_CFLAGS) $(OPENSSL_CFLAGS)' SPICE_COMMON_CFLAGS="$SPICE_COMMON_CFLAGS -DG_LOG_DOMAIN=\\\"Spice\\\"" diff --git a/m4/spice-deps.m4 b/m4/spice-deps.m4 index e11fc4e..6a07ee6 100644 --- a/m4/spice-deps.m4 +++ b/m4/spice-deps.m4 @@ -302,6 +302,18 @@ AC_DEFUN([SPICE_CHECK_OPENSSL], [ PKG_CHECK_MODULES(OPENSSL, openssl) ]) +# SPICE_CHECK_UDEV +# ----------------- +# Check for the availability of libudev. If found, it will help to determine +# if a given vendor GPU is available or not. +#------------------ +AC_DEFUN([SPICE_CHECK_UDEV], [ + PKG_CHECK_MODULES([UDEV], [libudev], [have_udev=yes],[have_udev=no]) + if test "x$have_udev" = "xyes"; then + AC_DEFINE([HAVE_UDEV], 1, [whether libudev is available to identify GPU]) + fi +]) + # SPICE_CHECK_INSTRUMENTATION # ----------------- # Check for the availability of an instrumentation library. diff --git a/meson.build b/meson.build index eeccecd..1018769 100644 --- a/meson.build +++ b/meson.build @@ -147,6 +147,13 @@ if smartcard_dep.found() spice_common_config_data.set('USE_SMARTCARD', '1') endif +# udev check +udev_dep = dependency('libudev', required : false) +if udev_dep.found() + spice_common_deps += udev_dep + spice_common_config_data.set('HAVE_UDEV', '1') +endif + # # global C defines # |