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 <nlohmann/json.hpp> 214f0d1de6SSteve Foreman #include <sdbusplus/bus.hpp> 22444b5ea4SPatrick Williams 23444b5ea4SPatrick Williams #include <cstdint> 24444b5ea4SPatrick Williams #include <map> 25c87de558SPatrick Venture #include <string> 264f0d1de6SSteve Foreman #include <string_view> 27c87de558SPatrick Venture #include <tuple> 28c87de558SPatrick Venture #include <vector> 29c87de558SPatrick Venture 30c87de558SPatrick Venture namespace google 31c87de558SPatrick Venture { 32c87de558SPatrick Venture namespace ipmi 33c87de558SPatrick Venture { 34c87de558SPatrick Venture 3596ad9069SWilliam A. Kennington III constexpr char defaultConfigFile[] = 3696ad9069SWilliam A. Kennington III "/usr/share/ipmi-entity-association/entity_association_map.json"; 37c87de558SPatrick Venture 38c87de558SPatrick Venture class Handler : public HandlerInterface 39c87de558SPatrick Venture { 40c87de558SPatrick Venture public: 41c87de558SPatrick Venture explicit Handler(const std::string& entityConfigPath = defaultConfigFile) : 426c71b0f9SWilly Tu _configFile(entityConfigPath), 436c71b0f9SWilly Tu bifurcationHelper(BifurcationStatic::createBifurcation()){}; 446c71b0f9SWilly Tu Handler(std::reference_wrapper<BifurcationInterface> bifurcationHelper, 456c71b0f9SWilly Tu const std::string& entityConfigPath = defaultConfigFile) : 466c71b0f9SWilly Tu _configFile(entityConfigPath), 476c71b0f9SWilly Tu bifurcationHelper(bifurcationHelper){}; 48c87de558SPatrick Venture ~Handler() = default; 49c87de558SPatrick Venture 505e70dc8cSNikhil Namjoshi uint8_t getBmcMode() override; 51b69209b4SWilliam A. Kennington III std::tuple<std::uint8_t, std::string> 52b69209b4SWilliam A. Kennington III getEthDetails(std::string intf) const override; 53c87de558SPatrick Venture std::int64_t getRxPackets(const std::string& name) const override; 54c87de558SPatrick Venture VersionTuple getCpldVersion(unsigned int id) const override; 55c87de558SPatrick Venture void psuResetDelay(std::uint32_t delay) const override; 56ac4a16f7SShounak Mitra void psuResetOnShutdown() const override; 57c87de558SPatrick Venture std::string getEntityName(std::uint8_t id, std::uint8_t instance) override; 583b1b427cSWilly Tu uint32_t getFlashSize() override; 5929f35bceSWilliam A. Kennington III std::string getMachineName() override; 60c87de558SPatrick Venture void buildI2cPcieMapping() override; 61c87de558SPatrick Venture size_t getI2cPcieMappingSize() const override; 628cfa4c44Slinyuny void hostPowerOffDelay(std::uint32_t delay) const override; 63c87de558SPatrick Venture std::tuple<std::uint32_t, std::string> 64c87de558SPatrick Venture getI2cEntry(unsigned int entry) const override; 656c71b0f9SWilly Tu std::vector<uint8_t> pcieBifurcation(uint8_t) override; 66c87de558SPatrick Venture 674f0d1de6SSteve Foreman uint32_t accelOobDeviceCount() const override; 684f0d1de6SSteve Foreman std::string accelOobDeviceName(size_t index) const override; 694f0d1de6SSteve Foreman uint64_t accelOobRead(std::string_view name, uint64_t address, 704f0d1de6SSteve Foreman uint8_t num_bytes) const override; 714f0d1de6SSteve Foreman void accelOobWrite(std::string_view name, uint64_t address, 724f0d1de6SSteve Foreman uint8_t num_bytes, uint64_t data) const override; 73*a92d0e6bSJohn Wedig void linuxBootDone() const override; 744f0d1de6SSteve Foreman 754f0d1de6SSteve Foreman protected: 764f0d1de6SSteve Foreman // Exposed for dependency injection 7765371228SPatrick Williams virtual sdbusplus::bus_t getDbus() const; 784f0d1de6SSteve Foreman 79c87de558SPatrick Venture private: 80c87de558SPatrick Venture std::string _configFile; 81c87de558SPatrick Venture 82c87de558SPatrick Venture bool _entityConfigParsed = false; 83c87de558SPatrick Venture 84c87de558SPatrick Venture const std::map<uint8_t, std::string> _entityIdToName{ 85c87de558SPatrick Venture {0x03, "cpu"}, 86c87de558SPatrick Venture {0x04, "storage_device"}, 87c87de558SPatrick Venture {0x06, "system_management_module"}, 88c87de558SPatrick Venture {0x07, "system_board"}, 89c87de558SPatrick Venture {0x08, "memory_module"}, 90c87de558SPatrick Venture {0x0B, "add_in_card"}, 91c87de558SPatrick Venture {0x0E, "power_system_board"}, 92c87de558SPatrick Venture {0x10, "system_internal_expansion_board"}, 93c87de558SPatrick Venture {0x11, "other_system_board"}, 94c87de558SPatrick Venture {0x17, "system_chassis"}, 95c87de558SPatrick Venture {0x1D, "fan"}, 96c87de558SPatrick Venture {0x1E, "cooling_unit"}, 97c87de558SPatrick Venture {0x20, "memory_device"}}; 98c87de558SPatrick Venture 99c87de558SPatrick Venture nlohmann::json _entityConfig{}; 100c87de558SPatrick Venture 101c87de558SPatrick Venture std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map; 1026c71b0f9SWilly Tu 1036c71b0f9SWilly Tu std::reference_wrapper<BifurcationInterface> bifurcationHelper; 104c87de558SPatrick Venture }; 105c87de558SPatrick Venture 106a3f9c2d3SPatrick Venture /** 107a3f9c2d3SPatrick Venture * Given a type, entity instance, and a configuration, return the name. 108a3f9c2d3SPatrick Venture * 109a3f9c2d3SPatrick Venture * @param[in] type - the entity type 110a3f9c2d3SPatrick Venture * @param[in] instance - the entity instance 111a3f9c2d3SPatrick Venture * @param[in] config - the json object holding the entity mapping 112a3f9c2d3SPatrick Venture * @return the name of the entity from the map 113a3f9c2d3SPatrick Venture */ 114a3f9c2d3SPatrick Venture std::string readNameFromConfig(const std::string& type, uint8_t instance, 115a3f9c2d3SPatrick Venture const nlohmann::json& config); 116a3f9c2d3SPatrick Venture 117c87de558SPatrick Venture } // namespace ipmi 118c87de558SPatrick Venture } // namespace google 119