Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 1 | /* |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 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 | #include <arch.h> |
| 32 | #include <arch_helpers.h> |
| 33 | #include <assert.h> |
| 34 | #include <debug.h> |
Soby Mathew | 82dcc03 | 2015-04-08 17:42:06 +0100 | [diff] [blame^] | 35 | #include <platform.h> |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 36 | #include <string.h> |
| 37 | #include "psci_private.h" |
| 38 | |
Soby Mathew | 6590ce2 | 2015-06-30 11:00:24 +0100 | [diff] [blame] | 39 | /****************************************************************************** |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 40 | * Top level handler which is called when a cpu wants to power itself down. |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 41 | * It's assumed that along with turning the cpu power domain off, power |
| 42 | * domains at higher levels will be turned off as far as possible. It finds |
| 43 | * the highest level where a domain has to be powered off by traversing the |
| 44 | * node information and then performs generic, architectural, platform setup |
| 45 | * and state management required to turn OFF that power domain and domains |
| 46 | * below it. e.g. For a cpu that's to be powered OFF, it could mean programming |
| 47 | * the power controller whereas for a cluster that's to be powered off, it will |
| 48 | * call the platform specific code which will disable coherency at the |
| 49 | * interconnect level if the cpu is the last in the cluster and also the |
| 50 | * program the power controller. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 51 | ******************************************************************************/ |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 52 | int psci_do_cpu_off(int end_pwrlvl) |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 53 | { |
Soby Mathew | 82dcc03 | 2015-04-08 17:42:06 +0100 | [diff] [blame^] | 54 | int rc, idx = plat_my_core_pos(); |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 55 | unsigned int max_phys_off_pwrlvl; |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * This function must only be called on platforms where the |
| 59 | * CPU_OFF platform hooks have been implemented. |
| 60 | */ |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 61 | assert(psci_plat_pm_ops->pwr_domain_off); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 62 | |
| 63 | /* |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 64 | * This function acquires the lock corresponding to each power |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 65 | * level so that by the time all locks are taken, the system topology |
| 66 | * is snapshot and state management can be done safely. |
| 67 | */ |
Soby Mathew | 82dcc03 | 2015-04-08 17:42:06 +0100 | [diff] [blame^] | 68 | psci_acquire_pwr_domain_locks(end_pwrlvl, |
| 69 | idx); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Call the cpu off handler registered by the Secure Payload Dispatcher |
| 73 | * to let it do any bookkeeping. Assume that the SPD always reports an |
| 74 | * E_DENIED error if SP refuse to power down |
| 75 | */ |
| 76 | if (psci_spd_pm && psci_spd_pm->svc_off) { |
| 77 | rc = psci_spd_pm->svc_off(0); |
| 78 | if (rc) |
| 79 | goto exit; |
| 80 | } |
| 81 | |
| 82 | /* |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 83 | * This function updates the state of each power domain instance |
Soby Mathew | 82dcc03 | 2015-04-08 17:42:06 +0100 | [diff] [blame^] | 84 | * corresponding to the cpu index in the range of power levels |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 85 | * specified. |
| 86 | */ |
Soby Mathew | 82dcc03 | 2015-04-08 17:42:06 +0100 | [diff] [blame^] | 87 | psci_do_state_coordination(end_pwrlvl, |
| 88 | idx, |
| 89 | PSCI_STATE_OFF); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 90 | |
Soby Mathew | 82dcc03 | 2015-04-08 17:42:06 +0100 | [diff] [blame^] | 91 | max_phys_off_pwrlvl = psci_find_max_phys_off_pwrlvl(end_pwrlvl, idx); |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 92 | assert(max_phys_off_pwrlvl != PSCI_INVALID_DATA); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 93 | |
Soby Mathew | 6590ce2 | 2015-06-30 11:00:24 +0100 | [diff] [blame] | 94 | /* |
| 95 | * Arch. management. Perform the necessary steps to flush all |
| 96 | * cpu caches. |
| 97 | */ |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 98 | psci_do_pwrdown_cache_maintenance(max_phys_off_pwrlvl); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 99 | |
| 100 | /* |
Soby Mathew | 6590ce2 | 2015-06-30 11:00:24 +0100 | [diff] [blame] | 101 | * Plat. management: Perform platform specific actions to turn this |
| 102 | * cpu off e.g. exit cpu coherency, program the power controller etc. |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 103 | */ |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 104 | psci_plat_pm_ops->pwr_domain_off(max_phys_off_pwrlvl); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 105 | |
| 106 | exit: |
| 107 | /* |
Soby Mathew | 4067dc3 | 2015-05-05 16:33:16 +0100 | [diff] [blame] | 108 | * Release the locks corresponding to each power level in the |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 109 | * reverse order to which they were acquired. |
| 110 | */ |
Soby Mathew | 82dcc03 | 2015-04-08 17:42:06 +0100 | [diff] [blame^] | 111 | psci_release_pwr_domain_locks(end_pwrlvl, |
| 112 | idx); |
Soby Mathew | b48349e | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * Check if all actions needed to safely power down this cpu have |
| 116 | * successfully completed. Enter a wfi loop which will allow the |
| 117 | * power controller to physically power down this cpu. |
| 118 | */ |
| 119 | if (rc == PSCI_E_SUCCESS) |
| 120 | psci_power_down_wfi(); |
| 121 | |
| 122 | return rc; |
| 123 | } |