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
35 print_device_info(drmDevicePtr device, int i)
37 printf("device[%i]\n", i);
38 printf("\tavailable_nodes %04x\n", device->available_nodes);
40 for (int j = 0; j < DRM_NODE_MAX; j++)
41 if (device->available_nodes & 1 << j)
42 printf("\t\tnodes[%d] %s\n", j, device->nodes[j]);
44 printf("\tbustype %04x\n", device->bustype);
45 printf("\tbusinfo\n");
46 if (device->bustype == DRM_BUS_PCI) {
48 printf("\t\t\tdomain\t%04x\n",device->businfo.pci->domain);
49 printf("\t\t\tbus\t%02x\n", device->businfo.pci->bus);
50 printf("\t\t\tdev\t%02x\n", device->businfo.pci->dev);
51 printf("\t\t\tfunc\t%1u\n", device->businfo.pci->func);
53 printf("\tdeviceinfo\n");
55 printf("\t\t\tvendor_id\t%04x\n", device->deviceinfo.pci->vendor_id);
56 printf("\t\t\tdevice_id\t%04x\n", device->deviceinfo.pci->device_id);
57 printf("\t\t\tsubvendor_id\t%04x\n", device->deviceinfo.pci->subvendor_id);
58 printf("\t\t\tsubdevice_id\t%04x\n", device->deviceinfo.pci->subdevice_id);
59 printf("\t\t\trevision_id\t%02x\n", device->deviceinfo.pci->revision_id);
61 printf("Unknown/unhandled bustype\n");
69 drmDevicePtr *devices;
71 int fd, ret, max_devices;
73 max_devices = drmGetDevices(NULL, 0);
75 if (max_devices <= 0) {
76 printf("drmGetDevices() has returned %d\n", max_devices);
80 devices = calloc(max_devices, sizeof(drmDevicePtr));
81 if (devices == NULL) {
82 printf("Failed to allocate memory for the drmDevicePtr array\n");
86 ret = drmGetDevices(devices, max_devices);
88 printf("drmGetDevices() returned an error %d\n", ret);
93 for (int i = 0; i < ret; i++) {
94 print_device_info(devices[i], i);
96 for (int j = 0; j < DRM_NODE_MAX; j++) {
97 if (devices[i]->available_nodes & 1 << j) {
98 printf("Opening device %d node %s\n", i, devices[i]->nodes[j]);
99 fd = open(devices[i]->nodes[j], O_RDONLY | O_CLOEXEC, 0);
101 printf("Failed - %s (%d)\n", strerror(errno), errno);
105 if (drmGetDevice(fd, &device) == 0) {
106 print_device_info(device, i);
107 drmFreeDevice(&device);
114 drmFreeDevices(devices, ret);