feat: Add /dev/quickstart to support synchronous communication between processes in user mode startup.

Add /dev/quickstart to support synchronous communication between processes in user mode startup.
Support ioctl cmd:
 QUICKSTART_LISTEN,QUICKSTART_STAGE1,QUICKSTART_STAGE2,QUICKSTART_STAGE3,QUICKSTART_UNREGISTER only for init process;
 QUICKSTART_NOTIFY for other app process.

Close #I3OHO5

Change-Id: If6a56123be93a5bc6b6d1069abda8d872b15fae1
This commit is contained in:
boxi 2021-04-28 08:59:17 +08:00
parent 7e698f4b22
commit 46b63f7153
7 changed files with 90 additions and 87 deletions

View File

@ -303,6 +303,7 @@ source "../../kernel/liteos_a/bsd/dev/usb/Kconfig"
source "../../drivers/adapter/khdf/liteos/Kconfig"
source "drivers/char/mem/Kconfig"
source "drivers/char/quickstart/Kconfig"
source "drivers/char/random/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
source "drivers/char/video/Kconfig"

View File

@ -0,0 +1,6 @@
config DRIVERS_QUICKSTART
bool "Enable QUICKSTART"
default y
depends on DRIVERS && FS_VFS
help
Answer Y to enable LiteOS support quickstart frame dev.

View File

@ -33,6 +33,7 @@
#define __LOS_QUICK_START_H__
#include "los_typedef.h"
#include "sys/ioctl.h"
#ifdef __cplusplus
#if __cplusplus
@ -40,7 +41,41 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern int DevQuickStartRegister(void);
typedef enum {
QS_STAGE1 = 1, /* 1: start from stage1, 0 is already called in kernel process */
QS_STAGE2, /* system init stage No 2 */
QS_STAGE3, /* system init stage No 3 */
QS_STAGE_LIMIT
} QS_STAGE;
typedef enum {
QS_UNREGISTER = QS_STAGE_LIMIT, /* quickstart dev unregister */
QS_NOTIFY, /* quickstart notify */
QS_LISTEN, /* quickstart listen */
QS_CTL_LIMIT
} QS_CTL;
#define QS_STAGE_CNT (QS_STAGE_LIMIT - QS_STAGE1)
#define QS_STAGE_NO(x) QS_STAGE##x
#define QUICKSTART_IOC_MAGIC 'T'
#define QUICKSTART_UNREGISTER _IO(QUICKSTART_IOC_MAGIC, QS_UNREGISTER)
#define QUICKSTART_NOTIFY _IO(QUICKSTART_IOC_MAGIC, QS_NOTIFY)
#define QUICKSTART_LISTEN _IO(QUICKSTART_IOC_MAGIC, QS_LISTEN)
#define QUICKSTART_STAGE(x) _IO(QUICKSTART_IOC_MAGIC, QS_STAGE_NO(x))
#define QUICKSTART_NODE "/dev/quickstart"
typedef void (*SysteminitHook)(void);
typedef struct {
SysteminitHook func[QS_STAGE_CNT];
} LosSysteminitHook;
extern void QuickStartHookRegister(LosSysteminitHook hooks);
extern int QuickStartDevRegister(void);
#ifdef __cplusplus
#if __cplusplus

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* 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.
*/
#ifndef __LOS_QUICK_START_PRI_H__
#define __LOS_QUICK_START_PRI_H__
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
unsigned int OsSystemInitStep2(void);
extern VOID SystemInit2(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __LOS_QUICK_START_PRI_H__ */

View File

@ -29,16 +29,15 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_quick_start_pri.h"
#include "bits/ioctl.h"
#include "los_dev_quickstart.h"
#include "fcntl.h"
#include "linux/kernel.h"
#include "los_process_pri.h"
#define QUICKSTART_IOC_MAGIC 'T'
#define QUICKSTART_INITSTEP2 _IO(QUICKSTART_IOC_MAGIC, 0)
#define QUICKSTART_UNREGISTER _IO(QUICKSTART_IOC_MAGIC, 1)
#define QUICKSTART_NODE "/dev/quickstart"
EVENT_CB_S g_qsEvent;
static SysteminitHook g_systemInitFunc[QS_STAGE_CNT] = {0};
static char g_callOnce[QS_STAGE_CNT] = {0};
static int QuickstartOpen(struct file *filep)
{
@ -50,18 +49,30 @@ static int QuickstartClose(struct file *filep)
return 0;
}
static void SystemInitStep2(void)
static void QuickstartNotify(unsigned int events)
{
static int once = 0;
/* Only one call is allowed */
if (once != 0) {
return;
}
once = 1;
LOS_EventWrite((PEVENT_CB_S)&g_qsEvent, events);
}
unsigned int ret = OsSystemInitStep2();
if (ret != LOS_OK) {
PRINT_ERR("systemInitStep2 failed\n");
static void QuickstartListen(unsigned int eventMask)
{
LOS_EventRead((PEVENT_CB_S)&g_qsEvent, eventMask, LOS_WAITMODE_AND | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
}
void QuickStartHookRegister(LosSysteminitHook hooks)
{
for (int i = 0; i < QS_STAGE_CNT; i++) {
g_systemInitFunc[i] = hooks.func[i];
}
}
static void QuickStartStageWorking(unsigned int level)
{
if ((level < QS_STAGE_CNT) && (g_callOnce[level] == 0) && (g_systemInitFunc[level] != NULL)) {
g_callOnce[level] = 1; /* 1: Already called */
g_systemInitFunc[level]();
} else {
PRINT_WARN("Trigger quickstart,but doing nothing!!\n");
}
}
@ -72,15 +83,27 @@ static int QuickstartDevUnregister(void)
static ssize_t QuickstartIoctl(struct file *filep, int cmd, unsigned long arg)
{
if (cmd == QUICKSTART_NOTIFY) {
QuickstartNotify(arg);
return 0;
}
if (OsGetUserInitProcessID() != LOS_GetCurrProcessID()) {
PRINT_ERR("Permission denios!\n");
return -1;
}
switch (cmd) {
case QUICKSTART_INITSTEP2:
SystemInitStep2();
break;
case QUICKSTART_UNREGISTER:
QuickstartDevUnregister();
break;
case QUICKSTART_LISTEN:
QuickstartListen(arg);
break;
default:
QuickStartStageWorking(cmd - QUICKSTART_STAGE(1)); /* ioctl cmd converted to stage level */
break;
}
return 0;
@ -100,8 +123,9 @@ static const struct file_operations_vfs g_quickstartDevOps = {
NULL, /* unlink */
};
int DevQuickStartRegister(void)
int QuickStartDevRegister(void)
{
LOS_EventInit(&g_qsEvent);
return register_driver(QUICKSTART_NODE, &g_quickstartDevOps, 0666, 0); /* 0666: file mode */
}

View File

@ -117,10 +117,6 @@
#include "los_hilog.h"
#endif
#ifdef LOSCFG_QUICK_START
#include "los_quick_start_pri.h"
#endif
STATIC SystemRebootFunc g_rebootHook = NULL;
@ -388,13 +384,6 @@ STATIC UINT32 OsSystemInitTaskCreate(VOID)
return LOS_TaskCreate(&taskID, &sysTask);
}
#ifdef LOSCFG_QUICK_START
UINT32 OsSystemInitStep2(VOID)
{
SystemInit2();
return 0;
}
#endif
UINT32 OsSystemInit(VOID)
{

View File

@ -398,10 +398,10 @@ ifeq ($(LOSCFG_DRIVERS_MEM), y)
LITEOS_DEV_MEM_INCLUDE = -I $(LITEOSTOPDIR)/drivers/char/mem/include
endif
ifeq ($(LOSCFG_QUICK_START), y)
ifeq ($(LOSCFG_DRIVERS_QUICKSTART), y)
LITEOS_BASELIB += -lquickstart
LIB_SUBDIRS += $(LITEOSTOPDIR)/drivers/char/quickstart
LITEOS_QUICK_START_INCLUDE = -I $(LITEOSTOPDIR)/drivers/char/quickstart/include
LITEOS_DEV_QUICKSTART_INCLUDE = -I $(LITEOSTOPDIR)/drivers/char/quickstart/include
endif
ifeq ($(LOSCFG_DRIVERS_RANDOM), y)
@ -642,7 +642,7 @@ LITEOS_DRIVERS_INCLUDE := $(LITEOS_CELLWISE_INCLUDE) $(LITEOS_GPIO_INCLUDE
$(LITEOS_REGULATOR_INCLUDE) $(LITEOS_VIDEO_INCLUDE) \
$(LITEOS_DRIVERS_HDF_INCLUDE) $(LITEOS_TZDRIVER_INCLUDE) \
$(LITEOS_HIEVENT_INCLUDE) $(LITEOS_DEV_MEM_INCLUDE) \
$(LITEOS_QUICK_START_INCLUDE)
$(LITEOS_DEV_QUICKSTART_INCLUDE)
LITEOS_DFX_INCLUDE := $(LITEOS_HILOG_INCLUDE)
LITEOS_SECURITY_INCLUDE := $(LITEOS_SECURITY_CAP_INC) $(LITEOS_SECURITY_VID_INC)