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