summaryrefslogtreecommitdiffstats
path: root/src/import/generic/memory/lib/spd/spd_checker.H
blob: 50e6ef3472dc911161630caabaad7358a8f88f12 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/generic/memory/lib/spd/spd_checker.H $             */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017,2019                        */
/* [+] Evan Lojewski                                                      */
/* [+] 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 spd_checker.H
/// @brief SPD functions to check boundaries
///
// *HWP HWP Owner: Andre Marin <aamarin@us.ibm.com>
// *HWP HWP Backup: Stephen Glancy <sglancy@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 3
// *HWP Consumed by: HB:FSP

#ifndef _SPD_CHECKER_H_
#define _SPD_CHECKER_H_

#include <fapi2.H>
#include <generic/memory/lib/utils/shared/mss_generic_consts.H>
#include <generic/memory/lib/utils/c_str.H>

namespace mss
{

///
/// @brief Selectors for timing limits
/// @note BITS12 stands for a 12 bit range
/// @note BITS16 stands for a 16 bit range
///
enum bit_len
{
    BITS12 = 12,
    BITS16 = 16,
};

///
/// @class bitRangeTraits
/// @brief Traits class to select
/// @tparam T bit_len selector
///
template <bit_len T>
struct bitRangeTraits;

///
/// @class bitRangeTraits
/// @brief Traits class to select - BITS12 specialization
///
template<>
struct bitRangeTraits<BITS12>
{
    enum
    {
        LOWER_BOUND = 0x1,
        UPPER_BOUND = 0xfff,
    };
};

///
/// @class bitRangeTraits
/// @brief Traits class to select - BITS16 specialization
///
template<>
struct bitRangeTraits<BITS16>
{
    enum
    {
        LOWER_BOUND = 0x1,
        UPPER_BOUND = 0xffff,
    };
};

namespace spd
{
namespace check
{

///
/// @brief SPD timing boundary check
/// @tparam BL bit_len selector
/// @tparam T the TargetType
/// @tparam TT defaulted to bitRangeTraits<TB>
/// @param[in] i_target fapi2 target
/// @param[in] i_timing the timing value
/// @param[in] i_rev the SPD revision that needs to be checked
/// @param[in] i_ffdc ffdc function code
/// @return FAPI2_RC_SUCCESS iff okay
///
template < bit_len BL, fapi2::TargetType T, typename TT = bitRangeTraits<BL> >
fapi2::ReturnCode max_timing_range(const fapi2::Target<T>& i_target,
                                   const int64_t i_timing,
                                   const rev i_rev,
                                   const generic_ffdc_codes i_ffdc)
{
    FAPI_ASSERT( (i_timing <= TT::UPPER_BOUND) &&
                 (i_timing >= TT::LOWER_BOUND),
                 fapi2::MSS_SPD_TIMING_FAIL()
                 .set_FAILED_REVISION(i_rev)
                 .set_FUNCTION_CODE(i_ffdc)
                 .set_TARGET(i_target),
                 "Failed timing parameter check for %s",
                 spd::c_str(i_target));

    return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Helper function to test if a DRAM generation is valid
/// @param[in] i_dram_gen the DRAM gen from SPD
/// @return true if this DRAM gen is valid, else false
///
static inline bool is_dram_gen_valid(const uint8_t i_dram_gen)
{
    bool l_result = false;

    switch(i_dram_gen)
    {
        case DDR4:
            l_result = true;
            break;

        default:
            l_result = false;
            break;
    }

    return l_result;
}

///
/// @brief Checks for valid DRAM generation
/// @param[in] i_target the DIMM target
/// @param[in] i_dram_gen the DRAM gen from SPD
/// @param[in] i_func_code mss ffdc code
/// @return FAPI2_RC_SUCCESS iff okay
///
inline fapi2::ReturnCode dram_gen(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
                                  const uint8_t i_dram_gen,
                                  const generic_ffdc_codes i_func_code)
{
    FAPI_ASSERT(is_dram_gen_valid(i_dram_gen),
                fapi2::MSS_INVALID_DRAM_GEN()
                .set_DRAM_GEN(i_dram_gen)
                .set_FUNCTION(i_func_code)
                .set_DIMM_TARGET(i_target),
                "Invalid DRAM gen recieved (%d) for %s",
                i_dram_gen, spd::c_str(i_target));

    return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Helper function to test if a DIMM type is valid
/// @param[in] i_dimm_type the DIMM type from SPD
/// @return true if this DIMM type is valid, else false
///
static inline bool is_dimm_type_valid(const uint8_t i_dimm_type)
{
    bool l_result = false;

    switch(i_dimm_type)
    {
        case RDIMM:
        case LRDIMM:
        case DDIMM:
        case SORDIMM:
        case MINIRDIMM:
            l_result = true;
            break;

        default:
            l_result = false;
            break;
    }

    return l_result;
}

///
/// @brief Checks for valid DIMM type
/// @param[in] i_target the DIMM target
/// @param[in] i_dram_gen the DIMM type from SPD
/// @param[in] i_func_code mss ffdc code
/// @return FAPI2_RC_SUCCESS iff okay
///
inline fapi2::ReturnCode dimm_type(const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target,
                                   const uint8_t i_dimm_type,
                                   const generic_ffdc_codes i_func_code)
{
    FAPI_ASSERT(is_dimm_type_valid(i_dimm_type),
                fapi2::MSS_INVALID_DIMM_TYPE()
                .set_DIMM_TYPE(i_dimm_type)
                .set_FUNCTION(i_func_code)
                .set_DIMM_TARGET(i_target),
                "Invalid DIMM type recieved (%d) for %s",
                i_dimm_type, DDIMM, spd::c_str(i_target));

    return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Helper function to check for reserved values
/// @tparam TT FAPI2 target type
/// @param[in] i_target the fapi2 target
/// @param[in] i_reserved_bits vector of SORTED reserved bits to sort through
/// @param[in] i_ffdc ffdc function code
/// @param[in] i_input value to check
/// @return FAPI2_RC_SUCCESS iff okay
///
template < fapi2::TargetType TT >
inline fapi2::ReturnCode reserved_values(const fapi2::Target<TT>& i_target,
        const std::vector<uint8_t>& i_reserved_bits,
        const generic_ffdc_codes i_ffdc,
        const uint8_t i_input)
{
    // Lets make an additional check that we aren't being set to a reserved field
    FAPI_ASSERT( !std::binary_search(i_reserved_bits.begin(), i_reserved_bits.end(), i_input),
                 fapi2::MSS_INVALID_SPD_RESERVED_BITS()
                 .set_FUNCTION_CODE(i_ffdc)
                 .set_TARGET(i_target),
                 "Reserved bits seen on %s",
                 spd::c_str(i_target) );

    return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
    return fapi2::current_err;
}

}// check
}// spd
}// mss

#endif
OpenPOWER on IntegriCloud