kernel_liteos_a/kernel/common/los_config.c

326 lines
7.9 KiB
C
Raw Normal View History

2020-09-08 10:21:39 +08:00
/*
2021-03-11 18:43:57 +08:00
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
2020-09-08 10:21:39 +08:00
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_config.h"
#include "stdio.h"
#include "string.h"
#include "gic_common.h"
#include "los_atomic.h"
#include "los_exc_pri.h"
#include "los_hwi_pri.h"
#include "los_hw_tick_pri.h"
#include "los_init_pri.h"
2020-09-08 10:21:39 +08:00
#include "los_memory_pri.h"
#include "los_mp.h"
2020-09-08 10:21:39 +08:00
#include "los_mux_pri.h"
#include "los_printf.h"
#include "los_process_pri.h"
2020-09-08 10:21:39 +08:00
#include "los_queue_pri.h"
#include "los_sem_pri.h"
2020-09-08 10:21:39 +08:00
#include "los_spinlock.h"
#include "los_swtmr_pri.h"
#include "los_task_pri.h"
#include "los_tick.h"
2020-09-08 10:21:39 +08:00
#include "los_vm_boot.h"
2021-03-11 18:43:57 +08:00
STATIC SystemRebootFunc g_rebootHook = NULL;
VOID OsSetRebootHook(SystemRebootFunc func)
{
g_rebootHook = func;
}
2020-09-08 10:21:39 +08:00
2021-03-11 18:43:57 +08:00
SystemRebootFunc OsGetRebootHook(VOID)
{
2021-03-11 18:43:57 +08:00
return g_rebootHook;
}
2021-03-11 18:43:57 +08:00
extern UINT32 OsSystemInit(VOID);
extern VOID SystemInit(VOID);
#if (LOSCFG_KERNEL_SMP == 1)
extern VOID release_secondary_cores(VOID);
#endif
2021-03-11 18:43:57 +08:00
LITE_OS_SEC_TEXT_INIT STATIC UINT32 EarliestInit(VOID)
2020-09-08 10:21:39 +08:00
{
/* Must be placed at the beginning of the boot process */
OsSetMainTask();
OsCurrTaskSet(OsGetMainTask());
2020-09-08 10:21:39 +08:00
g_sysClock = OS_SYS_CLOCK;
g_tickPerSecond = LOSCFG_BASE_CORE_TICK_PER_SECOND;
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 ArchEarlyInit(VOID)
{
UINT32 ret = LOS_OK;
/* set system counter freq */
#ifndef LOSCFG_TEE_ENABLE
HalClockFreqWrite(OS_SYS_CLOCK);
#endif
#if (LOSCFG_PLATFORM_HWI == 1)
OsHwiInit();
#endif
OsExcInit();
ret = OsTickInit(g_sysClock, LOSCFG_BASE_CORE_TICK_PER_SECOND);
if (ret != LOS_OK) {
PRINT_ERR("OsTickInit error!\n");
return ret;
}
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 PlatformEarlyInit(VOID)
{
#if defined(LOSCFG_PLATFORM_UART_WITHOUT_VFS) && defined(LOSCFG_DRIVERS)
uart_init();
#endif /* LOSCFG_PLATFORM_UART_WITHOUT_VFS */
return LOS_OK;
2020-09-08 10:21:39 +08:00
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsIpcInit(VOID)
{
UINT32 ret;
#if (LOSCFG_BASE_IPC_SEM == 1)
2020-09-08 10:21:39 +08:00
ret = OsSemInit();
if (ret != LOS_OK) {
PRINT_ERR("OsSemInit error\n");
2020-09-08 10:21:39 +08:00
return ret;
}
#endif
#if (LOSCFG_BASE_IPC_QUEUE == 1)
2020-09-08 10:21:39 +08:00
ret = OsQueueInit();
if (ret != LOS_OK) {
PRINT_ERR("OsQueueInit error\n");
2020-09-08 10:21:39 +08:00
return ret;
}
#endif
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 ArchInit(VOID)
2020-09-08 10:21:39 +08:00
{
#ifdef LOSCFG_KERNEL_MMU
OsArchMmuInitPerCPU();
2020-09-08 10:21:39 +08:00
#endif
return LOS_OK;
}
2020-09-08 10:21:39 +08:00
LITE_OS_SEC_TEXT_INIT STATIC UINT32 PlatformInit(VOID)
2020-09-08 10:21:39 +08:00
{
return LOS_OK;
2020-09-08 10:21:39 +08:00
}
LITE_OS_SEC_TEXT_INIT STATIC UINT32 KModInit(VOID)
2020-09-08 10:21:39 +08:00
{
#if (LOSCFG_BASE_CORE_SWTMR == 1)
OsSwtmrInit();
#endif
2020-09-08 10:21:39 +08:00
return LOS_OK;
}
LITE_OS_SEC_TEXT_INIT VOID OsSystemInfo(VOID)
{
#ifdef LOSCFG_DEBUG_VERSION
const CHAR *buildType = "debug";
#else
const CHAR *buildType = "release";
#endif /* LOSCFG_DEBUG_VERSION */
PRINT_RELEASE("\n******************Welcome******************\n\n"
"Processor : %s"
#if (LOSCFG_KERNEL_SMP == 1)
" * %d\n"
"Run Mode : SMP\n"
#else
"\n"
"Run Mode : UP\n"
#endif
"GIC Rev : %s\n"
"build time : %s %s\n"
"Kernel : %s %d.%d.%d.%d/%s\n"
"\n*******************************************\n",
LOS_CpuInfo(),
#if (LOSCFG_KERNEL_SMP == 1)
LOSCFG_KERNEL_SMP_CORE_NUM,
#endif
HalIrqVersion(), __DATE__, __TIME__,\
KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE, buildType);
}
2020-09-08 10:21:39 +08:00
LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
{
UINT32 ret;
#ifdef LOS_INIT_STATISTICS
UINT64 startNsec, endNsec, durationUsec;
#endif
2020-09-08 10:21:39 +08:00
ret = EarliestInit();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_EARLIEST);
2020-09-08 10:21:39 +08:00
ret = ArchEarlyInit();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_ARCH_EARLY);
2020-09-08 10:21:39 +08:00
ret = PlatformEarlyInit();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_PLATFORM_EARLY);
2020-09-08 10:21:39 +08:00
/* system and chip info */
OsSystemInfo();
PRINT_RELEASE("\nmain core booting up...\n");
#ifdef LOS_INIT_STATISTICS
startNsec = LOS_CurrNanosec();
2020-09-08 10:21:39 +08:00
#endif
2020-09-08 10:21:39 +08:00
ret = OsTaskInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_KMOD_PREVM);
2020-09-08 10:21:39 +08:00
ret = OsSysMemInit();
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_VM_COMPLETE);
2020-09-08 10:21:39 +08:00
ret = OsIpcInit();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
2021-03-11 18:43:57 +08:00
ret = OsSystemProcessCreate();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
ret = ArchInit();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_ARCH);
2020-09-08 10:21:39 +08:00
ret = PlatformInit();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_PLATFORM);
2020-09-08 10:21:39 +08:00
ret = KModInit();
2020-09-08 10:21:39 +08:00
if (ret != LOS_OK) {
return ret;
}
OsInitCall(LOS_INIT_LEVEL_KMOD_BASIC);
2020-09-08 10:21:39 +08:00
OsInitCall(LOS_INIT_LEVEL_KMOD_EXTENDED);
2020-09-08 10:21:39 +08:00
#if (LOSCFG_KERNEL_SMP == 1)
release_secondary_cores();
#endif
OsInitCall(LOS_INIT_LEVEL_KMOD_TASK);
2020-09-08 10:21:39 +08:00
#ifdef LOS_INIT_STATISTICS
endNsec = LOS_CurrNanosec();
durationUsec = (endNsec - startNsec) / OS_SYS_NS_PER_US;
PRINTK("The main core takes %lluus to start.\n", durationUsec);
#endif
2020-09-08 10:21:39 +08:00
return LOS_OK;
}
#ifndef LOSCFG_PLATFORM_ADAPT
STATIC VOID SystemInit(VOID)
{
PRINTK("dummy: *** %s ***\n", __FUNCTION__);
}
#endif
2020-09-08 10:21:39 +08:00
STATIC UINT32 OsSystemInitTaskCreate(VOID)
{
UINT32 taskID;
TSK_INIT_PARAM_S sysTask;
(VOID)memset_s(&sysTask, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
#ifndef LOSCFG_ENABLE_KERNEL_TEST
2020-09-08 10:21:39 +08:00
sysTask.pfnTaskEntry = (TSK_ENTRY_FUNC)SystemInit;
#else
extern void TestSystemInit(void);
sysTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TestSystemInit;
#endif
2020-09-08 10:21:39 +08:00
sysTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
sysTask.pcName = "SystemInit";
sysTask.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
sysTask.uwResved = LOS_TASK_STATUS_DETACHED;
#if (LOSCFG_KERNEL_SMP == 1)
2020-09-08 10:21:39 +08:00
sysTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
return LOS_TaskCreate(&taskID, &sysTask);
}
2021-03-11 18:43:57 +08:00
2020-09-08 10:21:39 +08:00
UINT32 OsSystemInit(VOID)
{
UINT32 ret;
2020-09-08 10:21:39 +08:00
ret = OsSystemInitTaskCreate();
if (ret != LOS_OK) {
return ret;
}
return 0;
}
LOS_MODULE_INIT(OsSystemInit, LOS_INIT_LEVEL_KMOD_TASK);