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> |
kasunath | 634ec6a | 2022-07-25 15:34:17 -0700 | [diff] [blame] | 23 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 24 | namespace phosphor |
| 25 | { |
| 26 | namespace smbios |
| 27 | { |
| 28 | |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 29 | #ifdef DIMM_ONLY_LOCATOR |
| 30 | bool onlyDimmLocationCode = true; |
| 31 | #else |
| 32 | bool onlyDimmLocationCode = false; |
| 33 | #endif |
| 34 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 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 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 41 | static constexpr uint16_t maxOldDimmSize = 0x7fff; |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 42 | void Dimm::memoryInfoUpdate(uint8_t* smbiosTableStorage, |
| 43 | const std::string& motherboard) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 44 | { |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 45 | storage = smbiosTableStorage; |
| 46 | motherboardPath = motherboard; |
| 47 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 48 | uint8_t* dataIn = storage; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 49 | |
| 50 | dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType); |
| 51 | |
| 52 | if (dataIn == nullptr) |
| 53 | { |
| 54 | return; |
| 55 | } |
| 56 | for (uint8_t index = 0; index < dimmNum; index++) |
| 57 | { |
| 58 | dataIn = smbiosNextPtr(dataIn); |
| 59 | if (dataIn == nullptr) |
| 60 | { |
| 61 | return; |
| 62 | } |
| 63 | dataIn = getSMBIOSTypePtr(dataIn, memoryDeviceType); |
| 64 | if (dataIn == nullptr) |
| 65 | { |
| 66 | return; |
| 67 | } |
| 68 | } |
| 69 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 70 | auto memoryInfo = reinterpret_cast<struct MemoryInfo*>(dataIn); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 71 | |
| 72 | memoryDataWidth(memoryInfo->dataWidth); |
| 73 | |
| 74 | if (memoryInfo->size == maxOldDimmSize) |
| 75 | { |
| 76 | dimmSizeExt(memoryInfo->extendedSize); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | dimmSize(memoryInfo->size); |
| 81 | } |
Tom Tung | 39cc368 | 2023-03-15 04:44:04 +0800 | [diff] [blame] | 82 | // If the size is 0, no memory device is installed in the socket. |
| 83 | const auto isDimmPresent = memoryInfo->size > 0; |
| 84 | present(isDimmPresent); |
| 85 | functional(isDimmPresent); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 86 | |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 87 | dimmDeviceLocator(memoryInfo->bankLocator, memoryInfo->deviceLocator, |
| 88 | memoryInfo->length, dataIn); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 89 | dimmType(memoryInfo->memoryType); |
| 90 | dimmTypeDetail(memoryInfo->typeDetail); |
| 91 | maxMemorySpeedInMhz(memoryInfo->speed); |
| 92 | dimmManufacturer(memoryInfo->manufacturer, memoryInfo->length, dataIn); |
| 93 | dimmSerialNum(memoryInfo->serialNum, memoryInfo->length, dataIn); |
| 94 | dimmPartNum(memoryInfo->partNum, memoryInfo->length, dataIn); |
| 95 | memoryAttributes(memoryInfo->attributes); |
| 96 | memoryConfiguredSpeedInMhz(memoryInfo->confClockSpeed); |
| 97 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 98 | updateEccType(memoryInfo->phyArrayHandle); |
| 99 | |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 100 | if (!motherboardPath.empty()) |
| 101 | { |
| 102 | std::vector<std::tuple<std::string, std::string, std::string>> assocs; |
| 103 | assocs.emplace_back("chassis", "memories", motherboardPath); |
| 104 | association::associations(assocs); |
| 105 | } |
| 106 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 110 | void Dimm::updateEccType(uint16_t exPhyArrayHandle) |
| 111 | { |
| 112 | uint8_t* dataIn = storage; |
| 113 | |
| 114 | while (dataIn != nullptr) |
| 115 | { |
| 116 | dataIn = getSMBIOSTypePtr(dataIn, physicalMemoryArrayType); |
| 117 | if (dataIn == nullptr) |
| 118 | { |
| 119 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 120 | "Failed to get SMBIOS table type-16 data."); |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | auto info = reinterpret_cast<struct PhysicalMemoryArrayInfo*>(dataIn); |
| 125 | if (info->handle == exPhyArrayHandle) |
| 126 | { |
| 127 | std::map<uint8_t, EccType>::const_iterator it = |
| 128 | dimmEccTypeMap.find(info->memoryErrorCorrection); |
| 129 | if (it == dimmEccTypeMap.end()) |
| 130 | { |
| 131 | ecc(EccType::NoECC); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | ecc(it->second); |
| 136 | } |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | dataIn = smbiosNextPtr(dataIn); |
| 141 | } |
| 142 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 143 | "Failed find the corresponding SMBIOS table type-16 data for dimm:", |
| 144 | phosphor::logging::entry("DIMM:%d", dimmNum)); |
| 145 | } |
| 146 | |
| 147 | EccType Dimm::ecc(EccType value) |
| 148 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 149 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm::ecc( |
kasunath | 2eca4fe | 2022-08-17 17:30:07 -0700 | [diff] [blame] | 150 | value); |
| 151 | } |
| 152 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 153 | uint16_t Dimm::memoryDataWidth(uint16_t value) |
| 154 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 155 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 156 | memoryDataWidth(value); |
| 157 | } |
| 158 | |
| 159 | static constexpr uint16_t baseNewVersionDimmSize = 0x8000; |
| 160 | static constexpr uint16_t dimmSizeUnit = 1024; |
| 161 | void Dimm::dimmSize(const uint16_t size) |
| 162 | { |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 163 | uint32_t result = size & maxOldDimmSize; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 164 | if (0 == (size & baseNewVersionDimmSize)) |
| 165 | { |
| 166 | result = result * dimmSizeUnit; |
| 167 | } |
| 168 | memorySizeInKB(result); |
| 169 | } |
| 170 | |
Joseph Fu | 0b1d942 | 2023-03-31 17:47:12 +0800 | [diff] [blame] | 171 | void Dimm::dimmSizeExt(uint32_t size) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 172 | { |
| 173 | size = size * dimmSizeUnit; |
| 174 | memorySizeInKB(size); |
| 175 | } |
| 176 | |
Jason M. Bills | e777099 | 2021-05-14 13:24:33 -0700 | [diff] [blame] | 177 | size_t Dimm::memorySizeInKB(size_t value) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 178 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 179 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 180 | memorySizeInKB(value); |
| 181 | } |
| 182 | |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 183 | void Dimm::dimmDeviceLocator(const uint8_t bankLocatorPositionNum, |
| 184 | const uint8_t deviceLocatorPositionNum, |
| 185 | const uint8_t structLen, uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 186 | { |
Patrick Williams | c39d3df | 2023-05-10 07:51:14 -0500 | [diff] [blame] | 187 | std::string deviceLocator = positionToString(deviceLocatorPositionNum, |
| 188 | structLen, dataIn); |
| 189 | std::string bankLocator = positionToString(bankLocatorPositionNum, |
| 190 | structLen, dataIn); |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 191 | |
| 192 | std::string result; |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 193 | if (bankLocator.empty() || onlyDimmLocationCode) |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 194 | { |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 195 | result = deviceLocator; |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 196 | } |
| 197 | else |
| 198 | { |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 199 | result = bankLocator + " " + deviceLocator; |
Konstantin Aladyshev | 744b35a | 2022-11-02 08:34:27 +0000 | [diff] [blame] | 200 | } |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 201 | |
| 202 | memoryDeviceLocator(result); |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 203 | |
| 204 | locationCode(result); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | std::string Dimm::memoryDeviceLocator(std::string value) |
| 208 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 209 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 210 | memoryDeviceLocator(value); |
| 211 | } |
| 212 | |
| 213 | void Dimm::dimmType(const uint8_t type) |
| 214 | { |
| 215 | std::map<uint8_t, DeviceType>::const_iterator it = dimmTypeTable.find(type); |
| 216 | if (it == dimmTypeTable.end()) |
| 217 | { |
| 218 | memoryType(DeviceType::Unknown); |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | memoryType(it->second); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | DeviceType Dimm::memoryType(DeviceType value) |
| 227 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 228 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 229 | memoryType(value); |
| 230 | } |
| 231 | |
| 232 | void Dimm::dimmTypeDetail(uint16_t detail) |
| 233 | { |
| 234 | std::string result; |
| 235 | for (uint8_t index = 0; index < (8 * sizeof(detail)); index++) |
| 236 | { |
| 237 | if (detail & 0x01) |
| 238 | { |
| 239 | result += detailTable[index]; |
| 240 | } |
| 241 | detail >>= 1; |
| 242 | } |
| 243 | memoryTypeDetail(result); |
| 244 | } |
| 245 | |
| 246 | std::string Dimm::memoryTypeDetail(std::string value) |
| 247 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 248 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 249 | memoryTypeDetail(value); |
| 250 | } |
| 251 | |
| 252 | uint16_t Dimm::maxMemorySpeedInMhz(uint16_t value) |
| 253 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 254 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 255 | maxMemorySpeedInMhz(value); |
| 256 | } |
| 257 | |
| 258 | void Dimm::dimmManufacturer(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 259 | uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 260 | { |
| 261 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 262 | |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 263 | if (result == "NO DIMM") |
| 264 | { |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 265 | // No dimm presence so making manufacturer value as "" (instead of |
| 266 | // NO DIMM - as there won't be any manufacturer for DIMM which is not |
| 267 | // present). |
| 268 | result = ""; |
| 269 | } |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 270 | manufacturer(result); |
| 271 | } |
| 272 | |
| 273 | std::string Dimm::manufacturer(std::string value) |
| 274 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 275 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 276 | Asset::manufacturer(value); |
| 277 | } |
| 278 | |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 279 | bool Dimm::present(bool value) |
| 280 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 281 | return sdbusplus::server::xyz::openbmc_project::inventory::Item::present( |
Joshi-Mansi | 33c948a | 2021-03-20 00:58:50 +0530 | [diff] [blame] | 282 | value); |
| 283 | } |
| 284 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 285 | void Dimm::dimmSerialNum(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 286 | uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 287 | { |
| 288 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 289 | |
| 290 | serialNumber(result); |
| 291 | } |
| 292 | |
| 293 | std::string Dimm::serialNumber(std::string value) |
| 294 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 295 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 296 | Asset::serialNumber(value); |
| 297 | } |
| 298 | |
| 299 | void Dimm::dimmPartNum(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 300 | uint8_t* dataIn) |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 301 | { |
| 302 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 303 | |
kasunath | 634ec6a | 2022-07-25 15:34:17 -0700 | [diff] [blame] | 304 | // Part number could contain spaces at the end. Eg: "abcd123 ". Since its |
| 305 | // unnecessary, we should remove them. |
| 306 | boost::algorithm::trim_right(result); |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 307 | partNumber(result); |
| 308 | } |
| 309 | |
| 310 | std::string Dimm::partNumber(std::string value) |
| 311 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 312 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 313 | Asset::partNumber(value); |
| 314 | } |
| 315 | |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 316 | std::string Dimm::locationCode(std::string value) |
| 317 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 318 | return sdbusplus::server::xyz::openbmc_project::inventory::decorator:: |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 319 | LocationCode::locationCode(value); |
| 320 | } |
| 321 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 322 | uint8_t Dimm::memoryAttributes(uint8_t value) |
| 323 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 324 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 325 | memoryAttributes(value); |
| 326 | } |
| 327 | |
| 328 | uint16_t Dimm::memoryConfiguredSpeedInMhz(uint16_t value) |
| 329 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 330 | return sdbusplus::server::xyz::openbmc_project::inventory::item::Dimm:: |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 331 | memoryConfiguredSpeedInMhz(value); |
| 332 | } |
| 333 | |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 334 | bool Dimm::functional(bool value) |
| 335 | { |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 336 | return sdbusplus::server::xyz::openbmc_project::state::decorator:: |
Tim Lee | dc469c7 | 2021-07-20 10:55:58 +0800 | [diff] [blame] | 337 | OperationalStatus::functional(value); |
| 338 | } |
| 339 | |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 340 | } // namespace smbios |
| 341 | } // namespace phosphor |