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