Skip to contentSkip to conversation

riscv: cpu: Add support for cv1800b SoC

PATCH Superseded Kongyang Liu 2 participants 5 messages Feb 2, 2024 – Feb 3, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#2 lore raw

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

In reply to Kongyang Liu
Quoted 78 lines · Kongyang Liu

Add Sophgo cv1800b SoC to support RISC-V arch.

---

  arch/riscv/Kconfig              |  1 +
  arch/riscv/cpu/cv1800b/Kconfig  | 12 ++++++++++++
  arch/riscv/cpu/cv1800b/Makefile |  6 ++++++
  arch/riscv/cpu/cv1800b/cpu.c    | 22 ++++++++++++++++++++++
  arch/riscv/cpu/cv1800b/dram.c   | 21 +++++++++++++++++++++
  board/sophgo/milkv_duo/Kconfig  |  4 ++--
  6 files changed, 64 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 +12 -0
new file mode 100644
index 0000000000..f13c18942f
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng <[email protected]>
+ */
+
+#include <irq_func.h>
+#include <asm/cache.h>
+
+/*
+ * cleanup_before_linux() is called just before we call linux
+ * it prepares the processor for linux
+ *

arch/riscv/cpu/cv1800b/cpu.c line 22

Quoted 10 lines
arch/riscv/cpu/cv1800b/cpu.c new file +10 -0
+ * we disable interrupt and caches.
+ */
+int cleanup_before_linux(void)
+{
+	disable_interrupts();
+
+	cache_flush();
+
+	return 0;
+}

Thank you for enabling another board.

The same cleanup_before_linux() code can be found in:

arch/riscv/cpu/fu740/cpu.c
arch/riscv/cpu/andesv5/cpu.c
arch/riscv/cpu/fu540/cpu.c
arch/riscv/cpu/generic/cpu.c
arch/riscv/cpu/jh7110/cpu.c

We should try to avoid this code duplication.

disable_interrupts() is already called by bootm_disable_interrupts().

flushing the instruction cache after loading a binary is not architecture specific either. This is why bootm_load_os() calls flush_cache().

It should be sufficient to let weak function flush_dcache_range() in arch/riscv/lib/cache.c call flush_dcache_all(). And then remove all cleanup_before_linux() implementations.

Best regards

Heinrich

Quoted 48 lines
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
#0 lore raw

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.

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    | 22 ++++++++++++++++
 arch/riscv/cpu/cv1800b/dram.c   | 21 +++++++++++++++
 board/sophgo/milkv_duo/Kconfig  |  4 +--
 7 files changed, 110 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 1/2 riscv: cpu: cv1800b: Add support for cv1800b SoC

Add Sophgo cv1800b SoC to support RISC-V arch.

---

 arch/riscv/Kconfig              |  1 +
 arch/riscv/cpu/cv1800b/Kconfig  | 12 ++++++++++++
 arch/riscv/cpu/cv1800b/Makefile |  6 ++++++
 arch/riscv/cpu/cv1800b/cpu.c    | 22 ++++++++++++++++++++++
 arch/riscv/cpu/cv1800b/dram.c   | 21 +++++++++++++++++++++
 board/sophgo/milkv_duo/Kconfig  |  4 ++--
 6 files changed, 64 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 +22 -0
new file mode 100644
index 0000000000..f13c18942f
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng <[email protected]>
+ */
+
+#include <irq_func.h>
+#include <asm/cache.h>
+
+/*
+ * cleanup_before_linux() is called just before we call linux
+ * it prepares the processor for linux
+ *
+ * we disable interrupt and caches.
+ */
+int cleanup_before_linux(void)
+{
+	disable_interrupts();
+
+	cache_flush();
+
+	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
#4 lore raw

PATCH 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.

---

 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
#3 lore raw

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

In reply to Heinrich Schuchardt
Quoted 105 lines · Heinrich Schuchardt <[email protected]> 于2024年2月2日周五 19:11写道:
Quoted 78 lines · Kongyang Liu

Add Sophgo cv1800b SoC to support RISC-V arch.

---

  arch/riscv/Kconfig              |  1 +
  arch/riscv/cpu/cv1800b/Kconfig  | 12 ++++++++++++
  arch/riscv/cpu/cv1800b/Makefile |  6 ++++++
  arch/riscv/cpu/cv1800b/cpu.c    | 22 ++++++++++++++++++++++
  arch/riscv/cpu/cv1800b/dram.c   | 21 +++++++++++++++++++++
  board/sophgo/milkv_duo/Kconfig  |  4 ++--
  6 files changed, 64 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 +12 -0
new file mode 100644
index 0000000000..f13c18942f
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng <[email protected]>
+ */
+
+#include <irq_func.h>
+#include <asm/cache.h>
+
+/*
+ * cleanup_before_linux() is called just before we call linux
+ * it prepares the processor for linux
+ *

arch/riscv/cpu/cv1800b/cpu.c line 22

Quoted 10 lines
arch/riscv/cpu/cv1800b/cpu.c new file +10 -0
+ * we disable interrupt and caches.
+ */
+int cleanup_before_linux(void)
+{
+     disable_interrupts();
+
+     cache_flush();
+
+     return 0;
+}

Thank you for enabling another board.

The same cleanup_before_linux() code can be found in:

arch/riscv/cpu/fu740/cpu.c
arch/riscv/cpu/andesv5/cpu.c
arch/riscv/cpu/fu540/cpu.c
arch/riscv/cpu/generic/cpu.c
arch/riscv/cpu/jh7110/cpu.c

We should try to avoid this code duplication.

disable_interrupts() is already called by bootm_disable_interrupts().

Quoted 8 lines

flushing the instruction cache after loading a binary is not architecture specific either. This is why bootm_load_os() calls flush_cache().

It should be sufficient to let weak function flush_dcache_range() in arch/riscv/lib/cache.c call flush_dcache_all(). And then remove all cleanup_before_linux() implementations.

Thanks for your explanation.

Currently, we have only implemented cache for SoC cv1800b, and for the sake of compatibility, the remaining code has been simply copied from the generic folder without a thorough examination.

If this function is unnecessary, it will be removed in the next version.

Best regards
Kongyang Liu

Quoted 54 lines

Best regards

Heinrich

Quoted 48 lines
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