summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/pm/p9_pm_get_poundv_bucket.C
blob: dcb719187e1273bb7c7ed0a3497f12dd0b581c6b (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: chips/p9/procedures/hwp/pm/p9_pm_get_poundv_bucket.C $        */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* EKB Project                                                            */
/*                                                                        */
/* COPYRIGHT 2015,2016                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_pm_get_poundv_bucket.C
/// @brief Grab PM data from certain bucket in #V keyword in LRPX record
///

// ----------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------
#include <p9_pm_get_poundv_bucket.H>
#include <mvpd_access_defs.H>
#include <attribute_ids.H>

fapi2::ReturnCode p9_pm_get_poundv_bucket(
    const fapi2::Target<fapi2::TARGET_TYPE_EQ>& i_target,
    fapi2::voltageBucketData_t& o_data)
{
    FAPI_IMP("Entering p9_pm_get_poundv_bucket ....");


    //Create a pointer version of the out param o_data so that
    // we can access bytes individually
    uint8_t* l_tempBuffer = reinterpret_cast<uint8_t*>(malloc(sizeof(o_data)));

    //Set up a char array to hold the bucket data from an attr read
    fapi2::ATTR_POUNDV_BUCKET_DATA_Type l_bucketAttr;

    //Perform an ATTR_GET for POUNDV_BUCKET data on the EQ target
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_POUNDV_BUCKET_DATA,
                           i_target,
                           l_bucketAttr));


#ifndef _BIG_ENDIAN
    //The first byte is simply a uint8 that describes the bucket ID
    l_tempBuffer[0] = l_bucketAttr[0];

    //Skipping the first byte (which has already been taken of) start reading
    //the voltage data 2 bytes at a time.
    for(uint8_t offset = 1; offset < sizeof(o_data); offset += 2)
    {
        //Switch from Big Endian to Little Endian
        l_tempBuffer[offset] = l_bucketAttr[offset + 1];
        l_tempBuffer[offset + 1] = l_bucketAttr[offset];
    }

    memcpy(&o_data,
           l_tempBuffer,
           sizeof(o_data));

#else
    memcpy(&o_data,
           l_bucketAttr,
           sizeof(o_data));
#endif


fapi_try_exit:
    free(l_tempBuffer);
    FAPI_IMP("Exiting p9_pm_get_poundv_bucket ....");

    return fapi2::current_err;
}

fapi2::ReturnCode p9_pm_get_poundv_bucket_attr(
    const fapi2::Target<fapi2::TARGET_TYPE_EQ>& i_target,
    uint8_t* o_data)
{
    FAPI_IMP("Entering p9_pm_get_poundv_bucket_attr ....");
    uint8_t* l_prDataPtr = NULL;
    uint8_t* l_fullVpdData = NULL;
    uint8_t l_overridePresent = 0;
    uint32_t l_vpdSize = 0;
    uint32_t l_eqFapiPos = 0;
    uint8_t l_bucketId;
    fapi2::ReturnCode l_rc = fapi2::FAPI2_RC_SUCCESS;

    do
    {
        //To read MVPD we will need the proc parent of the inputted EQ target
        fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> l_procParent =
            i_target.getParent<fapi2::TARGET_TYPE_PROC_CHIP>();

        //check if bucket num has been overriden
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_POUNDV_BUCKET_NUM_OVERRIDE,
                               i_target,
                               l_overridePresent));

        if(l_overridePresent != 0)
        {
            //If it has been overriden then get the override
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_POUNDV_BUCKET_NUM,
                                   i_target,
                                   l_bucketId));
        }
        else
        {
            //Otherwise get the bucket num from MVPD data
            //First read is to get size of vpd record, note the o_buffer is NULL
            l_rc = getMvpdField(fapi2::MVPD_RECORD_VINI,
                                fapi2::MVPD_KEYWORD_PR,
                                l_procParent,
                                NULL,
                                l_vpdSize);

            if(l_rc)
            {
                FAPI_ERR("p9_pm_get_poundv_bucket_attr:: Error reading PR keyword size from VINI record");
                break;
            }

            l_prDataPtr = reinterpret_cast<uint8_t*>(malloc(l_vpdSize));

            //Second read is to get data of vpd record
            l_rc = getMvpdField(fapi2::MVPD_RECORD_VINI,
                                fapi2::MVPD_KEYWORD_PR,
                                l_procParent,
                                l_prDataPtr,
                                l_vpdSize);

            if(l_rc)
            {
                FAPI_ERR("p9_pm_get_poundv_bucket_attr:: Error reading PR keyword from VINI record");
                break;
            }

            //Bucket ID is byte[4] of the PR keyword
            memcpy(&l_bucketId, (l_prDataPtr + 4), sizeof(uint8_t));
        }


        //Need to determine which LRP record to read from depending on which
        //bucket we are getting the power management data from. FapiPos will
        //tell us which LRP record to use.
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_FAPI_POS,
                               i_target,
                               l_eqFapiPos));
        fapi2::MvpdRecord lprRecord;

        switch(l_eqFapiPos)
        {
            case 0:
                lprRecord = fapi2::MVPD_RECORD_LRP0;
                break;

            case 1:
                lprRecord = fapi2::MVPD_RECORD_LRP1;
                break;

            case 2:
                lprRecord = fapi2::MVPD_RECORD_LRP2;
                break;

            case 3:
                lprRecord = fapi2::MVPD_RECORD_LRP3;
                break;

            case 4:
                lprRecord = fapi2::MVPD_RECORD_LRP4;
                break;

            case 5:
                lprRecord = fapi2::MVPD_RECORD_LRP5;
                break;

            default:
                FAPI_ERR("No LRP record found for EQ with fapi pos = %d", l_eqFapiPos);
                assert(0);
                break;
        }

        //Reset VPD size because we want to find size of another VPD record
        l_vpdSize = 0;

        //First read is to get size of vpd record, note the o_buffer is NULL
        l_rc = getMvpdField(lprRecord,
                            fapi2::MVPD_KEYWORD_PDV,
                            l_procParent,
                            NULL,
                            l_vpdSize);

        if(l_rc)
        {
            FAPI_ERR("p9_pm_get_poundv_bucket_attr:: Error reading PDV keyword size from LRP%d record", l_eqFapiPos);
            break;
        }

        //Allocate memory for vpd data
        l_fullVpdData = reinterpret_cast<uint8_t*>(malloc(l_vpdSize));

        FAPI_ASSERT(l_vpdSize - 4 - ((l_bucketId - 1) * 0x33) >= sizeof(fapi2::ATTR_POUNDV_BUCKET_DATA_Type),
                    fapi2::BAD_VPD_READ()
                    .set_EXPECTED_SIZE(sizeof(fapi2::ATTR_POUNDV_BUCKET_DATA_Type))
                    .set_ACTUAL_SIZE(l_vpdSize - 4 - ((l_bucketId - 1) * 0x33)),
                    "#V data read was too small!" );

        //Second read is to get data of vpd record
        l_rc = getMvpdField(lprRecord,
                            fapi2::MVPD_KEYWORD_PDV,
                            l_procParent,
                            l_fullVpdData,
                            l_vpdSize);

        if(l_rc)
        {
            FAPI_ERR("p9_pm_get_poundv_bucket_attr:: Error reading PDV keyword from LRP%d record", l_eqFapiPos);
            break;
        }

        //#V record is laid out as follows:
        //Name:     0x2 byte
        //Length:   0x2 byte
        //Version:  0x1 byte **buffer starts here
        //PNP:      0x3 byte
        //bucket a: 0x33 byte
        //bucket b: 0x33 byte
        //bucket c: 0x33 byte
        //bucket d: 0x33 byte
        //bucket e: 0x33 byte
        //bucket f: 0x33 byte
        if( *l_fullVpdData == 0x2)
        {
            memcpy(o_data,
                   l_fullVpdData + 4 + (l_bucketId - 1) * 0x33,
                   sizeof(fapi2::ATTR_POUNDV_BUCKET_DATA_Type));
        }
        else
        {
            FAPI_ERR("p9_pm_get_poundv_bucket_attr::Invalid #V record version: 0x%x", *l_fullVpdData);
            FAPI_ASSERT(0,
                        fapi2::INVALID_POUNDV_VERSION()
                        .set_POUNDV_VERSION(*l_fullVpdData),
                        "#V is of an invalid version!" );
        }


    }
    while(0);

fapi_try_exit:

    if(l_fullVpdData != NULL)
    {
        free(l_fullVpdData);
    }

    if(l_prDataPtr != NULL)
    {
        free(l_prDataPtr);
    }

    FAPI_IMP("Exiting p9_pm_get_poundv_bucket_attr ....");

    //If there is no issue in the current err, check
    //the local rc to see if the mvpd access methods caught anything
    if((fapi2::current_err == fapi2::FAPI2_RC_SUCCESS) &&
       (l_rc != fapi2::FAPI2_RC_SUCCESS))
    {
        fapi2::current_err = l_rc;
    }

    return fapi2::current_err;
}


OpenPOWER on IntegriCloud