From nobody Tue Apr 29 18:30:47 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Zn85Q0fY1z5vMvx; Tue, 29 Apr 2025 18:30:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zn85N0116z4Hy4; Tue, 29 Apr 2025 18:30:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745951448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OsGFGyUyqyALVCmpLp6R29ogLKIMzV5CbeX1TyYoEuk=; b=GIXd9A/mFLwAwQlCK4PW0h1ylNSiojT6P+hfGn2ePFFsm010szODOf6qLR4Gr+Qm2AR3HF /Qdp8nCrUmBd2YHW7pl9yj4Zj2ZWPmsq2Y2/Mo/jfdF5Bd+NaHwA6F+H+zFIEp2WExwNBn VEdDIRIf6CkjiazwcxUa3rN9/tA5PxCZe9O3yNdc9J8ktVtBsTrC8qaYREp2gDVIsaNQQB Ihn2NJjVoJVSG5MXjFlJF+gnobVEnGUne4fZq3/ImrKw+pLoHLmy+MX6hvh2GaQFagXgqd pYTkByJUZn04hv+FnoY5MbwsbbULKgQ1SuYeWzkWpQhtf0ykW5ZXk137it7ARQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745951448; a=rsa-sha256; cv=none; b=FbByNyDTNlBb+mRNSsUtVPClSKosmwY8Ag0ZaaKaGFMOgTcycIWvlrcUxP0/eow3HW4upF AJmt/nvGCjlabj7SpPnWIe68TWQDSEhbJe2Itd+1fdkbKkttKhLVMlKf7rcHjfqYwVOYiR D5p51MbAenB20KhddpIctxahFhjju1eRzwS+J8hZWnALZqlIgVXzie5zpjwgB4WmwxC8Nz iA0VfAER2uVAQNRLOQR1rGcn5XyeOWgO//IRLRXxBL5l2Qa6zu5MHh8HMziQsjvHvF3oCu 8hdRGBmSWQf+Cb62DaWlbNj2mB8Csur6304ky9lokx5xqFCB143IYzfm06wlFA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745951448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OsGFGyUyqyALVCmpLp6R29ogLKIMzV5CbeX1TyYoEuk=; b=WRqzmiZkEZ3f5Dhg2XUk5sz0Mswlzjm+L4h5sxRf/FRUATTT9IrL9diQCLwJ/9HbgKqji+ DIUPLXjj2rzINtj7b488Ny8TRhpdKoFg743q9cGwGgZQMN+mGLmdaRebBiEuhM8Ino29Hf pGAET2kpaXTXwFnBaKMQqCVH8ILPD7KMqHT4yZmxN95Ith4pVhhhmdzIJ9tecHGocoKLPM spObrc961pFpp9IF96prTtIg8SonBQk4iZ9a7NcAdtgGK/6kyhKEyiVX8XnKegKMCmpK8w kFenJXeJTscJCNU7T3mD5i3loyvI2UIWopPuC4zUUk7K/nV1mv2Lsmc4uR82qA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Zn85M5kRgzXn3; Tue, 29 Apr 2025 18:30:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53TIUlAK022871; Tue, 29 Apr 2025 18:30:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53TIUl72022868; Tue, 29 Apr 2025 18:30:47 GMT (envelope-from git) Date: Tue, 29 Apr 2025 18:30:47 GMT Message-Id: <202504291830.53TIUl72022868@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: b5bc47f1e1ab - stable/14 - pci: Clear active PME# and disable PME# generation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: b5bc47f1e1ab31086c1bf2e68944ea0331059c2c Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b5bc47f1e1ab31086c1bf2e68944ea0331059c2c commit b5bc47f1e1ab31086c1bf2e68944ea0331059c2c Author: John Baldwin AuthorDate: 2025-03-27 20:53:24 +0000 Commit: John Baldwin CommitDate: 2025-04-29 14:44:25 +0000 pci: Clear active PME# and disable PME# generation The PCI power management specification requires that the OS clear any pending PME# interrupt and generation of PME# interrupts during "initial operating system load". Note that clearing a pending PME# interrupt requires writing a 1 to the Read/Write-Clear PME bit in the power management status register. To handle the boot time case, clear PME# state in pci_read_cap() when scanning new PCI devices. This should also cover hotplug devices. In addition, clear this state on every PCI device after resume from sleep in pci_resume_child before invoking the driver's DEVICE_RESUME method. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D49222 (cherry picked from commit 82d692771239f1d156a875087dff4cf09f0e8b80) --- share/man/man9/Makefile | 1 + share/man/man9/pci.9 | 8 ++++++++ sys/dev/cardbus/cardbus.c | 1 + sys/dev/pci/pci.c | 18 ++++++++++++++++++ sys/dev/pci/pcivar.h | 1 + 5 files changed, 29 insertions(+) diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 3ee1d2bb0108..dcaf1d4ac5ed 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1781,6 +1781,7 @@ MLINKS+=panic.9 vpanic.9 \ panic.9 KERNEL_PANICKED.9 MLINKS+=pci.9 pci_alloc_msi.9 \ pci.9 pci_alloc_msix.9 \ + pci.9 pci_clear_pme.9 \ pci.9 pci_disable_busmaster.9 \ pci.9 pci_disable_io.9 \ pci.9 pci_enable_busmaster.9 \ diff --git a/share/man/man9/pci.9 b/share/man/man9/pci.9 index 3c3e54bf8760..0f3fc92c23e7 100644 --- a/share/man/man9/pci.9 +++ b/share/man/man9/pci.9 @@ -30,6 +30,7 @@ .Nm pci , .Nm pci_alloc_msi , .Nm pci_alloc_msix , +.Nm pci_clear_pme , .Nm pci_disable_busmaster , .Nm pci_disable_io , .Nm pci_enable_busmaster , @@ -81,6 +82,8 @@ .Fn pci_alloc_msi "device_t dev" "int *count" .Ft int .Fn pci_alloc_msix "device_t dev" "int *count" +.Ft void +.Fn pci_clear_pme "device_t dev" .Ft int .Fn pci_disable_busmaster "device_t dev" .Ft int @@ -670,6 +673,11 @@ then the function will fail with .Er EOPNOTSUPP . .Pp The +.Fn pci_clear_pme +function is used to clear any pending PME# signal and disable generation +of power management events. +.Pp +The .Fn pci_iov_attach function is used to advertise that the given device .Pq and associated device driver diff --git a/sys/dev/cardbus/cardbus.c b/sys/dev/cardbus/cardbus.c index 261e9a5205ae..8dd543c68677 100644 --- a/sys/dev/cardbus/cardbus.c +++ b/sys/dev/cardbus/cardbus.c @@ -223,6 +223,7 @@ cardbus_attach_card(device_t cbdev) DEVPRINTF((cbdev, "Warning: Bogus CIS ignored\n")); pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 0); pci_cfg_restore(dinfo->pci.cfg.dev, &dinfo->pci); + pci_clear_pme(child); cardbus_device_setup_regs(&dinfo->pci.cfg); pci_add_resources(cbdev, child, 1, dinfo->mprefetchable); pci_print_verbose(&dinfo->pci); diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 7107fbe4884b..a99c34271f96 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -2921,6 +2921,22 @@ pci_get_powerstate_method(device_t dev, device_t child) return (result); } +/* Clear any active PME# and disable PME# generation. */ +void +pci_clear_pme(device_t dev) +{ + struct pci_devinfo *dinfo = device_get_ivars(dev); + pcicfgregs *cfg = &dinfo->cfg; + uint16_t status; + + if (cfg->pp.pp_cap != 0) { + status = pci_read_config(dev, dinfo->cfg.pp.pp_status, 2); + status &= ~PCIM_PSTAT_PMEENABLE; + status |= PCIM_PSTAT_PME; + pci_write_config(dev, dinfo->cfg.pp.pp_status, status, 2); + } +} + /* * Some convenience functions for PCI device drivers. */ @@ -4466,6 +4482,7 @@ pci_add_child(device_t bus, struct pci_devinfo *dinfo) resource_list_init(&dinfo->resources); pci_cfg_save(dev, dinfo, 0); pci_cfg_restore(dev, dinfo); + pci_clear_pme(dev); pci_print_verbose(dinfo); pci_add_resources(bus, dev, 0, 0); if (pci_enable_mps_tune) @@ -4665,6 +4682,7 @@ pci_resume_child(device_t dev, device_t child) dinfo = device_get_ivars(child); pci_cfg_restore(child, dinfo); + pci_clear_pme(child); if (!device_is_attached(child)) pci_cfg_save(child, dinfo, 1); diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index 888159d59c1a..d365b9132069 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -685,6 +685,7 @@ void pci_restore_state(device_t dev); void pci_save_state(device_t dev); int pci_set_max_read_req(device_t dev, int size); int pci_power_reset(device_t dev); +void pci_clear_pme(device_t dev); uint32_t pcie_read_config(device_t dev, int reg, int width); void pcie_write_config(device_t dev, int reg, uint32_t value, int width); uint32_t pcie_adjust_config(device_t dev, int reg, uint32_t mask,