summaryrefslogtreecommitdiffstats
path: root/src/usr/fapi2/plat_mbvpd_access.C
blob: c13b6b08227bddda5733c15017d7179c488fc964 (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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/fapi2/plat_mbvpd_access.C $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017                             */
/* [+] 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                                                     */
/**
 *  @file  plat_mbvpd_access.C
 *
 *  @brief Implements the fapi2_mbvpd_access.H functions
 */

#include    <stdint.h>
#include    <errl/errlentry.H>

// fapi2 support changes
#include <fapi2_mbvpd_access.H>
#include <fapi2_mbvpd_access_defs.H>
#include <hwpf_fapi2_reasoncodes.H>
#include <devicefw/userif.H>
#include <vpd/cvpdenums.H>

// Invalid chip unit
const uint8_t MBVPD_INVALID_CHIP_UNIT = 0xFF;

namespace fapi2
{

//******************************************************************************
// CvpdRecordXlate
// Translates a FAPI MBVPD Record enumerator into a Hostboot CVPD Record
// enumerator
//******************************************************************************
fapi2::ReturnCode CvpdRecordXlate(const fapi2::MBvpdRecord i_fapiRecord,
                                  CVPD::cvpdRecord & o_hbRecord,
                                  uint8_t & o_recordIndex)
{
    // Create a lookup table for converting a FAPI CVPD record enumerator to a
    // Hostboot CVPD record enumerator. This is a simple array and relies on
    // the FAPI record enumerators starting at zero and incrementing.
    struct cvpdRecordToChip
    {
        CVPD::cvpdRecord rec;
        // This is the fapi2 Index to the CVPD record
        uint8_t recIndex;
    };
    static const cvpdRecordToChip cvpdFapiRecordToHbRecord[] =
    {
        /** CVPD record mapping to FAPI2 CVPD **/
        {CVPD::VEIR,MBVPD_RECORD_VEIR},
        {CVPD::VER0,MBVPD_RECORD_VER0},
        {CVPD::MER0,MBVPD_RECORD_MER0},
        {CVPD::VSPD,MBVPD_RECORD_VSPD},
        {CVPD::VINI,MBVPD_RECORD_VINI},
        {CVPD::OPFR,MBVPD_RECORD_OPFR},
        {CVPD::VNDR,MBVPD_RECORD_VNDR},
        {CVPD::SPDX,MBVPD_RECORD_SPDX},
    };
    const uint8_t NUM_CVPD_RECORDS =
           sizeof(cvpdFapiRecordToHbRecord)/sizeof(cvpdFapiRecordToHbRecord[0]);

    fapi2::ReturnCode l_rc;

    uint8_t l_index = static_cast<uint8_t>(i_fapiRecord);

    if (l_index >= NUM_CVPD_RECORDS)
    {
        FAPI_ERR("MBvpdRecordXlate: Index went out of bounds looking for record: 0x%x", i_fapiRecord);
        /*@
         * @errortype
         * @moduleid         MOD_FAPI2_CVPD_ACCESS
         * @reasoncode       RC_RECORD_OUT_OF_BOUNDS
         * @userdata1        Record enumerator
         * @userdata2[0:31]  Index
         * @userdata2[32:63] Max Index
         * @devdesc          Attempt to read an CVPD field using
         *                   an invalid record
         * @custdesc         Firmware error during IPL
         */

        errlHndl_t l_errl = new ERRORLOG::ErrlEntry(
            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
            fapi2::MOD_FAPI2_CVPD_ACCESS,
            fapi2::RC_RECORD_OUT_OF_BOUNDS,
            i_fapiRecord,
            TWO_UINT32_TO_UINT64(l_index,
            NUM_CVPD_RECORDS),
            true);

        //Set the record index to INVALID
        //Don't set the data because we dont know anything about it
        o_recordIndex  = MBVPD_INVALID_CHIP_UNIT;

        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }


    if(!l_rc)
    {
        o_hbRecord    = cvpdFapiRecordToHbRecord[l_index].rec;
        o_recordIndex = cvpdFapiRecordToHbRecord[l_index].recIndex;
    }

    return l_rc;
}

//******************************************************************************
// CvpdKeywordXlate
// Translates a FAPI MBVPD Keyword enumerator into a Hostboot CVPD Keyword
// enumerator
//******************************************************************************
fapi2::ReturnCode CvpdKeywordXlate(const fapi2::MBvpdKeyword i_fapiKeyword,
                                   CVPD::cvpdKeyword & o_hbKeyword,
                                   uint8_t & o_keywordIndex)
{
    // Create a lookup table for converting a FAPI CVPD keyword enumerator to a
    // Hostboot CVPD keyword enumerator. This is a simple array and relies on
    // the FAPI keyword enumerators starting at zero and incrementing.
    struct cvpdKeywordToHb
    {
        CVPD::cvpdKeyword keyword;
        // This is the fapi2 Index to the CVPD Keyword
        uint8_t keywordIndex;
    };
    static const cvpdKeywordToHb cvpdFapiKeywordToHbKeyword[] =
    {
        {CVPD::pdI, MBVPD_KEYWORD_PDI},
        {CVPD::PF,  MBVPD_KEYWORD_PF},
        {CVPD::MT,  MBVPD_KEYWORD_MT},
        {CVPD::MR,  MBVPD_KEYWORD_MR},
        {CVPD::pdA, MBVPD_KEYWORD_PDA},
        {CVPD::EL,  MBVPD_KEYWORD_EL},
        {CVPD::LM,  MBVPD_KEYWORD_LM},
        {CVPD::MW,  MBVPD_KEYWORD_MW},
        {CVPD::MV,  MBVPD_KEYWORD_MV},
        {CVPD::AM,  MBVPD_KEYWORD_AM},
        {CVPD::VZ,  MBVPD_KEYWORD_VZ},
        {CVPD::pdD, MBVPD_KEYWORD_PDD},
        {CVPD::MX,  MBVPD_KEYWORD_MX},
        {CVPD::DW,  MBVPD_KEYWORD_DW},
        {CVPD::PN,  MBVPD_KEYWORD_PN},
        {CVPD::SN,  MBVPD_KEYWORD_SN},
        {CVPD::DR,  MBVPD_KEYWORD_DR},
        {CVPD::CE,  MBVPD_KEYWORD_CE},
        {CVPD::FN,  MBVPD_KEYWORD_FN},
        {CVPD::CC,  MBVPD_KEYWORD_CC},
        {CVPD::HE,  MBVPD_KEYWORD_HE},
        {CVPD::CT,  MBVPD_KEYWORD_CT},
        {CVPD::HW,  MBVPD_KEYWORD_HW},
        {CVPD::VD,  MBVPD_KEYWORD_VD},
        {CVPD::VN,  MBVPD_KEYWORD_VN},
        {CVPD::VP,  MBVPD_KEYWORD_VP},
        {CVPD::VS,  MBVPD_KEYWORD_SV},
        {CVPD::M0,  MBVPD_KEYWORD_M0},
        {CVPD::M1,  MBVPD_KEYWORD_M1},
        {CVPD::M2,  MBVPD_KEYWORD_M2},
        {CVPD::M3,  MBVPD_KEYWORD_M3},
        {CVPD::M4,  MBVPD_KEYWORD_M4},
        {CVPD::M5,  MBVPD_KEYWORD_M5},
        {CVPD::M6,  MBVPD_KEYWORD_M6},
        {CVPD::M7,  MBVPD_KEYWORD_M7},
        {CVPD::M8,  MBVPD_KEYWORD_M8},
        {CVPD::T1,  MBVPD_KEYWORD_T1},
        {CVPD::T2,  MBVPD_KEYWORD_T2},
        {CVPD::T4,  MBVPD_KEYWORD_T4},
        {CVPD::T5,  MBVPD_KEYWORD_T5},
        {CVPD::T6,  MBVPD_KEYWORD_T6},
        {CVPD::T8,  MBVPD_KEYWORD_T8},
        {CVPD::Q0,  MBVPD_KEYWORD_Q0},
        {CVPD::Q1,  MBVPD_KEYWORD_Q1},
        {CVPD::Q2,  MBVPD_KEYWORD_Q2},
        {CVPD::Q3,  MBVPD_KEYWORD_Q3},
        {CVPD::Q4,  MBVPD_KEYWORD_Q4},
        {CVPD::Q5,  MBVPD_KEYWORD_Q5},
        {CVPD::Q6,  MBVPD_KEYWORD_Q6},
        {CVPD::Q7,  MBVPD_KEYWORD_Q7},
        {CVPD::Q8,  MBVPD_KEYWORD_Q8},
        {CVPD::K0,  MBVPD_KEYWORD_K0},
        {CVPD::K1,  MBVPD_KEYWORD_K1},
        {CVPD::K2,  MBVPD_KEYWORD_K2},
        {CVPD::K3,  MBVPD_KEYWORD_K3},
        {CVPD::K4,  MBVPD_KEYWORD_K4},
        {CVPD::K5,  MBVPD_KEYWORD_K5},
        {CVPD::K6,  MBVPD_KEYWORD_K6},
        {CVPD::K7,  MBVPD_KEYWORD_K7},
        {CVPD::K8,  MBVPD_KEYWORD_K8},
        {CVPD::MM,  MBVPD_KEYWORD_MM},
        {CVPD::SS,  MBVPD_KEYWORD_SS},
        {CVPD::ET,  MBVPD_KEYWORD_ET},
        {CVPD::VM,  MBVPD_KEYWORD_VM},
        {CVPD::pd1, MBVPD_KEYWORD_PD1},
        {CVPD::pdZ, MBVPD_KEYWORD_PDZ},
        {CVPD::pd4, MBVPD_KEYWORD_PD4},
        {CVPD::pd5, MBVPD_KEYWORD_PD5},
        {CVPD::pd6, MBVPD_KEYWORD_PD6},
        {CVPD::pd8, MBVPD_KEYWORD_PD8},
        {CVPD::pdY, MBVPD_KEYWORD_PDY},
    };
    const uint8_t NUM_CVPD_KEYWORDS =
       sizeof(cvpdFapiKeywordToHbKeyword)/sizeof(cvpdFapiKeywordToHbKeyword[0]);

    fapi2::ReturnCode l_rc;

    uint8_t l_index = static_cast<uint8_t>(i_fapiKeyword);



    if (l_index >= NUM_CVPD_KEYWORDS)
    {
        FAPI_ERR("CvpdKeywordXlate: Index went out of bounds looking for keyword: 0x%x", i_fapiKeyword);
        /*@
         * @errortype
         * @moduleid         MOD_FAPI2_CVPD_ACCESS
         * @reasoncode       RC_KEYWORD_OUT_OF_BOUNDS
         * @userdata1        Keyword enumerator
         * @userdata2[0:31]  Index
         * @userdata2[32:63] Max Index
         * @devdesc          Attempt to read an CVPD field using
         *                   an invalid keyword
         * @custdesc         Firmware error during IPL
         */

        errlHndl_t l_errl = new ERRORLOG::ErrlEntry(
            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
            fapi2::MOD_FAPI2_CVPD_ACCESS,
            fapi2::RC_KEYWORD_OUT_OF_BOUNDS,
            i_fapiKeyword,
            TWO_UINT32_TO_UINT64(l_index,
            NUM_CVPD_KEYWORDS),
            true);

        //Set the keyword index to INVALID
        //Don't set the data because we dont know anything about it
        o_keywordIndex  = MBVPD_INVALID_CHIP_UNIT;

        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }

    if(!l_rc)
    {
        o_hbKeyword    = cvpdFapiKeywordToHbKeyword[l_index].keyword;
        o_keywordIndex = cvpdFapiKeywordToHbKeyword[l_index].keywordIndex;
    }

    return l_rc;
}

//******************************************************************************
// getMvpdField
//******************************************************************************
fapi2::ReturnCode getMBvpdField
                (const fapi2::MBvpdRecord  i_record,
                 const fapi2::MBvpdKeyword i_keyword,
                 const fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> &i_target,
                 uint8_t * const i_pBuffer,
                 size_t& io_fieldSize)
{
    uint8_t l_recIndex = MBVPD_INVALID_CHIP_UNIT;
    uint8_t l_keyIndex = MBVPD_INVALID_CHIP_UNIT;
    errlHndl_t l_errl = NULL;
    fapi2::ReturnCode l_rc;
    FAPI_DBG("getMBvpdField entry");

    do
    {
        // Translate the FAPI record to a Hostboot record
        CVPD::cvpdRecord l_hbRecord = CVPD::CVPD_INVALID_RECORD;

        l_rc = fapi2::CvpdRecordXlate(i_record, l_hbRecord, l_recIndex);

        if (l_rc)
        {
            break;
        }

        // Translate the FAPI keyword to a Hostboot keyword
        CVPD::cvpdKeyword l_hbKeyword = CVPD::CVPD_INVALID_KEYWORD;

        l_rc = fapi2::CvpdKeywordXlate(i_keyword, l_hbKeyword, l_keyIndex);

        if (l_rc)
        {
            break;
        }

        // deviceRead will return the size of the field if the
        // pointer is NULL
        size_t l_fieldLen = io_fieldSize;

        l_errl = deviceRead(
                reinterpret_cast< TARGETING::Target*>(i_target.get()),
                i_pBuffer,
                l_fieldLen,
                DEVICE_CVPD_ADDRESS(l_hbRecord, l_hbKeyword));

        if (l_errl)
        {
            FAPI_ERR("getMBvpdField: ERROR: deviceRead : errorlog PLID=0x%x",
                    l_errl->plid());

            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));

            break;
        }

        // Success, update callers io_fieldSize for the case where the
        // pointer is NULL and deviceRead returned the actual size
        io_fieldSize = l_fieldLen;

        FAPI_DBG("getMBvpdField: returning field len=0x%x", io_fieldSize);

    } while(0);

    if( l_rc)
    {
        io_fieldSize = 0;
    }

    FAPI_DBG( "getMBvpdField: exit" );

    return  l_rc;
}

//******************************************************************************
// setMBvpdField
//******************************************************************************
fapi2::ReturnCode setMBvpdField
                (const fapi2::MBvpdRecord i_record,
                 const fapi2::MBvpdKeyword i_keyword,
                 const fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> &i_target,
                 const uint8_t * const i_pBuffer,
                 const size_t i_fieldSize)
{
    fapi2::ReturnCode l_rc;
    uint8_t l_recIndex = MBVPD_INVALID_CHIP_UNIT;
    uint8_t l_keyIndex = MBVPD_INVALID_CHIP_UNIT;
    errlHndl_t l_errl = NULL;
    FAPI_DBG("setMBvpdField entry");

    do
    {
        // Translate the FAPI record to a Hostboot record
        CVPD::cvpdRecord l_hbRecord = CVPD::CVPD_INVALID_RECORD;

        l_rc = fapi2::CvpdRecordXlate(i_record, l_hbRecord, l_recIndex);

        if (l_rc)
        {
            break;
        }

        // Translate the FAPI keyword to a Hostboot keyword
        CVPD::cvpdKeyword l_hbKeyword = CVPD::CVPD_INVALID_KEYWORD;

        l_rc = fapi2::CvpdKeywordXlate(i_keyword, l_hbKeyword, l_keyIndex);

        if (l_rc)
        {
            break;
        }

        size_t l_fieldLen = i_fieldSize;

        l_errl = deviceWrite(
                reinterpret_cast< TARGETING::Target*>(i_target.get()),
                const_cast<uint8_t *>(i_pBuffer),
                l_fieldLen,
                DEVICE_CVPD_ADDRESS(l_hbRecord, l_hbKeyword));

    } while(0);

    if (l_errl)
    {
        FAPI_ERR("setMBvpdField: ERROR: deviceWrite : errorlog PLID=0x%x",
                l_errl->plid());

        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));

    }

    FAPI_DBG( "setMBvpdField: exit" );

    return  l_rc;
}

} // fapi2

OpenPOWER on IntegriCloud