Skip to content

Commit 3288548

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

5 files changed

Lines changed: 46 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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,41 @@ 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+
cmp x0, #0
186+
bne 1f
187+
188+
mrs x1, SYS_IMP_APL_CYC_OVRD
189+
and x1, x1, #~CYC_OVRD_IRQ_MODE_MASK
190+
orr x1, x1, #CYC_OVRD_IRQ_MODE(2)
191+
and x1, x1, #~CYC_OVRD_FIQ_MODE_MASK
192+
orr x1, x1, #CYC_OVRD_FIQ_MODE(2)
193+
msr SYS_IMP_APL_CYC_OVRD, x1
194+
1:
195+
196+
cmp x0, #0
197+
beq 2f
198+
199+
mrs x1, SYS_IMP_APL_ACC_OVRD
200+
orr x1, x1, #ACC_OVRD_PWR_DN_SRM(3)
201+
and x1, x1, #~ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP_MASK
202+
orr x1, x1, #ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(2)
203+
orr x1, x1, #ACC_OVRD_TRAIN_DOWN_LINK(3)
204+
orr x1, x1, #ACC_OVRD_POWER_DOWN_CPM(3)
205+
orr x1, x1, #ACC_OVRD_DISABLE_PIO_ON_WFI_CPU
206+
orr x1, x1, #ACC_OVRD_DEEP_SLEEP
207+
msr SYS_IMP_APL_ACC_OVRD, x1
208+
2:
209+
210+
mrs x1, SYS_IMP_APL_CYC_OVRD
211+
orr x1, x1, #CYC_OVRD_WFI_MODE(3)
212+
orr x1, x1, #CYC_OVRD_DISABLE_WFI_RET
213+
msr SYS_IMP_APL_CYC_OVRD, x1
214+
215+
3:
216+
isb
217+
wfi
218+
b 3b

0 commit comments

Comments
 (0)