1 /******************************************************************************
3 * Copyright (C) 2012 - 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.
33 * Scrub LMB memory and all internal BRAMs (data cache, instruction cache,
34 * MMU UTLB and branch target cache) in MicroBlaze to reduce the possibility
35 * of an uncorrectable error when fault tolerance support is enabled.
37 * This routine assumes that the processor is in privileged mode when it is
38 * called, if the MMU is enabled.
40 * Call this routine regularly from a timer interrupt.
46 *******************************************************************************/
48 #include "xparameters.h"
50 /* Define if fault tolerance is used */
51 #ifdef XPAR_MICROBLAZE_FAULT_TOLERANT
52 #if XPAR_MICROBLAZE_FAULT_TOLERANT > 0
53 #define FAULT_TOLERANT
57 /* Define if LMB is used and can be scrubbed */
58 #if defined(XPAR_MICROBLAZE_D_LMB) && \
59 defined(XPAR_DLMB_CNTLR_BASEADDR) && \
60 defined(XPAR_DLMB_CNTLR_HIGHADDR)
61 #if XPAR_MICROBLAZE_D_LMB == 1
62 #define HAS_SCRUBBABLE_LMB
63 #define DLMB_MASK (XPAR_DLMB_CNTLR_HIGHADDR - XPAR_DLMB_CNTLR_BASEADDR)
67 /* Set default cache line lengths */
68 #ifndef XPAR_MICROBLAZE_DCACHE_LINE_LEN
69 #define XPAR_MICROBLAZE_DCACHE_LINE_LEN 4
72 #ifndef XPAR_MICROBLAZE_ICACHE_LINE_LEN
73 #define XPAR_MICROBLAZE_ICACHE_LINE_LEN 4
76 /* Define if internal Data Cache BRAMs are used */
77 #if defined(XPAR_MICROBLAZE_USE_DCACHE) && defined(XPAR_MICROBLAZE_DCACHE_BYTE_SIZE)
78 #if XPAR_MICROBLAZE_USE_DCACHE == 1 && XPAR_MICROBLAZE_DCACHE_BYTE_SIZE > 1024
79 #define HAS_BRAM_DCACHE
80 #define DCACHE_INCREMENT (XPAR_MICROBLAZE_DCACHE_LINE_LEN * 4)
81 #define DCACHE_MASK (XPAR_MICROBLAZE_DCACHE_BYTE_SIZE - 1)
85 /* Define if internal Instruction Cache BRAMs are used */
86 #if defined(XPAR_MICROBLAZE_USE_ICACHE) && defined(XPAR_MICROBLAZE_CACHE_BYTE_SIZE)
87 #if XPAR_MICROBLAZE_USE_ICACHE == 1 && XPAR_MICROBLAZE_CACHE_BYTE_SIZE > 1024
88 #define HAS_BRAM_ICACHE
89 #define ICACHE_INCREMENT (XPAR_MICROBLAZE_ICACHE_LINE_LEN * 4)
90 #define ICACHE_MASK (XPAR_MICROBLAZE_CACHE_BYTE_SIZE - 1)
94 /* Define if internal MMU UTLB BRAM is used */
95 #ifdef XPAR_MICROBLAZE_USE_MMU
96 #if XPAR_MICROBLAZE_USE_MMU > 1
97 #define HAS_BRAM_MMU_UTLB
101 /* Define if internal BTC BRAM is used, and match BTC clear to a complete cache scrub */
102 #if defined(XPAR_MICROBLAZE_USE_BRANCH_TARGET_CACHE) && \
103 defined(XPAR_MICROBLAZE_BRANCH_TARGET_CACHE_SIZE)
104 #if XPAR_MICROBLAZE_USE_BRANCH_TARGET_CACHE == 1
105 #if XPAR_MICROBLAZE_BRANCH_TARGET_CACHE_SIZE == 0 || \
106 XPAR_MICROBLAZE_BRANCH_TARGET_CACHE_SIZE > 4
107 #define HAS_BRAM_BRANCH_TARGET_CACHE
108 #ifdef HAS_BRAM_DCACHE
109 #define BTC_MASK_D (XPAR_MICROBLAZE_DCACHE_BYTE_SIZE/DCACHE_INCREMENT-1)
111 #define BTC_MASK_D 256
113 #ifdef HAS_BRAM_ICACHE
114 #define BTC_MASK_I (XPAR_MICROBLAZE_CACHE_BYTE_SIZE/ICACHE_INCREMENT-1)
116 #define BTC_MASK_I 256
118 #if BTC_MASK_D > BTC_MASK_I
119 #define BTC_MASK BTC_MASK_D
121 #define BTC_MASK BTC_MASK_I
127 /* Define index offsets to persistent data used by this routine */
128 #define DLMB_INDEX_OFFSET 0
129 #define DCACHE_INDEX_OFFSET 4
130 #define ICACHE_INDEX_OFFSET 8
131 #define MMU_INDEX_OFFSET 12
132 #define BTC_CALL_COUNT_OFFSET 16
135 .globl microblaze_scrub
136 .ent microblaze_scrub
140 #ifdef FAULT_TOLERANT
141 la r6, r0, L_persistent_data /* Get pointer to data */
143 #ifdef HAS_SCRUBBABLE_LMB
145 lwi r5, r6, DLMB_INDEX_OFFSET /* Get dlmb index */
146 lw r7, r5, r0 /* Load and store */
148 addik r5, r5, 4 /* Increment and save dlmb index */
149 andi r5, r5, DLMB_MASK
150 swi r5, r6, DLMB_INDEX_OFFSET
151 #endif /* HAS_SCRUBBABLE_LMB */
153 #ifdef HAS_BRAM_DCACHE
155 lwi r5, r6, DCACHE_INDEX_OFFSET /* Get dcache line index */
156 wdc r5, r0 /* Invalidate data cache line */
157 addik r5, r5, DCACHE_INCREMENT /* Increment and save entry index */
158 andi r5, r5, DCACHE_MASK
159 swi r5, r6, DCACHE_INDEX_OFFSET
160 #endif /* HAS_BRAM_DCACHE */
162 #ifdef HAS_BRAM_ICACHE
164 lwi r5, r6, ICACHE_INDEX_OFFSET /* Get icache line index */
165 wic r5, r0 /* Invalidate data cache line */
166 addik r5, r5, ICACHE_INCREMENT /* Increment and save entry index */
167 andi r5, r5, ICACHE_MASK
168 swi r5, r6, ICACHE_INDEX_OFFSET
169 #endif /* HAS_BRAM_ICACHE */
171 #ifdef HAS_BRAM_MMU_UTLB
173 lwi r5, r6, MMU_INDEX_OFFSET /* Get UTLB entry index */
174 mts rtlbx, r5 /* Access next entry in UTLB */
175 mts rtlbhi, r0 /* Clear the UTLB entry */
177 addik r5, r5, 1 /* Increment and save entry index */
179 swi r5, r6, MMU_INDEX_OFFSET
180 #endif /* HAS_BRAM_MMU_UTLB */
182 #ifdef HAS_BRAM_BRANCH_TARGET_CACHE
184 lwi r5, r6, BTC_CALL_COUNT_OFFSET /* Get BTC call count offset */
185 addik r5, r5, 1 /* Increment and save call count */
186 andi r5, r5, BTC_MASK
187 swi r5, r6, BTC_CALL_COUNT_OFFSET
189 bnei r5, L_skip_btc_scrub /* Skip scrub unless count wrap */
190 bri 4 /* Clear branch target cache */
192 #endif /* HAS_BRAM_BRANCH_TARGET_CACHE */
194 #endif /* FAULT_TOLERANT */
196 rtsd r15, 8 /* Return */
198 .end microblaze_scrub
200 /* Persistent data used by this routine */
204 .long 0 /* dlmb index */
205 .long 0 /* dcache index */
206 .long 0 /* icache index */
207 .long 0 /* mmu entry index */
208 .long 0 /* btc call count */