15dffb46cSSoby Mathew /* 2*a7be2a57SManish V Badarkhe * Copyright (c) 2017-2025, 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 1009d40e0eSAntonio Nino Diaz #include <common/ep_info.h> 115dffb46cSSoby Mathew 12d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 1309d40e0eSAntonio Nino Diaz 1493c78ed2SAntonio Nino Diaz #include <cdefs.h> 1593c78ed2SAntonio Nino Diaz #include <stdint.h> 165dffb46cSSoby Mathew 175dffb46cSSoby Mathew /******************************************************************************* 185dffb46cSSoby Mathew * Optional structure populated by the Secure Payload Dispatcher to be given a 195dffb46cSSoby Mathew * chance to perform any bookkeeping before PSCI executes a power management 205dffb46cSSoby Mathew * operation. It also allows PSCI to determine certain properties of the SP e.g. 215dffb46cSSoby Mathew * migrate capability etc. 225dffb46cSSoby Mathew ******************************************************************************/ 235dffb46cSSoby Mathew typedef struct spd_pm_ops { 245dffb46cSSoby Mathew void (*svc_on)(u_register_t target_cpu); 25369742ecSAntonio Nino Diaz int32_t (*svc_off)(u_register_t __unused unused); 265dffb46cSSoby Mathew void (*svc_suspend)(u_register_t max_off_pwrlvl); 27369742ecSAntonio Nino Diaz void (*svc_on_finish)(u_register_t __unused unused); 285dffb46cSSoby Mathew void (*svc_suspend_finish)(u_register_t max_off_pwrlvl); 295dffb46cSSoby Mathew int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu); 305dffb46cSSoby Mathew int32_t (*svc_migrate_info)(u_register_t *resident_cpu); 315dffb46cSSoby Mathew void (*svc_system_off)(void); 325dffb46cSSoby Mathew void (*svc_system_reset)(void); 335dffb46cSSoby Mathew } spd_pm_ops_t; 345dffb46cSSoby Mathew 355dffb46cSSoby Mathew /* 365dffb46cSSoby Mathew * Function prototype for the warmboot entrypoint function which will be 375dffb46cSSoby Mathew * programmed in the mailbox by the platform. 385dffb46cSSoby Mathew */ 395dffb46cSSoby Mathew typedef void (*mailbox_entrypoint_t)(void); 405dffb46cSSoby Mathew 415dffb46cSSoby Mathew /****************************************************************************** 425dffb46cSSoby Mathew * Structure to pass PSCI Library arguments. 435dffb46cSSoby Mathew *****************************************************************************/ 445dffb46cSSoby Mathew typedef struct psci_lib_args { 455dffb46cSSoby Mathew /* The version information of PSCI Library Interface */ 465dffb46cSSoby Mathew param_header_t h; 475dffb46cSSoby Mathew /* The warm boot entrypoint function */ 485dffb46cSSoby Mathew mailbox_entrypoint_t mailbox_ep; 495dffb46cSSoby Mathew } psci_lib_args_t; 505dffb46cSSoby Mathew 515dffb46cSSoby Mathew /* Helper macro to set the psci_lib_args_t structure at runtime */ 525dffb46cSSoby Mathew #define SET_PSCI_LIB_ARGS_V1(_p, _entry) do { \ 535dffb46cSSoby Mathew SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0); \ 545dffb46cSSoby Mathew (_p)->mailbox_ep = (_entry); \ 555dffb46cSSoby Mathew } while (0) 565dffb46cSSoby Mathew 575dffb46cSSoby Mathew /* Helper macro to define the psci_lib_args_t statically */ 585dffb46cSSoby Mathew #define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry) \ 595dffb46cSSoby Mathew static const psci_lib_args_t (_name) = { \ 605dffb46cSSoby Mathew .h.type = (uint8_t)PARAM_PSCI_LIB_ARGS, \ 615dffb46cSSoby Mathew .h.version = (uint8_t)VERSION_1, \ 625dffb46cSSoby Mathew .h.size = (uint16_t)sizeof(_name), \ 636b7b0f36SAntonio Nino Diaz .h.attr = 0U, \ 645dffb46cSSoby Mathew .mailbox_ep = (_entry) \ 655dffb46cSSoby Mathew } 665dffb46cSSoby Mathew 675dffb46cSSoby Mathew /* Helper macro to verify the pointer to psci_lib_args_t structure */ 686b7b0f36SAntonio Nino Diaz #define VERIFY_PSCI_LIB_ARGS_V1(_p) (((_p) != NULL) \ 695dffb46cSSoby Mathew && ((_p)->h.type == PARAM_PSCI_LIB_ARGS) \ 705dffb46cSSoby Mathew && ((_p)->h.version == VERSION_1) \ 715dffb46cSSoby Mathew && ((_p)->h.size == sizeof(*(_p))) \ 725dffb46cSSoby Mathew && ((_p)->h.attr == 0) \ 736b7b0f36SAntonio Nino Diaz && ((_p)->mailbox_ep != NULL)) 745dffb46cSSoby Mathew 755dffb46cSSoby Mathew /****************************************************************************** 765dffb46cSSoby Mathew * PSCI Library Interfaces 775dffb46cSSoby Mathew *****************************************************************************/ 785dffb46cSSoby Mathew u_register_t psci_smc_handler(uint32_t smc_fid, 795dffb46cSSoby Mathew u_register_t x1, 805dffb46cSSoby Mathew u_register_t x2, 815dffb46cSSoby Mathew u_register_t x3, 825dffb46cSSoby Mathew u_register_t x4, 835dffb46cSSoby Mathew void *cookie, 845dffb46cSSoby Mathew void *handle, 855dffb46cSSoby Mathew u_register_t flags); 865dffb46cSSoby Mathew int psci_setup(const psci_lib_args_t *lib_args); 87b10d4499SJeenu Viswambharan int psci_secondaries_brought_up(void); 885dffb46cSSoby Mathew void psci_warmboot_entrypoint(void); 895dffb46cSSoby Mathew void psci_register_spd_pm_hook(const spd_pm_ops_t *pm); 905dffb46cSSoby Mathew void psci_prepare_next_non_secure_ctx( 915dffb46cSSoby Mathew entry_point_info_t *next_image_info); 923b802105SBoyan Karatotev int psci_stop_other_cores(unsigned int this_cpu_idx, unsigned int wait_ms, 9322744909SSandeep Tripathy void (*stop_func)(u_register_t mpidr)); 943b802105SBoyan Karatotev bool psci_is_last_on_cpu_safe(unsigned int this_core); 953b802105SBoyan Karatotev bool psci_are_all_cpus_on_safe(unsigned int this_core); 9665bbb935SPranav Madhu void psci_pwrdown_cpu(unsigned int power_level); 972b5e00d4SBoyan Karatotev void psci_pwrdown_cpu_start(unsigned int power_level); 982b5e00d4SBoyan Karatotev void __dead2 psci_pwrdown_cpu_end_terminal(void); 992b5e00d4SBoyan Karatotev void psci_pwrdown_cpu_end_wakeup(unsigned int power_level); 100160e8434SJayanth Dodderi Chidanand void psci_do_manage_extensions(void); 101*a7be2a57SManish V Badarkhe unsigned int psci_num_cpus_running_on_safe(unsigned int this_core); 102ce14a12fSLucian Paul-Trifu 103d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */ 1045dffb46cSSoby Mathew 105369742ecSAntonio Nino Diaz #endif /* PSCI_LIB_H */ 106