blob: 10a46941c4aeeff1ef4e24ddeb26fd7acb67f070 [file] [log] [blame]
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -06001#pragma once
2
Zane Shelleya0299852020-11-13 13:38:04 -06003#include <libpdbg.h>
4
Zane Shelley38501e12022-01-10 15:42:28 -06005#include <analyzer/callout.hpp>
6
Zane Shelley3a851082021-03-23 16:45:28 -05007#include <string>
Zane Shelley7ae9c8c2020-12-02 20:10:31 -06008#include <vector>
9
10// Forward reference to avoid pulling the libhei library into everything that
11// includes this header.
12namespace libhei
13{
14class Chip;
15}
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060016
17namespace util
18{
19
20namespace pdbg
21{
22
Zane Shelley35171d92020-12-03 13:31:13 -060023/** Chip target types. */
24enum TargetType_t : uint8_t
25{
Zane Shelley55e7fec2022-01-28 15:29:44 -060026 TYPE_DIMM = 0x03,
27 TYPE_PROC = 0x05,
28 TYPE_CORE = 0x07,
Caleb Palmerbc94bde2022-02-18 09:03:37 -060029 TYPE_NX = 0x1e,
Zane Shelley55e7fec2022-01-28 15:29:44 -060030 TYPE_EQ = 0x23,
31 TYPE_PEC = 0x2d,
32 TYPE_PHB = 0x2e,
33 TYPE_MC = 0x44,
34 TYPE_IOLINK = 0x47,
35 TYPE_OMI = 0x48,
36 TYPE_MCC = 0x49,
37 TYPE_OMIC = 0x4a,
38 TYPE_OCMB = 0x4b,
39 TYPE_MEM_PORT = 0x4c,
40 TYPE_NMMU = 0x4f,
41 TYPE_PAU = 0x50,
42 TYPE_IOHS = 0x51,
43 TYPE_PAUC = 0x52,
Zane Shelley35171d92020-12-03 13:31:13 -060044};
45
Zane Shelleya0299852020-11-13 13:38:04 -060046/** @return The target associated with the given chip. */
47pdbg_target* getTrgt(const libhei::Chip& i_chip);
48
Zane Shelley236bb732021-03-24 17:07:46 -050049/** @return The target associated with the given devtree path. */
50pdbg_target* getTrgt(const std::string& i_path);
51
Zane Shelleya0299852020-11-13 13:38:04 -060052/** @return A string representing the given target's devtree path. */
53const char* getPath(pdbg_target* i_trgt);
54
55/** @return A string representing the given chip's devtree path. */
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060056const char* getPath(const libhei::Chip& i_chip);
57
Zane Shelleya0299852020-11-13 13:38:04 -060058/** @return The absolute position of the given target. */
59uint32_t getChipPos(pdbg_target* i_trgt);
60
61/** @return The absolute position of the given chip. */
62uint32_t getChipPos(const libhei::Chip& i_chip);
63
64/** @return The target type of the given target. */
65uint8_t getTrgtType(pdbg_target* i_trgt);
66
67/** @return The target type of the given chip. */
68uint8_t getTrgtType(const libhei::Chip& i_chip);
69
Zane Shelley171a2e02020-11-13 13:56:13 -060070/**
Zane Shelley38501e12022-01-10 15:42:28 -060071 * @return The connected target on the other side of the given bus.
72 * @param i_rxTarget The target on the receiving side (RX) of the bus.
73 * @param i_busType The bus type.
74 */
75pdbg_target* getConnectedTarget(pdbg_target* i_rxTarget,
76 const analyzer::callout::BusType& i_busType);
77
78/**
Zane Shelley171a2e02020-11-13 13:56:13 -060079 * @return The pib target associated with the given proc target.
80 * @note Will assert the given target is a proc target.
81 * @note Will assert the returned pib target it not nullptr.
82 */
83pdbg_target* getPibTrgt(pdbg_target* i_procTrgt);
84
85/**
Zane Shelleyff76b6b2020-11-18 13:54:26 -060086 * @return The fsi target associated with the given proc target.
87 * @note Will assert the given target is a proc target.
88 * @note Will assert the returned fsi target it not nullptr.
89 */
90pdbg_target* getFsiTrgt(pdbg_target* i_procTrgt);
91
92/**
Zane Shelleyc18ba8f2021-12-01 16:29:20 -060093 * @brief Reads a SCOM register.
94 * @param i_trgt Given target.
95 * @param i_addr Given address.
96 * @param o_val The returned value of the register.
97 * @return 0 if successful, non-0 otherwise.
98 * @note Will assert the given target is a proc target.
99 */
100int getScom(pdbg_target* i_trgt, uint64_t i_addr, uint64_t& o_val);
101
102/**
Zane Shelley35171d92020-12-03 13:31:13 -0600103 * @brief Reads a CFAM FSI register.
104 * @param i_trgt Given target.
105 * @param i_addr Given address.
106 * @param o_val The returned value of the register.
107 * @return 0 if successful, non-0 otherwise.
108 * @note Will assert the given target is a proc target.
109 */
110int getCfam(pdbg_target* i_trgt, uint32_t i_addr, uint32_t& o_val);
111
112/**
Zane Shelley171a2e02020-11-13 13:56:13 -0600113 * @brief Returns the list of all active chips in the system.
114 * @param o_chips The returned list of chips.
115 */
116void getActiveChips(std::vector<libhei::Chip>& o_chips);
117
Zane Shelley7ae9c8c2020-12-02 20:10:31 -0600118/**
Zane Shelleyc18ba8f2021-12-01 16:29:20 -0600119 * @return The primary processor (i.e. the processor connected to the BMC).
120 */
121pdbg_target* getPrimaryProcessor();
122
123/**
Zane Shelley7ae9c8c2020-12-02 20:10:31 -0600124 * @return True, if hardware analysis is supported on this system. False,
125 * otherwise.
126 * @note Support for hardware analysis from the BMC started with P10 systems
127 * and is not supported on any older chip generations.
128 */
129bool queryHardwareAnalysisSupported();
130
Zane Shelley3a851082021-03-23 16:45:28 -0500131/**
132 * @return A string containing the FRU location code of the given chip. An empty
133 * string indicates the target was null or the attribute does not exist
134 * for this target.
135 * @note This function requires PHAL APIs that are only available in certain
136 * environments. If they do not exist the devtree path of the target is
137 * returned.
138 */
139std::string getLocationCode(pdbg_target* trgt);
140
141/**
142 * @return A string containing the physical device path (entity path) of the
143 * given chip. An empty string indicates the target was null or the
144 * attribute does not exist for this target.
145 * @note This function requires PHAL APIs that are only available in certain
146 * environments. If they do not exist the devtree path of the target is
147 * returned.
148 */
149std::string getPhysDevPath(pdbg_target* trgt);
150
Zane Shelleybf3326f2021-11-12 13:41:39 -0600151/**
152 * @return A vector of bytes representing the numerical values of the physical
153 * device path (entity path) of the given target. An empty vector
154 * indicates the target was null or the attribute does not exist for
155 * this target or any parent targets along the device tree path.
156 * @note This function requires PHAL APIs that are only available in certain
157 * environments. If they do not exist, an empty vector is returned.
158 */
159std::vector<uint8_t> getPhysBinPath(pdbg_target* trgt);
160
Zane Shelleye90b85d2021-12-17 17:24:49 -0600161/**
162 * @brief Uses an SBE chip-op to query if there has been an LPC timeout.
163 * @return True, if there was an LPC timeout. False, otherwise.
164 */
165bool queryLpcTimeout(pdbg_target* target);
166
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600167} // namespace pdbg
168
169} // namespace util