Lines Matching +full:idle +full:- +full:mode +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0-or-later
15 #include <asm/asm-prototypes.h>
21 #include <asm/code-patching.h>
29 /* Power ISA 3.0 allows for stop states 0x0 - 0xF */
54 * psscr value and mask of the deepest stop idle state.
162 * 0 - Workaround applied/undone at fastsleep entry/exit path (Default)
163 * 1 - Workaround applied once, never undone.
182 return -EINVAL; in store_fastsleep_workaround_applyonce()
190 * the cores. Do this by- in store_fastsleep_workaround_applyonce()
218 return -EIO; in store_fastsleep_workaround_applyonce()
230 unsigned long *state = &paca_ptrs[first]->idle_state; in atomic_start_thread_idle()
240 unsigned long *state = &paca_ptrs[first]->idle_state; in atomic_stop_thread_idle()
249 unsigned long *state = &paca_ptrs[first]->idle_state; in atomic_lock_thread_idle()
260 unsigned long *state = &paca_ptrs[first]->idle_state; in atomic_unlock_and_stop_thread_idle()
280 unsigned long *state = &paca_ptrs[first]->idle_state; in atomic_unlock_thread_idle()
316 unsigned long *state = &paca_ptrs[first]->idle_state; in power7_idle_insn()
318 unsigned long core_thread_mask = (1UL << threads_per_core) - 1; in power7_idle_insn()
321 struct p7_sprs sprs = {}; /* avoid false use-uninitialised */ in power7_idle_insn()
384 local_paca->thread_idle_state = type; in power7_idle_insn()
385 srr1 = isa206_idle_insn_mayloss(type); /* go idle */ in power7_idle_insn()
386 local_paca->thread_idle_state = PNV_THREAD_RUNNING; in power7_idle_insn()
412 *state -= 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT; in power7_idle_insn()
428 *state -= 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT; in power7_idle_insn()
441 /* Per-core SPRs */ in power7_idle_insn()
461 if ((*state & local_paca->subcore_sibling_mask) != 0) in power7_idle_insn()
464 /* Per-subcore SPRs */ in power7_idle_insn()
481 /* Per-thread SPRs */ in power7_idle_insn()
492 mtspr(SPRN_SPRG3, local_paca->sprg_vdso); in power7_idle_insn()
514 /* Tell KVM we're entering idle. */ in power7_offline()
518 /* MUST occur in real mode, i.e. with the MMU off, */ in power7_offline()
527 /* hypervisor mode, leading to a host crash or data */ in power7_offline()
530 local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_IDLE; in power7_offline()
538 local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_KERNEL; in power7_offline()
541 if (local_paca->kvm_hstate.hwthread_req) in power7_offline()
609 unsigned long *state = &paca_ptrs[first]->idle_state; in power9_idle_stop()
610 unsigned long core_thread_mask = (1UL << threads_per_core) - 1; in power9_idle_stop()
615 struct p9_sprs sprs = {}; /* avoid false used-uninitialised */ in power9_idle_stop()
627 srr1 = isa300_idle_stop_noloss(psscr); /* go idle */ in power9_idle_stop()
643 local_paca->requested_psscr = psscr; in power9_idle_stop()
646 if (atomic_read(&local_paca->dont_stop)) { in power9_idle_stop()
647 local_paca->requested_psscr = 0; in power9_idle_stop()
656 * after a state-loss idle. Saving and restoring MMCR0 in power9_idle_stop()
657 * over idle is a workaround. in power9_idle_stop()
693 srr1 = isa300_idle_stop_mayloss(psscr); /* go idle */ in power9_idle_stop()
696 local_paca->requested_psscr = 0; in power9_idle_stop()
758 /* Per-core SPRs */ in power9_idle_stop()
779 /* Per-thread SPRs */ in power9_idle_stop()
796 mtspr(SPRN_SPRG3, local_paca->sprg_vdso); in power9_idle_stop()
826 cpu0 = cpu & ~(threads_per_core - 1); in pnv_power9_force_smt4_catch()
829 atomic_inc(&paca_ptrs[cpu0+thr]->dont_stop); in pnv_power9_force_smt4_catch()
834 if (!paca_ptrs[cpu0+thr]->requested_psscr) in pnv_power9_force_smt4_catch()
847 paca_ptrs[cpu0+thr]->hw_cpu_id); in pnv_power9_force_smt4_catch()
854 !paca_ptrs[cpu0+thr]->requested_psscr) { in pnv_power9_force_smt4_catch()
869 cpu0 = cpu & ~(threads_per_core - 1); in pnv_power9_force_smt4_release()
874 atomic_dec(&paca_ptrs[cpu0+thr]->dont_stop); in pnv_power9_force_smt4_release()
885 * isa300 idle routines restore CR, LR.
887 * idle thread doesn't use FP or VEC
898 unsigned long *state = &paca_ptrs[first]->idle_state; in power10_idle_stop()
899 unsigned long core_thread_mask = (1UL << threads_per_core) - 1; in power10_idle_stop()
902 // struct p10_sprs sprs = {}; /* avoid false used-uninitialised */ in power10_idle_stop()
914 srr1 = isa300_idle_stop_noloss(psscr); /* go idle */ in power10_idle_stop()
936 srr1 = isa300_idle_stop_mayloss(psscr); /* go idle */ in power10_idle_stop()
966 /* XXX: restore per-core SPRs here */ in power10_idle_stop()
984 /* XXX: restore per-thread SPRs here */ in power10_idle_stop()
1010 * Tell KVM we're entering idle. in arch300_offline_stop()
1011 * This does not have to be done in real mode because the P9 MMU in arch300_offline_stop()
1012 * is independent per-thread. Some steppings share radix/hash mode in arch300_offline_stop()
1014 * mode before and after switching between radix and hash. in arch300_offline_stop()
1016 * kvm_start_guest must still be called in real mode though, hence in arch300_offline_stop()
1019 local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_IDLE; in arch300_offline_stop()
1028 local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_KERNEL; in arch300_offline_stop()
1031 if (local_paca->kvm_hstate.hwthread_req) in arch300_offline_stop()
1081 * Program the LPCR via stop-api only if the deepest stop state in pnv_program_cpu_hotplug_lpcr()
1090 * available platform idle state on a CPU-Offline.
1125 * Power ISA 3.0 idle initialization.
1128 * Register (PSSCR) to control idle behavior.
1131 * ----------------------------------------------------------
1133 * ----------------------------------------------------------
1137 * Bits 0:3 - Power-Saving Level Status (PLS). This field indicates the
1138 * lowest power-saving state the thread entered since stop instruction was
1141 * Bit 41 - Status Disable(SD)
1142 * 0 - Shows PLS entries
1143 * 1 - PLS entries are all 0
1145 * Bit 42 - Enable State Loss
1146 * 0 - No state is lost irrespective of other fields
1147 * 1 - Allows state loss
1149 * Bit 43 - Exit Criterion
1150 * 0 - Exit from power-save mode on any interrupt
1151 * 1 - Exit from power-save mode controlled by LPCR's PECE bits
1153 * Bits 44:47 - Power-Saving Level Limit
1154 * This limits the power-saving level that can be entered into.
1156 * Bits 60:63 - Requested Level
1157 * Used to specify which power-saving level must be entered on executing
1180 * - ESL bit value matches the EC bit value. in validate_psscr_val_mask()
1181 * - ESL bit is set for all the deep stop states. in validate_psscr_val_mask()
1194 * pnv_arch300_idle_init: Initializes the default idle state, first
1195 * deep idle state and deepest idle state on
1198 * @np: /ibm,opal/power-mgt device node
1199 * @flags: cpu-idle-state-flags array
1200 * @dt_idle_states: Number of idle state entries
1213 * pnv_deepest_stop_{val,mask} should be set to values corresponding to in pnv_arch300_idle_init()
1216 * pnv_default_stop_{val,mask} should be set to values corresponding to in pnv_arch300_idle_init()
1217 * the deepest loss-less (OPAL_PM_STOP_INST_FAST) stop state. in pnv_arch300_idle_init()
1224 u64 psscr_rl = state->psscr_val & PSSCR_RL_MASK; in pnv_arch300_idle_init()
1228 state->flags & (OPAL_PM_TIMEBASE_STOP|OPAL_PM_LOSE_FULL_CONTEXT)) in pnv_arch300_idle_init()
1231 if ((state->flags & OPAL_PM_TIMEBASE_STOP) && in pnv_arch300_idle_init()
1235 if ((state->flags & OPAL_PM_LOSE_FULL_CONTEXT) && in pnv_arch300_idle_init()
1240 * The idle code does not deal with TB loss occurring in pnv_arch300_idle_init()
1247 if ((state->flags & OPAL_PM_TIMEBASE_STOP) && in pnv_arch300_idle_init()
1251 err = validate_psscr_val_mask(&state->psscr_val, in pnv_arch300_idle_init()
1252 &state->psscr_mask, in pnv_arch300_idle_init()
1253 state->flags); in pnv_arch300_idle_init()
1255 report_invalid_psscr_val(state->psscr_val, err); in pnv_arch300_idle_init()
1259 state->valid = true; in pnv_arch300_idle_init()
1261 if (max_residency_ns < state->residency_ns) { in pnv_arch300_idle_init()
1262 max_residency_ns = state->residency_ns; in pnv_arch300_idle_init()
1263 pnv_deepest_stop_psscr_val = state->psscr_val; in pnv_arch300_idle_init()
1264 pnv_deepest_stop_psscr_mask = state->psscr_mask; in pnv_arch300_idle_init()
1265 pnv_deepest_stop_flag = state->flags; in pnv_arch300_idle_init()
1270 (state->flags & OPAL_PM_STOP_INST_FAST)) { in pnv_arch300_idle_init()
1271 pnv_default_stop_val = state->psscr_val; in pnv_arch300_idle_init()
1272 pnv_default_stop_mask = state->psscr_mask; in pnv_arch300_idle_init()
1274 WARN_ON(state->flags & OPAL_PM_LOSE_FULL_CONTEXT); in pnv_arch300_idle_init()
1279 pr_warn("cpuidle-powernv: No suitable default stop state found. Disabling platform idle.\n"); in pnv_arch300_idle_init()
1282 pr_info("cpuidle-powernv: Default stop: psscr = 0x%016llx,mask=0x%016llx\n", in pnv_arch300_idle_init()
1287 pr_warn("cpuidle-powernv: No suitable stop state for CPU-Hotplug. Offlined CPUs will busy wait"); in pnv_arch300_idle_init()
1289 pr_info("cpuidle-powernv: Deepest stop: psscr = 0x%016llx,mask=0x%016llx\n", in pnv_arch300_idle_init()
1294 pr_info("cpuidle-powernv: First stop level that may lose SPRs = 0x%llx\n", in pnv_arch300_idle_init()
1297 pr_info("cpuidle-powernv: First stop level that may lose timebase = 0x%llx\n", in pnv_arch300_idle_init()
1304 * The stop-api is unable to restore hypervisor in pnv_disable_deep_states()
1305 * resources on wakeup from platform idle states which in pnv_disable_deep_states()
1309 pr_warn("cpuidle-powernv: Disabling idle states that lose full context\n"); in pnv_disable_deep_states()
1310 pr_warn("cpuidle-powernv: Idle power-savings, CPU-Hotplug affected\n"); in pnv_disable_deep_states()
1315 * Use the default stop state for CPU-Hotplug in pnv_disable_deep_states()
1321 pr_warn("cpuidle-powernv: Offlined CPUs will stop with psscr = 0x%016llx\n", in pnv_disable_deep_states()
1323 } else { /* Fallback to snooze loop for CPU-Hotplug */ in pnv_disable_deep_states()
1325 pr_warn("cpuidle-powernv: Offlined CPUs will busy wait\n"); in pnv_disable_deep_states()
1331 * Probe device tree for supported idle states
1338 pr_warn("cpuidle-powernv: no idle states found in the DT\n"); in pnv_probe_idle_states()
1350 * This function parses device-tree and populates all the information
1352 * which is the number of cpuidle states discovered through device-tree.
1364 np = of_find_node_by_path("/ibm,opal/power-mgt"); in pnv_parse_cpuidle_dt()
1367 return -ENODEV; in pnv_parse_cpuidle_dt()
1370 "ibm,cpu-idle-state-flags"); in pnv_parse_cpuidle_dt()
1380 rc = -ENOMEM; in pnv_parse_cpuidle_dt()
1385 if (of_property_read_u32_array(np, "ibm,cpu-idle-state-flags", in pnv_parse_cpuidle_dt()
1387 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-flags in DT\n"); in pnv_parse_cpuidle_dt()
1388 rc = -EINVAL; in pnv_parse_cpuidle_dt()
1395 if (of_property_read_u32_array(np, "ibm,cpu-idle-state-latencies-ns", in pnv_parse_cpuidle_dt()
1397 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n"); in pnv_parse_cpuidle_dt()
1398 rc = -EINVAL; in pnv_parse_cpuidle_dt()
1405 if (of_property_read_u32_array(np, "ibm,cpu-idle-state-residency-ns", in pnv_parse_cpuidle_dt()
1407 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-residency-ns in DT\n"); in pnv_parse_cpuidle_dt()
1408 rc = -EINVAL; in pnv_parse_cpuidle_dt()
1417 if (of_property_read_u64_array(np, "ibm,cpu-idle-state-psscr", in pnv_parse_cpuidle_dt()
1419 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr in DT\n"); in pnv_parse_cpuidle_dt()
1420 rc = -EINVAL; in pnv_parse_cpuidle_dt()
1427 if (of_property_read_u64_array(np, "ibm,cpu-idle-state-psscr-mask", in pnv_parse_cpuidle_dt()
1429 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr-mask in DT\n"); in pnv_parse_cpuidle_dt()
1430 rc = -EINVAL; in pnv_parse_cpuidle_dt()
1438 * power8 specific properties ibm,cpu-idle-state-pmicr-mask and in pnv_parse_cpuidle_dt()
1439 * ibm,cpu-idle-state-pmicr-val were never used and there is no in pnv_parse_cpuidle_dt()
1443 if (of_property_read_string_array(np, "ibm,cpu-idle-state-names", in pnv_parse_cpuidle_dt()
1445 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-names in DT\n"); in pnv_parse_cpuidle_dt()
1446 rc = -EINVAL; in pnv_parse_cpuidle_dt()
1470 p->idle_state = 0; in pnv_init_idle_states()
1472 p->idle_state = (1 << threads_per_core) - 1; in pnv_init_idle_states()
1476 p->thread_idle_state = PNV_THREAD_RUNNING; in pnv_init_idle_states()
1480 p->requested_psscr = 0; in pnv_init_idle_states()
1481 atomic_set(&p->dont_stop, 0); in pnv_init_idle_states()