xref: /openbmc/u-boot/arch/arm/cpu/armv8/s32v234/cpu.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
29702ec00SEddy Petrișor /*
39702ec00SEddy Petrișor  * (C) Copyright 2014-2016, Freescale Semiconductor, Inc.
49702ec00SEddy Petrișor  */
59702ec00SEddy Petrișor 
69702ec00SEddy Petrișor #include <common.h>
79702ec00SEddy Petrișor #include <asm/io.h>
89702ec00SEddy Petrișor #include <asm/system.h>
99702ec00SEddy Petrișor #include <asm/armv8/mmu.h>
109702ec00SEddy Petrișor #include <asm/io.h>
119702ec00SEddy Petrișor #include <asm/arch/mc_me_regs.h>
129702ec00SEddy Petrișor #include "cpu.h"
139702ec00SEddy Petrișor 
cpu_mask(void)149702ec00SEddy Petrișor u32 cpu_mask(void)
159702ec00SEddy Petrișor {
169702ec00SEddy Petrișor 	return readl(MC_ME_CS);
179702ec00SEddy Petrișor }
189702ec00SEddy Petrișor 
199702ec00SEddy Petrișor #ifndef CONFIG_SYS_DCACHE_OFF
209702ec00SEddy Petrișor 
219702ec00SEddy Petrișor #define S32V234_IRAM_BASE        0x3e800000UL
229702ec00SEddy Petrișor #define S32V234_IRAM_SIZE        0x800000UL
239702ec00SEddy Petrișor #define S32V234_DRAM_BASE1       0x80000000UL
249702ec00SEddy Petrișor #define S32V234_DRAM_SIZE1       0x40000000UL
259702ec00SEddy Petrișor #define S32V234_DRAM_BASE2       0xC0000000UL
269702ec00SEddy Petrișor #define S32V234_DRAM_SIZE2       0x20000000UL
279702ec00SEddy Petrișor #define S32V234_PERIPH_BASE      0x40000000UL
289702ec00SEddy Petrișor #define S32V234_PERIPH_SIZE      0x40000000UL
299702ec00SEddy Petrișor 
309702ec00SEddy Petrișor static struct mm_region s32v234_mem_map[] = {
319702ec00SEddy Petrișor 	{
32cd4b0c5fSYork Sun 		.virt = S32V234_IRAM_BASE,
33cd4b0c5fSYork Sun 		.phys = S32V234_IRAM_BASE,
349702ec00SEddy Petrișor 		.size = S32V234_IRAM_SIZE,
359702ec00SEddy Petrișor 		.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
369702ec00SEddy Petrișor 			 PTE_BLOCK_OUTER_SHARE
379702ec00SEddy Petrișor 	}, {
38cd4b0c5fSYork Sun 		.virt = S32V234_DRAM_BASE1,
39cd4b0c5fSYork Sun 		.phys = S32V234_DRAM_BASE1,
409702ec00SEddy Petrișor 		.size = S32V234_DRAM_SIZE1,
419702ec00SEddy Petrișor 		.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
429702ec00SEddy Petrișor 			 PTE_BLOCK_OUTER_SHARE
439702ec00SEddy Petrișor 	}, {
44cd4b0c5fSYork Sun 		.virt = S32V234_PERIPH_BASE,
45cd4b0c5fSYork Sun 		.phys = S32V234_PERIPH_BASE,
469702ec00SEddy Petrișor 		.size = S32V234_PERIPH_SIZE,
479702ec00SEddy Petrișor 		.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
489702ec00SEddy Petrișor 			 PTE_BLOCK_NON_SHARE
499702ec00SEddy Petrișor 			 /* TODO: Do we need these? */
509702ec00SEddy Petrișor 			 /* | PTE_BLOCK_PXN | PTE_BLOCK_UXN */
519702ec00SEddy Petrișor 	}, {
52cd4b0c5fSYork Sun 		.virt = S32V234_DRAM_BASE2,
53cd4b0c5fSYork Sun 		.phys = S32V234_DRAM_BASE2,
549702ec00SEddy Petrișor 		.size = S32V234_DRAM_SIZE2,
559702ec00SEddy Petrișor 		.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) |
569702ec00SEddy Petrișor 			 PTE_BLOCK_OUTER_SHARE
579702ec00SEddy Petrișor 	}, {
589702ec00SEddy Petrișor 		/* List terminator */
599702ec00SEddy Petrișor 		0,
609702ec00SEddy Petrișor 	}
619702ec00SEddy Petrișor };
629702ec00SEddy Petrișor 
639702ec00SEddy Petrișor struct mm_region *mem_map = s32v234_mem_map;
649702ec00SEddy Petrișor 
659702ec00SEddy Petrișor #endif
669702ec00SEddy Petrișor 
679702ec00SEddy Petrișor /*
689702ec00SEddy Petrișor  * Return the number of cores on this SOC.
699702ec00SEddy Petrișor  */
cpu_numcores(void)709702ec00SEddy Petrișor int cpu_numcores(void)
719702ec00SEddy Petrișor {
729702ec00SEddy Petrișor 	int numcores;
739702ec00SEddy Petrișor 	u32 mask;
749702ec00SEddy Petrișor 
759702ec00SEddy Petrișor 	mask = cpu_mask();
769702ec00SEddy Petrișor 	numcores = hweight32(cpu_mask());
779702ec00SEddy Petrișor 
789702ec00SEddy Petrișor 	/* Verify if M4 is deactivated */
799702ec00SEddy Petrișor 	if (mask & 0x1)
809702ec00SEddy Petrișor 		numcores--;
819702ec00SEddy Petrișor 
829702ec00SEddy Petrișor 	return numcores;
839702ec00SEddy Petrișor }
849702ec00SEddy Petrișor 
859702ec00SEddy Petrișor #if defined(CONFIG_ARCH_EARLY_INIT_R)
arch_early_init_r(void)869702ec00SEddy Petrișor int arch_early_init_r(void)
879702ec00SEddy Petrișor {
889702ec00SEddy Petrișor 	int rv;
899702ec00SEddy Petrișor 	asm volatile ("dsb sy");
909702ec00SEddy Petrișor 	rv = fsl_s32v234_wake_seconday_cores();
919702ec00SEddy Petrișor 
929702ec00SEddy Petrișor 	if (rv)
939702ec00SEddy Petrișor 		printf("Did not wake secondary cores\n");
949702ec00SEddy Petrișor 
959702ec00SEddy Petrișor 	asm volatile ("sev");
969702ec00SEddy Petrișor 	return 0;
979702ec00SEddy Petrișor }
989702ec00SEddy Petrișor #endif /* CONFIG_ARCH_EARLY_INIT_R */
99