blob: c9396e263c17953d7e6282f4d8c1babcae3dc30e [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"
Jie Yang08e4a6d2021-08-23 13:07:41 -070020#include "pcieslot.hpp"
Zhikui Ren18a5ab92020-09-01 21:35:20 -070021#include "smbios_mdrv2.hpp"
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080022#include "system.hpp"
Cheng C Yang3e3269a2019-12-02 15:11:30 +080023
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
Zhikui Ren18a5ab92020-09-01 21:35:20 -070028#include <boost/asio/io_context.hpp>
29#include <boost/asio/steady_timer.hpp>
30#include <boost/container/flat_map.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080031#include <phosphor-logging/elog-errors.hpp>
Alex Schendel5f2d6272021-09-22 10:35:40 -070032#include <phosphor-logging/lg2.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080033#include <phosphor-logging/log.hpp>
Zhikui Ren18a5ab92020-09-01 21:35:20 -070034#include <sdbusplus/asio/object_server.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080035#include <sdbusplus/server.hpp>
36#include <sdbusplus/timer.hpp>
Cheng C Yangeecaf822019-12-19 00:34:23 +080037#include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080038
Zhikui Ren18a5ab92020-09-01 21:35:20 -070039sdbusplus::asio::object_server& getObjectServer(void);
Cheng C Yang3e3269a2019-12-02 15:11:30 +080040
Zhikui Ren18a5ab92020-09-01 21:35:20 -070041using RecordVariant =
42 std::variant<std::string, uint64_t, uint32_t, uint16_t, uint8_t>;
Cheng C Yang3e3269a2019-12-02 15:11:30 +080043namespace phosphor
44{
45namespace smbios
46{
47
Zhikui Ren18a5ab92020-09-01 21:35:20 -070048static constexpr const char* mdrV2Path = "/xyz/openbmc_project/Smbios/MDR_V2";
49static constexpr const char* smbiosPath = "/xyz/openbmc_project/Smbios";
50static constexpr const char* smbiosInterfaceName =
51 "xyz.openbmc_project.Smbios.GetRecordType";
Gobinath Krishnamoorthybb9c6222022-11-03 20:08:01 +000052static constexpr const char* mapperBusName = "xyz.openbmc_project.ObjectMapper";
53static constexpr const char* mapperPath = "/xyz/openbmc_project/object_mapper";
54static constexpr const char* mapperInterface =
55 "xyz.openbmc_project.ObjectMapper";
56static constexpr const char* systemInterfacePath =
57 "/xyz/openbmc_project/inventory/system";
58static constexpr const char* systemInterface =
59 "xyz.openbmc_project.Inventory.Item.System";
Zhikui Ren18a5ab92020-09-01 21:35:20 -070060constexpr const int limitEntryLen = 0xff;
61
Jason M. Billsa3f5b382023-04-26 08:17:28 -070062class MDRV2 :
Patrick Williams77b9c472022-07-22 19:26:57 -050063 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070064 sdbusplus::server::xyz::openbmc_project::smbios::MDRV2>
Cheng C Yang3e3269a2019-12-02 15:11:30 +080065{
66 public:
Jason M. Billsa3f5b382023-04-26 08:17:28 -070067 MDRV2() = delete;
68 MDRV2(const MDRV2&) = delete;
69 MDRV2& operator=(const MDRV2&) = delete;
70 MDRV2(MDRV2&&) = delete;
71 MDRV2& operator=(MDRV2&&) = delete;
72 ~MDRV2() = default;
Cheng C Yang3e3269a2019-12-02 15:11:30 +080073
Jason M. Billsa3f5b382023-04-26 08:17:28 -070074 MDRV2(sdbusplus::bus_t& bus, const char* path,
75 boost::asio::io_context& io) :
Patrick Williams77b9c472022-07-22 19:26:57 -050076 sdbusplus::server::object_t<
Jason M. Bills33ae81f2023-04-26 09:06:08 -070077 sdbusplus::server::xyz::openbmc_project::smbios::MDRV2>(bus, path),
Zhikui Ren18a5ab92020-09-01 21:35:20 -070078 bus(bus), timer(io), smbiosInterface(getObjectServer().add_interface(
79 smbiosPath, smbiosInterfaceName))
Cheng C Yang3e3269a2019-12-02 15:11:30 +080080 {
81
82 smbiosDir.agentVersion = smbiosAgentVersion;
83 smbiosDir.dirVersion = 1;
84 smbiosDir.dirEntries = 1;
85 directoryEntries(smbiosDir.dirEntries);
86 smbiosDir.status = 1;
87 smbiosDir.remoteDirVersion = 0;
88
89 std::copy(smbiosTableId.begin(), smbiosTableId.end(),
90 smbiosDir.dir[smbiosDirIndex].common.id.dataInfo);
91
92 smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage;
93
94 agentSynchronizeData();
Zhikui Ren18a5ab92020-09-01 21:35:20 -070095
96 smbiosInterface->register_method("GetRecordType", [this](size_t type) {
97 return getRecordType(type);
98 });
99 smbiosInterface->initialize();
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800100 }
101
Cheng C Yangeecaf822019-12-19 00:34:23 +0800102 std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override;
103
104 std::vector<uint8_t> getDataInformation(uint8_t idIndex) override;
105
106 bool sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex,
107 uint8_t returnedEntries,
108 uint8_t remainingEntries,
109 std::vector<uint8_t> dirEntry) override;
110
111 std::vector<uint8_t> getDataOffer() override;
112
113 bool sendDataInformation(uint8_t idIndex, uint8_t flag, uint32_t dataLen,
114 uint32_t dataVer, uint32_t timeStamp) override;
115
116 int findIdIndex(std::vector<uint8_t> dataInfo) override;
117
118 bool agentSynchronizeData() override;
119
120 std::vector<uint32_t>
121 synchronizeDirectoryCommonData(uint8_t idIndex, uint32_t size) override;
122
123 uint8_t directoryEntries(uint8_t value) override;
124
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700125 std::vector<boost::container::flat_map<std::string, RecordVariant>>
126 getRecordType(size_t type);
127
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800128 private:
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700129 boost::asio::steady_timer timer;
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800130
Patrick Williams77b9c472022-07-22 19:26:57 -0500131 sdbusplus::bus_t& bus;
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800132
133 Mdr2DirStruct smbiosDir;
134
Cheng C Yangec634252019-12-19 00:42:36 +0800135 bool readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data);
Arun P. Mohanan0435a482022-02-01 21:45:55 +0530136 bool checkSMBIOSVersion(uint8_t* dataIn);
Cheng C Yangec634252019-12-19 00:42:36 +0800137
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800138 const std::array<uint8_t, 16> smbiosTableId{
139 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42};
140 uint8_t smbiosTableStorage[smbiosTableStorageSize];
141
142 bool smbiosIsUpdating(uint8_t index);
143 bool smbiosIsAvailForUpdate(uint8_t index);
144 inline uint8_t smbiosValidFlag(uint8_t index);
145 void systemInfoUpdate(void);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800146
147 int getTotalCpuSlot(void);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800148 int getTotalDimmSlot(void);
Jie Yang08e4a6d2021-08-23 13:07:41 -0700149 int getTotalPcieSlot(void);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800150 std::vector<std::unique_ptr<Cpu>> cpus;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800151 std::vector<std::unique_ptr<Dimm>> dimms;
Jie Yang08e4a6d2021-08-23 13:07:41 -0700152 std::vector<std::unique_ptr<Pcie>> pcies;
Cheng C Yangb4651b92019-12-19 00:59:01 +0800153 std::unique_ptr<System> system;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700154 std::shared_ptr<sdbusplus::asio::dbus_interface> smbiosInterface;
Cheng C Yang3e3269a2019-12-02 15:11:30 +0800155};
156
157} // namespace smbios
158} // namespace phosphor