1 /* 2 // Copyright (c) 2018 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 #include "cpu.hpp" 19 #include "dimm.hpp" 20 #include "pcieslot.hpp" 21 #include "smbios_mdrv2.hpp" 22 #include "system.hpp" 23 24 #include <sys/stat.h> 25 #include <sys/types.h> 26 #include <unistd.h> 27 28 #include <boost/asio/io_context.hpp> 29 #include <boost/asio/steady_timer.hpp> 30 #include <boost/container/flat_map.hpp> 31 #include <phosphor-logging/elog-errors.hpp> 32 #include <phosphor-logging/lg2.hpp> 33 #include <phosphor-logging/log.hpp> 34 #include <sdbusplus/asio/object_server.hpp> 35 #include <sdbusplus/server.hpp> 36 #include <sdbusplus/timer.hpp> 37 #include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp> 38 39 sdbusplus::asio::object_server& getObjectServer(void); 40 41 using RecordVariant = 42 std::variant<std::string, uint64_t, uint32_t, uint16_t, uint8_t>; 43 namespace phosphor 44 { 45 namespace smbios 46 { 47 48 static constexpr const char* mdrV2Path = "/xyz/openbmc_project/Smbios/MDR_V2"; 49 static constexpr const char* smbiosPath = "/xyz/openbmc_project/Smbios"; 50 static constexpr const char* smbiosInterfaceName = 51 "xyz.openbmc_project.Smbios.GetRecordType"; 52 constexpr const int limitEntryLen = 0xff; 53 54 class MDR_V2 : 55 sdbusplus::server::object::object< 56 sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2> 57 { 58 public: 59 MDR_V2() = delete; 60 MDR_V2(const MDR_V2&) = delete; 61 MDR_V2& operator=(const MDR_V2&) = delete; 62 MDR_V2(MDR_V2&&) = delete; 63 MDR_V2& operator=(MDR_V2&&) = delete; 64 ~MDR_V2() = default; 65 66 MDR_V2(sdbusplus::bus::bus& bus, const char* path, 67 boost::asio::io_context& io) : 68 sdbusplus::server::object::object< 69 sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2>(bus, path), 70 bus(bus), timer(io), smbiosInterface(getObjectServer().add_interface( 71 smbiosPath, smbiosInterfaceName)) 72 { 73 74 smbiosDir.agentVersion = smbiosAgentVersion; 75 smbiosDir.dirVersion = 1; 76 smbiosDir.dirEntries = 1; 77 directoryEntries(smbiosDir.dirEntries); 78 smbiosDir.status = 1; 79 smbiosDir.remoteDirVersion = 0; 80 81 std::copy(smbiosTableId.begin(), smbiosTableId.end(), 82 smbiosDir.dir[smbiosDirIndex].common.id.dataInfo); 83 84 smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage; 85 86 agentSynchronizeData(); 87 88 smbiosInterface->register_method("GetRecordType", [this](size_t type) { 89 return getRecordType(type); 90 }); 91 smbiosInterface->initialize(); 92 } 93 94 std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override; 95 96 std::vector<uint8_t> getDataInformation(uint8_t idIndex) override; 97 98 bool sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex, 99 uint8_t returnedEntries, 100 uint8_t remainingEntries, 101 std::vector<uint8_t> dirEntry) override; 102 103 std::vector<uint8_t> getDataOffer() override; 104 105 bool sendDataInformation(uint8_t idIndex, uint8_t flag, uint32_t dataLen, 106 uint32_t dataVer, uint32_t timeStamp) override; 107 108 int findIdIndex(std::vector<uint8_t> dataInfo) override; 109 110 bool agentSynchronizeData() override; 111 112 std::vector<uint32_t> 113 synchronizeDirectoryCommonData(uint8_t idIndex, uint32_t size) override; 114 115 uint8_t directoryEntries(uint8_t value) override; 116 117 std::vector<boost::container::flat_map<std::string, RecordVariant>> 118 getRecordType(size_t type); 119 120 private: 121 boost::asio::steady_timer timer; 122 123 sdbusplus::bus::bus& bus; 124 125 Mdr2DirStruct smbiosDir; 126 127 bool readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data); 128 129 const std::array<uint8_t, 16> smbiosTableId{ 130 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42}; 131 uint8_t smbiosTableStorage[smbiosTableStorageSize]; 132 133 bool smbiosIsUpdating(uint8_t index); 134 bool smbiosIsAvailForUpdate(uint8_t index); 135 inline uint8_t smbiosValidFlag(uint8_t index); 136 void systemInfoUpdate(void); 137 138 int getTotalCpuSlot(void); 139 int getTotalDimmSlot(void); 140 int getTotalPcieSlot(void); 141 std::vector<std::unique_ptr<Cpu>> cpus; 142 std::vector<std::unique_ptr<Dimm>> dimms; 143 std::vector<std::unique_ptr<Pcie>> pcies; 144 std::unique_ptr<System> system; 145 std::shared_ptr<sdbusplus::asio::dbus_interface> smbiosInterface; 146 }; 147 148 } // namespace smbios 149 } // namespace phosphor 150