summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Kosenkov <NKosenkov@IBS.RU>2022-08-29 18:26:59 +0300
committerNikita Kosenkov <NKosenkov@IBS.RU>2022-08-29 18:26:59 +0300
commitf703aec64fc2d6dc7e30d5cc0b2617f770c2b9f1 (patch)
tree989601cdba47b7511a1f5b81ae0736c40cbbf73f
parent2d080551eb07d137ca5cd0d2674564274ccb4a5b (diff)
downloadsmbios-mdrv1-f703aec64fc2d6dc7e30d5cc0b2617f770c2b9f1.tar.xz
Refactor CPU class
-rw-r--r--include/cpu.hpp33
-rw-r--r--src/cpu.cpp66
2 files changed, 35 insertions, 64 deletions
diff --git a/include/cpu.hpp b/include/cpu.hpp
index 4f31c93..231d5f4 100644
--- a/include/cpu.hpp
+++ b/include/cpu.hpp
@@ -25,6 +25,7 @@
#include <xyz/openbmc_project/Inventory/Decorator/Revision/server.hpp>
#include <xyz/openbmc_project/Inventory/Item/Cpu/server.hpp>
#include <xyz/openbmc_project/Inventory/Item/server.hpp>
+#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
namespace phosphor
{
@@ -37,8 +38,9 @@ using asset = sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Ass
using location = sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::LocationCode;
using connector = sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot;
using processor = sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu;
-using Item = sdbusplus::xyz::openbmc_project::Inventory::server::Item;
+using item = sdbusplus::xyz::openbmc_project::Inventory::server::Item;
using association = sdbusplus::xyz::openbmc_project::Association::server::Definitions;
+using operstatus = sdbusplus::xyz::openbmc_project::State::Decorator::server::OperationalStatus;
// Definition follow smbios spec DSP0134 3.0.0
static const std::map<uint8_t, std::string> familyTable = {
@@ -95,8 +97,9 @@ static const std::array<std::optional<processor::Capability>, 16>
std::nullopt,
std::nullopt};
-class Cpu : sdbusplus::server::object_t<processor, asset, location, connector, rev,
- Item, association>
+class Cpu :
+ sdbusplus::server::object_t<processor, asset, location, connector, rev,
+ item, association, operstatus>
{
public:
Cpu() = delete;
@@ -110,19 +113,13 @@ class Cpu : sdbusplus::server::object_t<processor, asset, location, connector, r
const uint8_t &cpuId, struct ManagedDataRegion *region) :
sdbusplus::server::object_t<processor, asset, location, connector, rev,
- Item, association>(bus, objPath.c_str()),
+ Item, association, operstatus>(bus, objPath.c_str()),
cpuNum(cpuId), regionS(region)
{
- processorInfoUpdate();
+ infoUpdate();
}
- void processorInfoUpdate(void);
-
- std::string processorSocket(std::string value);
- uint32_t processorId(uint32_t value);
- uint16_t processorMaxSpeed(uint16_t value);
- uint16_t processorCoreCount(uint16_t value);
- uint16_t processorThreadCount(uint16_t value);
+ void infoUpdate(void);
private:
/** @brief Path of the group instance */
@@ -163,13 +160,11 @@ class Cpu : sdbusplus::server::object_t<processor, asset, location, connector, r
uint16_t threadCount2;
} __attribute__((packed));
- void cpuSocket(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn);
- void cpuType(uint8_t value);
- void cpuFamily(uint8_t value);
- void cpuManufacturer(uint8_t positionNum, uint8_t structLen,
- uint8_t *dataIn);
- void cpuVersion(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn);
- void cpuCharacteristics(uint16_t value);
+ void socket(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn);
+ void family(uint8_t value);
+ void manufacturer(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn);
+ void version(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn);
+ void characteristics(uint16_t value);
};
} // namespace smbios
diff --git a/src/cpu.cpp b/src/cpu.cpp
index 552a781..8f4fd49 100644
--- a/src/cpu.cpp
+++ b/src/cpu.cpp
@@ -26,7 +26,7 @@ namespace phosphor
namespace smbios
{
-void Cpu::cpuSocket(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn)
+void Cpu::socket(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn)
{
std::string result;
@@ -37,12 +37,7 @@ void Cpu::cpuSocket(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn)
location::locationCode(result);
}
-std::string Cpu::processorSocket(std::string value)
-{
- return processor::socket(value);
-}
-
-void Cpu::cpuFamily(uint8_t value)
+void Cpu::family(uint8_t value)
{
std::map<uint8_t, std::string>::const_iterator it = familyTable.find(value);
if (it == familyTable.end())
@@ -55,7 +50,7 @@ void Cpu::cpuFamily(uint8_t value)
}
}
-void Cpu::cpuManufacturer(uint8_t positionNum, uint8_t structLen,
+void Cpu::manufacturer(uint8_t positionNum, uint8_t structLen,
uint8_t *dataIn)
{
std::string result;
@@ -65,12 +60,7 @@ void Cpu::cpuManufacturer(uint8_t positionNum, uint8_t structLen,
asset::manufacturer(result);
}
-uint32_t Cpu::processorId(uint32_t value)
-{
- return processor::id(value);
-}
-
-void Cpu::cpuVersion(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn)
+void Cpu::version(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn)
{
std::string result;
@@ -80,12 +70,7 @@ void Cpu::cpuVersion(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn)
rev::version(result);
}
-uint16_t Cpu::processorMaxSpeed(uint16_t value)
-{
- return processor::maxSpeedInMhz(value);
-}
-
-void Cpu::cpuCharacteristics(uint16_t value)
+void Cpu::characteristics(uint16_t value)
{
std::vector<processor::Capability> result;
std::optional<processor::Capability> cap;
@@ -105,18 +90,8 @@ void Cpu::cpuCharacteristics(uint16_t value)
processor::characteristics(result);
}
-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)
+void Cpu::infoUpdate(void)
{
uint8_t *dataIn = regionS[0].regionData;
@@ -146,37 +121,38 @@ void Cpu::processorInfoUpdate(void)
if ((cpuInfo->status & socketPopulatedMask) == 0)
{
// Don't attempt to fill in any other details if the CPU is not present.
- present(false);
+ item::present(false);
return;
}
- present(true);
-
- cpuSocket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h
- 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
+ item::present(true);
+ operstatus::functional(true);
+
+ socket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h
+ family(cpuInfo->family); // offset 6h
+ manufacturer(cpuInfo->manufacturer, cpuInfo->length, dataIn);// offset 7h
+ processor::id(cpuInfo->id); // offset 8h
+ version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h
+ processor::maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h
if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah
{
- processorCoreCount((uint16_t)cpuInfo->coreCount);
+ processor::coreCount((uint16_t)cpuInfo->coreCount);
}
else
{
- processorCoreCount(cpuInfo->coreCount2);
+ processor::coreCount(cpuInfo->coreCount2);
}
if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh)
{
- processorThreadCount((uint16_t)cpuInfo->threadCount);
+ processor::coreCount((uint16_t)cpuInfo->threadCount);
}
else
{
- processorThreadCount(cpuInfo->threadCount2);
+ processor::coreCount(cpuInfo->threadCount2);
}
- cpuCharacteristics(cpuInfo->characteristics); // offset 26h
+ characteristics(cpuInfo->characteristics); // offset 26h
}
} // namespace smbios