Commit bdd03405 authored by ZhiChao Yu's avatar ZhiChao Yu Committed by Mauro Carvalho Chehab

media: hantro: Add support for VP8 decoding on rk3288

Introduce VP8 decoding support in RK3288.
Signed-off-by: default avatarZhiChao Yu <zhichao.yu@rock-chips.com>
Signed-off-by: default avatarTomasz Figa <tfiga@chromium.org>
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 298c62d3
......@@ -5,10 +5,12 @@ hantro-vpu-y += \
hantro_v4l2.o \
hantro_h1_jpeg_enc.o \
hantro_g1_mpeg2_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
hantro_jpeg.o \
hantro_mpeg2.o
hantro_mpeg2.o \
hantro_vp8.o
hantro-vpu-$(CONFIG_VIDEO_HANTRO_ROCKCHIP) += \
rk3288_vpu_hw.o \
......
......@@ -25,6 +25,10 @@
#include "hantro_hw.h"
#define VP8_MB_DIM 16
#define VP8_MB_WIDTH(w) DIV_ROUND_UP(w, VP8_MB_DIM)
#define VP8_MB_HEIGHT(h) DIV_ROUND_UP(h, VP8_MB_DIM)
#define MPEG2_MB_DIM 16
#define MPEG2_MB_WIDTH(w) DIV_ROUND_UP(w, MPEG2_MB_DIM)
#define MPEG2_MB_HEIGHT(h) DIV_ROUND_UP(h, MPEG2_MB_DIM)
......@@ -40,6 +44,7 @@ struct hantro_codec_ops;
#define HANTRO_ENCODERS 0x0000ffff
#define HANTRO_MPEG2_DECODER BIT(16)
#define HANTRO_VP8_DECODER BIT(17)
#define HANTRO_DECODERS 0xffff0000
/**
......@@ -97,11 +102,13 @@ struct hantro_variant {
* @HANTRO_MODE_NONE: No operating mode. Used for RAW video formats.
* @HANTRO_MODE_JPEG_ENC: JPEG encoder.
* @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
* @HANTRO_MODE_VP8_DEC: VP8 decoder.
*/
enum hantro_codec_mode {
HANTRO_MODE_NONE = -1,
HANTRO_MODE_JPEG_ENC,
HANTRO_MODE_MPEG2_DEC,
HANTRO_MODE_VP8_DEC,
};
/*
......@@ -215,6 +222,7 @@ struct hantro_dev {
* @codec_ops: Set of operations related to codec mode.
* @jpeg_enc: JPEG-encoding context.
* @mpeg2_dec: MPEG-2-decoding context.
* @vp8_dec: VP8-decoding context.
*/
struct hantro_ctx {
struct hantro_dev *dev;
......@@ -241,6 +249,7 @@ struct hantro_ctx {
union {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
};
};
......@@ -265,6 +274,12 @@ struct hantro_fmt {
struct v4l2_frmsize_stepwise frmsize;
};
struct hantro_reg {
u32 base;
u32 shift;
u32 mask;
};
/* Logging helpers */
/**
......@@ -343,6 +358,18 @@ static inline u32 vdpu_read(struct hantro_dev *vpu, u32 reg)
return val;
}
static inline void hantro_reg_write(struct hantro_dev *vpu,
const struct hantro_reg *reg,
u32 val)
{
u32 v;
v = vdpu_read(vpu, reg->base);
v &= ~(reg->mask << reg->shift);
v |= ((val & reg->mask) << reg->shift);
vdpu_write_relaxed(vpu, v, reg->base);
}
bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx);
void *hantro_get_ctrl(struct hantro_ctx *ctx, u32 id);
......
......@@ -284,6 +284,12 @@ static struct hantro_ctrl controls[] = {
.cfg = {
.elem_size = sizeof(struct v4l2_ctrl_mpeg2_quantization),
},
}, {
.id = V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER,
.codec = HANTRO_VP8_DECODER,
.cfg = {
.elem_size = sizeof(struct v4l2_ctrl_vp8_frame_header),
},
},
};
......
This diff is collapsed.
......@@ -12,6 +12,7 @@
#include <linux/interrupt.h>
#include <linux/v4l2-controls.h>
#include <media/mpeg2-ctrls.h>
#include <media/vp8-ctrls.h>
#include <media/videobuf2-core.h>
struct hantro_dev;
......@@ -47,6 +48,16 @@ struct hantro_mpeg2_dec_hw_ctx {
struct hantro_aux_buf qtable;
};
/**
* struct hantro_vp8d_hw_ctx
* @segment_map: Segment map buffer.
* @prob_tbl: Probability table buffer.
*/
struct hantro_vp8_dec_hw_ctx {
struct hantro_aux_buf segment_map;
struct hantro_aux_buf prob_tbl;
};
/**
* struct hantro_codec_ops - codec mode specific operations
*
......@@ -99,4 +110,10 @@ void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
int hantro_mpeg2_dec_init(struct hantro_ctx *ctx);
void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx);
void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx);
int hantro_vp8_dec_init(struct hantro_ctx *ctx);
void hantro_vp8_dec_exit(struct hantro_ctx *ctx);
void hantro_vp8_prob_update(struct hantro_ctx *ctx,
const struct v4l2_ctrl_vp8_frame_header *hdr);
#endif /* HANTRO_HW_H_ */
......@@ -344,6 +344,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 fourcc)
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = false;
break;
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
......
// SPDX-License-Identifier: GPL-2.0
/*
* Hantro VPU codec driver
*
* Copyright (C) 2018 Rockchip Electronics Co., Ltd.
*/
#include "hantro.h"
/*
* probs table with packed
*/
struct vp8_prob_tbl_packed {
u8 prob_mb_skip_false;
u8 prob_intra;
u8 prob_ref_last;
u8 prob_ref_golden;
u8 prob_segment[3];
u8 padding0;
u8 prob_luma_16x16_pred_mode[4];
u8 prob_chroma_pred_mode[3];
u8 padding1;
/* mv prob */
u8 prob_mv_context[2][19];
u8 padding2[2];
/* coeff probs */
u8 prob_coeffs[4][8][3][11];
u8 padding3[96];
};
void hantro_vp8_prob_update(struct hantro_ctx *ctx,
const struct v4l2_ctrl_vp8_frame_header *hdr)
{
const struct v4l2_vp8_entropy_header *entropy = &hdr->entropy_header;
u32 i, j, k;
u8 *dst;
/* first probs */
dst = ctx->vp8_dec.prob_tbl.cpu;
dst[0] = hdr->prob_skip_false;
dst[1] = hdr->prob_intra;
dst[2] = hdr->prob_last;
dst[3] = hdr->prob_gf;
dst[4] = hdr->segment_header.segment_probs[0];
dst[5] = hdr->segment_header.segment_probs[1];
dst[6] = hdr->segment_header.segment_probs[2];
dst[7] = 0;
dst += 8;
dst[0] = entropy->y_mode_probs[0];
dst[1] = entropy->y_mode_probs[1];
dst[2] = entropy->y_mode_probs[2];
dst[3] = entropy->y_mode_probs[3];
dst[4] = entropy->uv_mode_probs[0];
dst[5] = entropy->uv_mode_probs[1];
dst[6] = entropy->uv_mode_probs[2];
dst[7] = 0; /*unused */
/* mv probs */
dst += 8;
dst[0] = entropy->mv_probs[0][0]; /* is short */
dst[1] = entropy->mv_probs[1][0];
dst[2] = entropy->mv_probs[0][1]; /* sign */
dst[3] = entropy->mv_probs[1][1];
dst[4] = entropy->mv_probs[0][8 + 9];
dst[5] = entropy->mv_probs[0][9 + 9];
dst[6] = entropy->mv_probs[1][8 + 9];
dst[7] = entropy->mv_probs[1][9 + 9];
dst += 8;
for (i = 0; i < 2; ++i) {
for (j = 0; j < 8; j += 4) {
dst[0] = entropy->mv_probs[i][j + 9 + 0];
dst[1] = entropy->mv_probs[i][j + 9 + 1];
dst[2] = entropy->mv_probs[i][j + 9 + 2];
dst[3] = entropy->mv_probs[i][j + 9 + 3];
dst += 4;
}
}
for (i = 0; i < 2; ++i) {
dst[0] = entropy->mv_probs[i][0 + 2];
dst[1] = entropy->mv_probs[i][1 + 2];
dst[2] = entropy->mv_probs[i][2 + 2];
dst[3] = entropy->mv_probs[i][3 + 2];
dst[4] = entropy->mv_probs[i][4 + 2];
dst[5] = entropy->mv_probs[i][5 + 2];
dst[6] = entropy->mv_probs[i][6 + 2];
dst[7] = 0; /*unused */
dst += 8;
}
/* coeff probs (header part) */
dst = ctx->vp8_dec.prob_tbl.cpu;
dst += (8 * 7);
for (i = 0; i < 4; ++i) {
for (j = 0; j < 8; ++j) {
for (k = 0; k < 3; ++k) {
dst[0] = entropy->coeff_probs[i][j][k][0];
dst[1] = entropy->coeff_probs[i][j][k][1];
dst[2] = entropy->coeff_probs[i][j][k][2];
dst[3] = entropy->coeff_probs[i][j][k][3];
dst += 4;
}
}
}
/* coeff probs (footer part) */
dst = ctx->vp8_dec.prob_tbl.cpu;
dst += (8 * 55);
for (i = 0; i < 4; ++i) {
for (j = 0; j < 8; ++j) {
for (k = 0; k < 3; ++k) {
dst[0] = entropy->coeff_probs[i][j][k][4];
dst[1] = entropy->coeff_probs[i][j][k][5];
dst[2] = entropy->coeff_probs[i][j][k][6];
dst[3] = entropy->coeff_probs[i][j][k][7];
dst[4] = entropy->coeff_probs[i][j][k][8];
dst[5] = entropy->coeff_probs[i][j][k][9];
dst[6] = entropy->coeff_probs[i][j][k][10];
dst[7] = 0; /*unused */
dst += 8;
}
}
}
}
int hantro_vp8_dec_init(struct hantro_ctx *ctx)
{
struct hantro_dev *vpu = ctx->dev;
struct hantro_aux_buf *aux_buf;
unsigned int mb_width, mb_height;
size_t segment_map_size;
int ret;
/* segment map table size calculation */
mb_width = DIV_ROUND_UP(ctx->dst_fmt.width, 16);
mb_height = DIV_ROUND_UP(ctx->dst_fmt.height, 16);
segment_map_size = round_up(DIV_ROUND_UP(mb_width * mb_height, 4), 64);
/*
* In context init the dma buffer for segment map must be allocated.
* And the data in segment map buffer must be set to all zero.
*/
aux_buf = &ctx->vp8_dec.segment_map;
aux_buf->size = segment_map_size;
aux_buf->cpu = dma_alloc_coherent(vpu->dev, aux_buf->size,
&aux_buf->dma, GFP_KERNEL);
if (!aux_buf->cpu)
return -ENOMEM;
memset(aux_buf->cpu, 0, aux_buf->size);
/*
* Allocate probability table buffer,
* total 1208 bytes, 4K page is far enough.
*/
aux_buf = &ctx->vp8_dec.prob_tbl;
aux_buf->size = sizeof(struct vp8_prob_tbl_packed);
aux_buf->cpu = dma_alloc_coherent(vpu->dev, aux_buf->size,
&aux_buf->dma, GFP_KERNEL);
if (!aux_buf->cpu) {
ret = -ENOMEM;
goto err_free_seg_map;
}
return 0;
err_free_seg_map:
dma_free_coherent(vpu->dev, ctx->vp8_dec.segment_map.size,
ctx->vp8_dec.segment_map.cpu,
ctx->vp8_dec.segment_map.dma);
return ret;
}
void hantro_vp8_dec_exit(struct hantro_ctx *ctx)
{
struct hantro_vp8_dec_hw_ctx *vp8_dec = &ctx->vp8_dec;
struct hantro_dev *vpu = ctx->dev;
dma_free_coherent(vpu->dev, vp8_dec->segment_map.size,
vp8_dec->segment_map.cpu, vp8_dec->segment_map.dma);
dma_free_coherent(vpu->dev, vp8_dec->prob_tbl.size,
vp8_dec->prob_tbl.cpu, vp8_dec->prob_tbl.dma);
}
......@@ -74,6 +74,19 @@ static const struct hantro_fmt rk3288_vpu_dec_fmts[] = {
.step_height = MPEG2_MB_DIM,
},
},
{
.fourcc = V4L2_PIX_FMT_VP8_FRAME,
.codec_mode = HANTRO_MODE_VP8_DEC,
.max_depth = 2,
.frmsize = {
.min_width = 48,
.max_width = 3840,
.step_width = VP8_MB_DIM,
.min_height = 48,
.max_height = 2160,
.step_height = VP8_MB_DIM,
},
},
};
static irqreturn_t rk3288_vepu_irq(int irq, void *dev_id)
......@@ -155,6 +168,12 @@ static const struct hantro_codec_ops rk3288_vpu_codec_ops[] = {
.init = hantro_mpeg2_dec_init,
.exit = hantro_mpeg2_dec_exit,
},
[HANTRO_MODE_VP8_DEC] = {
.run = hantro_g1_vp8_dec_run,
.reset = rk3288_vpu_dec_reset,
.init = hantro_vp8_dec_init,
.exit = hantro_vp8_dec_exit,
},
};
/*
......@@ -177,7 +196,8 @@ const struct hantro_variant rk3288_vpu_variant = {
.dec_offset = 0x400,
.dec_fmts = rk3288_vpu_dec_fmts,
.num_dec_fmts = ARRAY_SIZE(rk3288_vpu_dec_fmts),
.codec = HANTRO_JPEG_ENCODER | HANTRO_MPEG2_DECODER,
.codec = HANTRO_JPEG_ENCODER | HANTRO_MPEG2_DECODER |
HANTRO_VP8_DECODER,
.codec_ops = rk3288_vpu_codec_ops,
.irqs = rk3288_irqs,
.num_irqs = ARRAY_SIZE(rk3288_irqs),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment