Commit 11d1fc3b authored by Marek Szyprowski's avatar Marek Szyprowski Committed by Mauro Carvalho Chehab

[media] s5p-mfc: Simplify alloc/release private buffer functions

Change parameters for s5p_mfc_alloc_priv_buf() and s5p_mfc_release_priv_buf()
functions. Instead of DMA device pointer and a base, provide common MFC
device structure and memory bank context identifier.
Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: default avatarJavier Martinez Canillas <javier@osg.samsung.com>
Tested-by: default avatarJavier Martinez Canillas <javier@osg.samsung.com>
Acked-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Tested-by: default avatarSmitha T Murthy <smitha.t@samsung.com>
Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 0d9e301b
...@@ -240,12 +240,14 @@ struct s5p_mfc_variant { ...@@ -240,12 +240,14 @@ struct s5p_mfc_variant {
* buffer accessed by driver * buffer accessed by driver
* @dma: DMA address, only valid when kernel DMA API used * @dma: DMA address, only valid when kernel DMA API used
* @size: size of the buffer * @size: size of the buffer
* @ctx: memory context (bank) used for this allocation
*/ */
struct s5p_mfc_priv_buf { struct s5p_mfc_priv_buf {
unsigned long ofs; unsigned long ofs;
void *virt; void *virt;
dma_addr_t dma; dma_addr_t dma;
size_t size; size_t size;
unsigned int ctx;
}; };
/** /**
......
...@@ -37,12 +37,16 @@ void s5p_mfc_init_regs(struct s5p_mfc_dev *dev) ...@@ -37,12 +37,16 @@ void s5p_mfc_init_regs(struct s5p_mfc_dev *dev)
dev->mfc_regs = s5p_mfc_init_regs_v6_plus(dev); dev->mfc_regs = s5p_mfc_init_regs_v6_plus(dev);
} }
int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base, int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx,
struct s5p_mfc_priv_buf *b) struct s5p_mfc_priv_buf *b)
{ {
struct device *mem_dev = dev->mem_dev[mem_ctx];
dma_addr_t base = dev->dma_base[mem_ctx];
mfc_debug(3, "Allocating priv: %zu\n", b->size); mfc_debug(3, "Allocating priv: %zu\n", b->size);
b->virt = dma_alloc_coherent(dev, b->size, &b->dma, GFP_KERNEL); b->ctx = mem_ctx;
b->virt = dma_alloc_coherent(mem_dev, b->size, &b->dma, GFP_KERNEL);
if (!b->virt) { if (!b->virt) {
mfc_err("Allocating private buffer of size %zu failed\n", mfc_err("Allocating private buffer of size %zu failed\n",
...@@ -53,7 +57,7 @@ int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base, ...@@ -53,7 +57,7 @@ int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base,
if (b->dma < base) { if (b->dma < base) {
mfc_err("Invalid memory configuration - buffer (%pad) is below base memory address(%pad)\n", mfc_err("Invalid memory configuration - buffer (%pad) is below base memory address(%pad)\n",
&b->dma, &base); &b->dma, &base);
dma_free_coherent(dev, b->size, b->virt, b->dma); dma_free_coherent(mem_dev, b->size, b->virt, b->dma);
return -ENOMEM; return -ENOMEM;
} }
...@@ -61,11 +65,13 @@ int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base, ...@@ -61,11 +65,13 @@ int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base,
return 0; return 0;
} }
void s5p_mfc_release_priv_buf(struct device *dev, void s5p_mfc_release_priv_buf(struct s5p_mfc_dev *dev,
struct s5p_mfc_priv_buf *b) struct s5p_mfc_priv_buf *b)
{ {
struct device *mem_dev = dev->mem_dev[b->ctx];
if (b->virt) { if (b->virt) {
dma_free_coherent(dev, b->size, b->virt, b->dma); dma_free_coherent(mem_dev, b->size, b->virt, b->dma);
b->virt = NULL; b->virt = NULL;
b->dma = 0; b->dma = 0;
b->size = 0; b->size = 0;
......
...@@ -315,9 +315,9 @@ struct s5p_mfc_hw_ops { ...@@ -315,9 +315,9 @@ struct s5p_mfc_hw_ops {
void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev); void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev);
void s5p_mfc_init_regs(struct s5p_mfc_dev *dev); void s5p_mfc_init_regs(struct s5p_mfc_dev *dev);
int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base, int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx,
struct s5p_mfc_priv_buf *b); struct s5p_mfc_priv_buf *b);
void s5p_mfc_release_priv_buf(struct device *dev, void s5p_mfc_release_priv_buf(struct s5p_mfc_dev *dev,
struct s5p_mfc_priv_buf *b); struct s5p_mfc_priv_buf *b);
......
...@@ -41,8 +41,7 @@ static int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx) ...@@ -41,8 +41,7 @@ static int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx)
int ret; int ret;
ctx->dsc.size = buf_size->dsc; ctx->dsc.size = buf_size->dsc;
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK1_CTX, &ctx->dsc);
dev->dma_base[BANK1_CTX], &ctx->dsc);
if (ret) { if (ret) {
mfc_err("Failed to allocate temporary buffer\n"); mfc_err("Failed to allocate temporary buffer\n");
return ret; return ret;
...@@ -58,7 +57,7 @@ static int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx) ...@@ -58,7 +57,7 @@ static int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx)
/* Release temporary buffers for decoding */ /* Release temporary buffers for decoding */
static void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx *ctx) static void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx *ctx)
{ {
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK1_CTX], &ctx->dsc); s5p_mfc_release_priv_buf(ctx->dev, &ctx->dsc);
} }
/* Allocate codec buffers */ /* Allocate codec buffers */
...@@ -173,8 +172,7 @@ static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx) ...@@ -173,8 +172,7 @@ static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
/* Allocate only if memory from bank 1 is necessary */ /* Allocate only if memory from bank 1 is necessary */
if (ctx->bank1.size > 0) { if (ctx->bank1.size > 0) {
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK1_CTX, &ctx->bank1);
dev->dma_base[BANK1_CTX], &ctx->bank1);
if (ret) { if (ret) {
mfc_err("Failed to allocate Bank1 temporary buffer\n"); mfc_err("Failed to allocate Bank1 temporary buffer\n");
return ret; return ret;
...@@ -183,12 +181,10 @@ static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx) ...@@ -183,12 +181,10 @@ static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
} }
/* Allocate only if memory from bank 2 is necessary */ /* Allocate only if memory from bank 2 is necessary */
if (ctx->bank2.size > 0) { if (ctx->bank2.size > 0) {
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK2_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK2_CTX, &ctx->bank2);
dev->dma_base[BANK2_CTX], &ctx->bank2);
if (ret) { if (ret) {
mfc_err("Failed to allocate Bank2 temporary buffer\n"); mfc_err("Failed to allocate Bank2 temporary buffer\n");
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK1_CTX], s5p_mfc_release_priv_buf(ctx->dev, &ctx->bank1);
&ctx->bank1);
return ret; return ret;
} }
BUG_ON(ctx->bank2.dma & ((1 << MFC_BANK2_ALIGN_ORDER) - 1)); BUG_ON(ctx->bank2.dma & ((1 << MFC_BANK2_ALIGN_ORDER) - 1));
...@@ -199,8 +195,8 @@ static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx) ...@@ -199,8 +195,8 @@ static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
/* Release buffers allocated for codec */ /* Release buffers allocated for codec */
static void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx *ctx) static void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
{ {
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK1_CTX], &ctx->bank1); s5p_mfc_release_priv_buf(ctx->dev, &ctx->bank1);
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK2_CTX], &ctx->bank2); s5p_mfc_release_priv_buf(ctx->dev, &ctx->bank2);
} }
/* Allocate memory for instance data buffer */ /* Allocate memory for instance data buffer */
...@@ -216,8 +212,7 @@ static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx) ...@@ -216,8 +212,7 @@ static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
else else
ctx->ctx.size = buf_size->non_h264_ctx; ctx->ctx.size = buf_size->non_h264_ctx;
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK1_CTX, &ctx->ctx);
dev->dma_base[BANK1_CTX], &ctx->ctx);
if (ret) { if (ret) {
mfc_err("Failed to allocate instance buffer\n"); mfc_err("Failed to allocate instance buffer\n");
return ret; return ret;
...@@ -230,11 +225,10 @@ static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx) ...@@ -230,11 +225,10 @@ static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
/* Initialize shared memory */ /* Initialize shared memory */
ctx->shm.size = buf_size->shm; ctx->shm.size = buf_size->shm;
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK1_CTX, &ctx->shm);
dev->dma_base[BANK1_CTX], &ctx->shm);
if (ret) { if (ret) {
mfc_err("Failed to allocate shared memory buffer\n"); mfc_err("Failed to allocate shared memory buffer\n");
s5p_mfc_release_priv_buf(dev->mem_dev[BANK1_CTX], &ctx->ctx); s5p_mfc_release_priv_buf(dev, &ctx->ctx);
return ret; return ret;
} }
...@@ -250,8 +244,8 @@ static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx) ...@@ -250,8 +244,8 @@ static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
/* Release instance buffer */ /* Release instance buffer */
static void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx *ctx) static void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
{ {
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK1_CTX], &ctx->ctx); s5p_mfc_release_priv_buf(ctx->dev, &ctx->ctx);
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK1_CTX], &ctx->shm); s5p_mfc_release_priv_buf(ctx->dev, &ctx->shm);
} }
static int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev *dev) static int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev *dev)
......
...@@ -239,8 +239,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx) ...@@ -239,8 +239,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
/* Allocate only if memory from bank 1 is necessary */ /* Allocate only if memory from bank 1 is necessary */
if (ctx->bank1.size > 0) { if (ctx->bank1.size > 0) {
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK1_CTX, &ctx->bank1);
dev->dma_base[BANK1_CTX], &ctx->bank1);
if (ret) { if (ret) {
mfc_err("Failed to allocate Bank1 memory\n"); mfc_err("Failed to allocate Bank1 memory\n");
return ret; return ret;
...@@ -253,7 +252,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx) ...@@ -253,7 +252,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
/* Release buffers allocated for codec */ /* Release buffers allocated for codec */
static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx) static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
{ {
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK1_CTX], &ctx->bank1); s5p_mfc_release_priv_buf(ctx->dev, &ctx->bank1);
} }
/* Allocate memory for instance data buffer */ /* Allocate memory for instance data buffer */
...@@ -292,8 +291,7 @@ static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx) ...@@ -292,8 +291,7 @@ static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
break; break;
} }
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK1_CTX, &ctx->ctx);
dev->dma_base[BANK1_CTX], &ctx->ctx);
if (ret) { if (ret) {
mfc_err("Failed to allocate instance buffer\n"); mfc_err("Failed to allocate instance buffer\n");
return ret; return ret;
...@@ -310,7 +308,7 @@ static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx) ...@@ -310,7 +308,7 @@ static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
/* Release instance buffer */ /* Release instance buffer */
static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx) static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
{ {
s5p_mfc_release_priv_buf(ctx->dev->mem_dev[BANK1_CTX], &ctx->ctx); s5p_mfc_release_priv_buf(ctx->dev, &ctx->ctx);
} }
/* Allocate context buffers for SYS_INIT */ /* Allocate context buffers for SYS_INIT */
...@@ -322,8 +320,7 @@ static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev) ...@@ -322,8 +320,7 @@ static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
mfc_debug_enter(); mfc_debug_enter();
dev->ctx_buf.size = buf_size->dev_ctx; dev->ctx_buf.size = buf_size->dev_ctx;
ret = s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX], ret = s5p_mfc_alloc_priv_buf(dev, BANK1_CTX, &dev->ctx_buf);
dev->dma_base[BANK1_CTX], &dev->ctx_buf);
if (ret) { if (ret) {
mfc_err("Failed to allocate device context buffer\n"); mfc_err("Failed to allocate device context buffer\n");
return ret; return ret;
...@@ -340,7 +337,7 @@ static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev) ...@@ -340,7 +337,7 @@ static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
/* Release context buffers for SYS_INIT */ /* Release context buffers for SYS_INIT */
static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev) static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
{ {
s5p_mfc_release_priv_buf(dev->mem_dev[BANK1_CTX], &dev->ctx_buf); s5p_mfc_release_priv_buf(dev, &dev->ctx_buf);
} }
static int calc_plane(int width, int height) static int calc_plane(int width, int height)
......
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