Skip to content

Commit f377d9c

Browse files
committed
Merge branch 'pci/pm'
- Add pm_runtime_put() cleanup helper for use with __free() to automatically drop the device usage count when a pointer goes out of scope (Alex Williamson) - Increment PM usage counter when probing reset methods so we don't try to read config space of a powered-off device (Alex Williamson) - Set all devices to D0 during enumeration to ensure ACPI opregion is connected via _REG (Mario Limonciello) * pci/pm: PCI: Explicitly put devices into D0 when initializing PCI: Increment PM usage counter when probing reset methods PM: runtime: Define pm_runtime_put cleanup helper
2 parents 80fe18d + 4d4c10f commit f377d9c

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

drivers/pci/pci-driver.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,6 @@ static void pci_pm_default_resume(struct pci_dev *pci_dev)
555555
pci_enable_wake(pci_dev, PCI_D0, false);
556556
}
557557

558-
static void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev)
559-
{
560-
pci_power_up(pci_dev);
561-
pci_update_current_state(pci_dev, PCI_D0);
562-
}
563-
564558
static void pci_pm_default_resume_early(struct pci_dev *pci_dev)
565559
{
566560
pci_pm_power_up_and_verify_state(pci_dev);

drivers/pci/pci-sysfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,9 @@ static ssize_t reset_method_store(struct device *dev,
14751475
return count;
14761476
}
14771477

1478+
pm_runtime_get_sync(dev);
1479+
struct device *pmdev __free(pm_runtime_put) = dev;
1480+
14781481
if (sysfs_streq(buf, "default")) {
14791482
pci_init_reset_methods(pdev);
14801483
return count;

drivers/pci/pci.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,12 @@ void pci_d3cold_disable(struct pci_dev *dev)
31923192
}
31933193
EXPORT_SYMBOL_GPL(pci_d3cold_disable);
31943194

3195+
void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev)
3196+
{
3197+
pci_power_up(pci_dev);
3198+
pci_update_current_state(pci_dev, PCI_D0);
3199+
}
3200+
31953201
/**
31963202
* pci_pm_init - Initialize PM functions of given PCI device
31973203
* @dev: PCI device to handle.
@@ -3202,9 +3208,6 @@ void pci_pm_init(struct pci_dev *dev)
32023208
u16 status;
32033209
u16 pmc;
32043210

3205-
pm_runtime_forbid(&dev->dev);
3206-
pm_runtime_set_active(&dev->dev);
3207-
pm_runtime_enable(&dev->dev);
32083211
device_enable_async_suspend(&dev->dev);
32093212
dev->wakeup_prepared = false;
32103213

@@ -3266,6 +3269,10 @@ void pci_pm_init(struct pci_dev *dev)
32663269
pci_read_config_word(dev, PCI_STATUS, &status);
32673270
if (status & PCI_STATUS_IMM_READY)
32683271
dev->imm_ready = 1;
3272+
pci_pm_power_up_and_verify_state(dev);
3273+
pm_runtime_forbid(&dev->dev);
3274+
pm_runtime_set_active(&dev->dev);
3275+
pm_runtime_enable(&dev->dev);
32693276
}
32703277

32713278
static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)

drivers/pci/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ void pci_dev_adjust_pme(struct pci_dev *dev);
148148
void pci_dev_complete_resume(struct pci_dev *pci_dev);
149149
void pci_config_pm_runtime_get(struct pci_dev *dev);
150150
void pci_config_pm_runtime_put(struct pci_dev *dev);
151+
void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev);
151152
void pci_pm_init(struct pci_dev *dev);
152153
void pci_ea_init(struct pci_dev *dev);
153154
void pci_msi_init(struct pci_dev *dev);

include/linux/pm_runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ static inline int pm_runtime_put(struct device *dev)
466466
return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);
467467
}
468468

469+
DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T))
470+
469471
/**
470472
* __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
471473
* @dev: Target device.

0 commit comments

Comments
 (0)