From: Chao-ying Fu <icebergfu@gmail.com>
To: opensbi@lists.infradead.org
Cc: Chao-ying Fu <cfu@mips.com>
Subject: [PATCH v5 04/10] platform: generic: mips: add the platform file
Date: Mon, 19 May 2025 14:58:41 -0700 [thread overview]
Message-ID: <20250519215848.27569-5-cfu@mips.com> (raw)
In-Reply-To: <CAAhSdy2jObwq5SUymwVmwMhcQ_h0-4OJuhwitgcVN2gPq2B=XQ@mail.gmail.com>
We add the platform file for MIPS P8700.
Signed-off-by: Chao-ying Fu <cfu@mips.com>
---
platform/generic/mips/p8700.c | 279 ++++++++++++++++++++++++++++++++++
1 file changed, 279 insertions(+)
create mode 100644 platform/generic/mips/p8700.c
diff --git a/platform/generic/mips/p8700.c b/platform/generic/mips/p8700.c
new file mode 100644
index 0000000..5f3c48a
--- /dev/null
+++ b/platform/generic/mips/p8700.c
@@ -0,0 +1,279 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 MIPS
+ *
+ */
+
+#include <platform_override.h>
+#include <sbi/riscv_barrier.h>
+#include <sbi/riscv_io.h>
+#include <sbi/sbi_domain.h>
+#include <sbi/sbi_error.h>
+#include <sbi/sbi_hsm.h>
+#include <sbi/sbi_timer.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+#include <mips/p8700.h>
+#include <mips/mips-cm.h>
+
+extern void mips_cps_core_entry(void);
+
+#if CLUSTERS_IN_PLATFORM > 1
+static void power_up_other_cluster(u32 hartid)
+{
+ unsigned int stat;
+ unsigned int timeout;
+ bool local_p = (cpu_cluster(current_hartid()) == cpu_cluster(hartid));
+
+ /* Power up cluster cl core 0 hart 0 */
+ write_cpc_pwrup_ctl(hartid, 1, local_p);
+
+ /* Wait for the CM to start up */
+ timeout = 100;
+ while (true) {
+ stat = read_cpc_cm_stat_conf(hartid, local_p);
+ stat = EXT(stat, CPC_Cx_STAT_CONF_SEQ_STATE);
+ if (stat == CPC_Cx_STAT_CONF_SEQ_STATE_U5)
+ break;
+
+ /* Delay a little while before we start warning */
+ if (timeout) {
+ sbi_dprintf("Delay a little while before we start warning\n");
+ timeout--;
+ }
+ else {
+ sbi_printf("Waiting for cluster %u CM to power up... STAT_CONF=0x%x\n",
+ cpu_cluster(hartid), stat);
+ break;
+ }
+ }
+}
+#endif
+
+static int mips_hart_start(u32 hartid, ulong saddr)
+{
+ unsigned int stat;
+ unsigned int timeout;
+ bool local_p = (cpu_cluster(current_hartid()) == cpu_cluster(hartid));
+
+ /* Hart 0 is the boot hart, and we don't use the CPC cmd to start. */
+ if (hartid == 0)
+ return SBI_ENOTSUPP;
+
+ if (cpu_hart(hartid) == 0) {
+ /* Change cluster cl core co hart 0 reset base */
+ write_gcr_co_reset_base(hartid,
+ (unsigned long)mips_cps_core_entry, local_p);
+
+ /* Ensure its coherency is disabled */
+ write_gcr_co_coherence(hartid, 0, local_p);
+
+ /* Start cluster cl core co hart 0 */
+ write_cpc_co_vp_run(hartid, 1 << cpu_hart(hartid), local_p);
+
+ /* Reset cluster cl core co hart 0 */
+ write_cpc_co_cmd(hartid, CPC_Cx_CMD_RESET, local_p);
+
+ timeout = 100;
+ while (true) {
+ stat = read_cpc_co_stat_conf(hartid, local_p);
+ stat = EXT(stat, CPC_Cx_STAT_CONF_SEQ_STATE);
+ if (stat == CPC_Cx_STAT_CONF_SEQ_STATE_U6)
+ break;
+
+ /* Delay a little while before we start warning */
+ if (timeout) {
+ sbi_timer_mdelay(10);
+ timeout--;
+ }
+ else {
+ sbi_printf("Waiting for cluster %u core %u hart %u to start... STAT_CONF=0x%x\n",
+ cpu_cluster(hartid),
+ cpu_core(hartid), cpu_hart(hartid),
+ stat);
+ break;
+ }
+ }
+ }
+ else {
+ write_gcr_co_reset_base(hartid,
+ (unsigned long)mips_cps_core_entry, local_p);
+ write_cpc_co_vp_run(hartid, 1 << cpu_hart(hartid), local_p);
+ }
+
+ return 0;
+}
+
+static int mips_hart_stop()
+{
+ u32 hartid = current_hartid();
+ bool local_p = (cpu_cluster(current_hartid()) == cpu_cluster(hartid));
+
+ /* Hart 0 is the boot hart, and we don't use the CPC cmd to stop. */
+ if (hartid == 0)
+ return SBI_ENOTSUPP;
+
+ write_cpc_co_vp_stop(hartid, 1 << cpu_hart(hartid), local_p);
+
+ return 0;
+}
+
+static const struct sbi_hsm_device mips_hsm = {
+ .name = "mips_hsm",
+ .hart_start = mips_hart_start,
+ .hart_stop = mips_hart_stop,
+};
+
+static int mips_p8700_final_init(bool cold_boot)
+{
+ if (cold_boot)
+ sbi_hsm_set_device(&mips_hsm);
+
+ return generic_final_init(cold_boot);
+}
+
+static int mips_p8700_early_init(bool cold_boot)
+{
+ int rc;
+
+ rc = generic_early_init(cold_boot);
+ if (rc)
+ return rc;
+
+ if (cold_boot)
+ {
+#if CLUSTERS_IN_PLATFORM > 1
+ int i;
+ /* Power up other clusters in the platform. */
+ for (i = 1; i < CLUSTERS_IN_PLATFORM; i++) {
+ power_up_other_cluster(i << NEW_CLUSTER_SHIFT);
+ }
+#endif
+
+ /* For the CPC mtime region, the minimum size is 0x10000. */
+ rc = sbi_domain_root_add_memrange(CM_BASE, SIZE_FOR_CPC_MTIME,
+ P8700_ALIGN,
+ (SBI_DOMAIN_MEMREGION_MMIO |
+ SBI_DOMAIN_MEMREGION_M_READABLE |
+ SBI_DOMAIN_MEMREGION_M_WRITABLE));
+ if (rc)
+ return rc;
+
+ /* For the APLIC and ACLINT m-mode region */
+ rc = sbi_domain_root_add_memrange(AIA_BASE, SIZE_FOR_AIA_M_MODE,
+ P8700_ALIGN,
+ (SBI_DOMAIN_MEMREGION_MMIO |
+ SBI_DOMAIN_MEMREGION_M_READABLE |
+ SBI_DOMAIN_MEMREGION_M_WRITABLE));
+ if (rc)
+ return rc;
+
+#if CLUSTERS_IN_PLATFORM > 1
+ for (i = 0; i < CLUSTERS_IN_PLATFORM; i++) {
+ /* For the CPC mtime region, the minimum size is 0x10000. */
+ rc = sbi_domain_root_add_memrange(GLOBAL_CM_BASE[i], SIZE_FOR_CPC_MTIME,
+ P8700_ALIGN,
+ (SBI_DOMAIN_MEMREGION_MMIO |
+ SBI_DOMAIN_MEMREGION_M_READABLE |
+ SBI_DOMAIN_MEMREGION_M_WRITABLE));
+ if (rc)
+ return rc;
+
+ /* For the APLIC and ACLINT m-mode region */
+ rc = sbi_domain_root_add_memrange(AIA_BASE - CM_BASE + GLOBAL_CM_BASE[i], SIZE_FOR_AIA_M_MODE,
+ P8700_ALIGN,
+ (SBI_DOMAIN_MEMREGION_MMIO |
+ SBI_DOMAIN_MEMREGION_M_READABLE |
+ SBI_DOMAIN_MEMREGION_M_WRITABLE));
+ if (rc)
+ return rc;
+ }
+#endif
+ }
+
+ return 0;
+}
+
+static int mips_p8700_nascent_init(void)
+{
+ u64 hartid = current_hartid();
+ u64 cm_base = CM_BASE;
+ int i;
+
+ /* Coherence enable for every core */
+ if (cpu_hart(hartid) == 0) {
+ cm_base += (cpu_core(hartid) << CM_BASE_CORE_SHIFT);
+ __raw_writeq(GCR_CORE_COH_EN_EN,
+ (void *)(cm_base + GCR_OFF_LOCAL +
+ GCR_CORE_COH_EN));
+ mb();
+ }
+
+ /* Set up pmp for DRAM */
+ csr_write(CSR_PMPADDR14, DRAM_PMP_ADDR);
+ /* All from 0x0 */
+ csr_write(CSR_PMPADDR15, 0x1fffffffffffffff);
+ csr_write(CSR_PMPCFG2, ((PMP_A_NAPOT|PMP_R|PMP_W|PMP_X)<<56)|
+ ((PMP_A_NAPOT|PMP_R|PMP_W|PMP_X)<<48));
+ /* Set cacheable for pmp6, uncacheable for pmp7 */
+ csr_write(CSR_MIPSPMACFG2, ((u64)CCA_CACHE_DISABLE << 56)|
+ ((u64)CCA_CACHE_ENABLE << 48));
+ /* Reset pmpcfg0 */
+ csr_write(CSR_PMPCFG0, 0);
+ /* Reset pmacfg0 */
+ csr_write(CSR_MIPSPMACFG0, 0);
+ mb();
+
+ /* Per cluster set up */
+ if (cpu_core(hartid) == 0 && cpu_hart(hartid) == 0) {
+ /* Enable L2 prefetch */
+ __raw_writel(0xfffff110,
+ (void *)(cm_base + L2_PFT_CONTROL_OFFSET));
+ __raw_writel(0x15ff,
+ (void *)(cm_base + L2_PFT_CONTROL_B_OFFSET));
+ }
+
+ /* Per core set up */
+ if (cpu_hart(hartid) == 0) {
+ /* Enable load pair, store pair, and HTW */
+ csr_clear(CSR_MIPSCONFIG7, (1<<12)|(1<<13)|(1<<7));
+
+ /* Disable noRFO, misaligned load/store */
+ csr_set(CSR_MIPSCONFIG7, (1<<25)|(1<<9));
+
+ /* Enable L1-D$ Prefetch */
+ csr_write(CSR_MIPSCONFIG11, 0xff);
+
+ for (i = 0; i < 8; i++) {
+ csr_set(CSR_MIPSCONFIG8, 4 + 0x100 * i);
+ csr_set(CSR_MIPSCONFIG9, 8);
+ mb();
+ RISCV_FENCE_I;
+ }
+ }
+
+ /* Per hart set up */
+ /* Enable AMO and RDTIME illegal instruction exceptions. */
+ csr_set(CSR_MIPSCONFIG6, (1<<2)|(1<<1));
+
+ return 0;
+}
+
+static int mips_p8700_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match)
+{
+ generic_platform_ops.early_init = mips_p8700_early_init;
+ generic_platform_ops.final_init = mips_p8700_final_init;
+ generic_platform_ops.nascent_init = mips_p8700_nascent_init;
+
+ return 0;
+}
+
+static const struct fdt_match mips_p8700_match[] = {
+ { .compatible = "mips,p8700" },
+ { },
+};
+
+const struct fdt_driver mips_p8700 = {
+ .match_table = mips_p8700_match,
+ .init = mips_p8700_platform_init,
+};
--
2.47.1
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2025-05-19 21:59 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-17 22:34 [PATCH] platform: generic: mips: add P8700 Chao-ying Fu
2025-02-12 12:27 ` Anup Patel
2025-02-26 0:53 ` [PATCH v2 01/11] " Chao-ying Fu
2025-03-28 4:45 ` Anup Patel
2025-02-26 0:53 ` [PATCH v2 02/11] platform: generic: mips: add header files Chao-ying Fu
2025-03-28 4:47 ` Anup Patel
2025-02-26 0:53 ` [PATCH v2 03/11] platform: generic: mips: add mips-cm header file Chao-ying Fu
2025-03-28 4:48 ` Anup Patel
2025-02-26 0:53 ` [PATCH v2 04/11] platform: generic: mips: add custom exception handler Chao-ying Fu
2025-03-28 4:53 ` Anup Patel
2025-04-08 2:49 ` Chao-ying Fu
2025-02-26 0:53 ` [PATCH v2 05/11] platform: generic: mips: add extra scratch space Chao-ying Fu
2025-03-28 4:56 ` Anup Patel
2025-02-26 0:53 ` [PATCH v2 06/11] platform: generic: mips: add an entry function Chao-ying Fu
2025-03-28 5:00 ` Anup Patel
2025-02-26 0:53 ` [PATCH v2 07/11] platform: generic: mips: add the platform file Chao-ying Fu
2025-02-26 0:53 ` [PATCH v2 08/11] platform: generic: mips: add a dts file Chao-ying Fu
2025-02-26 0:53 ` [PATCH v2 09/11] platform: generic: mips: add objects.mk Chao-ying Fu
2025-02-26 0:53 ` [PATCH v2 10/11] Change to jump to mips_cps_core_entry Chao-ying Fu
2025-02-26 0:53 ` [PATCH v2 11/11] Initialize MIPS custom PMA registers Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 0/9] *** Add MIPS P8700 platform *** Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 1/9] platform: generic: mips: add P8700 Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 2/9] platform: generic: mips: add header files Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 3/9] platform: generic: mips: add an entry function Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 4/9] platform: generic: add nanscent_init to platform_override Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 5/9] platform: generic: mips: add the platform file Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 6/9] lib: Emulate amo instructions Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 7/9] platform: generic: mips: add a dts file Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 8/9] platform: generic: mips: add objects.mk Chao-ying Fu
2025-04-10 22:45 ` [PATCH v3 9/9] Initialize MIPS custom PMA registers Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 0/8] *** Add MIPS P8700 platform *** Chao-ying Fu
2025-05-19 12:16 ` Anup Patel
2025-05-19 18:33 ` Chao-ying Fu
2025-05-19 21:52 ` Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 1/8] platform: generic: mips: add P8700 Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 2/8] platform: generic: mips: add header files Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 3/8] platform: generic: mips: add an entry function Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 4/8] platform: generic: mips: add the platform file Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 5/8] lib: Emulate amo instructions Chao-ying Fu
2025-05-19 12:14 ` Anup Patel
2025-04-29 23:29 ` [PATCH v4 6/8] platform: generic: mips: add a dts file Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 7/8] platform: generic: mips: add objects.mk Chao-ying Fu
2025-04-29 23:29 ` [PATCH v4 8/8] Initialize MIPS custom PMA registers Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 00/10] *** Add MIPS P8700 Platform *** Chao-ying Fu
2025-05-20 5:18 ` Anup Patel
2025-05-19 21:58 ` [PATCH v5 01/10] platform: generic: mips: add P8700 Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 02/10] platform: generic: mips: add header files Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 03/10] platform: generic: mips: add an entry function Chao-ying Fu
2025-05-20 5:29 ` Anup Patel
2025-05-22 20:50 ` Chao-ying Fu
2025-05-19 21:58 ` Chao-ying Fu [this message]
2025-05-19 21:58 ` [PATCH v5 05/10] platform: generic: mips: add a dts file Chao-ying Fu
2025-05-20 5:31 ` Anup Patel
2025-05-22 20:52 ` Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 06/10] platform: generic: mips: add objects.mk Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 07/10] Initialize MIPS custom PMA registers Chao-ying Fu
2025-05-20 5:08 ` Anup Patel
2025-05-22 20:47 ` Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 08/10] devices to use MMIO memory Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 09/10] platform: generic: mips: add mmio to allmem in the dts file Chao-ying Fu
2025-05-19 21:58 ` [PATCH v5 10/10] Fix PMA init for MMIO regions Chao-ying Fu
2025-05-22 21:21 ` [MIPS P8700 v6 0/7] Add MIPS P8700 support to generic platform Chao-ying Fu
2025-06-14 16:18 ` Anup Patel
2025-05-22 21:21 ` [MIPS P8700 v6 1/7] platform: generic: mips: add P8700 Chao-ying Fu
2025-05-22 21:21 ` [MIPS P8700 v6 2/7] platform: generic: mips: add header files Chao-ying Fu
2025-05-22 21:21 ` [MIPS P8700 v6 3/7] platform: generic: mips: add the platform file Chao-ying Fu
2025-05-22 21:21 ` [MIPS P8700 v6 4/7] platform: generic: mips: add objects.mk Chao-ying Fu
2025-05-22 21:21 ` [MIPS P8700 v6 5/7] devices to use MMIO memory Chao-ying Fu
2025-05-22 21:21 ` [MIPS P8700 v6 6/7] Convey MMIO flag as specified by SBI_DOMAIN_MEMREGION_MMIO Chao-ying Fu
2025-05-22 21:21 ` [MIPS P8700 v6 7/7] lib: sbi_platform: Add the platform pma_set function to set up cacheability Chao-ying Fu
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=20250519215848.27569-5-cfu@mips.com \
--to=icebergfu@gmail.com \
--cc=cfu@mips.com \
--cc=opensbi@lists.infradead.org \
/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