From: Feng Tang <feng.tang@linux.alibaba.com>
To: "Johnny.Fan" <johnny.fan@cixtech.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
linux-rtc@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
cix-kernel-upstream@cixtech.com, bob.zhang@cixtech.com,
jie.fu@cixtech.com
Subject: Re: [PATCH] rtc: efi: restore alarm support with runtime capability probe
Date: Mon, 31 Aug 2026 09:10:47 +0800 [thread overview]
Message-ID: <apTUlyX9XWyo018i@U-2FWC9VHC-2323.local> (raw)
In-Reply-To: <20260828031519.2749354-1-johnny.fan@cixtech.com>
On Fri, Aug 28, 2026 at 11:15:19AM +0800, Johnny.Fan wrote:
> From: "Johnny.Fan" <Johnny.Fan@cixtech.com>
>
> Restore the EFI RTC alarm functionality (read_alarm/set_alarm and
> procfs output) that was removed by commit 18a3510bc87d ("rtc: efi:
> Remove wakeup functionality").
>
> The removal was motivated by the observation that many EFI platforms
> lack RTC wakeup support while also omitting the RT_PROP table, causing
> the wakeup capability to be incorrectly advertised. While that is
> true, removing the feature entirely also breaks platforms where the
> wakeup runtime service actually works.
>
> On CIX SoCs with an I2C-connected RTC, the firmware owns the RTC and
> exposes it via EFI runtime services. Using the native I2C RTC driver
> under Linux breaks Windows, which relies on EFI runtime services to
> access the RTC. rtc-efi is therefore the only viable option for
> shared RTC access across operating systems, and it needs working
> alarm/wakeup support.
>
> To avoid exposing a broken alarm on firmware that does not implement
> the wakeup runtime services, probe the capability at ->probe() time by
> actually calling GetWakeupTime() -- if it fails, clear RTC_FEATURE_ALARM
> and the device behaves as before the removal.
>
> Also set RTC_FEATURE_ALARM_WAKEUP_ONLY since EFI wakeup time is a
> wakeup-only alarm, not a periodic/update interrupt source.
It covers the alarm selftest failure we met before, thanks!
Reviewed-by: Feng Tang <feng.tang@linux.alibaba.com>
>
> Reviewed-by: Fugang Duan <fugang.duan@cixtech.com>
> Tested-by: Johnny.Fan <Johnny.Fan@cixtech.com>
> Signed-off-by: Johnny.Fan <Johnny.Fan@cixtech.com>
> ---
> drivers/rtc/rtc-efi.c | 78 +++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 76 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-efi.c b/drivers/rtc/rtc-efi.c
> index b4f44999ef0f..708cba43435e 100644
> --- a/drivers/rtc/rtc-efi.c
> +++ b/drivers/rtc/rtc-efi.c
> @@ -112,6 +112,34 @@ 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;
> +
> + 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);
> +
> + status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft);
> +
> + return status == EFI_SUCCESS ? 0 : -EINVAL;
> +}
> +
> static int efi_read_time(struct device *dev, struct rtc_time *tm)
> {
> efi_status_t status;
> @@ -146,13 +174,21 @@ 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;
> + 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));
> memset(&cap, 0, sizeof(cap));
>
> efi.get_time(&eft, &cap);
> + if (test_bit(RTC_FEATURE_ALARM, rtc->features) &&
> + efi.get_wakeup_time(&enabled, &pending, &alm) != EFI_SUCCESS) {
> + enabled = false;
> + pending = false;
> + }
>
> seq_printf(seq,
> "Time\t\t: %u:%u:%u.%09u\n"
> @@ -168,6 +204,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);
>
> + 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, "Alarm Timezone\t: unspecified\n");
> + else
> + seq_printf(seq, "Alarm Timezone\t: %u\n", alm.timezone);
> + }
> +
> /*
> * now prints the capabilities
> */
> @@ -183,6 +238,8 @@ 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,
> };
>
> @@ -191,6 +248,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
> struct rtc_device *rtc;
> efi_time_t eft;
> efi_time_cap_t cap;
> + efi_bool_t enabled, pending;
>
> /* First check if the RTC is usable */
> if (efi.get_time(&eft, &cap) != EFI_SUCCESS)
> @@ -203,7 +261,23 @@ static int __init efi_rtc_probe(struct platform_device *dev)
> platform_set_drvdata(dev, rtc);
>
> rtc->ops = &efi_rtc_ops;
> - clear_bit(RTC_FEATURE_ALARM, rtc->features);
> + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
> +
> + /*
> + * The EFI_RT_SUPPORTED_WAKEUP_SERVICES bit defaults to enabled
> + * and only gets cleared when the RT_PROP table explicitly says
> + * wakeup is unsupported. Many platforms lack an RT_PROP table
> + * even though they don't implement the wakeup runtime service,
> + * so probe by actually calling GetWakeupTime() to avoid exposing
> + * a broken alarm to userspace.
> + */
> + if (efi_rt_services_supported(EFI_RT_SUPPORTED_WAKEUP_SERVICES) &&
> + efi.get_wakeup_time(&enabled, &pending, &eft) == EFI_SUCCESS) {
> + set_bit(RTC_FEATURE_ALARM, rtc->features);
> + set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, rtc->features);
> + } else {
> + clear_bit(RTC_FEATURE_ALARM, rtc->features);
> + }
>
> device_init_wakeup(&dev->dev, true);
>
> --
> 2.55.0
next prev parent reply other threads:[~2026-08-31 1:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 3:15 [PATCH] rtc: efi: restore alarm support with runtime capability probe Johnny.Fan
2026-08-28 3:32 ` sashiko-bot
2026-08-28 7:26 ` Ard Biesheuvel
2026-08-28 8:23 ` Johnny Fan
2026-08-28 8:32 ` Johnny Fan
2026-08-28 10:13 ` Ard Biesheuvel
2026-08-28 12:48 ` Alexandre Belloni
2026-08-31 1:10 ` Feng Tang [this message]
2026-08-31 11:38 ` [PATCH v2] " Johnny.Fan
2026-08-31 11:56 ` sashiko-bot
2026-08-31 13:34 ` Ard Biesheuvel
2026-08-31 14:00 ` [PATCH v3] " Johnny.Fan
2026-08-31 17:47 ` sashiko-bot
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=apTUlyX9XWyo018i@U-2FWC9VHC-2323.local \
--to=feng.tang@linux.alibaba.com \
--cc=alexandre.belloni@bootlin.com \
--cc=ardb@kernel.org \
--cc=bob.zhang@cixtech.com \
--cc=cix-kernel-upstream@cixtech.com \
--cc=jie.fu@cixtech.com \
--cc=johnny.fan@cixtech.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.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