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
|
/* IBM_PROLOG_BEGIN_TAG
* This is an automatically generated prolog.
*
* $Source: src/usr/hwpf/hwp/start_payload/start_payload.C $
*
* IBM CONFIDENTIAL
*
* COPYRIGHT International Business Machines Corp. 2012
*
* 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 other-
* wise divested of its trade secrets, irrespective of what has
* been deposited with the U.S. Copyright Office.
*
* Origin: 30
*
* IBM_PROLOG_END_TAG
*/
/**
* @file start_payload.C
*
* Support file for IStep: start_payload
* Start Payload
*
* HWP_IGNORE_VERSION_CHECK
*
*/
/******************************************************************************/
// Includes
/******************************************************************************/
#include <stdint.h>
#include <kernel/console.H> // printk status
#include <sys/misc.h>
#include <trace/interface.H>
#include <initservice/taskargs.H>
#include <errl/errlentry.H>
#include <vfs/vfs.H>
#include <initservice/initserviceif.H>
#include <initservice/extinitserviceif.H>
#include <initservice/istepdispatcherif.H>
#include <usr/cxxtest/TestSuite.H>
#include <hwpf/istepreasoncodes.H>
#include <sys/time.h>
#include <sys/mmio.h>
#include <mbox/mbox_queues.H>
#include <mbox/mboxif.H>
#include <i2c/i2cif.H>
#include <initservice/isteps_trace.H>
#include <hwpisteperror.H>
// targeting support
#include <targeting/common/commontargeting.H>
// fapi support
#include <fapi.H>
#include <fapiPlatHwpInvoker.H>
#include "start_payload.H"
#include <runtime/runtime.H>
// Uncomment these files as they become available:
// #include "host_start_payload/host_start_payload.H"
namespace START_PAYLOAD
{
using namespace TARGETING;
using namespace fapi;
using namespace ISTEP;
using namespace ISTEP_ERROR;
/**
* @brief This function will call the Initservice interface to shutdown
* Hostboot. This function will call shutdown, passing in system
* attribute variables for the Payload base and Payload offset.
*
* @return errlHndl_t - NULL if succesful, otherwise a pointer to the error
* log.
*/
errlHndl_t callShutdown ( void );
/**
* @brief This function will check the Istep mode and send the appropriate
* mailbox message to the Fsp to indicate what we're doing.
*
* @param[in] i_istepModeFlag - Whether or not Isteps is enabled.
*
* @param[in] i_spFuncs - The SpFuncs system attribute.
*
* @return errlHndl_t - NULL if successful, otherwise a pointer to the error
* log.
*/
errlHndl_t notifyFsp ( bool i_istepModeFlag,
TARGETING::SpFunctions i_spFuncs );
//
// Wrapper function to call host_runtime_setup
//
void* call_host_runtime_setup( void *io_pArgs )
{
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"call_host_runtime_setup entry" );
errlHndl_t l_err = NULL;
IStepError l_StepError;
// Need to wait here until Fsp tells us go
INITSERVICE::waitForSyncPoint();
do
{
// Need to load up the runtime module if it isn't already loaded
if ( !VFS::module_is_loaded( "libruntime.so" ) )
{
l_err = VFS::module_load( "libruntime.so" );
if ( l_err )
{
// load module returned with errl set
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"Could not load runtime module" );
// break from do loop if error occured
break;
}
}
// Write the HostServices attributes into mainstore
l_err = RUNTIME::populate_attributes();
// - Update HDAT with tpmd logs
} while(0);
if( l_err )
{
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"istep start_payload_failed see plid 0x%x", l_err->plid());
l_StepError.addErrorDetails(ISTEP_START_PAYLOAD_FAILED,
ISTEP_HOST_RUNTIME_SETUP, l_err );
errlCommit(l_err, ISTEP_COMP_ID);
}
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"call_host_runtime_setup exit" );
return l_StepError.getErrorHandle();
}
//
// Wrapper function to call host_start_payload
//
void* call_host_verify_hdat( void *io_pArgs )
{
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"call_host_verify_hdat entry" );
errlHndl_t l_err = NULL;
// Host Start Payload procedure, per documentation from Patrick.
// - Verify target image
// - TODO - Done via call to Secure Boot ROM.
// - Will be done in future sprints
// stub for now..
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"call_host_verify_hdat exit" );
return l_err;
}
//
// Wrapper function to call host_start_payload
//
void* call_host_start_payload( void *io_pArgs )
{
errlHndl_t l_errl = NULL;
IStepError l_StepError;
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"call_host_start_payload entry" );
// - Run CXX testcases
l_errl = INITSERVICE::executeUnitTests();
if( l_errl == NULL )
{
// - Call shutdown using payload base, and payload entry.
// - base/entry will be from system attributes
// - this will start the payload (Phyp)
// NOTE: this call will not return if successful.
l_errl = callShutdown();
};
if( l_errl )
{
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"istep start_payload_failed see plid 0x%x", l_errl->plid());
l_StepError.addErrorDetails(ISTEP_START_PAYLOAD_FAILED,
ISTEP_HOST_START_PAYLOAD, l_errl );
errlCommit(l_errl, ISTEP_COMP_ID);
}
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"call_host_start_payload exit" );
// end task, returning any errorlogs to IStepDisp
return l_StepError.getErrorHandle();
}
//
// Call shutdown
//
errlHndl_t callShutdown ( void )
{
errlHndl_t err = NULL;
uint64_t payloadBase = 0x0;
uint64_t payloadEntry = 0x0;
bool istepModeFlag = false;
uint64_t status = SHUTDOWN_STATUS_GOOD;
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
ENTER_MRK"callShutdown()" );
do
{
// Phyp needs us to program all of the I2C masters with the bus
// divisor
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"Setup I2C Masters" );
err = I2C::i2cSetupMasters();
if( err )
{
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"Error setting up I2C Bus Divisors" );
break;
}
// Set scratch register to indicate Hostboot is [still] active.
const char * hostboot_string = "hostboot";
mmio_scratch_write(MMIO_SCRATCH_HOSTBOOT_ACTIVE,
*reinterpret_cast<const uint64_t*>(hostboot_string));
// Get Target Service, and the system target.
TargetService& tS = targetService();
TARGETING::Target* sys = NULL;
(void) tS.getTopLevelTarget( sys );
if( NULL == sys )
{
// Error getting system target to get payload related values. We
// will create an error to be passed back. This will cause the
// istep to fail.
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
ERR_MRK"System Target was NULL!" );
/*@
* @errortype
* @reasoncode ISTEP_TARGET_NULL
* @severity ERRORLOG::ERRL_SEV_CRITICAL_SYS_TERM
* @moduleid ISTEP_START_PAYLOAD_CALL_SHUTDOWN
* @userdata1 <UNUSED>
* @userdata2 <UNUSED>
* @devdesc System target was NULL!
*/
err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_CRITICAL_SYS_TERM,
ISTEP_START_PAYLOAD_CALL_SHUTDOWN,
ISTEP_TARGET_NULL,
0x0,
0x0 );
break;
}
// Get Payload base/entry from attributes
payloadBase = sys->getAttr<TARGETING::ATTR_PAYLOAD_BASE>();
payloadEntry = sys->getAttr<TARGETING::ATTR_PAYLOAD_ENTRY>();
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
INFO_MRK"Payload Base: 0x%08x, Entry: 0x%08x",
payloadBase, payloadEntry );
payloadBase = (payloadBase * MEGABYTE);
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
INFO_MRK" base: 0x%08x",
payloadBase );
// Get Istep Mode flag
istepModeFlag = sys->getAttr<ATTR_ISTEP_MODE>();
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
INFO_MRK"Istep mode flag: %s",
((istepModeFlag) ? "Enabled" : "Disabled") );
// Get the Service Processor Functions
TARGETING::SpFunctions spFuncs =
sys->getAttr<TARGETING::ATTR_SP_FUNCTIONS>();
// Notify Fsp with appropriate mailbox message.
err = notifyFsp( istepModeFlag,
spFuncs );
if( err )
{
break;
}
// do the shutdown.
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
"callShutdown finished, shutdown = 0x%x.",
status );
INITSERVICE::doShutdown( status,
payloadBase,
payloadEntry );
// Hang out here until shutdown happens
int status = 0x0;
while( 1 )
{
task_wait( &status,
NULL );
}
} while( 0 );
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
EXIT_MRK"callShutdown()" );
return err;
}
//
// Notify the Fsp via Mailbox Message
//
errlHndl_t notifyFsp ( bool i_istepModeFlag,
TARGETING::SpFunctions i_spFuncs )
{
errlHndl_t err = NULL;
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
ENTER_MRK"notifyFsp()" );
do
{
if( i_istepModeFlag )
{
// Istep Mode send istep complete
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
INFO_MRK"Isteps enabled, send istep complete msg" );
err = INITSERVICE::sendIstepCompleteMsg();
if( err )
{
break;
}
}
else
{
// Non-Istep mode send SYNC_POINT_REACHED
TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
INFO_MRK"Isteps disabled, send SYNC_POINT_REACHED msg" );
err = INITSERVICE::sendSyncPoint();
if( err )
{
break;
}
}
} while( 0 );
TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
EXIT_MRK"notifyFsp()" );
return err;
}
}; // end namespace
|