zmatt

list-kms-devices.c

Sep 30th, 2021 (edited)
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. // gcc -Og -Wall -Wextra $(pkg-config --cflags libdrm) -o list-kms-devices list-kms-devices.c $(pkg-config --libs libdrm)
  2.  
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <errno.h>
  6. #include <unistd.h>
  7. #include <xf86drm.h>
  8.  
  9. int main()
  10. {
  11.     for( int i = 0; i < DRM_MAX_MINOR; ++i ) {
  12.         char path[ 32 ];  // this is plenty for this purpose
  13.         sprintf( path, DRM_DEV_NAME, DRM_DIR_NAME, i );
  14.  
  15.         int fd = open( path, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK );
  16.         if( fd < 0 ) {
  17.             if( errno != ENOENT )
  18.                 fprintf( stderr, "%s: %m\n", path );
  19.             continue;
  20.         }
  21.  
  22.         if( drmSetClientCap( fd, DRM_CLIENT_CAP_ATOMIC, 1 ) >= 0 ) {
  23.             printf( "%s:\n", path );
  24.  
  25.             drmVersionPtr v = drmGetVersion( fd );
  26.             printf( "\tdriver: %s (%s)\n", v->name, v->desc );
  27.             printf( "\tversion: v%d.%d.%d (%s)\n", v->version_major, v->version_minor, v->version_patchlevel, v->date );
  28.             drmFreeVersion( v );
  29.         }
  30.  
  31.         close( fd );
  32.     }
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment