Files
opensbi/platform/generic/spacemit/k3.c
T
Xianbin Zhu cca121056f platform: generic: spacemit: k3: add platform support
SpacemiT K3 has 16 harts split across four clusters, with eight X100
harts in C0/C1 and eight A100 harts in C2/C3. Only hart 0 is powered at
reset, so secondary harts cannot reach the OpenSBI warm-boot path until
the platform removes their PMU power-down votes and wakes them.

Add a start-only HSM backend which performs those operations for the
requested hart. This lets the common HSM state machine start secondary
harts on demand instead of waking every hart during cold boot.
Select the HSM backend from the root compatible, preserving K1's
existing start and stop behavior.

The Boot ROM maps the audio buffer region as I/O although later firmware
uses it as normal memory. Restore its cacheable PMA attribute and mark
the XIP region as I/O before enabling caches. The boot hart performs the
per-hart setup during early platform discovery, while secondary harts do
the same in their assembly entry before reaching common warm-boot code.
This also enables MISA.H on X100 before common code selects its trap
entry; A100 does not implement H. Fence the PMA and guest translation
changes before continuing.

Use assembler-safe constants shared by the C and warm-entry assembly
paths. Since K1 and K3 are RV64-only, omit the SpacemiT platform objects
from RV32 generic builds.

Program the four cluster warm-boot vectors once and enable CCI-550 snoop
and DVM requests before any secondary hart is started.

Signed-off-by: Xianbin Zhu <xianbin.zhu@linux.spacemit.com>
Tested-by: E Shattow <e@freeshell.de>
Co-developed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20261028-spacemit-k3-v6-5-01d984f60941@linux.spacemit.com
Signed-off-by: Anup Patel <anup@brainfault.org>
2026-10-29 11:24:05 +05:30

123 lines
3.4 KiB
C

/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2026 SpacemiT
* Authors:
* Xianbin Zhu <xianbin.zhu@linux.spacemit.com>
* Troy Mitchell <troy.mitchell@linux.spacemit.com>
*/
#include <platform_override.h>
#include <sbi/riscv_asm.h>
#include <sbi/riscv_io.h>
#include <sbi/sbi_hfence.h>
#include <sbi/sbi_tlb.h>
#include <spacemit/k3.h>
#include <spacemit/k3_asm.h>
#include <spacemit/spacemit.h>
static const int cci_map[] = {
PLAT_CCI_K3_AIDMA_IFACE_IX,
PLAT_CCI_K3_CLUSTER0_IFACE_IX,
PLAT_CCI_K3_CLUSTER1_IFACE_IX,
PLAT_CCI_K3_CLUSTER2_0_IFACE_IX,
PLAT_CCI_K3_CLUSTER2_1_IFACE_IX,
PLAT_CCI_K3_CLUSTER3_0_IFACE_IX,
PLAT_CCI_K3_CLUSTER3_1_IFACE_IX,
};
/*
* The boot hart reaches this function before caches are enabled. Secondary
* harts perform the same setup in _spacemit_k3_warm_start before entering
* the common warm-boot path.
*/
static void spacemit_k3_hart_init(u32 hartid)
{
csr_clear(CSR_PMACFG0,
PMACFG0_AUDIO_BUF_FIELD_MASK <<
PMACFG0_AUDIO_BUF_FIELD_SHIFT);
csr_set(CSR_PMACFG0,
PMACFG0_AUDIO_BUF_ATTR_CACHEABLE <<
PMACFG0_AUDIO_BUF_FIELD_SHIFT);
csr_clear(CSR_PMACFG0, PMACFG0_XIP_FIELD_CLEAR);
csr_set(CSR_PMACFG0, PMACFG0_XIP_ATTR_IO);
__sbi_sfence_vma_all();
csr_set(CSR_ML2SETUP,
_BITUL(hartid % PLATFORM_MAX_CPUS_PER_CLUSTER) |
ML2SETUP_IPRF | ML2SETUP_TPRF);
csr_set(CSR_ML2HINT, ML2HINT_TRACE_TOP_ICGEN);
csr_set(CSR_MSETUP, MSETUP_BOOT_FLAGS);
if (hartid < PLATFORM_A100_FIRST_ID) {
/* MISA.H is writable on X100 and not implemented on A100. */
csr_set(CSR_MISA, MISA_EXT_H);
__sbi_hfence_gvma_all();
}
}
/* The boot hart is already running, so it is never started by the HSM. */
static void spacemit_k3_keep_boot_hart_powered(void)
{
u32 value;
value = readl((void *)(unsigned long)PMU_CX_CAPMP_IDLE_CFG0);
value &= ~CLUSTER_PWR_DOWN_VALUE;
writel(value, (void *)(unsigned long)PMU_CX_CAPMP_IDLE_CFG0);
value = readl((void *)(unsigned long)PMU_AP_CORE0_IDLE_CFG);
value &= ~PMU_AP_IDLE_PWRDOWN_K3_MASK;
writel(value, (void *)(unsigned long)PMU_AP_CORE0_IDLE_CFG);
}
/* Program global state before the HSM starts any secondary hart. */
static void spacemit_k3_pre_init(void)
{
unsigned long entry = (unsigned long)&_spacemit_k3_warm_start;
int i;
writel((u32)entry, (void *)(unsigned long)C0_RVBADDR_LO_ADDR);
writel((u32)(entry >> 32), (void *)(unsigned long)C0_RVBADDR_HI_ADDR);
writel((u32)entry, (void *)(unsigned long)C1_RVBADDR_LO_ADDR);
writel((u32)(entry >> 32), (void *)(unsigned long)C1_RVBADDR_HI_ADDR);
writel((u32)entry, (void *)(unsigned long)C2_RVBADDR_LO_ADDR);
writel((u32)(entry >> 32), (void *)(unsigned long)C2_RVBADDR_HI_ADDR);
writel((u32)entry, (void *)(unsigned long)C3_RVBADDR_LO_ADDR);
writel((u32)(entry >> 32), (void *)(unsigned long)C3_RVBADDR_HI_ADDR);
for (i = 0; i < array_size(cci_map); i++)
cci_enable_snoop_dvm_reqs(cci_map, i);
spacemit_k3_keep_boot_hart_powered();
}
static int spacemit_k3_early_init(bool cold_boot)
{
if (cold_boot)
spacemit_k3_pre_init();
return generic_early_init(cold_boot);
}
static int spacemit_k3_platform_init(const void *fdt, int nodeoff,
const struct fdt_match *match)
{
spacemit_k3_hart_init(current_hartid());
generic_platform_ops.early_init = spacemit_k3_early_init;
return 0;
}
static const struct fdt_match spacemit_k3_match[] = {
{ .compatible = "spacemit,k3" },
{ /* sentinel */ }
};
const struct fdt_driver spacemit_k3 = {
.match_table = spacemit_k3_match,
.init = spacemit_k3_platform_init,
};