diff options
author | Hugues Fruchet <hugues.fruchet@st.com> | 2017-02-02 09:59:49 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-02-08 07:01:55 -0500 |
commit | c502e583506ec94cee780c080fff7b4e9ef6ef61 (patch) | |
tree | 6927ffdeb09332519e412f6d2e737f900f739174 | |
parent | f386509e49594591f80af2e5a73d4c9ce389aa29 (diff) |
[media] st-delta: add memory allocator helper functions
Helper functions used by decoder back-ends to allocate
physically contiguous memory required by hardware video
decoder.
Acked-by: Peter Griffin <peter.griffin@linaro.org>
Signed-off-by: Hugues Fruchet <hugues.fruchet@st.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r-- | drivers/media/platform/sti/delta/Makefile | 2 | ||||
-rw-r--r-- | drivers/media/platform/sti/delta/delta-mem.c | 51 | ||||
-rw-r--r-- | drivers/media/platform/sti/delta/delta-mem.h | 14 | ||||
-rw-r--r-- | drivers/media/platform/sti/delta/delta.h | 8 |
4 files changed, 74 insertions, 1 deletions
diff --git a/drivers/media/platform/sti/delta/Makefile b/drivers/media/platform/sti/delta/Makefile index 467519e12ba5..93a3037c29b9 100644 --- a/drivers/media/platform/sti/delta/Makefile +++ b/drivers/media/platform/sti/delta/Makefile | |||
@@ -1,2 +1,2 @@ | |||
1 | obj-$(CONFIG_VIDEO_STI_DELTA_DRIVER) := st-delta.o | 1 | obj-$(CONFIG_VIDEO_STI_DELTA_DRIVER) := st-delta.o |
2 | st-delta-y := delta-v4l2.o | 2 | st-delta-y := delta-v4l2.o delta-mem.o |
diff --git a/drivers/media/platform/sti/delta/delta-mem.c b/drivers/media/platform/sti/delta/delta-mem.c new file mode 100644 index 000000000000..d7b53d31caa6 --- /dev/null +++ b/drivers/media/platform/sti/delta/delta-mem.c | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Copyright (C) STMicroelectronics SA 2015 | ||
3 | * Author: Hugues Fruchet <hugues.fruchet@st.com> for STMicroelectronics. | ||
4 | * License terms: GNU General Public License (GPL), version 2 | ||
5 | */ | ||
6 | |||
7 | #include "delta.h" | ||
8 | #include "delta-mem.h" | ||
9 | |||
10 | int hw_alloc(struct delta_ctx *ctx, u32 size, const char *name, | ||
11 | struct delta_buf *buf) | ||
12 | { | ||
13 | struct delta_dev *delta = ctx->dev; | ||
14 | dma_addr_t dma_addr; | ||
15 | void *addr; | ||
16 | unsigned long attrs = DMA_ATTR_WRITE_COMBINE; | ||
17 | |||
18 | addr = dma_alloc_attrs(delta->dev, size, &dma_addr, | ||
19 | GFP_KERNEL | __GFP_NOWARN, attrs); | ||
20 | if (!addr) { | ||
21 | dev_err(delta->dev, | ||
22 | "%s hw_alloc:dma_alloc_coherent failed for %s (size=%d)\n", | ||
23 | ctx->name, name, size); | ||
24 | ctx->sys_errors++; | ||
25 | return -ENOMEM; | ||
26 | } | ||
27 | |||
28 | buf->size = size; | ||
29 | buf->paddr = dma_addr; | ||
30 | buf->vaddr = addr; | ||
31 | buf->name = name; | ||
32 | buf->attrs = attrs; | ||
33 | |||
34 | dev_dbg(delta->dev, | ||
35 | "%s allocate %d bytes of HW memory @(virt=0x%p, phy=0x%pad): %s\n", | ||
36 | ctx->name, size, buf->vaddr, &buf->paddr, buf->name); | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | void hw_free(struct delta_ctx *ctx, struct delta_buf *buf) | ||
42 | { | ||
43 | struct delta_dev *delta = ctx->dev; | ||
44 | |||
45 | dev_dbg(delta->dev, | ||
46 | "%s free %d bytes of HW memory @(virt=0x%p, phy=0x%pad): %s\n", | ||
47 | ctx->name, buf->size, buf->vaddr, &buf->paddr, buf->name); | ||
48 | |||
49 | dma_free_attrs(delta->dev, buf->size, | ||
50 | buf->vaddr, buf->paddr, buf->attrs); | ||
51 | } | ||
diff --git a/drivers/media/platform/sti/delta/delta-mem.h b/drivers/media/platform/sti/delta/delta-mem.h new file mode 100644 index 000000000000..f8ca109e1241 --- /dev/null +++ b/drivers/media/platform/sti/delta/delta-mem.h | |||
@@ -0,0 +1,14 @@ | |||
1 | /* | ||
2 | * Copyright (C) STMicroelectronics SA 2015 | ||
3 | * Author: Hugues Fruchet <hugues.fruchet@st.com> for STMicroelectronics. | ||
4 | * License terms: GNU General Public License (GPL), version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef DELTA_MEM_H | ||
8 | #define DELTA_MEM_H | ||
9 | |||
10 | int hw_alloc(struct delta_ctx *ctx, u32 size, const char *name, | ||
11 | struct delta_buf *buf); | ||
12 | void hw_free(struct delta_ctx *ctx, struct delta_buf *buf); | ||
13 | |||
14 | #endif /* DELTA_MEM_H */ | ||
diff --git a/drivers/media/platform/sti/delta/delta.h b/drivers/media/platform/sti/delta/delta.h index 74a42404bc50..9e265255e30a 100644 --- a/drivers/media/platform/sti/delta/delta.h +++ b/drivers/media/platform/sti/delta/delta.h | |||
@@ -191,6 +191,14 @@ struct delta_dts { | |||
191 | u64 val; | 191 | u64 val; |
192 | }; | 192 | }; |
193 | 193 | ||
194 | struct delta_buf { | ||
195 | u32 size; | ||
196 | void *vaddr; | ||
197 | dma_addr_t paddr; | ||
198 | const char *name; | ||
199 | unsigned long attrs; | ||
200 | }; | ||
201 | |||
194 | struct delta_ctx; | 202 | struct delta_ctx; |
195 | 203 | ||
196 | /* | 204 | /* |