media: mtk-vcodec: abstract firmware interface
MT8183's codec firmware is run by a different remote processor from MT8173. While the firmware interface is basically the same, the way to invoke it differs. Abstract all firmware calls under a layer that will allow us to handle both firmware types transparently. [acourbot: refactor, cleanup and split] [pihsun: fix error path and add mtk_vcodec_fw_release] [hverkuil: fixed some checkpatch alignment warnings] [hverkuil: fixed merge conflicts] Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com> Co-developed-by: Alexandre Courbot <acourbot@chromium.org> Signed-off-by: Alexandre Courbot <acourbot@chromium.org> Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org> Reviewed-by: Tiffany Lin <tiffany.lin@mediatek.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
parent
cbd2dca749
commit
bf1d556ad4
@ -13,7 +13,6 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
|
||||
mtk_vcodec_dec.o \
|
||||
mtk_vcodec_dec_pm.o \
|
||||
|
||||
|
||||
mtk-vcodec-enc-y := venc/venc_vp8_if.o \
|
||||
venc/venc_h264_if.o \
|
||||
mtk_vcodec_enc.o \
|
||||
@ -24,6 +23,5 @@ mtk-vcodec-enc-y := venc/venc_vp8_if.o \
|
||||
|
||||
|
||||
mtk-vcodec-common-y := mtk_vcodec_intr.o \
|
||||
mtk_vcodec_util.o\
|
||||
|
||||
ccflags-y += -I$(srctree)/drivers/media/platform/mtk-vpu
|
||||
mtk_vcodec_util.o \
|
||||
mtk_vcodec_fw.o
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "mtk_vcodec_dec_pm.h"
|
||||
#include "mtk_vcodec_intr.h"
|
||||
#include "mtk_vcodec_util.h"
|
||||
#include "mtk_vpu.h"
|
||||
#include "mtk_vcodec_fw.h"
|
||||
|
||||
#define VDEC_HW_ACTIVE 0x10
|
||||
#define VDEC_IRQ_CFG 0x11
|
||||
@ -77,22 +77,6 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void mtk_vcodec_dec_reset_handler(void *priv)
|
||||
{
|
||||
struct mtk_vcodec_dev *dev = priv;
|
||||
struct mtk_vcodec_ctx *ctx;
|
||||
|
||||
mtk_v4l2_err("Watchdog timeout!!");
|
||||
|
||||
mutex_lock(&dev->dev_mutex);
|
||||
list_for_each_entry(ctx, &dev->ctx_list, list) {
|
||||
ctx->state = MTK_STATE_ABORT;
|
||||
mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ERROR",
|
||||
ctx->id);
|
||||
}
|
||||
mutex_unlock(&dev->dev_mutex);
|
||||
}
|
||||
|
||||
static int fops_vcodec_open(struct file *file)
|
||||
{
|
||||
struct mtk_vcodec_dev *dev = video_drvdata(file);
|
||||
@ -144,21 +128,20 @@ static int fops_vcodec_open(struct file *file)
|
||||
if (v4l2_fh_is_singular(&ctx->fh)) {
|
||||
mtk_vcodec_dec_pw_on(&dev->pm);
|
||||
/*
|
||||
* vpu_load_firmware checks if it was loaded already and
|
||||
* does nothing in that case
|
||||
* Does nothing if firmware was already loaded.
|
||||
*/
|
||||
ret = vpu_load_firmware(dev->vpu_plat_dev);
|
||||
ret = mtk_vcodec_fw_load_firmware(dev->fw_handler);
|
||||
if (ret < 0) {
|
||||
/*
|
||||
* Return 0 if downloading firmware successfully,
|
||||
* otherwise it is failed
|
||||
*/
|
||||
mtk_v4l2_err("vpu_load_firmware failed!");
|
||||
mtk_v4l2_err("failed to load firmware!");
|
||||
goto err_load_fw;
|
||||
}
|
||||
|
||||
dev->dec_capability =
|
||||
vpu_get_vdec_hw_capa(dev->vpu_plat_dev);
|
||||
mtk_vcodec_fw_get_vdec_capa(dev->fw_handler);
|
||||
mtk_v4l2_debug(0, "decoder capability %x", dev->dec_capability);
|
||||
}
|
||||
|
||||
@ -228,6 +211,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
|
||||
struct mtk_vcodec_dev *dev;
|
||||
struct video_device *vfd_dec;
|
||||
struct resource *res;
|
||||
phandle rproc_phandle;
|
||||
enum mtk_vcodec_fw_type fw_type;
|
||||
int i, ret;
|
||||
|
||||
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
|
||||
@ -237,10 +222,12 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
|
||||
INIT_LIST_HEAD(&dev->ctx_list);
|
||||
dev->plat_dev = pdev;
|
||||
|
||||
dev->vpu_plat_dev = vpu_get_plat_device(dev->plat_dev);
|
||||
if (dev->vpu_plat_dev == NULL) {
|
||||
mtk_v4l2_err("[VPU] vpu device in not ready");
|
||||
return -EPROBE_DEFER;
|
||||
if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu",
|
||||
&rproc_phandle)) {
|
||||
fw_type = VPU;
|
||||
} else {
|
||||
mtk_v4l2_err("Could not get vdec IPI device");
|
||||
return -ENODEV;
|
||||
}
|
||||
if (!pdev->dev.dma_parms) {
|
||||
pdev->dev.dma_parms = devm_kzalloc(&pdev->dev,
|
||||
@ -251,13 +238,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
|
||||
}
|
||||
dma_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
|
||||
|
||||
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_dec_reset_handler,
|
||||
dev, VPU_RST_DEC);
|
||||
dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, VPU_RST_DEC);
|
||||
if (IS_ERR(dev->fw_handler))
|
||||
return PTR_ERR(dev->fw_handler);
|
||||
|
||||
ret = mtk_vcodec_init_dec_pm(dev);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Failed to get mt vcodec clock source");
|
||||
return ret;
|
||||
goto err_dec_pm;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_MAX_VDEC_REG_BASE; i++) {
|
||||
@ -360,6 +348,8 @@ err_dec_alloc:
|
||||
v4l2_device_unregister(&dev->v4l2_dev);
|
||||
err_res:
|
||||
mtk_vcodec_release_dec_pm(dev);
|
||||
err_dec_pm:
|
||||
mtk_vcodec_fw_release(dev->fw_handler);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -384,6 +374,7 @@ static int mtk_vcodec_dec_remove(struct platform_device *pdev)
|
||||
|
||||
v4l2_device_unregister(&dev->v4l2_dev);
|
||||
mtk_vcodec_release_dec_pm(dev);
|
||||
mtk_vcodec_fw_release(dev->fw_handler);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include "mtk_vcodec_dec_pm.h"
|
||||
#include "mtk_vcodec_util.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
|
||||
{
|
||||
|
@ -309,13 +309,13 @@ struct mtk_vcodec_ctx {
|
||||
* @m2m_dev_dec: m2m device for decoder
|
||||
* @m2m_dev_enc: m2m device for encoder.
|
||||
* @plat_dev: platform device
|
||||
* @vpu_plat_dev: mtk vpu platform device
|
||||
* @ctx_list: list of struct mtk_vcodec_ctx
|
||||
* @irqlock: protect data access by irq handler and work thread
|
||||
* @curr_ctx: The context that is waiting for codec hardware
|
||||
*
|
||||
* @reg_base: Mapped address of MTK Vcodec registers.
|
||||
*
|
||||
* @fw_handler: used to communicate with the firmware.
|
||||
* @id_counter: used to identify current opened instance
|
||||
*
|
||||
* @encode_workqueue: encode work queue
|
||||
@ -344,12 +344,13 @@ struct mtk_vcodec_dev {
|
||||
struct v4l2_m2m_dev *m2m_dev_dec;
|
||||
struct v4l2_m2m_dev *m2m_dev_enc;
|
||||
struct platform_device *plat_dev;
|
||||
struct platform_device *vpu_plat_dev;
|
||||
struct list_head ctx_list;
|
||||
spinlock_t irqlock;
|
||||
struct mtk_vcodec_ctx *curr_ctx;
|
||||
void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
|
||||
|
||||
struct mtk_vcodec_fw *fw_handler;
|
||||
|
||||
unsigned long id_counter;
|
||||
|
||||
struct workqueue_struct *decode_workqueue;
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "mtk_vcodec_enc_pm.h"
|
||||
#include "mtk_vcodec_intr.h"
|
||||
#include "mtk_vcodec_util.h"
|
||||
#include "mtk_vpu.h"
|
||||
#include "mtk_vcodec_fw.h"
|
||||
|
||||
module_param(mtk_v4l2_dbg_level, int, S_IRUGO | S_IWUSR);
|
||||
module_param(mtk_vcodec_dbg, bool, S_IRUGO | S_IWUSR);
|
||||
@ -101,22 +101,6 @@ static irqreturn_t mtk_vcodec_enc_lt_irq_handler(int irq, void *priv)
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void mtk_vcodec_enc_reset_handler(void *priv)
|
||||
{
|
||||
struct mtk_vcodec_dev *dev = priv;
|
||||
struct mtk_vcodec_ctx *ctx;
|
||||
|
||||
mtk_v4l2_debug(0, "Watchdog timeout!!");
|
||||
|
||||
mutex_lock(&dev->dev_mutex);
|
||||
list_for_each_entry(ctx, &dev->ctx_list, list) {
|
||||
ctx->state = MTK_STATE_ABORT;
|
||||
mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ABORT",
|
||||
ctx->id);
|
||||
}
|
||||
mutex_unlock(&dev->dev_mutex);
|
||||
}
|
||||
|
||||
static int fops_vcodec_open(struct file *file)
|
||||
{
|
||||
struct mtk_vcodec_dev *dev = video_drvdata(file);
|
||||
@ -159,10 +143,10 @@ static int fops_vcodec_open(struct file *file)
|
||||
|
||||
if (v4l2_fh_is_singular(&ctx->fh)) {
|
||||
/*
|
||||
* vpu_load_firmware checks if it was loaded already and
|
||||
* load fireware to checks if it was loaded already and
|
||||
* does nothing in that case
|
||||
*/
|
||||
ret = vpu_load_firmware(dev->vpu_plat_dev);
|
||||
ret = mtk_vcodec_fw_load_firmware(dev->fw_handler);
|
||||
if (ret < 0) {
|
||||
/*
|
||||
* Return 0 if downloading firmware successfully,
|
||||
@ -173,7 +157,7 @@ static int fops_vcodec_open(struct file *file)
|
||||
}
|
||||
|
||||
dev->enc_capability =
|
||||
vpu_get_venc_hw_capa(dev->vpu_plat_dev);
|
||||
mtk_vcodec_fw_get_venc_capa(dev->fw_handler);
|
||||
mtk_v4l2_debug(0, "encoder capability %x", dev->enc_capability);
|
||||
}
|
||||
|
||||
@ -235,6 +219,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
|
||||
struct mtk_vcodec_dev *dev;
|
||||
struct video_device *vfd_enc;
|
||||
struct resource *res;
|
||||
phandle rproc_phandle;
|
||||
enum mtk_vcodec_fw_type fw_type;
|
||||
int i, j, ret;
|
||||
|
||||
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
|
||||
@ -244,10 +230,12 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
|
||||
INIT_LIST_HEAD(&dev->ctx_list);
|
||||
dev->plat_dev = pdev;
|
||||
|
||||
dev->vpu_plat_dev = vpu_get_plat_device(dev->plat_dev);
|
||||
if (dev->vpu_plat_dev == NULL) {
|
||||
mtk_v4l2_err("[VPU] vpu device in not ready");
|
||||
return -EPROBE_DEFER;
|
||||
if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu",
|
||||
&rproc_phandle)) {
|
||||
fw_type = VPU;
|
||||
} else {
|
||||
mtk_v4l2_err("Could not get venc IPI device");
|
||||
return -ENODEV;
|
||||
}
|
||||
if (!pdev->dev.dma_parms) {
|
||||
pdev->dev.dma_parms = devm_kzalloc(&pdev->dev,
|
||||
@ -258,13 +246,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
|
||||
}
|
||||
dma_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
|
||||
|
||||
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_enc_reset_handler,
|
||||
dev, VPU_RST_ENC);
|
||||
dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, VPU_RST_ENC);
|
||||
if (IS_ERR(dev->fw_handler))
|
||||
return PTR_ERR(dev->fw_handler);
|
||||
|
||||
ret = mtk_vcodec_init_enc_pm(dev);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Failed to get mt vcodec clock source!");
|
||||
return ret;
|
||||
goto err_enc_pm;
|
||||
}
|
||||
|
||||
for (i = VENC_SYS, j = 0; i < NUM_MAX_VCODEC_REG_BASE; i++, j++) {
|
||||
@ -385,6 +374,8 @@ err_enc_alloc:
|
||||
v4l2_device_unregister(&dev->v4l2_dev);
|
||||
err_res:
|
||||
mtk_vcodec_release_enc_pm(dev);
|
||||
err_enc_pm:
|
||||
mtk_vcodec_fw_release(dev->fw_handler);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -409,6 +400,7 @@ static int mtk_vcodec_enc_remove(struct platform_device *pdev)
|
||||
|
||||
v4l2_device_unregister(&dev->v4l2_dev);
|
||||
mtk_vcodec_release_enc_pm(dev);
|
||||
mtk_vcodec_fw_release(dev->fw_handler);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
#include "mtk_vcodec_enc_pm.h"
|
||||
#include "mtk_vcodec_util.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
|
||||
int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
|
||||
{
|
||||
|
174
drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c
Normal file
174
drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c
Normal file
@ -0,0 +1,174 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include "mtk_vcodec_fw.h"
|
||||
#include "mtk_vcodec_util.h"
|
||||
#include "mtk_vcodec_drv.h"
|
||||
|
||||
struct mtk_vcodec_fw_ops {
|
||||
int (*load_firmware)(struct mtk_vcodec_fw *fw);
|
||||
unsigned int (*get_vdec_capa)(struct mtk_vcodec_fw *fw);
|
||||
unsigned int (*get_venc_capa)(struct mtk_vcodec_fw *fw);
|
||||
void * (*map_dm_addr)(struct mtk_vcodec_fw *fw, u32 dtcm_dmem_addr);
|
||||
int (*ipi_register)(struct mtk_vcodec_fw *fw, int id,
|
||||
mtk_vcodec_ipi_handler handler, const char *name, void *priv);
|
||||
int (*ipi_send)(struct mtk_vcodec_fw *fw, int id, void *buf,
|
||||
unsigned int len, unsigned int wait);
|
||||
};
|
||||
|
||||
struct mtk_vcodec_fw {
|
||||
enum mtk_vcodec_fw_type type;
|
||||
const struct mtk_vcodec_fw_ops *ops;
|
||||
struct platform_device *pdev;
|
||||
};
|
||||
|
||||
static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw)
|
||||
{
|
||||
return vpu_load_firmware(fw->pdev);
|
||||
}
|
||||
|
||||
static unsigned int mtk_vcodec_vpu_get_vdec_capa(struct mtk_vcodec_fw *fw)
|
||||
{
|
||||
return vpu_get_vdec_hw_capa(fw->pdev);
|
||||
}
|
||||
|
||||
static unsigned int mtk_vcodec_vpu_get_venc_capa(struct mtk_vcodec_fw *fw)
|
||||
{
|
||||
return vpu_get_venc_hw_capa(fw->pdev);
|
||||
}
|
||||
|
||||
static void *mtk_vcodec_vpu_map_dm_addr(struct mtk_vcodec_fw *fw,
|
||||
u32 dtcm_dmem_addr)
|
||||
{
|
||||
return vpu_mapping_dm_addr(fw->pdev, dtcm_dmem_addr);
|
||||
}
|
||||
|
||||
static int mtk_vcodec_vpu_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
|
||||
mtk_vcodec_ipi_handler handler,
|
||||
const char *name, void *priv)
|
||||
{
|
||||
/*
|
||||
* The handler we receive takes a void * as its first argument. We
|
||||
* cannot change this because it needs to be passed down to the rproc
|
||||
* subsystem when SCP is used. VPU takes a const argument, which is
|
||||
* more constrained, so the conversion below is safe.
|
||||
*/
|
||||
ipi_handler_t handler_const = (ipi_handler_t)handler;
|
||||
|
||||
return vpu_ipi_register(fw->pdev, id, handler_const, name, priv);
|
||||
}
|
||||
|
||||
static int mtk_vcodec_vpu_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
|
||||
unsigned int len, unsigned int wait)
|
||||
{
|
||||
return vpu_ipi_send(fw->pdev, id, buf, len);
|
||||
}
|
||||
|
||||
static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = {
|
||||
.load_firmware = mtk_vcodec_vpu_load_firmware,
|
||||
.get_vdec_capa = mtk_vcodec_vpu_get_vdec_capa,
|
||||
.get_venc_capa = mtk_vcodec_vpu_get_venc_capa,
|
||||
.map_dm_addr = mtk_vcodec_vpu_map_dm_addr,
|
||||
.ipi_register = mtk_vcodec_vpu_set_ipi_register,
|
||||
.ipi_send = mtk_vcodec_vpu_ipi_send,
|
||||
};
|
||||
|
||||
static void mtk_vcodec_reset_handler(void *priv)
|
||||
{
|
||||
struct mtk_vcodec_dev *dev = priv;
|
||||
struct mtk_vcodec_ctx *ctx;
|
||||
|
||||
mtk_v4l2_err("Watchdog timeout!!");
|
||||
|
||||
mutex_lock(&dev->dev_mutex);
|
||||
list_for_each_entry(ctx, &dev->ctx_list, list) {
|
||||
ctx->state = MTK_STATE_ABORT;
|
||||
mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ABORT",
|
||||
ctx->id);
|
||||
}
|
||||
mutex_unlock(&dev->dev_mutex);
|
||||
}
|
||||
|
||||
struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev,
|
||||
enum mtk_vcodec_fw_type type,
|
||||
enum rst_id rst_id)
|
||||
{
|
||||
const struct mtk_vcodec_fw_ops *ops;
|
||||
struct mtk_vcodec_fw *fw;
|
||||
struct platform_device *fw_pdev = NULL;
|
||||
|
||||
switch (type) {
|
||||
case VPU:
|
||||
ops = &mtk_vcodec_vpu_msg;
|
||||
fw_pdev = vpu_get_plat_device(dev->plat_dev);
|
||||
if (!fw_pdev) {
|
||||
mtk_v4l2_err("firmware device is not ready");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_reset_handler,
|
||||
dev, rst_id);
|
||||
break;
|
||||
default:
|
||||
mtk_v4l2_err("invalid vcodec fw type");
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
fw = devm_kzalloc(&dev->plat_dev->dev, sizeof(*fw), GFP_KERNEL);
|
||||
if (!fw)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
fw->type = type;
|
||||
fw->ops = ops;
|
||||
fw->pdev = fw_pdev;
|
||||
|
||||
return fw;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_select);
|
||||
|
||||
void mtk_vcodec_fw_release(struct mtk_vcodec_fw *fw)
|
||||
{
|
||||
switch (fw->type) {
|
||||
case VPU:
|
||||
put_device(&fw->pdev->dev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_release);
|
||||
|
||||
int mtk_vcodec_fw_load_firmware(struct mtk_vcodec_fw *fw)
|
||||
{
|
||||
return fw->ops->load_firmware(fw);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_load_firmware);
|
||||
|
||||
unsigned int mtk_vcodec_fw_get_vdec_capa(struct mtk_vcodec_fw *fw)
|
||||
{
|
||||
return fw->ops->get_vdec_capa(fw);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_get_vdec_capa);
|
||||
|
||||
unsigned int mtk_vcodec_fw_get_venc_capa(struct mtk_vcodec_fw *fw)
|
||||
{
|
||||
return fw->ops->get_venc_capa(fw);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_get_venc_capa);
|
||||
|
||||
void *mtk_vcodec_fw_map_dm_addr(struct mtk_vcodec_fw *fw, u32 mem_addr)
|
||||
{
|
||||
return fw->ops->map_dm_addr(fw, mem_addr);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_map_dm_addr);
|
||||
|
||||
int mtk_vcodec_fw_ipi_register(struct mtk_vcodec_fw *fw, int id,
|
||||
mtk_vcodec_ipi_handler handler,
|
||||
const char *name, void *priv)
|
||||
{
|
||||
return fw->ops->ipi_register(fw, id, handler, name, priv);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_ipi_register);
|
||||
|
||||
int mtk_vcodec_fw_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
|
||||
unsigned int len, unsigned int wait)
|
||||
{
|
||||
return fw->ops->ipi_send(fw, id, buf, len, wait);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_ipi_send);
|
36
drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h
Normal file
36
drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
#ifndef _MTK_VCODEC_FW_H_
|
||||
#define _MTK_VCODEC_FW_H_
|
||||
|
||||
#include <linux/remoteproc.h>
|
||||
|
||||
#include "../mtk-vpu/mtk_vpu.h"
|
||||
|
||||
struct mtk_vcodec_dev;
|
||||
|
||||
enum mtk_vcodec_fw_type {
|
||||
VPU,
|
||||
};
|
||||
|
||||
struct mtk_vcodec_fw;
|
||||
|
||||
typedef void (*mtk_vcodec_ipi_handler) (void *data,
|
||||
unsigned int len, void *priv);
|
||||
|
||||
struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev,
|
||||
enum mtk_vcodec_fw_type type,
|
||||
enum rst_id rst_id);
|
||||
void mtk_vcodec_fw_release(struct mtk_vcodec_fw *fw);
|
||||
|
||||
int mtk_vcodec_fw_load_firmware(struct mtk_vcodec_fw *fw);
|
||||
unsigned int mtk_vcodec_fw_get_vdec_capa(struct mtk_vcodec_fw *fw);
|
||||
unsigned int mtk_vcodec_fw_get_venc_capa(struct mtk_vcodec_fw *fw);
|
||||
void *mtk_vcodec_fw_map_dm_addr(struct mtk_vcodec_fw *fw, u32 mem_addr);
|
||||
int mtk_vcodec_fw_ipi_register(struct mtk_vcodec_fw *fw, int id,
|
||||
mtk_vcodec_ipi_handler handler,
|
||||
const char *name, void *priv);
|
||||
int mtk_vcodec_fw_ipi_send(struct mtk_vcodec_fw *fw, int id,
|
||||
void *buf, unsigned int len, unsigned int wait);
|
||||
|
||||
#endif /* _MTK_VCODEC_FW_H_ */
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "mtk_vcodec_drv.h"
|
||||
#include "mtk_vcodec_util.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
/* For encoder, this will enable logs in venc/*/
|
||||
bool mtk_vcodec_dbg;
|
||||
|
@ -281,7 +281,6 @@ static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)
|
||||
inst->ctx = ctx;
|
||||
|
||||
inst->vpu.id = IPI_VDEC_H264;
|
||||
inst->vpu.dev = ctx->dev->vpu_plat_dev;
|
||||
inst->vpu.ctx = ctx;
|
||||
|
||||
err = vpu_dec_init(&inst->vpu);
|
||||
|
@ -400,7 +400,6 @@ static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx)
|
||||
inst->ctx = ctx;
|
||||
|
||||
inst->vpu.id = IPI_VDEC_VP8;
|
||||
inst->vpu.dev = ctx->dev->vpu_plat_dev;
|
||||
inst->vpu.ctx = ctx;
|
||||
|
||||
err = vpu_dec_init(&inst->vpu);
|
||||
|
@ -795,7 +795,6 @@ static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx)
|
||||
inst->ctx = ctx;
|
||||
|
||||
inst->vpu.id = IPI_VDEC_VP9;
|
||||
inst->vpu.dev = ctx->dev->vpu_plat_dev;
|
||||
inst->vpu.ctx = ctx;
|
||||
|
||||
if (vpu_dec_init(&inst->vpu)) {
|
||||
|
@ -7,8 +7,6 @@
|
||||
#ifndef _VDEC_DRV_BASE_
|
||||
#define _VDEC_DRV_BASE_
|
||||
|
||||
#include "mtk_vcodec_drv.h"
|
||||
|
||||
#include "vdec_drv_if.h"
|
||||
|
||||
struct vdec_common_if {
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "mtk_vcodec_dec.h"
|
||||
#include "vdec_drv_base.h"
|
||||
#include "mtk_vcodec_dec_pm.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
|
||||
{
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "mtk_vcodec_util.h"
|
||||
#include "vdec_ipi_msg.h"
|
||||
#include "vdec_vpu_if.h"
|
||||
#include "mtk_vcodec_fw.h"
|
||||
|
||||
static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)
|
||||
{
|
||||
@ -18,7 +19,8 @@ static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)
|
||||
|
||||
/* mapping VPU address to kernel virtual address */
|
||||
/* the content in vsi is initialized to 0 in VPU */
|
||||
vpu->vsi = vpu_mapping_dm_addr(vpu->dev, msg->vpu_inst_addr);
|
||||
vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler,
|
||||
msg->vpu_inst_addr);
|
||||
vpu->inst_addr = msg->vpu_inst_addr;
|
||||
|
||||
mtk_vcodec_debug(vpu, "- vpu_inst_addr = 0x%x", vpu->inst_addr);
|
||||
@ -34,7 +36,7 @@ static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)
|
||||
* This function runs in interrupt context and it means there's an IPI MSG
|
||||
* from VPU.
|
||||
*/
|
||||
static void vpu_dec_ipi_handler(const void *data, unsigned int len, void *priv)
|
||||
static void vpu_dec_ipi_handler(void *data, unsigned int len, void *priv)
|
||||
{
|
||||
const struct vdec_vpu_ipi_ack *msg = data;
|
||||
struct vdec_vpu_inst *vpu = (struct vdec_vpu_inst *)
|
||||
@ -74,7 +76,8 @@ static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len)
|
||||
vpu->failure = 0;
|
||||
vpu->signaled = 0;
|
||||
|
||||
err = vpu_ipi_send(vpu->dev, vpu->id, msg, len);
|
||||
err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, vpu->id, msg,
|
||||
len, 2000);
|
||||
if (err) {
|
||||
mtk_vcodec_err(vpu, "send fail vpu_id=%d msg_id=%X status=%d",
|
||||
vpu->id, *(uint32_t *)msg, err);
|
||||
@ -110,7 +113,8 @@ int vpu_dec_init(struct vdec_vpu_inst *vpu)
|
||||
init_waitqueue_head(&vpu->wq);
|
||||
vpu->handler = vpu_dec_ipi_handler;
|
||||
|
||||
err = vpu_ipi_register(vpu->dev, vpu->id, vpu->handler, "vdec", NULL);
|
||||
err = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->id,
|
||||
vpu->handler, "vdec", NULL);
|
||||
if (err != 0) {
|
||||
mtk_vcodec_err(vpu, "vpu_ipi_register fail status=%d", err);
|
||||
return err;
|
||||
|
@ -7,11 +7,13 @@
|
||||
#ifndef _VDEC_VPU_IF_H_
|
||||
#define _VDEC_VPU_IF_H_
|
||||
|
||||
#include "mtk_vpu.h"
|
||||
#include "mtk_vcodec_fw.h"
|
||||
|
||||
struct mtk_vcodec_ctx;
|
||||
|
||||
/**
|
||||
* struct vdec_vpu_inst - VPU instance for video codec
|
||||
* @ipi_id : ipi id for each decoder
|
||||
* @id : ipi msg id for each decoder
|
||||
* @vsi : driver structure allocated by VPU side and shared to AP side
|
||||
* for control and info share
|
||||
* @failure : VPU execution result status, 0: success, others: fail
|
||||
@ -23,15 +25,14 @@
|
||||
* @handler : ipi handler for each decoder
|
||||
*/
|
||||
struct vdec_vpu_inst {
|
||||
enum ipi_id id;
|
||||
int id;
|
||||
void *vsi;
|
||||
int32_t failure;
|
||||
uint32_t inst_addr;
|
||||
unsigned int signaled;
|
||||
struct mtk_vcodec_ctx *ctx;
|
||||
struct platform_device *dev;
|
||||
wait_queue_head_t wq;
|
||||
ipi_handler_t handler;
|
||||
mtk_vcodec_ipi_handler handler;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "../venc_drv_base.h"
|
||||
#include "../venc_ipi_msg.h"
|
||||
#include "../venc_vpu_if.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
static const char h264_filler_marker[] = {0x0, 0x0, 0x0, 0x1, 0xc};
|
||||
|
||||
@ -257,8 +256,11 @@ static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst)
|
||||
*/
|
||||
inst->work_bufs[i].size = wb[i].size;
|
||||
if (i == VENC_H264_VPU_WORK_BUF_SKIP_FRAME) {
|
||||
inst->work_bufs[i].va = vpu_mapping_dm_addr(
|
||||
inst->vpu_inst.dev, wb[i].vpua);
|
||||
struct mtk_vcodec_fw *handler;
|
||||
|
||||
handler = inst->vpu_inst.ctx->dev->fw_handler;
|
||||
inst->work_bufs[i].va =
|
||||
mtk_vcodec_fw_map_dm_addr(handler, wb[i].vpua);
|
||||
inst->work_bufs[i].dma_addr = 0;
|
||||
} else {
|
||||
ret = mtk_vcodec_mem_alloc(inst->ctx,
|
||||
@ -275,10 +277,12 @@ static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst)
|
||||
* setting in VPU side.
|
||||
*/
|
||||
if (i == VENC_H264_VPU_WORK_BUF_RC_CODE) {
|
||||
struct mtk_vcodec_fw *handler;
|
||||
void *tmp_va;
|
||||
|
||||
tmp_va = vpu_mapping_dm_addr(inst->vpu_inst.dev,
|
||||
wb[i].vpua);
|
||||
handler = inst->vpu_inst.ctx->dev->fw_handler;
|
||||
tmp_va = mtk_vcodec_fw_map_dm_addr(handler,
|
||||
wb[i].vpua);
|
||||
memcpy(inst->work_bufs[i].va, tmp_va,
|
||||
wb[i].size);
|
||||
}
|
||||
@ -469,7 +473,6 @@ static int h264_enc_init(struct mtk_vcodec_ctx *ctx)
|
||||
|
||||
inst->ctx = ctx;
|
||||
inst->vpu_inst.ctx = ctx;
|
||||
inst->vpu_inst.dev = ctx->dev->vpu_plat_dev;
|
||||
inst->vpu_inst.id = IPI_VENC_H264;
|
||||
inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx, VENC_SYS);
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "../venc_drv_base.h"
|
||||
#include "../venc_ipi_msg.h"
|
||||
#include "../venc_vpu_if.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
#define VENC_BITSTREAM_FRAME_SIZE 0x0098
|
||||
#define VENC_BITSTREAM_HEADER_LEN 0x00e8
|
||||
@ -190,10 +189,12 @@ static int vp8_enc_alloc_work_buf(struct venc_vp8_inst *inst)
|
||||
if (i == VENC_VP8_VPU_WORK_BUF_RC_CODE ||
|
||||
i == VENC_VP8_VPU_WORK_BUF_RC_CODE2 ||
|
||||
i == VENC_VP8_VPU_WORK_BUF_RC_CODE3) {
|
||||
struct mtk_vcodec_fw *handler;
|
||||
void *tmp_va;
|
||||
|
||||
tmp_va = vpu_mapping_dm_addr(inst->vpu_inst.dev,
|
||||
wb[i].vpua);
|
||||
handler = inst->vpu_inst.ctx->dev->fw_handler;
|
||||
tmp_va = mtk_vcodec_fw_map_dm_addr(handler,
|
||||
wb[i].vpua);
|
||||
memcpy(inst->work_bufs[i].va, tmp_va, wb[i].size);
|
||||
}
|
||||
wb[i].iova = inst->work_bufs[i].dma_addr;
|
||||
@ -334,7 +335,6 @@ static int vp8_enc_init(struct mtk_vcodec_ctx *ctx)
|
||||
|
||||
inst->ctx = ctx;
|
||||
inst->vpu_inst.ctx = ctx;
|
||||
inst->vpu_inst.dev = ctx->dev->vpu_plat_dev;
|
||||
inst->vpu_inst.id = IPI_VENC_VP8;
|
||||
inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx, VENC_LT_SYS);
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "mtk_vcodec_enc.h"
|
||||
#include "mtk_vcodec_enc_pm.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Author: PoChun Lin <pochun.lin@mediatek.com>
|
||||
*/
|
||||
|
||||
#include "mtk_vpu.h"
|
||||
#include "mtk_vcodec_fw.h"
|
||||
#include "venc_ipi_msg.h"
|
||||
#include "venc_vpu_if.h"
|
||||
|
||||
@ -13,7 +13,8 @@ static void handle_enc_init_msg(struct venc_vpu_inst *vpu, const void *data)
|
||||
const struct venc_vpu_ipi_msg_init *msg = data;
|
||||
|
||||
vpu->inst_addr = msg->vpu_inst_addr;
|
||||
vpu->vsi = vpu_mapping_dm_addr(vpu->dev, msg->vpu_inst_addr);
|
||||
vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler,
|
||||
msg->vpu_inst_addr);
|
||||
}
|
||||
|
||||
static void handle_enc_encode_msg(struct venc_vpu_inst *vpu, const void *data)
|
||||
@ -25,7 +26,7 @@ static void handle_enc_encode_msg(struct venc_vpu_inst *vpu, const void *data)
|
||||
vpu->is_key_frm = msg->is_key_frm;
|
||||
}
|
||||
|
||||
static void vpu_enc_ipi_handler(const void *data, unsigned int len, void *priv)
|
||||
static void vpu_enc_ipi_handler(void *data, unsigned int len, void *priv)
|
||||
{
|
||||
const struct venc_vpu_ipi_msg_common *msg = data;
|
||||
struct venc_vpu_inst *vpu =
|
||||
@ -63,12 +64,13 @@ static int vpu_enc_send_msg(struct venc_vpu_inst *vpu, void *msg,
|
||||
|
||||
mtk_vcodec_debug_enter(vpu);
|
||||
|
||||
if (!vpu->dev) {
|
||||
if (!vpu->ctx->dev->fw_handler) {
|
||||
mtk_vcodec_err(vpu, "inst dev is NULL");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
status = vpu_ipi_send(vpu->dev, vpu->id, msg, len);
|
||||
status = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, vpu->id, msg,
|
||||
len, 2000);
|
||||
if (status) {
|
||||
mtk_vcodec_err(vpu, "vpu_ipi_send msg_id %x len %d fail %d",
|
||||
*(uint32_t *)msg, len, status);
|
||||
@ -93,8 +95,9 @@ int vpu_enc_init(struct venc_vpu_inst *vpu)
|
||||
vpu->signaled = 0;
|
||||
vpu->failure = 0;
|
||||
|
||||
status = vpu_ipi_register(vpu->dev, vpu->id, vpu_enc_ipi_handler,
|
||||
NULL, NULL);
|
||||
status = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->id,
|
||||
vpu_enc_ipi_handler, "venc", NULL);
|
||||
|
||||
if (status) {
|
||||
mtk_vcodec_err(vpu, "vpu_ipi_register fail %d", status);
|
||||
return -EINVAL;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#ifndef _VENC_VPU_IF_H_
|
||||
#define _VENC_VPU_IF_H_
|
||||
|
||||
#include "mtk_vpu.h"
|
||||
#include "mtk_vcodec_fw.h"
|
||||
#include "venc_drv_if.h"
|
||||
|
||||
/*
|
||||
@ -34,9 +34,8 @@ struct venc_vpu_inst {
|
||||
int is_key_frm;
|
||||
unsigned int inst_addr;
|
||||
void *vsi;
|
||||
enum ipi_id id;
|
||||
int id;
|
||||
struct mtk_vcodec_ctx *ctx;
|
||||
struct platform_device *dev;
|
||||
};
|
||||
|
||||
int vpu_enc_init(struct venc_vpu_inst *vpu);
|
||||
|
Loading…
Reference in New Issue
Block a user