1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2015, Atmel Corporation
\r
6 * All rights reserved.
\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
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\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
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
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
36 /*----------------------------------------------------------------------------
\r
38 *----------------------------------------------------------------------------*/
\r
39 #define CP15_L4_BIT 15 // Determines if the T bit is set when load instructions
\r
41 // 0 = loads to PC set the T bit
\r
42 // 1 = loads to PC do not set T bit
\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
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
52 #define CP15_I_BIT 12 // I bit Icache enable/disable:
\r
53 // 0 = Icache disabled
\r
54 // 1 = Icache enabled
\r
56 #define CP15_R_BIT 9 // R bit ROM protection
\r
58 #define CP15_S_BIT 8 // S bit System protection
\r
60 #define CP15_B_BIT 7 // B bit Endianness:
\r
61 // 0 = Little-endian operation
\r
62 // 1 = Big-endian operation.
\r
64 #define CP15_C_BIT 2 // C bit Dcache enable/disable:
\r
65 // 0 = cache disabled
\r
66 // 1 = cache enabled
\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
72 #define CP15_M_BIT 0 // M bit MMU enable/disable: 0 = disabled 1 = enabled.
\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
83 #define CP15_ICache 1
\r
84 #define CP15_DCache 0
\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
91 /*------------------------------------------------------------------------------ */
\r
92 /* Exported functions */
\r
93 /*------------------------------------------------------------------------------ */
\r
96 * \brief Read the Main ID Register (MIDR).
\r
97 * \return register contents
\r
99 extern unsigned int cp15_read_id(void);
\r
102 * \brief Read the System Control Register (SCTLR).
\r
103 * \return register contents
\r
105 extern unsigned int cp15_read_control(void);
\r
108 * \brief Indicate CPU that L2 is in exclusive caching mode.
\r
110 extern void cp15_exclusive_cache(void);
\r
113 * \brief Allow data to reside in the L1 and L2 caches at the same time.
\r
115 extern void cp15_non_exclusive_cache(void);
\r
118 * \brief Instruction Synchronization Barrier operation.
\r
120 extern void cp15_isb(void);
\r
123 * \brief Data Synchronization Barrier operation.
\r
125 extern void cp15_dsb(void);
\r
128 * \brief Data Memory Barrier operation.
\r
130 extern void cp15_dmb(void);
\r
133 * \brief Invalidate unified Translation Lookaside Buffer.
\r
135 extern void cp15_invalidate_tlb(void);
\r
138 * \brief Select the data cache as the one to later retrieve architecture
\r
139 * information about.
\r
141 extern void cp15_select_dcache(void);
\r
144 * \brief Select the instruction cache as the one to later retrieve architecture
\r
145 * information about.
\r
147 extern void cp15_select_icache(void);
\r
150 * \brief Modify the System Control Register (SCTLR).
\r
151 * This register specifies the configuration used to enable and disable the
\r
153 * It is recommended that you access this register using a read-modify-
\r
155 * \param value new value for SCTLR
\r
157 extern void cp15_write_control(unsigned int value);
\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
164 extern void cp15_write_ttb(unsigned int value);
\r
167 * \brief Modify the Domain Access Control Register (DACR).
\r
168 * \param value new value for DACR
\r
170 extern void cp15_write_domain_access_control(unsigned int value);
\r
173 * \brief Invalidate I cache predictor array to point of unification Inner
\r
176 extern void cp15_invalid_icache_inner_sharable(void);
\r
179 * \brief Invalidate entire branch predictor array Inner Shareable
\r
181 extern void cp15_invalid_btb_inner_sharable(void);
\r
184 * \brief Invalidate all instruction caches to point of unification.
\r
185 * Also flush branch target cache.
\r
187 extern void cp15_invalid_icache(void);
\r
190 * \brief Invalidate instruction caches by virtual address to point of
\r
193 extern void cp15_invalid_icache_by_mva(void);
\r
196 * \brief Invalidate entire branch predictor array.
\r
198 extern void cp15_invalid_btb(void);
\r
201 * \brief Invalidate branch predictor array entry by modified virtual address.
\r
202 * \param addr virtual address
\r
204 extern void cp15_invalid_btb_by_mva(uint32_t addr);
\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
211 extern void cp15_invalid_dcache_by_set_way(void);
\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
218 extern void cp15_clean_dcache_by_set_way(void);
\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
225 extern void cp15_clean_invalid_dcache_by_set_way(void);
\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
232 extern void cp15_invalid_dcache_by_mva(uint32_t start, uint32_t end);
\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
239 extern void cp15_clean_dcache_by_mva(uint32_t start, uint32_t end);
\r
242 * \brief Clean and invalidate data cache by virtual address to point of
\r
244 * \param start virtual start address of region
\r
245 * \param end virtual end address of region
\r
247 extern void cp15_clean_invalid_dcache_by_mva(uint32_t start, uint32_t end);
\r
250 * \brief Clean unified cache by modified virtual address to point of
\r
253 extern void cp15_clean_dcache_umva(void);
\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
262 extern void cp15_coherent_dcache_for_dma(uint32_t start, uint32_t end);
\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
274 extern void cp15_invalidate_dcache_for_dma(uint32_t start, uint32_t end);
\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
281 extern void cp15_clean_dcache_for_dma(uint32_t start, uint32_t end);
\r
284 * \brief Flush, i.e. clean and invalidate, the data cache within the specified
\r
286 * \param start virtual start address of region
\r
287 * \param end virtual end address of region
\r
289 extern void cp15_flush_dcache_for_dma(uint32_t start, uint32_t end);
\r
291 /*------------------------------------------------------------------------------ */
\r
292 /* Exported functions from CP15.c */
\r
293 /*------------------------------------------------------------------------------ */
\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
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
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
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
318 #endif // #ifndef _CP15_H
\r