summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/istepHelperFuncs.H
blob: 27f8dd1336fe07ab6cc38cacf3ddb70cc8870dbe (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/istepHelperFuncs.H $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2018                        */
/* [+] 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                                                     */

#ifndef _ISTEP_HELPER_FUNCS_H
#define _ISTEP_HELPER_FUNCS_H

//  targeting support
#include    <targeting/common/commontargeting.H>
#include    <targeting/common/utilFilter.H>
#include    <attributetraits.H>
#include    <attributeenums.H>
#include    <initservice/isteps_trace.H>
#include    <fapi2.H>

// fapi2 HWP invoker
#include  <fapi2/plat_hwp_invoker.H>

// IStep Error support
#include  <isteps/hwpisteperror.H>

/**
 *  @brief Enum specifying what attributes should be used to set the
 *         memory _EFF_CONFIG attributes
 *
 */
enum EFF_CONFIG_ATTRIBUTES_BASE
{
    DEFAULT         = 0x00, ///< Use System Defaults
    POST_DRAM_INIT  = 0x01, ///< Use POST_DRAM_INIT attributes if non-zero
};

/**
 *  @brief Enum for per-domain control of different voltages
 */
enum MSS_PROGRAM_TYPE
{
    // domain is programmed as part of regular power on sequence
    POWERON_TYPE = 0,

    // domain needs to be programmed, no special computation needed
    STATIC_TYPE  = 1,

    // domain needs to be programmed, uses dynamic vid logic
    DYNAMIC_TYPE = 2,

    // domain needs to be programmed,
    // POWR responsible for vid values attained via sys vrm xml
    DEFAULT_TYPE = 3,
};

//
//  Helper function to set _EFF_CONFIG attributes for HWPs
//
void set_eff_config_attrs_helper( const EFF_CONFIG_ATTRIBUTES_BASE i_base,
                                  bool & o_post_dram_inits_found);

/**
 *  @brief Compares two mcbist targets based on the voltage domain ID for
 *      the voltage domain given by the template parameter.  Used for sorting
 *      mcbist targets within containers.  API should be called in well
 *      controlled conditions where the input restrictions can be guaranteed.
 *
 *  @param[in] i_pMcbistLhs
 *      Left hand side mcbist target.  Must be a mcbist target,
 *      and must not be NULL.  These conditions are not enforced internally.
 *
 *  @param[in] i_pMcbistRhs
 *      Right hand side mcbist target.  Must be a mcbist target,
 *      and must not be NULL.  These conditions are not enforced internally.
 *
 *  @tparam VOLTAGE_DOMAIN_ID_ATTR
 *      Attribute corresponding to voltage domain to compare
 *
 *  @return Bool indicating whether LHS mcbist target's voltage domain ID
 *      for the specified domain logically precedes the RHS mcbist
 *      target's voltage domain ID for the same domain
 */
template < const TARGETING::ATTRIBUTE_ID VOLTAGE_DOMAIN_ID_ATTR>
bool _compareMcbistWrtVoltageDomain(
    TARGETING::Target* i_pMcbistLhs,
    TARGETING::Target* i_pMcbistRhs)
{
    typename TARGETING::AttributeTraits< VOLTAGE_DOMAIN_ID_ATTR >::Type
        lhsDomain = i_pMcbistLhs->getAttr<VOLTAGE_DOMAIN_ID_ATTR>();
    typename TARGETING::AttributeTraits< VOLTAGE_DOMAIN_ID_ATTR >::Type
        rhsDomain = i_pMcbistRhs->getAttr<VOLTAGE_DOMAIN_ID_ATTR>();

    return lhsDomain < rhsDomain;
}


//******************************************************************************
// computeDynamicMemoryVoltage
//******************************************************************************

// TODO via RTC: 110777
// Optimize computeDynamicMemoryVoltage into templated and non-templated
// pieces to reduce code size
template< const TARGETING::ATTRIBUTE_ID OFFSET_DISABLEMENT_ATTR,
          const TARGETING::ATTRIBUTE_ID VOLTAGE_DOMAIN_ID_ATTR >
errlHndl_t computeDynamicMemoryVoltage()
{
  TRACDCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
            "computeDynamicMemoryVoltage enter");

  errlHndl_t pError = NULL;

  do
  {
    TARGETING::Target* pSysTarget = NULL;
    TARGETING::targetService().getTopLevelTarget(pSysTarget);
    assert(pSysTarget != NULL,
           "computeDynamicMemoryVoltage: System target was NULL.");

    typename TARGETING::AttributeTraits< OFFSET_DISABLEMENT_ATTR >::Type
        domainProgram =
            pSysTarget->getAttr< OFFSET_DISABLEMENT_ATTR >();


    if(domainProgram != MSS_PROGRAM_TYPE::DYNAMIC_TYPE)
    {
        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
            "INFO: Dynamic offset voltage processing disabled for domain type 0x%08X.",
            OFFSET_DISABLEMENT_ATTR);
        break;
    }

    TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
        "INFO: Offset voltage processing enabled for domain type 0x%08X.",
        OFFSET_DISABLEMENT_ATTR);

    typedef fapi2::ReturnCode (*pOffsetFn_t)(std::vector<fapi2::Target<fapi2::TARGET_TYPE_MCS>>&);

    struct {

        TARGETING::ATTRIBUTE_ID domain;
        pOffsetFn_t             fn;
        const char*             fnName;
        bool                    callIfAllNonFunc;

    } fnMap[] = {
/* TODO: RTC 157349 -- These HWPs don't exist yet
        {TARGETING::ATTR_AVDD_ID,
            p9_mss_dynamic_vid_avdd,"p9_mss_dynamic_vid_avdd", true},
        {TARGETING::ATTR_VDD_ID ,
            p9_mss_dynamic_vid_vdd ,"p9_mss_dynamic_vid_vdd", true},
        {TARGETING::ATTR_VCS_ID ,
            p9_mss_dynamic_vcs_avdd ,"p9_mss_dynamic_vcs_avdd", true},
        {TARGETING::ATTR_VDDR_ID,
            p9_mss_dynamic_vid_vddr,"p9_mss_dynamic_vid_vddr", false},
        {TARGETING::ATTR_VPP_ID ,
            p9_mss_dynamic_vid_vpp ,"p9_mss_dynamic_vid_vpp", false}
*/
    };

    size_t recordIndex = 0;
    const size_t records = sizeof(fnMap)/sizeof(fnMap[0]);
    for(; recordIndex<records; ++recordIndex)
    {
        if(VOLTAGE_DOMAIN_ID_ATTR == fnMap[recordIndex].domain)
        {
            break;
        }
    }

    assert(recordIndex < records,
        "Code bug! Called computeDynamicMemoryVoltage "
        "using unsupported voltage offset attribute type of 0x%08X.",
        VOLTAGE_DOMAIN_ID_ATTR);

    TARGETING::TargetHandleList l_mcbistTargetList;

    // Must pull ALL present mcbist (not just functional) for these
    // computations
    getAllChiplets(l_mcbistTargetList, TARGETING::TYPE_MCBIST, false);

    // sort the mcbist targets based on domain id
    std::sort(l_mcbistTargetList.begin(), l_mcbistTargetList.end(),
        _compareMcbistWrtVoltageDomain< VOLTAGE_DOMAIN_ID_ATTR >);

    std::vector<fapi2::Target<fapi2::TARGET_TYPE_MCS>> l_mcsFapiTargetsList;
    typename TARGETING::AttributeTraits< VOLTAGE_DOMAIN_ID_ATTR >::Type lastDomainId
        = 0;

    if(!l_mcbistTargetList.empty())
    {
        lastDomainId =
            (*l_mcbistTargetList.begin())->getAttr<VOLTAGE_DOMAIN_ID_ATTR>();
    }

    // O(n) algorithm to execute HWPs on groups of memory buffers.  As the
    // memory buffers are sorted in order of domain ID (several records in a row
    // might have same domain ID), walk down the list accumulating targets for
    // the HWP until the domain ID changes.  The first record is not considered
    // a change.  At the time the change is detected, run the HWP on the set of
    // accumulated targets, clear the list, and accumulate the target with a new
    // domain ID as the start of the new list.  When we hit end of list, we
    // might add this last target to a new accumulation, so we have to go back
    // through the loop one more time to process it (being careful not to do
    // unholy things to the iterator, etc.)

    // Prevent running the HWP on the first target.  Var is used to push us
    // through the loop after we exhausted all the targets
    bool last = l_mcbistTargetList.empty();
    for (TARGETING::TargetHandleList::const_iterator
            ppPresentMcbist = l_mcbistTargetList.begin();
         ((ppPresentMcbist != l_mcbistTargetList.end()) || (last == false));
         ++ppPresentMcbist)
    {
        // If no valid target to process, this is our last time through the loop
        last = (ppPresentMcbist == l_mcbistTargetList.end());

        typename TARGETING::AttributeTraits< VOLTAGE_DOMAIN_ID_ATTR >::Type
            currentDomainId = last ? lastDomainId :
                (*ppPresentMcbist)->getAttr<VOLTAGE_DOMAIN_ID_ATTR>();

        // Invoke the HWP if the domain ID in the sorted list change relative to
        // prior entry or this is our final time through the loop (and there is
        // a list entry to process)
        if(   ( (currentDomainId != lastDomainId)
               || (last))
           && (!l_mcsFapiTargetsList.empty()) )
        {
            // Skip HWP if this domain has all deconfigured mcs and the
            // domain rule specifies not running the HWP for that case
            bool invokeHwp = true;
            if(fnMap[recordIndex].callIfAllNonFunc == false)
            {
                invokeHwp = false;
                TARGETING::PredicateIsFunctional funcPred;
                std::vector<fapi2::Target<fapi2::TARGET_TYPE_MCS>>::const_iterator
                    pFapiTarget = l_mcsFapiTargetsList.begin();

                for(;pFapiTarget != l_mcsFapiTargetsList.end();++pFapiTarget)
                {
                    // Is there a functional mcs target?
                    if(funcPred(
                           reinterpret_cast<const TARGETING::Target*>(
                               pFapiTarget->get())))
                    {
                        invokeHwp = true;
                        break;
                    }
                }
            }

            if(invokeHwp)
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                    "INFO invoking %s on domain type 0x%08X, ID 0x%08X",
                    fnMap[recordIndex].fnName,
                    VOLTAGE_DOMAIN_ID_ATTR, lastDomainId);

                // HWP should set up ATTR_MSS_VOLT_<domain>_OFFSET_MILLIVOLTS
                // for MCBIST targets associated with the mcs list
                FAPI_INVOKE_HWP(
                    pError,
                    fnMap[recordIndex].fn,
                    l_mcsFapiTargetsList);

                if (pError)
                {
                    TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                        "ERROR 0x%.8X: %s",
                        pError->reasonCode(),fnMap[recordIndex].fnName);
                    break;
                }
                else
                {
                    TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                        "SUCCESS : %s",fnMap[recordIndex].fnName );
                }
            }
            else
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                    "INFO not invoking %s on domain type 0x%08X, ID 0x%08X "
                    "since domain has no functional mcbist.",
                    fnMap[recordIndex].fnName,
                    VOLTAGE_DOMAIN_ID_ATTR, lastDomainId);
            }

            l_mcsFapiTargetsList.clear();

            lastDomainId = currentDomainId;
        }

        // If not the last time through loop, there is a new target
        // to accumulate
        if(!last)
        {
            const TARGETING::Target* pPresentMcbist = *ppPresentMcbist;

            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                "=====  add to fapi::Target vector attr type=0x%08X, "
                "id=0x%08X, target HUID=0x%08X",
                VOLTAGE_DOMAIN_ID_ATTR,
                pPresentMcbist->getAttr<VOLTAGE_DOMAIN_ID_ATTR>(),
                TARGETING::get_huid(pPresentMcbist));

            fapi2::Target<fapi2::TARGET_TYPE_MCBIST> mcbistFapiTarget(
                (const_cast<TARGETING::Target*>(pPresentMcbist)) );

            // Get the mcs targets under this current mcbist target
            std::vector<fapi2::Target<fapi2::TARGET_TYPE_MCS>> l_childMCSs =
                mcbistFapiTarget.getChildren<fapi2::TARGET_TYPE_MCS>(fapi2::TARGET_STATE_PRESENT);

            // append this mcs target list to the overall mcs target list
            // for that particular domain
            l_mcsFapiTargetsList.insert( l_mcsFapiTargetsList.end(),
                                         l_childMCSs.begin(),
                                         l_childMCSs.end() );
        }
        // Otherwise need to bail, lest we increment the iterator again, which
        // is undefined
        else
        {
            break;
        }
    }

    if(pError)
    {
        break;
    }

  } while(0);

  TRACDCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
        "computeDynamicMemoryVoltage exit");

  return pError;
}


/**
 *  @brief
 *      This functions captures the user details of the given targets,
 *      if given any, and is added to the error log handle. Once the error
 *      log has the user data, for the given targets, the details of error
 *      log or added to the io_stepError.  The error log is then committed
 *      with the given component ID, leaving the error log handle NULL.
 *
 *      If no valid targets are given, everything is the same as above -
 *      io_stepError will contain the io_err info and the io_err will be
 *      committed - except the io_stepError will not contain any info
 *      collected from targets.
 *
 *  @param[in/out] io_err
 *      An error log handle, that contains the error log info. Can be NULL.  If
 *      NULL then this function becomes a no-op.  BEWARE: Upon exit of
 *      this function, the handle will be NULL.
 *
 *  @param[out] io_stepError
 *      The details from the error handle, io_err, which will be added to this.
 *
 *  @param[in] i_componentId
 *      The component ID that will be associated with the error handler, io_err,
 *      when the error is committed.
 *
 *  @param[in] i_target, i_targetList
 *      The list of target(s) that will be assimilated and have their knowledge
 *      added to the collective and when I say collective, I mean the error log
 *      handle, io_err ... resistance is futile. If not target is given, then
 *      target data will not be collected.
 */
void captureError(errlHndl_t               &io_err,
                  ISTEP_ERROR::IStepError  &io_stepError,
                  compId_t                  i_componentId,
                  const TARGETING::Target*  i_target = nullptr);

void captureError(errlHndl_t                        &io_err,
                  ISTEP_ERROR::IStepError           &io_stepError,
                  compId_t                           i_componentId,
                  const TARGETING::TargetHandleList &i_targetList);

#endif
OpenPOWER on IntegriCloud