diff --git a/mpp/hal/worker/inc/mpp_device.h b/mpp/hal/worker/inc/mpp_device.h index ada1e3ca..185784ae 100644 --- a/mpp/hal/worker/inc/mpp_device.h +++ b/mpp/hal/worker/inc/mpp_device.h @@ -18,62 +18,7 @@ #define __MPP_DEVICE_H__ #include "mpp_device_patch.h" - -/* define flags for mpp_request */ -#define MPP_FLAGS_MULTI_MSG (0x00000001) -#define MPP_FLAGS_LAST_MSG (0x00000002) -#define MPP_FLAGS_REG_FD_NO_TRANS (0x00000004) -#define MPP_FLAGS_SCL_FD_NO_TRANS (0x00000008) -#define MPP_FLAGS_LINK_MODE_FIX (0x00000010) -#define MPP_FLAGS_LINK_MODE_UPDATE (0x00000020) -#define MPP_FLAGS_SECURE_MODE (0x00010000) - -/* mpp service capability description */ -typedef enum MppDevCmd_e { - MPP_DEV_GET_START = 0, - MPP_DEV_GET_MAX_WIDTH, - MPP_DEV_GET_MAX_HEIGHT, - MPP_DEV_GET_MIN_WIDTH, - MPP_DEV_GET_MIN_HEIGHT, - MPP_DEV_GET_MMU_STATUS, - - MPP_DEV_SET_START = 0x01000000, - MPP_DEV_SET_HARD_PLATFORM, // set paltform by user - MPP_DEV_ENABLE_POSTPROCCESS, - - MPP_DEV_PROP_BUTT, -} MppDevCmd; - -typedef enum MppDevCmdType_e { - MPP_CMD_QUERY_BASE = 0, - MPP_CMD_PROBE_HW_SUPPORT = MPP_CMD_QUERY_BASE + 0, - MPP_CMD_QUERY_HW_ID = MPP_CMD_QUERY_BASE + 1, - MPP_CMD_QUERY_CMD_SUPPORT = MPP_CMD_QUERY_BASE + 2, - MPP_CMD_QUERY_BUTT, - - MPP_CMD_INIT_BASE = 0x100, - MPP_CMD_INIT_CLIENT_TYPE = MPP_CMD_INIT_BASE + 0, - MPP_CMD_INIT_DRIVER_DATA = MPP_CMD_INIT_BASE + 1, - MPP_CMD_INIT_TRANS_TABLE = MPP_CMD_INIT_BASE + 2, - MPP_CMD_INIT_BUTT, - - MPP_CMD_SEND_BASE = 0x200, - MPP_CMD_SET_REG_WRITE = MPP_CMD_SEND_BASE + 0, - MPP_CMD_SET_REG_READ = MPP_CMD_SEND_BASE + 1, - MPP_CMD_SET_REG_ADDR_OFFSET = MPP_CMD_SEND_BASE + 2, - MPP_CMD_SEND_BUTT, - - MPP_CMD_POLL_BASE = 0x300, - MPP_CMD_POLL_HW_FINISH = MPP_CMD_POLL_BASE + 0, - MPP_CMD_POLL_BUTT, - - MPP_CMD_CONTROL_BASE = 0x400, - MPP_CMD_RESET_SESSION = MPP_CMD_CONTROL_BASE + 0, - MPP_CMD_TRANS_FD_TO_IOVA = MPP_CMD_CONTROL_BASE + 1, - MPP_CMD_CONTROL_BUTT, - - MPP_CMD_BUTT, -} MppDevCmdType; +#include "mpp_service.h" typedef struct MppDevCfg_t { // input diff --git a/mpp/hal/worker/mpp_device/mpp_device.c b/mpp/hal/worker/mpp_device/mpp_device.c index 791734c9..6bd512bb 100644 --- a/mpp/hal/worker/mpp_device/mpp_device.c +++ b/mpp/hal/worker/mpp_device/mpp_device.c @@ -63,12 +63,7 @@ typedef struct MppDevCtxImpl_t { MppReqV1 reqs[MAX_REQ_NUM]; /* support max cmd buttom */ - RK_U32 support_cmd_butt; - RK_U32 query_cmd_butt; - RK_U32 init_cmd_butt; - RK_U32 send_cmd_butt; - RK_U32 poll_cmd_butt; - RK_U32 control_cmd_butt; + const MppServiceCmdCap *cap; } MppDevCtxImpl; #define MPP_DEVICE_DBG_FUNC (0x00000001) @@ -90,63 +85,19 @@ typedef struct MppDevCtxImpl_t { static RK_U32 mpp_device_debug = 0; -static MPP_RET mpp_probe_cmd_butt(RK_S32 dev, MppDevCtxImpl *p) -{ - MPP_RET ret = MPP_OK; - - p->support_cmd_butt = access("/proc/mpp_service/support_cmd", F_OK) ? 0 : 1; - if (p->support_cmd_butt) { - MppReqV1 mpp_req; - - memset(&mpp_req, 0, sizeof(mpp_req)); - p->query_cmd_butt = MPP_CMD_QUERY_BASE; - mpp_req.cmd = MPP_CMD_QUERY_CMD_SUPPORT; - mpp_req.data_ptr = REQ_DATA_PTR(&p->query_cmd_butt); - - ret = (RK_S32)ioctl(dev, MPP_IOC_CFG_V1, &mpp_req); - if (ret) - mpp_err_f("query cmd support error %s.\n", strerror(errno)); - - p->init_cmd_butt = MPP_CMD_INIT_BASE; - mpp_req.data_ptr = REQ_DATA_PTR(&p->init_cmd_butt); - ret = (RK_S32)ioctl(dev, MPP_IOC_CFG_V1, &mpp_req); - if (ret) - mpp_err_f("query INIT_CMD_BUTT error %s.\n", strerror(errno)); - - p->send_cmd_butt = MPP_CMD_SEND_BASE; - mpp_req.data_ptr = REQ_DATA_PTR(&p->send_cmd_butt); - ret = (RK_S32)ioctl(dev, MPP_IOC_CFG_V1, &mpp_req); - if (ret) - mpp_err_f("query SEND_CMD_BUTT error %s.\n", strerror(errno)); - - p->poll_cmd_butt = MPP_CMD_POLL_BASE; - mpp_req.data_ptr = REQ_DATA_PTR(&p->poll_cmd_butt); - ret = (RK_S32)ioctl(dev, MPP_IOC_CFG_V1, &mpp_req); - if (ret) - mpp_err_f("query POLL_CMD_BUTT error %s.\n", strerror(errno)); - - p->control_cmd_butt = MPP_CMD_CONTROL_BASE; - mpp_req.data_ptr = REQ_DATA_PTR(&p->control_cmd_butt); - ret = (RK_S32)ioctl(dev, MPP_IOC_CFG_V1, &mpp_req); - if (ret) - mpp_err_f("query CONTROL_CMD_BUTT error %s.\n", strerror(errno)); - } - - return ret; -} - static MPP_RET mpp_check_cmd_valid(RK_U32 cmd, MppDevCtxImpl *p) { + const MppServiceCmdCap *cap = p->cap; MPP_RET ret = MPP_OK; - if (p->support_cmd_butt > 0) { + if (cap->support_cmd > 0) { RK_U32 found = 0; - found = (cmd < p->query_cmd_butt) ? 1 : 0; - found = (cmd >= MPP_CMD_INIT_BASE && cmd < p->init_cmd_butt) ? 1 : found; - found = (cmd >= MPP_CMD_SEND_BASE && cmd < p->send_cmd_butt) ? 1 : found; - found = (cmd >= MPP_CMD_POLL_BASE && cmd < p->poll_cmd_butt) ? 1 : found; - found = (cmd >= MPP_CMD_CONTROL_BASE && cmd < p->control_cmd_butt) ? 1 : found; + found = (cmd < cap->query_cmd) ? 1 : 0; + found = (cmd >= MPP_CMD_INIT_BASE && cmd < cap->init_cmd) ? 1 : found; + found = (cmd >= MPP_CMD_SEND_BASE && cmd < cap->send_cmd) ? 1 : found; + found = (cmd >= MPP_CMD_POLL_BASE && cmd < cap->poll_cmd) ? 1 : found; + found = (cmd >= MPP_CMD_CONTROL_BASE && cmd < cap->ctrl_cmd) ? 1 : found; ret = found ? MPP_OK : MPP_NOK; } @@ -317,7 +268,7 @@ MPP_RET mpp_device_init(MppDevCtx *ctx, MppDevCfg *cfg) /* if ioctl_version is 1, query hw supprot*/ if (p->ioctl_version > 0) { - mpp_probe_cmd_butt(dev, p); + p->cap = mpp_get_mpp_service_cmd_cap(); mpp_probe_hw_support(dev); } diff --git a/mpp/vproc/iep2/iep2.c b/mpp/vproc/iep2/iep2.c index 47e84158..d42aa29a 100644 --- a/mpp/vproc/iep2/iep2.c +++ b/mpp/vproc/iep2/iep2.c @@ -40,44 +40,6 @@ #define IEP2_TILE_W_MAX 120 #define IEP2_TILE_H_MAX 272 -/** - * Command type: keep the same as kernel - */ -enum MPP_DEV_COMMAND_TYPE { - MPP_CMD_QUERY_BASE = 0, - MPP_CMD_QUERY_HW_SUPPORT = MPP_CMD_QUERY_BASE + 0, - MPP_CMD_QUERY_HW_ID = MPP_CMD_QUERY_BASE + 1, - - MPP_CMD_INIT_BASE = 0x100, - MPP_CMD_INIT_CLIENT_TYPE = MPP_CMD_INIT_BASE + 0, - MPP_CMD_INIT_DRIVER_DATA = MPP_CMD_INIT_BASE + 1, - MPP_CMD_INIT_TRANS_TABLE = MPP_CMD_INIT_BASE + 2, - - MPP_CMD_SEND_BASE = 0x200, - MPP_CMD_SET_REG_WRITE = MPP_CMD_SEND_BASE + 0, - MPP_CMD_SET_REG_READ = MPP_CMD_SEND_BASE + 1, - MPP_CMD_SET_REG_ADDR_OFFSET = MPP_CMD_SEND_BASE + 2, - - MPP_CMD_POLL_BASE = 0x300, - MPP_CMD_POLL_HW_FINISH = MPP_CMD_POLL_BASE + 0, - - MPP_CMD_CONTROL_BASE = 0x400, - MPP_CMD_RESET_SESSION = MPP_CMD_CONTROL_BASE + 0, - MPP_CMD_TRANS_FD_TO_IOVA = MPP_CMD_CONTROL_BASE + 1, - MPP_CMD_RELEASE_FD = MPP_CMD_CONTROL_BASE + 2, - - MPP_CMD_BUTT, -}; - -/* define flags for mpp_request */ -#define MPP_FLAGS_MULTI_MSG (0x00000001) -#define MPP_FLAGS_LAST_MSG (0x00000002) -#define MPP_FLAGS_REG_FD_NO_TRANS (0x00000004) -#define MPP_FLAGS_SCL_FD_NO_TRANS (0x00000008) -#define MPP_FLAGS_LINK_MODE_FIX (0x00000010) -#define MPP_FLAGS_LINK_MODE_UPDATE (0x00000020) -#define MPP_FLAGS_SECURE_MODE (0x00010000) - static MPP_RET iep2_init(IepCtx *ictx) { MPP_RET ret; diff --git a/osal/inc/mpp_platform.h b/osal/inc/mpp_platform.h index 06cfe300..cb6502d8 100644 --- a/osal/inc/mpp_platform.h +++ b/osal/inc/mpp_platform.h @@ -18,6 +18,7 @@ #define __MPP_PLATFORM__ #include "rk_type.h" +#include "mpp_service.h" /* * Platform flag detection is for rockchip hardware platform detection @@ -96,6 +97,7 @@ RK_U32 mpp_get_2d_hw_flag(void); RK_U32 mpp_refresh_vcodec_type(RK_U32 vcodec_type); const char *mpp_get_platform_dev_name(MppCtxType type, MppCodingType coding, RK_U32 platform); const char *mpp_get_vcodec_dev_name(MppCtxType type, MppCodingType coding); +const MppServiceCmdCap *mpp_get_mpp_service_cmd_cap(void); #ifdef __cplusplus } diff --git a/osal/inc/mpp_service.h b/osal/inc/mpp_service.h index cf272965..238a11f8 100644 --- a/osal/inc/mpp_service.h +++ b/osal/inc/mpp_service.h @@ -18,6 +18,7 @@ #define __MPP_SERVICE_H__ #include "rk_type.h" +#include /* Use 'v' as magic number */ #define MPP_IOC_MAGIC 'v' @@ -30,6 +31,64 @@ #define REQ_DATA_PTR(ptr) ((RK_U64)ptr) #endif +/* define flags for mpp_request */ +#define MPP_FLAGS_MULTI_MSG (0x00000001) +#define MPP_FLAGS_LAST_MSG (0x00000002) +#define MPP_FLAGS_REG_FD_NO_TRANS (0x00000004) +#define MPP_FLAGS_SCL_FD_NO_TRANS (0x00000008) +#define MPP_FLAGS_LINK_MODE_FIX (0x00000010) +#define MPP_FLAGS_LINK_MODE_UPDATE (0x00000020) +#define MPP_FLAGS_SECURE_MODE (0x00010000) + +/* mpp service capability description */ +typedef enum MppDevCmd_e { + MPP_DEV_GET_START = 0, + MPP_DEV_GET_MAX_WIDTH, + MPP_DEV_GET_MAX_HEIGHT, + MPP_DEV_GET_MIN_WIDTH, + MPP_DEV_GET_MIN_HEIGHT, + MPP_DEV_GET_MMU_STATUS, + + MPP_DEV_SET_START = 0x01000000, + MPP_DEV_SET_HARD_PLATFORM, // set paltform by user + MPP_DEV_ENABLE_POSTPROCCESS, + + MPP_DEV_PROP_BUTT, +} MppDevCmd; + +typedef enum MppDevCmdType_e { + MPP_CMD_QUERY_BASE = 0, + MPP_CMD_PROBE_HW_SUPPORT = MPP_CMD_QUERY_BASE + 0, + MPP_CMD_QUERY_HW_ID = MPP_CMD_QUERY_BASE + 1, + MPP_CMD_QUERY_CMD_SUPPORT = MPP_CMD_QUERY_BASE + 2, + MPP_CMD_QUERY_BUTT, + + MPP_CMD_INIT_BASE = 0x100, + MPP_CMD_INIT_CLIENT_TYPE = MPP_CMD_INIT_BASE + 0, + MPP_CMD_INIT_DRIVER_DATA = MPP_CMD_INIT_BASE + 1, + MPP_CMD_INIT_TRANS_TABLE = MPP_CMD_INIT_BASE + 2, + MPP_CMD_INIT_BUTT, + + MPP_CMD_SEND_BASE = 0x200, + MPP_CMD_SET_REG_WRITE = MPP_CMD_SEND_BASE + 0, + MPP_CMD_SET_REG_READ = MPP_CMD_SEND_BASE + 1, + MPP_CMD_SET_REG_ADDR_OFFSET = MPP_CMD_SEND_BASE + 2, + MPP_CMD_SEND_BUTT, + + MPP_CMD_POLL_BASE = 0x300, + MPP_CMD_POLL_HW_FINISH = MPP_CMD_POLL_BASE + 0, + MPP_CMD_POLL_BUTT, + + MPP_CMD_CONTROL_BASE = 0x400, + MPP_CMD_RESET_SESSION = MPP_CMD_CONTROL_BASE + 0, + MPP_CMD_TRANS_FD_TO_IOVA = MPP_CMD_CONTROL_BASE + 1, + MPP_CMD_RELEASE_FD = MPP_CMD_CONTROL_BASE + 2, + MPP_CMD_SEND_CODEC_INFO = MPP_CMD_CONTROL_BASE + 3, + MPP_CMD_CONTROL_BUTT, + + MPP_CMD_BUTT, +} MppDevCmdType; + typedef struct MppReq_t { RK_U32 *req; RK_U32 size; @@ -43,4 +102,13 @@ typedef struct mppReqV1_t { RK_U64 data_ptr; } MppReqV1; +typedef struct MppServiceCmdCap_t { + RK_U32 support_cmd; + RK_U32 query_cmd; + RK_U32 init_cmd; + RK_U32 send_cmd; + RK_U32 poll_cmd; + RK_U32 ctrl_cmd; +} MppServiceCmdCap; + #endif /* __MPP_SERVICE_H__ */ diff --git a/osal/mpp_platform.cpp b/osal/mpp_platform.cpp index 6bbba7a0..f66ab401 100644 --- a/osal/mpp_platform.cpp +++ b/osal/mpp_platform.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include +#include #include #include @@ -22,6 +24,7 @@ #include "mpp_mem.h" #include "mpp_common.h" #include "mpp_platform.h" +#include "mpp_service.h" #define MAX_SOC_NAME_LENGTH 128 @@ -140,6 +143,63 @@ static const char *_mpp_find_device(const char **dev, RK_U32 size) return NULL; } +typedef struct MppServiceQueryCfg_t { + RK_U32 cmd_butt; + const char *name; +} MppServiceQueryCfg; + +static const MppServiceQueryCfg query_cfg[] = { + { MPP_CMD_QUERY_BASE, "query_cmd", }, + { MPP_CMD_INIT_BASE, "init_cmd", }, + { MPP_CMD_SEND_BASE, "query_cmd", }, + { MPP_CMD_POLL_BASE, "init_cmd", }, + { MPP_CMD_CONTROL_BASE, "control_cmd", }, +}; + +static const RK_U32 query_count = MPP_ARRAY_ELEMS(query_cfg); + +static void check_mpp_service_cap(MppServiceCmdCap *cap) +{ + const char *name = NULL; + MppReqV1 mpp_req; + RK_S32 fd = -1; + RK_S32 ret = 0; + RK_U32 *cmd_butt = &cap->query_cmd;; + RK_U32 i; + + cap->support_cmd = access("/proc/mpp_service/support_cmd", F_OK) ? 0 : 1; + if (!cap->support_cmd) + return ; + + name = mpp_find_device(mpp_service_dev); + mpp_assert(name); + fd = open(name, O_RDWR); + if (fd < 0) { + mpp_err("open mpp_service to check cmd capability failed\n"); + memset(cap, 0, sizeof(*cap)); + return ; + } + + for (i = 0; i < query_count; i++, cmd_butt++) { + const MppServiceQueryCfg *cfg = &query_cfg[i]; + RK_U32 val; + + memset(&mpp_req, 0, sizeof(mpp_req)); + + val = cfg->cmd_butt; + mpp_req.cmd = MPP_CMD_QUERY_CMD_SUPPORT; + mpp_req.data_ptr = REQ_DATA_PTR(&val); + + ret = (RK_S32)ioctl(fd, MPP_IOC_CFG_V1, &mpp_req); + if (ret) + mpp_err_f("query %s support error %s.\n", cfg->name, strerror(errno)); + else + *cmd_butt = val; + } + + close(fd); +} + class MppPlatformService { private: @@ -149,11 +209,12 @@ private: MppPlatformService(const MppPlatformService &); MppPlatformService &operator=(const MppPlatformService &); - MppIoctlVersion ioctl_version; - char *soc_name; - RockchipSocType soc_type; - RK_U32 vcodec_type; - RK_U32 vcodec_capability; + MppIoctlVersion ioctl_version; + char *soc_name; + RockchipSocType soc_type; + RK_U32 vcodec_type; + RK_U32 vcodec_capability; + MppServiceCmdCap mpp_service_cmd_cap; public: static MppPlatformService *get_instance() { @@ -161,12 +222,13 @@ public: return &instance; } - MppIoctlVersion get_ioctl_version(void) { return ioctl_version; }; - const char *get_soc_name() { return soc_name; }; - RockchipSocType get_soc_type() { return soc_type; }; - RK_U32 get_vcodec_type() { return vcodec_type; }; - void set_vcodec_type(RK_U32 val) { vcodec_type = val; }; - RK_U32 get_vcodec_capability() { return vcodec_capability; }; + MppIoctlVersion get_ioctl_version(void) { return ioctl_version; }; + const char *get_soc_name() { return soc_name; }; + RockchipSocType get_soc_type() { return soc_type; }; + RK_U32 get_vcodec_type() { return vcodec_type; }; + void set_vcodec_type(RK_U32 val) { vcodec_type = val; }; + RK_U32 get_vcodec_capability() { return vcodec_capability; }; + MppServiceCmdCap *get_mpp_service_cmd_cap() { return &mpp_service_cmd_cap; }; }; MppPlatformService::MppPlatformService() @@ -176,8 +238,17 @@ MppPlatformService::MppPlatformService() vcodec_capability(0) { /* judge vdpu support version */ + MppServiceCmdCap *cap = &mpp_service_cmd_cap; RK_S32 fd = -1; + /* default value */ + cap->support_cmd = 0; + cap->query_cmd = MPP_CMD_QUERY_BASE + 1; + cap->init_cmd = MPP_CMD_INIT_BASE + 1; + cap->send_cmd = MPP_CMD_SEND_BASE + 1; + cap->poll_cmd = MPP_CMD_POLL_BASE + 1; + cap->ctrl_cmd = MPP_CMD_CONTROL_BASE + 0; + mpp_env_get_u32("mpp_debug", &mpp_debug, 0); /* set vpu1 defalut for old chip without dts */ @@ -227,6 +298,7 @@ MppPlatformService::MppPlatformService() /* if /dev/mpp_service not double check */ if (mpp_find_device(mpp_service_dev)) { ioctl_version = IOCTL_MPP_SERVICE_V1; + check_mpp_service_cap(cap); mpp_dbg(MPP_DBG_PLATFORM, "/dev/mpp_service not double check device\n"); goto __return; } @@ -537,3 +609,8 @@ const char *mpp_get_vcodec_dev_name(MppCtxType type, MppCodingType coding) return dev; } + +const MppServiceCmdCap *mpp_get_mpp_service_cmd_cap(void) +{ + return MppPlatformService::get_instance()->get_mpp_service_cmd_cap(); +}