1 /******************************************************************************
3 * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
37 * This header file contains cache related driver functions (or macros)
38 * that can be used to access the device. The user should refer to the
39 * hardware device specification for more details of the device operation.
40 * The functions in this header file can be used across all Xilinx supported
44 * MODIFICATION HISTORY:
46 * Ver Who Date Changes
47 * ----- ---- -------- -------------------------------------------------------
48 * 1.00 hbm 07/28/09 Initial release
49 * 3.02a sdm 10/24/11 Updated the file to include xparameters.h so that
50 * the correct cache flush routines are used based on
51 * whether the write-back or write-through caches are
53 * 3.10a asa 05/04/13 This version of MicroBlaze BSP adds support for system
54 * cache/L2 cache. The existing/old APIs/macros in this
55 * file are renamed to imply that they deal with L1 cache.
56 * New macros/APIs are added to address similar features for
57 * L2 cache. Users can include this file in their application
58 * to use the various cache related APIs. These changes are
59 * done for implementing PR #697214.
67 ******************************************************************************/
72 #if defined XENV_VXWORKS
73 /* VxWorks environment */
74 #error "Unknown processor / architecture. Must be PPC for VxWorks."
76 /* standalone environment */
78 #include "mb_interface.h"
79 #include "xil_types.h"
80 #include "xparameters.h"
86 /****************************************************************************/
89 * Invalidate the entire L1 data cache. If the cacheline is modified (dirty),
90 * the modified contents are lost.
98 * Processor must be in real mode.
99 ****************************************************************************/
100 #define Xil_L1DCacheInvalidate() microblaze_invalidate_dcache()
102 /****************************************************************************/
105 * Invalidate the entire L2 data cache. If the cacheline is modified (dirty),
106 * the modified contents are lost.
114 * Processor must be in real mode.
115 ****************************************************************************/
116 #define Xil_L2CacheInvalidate() microblaze_invalidate_cache_ext()
118 /****************************************************************************/
121 * Invalidate the L1 data cache for the given address range.
122 * If the bytes specified by the address (Addr) are cached by the L1 data cache,
123 * the cacheline containing that byte is invalidated. If the cacheline
124 * is modified (dirty), the modified contents are lost.
126 * @param Addr is address of ragne to be invalidated.
127 * @param Len is the length in bytes to be invalidated.
133 * Processor must be in real mode.
134 ****************************************************************************/
135 #define Xil_L1DCacheInvalidateRange(Addr, Len) \
136 microblaze_invalidate_dcache_range(Addr, Len)
138 /****************************************************************************/
141 * Invalidate the L1 data cache for the given address range.
142 * If the bytes specified by the address (Addr) are cached by the L1 data cache,
143 * the cacheline containing that byte is invalidated. If the cacheline
144 * is modified (dirty), the modified contents are lost.
146 * @param Addr is address of ragne to be invalidated.
147 * @param Len is the length in bytes to be invalidated.
153 * Processor must be in real mode.
154 ****************************************************************************/
155 #define Xil_L2CacheInvalidateRange(Addr, Len) \
156 microblaze_invalidate_cache_ext_range(Addr, Len)
158 /****************************************************************************/
160 * Flush the L1 data cache for the given address range.
161 * If the bytes specified by the address (Addr) are cached by the data cache,
162 * and is modified (dirty), the cacheline will be written to system memory.
163 * The cacheline will also be invalidated.
165 * @param Addr is the starting address of the range to be flushed.
166 * @param Len is the length in byte to be flushed.
170 ****************************************************************************/
171 #if (XPAR_MICROBLAZE_DCACHE_USE_WRITEBACK == 1)
172 # define Xil_L1DCacheFlushRange(Addr, Len) \
173 microblaze_flush_dcache_range(Addr, Len)
175 # define Xil_L1DCacheFlushRange(Addr, Len) \
176 microblaze_invalidate_dcache_range(Addr, Len)
177 #endif /* XPAR_MICROBLAZE_DCACHE_USE_WRITEBACK */
179 /****************************************************************************/
181 * Flush the L2 data cache for the given address range.
182 * If the bytes specified by the address (Addr) are cached by the data cache,
183 * and is modified (dirty), the cacheline will be written to system memory.
184 * The cacheline will also be invalidated.
186 * @param Addr is the starting address of the range to be flushed.
187 * @param Len is the length in byte to be flushed.
191 ****************************************************************************/
192 #define Xil_L2CacheFlushRange(Addr, Len) \
193 microblaze_flush_cache_ext_range(Addr, Len)
195 /****************************************************************************/
197 * Flush the entire L1 data cache. If any cacheline is dirty, the cacheline will be
198 * written to system memory. The entire data cache will be invalidated.
204 ****************************************************************************/
205 #if (XPAR_MICROBLAZE_DCACHE_USE_WRITEBACK == 1)
206 # define Xil_L1DCacheFlush() microblaze_flush_dcache()
208 # define Xil_L1DCacheFlush() microblaze_invalidate_dcache()
209 #endif /* XPAR_MICROBLAZE_DCACHE_USE_WRITEBACK */
211 /****************************************************************************/
213 * Flush the entire L2 data cache. If any cacheline is dirty, the cacheline will be
214 * written to system memory. The entire data cache will be invalidated.
220 ****************************************************************************/
221 #define Xil_L2CacheFlush() microblaze_flush_cache_ext()
223 /****************************************************************************/
226 * Invalidate the instruction cache for the given address range.
228 * @param Addr is address of ragne to be invalidated.
229 * @param Len is the length in bytes to be invalidated.
233 ****************************************************************************/
234 #define Xil_L1ICacheInvalidateRange(Addr, Len) \
235 microblaze_invalidate_icache_range(Addr, Len)
237 /****************************************************************************/
240 * Invalidate the entire instruction cache.
246 ****************************************************************************/
247 #define Xil_L1ICacheInvalidate() \
248 microblaze_invalidate_icache()
251 /****************************************************************************/
254 * Enable the L1 data cache.
258 * @note This is processor specific.
260 ****************************************************************************/
261 #define Xil_L1DCacheEnable() \
262 microblaze_enable_dcache()
264 /****************************************************************************/
267 * Disable the L1 data cache.
271 * @note This is processor specific.
273 ****************************************************************************/
274 #define Xil_L1DCacheDisable() \
275 microblaze_disable_dcache()
277 /****************************************************************************/
280 * Enable the instruction cache.
284 * @note This is processor specific.
286 ****************************************************************************/
287 #define Xil_L1ICacheEnable() \
288 microblaze_enable_icache()
290 /****************************************************************************/
293 * Disable the L1 Instruction cache.
297 * @note This is processor specific.
299 ****************************************************************************/
300 #define Xil_L1ICacheDisable() \
301 microblaze_disable_icache()
303 /****************************************************************************/
306 * Enable the data cache.
312 ****************************************************************************/
313 #define Xil_DCacheEnable() Xil_L1DCacheEnable()
315 /****************************************************************************/
318 * Enable the instruction cache.
327 ****************************************************************************/
328 #define Xil_ICacheEnable() Xil_L1ICacheEnable()
330 /****************************************************************************
332 * Invalidate the entire Data cache.
340 ****************************************************************************/
341 #define Xil_DCacheInvalidate() \
342 Xil_L2CacheInvalidate(); \
343 Xil_L1DCacheInvalidate();
346 /****************************************************************************
348 * Invalidate the Data cache for the given address range.
349 * If the bytes specified by the address (adr) are cached by the Data cache,
350 * the cacheline containing that byte is invalidated. If the cacheline
351 * is modified (dirty), the modified contents are lost and are NOT
352 * written to system memory before the line is invalidated.
354 * @param Start address of ragne to be invalidated.
355 * @param Length of range to be invalidated in bytes.
361 ****************************************************************************/
362 #define Xil_DCacheInvalidateRange(Addr, Len) \
363 Xil_L2CacheInvalidateRange(Addr, Len); \
364 Xil_L1DCacheInvalidateRange(Addr, Len);
367 /****************************************************************************
369 * Flush the entire Data cache.
377 ****************************************************************************/
378 #define Xil_DCacheFlush() \
379 Xil_L2CacheFlush(); \
382 /****************************************************************************
383 * Flush the Data cache for the given address range.
384 * If the bytes specified by the address (adr) are cached by the Data cache,
385 * the cacheline containing that byte is invalidated. If the cacheline
386 * is modified (dirty), the written to system memory first before the
387 * before the line is invalidated.
389 * @param Start address of range to be flushed.
390 * @param Length of range to be flushed in bytes.
396 ****************************************************************************/
397 #define Xil_DCacheFlushRange(Addr, Len) \
398 Xil_L2CacheFlushRange(Addr, Len); \
399 Xil_L1DCacheFlushRange(Addr, Len);
402 /****************************************************************************
404 * Invalidate the entire instruction cache.
412 ****************************************************************************/
413 #define Xil_ICacheInvalidate() \
414 Xil_L2CacheInvalidate(); \
415 Xil_L1ICacheInvalidate();
418 /****************************************************************************
420 * Invalidate the instruction cache for the given address range.
421 * If the bytes specified by the address (adr) are cached by the Data cache,
422 * the cacheline containing that byte is invalidated. If the cacheline
423 * is modified (dirty), the modified contents are lost and are NOT
424 * written to system memory before the line is invalidated.
426 * @param Start address of ragne to be invalidated.
427 * @param Length of range to be invalidated in bytes.
433 ****************************************************************************/
434 #define Xil_ICacheInvalidateRange(Addr, Len) \
435 Xil_L2CacheInvalidateRange(Addr, Len); \
436 Xil_L1ICacheInvalidateRange(Addr, Len);
438 void Xil_DCacheDisable(void);
439 void Xil_ICacheDisable(void);