-
Notifications
You must be signed in to change notification settings - Fork 8
/
p9_cme_copy_scan_ring.c
299 lines (239 loc) · 8.71 KB
/
p9_cme_copy_scan_ring.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: import/chips/p9/procedures/ppe_closed/cme/stop_cme/p9_cme_copy_scan_ring.c $ */
/* */
/* OpenPOWER HCODE Project */
/* */
/* COPYRIGHT 2015,2020 */
/* [+] International Business Machines Corp. */
/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
/* implied. See the License for the specific language governing */
/* permissions and limitations under the License. */
/* */
/* IBM_PROLOG_END_TAG */
#include "p9_cme_copy_scan_ring.h"
#include "p9_cme_stop.h"
/// @brief local constants.
enum
{
SPR_NUM_PIR = 286,
CME_INST_ID_MASK = 0x0000001E,
COPY_DEF_CME_ADDR = 0x00000000,
CME_PAGE_RD_SIZE = 0x20,
CME_FLAG_EX_ID_BIT = 26,
EX_ID_SHIFT_POS = 5
};
#if TEST_ONLY_BCE_IRR
extern BceIrritator G_bce_irr;
#define RAND32_ALL 0
uint32_t _seed32 = 405405405;
uint32_t
_rand32(uint32_t* seed, uint32_t limit)
{
uint64_t x;
*seed = (*seed * 1664525) + 1013904223;
if (limit == RAND32_ALL)
{
return *seed;
}
else
{
x = (uint64_t)(*seed) * limit;
return x >> 32;
}
}
uint32_t
rand32(uint32_t limit)
{
return _rand32(&_seed32, limit);
}
void bce_irr_setup()
{
BceReturnCode_t l_rc;
uint32_t l_cmePir = 0;
uint32_t l_exId = (in32(G_CME_LCL_FLAGS) & BIT32(26)) >> SHIFT32(26);
asm volatile ( "mfspr %0, %1 \n\t" : "=r" (l_cmePir) : "i" (SPR_NUM_PIR));
//CME's PIR gives only quad id. To determine the correct CME instance, follow the steps below:
//(1). Read CME PIR's CME instance bit field (bit 27 -bit 31)
//(2). Bitwise shift left by one bit position.
//(3). OR to LSB of CME PIR (bit 31), bit 26 of CME Flag Register
G_bce_irr.cmeid = (((l_cmePir << 1) & CME_INST_ID_MASK) | l_exId); // get CME instance number
G_bce_irr.mbase = CPMR_DEBUG_REGION_OFFSET + (G_bce_irr.cmeid << 3); //8B for each CME
G_bce_irr.sbase = 0xFFFFFFF0; // use 8B at the end of CME SRAM
startCmeBlockCopy(G_bce_irr.sbase, 1, G_bce_irr.cmeid, BAR_INDEX_1, G_bce_irr.mbase);
while(1)
{
l_rc = checkCmeBlockCopyStatus( G_bce_irr.cmeid );
if( BLOCK_COPY_SUCCESS == l_rc )
{
break;
}
if( BLOCK_COPY_FAILED == l_rc )
{
PK_TRACE( "failed to read bce irritator data on cme %d",
G_bce_irr.cmeid );
pk_halt();
}
}
G_bce_irr.data.word = in32(G_bce_irr.sbase);
G_bce_irr.data.word++;
out32(G_bce_irr.sbase, G_bce_irr.data.word);
startCmeBlockCopyWriteHomer(G_bce_irr.sbase, 4, G_bce_irr.cmeid, BAR_INDEX_1, G_bce_irr.mbase);
while(1)
{
l_rc = checkCmeBlockCopyStatus( G_bce_irr.cmeid );
if( BLOCK_COPY_SUCCESS == l_rc )
{
break;
}
if( BLOCK_COPY_FAILED == l_rc )
{
PK_TRACE( "failed to write bce irritator data on cme %d",
G_bce_irr.cmeid );
pk_halt();
}
}
}
void bce_irr_run()
{
BceReturnCode_t l_rc;
uint32_t l_data32 = 0;
if (rand32(1000) > 500)
{
return;
}
while(1)
{
l_rc = checkCmeBlockCopyStatus( G_bce_irr.cmeid );
if( BLOCK_COPY_SUCCESS == l_rc )
{
break;
}
if( BLOCK_COPY_FAILED == l_rc )
{
PK_TRACE( "failed to read bce irritator data on cme %d",
G_bce_irr.cmeid );
pk_halt();
}
}
startCmeBlockCopy(G_bce_irr.sbase, 1, G_bce_irr.cmeid, BAR_INDEX_1, G_bce_irr.mbase);
while(1)
{
l_rc = checkCmeBlockCopyStatus( G_bce_irr.cmeid );
if( BLOCK_COPY_SUCCESS == l_rc )
{
break;
}
if( BLOCK_COPY_FAILED == l_rc )
{
PK_TRACE( "failed to read bce irritator data on cme %d",
G_bce_irr.cmeid );
pk_halt();
}
}
l_data32 = in32(G_bce_irr.sbase);
if (l_data32 != G_bce_irr.data.word)
{
PK_TRACE_DBG("miscompare between bce irr read[%x] and cme shadow copy[%x]",
l_data32, G_bce_irr.data.word);
pk_halt();
}
G_bce_irr.data.word++;
out32(G_bce_irr.sbase, G_bce_irr.data.word);
while(1)
{
l_rc = checkCmeBlockCopyStatus( G_bce_irr.cmeid );
if( BLOCK_COPY_SUCCESS == l_rc )
{
break;
}
if( BLOCK_COPY_FAILED == l_rc )
{
PK_TRACE( "failed to write bce irritator data on cme %d",
G_bce_irr.cmeid );
pk_halt();
}
}
startCmeBlockCopyWriteHomer(G_bce_irr.sbase, 4, G_bce_irr.cmeid, BAR_INDEX_1, G_bce_irr.mbase);
while(1)
{
l_rc = checkCmeBlockCopyStatus( G_bce_irr.cmeid );
if( BLOCK_COPY_SUCCESS == l_rc )
{
break;
}
if( BLOCK_COPY_FAILED == l_rc )
{
PK_TRACE( "failed to write bce irritator data on cme %d",
G_bce_irr.cmeid );
pk_halt();
}
}
}
void bce_irr_thread()
{
while(1)
{
wrteei(0);
bce_irr_run();
wrteei(1);
}
}
#endif
void start_cme_block_copy(uint32_t barIndex, uint32_t bcMembase, uint32_t bcSrambase, uint32_t bcLength)
{
uint32_t l_cmePir = 0;
uint32_t l_exId = ((in32(G_CME_LCL_FLAGS) & BITS32(CME_FLAG_EX_ID_BIT, 1)) >> EX_ID_SHIFT_POS);
asm volatile ( "mfspr %0, %1 \n\t" : "=r" (l_cmePir) : "i" (SPR_NUM_PIR));
//CME's PIR gives only quad id. To determine the correct CME instance, follow the steps below:
//(1). Read CME PIR's CME instance bit field (bit 27 -bit 31)
//(2). Bitwise shift left by one bit position.
//(3). OR to LSB of CME PIR (bit 31), bit 26 of CME Flag Register
l_cmePir = (((l_cmePir << 1) & CME_INST_ID_MASK) | l_exId); // get CME instance number
//let us find out HOMER address where core specific scan rings reside.
// use native 16-bit PPE multiply instruction
bcMembase = bcMembase + (mulu16( l_cmePir , bcLength ) << 5 );
bcMembase = bcMembase >> 5;
PK_TRACE( "Start cme block copy MBASE 0x%08x SBSE 0x%08x Len 0x%08x CME Ist %d",
bcMembase, bcSrambase, bcLength, l_cmePir );
startCmeBlockCopy( bcSrambase, bcLength, l_cmePir, barIndex, bcMembase );
PK_TRACE("Done startCmeBlockCopy(instance_scan_init).");
}
BceReturnCode_t check_cme_block_copy()
{
BceReturnCode_t l_rc;
uint32_t l_cmePir = 0;
uint32_t l_exId = ((in32(G_CME_LCL_FLAGS) & BITS32(CME_FLAG_EX_ID_BIT, 1)) >> EX_ID_SHIFT_POS);
asm volatile ( "mfspr %0, %1 \n\t" : "=r" (l_cmePir) : "i" (SPR_NUM_PIR));
//CME's PIR gives only quad id. To determine the correct CME instance, follow the steps below:
//(1). Read CME PIR's CME instance bit field (bit 27 -bit 31)
//(2). Bitwise shift left by one bit position.
//(3). OR to LSB of CME PIR (bit 31), bit 26 of CME Flag Register
l_cmePir = ((( l_cmePir << 1 ) & CME_INST_ID_MASK) | l_exId); // get CME instance number
while(1)
{
l_rc = checkCmeBlockCopyStatus(l_cmePir);
if(BLOCK_COPY_SUCCESS == l_rc)
{
break;
}
if(BLOCK_COPY_FAILED == l_rc)
{
PK_TRACE("failed to copy instance specific scan ring on cme %d",
l_cmePir);
break;
}
}
return l_rc;
}