drivers: add API for drivers early initialization

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
xuxingliang 2024-07-06 19:04:04 +08:00 committed by Xiang Xiao
parent b881868f19
commit bbc31d70f4
5 changed files with 98 additions and 25 deletions

View File

@ -53,6 +53,26 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: drivers_early_initialize
*
* Description:
* drivers_early_initialize will be called once before OS initialization
* when no system resource is ready to use.
*
* drivers_early_initialize serves the purpose of bringing up drivers as
* early as possible, so they can be used even during OS initialization.
* It must not rely on any system resources, such as heap memory.
*
****************************************************************************/
void drivers_early_initialize(void)
{
#ifdef CONFIG_DRIVERS_NOTE
note_early_initialize();
#endif
}
/****************************************************************************
* Name: drivers_initialize
*

View File

@ -35,6 +35,46 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: note_early_initialize
*
* Description:
* Registers note drivers early, without depending on system features
* such as heap memory.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero on success. A negated errno value is returned on a failure.
*
****************************************************************************/
int note_early_initialize(void)
{
int ret = 0;
#ifdef CONFIG_SEGGER_SYSVIEW
ret = note_sysview_initialize();
if (ret < 0)
{
serr("note_sysview_initialize failed %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_DRIVERS_NOTESNAP
ret = notesnap_register();
if (ret < 0)
{
serr("notesnap_register failed %d\n", ret);
return ret;
}
#endif
return ret;
}
/****************************************************************************
* Name: note_initialize
*
@ -46,7 +86,7 @@
* None.
*
* Returned Value:
* Zero on succress. A negated errno value is returned on a failure.
* Zero on success. A negated errno value is returned on a failure.
*
****************************************************************************/
@ -81,23 +121,5 @@ int note_initialize(void)
}
#endif
#ifdef CONFIG_SEGGER_SYSVIEW
ret = note_sysview_initialize();
if (ret < 0)
{
serr("note_sysview_initialize failed %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_DRIVERS_NOTESNAP
ret = notesnap_register();
if (ret < 0)
{
serr("notesnap_register failed %d\n", ret);
return ret;
}
#endif
return ret;
}

View File

@ -43,6 +43,17 @@ extern "C"
#define EXTERN extern
#endif
/****************************************************************************
* Name: drivers_early_initialize
*
* Description:
* Performs one-time, early driver initialization that doesn't rely on OS
* resources being ready.
*
****************************************************************************/
void drivers_early_initialize(void);
/****************************************************************************
* Name: drivers_initialize
*

View File

@ -112,6 +112,25 @@ struct note_driver_s
#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT)
#ifdef CONFIG_DRIVERS_NOTE
/****************************************************************************
* Name: note_early_initialize
*
* Description:
* Early register sched note related drivers that do not rely on system
* features like mm.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero on success. A negative errno value is returned on a failure.
*
****************************************************************************/
int note_early_initialize(void);
/****************************************************************************
* Name: note_initialize
*
@ -123,11 +142,10 @@ struct note_driver_s
* None.
*
* Returned Value:
* Zero on succress. A negated errno value is returned on a failure.
* Zero on success. A negative errno value is returned on a failure.
*
****************************************************************************/
#ifdef CONFIG_DRIVERS_NOTE
int note_initialize(void);
#endif

View File

@ -518,10 +518,6 @@ void nx_start(void)
g_nx_initstate = OSINIT_BOOT;
/* Initialize RTOS Data ***************************************************/
sched_trace_begin();
/* Initialize task list table *********************************************/
tasklist_initialize();
@ -534,6 +530,12 @@ void nx_start(void)
g_nx_initstate = OSINIT_TASKLISTS;
/* Initialize RTOS Data ***************************************************/
drivers_early_initialize();
sched_trace_begin();
/* Initialize RTOS facilities *********************************************/
/* Initialize the semaphore facility. This has to be done very early