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> |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 24 | #include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp> |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 25 | #include <xyz/openbmc_project/Inventory/Item/server.hpp> |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 26 | #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 27 | |
| 28 | namespace phosphor |
| 29 | { |
| 30 | |
| 31 | namespace smbios |
| 32 | { |
| 33 | |
| 34 | using DeviceType = |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 35 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::DeviceType; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 36 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 37 | using EccType = |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 38 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::Ecc; |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 39 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 40 | class Dimm : |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 41 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 42 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>, |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 43 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 44 | sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset>, |
| 45 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 46 | inventory::decorator::LocationCode>, |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 47 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 48 | sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot>, |
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::Item>, |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 51 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 52 | sdbusplus::server::xyz::openbmc_project::association::Definitions>, |
| 53 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::state:: |
| 54 | decorator::OperationalStatus> |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 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 | |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 64 | Dimm(sdbusplus::bus_t& bus, const std::string& objPath, |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 65 | const uint8_t& dimmId, uint8_t* smbiosTableStorage, |
| 66 | const std::string& motherboard) : |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 67 | |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 68 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 69 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm>( |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 70 | bus, objPath.c_str()), |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 71 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 72 | inventory::decorator::Asset>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 73 | bus, objPath.c_str()), |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 74 | sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project:: |
| 75 | inventory::decorator::LocationCode>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [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:: |
| 78 | inventory::connector::Slot>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 79 | bus, objPath.c_str()), |
| 80 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 81 | sdbusplus::server::xyz::openbmc_project::inventory::Item>( |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 82 | bus, objPath.c_str()), |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 83 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 84 | sdbusplus::server::xyz::openbmc_project::association::Definitions>( |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [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 | state::decorator::OperationalStatus>( |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 88 | bus, objPath.c_str()), |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 89 | dimmNum(dimmId) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 90 | { |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 91 | memoryInfoUpdate(smbiosTableStorage, motherboard); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 92 | } |
| 93 | |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 94 | void memoryInfoUpdate(uint8_t* smbiosTableStorage, |
| 95 | const std::string& motherboard); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 96 | |
| 97 | uint16_t memoryDataWidth(uint16_t value) override; |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 98 | size_t memorySizeInKB(size_t value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 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; |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 104 | bool present(bool value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 105 | std::string serialNumber(std::string value) override; |
| 106 | std::string partNumber(std::string value) override; |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 107 | std::string locationCode(std::string value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 108 | uint8_t memoryAttributes(uint8_t value) override; |
| 109 | uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override; |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 110 | bool functional(bool value) override; |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 111 | EccType ecc(EccType value) override; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 112 | |
| 113 | private: |
| 114 | uint8_t dimmNum; |
| 115 | |
| 116 | uint8_t* storage; |
| 117 | |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 118 | std::string motherboardPath; |
| 119 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 120 | void dimmSize(const uint16_t size); |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 121 | void dimmSizeExt(const uint32_t size); |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 122 | void dimmDeviceLocator(const uint8_t bankLocatorPositionNum, |
| 123 | const uint8_t deviceLocatorPositionNum, |
| 124 | const uint8_t structLen, uint8_t* dataIn); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 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); |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 133 | void updateEccType(uint16_t exPhyArrayHandle); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 134 | }; |
| 135 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 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; |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 158 | uint32_t extendedSize; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 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 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 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 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 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}, |
Mansi Joshi | 7ece93a | 2021-07-19 15:07:52 +0530 | [diff] [blame] | 210 | {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2}, |
| 211 | {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}}; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 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 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 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 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 233 | } // namespace smbios |
| 234 | |
| 235 | } // namespace phosphor |