Re: [PATCH 05/15] media: s5p-mfc: Simplify alloc/release private buffer functions

2017-02-17 Thread Javier Martinez Canillas
Hello Marek,

On 02/14/2017 04:51 AM, Marek Szyprowski wrote:
> 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: Marek Szyprowski 
> ---

Reviewed-by: Javier Martinez Canillas 
Tested-by: Javier Martinez Canillas 

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America


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

2017-02-13 Thread Marek Szyprowski
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: Marek Szyprowski 
---
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h |  2 ++
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.c| 20 +++--
 drivers/media/platform/s5p-mfc/s5p_mfc_opr.h|  8 +++
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c | 30 ++---
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c | 15 +
 5 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index da601a2dba2f..9cf860f34c71 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -240,12 +240,14 @@ struct s5p_mfc_variant {
  * buffer accessed by driver
  * @dma:   DMA address, only valid when kernel DMA API used
  * @size:  size of the buffer
+ * @ctx:   memory context (bank) used for this allocation
  */
 struct s5p_mfc_priv_buf {
unsigned long   ofs;
void*virt;
dma_addr_t  dma;
size_t  size;
+   unsigned intctx;
 };
 
 /**
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
index 99f65a92a6be..9294ee124661 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
@@ -37,12 +37,16 @@ void s5p_mfc_init_regs(struct s5p_mfc_dev *dev)
dev->mfc_regs = s5p_mfc_init_regs_v6_plus(dev);
 }
 
-int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base,
-   struct s5p_mfc_priv_buf *b)
+int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx,
+  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);
 
-   b->virt = dma_alloc_coherent(dev, b->size, >dma, GFP_KERNEL);
+   b->ctx = mem_ctx;
+   b->virt = dma_alloc_coherent(mem_dev, b->size, >dma, GFP_KERNEL);
 
if (!b->virt) {
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,
if (b->dma < base) {
mfc_err("Invalid memory configuration - buffer (%pad) is below 
base memory address(%pad)\n",
>dma, );
-   dma_free_coherent(dev, b->size, b->virt, b->dma);
+   dma_free_coherent(mem_dev, b->size, b->virt, b->dma);
return -ENOMEM;
}
 
@@ -61,11 +65,13 @@ int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t 
base,
return 0;
 }
 
-void s5p_mfc_release_priv_buf(struct device *dev,
-   struct s5p_mfc_priv_buf *b)
+void s5p_mfc_release_priv_buf(struct s5p_mfc_dev *dev,
+ struct s5p_mfc_priv_buf *b)
 {
+   struct device *mem_dev = dev->mem_dev[b->ctx];
+
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->dma = 0;
b->size = 0;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
index b6ac417ab63e..108e59382e0c 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
@@ -315,10 +315,10 @@ struct s5p_mfc_hw_ops {
 
 void s5p_mfc_init_hw_ops(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,
-   struct s5p_mfc_priv_buf *b);
-void s5p_mfc_release_priv_buf(struct device *dev,
-   struct s5p_mfc_priv_buf *b);
+int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx,
+  struct s5p_mfc_priv_buf *b);
+void s5p_mfc_release_priv_buf(struct s5p_mfc_dev *dev,
+ struct s5p_mfc_priv_buf *b);
 
 
 #endif /* S5P_MFC_OPR_H_ */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
index 32ce9ade2edb..20e8a1bdc984 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -41,8 +41,7 @@ static int s5p_mfc_alloc_dec_temp_buffers_v5(struct 
s5p_mfc_ctx *ctx)
int ret;
 
ctx->dsc.size = buf_size->dsc;
-   ret =  s5p_mfc_alloc_priv_buf(dev->mem_dev[BANK1_CTX],
-