Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * acpi_pad.c ACPI Processor Aggregator Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2009, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <uapi/linux/sched/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/tick.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/mwait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <xen/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define ACPI_PROCESSOR_AGGREGATOR_CLASS	"acpi_pad"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static DEFINE_MUTEX(isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static DEFINE_MUTEX(round_robin_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static unsigned long power_saving_mwait_eax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static unsigned char tsc_detected_unstable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static unsigned char tsc_marked_unstable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static void power_saving_mwait_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned int eax, ebx, ecx, edx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	unsigned int highest_cstate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	unsigned int highest_subcstate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (!boot_cpu_has(X86_FEATURE_MWAIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	    !(ecx & CPUID5_ECX_INTERRUPT_BREAK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	edx >>= MWAIT_SUBSTATE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	for (i = 0; i < 7 && edx; i++, edx >>= MWAIT_SUBSTATE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		if (edx & MWAIT_SUBSTATE_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			highest_cstate = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			highest_subcstate = edx & MWAIT_SUBSTATE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	power_saving_mwait_eax = (highest_cstate << MWAIT_SUBSTATE_SIZE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		(highest_subcstate - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #if defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	switch (boot_cpu_data.x86_vendor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	case X86_VENDOR_HYGON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	case X86_VENDOR_AMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	case X86_VENDOR_INTEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	case X86_VENDOR_ZHAOXIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		 * AMD Fam10h TSC will tick in all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		 * C/P/S0/S1 states when this bit is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			tsc_detected_unstable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		/* TSC could halt in idle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		tsc_detected_unstable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static unsigned long cpu_weight[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int tsk_in_cpu[NR_CPUS] = {[0 ... NR_CPUS-1] = -1};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static DECLARE_BITMAP(pad_busy_cpus_bits, NR_CPUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static void round_robin_cpu(unsigned int tsk_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct cpumask *pad_busy_cpus = to_cpumask(pad_busy_cpus_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	cpumask_var_t tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned long min_weight = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned long preferred_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	mutex_lock(&round_robin_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	cpumask_clear(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	for_each_cpu(cpu, pad_busy_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		cpumask_or(tmp, tmp, topology_sibling_cpumask(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	cpumask_andnot(tmp, cpu_online_mask, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* avoid HT sibilings if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (cpumask_empty(tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		cpumask_andnot(tmp, cpu_online_mask, pad_busy_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (cpumask_empty(tmp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		mutex_unlock(&round_robin_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		free_cpumask_var(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	for_each_cpu(cpu, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if (cpu_weight[cpu] < min_weight) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			min_weight = cpu_weight[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			preferred_cpu = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (tsk_in_cpu[tsk_index] != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		cpumask_clear_cpu(tsk_in_cpu[tsk_index], pad_busy_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	tsk_in_cpu[tsk_index] = preferred_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	cpumask_set_cpu(preferred_cpu, pad_busy_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	cpu_weight[preferred_cpu]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	mutex_unlock(&round_robin_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	set_cpus_allowed_ptr(current, cpumask_of(preferred_cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	free_cpumask_var(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static void exit_round_robin(unsigned int tsk_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct cpumask *pad_busy_cpus = to_cpumask(pad_busy_cpus_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	cpumask_clear_cpu(tsk_in_cpu[tsk_index], pad_busy_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	tsk_in_cpu[tsk_index] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static unsigned int idle_pct = 5; /* percentage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static unsigned int round_robin_time = 1; /* second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int power_saving_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int do_sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	unsigned int tsk_index = (unsigned long)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	u64 last_jiffies = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	sched_set_fifo_low(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		unsigned long expire_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		/* round robin to cpus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		expire_time = last_jiffies + round_robin_time * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (time_before(expire_time, jiffies)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			last_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			round_robin_cpu(tsk_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		do_sleep = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		expire_time = jiffies + HZ * (100 - idle_pct) / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		while (!need_resched()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			if (tsc_detected_unstable && !tsc_marked_unstable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				/* TSC could halt in idle, so notify users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				mark_tsc_unstable("TSC halts in idle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				tsc_marked_unstable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			tick_broadcast_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			tick_broadcast_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			stop_critical_timings();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			mwait_idle_with_hints(power_saving_mwait_eax, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			start_critical_timings();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			tick_broadcast_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			if (time_before(expire_time, jiffies)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				do_sleep = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		 * current sched_rt has threshold for rt task running time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		 * When a rt task uses 95% CPU time, the rt thread will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		 * scheduled out for 5% CPU time to not starve other tasks. But
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		 * the mechanism only works when all CPUs have RT task running,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		 * as if one CPU hasn't RT task, RT task from other CPUs will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		 * borrow CPU time from this CPU and cause RT task use > 95%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		 * CPU time. To make 'avoid starvation' work, takes a nap here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (unlikely(do_sleep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			schedule_timeout_killable(HZ * idle_pct / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		/* If an external event has set the need_resched flag, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		 * we need to deal with it, or this loop will continue to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		 * spin without calling __mwait().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		if (unlikely(need_resched()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	exit_round_robin(tsk_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static struct task_struct *ps_tsks[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static unsigned int ps_tsk_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int create_power_saving_task(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	ps_tsks[ps_tsk_num] = kthread_run(power_saving_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		(void *)(unsigned long)ps_tsk_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		"acpi_pad/%d", ps_tsk_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (IS_ERR(ps_tsks[ps_tsk_num])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		rc = PTR_ERR(ps_tsks[ps_tsk_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		ps_tsks[ps_tsk_num] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		ps_tsk_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static void destroy_power_saving_task(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (ps_tsk_num > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		ps_tsk_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		kthread_stop(ps_tsks[ps_tsk_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		ps_tsks[ps_tsk_num] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void set_power_saving_task_num(unsigned int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (num > ps_tsk_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		while (ps_tsk_num < num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			if (create_power_saving_task())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	} else if (num < ps_tsk_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		while (ps_tsk_num > num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			destroy_power_saving_task();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static void acpi_pad_idle_cpus(unsigned int num_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	get_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	num_cpus = min_t(unsigned int, num_cpus, num_online_cpus());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	set_power_saving_task_num(num_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	put_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static uint32_t acpi_pad_idle_cpus_num(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return ps_tsk_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static ssize_t rrtime_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	unsigned long num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (kstrtoul(buf, 0, &num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (num < 1 || num >= 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	mutex_lock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	round_robin_time = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	mutex_unlock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static ssize_t rrtime_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return scnprintf(buf, PAGE_SIZE, "%d\n", round_robin_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static DEVICE_ATTR_RW(rrtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static ssize_t idlepct_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	unsigned long num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (kstrtoul(buf, 0, &num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (num < 1 || num >= 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	mutex_lock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	idle_pct = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	mutex_unlock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static ssize_t idlepct_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return scnprintf(buf, PAGE_SIZE, "%d\n", idle_pct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static DEVICE_ATTR_RW(idlepct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static ssize_t idlecpus_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	unsigned long num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (kstrtoul(buf, 0, &num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	mutex_lock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	acpi_pad_idle_cpus(num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	mutex_unlock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static ssize_t idlecpus_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	return cpumap_print_to_pagebuf(false, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				       to_cpumask(pad_busy_cpus_bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static DEVICE_ATTR_RW(idlecpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int acpi_pad_add_sysfs(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	result = device_create_file(&device->dev, &dev_attr_idlecpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	result = device_create_file(&device->dev, &dev_attr_idlepct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		device_remove_file(&device->dev, &dev_attr_idlecpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	result = device_create_file(&device->dev, &dev_attr_rrtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		device_remove_file(&device->dev, &dev_attr_idlecpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		device_remove_file(&device->dev, &dev_attr_idlepct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void acpi_pad_remove_sysfs(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	device_remove_file(&device->dev, &dev_attr_idlecpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	device_remove_file(&device->dev, &dev_attr_idlepct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	device_remove_file(&device->dev, &dev_attr_rrtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * Query firmware how many CPUs should be idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * return -1 on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static int acpi_pad_pur(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	union acpi_object *package;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	int num = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PUR", NULL, &buffer)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (!buffer.length || !buffer.pointer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	package = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (package->type == ACPI_TYPE_PACKAGE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		package->package.count == 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		package->package.elements[0].integer.value == 1) /* rev 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		num = package->package.elements[1].integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void acpi_pad_handle_notify(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	int num_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	uint32_t idle_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct acpi_buffer param = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		.length = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		.pointer = (void *)&idle_cpus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	mutex_lock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	num_cpus = acpi_pad_pur(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (num_cpus < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		mutex_unlock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	acpi_pad_idle_cpus(num_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	idle_cpus = acpi_pad_idle_cpus_num();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	acpi_evaluate_ost(handle, ACPI_PROCESSOR_AGGREGATOR_NOTIFY, 0, &param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	mutex_unlock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static void acpi_pad_notify(acpi_handle handle, u32 event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct acpi_device *device = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	case ACPI_PROCESSOR_AGGREGATOR_NOTIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		acpi_pad_handle_notify(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		acpi_bus_generate_netlink_event(device->pnp.device_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			dev_name(&device->dev), event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		pr_warn("Unsupported event [0x%x]\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static int acpi_pad_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	strcpy(acpi_device_name(device), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	strcpy(acpi_device_class(device), ACPI_PROCESSOR_AGGREGATOR_CLASS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (acpi_pad_add_sysfs(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	status = acpi_install_notify_handler(device->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		ACPI_DEVICE_NOTIFY, acpi_pad_notify, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		acpi_pad_remove_sysfs(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static int acpi_pad_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	mutex_lock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	acpi_pad_idle_cpus(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	mutex_unlock(&isolated_cpus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	acpi_remove_notify_handler(device->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		ACPI_DEVICE_NOTIFY, acpi_pad_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	acpi_pad_remove_sysfs(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static const struct acpi_device_id pad_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	{"ACPI000C", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) MODULE_DEVICE_TABLE(acpi, pad_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static struct acpi_driver acpi_pad_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	.name = "processor_aggregator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	.class = ACPI_PROCESSOR_AGGREGATOR_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	.ids = pad_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	.ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		.add = acpi_pad_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		.remove = acpi_pad_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static int __init acpi_pad_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/* Xen ACPI PAD is used when running as Xen Dom0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (xen_initial_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	power_saving_mwait_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (power_saving_mwait_eax == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	return acpi_bus_register_driver(&acpi_pad_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static void __exit acpi_pad_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	acpi_bus_unregister_driver(&acpi_pad_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) module_init(acpi_pad_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) module_exit(acpi_pad_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) MODULE_AUTHOR("Shaohua Li<shaohua.li@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) MODULE_DESCRIPTION("ACPI Processor Aggregator Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) MODULE_LICENSE("GPL");