drm/spacemit: add SpacemiT K3 display support
Subsystems (7)
cover drm/spacemit: add SpacemiT K3 display support
This is a resend of today's earlier posting, which was only partially delivered because of a mail failure on the sending side: the cover letter and eight of the patches never reached the lists. The patches are unchanged. Apologies for the duplicates.
This series adds display support for the SpacemiT K3 [2], a RISC-V SoC:
a new DRM driver, a new PHY driver and three new bindings.
The display path is three blocks deep:
Saturn DPU -> Innosilicon DP/eDP controller -> Innosilicon DP PHY
The Saturn DPU is SpacemiT's own display processing unit. It has a private address translation unit and a command-list composer that replays a batch of register writes when a flush is latched. It exposes one CRTC with one primary plane. The K3 instantiates two DPUs, one per display path.
The DPU driver arrives as five staged patches to keep each one a reasonable size. The driver only becomes buildable with that last patch. Bisect safe.
The DP/eDP controller and its PHY are Innosilicon IP, also two instances of each. An instance behaves as embedded DisplayPort or as external DisplayPort purely according to what its output port is wired to, so the bindings do not distinguish them. The PHY's registers are interleaved with the controller's inside one MMIO window, which is why it is described as a child node and shares the controller's regmap.
The pixel clock is generated by the DP PHY's PLL, and the SoC's APMU pixel-clock mux takes that PLL as an input. Rather than let the display driver reach into PHY registers, the PHY registers its PLL as a clock provider and the APMU mux is parented to it through the clock framework. That is what patches 2, 4, 5 and 6 are for, and it is also what keeps the APMU and the DP/eDP controller out of a devicetree provider cycle.
As a first posting of the K3 display subsystem, this patchset supports:
a single primary plane per CRTC, linear RGB scanout (no plane scaling, rotation, YUV or writeback). It does not support DSI, DSC or DP audio, and link rates are capped at HBR2.
Based on drm-misc-next at commit 5b9af25f2d0b ("accel/ivpu: Remove unnecessary min_t()/max_t() usage"), v7.2-rc2 based.
Testing this series needs a SpacemiT u-boot carrying display support [1]. SpacemiT expects to add that support into an official u-boot release in August 2026.
Tested on two K3 boards:
- Pico-ITX: an eDP panel and an external DisplayPort monitor.
- CoM260-IFX: DisplayPort only, no eDP.
Note: The eDP panel DTS enablement is not part of this series; a separate
series will follow showing how eDP can be verified.
What was run on both boards, with modetest from libdrm and with kmscube:
- modetest -s, looped over 1920x1080, 1280x720 and 3840x2160
on DisplayPort and 2560x1600 on eDP
- kmscube, on each head and on both at once
- hot-plug and sink swap on the DisplayPort connector
Both built-in and modular configurations were tested, and the runs above were repeated in both. Patch 17 defconfig adds them as modules.
[1] https://github.com/spacemit-com/uboot-for-k3-display-verify/tree/k3-br-v1.0.y
[2] https://www.spacemit.com/community/document/info?lang=en&nodepath=hardware/key_stone/k3
---
Cody Kang (17):
dt-bindings: display: spacemit: add K3 Saturn DPU controller
dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY
dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller
dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU
phy: spacemit: add Innosilicon DP TX PHY driver
clk: spacemit: k3: parent eDP/DP pixel clock to the PHY PLL drm/spacemit: add Saturn DPU register model
drm/spacemit: add Saturn DPU core types, cmdlist and display MMU drm/spacemit: add Saturn DPU hardware backend
drm/spacemit: add Saturn DPU KMS pipeline
drm/spacemit: add Saturn DPU DRM device driver drm/spacemit: add Innosilicon DP/eDP controller bridge driver
MAINTAINERS: add SpacemiT K3 display driver entry
riscv: dts: spacemit: k3: add display nodes
riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output
riscv: dts: spacemit: k3-com260-ifx: enable the DisplayPort output
riscv: defconfig: spacemit: k3: enable display driver
.../display/spacemit/spacemit,k3-inno-dp.yaml | 140 ++ .../display/spacemit/spacemit,k3-saturn-dpu.yaml | 132 ++ .../bindings/phy/spacemit,k3-inno-dp-phy.yaml | 48 + .../bindings/soc/spacemit/spacemit,k1-syscon.yaml | 30 +- MAINTAINERS | 10 + arch/riscv/boot/dts/spacemit/k3-com260-ifx.dts | 11 + arch/riscv/boot/dts/spacemit/k3-display.dtsi | 156 ++ arch/riscv/boot/dts/spacemit/k3-pico-itx.dts | 11 + arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 22 + arch/riscv/configs/defconfig | 2 + drivers/clk/spacemit/ccu-k3.c | 4 +- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/spacemit/Kconfig | 37 + drivers/gpu/drm/spacemit/Makefile | 15 + drivers/gpu/drm/spacemit/dpu/dpu_saturn.c | 483 ++++ drivers/gpu/drm/spacemit/dpu/dpu_saturn.h | 35 + drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c | 896 +++++++ drivers/gpu/drm/spacemit/dpu/dpu_trace.h | 350 +++ drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c | 152 ++ drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h | 21 + drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h | 25 + drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h | 52 + .../gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h | 64 + .../drm/spacemit/dpu/saturn_regs/saturn_fields.h | 298 +++ drivers/gpu/drm/spacemit/spacemit_cmdlist.c | 304 +++ drivers/gpu/drm/spacemit/spacemit_cmdlist.h | 146 ++ drivers/gpu/drm/spacemit/spacemit_crtc.c | 815 +++++++ drivers/gpu/drm/spacemit/spacemit_crtc.h | 259 +++ drivers/gpu/drm/spacemit/spacemit_dmmu.c | 103 + drivers/gpu/drm/spacemit/spacemit_dmmu.h | 40 + drivers/gpu/drm/spacemit/spacemit_dpu_ids.h | 22 + drivers/gpu/drm/spacemit/spacemit_dpu_reg.h | 108 + drivers/gpu/drm/spacemit/spacemit_drm.c | 132 ++ drivers/gpu/drm/spacemit/spacemit_drm.h | 68 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2443 ++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 +++ drivers/gpu/drm/spacemit/spacemit_planes.c | 376 +++ drivers/phy/spacemit/Kconfig | 13 + drivers/phy/spacemit/Makefile | 1 + drivers/phy/spacemit/phy-k3-inno-dp.c | 948 ++++++++ 41 files changed, 9099 insertions(+), 3 deletions(-)
---
base-commit: 5b9af25f2d0b574b4058c9f8c84486a597168116
change-id: 20260713-k3-display-e8ffed67e936
Signature · 1 line
Cody Kang <[email protected]>
PATCH RESEND 1/17 dt-bindings: display: spacemit: add K3 Saturn DPU controller
Document the Saturn display processing unit found on the SpacemiT K3 SoC. The K3 instantiates two of them, one per display path. They share a
compatible: an instance differs only in which register window, interrupt, clock and reset lines it takes.
--- .../display/spacemit/spacemit,k3-saturn-dpu.yaml | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+)
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +132 -0
@@ -0,0 +1,132 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/spacemit/spacemit,k3-saturn-dpu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K3 Saturn Display Processing Unit + +maintainers: + - Cody Kang <[email protected]> + +description: + The Saturn DPU is the display processing unit of the SpacemiT K3 SoC. It + composes the display planes and drives the timing for one display path. Its + output goes to a DisplayPort or embedded DisplayPort controller. The K3 has + two instances. + +properties: + compatible: + const: spacemit,k3-saturn-dpu + + reg: + maxItems: 1 + + interrupts: + items: + - description: Online (live display) compose path. + - description: Offline (writeback) compose path. + + interrupt-names: + items: + - const: online + - const: offline + + clocks: + items: + - description: Pixel clock. + - description: Memory clock for the compose pipeline. + - description: AXI bus clock. + - description: DSI escape clock. + - description: DSC clock. + + clock-names: + items: + - const: pxclk + - const: mclk + - const: aclk + - const: escclk + - const: dscclk + + resets: + items: + - description: Memory clock domain. + - description: LCD domain, shared with the downstream controller. + - description: DSI escape clock domain. + - description: AXI clock domain. + - description: DSC domain. + + reset-names: + items: + - const: mclk + - const: lcd + - const: esc + - const: aclk + - const: dsc + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: Video output to the DisplayPort or eDP controller. + + required: + - port@0 + +required: + - compatible + - reg + - interrupts + - interrupt-names + - clocks + - clock-names + - resets + - reset-names + - ports + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/spacemit,k3-clocks.h> + #include <dt-bindings/reset/spacemit,k3-resets.h> + #include <dt-bindings/interrupt-controller/irq.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + dpu@c0340000 { + compatible = "spacemit,k3-saturn-dpu"; + reg = <0x0 0xc0340000 0x0 0x54000>; + interrupts = <90 IRQ_TYPE_LEVEL_HIGH>, + <89 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "online", "offline"; + clocks = <&syscon_apmu CLK_APMU_LCD_PXCLK>, + <&syscon_apmu CLK_APMU_LCD_MCLK>, + <&syscon_apmu CLK_APMU_DPU_ACLK>, + <&syscon_apmu CLK_APMU_DSI_ESC>, + <&syscon_apmu CLK_APMU_LCD_DSC>; + clock-names = "pxclk", "mclk", "aclk", "escclk", "dscclk"; + resets = <&syscon_apmu RESET_APMU_LCD_MCLK>, + <&syscon_apmu RESET_APMU_LCD>, + <&syscon_apmu RESET_APMU_DSI_ESC>, + <&syscon_apmu RESET_APMU_DPU_ACLK>, + <&syscon_apmu RESET_APMU_LCD_DSCCLK>; + reset-names = "mclk", "lcd", "esc", "aclk", "dsc"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + endpoint { + remote-endpoint = <&edp0_in>; + }; + }; + }; + }; + };
Signature · 1 line
2.43.0
Re: [PATCH RESEND 01/17] dt-bindings: display: spacemit: add K3 Saturn DPU controller
Quoted 10 lines · Cody Kang
Document the Saturn display processing unit found on the SpacemiT K3 SoC. The K3 instantiates two of them, one per display path. They share a
compatible: an instance differs only in which register window, interrupt, clock and reset lines it takes.Signed-off-by Cody Kang <[email protected]>--- .../display/spacemit/spacemit,k3-saturn-dpu.yaml | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+)
PATCH RESEND 2/17 dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY
In reply to Cody KangThe SpacemiT K3 DisplayPort controller drives its four transmit lanes through an integrated Innosilicon DP PHY, one PHY per controller. Add a binding so the controller can reference its transmit PHY and the pixel clock the PHY's PLL sources.
The PHY's registers are interleaved with its parent controller's inside one MMIO window, so it owns neither a reg nor a reset and is modelled as a child of the controller.
It exposes its PLL-generated pixel clock through #clock-cells, so the APMU pixel-clock mux can select it as a parent through the clock framework.
--- .../bindings/phy/spacemit,k3-inno-dp-phy.yaml | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+)
Documentation/devicetree/bindings/phy/spacemit,k3-inno-dp-phy.yaml new file +48 -0
@@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/spacemit,k3-inno-dp-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K3 Innosilicon DisplayPort PHY + +maintainers: + - Cody Kang <[email protected]> + +description: + Innosilicon four-lane DisplayPort transmit PHY integrated in the SpacemiT + K3 SoC, one per DisplayPort controller. Its registers are interleaved with + the controller's own inside a single register window, so it is described as + a child of the controller and owns neither a reg nor a reset. + + The PHY provides the pixel clock its PLL generates, which the APMU + pixel-clock mux takes as one of its inputs. + +properties: + compatible: + const: spacemit,k3-inno-dp-phy + + "#phy-cells": + const: 0 + + "#clock-cells": + const: 0 + + clock-output-names: + maxItems: 1 + +required: + - compatible + - "#phy-cells" + - "#clock-cells" + +additionalProperties: false + +examples: + - | + phy { + compatible = "spacemit,k3-inno-dp-phy"; + #phy-cells = <0>; + #clock-cells = <0>; + clock-output-names = "edp0_pll_pxclk"; + };
Signature · 1 line
2.43.0
Re: [PATCH RESEND 02/17] dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY
Quoted 9 lines · Cody Kang
The SpacemiT K3 DisplayPort controller drives its four transmit lanes through an integrated Innosilicon DP PHY, one PHY per controller. Add a binding so the controller can reference its transmit PHY and the pixel clock the PHY's PLL sources.
The PHY's registers are interleaved with its parent controller's inside one MMIO window, so it owns neither a reg nor a reset and is modelled as a child of the controller.
Quoted 9 lines
It exposes its PLL-generated pixel clock through #clock-cells, so the APMU pixel-clock mux can select it as a parent through the clock framework.
Signed-off-by Cody Kang <[email protected]>--- .../bindings/phy/spacemit,k3-inno-dp-phy.yaml | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+)
PATCH RESEND 3/17 dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller
In reply to Cody KangBoth K3 instances are the same IP and share one compatible; which one behaves as eDP is decided by what its downstream port is wired to, not by which register window it sits in, so the binding does not distinguish them.
--- .../display/spacemit/spacemit,k3-inno-dp.yaml | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+)
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +140 -0
@@ -0,0 +1,140 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/spacemit/spacemit,k3-inno-dp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K3 Innosilicon DisplayPort / embedded DisplayPort Controller + +maintainers: + - Cody Kang <[email protected]> + +description: + Innosilicon DisplayPort transmit controller integrated in the SpacemiT K3 + SoC. The K3 has two instances of the same block sharing one compatible; + each acts as embedded or external DisplayPort depending on whether its + output port drives a panel or a connector. + +properties: + compatible: + const: spacemit,k3-inno-dp + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: Link and hot-plug events. + + clocks: + items: + - description: Pixel clock for the controller. + - description: + Pixel clock generated by the DP PHY PLL; the pixel clock above is + parented onto it in use. + + clock-names: + items: + - const: pxclk + - const: pll + + resets: + maxItems: 1 + description: Controller-wide reset signal. + + phys: + maxItems: 1 + description: Phandle to the K3 Innosilicon DP PHY. + + phy-names: + items: + - const: dp + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: Video input from the DPU. + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Output to the panel or to the DisplayPort connector. + + required: + - port@0 + + aux-bus: + $ref: /schemas/display/dp-aux-bus.yaml# + description: + The DisplayPort AUX bus. Present when the output drives an embedded + panel, which is described as a child of this node and identifies itself + over AUX. Absent when the output is a connector. + + phy: + $ref: /schemas/phy/spacemit,k3-inno-dp-phy.yaml# + description: + The DisplayPort PHY. Its registers live inside this controller's + register window, so it is described here as a child node. + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - resets + - phys + - phy-names + - ports + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/spacemit,k3-clocks.h> + #include <dt-bindings/reset/spacemit,k3-resets.h> + #include <dt-bindings/interrupt-controller/irq.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + edp@cac84000 { + compatible = "spacemit,k3-inno-dp"; + reg = <0x0 0xcac84000 0x0 0x4000>; + interrupts = <132 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&syscon_apmu CLK_APMU_EDP0_PXCLK>, <&edp0_phy>; + clock-names = "pxclk", "pll"; + resets = <&syscon_apmu RESET_APMU_EDP0>; + phys = <&edp0_phy>; + phy-names = "dp"; + + edp0_phy: phy { + compatible = "spacemit,k3-inno-dp-phy"; + #phy-cells = <0>; + #clock-cells = <0>; + clock-output-names = "edp0_pll_pxclk"; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + endpoint { + remote-endpoint = <&dpu0_out>; + }; + }; + + port@1 { + reg = <1>; + endpoint { + remote-endpoint = <&panel_in>; + }; + }; + }; + }; + };
Signature · 1 line
2.43.0
Re: [PATCH RESEND 03/17] dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller
Quoted 71 lines · Cody Kang
Both K3 instances are the same IP and share one compatible; which one behaves as eDP is decided by what its downstream port is wired to, not by which register window it sits in, so the binding does not distinguish them.
Signed-off-by Cody Kang <[email protected]>--- .../display/spacemit/spacemit,k3-inno-dp.yaml | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+)Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +56
-0@@ -0,0 +1,140 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/spacemit/spacemit,k3-inno-dp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K3 Innosilicon DisplayPort / embedded DisplayPort Controller + +maintainers: + - Cody Kang <[email protected]> + +description: + Innosilicon DisplayPort transmit controller integrated in the SpacemiT K3 + SoC. The K3 has two instances of the same block sharing one compatible; + each acts as embedded or external DisplayPort depending on whether its + output port drives a panel or a connector. + +properties: + compatible: + const: spacemit,k3-inno-dp + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: Link and hot-plug events. + + clocks: + items: + - description: Pixel clock for the controller. + - description: + Pixel clock generated by the DP PHY PLL; the pixel clock above is + parented onto it in use. + + clock-names: + items: + - const: pxclk + - const: pll + + resets: + maxItems: 1 + description: Controller-wide reset signal. + + phys: + maxItems: 1 + description: Phandle to the K3 Innosilicon DP PHY. + + phy-names: + items: + - const: dp + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties:
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml line 66
Quoted 10 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +10
-0+ port@0: + $ref: /schemas/graph.yaml#/properties/port + description: Video input from the DPU. + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Output to the panel or to the DisplayPort connector. + + required: + - port@0
Shouldn't port@1 be required too?
Otherwise,
Rob
Re: [PATCH RESEND 03/17] dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller
Hi Rob,
Quoted 76 lines · Rob Herring
Quoted 75 lines · Cody Kang
Both K3 instances are the same IP and share one compatible; which one behaves as eDP is decided by what its downstream port is wired to, not by which register window it sits in, so the binding does not distinguish them.
Signed-off-by Cody Kang <[email protected]>--- .../display/spacemit/spacemit,k3-inno-dp.yaml | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+)Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +60
-0@@ -0,0 +1,140 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/spacemit/spacemit,k3-inno-dp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K3 Innosilicon DisplayPort / embedded DisplayPort Controller + +maintainers: + - Cody Kang <[email protected]> + +description: + Innosilicon DisplayPort transmit controller integrated in the SpacemiT K3 + SoC. The K3 has two instances of the same block sharing one compatible; + each acts as embedded or external DisplayPort depending on whether its + output port drives a panel or a connector. + +properties: + compatible: + const: spacemit,k3-inno-dp + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: Link and hot-plug events. + + clocks: + items: + - description: Pixel clock for the controller. + - description: + Pixel clock generated by the DP PHY PLL; the pixel clock above is + parented onto it in use. + + clock-names: + items: + - const: pxclk + - const: pll + + resets: + maxItems: 1 + description: Controller-wide reset signal. + + phys: + maxItems: 1 + description: Phandle to the K3 Innosilicon DP PHY. + + phy-names: + items: + - const: dp + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: Video input from the DPU. +
Quoted 8 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml line 66
Quoted 6 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +6
-0+ port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Output to the panel or to the DisplayPort connector. + + required: + - port@0Shouldn't port@1 be required too?
Thanks for the review. Yes, will make port@1 required in v2 and describe the DP connector on the board side (dp-connector) so the graph is complete.
Quoted 3 lines
Otherwise,
Reviewed-by Rob Herring (Arm) <[email protected]>
Thanks! Will pick up your Reviewed-by with that change in v2.
Cody
PATCH RESEND 4/17 dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU
In reply to Cody KangThe APMU's eDP pixel-clock muxes select the DP PHY PLLs as parents, so the K3 syscon takes two clock inputs the other variants do not have.
Gate them behind the K3 compatible instead of widening the shared clock list, so a non-K3 syscon cannot silently accept clocks it has no mux for.
--- .../bindings/soc/spacemit/spacemit,k1-syscon.yaml | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml +29 -1
@@ -31,14 +31,18 @@ properties: maxItems: 1 clocks: - maxItems: 4 + minItems: 4 + maxItems: 6 clock-names: + minItems: 4 items: - const: osc - const: vctcxo_1m - const: vctcxo_3m - const: vctcxo_24m + - const: edp0_pll_pxclk + - const: edp1_pll_pxclk "#clock-cells": const: 1
@@ -95,6 +99,30 @@ allOf: - clocks - clock-names - "#clock-cells" + # Only the K3 APMU exposes the two eDP/DP PHY PLL pixel clocks as extra + # inputs (parents of its eDP pixel-clock muxes); every other variant has + # the four base oscillator inputs only. + - if: + properties: + compatible: + contains: + const: spacemit,k3-syscon-apmu + then: + properties: + clocks: + minItems: 4 + maxItems: 6 + clock-names: + minItems: 4 + maxItems: 6 + else: + properties: + clocks: + minItems: 4 + maxItems: 4 + clock-names: + minItems: 4 + maxItems: 4 additionalProperties: false
Signature · 1 line
2.43.0
Rob Herring
maintainerRe: [PATCH RESEND 04/17] dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU
Quoted 54 lines · Cody Kang
The APMU's eDP pixel-clock muxes select the DP PHY PLLs as parents, so the K3 syscon takes two clock inputs the other variants do not have.
Gate them behind the K3 compatible instead of widening the shared clock list, so a non-K3 syscon cannot silently accept clocks it has no mux for.
Signed-off-by Cody Kang <[email protected]>--- .../bindings/soc/spacemit/spacemit,k1-syscon.yaml | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml +19
-1@@ -31,14 +31,18 @@ properties: maxItems: 1 clocks: - maxItems: 4 + minItems: 4 + maxItems: 6 clock-names: + minItems: 4 items: - const: osc - const: vctcxo_1m - const: vctcxo_3m - const: vctcxo_24m + - const: edp0_pll_pxclk + - const: edp1_pll_pxclk "#clock-cells": const: 1@@ -95,6 +99,30 @@ allOf: - clocks - clock-names - "#clock-cells" + # Only the K3 APMU exposes the two eDP/DP PHY PLL pixel clocks as extra + # inputs (parents of its eDP pixel-clock muxes); every other variant has + # the four base oscillator inputs only. + - if: + properties: + compatible: + contains: + const: spacemit,k3-syscon-apmu + then: + properties: + clocks: + minItems: 4 + maxItems: 6 + clock-names:
Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml allOf: · line 126
Quoted 10 lines
Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml +10
-0+ minItems: 4 + maxItems: 6 + else: + properties: + clocks: + minItems: 4 + maxItems: 4 + clock-names: + minItems: 4 + maxItems: 4
4 is already the minimum, so it can be dropped on all of these.
Rob
Re: [PATCH RESEND 04/17] dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU
Hi Rob,
Quoted 66 lines · Rob Herring
Quoted 54 lines · Cody Kang
The APMU's eDP pixel-clock muxes select the DP PHY PLLs as parents, so the K3 syscon takes two clock inputs the other variants do not have.
Gate them behind the K3 compatible instead of widening the shared clock list, so a non-K3 syscon cannot silently accept clocks it has no mux for.
Signed-off-by Cody Kang <[email protected]>--- .../bindings/soc/spacemit/spacemit,k1-syscon.yaml | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml +19
-1@@ -31,14 +31,18 @@ properties: maxItems: 1 clocks: - maxItems: 4 + minItems: 4 + maxItems: 6 clock-names: + minItems: 4 items: - const: osc - const: vctcxo_1m - const: vctcxo_3m - const: vctcxo_24m + - const: edp0_pll_pxclk + - const: edp1_pll_pxclk "#clock-cells": const: 1@@ -95,6 +99,30 @@ allOf: - clocks - clock-names - "#clock-cells" + # Only the K3 APMU exposes the two eDP/DP PHY PLL pixel clocks as extra + # inputs (parents of its eDP pixel-clock muxes); every other variant has + # the four base oscillator inputs only. + - if: + properties: + compatible: + contains: + const: spacemit,k3-syscon-apmu + then: + properties: + clocks: + minItems: 4 + maxItems: 6 + clock-names:Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml allOf: · line 126
Quoted 10 lines
Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml +10
-0+ minItems: 4 + maxItems: 6 + else: + properties: + clocks: + minItems: 4 + maxItems: 4 + clock-names: + minItems: 4 + maxItems: 4
Quoted 1 line
4 is already the minimum, so it can be dropped on all of these.
Thanks for the review. Will drop them in v2.
Cody
PATCH RESEND 5/17 phy: spacemit: add Innosilicon DP TX PHY driver
In reply to Cody KangThe PHY's registers are interleaved into its parent DP controller's MMIO window rather than a window of its own, so it probes as a child of the controller, carries no reg or reset, and reaches its registers through the controller's regmap.
It registers its pixel PLL as a clock provider. That lets the display controller ask for a mode's pixel rate through clk_set_rate(), and it lets the APMU pixel-clock mux parent to the PHY through the clock framework. Without it the controller and PHY would have to know each other's registers.
--- drivers/phy/spacemit/Kconfig | 13 + drivers/phy/spacemit/Makefile | 1 + drivers/phy/spacemit/phy-k3-inno-dp.c | 948 ++++++++++++++++++++++++++++++++++ 3 files changed, 962 insertions(+)
drivers/phy/spacemit/Kconfig +13 -0
@@ -23,3 +23,16 @@ config PHY_SPACEMIT_K1_USB2 help Enable this to support K1 USB 2.0 PHY driver. This driver takes care of enabling and clock setup and will be used by K1 udc/ehci/otg/xhci driver. + +config PHY_SPACEMIT_K3_INNO_DP + tristate "SpacemiT K3 Innosilicon DisplayPort PHY driver" + depends on (ARCH_SPACEMIT || COMPILE_TEST) && OF + depends on COMMON_CLK + select GENERIC_PHY + select REGMAP + help + Enable support for the Innosilicon DisplayPort transmit PHY + integrated in the SpacemiT K3 SoC. The PHY shares its MMIO window + with its parent DP/eDP controller (drivers/gpu/drm/spacemit/) and + exposes lane / rate / vswing / pre-emphasis control through the + generic PHY framework.
drivers/phy/spacemit/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_PHY_SPACEMIT_K1_PCIE) += phy-k1-pcie.o obj-$(CONFIG_PHY_SPACEMIT_K1_USB2) += phy-k1-usb2.o +obj-$(CONFIG_PHY_SPACEMIT_K3_INNO_DP) += phy-k3-inno-dp.o
drivers/phy/spacemit/phy-k3-inno-dp.c new file +948 -0
948 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 05/17] phy: spacemit: add Innosilicon DP TX PHY driver
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] PHY provider is registered before probe finishes, exposing it to early concurrent access and…
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] PHY provider is registered before probe finishes, exposing it to early concurrent access and potential Use-After-Free (UAF) on probe failure.
- [High] Lack of driver-level synchronization between CCF and PHY frameworks leads to concurrent hardware state corruption.
- [Medium] The MPLL (main link PLL) is powered on during PHY initialization but is never powered off in the power down sequence.
- [Medium] Missing hardware state cleanup on error paths in k3_inno_dp_phy_power_on leaves the PHY powered on.
- [Medium] Rate configuration functions unconditionally power on the PLLs, overriding the logical PHY power state.
- [Medium] PLL programming functions do not poll for hardware lock before proceeding.
--
--- Patch [5]: [PATCH RESEND 05/17] phy: spacemit: add Innosilicon DP TX PHY driver --- commit 31db74eae7dc59ddc61373dbe3e2c6c1e6966ccd
Author: Cody Kang <[email protected]>
Subject: phy: spacemit: add Innosilicon DP TX PHY driver
This commit introduces the SpacemiT K3 Innosilicon DisplayPort PHY driver. It integrates the PHY as a child of the DP controller, registering a PHY provider and exposing the pixel PLL as a clock provider.
Quoted 6 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +0
-0@@ -0,0 +1,948 @@
[ ... ]
Quoted 6 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +6
-0+static int k3_inno_dp_phy_power_on (struct phy *phy) +{ +struct k3_inno_dp_phy *p =phy_get_drvdata (phy); +u32 lane_en; +u32 val; +int ret;
[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 144
Quoted 7 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +7
-0+ ret =regmap_read_poll_timeout (p->regmap,DPTX_ANA_MPLL , val, + val &DPTX_ANA_MPLL_LOCKED , +2000 ,10 *1000 ); +if (ret) { +dev_err (p->dev,"DP PHY core PLL lock timed out\n" ); +return ret; + }
[Severity: Medium]
If the MPLL or PREPLL fails to lock within 10ms, this immediately returns an error without restoring the power down bits or XMIT_EN.
Since the generic PHY framework does not automatically call phy_power_off() when phy_power_on() fails, could this leave the hardware running in an inconsistent state and leak power?
Quoted 13 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +13
-0+ + ret =regmap_read_poll_timeout (p->regmap,DPTX_ANA_PREPLL , val, + val &DPTX_ANA_PREPLL_LOCKED , +2000 ,10 *1000 ); +if (ret) +dev_err (p->dev,"DP PHY pixel PLL lock timed out\n" ); + +return ret; +} + +static int k3_inno_dp_phy_power_off (struct phy *phy) +{ +struct k3_inno_dp_phy *p =phy_get_drvdata (phy);
drivers/phy/spacemit/phy-k3-inno-dp.c line 167
Quoted 10 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +10
-0+ +regmap_write_bits (p->regmap,DPTX_PHY_CTRL ,DPTX_PHY_CTRL_XMIT_EN ,0 ); +usleep_range (2000 ,4000 ); + +regmap_write_bits (p->regmap,DPTX_ANA_PREPLL ,DPTX_ANA_PREPLL_PD , +DPTX_ANA_PREPLL_PD ); +usleep_range (2000 ,4000 ); + +return 0 ; +}
[Severity: Medium]
Does this power down sequence omit the MPLL?
The k3_inno_dp_phy_power_on() function powers up the MPLL by clearing DPTX_ANA_MPLL_PD, but this power_off function does not appear to re-assert it. Could this leave the main link PLL running indefinitely when the DP controller is suspended or torn down?
[ ... ]
Quoted 4 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +4
-0+static void k3_inno_dp_phy_program_mpll (struct k3_inno_dp_phy *p, +const struct k3_inno_dp_mpll_cfg *cfg) +{ +struct regmap *rm = p->regmap;
[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 293
Quoted 5 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +5
-0+regmap_write_bits (rm,DPTX_ANA_PREPLL_CTRL ,DPTX_ANA_PREPLL_LOCK_BYPEN , +FIELD_PREP (DPTX_ANA_PREPLL_LOCK_BYPEN ,1 )); + +regmap_write_bits (rm,DPTX_ANA_MPLL ,DPTX_ANA_MPLL_PD , +FIELD_PREP (DPTX_ANA_MPLL_PD ,0 ));
[Severity: Medium]
Does unconditionally writing 0 to DPTX_ANA_MPLL_PD override the logical power state of the PHY?
If a DRM driver configures the link rate (calling phy_configure()) while the PHY is logically powered off, this will force the PLL to run and desynchronize the hardware from the PHY framework's power state.
drivers/phy/spacemit/phy-k3-inno-dp.c
Quoted 2 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +2
-0+usleep_range (2000 ,4000 ); +}
[Severity: Medium]
Is it safe to rely on a fixed 2-4ms sleep here instead of polling DPTX_ANA_MPLL_LOCKED?
The power_on() function polls the locked bit for up to 10ms. A fixed delay here might proceed with an unstable clock if the hardware takes longer to lock, potentially causing display failures or link training issues.
[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 749
Quoted 6 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +6
-0+static void k3_inno_dp_program_prepll (struct k3_inno_dp_phy *p, +const struct k3_inno_dp_prepll_cfg *cfg) +{ +regmap_write_bits (p->regmap,DPTX_ANA_PREPLL ,DPTX_ANA_PREPLL_PD , +FIELD_PREP (DPTX_ANA_PREPLL_PD ,1 )); +usleep_range (2000 ,4000 );
[Severity: High]
Is a driver-level lock needed to synchronize access to the PHY registers between the CCF and PHY frameworks?
Since this driver exposes both a clock (via CCF) and a PHY that share the same hardware registers, concurrent calls to clk_set_rate() and phy_power_on() can interleave.
If clk_set_rate() begins this multi-step programming sequence, a concurrent phy_power_on() could clear the PD bit while the clock is still being configured, corrupting the hardware state.
[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 796
Quoted 7 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +7
-0+regmap_write_bits (p->regmap,DPTX_ANA_PREPLL , +DPTX_ANA_PREPLL_PCLK_NORMAL , +FIELD_PREP (DPTX_ANA_PREPLL_PCLK_NORMAL ,1 )); +usleep_range (2000 ,4000 ); + +regmap_write_bits (p->regmap,DPTX_ANA_PREPLL ,DPTX_ANA_PREPLL_PD , +FIELD_PREP (DPTX_ANA_PREPLL_PD ,0 ));
[Severity: Medium]
Similar to the MPLL configuration, does unconditionally clearing DPTX_ANA_PREPLL_PD here override the PHY power state if the clock rate is set while the PHY is logically off?
drivers/phy/spacemit/phy-k3-inno-dp.c
Quoted 2 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +2
-0+usleep_range (2000 ,4000 ); +}
[Severity: Medium]
Is it safe to rely on a fixed delay here instead of polling the DPTX_ANA_PREPLL_LOCKED bit, which could lead to proceeding with an unstable pixel clock?
[ ... ]
Quoted 7 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +7
-0+static int k3_inno_dp_phy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct k3_inno_dp_phy *p; +struct phy_provider *provider; +struct clk_init_data init = {}; +int ret;
[ ... ]
Quoted 12 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +12
-0+ provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); +if (IS_ERR (provider)) +return dev_err_probe (dev,PTR_ERR (provider), +"failed to register PHY provider\n" ); + +/* PHY takes a 24 MHz reference clock */ + p->ref_clk_khz =24000 ; + +/* The APMU pixel-clock mux references this clock by name. */ +of_property_read_string (dev->of_node,"clock-output-names" , &init.name); +if (!init.name) + init.name =dev_name (dev);
drivers/phy/spacemit/phy-k3-inno-dp.c line 920
Quoted 10 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +10
-0+ init.ops = &k3_inno_dp_pxclk_ops; + init.parent_names =NULL ; + init.num_parents =0 ; + init.flags =0 ; + p->pxclk_hw.init = &init; + + ret =devm_clk_hw_register (dev, &p->pxclk_hw); +if (ret) +return dev_err_probe (dev, ret, +"failed to register pixel clock\n" );
[Severity: High]
Can the PHY provider be accessed by consumers before probe completes successfully?
The PHY provider is registered via devm_of_phy_provider_register() before the pixel clock is registered. If devm_clk_hw_register() fails, probe will return an error and devres will free the driver context struct.
If a consumer driver acquires a reference to the PHY during this race window, it could retain the reference after probe fails, leading to a use-after-free when it attempts PHY operations on the freed pointer.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH RESEND 05/17] phy: spacemit: add Innosilicon DP TX PHY driver
Quoted 48 lines · On Sat, Jul 25, 2026 at 05:02:54AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] PHY provider is registered before probe finishes, exposing it to early concurrent access and potential Use-After-Free (UAF) on probe failure.
- [High] Lack of driver-level synchronization between CCF and PHY frameworks leads to concurrent hardware state corruption.
- [Medium] The MPLL (main link PLL) is powered on during PHY initialization but is never powered off in the power down sequence.
- [Medium] Missing hardware state cleanup on error paths ink3_inno_dp_phy_power_onleaves the PHY powered on.
- [Medium] Rate configuration functions unconditionally power on the PLLs, overriding the logical PHY power state.
- [Medium] PLL programming functions do not poll for hardware lock before proceeding.
----- Patch [5]: [PATCH RESEND 05/17] phy: spacemit: add Innosilicon DP TX PHY driver --- commit
31db74eae7dc59ddc61373dbe3e2c6c1e6966ccd
Author: Cody Kang <[email protected]>
Subject: phy: spacemit: add Innosilicon DP TX PHY driverThis commit introduces the SpacemiT K3 Innosilicon DisplayPort PHY driver. It integrates the PHY as a child of the DP controller, registering a PHY provider and exposing the pixel PLL as a clock provider.
Quoted 6 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +0
-0@@ -0,0 +1,948 @@[ ... ]
Quoted 6 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +6
-0+static int k3_inno_dp_phy_power_on (struct phy *phy) +{ +struct k3_inno_dp_phy *p =phy_get_drvdata (phy); +u32 lane_en; +u32 val; +int ret;[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 144
Quoted 7 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +7
-0+ ret =regmap_read_poll_timeout (p->regmap,DPTX_ANA_MPLL , val, + val &DPTX_ANA_MPLL_LOCKED , +2000 ,10 *1000 ); +if (ret) { +dev_err (p->dev,"DP PHY core PLL lock timed out\n" ); +return ret; + }[Severity: Medium]
If the MPLL or PREPLL fails to lock within 10ms, this immediately returns an error without restoring the power down bits orXMIT_EN.
Quoted 3 lines
Since the generic PHY framework does not automatically call
phy_power_off()whenphy_power_on()fails, could this leave the hardware running in an inconsistent state and leak power?
Real; will fix in v2: the lock-timeout paths will park the lanes and the pixel PLL, the same set power_off parks.
Quoted 28 lines
Quoted 14 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +13
-0+ + ret =regmap_read_poll_timeout (p->regmap,DPTX_ANA_PREPLL , val, + val &DPTX_ANA_PREPLL_LOCKED , +2000 ,10 *1000 ); +if (ret) +dev_err (p->dev,"DP PHY pixel PLL lock timed out\n" ); + +return ret; +} + +static int k3_inno_dp_phy_power_off (struct phy *phy) +{ +struct k3_inno_dp_phy *p =phy_get_drvdata (phy);drivers/phy/spacemit/phy-k3-inno-dp.c line 167
Quoted 10 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +10
-0+ +regmap_write_bits (p->regmap,DPTX_PHY_CTRL ,DPTX_PHY_CTRL_XMIT_EN ,0 ); +usleep_range (2000 ,4000 ); + +regmap_write_bits (p->regmap,DPTX_ANA_PREPLL ,DPTX_ANA_PREPLL_PD , +DPTX_ANA_PREPLL_PD ); +usleep_range (2000 ,4000 ); + +return 0 ; +}[Severity: Medium]
Does this power down sequence omit the MPLL?
Quoted 4 lines
The
k3_inno_dp_phy_power_on()function powers up the MPLL by clearingDPTX_ANA_MPLL_PD, but thispower_offfunction does not appear to re-assert it. Could this leave the main link PLL running indefinitely when the DP controller is suspended or torn down?
Intentional, and it took a board round to prove it: the MPLL also feeds the 16 MHz AUX reference, and the controller parks the PHY through power_off on every link drop while AUX still has to serve EDID, DPCD and panel detection. Parking the MPLL here kills AUX from bind onward. Will add a comment in v2 saying so.
Quoted 20 lines
[ ... ]
Quoted 4 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +4
-0+static void k3_inno_dp_phy_program_mpll (struct k3_inno_dp_phy *p, +const struct k3_inno_dp_mpll_cfg *cfg) +{ +struct regmap *rm = p->regmap;[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 293
Quoted 5 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +5
-0+regmap_write_bits (rm,DPTX_ANA_PREPLL_CTRL ,DPTX_ANA_PREPLL_LOCK_BYPEN , +FIELD_PREP (DPTX_ANA_PREPLL_LOCK_BYPEN ,1 )); + +regmap_write_bits (rm,DPTX_ANA_MPLL ,DPTX_ANA_MPLL_PD , +FIELD_PREP (DPTX_ANA_MPLL_PD ,0 ));[Severity: Medium]
Does unconditionally writing 0 toDPTX_ANA_MPLL_PDoverride the logical power state of the PHY?
Quoted 3 lines
If a DRM driver configures the link rate (calling
phy_configure()) while the PHY is logically powered off, this will force the PLL to run and desynchronize the hardware from the PHY framework's power state.
Not reachable: the PHY has a single consumer, the parent DP controller, and it only configures rates from the enable path, never while the PHY is logically off.
Quoted 11 lines
drivers/phy/spacemit/phy-k3-inno-dp.c
Quoted 3 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +2
-0+usleep_range (2000 ,4000 ); +}[Severity: Medium]
Is it safe to rely on a fixed 2-4ms sleep here instead of pollingDPTX_ANA_MPLL_LOCKED?The
power_on()function polls the locked bit for up to 10ms. A fixed delay here might proceed with an unstable clock if the hardware takes longer to lock, potentially causing display failures or link training issues.
power_on polls both PLL lock bits after programming; that is the lock gate for the whole bring-up sequence.
Quoted 14 lines
[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 749
Quoted 6 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +6
-0+static void k3_inno_dp_program_prepll (struct k3_inno_dp_phy *p, +const struct k3_inno_dp_prepll_cfg *cfg) +{ +regmap_write_bits (p->regmap,DPTX_ANA_PREPLL ,DPTX_ANA_PREPLL_PD , +FIELD_PREP (DPTX_ANA_PREPLL_PD ,1 )); +usleep_range (2000 ,4000 );[Severity: High]
Is a driver-level lock needed to synchronize access to the PHY registers between the CCF and PHY frameworks?
Quoted 7 lines
Since this driver exposes both a clock (via CCF) and a PHY that share the same hardware registers, concurrent calls to
clk_set_rate()andphy_power_on()can interleave.If
clk_set_rate()begins this multi-step programming sequence, a concurrentphy_power_on()could clear the PD bit while the clock is still being configured, corrupting the hardware state.
No concurrent callers exist: the single consumer serializes all clk_set_rate() and phy_power_on/off() calls through its own modeset path.
Quoted 15 lines
[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 796
Quoted 7 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +7
-0+regmap_write_bits (p->regmap,DPTX_ANA_PREPLL , +DPTX_ANA_PREPLL_PCLK_NORMAL , +FIELD_PREP (DPTX_ANA_PREPLL_PCLK_NORMAL ,1 )); +usleep_range (2000 ,4000 ); + +regmap_write_bits (p->regmap,DPTX_ANA_PREPLL ,DPTX_ANA_PREPLL_PD , +FIELD_PREP (DPTX_ANA_PREPLL_PD ,0 ));[Severity: Medium]
Similar to the MPLL configuration, does unconditionally clearingDPTX_ANA_PREPLL_PDhere override the PHY power state if the clock rate is set while the PHY is logically off?
Same as the MPLL case above: rates are only set from the enable path.
Quoted 8 lines
drivers/phy/spacemit/phy-k3-inno-dp.c
Quoted 3 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +2
-0+usleep_range (2000 ,4000 ); +}[Severity: Medium]
Is it safe to rely on a fixed delay here instead of polling theDPTX_ANA_PREPLL_LOCKEDbit, which could lead to proceeding with an unstable pixel clock?
Same: power_on polls DPTX_ANA_PREPLL_LOCKED before the sequence completes.
Quoted 40 lines
[ ... ]
Quoted 7 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +7
-0+static int k3_inno_dp_phy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct k3_inno_dp_phy *p; +struct phy_provider *provider; +struct clk_init_data init = {}; +int ret;[ ... ]
Quoted 12 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +12
-0+ provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); +if (IS_ERR (provider)) +return dev_err_probe (dev,PTR_ERR (provider), +"failed to register PHY provider\n" ); + +/* PHY takes a 24 MHz reference clock */ + p->ref_clk_khz =24000 ; + +/* The APMU pixel-clock mux references this clock by name. */ +of_property_read_string (dev->of_node,"clock-output-names" , &init.name); +if (!init.name) + init.name =dev_name (dev);drivers/phy/spacemit/phy-k3-inno-dp.c line 920
Quoted 10 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +10
-0+ init.ops = &k3_inno_dp_pxclk_ops; + init.parent_names =NULL ; + init.num_parents =0 ; + init.flags =0 ; + p->pxclk_hw.init = &init; + + ret =devm_clk_hw_register (dev, &p->pxclk_hw); +if (ret) +return dev_err_probe (dev, ret, +"failed to register pixel clock\n" );[Severity: High]
Can the PHY provider be accessed by consumers before probe completes successfully?
Quoted 7 lines
The PHY provider is registered via
devm_of_phy_provider_register()before the pixel clock is registered. Ifdevm_clk_hw_register()fails, probe will return an error and devres will free the driver context struct.If a consumer driver acquires a reference to the PHY during this race window, it could retain the reference after probe fails, leading to a use-after-free when it attempts PHY operations on the freed pointer.
Taken: will register the PHY and clock providers last in probe in v2.
Cody
Re: [PATCH RESEND 05/17] phy: spacemit: add Innosilicon DP TX PHY driver
In reply to Cody KangHello,
drivers/phy/spacemit/phy-k3-inno-dp.c line 18
Quoted 3 lines · On Sat, Jul 25, 2026 at 12:51:14AM -0400, Cody Kang via B4 Relay wrote:
drivers/phy/spacemit/phy-k3-inno-dp.c new file +2
-0+#include <linux/mod_devicetable.h> +#include <linux/platform_device.h>
<linux/platform_device.h> already makes sure that of_device_id is available and <linux/mod_devicetable.h> will go away soon.
So please drop the latter #include.
Best regards
Uwe
Re: [PATCH RESEND 05/17] phy: spacemit: add Innosilicon DP TX PHY driver
Hi Uwe,
Quoted 11 lines · Uwe Kleine-König
Hello,
drivers/phy/spacemit/phy-k3-inno-dp.c line 18
Quoted 3 lines · On Sat, Jul 25, 2026 at 12:51:14AM -0400, Cody Kang via B4 Relay wrote:
drivers/phy/spacemit/phy-k3-inno-dp.c new file +2
-0+#include <linux/mod_devicetable.h> +#include <linux/platform_device.h> <
linux/platform_device.h> already makes sure thatof_device_idis available and <linux/mod_devicetable.h> will go away soon.So please drop the latter #include.
Thanks for the review. Will do in v2.
Cody
PATCH RESEND 6/17 clk: spacemit: k3: parent eDP/DP pixel clock to the PHY PLL
In reply to Cody KangThe APMU eDP/DP pixel-clock muxes were parented to a placeholder, because their real parents (the DP PHY PLLs) did not exist as clocks yet. They do now, so point each mux at its PLL and let the pixel clock reach the controller through the clock framework.
--- drivers/clk/spacemit/ccu-k3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/spacemit/ccu-k3.c +2 -2
@@ -937,13 +937,13 @@ CCU_MUX_DIV_GATE_FC_DEFINE(ufs_aclk, ufs_aclk_parents, APMU_UFS_CLK_RES_CTRL, 5,static const struct clk_parent_data edp0_pclk_parents[] = {CCU_PARENT_HW (lcd_pxclk), -CCU_PARENT_NAME (external_clk), +CCU_PARENT_NAME (edp0_pll_pxclk), };CCU_MUX_GATE_DEFINE (edp0_pxclk, edp0_pclk_parents,APMU_LCD_EDP_CTRL ,2 ,1 ,BIT (1 ),0 );static const struct clk_parent_data edp1_pclk_parents[] = {CCU_PARENT_HW (dsi4ln2_lcd_pxclk), -CCU_PARENT_NAME (external_clk), +CCU_PARENT_NAME (edp1_pll_pxclk), };CCU_MUX_GATE_DEFINE (edp1_pxclk, edp1_pclk_parents,APMU_LCD_EDP_CTRL ,18 ,1 ,BIT (17 ),0 );
Signature · 1 line
2.43.0
PATCH RESEND 7/17 drm/spacemit: add Saturn DPU register model
In reply to Cody KangThe Saturn display processing unit is programmed through a set of register blocks (composer, RDMA, timing generator, cmdlist engine, display MMU) laid out identically in both SoC instances. Add the block address map, the per-field word offset and mask tables consumed by the field accessors, the interrupt bit layout and the compositor and output-format ID encodings. The address map describes the whole IP block on purpose, including blocks the driver does not touch; the field tables carry the fields the driver programs, with each block's full word count kept as its NWORDS extent.
Consumers arrive with the following patches; the driver only becomes buildable once the final patch adds the Kconfig and Makefile glue.
--- drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h | 25 ++ .../gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h | 64 +++++ .../drm/spacemit/dpu/saturn_regs/saturn_fields.h | 298 +++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_dpu_ids.h | 22 ++ 4 files changed, 409 insertions(+)
drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +* +*/ + +#ifndef DPU_INT_REG_H +#define DPU_INT_REG_H + +#include <linux/bits.h> + +#define DPU_INT_CMDLIST_CH_FRM_CFG_DONE_MASK (0xff) +#define DPU_INT_CMDLIST_CH_FRM_CFG_DONE (DPU_INT_CMDLIST_CH_FRM_CFG_DONE_MASK << 11) +#define DPU_INT_FRM_TIMING_UNFLOW BIT(8) +#define DPU_INT_CFG_RDY_CLR BIT(5) +#define DPU_INT_FRM_TIMING_CFG_LINE BIT(4) +#define DPU_INT_FRM_TIMING_CFG_EOF (BIT(2) | BIT(3)) +#define DPU_INT_FRM_TIMING_EOF BIT(1) +#define DPU_INT_FRM_TIMING_VSYNC BIT(0) +#define DPU_REST_INT_BITS (DPU_INT_FRM_TIMING_CFG_EOF | \ + DPU_INT_FRM_TIMING_CFG_LINE | \ + DPU_INT_FRM_TIMING_EOF | \ + DPU_INT_CMDLIST_CH_FRM_CFG_DONE) + +#endif
drivers/gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h new file +64 -0
64 lines not on this page · raw message
drivers/gpu/drm/spacemit/dpu/saturn_regs/saturn_fields.h new file +298 -0
298 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_dpu_ids.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +*/ + +#ifndef _SPACEMIT_DPU_IDS_H_ +#define _SPACEMIT_DPU_IDS_H_ + +/* Saturn online compositor instance ids (hardware IRQ-table indices). */ +#define COMPOSER0 0 +#define COMPOSER1 1 +#define COMPOSER2 2 +#define COMPOSER3 3 + +/* DPU output-format field encoding (dpuctrl out-format register). */ +#define OUTFMT_RGB121212 0 +#define OUTFMT_RGB101010 1 +#define OUTFMT_RGB888 2 +#define OUTFMT_RGB666 12 +#define OUTFMT_RGB565 13 + +#endif /* _SPACEMIT_DPU_IDS_H_ */
Signature · 1 line
2.43.0
PATCH RESEND 8/17 drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
In reply to Cody KangRegister programming of the Saturn DPU is batched: the driver builds per-module register lists in memory and the hardware command-list engine replays them at frame boundaries, while scanout buffers are mapped through the DPU's private address translation unit (DMMU) rather than scanned out by physical address.
Add the shared driver types, the MMIO field accessors, the trace events, the command-list builder and the DMMU table code. Some DPU configuration registers are write-only, so a read-modify-write would corrupt neighbouring fields; byte- and halfword-aligned fields are therefore written at their native width instead.
--- drivers/gpu/drm/spacemit/dpu/dpu_saturn.h | 35 +++ drivers/gpu/drm/spacemit/dpu/dpu_trace.h | 350 ++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.c | 304 ++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.h | 146 ++++++++++++ drivers/gpu/drm/spacemit/spacemit_crtc.h | 259 ++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.c | 103 ++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.h | 40 ++++ drivers/gpu/drm/spacemit/spacemit_dpu_reg.h | 108 +++++++++ drivers/gpu/drm/spacemit/spacemit_drm.h | 68 ++++++ 9 files changed, 1413 insertions(+)
drivers/gpu/drm/spacemit/dpu/dpu_saturn.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +* +*/ + +#ifndef _DPU_SATURN_H_ +#define _DPU_SATURN_H_ + +#include "../spacemit_crtc.h" + +struct dpu_format_id { +u32 format;/* DRM fourcc */ +u8 id; +u8 bpp;/* bits per pixel */ +}; + +#define SPACEMIT_DPU_INVALID_FORMAT_ID 0xff + +enum format_features { +FORMAT_RGB =BIT (0 ), +}; + +struct spacemit_hw_rdma { +u16 formats; +}; + +int dpu_parse_clocks (struct device *dev,struct dpu_clk_context *clk_ctx); +u8 spacemit_plane_hw_get_format_id (u32 format); +u32 saturn_conf_dpuctrl_rdma (struct spacemit_crtc *a_crtc); +extern const struct spacemit_hw_device k3_saturn_dpu; +void saturn_enable_irq_mask (struct spacemit_crtc *a_crtc,bool enable, +u32 offset,u32 mask); +void spacemit_cfg_rdy_timer_handler (struct timer_list *t); +#endif
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +350 -0
350 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +304 -0
304 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +146 -0
146 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_crtc.h new file +259 -0
259 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +103 -0
103 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_dmmu.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +* +*/ + +#ifndef _SPACEMIT_DMMU_H_ +#define _SPACEMIT_DMMU_H_ + +#include <linux/types.h> + +#include <drm/drm_file.h> +#include "spacemit_cmdlist.h" + +#define DPU_QOS_URGENT 4 +#define DPU_QOS_NORMAL 3 +#define DPU_QOS_LOW 2 +/* Worst-case TLB alignment over-fetch at the maximum 4096 src_x. */ +#define HW_ALIGN_TTB_NUM 60 + +#define RD_OUTS_NUM 16 +#define RDMA_TIMELIMIT 0xFFFF + +#define BASE_VA 0x10000000ULL +#define VA_STEP_PER_TBU 0x40000000ULL + +#define TBU_BASE_VA (tbu_id) ((u64)BASE_VA + (u64)VA_STEP_PER_TBU * (tbu_id)) + +struct tbu_instance { +u64 ttb_pa[3 ]; +u64 tbu_va[3 ]; +u32 ttb_size[3 ]; +}; + +struct dpu_mmu_tbl ; +int spacemit_dmmu_map (struct drm_framebuffer *fb,struct dpu_mmu_tbl *mmu_tbl, +u8 tbu_id,struct cmdlist_regs *cl_rdma, +struct drm_plane *plane); + +#endif /* _SPACEMIT_DMMU_H_ */
drivers/gpu/drm/spacemit/spacemit_dpu_reg.h new file +108 -0
108 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_drm.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 08/17] drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider: - [Critical] DMMU page table size calculation underflow allows arbitrary physical memory access.…
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider:
- [Critical] DMMU page table size calculation underflow allows arbitrary physical memory access.
- [Critical] Shallow copy of DMA buffers in atomic state causes active display corruption.
- [High] crtc_cmdlist_atomic_commit() passes a guaranteed NULL pointer to the hardware command list execution callback.
- [High] Global cmdlist_groups array causes data races across concurrent atomic commits.
- [High] Unconditional dereference of first_cl in cmdlist_atomic_commit() causes a kernel panic if the command list group is empty.
- [High] DMMU maps only the first GEM object, breaking multi-planar framebuffers.
- [High] NULL pointer dereference in dpu_plane_info tracepoint.
- [High] Sleeping in atomic context via drm_gem_shmem_get_pages_sgt().
- [High] Missing bounds check on nod_len causes DMA buffer overflow.
- [Medium] Unaligned base virtual addresses are used for DMMU translation regions.
- [Medium] Memory leak of DMA buffers upon atomic state destruction.
- [Medium] Speculative array out-of-bounds access in cmdlist_sort_by_group().
--
--- Patch [8]: [PATCH RESEND 08/17] drm/spacemit: add Saturn DPU core types, cmdlist and display MMU --- commit dc983d68951c3577447bb897e17c833e557da908
Author: Cody Kang <[email protected]>
drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
This commit introduces the shared driver types, MMIO accessors, trace events, command-list builder, and DMMU table code for the Saturn DPU. It enables batched register programming by building per-module register lists in memory, which the hardware command-list engine replays.
Quoted 4 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +0
-0
[ ... ]
Quoted 25 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +25
-0+TRACE_EVENT(dpu_plane_info, + TP_PROTO(struct drm_plane_state *state, struct drm_framebuffer *fb, + u32 rdma_id, u32 alpha, u32 rotation), + TP_ARGS(state, fb, rdma_id, alpha, rotation), + TP_STRUCT__entry( + __field(u32, rdma_id) + __field(u32, src_w) + __field(u32, src_h) + __field(u32, src_x) + __field(u32, src_y) + __field(u32, crtc_w) + __field(u32, crtc_h) + __field(u32, crtc_x) + __field(u32, crtc_y) + __field(u32, width) + __field(u32, height) + __field(u32, format) + __field(u32, blend_mode) + __field(u32, alpha) + __field(u32, zpos) + __field(u32, rotation) + ), + TP_fast_assign( + __entry->rdma_id = rdma_id; + __entry->src_w = state->src_w >> 16;
drivers/gpu/drm/spacemit/dpu/dpu_trace.h line 82
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +10
-0+ __entry->src_h = state->src_h >>16 ; + __entry->src_x = state->src_x >>16 ; + __entry->src_y = state->src_y >>16 ; + __entry->crtc_w = state->crtc_w; + __entry->crtc_h = state->crtc_h; + __entry->crtc_x = state->crtc_x; + __entry->crtc_y = state->crtc_y; + __entry->width = fb->width; + __entry->height = fb->height; + __entry->format = fb->format->format;
[Severity: High]
Can this dereference a NULL pointer? When a plane is disabled during an atomic commit, state->fb might be NULL. Unconditionally reading fb->width here could cause a kernel panic if tracing is enabled.
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +5
-0+ __entry->blend_mode = state->pixel_blend_mode; + __entry->alpha = alpha; + __entry->zpos = state->zpos; + __entry->rotation = rotation; + ),
[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +3
-0+void cmdlist_regs_packing (struct cmdlist *cl,enum cmdlist_mode_type mod, +struct cmdlist_regs *cl_regs) +{
[ ... ]
Quoted 16 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +16
-0+for (i =0 ; i < cl_regs->size;) { +u32 value[CMDLIST_ROW_REGS ] = {0x0 }; +u32 offset, strobe =0 ; +u8 regs_in_row =0 ; + +if (cl_regs->flags[i]) { + offset = cl_regs->base + i *sizeof (u32); +for (u8 j =0 ; j <CMDLIST_ROW_REGS ; j++) { + index = i + j; +if (likely (index < cl_regs->size)) { +if (cl_regs->flags[index]) { + value[j] = reg_base[index]; + regs_in_row++; + strobe |=CMDLIST_REG_STROBE (j); + } + }else {
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 153
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +10
-0+break ; + } + } + hwdev->cmdlist_fill_data_row (cl, strobe, offset, value); +/* +* the row covers the whole window; a shorter stride +* would revisit covered words as duplicate rows +*/ + i +=CMDLIST_ROW_REGS ; + cl->nod_len++;
[Severity: High]
Is there a risk of overflowing the DMA command list buffer here? The loop increments cl->nod_len and writes to memory, but there doesn't seem to be a bounds check to ensure the packed rows do not exceed the allocated capacity in cl->size.
Quoted 22 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +22
-0+ }else { + i++; + } + } + +drm_dbg (a_crtc->crtc.dev,"row_num = %d\n" , cl->nod_len); +} + +void cmdlist_sort_by_group (struct drm_crtc *crtc) +{ +struct cmdlist *first_cl; +struct cmdlist *last_cl; +struct cmdlist *p; +struct cmdlist *prev; +struct drm_plane *plane; +struct spacemit_crtc_rdma *rdmas = +to_spacemit_crtc_state (crtc->state)->rdmas; +struct spacemit_drm_private *priv = crtc->dev->dev_private; + +drm_atomic_crtc_for_each_plane (plane, crtc) { +struct spacemit_plane_state *spacemit_pstate = +to_spacemit_plane_state (plane->state);
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 185
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +10
-0+u32 rdma_id = spacemit_pstate->rdma_id; + + first_cl = &spacemit_pstate->cl; +if (!first_cl->va) +continue ; + + last_cl = first_cl; + last_cl->next =NULL ; + + rdmas[rdma_id].in_use = true;
[Severity: Medium]
Could rdma_id exceed the bounds of the array? It is used directly as an index for the rdmas array without checking if it is within hwdev->rdma_nums.
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 186
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +1
-0+if (priv->cmdlist_groups[rdma_id]) {
[Severity: High]
Does modifying the global priv->cmdlist_groups array here cause data races? Since this array is stored in the shared spacemit_drm_private structure, concurrent atomic commits on multiple CRTCs might overwrite each other's command lists without locking.
Quoted 27 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +27
-0+ p = priv->cmdlist_groups[rdma_id]; + prev =NULL ; +while (p) { +if (cl_to_spacemit_pstate (p)->state.crtc_y < + spacemit_pstate->state.crtc_y) { + prev = p; + p = p->next; + }else { +break ; + } + } +if (!prev) { + priv->cmdlist_groups[rdma_id] = first_cl; + last_cl->next = p; + }else { + prev->next = first_cl; + last_cl->next = p; + } + }else { + priv->cmdlist_groups[rdma_id] = first_cl; + } + } +} + +void cmdlist_atomic_commit (struct drm_crtc *crtc, +struct drm_crtc_state *old_state) +{
[ ... ]
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +5
-0+for (i =0 ; i < hwdev->rdma_nums; i++) { +if (old_rdmas[i].in_use) + hwdev->enable_cmdlist (a_crtc, hwdev, i, false); + +if (cur_rdmas[i].in_use) {
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 241
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +10
-0+drm_dbg (crtc->dev,"cmdlist group = %d\n" , i); + cur_cl = priv->cmdlist_groups[i]; + first_cl = cur_cl; +while (cur_cl) { + hwdev->cmdlist_fill_conf_row (cur_cl, hwdev, +CMDLIST_CMP_INVALID ); +cmdlist_dump_node (cur_cl); + cur_cl = cur_cl->next; + } + chy =cl_to_spacemit_pstate (first_cl)->state.crtc_y;
[Severity: High]
Could first_cl be NULL here? If cur_rdmas[i].in_use is true but priv->cmdlist_groups[i] is empty, first_cl would be NULL. This can happen if planes are removed from the state but in_use was copied as true from the old state. The cl_to_spacemit_pstate macro would yield a negative offset from NULL, resulting in a crash.
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +11
-0+ addrl = (lower_32_bits (priv->cmdlist_groups[i]->pa) & +CMDLIST_ADDRL_ALIGN_MASK ) >>CMDLIST_ADDRL_ALIGN_BITS ; + + addrh =upper_32_bits (priv->cmdlist_groups[i]->pa); + hwdev->cfg_cmdlist (hwdev, i, chy, addrl, addrh); + hwdev->enable_cmdlist (a_crtc, hwdev, i, true); + priv->cmdlist_groups[i] =NULL ; + } + } +} +
[ ... ]
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +8
-0+void crtc_cmdlist_atomic_commit (struct spacemit_crtc *a_crtc) +{ +struct cmdlist *cur_cl; +struct drm_crtc *crtc = &a_crtc->crtc; +struct spacemit_drm_private *priv = crtc->dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; +u8 crtc_id =drm_crtc_index (crtc); +u8 dev_id = a_crtc->dev_id;
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 288
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +10
-0+ +drm_dbg (crtc->dev,"cmdlist group = %d\n" , + hwdev->rdma_nums + crtc_id); + cur_cl = priv->cmdlist_groups[hwdev->rdma_nums + crtc_id]; +while (cur_cl) { + hwdev->cmdlist_fill_conf_row (cur_cl, hwdev, dev_id); +cmdlist_dump_node (cur_cl); + cur_cl = cur_cl->next; + } + hwdev->crtc_cmdlist (cur_cl, hwdev, priv, crtc_id, dev_id);
[Severity: High]
Does this pass a guaranteed NULL pointer to the hardware callback? The while loop exhausts cur_cl to NULL, which is then immediately passed to hwdev->crtc_cmdlist. It looks like the head of the list should be passed instead.
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 295
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +7
-0+} + +/* Called from atomic_check(), where -ENOMEM is still an answer. */ +int spacemit_cmdlist_alloc (struct device *dev,struct cmdlist *cl) +{ +if (cl->va) +return 0 ;
[Severity: Critical]
Does returning early when cl->va is present cause active display corruption? Because struct cmdlist is embedded directly in the plane state, DRM's state duplication will shallow-copy cl->va. If atomic_update mutates this same virtual address while the hardware is actively reading it from the old state, it could lead to screen tearing or DPU hangs. DMA buffers for command lists generally need to be multi-buffered or allocated per-state.
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 301
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +6
-0+ + cl->size =PER_CMDLIST_SIZE ; + cl->va =dma_alloc_coherent (dev, cl->size, &cl->pa, +GFP_KERNEL | __GFP_ZERO); +if (!cl->va) +return -ENOMEM ;
[Severity: Medium]
Is there a corresponding dma_free_coherent() during state destruction? If the allocated cl->va is never freed when the atomic state is destroyed, this might cause a steady leak of DMA memory.
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +3
-0+ +return 0 ; +}
[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +0
-0
[ ... ]
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +5
-0+int spacemit_dmmu_map (struct drm_framebuffer *fb,struct dpu_mmu_tbl *mmu_tbl, +u8 tbu_id,struct cmdlist_regs *cl_rdma, +struct drm_plane *plane) +{ +struct spacemit_drm_private *priv = fb->dev->dev_private;
drivers/gpu/drm/spacemit/spacemit_dmmu.c line 62
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +10
-0+struct spacemit_hw_device *hwdev = priv->hwdev; +const struct drm_format_info *format =NULL ; +struct sg_table *sgt =NULL ; +u32 total_size, offset1, offset2; +struct tbu_instance tbu = { }; +u8 plane_num; +u32 val; + + format = fb->format; + sgt =drm_gem_shmem_get_pages_sgt (to_drm_gem_shmem_obj (fb->obj[0 ]));
[Severity: High]
Will this sleep in atomic context? This function appears to be called during hardware programming in the atomic commit phase. Calling drm_gem_shmem_get_pages_sgt allocates memory and can acquire a mutex, which is forbidden in atomic context. Buffer mapping typically needs to be deferred to the sleepable prepare_fb callback.
[Severity: High]
Does mapping only fb->obj[0] break multi-planar framebuffers? If userspace provides a multi-planar framebuffer where the planes reside in different GEM objects, extracting the SG table only for obj[0] will result in incorrect physical memory pages for the secondary planes.
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +4
-0+if (IS_ERR (sgt)) +return PTR_ERR (sgt); + + plane_num = format->num_planes;
drivers/gpu/drm/spacemit/spacemit_dmmu.c line 76
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +10
-0+ + total_size =roundup (fb->obj[0 ]->size,PAGE_SIZE ); + + offset1 = plane_num >1 ? fb->offsets[1 ] : total_size; + offset2 = plane_num >2 ? fb->offsets[2 ] : total_size; + +switch (plane_num) { +case 3 : + tbu.ttb_pa[2 ] = mmu_tbl->pa + (offset2 >>PAGE_SHIFT ) *4 ; + tbu.tbu_va[2 ] =TBU_BASE_VA (tbu_id) + offset2;
[Severity: Medium]
Could adding offset2 directly to TBU_BASE_VA result in unaligned base virtual addresses? If userspace supplies an offset that is not a multiple of PAGE_SIZE, programming an unaligned virtual address might confuse the hardware MMU.
drivers/gpu/drm/spacemit/spacemit_dmmu.c line 78
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +2
-0+ tbu.ttb_size[2 ] =PAGE_ALIGN (total_size -rounddown (offset2,PAGE_SIZE )) + >>PAGE_SHIFT ;
[Severity: Critical]
Can this size calculation underflow? If a malicious userspace client provides offset2 smaller than offset1, the unsigned subtraction offset2 - rounddown(offset1, PAGE_SIZE) will underflow to a massive positive value. This could program the DMMU with a huge translation block, allowing arbitrary out-of-bounds physical memory reads.
Quoted 14 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +14
-0+ fallthrough; +case 2 : + tbu.ttb_pa[1 ] = mmu_tbl->pa + (offset1 >>PAGE_SHIFT ) *4 ; + tbu.tbu_va[1 ] =TBU_BASE_VA (tbu_id) + offset1; + tbu.ttb_size[1 ] =PAGE_ALIGN (offset2 -rounddown (offset1,PAGE_SIZE )) >>PAGE_SHIFT ; + fallthrough; +case 1 : + tbu.ttb_pa[0 ] = mmu_tbl->pa; + tbu.tbu_va[0 ] =TBU_BASE_VA (tbu_id); + tbu.ttb_size[0 ] =PAGE_ALIGN (offset1) >>PAGE_SHIFT ; + fallthrough; +default : +break ; + }
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH RESEND 08/17] drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
Quoted 63 lines · On Sat, 25 Jul 2026 05:04:38 +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider:
- [Critical] DMMU page table size calculation underflow allows arbitrary physical memory access.
- [Critical] Shallow copy of DMA buffers in atomic state causes active display corruption.
- [High]crtc_cmdlist_atomic_commit()passes a guaranteed NULL pointer to the hardware command list execution callback.
- [High] Globalcmdlist_groupsarray causes data races across concurrent atomic commits.
- [High] Unconditional dereference offirst_clincmdlist_atomic_commit()causes a kernel panic if the command list group is empty.
- [High] DMMU maps only the first GEM object, breaking multi-planar framebuffers.
- [High] NULL pointer dereference indpu_plane_infotracepoint.
- [High] Sleeping in atomic context viadrm_gem_shmem_get_pages_sgt().
- [High] Missing bounds check onnod_lencauses DMA buffer overflow.
- [Medium] Unaligned base virtual addresses are used for DMMU translation regions.
- [Medium] Memory leak of DMA buffers upon atomic state destruction.
- [Medium] Speculative array out-of-bounds access incmdlist_sort_by_group().
----- Patch [8]: [PATCH RESEND 08/17] drm/spacemit: add Saturn DPU core types, cmdlist and display MMU --- commit
dc983d68951c3577447bb897e17c833e557da908
Author: Cody Kang <[email protected]>drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
This commit introduces the shared driver types, MMIO accessors, trace events, command-list builder, and DMMU table code for the Saturn DPU. It enables batched register programming by building per-module register lists in memory, which the hardware command-list engine replays.
Quoted 4 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +0
-0[ ... ]
Quoted 32 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +32
-0+TRACE_EVENT(dpu_plane_info, + TP_PROTO(struct drm_plane_state *state, struct drm_framebuffer *fb, + u32 rdma_id, u32 alpha, u32 rotation), + TP_ARGS(state, fb, rdma_id, alpha, rotation), + TP_STRUCT__entry( + __field(u32, rdma_id) + __field(u32, src_w) + __field(u32, src_h) + __field(u32, src_x) + __field(u32, src_y) + __field(u32, crtc_w) + __field(u32, crtc_h) + __field(u32, crtc_x) + __field(u32, crtc_y) + __field(u32, width) + __field(u32, height) + __field(u32, format) + __field(u32, blend_mode) + __field(u32, alpha) + __field(u32, zpos) + __field(u32, rotation) + ), + TP_fast_assign( + __entry->rdma_id = rdma_id; + __entry->src_w = state->src_w >> 16; + __entry->src_h = state->src_h >> 16; + __entry->src_x = state->src_x >> 16; + __entry->src_y = state->src_y >> 16; + __entry->crtc_w = state->crtc_w; + __entry->crtc_h = state->crtc_h; + __entry->crtc_x = state->crtc_x; + __entry->crtc_y = state->crtc_y;
Quoted 8 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h line 82
Quoted 3 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +3
-0+ __entry->width = fb->width; + __entry->height = fb->height; + __entry->format = fb->format->format;[Severity: High]
Can this dereference a NULL pointer? When a plane is disabled during an atomic commit,state->fbmight be NULL. Unconditionally readingfb->widthhere could cause a kernel panic if tracing is enabled.
The tracepoint's only caller passes a validated fb from an enabled plane's update path; disabled planes never reach it.
Quoted 39 lines
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/dpu_trace.h new file +5
-0+ __entry->blend_mode = state->pixel_blend_mode; + __entry->alpha = alpha; + __entry->zpos = state->zpos; + __entry->rotation = rotation; + ),[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +0
-0[ ... ]
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +3
-0+void cmdlist_regs_packing (struct cmdlist *cl,enum cmdlist_mode_type mod, +struct cmdlist_regs *cl_regs) +{[ ... ]
Quoted 24 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +24
-0+for (i =0 ; i < cl_regs->size;) { +u32 value[CMDLIST_ROW_REGS ] = {0x0 }; +u32 offset, strobe =0 ; +u8 regs_in_row =0 ; + +if (cl_regs->flags[i]) { + offset = cl_regs->base + i *sizeof (u32); +for (u8 j =0 ; j <CMDLIST_ROW_REGS ; j++) { + index = i + j; +if (likely (index < cl_regs->size)) { +if (cl_regs->flags[index]) { + value[j] = reg_base[index]; + regs_in_row++; + strobe |=CMDLIST_REG_STROBE (j); + } + }else { +break ; + } + } + hwdev->cmdlist_fill_data_row (cl, strobe, offset, value); +/* +* the row covers the whole window; a shorter stride +* would revisit covered words as duplicate rows +*/
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 153
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +2
-0+ i +=CMDLIST_ROW_REGS ; + cl->nod_len++;[Severity: High]
Is there a risk of overflowing the DMA command list buffer here? The loop incrementscl->nod_lenand writes to memory, but there doesn't seem to be a bounds check to ensure the packed rows do not exceed the allocated capacity incl->size.
Not reachable: the 4 KiB cmdlist holds 255 rows, the largest register window (146 words) packs into at most 49, and no single list carries more than a few windows. v2 I can add a WARN_ONCE guard in the row-fill helpers rather than trusting the arithmetic.
Quoted 28 lines
Quoted 28 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +28
-0+ }else { + i++; + } + } + +drm_dbg (a_crtc->crtc.dev,"row_num = %d\n" , cl->nod_len); +} + +void cmdlist_sort_by_group (struct drm_crtc *crtc) +{ +struct cmdlist *first_cl; +struct cmdlist *last_cl; +struct cmdlist *p; +struct cmdlist *prev; +struct drm_plane *plane; +struct spacemit_crtc_rdma *rdmas = +to_spacemit_crtc_state (crtc->state)->rdmas; +struct spacemit_drm_private *priv = crtc->dev->dev_private; + +drm_atomic_crtc_for_each_plane (plane, crtc) { +struct spacemit_plane_state *spacemit_pstate = +to_spacemit_plane_state (plane->state); +u32 rdma_id = spacemit_pstate->rdma_id; + + first_cl = &spacemit_pstate->cl; +if (!first_cl->va) +continue ; +
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 185
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +4
-0+ last_cl = first_cl; + last_cl->next =NULL ; + + rdmas[rdma_id].in_use = true;[Severity: Medium]
Couldrdma_idexceed the bounds of the array? It is used directly as an index for the rdmas array without checking if it is withinhwdev->rdma_nums.
rdma_id is validated against hwdev->rdma_nums in plane atomic_check before any array use.
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 186
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +1
-0+if (priv->cmdlist_groups[rdma_id]) {[Severity: High]
Does modifying the globalpriv->cmdlist_groupsarray here cause data races? Since this array is stored in the sharedspacemit_drm_privatestructure, concurrent atomic commits on multiple CRTCs might overwrite each other's command lists without locking.
There is one CRTC per DRM device in this driver; commits on a CRTC are serialized by the atomic helpers, and the group array is filled and consumed within a single commit tail.
Quoted 42 lines
Quoted 27 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +27
-0+ p = priv->cmdlist_groups[rdma_id]; + prev =NULL ; +while (p) { +if (cl_to_spacemit_pstate (p)->state.crtc_y < + spacemit_pstate->state.crtc_y) { + prev = p; + p = p->next; + }else { +break ; + } + } +if (!prev) { + priv->cmdlist_groups[rdma_id] = first_cl; + last_cl->next = p; + }else { + prev->next = first_cl; + last_cl->next = p; + } + }else { + priv->cmdlist_groups[rdma_id] = first_cl; + } + } +} + +void cmdlist_atomic_commit (struct drm_crtc *crtc, +struct drm_crtc_state *old_state) +{[ ... ]
Quoted 14 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +14
-0+for (i =0 ; i < hwdev->rdma_nums; i++) { +if (old_rdmas[i].in_use) + hwdev->enable_cmdlist (a_crtc, hwdev, i, false); + +if (cur_rdmas[i].in_use) { +drm_dbg (crtc->dev,"cmdlist group = %d\n" , i); + cur_cl = priv->cmdlist_groups[i]; + first_cl = cur_cl; +while (cur_cl) { + hwdev->cmdlist_fill_conf_row (cur_cl, hwdev, +CMDLIST_CMP_INVALID ); +cmdlist_dump_node (cur_cl); + cur_cl = cur_cl->next; + }
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 241
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +1
-0+ chy =cl_to_spacemit_pstate (first_cl)->state.crtc_y;[Severity: High]
Couldfirst_clbe NULL here? If cur_rdmas[i].in_use is true but priv->cmdlist_groups[i] is empty,first_clwould be NULL. This can happen if planes are removed from the state butin_usewas copied as true from the old state. Thecl_to_spacemit_pstatemacro would yield a negative offset from NULL, resulting in a crash.
in_use cannot be inherited: crtc duplicate_state allocates a zeroed rdmas array for every state, so it is only set by cmdlist_sort_by_group() for planes whose cmdlist exists in the same commit.
Quoted 28 lines
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +11
-0+ addrl = (lower_32_bits (priv->cmdlist_groups[i]->pa) & +CMDLIST_ADDRL_ALIGN_MASK ) >>CMDLIST_ADDRL_ALIGN_BITS ; + + addrh =upper_32_bits (priv->cmdlist_groups[i]->pa); + hwdev->cfg_cmdlist (hwdev, i, chy, addrl, addrh); + hwdev->enable_cmdlist (a_crtc, hwdev, i, true); + priv->cmdlist_groups[i] =NULL ; + } + } +} +[ ... ]
Quoted 16 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +16
-0+void crtc_cmdlist_atomic_commit (struct spacemit_crtc *a_crtc) +{ +struct cmdlist *cur_cl; +struct drm_crtc *crtc = &a_crtc->crtc; +struct spacemit_drm_private *priv = crtc->dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; +u8 crtc_id =drm_crtc_index (crtc); +u8 dev_id = a_crtc->dev_id; + +drm_dbg (crtc->dev,"cmdlist group = %d\n" , + hwdev->rdma_nums + crtc_id); + cur_cl = priv->cmdlist_groups[hwdev->rdma_nums + crtc_id]; +while (cur_cl) { + hwdev->cmdlist_fill_conf_row (cur_cl, hwdev, dev_id); +cmdlist_dump_node (cur_cl); + cur_cl = cur_cl->next;
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +2
-0+ } + hwdev->crtc_cmdlist (cur_cl, hwdev, priv, crtc_id, dev_id);[Severity: High]
Does this pass a guaranteed NULL pointer to the hardware callback? The while loop exhaustscur_clto NULL, which is then immediately passed tohwdev->crtc_cmdlist. It looks like the head of the list should be passed instead.
The callback never reads that parameter; it re-reads the group from spacemit_drm_private itself. Will drop the unused parameter in v2 so this stops reading like a bug.
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 295
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +7
-0+} + +/* Called from atomic_check(), where -ENOMEM is still an answer. */ +int spacemit_cmdlist_alloc (struct device *dev,struct cmdlist *cl) +{ +if (cl->va) +return 0 ;
Quoted 7 lines
[Severity: Critical]
Does returning early whencl->vais present cause active display corruption? Because struct cmdlist is embedded directly in the plane state, DRM's state duplication will shallow-copycl->va. Ifatomic_updatemutates this same virtual address while the hardware is actively reading it from the old state, it could lead to screen tearing or DPU hangs. DMA buffers for command lists generally need to be multi-buffered or allocated per-state.
There is no shallow copy: duplicate_state zeroes the embedded cmdlist, atomic_check allocates a fresh buffer for each new state, and destroy_state frees it.
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c line 301
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +6
-0+ + cl->size =PER_CMDLIST_SIZE ; + cl->va =dma_alloc_coherent (dev, cl->size, &cl->pa, +GFP_KERNEL | __GFP_ZERO); +if (!cl->va) +return -ENOMEM ;[Severity: Medium]
Is there a correspondingdma_free_coherent()during state destruction? If the allocatedcl->vais never freed when the atomic state is destroyed, this might cause a steady leak of DMA memory.
Yes: spacemit_plane_atomic_destroy_state() frees both the cmdlist and the DMMU table.
Quoted 23 lines
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +3
-0+ +return 0 ; +}[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +0
-0[ ... ]
Quoted 14 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +14
-0+int spacemit_dmmu_map (struct drm_framebuffer *fb,struct dpu_mmu_tbl *mmu_tbl, +u8 tbu_id,struct cmdlist_regs *cl_rdma, +struct drm_plane *plane) +{ +struct spacemit_drm_private *priv = fb->dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; +const struct drm_format_info *format =NULL ; +struct sg_table *sgt =NULL ; +u32 total_size, offset1, offset2; +struct tbu_instance tbu = { }; +u8 plane_num; +u32 val; + + format = fb->format;
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c line 62
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +1
-0+ sgt =drm_gem_shmem_get_pages_sgt (to_drm_gem_shmem_obj (fb->obj[0 ]));[Severity: High]
Will this sleep in atomic context? This function appears to be called during hardware programming in the atomic commit phase. Callingdrm_gem_shmem_get_pages_sgtallocates memory and can acquire a mutex, which is forbidden in atomic context. Buffer mapping typically needs to be deferred to the sleepableprepare_fbcallback.
This runs from plane atomic_update in the commit tail, which is process context; sleeping is allowed there.
Quoted 5 lines
[Severity: High]
Does mapping only fb->obj[0] break multi-planar framebuffers? If userspace provides a multi-planar framebuffer where the planes reside in different GEM objects, extracting the SG table only for obj[0] will result in incorrect physical memory pages for the secondary planes.
Every advertised format is single-planar, so the two- and three-plane arms cannot execute; will drop them in v2 rather than harden dead code.
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +12
-0+if (IS_ERR (sgt)) +return PTR_ERR (sgt); + + plane_num = format->num_planes; + + total_size =roundup (fb->obj[0 ]->size,PAGE_SIZE ); + + offset1 = plane_num >1 ? fb->offsets[1 ] : total_size; + offset2 = plane_num >2 ? fb->offsets[2 ] : total_size; + +switch (plane_num) { +case 3 :
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c line 76
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +2
-0+ tbu.ttb_pa[2 ] = mmu_tbl->pa + (offset2 >>PAGE_SHIFT ) *4 ; + tbu.tbu_va[2 ] =TBU_BASE_VA (tbu_id) + offset2;[Severity: Medium]
Could adding offset2 directly toTBU_BASE_VAresult in unaligned base virtual addresses? If userspace supplies an offset that is not a multiple ofPAGE_SIZE, programming an unaligned virtual address might confuse the hardware MMU.
Unreachable for the same reason: single-planar formats only.
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c line 78
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +2
-0+ tbu.ttb_size[2 ] =PAGE_ALIGN (total_size -rounddown (offset2,PAGE_SIZE )) + >>PAGE_SHIFT ;[Severity: Critical]
Can this size calculation underflow? If a malicious userspace client provides offset2 smaller than offset1, the unsigned subtraction offset2 -rounddown(offset1, PAGE_SIZE)will underflow to a massive positive value. This could program the DMMU with a huge translation block, allowing arbitrary out-of-bounds physical memory reads.
Also unreachable: single-planar formats only, and the framebuffer core bounds every offsets[] within the GEM object at creation time.
Cody
Re: [PATCH RESEND 08/17] drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
In reply to Cody KangQuoted 27 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Register programming of the Saturn DPU is batched: the driver builds per-module register lists in memory and the hardware command-list engine replays them at frame boundaries, while scanout buffers are mapped through the DPU's private address translation unit (DMMU) rather than scanned out by physical address.
Add the shared driver types, the MMIO field accessors, the trace events, the command-list builder and the DMMU table code. Some DPU configuration registers are write-only, so a read-modify-write would corrupt neighbouring fields; byte- and halfword-aligned fields are therefore written at their native width instead.
Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/dpu/dpu_saturn.h | 35 +++ drivers/gpu/drm/spacemit/dpu/dpu_trace.h | 350 ++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.c | 304 ++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.h | 146 ++++++++++++ drivers/gpu/drm/spacemit/spacemit_crtc.h | 259 ++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.c | 103 ++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.h | 40 ++++ drivers/gpu/drm/spacemit/spacemit_dpu_reg.h | 108 +++++++++ drivers/gpu/drm/spacemit/spacemit_drm.h | 68 ++++++ 9 files changed, 1413 insertions(+)
[...]
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +0
-0@@ -0,0 +1,146 @@
[...]
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +10
-0+struct spacemit_crtc { +struct device *dev; +struct drm_crtc crtc; +const struct dpu_core_ops *core; +struct dpu_mmu_tbl mmu_tbl; +int dev_id; +int irq_online; +struct timer_list cfg_rdy_timer; + +bool is_1st_f;
drivers/gpu/drm/spacemit/spacemit_cmdlist.h
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +10
-0+bool first_modeset; +struct dpu_clk_context clk_ctx; +u32 aclk; +u32 out_format; + +struct reset_control *mclk_reset; +struct reset_control *lcd_reset; +struct reset_control *esc_reset; +struct reset_control *aclk_reset; +struct reset_control *dsc_reset;
Why are these duplicated from spacemit_drm_private? dpu_pm_suspend/resume() in patch 10 have access to priv.
regards
Philipp
Re: [PATCH RESEND 08/17] drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
Quoted 51 lines · Philipp Zabel
Quoted 27 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Register programming of the Saturn DPU is batched: the driver builds per-module register lists in memory and the hardware command-list engine replays them at frame boundaries, while scanout buffers are mapped through the DPU's private address translation unit (DMMU) rather than scanned out by physical address.
Add the shared driver types, the MMIO field accessors, the trace events, the command-list builder and the DMMU table code. Some DPU configuration registers are write-only, so a read-modify-write would corrupt neighbouring fields; byte- and halfword-aligned fields are therefore written at their native width instead.
Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/dpu/dpu_saturn.h | 35 +++ drivers/gpu/drm/spacemit/dpu/dpu_trace.h | 350 ++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.c | 304 ++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.h | 146 ++++++++++++ drivers/gpu/drm/spacemit/spacemit_crtc.h | 259 ++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.c | 103 ++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.h | 40 ++++ drivers/gpu/drm/spacemit/spacemit_dpu_reg.h | 108 +++++++++ drivers/gpu/drm/spacemit/spacemit_drm.h | 68 ++++++ 9 files changed, 1413 insertions(+)[...]
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +0
-0@@ -0,0 +1,146 @@[...]
Quoted 15 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +15
-0+struct spacemit_crtc { +struct device *dev; +struct drm_crtc crtc; +const struct dpu_core_ops *core; +struct dpu_mmu_tbl mmu_tbl; +int dev_id; +int irq_online; +struct timer_list cfg_rdy_timer; + +bool is_1st_f; +bool first_modeset; +struct dpu_clk_context clk_ctx; +u32 aclk; +u32 out_format; +
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.h
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +5
-0+struct reset_control *mclk_reset; +struct reset_control *lcd_reset; +struct reset_control *esc_reset; +struct reset_control *aclk_reset; +struct reset_control *dsc_reset;Why are these duplicated from
spacemit_drm_private? dpu_pm_suspend/resume() in patch 10 have access to priv.
You are right, they are plain 1:1 copies. Will drop the five pointers from struct spacemit_crtc in v2; the reset sequencing in spacemit_crtc.c and the suspend/resume paths will take them from spacemit_drm_private instead.
Thanks for the review.
Cody
PATCH RESEND 9/17 drm/spacemit: add Saturn DPU hardware backend
In reply to Cody KangAdd the register-level programming of one Saturn instance: clock and reset bring-up, scene control and timing generator setup, RDMA channel and composer layer programming, FBC line-buffer budgeting, interrupt dispatch and the cfg-ready/vsync handshake that paces commits. The backend is exposed as an ops table and hardware descriptor to be aggregated by the KMS layer in an upcoming patch.
--- drivers/gpu/drm/spacemit/dpu/dpu_saturn.c | 483 +++++++++++ drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c | 896 +++++++++++++++++++++ drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c | 152 ++++ drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h | 21 + drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h | 52 ++ 5 files changed, 1604 insertions(+)
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +483 -0
@@ -0,0 +1,483 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +* +*/ + +#include <linux/delay.h> +#include <linux/dma-mapping.h> +#include <linux/wait.h> +#include <linux/workqueue.h> +#include <linux/clk.h> +#include <linux/clk-provider.h> +#include <linux/module.h> +#include <linux/mfd/syscon.h> +#include <linux/pm_qos.h> +#include <linux/regmap.h> +#include <linux/of.h> +#include <linux/of_graph.h> +#include <linux/types.h> +#include <linux/math64.h> +#include <drm/drm_print.h> +#include <drm/drm_atomic.h> +#include <drm/drm_framebuffer.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_gem.h> +#include "dpu_saturn.h" +#include "saturn_fbcmem.h" +#include "../spacemit_cmdlist.h" +#include "../spacemit_dmmu.h" +#include "../spacemit_dpu_reg.h" +#include "../spacemit_drm.h" +#include <video/display_timing.h> +#include "../spacemit_dpu_ids.h" +#include "saturn_regs/ops_hee.h" + +#define CREATE_TRACE_POINTS +#include "dpu_trace.h" + +#define TOTAL_RDMA_MEMSIZE (68 * 1024) +static const struct dpu_format_id primary_fmts[] = { + {DRM_FORMAT_XRGB8888 ,8 ,32 },/* RDMA_FMT_XRGB_8888 */ + {DRM_FORMAT_ARGB8888 ,4 ,32 },/* RDMA_FMT_ARGB_8888 */ + {DRM_FORMAT_XBGR8888 ,9 ,32 },/* RDMA_FMT_XBGR_8888 */ + {DRM_FORMAT_ABGR8888 ,5 ,32 },/* RDMA_FMT_ABGR_8888 */ + {DRM_FORMAT_RGBX8888 ,10 ,32 },/* RDMA_FMT_RGBX_8888 */ + {DRM_FORMAT_RGBA8888 ,6 ,32 },/* RDMA_FMT_RGBA_8888 */ + {DRM_FORMAT_BGRX8888 ,11 ,32 },/* RDMA_FMT_BGRX_8888 */ + {DRM_FORMAT_BGRA8888 ,7 ,32 },/* RDMA_FMT_BGRA_8888 */ + {DRM_FORMAT_ABGR2101010 ,1 ,32 },/* RDMA_FMT_ABGR_2101010 */ + {DRM_FORMAT_RGB888 ,12 ,24 },/* RDMA_FMT_RGB_888 */ + {DRM_FORMAT_BGR888 ,13 ,24 },/* RDMA_FMT_BGR_888 */ + {DRM_FORMAT_RGB565 ,22 ,16 },/* RDMA_FMT_RGB_565 */ + {DRM_FORMAT_BGR565 ,23 ,16 },/* RDMA_FMT_BGR_565 */ +}; + +static const struct spacemit_hw_rdma saturn_hee_rdmas[] = { + {FORMAT_RGB }, + {FORMAT_RGB }, + {FORMAT_RGB }, + {FORMAT_RGB }, +}; + +static const u32 saturn_hee_fbcmem_sizes[] = { +89600 ,/* 87.5k */ +15360 ,/* 16k */ +}; + +const struct spacemit_hw_device k3_saturn_dpu = { + .plane_nums =1 , + .crtc_nums =2 , + .rdma_nums =ARRAY_SIZE (saturn_hee_rdmas), + .rdmas = saturn_hee_rdmas, + .n_formats =ARRAY_SIZE (primary_fmts), + .formats = primary_fmts, + .n_fbcmems =ARRAY_SIZE (saturn_hee_fbcmem_sizes), + .fbcmem_sizes = saturn_hee_fbcmem_sizes, + .enable_vsync = saturn_hee_enable_vsync, + .enable_cfg_irq = saturn_hee_enable_cfg_irq, + .cfg_ready = saturn_hee_cfg_ready, + .sw_start = saturn_hee_sw_start, + .irq_enable = saturn_hee_irq_enable, + .dpu_init = saturn_hee_dpu_init, + .plane_update_hw_channel = saturn_hee_plane_update_hw_channel, + .plane_disable_hw_channel = saturn_hee_plane_disable_hw_channel, + .conf_dpuctrl = saturn_hee_conf_dpuctrl, + .get_cfg_rdy = saturn_hee_get_cfg_rdy, + .get_int_sts = saturn_hee_get_int_sts, + .get_irq_bit = saturn_hee_get_irq_bit, + .clr_int_sts = saturn_hee_clr_int_sts, + .enable_cmdlist = saturn_hee_enable_cmdlist, + .cfg_cmdlist = saturn_hee_cfg_cmdlist, + .rdma_dmmu = saturn_hee_rdma_dmmu, + .get_cl_rdma_buf = saturn_hee_get_cl_rdma_buf, + .cmdlist_fill_data_row = saturn_hee_cmdlist_fill_data_row, + .cmdlist_fill_conf_row = saturn_hee_cmdlist_fill_conf_row, + .crtc_cmdlist = saturn_hee_crtc_cmdlist, + .cmdlist_dump_node = saturn_hee_cmdlist_dump_node, +}; + +void saturn_enable_irq_mask (struct spacemit_crtc *a_crtc,bool enable, +u32 offset,u32 mask) +{ +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +if (!hwdev->base) { +drm_err (a_crtc->crtc.dev,"hwdev->base is NULL\n" ); +return ; + } + +if (!a_crtc->clocks_on) +return ; + +regmap_update_bits (hwdev->regmap, offset, mask, enable ? mask :0 ); +} + +int dpu_parse_clocks (struct device *dev,struct dpu_clk_context *clk_ctx) +{ + clk_ctx->pxclk =devm_clk_get (dev,"pxclk" ); +if (IS_ERR (clk_ctx->pxclk)) +return dev_err_probe (dev,PTR_ERR (clk_ctx->pxclk), +"failed to get pxclk\n" ); + + clk_ctx->mclk =devm_clk_get (dev,"mclk" ); +if (IS_ERR (clk_ctx->mclk)) +return dev_err_probe (dev,PTR_ERR (clk_ctx->mclk), +"failed to get mclk\n" ); + + clk_ctx->escclk =devm_clk_get (dev,"escclk" ); +if (IS_ERR (clk_ctx->escclk)) +return dev_err_probe (dev,PTR_ERR (clk_ctx->escclk), +"failed to get escclk\n" ); + + clk_ctx->aclk =devm_clk_get (dev,"aclk" ); +if (IS_ERR (clk_ctx->aclk)) +return dev_err_probe (dev,PTR_ERR (clk_ctx->aclk), +"failed to get aclk\n" ); + + clk_ctx->dscclk =devm_clk_get (dev,"dscclk" ); +if (IS_ERR (clk_ctx->dscclk)) +return dev_err_probe (dev,PTR_ERR (clk_ctx->dscclk), +"failed to get dscclk\n" ); + +return 0 ; +} + +static int dpu_enable_clocks (struct spacemit_crtc *a_crtc) +{ +struct dpu_clk_context *clk_ctx = &a_crtc->clk_ctx; +struct drm_crtc *crtc = &a_crtc->crtc; +struct drm_display_mode *mode = &crtc->mode; +u64 clk_val; +u64 set_clk_val; +int ret; + + ret =clk_prepare_enable (clk_ctx->pxclk); +if (ret) + goto err; + set_clk_val = mode->clock *1000 ; +if (set_clk_val) { + set_clk_val =clk_round_rate (clk_ctx->pxclk, set_clk_val); + clk_val =clk_get_rate (clk_ctx->pxclk); +if (clk_val != set_clk_val) { +clk_set_rate (clk_ctx->pxclk, set_clk_val); +drm_dbg (crtc->dev,"pxclk=%lld\n" , clk_val); + } + } + + ret =clk_prepare_enable (clk_ctx->mclk); +if (ret) + goto err_pxclk; + clk_val =clk_get_rate (clk_ctx->mclk); +if (clk_val !=DPU_MCLK_DEFAULT ) { + clk_val =clk_round_rate (clk_ctx->mclk,DPU_MCLK_DEFAULT ); +clk_set_rate (clk_ctx->mclk, clk_val); +drm_dbg (crtc->dev,"mclk=%lld\n" , clk_val); + } + +/* The escape clock only has to run for the "esc" reset to propagate. */ + ret =clk_prepare_enable (clk_ctx->escclk); +if (ret) + goto err_mclk; + + ret =clk_prepare_enable (clk_ctx->aclk); +if (ret) + goto err_escclk; + clk_val =clk_get_rate (clk_ctx->aclk); +if (clk_val != a_crtc->aclk) { + set_clk_val =clk_round_rate (clk_ctx->aclk, a_crtc->aclk); +if (set_clk_val != clk_val) { +clk_set_rate (clk_ctx->aclk, set_clk_val); +drm_dbg (crtc->dev,"aclk %llu -> %llu\n" , clk_val, + set_clk_val); + } + } + + ret =clk_prepare_enable (clk_ctx->dscclk); +if (ret) + goto err_aclk; + +trace_dpu_enable_clocks (a_crtc->dev_id); +return 0 ; + +err_aclk: +clk_disable_unprepare (clk_ctx->aclk); +err_escclk: +clk_disable_unprepare (clk_ctx->escclk); +err_mclk: +clk_disable_unprepare (clk_ctx->mclk); +err_pxclk: +clk_disable_unprepare (clk_ctx->pxclk); +err: +drm_err (crtc->dev,"failed to enable DPU clocks: %d\n" , ret); +return ret; +} + +static int dpu_disable_clocks (struct spacemit_crtc *a_crtc) +{ +struct dpu_clk_context *clk_ctx = &a_crtc->clk_ctx; + +trace_dpu_disable_clocks (a_crtc->dev_id); + +clk_disable_unprepare (clk_ctx->pxclk); +clk_disable_unprepare (clk_ctx->mclk); +clk_disable_unprepare (clk_ctx->escclk); + +clk_disable_unprepare (clk_ctx->aclk); +clk_disable_unprepare (clk_ctx->dscclk); + +return 0 ; +} + +u8 spacemit_plane_hw_get_format_id (u32 format) +{ +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (primary_fmts); i++) { +if (primary_fmts[i].format == format) +return primary_fmts[i].id; + } + +return SPACEMIT_DPU_INVALID_FORMAT_ID ; +} + +static void saturn_enable_vsync (struct spacemit_crtc *a_crtc,bool enable) +{ +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +trace_saturn_enable_vsync ("vsync" , enable); + hwdev->enable_vsync (a_crtc, hwdev, enable); +} + +void spacemit_cfg_rdy_timer_handler (struct timer_list *t) +{ +struct spacemit_crtc *a_crtc =timer_container_of (a_crtc, t, + cfg_rdy_timer); +struct drm_crtc *crtc = &a_crtc->crtc; +struct drm_device *drm = crtc->dev; +struct drm_pending_vblank_event *event; +unsigned long flags; + +drm_err_ratelimited (drm,"CFG_RDY handshake timeout\n" ); +trace_saturn_ctrl_cfg_ready_timer (a_crtc->dev_id); + + a_crtc->flip_done = true; + +spin_lock_irqsave (&drm->event_lock, flags); + event = crtc->state->event; +if (event) { + crtc->state->event =NULL ; +drm_crtc_send_vblank_event (crtc, event); + } +spin_unlock_irqrestore (&drm->event_lock, flags); + +drm_crtc_vblank_put (crtc); +} + +static void saturn_ctrl_cfg_ready (struct spacemit_crtc *a_crtc,bool enable) +{ +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +trace_saturn_ctrl_cfg_ready (a_crtc->dev_id, enable); +mod_timer (&a_crtc->cfg_rdy_timer, jiffies +msecs_to_jiffies (3000 )); + hwdev->cfg_ready (a_crtc, hwdev); +} + +static void saturn_ctrl_sw_start (struct spacemit_crtc *a_crtc,bool enable) +{ +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +trace_saturn_ctrl_sw_start (a_crtc->dev_id, enable); + + hwdev->sw_start (a_crtc, hwdev); +} + +static int dpu_init (struct spacemit_crtc *a_crtc) +{ +unsigned int timeout =1000 ; +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +if (!a_crtc->clocks_on) +return 0 ; + +while (timeout) { +if (hwdev->get_cfg_rdy (a_crtc, hwdev) ==0 ) +break ; +usleep_range (100 ,200 ); + timeout--; + } +if (timeout ==0 ) +drm_err (a_crtc->crtc.dev,"wait for cfg ready timed out\n" ); + + hwdev->dpu_init (a_crtc); + +return 0 ; +} + +static void dpu_uninit (struct spacemit_crtc *a_crtc) +{ +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +if (!a_crtc->clocks_on) +return ; + +trace_dpu_uninit (a_crtc->dev_id); + hwdev->irq_enable (a_crtc, false); +} + +static inline void dpu_isr_vblank (struct spacemit_crtc *a_crtc,bool *flip) +{ +struct drm_crtc *crtc = &a_crtc->crtc; +struct drm_device *drm = crtc->dev; +struct drm_pending_vblank_event *event; + +drm_crtc_handle_vblank (crtc); + +if (*flip) +return ; + *flip = true; + +/* +* event_lock serialises this against the commit arming +* crtc->state->event. +*/ +spin_lock (&drm->event_lock); + event = crtc->state->event; +if (event) { +/* +* Consume it exactly once, even against a concurrent +* commit_hw_done(). +*/ + crtc->state->event =NULL ; +drm_crtc_send_vblank_event (crtc, event); + } +spin_unlock (&drm->event_lock); + +drm_crtc_vblank_put (crtc); +} + +u32 saturn_conf_dpuctrl_rdma (struct spacemit_crtc *a_crtc) +{ +struct drm_crtc *crtc = &a_crtc->crtc; +struct drm_plane *plane; +u32 rdma_en =0 ; + +drm_atomic_crtc_for_each_plane (plane, crtc) { +u32 rdma_id =to_spacemit_plane_state (plane->state)->rdma_id; + +if (rdma_id !=RDMA_INVALID_ID ) + rdma_en |= (1 << rdma_id); + } + +trace_dpuctrl ("rdma_en" , rdma_en); + +return rdma_en; +} + +static u32 dpu_online_isr (struct spacemit_crtc *a_crtc) +{ +u32 irq_raw, irq_bit, irq_ur_bit; +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; +int dev_id = a_crtc->dev_id; + +trace_dpu_isr (a_crtc->dev_id); + + irq_raw = hwdev->get_int_sts (hwdev, dev_id); +trace_dpu_isr_status ("ONLINE" , irq_raw); + irq_bit = hwdev->get_irq_bit (INT_UNDERRUN , dev_id); + irq_ur_bit = irq_raw & irq_bit; +if (irq_ur_bit && !a_crtc->ur_reported) { + hwdev->clr_int_sts (a_crtc, irq_ur_bit, dev_id); +trace_dpu_isr_status ("underrun" , irq_ur_bit); +drm_err_ratelimited (a_crtc->crtc.dev,"underrun\n" ); + a_crtc->ur_reported = true; + } + irq_bit = hwdev->get_irq_bit (INT_CFG_RDY , dev_id); +if (irq_raw & irq_bit) { + hwdev->clr_int_sts (a_crtc, irq_bit, dev_id); +trace_dpu_isr_status ("cfg_rdy_clr" , irq_raw & irq_bit); +/* +* A fired watchdog already sent the event and put this flip's +* vblank reference; re-arming the vsync path would put twice. +*/ +if (timer_delete (&a_crtc->cfg_rdy_timer)) + a_crtc->flip_done = false; + a_crtc->ur_reported = false; +if (hwdev->enable_cfg_irq) + hwdev->enable_cfg_irq (a_crtc, hwdev, false); + } + irq_bit = hwdev->get_irq_bit (INT_VSYNC , dev_id); +if (irq_raw & irq_bit) { + hwdev->clr_int_sts (a_crtc, irq_bit, dev_id); +trace_dpu_isr_status ("vsync" , irq_raw & irq_bit); +dpu_isr_vblank (a_crtc, &a_crtc->flip_done); + } + irq_bit = hwdev->get_irq_bit (INT_REST , dev_id) | irq_ur_bit; +if (irq_raw & irq_bit) + hwdev->clr_int_sts (a_crtc, irq_bit, dev_id); + + irq_bit = hwdev->get_irq_bit (INT_VSYNC_UPDATE , dev_id); +if (irq_raw & irq_bit) + hwdev->clr_int_sts (a_crtc, irq_bit, dev_id); + +return 0 ; +} + +static void dpu_run (struct drm_crtc *crtc, +struct drm_crtc_state *old_state) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +trace_dpu_run (a_crtc->dev_id); + +if (hwdev->conf_dpuctrl) + hwdev->conf_dpuctrl (crtc, old_state); + +/* flush all config register writes before CFG_RDY is raised */ +mb (); + +drm_crtc_vblank_get (crtc); +if (hwdev->enable_cfg_irq) + hwdev->enable_cfg_irq (a_crtc, hwdev, true); + +saturn_ctrl_cfg_ready (a_crtc, true); + +if (unlikely (a_crtc->is_1st_f)) { +drm_dbg (a_crtc->crtc.dev,"DPU start\n" ); + a_crtc->is_1st_f = false; +saturn_ctrl_sw_start (a_crtc, true); + } +dma_rmb (); +} + +static void dpu_enable_vsync (struct spacemit_crtc *a_crtc) +{ +saturn_enable_vsync (a_crtc, true); +} + +static void dpu_disable_vsync (struct spacemit_crtc *a_crtc) +{ +saturn_enable_vsync (a_crtc, false); +} + +const struct dpu_core_ops dpu_saturn_ops = { + .init = dpu_init, + .uninit = dpu_uninit, + .run = dpu_run, + .online_isr = dpu_online_isr, + .enable_clk = dpu_enable_clocks, + .disable_clk = dpu_disable_clocks, + .enable_vsync = dpu_enable_vsync, + .disable_vsync = dpu_disable_vsync, + .cal_layer_fbcmem_size = saturn_cal_layer_fbcmem_size, + .adjust_rdma_fbcmem = saturn_adjust_rdma_fbcmem, +};
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +896 -0
896 lines not on this page · raw message
drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c new file +152 -0
152 lines not on this page · raw message
drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SATURN_FBCMEM_H_ +#define _SATURN_FBCMEM_H_ + +#include <drm/drm_plane.h> +#include "../spacemit_crtc.h" +#include "../spacemit_dpu_reg.h" +#include "dpu_saturn.h" + +#define FBCMEM_UNIT (32)/* fbcmem is 32 bytes per unit */ + +int get_raw_data_plane_rdma_mem_size (u32 drm_4cc_fmt,u32 plane_crop_width, +u32 *output_mem_size); + +int saturn_cal_layer_fbcmem_size (struct drm_plane *plane, +struct drm_plane_state *state); + +int saturn_adjust_rdma_fbcmem (struct spacemit_hw_device *hwdev, +struct spacemit_crtc_rdma *rdmas); + +#endif
drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 09/17] drm/spacemit: add Saturn DPU hardware backend
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider: - [High] Sleeping memory allocations (`GFP_KERNEL`) in atomic context plane and CRTC update paths, with a…
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [High] Sleeping memory allocations (GFP_KERNEL) in atomic context plane and CRTC update paths, with a silent fallback that breaks atomic update semantics.
- [High] Sleeping delay function (usleep_range) used in CRTC atomic enable context.
- [High] Unconditional dereference of state->fb for disabled or solid-fill planes.
- [High] Race condition between the configuration timer handler and the VSYNC ISR leads to a double drm_crtc_vblank_put and refcount underflow.
- [High] The cfg_rdy_timer is not synchronously canceled when the DPU hardware is uninitialized or disabled.
- [High] row_eof_tag and un-strobed module_regs are left uninitialized in saturn_hee_cmdlist_fill_data_row().
- [High] Accessing crtc->state->event from the VBLANK interrupt handler races with concurrent non-blocking atomic commits, causing leaked and premature events.
- [High] Command list length counter desynchronization leads to missing EOF tags and display hangs.
- [High] RDMA hardware configuration is written to a shared staging buffer but is never packed into the DMA command list, causing updates to be dropped or overwritten.
- [Medium] dpu_run() ignores the return value of drm_crtc_vblank_get(), potentially leading to refcount underflow.
- [Medium] Using C bitfields for DMA-shared hardware descriptors (struct cmdlist_header and struct cmdlist_row) leads to compiler-dependent memory layout and breaks on different endiannesses. --
--- Patch [9]: [PATCH RESEND 09/17] drm/spacemit: add Saturn DPU hardware backend --- commit 51bff8176b75d13f3aa75c39d52083ed25e121c0
Author: Cody Kang <[email protected]> Date: Sat Jul 25 04:51:18 2026 +0000
drm/spacemit: add Saturn DPU hardware backend
Add the register-level programming of one Saturn instance: clock and reset bring-up, scene control and timing generator setup, RDMA channel and composer layer programming, FBC line-buffer budgeting, interrupt dispatch and the cfg-ready/vsync handshake that paces commits.
Quoted 4 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +2
-0+void spacemit_cfg_rdy_timer_handler (struct timer_list *t) +{
[ ... ]
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 269
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +2
-0+spin_lock_irqsave (&drm->event_lock, flags); + event = crtc->state->event;
[Severity: High]
Does this race with concurrent non-blocking atomic commits?
The DRM core's atomic helpers synchronously swap the crtc->state pointer during the commit phase before the hardware's VBLANK interrupt fires. If two non-blocking commits are issued back-to-back, the second commit swaps crtc->state to its new state.
When the first commit's VBLANK fires (or this timer handler executes), reading crtc->state->event prematurely consumes the second commit's event, leaking the first commit's event. Should the event be stored in a driver-private CRTC structure instead?
Quoted 8 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +8
-0+if (event) { + crtc->state->event =NULL ; +drm_crtc_send_vblank_event (crtc, event); + } +spin_unlock_irqrestore (&drm->event_lock, flags); + +drm_crtc_vblank_put (crtc); +}
[ ... ]
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 311
Quoted 13 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +13
-0+static int dpu_init (struct spacemit_crtc *a_crtc) +{ +unsigned int timeout =1000 ; +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +if (!a_crtc->clocks_on) +return 0 ; + +while (timeout) { +if (hwdev->get_cfg_rdy (a_crtc, hwdev) ==0 ) +break ; +usleep_range (100 ,200 );
[Severity: High]
Is it safe to use a sleeping delay function here?
dpu_init() is hooked to the .init callback of dpu_core_ops, which executes during the CRTC atomic enable phase. The DRM subsystem guidelines explicitly state that CRTC atomic enable callbacks run in atomic context where sleeping is strictly forbidden.
Will this trigger a "scheduling while atomic" panic?
Quoted 11 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +11
-0+ timeout--; + } +if (timeout ==0 ) +drm_err (a_crtc->crtc.dev,"wait for cfg ready timed out\n" ); + + hwdev->dpu_init (a_crtc); + +return 0 ; +} + +static void dpu_uninit (struct spacemit_crtc *a_crtc)
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 332
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10
-0+{ +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; + +if (!a_crtc->clocks_on) +return ; + +trace_dpu_uninit (a_crtc->dev_id); + hwdev->irq_enable (a_crtc, false); +}
[Severity: High]
Does this uninitialization path need to cancel the configuration timer?
saturn_ctrl_cfg_ready() arms a_crtc->cfg_rdy_timer when the DPU is started. If the display pipeline is disabled before the hardware raises the CFG_RDY interrupt, this timer will remain active and could fire asynchronously after shutdown.
Can this lead to spurious timeout errors, incorrect vblank reference decrements, or a use-after-free if the CRTC object is destroyed before the timer is canceled?
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +2
-0+static inline void dpu_isr_vblank (struct spacemit_crtc *a_crtc,bool *flip) +{
[ ... ]
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 351
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +2
-0+spin_lock (&drm->event_lock); + event = crtc->state->event;
[Severity: High]
Can this read the wrong event pointer?
Similar to the timer handler above, accessing crtc->state->event races with concurrent non-blocking atomic commits that swap the crtc->state pointer. If a new commit is queued, this reads the new state's event and leaks the current flip's event.
Quoted 1 line
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +1
-0+if (event) {
[ ... ]
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +2
-0+static u32 dpu_online_isr (struct spacemit_crtc *a_crtc) +{
[ ... ]
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 411
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10
-0+ irq_bit = hwdev->get_irq_bit (INT_CFG_RDY , dev_id); +if (irq_raw & irq_bit) { + hwdev->clr_int_sts (a_crtc, irq_bit, dev_id); +trace_dpu_isr_status ("cfg_rdy_clr" , irq_raw & irq_bit); +/* +* A fired watchdog already sent the event and put this flip's +* vblank reference; re-arming the vsync path would put twice. +*/ +if (timer_delete (&a_crtc->cfg_rdy_timer)) + a_crtc->flip_done = false;
[Severity: High]
Does using the non-blocking timer_delete() return value create a race condition?
If timer_delete() returns 0 (e.g., because the callback is actively executing on another CPU), it leaves a_crtc->flip_done unmodified.
The ISR then processes INT_VSYNC and calls dpu_isr_vblank(), which reads flip_done == false, sets it to true, and calls drm_crtc_vblank_put(). Concurrently, the timer handler runs, sets flip_done = true, and also unconditionally calls drm_crtc_vblank_put().
Could this lead to a double vblank put and refcount underflow?
Quoted 1 line
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +1
-0+ a_crtc->ur_reported = false;
[ ... ]
Quoted 6 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +6
-0+static void dpu_run (struct drm_crtc *crtc, +struct drm_crtc_state *old_state) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); +struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev;
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 448
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10
-0+ +trace_dpu_run (a_crtc->dev_id); + +if (hwdev->conf_dpuctrl) + hwdev->conf_dpuctrl (crtc, old_state); + +/* flush all config register writes before CFG_RDY is raised */ +mb (); + +drm_crtc_vblank_get (crtc);
[Severity: Medium]
Should the return value of drm_crtc_vblank_get() be checked?
drm_crtc_vblank_get() can fail (e.g., if vblank interrupts are uninitialized or disabled), returning a negative error code without incrementing the vblank reference count.
By ignoring this return value, this function proceeds as if the reference was successfully acquired. When the hardware interrupt or timeout later triggers, they unconditionally call drm_crtc_vblank_put(), which could cause a refcount underflow.
Quoted 9 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +4
-0+if (hwdev->enable_cfg_irq) + hwdev->enable_cfg_irq (a_crtc, hwdev, true); + +saturn_ctrl_cfg_ready (a_crtc, true);drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +2
-0+void saturn_hee_plane_update_hw_channel (struct drm_plane *plane) +{
[ ... ]
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 388
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +5
-0+/* For solid color both src_w and src_h are 0 */ +if (!solid_en) { + base =RDMA_BASE_ADDR [rdma_id]; +/* linear scanout only: the FBC decode path is not exposed */ +dpu_write (hwdev,RDMA_PATH_X_REG , base, layer_mode,0 , cl_rdma);
[Severity: High]
Are these RDMA hardware configuration writes dropped because they are never packed into the DMA command list?
This uses a_crtc->cl_rdma to stage hardware writes for the RDMA block. However, there is no corresponding call to cmdlist_regs_packing() for cl_rdma to commit these writes to the DMA-backed command list.
Since a_crtc->cl_rdma is a single shared buffer, do subsequent plane updates overwrite the staged settings of previous planes, silently corrupting the configuration and failing to program the hardware?
Quoted 1 line
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +1
-0+ dpu_write(hwdev, RDMA_PATH_X_REG, base, layer_cmpsr_id,
[ ... ]
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +5
-0+switch (pixel_alpha) { +case DRM_MODE_BLEND_COVERAGE : + blend_mode =0x0 ; +break ; +case DRM_MODE_BLEND_PREMULTI :
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 440
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +10
-0+ blend_mode =0x1 ; +break ; +case DRM_MODE_BLEND_PIXEL_NONE : + blend_mode =0x0 ; +break ; +default : +drm_err (plane->dev,"unsupported blend mode for pixel alpha\n" ); + } + + if (state->fb->format && state->fb->format->has_alpha &&
[Severity: High]
Will this unconditionally dereference a NULL pointer for solid-fill planes?
During DRM atomic commits, a plane's state->fb is frequently NULL (e.g., when a plane is being disabled, or for solid color fill planes).
While the earlier code handles solid fills by skipping the RDMA block (if (!solid_en)), this block evaluates state->fb->format unconditionally, which will cause a kernel panic if state->fb is NULL.
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 451
Quoted 11 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +11
-0+ pixel_alpha != DRM_MODE_BLEND_PIXEL_NONE) { + if (alpha != 0xff) + alpha_sel = 0x2; + else + alpha_sel = 0x1; + } else { + blend_mode =0x0 ; + alpha_sel =0x0 ; + } + + cl_cmp =alloc_cmdlist_regs (CMPS_X_REG );
[Severity: High]
Can this trigger a "scheduling while atomic" panic or silent fallback failures?
alloc_cmdlist_regs() is a macro that uses GFP_KERNEL allocations (kzalloc(sizeof(*cl), GFP_KERNEL)). This plane update callback runs in atomic context where sleeping is forbidden.
Additionally, if the allocation fails and returns NULL, the dpu_write() macro silently falls back to immediate MMIO writes (dpu_write_reg_word). This bypasses the command list's VBLANK synchronization, applying partial hardware state immediately and causing visual tearing or lockups.
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +2
-0+ + base =CMP_BASE_ADDR [a_crtc->dev_id];
[ ... ]
Quoted 11 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +11
-0+struct cmdlist_header { +u64 next_list_addr :39 ; +/* reserved */ + u32: 1; +u32 nod_len :16 ; +/* 1: the last cmdlist node, 2: pending node, otherwise 0 */ +u32 nod_type :2 ; +u32 next_nod_secu :1 ; +u64 wait_event_low :5 ; +u64 wait_event :59 ; +/* reserved */
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 702
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +10
-0+ u32:5 ; +}; + +struct cmdlist_row { +u32 module_cfg_addr :19 ; +u32 module_cfg_strobe :12 ; +/* the last row tag = 1, else tag = 0. */ +u32 row_eof_tag :1 ; +u32 module_regs[3 ]; +};
[Severity: Medium]
Does using C bitfields for DMA-shared hardware descriptors break on different compilers or endiannesses?
These structures format command list nodes directly into a DMA buffer consumed by the hardware. The C standard leaves bitfield packing order and alignment entirely implementation-defined.
Mixing u64 and u32 bitfields makes the exact memory layout highly sensitive to compiler ABIs and versions, and it will not work correctly across different endiannesses. Could you use explicit bitwise operations with fixed-width types instead?
Quoted 2 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +2
-0+ +/* DMA stream layout consumed by the cmdlist engine; sizes are load-bearing. */
[ ... ]
Quoted 8 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +8
-0+void saturn_hee_cmdlist_fill_data_row (struct cmdlist *cl,u32 strobe, +u32 offset,u32 value[]) +{ +struct cmdlist_row *row; +u8 i; + +/* +* packing counts rows blindly; drop the row rather than the buffer end
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 734
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +10
-0+*/ +if (WARN_ONCE (CL_HEADER_SZ + (cl->nod_len +1 ) *CL_ROW_SZ > cl->size, +"cmdlist buffer full (rows %u)\n" , cl->nod_len)) +return ; + + row = (struct cmdlist_row *)((char *)cl->va +CL_HEADER_SZ ) + cl->nod_len; + row->module_cfg_addr = offset >>2 ; + row->module_cfg_strobe = strobe; + +for (i =0 ; i <CMDLIST_ROW_REGS ; i++)
[Severity: High]
Are row_eof_tag and un-strobed module_regs left uninitialized here?
This overlays a struct cmdlist_row onto the cl->va DMA buffer without explicitly clearing or setting row->row_eof_tag. If the buffer is reused across frames and the current frame is shorter than the previous one, row_eof_tag could contain a stale 1 from the end of a previous commit's list.
If the hardware sees this uninitialized bitfield as 1, it will terminate command processing prematurely, ignoring all subsequent commands in the current frame and causing display hangs.
Quoted 1 line
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +1
-0+if (strobe &CMDLIST_REG_STROBE (i))
[ ... ]
Quoted 3 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +3
-0+void saturn_hee_cmdlist_fill_conf_row (struct cmdlist *cl,struct spacemit_hw_device *hwdev, +u8 dev_id) +{
[ ... ]
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 761
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +5
-0+/* At most three rows are appended below; bail before overrunning. */ +if (WARN_ONCE (CL_HEADER_SZ + (cl->nod_len +3 ) *CL_ROW_SZ > cl->size, +"cmdlist buffer full (type %u, rows %u)\n" , + cl->type, cl->nod_len)) +return ;
[Severity: High]
Does a desynchronized cl->nod_len cause the EOF tag to be dropped?
The calling code in cmdlist_regs_packing() unconditionally increments cl->nod_len after calling saturn_hee_cmdlist_fill_data_row(), even if that function silently dropped the row due to the buffer being full.
This causes cl->nod_len to artificially inflate beyond the actual rows written. If it hits this WARN_ONCE, it aborts before appending the critical configuration row containing row_eof_tag = 1.
Could the hardware process an incomplete command list lacking an EOF tag, thereby failing to signal the CFG_RDY interrupt?
Quoted 7 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +2
-0+ + header = (struct cmdlist_header *)(cl->va);drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c new file +0
-0
[ ... ]
drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c line 40
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c new file +5
-0+int saturn_cal_layer_fbcmem_size (struct drm_plane *plane, +struct drm_plane_state *state) +{ +struct spacemit_plane_state *pstate =to_spacemit_plane_state (state); +u32 drm_4cc_fmt = pstate->state.fb->format->format;
[Severity: High]
Will this dereference a NULL pointer when pstate->state.fb is NULL?
Similar to the issue in saturn_hee_plane_update_hw_channel(), state->fb can be NULL during plane disablement or solid-fill scenarios. This unconditional dereference will cause a kernel panic in those cases.
Quoted 3 lines
drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c new file +3
-0+u32 crop_w = pstate->state.src_w >>16 ; + +/* Only linear sizing: the compressed path is not exposed. */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
PATCH RESEND 10/17 drm/spacemit: add Saturn DPU KMS pipeline
In reply to Cody KangAdd the atomic KMS implementation on top of the hardware backend: one CRTC and one primary plane per DPU instance. atomic_check validates the plane rectangle 1:1 against the mode and sizes the per-channel FBC line buffer; atomic commit builds the cmdlist batches, maps the framebuffer through the DMMU and arms the cfg-ready handshake, with vblank events driven from the DPU interrupt.
--- drivers/gpu/drm/spacemit/spacemit_crtc.c | 815 +++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_planes.c | 376 +++++++++++++ 2 files changed, 1191 insertions(+)
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +815 -0
@@ -0,0 +1,815 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +* +*/ + +#include <drm/drm_print.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_crtc_helper.h> +#include <drm/drm_drv.h> +#include <drm/drm_plane_helper.h> +#include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_managed.h> +#include <drm/clients/drm_client_setup.h> +#include <linux/aperture.h> +#include <linux/clk.h> +#include <linux/clk-provider.h> +#include <linux/component.h> +#include <linux/interrupt.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/pm_qos.h> +#include <linux/property.h> +#include <linux/mutex.h> +#include <linux/string.h> +#include <linux/trace_events.h> +#include <linux/of_platform.h> +#include <linux/regmap.h> +#include "spacemit_dpu_ids.h" +#include <linux/reset.h> +#include "spacemit_cmdlist.h" +#include "spacemit_dmmu.h" +#include "spacemit_drm.h" +#include "spacemit_crtc.h" +#include "dpu/dpu_saturn.h" +#include "dpu/dpu_trace.h" + +static int spacemit_crtc_init (struct spacemit_crtc *a_crtc); +static int spacemit_crtc_uninit (struct spacemit_crtc *a_crtc); +static int dpu_pm_suspend (struct device *dev); +static int dpu_pm_resume (struct device *dev); +static void dpu_reset_assert (struct device *dev,const char *name, +struct reset_control *rstc); + +static void saturn_count_rdma_use (struct drm_crtc_state *crtc_state) +{ +struct drm_plane *plane; +struct spacemit_crtc_state *spacemit_state = +to_spacemit_crtc_state (crtc_state); +struct spacemit_crtc_rdma *rdmas = spacemit_state->rdmas; +u32 rdma_id =0 ; +const struct drm_plane_state *pstate; + +drm_atomic_crtc_state_for_each_plane_state (plane, pstate, crtc_state) { + rdma_id =to_spacemit_plane_state (pstate)->rdma_id; +if (rdma_id !=RDMA_INVALID_ID ) + rdmas[rdma_id].use_cnt++; + } +} + +static int spacemit_crtc_atomic_check_fbmem (struct drm_crtc *crtc, +struct drm_crtc_state *crtc_state) +{ +struct spacemit_crtc_rdma *rdmas = +to_spacemit_crtc_state (crtc_state)->rdmas; +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); +struct spacemit_drm_private *priv = crtc->dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; +const struct drm_plane_state *pstate; +struct drm_plane *plane; + +drm_atomic_crtc_state_for_each_plane_state (plane, pstate, crtc_state) { +u32 rdma_id =to_spacemit_plane_state (pstate)->rdma_id; +u32 layer_fbcmem_size = +to_spacemit_plane_state (pstate)->fbcmem_size; + +if (rdma_id !=RDMA_INVALID_ID ) + rdmas[rdma_id].fbcmem.size =max (layer_fbcmem_size, + rdmas[rdma_id].fbcmem.size); + } + +return a_crtc->core->adjust_rdma_fbcmem (hwdev, rdmas); +} + +static void spacemit_crtc_atomic_enable (struct drm_crtc *crtc, +struct drm_atomic_commit *old_state) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); +int idx; + +if (!drm_dev_enter (crtc->dev, &idx)) +return ; + +trace_spacemit_crtc_atomic_enable (a_crtc->dev_id); + +/* +* U-Boot leaves its boot-logo pipeline running. Hard-stop it with the +* resets alone; the clocks are not ours to gate until we have enabled +* them. +*/ +if (unlikely (a_crtc->first_modeset)) { +dpu_reset_assert (a_crtc->dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_assert (a_crtc->dev,"esc" , a_crtc->esc_reset); +dpu_reset_assert (a_crtc->dev,"mclk" , a_crtc->mclk_reset); +dpu_reset_assert (a_crtc->dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_assert (a_crtc->dev,"dsc" , a_crtc->dsc_reset); +usleep_range (10000 ,20000 ); + a_crtc->first_modeset = false; + } + +if (!a_crtc->clocks_on) { + a_crtc->clocks_on = true; +dpu_pm_resume (a_crtc->dev); + +/* +* The DPU must settle after reset deassert or CFG_RDY races +* the flush. +*/ +usleep_range (10000 ,20000 ); + } + +drm_crtc_vblank_on (&a_crtc->crtc); + +spacemit_crtc_init (a_crtc); + +drm_dev_exit (idx); +} + +static void spacemit_crtc_atomic_disable (struct drm_crtc *crtc, +struct drm_atomic_commit *old_state) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); +struct drm_device *drm = a_crtc->crtc.dev; +int idx; + +if (!drm_dev_enter (drm, &idx)) +return ; + +trace_spacemit_crtc_atomic_disable (a_crtc->dev_id); + +spacemit_crtc_uninit (a_crtc); + +drm_crtc_vblank_off (&a_crtc->crtc); + +/* +* MMIO on a clock-gated DPU stalls the bus, so an in-flight handler +* must finish its status reads before dpu_pm_suspend() gates the +* clocks. +*/ +if (a_crtc->irq_online >0 ) +synchronize_irq (a_crtc->irq_online); + +/* +* Nothing else cancels the watchdog; it would fire against freed state. +*/ +timer_delete_sync (&a_crtc->cfg_rdy_timer); + +/* Close the ISR's MMIO gate before the clocks actually stop. */ + a_crtc->clocks_on = false; +dpu_pm_suspend (a_crtc->dev); + +spin_lock_irq (&drm->event_lock); +if (crtc->state->event) { +drm_crtc_send_vblank_event (crtc, crtc->state->event); + crtc->state->event =NULL ; + } +spin_unlock_irq (&drm->event_lock); + +drm_dev_exit (idx); +} + +static int spacemit_crtc_atomic_check (struct drm_crtc *crtc, +struct drm_atomic_commit *atomic_state) +{ +struct drm_crtc_state *state = +drm_atomic_get_new_crtc_state (atomic_state, crtc); +struct spacemit_crtc_state *cstate =to_spacemit_crtc_state (state); +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); +int ret =0 ; + +trace_spacemit_crtc_atomic_check (a_crtc->dev_id); + + ret =spacemit_crtc_atomic_check_fbmem (crtc, state); +if (ret) { +drm_dbg_kms (crtc->dev, +"failed to satisfy fbcmem size for all rdmas\n" ); +return ret; + } + +saturn_count_rdma_use (state); + + ret =spacemit_cmdlist_alloc (a_crtc->dev, &cstate->cl); +if (ret) +return ret; + +return 0 ; +} + +static void spacemit_crtc_atomic_begin (struct drm_crtc *crtc, +struct drm_atomic_commit *state) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); + +trace_spacemit_crtc_atomic_begin (a_crtc->dev_id); +} + +static void spacemit_crtc_atomic_flush (struct drm_crtc *crtc, +struct drm_atomic_commit *state) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); +struct drm_crtc_state *old_state =drm_atomic_get_old_crtc_state (state, + crtc); +int idx; + +if (!drm_dev_enter (crtc->dev, &idx)) +return ; + +trace_spacemit_crtc_atomic_flush (a_crtc->dev_id); + +spacemit_crtc_run (crtc, old_state); + +drm_dev_exit (idx); +} + +static struct drm_crtc_state * +spacemit_crtc_duplicate_state (struct drm_crtc *crtc) +{ +struct spacemit_crtc_state *state; +struct spacemit_drm_private *priv = crtc->dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; +u8 n_rdma; + +if (WARN_ON (!crtc->state)) +return NULL ; + + state =kzalloc_obj (*state); +if (!state) +return NULL ; + +__drm_atomic_helper_crtc_duplicate_state (crtc, &state->base); + + n_rdma = hwdev->rdma_nums; + state->rdmas =kzalloc_objs (*state->rdmas, n_rdma); +if (!state->rdmas) { +kfree (state); +return NULL ; + } + + state->cl.type =CMDLIST_CRTC ; + +return &state->base; +} + +static void spacemit_crtc_destroy_state (struct drm_crtc *crtc, +struct drm_crtc_state *state) +{ +struct spacemit_crtc_state *spacemit_state =NULL ; +struct spacemit_crtc *a_crtc =NULL ; + +if (state) { + spacemit_state =to_spacemit_crtc_state (state); +__drm_atomic_helper_crtc_destroy_state (state); + a_crtc =to_spacemit_crtc (crtc); +if (spacemit_state->cl.va) +dma_free_coherent (a_crtc->dev, + spacemit_state->cl.size, + spacemit_state->cl.va, + spacemit_state->cl.pa); +kfree (spacemit_state->rdmas); +kfree (spacemit_state); + } +} + +static void spacemit_crtc_reset (struct drm_crtc *crtc) +{ +struct spacemit_drm_private *priv = crtc->dev->dev_private; +struct spacemit_hw_device *hwdev = priv->hwdev; +struct spacemit_crtc_state *state; + +if (crtc->state) +spacemit_crtc_destroy_state (crtc, crtc->state); + + state =kzalloc_obj (*state); +if (!state) { +__drm_atomic_helper_crtc_reset (crtc,NULL ); +return ; + } + + state->rdmas =kzalloc_objs (*state->rdmas, hwdev->rdma_nums); +if (!state->rdmas) { +kfree (state); +__drm_atomic_helper_crtc_reset (crtc,NULL ); +return ; + } + +__drm_atomic_helper_crtc_reset (crtc, &state->base); +} + +static int spacemit_crtc_enable_vblank (struct drm_crtc *crtc) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); + +trace_spacemit_crtc_enable_vblank (a_crtc->dev_id); + +if (a_crtc->core && a_crtc->core->enable_vsync) + a_crtc->core->enable_vsync (a_crtc); + +return 0 ; +} + +static void spacemit_crtc_disable_vblank (struct drm_crtc *crtc) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); + +trace_spacemit_crtc_disable_vblank (a_crtc->dev_id); + +if (a_crtc->core && a_crtc->core->disable_vsync) + a_crtc->core->disable_vsync (a_crtc); +} + +static const struct drm_crtc_helper_funcs spacemit_crtc_helper_funcs = { + .atomic_check = spacemit_crtc_atomic_check, + .atomic_begin = spacemit_crtc_atomic_begin, + .atomic_flush = spacemit_crtc_atomic_flush, + .atomic_enable = spacemit_crtc_atomic_enable, + .atomic_disable = spacemit_crtc_atomic_disable, +}; + +static const struct drm_crtc_funcs spacemit_crtc_funcs = { + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .reset = spacemit_crtc_reset, + .atomic_duplicate_state = spacemit_crtc_duplicate_state, + .atomic_destroy_state = spacemit_crtc_destroy_state, + .enable_vblank = spacemit_crtc_enable_vblank, + .disable_vblank = spacemit_crtc_disable_vblank, +}; + +static void spacemit_crtc_put_port (struct drm_device *drm,void *port) +{ +of_node_put (port); +} + +static int spacemit_crtc_bind_init (struct drm_device *drm,struct drm_crtc *crtc, +struct drm_plane *primary,struct device_node *port) +{ +int err; + +/* +* drm_of_find_possible_crtcs() walks crtc->port for the life of the +* drm_device. +*/ + crtc->port =of_node_get (port); + err =drmm_add_action_or_reset (drm, spacemit_crtc_put_port, port); +if (err) +return err; + + err =drm_crtc_init_with_planes (drm, crtc, primary,NULL , + &spacemit_crtc_funcs,NULL ); +if (err) { +drm_err (drm,"failed to init crtc\n" ); +return err; + } + +drm_mode_crtc_set_gamma_size (crtc,256 ); + +drm_crtc_helper_add (crtc, &spacemit_crtc_helper_funcs); + +return 0 ; +} + +int spacemit_crtc_run (struct drm_crtc *crtc, +struct drm_crtc_state *old_state) +{ +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); + +trace_spacemit_crtc_run (a_crtc->dev_id); + +if (a_crtc->core && a_crtc->core->run) + a_crtc->core->run (crtc, old_state); + +return 0 ; +} + +static int spacemit_crtc_init (struct spacemit_crtc *a_crtc) +{ +trace_spacemit_crtc_init (a_crtc->dev_id); + +if (a_crtc->core && a_crtc->core->init) + a_crtc->core->init (a_crtc); + + a_crtc->is_1st_f = true; + +return 0 ; +} + +static int spacemit_crtc_uninit (struct spacemit_crtc *a_crtc) +{ +trace_spacemit_crtc_uninit (a_crtc->dev_id); + +if (a_crtc->core && a_crtc->core->uninit) + a_crtc->core->uninit (a_crtc); + +return 0 ; +} + +static irqreturn_t spacemit_dpu_isr (int irq,void *data) +{ +struct spacemit_drm_private *priv = data; +struct spacemit_crtc *a_crtc = priv->a_crtc; +int idx; + +if (!a_crtc) +return IRQ_NONE ; + +if (!drm_dev_enter (a_crtc->crtc.dev, &idx)) +return IRQ_NONE ; + +/* Reading a clock-gated DPU's status registers stalls the bus. */ +if (unlikely (!a_crtc->clocks_on)) { +drm_dev_exit (idx); +return IRQ_NONE ; + } + +if (a_crtc->core && a_crtc->core->online_isr) + a_crtc->core->online_isr (a_crtc); + +drm_dev_exit (idx); + +return IRQ_HANDLED ; +} + +/* +* Acquire at probe, not at bind: the aggregate can rebind without this device +* detaching, and the exclusive resets would not be handed out a second time. +*/ +static int spacemit_dpu_hw_resources_init (struct spacemit_drm_private *priv, +struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +int ret; + + ret =dpu_parse_clocks (dev, &priv->clk_ctx); +if (ret) +return ret; + + priv->mclk_reset =devm_reset_control_get_optional_exclusive (dev, +"mclk" ); +if (IS_ERR (priv->mclk_reset)) +return dev_err_probe (dev,PTR_ERR (priv->mclk_reset), +"failed to get mclk reset\n" ); + priv->esc_reset =devm_reset_control_get_optional_exclusive (dev,"esc" ); +if (IS_ERR (priv->esc_reset)) +return dev_err_probe (dev,PTR_ERR (priv->esc_reset), +"failed to get esc reset\n" ); + priv->lcd_reset =devm_reset_control_get_optional_exclusive (dev,"lcd" ); +if (IS_ERR (priv->lcd_reset)) +return dev_err_probe (dev,PTR_ERR (priv->lcd_reset), +"failed to get lcd reset\n" ); + priv->aclk_reset =devm_reset_control_get_optional_exclusive (dev, +"aclk" ); +if (IS_ERR (priv->aclk_reset)) +return dev_err_probe (dev,PTR_ERR (priv->aclk_reset), +"failed to get aclk reset\n" ); + priv->dsc_reset =devm_reset_control_get_optional_exclusive (dev,"dsc" ); +if (IS_ERR (priv->dsc_reset)) +return dev_err_probe (dev,PTR_ERR (priv->dsc_reset), +"failed to get dsc reset\n" ); + + priv->irq_online =platform_get_irq_byname (pdev,"online" ); +if (priv->irq_online <0 ) +return priv->irq_online; + +/* +* Keep the line disabled until bind: the handler needs bind-created +* state, and a bootloader-left display can raise an interrupt during +* probe. +*/ + ret =devm_request_irq (dev, priv->irq_online, spacemit_dpu_isr, +IRQF_NO_AUTOEN ,"DPU_ONLINE" , priv); +if (ret) +return dev_err_probe (dev, ret, +"failed to request online IRQ\n" ); + +return 0 ; +} + +static const struct regmap_config spacemit_dpu_regmap_config = { + .name ="dpu" , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =0x53ffc ,/* 0x54000-byte DPU MMIO from binding */ +}; + +/* Bind-scope wrapper so devm_drm_dev_alloc has a struct to embed into. */ +struct spacemit_kms { +struct drm_device drm; +}; + +static int spacemit_drm_master_bind (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev); +struct device_node *np = dev->of_node; +struct device_node *ports =NULL , *port =NULL ; +struct spacemit_crtc *a_crtc; +struct drm_plane *plane; +struct spacemit_kms *kms; +struct drm_device *drm; +int ret; + + ret =aperture_remove_all_conflicting_devices (spacemit_drm_drv.name); +if (ret) { +dev_err (dev,"failed to remove existing framebuffers: %d\n" , + ret); +return ret; + } + + kms =devm_drm_dev_alloc (dev, &spacemit_drm_drv, + struct spacemit_kms, drm); +if (IS_ERR (kms)) +return PTR_ERR (kms); + drm = &kms->drm; + priv->ddev = drm; + drm->dev_private = priv; + + ret =spacemit_drm_mode_config_init (drm); +if (ret) +return ret; + + a_crtc =drmm_kzalloc (drm,sizeof (*a_crtc),GFP_KERNEL ); +if (!a_crtc) { + ret = -ENOMEM ; + goto err_dc; + } + a_crtc->dev = dev; + a_crtc->first_modeset = true; + priv->a_crtc = a_crtc; + + a_crtc->clk_ctx = priv->clk_ctx; + a_crtc->aclk =DPU_AXICLK_DEFAULT ; + a_crtc->mclk_reset = priv->mclk_reset; + a_crtc->esc_reset = priv->esc_reset; + a_crtc->lcd_reset = priv->lcd_reset; + a_crtc->aclk_reset = priv->aclk_reset; + a_crtc->dsc_reset = priv->dsc_reset; + a_crtc->irq_online = priv->irq_online; + +/* Both K3 DPU instances are COMPOSER1 in the Saturn IRQ tables. */ + a_crtc->dev_id =COMPOSER1 ; + +/* The K3 pipeline always hands RGB888 to the DP/eDP encoder. */ + a_crtc->out_format =OUTFMT_RGB888 ; + + a_crtc->core = &dpu_saturn_ops; + +timer_setup (&a_crtc->cfg_rdy_timer, spacemit_cfg_rdy_timer_handler,0 ); + + plane =spacemit_plane_init (drm, a_crtc); +if (IS_ERR (plane)) { + ret =PTR_ERR (plane); + goto err_dc; + } + + ports =of_get_child_by_name (np,"ports" ); +if (!ports) { +dev_err (dev,"CRTC %pOF has no ports node\n" , np); + ret = -EINVAL ; + goto err_dc; + } + + port =of_get_child_by_name (ports,"port" ); +if (!port) { +dev_err (dev,"CRTC %pOF has no port@X node\n" , np); + ret = -EINVAL ; + goto err_ports_put; + } + + ret =spacemit_crtc_bind_init (drm, &a_crtc->crtc, plane, port); +of_node_put (port); +of_node_put (ports); + port =NULL ; + ports =NULL ; +if (ret) + goto err_dc; + +/* +* component_bind_all() unbinds what it bound before returning an error. +*/ + ret =component_bind_all (dev, drm); +if (ret) { +dev_err (dev,"failed to bind all components\n" ); + goto err_dc; + } + + ret =drm_vblank_init (drm, drm->mode_config.num_crtc); +if (ret) { +dev_err (dev,"failed to initialize vblank\n" ); + goto err_unbind_all; + } + +drm_mode_config_reset (drm); +drmm_kms_helper_poll_init (drm); +drm_helper_hpd_irq_event (drm); + +enable_irq (priv->irq_online); + + ret =drm_dev_register (drm,0 ); +if (ret <0 ) + goto err_disable_irq; +drm_client_setup (drm,NULL ); + +return 0 ; + +err_disable_irq: +disable_irq (priv->irq_online); + +err_unbind_all: +component_unbind_all (dev, drm); + goto err_dc; +err_ports_put: +of_node_put (port); +of_node_put (ports); +err_dc: +/* +* .shutdown tests priv->ddev; never leave it on a half-initialised +* device. +*/ + priv->ddev =NULL ; + priv->a_crtc =NULL ; +return ret; +} + +static void spacemit_drm_master_unbind (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev); +struct drm_device *drm = priv->ddev; + +disable_irq (priv->irq_online); + +drm_dev_unregister (drm); +drm_atomic_helper_shutdown (drm); +component_unbind_all (dev, drm); + +/* .shutdown and a later re-bind must not touch the stale instance. */ + priv->ddev =NULL ; + priv->a_crtc =NULL ; +} + +const struct component_master_ops spacemit_drm_master_ops = { + .bind = spacemit_drm_master_bind, + .unbind = spacemit_drm_master_unbind, +}; + +static int spacemit_dpu_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +const struct spacemit_hw_device *hwdev_template; +struct spacemit_drm_private *priv; +struct device_node *np = dev->of_node; +int ret; + +if (!np) { +dev_err (dev,"no OF node for the DPU\n" ); +return -ENODEV ; + } + + ret =dma_coerce_mask_and_coherent (dev,DMA_BIT_MASK (64 )); +if (ret) +return dev_err_probe (dev, ret,"failed to set DMA mask\n" ); + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->dev = dev; +dev_set_drvdata (dev, priv); + +/* The match data is shared const; the MMIO mapping is per-instance. */ + hwdev_template =device_get_match_data (dev); +if (!hwdev_template) +return -ENODEV ; + priv->hwdev =devm_kmemdup (dev, hwdev_template, +sizeof (*hwdev_template),GFP_KERNEL ); +if (!priv->hwdev) +return -ENOMEM ; + + priv->cmdlist_groups =devm_kcalloc (dev, + priv->hwdev->rdma_nums + priv->hwdev->crtc_nums, +sizeof (*priv->cmdlist_groups),GFP_KERNEL ); +if (!priv->cmdlist_groups) +return -ENOMEM ; + + priv->hwdev->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (priv->hwdev->base)) +return PTR_ERR (priv->hwdev->base); + + priv->hwdev->regmap =devm_regmap_init_mmio (dev, priv->hwdev->base, + &spacemit_dpu_regmap_config); +if (IS_ERR (priv->hwdev->regmap)) +return dev_err_probe (dev,PTR_ERR (priv->hwdev->regmap), +"failed to init DPU regmap\n" ); + + ret =spacemit_dpu_hw_resources_init (priv, pdev); +if (ret) +return ret; + +return spacemit_drm_of_component_probe (dev); +} + +static void spacemit_dpu_remove (struct platform_device *pdev) +{ +component_master_del (&pdev->dev, &spacemit_drm_master_ops); +} + +static void spacemit_dpu_shutdown (struct platform_device *pdev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (&pdev->dev); +struct drm_device *drm = priv->ddev; + +if (!drm) { +dev_warn (&pdev->dev, +"drm device is not available, no shutdown\n" ); +return ; + } + +drm_atomic_helper_shutdown (drm); +} + +/* +* The assert and deassert orders are not mirror images: the hardware wants +* these. +*/ +static void dpu_reset_assert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_assert (rstc); + +if (ret) +dev_warn (dev,"failed to assert %s reset: %d\n" , name, ret); +} + +static void dpu_reset_deassert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_deassert (rstc); + +if (ret) +dev_warn (dev,"failed to deassert %s reset: %d\n" , name, ret); +} + +static int dpu_pm_suspend (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev); +struct spacemit_crtc *a_crtc = priv->a_crtc; + +/* +* Assert before gating: a reset asserted into an already-gated block +* has no clock edges to propagate on and leaves the register file +* untouched. +*/ +dpu_reset_assert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_assert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_assert (dev,"mclk" , a_crtc->mclk_reset); +dpu_reset_assert (dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_assert (dev,"dsc" , a_crtc->dsc_reset); +usleep_range (10000 ,20000 ); + +if (a_crtc->core && a_crtc->core->disable_clk) + a_crtc->core->disable_clk (a_crtc); + +return 0 ; +} + +static int dpu_pm_resume (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev); +struct spacemit_crtc *a_crtc = priv->a_crtc; + +dpu_reset_deassert (dev,"mclk" , a_crtc->mclk_reset); +dpu_reset_deassert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_deassert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_deassert (dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_deassert (dev,"dsc" , a_crtc->dsc_reset); + +if (a_crtc->core && a_crtc->core->enable_clk) + a_crtc->core->enable_clk (a_crtc); + +return 0 ; +} + +static const struct of_device_id dpu_match_table[] = { + { + .compatible ="spacemit,k3-saturn-dpu" , + .data = &k3_saturn_dpu, + }, + {}, +}; +MODULE_DEVICE_TABLE (of, dpu_match_table); + +static struct platform_driver spacemit_dpu_driver = { + .probe = spacemit_dpu_probe, + .remove = spacemit_dpu_remove, + .shutdown = spacemit_dpu_shutdown, + .driver = { + .name ="spacemit-dpu-drv" , + .of_match_table = dpu_match_table, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver (spacemit_dpu_driver); + +MODULE_DESCRIPTION ("SpacemiT DRM KMS master driver" ); +MODULE_LICENSE ("GPL" );
drivers/gpu/drm/spacemit/spacemit_planes.c new file +376 -0
376 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider: - [High] Sleeping functions are called from CRTC atomic enable and disable callbacks, which execute in…
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
- [High] Sleeping functions are called from CRTC atomic enable and disable callbacks, which execute in atomic context.
- [High] TOCTOU race when updating the clocks_on flag and gating hardware clocks leads to MMIO stalls.
- [High] Calling devm_drm_dev_alloc inside a component bind callback leaks the DRM device on rebinds.
- [High] Enabling the DPU interrupt before hardware is initialized leads to an unhandled IRQ storm.
- [High] spacemit_plane_reset bypasses the custom state destructor, leaking DMA coherent memory.
- [High] disable_irq() is called before drm_atomic_helper_shutdown() during driver unbind, causing shutdown to hang.
- [High] spacemit_plane_atomic_check() assigns RDMA channels based on unvalidated zpos, leading to channel collisions.
- [High] Unconditional spin_unlock_irq used in atomic context improperly re-enables interrupts.
- [Medium] Leaking DRM property blob references in spacemit_crtc_duplicate_state on error.
- [Medium] Missing NULL check on plane->state in spacemit_plane_atomic_duplicate_state causes a crash if the state is missing. --
--- Patch [10]: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline --- commit cf6665928c2c5fcf07a88c5cd2141feb18245e17
Author: Cody Kang <[email protected]>
Subject: drm/spacemit: add Saturn DPU KMS pipeline
Add the atomic KMS implementation on top of the hardware backend: one CRTC and one primary plane per DPU instance. atomic_check validates the plane rectangle 1:1 against the mode and sizes the per-channel FBC line buffer.
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_crtc_atomic_enable(struct drm_crtc *crtc, · line 96
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -91,7 +91,7 @@ static void spacemit_crtc_atomic_enable(struct drm_crtc *crtc,dpu_reset_assert (a_crtc->dev,"lcd" , a_crtc->lcd_reset);dpu_reset_assert (a_crtc->dev,"esc" , a_crtc->esc_reset);dpu_reset_assert (a_crtc->dev,"mclk" , a_crtc->mclk_reset);dpu_reset_assert (a_crtc->dev,"aclk" , a_crtc->aclk_reset);dpu_reset_assert (a_crtc->dev,"dsc" , a_crtc->dsc_reset);usleep_range (10000 ,20000 );
[Severity: High]
Does this sleep in an atomic context? The spacemit_crtc_atomic_enable callback is executed during a non-blocking DRM atomic commit, which runs in an atomic context. Calling usleep_range() here might violate atomic context rules and lead to scheduling-while-atomic warnings.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc, · line 149
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -145,13 +145,13 @@ static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc,* must finish its status reads before dpu_pm_suspend() gates the * clocks. */ if (a_crtc->irq_online >0 )synchronize_irq (a_crtc->irq_online);
[Severity: High]
Can synchronize_irq() safely execute here? This callback runs in an atomic context, but synchronize_irq() blocks waiting for executing handlers.
[Severity: High]
Does this code leave a race window before the flags are updated? An interrupt could fire immediately after synchronize_irq() returns but before clocks_on is toggled to false, leading the ISR to access MMIO while dpu_pm_suspend() is shutting down the clocks.
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc, · line 157
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0/* * Nothing else cancels the watchdog; it would fire against freed state. */ timer_delete_sync (&a_crtc->cfg_rdy_timer);/* Close the ISR's MMIO gate before the clocks actually stop. */ a_crtc->clocks_on = false;dpu_pm_suspend (a_crtc->dev);
[Severity: High]
Does dpu_pm_suspend() sleep in this atomic context? It calls usleep_range() which could trigger kernel warnings and deadlocks when reached via spacemit_crtc_atomic_disable().
drivers/gpu/drm/spacemit/spacemit_crtc.c
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0spin_lock_irq (&drm->event_lock);if (crtc->state->event) {drm_crtc_send_vblank_event (crtc, crtc->state->event); crtc->state->event =NULL ; }spin_unlock_irq (&drm->event_lock);
[Severity: High]
Is it safe to use unconditional spin_unlock_irq() here? Since this callback executes in an atomic context (e.g. from drm_atomic_helper_commit_tail), unconditionally re-enabling interrupts breaks the caller's atomic assumptions. Should this use spin_lock_irqsave() and spin_unlock_irqrestore() instead?
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static struct drm_crtc_state *
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -231,6 +231,5 @@ static struct drm_crtc_state *__drm_atomic_helper_crtc_duplicate_state (crtc, &state->base); n_rdma = hwdev->rdma_nums; state->rdmas =kzalloc_objs (*state->rdmas, n_rdma);if (!state->rdmas) {kfree (state);return NULL ; }
[Severity: Medium]
Does this error path leak DRM property blob references? __drm_atomic_helper_crtc_duplicate_state() increments references on blobs like mode_blob, ctm, and gamma_lut. Returning NULL here without releasing them could leak those references.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static irqreturn_t spacemit_dpu_isr(int irq, void *data) · line 422
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -418,6 +418,5 @@ static irqreturn_t spacemit_dpu_isr(int irq, void *data)/* Reading a clock-gated DPU's status registers stalls the bus. */ if (unlikely (!a_crtc->clocks_on)) {drm_dev_exit (idx);return IRQ_NONE ; }
[Severity: High]
Does this code cause an IRQ storm? By returning IRQ_NONE without clearing the hardware interrupt status when clocks_on is false, the interrupt controller might continuously re-trigger the ISR if the bootloader left the interrupt asserted.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static int spacemit_drm_master_bind(struct device *dev) · line 500
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -496,6 +496,5 @@ static int spacemit_drm_master_bind(struct device *dev) } kms =devm_drm_dev_alloc (dev, &spacemit_drm_drv, struct spacemit_kms, drm);if (IS_ERR (kms))
[Severity: High]
Will this leak the DRM device on rebind? devm_drm_dev_alloc ties the allocation lifetime to the platform device's probe/remove cycle. If the component unbinds and rebinds, new DRM devices are allocated but the old ones are never freed.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static int spacemit_drm_master_bind(struct device *dev) · line 577
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -573,6 +573,5 @@ static int spacemit_drm_master_bind(struct device *dev)drm_mode_config_reset (drm);drmm_kms_helper_poll_init (drm);drm_helper_hpd_irq_event (drm);enable_irq (priv->irq_online);
[Severity: High]
Is it safe to enable the IRQ before the hardware state is fully initialized? If the bootloader left the display hardware active, the ISR might fire immediately while a_crtc->clocks_on is still false, leading to the IRQ storm mentioned above.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_drm_master_unbind(struct device *dev)
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -594,6 +594,5 @@ static void spacemit_drm_master_unbind(struct device *dev)disable_irq (priv->irq_online);drm_dev_unregister (drm);drm_atomic_helper_shutdown (drm);component_unbind_all (dev, drm);
[Severity: High]
Will calling drm_atomic_helper_shutdown() hang if the IRQ is already disabled? The shutdown helper flushes pending atomic commits and disables CRTCs, which requires the hardware vblank interrupt to signal completion. Without it, the commit wait could time out.
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0
[ ... ]
drivers/gpu/drm/spacemit/spacemit_planes.c static int spacemit_plane_atomic_check(struct drm_plane *plane, · line 102
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0@@ -98,6 +98,5 @@ static int spacemit_plane_atomic_check(struct drm_plane *plane,if (src_w ==0 && src_h ==0 ) cur_rdma_id =RDMA_INVALID_ID ;/* constant-fill layer, no RDMA */ else if (cur_rdma_id ==RDMA_INVALID_ID ) cur_rdma_id = state->zpos;/* first commit: bind channel by zpos */ cur_state->rdma_id = cur_rdma_id;
[Severity: High]
Does this code assign RDMA channels based on unvalidated zpos? Userspace could submit a configuration with duplicate zpos values across multiple planes, resulting in channel collisions where planes overwrite each other's hardware registers during spacemit_plane_atomic_update().
[ ... ]
drivers/gpu/drm/spacemit/spacemit_planes.c static void spacemit_plane_reset(struct drm_plane *plane) · line 198
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0@@ -193,7 +193,6 @@ static void spacemit_plane_reset(struct drm_plane *plane)if (plane->state) { s =to_spacemit_plane_state (plane->state);__drm_atomic_helper_plane_destroy_state (plane->state);kfree (s); plane->state =NULL ; }
[Severity: High]
Does freeing the state directly bypass the driver's custom destructor? Calling kfree(s) directly in spacemit_plane_reset() skips spacemit_plane_atomic_destroy_state(), which means the DMA coherent buffers for mmu_tbl.va and cl.va could be permanently leaked when a plane is reset.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_planes.c static struct drm_plane_state *
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0@@ -211,6 +211,5 @@ static struct drm_plane_state * spacemit_plane_atomic_duplicate_state(struct drm_plane *plane) {struct spacemit_plane_state *s;struct spacemit_plane_state *old_state =to_spacemit_plane_state (plane->state);struct spacemit_crtc *a_crtc =NULL ;
[Severity: Medium]
Will this crash if plane->state is NULL? The to_spacemit_plane_state() macro uses container_of, which will produce a negative pointer if plane->state is NULL. Dereferencing old_state->rdma_id later would trigger a fault.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline
Quoted 31 lines · On Sat, 25 Jul 2026 05:04:26 +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
- [High] Sleeping functions are called from CRTC atomic enable and disable callbacks, which execute in atomic context.
- [High] TOCTOU race when updating theclocks_onflag and gating hardware clocks leads to MMIO stalls.
- [High] Callingdevm_drm_dev_allocinside a componentbindcallback leaks the DRM device on rebinds.
- [High] Enabling the DPU interrupt before hardware is initialized leads to an unhandled IRQ storm.
- [High]spacemit_plane_resetbypasses the custom state destructor, leaking DMA coherent memory.
- [High]disable_irq()is called beforedrm_atomic_helper_shutdown()during driver unbind, causing shutdown to hang.
- [High]spacemit_plane_atomic_check()assigns RDMA channels based on unvalidatedzpos, leading to channel collisions.
- [High] Unconditionalspin_unlock_irqused in atomic context improperly re-enables interrupts.
- [Medium] Leaking DRM property blob references inspacemit_crtc_duplicate_stateon error.
- [Medium] Missing NULL check onplane->stateinspacemit_plane_atomic_duplicate_statecauses a crash if the state is missing. ----- Patch [10]: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline --- commit
cf6665928c2c5fcf07a88c5cd2141feb18245e17
Author: Cody Kang <[email protected]>
Subject: drm/spacemit: add Saturn DPU KMS pipelineAdd the atomic KMS implementation on top of the hardware backend: one CRTC and one primary plane per DPU instance.
atomic_checkvalidates the plane rectangle 1:1 against the mode and sizes the per-channel FBC line buffer.Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0[ ... ]
Quoted 13 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_crtc_atomic_enable(struct drm_crtc *crtc, · line 96
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -91,7 +91,7 @@ static void spacemit_crtc_atomic_enable(struct drm_crtc *crtc,dpu_reset_assert (a_crtc->dev,"lcd" , a_crtc->lcd_reset);dpu_reset_assert (a_crtc->dev,"esc" , a_crtc->esc_reset);dpu_reset_assert (a_crtc->dev,"mclk" , a_crtc->mclk_reset);dpu_reset_assert (a_crtc->dev,"aclk" , a_crtc->aclk_reset);dpu_reset_assert (a_crtc->dev,"dsc" , a_crtc->dsc_reset);usleep_range (10000 ,20000 );[Severity: High]
Does this sleep in an atomic context? Thespacemit_crtc_atomic_enablecallback is executed during a non-blocking DRM atomic commit, which runs in an atomic context. Callingusleep_range()here might violate atomic context rules and lead to scheduling-while-atomic warnings.
atomic_enable runs from the commit tail worker, which is process context; sleeping is allowed.
Quoted 12 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc, · line 149
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -145,13 +145,13 @@ static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc,* must finish its status reads before dpu_pm_suspend() gates the * clocks. */ if (a_crtc->irq_online >0 )synchronize_irq (a_crtc->irq_online);[Severity: High]
Cansynchronize_irq()safely execute here? This callback runs in an atomic context, butsynchronize_irq()blocks waiting for executing handlers.
atomic_disable also runs in the commit tail (process context); synchronize_irq() is legal there.
Quoted 5 lines
[Severity: High]
Does this code leave a race window before the flags are updated? An interrupt could fire immediately aftersynchronize_irq()returns but beforeclocks_onis toggled to false, leading the ISR to access MMIO whiledpu_pm_suspend()is shutting down the clocks.
The DPU cannot raise its interrupt while its own clocks are off, so the window is not exploitable; still, will move the flag update after dpu_pm_resume() in v2.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0/* * Nothing else cancels the watchdog; it would fire against freed state. */ timer_delete_sync (&a_crtc->cfg_rdy_timer);
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc, · line 157
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0/* Close the ISR's MMIO gate before the clocks actually stop. */ a_crtc->clocks_on = false;dpu_pm_suspend (a_crtc->dev);[Severity: High]
Doesdpu_pm_suspend()sleep in this atomic context? It callsusleep_range()which could trigger kernel warnings and deadlocks when reached viaspacemit_crtc_atomic_disable().
Process context, as above.
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0spin_lock_irq (&drm->event_lock);if (crtc->state->event) {drm_crtc_send_vblank_event (crtc, crtc->state->event); crtc->state->event =NULL ; }spin_unlock_irq (&drm->event_lock);
Quoted 5 lines
[Severity: High]
Is it safe to use unconditionalspin_unlock_irq()here? Since this callback executes in an atomic context (e.g. fromdrm_atomic_helper_commit_tail), unconditionally re-enabling interrupts breaks the caller's atomic assumptions. Should this usespin_lock_irqsave()andspin_unlock_irqrestore()instead?
The callback is not entered with interrupts disabled (commit tail); the event_lock pattern here matches the drm helpers' own usage.
Quoted 5 lines
[ ... ]
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -231,6 +231,5 @@ static struct drm_crtc_state *__drm_atomic_helper_crtc_duplicate_state (crtc, &state->base);
Quoted 12 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c static struct drm_crtc_state *
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0n_rdma = hwdev->rdma_nums; state->rdmas =kzalloc_objs (*state->rdmas, n_rdma);if (!state->rdmas) {kfree (state);return NULL ; }[Severity: Medium]
Does this error path leak DRM property blob references?__drm_atomic_helper_crtc_duplicate_state()increments references on blobs likemode_blob, ctm, andgamma_lut. Returning NULL here without releasing them could leak those references.
Real; will fix in v2 with __drm_atomic_helper_crtc_destroy_state() on that error path.
Quoted 14 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c static irqreturn_t spacemit_dpu_isr(int irq, void *data) · line 422
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -418,6 +418,5 @@ static irqreturn_t spacemit_dpu_isr(int irq, void *data)/* Reading a clock-gated DPU's status registers stalls the bus. */ if (unlikely (!a_crtc->clocks_on)) {drm_dev_exit (idx);return IRQ_NONE ; }[Severity: High]
Does this code cause an IRQ storm? By returningIRQ_NONEwithout clearing the hardware interrupt status whenclocks_onis false, the interrupt controller might continuously re-trigger the ISR if the bootloader left the interrupt asserted.
Only reachable in the unbind window where the line is being torn down; otherwise the ISR acks all status it observes.
Quoted 5 lines
[ ... ]
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -496,6 +496,5 @@ static int spacemit_drm_master_bind(struct device *dev) }
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c static int spacemit_drm_master_bind(struct device *dev) · line 500
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0kms =devm_drm_dev_alloc (dev, &spacemit_drm_drv, struct spacemit_kms, drm);if (IS_ERR (kms))[Severity: High]
Will this leak the DRM device on rebind?devm_drm_dev_allocties the allocation lifetime to the platform device's probe/remove cycle. If the component unbinds and rebinds, new DRM devices are allocated but the old ones are never freed.
A known trade-off of devm on the component master: the device is unregistered at unbind and the memory is bounded by the platform device lifetime.
Quoted 7 lines
[ ... ]
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -573,6 +573,5 @@ static int spacemit_drm_master_bind(struct device *dev)drm_mode_config_reset (drm);drmm_kms_helper_poll_init (drm);drm_helper_hpd_irq_event (drm);
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c static int spacemit_drm_master_bind(struct device *dev) · line 577
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0enable_irq (priv->irq_online);[Severity: High]
Is it safe to enable the IRQ before the hardware state is fully initialized? If the bootloader left the display hardware active, the ISR might fire immediately whilea_crtc->clocks_onis still false, leading to the IRQ storm mentioned above.
The ISR is gated on clocks_on and drm_dev_enter, and every board cycle boots through this path; no storm has been observed.
Quoted 6 lines
[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -594,6 +594,5 @@ static void spacemit_drm_master_unbind(struct device *dev)disable_irq (priv->irq_online);
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c static void spacemit_drm_master_unbind(struct device *dev)
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0drm_dev_unregister (drm);drm_atomic_helper_shutdown (drm);component_unbind_all (dev, drm);[Severity: High]
Will callingdrm_atomic_helper_shutdown()hang if the IRQ is already disabled? The shutdown helper flushes pending atomic commits and disables CRTCs, which requires the hardware vblank interrupt to signal completion. Without it, the commit wait could time out.
Confirmed on hardware: the fbdev-restore commit arms the CFG_RDY handshake after the line is dead, and every unload rode two watchdog timeouts. Will reorder in v2: unregister and shutdown before disable_irq().
Quoted 8 lines
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0[ ... ]
Quoted 12 lines
drivers/gpu/drm/spacemit/spacemit_planes.c static int spacemit_plane_atomic_check(struct drm_plane *plane, · line 102
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0@@ -98,6 +98,5 @@ static int spacemit_plane_atomic_check(struct drm_plane *plane,if (src_w ==0 && src_h ==0 ) cur_rdma_id =RDMA_INVALID_ID ;/* constant-fill layer, no RDMA */ else if (cur_rdma_id ==RDMA_INVALID_ID ) cur_rdma_id = state->zpos;/* first commit: bind channel by zpos */ cur_state->rdma_id = cur_rdma_id;[Severity: High]
Does this code assign RDMA channels based on unvalidated zpos? Userspace could submit a configuration with duplicate zpos values across multiple planes, resulting in channel collisions where planes overwrite each other's hardware registers duringspacemit_plane_atomic_update().
There is a single primary plane per CRTC, so no collision is possible; rdma_id is also bounds-checked in atomic_check.
Quoted 15 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_planes.c static void spacemit_plane_reset(struct drm_plane *plane) · line 198
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0@@ -193,7 +193,6 @@ static void spacemit_plane_reset(struct drm_plane *plane)if (plane->state) { s =to_spacemit_plane_state (plane->state);__drm_atomic_helper_plane_destroy_state (plane->state);kfree (s); plane->state =NULL ; }[Severity: High]
Does freeing the state directly bypass the driver's custom destructor? Calling kfree(s) directly inspacemit_plane_reset()skipsspacemit_plane_atomic_destroy_state(), which means the DMA coherent buffers for mmu_tbl.va and cl.va could be permanently leaked when a plane is reset.
Real; will route .reset through the custom destroy in v2, the same way the CRTC side already does.
Quoted 15 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_planes.c static struct drm_plane_state *
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0
-0@@ -211,6 +211,5 @@ static struct drm_plane_state * spacemit_plane_atomic_duplicate_state(struct drm_plane *plane) {struct spacemit_plane_state *s;struct spacemit_plane_state *old_state =to_spacemit_plane_state (plane->state);struct spacemit_crtc *a_crtc =NULL ;[Severity: Medium]
Will this crash ifplane->stateis NULL? Theto_spacemit_plane_state()macro usescontainer_of, which will produce a negative pointer ifplane->stateis NULL. Dereferencingold_state->rdma_idlater would trigger a fault.
The core only calls duplicate_state with an existing state; this is the same contract the helpers themselves rely on.
Cody
Re: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline
In reply to Cody KangQuoted 21 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Add the atomic KMS implementation on top of the hardware backend: one CRTC and one primary plane per DPU instance.
atomic_checkvalidates the plane rectangle 1:1 against the mode and sizes the per-channel FBC line buffer; atomic commit builds the cmdlist batches, maps the framebuffer through the DMMU and arms the cfg-ready handshake, with vblank events driven from the DPU interrupt.Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/spacemit_crtc.c | 815 +++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_planes.c | 376 +++++++++++++ 2 files changed, 1191 insertions(+)drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -0,0 +1,815 @@
[...]
Quoted 25 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +25
-0+/* +* The assert and deassert orders are not mirror images: the hardware wants +* these. +*/ +static void dpu_reset_assert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_assert (rstc); + +if (ret) +dev_warn (dev,"failed to assert %s reset: %d\n" , name, ret); +} + +static void dpu_reset_deassert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_deassert (rstc); + +if (ret) +dev_warn (dev,"failed to deassert %s reset: %d\n" , name, ret); +} + +static int dpu_pm_suspend (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev);
drivers/gpu/drm/spacemit/spacemit_crtc.c line 765
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10
-0+struct spacemit_crtc *a_crtc = priv->a_crtc; + +/* +* Assert before gating: a reset asserted into an already-gated block +* has no clock edges to propagate on and leaves the register file +* untouched. +*/ +dpu_reset_assert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_assert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_assert (dev,"mclk" , a_crtc->mclk_reset);
It looks like these three are mirrored, and could be handled by reset_control_bulk_assert/deassert().
Quoted 16 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +16
-0+dpu_reset_assert (dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_assert (dev,"dsc" , a_crtc->dsc_reset); +usleep_range (10000 ,20000 ); + +if (a_crtc->core && a_crtc->core->disable_clk) + a_crtc->core->disable_clk (a_crtc); + +return 0 ; +} + +static int dpu_pm_resume (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev); +struct spacemit_crtc *a_crtc = priv->a_crtc; + +dpu_reset_deassert (dev,"mclk" , a_crtc->mclk_reset);
drivers/gpu/drm/spacemit/spacemit_crtc.c line 791
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10
-0+dpu_reset_deassert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_deassert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_deassert (dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_deassert (dev,"dsc" , a_crtc->dsc_reset); + +if (a_crtc->core && a_crtc->core->enable_clk) + a_crtc->core->enable_clk (a_crtc); + +return 0 ; +}
regards
Philipp
Re: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline
Quoted 62 lines · Philipp Zabel
Quoted 21 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Add the atomic KMS implementation on top of the hardware backend: one CRTC and one primary plane per DPU instance.
atomic_checkvalidates the plane rectangle 1:1 against the mode and sizes the per-channel FBC line buffer; atomic commit builds the cmdlist batches, maps the framebuffer through the DMMU and arms the cfg-ready handshake, with vblank events driven from the DPU interrupt.Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/spacemit_crtc.c | 815 +++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_planes.c | 376 +++++++++++++ 2 files changed, 1191 insertions(+)drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -0,0 +1,815 @@[...]
Quoted 25 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +25
-0+/* +* The assert and deassert orders are not mirror images: the hardware wants +* these. +*/ +static void dpu_reset_assert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_assert (rstc); + +if (ret) +dev_warn (dev,"failed to assert %s reset: %d\n" , name, ret); +} + +static void dpu_reset_deassert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_deassert (rstc); + +if (ret) +dev_warn (dev,"failed to deassert %s reset: %d\n" , name, ret); +} + +static int dpu_pm_suspend (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev);drivers/gpu/drm/spacemit/spacemit_crtc.c line 765
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10
-0+struct spacemit_crtc *a_crtc = priv->a_crtc; + +/* +* Assert before gating: a reset asserted into an already-gated block +* has no clock edges to propagate on and leaves the register file +* untouched. +*/ +dpu_reset_assert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_assert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_assert (dev,"mclk" , a_crtc->mclk_reset);It looks like these three are mirrored, and could be handled by reset_control_bulk_assert/deassert().
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c line 767
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +2
-0+dpu_reset_assert (dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_assert (dev,"dsc" , a_crtc->dsc_reset);
Is there a reason these two cannot be mirrored in order? Please double check. As I checked the vendor tree, the suspend/resume side appear to be copy/paste rather than a deliberate ordering.
Please double-check. Unless I'm missing something, I suggest to bulk them.
Thanks,
Guodong
Quoted 27 lines
Quoted 14 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +14
-0+usleep_range (10000 ,20000 ); + +if (a_crtc->core && a_crtc->core->disable_clk) + a_crtc->core->disable_clk (a_crtc); + +return 0 ; +} + +static int dpu_pm_resume (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev); +struct spacemit_crtc *a_crtc = priv->a_crtc; + +dpu_reset_deassert (dev,"mclk" , a_crtc->mclk_reset);drivers/gpu/drm/spacemit/spacemit_crtc.c line 791
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10
-0+dpu_reset_deassert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_deassert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_deassert (dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_deassert (dev,"dsc" , a_crtc->dsc_reset); + +if (a_crtc->core && a_crtc->core->enable_clk) + a_crtc->core->enable_clk (a_crtc); + +return 0 ; +}regards
Philipp
Re: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline
Quoted 16 lines · Guodong Xu
Quoted 15 lines · Philipp Zabel
drivers/gpu/drm/spacemit/spacemit_crtc.c line 765
Quoted 10 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +8
-0+/* +* Assert before gating: a reset asserted into an already-gated block +* has no clock edges to propagate on and leaves the register file +* untouched. +*/ +dpu_reset_assert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_assert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_assert (dev,"mclk" , a_crtc->mclk_reset);It looks like these three are mirrored, and could be handled by reset_control_bulk_assert/deassert().
Quoted 8 lines
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c line 767
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +2
-0+dpu_reset_assert (dev,"aclk" , a_crtc->aclk_reset); +dpu_reset_assert (dev,"dsc" , a_crtc->dsc_reset);Is there a reason these two cannot be mirrored in order? Please double check. As I checked the vendor tree, the suspend/resume side appear to be copy/paste rather than a deliberate ordering.
Please double-check. Unless I'm missing something, I suggest to bulk them.
Agree, I'll check.
Cody
Re: [PATCH RESEND 10/17] drm/spacemit: add Saturn DPU KMS pipeline
In reply to Philipp ZabelHi Philipp,
Quoted 53 lines · Philipp Zabel
Quoted 21 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Add the atomic KMS implementation on top of the hardware backend: one CRTC and one primary plane per DPU instance.
atomic_checkvalidates the plane rectangle 1:1 against the mode and sizes the per-channel FBC line buffer; atomic commit builds the cmdlist batches, maps the framebuffer through the DMMU and arms the cfg-ready handshake, with vblank events driven from the DPU interrupt.Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/spacemit_crtc.c | 815 +++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_planes.c | 376 +++++++++++++ 2 files changed, 1191 insertions(+)drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0@@ -0,0 +1,815 @@[...]
Quoted 30 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +30
-0+/* +* The assert and deassert orders are not mirror images: the hardware wants +* these. +*/ +static void dpu_reset_assert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_assert (rstc); + +if (ret) +dev_warn (dev,"failed to assert %s reset: %d\n" , name, ret); +} + +static void dpu_reset_deassert (struct device *dev,const char *name, +struct reset_control *rstc) +{ +int ret =reset_control_deassert (rstc); + +if (ret) +dev_warn (dev,"failed to deassert %s reset: %d\n" , name, ret); +} + +static int dpu_pm_suspend (struct device *dev) +{ +struct spacemit_drm_private *priv =dev_get_drvdata (dev); +struct spacemit_crtc *a_crtc = priv->a_crtc; + +/* +* Assert before gating: a reset asserted into an already-gated block +* has no clock edges to propagate on and leaves the register file
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c line 765
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +5
-0+* untouched. +*/ +dpu_reset_assert (dev,"lcd" , a_crtc->lcd_reset); +dpu_reset_assert (dev,"esc" , a_crtc->esc_reset); +dpu_reset_assert (dev,"mclk" , a_crtc->mclk_reset);It looks like these three are mirrored, and could be handled by reset_control_bulk_assert/deassert().
Thanks for the review. Indeed, reset_control_bulk_deassert() walking the array in reverse gives exactly the mirrored order the hardware wants. Will fix in v2.
Cody
PATCH RESEND 11/17 drm/spacemit: add Saturn DPU DRM device driver
In reply to Cody KangAdd the DRM device for the SpacemiT K3 Saturn display processing unit and hook the driver up to the build. The SoC has two DPU instances; each drives one CRTC that scans out a single primary plane in linear RGB at up to 3840x2160@60 and feeds a downstream DP/eDP controller over an OF-graph endpoint. Buffers use drm_gem_shmem_helper. The AFBC/compressed decode path is not exposed and writeback is not implemented.
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/spacemit/Kconfig | 18 +++++ drivers/gpu/drm/spacemit/Makefile | 12 +++ drivers/gpu/drm/spacemit/spacemit_drm.c | 132 ++++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+)
drivers/gpu/drm/Kconfig +1 -0
@@ -341,6 +341,7 @@ source "drivers/gpu/drm/renesas/Kconfig" source "drivers/gpu/drm/rockchip/Kconfig" source "drivers/gpu/drm/sitronix/Kconfig" source "drivers/gpu/drm/solomon/Kconfig" +source "drivers/gpu/drm/spacemit/Kconfig" source "drivers/gpu/drm/sprd/Kconfig" source "drivers/gpu/drm/sti/Kconfig" source "drivers/gpu/drm/stm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -204,6 +204,7 @@ obj-$(CONFIG_DRM_MSM) += msm/ obj-$(CONFIG_DRM_TEGRA) += tegra/ obj-$(CONFIG_DRM_STM) += stm/ obj-$(CONFIG_DRM_STI) += sti/ +obj-$(CONFIG_DRM_SPACEMIT) += spacemit/ obj-y += imx/ obj-$(CONFIG_DRM_INGENIC) += ingenic/ obj-$(CONFIG_DRM_LOGICVC) += logicvc/
drivers/gpu/drm/spacemit/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 + +config DRM_SPACEMIT + tristate "DRM support for SpacemiT display controllers" + depends on DRM && OF && MMU + depends on ARCH_SPACEMIT || COMPILE_TEST + select DRM_CLIENT_SELECTION + select DRM_KMS_HELPER + select DRM_GEM_SHMEM_HELPER + select REGMAP_MMIO + select VIDEOMODE_HELPERS + help + Choose this option if you have a SpacemiT SoC with the Saturn + display processing unit, such as the K3. The DPU scans out + framebuffers through its private display MMU and feeds a + DisplayPort or embedded DisplayPort controller. + + If M is selected the module will be called spacemit-drm.
drivers/gpu/drm/spacemit/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 + +spacemit-drm-y := spacemit_drm.o \ + spacemit_crtc.o \ + spacemit_cmdlist.o \ + spacemit_planes.o \ + spacemit_dmmu.o \ + dpu/dpu_saturn.o \ + dpu/dpu_saturn_hee.o \ + dpu/saturn_fbcmem.o + +obj-$(CONFIG_DRM_SPACEMIT) += spacemit-drm.o
drivers/gpu/drm/spacemit/spacemit_drm.c new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 11/17] drm/spacemit: add Saturn DPU DRM device driver
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Stalling the atomic commit pipeline by calling wait_for_flip_done() before commit_hw_done()…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Stalling the atomic commit pipeline by calling wait_for_flip_done() before commit_hw_done()
- [High] Sleeping functions (usleep_range) called from atomic context in CRTC enable/disable
- [High] Sleeping function called from atomic context in plane update due to missing prepare_fb --
--- Patch [11]: [PATCH RESEND 11/17] drm/spacemit: add Saturn DPU DRM device driver --- commit db43bd6ae677a859cea76ccf2390ca3d109d0fe0
Author: Cody Kang <[email protected]>
drm/spacemit: add Saturn DPU DRM device driver
Add the DRM device for the SpacemiT K3 Saturn display processing unit and hook the driver up to the build. The SoC has two DPU instances; each drives one CRTC that scans out a single primary plane in linear RGB at up to 3840x2160@60 and feeds a downstream DP/eDP controller over an OF-graph endpoint. Buffers use drm_gem_shmem_helper. The AFBC/compressed decode path is not exposed and writeback is not implemented.
[ ... ]
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_drm.c new file +5
-0@@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +* +*/
[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_drm.c new file +4
-0+static void spacemit_drm_atomic_commit_tail (struct drm_atomic_commit *old_state) +{ +struct drm_device *dev = old_state->dev; +
drivers/gpu/drm/spacemit/spacemit_drm.c line 37
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_drm.c new file +10
-0+drm_atomic_helper_commit_modeset_disables (dev, old_state); + +drm_atomic_helper_commit_modeset_enables (dev, old_state); + +drm_atomic_helper_commit_planes (dev, old_state, +DRM_PLANE_COMMIT_ACTIVE_ONLY ); + +drm_atomic_helper_wait_for_flip_done (dev, old_state); + +drm_atomic_helper_commit_hw_done (old_state);
[Severity: High]
Does calling drm_atomic_helper_wait_for_flip_done() before drm_atomic_helper_commit_hw_done() stall the commit pipeline?
drm_atomic_helper_commit_hw_done() signals that the driver has finished programming the hardware, which unblocks subsequent non-blocking atomic commits.
Waiting for the VBLANK page flip to complete before signaling hw_done blocks all subsequent commits, artificially serializing the commit pipeline and defeating the non-blocking design of atomic KMS.
Could this lead to UI stutter and performance regressions?
drivers/gpu/drm/spacemit/spacemit_drm.c line 40
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_drm.c new file +3
-0+ +drm_atomic_helper_cleanup_planes (dev, old_state); +}
I also noticed a few additional regressions in files that appear to be part of this driver series:
[Severity: High]
Are these usleep_range() calls safe in atomic context?
According to DRM subsystem guidelines, CRTC atomic enable/disable callbacks execute in atomic context during non-blocking commits where sleeping is forbidden.
Both spacemit_crtc_atomic_enable() and dpu_pm_suspend() (called from spacemit_crtc_atomic_disable()) invoke usleep_range():
drivers/gpu/drm/spacemit/spacemit_crtc.c:spacemit_crtc_atomic_enable() {
...
dpu_reset_assert(a_crtc->dev, "mclk", a_crtc->mclk_reset);
dpu_reset_assert(a_crtc->dev, "aclk", a_crtc->aclk_reset);
dpu_reset_assert(a_crtc->dev, "dsc", a_crtc->dsc_reset);
usleep_range(10000, 20000);
...
}drivers/gpu/drm/spacemit/spacemit_crtc.c:dpu_pm_suspend() {
...
dpu_reset_assert(dev, "aclk", a_crtc->aclk_reset);
dpu_reset_assert(dev, "dsc", a_crtc->dsc_reset);
usleep_range(10000, 20000);
...
}Calling sleeping functions in this context causes kernel warnings and system instability.
Should non-sleeping delays like udelay() be used instead?
[Severity: High]
Does spacemit_plane_atomic_update() sleep in atomic context?
The DRM subsystem guidelines explicitly state that Plane atomic update callbacks execute in atomic context where sleeping is forbidden.
spacemit_plane_atomic_update() calls spacemit_dmmu_map():
drivers/gpu/drm/spacemit/spacemit_planes.c:spacemit_plane_atomic_update() {
...
ret = spacemit_dmmu_map(plane->state->fb,
&spacemit_pstate->mmu_tbl, tbu_id,
a_crtc->cl_rdma, plane);
...
}which then calls drm_gem_shmem_get_pages_sgt():
drivers/gpu/drm/spacemit/spacemit_dmmu.c:spacemit_dmmu_map() {
...
sgt = drm_gem_shmem_get_pages_sgt(to_drm_gem_shmem_obj(fb->obj[0]));
if (IS_ERR(sgt))
...
}This helper acquires a sleeping mutex via dma_resv_lock_interruptible(). This causes a sleep in atomic context, risking kernel panics.
Should the driver implement a prepare_fb hook (e.g. drm_gem_shmem_plane_helper_prepare_fb) to pin the pages and obtain the SGT outside of the atomic update phase?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
PATCH RESEND 12/17 drm/spacemit: add Innosilicon DP/eDP controller bridge driver
In reply to Cody KangAdd the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree: an eDP panel always sits under an aux-bus child node, an external DP connector never does.
The link is driven through the generic PHY framework, so the controller never touches a PLL register. The controller's HPD interrupt is gated by the DP pixel clock, which can be off exactly when a plug has to be caught, so the connector is also polled and the interrupt path re-reads the live level when it does fire.
--- drivers/gpu/drm/spacemit/Kconfig | 19 + drivers/gpu/drm/spacemit/Makefile | 3 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2443 +++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 ++++ 4 files changed, 2793 insertions(+)
drivers/gpu/drm/spacemit/Kconfig +19 -0
@@ -16,3 +16,22 @@ config DRM_SPACEMIT DisplayPort or embedded DisplayPort controller. If M is selected the module will be called spacemit-drm. + +config SPACEMIT_INNO_DP + tristate "SpacemiT Innosilicon DP/eDP controller support" + depends on DRM_SPACEMIT + imply PHY_SPACEMIT_K3_INNO_DP + select GENERIC_PHY + select DRM_PANEL + select DRM_BRIDGE_CONNECTOR + select DRM_DISPLAY_HELPER + select DRM_DISPLAY_DP_HELPER + select DRM_DISPLAY_DP_AUX_BUS + help + Choose this option to enable the Innosilicon DisplayPort / + embedded DisplayPort transmitter integrated in SpacemiT SoCs. + The controller sits downstream of the Saturn DPU and drives an + eDP panel (discovered over the DP AUX bus) or an external + DisplayPort connector. + + If M is selected the module will be called spacemit-inno-dp.
drivers/gpu/drm/spacemit/Makefile +3 -0
@@ -9,4 +9,7 @@ spacemit-drm-y := spacemit_drm.o \ dpu/dpu_saturn_hee.o \ dpu/saturn_fbcmem.o +spacemit-inno-dp-y := spacemit_inno_dp.o + obj-$(CONFIG_DRM_SPACEMIT) += spacemit-drm.o +obj-$(CONFIG_SPACEMIT_INNO_DP) += spacemit-inno-dp.o
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2443 -0
2,443 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_inno_dp.h new file +328 -0
328 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider: - [High] Custom EDID read function bypasses DRM core and breaks I2C repeated-start (MOT) rules, corrupting…
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [High] Custom EDID read function bypasses DRM core and breaks I2C repeated-start (MOT) rules, corrupting EDID reads for blocks > 0 or on active adapters.
- [High] The hardirq handler returns IRQ_NONE after clearing hardware interrupt flags, permanently disabling the IRQ line.
- [High] Late attachment of the eDP panel bridge violates drm_bridge_connector architecture and breaks panel support if the panel probes asynchronously.
- [High] DP Transfer Unit (TU) miscalculation due to pixel clock truncation.
- [High] The IRQ handler returns IRQ_NONE without clearing the hardware interrupt when drm_dev_enter() fails, leading to an interrupt storm.
- [High] spacemit_dp_bridge_atomic_create_state returns an error pointer instead of NULL on allocation failure, causing a kernel crash in the DRM core.
- [High] The hardirq handler calls regmap functions which use a sleepable lock on PREEMPT_RT.
- [Medium] The atomic_check and mode_valid callbacks access DPCD link capabilities without holding mode_lock, leading to data races with the hotplug IRQ handler.
- [Medium] The DP IRQ handler silently drops hotplug notifications because drm_bridge_hpd_notify() is a no-op when DRM_BRIDGE_OP_HPD is omitted.
- [Medium] Calling clk_set_parent() on an already enabled clock.
- [Medium] Resetting the AUX controller without holding aux->hw_mutex races with concurrent AUX transfers.
--
--- Patch [12]: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver --- commit b7eace372254ab27e120213d38c3a656b2a195b8
Author: Cody Kang <[email protected]>
drm/spacemit: add Innosilicon DP/eDP controller bridge driver
Add the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree.
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -248,16 +248,10 @@static inline struct spacemit_dp_bridge_state *to_spacemit_dp_bridge_state (struct drm_bridge_state *state) {
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0return container_of(state, struct spacemit_dp_bridge_state, base); }static const struct regmap_config spacemit_dp_regmap_config = { .name ="dp" , .reg_bits =32 , .val_bits =32 , .reg_stride =4 , .max_register =0x3ffc ,/* full 0x4000 reg region from binding */ };
[Severity: High]
Is it safe to omit use_raw_spinlock from the regmap configuration? Because this is not set to true, the regmap defaults to a sleepable lock on PREEMPT_RT. This causes a BUG when regmap read/write functions are called from the hardirq handler spacemit_dp_irq_handler().
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 669
Quoted 11 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -661,16 +661,10 @@static void spacemit_dp_link_disable (struct spacemit_dp_dev *dp) {regmap_write_bits (dp->regs,DP_VIDEO_VSAMPLE_REG ,DP_VIDEO_STREAM_ENABLE ,FIELD_PREP (DP_VIDEO_STREAM_ENABLE ,0 ));spacemit_dp_phy_off (dp);regmap_write_bits (dp->regs,DP_SOFT_RESET ,DP_AUX_RESET ,FIELD_PREP (DP_AUX_RESET ,0x1 ));
[Severity: Medium]
Could this reset corrupt concurrent AUX transfers? Modifying the AUX hardware in spacemit_dp_link_disable() without holding the aux->hw_mutex could race against a userspace or deferred transfer, potentially wedging the controller.
Quoted 10 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -936,15 +936,10 @@static void spacemit_dp_hw_set_msa_and_enable_video (struct spacemit_dp_dev *dp,const struct drm_display_mode *mode,enum spacemit_dp_link_rate rate,enum spacemit_dp_lane_count lanes,u32 color_format) {u64 hb_num;u32 link_rate;
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0u32 fp;/* Pixel clock in MHz */ u32 bpp, misc0;u32 tu, tu_frac, tu_int, rd_thres;u32 hsync_len;/* mode->clock unit is kHz, fp unit is MHz */ if (dp->use_ext_pixel_clock) fp = dp->pixel_clock /1000 ;else fp = mode->clock /1000 ;
[Severity: High]
Can this truncation of the pixel clock to an integer MHz value cause DP FIFO underflows or overflows? For non-integer MHz pixel clocks like 148.5 MHz, this truncates to 148, introducing precision errors in the Transfer Unit (TU) calculations which results in corrupted video.
Quoted 5 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1286,13 +1286,10 @@static int spacemit_dp_conn_get_edid_block (void *data,u8 *buf,unsigned int block,size_t len) {
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0struct spacemit_dp_dev *dp = data;unsigned int start = block *EDID_LENGTH ;u8 segment = block >>1 ;int ret, retry;size_t offset;if (segment) {for (retry =0 ; retry <3 ; retry++) { ret =spacemit_dp_aux_i2c_write (dp,SPACEMIT_DP_DDC_SEGMENT_ADDR , &segment,1 );
[Severity: High]
Does this custom EDID read function bypass the Middle-Of-Transaction (MOT) rules for I2C repeated-start? Issuing writes and reads without the MOT flag resets the DDC segment pointer to 0, breaking EDID reads for displays with multiple EDID blocks (block >= 1) or on active adapters.
Quoted 14 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1632,15 +1632,10 @@static int spacemit_dp_bridge_atomic_check (struct drm_bridge *bridge,struct drm_bridge_state *bridge_state,struct drm_crtc_state *crtc_state,struct drm_connector_state *conn_state) {struct spacemit_dp_dev *dp =container_of (bridge, struct spacemit_dp_dev, bridge);struct spacemit_dp_bridge_state *st =to_spacemit_dp_bridge_state (bridge_state);const struct drm_display_mode *mode = &crtc_state->adjusted_mode;int bpp;
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0u32 req_bw;int i;/* A single output bus format, see ->atomic_get_output_bus_fmts(). */ st->color_format =SOC_VIDEO_RGB_8BIT ; bpp =spacemit_dp_get_bpp (dp, st->color_format); req_bw =spacemit_dp_calc_required_bw (mode, bpp);/* No caps yet: leave idx unset and let ->atomic_enable() retry. */ if (!dp->link.max_rate || !dp->link.max_num_lanes) {
[Severity: Medium]
Could reading the DPCD link capabilities here race with the hotplug IRQ handler? Accessing the dp->link capabilities in spacemit_dp_bridge_atomic_check() without holding mode_lock might observe intermediate or torn states if a concurrent interrupt triggers a capability re-read, leading to transient rejections of valid modes.
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1712
Quoted 10 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1705,10 +1705,10 @@static struct drm_bridge_state *spacemit_dp_bridge_atomic_create_state (struct drm_bridge *bridge) {struct spacemit_dp_bridge_state *new; new =kzalloc_obj (*new);if (!new)return ERR_PTR (-ENOMEM );
[Severity: High]
Should this return NULL on allocation failure instead of an error pointer? The DRM core's reset helper assigns the returned state directly without checking for errors. Returning an error pointer here causes a fatal page fault when the DRM core later dereferences it.
Quoted 13 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1742,16 +1742,10 @@static int spacemit_dp_edp_link_panel (struct drm_dp_aux *aux) { struct spacemit_dp_dev *dp = container_of(aux, struct spacemit_dp_dev, aux);struct drm_bridge *next;int ret; next =devm_drm_of_get_bridge (dp->dev, dp->dev->of_node,1 ,0 );if (IS_ERR (next))return PTR_ERR (next);
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0dp->next_bridge = next;/* * A non-NULL bridge.encoder means .attach already ran: late-chain * panel-edp. */ if (dp->bridge.encoder) { ret =drm_bridge_attach (dp->bridge.encoder, next, &dp->bridge,DRM_BRIDGE_ATTACH_NO_CONNECTOR );
[Severity: High]
Does dynamically attaching the panel bridge late bypass connector initialization? If the eDP panel defers its probe, drm_bridge_connector_init() builds the connector without the panel bridge. Attaching it here later violates the drm_bridge_connector architecture and breaks panel support, because the connector will lack the panel's mode or EDID operations.
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1789
Quoted 10 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1782,10 +1782,10 @@static irqreturn_t spacemit_dp_irq_handler (int irq,void *data) {struct spacemit_dp_dev *dp = data;irqreturn_t ret =IRQ_NONE ;int idx;if (!drm_dev_enter (dp->drm, &idx))return IRQ_NONE ;
[Severity: High]
Will returning IRQ_NONE here without clearing the hardware interrupt cause an interrupt storm? If an interrupt fires while the DRM device is unregistered (such as during module unload), the handler exits without acknowledging the hardware interrupt, causing it to continuously fire and stall the CPU.
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 13 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1796,11 +1796,10 @@/* * Only compare here: the authoritative connector_status update * happens in the thread under mode_lock, via .detect(). */ if (spacemit_dp_hw_detect_hpd (dp) !=READ_ONCE (dp->connector_status)) ret =IRQ_WAKE_THREAD ;/* Call hotplug_event */ spacemit_dp_hw_clean_hpd (dp);drm_dev_exit (idx);return ret; }
[Severity: High]
Is it safe to return IRQ_NONE after clearing the hardware interrupt flags? If the logical state has not changed (e.g. from a transient hardware glitch), returning IRQ_NONE causes the kernel's spurious interrupt detector to eventually disable the IRQ line, which results in all future hotplug events being permanently missed.
Quoted 6 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1813,11 +1813,10 @@static irqreturn_t spacemit_dp_hotplug_event_handler (int irq,void *data) {struct spacemit_dp_dev *dp = data;enum drm_connector_status status;
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0int idx;if (!drm_dev_enter (dp->drm, &idx))return IRQ_HANDLED ;/* * .detect() owns mode_lock and re-reads the sink caps on a fresh plug */ status =spacemit_dp_bridge_detect (&dp->bridge, dp->connector);drm_bridge_hpd_notify (&dp->bridge, status);
[Severity: Medium]
Will this hotplug notification be silently dropped? Since DRM_BRIDGE_OP_HPD is not set for the DP bridge during inno_dp_probe(), the bridge->hpd_cb is NULL, making drm_bridge_hpd_notify() a no-op and forcing the DRM core to rely entirely on periodic polling.
Quoted 6 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -2338,10 +2338,15 @@static int inno_dp_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0if (dp->pxclk) { ret =clk_prepare_enable (dp->pxclk);if (ret) {dev_err (dev,"failed to enable pxclk: %d\n" , ret); goto err_reset; } }if (dp->pxclk) { ret =clk_set_parent (dp->pxclk, dp->pll_clk);
[Severity: Medium]
Can calling clk_set_parent() on an already enabled clock cause hardware glitches? The pxclk is prepared and enabled earlier in inno_dp_probe(), and reparenting a running clock without hardware-specific glitch-free muxing can lock up downstream logic.
Quoted 1 line
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Re: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver
Quoted 35 lines · On Sat, 25 Jul 2026 05:04:37 +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [High] Custom EDID read function bypasses DRM core and breaks I2C repeated-start (MOT) rules, corrupting EDID reads for blocks > 0 or on active adapters.
- [High] The hardirq handler returnsIRQ_NONEafter clearing hardware interrupt flags, permanently disabling the IRQ line.
- [High] Late attachment of the eDP panel bridge violatesdrm_bridge_connectorarchitecture and breaks panel support if the panel probes asynchronously.
- [High] DP Transfer Unit (TU) miscalculation due to pixel clock truncation.
- [High] The IRQ handler returnsIRQ_NONEwithout clearing the hardware interrupt whendrm_dev_enter()fails, leading to an interrupt storm.
- [High]spacemit_dp_bridge_atomic_create_statereturns an error pointer instead ofNULLon allocation failure, causing a kernel crash in the DRM core.
- [High] The hardirq handler calls regmap functions which use a sleepable lock onPREEMPT_RT.
- [Medium] Theatomic_checkandmode_validcallbacks access DPCD link capabilities without holdingmode_lock, leading to data races with the hotplug IRQ handler.
- [Medium] The DP IRQ handler silently drops hotplug notifications becausedrm_bridge_hpd_notify()is a no-op whenDRM_BRIDGE_OP_HPDis omitted.
- [Medium] Callingclk_set_parent()on an already enabled clock.
- [Medium] Resetting the AUX controller without holdingaux->hw_mutexraces with concurrent AUX transfers.
----- Patch [12]: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver --- commit
b7eace372254ab27e120213d38c3a656b2a195b8
Author: Cody Kang <[email protected]>drm/spacemit: add Innosilicon DP/eDP controller bridge driver
Add the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree.
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -248,16 +248,10 @@static inline struct spacemit_dp_bridge_state *to_spacemit_dp_bridge_state (struct drm_bridge_state *state) { return container_of(state, struct spacemit_dp_bridge_state, base); }
Quoted 13 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0static const struct regmap_config spacemit_dp_regmap_config = { .name ="dp" , .reg_bits =32 , .val_bits =32 , .reg_stride =4 , .max_register =0x3ffc ,/* full 0x4000 reg region from binding */ };[Severity: High]
Is it safe to omituse_raw_spinlockfrom the regmap configuration? Because this is not set to true, the regmap defaults to a sleepable lock onPREEMPT_RT. This causes a BUG when regmap read/write functions are called from the hardirq handlerspacemit_dp_irq_handler().
The handler is force-threaded on PREEMPT_RT (no IRQF_NO_THREAD), so the regmap spinlock is fine there.
Quoted 9 lines
Quoted 9 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -661,16 +661,10 @@static void spacemit_dp_link_disable (struct spacemit_dp_dev *dp) {regmap_write_bits (dp->regs,DP_VIDEO_VSAMPLE_REG ,DP_VIDEO_STREAM_ENABLE ,FIELD_PREP (DP_VIDEO_STREAM_ENABLE ,0 ));spacemit_dp_phy_off (dp);
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 669
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0regmap_write_bits (dp->regs,DP_SOFT_RESET ,DP_AUX_RESET ,FIELD_PREP (DP_AUX_RESET ,0x1 ));[Severity: Medium]
Could this reset corrupt concurrent AUX transfers? Modifying the AUX hardware inspacemit_dp_link_disable()without holding theaux->hw_mutexcould race against a userspace or deferred transfer, potentially wedging the controller.
All driver-internal AUX users serialize on mode_lock; the EDID rework below also serializes with the userspace i2c node.
Quoted 15 lines
Quoted 15 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -936,15 +936,10 @@static void spacemit_dp_hw_set_msa_and_enable_video (struct spacemit_dp_dev *dp,const struct drm_display_mode *mode,enum spacemit_dp_link_rate rate,enum spacemit_dp_lane_count lanes,u32 color_format) {u64 hb_num;u32 link_rate;u32 fp;/* Pixel clock in MHz */ u32 bpp, misc0;u32 tu, tu_frac, tu_int, rd_thres;u32 hsync_len;
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0/* mode->clock unit is kHz, fp unit is MHz */ if (dp->use_ext_pixel_clock) fp = dp->pixel_clock /1000 ;else fp = mode->clock /1000 ;[Severity: High]
Can this truncation of the pixel clock to an integer MHz value cause DP FIFO underflows or overflows? For non-integer MHz pixel clocks like 148.5 MHz, this truncates to 148, introducing precision errors in the Transfer Unit (TU) calculations which results in corrupted video.
The values are vendor-faithful and board-proven at 4K; computing in kHz is a possible later refinement, not a v2 change.
Quoted 11 lines
Quoted 11 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1286,13 +1286,10 @@static int spacemit_dp_conn_get_edid_block (void *data,u8 *buf,unsigned int block,size_t len) {struct spacemit_dp_dev *dp = data;unsigned int start = block *EDID_LENGTH ;u8 segment = block >>1 ;int ret, retry;size_t offset;
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0if (segment) {for (retry =0 ; retry <3 ; retry++) { ret =spacemit_dp_aux_i2c_write (dp,SPACEMIT_DP_DDC_SEGMENT_ADDR , &segment,1 );[Severity: High]
Does this custom EDID read function bypass the Middle-Of-Transaction (MOT) rules for I2C repeated-start? Issuing writes and reads without the MOT flag resets the DDC segment pointer to 0, breaking EDID reads for displays with multiple EDID blocks (block >= 1) or on active adapters.
Will rework in v2: the custom reader becomes one i2c_transfer per block on the aux I2C adapter, so the DP I2C-over-AUX core chains segment, offset and data with MOT, and 3+ block EDIDs work.
Quoted 22 lines
Quoted 22 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1632,15 +1632,10 @@static int spacemit_dp_bridge_atomic_check (struct drm_bridge *bridge,struct drm_bridge_state *bridge_state,struct drm_crtc_state *crtc_state,struct drm_connector_state *conn_state) {struct spacemit_dp_dev *dp =container_of (bridge, struct spacemit_dp_dev, bridge);struct spacemit_dp_bridge_state *st =to_spacemit_dp_bridge_state (bridge_state);const struct drm_display_mode *mode = &crtc_state->adjusted_mode;int bpp;u32 req_bw;int i;/* A single output bus format, see ->atomic_get_output_bus_fmts(). */ st->color_format =SOC_VIDEO_RGB_8BIT ; bpp =spacemit_dp_get_bpp (dp, st->color_format); req_bw =spacemit_dp_calc_required_bw (mode, bpp);
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0/* No caps yet: leave idx unset and let ->atomic_enable() retry. */ if (!dp->link.max_rate || !dp->link.max_num_lanes) {[Severity: Medium]
Could reading the DPCD link capabilities here race with the hotplug IRQ handler? Accessing thedp->linkcapabilities inspacemit_dp_bridge_atomic_check()without holdingmode_lockmight observe intermediate or torn states if a concurrent interrupt triggers a capability re-read, leading to transient rejections of valid modes.
detect(), enable and the EDID paths all serialize on mode_lock.
Quoted 7 lines
Quoted 7 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1705,10 +1705,10 @@static struct drm_bridge_state *spacemit_dp_bridge_atomic_create_state (struct drm_bridge *bridge) {struct spacemit_dp_bridge_state *new;
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1712
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0new =kzalloc_obj (*new);if (!new)return ERR_PTR (-ENOMEM );[Severity: High]
Should this return NULL on allocation failure instead of an error pointer? The DRM core's reset helper assigns the returned state directly without checking for errors. Returning an error pointer here causes a fatal page fault when the DRM core later dereferences it.
ERR_PTR is what the bridge core expects here; drm_bridge_atomic_create_priv_state() checks IS_ERR().
Quoted 15 lines
Quoted 15 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1742,16 +1742,10 @@static int spacemit_dp_edp_link_panel (struct drm_dp_aux *aux) { struct spacemit_dp_dev *dp = container_of(aux, struct spacemit_dp_dev, aux);struct drm_bridge *next;int ret; next =devm_drm_of_get_bridge (dp->dev, dp->dev->of_node,1 ,0 );if (IS_ERR (next))return PTR_ERR (next); dp->next_bridge = next;
Quoted 16 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0/* * A non-NULL bridge.encoder means .attach already ran: late-chain * panel-edp. */ if (dp->bridge.encoder) { ret =drm_bridge_attach (dp->bridge.encoder, next, &dp->bridge,DRM_BRIDGE_ATTACH_NO_CONNECTOR );[Severity: High]
Does dynamically attaching the panel bridge late bypass connector initialization? If the eDP panel defers its probe,drm_bridge_connector_init()builds the connector without the panel bridge. Attaching it here later violates thedrm_bridge_connectorarchitecture and breaks panel support, because the connector will lack the panel's mode or EDID operations.
Handled by design: the aux-bus done-probing callback late-chains with DRM_BRIDGE_ATTACH_NO_CONNECTOR and re-fires detection; both probe orders are exercised on hardware. See the comment above spacemit_dp_edp_link_panel().
Quoted 8 lines
Quoted 8 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1782,10 +1782,10 @@static irqreturn_t spacemit_dp_irq_handler (int irq,void *data) {struct spacemit_dp_dev *dp = data;irqreturn_t ret =IRQ_NONE ;int idx;
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1789
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0if (!drm_dev_enter (dp->drm, &idx))return IRQ_NONE ;[Severity: High]
Will returningIRQ_NONEhere without clearing the hardware interrupt cause an interrupt storm? If an interrupt fires while the DRM device is unregistered (such as during module unload), the handler exits without acknowledging the hardware interrupt, causing it to continuously fire and stall the CPU.
Only reachable during unbind while the line is being torn down.
Quoted 10 lines
Quoted 10 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1796,11 +1796,10 @@/* * Only compare here: the authoritative connector_status update * happens in the thread under mode_lock, via .detect(). */ if (spacemit_dp_hw_detect_hpd (dp) !=READ_ONCE (dp->connector_status)) ret =IRQ_WAKE_THREAD ;/* Call hotplug_event */ spacemit_dp_hw_clean_hpd (dp);
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0drm_dev_exit (idx);return ret; }[Severity: High]
Is it safe to returnIRQ_NONEafter clearing the hardware interrupt flags? If the logical state has not changed (e.g. from a transient hardware glitch), returningIRQ_NONEcauses the kernel's spurious interrupt detector to eventually disable the IRQ line, which results in all future hotplug events being permanently missed.
Real; will return IRQ_HANDLED in v2 when a latched HPD event was consumed.
Quoted 11 lines
Quoted 11 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1813,11 +1813,10 @@static irqreturn_t spacemit_dp_hotplug_event_handler (int irq,void *data) {struct spacemit_dp_dev *dp = data;enum drm_connector_status status;int idx;if (!drm_dev_enter (dp->drm, &idx))return IRQ_HANDLED ;
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0/* * .detect() owns mode_lock and re-reads the sink caps on a fresh plug */ status =spacemit_dp_bridge_detect (&dp->bridge, dp->connector);drm_bridge_hpd_notify (&dp->bridge, status);[Severity: Medium]
Will this hotplug notification be silently dropped? SinceDRM_BRIDGE_OP_HPDis not set for the DP bridge duringinno_dp_probe(), thebridge->hpd_cbis NULL, makingdrm_bridge_hpd_notify()a no-op and forcing the DRM core to rely entirely on periodic polling.
Deliberate: the HPD interrupt is gated by the DP pixel clock, so the connector is polled instead, and the IRQ path still refreshes status early when it does fire. Documented at the ops assignment.
Quoted 14 lines
Quoted 14 lines
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -2338,10 +2338,15 @@static int inno_dp_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;if (dp->pxclk) { ret =clk_prepare_enable (dp->pxclk);if (ret) {dev_err (dev,"failed to enable pxclk: %d\n" , ret); goto err_reset; } }
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0if (dp->pxclk) { ret =clk_set_parent (dp->pxclk, dp->pll_clk);[Severity: Medium]
Can callingclk_set_parent()on an already enabled clock cause hardware glitches? The pxclk is prepared and enabled earlier ininno_dp_probe(), and reparenting a running clock without hardware-specific glitch-free muxing can lock up downstream logic.
The mux is reparented before the display is enabled; nothing scans while it switches at probe.
Cody
Re: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver
In reply to Cody KangQuoted 21 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Add the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree: an eDP panel always sits under an aux-bus child node, an external DP connector never does.
The link is driven through the generic PHY framework, so the controller never touches a PLL register. The controller's HPD interrupt is gated by the DP pixel clock, which can be off exactly when a plug has to be caught, so the connector is also polled and the interrupt path re-reads the live level when it does fire.
Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/Kconfig | 19 + drivers/gpu/drm/spacemit/Makefile | 3 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2443 +++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 ++++ 4 files changed, 2793 insertions(+)
[...]
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -0,0 +1,2443 @@
[...]
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2
-0+static int inno_dp_probe (struct platform_device *pdev) +{
[...]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2241
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +1
-0+ dp->reset =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL );
Since this is only asserted in probe and deasserted in remove, you could use devm_reset_control_get_optional_exclusive_deasserted() [1].
[1] https://docs.kernel.org/driver-api/reset.html#c.devm_reset_control_get_optional_exclusive_deasserted
Quoted 24 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +24
-0+if (IS_ERR (dp->reset)) { + ret =dev_err_probe (dev,PTR_ERR (dp->reset), +"failed to get reset\n" ); +return ret; + } + + dp->pxclk =devm_clk_get (dev,"pxclk" ); +if (IS_ERR (dp->pxclk)) { + ret =dev_err_probe (dev,PTR_ERR (dp->pxclk), +"failed to get pxclk\n" ); +return ret; + } + +if (dp->edp_mode) { + dp->bridge.type = DRM_MODE_CONNECTOR_eDP; +/* +* OP_DETECT is required: without it +* drm_bridge_connector_detect() hard-codes CONNECTED for any +* eDP connector and fbdev wedges at bind. +*/ + dp->bridge.ops =DRM_BRIDGE_OP_DETECT |DRM_BRIDGE_OP_EDID | +DRM_BRIDGE_OP_HPD ; + }else { + dp->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2275
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+/* +* No OP_HPD: the HPD interrupt is gated by the DP pixel clock. +* Leaving it out marks the connector POLL_CONNECT | +* POLL_DISCONNECT instead. +*/ + dp->bridge.ops =DRM_BRIDGE_OP_DETECT |DRM_BRIDGE_OP_EDID | +DRM_BRIDGE_OP_MODES ; + } + +if (dp->reset) {
This check is not necessary, reset_control_deassert() handles NULL pointers.
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2276
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +1
-0+ ret =reset_control_deassert (dp->reset);
If the _deasserted() variant is used above, this can be removed and the reset control doesn't need to be stored in dp.
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +6
-0+if (ret) { +dev_err (dev,"failed to deassert reset: %d\n" , ret); +return ret; + } + } +
[...]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2394
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +7
-0+return 0 ; + +err_clk: +clk_disable_unprepare (dp->pxclk); +err_reset: +if (dp->reset) +reset_control_assert (dp->reset);
Same as above. Remove the unnecessary check or manual assertion entirely.
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +4
-0+ +return ret; +} +
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2408
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+static void inno_dp_remove (struct platform_device *pdev) +{ +struct spacemit_dp_dev *dp =platform_get_drvdata (pdev); + +component_del (&pdev->dev, &spacemit_dp_ops); + +if (dp) { +clk_disable_unprepare (dp->pxclk); +if (dp->reset) +reset_control_assert (dp->reset);
Same as above.
drivers/gpu/drm/spacemit/spacemit_inno_dp.c
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2
-0+ } +}
regards
Philipp
Re: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver
Hi Philipp,
Quoted 30 lines · Philipp Zabel
Quoted 21 lines · On Sa, 2026-07-25 at 00:51 -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Add the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree: an eDP panel always sits under an aux-bus child node, an external DP connector never does.
The link is driven through the generic PHY framework, so the controller never touches a PLL register. The controller's HPD interrupt is gated by the DP pixel clock, which can be off exactly when a plug has to be caught, so the connector is also polled and the interrupt path re-reads the live level when it does fire.
Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/Kconfig | 19 + drivers/gpu/drm/spacemit/Makefile | 3 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2443 +++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 ++++ 4 files changed, 2793 insertions(+)[...]
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -0,0 +1,2443 @@[...]
Quoted 7 lines
Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2
-0+static int inno_dp_probe (struct platform_device *pdev) +{[...]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2241
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +1
-0+ dp->reset =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL );Since this is only asserted in probe and deasserted in remove, you could use
devm_reset_control_get_optional_exclusive_deasserted()[1].
Thanks for the review. Will do in v2. The binding marks resets as required, which means I shouldn't use _optional in the first place. I will use the non-optional devm_reset_control_get_exclusive_deasserted().
Quoted 52 lines
[1] https://docs.kernel.org/driver-api/reset.html#c.devm_reset_control_get_optional_exclusive_deasserted
Quoted 24 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +24
-0+if (IS_ERR (dp->reset)) { + ret =dev_err_probe (dev,PTR_ERR (dp->reset), +"failed to get reset\n" ); +return ret; + } + + dp->pxclk =devm_clk_get (dev,"pxclk" ); +if (IS_ERR (dp->pxclk)) { + ret =dev_err_probe (dev,PTR_ERR (dp->pxclk), +"failed to get pxclk\n" ); +return ret; + } + +if (dp->edp_mode) { + dp->bridge.type = DRM_MODE_CONNECTOR_eDP; +/* +* OP_DETECT is required: without it +* drm_bridge_connector_detect() hard-codes CONNECTED for any +* eDP connector and fbdev wedges at bind. +*/ + dp->bridge.ops =DRM_BRIDGE_OP_DETECT |DRM_BRIDGE_OP_EDID | +DRM_BRIDGE_OP_HPD ; + }else { + dp->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2275
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+/* +* No OP_HPD: the HPD interrupt is gated by the DP pixel clock. +* Leaving it out marks the connector POLL_CONNECT | +* POLL_DISCONNECT instead. +*/ + dp->bridge.ops =DRM_BRIDGE_OP_DETECT |DRM_BRIDGE_OP_EDID | +DRM_BRIDGE_OP_MODES ; + } + +if (dp->reset) {This check is not necessary,
reset_control_deassert()handles NULL pointers.drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2276
Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +1
-0+ ret =reset_control_deassert (dp->reset);If the
_deasserted()variant is used above, this can be removed and the reset control doesn't need to be stored in dp.Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +6
-0+if (ret) { +dev_err (dev,"failed to deassert reset: %d\n" , ret); +return ret; + } + } +[...]
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2394
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +7
-0+return 0 ; + +err_clk: +clk_disable_unprepare (dp->pxclk); +err_reset: +if (dp->reset) +reset_control_assert (dp->reset);Same as above. Remove the unnecessary check or manual assertion entirely.
Agree, all of these will be fixed in v2.
Cody
Re: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver
In reply to Cody KangQuoted 20 lines · On Sat, Jul 25, 2026 at 12:51:21AM -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Add the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree: an eDP panel always sits under an aux-bus child node, an external DP connector never does.
The link is driven through the generic PHY framework, so the controller never touches a PLL register. The controller's HPD interrupt is gated by the DP pixel clock, which can be off exactly when a plug has to be caught, so the connector is also polled and the interrupt path re-reads the live level when it does fire.
Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/Kconfig | 19 + drivers/gpu/drm/spacemit/Makefile | 3 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2443 +++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 ++++ 4 files changed, 2793 insertions(+)
...
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +7
-0+static int inno_dp_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *aux_bus_np; +struct spacemit_dp_dev *dp; +struct resource *res; +int ret;
...
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2253
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +6
-0+ dp->pxclk =devm_clk_get (dev,"pxclk" ); +if (IS_ERR (dp->pxclk)) { + ret =dev_err_probe (dev,PTR_ERR (dp->pxclk), +"failed to get pxclk\n" ); +return ret; + }
It seems pxclk is only enabled in probe() and disabled in remove(), please consider using devm_clk_get_optional_enabled().
...
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2289
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +7
-0+if (dp->pxclk) { + ret =clk_prepare_enable (dp->pxclk); +if (ret) { +dev_err (dev,"failed to enable pxclk: %d\n" , ret); + goto err_reset; + } + }
So this check could be dropped.
...
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2322
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+/* +* The PHY exposes its PLL as the APMU pixel-clock mux's external +* parent. +*/ + dp->pll_clk =devm_clk_get (dev,"pll" ); +if (IS_ERR (dp->pll_clk)) { + ret =dev_err_probe (dev,PTR_ERR (dp->pll_clk), +"failed to get PHY pixel clock\n" ); + goto err_clk; + }
Same for the "pll" clock.
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +5
-0+if (dp->pxclk) { + ret =clk_set_parent (dp->pxclk, dp->pll_clk); +if (ret) { +dev_err (dev,"failed to route eDP pixel mux to PHY PLL: %d\n" , ret); + goto err_clk;
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2380
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+} +} +*/ + ret =devm_request_threaded_irq (dev, dp->irq, spacemit_dp_irq_handler, + spacemit_dp_hotplug_event_handler, +IRQF_NO_AUTOEN ,dev_name (dev), dp); +if (ret) { +dev_err (dev,"failed to request irq %d: %d\n" , dp->irq, ret); + goto err_clk; + }
Since 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()") devm_request_threaded_irq() automatically throws an error message when it fails, so this error message is redundant.
...
Review
Quoted 2 lines
(quoted diff) +2
-0+err_clk: + clk_disable_unprepare(dp->pxclk);
With devm_clk_get_optional_enabled(), you could remove this and simplify some error handling paths.
Regards,
Yao Zi
Re: [PATCH RESEND 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver
Hi Yao Zi,
Quoted 34 lines · Yao Zi
Quoted 20 lines · On Sat, Jul 25, 2026 at 12:51:21AM -0400, Cody Kang via B4 Relay wrote:
From: Cody Kang <[email protected]>
Add the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree: an eDP panel always sits under an aux-bus child node, an external DP connector never does.
The link is driven through the generic PHY framework, so the controller never touches a PLL register. The controller's HPD interrupt is gated by the DP pixel clock, which can be off exactly when a plug has to be caught, so the connector is also polled and the interrupt path re-reads the live level when it does fire.
Signed-off-by Cody Kang <[email protected]>--- drivers/gpu/drm/spacemit/Kconfig | 19 + drivers/gpu/drm/spacemit/Makefile | 3 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2443 +++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 ++++ 4 files changed, 2793 insertions(+)...
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +7
-0+static int inno_dp_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *aux_bus_np; +struct spacemit_dp_dev *dp; +struct resource *res; +int ret;...
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2253
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +6
-0+ dp->pxclk =devm_clk_get (dev,"pxclk" ); +if (IS_ERR (dp->pxclk)) { + ret =dev_err_probe (dev,PTR_ERR (dp->pxclk), +"failed to get pxclk\n" ); +return ret; + }It seems pxclk is only enabled in
probe()and disabled inremove(), please consider usingdevm_clk_get_optional_enabled().
Thanks for the review. You are right that the disable belongs to devres. I will move the disable to a devm action registered after the populate.
But the _enabled part of devm_clk_get_optional_enabled() doesn't fit here: it hands the disable to devres at get time, before the PHY child is populated, so on unbind pxclk would be disabled only after the PHY PLL it is parented on is gone, and the clock core would warn.
I will keep the non-optional getter, since the binding requires the clocks.
Quoted 11 lines
...
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2289
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +7
-0+if (dp->pxclk) { + ret =clk_prepare_enable (dp->pxclk); +if (ret) { +dev_err (dev,"failed to enable pxclk: %d\n" , ret); + goto err_reset; + } + }So this check could be dropped.
Yes, all the if (dp->pxclk) guards are dead code; will drop them in v2.
Quoted 14 lines
...
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2322
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+/* +* The PHY exposes its PLL as the APMU pixel-clock mux's external +* parent. +*/ + dp->pll_clk =devm_clk_get (dev,"pll" ); +if (IS_ERR (dp->pll_clk)) { + ret =dev_err_probe (dev,PTR_ERR (dp->pll_clk), +"failed to get PHY pixel clock\n" ); + goto err_clk; + }Same for the "pll" clock.
We never enable "pll" ourselves (it is only a parent and rate target), so it will stay a plain non-optional devm_clk_get().
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +11
-0+if (dp->pxclk) { +ret = clk_set_parent(dp->pxclk, dp->pll_clk); +if (ret) { +dev_err(dev, "failed to route eDP pixel mux to PHY PLL: %d\n", ret); +goto err_clk; +} +} +*/ + ret =devm_request_threaded_irq (dev, dp->irq, spacemit_dp_irq_handler, + spacemit_dp_hotplug_event_handler, +IRQF_NO_AUTOEN ,dev_name (dev), dp);
Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2380
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +4
-0+if (ret) { +dev_err (dev,"failed to request irq %d: %d\n" , dp->irq, ret); + goto err_clk; + }Since
55b48e23f5c4("genirq/devres: Add error handling in devm_request_*_irq()")devm_request_threaded_irq()automatically throws an error message when it fails, so this error message is redundant.
Right, will drop it.
Cody
PATCH RESEND 13/17 MAINTAINERS: add SpacemiT K3 display driver entry
In reply to Cody KangCover the Saturn DPU, the Innosilicon DP/eDP controller, the DP PHY and their bindings.
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
@@ -25436,6 +25436,16 @@ S: Maintained F: Documentation/devicetree/bindings/i2c/spacemit,k1-i2c.yaml F: drivers/i2c/busses/i2c-k1.c +SPACEMIT K3 DISPLAY DRIVER +M: Cody Kang <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/display/spacemit/ +F: Documentation/devicetree/bindings/phy/spacemit,k3-inno-dp-phy.yaml +F: drivers/gpu/drm/spacemit/ +F: drivers/phy/spacemit/phy-k3-inno-dp.c + SPANISH DOCUMENTATION M: Carlos Bilbao <[email protected]> R: Avadhut Naik <[email protected]>
Signature · 1 line
2.43.0
PATCH RESEND 14/17 riscv: dts: spacemit: k3: add display nodes
In reply to Cody KangAdd the SoC-level display nodes: the two Saturn DPUs, the two DP/eDP controllers with their PHY children.
The PHY PLLs are fed back into the APMU as pixel-clock mux parents, so updated the &syscon_apmu node in the display dtsi.
--- arch/riscv/boot/dts/spacemit/k3-display.dtsi | 156 +++++++++++++++++++++++++++ 1 file changed, 156 insertions(+)
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +156 -0
@@ -0,0 +1,156 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * SpacemiT K3 display subsystem (DPU0/eDP0 + DPU1/DP1) shared + * device-tree definitions for inclusion alongside k3.dtsi. + * + * Copyright (C) 2026 SpacemiT Co., Ltd. + */ + +#include <dt-bindings/clock/spacemit,k3-clocks.h> +#include <dt-bindings/reset/spacemit,k3-resets.h> +#include <dt-bindings/interrupt-controller/irq.h> + +&soc { + dpu0_crtc0: dpu@c0340000 { + compatible = "spacemit,k3-saturn-dpu"; + reg = <0x0 0xc0340000 0x0 0x54000>; + interrupts = <90 IRQ_TYPE_LEVEL_HIGH>, + <89 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "online", "offline"; + clocks = <&syscon_apmu CLK_APMU_LCD_PXCLK>, + <&syscon_apmu CLK_APMU_LCD_MCLK>, + <&syscon_apmu CLK_APMU_DPU_ACLK>, + <&syscon_apmu CLK_APMU_DSI_ESC>, + <&syscon_apmu CLK_APMU_LCD_DSC>; + clock-names = "pxclk", "mclk", "aclk", "escclk", "dscclk"; + resets = <&syscon_apmu RESET_APMU_LCD_MCLK>, + <&syscon_apmu RESET_APMU_LCD>, + <&syscon_apmu RESET_APMU_DSI_ESC>, + <&syscon_apmu RESET_APMU_DPU_ACLK>, + <&syscon_apmu RESET_APMU_LCD_DSCCLK>; + reset-names = "mclk", "lcd", "esc", + "aclk", "dsc"; + status = "disabled"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + dpu0_out: endpoint { + remote-endpoint = <&edp0_in>; + }; + }; + }; + }; + + edp0: edp@cac84000 { + compatible = "spacemit,k3-inno-dp"; + reg = <0x0 0xcac84000 0x0 0x4000>; + interrupts = <132 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&syscon_apmu CLK_APMU_EDP0_PXCLK>, <&edp0_phy>; + clock-names = "pxclk", "pll"; + resets = <&syscon_apmu RESET_APMU_EDP0>; + phys = <&edp0_phy>; + phy-names = "dp"; + status = "disabled"; + + edp0_phy: phy { + compatible = "spacemit,k3-inno-dp-phy"; + #phy-cells = <0>; + #clock-cells = <0>; + clock-output-names = "edp0_pll_pxclk"; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + edp0_in: endpoint { + remote-endpoint = <&dpu0_out>; + }; + }; + /* port@1 (panel output) is added by boards fitting an eDP panel */ + }; + }; + + dpu1_crtc0: dpu@c0440000 { + compatible = "spacemit,k3-saturn-dpu"; + reg = <0x0 0xc0440000 0x0 0x54000>; + interrupts = <139 IRQ_TYPE_LEVEL_HIGH>, + <138 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "online", "offline"; + clocks = <&syscon_apmu CLK_APMU_DSI4LN2_LCD_PXCLK>, + <&syscon_apmu CLK_APMU_DSI4LN2_LCD_MCLK>, + <&syscon_apmu CLK_APMU_DSI4LN2_DPU_ACLK>, + <&syscon_apmu CLK_APMU_DSI4LN2_DSI_ESC>, + <&syscon_apmu CLK_APMU_DSI4LN2_LCD_DSC>; + clock-names = "pxclk", "mclk", "aclk", "escclk", "dscclk"; + resets = <&syscon_apmu RESET_APMU_DSI4LN2_LCD_MCLK>, + <&syscon_apmu RESET_APMU_DSI4LN2_LCD_SW>, + <&syscon_apmu RESET_APMU_DSI4LN2_ESCCLK>, + <&syscon_apmu RESET_APMU_DSI4LN2_DPU_ACLK>, + <&syscon_apmu RESET_APMU_DSI4LN2_LCD_DSCCLK>; + reset-names = "mclk", "lcd", "esc", + "aclk", "dsc"; + status = "disabled"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + dpu1_out: endpoint { + remote-endpoint = <&dp1_in>; + }; + }; + }; + }; + + dp1: dp@cac88000 { + compatible = "spacemit,k3-inno-dp"; + reg = <0x0 0xcac88000 0x0 0x4000>; + interrupts = <140 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&syscon_apmu CLK_APMU_EDP1_PXCLK>, <&dp1_phy>; + clock-names = "pxclk", "pll"; + resets = <&syscon_apmu RESET_APMU_EDP1>; + phys = <&dp1_phy>; + phy-names = "dp"; + status = "disabled"; + + dp1_phy: phy { + compatible = "spacemit,k3-inno-dp-phy"; + #phy-cells = <0>; + #clock-cells = <0>; + clock-output-names = "edp1_pll_pxclk"; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + dp1_in: endpoint { + remote-endpoint = <&dpu1_out>; + }; + }; + /* no port@1: the DP TX drives the external connector directly */ + }; + }; +}; + +/* + * Feed the PHY PLL pixel clocks back in as the APMU mux parents. This lives + * here, not in k3.dtsi: the PHYs only exist where this file is included. + */ +&syscon_apmu { + clocks = <&osc_32k>, <&vctcxo_1m>, <&vctcxo_3m>, <&vctcxo_24m>, + <&edp0_phy>, <&dp1_phy>; + clock-names = "osc", "vctcxo_1m", "vctcxo_3m", "vctcxo_24m", + "edp0_pll_pxclk", "edp1_pll_pxclk"; +};
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 14/17] riscv: dts: spacemit: k3: add display nodes
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The DP controller hardware is not initialized before the eDP panel probe is triggered, causing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The DP controller hardware is not initialized before the eDP panel probe is triggered, causing synchronous AUX transfers to fail or hang.
- [High] The custom EDID read function violates the I2C EEPROM protocol by omitting the Middle-of-Transaction (MOT) bit, breaking EDID reads on sinks that require a repeated START. --
--- Patch [14]: [PATCH RESEND 14/17] riscv: dts: spacemit: k3: add display nodes --- commit 9b9ee39195ad90a76f056f9bddbdabb8377b67ec
Author: Cody Kang <[email protected]>
riscv: dts: spacemit: k3: add display nodes
Add the SoC-level display nodes: the two Saturn DPUs, the two DP/eDP controllers with their PHY children.
Quoted 6 lines
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +0
-0@@ -0,0 +1,156 @@
[ ... ]
Quoted 1 line
+&soc {
[ ... ]
arch/riscv/boot/dts/spacemit/k3-display.dtsi line 49
Quoted 2 lines
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +2
-0+ edp0: edp@cac84000 { + compatible = "spacemit,k3-inno-dp";
[Severity: High]
Does enabling this device node cause the eDP panel probe to fail?
Looking at inno_dp_probe() in drivers/gpu/drm/spacemit/spacemit_inno_dp.c, it populates the eDP panel device on the AUX bus:
ret = devm_of_dp_aux_populate_bus(&dp->aux,
spacemit_dp_edp_link_panel);The panel driver probes synchronously and attempts an AUX transfer to read the EDID.
However, the DP controller's hardware registers (including the AUX clock divider DP_AUX_CTRL_CLK_DIV and soft resets) are not initialized until later:
spacemit_inno_dp.c:spacemit_dp_bind() {
...
ret = spacemit_dp_dev_init(dp);
...
}The uninitialized controller ignores the transfer or the AUX state machine does not start, causing an unavoidable timeout.
Quoted 1 line
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +1
-0+ reg = <0x0 0xcac84000 0x0 0x4000>;
[ ... ]
arch/riscv/boot/dts/spacemit/k3-display.dtsi line 115
Quoted 2 lines
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +2
-0+ dp1: dp@cac88000 { + compatible = "spacemit,k3-inno-dp";
[Severity: High]
Will EDID reads fail for sinks connected to this node?
When reading EDID, the driver splits the transaction into a write and a read:
spacemit_inno_dp.c:spacemit_dp_conn_get_edid_block() {
...
ret = spacemit_dp_aux_i2c_write(dp, DDC_ADDR,
&edid_offset, 1);
...
}It calls spacemit_dp_aux_i2c_write() which hardcodes the request:
spacemit_inno_dp.c:spacemit_dp_aux_i2c_write() {
...
.request = DP_AUX_I2C_WRITE,
...
}The missing MOT (Middle-of-Transaction) bit guarantees an I2C STOP condition after writing the offset address. This resets the internal address pointer of many standard EEPROMs, causing the subsequent read to repeatedly fetch block 0 instead of the requested extension block.
Quoted 1 line
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +1
-0+ reg = <0x0 0xcac88000 0x0 0x4000>;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
PATCH RESEND 15/17 riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output
In reply to Cody KangPico-ITX brings the second DPU's output to an external DisplayPort connector. Enable that DPU and the DisplayPort controller it feeds.
--- arch/riscv/boot/dts/spacemit/k3-pico-itx.dts | 11 +++++++++++ arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 11 +++++++++++ 2 files changed, 22 insertions(+)
arch/riscv/boot/dts/spacemit/k3-pico-itx.dts +11 -0
@@ -6,6 +6,7 @@ #include <dt-bindings/gpio/gpio.h> #include "k3.dtsi" +#include "k3-display.dtsi" #include "k3-pinctrl.dtsi" / {
@@ -221,3 +222,13 @@ hub@1 { &usb2_phy { status = "okay"; }; + +&dpu1_crtc0 { + status = "okay"; +}; + +&dp1 { + pinctrl-names = "default"; + pinctrl-0 = <&dp1_1_cfg>; + status = "okay"; +};
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi +11 -0
@@ -11,6 +11,17 @@ #define K3_GPIO(x) (x / 32) (x % 32) &pinctrl { + /omit-if-no-ref/ + dp1_1_cfg: dp1-1-cfg { + dp1-pins { + pinmux = <K3_PADCONF(24, 6)>; /* dp1 hpd */ + + bias-disable; + drive-strength = <25>; + power-source = <3300>; + }; + }; + gmac0_rgmii_0_cfg: gmac0-rgmii-0-cfg { gmac0-rgmii-0-pins { pinmux = <K3_PADCONF(0, 1)>, /* gmac0_rxdv */
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH RESEND 15/17] riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Precision Loss in DP Timing Configuration due to integer division - [High] Protocol Violation in…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Precision Loss in DP Timing Configuration due to integer division
- [High] Protocol Violation in I2C-over-AUX EDID Read (Missing MOT flag)
--
--- Patch [15]: [PATCH RESEND 15/17] riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output --- commit 8521347c30ea3dc057bb9d8b08c1de584bd6ba67
Author: Cody Kang <[email protected]>
riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output
This commit enables the second Saturn DPU and the corresponding DisplayPort controller on the Pico-ITX board. While this patch configures the devicetree to route the DPU output, it exposes regressions in the newly added underlying Innosilicon DP/eDP driver.
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0
[ ... ]
Quoted 20 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -982,19 +982,19 @@ static void spacemit_dp_hw_set_msa_and_enable_video(struct spacemit_dp_dev *dp,const struct drm_display_mode *mode, enum spacemit_dp_link_rate rate, enum spacemit_dp_lane_count lanes, u32 color_format) { u64 hb_num;u32 link_rate;u32 fp;/* Pixel clock in MHz */ u32 bpp, misc0;u32 tu, tu_frac, tu_int, rd_thres;u32 hsync_len;/* mode->clock unit is kHz, fp unit is MHz */ if (dp->use_ext_pixel_clock) fp = dp->pixel_clock /1000 ;else fp = mode->clock /1000 ;if (fp ==0 )
Quoted 1 line
fp = 1; /* Prevent division by zero */
[Severity: High]
Will dividing by 1000 here truncate necessary precision?
Since mode->clock / 1000 discards the fractional part (for example, a 74.25 MHz clock becomes 74 MHz), this truncated value is used in calculating the Transfer Unit size and horizontal blanking interval. This discrepancy can cause the display controller and the DP transmitter to disagree on the required bandwidth, resulting in the DP TX FIFO overflowing and corrupting the display for common standard resolutions like 720p and 1080p.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c static int spacemit_dp_aux_i2c_write(struct spacemit_dp_dev *dp, u32 address, · line 1282
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1278,9 +1278,9 @@ static int spacemit_dp_aux_i2c_write(struct spacemit_dp_dev *dp, u32 address, const u8 *buf, size_t len) {struct drm_dp_aux_msg msg = { .address = address, .request =DP_AUX_I2C_WRITE ,
[Severity: High]
Is it intentional to hardcode DP_AUX_I2C_WRITE here without allowing the DP_AUX_I2C_MOT (Middle Of Transaction) flag to be appended?
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c static int spacemit_dp_conn_get_edid_block(void *data, u8 *buf, · line 1329
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0@@ -1320,11 +1320,11 @@ static int spacemit_dp_conn_get_edid_block(void *data, u8 *buf,int ret, retry;size_t offset;if (segment) {for (retry =0 ; retry <3 ; retry++) { ret =spacemit_dp_aux_i2c_write (dp,SPACEMIT_DP_DDC_SEGMENT_ADDR , &segment,1 );if (!ret)break ; }
[Severity: High]
Can this segment write cause the hardware to generate an I2C STOP condition?
Because spacemit_dp_aux_i2c_write() lacks the MOT flag, writing the E-DDC segment pointer without it directs the hardware to generate a STOP condition. According to the E-DDC specification, a STOP condition immediately after writing the segment pointer forces the display EEPROM to reset its segment pointer to 0.
As a result, subsequent reads might always fetch EDID blocks 0 and 1, making it impossible to correctly read EDID blocks >= 2 (such as CTA-861 extension blocks) and potentially breaking support for advanced resolutions and audio and HDR features.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
PATCH RESEND 16/17 riscv: dts: spacemit: k3-com260-ifx: enable the DisplayPort output
In reply to Cody KangCoM260-IFX carries a single DisplayPort output, so the second DPU and the DisplayPort controller it feeds are enabled.
--- arch/riscv/boot/dts/spacemit/k3-com260-ifx.dts | 11 +++++++++++ arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 11 +++++++++++ 2 files changed, 22 insertions(+)
arch/riscv/boot/dts/spacemit/k3-com260-ifx.dts +11 -0
@@ -5,6 +5,7 @@ */ #include "k3-com260.dtsi" +#include "k3-display.dtsi" / { model = "SpacemiT K3 CoM260 IFX";
@@ -19,3 +20,13 @@ chosen { stdout-path = "serial0:115200n8"; }; }; + +&dpu1_crtc0 { + status = "okay"; +}; + +&dp1 { + pinctrl-names = "default"; + pinctrl-0 = <&dp1_3_cfg>; + status = "okay"; +};
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi +11 -0
@@ -22,6 +22,17 @@ dp1-pins { }; }; + /omit-if-no-ref/ + dp1_3_cfg: dp1-3-cfg { + dp1-pins { + pinmux = <K3_PADCONF(72, 4)>; /* dp1 hpd */ + + bias-disable; + drive-strength = <25>; + power-source = <3300>; + }; + }; + gmac0_rgmii_0_cfg: gmac0-rgmii-0-cfg { gmac0-rgmii-0-pins { pinmux = <K3_PADCONF(0, 1)>, /* gmac0_rxdv */
Signature · 1 line
2.43.0
PATCH RESEND 17/17 riscv: defconfig: spacemit: k3: enable display driver
In reply to Cody KangEnable the Saturn DPU and the DP/eDP controller as modules, matching the other DRM drivers in this defconfig; the DP PHY follows through the controller's imply.
--- arch/riscv/configs/defconfig | 2 ++ 1 file changed, 2 insertions(+)
arch/riscv/configs/defconfig +2 -0
@@ -191,6 +191,8 @@ CONFIG_VIDEO_CADENCE_CSI2RX=m CONFIG_DRM=m CONFIG_DRM_RADEON=m CONFIG_DRM_NOUVEAU=m +CONFIG_DRM_SPACEMIT=m +CONFIG_SPACEMIT_INNO_DP=m CONFIG_DRM_SUN4I=m CONFIG_DRM_VIRTIO_GPU=m CONFIG_FB=y
Signature · 1 line
2.43.0