blob: 4a46c122ccacaf5ba383f4fe87f3e4086bccb455 [file] [log] [blame]
Cheng C Yang3e3269a2019-12-02 15:11:30 +08001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#pragma once
18
19#include <sys/stat.h>
20#include <sys/types.h>
21#include <unistd.h>
22
23#include <phosphor-logging/elog-errors.hpp>
24#include <phosphor-logging/log.hpp>
25#include <sdbusplus/server.hpp>
26#include <sdbusplus/timer.hpp>
Cheng C Yangeecaf822019-12-19 00:34:23 +080027#include <smbios.hpp>
28#include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080029
30static constexpr uint8_t mdr2Version = 2;
31static constexpr uint32_t mdr2SMSize = 0x00100000;
Cheng C Yang3e3269a2019-12-02 15:11:30 +080032static constexpr uint32_t mdr2SMBaseAddress = 0x9FF00000;
33static constexpr const char* mdrType2File = "/var/lib/smbios/smbios2";
Cheng C Yangeecaf822019-12-19 00:34:23 +080034static constexpr const char* mdrV2Path = "/xyz/openbmc_project/Smbios/MDR_V2";
Cheng C Yang3e3269a2019-12-02 15:11:30 +080035
36enum class MDR2SMBIOSStatusEnum
37{
38 mdr2Init = 0,
39 mdr2Loaded = 1,
40 mdr2Updated = 2,
41 mdr2Updating = 3
42};
43
44enum class MDR2DirLockEnum
45{
46 mdr2DirUnlock = 0,
47 mdr2DirLock = 1
48};
49
50typedef struct
51{
52 uint8_t dataInfo[16];
53} DataIdStruct;
54
55typedef struct
56{
57 DataIdStruct id;
58 uint32_t size;
59 uint32_t dataSetSize;
60 uint32_t dataVersion;
61 uint32_t timestamp;
62} Mdr2DirEntry;
63
64typedef struct
65{
66 Mdr2DirEntry common;
67 MDR2SMBIOSStatusEnum stage;
68 MDR2DirLockEnum lock;
69 uint16_t lockHandle;
70 uint32_t xferBuff;
71 uint32_t xferSize;
72 uint32_t maxDataSize;
73 uint8_t* dataStorage;
74} Mdr2DirLocalStruct;
75
76typedef struct
77{
78 uint8_t agentVersion;
79 uint8_t dirVersion;
80 uint8_t dirEntries;
81 uint8_t status; // valid / locked / etc
82 uint8_t remoteDirVersion;
83 uint16_t sessionHandle;
84 Mdr2DirLocalStruct dir[maxDirEntries];
85} Mdr2DirStruct;
86
87struct MDRSMBIOSHeader
88{
89 uint8_t dirVer;
90 uint8_t mdrType;
91 uint32_t timestamp;
92 uint32_t dataSize;
93} __attribute__((packed));
94
95namespace phosphor
96{
97namespace smbios
98{
99
Cheng C Yangeecaf822019-12-19 00:34:23 +0800100class MDR_V2 : sdbusplus::server::object::object<
101 sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800102{
103 public:
104 MDR_V2() = delete;
105 MDR_V2(const MDR_V2&) = delete;
106 MDR_V2& operator=(const MDR_V2&) = delete;
107 MDR_V2(MDR_V2&&) = delete;
108 MDR_V2& operator=(MDR_V2&&) = delete;
109 ~MDR_V2() = default;
110
111 MDR_V2(sdbusplus::bus::bus& bus, const char* path, sd_event* event) :
Cheng C Yangeecaf822019-12-19 00:34:23 +0800112 sdbusplus::server::object::object<
113 sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>(bus, path),
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800114 bus(bus), timer(event, [&](void) { agentSynchronizeData(); })
115 {
116
117 smbiosDir.agentVersion = smbiosAgentVersion;
118 smbiosDir.dirVersion = 1;
119 smbiosDir.dirEntries = 1;
120 directoryEntries(smbiosDir.dirEntries);
121 smbiosDir.status = 1;
122 smbiosDir.remoteDirVersion = 0;
123
124 std::copy(smbiosTableId.begin(), smbiosTableId.end(),
125 smbiosDir.dir[smbiosDirIndex].common.id.dataInfo);
126
127 smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage;
128
129 agentSynchronizeData();
130 }
131
Cheng C Yangeecaf822019-12-19 00:34:23 +0800132 std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override;
133
134 std::vector<uint8_t> getDataInformation(uint8_t idIndex) override;
135
136 bool sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex,
137 uint8_t returnedEntries,
138 uint8_t remainingEntries,
139 std::vector<uint8_t> dirEntry) override;
140
141 std::vector<uint8_t> getDataOffer() override;
142
143 bool sendDataInformation(uint8_t idIndex, uint8_t flag, uint32_t dataLen,
144 uint32_t dataVer, uint32_t timeStamp) override;
145
146 int findIdIndex(std::vector<uint8_t> dataInfo) override;
147
148 bool agentSynchronizeData() override;
149
150 std::vector<uint32_t>
151 synchronizeDirectoryCommonData(uint8_t idIndex, uint32_t size) override;
152
153 uint8_t directoryEntries(uint8_t value) override;
154
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800155 private:
156 Timer timer;
157
158 sdbusplus::bus::bus& bus;
159
160 Mdr2DirStruct smbiosDir;
161
162 const std::array<uint8_t, 16> smbiosTableId{
163 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42};
164 uint8_t smbiosTableStorage[smbiosTableStorageSize];
165
166 bool smbiosIsUpdating(uint8_t index);
167 bool smbiosIsAvailForUpdate(uint8_t index);
168 inline uint8_t smbiosValidFlag(uint8_t index);
169 void systemInfoUpdate(void);
170};
171
172} // namespace smbios
173} // namespace phosphor