14f0d1de6SSteve Foreman // Copyright 2022 Google LLC 2a2056e9cSWilly Tu // 3a2056e9cSWilly Tu // Licensed under the Apache License, Version 2.0 (the "License"); 4a2056e9cSWilly Tu // you may not use this file except in compliance with the License. 5a2056e9cSWilly Tu // You may obtain a copy of the License at 6a2056e9cSWilly Tu // 7a2056e9cSWilly Tu // http://www.apache.org/licenses/LICENSE-2.0 8a2056e9cSWilly Tu // 9a2056e9cSWilly Tu // Unless required by applicable law or agreed to in writing, software 10a2056e9cSWilly Tu // distributed under the License is distributed on an "AS IS" BASIS, 11a2056e9cSWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a2056e9cSWilly Tu // See the License for the specific language governing permissions and 13a2056e9cSWilly Tu // limitations under the License. 14a2056e9cSWilly Tu 15c87de558SPatrick Venture #pragma once 16c87de558SPatrick Venture 176c71b0f9SWilly Tu #include "bifurcation.hpp" 18c87de558SPatrick Venture #include "handler.hpp" 19c87de558SPatrick Venture 20c87de558SPatrick Venture #include <cstdint> 21c87de558SPatrick Venture #include <map> 22c87de558SPatrick Venture #include <nlohmann/json.hpp> 234f0d1de6SSteve Foreman #include <sdbusplus/bus.hpp> 24c87de558SPatrick Venture #include <string> 254f0d1de6SSteve Foreman #include <string_view> 26c87de558SPatrick Venture #include <tuple> 27c87de558SPatrick Venture #include <vector> 28c87de558SPatrick Venture 29c87de558SPatrick Venture namespace google 30c87de558SPatrick Venture { 31c87de558SPatrick Venture namespace ipmi 32c87de558SPatrick Venture { 33c87de558SPatrick Venture 3496ad9069SWilliam A. Kennington III constexpr char defaultConfigFile[] = 3596ad9069SWilliam A. Kennington III "/usr/share/ipmi-entity-association/entity_association_map.json"; 36c87de558SPatrick Venture 37c87de558SPatrick Venture class Handler : public HandlerInterface 38c87de558SPatrick Venture { 39c87de558SPatrick Venture public: 40c87de558SPatrick Venture explicit Handler(const std::string& entityConfigPath = defaultConfigFile) : 416c71b0f9SWilly Tu _configFile(entityConfigPath), 426c71b0f9SWilly Tu bifurcationHelper(BifurcationStatic::createBifurcation()){}; 436c71b0f9SWilly Tu Handler(std::reference_wrapper<BifurcationInterface> bifurcationHelper, 446c71b0f9SWilly Tu const std::string& entityConfigPath = defaultConfigFile) : 456c71b0f9SWilly Tu _configFile(entityConfigPath), 466c71b0f9SWilly Tu bifurcationHelper(bifurcationHelper){}; 47c87de558SPatrick Venture ~Handler() = default; 48c87de558SPatrick Venture 495e70dc8cSNikhil Namjoshi uint8_t getBmcMode() override; 50b69209b4SWilliam A. Kennington III std::tuple<std::uint8_t, std::string> 51b69209b4SWilliam A. Kennington III getEthDetails(std::string intf) const override; 52c87de558SPatrick Venture std::int64_t getRxPackets(const std::string& name) const override; 53c87de558SPatrick Venture VersionTuple getCpldVersion(unsigned int id) const override; 54c87de558SPatrick Venture void psuResetDelay(std::uint32_t delay) const override; 55ac4a16f7SShounak Mitra void psuResetOnShutdown() const override; 56c87de558SPatrick Venture std::string getEntityName(std::uint8_t id, std::uint8_t instance) override; 573b1b427cSWilly Tu uint32_t getFlashSize() override; 5829f35bceSWilliam A. Kennington III std::string getMachineName() override; 59c87de558SPatrick Venture void buildI2cPcieMapping() override; 60c87de558SPatrick Venture size_t getI2cPcieMappingSize() const override; 618cfa4c44Slinyuny void hostPowerOffDelay(std::uint32_t delay) const override; 62c87de558SPatrick Venture std::tuple<std::uint32_t, std::string> 63c87de558SPatrick Venture getI2cEntry(unsigned int entry) const override; 646c71b0f9SWilly Tu std::vector<uint8_t> pcieBifurcation(uint8_t) override; 65c87de558SPatrick Venture 664f0d1de6SSteve Foreman uint32_t accelOobDeviceCount() const override; 674f0d1de6SSteve Foreman std::string accelOobDeviceName(size_t index) const override; 684f0d1de6SSteve Foreman uint64_t accelOobRead(std::string_view name, uint64_t address, 694f0d1de6SSteve Foreman uint8_t num_bytes) const override; 704f0d1de6SSteve Foreman void accelOobWrite(std::string_view name, uint64_t address, 714f0d1de6SSteve Foreman uint8_t num_bytes, uint64_t data) const override; 724f0d1de6SSteve Foreman 734f0d1de6SSteve Foreman protected: 744f0d1de6SSteve Foreman // Exposed for dependency injection 75*65371228SPatrick Williams virtual sdbusplus::bus_t getDbus() const; 764f0d1de6SSteve Foreman 77c87de558SPatrick Venture private: 78c87de558SPatrick Venture std::string _configFile; 79c87de558SPatrick Venture 80c87de558SPatrick Venture bool _entityConfigParsed = false; 81c87de558SPatrick Venture 82c87de558SPatrick Venture const std::map<uint8_t, std::string> _entityIdToName{ 83c87de558SPatrick Venture {0x03, "cpu"}, 84c87de558SPatrick Venture {0x04, "storage_device"}, 85c87de558SPatrick Venture {0x06, "system_management_module"}, 86c87de558SPatrick Venture {0x07, "system_board"}, 87c87de558SPatrick Venture {0x08, "memory_module"}, 88c87de558SPatrick Venture {0x0B, "add_in_card"}, 89c87de558SPatrick Venture {0x0E, "power_system_board"}, 90c87de558SPatrick Venture {0x10, "system_internal_expansion_board"}, 91c87de558SPatrick Venture {0x11, "other_system_board"}, 92c87de558SPatrick Venture {0x17, "system_chassis"}, 93c87de558SPatrick Venture {0x1D, "fan"}, 94c87de558SPatrick Venture {0x1E, "cooling_unit"}, 95c87de558SPatrick Venture {0x20, "memory_device"}}; 96c87de558SPatrick Venture 97c87de558SPatrick Venture nlohmann::json _entityConfig{}; 98c87de558SPatrick Venture 99c87de558SPatrick Venture std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map; 1006c71b0f9SWilly Tu 1016c71b0f9SWilly Tu std::reference_wrapper<BifurcationInterface> bifurcationHelper; 102c87de558SPatrick Venture }; 103c87de558SPatrick Venture 104a3f9c2d3SPatrick Venture /** 105a3f9c2d3SPatrick Venture * Given a type, entity instance, and a configuration, return the name. 106a3f9c2d3SPatrick Venture * 107a3f9c2d3SPatrick Venture * @param[in] type - the entity type 108a3f9c2d3SPatrick Venture * @param[in] instance - the entity instance 109a3f9c2d3SPatrick Venture * @param[in] config - the json object holding the entity mapping 110a3f9c2d3SPatrick Venture * @return the name of the entity from the map 111a3f9c2d3SPatrick Venture */ 112a3f9c2d3SPatrick Venture std::string readNameFromConfig(const std::string& type, uint8_t instance, 113a3f9c2d3SPatrick Venture const nlohmann::json& config); 114a3f9c2d3SPatrick Venture 115c87de558SPatrick Venture } // namespace ipmi 116c87de558SPatrick Venture } // namespace google 117