summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/lib/power_thermal/decoder.C
blob: 1013cbbfeec0c411596d3e9c6688603312084f12 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/power_thermal/decoder.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016                             */
/* [+] 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 decoder.C
/// @brief Decode MSS_MRW_PWR_CURVE_SLOPE, PWR_CURVE_INTERCEPT, and THERMAL_POWER_LIMIT
///
// *HWP HWP Owner: Jacob Harvey <jlharvey@us.ibm.com>
// *HWP HWP Backup: Brian Silver <bsilver@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

// fapi2
#include <fapi2.H>
#include <vector>
#include <utility>

// mss lib
#include <mss.H>
#include <lib/power_thermal/throttle.H>
#include <lib/power_thermal/decoder.H>
#include <lib/utils/find.H>
#include <lib/utils/c_str.H>
#include <lib/utils/count_dimm.H>
#include <lib/dimm/kind.H>


using fapi2::TARGET_TYPE_MCA;
using fapi2::TARGET_TYPE_MCS;
using fapi2::TARGET_TYPE_DIMM;
using fapi2::TARGET_TYPE_MCBIST;

namespace mss
{
namespace power_thermal
{

///
/// @brief generates the 32 bit encoding for the power curve attributes
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff the encoding was successful
/// @note populates iv_gen_keys
///
fapi2::ReturnCode decoder::generate_encoding()
{
    //DIMM_SIZE
    FAPI_TRY(( encode<DIMM_SIZE_START, DIMM_SIZE_LEN>
               (iv_kind.iv_target, iv_kind.iv_size, DIMM_SIZE_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DIMM_SIZE", iv_kind.iv_size, c_str(iv_kind.iv_target) );

    //DRAM_GEN
    FAPI_TRY(( encode<DRAM_GEN_START, DRAM_GEN_LEN>
               (iv_kind.iv_target, iv_kind.iv_dram_generation, DRAM_GEN_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DRAM_GEN", iv_kind.iv_dram_generation, c_str(iv_kind.iv_target) );

    //DIMM_TYPE
    FAPI_TRY(( encode<DIMM_TYPE_START, DIMM_TYPE_LEN>
               (iv_kind.iv_target, iv_kind.iv_dimm_type, DIMM_TYPE_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DIMM_TYPE", iv_kind.iv_dimm_type, c_str(iv_kind.iv_target) );

    //DRAM WIDTH
    FAPI_TRY(( encode<DRAM_WIDTH_START, DRAM_WIDTH_LEN>
               (iv_kind.iv_target, iv_kind.iv_dram_width, DRAM_WIDTH_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DRAM_WIDTH", iv_kind.iv_dram_width, c_str(iv_kind.iv_target) );

    //DRAM DENSITY
    FAPI_TRY(( encode<DRAM_DENSITY_START, DRAM_DENSITY_LEN>
               (iv_kind.iv_target, iv_kind.iv_dram_density, DRAM_DENSITY_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DRAM_DENSITY", iv_kind.iv_dram_density, c_str(iv_kind.iv_target) );

    //DRAM STACK TYPE
    FAPI_TRY(( encode<DRAM_STACK_TYPE_START, DRAM_STACK_TYPE_LEN>
               (iv_kind.iv_target, iv_kind.iv_stack_type, DRAM_STACK_TYPE_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DRAM_STACK_TYPE", iv_kind.iv_stack_type, c_str(iv_kind.iv_target) );

    //DRAM MFG ID
    FAPI_TRY(( encode<DRAM_MFGID_START, DRAM_MFGID_LEN>
               (iv_kind.iv_target, iv_kind.iv_mfgid, DRAM_MFGID_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DRAM_MFG_ID", iv_kind.iv_mfgid, c_str(iv_kind.iv_target) );

    //NUM DROPS PER PORT
    FAPI_TRY(( encode<DIMMS_PER_PORT_START, DIMMS_PER_PORT_LEN>
               (iv_kind.iv_target, iv_dimms_per_port, DIMMS_PORT_MAP, iv_gen_key)),
             "Failed to generate power thermal encoding for %s val %d on target: %s",
             "DIMMS_PER_PORT", iv_dimms_per_port, c_str(iv_kind.iv_target) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Finds a value for the power curve slope attributes by matching the generated hashes
/// @param[in] i_slope vector of generated key-values from POWER_CURVE_SLOPE
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff the encoding was successful
/// @note populates iv_vddr_slope, iv_total_slop
///
fapi2::ReturnCode decoder::find_slope (const std::vector<fapi2::buffer<uint64_t>>& i_slope)
{

    // Comparator lambda expression
    const auto compare = [this](const fapi2::buffer<uint64_t>& i_hash)
    {
        uint32_t l_temp = 0;
        i_hash.extractToRight<ENCODING_START, ENCODING_LENGTH>(l_temp);
        return ((l_temp & iv_gen_key) == iv_gen_key);
    };

    // Find iterator to matching key (if it exists)
    const auto l_value_iterator  =  std::find_if(i_slope.begin(),
                                    i_slope.end(),
                                    compare);

    //Should have matched with the all default ATTR at least
    //The last value should always be the default value
    FAPI_ASSERT(l_value_iterator != i_slope.end(),
                fapi2::MSS_NO_POWER_THERMAL_ATTR_FOUND()
                .set_GENERATED_KEY(iv_gen_key)
                .set_DIMM_TARGET(iv_kind.iv_target),
                "Couldn't find %s value for generated key:%016lx, for target %s. "
                "DIMM values for generated key are "
                "size is %d, gen is %d, type is %d, width is %d, density %d, stack %d, mfgid %d, dimms %d",
                "ATTR_MSS_MRW_POWER_CURVE_SLOPE",
                iv_gen_key,
                mss::c_str(iv_kind.iv_target),
                iv_kind.iv_size,
                iv_kind.iv_dram_generation,
                iv_kind.iv_dimm_type,
                iv_kind.iv_dram_width,
                iv_kind.iv_dram_density,
                iv_kind.iv_stack_type,
                iv_kind.iv_mfgid,
                iv_dimms_per_port);

    (*l_value_iterator).extractToRight<VDDR_START, VDDR_LENGTH>( iv_vddr_slope);
    (*l_value_iterator).extractToRight<TOTAL_START, TOTAL_LENGTH>(iv_total_slope);

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Finds a value for power curve intercept attributes by matching the generated hashes
/// @param[in] i_intercept vector of generated key-values for ATTR_MSS_MRW_POWER_CURVE_INTERCEPT
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff the encoding was successful
/// @note populates iv_vddr_intercept, iv_total_intercept
///
fapi2::ReturnCode decoder::find_intercept (const std::vector<fapi2::buffer<uint64_t>>& i_intercept)
{
    // Comparator lambda expression
    const auto compare = [this](const fapi2::buffer<uint64_t>& i_hash)
    {
        uint32_t l_temp = 0;
        i_hash.extractToRight<ENCODING_START, ENCODING_LENGTH>(l_temp);
        return ((l_temp & iv_gen_key) == iv_gen_key);
    };

    // Find iterator to matching key (if it exists)
    const auto l_value_iterator  =  std::find_if(i_intercept.begin(),
                                    i_intercept.end(),
                                    compare);

    //Should have matched with the all default ATTR at least
    //The last value should always be the default value
    FAPI_ASSERT(l_value_iterator != i_intercept.end(),
                fapi2::MSS_NO_POWER_THERMAL_ATTR_FOUND()
                .set_GENERATED_KEY(iv_gen_key)
                .set_DIMM_TARGET(iv_kind.iv_target),
                "Couldn't find %s value for generated key:%016lx, for target %s. "
                "DIMM values for generated key are "
                "size is %d, gen is %d, type is %d, width is %d, density %d, stack %d, mfgid %d, dimms %d",
                "ATTR_MSS_MRW_POWER_CURVE_INTERCEPT",
                iv_gen_key,
                mss::c_str(iv_kind.iv_target),
                iv_kind.iv_size,
                iv_kind.iv_dram_generation,
                iv_kind.iv_dimm_type,
                iv_kind.iv_dram_width,
                iv_kind.iv_dram_density,
                iv_kind.iv_stack_type,
                iv_kind.iv_mfgid,
                iv_dimms_per_port);

    (*l_value_iterator).extractToRight<VDDR_START, VDDR_LENGTH>( iv_vddr_intercept);
    (*l_value_iterator).extractToRight<TOTAL_START, TOTAL_LENGTH>(iv_total_intercept);

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Finds a value from ATTR_MSS_MRW_THERMAL_MEMORY_POWER_LIMIT and stores in iv variable
/// @param[in] i_thermal_limits is a vector of the generated values from ATTR_MSS_MRW_THERMAL_POWER_LIMIT
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff the encoding was successful
/// @note populates thermal_power_limit
///
fapi2::ReturnCode decoder::find_thermal_power_limit (const std::vector<fapi2::buffer<uint64_t>>& i_thermal_limits)
{
    // Comparator lambda expression
    const auto compare = [this](const fapi2::buffer<uint64_t>& i_hash)
    {
        uint32_t l_temp = 0;
        i_hash.extractToRight<ENCODING_START, ENCODING_LENGTH>(l_temp);
        return ((l_temp & iv_gen_key) == iv_gen_key);
    };

    // Find iterator to matching key (if it exists)
    const auto l_value_iterator  =  std::find_if(i_thermal_limits.begin(),
                                    i_thermal_limits.end(),
                                    compare);

    //Should have matched with the all default ATTR at least
    //The last value should always be the default value
    FAPI_ASSERT(l_value_iterator != i_thermal_limits.end(),
                fapi2::MSS_NO_POWER_THERMAL_ATTR_FOUND()
                .set_GENERATED_KEY(iv_gen_key)
                .set_DIMM_TARGET(iv_kind.iv_target),
                "Couldn't find %s value for generated key:%016lx, for target %s. "
                "DIMM values for generated key are "
                "size is %d, gen is %d, type is %d, width is %d, density %d, stack %d, mfgid %d, dimms %d",
                "ATTR_MSS_MRW_THERMAL_POWER_LIMIT",
                iv_gen_key,
                mss::c_str(iv_kind.iv_target),
                iv_kind.iv_size,
                iv_kind.iv_dram_generation,
                iv_kind.iv_dimm_type,
                iv_kind.iv_dram_width,
                iv_kind.iv_dram_density,
                iv_kind.iv_stack_type,
                iv_kind.iv_mfgid,
                iv_dimms_per_port);

    (*l_value_iterator).extractToRight<THERMAL_POWER_START, THERMAL_POWER_LENGTH>( iv_thermal_power_limit);

fapi_try_exit:
    return fapi2::current_err;
}

} //ns power_thermal
} // ns mss
OpenPOWER on IntegriCloud