1*91f16700SchasingluluPSCI OS-initiated mode 2*91f16700Schasinglulu====================== 3*91f16700Schasinglulu 4*91f16700Schasinglulu:Author: Maulik Shah & Wing Li 5*91f16700Schasinglulu:Organization: Qualcomm Innovation Center, Inc. & Google LLC 6*91f16700Schasinglulu:Contact: Maulik Shah <quic_mkshah@quicinc.com> & Wing Li <wingers@google.com> 7*91f16700Schasinglulu:Status: Accepted 8*91f16700Schasinglulu 9*91f16700Schasinglulu.. contents:: Table of Contents 10*91f16700Schasinglulu 11*91f16700SchasingluluIntroduction 12*91f16700Schasinglulu------------ 13*91f16700Schasinglulu 14*91f16700SchasingluluPower state coordination 15*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^^^^ 16*91f16700Schasinglulu 17*91f16700SchasingluluA power domain topology is a logical hierarchy of power domains in a system that 18*91f16700Schasingluluarises from the physical dependencies between power domains. 19*91f16700Schasinglulu 20*91f16700SchasingluluLocal power states describe power states for an individual node, and composite 21*91f16700Schasinglulupower states describe the combined power states for an individual node and its 22*91f16700Schasingluluparent node(s). 23*91f16700Schasinglulu 24*91f16700SchasingluluEntry into low-power states for a topology node above the core level requires 25*91f16700Schasinglulucoordinating its children nodes. For example, in a system with a power domain 26*91f16700Schasingluluthat encompasses a shared cache, and a separate power domain for each core that 27*91f16700Schasingluluuses the shared cache, the core power domains must be powered down before the 28*91f16700Schasinglulushared cache power domain can be powered down. 29*91f16700Schasinglulu 30*91f16700SchasingluluPSCI supports two modes of power state coordination: platform-coordinated and 31*91f16700SchasingluluOS-initiated. 32*91f16700Schasinglulu 33*91f16700SchasingluluPlatform-coordinated 34*91f16700Schasinglulu~~~~~~~~~~~~~~~~~~~~ 35*91f16700Schasinglulu 36*91f16700SchasingluluPlatform-coordinated mode is the default mode of power state coordination, and 37*91f16700Schasingluluis currently the only supported mode in TF-A. 38*91f16700Schasinglulu 39*91f16700SchasingluluIn platform-coordinated mode, the platform is responsible for coordinating power 40*91f16700Schasinglulustates, and chooses the deepest power state for a topology node that can be 41*91f16700Schasinglulutolerated by its children. 42*91f16700Schasinglulu 43*91f16700SchasingluluOS-initiated 44*91f16700Schasinglulu~~~~~~~~~~~~ 45*91f16700Schasinglulu 46*91f16700SchasingluluOS-initiated mode is optional. 47*91f16700Schasinglulu 48*91f16700SchasingluluIn OS-initiated mode, the calling OS is responsible for coordinating power 49*91f16700Schasinglulustates, and may request for a topology node to enter a low-power state when 50*91f16700Schasingluluits last child enters the low-power state. 51*91f16700Schasinglulu 52*91f16700SchasingluluMotivation 53*91f16700Schasinglulu---------- 54*91f16700Schasinglulu 55*91f16700SchasingluluThere are two reasons why OS-initiated mode might be a more suitable option than 56*91f16700Schasingluluplatform-coordinated mode for a platform. 57*91f16700Schasinglulu 58*91f16700SchasingluluScalability 59*91f16700Schasinglulu^^^^^^^^^^^ 60*91f16700Schasinglulu 61*91f16700SchasingluluIn platform-coordinated mode, each core independently selects their own local 62*91f16700Schasinglulupower states, and doesn't account for composite power states that are shared 63*91f16700Schasinglulubetween cores. 64*91f16700Schasinglulu 65*91f16700SchasingluluIn OS-initiated mode, the OS has knowledge of the next wakeup event for each 66*91f16700Schasinglulucore, and can have more precise control over the entry, exit, and wakeup 67*91f16700Schasinglululatencies when deciding if a composite power state (e.g. for a cluster) is 68*91f16700Schasingluluappropriate. This is especially important for multi-cluster SMP systems and 69*91f16700Schasingluluheterogeneous systems like big.LITTLE, where different processor types can have 70*91f16700Schasingluludifferent power efficiencies. 71*91f16700Schasinglulu 72*91f16700SchasingluluSimplicity 73*91f16700Schasinglulu^^^^^^^^^^ 74*91f16700Schasinglulu 75*91f16700SchasingluluIn platform-coordinated mode, the OS doesn't have visibility when the last core 76*91f16700Schasingluluat a power level enters a low-power state. If the OS wants to perform last man 77*91f16700Schasingluluactivity (e.g. powering off a shared resource when it is no longer needed), it 78*91f16700Schasingluluwould have to communicate with an API side channel to know when it can do so. 79*91f16700SchasingluluThis could result in a design smell where the platform is using 80*91f16700Schasingluluplatform-coordinated mode when it should be using OS-initiated mode instead. 81*91f16700Schasinglulu 82*91f16700SchasingluluIn OS-initiated mode, the OS can perform last man activity if it selects a 83*91f16700Schasinglulucomposite power state when the last core enters a low-power state. This 84*91f16700Schasinglulueliminates the need for a side channel, and uses the well documented API between 85*91f16700Schasingluluthe OS and the platform. 86*91f16700Schasinglulu 87*91f16700SchasingluluCurrent vendor implementations and workarounds 88*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 89*91f16700Schasinglulu 90*91f16700Schasinglulu* STMicroelectronics 91*91f16700Schasinglulu 92*91f16700Schasinglulu * For their ARM32 platforms, they're using OS-initiated mode implemented in 93*91f16700Schasinglulu OP-TEE. 94*91f16700Schasinglulu * For their future ARM64 platforms, they are interested in using OS-initiated 95*91f16700Schasinglulu mode in TF-A. 96*91f16700Schasinglulu 97*91f16700Schasinglulu* Qualcomm 98*91f16700Schasinglulu 99*91f16700Schasinglulu * For their mobile platforms, they're using OS-initiated mode implemented in 100*91f16700Schasinglulu their own custom secure monitor firmware. 101*91f16700Schasinglulu * For their Chrome OS platforms, they're using platform-coordinated mode in 102*91f16700Schasinglulu TF-A with custom driver logic to perform last man activity. 103*91f16700Schasinglulu 104*91f16700Schasinglulu* Google 105*91f16700Schasinglulu 106*91f16700Schasinglulu * They're using platform-coordinated mode in TF-A with custom driver logic to 107*91f16700Schasinglulu perform last man activity. 108*91f16700Schasinglulu 109*91f16700SchasingluluBoth Qualcomm and Google would like to be able to use OS-initiated mode in TF-A 110*91f16700Schasingluluin order to simplify custom driver logic. 111*91f16700Schasinglulu 112*91f16700SchasingluluRequirements 113*91f16700Schasinglulu------------ 114*91f16700Schasinglulu 115*91f16700SchasingluluPSCI_FEATURES 116*91f16700Schasinglulu^^^^^^^^^^^^^ 117*91f16700Schasinglulu 118*91f16700SchasingluluPSCI_FEATURES is for checking whether or not a PSCI function is implemented and 119*91f16700Schasingluluwhat its properties are. 120*91f16700Schasinglulu 121*91f16700Schasinglulu.. c:macro:: PSCI_FEATURES 122*91f16700Schasinglulu 123*91f16700Schasinglulu :param func_id: 0x8400_000A. 124*91f16700Schasinglulu :param psci_func_id: the function ID of a PSCI function. 125*91f16700Schasinglulu :retval NOT_SUPPORTED: if the function is not implemented. 126*91f16700Schasinglulu :retval feature flags associated with the function: if the function is 127*91f16700Schasinglulu implemented. 128*91f16700Schasinglulu 129*91f16700SchasingluluCPU_SUSPEND feature flags 130*91f16700Schasinglulu~~~~~~~~~~~~~~~~~~~~~~~~~ 131*91f16700Schasinglulu 132*91f16700Schasinglulu* Reserved, bits[31:2] 133*91f16700Schasinglulu* Power state parameter format, bit[1] 134*91f16700Schasinglulu 135*91f16700Schasinglulu * A value of 0 indicates the original format is used. 136*91f16700Schasinglulu * A value of 1 indicates the extended format is used. 137*91f16700Schasinglulu 138*91f16700Schasinglulu* OS-initiated mode, bit[0] 139*91f16700Schasinglulu 140*91f16700Schasinglulu * A value of 0 indicates OS-initiated mode is not supported. 141*91f16700Schasinglulu * A value of 1 indicates OS-initiated mode is supported. 142*91f16700Schasinglulu 143*91f16700SchasingluluSee sections 5.1.14 and 5.15 of the PSCI spec (DEN0022D.b) for more details. 144*91f16700Schasinglulu 145*91f16700SchasingluluPSCI_SET_SUSPEND_MODE 146*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^ 147*91f16700Schasinglulu 148*91f16700SchasingluluPSCI_SET_SUSPEND_MODE is for switching between the two different modes of power 149*91f16700Schasinglulustate coordination. 150*91f16700Schasinglulu 151*91f16700Schasinglulu.. c:macro:: PSCI_SET_SUSPEND_MODE 152*91f16700Schasinglulu 153*91f16700Schasinglulu :param func_id: 0x8400_000F. 154*91f16700Schasinglulu :param mode: 0 indicates platform-coordinated mode, 1 indicates OS-initiated 155*91f16700Schasinglulu mode. 156*91f16700Schasinglulu :retval SUCCESS: if the request is successful. 157*91f16700Schasinglulu :retval NOT_SUPPORTED: if OS-initiated mode is not supported. 158*91f16700Schasinglulu :retval INVALID_PARAMETERS: if the requested mode is not a valid value (0 or 159*91f16700Schasinglulu 1). 160*91f16700Schasinglulu :retval DENIED: if the cores are not in the correct state. 161*91f16700Schasinglulu 162*91f16700SchasingluluSwitching from platform-coordinated to OS-initiated is only allowed if the 163*91f16700Schasinglulufollowing conditions are met: 164*91f16700Schasinglulu 165*91f16700Schasinglulu* All cores are in one of the following states: 166*91f16700Schasinglulu 167*91f16700Schasinglulu * Running. 168*91f16700Schasinglulu * Off, through a call to CPU_OFF or not yet booted. 169*91f16700Schasinglulu * Suspended, through a call to CPU_DEFAULT_SUSPEND. 170*91f16700Schasinglulu 171*91f16700Schasinglulu* None of the cores has called CPU_SUSPEND since the last change of mode or 172*91f16700Schasinglulu boot. 173*91f16700Schasinglulu 174*91f16700SchasingluluSwitching from OS-initiated to platform-coordinated is only allowed if all cores 175*91f16700Schasingluluother than the calling core are off, either through a call to CPU_OFF or not yet 176*91f16700Schasinglulubooted. 177*91f16700Schasinglulu 178*91f16700SchasingluluIf these conditions are not met, the PSCI implementation must return DENIED. 179*91f16700Schasinglulu 180*91f16700SchasingluluSee sections 5.1.19 and 5.20 of the PSCI spec (DEN0022D.b) for more details. 181*91f16700Schasinglulu 182*91f16700SchasingluluCPU_SUSPEND 183*91f16700Schasinglulu^^^^^^^^^^^ 184*91f16700Schasinglulu 185*91f16700SchasingluluCPU_SUSPEND is for moving a topology node into a low-power state. 186*91f16700Schasinglulu 187*91f16700Schasinglulu.. c:macro:: CPU_SUSPEND 188*91f16700Schasinglulu 189*91f16700Schasinglulu :param func_id: 0xC400_0001. 190*91f16700Schasinglulu :param power_state: the requested low-power state to enter. 191*91f16700Schasinglulu :param entry_point_address: the address at which the core must resume 192*91f16700Schasinglulu execution following wakeup from a powerdown state. 193*91f16700Schasinglulu :param context_id: this field specifies a pointer to the saved context that 194*91f16700Schasinglulu must be restored on a core following wakeup from a powerdown state. 195*91f16700Schasinglulu :retval SUCCESS: if the request is successful. 196*91f16700Schasinglulu :retval INVALID_PARAMETERS: in OS-initiated mode, this error is returned when 197*91f16700Schasinglulu a low-power state is requested for a topology node above the core level, 198*91f16700Schasinglulu and at least one of the node's children is in a local low-power state 199*91f16700Schasinglulu that is incompatible with the request. 200*91f16700Schasinglulu :retval INVALID_ADDRESS: if the entry_point_address argument is invalid. 201*91f16700Schasinglulu :retval DENIED: only in OS-initiated mode; this error is returned when a 202*91f16700Schasinglulu low-power state is requested for a topology node above the core level, 203*91f16700Schasinglulu and at least one of the node's children is running, i.e. not in a 204*91f16700Schasinglulu low-power state. 205*91f16700Schasinglulu 206*91f16700SchasingluluIn platform-coordinated mode, the PSCI implementation coordinates requests from 207*91f16700Schasingluluall cores to determine the deepest power state to enter. 208*91f16700Schasinglulu 209*91f16700SchasingluluIn OS-initiated mode, the calling OS is making an explicit request for a 210*91f16700Schasingluluspecific power state, as opposed to expressing a vote. The PSCI implementation 211*91f16700Schasinglulumust comply with the request, unless the request is not consistent with the 212*91f16700Schasingluluimplementation's view of the system's state, in which case, the implementation 213*91f16700Schasinglulumust return INVALID_PARAMETERS or DENIED. 214*91f16700Schasinglulu 215*91f16700SchasingluluSee sections 5.1.2 and 5.4 of the PSCI spec (DEN0022D.b) for more details. 216*91f16700Schasinglulu 217*91f16700SchasingluluPower state formats 218*91f16700Schasinglulu~~~~~~~~~~~~~~~~~~~ 219*91f16700Schasinglulu 220*91f16700SchasingluluOriginal format 221*91f16700Schasinglulu 222*91f16700Schasinglulu* Power Level, bits[25:24] 223*91f16700Schasinglulu 224*91f16700Schasinglulu * The requested level in the power domain topology to enter a low-power 225*91f16700Schasinglulu state. 226*91f16700Schasinglulu 227*91f16700Schasinglulu* State Type, bit[16] 228*91f16700Schasinglulu 229*91f16700Schasinglulu * A value of 0 indicates a standby or retention state. 230*91f16700Schasinglulu * A value of 1 indicates a powerdown state. 231*91f16700Schasinglulu 232*91f16700Schasinglulu* State ID, bits[15:0] 233*91f16700Schasinglulu 234*91f16700Schasinglulu * Field to specify the requested composite power state. 235*91f16700Schasinglulu * The state ID encodings must uniquely describe every possible composite 236*91f16700Schasinglulu power state. 237*91f16700Schasinglulu * In OS-initiated mode, the state ID encoding must allow expressing the 238*91f16700Schasinglulu power level at which the calling core is the last to enter a powerdown 239*91f16700Schasinglulu state. 240*91f16700Schasinglulu 241*91f16700SchasingluluExtended format 242*91f16700Schasinglulu 243*91f16700Schasinglulu* State Type, bit[30] 244*91f16700Schasinglulu* State ID, bits[27:0] 245*91f16700Schasinglulu 246*91f16700SchasingluluRaces in OS-initiated mode 247*91f16700Schasinglulu~~~~~~~~~~~~~~~~~~~~~~~~~~ 248*91f16700Schasinglulu 249*91f16700SchasingluluIn OS-initiated mode, there are race windows where the OS's view and 250*91f16700Schasingluluimplementation's view of the system's state differ. It is possible for the OS to 251*91f16700Schasinglulumake requests that are invalid given the implementation's view of the system's 252*91f16700Schasinglulustate. For example, the OS might request a powerdown state for a node from one 253*91f16700Schasinglulucore, while at the same time, the implementation observes that another core in 254*91f16700Schasingluluthat node is powering up. 255*91f16700Schasinglulu 256*91f16700SchasingluluTo address potential race conditions in power state requests: 257*91f16700Schasinglulu 258*91f16700Schasinglulu* The calling OS must specify in each CPU_SUSPEND request the deepest power 259*91f16700Schasinglulu level for which it sees the calling core as the last running core (last man). 260*91f16700Schasinglulu This is required even if the OS doesn't want the node at that power level to 261*91f16700Schasinglulu enter a low-power state. 262*91f16700Schasinglulu* The implementation must validate that the requested power states in the 263*91f16700Schasinglulu CPU_SUSPEND request are consistent with the system's state, and that the 264*91f16700Schasinglulu calling core is the last core running at the requested power level, or deny 265*91f16700Schasinglulu the request otherwise. 266*91f16700Schasinglulu 267*91f16700SchasingluluSee sections 4.2.3.2, 6.2, and 6.3 of the PSCI spec (DEN0022D.b) for more 268*91f16700Schasingluludetails. 269*91f16700Schasinglulu 270*91f16700SchasingluluCaveats 271*91f16700Schasinglulu------- 272*91f16700Schasinglulu 273*91f16700SchasingluluCPU_OFF 274*91f16700Schasinglulu^^^^^^^ 275*91f16700Schasinglulu 276*91f16700SchasingluluCPU_OFF is always platform-coordinated, regardless of whether the power state 277*91f16700Schasinglulucoordination mode for suspend is platform-coordinated or OS-initiated. If all 278*91f16700Schasinglulucores in a topology node call CPU_OFF, the last core will power down the node. 279*91f16700Schasinglulu 280*91f16700SchasingluluIn OS-initiated mode, if a subset of the cores in a topology node has called 281*91f16700SchasingluluCPU_OFF, the last running core may call CPU_SUSPEND to request a powerdown state 282*91f16700Schasingluluat or above that node's power level. 283*91f16700Schasinglulu 284*91f16700SchasingluluSee section 5.5.2 of the PSCI spec (DEN0022D.b) for more details. 285*91f16700Schasinglulu 286*91f16700SchasingluluImplementation 287*91f16700Schasinglulu-------------- 288*91f16700Schasinglulu 289*91f16700SchasingluluCurrent implementation of platform-coordinated mode 290*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 291*91f16700Schasinglulu 292*91f16700SchasingluluPlatform-coordinated is currently the only supported power state coordination 293*91f16700Schasinglulumode in TF-A. 294*91f16700Schasinglulu 295*91f16700SchasingluluThe functions of interest in the ``psci_cpu_suspend`` call stack are as follows: 296*91f16700Schasinglulu 297*91f16700Schasinglulu* ``psci_validate_power_state`` 298*91f16700Schasinglulu 299*91f16700Schasinglulu * This function calls a platform specific ``validate_power_state`` handler, 300*91f16700Schasinglulu which takes the ``power_state`` parameter, and updates the ``state_info`` 301*91f16700Schasinglulu object with the requested states for each power level. 302*91f16700Schasinglulu 303*91f16700Schasinglulu* ``psci_find_target_suspend_lvl`` 304*91f16700Schasinglulu 305*91f16700Schasinglulu * This function takes the ``state_info`` object containing the requested power 306*91f16700Schasinglulu states for each power level, and returns the deepest power level that was 307*91f16700Schasinglulu requested to enter a low power state, i.e. the target power level. 308*91f16700Schasinglulu 309*91f16700Schasinglulu* ``psci_do_state_coordination`` 310*91f16700Schasinglulu 311*91f16700Schasinglulu * This function takes the target power level and the ``state_info`` object 312*91f16700Schasinglulu containing the requested power states for each power level, and updates the 313*91f16700Schasinglulu ``state_info`` object with the coordinated target power state for each 314*91f16700Schasinglulu level. 315*91f16700Schasinglulu 316*91f16700Schasinglulu* ``pwr_domain_suspend`` 317*91f16700Schasinglulu 318*91f16700Schasinglulu * This is a platform specific handler that takes the ``state_info`` object 319*91f16700Schasinglulu containing the target power states for each power level, and transitions 320*91f16700Schasinglulu each power level to the specified power state. 321*91f16700Schasinglulu 322*91f16700SchasingluluProposed implementation of OS-initiated mode 323*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 324*91f16700Schasinglulu 325*91f16700SchasingluluTo add support for OS-initiated mode, the following changes are proposed: 326*91f16700Schasinglulu 327*91f16700Schasinglulu* Add a boolean build option ``PSCI_OS_INIT_MODE`` for a platform to enable 328*91f16700Schasinglulu optional support for PSCI OS-initiated mode. This build option defaults to 0. 329*91f16700Schasinglulu 330*91f16700Schasinglulu.. note:: 331*91f16700Schasinglulu 332*91f16700Schasinglulu If ``PSCI_OS_INIT_MODE=0``, the following changes will not be compiled into 333*91f16700Schasinglulu the build. 334*91f16700Schasinglulu 335*91f16700Schasinglulu* Update ``psci_features`` to return 1 in bit[0] to indicate support for 336*91f16700Schasinglulu OS-initiated mode for CPU_SUSPEND. 337*91f16700Schasinglulu* Define a ``suspend_mode`` enum: ``PLAT_COORD`` and ``OS_INIT``. 338*91f16700Schasinglulu* Define a ``psci_suspend_mode`` global variable with a default value of 339*91f16700Schasinglulu ``PLAT_COORD``. 340*91f16700Schasinglulu* Implement a new function handler ``psci_set_suspend_mode`` for 341*91f16700Schasinglulu PSCI_SET_SUSPEND_MODE. 342*91f16700Schasinglulu* Since ``psci_validate_power_state`` calls a platform specific 343*91f16700Schasinglulu ``validate_power_state`` handler, the platform implementation should populate 344*91f16700Schasinglulu the ``state_info`` object based on the state ID from the given ``power_state`` 345*91f16700Schasinglulu parameter. 346*91f16700Schasinglulu* ``psci_find_target_suspend_lvl`` remains unchanged. 347*91f16700Schasinglulu* Implement a new function ``psci_validate_state_coordination`` that ensures the 348*91f16700Schasinglulu request satisfies the following conditions, and denies any requests 349*91f16700Schasinglulu that don't: 350*91f16700Schasinglulu 351*91f16700Schasinglulu * The requested power states for each power level are consistent with the 352*91f16700Schasinglulu system's state 353*91f16700Schasinglulu * The calling core is the last core running at the requested power level 354*91f16700Schasinglulu 355*91f16700Schasinglulu This function differs from ``psci_do_state_coordination`` in that: 356*91f16700Schasinglulu 357*91f16700Schasinglulu * The ``psci_req_local_pwr_states`` map is not modified if the request were to 358*91f16700Schasinglulu be denied 359*91f16700Schasinglulu * The ``state_info`` argument is never modified since it contains the power 360*91f16700Schasinglulu states requested by the calling OS 361*91f16700Schasinglulu 362*91f16700Schasinglulu* Update ``psci_cpu_suspend_start`` to do the following: 363*91f16700Schasinglulu 364*91f16700Schasinglulu * If ``PSCI_SUSPEND_MODE`` is ``PLAT_COORD``, call 365*91f16700Schasinglulu ``psci_do_state_coordination``. 366*91f16700Schasinglulu * If ``PSCI_SUSPEND_MODE`` is ``OS_INIT``, call 367*91f16700Schasinglulu ``psci_validate_state_coordination``. If validation fails, propagate the 368*91f16700Schasinglulu error up the call stack. 369*91f16700Schasinglulu 370*91f16700Schasinglulu* Add a new optional member ``pwr_domain_validate_suspend`` to 371*91f16700Schasinglulu ``plat_psci_ops_t`` to allow the platform to optionally perform validations 372*91f16700Schasinglulu based on hardware states. 373*91f16700Schasinglulu 374*91f16700Schasinglulu* The platform specific ``pwr_domain_suspend`` handler remains unchanged. 375*91f16700Schasinglulu 376*91f16700Schasinglulu.. image:: ../resources/diagrams/psci-osi-mode.png 377*91f16700Schasinglulu 378*91f16700SchasingluluTesting 379*91f16700Schasinglulu------- 380*91f16700Schasinglulu 381*91f16700SchasingluluThe proposed patches can be found at 382*91f16700Schasingluluhttps://review.trustedfirmware.org/q/topic:psci-osi. 383*91f16700Schasinglulu 384*91f16700SchasingluluTesting on FVP and Google platforms 385*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 386*91f16700Schasinglulu 387*91f16700SchasingluluThe proposed patches add a new CPU Suspend in OSI mode test suite to TF-A Tests. 388*91f16700SchasingluluThis has been enabled and verified on the FVP_Base_RevC-2xAEMvA platform and 389*91f16700SchasingluluGoogle platforms, and excluded from all other platforms via the build option 390*91f16700Schasinglulu``PLAT_TESTS_SKIP_LIST``. 391*91f16700Schasinglulu 392*91f16700SchasingluluTesting on STM32MP15 393*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^ 394*91f16700Schasinglulu 395*91f16700SchasingluluThe proposed patches have been tested and verified on the STM32MP15 platform, 396*91f16700Schasingluluwhich has a single cluster with 2 CPUs, by Gabriel Fernandez 397*91f16700Schasinglulu<gabriel.fernandez@st.com> from STMicroelectronics with this device tree 398*91f16700Schasingluluconfiguration: 399*91f16700Schasinglulu 400*91f16700Schasinglulu.. code-block:: devicetree 401*91f16700Schasinglulu 402*91f16700Schasinglulu cpus { 403*91f16700Schasinglulu #address-cells = <1>; 404*91f16700Schasinglulu #size-cells = <0>; 405*91f16700Schasinglulu 406*91f16700Schasinglulu cpu0: cpu@0 { 407*91f16700Schasinglulu device_type = "cpu"; 408*91f16700Schasinglulu compatible = "arm,cortex-a7"; 409*91f16700Schasinglulu reg = <0>; 410*91f16700Schasinglulu enable-method = "psci"; 411*91f16700Schasinglulu power-domains = <&CPU_PD0>; 412*91f16700Schasinglulu power-domain-names = "psci"; 413*91f16700Schasinglulu }; 414*91f16700Schasinglulu cpu1: cpu@1 { 415*91f16700Schasinglulu device_type = "cpu"; 416*91f16700Schasinglulu compatible = "arm,cortex-a7"; 417*91f16700Schasinglulu reg = <1>; 418*91f16700Schasinglulu enable-method = "psci"; 419*91f16700Schasinglulu power-domains = <&CPU_PD1>; 420*91f16700Schasinglulu power-domain-names = "psci"; 421*91f16700Schasinglulu }; 422*91f16700Schasinglulu 423*91f16700Schasinglulu idle-states { 424*91f16700Schasinglulu cpu_retention: cpu-retention { 425*91f16700Schasinglulu compatible = "arm,idle-state"; 426*91f16700Schasinglulu arm,psci-suspend-param = <0x00000001>; 427*91f16700Schasinglulu entry-latency-us = <130>; 428*91f16700Schasinglulu exit-latency-us = <620>; 429*91f16700Schasinglulu min-residency-us = <700>; 430*91f16700Schasinglulu local-timer-stop; 431*91f16700Schasinglulu }; 432*91f16700Schasinglulu }; 433*91f16700Schasinglulu 434*91f16700Schasinglulu domain-idle-states { 435*91f16700Schasinglulu CLUSTER_STOP: core-power-domain { 436*91f16700Schasinglulu compatible = "domain-idle-state"; 437*91f16700Schasinglulu arm,psci-suspend-param = <0x01000001>; 438*91f16700Schasinglulu entry-latency-us = <230>; 439*91f16700Schasinglulu exit-latency-us = <720>; 440*91f16700Schasinglulu min-residency-us = <2000>; 441*91f16700Schasinglulu local-timer-stop; 442*91f16700Schasinglulu }; 443*91f16700Schasinglulu }; 444*91f16700Schasinglulu }; 445*91f16700Schasinglulu 446*91f16700Schasinglulu psci { 447*91f16700Schasinglulu compatible = "arm,psci-1.0"; 448*91f16700Schasinglulu method = "smc"; 449*91f16700Schasinglulu 450*91f16700Schasinglulu CPU_PD0: power-domain-cpu0 { 451*91f16700Schasinglulu #power-domain-cells = <0>; 452*91f16700Schasinglulu power-domains = <&pd_core>; 453*91f16700Schasinglulu domain-idle-states = <&cpu_retention>; 454*91f16700Schasinglulu }; 455*91f16700Schasinglulu 456*91f16700Schasinglulu CPU_PD1: power-domain-cpu1 { 457*91f16700Schasinglulu #power-domain-cells = <0>; 458*91f16700Schasinglulu power-domains = <&pd_core>; 459*91f16700Schasinglulu domain-idle-states = <&cpu_retention>; 460*91f16700Schasinglulu }; 461*91f16700Schasinglulu 462*91f16700Schasinglulu pd_core: power-domain-cluster { 463*91f16700Schasinglulu #power-domain-cells = <0>; 464*91f16700Schasinglulu domain-idle-states = <&CLUSTER_STOP>; 465*91f16700Schasinglulu }; 466*91f16700Schasinglulu }; 467*91f16700Schasinglulu 468*91f16700SchasingluluTesting on Qualcomm SC7280 469*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^^^^^^ 470*91f16700Schasinglulu 471*91f16700SchasingluluThe proposed patches have been tested and verified on the SC7280 platform by 472*91f16700SchasingluluMaulik Shah <quic_mkshah@quicinc.com> from Qualcomm with this device tree 473*91f16700Schasingluluconfiguration: 474*91f16700Schasinglulu 475*91f16700Schasinglulu.. code-block:: devicetree 476*91f16700Schasinglulu 477*91f16700Schasinglulu cpus { 478*91f16700Schasinglulu #address-cells = <2>; 479*91f16700Schasinglulu #size-cells = <0>; 480*91f16700Schasinglulu 481*91f16700Schasinglulu CPU0: cpu@0 { 482*91f16700Schasinglulu device_type = "cpu"; 483*91f16700Schasinglulu compatible = "arm,kryo"; 484*91f16700Schasinglulu reg = <0x0 0x0>; 485*91f16700Schasinglulu enable-method = "psci"; 486*91f16700Schasinglulu power-domains = <&CPU_PD0>; 487*91f16700Schasinglulu power-domain-names = "psci"; 488*91f16700Schasinglulu }; 489*91f16700Schasinglulu 490*91f16700Schasinglulu CPU1: cpu@100 { 491*91f16700Schasinglulu device_type = "cpu"; 492*91f16700Schasinglulu compatible = "arm,kryo"; 493*91f16700Schasinglulu reg = <0x0 0x100>; 494*91f16700Schasinglulu enable-method = "psci"; 495*91f16700Schasinglulu power-domains = <&CPU_PD1>; 496*91f16700Schasinglulu power-domain-names = "psci"; 497*91f16700Schasinglulu }; 498*91f16700Schasinglulu 499*91f16700Schasinglulu CPU2: cpu@200 { 500*91f16700Schasinglulu device_type = "cpu"; 501*91f16700Schasinglulu compatible = "arm,kryo"; 502*91f16700Schasinglulu reg = <0x0 0x200>; 503*91f16700Schasinglulu enable-method = "psci"; 504*91f16700Schasinglulu power-domains = <&CPU_PD2>; 505*91f16700Schasinglulu power-domain-names = "psci"; 506*91f16700Schasinglulu }; 507*91f16700Schasinglulu 508*91f16700Schasinglulu CPU3: cpu@300 { 509*91f16700Schasinglulu device_type = "cpu"; 510*91f16700Schasinglulu compatible = "arm,kryo"; 511*91f16700Schasinglulu reg = <0x0 0x300>; 512*91f16700Schasinglulu enable-method = "psci"; 513*91f16700Schasinglulu power-domains = <&CPU_PD3>; 514*91f16700Schasinglulu power-domain-names = "psci"; 515*91f16700Schasinglulu } 516*91f16700Schasinglulu 517*91f16700Schasinglulu CPU4: cpu@400 { 518*91f16700Schasinglulu device_type = "cpu"; 519*91f16700Schasinglulu compatible = "arm,kryo"; 520*91f16700Schasinglulu reg = <0x0 0x400>; 521*91f16700Schasinglulu enable-method = "psci"; 522*91f16700Schasinglulu power-domains = <&CPU_PD4>; 523*91f16700Schasinglulu power-domain-names = "psci"; 524*91f16700Schasinglulu }; 525*91f16700Schasinglulu 526*91f16700Schasinglulu CPU5: cpu@500 { 527*91f16700Schasinglulu device_type = "cpu"; 528*91f16700Schasinglulu compatible = "arm,kryo"; 529*91f16700Schasinglulu reg = <0x0 0x500>; 530*91f16700Schasinglulu enable-method = "psci"; 531*91f16700Schasinglulu power-domains = <&CPU_PD5>; 532*91f16700Schasinglulu power-domain-names = "psci"; 533*91f16700Schasinglulu }; 534*91f16700Schasinglulu 535*91f16700Schasinglulu CPU6: cpu@600 { 536*91f16700Schasinglulu device_type = "cpu"; 537*91f16700Schasinglulu compatible = "arm,kryo"; 538*91f16700Schasinglulu reg = <0x0 0x600>; 539*91f16700Schasinglulu enable-method = "psci"; 540*91f16700Schasinglulu power-domains = <&CPU_PD6>; 541*91f16700Schasinglulu power-domain-names = "psci"; 542*91f16700Schasinglulu }; 543*91f16700Schasinglulu 544*91f16700Schasinglulu CPU7: cpu@700 { 545*91f16700Schasinglulu device_type = "cpu"; 546*91f16700Schasinglulu compatible = "arm,kryo"; 547*91f16700Schasinglulu reg = <0x0 0x700>; 548*91f16700Schasinglulu enable-method = "psci"; 549*91f16700Schasinglulu power-domains = <&CPU_PD7>; 550*91f16700Schasinglulu power-domain-names = "psci"; 551*91f16700Schasinglulu }; 552*91f16700Schasinglulu 553*91f16700Schasinglulu idle-states { 554*91f16700Schasinglulu entry-method = "psci"; 555*91f16700Schasinglulu 556*91f16700Schasinglulu LITTLE_CPU_SLEEP_0: cpu-sleep-0-0 { 557*91f16700Schasinglulu compatible = "arm,idle-state"; 558*91f16700Schasinglulu idle-state-name = "little-power-down"; 559*91f16700Schasinglulu arm,psci-suspend-param = <0x40000003>; 560*91f16700Schasinglulu entry-latency-us = <549>; 561*91f16700Schasinglulu exit-latency-us = <901>; 562*91f16700Schasinglulu min-residency-us = <1774>; 563*91f16700Schasinglulu local-timer-stop; 564*91f16700Schasinglulu }; 565*91f16700Schasinglulu 566*91f16700Schasinglulu LITTLE_CPU_SLEEP_1: cpu-sleep-0-1 { 567*91f16700Schasinglulu compatible = "arm,idle-state"; 568*91f16700Schasinglulu idle-state-name = "little-rail-power-down"; 569*91f16700Schasinglulu arm,psci-suspend-param = <0x40000004>; 570*91f16700Schasinglulu entry-latency-us = <702>; 571*91f16700Schasinglulu exit-latency-us = <915>; 572*91f16700Schasinglulu min-residency-us = <4001>; 573*91f16700Schasinglulu local-timer-stop; 574*91f16700Schasinglulu }; 575*91f16700Schasinglulu 576*91f16700Schasinglulu BIG_CPU_SLEEP_0: cpu-sleep-1-0 { 577*91f16700Schasinglulu compatible = "arm,idle-state"; 578*91f16700Schasinglulu idle-state-name = "big-power-down"; 579*91f16700Schasinglulu arm,psci-suspend-param = <0x40000003>; 580*91f16700Schasinglulu entry-latency-us = <523>; 581*91f16700Schasinglulu exit-latency-us = <1244>; 582*91f16700Schasinglulu min-residency-us = <2207>; 583*91f16700Schasinglulu local-timer-stop; 584*91f16700Schasinglulu }; 585*91f16700Schasinglulu 586*91f16700Schasinglulu BIG_CPU_SLEEP_1: cpu-sleep-1-1 { 587*91f16700Schasinglulu compatible = "arm,idle-state"; 588*91f16700Schasinglulu idle-state-name = "big-rail-power-down"; 589*91f16700Schasinglulu arm,psci-suspend-param = <0x40000004>; 590*91f16700Schasinglulu entry-latency-us = <526>; 591*91f16700Schasinglulu exit-latency-us = <1854>; 592*91f16700Schasinglulu min-residency-us = <5555>; 593*91f16700Schasinglulu local-timer-stop; 594*91f16700Schasinglulu }; 595*91f16700Schasinglulu }; 596*91f16700Schasinglulu 597*91f16700Schasinglulu domain-idle-states { 598*91f16700Schasinglulu CLUSTER_SLEEP_0: cluster-sleep-0 { 599*91f16700Schasinglulu compatible = "arm,idle-state"; 600*91f16700Schasinglulu idle-state-name = "cluster-power-down"; 601*91f16700Schasinglulu arm,psci-suspend-param = <0x40003444>; 602*91f16700Schasinglulu entry-latency-us = <3263>; 603*91f16700Schasinglulu exit-latency-us = <6562>; 604*91f16700Schasinglulu min-residency-us = <9926>; 605*91f16700Schasinglulu local-timer-stop; 606*91f16700Schasinglulu }; 607*91f16700Schasinglulu }; 608*91f16700Schasinglulu }; 609*91f16700Schasinglulu 610*91f16700Schasinglulu psci { 611*91f16700Schasinglulu compatible = "arm,psci-1.0"; 612*91f16700Schasinglulu method = "smc"; 613*91f16700Schasinglulu 614*91f16700Schasinglulu CPU_PD0: cpu0 { 615*91f16700Schasinglulu #power-domain-cells = <0>; 616*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 617*91f16700Schasinglulu domain-idle-states = <&LITTLE_CPU_SLEEP_0 &LITTLE_CPU_SLEEP_1>; 618*91f16700Schasinglulu }; 619*91f16700Schasinglulu 620*91f16700Schasinglulu CPU_PD1: cpu1 { 621*91f16700Schasinglulu #power-domain-cells = <0>; 622*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 623*91f16700Schasinglulu domain-idle-states = <&LITTLE_CPU_SLEEP_0 &LITTLE_CPU_SLEEP_1>; 624*91f16700Schasinglulu }; 625*91f16700Schasinglulu 626*91f16700Schasinglulu CPU_PD2: cpu2 { 627*91f16700Schasinglulu #power-domain-cells = <0>; 628*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 629*91f16700Schasinglulu domain-idle-states = <&LITTLE_CPU_SLEEP_0 &LITTLE_CPU_SLEEP_1>; 630*91f16700Schasinglulu }; 631*91f16700Schasinglulu 632*91f16700Schasinglulu CPU_PD3: cpu3 { 633*91f16700Schasinglulu #power-domain-cells = <0>; 634*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 635*91f16700Schasinglulu domain-idle-states = <&LITTLE_CPU_SLEEP_0 &LITTLE_CPU_SLEEP_1>; 636*91f16700Schasinglulu }; 637*91f16700Schasinglulu 638*91f16700Schasinglulu CPU_PD4: cpu4 { 639*91f16700Schasinglulu #power-domain-cells = <0>; 640*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 641*91f16700Schasinglulu domain-idle-states = <&BIG_CPU_SLEEP_0 &BIG_CPU_SLEEP_1>; 642*91f16700Schasinglulu }; 643*91f16700Schasinglulu 644*91f16700Schasinglulu CPU_PD5: cpu5 { 645*91f16700Schasinglulu #power-domain-cells = <0>; 646*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 647*91f16700Schasinglulu domain-idle-states = <&BIG_CPU_SLEEP_0 &BIG_CPU_SLEEP_1>; 648*91f16700Schasinglulu }; 649*91f16700Schasinglulu 650*91f16700Schasinglulu CPU_PD6: cpu6 { 651*91f16700Schasinglulu #power-domain-cells = <0>; 652*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 653*91f16700Schasinglulu domain-idle-states = <&BIG_CPU_SLEEP_0 &BIG_CPU_SLEEP_1>; 654*91f16700Schasinglulu }; 655*91f16700Schasinglulu 656*91f16700Schasinglulu CPU_PD7: cpu7 { 657*91f16700Schasinglulu #power-domain-cells = <0>; 658*91f16700Schasinglulu power-domains = <&CLUSTER_PD>; 659*91f16700Schasinglulu domain-idle-states = <&BIG_CPU_SLEEP_0 &BIG_CPU_SLEEP_1>; 660*91f16700Schasinglulu }; 661*91f16700Schasinglulu 662*91f16700Schasinglulu CLUSTER_PD: cpu-cluster0 { 663*91f16700Schasinglulu #power-domain-cells = <0>; 664*91f16700Schasinglulu domain-idle-states = <&CLUSTER_SLEEP_0>; 665*91f16700Schasinglulu }; 666*91f16700Schasinglulu }; 667*91f16700Schasinglulu 668*91f16700SchasingluluComparisons on Qualcomm SC7280 669*91f16700Schasinglulu^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 670*91f16700Schasinglulu 671*91f16700SchasingluluCPUIdle states 672*91f16700Schasinglulu~~~~~~~~~~~~~~ 673*91f16700Schasinglulu 674*91f16700Schasinglulu* 8 CPUs, 1 L3 cache 675*91f16700Schasinglulu* Platform-coordinated mode 676*91f16700Schasinglulu 677*91f16700Schasinglulu * CPUIdle states 678*91f16700Schasinglulu 679*91f16700Schasinglulu * State0 - WFI 680*91f16700Schasinglulu * State1 - Core collapse 681*91f16700Schasinglulu * State2 - Rail collapse 682*91f16700Schasinglulu * State3 - L3 cache off and system resources voted off 683*91f16700Schasinglulu 684*91f16700Schasinglulu* OS-initiated mode 685*91f16700Schasinglulu 686*91f16700Schasinglulu * CPUIdle states 687*91f16700Schasinglulu 688*91f16700Schasinglulu * State0 - WFI 689*91f16700Schasinglulu * State1 - Core collapse 690*91f16700Schasinglulu * State2 - Rail collapse 691*91f16700Schasinglulu 692*91f16700Schasinglulu * Cluster domain idle state 693*91f16700Schasinglulu 694*91f16700Schasinglulu * State3 - L3 cache off and system resources voted off 695*91f16700Schasinglulu 696*91f16700Schasinglulu.. image:: ../resources/diagrams/psci-flattened-vs-hierarchical-idle-states.png 697*91f16700Schasinglulu 698*91f16700SchasingluluResults 699*91f16700Schasinglulu~~~~~~~ 700*91f16700Schasinglulu 701*91f16700Schasinglulu* The following stats have been captured with fixed CPU frequencies from the use 702*91f16700Schasinglulu case of 10 seconds of device idle with the display turned on and Wi-Fi and 703*91f16700Schasinglulu modem turned off. 704*91f16700Schasinglulu* Count refers to the number of times a CPU or cluster entered power collapse. 705*91f16700Schasinglulu* Residency refers to the time in seconds a CPU or cluster stayed in power 706*91f16700Schasinglulu collapse. 707*91f16700Schasinglulu* The results are an average of 3 iterations of actual counts and residencies. 708*91f16700Schasinglulu 709*91f16700Schasinglulu.. image:: ../resources/diagrams/psci-pc-mode-vs-osi-mode.png 710*91f16700Schasinglulu 711*91f16700SchasingluluOS-initiated mode was able to scale better than platform-coordinated mode for 712*91f16700Schasinglulumultiple CPUs. The count and residency results for state3 (i.e. a cluster domain 713*91f16700Schasingluluidle state) in OS-initiated mode for multiple CPUs were much closer to the 714*91f16700Schasingluluresults for a single CPU than in platform-coordinated mode. 715*91f16700Schasinglulu 716*91f16700Schasinglulu-------------- 717*91f16700Schasinglulu 718*91f16700Schasinglulu*Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.* 719