Skip to contentSkip to conversation

efi: rtc: Enable SET/GET WAKEUP services as optional

PATCH Applied Shanker Donthineni 3 participants 7 messages Dec 27, 2022 – Jan 3, 2023

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: rtc: Enable SET/GET WAKEUP services as optional

The current implementation of rtc-efi is expecting all the 4 time services GET{SET}_TIME{WAKEUP} must be supported by UEFI firmware. As per the EFI_RT_PROPERTIES_TABLE, the platform specific implementations can choose to enable selective time services based on the RTC device capabilities.

This patch does the following changes to provide GET/SET RTC services on platforms that do not support the WAKEUP feature.

1) Relax time services cap check when creating a platform device.
2) Clear RTC_FEATURE_ALARM bit in the absence of WAKEUP services.
3) Conditional alarm entries in '/proc/driver/rtc'.

---
 drivers/rtc/rtc-efi.c | 48 ++++++++++++++++++++++++-------------------
 include/linux/efi.h   |  3 ++-
 2 files changed, 29 insertions(+), 22 deletions(-)
drivers/rtc/rtc-efi.c +27 -21
index e991cccdb6e9c..1e8bc6cc1e12d 100644
@@ -188,9 +188,10 @@ 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_cap_t  cap;
-	efi_bool_t      enabled, pending;
+	efi_time_t        eft, alm;
+	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));
@@ -213,23 +214,25 @@ 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);
 
-	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 (eft.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);
+	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 (eft.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
@@ -269,7 +272,10 @@ static int __init efi_rtc_probe(struct platform_device *dev)
 
 	rtc->ops = &efi_rtc_ops;
 	clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
-	set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, 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);
 
 	device_init_wakeup(&dev->dev, true);
 
include/linux/efi.h +2 -1
index 4b27519143f56..98598bd1d2fa5 100644
@@ -668,7 +668,8 @@ extern struct efi {
 
 #define EFI_RT_SUPPORTED_ALL					0x3fff
 
-#define EFI_RT_SUPPORTED_TIME_SERVICES				0x000f
+#define EFI_RT_SUPPORTED_TIME_SERVICES				0x0003
+#define EFI_RT_SUPPORTED_WAKEUP_SERVICES			0x000c
 #define EFI_RT_SUPPORTED_VARIABLE_SERVICES			0x0070
 
 extern struct mm_struct efi_mm;
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Shanker Donthineni

The current implementation of rtc-efi is expecting all the 4 time services GET{SET}_TIME{WAKEUP} must be supported by UEFI firmware. As per the EFI_RT_PROPERTIES_TABLE, the platform specific implementations can choose to enable selective time services based on the RTC device capabilities.

Quoted 8 lines

This patch does the following changes to provide GET/SET RTC services on platforms that do not support the WAKEUP feature.

1) Relax time services cap check when creating a platform device.
2) Clear RTC_FEATURE_ALARM bit in the absence of WAKEUP services.
3) Conditional alarm entries in '/proc/driver/rtc'.

Queued as a fix in efi/urgent, thanks.

Quoted 95 lines
---
 drivers/rtc/rtc-efi.c | 48 ++++++++++++++++++++++++-------------------
 include/linux/efi.h   |  3 ++-
 2 files changed, 29 insertions(+), 22 deletions(-)
drivers/rtc/rtc-efi.c +27 -21
index e991cccdb6e9c..1e8bc6cc1e12d 100644
@@ -188,9 +188,10 @@ 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_cap_t  cap;
-       efi_bool_t      enabled, pending;
+       efi_time_t        eft, alm;
+       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));
@@ -213,23 +214,25 @@ 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);
 
-       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 (eft.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);
+       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 (eft.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
@@ -269,7 +272,10 @@ static int __init efi_rtc_probe(struct platform_device *dev)
 
        rtc->ops = &efi_rtc_ops;
        clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
-       set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, 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);
 
        device_init_wakeup(&dev->dev, true);
 
include/linux/efi.h +2 -2
index 4b27519143f56..98598bd1d2fa5 100644
@@ -668,7 +668,8 @@ extern struct efi {
 
 #define EFI_RT_SUPPORTED_ALL                                   0x3fff
 
-#define EFI_RT_SUPPORTED_TIME_SERVICES                         0x000f
+#define EFI_RT_SUPPORTED_TIME_SERVICES                         0x0003
+#define EFI_RT_SUPPORTED_WAKEUP_SERVICES                       0x000c
 #define EFI_RT_SUPPORTED_VARIABLE_SERVICES                     0x0070
 
 extern struct mm_struct efi_mm;
--

2.25.1

#2 lore raw
Quoted 11 lines · Ard Biesheuvel
Quoted 10 lines · Shanker Donthineni

The current implementation of rtc-efi is expecting all the 4 time services GET{SET}_TIME{WAKEUP} must be supported by UEFI firmware. As per the EFI_RT_PROPERTIES_TABLE, the platform specific implementations can choose to enable selective time services based on the RTC device capabilities.

This patch does the following changes to provide GET/SET RTC services on platforms that do not support the WAKEUP feature.

Quoted 7 lines
Quoted 5 lines

1) Relax time services cap check when creating a platform device.
2) Clear RTC_FEATURE_ALARM bit in the absence of WAKEUP services.
3) Conditional alarm entries in '/proc/driver/rtc'.

Queued as a fix in efi/urgent, thanks.

This rather seems like an rtc heavy patch and the subject line is misleading. This should be rtc: efi:
Also, I'm pretty sure this doesn't qualify as an urgent fix.

Quoted 97 lines
Quoted 97 lines

---
 drivers/rtc/rtc-efi.c | 48 ++++++++++++++++++++++++-------------------
 include/linux/efi.h   |  3 ++-
 2 files changed, 29 insertions(+), 22 deletions(-)
drivers/rtc/rtc-efi.c +27 -21
index e991cccdb6e9c..1e8bc6cc1e12d 100644
@@ -188,9 +188,10 @@ 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_cap_t  cap;
-       efi_bool_t      enabled, pending;
+       efi_time_t        eft, alm;
+       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));
@@ -213,23 +214,25 @@ 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);
 
-       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 (eft.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);
+       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 (eft.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
@@ -269,7 +272,10 @@ static int __init efi_rtc_probe(struct platform_device *dev)
 
        rtc->ops = &efi_rtc_ops;
        clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
-       set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, 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);
 
        device_init_wakeup(&dev->dev, true);
 
include/linux/efi.h +2 -2
index 4b27519143f56..98598bd1d2fa5 100644
@@ -668,7 +668,8 @@ extern struct efi {
 
 #define EFI_RT_SUPPORTED_ALL                                   0x3fff
 
-#define EFI_RT_SUPPORTED_TIME_SERVICES                         0x000f
+#define EFI_RT_SUPPORTED_TIME_SERVICES                         0x0003
+#define EFI_RT_SUPPORTED_WAKEUP_SERVICES                       0x000c
 #define EFI_RT_SUPPORTED_VARIABLE_SERVICES                     0x0070
 
 extern struct mm_struct efi_mm;
--

2.25.1

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

Hi Alexandre Belloni,

Quoted 15 lines · Alexandre Belloni
Quoted 14 lines · Ard Biesheuvel
Quoted 13 lines · Shanker Donthineni

The current implementation of rtc-efi is expecting all the 4 time services GET{SET}_TIME{WAKEUP} must be supported by UEFI firmware. As per the EFI_RT_PROPERTIES_TABLE, the platform specific implementations can choose to enable selective time services based on the RTC device capabilities.

This patch does the following changes to provide GET/SET RTC services on platforms that do not support the WAKEUP feature.

1) Relax time services cap check when creating a platform device.
2) Clear RTC_FEATURE_ALARM bit in the absence of WAKEUP services.
3) Conditional alarm entries in '/proc/driver/rtc'.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Queued as a fix in efi/urgent, thanks.

This rather seems like an rtc heavy patch and the subject line is misleading. This should be rtc: efi:
Also, I'm pretty sure this doesn't qualify as an urgent fix.

Thanks, I'll post v2 patch with your suggested subject.

maintainer
#4 lore raw
In reply to Alexandre Belloni
Quoted 17 lines · Alexandre Belloni
Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Shanker Donthineni

The current implementation of rtc-efi is expecting all the 4 time services GET{SET}_TIME{WAKEUP} must be supported by UEFI firmware. As per the EFI_RT_PROPERTIES_TABLE, the platform specific implementations can choose to enable selective time services based on the RTC device capabilities.

This patch does the following changes to provide GET/SET RTC services on platforms that do not support the WAKEUP feature.

1) Relax time services cap check when creating a platform device.
2) Clear RTC_FEATURE_ALARM bit in the absence of WAKEUP services.
3) Conditional alarm entries in '/proc/driver/rtc'.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Queued as a fix in efi/urgent, thanks.

This rather seems like an rtc heavy patch and the subject line is misleading. This should be rtc: efi:
Also, I'm pretty sure this doesn't qualify as an urgent fix.

I'm happy to drop it from my tree, but please add a cc:stable so it gets backported to v6.1 at least. Otherwise, EFI compliant systems that implement get/set_time but not get/set_wakeup_time have no RTC at all on any LTS kernel until a year from now, and this was never the intent when we introduced the EFI_RT_PROPERTIES_TABLE.

#5 lore raw

Hi Ard Biesheuvel,

Quoted 31 lines · Ard Biesheuvel

External email: Use caution opening links or attachments

Quoted 17 lines · Alexandre Belloni
Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Shanker Donthineni

The current implementation of rtc-efi is expecting all the 4 time services GET{SET}_TIME{WAKEUP} must be supported by UEFI firmware. As per the EFI_RT_PROPERTIES_TABLE, the platform specific implementations can choose to enable selective time services based on the RTC device capabilities.

This patch does the following changes to provide GET/SET RTC services on platforms that do not support the WAKEUP feature.

1) Relax time services cap check when creating a platform device.
2) Clear RTC_FEATURE_ALARM bit in the absence of WAKEUP services.
3) Conditional alarm entries in '/proc/driver/rtc'.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Queued as a fix in efi/urgent, thanks.

This rather seems like an rtc heavy patch and the subject line is misleading. This should be rtc: efi:
Also, I'm pretty sure this doesn't qualify as an urgent fix.

Quoted 5 lines

I'm happy to drop it from my tree, but please add a cc:stable so it gets backported to v6.1 at least. Otherwise, EFI compliant systems that implement get/set_time but not get/set_wakeup_time have no RTC at all on any LTS kernel until a year from now, and this was never the intent when we introduced the EFI_RT_PROPERTIES_TABLE.

Thanks for considering the fix for stable releases, I'll post v3 patch with tag 'CC: <[email protected]> # v6.0+'

maintainer
#6 lore raw
Quoted 35 lines · Shanker Donthineni

Hi Ard Biesheuvel,

Quoted 31 lines · Ard Biesheuvel

External email: Use caution opening links or attachments

Quoted 25 lines · Alexandre Belloni
Quoted 11 lines · Ard Biesheuvel
Quoted 10 lines · Shanker Donthineni

The current implementation of rtc-efi is expecting all the 4 time services GET{SET}_TIME{WAKEUP} must be supported by UEFI firmware. As per the EFI_RT_PROPERTIES_TABLE, the platform specific implementations can choose to enable selective time services based on the RTC device capabilities.

This patch does the following changes to provide GET/SET RTC services on platforms that do not support the WAKEUP feature.

Quoted 7 lines
Quoted 5 lines

1) Relax time services cap check when creating a platform device.
2) Clear RTC_FEATURE_ALARM bit in the absence of WAKEUP services.
3) Conditional alarm entries in '/proc/driver/rtc'.

Queued as a fix in efi/urgent, thanks.

This rather seems like an rtc heavy patch and the subject line is misleading. This should be rtc: efi:
Also, I'm pretty sure this doesn't qualify as an urgent fix.

Quoted 8 lines
Quoted 5 lines

I'm happy to drop it from my tree, but please add a cc:stable so it gets backported to v6.1 at least. Otherwise, EFI compliant systems that implement get/set_time but not get/set_wakeup_time have no RTC at all on any LTS kernel until a year from now, and this was never the intent when we introduced the EFI_RT_PROPERTIES_TABLE.

Thanks for considering the fix for stable releases, I'll post v3 patch with tag 'CC: <[email protected]> # v6.0+'

No please don't resend the patch