Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: video: Add SMH option for video buffer #76982

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions drivers/video/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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"
uLipe marked this conversation as resolved.
Show resolved Hide resolved
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
LucasTambor marked this conversation as resolved.
Show resolved Hide resolved

source "drivers/video/Kconfig.esp32_dvp"

source "drivers/video/Kconfig.mcux_csi"
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/kernel.h>
#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);
#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \

Check notice on line 18 in drivers/video/video_common.c

View workflow job for this annotation

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

You may want to run clang-format on this change

drivers/video/video_common.c:18 -K_HEAP_DEFINE(video_buffer_pool, CONFIG_VIDEO_BUFFER_POOL_SZ_MAX*CONFIG_VIDEO_BUFFER_POOL_NUM_MAX); +K_HEAP_DEFINE(video_buffer_pool, CONFIG_VIDEO_BUFFER_POOL_SZ_MAX *CONFIG_VIDEO_BUFFER_POOL_NUM_MAX);
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 @@
}

/* 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 @@

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