blob: a3a48be4ab382f10a5541034911dab0e7161c5cd [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
Jie Yange7cf3192021-08-20 11:21:43 -070020#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Jie Yang41654fc2021-09-07 20:26:32 -070021#include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080022#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
Jie Yang31720392021-07-22 21:45:45 -070023#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000024#include <xyz/openbmc_project/Inventory/Item/Dimm/MemoryLocation/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080025#include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp>
Joshi-Mansi33c948a2021-03-20 00:58:50 +053026#include <xyz/openbmc_project/Inventory/Item/server.hpp>
Tim Leedc469c72021-07-20 10:55:58 +080027#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080028
29namespace phosphor
30{
31
32namespace smbios
33{
34
35using DeviceType =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070036 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::DeviceType;
Cheng C Yang8c3fab62019-12-19 00:51:06 +080037
kasunath2eca4fe2022-08-17 17:30:07 -070038using EccType =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070039 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::Ecc;
kasunath2eca4fe2022-08-17 17:30:07 -070040
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000041using MemoryTechType =
42 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::MemoryTech;
43
Zhikui Ren18a5ab92020-09-01 21:35:20 -070044class Dimm :
Patrick Williams77b9c472022-07-22 19:26:57 -050045 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070046 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>,
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000047 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
48 inventory::item::dimm::MemoryLocation>,
Patrick Williams77b9c472022-07-22 19:26:57 -050049 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070050 sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset>,
51 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
52 inventory::decorator::LocationCode>,
Patrick Williams77b9c472022-07-22 19:26:57 -050053 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070054 sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot>,
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::Item>,
Patrick Williams77b9c472022-07-22 19:26:57 -050057 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070058 sdbusplus::server::xyz::openbmc_project::association::Definitions>,
59 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::state::
60 decorator::OperationalStatus>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080061{
62 public:
63 Dimm() = delete;
64 ~Dimm() = default;
65 Dimm(const Dimm&) = delete;
66 Dimm& operator=(const Dimm&) = delete;
67 Dimm(Dimm&&) = default;
68 Dimm& operator=(Dimm&&) = default;
69
Patrick Williams77b9c472022-07-22 19:26:57 -050070 Dimm(sdbusplus::bus_t& bus, const std::string& objPath,
Jie Yange7cf3192021-08-20 11:21:43 -070071 const uint8_t& dimmId, uint8_t* smbiosTableStorage,
72 const std::string& motherboard) :
Cheng C Yang8c3fab62019-12-19 00:51:06 +080073
Patrick Williams77b9c472022-07-22 19:26:57 -050074 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070075 sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>(
Cheng C Yang8c3fab62019-12-19 00:51:06 +080076 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -070077 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +000078 inventory::item::dimm::MemoryLocation>(
79 bus, objPath.c_str()),
80 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
Jason M. Bills33ae81f2023-04-26 09:06:08 -070081 inventory::decorator::Asset>(
Patrick Williams77b9c472022-07-22 19:26:57 -050082 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -070083 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
84 inventory::decorator::LocationCode>(
Patrick Williams77b9c472022-07-22 19:26:57 -050085 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -070086 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
87 inventory::connector::Slot>(
Patrick Williams77b9c472022-07-22 19:26:57 -050088 bus, objPath.c_str()),
89 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070090 sdbusplus::server::xyz::openbmc_project::inventory::Item>(
Joshi-Mansi33c948a2021-03-20 00:58:50 +053091 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050092 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070093 sdbusplus::server::xyz::openbmc_project::association::Definitions>(
Jie Yange7cf3192021-08-20 11:21:43 -070094 bus, objPath.c_str()),
Jason M. Bills33ae81f2023-04-26 09:06:08 -070095 sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
96 state::decorator::OperationalStatus>(
Patrick Williams77b9c472022-07-22 19:26:57 -050097 bus, objPath.c_str()),
Brandon Kim5a122a62023-05-04 04:25:03 +000098 dimmNum(dimmId)
Cheng C Yang8c3fab62019-12-19 00:51:06 +080099 {
Brandon Kim5a122a62023-05-04 04:25:03 +0000100 memoryInfoUpdate(smbiosTableStorage, motherboard);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800101 }
102
Brandon Kim5a122a62023-05-04 04:25:03 +0000103 void memoryInfoUpdate(uint8_t* smbiosTableStorage,
104 const std::string& motherboard);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800105
106 uint16_t memoryDataWidth(uint16_t value) override;
Joseph Fu410bbc22023-07-12 19:01:04 +0800107 uint16_t memoryTotalWidth(uint16_t value) override;
Jason M. Billse7770992021-05-14 13:24:33 -0700108 size_t memorySizeInKB(size_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800109 std::string memoryDeviceLocator(std::string value) override;
110 DeviceType memoryType(DeviceType value) override;
111 std::string memoryTypeDetail(std::string value) override;
112 uint16_t maxMemorySpeedInMhz(uint16_t value) override;
113 std::string manufacturer(std::string value) override;
Joshi-Mansi33c948a2021-03-20 00:58:50 +0530114 bool present(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800115 std::string serialNumber(std::string value) override;
116 std::string partNumber(std::string value) override;
Jie Yang31720392021-07-22 21:45:45 -0700117 std::string locationCode(std::string value) override;
George Liu036374a2023-06-15 08:47:46 +0800118 size_t memoryAttributes(size_t value) override;
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +0000119 MemoryTechType memoryMedia(MemoryTechType value) override;
120 uint8_t slot(uint8_t value) override;
121 uint8_t socket(uint8_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800122 uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
Tim Leedc469c72021-07-20 10:55:58 +0800123 bool functional(bool value) override;
kasunath2eca4fe2022-08-17 17:30:07 -0700124 EccType ecc(EccType value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800125
126 private:
127 uint8_t dimmNum;
128
129 uint8_t* storage;
130
Jie Yange7cf3192021-08-20 11:21:43 -0700131 std::string motherboardPath;
132
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800133 void dimmSize(const uint16_t size);
Joseph Fu0b1d9422023-03-31 17:47:12 +0800134 void dimmSizeExt(const uint32_t size);
Konstantin Aladyshev744b35a2022-11-02 08:34:27 +0000135 void dimmDeviceLocator(const uint8_t bankLocatorPositionNum,
136 const uint8_t deviceLocatorPositionNum,
137 const uint8_t structLen, uint8_t* dataIn);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800138 void dimmType(const uint8_t type);
139 void dimmTypeDetail(const uint16_t detail);
140 void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen,
141 uint8_t* dataIn);
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +0000142 void dimmMedia(const uint8_t type);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800143 void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen,
144 uint8_t* dataIn);
145 void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
146 uint8_t* dataIn);
kasunath2eca4fe2022-08-17 17:30:07 -0700147 void updateEccType(uint16_t exPhyArrayHandle);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800148};
149
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700150struct MemoryInfo
151{
152 uint8_t type;
153 uint8_t length;
154 uint16_t handle;
155 uint16_t phyArrayHandle;
156 uint16_t errInfoHandle;
157 uint16_t totalWidth;
158 uint16_t dataWidth;
159 uint16_t size;
160 uint8_t formFactor;
161 uint8_t deviceSet;
162 uint8_t deviceLocator;
163 uint8_t bankLocator;
164 uint8_t memoryType;
165 uint16_t typeDetail;
166 uint16_t speed;
167 uint8_t manufacturer;
168 uint8_t serialNum;
169 uint8_t assetTag;
170 uint8_t partNum;
Michael Shen21cb0e82023-08-16 09:26:05 +0000171 uint8_t attributes;
Joseph Fu0b1d9422023-03-31 17:47:12 +0800172 uint32_t extendedSize;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700173 uint16_t confClockSpeed;
174 uint16_t minimumVoltage;
175 uint16_t maximumVoltage;
176 uint16_t configuredVoltage;
177 uint8_t memoryTechnology;
178 uint16_t memoryOperatingModeCap;
179 uint8_t firwareVersion;
180 uint16_t modelManufId;
181 uint16_t modelProdId;
182 uint16_t memSubConManufId;
183 uint16_t memSubConProdId;
184 uint64_t nvSize;
185 uint64_t volatileSize;
186 uint64_t cacheSize;
187 uint64_t logicalSize;
188} __attribute__((packed));
189
kasunath2eca4fe2022-08-17 17:30:07 -0700190/**
191 * @brief Struct to represent SMBIOS 3.2 type-16 (Physical Memory Array) data.
192 */
193struct PhysicalMemoryArrayInfo
194{
195 uint8_t type;
196 uint8_t length;
197 uint16_t handle;
198 uint8_t location;
199 uint8_t use;
200 uint8_t memoryErrorCorrection;
201 uint32_t maximumCapacity;
202 uint16_t memoryErrorInformationHandle;
203 uint16_t numberOfMemoryDevices;
204 uint64_t extendedMaximumCapacity;
205} __attribute__((packed));
206static_assert(sizeof(PhysicalMemoryArrayInfo) == 23,
207 "Size of PhysicalMemoryArrayInfo struct is incorrect.");
208
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800209const std::map<uint8_t, DeviceType> dimmTypeTable = {
210 {0x1, DeviceType::Other}, {0x2, DeviceType::Unknown},
211 {0x3, DeviceType::DRAM}, {0x4, DeviceType::EDRAM},
212 {0x5, DeviceType::VRAM}, {0x6, DeviceType::SRAM},
213 {0x7, DeviceType::RAM}, {0x8, DeviceType::ROM},
214 {0x9, DeviceType::FLASH}, {0xa, DeviceType::EEPROM},
215 {0xb, DeviceType::FEPROM}, {0xc, DeviceType::EPROM},
216 {0xd, DeviceType::CDRAM}, {0xe, DeviceType::ThreeDRAM},
217 {0xf, DeviceType::SDRAM}, {0x10, DeviceType::DDR_SGRAM},
218 {0x11, DeviceType::RDRAM}, {0x12, DeviceType::DDR},
219 {0x13, DeviceType::DDR2}, {0x14, DeviceType::DDR2_SDRAM_FB_DIMM},
220 {0x18, DeviceType::DDR3}, {0x19, DeviceType::FBD2},
221 {0x1a, DeviceType::DDR4}, {0x1b, DeviceType::LPDDR_SDRAM},
222 {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM},
223 {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical},
Mansi Joshi7ece93a2021-07-19 15:07:52 +0530224 {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2},
225 {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}};
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800226
227const std::array<std::string, 16> detailTable{
228 "Reserved", "Other", "Unknown", "Fast-paged",
229 "Static column", "Pseudo-static", "RAMBUS", "Synchronous",
230 "CMOS", "EDO", "Window DRAM", "Cache DRAM",
231 "Non-volatile", "Registered", "Unbuffered", "LRDIMM"};
232
kasunath2eca4fe2022-08-17 17:30:07 -0700233/**
234 * @brief Map SMBIOS 3.2 Memory Array Error Correction Types to
235 * xyz.openbmc_project.Inventory.Item.Dimm.Ecc types.
236 *
237 * SMBIOS 3.2 Memory Array Error Correction Types 'Unknown', 'None', 'CRC' are
238 * mapped to EccType::NoECC since the DBUs interface does not support those
239 * representations.
240 */
241const std::map<uint8_t, EccType> dimmEccTypeMap = {
242 {0x1, EccType::NoECC}, {0x2, EccType::NoECC},
243 {0x3, EccType::NoECC}, {0x4, EccType::AddressParity},
244 {0x5, EccType::SingleBitECC}, {0x6, EccType::MultiBitECC},
245 {0x7, EccType::NoECC}};
246
Jayaprakash Mutyalaa1ff2442023-06-15 07:10:07 +0000247const std::map<uint8_t, MemoryTechType> dimmMemoryTechTypeMap = {
248 {0x1, MemoryTechType::Other}, {0x2, MemoryTechType::Unknown},
249 {0x3, MemoryTechType::DRAM}, {0x4, MemoryTechType::NVDIMM_N},
250 {0x5, MemoryTechType::NVDIMM_F}, {0x6, MemoryTechType::NVDIMM_P},
251 {0x7, MemoryTechType::IntelOptane}};
252
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800253} // namespace smbios
254
255} // namespace phosphor