From 7a9e031bff3abf56624b257357ee281f00f39e61 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 27 Feb 2018 16:10:51 -0800 Subject: [PATCH] Uncomment more sleep/suspend code --- exosphere/src/arm.h | 3 +++ exosphere/src/arm.s | 9 +++++++++ exosphere/src/cpu_context.c | 16 ++++++++++++++-- exosphere/src/cpu_context.h | 3 +++ exosphere/src/lp0.c | 8 ++++---- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/exosphere/src/arm.h b/exosphere/src/arm.h index d76441861..160a3a762 100644 --- a/exosphere/src/arm.h +++ b/exosphere/src/arm.h @@ -17,4 +17,7 @@ void invalidate_dcache_range(const void *start, const void *end); void invalidate_icache_inner_shareable(void); + +void call_with_stack_pointer(uintptr_t stack_pointer, void (*function)(void)); + #endif diff --git a/exosphere/src/arm.s b/exosphere/src/arm.s index 128afe973..0d5f58540 100644 --- a/exosphere/src/arm.s +++ b/exosphere/src/arm.s @@ -227,3 +227,12 @@ invalidate_icache_inner_shareable: dsb ish isb ret + + +/* Call a function with desired stack pointer. */ +.section .text.call_with_stack_pointer, "ax", %progbits +.type call_with_stack_pointer, %function +.global call_with_stack_pointer +call_with_stack_pointer: + mov sp, x0 + br x1 \ No newline at end of file diff --git a/exosphere/src/cpu_context.c b/exosphere/src/cpu_context.c index db33f6a57..29ae4ed88 100644 --- a/exosphere/src/cpu_context.c +++ b/exosphere/src/cpu_context.c @@ -5,6 +5,7 @@ #include "flow.h" #include "pmc.h" #include "timers.h" +#include "smc_api.h" #include "utils.h" static saved_cpu_context_t g_cpu_contexts[NUM_CPU_CORES] = {0}; @@ -72,10 +73,11 @@ void power_down_current_core(void) { } uint32_t cpu_off(void) { - if (get_core_id() == 3) { + unsigned int current_core = get_core_id(); + if (current_core == 3) { power_down_current_core(); } else { - /* TODO: call_with_stack_pointer(get_powerdown_stack(), power_down_current_core); */ + call_with_stack_pointer(get_exception_entry_stack_address(current_core), power_down_current_core); } while (true) { /* Wait forever. */ @@ -220,3 +222,13 @@ void restore_current_core_context(void) { g_cpu_contexts[current_core].is_saved = 0; } } + + +void set_current_core_active(void) { + g_cpu_contexts[get_core_id()].is_active = 1; +} + +void set_current_core_inactive(void) { + g_cpu_contexts[get_core_id()].is_active = 0; +} + diff --git a/exosphere/src/cpu_context.h b/exosphere/src/cpu_context.h index 72ad0cb86..f1236524c 100644 --- a/exosphere/src/cpu_context.h +++ b/exosphere/src/cpu_context.h @@ -47,6 +47,9 @@ typedef struct { void save_current_core_context(void); void restore_current_core_context(void); +void set_current_core_active(void); +void set_current_core_inactive(void); + void set_core_entrypoint_and_argument(uint32_t core, uint64_t entrypoint_addr, uint64_t argument); uint32_t cpu_on(uint32_t core, uint64_t entrypoint_addr, uint64_t argument); diff --git a/exosphere/src/lp0.c b/exosphere/src/lp0.c index b601a2a23..83690ee22 100644 --- a/exosphere/src/lp0.c +++ b/exosphere/src/lp0.c @@ -7,6 +7,7 @@ #include "bpmp.h" #include "arm.h" #include "configitem.h" +#include "cpu_context.h" #include "flow.h" #include "fuse.h" #include "i2c.h" @@ -121,10 +122,9 @@ uint32_t cpu_suspend(uint64_t power_state, uint64_t entrypoint, uint64_t argumen /* Save core context. */ set_core_entrypoint_and_argument(current_core, entrypoint, argument); - /* TODO: save_current_core_context(); */ - /* TODO: set_current_core_inacctive(); */ - /* TODO: set_current_core_saved(true); */ - /* TODO: call_with_stack_pointer(TZRAM_GET_SEGMENT_ADDR(TZRAM_SEGMENT_ID_CORE012_STACK) + 0x1000ULL, save_se_and_power_down_cpu); */ + save_current_core_context(); + set_current_core_inactive(); + call_with_stack_pointer(get_smc_core012_stack_address(), save_se_and_power_down_cpu); /* NOTE: This return never actually occurs. */ return 0;