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 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 56 | void Cpu::version(const uint8_t positionNum, const uint8_t structLen, |
| 57 | uint8_t* dataIn) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 58 | { |
| 59 | std::string result; |
| 60 | |
| 61 | result = positionToString(positionNum, structLen, dataIn); |
| 62 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 63 | rev::version(result); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 66 | void Cpu::characteristics(uint16_t value) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 67 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 68 | std::vector<processor::Capability> result; |
| 69 | std::optional<processor::Capability> cap; |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 70 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 71 | std::bitset<16> charBits = value; |
| 72 | for (uint8_t index = 0; index < charBits.size(); index++) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 73 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 74 | if (charBits.test(index)) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 75 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 76 | if (cap = characteristicsTable[index]) |
| 77 | { |
| 78 | result.emplace_back(*cap); |
| 79 | } |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 80 | } |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 81 | } |
| 82 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 83 | processor::characteristics(result); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static constexpr uint8_t maxOldVersionCount = 0xff; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 87 | void Cpu::infoUpdate(void) |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 88 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 89 | uint8_t* dataIn = storage; |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 90 | |
| 91 | dataIn = getSMBIOSTypePtr(dataIn, processorsType); |
| 92 | if (dataIn == nullptr) |
| 93 | { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | for (uint8_t index = 0; index < cpuNum; index++) |
| 98 | { |
| 99 | dataIn = smbiosNextPtr(dataIn); |
| 100 | if (dataIn == nullptr) |
| 101 | { |
| 102 | return; |
| 103 | } |
| 104 | dataIn = getSMBIOSTypePtr(dataIn, processorsType); |
| 105 | if (dataIn == nullptr) |
| 106 | { |
| 107 | return; |
| 108 | } |
| 109 | } |
| 110 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 111 | auto cpuInfo = reinterpret_cast<struct ProcessorInfo*>(dataIn); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 112 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 113 | socket(cpuInfo->socketDesignation, cpuInfo->length, |
| 114 | dataIn); // offset 4h |
| 115 | // this class is for type CPU //offset 5h |
| 116 | family(cpuInfo->family); // offset 6h |
| 117 | manufacturer(cpuInfo->manufacturer, cpuInfo->length, |
| 118 | dataIn); // offset 7h |
| 119 | id(cpuInfo->id); // offset 8h |
| 120 | version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h |
| 121 | maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h |
| 122 | if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 123 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 124 | coreCount(cpuInfo->coreCount); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 125 | } |
| 126 | else |
| 127 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 128 | coreCount(cpuInfo->coreCount2); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh) |
| 132 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 133 | threadCount(cpuInfo->threadCount); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 134 | } |
| 135 | else |
| 136 | { |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 137 | threadCount(cpuInfo->threadCount2); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 138 | } |
| 139 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 140 | characteristics(cpuInfo->characteristics); // offset 26h |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | } // namespace smbios |
| 144 | } // namespace phosphor |