Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +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 "cpu.hpp" |
| 18 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 19 | #include <bitset> |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 20 | #include <map> |
| 21 | |
| 22 | namespace phosphor |
| 23 | { |
| 24 | namespace smbios |
| 25 | { |
| 26 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 27 | void Cpu::socket(const uint8_t positionNum, const uint8_t structLen, |
| 28 | uint8_t* dataIn) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 29 | { |
| 30 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 31 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 32 | processor::socket(result); |
Jie Yang | 3172039 | 2021-07-22 21:45:45 -0700 | [diff] [blame] | 33 | |
| 34 | location::locationCode(result); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 35 | } |
| 36 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 37 | void Cpu::family(const uint8_t value) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 38 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 39 | std::map<uint8_t, const char*>::const_iterator it = familyTable.find(value); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 40 | if (it == familyTable.end()) |
| 41 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 42 | processor::family("Unknown Processor Family"); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 43 | } |
| 44 | else |
| 45 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 46 | processor::family(it->second); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 50 | void Cpu::manufacturer(const uint8_t positionNum, const uint8_t structLen, |
| 51 | uint8_t* dataIn) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 52 | { |
| 53 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 54 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 55 | asset::manufacturer(result); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 56 | } |
| 57 | |
Charles Boyer | e643169 | 2021-08-31 16:47:47 -0500 | [diff] [blame] | 58 | void Cpu::partNumber(const uint8_t positionNum, const uint8_t structLen, |
| 59 | uint8_t* dataIn) |
| 60 | { |
| 61 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 62 | |
| 63 | asset::partNumber(result); |
| 64 | } |
| 65 | |
| 66 | void Cpu::serialNumber(const uint8_t positionNum, const uint8_t structLen, |
| 67 | uint8_t* dataIn) |
| 68 | { |
| 69 | std::string result = positionToString(positionNum, structLen, dataIn); |
| 70 | |
| 71 | asset::serialNumber(result); |
| 72 | } |
| 73 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 74 | void Cpu::version(const uint8_t positionNum, const uint8_t structLen, |
| 75 | uint8_t* dataIn) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 76 | { |
| 77 | std::string result; |
| 78 | |
| 79 | result = positionToString(positionNum, structLen, dataIn); |
| 80 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 81 | rev::version(result); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 84 | void Cpu::characteristics(uint16_t value) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 85 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 86 | std::vector<processor::Capability> result; |
| 87 | std::optional<processor::Capability> cap; |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 88 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 89 | std::bitset<16> charBits = value; |
| 90 | for (uint8_t index = 0; index < charBits.size(); index++) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 91 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 92 | if (charBits.test(index)) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 93 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 94 | if (cap = characteristicsTable[index]) |
| 95 | { |
| 96 | result.emplace_back(*cap); |
| 97 | } |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 98 | } |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 99 | } |
| 100 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 101 | processor::characteristics(result); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static constexpr uint8_t maxOldVersionCount = 0xff; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 105 | void Cpu::infoUpdate(void) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 106 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 107 | uint8_t* dataIn = storage; |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 108 | |
| 109 | dataIn = getSMBIOSTypePtr(dataIn, processorsType); |
| 110 | if (dataIn == nullptr) |
| 111 | { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | for (uint8_t index = 0; index < cpuNum; index++) |
| 116 | { |
| 117 | dataIn = smbiosNextPtr(dataIn); |
| 118 | if (dataIn == nullptr) |
| 119 | { |
| 120 | return; |
| 121 | } |
| 122 | dataIn = getSMBIOSTypePtr(dataIn, processorsType); |
| 123 | if (dataIn == nullptr) |
| 124 | { |
| 125 | return; |
| 126 | } |
| 127 | } |
| 128 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 129 | auto cpuInfo = reinterpret_cast<struct ProcessorInfo*>(dataIn); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 130 | |
Jonathan Doman | 563570d | 2021-05-24 10:52:43 -0700 | [diff] [blame] | 131 | socket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h |
| 132 | |
| 133 | constexpr uint32_t socketPopulatedMask = 1 << 6; |
| 134 | if ((cpuInfo->status & socketPopulatedMask) == 0) |
| 135 | { |
| 136 | // Don't attempt to fill in any other details if the CPU is not present. |
| 137 | present(false); |
| 138 | return; |
| 139 | } |
| 140 | present(true); |
| 141 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 142 | // this class is for type CPU //offset 5h |
| 143 | family(cpuInfo->family); // offset 6h |
| 144 | manufacturer(cpuInfo->manufacturer, cpuInfo->length, |
| 145 | dataIn); // offset 7h |
| 146 | id(cpuInfo->id); // offset 8h |
| 147 | version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h |
| 148 | maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h |
Charles Boyer | e643169 | 2021-08-31 16:47:47 -0500 | [diff] [blame] | 149 | serialNumber(cpuInfo->serialNum, cpuInfo->length, |
| 150 | dataIn); // offset 20h |
| 151 | partNumber(cpuInfo->partNum, cpuInfo->length, |
| 152 | dataIn); // offset 22h |
| 153 | if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 154 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 155 | coreCount(cpuInfo->coreCount); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 156 | } |
| 157 | else |
| 158 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 159 | coreCount(cpuInfo->coreCount2); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh) |
| 163 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 164 | threadCount(cpuInfo->threadCount); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 165 | } |
| 166 | else |
| 167 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 168 | threadCount(cpuInfo->threadCount2); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 169 | } |
| 170 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 171 | characteristics(cpuInfo->characteristics); // offset 26h |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 172 | |
| 173 | if (!motherboardPath.empty()) |
| 174 | { |
| 175 | std::vector<std::tuple<std::string, std::string, std::string>> assocs; |
| 176 | assocs.emplace_back("chassis", "processors", motherboardPath); |
| 177 | association::associations(assocs); |
| 178 | } |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | } // namespace smbios |
| 182 | } // namespace phosphor |