summaryrefslogtreecommitdiffstats
path: root/src/import/generic/memory/lib/data_engine/pre_data_init.H
blob: aa061a530e87ab0ff6dbd6a87d78e981ccb77a79 (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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/generic/memory/lib/data_engine/pre_data_init.H $   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 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                                                     */

///
/// @file pre_data_init.H
/// @brief Class to set preliminary eff_config attributes
///
// *HWP HWP Owner: Andre Marin <aamarin@us.ibm.com>
// *HWP FW Owner: Stephen Glancy <sglancy@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: CI

#ifndef _MSS_PRE_DATA_INIT_H_
#define _MSS_PRE_DATA_INIT_H_

#include <cstring>
#include <fapi2.H>
#include <generic/memory/lib/spd/spd_facade.H>
#include <generic/memory/lib/utils/find.H>
#include <generic/memory/lib/utils/shared/mss_generic_consts.H>

namespace mss
{

///
/// @brief enum list of preliminary data fields
///
enum pre_data_init_fields
{
    DIMM_TYPE,
    DRAM_GEN,
    HYBRID,
    HYBRID_MEDIA,
    MRANKS,
    DIMM_RANKS_CNFG,
};

///
/// @brief Traits for pre_data_engine
/// @class preDataInitTraits
/// @tparam T proc_type (e.g. Nimbus, Axone, etc.)
/// @tparam TT pre_data_init_fields (e.g. DIMM_TYPE, MRANK, etc.)
///
template< proc_type T, pre_data_init_fields TT >
class preDataInitTraits;

///
/// @brief Traits for pre_data_engine
/// @class preDataInitTraits
/// @note NIMBUS, DIMM_TYPE specialization
///
template<>
class preDataInitTraits<NIMBUS, DIMM_TYPE>
{
    public:
        using attr_type = fapi2::ATTR_EFF_DIMM_TYPE_Type;
        static const fapi2::TargetType TARGET_TYPE = fapi2::ATTR_EFF_DIMM_TYPE_TargetType;

        ///
        /// @brief attribute getter
        /// @param[in] i_target the MCS target
        /// @param[out] o_setting array to populate
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode get_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          attr_type& o_setting)
        {
            FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_EFF_DIMM_TYPE, i_target, o_setting) );

        fapi_try_exit:
            return fapi2::current_err;
        }

        ///
        /// @brief attribute setter
        /// @param[in] i_target the MCS target
        /// @param[in] i_setting array to set
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode set_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          const attr_type& i_setting)
        {
            attr_type l_data = {};
            memcpy(l_data, i_setting, sizeof(l_data));
            FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_EFF_DIMM_TYPE, i_target, l_data) );

        fapi_try_exit:
            return fapi2::current_err;
        }
};

///
/// @brief Traits for pre_data_engine
/// @class preDataInitTraits
/// @note NIMBUS, DRAM_GEN specialization
///
template<>
class preDataInitTraits<NIMBUS, DRAM_GEN>
{
    public:
        using attr_type = fapi2::ATTR_EFF_DRAM_GEN_Type;
        static const fapi2::TargetType TARGET_TYPE = fapi2::ATTR_EFF_DRAM_GEN_TargetType;

        ///
        /// @brief attribute getter
        /// @param[in] i_target the MCS target
        /// @param[out] o_setting array to populate
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode get_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          attr_type& o_setting)
        {
            FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_EFF_DRAM_GEN, i_target, o_setting) );

        fapi_try_exit:
            return fapi2::current_err;
        }

        ///
        /// @brief attribute setter
        /// @param[in] i_target the MCS target
        /// @param[in] i_setting array to set
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode set_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          const attr_type& i_setting)
        {
            attr_type l_data = {};
            memcpy(l_data, i_setting, sizeof(l_data));

            FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_EFF_DRAM_GEN, i_target, l_data) );

        fapi_try_exit:
            return fapi2::current_err;
        }
};

///
/// @brief Traits for pre_data_engine
/// @class preDataInitTraits
/// @note NIMBUS, HYBRID specialization
///
template<>
class preDataInitTraits<NIMBUS, HYBRID>
{
    public:
        using attr_type = fapi2::ATTR_EFF_HYBRID_Type;
        static const fapi2::TargetType TARGET_TYPE = fapi2::ATTR_EFF_HYBRID_TargetType;

        ///
        /// @brief attribute getter
        /// @param[in] i_target the MCS target
        /// @param[out] o_setting array to populate
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode get_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          attr_type& o_setting)
        {
            FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_EFF_HYBRID, i_target, o_setting) );

        fapi_try_exit:
            return fapi2::current_err;
        }

        ///
        /// @brief attribute setter
        /// @param[in] i_target the MCS target
        /// @param[in] i_setting array to set
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode set_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          const attr_type& i_setting)
        {
            attr_type l_data = {};
            memcpy(l_data, i_setting, sizeof(l_data));

            FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_EFF_HYBRID, i_target, l_data) );

        fapi_try_exit:
            return fapi2::current_err;
        }
};

///
/// @brief Traits for pre_data_engine
/// @class preDataInitTraits
/// @note NIMBUS, HYBRID_MEDIA specialization
///
template<>
class preDataInitTraits<NIMBUS, HYBRID_MEDIA>
{
    public:
        using attr_type = fapi2::ATTR_EFF_HYBRID_MEMORY_TYPE_Type;
        static const fapi2::TargetType TARGET_TYPE = fapi2::ATTR_EFF_HYBRID_MEMORY_TYPE_TargetType;

        ///
        /// @brief attribute getter
        /// @param[in] i_target the MCS target
        /// @param[out] o_setting array to populate
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode get_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          attr_type& o_setting)
        {
            FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_EFF_HYBRID_MEMORY_TYPE, i_target, o_setting) );

        fapi_try_exit:
            return fapi2::current_err;
        }

        ///
        /// @brief attribute setter
        /// @param[in] i_target the MCS target
        /// @param[in] i_setting array to set
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode set_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          const attr_type& i_setting)
        {
            attr_type l_data = {};
            memcpy(l_data, i_setting, sizeof(l_data));

            FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_EFF_HYBRID_MEMORY_TYPE, i_target, l_data) );

        fapi_try_exit:
            return fapi2::current_err;
        }
};

///
/// @brief Traits for pre_data_engine
/// @class preDataInitTraits
/// @note NIMBUS, MRANKS specialization
///
template<>
class preDataInitTraits<NIMBUS, MRANKS>
{
    public:
        using attr_type = fapi2::ATTR_EFF_NUM_MASTER_RANKS_PER_DIMM_Type;
        static const fapi2::TargetType TARGET_TYPE = fapi2::ATTR_EFF_NUM_MASTER_RANKS_PER_DIMM_TargetType;

        ///
        /// @brief attribute getter
        /// @param[in] i_target the MCS target
        /// @param[out] o_setting array to populate
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode get_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          attr_type& o_setting)
        {
            FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_EFF_NUM_MASTER_RANKS_PER_DIMM, i_target, o_setting) );

        fapi_try_exit:
            return fapi2::current_err;
        }

        ///
        /// @brief attribute setter
        /// @param[in] i_target the MCS target
        /// @param[in] i_setting array to set
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode set_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          const attr_type& i_setting)
        {
            attr_type l_data = {};
            memcpy(l_data, i_setting, sizeof(l_data));

            FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_EFF_NUM_MASTER_RANKS_PER_DIMM, i_target, l_data) );

        fapi_try_exit:
            return fapi2::current_err;
        }
};

///
/// @brief Traits for pre_data_engine
/// @class preDataInitTraits
/// @note NIMBUS, DIMM_RANKS_CNFG specialization
///
template<>
class preDataInitTraits<NIMBUS, DIMM_RANKS_CNFG>
{
    public:
        using attr_type = fapi2::ATTR_EFF_DIMM_RANKS_CONFIGED_Type;
        static const fapi2::TargetType TARGET_TYPE = fapi2::ATTR_EFF_NUM_MASTER_RANKS_PER_DIMM_TargetType;

        ///
        /// @brief attribute getter
        /// @param[in] i_target the MCS target
        /// @param[out] o_setting array to populate
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode get_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          attr_type& o_setting)
        {
            FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_EFF_DIMM_RANKS_CONFIGED, i_target, o_setting) );

        fapi_try_exit:
            return fapi2::current_err;
        }

        ///
        /// @brief attribute setter
        /// @param[in] i_target the MCS target
        /// @param[in] i_setting array to set
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        static fapi2::ReturnCode set_attr(const fapi2::Target<TARGET_TYPE>& i_target,
                                          const attr_type& i_setting)
        {
            attr_type l_data = {};
            memcpy(l_data, i_setting, sizeof(l_data));

            FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_EFF_DIMM_RANKS_CONFIGED, i_target, l_data) );

        fapi_try_exit:
            return fapi2::current_err;
        }
};

///
/// @brief Helper function for attribute setting
/// @tparam T processor type (e.g. NIMBUS, AXONE, etc.)
/// defaulted to NIMBUS
/// @tparam X size of 1st array index
/// @tparam Y size of 2nd array index
/// @tparam TT FAPI2 target type
/// @tparam IT Input/outpu data type
/// @param[in] i_target the MCS target
/// @param[in] i_setting array to set
/// @param[out] o_data attribute data structure to set
/// @warning This is Nimbus specific
///
template < size_t X, size_t Y, typename IT >
void data_setter( const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
                  const IT i_setting,
                  IT (&o_data)[X][Y])
{
    const size_t l_port_index = mss::index( find_target<fapi2::TARGET_TYPE_MCA>(i_target) );
    const size_t l_dimm_index = mss::index(i_target);

    o_data[l_port_index][l_dimm_index] = i_setting;
}

///
/// @brief Mapping boilerplate check
/// @tparam T FAPI2 target type
/// @tparam IT map key type
/// @tparam OT map value type
/// @param[in] i_map SPD to attribute data mapping
/// @param[in] i_ffdc_code FFDC function code
/// @param[in] i_key Key to query map
/// @param[out] o_output value from key
///
template< fapi2::TargetType T, typename IT, typename OT >
fapi2::ReturnCode lookup_table_check(const fapi2::Target<T>& i_target,
                                     const std::vector<std::pair<IT, OT>>& i_map,
                                     const generic_ffdc_codes i_ffdc_code,
                                     const IT i_key,
                                     OT& o_output)
{
    const bool l_is_val_found = mss::find_value_from_key(i_map, i_key, o_output);

    FAPI_ASSERT( l_is_val_found,
                 fapi2::MSS_LOOKUP_FAILED()
                 .set_KEY(i_key)
                 .set_DATA(o_output)
                 .set_FUNCTION(i_ffdc_code)
                 .set_TARGET(i_target),
                 "Failed to find a mapped value for %d on %s",
                 i_key,
                 spd::c_str(i_target) );
fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Sets preliminary data fields
/// @tparam P processor type (e.g. NIMBUS, AXONE, etc.)
/// @tparam F pre_data_init_fields
/// @tparam T FAPI2 target type
/// @tparam IT Input data type
/// @tparam TT defaulted to preDataInitTraits<T>
/// @param[in] i_setting value we want to set attr with
/// @return FAPI2_RC_SUCCESS iff okay
///
template< proc_type P,
          pre_data_init_fields F,
          fapi2::TargetType T,
          typename IT,
          typename TT = preDataInitTraits<P, F>
          >
fapi2::ReturnCode set_field(const fapi2::Target<T>& i_target, const IT i_setting)
{
    const auto l_target = mss::find_target<TT::TARGET_TYPE>(i_target);
    typename TT::attr_type l_attr_list = {};
    IT l_mapping_value = i_setting;

    FAPI_TRY( TT::get_attr(l_target, l_attr_list) );

    // Indexing isn't very general
    data_setter(i_target, l_mapping_value, l_attr_list);

    FAPI_TRY( TT::set_attr(l_target, l_attr_list) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Data structure to set pre-effective config data
/// @class pre_data_engine
/// @tparam T supported processor type (e.g. Nimbus, Axone, etc.)
///
template< proc_type T >
class pre_data_engine;

///
/// @brief Data structure to set pre-effective config data
/// @class pre_data_engine
/// @note NIMBUS specialization
///
template< >
class pre_data_engine< NIMBUS >
{
    private:

        fapi2::Target<fapi2::TARGET_TYPE_DIMM> iv_dimm;
        uint8_t iv_master_ranks;
        spd::facade iv_spd_data;
        size_t iv_port_index;
        size_t iv_dimm_index;

    public:

        static const std::vector<std::pair<uint8_t, uint8_t> > NUM_PACKAGE_RANKS_MAP;
        static const std::vector<std::pair<uint8_t, uint8_t> > BASE_MODULE_TYPE_MAP;
        static const std::vector<std::pair<uint8_t, uint8_t> > DRAM_GEN_MAP;
        static const std::vector<std::pair<uint8_t, uint8_t> > HYBRID_MAP;
        static const std::vector<std::pair<uint8_t, uint8_t> > HYBRID_MEMORY_TYPE_MAP;

        ///
        /// @brief ctor
        /// @param[in] i_target the DIMM target
        /// @param[in] i_spd_data SPD decoder
        /// @param[out] o_rc ReturnCode for failure to init object
        ///
        pre_data_engine(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
                        const spd::facade& i_spd_data,
                        fapi2::ReturnCode& o_rc);

        ///
        /// @brief default dtor
        ///
        ~pre_data_engine() = default;

        ///
        /// @brief Set ATTR_EFF_DIMM_TYPE
        /// @return FAPI2_RC_SUCCESS iff ok
        ///
        fapi2::ReturnCode set_dimm_type();

        ///
        /// @brief Set ATTR_EFF_DRAM_GEN
        /// @return FAPI2_RC_SUCCESS iff ok
        ///
        fapi2::ReturnCode set_dram_gen();

        ///
        /// @brief Set ATTR_EFF_HYBRID
        /// @return FAPI2_RC_SUCCESS iff ok
        ///
        fapi2::ReturnCode set_hybrid();

        ///
        /// @brief Set ATTR_EFF_HYBRID_MEMORY_TYPE
        /// @return FAPI2_RC_SUCCESS iff ok
        ///
        fapi2::ReturnCode set_hybrid_media();

        ///
        /// @brief Set ATTR_EFF_NUM_MASTER_RANKS_PER_DIMM
        /// @return FAPI2_RC_SUCCESS iff ok
        ///
        fapi2::ReturnCode set_master_ranks();

        ///
        /// @brief Sets ATTR_EFF_DIMM_RANKS_CONFIGED
        /// @return FAPI2_RC_SUCCESS iff okay
        ///
        fapi2::ReturnCode set_dimm_ranks_configured();
};

}//mss

#endif
OpenPOWER on IntegriCloud