Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 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 |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 18 | #include "smbios_mdrv2.hpp" |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 19 | |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 20 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Jie Yang | 41654fc | 2021-09-07 20:26:32 -0700 | [diff] [blame] | 21 | #include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp> |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 22 | #include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp> |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 23 | #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp> |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame^] | 24 | #include <xyz/openbmc_project/Inventory/Item/Dimm/MemoryLocation/server.hpp> |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 25 | #include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp> |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 26 | #include <xyz/openbmc_project/Inventory/Item/server.hpp> |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 27 | #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 28 | |
| 29 | namespace phosphor |
| 30 | { |
| 31 | |
| 32 | namespace smbios |
| 33 | { |
| 34 | |
| 35 | using DeviceType = |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 36 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::DeviceType; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 37 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 38 | using EccType = |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 39 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::Ecc; |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 40 | |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame^] | 41 | using MemoryTechType = |
| 42 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::MemoryTech; |
| 43 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 44 | class Dimm : |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 45 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 46 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>, |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame^] | 47 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 48 | inventory::item::dimm::MemoryLocation>, |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 49 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 50 | sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset>, |
| 51 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 52 | inventory::decorator::LocationCode>, |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 53 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 54 | sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot>, |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 55 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 56 | sdbusplus::server::xyz::openbmc_project::inventory::Item>, |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 57 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 58 | sdbusplus::server::xyz::openbmc_project::association::Definitions>, |
| 59 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::state:: |
| 60 | decorator::OperationalStatus> |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 61 | { |
| 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 Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 70 | Dimm(sdbusplus::bus_t& bus, const std::string& objPath, |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 71 | const uint8_t& dimmId, uint8_t* smbiosTableStorage, |
| 72 | const std::string& motherboard) : |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 73 | |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 74 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 75 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>( |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 76 | bus, objPath.c_str()), |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 77 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame^] | 78 | inventory::item::dimm::MemoryLocation>( |
| 79 | bus, objPath.c_str()), |
| 80 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 81 | inventory::decorator::Asset>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 82 | bus, objPath.c_str()), |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 83 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 84 | inventory::decorator::LocationCode>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 85 | bus, objPath.c_str()), |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 86 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 87 | inventory::connector::Slot>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 88 | bus, objPath.c_str()), |
| 89 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 90 | sdbusplus::server::xyz::openbmc_project::inventory::Item>( |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 91 | bus, objPath.c_str()), |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 92 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 93 | sdbusplus::server::xyz::openbmc_project::association::Definitions>( |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 94 | bus, objPath.c_str()), |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 95 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 96 | state::decorator::OperationalStatus>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 97 | bus, objPath.c_str()), |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 98 | dimmNum(dimmId) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 99 | { |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 100 | memoryInfoUpdate(smbiosTableStorage, motherboard); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 101 | } |
| 102 | |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 103 | void memoryInfoUpdate(uint8_t* smbiosTableStorage, |
| 104 | const std::string& motherboard); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 105 | |
| 106 | uint16_t memoryDataWidth(uint16_t value) override; |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 107 | size_t memorySizeInKB(size_t value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 108 | std::string memoryDeviceLocator(std::string value) override; |
| 109 | DeviceType memoryType(DeviceType value) override; |
| 110 | std::string memoryTypeDetail(std::string value) override; |
| 111 | uint16_t maxMemorySpeedInMhz(uint16_t value) override; |
| 112 | std::string manufacturer(std::string value) override; |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 113 | bool present(bool value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 114 | std::string serialNumber(std::string value) override; |
| 115 | std::string partNumber(std::string value) override; |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 116 | std::string locationCode(std::string value) override; |
George Liu | 036374a | 2023-06-15 08:47:46 +0800 | [diff] [blame] | 117 | size_t memoryAttributes(size_t value) override; |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame^] | 118 | MemoryTechType memoryMedia(MemoryTechType value) override; |
| 119 | uint8_t slot(uint8_t value) override; |
| 120 | uint8_t socket(uint8_t value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 121 | uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override; |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 122 | bool functional(bool value) override; |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 123 | EccType ecc(EccType value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 124 | |
| 125 | private: |
| 126 | uint8_t dimmNum; |
| 127 | |
| 128 | uint8_t* storage; |
| 129 | |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 130 | std::string motherboardPath; |
| 131 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 132 | void dimmSize(const uint16_t size); |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 133 | void dimmSizeExt(const uint32_t size); |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 134 | void dimmDeviceLocator(const uint8_t bankLocatorPositionNum, |
| 135 | const uint8_t deviceLocatorPositionNum, |
| 136 | const uint8_t structLen, uint8_t* dataIn); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 137 | void dimmType(const uint8_t type); |
| 138 | void dimmTypeDetail(const uint16_t detail); |
| 139 | void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen, |
| 140 | uint8_t* dataIn); |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame^] | 141 | void dimmMedia(const uint8_t type); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 142 | void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen, |
| 143 | uint8_t* dataIn); |
| 144 | void dimmPartNum(const uint8_t positionNum, const uint8_t structLen, |
| 145 | uint8_t* dataIn); |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 146 | void updateEccType(uint16_t exPhyArrayHandle); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 147 | }; |
| 148 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 149 | struct MemoryInfo |
| 150 | { |
| 151 | uint8_t type; |
| 152 | uint8_t length; |
| 153 | uint16_t handle; |
| 154 | uint16_t phyArrayHandle; |
| 155 | uint16_t errInfoHandle; |
| 156 | uint16_t totalWidth; |
| 157 | uint16_t dataWidth; |
| 158 | uint16_t size; |
| 159 | uint8_t formFactor; |
| 160 | uint8_t deviceSet; |
| 161 | uint8_t deviceLocator; |
| 162 | uint8_t bankLocator; |
| 163 | uint8_t memoryType; |
| 164 | uint16_t typeDetail; |
| 165 | uint16_t speed; |
| 166 | uint8_t manufacturer; |
| 167 | uint8_t serialNum; |
| 168 | uint8_t assetTag; |
| 169 | uint8_t partNum; |
George Liu | 036374a | 2023-06-15 08:47:46 +0800 | [diff] [blame] | 170 | size_t attributes; |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 171 | uint32_t extendedSize; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 172 | uint16_t confClockSpeed; |
| 173 | uint16_t minimumVoltage; |
| 174 | uint16_t maximumVoltage; |
| 175 | uint16_t configuredVoltage; |
| 176 | uint8_t memoryTechnology; |
| 177 | uint16_t memoryOperatingModeCap; |
| 178 | uint8_t firwareVersion; |
| 179 | uint16_t modelManufId; |
| 180 | uint16_t modelProdId; |
| 181 | uint16_t memSubConManufId; |
| 182 | uint16_t memSubConProdId; |
| 183 | uint64_t nvSize; |
| 184 | uint64_t volatileSize; |
| 185 | uint64_t cacheSize; |
| 186 | uint64_t logicalSize; |
| 187 | } __attribute__((packed)); |
| 188 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 189 | /** |
| 190 | * @brief Struct to represent SMBIOS 3.2 type-16 (Physical Memory Array) data. |
| 191 | */ |
| 192 | struct PhysicalMemoryArrayInfo |
| 193 | { |
| 194 | uint8_t type; |
| 195 | uint8_t length; |
| 196 | uint16_t handle; |
| 197 | uint8_t location; |
| 198 | uint8_t use; |
| 199 | uint8_t memoryErrorCorrection; |
| 200 | uint32_t maximumCapacity; |
| 201 | uint16_t memoryErrorInformationHandle; |
| 202 | uint16_t numberOfMemoryDevices; |
| 203 | uint64_t extendedMaximumCapacity; |
| 204 | } __attribute__((packed)); |
| 205 | static_assert(sizeof(PhysicalMemoryArrayInfo) == 23, |
| 206 | "Size of PhysicalMemoryArrayInfo struct is incorrect."); |
| 207 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 208 | const std::map<uint8_t, DeviceType> dimmTypeTable = { |
| 209 | {0x1, DeviceType::Other}, {0x2, DeviceType::Unknown}, |
| 210 | {0x3, DeviceType::DRAM}, {0x4, DeviceType::EDRAM}, |
| 211 | {0x5, DeviceType::VRAM}, {0x6, DeviceType::SRAM}, |
| 212 | {0x7, DeviceType::RAM}, {0x8, DeviceType::ROM}, |
| 213 | {0x9, DeviceType::FLASH}, {0xa, DeviceType::EEPROM}, |
| 214 | {0xb, DeviceType::FEPROM}, {0xc, DeviceType::EPROM}, |
| 215 | {0xd, DeviceType::CDRAM}, {0xe, DeviceType::ThreeDRAM}, |
| 216 | {0xf, DeviceType::SDRAM}, {0x10, DeviceType::DDR_SGRAM}, |
| 217 | {0x11, DeviceType::RDRAM}, {0x12, DeviceType::DDR}, |
| 218 | {0x13, DeviceType::DDR2}, {0x14, DeviceType::DDR2_SDRAM_FB_DIMM}, |
| 219 | {0x18, DeviceType::DDR3}, {0x19, DeviceType::FBD2}, |
| 220 | {0x1a, DeviceType::DDR4}, {0x1b, DeviceType::LPDDR_SDRAM}, |
| 221 | {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM}, |
| 222 | {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical}, |
Mansi Joshi | 7ece93a | 2021-07-19 15:07:52 +0530 | [diff] [blame] | 223 | {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2}, |
| 224 | {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}}; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 225 | |
| 226 | const std::array<std::string, 16> detailTable{ |
| 227 | "Reserved", "Other", "Unknown", "Fast-paged", |
| 228 | "Static column", "Pseudo-static", "RAMBUS", "Synchronous", |
| 229 | "CMOS", "EDO", "Window DRAM", "Cache DRAM", |
| 230 | "Non-volatile", "Registered", "Unbuffered", "LRDIMM"}; |
| 231 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 232 | /** |
| 233 | * @brief Map SMBIOS 3.2 Memory Array Error Correction Types to |
| 234 | * xyz.openbmc_project.Inventory.Item.Dimm.Ecc types. |
| 235 | * |
| 236 | * SMBIOS 3.2 Memory Array Error Correction Types 'Unknown', 'None', 'CRC' are |
| 237 | * mapped to EccType::NoECC since the DBUs interface does not support those |
| 238 | * representations. |
| 239 | */ |
| 240 | const std::map<uint8_t, EccType> dimmEccTypeMap = { |
| 241 | {0x1, EccType::NoECC}, {0x2, EccType::NoECC}, |
| 242 | {0x3, EccType::NoECC}, {0x4, EccType::AddressParity}, |
| 243 | {0x5, EccType::SingleBitECC}, {0x6, EccType::MultiBitECC}, |
| 244 | {0x7, EccType::NoECC}}; |
| 245 | |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame^] | 246 | const std::map<uint8_t, MemoryTechType> dimmMemoryTechTypeMap = { |
| 247 | {0x1, MemoryTechType::Other}, {0x2, MemoryTechType::Unknown}, |
| 248 | {0x3, MemoryTechType::DRAM}, {0x4, MemoryTechType::NVDIMM_N}, |
| 249 | {0x5, MemoryTechType::NVDIMM_F}, {0x6, MemoryTechType::NVDIMM_P}, |
| 250 | {0x7, MemoryTechType::IntelOptane}}; |
| 251 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 252 | } // namespace smbios |
| 253 | |
| 254 | } // namespace phosphor |