blob: d7b7f9098e5a9c5ddf7543b645a509fc3c7c38bc [file] [log] [blame]
Zane Shelleye90b85d2021-12-17 17:24:49 -06001//------------------------------------------------------------------------------
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
11extern "C"
12{
13#include <libpdbg_sbe.h>
14}
15
Zane Shelley20ed74d2022-03-26 13:50:57 -050016#include <util/log.hpp>
Zane Shelleye90b85d2021-12-17 17:24:49 -060017#include <util/pdbg.hpp>
18#include <util/trace.hpp>
19
20using namespace analyzer;
21
22namespace util
23{
24
25namespace pdbg
26{
27
28//------------------------------------------------------------------------------
29
30bool 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
Zane Shelleyc7026262022-02-22 16:37:36 -060048int 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 {
Zane Shelley20ed74d2022-03-26 13:50:57 -050072 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);
Zane Shelleyc7026262022-02-22 16:37:36 -060076 }
77
78 return rc;
79}
80
81//------------------------------------------------------------------------------
82
83int 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 {
Zane Shelley20ed74d2022-03-26 13:50:57 -050092 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);
Zane Shelleyc7026262022-02-22 16:37:36 -060096 }
97
98 return rc;
99}
100
101//------------------------------------------------------------------------------
102
Zane Shelleye90b85d2021-12-17 17:24:49 -0600103} // namespace pdbg
104
105} // namespace util