RealTimeClockLib instances are consumed by edk2's
EmbeddedPkg/RealTimeClockRuntimeDxe driver. In its entry point function
InitializeRealTimeClock(), the driver:

(1) calls LibRtcInitialize(),

(2) sets the GetTime(), SetTime(), GetWakeupTime() and SetWakeupTime()
    runtime services to its own similarly-named functions -- where those
    functions wrap the corresponding RealTimeClockLib APIs,

(3) installs EFI_REAL_TIME_CLOCK_ARCH_PROTOCOL with a NULL protocol
    interface.

Steps (2) and (3) conform to PI v1.8 sections II-9.7.2.4 through
II-9.7.2.7.

However, this means that LibRtcInitialize() (of any RealTimeClockLib
instance) should not itself (a) set the GetTime(), SetTime(),
GetWakeupTime() and SetWakeupTime() runtime services, nor (b) install
EFI_REAL_TIME_CLOCK_ARCH_PROTOCOL. The runtime service pointers will be
overwritten in step (2) anyway, and step (3) will uselessly install a
second (NULL-interface) EFI_REAL_TIME_CLOCK_ARCH_PROTOCOL instance in the
protocol database. (The protocol only serves to notify the DXE Foundation
about said runtime services being available.)

Clean up Hisilicon/RX8900RealTimeClockLib accordingly.

(Note that the lib instance INF file already does not list
UefiBootServicesTableLib, UefiRuntimeServicesTableLib, and
gEfiRealTimeClockArchProtocolGuid.)

Note that this patch is *untestable* in edk2-platforms (and in
edk2-non-osi too), because no platform consumes RX8900RealTimeClockLib --
worse, there hasn't been a single consumer since the introduction of the
lib instance in commit de704335c47f ("Silicon/Hisilicon: Add
RX8900RealTimeClockLib", 2020-05-20).

Normally this would nominate RX8900RealTimeClockLib to the axe, but commit
de704335c47f said, "There are some boards base on D06, but use RX8900 RTC,
so upstream the RX8900RealTimeClockLib", so I guess there might be
out-of-tree / proprietary consumers. Quite unfortunate.

Cc: Ard Biesheuvel <ardb+tianoc...@kernel.org>
Cc: Leif Lindholm <quic_llind...@quicinc.com>
Cc: Wenyi Xie <xiewen...@huawei.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4565
Signed-off-by: Laszlo Ersek <ler...@redhat.com>
---
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c | 24 
+++-----------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git 
a/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c 
b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
index ea41202fc72a..eaaf95a1979d 100644
--- a/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
+++ b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
@@ -15,11 +15,8 @@
 #include <Library/RtcHelperLib.h>
 #include <Library/TimeBaseLib.h>
 #include <Library/TimerLib.h>
-#include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiLib.h>
 #include <Library/UefiRuntimeLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Protocol/RealTimeClock.h>
 #include "RX8900RealTimeClock.h"
 
 extern I2C_DEVICE gRtcDevice;
@@ -417,16 +414,9 @@ LibRtcInitialize (
   )
 {
   EFI_STATUS    Status;
-  EFI_HANDLE    Handle;
   EFI_TIME      EfiTime;
 
-  // Setup the setters and getters
-  gRT->GetTime = LibGetTime;
-  gRT->SetTime = LibSetTime;
-  gRT->GetWakeupTime = LibGetWakeupTime;
-  gRT->SetWakeupTime = LibSetWakeupTime;
-
-  Status = gRT->GetTime (&EfiTime, NULL);
+  Status = LibGetTime (&EfiTime, NULL);
   if (EFI_ERROR (Status) || (EfiTime.Year < 2000) || (EfiTime.Year > 2099) ||
       (!IsTimeValid (&EfiTime))) {
        EfiTime.Year = 2000;
@@ -439,19 +429,11 @@ LibRtcInitialize (
        EfiTime.Daylight = 0;
        EfiTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
 
-      Status = gRT->SetTime (&EfiTime);
+      Status = LibSetTime (&EfiTime);
       if (EFI_ERROR (Status)) {
         DEBUG ((DEBUG_ERROR, "SetTime Status : %r\n", Status));
       }
   }
 
-  Handle = NULL;
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &Handle,
-                  &gEfiRealTimeClockArchProtocolGuid,
-                  NULL,
-                  NULL
-                 );
-
-  return Status;
+  return EFI_SUCCESS;
 }



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109843): https://edk2.groups.io/g/devel/message/109843
Mute This Topic: https://groups.io/mt/102079662/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: 
https://edk2.groups.io/g/devel/leave/9847357/21656/1706620634/xyzzy 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to