blob: 87b49cf864bf5bdc917d41b22dd5f8da514aba7d [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
16#include <util/pdbg.hpp>
17#include <util/trace.hpp>
18
19using namespace analyzer;
20
21namespace util
22{
23
24namespace pdbg
25{
26
27//------------------------------------------------------------------------------
28
29bool queryLpcTimeout(pdbg_target* target)
30{
31 // Must be a processor target.
32 assert(TYPE_PROC == getTrgtType(target));
33
34 uint32_t result = 0;
35 if (0 != sbe_lpc_timeout(util::pdbg::getPibTrgt(target), &result))
36 {
37 trace::err("sbe_lpc_timeout() failed: target=%s", getPath(target));
38 result = 0; // just in case
39 }
40
41 // 0 if no timeout, 1 if LPC timeout occurred.
42 return (0 != result);
43}
44
45//------------------------------------------------------------------------------
46
Zane Shelleyc7026262022-02-22 16:37:36 -060047int getScom(pdbg_target* i_target, uint64_t i_addr, uint64_t& o_val)
48{
49 assert(nullptr != i_target);
50
51 int rc = 0;
52
53 auto targetType = getTrgtType(i_target);
54
55 if (TYPE_PROC == targetType)
56 {
57 rc = pib_read(getPibTrgt(i_target), i_addr, &o_val);
58 }
59 else if (TYPE_OCMB == targetType)
60 {
61 rc = ocmb_getscom(i_target, i_addr, &o_val);
62 }
63 else
64 {
65 throw std::logic_error("Invalid type for SCOM operation: target=" +
66 std::string{getPath(i_target)});
67 }
68
69 if (0 != rc)
70 {
71 trace::err("SCOM read failure: target=%s addr=0x%0" PRIx64,
72 getPath(i_target), i_addr);
73 }
74
75 return rc;
76}
77
78//------------------------------------------------------------------------------
79
80int getCfam(pdbg_target* i_target, uint32_t i_addr, uint32_t& o_val)
81{
82 assert(nullptr != i_target);
83 assert(TYPE_PROC == getTrgtType(i_target));
84
85 int rc = fsi_read(getFsiTrgt(i_target), i_addr, &o_val);
86
87 if (0 != rc)
88 {
89 trace::err("CFAM read failure: target=%s addr=0x%08x",
90 getPath(i_target), i_addr);
91 }
92
93 return rc;
94}
95
96//------------------------------------------------------------------------------
97
Zane Shelleye90b85d2021-12-17 17:24:49 -060098} // namespace pdbg
99
100} // namespace util