Skip to content

Commit

Permalink
fixup! drivers: ele: add memory management functions
Browse files Browse the repository at this point in the history
fixup! drivers: ele: add memory management functions

Signed-off-by: Sahil Malhotra <[email protected]>
  • Loading branch information
sahilnxp committed Feb 14, 2025
1 parent 3f73015 commit b589598
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 50 deletions.
8 changes: 0 additions & 8 deletions core/drivers/crypto/ele/include/utils_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ struct imx_ele_buf {
uint32_t paddr_lsb; /* LSB of the physical address */
};

/*
* Cache operation on IMX ELE buffer
*
* @op: Cache operation
* @ele_buf: Buffer on which cache operation to be performed
*/
void imx_ele_buf_cache_op(enum utee_cache_operation op,
struct imx_ele_buf *ele_buf);
/*
* Allocate cache aligned buffer, initialize it with 0's, copy data from
* @buf to newly allocated buffer and cache flush the buffer.
Expand Down
48 changes: 6 additions & 42 deletions core/drivers/crypto/ele/utils_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,13 @@
* Copyright 2025 NXP
*/
#include <io.h>
#include <kernel/tee_misc.h>
#include <mm/core_memprot.h>
#include <string.h>
#include <utils_mem.h>

/*
* Allocate cache aligned memory of given size in bytes.
* Size will also be rounded up to cachec line size.
*
* @size Size in bytes to allocate
*/
static void *imx_ele_calloc_align(size_t size)
{
void *ptr = NULL;
size_t alloc_size = size;
size_t cacheline_size = dcache_get_line_size();

if (ROUNDUP_OVERFLOW(alloc_size, cacheline_size, &alloc_size))
return NULL;

ptr = memalign(cacheline_size, alloc_size);
if (!ptr) {
EMSG("alloc Error - NULL");
return NULL;
}

memset(ptr, 0, alloc_size);

return ptr;
}

/*
* Free allocated area
*
* @ptr area to free
*/
static void imx_ele_free(void *ptr)
{
if (ptr)
free(ptr);
}

void imx_ele_buf_cache_op(enum utee_cache_operation op,
struct imx_ele_buf *ele_buf)
static void imx_ele_buf_cache_op(enum utee_cache_operation op,
struct imx_ele_buf *ele_buf)
{
if (ele_buf && ele_buf->data)
cache_operation(op, ele_buf->data, ele_buf->size);
Expand All @@ -57,15 +21,15 @@ TEE_Result imx_ele_buf_alloc(struct imx_ele_buf *ele_buf, const uint8_t *buf,
if (!ele_buf || !size)
return TEE_ERROR_BAD_PARAMETERS;

ele_buf->data = imx_ele_calloc_align(size);
ele_buf->data = alloc_cache_aligned(size);
if (!ele_buf->data) {
EMSG("buffer allocation failed");
return TEE_ERROR_OUT_OF_MEMORY;
}

ele_buf->paddr = virt_to_phys(ele_buf->data);
if (!ele_buf->paddr) {
imx_ele_free(ele_buf->data);
free(ele_buf->data);
return TEE_ERROR_OUT_OF_MEMORY;
}

Expand All @@ -85,7 +49,7 @@ TEE_Result imx_ele_buf_alloc(struct imx_ele_buf *ele_buf, const uint8_t *buf,
void imx_ele_buf_free(struct imx_ele_buf *ele_buf)
{
if (ele_buf) {
imx_ele_free(ele_buf->data);
free(ele_buf->data);
ele_buf->data = NULL;
ele_buf->paddr = 0;
ele_buf->size = 0;
Expand Down

0 comments on commit b589598

Please sign in to comment.