xref: /rk3399_ARM-atf/include/lib/psci/psci_lib.h (revision 93c78ed231a6ea30f1c30ecbbb0f245fa9d75075)
15dffb46cSSoby Mathew /*
2369742ecSAntonio Nino Diaz  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
35dffb46cSSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
55dffb46cSSoby Mathew  */
65dffb46cSSoby Mathew 
7369742ecSAntonio Nino Diaz #ifndef PSCI_LIB_H
8369742ecSAntonio Nino Diaz #define PSCI_LIB_H
95dffb46cSSoby Mathew 
105dffb46cSSoby Mathew #include <ep_info.h>
115dffb46cSSoby Mathew 
125dffb46cSSoby Mathew #ifndef __ASSEMBLY__
13*93c78ed2SAntonio Nino Diaz #include <cdefs.h>
14*93c78ed2SAntonio Nino Diaz #include <stdint.h>
155dffb46cSSoby Mathew 
165dffb46cSSoby Mathew /*******************************************************************************
175dffb46cSSoby Mathew  * Optional structure populated by the Secure Payload Dispatcher to be given a
185dffb46cSSoby Mathew  * chance to perform any bookkeeping before PSCI executes a power management
195dffb46cSSoby Mathew  * operation. It also allows PSCI to determine certain properties of the SP e.g.
205dffb46cSSoby Mathew  * migrate capability etc.
215dffb46cSSoby Mathew  ******************************************************************************/
225dffb46cSSoby Mathew typedef struct spd_pm_ops {
235dffb46cSSoby Mathew 	void (*svc_on)(u_register_t target_cpu);
24369742ecSAntonio Nino Diaz 	int32_t (*svc_off)(u_register_t __unused unused);
255dffb46cSSoby Mathew 	void (*svc_suspend)(u_register_t max_off_pwrlvl);
26369742ecSAntonio Nino Diaz 	void (*svc_on_finish)(u_register_t __unused unused);
275dffb46cSSoby Mathew 	void (*svc_suspend_finish)(u_register_t max_off_pwrlvl);
285dffb46cSSoby Mathew 	int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu);
295dffb46cSSoby Mathew 	int32_t (*svc_migrate_info)(u_register_t *resident_cpu);
305dffb46cSSoby Mathew 	void (*svc_system_off)(void);
315dffb46cSSoby Mathew 	void (*svc_system_reset)(void);
325dffb46cSSoby Mathew } spd_pm_ops_t;
335dffb46cSSoby Mathew 
345dffb46cSSoby Mathew /*
355dffb46cSSoby Mathew  * Function prototype for the warmboot entrypoint function which will be
365dffb46cSSoby Mathew  * programmed in the mailbox by the platform.
375dffb46cSSoby Mathew  */
385dffb46cSSoby Mathew typedef void (*mailbox_entrypoint_t)(void);
395dffb46cSSoby Mathew 
405dffb46cSSoby Mathew /******************************************************************************
415dffb46cSSoby Mathew  * Structure to pass PSCI Library arguments.
425dffb46cSSoby Mathew  *****************************************************************************/
435dffb46cSSoby Mathew typedef struct psci_lib_args {
445dffb46cSSoby Mathew 	/* The version information of PSCI Library Interface */
455dffb46cSSoby Mathew 	param_header_t		h;
465dffb46cSSoby Mathew 	/* The warm boot entrypoint function */
475dffb46cSSoby Mathew 	mailbox_entrypoint_t	mailbox_ep;
485dffb46cSSoby Mathew } psci_lib_args_t;
495dffb46cSSoby Mathew 
505dffb46cSSoby Mathew /* Helper macro to set the psci_lib_args_t structure at runtime */
515dffb46cSSoby Mathew #define SET_PSCI_LIB_ARGS_V1(_p, _entry)	do {			\
525dffb46cSSoby Mathew 	SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0);		\
535dffb46cSSoby Mathew 	(_p)->mailbox_ep = (_entry);					\
545dffb46cSSoby Mathew 	} while (0)
555dffb46cSSoby Mathew 
565dffb46cSSoby Mathew /* Helper macro to define the psci_lib_args_t statically */
575dffb46cSSoby Mathew #define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry)		\
585dffb46cSSoby Mathew 	static const psci_lib_args_t (_name) = {		\
595dffb46cSSoby Mathew 		.h.type = (uint8_t)PARAM_PSCI_LIB_ARGS,		\
605dffb46cSSoby Mathew 		.h.version = (uint8_t)VERSION_1,		\
615dffb46cSSoby Mathew 		.h.size = (uint16_t)sizeof(_name),		\
626b7b0f36SAntonio Nino Diaz 		.h.attr = 0U,					\
635dffb46cSSoby Mathew 		.mailbox_ep = (_entry)				\
645dffb46cSSoby Mathew 	}
655dffb46cSSoby Mathew 
665dffb46cSSoby Mathew /* Helper macro to verify the pointer to psci_lib_args_t structure */
676b7b0f36SAntonio Nino Diaz #define VERIFY_PSCI_LIB_ARGS_V1(_p)	(((_p) != NULL)		\
685dffb46cSSoby Mathew 		&& ((_p)->h.type == PARAM_PSCI_LIB_ARGS)	\
695dffb46cSSoby Mathew 		&& ((_p)->h.version == VERSION_1)		\
705dffb46cSSoby Mathew 		&& ((_p)->h.size == sizeof(*(_p)))		\
715dffb46cSSoby Mathew 		&& ((_p)->h.attr == 0)				\
726b7b0f36SAntonio Nino Diaz 		&& ((_p)->mailbox_ep != NULL))
735dffb46cSSoby Mathew 
745dffb46cSSoby Mathew /******************************************************************************
755dffb46cSSoby Mathew  * PSCI Library Interfaces
765dffb46cSSoby Mathew  *****************************************************************************/
775dffb46cSSoby Mathew u_register_t psci_smc_handler(uint32_t smc_fid,
785dffb46cSSoby Mathew 			  u_register_t x1,
795dffb46cSSoby Mathew 			  u_register_t x2,
805dffb46cSSoby Mathew 			  u_register_t x3,
815dffb46cSSoby Mathew 			  u_register_t x4,
825dffb46cSSoby Mathew 			  void *cookie,
835dffb46cSSoby Mathew 			  void *handle,
845dffb46cSSoby Mathew 			  u_register_t flags);
855dffb46cSSoby Mathew int psci_setup(const psci_lib_args_t *lib_args);
86b10d4499SJeenu Viswambharan int psci_secondaries_brought_up(void);
875dffb46cSSoby Mathew void psci_warmboot_entrypoint(void);
885dffb46cSSoby Mathew void psci_register_spd_pm_hook(const spd_pm_ops_t *pm);
895dffb46cSSoby Mathew void psci_prepare_next_non_secure_ctx(
905dffb46cSSoby Mathew 			  entry_point_info_t *next_image_info);
915dffb46cSSoby Mathew #endif /* __ASSEMBLY__ */
925dffb46cSSoby Mathew 
93369742ecSAntonio Nino Diaz #endif /* PSCI_LIB_H */
94