Skip to content

Commit

Permalink
aop: Bring up AOP via standard ASC API
Browse files Browse the repository at this point in the history
Works up to "Finished boot" on J293AP 13.5

```
< 27:0x85000000000000
[audio] <RX rptr=0x80
00000000  08 00 00 10 00 00 00 00  02 00 00 00 00 00 00 00  |................|
00000010  8f 1f b9 29 00 00 00 00  2c 00 00 00 02 00 c0 00  |...)....,.......|
00000020  00 00 8e 1f b9 29 00 00  00 00 00 00 00 00 00 00  |.....)..........|
00000030  61 6f 70 2d 61 75 64 69  6f 00 72 69 67 67 65 72  |aop-audio.rigger|
00000040  00 cf 09 01 00 00 00 00  c2 02 00 e0 00 00 00 00  |................|
00000050  08 00 00 10 04 00 00 80  00 00 00 00              |............    |
[audio] Hello! (endpoint aop-audio)
[audio] < 0x10000008 Type NOTIFY Ver 2 Tag 0
[audio]   Len 44 Ver 2 Cat REPORT Type 0xc0 Ts 0x29b91f8e0000
[audio]   Unk1 0x0 Unk2 0x0
< 02:0x5000000000000d
[syslog] * [SPU_init.cpp:320]===( AOP IS READY )===
> 02:0x5000000000000d (TYPE=0x5, INDEX=0xd)
Finished boot
```

Signed-off-by: Eileen Yoon <[email protected]>
  • Loading branch information
eiln committed Jan 19, 2024
1 parent f6f3f3f commit 5a5c4fc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 90 deletions.
143 changes: 56 additions & 87 deletions proxyclient/experiments/aop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@

from m1n1.setup import *
from m1n1.shell import run_shell
from m1n1.hw.dart import DART, DARTRegs
from m1n1.hw.dart import DART
from m1n1.fw.asc import StandardASC, ASCDummyEndpoint
from m1n1.fw.asc.base import *
from m1n1.fw.aop import *
from m1n1.fw.aop.ipc import *
from m1n1.fw.afk.rbep import *
from m1n1.fw.afk.epic import *

# aop nodes have no clocks described in adt for j293. it does it itself
# p.pmgr_adt_clocks_enable("/arm-io/aop")
# p.pmgr_adt_clocks_enable("/arm-io/dart-aop")

# Set up a secondary proxy channel so that we can stream
# the microphone samples
p.usb_iodev_vuart_setup(p.iodev_whoami())
p.iodev_set_usage(IODEV.USB_VUART, USAGE.UARTPROXY)

p.pmgr_adt_clocks_enable("/arm-io/dart-aop")

adt_dc = u.adt["/arm-io/aop/iop-aop-nub/aop-audio/dc-2400000"]

pdm_config = Container(
Expand Down Expand Up @@ -72,6 +74,7 @@ class AFKEP_Hello_Ack(AFKEPMessage):

class EPICEndpoint(AFKRingBufEndpoint):
BUFSIZE = 0x1000
VERBOSE = True

def __init__(self, *args, **kwargs):
self.seq = 0x0
Expand All @@ -81,10 +84,11 @@ def __init__(self, *args, **kwargs):

@msg_handler(0x80, AFKEP_Hello)
def Hello(self, msg):
self.log("hello!")
self.rxbuf, self.rxbuf_dva = self.asc.ioalloc(self.BUFSIZE)
self.txbuf, self.txbuf_dva = self.asc.ioalloc(self.BUFSIZE)

self.send(AFKEP_Hello_Ack())
return True

def handle_hello(self, hdr, sub, fd):
if sub.type != 0xc0:
Expand Down Expand Up @@ -115,11 +119,11 @@ def handle_ipc(self, data):
if sub.category == EPICCategory.REPLY:
handled = self.handle_reply(hdr, sub, fd)

if not handled and getattr(self, 'VERBOSE', False):
self.log(f"< 0x{hdr.channel:x} Type {hdr.type} Ver {hdr.version} Tag {hdr.seq}")
self.log(f" Len {sub.length} Ver {sub.version} Cat {sub.category} Type {sub.type:#x} Ts {sub.timestamp:#x}")
self.log(f" Unk1 {sub.unk1:#x} Unk2 {sub.unk2:#x}")
chexdump(fd.read())
self.log(f"< 0x{hdr.channel:x} Type {hdr.type} Ver {hdr.version} Tag {hdr.seq}")
self.log(f" Len {sub.length} Ver {sub.version} Cat {sub.category} Type {sub.type:#x} Ts {sub.timestamp:#x}")
self.log(f" Unk1 {sub.unk1:#x} Unk2 {sub.unk2:#x}")
chexdump(fd.read())
return handled

def indirect(self, call, chan=0x1000000d, timeout=0.1):
tx = call.ARGS.build(call.args)
Expand Down Expand Up @@ -168,99 +172,67 @@ def roundtrip(self, call, chan=0x1000000d, timeout=0.3,

return call

class SPUAppEndpoint(EPICEndpoint):
SHORT = "SPUAppep"
class SPUEndpoint(EPICEndpoint): # SPUApp.t / i2c.pp.t
SHORT = "spu"

class AccelEndpoint(EPICEndpoint):
SHORT = "accelep"
SHORT = "accel"

class GyroEndpoint(EPICEndpoint):
SHORT = "gyroep"
SHORT = "gyro"

class UNK23Endpoint(EPICEndpoint):
SHORT = "unk23ep"
def start_queues(self):
pass # don't init gyro ep (we don't have one)

class LASEndpoint(EPICEndpoint):
SHORT = "lasep"
#VERBOSE = True # <--- uncomment to see lid angle measurements
class ALSEndpoint(EPICEndpoint): # als.hint
SHORT = "als"

class WakehintEndpoint(EPICEndpoint):
SHORT = "wakehintep"
class WakehintEndpoint(EPICEndpoint): # wakehint
SHORT = "wakehint"

class UNK26Endpoint(EPICEndpoint):
SHORT = "unk26ep"

class AudioEndpoint(EPICEndpoint):
SHORT = "audioep"

SHORT = "unk26"

class OSLogMessage(Register64):
TYPE = 63, 56
class AudioEndpoint(EPICEndpoint): # aop-audio.rigger
SHORT = "audio"

class OSLog_Init(OSLogMessage):
TYPE = 63, 56, Constant(1)
UNK = 51, 0
DVA = 7, 0

class AOPOSLogEndpoint(ASCBaseEndpoint):
BASE_MESSAGE = OSLogMessage
SHORT = "oslog"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.started = False

@msg_handler(1, OSLog_Init)
def Init(self, msg):
self.iobuffer, self.iobuffer_dva = self.asc.ioalloc(0x1_0000)
self.send(OSLog_Init(DVA=self.iobuffer_dva//0x1000))
self.started = True
return True
class VoiceTriggerEndpoint(EPICEndpoint): # aop-voicetrigger
SHORT = "voicetrigger"


class AOPClient(StandardASC, AOPBase):
ENDPOINTS = {
8: AOPOSLogEndpoint,

0x20: SPUAppEndpoint,
0x20: SPUEndpoint,
0x21: AccelEndpoint,
0x22: GyroEndpoint,
0x23: UNK23Endpoint,
0x24: LASEndpoint,
0x24: ALSEndpoint,
0x25: WakehintEndpoint,
0x26: UNK26Endpoint,
0x27: AudioEndpoint,
0x28: EPICEndpoint,
0x29: EPICEndpoint,
0x2a: EPICEndpoint,
0x2b: EPICEndpoint
0x28: VoiceTriggerEndpoint,
}

def __init__(self, u, adtpath, dart=None):
node = u.adt[adtpath]
self.base = node.get_reg(0)[0]

AOPBase.__init__(self, u, node)
super().__init__(u, self.base, dart)

p.dapf_init_all()

dart = DART.from_adt(u, "/arm-io/dart-aop", iova_range=(0x2c000, 0x10_000_000))
dart = DART.from_adt(u, "/arm-io/dart-aop", iova_range=(0x34000, 0x10_000_000))
dart.initialize()
dart.regs.TCR[0].set(BYPASS_DAPF=0, BYPASS_DART=0, TRANSLATE_ENABLE=1)
dart.regs.TCR[7].set(BYPASS_DAPF=0, BYPASS_DART=0, TRANSLATE_ENABLE=1)
dart.regs.TCR[15].val = 0x20100

aop = AOPClient(u, "/arm-io/aop", dart)

aop.update_bootargs({
'p0CE': 0x20000,
# 'laCn': 0x0,
# 'tPOA': 0x1,
'laCn': 0x0,
'tPOA': 0x1,
"gila": 0x80,
})

aop.verbose = 4

p.dapf_init_all()
aop.asc.OUTBOX_CTRL.val = 0x20001 # (FIFOCNT=0x0, OVERFLOW=0, EMPTY=1, FULL=0, RPTR=0x0, WPTR=0x0, ENABLE=1)

def set_aop_audio_pstate(devid, pstate):
audep.roundtrip(SetDeviceProp(
devid=devid,
Expand All @@ -274,34 +246,31 @@ def set_aop_audio_pstate(devid, pstate):
)).check_retcode()

try:
aop.boot()
for epno in range(0x20, 0x2c):
aop.start_ep(epno)
aop.start()

timeout = 10
while (not aop.audioep.ready) and timeout:
timeout = 5
while (not aop.audio.ready) and timeout:
aop.work_for(0.1)
timeout -= 1

if not timeout:
raise Exception("Timed out waiting on audio endpoint")

print("Finished boot")

audep = aop.audioep

audep.roundtrip(AttachDevice(devid='pdm0')).check_retcode()
audep.indirect(SetDeviceProp(
devid='pdm0', modifier=200, data=pdm_config)
).check_retcode()
audep.indirect(SetDeviceProp(
devid='pdm0', modifier=210, data=decimator_config)
).check_retcode()
audep.roundtrip(AttachDevice(devid='hpai')).check_retcode()
audep.roundtrip(AttachDevice(devid='lpai')).check_retcode()
audep.roundtrip(SetDeviceProp(
devid='lpai', modifier=301, data=Container(unk1=7, unk2=7, unk3=1, unk4=7))
).check_retcode()
audep = aop.audio

if 1:
audep.roundtrip(AttachDevice(devid='pdm0')).check_retcode()
audep.indirect(SetDeviceProp(
devid='pdm0', modifier=200, data=pdm_config)
).check_retcode()
audep.indirect(SetDeviceProp(
devid='pdm0', modifier=210, data=decimator_config)
).check_retcode()
audep.roundtrip(AttachDevice(devid='hpai')).check_retcode()
audep.roundtrip(AttachDevice(devid='lpai')).check_retcode()
audep.roundtrip(SetDeviceProp(
devid='lpai', modifier=301, data=Container(unk1=7, unk2=7, unk3=1, unk4=7))
).check_retcode()
except KeyboardInterrupt:
pass
except Exception:
Expand Down
9 changes: 6 additions & 3 deletions proxyclient/m1n1/fw/afk/rbep.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(self, *args, **kwargs):
self.alive = False
self.started = False
self.iobuffer = None
self.verbose = 2
self.verbose = 3
self.msgid = 0

def start(self):
Expand Down Expand Up @@ -204,14 +204,17 @@ def InitRX(self, msg):
self.start_queues()
return True

@msg_handler(0x8c, AFKEP_InitRB)
def InitUnk(self, msg):
return True

def init_rb(self, msg):
off = msg.OFFSET * AFKRingBuf.BLOCK_SIZE
size = msg.SIZE * AFKRingBuf.BLOCK_SIZE

return AFKRingBuf(self, self.iobuffer + off, size)

def start_queues(self):
self.send(AFKEP_Start())
self.send(AFKEP_Start())

@msg_handler(0x86, AFKEP_Start_Ack)
def Start_Ack(self, msg):
Expand Down

0 comments on commit 5a5c4fc

Please sign in to comment.