summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/nest/nestHwpHelperFuncs.C
blob: 921fd3d357aa8cf2bbc00bed9331ae7ca94984d3 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/nest/nestHwpHelperFuncs.C $                    */
/*                                                                        */
/* 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                                                     */

/******************************************************************************/
// Includes
/******************************************************************************/
#include "nestHwpHelperFuncs.H"

//  STD support
#include <map>

//  Tracing support
#include <trace/interface.H>           // TRACFCOMP
#include <initservice/isteps_trace.H>  // g_trac_isteps_trace

//  Targeting support
#include <fapi2_target.H>              // fapi2::Target
#include <target.H>                    // TARGETING::Target

//  Error handling support
#include <istepHelperFuncs.H>          // captureError
#include <errl/errlentry.H>            // errlHndl_t

//  HWP call support
#include <fapi2/plat_hwp_invoker.H>    // FAPI_INVOKE_HWP
#include <p9_chiplet_enable_ridi.H>
#include <p9_chiplet_scominit.H>
#include <p9_psi_scominit.H>
#include <p9_npu_scominit.H>
#include <p9_io_obus_scominit.H>
#include <p9_xbus_enable_ridi.H>
#include <p9_fbc_eff_config_links.H>
#include <p9_sys_chiplet_scominit.H>
#include <p9_chiplet_fabric_scominit.H>
#include <p9_io_obus_firmask_save_restore.H>
#include <p9_io_obus_image_build.H>
#include <p9_io_xbus_image_build.H>

namespace ISTEP
{
using namespace ISTEP_ERROR;
using namespace ISTEPS_TRACE;

// Size of string that contains "ERROR" or "SUCCESS" message
constexpr const int l_errorSuccesStrSize = 40;

 /**
 *
 *  hwpCallToString
 */
const char * hwpCallToString( HWP_CALL_TYPE i_hwpCall )
{
    const static std::map<HWP_CALL_TYPE, const char*> hwpCallToStringMap =
    {
        { P9_CHIPLET_ENABLE_RIDI, "p9_chiplet_enable_ridi"},
        { P9_CHIPLET_FABRIC_SCOMINIT, "p9_chiplet_fabric_scominit" },
        { P9_CHIPLET_SCOMINIT, "p9_chiplet_scominit" },
        { P9_FBC_EFF_CONFIG_LINKS_T_F, "p9_fbc_eff_config_links" },
        { P9_FBC_EFF_CONFIG_LINKS_F_T, "p9_fbc_eff_config_links" },
        { P9_IO_OBUS_SCOMINIT, "p9_io_obus_scominit" },
        { P9_NPU_SCOMINIT, "p9_npu_scominit" },
        { P9_PSI_SCOMINIT, "p9_psi_scominit" },
        { P9_SYS_CHIPLET_SCOMINIT, "p9_sys_chiplet_scominit" },
        { P9_XBUS_ENABLE_RIDI, "p9_xbus_enable_ridi" },
        { P9_OBUS_FIRMASK_SAVE_RESTORE, "p9_io_obus_firmask_save_restore" },
        { P9_IO_OBUS_IMAGE_BUILD, "p9_io_obus_image_build" },
        { P9_IO_XBUS_IMAGE_BUILD, "p9_io_xbus_image_build" },
    };

    if (hwpCallToStringMap.count(i_hwpCall) > 0)
    {
        return hwpCallToStringMap.at(i_hwpCall);
    }
    else
    {
        return "";
    }
}

/**
 *  @brief Load HCODE image and return a pointer to it, or NULL
 *  @param[out] -   address of the HCODE image
 *  @return      NULL if success, errorlog if failure
 */
errlHndl_t loadHcodeImage(char *& o_rHcodeAddr)
{
    errlHndl_t l_err = NULL;
    PNOR::SectionInfo_t l_info;

    do
    {

#ifdef CONFIG_SECUREBOOT
        l_err = loadSecureSection(PNOR::HCODE);
        if (l_err)
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       ERR_MRK"loadHcodeImage() - Error from "
                       "loadSecureSection(PNOR::HCODE)");

            //No need to commit error here, it gets handled later
            //just break out to escape this function
            break;
        }
#endif

        // Get HCODE/WINK PNOR section info from PNOR RP
        l_err = PNOR::getSectionInfo( PNOR::HCODE, l_info );
        if( l_err )
        {
            //No need to commit error here, it gets handled later
            //just break out to escape this function
            break;
        }

        o_rHcodeAddr = reinterpret_cast<char*>(l_info.vaddr);

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "HCODE addr = 0x%p ",
                   o_rHcodeAddr);

    } while ( 0 );

    return  l_err;
}

/**
 *  fapiHWPCallWrapper
 */
void fapiHWPCallWrapper(HWP_CALL_TYPE    i_hwpCall,
                        IStepError      &o_stepError,
                        compId_t         i_componentId,
                        TARGETING::TYPE  i_targetType)
{
    // Cache the HWP call in string form
    const char* l_hwpCallStr = hwpCallToString(i_hwpCall);

    TRACFCOMP(g_trac_isteps_trace,
              ENTER_MRK"fapiHWPCallWrapper (%s) entry", l_hwpCallStr);

    // An error handler
    errlHndl_t l_err(nullptr);
    char* l_pHcodeImage = NULL;
    TARGETING::TargetHandleList l_targetList;

    do {

        // Load OBUS/XBUS image
        if ( (P9_IO_OBUS_IMAGE_BUILD == i_hwpCall) ||
             (P9_IO_XBUS_IMAGE_BUILD == i_hwpCall) )
        {
            l_err = loadHcodeImage(l_pHcodeImage);
            if (l_err)
            {
                  TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                            "call_host_load_io_ppe ERROR : "
                            "Unable to load HCODE image errorlog PLID=0x%x",
                            l_err->plid());
                  // Capture error and exit
                  captureError(l_err,
                               o_stepError,
                               i_componentId,
                               NULL);
                  break;
             }
        }

        // Get a list of all the processors in the system
        if (TARGETING::TYPE_PROC == i_targetType)
        {
            getAllChips(l_targetList, i_targetType);
        }
        else if (TARGETING::TYPE_OBUS == i_targetType)
        {
            getAllChiplets(l_targetList, i_targetType);
        }
        else
        {
            assert(0, "ERROR: Invalid target type %d", i_targetType);
        }

        if (l_targetList.empty())
        {
            TRACFCOMP(g_trac_isteps_trace, "Target list empty, no targets "
                      "found. HWP call %s will not be called", l_hwpCallStr);
        }

        // Loop through all processors including master
        for (const auto & l_target: l_targetList)
        {
            // A string to contain an error or success message, defaulted to success
            char l_errorSuccesStr[l_errorSuccesStrSize] = "SUCCESS";

            TRACFCOMP(g_trac_isteps_trace,
                      "Running %s HWP on target HUID %.8X",
                      l_hwpCallStr,
                      TARGETING::get_huid(l_target));

            // Call HWP calls for chips (target type: TYPE_PROC)
            if (TARGETING::TYPE_PROC == i_targetType)
            {
                // Get a FAPI2 target of type PROC
                const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>l_fapi2Target(l_target);

                if (P9_XBUS_ENABLE_RIDI == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_xbus_enable_ridi,
                                    l_fapi2Target);
                }
                else if (P9_CHIPLET_ENABLE_RIDI == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_chiplet_enable_ridi,
                                    l_fapi2Target);
                }
                else if (P9_CHIPLET_SCOMINIT == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_chiplet_scominit,
                                    l_fapi2Target);
                }
                else if (P9_PSI_SCOMINIT == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_psi_scominit,
                                    l_fapi2Target);
                }
                else if (P9_NPU_SCOMINIT == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_npu_scominit,
                                    l_fapi2Target);
                }
                else if (P9_FBC_EFF_CONFIG_LINKS_F_T == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_fbc_eff_config_links,
                                    l_fapi2Target,
                                    SMP_ACTIVATE_PHASE2, // P9 build SMP operation
                                    false,  // process electrical
                                    true);  // process optical
                }
                else if (P9_FBC_EFF_CONFIG_LINKS_T_F == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_fbc_eff_config_links,
                                    l_fapi2Target,
                                    SMP_ACTIVATE_PHASE1, // P9 build SMP operation
                                    true,    // process electrical
                                    false);  // process optical
                }
                else if (P9_SYS_CHIPLET_SCOMINIT == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_sys_chiplet_scominit,
                                    l_fapi2Target);
                }
                else if (P9_CHIPLET_FABRIC_SCOMINIT == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_chiplet_fabric_scominit,
                                    l_fapi2Target);
                }
                else if (P9_OBUS_FIRMASK_SAVE_RESTORE == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_io_obus_firmask_save_restore,
                                    l_fapi2Target, p9iofirmasksaverestore::SAVE);
                }
                else if (P9_IO_XBUS_IMAGE_BUILD == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_io_xbus_image_build,
                                    l_fapi2Target, reinterpret_cast<void*>(l_pHcodeImage));
                }
                else
                {
                    TRACFCOMP(g_trac_isteps_trace, "ERROR: Invalid/Uknown HWP call");
                    break;
                }
            }  // end if (TARGETING::TYPE_PROC == i_targetType)

            // Call HWP calls for chiplets (target type: TYPE_OBUS)
            else if (TARGETING::TYPE_OBUS == i_targetType)
            {
                // Get a FAPI2 target of type OBUS
                const fapi2::Target<fapi2::TARGET_TYPE_OBUS>l_fapi2Target(l_target);

                if (P9_IO_OBUS_SCOMINIT == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_io_obus_scominit,
                                    l_fapi2Target);
                }
                else if (P9_IO_OBUS_IMAGE_BUILD == i_hwpCall)
                {
                    FAPI_INVOKE_HWP(l_err,
                                    p9_io_obus_image_build,
                                    l_fapi2Target,
                                    reinterpret_cast<void*>(l_pHcodeImage));
                }
                else
                {
                    TRACFCOMP(g_trac_isteps_trace,"ERROR: Invalid/Uknown HWP call");
                    break;
                }

            }  // end else if (TARGETING::TYPE_OBUS == i_targetType)
            else
            {
               assert(0, "ERROR: Invalid target type %d", i_targetType);
            }


            // If an error ocurred with HWP call, setup error message
            if (l_err)
            {
                snprintf(l_errorSuccesStr, l_errorSuccesStrSize,
                         "ERROR 0x%.8X", l_err->plid());
            }

            TRACFCOMP(g_trac_isteps_trace,
                      "%s: %s HWP returned %s with target HUID 0x%.8X",
                      l_errorSuccesStr,
                      l_hwpCallStr,
                      (l_err ? "an error" : "success"),
                      TARGETING::get_huid(l_target));

            if (l_err)
            {
                // Capture error and continue
                captureError(l_err,
                             o_stepError,
                             i_componentId,
                             l_target);
            }

        } // end for (const auto & l_target: l_targetList)

    } while (0);

#ifdef CONFIG_SECUREBOOT
    if ( (P9_IO_OBUS_IMAGE_BUILD == i_hwpCall) ||
           (P9_IO_XBUS_IMAGE_BUILD == i_hwpCall) )
    {
        l_err = unloadSecureSection(PNOR::HCODE);
        if (l_err)
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       ERR_MRK"host_load_io_ppe() - Error from "
                       "unloadSecureSection(PNOR::HCODE)");
            captureError(l_err,
                         o_stepError,
                         i_componentId,
                         NULL);
        }
    }
#endif

    TRACFCOMP(g_trac_isteps_trace,
              EXIT_MRK"fapiHWPCallWrapper (%s) exit", l_hwpCallStr);
    return;
}

/**
 *  fapiHWPCallWrapperHandler
 */
bool fapiHWPCallWrapperHandler(HWP_CALL_TYPE    i_hwpCall,
                               IStepError      &o_stepError,
                               compId_t         i_componentId,
                               TARGETING::TYPE  i_targetType)
{
    bool l_retSuccess = true;

    fapiHWPCallWrapper(i_hwpCall, o_stepError, i_componentId, i_targetType);

    if (!o_stepError.isNull())
    {
        TRACFCOMP(g_trac_isteps_trace,
                  "ERROR from %s", hwpCallToString(i_hwpCall));

        l_retSuccess = false;
    }

    return l_retSuccess;
}

};   // end namespace ISTEP
OpenPOWER on IntegriCloud