diff mbox

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

Message ID 1397808565-14255-1-git-send-email-aplattner@nvidia.com (mailing list archive)
State New, archived
Headers show

Commit Message

Aaron Plattner April 18, 2014, 8:09 a.m. UTC
Signed-off-by: Aaron Plattner <aplattner@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(-)

Comments

Thierry Reding May 13, 2014, 10:37 a.m. UTC | #1
On Fri, Apr 18, 2014 at 01:09:25AM -0700, Aaron Plattner wrote:
> Signed-off-by: Aaron Plattner <aplattner@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

I think this could go into the commit message.

> diff --git a/tests/dristat.c b/tests/dristat.c
[...]
> +static void getcaps(int fd)
> +{
> +    const struct {
> +	    uint64_t capability;
> +	    enum cap_type type;
> +	    const char *name;

The indentation here is slightly odd. Indentation is slightly odd
throughout the file, but it's more odd here than elsewhere. I think to
make it consistent this should be indented using a single tab rather
than a tab and four spaces.

> +    } 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" },

/usr/include/drm/drm.h on my system has DRM_CAP_TIMESTAMP_MONOTONIC and
DRM_CAP_ASYNC_PAGE_FLIP in addition to the above. Any chance you could
add support for those as well?

Oh, and there's DRM_CAP_CURSOR_WIDTH and DRM_CAP_CURSOR_HEIGHT, although
those haven't been added to libdrm's copy of drm.h yet.

> +    };
> +    int i;

Perhaps unsigned int here?

Other than that this looks like a useful addition.

Thierry
diff mbox

Patch

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@valinux.com>
+ * Authors: Aaron Plattner <aplattner@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);
 	}
     }