diff options
author | Simon Ser <contact@emersion.fr> | 2019-12-24 15:35:54 +0100 |
---|---|---|
committer | Scott Anderson <scott@anderso.nz> | 2020-01-13 16:49:31 +1300 |
commit | 7cabf04ace646af036d47081d9260d1d74295cb1 (patch) | |
tree | e99a75aa5d296844612b6bf4e2d386565844c99e | |
parent | 6a0d8c85e49e4cdd103005a189f722f7678b0e20 (diff) | |
download | external_drm_info-7cabf04ace646af036d47081d9260d1d74295cb1.tar.gz external_drm_info-7cabf04ace646af036d47081d9260d1d74295cb1.tar.bz2 external_drm_info-7cabf04ace646af036d47081d9260d1d74295cb1.zip |
Print PCI device names with libpci
-rw-r--r-- | meson.build | 7 | ||||
-rw-r--r-- | meson_options.txt | 5 | ||||
-rw-r--r-- | pretty.c | 13 |
3 files changed, 24 insertions, 1 deletions
diff --git a/meson.build b/meson.build index 8279c06..086a9f2 100644 --- a/meson.build +++ b/meson.build @@ -11,6 +11,7 @@ project('drm_info', 'c', add_project_arguments('-D_POSIX_C_SOURCE=200809L', language: 'c') jsonc = dependency('json-c', version: '>=0.13', fallback: ['json-c', 'json_c']) +libpci = dependency('libpci', required: get_option('libpci')) libdrm = dependency('libdrm', fallback: ['libdrm', 'ext_libdrm'], default_options: [ @@ -62,6 +63,10 @@ else fourcc_h = files(libdrm.get_pkgconfig_variable('includedir') / 'libdrm/drm_fourcc.h') endif +if libpci.found() + add_project_arguments('-DHAVE_LIBPCI', language: 'c') +endif + python3 = import('python').find_installation() tables_c = custom_target('tables_c', @@ -71,6 +76,6 @@ tables_c = custom_target('tables_c', executable('drm_info', [files('main.c', 'json.c', 'pretty.c'), tables_c], include_directories: inc, - dependencies: [libdrm, jsonc], + dependencies: [libdrm, libpci, jsonc], install: true, ) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..ffaaf8b --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,5 @@ +option('libpci', + type: 'feature', + value: 'auto', + description: 'Print PCI device names via libpci' +) @@ -7,6 +7,10 @@ #include <xf86drm.h> #include <xf86drmMode.h> +#ifdef HAVE_LIBPCI +#include <pci/pci.h> +#endif + #include "drm_info.h" #include "tables.h" @@ -96,6 +100,15 @@ static void print_device(struct json_object *obj) uint16_t vendor = get_object_object_uint64(data_obj, "vendor"); uint16_t device = get_object_object_uint64(data_obj, "device"); printf(" %04x:%04x", vendor, device); +#ifdef HAVE_LIBPCI + struct pci_access *pci = pci_alloc(); + char name[512]; + if (pci_lookup_name(pci, name, sizeof(name), + PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, vendor, device)) { + printf(" %s", name); + } + pci_cleanup(pci); +#endif break; case DRM_BUS_PLATFORM:; struct json_object *compatible_arr = |