Linux EFI development
 help / color / mirror / Atom feed
From: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
To: linux-acpi@vger.kernel.org, linux-efi@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>, Ard Biesheuvel <ardb@kernel.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
	Pawel Chmielewski <pawel.chmielewski@intel.com>,
	acpica-devel@lists.linux.dev,
	Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
Subject: [PATCH 1/2] ACPI: TAD: introduce acpi_tad_rtc_available()
Date: Thu, 22 Oct 2026 17:13:03 -0400	[thread overview]
Message-ID: <20261022211304.2285792-1-hamzamahfooz@linux.microsoft.com> (raw)

Code outside of the TAD driver, such as the EFI subsystem, may need to
know whether or not the RTC can be driven via the ACPI TAD, for example
to avoid registering a redundant RTC.

For this purpose, add a new header, include/acpi/acpi_tad.h, containing
a define for the TAD's hardware ID, the TAD capability flags moved there
from the driver, and a helper, acpi_tad_rtc_available(), that returns
whether or not acpi-tad will register an RTC class device for a TAD.

acpi-tad does that for a TAD that implements the Get/Set Real Time
methods, as advertised by bit 2 of its _GCP return value, but only if
the TAD has been enumerated as a platform device, so make the helper
check both.

Signed-off-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
---
 drivers/acpi/acpi_tad.c | 15 ++-------
 include/acpi/acpi_tad.h | 67 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 12 deletions(-)
 create mode 100644 include/acpi/acpi_tad.h

diff --git a/drivers/acpi/acpi_tad.c b/drivers/acpi/acpi_tad.c
index 45459a4ca..5fb978523 100644
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -33,21 +33,12 @@
 #include <linux/rtc.h>
 #include <linux/suspend.h>
 
+#include <acpi/acpi_tad.h>
+
 MODULE_DESCRIPTION("ACPI Time and Alarm (TAD) Device Driver");
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Rafael J. Wysocki");
 
-/* ACPI TAD capability flags (ACPI 6.6, Section 9.17.2) */
-#define ACPI_TAD_AC_WAKE	BIT(0)
-#define ACPI_TAD_DC_WAKE	BIT(1)
-#define ACPI_TAD_RT		BIT(2)
-#define ACPI_TAD_RT_IN_MS	BIT(3)
-#define ACPI_TAD_S4_S5__GWS	BIT(4)
-#define ACPI_TAD_AC_S4_WAKE	BIT(5)
-#define ACPI_TAD_AC_S5_WAKE	BIT(6)
-#define ACPI_TAD_DC_S4_WAKE	BIT(7)
-#define ACPI_TAD_DC_S5_WAKE	BIT(8)
-
 /* ACPI TAD alarm timer selection */
 #define ACPI_TAD_AC_TIMER	(u32)0
 #define ACPI_TAD_DC_TIMER	(u32)1
@@ -895,7 +886,7 @@ static int acpi_tad_probe(struct platform_device *pdev)
 }
 
 static const struct acpi_device_id acpi_tad_ids[] = {
-	{"ACPI000E", 0},
+	{ACPI_TAD_HID, 0},
 	{}
 };
 
diff --git a/include/acpi/acpi_tad.h b/include/acpi/acpi_tad.h
new file mode 100644
index 000000000..4825e10e9
--- /dev/null
+++ b/include/acpi/acpi_tad.h
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * ACPI Time and Alarm Device (TAD) definitions (ACPI 6.6, Section 9.17)
+ */
+#ifndef __ACPI_TAD_H
+#define __ACPI_TAD_H
+
+#include <linux/acpi.h>
+#include <linux/bits.h>
+#include <linux/platform_device.h>
+#include <linux/types.h>
+
+#define ACPI_TAD_HID		"ACPI000E"
+
+/* ACPI TAD capability flags (ACPI 6.6, Section 9.17.2) */
+#define ACPI_TAD_AC_WAKE	BIT(0)
+#define ACPI_TAD_DC_WAKE	BIT(1)
+#define ACPI_TAD_RT		BIT(2)
+#define ACPI_TAD_RT_IN_MS	BIT(3)
+#define ACPI_TAD_S4_S5__GWS	BIT(4)
+#define ACPI_TAD_AC_S4_WAKE	BIT(5)
+#define ACPI_TAD_AC_S5_WAKE	BIT(6)
+#define ACPI_TAD_DC_S4_WAKE	BIT(7)
+#define ACPI_TAD_DC_S5_WAKE	BIT(8)
+
+#if IS_ENABLED(CONFIG_ACPI_TAD) && IS_ENABLED(CONFIG_RTC_CLASS)
+/**
+ * acpi_tad_rtc_available - Check if the RTC can be driven via the ACPI TAD
+ *
+ * Check if there is a TAD that the acpi-tad driver will register an RTC class
+ * device for.
+ *
+ * Context: Process context, after the ACPI namespace has been scanned.
+ *
+ * Return: %true if acpi-tad will provide an RTC, %false otherwise.
+ */
+static inline bool acpi_tad_rtc_available(void)
+{
+	struct acpi_device *adev;
+	unsigned long long caps;
+	struct device *dev;
+	acpi_status status;
+
+	adev = acpi_dev_get_first_match_dev(ACPI_TAD_HID, NULL, -1);
+	if (!adev)
+		return false;
+
+	dev = bus_find_device_by_acpi_dev(&platform_bus_type, adev);
+	if (!dev) {
+		acpi_dev_put(adev);
+		return false;
+	}
+	put_device(dev);
+
+	status = acpi_evaluate_integer(adev->handle, "_GCP", NULL, &caps);
+	acpi_dev_put(adev);
+
+	return ACPI_SUCCESS(status) && (caps & ACPI_TAD_RT);
+}
+#else
+static inline bool acpi_tad_rtc_available(void)
+{
+	return false;
+}
+#endif /* CONFIG_ACPI_TAD && CONFIG_RTC_CLASS */
+
+#endif /* __ACPI_TAD_H */
-- 
2.56.0


             reply	other threads:[~2026-10-22 21:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 21:13 Hamza Mahfooz [this message]
2026-10-22 21:13 ` [PATCH 2/2] efi: don't register rtc-efi if the ACPI TAD can drive the RTC Hamza Mahfooz
2026-10-23 13:50 ` [PATCH 1/2] ACPI: TAD: introduce acpi_tad_rtc_available() Ard Biesheuvel
2026-10-23 21:28   ` Hamza Mahfooz

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=20261022211304.2285792-1-hamzamahfooz@linux.microsoft.com \
    --to=hamzamahfooz@linux.microsoft.com \
    --cc=acpica-devel@lists.linux.dev \
    --cc=ardb@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=pawel.chmielewski@intel.com \
    --cc=rafael@kernel.org \
    /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