From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mx.groups.io with SMTP id smtpd.web08.9653.1622616818590974286 for ; Tue, 01 Jun 2021 23:53:38 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IKOgtNM2; spf=pass (domain: kernel.org, ip: 198.145.29.99, mailfrom: ardb@kernel.org) Received: by mail.kernel.org (Postfix) with ESMTPSA id D862961376 for ; Wed, 2 Jun 2021 06:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622616817; bh=cPBR+OZs8WcCQ0+NUSuuLcsWhC7saco1hRDW1phcWAk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IKOgtNM2MLxA1zR3btOcFy3Qwq+qeamcTGJpmS/Fw5KrSLcLJKToF6VGGEM5Iaces +dGFysuVTanB1bejh2PpseLhHbnmX4Y7UMbwolm7sMwVH6cR9zkLoVAy/p1mwGWvP3 dSiYjmNKNdxcaPpqXkk0weuCON8ZbGmzTd71B4sREJlqR+BB9j4gn3hYjasJ1tk2Hl 0GKqoJLH16t4qEpVvIIsYwU50f6dmZZrIXmKqBzqulCCFqAHGZMZPPDSi7buBvTxP8 wzL3Yqe5mcZhhW32VEqYjlzNXV1L/BD9rVjK+BdtW07r5ZlIsiSlsSw/dyNTGRINTh EvVVXLdMxQALg== Received: by mail-lf1-f42.google.com with SMTP id w33so1713368lfu.7 for ; Tue, 01 Jun 2021 23:53:37 -0700 (PDT) X-Gm-Message-State: AOAM532/fFgRMYUM36eWZ5YV4Jx/PdrQeqvFs7rrFoInQ1GTJLlXp7vh lLeilE45FNvfuKJyuEjsLOUf9KMQ/uqs1wICSnI= X-Google-Smtp-Source: ABdhPJxZ+vkz0oYNMwTIYRwNP7zeojSNjwxvuwXDjnIm5NESpDWhK45yCbByNbvS2GOhaJT1b14nqEqBBnU0LxvpMd8= X-Received: by 2002:ac2:55b2:: with SMTP id y18mr21698543lfg.79.1622616816123; Tue, 01 Jun 2021 23:53:36 -0700 (PDT) MIME-Version: 1.0 References: <20210524052919.2496579-1-mw@semihalf.com> <20210524052919.2496579-7-mw@semihalf.com> In-Reply-To: <20210524052919.2496579-7-mw@semihalf.com> From: "Ard Biesheuvel" Date: Wed, 2 Jun 2021 08:53:24 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-platforms PATCH 6/6] Marvell: RealTimeClockLib: Rework LibGetWakeupTime/LibSetWakeupTime To: Marcin Wojtas Cc: edk2-devel-groups-io , Leif Lindholm , Ard Biesheuvel , Samer El-Haj-Mahmoud , Sunny Wang , Grzegorz Bernacki , upstream@semihalf.com Content-Type: text/plain; charset="UTF-8" On Mon, 24 May 2021 at 07:29, Marcin Wojtas wrote: > > Apply multiple fixes to the Marvell RealTimeClockLib wakeup > library callbacks. > > LibGetWakeupTime: > * Add input parameters validation > * Fix 'Pending' value check > > LibSetWakeupTime: > * Allow disabling the wakeup timer regardless the input 'Time' value > * Use more generic 'Time' value verification, which is more strict > than the replaced custom one. > * Use proper alarm mask for 'Pending' signalling > > With above the ACS3.0 FWTS and SCT timer tests pass cleanly. > > Signed-off-by: Marcin Wojtas Reviewed-by: Ard Biesheuvel > --- > Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.h | 2 +- > Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c | 29 ++++++++++---------- > 2 files changed, 16 insertions(+), 15 deletions(-) > > diff --git a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.h b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.h > index 7fa1d092e4..c33e63d107 100644 > --- a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.h > +++ b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.h > @@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #define RTC_BRIDGE_TIMING_CTRL0_REG_OFFS 0x80 > #define RTC_BRIDGE_TIMING_CTRL1_REG_OFFS 0x84 > #define RTC_IRQ_STATUS_REG 0x90 > -#define RTC_IRQ_ALARM_MASK 0x1 > +#define RTC_IRQ_ALARM_MASK 0x2 > #define RTC_WRITE_PERIOD_DELAY_MASK 0xFFFF > #define RTC_WRITE_PERIOD_DELAY_DEFAULT 0x3FF > #define RTC_WRITE_SETUP_DELAY_MASK (0xFFFF << 16) > diff --git a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c > index a48d44ed83..49c9385d53 100644 > --- a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c > +++ b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c > @@ -140,11 +140,15 @@ LibGetWakeupTime ( > { > UINT32 WakeupSeconds; > > + if (Time == NULL || Enabled == NULL || Pending == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > *Enabled = MmioRead32 (mArmadaRtcBase + RTC_IRQ_2_CONFIG_REG) & RTC_IRQ_ALARM_EN; > > *Pending = MmioRead32 (mArmadaRtcBase + RTC_IRQ_STATUS_REG) & RTC_IRQ_ALARM_MASK; > // Ack pending alarm > - if (Pending) { > + if (*Pending) { > MmioWrite32 (mArmadaRtcBase + RTC_IRQ_STATUS_REG, RTC_IRQ_ALARM_MASK); > } > > @@ -176,14 +180,14 @@ LibSetWakeupTime ( > { > UINTN WakeupSeconds; > > - // > - // Because the Armada RTC uses a 32-bit counter for seconds, > - // the maximum time span is just over 136 years. > - // Time is stored in Unix Epoch format, so it starts in 1970, > - // Therefore it can not exceed the year 2106. > - // > - if ((Time->Year < 1970) || (Time->Year >= 2106)) { > - return EFI_UNSUPPORTED; > + // Handle timer disabling case > + if (!Enabled) { > + RtcDelayedWrite (RTC_IRQ_2_CONFIG_REG, 0); > + return EFI_SUCCESS; > + } > + > + if (Time == NULL || !IsTimeValid (Time)) { > + return EFI_INVALID_PARAMETER; > } > > // Convert time to raw seconds > @@ -195,11 +199,8 @@ LibSetWakeupTime ( > // Issue delayed write to alarm register > RtcDelayedWrite (RTC_ALARM_2_REG, (UINT32)WakeupSeconds); > > - if (Enabled) { > - MmioWrite32 (mArmadaRtcBase + RTC_IRQ_2_CONFIG_REG, RTC_IRQ_ALARM_EN); > - } else { > - MmioWrite32 (mArmadaRtcBase + RTC_IRQ_2_CONFIG_REG, 0); > - } > + // Enable wakeup timer > + RtcDelayedWrite (RTC_IRQ_2_CONFIG_REG, RTC_IRQ_ALARM_EN); > > return EFI_SUCCESS; > } > -- > 2.29.0 >