2 * Copyright (c) 2015 Emil Velikov <emil.l.velikov@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 print_device_info(drmDevicePtr device, int i)
35 printf("device[%i]\n", i);
36 printf("\tavailable_nodes %04x\n", device->available_nodes);
38 for (int j = 0; j < DRM_NODE_MAX; j++)
39 if (device->available_nodes & 1 << j)
40 printf("\t\tnodes[%d] %s\n", j, device->nodes[j]);
42 printf("\tbustype %04x\n", device->bustype);
43 printf("\tbusinfo\n");
44 if (device->bustype == DRM_BUS_PCI) {
46 printf("\t\t\tdomain\t%04x\n",device->businfo.pci->domain);
47 printf("\t\t\tbu\t%02x\n", device->businfo.pci->bus);
48 printf("\t\t\tde\t%02x\n", device->businfo.pci->dev);
49 printf("\t\t\tfunc\t%1u\n", device->businfo.pci->func);
51 printf("\tdeviceinfo\n");
53 printf("\t\t\tvendor_id\t%04x\n", device->deviceinfo.pci->vendor_id);
54 printf("\t\t\tdevice_id\t%04x\n", device->deviceinfo.pci->device_id);
55 printf("\t\t\tsubvendor_id\t%04x\n", device->deviceinfo.pci->subvendor_id);
56 printf("\t\t\tsubdevice_id\t%04x\n", device->deviceinfo.pci->subdevice_id);
57 printf("\t\t\trevision_id\t%02x\n", device->deviceinfo.pci->revision_id);
59 printf("Unknown/unhandled bustype\n");
67 drmDevicePtr *devices;
69 int fd, ret, max_devices;
71 max_devices = drmGetDevices(NULL, 0);
73 if (max_devices <= 0) {
74 printf("drmGetDevices() has returned %d\n", max_devices);
78 devices = calloc(max_devices, sizeof(drmDevicePtr));
79 if (devices == NULL) {
80 printf("Failed to allocate memory for the drmDevicePtr array\n");
84 ret = drmGetDevices(devices, max_devices);
86 printf("drmGetDevices() returned an error %d\n", ret);
91 for (int i = 0; i < ret; i++) {
92 print_device_info(devices[i], i);
94 for (int j = 0; j < DRM_NODE_MAX; j++) {
95 if (devices[i]->available_nodes & 1 << j) {
96 fd = open(devices[i]->nodes[j], O_RDONLY | O_CLOEXEC, 0);
100 if (drmGetDevice(fd, &device) == 0) {
101 print_device_info(device, -1);
102 drmFreeDevice(&device);
109 drmFreeDevices(devices, ret);