Skip to content

Commit 0428d4b

Browse files
committed
bluetooth: trace the HIA/TIA access
Signed-off-by: R <[email protected]>
1 parent c1776a9 commit 0428d4b

1 file changed

Lines changed: 56 additions & 5 deletions

File tree

proxyclient/hv/trace_bt.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
from m1n1.trace import Tracer
22
from m1n1.trace.dart import DARTTracer
33
from m1n1.utils import *
4+
from collections import namedtuple
45
import struct
56

67

8+
ContextStruct = namedtuple('ContextStruct', [
9+
'version',
10+
'sz',
11+
'enabled_caps',
12+
'perInfo',
13+
'crHIA',
14+
'trTIA',
15+
'crTIA',
16+
'trHIA',
17+
'crIAEntry',
18+
'trIAEntry',
19+
'mcr',
20+
'mtr',
21+
'mtrEntry',
22+
'mcrEntry',
23+
'mtrDb',
24+
'mcrDb',
25+
'mtrMsi',
26+
'mcrMsi',
27+
'mtrOptHeadSize',
28+
'mtrOptFootSize',
29+
'mcrOptHeadSize',
30+
'mcrOptFootSize',
31+
'res_inPlaceComp_oOOComp',
32+
'piMsi',
33+
'scratchPa',
34+
'scratchSize',
35+
'res',
36+
])
37+
CONTEXTSTRUCT_STR = "<HHIQQQQQHHQQHHHHHHBBBBHHQII"
38+
39+
740
class BTBAR0Regs(RegMap):
841
IMG_DOORBELL = 0x140, Register32
942
RTI_CONTROL = 0x144, Register32
@@ -87,6 +120,10 @@ def start(self):
87120
self.trace_regmap(start, size, regmap, name=name, prefix=prefix)
88121

89122

123+
# FIXME how do we get stream IDs without hardcoding?
124+
STREAM = 2
125+
126+
90127
class BTTracer(MemRangeTracer):
91128
DEFAULT_MODE = TraceMode.SYNC
92129
REGMAPS = [BTBAR0Regs, BTBAR1Regs]
@@ -133,9 +170,8 @@ def w_IMG_DOORBELL(self, val):
133170

134171
self.dart_tracer.dart.dump_all()
135172

136-
# FIXME how do we get stream IDs without hardcoding?
137173
try:
138-
data = self.dart_tracer.dart.ioread(2, host_window_iova, host_window_sz)
174+
data = self.dart_tracer.dart.ioread(STREAM, host_window_iova, host_window_sz)
139175
with open(f'bt_dump_{self._dump_idx}.bin', 'wb') as f:
140176
f.write(data)
141177
chexdump(data[:0x400])
@@ -172,9 +208,8 @@ def w_RTI_CONTROL(self, val):
172208

173209
self.dart_tracer.dart.dump_all()
174210

175-
# FIXME how do we get stream IDs without hardcoding?
176211
try:
177-
data = self.dart_tracer.dart.ioread(2, host_window_iova, host_window_sz)
212+
data = self.dart_tracer.dart.ioread(STREAM, host_window_iova, host_window_sz)
178213
with open(f'bt_dump_{self._dump_idx}.bin', 'wb') as f:
179214
f.write(data)
180215
chexdump(data[:0x400])
@@ -183,11 +218,27 @@ def w_RTI_CONTROL(self, val):
183218
print(e)
184219

185220
try:
186-
data = self.dart_tracer.dart.ioread(2, rti_context_iova, 0x100)
221+
data = self.dart_tracer.dart.ioread(STREAM, rti_context_iova, 0x68)
187222
with open(f'bt_dump_{self._dump_idx}.bin', 'wb') as f:
188223
f.write(data)
189224
chexdump(data)
190225
self._dump_idx += 1
226+
227+
print("Got context data now")
228+
context = ContextStruct._make(struct.unpack(CONTEXTSTRUCT_STR, data))
229+
print(context)
230+
231+
def hook(name, iova, sz):
232+
physaddr = self.dart_tracer.dart.iotranslate(STREAM, iova, sz)[0][0]
233+
print(f"hooking {name} @ IOVA {iova:016X} phys {physaddr:016X}")
234+
self.trace(physaddr, sz, TraceMode.SYNC, prefix=name)
235+
236+
hook('perInfo', context.perInfo, 0x10)
237+
hook('crHIA', context.crHIA, 12)
238+
hook('crTIA', context.crTIA, 12)
239+
hook('trHIA', context.trHIA, 18)
240+
hook('trTIA', context.trTIA, 18)
241+
191242
except Exception as e:
192243
print(e)
193244

0 commit comments

Comments
 (0)