xref: /OK3568_Linux_fs/external/rockit/mpi/sdk/include/rk_comm_mb.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* GPL-2.0 WITH Linux-syscall-note OR Apache 2.0 */
2 /* Copyright (c) 2021 Fuzhou Rockchip Electronics Co., Ltd */
3 
4 #ifndef INCLUDE_RT_MPI_RK_COMM_MB_H_
5 #define INCLUDE_RT_MPI_RK_COMM_MB_H_
6 
7 #include "rk_type.h"
8 #include "rk_errno.h"
9 
10 #ifdef __cplusplus
11 #if __cplusplus
12 extern "C" {
13 #endif
14 #endif
15 
16 typedef enum rkMB_UID_E {
17     MB_UID_VI = 0,
18     MB_UID_VO = 1,
19     MB_UID_VGS = 2,
20     MB_UID_VENC = 3,
21     MB_UID_VDEC = 4,
22     MB_UID_VPSS = 5,
23     MB_UID_AI = 6,
24     MB_UID_AENC = 7,
25     MB_UID_ADEC = 8,
26     MB_UID_AVS = 9,
27     MB_UID_BUTT = 10
28 } MB_UID_E;
29 
30 #define MB_INVALID_POOLID              (-1U)
31 #define MB_INVALID_HANDLE              NULL
32 
33 #define MB_MAX_COMM_POOLS              16
34 #define MB_MAX_MOD_COMM_POOLS          16
35 
36 #define MB_MAX_COUNT                   10240
37 
38 /* Generall common pool use this owner id, module common pool use VB_UID as owner id */
39 #define POOL_OWNER_COMMON              -1
40 
41 /* Private pool use this owner id */
42 #define POOL_OWNER_PRIVATE             -2
43 
44 typedef RK_U32 MB_POOL;
45 typedef void * MB_BLK;
46 
47 typedef enum rkMB_BUF_SYNC_TYPE_E {
48     MB_BUF_SYNC_TYPE_READ = 0,
49     MB_BUF_SYNC_TYPE_WRITE,
50     MB_BUF_SYNC_TYPE_RW,
51 } MB_BUF_SYNC_TYPE_E;
52 
53 typedef enum rkMB_ALLOC_TYPE {
54     MB_ALLOC_TYPE_UNUSED = -1,
55     MB_ALLOC_TYPE_DMA = 0,
56     MB_ALLOC_TYPE_MALLOC,
57     MB_ALLOC_TYPE_MAX,
58 } MB_ALLOC_TYPE_E;
59 
60 typedef enum rkMB_REMAP_MODE_E {
61     MB_REMAP_MODE_NONE = 0, /* no remap */
62     MB_REMAP_MODE_NOCACHE = 1 << 8, /* no cache remap */
63     MB_REMAP_MODE_CACHED = 1 << 9,  /* cache remap, if you use this mode, you should flush cache by yourself */
64     MB_REMAP_MODE_BUTT
65 } MB_REMAP_MODE_E;
66 
67 typedef enum rkMB_DMA_TYPE_E {
68     MB_DMA_TYPE_NONE = 0,       /* Physically Non-Continuous memory default */
69     MB_DMA_TYPE_CMA = 1 << 12,  /* Physically Continuous memory */
70     MB_DMA_TYPE_BUTT
71 } MB_DMA_TYPE_E;
72 
73 typedef struct rkMB_POOL_CONFIG_S {
74     RK_U64 u64MBSize;
75     RK_U32 u32MBCnt;
76     MB_REMAP_MODE_E enRemapMode;
77     MB_ALLOC_TYPE_E enAllocType;
78     MB_DMA_TYPE_E enDmaType;
79     RK_BOOL bPreAlloc;
80 } MB_POOL_CONFIG_S;
81 
82 typedef struct rkMB_CONFIG_S {
83     RK_U32 u32MaxPoolCnt;
84     MB_POOL_CONFIG_S astCommPool[MB_MAX_COMM_POOLS];
85 } MB_CONFIG_S;
86 
87 typedef RK_S32 (*RK_MPI_MB_FREE_CB)(void *);
88 
89 typedef struct _rkMB_EXT_CONFIG_S {
90     RK_U8              *pu8VirAddr;
91     RK_U64              u64PhyAddr;
92     RK_S32              s32Fd;
93     RK_U64              u64Size;
94     RK_MPI_MB_FREE_CB   pFreeCB;
95     RK_VOID            *pOpaque;
96 } MB_EXT_CONFIG_S;
97 
98 #define RK_ERR_MB_NULL_PTR             RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_NULL_PTR)
99 #define RK_ERR_MB_NOMEM                RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_NOMEM)
100 #define RK_ERR_MB_NOBUF                RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_NOBUF)
101 #define RK_ERR_MB_UNEXIST              RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_UNEXIST)
102 #define RK_ERR_MB_ILLEGAL_PARAM        RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_ILLEGAL_PARAM)
103 #define RK_ERR_MB_NOTREADY             RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_NOTREADY)
104 #define RK_ERR_MB_BUSY                 RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_BUSY)
105 #define RK_ERR_MB_NOT_PERM             RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_NOT_PERM)
106 #define RK_ERR_MB_SIZE_NOT_ENOUGH      RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_SIZE_NOT_ENOUGH)
107 
108 #define RK_ERR_MB_2MPOOLS              RK_DEF_ERR(RK_ID_MB, RK_ERR_LEVEL_ERROR, RK_ERR_BUTT + 1)
109 
110 #ifdef __cplusplus
111 #if __cplusplus
112 }
113 #endif
114 #endif /* __cplusplus */
115 
116 #endif /* INCLUDE_RT_MPI_RK_COMM_MB_H_ */
117 
118