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