summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/istepdispatcher/istepdispatcher.H
blob: 1048b9c754a48cfd7e06e02f8c92c03430aceb9d (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/initservice/istepdispatcher/istepdispatcher.H $       */
/*                                                                        */
/* 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                                                     */
#ifndef __ISTEPDISPATCHER_ISTEPDISPATCHER_H
#define __ISTEPDISPATCHER_ISTEPDISPATCHER_H
/**
 *  @file istepdispatcher.H
 *
 *  IStep Dispatcher interface.  Launched from Extended Initialization Service
 *
 */

/**
 * @page    IStepDispatcher IStep Dispatcher
 *
 *
 */


/******************************************************************************/
// Includes
/******************************************************************************/
#include    <stdint.h>
#include    <time.h>
#include    <util/singleton.H>
#include    <sys/msg.h>
#include    <sys/sync.h>
#include    <errl/errlentry.H>
#include    <initservice/taskargs.H>
#include    <initservice/initsvcreasoncodes.H>
#include    <initservice/initsvcstructs.H>
#include    "../baseinitsvc/initservice.H"
#include    "splesscommon.H"
#include    "istep_mbox_msgs.H"

namespace   INITSERVICE
{

/******************************************************************************/
// Globals/Constants
/******************************************************************************/

/**
 * @brief the maximum time (seconds) runProgressThread() waits to send the next
 *      progress code (FSP requires a message every 15 sec). Picking 10 sec
 *      is a good choice because it is sufficiently less than 15.
 */
const uint64_t MAX_WAIT_TIME_SEC = 10;

/******************************************************************************/
// Typedef/Enumerations
/******************************************************************************/

/**
 * @brief   detached task (daemon) to handle communication from
 *          VPO / Simics user console.
 *
 * param[in,out]    -   pointer to any args
 *
 * @return  NULL
 */
void* spTask ( void *io_pArgs );

/**
 * @brief enums for whether the messages IStepdispatcher sends are synchronus
 *      or asynchronous.
 */
enum IStepSync_t
{
    ISTEP_SYNC,
    ISTEP_ASYNC,
};

/******************************************************************************/
//  Class IStepDispatcher
/******************************************************************************/

/**
 *  @class  IStepDispatcher
 *
 *  Dispatch ISteps and handle return codes, errorlogs, etc.
 *
 */
class IStepDispatcher
{

public:

    /**
     * @brief Get singleton instance of this class.
     *
     *  @return the (one and only) instance of IStepDispatcher
     */
    static IStepDispatcher& getTheInstance();

    /**
     * @brief This function is what is called to startup the main istep
     *      dispatcher thread.
     *
     * @param[in/out] io_rtaskRetErrl - Errorlog pointer to be returned for
     *      any errors that might have been encountered.
     *
     * @return NONE.
     */
    void init ( errlHndl_t &io_rtaskRetErrl );

    /**
     * @brief This function is used to send a sync point message from Hostboot
     *      to the Fsp.
     *
     * @return errlHndl_t - NULL if successful, otherwise a pointer to the
     *      error log.
     */
    errlHndl_t sendSyncPoint ( void );

    /**
     * @brief This function is used for calling code to be held off waiting
     *      for a syncpoint message from an external source.  Anyone calling
     *      this will be blocked on this call until ANY sync point message is
     *      received.  Once received, each caller in succession will be
     *      released.
     *
     * @return NONE.
     */
    void waitForSyncPoint ( void );

    /**
     * @brief This function when called will send a Istep complete mailbox
     *      message to the Fsp to indicate that the current Istep is complete.
     *
     * @return errlHndl_t - NULL if successful, otherwise a pointer to the
     *      error log.
     */
    errlHndl_t sendIstepCompleteMsg ( void );

    /**
     * @brief This function will handle all breakpoint requests from the
     *      running istep code.  The running istep code would be initiated via
     *      the istep dispatcher worker thread.  Thus, holding off the worker
     *      thread.
     *
     * @param[in] i_info - TODO - this needs to be decided yet.  But it seems
     *      at least preliminarily that this will contain a unique breakpoint
     *      numbering value.
     *
     * @return NONE.
     */
    void handleBreakpoint ( uint32_t i_info );

    /**
     * @brief This function will return the current istep and substep.
     *
     * @param[out] o_iStep - The current Istep value.
     *
     * @param[out] o_subStep - The current SubStep value.
     *
     * @return NONE.
     */
    void getIstepInfo ( uint8_t & o_iStep,
                        uint8_t & o_subStep );

    /**
     * @brief This function will return whether or not we are in MPIPL mode
     *
     *  @return bool - flag indicating whether we're in MPIPL mode
     *  @retval false if not in  MPIPL mode
     *          true if in MPIPL mode
     */
    bool isMpiplMode( void ) const
    {
        return iv_mpipl_mode;
    }

    /**
     * @brief   getIStepMode - return value of IStep Mode
     *
     *  @return bool - value of iv_istepmodeflag
     *  @retval false if IStep Mode is "OFF"
     *          true if IStep Mode is "ON"
     */
    bool getIStepMode( ) const;

    /**
     * @brief This function sends a progress message if an istep/substep takes
     *      longer than MAX_WAIT_TIME_SEC. This function never returns and
     *      should only be called on a new thread by the startProgressThread
     *      function
     *
     *  @return NONE.
     */
    void runProgressThread ( void );

protected:

    /**
     * @brief Constructor for the IStepDispatcher object.
     */
    IStepDispatcher();


    /**
     * @brief Destructor for the IStepDispatcher object.
     */
    ~IStepDispatcher();

private:

    /**
     * @note   Disable copy constructor and assignment operator
     */
    IStepDispatcher(const IStepDispatcher& i_right);
    IStepDispatcher& operator=(const IStepDispatcher& i_right);


    /**
     * @brief This function will start at istep 0, substep 0, and cycle
     *      through all possible isteps, returning when complete, or an error
     *      is hit.
     *
     * @return errlHndl_t - NULL if successful, otherwise a pointer to an
     *      error log.
     */
    errlHndl_t executeAllISteps ( void );

    /**
     * @brief This function is the main handler loop for the Istep Dispatcher.
     *      it receives all messages from outside sources and initiates the
     *      proper action and response (if required).
     *
     * @return errlHndl_t - NULL if successful, otherwise a pointer to an
     *      error log.
     */
    errlHndl_t msgHndlr ( void );

    /**
     * @brief This function is used to send mailbox messages to the Fsp.
     *
     * @param[in] i_sendSync - The sync type of message to send.  Whether
     *      synchronous or asynchronous.
     *
     * @param[in] i_msg - The message to send to the Fsp.
     *
     * @return errlHndl_t - NULL if successful, otherwise a pointer to an
     *      error log.
     */
    errlHndl_t sendMboxMsg ( IStepSync_t i_sendSync,
                             msg_t * i_msg );

    /**
     * @brief This function is used for all of the Syncpoint message handling.
     *
     * @return NONE.
     */
    void handleSyncPointReachedMsg ( void );

    /**
     * @brief This function is used to handle the message from the worker
     *      thread requesting more work.
     *
     * @param[in] i_first - TRUE for the very first call. FALSE afterward
     *
     * @return NONE.
     */
    void handleMoreWorkNeededMsg ( bool i_first );

    /**
     * @brief This function is used to handle the message from the FSP
     *        telling hostboot to execute the processing required for
     *        the sys_proc_fab_iovalid istep
     *
     * @return NONE.
     */
    void handleProcFabIovalidMsg( void );

        /**
     * @brief This function is used to handle the single Istep requests from
     *      outside sources.
     *
     * @return NONE.
     */
    void handleIStepRequestMsg ( void );

    /**
     * @brief This function is used to set the current Istep and Substep
     *      values for what is currently running.
     *
     * @return NONE.
     */
    void setIstepInfo ( uint16_t i_type );


    /**
     * @brief This function will check whether or not we are in MPIPL mode
     *
     *  @return bool - flag indicating whether we're in MPIPL mode
     *  @retval false if not in  MPIPL mode
     *          true if in MPIPL mode
     */
    bool checkMpiplMode ( void ) const;

    /**
     * @brief This function is used to send a progress message from Hostboot
     *      to Fsp.
     *
     * param[in]    -   flag to acquire mutex or not
     *
     * @return errlHndl_t - NULL if successful, otherwise a pointer to the
     *      error log.
     */
    errlHndl_t sendProgressCode ( bool i_needsLock = true );

    /**
     * @brief This function spawns a thread for runProgressThread to run on
     *
     * param[in,out]    -   pointer to any args
     *
     * @return  NONE
     */
    static void * startProgressThread ( void * p);

    //  -----   internal vars   -----------------------------

    mutex_t iv_bkPtMutex;
    mutex_t iv_syncMutex;
    mutex_t iv_mutex;       //used to synchronize access to all instance
                            //variables except iv_sync which is handled by
                            //iv_syncMutex/iv_syncHit
    sync_cond_t iv_syncHit;
    uint8_t iv_curIStep;
    uint8_t iv_curSubStep;
    bool iv_sync;
    bool iv_mpipl_mode;     //flag indicating whether we're in MPIPL mode
    msg_q_t iv_msgQ;
    msg_t* iv_workerMsg;    // More work Needed Msg from Worker
    msg_t* iv_Msg;          // All other Msgs that need to be saved
    bool iv_progressThreadStarted;

    //For progress code messages
    timespec_t iv_lastProgressMsgTime;

};  //  class IStepDispatcher


} // namespace

#endif
OpenPOWER on IntegriCloud