* [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo()
@ 2016-12-02 16:32 Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision Emil Velikov
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Emil Velikov @ 2016-12-02 16:32 UTC (permalink / raw)
To: dri-devel; +Cc: emil.l.velikov
From: Emil Velikov <emil.velikov@collabora.com>
Be consistent with drmParsePciBusInfo() and use solely the device
major/minor pair.
Cc: Jonathan Gray <jsg@jsg.id.au>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
---
Jonathan, please respin your patches on top of this series.
---
xf86drm.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index ed924a7..c788c93 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2946,7 +2946,7 @@ static int drmGetMaxNodeName(void)
3 /* length of the node number */;
}
-static int drmParsePciDeviceInfo(const char *d_name,
+static int drmParsePciDeviceInfo(int maj, int min,
drmPciDeviceInfoPtr device)
{
#ifdef __linux__
@@ -2954,7 +2954,7 @@ static int drmParsePciDeviceInfo(const char *d_name,
unsigned char config[64];
int fd, ret;
- snprintf(path, PATH_MAX, "/sys/class/drm/%s/device/config", d_name);
+ snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/config", maj, min);
fd = open(path, O_RDONLY);
if (fd < 0)
return -errno;
@@ -2998,7 +2998,7 @@ void drmFreeDevices(drmDevicePtr devices[], int count)
drmFreeDevice(&devices[i]);
}
-static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
+static int drmProcessPciDevice(drmDevicePtr *device,
const char *node, int node_type,
int maj, int min, bool fetch_deviceinfo)
{
@@ -3039,7 +3039,7 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
addr += sizeof(drmPciBusInfo);
(*device)->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
- ret = drmParsePciDeviceInfo(d_name, (*device)->deviceinfo.pci);
+ ret = drmParsePciDeviceInfo(maj, min, (*device)->deviceinfo.pci);
if (ret)
goto free_device;
}
@@ -3142,8 +3142,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
switch (subsystem_type) {
case DRM_BUS_PCI:
- ret = drmProcessPciDevice(&d, dent->d_name, node, node_type,
- maj, min, true);
+ ret = drmProcessPciDevice(&d, node, node_type, maj, min, true);
if (ret)
goto free_devices;
@@ -3251,7 +3250,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
switch (subsystem_type) {
case DRM_BUS_PCI:
- ret = drmProcessPciDevice(&device, dent->d_name, node, node_type,
+ ret = drmProcessPciDevice(&device, node, node_type,
maj, min, devices != NULL);
if (ret)
goto free_devices;
--
2.10.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision
2016-12-02 16:32 [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo() Emil Velikov
@ 2016-12-02 16:32 ` Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 3/5] xf86drm: parse the separate sysfs files for vendor... info Emil Velikov
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Emil Velikov @ 2016-12-02 16:32 UTC (permalink / raw)
To: dri-devel; +Cc: Mauro Santos, Michel Dänzer, emil.l.velikov
From: Emil Velikov <emil.velikov@collabora.com>
Will be used with the drmGetDevice[s]2 API.
Cc: Michel Dänzer <michel@daenzer.net>
Cc: Nicolai Hähnle <nhaehnle@gmail.com>
Cc: Mauro Santos <registo.mailling@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98502
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
---
xf86drm.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index c788c93..ddb8f9f 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2947,7 +2947,8 @@ static int drmGetMaxNodeName(void)
}
static int drmParsePciDeviceInfo(int maj, int min,
- drmPciDeviceInfoPtr device)
+ drmPciDeviceInfoPtr device,
+ uint32_t flags)
{
#ifdef __linux__
char path[PATH_MAX + 1];
@@ -3000,7 +3001,8 @@ void drmFreeDevices(drmDevicePtr devices[], int count)
static int drmProcessPciDevice(drmDevicePtr *device,
const char *node, int node_type,
- int maj, int min, bool fetch_deviceinfo)
+ int maj, int min, bool fetch_deviceinfo,
+ uint32_t flags)
{
const int max_node_str = ALIGN(drmGetMaxNodeName(), sizeof(void *));
int ret, i;
@@ -3039,7 +3041,7 @@ static int drmProcessPciDevice(drmDevicePtr *device,
addr += sizeof(drmPciBusInfo);
(*device)->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
- ret = drmParsePciDeviceInfo(maj, min, (*device)->deviceinfo.pci);
+ ret = drmParsePciDeviceInfo(maj, min, (*device)->deviceinfo.pci, flags);
if (ret)
goto free_device;
}
@@ -3095,6 +3097,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
int ret, i, node_count;
int max_count = 16;
dev_t find_rdev;
+ uint32_t flags = 0;
if (fd == -1 || device == NULL)
return -EINVAL;
@@ -3142,7 +3145,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
switch (subsystem_type) {
case DRM_BUS_PCI:
- ret = drmProcessPciDevice(&d, node, node_type, maj, min, true);
+ ret = drmProcessPciDevice(&d, node, node_type, maj, min, true, flags);
if (ret)
goto free_devices;
@@ -3216,6 +3219,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
int maj, min;
int ret, i, node_count, device_count;
int max_count = 16;
+ uint32_t flags = 0;
local_devices = calloc(max_count, sizeof(drmDevicePtr));
if (local_devices == NULL)
@@ -3251,7 +3255,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
switch (subsystem_type) {
case DRM_BUS_PCI:
ret = drmProcessPciDevice(&device, node, node_type,
- maj, min, devices != NULL);
+ maj, min, devices != NULL, flags);
if (ret)
goto free_devices;
--
2.10.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH libdrm 3/5] xf86drm: parse the separate sysfs files for vendor... info
2016-12-02 16:32 [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo() Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision Emil Velikov
@ 2016-12-02 16:32 ` Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 4/5] xf86drm: introduce drmGetDevice[s]2 Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 5/5] tests/drmdevice: use drmGetDevice[s]2 Emil Velikov
3 siblings, 0 replies; 7+ messages in thread
From: Emil Velikov @ 2016-12-02 16:32 UTC (permalink / raw)
To: dri-devel; +Cc: Mauro Santos, Michel Dänzer, emil.l.velikov
From: Emil Velikov <emil.velikov@collabora.com>
Up-to recently (patch should land in 4.10) the kernel did not expose the
PCI device revision field as a separate sysfs file.
Thus one needed too parse the config file to retrieve it. This in
itself wakes up the device, which in some cases can be quite slow.
To avoid that, just check for the separate files and fall-back to the
original if kernel is not new enough.
v3: rework alongside drmGetDevice[s]2
Cc: Michel Dänzer <michel@daenzer.net>
Cc: Nicolai Hähnle <nhaehnle@gmail.com>
Cc: Mauro Santos <registo.mailling@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98502
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
---
xf86drm.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index ddb8f9f..701cf29 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2946,11 +2946,49 @@ static int drmGetMaxNodeName(void)
3 /* length of the node number */;
}
-static int drmParsePciDeviceInfo(int maj, int min,
- drmPciDeviceInfoPtr device,
- uint32_t flags)
-{
#ifdef __linux__
+static int parse_separate_sysfs_files(int maj, int min,
+ drmPciDeviceInfoPtr device)
+{
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+ static const char *attrs[] = {
+ "revision", /* Older kernels are missing the file, so check for it first */
+ "vendor",
+ "device",
+ "subsystem_vendor",
+ "subsystem_device",
+ };
+ char path[PATH_MAX + 1];
+ unsigned int data[ARRAY_SIZE(attrs)];
+ FILE *fp;
+ int ret;
+
+ for (unsigned i = 0; i < ARRAY_SIZE(attrs); i++) {
+ snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/%s", maj, min,
+ attrs[i]);
+ fp = fopen(path, "r");
+ if (!fp)
+ return -errno;
+
+ ret = fscanf(fp, "%x", &data[i]);
+ fclose(fp);
+ if (ret != 1)
+ return -errno;
+
+ }
+
+ device->revision_id = data[0] & 0xff;
+ device->vendor_id = data[1] & 0xffff;
+ device->device_id = data[2] & 0xffff;
+ device->subvendor_id = data[3] & 0xffff;
+ device->subdevice_id = data[4] & 0xffff;
+
+ return 0;
+}
+
+static int parse_config_sysfs_file(int maj, int min,
+ drmPciDeviceInfoPtr device)
+{
char path[PATH_MAX + 1];
unsigned char config[64];
int fd, ret;
@@ -2972,6 +3010,18 @@ static int drmParsePciDeviceInfo(int maj, int min,
device->subdevice_id = config[46] | (config[47] << 8);
return 0;
+}
+#endif
+
+static int drmParsePciDeviceInfo(int maj, int min,
+ drmPciDeviceInfoPtr device,
+ uint32_t flags)
+{
+#ifdef __linux__
+ if (parse_separate_sysfs_files(maj, min, device))
+ return parse_config_sysfs_file(maj, min, device);
+
+ return 0;
#else
#warning "Missing implementation of drmParsePciDeviceInfo"
return -EINVAL;
--
2.10.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH libdrm 4/5] xf86drm: introduce drmGetDevice[s]2
2016-12-02 16:32 [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo() Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 3/5] xf86drm: parse the separate sysfs files for vendor... info Emil Velikov
@ 2016-12-02 16:32 ` Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 5/5] tests/drmdevice: use drmGetDevice[s]2 Emil Velikov
3 siblings, 0 replies; 7+ messages in thread
From: Emil Velikov @ 2016-12-02 16:32 UTC (permalink / raw)
To: dri-devel; +Cc: Mauro Santos, Michel Dänzer, emil.l.velikov
From: Emil Velikov <emil.velikov@collabora.com>
Relative to the original version, here one can provide a flags bitmask.
Currently only DRM_DEVICE_IGNORE_PCI_REVISION is supported.
Implementation detail:
If it's set, we will only parse the separate sysfs files and we won't
touch the config one. The latter awakes the device (causing delays)
which is the core reason why this API was introduced.
v2:
- Initialize revision to 0xff if it's unread.
- Change DRM_DEVICE_IGNORE_PCI_REVISION to DRM_DEVICE_GET_PCI_REVISION
- Add explicit note that drmGetDevice[s]2 does not retrieve the
revision by default.
Cc: Michel Dänzer <michel@daenzer.net>
Cc: Nicolai Hähnle <nhaehnle@gmail.com>
Cc: Mauro Santos <registo.mailling@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98502
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
---
xf86drm.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
xf86drm.h | 4 ++++
2 files changed, 66 insertions(+), 8 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index 701cf29..52e9b9f 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2948,7 +2948,8 @@ static int drmGetMaxNodeName(void)
#ifdef __linux__
static int parse_separate_sysfs_files(int maj, int min,
- drmPciDeviceInfoPtr device)
+ drmPciDeviceInfoPtr device,
+ bool ignore_revision)
{
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
static const char *attrs[] = {
@@ -2963,7 +2964,7 @@ static int parse_separate_sysfs_files(int maj, int min,
FILE *fp;
int ret;
- for (unsigned i = 0; i < ARRAY_SIZE(attrs); i++) {
+ for (unsigned i = ignore_revision ? 1 : 0; i < ARRAY_SIZE(attrs); i++) {
snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/%s", maj, min,
attrs[i]);
fp = fopen(path, "r");
@@ -2977,7 +2978,7 @@ static int parse_separate_sysfs_files(int maj, int min,
}
- device->revision_id = data[0] & 0xff;
+ device->revision_id = ignore_revision ? 0xff : data[0] & 0xff;
device->vendor_id = data[1] & 0xffff;
device->device_id = data[2] & 0xffff;
device->subvendor_id = data[3] & 0xffff;
@@ -3018,7 +3019,10 @@ static int drmParsePciDeviceInfo(int maj, int min,
uint32_t flags)
{
#ifdef __linux__
- if (parse_separate_sysfs_files(maj, min, device))
+ if (flags & DRM_DEVICE_GET_PCI_REVISION == 0)
+ return parse_separate_sysfs_files(maj, min, device, true);
+
+ if (parse_separate_sysfs_files(maj, min, device, false))
return parse_config_sysfs_file(maj, min, device);
return 0;
@@ -3125,16 +3129,27 @@ static void drmFoldDuplicatedDevices(drmDevicePtr local_devices[], int count)
}
}
+/* Check that the given flags are valid returning 0 on success */
+static int
+drm_device_validate_flags(uint32_t flags)
+{
+ return (flags & ~DRM_DEVICE_GET_PCI_REVISION);
+}
+
/**
* Get information about the opened drm device
*
* \param fd file descriptor of the drm device
+ * \param flags feature/behaviour bitmask
* \param device the address of a drmDevicePtr where the information
* will be allocated in stored
*
* \return zero on success, negative error code otherwise.
+ *
+ * \note Unlike drmGetDevice it does not retrieve the pci device revision field
+ * unless the DRM_DEVICE_GET_PCI_REVISION \p flag is set.
*/
-int drmGetDevice(int fd, drmDevicePtr *device)
+int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
{
drmDevicePtr *local_devices;
drmDevicePtr d;
@@ -3147,7 +3162,9 @@ int drmGetDevice(int fd, drmDevicePtr *device)
int ret, i, node_count;
int max_count = 16;
dev_t find_rdev;
- uint32_t flags = 0;
+
+ if (drm_device_validate_flags(flags))
+ return -EINVAL;
if (fd == -1 || device == NULL)
return -EINVAL;
@@ -3246,8 +3263,23 @@ free_locals:
}
/**
+ * Get information about the opened drm device
+ *
+ * \param fd file descriptor of the drm device
+ * \param device the address of a drmDevicePtr where the information
+ * will be allocated in stored
+ *
+ * \return zero on success, negative error code otherwise.
+ */
+int drmGetDevice(int fd, drmDevicePtr *device)
+{
+ return drmGetDevice2(fd, DRM_DEVICE_GET_PCI_REVISION, device);
+}
+
+/**
* Get drm devices on the system
*
+ * \param flags feature/behaviour bitmask
* \param devices the array of devices with drmDevicePtr elements
* can be NULL to get the device number first
* \param max_devices the maximum number of devices for the array
@@ -3256,8 +3288,11 @@ free_locals:
* if devices is NULL - total number of devices available on the system,
* alternatively the number of devices stored in devices[], which is
* capped by the max_devices.
+ *
+ * \note Unlike drmGetDevices it does not retrieve the pci device revision field
+ * unless the DRM_DEVICE_GET_PCI_REVISION \p flag is set.
*/
-int drmGetDevices(drmDevicePtr devices[], int max_devices)
+int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
{
drmDevicePtr *local_devices;
drmDevicePtr device;
@@ -3269,7 +3304,9 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
int maj, min;
int ret, i, node_count, device_count;
int max_count = 16;
- uint32_t flags = 0;
+
+ if (drm_device_validate_flags(flags))
+ return -EINVAL;
local_devices = calloc(max_count, sizeof(drmDevicePtr));
if (local_devices == NULL)
@@ -3357,6 +3394,23 @@ free_locals:
return ret;
}
+/**
+ * Get drm devices on the system
+ *
+ * \param devices the array of devices with drmDevicePtr elements
+ * can be NULL to get the device number first
+ * \param max_devices the maximum number of devices for the array
+ *
+ * \return on error - negative error code,
+ * if devices is NULL - total number of devices available on the system,
+ * alternatively the number of devices stored in devices[], which is
+ * capped by the max_devices.
+ */
+int drmGetDevices(drmDevicePtr devices[], int max_devices)
+{
+ return drmGetDevices2(DRM_DEVICE_GET_PCI_REVISION, devices, max_devices);
+}
+
char *drmGetDeviceNameFromFd2(int fd)
{
#ifdef __linux__
diff --git a/xf86drm.h b/xf86drm.h
index 4da6bd3..b340fc4 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -801,6 +801,10 @@ extern void drmFreeDevice(drmDevicePtr *device);
extern int drmGetDevices(drmDevicePtr devices[], int max_devices);
extern void drmFreeDevices(drmDevicePtr devices[], int count);
+#define DRM_DEVICE_GET_PCI_REVISION (1 << 0)
+extern int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device);
+extern int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices);
+
#if defined(__cplusplus)
}
#endif
--
2.10.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH libdrm 5/5] tests/drmdevice: use drmGetDevice[s]2
2016-12-02 16:32 [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo() Emil Velikov
` (2 preceding siblings ...)
2016-12-02 16:32 ` [PATCH libdrm 4/5] xf86drm: introduce drmGetDevice[s]2 Emil Velikov
@ 2016-12-02 16:32 ` Emil Velikov
2016-12-05 9:39 ` Michel Dänzer
3 siblings, 1 reply; 7+ messages in thread
From: Emil Velikov @ 2016-12-02 16:32 UTC (permalink / raw)
To: dri-devel; +Cc: emil.l.velikov
From: Emil Velikov <emil.velikov@collabora.com>
Pass along DRM_DEVICE_GET_PCI_REVISION only when the individual nodes
are opened and update the printed messages accordingly.
v2: Attribute for the flag rename, call drmGetDevices2 w/o the flag.
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
---
tests/drmdevice.c | 23 ++++++++++++++---------
xf86drm.c | 2 +-
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/tests/drmdevice.c b/tests/drmdevice.c
index 72e7066..8c4f091 100644
--- a/tests/drmdevice.c
+++ b/tests/drmdevice.c
@@ -24,6 +24,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -32,7 +33,7 @@
static void
-print_device_info(drmDevicePtr device, int i)
+print_device_info(drmDevicePtr device, int i, bool print_revision)
{
printf("device[%i]\n", i);
printf("\tavailable_nodes %04x\n", device->available_nodes);
@@ -56,7 +57,11 @@ print_device_info(drmDevicePtr device, int i)
printf("\t\t\tdevice_id\t%04x\n", device->deviceinfo.pci->device_id);
printf("\t\t\tsubvendor_id\t%04x\n", device->deviceinfo.pci->subvendor_id);
printf("\t\t\tsubdevice_id\t%04x\n", device->deviceinfo.pci->subdevice_id);
- printf("\t\t\trevision_id\t%02x\n", device->deviceinfo.pci->revision_id);
+ if (print_revision)
+ printf("\t\t\trevision_id\t%02x\n", device->deviceinfo.pci->revision_id);
+ else
+ printf("\t\t\trevision_id\tIGNORED\n");
+
} else {
printf("Unknown/unhandled bustype\n");
}
@@ -70,10 +75,10 @@ main(void)
drmDevicePtr device;
int fd, ret, max_devices;
- max_devices = drmGetDevices(NULL, 0);
+ max_devices = drmGetDevices2(0, NULL, 0);
if (max_devices <= 0) {
- printf("drmGetDevices() has returned %d\n", max_devices);
+ printf("drmGetDevices2() has returned %d\n", max_devices);
return -1;
}
@@ -83,15 +88,15 @@ main(void)
return -1;
}
- ret = drmGetDevices(devices, max_devices);
+ ret = drmGetDevices2(0, devices, max_devices);
if (ret < 0) {
- printf("drmGetDevices() returned an error %d\n", ret);
+ printf("drmGetDevices2() returned an error %d\n", ret);
free(devices);
return -1;
}
for (int i = 0; i < ret; i++) {
- print_device_info(devices[i], i);
+ print_device_info(devices[i], i, false);
for (int j = 0; j < DRM_NODE_MAX; j++) {
if (devices[i]->available_nodes & 1 << j) {
@@ -102,8 +107,8 @@ main(void)
continue;
}
- if (drmGetDevice(fd, &device) == 0) {
- print_device_info(device, i);
+ if (drmGetDevice2(fd, DRM_DEVICE_GET_PCI_REVISION, &device) == 0) {
+ print_device_info(device, i, true);
drmFreeDevice(&device);
}
close(fd);
diff --git a/xf86drm.c b/xf86drm.c
index 52e9b9f..a886768 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3019,7 +3019,7 @@ static int drmParsePciDeviceInfo(int maj, int min,
uint32_t flags)
{
#ifdef __linux__
- if (flags & DRM_DEVICE_GET_PCI_REVISION == 0)
+ if (!(flags & DRM_DEVICE_GET_PCI_REVISION))
return parse_separate_sysfs_files(maj, min, device, true);
if (parse_separate_sysfs_files(maj, min, device, false))
--
2.10.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH libdrm 5/5] tests/drmdevice: use drmGetDevice[s]2
2016-12-02 16:32 ` [PATCH libdrm 5/5] tests/drmdevice: use drmGetDevice[s]2 Emil Velikov
@ 2016-12-05 9:39 ` Michel Dänzer
0 siblings, 0 replies; 7+ messages in thread
From: Michel Dänzer @ 2016-12-05 9:39 UTC (permalink / raw)
To: Emil Velikov; +Cc: dri-devel
On 03/12/16 01:32 AM, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov@collabora.com>
>
> Pass along DRM_DEVICE_GET_PCI_REVISION only when the individual nodes
> are opened and update the printed messages accordingly.
>
> v2: Attribute for the flag rename, call drmGetDevices2 w/o the flag.
>
> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
[...]
> diff --git a/xf86drm.c b/xf86drm.c
> index 52e9b9f..a886768 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -3019,7 +3019,7 @@ static int drmParsePciDeviceInfo(int maj, int min,
> uint32_t flags)
> {
> #ifdef __linux__
> - if (flags & DRM_DEVICE_GET_PCI_REVISION == 0)
> + if (!(flags & DRM_DEVICE_GET_PCI_REVISION))
> return parse_separate_sysfs_files(maj, min, device, true);
>
> if (parse_separate_sysfs_files(maj, min, device, false))
>
Please squash this hunk into patch 4 before pushing.
--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo()
@ 2016-11-30 20:35 Emil Velikov
2016-11-30 20:35 ` [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision Emil Velikov
0 siblings, 1 reply; 7+ messages in thread
From: Emil Velikov @ 2016-11-30 20:35 UTC (permalink / raw)
To: dri-devel; +Cc: emil.l.velikov
From: Emil Velikov <emil.velikov@collabora.com>
Be consistent with drmParsePciBusInfo() and use solely the device
major/minor pair.
Cc: Jonathan Gray <jsg@jsg.id.au>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
---
Jonathan, please respin your patches on top of this series.
---
xf86drm.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index ed924a7..c788c93 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2946,7 +2946,7 @@ static int drmGetMaxNodeName(void)
3 /* length of the node number */;
}
-static int drmParsePciDeviceInfo(const char *d_name,
+static int drmParsePciDeviceInfo(int maj, int min,
drmPciDeviceInfoPtr device)
{
#ifdef __linux__
@@ -2954,7 +2954,7 @@ static int drmParsePciDeviceInfo(const char *d_name,
unsigned char config[64];
int fd, ret;
- snprintf(path, PATH_MAX, "/sys/class/drm/%s/device/config", d_name);
+ snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/config", maj, min);
fd = open(path, O_RDONLY);
if (fd < 0)
return -errno;
@@ -2998,7 +2998,7 @@ void drmFreeDevices(drmDevicePtr devices[], int count)
drmFreeDevice(&devices[i]);
}
-static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
+static int drmProcessPciDevice(drmDevicePtr *device,
const char *node, int node_type,
int maj, int min, bool fetch_deviceinfo)
{
@@ -3039,7 +3039,7 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
addr += sizeof(drmPciBusInfo);
(*device)->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
- ret = drmParsePciDeviceInfo(d_name, (*device)->deviceinfo.pci);
+ ret = drmParsePciDeviceInfo(maj, min, (*device)->deviceinfo.pci);
if (ret)
goto free_device;
}
@@ -3142,8 +3142,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
switch (subsystem_type) {
case DRM_BUS_PCI:
- ret = drmProcessPciDevice(&d, dent->d_name, node, node_type,
- maj, min, true);
+ ret = drmProcessPciDevice(&d, node, node_type, maj, min, true);
if (ret)
goto free_devices;
@@ -3251,7 +3250,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
switch (subsystem_type) {
case DRM_BUS_PCI:
- ret = drmProcessPciDevice(&device, dent->d_name, node, node_type,
+ ret = drmProcessPciDevice(&device, node, node_type,
maj, min, devices != NULL);
if (ret)
goto free_devices;
--
2.10.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision
2016-11-30 20:35 [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo() Emil Velikov
@ 2016-11-30 20:35 ` Emil Velikov
0 siblings, 0 replies; 7+ messages in thread
From: Emil Velikov @ 2016-11-30 20:35 UTC (permalink / raw)
To: dri-devel; +Cc: Mauro Santos, Michel Dänzer, emil.l.velikov
From: Emil Velikov <emil.velikov@collabora.com>
Will be used with the drmGetDevice[s]2 API.
Cc: Michel Dänzer <michel@daenzer.net>
Cc: Nicolai Hähnle <nhaehnle@gmail.com>
Cc: Mauro Santos <registo.mailling@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98502
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
---
xf86drm.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index c788c93..ddb8f9f 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2947,7 +2947,8 @@ static int drmGetMaxNodeName(void)
}
static int drmParsePciDeviceInfo(int maj, int min,
- drmPciDeviceInfoPtr device)
+ drmPciDeviceInfoPtr device,
+ uint32_t flags)
{
#ifdef __linux__
char path[PATH_MAX + 1];
@@ -3000,7 +3001,8 @@ void drmFreeDevices(drmDevicePtr devices[], int count)
static int drmProcessPciDevice(drmDevicePtr *device,
const char *node, int node_type,
- int maj, int min, bool fetch_deviceinfo)
+ int maj, int min, bool fetch_deviceinfo,
+ uint32_t flags)
{
const int max_node_str = ALIGN(drmGetMaxNodeName(), sizeof(void *));
int ret, i;
@@ -3039,7 +3041,7 @@ static int drmProcessPciDevice(drmDevicePtr *device,
addr += sizeof(drmPciBusInfo);
(*device)->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
- ret = drmParsePciDeviceInfo(maj, min, (*device)->deviceinfo.pci);
+ ret = drmParsePciDeviceInfo(maj, min, (*device)->deviceinfo.pci, flags);
if (ret)
goto free_device;
}
@@ -3095,6 +3097,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
int ret, i, node_count;
int max_count = 16;
dev_t find_rdev;
+ uint32_t flags = 0;
if (fd == -1 || device == NULL)
return -EINVAL;
@@ -3142,7 +3145,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
switch (subsystem_type) {
case DRM_BUS_PCI:
- ret = drmProcessPciDevice(&d, node, node_type, maj, min, true);
+ ret = drmProcessPciDevice(&d, node, node_type, maj, min, true, flags);
if (ret)
goto free_devices;
@@ -3216,6 +3219,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
int maj, min;
int ret, i, node_count, device_count;
int max_count = 16;
+ uint32_t flags = 0;
local_devices = calloc(max_count, sizeof(drmDevicePtr));
if (local_devices == NULL)
@@ -3251,7 +3255,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
switch (subsystem_type) {
case DRM_BUS_PCI:
ret = drmProcessPciDevice(&device, node, node_type,
- maj, min, devices != NULL);
+ maj, min, devices != NULL, flags);
if (ret)
goto free_devices;
--
2.10.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-12-05 9:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-02 16:32 [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo() Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 3/5] xf86drm: parse the separate sysfs files for vendor... info Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 4/5] xf86drm: introduce drmGetDevice[s]2 Emil Velikov
2016-12-02 16:32 ` [PATCH libdrm 5/5] tests/drmdevice: use drmGetDevice[s]2 Emil Velikov
2016-12-05 9:39 ` Michel Dänzer
-- strict thread matches above, loose matches on Subject: below --
2016-11-30 20:35 [PATCH libdrm 1/5] xf86drm: use maj/min in drmParsePciDeviceInfo() Emil Velikov
2016-11-30 20:35 ` [PATCH libdrm 2/5] xf86drm: add plumbing to not retrieve PCI device revision Emil Velikov
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).