[PATCH libdrm resend] tests/dristat: add -C to pretty-print device capabilities

Aaron Plattner aplattner at nvidia.com
Fri Apr 18 01:09:25 PDT 2014


Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
---
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 <faith at valinux.com>
+ * Authors: Aaron Plattner <aplattner at nvidia.com>
  * 
  */
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -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("<error>\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);
 	}
     }
-- 
1.9.2



More information about the dri-devel mailing list