Skip to content

Commit b085c77

Browse files
Alain Volmathfruchet-st
authored andcommitted
video: allow allocating buffers via the mem sw attr heap allocator
Video buffers being often quite big, it might not be possible to allocate them from the default heap. For that reason, rely on the mem sw attr heap allocator in order to design from where to allocate buffers using which attributes. Signed-off-by: Alain Volmat <[email protected]>
1 parent 57454b2 commit b085c77

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

drivers/video/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ config VIDEO_I2C_RETRY_NUM
5858
The default is to not retry. Board configuration files or user project can then
5959
use the number of retries that matches their situation.
6060

61+
config VIDEO_BUFFER_USE_MEM_ATTR_HEAP
62+
bool "Use mem attr api for video buffer"
63+
default n
64+
65+
config VIDEO_BUFFER_MEM_SW_ATTRIBUTE
66+
int "Mem SW attribute for video buffer"
67+
depends on VIDEO_BUFFER_USE_MEM_ATTR_HEAP
68+
default 1
69+
help
70+
Mem SW attribute for video buffer:
71+
1: ATTR_SW_ALLOC_CACHE
72+
2: ATTR_SW_ALLOC_NON_CACHE
73+
4: ATTR_SW_ALLOC_DMA
74+
6175
source "drivers/video/Kconfig.esp32_dvp"
6276

6377
source "drivers/video/Kconfig.mcux_csi"

drivers/video/video_common.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ LOG_MODULE_REGISTER(video_common, CONFIG_VIDEO_LOG_LEVEL);
2626
#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \
2727
shared_multi_heap_aligned_alloc(CONFIG_VIDEO_BUFFER_SMH_ATTRIBUTE, align, size)
2828
#define VIDEO_COMMON_FREE(block) shared_multi_heap_free(block)
29+
#elif defined(CONFIG_VIDEO_BUFFER_USE_MEM_ATTR_HEAP)
30+
#include <zephyr/mem_mgmt/mem_attr_heap.h>
31+
#include <zephyr/dt-bindings/memory-attr/memory-attr.h>
32+
33+
#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \
34+
mem_attr_heap_aligned_alloc((CONFIG_VIDEO_BUFFER_MEM_SW_ATTRIBUTE << \
35+
DT_MEM_SW_ATTR_SHIFT), align, size)
36+
#define VIDEO_COMMON_FREE(block) mem_attr_heap_free(block)
2937
#else
3038
K_HEAP_DEFINE(video_buffer_pool, CONFIG_VIDEO_BUFFER_POOL_SZ_MAX*CONFIG_VIDEO_BUFFER_POOL_NUM_MAX);
3139
#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \
@@ -47,6 +55,9 @@ struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align, k_tim
4755
struct mem_block *block;
4856
int i;
4957

58+
#if defined(CONFIG_VIDEO_BUFFER_USE_MEM_ATTR_HEAP)
59+
mem_attr_heap_pool_init();
60+
#endif
5061
/* find available video buffer */
5162
for (i = 0; i < ARRAY_SIZE(video_buf); i++) {
5263
if (video_buf[i].buffer == NULL) {

0 commit comments

Comments
 (0)