blob: 105884ac005b9ab359bd8b00482be5544c7a0b4b [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 **/
61std::string getService(sdbusplus::bus::bus& bus, const std::string& intf,
62 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,
76 const std::string& path, sdbusplus::bus::bus& bus,
77 const T& value)
78{
79 constexpr auto PROPERTY_INTF = "org.freedesktop.DBus.Properties";
80
81 auto service = getService(bus, interface, path);
82 auto method = bus.new_method_call(service.c_str(), path.c_str(),
83 PROPERTY_INTF, "Set");
84 method.append(interface, propertyName, value);
85 auto reply = bus.call(method);
86}
87
Dhruvaraj Subhashchandran5f5c94d2021-10-19 07:18:30 -050088/**
89 * Request SBE dump from the dump manager
90 *
91 * Request SBE dump from the dump manager and register a monitor for observing
92 * the dump progress.
93 *
94 * @param failingUnit The id of the proc containing failed SBE
95 * @param eid Error log id associated with dump
96 * @param sbeType Type of the SBE
97 */
98void requestSBEDump(const uint32_t failingUnit, const uint32_t eid,
99 SBETypes sbeType);
100
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -0500101} // namespace openpower::dump::util