aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/acpi/lpit.txt25
-rw-r--r--drivers/acpi/Kconfig5
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/acpi_lpit.c162
-rw-r--r--drivers/acpi/acpi_lpss.c84
-rw-r--r--drivers/acpi/device_pm.c157
-rw-r--r--drivers/acpi/internal.h6
-rw-r--r--drivers/acpi/osl.c42
-rw-r--r--drivers/acpi/scan.c1
-rw-r--r--include/acpi/acpiosxf.h2
-rw-r--r--include/linux/acpi.h20
11 files changed, 343 insertions, 162 deletions
diff --git a/Documentation/acpi/lpit.txt b/Documentation/acpi/lpit.txt
new file mode 100644
index 000000000000..b426398d2e97
--- /dev/null
+++ b/Documentation/acpi/lpit.txt
@@ -0,0 +1,25 @@
1To enumerate platform Low Power Idle states, Intel platforms are using
2“Low Power Idle Table” (LPIT). More details about this table can be
3downloaded from:
4http://www.uefi.org/sites/default/files/resources/Intel_ACPI_Low_Power_S0_Idle.pdf
5
6Residencies for each low power state can be read via FFH
7(Function fixed hardware) or a memory mapped interface.
8
9On platforms supporting S0ix sleep states, there can be two types of
10residencies:
11- CPU PKG C10 (Read via FFH interface)
12- Platform Controller Hub (PCH) SLP_S0 (Read via memory mapped interface)
13
14The following attributes are added dynamically to the cpuidle
15sysfs 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
19The "low_power_idle_cpu_residency_us" attribute shows time spent
20by the CPU package in PKG C10
21
22The "low_power_idle_system_residency_us" attribute shows SLP_S0
23residency, or system time spent with the SLP_S0# signal asserted.
24This is the lowest possible system power state, achieved only when CPU is in
25PKG C10 and all functional blocks in PCH are in a low power state.
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 5b1938f4b626..4cb763a01f4d 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -81,6 +81,11 @@ endif
81config ACPI_SPCR_TABLE 81config ACPI_SPCR_TABLE
82 bool 82 bool
83 83
84config ACPI_LPIT
85 bool
86 depends on X86_64
87 default y
88
84config ACPI_SLEEP 89config ACPI_SLEEP
85 bool 90 bool
86 depends on SUSPEND || HIBERNATION 91 depends on SUSPEND || HIBERNATION
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index cd1abc9bc325..168e14d29d31 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -57,6 +57,7 @@ acpi-$(CONFIG_DEBUG_FS) += debugfs.o
57acpi-$(CONFIG_ACPI_NUMA) += numa.o 57acpi-$(CONFIG_ACPI_NUMA) += numa.o
58acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o 58acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
59acpi-y += acpi_lpat.o 59acpi-y += acpi_lpat.o
60acpi-$(CONFIG_ACPI_LPIT) += acpi_lpit.o
60acpi-$(CONFIG_ACPI_GENERIC_GSI) += irq.o 61acpi-$(CONFIG_ACPI_GENERIC_GSI) += irq.o
61acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o 62acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o
62 63
diff --git a/drivers/acpi/acpi_lpit.c b/drivers/acpi/acpi_lpit.c
new file mode 100644
index 000000000000..e94e478dd18b
--- /dev/null
+++ b/drivers/acpi/acpi_lpit.c
@@ -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
22struct 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 */
29static struct lpit_residency_info residency_info_mem;
30static struct lpit_residency_info residency_info_ffh;
31
32static 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
64static 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}
77static DEVICE_ATTR_RO(low_power_idle_system_residency_us);
78
79static 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}
92static DEVICE_ATTR_RO(low_power_idle_cpu_residency_us);
93
94int 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
104static 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
131static 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
149void 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}
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 032ae44710e5..04d32bdb5a95 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -693,7 +693,7 @@ static int acpi_lpss_activate(struct device *dev)
693 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); 693 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
694 int ret; 694 int ret;
695 695
696 ret = acpi_dev_runtime_resume(dev); 696 ret = acpi_dev_resume(dev);
697 if (ret) 697 if (ret)
698 return ret; 698 return ret;
699 699
@@ -713,43 +713,9 @@ static int acpi_lpss_activate(struct device *dev)
713 713
714static void acpi_lpss_dismiss(struct device *dev) 714static void acpi_lpss_dismiss(struct device *dev)
715{ 715{
716 acpi_dev_runtime_suspend(dev); 716 acpi_dev_suspend(dev, false);
717} 717}
718 718
719#ifdef CONFIG_PM_SLEEP
720static 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
735static 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_early(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
753/* IOSF SB for LPSS island */ 719/* IOSF SB for LPSS island */
754#define LPSS_IOSF_UNIT_LPIOEP 0xA0 720#define LPSS_IOSF_UNIT_LPIOEP 0xA0
755#define LPSS_IOSF_UNIT_LPIO1 0xAB 721#define LPSS_IOSF_UNIT_LPIO1 0xAB
@@ -835,19 +801,15 @@ static void lpss_iosf_exit_d3_state(void)
835 mutex_unlock(&lpss_iosf_mutex); 801 mutex_unlock(&lpss_iosf_mutex);
836} 802}
837 803
838static int acpi_lpss_runtime_suspend(struct device *dev) 804static int acpi_lpss_suspend(struct device *dev, bool wakeup)
839{ 805{
840 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); 806 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
841 int ret; 807 int ret;
842 808
843 ret = pm_generic_runtime_suspend(dev);
844 if (ret)
845 return ret;
846
847 if (pdata->dev_desc->flags & LPSS_SAVE_CTX) 809 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
848 acpi_lpss_save_ctx(dev, pdata); 810 acpi_lpss_save_ctx(dev, pdata);
849 811
850 ret = acpi_dev_runtime_suspend(dev); 812 ret = acpi_dev_suspend(dev, wakeup);
851 813
852 /* 814 /*
853 * This call must be last in the sequence, otherwise PMC will return 815 * 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)
860 return ret; 822 return ret;
861} 823}
862 824
863static int acpi_lpss_runtime_resume(struct device *dev) 825static int acpi_lpss_resume(struct device *dev)
864{ 826{
865 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); 827 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
866 int ret; 828 int ret;
@@ -872,7 +834,7 @@ static int acpi_lpss_runtime_resume(struct device *dev)
872 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available()) 834 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
873 lpss_iosf_exit_d3_state(); 835 lpss_iosf_exit_d3_state();
874 836
875 ret = acpi_dev_runtime_resume(dev); 837 ret = acpi_dev_resume(dev);
876 if (ret) 838 if (ret)
877 return ret; 839 return ret;
878 840
@@ -881,7 +843,37 @@ static int acpi_lpss_runtime_resume(struct device *dev)
881 if (pdata->dev_desc->flags & LPSS_SAVE_CTX) 843 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
882 acpi_lpss_restore_ctx(dev, pdata); 844 acpi_lpss_restore_ctx(dev, pdata);
883 845
884 return pm_generic_runtime_resume(dev); 846 return 0;
847}
848
849#ifdef CONFIG_PM_SLEEP
850static 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
857static 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
865static 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
872static 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);
885} 877}
886#endif /* CONFIG_PM */ 878#endif /* CONFIG_PM */
887 879
@@ -894,7 +886,7 @@ static struct dev_pm_domain acpi_lpss_pm_domain = {
894#ifdef CONFIG_PM 886#ifdef CONFIG_PM
895#ifdef CONFIG_PM_SLEEP 887#ifdef CONFIG_PM_SLEEP
896 .prepare = acpi_subsys_prepare, 888 .prepare = acpi_subsys_prepare,
897 .complete = pm_complete_with_resume_check, 889 .complete = acpi_subsys_complete,
898 .suspend = acpi_subsys_suspend, 890 .suspend = acpi_subsys_suspend,
899 .suspend_late = acpi_lpss_suspend_late, 891 .suspend_late = acpi_lpss_suspend_late,
900 .resume_early = acpi_lpss_resume_early, 892 .resume_early = acpi_lpss_resume_early,
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index e8c820129797..69ffd1dc1de7 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -387,6 +387,7 @@ EXPORT_SYMBOL(acpi_bus_power_manageable);
387 387
388#ifdef CONFIG_PM 388#ifdef CONFIG_PM
389static DEFINE_MUTEX(acpi_pm_notifier_lock); 389static DEFINE_MUTEX(acpi_pm_notifier_lock);
390static DEFINE_MUTEX(acpi_pm_notifier_install_lock);
390 391
391void acpi_pm_wakeup_event(struct device *dev) 392void acpi_pm_wakeup_event(struct device *dev)
392{ 393{
@@ -443,24 +444,25 @@ acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
443 if (!dev && !func) 444 if (!dev && !func)
444 return AE_BAD_PARAMETER; 445 return AE_BAD_PARAMETER;
445 446
446 mutex_lock(&acpi_pm_notifier_lock); 447 mutex_lock(&acpi_pm_notifier_install_lock);
447 448
448 if (adev->wakeup.flags.notifier_present) 449 if (adev->wakeup.flags.notifier_present)
449 goto out; 450 goto out;
450 451
451 adev->wakeup.ws = wakeup_source_register(dev_name(&adev->dev));
452 adev->wakeup.context.dev = dev;
453 adev->wakeup.context.func = func;
454
455 status = acpi_install_notify_handler(adev->handle, ACPI_SYSTEM_NOTIFY, 452 status = acpi_install_notify_handler(adev->handle, ACPI_SYSTEM_NOTIFY,
456 acpi_pm_notify_handler, NULL); 453 acpi_pm_notify_handler, NULL);
457 if (ACPI_FAILURE(status)) 454 if (ACPI_FAILURE(status))
458 goto out; 455 goto out;
459 456
457 mutex_lock(&acpi_pm_notifier_lock);
458 adev->wakeup.ws = wakeup_source_register(dev_name(&adev->dev));
459 adev->wakeup.context.dev = dev;
460 adev->wakeup.context.func = func;
460 adev->wakeup.flags.notifier_present = true; 461 adev->wakeup.flags.notifier_present = true;
462 mutex_unlock(&acpi_pm_notifier_lock);
461 463
462 out: 464 out:
463 mutex_unlock(&acpi_pm_notifier_lock); 465 mutex_unlock(&acpi_pm_notifier_install_lock);
464 return status; 466 return status;
465} 467}
466 468
@@ -472,7 +474,7 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
472{ 474{
473 acpi_status status = AE_BAD_PARAMETER; 475 acpi_status status = AE_BAD_PARAMETER;
474 476
475 mutex_lock(&acpi_pm_notifier_lock); 477 mutex_lock(&acpi_pm_notifier_install_lock);
476 478
477 if (!adev->wakeup.flags.notifier_present) 479 if (!adev->wakeup.flags.notifier_present)
478 goto out; 480 goto out;
@@ -483,14 +485,15 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
483 if (ACPI_FAILURE(status)) 485 if (ACPI_FAILURE(status))
484 goto out; 486 goto out;
485 487
488 mutex_lock(&acpi_pm_notifier_lock);
486 adev->wakeup.context.func = NULL; 489 adev->wakeup.context.func = NULL;
487 adev->wakeup.context.dev = NULL; 490 adev->wakeup.context.dev = NULL;
488 wakeup_source_unregister(adev->wakeup.ws); 491 wakeup_source_unregister(adev->wakeup.ws);
489
490 adev->wakeup.flags.notifier_present = false; 492 adev->wakeup.flags.notifier_present = false;
493 mutex_unlock(&acpi_pm_notifier_lock);
491 494
492 out: 495 out:
493 mutex_unlock(&acpi_pm_notifier_lock); 496 mutex_unlock(&acpi_pm_notifier_install_lock);
494 return status; 497 return status;
495} 498}
496 499
@@ -847,47 +850,48 @@ static int acpi_dev_pm_full_power(struct acpi_device *adev)
847} 850}
848 851
849/** 852/**
850 * acpi_dev_runtime_suspend - Put device into a low-power state using ACPI. 853 * acpi_dev_suspend - Put device into a low-power state using ACPI.
851 * @dev: Device to put into a low-power state. 854 * @dev: Device to put into a low-power state.
855 * @wakeup: Whether or not to enable wakeup for the device.
852 * 856 *
853 * Put the given device into a runtime low-power state using the standard ACPI 857 * Put the given device into a low-power state using the standard ACPI
854 * mechanism. Set up remote wakeup if desired, choose the state to put the 858 * mechanism. Set up remote wakeup if desired, choose the state to put the
855 * device into (this checks if remote wakeup is expected to work too), and set 859 * device into (this checks if remote wakeup is expected to work too), and set
856 * the power state of the device. 860 * the power state of the device.
857 */ 861 */
858int acpi_dev_runtime_suspend(struct device *dev) 862int acpi_dev_suspend(struct device *dev, bool wakeup)
859{ 863{
860 struct acpi_device *adev = ACPI_COMPANION(dev); 864 struct acpi_device *adev = ACPI_COMPANION(dev);
861 bool remote_wakeup; 865 u32 target_state = acpi_target_system_state();
862 int error; 866 int error;
863 867
864 if (!adev) 868 if (!adev)
865 return 0; 869 return 0;
866 870
867 remote_wakeup = acpi_device_can_wakeup(adev); 871 if (wakeup && acpi_device_can_wakeup(adev)) {
868 if (remote_wakeup) { 872 error = acpi_device_wakeup_enable(adev, target_state);
869 error = acpi_device_wakeup_enable(adev, ACPI_STATE_S0);
870 if (error) 873 if (error)
871 return -EAGAIN; 874 return -EAGAIN;
875 } else {
876 wakeup = false;
872 } 877 }
873 878
874 error = acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0); 879 error = acpi_dev_pm_low_power(dev, adev, target_state);
875 if (error && remote_wakeup) 880 if (error && wakeup)
876 acpi_device_wakeup_disable(adev); 881 acpi_device_wakeup_disable(adev);
877 882
878 return error; 883 return error;
879} 884}
880EXPORT_SYMBOL_GPL(acpi_dev_runtime_suspend); 885EXPORT_SYMBOL_GPL(acpi_dev_suspend);
881 886
882/** 887/**
883 * acpi_dev_runtime_resume - Put device into the full-power state using ACPI. 888 * acpi_dev_resume - Put device into the full-power state using ACPI.
884 * @dev: Device to put into the full-power state. 889 * @dev: Device to put into the full-power state.
885 * 890 *
886 * Put the given device into the full-power state using the standard ACPI 891 * Put the given device into the full-power state using the standard ACPI
887 * mechanism at run time. Set the power state of the device to ACPI D0 and 892 * mechanism. Set the power state of the device to ACPI D0 and disable wakeup.
888 * disable remote wakeup.
889 */ 893 */
890int acpi_dev_runtime_resume(struct device *dev) 894int acpi_dev_resume(struct device *dev)
891{ 895{
892 struct acpi_device *adev = ACPI_COMPANION(dev); 896 struct acpi_device *adev = ACPI_COMPANION(dev);
893 int error; 897 int error;
@@ -899,7 +903,7 @@ int acpi_dev_runtime_resume(struct device *dev)
899 acpi_device_wakeup_disable(adev); 903 acpi_device_wakeup_disable(adev);
900 return error; 904 return error;
901} 905}
902EXPORT_SYMBOL_GPL(acpi_dev_runtime_resume); 906EXPORT_SYMBOL_GPL(acpi_dev_resume);
903 907
904/** 908/**
905 * acpi_subsys_runtime_suspend - Suspend device using ACPI. 909 * acpi_subsys_runtime_suspend - Suspend device using ACPI.
@@ -911,7 +915,7 @@ EXPORT_SYMBOL_GPL(acpi_dev_runtime_resume);
911int acpi_subsys_runtime_suspend(struct device *dev) 915int acpi_subsys_runtime_suspend(struct device *dev)
912{ 916{
913 int ret = pm_generic_runtime_suspend(dev); 917 int ret = pm_generic_runtime_suspend(dev);
914 return ret ? ret : acpi_dev_runtime_suspend(dev); 918 return ret ? ret : acpi_dev_suspend(dev, true);
915} 919}
916EXPORT_SYMBOL_GPL(acpi_subsys_runtime_suspend); 920EXPORT_SYMBOL_GPL(acpi_subsys_runtime_suspend);
917 921
@@ -924,68 +928,32 @@ EXPORT_SYMBOL_GPL(acpi_subsys_runtime_suspend);
924 */ 928 */
925int acpi_subsys_runtime_resume(struct device *dev) 929int acpi_subsys_runtime_resume(struct device *dev)
926{ 930{
927 int ret = acpi_dev_runtime_resume(dev); 931 int ret = acpi_dev_resume(dev);
928 return ret ? ret : pm_generic_runtime_resume(dev); 932 return ret ? ret : pm_generic_runtime_resume(dev);
929} 933}
930EXPORT_SYMBOL_GPL(acpi_subsys_runtime_resume); 934EXPORT_SYMBOL_GPL(acpi_subsys_runtime_resume);
931 935
932#ifdef CONFIG_PM_SLEEP 936#ifdef CONFIG_PM_SLEEP
933/** 937static bool acpi_dev_needs_resume(struct device *dev, struct acpi_device *adev)
934 * acpi_dev_suspend_late - Put device into a low-power state using ACPI.
935 * @dev: Device to put into a low-power state.
936 *
937 * Put the given device into a low-power state during system transition to a
938 * sleep state using the standard ACPI mechanism. Set up system wakeup if
939 * desired, choose the state to put the device into (this checks if system
940 * wakeup is expected to work too), and set the power state of the device.
941 */
942int acpi_dev_suspend_late(struct device *dev)
943{ 938{
944 struct acpi_device *adev = ACPI_COMPANION(dev); 939 u32 sys_target = acpi_target_system_state();
945 u32 target_state; 940 int ret, state;
946 bool wakeup;
947 int error;
948
949 if (!adev)
950 return 0;
951
952 target_state = acpi_target_system_state();
953 wakeup = device_may_wakeup(dev) && acpi_device_can_wakeup(adev);
954 if (wakeup) {
955 error = acpi_device_wakeup_enable(adev, target_state);
956 if (error)
957 return error;
958 }
959 941
960 error = acpi_dev_pm_low_power(dev, adev, target_state); 942 if (device_may_wakeup(dev) != !!adev->wakeup.prepare_count)
961 if (error && wakeup) 943 return true;
962 acpi_device_wakeup_disable(adev);
963 944
964 return error; 945 if (sys_target == ACPI_STATE_S0)
965} 946 return false;
966EXPORT_SYMBOL_GPL(acpi_dev_suspend_late);
967 947
968/** 948 if (adev->power.flags.dsw_present)
969 * acpi_dev_resume_early - Put device into the full-power state using ACPI. 949 return true;
970 * @dev: Device to put into the full-power state.
971 *
972 * Put the given device into the full-power state using the standard ACPI
973 * mechanism during system transition to the working state. Set the power
974 * state of the device to ACPI D0 and disable remote wakeup.
975 */
976int acpi_dev_resume_early(struct device *dev)
977{
978 struct acpi_device *adev = ACPI_COMPANION(dev);
979 int error;
980 950
981 if (!adev) 951 ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state);
982 return 0; 952 if (ret)
953 return true;
983 954
984 error = acpi_dev_pm_full_power(adev); 955 return state != adev->power.state;
985 acpi_device_wakeup_disable(adev);
986 return error;
987} 956}
988EXPORT_SYMBOL_GPL(acpi_dev_resume_early);
989 957
990/** 958/**
991 * acpi_subsys_prepare - Prepare device for system transition to a sleep state. 959 * acpi_subsys_prepare - Prepare device for system transition to a sleep state.
@@ -994,30 +962,37 @@ EXPORT_SYMBOL_GPL(acpi_dev_resume_early);
994int acpi_subsys_prepare(struct device *dev) 962int acpi_subsys_prepare(struct device *dev)
995{ 963{
996 struct acpi_device *adev = ACPI_COMPANION(dev); 964 struct acpi_device *adev = ACPI_COMPANION(dev);
997 u32 sys_target; 965 int ret;
998 int ret, state;
999 966
1000 ret = pm_generic_prepare(dev); 967 ret = pm_generic_prepare(dev);
1001 if (ret < 0) 968 if (ret < 0)
1002 return ret; 969 return ret;
1003 970
1004 if (!adev || !pm_runtime_suspended(dev) 971 if (!adev || !pm_runtime_suspended(dev))
1005 || device_may_wakeup(dev) != !!adev->wakeup.prepare_count)
1006 return 0; 972 return 0;
1007 973
1008 sys_target = acpi_target_system_state(); 974 return !acpi_dev_needs_resume(dev, adev);
1009 if (sys_target == ACPI_STATE_S0)
1010 return 1;
1011
1012 if (adev->power.flags.dsw_present)
1013 return 0;
1014
1015 ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state);
1016 return !ret && state == adev->power.state;
1017} 975}
1018EXPORT_SYMBOL_GPL(acpi_subsys_prepare); 976EXPORT_SYMBOL_GPL(acpi_subsys_prepare);
1019 977
1020/** 978/**
979 * acpi_subsys_complete - Finalize device's resume during system resume.
980 * @dev: Device to handle.
981 */
982void acpi_subsys_complete(struct device *dev)
983{
984 pm_generic_complete(dev);
985 /*
986 * If the device had been runtime-suspended before the system went into
987 * the sleep state it is going out of and it has never been resumed till
988 * now, resume it in case the firmware powered it up.
989 */
990 if (dev->power.direct_complete && pm_resume_via_firmware())
991 pm_request_resume(dev);
992}
993EXPORT_SYMBOL_GPL(acpi_subsys_complete);
994
995/**
1021 * acpi_subsys_suspend - Run the device driver's suspend callback. 996 * acpi_subsys_suspend - Run the device driver's suspend callback.
1022 * @dev: Device to handle. 997 * @dev: Device to handle.
1023 * 998 *
@@ -1041,7 +1016,7 @@ EXPORT_SYMBOL_GPL(acpi_subsys_suspend);
1041int acpi_subsys_suspend_late(struct device *dev) 1016int acpi_subsys_suspend_late(struct device *dev)
1042{ 1017{
1043 int ret = pm_generic_suspend_late(dev); 1018 int ret = pm_generic_suspend_late(dev);
1044 return ret ? ret : acpi_dev_suspend_late(dev); 1019 return ret ? ret : acpi_dev_suspend(dev, device_may_wakeup(dev));
1045} 1020}
1046EXPORT_SYMBOL_GPL(acpi_subsys_suspend_late); 1021EXPORT_SYMBOL_GPL(acpi_subsys_suspend_late);
1047 1022
@@ -1055,7 +1030,7 @@ EXPORT_SYMBOL_GPL(acpi_subsys_suspend_late);
1055 */ 1030 */
1056int acpi_subsys_resume_early(struct device *dev) 1031int acpi_subsys_resume_early(struct device *dev)
1057{ 1032{
1058 int ret = acpi_dev_resume_early(dev); 1033 int ret = acpi_dev_resume(dev);
1059 return ret ? ret : pm_generic_resume_early(dev); 1034 return ret ? ret : pm_generic_resume_early(dev);
1060} 1035}
1061EXPORT_SYMBOL_GPL(acpi_subsys_resume_early); 1036EXPORT_SYMBOL_GPL(acpi_subsys_resume_early);
@@ -1085,7 +1060,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
1085 .runtime_resume = acpi_subsys_runtime_resume, 1060 .runtime_resume = acpi_subsys_runtime_resume,
1086#ifdef CONFIG_PM_SLEEP 1061#ifdef CONFIG_PM_SLEEP
1087 .prepare = acpi_subsys_prepare, 1062 .prepare = acpi_subsys_prepare,
1088 .complete = pm_complete_with_resume_check, 1063 .complete = acpi_subsys_complete,
1089 .suspend = acpi_subsys_suspend, 1064 .suspend = acpi_subsys_suspend,
1090 .suspend_late = acpi_subsys_suspend_late, 1065 .suspend_late = acpi_subsys_suspend_late,
1091 .resume_early = acpi_subsys_resume_early, 1066 .resume_early = acpi_subsys_resume_early,
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 4361c4415b4f..fc8c43e76707 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -248,4 +248,10 @@ void acpi_watchdog_init(void);
248static inline void acpi_watchdog_init(void) {} 248static inline void acpi_watchdog_init(void) {}
249#endif 249#endif
250 250
251#ifdef CONFIG_ACPI_LPIT
252void acpi_init_lpit(void);
253#else
254static inline void acpi_init_lpit(void) { }
255#endif
256
251#endif /* _ACPI_INTERNAL_H_ */ 257#endif /* _ACPI_INTERNAL_H_ */
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index db78d353bab1..3bb46cb24a99 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -663,6 +663,29 @@ acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
663 663
664EXPORT_SYMBOL(acpi_os_write_port); 664EXPORT_SYMBOL(acpi_os_write_port);
665 665
666int acpi_os_read_iomem(void __iomem *virt_addr, u64 *value, u32 width)
667{
668
669 switch (width) {
670 case 8:
671 *(u8 *) value = readb(virt_addr);
672 break;
673 case 16:
674 *(u16 *) value = readw(virt_addr);
675 break;
676 case 32:
677 *(u32 *) value = readl(virt_addr);
678 break;
679 case 64:
680 *(u64 *) value = readq(virt_addr);
681 break;
682 default:
683 return -EINVAL;
684 }
685
686 return 0;
687}
688
666acpi_status 689acpi_status
667acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width) 690acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
668{ 691{
@@ -670,6 +693,7 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
670 unsigned int size = width / 8; 693 unsigned int size = width / 8;
671 bool unmap = false; 694 bool unmap = false;
672 u64 dummy; 695 u64 dummy;
696 int error;
673 697
674 rcu_read_lock(); 698 rcu_read_lock();
675 virt_addr = acpi_map_vaddr_lookup(phys_addr, size); 699 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
@@ -684,22 +708,8 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
684 if (!value) 708 if (!value)
685 value = &dummy; 709 value = &dummy;
686 710
687 switch (width) { 711 error = acpi_os_read_iomem(virt_addr, value, width);
688 case 8: 712 BUG_ON(error);
689 *(u8 *) value = readb(virt_addr);
690 break;
691 case 16:
692 *(u16 *) value = readw(virt_addr);
693 break;
694 case 32:
695 *(u32 *) value = readl(virt_addr);
696 break;
697 case 64:
698 *(u64 *) value = readq(virt_addr);
699 break;
700 default:
701 BUG();
702 }
703 713
704 if (unmap) 714 if (unmap)
705 iounmap(virt_addr); 715 iounmap(virt_addr);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 602f8ff212f2..81367edc8a10 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2122,6 +2122,7 @@ int __init acpi_scan_init(void)
2122 acpi_int340x_thermal_init(); 2122 acpi_int340x_thermal_init();
2123 acpi_amba_init(); 2123 acpi_amba_init();
2124 acpi_watchdog_init(); 2124 acpi_watchdog_init();
2125 acpi_init_lpit();
2125 2126
2126 acpi_scan_add_handler(&generic_device_handler); 2127 acpi_scan_add_handler(&generic_device_handler);
2127 2128
diff --git a/include/acpi/acpiosxf.h b/include/acpi/acpiosxf.h
index c66eb8ffa454..d5c0f5153c4e 100644
--- a/include/acpi/acpiosxf.h
+++ b/include/acpi/acpiosxf.h
@@ -287,6 +287,8 @@ acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width);
287/* 287/*
288 * Platform and hardware-independent physical memory interfaces 288 * Platform and hardware-independent physical memory interfaces
289 */ 289 */
290int acpi_os_read_iomem(void __iomem *virt_addr, u64 *value, u32 width);
291
290#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_read_memory 292#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_read_memory
291acpi_status 293acpi_status
292acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width); 294acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width);
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 502af53ec012..0ada2a948b44 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -864,21 +864,16 @@ static inline void arch_reserve_mem_area(acpi_physical_address addr,
864#endif 864#endif
865 865
866#if defined(CONFIG_ACPI) && defined(CONFIG_PM) 866#if defined(CONFIG_ACPI) && defined(CONFIG_PM)
867int acpi_dev_runtime_suspend(struct device *dev); 867int acpi_dev_suspend(struct device *dev, bool wakeup);
868int acpi_dev_runtime_resume(struct device *dev); 868int acpi_dev_resume(struct device *dev);
869int acpi_subsys_runtime_suspend(struct device *dev); 869int acpi_subsys_runtime_suspend(struct device *dev);
870int acpi_subsys_runtime_resume(struct device *dev); 870int acpi_subsys_runtime_resume(struct device *dev);
871struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
872int acpi_dev_pm_attach(struct device *dev, bool power_on); 871int acpi_dev_pm_attach(struct device *dev, bool power_on);
873#else 872#else
874static inline int acpi_dev_runtime_suspend(struct device *dev) { return 0; } 873static inline int acpi_dev_runtime_suspend(struct device *dev) { return 0; }
875static inline int acpi_dev_runtime_resume(struct device *dev) { return 0; } 874static inline int acpi_dev_runtime_resume(struct device *dev) { return 0; }
876static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; } 875static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; }
877static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; } 876static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; }
878static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
879{
880 return NULL;
881}
882static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) 877static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
883{ 878{
884 return -ENODEV; 879 return -ENODEV;
@@ -887,7 +882,6 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
887 882
888#if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP) 883#if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP)
889int acpi_dev_suspend_late(struct device *dev); 884int acpi_dev_suspend_late(struct device *dev);
890int acpi_dev_resume_early(struct device *dev);
891int acpi_subsys_prepare(struct device *dev); 885int acpi_subsys_prepare(struct device *dev);
892void acpi_subsys_complete(struct device *dev); 886void acpi_subsys_complete(struct device *dev);
893int acpi_subsys_suspend_late(struct device *dev); 887int acpi_subsys_suspend_late(struct device *dev);
@@ -895,7 +889,6 @@ int acpi_subsys_resume_early(struct device *dev);
895int acpi_subsys_suspend(struct device *dev); 889int acpi_subsys_suspend(struct device *dev);
896int acpi_subsys_freeze(struct device *dev); 890int acpi_subsys_freeze(struct device *dev);
897#else 891#else
898static inline int acpi_dev_suspend_late(struct device *dev) { return 0; }
899static inline int acpi_dev_resume_early(struct device *dev) { return 0; } 892static inline int acpi_dev_resume_early(struct device *dev) { return 0; }
900static inline int acpi_subsys_prepare(struct device *dev) { return 0; } 893static inline int acpi_subsys_prepare(struct device *dev) { return 0; }
901static inline void acpi_subsys_complete(struct device *dev) {} 894static inline void acpi_subsys_complete(struct device *dev) {}
@@ -1254,4 +1247,13 @@ int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res)
1254} 1247}
1255#endif 1248#endif
1256 1249
1250#ifdef CONFIG_ACPI_LPIT
1251int lpit_read_residency_count_address(u64 *address);
1252#else
1253static inline int lpit_read_residency_count_address(u64 *address)
1254{
1255 return -EINVAL;
1256}
1257#endif
1258
1257#endif /*_LINUX_ACPI_H*/ 1259#endif /*_LINUX_ACPI_H*/