zmatt icon

list-kms-devices.c

zmatt | PRO | 10/01/21 03:13:38 AM UTC (Edited) | 0 ⭐ | 520 👁️ | Never ⏰ | []
C |

920 B

|

None

|

0 👍

/

0 👎

// gcc -Og -Wall -Wextra $(pkg-config --cflags libdrm) -o list-kms-devices list-kms-devices.c $(pkg-config --libs libdrm)
 
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <xf86drm.h>
 
int main()
{
    for( int i = 0; i < DRM_MAX_MINOR; ++i ) {
        char path[ 32 ];  // this is plenty for this purpose
        sprintf( path, DRM_DEV_NAME, DRM_DIR_NAME, i );
 
        int fd = open( path, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK );
        if( fd < 0 ) {
            if( errno != ENOENT )
                fprintf( stderr, "%s: %m\n", path );
            continue;
        }
 
        if( drmSetClientCap( fd, DRM_CLIENT_CAP_ATOMIC, 1 ) >= 0 ) {
            printf( "%s:\n", path );
 
            drmVersionPtr v = drmGetVersion( fd );
            printf( "\tdriver: %s (%s)\n", v->name, v->desc );
            printf( "\tversion: v%d.%d.%d (%s)\n", v->version_major, v->version_minor, v->version_patchlevel, v->date );
            drmFreeVersion( v );
        }
 
        close( fd );
    }
    return 0;
}

Comments