summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/service/prdfPlatServices.C
blob: 9c6173c51c03d4b5c54ce60fa187fd0918b51366 (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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/service/prdfPlatServices.C $ */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/**
 * @file prdfPlatServices.C
 * @brief PRD wrapper of external componnets ( other then targetting)
 */

//------------------------------------------------------------------------------
//  Includes
//------------------------------------------------------------------------------

#include <prdfPlatServices.H>

#include <iipbits.h>
#include <iipsdbug.h>
#include <iipglobl.h>
#include <prdfTrace.H>

#include <fapi.H>

#ifdef __HOSTBOOT_MODULE
  #include <time.h>
  #include <errno.h>
  #include <sys/time.h>
  #include <diag/mdia/mdia.H>
  #include <diag/mdia/mdiamevent.H>
  #include <fapiPlatHwpInvoker.H>
  #include <dimmBadDqBitmapFuncs.H>
#else
  #include <iplp_registry.H>
  #include <mboxclientlib.H>
  #include <mnfgPolicyFlags.H>
  #include <smgr_ipltypes.H>
  #include <smgr_registry.H>
  #include <svpd_externals.H>
  #include <svpdextstructs.H>
  #include <GardExtInt.H>
  #include <dscvReg.H>
  #include <dadaProcMsViaProc.H>
  #include <utillib.H>
  #include <rmgrBaseClientLib.H>
  #include <services/hwas/hwsvHwAvailSvc.H> // For deconfigureTargetAtRuntime()
#endif

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

namespace PRDF
{

namespace PlatServices
{

//##############################################################################
//##
//##                        Hostboot and FSP functions
//##
//##############################################################################

//##############################################################################
//##                     System Level Utility Functions
//##############################################################################

bool isMasterFSP()
{
    bool l_isMaster = true;
    #ifdef __HOSTBOOT_MODULE
    // Always true in hostboot
    l_isMaster = true;
    #else
    // We're going to assume master because it's better to have scom
    // errors by writing on the slave then to not do something on the
    // master.

    errlHndl_t l_errl = NULL;
    uint8_t l_roleRegValue;
    size_t l_roleRegSize = sizeof(l_roleRegValue);

    l_errl = UtilReg::read(FSP_ROLE_STR,&l_roleRegValue,
                        l_roleRegSize);

    if (NULL != l_errl)
    {
        PRDF_COMMIT_ERRL(l_errl, ERRL_ACTION_REPORT);
    }
    else
    {
        l_isMaster = (DSCV_FSP_MASTER == l_roleRegValue);
    }
    #endif

    return l_isMaster;
}

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

bool isMemoryPreservingIpl()
{
    bool l_isMemPreservingIpl = false;
    #ifdef __HOSTBOOT_MODULE
    //TODO
    #else
    //if (inCMMode())
    //    return false;

    // Check the fsp ipl type so we know if this needs to be initialized
    uint32_t l_iplType = 0x00000000;
    size_t l_size = sizeof( l_iplType );

    // Terry Opie Comments:  First thing I see...  You're gonna want to
    // read:SMGR_REG_CECIPL_TYPE_KEY instead of the fsp ipl type.
    // The one(SMGR_REG_FSPIPL_TYPE_KEY) you're reading is strictly fsp
    // related ipl types.  resets/reset reloads, etc.

    errlHndl_t l_errl = UtilReg::read( SMGR_REG_CECIPL_TYPE_KEY,
                                    &l_iplType,
                                    l_size );
    if (NULL != l_errl)
    {
        PRDF_ERR( "[isMemoryPreservingIpl] Failed to read registry" );
        PRDF_COMMIT_ERRL(l_errl, ERRL_ACTION_REPORT);
    }
    else
    {
        // Terry Opie Comments:  Also for checking the mask..You can do
        // it the way you have it,or use a macro that are in
        // smgr_ipltypes.H. Returns true if the Main Store preserved
        // attribute bit is set #define
        // SMGR_IPLTYPE_IS_MS_PRESVD(_i_ipltype_)(((_i_ipltype_)&
        // SMGR_ATTR_MS_PRESVD_MASK) != 0)Call that
        // passing in the ipl type, and it'll return true if its Mem presv.
        if(SMGR_IPLTYPE_IS_MS_PRESVD(l_iplType))
        {
            l_isMemPreservingIpl = true;
        }
    }
    #endif

    return l_isMemPreservingIpl;
}

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

void getECIDString(TARGETING::TargetHandle_t i_pGivenTarget, const char *o_ecidStr )
{
    o_ecidStr ="";
    PRDF_ERR( "[getECIDString] Function not implemented yet" );

}

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

void getCurrentTime( PrdTimer & o_timer )
{
#ifdef __HOSTBOOT_MODULE

    timespec_t curTime;
    PRDF_ASSERT(0 == clock_gettime(CLOCK_MONOTONIC, &curTime))

    // Hostboot uptime in secs
    o_timer = curTime.tv_sec;

    //Since Hostboot doesn't have any System checkstop
    //We don't have to worry about the detailed time struct
    //for System checkstop timestamp

#else

    time_t thetime = time(NULL);
    struct tm * l_curEventTime = localtime(&thetime);

    // record the detailed time struct
    PrdTimer::prdftm_t l_tm(l_curEventTime->tm_sec,
                            l_curEventTime->tm_min,
                            l_curEventTime->tm_hour,
                            l_curEventTime->tm_wday,
                            l_curEventTime->tm_mday,
                            l_curEventTime->tm_yday,
                            l_curEventTime->tm_mon,
                            l_curEventTime->tm_year);
    o_timer.settm(l_tm);

#endif
}

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

errlHndl_t syncFile( const char* i_fileName )
{
#ifdef __HOSTBOOT_MODULE
    return NULL;
#else
    return rmgrSyncFile(PRDF_COMP_ID, i_fileName);
#endif
}

//##############################################################################
//##                     MNFG Policy Flag Functions
//##############################################################################

#ifdef __HOSTBOOT_MODULE

// TODO: This is a hack until we are able to get these flags supported in
//       Hostboot.
enum
{
    MNFG_THRESHOLDS = 0,
    MNFG_HDAT_AVP_ENABLE,
    MNFG_SRC_TERM,
    MNFG_NO_RBS,
};

#endif

// Helper function to access the state of manufacturing policy flags.
// TODO: Need hostboot support for the following flags:
//          MNFG_AVP_ENABLE
//          MNFG_SRC_TERM
//          MNFG_NO_RBS
//          MNFG_FAST_BACKGROUND_SCRUB
//          MNFG_TEST_RBS
//          MNFG_IPL_MEMORY_CE_CHECKING
bool isMnfgFlagSet( uint32_t i_flag )
{
    bool o_rc = false;

    #ifdef __HOSTBOOT_MODULE

    // TODO - mnfgIsPolicyFlagSet() may not be supported in hostboot. Need to
    // verify how this will be done.
    PRDF_ERR( "[isMnfgFlagSet] Hostboot Function not implemented yet" );

    #else

    errlHndl_t errl = mnfgIsPolicyFlagSet( i_flag, o_rc );
    if ( NULL != errl )
    {
        PRDF_ERR( "[isMnfgFlagSet] mnfgIsPolicyFlagSet(0x%08x)", i_flag );
        PRDF_COMMIT_ERRL(errl, ERRL_ACTION_REPORT);
        o_rc = false;
    }

    #endif

    return o_rc;
}

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

bool mfgMode()       { return isMnfgFlagSet( MNFG_THRESHOLDS      ); }
bool hdatAvpMode()   { return isMnfgFlagSet( MNFG_HDAT_AVP_ENABLE ); }
bool mnfgTerminate() { return isMnfgFlagSet( MNFG_SRC_TERM        ); }
bool areDramRepairsDisabled() { return isMnfgFlagSet( MNFG_NO_RBS ); }

//##############################################################################
//##                        Memory specific functions
//##############################################################################

/* TODO - Get the memory buffer raw card type (i.e. R/C A). This is needed for
          the DRAM site locations for buffered DIMMs. Should be able to get this
          from an attribute but doesn't look like this is available yet.
getMembufRawCardType()
{
}
*/

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

/* TODO - Get the type of the card a DIMM is plugged into. This is needed for
          the DRAM site locations for IS DIMMs. Should be able to get this from
          an attribute but doesn't look like this is available yet.
getDimmPlugCardType()
{
}
*/

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

/* TODO
//------------------------------------------------------------------------------

int32_t setBadDqBitmap( TARGETING::TargetHandle_t i_mbaTarget
                        const uint8_t i_portSlct,
                        const uint8_t i_dimmSlct,
                        const uint8_t i_rankSlct,
                        const uint8_t (&i_data)[DIMM_DQ_RANK_BITMAP_SIZE] )
{
    int32_t o_rc = SUCCESS;

    // TODO: Call dimmSetBadDqBitmap() in dimmBadDqBitmapFuncs.H.
    // NOTE: DIMM_DQ_RANK_BITMAP_SIZE is in dimmConsts.H
    // NOTE: Will need to convert TARGETING::TargetHandle_t to fapi::Target.

    return o_rc;
}
*/

//##############################################################################
//##
//##                        Hostboot only functions
//##
//##############################################################################

#ifdef __HOSTBOOT_MODULE

bool isInMdiaMode()
{
    bool o_isInMdiaMode = false;

    MDIA::waitingForMaintCmdEvents(o_isInMdiaMode);

    return o_isInMdiaMode;
}

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

int32_t mdiaSendCmdComplete( TARGETING::TargetHandle_t i_mbaTarget )
{
    using namespace TARGETING;

    int32_t o_rc = SUCCESS;

    do
    {
        // Verify type.
        TYPE l_type = getTargetType(i_mbaTarget);
        if ( TYPE_MBA != l_type )
        {
            PRDF_ERR( "[PlatServices::mdiaSendCmdComplete] unsupported target "
                      "type %d", l_type );
            o_rc = FAIL;
            break;
        }

        // Send command complete to MDIA.
        MDIA::MaintCommandEvent l_mdiaEvent;
        l_mdiaEvent.type   = MDIA::COMMAND_COMPLETE;
        l_mdiaEvent.target = i_mbaTarget;

        errlHndl_t errl = MDIA::processEvent( l_mdiaEvent );
        if ( NULL != errl )
        {
            PRDF_ERR( "[PlatServices::mdiaSendCmdComplete] MDIA::processEvent "
                      "failed" );
            PRDF_COMMIT_ERRL( errl, ERRL_ACTION_REPORT );
            o_rc = FAIL;
            break;
        }

    } while (0);

    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( "[PlatServices::mdiaSendCmdComplete] Failed: i_target=0x%08x",
                  getHuid(i_mbaTarget) );
    }

    return o_rc;
}

int32_t mssGetMarkStore(
        TARGETING::TargetHandle_t i_mbaTarget,
        uint8_t i_rank,
        uint8_t & o_chipMark,
        uint8_t & o_symbolMark)
{
    int32_t o_rc = SUCCESS;

    errlHndl_t err = NULL;

    FAPI_INVOKE_HWP(
            err,
            mss_get_mark_store,
            fapi::Target(fapi::TARGET_TYPE_MBA_CHIPLET, i_mbaTarget),
            i_rank,
            o_chipMark,
            o_symbolMark);

    if(NULL != err)
    {
        PRDF_ERR( "[PlatServices::mssGetMarkStore] mss_get_mark_store"
                "failed" );
        PRDF_COMMIT_ERRL( err, ERRL_ACTION_REPORT );
        o_rc = FAIL;
    }

    return o_rc;
}

int32_t mssGetSteerMux(
        TARGETING::TargetHandle_t i_mbaTarget,
        uint8_t i_rank,
        mss_SteerMux::muxType i_muxType,
        uint8_t & o_portZeroSpare,
        uint8_t & o_portOneSpare,
        uint8_t & o_eccSpare)
{
    int32_t o_rc = SUCCESS;

    errlHndl_t err = NULL;

    FAPI_INVOKE_HWP(
            err,
            mss_get_steer_mux,
            fapi::Target(fapi::TARGET_TYPE_MBA_CHIPLET, i_mbaTarget),
            i_rank,
            i_muxType,
            o_portZeroSpare,
            o_portOneSpare,
            o_eccSpare);

    if(NULL != err)
    {
        PRDF_ERR( "[PlatServices::mssGetSteerMux] mss_get_steer_mux"
                "failed" );
        PRDF_COMMIT_ERRL( err, ERRL_ACTION_REPORT );
        o_rc = FAIL;
    }

    return o_rc;

}

int32_t mssRestoreDramRepairs(
        TARGETING::TargetHandle_t i_mbaTarget,
        uint8_t & o_repairedRankMask,
        uint8_t & o_badDimmMask)
{
    int32_t o_rc = SUCCESS;

    errlHndl_t err = NULL;

    // FIXME uncomment when this function exists ... RTC 51507

#if 0

    FAPI_INVOKE_HWP(
            err,
            mss_restore_dram_repairs,
            fapi::Target(fapi::TARGET_TYPE_MBA_CHIPLET, i_mbaTarget),
            o_repairedRankMask,
            o_badDimmMask);
#endif

    if(NULL != err)
    {
        PRDF_ERR( "[PlatServices::mssRestoreDramRepairs] "
                "mss_restore_dram_repairs failed" );
        PRDF_COMMIT_ERRL( err, ERRL_ACTION_REPORT );
        o_rc = FAIL;
    }

    return o_rc;
}

int32_t getBadDqBitmap( TARGETING::TargetHandle_t i_mbaTarget,
        const uint8_t i_portSlct,
        const uint8_t i_dimmSlct,
        const uint8_t i_rankSlct,
        uint8_t (&o_data)[DIMM_DQ_RANK_BITMAP_SIZE] )
{
    int32_t o_rc = SUCCESS;

    errlHndl_t err = NULL;

    FAPI_INVOKE_HWP(
            err,
            dimmGetBadDqBitmap,
            fapi::Target(fapi::TARGET_TYPE_MBA_CHIPLET, i_mbaTarget),
            i_portSlct,
            i_dimmSlct,
            i_rankSlct,
            o_data);

    if(NULL != err)
    {
        PRDF_ERR( "[PlatServices::getBadDqBitmap] dimmGetBadDqBitmap"
                "failed" );
        PRDF_COMMIT_ERRL( err, ERRL_ACTION_REPORT );
        o_rc = FAIL;
    }

    return o_rc;
}

#endif // __HOSTBOOT_MODULE

//##############################################################################
//##
//##                           FSP only functions
//##
//##############################################################################

#ifndef __HOSTBOOT_MODULE

errlHndl_t runtimeDeconfig( TARGETING::TargetHandle_t i_target )
{
    using namespace HWAS;
    return deconfigureTargetAtRuntime( i_target, DECONFIG_FOR_DUMP );
}

#endif // not __HOSTBOOT_MODULE

} // end namespace PlatServices

} // end namespace PRDF

OpenPOWER on IntegriCloud