summaryrefslogtreecommitdiffstats
path: root/src/sbefw/sbecmdmpipl.C
blob: ad519f68c0604a76555ec3d79c658f9a30cc7fb8 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/sbefw/sbecmdmpipl.C $                                     */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016                             */
/* [+] 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/src/sbefw/sbecmdmpipl.C
 *
 * @brief This file contains the SBE MPIPL chipOps
 *
 */

#include "sbefifo.H"
#include "sbeSpMsg.H"
#include "sbe_sp_intf.H"
#include "sbetrace.H"
#include "sbeFifoMsgUtils.H"
#include "sbecmdmpipl.H"
#include "sberegaccess.H"
#include "sbefapiutil.H"
#include "sbecmdiplcontrol.H"

#include "p9_hcd_core_stopclocks.H"
#include "p9_hcd_cache_stopclocks.H"
#include "fapi2.H"

using namespace fapi2;

#ifdef SEEPROM_IMAGE
    // Using function pointer to force long call.
p9_hcd_cache_stopclocks_FP_t p9_hcd_cache_stopclocks_hwp = &p9_hcd_cache_stopclocks;
p9_hcd_core_stopclocks_FP_t p9_hcd_core_stopclocks_hwp = &p9_hcd_core_stopclocks;
#endif

///////////////////////////////////////////////////////////////////////
// @brief sbeEnterMpipl Sbe enter MPIPL function
//
// @return  RC from the underlying FIFO utility
///////////////////////////////////////////////////////////////////////
uint32_t sbeEnterMpipl(uint8_t *i_pArg)
{
    #define SBE_FUNC " sbeEnterMpipl "
    SBE_ENTER(SBE_FUNC);
    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
    uint32_t l_fapiRc = FAPI2_RC_SUCCESS;
    uint32_t len = 0;
    sbeRespGenHdr_t l_respHdr;
    l_respHdr.init();
    sbeResponseFfdc_t l_ffdc;

    do
    {
        // Dequeue the EOT entry as no more data is expected.
        l_rc = sbeUpFifoDeq_mult (len, NULL);
        CHECK_SBE_RC_AND_BREAK_IF_NOT_SUCCESS(l_rc);

        uint32_t l_minor = 1;
        do
        {
            l_fapiRc = sbeExecuteIstep(SBE_ISTEP_MPIPL_START, l_minor);
            if(l_fapiRc != FAPI2_RC_SUCCESS)
            {
                SBE_ERROR(SBE_FUNC "Failed in Mpipl Start in ChipOp Mode "
                    "Minor: %d", l_minor);
                l_respHdr.setStatus( SBE_PRI_GENERIC_EXECUTION_FAILURE,
                                 SBE_SEC_GENERIC_FAILURE_IN_EXECUTION);
                l_ffdc.setRc(l_fapiRc);
                break;
            }
            ++l_minor;
        }while(l_minor<=MPIPL_START_MAX_SUBSTEPS);

    }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
        CHECK_SBE_RC_AND_BREAK_IF_NOT_SUCCESS(l_rc);
        l_rc = sbeDsSendRespHdr( l_respHdr, &l_ffdc);
    }while(0);

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

// TODO - RTC 133367
///////////////////////////////////////////////////////////////////////
// @brief sbeContinueMpipl Sbe Continue MPIPL function
//
// @return  RC from the underlying FIFO utility
///////////////////////////////////////////////////////////////////////
uint32_t sbeContinueMpipl(uint8_t *i_pArg)
{
    #define SBE_FUNC " sbeContinueMpipl "
    SBE_ENTER(SBE_FUNC);
    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
    uint32_t len = 0;
    ReturnCode l_fapiRc = FAPI2_RC_SUCCESS;
    sbeResponseFfdc_t l_ffdc;
    sbeRespGenHdr_t l_respHdr;
    l_respHdr.init();

    do
    {
        // Dequeue the EOT entry as no more data is expected.
        l_rc = sbeUpFifoDeq_mult (len, NULL);
        CHECK_SBE_RC_AND_BREAK_IF_NOT_SUCCESS(l_rc);

        // Run isteps
        const uint8_t isteps[][3] = {
            // Major Num,              Minor Start,       Minor End
            {SBE_ISTEP_MPIPL_CONTINUE, ISTEP_MINOR_START, MPIPL_CONTINUE_MAX_SUBSTEPS},
            {SBE_ISTEP4,               ISTEP_MINOR_START, ISTEP4_MAX_SUBSTEPS},
            {SBE_ISTEP5,               ISTEP_MINOR_START, ISTEP5_MAX_SUBSTEPS}};
        // Loop through isteps
        for( auto istep : isteps)
        {
            for(uint8_t l_minor = istep[1]; l_minor <= istep[2]; l_minor++)
            {
                l_fapiRc = sbeExecuteIstep(istep[0], l_minor);
                if(l_fapiRc != FAPI2_RC_SUCCESS)
                {
                    SBE_ERROR(SBE_FUNC "Failed in Mpipl continue in ChipOp "
                        "Mode Major [%d] Minor [%d]", istep[0], l_minor);
                    l_respHdr.setStatus( SBE_PRI_GENERIC_EXECUTION_FAILURE,
                                     SBE_SEC_GENERIC_FAILURE_IN_EXECUTION);
                    l_ffdc.setRc(l_fapiRc);
                    break;
                }
            }
            if(l_ffdc.getRc() != FAPI2_RC_SUCCESS)
            {
                break;
            }
        }
    }while(0);

    // Create the Response to caller
    // 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)
    {
        l_rc = sbeDsSendRespHdr( l_respHdr, &l_ffdc);
    }
    SBE_EXIT(SBE_FUNC);
    return l_rc;
    #undef SBE_FUNC
}

///////////////////////////////////////////////////////////////////////
// @brief sbeStopClocks Sbe Stop Clocks function
//
// @return  RC from the underlying FIFO utility
// RTC-161679 : Stop Clocks Chip-op to handle Proc Chip Target
///////////////////////////////////////////////////////////////////////
uint32_t sbeStopClocks(uint8_t *i_pArg)
{
    #define SBE_FUNC " sbeStopClocks"
    SBE_ENTER(SBE_FUNC);
    uint32_t l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
    uint32_t l_fapiRc = FAPI2_RC_SUCCESS;
    uint32_t l_len = 0;
    sbeResponseFfdc_t l_ffdc;
    sbeRespGenHdr_t l_respHdr;
    l_respHdr.init();
    sbeStopClocksReqMsgHdr_t l_reqMsg = {0};

    do
    {
        // Get the TargetType and ChipletId from the command message
        l_len  = sizeof(sbeStopClocksReqMsgHdr_t)/sizeof(uint32_t);
        l_rc = sbeUpFifoDeq_mult (l_len, (uint32_t *)&l_reqMsg); // EOT fetch
        // If FIFO access failure
        CHECK_SBE_RC_AND_BREAK_IF_NOT_SUCCESS(l_rc);

        SBE_INFO(SBE_FUNC "TargetType 0x%04X ChipletId 0x%02X",
                    (uint16_t)l_reqMsg.targetType,
                    (uint8_t)l_reqMsg.chipletId);

        if(false == l_reqMsg.validateInputTargetType())
        {
            l_respHdr.setStatus( SBE_PRI_INVALID_DATA,
                                 SBE_SEC_INVALID_TARGET_TYPE_PASSED );
            break;
        }

        uint64_t l_clk_regions = p9hcd::CLK_REGION_ALL_BUT_PLL_REFR;
        uint8_t l_ex_select   = p9hcd::BOTH_EX;

        if( (l_reqMsg.chipletId == SMT4_ALL_CORES) ||
            (l_reqMsg.chipletId == EQ_ALL_CHIPLETS) )
        {
            Target<TARGET_TYPE_PROC_CHIP > l_procTgt = plat_getChipTarget();
            if(l_reqMsg.targetType == TARGET_CORE)
            {
                for (auto l_coreTgt : l_procTgt.getChildren<fapi2::TARGET_TYPE_CORE>())
                {
                    SBE_DEBUG(SBE_FUNC " Calling p9_hcd_core_stopclocks");
                    SBE_EXEC_HWP(l_fapiRc, p9_hcd_core_stopclocks_hwp, l_coreTgt)
                    if(l_fapiRc != FAPI2_RC_SUCCESS)
                    {
                        // break from internal for loop
                        break;
                    }
                }
            }
            else // Cache
            {
                for (auto l_eqTgt : l_procTgt.getChildren<fapi2::TARGET_TYPE_EQ>())
                {
                    SBE_DEBUG(SBE_FUNC " Calling p9_hcd_cache_stopclocks");
                    SBE_EXEC_HWP(l_fapiRc, p9_hcd_cache_stopclocks_hwp,
                                 l_eqTgt,
                                 (p9hcd::P9_HCD_CLK_CTRL_CONSTANTS)l_clk_regions,
                                 (p9hcd::P9_HCD_EX_CTRL_CONSTANTS)l_ex_select)
                    if(l_fapiRc != FAPI2_RC_SUCCESS)
                    {
                        // break from internal for loop
                        break;
                    }
                }
            }
        }
        else // for a single Core/Cache chiplet
        {
            // Construct the Target
            fapi2::plat_target_handle_t l_tgtHndl;
            // No Need to check the return here, it's already validated
            sbeGetFapiTargetHandle( l_reqMsg.targetType,
                                    l_reqMsg.chipletId,
                                    l_tgtHndl );

            if(l_reqMsg.targetType == TARGET_CORE)
            {
                SBE_DEBUG(SBE_FUNC " Calling p9_hcd_core_stopclocks");
                l_fapiRc = p9_hcd_core_stopclocks(l_tgtHndl);
            }
            else //Cache
            {
                SBE_DEBUG(SBE_FUNC " Calling p9_hcd_cache_stopclocks");
                l_fapiRc = p9_hcd_cache_stopclocks(l_tgtHndl,
                                (p9hcd::P9_HCD_CLK_CTRL_CONSTANTS)l_clk_regions,
                                (p9hcd::P9_HCD_EX_CTRL_CONSTANTS)l_ex_select);
            }
        }

        if( l_fapiRc != FAPI2_RC_SUCCESS )
        {
            SBE_ERROR(SBE_FUNC" Stopclocks failed for TargetType [0x%04X] "
                "ChipletId [0x%02X]",
                (uint16_t)l_reqMsg.targetType,
                (uint8_t)l_reqMsg.chipletId);
            l_respHdr.setStatus( SBE_PRI_GENERIC_EXECUTION_FAILURE,
                                 SBE_SEC_GENERIC_FAILURE_IN_EXECUTION);
            l_ffdc.setRc(l_fapiRc);
            break;
        }
    }while(0);

    // Create the Response to caller
    // 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)
    {
        l_rc = sbeDsSendRespHdr( l_respHdr, &l_ffdc);
    }

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


OpenPOWER on IntegriCloud