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 | #include "dimm.hpp" |
| 18 | |
| 19 | #include "mdrv2.hpp" |
| 20 | |
kasunath | 634ec6a | 2022-07-25 15:34:17 -0700 | [diff] [blame] | 21 | #include <boost/algorithm/string.hpp> |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 22 | #include <phosphor-logging/elog-errors.hpp> |
Prithvi Pai | 6981b7f | 2025-04-02 10:33:29 +0530 | [diff] [blame] | 23 | #include <phosphor-logging/lg2.hpp> |
kasunath | 634ec6a | 2022-07-25 15:34:17 -0700 | [diff] [blame] | 24 | |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 25 | #include <fstream> |
| 26 | #include <iostream> |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 27 | #include <regex> |
| 28 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 29 | namespace phosphor |
| 30 | { |
| 31 | namespace smbios |
| 32 | { |
| 33 | |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 34 | #ifdef DIMM_ONLY_LOCATOR |
| 35 | bool onlyDimmLocationCode = true; |
| 36 | #else |
| 37 | bool onlyDimmLocationCode = false; |
| 38 | #endif |
| 39 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 40 | using DeviceType = |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 41 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::DeviceType; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 42 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 43 | using EccType = |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 44 | sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::Ecc; |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 45 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 46 | static constexpr uint16_t maxOldDimmSize = 0x7fff; |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 47 | |
| 48 | static constexpr const char* filename = |
| 49 | "/usr/share/smbios-mdr/memoryLocationTable.json"; |
| 50 | |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 51 | void Dimm::memoryInfoUpdate(uint8_t* smbiosTableStorage, |
| 52 | const std::string& motherboard) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 53 | { |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 54 | storage = smbiosTableStorage; |
| 55 | motherboardPath = motherboard; |
| 56 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 57 | uint8_t* dataIn = storage; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 58 | |
| 59 | dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType); |
| 60 | |
| 61 | if (dataIn == nullptr) |
| 62 | { |
| 63 | return; |
| 64 | } |
| 65 | for (uint8_t index = 0; index < dimmNum; index++) |
| 66 | { |
| 67 | dataIn = smbiosNextPtr(dataIn); |
| 68 | if (dataIn == nullptr) |
| 69 | { |
| 70 | return; |
| 71 | } |
| 72 | dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType); |
| 73 | if (dataIn == nullptr) |
| 74 | { |
| 75 | return; |
| 76 | } |
| 77 | } |
| 78 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 79 | auto memoryInfo = reinterpret_cast<struct MemoryInfo*>(dataIn); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 80 | |
| 81 | memoryDataWidth(memoryInfo->dataWidth); |
Joseph Fu | 410bbc2 | 2023-07-12 19:01:04 +0800 | [diff] [blame] | 82 | memoryTotalWidth(memoryInfo->totalWidth); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 83 | |
| 84 | if (memoryInfo->size == maxOldDimmSize) |
| 85 | { |
| 86 | dimmSizeExt(memoryInfo->extendedSize); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | dimmSize(memoryInfo->size); |
| 91 | } |
Tom Tung | 39cc368 | 2023-03-15 04:44:04 +0800 | [diff] [blame] | 92 | // If the size is 0, no memory device is installed in the socket. |
| 93 | const auto isDimmPresent = memoryInfo->size > 0; |
| 94 | present(isDimmPresent); |
| 95 | functional(isDimmPresent); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 96 | |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 97 | dimmDeviceLocator(memoryInfo->bankLocator, memoryInfo->deviceLocator, |
| 98 | memoryInfo->length, dataIn); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 99 | dimmType(memoryInfo->memoryType); |
| 100 | dimmTypeDetail(memoryInfo->typeDetail); |
| 101 | maxMemorySpeedInMhz(memoryInfo->speed); |
Prithvi Pai | 1aea7e4 | 2025-04-11 15:00:26 +0530 | [diff] [blame^] | 102 | updateFormFactor(memoryInfo->formFactor); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 103 | dimmManufacturer(memoryInfo->manufacturer, memoryInfo->length, dataIn); |
| 104 | dimmSerialNum(memoryInfo->serialNum, memoryInfo->length, dataIn); |
| 105 | dimmPartNum(memoryInfo->partNum, memoryInfo->length, dataIn); |
| 106 | memoryAttributes(memoryInfo->attributes); |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 107 | dimmMedia(memoryInfo->memoryTechnology); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 108 | memoryConfiguredSpeedInMhz(memoryInfo->confClockSpeed); |
| 109 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 110 | updateEccType(memoryInfo->phyArrayHandle); |
| 111 | |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 112 | if (!motherboardPath.empty()) |
| 113 | { |
| 114 | std::vector<std::tuple<std::string, std::string, std::string>> assocs; |
| 115 | assocs.emplace_back("chassis", "memories", motherboardPath); |
| 116 | association::associations(assocs); |
| 117 | } |
| 118 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 119 | return; |
| 120 | } |
| 121 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 122 | void Dimm::updateEccType(uint16_t exPhyArrayHandle) |
| 123 | { |
| 124 | uint8_t* dataIn = storage; |
| 125 | |
| 126 | while (dataIn != nullptr) |
| 127 | { |
| 128 | dataIn = getSMBIOSTypePtr(dataIn, physicalMemoryArrayType); |
| 129 | if (dataIn == nullptr) |
| 130 | { |
Prithvi Pai | 6981b7f | 2025-04-02 10:33:29 +0530 | [diff] [blame] | 131 | lg2::error("Failed to get SMBIOS table type-16 data."); |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 132 | return; |
| 133 | } |
| 134 | |
| 135 | auto info = reinterpret_cast<struct PhysicalMemoryArrayInfo*>(dataIn); |
| 136 | if (info->handle == exPhyArrayHandle) |
| 137 | { |
| 138 | std::map<uint8_t, EccType>::const_iterator it = |
| 139 | dimmEccTypeMap.find(info->memoryErrorCorrection); |
| 140 | if (it == dimmEccTypeMap.end()) |
| 141 | { |
| 142 | ecc(EccType::NoECC); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | ecc(it->second); |
| 147 | } |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | dataIn = smbiosNextPtr(dataIn); |
| 152 | } |
Prithvi Pai | 6981b7f | 2025-04-02 10:33:29 +0530 | [diff] [blame] | 153 | lg2::error( |
| 154 | "Failed find the corresponding SMBIOS table type-16 data for dimm: {DIMM}", |
| 155 | "DIMM", dimmNum); |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | EccType Dimm::ecc(EccType value) |
| 159 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 160 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::ecc( |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 161 | value); |
| 162 | } |
| 163 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 164 | uint16_t Dimm::memoryDataWidth(uint16_t value) |
| 165 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 166 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 167 | memoryDataWidth(value); |
| 168 | } |
| 169 | |
Joseph Fu | 410bbc2 | 2023-07-12 19:01:04 +0800 | [diff] [blame] | 170 | uint16_t Dimm::memoryTotalWidth(uint16_t value) |
| 171 | { |
| 172 | return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm:: |
| 173 | memoryTotalWidth(value); |
| 174 | } |
| 175 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 176 | static constexpr uint16_t baseNewVersionDimmSize = 0x8000; |
| 177 | static constexpr uint16_t dimmSizeUnit = 1024; |
| 178 | void Dimm::dimmSize(const uint16_t size) |
| 179 | { |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 180 | uint32_t result = size & maxOldDimmSize; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 181 | if (0 == (size & baseNewVersionDimmSize)) |
| 182 | { |
| 183 | result = result * dimmSizeUnit; |
| 184 | } |
| 185 | memorySizeInKB(result); |
| 186 | } |
| 187 | |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 188 | void Dimm::dimmSizeExt(uint32_t size) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 189 | { |
| 190 | size = size * dimmSizeUnit; |
| 191 | memorySizeInKB(size); |
| 192 | } |
| 193 | |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 194 | size_t Dimm::memorySizeInKB(size_t value) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 195 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 196 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 197 | memorySizeInKB(value); |
| 198 | } |
| 199 | |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 200 | void Dimm::dimmDeviceLocator(const uint8_t bankLocatorPositionNum, |
| 201 | const uint8_t deviceLocatorPositionNum, |
| 202 | const uint8_t structLen, uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 203 | { |
Patrick Williams | 1d73dcc | 2024-08-16 15:21:42 -0400 | [diff] [blame] | 204 | std::string deviceLocator = |
| 205 | positionToString(deviceLocatorPositionNum, structLen, dataIn); |
| 206 | std::string bankLocator = |
| 207 | positionToString(bankLocatorPositionNum, structLen, dataIn); |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 208 | |
| 209 | std::string result; |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 210 | if (bankLocator.empty() || onlyDimmLocationCode) |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 211 | { |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 212 | result = deviceLocator; |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 213 | } |
| 214 | else |
| 215 | { |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 216 | result = bankLocator + " " + deviceLocator; |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 217 | } |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 218 | |
| 219 | memoryDeviceLocator(result); |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 220 | |
| 221 | locationCode(result); |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 222 | const std::string substrCpu = "CPU"; |
| 223 | auto cpuPos = deviceLocator.find(substrCpu); |
| 224 | |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 225 | auto data = parseConfigFile(); |
| 226 | |
| 227 | if (!data.empty()) |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 228 | { |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 229 | auto it = data.find(deviceLocator); |
| 230 | |
| 231 | if (it != data.end()) |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 232 | { |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 233 | uint8_t memoryControllerValue = |
| 234 | it.value()["MemoryController"].get<uint8_t>(); |
| 235 | uint8_t socketValue = it.value()["Socket"].get<uint8_t>(); |
| 236 | uint8_t slotValue = it.value()["Slot"].get<uint8_t>(); |
| 237 | uint8_t channelValue = it.value()["Channel"].get<uint8_t>(); |
| 238 | |
Chanh Nguyen | 9a6ac03 | 2025-01-09 07:03:15 +0000 | [diff] [blame] | 239 | socket(socketValue); |
| 240 | memoryController(memoryControllerValue); |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 241 | slot(slotValue); |
| 242 | channel(channelValue); |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 243 | } |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 244 | else |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 245 | { |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 246 | socket(0); |
| 247 | memoryController(0); |
| 248 | slot(0); |
| 249 | channel(0); |
Prithvi Pai | 6981b7f | 2025-04-02 10:33:29 +0530 | [diff] [blame] | 250 | lg2::error("Failed find the corresponding table for dimm {DIMM}", |
| 251 | "DIMM", deviceLocator.c_str()); |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | if (cpuPos != std::string::npos) |
| 257 | { |
| 258 | std::string socketString = |
| 259 | deviceLocator.substr(cpuPos + substrCpu.length(), 1); |
| 260 | try |
| 261 | { |
| 262 | uint8_t socketNum = |
| 263 | static_cast<uint8_t>(std::stoi(socketString) + 1); |
| 264 | socket(socketNum); |
| 265 | } |
| 266 | catch (const sdbusplus::exception_t& ex) |
| 267 | { |
Prithvi Pai | 6981b7f | 2025-04-02 10:33:29 +0530 | [diff] [blame] | 268 | lg2::error("std::stoi operation failed {ERROR}", "ERROR", |
| 269 | ex.what()); |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 270 | } |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | const std::string substrDimm = "DIMM"; |
| 275 | auto dimmPos = deviceLocator.find(substrDimm); |
| 276 | |
| 277 | if (dimmPos != std::string::npos) |
| 278 | { |
| 279 | std::string slotString = |
| 280 | deviceLocator.substr(dimmPos + substrDimm.length() + 1); |
| 281 | /* slotString is extracted from substrDimm (DIMM_A) if slotString is |
| 282 | * single alphabet like A, B , C.. then assign ASCII value of slotString |
| 283 | * to slot */ |
| 284 | if ((std::regex_match(slotString, std::regex("^[A-Za-z]+$"))) && |
| 285 | (slotString.length() == 1)) |
| 286 | { |
| 287 | slot(static_cast<uint8_t>(toupper(slotString[0]))); |
| 288 | } |
| 289 | } |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | std::string Dimm::memoryDeviceLocator(std::string value) |
| 293 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 294 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 295 | memoryDeviceLocator(value); |
| 296 | } |
| 297 | |
| 298 | void Dimm::dimmType(const uint8_t type) |
| 299 | { |
| 300 | std::map<uint8_t, DeviceType>::const_iterator it = dimmTypeTable.find(type); |
| 301 | if (it == dimmTypeTable.end()) |
| 302 | { |
| 303 | memoryType(DeviceType::Unknown); |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | memoryType(it->second); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | DeviceType Dimm::memoryType(DeviceType value) |
| 312 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 313 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 314 | memoryType(value); |
| 315 | } |
| 316 | |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 317 | void Dimm::dimmMedia(const uint8_t type) |
| 318 | { |
| 319 | std::map<uint8_t, MemoryTechType>::const_iterator it = |
| 320 | dimmMemoryTechTypeMap.find(type); |
| 321 | if (it == dimmMemoryTechTypeMap.end()) |
| 322 | { |
| 323 | memoryMedia(MemoryTechType::Unknown); |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | memoryMedia(it->second); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | MemoryTechType Dimm::memoryMedia(MemoryTechType value) |
| 332 | { |
| 333 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
| 334 | memoryMedia(value); |
| 335 | } |
| 336 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 337 | void Dimm::dimmTypeDetail(uint16_t detail) |
| 338 | { |
| 339 | std::string result; |
| 340 | for (uint8_t index = 0; index < (8 * sizeof(detail)); index++) |
| 341 | { |
| 342 | if (detail & 0x01) |
| 343 | { |
| 344 | result += detailTable[index]; |
| 345 | } |
| 346 | detail >>= 1; |
| 347 | } |
| 348 | memoryTypeDetail(result); |
| 349 | } |
| 350 | |
| 351 | std::string Dimm::memoryTypeDetail(std::string value) |
| 352 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 353 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 354 | memoryTypeDetail(value); |
| 355 | } |
| 356 | |
| 357 | uint16_t Dimm::maxMemorySpeedInMhz(uint16_t value) |
| 358 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 359 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 360 | maxMemorySpeedInMhz(value); |
| 361 | } |
| 362 | |
| 363 | void Dimm::dimmManufacturer(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 364 | uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 365 | { |
| 366 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 367 | |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 368 | if (result == "NO DIMM") |
| 369 | { |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 370 | // No dimm presence so making manufacturer value as "" (instead of |
| 371 | // NO DIMM - as there won't be any manufacturer for DIMM which is not |
| 372 | // present). |
| 373 | result = ""; |
| 374 | } |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 375 | manufacturer(result); |
| 376 | } |
| 377 | |
| 378 | std::string Dimm::manufacturer(std::string value) |
| 379 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 380 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 381 | Asset::manufacturer(value); |
| 382 | } |
| 383 | |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 384 | bool Dimm::present(bool value) |
| 385 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 386 | return sdbusplus::server::xyz::openbmc_project::inventory::Item::present( |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 387 | value); |
| 388 | } |
| 389 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 390 | void Dimm::dimmSerialNum(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 391 | uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 392 | { |
| 393 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 394 | |
| 395 | serialNumber(result); |
| 396 | } |
| 397 | |
| 398 | std::string Dimm::serialNumber(std::string value) |
| 399 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 400 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 401 | Asset::serialNumber(value); |
| 402 | } |
| 403 | |
| 404 | void Dimm::dimmPartNum(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 405 | uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 406 | { |
| 407 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 408 | |
kasunath | 634ec6a | 2022-07-25 15:34:17 -0700 | [diff] [blame] | 409 | // Part number could contain spaces at the end. Eg: "abcd123 ". Since its |
| 410 | // unnecessary, we should remove them. |
| 411 | boost::algorithm::trim_right(result); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 412 | partNumber(result); |
| 413 | } |
| 414 | |
| 415 | std::string Dimm::partNumber(std::string value) |
| 416 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 417 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 418 | Asset::partNumber(value); |
| 419 | } |
| 420 | |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 421 | std::string Dimm::locationCode(std::string value) |
| 422 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 423 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 424 | LocationCode::locationCode(value); |
| 425 | } |
| 426 | |
George Liu | 036374a | 2023-06-15 08:47:46 +0800 | [diff] [blame] | 427 | size_t Dimm::memoryAttributes(size_t value) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 428 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 429 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 430 | memoryAttributes(value); |
| 431 | } |
| 432 | |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 433 | uint8_t Dimm::slot(uint8_t value) |
| 434 | { |
| 435 | return sdbusplus::server::xyz::openbmc_project::inventory::item::dimm:: |
| 436 | MemoryLocation::slot(value); |
| 437 | } |
| 438 | |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 439 | uint8_t Dimm::memoryController(uint8_t value) |
| 440 | { |
| 441 | return sdbusplus::server::xyz::openbmc_project::inventory::item::dimm:: |
| 442 | MemoryLocation::memoryController(value); |
| 443 | } |
| 444 | |
| 445 | uint8_t Dimm::channel(uint8_t value) |
| 446 | { |
| 447 | return sdbusplus::server::xyz::openbmc_project::inventory::item::dimm:: |
| 448 | MemoryLocation::channel(value); |
| 449 | } |
| 450 | |
Jayaprakash Mutyala | a1ff244 | 2023-06-15 07:10:07 +0000 | [diff] [blame] | 451 | uint8_t Dimm::socket(uint8_t value) |
| 452 | { |
| 453 | return sdbusplus::server::xyz::openbmc_project::inventory::item::dimm:: |
| 454 | MemoryLocation::socket(value); |
| 455 | } |
| 456 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 457 | uint16_t Dimm::memoryConfiguredSpeedInMhz(uint16_t value) |
| 458 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 459 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 460 | memoryConfiguredSpeedInMhz(value); |
| 461 | } |
| 462 | |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 463 | bool Dimm::functional(bool value) |
| 464 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 465 | return sdbusplus::server::xyz::openbmc_project::state::decorator:: |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 466 | OperationalStatus::functional(value); |
| 467 | } |
| 468 | |
Prithvi Pai | 1aea7e4 | 2025-04-11 15:00:26 +0530 | [diff] [blame^] | 469 | void Dimm::updateFormFactor(const uint8_t formFactorKey) |
| 470 | { |
| 471 | std::map<uint8_t, FormFactor>::const_iterator it = |
| 472 | dimmFormFactorMap.find(formFactorKey); |
| 473 | if (it != dimmFormFactorMap.end()) |
| 474 | { |
| 475 | formFactor(it->second); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | FormFactor Dimm::formFactor(FormFactor value) |
| 480 | { |
| 481 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
| 482 | formFactor(value); |
| 483 | } |
| 484 | |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 485 | Json Dimm::parseConfigFile() |
| 486 | { |
| 487 | std::ifstream memoryLocationFile(filename); |
| 488 | |
| 489 | if (!memoryLocationFile.is_open()) |
| 490 | { |
Prithvi Pai | 6981b7f | 2025-04-02 10:33:29 +0530 | [diff] [blame] | 491 | lg2::error("config JSON file not found, FILENAME {FILENAME}", |
| 492 | "FILENAME", filename); |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 493 | return {}; |
| 494 | } |
| 495 | |
| 496 | auto data = Json::parse(memoryLocationFile, nullptr, false); |
| 497 | if (data.is_discarded()) |
| 498 | { |
Prithvi Pai | 6981b7f | 2025-04-02 10:33:29 +0530 | [diff] [blame] | 499 | lg2::error("config readings JSON parser failure"); |
Tony Lee | 8f789c3 | 2024-07-10 20:01:43 +0800 | [diff] [blame] | 500 | return {}; |
| 501 | } |
| 502 | |
| 503 | return data; |
| 504 | } |
| 505 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 506 | } // namespace smbios |
| 507 | } // namespace phosphor |