summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/istepdispatcher/splesscommon.C
blob: fdba904de536e2ae5f085aaf8bf68dfb658b2d05 (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
/*  IBM_PROLOG_BEGIN_TAG
 *  This is an automatically generated prolog.
 *
 *  $Source: src/usr/initservice/istepdispatcher/splesscommon.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 splesscommon.C
 *
 *  Routines to access SPLESS Command and
 *  and SPLESS Status interfaces
 *
 *  Currently SPLess only supports the one command 0x00, this rewrite will
 *  allow support of other SPLess commands.
 *
 */

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

//  $$$$$$$ undefine this before checking in....
// #define SPLESS_DEBUG    1

#ifdef  SPLESS_DEBUG
    #include    <kernel/console.H>          // printk DEBUG
#endif

#include    <sys/mmio.h>                    //  mmio_scratch_read()
#include    <devicefw/userif.H>        //  deviceRead(), deviceWrite()

#include    <targeting/common/attributes.H>        //  ISTEP_MODE attribute
#include    <targeting/common/targetservice.H>

#include    "splesscommon.H"


// external reference
namespace   INITSERVICE
{
    extern trace_desc_t *g_trac_initsvc;
}   // end namespace    INITSERVICE



namespace   SPLESS
{

using namespace   TARGETING;

//  extern declarations for regs.
extern  uint64_t    g_SPLess_Command_Reg;
extern  uint64_t    g_SPLess_Status_Reg;

extern  uint64_t    g_SPLess_IStepMode_Reg;

/**
 * @def g_SPLess_pMasterProcChip
 *
 *  pointer to master proc chip used for deviceRead deviceWrite
 */
TARGETING::Target* g_SPLess_pMasterProcChip =   NULL;


/******************************************************************************/
//  SPLESS support functions
/******************************************************************************/

bool    SPLessAttached( )
{
    bool    l_rc  =   false;

    // check for IStep Mode signature(s)
    if (    g_SPLess_IStepMode_Reg == ISTEP_MODE_SPLESS_SIGNATURE )
    {
        l_rc    =   true;
    }

    return l_rc;
}


void initIStepMode( )
{
    using namespace TARGETING;
    uint64_t    l_readData      =   0;
    Target      *l_pTopLevel    =   NULL;
    TargetService& l_targetService = targetService();

    (void) l_targetService.getTopLevelTarget(l_pTopLevel);
    if (l_pTopLevel == NULL)
    {
        TRACFCOMP( INITSERVICE::g_trac_initsvc, "Top level handle was NULL" );
        // drop through, default of attribute is is false
    }
    else
    {
        // got a pointer to Targeting, complete setting the flag
        // $$ save l_readData  =   mmio_scratch_read( MMIO_SCRATCH_IPLSTEP_CONFIG );
        l_readData  =   g_SPLess_IStepMode_Reg;

#ifdef  SPLESS_DEBUG
        printk( "IStepMode Reg  = 0x%p, 0x%lx\n",   &g_SPLess_IStepMode_Reg, l_readData );
        printk( "Status Reg     = 0x%p\n",          &g_SPLess_Status_Reg );
        printk( "Command Reg    = 0x%p\n",          &g_SPLess_Command_Reg );
#endif
        TRACDCOMP( INITSERVICE::g_trac_initsvc,
                "IStepMode Reg = 0x%llx",
                l_readData );

        // check for IStep Mode signature(s)
        if (    ( l_readData == ISTEP_MODE_SPLESS_SIGNATURE )
             || ( l_readData == ISTEP_MODE_FSP_SIGNATURE )
           )
        {
            l_pTopLevel->setAttr<ATTR_ISTEP_MODE> (true );

            TRACDCOMP( INITSERVICE::g_trac_initsvc,
                    "ISTEP_MODE attribute set to TRUE." );
        }
        else
        {
            //  If not either of the above, set to run-all
            l_readData = RUN_ALL_MODE_SIGNATURE;
            // $$ save mmio_scratch_write( MMIO_SCRATCH_IPLSTEP_CONFIG, l_readData );
            l_pTopLevel->setAttr<ATTR_ISTEP_MODE> ( false );

            TRACDCOMP( INITSERVICE::g_trac_initsvc,
                    "ISTEP_MODE attribute set to FALSE." );
        }
    }

}

/******************************************************************************/
//  SPLESS Command functions
/******************************************************************************/

void    readCmd( SPLessCmd   &io_rcmd )
{
    // Do this once and save it...
    if ( g_SPLess_pMasterProcChip  == NULL )
    {
        (void)TARGETING::targetService().masterProcChipTargetHandle(
                                                       g_SPLess_pMasterProcChip );
    }

    // $$ save - mem io_rcmd.val64   =   g_SPLess_Command_Reg;
    // $$ save -io_rcmd.val64 = mmio_scratch_read(MMIO_SCRATCH_IPLSTEP_COMMAND);

    //  command reg is GMB2EC is mailbox scratchpad 3 { regs 0 - 3 }.
    size_t  op_size =   sizeof( uint64_t );
    DeviceFW::deviceRead(
              g_SPLess_pMasterProcChip,
              &(io_rcmd.val64),
              op_size,
              DEVICE_SCOM_ADDRESS( MBOX_SCRATCH_REG3 )  );

#ifdef  SPLESS_DEBUG
    printk( "readCmd hi 0x%x\n", io_rcmd.hi32 );
    printk( "readCmd lo 0x%x\n", io_rcmd.lo32 );
#endif
}


void    writeCmd( SPLessCmd    &io_rcmd )
{
    // Do this once and save it...
    if ( g_SPLess_pMasterProcChip  == NULL )
    {
        (void)TARGETING::targetService().masterProcChipTargetHandle(
                                                       g_SPLess_pMasterProcChip );
    }

    // save - mem g_SPLess_Command_Reg    =   io_rcmd.val64;
    // save mmio_scratch_write( MMIO_SCRATCH_IPLSTEP_COMMAND, io_rcmd.val64 );

    //  command reg is GMB2EC is mailbox scratchpad 3 { regs 0 - 3 }.
    size_t  op_size =   sizeof( uint64_t );
    DeviceFW::deviceWrite(
               g_SPLess_pMasterProcChip,
               &(io_rcmd.val64),
               op_size,
               DEVICE_SCOM_ADDRESS( MBOX_SCRATCH_REG3 )  );

#ifdef  SPLESS_DEBUG
    printk( "writeCmd hi 0x%x\n", io_rcmd.hi32 );
    printk( "writeCmd lo 0x%x\n", io_rcmd.lo32 );
#endif
}


/******************************************************************************/
//  SPLESS Status
/******************************************************************************/

void    readSts(   SPLessSts   &io_rsts )
{
    // Do this once and save it...
    if ( g_SPLess_pMasterProcChip  == NULL )
    {
        (void)TARGETING::targetService().masterProcChipTargetHandle(
                                                       g_SPLess_pMasterProcChip );
    }

    // $$ save - mem io_rsts.val64   =   g_SPLess_Status_Reg;
    // $$ io_rsts.val64 = mmio_scratch_read(MMIO_SCRATCH_IPLSTEP_STATUS);

    // status reg (Hi 32) is now GMB2E8 is mailbox scratchpad 2  {regs 0 - 3 }
    size_t  op_size =   sizeof( uint64_t );
    DeviceFW::deviceRead(
              g_SPLess_pMasterProcChip,
              &(io_rsts.val64),
              op_size,
              DEVICE_SCOM_ADDRESS( MBOX_SCRATCH_REG2 )  );
    // status reg lo is GMB2E4 - mailbox scratchpad 1  { regs 0 -3 }
    uint64_t    swap    =   0;
    DeviceFW::deviceRead(
              g_SPLess_pMasterProcChip,
              &(swap),
              op_size,
              DEVICE_SCOM_ADDRESS( MBOX_SCRATCH_REG1 )  );
    io_rsts.lo32    =
        static_cast<uint32_t>( ((swap >> 32) & 0x00000000ffffffff) );

#ifdef  SPLESS_DEBUG
    printk( "readSts hi 0x%x\n", io_rsts.hi32 );
    printk( "readSts lo 0x%x\n", io_rsts.lo32 );
#endif
}


void    writeSts(  SPLessSts   &io_rsts )
{
    // Do this once and save it...
    if ( g_SPLess_pMasterProcChip  == NULL )
    {
        (void)TARGETING::targetService().masterProcChipTargetHandle(
                                                       g_SPLess_pMasterProcChip );
    }

    size_t  op_size =   sizeof( uint64_t );

    //  Write Status reg first
    // status reg lo is GMB2E4 - mailbox scratchpad 1  { regs 0 -3 }
    uint64_t    swap    =
        ((static_cast<uint64_t>(io_rsts.lo32) << 32 ) & 0xffffffff00000000) ;
    DeviceFW::deviceWrite(
              g_SPLess_pMasterProcChip,
              &(swap),
              op_size,
              DEVICE_SCOM_ADDRESS( MBOX_SCRATCH_REG1 )  );

    // $$ save - mem g_SPLess_Status_Reg =   io_rsts.val64;
    // $$ save mmio_scratch_write( MMIO_SCRATCH_IPLSTEP_STATUS, io_rsts.val64 );
    DeviceFW::deviceWrite(
              g_SPLess_pMasterProcChip,
              &(io_rsts.val64),
              op_size,
              DEVICE_SCOM_ADDRESS( MBOX_SCRATCH_REG2 )  );

#ifdef  SPLESS_DEBUG
    printk( "writeSts hi 0x%x\n", io_rsts.hi32 );
    printk( "writeSts lo 0x%x\n", io_rsts.lo32 );
#endif
}

}   // namespace

OpenPOWER on IntegriCloud