mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] riscv/clk: sophgo: Fix EFI RTC on Milk-V Pioneer
@ 2026-11-21 10:38 Han Gao via B4 Relay
  2026-11-21 10:38 ` [PATCH 1/2] riscv: efi: Map runtime MMIO with device attributes Han Gao via B4 Relay
  2026-11-21 10:38 ` [PATCH 2/2] clk: sophgo: sg2042-clkgen: Keep gates of reserved devices enabled Han Gao via B4 Relay
  0 siblings, 2 replies; 4+ messages in thread
From: Han Gao via B4 Relay @ 2026-11-21 10:38 UTC (permalink / raw)
  To: Ard Biesheuvel, Ilias Apalodimas, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Stephen Boyd,
	Brian Masney, Jerome Brunet, Chen Wang, Inochi Amaoto
  Cc: Han Gao, linux-efi, linux-riscv, linux-kernel, linux-clk, sophgo,
	Han Gao

Pioneer firmware can take over the DS1307 on I2C0 and expose it through
EFI runtime services, so Linux uses rtc-efi. I2C0 is then marked
"reserved" in the device tree.

Two things break GetTime() in that setup:

- RISC-V maps EFI runtime MMIO as normal memory, and firmware takes a
  load access fault on the clock controller. Patch 1 maps it as I/O.

- I2C0 shares a clock gate with the other I2C controllers. Once Linux
  runtime-suspends them, the gate goes off and GetTime() returns
  EFI_NOT_READY. Patch 2 keeps gates used by reserved devices on.

Tested on Milk-V Pioneer.

Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
---
Han Gao (2):
      riscv: efi: Map runtime MMIO with device attributes
      clk: sophgo: sg2042-clkgen: Keep gates of reserved devices enabled

 arch/riscv/kernel/efi.c                |  2 +-
 drivers/clk/sophgo/clk-sg2042-clkgen.c | 38 +++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261121-b4-sg2042-efi-rtc-e4d5222513ae

Best regards,
--  
Han Gao <gaohan@iscas.ac.cn>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] riscv: efi: Map runtime MMIO with device attributes
  2026-11-21 10:38 [PATCH 0/2] riscv/clk: sophgo: Fix EFI RTC on Milk-V Pioneer Han Gao via B4 Relay
@ 2026-11-21 10:38 ` Han Gao via B4 Relay
  2026-11-21 12:42   ` Ard Biesheuvel
  2026-11-21 10:38 ` [PATCH 2/2] clk: sophgo: sg2042-clkgen: Keep gates of reserved devices enabled Han Gao via B4 Relay
  1 sibling, 1 reply; 4+ messages in thread
From: Han Gao via B4 Relay @ 2026-11-21 10:38 UTC (permalink / raw)
  To: Ard Biesheuvel, Ilias Apalodimas, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Stephen Boyd,
	Brian Masney, Jerome Brunet, Chen Wang, Inochi Amaoto
  Cc: Han Gao, linux-efi, linux-riscv, linux-kernel, linux-clk, sophgo,
	Han Gao

From: Han Gao <gaohan@iscas.ac.cn>

EFI_MEMORY_MAPPED_IO regions are mapped with PAGE_KERNEL, so device
registers end up mapped as normal memory.

On Milk-V Pioneer, GetTime() reads the clock controller registers and
faults:

  Oops - load access fault [#1]
  Workqueue: efi_runtime efi_call_rts
  status: 0000000200000120 badaddr: 0000007030012000 cause: 0000000000000005

Use PAGE_KERNEL_IO for these regions.

Fixes: b91540d52a08 ("RISC-V: Add EFI runtime services")
Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
---
 arch/riscv/kernel/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/efi.c b/arch/riscv/kernel/efi.c
index 2d3cc57b4535..11e85d0ebc91 100644
--- a/arch/riscv/kernel/efi.c
+++ b/arch/riscv/kernel/efi.c
@@ -22,7 +22,7 @@ static __init pgprot_t efimem_to_pgprot_map(efi_memory_desc_t *md)
 	u32 type = md->type;
 
 	if (type == EFI_MEMORY_MAPPED_IO)
-		return PAGE_KERNEL;
+		return PAGE_KERNEL_IO;
 
 	/* R-- */
 	if ((attr & (EFI_MEMORY_XP | EFI_MEMORY_RO)) ==

-- 
2.55.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] clk: sophgo: sg2042-clkgen: Keep gates of reserved devices enabled
  2026-11-21 10:38 [PATCH 0/2] riscv/clk: sophgo: Fix EFI RTC on Milk-V Pioneer Han Gao via B4 Relay
  2026-11-21 10:38 ` [PATCH 1/2] riscv: efi: Map runtime MMIO with device attributes Han Gao via B4 Relay
@ 2026-11-21 10:38 ` Han Gao via B4 Relay
  1 sibling, 0 replies; 4+ messages in thread
From: Han Gao via B4 Relay @ 2026-11-21 10:38 UTC (permalink / raw)
  To: Ard Biesheuvel, Ilias Apalodimas, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Stephen Boyd,
	Brian Masney, Jerome Brunet, Chen Wang, Inochi Amaoto
  Cc: Han Gao, linux-efi, linux-riscv, linux-kernel, linux-clk, sophgo,
	Han Gao

From: Han Gao <gaohan@iscas.ac.cn>

On Milk-V Pioneer, firmware can own I2C0 to back the EFI RTC, with the
node marked status = "reserved". I2C0 shares GATE_CLK_APB_I2C with the
I2C controllers Linux uses. When those runtime-suspend, the gate is
switched off under the firmware and GetTime() returns EFI_NOT_READY.

Walk the reserved children of /soc and match their clock references,
as done in commit 6aa175476490 ("clk: renesas: cpg-mssr: Ignore all
clocks assigned to non-Linux system"). Unlike that driver, use
CLK_IS_CRITICAL rather than CLK_IGNORE_UNUSED: the gate is shared with
devices Linux drives, and their runtime PM would still turn it off.

Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
---
 drivers/clk/sophgo/clk-sg2042-clkgen.c | 38 +++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/sophgo/clk-sg2042-clkgen.c b/drivers/clk/sophgo/clk-sg2042-clkgen.c
index 6abc2c973c49..414904965edf 100644
--- a/drivers/clk/sophgo/clk-sg2042-clkgen.c
+++ b/drivers/clk/sophgo/clk-sg2042-clkgen.c
@@ -11,6 +11,8 @@
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
 #include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_clk.h>
 #include <linux/platform_device.h>
 #include <asm/div64.h>
 
@@ -840,6 +842,35 @@ static int sg2042_clk_register_divs(struct device *dev,
 	return ret;
 }
 
+static bool sg2042_clk_is_reserved(struct device_node *clkgen, unsigned int id)
+{
+	struct device_node *soc __free(device_node) = of_find_node_by_path("/soc");
+	struct device_node *node;
+
+	for_each_reserved_child_of_node(soc, node) {
+		unsigned int i, count = of_clk_get_parent_count(node);
+
+		for (i = 0; i < count; i++) {
+			struct of_phandle_args clkspec;
+			bool match;
+
+			if (of_parse_phandle_with_args(node, "clocks", "#clock-cells",
+						       i, &clkspec))
+				continue;
+
+			match = clkspec.np == clkgen && clkspec.args_count == 1 &&
+				clkspec.args[0] == id;
+			of_node_put(clkspec.np);
+			if (match) {
+				of_node_put(node);
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
 static int sg2042_clk_register_gates(struct device *dev,
 				     struct sg2042_clk_data *clk_data,
 				     const struct sg2042_gate_clock gate_clks[],
@@ -850,7 +881,12 @@ static int sg2042_clk_register_gates(struct device *dev,
 	int i, ret = 0;
 
 	for (i = 0; i < num_gate_clks; i++) {
+		unsigned long flags;
+
 		gate = &gate_clks[i];
+		flags = gate->hw.init->flags;
+		if (sg2042_clk_is_reserved(dev->of_node, gate->id))
+			flags |= CLK_IS_CRITICAL;
 		hw = __devm_clk_hw_register_gate
 			(dev,
 			 NULL,
@@ -858,7 +894,7 @@ static int sg2042_clk_register_gates(struct device *dev,
 			 NULL,
 			 gate->hw.init->parent_hws[0],
 			 NULL,
-			 gate->hw.init->flags,
+			 flags,
 			 clk_data->iobase + gate->offset_enable,
 			 gate->bit_idx,
 			 0,

-- 
2.55.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] riscv: efi: Map runtime MMIO with device attributes
  2026-11-21 10:38 ` [PATCH 1/2] riscv: efi: Map runtime MMIO with device attributes Han Gao via B4 Relay
@ 2026-11-21 12:42   ` Ard Biesheuvel
  0 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-11-21 12:42 UTC (permalink / raw)
  To: gaohan, Ilias Apalodimas, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Stephen Boyd,
	Brian Masney, Jerome Brunet, Chen Wang, Inochi Amaoto
  Cc: Han Gao, linux-efi, linux-riscv, linux-kernel, linux-clk, sophgo



On Sat, 21 Nov 2026, at 11:38, Han Gao via B4 Relay wrote:
> From: Han Gao <gaohan@iscas.ac.cn>
>
> EFI_MEMORY_MAPPED_IO regions are mapped with PAGE_KERNEL, so device
> registers end up mapped as normal memory.
>
> On Milk-V Pioneer, GetTime() reads the clock controller registers and
> faults:
>
>   Oops - load access fault [#1]
>   Workqueue: efi_runtime efi_call_rts
>   status: 0000000200000120 badaddr: 0000007030012000 cause: 0000000000000005
>
> Use PAGE_KERNEL_IO for these regions.
>
> Fixes: b91540d52a08 ("RISC-V: Add EFI runtime services")
> Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> ---
>  arch/riscv/kernel/efi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

I can take this as a fix via the EFI tree if you like.


> diff --git a/arch/riscv/kernel/efi.c b/arch/riscv/kernel/efi.c
> index 2d3cc57b4535..11e85d0ebc91 100644
> --- a/arch/riscv/kernel/efi.c
> +++ b/arch/riscv/kernel/efi.c
> @@ -22,7 +22,7 @@ static __init pgprot_t 
> efimem_to_pgprot_map(efi_memory_desc_t *md)
>  	u32 type = md->type;
> 
>  	if (type == EFI_MEMORY_MAPPED_IO)
> -		return PAGE_KERNEL;
> +		return PAGE_KERNEL_IO;
> 
>  	/* R-- */
>  	if ((attr & (EFI_MEMORY_XP | EFI_MEMORY_RO)) ==
>
> -- 
> 2.55.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-21 12:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21 10:38 [PATCH 0/2] riscv/clk: sophgo: Fix EFI RTC on Milk-V Pioneer Han Gao via B4 Relay
2026-11-21 10:38 ` [PATCH 1/2] riscv: efi: Map runtime MMIO with device attributes Han Gao via B4 Relay
2026-11-21 12:42   ` Ard Biesheuvel
2026-11-21 10:38 ` [PATCH 2/2] clk: sophgo: sg2042-clkgen: Keep gates of reserved devices enabled Han Gao via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®