blob: a37df2c44b6ec2190eb478ad36efb9586ab228a9 [file] [log] [blame]
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -05001#pragma once
2
Dhruvaraj Subhashchandran5f5c94d2021-10-19 07:18:30 -05003#include "sbe_type.hpp"
4
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -05005#include <sdbusplus/server.hpp>
6
7#include <filesystem>
8#include <map>
9#include <string>
10#include <variant>
11namespace openpower::dump::util
12{
13
Dhruvaraj Subhashchandran5f5c94d2021-10-19 07:18:30 -050014constexpr auto SBE_DUMP_TIMEOUT = 4 * 60; // Timeout in seconds
15
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050016using DumpCreateParams =
17 std::map<std::string, std::variant<std::string, uint64_t>>;
18
19/** @struct DumpPtr
20 * @brief a structure holding the data pointer
21 * @details This is a RAII container for the dump data
22 * returned by the SBE
23 */
24struct DumpDataPtr
25{
26 public:
27 /** @brief Destructor for the object, free the allocated memory.
28 */
29 ~DumpDataPtr()
30 {
31 // The memory is allocated using malloc
32 free(dataPtr);
33 }
34 /** @brief Returns the pointer to the data
35 */
36 uint8_t** getPtr()
37 {
38 return &dataPtr;
39 }
40 /** @brief Returns the stored data
41 */
42 uint8_t* getData()
43 {
44 return dataPtr;
45 }
46
47 private:
48 /** The pointer to the data */
49 uint8_t* dataPtr = nullptr;
50};
51
52/**
53 * @brief Get DBUS service for input interface via mapper call
54 *
55 * @param[in] bus - DBUS Bus Object
56 * @param[in] intf - DBUS Interface
57 * @param[in] path - DBUS Object Path
58 *
59 * @return distinct dbus name for input interface/path
60 **/
Patrick Williams9ae780d2024-04-26 02:34:31 -050061std::string getService(sdbusplus::bus_t& bus, const std::string& intf,
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050062 const std::string& path);
63
64/**
65 * @brief Set the property value based on the inputs
66 *
67 * @param[in] interface - the interface the property is on
68 * @param[in] propertName - the name of the property
69 * @param[in] path - the D-Bus path
70 * @param[in] service - the D-Bus service
71 * @param[in] bus - the D-Bus object
72 * @param[in] value - the value to set the property to
73 */
74template <typename T>
75void setProperty(const std::string& interface, const std::string& propertyName,
Patrick Williams9ae780d2024-04-26 02:34:31 -050076 const std::string& path, sdbusplus::bus_t& bus, const T& value)
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050077{
78 constexpr auto PROPERTY_INTF = "org.freedesktop.DBus.Properties";
79
80 auto service = getService(bus, interface, path);
81 auto method = bus.new_method_call(service.c_str(), path.c_str(),
82 PROPERTY_INTF, "Set");
83 method.append(interface, propertyName, value);
84 auto reply = bus.call(method);
85}
86
Dhruvaraj Subhashchandran5f5c94d2021-10-19 07:18:30 -050087/**
88 * Request SBE dump from the dump manager
89 *
90 * Request SBE dump from the dump manager and register a monitor for observing
91 * the dump progress.
92 *
93 * @param failingUnit The id of the proc containing failed SBE
94 * @param eid Error log id associated with dump
95 * @param sbeType Type of the SBE
96 */
97void requestSBEDump(const uint32_t failingUnit, const uint32_t eid,
98 SBETypes sbeType);
99
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -0500100} // namespace openpower::dump::util