blob: 0ca6574687814633c525c7dd5856c3b981490183 [file] [log] [blame]
Zane Shelley171a2e02020-11-13 13:56:13 -06001#include <assert.h>
2
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -06003#include <util/pdbg.hpp>
Zane Shelley171a2e02020-11-13 13:56:13 -06004#include <util/trace.hpp>
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -06005
6namespace util
7{
8
9namespace pdbg
10{
11
12//------------------------------------------------------------------------------
13
Zane Shelleya0299852020-11-13 13:38:04 -060014pdbg_target* getTrgt(const libhei::Chip& i_chip)
15{
16 return (pdbg_target*)i_chip.getChip();
17}
18
19//------------------------------------------------------------------------------
20
21const char* getPath(pdbg_target* i_trgt)
22{
23 return pdbg_target_path(i_trgt);
24}
25
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060026const char* getPath(const libhei::Chip& i_chip)
27{
Zane Shelleya0299852020-11-13 13:38:04 -060028 return getPath(getTrgt(i_chip));
29}
30
31//------------------------------------------------------------------------------
32
33uint32_t getChipPos(pdbg_target* i_trgt)
34{
35 uint32_t attr = 0;
36 pdbg_target_get_attribute(i_trgt, "ATTR_FAPI_POS", 4, 1, &attr);
37 return attr;
38}
39
40uint32_t getChipPos(const libhei::Chip& i_chip)
41{
42 return getChipPos(getTrgt(i_chip));
43}
44
45//------------------------------------------------------------------------------
46
47uint8_t getTrgtType(pdbg_target* i_trgt)
48{
49 uint8_t attr = 0;
50 pdbg_target_get_attribute(i_trgt, "ATTR_TYPE", 1, 1, &attr);
51 return attr;
52}
53
54uint8_t getTrgtType(const libhei::Chip& i_chip)
55{
56 return getTrgtType(getTrgt(i_chip));
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -060057}
58
59//------------------------------------------------------------------------------
60
Zane Shelley171a2e02020-11-13 13:56:13 -060061pdbg_target* getPibTrgt(pdbg_target* i_procTrgt)
62{
63 // The input target must be a processor.
64 assert(0x05 == getTrgtType(i_procTrgt));
65
66 // Get the pib path.
67 char path[16];
68 sprintf(path, "/proc%d/pib", pdbg_target_index(i_procTrgt));
69
70 // Return the pib target.
71 pdbg_target* pibTrgt = pdbg_target_from_path(nullptr, path);
72 assert(nullptr != pibTrgt);
73
74 return pibTrgt;
75}
76
77//------------------------------------------------------------------------------
78
79uint32_t __getChipId(pdbg_target* i_trgt)
80{
81 uint32_t attr = 0;
82 pdbg_target_get_attribute(i_trgt, "ATTR_CHIP_ID", 4, 1, &attr);
83 return attr;
84}
85
86uint8_t __getChipEc(pdbg_target* i_trgt)
87{
88 uint8_t attr = 0;
89 pdbg_target_get_attribute(i_trgt, "ATTR_EC", 1, 1, &attr);
90 return attr;
91}
92
93uint32_t __getChipIdEc(pdbg_target* i_trgt)
94{
95 return ((__getChipId(i_trgt) & 0xffff) << 16) | __getChipEc(i_trgt);
96}
97
98void __addChip(std::vector<libhei::Chip>& o_chips, pdbg_target* i_trgt,
99 libhei::ChipType_t i_type)
100{
101 // Trace each chip for debug. It is important to show the type just in case
102 // the model/EC does not exist. See note below.
103 trace::inf("Chip found: type=0x%08" PRIx32 " chip=%s", i_type,
104 getPath(i_trgt));
105
106 if (0 == i_type)
107 {
108 // There is a special case where the model/level attributes have not
109 // been initialized in the devtree. This is possible on the epoch IPL
110 // where an attention occurs before Hostboot is able to update the
111 // devtree information on the BMC. For now, just ignore the chip.
112 }
113 else
114 {
115 o_chips.emplace_back(i_trgt, i_type);
116 }
117}
118
119void getActiveChips(std::vector<libhei::Chip>& o_chips)
120{
121 o_chips.clear();
122
123 // Iterate each processor.
124 pdbg_target* procTrgt;
125 pdbg_for_each_class_target("proc", procTrgt)
126 {
127 // We cannot use the proc target to determine if the chip is active.
128 // There is some design limitation in pdbg that requires the proc
129 // targets to always be active. Instead, we must get the associated pib
130 // target and check if it is active.
131
132 // Active processors only.
133 if (PDBG_TARGET_ENABLED != pdbg_target_probe(getPibTrgt(procTrgt)))
134 continue;
135
136 // Add the processor to the list.
137 __addChip(o_chips, procTrgt, __getChipIdEc(procTrgt));
138
139 // Iterate the connected OCMBs, if they exist.
140 pdbg_target* ocmbTrgt;
141 pdbg_for_each_target("ocmb", procTrgt, ocmbTrgt)
142 {
143 // Active OCMBs only.
144 if (PDBG_TARGET_ENABLED != pdbg_target_probe(ocmbTrgt))
145 continue;
146
147 // Add the OCMB to the list.
148 __addChip(o_chips, ocmbTrgt, __getChipIdEc(ocmbTrgt));
149 }
150 }
151}
152
153//------------------------------------------------------------------------------
154
Zane Shelleyf4bd5ff2020-11-05 22:26:04 -0600155} // namespace pdbg
156
157} // namespace util