From patchwork Wed Sep 9 17:21:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 7147601 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B52B7BEEC1 for ; Wed, 9 Sep 2015 17:17:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FBA820A06 for ; Wed, 9 Sep 2015 17:17:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 953C620567 for ; Wed, 9 Sep 2015 17:17:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2D7386E15A; Wed, 9 Sep 2015 10:17:24 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by gabe.freedesktop.org (Postfix) with ESMTPS id D76756E15A for ; Wed, 9 Sep 2015 10:17:22 -0700 (PDT) Received: by wiclk2 with SMTP id lk2so165399995wic.0 for ; Wed, 09 Sep 2015 10:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Nw5J6c6DEsPYJULjqGSbxA7eBIJiBlWTQG+MEVqJPWw=; b=JImF9wVQ7WL80QS9Ym886ua5mhBJIyXvHdYDMrdJFCY5m5xrXy+TVwJXAWAsdy8NGb TCFuNKjmRy33J+H6ilH6YpdNa3+JGrWUWrNeQhMFf8Qi2gDMBXRiwAD8/UqOk9949YcF /DQZCMRLB8wnaKGQpKxm1UFUEsr4uN2cDwR0M5XdJnBk4HsJ7jmrpBBslz8swl18SOeb STUVX/czMpAbBGK8ItZrMLqTXBx4YDB1YwBv7u++YKr3KHErWpkhFtqKATEhQQwezzVJ QB5PNwm2YoRjkhGuGcDJc4u1M2BKv5EM3wIjQtFLCzSYq2eW0lyl+7T3T0gpEMbjWHbW f9xg== X-Received: by 10.194.62.107 with SMTP id x11mr27352531wjr.27.1441819041623; Wed, 09 Sep 2015 10:17:21 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by smtp.gmail.com with ESMTPSA id j7sm11257042wjz.11.2015.09.09.10.17.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 10:17:21 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 01/12] tests/drmdevice: add new 'test' Date: Wed, 9 Sep 2015 18:21:22 +0100 Message-Id: <1441819293-25567-2-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> References: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> Cc: emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A simple example of how to use/what is the new drm{Get,Free}Devices() interface. Signed-off-by: Emil Velikov --- tests/Makefile.am | 1 + tests/drmdevice.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/drmdevice.c diff --git a/tests/Makefile.am b/tests/Makefile.am index a511d28..c53f4af 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -31,6 +31,7 @@ LDADD = $(top_builddir)/libdrm.la check_PROGRAMS = \ dristat \ + drmdevice \ drmstat dristat_LDADD = -lm diff --git a/tests/drmdevice.c b/tests/drmdevice.c new file mode 100644 index 0000000..4055f45 --- /dev/null +++ b/tests/drmdevice.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015 Emil Velikov + * + * 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. + * + */ + +#include +#include +#include + + +static void +print_device_info(drmDevicePtr device, int i) +{ + printf("device[%i]\n", i); + printf("\tavailable_nodes %04x\n", device->available_nodes); + printf("\tnodes\n"); + for (int j = 0; j < DRM_NODE_MAX; j++) + if (device->available_nodes & 1 << j) + printf("\t\tnodes[%d] %s\n", j, device->nodes[j]); + + printf("\tbustype %04x\n", device->bustype); + printf("\tbusinfo\n"); + if (device->bustype == DRM_BUS_PCI) { + printf("\t\tpci\n"); + printf("\t\t\tdomain\t%04x\n",device->businfo.pci->domain); + printf("\t\t\tbu\t%02x\n", device->businfo.pci->bus); + printf("\t\t\tde\t%02x\n", device->businfo.pci->dev); + printf("\t\t\tfunc\t%1u\n", device->businfo.pci->func); + + printf("\tdeviceinfo\n"); + printf("\t\tpci\n"); + printf("\t\t\tvendor_id\t%04x\n", device->deviceinfo.pci->vendor_id); + 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); + } else { + printf("Unknown/unhandled bustype\n"); + } + printf("\n"); +} + +int +main(void) +{ + drmDevicePtr *devices; + int ret, max_devices; + + max_devices = drmGetDevices(NULL, 0); + + if (max_devices <= 0) { + printf("drmGetDevices() has returned %d\n", max_devices); + return -1; + } + + devices = calloc(max_devices, sizeof(drmDevicePtr)); + if (devices == NULL) { + printf("Failed to allocate memory for the drmDevicePtr array\n"); + return -1; + } + + ret = drmGetDevices(devices, max_devices); + if (ret < 0) { + printf("drmGetDevices() returned an error %d\n", ret); + free(devices); + return -1; + } + + for (int i = 0; i < ret; i++) + print_device_info(devices[i], i); + + drmFreeDevices(devices, ret); + free(devices); + return 0; +}