summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/pm/runtime/rt_pm.C
blob: 3619a2315fa0f55ea31874f75351a72d8e6208e6 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/pm/runtime/rt_pm.C $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2017                        */
/* [+] 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 <stdint.h>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <errno.h>
#include <sys/misc.h>
#include <trace/interface.H>
#include <util/utillidmgr.H>

#include <pm/pm_common.H>
#include <isteps/pm/pm_common_ext.H>

#include <runtime/interface.h>
#include <runtime/rt_targeting.H>
#include <runtime/runtime_reasoncodes.H>

#include <initservice/isteps_trace.H>

//  targeting support
#include    <targeting/common/utilFilter.H>
#include    <targeting/common/targetservice.H>

#include <scom/scomif.H>
#include "handleSpecialWakeup.H"

using namespace TARGETING;
using namespace RUNTIME;

namespace ISTEPS_TRACE
{
    // declare storage for isteps_trace!
    trace_desc_t * g_trac_isteps_trace = nullptr;
    TRAC_INIT(&ISTEPS_TRACE::g_trac_isteps_trace, "ISTEPS_TRACE", 2*KILOBYTE);
}

namespace RTPM
{
    /**
     *  @brief Process error log created while running a PM Complex function
     *  @param[in]      i_err      Error handle
     *  @param[in/out]  io_rc      Return code
     */
    void pm_complex_error( errlHndl_t i_err,
                           int &io_rc )
    {
        errlCommit( i_err, RUNTIME_COMP_ID );

        if(io_rc == 0)
        {
            io_rc = -1;
        }

        return;
    }


    /**
     *  @brief Load OCC/HCODE images into mainstore
     *  @param[in]  i_chip              Processor Chip ID
     *  @param[in]  i_homer_addr        Homer physical address
     *  @param[in]  i_occ_common_addr   OCC common area physical address
     *  @param[in]  i_mode              PM load / reload
     *  @return                         Return Code
     */
    int load_pm_complex( uint64_t i_chip,
                         uint64_t i_homer_addr,
                         uint64_t i_occ_common_addr,
                         uint32_t i_mode )
    {
        Target* proc_target = nullptr;
        errlHndl_t l_err = nullptr;
        int rc = 0;

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "load_pm_complex: homer addr=%016llx. "
                   "occ common addr=%016lx. RtProcChip=%llx. mode=%d",
                   i_homer_addr,
                   i_occ_common_addr,
                   i_chip,
                   i_mode);

        do
        {
            // Utility to convert i_chip to Target
            l_err = RT_TARG::getHbTarget(i_chip, proc_target);
            if(l_err)
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"load_pm_complex: "
                           "convert Chip to Target failed!" );
                rc = EINVAL;
                break;
            }
            else
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           "load_pm_complex: "
                           "proc Target HUID=0x%08X",
                            get_huid(proc_target));
            }

            HBPM::loadPmMode l_hb_mode = HBPM::PM_UNKNOWN;
            switch (i_mode)
            {
                case HBRT_PM_LOAD:
                    l_hb_mode = HBPM::PM_LOAD;
                    break;
                case HBRT_PM_RELOAD:
                    l_hb_mode = HBPM::PM_RELOAD;
                    break;
                default:
                    /*@
                    * @errortype
                    * @moduleid     MOD_PM_RT_LOAD_PM_COMPLEX
                    * @reasoncode   RC_PM_RT_UNKNOWN_MODE
                    * @userdata1    HBRT PM Mode
                    * @userdata2    HUID
                    * @devdesc      PM load complex unknown mode
                    */
                    l_err = new ERRORLOG::ErrlEntry(
                                    ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                    MOD_PM_RT_LOAD_PM_COMPLEX,
                                    RC_PM_RT_UNKNOWN_MODE,
                                    i_mode,
                                    get_huid(proc_target));
                    break;
            }
            if( l_err )
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                          ERR_MRK"load_pm_complex: "
                          "Unknown Mode 0x%X for HUID=0x%08X",
                          i_mode, get_huid(proc_target));
                break;
            }

            l_err = HBPM::loadPMComplex(proc_target,
                                        i_homer_addr,
                                        i_occ_common_addr,
                                        l_hb_mode);
            if( l_err )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"load_pm_complex: "
                           "load PM complex failed!" );
                break;
            }

        } while(0);

        if (l_err)
        {
            pm_complex_error(l_err,
                             rc);
        }

        return rc;
    }


    /**
     *  @brief Start OCC/HCODE on the specified chip
     *  @param[in]  i_chip              Processor Chip ID
     *  @return                         Return Code
     */
    int start_pm_complex( uint64_t i_chip )
    {
        Target* proc_target = nullptr;
        errlHndl_t l_err = nullptr;
        int rc = 0;

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "start_pm_complex: RtProcChip %llx", i_chip);

        do
        {
            // Utility to convert i_chip to Target
            l_err = RT_TARG::getHbTarget(i_chip, proc_target);
            if( l_err )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"start_pm_complex: "
                           "convert Chip to Target failed!" );
                rc = EINVAL;
                break;
            }
            else
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           "start_pm_complex: "
                           "proc Target HUID=0x%08X",
                           get_huid(proc_target));
            }

            l_err = HBPM::startPMComplex(proc_target);
            if( l_err )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"start_pm_complex: "
                           "start PM complex failed!" );
                break;
            }

        } while(0);

        if ( l_err )
        {
            pm_complex_error(l_err,
                             rc);
        }

        return rc;
    }


    /**
     *  @brief Reset OCC/HCODE on the specified chip
     *  @param[in]  i_chip              Processor Chip ID
     *  @return                         Return Code
     */
    int reset_pm_complex( uint64_t i_chip )
    {
        Target* proc_target = nullptr;
        errlHndl_t l_err = nullptr;
        int rc = 0;

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "reset_pm_complex: RtProcChip %llx", i_chip);

        do
        {
            // Utility to convert i_chip to Target
            l_err = RT_TARG::getHbTarget(i_chip, proc_target);
            if( l_err )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"reset_pm_complex: "
                           "convert Chip to Target failed!" );
                rc = EINVAL;
                break;
            }
            else
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           "reset_pm_complex: "
                           "proc Target HUID=0x%08X",
                           get_huid(proc_target));
            }

            l_err = HBPM::resetPMComplex(proc_target);
            if( l_err )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"reset_pm_complex: "
                           "reset PM complex failed!" );
                break;
            }
        } while(0);

        if ( l_err )
        {
            pm_complex_error(l_err,
                             rc);
        }

        return rc;
    }


    /**
    * @brief HCODE update operation
    */
    errlHndl_t hcode_update( uint32_t i_section,
                             uint32_t i_operation,
                             Target*  i_target,
                             uint64_t i_rel_scom_addr,
                             uint64_t i_scom_data )
    {
        errlHndl_t l_err = NULL;
        int rc = 0;

        do {
            if( g_hostInterfaces == NULL ||
                g_hostInterfaces->hcode_scom_update == NULL )
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                          ERR_MRK"hcode_update: "
                          "Hypervisor hcode_scom_update interface not linked");
                /*@
                * @errortype
                * @moduleid         MOD_PM_RT_HCODE_UPDATE
                * @reasoncode       RC_PM_RT_INTERFACE_ERR
                * @userdata1[0:31]  Target HUID
                * @userdata1[32:63] SCOM restore section
                * @userdata2        SCOM address
                * @devdesc      HCODE scom update runtime interface not linked.
                */
                l_err= new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                               MOD_PM_RT_HCODE_UPDATE,
                                               RC_PM_RT_INTERFACE_ERR,
                                               TWO_UINT32_TO_UINT64(
                                                 TARGETING::get_huid(i_target),
                                                 i_section),
                                               i_rel_scom_addr);
                break;
            }

            // Enable special wakeup
            l_err = handleSpecialWakeup(i_target,true);
            if(l_err)
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"hcode_update: "
                           "handleSpecialWakeup enable ERROR" );
                break;
            }

            // Get the Proc Chip Id
            const TARGETING::Target * l_pChipTarget =
                getParentChip(const_cast<TARGETING::Target *>(i_target));
            RT_TARG::rtChipId_t l_chipId = 0;

            l_err = RT_TARG::getRtTarget(l_pChipTarget, l_chipId);
            if(l_err)
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"hcode_update: getRtTarget ERROR" );
                break;
            }

            // Translate the scom address
            uint64_t l_scomAddr = i_rel_scom_addr;
            bool l_needsWakeup = false;     // Ignored - SW already enabled

            l_err = SCOM::scomTranslate(i_target,
                                        l_scomAddr,
                                        l_needsWakeup);
            if(l_err)
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"hcode_update: scomTranslate ERROR" );
                break;
            }

            rc = g_hostInterfaces->hcode_scom_update(l_chipId,
                                                     i_section,
                                                     i_operation,
                                                     l_scomAddr,
                                                     i_scom_data);
            if(rc)
            {
                TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                          ERR_MRK"hcode_update: "
                          "HCODE scom update failed. "
                          "rc 0x%X target 0x%llX chipId 0x%llX section 0x%X "
                          "operation 0x%X scomAddr 0x%llX scomData 0x%llX",
                          rc, get_huid(i_target), l_chipId, i_section,
                          i_operation, l_scomAddr, i_scom_data);

                // convert rc to error log
                /*@
                * @errortype
                * @moduleid     MOD_PM_RT_HCODE_UPDATE
                * @reasoncode   RC_PM_RT_HCODE_UPDATE_ERR
                * @userdata1    Hypervisor return code
                * @userdata2    SCOM address
                * @devdesc      HCODE SCOM update error
                */
                l_err=new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                              MOD_PM_RT_HCODE_UPDATE,
                                              RC_PM_RT_HCODE_UPDATE_ERR,
                                              rc,
                                              l_scomAddr);
                break;
            }

            // Disable special wakeup
            l_err = handleSpecialWakeup(i_target,false);
            if(l_err)
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           ERR_MRK"hcode_update: "
                           "handleSpecialWakeup disable ERROR" );
                break;
            }

        } while (0);

        return l_err;
    }


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

    struct registerPm
    {
        registerPm()
        {
            runtimeInterfaces_t * rt_intf = getRuntimeInterfaces();
            rt_intf->load_pm_complex = &load_pm_complex;
            rt_intf->start_pm_complex = &start_pm_complex;
            rt_intf->reset_pm_complex = &reset_pm_complex;

            // If we already loaded OCC during the IPL we need to fix up
            //  the virtual address because we're now not using virtual
            //  memory

            TargetHandleList procChips;
            getAllChips(procChips, TYPE_PROC, true);
            for (TargetHandleList::iterator itr = procChips.begin();
                 itr != procChips.end();
                 ++itr)
            {
                (*itr)->setAttr<ATTR_HOMER_VIRT_ADDR>(0);
            }
        }
    };

    registerPm g_registerPm;
};
OpenPOWER on IntegriCloud