blob: 9baa1dcf8a38fa75ebd8a93921ef08d3ba3b27b7 [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"
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -05006#include "motherboard.hpp"
Archana Kakani733b39d2024-06-05 21:05:20 -05007#include "pcie_device.hpp"
Archana Kakanibf1fd272024-06-05 13:25:53 -05008#include "pcie_slot.hpp"
George Liu682ee182020-12-25 15:24:33 +08009
10#include <sdbusplus/server.hpp>
11#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
12
13#include <memory>
14#include <optional>
15#include <string>
16#include <unordered_map>
17
18namespace pldm
19{
20namespace dbus
21{
22using ObjectPath = std::string;
23
Patrick Williams705fa982023-09-27 02:32:20 -050024using LocationIntf =
25 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
26 Decorator::server::LocationCode>;
George Liu682ee182020-12-25 15:24:33 +080027
28/** @class CustomDBus
29 * @brief This is a custom D-Bus object, used to add D-Bus interface and update
30 * the corresponding properties value.
31 */
32class CustomDBus
33{
34 private:
35 CustomDBus() {}
36
37 public:
38 CustomDBus(const CustomDBus&) = delete;
39 CustomDBus(CustomDBus&&) = delete;
40 CustomDBus& operator=(const CustomDBus&) = delete;
41 CustomDBus& operator=(CustomDBus&&) = delete;
42 ~CustomDBus() = default;
43
44 static CustomDBus& getCustomDBus()
45 {
46 static CustomDBus customDBus;
47 return customDBus;
48 }
49
50 public:
51 /** @brief Set the LocationCode property
52 *
53 * @param[in] path - The object path
54 *
55 * @param[in] value - The value of the LocationCode property
56 */
57 void setLocationCode(const std::string& path, std::string value);
58
59 /** @brief Get the LocationCode property
60 *
Kamalkumar Patel56da5742024-05-23 04:53:07 -050061 * @param[in] path - The object path
George Liu682ee182020-12-25 15:24:33 +080062 *
63 * @return std::optional<std::string> - The value of the LocationCode
64 * property
65 */
66 std::optional<std::string> getLocationCode(const std::string& path) const;
Kamalkumar Patel56da5742024-05-23 04:53:07 -050067 /** @brief Implement CpuCore Interface
68 *
69 * @param[in] path - The object path
70 *
71 */
72 void implementCpuCoreInterface(const std::string& path);
73 /** @brief Set the microcode property
74 *
75 * @param[in] path - The object path
76 *
77 * @param[in] value - microcode value
78 */
79 void setMicroCode(const std::string& path, uint32_t value);
80
81 /** @brief Get the microcode property
82 *
83 * @param[in] path - The object path
84 *
85 * @return std::optional<uint32_t> - The value of the microcode value
86 */
87 std::optional<uint32_t> getMicroCode(const std::string& path) const;
George Liu682ee182020-12-25 15:24:33 +080088
Archana Kakanibf1fd272024-06-05 13:25:53 -050089 /** @brief Implement PCIeSlot Interface
90 *
91 * @param[in] path - the object path
92 */
93 void implementPCIeSlotInterface(const std::string& path);
94
95 /** @brief Set the slot type
96 *
97 * @param[in] path - the object path
98 * @param[in] slot type - Slot type
99 */
100 void setSlotType(const std::string& path, const std::string& slotType);
101
Archana Kakani733b39d2024-06-05 21:05:20 -0500102 /** @brief Implement PCIe Device Interface
103 *
104 * @param[in] path - the object path
105 */
106 void implementPCIeDeviceInterface(const std::string& path);
107
108 /** @brief Set PCIe Device Lanes in use property
109 *
110 * @param[in] path - the object path
111 * @param[in] lanesInUse - Lanes in use
112 * @param[in] value - Generation in use
113 */
114 void setPCIeDeviceProps(const std::string& path, size_t lanesInUse,
115 const std::string& value);
116
Archana Kakanib40f4f82024-06-06 01:04:38 -0500117 /** @brief Implement PCIe Cable Interface
118 *
119 * @param[in] path - the object path
120 */
121 void implementCableInterface(const std::string& path);
122
123 /** @brief set cable attributes
124 *
125 * @param[in] path - the object path
126 * @param[in] length - length of the wire
127 * @param[in] cableDescription - cable details
128 */
129 void setCableAttributes(const std::string& path, double length,
130 const std::string& cableDescription);
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500131 /** @brief Implement interface for motherboard property
132 *
133 * @param[in] path - The object path
134 *
135 */
136 void implementMotherboardInterface(const std::string& path);
Archana Kakanib40f4f82024-06-06 01:04:38 -0500137
George Liu682ee182020-12-25 15:24:33 +0800138 private:
139 std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
Kamalkumar Patel56da5742024-05-23 04:53:07 -0500140 std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
Archana Kakani733b39d2024-06-05 21:05:20 -0500141 std::unordered_map<ObjectPath, std::unique_ptr<PCIeDevice>> pcieDevice;
Archana Kakanibf1fd272024-06-05 13:25:53 -0500142 std::unordered_map<ObjectPath, std::unique_ptr<PCIeSlot>> pcieSlot;
Archana Kakanib40f4f82024-06-06 01:04:38 -0500143 std::unordered_map<ObjectPath, std::unique_ptr<Cable>> cable;
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500144 std::unordered_map<ObjectPath, std::unique_ptr<Motherboard>> motherboard;
George Liu682ee182020-12-25 15:24:33 +0800145};
146
147} // namespace dbus
148} // namespace pldm