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