git: ced5806515aa - main - pci: Accept D3hot in pci_set_powerstate_method()

From: Olivier Cochard <olivier_at_FreeBSD.org>
Date: Mon, 23 Nov 2026 08:59:38 UTC
The branch main has been updated by olivier:

URL: https://cgit.FreeBSD.org/src/commit/?id=ced5806515aacf17ec29a353edb0b86f8b8b4e40

commit ced5806515aacf17ec29a353edb0b86f8b8b4e40
Author:     Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-11-15 13:35:15 +0000
Commit:     Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-11-23 08:53:57 +0000

    pci: Accept D3hot in pci_set_powerstate_method()
    
    Since D3 was split into D3hot and D3cold, PCI_POWERSTATE_D3 is D3cold
    and the switch rejects D3hot with EINVAL.  Devices whose _SxD is 3
    (D3hot) then stay in D0 on suspend, and acpi_pci skips their ACPI
    transition.  LinuxKPI pci_set_power_state(PCI_D3hot) fails the same way.
    
    The PM register has a single D3 state, so write it for both.
    
    Reviewed by:    kbowling
    Approved by:    kbowling
    Fixes:          84bbfc32a3f4 ("acpi_powerres: D3cold support")
    MFC after:      1 week
    Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/111
---
 sys/dev/pci/pci.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index 35f8e1154d6c..a95ace27d122 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -2891,10 +2891,12 @@ pci_set_powerstate_method(device_t dev, device_t child, int state)
 	/*
 	 * Optimize a no state change request away.  While it would be OK to
 	 * write to the hardware in theory, some devices have shown odd
-	 * behavior when going from D3 -> D3.
+	 * behavior when going from D3 -> D3.  D3hot and D3cold are the same
+	 * state in the PM register.
 	 */
 	oldstate = pci_get_powerstate(child);
-	if (oldstate == state)
+	if (oldstate == state || (oldstate >= PCI_POWERSTATE_D3_HOT &&
+	    state >= PCI_POWERSTATE_D3_HOT && state <= PCI_POWERSTATE_MAX))
 		return (0);
 
 	/*
@@ -2910,7 +2912,7 @@ pci_set_powerstate_method(device_t dev, device_t child, int state)
 	 * this function can be called from contexts where we cannot sleep.
 	 */
 	highest = (oldstate > state) ? oldstate : state;
-	if (highest == PCI_POWERSTATE_D3)
+	if (highest >= PCI_POWERSTATE_D3_HOT)
 	    delay = 10000;
 	else if (highest == PCI_POWERSTATE_D2)
 	    delay = 200;
@@ -2932,7 +2934,8 @@ pci_set_powerstate_method(device_t dev, device_t child, int state)
 			return (EOPNOTSUPP);
 		status |= PCIM_PSTAT_D2;
 		break;
-	case PCI_POWERSTATE_D3:
+	case PCI_POWERSTATE_D3_HOT:
+	case PCI_POWERSTATE_D3_COLD:
 		status |= PCIM_PSTAT_D3;
 		break;
 	default: