1 |
|
|
#ifndef GSCMEMORY_HPP_ |
2 |
|
|
#define GSCMEMORY_HPP_ |
3 |
|
|
|
4 |
|
|
#ifndef LEON3 |
5 |
|
|
#define LEON3 |
6 |
|
|
#endif |
7 |
|
|
|
8 |
|
|
#define REGS_ADDR_PLUGANDPLAY 0xFFFFF000 |
9 |
|
|
#define ASR16_REG_ADDRESS 0x90400040 // Ancillary State Register 16 = Register protection control register (FT only) |
10 |
|
|
|
11 |
|
|
#define DEVICEID_LEON3 0x003 |
12 |
|
|
#define DEVICEID_LEON3FT 0x053 |
13 |
|
|
#define VENDORID_GAISLER 0x01 |
14 |
|
|
|
15 |
|
|
// CCR |
16 |
|
|
#define POS_FT 19 |
17 |
|
|
// |
18 |
|
|
#define POS_ITE 12 |
19 |
|
|
#define COUNTER_FIELD_ITE 0x00003000 // 0000 0000 0000 0000 0011 0000 0000 0000 |
20 |
|
|
#define COUNTER_MASK_ITE 0xffffcfff // 1111 1111 1111 1111 1100 1111 1111 1111 |
21 |
|
|
#define POS_IDE 10 |
22 |
|
|
#define COUNTER_FIELD_IDE 0x00000c00 // 0000 0000 0000 0000 0000 1100 0000 0000 |
23 |
|
|
#define COUNTER_MASK_IDE 0xfffff3ff // 1111 1111 1111 1111 1111 0011 1111 1111 |
24 |
|
|
// |
25 |
|
|
#define POS_DTE 8 |
26 |
|
|
#define COUNTER_FIELD_DTE 0x00000300 // 0000 0000 0000 0000 0000 0011 0000 0000 |
27 |
|
|
#define COUNTER_MASK_DTE 0xfffffcff // 1111 1111 1111 1111 1111 1100 1111 1111 |
28 |
|
|
#define POS_DDE 6 |
29 |
|
|
#define COUNTER_FIELD_DDE 0x000000c0 // 0000 0000 0000 0000 0000 0000 1100 0000 |
30 |
|
|
#define COUNTER_MASK_DDE 0xffffff3f // 1111 1111 1111 1111 1111 1111 0011 1111 |
31 |
|
|
|
32 |
|
|
// ASR16 |
33 |
|
|
#define POS_FPFTID 30 |
34 |
|
|
#define POS_FPRF 27 |
35 |
|
|
#define POS_FDI 16 // FP RF protection enable/disable |
36 |
|
|
#define POS_IUFTID 14 |
37 |
|
|
#define POS_IURF 11 |
38 |
|
|
#define POS_IDI 0 // IU RF protection enable/disable |
39 |
|
|
|
40 |
|
|
#define COUNTER_FIELD_FPRF 0x38000000 // 0011 1000 0000 0000 0000 0000 0000 0000 |
41 |
|
|
#define COUNTER_MASK_FPRF 0xc7ffffff // 1100 0111 1111 1111 1111 1111 1111 1111 |
42 |
|
|
|
43 |
|
|
#define COUNTER_FIELD_IURF 0x00003800 // 0000 0000 0000 0000 0011 1000 0000 0000 |
44 |
|
|
#define COUNTER_MASK_IURF 0xffffc7ff // 1111 1111 1111 1111 1100 0111 1111 1111 |
45 |
|
|
|
46 |
|
|
volatile unsigned int *asr16Ptr = (volatile unsigned int *) ASR16_REG_ADDRESS; |
47 |
|
|
#ifdef ENABLE_DEAD_CODE |
48 |
|
|
static inline void flushCache() |
49 |
|
|
{ |
50 |
|
|
/** |
51 |
|
|
* Flush the data cache and the instruction cache. |
52 |
|
|
* |
53 |
|
|
* @param void |
54 |
|
|
* |
55 |
|
|
* @return void |
56 |
|
|
*/ |
57 |
|
|
|
58 |
|
|
asm("flush"); |
59 |
|
|
} |
60 |
|
|
#endif |
61 |
|
|
|
62 |
|
|
//*************************** |
63 |
|
|
// CCR Cache control register |
64 |
|
|
|
65 |
|
522 |
static unsigned int CCR_getValue() |
66 |
|
|
{ |
67 |
|
522 |
unsigned int cacheControlRegister = 0; |
68 |
|
522 |
__asm__ __volatile__("lda [%%g0] 2, %0" : "=r"(cacheControlRegister) : ); |
69 |
|
381 |
return cacheControlRegister; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
254 |
static void CCR_setValue(unsigned int cacheControlRegister) |
73 |
|
|
{ |
74 |
|
254 |
__asm__ __volatile__("sta %0, [%%g0] 2" : : "r"(cacheControlRegister)); |
75 |
|
254 |
} |
76 |
|
|
|
77 |
|
87 |
static void CCR_resetCacheControlRegister() |
78 |
|
|
{ |
79 |
|
|
unsigned int cacheControlRegister; |
80 |
|
87 |
cacheControlRegister = 0x00; |
81 |
|
87 |
CCR_setValue(cacheControlRegister); |
82 |
|
87 |
} |
83 |
|
|
|
84 |
|
87 |
static void CCR_enableInstructionCache() |
85 |
|
|
{ |
86 |
|
|
// [1:0] Instruction Cache state (ICS) |
87 |
|
|
// Indicates the current data cache state according to the following: X0 = disabled, 01 = frozen, 11 = enabled. |
88 |
|
|
unsigned int cacheControlRegister; |
89 |
|
87 |
cacheControlRegister = CCR_getValue(); |
90 |
|
87 |
cacheControlRegister = (cacheControlRegister | 0x3); |
91 |
|
87 |
CCR_setValue(cacheControlRegister); |
92 |
|
87 |
} |
93 |
|
|
|
94 |
|
87 |
static void CCR_enableDataCache() |
95 |
|
|
{ |
96 |
|
|
// [3:2] Data Cache state (DCS) |
97 |
|
|
// Indicates the current data cache state according to the following: X0 = disabled, 01 = frozen, 11 = enabled. |
98 |
|
|
unsigned int cacheControlRegister; |
99 |
|
87 |
cacheControlRegister = CCR_getValue(); |
100 |
|
87 |
cacheControlRegister = (cacheControlRegister | 0xc); |
101 |
|
87 |
CCR_setValue(cacheControlRegister); |
102 |
|
87 |
} |
103 |
|
|
|
104 |
|
87 |
static void CCR_enableInstructionBurstFetch() |
105 |
|
|
{ |
106 |
|
|
// [16] Instruction burst fetch (IB). This bit enables burst fill during instruction fetch. |
107 |
|
|
unsigned int cacheControlRegister; |
108 |
|
87 |
cacheControlRegister = CCR_getValue(); |
109 |
|
|
// set the bit IB to 1 |
110 |
|
87 |
cacheControlRegister = (cacheControlRegister | 0x10000); |
111 |
|
87 |
CCR_setValue(cacheControlRegister); |
112 |
|
87 |
} |
113 |
|
|
|
114 |
|
|
void CCR_getInstructionAndDataErrorCounters( unsigned int* instructionErrorCounter, unsigned int* dataErrorCounter ) |
115 |
|
|
{ |
116 |
|
|
// [13:12] Instruction Tag Errors (ITE) - Number of detected parity errors in the instruction tag cache. |
117 |
|
|
// Only available if fault-tolerance is enabled (FT field in this register is non-zero). |
118 |
|
|
// [11:10] Instruction Data Errors (IDE) - Number of detected parity errors in the instruction data cache. |
119 |
|
|
// Only available if fault-tolerance is enabled (FT field in this register is non-zero). |
120 |
|
|
|
121 |
|
|
unsigned int cacheControlRegister; |
122 |
|
|
unsigned int iTE; |
123 |
|
|
unsigned int iDE; |
124 |
|
|
unsigned int dTE; |
125 |
|
|
unsigned int dDE; |
126 |
|
|
|
127 |
|
|
cacheControlRegister = CCR_getValue(); |
128 |
|
|
iTE = (cacheControlRegister & COUNTER_FIELD_ITE) >> POS_ITE; |
129 |
|
|
iDE = (cacheControlRegister & COUNTER_FIELD_IDE) >> POS_IDE; |
130 |
|
|
dTE = (cacheControlRegister & COUNTER_FIELD_DTE) >> POS_DTE; |
131 |
|
|
dDE = (cacheControlRegister & COUNTER_FIELD_DDE) >> POS_DDE; |
132 |
|
|
|
133 |
|
|
*instructionErrorCounter = iTE + iDE; |
134 |
|
|
*dataErrorCounter = dTE + dDE; |
135 |
|
|
|
136 |
|
|
// reset counters |
137 |
|
|
cacheControlRegister = cacheControlRegister |
138 |
|
|
& COUNTER_FIELD_ITE |
139 |
|
|
& COUNTER_FIELD_IDE |
140 |
|
|
& COUNTER_FIELD_DTE |
141 |
|
|
& COUNTER_FIELD_DDE; |
142 |
|
|
|
143 |
|
|
CCR_setValue(cacheControlRegister); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
//******************************************* |
147 |
|
|
// ASR16 Register protection control register |
148 |
|
|
|
149 |
|
87 |
static void ASR16_resetRegisterProtectionControlRegister() |
150 |
|
|
{ |
151 |
|
87 |
*asr16Ptr = 0x00; |
152 |
|
87 |
} |
153 |
|
|
|
154 |
|
|
void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int* fprfErrorCounter, unsigned int* iurfErrorCounter) |
155 |
|
|
{ |
156 |
|
|
/** This function is used to retrieve the integer unit register file error counter and the floating point unit |
157 |
|
|
* register file error counter |
158 |
|
|
* |
159 |
|
|
* @return void |
160 |
|
|
* |
161 |
|
|
* [29:27] FP RF error counter - Number of detected parity errors in the FP register file. |
162 |
|
|
* [13:11] IU RF error counter - Number of detected parity errors in the IU register file. |
163 |
|
|
* |
164 |
|
|
*/ |
165 |
|
|
|
166 |
|
|
unsigned int asr16; |
167 |
|
|
|
168 |
|
|
asr16 = *asr16Ptr; |
169 |
|
|
*fprfErrorCounter = ( asr16 & COUNTER_FIELD_FPRF ) >> POS_FPRF; |
170 |
|
|
*iurfErrorCounter = ( asr16 & COUNTER_FIELD_IURF ) >> POS_IURF; |
171 |
|
|
|
172 |
|
|
// reset the counter to 0 |
173 |
|
|
asr16 = asr16 |
174 |
|
|
& COUNTER_MASK_FPRF |
175 |
|
|
& COUNTER_FIELD_IURF; |
176 |
|
|
|
177 |
|
|
*asr16Ptr = asr16; |
178 |
|
|
} |
179 |
|
|
|
180 |
|
87 |
static void faultTolerantScheme() |
181 |
|
|
{ |
182 |
|
|
// [20:19] FT scheme (FT) - “00” = no FT, “01” = 4-bit checking implemented |
183 |
|
|
unsigned int cacheControlRegister; |
184 |
|
|
unsigned int *plugAndPlayRegister; |
185 |
|
|
unsigned int vendorId; |
186 |
|
|
unsigned int deviceId; |
187 |
|
|
|
188 |
|
87 |
plugAndPlayRegister = (unsigned int*) REGS_ADDR_PLUGANDPLAY; |
189 |
|
87 |
vendorId = ( (*plugAndPlayRegister) & 0xff000000 ) >> 24; |
190 |
|
87 |
deviceId = ( (*plugAndPlayRegister) & 0x00fff000 ) >> 12; |
191 |
|
|
|
192 |
|
87 |
cacheControlRegister = CCR_getValue(); |
193 |
|
|
|
194 |
|
87 |
if( (vendorId == VENDORID_GAISLER) & (deviceId ==DEVICEID_LEON3FT) ) |
195 |
|
|
{ |
196 |
|
|
PRINTF("in faultTolerantScheme *** Leon3FT detected\n"); |
197 |
|
|
PRINTF2(" *** vendorID = 0x%x, deviceId = 0x%x\n", vendorId, deviceId); |
198 |
|
|
PRINTF1("ASR16 IU RF protection, bit 0 (IDI) is: 0x%x (0 => protection enabled)\n", |
199 |
|
|
(*asr16Ptr >> POS_IDI) & 1); |
200 |
|
|
PRINTF1("ASR16 FP RF protection, bit 16 (FDI) is: 0x%x (0 => protection enabled)\n", |
201 |
|
|
(*asr16Ptr >> POS_FDI) & 1); |
202 |
|
|
PRINTF1("ASR16 IU FT ID bits [15:14] is: 0x%x (2 => 8-bit parity without restart)\n", |
203 |
|
|
(*asr16Ptr >> POS_IUFTID) & 0x3); |
204 |
|
|
PRINTF1("ASR16 FP FT ID bits [31:30] is: 0x%x (1 => 4-bit parity with restart)\n", |
205 |
|
|
(*asr16Ptr >> POS_FPFTID) & 0x03); |
206 |
|
|
PRINTF1("CCR FT bits [20:19] are: 0x%x (1 => 4-bit parity with restart)\n", |
207 |
|
|
(cacheControlRegister >> POS_FT) & 0x3 ); |
208 |
|
|
|
209 |
|
|
// CCR The FFT bits are just read, the FT scheme is set to “01” = 4-bit checking implemented by default |
210 |
|
|
|
211 |
|
|
// ASR16 Ancillary State Register configuration (Register protection control register) |
212 |
|
|
// IU RF protection is set by default, bit 0 IDI = 0 |
213 |
|
|
// FP RF protection is set by default, bit 16 FDI = 0 |
214 |
|
|
} |
215 |
|
|
else |
216 |
|
|
{ |
217 |
|
|
PRINTF("in faultTolerantScheme *** Leon3FT not detected\n"); |
218 |
|
|
PRINTF2(" *** vendorID = 0x%x, deviceId = 0x%x\n", vendorId, deviceId); |
219 |
|
|
} |
220 |
|
87 |
} |
221 |
|
|
|
222 |
|
|
#endif /* GSCMEMORY_HPP_ */ |