From patchwork Fri Apr 18 08:09:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Plattner X-Patchwork-Id: 4013761 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 15B16BFF02 for ; Fri, 18 Apr 2014 08:10:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29EEF20380 for ; Fri, 18 Apr 2014 08:10:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id CCCAB2038E for ; Fri, 18 Apr 2014 08:10:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BB7F6E622; Fri, 18 Apr 2014 01:10:03 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from hqemgate15.nvidia.com (hqemgate15.nvidia.com [216.228.121.64]) by gabe.freedesktop.org (Postfix) with ESMTP id 797146E622 for ; Fri, 18 Apr 2014 01:10:01 -0700 (PDT) Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com id ; Fri, 18 Apr 2014 01:08:58 -0700 Received: from hqemhub02.nvidia.com ([172.20.12.94]) by hqnvupgp08.nvidia.com (PGP Universal service); Fri, 18 Apr 2014 01:04:44 -0700 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Fri, 18 Apr 2014 01:04:44 -0700 Received: from soprano.nvidia.com (172.20.144.16) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server (TLS) id 8.3.327.1; Fri, 18 Apr 2014 01:10:00 -0700 From: Aaron Plattner To: Subject: [PATCH libdrm resend] tests/dristat: add -C to pretty-print device capabilities Date: Fri, 18 Apr 2014 01:09:25 -0700 Message-ID: <1397808565-14255-1-git-send-email-aplattner@nvidia.com> X-Mailer: git-send-email 1.7.12 X-NVConfidentiality: public MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Signed-off-by: Aaron Plattner --- Example output of dristat -C: /dev/dri/card0 Device capabilities: Dumb framebuffer: yes VBlank high crtc: yes Preferred depth: 24 Prefer shadow: yes Prime: import export tests/dristat.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/dristat.c b/tests/dristat.c index 900a3e6..d36c3de 100644 --- a/tests/dristat.c +++ b/tests/dristat.c @@ -24,9 +24,11 @@ * DEALINGS IN THE SOFTWARE. * * Authors: Rickard E. (Rik) Faith + * Authors: Aaron Plattner * */ +#include #include #include #include @@ -35,11 +37,14 @@ #include "xf86drmHash.c" #include "xf86drm.c" +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + #define DRM_VERSION 0x00000001 #define DRM_MEMORY 0x00000002 #define DRM_CLIENTS 0x00000004 #define DRM_STATS 0x00000008 #define DRM_BUSID 0x00000010 +#define DRM_CAPS 0x00000020 static void getversion(int fd) { @@ -228,6 +233,65 @@ static void getstats(int fd, int i) } +enum cap_type { + CAP_BOOL, + CAP_UINT, + CAP_PRIME +}; + +static void printcap(enum cap_type type, uint64_t value) +{ + switch (type) { + case CAP_BOOL: + if (value) printf("yes"); + else printf("no"); + break; + case CAP_UINT: + printf("%" PRIu64, value); + break; + case CAP_PRIME: + if (value == 0) printf("none"); + else { + if (value & DRM_PRIME_CAP_IMPORT) printf("import "); + if (value & DRM_PRIME_CAP_EXPORT) printf("export"); + } + break; + } +} + +static void getcaps(int fd) +{ + const struct { + uint64_t capability; + enum cap_type type; + const char *name; + } caps[] = { + { DRM_CAP_DUMB_BUFFER, CAP_BOOL, "Dumb framebuffer" }, + { DRM_CAP_VBLANK_HIGH_CRTC, CAP_BOOL, "VBlank high crtc" }, + { DRM_CAP_DUMB_PREFERRED_DEPTH, CAP_UINT, "Preferred depth" }, + { DRM_CAP_DUMB_PREFER_SHADOW, CAP_BOOL, "Prefer shadow" }, + { DRM_CAP_PRIME, CAP_PRIME, "Prime" }, + }; + int i; + + printf(" Device capabilities:\n"); + + for (i = 0; i < ARRAY_SIZE(caps); i++) { + uint64_t value; + int ret = drmGetCap(fd, caps[i].capability, &value); + + printf(" %s: ", caps[i].name); + + if (ret) { + printf("\n"); + continue; + } + + printcap(caps[i].type, value); + printf("\n"); + } +} + int main(int argc, char **argv) { int c; @@ -238,7 +302,7 @@ int main(int argc, char **argv) char buf[64]; int i; - while ((c = getopt(argc, argv, "avmcsbM:i:")) != EOF) + while ((c = getopt(argc, argv, "avmcCsbM:i:")) != EOF) switch (c) { case 'a': mask = ~0; break; case 'v': mask |= DRM_VERSION; break; @@ -246,6 +310,7 @@ int main(int argc, char **argv) case 'c': mask |= DRM_CLIENTS; break; case 's': mask |= DRM_STATS; break; case 'b': mask |= DRM_BUSID; break; + case 'C': mask |= DRM_CAPS; break; case 'i': interval = strtol(optarg, NULL, 0); break; case 'M': minor = strtol(optarg, NULL, 0); break; default: @@ -254,6 +319,7 @@ int main(int argc, char **argv) fprintf( stderr, " -a Show all available information\n" ); fprintf( stderr, " -b Show DRM bus ID's\n" ); fprintf( stderr, " -c Display information about DRM clients\n" ); + fprintf( stderr, " -C Display DRM device capabilities\n" ); fprintf( stderr, " -i [interval] Continuously display statistics every [interval] seconds\n" ); fprintf( stderr, " -v Display DRM module and card version information\n" ); fprintf( stderr, " -m Display memory use information\n" ); @@ -272,6 +338,7 @@ int main(int argc, char **argv) if (mask & DRM_MEMORY) getvm(fd); if (mask & DRM_CLIENTS) getclients(fd); if (mask & DRM_STATS) getstats(fd, interval); + if (mask & DRM_CAPS) getcaps(fd); close(fd); } }