summaryrefslogtreecommitdiff
path: root/lib/power_management/suspend/suspend_private.h
blob: dc84d4e93f8a8169b4adefd10e516bea6693149b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/** @file
*
*  Copyright (c) 2014, ARM Limited. All rights reserved.
*
*  This program and the accompanying materials
*  are licensed and made available under the terms and conditions of the BSD License
*  which accompanies this distribution.  The full text of the license may be found at
*  http://opensource.org/licenses/bsd-license.php
*
*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/

#ifndef __SUSPEND_PRIV_H__
#define __SUSPEND_PRIV_H__

#define CPU_SUSPEND_SZ 64
#define CPU_CTX_SP 48

#ifndef __ASSEMBLY__
#include <cassert.h>
#include <stdint.h>
#include <string.h>

#define NR_CTX_REGS 6

/*
 * struct tftf_cpu_suspend_ctx represents the architecture context to
 * be saved and restored while entering suspend and coming out.
 * It must be 16-byte aligned since it is allocated on the stack, which must be
 * 16-byte aligned on ARMv8
 */
typedef struct tftf_cpu_suspend_context {
	uint64_t arch_ctx_regs[NR_CTX_REGS];
	uint64_t stack_pointer;
} __aligned(16) tftf_cpu_suspend_ctx_t;

/*
 * Saves callee save registers on the stack
 * Allocate space on stack for CPU context regs
 * Enters suspend by calling tftf_enter_suspend.
 *     power state: PSCI power state to be sent via SMC
 *     Returns: PSCI_E_SUCCESS or PSCI_E_INVALID_PARAMS
 */
unsigned int __tftf_cpu_suspend(uint32_t power_state);

/*
 * Saves the architecture context of CPU in the memory
 *     tftf_cpu_suspend_context: Pointer to the location for saving the context
 */
void __tftf_save_arch_context(struct tftf_cpu_suspend_context *ctx);

/*
 * Calls __tftf_save_arch_context to saves arch context of cpu to the memory
 * pointed by ctx
 * Enters suspend by calling the SMC
 *     power state: PSCI power state to be sent via SMC
 *     ptr: Pointer to the location where CPU context can be stored
 *     Returns: PSCI_E_SUCCESS or PSCI_E_INVALID_PARAMS
 */
unsigned int __tftf_enter_suspend(uint32_t power_state,
					 tftf_cpu_suspend_ctx_t *ctx);

/*
 * Restores the CPU arch context and callee registers from the location pointed
 * by X0(context ID).
 * Returns: PSCI_E_SUCCESS
 */
unsigned int __tftf_cpu_resume_ep(void);

/* Assembler asserts to verify #defines of offsets match as seen by compiler */
CASSERT(CPU_SUSPEND_SZ == sizeof(tftf_cpu_suspend_ctx_t),
				assert_cpu_context_size_mismatch);
CASSERT(CPU_CTX_SP == __builtin_offsetof(tftf_cpu_suspend_ctx_t, stack_pointer),
			assert_stack_pointer_location_mismatch_in_suspend_cxt);
#endif	/* __ASSEMBLY__ */

#endif	/* __SUSPEND_PRIV_H__ */