blob: 8f03579638f10aa707a002433187fae18e5387d9 [file] [log] [blame]
Cheng C Yang3e3269a2019-12-02 15:11:30 +08001/*
Zhikui Ren18a5ab92020-09-01 21:35:20 -07002// Copyright (c) 2018 Intel Corporation
Cheng C Yang3e3269a2019-12-02 15:11:30 +08003//
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
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080018#include "cpu.hpp"
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080019#include "dimm.hpp"
Zhikui Ren18a5ab92020-09-01 21:35:20 -070020#include "smbios_mdrv2.hpp"
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080021#include "system.hpp"
Cheng C Yang3e3269a2019-12-02 15:11:30 +080022
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <unistd.h>
26
Zhikui Ren18a5ab92020-09-01 21:35:20 -070027#include <boost/asio/io_context.hpp>
28#include <boost/asio/steady_timer.hpp>
29#include <boost/container/flat_map.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080030#include <phosphor-logging/elog-errors.hpp>
31#include <phosphor-logging/log.hpp>
Zhikui Ren18a5ab92020-09-01 21:35:20 -070032#include <sdbusplus/asio/object_server.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080033#include <sdbusplus/server.hpp>
34#include <sdbusplus/timer.hpp>
Cheng C Yangeecaf822019-12-19 00:34:23 +080035#include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080036
Zhikui Ren18a5ab92020-09-01 21:35:20 -070037sdbusplus::asio::object_server& getObjectServer(void);
Cheng C Yang3e3269a2019-12-02 15:11:30 +080038
Zhikui Ren18a5ab92020-09-01 21:35:20 -070039using RecordVariant =
40 std::variant<std::string, uint64_t, uint32_t, uint16_t, uint8_t>;
Cheng C Yang3e3269a2019-12-02 15:11:30 +080041namespace phosphor
42{
43namespace smbios
44{
45
Zhikui Ren18a5ab92020-09-01 21:35:20 -070046static constexpr const char* mdrV2Path = "/xyz/openbmc_project/Smbios/MDR_V2";
47static constexpr const char* smbiosPath = "/xyz/openbmc_project/Smbios";
48static constexpr const char* smbiosInterfaceName =
49 "xyz.openbmc_project.Smbios.GetRecordType";
50constexpr const int limitEntryLen = 0xff;
51
52class MDR_V2 :
53 sdbusplus::server::object::object<
54 sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080055{
56 public:
57 MDR_V2() = delete;
58 MDR_V2(const MDR_V2&) = delete;
59 MDR_V2& operator=(const MDR_V2&) = delete;
60 MDR_V2(MDR_V2&&) = delete;
61 MDR_V2& operator=(MDR_V2&&) = delete;
62 ~MDR_V2() = default;
63
Zhikui Ren18a5ab92020-09-01 21:35:20 -070064 MDR_V2(sdbusplus::bus::bus& bus, const char* path,
65 boost::asio::io_context& io) :
Cheng C Yangeecaf822019-12-19 00:34:23 +080066 sdbusplus::server::object::object<
67 sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>(bus, path),
Zhikui Ren18a5ab92020-09-01 21:35:20 -070068 bus(bus), timer(io), smbiosInterface(getObjectServer().add_interface(
69 smbiosPath, smbiosInterfaceName))
Cheng C Yang3e3269a2019-12-02 15:11:30 +080070 {
71
72 smbiosDir.agentVersion = smbiosAgentVersion;
73 smbiosDir.dirVersion = 1;
74 smbiosDir.dirEntries = 1;
75 directoryEntries(smbiosDir.dirEntries);
76 smbiosDir.status = 1;
77 smbiosDir.remoteDirVersion = 0;
78
79 std::copy(smbiosTableId.begin(), smbiosTableId.end(),
80 smbiosDir.dir[smbiosDirIndex].common.id.dataInfo);
81
82 smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage;
83
84 agentSynchronizeData();
Zhikui Ren18a5ab92020-09-01 21:35:20 -070085
86 smbiosInterface->register_method("GetRecordType", [this](size_t type) {
87 return getRecordType(type);
88 });
89 smbiosInterface->initialize();
Cheng C Yang3e3269a2019-12-02 15:11:30 +080090 }
91
Cheng C Yangeecaf822019-12-19 00:34:23 +080092 std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override;
93
94 std::vector<uint8_t> getDataInformation(uint8_t idIndex) override;
95
96 bool sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex,
97 uint8_t returnedEntries,
98 uint8_t remainingEntries,
99 std::vector<uint8_t> dirEntry) override;
100
101 std::vector<uint8_t> getDataOffer() override;
102
103 bool sendDataInformation(uint8_t idIndex, uint8_t flag, uint32_t dataLen,
104 uint32_t dataVer, uint32_t timeStamp) override;
105
106 int findIdIndex(std::vector<uint8_t> dataInfo) override;
107
108 bool agentSynchronizeData() override;
109
110 std::vector<uint32_t>
111 synchronizeDirectoryCommonData(uint8_t idIndex, uint32_t size) override;
112
113 uint8_t directoryEntries(uint8_t value) override;
114
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700115 std::vector<boost::container::flat_map<std::string, RecordVariant>>
116 getRecordType(size_t type);
117
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800118 private:
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700119 boost::asio::steady_timer timer;
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800120
121 sdbusplus::bus::bus& bus;
122
123 Mdr2DirStruct smbiosDir;
124
Cheng C Yangec634252019-12-19 00:42:36 +0800125 bool readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data);
126
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800127 const std::array<uint8_t, 16> smbiosTableId{
128 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42};
129 uint8_t smbiosTableStorage[smbiosTableStorageSize];
130
131 bool smbiosIsUpdating(uint8_t index);
132 bool smbiosIsAvailForUpdate(uint8_t index);
133 inline uint8_t smbiosValidFlag(uint8_t index);
134 void systemInfoUpdate(void);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800135
136 int getTotalCpuSlot(void);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800137 int getTotalDimmSlot(void);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800138 std::vector<std::unique_ptr<Cpu>> cpus;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800139 std::vector<std::unique_ptr<Dimm>> dimms;
Cheng C Yangb4651b92019-12-19 00:59:01 +0800140 std::unique_ptr<System> system;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700141 std::shared_ptr<sdbusplus::asio::dbus_interface> smbiosInterface;
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800142};
143
144} // namespace smbios
145} // namespace phosphor