Commit 53ebeea5 authored by Ming Qian's avatar Ming Qian Committed by Mauro Carvalho Chehab

media: imx-jpeg: Support to assign slot for encoder/decoder

imx jpeg encoder and decoder support 4 slots each,
aim to support some virtualization scenarios.

driver should only enable one slot one time.

but due to some hardware issue,
only slot 0 can be enabled in imx8q platform,
and they may be fixed in imx9 platform.
Signed-off-by: default avatarMing Qian <ming.qian@nxp.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent dcff0b56
...@@ -58,7 +58,6 @@ ...@@ -58,7 +58,6 @@
#define CAST_OFBSIZE_LO CAST_STATUS18 #define CAST_OFBSIZE_LO CAST_STATUS18
#define CAST_OFBSIZE_HI CAST_STATUS19 #define CAST_OFBSIZE_HI CAST_STATUS19
#define MXC_MAX_SLOTS 1 /* TODO use all 4 slots*/
/* JPEG-Decoder Wrapper Slot Registers 0..3 */ /* JPEG-Decoder Wrapper Slot Registers 0..3 */
#define SLOT_BASE 0x10000 #define SLOT_BASE 0x10000
#define SLOT_STATUS 0x0 #define SLOT_STATUS 0x0
......
...@@ -745,87 +745,77 @@ static void notify_src_chg(struct mxc_jpeg_ctx *ctx) ...@@ -745,87 +745,77 @@ static void notify_src_chg(struct mxc_jpeg_ctx *ctx)
v4l2_event_queue_fh(&ctx->fh, &ev); v4l2_event_queue_fh(&ctx->fh, &ev);
} }
static int mxc_get_free_slot(struct mxc_jpeg_slot_data slot_data[], int n) static int mxc_get_free_slot(struct mxc_jpeg_slot_data *slot_data)
{ {
int free_slot = 0; if (!slot_data->used)
return slot_data->slot;
while (slot_data[free_slot].used && free_slot < n) return -1;
free_slot++;
return free_slot; /* >=n when there are no more free slots */
} }
static bool mxc_jpeg_alloc_slot_data(struct mxc_jpeg_dev *jpeg, static bool mxc_jpeg_alloc_slot_data(struct mxc_jpeg_dev *jpeg)
unsigned int slot)
{ {
struct mxc_jpeg_desc *desc; struct mxc_jpeg_desc *desc;
struct mxc_jpeg_desc *cfg_desc; struct mxc_jpeg_desc *cfg_desc;
void *cfg_stm; void *cfg_stm;
if (jpeg->slot_data[slot].desc) if (jpeg->slot_data.desc)
goto skip_alloc; /* already allocated, reuse it */ goto skip_alloc; /* already allocated, reuse it */
/* allocate descriptor for decoding/encoding phase */ /* allocate descriptor for decoding/encoding phase */
desc = dma_alloc_coherent(jpeg->dev, desc = dma_alloc_coherent(jpeg->dev,
sizeof(struct mxc_jpeg_desc), sizeof(struct mxc_jpeg_desc),
&jpeg->slot_data[slot].desc_handle, &jpeg->slot_data.desc_handle,
GFP_ATOMIC); GFP_ATOMIC);
if (!desc) if (!desc)
goto err; goto err;
jpeg->slot_data[slot].desc = desc; jpeg->slot_data.desc = desc;
/* allocate descriptor for configuration phase (encoder only) */ /* allocate descriptor for configuration phase (encoder only) */
cfg_desc = dma_alloc_coherent(jpeg->dev, cfg_desc = dma_alloc_coherent(jpeg->dev,
sizeof(struct mxc_jpeg_desc), sizeof(struct mxc_jpeg_desc),
&jpeg->slot_data[slot].cfg_desc_handle, &jpeg->slot_data.cfg_desc_handle,
GFP_ATOMIC); GFP_ATOMIC);
if (!cfg_desc) if (!cfg_desc)
goto err; goto err;
jpeg->slot_data[slot].cfg_desc = cfg_desc; jpeg->slot_data.cfg_desc = cfg_desc;
/* allocate configuration stream */ /* allocate configuration stream */
cfg_stm = dma_alloc_coherent(jpeg->dev, cfg_stm = dma_alloc_coherent(jpeg->dev,
MXC_JPEG_MAX_CFG_STREAM, MXC_JPEG_MAX_CFG_STREAM,
&jpeg->slot_data[slot].cfg_stream_handle, &jpeg->slot_data.cfg_stream_handle,
GFP_ATOMIC); GFP_ATOMIC);
if (!cfg_stm) if (!cfg_stm)
goto err; goto err;
jpeg->slot_data[slot].cfg_stream_vaddr = cfg_stm; jpeg->slot_data.cfg_stream_vaddr = cfg_stm;
skip_alloc: skip_alloc:
jpeg->slot_data[slot].used = true; jpeg->slot_data.used = true;
return true; return true;
err: err:
dev_err(jpeg->dev, "Could not allocate descriptors for slot %d", slot); dev_err(jpeg->dev, "Could not allocate descriptors for slot %d", jpeg->slot_data.slot);
return false; return false;
} }
static void mxc_jpeg_free_slot_data(struct mxc_jpeg_dev *jpeg, static void mxc_jpeg_free_slot_data(struct mxc_jpeg_dev *jpeg)
unsigned int slot)
{ {
if (slot >= MXC_MAX_SLOTS) {
dev_err(jpeg->dev, "Invalid slot %d, nothing to free.", slot);
return;
}
/* free descriptor for decoding/encoding phase */ /* free descriptor for decoding/encoding phase */
dma_free_coherent(jpeg->dev, sizeof(struct mxc_jpeg_desc), dma_free_coherent(jpeg->dev, sizeof(struct mxc_jpeg_desc),
jpeg->slot_data[slot].desc, jpeg->slot_data.desc,
jpeg->slot_data[slot].desc_handle); jpeg->slot_data.desc_handle);
/* free descriptor for encoder configuration phase / decoder DHT */ /* free descriptor for encoder configuration phase / decoder DHT */
dma_free_coherent(jpeg->dev, sizeof(struct mxc_jpeg_desc), dma_free_coherent(jpeg->dev, sizeof(struct mxc_jpeg_desc),
jpeg->slot_data[slot].cfg_desc, jpeg->slot_data.cfg_desc,
jpeg->slot_data[slot].cfg_desc_handle); jpeg->slot_data.cfg_desc_handle);
/* free configuration stream */ /* free configuration stream */
dma_free_coherent(jpeg->dev, MXC_JPEG_MAX_CFG_STREAM, dma_free_coherent(jpeg->dev, MXC_JPEG_MAX_CFG_STREAM,
jpeg->slot_data[slot].cfg_stream_vaddr, jpeg->slot_data.cfg_stream_vaddr,
jpeg->slot_data[slot].cfg_stream_handle); jpeg->slot_data.cfg_stream_handle);
jpeg->slot_data[slot].used = false; jpeg->slot_data.used = false;
} }
static void mxc_jpeg_check_and_set_last_buffer(struct mxc_jpeg_ctx *ctx, static void mxc_jpeg_check_and_set_last_buffer(struct mxc_jpeg_ctx *ctx,
...@@ -855,7 +845,7 @@ static void mxc_jpeg_job_finish(struct mxc_jpeg_ctx *ctx, enum vb2_buffer_state ...@@ -855,7 +845,7 @@ static void mxc_jpeg_job_finish(struct mxc_jpeg_ctx *ctx, enum vb2_buffer_state
v4l2_m2m_buf_done(dst_buf, state); v4l2_m2m_buf_done(dst_buf, state);
mxc_jpeg_disable_irq(reg, ctx->slot); mxc_jpeg_disable_irq(reg, ctx->slot);
ctx->mxc_jpeg->slot_data[ctx->slot].used = false; jpeg->slot_data.used = false;
if (reset) if (reset)
mxc_jpeg_sw_reset(reg); mxc_jpeg_sw_reset(reg);
} }
...@@ -919,7 +909,7 @@ static irqreturn_t mxc_jpeg_dec_irq(int irq, void *priv) ...@@ -919,7 +909,7 @@ static irqreturn_t mxc_jpeg_dec_irq(int irq, void *priv)
goto job_unlock; goto job_unlock;
} }
if (!jpeg->slot_data[slot].used) if (!jpeg->slot_data.used)
goto job_unlock; goto job_unlock;
dec_ret = readl(reg + MXC_SLOT_OFFSET(slot, SLOT_STATUS)); dec_ret = readl(reg + MXC_SLOT_OFFSET(slot, SLOT_STATUS));
...@@ -1179,13 +1169,13 @@ static void mxc_jpeg_config_dec_desc(struct vb2_buffer *out_buf, ...@@ -1179,13 +1169,13 @@ static void mxc_jpeg_config_dec_desc(struct vb2_buffer *out_buf,
struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
void __iomem *reg = jpeg->base_reg; void __iomem *reg = jpeg->base_reg;
unsigned int slot = ctx->slot; unsigned int slot = ctx->slot;
struct mxc_jpeg_desc *desc = jpeg->slot_data[slot].desc; struct mxc_jpeg_desc *desc = jpeg->slot_data.desc;
struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data[slot].cfg_desc; struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data.cfg_desc;
dma_addr_t desc_handle = jpeg->slot_data[slot].desc_handle; dma_addr_t desc_handle = jpeg->slot_data.desc_handle;
dma_addr_t cfg_desc_handle = jpeg->slot_data[slot].cfg_desc_handle; dma_addr_t cfg_desc_handle = jpeg->slot_data.cfg_desc_handle;
dma_addr_t cfg_stream_handle = jpeg->slot_data[slot].cfg_stream_handle; dma_addr_t cfg_stream_handle = jpeg->slot_data.cfg_stream_handle;
unsigned int *cfg_size = &jpeg->slot_data[slot].cfg_stream_size; unsigned int *cfg_size = &jpeg->slot_data.cfg_stream_size;
void *cfg_stream_vaddr = jpeg->slot_data[slot].cfg_stream_vaddr; void *cfg_stream_vaddr = jpeg->slot_data.cfg_stream_vaddr;
struct mxc_jpeg_src_buf *jpeg_src_buf; struct mxc_jpeg_src_buf *jpeg_src_buf;
jpeg_src_buf = vb2_to_mxc_buf(src_buf); jpeg_src_buf = vb2_to_mxc_buf(src_buf);
...@@ -1245,18 +1235,18 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf, ...@@ -1245,18 +1235,18 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf,
struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
void __iomem *reg = jpeg->base_reg; void __iomem *reg = jpeg->base_reg;
unsigned int slot = ctx->slot; unsigned int slot = ctx->slot;
struct mxc_jpeg_desc *desc = jpeg->slot_data[slot].desc; struct mxc_jpeg_desc *desc = jpeg->slot_data.desc;
struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data[slot].cfg_desc; struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data.cfg_desc;
dma_addr_t desc_handle = jpeg->slot_data[slot].desc_handle; dma_addr_t desc_handle = jpeg->slot_data.desc_handle;
dma_addr_t cfg_desc_handle = jpeg->slot_data[slot].cfg_desc_handle; dma_addr_t cfg_desc_handle = jpeg->slot_data.cfg_desc_handle;
void *cfg_stream_vaddr = jpeg->slot_data[slot].cfg_stream_vaddr; void *cfg_stream_vaddr = jpeg->slot_data.cfg_stream_vaddr;
struct mxc_jpeg_q_data *q_data; struct mxc_jpeg_q_data *q_data;
enum mxc_jpeg_image_format img_fmt; enum mxc_jpeg_image_format img_fmt;
int w, h; int w, h;
q_data = mxc_jpeg_get_q_data(ctx, src_buf->vb2_queue->type); q_data = mxc_jpeg_get_q_data(ctx, src_buf->vb2_queue->type);
jpeg->slot_data[slot].cfg_stream_size = jpeg->slot_data.cfg_stream_size =
mxc_jpeg_setup_cfg_stream(cfg_stream_vaddr, mxc_jpeg_setup_cfg_stream(cfg_stream_vaddr,
q_data->fmt->fourcc, q_data->fmt->fourcc,
q_data->crop.width, q_data->crop.width,
...@@ -1265,7 +1255,7 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf, ...@@ -1265,7 +1255,7 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf,
/* chain the config descriptor with the encoding descriptor */ /* chain the config descriptor with the encoding descriptor */
cfg_desc->next_descpt_ptr = desc_handle | MXC_NXT_DESCPT_EN; cfg_desc->next_descpt_ptr = desc_handle | MXC_NXT_DESCPT_EN;
cfg_desc->buf_base0 = jpeg->slot_data[slot].cfg_stream_handle; cfg_desc->buf_base0 = jpeg->slot_data.cfg_stream_handle;
cfg_desc->buf_base1 = 0; cfg_desc->buf_base1 = 0;
cfg_desc->line_pitch = 0; cfg_desc->line_pitch = 0;
cfg_desc->stm_bufbase = 0; /* no output expected */ cfg_desc->stm_bufbase = 0; /* no output expected */
...@@ -1408,7 +1398,7 @@ static void mxc_jpeg_device_run_timeout(struct work_struct *work) ...@@ -1408,7 +1398,7 @@ static void mxc_jpeg_device_run_timeout(struct work_struct *work)
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ctx->mxc_jpeg->hw_lock, flags); spin_lock_irqsave(&ctx->mxc_jpeg->hw_lock, flags);
if (ctx->slot < MXC_MAX_SLOTS && ctx->mxc_jpeg->slot_data[ctx->slot].used) { if (ctx->mxc_jpeg->slot_data.used) {
dev_warn(jpeg->dev, "%s timeout, cancel it\n", dev_warn(jpeg->dev, "%s timeout, cancel it\n",
ctx->mxc_jpeg->mode == MXC_JPEG_DECODE ? "decode" : "encode"); ctx->mxc_jpeg->mode == MXC_JPEG_DECODE ? "decode" : "encode");
mxc_jpeg_job_finish(ctx, VB2_BUF_STATE_ERROR, true); mxc_jpeg_job_finish(ctx, VB2_BUF_STATE_ERROR, true);
...@@ -1476,12 +1466,12 @@ static void mxc_jpeg_device_run(void *priv) ...@@ -1476,12 +1466,12 @@ static void mxc_jpeg_device_run(void *priv)
mxc_jpeg_enable(reg); mxc_jpeg_enable(reg);
mxc_jpeg_set_l_endian(reg, 1); mxc_jpeg_set_l_endian(reg, 1);
ctx->slot = mxc_get_free_slot(jpeg->slot_data, MXC_MAX_SLOTS); ctx->slot = mxc_get_free_slot(&jpeg->slot_data);
if (ctx->slot >= MXC_MAX_SLOTS) { if (ctx->slot < 0) {
dev_err(dev, "No more free slots\n"); dev_err(dev, "No more free slots\n");
goto end; goto end;
} }
if (!mxc_jpeg_alloc_slot_data(jpeg, ctx->slot)) { if (!mxc_jpeg_alloc_slot_data(jpeg)) {
dev_err(dev, "Cannot allocate slot data\n"); dev_err(dev, "Cannot allocate slot data\n");
goto end; goto end;
} }
...@@ -2101,7 +2091,7 @@ static int mxc_jpeg_open(struct file *file) ...@@ -2101,7 +2091,7 @@ static int mxc_jpeg_open(struct file *file)
} }
ctx->fh.ctrl_handler = &ctx->ctrl_handler; ctx->fh.ctrl_handler = &ctx->ctrl_handler;
mxc_jpeg_set_default_params(ctx); mxc_jpeg_set_default_params(ctx);
ctx->slot = MXC_MAX_SLOTS; /* slot not allocated yet */ ctx->slot = -1; /* slot not allocated yet */
INIT_DELAYED_WORK(&ctx->task_timer, mxc_jpeg_device_run_timeout); INIT_DELAYED_WORK(&ctx->task_timer, mxc_jpeg_device_run_timeout);
if (mxc_jpeg->mode == MXC_JPEG_DECODE) if (mxc_jpeg->mode == MXC_JPEG_DECODE)
...@@ -2677,6 +2667,11 @@ static int mxc_jpeg_attach_pm_domains(struct mxc_jpeg_dev *jpeg) ...@@ -2677,6 +2667,11 @@ static int mxc_jpeg_attach_pm_domains(struct mxc_jpeg_dev *jpeg)
dev_err(dev, "No power domains defined for jpeg node\n"); dev_err(dev, "No power domains defined for jpeg node\n");
return jpeg->num_domains; return jpeg->num_domains;
} }
if (jpeg->num_domains == 1) {
/* genpd_dev_pm_attach() attach automatically if power domains count is 1 */
jpeg->num_domains = 0;
return 0;
}
jpeg->pd_dev = devm_kmalloc_array(dev, jpeg->num_domains, jpeg->pd_dev = devm_kmalloc_array(dev, jpeg->num_domains,
sizeof(*jpeg->pd_dev), GFP_KERNEL); sizeof(*jpeg->pd_dev), GFP_KERNEL);
...@@ -2718,7 +2713,6 @@ static int mxc_jpeg_probe(struct platform_device *pdev) ...@@ -2718,7 +2713,6 @@ static int mxc_jpeg_probe(struct platform_device *pdev)
int ret; int ret;
int mode; int mode;
const struct of_device_id *of_id; const struct of_device_id *of_id;
unsigned int slot;
of_id = of_match_node(mxc_jpeg_match, dev->of_node); of_id = of_match_node(mxc_jpeg_match, dev->of_node);
if (!of_id) if (!of_id)
...@@ -2742,19 +2736,22 @@ static int mxc_jpeg_probe(struct platform_device *pdev) ...@@ -2742,19 +2736,22 @@ static int mxc_jpeg_probe(struct platform_device *pdev)
if (IS_ERR(jpeg->base_reg)) if (IS_ERR(jpeg->base_reg))
return PTR_ERR(jpeg->base_reg); return PTR_ERR(jpeg->base_reg);
for (slot = 0; slot < MXC_MAX_SLOTS; slot++) { ret = of_property_read_u32_index(pdev->dev.of_node, "slot", 0, &jpeg->slot_data.slot);
dec_irq = platform_get_irq(pdev, slot); if (ret)
if (dec_irq < 0) { jpeg->slot_data.slot = 0;
ret = dec_irq; dev_info(&pdev->dev, "choose slot %d\n", jpeg->slot_data.slot);
goto err_irq; dec_irq = platform_get_irq(pdev, 0);
} if (dec_irq < 0) {
ret = devm_request_irq(&pdev->dev, dec_irq, mxc_jpeg_dec_irq, dev_err(&pdev->dev, "Failed to get irq %d\n", dec_irq);
0, pdev->name, jpeg); ret = dec_irq;
if (ret) { goto err_irq;
dev_err(&pdev->dev, "Failed to request irq %d (%d)\n", }
dec_irq, ret); ret = devm_request_irq(&pdev->dev, dec_irq, mxc_jpeg_dec_irq,
goto err_irq; 0, pdev->name, jpeg);
} if (ret) {
dev_err(&pdev->dev, "Failed to request irq %d (%d)\n",
dec_irq, ret);
goto err_irq;
} }
jpeg->pdev = pdev; jpeg->pdev = pdev;
...@@ -2914,11 +2911,9 @@ static const struct dev_pm_ops mxc_jpeg_pm_ops = { ...@@ -2914,11 +2911,9 @@ static const struct dev_pm_ops mxc_jpeg_pm_ops = {
static void mxc_jpeg_remove(struct platform_device *pdev) static void mxc_jpeg_remove(struct platform_device *pdev)
{ {
unsigned int slot;
struct mxc_jpeg_dev *jpeg = platform_get_drvdata(pdev); struct mxc_jpeg_dev *jpeg = platform_get_drvdata(pdev);
for (slot = 0; slot < MXC_MAX_SLOTS; slot++) mxc_jpeg_free_slot_data(jpeg);
mxc_jpeg_free_slot_data(jpeg, slot);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
video_unregister_device(jpeg->dec_vdev); video_unregister_device(jpeg->dec_vdev);
......
...@@ -97,7 +97,7 @@ struct mxc_jpeg_ctx { ...@@ -97,7 +97,7 @@ struct mxc_jpeg_ctx {
struct mxc_jpeg_q_data cap_q; struct mxc_jpeg_q_data cap_q;
struct v4l2_fh fh; struct v4l2_fh fh;
enum mxc_jpeg_enc_state enc_state; enum mxc_jpeg_enc_state enc_state;
unsigned int slot; int slot;
unsigned int source_change; unsigned int source_change;
bool header_parsed; bool header_parsed;
struct v4l2_ctrl_handler ctrl_handler; struct v4l2_ctrl_handler ctrl_handler;
...@@ -106,6 +106,7 @@ struct mxc_jpeg_ctx { ...@@ -106,6 +106,7 @@ struct mxc_jpeg_ctx {
}; };
struct mxc_jpeg_slot_data { struct mxc_jpeg_slot_data {
int slot;
bool used; bool used;
struct mxc_jpeg_desc *desc; // enc/dec descriptor struct mxc_jpeg_desc *desc; // enc/dec descriptor
struct mxc_jpeg_desc *cfg_desc; // configuration descriptor struct mxc_jpeg_desc *cfg_desc; // configuration descriptor
...@@ -128,7 +129,7 @@ struct mxc_jpeg_dev { ...@@ -128,7 +129,7 @@ struct mxc_jpeg_dev {
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
struct v4l2_m2m_dev *m2m_dev; struct v4l2_m2m_dev *m2m_dev;
struct video_device *dec_vdev; struct video_device *dec_vdev;
struct mxc_jpeg_slot_data slot_data[MXC_MAX_SLOTS]; struct mxc_jpeg_slot_data slot_data;
int num_domains; int num_domains;
struct device **pd_dev; struct device **pd_dev;
struct device_link **pd_link; struct device_link **pd_link;
......
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