summaryrefslogtreecommitdiffstats
path: root/sbe/sbefw/sbecmdiplcontrol.C
blob: 5bc700c0b3c174c9c55edd779c5dd7aad1749a60 (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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*
 * @file: ppe/sbe/sbefw/sbecmdiplcontrol.C
 *
 * @brief This file contains the SBE istep chipOps
 *
 */

#include "sbecmdiplcontrol.H"
#include "sbefifo.H"
#include "sbetrace.H"
#include "sbe_sp_intf.H"
#include "assert.h"

#include "fapi2.H"
// Pervasive HWP Header Files ( istep 2)
#include <p9_sbe_attr_setup.H>
#include <p9_sbe_tp_chiplet_init1.H>
#include <p9_sbe_npll_initf.H>
#include <p9_sbe_npll_setup.H>
#include <p9_sbe_tp_switch_gears.H>
#include <p9_sbe_tp_chiplet_reset.H>
#include <p9_sbe_tp_gptr_time_repr_initf.H>
#include <p9_sbe_tp_chiplet_init2.H>
#include <p9_sbe_tp_arrayinit.H>
#include <p9_sbe_tp_initf.H>
#include <p9_sbe_tp_chiplet_init3.H>

// Pervasive HWP Header Files ( istep 3)
#include <p9_sbe_chiplet_reset.H>
#include <p9_sbe_chiplet_pll_initf.H>
#include <p9_sbe_chiplet_pll_setup.H>
#include <p9_sbe_gptr_time_repr_initf.H>
#include <p9_sbe_chiplet_init.H>
#include <p9_sbe_arrayinit.H>
#include <p9_sbe_tp_enable_ridi.H>
#include <p9_sbe_setup_evid.H>
#include <p9_sbe_nest_initf.H>
#include <p9_sbe_nest_startclocks.H>
#include <p9_sbe_nest_enable_ridi.H>
#include <p9_sbe_startclock_chiplets.H>
#include <p9_sbe_scominit.H>
#include <p9_sbe_lpc_init.H>
#include <p9_sbe_fabricinit.H>
#include <p9_sbe_mcs_setup.H>
#include <p9_sbe_select_ex.H>
// Cache HWP header file
#include "p9_hcd_cache.H"
// Core HWP header file
#include "p9_hcd_core.H"

// Forward declaration
using namespace fapi2;
ReturnCode sbeExecuteIstep (uint8_t i_major, uint8_t i_minor);
bool validateIstep (uint8_t i_major, uint8_t i_minor);


//typedefs
typedef ReturnCode (*sbeIstepHwp_t)
                    (const Target<TARGET_TYPE_ALL> & i_target);

// Wrapper function for HWP IPl functions
typedef ReturnCode (*sbeIstep_t)( sbeIstepHwp_t );

// Wrapper function which will call HWP with Proc target.
ReturnCode istepWithProc( sbeIstepHwp_t i_hwp );
ReturnCode istepNoOp( sbeIstepHwp_t i_hwp );

ReturnCode istepWithEx( sbeIstepHwp_t i_hwp);

ReturnCode istepWithEq( sbeIstepHwp_t i_hwp);
ReturnCode istepWithCore( sbeIstepHwp_t i_hwp);
//structure for mapping SBE wrapper and HWP functions

typedef struct
{
    sbeIstep_t istepWrapper;
    sbeIstepHwp_t istepHwp;
}istepMap_t;

// Major isteps which are supported
typedef enum
{
    SBE_ISTEP2 = 2,
    SBE_ISTEP3 = 3,
    SBE_ISTEP4 = 4,
    SBE_ISTEP5 = 5,
}sbe_supported_steps_t;

// constants
// TODO via RTC 135345
// Check with Dean. In IPL flow doc ( version 0.63 ),
// after istep 2.9, next istep is 2.11. istep 2.10 is not present.
// So in IPL flow doc, total minor isteps for step 2 are 16.
const uint32_t ISTEP2_MAX_SUBSTEPS = 15;
const uint32_t ISTEP3_MAX_SUBSTEPS = 20;
const uint32_t ISTEP4_MAX_SUBSTEPS = 31;
const uint32_t ISTEP5_MAX_SUBSTEPS = 2;

// File static data

static istepMap_t g_istep2PtrTbl[ ISTEP2_MAX_SUBSTEPS ] =
         {
             { NULL, NULL },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_attr_setup },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_chiplet_init1 },
             { &istepNoOp, NULL },  // DFT only
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_npll_initf },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_npll_setup },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_switch_gears },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_chiplet_reset },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_gptr_time_repr_initf },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_chiplet_init2 },
             { &istepNoOp, NULL },  // DFT only
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_arrayinit },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_initf },
             { &istepNoOp, NULL }, // DFT only
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_chiplet_init3},
         };

static istepMap_t g_istep3PtrTbl[ ISTEP3_MAX_SUBSTEPS ] =
         {
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_chiplet_reset },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_chiplet_pll_initf },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_chiplet_pll_setup },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_gptr_time_repr_initf },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_chiplet_init },
             { &istepNoOp, NULL }, // DFT only
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_arrayinit },
             { &istepNoOp, NULL }, // DFT only
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_tp_enable_ridi },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_setup_evid },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_nest_initf },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_nest_startclocks },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_nest_enable_ridi },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_startclock_chiplets },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_scominit },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_lpc_init },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_fabricinit },
             { &istepNoOp, NULL }, // TODO via RTC 120752
                                   // FW proc_sbe_check_master
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_mcs_setup },
             { &istepWithProc, (sbeIstepHwp_t)&p9_sbe_select_ex },
         };
static istepMap_t g_istep4PtrTbl[ ISTEP4_MAX_SUBSTEPS ] =
         {
             { &istepWithEq, (sbeIstepHwp_t )&p9_hcd_cache_poweron },
             { &istepWithEq, (sbeIstepHwp_t )&p9_hcd_cache_chiplet_reset },
             { &istepWithEq, (sbeIstepHwp_t )&p9_hcd_cache_gptr_time_initf },
             { &istepWithEq, (sbeIstepHwp_t )&p9_hcd_cache_dpll_setup },
             { &istepWithEq, (sbeIstepHwp_t )&p9_hcd_cache_chiplet_init },
             { &istepWithEx, (sbeIstepHwp_t )&p9_hcd_cache_repair_initf },
             { &istepWithEx, (sbeIstepHwp_t )&p9_hcd_cache_arrayinit },
             { &istepNoOp, NULL },  // DFT Only
             { &istepNoOp, NULL },  // DFT Only
             { &istepWithEx, (sbeIstepHwp_t )&p9_hcd_cache_initf },
             { &istepWithEx, (sbeIstepHwp_t )&p9_hcd_cache_startclocks },
             { &istepWithEx, (sbeIstepHwp_t )&p9_hcd_cache_scominit },
             { &istepWithEx, (sbeIstepHwp_t )&p9_hcd_cache_scomcust },
             { &istepNoOp, NULL }, // Runtime only
             { &istepNoOp, NULL }, // Runtime only
             { &istepNoOp, NULL }, // stub for SBE
             // TODO via RTC 135345
             // As per IPL flow doc, p9_hcd_core_pcb_arb is no-op on SBE
             // But this HWP is present in SBE code bas and is No-OP.
             // If we do not require this HWP for future use cases, we
             // can make it istepNoOp as it will save space in SBE.
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_pcb_arb },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_poweron },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_chiplet_reset },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_gptr_time_initf },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_chiplet_init },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_repair_initf },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_arrayinit },
             { &istepNoOp, NULL },  // DFT Only
             { &istepNoOp, NULL },  // DFT Only
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_initf },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_startclocks },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_scominit },
             { &istepWithCore, (sbeIstepHwp_t )&p9_hcd_core_scomcust },
             { &istepNoOp, NULL },
             { &istepNoOp, NULL },
         };

// TODO via RTC 135345
//  Add the support for istep 5 HWP
static istepMap_t g_istep5PtrTbl[ ISTEP5_MAX_SUBSTEPS ]
         {
             { &istepNoOp, NULL },
             { &istepNoOp, NULL },
         };

// Functions
//----------------------------------------------------------------------------
uint32_t sbeHandleIstep (uint8_t *i_pArg)
{
    #define SBE_FUNC "sbeHandleIstep "
    SBE_DEBUG(SBE_FUNC);
    uint32_t rc = SBE_SEC_OPERATION_SUCCESSFUL;
    uint8_t len = 0;
    ReturnCode fapiRc = FAPI2_RC_SUCCESS;
    sbeIstepReqMsg_t req;
    sbeResponseGenericHeader_t respHdr;
    respHdr.init();
    sbeResponseFfdc_t ffdc;

    // NOTE: In this function we will have two loops
    // First loop will deque data and prepare the response
    // Second response will enque the data on DS FIFO
    //loop 1
    do
    {
        // @TODO via RTC : 130575
        // Optimize both the RC handling and
        // FIFO operation infrastructure.
        len = sizeof( req )/sizeof(uint32_t);
        rc = sbeUpFifoDeq_mult ( len, (uint32_t *)&req);
        if (rc) //FIFO access issue
        {
            SBE_ERROR(SBE_FUNC"FIFO dequeue failed, rc[0x%X]", rc);
            break;
        }
        len = 1;
        rc = sbeUpFifoDeq_mult ( len, NULL, true );

        // If we didn't receive EOT yet
        if ( rc != SBE_FIFO_RC_EOT_ACKED )
        {
            SBE_ERROR(SBE_FUNC"FIFO dequeue failed, rc[0x%X]", rc);
            break;
        }
        // override Rc as we do not want to treat SBE_FIFO_RC_EOT_ACKED as error
        rc = SBE_SEC_OPERATION_SUCCESSFUL;

        SBE_DEBUG(SBE_FUNC"Major number:0x%08x minor number:0x%08x",
                  req.major, req.minor );

        if( false == validateIstep( req.major, req.minor ) )
        {
            SBE_ERROR(SBE_FUNC" Invalid Istep. major:0x%08x"
                      " minor:0x%08x", req.major, req.minor);
            // @TODO via RTC 132295.
            // Need to change code asper better error handling.
            respHdr.setStatus( SBE_PRI_INVALID_DATA,
                               SBE_SEC_GENERIC_FAILURE_IN_EXECUTION);
            break;
        }
        fapiRc = sbeExecuteIstep( req.major, req.minor );
        if( fapiRc != FAPI2_RC_SUCCESS )
        {
            SBE_ERROR(SBE_FUNC" sbeExecuteIstep() Failed. major:0x%08x"
                                      " minor:0x%08x", req.major, req.minor);
            respHdr.setStatus( SBE_PRI_GENERIC_EXECUTION_FAILURE,
                               SBE_SEC_GENERIC_FAILURE_IN_EXECUTION);
            ffdc.setRc(fapiRc);
        }

    }while(0);

    //loop 2
    do
    {
        // FIFO error
        if ( rc )
        {
            break;
        }

        uint32_t distance = 1; //initialise by 1 for entry count itself.
        len = sizeof(respHdr)/sizeof(uint32_t);
        // sbeDownFifoEnq_mult.
        rc = sbeDownFifoEnq_mult ( len, ( uint32_t *) &respHdr);
        if (rc)
        {
            break;
        }
        distance += len;

        // If no ffdc , exit;
        if( ffdc.getRc() )
        {
            len = sizeof(ffdc)/sizeof(uint32_t);
            rc = sbeDownFifoEnq_mult ( len, ( uint32_t *) &ffdc);
            if (rc)
            {
                break;
            }
            distance += len;
        }
        len = sizeof(distance)/sizeof(uint32_t);
        //@TODO via RTC 129076.
        //Need to add FFDC data as well.
        rc = sbeDownFifoEnq_mult ( len, &distance);
        if (rc)
        {
            break;
        }
    }while(0);

    if( rc )
    {
        SBE_ERROR( SBE_FUNC"Failed. rc[0x%X]", rc);
    }
    return rc;
    #undef SBE_FUNC
}

//----------------------------------------------------------------------------
// @note This is the responsibilty of caller to verify major/minor
//       number before calling this function

// @TODO via RTC 129077.
// This function should check for system checkstop as well.
ReturnCode sbeExecuteIstep (const uint8_t i_major, const uint8_t i_minor)
{
    #define SBE_FUNC "sbeExecuteIstep "
    SBE_DEBUG(SBE_FUNC"Major number:0x%x minor number:0x%x",
                       i_major, i_minor );

    ReturnCode rc = FAPI2_RC_SUCCESS;
    switch( i_major )
    {
        case SBE_ISTEP2:
            rc = (g_istep2PtrTbl[i_minor-1].istepWrapper)(
                                g_istep2PtrTbl[i_minor-1].istepHwp);
            break;

        case SBE_ISTEP3:
            rc = (g_istep3PtrTbl[i_minor-1].istepWrapper)(
                                g_istep3PtrTbl[i_minor-1].istepHwp);
            break;

        case SBE_ISTEP4:
            rc = (g_istep4PtrTbl[i_minor-1].istepWrapper)(
                              g_istep4PtrTbl[i_minor-1].istepHwp);
            break;

        case SBE_ISTEP5:
            rc = (g_istep5PtrTbl[i_minor-1].istepWrapper)(
                              g_istep5PtrTbl[i_minor-1].istepHwp);
            break;

        // We should never reach here as before calling this validation has
        // been done.
        default:
            assert(0);
            break;
        }

    return rc;
    #undef SBE_FUNC
}

//----------------------------------------------------------------------------
bool validateIstep (const uint8_t i_major, const uint8_t i_minor)
{
    bool valid = true;
    do
    {
        if( 0 == i_minor )
        {
            valid = false;
            break;
        }

        switch( i_major )
        {
            case SBE_ISTEP2:
                // istep 2.1 loads image to PIBMEM
                // So SBE control loop can not execute istep 2.1.
                if(( i_minor > ISTEP2_MAX_SUBSTEPS ) || ( i_minor == 1) )
                {
                    valid = false;
                }
                break;

            case SBE_ISTEP3:
                if( i_minor > ISTEP3_MAX_SUBSTEPS ) { valid = false; } ;
                break;

            case SBE_ISTEP4:
                if( i_minor > ISTEP4_MAX_SUBSTEPS )
                {
                    valid = false;
                }
                break;

            case SBE_ISTEP5:
                if( i_minor > ISTEP5_MAX_SUBSTEPS )
                {
                    valid = false;
                }
                break;

            default:
                valid= false;
                break;
        }
    } while(0);

    return valid;
}

//----------------------------------------------------------------------------

ReturnCode istepWithProc( sbeIstepHwp_t i_hwp)
{
    SBE_DEBUG("istepWithProc");
    Target<TARGET_TYPE_PROC_CHIP > proc = plat_getChipTarget();
    ReturnCode rc = FAPI2_RC_SUCCESS;
    if( i_hwp )
    {
        rc = i_hwp(proc);
    }
    SBE_DEBUG("istepWithProc");
    return rc;
}

//----------------------------------------------------------------------------

ReturnCode istepWithEx( sbeIstepHwp_t i_hwp)
{
    fapi2::Target<fapi2::TARGET_TYPE_EX > ex10_target((uint64_t)10);
    SBE_DEBUG("istepWithEx");
    ReturnCode rc = FAPI2_RC_SUCCESS;
    if( i_hwp )
    {
        rc = i_hwp(ex10_target);
    }
    return rc;
}

//----------------------------------------------------------------------------

ReturnCode istepWithEq( sbeIstepHwp_t i_hwp)
{
    // TODO via RTC 135345
    // Curently we are passing Hard code eq target. Finally it is
    // going to be a multicast target. Once multicast support is
    // present, use the right target.
    fapi2::Target<fapi2::TARGET_TYPE_EQ > eq10_target((uint64_t)10);
    SBE_DEBUG("istepWithEq");
    ReturnCode rc = FAPI2_RC_SUCCESS;
    if( i_hwp )
    {
        rc = i_hwp( eq10_target );
    }
    return rc;
}

//----------------------------------------------------------------------------

ReturnCode istepWithCore( sbeIstepHwp_t i_hwp)
{
    // TODO via RTC 135345
    // Curently we are passing Hard code core target. Finally it is
    // going to be a multicast target. Once multicast support is
    // present, use the right target.
    fapi2::Target<fapi2::TARGET_TYPE_CORE > core_target((uint64_t)10);
    SBE_DEBUG("istepWithCore");
    ReturnCode rc = FAPI2_RC_SUCCESS;
    if( i_hwp )
    {
        rc = i_hwp( core_target );
    }
    return rc;
}

//----------------------------------------------------------------------------

ReturnCode istepNoOp( sbeIstepHwp_t i_hwp)
{
    SBE_DEBUG("istepNoOp");
    return FAPI2_RC_SUCCESS ;
}

//----------------------------------------------------------------------------

uint32_t sbeWaitForSbeIplDone (uint8_t *i_pArg)
{
    uint32_t rc = SBE_SEC_OPERATION_SUCCESSFUL;
    SBE_TRACE("sbeWaitForSbeIplDone");


    return rc;
}
OpenPOWER on IntegriCloud