media_modules: add sec firmload for 4.9[3/3]

PD# 150992

add sec firmload for 4.9 under optee

Change-Id: Id1f5cbcfc293746869bea9542109a9ef7ed628e5
Signed-off-by: Yvonne Chen <yvonne.chen@amlogic.com>
This commit is contained in:
Yvonne Chen
2017-09-26 17:29:59 +08:00
committed by Dongjin Kim
parent 89928d7baa
commit 01bd5ba2b8
16 changed files with 80 additions and 55 deletions

View File

@@ -34,6 +34,7 @@
#include <linux/string.h>
#include <linux/amlogic/media/utils/log.h>
#include <linux/firmware.h>
#include <linux/amlogic/tee.h>
#include <linux/amlogic/major.h>
#include <linux/cdev.h>
#include <linux/crc32.h>
@@ -67,7 +68,15 @@ int get_firmware_data(enum firmware_type_e type, char *buf)
int data_len, ret = -1;
struct firmware_mgr_s *mgr = g_mgr;
struct firmware_info_s *info;
if (tee_enabled()) {
pr_info ("tee load firmware type= %d\n",(u32)type);
ret = tee_load_video_fw((u32)type);
if (ret == 0)
ret = 1;
else
ret = -1;
return ret;
}
if (list_empty(&mgr->head)) {
pr_info("the info list is empty.\n");
return 0;
@@ -143,7 +152,7 @@ static int request_firmware_from_sys(const char *file_name,
goto release;
}
memcpy(buf, (char *)firmware->data, firmware->size);
memcpy(buf, (char *)firmware->data+256, firmware->size-256);
pr_info("load firmware size : %zd, Name : %s.\n",
firmware->size, file_name);

View File

@@ -1460,12 +1460,15 @@ static s32 vavs_init(void)
size = get_firmware_data(VIDEO_DEC_AVS, buf);
if (size < 0) {
amvdec_disable();
pr_err("get firmware fail.");
vfree(buf);
return -1;
}
if (amvdec_loadmc_ex(VFORMAT_AVS, NULL, buf) < 0) {
if (size == 1)
pr_info ("tee load ok");
else if (amvdec_loadmc_ex(VFORMAT_AVS, NULL, buf) < 0) {
amvdec_disable();
vfree(buf);
return -EBUSY;

View File

@@ -45,7 +45,7 @@
#include "../../../stream_input/parser/streambuf.h"
#include <linux/delay.h>
#include <linux/amlogic/media/video_sink/video.h>
#include <linux/amlogic/tee.h>
#include <linux/amlogic/media/ge2d/ge2d.h>
#include "../utils/decoder_mmu_box.h"
#include "../utils/decoder_bmmu_box.h"
@@ -2348,7 +2348,7 @@ static void vh264_prot_init(void)
WRITE_VREG(AV_SCRATCH_0, 0);
WRITE_VREG(AV_SCRATCH_1, buf_offset);
if (!is_secload_get())
if (!tee_enabled())
WRITE_VREG(AV_SCRATCH_G, mc_dma_handle);
WRITE_VREG(AV_SCRATCH_7, 0);
WRITE_VREG(AV_SCRATCH_8, 0);
@@ -2565,7 +2565,7 @@ static s32 vh264_init(void)
query_video_status(0, &trickmode_fffb);
amvdec_enable();
if (!firmwareloaded && is_secload_get()) {
if (!firmwareloaded && tee_enabled()) {
if (tee_load_video_fw((u32)VIDEO_DEC_H264) != 0) {
amvdec_disable();
return -1;

View File

@@ -31,6 +31,7 @@
#include <linux/workqueue.h>
#include <linux/dma-mapping.h>
#include <linux/atomic.h>
#include <linux/amlogic/tee.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -1404,7 +1405,7 @@ static s32 vh264mvc_init(void)
amvdec_enable();
if (is_secload_get()) {
if (tee_enabled()) {
if (tee_load_video_fw((u32)VIDEO_DEC_H264_MVC) != 0) {
amvdec_disable();
return -1;

View File

@@ -42,6 +42,7 @@
#include <linux/amlogic/media/codec_mm/codec_mm.h>
#include "../utils/vdec_input.h"
#include <linux/amlogic/tee.h>
#include <linux/amlogic/media/utils/vdec_reg.h>
#include "../utils/vdec.h"
@@ -4342,7 +4343,7 @@ static int vh264_hw_ctx_restore(struct vdec_h264_hw_s *hw)
WRITE_VREG(FRAME_COUNTER_REG, hw->decode_pic_count);
WRITE_VREG(AV_SCRATCH_8, hw->buf_offset);
if (!is_secload_get())
if (!tee_enabled())
WRITE_VREG(AV_SCRATCH_G, hw->mc_dma_handle);
/* hw->error_recovery_mode = (error_recovery_mode != 0) ?
@@ -4495,7 +4496,7 @@ static s32 vh264_init(struct vdec_h264_hw_s *hw)
return -ENOMEM;
}
}
if (is_secload_get() && !firmwareloaded) {
if (tee_enabled() && !firmwareloaded) {
pr_info("VMH264 start load sec firmware ...\n");
if (tee_load_video_fw((u32)VIDEO_DEC_H264_MULTI)
!= 0) {
@@ -5094,8 +5095,7 @@ static void run(struct vdec_s *vdec,
size);
start_process_time(hw);
if (is_secload_get()) {
if (tee_enabled()) {
if (tee_load_video_fw((u32)VIDEO_DEC_H264_MULTI)
!= 0) {
amvdec_enable_flag = false;

View File

@@ -8613,7 +8613,9 @@ static s32 vh265_init(struct hevc_state_s *hevc)
#endif
amhevc_enable();
if (amhevc_loadmc_ex(VFORMAT_HEVC, NULL, fw->data) < 0) {
if (size == 1)
pr_info ("tee load ok");
else if (amhevc_loadmc_ex(VFORMAT_HEVC, NULL, fw->data) < 0) {
amhevc_disable();
vfree(fw);
return -EBUSY;
@@ -9423,7 +9425,12 @@ static void run(struct vdec_s *vdec,
}
}
if (amhevc_vdec_loadmc_ex(vdec, NULL, hevc->fw->data) < 0) {
if (hevc->mmu_enable &&(get_cpu_type() >= MESON_CPU_MAJOR_ID_GXL))
r = amhevc_vdec_loadmc_ex(vdec, "vh265_mc_mmu", hevc->fw->data);
else
r = amhevc_vdec_loadmc_ex(vdec, "vh265_mc", hevc->fw->data);
if (r < 0) {
amhevc_disable();
hevc_print(hevc, 0,
"%s: Error amvdec_loadmc fail\n",

View File

@@ -727,12 +727,15 @@ static s32 vmjpeg_init(void)
size = get_firmware_data(VIDEO_DEC_MJPEG, buf);
if (size < 0) {
amvdec_disable();
pr_err("get firmware fail.");
vfree(buf);
return -1;
}
if (amvdec_loadmc_ex(VFORMAT_MJPEG, NULL, buf) < 0) {
if (size == 1)
pr_info ("tee load ok");
else if (amvdec_loadmc_ex(VFORMAT_MJPEG, NULL, buf) < 0) {
amvdec_disable();
vfree(buf);
return -EBUSY;

View File

@@ -1082,7 +1082,9 @@ static s32 vmpeg12_init(void)
return -1;
}
if (amvdec_loadmc_ex(VFORMAT_MPEG12, NULL, buf) < 0) {
if (size == 1)
pr_info ("tee load ok");
else if (amvdec_loadmc_ex(VFORMAT_MPEG12, NULL, buf) < 0) {
amvdec_disable();
vfree(buf);
return -EBUSY;

View File

@@ -1040,7 +1040,9 @@ static s32 vmpeg4_init(void)
return -1;
}
if (amvdec_loadmc_ex(VFORMAT_MPEG4, NULL, buf) < 0) {
if (size == 1)
pr_info ("tee load ok");
else if (amvdec_loadmc_ex(VFORMAT_MPEG4, NULL, buf) < 0) {
amvdec_disable();
vfree(buf);
return -EBUSY;

View File

@@ -822,12 +822,14 @@ s32 vreal_init(struct vdec_s *vdec)
pr_info("unsurpported real format\n");
if (size < 0) {
amvdec_disable();
pr_err("get firmware fail.");
vfree(buf);
return -1;
}
if (amvdec_loadmc_ex(VFORMAT_REAL, NULL, buf) < 0) {
if (size == 1)
pr_info ("tee load ok");
else if (amvdec_loadmc_ex(VFORMAT_REAL, NULL, buf) < 0) {
amvdec_disable();
vfree(buf);
return -EBUSY;

View File

@@ -421,6 +421,26 @@ s32 optee_load_fw(enum vformat_e type, const char *name)
else if (!strcmp(name, "h263_mc"))
ret = tee_load_video_fw((u32)VIDEO_DEC_FORMAT_H263);
break;
default:
if (!strcmp(name, "vh265_mc"))
ret = tee_load_video_fw((u32)VIDEO_DEC_HEVC);
else if (!strcmp(name, "vh265_mc_mmu"))
ret = tee_load_video_fw((u32)VIDEO_DEC_HEVC_MMU);
else if (!strcmp(name, "vmpeg4_mc_311"))
ret = tee_load_video_fw((u32)VIDEO_DEC_MPEG4_3);
else if (!strcmp(name, "vmpeg4_mc_4"))
ret = tee_load_video_fw((u32)VIDEO_DEC_MPEG4_4);
else if (!strcmp(name, "vmpeg4_mc_5"))
ret = tee_load_video_fw((u32)VIDEO_DEC_MPEG4_5);
else if (!strcmp(name, "h263_mc"))
ret = tee_load_video_fw((u32)VIDEO_DEC_FORMAT_H263);
else if (!strcmp(name, "vreal_mc_8"))
ret = tee_load_video_fw((u32)VIDEO_DEC_REAL_V8);
else if (!strcmp(name, "vreal_mc_9"))
ret = tee_load_video_fw((u32)VIDEO_DEC_REAL_V9);
else
pr_info("unknow dec format\n");
break;
}
return ret;
}
@@ -428,7 +448,7 @@ EXPORT_SYMBOL(optee_load_fw);
s32 amvdec_loadmc_ex(enum vformat_e type, const char *name, char *def)
{
if (is_secload_get())
if (tee_enabled())
return optee_load_fw(type, name);
else
return am_loadmc_ex(type, name, def, &amvdec_loadmc);
@@ -617,7 +637,7 @@ static s32 amhevc_loadmc(const u32 *p)
s32 amhevc_loadmc_ex(enum vformat_e type, const char *name, char *def)
{
if (has_hevc_vdec())
if (is_secload_get())
if (tee_enabled())
return optee_load_fw(type, name);
else
return am_loadmc_ex(type, name, def, &amhevc_loadmc);
@@ -629,6 +649,9 @@ EXPORT_SYMBOL(amhevc_loadmc_ex);
s32 amhevc_vdec_loadmc_ex(struct vdec_s *vdec, const char *name, char *def)
{
if (has_hevc_vdec())
if (tee_enabled())
return optee_load_fw(FIRMWARE_MAX, name);
else
return am_vdec_loadmc_ex(vdec, name, def, &amhevc_loadmc);
else
return 0;

View File

@@ -65,7 +65,6 @@
#include <linux/amlogic/media/codec_mm/configs.h>
#include <linux/amlogic/media/frame_sync/ptsserv.h>
#include "secprot.h"
#include <linux/amlogic/tee.h>
static DEFINE_MUTEX(vdec_mutex);
@@ -78,7 +77,7 @@ static int keep_vdec_mem;
static unsigned int debug_trace_num = 16 * 20;
static int step_mode;
static unsigned int clk_config;
static int is_secload;
static int hevc_max_reset_count;
#define MAX_INSTANCE_MUN 9
@@ -3062,34 +3061,7 @@ static ssize_t dump_decoder_state_show(struct class *class,
return pbuf - buf;
}
int is_secload_get(void)
{
return is_secload;
}
EXPORT_SYMBOL(is_secload_get);
static ssize_t is_secload_show(struct class *cla,
struct class_attribute *attr,
char *buf)
{
return sprintf(buf, "%d\n", is_secload ? 1 : 0);
}
static ssize_t is_secload_store(struct class *cla,
struct class_attribute *attr,
const char *buf, size_t count)
{
size_t r;
int value;
r = sscanf(buf, "%d", &value);
if (r != 1)
return -EINVAL;
is_secload = value & tee_enabled();
return count;
}
static struct class_attribute vdec_class_attrs[] = {
__ATTR_RO(amrisc_regs),
@@ -3106,8 +3078,6 @@ static struct class_attribute vdec_class_attrs[] = {
__ATTR_RO(dump_vdec_blocks),
__ATTR_RO(dump_vdec_chunks),
__ATTR_RO(dump_decoder_state),
__ATTR(is_secload, S_IRUGO | S_IWUSR | S_IWGRP, is_secload_show,
is_secload_store),
__ATTR_NULL
};

View File

@@ -351,5 +351,4 @@ int vdec_get_debug_flags(void);
unsigned char is_mult_inc(unsigned int);
int is_secload_get(void);
#endif /* VDEC_H */

View File

@@ -1038,12 +1038,15 @@ static s32 vvc1_init(void)
size = get_firmware_data(VIDEO_DEC_VC1, buf);
if (size < 0) {
amvdec_disable();
pr_err("get firmware fail.");
vfree(buf);
return -1;
}
if (amvdec_loadmc_ex(VFORMAT_VC1, NULL, buf) < 0) {
if (size == 1)
pr_info ("tee load ok");
else if (amvdec_loadmc_ex(VFORMAT_VC1, NULL, buf) < 0) {
amvdec_disable();
vfree(buf);
return -EBUSY;

View File

@@ -6649,8 +6649,9 @@ static s32 vvp9_init(struct VP9Decoder_s *pbi)
#endif
amhevc_enable();
if (amhevc_loadmc_ex(VFORMAT_VP9, NULL, fw->data) < 0) {
if (size == 1)
pr_info ("tee load ok\n");
else if (amhevc_loadmc_ex(VFORMAT_VP9, NULL, fw->data) < 0) {
amhevc_disable();
vfree(fw);
return -EBUSY;

Binary file not shown.