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" |
Prithvi Pai | 6f9e7a7 | 2025-03-14 13:05:02 +0530 | [diff] [blame] | 20 | #include "firmware_inventory.hpp" |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 21 | #include "pcieslot.hpp" |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 22 | #include "smbios_mdrv2.hpp" |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 23 | #include "system.hpp" |
Prithvi Pai | 5af42bb | 2025-02-11 17:59:07 +0530 | [diff] [blame] | 24 | #include "tpm.hpp" |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 25 | |
| 26 | #include <sys/stat.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <unistd.h> |
| 29 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 30 | #include <boost/asio/io_context.hpp> |
| 31 | #include <boost/asio/steady_timer.hpp> |
| 32 | #include <boost/container/flat_map.hpp> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 33 | #include <phosphor-logging/elog-errors.hpp> |
Alex Schendel | 5f2d627 | 2021-09-22 10:35:40 -0700 | [diff] [blame] | 34 | #include <phosphor-logging/lg2.hpp> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 35 | #include <phosphor-logging/log.hpp> |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 36 | #include <sdbusplus/asio/object_server.hpp> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 37 | #include <sdbusplus/server.hpp> |
| 38 | #include <sdbusplus/timer.hpp> |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 39 | #include <xyz/openbmc_project/Smbios/MDR_V2/server.hpp> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 40 | |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 41 | #include <filesystem> |
| 42 | #include <memory> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 43 | |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 44 | namespace phosphor |
| 45 | { |
| 46 | namespace smbios |
| 47 | { |
| 48 | |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 49 | using RecordVariant = |
| 50 | std::variant<std::string, uint64_t, uint32_t, uint16_t, uint8_t>; |
| 51 | |
| 52 | static constexpr const char* defaultObjectPath = |
| 53 | "/xyz/openbmc_project/Smbios/MDR_V2"; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 54 | static constexpr const char* smbiosInterfaceName = |
| 55 | "xyz.openbmc_project.Smbios.GetRecordType"; |
Gobinath Krishnamoorthy | bb9c622 | 2022-11-03 20:08:01 +0000 | [diff] [blame] | 56 | static constexpr const char* mapperBusName = "xyz.openbmc_project.ObjectMapper"; |
| 57 | static constexpr const char* mapperPath = "/xyz/openbmc_project/object_mapper"; |
| 58 | static constexpr const char* mapperInterface = |
| 59 | "xyz.openbmc_project.ObjectMapper"; |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 60 | static constexpr const char* defaultInventoryPath = |
Gobinath Krishnamoorthy | bb9c622 | 2022-11-03 20:08:01 +0000 | [diff] [blame] | 61 | "/xyz/openbmc_project/inventory/system"; |
| 62 | static constexpr const char* systemInterface = |
| 63 | "xyz.openbmc_project.Inventory.Item.System"; |
Josh Lehan | abdccd3 | 2024-01-26 15:49:50 -0800 | [diff] [blame] | 64 | static constexpr const char* boardInterface = |
| 65 | "xyz.openbmc_project.Inventory.Item.Board"; |
Prithvi Pai | 6f9e7a7 | 2025-03-14 13:05:02 +0530 | [diff] [blame] | 66 | static constexpr const char* versionInterface = |
| 67 | "xyz.openbmc_project.Software.Version"; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 68 | constexpr const int limitEntryLen = 0xff; |
| 69 | |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 70 | // Avoid putting multiple interfaces with same name on same object |
| 71 | static std::string placeGetRecordType(const std::string& objectPath) |
| 72 | { |
| 73 | if (objectPath != defaultObjectPath) |
| 74 | { |
| 75 | // Place GetRecordType interface on object itself, not parent |
| 76 | return objectPath; |
| 77 | } |
| 78 | |
| 79 | std::filesystem::path path(objectPath); |
| 80 | |
| 81 | // As there is only one default, safe to place it on the common parent |
| 82 | return path.parent_path().string(); |
| 83 | } |
| 84 | |
Jason M. Bills | a3f5b38 | 2023-04-26 08:17:28 -0700 | [diff] [blame] | 85 | class MDRV2 : |
Patrick Williams | 77b9c47 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 86 | sdbusplus::server::object_t< |
Jason M. Bills | 33ae81f | 2023-04-26 09:06:08 -0700 | [diff] [blame] | 87 | sdbusplus::server::xyz::openbmc_project::smbios::MDRV2> |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 88 | { |
| 89 | public: |
Jason M. Bills | a3f5b38 | 2023-04-26 08:17:28 -0700 | [diff] [blame] | 90 | MDRV2() = delete; |
| 91 | MDRV2(const MDRV2&) = delete; |
| 92 | MDRV2& operator=(const MDRV2&) = delete; |
| 93 | MDRV2(MDRV2&&) = delete; |
| 94 | MDRV2& operator=(MDRV2&&) = delete; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 95 | |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 96 | virtual ~MDRV2() |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 97 | { |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 98 | if (smbiosInterface) |
| 99 | { |
| 100 | if (objServer) |
| 101 | { |
| 102 | // Must manually undo add_interface() |
| 103 | objServer->remove_interface(smbiosInterface); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | MDRV2(std::shared_ptr<boost::asio::io_context> io, |
| 109 | std::shared_ptr<sdbusplus::asio::connection> conn, |
| 110 | std::shared_ptr<sdbusplus::asio::object_server> obj, |
| 111 | std::string filePath, std::string objectPath, |
| 112 | std::string inventoryPath) : |
| 113 | sdbusplus::server::object_t< |
| 114 | sdbusplus::server::xyz::openbmc_project::smbios::MDRV2>( |
| 115 | *conn, objectPath.c_str()), |
| 116 | timer(*io), bus(conn), objServer(std::move(obj)), |
| 117 | smbiosInterface(objServer->add_interface(placeGetRecordType(objectPath), |
| 118 | smbiosInterfaceName)), |
| 119 | smbiosFilePath(std::move(filePath)), |
| 120 | smbiosObjectPath(std::move(objectPath)), |
| 121 | smbiosInventoryPath(std::move(inventoryPath)) |
| 122 | { |
| 123 | lg2::info("SMBIOS data file path: {F}", "F", smbiosFilePath); |
| 124 | lg2::info("SMBIOS control object: {O}", "O", smbiosObjectPath); |
| 125 | lg2::info("SMBIOS inventory path: {I}", "I", smbiosInventoryPath); |
| 126 | |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 127 | smbiosDir.agentVersion = smbiosAgentVersion; |
Josh Lehan | f079e83 | 2023-09-19 15:52:52 -0700 | [diff] [blame] | 128 | smbiosDir.dirVersion = smbiosDirVersion; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 129 | smbiosDir.dirEntries = 1; |
| 130 | directoryEntries(smbiosDir.dirEntries); |
| 131 | smbiosDir.status = 1; |
| 132 | smbiosDir.remoteDirVersion = 0; |
| 133 | |
| 134 | std::copy(smbiosTableId.begin(), smbiosTableId.end(), |
| 135 | smbiosDir.dir[smbiosDirIndex].common.id.dataInfo); |
| 136 | |
| 137 | smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage; |
| 138 | |
| 139 | agentSynchronizeData(); |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 140 | |
| 141 | smbiosInterface->register_method("GetRecordType", [this](size_t type) { |
| 142 | return getRecordType(type); |
| 143 | }); |
| 144 | smbiosInterface->initialize(); |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 145 | } |
| 146 | |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 147 | std::vector<uint8_t> getDirectoryInformation(uint8_t dirIndex) override; |
| 148 | |
| 149 | std::vector<uint8_t> getDataInformation(uint8_t idIndex) override; |
| 150 | |
Patrick Williams | 1d73dcc | 2024-08-16 15:21:42 -0400 | [diff] [blame] | 151 | bool sendDirectoryInformation( |
| 152 | uint8_t dirVersion, uint8_t dirIndex, uint8_t returnedEntries, |
| 153 | uint8_t remainingEntries, std::vector<uint8_t> dirEntry) override; |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 154 | |
| 155 | std::vector<uint8_t> getDataOffer() override; |
| 156 | |
| 157 | bool sendDataInformation(uint8_t idIndex, uint8_t flag, uint32_t dataLen, |
| 158 | uint32_t dataVer, uint32_t timeStamp) override; |
| 159 | |
| 160 | int findIdIndex(std::vector<uint8_t> dataInfo) override; |
| 161 | |
| 162 | bool agentSynchronizeData() override; |
| 163 | |
Patrick Williams | 07a2c9a | 2025-02-01 08:23:10 -0500 | [diff] [blame] | 164 | std::vector<uint32_t> synchronizeDirectoryCommonData( |
| 165 | uint8_t idIndex, uint32_t size) override; |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 166 | |
| 167 | uint8_t directoryEntries(uint8_t value) override; |
| 168 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 169 | std::vector<boost::container::flat_map<std::string, RecordVariant>> |
| 170 | getRecordType(size_t type); |
| 171 | |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 172 | private: |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 173 | boost::asio::steady_timer timer; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 174 | |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 175 | std::shared_ptr<sdbusplus::asio::connection> bus; |
| 176 | std::shared_ptr<sdbusplus::asio::object_server> objServer; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 177 | |
| 178 | Mdr2DirStruct smbiosDir; |
| 179 | |
Cheng C Yang | ec63425 | 2019-12-19 00:42:36 +0800 | [diff] [blame] | 180 | bool readDataFromFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data); |
Arun P. Mohanan | 0435a48 | 2022-02-01 21:45:55 +0530 | [diff] [blame] | 181 | bool checkSMBIOSVersion(uint8_t* dataIn); |
Cheng C Yang | ec63425 | 2019-12-19 00:42:36 +0800 | [diff] [blame] | 182 | |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 183 | const std::array<uint8_t, 16> smbiosTableId{ |
| 184 | 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42}; |
Josh Lehan | c6d87a5 | 2024-02-08 19:01:29 -0800 | [diff] [blame] | 185 | uint8_t smbiosTableStorage[smbiosTableStorageSize] = {}; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 186 | |
| 187 | bool smbiosIsUpdating(uint8_t index); |
| 188 | bool smbiosIsAvailForUpdate(uint8_t index); |
| 189 | inline uint8_t smbiosValidFlag(uint8_t index); |
| 190 | void systemInfoUpdate(void); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 191 | |
Jonathan Doman | f2d8bb4 | 2023-07-26 10:13:34 -0700 | [diff] [blame] | 192 | std::optional<size_t> getTotalCpuSlot(void); |
| 193 | std::optional<size_t> getTotalDimmSlot(void); |
| 194 | std::optional<size_t> getTotalPcieSlot(void); |
Prithvi Pai | 5af42bb | 2025-02-11 17:59:07 +0530 | [diff] [blame] | 195 | std::optional<size_t> getTotalTpm(void); |
Prithvi Pai | 6f9e7a7 | 2025-03-14 13:05:02 +0530 | [diff] [blame] | 196 | std::optional<size_t> getTotalFirmwareInventory(void); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 197 | std::vector<std::unique_ptr<Cpu>> cpus; |
Cheng C Yang | 8c3fab6 | 2019-12-19 00:51:06 +0800 | [diff] [blame] | 198 | std::vector<std::unique_ptr<Dimm>> dimms; |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 199 | std::vector<std::unique_ptr<Pcie>> pcies; |
Prithvi Pai | 5af42bb | 2025-02-11 17:59:07 +0530 | [diff] [blame] | 200 | std::vector<std::unique_ptr<Tpm>> tpms; |
Prithvi Pai | 6f9e7a7 | 2025-03-14 13:05:02 +0530 | [diff] [blame] | 201 | std::vector<std::unique_ptr<FirmwareInventory>> firmwareCollection; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 202 | std::unique_ptr<System> system; |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 203 | std::shared_ptr<sdbusplus::asio::dbus_interface> smbiosInterface; |
Josh Lehan | 027277a | 2023-09-11 05:28:19 -0700 | [diff] [blame] | 204 | |
| 205 | std::string smbiosFilePath; |
| 206 | std::string smbiosObjectPath; |
| 207 | std::string smbiosInventoryPath; |
| 208 | std::unique_ptr<sdbusplus::bus::match_t> motherboardConfigMatch; |
Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | } // namespace smbios |
| 212 | } // namespace phosphor |