1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2cff7d378SThomas Gleixner #ifndef __CPUHOTPLUG_H
3cff7d378SThomas Gleixner #define __CPUHOTPLUG_H
4cff7d378SThomas Gleixner
56cfeaf51SPaul Burton #include <linux/types.h>
66cfeaf51SPaul Burton
7fac1c204SPeter Zijlstra /*
8fac1c204SPeter Zijlstra * CPU-up CPU-down
9fac1c204SPeter Zijlstra *
10fac1c204SPeter Zijlstra * BP AP BP AP
11fac1c204SPeter Zijlstra *
12fac1c204SPeter Zijlstra * OFFLINE OFFLINE
13fac1c204SPeter Zijlstra * | ^
14fac1c204SPeter Zijlstra * v |
15fac1c204SPeter Zijlstra * BRINGUP_CPU->AP_OFFLINE BRINGUP_CPU <- AP_IDLE_DEAD (idle thread/play_dead)
16fac1c204SPeter Zijlstra * | AP_OFFLINE
17fac1c204SPeter Zijlstra * v (IRQ-off) ,---------------^
18fac1c204SPeter Zijlstra * AP_ONLNE | (stop_machine)
19fac1c204SPeter Zijlstra * | TEARDOWN_CPU <- AP_ONLINE_IDLE
20fac1c204SPeter Zijlstra * | ^
21fac1c204SPeter Zijlstra * v |
22fac1c204SPeter Zijlstra * AP_ACTIVE AP_ACTIVE
23fac1c204SPeter Zijlstra */
24fac1c204SPeter Zijlstra
25c9871c80SThomas Gleixner /*
26c9871c80SThomas Gleixner * CPU hotplug states. The state machine invokes the installed state
27c9871c80SThomas Gleixner * startup callbacks sequentially from CPUHP_OFFLINE + 1 to CPUHP_ONLINE
28c9871c80SThomas Gleixner * during a CPU online operation. During a CPU offline operation the
29c9871c80SThomas Gleixner * installed teardown callbacks are invoked in the reverse order from
30f45a6051SCosta Shulyupin * CPUHP_ONLINE - 1 down to CPUHP_OFFLINE.
31c9871c80SThomas Gleixner *
32c9871c80SThomas Gleixner * The state space has three sections: PREPARE, STARTING and ONLINE.
33c9871c80SThomas Gleixner *
34c9871c80SThomas Gleixner * PREPARE: The callbacks are invoked on a control CPU before the
35c9871c80SThomas Gleixner * hotplugged CPU is started up or after the hotplugged CPU has died.
36c9871c80SThomas Gleixner *
37c9871c80SThomas Gleixner * STARTING: The callbacks are invoked on the hotplugged CPU from the low level
38c9871c80SThomas Gleixner * hotplug startup/teardown code with interrupts disabled.
39c9871c80SThomas Gleixner *
40c9871c80SThomas Gleixner * ONLINE: The callbacks are invoked on the hotplugged CPU from the per CPU
41c9871c80SThomas Gleixner * hotplug thread with interrupts and preemption enabled.
42c9871c80SThomas Gleixner *
43c9871c80SThomas Gleixner * Adding explicit states to this enum is only necessary when:
44c9871c80SThomas Gleixner *
45c9871c80SThomas Gleixner * 1) The state is within the STARTING section
46c9871c80SThomas Gleixner *
47c9871c80SThomas Gleixner * 2) The state has ordering constraints vs. other states in the
48c9871c80SThomas Gleixner * same section.
49c9871c80SThomas Gleixner *
50c9871c80SThomas Gleixner * If neither #1 nor #2 apply, please use the dynamic state space when
51e0a99a83SAnna-Maria Behnsen * setting up a state by using CPUHP_BP_PREPARE_DYN or CPUHP_AP_ONLINE_DYN
52c9871c80SThomas Gleixner * for the @state argument of the setup function.
53c9871c80SThomas Gleixner *
54c9871c80SThomas Gleixner * See Documentation/core-api/cpu_hotplug.rst for further information and
55c9871c80SThomas Gleixner * examples.
56c9871c80SThomas Gleixner */
57cff7d378SThomas Gleixner enum cpuhp_state {
581db49484SPeter Zijlstra CPUHP_INVALID = -1,
59c9871c80SThomas Gleixner
60c9871c80SThomas Gleixner /* PREPARE section invoked on a control CPU */
611db49484SPeter Zijlstra CPUHP_OFFLINE = 0,
62cff7d378SThomas Gleixner CPUHP_CREATE_THREADS,
6300e16c3dSThomas Gleixner CPUHP_PERF_PREPARE,
6495ca792cSThomas Gleixner CPUHP_PERF_X86_PREPARE,
6596b2bd38SRichard Cochran CPUHP_PERF_X86_AMD_UNCORE_PREP,
6657ecde42SThomas Gleixner CPUHP_PERF_POWER,
67e3cfce17SThomas Gleixner CPUHP_PERF_SUPERH,
6848d7f6c7SSebastian Andrzej Siewior CPUHP_X86_HPET_DEAD,
690e285d36SSebastian Andrzej Siewior CPUHP_X86_MCE_DEAD,
708017c279SSebastian Andrzej Siewior CPUHP_VIRT_NET_DEAD,
7192125c3aSNick Child CPUHP_IBMVNIC_DEAD,
72a96a87bfSSebastian Andrzej Siewior CPUHP_SLUB_DEAD,
7388451f2cSZqiang CPUHP_DEBUG_OBJ_DEAD,
741d7ac6aeSSebastian Andrzej Siewior CPUHP_MM_WRITEBACK_DEAD,
755438da97SSebastian Andrzej Siewior CPUHP_MM_VMSTAT_DEAD,
76c4544dbcSSebastian Andrzej Siewior CPUHP_SOFTIRQ_DEAD,
7784a3f4dbSSebastian Andrzej Siewior CPUHP_NET_MVNETA_DEAD,
78529351fdSSebastian Andrzej Siewior CPUHP_CPUIDLE_DEAD,
79c23a7266SSebastian Andrzej Siewior CPUHP_ARM64_FPSIMD_DEAD,
80a4fa9cc2SSebastian Andrzej Siewior CPUHP_ARM_OMAP_WAKE_DEAD,
8175e12ed6SSebastian Andrzej Siewior CPUHP_IRQ_POLL_DEAD,
829a659f43SSebastian Andrzej Siewior CPUHP_BLOCK_SOFTIRQ_DEAD,
83be4d234dSJens Axboe CPUHP_BIO_DEAD,
8464f3bf2fSSebastian Andrzej Siewior CPUHP_ACPI_CPUDRV_DEAD,
8584c9ceefSSebastian Andrzej Siewior CPUHP_S390_PFAULT_DEAD,
86e2a738f7SSebastian Andrzej Siewior CPUHP_BLK_MQ_DEAD,
87fc4d24c9SSebastian Andrzej Siewior CPUHP_FS_BUFF_DEAD,
8890b14889SSebastian Andrzej Siewior CPUHP_PRINTK_DEAD,
89308167fcSSebastian Andrzej Siewior CPUHP_MM_MEMCQ_DEAD,
905588f5afSSebastian Andrzej Siewior CPUHP_PERCPU_CNT_DEAD,
91d544abd5SSebastian Andrzej Siewior CPUHP_RADIX_DEAD,
9204f8cfeaSMel Gorman CPUHP_PAGE_ALLOC,
93f0bf90deSSebastian Andrzej Siewior CPUHP_NET_DEV_DEAD,
949c248f88SSebastian Andrzej Siewior CPUHP_PCI_XGENE_DEAD,
95f598a497SJohn Garry CPUHP_IOMMU_IOVA_DEAD,
9655de8877SFlorian Fainelli CPUHP_AP_ARM_CACHE_B15_RAC_DEAD,
97894c9ef9SDaniel Jordan CPUHP_PADATA_DEAD,
984570dddaSDaniel Lezcano CPUHP_AP_DTPM_CPU_DEAD,
993191dd5aSJason A. Donenfeld CPUHP_RANDOM_PREPARE,
1007ee681b2SThomas Gleixner CPUHP_WORKQUEUE_PREP,
101bdab88e0SSebastian Andrzej Siewior CPUHP_POWER_NUMA_PREPARE,
10227590dc1SThomas Gleixner CPUHP_HRTIMERS_PREPARE,
1036b2c2847SSebastian Andrzej Siewior CPUHP_X2APIC_PREPARE,
10431487f83SRichard Weinberger CPUHP_SMPCFD_PREPARE,
105e6d4989aSRichard Weinberger CPUHP_RELAY_PREPARE,
10629c6d1bbSSebastian Andrzej Siewior CPUHP_MD_RAID5_PREPARE,
1074df83742SThomas Gleixner CPUHP_RCUTREE_PREP,
108dfc616d8SSebastian Andrzej Siewior CPUHP_CPUIDLE_COUPLED_PREPARE,
10968e694dcSSebastian Andrzej Siewior CPUHP_POWERPC_PMAC_PREPARE,
110da3ed651SSebastian Andrzej Siewior CPUHP_POWERPC_MMU_CTX_PREPARE,
1114d737042SBoris Ostrovsky CPUHP_XEN_PREPARE,
112c8761e20SSebastian Andrzej Siewior CPUHP_XEN_EVTCHN_PREPARE,
113657ebf7aSSebastian Andrzej Siewior CPUHP_ARM_SHMOBILE_SCU_PREPARE,
11451533233SSebastian Andrzej Siewior CPUHP_SH_SH3X_PREPARE,
11538643a0eSSebastian Andrzej Siewior CPUHP_TOPOLOGY_PREPARE,
11638b48292SSebastian Andrzej Siewior CPUHP_NET_IUCV_PREPARE,
117a3c9b14fSSebastian Andrzej Siewior CPUHP_ARM_BL_PREPARE,
118b32614c0SSebastian Andrzej Siewior CPUHP_TRACE_RB_PREPARE,
119cab7a7e5SSebastian Andrzej Siewior CPUHP_MM_ZSWP_POOL_PREPARE,
1203f7cd919SAnna-Maria Gleixner CPUHP_KVM_PPC_BOOK3S_PREPARE,
1211dd6c834SAnna-Maria Gleixner CPUHP_ZCOMP_PREPARE,
12226456f87SThomas Gleixner CPUHP_TIMERS_PREPARE,
12310a0e6f3SAnna-Maria Behnsen CPUHP_TMIGR_PREPARE,
124dd6d7c6fSSebastian Andrzej Siewior CPUHP_MIPS_SOC_PREPARE,
1254205e478SThomas Gleixner CPUHP_BP_PREPARE_DYN,
1264205e478SThomas Gleixner CPUHP_BP_PREPARE_DYN_END = CPUHP_BP_PREPARE_DYN + 20,
127a631be92SThomas Gleixner CPUHP_BP_KICK_AP,
128cff7d378SThomas Gleixner CPUHP_BRINGUP_CPU,
129c9871c80SThomas Gleixner
130c9871c80SThomas Gleixner /*
131c9871c80SThomas Gleixner * STARTING section invoked on the hotplugged CPU in low level
132c9871c80SThomas Gleixner * bringup and teardown code.
133c9871c80SThomas Gleixner */
134e69aab13SThomas Gleixner CPUHP_AP_IDLE_DEAD,
1354baa0afcSThomas Gleixner CPUHP_AP_OFFLINE,
13630f89e52SJuergen Gross CPUHP_AP_CACHECTRL_STARTING,
1379cf7243dSThomas Gleixner CPUHP_AP_SCHED_STARTING,
1384df83742SThomas Gleixner CPUHP_AP_RCUTREE_DYING,
1399c6ceecbSUlf Hansson CPUHP_AP_CPU_PM_STARTING,
14093131f7aSRichard Cochran CPUHP_AP_IRQ_GIC_STARTING,
1416c034d17SRichard Cochran CPUHP_AP_IRQ_HIP04_STARTING,
14276cde263SHector Martin CPUHP_AP_IRQ_APPLE_AIC_STARTING,
143cb5ff2d2SRichard Cochran CPUHP_AP_IRQ_ARMADA_XP_STARTING,
1447ca04bc2SSebastian Andrzej Siewior CPUHP_AP_IRQ_BCM2836_STARTING,
145da61fcf9SPaul Burton CPUHP_AP_IRQ_MIPS_GIC_STARTING,
1469e83dd3eSHuacai Chen CPUHP_AP_IRQ_EIOINTC_STARTING,
147ae16f05cSTianyang Zhang CPUHP_AP_IRQ_AVECINTC_STARTING,
148ccbe80baSAtish Patra CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING,
14925caea95SInochi Amaoto CPUHP_AP_IRQ_THEAD_ACLINT_SSWI_STARTING,
15021a8f8a0SAnup Patel CPUHP_AP_IRQ_RISCV_IMSIC_STARTING,
1513908ba2eSNick Hu CPUHP_AP_IRQ_RISCV_SBI_IPI_STARTING,
1527fbbaebfSSebastian Andrzej Siewior CPUHP_AP_ARM_MVEBU_COHERENCY,
15396b2bd38SRichard Cochran CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING,
15495ca792cSThomas Gleixner CPUHP_AP_PERF_X86_STARTING,
1559744f7b7SThomas Gleixner CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
15625a77b55SSebastian Andrzej Siewior CPUHP_AP_PERF_XTENSA_STARTING,
157e5b61bafSThomas Gleixner CPUHP_AP_ARM_VFP_STARTING,
158e937dd57SWill Deacon CPUHP_AP_ARM64_DEBUG_MONITORS_STARTING,
159d7a83d12SWill Deacon CPUHP_AP_PERF_ARM_HW_BREAKPOINT_STARTING,
16045736a72SMark Rutland CPUHP_AP_PERF_ARM_ACPI_STARTING,
1617d88eb69SThomas Gleixner CPUHP_AP_PERF_ARM_STARTING,
162e9991434SAtish Patra CPUHP_AP_PERF_RISCV_STARTING,
1639eeb2264SRichard Cochran CPUHP_AP_ARM_L2X0_STARTING,
1646282edb7SMarek Szyprowski CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
1657e86e8bdSRichard Cochran CPUHP_AP_ARM_ARCH_TIMER_STARTING,
166166b76a0SMark Rutland CPUHP_AP_ARM_ARCH_TIMER_EVTSTRM_STARTING,
167b8a12296SRichard Cochran CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
1689995f4f1SRich Felker CPUHP_AP_JCORE_TIMER_STARTING,
16926b87688SRichard Cochran CPUHP_AP_ARM_TWD_STARTING,
170b0404165SRichard Cochran CPUHP_AP_QCOM_TIMER_STARTING,
171b4822dc7SJoseph Lo CPUHP_AP_TEGRA_TIMER_STARTING,
1722c48fef7SRichard Cochran CPUHP_AP_ARMADA_TIMER_STARTING,
1732dab9093SRichard Cochran CPUHP_AP_MIPS_GIC_TIMER_STARTING,
174ecd8081fSAnna-Maria Gleixner CPUHP_AP_ARC_TIMER_STARTING,
1754bdc3eaaSChris Packham CPUHP_AP_REALTEK_TIMER_STARTING,
17662b01943SPalmer Dabbelt CPUHP_AP_RISCV_TIMER_STARTING,
1772ac6795fSAnup Patel CPUHP_AP_CLINT_TIMER_STARTING,
178a7ad38b0SGuo Ren CPUHP_AP_CSKY_TIMER_STARTING,
17925de4ce5STony Lindgren CPUHP_AP_TI_GP_TIMER_STARTING,
1804df4cb9eSMichael Kelley CPUHP_AP_HYPERV_TIMER_STARTING,
1819bf11eccSThomas Gleixner /* Must be the last timer callback */
1829bf11eccSThomas Gleixner CPUHP_AP_DUMMY_TIMER_STARTING,
1834761adb6SRichard Cochran CPUHP_AP_ARM_XEN_STARTING,
18420f3b8eaSMark Rutland CPUHP_AP_ARM_XEN_RUNSTATE_STARTING,
1852b5283d1SRichard Cochran CPUHP_AP_ARM_CORESIGHT_STARTING,
186e9b88058SMike Leach CPUHP_AP_ARM_CORESIGHT_CTI_STARTING,
18727c01a8cSSebastian Andrzej Siewior CPUHP_AP_ARM64_ISNDEP_STARTING,
18831487f83SRichard Weinberger CPUHP_AP_SMPCFD_DYING,
1895c0930ccSThomas Gleixner CPUHP_AP_HRTIMERS_DYING,
1903ad6eb06SFrederic Weisbecker CPUHP_AP_TICK_DYING,
191ae6a8a2eSRichard Cochran CPUHP_AP_X86_TBOOT_DYING,
19255de8877SFlorian Fainelli CPUHP_AP_ARM_CACHE_B15_RAC_DYING,
1934baa0afcSThomas Gleixner CPUHP_AP_ONLINE,
1944baa0afcSThomas Gleixner CPUHP_TEARDOWN_CPU,
195c9871c80SThomas Gleixner
196c9871c80SThomas Gleixner /* Online section invoked on the hotplugged CPU from the hotplug thread */
197fc6d73d6SThomas Gleixner CPUHP_AP_ONLINE_IDLE,
1989636be85SMichael Kelley CPUHP_AP_HYPERV_ONLINE,
199aaf12a7bSChao Gao CPUHP_AP_KVM_ONLINE,
2001cf12e08SThomas Gleixner CPUHP_AP_SCHED_WAIT_EMPTY,
2011cf4f629SThomas Gleixner CPUHP_AP_SMPBOOT_THREADS,
202c5cb83bbSThomas Gleixner CPUHP_AP_IRQ_AFFINITY_ONLINE,
203bf0beec0SMing Lei CPUHP_AP_BLK_MQ_ONLINE,
20477bc8c28SLucas Stach CPUHP_AP_ARM_MVEBU_SYNC_CLOCKS,
2055861381dSRafael J. Wysocki CPUHP_AP_X86_INTEL_EPB_ONLINE,
20600e16c3dSThomas Gleixner CPUHP_AP_PERF_ONLINE,
20795ca792cSThomas Gleixner CPUHP_AP_PERF_X86_ONLINE,
2081a246b9fSThomas Gleixner CPUHP_AP_PERF_X86_UNCORE_ONLINE,
20996b2bd38SRichard Cochran CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
210c6a84daaSAnna-Maria Gleixner CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
2114f0f8217SThomas Gleixner CPUHP_AP_PERF_S390_CF_ONLINE,
212e3d617feSSebastian Andrzej Siewior CPUHP_AP_PERF_S390_SF_ONLINE,
21328c94843SSebastian Andrzej Siewior CPUHP_AP_PERF_ARM_CCI_ONLINE,
214fdc15a36SSebastian Andrzej Siewior CPUHP_AP_PERF_ARM_CCN_ONLINE,
2156b79738bSQi Liu CPUHP_AP_PERF_ARM_HISI_CPA_ONLINE,
216904dcf03SShaokun Zhang CPUHP_AP_PERF_ARM_HISI_DDRC_ONLINE,
2172bab3cf9SShaokun Zhang CPUHP_AP_PERF_ARM_HISI_HHA_ONLINE,
2182940bc43SShaokun Zhang CPUHP_AP_PERF_ARM_HISI_L3_ONLINE,
219a0ab25cdSShaokun Zhang CPUHP_AP_PERF_ARM_HISI_PA_ONLINE,
2203bf30882SShaokun Zhang CPUHP_AP_PERF_ARM_HISI_SLLC_ONLINE,
2218404b0fbSQi Liu CPUHP_AP_PERF_ARM_HISI_PCIE_PMU_ONLINE,
22266637ab1SGuangbin Huang CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE,
223b828f960SMark Rutland CPUHP_AP_PERF_ARM_L2X0_ONLINE,
22421bdbb71SNeil Leeder CPUHP_AP_PERF_ARM_QCOM_L2_ONLINE,
2253071f13dSAgustin Vega-Frias CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE,
226cbb72a3cSHoan Tran CPUHP_AP_PERF_ARM_APM_XGENE_ONLINE,
22769c32972SKulkarni, Ganapatrao CPUHP_AP_PERF_ARM_CAVIUM_TX2_UNCORE_ONLINE,
22868fa55f0SBharat Bhushan CPUHP_AP_PERF_ARM_MARVELL_CN10K_DDR_ONLINE,
229e1dce564SGowthami Thiagarajan CPUHP_AP_PERF_ARM_MRVL_PEM_ONLINE,
230885dcd70SAnju T Sudhakar CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE,
23139a846dbSAnju T Sudhakar CPUHP_AP_PERF_POWERPC_CORE_IMC_ONLINE,
232f74c89bdSAnju T Sudhakar CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE,
23372c69dcdSAnju T Sudhakar CPUHP_AP_PERF_POWERPC_TRACE_IMC_ONLINE,
2341a8f0886SKajol Jain CPUHP_AP_PERF_POWERPC_HV_24x7_ONLINE,
235dcb5cdf6SKajol Jain CPUHP_AP_PERF_POWERPC_HV_GPCI_ONLINE,
236398cb924SGuo Ren CPUHP_AP_PERF_CSKY_ONLINE,
2377ee98877SAnna-Maria Behnsen CPUHP_AP_TMIGR_ONLINE,
2389cf57731SPeter Zijlstra CPUHP_AP_WATCHDOG_ONLINE,
2397ee681b2SThomas Gleixner CPUHP_AP_WORKQUEUE_ONLINE,
2403191dd5aSJason A. Donenfeld CPUHP_AP_RANDOM_ONLINE,
2414df83742SThomas Gleixner CPUHP_AP_RCUTREE_ONLINE,
242*d1a89197SFrederic Weisbecker CPUHP_AP_KTHREADS_ONLINE,
24383b44fe3SJames Morse CPUHP_AP_BASE_CACHEINFO_ONLINE,
2441cf4f629SThomas Gleixner CPUHP_AP_ONLINE_DYN,
245fe22944cSxiaoming Wang CPUHP_AP_ONLINE_DYN_END = CPUHP_AP_ONLINE_DYN + 40,
24648d7f6c7SSebastian Andrzej Siewior CPUHP_AP_X86_HPET_ONLINE,
247251a5fd6SSebastian Andrzej Siewior CPUHP_AP_X86_KVM_CLK_ONLINE,
248aaddd7d1SThomas Gleixner CPUHP_AP_ACTIVE,
249cff7d378SThomas Gleixner CPUHP_ONLINE,
250cff7d378SThomas Gleixner };
251cff7d378SThomas Gleixner
2525b7aa87eSThomas Gleixner int __cpuhp_setup_state(enum cpuhp_state state, const char *name, bool invoke,
2535b7aa87eSThomas Gleixner int (*startup)(unsigned int cpu),
254cf392d10SThomas Gleixner int (*teardown)(unsigned int cpu), bool multi_instance);
2555b7aa87eSThomas Gleixner
25671def423SSebastian Andrzej Siewior int __cpuhp_setup_state_cpuslocked(enum cpuhp_state state, const char *name,
25771def423SSebastian Andrzej Siewior bool invoke,
25871def423SSebastian Andrzej Siewior int (*startup)(unsigned int cpu),
25971def423SSebastian Andrzej Siewior int (*teardown)(unsigned int cpu),
26071def423SSebastian Andrzej Siewior bool multi_instance);
2615b7aa87eSThomas Gleixner /**
262c9871c80SThomas Gleixner * cpuhp_setup_state - Setup hotplug state callbacks with calling the @startup
263c9871c80SThomas Gleixner * callback
2645b7aa87eSThomas Gleixner * @state: The state for which the calls are installed
2655b7aa87eSThomas Gleixner * @name: Name of the callback (will be used in debug output)
266c9871c80SThomas Gleixner * @startup: startup callback function or NULL if not required
267c9871c80SThomas Gleixner * @teardown: teardown callback function or NULL if not required
2685b7aa87eSThomas Gleixner *
269c9871c80SThomas Gleixner * Installs the callback functions and invokes the @startup callback on
270c9871c80SThomas Gleixner * the online cpus which have already reached the @state.
2715b7aa87eSThomas Gleixner */
cpuhp_setup_state(enum cpuhp_state state,const char * name,int (* startup)(unsigned int cpu),int (* teardown)(unsigned int cpu))2725b7aa87eSThomas Gleixner static inline int cpuhp_setup_state(enum cpuhp_state state,
2735b7aa87eSThomas Gleixner const char *name,
2745b7aa87eSThomas Gleixner int (*startup)(unsigned int cpu),
2755b7aa87eSThomas Gleixner int (*teardown)(unsigned int cpu))
2765b7aa87eSThomas Gleixner {
277cf392d10SThomas Gleixner return __cpuhp_setup_state(state, name, true, startup, teardown, false);
2785b7aa87eSThomas Gleixner }
2795b7aa87eSThomas Gleixner
280c9871c80SThomas Gleixner /**
281c9871c80SThomas Gleixner * cpuhp_setup_state_cpuslocked - Setup hotplug state callbacks with calling
282c9871c80SThomas Gleixner * @startup callback from a cpus_read_lock()
283c9871c80SThomas Gleixner * held region
284c9871c80SThomas Gleixner * @state: The state for which the calls are installed
285c9871c80SThomas Gleixner * @name: Name of the callback (will be used in debug output)
286c9871c80SThomas Gleixner * @startup: startup callback function or NULL if not required
287c9871c80SThomas Gleixner * @teardown: teardown callback function or NULL if not required
288c9871c80SThomas Gleixner *
289c9871c80SThomas Gleixner * Same as cpuhp_setup_state() except that it must be invoked from within a
290c9871c80SThomas Gleixner * cpus_read_lock() held region.
291c9871c80SThomas Gleixner */
cpuhp_setup_state_cpuslocked(enum cpuhp_state state,const char * name,int (* startup)(unsigned int cpu),int (* teardown)(unsigned int cpu))29271def423SSebastian Andrzej Siewior static inline int cpuhp_setup_state_cpuslocked(enum cpuhp_state state,
29371def423SSebastian Andrzej Siewior const char *name,
29471def423SSebastian Andrzej Siewior int (*startup)(unsigned int cpu),
29571def423SSebastian Andrzej Siewior int (*teardown)(unsigned int cpu))
29671def423SSebastian Andrzej Siewior {
29771def423SSebastian Andrzej Siewior return __cpuhp_setup_state_cpuslocked(state, name, true, startup,
29871def423SSebastian Andrzej Siewior teardown, false);
29971def423SSebastian Andrzej Siewior }
30071def423SSebastian Andrzej Siewior
3015b7aa87eSThomas Gleixner /**
3025b7aa87eSThomas Gleixner * cpuhp_setup_state_nocalls - Setup hotplug state callbacks without calling the
303c9871c80SThomas Gleixner * @startup callback
3045b7aa87eSThomas Gleixner * @state: The state for which the calls are installed
3055b7aa87eSThomas Gleixner * @name: Name of the callback.
306c9871c80SThomas Gleixner * @startup: startup callback function or NULL if not required
307c9871c80SThomas Gleixner * @teardown: teardown callback function or NULL if not required
3085b7aa87eSThomas Gleixner *
309c9871c80SThomas Gleixner * Same as cpuhp_setup_state() except that the @startup callback is not
310c9871c80SThomas Gleixner * invoked during installation. NOP if SMP=n or HOTPLUG_CPU=n.
3115b7aa87eSThomas Gleixner */
cpuhp_setup_state_nocalls(enum cpuhp_state state,const char * name,int (* startup)(unsigned int cpu),int (* teardown)(unsigned int cpu))3125b7aa87eSThomas Gleixner static inline int cpuhp_setup_state_nocalls(enum cpuhp_state state,
3135b7aa87eSThomas Gleixner const char *name,
3145b7aa87eSThomas Gleixner int (*startup)(unsigned int cpu),
3155b7aa87eSThomas Gleixner int (*teardown)(unsigned int cpu))
3165b7aa87eSThomas Gleixner {
317cf392d10SThomas Gleixner return __cpuhp_setup_state(state, name, false, startup, teardown,
318cf392d10SThomas Gleixner false);
319cf392d10SThomas Gleixner }
320cf392d10SThomas Gleixner
321c9871c80SThomas Gleixner /**
322c9871c80SThomas Gleixner * cpuhp_setup_state_nocalls_cpuslocked - Setup hotplug state callbacks without
323c9871c80SThomas Gleixner * invoking the @startup callback from
324c9871c80SThomas Gleixner * a cpus_read_lock() held region
325c9871c80SThomas Gleixner * callbacks
326c9871c80SThomas Gleixner * @state: The state for which the calls are installed
327c9871c80SThomas Gleixner * @name: Name of the callback.
328c9871c80SThomas Gleixner * @startup: startup callback function or NULL if not required
329c9871c80SThomas Gleixner * @teardown: teardown callback function or NULL if not required
330c9871c80SThomas Gleixner *
331c9871c80SThomas Gleixner * Same as cpuhp_setup_state_nocalls() except that it must be invoked from
332c9871c80SThomas Gleixner * within a cpus_read_lock() held region.
333c9871c80SThomas Gleixner */
cpuhp_setup_state_nocalls_cpuslocked(enum cpuhp_state state,const char * name,int (* startup)(unsigned int cpu),int (* teardown)(unsigned int cpu))33471def423SSebastian Andrzej Siewior static inline int cpuhp_setup_state_nocalls_cpuslocked(enum cpuhp_state state,
33571def423SSebastian Andrzej Siewior const char *name,
33671def423SSebastian Andrzej Siewior int (*startup)(unsigned int cpu),
33771def423SSebastian Andrzej Siewior int (*teardown)(unsigned int cpu))
33871def423SSebastian Andrzej Siewior {
33971def423SSebastian Andrzej Siewior return __cpuhp_setup_state_cpuslocked(state, name, false, startup,
34071def423SSebastian Andrzej Siewior teardown, false);
34171def423SSebastian Andrzej Siewior }
34271def423SSebastian Andrzej Siewior
343cf392d10SThomas Gleixner /**
344cf392d10SThomas Gleixner * cpuhp_setup_state_multi - Add callbacks for multi state
345cf392d10SThomas Gleixner * @state: The state for which the calls are installed
346cf392d10SThomas Gleixner * @name: Name of the callback.
347c9871c80SThomas Gleixner * @startup: startup callback function or NULL if not required
348c9871c80SThomas Gleixner * @teardown: teardown callback function or NULL if not required
349cf392d10SThomas Gleixner *
350cf392d10SThomas Gleixner * Sets the internal multi_instance flag and prepares a state to work as a multi
351cf392d10SThomas Gleixner * instance callback. No callbacks are invoked at this point. The callbacks are
352cf392d10SThomas Gleixner * invoked once an instance for this state are registered via
353c9871c80SThomas Gleixner * cpuhp_state_add_instance() or cpuhp_state_add_instance_nocalls()
354cf392d10SThomas Gleixner */
cpuhp_setup_state_multi(enum cpuhp_state state,const char * name,int (* startup)(unsigned int cpu,struct hlist_node * node),int (* teardown)(unsigned int cpu,struct hlist_node * node))355cf392d10SThomas Gleixner static inline int cpuhp_setup_state_multi(enum cpuhp_state state,
356cf392d10SThomas Gleixner const char *name,
357cf392d10SThomas Gleixner int (*startup)(unsigned int cpu,
358cf392d10SThomas Gleixner struct hlist_node *node),
359cf392d10SThomas Gleixner int (*teardown)(unsigned int cpu,
360cf392d10SThomas Gleixner struct hlist_node *node))
361cf392d10SThomas Gleixner {
362cf392d10SThomas Gleixner return __cpuhp_setup_state(state, name, false,
363cf392d10SThomas Gleixner (void *) startup,
364cf392d10SThomas Gleixner (void *) teardown, true);
365cf392d10SThomas Gleixner }
366cf392d10SThomas Gleixner
367cf392d10SThomas Gleixner int __cpuhp_state_add_instance(enum cpuhp_state state, struct hlist_node *node,
368cf392d10SThomas Gleixner bool invoke);
3699805c673SThomas Gleixner int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state,
3709805c673SThomas Gleixner struct hlist_node *node, bool invoke);
371cf392d10SThomas Gleixner
372cf392d10SThomas Gleixner /**
373cf392d10SThomas Gleixner * cpuhp_state_add_instance - Add an instance for a state and invoke startup
374cf392d10SThomas Gleixner * callback.
375cf392d10SThomas Gleixner * @state: The state for which the instance is installed
376cf392d10SThomas Gleixner * @node: The node for this individual state.
377cf392d10SThomas Gleixner *
378c9871c80SThomas Gleixner * Installs the instance for the @state and invokes the registered startup
379c9871c80SThomas Gleixner * callback on the online cpus which have already reached the @state. The
380c9871c80SThomas Gleixner * @state must have been earlier marked as multi-instance by
381c9871c80SThomas Gleixner * cpuhp_setup_state_multi().
382cf392d10SThomas Gleixner */
cpuhp_state_add_instance(enum cpuhp_state state,struct hlist_node * node)383cf392d10SThomas Gleixner static inline int cpuhp_state_add_instance(enum cpuhp_state state,
384cf392d10SThomas Gleixner struct hlist_node *node)
385cf392d10SThomas Gleixner {
386cf392d10SThomas Gleixner return __cpuhp_state_add_instance(state, node, true);
387cf392d10SThomas Gleixner }
388cf392d10SThomas Gleixner
389cf392d10SThomas Gleixner /**
390cf392d10SThomas Gleixner * cpuhp_state_add_instance_nocalls - Add an instance for a state without
391cf392d10SThomas Gleixner * invoking the startup callback.
392cf392d10SThomas Gleixner * @state: The state for which the instance is installed
393cf392d10SThomas Gleixner * @node: The node for this individual state.
394cf392d10SThomas Gleixner *
395c9871c80SThomas Gleixner * Installs the instance for the @state. The @state must have been earlier
396c9871c80SThomas Gleixner * marked as multi-instance by cpuhp_setup_state_multi. NOP if SMP=n or
397c9871c80SThomas Gleixner * HOTPLUG_CPU=n.
398cf392d10SThomas Gleixner */
cpuhp_state_add_instance_nocalls(enum cpuhp_state state,struct hlist_node * node)399cf392d10SThomas Gleixner static inline int cpuhp_state_add_instance_nocalls(enum cpuhp_state state,
400cf392d10SThomas Gleixner struct hlist_node *node)
401cf392d10SThomas Gleixner {
402cf392d10SThomas Gleixner return __cpuhp_state_add_instance(state, node, false);
4035b7aa87eSThomas Gleixner }
4045b7aa87eSThomas Gleixner
405c9871c80SThomas Gleixner /**
406c9871c80SThomas Gleixner * cpuhp_state_add_instance_nocalls_cpuslocked - Add an instance for a state
407c9871c80SThomas Gleixner * without invoking the startup
408c9871c80SThomas Gleixner * callback from a cpus_read_lock()
409c9871c80SThomas Gleixner * held region.
410c9871c80SThomas Gleixner * @state: The state for which the instance is installed
411c9871c80SThomas Gleixner * @node: The node for this individual state.
412c9871c80SThomas Gleixner *
413c9871c80SThomas Gleixner * Same as cpuhp_state_add_instance_nocalls() except that it must be
414c9871c80SThomas Gleixner * invoked from within a cpus_read_lock() held region.
415c9871c80SThomas Gleixner */
4169805c673SThomas Gleixner static inline int
cpuhp_state_add_instance_nocalls_cpuslocked(enum cpuhp_state state,struct hlist_node * node)4179805c673SThomas Gleixner cpuhp_state_add_instance_nocalls_cpuslocked(enum cpuhp_state state,
4189805c673SThomas Gleixner struct hlist_node *node)
4199805c673SThomas Gleixner {
4209805c673SThomas Gleixner return __cpuhp_state_add_instance_cpuslocked(state, node, false);
4219805c673SThomas Gleixner }
4229805c673SThomas Gleixner
4235b7aa87eSThomas Gleixner void __cpuhp_remove_state(enum cpuhp_state state, bool invoke);
42471def423SSebastian Andrzej Siewior void __cpuhp_remove_state_cpuslocked(enum cpuhp_state state, bool invoke);
4255b7aa87eSThomas Gleixner
4265b7aa87eSThomas Gleixner /**
4275b7aa87eSThomas Gleixner * cpuhp_remove_state - Remove hotplug state callbacks and invoke the teardown
4285b7aa87eSThomas Gleixner * @state: The state for which the calls are removed
4295b7aa87eSThomas Gleixner *
4305b7aa87eSThomas Gleixner * Removes the callback functions and invokes the teardown callback on
431c9871c80SThomas Gleixner * the online cpus which have already reached the @state.
4325b7aa87eSThomas Gleixner */
cpuhp_remove_state(enum cpuhp_state state)4335b7aa87eSThomas Gleixner static inline void cpuhp_remove_state(enum cpuhp_state state)
4345b7aa87eSThomas Gleixner {
4355b7aa87eSThomas Gleixner __cpuhp_remove_state(state, true);
4365b7aa87eSThomas Gleixner }
4375b7aa87eSThomas Gleixner
4385b7aa87eSThomas Gleixner /**
4395b7aa87eSThomas Gleixner * cpuhp_remove_state_nocalls - Remove hotplug state callbacks without invoking
440c9871c80SThomas Gleixner * the teardown callback
4415b7aa87eSThomas Gleixner * @state: The state for which the calls are removed
4425b7aa87eSThomas Gleixner */
cpuhp_remove_state_nocalls(enum cpuhp_state state)4435b7aa87eSThomas Gleixner static inline void cpuhp_remove_state_nocalls(enum cpuhp_state state)
4445b7aa87eSThomas Gleixner {
4455b7aa87eSThomas Gleixner __cpuhp_remove_state(state, false);
4465b7aa87eSThomas Gleixner }
4475b7aa87eSThomas Gleixner
448c9871c80SThomas Gleixner /**
449c9871c80SThomas Gleixner * cpuhp_remove_state_nocalls_cpuslocked - Remove hotplug state callbacks without invoking
450c9871c80SThomas Gleixner * teardown from a cpus_read_lock() held region.
451c9871c80SThomas Gleixner * @state: The state for which the calls are removed
452c9871c80SThomas Gleixner *
453c9871c80SThomas Gleixner * Same as cpuhp_remove_state nocalls() except that it must be invoked
454c9871c80SThomas Gleixner * from within a cpus_read_lock() held region.
455c9871c80SThomas Gleixner */
cpuhp_remove_state_nocalls_cpuslocked(enum cpuhp_state state)45671def423SSebastian Andrzej Siewior static inline void cpuhp_remove_state_nocalls_cpuslocked(enum cpuhp_state state)
45771def423SSebastian Andrzej Siewior {
45871def423SSebastian Andrzej Siewior __cpuhp_remove_state_cpuslocked(state, false);
45971def423SSebastian Andrzej Siewior }
46071def423SSebastian Andrzej Siewior
461cf392d10SThomas Gleixner /**
462cf392d10SThomas Gleixner * cpuhp_remove_multi_state - Remove hotplug multi state callback
463cf392d10SThomas Gleixner * @state: The state for which the calls are removed
464cf392d10SThomas Gleixner *
465cf392d10SThomas Gleixner * Removes the callback functions from a multi state. This is the reverse of
466cf392d10SThomas Gleixner * cpuhp_setup_state_multi(). All instances should have been removed before
467cf392d10SThomas Gleixner * invoking this function.
468cf392d10SThomas Gleixner */
cpuhp_remove_multi_state(enum cpuhp_state state)469cf392d10SThomas Gleixner static inline void cpuhp_remove_multi_state(enum cpuhp_state state)
470cf392d10SThomas Gleixner {
471cf392d10SThomas Gleixner __cpuhp_remove_state(state, false);
472cf392d10SThomas Gleixner }
473cf392d10SThomas Gleixner
474cf392d10SThomas Gleixner int __cpuhp_state_remove_instance(enum cpuhp_state state,
475cf392d10SThomas Gleixner struct hlist_node *node, bool invoke);
476cf392d10SThomas Gleixner
477cf392d10SThomas Gleixner /**
478cf392d10SThomas Gleixner * cpuhp_state_remove_instance - Remove hotplug instance from state and invoke
479cf392d10SThomas Gleixner * the teardown callback
480cf392d10SThomas Gleixner * @state: The state from which the instance is removed
481cf392d10SThomas Gleixner * @node: The node for this individual state.
482cf392d10SThomas Gleixner *
483c9871c80SThomas Gleixner * Removes the instance and invokes the teardown callback on the online cpus
484c9871c80SThomas Gleixner * which have already reached @state.
485cf392d10SThomas Gleixner */
cpuhp_state_remove_instance(enum cpuhp_state state,struct hlist_node * node)486cf392d10SThomas Gleixner static inline int cpuhp_state_remove_instance(enum cpuhp_state state,
487cf392d10SThomas Gleixner struct hlist_node *node)
488cf392d10SThomas Gleixner {
489cf392d10SThomas Gleixner return __cpuhp_state_remove_instance(state, node, true);
490cf392d10SThomas Gleixner }
491cf392d10SThomas Gleixner
492cf392d10SThomas Gleixner /**
493cf392d10SThomas Gleixner * cpuhp_state_remove_instance_nocalls - Remove hotplug instance from state
494c91eb283SJohn Garry * without invoking the teardown callback
495cf392d10SThomas Gleixner * @state: The state from which the instance is removed
496cf392d10SThomas Gleixner * @node: The node for this individual state.
497cf392d10SThomas Gleixner *
498cf392d10SThomas Gleixner * Removes the instance without invoking the teardown callback.
499cf392d10SThomas Gleixner */
cpuhp_state_remove_instance_nocalls(enum cpuhp_state state,struct hlist_node * node)500cf392d10SThomas Gleixner static inline int cpuhp_state_remove_instance_nocalls(enum cpuhp_state state,
501cf392d10SThomas Gleixner struct hlist_node *node)
502cf392d10SThomas Gleixner {
503cf392d10SThomas Gleixner return __cpuhp_state_remove_instance(state, node, false);
504cf392d10SThomas Gleixner }
505cf392d10SThomas Gleixner
5068df3e07eSThomas Gleixner #ifdef CONFIG_SMP
5078df3e07eSThomas Gleixner void cpuhp_online_idle(enum cpuhp_state state);
5088df3e07eSThomas Gleixner #else
cpuhp_online_idle(enum cpuhp_state state)5098df3e07eSThomas Gleixner static inline void cpuhp_online_idle(enum cpuhp_state state) { }
5108df3e07eSThomas Gleixner #endif
5118df3e07eSThomas Gleixner
512a631be92SThomas Gleixner struct task_struct;
513a631be92SThomas Gleixner
5146f062123SThomas Gleixner void cpuhp_ap_sync_alive(void);
5156f062123SThomas Gleixner void arch_cpuhp_sync_state_poll(void);
5166f062123SThomas Gleixner void arch_cpuhp_cleanup_kick_cpu(unsigned int cpu);
517a631be92SThomas Gleixner int arch_cpuhp_kick_ap_alive(unsigned int cpu, struct task_struct *tidle);
51818415f33SThomas Gleixner bool arch_cpuhp_init_parallel_bringup(void);
5196f062123SThomas Gleixner
5206f062123SThomas Gleixner #ifdef CONFIG_HOTPLUG_CORE_SYNC_DEAD
5216f062123SThomas Gleixner void cpuhp_ap_report_dead(void);
5226f062123SThomas Gleixner void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu);
5236f062123SThomas Gleixner #else
cpuhp_ap_report_dead(void)5246f062123SThomas Gleixner static inline void cpuhp_ap_report_dead(void) { }
arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)5256f062123SThomas Gleixner static inline void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu) { }
5266f062123SThomas Gleixner #endif
5276f062123SThomas Gleixner
528cff7d378SThomas Gleixner #endif
529