public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Jun Nie <jun.nie@linaro.org>
Cc: haojian.zhuang@linaro.org, ard.biesheuvel@linaro.org,
	linaro-uefi@lists.linaro.org, shawn.guo@linaro.org,
	jason.liu@linaro.org, edk2-devel@lists.01.org
Subject: Re: [PATCH 2/4] Platforms: Add ZX RTC driver for Sanchip SoC
Date: Thu, 17 Aug 2017 16:55:02 +0100	[thread overview]
Message-ID: <20170817155502.5rjnteaye6sq6m4y@bivouac.eciton.net> (raw)
In-Reply-To: <09ad9459-9cbe-ea49-53f0-e7ce1ba74302@linaro.org>

On Thu, Aug 17, 2017 at 11:43:37PM +0800, Jun Nie wrote:
> On 2017年08月10日 22:03, Leif Lindholm wrote:
> > On Wed, Aug 09, 2017 at 10:12:37PM +0800, Jun Nie wrote:
> > > Runtime service is not supported yet.
> > > 
> > > Contributed-under: TianoCore Contribution Agreement 1.0
> > > Signed-off-by: Jun Nie <jun.nie@linaro.org>
> > > ---
> > >   .../Zx6718RealTimeClockLib/Zx296718RealTimeClock.c | 376 +++++++++++++++++++++
> > >   .../Zx6718RealTimeClockLib/Zx296718RealTimeClock.h | 102 ++++++
> > >   .../Zx296718RealTimeClock.inf                      |  42 +++
> > >   3 files changed, 520 insertions(+)
> > >   create mode 100644 Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c
> > >   create mode 100644 Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h
> > >   create mode 100644 Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.inf
> > > 
> > > diff --git a/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c
> > > new file mode 100644
> > > index 0000000..af6e5bd
> > > --- /dev/null
> > > +++ b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c
> > > @@ -0,0 +1,376 @@
> > > +/** @file
> > > +  Implement EFI RealTimeClock runtime services via RTC Lib.
> > > +
> > > +  Currently this driver does not support runtime virtual calling.
> > > +
> > > +  Copyright (C) 2017 Sanechips Technology Co., Ltd.
> > > +  Copyright (c) 2017, Linaro Limited.
> > > +
> > > +  This program and the accompanying materials
> > > +  are licensed and made available under the terms and conditions of the BSD License
> > > +  which accompanies this distribution.  The full text of the license may be found at
> > > +  http://opensource.org/licenses/bsd-license.php
> > > +
> > > +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> > > +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> > > +
> > > +  Based on the files under ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
> > > +
> > > +**/
> > > +
> > > +#include <Uefi.h>
> > > +#include <PiDxe.h>
> > 
> > P before U.
> > 
> > > +#include <Library/BaseLib.h>
> > > +#include <Library/BaseMemoryLib.h>
> > > +#include <Library/DebugLib.h>
> > > +#include <Library/IoLib.h>
> > > +#include <Library/MemoryAllocationLib.h>
> > > +#include <Library/PcdLib.h>
> > > +#include <Library/TimerLib.h>
> > > +#include <Library/UefiBootServicesTableLib.h>
> > > +#include <Library/UefiLib.h>
> > > +#include <Library/UefiRuntimeServicesTableLib.h>
> > > +// Use EfiAtRuntime to check stage
> > > +#include <Library/UefiRuntimeLib.h>
> > 
> > L (UefiRuntimeLib) before S (UefiRuntimeServices...).
> > No need for a comment explaining why we include headers.
> > 
> > > +#include <Protocol/RealTimeClock.h>
> > > +#include "Zx296718RealTimeClock.h"
> > > +
> > > +STATIC UINTN       RtcBase;
> > 
> > mRtcBase.
> > 
> > > +STATIC BOOLEAN     RTCInitialized = FALSE;
> > 
> > mRTCInitialized.
> > 
> > > +
> > > +BOOLEAN
> > > +EFIAPI
> > > +IsTimeValid(
> > > +  IN EFI_TIME *Time
> > > +  )
> > > +{
> > > +  // Check the input parameters are within the range specified by UEFI
> > > +  if ((Time->Year  < 2000) ||
> > > +     (Time->Year   > 2099) ||
> > > +     (Time->Month  < 1   ) ||
> > > +     (Time->Month  > 12  ) ||
> > > +     (Time->Day    < 1   ) ||
> > > +     (Time->Day    > 31  ) ||
> > > +     (Time->Hour   > 23  ) ||
> > > +     (Time->Minute > 59  ) ||
> > > +     (Time->Second > 59  ) ||
> > > +     (Time->Nanosecond > 999999999) ||
> > > +     (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||
> > > +     (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))
> > > +  ) {
> > > +    return FALSE;
> > > +  }
> > > +
> > > +  return TRUE;
> > > +}
> > 
> > This appears a direct copy of the version in
> > EmbeddedPkg/Library/TimeBaseLib. Can you add that TimeBaseLib library
> > dependency to decrease duplication?
> > (This may not have existed as a standalone library at the time you
> > started this port.)
> > 
> > > +
> > > +VOID
> > 
> > A lot of the functions in this file could do with a STATIC prefix,
> > since they are only used internally.
> > 
> > > +Wait4Busy (
> > 
> > Semantically, this name is incorrect.
> > The function is waiting _while_ the state is RTC_BUSY, so seems to me
> > it should be called WaitBusy.
> > 
> > > +  VOID
> > > +  )
> > > +{
> > > +  UINT32 Val, Retry = 1000;
> > > +  do {
> > > +    MicroSecondDelay (200);
> > 
> > Why 200?
> 
> It is just a suggested delay time according to RTC clock frequency. You want
> a RTC_WAIT_DELAY macro here for better understanding, right?

That would be more clear, yes.
It is also good if next to that definition there is some description
of how the value was detemined. (I.e., are we waiting for a particular
number of cycles, or is this simply a determined to be "good enough".)

/
    Leif


  reply	other threads:[~2017-08-17 15:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1502287959-16806-1-git-send-email-jun.nie@linaro.org>
2017-08-10 13:04 ` [PATCH 1/4] Platforms: Add Sanchip Zx296718 basic library Leif Lindholm
2017-08-10 14:16   ` Laszlo Ersek
     [not found]   ` <e3573cc7-875f-6b44-12dd-b76ec8c9272a@linaro.org>
2017-08-17 15:51     ` Leif Lindholm
     [not found] ` <1502287959-16806-3-git-send-email-jun.nie@linaro.org>
2017-08-10 14:41   ` [PATCH 3/4] Platforms/zx: Add boot manager lib and entries Leif Lindholm
2017-08-17 15:45     ` Jun Nie
2017-08-17 18:53       ` Leif Lindholm
     [not found] ` <1502287959-16806-4-git-send-email-jun.nie@linaro.org>
2017-08-10 15:00   ` [PATCH 4/4] Platforms/zx: Add platform build system files Leif Lindholm
2017-08-17 15:46     ` Jun Nie
     [not found] ` <1502287959-16806-2-git-send-email-jun.nie@linaro.org>
2017-08-10 14:03   ` [PATCH 2/4] Platforms: Add ZX RTC driver for Sanchip SoC Leif Lindholm
2017-08-17 15:43     ` Jun Nie
2017-08-17 15:55       ` Leif Lindholm [this message]
2017-08-10 15:15   ` Leif Lindholm

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-list 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=20170817155502.5rjnteaye6sq6m4y@bivouac.eciton.net \
    --to=devel@edk2.groups.io \
    /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