summaryrefslogtreecommitdiffstats
path: root/src/import/chips/centaur/procedures/vpd_accessors/getMBvpdMemoryDataVersion.C
blob: b12ddc18f6a7cda91b6e79b3c08ae836e35fafdd (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/centaur/procedures/vpd_accessors/getMBvpdMemoryDataVersion.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017                             */
/* [+] 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 getMBvpdMemoryDataVersion.C
///  @brief MBVPD Accessor for providing the ATTR_VPD_VM_KEYWORD attribute
///
/// *HWP HWP Owner: Luke Mulkey <lwmulkey@us.ibm.com>
/// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
/// *HWP Team: Memory
/// *HWP Level: 2
/// *HWP Consumed by: HB

#include    <stdint.h>

//  fapi2 support
#include    <fapi2.H>
#include    <getMBvpdMemoryDataVersion.H>
#include    <getMBvpdAttr.H>
#include  <generic/memory/lib/utils/c_str.H>

extern "C"
{
    using namespace fapi2;
    using namespace getAttrData;

///
/// @brief Get the ATTR_VPD_VM_KEYWORD FAPI attribute
/// Return the Memory Data version from MBvpd record SPDX keyword VM.
///
/// The ATTR_VPD_VM_KEYWORD attribute is associated with a DIMM. The platfrom must
/// get the associated Membuff chip to be passed to this hwp accessor.
///
/// @param[in]  i_mbTarget - Reference to membuf Target
/// @param[out] o_val      - Filled in with vpd version
/// @return fapi::ReturnCode FAPI_RC_SUCCESS if success, else error code
///
    fapi2::ReturnCode getMBvpdMemoryDataVersion(
        const fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP>&   i_mbTarget,
        uint32_t&   o_val)
    {
        fapi2::ReturnCode l_fapi2rc;
        DimmType l_dimmType = DimmType::ISDIMM;
        fapi2::MBvpdRecord  l_record  = fapi2::MBVPD_RECORD_SPDX;
        uint32_t l_vpdMemoryDataVersion = VM_KEYWORD_DEFAULT_VALUE;
        size_t l_bufSize = sizeof(l_vpdMemoryDataVersion);

        FAPI_DBG("getMBvpdMemoryDataVersion: entry ");

        FAPI_DBG("getMBvpdMemoryDataVersion: Membuff path=%s ",
                 mss::c_str(i_mbTarget));

        // Find the dimm type
        // Determine if ISDIMM or CDIMM

        // Find one mba target for getting associated dimms
        auto l_mba_chiplets = i_mbTarget.getChildren<fapi2::TARGET_TYPE_MBA>();

        if(l_mba_chiplets.size() == 0)
        {
            FAPI_ERR("getMBvpdMemoryDataVersion: Problem getting MBA's of Membuff");
            return FAPI2_RC_FALSE;   //return error
        }

        auto l_target_dimm_array = l_mba_chiplets[0].getChildren<fapi2::TARGET_TYPE_DIMM>();

        if(l_target_dimm_array.size() != 0)
        {
            uint8_t l_customDimm = 0;
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_SPD_CUSTOM, l_target_dimm_array[0],
                                   l_customDimm), "getMBvpdMemoryDataVersion: ATTR_SPD_CUSTOM failed");

            if (l_customDimm == fapi2::ENUM_ATTR_CEN_SPD_CUSTOM_YES)
            {
                l_dimmType = DimmType::CDIMM;
                FAPI_DBG("getMBvpdMemoryDataVersion: CDIMM TYPE!!!");
            }
            else
            {
                l_dimmType = DimmType::ISDIMM;
                FAPI_DBG("getMBvpdMemoryDataVersion: ISDIMM TYPE!!!");
            }
        }
        else
        {
            l_dimmType = DimmType::ISDIMM;
            FAPI_DBG("getMBvpdMemoryDataVersion: ISDIMM TYPE (dimm array size = 0)");
        }

        if( l_dimmType == DimmType::CDIMM)
        {
            l_record = fapi2::MBVPD_RECORD_VSPD;
        }

        // get Memory Data  version from record VSPD/SPDX keyword VM
        l_fapi2rc = getMBvpdField(l_record,
                                  fapi2::MBVPD_KEYWORD_VM,
                                  i_mbTarget,
                                  reinterpret_cast<uint8_t*>(&l_vpdMemoryDataVersion),
                                  l_bufSize);

        if (l_fapi2rc)
        {
            FAPI_DBG("getMBvpdMemoryDataVersion: Returning default"
                     " as VM keyword read failed.");
            return fapi2::FAPI2_RC_SUCCESS;// Lets make it success and return default
        }

        // Check that sufficient size was returned.
        FAPI_ASSERT(l_bufSize >= sizeof(l_vpdMemoryDataVersion),
                    fapi2::CEN_MBVPD_INSUFFICIENT_VPD_RETURNED().
                    set_KEYWORD(fapi2::MBVPD_KEYWORD_VM).
                    set_RETURNED_SIZE(l_bufSize).
                    set_CHIP_TARGET(i_mbTarget),
                    "getMBvpdMemoryDataVersion:"
                    " less keyword data returned than expected %d < %d",
                    l_bufSize, sizeof(l_vpdMemoryDataVersion));

        // Check if the format byte in the value returned is in between valid range
        FAPI_ASSERT(( ((MBvpdVMKeyword*)(&l_vpdMemoryDataVersion))->iv_version <=  VM_SUPPORTED_HIGH_VER ) &&
                    ( ((MBvpdVMKeyword*)(&l_vpdMemoryDataVersion))->iv_version != VM_NOT_SUPPORTED ),
                    fapi2::CEN_MBVPD_INVALID_VM_DATA_RETURNED().
                    set_KEYWORD(fapi2::MBVPD_KEYWORD_VM).
                    set_RETURNED_VALUE(l_vpdMemoryDataVersion).
                    set_RECORD_NAME(l_record).
                    set_DIMM_TYPE(l_dimmType).
                    set_CHIP_TARGET(i_mbTarget),
                    "getMBvpdMemoryDataVersion:"
                    " keyword data returned is invalid : %d ",
                    l_vpdMemoryDataVersion);

        // return value
        o_val = static_cast<uint32_t>(be16toh(l_vpdMemoryDataVersion));

        FAPI_DBG("getMBvpdMemoryDataVersion: Memory Data version=0x%08x",
                 o_val);


        FAPI_DBG("getMBvpdMemoryDataVersion: exit");
    fapi_try_exit:
        return fapi2::current_err;
    }

}   // extern "C"
OpenPOWER on IntegriCloud