summaryrefslogtreecommitdiffstats
path: root/src/include/usr/initservice/taskargs.H
blob: 095590153a80a570bed90cb3cad27b3866c79af6 (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
/****************************************************************************
 * $IBMCopyrightBlock:
 * 
 *  IBM Confidential
 * 
 *  Licensed Internal Code Source Materials
 * 
 *  IBM HostBoot Licensed Internal Code
 * 
 *  (C) Copyright IBM Corp. 2011
 * 
 *  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.
 * $
****************************************************************************/

#ifndef __TASKARGS_TASKARGS_H
#define __TASKARGS_TASKARGS_H

/**
 * @file    taskargs.H
 *
 * common file to hold arguments passed onto tasks.
 *
 * will also hold macros, etc to manage arguments

 */

#include    <assert.h>
#include    <sys/sync.h>
#include    <trace/interface.H>
#include    <sys/task.h>  //needed to make macro work

#include    <errl/errlentry.H>
#include    <errl/errlmanager.H>

/**
 * @note macro to set up a _start() task entry routine.
 */
#define TASK_ENTRY_MACRO( MyInitFn )                                        \
extern "C"                                                                  \
void _start( void *io_pArgs )                                               \
{                                                                           \
    INITSERVICE::TaskArgs::TaskArgs *pTaskArgs  =                           \
            reinterpret_cast<INITSERVICE::TaskArgs::TaskArgs *>(io_pArgs);  \
                                                                            \
    MyInitFn( pTaskArgs );                                                  \
                                                                            \
    if  ( pTaskArgs )                                                       \
    {                                                                       \
        pTaskArgs->waitChildSync();                                         \
    }                                                                       \
                                                                            \
    task_end();                                                             \
}


namespace   INITSERVICE
{

/**
 * @const   TASKARGS_UNDEFINED64
 *  iv_taskreturncode and iv_taskcommand are initialized to this value -
 *  if parent or child change them, it can be easily recognized
 *
 *
 */
const   uint64_t    TASKARGS_UNDEFINED64  =   0xbadc0ffee0ddf00d;

/**
 *  @class TaskArgs
 *
 *  passed into a task as a void* pointer
 *  contains:
 *      - barrier to wait on
 *      - data from parent (if used)
 *      - return code from child (if used)
 *      - pointer to errorlog handle
 *
 */
class  TaskArgs
{

public:


    /**
     * @brief   TaskArgs    constructor
     *
     */
    TaskArgs();


    /**
     * @brief   TaskArgs    destructor
     */
    ~TaskArgs();


    /**
     * @brief   waitParentSync()
     *
     * Wait for internal barrier associated with this args struct
     * This should be called by the task that launches a child task.
     * Currently there is no difference between parent and child
     * but this may change.
     *
     */
    void    waitParentSync();


    /**
     * @brief   waitChildSync()
     *
     * Wait for internal barrier associated with this args struct
     * This should be called by the child task.
     * Currently there is no difference between parent and child
     * but this may change.
     *
     */
    void    waitChildSync();


    /**
     * @brief   postReturnCode
     *
     * Child task can use this to post a return code to InitServices
     *
     * @param[in]   i_returncode;
     *
     */
    void    postReturnCode( const uint64_t i_returncode );


    /**
     * @brief   getReturnCode
     *
     * Parent task can use this to get a return code from the child
     *
     * @return value of iv_taskreturncode;
     *
     */
    uint64_t getReturnCode( )   const;


    /**
     * @brief   setCommand
     *
     * Parent can pass commands and info to the child using this function
     *
     * @param[in]   i_command;
     */
    void    setCommand( const uint64_t  i_command );


    /**
     * @brief   getCommand
     *
     * Child can get commands from the parent using this function
     *
     *@return   value of iv_taskcommand;
     *
     * @todo    might overload this later if we need to pass structs,
     *          buffers, etc.
     */
    uint64_t    getCommand( )   const;


    /**
     * @brief   postErrorLog
     *
     * Child task can use this to post an errorlog to InitServices
     * Caller is responsible for creating a new errorlog, etc.
     * No checking is done.
     *
     * @param[in]   i_errl;
     *
     */
    void    postErrorLog( errlHndl_t i_errl );


    /**
     * @brief   getErrorLog
     *
     * Parent task can use this to get an errorlog from the child
     *
     * @return iv_errl
     *
     */
    errlHndl_t getErrorLog( );


    /**
     * @brief   clear taskargs struct between uses
     *          - barrier is left alone,
     *          - if iv_errl is non zero, we commit it here just to avoid
     *              a memory leak.
     */
    void    clear();


private:

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


    errlHndl_t  iv_errl;
    uint64_t    iv_taskreturncode;
    uint64_t    iv_taskcommand;

    barrier_t   iv_sync_barrier;

};

};  // namespace


#endif
OpenPOWER on IntegriCloud