Skip to content

Conversation

@bramoosterhuis
Copy link
Contributor

Fix DRM Pipeline Initialization for Platforms Without Pre-configured Encoders

Problem

On some platforms (e.g., BananaPi with Allwinner H3), the DRM driver does not pre-configure the encoder pipeline. The existing code assumed connector->encoder_id would always be set, causing initialization failures when starting from a cold boot state.

Changes

1. Enhanced Encoder Selection (DRM.cpp)

  • Strategy 1: Use pre-assigned encoder if connector->encoder_id is valid
  • Strategy 2: Search through connector's compatible encoders when no encoder is assigned
    • Prefer encoders already associated with a CRTC (warm state)
    • Fall back to free encoders
    • Validate encoder compatibility via possible_crtcs bitmask

2. CRTC Allocation

  • Allocate CRTC from possibleCrtcs bitmask when encoder has no CRTC assigned
  • Pick first available CRTC that matches the bitmask

3. Primary Plane Discovery

  • Fixed plane search to find PRIMARY planes compatible with selected CRTC
  • Check plane->possible_crtcs bitmask against CRTC index
  • Support both warm boot (plane already active) and cold boot (find unused PRIMARY plane)

4. Logging Improvements

  • Fixed division-by-zero when CRTC has no active mode (cold boot)
  • Added comprehensive trace logging for encoder/CRTC/plane selection process
  • Clear indication of warm vs cold boot paths

5. DRM Identifier Consistency

  • Changed DRM::InvalidIdentifier from ~0 to 0 to match kernel convention
  • All DRM objects (encoders, CRTCs, planes) use 0 as invalid ID

Testing

Tested on BananaPi M2 with Allwinner H3 SoC:

  • ✅ Cold boot initialization (no pre-configured pipeline)
  • ✅ Encoder search and selection
  • ✅ CRTC allocation from possibleCrtcs bitmask
  • ✅ Primary plane discovery
  • ✅ Proper modeset marking for inactive displays

Impact

  • Fixes compositor initialization on platforms where DRM driver leaves encoder pipeline unconfigured
  • Maintains backward compatibility with platforms that pre-configure encoders
  • More robust handling of cold boot scenarios

@pwielders pwielders merged commit afe4b29 into master Oct 15, 2025
48 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants