xref: /openbmc/smbios-mdr/include/dimm.hpp (revision 33ae81fe)
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 #include "smbios_mdrv2.hpp"
19 
20 #include <xyz/openbmc_project/Association/Definitions/server.hpp>
21 #include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
22 #include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
23 #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
24 #include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp>
25 #include <xyz/openbmc_project/Inventory/Item/server.hpp>
26 #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
27 
28 namespace phosphor
29 {
30 
31 namespace smbios
32 {
33 
34 using DeviceType =
35     sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::DeviceType;
36 
37 using EccType =
38     sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::Ecc;
39 
40 class Dimm :
41     sdbusplus::server::object_t<
42         sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>,
43     sdbusplus::server::object_t<
44         sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset>,
45     sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
46                                     inventory::decorator::LocationCode>,
47     sdbusplus::server::object_t<
48         sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot>,
49     sdbusplus::server::object_t<
50         sdbusplus::server::xyz::openbmc_project::inventory::Item>,
51     sdbusplus::server::object_t<
52         sdbusplus::server::xyz::openbmc_project::association::Definitions>,
53     sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::state::
54                                     decorator::OperationalStatus>
55 {
56   public:
57     Dimm() = delete;
58     ~Dimm() = default;
59     Dimm(const Dimm&) = delete;
60     Dimm& operator=(const Dimm&) = delete;
61     Dimm(Dimm&&) = default;
62     Dimm& operator=(Dimm&&) = default;
63 
64     Dimm(sdbusplus::bus_t& bus, const std::string& objPath,
65          const uint8_t& dimmId, uint8_t* smbiosTableStorage,
66          const std::string& motherboard) :
67 
68         sdbusplus::server::object_t<
69             sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>(
70             bus, objPath.c_str()),
71         sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
72                                         inventory::decorator::Asset>(
73             bus, objPath.c_str()),
74         sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
75                                         inventory::decorator::LocationCode>(
76             bus, objPath.c_str()),
77         sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
78                                         inventory::connector::Slot>(
79             bus, objPath.c_str()),
80         sdbusplus::server::object_t<
81             sdbusplus::server::xyz::openbmc_project::inventory::Item>(
82             bus, objPath.c_str()),
83         sdbusplus::server::object_t<
84             sdbusplus::server::xyz::openbmc_project::association::Definitions>(
85             bus, objPath.c_str()),
86         sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
87                                         state::decorator::OperationalStatus>(
88             bus, objPath.c_str()),
89         dimmNum(dimmId), storage(smbiosTableStorage),
90         motherboardPath(motherboard)
91     {
92         memoryInfoUpdate();
93     }
94 
95     void memoryInfoUpdate(void);
96 
97     uint16_t memoryDataWidth(uint16_t value) override;
98     size_t memorySizeInKB(size_t value) override;
99     std::string memoryDeviceLocator(std::string value) override;
100     DeviceType memoryType(DeviceType value) override;
101     std::string memoryTypeDetail(std::string value) override;
102     uint16_t maxMemorySpeedInMhz(uint16_t value) override;
103     std::string manufacturer(std::string value) override;
104     bool present(bool value) override;
105     std::string serialNumber(std::string value) override;
106     std::string partNumber(std::string value) override;
107     std::string locationCode(std::string value) override;
108     uint8_t memoryAttributes(uint8_t value) override;
109     uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
110     bool functional(bool value) override;
111     EccType ecc(EccType value) override;
112 
113   private:
114     uint8_t dimmNum;
115 
116     uint8_t* storage;
117 
118     std::string motherboardPath;
119 
120     void dimmSize(const uint16_t size);
121     void dimmSizeExt(const uint32_t size);
122     void dimmDeviceLocator(const uint8_t bankLocatorPositionNum,
123                            const uint8_t deviceLocatorPositionNum,
124                            const uint8_t structLen, uint8_t* dataIn);
125     void dimmType(const uint8_t type);
126     void dimmTypeDetail(const uint16_t detail);
127     void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen,
128                           uint8_t* dataIn);
129     void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen,
130                        uint8_t* dataIn);
131     void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
132                      uint8_t* dataIn);
133     void updateEccType(uint16_t exPhyArrayHandle);
134 };
135 
136 struct MemoryInfo
137 {
138     uint8_t type;
139     uint8_t length;
140     uint16_t handle;
141     uint16_t phyArrayHandle;
142     uint16_t errInfoHandle;
143     uint16_t totalWidth;
144     uint16_t dataWidth;
145     uint16_t size;
146     uint8_t formFactor;
147     uint8_t deviceSet;
148     uint8_t deviceLocator;
149     uint8_t bankLocator;
150     uint8_t memoryType;
151     uint16_t typeDetail;
152     uint16_t speed;
153     uint8_t manufacturer;
154     uint8_t serialNum;
155     uint8_t assetTag;
156     uint8_t partNum;
157     uint8_t attributes;
158     uint32_t extendedSize;
159     uint16_t confClockSpeed;
160     uint16_t minimumVoltage;
161     uint16_t maximumVoltage;
162     uint16_t configuredVoltage;
163     uint8_t memoryTechnology;
164     uint16_t memoryOperatingModeCap;
165     uint8_t firwareVersion;
166     uint16_t modelManufId;
167     uint16_t modelProdId;
168     uint16_t memSubConManufId;
169     uint16_t memSubConProdId;
170     uint64_t nvSize;
171     uint64_t volatileSize;
172     uint64_t cacheSize;
173     uint64_t logicalSize;
174 } __attribute__((packed));
175 
176 /**
177  * @brief Struct to represent SMBIOS 3.2 type-16 (Physical Memory Array) data.
178  */
179 struct PhysicalMemoryArrayInfo
180 {
181     uint8_t type;
182     uint8_t length;
183     uint16_t handle;
184     uint8_t location;
185     uint8_t use;
186     uint8_t memoryErrorCorrection;
187     uint32_t maximumCapacity;
188     uint16_t memoryErrorInformationHandle;
189     uint16_t numberOfMemoryDevices;
190     uint64_t extendedMaximumCapacity;
191 } __attribute__((packed));
192 static_assert(sizeof(PhysicalMemoryArrayInfo) == 23,
193               "Size of PhysicalMemoryArrayInfo struct is incorrect.");
194 
195 const std::map<uint8_t, DeviceType> dimmTypeTable = {
196     {0x1, DeviceType::Other},         {0x2, DeviceType::Unknown},
197     {0x3, DeviceType::DRAM},          {0x4, DeviceType::EDRAM},
198     {0x5, DeviceType::VRAM},          {0x6, DeviceType::SRAM},
199     {0x7, DeviceType::RAM},           {0x8, DeviceType::ROM},
200     {0x9, DeviceType::FLASH},         {0xa, DeviceType::EEPROM},
201     {0xb, DeviceType::FEPROM},        {0xc, DeviceType::EPROM},
202     {0xd, DeviceType::CDRAM},         {0xe, DeviceType::ThreeDRAM},
203     {0xf, DeviceType::SDRAM},         {0x10, DeviceType::DDR_SGRAM},
204     {0x11, DeviceType::RDRAM},        {0x12, DeviceType::DDR},
205     {0x13, DeviceType::DDR2},         {0x14, DeviceType::DDR2_SDRAM_FB_DIMM},
206     {0x18, DeviceType::DDR3},         {0x19, DeviceType::FBD2},
207     {0x1a, DeviceType::DDR4},         {0x1b, DeviceType::LPDDR_SDRAM},
208     {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM},
209     {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical},
210     {0x20, DeviceType::HBM},          {0x21, DeviceType::HBM2},
211     {0x22, DeviceType::DDR5},         {0x23, DeviceType::LPDDR5_SDRAM}};
212 
213 const std::array<std::string, 16> detailTable{
214     "Reserved",      "Other",         "Unknown",     "Fast-paged",
215     "Static column", "Pseudo-static", "RAMBUS",      "Synchronous",
216     "CMOS",          "EDO",           "Window DRAM", "Cache DRAM",
217     "Non-volatile",  "Registered",    "Unbuffered",  "LRDIMM"};
218 
219 /**
220  * @brief Map SMBIOS 3.2 Memory Array Error Correction Types to
221  * xyz.openbmc_project.Inventory.Item.Dimm.Ecc types.
222  *
223  * SMBIOS 3.2 Memory Array Error Correction Types 'Unknown', 'None', 'CRC' are
224  * mapped to EccType::NoECC since the DBUs interface does not support those
225  * representations.
226  */
227 const std::map<uint8_t, EccType> dimmEccTypeMap = {
228     {0x1, EccType::NoECC},        {0x2, EccType::NoECC},
229     {0x3, EccType::NoECC},        {0x4, EccType::AddressParity},
230     {0x5, EccType::SingleBitECC}, {0x6, EccType::MultiBitECC},
231     {0x7, EccType::NoECC}};
232 
233 } // namespace smbios
234 
235 } // namespace phosphor
236