blob: 9949dc6d32e15c129d15a49d12a463c443fe0405 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __SUSPEND_PRIV_H__
8#define __SUSPEND_PRIV_H__
9
10#define SUSPEND_CTX_SZ 64
11#define SUSPEND_CTX_SP_OFFSET 48
12#define SUSPEND_CTX_SAVE_SYSTEM_CTX_OFFSET 56
13
14#ifndef __ASSEMBLY__
15#include <cassert.h>
16#include <power_management.h>
17#include <stdint.h>
18#include <string.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020019
20#define NR_CTX_REGS 6
21
22/*
23 * struct tftf_suspend_ctx represents the architecture context to
24 * be saved and restored while entering suspend and coming out.
25 * It must be 16-byte aligned since it is allocated on the stack, which must be
26 * 16-byte aligned on ARMv8 (AArch64). Even though the alignment requirement
27 * is not present in AArch32, we use the same alignment and register width as
28 * it allows the same structure to be reused for AArch32.
29 */
30typedef struct tftf_suspend_context {
31 uint64_t arch_ctx_regs[NR_CTX_REGS];
32 uint64_t stack_pointer;
33 /*
34 * Whether the system context is saved and and needs to be restored.
35 * Note that the system context itself is not saved in this structure.
36 */
37 unsigned int save_system_context;
38} __aligned(16) tftf_suspend_ctx_t;
39
40/*
41 * Saves callee save registers on the stack
42 * Allocate space on stack for CPU context regs
43 * Enters suspend by calling tftf_enter_suspend.
44 * power state: PSCI power state to be sent via SMC
45 * Returns: PSCI_E_SUCCESS or PSCI_E_INVALID_PARAMS
46 */
47unsigned int __tftf_suspend(const suspend_info_t *power_state);
48
49/*
50 * Saves the architecture context of CPU in the memory
51 * tftf_suspend_context: Pointer to the location for saving the context
52 */
53void __tftf_save_arch_context(struct tftf_suspend_context *ctx);
54
55/*
56 * Calls __tftf_save_arch_context to saves arch context of cpu to the memory
57 * pointed by ctx
58 * Enters suspend by calling the SMC
59 * power state: PSCI power state to be sent via SMC
60 * ctx: Pointer to the location where suspend context can be stored
61 * Returns: PSCI_E_SUCCESS or PSCI_E_INVALID_PARAMS
62 */
63int32_t tftf_enter_suspend(const suspend_info_t *power_state,
64 tftf_suspend_ctx_t *ctx);
65
66/*
67 * Invokes the appropriate driver functions in the TFTF framework
68 * to save their context prior to a system suspend.
69 */
70void tftf_save_system_ctx(tftf_suspend_ctx_t *ctx);
71
72/*
73 * Invokes the appropriate driver functions in the TFTF framework
74 * to restore their context on wake-up from system suspend.
75 */
76void tftf_restore_system_ctx(tftf_suspend_ctx_t *ctx);
77
78/*
79 * Restores the CPU arch context and callee registers from the location pointed
80 * by X0(context ID).
81 * Returns: PSCI_E_SUCCESS
82 */
83unsigned int __tftf_cpu_resume_ep(void);
84
85/* Assembler asserts to verify #defines of offsets match as seen by compiler */
86CASSERT(SUSPEND_CTX_SZ == sizeof(tftf_suspend_ctx_t),
87 assert_suspend_context_size_mismatch);
88CASSERT(SUSPEND_CTX_SP_OFFSET == __builtin_offsetof(tftf_suspend_ctx_t, stack_pointer),
89 assert_stack_pointer_location_mismatch_in_suspend_ctx);
90CASSERT(SUSPEND_CTX_SAVE_SYSTEM_CTX_OFFSET ==
91 __builtin_offsetof(tftf_suspend_ctx_t, save_system_context),
92 assert_save_sys_ctx_mismatch_in_suspend_ctx);
93#endif /* __ASSEMBLY__ */
94
95#endif /* __SUSPEND_PRIV_H__ */