summaryrefslogtreecommitdiffstats
path: root/hwpf/plat/src/target.C
blob: be9727f9eb24031ad6ee29ce00c3bba6e968d8b1 (plain)
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/* IBM_PROLOG_BEGIN_TAG                                                 */
/* This is an automatically generated prolog.                           */
/*                                                                      */
/* $Source: $                                                           */
/*                                                                      */
/* OpenPOWER HostBoot Project                                           */
/*                                                                      */
/* Contributors Listed Below - COPYRIGHT 2012,2014                      */
/* [+] 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 <fapi2.H>
#include <new>
#include <utility> // For move
#include <plat_target_pg_attributes.H>

// Global Vector containing ALL targets.  This structure is referenced by
// fapi2::getChildren to produce the resultant returned vector from that
// call.
std::vector<fapi2::plat_target_handle_t> G_vec_targets;

fapi2attr::SystemAttributes_t*    G_system_attributes_ptr;
fapi2attr::ProcChipAttributes_t*  G_proc_chip_attributes_ptr;
fapi2attr::PervAttributes_t*      G_perv_attributes_ptr;
fapi2attr::CoreAttributes_t*      G_core_attributes_ptr;
fapi2attr::EQAttributes_t*        G_eq_attributes_ptr;
fapi2attr::EXAttributes_t*        G_ex_attributes_ptr;

namespace fapi2
{

    #ifndef __noRC__
    ReturnCode current_err;
    #endif


    // Not a fan of the switch technique;  I would prefer an array lookup
    // but the attritute lookup is done via compile time macros that are
    // resolved to attribute Ids (hashes).
     fapi2::ReturnCode plat_PervPGTargets(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_target,
                                          const fapi2::TargetTypes_t i_chiplet_num,
                                          bool & o_present)
     {

        o_present = false;
        uint16_t attr_value = 0;
        switch (i_chiplet_num)
        {
            case 0x00:   // Nop
                break;
            case 0x01:
                FAPI_ATTR_GET(ATTR_PG_PRV, i_target, *(&attr_value));
                FAPI_DBG("ATTR_PG_PRV value = %x", attr_value);
                break;
            case 0x02:
                FAPI_ATTR_GET(ATTR_PG_N0, i_target, attr_value);
                FAPI_DBG("ATTR_PG_N0 value = %x", attr_value);
                break;
            case 0x03:
                FAPI_ATTR_GET(ATTR_PG_N1, i_target, attr_value);
                FAPI_DBG("ATTR_PG_N1 value = %x", attr_value);
                break;
            case 0x04:
                FAPI_ATTR_GET(ATTR_PG_N2, i_target, attr_value);
                FAPI_DBG("ATTR_PG_N2 value = %x", attr_value);
                break;
            case 0x05:
                FAPI_ATTR_GET(ATTR_PG_N3, i_target, attr_value);
                FAPI_DBG("ATTR_PG_N0 value = %x", attr_value);
                break;
            case 0x06:
                FAPI_ATTR_GET(ATTR_PG_XB, i_target, attr_value);
                FAPI_DBG("ATTR_PG_XB value = %x", attr_value);
                break;
            case 0x07:
                FAPI_ATTR_GET(ATTR_PG_MC01, i_target, attr_value);
                FAPI_DBG("ATTR_PG_MC01 value = %x", attr_value);
                break;
            case 0x08:
                FAPI_ATTR_GET(ATTR_PG_MC23, i_target, attr_value);
                FAPI_DBG("ATTR_PG_MC23 value = %x", attr_value);
                break;
            case 0x09:
                FAPI_ATTR_GET(ATTR_PG_OB0, i_target, attr_value);
                FAPI_DBG("ATTR_PG_OB0 value = %x", attr_value);
                break;
            case 0x0A:
                FAPI_ATTR_GET(ATTR_PG_OB1, i_target, attr_value);
                FAPI_DBG("ATTR_PG_OB1 value = %x", attr_value);
                break;
            case 0x0B:
                FAPI_ATTR_GET(ATTR_PG_OB2, i_target, attr_value);
                FAPI_DBG("ATTR_PG_OB2 value = %x", attr_value);
                break;
            case 0x0C:
                FAPI_ATTR_GET(ATTR_PG_OB3, i_target, attr_value);
                FAPI_DBG("ATTR_PG_OB3 value = %x", attr_value);
                break;
            case 0x0D:
                FAPI_ATTR_GET(ATTR_PG_PCI0, i_target, attr_value);
                FAPI_DBG("ATTR_PG_PCI0 value = %x", attr_value);
                break;
            case 0x0E:
                FAPI_ATTR_GET(ATTR_PG_PCI1, i_target, attr_value);
                FAPI_DBG("ATTR_PG_PCI1 value = %x", attr_value);
                break;
            case 0x0F:
                FAPI_ATTR_GET(ATTR_PG_PCI2, i_target, attr_value);
                FAPI_DBG("ATTR_PG_PCI2 value = %x", attr_value);
                break;
            case 0x10:
                FAPI_ATTR_GET(ATTR_PG_EQ0, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EQ0 value = %x", attr_value);
                break;
            case 0x11:
                FAPI_ATTR_GET(ATTR_PG_EQ1, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EQ1 value = %x", attr_value);
                break;
            case 0x12:
                FAPI_ATTR_GET(ATTR_PG_EQ2, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EQ2 value = %x", attr_value);
                break;
            case 0x13:
                FAPI_ATTR_GET(ATTR_PG_EQ3, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EQ3 value = %x", attr_value);
                break;
            case 0x14:
                FAPI_ATTR_GET(ATTR_PG_EQ4, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EQ4 value = %x", attr_value);
                break;
            case 0x15:
                FAPI_ATTR_GET(ATTR_PG_EQ5, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EQ5 value = %x", attr_value);
                break;
            case 0x20:
                FAPI_ATTR_GET(ATTR_PG_EC00, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC00 value = %x", attr_value);
                break;
            case 0x21:
                FAPI_ATTR_GET(ATTR_PG_EC01, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC01 value = %x", attr_value);
                break;
            case 0x22:
                FAPI_ATTR_GET(ATTR_PG_EC02, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC02 value = %x", attr_value);
                break;
            case 0x23:
                FAPI_ATTR_GET(ATTR_PG_EC03, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC03 value = %x", attr_value);
                break;
            case 0x24:
                FAPI_ATTR_GET(ATTR_PG_EC04, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC04 value = %x", attr_value);
                break;
            case 0x25:
                FAPI_ATTR_GET(ATTR_PG_EC05, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC05 value = %x", attr_value);
                break;
            case 0x26:
                FAPI_ATTR_GET(ATTR_PG_EC06, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC06 value = %x", attr_value);
                break;
            case 0x27:
                FAPI_ATTR_GET(ATTR_PG_EC07, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC07 value = %x", attr_value);
                break;
            case 0x28:
                FAPI_ATTR_GET(ATTR_PG_EC08, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC08 value = %x", attr_value);
                break;
            case 0x29:
                FAPI_ATTR_GET(ATTR_PG_EC09, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC09 value = %x", attr_value);
                break;
            case 0x2A:
                FAPI_ATTR_GET(ATTR_PG_EC10, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC10 value = %x", attr_value);
                break;
            case 0x2B:
                FAPI_ATTR_GET(ATTR_PG_EC11, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC11 value = %x", attr_value);
                break;
            case 0x2C:
                FAPI_ATTR_GET(ATTR_PG_EC12, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC12 value = %x", attr_value);
                break;
            case 0x2D:
                FAPI_ATTR_GET(ATTR_PG_EC13, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC13 value = %x", attr_value);
                break;
            case 0x2E:
                FAPI_ATTR_GET(ATTR_PG_EC14, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC14 value = %x", attr_value);
                break;
            case 0x2F:
                FAPI_ATTR_GET(ATTR_PG_EC15, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC15 value = %x", attr_value);
                break;
            case 0x30:
                FAPI_ATTR_GET(ATTR_PG_EC16, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC16 value = %x", attr_value);
                break;
            case 0x31:
                FAPI_ATTR_GET(ATTR_PG_EC17, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC17 value = %x", attr_value);
                break;
            case 0x32:
                FAPI_ATTR_GET(ATTR_PG_EC18, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC18 value = %x", attr_value);
                break;
            case 0x33:
                FAPI_ATTR_GET(ATTR_PG_EC19, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC19 value = %x", attr_value);
                break;
            case 0x34:
                FAPI_ATTR_GET(ATTR_PG_EC20, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC20 value = %x", attr_value);
                break;
            case 0x35:
                FAPI_ATTR_GET(ATTR_PG_EC21, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC21 value = %x", attr_value);
                break;
            case 0x36:
                FAPI_ATTR_GET(ATTR_PG_EC22, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC22 value = %x", attr_value);
                break;
            case 0x37:
                FAPI_ATTR_GET(ATTR_PG_EC23, i_target, attr_value);
                FAPI_DBG("ATTR_PG_EC23 value = %x", attr_value);
                break;
            default:
                FAPI_ERR("PervPGTargets:  invalid chiplet number %u", i_chiplet_num);
        }

        if (attr_value & 0xC000)
        {
            o_present = true;
        }

        return fapi2::FAPI2_RC_SUCCESS;

    }

    /// @brief Function to determine if pervsaive target within a chip is
    ///     present and, thus, considered functional per PG attributes
    template<fapi2::TargetType K>
    fapi2::ReturnCode
    plat_TargetPresent( fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> & i_chip_target,
                        fapi2::Target<K> & i_chiplet_target,
                        bool & b_present)
    {

        // Find the PERV target number in the partial good initialization
        // array
        fapi2::ChipletNumber_t chiplet_number = i_chiplet_target.getChipletNumber();

        FAPI_TRY(plat_PervPGTargets(i_chip_target, chiplet_number, b_present));

        if (b_present)
        {
            i_chiplet_target.setPresent();
            i_chiplet_target.setFunctional();
        }
        else
        {
            FAPI_DBG("Perv target NOT present (nor functional): chiplet_number = %d",
                        chiplet_number);
        }

        FAPI_DBG("Target present = %u, Target functional = %u",
            i_chiplet_target.getPresent(),
            i_chiplet_target.getFunctional());
            
fapi_try_exit:
        return fapi2::current_err;
    }


    /// @brief Function to initialize the G_targets vector based on partial good
    ///      attributes ///  this will move to plat_target.H formally
    fapi2::ReturnCode plat_TargetsInit()
    {
        bool b_present = false;
        uint32_t c = 0;

        // Initialise global attribute pointers
        G_system_attributes_ptr = &G_system_attributes;
        G_proc_chip_attributes_ptr = &G_proc_chip_attributes;
        G_perv_attributes_ptr = &G_perv_attributes;
        G_core_attributes_ptr = &G_core_attributes;
        G_eq_attributes_ptr = &G_eq_attributes;
        G_ex_attributes_ptr = &G_ex_attributes;


        // This is workaround. Currently we do not have code to initialise
        // global objects. So initializing global objects against using local
        // initialized object
        std::vector<fapi2::plat_target_handle_t> targets1;
        G_vec_targets = std::move(targets1);
        std::vector<fapi2::plat_target_handle_t>::iterator tgt_iter;
        uint32_t l_beginning_offset;

        FAPI_DBG("Platform target initialization.  Target Count = %u", TARGET_COUNT);
        /*
         * Initialize all entries to NULL
         */
        for (uint32_t i = 0; i < TARGET_COUNT; ++i)
        {
            G_vec_targets.push_back((fapi2::plat_target_handle_t)0x0);
            FAPI_DBG("Nulling G_vec_targets[%u] hi value=0x%08X",
                        i, (uint32_t)(G_vec_targets.at(i)>>32));

        }
        FAPI_DBG("Vector size: %u", G_vec_targets.size());

        /*
         * Chip Target is the first one
         */
        FAPI_DBG("Chip Target info: CHIP_TARGET_OFFSET %u CHIP_TARGET_COUNT %u ",
                      CHIP_TARGET_OFFSET,CHIP_TARGET_COUNT);

        l_beginning_offset = CHIP_TARGET_OFFSET;

        fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> chip_target((fapi2::plat_target_handle_t)0);
        G_vec_targets.at(l_beginning_offset) = revle64((fapi2::plat_target_handle_t)(chip_target.get()));

        /*
         * Pervasive Targets
         */
        FAPI_DBG("Pervasive Target info: PERV_TARGET_OFFSET %u PERV_TARGET_COUNT %u",
                      PERV_TARGET_OFFSET, PERV_TARGET_COUNT);

        l_beginning_offset = PERV_TARGET_OFFSET;
        for (uint32_t i = 0; i < PERV_TARGET_COUNT; ++i)
        {
            fapi2::Target<fapi2::TARGET_TYPE_PERV> target_name((fapi2::plat_target_handle_t)i+1);
            FAPI_DBG("target_name i = %d hi word = 0x%08X", i+1, (uint32_t)(target_name.get()>>32));

            // Determine if the chiplet is present and, thus, functional
            // via partial good attributes
            FAPI_TRY(plat_TargetPresent(chip_target, target_name, b_present));

            G_vec_targets.at(l_beginning_offset+i) = revle64((fapi2::plat_target_handle_t)(target_name.get()));
            FAPI_DBG("G offset = %d", l_beginning_offset+i);
        }

        /*
         * Cache (EQ) Targets
         */
        FAPI_DBG("EQ Target info: EQ_TARGET_OFFSET %u EQ_TARGET_COUNT %u",
                      EQ_TARGET_OFFSET,  EQ_TARGET_COUNT);
        l_beginning_offset = EQ_TARGET_OFFSET;
        for (uint32_t i = 0; i < EQ_TARGET_COUNT; ++i)
        {
            fapi2::Target<fapi2::TARGET_TYPE_EQ> target_name((fapi2::plat_target_handle_t)i);
            FAPI_DBG("target_name i = %d hi word = 0x%08X", i, (uint32_t)(target_name.get()>>32));

            // Determine if the chiplet is present and, thus, functional
            // via partial good attributes
            FAPI_TRY(plat_TargetPresent(chip_target, target_name, b_present));

            G_vec_targets.at(l_beginning_offset+i) = revle64((fapi2::plat_target_handle_t)(target_name.get()));
            FAPI_DBG("G offset = %d", l_beginning_offset+i);
        }

        /*
         * Core (EC) Targets
         */
        FAPI_DBG("Core Target info: CORE_TARGET_OFFSET %u CORE_TARGET_COUNT %u",
                      CORE_TARGET_OFFSET, CORE_TARGET_COUNT);

        l_beginning_offset = CORE_TARGET_OFFSET;
        FAPI_DBG("Core beginning offset =%u", l_beginning_offset);
        for (uint32_t i = 0; i < CORE_TARGET_COUNT; ++i)
        {
            fapi2::Target<fapi2::TARGET_TYPE_CORE> target_name((fapi2::plat_target_handle_t)i);
            FAPI_DBG("target_name i = %d hi word = 0x%08X", i, (uint32_t)(target_name.get()>>32));

            // Determine if the chiplet is present and, thus, functional
            // via partial good attributes
            FAPI_TRY(plat_TargetPresent(chip_target, target_name, b_present));

            G_vec_targets.at(l_beginning_offset+i) = revle64((fapi2::plat_target_handle_t)(target_name.get()));
            FAPI_DBG("G offset = %d", l_beginning_offset+i);
        }

        /*
         * Memory Controller Synchronous (MCS) Targets
         */
        FAPI_DBG("MCS Target info: MCS_TARGET_OFFSET %u MCS_TARGET_COUNT %u",
                      MCS_TARGET_OFFSET, MCS_TARGET_COUNT);

        l_beginning_offset = MCS_TARGET_OFFSET;
        FAPI_DBG("MCS beginning offset =%u", l_beginning_offset);
        for (uint32_t i = 0; i < MCS_TARGET_COUNT; ++i)
        {
            fapi2::Target<fapi2::TARGET_TYPE_MCS> target_name((fapi2::plat_target_handle_t)i);
            FAPI_DBG("target_name i = %d hi word = 0x%08X", i, (uint32_t)(target_name.get()>>32));
            
            // Determine if the chiplet is present and, thus, functional
            // via partial good attributes
            FAPI_TRY(plat_TargetPresent(chip_target, target_name, b_present));

            G_vec_targets.at(l_beginning_offset+i) = revle64((fapi2::plat_target_handle_t)(target_name.get()));
            FAPI_DBG("G offset = %d", l_beginning_offset+i);

        }

        // Trace all entries
        for (auto tgt_iter : G_vec_targets)
        {
            FAPI_DBG("Trace hi word G_vec_targets[%u] value=%08X",
                       c, (uint32_t)(tgt_iter>>32));
            ++c;
        }

fapi_try_exit:
        return fapi2::current_err;
    }

    /// @brief Function to initialize the G_targets vector based on partial good
    ///        attributes
    fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> plat_getChipTarget()
    {

        // Get the chip specific target
        return ((fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>)G_vec_targets.at(0));
    }


} // fapi2
OpenPOWER on IntegriCloud