]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/cortex-a/cp15.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / cortex-a / cp15.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2015, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21 \r
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
27  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28  * ----------------------------------------------------------------------------\r
29  */\r
30 \r
31 #ifndef _CP15_H\r
32 #define _CP15_H\r
33 \r
34 #include <stdint.h>\r
35 \r
36 /*----------------------------------------------------------------------------\r
37  *        Definition\r
38  *----------------------------------------------------------------------------*/\r
39 #define CP15_L4_BIT 15          // Determines if the T bit is set when load instructions\r
40 // change the PC:\r
41 // 0 = loads to PC set the T bit\r
42 // 1 = loads to PC do not set T bit\r
43 \r
44 #define CP15_RR_BIT 14          // RR bit Replacement strategy for Icache and Dcache:\r
45 // 0 = Random replacement\r
46 // 1 = Round-robin replacement.\r
47 \r
48 #define CP15_V_BIT  13          // V bit Location of exception vectors:\r
49 // 0 = Normal exception vectors selected address range = 0x0000 0000 to 0x0000 001C\r
50 // 1 = High exception vect selected, address range = 0xFFFF 0000 to 0xFFFF 001C\r
51 \r
52 #define CP15_I_BIT  12          // I bit Icache enable/disable:\r
53 // 0 = Icache disabled\r
54 // 1 = Icache enabled\r
55 \r
56 #define CP15_R_BIT   9          // R bit ROM protection\r
57 \r
58 #define CP15_S_BIT   8          // S bit System protection\r
59 \r
60 #define CP15_B_BIT   7          // B bit Endianness:\r
61 // 0 = Little-endian operation\r
62 // 1 = Big-endian operation.\r
63 \r
64 #define CP15_C_BIT   2          // C bit Dcache enable/disable:\r
65 // 0 = cache disabled\r
66 // 1 = cache enabled\r
67 \r
68 #define CP15_A_BIT   1          // A bit Alignment fault enable/disable:\r
69 // 0 = Data address alignment fault checking disabled\r
70 // 1 = Data address alignment fault checking enabled\r
71 \r
72 #define CP15_M_BIT   0          // M bit MMU enable/disable: 0 = disabled 1 = enabled.\r
73 // 0 = disabled\r
74 // 1 = enabled\r
75 \r
76 /** No access Any access generates a domain fault. */\r
77 #define CP15_DOMAIN_NO_ACCESS      0x00\r
78 /** Client Accesses are checked against the access permission bits in the section or page descriptor. */\r
79 #define CP15_DOMAIN_CLIENT_ACCESS  0x01\r
80 /** Manager Accesses are not checked against the access permission bits so a permission fault cannot be generated. */\r
81 #define CP15_DOMAIN_MANAGER_ACCESS 0x03\r
82 \r
83 #define CP15_ICache             1\r
84 #define CP15_DCache             0\r
85 \r
86 #define CP15_PMCNTENSET_ENABLE  31\r
87 #define CP15_PMCR_DIVIDER       3\r
88 #define CP15_PMCR_RESET         2\r
89 #define CP15_PMCR_ENABLE        0\r
90 \r
91 /*------------------------------------------------------------------------------ */\r
92 /*         Exported functions */\r
93 /*------------------------------------------------------------------------------ */\r
94 \r
95 /**\r
96  * \brief Read the Main ID Register (MIDR).\r
97  * \return register contents\r
98  */\r
99 extern unsigned int cp15_read_id(void);\r
100 \r
101 /**\r
102  * \brief Read the System Control Register (SCTLR).\r
103  * \return register contents\r
104  */\r
105 extern unsigned int cp15_read_control(void);\r
106 \r
107 /**\r
108  * \brief Indicate CPU that L2 is in exclusive caching mode.\r
109  */\r
110 extern void cp15_exclusive_cache(void);\r
111 \r
112 /**\r
113  * \brief Allow data to reside in the L1 and L2 caches at the same time.\r
114  */\r
115 extern void cp15_non_exclusive_cache(void);\r
116 \r
117 /**\r
118  * \brief Instruction Synchronization Barrier operation.\r
119  */\r
120 extern void cp15_isb(void);\r
121 \r
122 /**\r
123  * \brief Data Synchronization Barrier operation.\r
124  */\r
125 extern void cp15_dsb(void);\r
126 \r
127 /**\r
128  * \brief Data Memory Barrier operation.\r
129  */\r
130 extern void cp15_dmb(void);\r
131 \r
132 /**\r
133  * \brief Invalidate unified Translation Lookaside Buffer.\r
134  */\r
135 extern void cp15_invalidate_tlb(void);\r
136 \r
137 /**\r
138  * \brief Select the data cache as the one to later retrieve architecture\r
139  *      information about.\r
140  */\r
141 extern void cp15_select_dcache(void);\r
142 \r
143 /**\r
144  * \brief Select the instruction cache as the one to later retrieve architecture\r
145  *      information about.\r
146  */\r
147 extern void cp15_select_icache(void);\r
148 \r
149 /**\r
150  * \brief Modify the System Control Register (SCTLR).\r
151  *      This register specifies the configuration used to enable and disable the\r
152  *      caches and MMU.\r
153  *      It is recommended that you access this register using a read-modify-\r
154  *      write sequence.\r
155  * \param value new value for SCTLR\r
156  */\r
157 extern void cp15_write_control(unsigned int value);\r
158 \r
159 /**\r
160  * \brief ARMv7A architecture supports two translation tables.\r
161  *      Configure translation table base (TTB) control register 0.\r
162  * \param value address of our page table base\r
163  */\r
164 extern void cp15_write_ttb(unsigned int value);\r
165 \r
166 /**\r
167  * \brief Modify the Domain Access Control Register (DACR).\r
168  * \param value new value for DACR\r
169  */\r
170 extern void cp15_write_domain_access_control(unsigned int value);\r
171 \r
172 /**\r
173  * \brief Invalidate I cache predictor array to point of unification Inner\r
174  *      Shareable.\r
175  */\r
176 extern void cp15_invalid_icache_inner_sharable(void);\r
177 \r
178 /**\r
179  * \brief Invalidate entire branch predictor array Inner Shareable\r
180  */\r
181 extern void cp15_invalid_btb_inner_sharable(void);\r
182 \r
183 /**\r
184  * \brief Invalidate all instruction caches to point of unification.\r
185  *      Also flush branch target cache.\r
186  */\r
187 extern void cp15_invalid_icache(void);\r
188 \r
189 /**\r
190  * \brief Invalidate instruction caches by virtual address to point of\r
191  *      unification.\r
192  */\r
193 extern void cp15_invalid_icache_by_mva(void);\r
194 \r
195 /**\r
196  * \brief Invalidate entire branch predictor array.\r
197  */\r
198 extern void cp15_invalid_btb(void);\r
199 \r
200 /**\r
201  * \brief Invalidate branch predictor array entry by modified virtual address.\r
202  * \param addr virtual address\r
203  */\r
204 extern void cp15_invalid_btb_by_mva(uint32_t addr);\r
205 \r
206 /**\r
207  * \brief Invalidate entire data cache by set/way.\r
208  *      Should be called further to cp15_select_dcache(), not\r
209  *      cp15_select_icache().\r
210  */\r
211 extern void cp15_invalid_dcache_by_set_way(void);\r
212 \r
213 /**\r
214  * \brief Clean entire data cache by set/way.\r
215  *      Should be called further to cp15_select_dcache(), not\r
216  *      cp15_select_icache().\r
217  */\r
218 extern void cp15_clean_dcache_by_set_way(void);\r
219 \r
220 /**\r
221  * \brief Clean and invalidate entire data cache by set/way\r
222  *      Should be called further to cp15_select_dcache(), not\r
223  *      cp15_select_icache().\r
224  */\r
225 extern void cp15_clean_invalid_dcache_by_set_way(void);\r
226 \r
227 /**\r
228  * \brief Invalidate data cache by virtual address to point of coherency.\r
229  * \param start virtual start address of region\r
230  * \param end virtual end address of region\r
231  */\r
232 extern void cp15_invalid_dcache_by_mva(uint32_t start, uint32_t end);\r
233 \r
234 /**\r
235  * \brief Clean data cache by modified virtual address to point of coherency.\r
236  * \param start virtual start address of region\r
237  * \param end virtual end address of region\r
238  */\r
239 extern void cp15_clean_dcache_by_mva(uint32_t start, uint32_t end);\r
240 \r
241 /**\r
242  * \brief Clean and invalidate data cache by virtual address to point of\r
243  *      coherency.\r
244  * \param start virtual start address of region\r
245  * \param end virtual end address of region\r
246  */\r
247 extern void cp15_clean_invalid_dcache_by_mva(uint32_t start, uint32_t end);\r
248 \r
249 /**\r
250  * \brief Clean unified cache by modified virtual address to point of\r
251  *      unification.\r
252  */\r
253 extern void cp15_clean_dcache_umva(void);\r
254 \r
255 /**\r
256  * \brief Ensure that the I and D caches are coherent within the specified\r
257  *      region. This is typically used when code has been written to\r
258  *      a memory region, and will be executed.\r
259  * \param start virtual start address of region\r
260  * \param end virtual end address of region\r
261  */\r
262 extern void cp15_coherent_dcache_for_dma(uint32_t start, uint32_t end);\r
263 \r
264 /**\r
265  * \brief Invalidate the data cache within the specified region; we will\r
266  *      be performing a DMA operation in this region and we want to purge the\r
267  *      cache of old data. Cache data will be discarded, not flushed.\r
268  *      The specified region should be aligned on cache lines. Otherwise mind\r
269  *      the data loss that may occur in the collateral part of start/end lines,\r
270  *      since cache data won't be flushed.\r
271  * \param start virtual start address of region\r
272  * \param end virtual end address of region\r
273  */\r
274 extern void cp15_invalidate_dcache_for_dma(uint32_t start, uint32_t end);\r
275 \r
276 /**\r
277  * \brief Clean the data cache within the specified region.\r
278  * \param start virtual start address of region\r
279  * \param end virtual end address of region\r
280  */\r
281 extern void cp15_clean_dcache_for_dma(uint32_t start, uint32_t end);\r
282 \r
283 /**\r
284  * \brief Flush, i.e. clean and invalidate, the data cache within the specified\r
285  *      region.\r
286  * \param start virtual start address of region\r
287  * \param end virtual end address of region\r
288  */\r
289 extern void cp15_flush_dcache_for_dma(uint32_t start, uint32_t end);\r
290 \r
291 /*------------------------------------------------------------------------------ */\r
292 /*         Exported functions  from CP15.c                                       */\r
293 /*------------------------------------------------------------------------------ */\r
294 \r
295 /** MMU (Status/Enable/Disable) */\r
296 extern unsigned int cp15_is_mmu_enabled(void);\r
297 extern void cp15_enable_mmu(void);\r
298 extern void cp15_disable_mmu(void);\r
299 \r
300 /** I cache (Status/Enable/Disable) */\r
301 extern unsigned int cp15_is_icached_enabled(void);\r
302 extern void cp15_enable_icache(void);\r
303 extern void cp15_disable_icache(void);\r
304 \r
305 /** D cache (Status/Enable/Disable) */\r
306 extern unsigned int cp15_is_dcache_enabled(void);\r
307 extern void cp15_enable_dcache(void);\r
308 extern void cp15_disable_dcache(void);\r
309 \r
310 extern void cp15_dcache_clean(void);\r
311 extern void cp15_dcache_invalidate(void);\r
312 extern void cp15_icache_invalidate(void);\r
313 extern void cp15_dcache_flush(void);\r
314 extern void cp15_invalid_dcache_by_va(uint32_t S_Add, uint32_t E_Add);\r
315 extern void cp15_clean_dcache_by_va(uint32_t S_Add, uint32_t E_Add);\r
316 extern void cp15_flush_dcache_by_va(uint32_t S_Add, uint32_t E_Add);\r
317 \r
318 #endif                          // #ifndef _CP15_H\r