From nobody Wed Mar 4 15:50:26 2026 X-Original-To: dev-commits-src-main@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 4fQxvk2560z6TgKG for ; Wed, 04 Mar 2026 15:50:26 +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 "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fQxvk14sFz3nRV for ; Wed, 04 Mar 2026 15:50:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772639426; 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=ncMEpIyeELc2z2bauQlpzWVLnyBFHIQOID4EKoODQOM=; b=xOl8OZEclb8q7EH8tlpAPds969ITKzLj2Xxl9VhKA7jViYUjJgPHqeQBN2M86rGUmG5TzX 5oe5LlHT12ThumiE1lqEv9sfa4NQjbxyXzwOLBvM+ZgVH2F3NXtyrF8KuBRO2FtS5sQHVH 5S/47ApYcchCfckW4mVJnBSkIp68IDUd16xYK4CZ8ztXHmdeALlBUJF4Na/nxEp5XtGtp5 2eI1Bnadd4o8NSFspCy5Jgnlfcgmb0hQi+e5INjTbY73VIq3v+g+4amOD6GY5GwUY4WBY/ bSVl9xgxtQAX+Lc4pT6GcaH4UvQeNOi/AcihKB0Tm3BpDJwIZhN0xq/5R53mfw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1772639426; a=rsa-sha256; cv=none; b=BNoxteHEKwTUcsWgya+zdzBNc1iJ5+EzqnZkHI4UFwsSxidMueusO6326ZQIhxzCKdykbF nKj+CsWKnqAHHDKUqYmpcmQ/Gd3z7oCNZENGZo64OhIXuFo5AwhMQOPHlL42z7NAyiYdxh wzymJ2q5fpR8ANPSe4/iSMF+2JBqPxhPeLiMNcR09K4LSb5MuDjPtdGX72hUNWORiIrbzv hkAzjnSWH1wgTUOAjr7vvWXT075ISQFzZmXBLUPuU2jjq7XXcpeeTXTVS4M0c48drXF5vU Y9Sk2rX0nrqvWVXP2Wx09839Kjcav0qAspit2QYHLxvhnkoIHlCC6qb3WfvBkA== 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=1772639426; 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=ncMEpIyeELc2z2bauQlpzWVLnyBFHIQOID4EKoODQOM=; b=LqtvQ9fCQjac/Akc7Uwp9nrBdiz8faJv5KQhxYlQoKZ24ZujID3Bywr/LJCMR0pW82SYcO 1TtbLJXR5zRQCOHTOPbaQm/0ZGUICjiMkplZ7Bn286xTeXl4FNmAQPHTUXntAwliWCdr7A GkSNmHr6aEJZFqos3f0HOcH6lwHjU+5Q2U70+vOSJqoWuoGJRJhJHEjNaVvWbXT2C/livE mIAHl1GHHc4w/u4tE++7c3MyNJSaYD4i5rMalZto09erKLAWqRla+V0pS88y7bEyAjPCWw GRFmzUARTWMHRRrzL8WxNM8npe1ZSwCerppjnH4H4GTq84rWBXj8wdihVMUZpQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fQxvk0Rl6zxT1 for ; Wed, 04 Mar 2026 15:50:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3386c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 04 Mar 2026 15:50:26 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Aymeric Wibo Subject: git: 2c60fce365f4 - main - amdsmu: Sleep entry/exit hints for PMFW List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: obiwac X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2c60fce365f4398ff02a86b46e2862905f88fa97 Auto-Submitted: auto-generated Date: Wed, 04 Mar 2026 15:50:26 +0000 Message-Id: <69a854c2.3386c.1a45b68f@gitrepo.freebsd.org> The branch main has been updated by obiwac: URL: https://cgit.FreeBSD.org/src/commit/?id=2c60fce365f4398ff02a86b46e2862905f88fa97 commit 2c60fce365f4398ff02a86b46e2862905f88fa97 Author: Aymeric Wibo AuthorDate: 2025-06-14 15:33:24 +0000 Commit: Aymeric Wibo CommitDate: 2026-03-04 15:38:57 +0000 amdsmu: Sleep entry/exit hints for PMFW amdsmu_suspend() and amdsmu_resume() for sending hints to the AMD SMU power management firmware (PMFW) that we are entering and exiting s2idle. We also dump sleep metrics once we tell it we're exiting sleep, so the relevant metrics are updated. Register these as acpi_post_dev_suspend and acpi_post_dev_resume eventhandlers. Reviewed by: olce Approved by: olce Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48721 --- sys/dev/amdsmu/amdsmu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++- sys/dev/amdsmu/amdsmu.h | 11 +++++++++-- sys/dev/amdsmu/amdsmu_reg.h | 1 + sys/modules/amdsmu/Makefile | 3 ++- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/sys/dev/amdsmu/amdsmu.c b/sys/dev/amdsmu/amdsmu.c index 416f875c6176..9a6873b43517 100644 --- a/sys/dev/amdsmu/amdsmu.c +++ b/sys/dev/amdsmu/amdsmu.c @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2025 The FreeBSD Foundation + * Copyright (c) 2025-2026 The FreeBSD Foundation * * This software was developed by Aymeric Wibo * under sponsorship from the FreeBSD Foundation. @@ -14,6 +14,13 @@ #include #include +#include "opt_acpi.h" + +#if defined(DEV_ACPI) +#include +#include +#endif + #include #include @@ -289,6 +296,27 @@ amdsmu_fetch_idlemask(device_t dev) sc->idlemask = amdsmu_read4(sc, SMU_REG_IDLEMASK); } +static void +amdsmu_suspend(device_t dev, enum power_stype stype) +{ + if (stype != POWER_STYPE_SUSPEND_TO_IDLE) + return; + if (amdsmu_cmd(dev, SMU_MSG_SLEEP_HINT, true, NULL) != 0) + device_printf(dev, "failed to hint to SMU to enter sleep"); +} + +static void +amdsmu_resume(device_t dev, enum power_stype stype) +{ + if (stype != POWER_STYPE_SUSPEND_TO_IDLE) + return; + if (amdsmu_cmd(dev, SMU_MSG_SLEEP_HINT, false, NULL) != 0) + device_printf(dev, "failed to hint to SMU to exit sleep"); + /* Update metrics after resume. */ + amdsmu_dump_metrics(dev); + amdsmu_fetch_idlemask(dev); +} + static int amdsmu_attach(device_t dev) { @@ -422,6 +450,19 @@ amdsmu_attach(device_t dev) "value is not documented - only used to help AMD internally debug " "issues"); +#if defined(DEV_ACPI) + /* + * Register post device suspend/pre device resume eventhandlers. We use + * a lower priority for the suspend event as we want this to be called + * after the SPMC suspend hook, and a higher priority for the resume + * event as we want this to be called before the SPMC hook. + */ + sc->eh_suspend = EVENTHANDLER_REGISTER(acpi_post_dev_suspend, + amdsmu_suspend, dev, -10); + sc->eh_resume = EVENTHANDLER_REGISTER(acpi_pre_dev_resume, + amdsmu_resume, dev, 10); +#endif + return (0); err_dump: bus_space_unmap(sc->bus_tag, sc->reg_space, SMU_MEM_SIZE); @@ -438,6 +479,11 @@ amdsmu_detach(device_t dev) struct amdsmu_softc *sc = device_get_softc(dev); int rid = 0; +#if defined(DEV_ACPI) + EVENTHANDLER_DEREGISTER(acpi_post_dev_suspend, sc->eh_suspend); + EVENTHANDLER_DEREGISTER(acpi_pre_dev_resume, sc->eh_resume); +#endif + bus_space_unmap(sc->bus_tag, sc->smu_space, SMU_MEM_SIZE); bus_space_unmap(sc->bus_tag, sc->reg_space, SMU_MEM_SIZE); diff --git a/sys/dev/amdsmu/amdsmu.h b/sys/dev/amdsmu/amdsmu.h index 025887f7fe5a..857fa21cba4e 100644 --- a/sys/dev/amdsmu/amdsmu.h +++ b/sys/dev/amdsmu/amdsmu.h @@ -6,11 +6,13 @@ * This software was developed by Aymeric Wibo * under sponsorship from the FreeBSD Foundation. */ + #ifndef _AMDSMU_H_ #define _AMDSMU_H_ #include #include +#include #include #include #include @@ -60,6 +62,9 @@ struct amdsmu_softc { struct sysctl_ctx_list *sysctlctx; struct sysctl_oid *sysctlnode; + struct eventhandler_entry *eh_suspend; + struct eventhandler_entry *eh_resume; + struct resource *res; bus_space_tag_t bus_tag; @@ -72,8 +77,10 @@ struct amdsmu_softc { uint32_t active_ip_blocks; struct sysctl_oid *ip_blocks_sysctlnode; size_t ip_block_count; - struct sysctl_oid *ip_block_sysctlnodes[nitems(amdsmu_ip_blocks_names)]; - bool ip_blocks_active[nitems(amdsmu_ip_blocks_names)]; + struct sysctl_oid *ip_block_sysctlnodes[ + nitems(amdsmu_ip_blocks_names)]; + bool ip_blocks_active[ + nitems(amdsmu_ip_blocks_names)]; bus_space_handle_t metrics_space; struct amdsmu_metrics metrics; diff --git a/sys/dev/amdsmu/amdsmu_reg.h b/sys/dev/amdsmu/amdsmu_reg.h index e685b34e6883..d45fa60941d5 100644 --- a/sys/dev/amdsmu/amdsmu_reg.h +++ b/sys/dev/amdsmu/amdsmu_reg.h @@ -45,6 +45,7 @@ enum amdsmu_res { enum amdsmu_msg { SMU_MSG_GETSMUVERSION = 0x02, + SMU_MSG_SLEEP_HINT = 0x03, SMU_MSG_LOG_GETDRAM_ADDR_HI = 0x04, SMU_MSG_LOG_GETDRAM_ADDR_LO = 0x05, SMU_MSG_LOG_START = 0x06, diff --git a/sys/modules/amdsmu/Makefile b/sys/modules/amdsmu/Makefile index 752f57173d61..faeb1b136060 100644 --- a/sys/modules/amdsmu/Makefile +++ b/sys/modules/amdsmu/Makefile @@ -9,6 +9,7 @@ KMOD= amdsmu SRCS= amdsmu.c -SRCS+= bus_if.h device_if.h pci_if.h +SRCS+= bus_if.h device_if.h pci_if.h \ + opt_acpi.h .include