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)  * Copyright 2020 Linaro Limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Daniel Lezcano <daniel.lezcano@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * The DTPM CPU is based on the energy model. It hooks the CPU in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * DTPM tree which in turns update the power number by propagating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * power number from the CPU energy model information to the parents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * The association between the power and the performance state, allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * to set the power of the CPU at the OPP granularity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * The CPU hotplug is supported and the power numbers will be updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * if a CPU is hot plugged / unplugged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/cpuhotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/dtpm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/energy_model.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/pm_qos.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/units.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static struct dtpm *__parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static DEFINE_PER_CPU(struct dtpm *, dtpm_per_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) struct dtpm_cpu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct freq_qos_request qos_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * When a new CPU is inserted at hotplug or boot time, add the power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * contribution and update the dtpm tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int power_add(struct dtpm *dtpm, struct em_perf_domain *em)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	u64 power_min, power_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	power_min = em->table[0].power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	power_min *= MICROWATT_PER_MILLIWATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	power_min += dtpm->power_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	power_max = em->table[em->nr_perf_states - 1].power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	power_max *= MICROWATT_PER_MILLIWATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	power_max += dtpm->power_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return dtpm_update_power(dtpm, power_min, power_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * When a CPU is unplugged, remove its power contribution from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * dtpm tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int power_sub(struct dtpm *dtpm, struct em_perf_domain *em)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u64 power_min, power_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	power_min = em->table[0].power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	power_min *= MICROWATT_PER_MILLIWATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	power_min = dtpm->power_min - power_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	power_max = em->table[em->nr_perf_states - 1].power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	power_max *= MICROWATT_PER_MILLIWATT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	power_max = dtpm->power_max - power_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return dtpm_update_power(dtpm, power_min, power_max);
^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 u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct dtpm_cpu *dtpm_cpu = dtpm->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct em_perf_domain *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct cpumask cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	unsigned long freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	u64 power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int i, nr_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	pd = em_cpu_get(dtpm_cpu->cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	cpumask_and(&cpus, cpu_online_mask, to_cpumask(pd->cpus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	nr_cpus = cpumask_weight(&cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	for (i = 0; i < pd->nr_perf_states; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		power = pd->table[i].power * MICROWATT_PER_MILLIWATT * nr_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (power > power_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			break;
^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) 	freq = pd->table[i - 1].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	freq_qos_update_request(&dtpm_cpu->qos_req, freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	power_limit = pd->table[i - 1].power *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		MICROWATT_PER_MILLIWATT * nr_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return power_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static u64 get_pd_power_uw(struct dtpm *dtpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct dtpm_cpu *dtpm_cpu = dtpm->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct em_perf_domain *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct cpumask cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	unsigned long freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int i, nr_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	pd = em_cpu_get(dtpm_cpu->cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	freq = cpufreq_quick_get(dtpm_cpu->cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	cpumask_and(&cpus, cpu_online_mask, to_cpumask(pd->cpus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	nr_cpus = cpumask_weight(&cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	for (i = 0; i < pd->nr_perf_states; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		if (pd->table[i].frequency < freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return pd->table[i].power *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			MICROWATT_PER_MILLIWATT * nr_cpus;
^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) 	return 0;
^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) static void pd_release(struct dtpm *dtpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct dtpm_cpu *dtpm_cpu = dtpm->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (freq_qos_request_active(&dtpm_cpu->qos_req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		freq_qos_remove_request(&dtpm_cpu->qos_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	kfree(dtpm_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static struct dtpm_ops dtpm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	.set_power_uw = set_pd_power_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	.get_power_uw = get_pd_power_uw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	.release = pd_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int cpuhp_dtpm_cpu_offline(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct cpufreq_policy *policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct em_perf_domain *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct dtpm *dtpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	policy = cpufreq_cpu_get(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (!policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	pd = em_cpu_get(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (!pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	dtpm = per_cpu(dtpm_per_cpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	power_sub(dtpm, pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (cpumask_weight(policy->cpus) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	for_each_cpu(cpu, policy->related_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		per_cpu(dtpm_per_cpu, cpu) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	dtpm_unregister(dtpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int cpuhp_dtpm_cpu_online(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct dtpm *dtpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct dtpm_cpu *dtpm_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct cpufreq_policy *policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct em_perf_domain *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	char name[CPUFREQ_NAME_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	policy = cpufreq_cpu_get(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (!policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	pd = em_cpu_get(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	dtpm = per_cpu(dtpm_per_cpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (dtpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return power_add(dtpm, pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	dtpm = dtpm_alloc(&dtpm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (!dtpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (!dtpm_cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		goto out_kfree_dtpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	dtpm->private = dtpm_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	dtpm_cpu->cpu = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	for_each_cpu(cpu, policy->related_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		per_cpu(dtpm_per_cpu, cpu) = dtpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	sprintf(name, "cpu%d", dtpm_cpu->cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	ret = dtpm_register(name, dtpm, __parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		goto out_kfree_dtpm_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	ret = power_add(dtpm, pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		goto out_dtpm_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	ret = freq_qos_add_request(&policy->constraints,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				   &dtpm_cpu->qos_req, FREQ_QOS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				   pd->table[pd->nr_perf_states - 1].frequency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		goto out_power_sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) out_power_sub:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	power_sub(dtpm, pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) out_dtpm_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	dtpm_unregister(dtpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	dtpm_cpu = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	dtpm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) out_kfree_dtpm_cpu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	for_each_cpu(cpu, policy->related_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		per_cpu(dtpm_per_cpu, cpu) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	kfree(dtpm_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) out_kfree_dtpm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	kfree(dtpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return ret;
^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) int dtpm_register_cpu(struct dtpm *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	__parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return cpuhp_setup_state(CPUHP_AP_DTPM_CPU_ONLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				 "dtpm_cpu:online",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				 cpuhp_dtpm_cpu_online,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				 cpuhp_dtpm_cpu_offline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }