summaryrefslogtreecommitdiff
path: root/src/cpu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpu.cpp')
-rw-r--r--src/cpu.cpp214
1 files changed, 214 insertions, 0 deletions
diff --git a/src/cpu.cpp b/src/cpu.cpp
new file mode 100644
index 0000000..a92d9e6
--- /dev/null
+++ b/src/cpu.cpp
@@ -0,0 +1,214 @@
+/*
+// 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 <map>
+
+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 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorSocket(value);
+}
+
+void Cpu::cpuType(uint8_t value)
+{
+ std::map<uint8_t, std::string>::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 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorType(value);
+}
+
+void Cpu::cpuFamily(uint8_t value)
+{
+ std::map<uint8_t, std::string>::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 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorFamily(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 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorManufacturer(value);
+}
+
+uint32_t Cpu::processorId(uint32_t value)
+{
+ return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorId(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 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorVersion(value);
+}
+
+uint16_t Cpu::processorMaxSpeed(uint16_t value)
+{
+ return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorMaxSpeed(value);
+}
+
+void Cpu::cpuCharacteristics(uint16_t value)
+{
+ std::string result = "";
+ for (uint8_t index = 0; index < (8 * sizeof(value)); index++)
+ {
+ if (value & 0x01)
+ {
+ result += characterTable[index];
+ }
+ value >>= 1;
+ }
+
+ processorCharacteristics(result);
+}
+
+std::string Cpu::processorCharacteristics(std::string value)
+{
+ return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorCharacteristics(value);
+}
+
+uint16_t Cpu::processorCoreCount(uint16_t value)
+{
+ return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorCoreCount(value);
+}
+
+uint16_t Cpu::processorThreadCount(uint16_t value)
+{
+ return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
+ processorThreadCount(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<struct ProcessorInfo *>(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