summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/plat/fapiPlatUtil.C
blob: 596802b4cd0e135d1930e2d9c308acf4cccfca95 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/plat/fapiPlatUtil.C $                            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2014                        */
/* [+] 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 fapiPlatUtil.C
 *
 *  @brief Implements the fapiUtil.H utility functions.
 *
 *  Note that platform code must provide the implementation.
 */

#include <assert.h>
#include <fapi.H>
#include <trace/interface.H>
#include <sys/time.h>
#include <errl/errlmanager.H>
#include <fapiPlatHwpInvoker.H>
#include <vfs/vfs.H>
#include <initservice/initsvcbreakpoint.H>
#include <errl/errlentry.H>

#ifdef __HOSTBOOT_RUNTIME
#include <runtime/interface.h>
#include <targeting/common/targetservice.H>
#include <runtime/rt_targeting.H>
#include <hwpf/hwpf_reasoncodes.H>
#endif

//******************************************************************************
// Trace descriptors
//******************************************************************************
trace_desc_t* g_fapiTd;
trace_desc_t* g_fapiImpTd;
trace_desc_t* g_fapiScanTd;

//******************************************************************************
// Global TracInit objects. Construction will initialize the trace buffer
//******************************************************************************
TRAC_INIT(&g_fapiTd, FAPI_TRACE_NAME, 2*KILOBYTE);
TRAC_INIT(&g_fapiImpTd, FAPI_IMP_TRACE_NAME, 2*KILOBYTE);
TRAC_INIT(&g_fapiScanTd, FAPI_SCAN_TRACE_NAME, 4*KILOBYTE);

extern "C"
{

//******************************************************************************
// fapiAssert
//******************************************************************************
void fapiAssert(bool i_expression)
{
    assert(i_expression);
}

//******************************************************************************
// fapiDelay
//
// At the present time, VBU runs hostboot without a Simics
// front end. If a HW procedure wants to delay, we just make the
// syscall nanosleep().  In the syscall, the kernel will continue to consume
// clock cycles as it looks for a runnable task. When the sleep time expires,
// the calling task will resume running.
//
// In the future there could be a Simics front end to hostboot VBU. Then
// a possible implementation will be to use the Simics magic instruction
// to trigger a Simics hap. The Simics hap handler can call the simdispatcher
// client/server API to tell the Awan to advance some number of cycles.
//
// Monte  4 Aug 2011
//******************************************************************************

fapi::ReturnCode fapiDelay(uint64_t i_nanoSeconds, uint64_t i_simCycles)
{
    FAPI_DBG( INFO_MRK "delay %lld nanosec", i_nanoSeconds );
#ifndef __HOSTBOOT_RUNTIME
    nanosleep( 0, i_nanoSeconds );
#else
    if(g_hostInterfaces && g_hostInterfaces->nanosleep)
    {
        g_hostInterfaces->nanosleep(0, i_nanoSeconds);
    }
#endif
    return fapi::FAPI_RC_SUCCESS;
}

//******************************************************************************
// fapiLogError
//******************************************************************************
void fapiLogError(fapi::ReturnCode & io_rc,
                  fapi::fapiErrlSeverity_t i_sev,
                  bool i_unitTestError)
{
    // ENUM CONVERSION FAPI to PLATFORM

    errlHndl_t l_pError = NULL;

    FAPI_INF("fapiLogError: logging error");

    // Convert a FAPI severity to a ERRORLOG severity
    ERRORLOG::errlSeverity_t l_sev = ERRORLOG::ERRL_SEV_UNRECOVERABLE;
    switch (i_sev)
    {
        case fapi::FAPI_ERRL_SEV_RECOVERED:
            l_sev = ERRORLOG::ERRL_SEV_RECOVERED;
            break;
        case fapi::FAPI_ERRL_SEV_PREDICTIVE:
            l_sev = ERRORLOG::ERRL_SEV_PREDICTIVE;
            break;
        case fapi::FAPI_ERRL_SEV_UNRECOVERABLE:
            // l_sev set above
            break;
        default:
            FAPI_ERR("severity (i_sev) of %d is unknown",i_sev);
    }

    // Convert the return code to an error log.
    // This will set the return code to FAPI_RC_SUCCESS and clear any PLAT Data,
    // HWP FFDC data, and Error Target associated with it.
    l_pError = fapiRcToErrl(io_rc, l_sev);

    // Commit the error log. This will delete the error log and set the handle
    // to NULL.
    if (i_unitTestError)
    {
        errlCommit(l_pError, CXXTEST_COMP_ID);
    }
    else
    {
        errlCommit(l_pError, HWPF_COMP_ID);
    }
}

//******************************************************************************
// platIsScanTraceEnabled
//******************************************************************************
bool platIsScanTraceEnabled()
{
  // SCAN trace can be dynamically turned on/off, always return true here
  return 1;
}

//******************************************************************************
// platSetScanTrace
// Implementation to be added if needed
//******************************************************************************
//void platSetScanTrace(bool i_enable)
//{
//
//}

//******************************************************************************
// fapiLoadInitFile
//******************************************************************************
fapi::ReturnCode fapiLoadInitFile(const fapi::Target & i_Target,
    const char * i_file, const char *& o_addr, size_t & o_size)
{
#ifndef __HOSTBOOT_RUNTIME
    fapi::ReturnCode l_rc = fapi::FAPI_RC_SUCCESS;
    errlHndl_t l_pError = NULL;
    o_size = 0;
    o_addr = NULL;

    FAPI_INF("fapiLoadInitFile: %s", i_file);

    l_pError = VFS::module_load(i_file);
    if(l_pError)
    {
        // Add the error log pointer as data to the ReturnCode
        FAPI_ERR("fapiLoadInitFile: module_load failed");
        l_rc.setPlatError(reinterpret_cast<void *> (l_pError));
    }
    else
    {
        l_pError = VFS::module_address(i_file, o_addr, o_size);
        if(l_pError)
        {
            // Add the error log pointer as data to the ReturnCode
            FAPI_ERR("fapiLoadInitFile: module_address failed");
            l_rc.setPlatError(reinterpret_cast<void *> (l_pError));
        }
        else
        {
            FAPI_DBG("fapiLoadInitFile: data module addr = %p, size = %ld",
                      o_addr, o_size);
            FAPI_DBG("fapiLoadInitFile: *addr = 0x%llX",
                      *(reinterpret_cast<const uint64_t*>(o_addr)));
        }
    }
#else
    fapi::ReturnCode l_rc = fapi::FAPI_RC_PLAT_NOT_SUPPORTED_AT_RUNTIME;
#endif

    return l_rc;
}

//******************************************************************************
// fapiUnloadInitFile
//******************************************************************************
fapi::ReturnCode fapiUnloadInitFile(const char * i_file, const char *& io_addr,
    size_t & io_size)
{
#ifndef __HOSTBOOT_RUNTIME
    fapi::ReturnCode l_rc = fapi::FAPI_RC_SUCCESS;
    errlHndl_t l_pError = NULL;

    FAPI_INF("fapiUnloadInitFile: %s", i_file);

    l_pError = VFS::module_unload(i_file);
    if(l_pError)
    {
        // Add the error log pointer as data to the ReturnCode
        FAPI_ERR("fapiUnloadInitFile: module_unload failed %s", i_file);
        l_rc.setPlatError(reinterpret_cast<void *> (l_pError));
    }
    else
    {
        io_addr = NULL;
        io_size = 0;
    }
#else
    fapi::ReturnCode l_rc = fapi::FAPI_RC_PLAT_NOT_SUPPORTED_AT_RUNTIME;
#endif

    return l_rc;
}

//******************************************************************************
// fapiBreakPoint
//******************************************************************************
void fapiBreakPoint( uint32_t i_info)
{
#ifndef __HOSTBOOT_RUNTIME
    INITSERVICE::iStepBreakPoint( i_info );
#endif
}

//******************************************************************************
// fapiSpecialWakeup
//******************************************************************************
fapi::ReturnCode fapiSpecialWakeup(const fapi::Target & i_target,
                                   const bool i_enable)
{
    fapi::ReturnCode fapi_rc = fapi::FAPI_RC_SUCCESS;
    FAPI_INF("fapiSpecialWakeup");
#ifdef __HOSTBOOT_RUNTIME
    if(g_hostInterfaces && g_hostInterfaces->wakeup)
    {
        TARGETING::Target* target =
            reinterpret_cast<TARGETING::Target*>(i_target.get());

        RT_TARG::rtChipId_t core_id = 0;
        errlHndl_t err = RT_TARG::getRtTarget(target, core_id);
        if(err)
        {
            fapi_rc.setPlatError(reinterpret_cast<void *>(err));
        }
        else
        {
            uint32_t mode = 0;   //Force awake
            if(!i_enable)
            {
                mode = 1;       // clear force
            }
            int rc = g_hostInterfaces->wakeup(core_id, mode);

            if(rc)
            {
                FAPI_ERR("CPU core wakeup call to hypervisor returned rc = %d",
                         rc);
                /*@
                 * @errortype
                 * @moduleid     fapi::MOD_PLAT_SPECIAL_WAKEUP
                 * @reasoncode   fapi::RC_RT_WAKEUP_FAILED
                 * @userdata1    Hypervisor return code
                 * @userdata2    Chiplet HUID
                 * @devdesc      Error code from hypervisor wakeup call
                 */
                const bool hbSwError = true;
                err = new ERRORLOG::ErrlEntry(
                                              ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                              fapi::MOD_PLAT_SPECIAL_WAKEUP,
                                              fapi::RC_RT_WAKEUP_FAILED,
                                              rc,
                                              TARGETING::get_huid(target),
                                              hbSwError);

                fapi_rc.setPlatError(reinterpret_cast<void*>(err));
            }
        }
    }
#endif
    // On Hostboot, processor cores cannot sleep so return success to the
    // fapiSpecialWakeup enable/disable calls
    return fapi_rc;
}

}
OpenPOWER on IntegriCloud