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