• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2023 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_PROCESS_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 typedef struct {
118     int32_t driverVersion;
119 } IpcVersion;
120 
121 /* lite ipc ioctl */
122 #define IPC_IOC_MAGIC       'i'
123 #define IPC_SET_CMS         _IO(IPC_IOC_MAGIC, 1)
124 #define IPC_CMS_CMD         _IOWR(IPC_IOC_MAGIC, 2, CmsCmdContent)
125 #define IPC_SET_IPC_THREAD  _IO(IPC_IOC_MAGIC, 3)
126 #define IPC_SEND_RECV_MSG   _IOWR(IPC_IOC_MAGIC, 4, IpcContent)
127 #define IPC_GET_VERSION     _IOR(IPC_IOC_MAGIC, 5, IpcVersion)
128 
129 typedef enum {
130     CMS_GEN_HANDLE,
131     CMS_REMOVE_HANDLE,
132     CMS_ADD_ACCESS
133 } CmsCmd;
134 
135 typedef struct {
136     CmsCmd        cmd;
137     UINT32        taskID;
138     UINT32        serviceHandle;
139 } CmsCmdContent;
140 
141 typedef enum {
142     LITEIPC_FLAG_DEFAULT = 0, // send and reply
143     LITEIPC_FLAG_ONEWAY,      // send message only
144 } IpcFlag;
145 
146 typedef struct {
147     MsgType        type;       /**< cmd type, decide the data structure below*/
148     SvcIdentity    target;    /**< serviceHandle or targetTaskId, depending on type */
149     UINT32         code;      /**< service function code */
150     UINT32         flag;
151 #if (USE_TIMESTAMP == 1)
152     UINT64         timestamp;
153 #endif
154     UINT32         dataSz;    /**< size of data */
155     VOID           *data;
156     UINT32         spObjNum;
157     VOID           *offsets;
158     UINT32         processID; /**< filled by kernel, processId of sender/receiver */
159     UINT32         taskID;    /**< filled by kernel, taskId of sender/receiver */
160 #ifdef LOSCFG_SECURITY_CAPABILITY
161     UINT32         userID;
162     UINT32         gid;
163 #endif
164 } IpcMsg;
165 
166 typedef struct {
167     IpcMsg         msg;
168     LOS_DL_LIST    listNode;
169 } IpcListNode;
170 
171 #define SEND (1 << 0)
172 #define RECV (1 << 1)
173 #define BUFF_FREE (1 << 2)
174 
175 typedef struct {
176     UINT32               flag;      /**< size of writeData */
177     IpcMsg               *outMsg;   /**< data to send to target */
178     IpcMsg               *inMsg;    /**< data reply by target */
179     VOID                 *buffToFree;
180 } IpcContent;
181 
182 /* init liteipc driver */
183 extern UINT32 OsLiteIpcInit(VOID);
184 
185 /* reinit process liteipc memory pool, using in fork situation */
186 extern ProcIpcInfo *LiteIpcPoolReInit(const ProcIpcInfo *parentIpcInfo);
187 
188 /* remove service handle and send death notify */
189 extern VOID LiteIpcRemoveServiceHandle(UINT32 taskID);
190 
191 extern UINT32 LiteIpcPoolDestroy(UINT32 processID);
192 
193 #ifdef __cplusplus
194 #if __cplusplus
195 }
196 #endif /* __cplusplus */
197 #endif /* __cplusplus */
198 
199 #endif
200