blob: 851ef82d1fea9c66bf5ac441dc2ee94720814e12 [file] [log] [blame]
Cheng C Yang8c3fab62019-12-19 00:51:06 +08001/*
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
Zhikui Ren18a5ab92020-09-01 21:35:20 -070018#include "smbios_mdrv2.hpp"
Cheng C Yang8c3fab62019-12-19 00:51:06 +080019
Tony Lee8f789c32024-07-10 20:01:43 +080020#include <nlohmann/json.hpp>
Jie Yange7cf3192021-08-20 11:21:43 -070021#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Jie Yang41654fc2021-09-07 20:26:32 -070022#include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080023#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
Jie Yang31720392021-07-22 21:45:45 -070024#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000025#include <xyz/openbmc_project/Inventory/Item/Dimm/MemoryLocation/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080026#include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp>
Joshi-Mansi33c948a2021-03-20 00:58:50 +053027#include <xyz/openbmc_project/Inventory/Item/server.hpp>
Tim Leedc469c72021-07-20 10:55:58 +080028#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080029
30namespace phosphor
31{
32
33namespace smbios
34{
35
36using DeviceType =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070037 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::DeviceType;
Cheng C Yang8c3fab62019-12-19 00:51:06 +080038
kasunath2eca4fe2022-08-17 17:30:07 -070039using EccType =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070040 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::Ecc;
kasunath2eca4fe2022-08-17 17:30:07 -070041
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000042using MemoryTechType =
43 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::MemoryTech;
44
Prithvi Pai1aea7e42025-04-11 15:00:26 +053045using FormFactor =
46 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::FormFactor;
47
Tony Lee8f789c32024-07-10 20:01:43 +080048using Json = nlohmann::json;
49
Zhikui Ren18a5ab92020-09-01 21:35:20 -070050class Dimm :
Patrick Williams77b9c472022-07-22 19:26:57 -050051 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070052 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>,
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000053 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
54 inventory::item::dimm::MemoryLocation>,
Patrick Williams77b9c472022-07-22 19:26:57 -050055 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070056 sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset>,
57 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
58 inventory::decorator::LocationCode>,
Patrick Williams77b9c472022-07-22 19:26:57 -050059 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070060 sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot>,
Patrick Williams77b9c472022-07-22 19:26:57 -050061 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070062 sdbusplus::server::xyz::openbmc_project::inventory::Item>,
Patrick Williams77b9c472022-07-22 19:26:57 -050063 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070064 sdbusplus::server::xyz::openbmc_project::association::Definitions>,
65 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::state::
66 decorator::OperationalStatus>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080067{
68 public:
69 Dimm() = delete;
70 ~Dimm() = default;
71 Dimm(const Dimm&) = delete;
72 Dimm& operator=(const Dimm&) = delete;
73 Dimm(Dimm&&) = default;
74 Dimm& operator=(Dimm&&) = default;
75
Patrick Williams77b9c472022-07-22 19:26:57 -050076 Dimm(sdbusplus::bus_t& bus, const std::string& objPath,
Jie Yange7cf3192021-08-20 11:21:43 -070077 const uint8_t& dimmId, uint8_t* smbiosTableStorage,
78 const std::string& motherboard) :
Cheng C Yang8c3fab62019-12-19 00:51:06 +080079
Patrick Williams77b9c472022-07-22 19:26:57 -050080 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070081 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>(
Cheng C Yang8c3fab62019-12-19 00:51:06 +080082 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -070083 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000084 inventory::item::dimm::MemoryLocation>(
85 bus, objPath.c_str()),
86 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
Jason M. Bills33ae81f2023-04-26 09:06:08 -070087 inventory::decorator::Asset>(
Patrick Williams77b9c472022-07-22 19:26:57 -050088 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -070089 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
90 inventory::decorator::LocationCode>(
Patrick Williams77b9c472022-07-22 19:26:57 -050091 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -070092 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
93 inventory::connector::Slot>(
Patrick Williams77b9c472022-07-22 19:26:57 -050094 bus, objPath.c_str()),
95 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070096 sdbusplus::server::xyz::openbmc_project::inventory::Item>(
Joshi-Mansi33c948a2021-03-20 00:58:50 +053097 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050098 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070099 sdbusplus::server::xyz::openbmc_project::association::Definitions>(
Jie Yange7cf3192021-08-20 11:21:43 -0700100 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -0700101 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
102 state::decorator::OperationalStatus>(
Patrick Williams77b9c472022-07-22 19:26:57 -0500103 bus, objPath.c_str()),
Brandon Kim5a122a62023-05-04 04:25:03 +0000104 dimmNum(dimmId)
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800105 {
Brandon Kim5a122a62023-05-04 04:25:03 +0000106 memoryInfoUpdate(smbiosTableStorage, motherboard);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800107 }
108
Brandon Kim5a122a62023-05-04 04:25:03 +0000109 void memoryInfoUpdate(uint8_t* smbiosTableStorage,
110 const std::string& motherboard);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800111
112 uint16_t memoryDataWidth(uint16_t value) override;
Joseph Fu410bbc22023-07-12 19:01:04 +0800113 uint16_t memoryTotalWidth(uint16_t value) override;
Jason M. Billse7770992021-05-14 13:24:33 -0700114 size_t memorySizeInKB(size_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800115 std::string memoryDeviceLocator(std::string value) override;
116 DeviceType memoryType(DeviceType value) override;
117 std::string memoryTypeDetail(std::string value) override;
118 uint16_t maxMemorySpeedInMhz(uint16_t value) override;
119 std::string manufacturer(std::string value) override;
Joshi-Mansi33c948a2021-03-20 00:58:50 +0530120 bool present(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800121 std::string serialNumber(std::string value) override;
122 std::string partNumber(std::string value) override;
Jie Yang31720392021-07-22 21:45:45 -0700123 std::string locationCode(std::string value) override;
George Liu036374a2023-06-15 08:47:46 +0800124 size_t memoryAttributes(size_t value) override;
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +0000125 MemoryTechType memoryMedia(MemoryTechType value) override;
126 uint8_t slot(uint8_t value) override;
127 uint8_t socket(uint8_t value) override;
Tony Lee8f789c32024-07-10 20:01:43 +0800128 uint8_t memoryController(uint8_t value) override;
129 uint8_t channel(uint8_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800130 uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
Tim Leedc469c72021-07-20 10:55:58 +0800131 bool functional(bool value) override;
kasunath2eca4fe2022-08-17 17:30:07 -0700132 EccType ecc(EccType value) override;
Prithvi Pai1aea7e42025-04-11 15:00:26 +0530133 FormFactor formFactor(FormFactor value) override;
Tony Lee8f789c32024-07-10 20:01:43 +0800134 Json parseConfigFile();
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800135
136 private:
137 uint8_t dimmNum;
138
139 uint8_t* storage;
140
Jie Yange7cf3192021-08-20 11:21:43 -0700141 std::string motherboardPath;
142
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800143 void dimmSize(const uint16_t size);
Joseph Fu0b1d9422023-03-31 17:47:12 +0800144 void dimmSizeExt(const uint32_t size);
Konstantin Aladyshev744b35a2022-11-02 08:34:27 +0000145 void dimmDeviceLocator(const uint8_t bankLocatorPositionNum,
146 const uint8_t deviceLocatorPositionNum,
147 const uint8_t structLen, uint8_t* dataIn);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800148 void dimmType(const uint8_t type);
149 void dimmTypeDetail(const uint16_t detail);
150 void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen,
151 uint8_t* dataIn);
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +0000152 void dimmMedia(const uint8_t type);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800153 void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen,
154 uint8_t* dataIn);
155 void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
156 uint8_t* dataIn);
kasunath2eca4fe2022-08-17 17:30:07 -0700157 void updateEccType(uint16_t exPhyArrayHandle);
Prithvi Pai1aea7e42025-04-11 15:00:26 +0530158 void updateFormFactor(const uint8_t formFactorKey);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800159};
160
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700161struct MemoryInfo
162{
163 uint8_t type;
164 uint8_t length;
165 uint16_t handle;
166 uint16_t phyArrayHandle;
167 uint16_t errInfoHandle;
168 uint16_t totalWidth;
169 uint16_t dataWidth;
170 uint16_t size;
171 uint8_t formFactor;
172 uint8_t deviceSet;
173 uint8_t deviceLocator;
174 uint8_t bankLocator;
175 uint8_t memoryType;
176 uint16_t typeDetail;
177 uint16_t speed;
178 uint8_t manufacturer;
179 uint8_t serialNum;
180 uint8_t assetTag;
181 uint8_t partNum;
Michael Shen21cb0e82023-08-16 09:26:05 +0000182 uint8_t attributes;
Joseph Fu0b1d9422023-03-31 17:47:12 +0800183 uint32_t extendedSize;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700184 uint16_t confClockSpeed;
185 uint16_t minimumVoltage;
186 uint16_t maximumVoltage;
187 uint16_t configuredVoltage;
188 uint8_t memoryTechnology;
189 uint16_t memoryOperatingModeCap;
190 uint8_t firwareVersion;
191 uint16_t modelManufId;
192 uint16_t modelProdId;
193 uint16_t memSubConManufId;
194 uint16_t memSubConProdId;
195 uint64_t nvSize;
196 uint64_t volatileSize;
197 uint64_t cacheSize;
198 uint64_t logicalSize;
199} __attribute__((packed));
200
kasunath2eca4fe2022-08-17 17:30:07 -0700201/**
202 * @brief Struct to represent SMBIOS 3.2 type-16 (Physical Memory Array) data.
203 */
204struct PhysicalMemoryArrayInfo
205{
206 uint8_t type;
207 uint8_t length;
208 uint16_t handle;
209 uint8_t location;
210 uint8_t use;
211 uint8_t memoryErrorCorrection;
212 uint32_t maximumCapacity;
213 uint16_t memoryErrorInformationHandle;
214 uint16_t numberOfMemoryDevices;
215 uint64_t extendedMaximumCapacity;
216} __attribute__((packed));
217static_assert(sizeof(PhysicalMemoryArrayInfo) == 23,
218 "Size of PhysicalMemoryArrayInfo struct is incorrect.");
219
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800220const std::map<uint8_t, DeviceType> dimmTypeTable = {
221 {0x1, DeviceType::Other}, {0x2, DeviceType::Unknown},
222 {0x3, DeviceType::DRAM}, {0x4, DeviceType::EDRAM},
223 {0x5, DeviceType::VRAM}, {0x6, DeviceType::SRAM},
224 {0x7, DeviceType::RAM}, {0x8, DeviceType::ROM},
225 {0x9, DeviceType::FLASH}, {0xa, DeviceType::EEPROM},
226 {0xb, DeviceType::FEPROM}, {0xc, DeviceType::EPROM},
227 {0xd, DeviceType::CDRAM}, {0xe, DeviceType::ThreeDRAM},
228 {0xf, DeviceType::SDRAM}, {0x10, DeviceType::DDR_SGRAM},
229 {0x11, DeviceType::RDRAM}, {0x12, DeviceType::DDR},
230 {0x13, DeviceType::DDR2}, {0x14, DeviceType::DDR2_SDRAM_FB_DIMM},
231 {0x18, DeviceType::DDR3}, {0x19, DeviceType::FBD2},
232 {0x1a, DeviceType::DDR4}, {0x1b, DeviceType::LPDDR_SDRAM},
233 {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM},
234 {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical},
Mansi Joshi7ece93a2021-07-19 15:07:52 +0530235 {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2},
236 {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}};
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800237
238const std::array<std::string, 16> detailTable{
239 "Reserved", "Other", "Unknown", "Fast-paged",
240 "Static column", "Pseudo-static", "RAMBUS", "Synchronous",
241 "CMOS", "EDO", "Window DRAM", "Cache DRAM",
242 "Non-volatile", "Registered", "Unbuffered", "LRDIMM"};
243
kasunath2eca4fe2022-08-17 17:30:07 -0700244/**
245 * @brief Map SMBIOS 3.2 Memory Array Error Correction Types to
246 * xyz.openbmc_project.Inventory.Item.Dimm.Ecc types.
247 *
248 * SMBIOS 3.2 Memory Array Error Correction Types 'Unknown', 'None', 'CRC' are
249 * mapped to EccType::NoECC since the DBUs interface does not support those
250 * representations.
251 */
252const std::map<uint8_t, EccType> dimmEccTypeMap = {
253 {0x1, EccType::NoECC}, {0x2, EccType::NoECC},
254 {0x3, EccType::NoECC}, {0x4, EccType::AddressParity},
255 {0x5, EccType::SingleBitECC}, {0x6, EccType::MultiBitECC},
256 {0x7, EccType::NoECC}};
257
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +0000258const std::map<uint8_t, MemoryTechType> dimmMemoryTechTypeMap = {
259 {0x1, MemoryTechType::Other}, {0x2, MemoryTechType::Unknown},
260 {0x3, MemoryTechType::DRAM}, {0x4, MemoryTechType::NVDIMM_N},
261 {0x5, MemoryTechType::NVDIMM_F}, {0x6, MemoryTechType::NVDIMM_P},
262 {0x7, MemoryTechType::IntelOptane}};
263
Tony Lee8f789c32024-07-10 20:01:43 +0800264struct memoryLocation
265{
266 uint8_t memoryController;
267 uint8_t socket;
268 uint8_t slot;
269 uint8_t channel;
270};
271
Prithvi Pai1aea7e42025-04-11 15:00:26 +0530272const std::map<uint8_t, FormFactor> dimmFormFactorMap = {
273 {0x10, FormFactor::Die}};
274
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800275} // namespace smbios
276
277} // namespace phosphor