2022-11-10 22:22:48 +08:00
|
|
|
/*
|
2023-05-11 10:25:21 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2022-11-10 22:22:48 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Email: opensource_embedded@phytium.com.cn
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2022-10-26 huanghe first commit
|
|
|
|
* 2022-10-26 zhugengyu support aarch64
|
2023-08-02 13:27:09 +08:00
|
|
|
* 2023-07-26 huanghe update psci uage
|
2022-11-10 22:22:48 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include "board.h"
|
|
|
|
#include <gicv3.h>
|
|
|
|
#include "rtconfig.h"
|
|
|
|
#include "phytium_cpu.h"
|
|
|
|
|
|
|
|
#if defined(TARGET_ARMV8_AARCH64)
|
|
|
|
#include "cpuport.h"
|
|
|
|
#include "gtimer.h"
|
|
|
|
#include "mmu.h"
|
2023-05-11 10:25:21 +08:00
|
|
|
#include "cp15.h"
|
2022-11-10 22:22:48 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RT_USING_SMP
|
|
|
|
#include <interrupt.h>
|
2024-06-16 15:42:37 +08:00
|
|
|
#include "phytium_interrupt.h"
|
2022-11-10 22:22:48 +08:00
|
|
|
|
|
|
|
#if defined(TARGET_ARMV8_AARCH64)
|
|
|
|
#include "psci.h"
|
2023-05-11 10:25:21 +08:00
|
|
|
extern void _secondary_cpu_entry(void);
|
|
|
|
#else
|
|
|
|
extern void rt_secondary_cpu_entry(void);
|
2022-11-10 22:22:48 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fpsci.h"
|
|
|
|
|
|
|
|
rt_uint64_t rt_cpu_mpidr_early[] =
|
|
|
|
{
|
2024-04-11 00:09:17 +08:00
|
|
|
|
2022-11-10 22:22:48 +08:00
|
|
|
#if defined(TARGET_E2000D)
|
|
|
|
[0] = 0x80000200,
|
|
|
|
[1] = 0x80000201,
|
2023-08-29 10:27:54 +08:00
|
|
|
#elif defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
|
2024-07-22 10:33:39 +08:00
|
|
|
[0] = 0x80000200,
|
|
|
|
[1] = 0x80000201,
|
|
|
|
[2] = 0x80000000,
|
|
|
|
[3] = 0x80000100,
|
2022-11-10 22:22:48 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int rt_hw_timer_init(void);
|
2023-11-21 17:42:23 +08:00
|
|
|
|
2022-11-10 22:22:48 +08:00
|
|
|
void rt_hw_secondary_cpu_up(void)
|
|
|
|
{
|
|
|
|
rt_uint32_t i;
|
|
|
|
rt_uint32_t cpu_mask = 0;
|
2023-05-11 10:25:21 +08:00
|
|
|
int cpu_id;
|
|
|
|
cpu_id = rt_hw_cpu_id();
|
2022-11-10 22:22:48 +08:00
|
|
|
rt_kprintf("rt_hw_secondary_cpu_up is processing \r\n");
|
2023-11-21 17:42:23 +08:00
|
|
|
for (i = 0; i < RT_CPUS_NR; i++)
|
2022-11-10 22:22:48 +08:00
|
|
|
{
|
2023-11-21 17:42:23 +08:00
|
|
|
if (i == cpu_id)
|
2023-05-11 10:25:21 +08:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2024-04-11 00:09:17 +08:00
|
|
|
cpu_mask = 1<<phytium_cpu_id_mapping(i);
|
2022-11-10 22:22:48 +08:00
|
|
|
|
|
|
|
#if defined(TARGET_ARMV8_AARCH64)
|
2023-05-11 10:25:21 +08:00
|
|
|
/* code */
|
2023-08-02 13:27:09 +08:00
|
|
|
rt_kprintf("cpu_mask = 0x%x \n", cpu_mask);
|
2023-05-11 10:25:21 +08:00
|
|
|
char *entry = (char *)_secondary_cpu_entry;
|
|
|
|
entry += PV_OFFSET;
|
2023-08-02 13:27:09 +08:00
|
|
|
FPsciCpuMaskOn(cpu_mask, (uintptr)entry);
|
2022-11-10 22:22:48 +08:00
|
|
|
__DSB();
|
|
|
|
#else
|
2023-11-21 17:42:23 +08:00
|
|
|
/* code */
|
2024-03-02 16:06:07 +08:00
|
|
|
char *entry = (char *)rt_secondary_cpu_entry;
|
|
|
|
entry += PV_OFFSET;
|
|
|
|
FPsciCpuMaskOn(cpu_mask, (uintptr)entry);
|
2022-11-10 22:22:48 +08:00
|
|
|
__asm__ volatile("dsb" ::: "memory");
|
|
|
|
#endif
|
2023-05-11 10:25:21 +08:00
|
|
|
|
2022-11-10 22:22:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-02 16:06:07 +08:00
|
|
|
/**
|
|
|
|
* This function will initialize board
|
|
|
|
*/
|
|
|
|
extern size_t MMUTable[];
|
|
|
|
|
2023-05-11 10:25:21 +08:00
|
|
|
void rt_hw_secondary_cpu_bsp_start(void)
|
2022-11-10 22:22:48 +08:00
|
|
|
{
|
2023-05-11 10:25:21 +08:00
|
|
|
/* spin lock init */
|
|
|
|
rt_hw_spin_lock(&_cpus_lock);
|
|
|
|
|
2022-11-10 22:22:48 +08:00
|
|
|
/* mmu init */
|
|
|
|
#if defined(TARGET_ARMV8_AARCH64)
|
2023-05-11 10:25:21 +08:00
|
|
|
extern unsigned long MMUTable[];
|
|
|
|
rt_hw_mmu_ktbl_set((unsigned long)MMUTable);
|
2024-03-02 16:06:07 +08:00
|
|
|
#else
|
|
|
|
rt_uint32_t mmutable_p;
|
|
|
|
mmutable_p = (rt_uint32_t)MMUTable + (rt_uint32_t)PV_OFFSET ;
|
2024-07-22 10:33:39 +08:00
|
|
|
rt_hw_mmu_switch((void*)mmutable_p) ;
|
2022-11-10 22:22:48 +08:00
|
|
|
#endif
|
2023-05-11 10:25:21 +08:00
|
|
|
|
|
|
|
/* vector init */
|
|
|
|
rt_hw_vector_init();
|
2024-07-22 10:33:39 +08:00
|
|
|
|
2022-11-10 22:22:48 +08:00
|
|
|
/* interrupt init */
|
|
|
|
#if defined(TARGET_ARMV8_AARCH64)
|
2023-05-11 10:25:21 +08:00
|
|
|
arm_gic_cpu_init(0, 0);
|
2024-07-22 10:33:39 +08:00
|
|
|
arm_gic_redist_address_set(0, platform_get_gic_redist_base(), rt_hw_cpu_id());
|
2024-04-11 00:09:17 +08:00
|
|
|
phytium_aarch64_arm_gic_redist_init();
|
2022-11-10 22:22:48 +08:00
|
|
|
#else
|
|
|
|
arm_gic_cpu_init(0);
|
2024-07-22 10:33:39 +08:00
|
|
|
arm_gic_redist_address_set(0, platform_get_gic_redist_base(), rt_hw_cpu_id());
|
2022-11-10 22:22:48 +08:00
|
|
|
arm_gic_redist_init(0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* gtimer init */
|
|
|
|
#if defined(TARGET_ARMV8_AARCH64)
|
2023-05-11 10:25:21 +08:00
|
|
|
rt_hw_gtimer_init();
|
2022-11-10 22:22:48 +08:00
|
|
|
#else
|
|
|
|
rt_hw_timer_init();
|
|
|
|
#endif
|
|
|
|
rt_hw_interrupt_umask(RT_SCHEDULE_IPI);
|
|
|
|
|
|
|
|
/* start scheduler */
|
|
|
|
rt_kprintf("\rcall cpu %d on success\n", rt_hw_cpu_id());
|
|
|
|
rt_hw_secondary_cpu_idle_exec();
|
|
|
|
rt_system_scheduler_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_secondary_cpu_idle_exec(void)
|
|
|
|
{
|
|
|
|
#if defined(TARGET_ARMV8_AARCH64)
|
|
|
|
__WFE();
|
|
|
|
#else
|
|
|
|
asm volatile("wfe" ::
|
|
|
|
: "memory", "cc");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|