Skip to content

Commit

Permalink
uboot/k230/cpu: disable maee/pmp for boot_baremetal
Browse files Browse the repository at this point in the history
This patch provides RISC-V standard M-mode env for boot_baremetal
command users. It doesn't affect K230 SDK boot behaviors.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed Jan 28, 2024
1 parent 2ec0dd4 commit a1818ab
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions src/little/uboot/arch/riscv/cpu/k230/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,38 @@
#include <linux/delay.h>
#include "platform.h"

static inline void improving_cpu_performance(void)
static void improving_cpu_performance(bool maee)
{
/* Set cpu regs */
csr_write(CSR_MCOR, 0x70013);
csr_write(CSR_MCCR2, 0xe0000009);
csr_write(CSR_MHCR, 0x11ff); //Enable L1 Cache
csr_write(CSR_MXSTATUS, 0x638000);
csr_write(CSR_MXSTATUS, maee?0x638000:0x438000);
csr_write(CSR_MHINT, 0x6e30c);

csr_write(CSR_SMPEN, 0x1);
}

static void enforce_pmp(void)
{
//start addr:0x24484c00<<2=0x91213000 len=1<<9 * 8 = 4KB
csr_write(pmpaddr0, 0x24484dff);
//start addr:0x24485000<<2=0x91214000 len=1<<9 * 8 = 4KB
csr_write(pmpaddr1, 0x244851ff);
// lock them as readonly
csr_write(pmpcfg0, 0x9999);
}

static void idle_wait(void){
while(1) {
asm volatile("wfi");
}
}

/*
* cleanup_before_linux() is called just before we call linux
* it prepares the processor for linux
* it prepares the processor with MAEE on and PMP set
*
* we disable interrupt and caches.
*/
int cleanup_before_linux(void)
{
Expand All @@ -65,11 +80,24 @@ int cleanup_before_linux(void)
// csi_l2cache_flush_invalid();
asm volatile(".long 0x0170000b\n":::"memory");

improving_cpu_performance();
improving_cpu_performance(true); /* MAEE on */

enforce_pmp();
return 0;
}

/*
* cleanup_std_riscv() prepares CPU with MAEE off and PMP open
*/
void cleanup_std_riscv(void)
{
cache_flush();
icache_disable();
dcache_disable();
asm volatile(".long 0x0170000b\n":::"memory");
improving_cpu_performance(false); /* MAEE off */
}

void harts_early_init(void)
{
/*enable mtimer clk*/
Expand All @@ -79,11 +107,7 @@ void harts_early_init(void)

writel(0x80199805, (void*)0x91100004);

csr_write(pmpaddr0, 0x24484dff);//start addr:0x24484c00<<2=0x91213000 len=1<<9 * 8 = 4KB
csr_write(pmpaddr1, 0x244851ff);//start addr:0x24485000<<2=0x91214000 len=1<<9 * 8 = 4KB
csr_write(pmpcfg0, 0x9999);

//improving_cpu_performance();
/* defer PMP until booting linux */
}
u32 spl_boot_device(void)
{
Expand Down Expand Up @@ -114,9 +138,11 @@ static int k230_boot_baremetal(struct cmd_tbl *cmdtp, int flag, int argc,
writel(0x10001,(void*)0x9110100c);
udelay(100);
writel(0x10000,(void*)0x9110100c);
idle_wait();
}
else
{
cleanup_std_riscv();
func_app_entry app_entry = (void *)(long)boot_address;
app_entry();
}
Expand Down

0 comments on commit a1818ab

Please sign in to comment.