Skip to content

Commit 112a7f9

Browse files
superm1bjorn-helgaas
authored andcommitted
PCI/ACPI: Call _REG when transitioning D-states
ACPI r6.5, sec 6.5.4, describes how AML is unable to access an OperationRegion unless _REG has been called to connect a handler: The OS runs _REG control methods to inform AML code of a change in the availability of an operation region. When an operation region handler is unavailable, AML cannot access data fields in that region. (Operation region writes will be ignored and reads will return indeterminate data.) The PCI core does not call _REG at any time, leading to the undefined behavior mentioned in the spec. The spec explains that _REG should be executed to indicate whether a given region can be accessed: Once _REG has been executed for a particular operation region, indicating that the operation region handler is ready, a control method can access fields in the operation region. Conversely, control methods must not access fields in operation regions when _REG method execution has not indicated that the operation region handler is ready. An example included in the spec demonstrates calling _REG when devices are turned off: "when the host controller or bridge controller is turned off or disabled, PCI Config Space Operation Regions for child devices are no longer available. As such, ETH0’s _REG method will be run when it is turned off and will again be run when PCI1 is turned off." It is reported that ASMedia PCIe GPIO controllers fail functional tests after the system has returning from suspend (S3 or s2idle). This is because the BIOS checks whether the OSPM has called the _REG method to determine whether it can interact with the OperationRegion assigned to the device as part of the other AML called for the device. To fix this issue, call acpi_evaluate_reg() when devices are transitioning to D3cold or D0. [bhelgaas: split pci_power_t checking to preliminary patch] Link: https://uefi.org/specs/ACPI/6.5/06_Device_Configuration.html#reg-region Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Rafael J. Wysocki <[email protected]>
1 parent 5557b62 commit 112a7f9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/pci/pci-acpi.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,16 @@ bool acpi_pci_bridge_d3(struct pci_dev *dev)
10431043
return false;
10441044
}
10451045

1046+
static void acpi_pci_config_space_access(struct pci_dev *dev, bool enable)
1047+
{
1048+
int val = enable ? ACPI_REG_CONNECT : ACPI_REG_DISCONNECT;
1049+
int ret = acpi_evaluate_reg(ACPI_HANDLE(&dev->dev),
1050+
ACPI_ADR_SPACE_PCI_CONFIG, val);
1051+
if (ret)
1052+
pci_dbg(dev, "ACPI _REG %s evaluation failed (%d)\n",
1053+
enable ? "connect" : "disconnect", ret);
1054+
}
1055+
10461056
int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
10471057
{
10481058
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
@@ -1074,6 +1084,9 @@ int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
10741084
if (dev_pm_qos_flags(&dev->dev, PM_QOS_FLAG_NO_POWER_OFF) ==
10751085
PM_QOS_FLAGS_ALL)
10761086
return -EBUSY;
1087+
1088+
/* Notify AML lack of PCI config space availability */
1089+
acpi_pci_config_space_access(dev, false);
10771090
}
10781091

10791092
error = acpi_device_set_power(adev, state_conv[state]);
@@ -1083,6 +1096,15 @@ int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
10831096
pci_dbg(dev, "power state changed by ACPI to %s\n",
10841097
acpi_power_state_string(adev->power.state));
10851098

1099+
/*
1100+
* Notify AML of PCI config space availability. Config space is
1101+
* accessible in all states except D3cold; the only transitions
1102+
* that change availability are transitions to D3cold and from
1103+
* D3cold to D0.
1104+
*/
1105+
if (state == PCI_D0)
1106+
acpi_pci_config_space_access(dev, true);
1107+
10861108
return 0;
10871109
}
10881110

0 commit comments

Comments
 (0)