blob: 02807a1d71968c66d54ae12f0d122957485d5b49 [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"
George Liu682ee182020-12-25 15:24:33 +08004#include "common/utils.hpp"
Kamalkumar Patel56da5742024-05-23 04:53:07 -05005#include "cpu_core.hpp"
Archana Kakani413f51e2025-02-03 04:14:36 -06006#include "fan.hpp"
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -05007#include "motherboard.hpp"
Archana Kakani733b39d2024-06-05 21:05:20 -05008#include "pcie_device.hpp"
Archana Kakanibf1fd272024-06-05 13:25:53 -05009#include "pcie_slot.hpp"
George Liu682ee182020-12-25 15:24:33 +080010
11#include <sdbusplus/server.hpp>
12#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
13
14#include <memory>
15#include <optional>
16#include <string>
17#include <unordered_map>
18
19namespace pldm
20{
21namespace dbus
22{
23using ObjectPath = std::string;
24
Patrick Williams705fa982023-09-27 02:32:20 -050025using LocationIntf =
26 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
27 Decorator::server::LocationCode>;
George Liu682ee182020-12-25 15:24:33 +080028
29/** @class CustomDBus
30 * @brief This is a custom D-Bus object, used to add D-Bus interface and update
31 * the corresponding properties value.
32 */
33class CustomDBus
34{
35 private:
36 CustomDBus() {}
37
38 public:
39 CustomDBus(const CustomDBus&) = delete;
40 CustomDBus(CustomDBus&&) = delete;
41 CustomDBus& operator=(const CustomDBus&) = delete;
42 CustomDBus& operator=(CustomDBus&&) = delete;
43 ~CustomDBus() = default;
44
45 static CustomDBus& getCustomDBus()
46 {
47 static CustomDBus customDBus;
48 return customDBus;
49 }
50
51 public:
52 /** @brief Set the LocationCode property
53 *
54 * @param[in] path - The object path
55 *
56 * @param[in] value - The value of the LocationCode property
57 */
58 void setLocationCode(const std::string& path, std::string value);
59
60 /** @brief Get the LocationCode property
61 *
Kamalkumar Patel56da5742024-05-23 04:53:07 -050062 * @param[in] path - The object path
George Liu682ee182020-12-25 15:24:33 +080063 *
64 * @return std::optional<std::string> - The value of the LocationCode
65 * property
66 */
67 std::optional<std::string> getLocationCode(const std::string& path) const;
Kamalkumar Patel56da5742024-05-23 04:53:07 -050068 /** @brief Implement CpuCore Interface
69 *
70 * @param[in] path - The object path
71 *
72 */
73 void implementCpuCoreInterface(const std::string& path);
74 /** @brief Set the microcode property
75 *
76 * @param[in] path - The object path
77 *
78 * @param[in] value - microcode value
79 */
80 void setMicroCode(const std::string& path, uint32_t value);
81
82 /** @brief Get the microcode property
83 *
84 * @param[in] path - The object path
85 *
86 * @return std::optional<uint32_t> - The value of the microcode value
87 */
88 std::optional<uint32_t> getMicroCode(const std::string& path) const;
George Liu682ee182020-12-25 15:24:33 +080089
Archana Kakanibf1fd272024-06-05 13:25:53 -050090 /** @brief Implement PCIeSlot Interface
91 *
92 * @param[in] path - the object path
93 */
94 void implementPCIeSlotInterface(const std::string& path);
95
96 /** @brief Set the slot type
97 *
98 * @param[in] path - the object path
99 * @param[in] slot type - Slot type
100 */
101 void setSlotType(const std::string& path, const std::string& slotType);
102
Archana Kakani733b39d2024-06-05 21:05:20 -0500103 /** @brief Implement PCIe Device Interface
104 *
105 * @param[in] path - the object path
106 */
107 void implementPCIeDeviceInterface(const std::string& path);
108
109 /** @brief Set PCIe Device Lanes in use property
110 *
111 * @param[in] path - the object path
112 * @param[in] lanesInUse - Lanes in use
113 * @param[in] value - Generation in use
114 */
115 void setPCIeDeviceProps(const std::string& path, size_t lanesInUse,
116 const std::string& value);
117
Archana Kakanib40f4f82024-06-06 01:04:38 -0500118 /** @brief Implement PCIe Cable Interface
119 *
120 * @param[in] path - the object path
121 */
122 void implementCableInterface(const std::string& path);
123
124 /** @brief set cable attributes
125 *
126 * @param[in] path - the object path
127 * @param[in] length - length of the wire
128 * @param[in] cableDescription - cable details
129 */
130 void setCableAttributes(const std::string& path, double length,
131 const std::string& cableDescription);
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500132 /** @brief Implement interface for motherboard property
133 *
134 * @param[in] path - The object path
135 *
136 */
137 void implementMotherboardInterface(const std::string& path);
Archana Kakanib40f4f82024-06-06 01:04:38 -0500138
Archana Kakani413f51e2025-02-03 04:14:36 -0600139 /** @brief Implement Fan Interface
140 *
141 * @param[in] path - The object path
142 *
143 */
144 void implementFanInterface(const std::string& path);
145
George Liu682ee182020-12-25 15:24:33 +0800146 private:
147 std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
Kamalkumar Patel56da5742024-05-23 04:53:07 -0500148 std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
Archana Kakani733b39d2024-06-05 21:05:20 -0500149 std::unordered_map<ObjectPath, std::unique_ptr<PCIeDevice>> pcieDevice;
Archana Kakanibf1fd272024-06-05 13:25:53 -0500150 std::unordered_map<ObjectPath, std::unique_ptr<PCIeSlot>> pcieSlot;
Archana Kakanib40f4f82024-06-06 01:04:38 -0500151 std::unordered_map<ObjectPath, std::unique_ptr<Cable>> cable;
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500152 std::unordered_map<ObjectPath, std::unique_ptr<Motherboard>> motherboard;
Archana Kakani413f51e2025-02-03 04:14:36 -0600153 std::unordered_map<ObjectPath, std::unique_ptr<Fan>> fan;
George Liu682ee182020-12-25 15:24:33 +0800154};
155
156} // namespace dbus
157} // namespace pldm