xref: /rk3399_ARM-atf/include/lib/psci/psci_lib.h (revision 5dffb46c9c0ba2d3ae455b50fb78f418bd1f1258)
1*5dffb46cSSoby Mathew /*
2*5dffb46cSSoby Mathew  * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3*5dffb46cSSoby Mathew  *
4*5dffb46cSSoby Mathew  * Redistribution and use in source and binary forms, with or without
5*5dffb46cSSoby Mathew  * modification, are permitted provided that the following conditions are met:
6*5dffb46cSSoby Mathew  *
7*5dffb46cSSoby Mathew  * Redistributions of source code must retain the above copyright notice, this
8*5dffb46cSSoby Mathew  * list of conditions and the following disclaimer.
9*5dffb46cSSoby Mathew  *
10*5dffb46cSSoby Mathew  * Redistributions in binary form must reproduce the above copyright notice,
11*5dffb46cSSoby Mathew  * this list of conditions and the following disclaimer in the documentation
12*5dffb46cSSoby Mathew  * and/or other materials provided with the distribution.
13*5dffb46cSSoby Mathew  *
14*5dffb46cSSoby Mathew  * Neither the name of ARM nor the names of its contributors may be used
15*5dffb46cSSoby Mathew  * to endorse or promote products derived from this software without specific
16*5dffb46cSSoby Mathew  * prior written permission.
17*5dffb46cSSoby Mathew  *
18*5dffb46cSSoby Mathew  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*5dffb46cSSoby Mathew  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*5dffb46cSSoby Mathew  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*5dffb46cSSoby Mathew  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*5dffb46cSSoby Mathew  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*5dffb46cSSoby Mathew  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*5dffb46cSSoby Mathew  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*5dffb46cSSoby Mathew  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*5dffb46cSSoby Mathew  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*5dffb46cSSoby Mathew  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*5dffb46cSSoby Mathew  * POSSIBILITY OF SUCH DAMAGE.
29*5dffb46cSSoby Mathew  */
30*5dffb46cSSoby Mathew 
31*5dffb46cSSoby Mathew #ifndef __PSCI_LIB_H__
32*5dffb46cSSoby Mathew #define __PSCI_LIB_H__
33*5dffb46cSSoby Mathew 
34*5dffb46cSSoby Mathew #include <ep_info.h>
35*5dffb46cSSoby Mathew 
36*5dffb46cSSoby Mathew #ifndef __ASSEMBLY__
37*5dffb46cSSoby Mathew #include <types.h>
38*5dffb46cSSoby Mathew 
39*5dffb46cSSoby Mathew /*******************************************************************************
40*5dffb46cSSoby Mathew  * Optional structure populated by the Secure Payload Dispatcher to be given a
41*5dffb46cSSoby Mathew  * chance to perform any bookkeeping before PSCI executes a power management
42*5dffb46cSSoby Mathew  * operation. It also allows PSCI to determine certain properties of the SP e.g.
43*5dffb46cSSoby Mathew  * migrate capability etc.
44*5dffb46cSSoby Mathew  ******************************************************************************/
45*5dffb46cSSoby Mathew typedef struct spd_pm_ops {
46*5dffb46cSSoby Mathew 	void (*svc_on)(u_register_t target_cpu);
47*5dffb46cSSoby Mathew 	int32_t (*svc_off)(u_register_t __unused);
48*5dffb46cSSoby Mathew 	void (*svc_suspend)(u_register_t max_off_pwrlvl);
49*5dffb46cSSoby Mathew 	void (*svc_on_finish)(u_register_t __unused);
50*5dffb46cSSoby Mathew 	void (*svc_suspend_finish)(u_register_t max_off_pwrlvl);
51*5dffb46cSSoby Mathew 	int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu);
52*5dffb46cSSoby Mathew 	int32_t (*svc_migrate_info)(u_register_t *resident_cpu);
53*5dffb46cSSoby Mathew 	void (*svc_system_off)(void);
54*5dffb46cSSoby Mathew 	void (*svc_system_reset)(void);
55*5dffb46cSSoby Mathew } spd_pm_ops_t;
56*5dffb46cSSoby Mathew 
57*5dffb46cSSoby Mathew /*
58*5dffb46cSSoby Mathew  * Function prototype for the warmboot entrypoint function which will be
59*5dffb46cSSoby Mathew  * programmed in the mailbox by the platform.
60*5dffb46cSSoby Mathew  */
61*5dffb46cSSoby Mathew typedef void (*mailbox_entrypoint_t)(void);
62*5dffb46cSSoby Mathew 
63*5dffb46cSSoby Mathew /******************************************************************************
64*5dffb46cSSoby Mathew  * Structure to pass PSCI Library arguments.
65*5dffb46cSSoby Mathew  *****************************************************************************/
66*5dffb46cSSoby Mathew typedef struct psci_lib_args {
67*5dffb46cSSoby Mathew 	/* The version information of PSCI Library Interface */
68*5dffb46cSSoby Mathew 	param_header_t		h;
69*5dffb46cSSoby Mathew 	/* The warm boot entrypoint function */
70*5dffb46cSSoby Mathew 	mailbox_entrypoint_t	mailbox_ep;
71*5dffb46cSSoby Mathew } psci_lib_args_t;
72*5dffb46cSSoby Mathew 
73*5dffb46cSSoby Mathew /* Helper macro to set the psci_lib_args_t structure at runtime */
74*5dffb46cSSoby Mathew #define SET_PSCI_LIB_ARGS_V1(_p, _entry)	do {			\
75*5dffb46cSSoby Mathew 	SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0);		\
76*5dffb46cSSoby Mathew 	(_p)->mailbox_ep = (_entry);					\
77*5dffb46cSSoby Mathew 	} while (0)
78*5dffb46cSSoby Mathew 
79*5dffb46cSSoby Mathew /* Helper macro to define the psci_lib_args_t statically */
80*5dffb46cSSoby Mathew #define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry)		\
81*5dffb46cSSoby Mathew 	static const psci_lib_args_t (_name) = {		\
82*5dffb46cSSoby Mathew 		.h.type = (uint8_t)PARAM_PSCI_LIB_ARGS,		\
83*5dffb46cSSoby Mathew 		.h.version = (uint8_t)VERSION_1,		\
84*5dffb46cSSoby Mathew 		.h.size = (uint16_t)sizeof(_name),		\
85*5dffb46cSSoby Mathew 		.h.attr = 0,					\
86*5dffb46cSSoby Mathew 		.mailbox_ep = (_entry)				\
87*5dffb46cSSoby Mathew 	}
88*5dffb46cSSoby Mathew 
89*5dffb46cSSoby Mathew /* Helper macro to verify the pointer to psci_lib_args_t structure */
90*5dffb46cSSoby Mathew #define VERIFY_PSCI_LIB_ARGS_V1(_p)	((_p)			\
91*5dffb46cSSoby Mathew 		&& ((_p)->h.type == PARAM_PSCI_LIB_ARGS)	\
92*5dffb46cSSoby Mathew 		&& ((_p)->h.version == VERSION_1)		\
93*5dffb46cSSoby Mathew 		&& ((_p)->h.size == sizeof(*(_p)))		\
94*5dffb46cSSoby Mathew 		&& ((_p)->h.attr == 0)				\
95*5dffb46cSSoby Mathew 		&& ((_p)->mailbox_ep))
96*5dffb46cSSoby Mathew 
97*5dffb46cSSoby Mathew /******************************************************************************
98*5dffb46cSSoby Mathew  * PSCI Library Interfaces
99*5dffb46cSSoby Mathew  *****************************************************************************/
100*5dffb46cSSoby Mathew u_register_t psci_smc_handler(uint32_t smc_fid,
101*5dffb46cSSoby Mathew 			  u_register_t x1,
102*5dffb46cSSoby Mathew 			  u_register_t x2,
103*5dffb46cSSoby Mathew 			  u_register_t x3,
104*5dffb46cSSoby Mathew 			  u_register_t x4,
105*5dffb46cSSoby Mathew 			  void *cookie,
106*5dffb46cSSoby Mathew 			  void *handle,
107*5dffb46cSSoby Mathew 			  u_register_t flags);
108*5dffb46cSSoby Mathew int psci_setup(const psci_lib_args_t *lib_args);
109*5dffb46cSSoby Mathew void psci_warmboot_entrypoint(void);
110*5dffb46cSSoby Mathew void psci_register_spd_pm_hook(const spd_pm_ops_t *pm);
111*5dffb46cSSoby Mathew void psci_prepare_next_non_secure_ctx(
112*5dffb46cSSoby Mathew 			  entry_point_info_t *next_image_info);
113*5dffb46cSSoby Mathew #endif /* __ASSEMBLY__ */
114*5dffb46cSSoby Mathew 
115*5dffb46cSSoby Mathew #endif /* __PSCI_LIB_H */
116*5dffb46cSSoby Mathew 
117