Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 1 | // Copyright 2022 Google LLC |
Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 15 | #pragma once |
| 16 | |
| 17 | #include "handler.hpp" |
| 18 | |
| 19 | #include <cstdint> |
| 20 | #include <map> |
| 21 | #include <nlohmann/json.hpp> |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 22 | #include <sdbusplus/bus.hpp> |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 23 | #include <string> |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 24 | #include <string_view> |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 25 | #include <tuple> |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace google |
| 29 | { |
| 30 | namespace ipmi |
| 31 | { |
| 32 | |
William A. Kennington III | 96ad906 | 2020-11-24 21:47:20 -0800 | [diff] [blame] | 33 | constexpr char defaultConfigFile[] = |
| 34 | "/usr/share/ipmi-entity-association/entity_association_map.json"; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 35 | |
| 36 | class Handler : public HandlerInterface |
| 37 | { |
| 38 | public: |
| 39 | explicit Handler(const std::string& entityConfigPath = defaultConfigFile) : |
| 40 | _configFile(entityConfigPath){}; |
| 41 | ~Handler() = default; |
| 42 | |
William A. Kennington III | b69209b | 2021-07-13 13:22:24 -0700 | [diff] [blame] | 43 | std::tuple<std::uint8_t, std::string> |
| 44 | getEthDetails(std::string intf) const override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 45 | std::int64_t getRxPackets(const std::string& name) const override; |
| 46 | VersionTuple getCpldVersion(unsigned int id) const override; |
| 47 | void psuResetDelay(std::uint32_t delay) const override; |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 48 | void psuResetOnShutdown() const override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 49 | std::string getEntityName(std::uint8_t id, std::uint8_t instance) override; |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 50 | uint32_t getFlashSize() override; |
William A. Kennington III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 51 | std::string getMachineName() override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 52 | void buildI2cPcieMapping() override; |
| 53 | size_t getI2cPcieMappingSize() const override; |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 54 | void hostPowerOffDelay(std::uint32_t delay) const override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 55 | std::tuple<std::uint32_t, std::string> |
| 56 | getI2cEntry(unsigned int entry) const override; |
| 57 | |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 58 | uint32_t accelOobDeviceCount() const override; |
| 59 | std::string accelOobDeviceName(size_t index) const override; |
| 60 | uint64_t accelOobRead(std::string_view name, uint64_t address, |
| 61 | uint8_t num_bytes) const override; |
| 62 | void accelOobWrite(std::string_view name, uint64_t address, |
| 63 | uint8_t num_bytes, uint64_t data) const override; |
| 64 | |
| 65 | protected: |
| 66 | // Exposed for dependency injection |
| 67 | virtual sdbusplus::bus::bus accelOobGetDbus() const; |
| 68 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 69 | private: |
| 70 | std::string _configFile; |
| 71 | |
| 72 | bool _entityConfigParsed = false; |
| 73 | |
| 74 | const std::map<uint8_t, std::string> _entityIdToName{ |
| 75 | {0x03, "cpu"}, |
| 76 | {0x04, "storage_device"}, |
| 77 | {0x06, "system_management_module"}, |
| 78 | {0x07, "system_board"}, |
| 79 | {0x08, "memory_module"}, |
| 80 | {0x0B, "add_in_card"}, |
| 81 | {0x0E, "power_system_board"}, |
| 82 | {0x10, "system_internal_expansion_board"}, |
| 83 | {0x11, "other_system_board"}, |
| 84 | {0x17, "system_chassis"}, |
| 85 | {0x1D, "fan"}, |
| 86 | {0x1E, "cooling_unit"}, |
| 87 | {0x20, "memory_device"}}; |
| 88 | |
| 89 | nlohmann::json _entityConfig{}; |
| 90 | |
| 91 | std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map; |
| 92 | }; |
| 93 | |
Patrick Venture | a3f9c2d | 2020-05-29 14:36:25 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Given a type, entity instance, and a configuration, return the name. |
| 96 | * |
| 97 | * @param[in] type - the entity type |
| 98 | * @param[in] instance - the entity instance |
| 99 | * @param[in] config - the json object holding the entity mapping |
| 100 | * @return the name of the entity from the map |
| 101 | */ |
| 102 | std::string readNameFromConfig(const std::string& type, uint8_t instance, |
| 103 | const nlohmann::json& config); |
| 104 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 105 | } // namespace ipmi |
| 106 | } // namespace google |