Skip to content

Support Linux DRM backend#69

Open
Bennctu wants to merge 1 commit intosysprog21:mainfrom
Bennctu:drm_dev
Open

Support Linux DRM backend#69
Bennctu wants to merge 1 commit intosysprog21:mainfrom
Bennctu:drm_dev

Conversation

@Bennctu
Copy link
Copy Markdown
Collaborator

@Bennctu Bennctu commented Nov 3, 2024

Currently, using the DRM legacy interface is suitable for Mado's backend because we only need basic window display without advanced features.

Comment thread backend/drm.c Outdated
@jserv jserv requested a review from shengwen-tw November 3, 2024 15:05
Comment thread backend/drm.c Outdated
@jserv

This comment was marked as outdated.

@jserv

This comment was marked as outdated.

Comment thread Makefile
Comment thread backend/drm.c

return true;

bail_crtc:
Copy link
Copy Markdown
Collaborator

@huaxinliao huaxinliao Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this. It should be as below.

/* Retrieve resources */
if (!get_resources(tx->drm_dri_fd, &RES(tx)))
    goto bail_res;
....
bail_fb:
    drmModeRmFB(tx->drm_dri_fd, tx->fb_id);
    munmap(tx->fb_base, tx->fb_len);
bail_crtc:
    drmModeFreeCrtc(CRTC(tx));
bail_conn:
    drmModeFreeConnector(CONN(tx));
bail_res:
    drmModeFreeResources(RES(tx));

jserv

This comment was marked as resolved.

Comment thread README.md Outdated
Comment thread backend/linux_vt.c Outdated
@Bennctu

This comment was marked as outdated.

Comment thread backend/drm.c Outdated
Comment thread backend/drm.c Outdated
Comment thread configs/Kconfig Outdated
Comment thread backend/drm.c Outdated
Comment thread backend/drm.c Outdated
Comment thread backend/drm.c Outdated
Comment thread backend/drm.c
@jserv
Copy link
Copy Markdown
Contributor

jserv commented Nov 11, 2024

Check the DRM implementation for reference: https://github.com/zlgopen/awtk-linux-fb/blob/master/awtk-port/lcd_linux/lcd_linux_drm.c

jserv

This comment was marked as resolved.

@Bennctu Bennctu force-pushed the drm_dev branch 2 times, most recently from 32e2217 to 3cba956 Compare November 23, 2024 07:19
Comment thread backend/drm.c
Comment thread README.md Outdated
@jserv jserv requested a review from alanjian85 November 28, 2024 16:23
jserv

This comment was marked as resolved.

@Bennctu Bennctu force-pushed the drm_dev branch 2 times, most recently from f711c33 to e275994 Compare January 22, 2025 13:51
@jserv jserv requested a review from huaxinliao January 22, 2025 14:21
jserv

This comment was marked as outdated.

Comment thread backend/drm.c Outdated
Comment thread backend/drm.c Outdated
Comment thread backend/drm.c
twin_screen_resize(SCREEN(ctx), width, height);
}

static void twin_drm_exit(twin_context_t *ctx)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider that twin_drm_exit should handle ioctl(tx->drm_dri_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy) to ensure allocated resources are properly released.

@huaxinliao

This comment was marked as resolved.

@Bennctu

This comment was marked as resolved.

@sysprog21 sysprog21 deleted a comment from cubic-dev-ai Bot Oct 16, 2025
cubic-dev-ai[bot]

This comment was marked as resolved.

@sysprog21 sysprog21 deleted a comment from cubic-dev-ai Bot Oct 16, 2025
cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv
Copy link
Copy Markdown
Contributor

jserv commented May 1, 2026

For mado, a libdrm-free DRM backend is realistic because the use caseonly needs KMS + dumb buffer + CPU rendering, not GBM/EGL/GPU rendering. This pull request currently uses libdrm helpers such as drmModeGetResources, drmModeGetConnector, drmModeAddFB, drmModeSetCrtc, and drmModeRmFB, while already using raw ioctls for dumb-buffer creation/mapping.

The dumb-buffer path is appropriate: DRM dumb buffers are CPU-mappable scanout buffers, suitable for simple rendering but not complex GPU composition. GETCONNECTOR is intentionally a two-pass ioctl: first retrieve counts, then allocate arrays and retrieve modes/encoders; hotplug can race, so retry until counts stabilize.

Minimal ioctl-only framebuffer sequence is shown below:

open("/dev/dri/card0", O_RDWR | O_CLOEXEC);

DRM_IOCTL_MODE_GETRESOURCES;
DRM_IOCTL_MODE_GETCONNECTOR;   /* two-pass */
DRM_IOCTL_MODE_GETCRTC;

DRM_IOCTL_MODE_CREATE_DUMB;
DRM_IOCTL_MODE_ADDFB2;
DRM_IOCTL_MODE_MAP_DUMB;
mmap();

DRM_IOCTL_MODE_SETCRTC;

Use legacy SETCRTC first, not atomic KMS. Atomic is cleaner long-term, but it requires property discovery and more code. For mado’s CPU-rendered full-screen backend, direct legacy KMS ioctls are the smallest maintainable step.

@Bennctu
Copy link
Copy Markdown
Collaborator Author

Bennctu commented May 1, 2026

I ran the DRM backend on a VM with Ubuntu 24.04. However, I noticed that the screen froze.
drm.mov

I verified that the DRM backend runs successfully on Ubuntu 24.04 VM.

Screencast.from.2026.02.00.56.24.webm

@jserv jserv requested review from huaxinliao and shengwen-tw May 1, 2026 17:12
@huaxinliao
Copy link
Copy Markdown
Collaborator

I'm curious which part of the code fixed the VM issue.

Comment thread backend/drm.c
Comment thread backend/drm.c Outdated
Comment thread backend/drm.c Outdated
@huaxinliao
Copy link
Copy Markdown
Collaborator

Currently, using the DRM legacy interface is suitable for Mado's backend because we only need basic window display without advanced features.

Hi @Bennctu, Also, does commit e4f93e9 show the same rendering result as this one? I’d like to learn more about this part as well. Thank you for your generous explanation!

@sysprog21 sysprog21 deleted a comment from cubic-dev-ai Bot May 1, 2026
cubic-dev-ai[bot]

This comment was marked as resolved.

Implemented DRM-based framebuffer setup, including:
 - Opening the DRM device
 - Creating dumb buffers and mapping them to framebuffers
 - Setting mode and handling CRTC for connected display output

The legacy DRM ioctl interface is used as the current implementation
does not require atomic mode-setting or page flipping.

Atomic mode-setting prevents inconsistent states, supports rollback on
failures, and enables mode testing before committing changes.

Atomic page flipping synchronizes multiple planes within a VBLANK
interval, preventing tearing and improving display updates, especially
for power-efficient embedded controllers.

While the atomic API enhances KMS with property-based state management,
its complexity is unnecessary for now. The legacy interface remains
adequate, but future needs may justify adopting atomic mode-setting.

Close sysprog21#60
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="configs/Kconfig">

<violation number="1" location="configs/Kconfig:81">
P2: `BACKEND_DRM` is missing a dependency gate for libdrm, so users can enable it in Kconfig and hit build failures on systems without libdrm installed.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread configs/Kconfig

config BACKEND_DRM
bool "Linux DRM support"
depends on !CC_IS_EMCC
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: BACKEND_DRM is missing a dependency gate for libdrm, so users can enable it in Kconfig and hit build failures on systems without libdrm installed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At configs/Kconfig, line 81:

<comment>`BACKEND_DRM` is missing a dependency gate for libdrm, so users can enable it in Kconfig and hit build failures on systems without libdrm installed.</comment>

<file context>
@@ -76,6 +76,15 @@ choice
 
+config BACKEND_DRM
+    bool "Linux DRM support"
+    depends on !CC_IS_EMCC
+    select CURSOR
+    help
</file context>

@sysprog21 sysprog21 deleted a comment from cubic-dev-ai Bot May 7, 2026
@sysprog21 sysprog21 deleted a comment from shengwen-tw May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants