Skip to content

Commit be61a77

Browse files
committed
Merge branches 'acpi-scan', 'acpi-processor' and 'acpi-sysfs'
Merge an ACPI device enumeration update, ACPI processor driver updates, and an ACPI sysfs-related code update for 6.18-rc1: - Add Intel CVS ACPI HIDs to acpi_ignore_dep_ids[] so it is not regarded as real dependency (Hans de Goede) - Use ACPI_FREE() for freeing an ACPI object in description_show() in the ACPI sysfs-related code (Kaushlendra Kumar) - Fix memory leak in the ACPI processor idle driver registration error code path and optimize ACPI idle driver registration (Huisong Li, Rafael Wysocki) - Add module import namespace to the ACPI processor idle driver (Rafael Wysocki) - Eliminate static variable flat_state_cnt from the ACPI processor idle driver (Rafael Wysocki) - Release cpufreq policy references using __free() in the ACPI processor thremal driver (Zihuan Zhang) - Remove unused empty stubs of some functions and rearrange function declarations in a header file in the ACPI processor driver (Huisong Li) - Redefine two functions as void in the ACPI processor driver (Rafael Wysocki) - Do not expose global variable acpi_idle_driver in the ACPI processor driver (Huisong Li) * acpi-scan: ACPI: scan: Add Intel CVS ACPI HIDs to acpi_ignore_dep_ids[] * acpi-processor: ACPI: processor: Do not expose global variable acpi_idle_driver ACPI: processor: idle: Redefine two functions as void ACPI: processor: Update cpuidle driver check in __acpi_processor_start() ACPI: processor: idle: Rearrange declarations in header file ACPI: processor: Remove unused empty stubs of some functions ACPI: processor: thermal: Release policy references using __free() ACPI: processor: idle: Fix function defined but not used warning ACPI: processor: idle: Eliminate static variable flat_state_cnt ACPI: processor: idle: Add module import namespace ACPI: processor: idle: Optimize ACPI idle driver registration ACPI: processor: idle: Fix memory leak when register cpuidle device failed * acpi-sysfs: ACPI: sysfs: Use ACPI_FREE() for freeing an ACPI object
4 parents ab80f77 + 4405a21 + 559f2ea + 149139d commit be61a77

File tree

7 files changed

+124
-115
lines changed

7 files changed

+124
-115
lines changed

drivers/acpi/acpi_processor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ bool acpi_processor_claim_cst_control(void)
815815
cst_control_claimed = true;
816816
return true;
817817
}
818-
EXPORT_SYMBOL_GPL(acpi_processor_claim_cst_control);
818+
EXPORT_SYMBOL_NS_GPL(acpi_processor_claim_cst_control, "ACPI_PROCESSOR_IDLE");
819819

820820
/**
821821
* acpi_processor_evaluate_cst - Evaluate the processor _CST control method.
@@ -994,5 +994,5 @@ int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu,
994994

995995
return ret;
996996
}
997-
EXPORT_SYMBOL_GPL(acpi_processor_evaluate_cst);
997+
EXPORT_SYMBOL_NS_GPL(acpi_processor_evaluate_cst, "ACPI_PROCESSOR_IDLE");
998998
#endif /* CONFIG_ACPI_PROCESSOR_CSTATE */

drivers/acpi/device_sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static ssize_t description_show(struct device *dev,
464464

465465
buf[result++] = '\n';
466466

467-
kfree(str_obj);
467+
ACPI_FREE(str_obj);
468468

469469
return result;
470470
}

drivers/acpi/processor_driver.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ static int __acpi_processor_start(struct acpi_device *device)
166166
if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
167167
dev_dbg(&device->dev, "CPPC data invalid or not present\n");
168168

169-
if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
170-
acpi_processor_power_init(pr);
169+
acpi_processor_power_init(pr);
171170

172171
acpi_pss_perf_init(pr);
173172

@@ -263,6 +262,8 @@ static int __init acpi_processor_driver_init(void)
263262
if (result < 0)
264263
return result;
265264

265+
acpi_processor_register_idle_driver();
266+
266267
result = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
267268
"acpi/cpu-drv:online",
268269
acpi_soft_cpu_online, NULL);
@@ -301,6 +302,7 @@ static void __exit acpi_processor_driver_exit(void)
301302

302303
cpuhp_remove_state_nocalls(hp_online);
303304
cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD);
305+
acpi_processor_unregister_idle_driver();
304306
driver_unregister(&acpi_processor_driver);
305307
}
306308

drivers/acpi/processor_idle.c

Lines changed: 82 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module_param(latency_factor, uint, 0644);
5151

5252
static DEFINE_PER_CPU(struct cpuidle_device *, acpi_cpuidle_device);
5353

54-
struct cpuidle_driver acpi_idle_driver = {
54+
static struct cpuidle_driver acpi_idle_driver = {
5555
.name = "acpi_idle",
5656
.owner = THIS_MODULE,
5757
};
@@ -998,11 +998,6 @@ static int acpi_processor_evaluate_lpi(acpi_handle handle,
998998
return ret;
999999
}
10001000

1001-
/*
1002-
* flat_state_cnt - the number of composite LPI states after the process of flattening
1003-
*/
1004-
static int flat_state_cnt;
1005-
10061001
/**
10071002
* combine_lpi_states - combine local and parent LPI states to form a composite LPI state
10081003
*
@@ -1045,9 +1040,10 @@ static void stash_composite_state(struct acpi_lpi_states_array *curr_level,
10451040
curr_level->composite_states[curr_level->composite_states_size++] = t;
10461041
}
10471042

1048-
static int flatten_lpi_states(struct acpi_processor *pr,
1049-
struct acpi_lpi_states_array *curr_level,
1050-
struct acpi_lpi_states_array *prev_level)
1043+
static unsigned int flatten_lpi_states(struct acpi_processor *pr,
1044+
unsigned int flat_state_cnt,
1045+
struct acpi_lpi_states_array *curr_level,
1046+
struct acpi_lpi_states_array *prev_level)
10511047
{
10521048
int i, j, state_count = curr_level->size;
10531049
struct acpi_lpi_state *p, *t = curr_level->entries;
@@ -1087,7 +1083,7 @@ static int flatten_lpi_states(struct acpi_processor *pr,
10871083
}
10881084

10891085
kfree(curr_level->entries);
1090-
return 0;
1086+
return flat_state_cnt;
10911087
}
10921088

10931089
int __weak acpi_processor_ffh_lpi_probe(unsigned int cpu)
@@ -1102,6 +1098,7 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
11021098
acpi_handle handle = pr->handle, pr_ahandle;
11031099
struct acpi_device *d = NULL;
11041100
struct acpi_lpi_states_array info[2], *tmp, *prev, *curr;
1101+
unsigned int state_count;
11051102

11061103
/* make sure our architecture has support */
11071104
ret = acpi_processor_ffh_lpi_probe(pr->id);
@@ -1114,14 +1111,13 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
11141111
if (!acpi_has_method(handle, "_LPI"))
11151112
return -EINVAL;
11161113

1117-
flat_state_cnt = 0;
11181114
prev = &info[0];
11191115
curr = &info[1];
11201116
handle = pr->handle;
11211117
ret = acpi_processor_evaluate_lpi(handle, prev);
11221118
if (ret)
11231119
return ret;
1124-
flatten_lpi_states(pr, prev, NULL);
1120+
state_count = flatten_lpi_states(pr, 0, prev, NULL);
11251121

11261122
status = acpi_get_parent(handle, &pr_ahandle);
11271123
while (ACPI_SUCCESS(status)) {
@@ -1143,18 +1139,19 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
11431139
break;
11441140

11451141
/* flatten all the LPI states in this level of hierarchy */
1146-
flatten_lpi_states(pr, curr, prev);
1142+
state_count = flatten_lpi_states(pr, state_count, curr, prev);
11471143

11481144
tmp = prev, prev = curr, curr = tmp;
11491145

11501146
status = acpi_get_parent(handle, &pr_ahandle);
11511147
}
11521148

1153-
pr->power.count = flat_state_cnt;
11541149
/* reset the index after flattening */
1155-
for (i = 0; i < pr->power.count; i++)
1150+
for (i = 0; i < state_count; i++)
11561151
pr->power.lpi_states[i].index = i;
11571152

1153+
pr->power.count = state_count;
1154+
11581155
/* Tell driver that _LPI is supported. */
11591156
pr->flags.has_lpi = 1;
11601157
pr->flags.power = 1;
@@ -1360,74 +1357,102 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
13601357
return 0;
13611358
}
13621359

1363-
static int acpi_processor_registered;
1360+
void acpi_processor_register_idle_driver(void)
1361+
{
1362+
struct acpi_processor *pr;
1363+
int ret = -ENODEV;
1364+
int cpu;
1365+
1366+
/*
1367+
* Acpi idle driver is used by all possible CPUs.
1368+
* Install the idle handler by the processor power info of one in them.
1369+
* Note that we use previously set idle handler will be used on
1370+
* platforms that only support C1.
1371+
*/
1372+
for_each_cpu(cpu, (struct cpumask *)cpu_possible_mask) {
1373+
pr = per_cpu(processors, cpu);
1374+
if (!pr)
1375+
continue;
1376+
1377+
ret = acpi_processor_get_power_info(pr);
1378+
if (!ret) {
1379+
pr->flags.power_setup_done = 1;
1380+
acpi_processor_setup_cpuidle_states(pr);
1381+
break;
1382+
}
1383+
}
1384+
1385+
if (ret) {
1386+
pr_debug("No ACPI power information from any CPUs.\n");
1387+
return;
1388+
}
1389+
1390+
ret = cpuidle_register_driver(&acpi_idle_driver);
1391+
if (ret) {
1392+
pr_debug("register %s failed.\n", acpi_idle_driver.name);
1393+
return;
1394+
}
1395+
pr_debug("%s registered with cpuidle.\n", acpi_idle_driver.name);
1396+
}
1397+
1398+
void acpi_processor_unregister_idle_driver(void)
1399+
{
1400+
cpuidle_unregister_driver(&acpi_idle_driver);
1401+
}
13641402

1365-
int acpi_processor_power_init(struct acpi_processor *pr)
1403+
void acpi_processor_power_init(struct acpi_processor *pr)
13661404
{
1367-
int retval;
13681405
struct cpuidle_device *dev;
13691406

1407+
/*
1408+
* The code below only works if the current cpuidle driver is the ACPI
1409+
* idle driver.
1410+
*/
1411+
if (cpuidle_get_driver() != &acpi_idle_driver)
1412+
return;
1413+
13701414
if (disabled_by_idle_boot_param())
1371-
return 0;
1415+
return;
13721416

13731417
acpi_processor_cstate_first_run_checks();
13741418

13751419
if (!acpi_processor_get_power_info(pr))
13761420
pr->flags.power_setup_done = 1;
13771421

1378-
/*
1379-
* Install the idle handler if processor power management is supported.
1380-
* Note that we use previously set idle handler will be used on
1381-
* platforms that only support C1.
1382-
*/
1383-
if (pr->flags.power) {
1384-
/* Register acpi_idle_driver if not already registered */
1385-
if (!acpi_processor_registered) {
1386-
acpi_processor_setup_cpuidle_states(pr);
1387-
retval = cpuidle_register_driver(&acpi_idle_driver);
1388-
if (retval)
1389-
return retval;
1390-
pr_debug("%s registered with cpuidle\n",
1391-
acpi_idle_driver.name);
1392-
}
1422+
if (!pr->flags.power)
1423+
return;
13931424

1394-
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1395-
if (!dev)
1396-
return -ENOMEM;
1397-
per_cpu(acpi_cpuidle_device, pr->id) = dev;
1425+
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1426+
if (!dev)
1427+
return;
13981428

1399-
acpi_processor_setup_cpuidle_dev(pr, dev);
1429+
per_cpu(acpi_cpuidle_device, pr->id) = dev;
14001430

1401-
/* Register per-cpu cpuidle_device. Cpuidle driver
1402-
* must already be registered before registering device
1403-
*/
1404-
retval = cpuidle_register_device(dev);
1405-
if (retval) {
1406-
if (acpi_processor_registered == 0)
1407-
cpuidle_unregister_driver(&acpi_idle_driver);
1408-
return retval;
1409-
}
1410-
acpi_processor_registered++;
1431+
acpi_processor_setup_cpuidle_dev(pr, dev);
1432+
1433+
/*
1434+
* Register a cpuidle device for this CPU. The cpuidle driver using
1435+
* this device is expected to be registered.
1436+
*/
1437+
if (cpuidle_register_device(dev)) {
1438+
per_cpu(acpi_cpuidle_device, pr->id) = NULL;
1439+
kfree(dev);
14111440
}
1412-
return 0;
14131441
}
14141442

1415-
int acpi_processor_power_exit(struct acpi_processor *pr)
1443+
void acpi_processor_power_exit(struct acpi_processor *pr)
14161444
{
14171445
struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id);
14181446

14191447
if (disabled_by_idle_boot_param())
1420-
return 0;
1448+
return;
14211449

14221450
if (pr->flags.power) {
14231451
cpuidle_unregister_device(dev);
1424-
acpi_processor_registered--;
1425-
if (acpi_processor_registered == 0)
1426-
cpuidle_unregister_driver(&acpi_idle_driver);
1427-
14281452
kfree(dev);
14291453
}
14301454

14311455
pr->flags.power_setup_done = 0;
1432-
return 0;
14331456
}
1457+
1458+
MODULE_IMPORT_NS("ACPI_PROCESSOR_IDLE");

drivers/acpi/processor_thermal.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
6262
return 0;
6363
}
6464

65-
static int cpu_has_cpufreq(unsigned int cpu)
65+
static bool cpu_has_cpufreq(unsigned int cpu)
6666
{
67-
struct cpufreq_policy *policy;
68-
6967
if (!acpi_processor_cpufreq_init)
7068
return 0;
7169

72-
policy = cpufreq_cpu_get(cpu);
73-
if (policy) {
74-
cpufreq_cpu_put(policy);
75-
return 1;
76-
}
77-
return 0;
70+
struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
71+
72+
return policy != NULL;
7873
}
7974

8075
static int cpufreq_get_max_state(unsigned int cpu)
@@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
9388
return reduction_step(cpu);
9489
}
9590

91+
static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
92+
{
93+
unsigned long max_freq;
94+
int ret;
95+
96+
struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
97+
if (!policy)
98+
return false;
99+
100+
max_freq = (policy->cpuinfo.max_freq *
101+
(100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
102+
103+
ret = freq_qos_update_request(&pr->thermal_req, max_freq);
104+
if (ret < 0) {
105+
pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
106+
pr->id, ret);
107+
}
108+
109+
return true;
110+
}
111+
96112
static int cpufreq_set_cur_state(unsigned int cpu, int state)
97113
{
98-
struct cpufreq_policy *policy;
99114
struct acpi_processor *pr;
100-
unsigned long max_freq;
101-
int i, ret;
115+
int i;
102116

103117
if (!cpu_has_cpufreq(cpu))
104118
return 0;
@@ -120,20 +134,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
120134
if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
121135
continue;
122136

123-
policy = cpufreq_cpu_get(i);
124-
if (!policy)
137+
if (!cpufreq_update_thermal_limit(i, pr))
125138
return -EINVAL;
126-
127-
max_freq = (policy->cpuinfo.max_freq *
128-
(100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
129-
130-
cpufreq_cpu_put(policy);
131-
132-
ret = freq_qos_update_request(&pr->thermal_req, max_freq);
133-
if (ret < 0) {
134-
pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
135-
pr->id, ret);
136-
}
137139
}
138140
return 0;
139141
}

drivers/acpi/scan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,8 @@ static bool acpi_info_matches_ids(struct acpi_device_info *info,
845845
static const char * const acpi_ignore_dep_ids[] = {
846846
"PNP0D80", /* Windows-compatible System Power Management Controller */
847847
"INT33BD", /* Intel Baytrail Mailbox Device */
848+
"INTC10DE", /* Intel CVS LNL */
849+
"INTC10E0", /* Intel CVS ARL */
848850
"LATT2021", /* Lattice FW Update Client Driver */
849851
NULL
850852
};

0 commit comments

Comments
 (0)