From patchwork Mon Jun 9 02:46:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 895074 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 929D924676B; Mon, 9 Jun 2025 02:46:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437198; cv=none; b=be+8fsaEtlCY1hDcGanIzQ001Qiro1Xz9aGSXFAINiPA384nxSFWCzzPyKrqowGjk7gvYAFDHvbFD9uiVM9dXoVwG5e2HiWLz6iWch+WetBgpEVXD0YaJKYNwHmF8xKfwiKwNtTUBRRq9FKXhYZmiQpQ3fxsMrkqWXlXTQyCVVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437198; c=relaxed/simple; bh=oLMw9x+WtPbHGPX21gfOQ8knl48wXe3kHwwnOtKAizk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MwRdDfojmqXwNhHW/UkIoz9ZBw4w2c+/NGo4GXv31etvKu8lhN9s4WCbYHBIf9XQepJH+hkYXuE+W62nIIP9ONqdGRiHSyCSw4Np+bWf4fFWt2OlG6dxsJOcCVWNCy5cmJ+bUZTqmnMmYERnTeN2n1+PgSLb1AN9pdWpd8yu0+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M5n05K0K; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M5n05K0K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DD64C4CEF3; Mon, 9 Jun 2025 02:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749437198; bh=oLMw9x+WtPbHGPX21gfOQ8knl48wXe3kHwwnOtKAizk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M5n05K0Km7kpuOmj70Xs5absUd89YGmrZr+yMqud5L0Qt575FV4G8v3fsEKU8QY0r iO5NX+VMLhPJDSXJMXqeDE30nzN6gf5sB2cKGjaHQj4JMh352jNax7BPKXiZgd8drX y3UznIkUrwIR9eums89f4oAER/ZzsjOxpz/0zWGOe63Bcu8mOfrlkoC26nzos7gHhJ /F2sPyrUe6wQcxASe0oqeSfBC5VkeE1yB1WdtN/xAO2sDMGWCdWPn0BhBMBQOEmYGf oy+Ld7kDCHeov0zKqBr1CGdmGEaHJP8aM2P7Ii14TRtCeyReN8SX1+3r2WV+MG5zgf qQDhZs69MiOAw== From: Mario Limonciello To: "Rafael J . Wysocki" , Alex Deucher , Bjorn Helgaas Cc: amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software Suspend, aka swsusp)), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list), Greg Kroah-Hartman , Danilo Krummrich , "James E . J . Bottomley" , "Martin K . Petersen" , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-scsi@vger.kernel.org (open list:SCSI SUBSYSTEM), linux-usb@vger.kernel.org (open list:USB SUBSYSTEM), Mario Limonciello , AceLan Kao , Kai-Heng Feng , Mark Pearson , =?utf-8?q?Merthan_Karaka=C5=9F?= , Denis Benato Subject: [PATCH v3 1/5] PM: Use hibernate flows for system power off Date: Sun, 8 Jun 2025 21:46:15 -0500 Message-ID: <20250609024619.407257-2-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250609024619.407257-1-superm1@kernel.org> References: <20250609024619.407257-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello When the system is powered off the kernel will call device_shutdown() which will issue callbacks into PCI core to wake up a device and call it's shutdown() callback. This will leave devices in ACPI D0 which can cause some devices to misbehave with spurious wakeups and also leave some devices on which will consume power needlessly. The issue won't happen if the device is in D3 before system shutdown, so putting device to low power state before shutdown solves the issue. ACPI Spec 6.5, "7.4.2.5 System \_S4 State" says "Devices states are compatible with the current Power Resource states. In other words, all devices are in the D3 state when the system state is S4." The following "7.4.2.6 System \_S5 State (Soft Off)" states "The S5 state is similar to the S4 state except that OSPM does not save any context." so it's safe to assume devices should be at D3 for S5. To accomplish this, introduce a new PMSG_POWEROFF event that the PM core will use. During shutdown the use the new event to call all the device hibernate callbacks when the kernel is compiled with hibernate support. If compiled without hibernate support or hibernate fails fall back into the previous shutdown flow. Cc: AceLan Kao Cc: Kai-Heng Feng Cc: Mark Pearson Cc: Merthan Karakaş Tested-by: Denis Benato Link: https://lore.kernel.org/linux-pci/20231213182656.6165-1-mario.limonciello@amd.com/ Link: https://lore.kernel.org/linux-pci/20250506041934.1409302-1-superm1@kernel.org/ Signed-off-by: Mario Limonciello --- v3: * Add new PMSG_POWEROFF and PM_EVENT_POWEROFF which alias to poweroff callbacks * Don't try to cleanup on dpm_suspend_start() or dpm_suspend_end() failures Jump right into normal shutdown flow instead. --- drivers/base/power/main.c | 7 +++++++ include/linux/pm.h | 3 +++ include/trace/events/power.h | 3 ++- kernel/reboot.c | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index eebe699fdf4f6..0215b20c5e2c8 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -85,6 +85,8 @@ static const char *pm_verb(int event) return "restore"; case PM_EVENT_RECOVER: return "recover"; + case PM_EVENT_POWEROFF: + return "poweroff"; default: return "(unknown PM event)"; } @@ -355,6 +357,7 @@ static pm_callback_t pm_op(const struct dev_pm_ops *ops, pm_message_t state) case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: return ops->freeze; + case PM_EVENT_POWEROFF: case PM_EVENT_HIBERNATE: return ops->poweroff; case PM_EVENT_THAW: @@ -389,6 +392,7 @@ static pm_callback_t pm_late_early_op(const struct dev_pm_ops *ops, case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: return ops->freeze_late; + case PM_EVENT_POWEROFF: case PM_EVENT_HIBERNATE: return ops->poweroff_late; case PM_EVENT_THAW: @@ -423,6 +427,7 @@ static pm_callback_t pm_noirq_op(const struct dev_pm_ops *ops, pm_message_t stat case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: return ops->freeze_noirq; + case PM_EVENT_POWEROFF: case PM_EVENT_HIBERNATE: return ops->poweroff_noirq; case PM_EVENT_THAW: @@ -1296,6 +1301,8 @@ static pm_message_t resume_event(pm_message_t sleep_state) return PMSG_RECOVER; case PM_EVENT_HIBERNATE: return PMSG_RESTORE; + case PM_EVENT_POWEROFF: + return PMSG_ON; } return PMSG_ON; } diff --git a/include/linux/pm.h b/include/linux/pm.h index f0bd8fbae4f2c..cb66f47631a70 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -506,6 +506,7 @@ const struct dev_pm_ops name = { \ * RECOVER Creation of a hibernation image or restoration of the main * memory contents from a hibernation image has failed, call * ->thaw() and ->complete() for all devices. + * POWEROFF System will poweroff, call ->poweroff() for all devices. * * The following PM_EVENT_ messages are defined for internal use by * kernel subsystems. They are never issued by the PM core. @@ -536,6 +537,7 @@ const struct dev_pm_ops name = { \ #define PM_EVENT_USER 0x0100 #define PM_EVENT_REMOTE 0x0200 #define PM_EVENT_AUTO 0x0400 +#define PM_EVENT_POWEROFF 0x0800 #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE) #define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND) @@ -550,6 +552,7 @@ const struct dev_pm_ops name = { \ #define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, }) #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, }) #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, }) +#define PMSG_POWEROFF ((struct pm_message){ .event = PM_EVENT_POWEROFF, }) #define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, }) #define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, }) #define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, }) diff --git a/include/trace/events/power.h b/include/trace/events/power.h index 6c631eec23e32..8fa70f2397379 100644 --- a/include/trace/events/power.h +++ b/include/trace/events/power.h @@ -199,7 +199,8 @@ TRACE_EVENT(pstate_sample, { PM_EVENT_HIBERNATE, "hibernate" }, \ { PM_EVENT_THAW, "thaw" }, \ { PM_EVENT_RESTORE, "restore" }, \ - { PM_EVENT_RECOVER, "recover" }) + { PM_EVENT_RECOVER, "recover" }, \ + { PM_EVENT_POWEROFF, "poweroff" }) DEFINE_EVENT(cpu, cpu_frequency, diff --git a/kernel/reboot.c b/kernel/reboot.c index ec087827c85cd..c8835f8e5f271 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -305,6 +306,11 @@ static void kernel_shutdown_prepare(enum system_states state) (state == SYSTEM_HALT) ? SYS_HALT : SYS_POWER_OFF, NULL); system_state = state; usermodehelper_disable(); +#ifdef CONFIG_HIBERNATE_CALLBACKS + if (!dpm_suspend_start(PMSG_POWEROFF) && !dpm_suspend_end(PMSG_POWEROFF)) + return; + pr_emerg("Failed to power off devices, using shutdown instead.\n"); +#endif device_shutdown(); } /** From patchwork Mon Jun 9 02:46:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 895491 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86E6A2472BD; Mon, 9 Jun 2025 02:46:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437200; cv=none; b=KjXDFQ4YNim0qoPNTVi+R1JhnrcpWnQpbEl6wBWaRrhZiOkzUb4lz7GvZEhEHUr8OnOLCfTM+Dkdd5Ejo2l152pajZHC7ti2r+TEUn/YAUZq6tVJehOMJ2g5MnS2qV7ntlXm7GZI1Yh3V33T4agPhoWfi74hAqRKvljvNvjJbYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437200; c=relaxed/simple; bh=wvLxIFbimkhYugOTUjv3XpoarND1GpGr/k48CafzKdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vALhUgWX3DuzKJqiZRQM6KtzlX6v0TyPB6aMB/p1gBNF1V2Wo7TYQOkzOAE47gROU4GkbnPfPt6zim6J9I5TF3HrtNnbebIrJPNRpESMl3l3w3Irjf7tLIRXFP3zEghKXw9enRHfkl2kWA+flAx5DU+3uf5sCF+abwJdDE5dyOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gf9fLsel; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gf9fLsel" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54AB3C4CEEE; Mon, 9 Jun 2025 02:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749437200; bh=wvLxIFbimkhYugOTUjv3XpoarND1GpGr/k48CafzKdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gf9fLsel6C/015X/FlldEfiTPYrLsuf9jk7ryZBpQAl/Ktw+AgTM10amXdWrU1PSy hv8SY75slNdaPuRc3oVd3scQraOcdU2pLVUwvUCEYLp2iEjytVUhwiO87OJSt3K3LD NfwQw9rBOplR7JybWqIMXq41rGArlXGUnu4mTPRe2h0+FwfOCqK39ukGNiNxQXvGTd 10gFdNHVR9K3ZcjSEU2FJVkEW6SSiU609/ZwGNdb8W5p040UaFcRwNqg9tsmwZfRIc QeK4UjafaGTqA4abo4EuZG4YxRVYLzSK7KOjFf0ZM9NWB+xGCu891SDLtJGqK/Q7TY giS+L7akcH/Fg== From: Mario Limonciello To: "Rafael J . Wysocki" , Alex Deucher , Bjorn Helgaas Cc: amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software Suspend, aka swsusp)), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list), Greg Kroah-Hartman , Danilo Krummrich , "James E . J . Bottomley" , "Martin K . Petersen" , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-scsi@vger.kernel.org (open list:SCSI SUBSYSTEM), linux-usb@vger.kernel.org (open list:USB SUBSYSTEM), Mario Limonciello , AceLan Kao , Kai-Heng Feng , Mark Pearson , Denis Benato , =?utf-8?q?Merthan_Karaka=C5=9F?= Subject: [PATCH v3 2/5] PCI: Put PCIe ports with downstream devices into D3 at hibernate Date: Sun, 8 Jun 2025 21:46:16 -0500 Message-ID: <20250609024619.407257-3-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250609024619.407257-1-superm1@kernel.org> References: <20250609024619.407257-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello For the suspend flow PCIe ports that have downstream devices are put into the appropriate D3 state when children are not in D0. For the hibernate flow, PCIe ports with downstream devices stay in D0 however. This can lead to PCIe ports that are remained powered on needlessly during hibernate. Adjust the pci_pm_poweroff_noirq() to follow the same flow as pci_pm_suspend_noirq() in that PCIe ports that are power manageable should without downstream devices in D0 should be put into their appropriate sleep state. Cc: AceLan Kao Cc: Kai-Heng Feng Cc: Mark Pearson Cc: Denis Benato Cc: Merthan Karakaş Signed-off-by: Mario Limonciello --- v3: * Split out common code between suspend_noirq() and poweroff_noirq() to a helper function --- drivers/pci/pci-driver.c | 92 ++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index e3dc26f691069..ab4cfdfc8fbc0 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -844,6 +844,54 @@ static int pci_pm_suspend_late(struct device *dev) return pm_generic_suspend_late(dev); } +/** + * pci_pm_set_prepare_bus_pm + * @pci_dev: pci device + * + * Prepare the device to go into a low power state by saving state + * and configure bus PM policy. + * + * Return: TRUE for bus PM will be used + * FALSE for bus PM will be skipped + */ +static bool pci_pm_set_prepare_bus_pm(struct pci_dev *pci_dev) +{ + if (!pci_dev->state_saved) { + pci_save_state(pci_dev); + + /* + * If the device is a bridge with a child in D0 below it, + * it needs to stay in D0, so check skip_bus_pm to avoid + * putting it into a low-power state in that case. + */ + if (!pci_dev->skip_bus_pm && pci_power_manageable(pci_dev)) + pci_prepare_to_sleep(pci_dev); + } + + pci_dbg(pci_dev, "PCI PM: Sleep power state: %s\n", + pci_power_name(pci_dev->current_state)); + + if (pci_dev->current_state == PCI_D0) { + pci_dev->skip_bus_pm = true; + /* + * Per PCI PM r1.2, table 6-1, a bridge must be in D0 if any + * downstream device is in D0, so avoid changing the power state + * of the parent bridge by setting the skip_bus_pm flag for it. + */ + if (pci_dev->bus->self) + pci_dev->bus->self->skip_bus_pm = true; + } + + if (pci_dev->skip_bus_pm && pm_suspend_no_platform()) { + pci_dbg(pci_dev, "PCI PM: Skipped\n"); + return FALSE; + } + + pci_pm_set_unknown_state(pci_dev); + + return TRUE; +} + static int pci_pm_suspend_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); @@ -878,38 +926,8 @@ static int pci_pm_suspend_noirq(struct device *dev) } } - if (!pci_dev->state_saved) { - pci_save_state(pci_dev); - - /* - * If the device is a bridge with a child in D0 below it, - * it needs to stay in D0, so check skip_bus_pm to avoid - * putting it into a low-power state in that case. - */ - if (!pci_dev->skip_bus_pm && pci_power_manageable(pci_dev)) - pci_prepare_to_sleep(pci_dev); - } - - pci_dbg(pci_dev, "PCI PM: Suspend power state: %s\n", - pci_power_name(pci_dev->current_state)); - - if (pci_dev->current_state == PCI_D0) { - pci_dev->skip_bus_pm = true; - /* - * Per PCI PM r1.2, table 6-1, a bridge must be in D0 if any - * downstream device is in D0, so avoid changing the power state - * of the parent bridge by setting the skip_bus_pm flag for it. - */ - if (pci_dev->bus->self) - pci_dev->bus->self->skip_bus_pm = true; - } - - if (pci_dev->skip_bus_pm && pm_suspend_no_platform()) { - pci_dbg(pci_dev, "PCI PM: Skipped\n"); + if (!pci_pm_set_prepare_bus_pm(pci_dev)) goto Fixup; - } - - pci_pm_set_unknown_state(pci_dev); /* * Some BIOSes from ASUS have a bug: If a USB EHCI host controller's @@ -1136,6 +1154,8 @@ static int pci_pm_poweroff(struct device *dev) struct pci_dev *pci_dev = to_pci_dev(dev); const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + pci_dev->skip_bus_pm = false; + if (pci_has_legacy_pm_support(pci_dev)) return pci_legacy_suspend(dev, PMSG_HIBERNATE); @@ -1199,8 +1219,8 @@ static int pci_pm_poweroff_noirq(struct device *dev) return error; } - if (!pci_dev->state_saved && !pci_has_subordinate(pci_dev)) - pci_prepare_to_sleep(pci_dev); + if (!pci_pm_set_prepare_bus_pm(pci_dev)) + goto Fixup; /* * The reason for doing this here is the same as for the analogous code @@ -1209,6 +1229,7 @@ static int pci_pm_poweroff_noirq(struct device *dev) if (pci_dev->class == PCI_CLASS_SERIAL_USB_EHCI) pci_write_config_word(pci_dev, PCI_COMMAND, 0); +Fixup: pci_fixup_device(pci_fixup_suspend_late, pci_dev); return 0; @@ -1218,10 +1239,15 @@ static int pci_pm_restore_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + pci_power_t prev_state = pci_dev->current_state; + bool skip_bus_pm = pci_dev->skip_bus_pm; pci_pm_default_resume_early(pci_dev); pci_fixup_device(pci_fixup_resume_early, pci_dev); + if (!skip_bus_pm && prev_state == PCI_D3cold) + pci_pm_bridge_power_up_actions(pci_dev); + if (pci_has_legacy_pm_support(pci_dev)) return 0; From patchwork Mon Jun 9 02:46:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 895073 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5E5724886E; Mon, 9 Jun 2025 02:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437202; cv=none; b=XRt8dJ1v+Sa5UUgGWbg8MG4QlH1faTjM6jIQ/62TJ+iXsq5qsY9MmuiE9jmGY5Vv7bFvprnVFumJQL7LKcAqFGBIdfwR8rHaw5CX9VYWdkLwHO/1uR5/330xYY2DeOYYwrw4nM2q5HIbGDjlM6fjz57arz94XishCBxrX5xfvws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437202; c=relaxed/simple; bh=0MvAj5fHNZer/gyNTD5dRZtPAGVeCT2cGvpl98GWx+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Di2C0QYEzYfewOWj0+ciHB9+6a/B9vcg2HGAnEJbZkYM4KCcTtF9sGlCZ0cmo0Dkl/RwHD+n/LnnaEBaO7F8aNd3UH7/n6gN5mNI7s0aU6cfkSb7zQ6/SZIdO2l6ctxq+/Kt8heQGXB0YeEZgGV7PU76ZTFoonHSS38xgrvjUq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LaxxAOyL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LaxxAOyL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61CAEC4CEF0; Mon, 9 Jun 2025 02:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749437202; bh=0MvAj5fHNZer/gyNTD5dRZtPAGVeCT2cGvpl98GWx+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LaxxAOyLWFOQmv9lQkh9+Fi91ZLvu6Y5hAWU3k71XQxqmvLZK1pNm3rjlUn8lcRRp AuiOzWQnuayJxAvDcxRiY6gLhMkjBWsDA8YPQXCkd52EXKgtlVjquZKTQis4Oo4eRW 8pSm7pMnDY0kPqZexcw13jHZYd7dAsoLAzLFzTB/tO+5Z/iAiO1v9Sh/oyYXJI7QbT rANBEiO+Xt1tDe6Kh56NaYhTCpdtStgg5DShKMSghJX7aqgCFe6n69i0ZkDkJEpPcM 9eJNKCs8rC4vLaVRYD0qFxJSfTZOQHRuZmt85Epv3JeWB8ZMfIRR1SE0RvSWtEAsOh TcqTli5wNlqXw== From: Mario Limonciello To: "Rafael J . Wysocki" , Alex Deucher , Bjorn Helgaas Cc: amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software Suspend, aka swsusp)), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list), Greg Kroah-Hartman , Danilo Krummrich , "James E . J . Bottomley" , "Martin K . Petersen" , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-scsi@vger.kernel.org (open list:SCSI SUBSYSTEM), linux-usb@vger.kernel.org (open list:USB SUBSYSTEM), Mario Limonciello , AceLan Kao , Kai-Heng Feng , Mark Pearson , Denis Benato , =?utf-8?q?Merthan_Karaka=C5=9F?= Subject: [PATCH v3 3/5] drm/amd: Avoid evicting resources at S5 Date: Sun, 8 Jun 2025 21:46:17 -0500 Message-ID: <20250609024619.407257-4-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250609024619.407257-1-superm1@kernel.org> References: <20250609024619.407257-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello Normally resources are evicted on dGPUs at suspend or hibernate and on APUs at hibernate. These steps are unnecessary when using the S4 callbacks to put the system into S5. Cc: AceLan Kao Cc: Kai-Heng Feng Cc: Mark Pearson Cc: Denis Benato Cc: Merthan Karakaş Signed-off-by: Mario Limonciello --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 8edd88328749b..c5d8f6d551238 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -4966,6 +4966,10 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev) if (!adev->in_s4 && (adev->flags & AMD_IS_APU)) return 0; + /* No need to evict when going to S5 through S4 callbacks */ + if (system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF) + return 0; + ret = amdgpu_ttm_evict_resources(adev, TTM_PL_VRAM); if (ret) DRM_WARN("evicting device resources failed\n"); From patchwork Mon Jun 9 02:46:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 895490 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04620248F75; Mon, 9 Jun 2025 02:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437204; cv=none; b=qIinu+IYl/sOu9upMO5232DXRBv1bidUesFrpJFicEuvR+wVfTHjkAoNmmqILArLYTXL+9mzWBbBvEKP6sM0X6eUwamPmadzjMjyW/k6RoTSvW9K6SXmlg5P0Ziy6JRUKfkPQLv7w9Ifr+ns4+u4pgpsrdmAhsIOtj2nml1MU4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437204; c=relaxed/simple; bh=OloXrw3xRIAtL6oQ+ic+cZq3x0zPylu+4Y8fZrphD2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CRoXIc39xFcaTTdUS8JGZWOzpgLEXSpqpAZM7KncnevcOYgj+Fg1JjrXFOHSGURB5d3G2yvHEv7641w5HsVcFsaa+R7X2B1D0DtnjLpvvvGRWJFUNYP7bb5FwXE14C4x9Xi7nE/m+FJD0QRPAUUdMQ3jqwp5eiJfa1bxvhFwS94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iOYZtfjn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iOYZtfjn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FB40C4CEEE; Mon, 9 Jun 2025 02:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749437203; bh=OloXrw3xRIAtL6oQ+ic+cZq3x0zPylu+4Y8fZrphD2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iOYZtfjnX7mRmNhehMbarMUyvinQ1IZmG62gX2LMonv9S+oOssImBrb39ii7EpCFd fb7eCQ4QLwAGMBWvXmeXT1PU7Bf5+juQs9383AgXBguhl2MkpQUqXQTiHQJI+h/TC3 41W5B4REpqzJ/92N3o0UUtSOf+OmqsgIMvD5SGoMTGz5KcnZd9EAiDvk9Jsp+A5WCo ZBrB2Kvzc4MhCuvnSj+CP8dCNmahOn1L2kXNyePN1HgLzIp3Ory/9uLNyJwl36+Ehx OfS/NvULqOdvcksibsgFrJ2Ty7FPqXP/hmbW/MeSTnV3ogSYn46vJYLlcDtDvPmwh3 mQITDbkIEmPoQ== From: Mario Limonciello To: "Rafael J . Wysocki" , Alex Deucher , Bjorn Helgaas Cc: amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software Suspend, aka swsusp)), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list), Greg Kroah-Hartman , Danilo Krummrich , "James E . J . Bottomley" , "Martin K . Petersen" , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-scsi@vger.kernel.org (open list:SCSI SUBSYSTEM), linux-usb@vger.kernel.org (open list:USB SUBSYSTEM), Mario Limonciello Subject: [PATCH v3 4/5] scsi: Add PM_EVENT_POWEROFF into suspend callbacks Date: Sun, 8 Jun 2025 21:46:18 -0500 Message-ID: <20250609024619.407257-5-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250609024619.407257-1-superm1@kernel.org> References: <20250609024619.407257-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello When the ACPI core uses hibernation callbacks for shutdown drivers will receive PM_EVENT_POWEROFF and should handle it the same as PM_EVENT_HIBERNATE would have been used. Signed-off-by: Mario Limonciello --- v3: * New patch --- drivers/scsi/mesh.c | 1 + drivers/scsi/stex.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c index 1c15cac41d805..768b85eecc8fd 100644 --- a/drivers/scsi/mesh.c +++ b/drivers/scsi/mesh.c @@ -1762,6 +1762,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t mesg) case PM_EVENT_SUSPEND: case PM_EVENT_HIBERNATE: case PM_EVENT_FREEZE: + case PM_EVENT_POWEROFF: break; default: return 0; diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c index 63ed7f9aaa937..ee9372e1f7f07 100644 --- a/drivers/scsi/stex.c +++ b/drivers/scsi/stex.c @@ -1965,6 +1965,7 @@ static int stex_choice_sleep_mic(struct st_hba *hba, pm_message_t state) case PM_EVENT_SUSPEND: return ST_S3; case PM_EVENT_HIBERNATE: + case PM_EVENT_POWEROFF: hba->msi_lock = 0; return ST_S4; default: From patchwork Mon Jun 9 02:46:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 895072 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E310624BBFC; Mon, 9 Jun 2025 02:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437207; cv=none; b=ocKW8SGCDnK+6SYuIHhbu7nfvKePN4Mp7nAwskxVgksia5V/CV1ihS/dmVHCv+dUA2h9a85SfOGGUkJogtAF3O7uBzhj8YRhXgddt0TMOM05uAlC0bs8t4E7UAyIkdMHvDlpNXpFivfX0a8zCKmloG63MpbUQc6hJQk8xD70Ldg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749437207; c=relaxed/simple; bh=kU6/5PrnoLPvsSRESMinNLoRD724Pj4qIwsER9avoT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jR8oXmZbDbaAPxp3eCoAHPQ5FntdHuUGEU+9ttqn/1EUkVUC0wsFJFXOnAIbQXZusv4kx6LdPvm+80qZavvmfLly1bgOyIatHTcJEs+mP7xhV2Z2UMA8mEYWXbmRjq3fvAivibokbgdRwWtYMdeDr0GFHOmtwpynNnjKKSyAD3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UZvKR70r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UZvKR70r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18763C4CEF5; Mon, 9 Jun 2025 02:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749437205; bh=kU6/5PrnoLPvsSRESMinNLoRD724Pj4qIwsER9avoT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZvKR70rBdP3dlik5UAP5m+f8VYflYUmi6Tv6l+mEvoC6VJoRyzu72O2599XlVn6o lTbUVQVIXEEJ5cIkl8pyOEmdDI0u+JD3VgxZdsCcuspODUmLpVKUQeOYStOAqyfGXi 8+hE9sFcPQSXmOwE2dZ7B+78khv437ikXt8MvsaU+SCwJv3ERtK89bUgI8FyUURrln 9Z93cSsv/BfCw9XgQWzpUOo3PHl8nMgL9M6EjIAT/aUDdd0bjtam5aFsMD7tA7tN6y IrtbehRzta/vL2J+cYTVxEnBuZIm84+eMthlOe9pjxOuqjTjeqSwvMXcScVRtb8dbN QdaudT+cjQWow== From: Mario Limonciello To: "Rafael J . Wysocki" , Alex Deucher , Bjorn Helgaas Cc: amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software Suspend, aka swsusp)), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list), Greg Kroah-Hartman , Danilo Krummrich , "James E . J . Bottomley" , "Martin K . Petersen" , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-scsi@vger.kernel.org (open list:SCSI SUBSYSTEM), linux-usb@vger.kernel.org (open list:USB SUBSYSTEM), Mario Limonciello Subject: [PATCH v3 5/5] usb: sl811-hcd: Add PM_EVENT_POWEROFF into suspend callbacks Date: Sun, 8 Jun 2025 21:46:19 -0500 Message-ID: <20250609024619.407257-6-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250609024619.407257-1-superm1@kernel.org> References: <20250609024619.407257-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello When the ACPI core uses hibernation callbacks for shutdown drivers will receive PM_EVENT_POWEROFF and should handle it the same as PM_EVENT_HIBERNATE would have been used. Signed-off-by: Mario Limonciello --- drivers/usb/host/sl811-hcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index ea3cab99c5d40..5d6dba681e503 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1748,6 +1748,7 @@ sl811h_suspend(struct platform_device *dev, pm_message_t state) break; case PM_EVENT_SUSPEND: case PM_EVENT_HIBERNATE: + case PM_EVENT_POWEROFF: case PM_EVENT_PRETHAW: /* explicitly discard hw state */ port_power(sl811, 0); break;