Skip to contentSkip to conversation

riscv: cpu: Add support for cv1800b SoC

PATCH In review Kongyang Liu 2 participants 5 messages Mar 9, 2024 – Mar 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover riscv: cpu: Add support for cv1800b SoC

This series add basic support for cv1800b SoC and enable dcache support.

The cv1800b utilizes CSR instructions to manipulate the first and second bits in the MHCR register (0x7C1) to indicate the activation status of icache and dcache. As the icache and dcache are already enabled in the FSBL (first stage bootloader) provided by the vendor, and the U-Boot running in S-Mode is unable to manipulate CSR registers, support for operations related to enabling, disabling, or checking the status of the cache is not provided.

Changes in v2:
- Remove duplicate code in function cleanup_before_linux

Kongyang Liu (2):
riscv: cpu: cv1800b: Add support for cv1800b SoC
riscv: cache: Implement dcache for cv1800b

 arch/riscv/Kconfig              |  1 +
 arch/riscv/cpu/cv1800b/Kconfig  | 12 +++++++++
 arch/riscv/cpu/cv1800b/Makefile |  7 +++++
 arch/riscv/cpu/cv1800b/cache.c  | 45 +++++++++++++++++++++++++++++++++
 arch/riscv/cpu/cv1800b/cpu.c    |  9 +++++++
 arch/riscv/cpu/cv1800b/dram.c   | 21 +++++++++++++++
 board/sophgo/milkv_duo/Kconfig  |  4 +--
 7 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/cpu/cv1800b/Kconfig
 create mode 100644 arch/riscv/cpu/cv1800b/Makefile
 create mode 100644 arch/riscv/cpu/cv1800b/cache.c
 create mode 100644 arch/riscv/cpu/cv1800b/cpu.c
 create mode 100644 arch/riscv/cpu/cv1800b/dram.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/2 riscv: cpu: cv1800b: Add support for cv1800b SoC

Add Sophgo cv1800b SoC to support RISC-V arch.

---

Changes in v2:
- Remove duplicate code in function cleanup_before_linux

 arch/riscv/Kconfig              |  1 +
 arch/riscv/cpu/cv1800b/Kconfig  | 12 ++++++++++++
 arch/riscv/cpu/cv1800b/Makefile |  6 ++++++
 arch/riscv/cpu/cv1800b/cpu.c    |  9 +++++++++
 arch/riscv/cpu/cv1800b/dram.c   | 21 +++++++++++++++++++++
 board/sophgo/milkv_duo/Kconfig  |  4 ++--
 6 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/cpu/cv1800b/Kconfig
 create mode 100644 arch/riscv/cpu/cv1800b/Makefile
 create mode 100644 arch/riscv/cpu/cv1800b/cpu.c
 create mode 100644 arch/riscv/cpu/cv1800b/dram.c
arch/riscv/Kconfig +1 -0
index ac52c5e6da..2c92b0d9f6 100644
@@ -93,6 +93,7 @@ source "board/xilinx/mbv/Kconfig"
 
 # platform-specific options below
 source "arch/riscv/cpu/andesv5/Kconfig"
+source "arch/riscv/cpu/cv1800b/Kconfig"
 source "arch/riscv/cpu/fu540/Kconfig"
 source "arch/riscv/cpu/fu740/Kconfig"
 source "arch/riscv/cpu/generic/Kconfig"
arch/riscv/cpu/cv1800b/Kconfig new file +12 -0
new file mode 100644
index 0000000000..7225b1210c
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2024, Kongyang Liu <[email protected]>
+
+config SOPHGO_CV1800B
+	bool
+	select ARCH_EARLY_INIT_R
+	select SYS_CACHE_SHIFT_6
+	imply CPU
+	imply CPU_RISCV
+	imply RISCV_TIMER
+	imply CMD_CPU
arch/riscv/cpu/cv1800b/Makefile new file +6 -0
new file mode 100644
index 0000000000..da12e0f64e
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2024, Kongyang Liu <[email protected]>
+
+obj-y += dram.o
+obj-y += cpu.o
arch/riscv/cpu/cv1800b/cpu.c new file +9 -0
new file mode 100644
index 0000000000..233a6a3d64
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024, Kongyang Liu <[email protected]>
+ */
+
+int cleanup_before_linux(void)
+{
+	return 0;
+}
arch/riscv/cpu/cv1800b/dram.c new file +21 -0
new file mode 100644
index 0000000000..91007c0a3d
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng <[email protected]>
+ */
+
+#include <fdtdec.h>
+#include <init.h>
+#include <asm/global_data.h>
+#include <linux/sizes.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int dram_init(void)
+{
+	return fdtdec_setup_mem_size_base();
+}
+
+int dram_init_banksize(void)
+{
+	return fdtdec_setup_memory_banksize();
+}
board/sophgo/milkv_duo/Kconfig +2 -2
index 2a458f291c..040a7487f1 100644
@@ -7,7 +7,7 @@ config SYS_VENDOR
 	default "sophgo"
 
 config SYS_CPU
-	default "generic"
+	default "cv1800b"
 
 config SYS_CONFIG_NAME
 	default "milkv_duo"
@@ -23,6 +23,6 @@ config ENV_SECT_SIZE
 
 config BOARD_SPECIFIC_OPTIONS
 	def_bool y
-	select GENERIC_RISCV
+	select SOPHGO_CV1800B
 
 endif
Signature · 1 line
2.41.0
#3 lore raw

PATCH v2 2/2 riscv: cache: Implement dcache for cv1800b

In reply to Kongyang Liu

Add dcache operations invalidate_dcache_range and flush_dcache_range for cv1800b.

---

(no changes since v1)

 arch/riscv/cpu/cv1800b/Makefile |  1 +
 arch/riscv/cpu/cv1800b/cache.c  | 45 +++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 arch/riscv/cpu/cv1800b/cache.c
arch/riscv/cpu/cv1800b/Makefile +1 -0
index da12e0f64e..95beb34b51 100644
@@ -4,3 +4,4 @@
 
 obj-y += dram.o
 obj-y += cpu.o
+obj-y += cache.o
arch/riscv/cpu/cv1800b/cache.c new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.41.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] riscv: cpu: cv1800b: Add support for cv1800b SoC

In reply to Kongyang Liu
Quoted 8 lines · Kongyang Liu

Add Sophgo cv1800b SoC to support RISC-V arch.

---

Changes in v2:
- Remove duplicate code in function cleanup_before_linux

Quoted 11 lines
 arch/riscv/Kconfig              |  1 +
 arch/riscv/cpu/cv1800b/Kconfig  | 12 ++++++++++++
 arch/riscv/cpu/cv1800b/Makefile |  6 ++++++
 arch/riscv/cpu/cv1800b/cpu.c    |  9 +++++++++
 arch/riscv/cpu/cv1800b/dram.c   | 21 +++++++++++++++++++++
 board/sophgo/milkv_duo/Kconfig  |  4 ++--
 6 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/cpu/cv1800b/Kconfig
 create mode 100644 arch/riscv/cpu/cv1800b/Makefile
 create mode 100644 arch/riscv/cpu/cv1800b/cpu.c
 create mode 100644 arch/riscv/cpu/cv1800b/dram.c
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] riscv: cache: Implement dcache for cv1800b

In reply to Kongyang Liu
Quoted 4 lines · Kongyang Liu

Add dcache operations invalidate_dcache_range and flush_dcache_range for cv1800b.

Quoted 8 lines

---

(no changes since v1)

 arch/riscv/cpu/cv1800b/Makefile |  1 +
 arch/riscv/cpu/cv1800b/cache.c  | 45 +++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 arch/riscv/cpu/cv1800b/cache.c