public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: wefu@redhat.com
To: u-boot@lists.denx.de, bmeng@tinylab.org, rick@andestech.com,
	trini@konsulko.com, wefu@redhat.com, dlan@gentoo.org,
	joe.hershberger@ni.com, rfried.dev@gmail.com, ypron.glpk@gmx.de,
	michal.simek@amd.com, randolph@andestech.com,
	seashell11234455@gmail.com, peterlin@andestech.com,
	samuel@sholland.org, wiagn233@outlook.com, jonas@kwiboo.se,
	seanga2@gmail.com, baruch@tkos.co.il, kever.yang@rock-chips.com,
	sjg@chromium.org, gilbsgilbert@gmail.com, ycliang@andestech.com
Cc: tekkamanninja@gmail.com, tekkamanninja@163.com
Subject: [PATCH 1/6] cpu: add t-head's c9xx
Date: Wed, 27 Mar 2024 16:07:22 +0800	[thread overview]
Message-ID: <20240327080817.44501-2-wefu@redhat.com> (raw)
In-Reply-To: <20240327080817.44501-1-wefu@redhat.com>

From: Wei Fu <wefu@redhat.com>

Signed-off-by: Wei Fu <wefu@redhat.com>
Co-authored-by: Yixun Lan <dlan@gentoo.org>
---
 arch/riscv/Kconfig               |  1 +
 arch/riscv/cpu/c9xx/Kconfig      | 12 ++++++++
 arch/riscv/cpu/c9xx/Makefile     |  5 ++++
 arch/riscv/cpu/c9xx/cpu.c        | 51 ++++++++++++++++++++++++++++++++
 arch/riscv/cpu/c9xx/dram.c       | 36 ++++++++++++++++++++++
 arch/riscv/include/asm/csr.h     |  2 ++
 board/thead/th1520_lpi4a/Kconfig |  3 +-
 7 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index ac52c5e6da..ac3b802abe 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -97,6 +97,7 @@ source "arch/riscv/cpu/fu540/Kconfig"
 source "arch/riscv/cpu/fu740/Kconfig"
 source "arch/riscv/cpu/generic/Kconfig"
 source "arch/riscv/cpu/jh7110/Kconfig"
+source "arch/riscv/cpu/c9xx/Kconfig"
 
 # architecture-specific options below
 
diff --git a/arch/riscv/cpu/c9xx/Kconfig b/arch/riscv/cpu/c9xx/Kconfig
new file mode 100644
index 0000000000..5a84bcacd6
--- /dev/null
+++ b/arch/riscv/cpu/c9xx/Kconfig
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2017-2020 Alibaba Group Holding Limited
+
+config RISCV_THEAD
+	bool
+	select ARCH_EARLY_INIT_R
+	imply CPU
+	imply CPU_RISCV
+	imply RISCV_TIMER
+	imply RISCV_RDTIME
+	imply CMD_CPU
diff --git a/arch/riscv/cpu/c9xx/Makefile b/arch/riscv/cpu/c9xx/Makefile
new file mode 100644
index 0000000000..e3f776cb41
--- /dev/null
+++ b/arch/riscv/cpu/c9xx/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2017-2020 Alibaba Group Holding Limited
+
+obj-y += cpu.o dram.o
diff --git a/arch/riscv/cpu/c9xx/cpu.c b/arch/riscv/cpu/c9xx/cpu.c
new file mode 100644
index 0000000000..4b21edd62b
--- /dev/null
+++ b/arch/riscv/cpu/c9xx/cpu.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017-2020 Alibaba Group Holding Limited
+ */
+
+#include <asm/cache.h>
+#include <asm/csr.h>
+#include <cpu_func.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)
+{
+	cache_flush();
+
+	return 0;
+}
+
+void flush_dcache_range(unsigned long start, unsigned long end)
+{
+	register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+
+	for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE)
+		asm volatile(".long 0x0295000b");  /* dcache.cpa a0 */
+
+	sync_is();
+}
+
+void invalidate_dcache_range(unsigned long start, unsigned long end)
+{
+	register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+
+	for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE)
+		asm volatile(".long 0x02b5000b");  /* dcache.cipa a0 */
+
+	sync_is();
+}
+
+void invalid_dcache_range(unsigned long start, unsigned long end)
+{
+	register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+
+	for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE)
+		asm volatile(".long 0x02a5000b");  /* dcache.ipa a0 */
+
+	sync_is();
+}
diff --git a/arch/riscv/cpu/c9xx/dram.c b/arch/riscv/cpu/c9xx/dram.c
new file mode 100644
index 0000000000..614d7bf1cc
--- /dev/null
+++ b/arch/riscv/cpu/c9xx/dram.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
+ */
+
+#include <fdtdec.h>
+#include <init.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();
+}
+
+phys_size_t board_get_usable_ram_top(phys_size_t total_size)
+{
+	/*
+	 * Ensure that we run from first 4GB so that all
+	 * addresses used by U-Boot are 32bit addresses.
+	 *
+	 * This in-turn ensures that 32bit DMA capable
+	 * devices work fine because DMA mapping APIs will
+	 * provide 32bit DMA addresses only.
+	 */
+	if (gd->ram_top >= SZ_4G)
+		return SZ_4G - 1;
+
+	return gd->ram_top;
+}
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 986f951c31..3102de6cbb 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -145,6 +145,8 @@
 #define CSR_MARCHID		0xf12
 #define CSR_MHARTID		0xf14
 
+#define sync_is()   asm volatile (".long 0x01b0000b")
+
 #ifndef __ASSEMBLY__
 
 #define csr_swap(csr, val)					\
diff --git a/board/thead/th1520_lpi4a/Kconfig b/board/thead/th1520_lpi4a/Kconfig
index 622246127c..bef0638e80 100644
--- a/board/thead/th1520_lpi4a/Kconfig
+++ b/board/thead/th1520_lpi4a/Kconfig
@@ -11,7 +11,7 @@ config SYS_VENDOR
 	default "thead"
 
 config SYS_CPU
-	default "generic"
+	default "c9xx"
 
 config SYS_CONFIG_NAME
 	default "th1520_lpi4a"
@@ -30,6 +30,7 @@ config SPL_OPENSBI_LOAD_ADDR
 config BOARD_SPECIFIC_OPTIONS
 	def_bool y
 	select ARCH_EARLY_INIT_R
+	select RISCV_THEAD
 	imply CPU
 	imply CPU_RISCV
 	imply RISCV_TIMER if RISCV_SMODE
-- 
2.44.0


  reply	other threads:[~2024-03-27 11:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27  8:07 [PATCH 0/6] riscv: adds T-Head C9xx basic and GMAC support wefu
2024-03-27  8:07 ` wefu [this message]
2024-03-27 13:30   ` [PATCH 1/6] cpu: add t-head's c9xx Nils Le Roux
2024-03-27  8:07 ` [PATCH 2/6] riscv/dts: add gmac node for th1520 wefu
2024-03-27  8:07 ` [PATCH 3/6] riscv/dts: add gmac node for lichee-pi-4a wefu
2024-03-27  8:07 ` [PATCH 4/6] net/designware: add compatible for "snps,dwmac" wefu
2024-03-27  8:07 ` [PATCH 5/6] config/th1520_lpi4a_defconfig:enable designware ethernet & realtek phy wefu
2024-03-27  8:07 ` [PATCH 6/6] config/th1520_lpi4a.h: add more env option for booting linux wefu
2024-03-27 12:07 ` [PATCH 0/6] riscv: adds T-Head C9xx basic and GMAC support Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240327080817.44501-2-wefu@redhat.com \
    --to=wefu@redhat.com \
    --cc=baruch@tkos.co.il \
    --cc=bmeng@tinylab.org \
    --cc=dlan@gentoo.org \
    --cc=gilbsgilbert@gmail.com \
    --cc=joe.hershberger@ni.com \
    --cc=jonas@kwiboo.se \
    --cc=kever.yang@rock-chips.com \
    --cc=michal.simek@amd.com \
    --cc=peterlin@andestech.com \
    --cc=randolph@andestech.com \
    --cc=rfried.dev@gmail.com \
    --cc=rick@andestech.com \
    --cc=samuel@sholland.org \
    --cc=seanga2@gmail.com \
    --cc=seashell11234455@gmail.com \
    --cc=sjg@chromium.org \
    --cc=tekkamanninja@163.com \
    --cc=tekkamanninja@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=wiagn233@outlook.com \
    --cc=ycliang@andestech.com \
    --cc=ypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox