Merge branches 'acpi-pm' and 'pm-pci'
* acpi-pm: ACPI: PM: Make acpi_sleep_state_supported() non-static ACPI: PM: Allow transitions to D0 to occur in special cases ACPI: PM: Avoid evaluating _PS3 on transitions from D3hot to D3cold ACPI / sleep: Switch to use acpi_dev_get_first_match_dev() ACPI / LPIT: Correct LPIT end address for lpit_process() * pm-pci: ACPI: PM: Unexport acpi_device_get_power() PCI: PM/ACPI: Refresh all stale power state data in pci_pm_complete() PCI / ACPI: Add _PR0 dependent devices ACPI / PM: Introduce concept of a _PR0 dependent device PCI / ACPI: Use cached ACPI device state to get PCI device power state PCI: Do not poll for PME if the device is in D3cold PCI: Add missing link delays required by the PCIe spec PCI: PM: Replace pci_dev_keep_suspended() with two functions PCI: PM: Avoid resuming devices in D3hot during system suspend
This commit is contained in:
commit
50e163d43a
|
@ -129,7 +129,7 @@ static void lpit_update_residency(struct lpit_residency_info *info,
|
||||||
|
|
||||||
static void lpit_process(u64 begin, u64 end)
|
static void lpit_process(u64 begin, u64 end)
|
||||||
{
|
{
|
||||||
while (begin + sizeof(struct acpi_lpit_native) < end) {
|
while (begin + sizeof(struct acpi_lpit_native) <= end) {
|
||||||
struct acpi_lpit_native *lpit_native = (struct acpi_lpit_native *)begin;
|
struct acpi_lpit_native *lpit_native = (struct acpi_lpit_native *)begin;
|
||||||
|
|
||||||
if (!lpit_native->header.type && !lpit_native->header.flags) {
|
if (!lpit_native->header.type && !lpit_native->header.flags) {
|
||||||
|
@ -148,7 +148,6 @@ static void lpit_process(u64 begin, u64 end)
|
||||||
void acpi_init_lpit(void)
|
void acpi_init_lpit(void)
|
||||||
{
|
{
|
||||||
acpi_status status;
|
acpi_status status;
|
||||||
u64 lpit_begin;
|
|
||||||
struct acpi_table_lpit *lpit;
|
struct acpi_table_lpit *lpit;
|
||||||
|
|
||||||
status = acpi_get_table(ACPI_SIG_LPIT, 0, (struct acpi_table_header **)&lpit);
|
status = acpi_get_table(ACPI_SIG_LPIT, 0, (struct acpi_table_header **)&lpit);
|
||||||
|
@ -156,6 +155,6 @@ void acpi_init_lpit(void)
|
||||||
if (ACPI_FAILURE(status))
|
if (ACPI_FAILURE(status))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lpit_begin = (u64)lpit + sizeof(*lpit);
|
lpit_process((u64)lpit + sizeof(*lpit),
|
||||||
lpit_process(lpit_begin, lpit_begin + lpit->header.length);
|
(u64)lpit + lpit->header.length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,19 @@ const char *acpi_power_state_string(int state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int acpi_dev_pm_explicit_get(struct acpi_device *device, int *state)
|
||||||
|
{
|
||||||
|
unsigned long long psc;
|
||||||
|
acpi_status status;
|
||||||
|
|
||||||
|
status = acpi_evaluate_integer(device->handle, "_PSC", NULL, &psc);
|
||||||
|
if (ACPI_FAILURE(status))
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
*state = psc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acpi_device_get_power - Get power state of an ACPI device.
|
* acpi_device_get_power - Get power state of an ACPI device.
|
||||||
* @device: Device to get the power state of.
|
* @device: Device to get the power state of.
|
||||||
|
@ -53,10 +66,16 @@ const char *acpi_power_state_string(int state)
|
||||||
* This function does not update the device's power.state field, but it may
|
* This function does not update the device's power.state field, but it may
|
||||||
* update its parent's power.state field (when the parent's power state is
|
* update its parent's power.state field (when the parent's power state is
|
||||||
* unknown and the device's power state turns out to be D0).
|
* unknown and the device's power state turns out to be D0).
|
||||||
|
*
|
||||||
|
* Also, it does not update power resource reference counters to ensure that
|
||||||
|
* the power state returned by it will be persistent and it may return a power
|
||||||
|
* state shallower than previously set by acpi_device_set_power() for @device
|
||||||
|
* (if that power state depends on any power resources).
|
||||||
*/
|
*/
|
||||||
int acpi_device_get_power(struct acpi_device *device, int *state)
|
int acpi_device_get_power(struct acpi_device *device, int *state)
|
||||||
{
|
{
|
||||||
int result = ACPI_STATE_UNKNOWN;
|
int result = ACPI_STATE_UNKNOWN;
|
||||||
|
int error;
|
||||||
|
|
||||||
if (!device || !state)
|
if (!device || !state)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -73,18 +92,16 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
|
||||||
* if available.
|
* if available.
|
||||||
*/
|
*/
|
||||||
if (device->power.flags.power_resources) {
|
if (device->power.flags.power_resources) {
|
||||||
int error = acpi_power_get_inferred_state(device, &result);
|
error = acpi_power_get_inferred_state(device, &result);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
if (device->power.flags.explicit_get) {
|
if (device->power.flags.explicit_get) {
|
||||||
acpi_handle handle = device->handle;
|
int psc;
|
||||||
unsigned long long psc;
|
|
||||||
acpi_status status;
|
|
||||||
|
|
||||||
status = acpi_evaluate_integer(handle, "_PSC", NULL, &psc);
|
error = acpi_dev_pm_explicit_get(device, &psc);
|
||||||
if (ACPI_FAILURE(status))
|
if (error)
|
||||||
return -ENODEV;
|
return error;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The power resources settings may indicate a power state
|
* The power resources settings may indicate a power state
|
||||||
|
@ -118,7 +135,6 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(acpi_device_get_power);
|
|
||||||
|
|
||||||
static int acpi_dev_pm_explicit_set(struct acpi_device *adev, int state)
|
static int acpi_dev_pm_explicit_set(struct acpi_device *adev, int state)
|
||||||
{
|
{
|
||||||
|
@ -152,7 +168,8 @@ int acpi_device_set_power(struct acpi_device *device, int state)
|
||||||
|
|
||||||
/* Make sure this is a valid target state */
|
/* Make sure this is a valid target state */
|
||||||
|
|
||||||
if (state == device->power.state) {
|
/* There is a special case for D0 addressed below. */
|
||||||
|
if (state > ACPI_STATE_D0 && state == device->power.state) {
|
||||||
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] already in %s\n",
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] already in %s\n",
|
||||||
device->pnp.bus_id,
|
device->pnp.bus_id,
|
||||||
acpi_power_state_string(state)));
|
acpi_power_state_string(state)));
|
||||||
|
@ -202,9 +219,15 @@ int acpi_device_set_power(struct acpi_device *device, int state)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the device goes from D3hot to D3cold, _PS3 has been
|
||||||
|
* evaluated for it already, so skip it in that case.
|
||||||
|
*/
|
||||||
|
if (device->power.state < ACPI_STATE_D3_HOT) {
|
||||||
result = acpi_dev_pm_explicit_set(device, state);
|
result = acpi_dev_pm_explicit_set(device, state);
|
||||||
if (result)
|
if (result)
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
if (device->power.flags.power_resources)
|
if (device->power.flags.power_resources)
|
||||||
result = acpi_power_transition(device, target_state);
|
result = acpi_power_transition(device, target_state);
|
||||||
|
@ -214,6 +237,30 @@ int acpi_device_set_power(struct acpi_device *device, int state)
|
||||||
if (result)
|
if (result)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device->power.state == ACPI_STATE_D0) {
|
||||||
|
int psc;
|
||||||
|
|
||||||
|
/* Nothing to do here if _PSC is not present. */
|
||||||
|
if (!device->power.flags.explicit_get)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The power state of the device was set to D0 last
|
||||||
|
* time, but that might have happened before a
|
||||||
|
* system-wide transition involving the platform
|
||||||
|
* firmware, so it may be necessary to evaluate _PS0
|
||||||
|
* for the device here. However, use extra care here
|
||||||
|
* and evaluate _PSC to check the device's current power
|
||||||
|
* state, and only invoke _PS0 if the evaluation of _PSC
|
||||||
|
* is successful and it returns a power state different
|
||||||
|
* from D0.
|
||||||
|
*/
|
||||||
|
result = acpi_dev_pm_explicit_get(device, &psc);
|
||||||
|
if (result || psc == ACPI_STATE_D0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
result = acpi_dev_pm_explicit_set(device, ACPI_STATE_D0);
|
result = acpi_dev_pm_explicit_set(device, ACPI_STATE_D0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,8 +139,15 @@ int acpi_power_get_inferred_state(struct acpi_device *device, int *state);
|
||||||
int acpi_power_on_resources(struct acpi_device *device, int state);
|
int acpi_power_on_resources(struct acpi_device *device, int state);
|
||||||
int acpi_power_transition(struct acpi_device *device, int state);
|
int acpi_power_transition(struct acpi_device *device, int state);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------
|
||||||
|
Device Power Management
|
||||||
|
-------------------------------------------------------------------------- */
|
||||||
|
int acpi_device_get_power(struct acpi_device *device, int *state);
|
||||||
int acpi_wakeup_device_init(void);
|
int acpi_wakeup_device_init(void);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------
|
||||||
|
Processor
|
||||||
|
-------------------------------------------------------------------------- */
|
||||||
#ifdef CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC
|
#ifdef CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC
|
||||||
void acpi_early_processor_set_pdc(void);
|
void acpi_early_processor_set_pdc(void);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -42,6 +42,11 @@ ACPI_MODULE_NAME("power");
|
||||||
#define ACPI_POWER_RESOURCE_STATE_ON 0x01
|
#define ACPI_POWER_RESOURCE_STATE_ON 0x01
|
||||||
#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
|
#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
|
||||||
|
|
||||||
|
struct acpi_power_dependent_device {
|
||||||
|
struct device *dev;
|
||||||
|
struct list_head node;
|
||||||
|
};
|
||||||
|
|
||||||
struct acpi_power_resource {
|
struct acpi_power_resource {
|
||||||
struct acpi_device device;
|
struct acpi_device device;
|
||||||
struct list_head list_node;
|
struct list_head list_node;
|
||||||
|
@ -51,6 +56,7 @@ struct acpi_power_resource {
|
||||||
unsigned int ref_count;
|
unsigned int ref_count;
|
||||||
bool wakeup_enabled;
|
bool wakeup_enabled;
|
||||||
struct mutex resource_lock;
|
struct mutex resource_lock;
|
||||||
|
struct list_head dependents;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct acpi_power_resource_entry {
|
struct acpi_power_resource_entry {
|
||||||
|
@ -232,8 +238,121 @@ static int acpi_power_get_list_state(struct list_head *list, int *state)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
acpi_power_resource_add_dependent(struct acpi_power_resource *resource,
|
||||||
|
struct device *dev)
|
||||||
|
{
|
||||||
|
struct acpi_power_dependent_device *dep;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
mutex_lock(&resource->resource_lock);
|
||||||
|
list_for_each_entry(dep, &resource->dependents, node) {
|
||||||
|
/* Only add it once */
|
||||||
|
if (dep->dev == dev)
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
dep = kzalloc(sizeof(*dep), GFP_KERNEL);
|
||||||
|
if (!dep) {
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
dep->dev = dev;
|
||||||
|
list_add_tail(&dep->node, &resource->dependents);
|
||||||
|
dev_dbg(dev, "added power dependency to [%s]\n", resource->name);
|
||||||
|
|
||||||
|
unlock:
|
||||||
|
mutex_unlock(&resource->resource_lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
acpi_power_resource_remove_dependent(struct acpi_power_resource *resource,
|
||||||
|
struct device *dev)
|
||||||
|
{
|
||||||
|
struct acpi_power_dependent_device *dep;
|
||||||
|
|
||||||
|
mutex_lock(&resource->resource_lock);
|
||||||
|
list_for_each_entry(dep, &resource->dependents, node) {
|
||||||
|
if (dep->dev == dev) {
|
||||||
|
list_del(&dep->node);
|
||||||
|
kfree(dep);
|
||||||
|
dev_dbg(dev, "removed power dependency to [%s]\n",
|
||||||
|
resource->name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mutex_unlock(&resource->resource_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* acpi_device_power_add_dependent - Add dependent device of this ACPI device
|
||||||
|
* @adev: ACPI device pointer
|
||||||
|
* @dev: Dependent device
|
||||||
|
*
|
||||||
|
* If @adev has non-empty _PR0 the @dev is added as dependent device to all
|
||||||
|
* power resources returned by it. This means that whenever these power
|
||||||
|
* resources are turned _ON the dependent devices get runtime resumed. This
|
||||||
|
* is needed for devices such as PCI to allow its driver to re-initialize
|
||||||
|
* it after it went to D0uninitialized.
|
||||||
|
*
|
||||||
|
* If @adev does not have _PR0 this does nothing.
|
||||||
|
*
|
||||||
|
* Returns %0 in case of success and negative errno otherwise.
|
||||||
|
*/
|
||||||
|
int acpi_device_power_add_dependent(struct acpi_device *adev,
|
||||||
|
struct device *dev)
|
||||||
|
{
|
||||||
|
struct acpi_power_resource_entry *entry;
|
||||||
|
struct list_head *resources;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!adev->flags.power_manageable)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
resources = &adev->power.states[ACPI_STATE_D0].resources;
|
||||||
|
list_for_each_entry(entry, resources, node) {
|
||||||
|
ret = acpi_power_resource_add_dependent(entry->resource, dev);
|
||||||
|
if (ret)
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
list_for_each_entry(entry, resources, node)
|
||||||
|
acpi_power_resource_remove_dependent(entry->resource, dev);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* acpi_device_power_remove_dependent - Remove dependent device
|
||||||
|
* @adev: ACPI device pointer
|
||||||
|
* @dev: Dependent device
|
||||||
|
*
|
||||||
|
* Does the opposite of acpi_device_power_add_dependent() and removes the
|
||||||
|
* dependent device if it is found. Can be called to @adev that does not
|
||||||
|
* have _PR0 as well.
|
||||||
|
*/
|
||||||
|
void acpi_device_power_remove_dependent(struct acpi_device *adev,
|
||||||
|
struct device *dev)
|
||||||
|
{
|
||||||
|
struct acpi_power_resource_entry *entry;
|
||||||
|
struct list_head *resources;
|
||||||
|
|
||||||
|
if (!adev->flags.power_manageable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
resources = &adev->power.states[ACPI_STATE_D0].resources;
|
||||||
|
list_for_each_entry_reverse(entry, resources, node)
|
||||||
|
acpi_power_resource_remove_dependent(entry->resource, dev);
|
||||||
|
}
|
||||||
|
|
||||||
static int __acpi_power_on(struct acpi_power_resource *resource)
|
static int __acpi_power_on(struct acpi_power_resource *resource)
|
||||||
{
|
{
|
||||||
|
struct acpi_power_dependent_device *dep;
|
||||||
acpi_status status = AE_OK;
|
acpi_status status = AE_OK;
|
||||||
|
|
||||||
status = acpi_evaluate_object(resource->device.handle, "_ON", NULL, NULL);
|
status = acpi_evaluate_object(resource->device.handle, "_ON", NULL, NULL);
|
||||||
|
@ -243,6 +362,21 @@ static int __acpi_power_on(struct acpi_power_resource *resource)
|
||||||
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
|
||||||
resource->name));
|
resource->name));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there are other dependents on this power resource we need to
|
||||||
|
* resume them now so that their drivers can re-initialize the
|
||||||
|
* hardware properly after it went back to D0.
|
||||||
|
*/
|
||||||
|
if (list_empty(&resource->dependents) ||
|
||||||
|
list_is_singular(&resource->dependents))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
list_for_each_entry(dep, &resource->dependents, node) {
|
||||||
|
dev_dbg(dep->dev, "runtime resuming because [%s] turned on\n",
|
||||||
|
resource->name);
|
||||||
|
pm_request_resume(dep->dev);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,6 +944,7 @@ int acpi_add_power_resource(acpi_handle handle)
|
||||||
ACPI_STA_DEFAULT);
|
ACPI_STA_DEFAULT);
|
||||||
mutex_init(&resource->resource_lock);
|
mutex_init(&resource->resource_lock);
|
||||||
INIT_LIST_HEAD(&resource->list_node);
|
INIT_LIST_HEAD(&resource->list_node);
|
||||||
|
INIT_LIST_HEAD(&resource->dependents);
|
||||||
resource->name = device->pnp.bus_id;
|
resource->name = device->pnp.bus_id;
|
||||||
strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
|
strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
|
||||||
strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
|
strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
|
||||||
|
|
|
@ -77,7 +77,7 @@ static int acpi_sleep_prepare(u32 acpi_state)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool acpi_sleep_state_supported(u8 sleep_state)
|
bool acpi_sleep_state_supported(u8 sleep_state)
|
||||||
{
|
{
|
||||||
acpi_status status;
|
acpi_status status;
|
||||||
u8 type_a, type_b;
|
u8 type_a, type_b;
|
||||||
|
@ -452,14 +452,6 @@ static int acpi_pm_prepare(void)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_powerf_dev(struct device *dev, void *data)
|
|
||||||
{
|
|
||||||
struct acpi_device *device = to_acpi_device(dev);
|
|
||||||
const char *hid = acpi_device_hid(device);
|
|
||||||
|
|
||||||
return !strcmp(hid, ACPI_BUTTON_HID_POWERF);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acpi_pm_finish - Instruct the platform to leave a sleep state.
|
* acpi_pm_finish - Instruct the platform to leave a sleep state.
|
||||||
*
|
*
|
||||||
|
@ -468,7 +460,7 @@ static int find_powerf_dev(struct device *dev, void *data)
|
||||||
*/
|
*/
|
||||||
static void acpi_pm_finish(void)
|
static void acpi_pm_finish(void)
|
||||||
{
|
{
|
||||||
struct device *pwr_btn_dev;
|
struct acpi_device *pwr_btn_adev;
|
||||||
u32 acpi_state = acpi_target_sleep_state;
|
u32 acpi_state = acpi_target_sleep_state;
|
||||||
|
|
||||||
acpi_ec_unblock_transactions();
|
acpi_ec_unblock_transactions();
|
||||||
|
@ -499,11 +491,11 @@ static void acpi_pm_finish(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pwr_btn_event_pending = false;
|
pwr_btn_event_pending = false;
|
||||||
pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL,
|
pwr_btn_adev = acpi_dev_get_first_match_dev(ACPI_BUTTON_HID_POWERF,
|
||||||
find_powerf_dev);
|
NULL, -1);
|
||||||
if (pwr_btn_dev) {
|
if (pwr_btn_adev) {
|
||||||
pm_wakeup_event(pwr_btn_dev, 0);
|
pm_wakeup_event(&pwr_btn_adev->dev, 0);
|
||||||
put_device(pwr_btn_dev);
|
acpi_dev_put(pwr_btn_adev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -685,12 +685,21 @@ static pci_power_t acpi_pci_get_power_state(struct pci_dev *dev)
|
||||||
if (!adev || !acpi_device_power_manageable(adev))
|
if (!adev || !acpi_device_power_manageable(adev))
|
||||||
return PCI_UNKNOWN;
|
return PCI_UNKNOWN;
|
||||||
|
|
||||||
if (acpi_device_get_power(adev, &state) || state == ACPI_STATE_UNKNOWN)
|
state = adev->power.state;
|
||||||
|
if (state == ACPI_STATE_UNKNOWN)
|
||||||
return PCI_UNKNOWN;
|
return PCI_UNKNOWN;
|
||||||
|
|
||||||
return state_conv[state];
|
return state_conv[state];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void acpi_pci_refresh_power_state(struct pci_dev *dev)
|
||||||
|
{
|
||||||
|
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
|
||||||
|
|
||||||
|
if (adev && acpi_device_power_manageable(adev))
|
||||||
|
acpi_device_update_power(adev, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static int acpi_pci_propagate_wakeup(struct pci_bus *bus, bool enable)
|
static int acpi_pci_propagate_wakeup(struct pci_bus *bus, bool enable)
|
||||||
{
|
{
|
||||||
while (bus->parent) {
|
while (bus->parent) {
|
||||||
|
@ -748,6 +757,7 @@ static const struct pci_platform_pm_ops acpi_pci_platform_pm = {
|
||||||
.is_manageable = acpi_pci_power_manageable,
|
.is_manageable = acpi_pci_power_manageable,
|
||||||
.set_state = acpi_pci_set_power_state,
|
.set_state = acpi_pci_set_power_state,
|
||||||
.get_state = acpi_pci_get_power_state,
|
.get_state = acpi_pci_get_power_state,
|
||||||
|
.refresh_state = acpi_pci_refresh_power_state,
|
||||||
.choose_state = acpi_pci_choose_state,
|
.choose_state = acpi_pci_choose_state,
|
||||||
.set_wakeup = acpi_pci_wakeup,
|
.set_wakeup = acpi_pci_wakeup,
|
||||||
.need_resume = acpi_pci_need_resume,
|
.need_resume = acpi_pci_need_resume,
|
||||||
|
@ -901,6 +911,7 @@ static void pci_acpi_setup(struct device *dev)
|
||||||
device_wakeup_enable(dev);
|
device_wakeup_enable(dev);
|
||||||
|
|
||||||
acpi_pci_wakeup(pci_dev, false);
|
acpi_pci_wakeup(pci_dev, false);
|
||||||
|
acpi_device_power_add_dependent(adev, dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pci_acpi_cleanup(struct device *dev)
|
static void pci_acpi_cleanup(struct device *dev)
|
||||||
|
@ -913,6 +924,7 @@ static void pci_acpi_cleanup(struct device *dev)
|
||||||
|
|
||||||
pci_acpi_remove_pm_notifier(adev);
|
pci_acpi_remove_pm_notifier(adev);
|
||||||
if (adev->wakeup.flags.valid) {
|
if (adev->wakeup.flags.valid) {
|
||||||
|
acpi_device_power_remove_dependent(adev, dev);
|
||||||
if (pci_dev->bridge_d3)
|
if (pci_dev->bridge_d3)
|
||||||
device_wakeup_disable(dev);
|
device_wakeup_disable(dev);
|
||||||
|
|
||||||
|
|
|
@ -678,6 +678,7 @@ static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
|
||||||
static int pci_pm_prepare(struct device *dev)
|
static int pci_pm_prepare(struct device *dev)
|
||||||
{
|
{
|
||||||
struct device_driver *drv = dev->driver;
|
struct device_driver *drv = dev->driver;
|
||||||
|
struct pci_dev *pci_dev = to_pci_dev(dev);
|
||||||
|
|
||||||
if (drv && drv->pm && drv->pm->prepare) {
|
if (drv && drv->pm && drv->pm->prepare) {
|
||||||
int error = drv->pm->prepare(dev);
|
int error = drv->pm->prepare(dev);
|
||||||
|
@ -687,7 +688,15 @@ static int pci_pm_prepare(struct device *dev)
|
||||||
if (!error && dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_PREPARE))
|
if (!error && dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_PREPARE))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return pci_dev_keep_suspended(to_pci_dev(dev));
|
if (pci_dev_need_resume(pci_dev))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The PME setting needs to be adjusted here in case the direct-complete
|
||||||
|
* optimization is used with respect to this device.
|
||||||
|
*/
|
||||||
|
pci_dev_adjust_pme(pci_dev);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pci_pm_complete(struct device *dev)
|
static void pci_pm_complete(struct device *dev)
|
||||||
|
@ -701,7 +710,14 @@ static void pci_pm_complete(struct device *dev)
|
||||||
if (pm_runtime_suspended(dev) && pm_resume_via_firmware()) {
|
if (pm_runtime_suspended(dev) && pm_resume_via_firmware()) {
|
||||||
pci_power_t pre_sleep_state = pci_dev->current_state;
|
pci_power_t pre_sleep_state = pci_dev->current_state;
|
||||||
|
|
||||||
pci_update_current_state(pci_dev, pci_dev->current_state);
|
pci_refresh_power_state(pci_dev);
|
||||||
|
/*
|
||||||
|
* On platforms with ACPI this check may also trigger for
|
||||||
|
* devices sharing power resources if one of those power
|
||||||
|
* resources has been activated as a result of a change of the
|
||||||
|
* power state of another device sharing it. However, in that
|
||||||
|
* case it is also better to resume the device, in general.
|
||||||
|
*/
|
||||||
if (pci_dev->current_state < pre_sleep_state)
|
if (pci_dev->current_state < pre_sleep_state)
|
||||||
pm_request_resume(dev);
|
pm_request_resume(dev);
|
||||||
}
|
}
|
||||||
|
@ -757,9 +773,11 @@ static int pci_pm_suspend(struct device *dev)
|
||||||
* better to resume the device from runtime suspend here.
|
* better to resume the device from runtime suspend here.
|
||||||
*/
|
*/
|
||||||
if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) ||
|
if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) ||
|
||||||
!pci_dev_keep_suspended(pci_dev)) {
|
pci_dev_need_resume(pci_dev)) {
|
||||||
pm_runtime_resume(dev);
|
pm_runtime_resume(dev);
|
||||||
pci_dev->state_saved = false;
|
pci_dev->state_saved = false;
|
||||||
|
} else {
|
||||||
|
pci_dev_adjust_pme(pci_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pm->suspend) {
|
if (pm->suspend) {
|
||||||
|
@ -1130,10 +1148,13 @@ static int pci_pm_poweroff(struct device *dev)
|
||||||
|
|
||||||
/* The reason to do that is the same as in pci_pm_suspend(). */
|
/* The reason to do that is the same as in pci_pm_suspend(). */
|
||||||
if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) ||
|
if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) ||
|
||||||
!pci_dev_keep_suspended(pci_dev))
|
pci_dev_need_resume(pci_dev)) {
|
||||||
pm_runtime_resume(dev);
|
pm_runtime_resume(dev);
|
||||||
|
|
||||||
pci_dev->state_saved = false;
|
pci_dev->state_saved = false;
|
||||||
|
} else {
|
||||||
|
pci_dev_adjust_pme(pci_dev);
|
||||||
|
}
|
||||||
|
|
||||||
if (pm->poweroff) {
|
if (pm->poweroff) {
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
|
|
@ -777,6 +777,12 @@ static inline pci_power_t platform_pci_get_power_state(struct pci_dev *dev)
|
||||||
return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN;
|
return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void platform_pci_refresh_power_state(struct pci_dev *dev)
|
||||||
|
{
|
||||||
|
if (pci_platform_pm && pci_platform_pm->refresh_state)
|
||||||
|
pci_platform_pm->refresh_state(dev);
|
||||||
|
}
|
||||||
|
|
||||||
static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
|
static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
|
||||||
{
|
{
|
||||||
return pci_platform_pm ?
|
return pci_platform_pm ?
|
||||||
|
@ -937,6 +943,21 @@ void pci_update_current_state(struct pci_dev *dev, pci_power_t state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pci_refresh_power_state - Refresh the given device's power state data
|
||||||
|
* @dev: Target PCI device.
|
||||||
|
*
|
||||||
|
* Ask the platform to refresh the devices power state information and invoke
|
||||||
|
* pci_update_current_state() to update its current PCI power state.
|
||||||
|
*/
|
||||||
|
void pci_refresh_power_state(struct pci_dev *dev)
|
||||||
|
{
|
||||||
|
if (platform_pci_power_manageable(dev))
|
||||||
|
platform_pci_refresh_power_state(dev);
|
||||||
|
|
||||||
|
pci_update_current_state(dev, dev->current_state);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pci_power_up - Put the given device into D0 forcibly
|
* pci_power_up - Put the given device into D0 forcibly
|
||||||
* @dev: PCI device to power up
|
* @dev: PCI device to power up
|
||||||
|
@ -1004,15 +1025,10 @@ static void __pci_start_power_transition(struct pci_dev *dev, pci_power_t state)
|
||||||
if (state == PCI_D0) {
|
if (state == PCI_D0) {
|
||||||
pci_platform_power_transition(dev, PCI_D0);
|
pci_platform_power_transition(dev, PCI_D0);
|
||||||
/*
|
/*
|
||||||
* Mandatory power management transition delays, see
|
* Mandatory power management transition delays are
|
||||||
* PCI Express Base Specification Revision 2.0 Section
|
* handled in the PCIe portdrv resume hooks.
|
||||||
* 6.6.1: Conventional Reset. Do not delay for
|
|
||||||
* devices powered on/off by corresponding bridge,
|
|
||||||
* because have already delayed for the bridge.
|
|
||||||
*/
|
*/
|
||||||
if (dev->runtime_d3cold) {
|
if (dev->runtime_d3cold) {
|
||||||
if (dev->d3cold_delay && !dev->imm_ready)
|
|
||||||
msleep(dev->d3cold_delay);
|
|
||||||
/*
|
/*
|
||||||
* When powering on a bridge from D3cold, the
|
* When powering on a bridge from D3cold, the
|
||||||
* whole hierarchy may be powered on into
|
* whole hierarchy may be powered on into
|
||||||
|
@ -2065,6 +2081,13 @@ static void pci_pme_list_scan(struct work_struct *work)
|
||||||
*/
|
*/
|
||||||
if (bridge && bridge->current_state != PCI_D0)
|
if (bridge && bridge->current_state != PCI_D0)
|
||||||
continue;
|
continue;
|
||||||
|
/*
|
||||||
|
* If the device is in D3cold it should not be
|
||||||
|
* polled either.
|
||||||
|
*/
|
||||||
|
if (pme_dev->dev->current_state == PCI_D3cold)
|
||||||
|
continue;
|
||||||
|
|
||||||
pci_pme_wakeup(pme_dev->dev, NULL);
|
pci_pme_wakeup(pme_dev->dev, NULL);
|
||||||
} else {
|
} else {
|
||||||
list_del(&pme_dev->list);
|
list_del(&pme_dev->list);
|
||||||
|
@ -2459,45 +2482,56 @@ bool pci_dev_run_wake(struct pci_dev *dev)
|
||||||
EXPORT_SYMBOL_GPL(pci_dev_run_wake);
|
EXPORT_SYMBOL_GPL(pci_dev_run_wake);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pci_dev_keep_suspended - Check if the device can stay in the suspended state.
|
* pci_dev_need_resume - Check if it is necessary to resume the device.
|
||||||
* @pci_dev: Device to check.
|
* @pci_dev: Device to check.
|
||||||
*
|
*
|
||||||
* Return 'true' if the device is runtime-suspended, it doesn't have to be
|
* Return 'true' if the device is not runtime-suspended or it has to be
|
||||||
* reconfigured due to wakeup settings difference between system and runtime
|
* reconfigured due to wakeup settings difference between system and runtime
|
||||||
* suspend and the current power state of it is suitable for the upcoming
|
* suspend, or the current power state of it is not suitable for the upcoming
|
||||||
* (system) transition.
|
* (system-wide) transition.
|
||||||
*
|
|
||||||
* If the device is not configured for system wakeup, disable PME for it before
|
|
||||||
* returning 'true' to prevent it from waking up the system unnecessarily.
|
|
||||||
*/
|
*/
|
||||||
bool pci_dev_keep_suspended(struct pci_dev *pci_dev)
|
bool pci_dev_need_resume(struct pci_dev *pci_dev)
|
||||||
{
|
{
|
||||||
struct device *dev = &pci_dev->dev;
|
struct device *dev = &pci_dev->dev;
|
||||||
bool wakeup = device_may_wakeup(dev);
|
pci_power_t target_state;
|
||||||
|
|
||||||
if (!pm_runtime_suspended(dev)
|
if (!pm_runtime_suspended(dev) || platform_pci_need_resume(pci_dev))
|
||||||
|| pci_target_state(pci_dev, wakeup) != pci_dev->current_state
|
return true;
|
||||||
|| platform_pci_need_resume(pci_dev))
|
|
||||||
return false;
|
target_state = pci_target_state(pci_dev, device_may_wakeup(dev));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At this point the device is good to go unless it's been configured
|
* If the earlier platform check has not triggered, D3cold is just power
|
||||||
* to generate PME at the runtime suspend time, but it is not supposed
|
* removal on top of D3hot, so no need to resume the device in that
|
||||||
* to wake up the system. In that case, simply disable PME for it
|
* case.
|
||||||
* (it will have to be re-enabled on exit from system resume).
|
|
||||||
*
|
|
||||||
* If the device's power state is D3cold and the platform check above
|
|
||||||
* hasn't triggered, the device's configuration is suitable and we don't
|
|
||||||
* need to manipulate it at all.
|
|
||||||
*/
|
*/
|
||||||
|
return target_state != pci_dev->current_state &&
|
||||||
|
target_state != PCI_D3cold &&
|
||||||
|
pci_dev->current_state != PCI_D3hot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pci_dev_adjust_pme - Adjust PME setting for a suspended device.
|
||||||
|
* @pci_dev: Device to check.
|
||||||
|
*
|
||||||
|
* If the device is suspended and it is not configured for system wakeup,
|
||||||
|
* disable PME for it to prevent it from waking up the system unnecessarily.
|
||||||
|
*
|
||||||
|
* Note that if the device's power state is D3cold and the platform check in
|
||||||
|
* pci_dev_need_resume() has not triggered, the device's configuration need not
|
||||||
|
* be changed.
|
||||||
|
*/
|
||||||
|
void pci_dev_adjust_pme(struct pci_dev *pci_dev)
|
||||||
|
{
|
||||||
|
struct device *dev = &pci_dev->dev;
|
||||||
|
|
||||||
spin_lock_irq(&dev->power.lock);
|
spin_lock_irq(&dev->power.lock);
|
||||||
|
|
||||||
if (pm_runtime_suspended(dev) && pci_dev->current_state < PCI_D3cold &&
|
if (pm_runtime_suspended(dev) && !device_may_wakeup(dev) &&
|
||||||
!wakeup)
|
pci_dev->current_state < PCI_D3cold)
|
||||||
__pci_pme_active(pci_dev, false);
|
__pci_pme_active(pci_dev, false);
|
||||||
|
|
||||||
spin_unlock_irq(&dev->power.lock);
|
spin_unlock_irq(&dev->power.lock);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4568,14 +4602,16 @@ static int pci_pm_reset(struct pci_dev *dev, int probe)
|
||||||
|
|
||||||
return pci_dev_wait(dev, "PM D3->D0", PCIE_RESET_READY_POLL_MS);
|
return pci_dev_wait(dev, "PM D3->D0", PCIE_RESET_READY_POLL_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pcie_wait_for_link - Wait until link is active or inactive
|
* pcie_wait_for_link_delay - Wait until link is active or inactive
|
||||||
* @pdev: Bridge device
|
* @pdev: Bridge device
|
||||||
* @active: waiting for active or inactive?
|
* @active: waiting for active or inactive?
|
||||||
|
* @delay: Delay to wait after link has become active (in ms)
|
||||||
*
|
*
|
||||||
* Use this to wait till link becomes active or inactive.
|
* Use this to wait till link becomes active or inactive.
|
||||||
*/
|
*/
|
||||||
bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
|
bool pcie_wait_for_link_delay(struct pci_dev *pdev, bool active, int delay)
|
||||||
{
|
{
|
||||||
int timeout = 1000;
|
int timeout = 1000;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
@ -4612,13 +4648,25 @@ bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
|
||||||
timeout -= 10;
|
timeout -= 10;
|
||||||
}
|
}
|
||||||
if (active && ret)
|
if (active && ret)
|
||||||
msleep(100);
|
msleep(delay);
|
||||||
else if (ret != active)
|
else if (ret != active)
|
||||||
pci_info(pdev, "Data Link Layer Link Active not %s in 1000 msec\n",
|
pci_info(pdev, "Data Link Layer Link Active not %s in 1000 msec\n",
|
||||||
active ? "set" : "cleared");
|
active ? "set" : "cleared");
|
||||||
return ret == active;
|
return ret == active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pcie_wait_for_link - Wait until link is active or inactive
|
||||||
|
* @pdev: Bridge device
|
||||||
|
* @active: waiting for active or inactive?
|
||||||
|
*
|
||||||
|
* Use this to wait till link becomes active or inactive.
|
||||||
|
*/
|
||||||
|
bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
|
||||||
|
{
|
||||||
|
return pcie_wait_for_link_delay(pdev, active, 100);
|
||||||
|
}
|
||||||
|
|
||||||
void pci_reset_secondary_bus(struct pci_dev *dev)
|
void pci_reset_secondary_bus(struct pci_dev *dev)
|
||||||
{
|
{
|
||||||
u16 ctrl;
|
u16 ctrl;
|
||||||
|
|
|
@ -51,6 +51,8 @@ int pci_bus_error_reset(struct pci_dev *dev);
|
||||||
*
|
*
|
||||||
* @get_state: queries the platform firmware for a device's current power state
|
* @get_state: queries the platform firmware for a device's current power state
|
||||||
*
|
*
|
||||||
|
* @refresh_state: asks the platform to refresh the device's power state data
|
||||||
|
*
|
||||||
* @choose_state: returns PCI power state of given device preferred by the
|
* @choose_state: returns PCI power state of given device preferred by the
|
||||||
* platform; to be used during system-wide transitions from a
|
* platform; to be used during system-wide transitions from a
|
||||||
* sleeping state to the working state and vice versa
|
* sleeping state to the working state and vice versa
|
||||||
|
@ -69,6 +71,7 @@ struct pci_platform_pm_ops {
|
||||||
bool (*is_manageable)(struct pci_dev *dev);
|
bool (*is_manageable)(struct pci_dev *dev);
|
||||||
int (*set_state)(struct pci_dev *dev, pci_power_t state);
|
int (*set_state)(struct pci_dev *dev, pci_power_t state);
|
||||||
pci_power_t (*get_state)(struct pci_dev *dev);
|
pci_power_t (*get_state)(struct pci_dev *dev);
|
||||||
|
void (*refresh_state)(struct pci_dev *dev);
|
||||||
pci_power_t (*choose_state)(struct pci_dev *dev);
|
pci_power_t (*choose_state)(struct pci_dev *dev);
|
||||||
int (*set_wakeup)(struct pci_dev *dev, bool enable);
|
int (*set_wakeup)(struct pci_dev *dev, bool enable);
|
||||||
bool (*need_resume)(struct pci_dev *dev);
|
bool (*need_resume)(struct pci_dev *dev);
|
||||||
|
@ -76,13 +79,15 @@ struct pci_platform_pm_ops {
|
||||||
|
|
||||||
int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
|
int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
|
||||||
void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
|
void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
|
||||||
|
void pci_refresh_power_state(struct pci_dev *dev);
|
||||||
void pci_power_up(struct pci_dev *dev);
|
void pci_power_up(struct pci_dev *dev);
|
||||||
void pci_disable_enabled_device(struct pci_dev *dev);
|
void pci_disable_enabled_device(struct pci_dev *dev);
|
||||||
int pci_finish_runtime_suspend(struct pci_dev *dev);
|
int pci_finish_runtime_suspend(struct pci_dev *dev);
|
||||||
void pcie_clear_root_pme_status(struct pci_dev *dev);
|
void pcie_clear_root_pme_status(struct pci_dev *dev);
|
||||||
int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
|
int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
|
||||||
void pci_pme_restore(struct pci_dev *dev);
|
void pci_pme_restore(struct pci_dev *dev);
|
||||||
bool pci_dev_keep_suspended(struct pci_dev *dev);
|
bool pci_dev_need_resume(struct pci_dev *dev);
|
||||||
|
void pci_dev_adjust_pme(struct pci_dev *dev);
|
||||||
void pci_dev_complete_resume(struct pci_dev *pci_dev);
|
void pci_dev_complete_resume(struct pci_dev *pci_dev);
|
||||||
void pci_config_pm_runtime_get(struct pci_dev *dev);
|
void pci_config_pm_runtime_get(struct pci_dev *dev);
|
||||||
void pci_config_pm_runtime_put(struct pci_dev *dev);
|
void pci_config_pm_runtime_put(struct pci_dev *dev);
|
||||||
|
@ -493,6 +498,7 @@ static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
|
||||||
void pcie_do_recovery(struct pci_dev *dev, enum pci_channel_state state,
|
void pcie_do_recovery(struct pci_dev *dev, enum pci_channel_state state,
|
||||||
u32 service);
|
u32 service);
|
||||||
|
|
||||||
|
bool pcie_wait_for_link_delay(struct pci_dev *pdev, bool active, int delay);
|
||||||
bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
|
bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
|
||||||
#ifdef CONFIG_PCIEASPM
|
#ifdef CONFIG_PCIEASPM
|
||||||
void pcie_aspm_init_link_state(struct pci_dev *pdev);
|
void pcie_aspm_init_link_state(struct pci_dev *pdev);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/pci.h>
|
#include <linux/pci.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/delay.h>
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
#include <linux/pm.h>
|
#include <linux/pm.h>
|
||||||
#include <linux/pm_runtime.h>
|
#include <linux/pm_runtime.h>
|
||||||
|
@ -378,6 +379,67 @@ static int pm_iter(struct device *dev, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_downstream_delay(struct pci_bus *bus)
|
||||||
|
{
|
||||||
|
struct pci_dev *pdev;
|
||||||
|
int min_delay = 100;
|
||||||
|
int max_delay = 0;
|
||||||
|
|
||||||
|
list_for_each_entry(pdev, &bus->devices, bus_list) {
|
||||||
|
if (!pdev->imm_ready)
|
||||||
|
min_delay = 0;
|
||||||
|
else if (pdev->d3cold_delay < min_delay)
|
||||||
|
min_delay = pdev->d3cold_delay;
|
||||||
|
if (pdev->d3cold_delay > max_delay)
|
||||||
|
max_delay = pdev->d3cold_delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
return max(min_delay, max_delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* wait_for_downstream_link - Wait for downstream link to establish
|
||||||
|
* @pdev: PCIe port whose downstream link is waited
|
||||||
|
*
|
||||||
|
* Handle delays according to PCIe 4.0 section 6.6.1 before configuration
|
||||||
|
* access to the downstream component is permitted.
|
||||||
|
*
|
||||||
|
* This blocks PCI core resume of the hierarchy below this port until the
|
||||||
|
* link is trained. Should be called before resuming port services to
|
||||||
|
* prevent pciehp from starting to tear-down the hierarchy too soon.
|
||||||
|
*/
|
||||||
|
static void wait_for_downstream_link(struct pci_dev *pdev)
|
||||||
|
{
|
||||||
|
int delay;
|
||||||
|
|
||||||
|
if (pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT &&
|
||||||
|
pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pci_dev_is_disconnected(pdev))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!pdev->subordinate || list_empty(&pdev->subordinate->devices) ||
|
||||||
|
!pdev->bridge_d3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
delay = get_downstream_delay(pdev->subordinate);
|
||||||
|
if (!delay)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dev_dbg(&pdev->dev, "waiting downstream link for %d ms\n", delay);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If downstream port does not support speeds greater than 5 GT/s
|
||||||
|
* need to wait 100ms. For higher speeds (gen3) we need to wait
|
||||||
|
* first for the data link layer to become active.
|
||||||
|
*/
|
||||||
|
if (pcie_get_speed_cap(pdev) <= PCIE_SPEED_5_0GT)
|
||||||
|
msleep(delay);
|
||||||
|
else
|
||||||
|
pcie_wait_for_link_delay(pdev, true, delay);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pcie_port_device_suspend - suspend port services associated with a PCIe port
|
* pcie_port_device_suspend - suspend port services associated with a PCIe port
|
||||||
* @dev: PCI Express port to handle
|
* @dev: PCI Express port to handle
|
||||||
|
@ -391,6 +453,8 @@ int pcie_port_device_suspend(struct device *dev)
|
||||||
int pcie_port_device_resume_noirq(struct device *dev)
|
int pcie_port_device_resume_noirq(struct device *dev)
|
||||||
{
|
{
|
||||||
size_t off = offsetof(struct pcie_port_service_driver, resume_noirq);
|
size_t off = offsetof(struct pcie_port_service_driver, resume_noirq);
|
||||||
|
|
||||||
|
wait_for_downstream_link(to_pci_dev(dev));
|
||||||
return device_for_each_child(dev, &off, pm_iter);
|
return device_for_each_child(dev, &off, pm_iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,6 +485,8 @@ int pcie_port_device_runtime_suspend(struct device *dev)
|
||||||
int pcie_port_device_runtime_resume(struct device *dev)
|
int pcie_port_device_runtime_resume(struct device *dev)
|
||||||
{
|
{
|
||||||
size_t off = offsetof(struct pcie_port_service_driver, runtime_resume);
|
size_t off = offsetof(struct pcie_port_service_driver, runtime_resume);
|
||||||
|
|
||||||
|
wait_for_downstream_link(to_pci_dev(dev));
|
||||||
return device_for_each_child(dev, &off, pm_iter);
|
return device_for_each_child(dev, &off, pm_iter);
|
||||||
}
|
}
|
||||||
#endif /* PM */
|
#endif /* PM */
|
||||||
|
|
|
@ -506,13 +506,16 @@ int acpi_bus_get_status(struct acpi_device *device);
|
||||||
|
|
||||||
int acpi_bus_set_power(acpi_handle handle, int state);
|
int acpi_bus_set_power(acpi_handle handle, int state);
|
||||||
const char *acpi_power_state_string(int state);
|
const char *acpi_power_state_string(int state);
|
||||||
int acpi_device_get_power(struct acpi_device *device, int *state);
|
|
||||||
int acpi_device_set_power(struct acpi_device *device, int state);
|
int acpi_device_set_power(struct acpi_device *device, int state);
|
||||||
int acpi_bus_init_power(struct acpi_device *device);
|
int acpi_bus_init_power(struct acpi_device *device);
|
||||||
int acpi_device_fix_up_power(struct acpi_device *device);
|
int acpi_device_fix_up_power(struct acpi_device *device);
|
||||||
int acpi_bus_update_power(acpi_handle handle, int *state_p);
|
int acpi_bus_update_power(acpi_handle handle, int *state_p);
|
||||||
int acpi_device_update_power(struct acpi_device *device, int *state_p);
|
int acpi_device_update_power(struct acpi_device *device, int *state_p);
|
||||||
bool acpi_bus_power_manageable(acpi_handle handle);
|
bool acpi_bus_power_manageable(acpi_handle handle);
|
||||||
|
int acpi_device_power_add_dependent(struct acpi_device *adev,
|
||||||
|
struct device *dev);
|
||||||
|
void acpi_device_power_remove_dependent(struct acpi_device *adev,
|
||||||
|
struct device *dev);
|
||||||
|
|
||||||
#ifdef CONFIG_PM
|
#ifdef CONFIG_PM
|
||||||
bool acpi_bus_can_wakeup(acpi_handle handle);
|
bool acpi_bus_can_wakeup(acpi_handle handle);
|
||||||
|
@ -651,6 +654,12 @@ static inline int acpi_pm_set_bridge_wakeup(struct device *dev, bool enable)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ACPI_SYSTEM_POWER_STATES_SUPPORT
|
||||||
|
bool acpi_sleep_state_supported(u8 sleep_state);
|
||||||
|
#else
|
||||||
|
static inline bool acpi_sleep_state_supported(u8 sleep_state) { return false; }
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ACPI_SLEEP
|
#ifdef CONFIG_ACPI_SLEEP
|
||||||
u32 acpi_target_system_state(void);
|
u32 acpi_target_system_state(void);
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue