• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef HM_LITEIPC_H
33 #define HM_LITEIPC_H
34 
35 #include "sys/ioctl.h"
36 #include "los_config.h"
37 #include "los_typedef.h"
38 #include "los_vm_map.h"
39 
40 #ifdef __cplusplus
41 #if __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44 #endif /* __cplusplus */
45 
46 #define LITEIPC_DRIVER "/dev/lite_ipc"
47 #define LITEIPC_DRIVER_MODE 0644
48 #define MAX_SERVICE_NUM LOSCFG_BASE_CORE_TSK_LIMIT
49 #define USE_TIMESTAMP 1
50 
51 typedef enum {
52     HANDLE_NOT_USED,
53     HANDLE_REGISTING,
54     HANDLE_REGISTED
55 } HandleStatus;
56 
57 typedef struct {
58     HandleStatus status;
59     UINT32       taskID;
60     UINTPTR      maxMsgSize;
61 } HandleInfo;
62 
63 typedef struct {
64     VOID   *uvaddr;
65     VOID   *kvaddr;
66     UINT32 poolSize;
67 } IpcPool;
68 
69 typedef struct {
70     IpcPool pool;
71     UINT32 ipcTaskID;
72     LOS_DL_LIST ipcUsedNodelist;
73     UINT32 access[LOSCFG_BASE_CORE_TSK_LIMIT];
74 } ProcIpcInfo;
75 
76 typedef struct {
77     LOS_DL_LIST     msgListHead;
78     BOOL            accessMap[LOSCFG_BASE_CORE_TSK_LIMIT];
79 } IpcTaskInfo;
80 
81 typedef enum {
82     OBJ_FD,
83     OBJ_PTR,
84     OBJ_SVC
85 } ObjType;
86 
87 typedef struct {
88     UINT32         buffSz;
89     VOID           *buff;
90 } BuffPtr;
91 
92 typedef struct {
93     UINT32         handle;
94     UINT32         token;
95     UINT32         cookie;
96 } SvcIdentity;
97 
98 typedef union {
99     UINT32      fd;
100     BuffPtr     ptr;
101     SvcIdentity  svc;
102 } ObjContent;
103 
104 typedef struct {
105     ObjType     type;
106     ObjContent  content;
107 } SpecialObj;
108 
109 typedef enum {
110     MT_REQUEST,
111     MT_REPLY,
112     MT_FAILED_REPLY,
113     MT_DEATH_NOTIFY,
114     MT_NUM
115 } MsgType;
116 
117 /* lite ipc ioctl */
118 #define IPC_IOC_MAGIC       'i'
119 #define IPC_SET_CMS         _IO(IPC_IOC_MAGIC, 1)
120 #define IPC_CMS_CMD         _IOWR(IPC_IOC_MAGIC, 2, CmsCmdContent)
121 #define IPC_SET_IPC_THREAD  _IO(IPC_IOC_MAGIC, 3)
122 #define IPC_SEND_RECV_MSG   _IOWR(IPC_IOC_MAGIC, 4, IpcContent)
123 
124 typedef enum {
125     CMS_GEN_HANDLE,
126     CMS_REMOVE_HANDLE,
127     CMS_ADD_ACCESS
128 } CmsCmd;
129 
130 typedef struct {
131     CmsCmd        cmd;
132     UINT32        taskID;
133     UINT32        serviceHandle;
134 } CmsCmdContent;
135 
136 typedef enum {
137     LITEIPC_FLAG_DEFAULT = 0, // send and reply
138     LITEIPC_FLAG_ONEWAY,      // send message only
139 } IpcFlag;
140 
141 typedef struct {
142     MsgType        type;       /**< cmd type, decide the data structure below*/
143     SvcIdentity    target;    /**< serviceHandle or targetTaskId, depending on type */
144     UINT32         code;      /**< service function code */
145     UINT32         flag;
146 #if (USE_TIMESTAMP == 1)
147     UINT64         timestamp;
148 #endif
149     UINT32         dataSz;    /**< size of data */
150     VOID           *data;
151     UINT32         spObjNum;
152     VOID           *offsets;
153     UINT32         processID; /**< filled by kernel, processId of sender/receiver */
154     UINT32         taskID;    /**< filled by kernel, taskId of sender/receiver */
155 #ifdef LOSCFG_SECURITY_CAPABILITY
156     UINT32         userID;
157     UINT32         gid;
158 #endif
159 } IpcMsg;
160 
161 typedef struct {
162     IpcMsg         msg;
163     LOS_DL_LIST    listNode;
164 } IpcListNode;
165 
166 #define SEND (1 << 0)
167 #define RECV (1 << 1)
168 #define BUFF_FREE (1 << 2)
169 
170 typedef struct {
171     UINT32               flag;      /**< size of writeData */
172     IpcMsg               *outMsg;   /**< data to send to target */
173     IpcMsg               *inMsg;    /**< data reply by target */
174     VOID                 *buffToFree;
175 } IpcContent;
176 
177 /* init liteipc driver */
178 extern UINT32 OsLiteIpcInit(VOID);
179 
180 /* reinit process liteipc memory pool, using in fork situation */
181 extern ProcIpcInfo *LiteIpcPoolReInit(const ProcIpcInfo *parentIpcInfo);
182 
183 /* remove service handle and send death notify */
184 extern VOID LiteIpcRemoveServiceHandle(UINT32 taskID);
185 
186 extern UINT32 LiteIpcPoolDestroy(UINT32 processID);
187 
188 #ifdef __cplusplus
189 #if __cplusplus
190 }
191 #endif /* __cplusplus */
192 #endif /* __cplusplus */
193 
194 #endif
195