Skip to content

Commit ca8be31

Browse files
committed
utils: Add cpu_sleep() function
Signed-off-by: Hector Martin <[email protected]>
1 parent 121d20c commit ca8be31

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

proxyclient/m1n1/proxy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ class M1N1Proxy(Reloadable):
488488
P_GET_SIMD_STATE = 0x00e
489489
P_PUT_SIMD_STATE = 0x00f
490490
P_REBOOT = 0x010
491+
P_SLEEP = 0x011
491492

492493
P_WRITE64 = 0x100
493494
P_WRITE32 = 0x101
@@ -744,6 +745,8 @@ def put_simd_state(self, buf):
744745
self.request(self.P_PUT_SIMD_STATE, buf)
745746
def reboot(self):
746747
self.request(self.P_REBOOT, no_reply=True)
748+
def sleep(self, deep=False):
749+
self.request(self.P_SLEEP, deep, no_reply=True)
747750

748751
def write64(self, addr, data):
749752
'''write 8 byte value to given address'''

src/proxy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ int proxy_process(ProxyRequest *request, ProxyReply *reply)
112112
case P_REBOOT:
113113
reboot();
114114
break;
115+
case P_SLEEP:
116+
cpu_sleep(request->args[0]);
117+
break;
115118

116119
case P_WRITE64:
117120
exc_guard = GUARD_SKIP;

src/proxy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef enum {
2323
P_GET_SIMD_STATE,
2424
P_PUT_SIMD_STATE,
2525
P_REBOOT,
26+
P_SLEEP,
2627

2728
P_WRITE64 = 0x100, // Generic register functions
2829
P_WRITE32,

src/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ extern u32 board_id, chip_id;
430430

431431
extern struct vector_args next_stage;
432432

433+
void cpu_sleep(bool deep) __attribute__((noreturn));
433434
void deep_wfi(void);
434435

435436
bool is_heap(void *addr);

src/utils_asm.S

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,37 @@ deep_wfi:
178178
msr SYS_IMP_APL_CYC_OVRD, x0
179179

180180
ret
181+
182+
.globl cpu_sleep
183+
.type cpu_sleep, @function
184+
cpu_sleep:
185+
mrs x1, SYS_IMP_APL_CYC_OVRD
186+
and x1, x1, #~CYC_OVRD_IRQ_MODE_MASK
187+
orr x1, x1, #CYC_OVRD_IRQ_MODE(2)
188+
and x1, x1, #~CYC_OVRD_FIQ_MODE_MASK
189+
orr x1, x1, #CYC_OVRD_FIQ_MODE(2)
190+
msr SYS_IMP_APL_CYC_OVRD, x1
191+
192+
cmp x0, #0
193+
beq 1f
194+
195+
mrs x1, SYS_IMP_APL_ACC_OVRD
196+
orr x1, x1, #ACC_OVRD_PWR_DN_SRM(3)
197+
and x1, x1, #~ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP_MASK
198+
orr x1, x1, #ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(2)
199+
orr x1, x1, #ACC_OVRD_TRAIN_DOWN_LINK(3)
200+
orr x1, x1, #ACC_OVRD_POWER_DOWN_CPM(3)
201+
orr x1, x1, #ACC_OVRD_DISABLE_PIO_ON_WFI_CPU
202+
orr x1, x1, #ACC_OVRD_DEEP_SLEEP
203+
msr SYS_IMP_APL_ACC_OVRD, x1
204+
1:
205+
206+
mrs x1, SYS_IMP_APL_CYC_OVRD
207+
orr x1, x1, #CYC_OVRD_WFI_MODE(3)
208+
orr x1, x1, #CYC_OVRD_DISABLE_WFI_RET
209+
msr SYS_IMP_APL_CYC_OVRD, x1
210+
211+
2:
212+
isb
213+
wfi
214+
b 2b

0 commit comments

Comments
 (0)