mirror of
https://github.com/nyanmisaka/mpp.git
synced 2026-01-23 23:50:38 +01:00
feat[kmpp_obj]: Add ioctl related macro
1. Add ioctl ctx / in / out / in_out macro. 2. Add get objdef function. Signed-off-by: Herman Chen <herman.chen@rock-chips.com> Change-Id: I350a673a2302341388a68e3019299b04cce39203
This commit is contained in:
parent
eed8ec347f
commit
1c3881cbac
3 changed files with 169 additions and 4 deletions
|
|
@ -21,7 +21,8 @@
|
|||
rk_s32 CONCAT_US(prefix, get)(KMPP_OBJ_INTF_TYPE *p); \
|
||||
rk_s32 CONCAT_US(prefix, assign)(KMPP_OBJ_INTF_TYPE *p, void *buf, rk_s32 size); \
|
||||
rk_s32 CONCAT_US(prefix, put)(KMPP_OBJ_INTF_TYPE p); \
|
||||
rk_s32 CONCAT_US(prefix, dump)(KMPP_OBJ_INTF_TYPE p, const char *caller);
|
||||
rk_s32 CONCAT_US(prefix, dump)(KMPP_OBJ_INTF_TYPE p, const char *caller); \
|
||||
KmppObjDef CONCAT_US(prefix, objdef)(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -55,9 +56,17 @@ KMPP_OBJ_FUNC_DEFINE(KMPP_OBJ_NAME)
|
|||
|
||||
#define ALIAS_DECLARE(prefix, ftype, type, name, flag, ...)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
KMPP_OBJ_ENTRY_TABLE(KMPP_OBJ_NAME, ENTRY_DECLARE, STRCT_DECLARE,
|
||||
ENTRY_DECLARE, STRCT_DECLARE, ALIAS_DECLARE)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef ENTRY_DECLARE
|
||||
#undef ENTRY_TO_ALIAS
|
||||
#undef STRCT_DECLARE
|
||||
|
|
@ -67,8 +76,40 @@ KMPP_OBJ_ENTRY_TABLE(KMPP_OBJ_NAME, ENTRY_DECLARE, STRCT_DECLARE,
|
|||
#undef STRUCT_START
|
||||
#undef STRUCT_END
|
||||
|
||||
#endif /* KMPP_OBJ_ENTRY_TABLE */
|
||||
|
||||
#ifdef KMPP_OBJ_FUNC_IOCTL
|
||||
|
||||
#define IOCTL_CTX(prefix, func, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx);
|
||||
|
||||
#define IOCTL_IN_(prefix, func, in_type, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx, in_type in);
|
||||
|
||||
#define IOCTL_OUT(prefix, func, out_type, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx, out_type out);
|
||||
|
||||
#define IOCTL_IO_(prefix, func, in_type, out_type, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx, in_type in, out_type out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
KMPP_OBJ_FUNC_IOCTL(KMPP_OBJ_NAME, IOCTL_CTX, IOCTL_IN_, IOCTL_OUT, IOCTL_IO_)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef IOCTL_CTX
|
||||
#undef IOCTL_IN_
|
||||
#undef IOCTL_OUT
|
||||
#undef IOCTL_IO_
|
||||
|
||||
#endif /* KMPP_OBJ_FUNC_IOCTL */
|
||||
|
||||
#undef KMPP_OBJ_NAME
|
||||
#undef KMPP_OBJ_INTF_TYPE
|
||||
#undef KMPP_OBJ_ENTRY_TABLE
|
||||
#undef KMPP_OBJ_FUNC_IOCTL
|
||||
|
|
|
|||
|
|
@ -301,9 +301,6 @@ static void CONCAT_US(KMPP_OBJ_NAME, register)(void)
|
|||
#if defined(KMPP_OBJ_FUNC_DEINIT)
|
||||
kmpp_objdef_add_deinit(KMPP_OBJ_DEF(KMPP_OBJ_NAME), KMPP_OBJ_FUNC_DEINIT);
|
||||
#endif
|
||||
#if defined(KMPP_OBJ_FUNC_IOCTL)
|
||||
kmpp_objdef_add_ioctl(KMPP_OBJ_DEF(KMPP_OBJ_NAME), &KMPP_OBJ_FUNC_IOCTL);
|
||||
#endif
|
||||
#if defined(KMPP_OBJ_FUNC_DUMP)
|
||||
kmpp_objdef_add_dump(KMPP_OBJ_DEF(KMPP_OBJ_NAME), KMPP_OBJ_FUNC_DUMP);
|
||||
#endif
|
||||
|
|
@ -347,6 +344,11 @@ rk_s32 CONCAT_US(KMPP_OBJ_NAME, dump)(KMPP_OBJ_INTF_TYPE obj, const char *caller
|
|||
return kmpp_obj_is_kobj(obj) ? kmpp_obj_kdump_f(obj, caller) : kmpp_obj_udump_f(obj, caller);
|
||||
}
|
||||
|
||||
KmppObjDef CONCAT_US(KMPP_OBJ_NAME, objdef)(void)
|
||||
{
|
||||
return KMPP_OBJ_DEF(KMPP_OBJ_NAME);
|
||||
}
|
||||
|
||||
#if !defined(KMPP_OBJ_FUNC_EXPORT_DISABLE) && defined(__KERNEL__)
|
||||
#include <linux/export.h>
|
||||
|
||||
|
|
@ -393,6 +395,114 @@ KMPP_OBJ_ENTRY_TABLE(KMPP_OBJ_NAME, KMPP_OBJ_EXPORT, KMPP_OBJ_EXPORT,
|
|||
#undef STRUCT_START
|
||||
#undef STRUCT_END
|
||||
|
||||
/* kmpp_obj ioctl function */
|
||||
#ifdef KMPP_OBJ_FUNC_IOCTL
|
||||
|
||||
#define IOCTL_CTX(prefix, func, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx) \
|
||||
{ \
|
||||
static rk_s32 old_cmd = GET_ARG0(-1, __VA_ARGS__); \
|
||||
static rk_s32 cmd = -1; \
|
||||
static rk_s32 once = 1; \
|
||||
KmppObjDef def = KMPP_OBJ_DEF(KMPP_OBJ_NAME); \
|
||||
if (!def) { \
|
||||
mpp_loge_f(TO_STR(KMPP_OBJ_NAME) " can not be found for ioctl\n"); \
|
||||
return rk_nok; \
|
||||
} \
|
||||
/* legacy compatible */ \
|
||||
if (old_cmd >= 0) \
|
||||
return kmpp_obj_ioctl(ctx, old_cmd, ctx, NULL, __FUNCTION__); \
|
||||
if (cmd < 0) { \
|
||||
cmd = kmpp_objdef_get_cmd(def, TO_STR(func)); \
|
||||
if (cmd < 0) { \
|
||||
mpp_loge_cf(once, TO_STR(KMPP_OBJ_NAME) " ioctl cmd %s not supported\n", TO_STR(func)); \
|
||||
once = 0; \
|
||||
return rk_nok; \
|
||||
} \
|
||||
} \
|
||||
return kmpp_obj_ioctl(ctx, cmd, NULL, NULL, __FUNCTION__); \
|
||||
}
|
||||
|
||||
#define IOCTL_IN_(prefix, func, in_type, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx, in_type in) \
|
||||
{ \
|
||||
KmppObjDef def = KMPP_OBJ_DEF(KMPP_OBJ_NAME); \
|
||||
static rk_s32 cmd = GET_ARG0(-1, __VA_ARGS__); \
|
||||
static rk_s32 once = 1; \
|
||||
if (!def) { \
|
||||
mpp_loge_f(TO_STR(KMPP_OBJ_NAME) " can not be found for ioctl\n"); \
|
||||
return rk_nok; \
|
||||
} \
|
||||
if (cmd < 0) { \
|
||||
cmd = kmpp_objdef_get_cmd(def, TO_STR(func)); \
|
||||
if (cmd < 0) { \
|
||||
mpp_loge_cf(once, TO_STR(KMPP_OBJ_NAME) " ioctl cmd %s not supported\n", TO_STR(func)); \
|
||||
once = 0; \
|
||||
return rk_nok; \
|
||||
} \
|
||||
} \
|
||||
return kmpp_obj_ioctl(ctx, cmd, in, NULL, __FUNCTION__); \
|
||||
}
|
||||
|
||||
#define IOCTL_OUT(prefix, name, out_type, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx, out_type out) \
|
||||
{ \
|
||||
KmppObjDef def = KMPP_OBJ_DEF(KMPP_OBJ_NAME); \
|
||||
static rk_s32 cmd = GET_ARG0(-1, __VA_ARGS__); \
|
||||
static rk_s32 once = 1; \
|
||||
if (!def) { \
|
||||
mpp_loge_f(TO_STR(KMPP_OBJ_NAME) " can not be found for ioctl\n"); \
|
||||
return rk_nok; \
|
||||
} \
|
||||
if (cmd < 0) { \
|
||||
cmd = kmpp_objdef_get_cmd(def, TO_STR(func)); \
|
||||
if (cmd < 0) { \
|
||||
mpp_loge_cf(once, TO_STR(KMPP_OBJ_NAME) " ioctl cmd %s not supported\n", TO_STR(func)); \
|
||||
once = 0; \
|
||||
return rk_nok; \
|
||||
} \
|
||||
} \
|
||||
return kmpp_obj_ioctl(ctx, cmd, NULL, out, __FUNCTION__); \
|
||||
}
|
||||
|
||||
#define IOCTL_IO_(prefix, name, in_type, out_type, ...) \
|
||||
rk_s32 CONCAT_US(prefix, func)(KMPP_OBJ_INTF_TYPE ctx, in_type in, out_type out) \
|
||||
{ \
|
||||
KmppObjDef def = KMPP_OBJ_DEF(KMPP_OBJ_NAME); \
|
||||
static rk_s32 cmd = GET_ARG0(-1, __VA_ARGS__); \
|
||||
static rk_s32 once = 1; \
|
||||
if (!def) { \
|
||||
mpp_loge_f(TO_STR(KMPP_OBJ_NAME) " can not be found for ioctl\n"); \
|
||||
return rk_nok; \
|
||||
} \
|
||||
if (cmd < 0) { \
|
||||
cmd = kmpp_objdef_get_cmd(def, TO_STR(func)); \
|
||||
if (cmd < 0) { \
|
||||
mpp_loge_cf(once, TO_STR(KMPP_OBJ_NAME) " ioctl cmd %s not supported\n", TO_STR(func)); \
|
||||
once = 0; \
|
||||
return rk_nok; \
|
||||
} \
|
||||
} \
|
||||
return kmpp_obj_ioctl(ctx, cmd, in, out, __FUNCTION__); \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
KMPP_OBJ_FUNC_IOCTL(KMPP_OBJ_NAME, IOCTL_CTX, IOCTL_IN_, IOCTL_OUT, IOCTL_IO_)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef IOCTL_CTX
|
||||
#undef IOCTL_IN_
|
||||
#undef IOCTL_OUT
|
||||
#undef IOCTL_IO_
|
||||
|
||||
#endif /* KMPP_OBJ_FUNC_IOCTL */
|
||||
|
||||
#undef KMPP_OBJ_NAME
|
||||
#undef KMPP_OBJ_INTF_TYPE
|
||||
#undef KMPP_OBJ_IMPL_TYPE
|
||||
|
|
|
|||
|
|
@ -17,6 +17,17 @@
|
|||
#define _TO_STR(x) #x
|
||||
#define TO_STR(x) _TO_STR(x)
|
||||
|
||||
/* concat two args */
|
||||
#define CONCAT_1(a) a
|
||||
#define CONCAT_2(a,b) a##b
|
||||
#define CONCAT_3(a,b,c) a##b##c
|
||||
#define CONCAT_4(a,b,c,d) a##b##c##d
|
||||
#define CONCAT_5(a,b,c,d,e) a##b##c##d##e
|
||||
#define CONCAT_6(a,b,c,d,e,f) a##b##c##d##e##f
|
||||
|
||||
#define CONCAT_HELPER(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
|
||||
#define CONCAT(...) CONCAT_HELPER(__VA_ARGS__, CONCAT_6, CONCAT_5, CONCAT_4, CONCAT_3, CONCAT_2, CONCAT_1)(__VA_ARGS__)
|
||||
|
||||
/* concat by underscore */
|
||||
#define CONCAT_US1(a) a
|
||||
#define CONCAT_US2(a,b) a##_##b
|
||||
|
|
@ -158,4 +169,7 @@ typedef enum ElemFlagType_e {
|
|||
|
||||
#define ENTRY_NOTHING(prefix, ftype, type, name, flag, ...)
|
||||
|
||||
#define GET_ARG0(def, ...) GET_ARG0_(def, __VA_ARGS__)
|
||||
#define GET_ARG0_(def, _0, ...) _0
|
||||
|
||||
#endif /* __KMPP_OBJ_MACRO_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue