1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BASE_STARTUP_INITLITE_STAGE_H
17 #define BASE_STARTUP_INITLITE_STAGE_H
18 
19 #include "init_sync.h"
20 #include <sys/ioctl.h>
21 #include <unistd.h>
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 typedef enum {
30     QS_STAGE1 = 1,   /* 1: start from stage1, 0 is already called in kernel process */
31     QS_STAGE2,       /* system init stage No 2 */
32     QS_STAGE3,       /* system init stage No 3 */
33     QS_STAGE_LIMIT
34 } QuickstartStage;
35 
36 typedef enum {
37     QS_NOTIFY = QS_STAGE_LIMIT,    /* quickstart notify */
38     QS_LISTEN,                     /* quickstart listen */
39     QS_CTL_LIMIT
40 } QuickstartConctrl;
41 
42 typedef struct {
43     unsigned int events;
44     unsigned int wait;
45 } QuickstartListenArgs;
46 
47 #define QUICKSTART_IOC_MAGIC    'T'
48 #define QUICKSTART_NOTIFY       _IO(QUICKSTART_IOC_MAGIC, QS_NOTIFY)
49 #define QUICKSTART_LISTEN       _IOR(QUICKSTART_IOC_MAGIC, QS_LISTEN, QuickstartListenArgs)
50 #define QUICKSTART_STAGE(x)     _IO(QUICKSTART_IOC_MAGIC, (x))
51 
52 #define QUICKSTART_NODE         "/dev/quickstart"
53 
54 /* Simple sample Usage:
55  *   INIT PROCESS
56  * SystemInitStage(QS_STAGE1)----(1)fork----> key APP
57  *      |(2)                                     |(3)
58  * InitListen<-------------------(4)---------- NotifyInit
59  *      |(5)
60  * SystemInitStage(QS_STAGE2)----(6)fork---------------------> other APP
61  *      |...
62  * InitStageFinished
63  */
64 
65 /*
66  * Listen the events of a specific pid process by Init process.
67  * Only be called by Init process.
68  * eventMask: There needs to be a consensus between the listener and the notifier.
69  */
70 extern int InitListen(unsigned long eventMask, unsigned int wait);
71 
72 /*
73  * Trigger the SystemInit stage.
74  * Only be called by Init process.
75  */
76 extern int SystemInitStage(QuickstartStage stage);
77 
78 /*
79  * InitStage finished.
80  * Only be called by Init process.
81  */
82 extern int InitStageFinished(void);
83 
84 /*
85  * Listen event and trigger the SystemInit stage.
86  * Only be called by Init process.
87  */
88 extern void TriggerStage(unsigned int event, unsigned int wait, QuickstartStage stagelevel);
89 #ifdef __cplusplus
90 #if __cplusplus
91 }
92 #endif
93 #endif
94 
95 #endif // BASE_STARTUP_INITLITE_STAGE_H
96