/* // Copyright (c) 2018 Intel Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. */ #include "cpu.hpp" #include "manager.hpp" #include #include #include namespace phosphor { namespace smbios { void Cpu::cpuSocket(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn) { std::string result; result = positionToString(positionNum, structLen, dataIn); processorSocket(result); } std::string Cpu::processorSocket(std::string value) { return processor::socket(value); } void Cpu::cpuType(uint8_t value) { std::map::const_iterator it = cpuTypeTable.find(value); if (it == cpuTypeTable.end()) { processorType("Unknown Processor Type"); } else { processorType(it->second); } } std::string Cpu::processorType(std::string value) { return "";//processor::processorType(value); } void Cpu::cpuFamily(uint8_t value) { std::map::const_iterator it = familyTable.find(value); if (it == familyTable.end()) { processorFamily("Unknown Processor Family"); } else { processorFamily(it->second); } } std::string Cpu::processorFamily(std::string value) { return processor::family(value); } void Cpu::cpuManufacturer(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn) { std::string result; result = positionToString(positionNum, structLen, dataIn); processorManufacturer(result); } std::string Cpu::processorManufacturer(std::string value) { return asset::manufacturer(value); } uint32_t Cpu::processorId(uint32_t value) { return processor::id(value); } void Cpu::cpuVersion(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn) { std::string result; result = positionToString(positionNum, structLen, dataIn); processorVersion(result); } std::string Cpu::processorVersion(std::string value) { return rev::version(value); } uint16_t Cpu::processorMaxSpeed(uint16_t value) { return processor::maxSpeedInMhz(value); } void Cpu::cpuCharacteristics(uint16_t value) { std::vector result; std::optional cap; std::bitset<16> charBits = value; for (uint8_t index = 0; index < charBits.size(); index++) { if (charBits.test(index)) { if (cap = characteristicsTable[index]) { result.emplace_back(*cap); } } } processor::characteristics(result); } std::string Cpu::processorCharacteristics(std::string value) { return "";//processor::characteristics(value); } uint16_t Cpu::processorCoreCount(uint16_t value) { return processor::coreCount(value); } uint16_t Cpu::processorThreadCount(uint16_t value) { return processor::threadCount(value); } static constexpr uint8_t maxOldVersionCount = 0xff; void Cpu::processorInfoUpdate(void) { uint8_t *dataIn = regionS[0].regionData; dataIn = smbiosTypePtr(dataIn, processorsType); if (dataIn == nullptr) { return; } for (uint8_t index = 0; index < cpuNum; index++) { dataIn = smbiosNextPtr(dataIn); if (dataIn == nullptr) { return; } dataIn = smbiosTypePtr(dataIn, processorsType); if (dataIn == nullptr) { return; } } auto cpuInfo = reinterpret_cast(dataIn); cpuSocket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h cpuType(cpuInfo->processorType); // offset 5h cpuFamily(cpuInfo->family); // offset 6h cpuManufacturer(cpuInfo->manufacturer, cpuInfo->length, dataIn); // offset 7h processorId(cpuInfo->id); // offset 8h cpuVersion(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h processorMaxSpeed(cpuInfo->maxSpeed); // offset 14h if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah { processorCoreCount((uint16_t)cpuInfo->coreCount); } else { processorCoreCount(cpuInfo->coreCount2); } if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh) { processorThreadCount((uint16_t)cpuInfo->threadCount); } else { processorThreadCount(cpuInfo->threadCount2); } cpuCharacteristics(cpuInfo->characteristics); // offset 26h } } // namespace smbios } // namespace phosphor