[mpp_platform]: Add kernel version detection

Change-Id: Id2110213daeaca606bafe288a6d4cd970c112d4f
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2021-02-02 20:19:01 +08:00
parent 7936ba3efe
commit 4ecb7de25c
3 changed files with 75 additions and 1 deletions

View File

@@ -16,12 +16,54 @@
#define MODULE_TAG "mpp_platform"
#include <string.h>
#include "mpp_env.h"
#include "mpp_log.h"
#include "mpp_common.h"
#include "mpp_platform.h"
#include "mpp_service.h"
static MppKernelVersion check_kernel_version(void)
{
static const char *kernel_version_path = "/proc/version";
MppKernelVersion version = KERNEL_UNKNOWN;
FILE *fp = NULL;
char buf[32];
if (access(kernel_version_path, F_OK | R_OK))
return version;
fp = fopen(kernel_version_path, "rb");
if (fp) {
size_t len = fread(buf, 1, sizeof(buf) - 1, fp);
char *pos = NULL;
buf[len] = '\0';
pos = strstr(buf, "Linux version ");
if (pos) {
RK_S32 major = 0;
RK_S32 minor = 0;
RK_S32 last = 0;
RK_S32 count = 0;
pos += 14;
count = sscanf(pos, "%d.%d.%d ", &major, &minor, &last);
if (count >= 2 && major > 0 && minor > 0) {
if (major == 3)
version = KERNEL_3_10;
else if (major == 4) {
version = KERNEL_4_4;
if (minor >= 19)
version = KERNEL_4_19;
}
}
}
fclose(fp);
}
return version;
}
class MppPlatformService
{
private:
@@ -32,6 +74,7 @@ private:
MppPlatformService &operator=(const MppPlatformService &);
MppIoctlVersion ioctl_version;
MppKernelVersion kernel_version;
RK_U32 vcodec_type;
RK_U32 hw_ids[32];
MppServiceCmdCap mpp_service_cmd_cap;
@@ -45,13 +88,15 @@ public:
}
MppIoctlVersion get_ioctl_version(void) { return ioctl_version; };
MppKernelVersion get_kernel_version(void) { return kernel_version; };
const char *get_soc_name() { return soc_name; };
MppServiceCmdCap *get_mpp_service_cmd_cap() { return &mpp_service_cmd_cap; };
RK_U32 get_hw_id(RK_S32 client_type);
};
MppPlatformService::MppPlatformService()
: ioctl_version(IOCTL_VCODEC_SERVICE),
: ioctl_version(IOCTL_MPP_SERVICE_V1),
kernel_version(KERNEL_UNKNOWN),
vcodec_type(0),
soc_info(NULL),
soc_name(NULL)
@@ -81,6 +126,7 @@ MppPlatformService::MppPlatformService()
ioctl_version = IOCTL_MPP_SERVICE_V1;
check_mpp_service_cap(&vcodec_type, hw_ids, cap);
}
kernel_version = check_kernel_version();
vcodec_type = soc_info->vcodec_type;
}
@@ -99,6 +145,11 @@ MppIoctlVersion mpp_get_ioctl_version(void)
return MppPlatformService::get_instance()->get_ioctl_version();
}
MppKernelVersion mpp_get_kernel_version(void)
{
return MppPlatformService::get_instance()->get_kernel_version();
}
RK_U32 mpp_get_2d_hw_flag(void)
{
RK_U32 flag = 0;