diff mbox series

[edk2,3/3] ArmPlatformPkg, ArmVirtPkg: delete redundant PL031 functions

Message ID 20170503213812.5971-4-leif.lindholm@linaro.org
State Accepted
Commit af5fed90bfbf27dc1acafbd69b98f4968a97ef3a
Headers show
Series Import a few items from OpenPlatformPkg | expand

Commit Message

Leif Lindholm May 3, 2017, 9:38 p.m. UTC
Remove the functions now provided by EfiTimeBaseLib from
PL031RealTimeClockLib. Add EfiTimeBaseLib resolution to ArmVirtPkg
in same commit to prevent breakage.

Cc: Laszlo Ersek <lersek@redhat.com>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>

---
 .../Include/Drivers/PL031RealTimeClock.h           |  11 --
 .../PL031RealTimeClockLib/PL031RealTimeClockLib.c  | 127 +--------------------
 .../PL031RealTimeClockLib.inf                      |   1 +
 ArmVirtPkg/ArmVirt.dsc.inc                         |   1 +
 4 files changed, 5 insertions(+), 135 deletions(-)

-- 
2.11.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Ard Biesheuvel May 4, 2017, 6:10 p.m. UTC | #1
On 3 May 2017 at 22:38, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> Remove the functions now provided by EfiTimeBaseLib from

> PL031RealTimeClockLib. Add EfiTimeBaseLib resolution to ArmVirtPkg

> in same commit to prevent breakage.

>

> Cc: Laszlo Ersek <lersek@redhat.com>

>

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>


I'd rather you'd call it something that doesn't start with 'Efi' given
that we usually reserve that for protocols and other prototypes that
are defined by the UEFI spec.

Other than that, this series looks fine to me

Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


> ---

>  .../Include/Drivers/PL031RealTimeClock.h           |  11 --

>  .../PL031RealTimeClockLib/PL031RealTimeClockLib.c  | 127 +--------------------

>  .../PL031RealTimeClockLib.inf                      |   1 +

>  ArmVirtPkg/ArmVirt.dsc.inc                         |   1 +

>  4 files changed, 5 insertions(+), 135 deletions(-)

>

> diff --git a/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h b/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h

> index 76fbd0eb82..812cd9b397 100644

> --- a/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h

> +++ b/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h

> @@ -42,15 +42,4 @@

>

>  #define PL031_COUNTS_PER_SECOND                         1

>

> -// Define EPOCH (1970-JANUARY-01) in the Julian Date representation

> -#define EPOCH_JULIAN_DATE                               2440588

> -

> -// Seconds per unit

> -#define SEC_PER_MIN                                     ((UINTN)    60)

> -#define SEC_PER_HOUR                                    ((UINTN)  3600)

> -#define SEC_PER_DAY                                     ((UINTN) 86400)

> -

> -#define SEC_PER_MONTH                                   ((UINTN)  2,592,000)

> -#define SEC_PER_YEAR                                    ((UINTN) 31,536,000)

> -

>  #endif

> diff --git a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c

> index 4aa448b528..9f115d383c 100644

> --- a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c

> +++ b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c

> @@ -36,6 +36,8 @@

>

>  #include <Drivers/PL031RealTimeClock.h>

>

> +#include <Library/EfiTimeBaseLib.h>

> +

>  #include <ArmPlatform.h>

>

>  STATIC CONST CHAR16           mTimeZoneVariableName[] = L"PL031RtcTimeZone";

> @@ -110,129 +112,6 @@ InitializePL031 (

>  }

>

>  /**

> -  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME

> - **/

> -VOID

> -EpochToEfiTime (

> -  IN  UINTN     EpochSeconds,

> -  OUT EFI_TIME  *Time

> -  )

> -{

> -  UINTN         a;

> -  UINTN         b;

> -  UINTN         c;

> -  UINTN         d;

> -  UINTN         g;

> -  UINTN         j;

> -  UINTN         m;

> -  UINTN         y;

> -  UINTN         da;

> -  UINTN         db;

> -  UINTN         dc;

> -  UINTN         dg;

> -  UINTN         hh;

> -  UINTN         mm;

> -  UINTN         ss;

> -  UINTN         J;

> -

> -  J  = (EpochSeconds / 86400) + 2440588;

> -  j  = J + 32044;

> -  g  = j / 146097;

> -  dg = j % 146097;

> -  c  = (((dg / 36524) + 1) * 3) / 4;

> -  dc = dg - (c * 36524);

> -  b  = dc / 1461;

> -  db = dc % 1461;

> -  a  = (((db / 365) + 1) * 3) / 4;

> -  da = db - (a * 365);

> -  y  = (g * 400) + (c * 100) + (b * 4) + a;

> -  m  = (((da * 5) + 308) / 153) - 2;

> -  d  = da - (((m + 4) * 153) / 5) + 122;

> -

> -  Time->Year  = y - 4800 + ((m + 2) / 12);

> -  Time->Month = ((m + 2) % 12) + 1;

> -  Time->Day   = d + 1;

> -

> -  ss = EpochSeconds % 60;

> -  a  = (EpochSeconds - ss) / 60;

> -  mm = a % 60;

> -  b = (a - mm) / 60;

> -  hh = b % 24;

> -

> -  Time->Hour        = hh;

> -  Time->Minute      = mm;

> -  Time->Second      = ss;

> -  Time->Nanosecond  = 0;

> -

> -}

> -

> -/**

> -  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)

> - **/

> -UINTN

> -EfiTimeToEpoch (

> -  IN  EFI_TIME  *Time

> -  )

> -{

> -  UINTN a;

> -  UINTN y;

> -  UINTN m;

> -  UINTN JulianDate;  // Absolute Julian Date representation of the supplied Time

> -  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY

> -  UINTN EpochSeconds;

> -

> -  a = (14 - Time->Month) / 12 ;

> -  y = Time->Year + 4800 - a;

> -  m = Time->Month + (12*a) - 3;

> -

> -  JulianDate = Time->Day + ((153*m + 2)/5) + (365*y) + (y/4) - (y/100) + (y/400) - 32045;

> -

> -  ASSERT (JulianDate >= EPOCH_JULIAN_DATE);

> -  EpochDays = JulianDate - EPOCH_JULIAN_DATE;

> -

> -  EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;

> -

> -  return EpochSeconds;

> -}

> -

> -BOOLEAN

> -IsLeapYear (

> -  IN EFI_TIME   *Time

> -  )

> -{

> -  if (Time->Year % 4 == 0) {

> -    if (Time->Year % 100 == 0) {

> -      if (Time->Year % 400 == 0) {

> -        return TRUE;

> -      } else {

> -        return FALSE;

> -      }

> -    } else {

> -      return TRUE;

> -    }

> -  } else {

> -    return FALSE;

> -  }

> -}

> -

> -BOOLEAN

> -DayValid (

> -  IN  EFI_TIME  *Time

> -  )

> -{

> -  STATIC CONST INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

> -

> -  if (Time->Day < 1 ||

> -      Time->Day > DayOfMonth[Time->Month - 1] ||

> -      (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))

> -     ) {

> -    return FALSE;

> -  }

> -

> -  return TRUE;

> -}

> -

> -/**

>    Returns the current time and date information, and the time-keeping capabilities

>    of the hardware platform.

>

> @@ -431,7 +310,7 @@ LibSetTime (

>         (Time->Year   > 9999) ||

>         (Time->Month  < 1   ) ||

>         (Time->Month  > 12  ) ||

> -       (!DayValid (Time)    ) ||

> +       (!IsDayValid (Time) ) ||

>         (Time->Hour   > 23  ) ||

>         (Time->Minute > 59  ) ||

>         (Time->Second > 59  ) ||

> diff --git a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> index 3a98fc757e..41a4e6d6bd 100644

> --- a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> +++ b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> @@ -36,6 +36,7 @@

>    PcdLib

>    ArmPlatformSysConfigLib

>    DxeServicesTableLib

> +  EfiTimeBaseLib

>    UefiRuntimeLib

>

>  [Guids]

> diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc

> index e74eaf16e7..bc96709d8a 100644

> --- a/ArmVirtPkg/ArmVirt.dsc.inc

> +++ b/ArmVirtPkg/ArmVirt.dsc.inc

> @@ -105,6 +105,7 @@

>

>    # ARM PL031 RTC Driver

>    RealTimeClockLib|ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> +  EfiTimeBaseLib|EmbeddedPkg/Library/EfiTimeBaseLib/EfiTimeBaseLib.inf

>    # ARM PL011 UART Driver

>    PL011UartLib|ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf

>    SerialPortLib|ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf

> --

> 2.11.0

>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Leif Lindholm May 10, 2017, 4:02 p.m. UTC | #2
On Thu, May 04, 2017 at 07:10:40PM +0100, Ard Biesheuvel wrote:
> On 3 May 2017 at 22:38, Leif Lindholm <leif.lindholm@linaro.org> wrote:

> > Remove the functions now provided by EfiTimeBaseLib from

> > PL031RealTimeClockLib. Add EfiTimeBaseLib resolution to ArmVirtPkg

> > in same commit to prevent breakage.

> >

> > Cc: Laszlo Ersek <lersek@redhat.com>

> >

> > Contributed-under: TianoCore Contribution Agreement 1.0

> > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>

> 

> I'd rather you'd call it something that doesn't start with 'Efi' given

> that we usually reserve that for protocols and other prototypes that

> are defined by the UEFI spec.


Yes, good call.

> Other than that, this series looks fine to me

> 

> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Thanks!
Pushed as d547b32..af5fed9

Required resulting updates for edk2-platforms/devel-OpenPlatformPkg
pushed as 43540a5.

/
    Leif

> > ---

> >  .../Include/Drivers/PL031RealTimeClock.h           |  11 --

> >  .../PL031RealTimeClockLib/PL031RealTimeClockLib.c  | 127 +--------------------

> >  .../PL031RealTimeClockLib.inf                      |   1 +

> >  ArmVirtPkg/ArmVirt.dsc.inc                         |   1 +

> >  4 files changed, 5 insertions(+), 135 deletions(-)

> >

> > diff --git a/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h b/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h

> > index 76fbd0eb82..812cd9b397 100644

> > --- a/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h

> > +++ b/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h

> > @@ -42,15 +42,4 @@

> >

> >  #define PL031_COUNTS_PER_SECOND                         1

> >

> > -// Define EPOCH (1970-JANUARY-01) in the Julian Date representation

> > -#define EPOCH_JULIAN_DATE                               2440588

> > -

> > -// Seconds per unit

> > -#define SEC_PER_MIN                                     ((UINTN)    60)

> > -#define SEC_PER_HOUR                                    ((UINTN)  3600)

> > -#define SEC_PER_DAY                                     ((UINTN) 86400)

> > -

> > -#define SEC_PER_MONTH                                   ((UINTN)  2,592,000)

> > -#define SEC_PER_YEAR                                    ((UINTN) 31,536,000)

> > -

> >  #endif

> > diff --git a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c

> > index 4aa448b528..9f115d383c 100644

> > --- a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c

> > +++ b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c

> > @@ -36,6 +36,8 @@

> >

> >  #include <Drivers/PL031RealTimeClock.h>

> >

> > +#include <Library/EfiTimeBaseLib.h>

> > +

> >  #include <ArmPlatform.h>

> >

> >  STATIC CONST CHAR16           mTimeZoneVariableName[] = L"PL031RtcTimeZone";

> > @@ -110,129 +112,6 @@ InitializePL031 (

> >  }

> >

> >  /**

> > -  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME

> > - **/

> > -VOID

> > -EpochToEfiTime (

> > -  IN  UINTN     EpochSeconds,

> > -  OUT EFI_TIME  *Time

> > -  )

> > -{

> > -  UINTN         a;

> > -  UINTN         b;

> > -  UINTN         c;

> > -  UINTN         d;

> > -  UINTN         g;

> > -  UINTN         j;

> > -  UINTN         m;

> > -  UINTN         y;

> > -  UINTN         da;

> > -  UINTN         db;

> > -  UINTN         dc;

> > -  UINTN         dg;

> > -  UINTN         hh;

> > -  UINTN         mm;

> > -  UINTN         ss;

> > -  UINTN         J;

> > -

> > -  J  = (EpochSeconds / 86400) + 2440588;

> > -  j  = J + 32044;

> > -  g  = j / 146097;

> > -  dg = j % 146097;

> > -  c  = (((dg / 36524) + 1) * 3) / 4;

> > -  dc = dg - (c * 36524);

> > -  b  = dc / 1461;

> > -  db = dc % 1461;

> > -  a  = (((db / 365) + 1) * 3) / 4;

> > -  da = db - (a * 365);

> > -  y  = (g * 400) + (c * 100) + (b * 4) + a;

> > -  m  = (((da * 5) + 308) / 153) - 2;

> > -  d  = da - (((m + 4) * 153) / 5) + 122;

> > -

> > -  Time->Year  = y - 4800 + ((m + 2) / 12);

> > -  Time->Month = ((m + 2) % 12) + 1;

> > -  Time->Day   = d + 1;

> > -

> > -  ss = EpochSeconds % 60;

> > -  a  = (EpochSeconds - ss) / 60;

> > -  mm = a % 60;

> > -  b = (a - mm) / 60;

> > -  hh = b % 24;

> > -

> > -  Time->Hour        = hh;

> > -  Time->Minute      = mm;

> > -  Time->Second      = ss;

> > -  Time->Nanosecond  = 0;

> > -

> > -}

> > -

> > -/**

> > -  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)

> > - **/

> > -UINTN

> > -EfiTimeToEpoch (

> > -  IN  EFI_TIME  *Time

> > -  )

> > -{

> > -  UINTN a;

> > -  UINTN y;

> > -  UINTN m;

> > -  UINTN JulianDate;  // Absolute Julian Date representation of the supplied Time

> > -  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY

> > -  UINTN EpochSeconds;

> > -

> > -  a = (14 - Time->Month) / 12 ;

> > -  y = Time->Year + 4800 - a;

> > -  m = Time->Month + (12*a) - 3;

> > -

> > -  JulianDate = Time->Day + ((153*m + 2)/5) + (365*y) + (y/4) - (y/100) + (y/400) - 32045;

> > -

> > -  ASSERT (JulianDate >= EPOCH_JULIAN_DATE);

> > -  EpochDays = JulianDate - EPOCH_JULIAN_DATE;

> > -

> > -  EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;

> > -

> > -  return EpochSeconds;

> > -}

> > -

> > -BOOLEAN

> > -IsLeapYear (

> > -  IN EFI_TIME   *Time

> > -  )

> > -{

> > -  if (Time->Year % 4 == 0) {

> > -    if (Time->Year % 100 == 0) {

> > -      if (Time->Year % 400 == 0) {

> > -        return TRUE;

> > -      } else {

> > -        return FALSE;

> > -      }

> > -    } else {

> > -      return TRUE;

> > -    }

> > -  } else {

> > -    return FALSE;

> > -  }

> > -}

> > -

> > -BOOLEAN

> > -DayValid (

> > -  IN  EFI_TIME  *Time

> > -  )

> > -{

> > -  STATIC CONST INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

> > -

> > -  if (Time->Day < 1 ||

> > -      Time->Day > DayOfMonth[Time->Month - 1] ||

> > -      (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))

> > -     ) {

> > -    return FALSE;

> > -  }

> > -

> > -  return TRUE;

> > -}

> > -

> > -/**

> >    Returns the current time and date information, and the time-keeping capabilities

> >    of the hardware platform.

> >

> > @@ -431,7 +310,7 @@ LibSetTime (

> >         (Time->Year   > 9999) ||

> >         (Time->Month  < 1   ) ||

> >         (Time->Month  > 12  ) ||

> > -       (!DayValid (Time)    ) ||

> > +       (!IsDayValid (Time) ) ||

> >         (Time->Hour   > 23  ) ||

> >         (Time->Minute > 59  ) ||

> >         (Time->Second > 59  ) ||

> > diff --git a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> > index 3a98fc757e..41a4e6d6bd 100644

> > --- a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> > +++ b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> > @@ -36,6 +36,7 @@

> >    PcdLib

> >    ArmPlatformSysConfigLib

> >    DxeServicesTableLib

> > +  EfiTimeBaseLib

> >    UefiRuntimeLib

> >

> >  [Guids]

> > diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc

> > index e74eaf16e7..bc96709d8a 100644

> > --- a/ArmVirtPkg/ArmVirt.dsc.inc

> > +++ b/ArmVirtPkg/ArmVirt.dsc.inc

> > @@ -105,6 +105,7 @@

> >

> >    # ARM PL031 RTC Driver

> >    RealTimeClockLib|ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

> > +  EfiTimeBaseLib|EmbeddedPkg/Library/EfiTimeBaseLib/EfiTimeBaseLib.inf

> >    # ARM PL011 UART Driver

> >    PL011UartLib|ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf

> >    SerialPortLib|ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf

> > --

> > 2.11.0

> >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h b/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h
index 76fbd0eb82..812cd9b397 100644
--- a/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h
+++ b/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h
@@ -42,15 +42,4 @@ 
 
 #define PL031_COUNTS_PER_SECOND                         1
 
-// Define EPOCH (1970-JANUARY-01) in the Julian Date representation
-#define EPOCH_JULIAN_DATE                               2440588
-
-// Seconds per unit
-#define SEC_PER_MIN                                     ((UINTN)    60)
-#define SEC_PER_HOUR                                    ((UINTN)  3600)
-#define SEC_PER_DAY                                     ((UINTN) 86400)
-
-#define SEC_PER_MONTH                                   ((UINTN)  2,592,000)
-#define SEC_PER_YEAR                                    ((UINTN) 31,536,000)
-
 #endif
diff --git a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c
index 4aa448b528..9f115d383c 100644
--- a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c
+++ b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c
@@ -36,6 +36,8 @@ 
 
 #include <Drivers/PL031RealTimeClock.h>
 
+#include <Library/EfiTimeBaseLib.h>
+
 #include <ArmPlatform.h>
 
 STATIC CONST CHAR16           mTimeZoneVariableName[] = L"PL031RtcTimeZone";
@@ -110,129 +112,6 @@  InitializePL031 (
 }
 
 /**
-  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME
- **/
-VOID
-EpochToEfiTime (
-  IN  UINTN     EpochSeconds,
-  OUT EFI_TIME  *Time
-  )
-{
-  UINTN         a;
-  UINTN         b;
-  UINTN         c;
-  UINTN         d;
-  UINTN         g;
-  UINTN         j;
-  UINTN         m;
-  UINTN         y;
-  UINTN         da;
-  UINTN         db;
-  UINTN         dc;
-  UINTN         dg;
-  UINTN         hh;
-  UINTN         mm;
-  UINTN         ss;
-  UINTN         J;
-
-  J  = (EpochSeconds / 86400) + 2440588;
-  j  = J + 32044;
-  g  = j / 146097;
-  dg = j % 146097;
-  c  = (((dg / 36524) + 1) * 3) / 4;
-  dc = dg - (c * 36524);
-  b  = dc / 1461;
-  db = dc % 1461;
-  a  = (((db / 365) + 1) * 3) / 4;
-  da = db - (a * 365);
-  y  = (g * 400) + (c * 100) + (b * 4) + a;
-  m  = (((da * 5) + 308) / 153) - 2;
-  d  = da - (((m + 4) * 153) / 5) + 122;
-
-  Time->Year  = y - 4800 + ((m + 2) / 12);
-  Time->Month = ((m + 2) % 12) + 1;
-  Time->Day   = d + 1;
-
-  ss = EpochSeconds % 60;
-  a  = (EpochSeconds - ss) / 60;
-  mm = a % 60;
-  b = (a - mm) / 60;
-  hh = b % 24;
-
-  Time->Hour        = hh;
-  Time->Minute      = mm;
-  Time->Second      = ss;
-  Time->Nanosecond  = 0;
-
-}
-
-/**
-  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
- **/
-UINTN
-EfiTimeToEpoch (
-  IN  EFI_TIME  *Time
-  )
-{
-  UINTN a;
-  UINTN y;
-  UINTN m;
-  UINTN JulianDate;  // Absolute Julian Date representation of the supplied Time
-  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY
-  UINTN EpochSeconds;
-
-  a = (14 - Time->Month) / 12 ;
-  y = Time->Year + 4800 - a;
-  m = Time->Month + (12*a) - 3;
-
-  JulianDate = Time->Day + ((153*m + 2)/5) + (365*y) + (y/4) - (y/100) + (y/400) - 32045;
-
-  ASSERT (JulianDate >= EPOCH_JULIAN_DATE);
-  EpochDays = JulianDate - EPOCH_JULIAN_DATE;
-
-  EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;
-
-  return EpochSeconds;
-}
-
-BOOLEAN
-IsLeapYear (
-  IN EFI_TIME   *Time
-  )
-{
-  if (Time->Year % 4 == 0) {
-    if (Time->Year % 100 == 0) {
-      if (Time->Year % 400 == 0) {
-        return TRUE;
-      } else {
-        return FALSE;
-      }
-    } else {
-      return TRUE;
-    }
-  } else {
-    return FALSE;
-  }
-}
-
-BOOLEAN
-DayValid (
-  IN  EFI_TIME  *Time
-  )
-{
-  STATIC CONST INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-
-  if (Time->Day < 1 ||
-      Time->Day > DayOfMonth[Time->Month - 1] ||
-      (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
-     ) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-/**
   Returns the current time and date information, and the time-keeping capabilities
   of the hardware platform.
 
@@ -431,7 +310,7 @@  LibSetTime (
        (Time->Year   > 9999) ||
        (Time->Month  < 1   ) ||
        (Time->Month  > 12  ) ||
-       (!DayValid (Time)    ) ||
+       (!IsDayValid (Time) ) ||
        (Time->Hour   > 23  ) ||
        (Time->Minute > 59  ) ||
        (Time->Second > 59  ) ||
diff --git a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
index 3a98fc757e..41a4e6d6bd 100644
--- a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
+++ b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
@@ -36,6 +36,7 @@ 
   PcdLib
   ArmPlatformSysConfigLib
   DxeServicesTableLib
+  EfiTimeBaseLib
   UefiRuntimeLib
 
 [Guids]
diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index e74eaf16e7..bc96709d8a 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -105,6 +105,7 @@ 
 
   # ARM PL031 RTC Driver
   RealTimeClockLib|ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
+  EfiTimeBaseLib|EmbeddedPkg/Library/EfiTimeBaseLib/EfiTimeBaseLib.inf
   # ARM PL011 UART Driver
   PL011UartLib|ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf
   SerialPortLib|ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf