Re: [PATCH v2 0/2] clk: sophgo: sg2042: Keep gates used by firmware enabled
From: Yao Zi
Date: Thu Dec 03 2026 - 13:07:22 EST
On Thu, Dec 03, 2026 at 12:29:33AM +0800, Icenowy Zheng wrote:
> 在 2026-12-02三的 08:50 -0600,Rob Herring写道:
> > On Fri, Nov 27, 2026 at 04:01:32PM +0100, Jerome Brunet wrote:
> > > > On Milk-V Pioneer, firmware uses I2C0 for the EFI RTC and the serial
> > > > flash for its own image and EFI variables. Both sit behind clock gates
> > > > shared with devices Linux drives, so runtime PM on the Linux side can
> > > > turn them off under the firmware, and GetTime() returns EFI_NOT_READY.
> > > >
> > > > Let firmware list such gates in protected-clocks on the clkgen node,
> > > > and keep them enabled.
> > > >
> > > > qcom, the only current user of protected-clocks, does not register such
> > > > clocks at all. That would break the I2C controllers Linux uses, as the
> > > > DesignWare driver needs the clock rate, so here they stay registered and
> > > > are only kept on. I'm not sure this fits the intended use; suggestions
> > > > welcome.
> > > >
> > > > Tested on Milk-V Pioneer.
> > > >
> > > > Signed-off-by: Han Gao <gaohan@xxxxxxxxxxx>
> > > > ---
> > > > Changes in v2:
> > > > - Drop the EFI MMIO patch, Ard is taking it through the EFI tree
> > > > - Use protected-clocks instead of scanning reserved nodes under /soc
> > > > (Krzysztof)
> > >
> > > Hey Krzysztof,
> > >
> > > Using protected-clocks in the way proposed in this series would give it a different
> > > behavior/meaning compared to what introduced it in Qcom:
> > >
> > > - Qualcomm skips registering listed clocks. A consumer requesting a listed ID gets NULL.
> > > - SG2042 still registers listed gates and marks them CLK_IS_CRITICAL.
> > > A consumer gets a valid clock handle, can read its rate, but releasing its enable
> > > reference won’t turn off the hardware gate.
> > >
> > > Having different meaning for the same property is not ideal, is it ?
> > > Eventually that might be something we could fold into the framework, but that can only
> > > happen if the meaning is consistent.
>
> Well in fact the purpose isn't the same on QCOM and SG2042 here:
>
> - On Qualcomm platforms, all resources specified as "protected" in DT is
> really protected by the TEE. If Linux even dare to touch these resources,
> the TEE will consider this as tamper of TEE security and hang the system,
> so these resources should never be touched by Linux.
> - On SG2042, there's no security enforcement on these resources, and Linux
> has the permission to access them. However this will render some part of
> the EFI runtime service unavailable, so for the sake of EFI runtime service
> availability these resources need to be kept on by Linux.
>
> These two behaviors are not possible to be unified, although the latter
> isn't restricted to SG2042 and is common on EFI-booted embedded systems.
>
> Maybe a new name (instead of protected-*) could be chosen for the latter
> behavior. Considering it would behaves like the `assigned-clock*` family
> when in the clock framework, maybe something like `assigned-clock-on = <0>
> /* doing nothing */, <1> /* keep the corresponding assigned-clocks entry on
> */;` ?
If we are introducing a property to protect clocks used by firmware,
it should probably protect all its states from changing, e.g., rate.
The firmware might expect a specific rate for the clock, and if its rate
is changed by requests to sibling clocks sharing the same parent, the
firmware wouldn't be able to restore the expected state without racing
with the kernel.
assigned-clock-rates/parents aren't a solution here, since they're only
initial settings and not exclusive.
> Thanks,
> Icenowy
[...]
--
Thanks,
Yao Zi
Meow-mrrp-mrow, I'm a cat.