[media] s5p-mfc: Don't allocate codec buffers from pre-allocated region
authorMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 22 Mar 2017 10:34:28 +0000 (07:34 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 5 Apr 2017 19:36:53 +0000 (16:36 -0300)
Further investigation revealed that codec buffers also don't need to
be allocated at higher addresses than firmware base for MFC v6+ hardware.
Those buffers can be quite large and its size depends on the selected
format and framesize. This patch changes the way the codec buffers are
allocated - driver will use generic allocator for them instead of the
pre-allocated buffer for firmware and contexts.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c

index 34a66189d980e68f125591de562c7b396ea0c5c5..7f33cf23947fbe1fabf00c55934677247cc5af0f 100644 (file)
@@ -79,6 +79,25 @@ no_mem:
        return -ENOMEM;
 }
 
+int s5p_mfc_alloc_generic_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];
+
+       mfc_debug(3, "Allocating generic buf: %zu\n", b->size);
+
+       b->ctx = mem_ctx;
+       b->virt = dma_alloc_coherent(mem_dev, b->size, &b->dma, GFP_KERNEL);
+       if (!b->virt)
+               goto no_mem;
+
+       mfc_debug(3, "Allocated addr %p %pad\n", b->virt, &b->dma);
+       return 0;
+no_mem:
+       mfc_err("Allocating generic buffer of size %zu failed\n", b->size);
+       return -ENOMEM;
+}
+
 void s5p_mfc_release_priv_buf(struct s5p_mfc_dev *dev,
                              struct s5p_mfc_priv_buf *b)
 {
@@ -97,3 +116,12 @@ void s5p_mfc_release_priv_buf(struct s5p_mfc_dev *dev,
        b->size = 0;
 }
 
+void s5p_mfc_release_generic_buf(struct s5p_mfc_dev *dev,
+                             struct s5p_mfc_priv_buf *b)
+{
+       struct device *mem_dev = dev->mem_dev[b->ctx];
+       dma_free_coherent(mem_dev, b->size, b->virt, b->dma);
+       b->virt = NULL;
+       b->dma = 0;
+       b->size = 0;
+}
index 108e59382e0cab4055ab72c6d8542ae03316c7ed..16d553fcff089da3c0f818cf09359ea4ed415cc4 100644 (file)
@@ -319,6 +319,10 @@ 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);
+int s5p_mfc_alloc_generic_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx,
+                          struct s5p_mfc_priv_buf *b);
+void s5p_mfc_release_generic_buf(struct s5p_mfc_dev *dev,
+                             struct s5p_mfc_priv_buf *b);
 
 
 #endif /* S5P_MFC_OPR_H_ */
index 70071a12db163d58c75dd2908ddf033cdf415c06..85880e9106be7335eb0e6090d4d387edc874f522 100644 (file)
@@ -239,7 +239,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
 
        /* Allocate only if memory from bank 1 is necessary */
        if (ctx->bank1.size > 0) {
-               ret = s5p_mfc_alloc_priv_buf(dev, BANK_L_CTX, &ctx->bank1);
+               ret = s5p_mfc_alloc_generic_buf(dev, BANK_L_CTX, &ctx->bank1);
                if (ret) {
                        mfc_err("Failed to allocate Bank1 memory\n");
                        return ret;
@@ -252,7 +252,7 @@ static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
 /* Release buffers allocated for codec */
 static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
 {
-       s5p_mfc_release_priv_buf(ctx->dev, &ctx->bank1);
+       s5p_mfc_release_generic_buf(ctx->dev, &ctx->bank1);
 }
 
 /* Allocate memory for instance data buffer */