1 /*******************************************************************************
2 * The confidential and proprietary information contained in this file may      *
3 * only be used by a person authorised under and to the extent permitted        *
4 * by a subsisting licensing agreement from ARM Limited or its affiliates.      *
5 *   (C) COPYRIGHT [2001-2017] ARM Limited or its affiliates.                   *
6 *       ALL RIGHTS RESERVED                                                    *
7 * This entire notice must be reproduced on all copies of this file             *
8 * and copies of this file may only be made by a person if such person is       *
9 * permitted to do so under the terms of a subsisting license agreement         *
10 * from ARM Limited or its affiliates.                                          *
11 *******************************************************************************/
12 
13 #ifndef TEST_PAL_MEM_H_
14 #define TEST_PAL_MEM_H_
15 
16 #include <stdint.h>
17 #include <stdio.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /******************************************************************************/
24 /* Note: When TrustZone-M is supported, the following functions use NON SECURE*/
25 /* memory by default.                                                         */
26 /******************************************************************************/
27 
28 /******************************************************************************/
29 /*
30  * @brief This function allocates "size" bytes.
31  * When TZM is supported, it is used only for NON SECURE memory allocations.
32  *
33  * @param[in] size in bytes.
34  *
35  * @param[out]
36  *
37  * @return pointer to the allocated memory.
38  */
39 void *Test_PalMalloc(size_t size);
40 
41 /******************************************************************************/
42 /*
43  * @brief This function frees allocated memory pointed by pvAddress.
44  * When TZM is supported, it is used only for NON SECURE memory blocks.
45  *
46  * @param[in] pvAddress - pointer to the allocated memory.
47  *
48  * @param[out]
49  *
50  * @return
51  */
52 void Test_PalFree(void *pvAddress);
53 
54 /******************************************************************************/
55 /*
56  * @brief This function changes the size of the memory block pointed by
57  * pvAddress.
58  * If the function fails to allocate the requested block of memory:
59  * 1. a null pointer is returned.
60  * 2. The memory block pointed by argument pvAddress is NOT deallocated.
61  * When TZM is supported, it is used only for NON SECURE memory blocks.
62  *
63  * @param[in]
64  * pvAddress - Pointer to the allocated memory.
65  * newSize - New size.
66  *
67  * @param[out]
68  *
69  * @return - a pointer to the new allocated memory or NULL in case of failure.
70  */
71 void *Test_PalRealloc(void *pvAddress, size_t newSize);
72 
73 /******************************************************************************/
74 /*
75  * @brief This function allocates a DMA-contiguous buffer and returns its
76  * address.
77  * When TZM is supported, it is used only for NON SECURE buffer allocations.
78  *
79  * @param[in] size - Buffer size in bytes.
80  *
81  * @param[out]
82  *
83  * @return an address of the allocated buffer.
84  */
85 void *Test_PalDMAContigBufferAlloc(size_t size);
86 
87 /******************************************************************************/
88 /*
89  * @brief This function frees resources previously allocated by
90  * Test_PalDMAContigBufferAlloc.
91  *
92  * When TZM is supported, it is used only for NON SECURE buffers.
93  *
94  * @param[in] pvAddress - address of the allocated buffer.
95  *
96  * @param[out]
97  *
98  * @return
99  */
100 void Test_PalDMAContigBufferFree(void *pvAddress);
101 
102 /******************************************************************************/
103 /*
104  * @brief This function changes the size of the memory block pointed by
105  * pvAddress.
106  * If the function fails to allocate the requested block of memory:
107  * 1. a null pointer is returned.
108  * 2. The memory block pointed by argument pvAddress is NOT deallocated.
109  * When TZM is supported, it is used only for NON SECURE buffers.
110  *
111  * @param[in]
112  * pvAddress - Pointer to the allocated memory.
113  * newSize - New size in bytes.
114  *
115  * @param[out]
116  *
117  * @return - a pointer to the new allocated memory.
118  */
119 void *Test_PalDMAContigBufferRealloc(void *pvAddress, size_t newSize);
120 
121 /******************************************************************************/
122 /*
123  * @brief This function returns DMA base address, i.e. the start address
124  * of the DMA region.
125  * When TZM is supported, it returns the NON SECURE DMA base address.
126  *
127  * @param[in]
128  *
129  * @param[out]
130  *
131  * @return - DMABaseAddr.
132  */
133 unsigned long Test_PalGetDMABaseAddr(void);
134 
135 /******************************************************************************/
136 /*
137  * @brief This function returns the unmanaged base address.
138  * When TZM is supported, it returns the NON SECURE unmanaged base address.
139  *
140  * @param[in]
141  *
142  * @param[out]
143  *
144  * @return - UnmanagedBaseAddr.
145  */
146 unsigned long Test_PalGetUnmanagedBaseAddr(void);
147 
148 /******************************************************************************/
149 /*
150  * @brief This function initializes DMA memory management.
151  * When TZM is supported, it initializes the NON SECURE DMA memory management.
152  *
153  * @param[in]
154  * newDMABaseAddr - new DMA start address.
155  * newUnmanagedBaseAddr - new unmanaged start address.
156  * DMAsize - DMA region size.
157  *
158  * @param[out]
159  *
160  * @return rc - 0 for success, 1 for failure.
161  */
162 uint32_t Test_PalMemInit(unsigned long newDMABaseAddr,
163              unsigned long newUnmanagedBaseAddr,
164              size_t DMAsize);
165 
166 /******************************************************************************/
167 /*
168  * @brief This function sets this driver to its initial state.
169  * When TZM is supported, it sets the NON SECURE management to its initial
170  * state.
171  *
172  * @param[in]
173  *
174  * @param[out]
175  *
176  * @return rc - 0 for success, 1 for failure.
177  */
178 uint32_t Test_PalMemFin(void);
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif /* TEST_PAL_MEM_H_ */
185