xref: /OK3568_Linux_fs/external/mpp/mpp/inc/mpp_cfg.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2020 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __MPP_CFG_H__
18 #define __MPP_CFG_H__
19 
20 #include "rk_type.h"
21 #include "mpp_err.h"
22 
23 typedef enum CfgType_e {
24     CFG_FUNC_TYPE_S32,
25     CFG_FUNC_TYPE_U32,
26     CFG_FUNC_TYPE_S64,
27     CFG_FUNC_TYPE_U64,
28     CFG_FUNC_TYPE_St,
29     CFG_FUNC_TYPE_Ptr,
30     CFG_FUNC_TYPE_BUTT,
31 } CfgType;
32 
33 typedef struct MppCfgApi_t {
34     const char          *name;
35     CfgType             data_type;
36     RK_U32              flag_offset;
37     RK_U32              flag_value;
38     RK_U32              data_offset;
39     RK_S32              data_size;
40 } MppCfgApi;
41 
42 typedef struct MppCfgInfo_t {
43     /* size for the whole node including name */
44     RK_S32          node_size;
45     RK_U32          name_len;
46     /* CfgType */
47     RK_S32          data_type;
48     /* update flag info 32bit */
49     RK_S32          flag_offset;
50     RK_U32          flag_value;
51     /* data access info */
52     RK_S32          data_offset;
53     RK_S32          data_size;
54     /* linked next node offset for pointer type */
55     RK_S32          node_next;
56     /* function pointer for get / put accessor (user filled) */
57     RK_U64          set_func;
58     RK_U64          get_func;
59     /* reserve for extension */
60     RK_U64          stuff[2];
61     char            name[];
62 } MppCfgInfoNode;
63 
64 typedef MPP_RET (*CfgSetS32)(MppCfgInfoNode *info, void *cfg, RK_S32 val);
65 typedef MPP_RET (*CfgGetS32)(MppCfgInfoNode *info, void *cfg, RK_S32 *val);
66 typedef MPP_RET (*CfgSetU32)(MppCfgInfoNode *info, void *cfg, RK_U32 val);
67 typedef MPP_RET (*CfgGetU32)(MppCfgInfoNode *info, void *cfg, RK_U32 *val);
68 typedef MPP_RET (*CfgSetS64)(MppCfgInfoNode *info, void *cfg, RK_S64 val);
69 typedef MPP_RET (*CfgGetS64)(MppCfgInfoNode *info, void *cfg, RK_S64 *val);
70 typedef MPP_RET (*CfgSetU64)(MppCfgInfoNode *info, void *cfg, RK_U64 val);
71 typedef MPP_RET (*CfgGetU64)(MppCfgInfoNode *info, void *cfg, RK_U64 *val);
72 typedef MPP_RET (*CfgSetSt) (MppCfgInfoNode *info, void *cfg, void *val);
73 typedef MPP_RET (*CfgGetSt) (MppCfgInfoNode *info, void *cfg, void *val);
74 typedef MPP_RET (*CfgSetPtr)(MppCfgInfoNode *info, void *cfg, void *val);
75 typedef MPP_RET (*CfgGetPtr)(MppCfgInfoNode *info, void *cfg, void **val);
76 
77 #define MPP_CFG_SET_S32(info, cfg, val) (mpp_cfg_ops.fp_SetS32)(info, cfg, val)
78 #define MPP_CFG_GET_S32(info, cfg, val) (mpp_cfg_ops.fp_GetS32)(info, cfg, (RK_S32 *)(val))
79 #define MPP_CFG_SET_U32(info, cfg, val) (mpp_cfg_ops.fp_SetU32)(info, cfg, val)
80 #define MPP_CFG_GET_U32(info, cfg, val) (mpp_cfg_ops.fp_GetU32)(info, cfg, (RK_U32 *)(val))
81 #define MPP_CFG_SET_S64(info, cfg, val) (mpp_cfg_ops.fp_SetS64)(info, cfg, val)
82 #define MPP_CFG_GET_S64(info, cfg, val) (mpp_cfg_ops.fp_GetS64)(info, cfg, (RK_S64 *)(val))
83 #define MPP_CFG_SET_U64(info, cfg, val) (mpp_cfg_ops.fp_SetU64)(info, cfg, val)
84 #define MPP_CFG_GET_U64(info, cfg, val) (mpp_cfg_ops.fp_GetU64)(info, cfg, (RK_U64 *)(val))
85 #define MPP_CFG_SET_St(info, cfg, val)  (mpp_cfg_ops.fp_SetSt )(info, cfg, val)
86 #define MPP_CFG_GET_St(info, cfg, val)  (mpp_cfg_ops.fp_GetSt )(info, cfg, (void *)(val))
87 #define MPP_CFG_SET_Ptr(info, cfg, val) (mpp_cfg_ops.fp_SetPtr)(info, cfg, val)
88 #define MPP_CFG_GET_Ptr(info, cfg, val) (mpp_cfg_ops.fp_GetPtr)(info, cfg, (void **)(val))
89 
90 /* header size 128 byte */
91 typedef struct MppCfgInfoHead_t {
92     char            version[112];
93     RK_S32          info_size;
94     RK_S32          info_count;
95     RK_S32          node_count;
96     RK_S32          cfg_size;
97 } MppCfgInfoHead;
98 
99 typedef struct MppCfgOps_t {
100     CfgSetS32       fp_SetS32;
101     CfgGetS32       fp_GetS32;
102     CfgSetU32       fp_SetU32;
103     CfgGetU32       fp_GetU32;
104     CfgSetS64       fp_SetS64;
105     CfgGetS64       fp_GetS64;
106     CfgSetU64       fp_SetU64;
107     CfgGetU64       fp_GetU64;
108     CfgSetSt        fp_SetSt;
109     CfgGetSt        fp_GetSt;
110     CfgSetPtr       fp_SetPtr;
111     CfgGetPtr       fp_GetPtr;
112 } MppCfgOps;
113 
114 #ifdef  __cplusplus
115 extern "C" {
116 #endif
117 
118 extern const char *cfg_type_names[];
119 
120 extern MppCfgOps mpp_cfg_ops;
121 MPP_RET mpp_cfg_node_fixup_func(MppCfgInfoNode *node);
122 
123 #define CHECK_CFG_INFO(node, name, type) \
124     check_cfg_info(node, name, type, __FUNCTION__)
125 
126 MPP_RET check_cfg_info(MppCfgInfoNode *node, const char *name, CfgType type,
127                        const char *func);
128 
129 #ifdef  __cplusplus
130 }
131 #endif
132 
133 #endif /*__MPP_CFG_H__*/
134