summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/plat/fapiPlatUtil.C
blob: 1b8575c9ef3ff8590b1f8630d62ede0eb2707734 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/plat/fapiPlatUtil.C $                            */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* 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>


//******************************************************************************
// 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 );
    nanosleep( 0, i_nanoSeconds );
    return fapi::FAPI_RC_SUCCESS;
}

//******************************************************************************
// fapiLogError
//******************************************************************************
void fapiLogError(fapi::ReturnCode & io_rc)
{
    errlHndl_t l_pError = NULL;
    bool l_unitTestError = false;

    FAPI_ERR("fapiLogError: logging error");

    if (fapi::RC_TEST_ERROR_A == static_cast<uint32_t>(io_rc))
    {
        l_unitTestError = true;
    }

    // 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);

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

//****************************************************************************
// platform-level implementation

bool platIsScanTraceEnabled()
{
  // TODO: Get the answer from g_fapiScanTd conditional trace buffer. Camvan
  // has not pushed the code yet.
  return 1;
}

//****************************************************************************
// platform-level implementation

void platSetScanTrace(bool i_enable)
{
  // TODO: enable or disable scan trace via the SCAN trace buffer.  Camvan
  // has not pushed the code yet.
  return;
}

//******************************************************************************
// fapiLoadInitFile
//******************************************************************************
fapi::ReturnCode fapiLoadInitFile(const fapi::Target & i_Target,
    const char * i_file, const char *& o_addr, size_t & o_size)
{
    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)));
        }
    }

    return l_rc;
}

//******************************************************************************
// fapiUnloadInitFile
//******************************************************************************
fapi::ReturnCode fapiUnloadInitFile(const char * i_file, const char *& io_addr,
    size_t & io_size)
{
    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;
    }

    return l_rc;
}

//******************************************************************************
// fapiBreakPoint
//******************************************************************************
void fapiBreakPoint( uint32_t i_info)
{
    INITSERVICE::iStepBreakPoint( i_info );
}

//******************************************************************************
// fapiSpecialWakeup
//******************************************************************************
fapi::ReturnCode fapiSpecialWakeup(const fapi::Target & i_target,
                                   const bool i_enable)
{
    // On Hostboot, processor cores cannot sleep so return success to the
    // fapiSpecialWakeup enable/disable calls
    return fapi::FAPI_RC_SUCCESS;
}

}
OpenPOWER on IntegriCloud