Skip to content

Commit

Permalink
drivers: video: Add SMH option for video buffer
Browse files Browse the repository at this point in the history
This commit enables the user to choose whether to
allocate the video buffer from the video heap pool
or use a memory region with specific extra capabilities,
such as being cacheable/non-cacheable or using external
memory.

Signed-off-by: Lucas Tamborrino <[email protected]>
  • Loading branch information
LucasTambor committed Aug 13, 2024
1 parent 217e439 commit 36be74e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
15 changes: 15 additions & 0 deletions drivers/video/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ config VIDEO_BUFFER_POOL_ALIGN
int "Alignment of the video pool’s buffer"
default 64

config VIDEO_BUFFER_USE_SHARED_MULTI_HEAP
bool "Use shared multi heap for video buffer"
default n

config VIDEO_BUFFER_SMH_ATTRIBUTE
int "Shared multi heap attribute for video buffer"
depends on VIDEO_BUFFER_USE_SHARED_MULTI_HEAP
default 0
range 0 2
help
Shared multi heap attribute for video buffer:
0: SMH_REG_ATTR_CACHEABLE
1: SMH_REG_ATTR_NON_CACHEABLE
2: SMH_REG_ATTR_EXTERNAL

source "drivers/video/Kconfig.mcux_csi"

source "drivers/video/Kconfig.mcux_mipi_csi2rx"
Expand Down
19 changes: 14 additions & 5 deletions drivers/video/video_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@

#include <zephyr/drivers/video.h>

K_HEAP_DEFINE(video_buffer_pool,
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX *
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX);
#if defined(CONFIG_VIDEO_BUFFER_USE_SHARED_MULTI_HEAP)
#include <zephyr/multi_heap/shared_multi_heap.h>

#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \
shared_multi_heap_aligned_alloc(CONFIG_VIDEO_BUFFER_SMH_ATTRIBUTE, align, size)
#define VIDEO_COMMON_FREE(block) shared_multi_heap_free(block)
#else
K_HEAP_DEFINE(video_buffer_pool, CONFIG_VIDEO_BUFFER_POOL_SZ_MAX *CONFIG_VIDEO_BUFFER_POOL_NUM_MAX);

Check failure on line 17 in drivers/video/video_common.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

drivers/video/video_common.c:17 need consistent spacing around '*' (ctx:WxV)
#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \
k_heap_aligned_alloc(&video_buffer_pool, align, size, timeout);
#define VIDEO_COMMON_FREE(block) k_heap_free(&video_buffer_pool, block)
#endif

static struct video_buffer video_buf[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX];

Expand Down Expand Up @@ -39,7 +48,7 @@ struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align)
}

/* Alloc buffer memory */
block->data = k_heap_aligned_alloc(&video_buffer_pool, align, size, K_FOREVER);
block->data = VIDEO_COMMON_HEAP_ALLOC(align, size, K_FOREVER);
if (block->data == NULL) {
return NULL;
}
Expand Down Expand Up @@ -71,6 +80,6 @@ void video_buffer_release(struct video_buffer *vbuf)

vbuf->buffer = NULL;
if (block) {
k_heap_free(&video_buffer_pool, block->data);
VIDEO_COMMON_FREE(block->data);
}
}

0 comments on commit 36be74e

Please sign in to comment.