Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 369742e | 2018-07-16 17:32:37 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 369742e | 2018-07-16 17:32:37 +0100 | [diff] [blame] | 7 | #ifndef PSCI_LIB_H |
| 8 | #define PSCI_LIB_H |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 9 | |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <common/ep_info.h> |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 11 | |
Julius Werner | d5dfdeb | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 12 | #ifndef __ASSEMBLER__ |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | |
Antonio Nino Diaz | 93c78ed | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 14 | #include <cdefs.h> |
| 15 | #include <stdint.h> |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 16 | |
| 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 | ******************************************************************************/ |
| 23 | typedef struct spd_pm_ops { |
| 24 | void (*svc_on)(u_register_t target_cpu); |
Antonio Nino Diaz | 369742e | 2018-07-16 17:32:37 +0100 | [diff] [blame] | 25 | int32_t (*svc_off)(u_register_t __unused unused); |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 26 | void (*svc_suspend)(u_register_t max_off_pwrlvl); |
Antonio Nino Diaz | 369742e | 2018-07-16 17:32:37 +0100 | [diff] [blame] | 27 | void (*svc_on_finish)(u_register_t __unused unused); |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 28 | 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 | */ |
| 39 | typedef void (*mailbox_entrypoint_t)(void); |
| 40 | |
Lucian Paul-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 41 | /* |
| 42 | * These are the states reported by the PSCI_AFFINITY_INFO API for the specified |
| 43 | * CPU. The definitions of these states can be found in Section 5.7.1 in the |
| 44 | * PSCI specification (ARM DEN 0022C). Available for psci_lib clients. |
| 45 | */ |
| 46 | typedef enum { |
| 47 | AFF_STATE_ON = U(0), |
| 48 | AFF_STATE_OFF = U(1), |
| 49 | AFF_STATE_ON_PENDING = U(2) |
| 50 | } aff_info_state_t; |
| 51 | |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 52 | /****************************************************************************** |
| 53 | * Structure to pass PSCI Library arguments. |
| 54 | *****************************************************************************/ |
| 55 | typedef struct psci_lib_args { |
| 56 | /* The version information of PSCI Library Interface */ |
| 57 | param_header_t h; |
| 58 | /* The warm boot entrypoint function */ |
| 59 | mailbox_entrypoint_t mailbox_ep; |
| 60 | } psci_lib_args_t; |
| 61 | |
| 62 | /* Helper macro to set the psci_lib_args_t structure at runtime */ |
| 63 | #define SET_PSCI_LIB_ARGS_V1(_p, _entry) do { \ |
| 64 | SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0); \ |
| 65 | (_p)->mailbox_ep = (_entry); \ |
| 66 | } while (0) |
| 67 | |
| 68 | /* Helper macro to define the psci_lib_args_t statically */ |
| 69 | #define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry) \ |
| 70 | static const psci_lib_args_t (_name) = { \ |
| 71 | .h.type = (uint8_t)PARAM_PSCI_LIB_ARGS, \ |
| 72 | .h.version = (uint8_t)VERSION_1, \ |
| 73 | .h.size = (uint16_t)sizeof(_name), \ |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 74 | .h.attr = 0U, \ |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 75 | .mailbox_ep = (_entry) \ |
| 76 | } |
| 77 | |
| 78 | /* Helper macro to verify the pointer to psci_lib_args_t structure */ |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 79 | #define VERIFY_PSCI_LIB_ARGS_V1(_p) (((_p) != NULL) \ |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 80 | && ((_p)->h.type == PARAM_PSCI_LIB_ARGS) \ |
| 81 | && ((_p)->h.version == VERSION_1) \ |
| 82 | && ((_p)->h.size == sizeof(*(_p))) \ |
| 83 | && ((_p)->h.attr == 0) \ |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 84 | && ((_p)->mailbox_ep != NULL)) |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 85 | |
| 86 | /****************************************************************************** |
| 87 | * PSCI Library Interfaces |
| 88 | *****************************************************************************/ |
| 89 | u_register_t psci_smc_handler(uint32_t smc_fid, |
| 90 | u_register_t x1, |
| 91 | u_register_t x2, |
| 92 | u_register_t x3, |
| 93 | u_register_t x4, |
| 94 | void *cookie, |
| 95 | void *handle, |
| 96 | u_register_t flags); |
| 97 | int psci_setup(const psci_lib_args_t *lib_args); |
Jeenu Viswambharan | b10d449 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 98 | int psci_secondaries_brought_up(void); |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 99 | void psci_warmboot_entrypoint(void); |
| 100 | void psci_register_spd_pm_hook(const spd_pm_ops_t *pm); |
| 101 | void psci_prepare_next_non_secure_ctx( |
| 102 | entry_point_info_t *next_image_info); |
Sandeep Tripathy | 2274490 | 2020-08-17 20:22:13 +0530 | [diff] [blame] | 103 | int psci_stop_other_cores(unsigned int wait_ms, |
| 104 | void (*stop_func)(u_register_t mpidr)); |
Lucian Paul-Trifu | 3519afe | 2022-03-08 15:02:31 +0000 | [diff] [blame^] | 105 | unsigned int psci_is_last_on_core_safe(void); |
| 106 | |
Julius Werner | d5dfdeb | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 107 | #endif /* __ASSEMBLER__ */ |
Soby Mathew | 5dffb46 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 108 | |
Antonio Nino Diaz | 369742e | 2018-07-16 17:32:37 +0100 | [diff] [blame] | 109 | #endif /* PSCI_LIB_H */ |