media: staging/imx: Pass device to alloc/free_dma_buf
Allocate and free a DMA coherent buffer in imx_media_alloc/free_dma_buf() from the given device. This allows DMA alloc and free using a device that is backed by real hardware, which for the imx5/6/7 CSI is the CSI unit, and for the internal IPU sub-devices, is the parent IPU. Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
parent
6d01b7ff52
commit
34ff38745b
|
@ -460,13 +460,13 @@ static int prp_setup_rotation(struct prp_priv *priv)
|
||||||
incc = priv->cc[PRPENCVF_SINK_PAD];
|
incc = priv->cc[PRPENCVF_SINK_PAD];
|
||||||
outcc = vdev->cc;
|
outcc = vdev->cc;
|
||||||
|
|
||||||
ret = imx_media_alloc_dma_buf(ic_priv->md, &priv->rot_buf[0],
|
ret = imx_media_alloc_dma_buf(ic_priv->ipu_dev, &priv->rot_buf[0],
|
||||||
outfmt->sizeimage);
|
outfmt->sizeimage);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[0], %d\n", ret);
|
v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[0], %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = imx_media_alloc_dma_buf(ic_priv->md, &priv->rot_buf[1],
|
ret = imx_media_alloc_dma_buf(ic_priv->ipu_dev, &priv->rot_buf[1],
|
||||||
outfmt->sizeimage);
|
outfmt->sizeimage);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[1], %d\n", ret);
|
v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[1], %d\n", ret);
|
||||||
|
@ -539,9 +539,9 @@ static int prp_setup_rotation(struct prp_priv *priv)
|
||||||
unsetup_vb2:
|
unsetup_vb2:
|
||||||
prp_unsetup_vb2_buf(priv, VB2_BUF_STATE_QUEUED);
|
prp_unsetup_vb2_buf(priv, VB2_BUF_STATE_QUEUED);
|
||||||
free_rot1:
|
free_rot1:
|
||||||
imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[1]);
|
imx_media_free_dma_buf(ic_priv->ipu_dev, &priv->rot_buf[1]);
|
||||||
free_rot0:
|
free_rot0:
|
||||||
imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[0]);
|
imx_media_free_dma_buf(ic_priv->ipu_dev, &priv->rot_buf[0]);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,8 +559,8 @@ static void prp_unsetup_rotation(struct prp_priv *priv)
|
||||||
|
|
||||||
ipu_ic_disable(priv->ic);
|
ipu_ic_disable(priv->ic);
|
||||||
|
|
||||||
imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[0]);
|
imx_media_free_dma_buf(ic_priv->ipu_dev, &priv->rot_buf[0]);
|
||||||
imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[1]);
|
imx_media_free_dma_buf(ic_priv->ipu_dev, &priv->rot_buf[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int prp_setup_norotation(struct prp_priv *priv)
|
static int prp_setup_norotation(struct prp_priv *priv)
|
||||||
|
@ -652,7 +652,7 @@ static int prp_start(struct prp_priv *priv)
|
||||||
|
|
||||||
outfmt = &vdev->fmt.fmt.pix;
|
outfmt = &vdev->fmt.fmt.pix;
|
||||||
|
|
||||||
ret = imx_media_alloc_dma_buf(ic_priv->md, &priv->underrun_buf,
|
ret = imx_media_alloc_dma_buf(ic_priv->ipu_dev, &priv->underrun_buf,
|
||||||
outfmt->sizeimage);
|
outfmt->sizeimage);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_put_ipu;
|
goto out_put_ipu;
|
||||||
|
@ -722,7 +722,7 @@ out_free_nfb4eof_irq:
|
||||||
out_unsetup:
|
out_unsetup:
|
||||||
prp_unsetup(priv, VB2_BUF_STATE_QUEUED);
|
prp_unsetup(priv, VB2_BUF_STATE_QUEUED);
|
||||||
out_free_underrun:
|
out_free_underrun:
|
||||||
imx_media_free_dma_buf(ic_priv->md, &priv->underrun_buf);
|
imx_media_free_dma_buf(ic_priv->ipu_dev, &priv->underrun_buf);
|
||||||
out_put_ipu:
|
out_put_ipu:
|
||||||
prp_put_ipu_resources(priv);
|
prp_put_ipu_resources(priv);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -759,7 +759,7 @@ static void prp_stop(struct prp_priv *priv)
|
||||||
|
|
||||||
prp_unsetup(priv, VB2_BUF_STATE_ERROR);
|
prp_unsetup(priv, VB2_BUF_STATE_ERROR);
|
||||||
|
|
||||||
imx_media_free_dma_buf(ic_priv->md, &priv->underrun_buf);
|
imx_media_free_dma_buf(ic_priv->ipu_dev, &priv->underrun_buf);
|
||||||
|
|
||||||
/* cancel the EOF timeout timer */
|
/* cancel the EOF timeout timer */
|
||||||
del_timer_sync(&priv->eof_timeout_timer);
|
del_timer_sync(&priv->eof_timeout_timer);
|
||||||
|
|
|
@ -608,7 +608,7 @@ static int csi_idmac_start(struct csi_priv *priv)
|
||||||
|
|
||||||
outfmt = &vdev->fmt.fmt.pix;
|
outfmt = &vdev->fmt.fmt.pix;
|
||||||
|
|
||||||
ret = imx_media_alloc_dma_buf(priv->md, &priv->underrun_buf,
|
ret = imx_media_alloc_dma_buf(priv->dev, &priv->underrun_buf,
|
||||||
outfmt->sizeimage);
|
outfmt->sizeimage);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_put_ipu;
|
goto out_put_ipu;
|
||||||
|
@ -662,7 +662,7 @@ out_free_nfb4eof_irq:
|
||||||
out_unsetup:
|
out_unsetup:
|
||||||
csi_idmac_unsetup(priv, VB2_BUF_STATE_QUEUED);
|
csi_idmac_unsetup(priv, VB2_BUF_STATE_QUEUED);
|
||||||
out_free_dma_buf:
|
out_free_dma_buf:
|
||||||
imx_media_free_dma_buf(priv->md, &priv->underrun_buf);
|
imx_media_free_dma_buf(priv->dev, &priv->underrun_buf);
|
||||||
out_put_ipu:
|
out_put_ipu:
|
||||||
csi_idmac_put_ipu_resources(priv);
|
csi_idmac_put_ipu_resources(priv);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -694,7 +694,7 @@ static void csi_idmac_stop(struct csi_priv *priv)
|
||||||
|
|
||||||
csi_idmac_unsetup(priv, VB2_BUF_STATE_ERROR);
|
csi_idmac_unsetup(priv, VB2_BUF_STATE_ERROR);
|
||||||
|
|
||||||
imx_media_free_dma_buf(priv->md, &priv->underrun_buf);
|
imx_media_free_dma_buf(priv->dev, &priv->underrun_buf);
|
||||||
|
|
||||||
/* cancel the EOF timeout timer */
|
/* cancel the EOF timeout timer */
|
||||||
del_timer_sync(&priv->eof_timeout_timer);
|
del_timer_sync(&priv->eof_timeout_timer);
|
||||||
|
|
|
@ -675,29 +675,28 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(imx_media_ipu_image_to_mbus_fmt);
|
EXPORT_SYMBOL_GPL(imx_media_ipu_image_to_mbus_fmt);
|
||||||
|
|
||||||
void imx_media_free_dma_buf(struct imx_media_dev *imxmd,
|
void imx_media_free_dma_buf(struct device *dev,
|
||||||
struct imx_media_dma_buf *buf)
|
struct imx_media_dma_buf *buf)
|
||||||
{
|
{
|
||||||
if (buf->virt)
|
if (buf->virt)
|
||||||
dma_free_coherent(imxmd->md.dev, buf->len,
|
dma_free_coherent(dev, buf->len, buf->virt, buf->phys);
|
||||||
buf->virt, buf->phys);
|
|
||||||
|
|
||||||
buf->virt = NULL;
|
buf->virt = NULL;
|
||||||
buf->phys = 0;
|
buf->phys = 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(imx_media_free_dma_buf);
|
EXPORT_SYMBOL_GPL(imx_media_free_dma_buf);
|
||||||
|
|
||||||
int imx_media_alloc_dma_buf(struct imx_media_dev *imxmd,
|
int imx_media_alloc_dma_buf(struct device *dev,
|
||||||
struct imx_media_dma_buf *buf,
|
struct imx_media_dma_buf *buf,
|
||||||
int size)
|
int size)
|
||||||
{
|
{
|
||||||
imx_media_free_dma_buf(imxmd, buf);
|
imx_media_free_dma_buf(dev, buf);
|
||||||
|
|
||||||
buf->len = PAGE_ALIGN(size);
|
buf->len = PAGE_ALIGN(size);
|
||||||
buf->virt = dma_alloc_coherent(imxmd->md.dev, buf->len, &buf->phys,
|
buf->virt = dma_alloc_coherent(dev, buf->len, &buf->phys,
|
||||||
GFP_DMA | GFP_KERNEL);
|
GFP_DMA | GFP_KERNEL);
|
||||||
if (!buf->virt) {
|
if (!buf->virt) {
|
||||||
dev_err(imxmd->md.dev, "failed to alloc dma buffer\n");
|
dev_err(dev, "%s: failed\n", __func__);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,9 +204,9 @@ struct imx_media_dma_buf {
|
||||||
unsigned long len;
|
unsigned long len;
|
||||||
};
|
};
|
||||||
|
|
||||||
void imx_media_free_dma_buf(struct imx_media_dev *imxmd,
|
void imx_media_free_dma_buf(struct device *dev,
|
||||||
struct imx_media_dma_buf *buf);
|
struct imx_media_dma_buf *buf);
|
||||||
int imx_media_alloc_dma_buf(struct imx_media_dev *imxmd,
|
int imx_media_alloc_dma_buf(struct device *dev,
|
||||||
struct imx_media_dma_buf *buf,
|
struct imx_media_dma_buf *buf,
|
||||||
int size);
|
int size);
|
||||||
|
|
||||||
|
|
|
@ -714,7 +714,7 @@ static int imx7_csi_dma_start(struct imx7_csi *csi)
|
||||||
struct v4l2_pix_format *out_pix = &vdev->fmt.fmt.pix;
|
struct v4l2_pix_format *out_pix = &vdev->fmt.fmt.pix;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = imx_media_alloc_dma_buf(csi->imxmd, &csi->underrun_buf,
|
ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf,
|
||||||
out_pix->sizeimage);
|
out_pix->sizeimage);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
v4l2_warn(&csi->sd, "consider increasing the CMA area\n");
|
v4l2_warn(&csi->sd, "consider increasing the CMA area\n");
|
||||||
|
@ -754,7 +754,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
|
||||||
|
|
||||||
imx7_csi_dma_unsetup_vb2_buf(csi, VB2_BUF_STATE_ERROR);
|
imx7_csi_dma_unsetup_vb2_buf(csi, VB2_BUF_STATE_ERROR);
|
||||||
|
|
||||||
imx_media_free_dma_buf(csi->imxmd, &csi->underrun_buf);
|
imx_media_free_dma_buf(csi->dev, &csi->underrun_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int imx7_csi_configure(struct imx7_csi *csi)
|
static int imx7_csi_configure(struct imx7_csi *csi)
|
||||||
|
|
Loading…
Reference in a new issue