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 19 #include <bitset> 20 #include <map> 21 22 namespace phosphor 23 { 24 namespace smbios 25 { 26 27 void Cpu::socket(const uint8_t positionNum, const uint8_t structLen, 28 uint8_t* dataIn) 29 { 30 std::string result = positionToString(positionNum, structLen, dataIn); 31 32 processor::socket(result); 33 } 34 35 void Cpu::family(const uint8_t value) 36 { 37 std::map<uint8_t, const char*>::const_iterator it = familyTable.find(value); 38 if (it == familyTable.end()) 39 { 40 processor::family("Unknown Processor Family"); 41 } 42 else 43 { 44 processor::family(it->second); 45 } 46 } 47 48 void Cpu::manufacturer(const uint8_t positionNum, const uint8_t structLen, 49 uint8_t* dataIn) 50 { 51 std::string result = positionToString(positionNum, structLen, dataIn); 52 53 asset::manufacturer(result); 54 } 55 56 void Cpu::version(const uint8_t positionNum, const uint8_t structLen, 57 uint8_t* dataIn) 58 { 59 std::string result; 60 61 result = positionToString(positionNum, structLen, dataIn); 62 63 rev::version(result); 64 } 65 66 void Cpu::characteristics(uint16_t value) 67 { 68 std::vector<processor::Capability> result; 69 std::optional<processor::Capability> cap; 70 71 std::bitset<16> charBits = value; 72 for (uint8_t index = 0; index < charBits.size(); index++) 73 { 74 if (charBits.test(index)) 75 { 76 if (cap = characteristicsTable[index]) 77 { 78 result.emplace_back(*cap); 79 } 80 } 81 } 82 83 processor::characteristics(result); 84 } 85 86 static constexpr uint8_t maxOldVersionCount = 0xff; 87 void Cpu::infoUpdate(void) 88 { 89 uint8_t* dataIn = storage; 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 111 auto cpuInfo = reinterpret_cast<struct ProcessorInfo*>(dataIn); 112 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 123 { 124 coreCount(cpuInfo->coreCount); 125 } 126 else 127 { 128 coreCount(cpuInfo->coreCount2); 129 } 130 131 if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh) 132 { 133 threadCount(cpuInfo->threadCount); 134 } 135 else 136 { 137 threadCount(cpuInfo->threadCount2); 138 } 139 140 characteristics(cpuInfo->characteristics); // offset 26h 141 } 142 143 } // namespace smbios 144 } // namespace phosphor 145