Skip to content

Commit fe31e69

Browse files
rjwysockijbarnes993
authored andcommitted
PCI/PCIe: Clear Root PME Status bits early during system resume
I noticed that PCI Express PMEs don't work on my Toshiba Portege R500 after the system has been woken up from a sleep state by a PME (through Wake-on-LAN). After some investigation it turned out that the BIOS didn't clear the Root PME Status bit in the root port that received the wakeup PME and since the Requester ID was also set in the port's Root Status register, any subsequent PMEs didn't trigger interrupts. This problem can be avoided by clearing the Root PME Status bits in all PCI Express root ports during early resume. For this purpose, add an early resume routine to the PCIe port driver and make this driver be always registered, even if pci_ports_disable is set (in which case the driver's only function is to provide the early resume callback). Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 99a0fad commit fe31e69

5 files changed

Lines changed: 55 additions & 38 deletions

File tree

‎drivers/pci/pcie/pme.c‎

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
#include "../pci.h"
2727
#include "portdrv.h"
2828

29-
#define PCI_EXP_RTSTA_PME 0x10000 /* PME status */
30-
#define PCI_EXP_RTSTA_PENDING 0x20000 /* PME pending */
31-
3229
/*
3330
* If this switch is set, MSI will not be used for PCIe PME signaling. This
3431
* causes the PCIe port driver to use INTx interrupts only, but it turns out
@@ -73,22 +70,6 @@ void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable)
7370
pci_write_config_word(dev, rtctl_pos, rtctl);
7471
}
7572

76-
/**
77-
* pcie_pme_clear_status - Clear root port PME interrupt status.
78-
* @dev: PCIe root port or event collector.
79-
*/
80-
static void pcie_pme_clear_status(struct pci_dev *dev)
81-
{
82-
int rtsta_pos;
83-
u32 rtsta;
84-
85-
rtsta_pos = pci_pcie_cap(dev) + PCI_EXP_RTSTA;
86-
87-
pci_read_config_dword(dev, rtsta_pos, &rtsta);
88-
rtsta |= PCI_EXP_RTSTA_PME;
89-
pci_write_config_dword(dev, rtsta_pos, rtsta);
90-
}
91-
9273
/**
9374
* pcie_pme_walk_bus - Scan a PCI bus for devices asserting PME#.
9475
* @bus: PCI bus to scan.
@@ -253,7 +234,7 @@ static void pcie_pme_work_fn(struct work_struct *work)
253234
* Clear PME status of the port. If there are other
254235
* pending PMEs, the status will be set again.
255236
*/
256-
pcie_pme_clear_status(port);
237+
pcie_clear_root_pme_status(port);
257238

258239
spin_unlock_irq(&data->lock);
259240
pcie_pme_handle_request(port, rtsta & 0xffff);
@@ -378,7 +359,7 @@ static int pcie_pme_probe(struct pcie_device *srv)
378359

379360
port = srv->port;
380361
pcie_pme_interrupt_enable(port, false);
381-
pcie_pme_clear_status(port);
362+
pcie_clear_root_pme_status(port);
382363

383364
ret = request_irq(srv->irq, pcie_pme_irq, IRQF_SHARED, "PCIe PME", srv);
384365
if (ret) {
@@ -402,7 +383,7 @@ static int pcie_pme_suspend(struct pcie_device *srv)
402383

403384
spin_lock_irq(&data->lock);
404385
pcie_pme_interrupt_enable(port, false);
405-
pcie_pme_clear_status(port);
386+
pcie_clear_root_pme_status(port);
406387
data->noirq = true;
407388
spin_unlock_irq(&data->lock);
408389

@@ -422,7 +403,7 @@ static int pcie_pme_resume(struct pcie_device *srv)
422403

423404
spin_lock_irq(&data->lock);
424405
data->noirq = false;
425-
pcie_pme_clear_status(port);
406+
pcie_clear_root_pme_status(port);
426407
pcie_pme_interrupt_enable(port, true);
427408
spin_unlock_irq(&data->lock);
428409

‎drivers/pci/pcie/portdrv.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extern void pcie_port_bus_unregister(void);
3535

3636
struct pci_dev;
3737

38+
extern void pcie_clear_root_pme_status(struct pci_dev *dev);
39+
3840
#ifdef CONFIG_PCIE_PME
3941
extern bool pcie_pme_msi_disabled;
4042

‎drivers/pci/pcie/portdrv_core.c‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,17 @@ static int get_port_device_capability(struct pci_dev *dev)
241241
int cap_mask;
242242
int err;
243243

244+
if (pcie_ports_disabled)
245+
return 0;
246+
244247
err = pcie_port_platform_notify(dev, &cap_mask);
245-
if (pcie_ports_auto) {
246-
if (err) {
247-
pcie_no_aspm();
248-
return 0;
249-
}
250-
} else {
248+
if (!pcie_ports_auto) {
251249
cap_mask = PCIE_PORT_SERVICE_PME | PCIE_PORT_SERVICE_HP
252250
| PCIE_PORT_SERVICE_VC;
253251
if (pci_aer_available())
254252
cap_mask |= PCIE_PORT_SERVICE_AER;
253+
} else if (err) {
254+
return 0;
255255
}
256256

257257
pos = pci_pcie_cap(dev);
@@ -349,15 +349,18 @@ int pcie_port_device_register(struct pci_dev *dev)
349349
int status, capabilities, i, nr_service;
350350
int irqs[PCIE_PORT_DEVICE_MAXSERVICES];
351351

352-
/* Get and check PCI Express port services */
353-
capabilities = get_port_device_capability(dev);
354-
if (!capabilities)
355-
return -ENODEV;
356-
357352
/* Enable PCI Express port device */
358353
status = pci_enable_device(dev);
359354
if (status)
360355
return status;
356+
357+
/* Get and check PCI Express port services */
358+
capabilities = get_port_device_capability(dev);
359+
if (!capabilities) {
360+
pcie_no_aspm();
361+
return 0;
362+
}
363+
361364
pci_set_master(dev);
362365
/*
363366
* Initialize service irqs. Don't use service devices that

‎drivers/pci/pcie/portdrv_pci.c‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ __setup("pcie_ports=", pcie_port_setup);
5757

5858
/* global data */
5959

60+
/**
61+
* pcie_clear_root_pme_status - Clear root port PME interrupt status.
62+
* @dev: PCIe root port or event collector.
63+
*/
64+
void pcie_clear_root_pme_status(struct pci_dev *dev)
65+
{
66+
int rtsta_pos;
67+
u32 rtsta;
68+
69+
rtsta_pos = pci_pcie_cap(dev) + PCI_EXP_RTSTA;
70+
71+
pci_read_config_dword(dev, rtsta_pos, &rtsta);
72+
rtsta |= PCI_EXP_RTSTA_PME;
73+
pci_write_config_dword(dev, rtsta_pos, rtsta);
74+
}
75+
6076
static int pcie_portdrv_restore_config(struct pci_dev *dev)
6177
{
6278
int retval;
@@ -69,13 +85,28 @@ static int pcie_portdrv_restore_config(struct pci_dev *dev)
6985
}
7086

7187
#ifdef CONFIG_PM
88+
static int pcie_port_resume_noirq(struct device *dev)
89+
{
90+
struct pci_dev *pdev = to_pci_dev(dev);
91+
92+
/*
93+
* Some BIOSes forget to clear Root PME Status bits after system wakeup
94+
* which breaks ACPI-based runtime wakeup on PCI Express, so clear those
95+
* bits now just in case (shouldn't hurt).
96+
*/
97+
if(pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT)
98+
pcie_clear_root_pme_status(pdev);
99+
return 0;
100+
}
101+
72102
static const struct dev_pm_ops pcie_portdrv_pm_ops = {
73103
.suspend = pcie_port_device_suspend,
74104
.resume = pcie_port_device_resume,
75105
.freeze = pcie_port_device_suspend,
76106
.thaw = pcie_port_device_resume,
77107
.poweroff = pcie_port_device_suspend,
78108
.restore = pcie_port_device_resume,
109+
.resume_noirq = pcie_port_resume_noirq,
79110
};
80111

81112
#define PCIE_PORTDRV_PM_OPS (&pcie_portdrv_pm_ops)
@@ -327,10 +358,8 @@ static int __init pcie_portdrv_init(void)
327358
{
328359
int retval;
329360

330-
if (pcie_ports_disabled) {
331-
pcie_no_aspm();
332-
return -EACCES;
333-
}
361+
if (pcie_ports_disabled)
362+
return pci_register_driver(&pcie_portdriver);
334363

335364
dmi_check_system(pcie_portdrv_dmi_table);
336365

‎include/linux/pci_regs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@
504504
#define PCI_EXP_RTCTL_CRSSVE 0x10 /* CRS Software Visibility Enable */
505505
#define PCI_EXP_RTCAP 30 /* Root Capabilities */
506506
#define PCI_EXP_RTSTA 32 /* Root Status */
507+
#define PCI_EXP_RTSTA_PME 0x10000 /* PME status */
508+
#define PCI_EXP_RTSTA_PENDING 0x20000 /* PME pending */
507509
#define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */
508510
#define PCI_EXP_DEVCAP2_ARI 0x20 /* Alternative Routing-ID */
509511
#define PCI_EXP_DEVCTL2 40 /* Device Control 2 */

0 commit comments

Comments
 (0)