From patchwork Wed Jan 30 00:56:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Plattner X-Patchwork-Id: 2064421 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id AA3E5DF23E for ; Wed, 30 Jan 2013 00:56:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92989E624D for ; Tue, 29 Jan 2013 16:56:52 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from hqemgate04.nvidia.com (hqemgate04.nvidia.com [216.228.121.35]) by gabe.freedesktop.org (Postfix) with ESMTP id 913AAE5E17 for ; Tue, 29 Jan 2013 16:56:40 -0800 (PST) Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Tue, 29 Jan 2013 16:56:28 -0800 Received: from hqemhub02.nvidia.com ([172.17.108.22]) by hqnvupgp08.nvidia.com (PGP Universal service); Tue, 29 Jan 2013 16:54:26 -0800 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Tue, 29 Jan 2013 16:54:26 -0800 Received: from tenor.nvidia.com (172.20.144.16) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server (TLS) id 8.3.297.1; Tue, 29 Jan 2013 16:56:39 -0800 From: Aaron Plattner To: Subject: [PATCH libdrm] tests/dristat: add -C to pretty-print device capabilities Date: Tue, 29 Jan 2013 16:56:31 -0800 Message-ID: <1359507391-24300-1-git-send-email-aplattner@nvidia.com> X-Mailer: git-send-email 1.8.1.2 X-NVConfidentiality: public MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org 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); } }