]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/peripherals/l2cc.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / peripherals / l2cc.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  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * Interface for Level 2 cache (L2CC) controller.\r
34  *\r
35  */\r
36 \r
37 /** \addtogroup l2cc_module L2 Cache Operations\r
38  * \ingroup cache_module\r
39  * \section Usage\r
40  * - Enable or disable L2CC with L2CC_Enable() or L2CC_Disable().\r
41  * - Check if L2CC is enabled with L2CC_IsEnabled().\r
42  * - Enable or disable L2CC interrupt with L2CC_EnableIT() or L2CC_DisableIT().\r
43  * - Enable data or instruction prefetch with L2CC_DataPrefetchEnable() or L2CC_InstPrefetchEnable().\r
44  *\r
45  * Related files:\n\r
46  * \ref l2cc.h\n\r
47  * \ref l2cc.c\n\r
48  */\r
49 \r
50 #ifndef _L2CC_H\r
51 #define _L2CC_H\r
52 \r
53 /*----------------------------------------------------------------------------\r
54  *        Headers\r
55  *----------------------------------------------------------------------------*/\r
56 #include "chip.h"\r
57 \r
58 #include <assert.h>\r
59 \r
60 /*----------------------------------------------------------------------------\r
61  *        Define\r
62  *----------------------------------------------------------------------------*/\r
63 \r
64 #ifdef __cplusplus\r
65 extern "C" {\r
66 #endif\r
67 \r
68 #define OFFSET_BIT      5\r
69 #define INDEX_BIT       9\r
70 #define TAG_BIT         18\r
71 \r
72 #define L2CC_RESET_EVCOUNTER0        0\r
73 #define L2CC_RESET_EVCOUNTER1        1\r
74 #define L2CC_RESET_BOTH_COUNTER      3\r
75 \r
76 #define FWA_DEFAULT             0u\r
77 #define FWA_NO_ALLOCATE         1u\r
78 #define FWA_FORCE_ALLOCATE      2u\r
79 #define FWA_INTERNALLY_MAPPED   3u\r
80 \r
81 /*----------------------------------------------------------------------------\r
82 *        Types\r
83 *----------------------------------------------------------------------------*/\r
84 \r
85 enum _maint_op {\r
86         L2CC_DCACHE_CLEAN,\r
87         L2CC_DCACHE_INVAL,\r
88         L2CC_DCACHE_FLUSH\r
89 };\r
90 \r
91 struct _latency {\r
92         uint8_t setup;\r
93         uint8_t read;\r
94         uint8_t write;\r
95 };\r
96 \r
97 struct _ram_latency_control {\r
98         struct _latency tag;\r
99         struct _latency data;\r
100 };\r
101 \r
102 /** L2CC structure */\r
103 struct _l2cc_control {\r
104         /** High Priority for SO and Dev Reads Enable */\r
105         uint32_t high_prior_so:    1,\r
106         /** Store Buffer Device Limitation Enable */\r
107                 store_buff_dev_limit:    1,\r
108         /** Shared Attribute Invalidate Enable */\r
109                 shared_attr_invalidate:     1,\r
110         /** Event Monitor Bus Enable */\r
111                 evt_mon_bus:    1,\r
112         /** Parity Enable */\r
113                 parity:      1,\r
114         /** Shared Attribute Override Enable */\r
115                 shared_attr_override:    1,\r
116         /** Force Write Allocate */\r
117                 force_write_alloc:      2,\r
118         /** Cache Replacement Policy */\r
119                 cache_replacement:    1,\r
120         /** Non-Secure Lockdown Enable*/\r
121                 non_sec_lockdown:    1,\r
122         /** Non-Secure Interrupt Access Control */\r
123                 it_acces_non_sec:    1,\r
124         /** Data Prefetch Enable*/\r
125                 data_prefetch:     1,\r
126         /** Instruction Prefetch Enable */\r
127                 instruct_prefetch:     1,\r
128         /** Prefetch Offset */\r
129                 offset:   5,\r
130         /** Not Same ID on Exclusive Sequence Enable */\r
131                 exclusive_seq_same_id:   1,\r
132         /** INCR Double Linefill Enable */\r
133                 incr_double_linefill:    1,\r
134         /** Prefetch Drop Enable*/\r
135                 prefetch_drop:     1,\r
136         /** Double Linefill on WRAP Read Disable */\r
137                 DLFWRDIS: 1,\r
138         /** Double linefill Enable */\r
139                 double_linefill:     1,\r
140         /** Standby Mode Enable */\r
141                 standby_mode:   1,\r
142         /** Dynamic Clock Gating Enable */\r
143                 dyn_clock_gating: 1,\r
144         /** Disable Cache Linefill*/\r
145                 no_cache_linefill:      1,\r
146         /** Disable Write-back, Force Write-through */\r
147                 no_write_back:      1;\r
148 };\r
149 /*----------------------------------------------------------------------------\r
150  *        Exported functions\r
151  *----------------------------------------------------------------------------*/\r
152 \r
153 /**\r
154  * \brief Check if Level 2 cache is enable.\r
155  */\r
156 extern uint32_t l2cc_is_enabled(void);\r
157 \r
158 /**\r
159  * \brief Enable Level 2 cache.\r
160  */\r
161 extern void l2cc_enable(void);\r
162 \r
163 /**\r
164  * \brief Disable Level 2 cache.\r
165  */\r
166 extern void l2cc_disable(void);\r
167 \r
168 /**\r
169  * \brief Configures Level 2 cache as exclusive cache.\r
170  * \param Enable Enable/disable exclusive cache.\r
171  */\r
172 extern void l2cc_exclusive_cache(uint8_t enable);\r
173 \r
174 /**\r
175  * \brief Configures Level 2 cache RAM Latency (Tag and Data).\r
176  * \param latencies  Structure containing RAM Tag and Data latencies\r
177  */\r
178 extern void l2cc_config_lat_ram(struct _ram_latency_control * latencies);\r
179 \r
180 /**\r
181  * \brief Configures Level 2 cache.\r
182  * \param cfg  Configuration values to put in Auxiliary, prefetch,\r
183  * debug and powercontrol registers.\r
184  */\r
185 extern void l2cc_set_config(const struct _l2cc_control* cfg);\r
186 \r
187 /**\r
188  * \brief Enables Data prefetch on L2\r
189  */\r
190 extern void l2cc_data_prefetch_enable(void);\r
191 \r
192 /**\r
193  * \brief Enables instruction prefetch on L2\r
194  */\r
195 extern void l2cc_inst_prefetch_enable(void);\r
196 \r
197 /**\r
198  * \brief Enables instruction prefetch on L2\r
199  * \param event_counter Counter of the events.\r
200  */\r
201 extern void l2cc_enable_reset_counter(uint8_t event_counter);\r
202 \r
203 /**\r
204  * \brief Configures Event of Level 2 cache.\r
205  * \param event_counter  Eventcounter 1 or 0\r
206  * \param source  Event Genration source\r
207  * \param it  Event Counter Interrupt Generation condition\r
208  */\r
209 extern void l2cc_event_config(uint8_t event_counter, uint8_t source,\r
210                               uint8_t it);\r
211 \r
212 /**\r
213  * \brief Reads Event Counter value.\r
214  * \param event_counter  choose Eventcounter 1 or 0\r
215  */\r
216 extern uint32_t l2cc_event_counter_value(uint8_t event_counter);\r
217 \r
218 /**\r
219  * \brief Enable interrupts\r
220  * \param sources  Interrupt source\r
221  */\r
222 extern void l2cc_enable_it(uint16_t sources);\r
223 \r
224 /**\r
225  * \brief Disable interrupts\r
226  * \param sources  Interrupt source\r
227  */\r
228 extern void l2cc_disable_it(uint16_t sources);\r
229 \r
230 /**\r
231  * \brief Enabled interrupt's raw status\r
232  * \param sources  Interrupt source\r
233  */\r
234 extern uint16_t l2cc_it_status_raw(uint16_t sources);\r
235 \r
236 /**\r
237  * \brief Status of masked interrupts\r
238  * \param sources  Interrupt source\r
239  */\r
240 extern uint16_t l2cc_it_status_mask(uint16_t sources);\r
241 \r
242 /**\r
243  * \brief Clear interrupts\r
244  * \param sources  Interrupt source\r
245  */\r
246 extern void l2cc_it_clear(uint16_t sources);\r
247 \r
248 /**\r
249  * \brief Poll SPNIDEN signal\r
250  */\r
251 extern uint8_t l2cc_poll_spniden(void);\r
252 \r
253 /**\r
254  * \brief Synchronizes the L2 cache\r
255  */\r
256 extern void l2cc_cache_sync(void);\r
257 \r
258 /**\r
259  * \brief Invalidate cache by way\r
260  * \param way  way number\r
261  */\r
262 extern void l2cc_invalidate_way(uint8_t way);\r
263 \r
264 /**\r
265  * \brief Clean cache by way\r
266  * \param way  way number\r
267  */\r
268 extern void l2cc_clean_way(uint8_t way);\r
269 \r
270 /**\r
271  * \brief Invalidate cache by Physical addersse\r
272  * \param phys_addr  Physical addresse\r
273  */\r
274 extern void l2cc_invalidate_pal(uint32_t phys_addr);\r
275 \r
276 /**\r
277  * \brief Clean cache by Physical addersse\r
278  * \param phys_addr  Physical addresse\r
279  */\r
280 extern void l2cc_clean_pal(uint32_t phys_addr);\r
281 \r
282 /**\r
283  * \brief Clean index cache by Physical addersse\r
284  * \param phys_addr  Physical addresse\r
285  */\r
286 extern void l2cc_clean_ix(uint32_t phys_addr);\r
287 \r
288 /**\r
289  * \brief Clean cache by Index\r
290  * \param phys_addr  Physical addresse\r
291  * \param way  way number\r
292  */\r
293 extern void l2cc_clean_index(uint32_t phys_addr, uint8_t way);\r
294 \r
295 /**\r
296  * \brief Clean Invalidate cache by index\r
297  * \param phys_addr  Physical address\r
298  * \param way  way number\r
299  */\r
300 extern void l2cc_clean_invalidate_index(uint32_t phys_addr, uint8_t way);\r
301 \r
302 /**\r
303  * \brief cache Data lockdown\r
304  * \param way  way number\r
305  */\r
306 extern void l2cc_data_lockdown(uint8_t way);\r
307 \r
308 /**\r
309  * \brief cache instruction lockdown\r
310  * \param way  way number\r
311  */\r
312 extern void l2cc_instruction_lockdown(uint8_t way);\r
313 \r
314 /**\r
315  *  \brief L2 DCache maintenance (clean/invalidate/flush)\r
316  *\r
317  *  \param maintenance Maintenance operation to apply: \sa #_maint_op\r
318  */\r
319 extern void l2cc_cache_maintenance(enum _maint_op maintenance);\r
320 \r
321 /**\r
322  *  \brief Invalidate cache lines corresponding to a memory region\r
323  *\r
324  *  \param start Beginning of the memory region\r
325  *  \param end End of the memory region\r
326  */\r
327 extern void l2cc_invalidate_region(uint32_t start, uint32_t end);\r
328 \r
329 /**\r
330  *  \brief Clean cache lines corresponding to a memory region\r
331  *\r
332  *  \param start Beginning of the memory region\r
333  *  \param end End of the memory region\r
334  */\r
335 extern void l2cc_clean_region(uint32_t start, uint32_t end);\r
336 \r
337 /**\r
338  *  \brief Enable level two cache controller (L2CC)\r
339  *\r
340  *  \param cfg configuration to apply: \sa #_l2cc_control\r
341  */\r
342 extern void l2cc_configure(const struct _l2cc_control* cfg);\r
343 \r
344 #ifdef __cplusplus\r
345 }\r
346 #endif\r
347 #endif                          /* #ifndef _L2CC_ */\r