Add some header files of MDR

To start the work of ManagedDataRegion, add some header files to
the repo.

Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Change-Id: I9dfad809d47f37f04ca6b8a7ca2e809cae79c012
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..ea71ad6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,99 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass:      true
+  AfterControlStatement: true
+  AfterEnum:       true
+  AfterFunction:   true
+  AfterNamespace:  true
+  AfterObjCDeclaration: true
+  AfterStruct:     true
+  AfterUnion:      true
+  BeforeCatch:     true
+  BeforeElse:      true
+  IndentBraces:    false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+  - Regex:           '^[<"](gtest|gmock)'
+    Priority:        5
+  - Regex:           '^"config.h"'
+    Priority:        -1
+  - Regex:           '^".*\.hpp"'
+    Priority:        1
+  - Regex:           '^<.*\.h>'
+    Priority:        2
+  - Regex:           '^<.*'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        4
+IndentCaseLabels: true
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        4
+UseTab:          Never
+...
+
diff --git a/include/mdrv2.hpp b/include/mdrv2.hpp
new file mode 100644
index 0000000..5313bec
--- /dev/null
+++ b/include/mdrv2.hpp
@@ -0,0 +1,145 @@
+/*
+// Copyright (c) 2019 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 <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/server.hpp>
+#include <sdbusplus/timer.hpp>
+
+static constexpr uint8_t mdr2Version = 2;
+static constexpr uint32_t mdr2SMSize = 0x00100000;
+static constexpr uint16_t mdrSMBIOSSize = 32 * 1024;
+static constexpr uint32_t mdr2SMBaseAddress = 0x9FF00000;
+static constexpr const char* mdrType2File = "/var/lib/smbios/smbios2";
+
+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));
+
+namespace phosphor
+{
+namespace smbios
+{
+
+class MDR_V2
+{
+  public:
+    MDR_V2() = delete;
+    MDR_V2(const MDR_V2&) = delete;
+    MDR_V2& operator=(const MDR_V2&) = delete;
+    MDR_V2(MDR_V2&&) = delete;
+    MDR_V2& operator=(MDR_V2&&) = delete;
+    ~MDR_V2() = default;
+
+    MDR_V2(sdbusplus::bus::bus& bus, const char* path, sd_event* event) :
+        bus(bus), timer(event, [&](void) { agentSynchronizeData(); })
+    {
+
+        smbiosDir.agentVersion = smbiosAgentVersion;
+        smbiosDir.dirVersion = 1;
+        smbiosDir.dirEntries = 1;
+        directoryEntries(smbiosDir.dirEntries);
+        smbiosDir.status = 1;
+        smbiosDir.remoteDirVersion = 0;
+
+        std::copy(smbiosTableId.begin(), smbiosTableId.end(),
+                  smbiosDir.dir[smbiosDirIndex].common.id.dataInfo);
+
+        smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage;
+
+        agentSynchronizeData();
+    }
+
+  private:
+    Timer timer;
+
+    sdbusplus::bus::bus& bus;
+
+    Mdr2DirStruct smbiosDir;
+
+    const std::array<uint8_t, 16> smbiosTableId{
+        40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42};
+    uint8_t smbiosTableStorage[smbiosTableStorageSize];
+
+    bool smbiosIsUpdating(uint8_t index);
+    bool smbiosIsAvailForUpdate(uint8_t index);
+    inline uint8_t smbiosValidFlag(uint8_t index);
+    void systemInfoUpdate(void);
+};
+
+} // namespace smbios
+} // namespace phosphor
diff --git a/include/smbios.hpp b/include/smbios.hpp
new file mode 100644
index 0000000..b39229d
--- /dev/null
+++ b/include/smbios.hpp
@@ -0,0 +1,68 @@
+/*
+// Copyright (c) 2019 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 <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* smbiosPath = "/var/lib/smbios";
+
+enum class DirDataRequestEnum
+{
+    dirDataNotRequested = 0x00,
+    dirDataRequested = 0x01
+};
+
+enum class FlagStatus
+{
+    flagIsInvalid = 0,
+    flagIsValid = 1,
+    flagIsLocked = 2
+};
+
+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;