blob: 709bfdfe9e1e3a71f44de72a0f35cbf81ee6d6f2 [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>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080024#include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp>
Joshi-Mansi33c948a2021-03-20 00:58:50 +053025#include <xyz/openbmc_project/Inventory/Item/server.hpp>
Tim Leedc469c72021-07-20 10:55:58 +080026#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080027
28namespace phosphor
29{
30
31namespace smbios
32{
33
34using DeviceType =
35 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm::DeviceType;
36
kasunath2eca4fe2022-08-17 17:30:07 -070037using EccType =
38 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm::Ecc;
39
Zhikui Ren18a5ab92020-09-01 21:35:20 -070040class Dimm :
Patrick Williams77b9c472022-07-22 19:26:57 -050041 sdbusplus::server::object_t<
Zhikui Ren18a5ab92020-09-01 21:35:20 -070042 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>,
Patrick Williams77b9c472022-07-22 19:26:57 -050043 sdbusplus::server::object_t<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053044 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>,
Patrick Williams77b9c472022-07-22 19:26:57 -050045 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
46 Decorator::server::LocationCode>,
47 sdbusplus::server::object_t<
Jie Yang41654fc2021-09-07 20:26:32 -070048 sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot>,
Patrick Williams77b9c472022-07-22 19:26:57 -050049 sdbusplus::server::object_t<
Jie Yange7cf3192021-08-20 11:21:43 -070050 sdbusplus::xyz::openbmc_project::Inventory::server::Item>,
Patrick Williams77b9c472022-07-22 19:26:57 -050051 sdbusplus::server::object_t<
Tim Leedc469c72021-07-20 10:55:58 +080052 sdbusplus::xyz::openbmc_project::Association::server::Definitions>,
Patrick Williams77b9c472022-07-22 19:26:57 -050053 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
54 Decorator::server::OperationalStatus>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080055{
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
Patrick Williams77b9c472022-07-22 19:26:57 -050064 Dimm(sdbusplus::bus_t& bus, const std::string& objPath,
Jie Yange7cf3192021-08-20 11:21:43 -070065 const uint8_t& dimmId, uint8_t* smbiosTableStorage,
66 const std::string& motherboard) :
Cheng C Yang8c3fab62019-12-19 00:51:06 +080067
Patrick Williams77b9c472022-07-22 19:26:57 -050068 sdbusplus::server::object_t<
Cheng C Yang8c3fab62019-12-19 00:51:06 +080069 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>(
70 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050071 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
72 Decorator::server::Asset>(
73 bus, objPath.c_str()),
74 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
75 Decorator::server::LocationCode>(
76 bus, objPath.c_str()),
77 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
78 Connector::server::Slot>(
79 bus, objPath.c_str()),
80 sdbusplus::server::object_t<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053081 sdbusplus::xyz::openbmc_project::Inventory::server::Item>(
82 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050083 sdbusplus::server::object_t<
Jie Yange7cf3192021-08-20 11:21:43 -070084 sdbusplus::xyz::openbmc_project::Association::server::Definitions>(
85 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050086 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
87 Decorator::server::OperationalStatus>(
88 bus, objPath.c_str()),
Jie Yange7cf3192021-08-20 11:21:43 -070089 dimmNum(dimmId), storage(smbiosTableStorage),
90 motherboardPath(motherboard)
Cheng C Yang8c3fab62019-12-19 00:51:06 +080091 {
92 memoryInfoUpdate();
93 }
94
95 void memoryInfoUpdate(void);
96
97 uint16_t memoryDataWidth(uint16_t value) override;
Jason M. Billse7770992021-05-14 13:24:33 -070098 size_t memorySizeInKB(size_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +080099 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;
Joshi-Mansi33c948a2021-03-20 00:58:50 +0530104 bool present(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800105 std::string serialNumber(std::string value) override;
106 std::string partNumber(std::string value) override;
Jie Yang31720392021-07-22 21:45:45 -0700107 std::string locationCode(std::string value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800108 uint8_t memoryAttributes(uint8_t value) override;
109 uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
Tim Leedc469c72021-07-20 10:55:58 +0800110 bool functional(bool value) override;
kasunath2eca4fe2022-08-17 17:30:07 -0700111 EccType ecc(EccType value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800112
113 private:
114 uint8_t dimmNum;
115
116 uint8_t* storage;
117
Jie Yange7cf3192021-08-20 11:21:43 -0700118 std::string motherboardPath;
119
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800120 void dimmSize(const uint16_t size);
Jason M. Billse7770992021-05-14 13:24:33 -0700121 void dimmSizeExt(const size_t size);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800122 void dimmDeviceLocator(const uint8_t positionNum, const uint8_t structLen,
123 uint8_t* dataIn);
124 void dimmType(const uint8_t type);
125 void dimmTypeDetail(const uint16_t detail);
126 void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen,
127 uint8_t* dataIn);
128 void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen,
129 uint8_t* dataIn);
130 void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
131 uint8_t* dataIn);
kasunath2eca4fe2022-08-17 17:30:07 -0700132 void updateEccType(uint16_t exPhyArrayHandle);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800133};
134
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700135struct MemoryInfo
136{
137 uint8_t type;
138 uint8_t length;
139 uint16_t handle;
140 uint16_t phyArrayHandle;
141 uint16_t errInfoHandle;
142 uint16_t totalWidth;
143 uint16_t dataWidth;
144 uint16_t size;
145 uint8_t formFactor;
146 uint8_t deviceSet;
147 uint8_t deviceLocator;
148 uint8_t bankLocator;
149 uint8_t memoryType;
150 uint16_t typeDetail;
151 uint16_t speed;
152 uint8_t manufacturer;
153 uint8_t serialNum;
154 uint8_t assetTag;
155 uint8_t partNum;
156 uint8_t attributes;
Jason M. Billse7770992021-05-14 13:24:33 -0700157 size_t extendedSize;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700158 uint16_t confClockSpeed;
159 uint16_t minimumVoltage;
160 uint16_t maximumVoltage;
161 uint16_t configuredVoltage;
162 uint8_t memoryTechnology;
163 uint16_t memoryOperatingModeCap;
164 uint8_t firwareVersion;
165 uint16_t modelManufId;
166 uint16_t modelProdId;
167 uint16_t memSubConManufId;
168 uint16_t memSubConProdId;
169 uint64_t nvSize;
170 uint64_t volatileSize;
171 uint64_t cacheSize;
172 uint64_t logicalSize;
173} __attribute__((packed));
174
kasunath2eca4fe2022-08-17 17:30:07 -0700175/**
176 * @brief Struct to represent SMBIOS 3.2 type-16 (Physical Memory Array) data.
177 */
178struct PhysicalMemoryArrayInfo
179{
180 uint8_t type;
181 uint8_t length;
182 uint16_t handle;
183 uint8_t location;
184 uint8_t use;
185 uint8_t memoryErrorCorrection;
186 uint32_t maximumCapacity;
187 uint16_t memoryErrorInformationHandle;
188 uint16_t numberOfMemoryDevices;
189 uint64_t extendedMaximumCapacity;
190} __attribute__((packed));
191static_assert(sizeof(PhysicalMemoryArrayInfo) == 23,
192 "Size of PhysicalMemoryArrayInfo struct is incorrect.");
193
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800194const std::map<uint8_t, DeviceType> dimmTypeTable = {
195 {0x1, DeviceType::Other}, {0x2, DeviceType::Unknown},
196 {0x3, DeviceType::DRAM}, {0x4, DeviceType::EDRAM},
197 {0x5, DeviceType::VRAM}, {0x6, DeviceType::SRAM},
198 {0x7, DeviceType::RAM}, {0x8, DeviceType::ROM},
199 {0x9, DeviceType::FLASH}, {0xa, DeviceType::EEPROM},
200 {0xb, DeviceType::FEPROM}, {0xc, DeviceType::EPROM},
201 {0xd, DeviceType::CDRAM}, {0xe, DeviceType::ThreeDRAM},
202 {0xf, DeviceType::SDRAM}, {0x10, DeviceType::DDR_SGRAM},
203 {0x11, DeviceType::RDRAM}, {0x12, DeviceType::DDR},
204 {0x13, DeviceType::DDR2}, {0x14, DeviceType::DDR2_SDRAM_FB_DIMM},
205 {0x18, DeviceType::DDR3}, {0x19, DeviceType::FBD2},
206 {0x1a, DeviceType::DDR4}, {0x1b, DeviceType::LPDDR_SDRAM},
207 {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM},
208 {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical},
Mansi Joshi7ece93a2021-07-19 15:07:52 +0530209 {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2},
210 {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}};
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800211
212const std::array<std::string, 16> detailTable{
213 "Reserved", "Other", "Unknown", "Fast-paged",
214 "Static column", "Pseudo-static", "RAMBUS", "Synchronous",
215 "CMOS", "EDO", "Window DRAM", "Cache DRAM",
216 "Non-volatile", "Registered", "Unbuffered", "LRDIMM"};
217
kasunath2eca4fe2022-08-17 17:30:07 -0700218/**
219 * @brief Map SMBIOS 3.2 Memory Array Error Correction Types to
220 * xyz.openbmc_project.Inventory.Item.Dimm.Ecc types.
221 *
222 * SMBIOS 3.2 Memory Array Error Correction Types 'Unknown', 'None', 'CRC' are
223 * mapped to EccType::NoECC since the DBUs interface does not support those
224 * representations.
225 */
226const std::map<uint8_t, EccType> dimmEccTypeMap = {
227 {0x1, EccType::NoECC}, {0x2, EccType::NoECC},
228 {0x3, EccType::NoECC}, {0x4, EccType::AddressParity},
229 {0x5, EccType::SingleBitECC}, {0x6, EccType::MultiBitECC},
230 {0x7, EccType::NoECC}};
231
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800232} // namespace smbios
233
234} // namespace phosphor