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