2015-09-09 09:48:29 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Emil Velikov <emil.l.velikov@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-07-13 03:01:34 -06:00
|
|
|
#include <errno.h>
|
2015-09-09 09:48:29 -06:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-11-30 12:13:04 -07:00
|
|
|
#include <stdbool.h>
|
2016-07-13 03:01:34 -06:00
|
|
|
#include <string.h>
|
2015-09-09 11:13:01 -06:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2015-09-09 09:48:29 -06:00
|
|
|
#include <xf86drm.h>
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2016-11-30 12:13:04 -07:00
|
|
|
print_device_info(drmDevicePtr device, int i, bool print_revision)
|
2015-09-09 09:48:29 -06:00
|
|
|
{
|
|
|
|
printf("device[%i]\n", i);
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("+-> available_nodes %#04x\n", device->available_nodes);
|
|
|
|
printf("+-> nodes\n");
|
2015-09-09 09:48:29 -06:00
|
|
|
for (int j = 0; j < DRM_NODE_MAX; j++)
|
|
|
|
if (device->available_nodes & 1 << j)
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("| +-> nodes[%d] %s\n", j, device->nodes[j]);
|
2015-09-09 09:48:29 -06:00
|
|
|
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("+-> bustype %04x\n", device->bustype);
|
2015-09-09 09:48:29 -06:00
|
|
|
if (device->bustype == DRM_BUS_PCI) {
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("| +-> pci\n");
|
|
|
|
printf("| +-> domain %04x\n",device->businfo.pci->domain);
|
|
|
|
printf("| +-> bus %02x\n", device->businfo.pci->bus);
|
|
|
|
printf("| +-> dev %02x\n", device->businfo.pci->dev);
|
|
|
|
printf("| +-> func %1u\n", device->businfo.pci->func);
|
|
|
|
|
|
|
|
printf("+-> deviceinfo\n");
|
|
|
|
printf(" +-> pci\n");
|
|
|
|
printf(" +-> vendor_id %04x\n", device->deviceinfo.pci->vendor_id);
|
|
|
|
printf(" +-> device_id %04x\n", device->deviceinfo.pci->device_id);
|
|
|
|
printf(" +-> subvendor_id %04x\n", device->deviceinfo.pci->subvendor_id);
|
|
|
|
printf(" +-> subdevice_id %04x\n", device->deviceinfo.pci->subdevice_id);
|
2016-11-30 12:13:04 -07:00
|
|
|
if (print_revision)
|
2018-06-25 11:29:35 -06:00
|
|
|
printf(" +-> revision_id %02x\n", device->deviceinfo.pci->revision_id);
|
2016-11-30 12:13:04 -07:00
|
|
|
else
|
2018-06-25 11:29:35 -06:00
|
|
|
printf(" +-> revision_id IGNORED\n");
|
2016-11-30 12:13:04 -07:00
|
|
|
|
2017-01-12 14:07:28 -07:00
|
|
|
} else if (device->bustype == DRM_BUS_USB) {
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("| +-> usb\n");
|
|
|
|
printf("| +-> bus %03u\n", device->businfo.usb->bus);
|
|
|
|
printf("| +-> dev %03u\n", device->businfo.usb->dev);
|
|
|
|
|
|
|
|
printf("+-> deviceinfo\n");
|
|
|
|
printf(" +-> usb\n");
|
|
|
|
printf(" +-> vendor %04x\n", device->deviceinfo.usb->vendor);
|
|
|
|
printf(" +-> product %04x\n", device->deviceinfo.usb->product);
|
2017-01-12 14:07:28 -07:00
|
|
|
} else if (device->bustype == DRM_BUS_PLATFORM) {
|
|
|
|
char **compatible = device->deviceinfo.platform->compatible;
|
|
|
|
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("| +-> platform\n");
|
|
|
|
printf("| +-> fullname\t%s\n", device->businfo.platform->fullname);
|
2017-01-12 14:07:28 -07:00
|
|
|
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("+-> deviceinfo\n");
|
|
|
|
printf(" +-> platform\n");
|
|
|
|
printf(" +-> compatible\n");
|
2017-01-12 14:07:28 -07:00
|
|
|
|
|
|
|
while (*compatible) {
|
2018-06-25 11:29:35 -06:00
|
|
|
printf(" %s\n", *compatible);
|
2017-01-12 14:07:28 -07:00
|
|
|
compatible++;
|
|
|
|
}
|
|
|
|
} else if (device->bustype == DRM_BUS_HOST1X) {
|
2018-06-25 11:31:35 -06:00
|
|
|
char **compatible = device->deviceinfo.host1x->compatible;
|
2017-01-12 14:07:28 -07:00
|
|
|
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("| +-> host1x\n");
|
|
|
|
printf("| +-> fullname\t%s\n", device->businfo.host1x->fullname);
|
2017-01-12 14:07:28 -07:00
|
|
|
|
2018-06-25 11:29:35 -06:00
|
|
|
printf("+-> deviceinfo\n");
|
2018-06-25 11:31:35 -06:00
|
|
|
printf(" +-> host1x\n");
|
2018-06-25 11:29:35 -06:00
|
|
|
printf(" +-> compatible\n");
|
2017-01-12 14:07:28 -07:00
|
|
|
|
|
|
|
while (*compatible) {
|
2018-06-25 11:29:35 -06:00
|
|
|
printf(" %s\n", *compatible);
|
2017-01-12 14:07:28 -07:00
|
|
|
compatible++;
|
|
|
|
}
|
2015-09-09 09:48:29 -06:00
|
|
|
} else {
|
|
|
|
printf("Unknown/unhandled bustype\n");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
drmDevicePtr *devices;
|
2015-09-09 11:13:01 -06:00
|
|
|
drmDevicePtr device;
|
|
|
|
int fd, ret, max_devices;
|
2015-09-09 09:48:29 -06:00
|
|
|
|
2018-06-25 11:07:49 -06:00
|
|
|
printf("--- Checking the number of DRM device available ---\n");
|
2016-11-30 12:13:04 -07:00
|
|
|
max_devices = drmGetDevices2(0, NULL, 0);
|
2015-09-09 09:48:29 -06:00
|
|
|
|
|
|
|
if (max_devices <= 0) {
|
2018-11-09 12:00:35 -07:00
|
|
|
printf("drmGetDevices2() has not found any devices (errno=%d)\n",
|
|
|
|
-max_devices);
|
|
|
|
return 77;
|
2015-09-09 09:48:29 -06:00
|
|
|
}
|
2018-06-25 11:07:49 -06:00
|
|
|
printf("--- Devices reported %d ---\n", max_devices);
|
|
|
|
|
2015-09-09 09:48:29 -06:00
|
|
|
|
|
|
|
devices = calloc(max_devices, sizeof(drmDevicePtr));
|
|
|
|
if (devices == NULL) {
|
|
|
|
printf("Failed to allocate memory for the drmDevicePtr array\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-25 11:07:49 -06:00
|
|
|
printf("--- Retrieving devices information (PCI device revision is ignored) ---\n");
|
2016-11-30 12:13:04 -07:00
|
|
|
ret = drmGetDevices2(0, devices, max_devices);
|
2015-09-09 09:48:29 -06:00
|
|
|
if (ret < 0) {
|
2016-11-30 12:13:04 -07:00
|
|
|
printf("drmGetDevices2() returned an error %d\n", ret);
|
2015-09-09 09:48:29 -06:00
|
|
|
free(devices);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:13:01 -06:00
|
|
|
for (int i = 0; i < ret; i++) {
|
2016-11-30 12:13:04 -07:00
|
|
|
print_device_info(devices[i], i, false);
|
2015-09-09 09:48:29 -06:00
|
|
|
|
2015-09-09 11:13:01 -06:00
|
|
|
for (int j = 0; j < DRM_NODE_MAX; j++) {
|
|
|
|
if (devices[i]->available_nodes & 1 << j) {
|
2018-06-25 11:07:49 -06:00
|
|
|
printf("--- Opening device node %s ---\n", devices[i]->nodes[j]);
|
2015-09-09 11:13:01 -06:00
|
|
|
fd = open(devices[i]->nodes[j], O_RDONLY | O_CLOEXEC, 0);
|
2016-07-13 03:01:34 -06:00
|
|
|
if (fd < 0) {
|
|
|
|
printf("Failed - %s (%d)\n", strerror(errno), errno);
|
2015-09-09 11:13:01 -06:00
|
|
|
continue;
|
2016-07-13 03:01:34 -06:00
|
|
|
}
|
2015-09-09 11:13:01 -06:00
|
|
|
|
2018-06-25 11:07:49 -06:00
|
|
|
printf("--- Retrieving device info, for node %s ---\n", devices[i]->nodes[j]);
|
2016-11-30 12:13:04 -07:00
|
|
|
if (drmGetDevice2(fd, DRM_DEVICE_GET_PCI_REVISION, &device) == 0) {
|
|
|
|
print_device_info(device, i, true);
|
2015-09-09 11:13:01 -06:00
|
|
|
drmFreeDevice(&device);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 09:48:29 -06:00
|
|
|
drmFreeDevices(devices, ret);
|
|
|
|
free(devices);
|
|
|
|
return 0;
|
|
|
|
}
|