Move downstream package to upstream
Use upstream cpu interface
Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: I490482b212df4b73cbdedaba0bc5fefa229a5489
diff --git a/include/smbios_mdrv2.hpp b/include/smbios_mdrv2.hpp
new file mode 100644
index 0000000..e53d709
--- /dev/null
+++ b/include/smbios_mdrv2.hpp
@@ -0,0 +1,244 @@
+/*
+// 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.
+*/
+
+#pragma once
+
+#include <phosphor-logging/elog-errors.hpp>
+
+#include <array>
+
+static constexpr const char* mdrType2File = "/var/lib/smbios/smbios2";
+static constexpr const char* smbiosPath = "/var/lib/smbios";
+
+static constexpr uint16_t mdrSMBIOSSize = 32 * 1024;
+
+constexpr uint16_t smbiosAgentId = 0x0101;
+constexpr int firstAgentIndex = 1;
+
+constexpr uint8_t maxDirEntries = 4;
+constexpr uint32_t mdr2SMSize = 0x00100000;
+constexpr uint32_t mdr2SMBaseAddress = 0x9FF00000;
+
+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
+{
+ dirDataNotRequested = 0x00,
+ dirDataRequested = 0x01
+};
+
+enum class FlagStatus
+{
+ flagIsInvalid = 0,
+ flagIsValid = 1,
+ 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,
+ systemType = 1,
+ baseboardType = 2,
+ chassisType = 3,
+ processorsType = 4,
+ memoryControllerType = 5,
+ memoryModuleInformationType = 6,
+ cacheType = 7,
+ portConnectorType = 8,
+ systemSlots = 9,
+ onBoardDevicesType = 10,
+ oemStringsType = 11,
+ systemCconfigurationOptionsType = 12,
+ biosLanguageType = 13,
+ groupAssociatonsType = 14,
+ systemEventLogType = 15,
+ physicalMemoryArrayType = 16,
+ memoryDeviceType = 17,
+} SmbiosType;
+
+static constexpr uint8_t separateLen = 2;
+
+static inline uint8_t* smbiosNextPtr(uint8_t* smbiosDataIn)
+{
+ if (smbiosDataIn == nullptr)
+ {
+ return nullptr;
+ }
+ uint8_t* smbiosData = smbiosDataIn + *(smbiosDataIn + 1);
+ int len = 0;
+ while ((*smbiosData | *(smbiosData + 1)) != 0)
+ {
+ smbiosData++;
+ len++;
+ if (len >= mdrSMBIOSSize) // To avoid endless loop
+ {
+ return nullptr;
+ }
+ }
+ return smbiosData + separateLen;
+}
+
+// When first time run getSMBIOSTypePtr, need to send the RegionS[].regionData
+// to smbiosDataIn
+static inline uint8_t* getSMBIOSTypePtr(uint8_t* smbiosDataIn, uint8_t typeId,
+ size_t size = 0)
+{
+ if (smbiosDataIn == nullptr)
+ {
+ return nullptr;
+ }
+ char* smbiosData = reinterpret_cast<char*>(smbiosDataIn);
+ while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
+ {
+ uint32_t len = *(smbiosData + 1);
+ if (*smbiosData != typeId)
+ {
+
+ smbiosData += len;
+ while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
+ {
+ smbiosData++;
+ len++;
+ if (len >= mdrSMBIOSSize) // To avoid endless loop
+ {
+ return nullptr;
+ }
+ }
+ 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;
+}
+
+static inline std::string positionToString(uint8_t positionNum,
+ uint8_t structLen, uint8_t* dataIn)
+{
+ if (dataIn == nullptr)
+ {
+ return "";
+ }
+ uint16_t limit = mdrSMBIOSSize; // set a limit to avoid endless loop
+
+ char* target = reinterpret_cast<char*>(dataIn + structLen);
+ for (uint8_t index = 1; index < positionNum; index++)
+ {
+ for (; *target != '\0'; target++)
+ {
+ limit--;
+ if (limit < 1)
+ {
+ return "";
+ }
+ }
+ target++;
+ if (*target == '\0')
+ {
+ return ""; // 0x00 0x00 means end of the entry.
+ }
+ }
+
+ std::string result = target;
+ return result;
+}