xref: /openbmc/openpower-hw-diags/util/pdbg.hpp (revision c62813d4de33804c7ba5d82fe8ddc4a0f722c5ed)
1f4bd5ff6SZane Shelley #pragma once
2f4bd5ff6SZane Shelley 
3a0299858SZane Shelley #include <libpdbg.h>
4a0299858SZane Shelley 
538501e12SZane Shelley #include <analyzer/callout.hpp>
638501e12SZane Shelley 
73a85108fSZane Shelley #include <string>
87ae9c8c7SZane Shelley #include <vector>
97ae9c8c7SZane Shelley 
107ae9c8c7SZane Shelley // Forward reference to avoid pulling the libhei library into everything that
117ae9c8c7SZane Shelley // includes this header.
127ae9c8c7SZane Shelley namespace libhei
137ae9c8c7SZane Shelley {
147ae9c8c7SZane Shelley class Chip;
157ae9c8c7SZane Shelley }
16f4bd5ff6SZane Shelley 
17f4bd5ff6SZane Shelley namespace util
18f4bd5ff6SZane Shelley {
19f4bd5ff6SZane Shelley 
20f4bd5ff6SZane Shelley namespace pdbg
21f4bd5ff6SZane Shelley {
22f4bd5ff6SZane Shelley 
2335171d90SZane Shelley /** Chip target types. */
2435171d90SZane Shelley enum TargetType_t : uint8_t
2535171d90SZane Shelley {
2655e7fec3SZane Shelley     TYPE_DIMM = 0x03,
2735171d90SZane Shelley     TYPE_PROC = 0x05,
2855e7fec3SZane Shelley     TYPE_CORE = 0x07,
29bc94bdeaSCaleb Palmer     TYPE_NX = 0x1e,
3055e7fec3SZane Shelley     TYPE_EQ = 0x23,
3155e7fec3SZane Shelley     TYPE_PEC = 0x2d,
3255e7fec3SZane Shelley     TYPE_PHB = 0x2e,
3355e7fec3SZane Shelley     TYPE_MC = 0x44,
345d63cefcSZane Shelley     TYPE_IOLINK = 0x47,
355d63cefcSZane Shelley     TYPE_OMI = 0x48,
3655e7fec3SZane Shelley     TYPE_MCC = 0x49,
3755e7fec3SZane Shelley     TYPE_OMIC = 0x4a,
3835171d90SZane Shelley     TYPE_OCMB = 0x4b,
3955e7fec3SZane Shelley     TYPE_MEM_PORT = 0x4c,
4055e7fec3SZane Shelley     TYPE_NMMU = 0x4f,
4155e7fec3SZane Shelley     TYPE_PAU = 0x50,
42be619c00SZane Shelley     TYPE_IOHS = 0x51,
4355e7fec3SZane Shelley     TYPE_PAUC = 0x52,
4435171d90SZane Shelley };
4535171d90SZane Shelley 
46a0299858SZane Shelley /** @return The target associated with the given chip. */
47a0299858SZane Shelley pdbg_target* getTrgt(const libhei::Chip& i_chip);
48a0299858SZane Shelley 
49236bb730SZane Shelley /** @return The target associated with the given devtree path. */
50236bb730SZane Shelley pdbg_target* getTrgt(const std::string& i_path);
51236bb730SZane Shelley 
52a0299858SZane Shelley /** @return A string representing the given target's devtree path. */
53a0299858SZane Shelley const char* getPath(pdbg_target* i_trgt);
54a0299858SZane Shelley 
55a0299858SZane Shelley /** @return A string representing the given chip's devtree path. */
56f4bd5ff6SZane Shelley const char* getPath(const libhei::Chip& i_chip);
57f4bd5ff6SZane Shelley 
58a0299858SZane Shelley /** @return The absolute position of the given target. */
59a0299858SZane Shelley uint32_t getChipPos(pdbg_target* i_trgt);
60a0299858SZane Shelley 
61a0299858SZane Shelley /** @return The absolute position of the given chip. */
62a0299858SZane Shelley uint32_t getChipPos(const libhei::Chip& i_chip);
63a0299858SZane Shelley 
642a394cbbSZane Shelley /** @return The unit position of a target within a chip. */
652a394cbbSZane Shelley uint8_t getUnitPos(pdbg_target* i_trgt);
662a394cbbSZane Shelley 
67a0299858SZane Shelley /** @return The target type of the given target. */
68a0299858SZane Shelley uint8_t getTrgtType(pdbg_target* i_trgt);
69a0299858SZane Shelley 
70a0299858SZane Shelley /** @return The target type of the given chip. */
71a0299858SZane Shelley uint8_t getTrgtType(const libhei::Chip& i_chip);
72a0299858SZane Shelley 
732a394cbbSZane Shelley /** @return The parent chip target of the given unit target. */
742a394cbbSZane Shelley pdbg_target* getParentChip(pdbg_target* i_unitTarget);
752a394cbbSZane Shelley 
76*c62813d4SZane Shelley /** @return The parent processor chip target of the given target. */
77*c62813d4SZane Shelley pdbg_target* getParentProcessor(pdbg_target* i_target);
78*c62813d4SZane Shelley 
792a394cbbSZane Shelley /** @return The unit target within chip of the given unit type and position
802a394cbbSZane Shelley  *          relative to the chip. */
812a394cbbSZane Shelley pdbg_target* getChipUnit(pdbg_target* i_parentChip, TargetType_t i_unitType,
822a394cbbSZane Shelley                          uint8_t i_unitPos);
832a394cbbSZane Shelley 
84171a2e04SZane Shelley /**
8538501e12SZane Shelley  * @return The connected target on the other side of the given bus.
8638501e12SZane Shelley  * @param  i_rxTarget The target on the receiving side (RX) of the bus.
8738501e12SZane Shelley  * @param  i_busType  The bus type.
8838501e12SZane Shelley  */
8938501e12SZane Shelley pdbg_target* getConnectedTarget(pdbg_target* i_rxTarget,
9038501e12SZane Shelley                                 const analyzer::callout::BusType& i_busType);
9138501e12SZane Shelley 
9238501e12SZane Shelley /**
93171a2e04SZane Shelley  * @return The pib target associated with the given proc target.
94171a2e04SZane Shelley  * @note   Will assert the given target is a proc target.
95171a2e04SZane Shelley  * @note   Will assert the returned pib target it not nullptr.
96171a2e04SZane Shelley  */
97171a2e04SZane Shelley pdbg_target* getPibTrgt(pdbg_target* i_procTrgt);
98171a2e04SZane Shelley 
99171a2e04SZane Shelley /**
100ff76b6b4SZane Shelley  * @return The fsi target associated with the given proc target.
101ff76b6b4SZane Shelley  * @note   Will assert the given target is a proc target.
102ff76b6b4SZane Shelley  * @note   Will assert the returned fsi target it not nullptr.
103ff76b6b4SZane Shelley  */
104ff76b6b4SZane Shelley pdbg_target* getFsiTrgt(pdbg_target* i_procTrgt);
105ff76b6b4SZane Shelley 
106ff76b6b4SZane Shelley /**
107c18ba8fbSZane Shelley  * @brief  Reads a SCOM register.
108c18ba8fbSZane Shelley  * @param  i_trgt Given target.
109c18ba8fbSZane Shelley  * @param  i_addr Given address.
110c18ba8fbSZane Shelley  * @param  o_val  The returned value of the register.
111c18ba8fbSZane Shelley  * @return 0 if successful, non-0 otherwise.
112c18ba8fbSZane Shelley  * @note   Will assert the given target is a proc target.
113c18ba8fbSZane Shelley  */
114c18ba8fbSZane Shelley int getScom(pdbg_target* i_trgt, uint64_t i_addr, uint64_t& o_val);
115c18ba8fbSZane Shelley 
116c18ba8fbSZane Shelley /**
11735171d90SZane Shelley  * @brief  Reads a CFAM FSI register.
11835171d90SZane Shelley  * @param  i_trgt Given target.
11935171d90SZane Shelley  * @param  i_addr Given address.
12035171d90SZane Shelley  * @param  o_val  The returned value of the register.
12135171d90SZane Shelley  * @return 0 if successful, non-0 otherwise.
12235171d90SZane Shelley  * @note   Will assert the given target is a proc target.
12335171d90SZane Shelley  */
12435171d90SZane Shelley int getCfam(pdbg_target* i_trgt, uint32_t i_addr, uint32_t& o_val);
12535171d90SZane Shelley 
12635171d90SZane Shelley /**
127171a2e04SZane Shelley  * @brief Returns the list of all active chips in the system.
128171a2e04SZane Shelley  * @param o_chips The returned list of chips.
129171a2e04SZane Shelley  */
130171a2e04SZane Shelley void getActiveChips(std::vector<libhei::Chip>& o_chips);
131171a2e04SZane Shelley 
1327ae9c8c7SZane Shelley /**
1333f363d4aSZane Shelley  * @brief Returns the list of all active processor chips in the system.
1343f363d4aSZane Shelley  * @param o_chips The returned list of chips.
1353f363d4aSZane Shelley  */
1363f363d4aSZane Shelley void getActiveProcessorChips(std::vector<pdbg_target*>& o_chips);
1373f363d4aSZane Shelley 
1383f363d4aSZane Shelley /**
139c18ba8fbSZane Shelley  * @return The primary processor (i.e. the processor connected to the BMC).
140c18ba8fbSZane Shelley  */
141c18ba8fbSZane Shelley pdbg_target* getPrimaryProcessor();
142c18ba8fbSZane Shelley 
143c18ba8fbSZane Shelley /**
1447ae9c8c7SZane Shelley  * @return True, if hardware analysis is supported on this system. False,
1457ae9c8c7SZane Shelley  *         otherwise.
1467ae9c8c7SZane Shelley  * @note   Support for hardware analysis from the BMC started with P10 systems
1477ae9c8c7SZane Shelley  *         and is not supported on any older chip generations.
1487ae9c8c7SZane Shelley  */
1497ae9c8c7SZane Shelley bool queryHardwareAnalysisSupported();
1507ae9c8c7SZane Shelley 
1513a85108fSZane Shelley /**
1523a85108fSZane Shelley  * @return A string containing the FRU location code of the given chip. An empty
1533a85108fSZane Shelley  *         string indicates the target was null or the attribute does not exist
1543a85108fSZane Shelley  *         for this target.
1553a85108fSZane Shelley  * @note   This function requires PHAL APIs that are only available in certain
1563a85108fSZane Shelley  *         environments. If they do not exist the devtree path of the target is
1573a85108fSZane Shelley  *         returned.
1583a85108fSZane Shelley  */
1593a85108fSZane Shelley std::string getLocationCode(pdbg_target* trgt);
1603a85108fSZane Shelley 
1613a85108fSZane Shelley /**
1623a85108fSZane Shelley  * @return A string containing the physical device path (entity path) of the
1633a85108fSZane Shelley  *         given chip. An empty string indicates the target was null or the
1643a85108fSZane Shelley  *         attribute does not exist for this target.
1653a85108fSZane Shelley  * @note   This function requires PHAL APIs that are only available in certain
1663a85108fSZane Shelley  *         environments. If they do not exist the devtree path of the target is
1673a85108fSZane Shelley  *         returned.
1683a85108fSZane Shelley  */
1693a85108fSZane Shelley std::string getPhysDevPath(pdbg_target* trgt);
1703a85108fSZane Shelley 
171bf3326fbSZane Shelley /**
172bf3326fbSZane Shelley  * @return A vector of bytes representing the numerical values of the physical
173bf3326fbSZane Shelley  *         device path (entity path) of the given target. An empty vector
174bf3326fbSZane Shelley  *         indicates the target was null or the attribute does not exist for
175bf3326fbSZane Shelley  *         this target or any parent targets along the device tree path.
176bf3326fbSZane Shelley  * @note   This function requires PHAL APIs that are only available in certain
177bf3326fbSZane Shelley  *         environments. If they do not exist, an empty vector is returned.
178bf3326fbSZane Shelley  */
179bf3326fbSZane Shelley std::vector<uint8_t> getPhysBinPath(pdbg_target* trgt);
180bf3326fbSZane Shelley 
181e90b85dcSZane Shelley /**
182e90b85dcSZane Shelley  * @brief  Uses an SBE chip-op to query if there has been an LPC timeout.
183e90b85dcSZane Shelley  * @return True, if there was an LPC timeout. False, otherwise.
184e90b85dcSZane Shelley  */
185e90b85dcSZane Shelley bool queryLpcTimeout(pdbg_target* target);
186e90b85dcSZane Shelley 
187f4bd5ff6SZane Shelley } // namespace pdbg
188f4bd5ff6SZane Shelley 
189f4bd5ff6SZane Shelley } // namespace util
190