mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-28 08:35:38 +00:00

SRAM2 is half L2 cache and default to SRAM after system boot. To enable the full l2 cache (512KB), it needs to reset A35 to make the change happen. So re-implement the jump entry function in SPL: 1. configure the core0 reset vector to entry (ATF) 2. enable the L2 full cache 3. reset A35 So when core0 up, it runs into ATF. And we have 512KB L2 cache working. Signed-off-by: Ye Li <ye.li@nxp.com> Signed-off-by: Peng Fan <peng.fan@nxp.com>
328 lines
6.9 KiB
C
328 lines
6.9 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright 2021 NXP
|
|
*/
|
|
|
|
#include <asm/io.h>
|
|
#include <asm/arch/clock.h>
|
|
#include <asm/arch/imx-regs.h>
|
|
#include <asm/arch/sys_proto.h>
|
|
#include <asm/armv8/mmu.h>
|
|
#include <asm/mach-imx/boot_mode.h>
|
|
#include <efi_loader.h>
|
|
#include <spl.h>
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
struct rom_api *g_rom_api = (struct rom_api *)0x1980;
|
|
|
|
u32 get_cpu_rev(void)
|
|
{
|
|
return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0;
|
|
}
|
|
|
|
enum bt_mode get_boot_mode(void)
|
|
{
|
|
u32 bt0_cfg = 0;
|
|
|
|
bt0_cfg = readl(CMC1_BASE_ADDR + 0xa0);
|
|
bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
|
|
|
|
if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
|
|
/* No low power boot */
|
|
if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
|
|
return DUAL_BOOT;
|
|
else
|
|
return SINGLE_BOOT;
|
|
}
|
|
|
|
return LOW_POWER_BOOT;
|
|
}
|
|
|
|
#define CMC_SRS_TAMPER BIT(31)
|
|
#define CMC_SRS_SECURITY BIT(30)
|
|
#define CMC_SRS_TZWDG BIT(29)
|
|
#define CMC_SRS_JTAG_RST BIT(28)
|
|
#define CMC_SRS_CORE1 BIT(16)
|
|
#define CMC_SRS_LOCKUP BIT(15)
|
|
#define CMC_SRS_SW BIT(14)
|
|
#define CMC_SRS_WDG BIT(13)
|
|
#define CMC_SRS_PIN_RESET BIT(8)
|
|
#define CMC_SRS_WARM BIT(4)
|
|
#define CMC_SRS_HVD BIT(3)
|
|
#define CMC_SRS_LVD BIT(2)
|
|
#define CMC_SRS_POR BIT(1)
|
|
#define CMC_SRS_WUP BIT(0)
|
|
|
|
static u32 reset_cause = -1;
|
|
|
|
static char *get_reset_cause(char *ret)
|
|
{
|
|
u32 cause1, cause = 0, srs = 0;
|
|
void __iomem *reg_ssrs = (void __iomem *)(CMC1_BASE_ADDR + 0x88);
|
|
void __iomem *reg_srs = (void __iomem *)(CMC1_BASE_ADDR + 0x80);
|
|
|
|
if (!ret)
|
|
return "null";
|
|
|
|
srs = readl(reg_srs);
|
|
cause1 = readl(reg_ssrs);
|
|
|
|
reset_cause = cause1;
|
|
|
|
cause = cause1 & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
|
|
|
|
switch (cause) {
|
|
case CMC_SRS_POR:
|
|
sprintf(ret, "%s", "POR");
|
|
break;
|
|
case CMC_SRS_WUP:
|
|
sprintf(ret, "%s", "WUP");
|
|
break;
|
|
case CMC_SRS_WARM:
|
|
cause = cause1 & (CMC_SRS_WDG | CMC_SRS_SW |
|
|
CMC_SRS_JTAG_RST);
|
|
switch (cause) {
|
|
case CMC_SRS_WDG:
|
|
sprintf(ret, "%s", "WARM-WDG");
|
|
break;
|
|
case CMC_SRS_SW:
|
|
sprintf(ret, "%s", "WARM-SW");
|
|
break;
|
|
case CMC_SRS_JTAG_RST:
|
|
sprintf(ret, "%s", "WARM-JTAG");
|
|
break;
|
|
default:
|
|
sprintf(ret, "%s", "WARM-UNKN");
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
sprintf(ret, "%s-%X", "UNKN", cause1);
|
|
break;
|
|
}
|
|
|
|
debug("[%X] SRS[%X] %X - ", cause1, srs, srs ^ cause1);
|
|
return ret;
|
|
}
|
|
|
|
#if defined(CONFIG_DISPLAY_CPUINFO)
|
|
const char *get_imx_type(u32 imxtype)
|
|
{
|
|
return "8ULP";
|
|
}
|
|
|
|
int print_cpuinfo(void)
|
|
{
|
|
u32 cpurev;
|
|
char cause[18];
|
|
|
|
cpurev = get_cpu_rev();
|
|
|
|
printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
|
|
get_imx_type((cpurev & 0xFF000) >> 12),
|
|
(cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
|
|
mxc_get_clock(MXC_ARM_CLK) / 1000000);
|
|
|
|
printf("Reset cause: %s\n", get_reset_cause(cause));
|
|
|
|
printf("Boot mode: ");
|
|
switch (get_boot_mode()) {
|
|
case LOW_POWER_BOOT:
|
|
printf("Low power boot\n");
|
|
break;
|
|
case DUAL_BOOT:
|
|
printf("Dual boot\n");
|
|
break;
|
|
case SINGLE_BOOT:
|
|
default:
|
|
printf("Single boot\n");
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
void init_wdog(void)
|
|
{
|
|
/* TODO */
|
|
}
|
|
|
|
static struct mm_region imx8ulp_arm64_mem_map[] = {
|
|
{
|
|
/* ROM */
|
|
.virt = 0x0,
|
|
.phys = 0x0,
|
|
.size = 0x40000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
PTE_BLOCK_OUTER_SHARE
|
|
},
|
|
{
|
|
/* FLEXSPI0 */
|
|
.virt = 0x04000000,
|
|
.phys = 0x04000000,
|
|
.size = 0x08000000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
PTE_BLOCK_NON_SHARE |
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
},
|
|
{
|
|
/* SSRAM (align with 2M) */
|
|
.virt = 0x1FE00000UL,
|
|
.phys = 0x1FE00000UL,
|
|
.size = 0x400000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
PTE_BLOCK_OUTER_SHARE |
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
}, {
|
|
/* SRAM1 (align with 2M) */
|
|
.virt = 0x21000000UL,
|
|
.phys = 0x21000000UL,
|
|
.size = 0x200000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
PTE_BLOCK_OUTER_SHARE |
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
}, {
|
|
/* SRAM0 (align with 2M) */
|
|
.virt = 0x22000000UL,
|
|
.phys = 0x22000000UL,
|
|
.size = 0x200000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
PTE_BLOCK_OUTER_SHARE |
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
}, {
|
|
/* Peripherals */
|
|
.virt = 0x27000000UL,
|
|
.phys = 0x27000000UL,
|
|
.size = 0x3000000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
PTE_BLOCK_NON_SHARE |
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
}, {
|
|
/* Peripherals */
|
|
.virt = 0x2D000000UL,
|
|
.phys = 0x2D000000UL,
|
|
.size = 0x1600000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
PTE_BLOCK_NON_SHARE |
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
}, {
|
|
/* FLEXSPI1-2 */
|
|
.virt = 0x40000000UL,
|
|
.phys = 0x40000000UL,
|
|
.size = 0x40000000UL,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
PTE_BLOCK_NON_SHARE |
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
}, {
|
|
/* DRAM1 */
|
|
.virt = 0x80000000UL,
|
|
.phys = 0x80000000UL,
|
|
.size = PHYS_SDRAM_SIZE,
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
PTE_BLOCK_OUTER_SHARE
|
|
}, {
|
|
/*
|
|
* empty entrie to split table entry 5
|
|
* if needed when TEEs are used
|
|
*/
|
|
0,
|
|
}, {
|
|
/* List terminator */
|
|
0,
|
|
}
|
|
};
|
|
|
|
struct mm_region *mem_map = imx8ulp_arm64_mem_map;
|
|
|
|
/* simplify the page table size to enhance boot speed */
|
|
#define MAX_PTE_ENTRIES 512
|
|
#define MAX_MEM_MAP_REGIONS 16
|
|
u64 get_page_table_size(void)
|
|
{
|
|
u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64);
|
|
u64 size = 0;
|
|
|
|
/*
|
|
* For each memory region, the max table size:
|
|
* 2 level 3 tables + 2 level 2 tables + 1 level 1 table
|
|
*/
|
|
size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt;
|
|
|
|
/*
|
|
* We need to duplicate our page table once to have an emergency pt to
|
|
* resort to when splitting page tables later on
|
|
*/
|
|
size *= 2;
|
|
|
|
/*
|
|
* We may need to split page tables later on if dcache settings change,
|
|
* so reserve up to 4 (random pick) page tables for that.
|
|
*/
|
|
size += one_pt * 4;
|
|
|
|
return size;
|
|
}
|
|
|
|
void enable_caches(void)
|
|
{
|
|
/* TODO: add TEE memmap region */
|
|
|
|
icache_enable();
|
|
dcache_enable();
|
|
}
|
|
|
|
int dram_init(void)
|
|
{
|
|
gd->ram_size = PHYS_SDRAM_SIZE;
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_SERIAL_TAG
|
|
void get_board_serial(struct tag_serialnr *serialnr)
|
|
{
|
|
/* TODO */
|
|
}
|
|
#endif
|
|
|
|
int arch_cpu_init(void)
|
|
{
|
|
if (IS_ENABLED(CONFIG_SPL_BUILD))
|
|
clock_init();
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if defined(CONFIG_SPL_BUILD)
|
|
__weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
|
|
{
|
|
debug("image entry point: 0x%lx\n", spl_image->entry_point);
|
|
|
|
/* Update SIM1 DGO8 for reset vector base */
|
|
writel((u32)spl_image->entry_point, SIM1_BASE_ADDR + 0x5c);
|
|
|
|
/* set update bit */
|
|
setbits_le32(SIM1_BASE_ADDR + 0x8, 0x1 << 24);
|
|
|
|
/* polling the ack */
|
|
while ((readl(SIM1_BASE_ADDR + 0x8) & (0x1 << 26)) == 0)
|
|
;
|
|
|
|
/* clear the update */
|
|
clrbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 24));
|
|
|
|
/* clear the ack by set 1 */
|
|
setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26));
|
|
|
|
/* Enable the 512KB cache */
|
|
setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 4));
|
|
|
|
/* reset core */
|
|
setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 16));
|
|
|
|
while (1)
|
|
;
|
|
}
|
|
#endif
|