Skip to content

drm: phytium: update phytium drm controller driver support to 6.6.0.4#1700

Open
xiaqian1486 wants to merge 5 commits into
deepin-community:linux-6.6.yfrom
xiaqian1486:drm-6.6.y
Open

drm: phytium: update phytium drm controller driver support to 6.6.0.4#1700
xiaqian1486 wants to merge 5 commits into
deepin-community:linux-6.6.yfrom
xiaqian1486:drm-6.6.y

Conversation

@xiaqian1486
Copy link
Copy Markdown

@xiaqian1486 xiaqian1486 commented May 14, 2026

This patches updates the support for phytium drm controller driver.

  1. Read EDID in BMC mod
  2. Bugfix lane count parameter can't be set problem
  3. Avoid NULL PTR issue when setting gamma
  4. Fix resource leaks when remove driver
  5. Modify DC hsync to fix dp timing

Summary by Sourcery

Update Phytium DRM DP controller to improve EDID handling, lane count configuration, gamma safety, cleanup on shutdown, and DC hsync timing.

Bug Fixes:

  • Ensure EDID is read correctly in BMC mode and reused outside BMC mode to avoid NULL access and improper audio detection.
  • Fix DP lane count selection by honoring non-default source_max_lane_count values.
  • Prevent NULL pointer dereferences in gamma LUT handling by validating CRTC state, LUT data, and mode.
  • Avoid memory pool and EDID-related resource leaks by guarding pool destruction, freeing EDID on unset, and invoking display shutdown during PCI and platform device removal.

Enhancements:

  • Adjust DC hsync timing dynamically based on link lane count to improve DP timing without rejecting specific modes.

For BMC mode, due to OpenBMC KVM need to read edid in
phytium_connector_get_modes() function, other application
scenarios, read edid in phytium_connector_detect() function.

Mainline: NA
Signed-off-by: Wang Hao <wanghao1851@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Xia Qian <xiaqian1486@phytium.com.cn>
Fix the issue where the source_max_lane_count parameter
cannot be customized during driver installation.

Mainline: NA
Signed-off-by: WangHao <wanghao1851@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Xia Qian <xiaqian1486@phytium.com.cn>
Add pointer validity checks to the gamma setting function
to prevent NULL pointer occurrence when running applications.

Mainline: Open-Source
Signed-off-by: Yu Da <yuda2152@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Xia Qian <xiaqian1486@phytium.com.cn>
When rmmod drivers, call the shutdown function
to release resources and prevent dp and
frame buffer leaks.

Mainline: Open-Source
Signed-off-by: Yu Da <yuda2152@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Xia Qian <xiaqian1486@phytium.com.cn>
There is an issue with DP when handling FIFO delay.
When connecting a Dell monitor with a link state of
1.62G/4 lanes, modes of 1600x900 and 1024x768-75Hz
can not display. Corrected timing must be configured
on the DC to ensure that DP output timing meets the
monitor's requirements.

Mainline: Open-Source
Signed-off-by: Yu Da <yuda2152@phytium.com.cn>
Signed-off-by: Wang Yinfeng<wangyinfeng@phytium.com.cn>
Signed-off-by: Xia Qian <xiaqian1486@phytium.com.cn>
@deepin-ci-robot deepin-ci-robot requested review from Ink-Paper and myml May 14, 2026 02:13
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 14, 2026

Reviewer's Guide

Updates the Phytium DRM DP, PCI, platform, CRTC, GEM, and register code to better support BMC EDID handling, correct lane-count-based timing, prevent NULL dereferences and memory issues, ensure proper shutdown on device removal, and adjust DC hsync timing based on FIFO and link configuration.

Sequence diagram for BMC and non-BMC EDID handling

sequenceDiagram
    participant DrmCore
    participant Connector as drm_connector
    participant DpDev as phytium_dp_device
    participant AuxDDC as aux_ddc

    Note over DrmCore,Connector: Hotplug long pulse handling
    DrmCore->>Connector: phytium_dp_long_pulse(hpd_raw_state)
    Connector->>DpDev: connector_to_dp_device()
    alt !priv->info.bmc_mode
        Connector->>Connector: phytium_dp_set_edid()
        Connector->>DpDev: phytium_dp_unset_edid()
        Connector->>AuxDDC: drm_get_edid(connector, &DpDev.aux.ddc)
        AuxDDC-->>Connector: edid or NULL
        alt edid == NULL
            Connector-->>DrmCore: connector_status_disconnected
        else edid valid
            Connector->>Connector: drm_detect_monitor_audio(DpDev.detect_edid)
            Connector-->>DrmCore: connector_status_connected
        end
    else priv->info.bmc_mode
        Note over Connector,DpDev: EDID read happens later in get_modes
    end

    Note over DrmCore,Connector: Mode enumeration
    DrmCore->>Connector: phytium_connector_get_modes()
    Connector->>DpDev: connector_to_dp_device()
    alt DpDev.is_edp
        Connector->>Connector: edid = DpDev.edp_edid
    else priv->info.bmc_mode
        Connector->>AuxDDC: drm_get_edid(connector, &DpDev.aux.ddc)
        AuxDDC-->>Connector: edid
    else non-BMC DP
        Connector->>Connector: edid = DpDev.detect_edid
    end
    alt edid && drm_edid_is_valid(edid)
        Connector->>Connector: drm_connector_update_edid_property()
        Connector->>Connector: drm_add_edid_modes()
        alt priv->info.bmc_mode
            Connector->>Connector: drm_detect_monitor_audio(edid)
        end
    else
        Connector->>Connector: DpDev.has_audio = false
    end
    alt priv->info.bmc_mode
        Connector->>Connector: kfree(edid)
    end
Loading

File-Level Changes

Change Details Files
Adjust DP connector EDID handling to support BMC mode and cached EDID, and gate audio detection appropriately.
  • Include phytium_crtc.h in the DP implementation to access CRTC structures used elsewhere in the file.
  • In connector_get_modes, select EDID from eDP, BMC-mode AUX DDC, or cached detect_edid depending on is_edp and priv->info.bmc_mode, and only detect audio in BMC mode.
  • Free EDID only in BMC mode, and add detect_edid field to the DP device struct for non-BMC cached EDID.
drivers/gpu/drm/phytium/phytium_dp.c
drivers/gpu/drm/phytium/phytium_dp.h
Handle hotplug long pulses by refreshing a cached EDID and audio state when not in BMC mode.
  • Add helper to clear detect_edid and reset has_audio, and another helper to read EDID via AUX into detect_edid and set has_audio, returning connector_status.
  • In phytium_dp_long_pulse, when link is up and not in BMC mode, call the EDID helper and early-exit when disconnected.
drivers/gpu/drm/phytium/phytium_dp.c
Modify DC horizontal sync timing based on lane count and FIFO status for DP outputs, and remove hard-coded mode rejections.
  • Introduce phytium_dp_modify_dc_hsync_time, which validates dev/priv/crtc, checks the DP FIFO against a default value, computes back porch and adjustment lines from link_lane_count and HSYNC_* constants, adjusts hsync start/end accordingly, and programs PHYTIUM_DC_HSYNC with polarity and enable bits.
  • Call the hsync modification routine from phytium_encoder_enable for non-eDP outputs before video configuration, conditioned on is_edp.
  • Define HSYNC_LANE_COUNT_MULTI and HSYNC_MIN_ADJ_OFFSET in the DP header, and define PHYTIUM_DP_DEFAULT_FIFO_VALUE in the register header.
  • Remove special-case rejections of 1600x900 and high-clock 1024x768 modes from encoder_mode_valid, leaving only minimum resolution checks.
drivers/gpu/drm/phytium/phytium_dp.c
drivers/gpu/drm/phytium/phytium_dp.h
drivers/gpu/drm/phytium/phytium_reg.h
Ensure clean driver shutdown on PCI and platform device removal without leaking resources or leaving hardware active.
  • Refactor phytium_pci_shutdown so it appears before use in remove; it still fetches drm_device and priv and calls priv->display_shutdown(dev).
  • In phytium_pci_remove, after disabling HPD IRQs and cancelling hotplug work, call the shutdown helper before unregistering and tearing down VRAM and private data.
  • Analogously, define phytium_platform_shutdown before its usage and call it from phytium_platform_remove after disabling HPD IRQs and cancelling hotplug work.
drivers/gpu/drm/phytium/phytium_pci.c
drivers/gpu/drm/phytium/phytium_platform.c
Harden gamma setting path to avoid NULL dereferences when gamma state or mode data is missing.
  • In phytium_crtc_gamma_set, bail out early if the CRTC state pointer is NULL.
  • After mapping gamma_lut to a drm_color_lut array, check for NULL and return early if absent.
  • Before computing frame timing for gamma updates, verify mode is non-NULL and return if it is.
drivers/gpu/drm/phytium/phytium_crtc.c
Make GEM memory pool management robust to uninitialized or already-destroyed memory pools.
  • Guard gen_pool_free with a NULL check on priv->memory_pool in phytium_memory_pool_free.
  • Guard gen_pool_destroy with a NULL check on priv->memory_pool in phytium_memory_pool_fini.
drivers/gpu/drm/phytium/phytium_gem.c
Fix lane count reporting for PX210 DP so that non-4-lane configurations respect source_max_lane_count.
  • Change px210_dp_hw_get_source_lane_count to return source_max_lane_count when it is not 4, otherwise fall back to the port-specific array value.
drivers/gpu/drm/phytium/px210_dp.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign opsiff for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Copy Markdown

Hi @xiaqian1486. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Copy Markdown

@sourcery-ai sourcery-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.

Hey - I've found 1 issue, and left some high level feedback:

  • In phytium_dp_modify_dc_hsync_time(), connector->state is dereferenced without a NULL check; please guard connector->state (and potentially crtc->state/mode) before use to avoid NULL pointer dereferences during enable paths or transient states.
  • The new PCI and platform shutdown helpers assume dev and dev->dev_private are always valid; consider adding NULL checks so that remove/shutdown paths after partial probe failures or unexpected drvdata states do not crash.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In phytium_dp_modify_dc_hsync_time(), connector->state is dereferenced without a NULL check; please guard connector->state (and potentially crtc->state/mode) before use to avoid NULL pointer dereferences during enable paths or transient states.
- The new PCI and platform shutdown helpers assume dev and dev->dev_private are always valid; consider adding NULL checks so that remove/shutdown paths after partial probe failures or unexpected drvdata states do not crash.

## Individual Comments

### Comment 1
<location path="drivers/gpu/drm/phytium/phytium_dp.c" line_range="2249" />
<code_context>
+		return;
+	}
+
+	crtc = connector->state->crtc;
+	if (!crtc)
+		return;
</code_context>
<issue_to_address>
**issue (bug_risk):** Connector state is dereferenced without a NULL check, which can lead to crashes.

In `phytium_dp_modify_dc_hsync_time`, `connector->state` is used without checking for NULL. In hotplug, early init, or teardown paths this can legitimately be NULL and will oops the kernel. Add a guard, e.g.:

```c
if (!connector->state)
	return;

crtc = connector->state->crtc;
```

before accessing `connector->state->crtc`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

return;
}

crtc = connector->state->crtc;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Connector state is dereferenced without a NULL check, which can lead to crashes.

In phytium_dp_modify_dc_hsync_time, connector->state is used without checking for NULL. In hotplug, early init, or teardown paths this can legitimately be NULL and will oops the kernel. Add a guard, e.g.:

if (!connector->state)
	return;

crtc = connector->state->crtc;

before accessing connector->state->crtc.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Phytium DRM DP controller driver with changes around EDID handling, lane-count selection, gamma safety checks, remove/shutdown cleanup, and DP/DC timing adjustment.

Changes:

  • Adds cached external-DP EDID handling and BMC-mode EDID reads.
  • Adds DP hsync timing adjustment and removes some hard-coded mode rejections.
  • Adds shutdown calls on remove paths and guards memory-pool cleanup/gamma paths.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
drivers/gpu/drm/phytium/px210_dp.c Adds module-parameter override for PX210 source lane count.
drivers/gpu/drm/phytium/phytium_reg.h Defines the default DP FIFO register value used by hsync adjustment.
drivers/gpu/drm/phytium/phytium_platform.c Calls display shutdown during platform-device removal.
drivers/gpu/drm/phytium/phytium_pci.c Calls display shutdown during PCI-device removal.
drivers/gpu/drm/phytium/phytium_gem.c Adds NULL guards around memory-pool free/destroy calls.
drivers/gpu/drm/phytium/phytium_dp.h Adds cached EDID storage and hsync adjustment constants.
drivers/gpu/drm/phytium/phytium_dp.c Updates EDID handling, audio detection, hsync timing, and mode validation behavior.
drivers/gpu/drm/phytium/phytium_crtc.c Adds defensive checks around gamma LUT programming.
Comments suppressed due to low confidence (1)

drivers/gpu/drm/phytium/phytium_crtc.c:369

  • mode is the address of state->adjusted_mode, so this NULL check can never be true once state is non-NULL. If the goal is to avoid invalid timing crashes, the check needs to validate fields used below (for example crtc_clock before the division) rather than testing this pointer.
			if (!mode)
				return;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1796 to +1797
if (status == connector_status_disconnected)
goto out;
Comment on lines +1794 to +1795
if (!priv->info.bmc_mode) {
status = phytium_dp_set_edid(connector);
Comment on lines +1739 to +1750
phytium_dp->has_audio = false;
}

static enum drm_connector_status phytium_dp_set_edid(struct drm_connector *connector)
{
struct phytium_dp_device *phytium_dp = connector_to_dp_device(connector);

phytium_dp_unset_edid(connector);
phytium_dp->detect_edid = drm_get_edid(connector, &phytium_dp->aux.ddc);
if (!phytium_dp->detect_edid)
return connector_status_disconnected;

Comment on lines +73 to +74
if (priv->memory_pool)
gen_pool_destroy(priv->memory_pool);
Comment on lines +345 to 346
phytium_pci_shutdown(pdev);
drm_dev_unregister(dev);
Comment on lines +331 to +332
if (priv->info.bmc_mode)
phytium_dp->has_audio = drm_detect_monitor_audio(edid);
Comment on lines +2244 to +2247
if (!connector) {
DRM_INFO("%s: connector is null\n", __func__);
return;
}
phytium_dp_hpd_irq_setup(dev, false);
cancel_work_sync(&priv->hotplug_work);
phytium_platform_shutdown(pdev);
drm_dev_unregister(dev);
Comment on lines +899 to 902
if (source_max_lane_count != 4)
return source_max_lane_count;

return px210_dp_source_lane_count[phytium_dp->port];
Comment on lines +351 to +352
if (!state)
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants