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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
//-----------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2014
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//-----------------------------------------------------------------------------
/// \file sample_main.c
/// \brief Sample program that creates and starts a thread
///
/// This file demonstrates how to create a thread and run it. It also provides
/// an example of how to add traces to the code.
#include <fapi2.H>
//#include <p9_sbe_perv.H>
#include <vector>
extern "C"
{
#include "pk.h"
#include "pk_trace.h"
//#include "pk_trace_wrap.h"
//#include "common_scom_addresses.H"
//#include "p9_sbe_perv.H"
#include "p9_hcd_cache.H"
#include "p9_hcd_core.H"
#include "proc_sbe_fixed.H"
#include "trac_interface.h"
}
namespace fapi2attr
{
extern ProcChipAttributes_t G_proc_chip_attributes asm("G_proc_chip_attributes") __attribute__ ((section (".fixed")));
extern PervAttributes_t G_perv_attributes asm("G_perv_attributes") __attribute__ ((section (".fixed")));
extern CoreAttributes_t G_core_attributes asm("G_core_attributes") __attribute__ ((section (".fixed")));
extern EQAttributes_t G_eq_attributes asm("G_eq_attributes") __attribute__ ((section (".fixed")));
extern EXAttributes_t G_ex_attributes asm("G_ex_attributes") __attribute__ ((section (".fixed")));
}
extern "C" {
#define KERNEL_STACK_SIZE 256
#define MAIN_THREAD_STACK_SIZE 256
// Necessary Kernel Structures
uint8_t G_kernel_stack[KERNEL_STACK_SIZE];
uint8_t G_main_thread_stack[MAIN_THREAD_STACK_SIZE];
PkThread G_main_thread;
fapi2::ReturnCode
hwp_chip_present(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_target);
fapi2::ReturnCode
hwp_chip_functional(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_target);
fapi2::ReturnCode
hwp_chip2(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_target);
fapi2::ReturnCode
hwp_core(const fapi2::Target<fapi2::TARGET_TYPE_CORE> & i_target);
fapi2::ReturnCode
hwp_eq(const fapi2::Target<fapi2::TARGET_TYPE_EQ> & i_target);
fapi2::ReturnCode
hwp_perv(const fapi2::Target<fapi2::TARGET_TYPE_PERV> & i_target);
//---------------------------------------------------------------------------
void main_thread(void* arg)
{
// This is workaround. Currently we do not have code to initialise
// global objects. So initializing global objects against using local
// initialized object
FAPI_DBG("Workaround temporary allocation of Global Vector");
std::vector<fapi2::plat_target_handle_t> targets1;
G_vec_targets = std::move(targets1);
// Intialize the targets
fapi2::plat_TargetsInit();
// Get a specific target
fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>chip_target_new =
fapi2::plat_getChipTarget();
FAPI_DBG("chip_target_new = 0x%08X", (uint32_t)(chip_target_new.get()>>32));
// FAPI_TRY(hwp_chip_present(chip_target_new));
FAPI_TRY(hwp_chip_functional(chip_target_new));
FAPI_TRY(hwp_chip2(chip_target_new));
///
#ifndef __noRC__
// PIB Errors are masked for platforms like SBE where
// explict error code checking is to occur
fapi2::setPIBErrorMask(0b11111111);
#else
// PIB Errors are unmaskd for platforms that desire to take machine
// check interrupts
fapi2::setPIBErrorMask(0b00000000);
#endif
// FAPI_TRY(hwp_chip(chip_target_new));
// FAPI_TRY(p9_sbe_attr_setup(chip_target));
// FAPI_TRY(p9_sbe_check_master(chip_target));
// FAPI_TRY(p9_sbe_setup_evid(chip_target));
fapi_try_exit:
return;
}
// A Chip try
fapi2::ReturnCode
hwp_chip_present(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_target)
{
FAPI_DBG("i_target = 0x%08X", (uint32_t)(i_target.get()>>32));
auto l_perv_present_vector =
i_target.getChildren<fapi2::TARGET_TYPE_PERV>
(fapi2::TARGET_STATE_PRESENT);
// Get the TPChiplet target
uint32_t i = 0;
for (auto it: l_perv_present_vector)
{
FAPI_DBG("Perv Present Target %u value=%08X chiplet %02X",
i,
(uint32_t)(it.get()>>32),
(uint32_t)(it.getChipletNumber()));
++i;
}
auto l_core_present_vector =
i_target.getChildren<fapi2::TARGET_TYPE_CORE>
(fapi2::TARGET_STATE_PRESENT);
// Get the Core Chiplet targets
uint32_t j = 0;
for (auto it: l_core_present_vector)
{
FAPI_DBG("Core Present Target %u value=%08X chiplet %02X",
j,
(uint32_t)(it.get()>>32),
(uint32_t)(it.getChipletNumber()));
++j;
}
fapi2::buffer<uint64_t> data = 0;
const uint32_t address = 0x0006d010;
FAPI_INF("hwp_chip %u", address);
uint64_t databuffer;
getscom_abs(address, &databuffer);
databuffer = 0xDEAD000000000000ull;
putscom_abs(address, databuffer);
data = 0xBADC0DE800000000ull;
FAPI_TRY(fapi2::putScom(i_target, address, data));
FAPI_TRY(fapi2::getScom(i_target, address, data));
// FAPI_DBG("The First getSCOM: data = %016llX", revle64(data));
data.setBit<0, 16>();
FAPI_TRY(fapi2::putScom(i_target, 0x0006d010, data));
return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
return fapi2::FAPI2_RC_PLAT_ERR_SEE_DATA;
}
// A Chip try
fapi2::ReturnCode
hwp_chip_functional(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_target)
{
FAPI_DBG("i_target = 0x%08X", (uint32_t)(i_target.get()>>32));
auto l_perv_functional_vector =
i_target.getChildren<fapi2::TARGET_TYPE_PERV>
(fapi2::TARGET_STATE_FUNCTIONAL);
// Get the TPChiplet target
uint32_t i = 0;
for (auto it: l_perv_functional_vector)
{
FAPI_DBG("Perv Functional Target %u value=%08X chiplet %02X",
i,
(uint32_t)(it.get()>>32),
(uint32_t)(it.getChipletNumber()));
++i;
}
auto l_core_functional_vector =
i_target.getChildren<fapi2::TARGET_TYPE_CORE>
(fapi2::TARGET_STATE_FUNCTIONAL);
// Get the Core Chiplet targets
uint32_t j = 0;
for (auto it: l_core_functional_vector)
{
FAPI_DBG("Core Functional Target %u value=%08X chiplet %02X",
j,
(uint32_t)(it.get()>>32),
(uint32_t)(it.getChipletNumber()));
++j;
}
return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
return fapi2::FAPI2_RC_PLAT_ERR_SEE_DATA;
}
// A Chip try
fapi2::ReturnCode
hwp_chip2(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_target)
{
FAPI_DBG("i_target = 0x%08X", (uint32_t)(i_target.get()>>32));
auto l_eq_functional_vector =
i_target.getChildren<fapi2::TARGET_TYPE_EQ>
(fapi2::TARGET_STATE_PRESENT);
// Get the EQ Chiplet target
uint32_t k = 0;
for (auto it: l_eq_functional_vector)
{
FAPI_DBG("EQ Functional Target %u value=%08X chiplet %02X",
k,
(uint32_t)(it.get()>>32),
(uint32_t)(it.getChipletNumber()));
++k;
}
auto l_mcs_functional_vector =
i_target.getChildren<fapi2::TARGET_TYPE_MCS>
(fapi2::TARGET_STATE_PRESENT);
// Get the MCS Chiplet target
uint32_t m = 0;
for (auto it: l_mcs_functional_vector)
{
FAPI_DBG("MCS Functional Target %u value=%08X chiplet %02X",
m,
(uint32_t)(it.get()>>32),
(uint32_t)(it.getChipletNumber()));
++m;
}
return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
return fapi2::FAPI2_RC_PLAT_ERR_SEE_DATA;
}
// A Core try
fapi2::ReturnCode
hwp_core(const fapi2::Target<fapi2::TARGET_TYPE_CORE> & i_target)
{
// Temporary target that pulls out only the chiplet overly. This keeps
// from having to compute this for each SCOM operation.
// fapi2::Target<fapi2::TARGET_TYPE_ADDRESS> iv_target (i_target.getAddressOverlay());
fapi2::buffer<uint64_t> data = 0;
fapi2::buffer<uint64_t> mask;
uint32_t address = 0x200F5678;
FAPI_TRY(fapi2::getScom(i_target, address, data));
FAPI_TRY(fapi2::putScom(i_target, 0x20006789, data));
data = 0xBADC0DEBADC0DEBAull;
FAPI_TRY(fapi2::putScom(i_target, 0x0000AAAA, data));
FAPI_TRY(fapi2::getScom(i_target, address, data));
FAPI_TRY(fapi2::modifyScom(i_target, address, data, fapi2::CHIP_OP_MODIFY_MODE_OR));
mask = BITS(4,4);
FAPI_TRY(fapi2::putScomUnderMask(i_target, address, data, mask));
return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
return fapi2::FAPI2_RC_PLAT_ERR_SEE_DATA;
}
// An EQ try
fapi2::ReturnCode
hwp_eq(const fapi2::Target<fapi2::TARGET_TYPE_EQ> & i_target)
{
fapi2::buffer<uint64_t> data = 0;
uint64_t address = 0x1000F2222;
FAPI_TRY(fapi2::getScom(i_target, address, data));
FAPI_TRY(fapi2::putScom(i_target, 0x10006789, data));
data = 0xDEADBEEFDEADBEEFull;
FAPI_TRY(fapi2::putScom(i_target, 0x1000ABCD, data));
return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
return fapi2::FAPI2_RC_PLAT_ERR_SEE_DATA;
}
// A Perv try
fapi2::ReturnCode
hwp_perv(const fapi2::Target<fapi2::TARGET_TYPE_PERV> & i_target)
{
fapi2::buffer<uint64_t> data = 0;;
uint64_t address = 0x00005678;
for (uint32_t i = 0; i < 5; i++)
{
FAPI_TRY(fapi2::getScom(i_target, address+i, data));
data.setBit<4>();
FAPI_TRY(fapi2::putScom(i_target, address+i, data));
data = 0xDEADBEEFDEADBEEFull;
FAPI_TRY(fapi2::putScom(i_target, address+(2*i), data));
}
return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
return fapi2::FAPI2_RC_PLAT_ERR_SEE_DATA;
}
// The main function is called by the boot code (after initializing some
// registers)
int main(int argc, char **argv)
{
// initializes kernel data (stack, threads, timebase, timers, etc.)
pk_initialize((PkAddress)G_kernel_stack,
KERNEL_STACK_SIZE,
0,
500000000);
PK_TRACE("Kernel init completed");
//Initialize the thread control block for G_main_thread
pk_thread_create(&G_main_thread,
(PkThreadRoutine)main_thread,
(void*)NULL,
(PkAddress)G_main_thread_stack,
(size_t)MAIN_THREAD_STACK_SIZE,
(PkThreadPriority)1);
PK_TRACE_BIN("G_main_thread", &G_main_thread, sizeof(G_main_thread));
//Make G_main_thread runnable
pk_thread_resume(&G_main_thread);
PK_TRACE("Starting thread(s)");
// Start running the highest priority thread.
// This function never returns
pk_start_threads();
return 0;
}
} // extern C
|