From: Grzegorz Jaszczyk <jaz@semihalf.com>
To: linux-kernel@vger.kernel.org
Cc: jaz@semihalf.com, dmy@semihalf.com, mario.limonciello@amd.com,
seanjc@google.com, dbehr@google.com, upstream@semihalf.com,
zide.chen@intel.corp-partner.google.com,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Hans de Goede <hdegoede@redhat.com>,
Mark Gross <markgross@kernel.org>, Pavel Machek <pavel@ucw.cz>,
Sachi King <nakato@nakato.io>,
linux-acpi@vger.kernel.org (open list:ACPI),
platform-driver-x86@vger.kernel.org (open list:X86 PLATFORM
DRIVERS), linux-pm@vger.kernel.org (open list:SUSPEND TO RAM)
Subject: [RFC PATCH 2/2] platform/x86: Add virtual PMC driver used for S2Idle
Date: Thu, 7 Jul 2022 12:53:24 +0000 [thread overview]
Message-ID: <20220707125329.378277-3-jaz@semihalf.com> (raw)
In-Reply-To: <20220707125329.378277-1-jaz@semihalf.com>
Virtual PMC driver is meant for the guest VMs for the S2Idle
notification. Its purpose is to register S2Idle dev ops notify handler,
which will evaluate ACPI _DSM as a very last command before the guest
enters S2Idle power state.
This allows to trap on MMIO access done as a consequence of _DSM
evaluation and therefore notify the VMM about the guest entering S2Idle
state.
Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
---
drivers/platform/x86/Kconfig | 7 ++++
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/virt_pmc.c | 73 +++++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+)
create mode 100644 drivers/platform/x86/virt_pmc.c
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index bc4013e950ed..dee974321b01 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -479,6 +479,13 @@ config WIRELESS_HOTKEY
To compile this driver as a module, choose M here: the module will
be called wireless-hotkey.
+config VIRT_PMC
+ tristate "Virt PMC"
+ depends on ACPI && SUSPEND
+ help
+ The Virtual PMC driver is meant for the guest VMs and it's main
+ purpose is to notify about guest entering s2idle state.
+
config HP_WMI
tristate "HP WMI extras"
depends on ACPI_WMI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 4a59f47a46e2..3c3e440f11bb 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -116,6 +116,7 @@ obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o
obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o
obj-$(CONFIG_WIRELESS_HOTKEY) += wireless-hotkey.o
obj-$(CONFIG_X86_ANDROID_TABLETS) += x86-android-tablets.o
+obj-$(CONFIG_VIRT_PMC) += virt_pmc.o
# Intel uncore drivers
obj-$(CONFIG_INTEL_IPS) += intel_ips.o
diff --git a/drivers/platform/x86/virt_pmc.c b/drivers/platform/x86/virt_pmc.c
new file mode 100644
index 000000000000..d0607db6cd22
--- /dev/null
+++ b/drivers/platform/x86/virt_pmc.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Virtual Power Management Controller Driver
+ *
+ * Author: Grzegorz Jaszczyk <jaz@semihalf.com>
+ */
+
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
+#define ACPI_VIRT_PMC_DSM_UUID "9ea49ba3-434a-49a6-be30-37cc55c4d397"
+#define ACPI_VIRT_PMC_NOTIFY 1
+
+static acpi_handle virt_pmc_handle;
+
+static void virt_pmc_s2idle_notify(void)
+{
+ union acpi_object *out_obj;
+ static guid_t dsm_guid;
+
+ guid_parse(ACPI_VIRT_PMC_DSM_UUID, &dsm_guid);
+
+ out_obj = acpi_evaluate_dsm(virt_pmc_handle, &dsm_guid,
+ 0, ACPI_VIRT_PMC_NOTIFY, NULL);
+
+ acpi_handle_debug(virt_pmc_handle, "_DSM function %u evaluation %s\n",
+ ACPI_VIRT_PMC_NOTIFY, out_obj ? "successful" : "failed");
+
+ ACPI_FREE(out_obj);
+}
+
+static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = {
+ .notify = virt_pmc_s2idle_notify,
+};
+
+static int virt_pmc_probe(struct platform_device *pdev)
+{
+ int err = 0;
+
+ virt_pmc_handle = ACPI_HANDLE(&pdev->dev);
+
+ err = acpi_register_lps0_dev(&amd_pmc_s2idle_dev_ops);
+ if (err)
+ dev_warn(&pdev->dev, "failed to register LPS0 sleep handler\n");
+
+ return err;
+}
+
+static int virt_pmc_remove(struct platform_device *pdev)
+{
+ acpi_unregister_lps0_dev(&amd_pmc_s2idle_dev_ops);
+
+ return 0;
+}
+
+static const struct acpi_device_id virt_pmc_acpi_ids[] = {
+ {"HYPE0001", 0}, /* _HID for XXX Power Engine, _CID PNP0D80*/
+ { }
+};
+MODULE_DEVICE_TABLE(acpi, virt_pmc_acpi_ids);
+
+static struct platform_driver virt_pmc_driver = {
+ .driver = {
+ .name = "virtual_pmc",
+ .acpi_match_table = ACPI_PTR(virt_pmc_acpi_ids),
+ },
+ .probe = virt_pmc_probe,
+ .remove = virt_pmc_remove,
+};
+
+module_platform_driver(virt_pmc_driver);
+
+MODULE_DESCRIPTION("Virtual PMC Driver");
--
2.37.0.rc0.161.g10f37bed90-goog
next prev parent reply other threads:[~2022-07-07 12:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-07 12:53 [RFC PATCH 0/2] x86: allow to notify host about guest entering s2idle Grzegorz Jaszczyk
2022-07-07 12:53 ` [RFC PATCH 1/2] suspend: extend S2Idle ops by new notify handler Grzegorz Jaszczyk
2022-07-19 18:08 ` Rafael J. Wysocki
2022-07-20 13:15 ` Grzegorz Jaszczyk
2022-07-20 15:22 ` Limonciello, Mario
2022-07-20 15:54 ` Grzegorz Jaszczyk
2022-08-22 9:26 ` Grzegorz Jaszczyk
2022-09-12 14:44 ` Grzegorz Jaszczyk
2022-11-30 12:25 ` Grzegorz Jaszczyk
2023-02-06 18:58 ` Rafael J. Wysocki
2022-07-07 12:53 ` Grzegorz Jaszczyk [this message]
2022-07-07 15:51 ` [RFC PATCH 2/2] platform/x86: Add virtual PMC driver used for S2Idle Randy Dunlap
2022-07-07 15:27 ` [RFC PATCH 0/2] x86: allow to notify host about guest entering s2idle Limonciello, Mario
2022-07-15 13:27 ` Grzegorz Jaszczyk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220707125329.378277-3-jaz@semihalf.com \
--to=jaz@semihalf.com \
--cc=dbehr@google.com \
--cc=dmy@semihalf.com \
--cc=hdegoede@redhat.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=markgross@kernel.org \
--cc=nakato@nakato.io \
--cc=pavel@ucw.cz \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=seanjc@google.com \
--cc=upstream@semihalf.com \
--cc=zide.chen@intel.corp-partner.google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox