Skip to content

Commit 69a10ca

Browse files
committed
Merge branch 'acpi-pm' into pm-core
2 parents 96428e9 + a192aa9 commit 69a10ca

File tree

16 files changed

+295
-166
lines changed

16 files changed

+295
-166
lines changed

Documentation/ABI/testing/sysfs-devices-power

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,3 @@ Description:
258258

259259
This attribute has no effect on system-wide suspend/resume and
260260
hibernation.
261-
262-
What: /sys/devices/.../power/pm_qos_remote_wakeup
263-
Date: September 2012
264-
Contact: Rafael J. Wysocki <[email protected]>
265-
Description:
266-
The /sys/devices/.../power/pm_qos_remote_wakeup attribute
267-
is used for manipulating the PM QoS "remote wakeup required"
268-
flag. If set, this flag indicates to the kernel that the
269-
device is a source of user events that have to be signaled from
270-
its low-power states.
271-
272-
Not all drivers support this attribute. If it isn't supported,
273-
it is not present.
274-
275-
This attribute has no effect on system-wide suspend/resume and
276-
hibernation.

Documentation/acpi/lpit.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
To enumerate platform Low Power Idle states, Intel platforms are using
2+
“Low Power Idle Table” (LPIT). More details about this table can be
3+
downloaded from:
4+
http://www.uefi.org/sites/default/files/resources/Intel_ACPI_Low_Power_S0_Idle.pdf
5+
6+
Residencies for each low power state can be read via FFH
7+
(Function fixed hardware) or a memory mapped interface.
8+
9+
On platforms supporting S0ix sleep states, there can be two types of
10+
residencies:
11+
- CPU PKG C10 (Read via FFH interface)
12+
- Platform Controller Hub (PCH) SLP_S0 (Read via memory mapped interface)
13+
14+
The following attributes are added dynamically to the cpuidle
15+
sysfs attribute group:
16+
/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us
17+
/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us
18+
19+
The "low_power_idle_cpu_residency_us" attribute shows time spent
20+
by the CPU package in PKG C10
21+
22+
The "low_power_idle_system_residency_us" attribute shows SLP_S0
23+
residency, or system time spent with the SLP_S0# signal asserted.
24+
This is the lowest possible system power state, achieved only when CPU is in
25+
PKG C10 and all functional blocks in PCH are in a low power state.

Documentation/power/pm_qos_interface.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ Values are updated in response to changes of the request list.
9898
The target values of resume latency and active state latency tolerance are
9999
simply the minimum of the request values held in the parameter list elements.
100100
The PM QoS flags aggregate value is a gather (bitwise OR) of all list elements'
101-
values. Two device PM QoS flags are defined currently: PM_QOS_FLAG_NO_POWER_OFF
102-
and PM_QOS_FLAG_REMOTE_WAKEUP.
101+
values. One device PM QoS flag is defined currently: PM_QOS_FLAG_NO_POWER_OFF.
103102

104103
Note: The aggregated target values are implemented in such a way that reading
105104
the aggregated value does not require any locking mechanism.
@@ -153,14 +152,14 @@ PM QoS list of resume latency constraints and remove sysfs attribute
153152
pm_qos_resume_latency_us from the device's power directory.
154153

155154
int dev_pm_qos_expose_flags(device, value)
156-
Add a request to the device's PM QoS list of flags and create sysfs attributes
157-
pm_qos_no_power_off and pm_qos_remote_wakeup under the device's power directory
158-
allowing user space to change these flags' value.
155+
Add a request to the device's PM QoS list of flags and create sysfs attribute
156+
pm_qos_no_power_off under the device's power directory allowing user space to
157+
change the value of the PM_QOS_FLAG_NO_POWER_OFF flag.
159158

160159
void dev_pm_qos_hide_flags(device)
161160
Drop the request added by dev_pm_qos_expose_flags() from the device's PM QoS list
162-
of flags and remove sysfs attributes pm_qos_no_power_off and pm_qos_remote_wakeup
163-
under the device's power directory.
161+
of flags and remove sysfs attribute pm_qos_no_power_off from the device's power
162+
directory.
164163

165164
Notification mechanisms:
166165
The per-device PM QoS framework has a per-device notification tree.

drivers/acpi/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ endif
8080
config ACPI_SPCR_TABLE
8181
bool
8282

83+
config ACPI_LPIT
84+
bool
85+
depends on X86_64
86+
default y
87+
8388
config ACPI_SLEEP
8489
bool
8590
depends on SUSPEND || HIBERNATION

drivers/acpi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ acpi-$(CONFIG_DEBUG_FS) += debugfs.o
5656
acpi-$(CONFIG_ACPI_NUMA) += numa.o
5757
acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
5858
acpi-y += acpi_lpat.o
59+
acpi-$(CONFIG_ACPI_LPIT) += acpi_lpit.o
5960
acpi-$(CONFIG_ACPI_GENERIC_GSI) += irq.o
6061
acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o
6162

drivers/acpi/acpi_lpit.c

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
2+
/*
3+
* acpi_lpit.c - LPIT table processing functions
4+
*
5+
* Copyright (C) 2017 Intel Corporation. All rights reserved.
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License version
9+
* 2 as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*/
16+
17+
#include <linux/cpu.h>
18+
#include <linux/acpi.h>
19+
#include <asm/msr.h>
20+
#include <asm/tsc.h>
21+
22+
struct lpit_residency_info {
23+
struct acpi_generic_address gaddr;
24+
u64 frequency;
25+
void __iomem *iomem_addr;
26+
};
27+
28+
/* Storage for an memory mapped and FFH based entries */
29+
static struct lpit_residency_info residency_info_mem;
30+
static struct lpit_residency_info residency_info_ffh;
31+
32+
static int lpit_read_residency_counter_us(u64 *counter, bool io_mem)
33+
{
34+
int err;
35+
36+
if (io_mem) {
37+
u64 count = 0;
38+
int error;
39+
40+
error = acpi_os_read_iomem(residency_info_mem.iomem_addr, &count,
41+
residency_info_mem.gaddr.bit_width);
42+
if (error)
43+
return error;
44+
45+
*counter = div64_u64(count * 1000000ULL, residency_info_mem.frequency);
46+
return 0;
47+
}
48+
49+
err = rdmsrl_safe(residency_info_ffh.gaddr.address, counter);
50+
if (!err) {
51+
u64 mask = GENMASK_ULL(residency_info_ffh.gaddr.bit_offset +
52+
residency_info_ffh.gaddr. bit_width - 1,
53+
residency_info_ffh.gaddr.bit_offset);
54+
55+
*counter &= mask;
56+
*counter >>= residency_info_ffh.gaddr.bit_offset;
57+
*counter = div64_u64(*counter * 1000000ULL, residency_info_ffh.frequency);
58+
return 0;
59+
}
60+
61+
return -ENODATA;
62+
}
63+
64+
static ssize_t low_power_idle_system_residency_us_show(struct device *dev,
65+
struct device_attribute *attr,
66+
char *buf)
67+
{
68+
u64 counter;
69+
int ret;
70+
71+
ret = lpit_read_residency_counter_us(&counter, true);
72+
if (ret)
73+
return ret;
74+
75+
return sprintf(buf, "%llu\n", counter);
76+
}
77+
static DEVICE_ATTR_RO(low_power_idle_system_residency_us);
78+
79+
static ssize_t low_power_idle_cpu_residency_us_show(struct device *dev,
80+
struct device_attribute *attr,
81+
char *buf)
82+
{
83+
u64 counter;
84+
int ret;
85+
86+
ret = lpit_read_residency_counter_us(&counter, false);
87+
if (ret)
88+
return ret;
89+
90+
return sprintf(buf, "%llu\n", counter);
91+
}
92+
static DEVICE_ATTR_RO(low_power_idle_cpu_residency_us);
93+
94+
int lpit_read_residency_count_address(u64 *address)
95+
{
96+
if (!residency_info_mem.gaddr.address)
97+
return -EINVAL;
98+
99+
*address = residency_info_mem.gaddr.address;
100+
101+
return 0;
102+
}
103+
104+
static void lpit_update_residency(struct lpit_residency_info *info,
105+
struct acpi_lpit_native *lpit_native)
106+
{
107+
info->frequency = lpit_native->counter_frequency ?
108+
lpit_native->counter_frequency : tsc_khz * 1000;
109+
if (!info->frequency)
110+
info->frequency = 1;
111+
112+
info->gaddr = lpit_native->residency_counter;
113+
if (info->gaddr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
114+
info->iomem_addr = ioremap_nocache(info->gaddr.address,
115+
info->gaddr.bit_width / 8);
116+
if (!info->iomem_addr)
117+
return;
118+
119+
/* Silently fail, if cpuidle attribute group is not present */
120+
sysfs_add_file_to_group(&cpu_subsys.dev_root->kobj,
121+
&dev_attr_low_power_idle_system_residency_us.attr,
122+
"cpuidle");
123+
} else if (info->gaddr.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
124+
/* Silently fail, if cpuidle attribute group is not present */
125+
sysfs_add_file_to_group(&cpu_subsys.dev_root->kobj,
126+
&dev_attr_low_power_idle_cpu_residency_us.attr,
127+
"cpuidle");
128+
}
129+
}
130+
131+
static void lpit_process(u64 begin, u64 end)
132+
{
133+
while (begin + sizeof(struct acpi_lpit_native) < end) {
134+
struct acpi_lpit_native *lpit_native = (struct acpi_lpit_native *)begin;
135+
136+
if (!lpit_native->header.type && !lpit_native->header.flags) {
137+
if (lpit_native->residency_counter.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY &&
138+
!residency_info_mem.gaddr.address) {
139+
lpit_update_residency(&residency_info_mem, lpit_native);
140+
} else if (lpit_native->residency_counter.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE &&
141+
!residency_info_ffh.gaddr.address) {
142+
lpit_update_residency(&residency_info_ffh, lpit_native);
143+
}
144+
}
145+
begin += lpit_native->header.length;
146+
}
147+
}
148+
149+
void acpi_init_lpit(void)
150+
{
151+
acpi_status status;
152+
u64 lpit_begin;
153+
struct acpi_table_lpit *lpit;
154+
155+
status = acpi_get_table(ACPI_SIG_LPIT, 0, (struct acpi_table_header **)&lpit);
156+
157+
if (ACPI_FAILURE(status))
158+
return;
159+
160+
lpit_begin = (u64)lpit + sizeof(*lpit);
161+
lpit_process(lpit_begin, lpit_begin + lpit->header.length);
162+
}

drivers/acpi/acpi_lpss.c

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -713,43 +713,9 @@ static int acpi_lpss_activate(struct device *dev)
713713

714714
static void acpi_lpss_dismiss(struct device *dev)
715715
{
716-
acpi_dev_runtime_suspend(dev);
716+
acpi_dev_suspend(dev, false);
717717
}
718718

719-
#ifdef CONFIG_PM_SLEEP
720-
static int acpi_lpss_suspend_late(struct device *dev)
721-
{
722-
struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
723-
int ret;
724-
725-
ret = pm_generic_suspend_late(dev);
726-
if (ret)
727-
return ret;
728-
729-
if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
730-
acpi_lpss_save_ctx(dev, pdata);
731-
732-
return acpi_dev_suspend_late(dev);
733-
}
734-
735-
static int acpi_lpss_resume_early(struct device *dev)
736-
{
737-
struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
738-
int ret;
739-
740-
ret = acpi_dev_resume(dev);
741-
if (ret)
742-
return ret;
743-
744-
acpi_lpss_d3_to_d0_delay(pdata);
745-
746-
if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
747-
acpi_lpss_restore_ctx(dev, pdata);
748-
749-
return pm_generic_resume_early(dev);
750-
}
751-
#endif /* CONFIG_PM_SLEEP */
752-
753719
/* IOSF SB for LPSS island */
754720
#define LPSS_IOSF_UNIT_LPIOEP 0xA0
755721
#define LPSS_IOSF_UNIT_LPIO1 0xAB
@@ -835,19 +801,15 @@ static void lpss_iosf_exit_d3_state(void)
835801
mutex_unlock(&lpss_iosf_mutex);
836802
}
837803

838-
static int acpi_lpss_runtime_suspend(struct device *dev)
804+
static int acpi_lpss_suspend(struct device *dev, bool wakeup)
839805
{
840806
struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
841807
int ret;
842808

843-
ret = pm_generic_runtime_suspend(dev);
844-
if (ret)
845-
return ret;
846-
847809
if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
848810
acpi_lpss_save_ctx(dev, pdata);
849811

850-
ret = acpi_dev_runtime_suspend(dev);
812+
ret = acpi_dev_suspend(dev, wakeup);
851813

852814
/*
853815
* This call must be last in the sequence, otherwise PMC will return
@@ -860,7 +822,7 @@ static int acpi_lpss_runtime_suspend(struct device *dev)
860822
return ret;
861823
}
862824

863-
static int acpi_lpss_runtime_resume(struct device *dev)
825+
static int acpi_lpss_resume(struct device *dev)
864826
{
865827
struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
866828
int ret;
@@ -881,7 +843,37 @@ static int acpi_lpss_runtime_resume(struct device *dev)
881843
if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
882844
acpi_lpss_restore_ctx(dev, pdata);
883845

884-
return pm_generic_runtime_resume(dev);
846+
return 0;
847+
}
848+
849+
#ifdef CONFIG_PM_SLEEP
850+
static int acpi_lpss_suspend_late(struct device *dev)
851+
{
852+
int ret = pm_generic_suspend_late(dev);
853+
854+
return ret ? ret : acpi_lpss_suspend(dev, device_may_wakeup(dev));
855+
}
856+
857+
static int acpi_lpss_resume_early(struct device *dev)
858+
{
859+
int ret = acpi_lpss_resume(dev);
860+
861+
return ret ? ret : pm_generic_resume_early(dev);
862+
}
863+
#endif /* CONFIG_PM_SLEEP */
864+
865+
static int acpi_lpss_runtime_suspend(struct device *dev)
866+
{
867+
int ret = pm_generic_runtime_suspend(dev);
868+
869+
return ret ? ret : acpi_lpss_suspend(dev, true);
870+
}
871+
872+
static int acpi_lpss_runtime_resume(struct device *dev)
873+
{
874+
int ret = acpi_lpss_resume(dev);
875+
876+
return ret ? ret : pm_generic_runtime_resume(dev);
885877
}
886878
#endif /* CONFIG_PM */
887879

0 commit comments

Comments
 (0)