tests/dristat: add -C to pretty-print device capabilities
PATCH RESEND 1/1 tests/dristat: add -C to pretty-print device capabilities
---
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(-)
tests/dristat.c +68 -1
@@ -24,9 +24,11 @@* DEALINGS IN THE SOFTWARE. * * Authors: Rickard E. (Rik) Faith <[email protected]> +* Authors: Aaron Plattner <[email protected]> * */ +#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 0x00000020static 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); } }
Signature · 1 line
1.9.2
Quoted 10 lines · Aaron Plattner
Signed-off-by Aaron Plattner <[email protected]>---
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.
Quoted 1 line
tests/dristat.c +0
-0
[...]
tests/dristat.c static void getstats(int fd, int i) · line 267
Quoted 6 lines
tests/dristat.c +6
-0+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.
tests/dristat.c static void getstats(int fd, int i) · line 273
Quoted 6 lines
tests/dristat.c +6
-0+ } 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.
tests/dristat.c
Quoted 2 lines
tests/dristat.c +2
-0+ }; +int i;
Perhaps unsigned int here?
Other than that this looks like a useful addition.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel