summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/plat/fapiPlatMBvpdAccess.C
blob: 184093b4be9a7a2ce3b80b27d76048ce8f868f6c (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/plat/fapiPlatMBvpdAccess.C $                     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2013,2015                        */
/* [+] 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 fapiPlatMBvpdAccess.C
 *
 *  @brief Implements the fapiMBvpdAccess.H functions
 */

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

//  fapi support
#include <isteps/hwpf_reasoncodes.H>
#include <fapiMBvpdAccess.H>

//  MBVPD
#include <devicefw/userif.H>
#include <vpd/cvpdenums.H>


namespace fapi
{

//******************************************************************************
// MBvpdRecordXlate
// Translates a FAPI MBVPD Record enumerator into a Hostboot MBVPD Record
// enumerator
//******************************************************************************
fapi::ReturnCode MBvpdRecordXlate(const fapi::MBvpdRecord i_fapiRecord,
                                 CVPD::cvpdRecord & o_hbRecord)
{
    // Create a lookup table for converting a FAPI MBVPD 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.
    static const CVPD::cvpdRecord
                  mbvpdFapiRecordToHbRecord[] =
    {
        CVPD::VEIR,
        CVPD::VER0,
        CVPD::MER0,
        CVPD::VSPD,
        CVPD::VINI,
        CVPD::OPFR,
        CVPD::VNDR,
        CVPD::SPDX,
    };
    const uint8_t NUM_MBVPD_RECORDS =
        sizeof(mbvpdFapiRecordToHbRecord)/sizeof(mbvpdFapiRecordToHbRecord[0]);

    fapi::ReturnCode l_rc;

    uint8_t l_index = static_cast<uint8_t>(i_fapiRecord);

    if (l_index >= NUM_MBVPD_RECORDS)
    {
        FAPI_ERR("MBvpdRecordXlate: Invalid MBVPD Record: 0x%x", i_fapiRecord);
        /*@
         * @errortype
         * @moduleid     MOD_MBVPD_ACCESS
         * @reasoncode   RC_INVALID_RECORD
         * @userdata1    Record enumerator
         * @devdesc      Attempt to read an MVPD field using an invalid record
         */
        const bool hbSwError = true;
        errlHndl_t l_errl = new ERRORLOG::ErrlEntry(
            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
            MOD_MBVPD_ACCESS,
            RC_INVALID_RECORD,
            i_fapiRecord, 0, hbSwError);

        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatError(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        o_hbRecord = mbvpdFapiRecordToHbRecord[l_index];
    }

    return l_rc;
}

//******************************************************************************
// MBvpdKeywordXlate
// Translates a FAPI MBVPD Keyword enumerator into a Hostboot CVPD Keyword
// enumerator
//******************************************************************************
fapi::ReturnCode MBvpdKeywordXlate(const fapi::MBvpdKeyword i_fapiKeyword,
                                  CVPD::cvpdKeyword & o_hbKeyword)
{
    // Create a lookup table for converting a FAPI MBVPD keyword enumerator to a
    // Hostboot CVPD keyword enumerator. This is a simple array and relies on
    // the FAPI record enumerators starting at zero and incrementing.
    static const CVPD::cvpdKeyword
        mbvpdFapiKeywordToHbKeyword[] =
    {
        CVPD::pdI,
        CVPD::PF,
        CVPD::MT,
        CVPD::MR,
        CVPD::pdA,
        CVPD::EL,
        CVPD::LM,
        CVPD::MW,
        CVPD::MV,
        CVPD::AM,
        CVPD::VZ,
        CVPD::pdD,
        CVPD::MX,
        CVPD::DW,
        CVPD::PN,
        CVPD::SN,
        CVPD::DR,
        CVPD::CE,
        CVPD::FN,
        CVPD::CC,
        CVPD::HE,
        CVPD::CT,
        CVPD::HW,
        CVPD::VD,
        CVPD::VN,
        CVPD::VP,
        CVPD::VS,
        CVPD::M0,
        CVPD::M1,
        CVPD::M2,
        CVPD::M3,
        CVPD::M4,
        CVPD::M5,
        CVPD::M6,
        CVPD::M7,
        CVPD::M8,
        CVPD::T1,
        CVPD::T2,
        CVPD::T4,
        CVPD::T5,
        CVPD::T6,
        CVPD::T8,
        CVPD::Q0,
        CVPD::Q1,
        CVPD::Q2,
        CVPD::Q3,
        CVPD::Q4,
        CVPD::Q5,
        CVPD::Q6,
        CVPD::Q7,
        CVPD::Q8,
        CVPD::K0,
        CVPD::K1,
        CVPD::K2,
        CVPD::K3,
        CVPD::K4,
        CVPD::K5,
        CVPD::K6,
        CVPD::K7,
        CVPD::K8,
        CVPD::MM,
        CVPD::SS,
        CVPD::ET,
        CVPD::VM,
        CVPD::pd1,
        CVPD::pdZ,
        CVPD::pd4,
        CVPD::pd5,
        CVPD::pd6,
        CVPD::pd8,
        CVPD::pdY,
    };
    const uint8_t NUM_MBVPD_KEYWORDS =
     sizeof(mbvpdFapiKeywordToHbKeyword)/sizeof(mbvpdFapiKeywordToHbKeyword[0]);

    fapi::ReturnCode l_rc;

    uint8_t l_index = static_cast<uint8_t>(i_fapiKeyword);

    if (l_index >= NUM_MBVPD_KEYWORDS)
    {
        FAPI_ERR("MbvpdKeywordXlate: Invalid MVPD Keyword: 0x%x",
                i_fapiKeyword);
        /*@
         * @errortype
         * @moduleid     MOD_MBVPD_ACCESS
         * @reasoncode   RC_INVALID_KEYWORD
         * @userdata1    Keyword enumerator
         * @devdesc      Attempt to read an MVPD field using an invalid keyword
         */
        const bool hbSwError = true;
        errlHndl_t l_errl = new ERRORLOG::ErrlEntry(
            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
            MOD_MBVPD_ACCESS,
            RC_INVALID_KEYWORD,
            i_fapiKeyword, 0, hbSwError);

        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatError(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        o_hbKeyword = mbvpdFapiKeywordToHbKeyword[l_index];
    }

    return l_rc;
}

}

extern "C"
{

//******************************************************************************
// fapiGetMBvpdField
//******************************************************************************
fapi::ReturnCode fapiGetMBvpdField(const fapi::MBvpdRecord i_record,
                                  const fapi::MBvpdKeyword i_keyword,
                                  const fapi::Target &i_memBufTarget,
                                  uint8_t * const i_pBuffer,
                                  uint32_t &io_fieldSize)
{
    fapi::ReturnCode l_rc;
    FAPI_DBG("fapiGetMBvpdField entry");

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

        l_rc = fapi::MBvpdRecordXlate(i_record, l_hbRecord);

        if (l_rc)
        {
            break;
        }

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

        l_rc = fapi::MBvpdKeywordXlate(i_keyword, l_hbKeyword);

        if (l_rc)
        {
            break;
        }

        // Similarly to this function, deviceRead will return the size of the
        // field if the pointer is NULL
        size_t l_fieldLen = io_fieldSize;

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

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

            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(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("fapGetMBvpdField: returning field len=0x%x", io_fieldSize);

    } while(0);

    FAPI_DBG( "fapGetMBvpdField: exit" );

    return  l_rc;
}

//******************************************************************************
// fapSetMBvpdField
//******************************************************************************
fapi::ReturnCode fapiSetMBvpdField(const fapi::MBvpdRecord i_record,
                                  const fapi::MBvpdKeyword i_keyword,
                                  const fapi::Target &i_memBufTarget,
                                  const uint8_t * const i_pBuffer,
                                  const uint32_t i_fieldSize)
{
    fapi::ReturnCode l_rc;
    FAPI_DBG("fapiSetMBvpdField entry");

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

        l_rc = fapi::MBvpdRecordXlate(i_record, l_hbRecord);

        if (l_rc)
        {
            break;
        }

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

        l_rc = fapi::MBvpdKeywordXlate(i_keyword, l_hbKeyword);

        if (l_rc)
        {
            break;
        }

        size_t l_fieldLen = i_fieldSize;

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

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

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

            break;
        }

    } while(0);

    FAPI_DBG( "fapSetMBvpdField: exit" );

    return  l_rc;
}

} // extern "C"
OpenPOWER on IntegriCloud