From 2fc024529e8f65c67f9d5614bcf8ea54cecfe2e0 Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Thu, 3 Nov 2016 10:44:53 +0800 Subject: [PATCH] [osal]: add environment detection function 1. add software runtime detection 2. add hardware platform detection Change-Id: I75736ae85130325029023d948e4d756e27953af8 Signed-off-by: Herman Chen --- osal/CMakeLists.txt | 2 ++ osal/inc/mpp_platform.h | 57 +++++++++++++++++++++++++++++++++++++ osal/inc/mpp_runtime.h | 45 ++++++++++++++++++++++++++++++ osal/mpp_platform.cpp | 62 +++++++++++++++++++++++++++++++++++++++++ osal/mpp_runtime.cpp | 43 ++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+) create mode 100644 osal/inc/mpp_platform.h create mode 100644 osal/inc/mpp_runtime.h create mode 100644 osal/mpp_platform.cpp create mode 100644 osal/mpp_runtime.cpp diff --git a/osal/CMakeLists.txt b/osal/CMakeLists.txt index 6d498ea0..40a9096a 100644 --- a/osal/CMakeLists.txt +++ b/osal/CMakeLists.txt @@ -21,6 +21,8 @@ include_directories(.) include_directories(./allocator) add_library(osal STATIC + mpp_platform.cpp + mpp_runtime.cpp mpp_allocator.cpp mpp_thread.cpp mpp_common.cpp diff --git a/osal/inc/mpp_platform.h b/osal/inc/mpp_platform.h new file mode 100644 index 00000000..056b2cf6 --- /dev/null +++ b/osal/inc/mpp_platform.h @@ -0,0 +1,57 @@ +/* + * Copyright 2015 Rockchip Electronics Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MPP_PLATFORM__ +#define __MPP_PLATFORM__ + +#include "rk_type.h" + +/* + * Platform flag detection is for rockchip hardware platform detection + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Platform video codec hardware feature + */ +#define HAVE_VPU1 (0x00000001) +#define HAVE_VPU2 (0x00000002) +#define HAVE_HEVC_DEC (0x00000010) +#define HAVE_RKVDEC (0x00000020) +#define HAVE_RKVENC (0x00000100) +#define HAVE_H265E (0x00010000) + +RK_U32 mpp_get_vcodec_hw_flag(void); + +/* + * Platform image process hardware feature + */ +#define HAVE_IPP (0x00000001) +#define HAVE_RGA (0x00000002) +#define HAVE_RGA2 (0x00000004) +#define HAVE_IEP (0x00000008) + +RK_U32 mpp_get_2d_hw_flag(void); + +#ifdef __cplusplus +} +#endif + +#endif /*__MPP_PLATFORM__*/ + diff --git a/osal/inc/mpp_runtime.h b/osal/inc/mpp_runtime.h new file mode 100644 index 00000000..6b87f243 --- /dev/null +++ b/osal/inc/mpp_runtime.h @@ -0,0 +1,45 @@ +/* + * Copyright 2015 Rockchip Electronics Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MPP_RUNTIME__ +#define __MPP_RUNTIME__ + +#include "mpp_common.h" + +/* + * Runtime function detection is for rockchip software platform detection + */ + +typedef void *(*func_mmap64)(void* addr,size_t length, int prot, int flags, + int fd, off_t offset); + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Runtime function detection is to support different binary on different + * runtime environment. This is usefull on product environemnt. + */ + +func_mmap64 mpp_rt_get_mmap64(); + +#ifdef __cplusplus +} +#endif + +#endif /*__MPP_RUNTIME__*/ + diff --git a/osal/mpp_platform.cpp b/osal/mpp_platform.cpp new file mode 100644 index 00000000..483adbe6 --- /dev/null +++ b/osal/mpp_platform.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2015 Rockchip Electronics Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "mpp_platform.h" + +RK_U32 mpp_get_vcodec_hw_flag(void) +{ + RK_U32 flag = 0; + +#ifdef RKPLATFORM + /* NOTE: current only support vpu2 */ + if (!access("/dev/vpu_service", F_OK)) + flag |= HAVE_VPU2; + + /* for rk3288 / rk3368 /rk312x hevc decoder */ + if (!access("/dev/hevc_service", F_OK)) + flag |= HAVE_HEVC_DEC; + + /* for rk3228 / rk3229 / rk3399 decoder */ + if (!access("/dev/rkvdec", F_OK)) + flag |= HAVE_RKVDEC; + + /* for rk1108 encoder */ + if (!access("/dev/rkvenc", F_OK)) + flag |= HAVE_RKVENC; +#endif + + return flag; +} + +RK_U32 mpp_get_2d_hw_flag(void) +{ + RK_U32 flag = 0; + +#ifdef RKPLATFORM + + if (!access("/dev/rga", F_OK)) + flag |= HAVE_RGA; + + if (!access("/dev/iep", F_OK)) + flag |= HAVE_IEP; +#endif + + return flag; +} + + diff --git a/osal/mpp_runtime.cpp b/osal/mpp_runtime.cpp new file mode 100644 index 00000000..bd96a763 --- /dev/null +++ b/osal/mpp_runtime.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2015 Rockchip Electronics Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef RKPLATFORM +#include +#endif + +#include "mpp_runtime.h" + +static func_mmap64 mpp_rt_mmap64 = NULL; + +func_mmap64 mpp_rt_get_mmap64() +{ +#ifdef RKPLATFORM + static RK_U32 once = 1; + + if (once) { + void *libc_hdl = dlopen("libc", RTLD_LAZY); + if (libc_hdl) { + mpp_rt_mmap64 = (func_mmap64)dlsym(libc_hdl, "mmap64"); + dlclose(libc_hdl); + } + + once = 0; + } +#endif + + return mpp_rt_mmap64; +} +