blob: 3edc50b6cec122a680d0deeb5e09d7cfec0943fb [file] [log] [blame]
Soby Mathewb911cc72017-02-13 12:46:28 +00001/*
Lucian Paul-Trifu5e685352022-03-02 21:28:24 +00002 * Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved.
Soby Mathewb911cc72017-02-13 12:46:28 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathewb911cc72017-02-13 12:46:28 +00005 */
6
Antonio Nino Diaz3ce0e772018-07-16 17:32:37 +01007#ifndef PSCI_LIB_H
8#define PSCI_LIB_H
Soby Mathewb911cc72017-02-13 12:46:28 +00009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/ep_info.h>
Soby Mathewb911cc72017-02-13 12:46:28 +000011
Julius Werner53456fc2019-07-09 13:49:11 -070012#ifndef __ASSEMBLER__
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010014#include <cdefs.h>
15#include <stdint.h>
Soby Mathewb911cc72017-02-13 12:46:28 +000016
17/*******************************************************************************
18 * Optional structure populated by the Secure Payload Dispatcher to be given a
19 * chance to perform any bookkeeping before PSCI executes a power management
20 * operation. It also allows PSCI to determine certain properties of the SP e.g.
21 * migrate capability etc.
22 ******************************************************************************/
23typedef struct spd_pm_ops {
24 void (*svc_on)(u_register_t target_cpu);
Antonio Nino Diaz3ce0e772018-07-16 17:32:37 +010025 int32_t (*svc_off)(u_register_t __unused unused);
Soby Mathewb911cc72017-02-13 12:46:28 +000026 void (*svc_suspend)(u_register_t max_off_pwrlvl);
Antonio Nino Diaz3ce0e772018-07-16 17:32:37 +010027 void (*svc_on_finish)(u_register_t __unused unused);
Soby Mathewb911cc72017-02-13 12:46:28 +000028 void (*svc_suspend_finish)(u_register_t max_off_pwrlvl);
29 int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu);
30 int32_t (*svc_migrate_info)(u_register_t *resident_cpu);
31 void (*svc_system_off)(void);
32 void (*svc_system_reset)(void);
33} spd_pm_ops_t;
34
35/*
36 * Function prototype for the warmboot entrypoint function which will be
37 * programmed in the mailbox by the platform.
38 */
39typedef void (*mailbox_entrypoint_t)(void);
40
41/******************************************************************************
42 * Structure to pass PSCI Library arguments.
43 *****************************************************************************/
44typedef struct psci_lib_args {
45 /* The version information of PSCI Library Interface */
46 param_header_t h;
47 /* The warm boot entrypoint function */
48 mailbox_entrypoint_t mailbox_ep;
49} psci_lib_args_t;
50
51/* Helper macro to set the psci_lib_args_t structure at runtime */
52#define SET_PSCI_LIB_ARGS_V1(_p, _entry) do { \
53 SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0); \
54 (_p)->mailbox_ep = (_entry); \
55 } while (0)
56
57/* Helper macro to define the psci_lib_args_t statically */
58#define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry) \
59 static const psci_lib_args_t (_name) = { \
60 .h.type = (uint8_t)PARAM_PSCI_LIB_ARGS, \
61 .h.version = (uint8_t)VERSION_1, \
62 .h.size = (uint16_t)sizeof(_name), \
Antonio Nino Diaz78a95a62018-07-17 15:10:08 +010063 .h.attr = 0U, \
Soby Mathewb911cc72017-02-13 12:46:28 +000064 .mailbox_ep = (_entry) \
65 }
66
67/* Helper macro to verify the pointer to psci_lib_args_t structure */
Antonio Nino Diaz78a95a62018-07-17 15:10:08 +010068#define VERIFY_PSCI_LIB_ARGS_V1(_p) (((_p) != NULL) \
Soby Mathewb911cc72017-02-13 12:46:28 +000069 && ((_p)->h.type == PARAM_PSCI_LIB_ARGS) \
70 && ((_p)->h.version == VERSION_1) \
71 && ((_p)->h.size == sizeof(*(_p))) \
72 && ((_p)->h.attr == 0) \
Antonio Nino Diaz78a95a62018-07-17 15:10:08 +010073 && ((_p)->mailbox_ep != NULL))
Soby Mathewb911cc72017-02-13 12:46:28 +000074
75/******************************************************************************
76 * PSCI Library Interfaces
77 *****************************************************************************/
78u_register_t psci_smc_handler(uint32_t smc_fid,
79 u_register_t x1,
80 u_register_t x2,
81 u_register_t x3,
82 u_register_t x4,
83 void *cookie,
84 void *handle,
85 u_register_t flags);
86int psci_setup(const psci_lib_args_t *lib_args);
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000087int psci_secondaries_brought_up(void);
Soby Mathewb911cc72017-02-13 12:46:28 +000088void psci_warmboot_entrypoint(void);
89void psci_register_spd_pm_hook(const spd_pm_ops_t *pm);
90void psci_prepare_next_non_secure_ctx(
91 entry_point_info_t *next_image_info);
Sandeep Tripathy12030042020-08-17 20:22:13 +053092int psci_stop_other_cores(unsigned int wait_ms,
93 void (*stop_func)(u_register_t mpidr));
Lucian Paul-Trifu5e685352022-03-02 21:28:24 +000094bool psci_is_last_on_cpu_safe(void);
Pranav Madhuc1e61d02022-07-22 23:11:16 +053095void psci_pwrdown_cpu(unsigned int power_level);
Lucian Paul-Trifu5e685352022-03-02 21:28:24 +000096
Julius Werner53456fc2019-07-09 13:49:11 -070097#endif /* __ASSEMBLER__ */
Soby Mathewb911cc72017-02-13 12:46:28 +000098
Antonio Nino Diaz3ce0e772018-07-16 17:32:37 +010099#endif /* PSCI_LIB_H */