blob: 9ca8926259a6c96a344cd184976776196ff5df11 [file] [log] [blame]
George Liu682ee182020-12-25 15:24:33 +08001#pragma once
2
Archana Kakanib40f4f82024-06-06 01:04:38 -05003#include "cable.hpp"
Archana Kakanidb65c3b2025-02-03 05:27:28 -06004#include "chassis.hpp"
George Liu682ee182020-12-25 15:24:33 +08005#include "common/utils.hpp"
Kamalkumar Patel56da5742024-05-23 04:53:07 -05006#include "cpu_core.hpp"
Archana Kakani413f51e2025-02-03 04:14:36 -06007#include "fan.hpp"
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -05008#include "motherboard.hpp"
Archana Kakani733b39d2024-06-05 21:05:20 -05009#include "pcie_device.hpp"
Archana Kakanibf1fd272024-06-05 13:25:53 -050010#include "pcie_slot.hpp"
George Liu682ee182020-12-25 15:24:33 +080011
12#include <sdbusplus/server.hpp>
13#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
14
15#include <memory>
16#include <optional>
17#include <string>
18#include <unordered_map>
19
20namespace pldm
21{
22namespace dbus
23{
24using ObjectPath = std::string;
25
Patrick Williams705fa982023-09-27 02:32:20 -050026using LocationIntf =
27 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
28 Decorator::server::LocationCode>;
George Liu682ee182020-12-25 15:24:33 +080029
30/** @class CustomDBus
31 * @brief This is a custom D-Bus object, used to add D-Bus interface and update
32 * the corresponding properties value.
33 */
34class CustomDBus
35{
36 private:
37 CustomDBus() {}
38
39 public:
40 CustomDBus(const CustomDBus&) = delete;
41 CustomDBus(CustomDBus&&) = delete;
42 CustomDBus& operator=(const CustomDBus&) = delete;
43 CustomDBus& operator=(CustomDBus&&) = delete;
44 ~CustomDBus() = default;
45
46 static CustomDBus& getCustomDBus()
47 {
48 static CustomDBus customDBus;
49 return customDBus;
50 }
51
52 public:
53 /** @brief Set the LocationCode property
54 *
55 * @param[in] path - The object path
56 *
57 * @param[in] value - The value of the LocationCode property
58 */
59 void setLocationCode(const std::string& path, std::string value);
60
61 /** @brief Get the LocationCode property
62 *
Kamalkumar Patel56da5742024-05-23 04:53:07 -050063 * @param[in] path - The object path
George Liu682ee182020-12-25 15:24:33 +080064 *
65 * @return std::optional<std::string> - The value of the LocationCode
66 * property
67 */
68 std::optional<std::string> getLocationCode(const std::string& path) const;
Kamalkumar Patel56da5742024-05-23 04:53:07 -050069 /** @brief Implement CpuCore Interface
70 *
71 * @param[in] path - The object path
72 *
73 */
74 void implementCpuCoreInterface(const std::string& path);
75 /** @brief Set the microcode property
76 *
77 * @param[in] path - The object path
78 *
79 * @param[in] value - microcode value
80 */
81 void setMicroCode(const std::string& path, uint32_t value);
82
83 /** @brief Get the microcode property
84 *
85 * @param[in] path - The object path
86 *
87 * @return std::optional<uint32_t> - The value of the microcode value
88 */
89 std::optional<uint32_t> getMicroCode(const std::string& path) const;
George Liu682ee182020-12-25 15:24:33 +080090
Archana Kakanibf1fd272024-06-05 13:25:53 -050091 /** @brief Implement PCIeSlot Interface
92 *
93 * @param[in] path - the object path
94 */
95 void implementPCIeSlotInterface(const std::string& path);
96
97 /** @brief Set the slot type
98 *
99 * @param[in] path - the object path
100 * @param[in] slot type - Slot type
101 */
102 void setSlotType(const std::string& path, const std::string& slotType);
103
Archana Kakani733b39d2024-06-05 21:05:20 -0500104 /** @brief Implement PCIe Device Interface
105 *
106 * @param[in] path - the object path
107 */
108 void implementPCIeDeviceInterface(const std::string& path);
109
110 /** @brief Set PCIe Device Lanes in use property
111 *
112 * @param[in] path - the object path
113 * @param[in] lanesInUse - Lanes in use
114 * @param[in] value - Generation in use
115 */
116 void setPCIeDeviceProps(const std::string& path, size_t lanesInUse,
117 const std::string& value);
118
Archana Kakanib40f4f82024-06-06 01:04:38 -0500119 /** @brief Implement PCIe Cable Interface
120 *
121 * @param[in] path - the object path
122 */
123 void implementCableInterface(const std::string& path);
124
125 /** @brief set cable attributes
126 *
127 * @param[in] path - the object path
128 * @param[in] length - length of the wire
129 * @param[in] cableDescription - cable details
130 */
131 void setCableAttributes(const std::string& path, double length,
132 const std::string& cableDescription);
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500133 /** @brief Implement interface for motherboard property
134 *
135 * @param[in] path - The object path
136 *
137 */
138 void implementMotherboardInterface(const std::string& path);
Archana Kakanib40f4f82024-06-06 01:04:38 -0500139
Archana Kakani413f51e2025-02-03 04:14:36 -0600140 /** @brief Implement Fan Interface
141 *
142 * @param[in] path - The object path
143 *
144 */
145 void implementFanInterface(const std::string& path);
146
Archana Kakanidb65c3b2025-02-03 05:27:28 -0600147 /** @brief Implement Chassis Interface
148 * @param[in] path - the object path
149 */
150 void implementChassisInterface(const std::string& path);
151
George Liu682ee182020-12-25 15:24:33 +0800152 private:
153 std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
Kamalkumar Patel56da5742024-05-23 04:53:07 -0500154 std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
Archana Kakanidb65c3b2025-02-03 05:27:28 -0600155 std::unordered_map<ObjectPath, std::unique_ptr<ItemChassis>> chassis;
Archana Kakani733b39d2024-06-05 21:05:20 -0500156 std::unordered_map<ObjectPath, std::unique_ptr<PCIeDevice>> pcieDevice;
Archana Kakanibf1fd272024-06-05 13:25:53 -0500157 std::unordered_map<ObjectPath, std::unique_ptr<PCIeSlot>> pcieSlot;
Archana Kakanib40f4f82024-06-06 01:04:38 -0500158 std::unordered_map<ObjectPath, std::unique_ptr<Cable>> cable;
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500159 std::unordered_map<ObjectPath, std::unique_ptr<Motherboard>> motherboard;
Archana Kakani413f51e2025-02-03 04:14:36 -0600160 std::unordered_map<ObjectPath, std::unique_ptr<Fan>> fan;
George Liu682ee182020-12-25 15:24:33 +0800161};
162
163} // namespace dbus
164} // namespace pldm