Skip to contentSkip to conversation

Add RISC-V 32 NOMMU support

PATCH Superseded Jesse Taube 2 participants 8 messages Feb 12, 2023 – Feb 13, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add RISC-V 32 NOMMU support

This patch-set aims to add NOMMU support to RV32. Many people want to build simple emulators or HDL models of RISC-V this patch makes it possible to run linux on them.

Yimin Gu is the original author of this set. Submitted here:
https://lists.buildroot.org/pipermail/buildroot/2022-November/656134.html

Though Jesse T rewrote the Dconf.

The new set:
https://lists.buildroot.org/pipermail/buildroot/2022-December/658258.html
---
V1->V2:
- Add Conor's clock patch for implicit div64
- Fix typo in commit title 3/3
- Fix typo in commit description 2/3
---

Conor Dooley (1):
clk: k210: remove an implicit 64-bit division

Jesse Taube (1):
riscv: configs: Add nommu defconfig for RV32

Yimin Gu (1):
riscv: Kconfig: Allow RV32 to build with no MMU

 arch/riscv/Kconfig                           |  5 ++---
 arch/riscv/configs/rv32_nommu_virt_defconfig | 16 ++++++++++++++++
 drivers/clk/clk-k210.c                       |  2 +-
 3 files changed, 19 insertions(+), 4 deletions(-)
 create mode 100644 arch/riscv/configs/rv32_nommu_virt_defconfig
Signature · 1 line
2.39.0
#1 lore raw

PATCH v2 1/3 clk: k210: remove an implicit 64-bit division

From: Conor Dooley <[email protected]>

The K210 clock driver depends on SOC_CANAAN, which is only selectable when !MMU on RISC-V. !MMU is not possible on 32-bit yet, but patches have been sent for its enabling. The kernel test robot reported this implicit 64-bit division there.

Replace the implicit division with an explicit one.

---
 drivers/clk/clk-k210.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk-k210.c +1 -1
index 67a7cb3503c3..4eed667eddaf 100644
@@ -495,7 +495,7 @@ static unsigned long k210_pll_get_rate(struct clk_hw *hw,
 	f = FIELD_GET(K210_PLL_CLKF, reg) + 1;
 	od = FIELD_GET(K210_PLL_CLKOD, reg) + 1;
 
-	return (u64)parent_rate * f / (r * od);
+	return div_u64((u64)parent_rate * f, r * od);
 }
 
 static const struct clk_ops k210_pll_ops = {
Signature · 1 line
2.39.0
#2 lore raw

Re: [PATCH v2 1/3] clk: k210: remove an implicit 64-bit division

Quoted 7 lines · Jesse Taube

From: Conor Dooley <[email protected]>

The K210 clock driver depends on SOC_CANAAN, which is only selectable when !MMU on RISC-V. !MMU is not possible on 32-bit yet, but patches have been sent for its enabling. The kernel test robot reported this implicit 64-bit division there.

Quoted 6 lines

Replace the implicit division with an explicit one.

btw, you'll need to run get_maintainer.pl on this patch so that the k210 and clock maintainers are CCed.

It's also worth adding Damien Le Moal <[email protected]>

Quoted 20 lines
---
 drivers/clk/clk-k210.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk-k210.c +1 -1
index 67a7cb3503c3..4eed667eddaf 100644
@@ -495,7 +495,7 @@ static unsigned long k210_pll_get_rate(struct clk_hw *hw,
 	f = FIELD_GET(K210_PLL_CLKF, reg) + 1;
 	od = FIELD_GET(K210_PLL_CLKOD, reg) + 1;
 
-	return (u64)parent_rate * f / (r * od);
+	return div_u64((u64)parent_rate * f, r * od);
 }
 
 static const struct clk_ops k210_pll_ops = {
Signature · 1 line
2.39.0

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw

PATCH v2 2/3 riscv: Kconfig: Allow RV32 to build with no MMU

In reply to Jesse Taube

From: Yimin Gu <[email protected]>

Some RISC-V 32bit cores do not have an MMU, and the kernel should be able to build for them. This patch enables the RV32 to be built with no MMU support.

---
 arch/riscv/Kconfig | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/riscv/Kconfig +2 -3
index 59d18881f35b..49759dbe6a8f 100644
@@ -163,8 +163,8 @@ config MMU
 
 config PAGE_OFFSET
 	hex
-	default 0xC0000000 if 32BIT
-	default 0x80000000 if 64BIT && !MMU
+	default 0xC0000000 if 32BIT && MMU
+	default 0x80000000 if !MMU
 	default 0xff60000000000000 if 64BIT
 
 config KASAN_SHADOW_OFFSET
@@ -262,7 +262,6 @@ config ARCH_RV32I
 	select GENERIC_LIB_ASHRDI3
 	select GENERIC_LIB_LSHRDI3
 	select GENERIC_LIB_UCMPDI2
-	select MMU
 
 config ARCH_RV64I
 	bool "RV64I"
Signature · 1 line
2.39.0
#4 lore raw

PATCH v2 3/3 riscv: configs: Add nommu defconfig for RV32

In reply to Jesse Taube

32bit risc-v can be configured to run without MMU. This patch adds an example configuration for RV32 nommu virtual machine.

---
 arch/riscv/configs/rv32_nommu_virt_defconfig | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 arch/riscv/configs/rv32_nommu_virt_defconfig
arch/riscv/configs/rv32_nommu_virt_defconfig new file +16 -0
new file mode 100644
index 000000000000..460907253a80
@@ -0,0 +1,16 @@
+CONFIG_BLK_DEV_INITRD=y
+# CONFIG_MMU is not set
+CONFIG_COMPAT_32BIT_TIME=y
+CONFIG_SOC_VIRT=y
+CONFIG_NONPORTABLE=y
+CONFIG_ARCH_RV32I=y
+CONFIG_BINFMT_FLAT=y
+CONFIG_SLOB=y
+CONFIG_VIRTIO_BLK=y
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_OF_PLATFORM=y
+CONFIG_VIRTIO_MMIO=y
+CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
+CONFIG_EXT2_FS=y
+CONFIG_PRINTK_TIME=y
Signature · 1 line
2.39.0
#5 lore raw

Re: [PATCH v2 3/3] riscv: configs: Add nommu defconfig for RV32

Hey Jesse,

Quoted 2 lines · Jesse Taube

32bit risc-v can be configured to run without MMU. This patch adds an example configuration for RV32 nommu virtual machine.

There's a patch on the list (I think it came in after you sent v1) that pointed out that the rv32_defconfig in the tree is not actually used if you do make ARCH=riscv rv32_defconfig, but instead a make target is used. How would you feel about replacing this final patch with the below? That way rv32_nommu_virt_defconfig would always be kept in sync with the rv64 version.

Cheers,
Conor.

arch/riscv/Makefile +4 -0
index 7123511d977c..785d438ae5fe 100644
@@ -173,3 +173,7 @@ rv64_randconfig:
 PHONY += rv32_defconfig
 rv32_defconfig:
 	$(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
+
+PHONY += rv32_nommu_virt_defconfig
+rv32_nommu_virt_defconfig:
+	$(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw

Re: [PATCH v2 3/3] riscv: configs: Add nommu defconfig for RV32

Quoted 10 lines · Conor Dooley

Hey Jesse,

Quoted 2 lines · Jesse Taube

32bit risc-v can be configured to run without MMU. This patch adds an example configuration for RV32 nommu virtual machine.

There's a patch on the list (I think it came in after you sent v1) that pointed out that the rv32_defconfig in the tree is not actually used if you do make ARCH=riscv rv32_defconfig, but instead a make target is used.

Oh that's interesting. Why is it still int the tree? How would you feel about replacing this final patch with the

Quoted 2 lines

below? That way rv32_nommu_virt_defconfig would always be kept in sync with the rv64 version.

Sounds good! The only gripe I have is the nommu_virt_defconfig is not very minimal, but that's not my problem.

Thanks,
Jesse Taube

Quoted 17 lines

Cheers,
Conor.

arch/riscv/Makefile +4 -0
index 7123511d977c..785d438ae5fe 100644
@@ -173,3 +173,7 @@ rv64_randconfig:
  PHONY += rv32_defconfig
  rv32_defconfig:
  	$(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
+
+PHONY += rv32_nommu_virt_defconfig
+rv32_nommu_virt_defconfig:
+	$(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config
#7 lore raw

Re: [PATCH v2 3/3] riscv: configs: Add nommu defconfig for RV32

Quoted 6 lines · Jesse Taube
Quoted 3 lines · Conor Dooley

Hey Jesse,

On Sun, Feb 12, 2023 at 03:55:06PM -0500, Jesse Taube wrote:

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

32bit risc-v can be configured to run without MMU. This patch adds an example configuration for RV32 nommu virtual machine.

There's a patch on the list (I think it came in after you sent v1) that pointed out that the rv32_defconfig in the tree is not actually used if you do make ARCH=riscv rv32_defconfig, but instead a make target is used.

Oh that's interesting. Why is it still int the tree?

See that's the thing - the patch was deleting the rv32_defconfig file:
https://lore.kernel.org/linux-riscv/[email protected]/

Quoted 25 lines
Quoted 3 lines

How would you feel about replacing this final patch with the below? That way rv32_nommu_virt_defconfig would always be kept in sync with the rv64 version.

Sounds good! The only gripe I have is the nommu_virt_defconfig is not very minimal, but that's not my problem.

Thanks,
Jesse Taube

Quoted 17 lines

Cheers,
Conor.

arch/riscv/Makefile +4 -0
index 7123511d977c..785d438ae5fe 100644
@@ -173,3 +173,7 @@ rv64_randconfig:
  PHONY += rv32_defconfig
  rv32_defconfig:
  	$(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
+
+PHONY += rv32_nommu_virt_defconfig
+rv32_nommu_virt_defconfig:
+	$(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config