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> |
Alex Schendel | 5f2d627 | 2021-09-22 10:35:40 -0700 | [diff] [blame] | 32 | #include <phosphor-logging/lg2.hpp> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 33 | #include <phosphor-logging/log.hpp> |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 34 | #include <sdbusplus/asio/object_server.hpp> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 35 | #include <sdbusplus/server.hpp> |
| 36 | #include <sdbusplus/timer.hpp> |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 37 | #include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 38 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 39 | sdbusplus::asio::object_server& getObjectServer(void); |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 40 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 41 | using RecordVariant = |
| 42 | 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] | 43 | namespace phosphor |
| 44 | { |
| 45 | namespace smbios |
| 46 | { |
| 47 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 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"; |
Gobinath Krishnamoorthy | bb9c622 | 2022-11-03 20:08:01 +0000 | [diff] [blame] | 52 | static constexpr const char* mapperBusName = "xyz.openbmc_project.ObjectMapper"; |
| 53 | static constexpr const char* mapperPath = "/xyz/openbmc_project/object_mapper"; |
| 54 | static constexpr const char* mapperInterface = |
| 55 | "xyz.openbmc_project.ObjectMapper"; |
| 56 | static constexpr const char* systemInterfacePath = |
| 57 | "/xyz/openbmc_project/inventory/system"; |
| 58 | static constexpr const char* systemInterface = |
| 59 | "xyz.openbmc_project.Inventory.Item.System"; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 60 | constexpr const int limitEntryLen = 0xff; |
| 61 | |
Jason M. Bills | a3f5b38 | 2023-04-26 08:17:28 -0700 | [diff] [blame] | 62 | class MDRV2 : |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 63 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 64 | sdbusplus::server::xyz::openbmc_project::smbios::MDRV2> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 65 | { |
| 66 | public: |
Jason M. Bills | a3f5b38 | 2023-04-26 08:17:28 -0700 | [diff] [blame] | 67 | 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 Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 73 | |
Jason M. Bills | a3f5b38 | 2023-04-26 08:17:28 -0700 | [diff] [blame] | 74 | MDRV2(sdbusplus::bus_t& bus, const char* path, |
| 75 | boost::asio::io_context& io) : |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 76 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 77 | sdbusplus::server::xyz::openbmc_project::smbios::MDRV2>(bus, path), |
Jonathan Doman | f2d8bb4 | 2023-07-26 10:13:34 -0700 | [diff] [blame] | 78 | timer(io), bus(bus), smbiosInterface(getObjectServer().add_interface( |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 79 | smbiosPath, smbiosInterfaceName)) |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 80 | { |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 81 | smbiosDir.agentVersion = smbiosAgentVersion; |
| 82 | smbiosDir.dirVersion = 1; |
| 83 | smbiosDir.dirEntries = 1; |
| 84 | directoryEntries(smbiosDir.dirEntries); |
| 85 | smbiosDir.status = 1; |
| 86 | smbiosDir.remoteDirVersion = 0; |
| 87 | |
| 88 | std::copy(smbiosTableId.begin(), smbiosTableId.end(), |
| 89 | smbiosDir.dir[smbiosDirIndex].common.id.dataInfo); |
| 90 | |
| 91 | smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage; |
| 92 | |
| 93 | agentSynchronizeData(); |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 94 | |
| 95 | smbiosInterface->register_method("GetRecordType", [this](size_t type) { |
| 96 | return getRecordType(type); |
| 97 | }); |
| 98 | smbiosInterface->initialize(); |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 99 | } |
| 100 | |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 101 | std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override; |
| 102 | |
| 103 | std::vector<uint8_t> getDataInformation(uint8_t idIndex) override; |
| 104 | |
| 105 | bool sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex, |
| 106 | uint8_t returnedEntries, |
| 107 | uint8_t remainingEntries, |
| 108 | std::vector<uint8_t> dirEntry) override; |
| 109 | |
| 110 | std::vector<uint8_t> getDataOffer() override; |
| 111 | |
| 112 | bool sendDataInformation(uint8_t idIndex, uint8_t flag, uint32_t dataLen, |
| 113 | uint32_t dataVer, uint32_t timeStamp) override; |
| 114 | |
| 115 | int findIdIndex(std::vector<uint8_t> dataInfo) override; |
| 116 | |
| 117 | bool agentSynchronizeData() override; |
| 118 | |
| 119 | std::vector<uint32_t> |
| 120 | synchronizeDirectoryCommonData(uint8_t idIndex, uint32_t size) override; |
| 121 | |
| 122 | uint8_t directoryEntries(uint8_t value) override; |
| 123 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 124 | std::vector<boost::container::flat_map<std::string, RecordVariant>> |
| 125 | getRecordType(size_t type); |
| 126 | |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 127 | private: |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 128 | boost::asio::steady_timer timer; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 129 | |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 130 | sdbusplus::bus_t& bus; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 131 | |
| 132 | Mdr2DirStruct smbiosDir; |
| 133 | |
Cheng C Yang | ec63425 | 2019-12-19 00:42:36 +0800 | [diff] [blame] | 134 | bool readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data); |
Arun P. Mohanan | 0435a48 | 2022-02-01 21:45:55 +0530 | [diff] [blame] | 135 | bool checkSMBIOSVersion(uint8_t* dataIn); |
Cheng C Yang | ec63425 | 2019-12-19 00:42:36 +0800 | [diff] [blame] | 136 | |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 137 | const std::array<uint8_t, 16> smbiosTableId{ |
| 138 | 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42}; |
| 139 | uint8_t smbiosTableStorage[smbiosTableStorageSize]; |
| 140 | |
| 141 | bool smbiosIsUpdating(uint8_t index); |
| 142 | bool smbiosIsAvailForUpdate(uint8_t index); |
| 143 | inline uint8_t smbiosValidFlag(uint8_t index); |
| 144 | void systemInfoUpdate(void); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 145 | |
Jonathan Doman | f2d8bb4 | 2023-07-26 10:13:34 -0700 | [diff] [blame] | 146 | std::optional<size_t> getTotalCpuSlot(void); |
| 147 | std::optional<size_t> getTotalDimmSlot(void); |
| 148 | std::optional<size_t> getTotalPcieSlot(void); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 149 | std::vector<std::unique_ptr<Cpu>> cpus; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 150 | std::vector<std::unique_ptr<Dimm>> dimms; |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 151 | std::vector<std::unique_ptr<Pcie>> pcies; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 152 | std::unique_ptr<System> system; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 153 | std::shared_ptr<sdbusplus::asio::dbus_interface> smbiosInterface; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | } // namespace smbios |
| 157 | } // namespace phosphor |