summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/bootconfig/bootconfig_ast2400.C
blob: 87caa32a5a90a5d8f9166b705658235f0ee9ed72 (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
366
367
368
369
370
371
372
373
374
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/initservice/bootconfig/bootconfig_ast2400.C $         */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2018                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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                                                     */
/******************************************************************************/
// Includes
/******************************************************************************/
#include "bootconfig_ast2400.H"

#include <lpc/lpcif.H>
#include <devicefw/userif.H>
#include <errl/errlentry.H>
#include <trace/interface.H>
#include <hwas/common/deconfigGard.H>
#include <console/consoleif.H>
#include <config.h>
#include <sio/sio.H>
#include <devicefw/driverif.H>

namespace INITSERVICE
{
namespace BOOTCONFIG
{

// declare storage for config trace
extern trace_desc_t * g_bc_trace;

AST2400BootConfig::AST2400BootConfig()
{
    CURRENT_CONFIG_VERSION = BOOT_FLAGS_VERSION_1;
};


AST2400BootConfig::~AST2400BootConfig()
{};

// ----------------------------------------------------------------------------
// configureBootMode()
// ----------------------------------------------------------------------------
void AST2400BootConfig::configureBootMode(uint8_t i_bootMode )
{
    // assume boot mode is exclusive..
    switch( i_bootMode )
    {
        case NORMAL:
            {
                TRACFCOMP(g_bc_trace,
                        "configureBootMode() - Boot Mode = NORMAL");
                break;
            }
        // RTC:123376 - Need to investigate if any additional flags need to be
        // set or if terminate on error is sufficient
        case TERMINATE_ON_ERROR:
            {

                TARGETING::Target* l_pTopLevel = NULL;
                TARGETING::targetService().getTopLevelTarget(l_pTopLevel);

                TRACFCOMP(g_bc_trace,
                        "configureBootMode() - Boot Mode = TERMINATE_ON_ERROR");

                l_pTopLevel->setAttr<TARGETING::ATTR_MNFG_FLAGS>
                                        (TARGETING::MNFG_FLAG_SRC_TERM );
                break;
            }

        case ISTEP_MODE:
            {
                TRACFCOMP(g_bc_trace,
                        "configureBootMode() - Boot Mode = ISTEP MODE");

                TARGETING::Target* l_pTopLevel = NULL;
                TARGETING::targetService().getTopLevelTarget(l_pTopLevel);

                l_pTopLevel->setAttr<TARGETING::ATTR_ISTEP_MODE>(1);

                break;
            }

         default:
                  TRACFCOMP(g_bc_trace,
                            "WRN>>configureBootMode() - Boot mode = "
                             "INVALID[0x%x] default to normal", i_bootMode );
                break;

          break;
    }
}

// ----------------------------------------------------------------------------
// configureHbLogLevel()
// ----------------------------------------------------------------------------
void AST2400BootConfig::configureHbLogLevel(uint8_t i_logOptions )
{

    switch( i_logOptions )
    {
        case LOG_ENABLE_SCAN_TRACE:
            {
                TRACFCOMP(g_bc_trace,
                  "configureHbLogLevel() - Log level = enable scan trace");

                // enable the scan trace for now.
                TARGETING::Target* l_pTopLevel = NULL;
                TARGETING::targetService().getTopLevelTarget(l_pTopLevel);

                TARGETING::HbSettings hbSettings =
                    l_pTopLevel->getAttr<TARGETING::ATTR_HB_SETTINGS>();

                // if its not already set, then set it.
                if( !hbSettings.traceScanDebug )
                {
                    hbSettings.traceScanDebug = 1;

                    l_pTopLevel->setAttr<
                                    TARGETING::ATTR_HB_SETTINGS>(hbSettings);
                }

                break;
            }

        default:
            {
                // do nothing
                TRACFCOMP(g_bc_trace,
                        "configureLogLevel() - Log level = NORMAL");

                break;
            }
    }

}

// ----------------------------------------------------------------------------
// configureBootOptions()
// ----------------------------------------------------------------------------
void AST2400BootConfig::configureBootOptions(uint8_t i_bootOptions )
{
    // clear gard records?
    if( i_bootOptions & CLEAR_GARD_RECORDS )
    {
        TRACFCOMP(g_bc_trace,
                "configureBootOptions()"
                " clearing gard records");

        errlHndl_t errl = HWAS::theDeconfigGard().clearGardRecords(NULL);

        if(errl)
        {
            errl->collectTrace( "BOOT_CFG", 512 );
            errlCommit(errl,INITSVC_COMP_ID);
        }
    }
};

// configurePnorDriver()
// ----------------------------------------------------------------------------
void AST2400BootConfig::configurePnorDriver( uint8_t i_driver )
{
    switch (i_driver) {
    case MBOX:
        TRACFCOMP(g_bc_trace,
                "configurePnorDriver() bmc supports mbox protocol");

#ifndef CONFIG_PNORDD_IS_BMCMBOX
        TRACFCOMP(g_bc_trace,
                  "configurePnorDriver() hb does not support mbox protocol");
#else
        TRACFCOMP(g_bc_trace,
                  "configurePnorDriver() using mbox driver");
        break;
#endif

    case SFC:
        TRACFCOMP(g_bc_trace,
                "configurePnorDriver() using sfc driver");
	break;
    }
}

// ----------------------------------------------------------------------------
// readAndProcessBootConfig()
// ----------------------------------------------------------------------------
errlHndl_t AST2400BootConfig::readAndProcessBootConfig()
{

    TRACDCOMP(g_bc_trace, ENTER_MRK"readAndProcessBootConfig()");

    errlHndl_t l_err = NULL;

    uint8_t register_data = 0;
    size_t l_len = sizeof(uint8_t);
    do
    {
        // The BMC may have disabled SIO, in which case we use a default set of
        // boot flags
        bool haveSio;
        l_err = SIO::isAvailable(haveSio);
        if (l_err)
        {
            break;
        }

        if (!haveSio)
        {
            processBootFlagsV1(0);
            break;
        }

        // read the register holding the agreed upon magic
        // number to indicate registers have been configured

        // Registers below 0x30 do not belong to any particular SIO device.
        // Device field advised to be set to SUART1 or iLPC2AHB as these are the
        // only two devices currently in use and will thereby save additional
        // SIO before and after this call.
        l_err = deviceOp( DeviceFW::READ,
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &(register_data),
                          l_len,
                          DEVICE_SIO_ADDRESS(SIO::DONT_CARE, BOOT_FLAGS_VERSION_REG));
        if( l_err )
        {
            TRACFCOMP(g_bc_trace,"Failed reading the boot flags version, skip processing");
            break;
        }

        if( register_data != BOOT_FLAGS_VERSION_1 )
        {

            TRACFCOMP(g_bc_trace,"WRN>>readAndProcessBootConfig() - "
                    "boot flags not correct version"
                    " 0x%x!=0x%x", register_data, BOOT_FLAGS_VERSION_1 );

#ifdef CONFIG_CONSOLE
            CONSOLE::displayf(NULL, "Ignoring boot flags, incorrect version 0x%x", register_data);
            CONSOLE::flush();
#endif

            break;
        }

        // read the SIO register holding the boot flags
        l_err = deviceOp( DeviceFW::READ,
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &(register_data),
                          l_len,
                          DEVICE_SIO_ADDRESS(SIO::DONT_CARE, BOOT_FLAGS_REG));
        if( l_err )
        {
            TRACFCOMP(g_bc_trace,"Failed reading the boot flags, leave"
                    " settings at default values");

            break;
        }

        processBootFlagsV1( register_data );

    }while(0);

    TRACDCOMP(g_bc_trace, EXIT_MRK"readAndProcessBootConfig()");

    return l_err;
}

// ----------------------------------------------------------------------------
// processBootFlagsV1()
// ----------------------------------------------------------------------------
void AST2400BootConfig::processBootFlagsV1( uint8_t i_flags )
{
    configureBootMode( i_flags & BOOT_MODE_FLAGS );

    configurePnorDriver( i_flags & PNOR_DRIVER_FLAGS );

    configureBootOptions( i_flags & BOOT_OPTIONS_FLAGS );

    configureHbLogLevel( i_flags & LOG_LEVEL_FLAGS );
}

// ----------------------------------------------------------------------------
// readIstepControl()
// ----------------------------------------------------------------------------
errlHndl_t AST2400BootConfig::readIstepControl( istepControl_t &o_stepInfo )
{
    errlHndl_t l_err = NULL;
    size_t l_len = sizeof(uint8_t);
    do
    {
        // read istep control from 0x2a
        l_err = deviceOp( DeviceFW::READ,
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &(o_stepInfo.istepControl),
                          l_len,
                          DEVICE_SIO_ADDRESS(SIO::DONT_CARE, ISTEP_CONTROL_REG));
        if(l_err) { break; }

        // read major number from 0x2b
        l_err = deviceOp( DeviceFW::READ,
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &(o_stepInfo.istepMajorNumber),
                          l_len,
                          DEVICE_SIO_ADDRESS(SIO::DONT_CARE, ISTEP_MAJOR_REG));
        if(l_err) { break; }

        // read minor number from 0x2c
        l_err = deviceOp( DeviceFW::READ,
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &(o_stepInfo.istepMinorNumber),
                          l_len,
                          DEVICE_SIO_ADDRESS(SIO::DONT_CARE, ISTEP_MINOR_REG));
    }
    while(0);

    return l_err;
}

// ----------------------------------------------------------------------------
// IStepDispatcher::writeIstepControl()
// ----------------------------------------------------------------------------
errlHndl_t AST2400BootConfig::writeIstepControl( istepControl_t i_istepCtl )
{
    errlHndl_t l_err = NULL;
    size_t l_len = sizeof(uint8_t);

    // read istep control from 0x2a
    TRACFCOMP( g_bc_trace, "AST2400BootConfig:: Write istep control %x",  i_istepCtl.istepControl);

    do
    {
        //write status
        l_err = deviceOp( DeviceFW::WRITE,
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &(i_istepCtl.istepStatus),
                          l_len,
                          DEVICE_SIO_ADDRESS(SIO::DONT_CARE, ISTEP_STATUS_REG));
        if(l_err) { break; }

        //write command/control
        l_err = deviceOp( DeviceFW::WRITE,
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &(i_istepCtl.istepControl),
                          l_len,
                          DEVICE_SIO_ADDRESS(SIO::DONT_CARE,
                                             ISTEP_HOST_CTL_REG));
        if(l_err) { break; }
    }
    while(0);

    return l_err;
}


};
};
OpenPOWER on IntegriCloud