mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 17:46:50 +08:00
[runtime]: Add more runtime detection
As we found that simple ion / drm device detectioin can not cover all the case. For example on some 3368 platform kernel provide both ion and drm device. We have better to use allocator chosen in dts. But later kernel patch from Randy will bring unified dma-fd translation in kernel then this detection will be removed. Change-Id: I2746142d1c3d0f36791bacaadb231dc2001a5aa7 Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
@@ -11,6 +11,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
if (HAVE_DRM)
|
||||
add_definitions(-DHAVE_DRM)
|
||||
set(DRM_FILES allocator/allocator_drm.c)
|
||||
message(STATUS "compile with drm support")
|
||||
else()
|
||||
message(STATUS "compile without drm support")
|
||||
endif()
|
||||
|
||||
set(MPP_ALLOCATOR
|
||||
|
@@ -20,8 +20,34 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mpp_log.h"
|
||||
#include "mpp_common.h"
|
||||
#include "mpp_runtime.h"
|
||||
|
||||
#define MAX_DTS_PATH_LEN 256
|
||||
|
||||
static const char *mpp_dts_base = "/proc/device-tree/";
|
||||
|
||||
static const char *mpp_vpu_names[] = {
|
||||
"vpu_service",
|
||||
"vpu-service",
|
||||
"vpu",
|
||||
//"hevc_service",
|
||||
//"hevc-service",
|
||||
//"rkvdec",
|
||||
//"rkvenc",
|
||||
//"vpu_combo",
|
||||
};
|
||||
|
||||
static const char *mpp_vpu_address[] = {
|
||||
"", /* old kernel */
|
||||
"@10108000", /* rk3036 */
|
||||
"@20020000", /* rk322x */
|
||||
"@30000000", /* rv1108 */
|
||||
"@ff9a0000", /* rk3288/3366 */
|
||||
"@ff350000", /* rk322xh/3328 */
|
||||
"@ff650000", /* rk3399 */
|
||||
};
|
||||
|
||||
class MppRuntimeService
|
||||
{
|
||||
private:
|
||||
@@ -72,6 +98,58 @@ MppRuntimeService::MppRuntimeService()
|
||||
mpp_log("found drm allocator\n");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
// If both ion and drm is enabled detect allocator in dts to choose one
|
||||
// TODO: When unify dma fd kernel is completed this part will be removed.
|
||||
if (allocator_valid[MPP_BUFFER_TYPE_ION] &&
|
||||
allocator_valid[MPP_BUFFER_TYPE_DRM]) {
|
||||
/* Detect hardware buffer type is ion or drm */
|
||||
RK_U32 i, j;
|
||||
char path[MAX_DTS_PATH_LEN];
|
||||
RK_U32 path_len = MAX_DTS_PATH_LEN;
|
||||
RK_U32 dts_path_len = snprintf(path, path_len, "%s", mpp_dts_base);
|
||||
char *p = path + dts_path_len;
|
||||
RK_U32 allocator_found = 0;
|
||||
|
||||
path_len -= dts_path_len;
|
||||
|
||||
for (i = 0; i < MPP_ARRAY_ELEMS(mpp_vpu_names); i++) {
|
||||
for (j = 0; j < MPP_ARRAY_ELEMS(mpp_vpu_address); j++) {
|
||||
RK_U32 dev_path_len = snprintf(p, path_len, "%s%s",
|
||||
mpp_vpu_names[i], mpp_vpu_address[j]);
|
||||
int f_ok = access(path, F_OK);
|
||||
if (f_ok == 0) {
|
||||
snprintf(p + dev_path_len, path_len - dev_path_len, "/%s", "allocator");
|
||||
f_ok = access(path, F_OK);
|
||||
if (f_ok == 0) {
|
||||
RK_S32 val = 0;
|
||||
FILE *fp = fopen(path, "rb");
|
||||
if (fp) {
|
||||
fread(&val, 1, 4, fp);
|
||||
// zero for ion non-zero for drm ->
|
||||
// zero - disable drm
|
||||
// non-zero - disable ion
|
||||
if (val == 0) {
|
||||
allocator_valid[MPP_BUFFER_TYPE_DRM] = 0;
|
||||
mpp_log("found ion allocator in dts\n");
|
||||
} else {
|
||||
allocator_valid[MPP_BUFFER_TYPE_ION] = 0;
|
||||
mpp_log("found drm allocator in dts\n");
|
||||
}
|
||||
allocator_found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allocator_found)
|
||||
break;
|
||||
}
|
||||
if (allocator_found)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!allocator_found)
|
||||
mpp_log("Can NOT found allocator in dts, enable both ion and drm\n");
|
||||
}
|
||||
}
|
||||
|
||||
RK_U32 mpp_rt_allcator_is_valid(MppBufferType type)
|
||||
|
@@ -13,7 +13,7 @@ macro(add_mpp_osal_test module)
|
||||
option(${test_tag} "Build osal ${module} unit test" ON)
|
||||
if(${test_tag})
|
||||
add_executable(${test_name} ${test_name}.c)
|
||||
target_link_libraries(${test_name} osal)
|
||||
target_link_libraries(${test_name} ${MPP_SHARED})
|
||||
set_target_properties(${test_name} PROPERTIES FOLDER "osal/test")
|
||||
add_test(NAME ${test_name} COMMAND ${test_name})
|
||||
endif()
|
||||
@@ -31,6 +31,9 @@ add_mpp_osal_test(mpp_mem)
|
||||
# hardware platform feature detection unit test
|
||||
add_mpp_osal_test(mpp_platform)
|
||||
|
||||
# software runtime feature detection unit test
|
||||
add_mpp_osal_test(mpp_runtime)
|
||||
|
||||
# thread implement unit test
|
||||
add_mpp_osal_test(mpp_thread)
|
||||
|
||||
|
35
osal/test/mpp_runtime_test.c
Normal file
35
osal/test/mpp_runtime_test.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define MODULE_TAG "mpp_rt_test"
|
||||
|
||||
#include "mpp_log.h"
|
||||
#include "mpp_runtime.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION))
|
||||
mpp_log("mpp found ion buffer is valid\n");
|
||||
else
|
||||
mpp_log("mpp found ion buffer is invalid\n");
|
||||
|
||||
if (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM))
|
||||
mpp_log("mpp found drm buffer is valid\n");
|
||||
else
|
||||
mpp_log("mpp found drm buffer is invalid\n");
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user