aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-24 15:35:54 +0100
committerSimon Ser <contact@emersion.fr>2020-01-12 12:25:16 +0100
commit29da493661c73b17a23f62e33b002ad62a530814 (patch)
tree5fc6efe6896860064392020c7c27c5935e73774e
parent5e083729ed0423e24f734bec1d9a91c77b21d31f (diff)
downloadexternal_drm_info-libpci.tar.gz
external_drm_info-libpci.tar.bz2
external_drm_info-libpci.zip
Print PCI device names with libpcilibpci
-rw-r--r--meson.build7
-rw-r--r--meson_options.txt5
-rw-r--r--pretty.c13
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'
+)
diff --git a/pretty.c b/pretty.c
index b21f4f7..5070316 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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 =