Skip to contentSkip to conversation

Remove unused EFI runtime APIs

RFC PATCH Applied Ard Biesheuvel 8 participants 17 messages Jul 14, 2025 – Sep 14, 2025

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover Remove unused EFI runtime APIs

From: Ard Biesheuvel <[email protected]>

Using EFI runtime services to program the RTC to wake up the system is supported in theory, but rarely works in practice. Fortunately, this functionality is rarely [if ever] used to begin with so we can just drop it. (Note that the EFI rtc driver is not used by x86, which programs the CMOS rtc directly)

The same applies to GetNextHighMonoCount(), which, if implemented, usually relies on SetVariable() under the hood *, which is often not supported at runtime by non-x86 platforms. But it has no known users either so let's drop support for it as well.

This means we need to drop the slightly pointless tests for it too.

* EDK2 based EFI implementations usually have a MTC variable carrying the monotonic counter variable, which is therefore not truly monotonic, given that SetVariable() will happily overwrite it.

Cc Heinrich Schuchardt <[email protected]>
Cc Feng Tang <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
Cc Sunil V L <[email protected]>
Cc Bibo Mao <[email protected]>

Ard Biesheuvel (3):
efi-rtc: Remove wakeup functionality
efi/test: Don't bother pseudo-testing unused EFI services
efi: Remove support for pointless, unused EFI services

 arch/x86/platform/efi/efi_64.c          |  22 ----
 drivers/firmware/efi/runtime-wrappers.c |  68 ------------
 drivers/firmware/efi/test/efi_test.c    | 108 +-------------------
 drivers/rtc/rtc-efi.c                   |  76 +-------------
 drivers/xen/efi.c                       |  56 ----------
 include/linux/efi.h                     |   6 --
 6 files changed, 4 insertions(+), 332 deletions(-)
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
#1 lore raw

RFC PATCH 1/3 efi-rtc: Remove wakeup functionality

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

---
 drivers/rtc/rtc-efi.c | 76 +-------------------
 1 file changed, 2 insertions(+), 74 deletions(-)
drivers/rtc/rtc-efi.c +2 -74
index fa8bf82df948..b4f44999ef0f 100644
@@ -112,48 +112,6 @@ convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime)
 	return true;
 }
 
-static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-	efi_time_t eft;
-	efi_status_t status;
-
-	/*
-	 * As of EFI v1.10, this call always returns an unsupported status
-	 */
-	status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled,
-				     (efi_bool_t *)&wkalrm->pending, &eft);
-
-	if (status != EFI_SUCCESS)
-		return -EINVAL;
-
-	if (!convert_from_efi_time(&eft, &wkalrm->time))
-		return -EIO;
-
-	return rtc_valid_tm(&wkalrm->time);
-}
-
-static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-	efi_time_t eft;
-	efi_status_t status;
-
-	convert_to_efi_time(&wkalrm->time, &eft);
-
-	/*
-	 * XXX Fixme:
-	 * As of EFI 0.92 with the firmware I have on my
-	 * machine this call does not seem to work quite
-	 * right
-	 *
-	 * As of v1.10, this call always returns an unsupported status
-	 */
-	status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft);
-
-	dev_warn(dev, "write status is %d\n", (int)status);
-
-	return status == EFI_SUCCESS ? 0 : -EINVAL;
-}
-
 static int efi_read_time(struct device *dev, struct rtc_time *tm)
 {
 	efi_status_t status;
@@ -188,17 +146,13 @@ static int efi_set_time(struct device *dev, struct rtc_time *tm)
 
 static int efi_procfs(struct device *dev, struct seq_file *seq)
 {
-	efi_time_t        eft, alm;
+	efi_time_t        eft;
 	efi_time_cap_t    cap;
-	efi_bool_t        enabled, pending;
-	struct rtc_device *rtc = dev_get_drvdata(dev);
 
 	memset(&eft, 0, sizeof(eft));
-	memset(&alm, 0, sizeof(alm));
 	memset(&cap, 0, sizeof(cap));
 
 	efi.get_time(&eft, &cap);
-	efi.get_wakeup_time(&enabled, &pending, &alm);
 
 	seq_printf(seq,
 		   "Time\t\t: %u:%u:%u.%09u\n"
@@ -214,26 +168,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
 		/* XXX fixme: convert to string? */
 		seq_printf(seq, "Timezone\t: %u\n", eft.timezone);
 
-	if (test_bit(RTC_FEATURE_ALARM, rtc->features)) {
-		seq_printf(seq,
-			   "Alarm Time\t: %u:%u:%u.%09u\n"
-			   "Alarm Date\t: %u-%u-%u\n"
-			   "Alarm Daylight\t: %u\n"
-			   "Enabled\t\t: %s\n"
-			   "Pending\t\t: %s\n",
-			   alm.hour, alm.minute, alm.second, alm.nanosecond,
-			   alm.year, alm.month, alm.day,
-			   alm.daylight,
-			   enabled == 1 ? "yes" : "no",
-			   pending == 1 ? "yes" : "no");
-
-		if (alm.timezone == EFI_UNSPECIFIED_TIMEZONE)
-			seq_puts(seq, "Timezone\t: unspecified\n");
-		else
-			/* XXX fixme: convert to string? */
-			seq_printf(seq, "Timezone\t: %u\n", alm.timezone);
-	}
-
 	/*
 	 * now prints the capabilities
 	 */
@@ -249,8 +183,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
 static const struct rtc_class_ops efi_rtc_ops = {
 	.read_time	= efi_read_time,
 	.set_time	= efi_set_time,
-	.read_alarm	= efi_read_alarm,
-	.set_alarm	= efi_set_alarm,
 	.proc		= efi_procfs,
 };
 
@@ -271,11 +203,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
 	platform_set_drvdata(dev, rtc);
 
 	rtc->ops = &efi_rtc_ops;
-	clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
-	if (efi_rt_services_supported(EFI_RT_SUPPORTED_WAKEUP_SERVICES))
-		set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, rtc->features);
-	else
-		clear_bit(RTC_FEATURE_ALARM, rtc->features);
+	clear_bit(RTC_FEATURE_ALARM, rtc->features);
 
 	device_init_wakeup(&dev->dev, true);
 
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
#2 lore raw

Re: [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

systemd uses the underlying functionality: a timer can wake the system up. I have no idea if that is implemented in terms of this function, though.

Signature · 2 lines
Sincerely,
Demi Marie Obenour (she/her/hers)
maintainer
#3 lore raw

Re: [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

Quoted 10 lines · Demi Marie Obenour
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

systemd uses the underlying functionality: a timer can wake the system up. I have no idea if that is implemented in terms of this function, though.

To be clear, you are referring to wake from poweroff at some date/time in the future, right?

This change does not remove this functionality from the RTC subsystem, it just ceases to expose it on non-x86 EFI platforms that claim to support it.

For reference (which I should have included in the cover letter) [0], there are arm64 server systems which always return an error when calling this API, and most non-server arm64 systems do not implement it to begin with.

The patch in question implements one of the workarounds that was considered, which is to invoke GetWakeupTime() when registering the RTC, and disable the wakeup functionality if that fails. However, that call by itself could easily regress other platforms, where GetWakeupTime() was simply never called before, and where calling it may tickle other bugs.

Hence this RFC: if nobody uses this API on non-x86 EFI platforms, then I'd rather not support it to begin with.

[0] https://lore.kernel.org/all/[email protected]/T/#u

#4 lore raw

Re: [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

Quoted 9 lines · Ard Biesheuvel
Quoted 8 lines · Demi Marie Obenour
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

Quoted 5 lines
Quoted 2 lines

systemd uses the underlying functionality: a timer can wake the system up. I have no idea if that is implemented in terms of this function, though.

To be clear, you are referring to wake from poweroff at some date/time in the future, right?

Yes.

Quoted 3 lines

This change does not remove this functionality from the RTC subsystem, it just ceases to expose it on non-x86 EFI platforms that claim to support it.

Do these platforms generally expose the functionality in a different way? If not, systemd should probably document that the functionality is non-portable if it doesn't do that already.

Signature · 2 lines
Sincerely,
Demi Marie Obenour (she/her/hers)
maintainer
#5 lore raw

Re: [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

Quoted 17 lines · Demi Marie Obenour
Quoted 9 lines · Ard Biesheuvel
Quoted 8 lines · Demi Marie Obenour
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

Quoted 5 lines
Quoted 2 lines

systemd uses the underlying functionality: a timer can wake the system up. I have no idea if that is implemented in terms of this function, though.

To be clear, you are referring to wake from poweroff at some date/time in the future, right?

Quoted 7 lines

Yes.

Quoted 3 lines

This change does not remove this functionality from the RTC subsystem, it just ceases to expose it on non-x86 EFI platforms that claim to support it.

Do these platforms generally expose the functionality in a different way?

On x86, the CMOS rtc is manipulated directly (and this is officially condoned by the EFI spec).

On non-x86, this functionality rarely works, which is really the point of this series.

Quoted 2 lines

If not, systemd should probably document that the functionality is non-portable if it doesn't do that already.

Not sure what you mean by non-portable. This functionality should be exposed in a generic manner (using the RTC subsystem interfaces), but only if it can be relied upon. On x86, the RTC subsystem will use the rtc-cmos driver, which implements the wakeup routines in terms of port I/O.

If removing this functionality altogether from the EFI rtc driver is a problem, perhaps it would be better to implement an allowlist based solution that does not attempt to access the runtime services by default.

Tested-by on v1 1/3
#6 lore raw

Re: [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

In reply to Ard Biesheuvel
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

This solves the problem reported in
https://lore.kernel.org/all/[email protected]/T/#u

Thanks!

- Feng

Quoted 129 lines
---
 drivers/rtc/rtc-efi.c | 76 +-------------------
 1 file changed, 2 insertions(+), 74 deletions(-)
drivers/rtc/rtc-efi.c +2 -74
index fa8bf82df948..b4f44999ef0f 100644
@@ -112,48 +112,6 @@ convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime)
 	return true;
 }
 
-static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-	efi_time_t eft;
-	efi_status_t status;
-
-	/*
-	 * As of EFI v1.10, this call always returns an unsupported status
-	 */
-	status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled,
-				     (efi_bool_t *)&wkalrm->pending, &eft);
-
-	if (status != EFI_SUCCESS)
-		return -EINVAL;
-
-	if (!convert_from_efi_time(&eft, &wkalrm->time))
-		return -EIO;
-
-	return rtc_valid_tm(&wkalrm->time);
-}
-
-static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-	efi_time_t eft;
-	efi_status_t status;
-
-	convert_to_efi_time(&wkalrm->time, &eft);
-
-	/*
-	 * XXX Fixme:
-	 * As of EFI 0.92 with the firmware I have on my
-	 * machine this call does not seem to work quite
-	 * right
-	 *
-	 * As of v1.10, this call always returns an unsupported status
-	 */
-	status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft);
-
-	dev_warn(dev, "write status is %d\n", (int)status);
-
-	return status == EFI_SUCCESS ? 0 : -EINVAL;
-}
-
 static int efi_read_time(struct device *dev, struct rtc_time *tm)
 {
 	efi_status_t status;
@@ -188,17 +146,13 @@ static int efi_set_time(struct device *dev, struct rtc_time *tm)
 
 static int efi_procfs(struct device *dev, struct seq_file *seq)
 {
-	efi_time_t        eft, alm;
+	efi_time_t        eft;
 	efi_time_cap_t    cap;
-	efi_bool_t        enabled, pending;
-	struct rtc_device *rtc = dev_get_drvdata(dev);
 
 	memset(&eft, 0, sizeof(eft));
-	memset(&alm, 0, sizeof(alm));
 	memset(&cap, 0, sizeof(cap));
 
 	efi.get_time(&eft, &cap);
-	efi.get_wakeup_time(&enabled, &pending, &alm);
 
 	seq_printf(seq,
 		   "Time\t\t: %u:%u:%u.%09u\n"
@@ -214,26 +168,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
 		/* XXX fixme: convert to string? */
 		seq_printf(seq, "Timezone\t: %u\n", eft.timezone);
 
-	if (test_bit(RTC_FEATURE_ALARM, rtc->features)) {
-		seq_printf(seq,
-			   "Alarm Time\t: %u:%u:%u.%09u\n"
-			   "Alarm Date\t: %u-%u-%u\n"
-			   "Alarm Daylight\t: %u\n"
-			   "Enabled\t\t: %s\n"
-			   "Pending\t\t: %s\n",
-			   alm.hour, alm.minute, alm.second, alm.nanosecond,
-			   alm.year, alm.month, alm.day,
-			   alm.daylight,
-			   enabled == 1 ? "yes" : "no",
-			   pending == 1 ? "yes" : "no");
-
-		if (alm.timezone == EFI_UNSPECIFIED_TIMEZONE)
-			seq_puts(seq, "Timezone\t: unspecified\n");
-		else
-			/* XXX fixme: convert to string? */
-			seq_printf(seq, "Timezone\t: %u\n", alm.timezone);
-	}
-
 	/*
 	 * now prints the capabilities
 	 */
@@ -249,8 +183,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
 static const struct rtc_class_ops efi_rtc_ops = {
 	.read_time	= efi_read_time,
 	.set_time	= efi_set_time,
-	.read_alarm	= efi_read_alarm,
-	.set_alarm	= efi_set_alarm,
 	.proc		= efi_procfs,
 };
 
@@ -271,11 +203,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
 	platform_set_drvdata(dev, rtc);
 
 	rtc->ops = &efi_rtc_ops;
-	clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
-	if (efi_rt_services_supported(EFI_RT_SUPPORTED_WAKEUP_SERVICES))
-		set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, rtc->features);
-	else
-		clear_bit(RTC_FEATURE_ALARM, rtc->features);
+	clear_bit(RTC_FEATURE_ALARM, rtc->features);
 
 	device_init_wakeup(&dev->dev, true);
 
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
#7 lore raw

Re: [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

In reply to Ard Biesheuvel

Hello,

Apart from the topic that should be "rtc: efi:...", I'm ready to apply this patch.

Quoted 136 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

---
 drivers/rtc/rtc-efi.c | 76 +-------------------
 1 file changed, 2 insertions(+), 74 deletions(-)
drivers/rtc/rtc-efi.c +2 -74
index fa8bf82df948..b4f44999ef0f 100644
@@ -112,48 +112,6 @@ convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime)
 	return true;
 }
 
-static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-	efi_time_t eft;
-	efi_status_t status;
-
-	/*
-	 * As of EFI v1.10, this call always returns an unsupported status
-	 */
-	status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled,
-				     (efi_bool_t *)&wkalrm->pending, &eft);
-
-	if (status != EFI_SUCCESS)
-		return -EINVAL;
-
-	if (!convert_from_efi_time(&eft, &wkalrm->time))
-		return -EIO;
-
-	return rtc_valid_tm(&wkalrm->time);
-}
-
-static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-	efi_time_t eft;
-	efi_status_t status;
-
-	convert_to_efi_time(&wkalrm->time, &eft);
-
-	/*
-	 * XXX Fixme:
-	 * As of EFI 0.92 with the firmware I have on my
-	 * machine this call does not seem to work quite
-	 * right
-	 *
-	 * As of v1.10, this call always returns an unsupported status
-	 */
-	status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft);
-
-	dev_warn(dev, "write status is %d\n", (int)status);
-
-	return status == EFI_SUCCESS ? 0 : -EINVAL;
-}
-
 static int efi_read_time(struct device *dev, struct rtc_time *tm)
 {
 	efi_status_t status;
@@ -188,17 +146,13 @@ static int efi_set_time(struct device *dev, struct rtc_time *tm)
 
 static int efi_procfs(struct device *dev, struct seq_file *seq)
 {
-	efi_time_t        eft, alm;
+	efi_time_t        eft;
 	efi_time_cap_t    cap;
-	efi_bool_t        enabled, pending;
-	struct rtc_device *rtc = dev_get_drvdata(dev);
 
 	memset(&eft, 0, sizeof(eft));
-	memset(&alm, 0, sizeof(alm));
 	memset(&cap, 0, sizeof(cap));
 
 	efi.get_time(&eft, &cap);
-	efi.get_wakeup_time(&enabled, &pending, &alm);
 
 	seq_printf(seq,
 		   "Time\t\t: %u:%u:%u.%09u\n"
@@ -214,26 +168,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
 		/* XXX fixme: convert to string? */
 		seq_printf(seq, "Timezone\t: %u\n", eft.timezone);
 
-	if (test_bit(RTC_FEATURE_ALARM, rtc->features)) {
-		seq_printf(seq,
-			   "Alarm Time\t: %u:%u:%u.%09u\n"
-			   "Alarm Date\t: %u-%u-%u\n"
-			   "Alarm Daylight\t: %u\n"
-			   "Enabled\t\t: %s\n"
-			   "Pending\t\t: %s\n",
-			   alm.hour, alm.minute, alm.second, alm.nanosecond,
-			   alm.year, alm.month, alm.day,
-			   alm.daylight,
-			   enabled == 1 ? "yes" : "no",
-			   pending == 1 ? "yes" : "no");
-
-		if (alm.timezone == EFI_UNSPECIFIED_TIMEZONE)
-			seq_puts(seq, "Timezone\t: unspecified\n");
-		else
-			/* XXX fixme: convert to string? */
-			seq_printf(seq, "Timezone\t: %u\n", alm.timezone);
-	}
-
 	/*
 	 * now prints the capabilities
 	 */
@@ -249,8 +183,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
 static const struct rtc_class_ops efi_rtc_ops = {
 	.read_time	= efi_read_time,
 	.set_time	= efi_set_time,
-	.read_alarm	= efi_read_alarm,
-	.set_alarm	= efi_set_alarm,
 	.proc		= efi_procfs,
 };
 
@@ -271,11 +203,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
 	platform_set_drvdata(dev, rtc);
 
 	rtc->ops = &efi_rtc_ops;
-	clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
-	if (efi_rt_services_supported(EFI_RT_SUPPORTED_WAKEUP_SERVICES))
-		set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, rtc->features);
-	else
-		clear_bit(RTC_FEATURE_ALARM, rtc->features);
+	clear_bit(RTC_FEATURE_ALARM, rtc->features);
 
 	device_init_wakeup(&dev->dev, true);
 
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer
#8 lore raw

Re: [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

Quoted 6 lines · Alexandre Belloni

Hello,

Apart from the topic that should be "rtc: efi:...", I'm ready to apply this patch.

Thanks, please go ahead.

Quoted 143 lines · Ard Biesheuvel
Quoted 134 lines

From: Ard Biesheuvel <[email protected]>

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

---
 drivers/rtc/rtc-efi.c | 76 +-------------------
 1 file changed, 2 insertions(+), 74 deletions(-)
drivers/rtc/rtc-efi.c +2 -75
index fa8bf82df948..b4f44999ef0f 100644
@@ -112,48 +112,6 @@ convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime)
      return true;
 }
 
-static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-     efi_time_t eft;
-     efi_status_t status;
-
-     /*
-      * As of EFI v1.10, this call always returns an unsupported status
-      */
-     status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled,
-                                  (efi_bool_t *)&wkalrm->pending, &eft);
-
-     if (status != EFI_SUCCESS)
-             return -EINVAL;
-
-     if (!convert_from_efi_time(&eft, &wkalrm->time))
-             return -EIO;
-
-     return rtc_valid_tm(&wkalrm->time);
-}
-
-static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
-{
-     efi_time_t eft;
-     efi_status_t status;
-
-     convert_to_efi_time(&wkalrm->time, &eft);
-
-     /*
-      * XXX Fixme:
-      * As of EFI 0.92 with the firmware I have on my
-      * machine this call does not seem to work quite
-      * right
-      *
-      * As of v1.10, this call always returns an unsupported status
-      */
-     status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft);
-
-     dev_warn(dev, "write status is %d\n", (int)status);
-
-     return status == EFI_SUCCESS ? 0 : -EINVAL;
-}
-
 static int efi_read_time(struct device *dev, struct rtc_time *tm)
 {
      efi_status_t status;
@@ -188,17 +146,13 @@ static int efi_set_time(struct device *dev, struct rtc_time *tm)
 
 static int efi_procfs(struct device *dev, struct seq_file *seq)
 {
-     efi_time_t        eft, alm;
+     efi_time_t        eft;
      efi_time_cap_t    cap;
-     efi_bool_t        enabled, pending;
-     struct rtc_device *rtc = dev_get_drvdata(dev);
 
      memset(&eft, 0, sizeof(eft));
-     memset(&alm, 0, sizeof(alm));
      memset(&cap, 0, sizeof(cap));
 
      efi.get_time(&eft, &cap);
-     efi.get_wakeup_time(&enabled, &pending, &alm);
 
      seq_printf(seq,
                 "Time\t\t: %u:%u:%u.%09u\n"
@@ -214,26 +168,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
              /* XXX fixme: convert to string? */
              seq_printf(seq, "Timezone\t: %u\n", eft.timezone);
 
-     if (test_bit(RTC_FEATURE_ALARM, rtc->features)) {
-             seq_printf(seq,
-                        "Alarm Time\t: %u:%u:%u.%09u\n"
-                        "Alarm Date\t: %u-%u-%u\n"
-                        "Alarm Daylight\t: %u\n"
-                        "Enabled\t\t: %s\n"
-                        "Pending\t\t: %s\n",
-                        alm.hour, alm.minute, alm.second, alm.nanosecond,
-                        alm.year, alm.month, alm.day,
-                        alm.daylight,
-                        enabled == 1 ? "yes" : "no",
-                        pending == 1 ? "yes" : "no");
-
-             if (alm.timezone == EFI_UNSPECIFIED_TIMEZONE)
-                     seq_puts(seq, "Timezone\t: unspecified\n");
-             else
-                     /* XXX fixme: convert to string? */
-                     seq_printf(seq, "Timezone\t: %u\n", alm.timezone);
-     }
-
      /*
       * now prints the capabilities
       */
@@ -249,8 +183,6 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
 static const struct rtc_class_ops efi_rtc_ops = {
      .read_time      = efi_read_time,
      .set_time       = efi_set_time,
-     .read_alarm     = efi_read_alarm,
-     .set_alarm      = efi_set_alarm,
      .proc           = efi_procfs,
 };
 
@@ -271,11 +203,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
      platform_set_drvdata(dev, rtc);
 
      rtc->ops = &efi_rtc_ops;
-     clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
-     if (efi_rt_services_supported(EFI_RT_SUPPORTED_WAKEUP_SERVICES))
-             set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, rtc->features);
-     else
-             clear_bit(RTC_FEATURE_ALARM, rtc->features);
+     clear_bit(RTC_FEATURE_ALARM, rtc->features);
 
      device_init_wakeup(&dev->dev, true);
 
--
Quoted 2 lines

2.50.0.727.gbf7dc18ff4-goog

--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

maintainer Applied
#9 lore raw

Re: (subset) [RFC PATCH 1/3] efi-rtc: Remove wakeup functionality

In reply to Ard Biesheuvel
Quoted 6 lines · Ard Biesheuvel

The EFI rtc driver is used by non-x86 architectures only, and exposes the get/set wakeup time functionality provided by the underlying platform. This is usually broken on most platforms, and not widely used to begin with [if at all], so let's just remove it.

Applied, thanks!

[1/3] efi-rtc: Remove wakeup functionality

      https://git.kernel.org/abelloni/c/50562f9cd366

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#10 lore raw

RFC PATCH 2/3 efi/test: Don't bother pseudo-testing unused EFI services

In reply to Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The EFI test module covers the get/set wakeup time EFI runtime services, as well as GetNextHighMonoCount(). In both cases, though, it just mindlessly exercises the API, without any functional testing.

In case of the get/set wakeup time services, this would involve setting the wakeup time, and subsequently checking whether the system actually wakes up at the configured time, which is difficult for obvious reasons.

In case of GetNextHighMonoCount(), this would involve performing some kind of verification that the returned number increases monotonically across reboots.

Given that these APIs are not used in Linux to begin with, let's not pretend that testing them in this manner has any value, and just drop these tests entirely, so that we can drop the APIs themselves from the Linux EFI runtime layer.

---
 drivers/firmware/efi/test/efi_test.c | 108 +-------------------
 1 file changed, 2 insertions(+), 106 deletions(-)
drivers/firmware/efi/test/efi_test.c +2 -106
index 77b5f7ac3e20..bb2ace902346 100644
@@ -333,77 +333,6 @@ static long efi_runtime_set_time(unsigned long arg)
 	return status == EFI_SUCCESS ? 0 : -EINVAL;
 }
 
-static long efi_runtime_get_waketime(unsigned long arg)
-{
-	struct efi_getwakeuptime __user *getwakeuptime_user;
-	struct efi_getwakeuptime getwakeuptime;
-	efi_bool_t enabled, pending;
-	efi_status_t status;
-	efi_time_t efi_time;
-
-	getwakeuptime_user = (struct efi_getwakeuptime __user *)arg;
-	if (copy_from_user(&getwakeuptime, getwakeuptime_user,
-				sizeof(getwakeuptime)))
-		return -EFAULT;
-
-	status = efi.get_wakeup_time(
-		getwakeuptime.enabled ? (efi_bool_t *)&enabled : NULL,
-		getwakeuptime.pending ? (efi_bool_t *)&pending : NULL,
-		getwakeuptime.time ? &efi_time : NULL);
-
-	if (put_user(status, getwakeuptime.status))
-		return -EFAULT;
-
-	if (status != EFI_SUCCESS)
-		return -EINVAL;
-
-	if (getwakeuptime.enabled && put_user(enabled,
-						getwakeuptime.enabled))
-		return -EFAULT;
-
-	if (getwakeuptime.pending && put_user(pending,
-						getwakeuptime.pending))
-		return -EFAULT;
-
-	if (getwakeuptime.time) {
-		if (copy_to_user(getwakeuptime.time, &efi_time,
-				sizeof(efi_time_t)))
-			return -EFAULT;
-	}
-
-	return 0;
-}
-
-static long efi_runtime_set_waketime(unsigned long arg)
-{
-	struct efi_setwakeuptime __user *setwakeuptime_user;
-	struct efi_setwakeuptime setwakeuptime;
-	efi_bool_t enabled;
-	efi_status_t status;
-	efi_time_t efi_time;
-
-	setwakeuptime_user = (struct efi_setwakeuptime __user *)arg;
-
-	if (copy_from_user(&setwakeuptime, setwakeuptime_user,
-				sizeof(setwakeuptime)))
-		return -EFAULT;
-
-	enabled = setwakeuptime.enabled;
-	if (setwakeuptime.time) {
-		if (copy_from_user(&efi_time, setwakeuptime.time,
-					sizeof(efi_time_t)))
-			return -EFAULT;
-
-		status = efi.set_wakeup_time(enabled, &efi_time);
-	} else
-		status = efi.set_wakeup_time(enabled, NULL);
-
-	if (put_user(status, setwakeuptime.status))
-		return -EFAULT;
-
-	return status == EFI_SUCCESS ? 0 : -EINVAL;
-}
-
 static long efi_runtime_get_nextvariablename(unsigned long arg)
 {
 	struct efi_getnextvariablename __user *getnextvariablename_user;
@@ -505,37 +434,6 @@ static long efi_runtime_get_nextvariablename(unsigned long arg)
 	return rv;
 }
 
-static long efi_runtime_get_nexthighmonocount(unsigned long arg)
-{
-	struct efi_getnexthighmonotoniccount __user *getnexthighmonocount_user;
-	struct efi_getnexthighmonotoniccount getnexthighmonocount;
-	efi_status_t status;
-	u32 count;
-
-	getnexthighmonocount_user = (struct
-			efi_getnexthighmonotoniccount __user *)arg;
-
-	if (copy_from_user(&getnexthighmonocount,
-			   getnexthighmonocount_user,
-			   sizeof(getnexthighmonocount)))
-		return -EFAULT;
-
-	status = efi.get_next_high_mono_count(
-		getnexthighmonocount.high_count ? &count : NULL);
-
-	if (put_user(status, getnexthighmonocount.status))
-		return -EFAULT;
-
-	if (status != EFI_SUCCESS)
-		return -EINVAL;
-
-	if (getnexthighmonocount.high_count &&
-	    put_user(count, getnexthighmonocount.high_count))
-		return -EFAULT;
-
-	return 0;
-}
-
 static long efi_runtime_reset_system(unsigned long arg)
 {
 	struct efi_resetsystem __user *resetsystem_user;
@@ -697,16 +595,14 @@ static long efi_test_ioctl(struct file *file, unsigned int cmd,
 		return efi_runtime_set_time(arg);
 
 	case EFI_RUNTIME_GET_WAKETIME:
-		return efi_runtime_get_waketime(arg);
-
 	case EFI_RUNTIME_SET_WAKETIME:
-		return efi_runtime_set_waketime(arg);
+		return -EINVAL;
 
 	case EFI_RUNTIME_GET_NEXTVARIABLENAME:
 		return efi_runtime_get_nextvariablename(arg);
 
 	case EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT:
-		return efi_runtime_get_nexthighmonocount(arg);
+		return -EINVAL;
 
 	case EFI_RUNTIME_QUERY_VARIABLEINFO:
 		return efi_runtime_query_variableinfo(arg);
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
#11 lore raw

RFC PATCH 3/3 efi: Remove support for pointless, unused EFI services

In reply to Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The get/set wakeup time EFI runtime services are often broken, and rarely if ever used in practice. But the GetNextHighMonoCount() EFI runtime services really takes the cake for most pointless API in the history of computing.

So let's stop exposing them in Linux, hopefully removing the urge some folks seem to feel to test these APIs, and send emails around when they don't work.

---
 arch/x86/platform/efi/efi_64.c          | 22 -------
 drivers/firmware/efi/runtime-wrappers.c | 68 --------------------
 drivers/xen/efi.c                       | 56 ----------------
 include/linux/efi.h                     |  6 --
 4 files changed, 152 deletions(-)
arch/x86/platform/efi/efi_64.c +0 -22
index e7e8f77f77f8..0207937ab39d 100644
@@ -540,19 +540,6 @@ static efi_status_t efi_thunk_set_time(efi_time_t *tm)
 	return EFI_UNSUPPORTED;
 }
 
-static efi_status_t
-efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
-			  efi_time_t *tm)
-{
-	return EFI_UNSUPPORTED;
-}
-
-static efi_status_t
-efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
-{
-	return EFI_UNSUPPORTED;
-}
-
 static unsigned long efi_name_size(efi_char16_t *name)
 {
 	return ucs2_strsize(name, EFI_VAR_NAME_LEN) + 1;
@@ -681,12 +668,6 @@ efi_thunk_get_next_variable(unsigned long *name_size,
 	return status;
 }
 
-static efi_status_t
-efi_thunk_get_next_high_mono_count(u32 *count)
-{
-	return EFI_UNSUPPORTED;
-}
-
 static void
 efi_thunk_reset_system(int reset_type, efi_status_t status,
 		       unsigned long data_size, efi_char16_t *data)
@@ -788,13 +769,10 @@ void __init efi_thunk_runtime_setup(void)
 
 	efi.get_time = efi_thunk_get_time;
 	efi.set_time = efi_thunk_set_time;
-	efi.get_wakeup_time = efi_thunk_get_wakeup_time;
-	efi.set_wakeup_time = efi_thunk_set_wakeup_time;
 	efi.get_variable = efi_thunk_get_variable;
 	efi.get_next_variable = efi_thunk_get_next_variable;
 	efi.set_variable = efi_thunk_set_variable;
 	efi.set_variable_nonblocking = efi_thunk_set_variable_nonblocking;
-	efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
 	efi.reset_system = efi_thunk_reset_system;
 	efi.query_variable_info = efi_thunk_query_variable_info;
 	efi.query_variable_info_nonblocking = efi_thunk_query_variable_info_nonblocking;
drivers/firmware/efi/runtime-wrappers.c +0 -68

114 lines not on this page · raw message

drivers/xen/efi.c +0 -56

80 lines not on this page · raw message

include/linux/efi.h +0 -6
index 50db7df0efab..516afdc8a49d 100644
@@ -650,8 +650,6 @@ extern struct efi {
 
 	efi_get_time_t			*get_time;
 	efi_set_time_t			*set_time;
-	efi_get_wakeup_time_t		*get_wakeup_time;
-	efi_set_wakeup_time_t		*set_wakeup_time;
 	efi_get_variable_t		*get_variable;
 	efi_get_next_variable_t		*get_next_variable;
 	efi_set_variable_t		*set_variable;
@@ -660,7 +658,6 @@ extern struct efi {
 	efi_query_variable_info_t	*query_variable_info_nonblocking;
 	efi_update_capsule_t		*update_capsule;
 	efi_query_capsule_caps_t	*query_capsule_caps;
-	efi_get_next_high_mono_count_t	*get_next_high_mono_count;
 	efi_reset_system_t		*reset_system;
 
 	struct efi_memory_map		memmap;
@@ -1235,13 +1232,10 @@ enum efi_rts_ids {
 	EFI_NONE,
 	EFI_GET_TIME,
 	EFI_SET_TIME,
-	EFI_GET_WAKEUP_TIME,
-	EFI_SET_WAKEUP_TIME,
 	EFI_GET_VARIABLE,
 	EFI_GET_NEXT_VARIABLE,
 	EFI_SET_VARIABLE,
 	EFI_QUERY_VARIABLE_INFO,
-	EFI_GET_NEXT_HIGH_MONO_COUNT,
 	EFI_RESET_SYSTEM,
 	EFI_UPDATE_CAPSULE,
 	EFI_QUERY_CAPSULE_CAPS,
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
maintainer Acked-by on v1 3/3
#12 lore raw

Re: [RFC PATCH 3/3] efi: Remove support for pointless, unused EFI services

Quoted 7 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The get/set wakeup time EFI runtime services are often broken, and rarely if ever used in practice. But the GetNextHighMonoCount() EFI runtime services really takes the cake for most pointless API in the history of computing.

Quoted 5 lines

So let's stop exposing them in Linux, hopefully removing the urge some folks seem to feel to test these APIs, and send emails around when they don't work.

For drivers/xen/efi.c:

Quoted 309 lines
---
 arch/x86/platform/efi/efi_64.c          | 22 -------
 drivers/firmware/efi/runtime-wrappers.c | 68 --------------------
 drivers/xen/efi.c                       | 56 ----------------
 include/linux/efi.h                     |  6 --
 4 files changed, 152 deletions(-)
arch/x86/platform/efi/efi_64.c +0 -22
index e7e8f77f77f8..0207937ab39d 100644
@@ -540,19 +540,6 @@ static efi_status_t efi_thunk_set_time(efi_time_t *tm)
 	return EFI_UNSUPPORTED;
 }
 
-static efi_status_t
-efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
-			  efi_time_t *tm)
-{
-	return EFI_UNSUPPORTED;
-}
-
-static efi_status_t
-efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
-{
-	return EFI_UNSUPPORTED;
-}
-
 static unsigned long efi_name_size(efi_char16_t *name)
 {
 	return ucs2_strsize(name, EFI_VAR_NAME_LEN) + 1;
@@ -681,12 +668,6 @@ efi_thunk_get_next_variable(unsigned long *name_size,
 	return status;
 }
 
-static efi_status_t
-efi_thunk_get_next_high_mono_count(u32 *count)
-{
-	return EFI_UNSUPPORTED;
-}
-
 static void
 efi_thunk_reset_system(int reset_type, efi_status_t status,
 		       unsigned long data_size, efi_char16_t *data)
@@ -788,13 +769,10 @@ void __init efi_thunk_runtime_setup(void)
 
 	efi.get_time = efi_thunk_get_time;
 	efi.set_time = efi_thunk_set_time;
-	efi.get_wakeup_time = efi_thunk_get_wakeup_time;
-	efi.set_wakeup_time = efi_thunk_set_wakeup_time;
 	efi.get_variable = efi_thunk_get_variable;
 	efi.get_next_variable = efi_thunk_get_next_variable;
 	efi.set_variable = efi_thunk_set_variable;
 	efi.set_variable_nonblocking = efi_thunk_set_variable_nonblocking;
-	efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
 	efi.reset_system = efi_thunk_reset_system;
 	efi.query_variable_info = efi_thunk_query_variable_info;
 	efi.query_variable_info_nonblocking = efi_thunk_query_variable_info_nonblocking;
drivers/firmware/efi/runtime-wrappers.c +0 -68
index 708b777857d3..2b66efb5ffef 100644
@@ -52,17 +52,6 @@ union efi_rts_args {
 		efi_time_t	*time;
 	} SET_TIME;
 
-	struct {
-		efi_bool_t	*enabled;
-		efi_bool_t	*pending;
-		efi_time_t	*time;
-	} GET_WAKEUP_TIME;
-
-	struct {
-		efi_bool_t	enable;
-		efi_time_t	*time;
-	} SET_WAKEUP_TIME;
-
 	struct {
 		efi_char16_t	*name;
 		efi_guid_t	*vendor;
@@ -92,10 +81,6 @@ union efi_rts_args {
 		u64		*max_variable_size;
 	} QUERY_VARIABLE_INFO;
 
-	struct {
-		u32		*high_count;
-	} GET_NEXT_HIGH_MONO_COUNT;
-
 	struct {
 		efi_capsule_header_t **capsules;
 		unsigned long	count;
@@ -232,17 +217,6 @@ static void __nocfi efi_call_rts(struct work_struct *work)
 		status = efi_call_virt(set_time,
 				       args->SET_TIME.time);
 		break;
-	case EFI_GET_WAKEUP_TIME:
-		status = efi_call_virt(get_wakeup_time,
-				       args->GET_WAKEUP_TIME.enabled,
-				       args->GET_WAKEUP_TIME.pending,
-				       args->GET_WAKEUP_TIME.time);
-		break;
-	case EFI_SET_WAKEUP_TIME:
-		status = efi_call_virt(set_wakeup_time,
-				       args->SET_WAKEUP_TIME.enable,
-				       args->SET_WAKEUP_TIME.time);
-		break;
 	case EFI_GET_VARIABLE:
 		status = efi_call_virt(get_variable,
 				       args->GET_VARIABLE.name,
@@ -272,10 +246,6 @@ static void __nocfi efi_call_rts(struct work_struct *work)
 				       args->QUERY_VARIABLE_INFO.remaining_space,
 				       args->QUERY_VARIABLE_INFO.max_variable_size);
 		break;
-	case EFI_GET_NEXT_HIGH_MONO_COUNT:
-		status = efi_call_virt(get_next_high_mono_count,
-				       args->GET_NEXT_HIGH_MONO_COUNT.high_count);
-		break;
 	case EFI_UPDATE_CAPSULE:
 		status = efi_call_virt(update_capsule,
 				       args->UPDATE_CAPSULE.capsules,
@@ -366,30 +336,6 @@ static efi_status_t virt_efi_set_time(efi_time_t *tm)
 	return status;
 }
 
-static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
-					     efi_bool_t *pending,
-					     efi_time_t *tm)
-{
-	efi_status_t status;
-
-	if (down_interruptible(&efi_runtime_lock))
-		return EFI_ABORTED;
-	status = efi_queue_work(GET_WAKEUP_TIME, enabled, pending, tm);
-	up(&efi_runtime_lock);
-	return status;
-}
-
-static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
-{
-	efi_status_t status;
-
-	if (down_interruptible(&efi_runtime_lock))
-		return EFI_ABORTED;
-	status = efi_queue_work(SET_WAKEUP_TIME, enabled, tm);
-	up(&efi_runtime_lock);
-	return status;
-}
-
 static efi_status_t virt_efi_get_variable(efi_char16_t *name,
 					  efi_guid_t *vendor,
 					  u32 *attr,
@@ -488,17 +434,6 @@ virt_efi_query_variable_info_nb(u32 attr, u64 *storage_space,
 	return status;
 }
 
-static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
-{
-	efi_status_t status;
-
-	if (down_interruptible(&efi_runtime_lock))
-		return EFI_ABORTED;
-	status = efi_queue_work(GET_NEXT_HIGH_MONO_COUNT, count);
-	up(&efi_runtime_lock);
-	return status;
-}
-
 static void __nocfi
 virt_efi_reset_system(int reset_type, efi_status_t status,
 		      unsigned long data_size, efi_char16_t *data)
@@ -556,13 +491,10 @@ void __init efi_native_runtime_setup(void)
 {
 	efi.get_time			    = virt_efi_get_time;
 	efi.set_time			    = virt_efi_set_time;
-	efi.get_wakeup_time		    = virt_efi_get_wakeup_time;
-	efi.set_wakeup_time		    = virt_efi_set_wakeup_time;
 	efi.get_variable		    = virt_efi_get_variable;
 	efi.get_next_variable		    = virt_efi_get_next_variable;
 	efi.set_variable		    = virt_efi_set_variable;
 	efi.set_variable_nonblocking	    = virt_efi_set_variable_nb;
-	efi.get_next_high_mono_count	    = virt_efi_get_next_high_mono_count;
 	efi.reset_system 		    = virt_efi_reset_system;
 	efi.query_variable_info		    = virt_efi_query_variable_info;
 	efi.query_variable_info_nonblocking = virt_efi_query_variable_info_nb;
drivers/xen/efi.c +0 -56
index fb321cd6415a..baccf2d90af0 100644
@@ -76,47 +76,6 @@ static efi_status_t xen_efi_set_time(efi_time_t *tm)
 	return efi_data(op).status;
 }
 
-static efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled,
-					    efi_bool_t *pending,
-					    efi_time_t *tm)
-{
-	struct xen_platform_op op = INIT_EFI_OP(get_wakeup_time);
-
-	if (HYPERVISOR_platform_op(&op) < 0)
-		return EFI_UNSUPPORTED;
-
-	if (tm) {
-		BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.get_wakeup_time));
-		memcpy(tm, &efi_data(op).u.get_wakeup_time, sizeof(*tm));
-	}
-
-	if (enabled)
-		*enabled = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_ENABLED);
-
-	if (pending)
-		*pending = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_PENDING);
-
-	return efi_data(op).status;
-}
-
-static efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
-{
-	struct xen_platform_op op = INIT_EFI_OP(set_wakeup_time);
-
-	BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.set_wakeup_time));
-	if (enabled)
-		efi_data(op).misc = XEN_EFI_SET_WAKEUP_TIME_ENABLE;
-	if (tm)
-		memcpy(&efi_data(op).u.set_wakeup_time, tm, sizeof(*tm));
-	else
-		efi_data(op).misc |= XEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY;
-
-	if (HYPERVISOR_platform_op(&op) < 0)
-		return EFI_UNSUPPORTED;
-
-	return efi_data(op).status;
-}
-
 static efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
 					 u32 *attr, unsigned long *data_size,
 					 void *data)
@@ -204,18 +163,6 @@ static efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
 	return efi_data(op).status;
 }
 
-static efi_status_t xen_efi_get_next_high_mono_count(u32 *count)
-{
-	struct xen_platform_op op = INIT_EFI_OP(get_next_high_monotonic_count);
-
-	if (HYPERVISOR_platform_op(&op) < 0)
-		return EFI_UNSUPPORTED;
-
-	*count = efi_data(op).misc;
-
-	return efi_data(op).status;
-}
-
 static efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
 				unsigned long count, unsigned long sg_list)
 {
@@ -280,8 +227,6 @@ void __init xen_efi_runtime_setup(void)
 {
 	efi.get_time			= xen_efi_get_time;
 	efi.set_time			= xen_efi_set_time;
-	efi.get_wakeup_time		= xen_efi_get_wakeup_time;
-	efi.set_wakeup_time		= xen_efi_set_wakeup_time;
 	efi.get_variable		= xen_efi_get_variable;
 	efi.get_next_variable		= xen_efi_get_next_variable;
 	efi.set_variable		= xen_efi_set_variable;
@@ -290,7 +235,6 @@ void __init xen_efi_runtime_setup(void)
 	efi.query_variable_info_nonblocking = xen_efi_query_variable_info;
 	efi.update_capsule		= xen_efi_update_capsule;
 	efi.query_capsule_caps		= xen_efi_query_capsule_caps;
-	efi.get_next_high_mono_count	= xen_efi_get_next_high_mono_count;
 	efi.reset_system		= xen_efi_reset_system;
 }
 
include/linux/efi.h +0 -6
index 50db7df0efab..516afdc8a49d 100644
@@ -650,8 +650,6 @@ extern struct efi {
 
 	efi_get_time_t			*get_time;
 	efi_set_time_t			*set_time;
-	efi_get_wakeup_time_t		*get_wakeup_time;
-	efi_set_wakeup_time_t		*set_wakeup_time;
 	efi_get_variable_t		*get_variable;
 	efi_get_next_variable_t		*get_next_variable;
 	efi_set_variable_t		*set_variable;
@@ -660,7 +658,6 @@ extern struct efi {
 	efi_query_variable_info_t	*query_variable_info_nonblocking;
 	efi_update_capsule_t		*update_capsule;
 	efi_query_capsule_caps_t	*query_capsule_caps;
-	efi_get_next_high_mono_count_t	*get_next_high_mono_count;
 	efi_reset_system_t		*reset_system;
 
 	struct efi_memory_map		memmap;
@@ -1235,13 +1232,10 @@ enum efi_rts_ids {
 	EFI_NONE,
 	EFI_GET_TIME,
 	EFI_SET_TIME,
-	EFI_GET_WAKEUP_TIME,
-	EFI_SET_WAKEUP_TIME,
 	EFI_GET_VARIABLE,
 	EFI_GET_NEXT_VARIABLE,
 	EFI_SET_VARIABLE,
 	EFI_QUERY_VARIABLE_INFO,
-	EFI_GET_NEXT_HIGH_MONO_COUNT,
 	EFI_RESET_SYSTEM,
 	EFI_UPDATE_CAPSULE,
 	EFI_QUERY_CAPSULE_CAPS,
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
#13 lore raw
In reply to Ard Biesheuvel
Quoted 7 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Using EFI runtime services to program the RTC to wake up the system is supported in theory, but rarely works in practice. Fortunately, this functionality is rarely [if ever] used to begin with so we can just drop it. (Note that the EFI rtc driver is not used by x86, which programs the CMOS rtc directly)

The main problem I see with firmware offering access to the RTC via UEFI services is that two different drivers, the firmware one and the Linux one might be trying to access the same busses or registers which might lead to unexpected results.

Recently there was a discussion in the RISC-V technical group for the server platform specification where the same issue was discussed concerning SetTime().

As a UEFI firmware should not care which operating system is booted, it should be up to the OS to disable EFI access to the RTC if it has native access.

Could we disable all the EFI services for the RTC in Linux dynamically when an RTC driver is successfully probed?

Best regards

Heinrich

Quoted 40 lines

The same applies to GetNextHighMonoCount(), which, if implemented, usually relies on SetVariable() under the hood *, which is often not supported at runtime by non-x86 platforms. But it has no known users either so let's drop support for it as well.

This means we need to drop the slightly pointless tests for it too.

* EDK2 based EFI implementations usually have a MTC variable carrying the monotonic counter variable, which is therefore not truly monotonic, given that SetVariable() will happily overwrite it.

Cc Heinrich Schuchardt <[email protected]>
Cc Feng Tang <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
Cc Sunil V L <[email protected]>
Cc Bibo Mao <[email protected]>

Ard Biesheuvel (3):
efi-rtc: Remove wakeup functionality
efi/test: Don't bother pseudo-testing unused EFI services
efi: Remove support for pointless, unused EFI services

  arch/x86/platform/efi/efi_64.c          |  22 ----
  drivers/firmware/efi/runtime-wrappers.c |  68 ------------
  drivers/firmware/efi/test/efi_test.c    | 108 +-------------------
  drivers/rtc/rtc-efi.c                   |  76 +-------------
  drivers/xen/efi.c                       |  56 ----------
  include/linux/efi.h                     |   6 --
  6 files changed, 4 insertions(+), 332 deletions(-)
maintainer
#14 lore raw
Quoted 19 lines · Heinrich Schuchardt
Quoted 7 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Using EFI runtime services to program the RTC to wake up the system is supported in theory, but rarely works in practice. Fortunately, this functionality is rarely [if ever] used to begin with so we can just drop it. (Note that the EFI rtc driver is not used by x86, which programs the CMOS rtc directly)

The main problem I see with firmware offering access to the RTC via UEFI services is that two different drivers, the firmware one and the Linux one might be trying to access the same busses or registers which might lead to unexpected results.

Recently there was a discussion in the RISC-V technical group for the server platform specification where the same issue was discussed concerning SetTime().

Quoted 7 lines

As a UEFI firmware should not care which operating system is booted, it should be up to the OS to disable EFI access to the RTC if it has native access.

Could we disable all the EFI services for the RTC in Linux dynamically when an RTC driver is successfully probed?

I don't think this would be the right way to do it.

It also depends on whether ACPI or DT is being used to describe the platform to the OS.

ACPI does not support describing the RTC device, so it should provide the EFI services.

DT can describe the RTC device directly, so I think it is acceptable for such firmware to mark all RTC routines unsupported in the RT_PROP table, and just expose the RTC device directly.

The OS shouldn't have to reason about these things: it is up to the platform to describe itself unambiguously.

#15 lore raw
Quoted 29 lines · Ard Biesheuvel
Quoted 19 lines · Heinrich Schuchardt
Quoted 7 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Using EFI runtime services to program the RTC to wake up the system is supported in theory, but rarely works in practice. Fortunately, this functionality is rarely [if ever] used to begin with so we can just drop it. (Note that the EFI rtc driver is not used by x86, which programs the CMOS rtc directly)

The main problem I see with firmware offering access to the RTC via UEFI services is that two different drivers, the firmware one and the Linux one might be trying to access the same busses or registers which might lead to unexpected results.

Recently there was a discussion in the RISC-V technical group for the server platform specification where the same issue was discussed concerning SetTime().

Quoted 7 lines

As a UEFI firmware should not care which operating system is booted, it should be up to the OS to disable EFI access to the RTC if it has native access.

Could we disable all the EFI services for the RTC in Linux dynamically when an RTC driver is successfully probed?

Quoted 8 lines

I don't think this would be the right way to do it.

It also depends on whether ACPI or DT is being used to describe the platform to the OS.

ACPI does not support describing the RTC device, so it should provide the EFI services.

Hi Ard,
IIUC, TAD is defined for this purpose, right?
https://uefi.org/specs/ACPI/6.6/09_ACPI_Defined_Devices_and_Device_Specific_Objects.html#time-and-alarm-device

Quoted 6 lines

DT can describe the RTC device directly, so I think it is acceptable for such firmware to mark all RTC routines unsupported in the RT_PROP table, and just expose the RTC device directly.

The OS shouldn't have to reason about these things: it is up to the platform to describe itself unambiguously.

I agree. But I think even with ACPI, EFI GetTime/SetTime can return unsupported if there is a TAD exposed with proper _GRT/_SRT and _GCP.

Thanks,
Sunil

maintainer
#16 lore raw
Quoted 47 lines · Sunil V L
Quoted 29 lines · Ard Biesheuvel
Quoted 19 lines · Heinrich Schuchardt
Quoted 7 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Using EFI runtime services to program the RTC to wake up the system is supported in theory, but rarely works in practice. Fortunately, this functionality is rarely [if ever] used to begin with so we can just drop it. (Note that the EFI rtc driver is not used by x86, which programs the CMOS rtc directly)

The main problem I see with firmware offering access to the RTC via UEFI services is that two different drivers, the firmware one and the Linux one might be trying to access the same busses or registers which might lead to unexpected results.

Recently there was a discussion in the RISC-V technical group for the server platform specification where the same issue was discussed concerning SetTime().

Quoted 7 lines

As a UEFI firmware should not care which operating system is booted, it should be up to the OS to disable EFI access to the RTC if it has native access.

Could we disable all the EFI services for the RTC in Linux dynamically when an RTC driver is successfully probed?

Quoted 8 lines

I don't think this would be the right way to do it.

It also depends on whether ACPI or DT is being used to describe the platform to the OS.

ACPI does not support describing the RTC device, so it should provide the EFI services.

Hi Ard,
IIUC, TAD is defined for this purpose, right?
https://uefi.org/specs/ACPI/6.6/09_ACPI_Defined_Devices_and_Device_Specific_Objects.html#time-and-alarm-device

Quoted 4 lines

DT can describe the RTC device directly, so I think it is acceptable for such firmware to mark all RTC routines unsupported in the RT_PROP table, and just expose the RTC device directly.

Quoted 6 lines
Quoted 2 lines

The OS shouldn't have to reason about these things: it is up to the platform to describe itself unambiguously.

I agree. But I think even with ACPI, EFI GetTime/SetTime can return unsupported if there is a TAD exposed with proper _GRT/_SRT and _GCP.

Thanks for the pointer. This device did not exist yet when I last looked at this stuff.

So it seems like TAD is a suitable way for exposing a RTC to the OS without the need for a hardware specific driver. However, the existing Linux driver does not appear to support get/set time, and is not hooked up to the RTC subsystem [yet].