2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* File: pci-acpi.c
|
2005-03-24 04:16:03 +07:00
|
|
|
* Purpose: Provide PCI support in ACPI
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2005-03-19 06:53:36 +07:00
|
|
|
* Copyright (C) 2005 David Shaohua Li <shaohua.li@intel.com>
|
|
|
|
* Copyright (C) 2004 Tom Long Nguyen <tom.l.nguyen@intel.com>
|
|
|
|
* Copyright (C) 2004 Intel Corp.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/module.h>
|
2008-07-23 09:32:24 +07:00
|
|
|
#include <linux/pci-aspm.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <acpi/acpi.h>
|
|
|
|
#include <acpi/acpi_bus.h>
|
|
|
|
|
|
|
|
#include <linux/pci-acpi.h>
|
2010-02-18 05:44:09 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
2005-03-19 12:15:48 +07:00
|
|
|
#include "pci.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-02-18 05:44:09 +07:00
|
|
|
static DEFINE_MUTEX(pci_acpi_pm_notify_mtx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_acpi_wake_bus - Wake-up notification handler for root buses.
|
|
|
|
* @handle: ACPI handle of a device the notification is for.
|
|
|
|
* @event: Type of the signaled event.
|
|
|
|
* @context: PCI root bus to wake up devices on.
|
|
|
|
*/
|
|
|
|
static void pci_acpi_wake_bus(acpi_handle handle, u32 event, void *context)
|
|
|
|
{
|
|
|
|
struct pci_bus *pci_bus = context;
|
|
|
|
|
|
|
|
if (event == ACPI_NOTIFY_DEVICE_WAKE && pci_bus)
|
|
|
|
pci_pme_wakeup_bus(pci_bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_acpi_wake_dev - Wake-up notification handler for PCI devices.
|
|
|
|
* @handle: ACPI handle of a device the notification is for.
|
|
|
|
* @event: Type of the signaled event.
|
|
|
|
* @context: PCI device object to wake up.
|
|
|
|
*/
|
|
|
|
static void pci_acpi_wake_dev(acpi_handle handle, u32 event, void *context)
|
|
|
|
{
|
|
|
|
struct pci_dev *pci_dev = context;
|
|
|
|
|
|
|
|
if (event == ACPI_NOTIFY_DEVICE_WAKE && pci_dev) {
|
|
|
|
pci_check_pme_status(pci_dev);
|
|
|
|
pm_runtime_resume(&pci_dev->dev);
|
PM: Make it possible to avoid races between wakeup and system sleep
One of the arguments during the suspend blockers discussion was that
the mainline kernel didn't contain any mechanisms making it possible
to avoid races between wakeup and system suspend.
Generally, there are two problems in that area. First, if a wakeup
event occurs exactly when /sys/power/state is being written to, it
may be delivered to user space right before the freezer kicks in, so
the user space consumer of the event may not be able to process it
before the system is suspended. Second, if a wakeup event occurs
after user space has been frozen, it is not generally guaranteed that
the ongoing transition of the system into a sleep state will be
aborted.
To address these issues introduce a new global sysfs attribute,
/sys/power/wakeup_count, associated with a running counter of wakeup
events and three helper functions, pm_stay_awake(), pm_relax(), and
pm_wakeup_event(), that may be used by kernel subsystems to control
the behavior of this attribute and to request the PM core to abort
system transitions into a sleep state already in progress.
The /sys/power/wakeup_count file may be read from or written to by
user space. Reads will always succeed (unless interrupted by a
signal) and return the current value of the wakeup events counter.
Writes, however, will only succeed if the written number is equal to
the current value of the wakeup events counter. If a write is
successful, it will cause the kernel to save the current value of the
wakeup events counter and to abort the subsequent system transition
into a sleep state if any wakeup events are reported after the write
has returned.
[The assumption is that before writing to /sys/power/state user space
will first read from /sys/power/wakeup_count. Next, user space
consumers of wakeup events will have a chance to acknowledge or
veto the upcoming system transition to a sleep state. Finally, if
the transition is allowed to proceed, /sys/power/wakeup_count will
be written to and if that succeeds, /sys/power/state will be written
to as well. Still, if any wakeup events are reported to the PM core
by kernel subsystems after that point, the transition will be
aborted.]
Additionally, put a wakeup events counter into struct dev_pm_info and
make these per-device wakeup event counters available via sysfs,
so that it's possible to check the activity of various wakeup event
sources within the kernel.
To illustrate how subsystems can use pm_wakeup_event(), make the
low-level PCI runtime PM wakeup-handling code use it.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: markgross <markgross@thegnar.org>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
2010-07-06 03:43:53 +07:00
|
|
|
pci_wakeup_event(pci_dev);
|
2010-02-18 05:44:09 +07:00
|
|
|
if (pci_dev->subordinate)
|
|
|
|
pci_pme_wakeup_bus(pci_dev->subordinate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add_pm_notifier - Register PM notifier for given ACPI device.
|
|
|
|
* @dev: ACPI device to add the notifier for.
|
|
|
|
* @context: PCI device or bus to check for PME status if an event is signaled.
|
|
|
|
*
|
|
|
|
* NOTE: @dev need not be a run-wake or wake-up device to be a valid source of
|
|
|
|
* PM wake-up events. For example, wake-up events may be generated for bridges
|
|
|
|
* if one of the devices below the bridge is signaling PME, even if the bridge
|
|
|
|
* itself doesn't have a wake-up GPE associated with it.
|
|
|
|
*/
|
|
|
|
static acpi_status add_pm_notifier(struct acpi_device *dev,
|
|
|
|
acpi_notify_handler handler,
|
|
|
|
void *context)
|
|
|
|
{
|
|
|
|
acpi_status status = AE_ALREADY_EXISTS;
|
|
|
|
|
|
|
|
mutex_lock(&pci_acpi_pm_notify_mtx);
|
|
|
|
|
|
|
|
if (dev->wakeup.flags.notifier_present)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
status = acpi_install_notify_handler(dev->handle,
|
|
|
|
ACPI_SYSTEM_NOTIFY,
|
|
|
|
handler, context);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
dev->wakeup.flags.notifier_present = true;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&pci_acpi_pm_notify_mtx);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove_pm_notifier - Unregister PM notifier from given ACPI device.
|
|
|
|
* @dev: ACPI device to remove the notifier from.
|
|
|
|
*/
|
|
|
|
static acpi_status remove_pm_notifier(struct acpi_device *dev,
|
|
|
|
acpi_notify_handler handler)
|
|
|
|
{
|
|
|
|
acpi_status status = AE_BAD_PARAMETER;
|
|
|
|
|
|
|
|
mutex_lock(&pci_acpi_pm_notify_mtx);
|
|
|
|
|
|
|
|
if (!dev->wakeup.flags.notifier_present)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
status = acpi_remove_notify_handler(dev->handle,
|
|
|
|
ACPI_SYSTEM_NOTIFY,
|
|
|
|
handler);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
dev->wakeup.flags.notifier_present = false;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&pci_acpi_pm_notify_mtx);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_acpi_add_bus_pm_notifier - Register PM notifier for given PCI bus.
|
|
|
|
* @dev: ACPI device to add the notifier for.
|
|
|
|
* @pci_bus: PCI bus to walk checking for PME status if an event is signaled.
|
|
|
|
*/
|
|
|
|
acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev,
|
|
|
|
struct pci_bus *pci_bus)
|
|
|
|
{
|
|
|
|
return add_pm_notifier(dev, pci_acpi_wake_bus, pci_bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_acpi_remove_bus_pm_notifier - Unregister PCI bus PM notifier.
|
|
|
|
* @dev: ACPI device to remove the notifier from.
|
|
|
|
*/
|
|
|
|
acpi_status pci_acpi_remove_bus_pm_notifier(struct acpi_device *dev)
|
|
|
|
{
|
|
|
|
return remove_pm_notifier(dev, pci_acpi_wake_bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_acpi_add_pm_notifier - Register PM notifier for given PCI device.
|
|
|
|
* @dev: ACPI device to add the notifier for.
|
|
|
|
* @pci_dev: PCI device to check for the PME status if an event is signaled.
|
|
|
|
*/
|
|
|
|
acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev,
|
|
|
|
struct pci_dev *pci_dev)
|
|
|
|
{
|
|
|
|
return add_pm_notifier(dev, pci_acpi_wake_dev, pci_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_acpi_remove_pm_notifier - Unregister PCI device PM notifier.
|
|
|
|
* @dev: ACPI device to remove the notifier from.
|
|
|
|
*/
|
|
|
|
acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev)
|
|
|
|
{
|
|
|
|
return remove_pm_notifier(dev, pci_acpi_wake_dev);
|
|
|
|
}
|
|
|
|
|
2005-03-19 12:15:48 +07:00
|
|
|
/*
|
|
|
|
* _SxD returns the D-state with the highest power
|
|
|
|
* (lowest D-state number) supported in the S-state "x".
|
|
|
|
*
|
|
|
|
* If the devices does not have a _PRW
|
|
|
|
* (Power Resources for Wake) supporting system wakeup from "x"
|
|
|
|
* then the OS is free to choose a lower power (higher number
|
|
|
|
* D-state) than the return value from _SxD.
|
|
|
|
*
|
|
|
|
* But if _PRW is enabled at S-state "x", the OS
|
|
|
|
* must not choose a power lower than _SxD --
|
|
|
|
* unless the device has an _SxW method specifying
|
|
|
|
* the lowest power (highest D-state number) the device
|
|
|
|
* may enter while still able to wake the system.
|
|
|
|
*
|
|
|
|
* ie. depending on global OS policy:
|
|
|
|
*
|
|
|
|
* if (_PRW at S-state x)
|
|
|
|
* choose from highest power _SxD to lowest power _SxW
|
|
|
|
* else // no _PRW at S-state x
|
|
|
|
* choose highest power _SxD or any lower power
|
|
|
|
*/
|
|
|
|
|
2008-06-05 06:16:37 +07:00
|
|
|
static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
|
2005-03-19 12:15:48 +07:00
|
|
|
{
|
2007-07-20 09:03:22 +07:00
|
|
|
int acpi_state;
|
2005-03-19 12:15:48 +07:00
|
|
|
|
2008-06-05 06:15:40 +07:00
|
|
|
acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL);
|
2007-07-20 09:03:22 +07:00
|
|
|
if (acpi_state < 0)
|
|
|
|
return PCI_POWER_ERROR;
|
|
|
|
|
|
|
|
switch (acpi_state) {
|
|
|
|
case ACPI_STATE_D0:
|
|
|
|
return PCI_D0;
|
|
|
|
case ACPI_STATE_D1:
|
|
|
|
return PCI_D1;
|
|
|
|
case ACPI_STATE_D2:
|
|
|
|
return PCI_D2;
|
|
|
|
case ACPI_STATE_D3:
|
|
|
|
return PCI_D3hot;
|
|
|
|
}
|
|
|
|
return PCI_POWER_ERROR;
|
2005-03-19 12:15:48 +07:00
|
|
|
}
|
2008-07-07 08:32:02 +07:00
|
|
|
|
|
|
|
static bool acpi_pci_power_manageable(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
|
|
|
|
|
|
|
|
return handle ? acpi_bus_power_manageable(handle) : false;
|
|
|
|
}
|
2005-03-19 12:15:48 +07:00
|
|
|
|
2005-03-19 12:16:18 +07:00
|
|
|
static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
|
|
|
|
{
|
|
|
|
acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
|
2007-07-20 09:03:25 +07:00
|
|
|
acpi_handle tmp;
|
2008-02-23 12:41:51 +07:00
|
|
|
static const u8 state_conv[] = {
|
|
|
|
[PCI_D0] = ACPI_STATE_D0,
|
|
|
|
[PCI_D1] = ACPI_STATE_D1,
|
|
|
|
[PCI_D2] = ACPI_STATE_D2,
|
|
|
|
[PCI_D3hot] = ACPI_STATE_D3,
|
|
|
|
[PCI_D3cold] = ACPI_STATE_D3
|
2005-03-19 12:16:18 +07:00
|
|
|
};
|
2008-07-07 08:32:52 +07:00
|
|
|
int error = -EINVAL;
|
2005-03-19 12:16:18 +07:00
|
|
|
|
2007-07-20 09:03:25 +07:00
|
|
|
/* If the ACPI device has _EJ0, ignore the device */
|
2008-07-07 08:32:52 +07:00
|
|
|
if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
|
|
|
|
return -ENODEV;
|
2008-02-23 12:41:51 +07:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case PCI_D0:
|
|
|
|
case PCI_D1:
|
|
|
|
case PCI_D2:
|
|
|
|
case PCI_D3hot:
|
|
|
|
case PCI_D3cold:
|
2008-07-07 08:32:52 +07:00
|
|
|
error = acpi_bus_set_power(handle, state_conv[state]);
|
2008-02-23 12:41:51 +07:00
|
|
|
}
|
2008-07-07 08:32:52 +07:00
|
|
|
|
|
|
|
if (!error)
|
|
|
|
dev_printk(KERN_INFO, &dev->dev,
|
|
|
|
"power state changed by ACPI to D%d\n", state);
|
|
|
|
|
|
|
|
return error;
|
2005-03-19 12:16:18 +07:00
|
|
|
}
|
|
|
|
|
2008-07-07 08:34:48 +07:00
|
|
|
static bool acpi_pci_can_wakeup(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
|
|
|
|
|
|
|
|
return handle ? acpi_bus_can_wakeup(handle) : false;
|
|
|
|
}
|
|
|
|
|
PCI / ACPI PM: Propagate wake-up enable for devices w/o ACPI support
Some PCI devices (not PCI Express), like PCI add-on cards, can
generate PME#, but they don't have any special platform wake-up
support. For this reason, even if they generate PME# to wake up the
system from a sleep state, wake-up events are not generated by the
platform.
It turns out that, at least on some systems, PCI bridges and the PCI
host bridge have ACPI GPEs associated with them that, if enabled to
generate wake-up events, allow the system to wake up if one of the
add-on devices asserts PME# while the system is in a sleep state.
Following this observation, if a PCI device without direct ACPI
wake-up support is prepared to wake up the system during a transition
into a sleep state (eg. suspend to RAM), try to configure the bridges
on the path from the device to the root bridge to wake-up the system.
Reviewed-by: Matthew Garrett <mjg59@srcf.ucam.org>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-09 04:16:24 +07:00
|
|
|
static void acpi_pci_propagate_wakeup_enable(struct pci_bus *bus, bool enable)
|
|
|
|
{
|
|
|
|
while (bus->parent) {
|
2009-11-29 22:35:54 +07:00
|
|
|
if (!acpi_pm_device_sleep_wake(&bus->self->dev, enable))
|
PCI / ACPI PM: Propagate wake-up enable for devices w/o ACPI support
Some PCI devices (not PCI Express), like PCI add-on cards, can
generate PME#, but they don't have any special platform wake-up
support. For this reason, even if they generate PME# to wake up the
system from a sleep state, wake-up events are not generated by the
platform.
It turns out that, at least on some systems, PCI bridges and the PCI
host bridge have ACPI GPEs associated with them that, if enabled to
generate wake-up events, allow the system to wake up if one of the
add-on devices asserts PME# while the system is in a sleep state.
Following this observation, if a PCI device without direct ACPI
wake-up support is prepared to wake up the system during a transition
into a sleep state (eg. suspend to RAM), try to configure the bridges
on the path from the device to the root bridge to wake-up the system.
Reviewed-by: Matthew Garrett <mjg59@srcf.ucam.org>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-09 04:16:24 +07:00
|
|
|
return;
|
|
|
|
bus = bus->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have reached the root bus. */
|
|
|
|
if (bus->bridge)
|
|
|
|
acpi_pm_device_sleep_wake(bus->bridge, enable);
|
|
|
|
}
|
|
|
|
|
2008-07-07 08:34:48 +07:00
|
|
|
static int acpi_pci_sleep_wake(struct pci_dev *dev, bool enable)
|
|
|
|
{
|
PCI / ACPI PM: Propagate wake-up enable for devices w/o ACPI support
Some PCI devices (not PCI Express), like PCI add-on cards, can
generate PME#, but they don't have any special platform wake-up
support. For this reason, even if they generate PME# to wake up the
system from a sleep state, wake-up events are not generated by the
platform.
It turns out that, at least on some systems, PCI bridges and the PCI
host bridge have ACPI GPEs associated with them that, if enabled to
generate wake-up events, allow the system to wake up if one of the
add-on devices asserts PME# while the system is in a sleep state.
Following this observation, if a PCI device without direct ACPI
wake-up support is prepared to wake up the system during a transition
into a sleep state (eg. suspend to RAM), try to configure the bridges
on the path from the device to the root bridge to wake-up the system.
Reviewed-by: Matthew Garrett <mjg59@srcf.ucam.org>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-09 04:16:24 +07:00
|
|
|
if (acpi_pci_can_wakeup(dev))
|
|
|
|
return acpi_pm_device_sleep_wake(&dev->dev, enable);
|
|
|
|
|
2009-11-29 22:35:54 +07:00
|
|
|
acpi_pci_propagate_wakeup_enable(dev->bus, enable);
|
PCI / ACPI PM: Propagate wake-up enable for devices w/o ACPI support
Some PCI devices (not PCI Express), like PCI add-on cards, can
generate PME#, but they don't have any special platform wake-up
support. For this reason, even if they generate PME# to wake up the
system from a sleep state, wake-up events are not generated by the
platform.
It turns out that, at least on some systems, PCI bridges and the PCI
host bridge have ACPI GPEs associated with them that, if enabled to
generate wake-up events, allow the system to wake up if one of the
add-on devices asserts PME# while the system is in a sleep state.
Following this observation, if a PCI device without direct ACPI
wake-up support is prepared to wake up the system during a transition
into a sleep state (eg. suspend to RAM), try to configure the bridges
on the path from the device to the root bridge to wake-up the system.
Reviewed-by: Matthew Garrett <mjg59@srcf.ucam.org>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-09 04:16:24 +07:00
|
|
|
return 0;
|
2008-07-07 08:34:48 +07:00
|
|
|
}
|
|
|
|
|
2010-02-18 05:44:09 +07:00
|
|
|
/**
|
|
|
|
* acpi_dev_run_wake - Enable/disable wake-up for given device.
|
|
|
|
* @phys_dev: Device to enable/disable the platform to wake-up the system for.
|
|
|
|
* @enable: Whether enable or disable the wake-up functionality.
|
|
|
|
*
|
|
|
|
* Find the ACPI device object corresponding to @pci_dev and try to
|
|
|
|
* enable/disable the GPE associated with it.
|
|
|
|
*/
|
|
|
|
static int acpi_dev_run_wake(struct device *phys_dev, bool enable)
|
|
|
|
{
|
|
|
|
struct acpi_device *dev;
|
|
|
|
acpi_handle handle;
|
|
|
|
int error = -ENODEV;
|
|
|
|
|
|
|
|
if (!device_run_wake(phys_dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
handle = DEVICE_ACPI_HANDLE(phys_dev);
|
|
|
|
if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) {
|
|
|
|
dev_dbg(phys_dev, "ACPI handle has no context in %s!\n",
|
|
|
|
__func__);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
if (!dev->wakeup.run_wake_count++) {
|
|
|
|
acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0);
|
|
|
|
acpi_enable_gpe(dev->wakeup.gpe_device,
|
2010-07-01 09:11:45 +07:00
|
|
|
dev->wakeup.gpe_number);
|
2010-02-18 05:44:09 +07:00
|
|
|
}
|
|
|
|
} else if (dev->wakeup.run_wake_count > 0) {
|
|
|
|
if (!--dev->wakeup.run_wake_count) {
|
|
|
|
acpi_disable_gpe(dev->wakeup.gpe_device,
|
2010-07-01 09:11:45 +07:00
|
|
|
dev->wakeup.gpe_number);
|
2010-02-18 05:44:09 +07:00
|
|
|
acpi_disable_wakeup_device_power(dev);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = -EALREADY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acpi_pci_propagate_run_wake(struct pci_bus *bus, bool enable)
|
|
|
|
{
|
|
|
|
while (bus->parent) {
|
|
|
|
struct pci_dev *bridge = bus->self;
|
|
|
|
|
|
|
|
if (bridge->pme_interrupt)
|
|
|
|
return;
|
|
|
|
if (!acpi_dev_run_wake(&bridge->dev, enable))
|
|
|
|
return;
|
|
|
|
bus = bus->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have reached the root bus. */
|
|
|
|
if (bus->bridge)
|
|
|
|
acpi_dev_run_wake(bus->bridge, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int acpi_pci_run_wake(struct pci_dev *dev, bool enable)
|
|
|
|
{
|
|
|
|
if (dev->pme_interrupt)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!acpi_dev_run_wake(&dev->dev, enable))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
acpi_pci_propagate_run_wake(dev->bus, enable);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-07 08:32:02 +07:00
|
|
|
static struct pci_platform_pm_ops acpi_pci_platform_pm = {
|
|
|
|
.is_manageable = acpi_pci_power_manageable,
|
|
|
|
.set_state = acpi_pci_set_power_state,
|
|
|
|
.choose_state = acpi_pci_choose_state,
|
2008-07-07 08:34:48 +07:00
|
|
|
.can_wakeup = acpi_pci_can_wakeup,
|
|
|
|
.sleep_wake = acpi_pci_sleep_wake,
|
2010-02-18 05:44:09 +07:00
|
|
|
.run_wake = acpi_pci_run_wake,
|
2008-07-07 08:32:02 +07:00
|
|
|
};
|
2005-03-19 12:16:18 +07:00
|
|
|
|
2005-03-19 06:53:36 +07:00
|
|
|
/* ACPI bus type */
|
2006-04-28 14:42:21 +07:00
|
|
|
static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
|
2005-03-19 06:53:36 +07:00
|
|
|
{
|
|
|
|
struct pci_dev * pci_dev;
|
2010-01-28 09:53:19 +07:00
|
|
|
u64 addr;
|
2005-03-19 06:53:36 +07:00
|
|
|
|
|
|
|
pci_dev = to_pci_dev(dev);
|
|
|
|
/* Please ref to ACPI spec for the syntax of _ADR */
|
|
|
|
addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
|
|
|
|
*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
|
|
|
|
if (!*handle)
|
|
|
|
return -ENODEV;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-28 14:42:21 +07:00
|
|
|
static int acpi_pci_find_root_bridge(struct device *dev, acpi_handle *handle)
|
2005-03-19 06:53:36 +07:00
|
|
|
{
|
|
|
|
int num;
|
|
|
|
unsigned int seg, bus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The string should be the same as root bridge's name
|
|
|
|
* Please look at 'pci_scan_bus_parented'
|
|
|
|
*/
|
2008-10-30 08:17:49 +07:00
|
|
|
num = sscanf(dev_name(dev), "pci%04x:%02x", &seg, &bus);
|
2005-03-19 06:53:36 +07:00
|
|
|
if (num != 2)
|
|
|
|
return -ENODEV;
|
|
|
|
*handle = acpi_get_pci_rootbridge_handle(seg, bus);
|
|
|
|
if (!*handle)
|
|
|
|
return -ENODEV;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-28 14:42:21 +07:00
|
|
|
static struct acpi_bus_type acpi_pci_bus = {
|
2005-03-19 06:53:36 +07:00
|
|
|
.bus = &pci_bus_type,
|
2006-04-28 14:42:21 +07:00
|
|
|
.find_device = acpi_pci_find_device,
|
|
|
|
.find_bridge = acpi_pci_find_root_bridge,
|
2005-03-19 06:53:36 +07:00
|
|
|
};
|
|
|
|
|
2006-04-28 14:42:21 +07:00
|
|
|
static int __init acpi_pci_init(void)
|
2005-03-19 06:53:36 +07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2009-02-03 14:14:33 +07:00
|
|
|
if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) {
|
2007-04-25 10:05:12 +07:00
|
|
|
printk(KERN_INFO"ACPI FADT declares the system doesn't support MSI, so disable it\n");
|
|
|
|
pci_no_msi();
|
|
|
|
}
|
2008-07-23 09:32:24 +07:00
|
|
|
|
2009-02-03 14:14:33 +07:00
|
|
|
if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
|
2008-07-23 09:32:24 +07:00
|
|
|
printk(KERN_INFO"ACPI FADT declares the system doesn't support PCIe ASPM, so disable it\n");
|
|
|
|
pcie_no_aspm();
|
|
|
|
}
|
|
|
|
|
2006-04-28 14:42:21 +07:00
|
|
|
ret = register_acpi_bus_type(&acpi_pci_bus);
|
2005-03-19 06:53:36 +07:00
|
|
|
if (ret)
|
|
|
|
return 0;
|
2008-07-07 08:32:02 +07:00
|
|
|
pci_set_platform_pm(&acpi_pci_platform_pm);
|
2005-03-19 06:53:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2006-04-28 14:42:21 +07:00
|
|
|
arch_initcall(acpi_pci_init);
|