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