summaryrefslogtreecommitdiffstats
path: root/src/sbefw/app/power/sbecmdcntlinst.C
blob: f5113cfc45846ffbb56e413ef4361cfd64f6b78a (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/sbefw/app/power/sbecmdcntlinst.C $                        */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] 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                                                     */
/*
 * @file: ppe/sbe/sbefw/sbecmdcntlinst.C
 *
 * @brief This file contains the SBE Control Instruction chipOps
 *
 */

#include "sbecmdcntlinst.H"
#include "sbecmdiplcontrol.H"
#include "sbefifo.H"
#include "sbe_sp_intf.H"
#include "sbetrace.H"
#include "sbeFifoMsgUtils.H"

#include "fapi2.H"
#include "p9_thread_control.H"
#include "p9_query_core_access_state.H"


using namespace fapi2;

//Utility function to mask special attention
extern ReturnCode maskSpecialAttn( const Target<TARGET_TYPE_CORE>& i_target);

// TODO via RTC 152424
// Currently all proecdures in core directory are in seeprom.
// So we have to use function pointer to force a long call.
#ifdef SEEPROM_IMAGE
p9_thread_control_FP_t threadCntlhwp = &p9_thread_control;
#endif

/* @brief Map User Thread Command to Hwp ThreadCommands Enum */
ThreadCommands getThreadCommand(const sbeCntlInstRegMsgHdr_t & i_req)
{
    ThreadCommands l_cmd = PTC_CMD_START;
    switch(i_req.threadOps)
    {
        case THREAD_START_INS:  l_cmd = PTC_CMD_START;  break;
        case THREAD_STOP_INS:   l_cmd = PTC_CMD_STOP;   break;
        case THREAD_STEP_INS:   l_cmd = PTC_CMD_STEP;   break;
        case THREAD_SRESET_INS: l_cmd = PTC_CMD_SRESET; break;
    }
    return l_cmd;
}

/* @brief Map User Mode Command to Hwp Warn Check flag */
inline bool getWarnCheckFlag(const sbeCntlInstRegMsgHdr_t & i_req)
{
    bool l_warnCheck = false;

    // EXIT_ON_FIRST_ERROR and IGNORE_HW_ERRORS are mutually exclusive
    if( EXIT_ON_FIRST_ERROR != (i_req.mode & 0x1) )
    {
        l_warnCheck = true;
    }
    return l_warnCheck;
}

static const uint64_t SPWKUP_ASSERT   = 0x8000000000000000ull;
static const uint64_t SPWKUP_DEASSERT = 0x0000000000000000ull;
static const uint64_t GPMMR_SPWKUP_DONE = 0x8000000000000000ull;
static const uint32_t SPECIAL_WAKE_UP_POLL_INTERVAL_NS = 1000000;   //1ms
static const uint32_t SPECIAL_WAKE_UP_POLL_INTERVAL_SIMICS = 1000000;
static const uint32_t SPECIAL_WAKEUP_TIMEOUT_COUNT = 100; // 100 * 1ms

static uint32_t specialWakeUpCoreAssert(
        const Target<TARGET_TYPE_CORE>& i_target, ReturnCode &o_fapiRc)
{
    #define SBE_FUNC "specialWakeUpCoreAssert"
    uint32_t rc = SBE_SEC_OPERATION_SUCCESSFUL;
    o_fapiRc = FAPI2_RC_SUCCESS;

    do
    {
        uint64_t data = 0;
        uint8_t pollCount = 0;

        data = SPWKUP_ASSERT; // assert
        o_fapiRc = putscom_abs_wrap(&i_target, C_PPM_SPWKUP_FSP, data);
        if(o_fapiRc != FAPI2_RC_SUCCESS)
        {
            SBE_ERROR(SBE_FUNC " special wakeup putscom failed");
            rc = SBE_SEC_SPECIAL_WAKEUP_SCOM_FAILURE;
            break;
        }

        do
        {
            delay(SPECIAL_WAKE_UP_POLL_INTERVAL_NS, SPECIAL_WAKE_UP_POLL_INTERVAL_SIMICS);
            o_fapiRc = getscom_abs_wrap(&i_target, C_PPM_GPMMR_SCOM, &data);
            if(o_fapiRc != FAPI2_RC_SUCCESS)
            {
                rc = SBE_SEC_SPECIAL_WAKEUP_SCOM_FAILURE;
                break;
            }
        }
        while(!(data & GPMMR_SPWKUP_DONE) &&
                (++pollCount < SPECIAL_WAKEUP_TIMEOUT_COUNT));

        if(!(data & GPMMR_SPWKUP_DONE))
        {
            if(rc == SBE_SEC_OPERATION_SUCCESSFUL) {
                SBE_ERROR(SBE_FUNC " special wakeup done timeout");
                rc = SBE_SEC_SPECIAL_WAKEUP_TIMEOUT;
            }
            break;
        }
    } while(false);

    return rc;
    #undef SBE_FUNC
}
static uint32_t specialWakeUpCoreDeAssert(
        const Target<TARGET_TYPE_CORE>& i_target, ReturnCode &o_fapiRc)
{
    #define SBE_FUNC "specialWakeUpCoreDeAssert"
    uint32_t rc = SBE_SEC_OPERATION_SUCCESSFUL;
    o_fapiRc = FAPI2_RC_SUCCESS;

    do
    {
        uint64_t data = SPWKUP_DEASSERT; // deassert
        o_fapiRc = putscom_abs_wrap(&i_target, C_PPM_SPWKUP_FSP, data);
        if(o_fapiRc != FAPI2_RC_SUCCESS)
        {
            SBE_ERROR(SBE_FUNC " special wakeup putscom failed");
            rc = SBE_SEC_SPECIAL_WAKEUP_SCOM_FAILURE;
            break;
        }

        // This puts an inherent delay in the propagation of the reset transition.
        o_fapiRc = getscom_abs_wrap(&i_target, C_PPM_SPWKUP_FSP, &data);
        if(o_fapiRc != FAPI2_RC_SUCCESS)
        {
            SBE_ERROR(SBE_FUNC " special wakeup getscom failed");
            rc = SBE_SEC_SPECIAL_WAKEUP_SCOM_FAILURE;
            break;
        }
    } while(false);

    return rc;
    #undef SBE_FUNC
}

///////////////////////////////////////////////////////////////////////
// @brief stopAllCoreInstructions  Stop all core instructions function
//
// @return  RC from the underlying FIFO utility
///////////////////////////////////////////////////////////////////////
ReturnCode stopAllCoreInstructions( )
{
    #define SBE_FUNC "stopAllCoreInstructions"
    SBE_ENTER(SBE_FUNC);
    ReturnCode l_fapiRc = FAPI2_RC_SUCCESS;
    Target<TARGET_TYPE_PROC_CHIP > l_procTgt = plat_getChipTarget();
    for (auto l_coreTgt : l_procTgt.getChildren<fapi2::TARGET_TYPE_CORE>())
    {
        bool l_isCoreScomEnabled = false;
        if(SBE::isSimicsRunning())
        {
            l_isCoreScomEnabled = true;
        }
        else
        {
            bool l_isScanEnable = false;
            SBE_EXEC_HWP(l_fapiRc, p9_query_core_access_state, l_coreTgt,
                    l_isCoreScomEnabled, l_isScanEnable)
            if(l_fapiRc != FAPI2_RC_SUCCESS)
            {
                SBE_ERROR(SBE_FUNC " p9_query_core_access_state failed, "
                        "RC=[0x%08X]", l_fapiRc);
                break;
            }
        }
        if(l_isCoreScomEnabled) //true
        {
            uint8_t l_thread = SMT4_THREAD0;
            fapi2::buffer<uint64_t> l_data64;
            uint64_t l_state;
            bool l_warnCheck = true;
            do
            {
                // Call instruction control stop
                // TODO RTC 164425 - Can we pass in 1111 i.e. all threads at the
                // same time instead of individual threads
                SBE_EXEC_HWP(l_fapiRc,
                             threadCntlhwp,
                             l_coreTgt,
                             (SINGLE_THREAD_BIT_MASK >> l_thread),
                             PTC_CMD_STOP, l_warnCheck,l_data64, l_state)
                if(l_fapiRc != FAPI2_RC_SUCCESS)
                {
                    SBE_ERROR(SBE_FUNC "p9_thread_control stop Failed for "
                        "Core Thread  RC[0x%08X]", l_fapiRc);
                    break;
                }
            }while(++l_thread < SMT4_THREAD_MAX);

            l_fapiRc = maskSpecialAttn(l_coreTgt);
            if( l_fapiRc != FAPI2_RC_SUCCESS)
            {
                SBE_ERROR(SBE_FUNC "maskSpecialAttn failed");
                break;
            }
        }
    }
    SBE_EXIT(SBE_FUNC);
    return l_fapiRc;
    #undef SBE_FUNC
}

///////////////////////////////////////////////////////////////////////
// @brief sbeCntlInst Sbe control instructions function
//
// @return  RC from the underlying FIFO utility
///////////////////////////////////////////////////////////////////////
uint32_t sbeCntlInst(uint8_t *i_pArg)
{
    #define SBE_FUNC " sbeCntlInst "
    SBE_ENTER(SBE_FUNC);

    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
    ReturnCode l_fapiRc = FAPI2_RC_SUCCESS;
    sbeRespGenHdr_t l_respHdr;
    l_respHdr.init();
    sbeResponseFfdc_t l_ffdc;

    // Create the req struct for Control Instructions Chip-op
    sbeCntlInstRegMsgHdr_t l_req = {0};

    do
    {
        // Get the Req Struct Data sbeCntlInstRegMsgHdr_t from upstream Fifo
        uint32_t l_len2dequeue  = sizeof(l_req) / sizeof(uint32_t);
        l_rc = sbeUpFifoDeq_mult (l_len2dequeue, (uint32_t *)&l_req, true);

        // If FIFO failure
        if ( SBE_SEC_OPERATION_SUCCESSFUL != l_rc )
        {
            // Let command processor routine to handle the RC.
            break;
        }

        SBE_INFO("mode[0x%04X] coreChipletId[0x%08X] threadNum[0x%04X] "
            "threadOps[0x%04X] ", l_req.mode, l_req.coreChipletId,
            l_req.threadNum, l_req.threadOps);

        // Validate Input Args
        if( false == l_req.validateInputArgs())
        {
            SBE_ERROR(SBE_FUNC "ValidateAndMapInputArgs failed");
            l_respHdr.setStatus( SBE_PRI_INVALID_DATA,
                                 SBE_SEC_GENERIC_FAILURE_IN_EXECUTION );
            break;
        }

        // Fetch HWP mapped values
        bool l_warnCheck = getWarnCheckFlag(l_req);
        ThreadCommands l_cmd = getThreadCommand(l_req);

        // Default assignment not required since it is assigned below
        uint8_t l_core, l_coreCntMax;
        uint8_t l_threadCnt, l_threadCntMax;

        l_req.processInputDataToIterate(l_core, l_coreCntMax,
                                        l_threadCnt, l_threadCntMax);
        fapi2::buffer<uint64_t> l_data64;
        uint64_t l_state;
        do
        {
            fapi2::Target<fapi2::TARGET_TYPE_CORE>
                l_coreTgt(plat_getTargetHandleByChipletNumber
                        <fapi2::TARGET_TYPE_CORE>(l_core));
            if(!l_coreTgt.isFunctional())
            {
                continue;
            }

            bool deassertRequired = false;
            if(l_req.isSpecialWakeUpRequired())
            {
                l_rc = specialWakeUpCoreAssert(l_coreTgt, l_fapiRc);
                if(l_rc != SBE_SEC_OPERATION_SUCCESSFUL)
                {
                    SBE_ERROR(SBE_FUNC "Special Wakeup Assert failed for core[0x%2x]",
                                                 (uint8_t)l_req.coreChipletId);
                    l_respHdr.setStatus(SBE_PRI_GENERIC_EXECUTION_FAILURE,
                                        l_rc);
                    l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
                    l_ffdc.setRc(l_fapiRc);
                    if(!(IGNORE_HW_ERRORS & l_req.mode))
                    {
                        break;
                    }
                    SBE_INFO(SBE_FUNC "Continuing in case of HW Errors"
                        " As user has passed to ignore errors.");
                }
                else
                {
                    SBE_INFO(SBE_FUNC "Special Wakeup assert succeeded for core[0x%2x]",
                                                     (uint8_t)l_req.coreChipletId);
                    deassertRequired = true;
                }
            }

            uint8_t l_thread = l_threadCnt;
            do
            {
                // Call the Procedure
                SBE_EXEC_HWP(l_fapiRc,
                             threadCntlhwp,
                             l_coreTgt,
                              (SINGLE_THREAD_BIT_MASK >> l_thread),
                              l_cmd, l_warnCheck,
                              l_data64, l_state)

                if(l_fapiRc != FAPI2_RC_SUCCESS)
                {
                    SBE_ERROR(SBE_FUNC "Failed for Core[%d] Thread [%d] "
                        "Cmd[%d] Mode[%d]", l_core, l_thread, l_req.threadOps,
                        l_req.mode);
                    if(IGNORE_HW_ERRORS & l_req.mode)
                    {
                        // No need to delete the l_fapiRc handle,it will get
                        // over-written
                        SBE_INFO(SBE_FUNC "Continuing in case of HW Errors"
                            " As user has passed to ignore errors.");
                        continue;
                    }
                    else
                    {
                        SBE_ERROR(SBE_FUNC "Breaking out, since User has "
                            "Selected the mode to exit on first error.");
                        l_respHdr.setStatus(SBE_PRI_GENERIC_EXECUTION_FAILURE,
                                         SBE_SEC_GENERIC_FAILURE_IN_EXECUTION);
                        l_ffdc.setRc(l_fapiRc);
                        break;
                    }
                }
            }while(++l_thread < l_threadCntMax);

            if(deassertRequired)
            {
                ReturnCode fapiRc = FAPI2_RC_SUCCESS;
                l_rc = specialWakeUpCoreDeAssert(l_coreTgt, fapiRc);
                if(l_rc != SBE_SEC_OPERATION_SUCCESSFUL)
                {
                    SBE_ERROR(SBE_FUNC "Special Wakeup de-asssert failed for core[0x%2x]",
                                                 (uint8_t)l_req.coreChipletId);
                    l_respHdr.setStatus(SBE_PRI_GENERIC_EXECUTION_FAILURE,
                                        l_rc);
                    l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
                    l_ffdc.setRc(fapiRc);
                    if(!(IGNORE_HW_ERRORS & l_req.mode))
                    {
                        break;
                    }
                    SBE_INFO(SBE_FUNC "Continuing in case of HW Errors"
                        " As user has passed to ignore errors.");
                }
                else
                {
                    SBE_INFO(SBE_FUNC "Special Wakeup de-assert succeeded for core[0x%2x]",
                                                     (uint8_t)l_req.coreChipletId);
                }
            }

            if ((l_fapiRc) && !(IGNORE_HW_ERRORS & l_req.mode))
            {
                // If FapiRc from the inner loop (thread loop), just break here
                break; // From core while loop
            }
        }while(++l_core < l_coreCntMax);

    }while(0);

    // Create the Response to caller
    do
    {
        // If there was a FIFO error, will skip sending the response,
        // instead give the control back to the command processor thread
        if ( SBE_SEC_OPERATION_SUCCESSFUL != l_rc)
        {
            break;
        }

        l_rc = sbeDsSendRespHdr(l_respHdr, &l_ffdc);
    }while(0);

    SBE_EXIT(SBE_FUNC);
    return l_rc;
    #undef SBE_FUNC
}

OpenPOWER on IntegriCloud