xref: /rk3399_ARM-atf/include/lib/psci/psci_lib.h (revision 6d4f6aea2cd96a4a57ffa2d88b9230e2cab88f28)
1 /*
2  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef PSCI_LIB_H
8 #define PSCI_LIB_H
9 
10 #include <ep_info.h>
11 
12 #ifndef __ASSEMBLY__
13 #include <cdefs.h>
14 #include <stdint.h>
15 
16 /*******************************************************************************
17  * Optional structure populated by the Secure Payload Dispatcher to be given a
18  * chance to perform any bookkeeping before PSCI executes a power management
19  * operation. It also allows PSCI to determine certain properties of the SP e.g.
20  * migrate capability etc.
21  ******************************************************************************/
22 typedef struct spd_pm_ops {
23 	void (*svc_on)(u_register_t target_cpu);
24 	int32_t (*svc_off)(u_register_t __unused unused);
25 	void (*svc_suspend)(u_register_t max_off_pwrlvl);
26 	void (*svc_on_finish)(u_register_t __unused unused);
27 	void (*svc_suspend_finish)(u_register_t max_off_pwrlvl);
28 	int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu);
29 	int32_t (*svc_migrate_info)(u_register_t *resident_cpu);
30 	void (*svc_system_off)(void);
31 	void (*svc_system_reset)(void);
32 } spd_pm_ops_t;
33 
34 /*
35  * Function prototype for the warmboot entrypoint function which will be
36  * programmed in the mailbox by the platform.
37  */
38 typedef void (*mailbox_entrypoint_t)(void);
39 
40 /******************************************************************************
41  * Structure to pass PSCI Library arguments.
42  *****************************************************************************/
43 typedef struct psci_lib_args {
44 	/* The version information of PSCI Library Interface */
45 	param_header_t		h;
46 	/* The warm boot entrypoint function */
47 	mailbox_entrypoint_t	mailbox_ep;
48 } psci_lib_args_t;
49 
50 /* Helper macro to set the psci_lib_args_t structure at runtime */
51 #define SET_PSCI_LIB_ARGS_V1(_p, _entry)	do {			\
52 	SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0);		\
53 	(_p)->mailbox_ep = (_entry);					\
54 	} while (0)
55 
56 /* Helper macro to define the psci_lib_args_t statically */
57 #define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry)		\
58 	static const psci_lib_args_t (_name) = {		\
59 		.h.type = (uint8_t)PARAM_PSCI_LIB_ARGS,		\
60 		.h.version = (uint8_t)VERSION_1,		\
61 		.h.size = (uint16_t)sizeof(_name),		\
62 		.h.attr = 0U,					\
63 		.mailbox_ep = (_entry)				\
64 	}
65 
66 /* Helper macro to verify the pointer to psci_lib_args_t structure */
67 #define VERIFY_PSCI_LIB_ARGS_V1(_p)	(((_p) != NULL)		\
68 		&& ((_p)->h.type == PARAM_PSCI_LIB_ARGS)	\
69 		&& ((_p)->h.version == VERSION_1)		\
70 		&& ((_p)->h.size == sizeof(*(_p)))		\
71 		&& ((_p)->h.attr == 0)				\
72 		&& ((_p)->mailbox_ep != NULL))
73 
74 /******************************************************************************
75  * PSCI Library Interfaces
76  *****************************************************************************/
77 u_register_t psci_smc_handler(uint32_t smc_fid,
78 			  u_register_t x1,
79 			  u_register_t x2,
80 			  u_register_t x3,
81 			  u_register_t x4,
82 			  void *cookie,
83 			  void *handle,
84 			  u_register_t flags);
85 int psci_setup(const psci_lib_args_t *lib_args);
86 int psci_secondaries_brought_up(void);
87 void psci_warmboot_entrypoint(void);
88 void psci_register_spd_pm_hook(const spd_pm_ops_t *pm);
89 void psci_prepare_next_non_secure_ctx(
90 			  entry_point_info_t *next_image_info);
91 #endif /* __ASSEMBLY__ */
92 
93 #endif /* PSCI_LIB_H */
94