Move downstream package to upstream
Use upstream cpu interface
Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: I490482b212df4b73cbdedaba0bc5fefa229a5489
diff --git a/.clang-format b/.clang-format
old mode 100644
new mode 100755
index ea71ad6..ef6f54e
--- a/.clang-format
+++ b/.clang-format
@@ -5,7 +5,7 @@
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
-AlignEscapedNewlinesLeft: false
+AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
@@ -14,13 +14,13 @@
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
-AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
-AlwaysBreakTemplateDeclarations: true
+AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
+ AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
@@ -29,15 +29,22 @@
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
+ AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
+BreakInheritanceList: AfterColon
+BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
@@ -51,17 +58,21 @@
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^[<"](gtest|gmock)'
- Priority: 5
+ Priority: 7
- Regex: '^"config.h"'
Priority: -1
- - Regex: '^".*\.hpp"'
+ - Regex: '^".*\.h"'
Priority: 1
- - Regex: '^<.*\.h>'
+ - Regex: '^".*\.hpp"'
Priority: 2
- - Regex: '^<.*'
+ - Regex: '^<.*\.h>'
Priority: 3
- - Regex: '.*'
+ - Regex: '^<.*\.hpp>'
Priority: 4
+ - Regex: '^<.*'
+ Priority: 5
+ - Regex: '.*'
+ Priority: 6
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: true
@@ -83,8 +94,13 @@
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
diff --git a/CMakeLists.txt b/CMakeLists.txt
old mode 100644
new mode 100755
index 3503c7f..a821080
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,6 +31,16 @@
include_directories (${DBUSINTERFACE_INCLUDE_DIRS})
link_directories (${DBUSINTERFACE_LIBRARY_DIRS})
+# boost
+include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
+set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
+add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
+add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
+add_definitions (-DBOOST_ALL_NO_LIB)
+add_definitions (-DBOOST_NO_RTTI)
+add_definitions (-DBOOST_NO_TYPEID)
+add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
+
set (SRC_FILES src/mdrv2.cpp src/mdrv2_main.cpp src/cpu.cpp src/dimm.cpp
src/system.cpp)
@@ -48,4 +58,46 @@
target_link_libraries (smbiosmdrv2app ${SDBUSPLUSPLUS_LIBRARIES})
target_link_libraries (smbiosmdrv2app phosphor_logging)
-install (TARGETS smbiosmdrv2app DESTINATION bin)
+add_executable (cpuinfoapp src/cpuinfo_main.cpp)
+target_link_libraries (cpuinfoapp ${SYSTEMD_LIBRARIES})
+target_link_libraries (cpuinfoapp ${DBUSINTERFACE_LIBRARIES})
+target_link_libraries (cpuinfoapp ${SDBUSPLUSPLUS_LIBRARIES})
+target_link_libraries (cpuinfoapp phosphor_logging)
+target_link_libraries (cpuinfoapp i2c)
+target_link_libraries (cpuinfoapp peci)
+
+option (DIMM_DBUS "Expose DIMM D-Bus Interface" ON)
+
+if (DIMM_DBUS)
+ target_compile_definitions (smbiosmdrv2app PRIVATE DIMM_DBUS)
+endif ()
+
+option (YOCTO "Enable Building in Yocto" OFF)
+
+if (NOT YOCTO)
+ add_dependencies (cpuinfoapp libpeci)
+ externalproject_add (libpeci PREFIX ${CMAKE_BINARY_DIR}/libpeci
+ GIT_REPOSITORY https://github.com/openbmc/libpeci.git
+ GIT_TAG a2ceec2aa139277cebb62e1eda449ef60fa4c962
+ INSTALL_COMMAND "")
+
+ externalproject_get_property (libpeci SOURCE_DIR)
+ include_directories (${SOURCE_DIR})
+
+ externalproject_get_property (libpeci BINARY_DIR)
+ add_library (peci SHARED IMPORTED)
+ set_target_properties (peci
+ PROPERTIES IMPORTED_LOCATION
+ ${BINARY_DIR}/libpeci.so)
+endif ()
+
+install (TARGETS smbiosmdrv2app DESTINATION sbin)
+
+install (TARGETS cpuinfoapp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib/static)
+
+set (SERVICE_FILES
+ ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.cpuinfo.service)
+install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)
diff --git a/LICENSE b/LICENSE
index 261eeb9..8dada3e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -178,7 +178,7 @@
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
+ boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
- Copyright [yyyy] [name of copyright owner]
+ Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/include/cpu.hpp b/include/cpu.hpp
index 22b6c08..5c8ca86 100644
--- a/include/cpu.hpp
+++ b/include/cpu.hpp
@@ -15,12 +15,11 @@
*/
#pragma once
-#include "smbios.hpp"
+#include "smbios_mdrv2.hpp"
#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
+#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
{
@@ -28,11 +27,11 @@
namespace smbios
{
-// Definition follow smbios spec DSP0134 3.0.0
-static const std::map<uint8_t, const char*> processorTypeTable = {
- {0x1, "Other"}, {0x2, "Unknown"}, {0x3, "Central Processor"},
- {0x4, "Math Processor"}, {0x5, "DSP Processor"}, {0x6, "Video Processor"},
-};
+using rev =
+ sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Revision;
+using asset =
+ sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset;
+using processor = sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu;
// Definition follow smbios spec DSP0134 3.0.0
static const std::map<uint8_t, const char*> familyTable = {
@@ -71,34 +70,25 @@
};
// Definition follow smbios spec DSP0134 3.0.0
-static const std::array<std::string, 16> characteristicsTable{
- "Reserved",
- "Unknown",
- "64-bit Capable",
- "Multi-Core",
- "Hardware Thread",
- "Execute Protection",
- "Enhanced Virtualization",
- "Power/Performance Control",
- "Reserved",
- "Reserved",
- "Reserved",
- "Reserved",
- "Reserved",
- "Reserved",
- "Reserved",
- "Reserved"};
+static const std::array<std::optional<processor::Capability>, 16>
+ characteristicsTable{std::nullopt,
+ std::nullopt,
+ processor::Capability::Capable64bit,
+ processor::Capability::MultiCore,
+ processor::Capability::HardwareThread,
+ processor::Capability::ExecuteProtection,
+ processor::Capability::EnhancedVirtualization,
+ processor::Capability::PowerPerformanceControl,
+ std::nullopt,
+ std::nullopt,
+ std::nullopt,
+ std::nullopt,
+ std::nullopt,
+ std::nullopt,
+ std::nullopt,
+ std::nullopt};
-class Cpu
- : sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu>,
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::server::Item>,
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>,
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::State::Decorator::server::
- OperationalStatus>
+class Cpu : sdbusplus::server::object_t<processor, asset, rev>
{
public:
Cpu() = delete;
@@ -110,37 +100,14 @@
Cpu(sdbusplus::bus::bus& bus, const std::string& objPath,
const uint8_t& cpuId, uint8_t* smbiosTableStorage) :
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu>(
- bus, objPath.c_str()),
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
- Asset>(bus, objPath.c_str()),
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::server::Item>(
- bus, objPath.c_str()),
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::State::Decorator::server::
- OperationalStatus>(bus, objPath.c_str()),
+ sdbusplus::server::object_t<processor, asset, rev>(bus,
+ objPath.c_str()),
cpuNum(cpuId), storage(smbiosTableStorage)
{
- processorInfoUpdate();
+ infoUpdate();
}
- void processorInfoUpdate(void);
-
- std::string processorSocket(std::string value) override;
- std::string processorType(std::string value) override;
- std::string processorFamily(std::string value) override;
- std::string manufacturer(std::string value) override;
- uint32_t processorId(uint32_t value) override;
- std::string processorVersion(std::string value) override;
- uint16_t processorMaxSpeed(uint16_t value) override;
- std::string processorCharacteristics(std::string value) override;
- uint16_t processorCoreCount(uint16_t value) override;
- uint16_t processorThreadCount(uint16_t value) override;
- bool present(bool value) override;
- bool functional(bool value) override;
+ void infoUpdate(void);
private:
uint8_t cpuNum;
@@ -180,16 +147,14 @@
uint16_t threadCount2;
} __attribute__((packed));
- void cpuSocket(const uint8_t positionNum, const uint8_t structLen,
- uint8_t* dataIn);
- void cpuType(const uint8_t value);
- void cpuFamily(const uint8_t value);
- void cpuManufacturer(const uint8_t positionNum, const uint8_t structLen,
- uint8_t* dataIn);
- void cpuVersion(const uint8_t positionNum, const uint8_t structLen,
- uint8_t* dataIn);
- void cpuCharacteristics(const uint16_t value);
- void cpuStatus(const uint8_t value);
+ void socket(const uint8_t positionNum, const uint8_t structLen,
+ uint8_t* dataIn);
+ void family(const uint8_t value);
+ void manufacturer(const uint8_t positionNum, const uint8_t structLen,
+ uint8_t* dataIn);
+ void version(const uint8_t positionNum, const uint8_t structLen,
+ uint8_t* dataIn);
+ void characteristics(const uint16_t value);
};
} // namespace smbios
diff --git a/include/cpuinfo.hpp b/include/cpuinfo.hpp
new file mode 100644
index 0000000..796ed4c
--- /dev/null
+++ b/include/cpuinfo.hpp
@@ -0,0 +1,57 @@
+/*
+// Copyright (c) 2020 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.
+*/
+
+#pragma once
+
+#include <sdbusplus/asio/object_server.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
+
+namespace phosphor
+{
+namespace cpu_info
+{
+static constexpr char const* cpuInfoObject = "xyz.openbmc_project.CPUInfo";
+static constexpr char const* cpuInfoPath = "/xyz/openbmc_project/CPUInfo";
+static constexpr char const* cpuInfoInterface = "xyz.openbmc_project.CPUInfo";
+
+static constexpr const int peciCheckInterval = 10;
+
+/** \ todo add cpu interface to CPUInfo and consolidate with smbios service
+ * using processor =
+ sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu;
+*/
+using asset =
+ sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset;
+
+struct CPUInfo : sdbusplus::server::object_t<asset>
+{
+ public:
+ CPUInfo() = delete;
+ CPUInfo(const CPUInfo&) = delete;
+ CPUInfo& operator=(const CPUInfo&) = delete;
+ CPUInfo(CPUInfo&&) = delete;
+ CPUInfo& operator=(CPUInfo&&) = delete;
+ ~CPUInfo() = default;
+
+ CPUInfo(sdbusplus::bus::bus& bus, const std::string& path) :
+ sdbusplus::server::object_t<asset>(bus, path.c_str())
+ {}
+
+ private:
+};
+
+} // namespace cpu_info
+} // namespace phosphor
diff --git a/include/dimm.hpp b/include/dimm.hpp
index ec0a4e9..7d69a29 100644
--- a/include/dimm.hpp
+++ b/include/dimm.hpp
@@ -15,7 +15,7 @@
*/
#pragma once
-#include "smbios.hpp"
+#include "smbios_mdrv2.hpp"
#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
#include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp>
@@ -29,11 +29,11 @@
using DeviceType =
sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm::DeviceType;
-class Dimm
- : sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>,
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>
+class Dimm :
+ sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>,
+ sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>
{
public:
Dimm() = delete;
@@ -88,34 +88,48 @@
uint8_t* dataIn);
void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
uint8_t* dataIn);
-
- struct MemoryInfo
- {
- uint8_t type;
- uint8_t length;
- uint16_t handle;
- uint16_t phyArrayHandle;
- uint16_t errInfoHandle;
- uint16_t totalWidth;
- uint16_t dataWidth;
- uint16_t size;
- uint8_t formFactor;
- uint8_t deviceSet;
- uint8_t deviceLocator;
- uint8_t bankLocator;
- uint8_t memoryType;
- uint16_t typeDetail;
- uint16_t speed;
- uint8_t manufacturer;
- uint8_t serialNum;
- uint8_t assetTag;
- uint8_t partNum;
- uint8_t attributes;
- uint32_t extendedSize;
- uint16_t confClockSpeed;
- } __attribute__((packed));
};
+struct MemoryInfo
+{
+ uint8_t type;
+ uint8_t length;
+ uint16_t handle;
+ uint16_t phyArrayHandle;
+ uint16_t errInfoHandle;
+ uint16_t totalWidth;
+ uint16_t dataWidth;
+ uint16_t size;
+ uint8_t formFactor;
+ uint8_t deviceSet;
+ uint8_t deviceLocator;
+ uint8_t bankLocator;
+ uint8_t memoryType;
+ uint16_t typeDetail;
+ uint16_t speed;
+ uint8_t manufacturer;
+ uint8_t serialNum;
+ uint8_t assetTag;
+ uint8_t partNum;
+ uint8_t attributes;
+ uint32_t extendedSize;
+ uint16_t confClockSpeed;
+ uint16_t minimumVoltage;
+ uint16_t maximumVoltage;
+ uint16_t configuredVoltage;
+ uint8_t memoryTechnology;
+ uint16_t memoryOperatingModeCap;
+ uint8_t firwareVersion;
+ uint16_t modelManufId;
+ uint16_t modelProdId;
+ uint16_t memSubConManufId;
+ uint16_t memSubConProdId;
+ uint64_t nvSize;
+ uint64_t volatileSize;
+ uint64_t cacheSize;
+ uint64_t logicalSize;
+} __attribute__((packed));
+
const std::map<uint8_t, DeviceType> dimmTypeTable = {
{0x1, DeviceType::Other}, {0x2, DeviceType::Unknown},
{0x3, DeviceType::DRAM}, {0x4, DeviceType::EDRAM},
diff --git a/include/mdrv2.hpp b/include/mdrv2.hpp
index 48df53e..8f03579 100644
--- a/include/mdrv2.hpp
+++ b/include/mdrv2.hpp
@@ -1,5 +1,5 @@
/*
-// Copyright (c) 2019 Intel Corporation
+// 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.
@@ -17,93 +17,41 @@
#pragma once
#include "cpu.hpp"
#include "dimm.hpp"
-#include "smbios.hpp"
+#include "smbios_mdrv2.hpp"
#include "system.hpp"
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/steady_timer.hpp>
+#include <boost/container/flat_map.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
+#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/server.hpp>
#include <sdbusplus/timer.hpp>
-#include <smbios.hpp>
#include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp>
-static constexpr int limitEntryLen = 0xff;
-static constexpr uint8_t mdr2Version = 2;
-static constexpr uint32_t mdr2SMSize = 0x00100000;
-static constexpr uint32_t mdr2SMBaseAddress = 0x9FF00000;
-static constexpr const char* mdrType2File = "/var/lib/smbios/smbios2";
-static constexpr const char* mdrV2Path = "/xyz/openbmc_project/Smbios/MDR_V2";
+sdbusplus::asio::object_server& getObjectServer(void);
-enum class MDR2SMBIOSStatusEnum
-{
- mdr2Init = 0,
- mdr2Loaded = 1,
- mdr2Updated = 2,
- mdr2Updating = 3
-};
-
-enum class MDR2DirLockEnum
-{
- mdr2DirUnlock = 0,
- mdr2DirLock = 1
-};
-
-typedef struct
-{
- uint8_t dataInfo[16];
-} DataIdStruct;
-
-typedef struct
-{
- DataIdStruct id;
- uint32_t size;
- uint32_t dataSetSize;
- uint32_t dataVersion;
- uint32_t timestamp;
-} Mdr2DirEntry;
-
-typedef struct
-{
- Mdr2DirEntry common;
- MDR2SMBIOSStatusEnum stage;
- MDR2DirLockEnum lock;
- uint16_t lockHandle;
- uint32_t xferBuff;
- uint32_t xferSize;
- uint32_t maxDataSize;
- uint8_t* dataStorage;
-} Mdr2DirLocalStruct;
-
-typedef struct
-{
- uint8_t agentVersion;
- uint8_t dirVersion;
- uint8_t dirEntries;
- uint8_t status; // valid / locked / etc
- uint8_t remoteDirVersion;
- uint16_t sessionHandle;
- Mdr2DirLocalStruct dir[maxDirEntries];
-} Mdr2DirStruct;
-
-struct MDRSMBIOSHeader
-{
- uint8_t dirVer;
- uint8_t mdrType;
- uint32_t timestamp;
- uint32_t dataSize;
-} __attribute__((packed));
-
+using RecordVariant =
+ std::variant<std::string, uint64_t, uint32_t, uint16_t, uint8_t>;
namespace phosphor
{
namespace smbios
{
-class MDR_V2 : sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>
+static constexpr const char* mdrV2Path = "/xyz/openbmc_project/Smbios/MDR_V2";
+static constexpr const char* smbiosPath = "/xyz/openbmc_project/Smbios";
+static constexpr const char* smbiosInterfaceName =
+ "xyz.openbmc_project.Smbios.GetRecordType";
+constexpr const int limitEntryLen = 0xff;
+
+class MDR_V2 :
+ sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>
{
public:
MDR_V2() = delete;
@@ -113,10 +61,12 @@
MDR_V2& operator=(MDR_V2&&) = delete;
~MDR_V2() = default;
- MDR_V2(sdbusplus::bus::bus& bus, const char* path, sd_event* event) :
+ MDR_V2(sdbusplus::bus::bus& bus, const char* path,
+ boost::asio::io_context& io) :
sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>(bus, path),
- bus(bus), timer(event, [&](void) { agentSynchronizeData(); })
+ bus(bus), timer(io), smbiosInterface(getObjectServer().add_interface(
+ smbiosPath, smbiosInterfaceName))
{
smbiosDir.agentVersion = smbiosAgentVersion;
@@ -132,6 +82,11 @@
smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage;
agentSynchronizeData();
+
+ smbiosInterface->register_method("GetRecordType", [this](size_t type) {
+ return getRecordType(type);
+ });
+ smbiosInterface->initialize();
}
std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override;
@@ -157,8 +112,11 @@
uint8_t directoryEntries(uint8_t value) override;
+ std::vector<boost::container::flat_map<std::string, RecordVariant>>
+ getRecordType(size_t type);
+
private:
- Timer timer;
+ boost::asio::steady_timer timer;
sdbusplus::bus::bus& bus;
@@ -180,6 +138,7 @@
std::vector<std::unique_ptr<Cpu>> cpus;
std::vector<std::unique_ptr<Dimm>> dimms;
std::unique_ptr<System> system;
+ std::shared_ptr<sdbusplus::asio::dbus_interface> smbiosInterface;
};
} // namespace smbios
diff --git a/include/smbios.hpp b/include/smbios_mdrv2.hpp
similarity index 64%
rename from include/smbios.hpp
rename to include/smbios_mdrv2.hpp
index e6dc743..e53d709 100644
--- a/include/smbios.hpp
+++ b/include/smbios_mdrv2.hpp
@@ -1,5 +1,5 @@
/*
-// Copyright (c) 2019 Intel Corporation
+// 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.
@@ -16,31 +16,50 @@
#pragma once
+#include <phosphor-logging/elog-errors.hpp>
+
#include <array>
-static constexpr uint16_t smbiosAgentId = 0x0101;
-static constexpr int smbiosDirIndex = 0;
-static constexpr int firstAgentIndex = 1;
-static constexpr uint8_t maxDirEntries = 4;
-static constexpr uint32_t pageMask = 0xf000;
-static constexpr uint8_t smbiosAgentVersion = 1;
-static constexpr uint32_t defaultTimeout = 20000;
-static constexpr uint32_t smbiosTableVersion = 15;
-static constexpr uint32_t smbiosSMMemoryOffset = 0;
-static constexpr uint32_t smbiosSMMemorySize = 1024 * 1024;
-static constexpr uint32_t smbiosTableTimestamp = 0x45464748;
-static constexpr uint32_t smbiosTableStorageSize = 64 * 1024;
+static constexpr const char* mdrType2File = "/var/lib/smbios/smbios2";
static constexpr const char* smbiosPath = "/var/lib/smbios";
+
static constexpr uint16_t mdrSMBIOSSize = 32 * 1024;
-static constexpr const char* cpuPath =
- "/xyz/openbmc_project/inventory/system/chassis/motherboard/cpu";
+constexpr uint16_t smbiosAgentId = 0x0101;
+constexpr int firstAgentIndex = 1;
-static constexpr const char* dimmPath =
- "/xyz/openbmc_project/inventory/system/chassis/motherboard/dimm";
+constexpr uint8_t maxDirEntries = 4;
+constexpr uint32_t mdr2SMSize = 0x00100000;
+constexpr uint32_t mdr2SMBaseAddress = 0x9FF00000;
-static constexpr const char* systemPath =
- "/xyz/openbmc_project/inventory/system/chassis/motherboard/bios";
+constexpr uint8_t mdrTypeII = 2;
+
+constexpr uint8_t mdr2Version = 2;
+constexpr uint8_t smbiosAgentVersion = 1;
+
+constexpr uint32_t pageMask = 0xf000;
+constexpr int smbiosDirIndex = 0;
+
+constexpr uint32_t smbiosTableVersion = 15;
+constexpr uint32_t smbiosTableTimestamp = 0x45464748;
+constexpr uint32_t smbiosSMMemoryOffset = 0;
+constexpr uint32_t smbiosSMMemorySize = 1024 * 1024;
+constexpr uint32_t smbiosTableStorageSize = 64 * 1024;
+constexpr uint32_t defaultTimeout = 20000;
+
+enum class MDR2SMBIOSStatusEnum
+{
+ mdr2Init = 0,
+ mdr2Loaded = 1,
+ mdr2Updated = 2,
+ mdr2Updating = 3
+};
+
+enum class MDR2DirLockEnum
+{
+ mdr2DirUnlock = 0,
+ mdr2DirLock = 1
+};
enum class DirDataRequestEnum
{
@@ -55,6 +74,60 @@
flagIsLocked = 2
};
+typedef struct
+{
+ uint8_t dataInfo[16];
+} DataIdStruct;
+
+typedef struct
+{
+ DataIdStruct id;
+ uint32_t size;
+ uint32_t dataSetSize;
+ uint8_t dataVersion;
+ uint32_t timestamp;
+} Mdr2DirEntry;
+
+typedef struct
+{
+ Mdr2DirEntry common;
+ MDR2SMBIOSStatusEnum stage;
+ MDR2DirLockEnum lock;
+ uint16_t lockHandle;
+ uint32_t xferBuff;
+ uint32_t xferSize;
+ uint32_t maxDataSize;
+ uint8_t* dataStorage;
+} Mdr2DirLocalStruct;
+
+typedef struct
+{
+ uint8_t agentVersion;
+ uint8_t dirVersion;
+ uint8_t dirEntries;
+ uint8_t status; // valid / locked / etc
+ uint8_t remoteDirVersion;
+ uint16_t sessionHandle;
+ Mdr2DirLocalStruct dir[maxDirEntries];
+} Mdr2DirStruct;
+
+struct MDRSMBIOSHeader
+{
+ uint8_t dirVer;
+ uint8_t mdrType;
+ uint32_t timestamp;
+ uint32_t dataSize;
+} __attribute__((packed));
+
+static constexpr const char* cpuPath =
+ "/xyz/openbmc_project/inventory/system/chassis/motherboard/cpu";
+
+static constexpr const char* dimmPath =
+ "/xyz/openbmc_project/inventory/system/chassis/motherboard/dimm";
+
+static constexpr const char* systemPath =
+ "/xyz/openbmc_project/inventory/system/chassis/motherboard/bios";
+
typedef enum
{
biosType = 0,
@@ -101,7 +174,8 @@
// When first time run getSMBIOSTypePtr, need to send the RegionS[].regionData
// to smbiosDataIn
-static inline uint8_t* getSMBIOSTypePtr(uint8_t* smbiosDataIn, uint8_t typeId)
+static inline uint8_t* getSMBIOSTypePtr(uint8_t* smbiosDataIn, uint8_t typeId,
+ size_t size = 0)
{
if (smbiosDataIn == nullptr)
{
@@ -110,9 +184,10 @@
char* smbiosData = reinterpret_cast<char*>(smbiosDataIn);
while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
{
+ uint32_t len = *(smbiosData + 1);
if (*smbiosData != typeId)
{
- uint32_t len = *(smbiosData + 1);
+
smbiosData += len;
while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
{
@@ -126,6 +201,12 @@
smbiosData += separateLen;
continue;
}
+ if (len < size)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Record size mismatch!");
+ return nullptr;
+ }
return reinterpret_cast<uint8_t*>(smbiosData);
}
return nullptr;
diff --git a/include/system.hpp b/include/system.hpp
index ea1eccf..cf69cb7 100644
--- a/include/system.hpp
+++ b/include/system.hpp
@@ -15,7 +15,7 @@
*/
#pragma once
-#include "smbios.hpp"
+#include "smbios_mdrv2.hpp"
#include <xyz/openbmc_project/Common/UUID/server.hpp>
#include <xyz/openbmc_project/Inventory/Decorator/Revision/server.hpp>
@@ -26,11 +26,11 @@
namespace smbios
{
-class System : sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Common::server::UUID>,
- sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Inventory::Decorator::
- server::Revision>
+class System :
+ sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Common::server::UUID>,
+ sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Revision>
{
public:
System() = delete;
diff --git a/service_files/xyz.openbmc_project.cpuinfo.service b/service_files/xyz.openbmc_project.cpuinfo.service
new file mode 100644
index 0000000..e29bf7e
--- /dev/null
+++ b/service_files/xyz.openbmc_project.cpuinfo.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Intel BMC CPU Info
+Requires=smbios-mdrv2.service
+After=smbios-mdrv2.service
+
+[Service]
+Restart=always
+ExecStart=/usr/bin/cpuinfoapp
+Type=dbus
+BusName=xyz.openbmc_project.CPUInfo
+Nice=19
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/cpu.cpp b/src/cpu.cpp
index ffef3cf..90c1191 100644
--- a/src/cpu.cpp
+++ b/src/cpu.cpp
@@ -16,7 +16,7 @@
#include "cpu.hpp"
-#include <iostream>
+#include <bitset>
#include <map>
namespace phosphor
@@ -24,169 +24,67 @@
namespace smbios
{
-void Cpu::cpuSocket(const uint8_t positionNum, const uint8_t structLen,
- uint8_t* dataIn)
+void Cpu::socket(const uint8_t positionNum, const uint8_t structLen,
+ uint8_t* dataIn)
{
std::string result = positionToString(positionNum, structLen, dataIn);
- processorSocket(result);
+ processor::socket(result);
}
-std::string Cpu::processorSocket(std::string value)
-{
- return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
- processorSocket(value);
-}
-
-void Cpu::cpuType(const uint8_t value)
-{
- std::map<uint8_t, const char*>::const_iterator it =
- processorTypeTable.find(value);
- if (it == processorTypeTable.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(const uint8_t value)
+void Cpu::family(const uint8_t value)
{
std::map<uint8_t, const char*>::const_iterator it = familyTable.find(value);
if (it == familyTable.end())
{
- processorFamily("Unknown Processor Family");
+ processor::family("Unknown Processor Family");
}
else
{
- processorFamily(it->second);
+ processor::family(it->second);
}
}
-std::string Cpu::processorFamily(std::string value)
-{
- return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
- processorFamily(value);
-}
-
-void Cpu::cpuManufacturer(const uint8_t positionNum, const uint8_t structLen,
- uint8_t* dataIn)
+void Cpu::manufacturer(const uint8_t positionNum, const uint8_t structLen,
+ uint8_t* dataIn)
{
std::string result = positionToString(positionNum, structLen, dataIn);
- manufacturer(result);
+ asset::manufacturer(result);
}
-std::string Cpu::manufacturer(std::string value)
-{
- return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
- Asset::manufacturer(value);
-}
-
-uint32_t Cpu::processorId(uint32_t value)
-{
- return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
- processorId(value);
-}
-
-void Cpu::cpuVersion(const uint8_t positionNum, const uint8_t structLen,
- uint8_t* dataIn)
+void Cpu::version(const uint8_t positionNum, const uint8_t structLen,
+ uint8_t* dataIn)
{
std::string result;
result = positionToString(positionNum, structLen, dataIn);
- processorVersion(result);
+ rev::version(result);
}
-std::string Cpu::processorVersion(std::string value)
+void Cpu::characteristics(uint16_t value)
{
- return sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu::
- processorVersion(value);
-}
+ std::vector<processor::Capability> result;
+ std::optional<processor::Capability> cap;
-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++)
+ std::bitset<16> charBits = value;
+ for (uint8_t index = 0; index < charBits.size(); index++)
{
- if (value & 0x01)
+ if (charBits.test(index))
{
- result += characteristicsTable[index];
+ if (cap = characteristicsTable[index])
+ {
+ result.emplace_back(*cap);
+ }
}
- 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 const uint8_t populateMask = 1 << 6;
-static constexpr const uint8_t statusMask = 0x07;
-void Cpu::cpuStatus(uint8_t value)
-{
- if (!(value & populateMask))
- {
- present(false);
- functional(false);
- return;
- }
- present(true);
- if ((value & statusMask) == 1)
- {
- functional(true);
- }
- else
- {
- functional(false);
- }
-}
-
-bool Cpu::present(bool value)
-{
- return sdbusplus::xyz::openbmc_project::Inventory::server::Item::present(
- value);
-}
-
-bool Cpu::functional(bool value)
-{
- return sdbusplus::xyz::openbmc_project::State::Decorator::server::
- OperationalStatus::functional(value);
+ processor::characteristics(result);
}
static constexpr uint8_t maxOldVersionCount = 0xff;
-void Cpu::processorInfoUpdate(void)
+void Cpu::infoUpdate(void)
{
uint8_t* dataIn = storage;
@@ -212,36 +110,34 @@
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
+ socket(cpuInfo->socketDesignation, cpuInfo->length,
+ dataIn); // offset 4h
+ // this class is for type CPU //offset 5h
+ family(cpuInfo->family); // offset 6h
+ manufacturer(cpuInfo->manufacturer, cpuInfo->length,
+ dataIn); // offset 7h
+ id(cpuInfo->id); // offset 8h
+ version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h
+ maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h
+ if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah
{
- processorCoreCount(cpuInfo->coreCount);
+ coreCount(cpuInfo->coreCount);
}
else
{
- processorCoreCount(cpuInfo->coreCount2);
+ coreCount(cpuInfo->coreCount2);
}
if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh)
{
- processorThreadCount(cpuInfo->threadCount);
+ threadCount(cpuInfo->threadCount);
}
else
{
- processorThreadCount(cpuInfo->threadCount2);
+ threadCount(cpuInfo->threadCount2);
}
- cpuCharacteristics(cpuInfo->characteristics); // offset 26h
-
- cpuStatus(cpuInfo->status);
+ characteristics(cpuInfo->characteristics); // offset 26h
}
} // namespace smbios
diff --git a/src/cpuinfo_main.cpp b/src/cpuinfo_main.cpp
new file mode 100644
index 0000000..dc3a8e8
--- /dev/null
+++ b/src/cpuinfo_main.cpp
@@ -0,0 +1,425 @@
+/*
+// Copyright (c) 2020 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 "cpuinfo.hpp"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+
+#include <boost/asio/io_service.hpp>
+#include <boost/asio/steady_timer.hpp>
+
+#include <optional>
+#include <sstream>
+#include <string>
+
+extern "C"
+{
+#include <i2c/smbus.h>
+#include <linux/i2c-dev.h>
+}
+
+#include <peci.h>
+
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+namespace phosphor
+{
+namespace cpu_info
+{
+
+static constexpr const char* cpuPath =
+ "/xyz/openbmc_project/inventory/system/chassis/motherboard/cpu";
+static constexpr const char* cpuInterfaceName =
+ "xyz.openbmc_project.Inventory.Decorator.Asset";
+static constexpr const char* cpuProcessName =
+ "xyz.openbmc_project.Smbios.MDR_V2";
+
+struct ProcessorInfo
+{
+ uint64_t ppin;
+ std::string sspec;
+};
+
+using CPUMap =
+ boost::container::flat_map<size_t,
+ std::pair<int, std::shared_ptr<CPUInfo>>>;
+
+static CPUMap cpuMap = {};
+
+static std::unique_ptr<sdbusplus::bus::match_t> cpuUpdatedMatch = nullptr;
+
+static std::optional<std::string> readSSpec(uint8_t bus, uint8_t slaveAddr,
+ uint8_t regAddr, size_t count)
+{
+ unsigned long funcs = 0;
+ std::string devPath = "/dev/i2c-" + std::to_string(bus);
+
+ int fd = ::open(devPath.c_str(), O_RDWR);
+ if (fd < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error in open!",
+ phosphor::logging::entry("PATH=%s", devPath.c_str()),
+ phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
+ return std::nullopt;
+ }
+
+ if (::ioctl(fd, I2C_FUNCS, &funcs) < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error in I2C_FUNCS!",
+ phosphor::logging::entry("PATH=%s", devPath.c_str()),
+ phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
+ ::close(fd);
+ return std::nullopt;
+ }
+
+ if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA))
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "i2c bus does not support read!",
+ phosphor::logging::entry("PATH=%s", devPath.c_str()),
+ phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
+ ::close(fd);
+ return std::nullopt;
+ }
+
+ if (::ioctl(fd, I2C_SLAVE_FORCE, slaveAddr) < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error in I2C_SLAVE_FORCE!",
+ phosphor::logging::entry("PATH=%s", devPath.c_str()),
+ phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
+ ::close(fd);
+ return std::nullopt;
+ }
+
+ int value = 0;
+ std::string sspec;
+ sspec.reserve(count);
+
+ for (size_t i = 0; i < count; i++)
+ {
+ value = ::i2c_smbus_read_byte_data(fd, regAddr++);
+ if (value < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error in i2c read!",
+ phosphor::logging::entry("PATH=%s", devPath.c_str()),
+ phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
+ ::close(fd);
+ return std::nullopt;
+ }
+ if (!std::isprint(static_cast<unsigned char>(value)))
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Non printable value in sspec, ignored.");
+ continue;
+ }
+ sspec.push_back(static_cast<unsigned char>(value));
+ }
+ ::close(fd);
+ return sspec;
+}
+
+// PECI Client Address Map
+static void getPECIAddrMap(CPUMap& cpuMap)
+{
+ int idx = 0;
+ for (size_t i = MIN_CLIENT_ADDR; i <= MAX_CLIENT_ADDR; i++)
+ {
+ if (peci_Ping(i) == PECI_CC_SUCCESS)
+ {
+ cpuMap.emplace(std::make_pair(i, std::make_pair(idx, nullptr)));
+ idx++;
+ }
+ }
+}
+
+static std::shared_ptr<CPUInfo>
+ createCPUInfo(std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const int& cpu)
+{
+ std::string path = cpuPath + std::to_string(cpu);
+ std::shared_ptr<CPUInfo> cpuInfo = std::make_shared<CPUInfo>(
+ static_cast<sdbusplus::bus::bus&>(*conn), path);
+ return cpuInfo;
+}
+
+static void setAssetProperty(
+ std::shared_ptr<sdbusplus::asio::connection>& conn, const int& cpu,
+ const std::vector<std::pair<std::string, std::string>>& propValues)
+{
+
+ const std::string objectPath = cpuPath + std::to_string(cpu);
+ for (const auto& prop : propValues)
+ {
+ conn->async_method_call(
+ [](const boost::system::error_code ec) {
+ // Use "Set" method to set the property value.
+ if (ec)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Cannot get CPU property!");
+ return;
+ }
+ },
+ cpuProcessName, objectPath.c_str(),
+ "org.freedesktop.DBus.Properties", "Set", cpuInterfaceName,
+ prop.first.c_str(), std::variant<std::string>{prop.second});
+ }
+}
+
+static void createCpuUpdatedMatch(
+ std::shared_ptr<sdbusplus::asio::connection>& conn, const int& cpu,
+ const std::vector<std::pair<std::string, std::string>>& propValues)
+{
+ if (cpuUpdatedMatch)
+ {
+ return;
+ }
+
+ const std::string objectPath = cpuPath + std::to_string(cpu);
+
+ cpuUpdatedMatch = std::make_unique<sdbusplus::bus::match::match>(
+ static_cast<sdbusplus::bus::bus&>(*conn),
+ sdbusplus::bus::match::rules::interfacesAdded() +
+ sdbusplus::bus::match::rules::argNpath(0, objectPath.c_str()),
+ [&conn, cpu, propValues](sdbusplus::message::message& msg) {
+ std::string objectName;
+ boost::container::flat_map<
+ std::string,
+ boost::container::flat_map<std::string,
+ std::variant<std::string, uint64_t>>>
+ msgData;
+
+ msg.read(objectName, msgData);
+
+ // Check for xyz.openbmc_project.Inventory.Item.Cpu
+ // interface match
+ auto intfFound = msgData.find(cpuInterfaceName);
+ if (msgData.end() != intfFound)
+ {
+ setAssetProperty(conn, cpu, propValues);
+ }
+ });
+}
+
+// constants for reading QDF string from PIROM
+// Currently, they are the same for platforms with icx
+// \todo: move into configuration file to be more robust
+static constexpr uint8_t i2cBus = 13;
+static constexpr uint8_t slaveAddr0 = 0x50;
+static constexpr uint8_t regAddr = 0xf;
+static constexpr uint8_t sspecSize = 4;
+
+static void getProcessorInfo(std::shared_ptr<sdbusplus::asio::connection>& conn,
+ sdbusplus::asio::object_server& objServer,
+ CPUMap& cpuMap)
+{
+
+ for (auto& cpu : cpuMap)
+ {
+ uint8_t cc = 0;
+ CPUModel model{};
+ uint8_t stepping = 0;
+
+ /// \todo in a follwup patch
+ // CPUInfo will be updated as the centrol place for CPU information
+ // std::shared_ptr<CPUInfo> cpuInfo =
+ // createCPUInfo(conn, cpu.second.first);
+ // cpu.second.second = cpuInfo;
+
+ if (peci_GetCPUID(cpu.first, &model, &stepping, &cc) != PECI_CC_SUCCESS)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Cannot get CPUID!",
+ phosphor::logging::entry("PECIADDR=0x%x", cpu.first));
+ continue;
+ }
+
+ switch (model)
+ {
+ case icx:
+ {
+ // get processor ID
+ static constexpr uint8_t u8Size = 4; // default to a DWORD
+ static constexpr uint8_t u8PPINPkgIndex = 19;
+ static constexpr uint16_t u16PPINPkgParamHigh = 2;
+ static constexpr uint16_t u16PPINPkgParamLow = 1;
+ uint64_t cpuPPIN = 0;
+ uint32_t u32PkgValue = 0;
+
+ int ret = peci_RdPkgConfig(cpu.first, u8PPINPkgIndex,
+ u16PPINPkgParamLow, u8Size,
+ (uint8_t*)&u32PkgValue, &cc);
+ if (0 != ret)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "peci read package config failed at address",
+ phosphor::logging::entry("PECIADDR=0x%x", cpu.first),
+ phosphor::logging::entry("CC=0x%x", cc));
+ u32PkgValue = 0;
+ }
+
+ cpuPPIN = u32PkgValue;
+ ret = peci_RdPkgConfig(cpu.first, u8PPINPkgIndex,
+ u16PPINPkgParamHigh, u8Size,
+ (uint8_t*)&u32PkgValue, &cc);
+ if (0 != ret)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "peci read package config failed at address",
+ phosphor::logging::entry("PECIADDR=0x%x", cpu.first),
+ phosphor::logging::entry("CC=0x%x", cc));
+ cpuPPIN = 0;
+ u32PkgValue = 0;
+ }
+
+ cpuPPIN |= static_cast<uint64_t>(u32PkgValue) << 32;
+
+ std::vector<std::pair<std::string, std::string>> values;
+
+ // set SerialNumber if cpuPPIN is valid
+ if (0 != cpuPPIN)
+ {
+ std::stringstream stream;
+ stream << std::hex << cpuPPIN;
+ std::string serialNumber(stream.str());
+ // cpuInfo->serialNumber(serialNumber);
+ values.emplace_back(
+ std::make_pair("SerialNumber", serialNumber));
+ }
+
+ // assuming the slaveAddress will be incrementing like peci
+ // client address
+ std::optional<std::string> sspec = readSSpec(
+ i2cBus, static_cast<uint8_t>(slaveAddr0 + cpu.second.first),
+ regAddr, sspecSize);
+ // cpuInfo->model(sspec.value_or(""));
+ values.emplace_back(
+ std::make_pair("Model", sspec.value_or("")));
+
+ /// \todo in followup patch
+ // CPUInfo is created by this service
+ // update the below logic, which is needed because smbios
+ // service creates the cpu object
+ createCpuUpdatedMatch(conn, cpu.second.first, values);
+ setAssetProperty(conn, cpu.second.first, values);
+ break;
+ }
+ default:
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ "in-compatible cpu for cpu asset info");
+ break;
+ }
+ }
+}
+
+static bool isPECIAvailable(void)
+{
+ for (size_t i = MIN_CLIENT_ADDR; i <= MAX_CLIENT_ADDR; i++)
+ {
+ if (peci_Ping(i) == PECI_CC_SUCCESS)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+static void
+ peciAvailableCheck(boost::asio::steady_timer& peciWaitTimer,
+ boost::asio::io_service& io,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ sdbusplus::asio::object_server& objServer)
+{
+ bool peciAvailable = isPECIAvailable();
+ if (peciAvailable)
+ {
+ // get the PECI client address list
+ getPECIAddrMap(cpuMap);
+ getProcessorInfo(conn, objServer, cpuMap);
+ }
+ if (!peciAvailable || !cpuMap.size())
+ {
+ peciWaitTimer.expires_after(
+ std::chrono::seconds(6 * peciCheckInterval));
+ peciWaitTimer.async_wait([&peciWaitTimer, &io, &conn, &objServer](
+ const boost::system::error_code& ec) {
+ if (ec)
+ {
+ // operation_aborted is expected if timer is canceled
+ // before completion.
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "PECI Available Check async_wait failed",
+ phosphor::logging::entry("EC=0x%x", ec.value()));
+ }
+ return;
+ }
+ peciAvailableCheck(peciWaitTimer, io, conn, objServer);
+ });
+ }
+}
+
+} // namespace cpu_info
+} // namespace phosphor
+
+int main(int argc, char* argv[])
+{
+ // setup connection to dbus
+ boost::asio::io_service io;
+ std::shared_ptr<sdbusplus::asio::connection> conn =
+ std::make_shared<sdbusplus::asio::connection>(io);
+
+ // CPUInfo Object
+ conn->request_name(phosphor::cpu_info::cpuInfoObject);
+ sdbusplus::asio::object_server server =
+ sdbusplus::asio::object_server(conn);
+ sdbusplus::bus::bus& bus = static_cast<sdbusplus::bus::bus&>(*conn);
+ sdbusplus::server::manager::manager objManager(
+ bus, "/xyz/openbmc_project/inventory");
+
+ // Start the PECI check loop
+ boost::asio::steady_timer peciWaitTimer(
+ io, std::chrono::seconds(phosphor::cpu_info::peciCheckInterval));
+ peciWaitTimer.async_wait([&peciWaitTimer, &io, &conn,
+ &server](const boost::system::error_code& ec) {
+ if (ec)
+ {
+ // operation_aborted is expected if timer is canceled
+ // before completion.
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "PECI Available Check async_wait failed ",
+ phosphor::logging::entry("EC=0x%x", ec.value()));
+ }
+ return;
+ }
+ phosphor::cpu_info::peciAvailableCheck(peciWaitTimer, io, conn, server);
+ });
+
+ io.run();
+
+ return 0;
+}
diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 07dcc6b..9a73c65 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -1,5 +1,5 @@
/*
-// Copyright (c) 2019 Intel Corporation
+// 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.
@@ -18,11 +18,12 @@
#include <sys/mman.h>
-#include <fstream>
#include <phosphor-logging/elog-errors.hpp>
#include <sdbusplus/exception.hpp>
#include <xyz/openbmc_project/Smbios/MDR_V2/error.hpp>
+#include <fstream>
+
namespace phosphor
{
namespace smbios
@@ -154,6 +155,17 @@
return static_cast<uint8_t>(ret);
}
+// If source variable size is 4 bytes (uint32_t) and destination is Vector type
+// is 1 byte (uint8_t), then by using this API can copy data byte by byte. For
+// Example copying data from smbiosDir.dir[idIndex].common.size and
+// smbiosDir.dir[idIndex].common.timestamp to vector variable responseInfo
+template <typename T>
+void appendReversed(std::vector<uint8_t>& vector, const T& value)
+{
+ auto data = reinterpret_cast<const uint8_t*>(&value);
+ std::reverse_copy(data, data + sizeof(value), std::back_inserter(vector));
+}
+
std::vector<uint8_t> MDR_V2::getDataInformation(uint8_t idIndex)
{
std::vector<uint8_t> responseInfo;
@@ -170,14 +182,67 @@
responseInfo.push_back(
smbiosDir.dir[idIndex].common.id.dataInfo[index]);
}
+
responseInfo.push_back(smbiosValidFlag(idIndex));
- responseInfo.push_back(smbiosDir.dir[idIndex].common.size);
+ appendReversed(responseInfo, smbiosDir.dir[idIndex].common.size);
responseInfo.push_back(smbiosDir.dir[idIndex].common.dataVersion);
- responseInfo.push_back(smbiosDir.dir[idIndex].common.timestamp);
+ appendReversed(responseInfo, smbiosDir.dir[idIndex].common.timestamp);
return responseInfo;
}
+bool MDR_V2::readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data)
+{
+ if (mdrHdr == nullptr)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Invalid mdr header");
+ return false;
+ }
+ if (data == nullptr)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Invalid data point");
+ return false;
+ }
+ std::ifstream smbiosFile(mdrType2File, std::ios_base::binary);
+ if (!smbiosFile.good())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Open MDRV2 table file failure");
+ return false;
+ }
+ smbiosFile.clear();
+ smbiosFile.seekg(0, std::ios_base::end);
+ int fileLength = smbiosFile.tellg();
+ smbiosFile.seekg(0, std::ios_base::beg);
+ if (fileLength < sizeof(MDRSMBIOSHeader))
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "MDR V2 file size is smaller than mdr header");
+ return false;
+ }
+ smbiosFile.read(reinterpret_cast<char*>(mdrHdr), sizeof(MDRSMBIOSHeader));
+ if (mdrHdr->dataSize > smbiosTableStorageSize)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Data size out of limitation");
+ smbiosFile.close();
+ return false;
+ }
+ fileLength -= sizeof(MDRSMBIOSHeader);
+ if (fileLength < mdrHdr->dataSize)
+ {
+ smbiosFile.read(reinterpret_cast<char*>(data), fileLength);
+ }
+ else
+ {
+ smbiosFile.read(reinterpret_cast<char*>(data), mdrHdr->dataSize);
+ }
+ smbiosFile.close();
+ return true;
+}
+
bool MDR_V2::sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex,
uint8_t returnedEntries,
uint8_t remainingEntries,
@@ -236,58 +301,6 @@
return teminate;
}
-bool MDR_V2::readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data)
-{
- if (mdrHdr == nullptr)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Read data from flash error - Invalid mdr header");
- return false;
- }
- if (data == nullptr)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Read data from flash error - Invalid data point");
- return false;
- }
- std::ifstream smbiosFile(mdrType2File, std::ios_base::binary);
- if (!smbiosFile.good())
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Read data from flash error - Open MDRV2 table file failure");
- return false;
- }
- smbiosFile.clear();
- smbiosFile.seekg(0, std::ios_base::end);
- int fileLength = smbiosFile.tellg();
- smbiosFile.seekg(0, std::ios_base::beg);
- if (fileLength < sizeof(MDRSMBIOSHeader))
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "MDR V2 file size is smaller than mdr header");
- return false;
- }
- smbiosFile.read(reinterpret_cast<char*>(mdrHdr), sizeof(MDRSMBIOSHeader));
- if (mdrHdr->dataSize > smbiosTableStorageSize)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Data size out of limitation");
- smbiosFile.close();
- return false;
- }
- fileLength -= sizeof(MDRSMBIOSHeader);
- if (fileLength < mdrHdr->dataSize)
- {
- smbiosFile.read(reinterpret_cast<char*>(data), fileLength);
- }
- else
- {
- smbiosFile.read(reinterpret_cast<char*>(data), mdrHdr->dataSize);
- }
- smbiosFile.close();
- return true;
-}
-
bool MDR_V2::sendDataInformation(uint8_t idIndex, uint8_t flag,
uint32_t dataLen, uint32_t dataVer,
uint32_t timeStamp)
@@ -380,6 +393,8 @@
bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage));
}
+#ifdef DIMM_DBUS
+
dimms.clear();
num = getTotalDimmSlot();
@@ -397,6 +412,8 @@
bus, path, index, smbiosDir.dir[smbiosDirIndex].dataStorage));
}
+#endif
+
system.reset();
system = std::make_unique<System>(
bus, systemPath, smbiosDir.dir[smbiosDirIndex].dataStorage);
@@ -490,7 +507,6 @@
smbiosDir.dir[smbiosDirIndex].stage = MDR2SMBIOSStatusEnum::mdr2Loaded;
smbiosDir.dir[smbiosDirIndex].lock = MDR2DirLockEnum::mdr2DirUnlock;
}
- timer.stop();
return true;
}
@@ -505,9 +521,105 @@
result.push_back(smbiosDir.dir[idIndex].common.dataVersion);
result.push_back(smbiosDir.dir[idIndex].common.timestamp);
- timer.start(usec);
+ timer.expires_after(usec);
+ timer.async_wait([this](boost::system::error_code ec) {
+ if (ec || this == nullptr)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Timer Error!");
+ return;
+ }
+ agentSynchronizeData();
+ });
return result;
}
+std::vector<boost::container::flat_map<std::string, RecordVariant>>
+ MDR_V2::getRecordType(size_t type)
+{
+
+ std::vector<boost::container::flat_map<std::string, RecordVariant>> ret;
+ if (type == memoryDeviceType)
+ {
+
+ uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
+
+ if (dataIn == nullptr)
+ {
+ throw std::runtime_error("Data not populated");
+ }
+
+ do
+ {
+ dataIn =
+ getSMBIOSTypePtr(dataIn, memoryDeviceType, sizeof(MemoryInfo));
+ if (dataIn == nullptr)
+ {
+ break;
+ }
+ boost::container::flat_map<std::string, RecordVariant>& record =
+ ret.emplace_back();
+
+ auto memoryInfo = reinterpret_cast<MemoryInfo*>(dataIn);
+
+ record["Type"] = memoryInfo->type;
+ record["Length"] = memoryInfo->length;
+ record["Handle"] = uint16_t(memoryInfo->handle);
+ record["Physical Memory Array Handle"] =
+ uint16_t(memoryInfo->phyArrayHandle);
+ record["Memory Error Information Handle"] =
+ uint16_t(memoryInfo->errInfoHandle);
+ record["Total Width"] = uint16_t(memoryInfo->totalWidth);
+ record["Data Width"] = uint16_t(memoryInfo->dataWidth);
+ record["Size"] = uint16_t(memoryInfo->size);
+ record["Form Factor"] = memoryInfo->formFactor;
+ record["Device Set"] = memoryInfo->deviceSet;
+ record["Device Locator"] = positionToString(
+ memoryInfo->deviceLocator, memoryInfo->length, dataIn);
+ record["Bank Locator"] = positionToString(
+ memoryInfo->bankLocator, memoryInfo->length, dataIn);
+ record["Memory Type"] = memoryInfo->memoryType;
+ record["Type Detail"] = uint16_t(memoryInfo->typeDetail);
+ record["Speed"] = uint16_t(memoryInfo->speed);
+ record["Manufacturer"] = positionToString(
+ memoryInfo->manufacturer, memoryInfo->length, dataIn);
+ record["Serial Number"] = positionToString(
+ memoryInfo->serialNum, memoryInfo->length, dataIn);
+ record["Asset Tag"] = positionToString(memoryInfo->assetTag,
+ memoryInfo->length, dataIn);
+ record["Part Number"] = positionToString(
+ memoryInfo->partNum, memoryInfo->length, dataIn);
+ record["Attributes"] = memoryInfo->attributes;
+ record["Extended Size"] = uint32_t(memoryInfo->extendedSize);
+ record["Configured Memory Speed"] =
+ uint32_t(memoryInfo->confClockSpeed);
+ record["Minimum voltage"] = uint16_t(memoryInfo->minimumVoltage);
+ record["Maximum voltage"] = uint16_t(memoryInfo->maximumVoltage);
+ record["Configured voltage"] =
+ uint16_t(memoryInfo->configuredVoltage);
+ record["Memory Technology"] = memoryInfo->memoryTechnology;
+ record["Memory Operating Mode Capabilty"] =
+ uint16_t(memoryInfo->memoryOperatingModeCap);
+ record["Firmare Version"] = memoryInfo->firwareVersion;
+ record["Module Manufacturer ID"] =
+ uint16_t(memoryInfo->modelManufId);
+ record["Module Product ID"] = uint16_t(memoryInfo->modelProdId);
+ record["Memory Subsystem Controller Manufacturer ID"] =
+ uint16_t(memoryInfo->memSubConManufId);
+ record["Memory Subsystem Controller Product Id"] =
+ uint16_t(memoryInfo->memSubConProdId);
+ record["Non-volatile Size"] = uint64_t(memoryInfo->nvSize);
+ record["Volatile Size"] = uint64_t(memoryInfo->volatileSize);
+ record["Cache Size"] = uint64_t(memoryInfo->cacheSize);
+ record["Logical Size"] = uint64_t(memoryInfo->logicalSize);
+ } while ((dataIn = smbiosNextPtr(dataIn)) != nullptr);
+
+ return ret;
+ }
+
+ throw std::invalid_argument("Invalid record type");
+ return ret;
+}
+
} // namespace smbios
} // namespace phosphor
diff --git a/src/mdrv2_main.cpp b/src/mdrv2_main.cpp
index 42b874f..2699571 100644
--- a/src/mdrv2_main.cpp
+++ b/src/mdrv2_main.cpp
@@ -1,5 +1,5 @@
/*
-// Copyright (c) 2019 Intel Corporation
+// 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.
@@ -16,33 +16,32 @@
#include "mdrv2.hpp"
-#include <systemd/sd-event.h>
-
+#include <boost/asio/io_context.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+boost::asio::io_context io;
+auto connection = std::make_shared<sdbusplus::asio::connection>(io);
+auto objServer = sdbusplus::asio::object_server(connection);
+
+sdbusplus::asio::object_server& getObjectServer(void)
+{
+ return objServer;
+}
int main(void)
{
- sd_event* events = nullptr;
- sd_event_default(&events);
- sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
+ sdbusplus::bus::bus& bus = static_cast<sdbusplus::bus::bus&>(*connection);
sdbusplus::server::manager::manager objManager(
bus, "/xyz/openbmc_project/inventory");
- bus.attach_event(events, SD_EVENT_PRIORITY_NORMAL);
+
bus.request_name("xyz.openbmc_project.Smbios.MDR_V2");
- phosphor::smbios::MDR_V2 mdrV2(bus, mdrV2Path, events);
+ phosphor::smbios::MDR_V2 mdrV2(bus, phosphor::smbios::mdrV2Path, io);
- while (true)
- {
- int r = sd_event_run(events, (uint64_t)-1);
- if (r < 0)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Failure processing request",
- phosphor::logging::entry("errno=0x%X", -r));
- return -1;
- }
- }
+ io.run();
+
return 0;
}