summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/istepdispatcher/sptask.C
blob: aa577301e7955424545abf2cf22c3fa3fbb806b0 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/initservice/istepdispatcher/sptask.C $                */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2014              */
/*                                                                        */
/* 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 sptask.C
 *
 *  SP / SPless task  detached from IStep Dispatcher.
 *      Handles
 *
 */


/******************************************************************************/
// Includes
/******************************************************************************/
#include    <stdint.h>
#include    <stdio.h>
#include    <string.h>


#include    <sys/task.h>                    //  tid_t, task_create, etc
#include    <sys/time.h>                    //  nanosleep
#include    <sys/msg.h>                     //  message Q's
#include    <mbox/mbox_queues.H>            //  MSG_HB_MSG_BASE


#include    <trace/interface.H>             //  trace support
#include    <errl/errlentry.H>              //  errlHndl_t

#include    <initservice/initsvcudistep.H>  //  InitSvcUserDetailsIstep
#include    <initservice/taskargs.H>        // TASK_ENTRY_MACRO

#include    <targeting/common/util.H>       //

#include    "istepdispatcher.H"
#include    "splesscommon.H"
#include    "istep_mbox_msgs.H"


namespace   INITSERVICE
{

using   namespace   ERRORLOG;               // IStepNameUserDetails
using   namespace   SPLESS;                 // SingleStepMode
using   namespace   TARGETING;              //

/******************************************************************************/
// Globals/Constants
/******************************************************************************/
extern trace_desc_t *g_trac_initsvc;

/**
 * @const   SPLess PAUSE - These two constants are used in a nanosleep() call
 *          below to sleep between polls of the StatusReg.  Typically this will
 *          be about 10 ms - the actual value will be determined empirically.
 */
const   uint64_t    SINGLESTEP_PAUSE_S     =   0;
const   uint64_t    SINGLESTEP_PAUSE_NS    =   10000000;

/**
 * @brief  userConsoleComm
 *
 * Communicate with User Console on VPO or Simics.
 * Forwards commands to HostBoot (IStep Dispatcher) via a message Q.
 * Forwards status from HostBoot to VPO or Simics user console.
 *
 * Stop and wait for the user console to send the next IStep to run.
 * Run that, then  wait for the next one.
 *
 * @param[in,out]  -   pointer to a message Q, passed in by the parent
 *
 * @return none
 */
void    userConsoleComm( void *  io_msgQ )
{
    SPLessCmd               l_cmd;
    SPLessSts               l_sts;
    uint8_t                 l_seqnum        =   0;
    int                     l_sr_rc         =   0;
    msg_q_t                 l_SendMsgQ      =   static_cast<msg_q_t>( io_msgQ );
    msg_t                   *l_pMsg         =   msg_allocate();
    msg_q_t                 l_RecvMsgQ      =   msg_q_create();
    msg_t                   *l_pCurrentMsg  =  NULL;

    TRACFCOMP( g_trac_initsvc,
            "userConsoleComm entry, args=%p",
            io_msgQ  );

    // initialize command reg
    l_cmd.val64 =   0;
    writeCmd( l_cmd );

    //  init status reg, enable ready bit
    l_sts.val64 =   0;
    l_sts.hdr.readybit  =   true;
    writeSts( l_sts );

    TRACFCOMP( g_trac_initsvc,
            "userConsoleComm : readybit set." );

    //  set Current to our message on entry
    l_pCurrentMsg   =   l_pMsg;
    //
    //  Start the polling loop.
    //
    while( 1 )
    {
        //  read command register from user console
        readCmd( l_cmd );

        //  process any pending commands
        if ( l_cmd.hdr.gobit )
        {
            l_cmd.hdr.readbit = 1;
            writeCmd( l_cmd );

            // get the sequence number from caller
            l_seqnum    =   l_cmd.hdr.seqnum;

            //  clear status
            l_sts.val64 =   0;

            //  set running bit, fill in istep and substep
            l_sts.hdr.runningbit    =   true;
            l_sts.hdr.readybit      =   true;

            // @todo modify hb-istep to check both running bit and seqnum
            // l_sts.hdr.seqnum        =   l_seqnum;
            l_sts.istep             =   l_cmd.istep;
            l_sts.substep           =   l_cmd.substep;


            // write the intermediate value back to the console.
            TRACDCOMP( g_trac_initsvc,
                    "userConsoleComm Write status (running) 0x%x.%x",
                    static_cast<uint32_t>( l_sts.val64 >> 32 ),
                    static_cast<uint32_t>( l_sts.val64 & 0x0ffffffff ) );

            writeSts( l_sts );

            // pass the command on to IstepDisp, block until reply

            l_pCurrentMsg->type     = ISTEP_MSG_TYPE;
            l_pCurrentMsg->data[0]  =
                ( ( static_cast<uint64_t>(l_cmd.istep & 0xFF) << 32) |
                  ( static_cast<uint64_t>(l_cmd.substep & 0xFF ) ) );
            l_pCurrentMsg->data[1]     =   0;
            l_pCurrentMsg->extra_data  =   NULL;

            TRACDCOMP( g_trac_initsvc,
            "userConsoleComm: sendmsg type=0x%08x, d0=0x%16x, d1=0x%16x, x=%p",
                       l_pCurrentMsg->type,
                       l_pCurrentMsg->data[0],
                       l_pCurrentMsg->data[1],
                       l_pCurrentMsg->extra_data );
            //
            //  msg_sendrecv_noblk  effectively splits the "channel" into
            //  a send Q and a receive Q
            //
            l_sr_rc =   msg_sendrecv_noblk( l_SendMsgQ, l_pCurrentMsg, l_RecvMsgQ );
            //  should never happen.
            assert( l_sr_rc == 0 );

            //  This should unblock on any message sent on the Q,
            l_pCurrentMsg  =   msg_wait( l_RecvMsgQ );

            // build status to return to console
            l_sts.istep         =   l_cmd.istep;
            l_sts.substep       =   l_cmd.substep;
            l_sts.hdr.status    =   0;

            // Clear command reg when the command is done
            TRACDCOMP( g_trac_initsvc,
                    "userConsoleComm Clear Command reg" );
            l_cmd.val64 =   0;
            writeCmd( l_cmd );


            TRACDCOMP( g_trac_initsvc,
            "userConsoleComm: rcvmsg type=0x%08x, d0=0x%16x, d1=0x%16x, x=%p",
                       l_pCurrentMsg->type,
                       l_pCurrentMsg->data[0],
                       l_pCurrentMsg->data[1],
                       l_pCurrentMsg->extra_data );

            if ( l_pCurrentMsg->type   == BREAKPOINT )
            {
                l_sts.hdr.status    =   SPLESS_AT_BREAK_POINT;
            }

            //  istep status is the hi word in the returned data 0
            //  this should be either 0 or a plid from a returned errorlog
            l_sts.istepStatus   =
                        static_cast<uint32_t>( l_pCurrentMsg->data[0] >> 32 );

            // finish filling in status
            l_sts.hdr.runningbit    =   false;
            l_sts.hdr.seqnum        =   l_seqnum;

            TRACDCOMP( g_trac_initsvc,
                    "userConsoleComm Write (finished) status 0x%x.%x",
                    static_cast<uint32_t>( l_sts.val64 >> 32 ),
                    static_cast<uint32_t>( l_sts.val64 & 0x0ffffffff ) );
            writeSts( l_sts );

            // clear command reg, including go bit (i.e. set to false)
            //  2012-04-27 hb-istep will clear the command reg after it sees
            //      the running bit turn on.
            //      Please save the following in case we have to turn this
            //      back on.

        }   //  endif   gobit

        // sleep, and wait for user to give us something else to do.
        if( TARGETING::is_vpo() )
        {
            // In VPO/VBU, yield the task, any real delay takes too long
            task_yield();
        }
        else
        {
            nanosleep( SINGLESTEP_PAUSE_S, SINGLESTEP_PAUSE_NS );
        }
    }   //  endwhile

    TRACFCOMP( g_trac_initsvc,
               "sptask: Uh-oh, we just exited...  what went wrong?" );

    //  @note
    //  Fell out of loop, clear sts reg and turn off readybit
    //  disable the ready bit so the user knows.
    l_sts.val64 =   0;
    l_sts.hdr.status    =   SPLESS_TASKRC_TERMINATED;
    l_sts.hdr.seqnum    =   l_seqnum;
    writeSts( l_sts );

    TRACFCOMP( g_trac_initsvc,
            "userConsoleComm exit" );

    //  free the message struct
    msg_free( l_pMsg  );

    // return to main to end task
}

void* spTask( void    *io_pArgs )
{

    TRACFCOMP( g_trac_initsvc,
            "spTask entry, args=%p",
            io_pArgs  );

    //  IStepDisp should not expect us to come back.
    task_detach();

    //  Start talking to VPO / Simics User console.
    userConsoleComm( io_pArgs );

    TRACFCOMP( g_trac_initsvc,
            "spTask exit." );

    // End the task.
    return NULL;
}


} // namespace
OpenPOWER on IntegriCloud