hm_liteipc.h 6.9 KB
Newer Older
1
/*
2 3
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
 *
 * 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 HM_LITEIPC_H
#define HM_LITEIPC_H

#include "sys/ioctl.h"
#include "los_config.h"
#include "los_task_pri.h"
#include "los_typedef.h"
#include "los_vm_map.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
46 47 48 49 50 51 52
/****************************************************
什么是句柄?
从形象意义的理解,跟门的把柄一样,握住门柄就控制了整个大门.
句柄是给用户程序使用的一个数字凭证,能以小博大,通过柄
能牵动内核模块工作.
****************************************************/
#define LITEIPC_DRIVER "/dev/lite_ipc"	//设备位置
53
#define LITEIPC_DRIVER_MODE 0644
54
#define MAX_SERVICE_NUM LOSCFG_BASE_CORE_TSK_LIMIT //最大服务数等于任务数 默认128
55 56
#define USE_TIMESTAMP YES

57 58 59 60
typedef enum { //句柄状态
    HANDLE_NOT_USED,	//未使用
    HANDLE_REGISTING,	//注册中
    HANDLE_REGISTED		//已注册
61 62 63 64
} HandleStatus;

typedef struct {//句柄信息
    HandleStatus status;	//状态
65
    UINT32       taskID;	//任务ID,以任务标识句柄
66 67 68
    UINTPTR      maxMsgSize;//最大消息大小
} HandleInfo;

69
typedef struct {// ipc池
70 71
    VOID   *uvaddr;	//虚拟地址,指向进程的LiteIPC线性区基地址
    VOID   *kvaddr;	//注意这里指的是物理地址
72
    UINT32 poolSize;//ipc池大小
73
} IpcPool;
74 75 76 77 78
//见于进程结构体:	LosProcessCB.ipcInfo
typedef struct {//进程IPC信息
    IpcPool pool;	//ipc池
    UINT32 ipcTaskID;	//
    UINT32 access[LOSCFG_BASE_CORE_TSK_LIMIT];	//访问的任务数组
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
} ProcIpcInfo;

typedef enum {
    OBJ_FD,
    OBJ_PTR,
    OBJ_SVC
} ObjType;

typedef struct {
    UINT32         buffSz;
    VOID           *buff;
} BuffPtr;

typedef struct {
    UINT32         handle;
    UINT32         token;
    UINT32         cookie;
} SvcIdentity;

typedef union {
    UINT32      fd;
    BuffPtr     ptr;
    SvcIdentity  svc;
} ObjContent;

typedef struct {
    ObjType     type;
    ObjContent  content;
} SpecialObj;

109 110 111 112 113
typedef enum {	//消息的类型
    MT_REQUEST,	//请求
    MT_REPLY,	//回复
    MT_FAILED_REPLY,//回复失败
    MT_DEATH_NOTIFY,//通知死亡
114 115 116
    MT_NUM
} MsgType;

117
/* lite ipc ioctl */// 控制命令
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
#define IPC_IOC_MAGIC       'i'
#define IPC_SET_CMS         _IO(IPC_IOC_MAGIC, 1)
#define IPC_CMS_CMD         _IOWR(IPC_IOC_MAGIC, 2, CmsCmdContent)
#define IPC_SET_IPC_THREAD  _IO(IPC_IOC_MAGIC, 3)
#define IPC_SEND_RECV_MSG   _IOWR(IPC_IOC_MAGIC, 4, IpcContent)

typedef enum {
    CMS_GEN_HANDLE,
    CMS_REMOVE_HANDLE,
    CMS_ADD_ACCESS
} CmsCmd;

typedef struct {
    CmsCmd        cmd;
    UINT32        taskID;
    UINT32        serviceHandle;
} CmsCmdContent;

typedef enum {
    LITEIPC_FLAG_DEFAULT = 0, // send and reply
    LITEIPC_FLAG_ONEWAY,      // send message only
} IpcFlag;

typedef struct {
142 143 144 145
    MsgType        type;       /**< cmd type, decide the data structure below*/	//命令类型,决定下面的数据结构
    SvcIdentity    target;    /**< serviceHandle or targetTaskId, depending on type */	//因命令类型不同而异
    UINT32         code;      /**< service function code */	//服务功能代码
    UINT32         flag;	//标签
146
#if (USE_TIMESTAMP == YES)
147
    UINT64         timestamp;	//时间戳
148
#endif
149 150 151 152 153 154 155 156 157
    UINT32         dataSz;    /**< size of data */ //消息内容大小
    VOID           *data;	//消息的内容,真正要传递的消息
    UINT32         spObjNum;	// ..
    VOID           *offsets;	// ..
    UINT32         processID; /**< filled by kernel, processId of sender/reciever */ //由内核填充,发送/接收消息的进程ID
    UINT32         taskID;    /**< filled by kernel, taskId of sender/reciever */	//由内核填充,发送/接收消息的任务ID
#ifdef LOSCFG_SECURITY_CAPABILITY	
    UINT32         userID;	//用户ID
    UINT32         gid;		//组ID
158 159 160
#endif
} IpcMsg;

161 162 163
typedef struct {	//IPC 内容节点
    IpcMsg         msg;	//内容体
    LOS_DL_LIST    listNode;//通过它挂到LosTaskCB.msgListHead链表上
164 165
} IpcListNode;

166 167
#define SEND (1 << 0)	//发送
#define RECV (1 << 1)	//接收
168
#define BUFF_FREE (1 << 2) //空闲状态
169

170 171 172 173
typedef struct {	//IPC消息内容回路,记录消息周期
    UINT32               flag;      /**< size of writeData */ //IPC标签 (SEND,RECV,BUFF_FREE)
    IpcMsg               *outMsg;   /**< data to send to target */ 	//发给给目标任务的消息内容
    IpcMsg               *inMsg;    /**< data reply by target */	//目标任务回复的消息内容
174 175 176 177
    VOID                 *buffToFree;
} IpcContent;

/* init liteipc driver */
178
extern UINT32 OsLiteIpcInit(VOID);
179 180 181 182 183 184 185 186

/* init process liteipc memory pool */
extern UINT32 LiteIpcPoolInit(ProcIpcInfo *ipcInfo);

/* reinit process liteipc memory pool, using in fork situation */
extern UINT32 LiteIpcPoolReInit(ProcIpcInfo *childIpcInfo, const ProcIpcInfo *parentIpcInfo);

/* delete process liteipc memory pool */
187
extern VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo, UINT32 processID);
188 189 190 191 192 193 194 195 196 197 198

/* remove service handle and send death notify */
extern VOID LiteIpcRemoveServiceHandle(LosTaskCB *taskCB);

#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif