# Linux Kernel Module Cheat

### 17.18. DRM

DRM / DRI is the new interface that supersedes `fbdev`:

    ./build-buildroot --config 'BR2_PACKAGE_LIBDRM=y'
    ./build-userland --package libdrm -- userland/libs/libdrm/modeset.c
    ./run --eval-after './libs/libdrm/modeset.out' --graphic

Source: userland/libs/libdrm/modeset.c

Outcome: for a few seconds, the screen that contains the terminal gets taken over by changing colors of the rainbow.

TODO not working for `aarch64`, it takes over the screen for a few seconds and the kernel messages disappear, but the screen stays black all the time.

    ./build-buildroot --config 'BR2_PACKAGE_LIBDRM=y'
    ./build-userland --package libdrm
    ./build-buildroot
    ./run --eval-after './libs/libdrm/modeset.out' --graphic

kmscube however worked, which means that it must be a bug with this demo?

We set `CONFIG_DRM=y` on our default kernel configuration, and it creates one device file for each display:

    # ls -l /dev/dri
    total 0
    crw-------    1 root     root      226,   0 May 28 09:41 card0
    # grep 226 /proc/devices
    226 drm
    # ls /sys/module/drm /sys/module/drm_kms_helper/

Try creating new displays:

    ./run --arch aarch64 --graphic -- -device virtio-gpu-pci

to see multiple `/dev/dri/cardN`, and then use a different display with:

    ./run --eval-after './libs/libdrm/modeset.out' --graphic

Bibliography:

- https://dri.freedesktop.org/wiki/DRM/

- https://en.wikipedia.org/wiki/Direct_Rendering_Infrastructure

- https://en.wikipedia.org/wiki/Direct_Rendering_Manager

- https://en.wikipedia.org/wiki/Mode_setting KMS

Tested on: 93e383902ebcc03d8a7ac0d65961c0e62af9612b

- kmscube

- kmscon

- libdri2