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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  cpuidle-pseries - idle state cpuidle driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Adapted from drivers/idle/intel_idle.c and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  drivers/acpi/processor_idle.c
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.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/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/cpuidle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/paca.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/machdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/runlatch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/idle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/plpar_wrappers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/rtas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static struct cpuidle_driver pseries_idle_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	.name             = "pseries_idle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	.owner            = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int max_idle_state __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static struct cpuidle_state *cpuidle_state_table __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static u64 snooze_timeout __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static bool snooze_timeout_en __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int snooze_loop(struct cpuidle_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			struct cpuidle_driver *drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u64 snooze_exit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	set_thread_flag(TIF_POLLING_NRFLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	pseries_idle_prolog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	snooze_exit_time = get_tb() + snooze_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	while (!need_resched()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		HMT_low();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		HMT_very_low();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			 * Task has not woken up but we are exiting the polling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			 * loop anyway. Require a barrier after polling is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			 * cleared to order subsequent test of need_resched().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			clear_thread_flag(TIF_POLLING_NRFLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	HMT_medium();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	clear_thread_flag(TIF_POLLING_NRFLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	pseries_idle_epilog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void check_and_cede_processor(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 * Ensure our interrupt state is properly tracked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 * also checks if no interrupt has occurred while we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * were soft-disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (prep_irq_for_idle()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		cede_processor();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		/* Ensure that H_CEDE returns with IRQs on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (WARN_ON(!(mfmsr() & MSR_EE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			__hard_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * XCEDE: Extended CEDE states discovered through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *        "ibm,get-systems-parameter" RTAS call with the token
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *        CEDE_LATENCY_TOKEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * Section 7.3.16 System Parameters Option of PAPR version 2.8.1 has a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * table with all the parameters to ibm,get-system-parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * CEDE_LATENCY_TOKEN corresponds to the token value for Cede Latency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * Settings Information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define CEDE_LATENCY_TOKEN	45
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * If the platform supports the cede latency settings information system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * parameter it must provide the following information in the NULL terminated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * parameter string:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * a. The first byte is the length “N” of each cede latency setting record minus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  *    one (zero indicates a length of 1 byte).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * b. For each supported cede latency setting a cede latency setting record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  *    consisting of the first “N” bytes as per the following table.
^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)  *    | Field           | Field   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *    | Name            | Length  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *    -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *    | Cede Latency    | 1 Byte  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *    | Specifier Value |         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *    -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  *    | Maximum wakeup  |         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *    | latency in      | 8 Bytes |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *    | tb-ticks        |         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  *    -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  *    | Responsive to   |         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *    | external        | 1 Byte  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *    | interrupts      |         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  *    -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * This version has cede latency record size = 10.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * The structure xcede_latency_payload represents a) and b) with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * xcede_latency_record representing the table in b).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * xcede_latency_parameter is what gets returned by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * ibm,get-systems-parameter RTAS call when made with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * CEDE_LATENCY_TOKEN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * These structures are only used to represent the data obtained by the RTAS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * call. The data is in big-endian.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct xcede_latency_record {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u8	hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	__be64	latency_ticks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	u8	wake_on_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) // Make space for 16 records, which "should be enough".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct xcede_latency_payload {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	u8     record_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct xcede_latency_record records[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct xcede_latency_parameter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	__be16  payload_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct xcede_latency_payload payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	u8 null_char;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static unsigned int nr_xcede_records;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static struct xcede_latency_parameter xcede_latency_parameter __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int __init parse_cede_parameters(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct xcede_latency_payload *payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	u32 total_xcede_records_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	u8 xcede_record_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	u16 payload_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ret = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			NULL, CEDE_LATENCY_TOKEN, __pa(&xcede_latency_parameter),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			sizeof(xcede_latency_parameter));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		pr_err("xcede: Error parsing CEDE_LATENCY_TOKEN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	payload_size = be16_to_cpu(xcede_latency_parameter.payload_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	payload = &xcede_latency_parameter.payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	xcede_record_size = payload->record_size + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (xcede_record_size != sizeof(struct xcede_latency_record)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		pr_err("xcede: Expected record-size %lu. Observed size %u.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		       sizeof(struct xcede_latency_record), xcede_record_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	pr_info("xcede: xcede_record_size = %d\n", xcede_record_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 * Since the payload_size includes the last NULL byte and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 * xcede_record_size, the remaining bytes correspond to array of all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * cede_latency settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	total_xcede_records_size = payload_size - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	nr_xcede_records = total_xcede_records_size / xcede_record_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	for (i = 0; i < nr_xcede_records; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		struct xcede_latency_record *record = &payload->records[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		u64 latency_ticks = be64_to_cpu(record->latency_ticks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		u8 wake_on_irqs = record->wake_on_irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		u8 hint = record->hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		pr_info("xcede: Record %d : hint = %u, latency = 0x%llx tb ticks, Wake-on-irq = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			i, hint, latency_ticks, wake_on_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define NR_DEDICATED_STATES	2 /* snooze, CEDE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static u8 cede_latency_hint[NR_DEDICATED_STATES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int dedicated_cede_loop(struct cpuidle_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				struct cpuidle_driver *drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 				int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	u8 old_latency_hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	pseries_idle_prolog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	get_lppaca()->donate_dedicated_cpu = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	old_latency_hint = get_lppaca()->cede_latency_hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	get_lppaca()->cede_latency_hint = cede_latency_hint[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	HMT_medium();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	check_and_cede_processor();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	get_lppaca()->donate_dedicated_cpu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	get_lppaca()->cede_latency_hint = old_latency_hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	pseries_idle_epilog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int shared_cede_loop(struct cpuidle_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			struct cpuidle_driver *drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	pseries_idle_prolog();
^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) 	 * Yield the processor to the hypervisor.  We return if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * an external interrupt occurs (which are driven prior
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 * to returning here) or if a prod occurs from another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	 * processor. When returning here, external interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 * are enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	check_and_cede_processor();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	pseries_idle_epilog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * States for dedicated partition case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static struct cpuidle_state dedicated_states[NR_DEDICATED_STATES] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	{ /* Snooze */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		.name = "snooze",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		.desc = "snooze",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		.exit_latency = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		.target_residency = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		.enter = &snooze_loop },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	{ /* CEDE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		.name = "CEDE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		.desc = "CEDE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		.exit_latency = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		.target_residency = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		.enter = &dedicated_cede_loop },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * States for shared partition case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static struct cpuidle_state shared_states[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	{ /* Snooze */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		.name = "snooze",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		.desc = "snooze",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		.exit_latency = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		.target_residency = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		.enter = &snooze_loop },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	{ /* Shared Cede */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		.name = "Shared Cede",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		.desc = "Shared Cede",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		.exit_latency = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		.target_residency = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		.enter = &shared_cede_loop },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int pseries_cpuidle_cpu_online(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (dev && cpuidle_get_driver()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		cpuidle_pause_and_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		cpuidle_enable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		cpuidle_resume_and_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static int pseries_cpuidle_cpu_dead(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (dev && cpuidle_get_driver()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		cpuidle_pause_and_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		cpuidle_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		cpuidle_resume_and_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * pseries_cpuidle_driver_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static int pseries_cpuidle_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	int idle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct cpuidle_driver *drv = &pseries_idle_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	drv->state_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	for (idle_state = 0; idle_state < max_idle_state; ++idle_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		/* Is the state not enabled? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		if (cpuidle_state_table[idle_state].enter == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		drv->states[drv->state_count] =	/* structure copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			cpuidle_state_table[idle_state];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		drv->state_count += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static void __init fixup_cede0_latency(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct xcede_latency_payload *payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	u64 min_latency_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	min_latency_us = dedicated_states[1].exit_latency; // CEDE latency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (parse_cede_parameters())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	pr_info("cpuidle: Skipping the %d Extended CEDE idle states\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		nr_xcede_records);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	payload = &xcede_latency_parameter.payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	for (i = 0; i < nr_xcede_records; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		struct xcede_latency_record *record = &payload->records[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		u64 latency_tb = be64_to_cpu(record->latency_ticks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		u64 latency_us = DIV_ROUND_UP_ULL(tb_to_ns(latency_tb), NSEC_PER_USEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		if (latency_us == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			pr_warn("cpuidle: xcede record %d has an unrealistic latency of 0us.\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		if (latency_us < min_latency_us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			min_latency_us = latency_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	 * By default, we assume that CEDE(0) has exit latency 10us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 * since there is no way for us to query from the platform.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * However, if the wakeup latency of an Extended CEDE state is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * smaller than 10us, then we can be sure that CEDE(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 * requires no more than that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	 * Perform the fix-up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (min_latency_us < dedicated_states[1].exit_latency) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		 * We set a minimum of 1us wakeup latency for cede0 to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		 * distinguish it from snooze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		u64 cede0_latency = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		if (min_latency_us > cede0_latency)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			cede0_latency = min_latency_us - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		dedicated_states[1].exit_latency = cede0_latency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		dedicated_states[1].target_residency = 10 * (cede0_latency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		pr_info("cpuidle: Fixed up CEDE exit latency to %llu us\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			cede0_latency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * pseries_idle_probe()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * Choose state table for shared versus dedicated partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int __init pseries_idle_probe(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	if (cpuidle_disable != IDLE_NO_OVERRIDE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		 * Use local_paca instead of get_lppaca() since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		 * preemption is not disabled, and it is not required in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		 * fact, since lppaca_ptr does not need to be the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		 * associated to the current CPU, it can be from any CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		if (lppaca_shared_proc(local_paca->lppaca_ptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			cpuidle_state_table = shared_states;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			max_idle_state = ARRAY_SIZE(shared_states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			 * Use firmware provided latency values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			 * starting with POWER10 platforms. In the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			 * case that we are running on a POWER10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			 * platform but in an earlier compat mode, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			 * can still use the firmware provided values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			 * However, on platforms prior to POWER10, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			 * cannot rely on the accuracy of the firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			 * provided latency values. On such platforms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			 * go with the conservative default estimate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			 * of 10us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			if (cpu_has_feature(CPU_FTR_ARCH_31) || pvr_version_is(PVR_POWER10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 				fixup_cede0_latency();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			cpuidle_state_table = dedicated_states;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			max_idle_state = NR_DEDICATED_STATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (max_idle_state > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		snooze_timeout_en = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		snooze_timeout = cpuidle_state_table[1].target_residency *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				 tb_ticks_per_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static int __init pseries_processor_idle_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	retval = pseries_idle_probe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	pseries_cpuidle_driver_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	retval = cpuidle_register(&pseries_idle_driver, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		printk(KERN_DEBUG "Registration of pseries driver failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	retval = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 					   "cpuidle/pseries:online",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 					   pseries_cpuidle_cpu_online, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	WARN_ON(retval < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	retval = cpuhp_setup_state_nocalls(CPUHP_CPUIDLE_DEAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 					   "cpuidle/pseries:DEAD", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 					   pseries_cpuidle_cpu_dead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	WARN_ON(retval < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	printk(KERN_DEBUG "pseries_idle_driver registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) device_initcall(pseries_processor_idle_init);