1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright 2025 NXP 4 * 5 * Memory management utilities. 6 * Primitive to allocate, free memory. 7 */ 8 9 #ifndef __MEMUTILS_H__ 10 #define __MEMUTILS_H__ 11 12 #include <kernel/cache_helpers.h> 13 #include <stddef.h> 14 #include <tee_api_types.h> 15 #include <tee/cache.h> 16 17 /* 18 * struct imx_ele_buf - Definition of a IMX ELE buffer type 19 * @data: Data buffer 20 * @size: Number of bytes in the data buffer 21 * @paddr: Physical address of the buffer 22 * @paddr_msb: MSB of the physical address 23 * @paddr_lsb: LSB of the physical address 24 */ 25 struct imx_ele_buf { 26 uint8_t *data; 27 size_t size; 28 paddr_t paddr; 29 uint32_t paddr_msb; 30 uint32_t paddr_lsb; 31 }; 32 33 /* 34 * Allocate cache aligned buffer, initialize it with 0's, copy data from 35 * @buf to newly allocated buffer and cache flush the buffer. 36 * 37 * @ele_buf: Buffer allocated 38 * @buf: If valid, will copy contents from this buffer to newly allocated 39 * buffer. Otherwise it is ignored. 40 * @size: Size in bytes of the memory to allocate. 41 */ 42 TEE_Result imx_ele_buf_alloc(struct imx_ele_buf *ele_buf, const uint8_t *buf, 43 size_t size); 44 45 /* 46 * Free buffer allocated memory 47 * 48 * @ele_buf: Buffer to free 49 */ 50 void imx_ele_buf_free(struct imx_ele_buf *ele_buf); 51 52 /* 53 * Copy data from ele_buf to data 54 * 55 * @ele_buf: Buffer from data to be copied 56 * @buf: Buffer to which data to be copied 57 * @size: Size of buf 58 */ 59 TEE_Result imx_ele_buf_copy(struct imx_ele_buf *ele_buf, uint8_t *buf, 60 size_t size); 61 62 #endif /* __MEMUTILS_H__ */ 63