drivers: video_common: Add aligned allocation API

For some hardwares, it is very common that some aligment on the allocated
memory is required. For example, the PxP and eLCDIF of NXP require aligned
buffers so that their performances can be optimal.

Add a new video_buffer_aligned_alloc() API for these needs.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
This commit is contained in:
Phi Bang Nguyen 2024-04-23 14:33:31 +02:00 committed by Anas Nashif
commit de29ffb033
2 changed files with 18 additions and 3 deletions

View file

@ -19,7 +19,7 @@ struct mem_block {
static struct mem_block video_block[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX]; static struct mem_block video_block[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX];
struct video_buffer *video_buffer_alloc(size_t size) struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align)
{ {
struct video_buffer *vbuf = NULL; struct video_buffer *vbuf = NULL;
struct mem_block *block; struct mem_block *block;
@ -39,7 +39,7 @@ struct video_buffer *video_buffer_alloc(size_t size)
} }
/* Alloc buffer memory */ /* Alloc buffer memory */
block->data = k_heap_alloc(&video_buffer_pool, size, K_FOREVER); block->data = k_heap_aligned_alloc(&video_buffer_pool, align, size, K_FOREVER);
if (block->data == NULL) { if (block->data == NULL) {
return NULL; return NULL;
} }
@ -51,6 +51,11 @@ struct video_buffer *video_buffer_alloc(size_t size)
return vbuf; return vbuf;
} }
struct video_buffer *video_buffer_alloc(size_t size)
{
return video_buffer_aligned_alloc(size, sizeof(void *));
}
void video_buffer_release(struct video_buffer *vbuf) void video_buffer_release(struct video_buffer *vbuf)
{ {
struct mem_block *block = NULL; struct mem_block *block = NULL;

View file

@ -560,10 +560,20 @@ static inline int video_set_signal(const struct device *dev,
return api->set_signal(dev, ep, signal); return api->set_signal(dev, ep, signal);
} }
/**
* @brief Allocate aligned video buffer.
*
* @param size Size of the video buffer (in bytes).
* @param align Alignment of the requested memory, must be a power of two.
*
* @retval pointer to allocated video buffer
*/
struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align);
/** /**
* @brief Allocate video buffer. * @brief Allocate video buffer.
* *
* @param size Size of the video buffer. * @param size Size of the video buffer (in bytes).
* *
* @retval pointer to allocated video buffer * @retval pointer to allocated video buffer
*/ */