blob: 2945f25b1af78a4e61c44b982afc4b8d5b12e722 [file] [log] [blame]
Matt Spinler18c42b02020-06-02 15:59:50 -05001#pragma once
2
3#include "pel_types.hpp"
4
5#include <filesystem>
6#include <nlohmann/json.hpp>
7#include <string>
8#include <tuple>
9#include <vector>
10
11/**
12 * @file device_callouts.hpp
13 *
14 * @brief Looks up FRU callouts, which are D-Bus inventory paths,
15 * in JSON for device sysfs paths.
16 *
17 * The code will extract the search keys from the sysfs path to
18 * use to look up the callout list in the JSON. The callouts will
19 * be sorted by priority as defined in th PEL spec.
20 *
21 * The JSON is normally generated from the MRW, and contains
22 * sections for the following types of callouts:
23 * * I2C (also based on bus/addr as well as the path)
24 * * FSI
25 * * FSI-I2C
26 * * FSI-SPI
27 *
28 * The JSON looks like:
29 *
30 * "I2C":
31 * "<bus>":
32 * "<address>":
33 * "Callouts": [
34 * {
35 * "LocationCode": "<location code>",
36 * "Name": "<inventory path>",
37 * "Priority": "<priority=H/M/L>",
38 * "MRU": "<optional MRU name>"
39 * },
40 * ...
41 * ],
42 * "Dest": "<destination MRW target>"
43 *
44 * "FSI":
45 * "<fsi link>":
46 * "Callouts": [
47 * ...
48 * ],
49 * "Dest": "<destination MRW target>"
50 *
51 * "FSI-I2C":
52 * "<fsi link>":
53 * "<bus>":
54 * "<address>":
55 * "Callouts": [
56 * ...
57 * ],
58 * "Dest": "<destination MRW target>"
59 *
60 * "FSI-SPI":
61 * "<fsi link>":
62 * "<bus>":
63 * "Callouts": [
64 * ...
65 * ],
66 * "Dest": "<destination MRW target>"
67 *
68 */
69
70namespace openpower::pels::device_callouts
71{
72
73/**
74 * @brief Represents a callout in the device JSON.
75 *
76 * The debug field will only be filled in for the first
77 * callout in the list of them and contains additional
78 * information about what happened when looking up the
79 * callouts that is meant to aid in debug.
80 */
81struct Callout
82{
83 std::string priority;
84 std::string locationCode;
85 std::string name;
86 std::string mru;
87 std::string debug;
88};
89
90/**
91 * @brief Looks up the callouts in a JSON File to add to a PEL
92 * for when the path between the BMC and the device specified
93 * by the passed in device path needs to be called out.
94 *
95 * The path is the path used to access the device in sysfs. It
96 * can be either a directory path or a file path.
97 *
98 * @param[in] devPath - The device path
99 * @param[in] compatibleList - The list of compatible names for this
100 * system.
101 * @return std::vector<Callout> - The list of callouts
102 */
103std::vector<Callout>
104 getCallouts(const std::string& devPath,
105 const std::vector<std::string>& compatibleList);
106
107/**
108 * @brief Looks up the callouts to add to a PEL for when the path
109 * between the BMC and the device specified by the passed in
110 * I2C bus and address needs to be called out.
111 *
112 * @param[in] i2cBus - The I2C bus
113 * @param[in] i2cAddress - The I2C address
114 * @param[in] compatibleList - The list of compatible names for this
115 * system.
116 * @return std::vector<Callout> - The list of callouts
117 */
118std::vector<Callout>
119 getI2CCallouts(size_t i2cBus, uint8_t i2cAddress,
120 const std::vector<std::string>& compatibleList);
121
122namespace util
123{
124
125/**
126 * @brief Returns the path to the JSON file to look up callouts in.
127 *
128 * @param[in] compatibleList - The list of compatible names for this
129 * system.
130 *
131 * @return path - The path to the file.
132 */
133std::filesystem::path
134 getJSONFilename(const std::vector<std::string>& compatibleList);
135
136/**
137 * @brief Looks up the callouts in the JSON using the I2C keys.
138 *
139 * @param[in] i2cBus - The I2C bus
140 * @param[in] i2cAddress - The I2C address
141 * @param[in] calloutJSON - The JSON containing the callouts
142 *
143 * @return std::vector<Callout> - The callouts
144 */
145std::vector<device_callouts::Callout>
146 calloutI2C(size_t i2CBus, uint8_t i2cAddress,
147 const nlohmann::json& calloutJSON);
148} // namespace util
149} // namespace openpower::pels::device_callouts