Mistake on this page?
Report an issue in GitHub or email us
tfm_pools.h
1 /*
2  * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 #ifndef __TFM_POOLS_H__
8 #define __TFM_POOLS_H__
9 
10 /*
11  * Resource pool - few known size resources allocation/free is required,
12  * so pool is more applicable than heap.
13  */
14 
15 /*
16  * Pool Instance:
17  * [ Pool Instance ] + N * [ Pool Chunks ]
18  */
20  struct tfm_list_node_t list; /* Chunk list */
21  void *pool; /* Point to the parent pool */
22  uint8_t data[0]; /* Data indicator */
23 };
24 
26  size_t chunksz; /* Chunks size of pool member */
27  struct tfm_list_node_t chunks_list; /* Chunk list head in pool */
28  struct tfm_pool_chunk_t chunks[0]; /* Data indicator */
29 };
30 
31 /*
32  * This will declares a static memory pool variable with chunk memory.
33  * Parameters:
34  * name - Variable name, will be used when register
35  * chunksz - chunk size in bytes
36  * num - Number of chunks
37  */
38 #define TFM_POOL_DECLARE(name, chunksz, num) \
39  static uint8_t name##_pool_buf[((chunksz) + \
40  sizeof(struct tfm_pool_chunk_t)) * (num) \
41  + sizeof(struct tfm_pool_instance_t)] \
42  __attribute__((aligned(4))); \
43  static struct tfm_pool_instance_t *name = \
44  (struct tfm_pool_instance_t *)name##_pool_buf
45 
46 /* Get the head size of memory pool */
47 #define POOL_HEAD_SIZE (sizeof(struct tfm_pool_instance_t) + \
48  sizeof(struct tfm_pool_chunk_t))
49 
50 /* Get the whole size of memory pool */
51 #define POOL_BUFFER_SIZE(name) sizeof(name##_pool_buf)
52 
53 /**
54  * \brief Register a memory pool.
55  *
56  * \param[in] pool Pointer to memory pool declared by
57  * \ref TFM_POOL_DECLARE
58  * \param[in] poolsz Size of the pool buffer.
59  * \param[in] chunksz Size of chunks.
60  * \param[in] num Number of chunks.
61  *
62  * \retval IPC_SUCCESS Success.
63  * \retval IPC_ERROR_BAD_PARAMETERS Parameters error.
64  */
65 int32_t tfm_pool_init(struct tfm_pool_instance_t *pool, size_t poolsz,
66  size_t chunksz, size_t num);
67 
68 /**
69  * \brief Allocate a memory from pool.
70  *
71  * \param[in] pool pool pointer decleared by \ref TFM_POOL_DECLARE
72  *
73  * \retval buffer pointer Success.
74  * \retval NULL Failed.
75  */
76 void *tfm_pool_alloc(struct tfm_pool_instance_t *pool);
77 
78 /**
79  * \brief Free the allocated memory.
80  *
81  * \param[in] ptr Buffer pointer want to free.
82  */
83 void tfm_pool_free(void *ptr);
84 
85 #endif
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.