Path: blob/master/arch/powerpc/platforms/powernv/idle.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* PowerNV cpuidle code3*4* Copyright 2015 IBM Corp.5*/67#include <linux/types.h>8#include <linux/mm.h>9#include <linux/slab.h>10#include <linux/of.h>11#include <linux/device.h>12#include <linux/cpu.h>1314#include <asm/firmware.h>15#include <asm/interrupt.h>16#include <asm/machdep.h>17#include <asm/opal.h>18#include <asm/cputhreads.h>19#include <asm/cpuidle.h>20#include <asm/text-patching.h>21#include <asm/smp.h>22#include <asm/runlatch.h>23#include <asm/dbell.h>2425#include "powernv.h"26#include "subcore.h"2728/* Power ISA 3.0 allows for stop states 0x0 - 0xF */29#define MAX_STOP_STATE 0xF3031#define P9_STOP_SPR_MSR 200032#define P9_STOP_SPR_PSSCR 8553334static u32 supported_cpuidle_states;35struct pnv_idle_states_t *pnv_idle_states;36int nr_pnv_idle_states;3738/*39* The default stop state that will be used by ppc_md.power_save40* function on platforms that support stop instruction.41*/42static u64 pnv_default_stop_val;43static u64 pnv_default_stop_mask;44static bool default_stop_found;4546/*47* First stop state levels when SPR and TB loss can occur.48*/49static u64 pnv_first_tb_loss_level = MAX_STOP_STATE + 1;50static u64 deep_spr_loss_state = MAX_STOP_STATE + 1;5152/*53* psscr value and mask of the deepest stop idle state.54* Used when a cpu is offlined.55*/56static u64 pnv_deepest_stop_psscr_val;57static u64 pnv_deepest_stop_psscr_mask;58static u64 pnv_deepest_stop_flag;59static bool deepest_stop_found;6061static unsigned long power7_offline_type;6263static int __init pnv_save_sprs_for_deep_states(void)64{65int cpu;66int rc;6768/*69* hid0, hid1, hid4, hid5, hmeer and lpcr values are symmetric across70* all cpus at boot. Get these reg values of current cpu and use the71* same across all cpus.72*/73uint64_t lpcr_val = mfspr(SPRN_LPCR);74uint64_t hid0_val = mfspr(SPRN_HID0);75uint64_t hmeer_val = mfspr(SPRN_HMEER);76uint64_t msr_val = MSR_IDLE;77uint64_t psscr_val = pnv_deepest_stop_psscr_val;7879for_each_present_cpu(cpu) {80uint64_t pir = get_hard_smp_processor_id(cpu);81uint64_t hsprg0_val = (uint64_t)paca_ptrs[cpu];8283rc = opal_slw_set_reg(pir, SPRN_HSPRG0, hsprg0_val);84if (rc != 0)85return rc;8687rc = opal_slw_set_reg(pir, SPRN_LPCR, lpcr_val);88if (rc != 0)89return rc;9091if (cpu_has_feature(CPU_FTR_ARCH_300)) {92rc = opal_slw_set_reg(pir, P9_STOP_SPR_MSR, msr_val);93if (rc)94return rc;9596rc = opal_slw_set_reg(pir,97P9_STOP_SPR_PSSCR, psscr_val);9899if (rc)100return rc;101}102103/* HIDs are per core registers */104if (cpu_thread_in_core(cpu) == 0) {105106rc = opal_slw_set_reg(pir, SPRN_HMEER, hmeer_val);107if (rc != 0)108return rc;109110rc = opal_slw_set_reg(pir, SPRN_HID0, hid0_val);111if (rc != 0)112return rc;113114/* Only p8 needs to set extra HID registers */115if (!cpu_has_feature(CPU_FTR_ARCH_300)) {116uint64_t hid1_val = mfspr(SPRN_HID1);117uint64_t hid4_val = mfspr(SPRN_HID4);118uint64_t hid5_val = mfspr(SPRN_HID5);119120rc = opal_slw_set_reg(pir, SPRN_HID1, hid1_val);121if (rc != 0)122return rc;123124rc = opal_slw_set_reg(pir, SPRN_HID4, hid4_val);125if (rc != 0)126return rc;127128rc = opal_slw_set_reg(pir, SPRN_HID5, hid5_val);129if (rc != 0)130return rc;131}132}133}134135return 0;136}137138u32 pnv_get_supported_cpuidle_states(void)139{140return supported_cpuidle_states;141}142EXPORT_SYMBOL_GPL(pnv_get_supported_cpuidle_states);143144static void pnv_fastsleep_workaround_apply(void *info)145146{147int cpu = smp_processor_id();148int rc;149int *err = info;150151if (cpu_first_thread_sibling(cpu) != cpu)152return;153154rc = opal_config_cpu_idle_state(OPAL_CONFIG_IDLE_FASTSLEEP,155OPAL_CONFIG_IDLE_APPLY);156if (rc)157*err = 1;158}159160static bool power7_fastsleep_workaround_entry = true;161static bool power7_fastsleep_workaround_exit = true;162163/*164* Used to store fastsleep workaround state165* 0 - Workaround applied/undone at fastsleep entry/exit path (Default)166* 1 - Workaround applied once, never undone.167*/168static u8 fastsleep_workaround_applyonce;169170static ssize_t show_fastsleep_workaround_applyonce(struct device *dev,171struct device_attribute *attr, char *buf)172{173return sprintf(buf, "%u\n", fastsleep_workaround_applyonce);174}175176static ssize_t store_fastsleep_workaround_applyonce(struct device *dev,177struct device_attribute *attr, const char *buf,178size_t count)179{180int err;181u8 val;182183if (kstrtou8(buf, 0, &val) || val != 1)184return -EINVAL;185186if (fastsleep_workaround_applyonce == 1)187return count;188189/*190* fastsleep_workaround_applyonce = 1 implies191* fastsleep workaround needs to be left in 'applied' state on all192* the cores. Do this by-193* 1. Disable the 'undo' workaround in fastsleep exit path194* 2. Sendi IPIs to all the cores which have at least one online thread195* 3. Disable the 'apply' workaround in fastsleep entry path196*197* There is no need to send ipi to cores which have all threads198* offlined, as last thread of the core entering fastsleep or deeper199* state would have applied workaround.200*/201power7_fastsleep_workaround_exit = false;202203cpus_read_lock();204on_each_cpu(pnv_fastsleep_workaround_apply, &err, 1);205cpus_read_unlock();206if (err) {207pr_err("fastsleep_workaround_applyonce change failed while running pnv_fastsleep_workaround_apply");208goto fail;209}210211power7_fastsleep_workaround_entry = false;212213fastsleep_workaround_applyonce = 1;214215return count;216fail:217return -EIO;218}219220static DEVICE_ATTR(fastsleep_workaround_applyonce, 0600,221show_fastsleep_workaround_applyonce,222store_fastsleep_workaround_applyonce);223224static inline void atomic_start_thread_idle(void)225{226int cpu = raw_smp_processor_id();227int first = cpu_first_thread_sibling(cpu);228int thread_nr = cpu_thread_in_core(cpu);229unsigned long *state = &paca_ptrs[first]->idle_state;230231clear_bit(thread_nr, state);232}233234static inline void atomic_stop_thread_idle(void)235{236int cpu = raw_smp_processor_id();237int first = cpu_first_thread_sibling(cpu);238int thread_nr = cpu_thread_in_core(cpu);239unsigned long *state = &paca_ptrs[first]->idle_state;240241set_bit(thread_nr, state);242}243244static inline void atomic_lock_thread_idle(void)245{246int cpu = raw_smp_processor_id();247int first = cpu_first_thread_sibling(cpu);248unsigned long *lock = &paca_ptrs[first]->idle_lock;249250while (unlikely(test_and_set_bit_lock(NR_PNV_CORE_IDLE_LOCK_BIT, lock)))251barrier();252}253254static inline void atomic_unlock_and_stop_thread_idle(void)255{256int cpu = raw_smp_processor_id();257int first = cpu_first_thread_sibling(cpu);258unsigned long thread = 1UL << cpu_thread_in_core(cpu);259unsigned long *state = &paca_ptrs[first]->idle_state;260unsigned long *lock = &paca_ptrs[first]->idle_lock;261u64 s = READ_ONCE(*state);262u64 new, tmp;263264BUG_ON(!(READ_ONCE(*lock) & PNV_CORE_IDLE_LOCK_BIT));265BUG_ON(s & thread);266267again:268new = s | thread;269tmp = cmpxchg(state, s, new);270if (unlikely(tmp != s)) {271s = tmp;272goto again;273}274clear_bit_unlock(NR_PNV_CORE_IDLE_LOCK_BIT, lock);275}276277static inline void atomic_unlock_thread_idle(void)278{279int cpu = raw_smp_processor_id();280int first = cpu_first_thread_sibling(cpu);281unsigned long *lock = &paca_ptrs[first]->idle_lock;282283BUG_ON(!test_bit(NR_PNV_CORE_IDLE_LOCK_BIT, lock));284clear_bit_unlock(NR_PNV_CORE_IDLE_LOCK_BIT, lock);285}286287/* P7 and P8 */288struct p7_sprs {289/* per core */290u64 tscr;291u64 worc;292293/* per subcore */294u64 sdr1;295u64 rpr;296297/* per thread */298u64 lpcr;299u64 hfscr;300u64 fscr;301u64 purr;302u64 spurr;303u64 dscr;304u64 wort;305306/* per thread SPRs that get lost in shallow states */307u64 amr;308u64 iamr;309u64 uamor;310/* amor is restored to constant ~0 */311};312313static unsigned long power7_idle_insn(unsigned long type)314{315int cpu = raw_smp_processor_id();316int first = cpu_first_thread_sibling(cpu);317unsigned long *state = &paca_ptrs[first]->idle_state;318unsigned long thread = 1UL << cpu_thread_in_core(cpu);319unsigned long core_thread_mask = (1UL << threads_per_core) - 1;320unsigned long srr1;321bool full_winkle;322struct p7_sprs sprs = {}; /* avoid false use-uninitialised */323bool sprs_saved = false;324int rc;325326if (unlikely(type != PNV_THREAD_NAP)) {327atomic_lock_thread_idle();328329BUG_ON(!(*state & thread));330*state &= ~thread;331332if (power7_fastsleep_workaround_entry) {333if ((*state & core_thread_mask) == 0) {334rc = opal_config_cpu_idle_state(335OPAL_CONFIG_IDLE_FASTSLEEP,336OPAL_CONFIG_IDLE_APPLY);337BUG_ON(rc);338}339}340341if (type == PNV_THREAD_WINKLE) {342sprs.tscr = mfspr(SPRN_TSCR);343sprs.worc = mfspr(SPRN_WORC);344345sprs.sdr1 = mfspr(SPRN_SDR1);346sprs.rpr = mfspr(SPRN_RPR);347348sprs.lpcr = mfspr(SPRN_LPCR);349if (cpu_has_feature(CPU_FTR_ARCH_207S)) {350sprs.hfscr = mfspr(SPRN_HFSCR);351sprs.fscr = mfspr(SPRN_FSCR);352}353sprs.purr = mfspr(SPRN_PURR);354sprs.spurr = mfspr(SPRN_SPURR);355sprs.dscr = mfspr(SPRN_DSCR);356sprs.wort = mfspr(SPRN_WORT);357358sprs_saved = true;359360/*361* Increment winkle counter and set all winkle bits if362* all threads are winkling. This allows wakeup side to363* distinguish between fast sleep and winkle state364* loss. Fast sleep still has to resync the timebase so365* this may not be a really big win.366*/367*state += 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT;368if ((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS)369>> PNV_CORE_IDLE_WINKLE_COUNT_SHIFT370== threads_per_core)371*state |= PNV_CORE_IDLE_THREAD_WINKLE_BITS;372WARN_ON((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS) == 0);373}374375atomic_unlock_thread_idle();376}377378if (cpu_has_feature(CPU_FTR_ARCH_207S)) {379sprs.amr = mfspr(SPRN_AMR);380sprs.iamr = mfspr(SPRN_IAMR);381sprs.uamor = mfspr(SPRN_UAMOR);382}383384local_paca->thread_idle_state = type;385srr1 = isa206_idle_insn_mayloss(type); /* go idle */386local_paca->thread_idle_state = PNV_THREAD_RUNNING;387388WARN_ON_ONCE(!srr1);389WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));390391if (cpu_has_feature(CPU_FTR_ARCH_207S)) {392if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {393/*394* We don't need an isync after the mtsprs here because395* the upcoming mtmsrd is execution synchronizing.396*/397mtspr(SPRN_AMR, sprs.amr);398mtspr(SPRN_IAMR, sprs.iamr);399mtspr(SPRN_AMOR, ~0);400mtspr(SPRN_UAMOR, sprs.uamor);401}402}403404if (unlikely((srr1 & SRR1_WAKEMASK_P8) == SRR1_WAKEHMI))405hmi_exception_realmode(NULL);406407if (likely((srr1 & SRR1_WAKESTATE) != SRR1_WS_HVLOSS)) {408if (unlikely(type != PNV_THREAD_NAP)) {409atomic_lock_thread_idle();410if (type == PNV_THREAD_WINKLE) {411WARN_ON((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS) == 0);412*state -= 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT;413*state &= ~(thread << PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT);414}415atomic_unlock_and_stop_thread_idle();416}417return srr1;418}419420/* HV state loss */421BUG_ON(type == PNV_THREAD_NAP);422423atomic_lock_thread_idle();424425full_winkle = false;426if (type == PNV_THREAD_WINKLE) {427WARN_ON((*state & PNV_CORE_IDLE_WINKLE_COUNT_BITS) == 0);428*state -= 1 << PNV_CORE_IDLE_WINKLE_COUNT_SHIFT;429if (*state & (thread << PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT)) {430*state &= ~(thread << PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT);431full_winkle = true;432BUG_ON(!sprs_saved);433}434}435436WARN_ON(*state & thread);437438if ((*state & core_thread_mask) != 0)439goto core_woken;440441/* Per-core SPRs */442if (full_winkle) {443mtspr(SPRN_TSCR, sprs.tscr);444mtspr(SPRN_WORC, sprs.worc);445}446447if (power7_fastsleep_workaround_exit) {448rc = opal_config_cpu_idle_state(OPAL_CONFIG_IDLE_FASTSLEEP,449OPAL_CONFIG_IDLE_UNDO);450BUG_ON(rc);451}452453/* TB */454if (opal_resync_timebase() != OPAL_SUCCESS)455BUG();456457core_woken:458if (!full_winkle)459goto subcore_woken;460461if ((*state & local_paca->subcore_sibling_mask) != 0)462goto subcore_woken;463464/* Per-subcore SPRs */465mtspr(SPRN_SDR1, sprs.sdr1);466mtspr(SPRN_RPR, sprs.rpr);467468subcore_woken:469/*470* isync after restoring shared SPRs and before unlocking. Unlock471* only contains hwsync which does not necessarily do the right472* thing for SPRs.473*/474isync();475atomic_unlock_and_stop_thread_idle();476477/* Fast sleep does not lose SPRs */478if (!full_winkle)479return srr1;480481/* Per-thread SPRs */482mtspr(SPRN_LPCR, sprs.lpcr);483if (cpu_has_feature(CPU_FTR_ARCH_207S)) {484mtspr(SPRN_HFSCR, sprs.hfscr);485mtspr(SPRN_FSCR, sprs.fscr);486}487mtspr(SPRN_PURR, sprs.purr);488mtspr(SPRN_SPURR, sprs.spurr);489mtspr(SPRN_DSCR, sprs.dscr);490mtspr(SPRN_WORT, sprs.wort);491492mtspr(SPRN_SPRG3, local_paca->sprg_vdso);493494#ifdef CONFIG_PPC_64S_HASH_MMU495/*496* The SLB has to be restored here, but it sometimes still497* contains entries, so the __ variant must be used to prevent498* multi hits.499*/500__slb_restore_bolted_realmode();501#endif502503return srr1;504}505506extern unsigned long idle_kvm_start_guest(unsigned long srr1);507508#ifdef CONFIG_HOTPLUG_CPU509static unsigned long power7_offline(void)510{511unsigned long srr1;512513mtmsr(MSR_IDLE);514515#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE516/* Tell KVM we're entering idle. */517/******************************************************/518/* N O T E W E L L ! ! ! N O T E W E L L */519/* The following store to HSTATE_HWTHREAD_STATE(r13) */520/* MUST occur in real mode, i.e. with the MMU off, */521/* and the MMU must stay off until we clear this flag */522/* and test HSTATE_HWTHREAD_REQ(r13) in */523/* pnv_powersave_wakeup in this file. */524/* The reason is that another thread can switch the */525/* MMU to a guest context whenever this flag is set */526/* to KVM_HWTHREAD_IN_IDLE, and if the MMU was on, */527/* that would potentially cause this thread to start */528/* executing instructions from guest memory in */529/* hypervisor mode, leading to a host crash or data */530/* corruption, or worse. */531/******************************************************/532local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_IDLE;533#endif534535__ppc64_runlatch_off();536srr1 = power7_idle_insn(power7_offline_type);537__ppc64_runlatch_on();538539#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE540local_paca->kvm_hstate.hwthread_state = KVM_HWTHREAD_IN_KERNEL;541/* Order setting hwthread_state vs. testing hwthread_req */542smp_mb();543if (local_paca->kvm_hstate.hwthread_req)544srr1 = idle_kvm_start_guest(srr1);545#endif546547mtmsr(MSR_KERNEL);548549return srr1;550}551#endif552553void power7_idle_type(unsigned long type)554{555unsigned long srr1;556557if (!prep_irq_for_idle_irqsoff())558return;559560mtmsr(MSR_IDLE);561__ppc64_runlatch_off();562srr1 = power7_idle_insn(type);563__ppc64_runlatch_on();564mtmsr(MSR_KERNEL);565566fini_irq_for_idle_irqsoff();567irq_set_pending_from_srr1(srr1);568}569570static void power7_idle(void)571{572if (!powersave_nap)573return;574575power7_idle_type(PNV_THREAD_NAP);576}577578struct p9_sprs {579/* per core */580u64 ptcr;581u64 rpr;582u64 tscr;583u64 ldbar;584585/* per thread */586u64 lpcr;587u64 hfscr;588u64 fscr;589u64 pid;590u64 purr;591u64 spurr;592u64 dscr;593u64 ciabr;594595u64 mmcra;596u32 mmcr0;597u32 mmcr1;598u64 mmcr2;599600/* per thread SPRs that get lost in shallow states */601u64 amr;602u64 iamr;603u64 amor;604u64 uamor;605};606607static unsigned long power9_idle_stop(unsigned long psscr)608{609int cpu = raw_smp_processor_id();610int first = cpu_first_thread_sibling(cpu);611unsigned long *state = &paca_ptrs[first]->idle_state;612unsigned long core_thread_mask = (1UL << threads_per_core) - 1;613unsigned long srr1;614unsigned long pls;615unsigned long mmcr0 = 0;616unsigned long mmcra = 0;617struct p9_sprs sprs = {}; /* avoid false used-uninitialised */618bool sprs_saved = false;619620if (!(psscr & (PSSCR_EC|PSSCR_ESL))) {621/* EC=ESL=0 case */622623/*624* Wake synchronously. SRESET via xscom may still cause625* a 0x100 powersave wakeup with SRR1 reason!626*/627srr1 = isa300_idle_stop_noloss(psscr); /* go idle */628if (likely(!srr1))629return 0;630631/*632* Registers not saved, can't recover!633* This would be a hardware bug634*/635BUG_ON((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS);636637goto out;638}639640/* EC=ESL=1 case */641#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE642if (cpu_has_feature(CPU_FTR_P9_TM_XER_SO_BUG)) {643local_paca->requested_psscr = psscr;644/* order setting requested_psscr vs testing dont_stop */645smp_mb();646if (atomic_read(&local_paca->dont_stop)) {647local_paca->requested_psscr = 0;648return 0;649}650}651#endif652653if (!cpu_has_feature(CPU_FTR_POWER9_DD2_1)) {654/*655* POWER9 DD2 can incorrectly set PMAO when waking up656* after a state-loss idle. Saving and restoring MMCR0657* over idle is a workaround.658*/659mmcr0 = mfspr(SPRN_MMCR0);660}661662if ((psscr & PSSCR_RL_MASK) >= deep_spr_loss_state) {663sprs.lpcr = mfspr(SPRN_LPCR);664sprs.hfscr = mfspr(SPRN_HFSCR);665sprs.fscr = mfspr(SPRN_FSCR);666sprs.pid = mfspr(SPRN_PID);667sprs.purr = mfspr(SPRN_PURR);668sprs.spurr = mfspr(SPRN_SPURR);669sprs.dscr = mfspr(SPRN_DSCR);670sprs.ciabr = mfspr(SPRN_CIABR);671672sprs.mmcra = mfspr(SPRN_MMCRA);673sprs.mmcr0 = mfspr(SPRN_MMCR0);674sprs.mmcr1 = mfspr(SPRN_MMCR1);675sprs.mmcr2 = mfspr(SPRN_MMCR2);676677sprs.ptcr = mfspr(SPRN_PTCR);678sprs.rpr = mfspr(SPRN_RPR);679sprs.tscr = mfspr(SPRN_TSCR);680if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))681sprs.ldbar = mfspr(SPRN_LDBAR);682683sprs_saved = true;684685atomic_start_thread_idle();686}687688sprs.amr = mfspr(SPRN_AMR);689sprs.iamr = mfspr(SPRN_IAMR);690sprs.uamor = mfspr(SPRN_UAMOR);691692srr1 = isa300_idle_stop_mayloss(psscr); /* go idle */693694#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE695local_paca->requested_psscr = 0;696#endif697698psscr = mfspr(SPRN_PSSCR);699700WARN_ON_ONCE(!srr1);701WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));702703if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {704/*705* We don't need an isync after the mtsprs here because the706* upcoming mtmsrd is execution synchronizing.707*/708mtspr(SPRN_AMR, sprs.amr);709mtspr(SPRN_IAMR, sprs.iamr);710mtspr(SPRN_AMOR, ~0);711mtspr(SPRN_UAMOR, sprs.uamor);712713/*714* Workaround for POWER9 DD2.0, if we lost resources, the ERAT715* might have been corrupted and needs flushing. We also need716* to reload MMCR0 (see mmcr0 comment above).717*/718if (!cpu_has_feature(CPU_FTR_POWER9_DD2_1)) {719asm volatile(PPC_ISA_3_0_INVALIDATE_ERAT);720mtspr(SPRN_MMCR0, mmcr0);721}722723/*724* DD2.2 and earlier need to set then clear bit 60 in MMCRA725* to ensure the PMU starts running.726*/727mmcra = mfspr(SPRN_MMCRA);728mmcra |= PPC_BIT(60);729mtspr(SPRN_MMCRA, mmcra);730mmcra &= ~PPC_BIT(60);731mtspr(SPRN_MMCRA, mmcra);732}733734if (unlikely((srr1 & SRR1_WAKEMASK_P8) == SRR1_WAKEHMI))735hmi_exception_realmode(NULL);736737/*738* On POWER9, SRR1 bits do not match exactly as expected.739* SRR1_WS_GPRLOSS (10b) can also result in SPR loss, so740* just always test PSSCR for SPR/TB state loss.741*/742pls = (psscr & PSSCR_PLS) >> PSSCR_PLS_SHIFT;743if (likely(pls < deep_spr_loss_state)) {744if (sprs_saved)745atomic_stop_thread_idle();746goto out;747}748749/* HV state loss */750BUG_ON(!sprs_saved);751752atomic_lock_thread_idle();753754if ((*state & core_thread_mask) != 0)755goto core_woken;756757/* Per-core SPRs */758mtspr(SPRN_PTCR, sprs.ptcr);759mtspr(SPRN_RPR, sprs.rpr);760mtspr(SPRN_TSCR, sprs.tscr);761762if (pls >= pnv_first_tb_loss_level) {763/* TB loss */764if (opal_resync_timebase() != OPAL_SUCCESS)765BUG();766}767768/*769* isync after restoring shared SPRs and before unlocking. Unlock770* only contains hwsync which does not necessarily do the right771* thing for SPRs.772*/773isync();774775core_woken:776atomic_unlock_and_stop_thread_idle();777778/* Per-thread SPRs */779mtspr(SPRN_LPCR, sprs.lpcr);780mtspr(SPRN_HFSCR, sprs.hfscr);781mtspr(SPRN_FSCR, sprs.fscr);782mtspr(SPRN_PID, sprs.pid);783mtspr(SPRN_PURR, sprs.purr);784mtspr(SPRN_SPURR, sprs.spurr);785mtspr(SPRN_DSCR, sprs.dscr);786mtspr(SPRN_CIABR, sprs.ciabr);787788mtspr(SPRN_MMCRA, sprs.mmcra);789mtspr(SPRN_MMCR0, sprs.mmcr0);790mtspr(SPRN_MMCR1, sprs.mmcr1);791mtspr(SPRN_MMCR2, sprs.mmcr2);792if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))793mtspr(SPRN_LDBAR, sprs.ldbar);794795mtspr(SPRN_SPRG3, local_paca->sprg_vdso);796797if (!radix_enabled())798__slb_restore_bolted_realmode();799800out:801mtmsr(MSR_KERNEL);802803return srr1;804}805806#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE807/*808* This is used in working around bugs in thread reconfiguration809* on POWER9 (at least up to Nimbus DD2.2) relating to transactional810* memory and the way that XER[SO] is checkpointed.811* This function forces the core into SMT4 in order by asking812* all other threads not to stop, and sending a message to any813* that are in a stop state.814* Must be called with preemption disabled.815*/816void pnv_power9_force_smt4_catch(void)817{818int cpu, cpu0, thr;819int awake_threads = 1; /* this thread is awake */820int poke_threads = 0;821int need_awake = threads_per_core;822823cpu = smp_processor_id();824cpu0 = cpu & ~(threads_per_core - 1);825for (thr = 0; thr < threads_per_core; ++thr) {826if (cpu != cpu0 + thr)827atomic_inc(&paca_ptrs[cpu0+thr]->dont_stop);828}829/* order setting dont_stop vs testing requested_psscr */830smp_mb();831for (thr = 0; thr < threads_per_core; ++thr) {832if (!paca_ptrs[cpu0+thr]->requested_psscr)833++awake_threads;834else835poke_threads |= (1 << thr);836}837838/* If at least 3 threads are awake, the core is in SMT4 already */839if (awake_threads < need_awake) {840/* We have to wake some threads; we'll use msgsnd */841for (thr = 0; thr < threads_per_core; ++thr) {842if (poke_threads & (1 << thr)) {843ppc_msgsnd_sync();844ppc_msgsnd(PPC_DBELL_MSGTYPE, 0,845paca_ptrs[cpu0+thr]->hw_cpu_id);846}847}848/* now spin until at least 3 threads are awake */849do {850for (thr = 0; thr < threads_per_core; ++thr) {851if ((poke_threads & (1 << thr)) &&852!paca_ptrs[cpu0+thr]->requested_psscr) {853++awake_threads;854poke_threads &= ~(1 << thr);855}856}857} while (awake_threads < need_awake);858}859}860EXPORT_SYMBOL_GPL(pnv_power9_force_smt4_catch);861862void pnv_power9_force_smt4_release(void)863{864int cpu, cpu0, thr;865866cpu = smp_processor_id();867cpu0 = cpu & ~(threads_per_core - 1);868869/* clear all the dont_stop flags */870for (thr = 0; thr < threads_per_core; ++thr) {871if (cpu != cpu0 + thr)872atomic_dec(&paca_ptrs[cpu0+thr]->dont_stop);873}874}875EXPORT_SYMBOL_GPL(pnv_power9_force_smt4_release);876#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */877878struct p10_sprs {879/*880* SPRs that get lost in shallow states:881*882* P10 loses CR, LR, CTR, FPSCR, VSCR, XER, TAR, SPRG2, and HSPRG1883* isa300 idle routines restore CR, LR.884* CTR is volatile885* idle thread doesn't use FP or VEC886* kernel doesn't use TAR887* HSPRG1 is only live in HV interrupt entry888* SPRG2 is only live in KVM guests, KVM handles it.889*/890};891892static unsigned long power10_idle_stop(unsigned long psscr)893{894int cpu = raw_smp_processor_id();895int first = cpu_first_thread_sibling(cpu);896unsigned long *state = &paca_ptrs[first]->idle_state;897unsigned long core_thread_mask = (1UL << threads_per_core) - 1;898unsigned long srr1;899unsigned long pls;900// struct p10_sprs sprs = {}; /* avoid false used-uninitialised */901bool sprs_saved = false;902903if (!(psscr & (PSSCR_EC|PSSCR_ESL))) {904/* EC=ESL=0 case */905906/*907* Wake synchronously. SRESET via xscom may still cause908* a 0x100 powersave wakeup with SRR1 reason!909*/910srr1 = isa300_idle_stop_noloss(psscr); /* go idle */911if (likely(!srr1))912return 0;913914/*915* Registers not saved, can't recover!916* This would be a hardware bug917*/918BUG_ON((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS);919920goto out;921}922923/* EC=ESL=1 case */924if ((psscr & PSSCR_RL_MASK) >= deep_spr_loss_state) {925/* XXX: save SPRs for deep state loss here. */926927sprs_saved = true;928929atomic_start_thread_idle();930}931932srr1 = isa300_idle_stop_mayloss(psscr); /* go idle */933934psscr = mfspr(SPRN_PSSCR);935936WARN_ON_ONCE(!srr1);937WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));938939if (unlikely((srr1 & SRR1_WAKEMASK_P8) == SRR1_WAKEHMI))940hmi_exception_realmode(NULL);941942/*943* On POWER10, SRR1 bits do not match exactly as expected.944* SRR1_WS_GPRLOSS (10b) can also result in SPR loss, so945* just always test PSSCR for SPR/TB state loss.946*/947pls = (psscr & PSSCR_PLS) >> PSSCR_PLS_SHIFT;948if (likely(pls < deep_spr_loss_state)) {949if (sprs_saved)950atomic_stop_thread_idle();951goto out;952}953954/* HV state loss */955BUG_ON(!sprs_saved);956957atomic_lock_thread_idle();958959if ((*state & core_thread_mask) != 0)960goto core_woken;961962/* XXX: restore per-core SPRs here */963964if (pls >= pnv_first_tb_loss_level) {965/* TB loss */966if (opal_resync_timebase() != OPAL_SUCCESS)967BUG();968}969970/*971* isync after restoring shared SPRs and before unlocking. Unlock972* only contains hwsync which does not necessarily do the right973* thing for SPRs.974*/975isync();976977core_woken:978atomic_unlock_and_stop_thread_idle();979980/* XXX: restore per-thread SPRs here */981982if (!radix_enabled())983__slb_restore_bolted_realmode();984985out:986mtmsr(MSR_KERNEL);987988return srr1;989}990991#ifdef CONFIG_HOTPLUG_CPU992static unsigned long arch300_offline_stop(unsigned long psscr)993{994unsigned long srr1;995996if (cpu_has_feature(CPU_FTR_ARCH_31))997srr1 = power10_idle_stop(psscr);998else999srr1 = power9_idle_stop(psscr);10001001return srr1;1002}1003#endif10041005void arch300_idle_type(unsigned long stop_psscr_val,1006unsigned long stop_psscr_mask)1007{1008unsigned long psscr;1009unsigned long srr1;10101011if (!prep_irq_for_idle_irqsoff())1012return;10131014psscr = mfspr(SPRN_PSSCR);1015psscr = (psscr & ~stop_psscr_mask) | stop_psscr_val;10161017__ppc64_runlatch_off();1018if (cpu_has_feature(CPU_FTR_ARCH_31))1019srr1 = power10_idle_stop(psscr);1020else1021srr1 = power9_idle_stop(psscr);1022__ppc64_runlatch_on();10231024fini_irq_for_idle_irqsoff();10251026irq_set_pending_from_srr1(srr1);1027}10281029/*1030* Used for ppc_md.power_save which needs a function with no parameters1031*/1032static void arch300_idle(void)1033{1034arch300_idle_type(pnv_default_stop_val, pnv_default_stop_mask);1035}10361037#ifdef CONFIG_HOTPLUG_CPU10381039void pnv_program_cpu_hotplug_lpcr(unsigned int cpu, u64 lpcr_val)1040{1041u64 pir = get_hard_smp_processor_id(cpu);10421043mtspr(SPRN_LPCR, lpcr_val);10441045/*1046* Program the LPCR via stop-api only if the deepest stop state1047* can lose hypervisor context.1048*/1049if (supported_cpuidle_states & OPAL_PM_LOSE_FULL_CONTEXT)1050opal_slw_set_reg(pir, SPRN_LPCR, lpcr_val);1051}10521053/*1054* pnv_cpu_offline: A function that puts the CPU into the deepest1055* available platform idle state on a CPU-Offline.1056* interrupts hard disabled and no lazy irq pending.1057*/1058unsigned long pnv_cpu_offline(unsigned int cpu)1059{1060unsigned long srr1;10611062__ppc64_runlatch_off();10631064if (cpu_has_feature(CPU_FTR_ARCH_300) && deepest_stop_found) {1065unsigned long psscr;10661067psscr = mfspr(SPRN_PSSCR);1068psscr = (psscr & ~pnv_deepest_stop_psscr_mask) |1069pnv_deepest_stop_psscr_val;1070srr1 = arch300_offline_stop(psscr);1071} else if (cpu_has_feature(CPU_FTR_ARCH_206) && power7_offline_type) {1072srr1 = power7_offline();1073} else {1074/* This is the fallback method. We emulate snooze */1075while (!generic_check_cpu_restart(cpu)) {1076HMT_low();1077HMT_very_low();1078}1079srr1 = 0;1080HMT_medium();1081}10821083__ppc64_runlatch_on();10841085return srr1;1086}1087#endif10881089/*1090* Power ISA 3.0 idle initialization.1091*1092* POWER ISA 3.0 defines a new SPR Processor stop Status and Control1093* Register (PSSCR) to control idle behavior.1094*1095* PSSCR layout:1096* ----------------------------------------------------------1097* | PLS | /// | SD | ESL | EC | PSLL | /// | TR | MTL | RL |1098* ----------------------------------------------------------1099* 0 4 41 42 43 44 48 54 56 601100*1101* PSSCR key fields:1102* Bits 0:3 - Power-Saving Level Status (PLS). This field indicates the1103* lowest power-saving state the thread entered since stop instruction was1104* last executed.1105*1106* Bit 41 - Status Disable(SD)1107* 0 - Shows PLS entries1108* 1 - PLS entries are all 01109*1110* Bit 42 - Enable State Loss1111* 0 - No state is lost irrespective of other fields1112* 1 - Allows state loss1113*1114* Bit 43 - Exit Criterion1115* 0 - Exit from power-save mode on any interrupt1116* 1 - Exit from power-save mode controlled by LPCR's PECE bits1117*1118* Bits 44:47 - Power-Saving Level Limit1119* This limits the power-saving level that can be entered into.1120*1121* Bits 60:63 - Requested Level1122* Used to specify which power-saving level must be entered on executing1123* stop instruction1124*/11251126int __init validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags)1127{1128int err = 0;11291130/*1131* psscr_mask == 0xf indicates an older firmware.1132* Set remaining fields of psscr to the default values.1133* See NOTE above definition of PSSCR_HV_DEFAULT_VAL1134*/1135if (*psscr_mask == 0xf) {1136*psscr_val = *psscr_val | PSSCR_HV_DEFAULT_VAL;1137*psscr_mask = PSSCR_HV_DEFAULT_MASK;1138return err;1139}11401141/*1142* New firmware is expected to set the psscr_val bits correctly.1143* Validate that the following invariants are correctly maintained by1144* the new firmware.1145* - ESL bit value matches the EC bit value.1146* - ESL bit is set for all the deep stop states.1147*/1148if (GET_PSSCR_ESL(*psscr_val) != GET_PSSCR_EC(*psscr_val)) {1149err = ERR_EC_ESL_MISMATCH;1150} else if ((flags & OPAL_PM_LOSE_FULL_CONTEXT) &&1151GET_PSSCR_ESL(*psscr_val) == 0) {1152err = ERR_DEEP_STATE_ESL_MISMATCH;1153}11541155return err;1156}11571158/*1159* pnv_arch300_idle_init: Initializes the default idle state, first1160* deep idle state and deepest idle state on1161* ISA 3.0 CPUs.1162*1163* @np: /ibm,opal/power-mgt device node1164* @flags: cpu-idle-state-flags array1165* @dt_idle_states: Number of idle state entries1166* Returns 0 on success1167*/1168static void __init pnv_arch300_idle_init(void)1169{1170u64 max_residency_ns = 0;1171int i;11721173/* stop is not really architected, we only have p9,p10 drivers */1174if (!pvr_version_is(PVR_POWER10) && !pvr_version_is(PVR_POWER9))1175return;11761177/*1178* pnv_deepest_stop_{val,mask} should be set to values corresponding to1179* the deepest stop state.1180*1181* pnv_default_stop_{val,mask} should be set to values corresponding to1182* the deepest loss-less (OPAL_PM_STOP_INST_FAST) stop state.1183*/1184pnv_first_tb_loss_level = MAX_STOP_STATE + 1;1185deep_spr_loss_state = MAX_STOP_STATE + 1;1186for (i = 0; i < nr_pnv_idle_states; i++) {1187int err;1188struct pnv_idle_states_t *state = &pnv_idle_states[i];1189u64 psscr_rl = state->psscr_val & PSSCR_RL_MASK;11901191/* No deep loss driver implemented for POWER10 yet */1192if (pvr_version_is(PVR_POWER10) &&1193state->flags & (OPAL_PM_TIMEBASE_STOP|OPAL_PM_LOSE_FULL_CONTEXT))1194continue;11951196if ((state->flags & OPAL_PM_TIMEBASE_STOP) &&1197(pnv_first_tb_loss_level > psscr_rl))1198pnv_first_tb_loss_level = psscr_rl;11991200if ((state->flags & OPAL_PM_LOSE_FULL_CONTEXT) &&1201(deep_spr_loss_state > psscr_rl))1202deep_spr_loss_state = psscr_rl;12031204/*1205* The idle code does not deal with TB loss occurring1206* in a shallower state than SPR loss, so force it to1207* behave like SPRs are lost if TB is lost. POWER9 would1208* never encounter this, but a POWER8 core would if it1209* implemented the stop instruction. So this is for forward1210* compatibility.1211*/1212if ((state->flags & OPAL_PM_TIMEBASE_STOP) &&1213(deep_spr_loss_state > psscr_rl))1214deep_spr_loss_state = psscr_rl;12151216err = validate_psscr_val_mask(&state->psscr_val,1217&state->psscr_mask,1218state->flags);1219if (err) {1220report_invalid_psscr_val(state->psscr_val, err);1221continue;1222}12231224state->valid = true;12251226if (max_residency_ns < state->residency_ns) {1227max_residency_ns = state->residency_ns;1228pnv_deepest_stop_psscr_val = state->psscr_val;1229pnv_deepest_stop_psscr_mask = state->psscr_mask;1230pnv_deepest_stop_flag = state->flags;1231deepest_stop_found = true;1232}12331234if (!default_stop_found &&1235(state->flags & OPAL_PM_STOP_INST_FAST)) {1236pnv_default_stop_val = state->psscr_val;1237pnv_default_stop_mask = state->psscr_mask;1238default_stop_found = true;1239WARN_ON(state->flags & OPAL_PM_LOSE_FULL_CONTEXT);1240}1241}12421243if (unlikely(!default_stop_found)) {1244pr_warn("cpuidle-powernv: No suitable default stop state found. Disabling platform idle.\n");1245} else {1246ppc_md.power_save = arch300_idle;1247pr_info("cpuidle-powernv: Default stop: psscr = 0x%016llx,mask=0x%016llx\n",1248pnv_default_stop_val, pnv_default_stop_mask);1249}12501251if (unlikely(!deepest_stop_found)) {1252pr_warn("cpuidle-powernv: No suitable stop state for CPU-Hotplug. Offlined CPUs will busy wait");1253} else {1254pr_info("cpuidle-powernv: Deepest stop: psscr = 0x%016llx,mask=0x%016llx\n",1255pnv_deepest_stop_psscr_val,1256pnv_deepest_stop_psscr_mask);1257}12581259pr_info("cpuidle-powernv: First stop level that may lose SPRs = 0x%llx\n",1260deep_spr_loss_state);12611262pr_info("cpuidle-powernv: First stop level that may lose timebase = 0x%llx\n",1263pnv_first_tb_loss_level);1264}12651266static void __init pnv_disable_deep_states(void)1267{1268/*1269* The stop-api is unable to restore hypervisor1270* resources on wakeup from platform idle states which1271* lose full context. So disable such states.1272*/1273supported_cpuidle_states &= ~OPAL_PM_LOSE_FULL_CONTEXT;1274pr_warn("cpuidle-powernv: Disabling idle states that lose full context\n");1275pr_warn("cpuidle-powernv: Idle power-savings, CPU-Hotplug affected\n");12761277if (cpu_has_feature(CPU_FTR_ARCH_300) &&1278(pnv_deepest_stop_flag & OPAL_PM_LOSE_FULL_CONTEXT)) {1279/*1280* Use the default stop state for CPU-Hotplug1281* if available.1282*/1283if (default_stop_found) {1284pnv_deepest_stop_psscr_val = pnv_default_stop_val;1285pnv_deepest_stop_psscr_mask = pnv_default_stop_mask;1286pr_warn("cpuidle-powernv: Offlined CPUs will stop with psscr = 0x%016llx\n",1287pnv_deepest_stop_psscr_val);1288} else { /* Fallback to snooze loop for CPU-Hotplug */1289deepest_stop_found = false;1290pr_warn("cpuidle-powernv: Offlined CPUs will busy wait\n");1291}1292}1293}12941295/*1296* Probe device tree for supported idle states1297*/1298static void __init pnv_probe_idle_states(void)1299{1300int i;13011302if (nr_pnv_idle_states < 0) {1303pr_warn("cpuidle-powernv: no idle states found in the DT\n");1304return;1305}13061307if (cpu_has_feature(CPU_FTR_ARCH_300))1308pnv_arch300_idle_init();13091310for (i = 0; i < nr_pnv_idle_states; i++)1311supported_cpuidle_states |= pnv_idle_states[i].flags;1312}13131314/*1315* This function parses device-tree and populates all the information1316* into pnv_idle_states structure. It also sets up nr_pnv_idle_states1317* which is the number of cpuidle states discovered through device-tree.1318*/13191320static int __init pnv_parse_cpuidle_dt(void)1321{1322struct device_node *np;1323int nr_idle_states, i;1324int rc = 0;1325u32 *temp_u32;1326u64 *temp_u64;1327const char **temp_string;13281329np = of_find_node_by_path("/ibm,opal/power-mgt");1330if (!np) {1331pr_warn("opal: PowerMgmt Node not found\n");1332return -ENODEV;1333}1334nr_idle_states = of_property_count_u32_elems(np,1335"ibm,cpu-idle-state-flags");13361337pnv_idle_states = kcalloc(nr_idle_states, sizeof(*pnv_idle_states),1338GFP_KERNEL);1339temp_u32 = kcalloc(nr_idle_states, sizeof(u32), GFP_KERNEL);1340temp_u64 = kcalloc(nr_idle_states, sizeof(u64), GFP_KERNEL);1341temp_string = kcalloc(nr_idle_states, sizeof(char *), GFP_KERNEL);13421343if (!(pnv_idle_states && temp_u32 && temp_u64 && temp_string)) {1344pr_err("Could not allocate memory for dt parsing\n");1345rc = -ENOMEM;1346goto out;1347}13481349/* Read flags */1350if (of_property_read_u32_array(np, "ibm,cpu-idle-state-flags",1351temp_u32, nr_idle_states)) {1352pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-flags in DT\n");1353rc = -EINVAL;1354goto out;1355}1356for (i = 0; i < nr_idle_states; i++)1357pnv_idle_states[i].flags = temp_u32[i];13581359/* Read latencies */1360if (of_property_read_u32_array(np, "ibm,cpu-idle-state-latencies-ns",1361temp_u32, nr_idle_states)) {1362pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n");1363rc = -EINVAL;1364goto out;1365}1366for (i = 0; i < nr_idle_states; i++)1367pnv_idle_states[i].latency_ns = temp_u32[i];13681369/* Read residencies */1370if (of_property_read_u32_array(np, "ibm,cpu-idle-state-residency-ns",1371temp_u32, nr_idle_states)) {1372pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-residency-ns in DT\n");1373rc = -EINVAL;1374goto out;1375}1376for (i = 0; i < nr_idle_states; i++)1377pnv_idle_states[i].residency_ns = temp_u32[i];13781379/* For power9 and later */1380if (cpu_has_feature(CPU_FTR_ARCH_300)) {1381/* Read pm_crtl_val */1382if (of_property_read_u64_array(np, "ibm,cpu-idle-state-psscr",1383temp_u64, nr_idle_states)) {1384pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr in DT\n");1385rc = -EINVAL;1386goto out;1387}1388for (i = 0; i < nr_idle_states; i++)1389pnv_idle_states[i].psscr_val = temp_u64[i];13901391/* Read pm_crtl_mask */1392if (of_property_read_u64_array(np, "ibm,cpu-idle-state-psscr-mask",1393temp_u64, nr_idle_states)) {1394pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr-mask in DT\n");1395rc = -EINVAL;1396goto out;1397}1398for (i = 0; i < nr_idle_states; i++)1399pnv_idle_states[i].psscr_mask = temp_u64[i];1400}14011402/*1403* power8 specific properties ibm,cpu-idle-state-pmicr-mask and1404* ibm,cpu-idle-state-pmicr-val were never used and there is no1405* plan to use it in near future. Hence, not parsing these properties1406*/14071408if (of_property_read_string_array(np, "ibm,cpu-idle-state-names",1409temp_string, nr_idle_states) < 0) {1410pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-names in DT\n");1411rc = -EINVAL;1412goto out;1413}1414for (i = 0; i < nr_idle_states; i++)1415strscpy(pnv_idle_states[i].name, temp_string[i],1416PNV_IDLE_NAME_LEN);1417nr_pnv_idle_states = nr_idle_states;1418rc = 0;1419out:1420kfree(temp_u32);1421kfree(temp_u64);1422kfree(temp_string);1423of_node_put(np);1424return rc;1425}14261427static int __init pnv_init_idle_states(void)1428{1429int cpu;1430int rc = 0;14311432/* Set up PACA fields */1433for_each_present_cpu(cpu) {1434struct paca_struct *p = paca_ptrs[cpu];14351436p->idle_state = 0;1437if (cpu == cpu_first_thread_sibling(cpu))1438p->idle_state = (1 << threads_per_core) - 1;14391440if (!cpu_has_feature(CPU_FTR_ARCH_300)) {1441/* P7/P8 nap */1442p->thread_idle_state = PNV_THREAD_RUNNING;1443} else if (pvr_version_is(PVR_POWER9)) {1444/* P9 stop workarounds */1445#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE1446p->requested_psscr = 0;1447atomic_set(&p->dont_stop, 0);1448#endif1449}1450}14511452/* In case we error out nr_pnv_idle_states will be zero */1453nr_pnv_idle_states = 0;1454supported_cpuidle_states = 0;14551456if (cpuidle_disable != IDLE_NO_OVERRIDE)1457goto out;1458rc = pnv_parse_cpuidle_dt();1459if (rc)1460return rc;1461pnv_probe_idle_states();14621463if (!cpu_has_feature(CPU_FTR_ARCH_300)) {1464if (!(supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED_ER1)) {1465power7_fastsleep_workaround_entry = false;1466power7_fastsleep_workaround_exit = false;1467} else {1468struct device *dev_root;1469/*1470* OPAL_PM_SLEEP_ENABLED_ER1 is set. It indicates that1471* workaround is needed to use fastsleep. Provide sysfs1472* control to choose how this workaround has to be1473* applied.1474*/1475dev_root = bus_get_dev_root(&cpu_subsys);1476if (dev_root) {1477device_create_file(dev_root,1478&dev_attr_fastsleep_workaround_applyonce);1479put_device(dev_root);1480}1481}14821483update_subcore_sibling_mask();14841485if (supported_cpuidle_states & OPAL_PM_NAP_ENABLED) {1486ppc_md.power_save = power7_idle;1487power7_offline_type = PNV_THREAD_NAP;1488}14891490if ((supported_cpuidle_states & OPAL_PM_WINKLE_ENABLED) &&1491(supported_cpuidle_states & OPAL_PM_LOSE_FULL_CONTEXT))1492power7_offline_type = PNV_THREAD_WINKLE;1493else if ((supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED) ||1494(supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED_ER1))1495power7_offline_type = PNV_THREAD_SLEEP;1496}14971498if (supported_cpuidle_states & OPAL_PM_LOSE_FULL_CONTEXT) {1499if (pnv_save_sprs_for_deep_states())1500pnv_disable_deep_states();1501}15021503out:1504return 0;1505}1506machine_subsys_initcall(powernv, pnv_init_idle_states);150715081509