1 //------------------------------------------------------------------------------
2 // IMPORTANT:
3 // This file will NOT be built in CI test and should be used for any functions
4 // that require addition support to simulate in CI test. Any functions that will
5 // work out-of-the-box in CI test with use of the fake device tree should be put
6 // in `pdbg.cpp`.
7 //------------------------------------------------------------------------------
8
9 #include <assert.h>
10
11 extern "C"
12 {
13 #include <libpdbg_sbe.h>
14 }
15
16 #include <util/log.hpp>
17 #include <util/pdbg.hpp>
18 #include <util/trace.hpp>
19
20 using namespace analyzer;
21
22 namespace util
23 {
24
25 namespace pdbg
26 {
27
28 //------------------------------------------------------------------------------
29
queryLpcTimeout(pdbg_target * target)30 bool queryLpcTimeout(pdbg_target* target)
31 {
32 // Must be a processor target.
33 assert(TYPE_PROC == getTrgtType(target));
34
35 uint32_t result = 0;
36 if (0 != sbe_lpc_timeout(util::pdbg::getPibTrgt(target), &result))
37 {
38 trace::err("sbe_lpc_timeout() failed: target=%s", getPath(target));
39 result = 0; // just in case
40 }
41
42 // 0 if no timeout, 1 if LPC timeout occurred.
43 return (0 != result);
44 }
45
46 //------------------------------------------------------------------------------
47
getScom(pdbg_target * i_target,uint64_t i_addr,uint64_t & o_val)48 int getScom(pdbg_target* i_target, uint64_t i_addr, uint64_t& o_val)
49 {
50 assert(nullptr != i_target);
51
52 int rc = 0;
53
54 auto targetType = getTrgtType(i_target);
55
56 if (TYPE_PROC == targetType)
57 {
58 rc = pib_read(getPibTrgt(i_target), i_addr, &o_val);
59 }
60 else if (TYPE_OCMB == targetType)
61 {
62 rc = ocmb_getscom(i_target, i_addr, &o_val);
63 }
64 else
65 {
66 throw std::logic_error("Invalid type for SCOM operation: target=" +
67 std::string{getPath(i_target)});
68 }
69
70 if (0 != rc)
71 {
72 lg2::error(
73 "SCOM read failure: target={SCOM_TARGET} addr={SCOM_ADDRESS}",
74 "SCOM_TARGET", getPath(i_target), "SCOM_ADDRESS",
75 (lg2::hex | lg2::field64), i_addr, "SCOM_ACCESS_RC", rc);
76 }
77
78 return rc;
79 }
80
81 //------------------------------------------------------------------------------
82
getCfam(pdbg_target * i_target,uint32_t i_addr,uint32_t & o_val)83 int getCfam(pdbg_target* i_target, uint32_t i_addr, uint32_t& o_val)
84 {
85 assert(nullptr != i_target);
86 assert(TYPE_PROC == getTrgtType(i_target));
87
88 int rc = fsi_read(getFsiTrgt(i_target), i_addr, &o_val);
89
90 if (0 != rc)
91 {
92 lg2::error(
93 "CFAM read failure: target={CFAM_TARGET} addr={CFAM_ADDRESS}",
94 "CFAM_TARGET", getPath(i_target), "CFAM_ADDRESS",
95 (lg2::hex | lg2::field32), i_addr, "CFAM_ACCESS_RC", rc);
96 }
97
98 return rc;
99 }
100
101 //------------------------------------------------------------------------------
102
103 } // namespace pdbg
104
105 } // namespace util
106