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 Silicon/Marvell/RealTimeClockLib accordingly (it only has code
that's redundant for step (3); it does not try to set "gRT" fields).

(Note that the lib instance INF file already does not list
gEfiRealTimeClockArchProtocolGuid.)

Build-tested only (with "Armada70x0Db.dsc").

Cc: Leif Lindholm <quic_llind...@quicinc.com>
Cc: Marcin Wojtas <m...@semihalf.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4565
Signed-off-by: Laszlo Ersek <ler...@redhat.com>
---

Notes:
    context:-W

 Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c | 19 
+------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git 
a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c 
b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c
index d538b030b111..c026ac2dee31 100644
--- a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c
+++ b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c
@@ -1,30 +1,29 @@
 /** @file
   Implement EFI RealTimeClock runtime services via RTC Lib.
 
   Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
   Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
   Copyright (c) 2017, Marvell International Ltd. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 /**
   Derived from:
   ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c
 
 **/
 
 #include <PiDxe.h>
 #include <Library/BaseLib.h>
 #include <Library/DebugLib.h>
 #include <Library/DxeServicesTableLib.h>
 #include <Library/TimeBaseLib.h>
 #include <Library/IoLib.h>
 #include <Library/RealTimeClockLib.h>
 #include <Library/TimerLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiRuntimeLib.h>
-#include <Protocol/RealTimeClock.h>
 #include "RealTimeClockLib.h"
 
 STATIC EFI_EVENT              mRtcVirtualAddrChangeEvent;
@@ -245,85 +244,69 @@ EFIAPI
 LibRtcInitialize (
   IN EFI_HANDLE                            ImageHandle,
   IN EFI_SYSTEM_TABLE                      *SystemTable
   )
 {
-  EFI_HANDLE    Handle;
   EFI_STATUS    Status;
 
   // Obtain RTC device base address
   mArmadaRtcBase = PcdGet64 (PcdRtcBaseAddress);
 
   // Check if the controller can be initialized
   if (mArmadaRtcBase == 0) {
     DEBUG ((DEBUG_ERROR, "RTC: None of controllers enabled\n"));
     return EFI_INVALID_PARAMETER;
   }
 
   // Declare the controller as EFI_MEMORY_RUNTIME
   Status = gDS->AddMemorySpace (
                   EfiGcdMemoryTypeMemoryMappedIo,
                   mArmadaRtcBase,
                   SIZE_4KB,
                   EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
                   );
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "RTC: Failed to add memory space\n"));
     return Status;
   }
 
   Status = gDS->SetMemorySpaceAttributes (
                   mArmadaRtcBase,
                   SIZE_4KB,
                   EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
                   );
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "RTC: Failed to set memory attributes\n"));
     goto ErrSetMem;
   }
 
   /* Update RTC-MBUS bridge timing parameters */
   MmioAndThenOr32 (
           mArmadaRtcBase + RTC_BRIDGE_TIMING_CTRL0_REG_OFFS,
           ~(RTC_WRITE_SETUP_DELAY_MASK | RTC_WRITE_PERIOD_DELAY_MASK),
           (RTC_WRITE_SETUP_DELAY_DEFAULT | RTC_WRITE_PERIOD_DELAY_DEFAULT)
           );
   MmioAndThenOr32 (
           mArmadaRtcBase + RTC_BRIDGE_TIMING_CTRL1_REG_OFFS,
           ~RTC_READ_OUTPUT_DELAY_MASK,
           RTC_READ_OUTPUT_DELAY_DEFAULT
           );
 
-  // Install the protocol
-  Handle = NULL;
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &Handle,
-                  &gEfiRealTimeClockArchProtocolGuid,
-                  NULL,
-                  NULL
-                 );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((DEBUG_ERROR, "RTC: Failed to install the protocol\n"));
-    goto ErrSetMem;
-  }
-
   // Register for the virtual address change event
   Status = gBS->CreateEventEx (
                   EVT_NOTIFY_SIGNAL,
                   TPL_NOTIFY,
                   VirtualNotifyEvent,
                   NULL,
                   &gEfiEventVirtualAddressChangeGuid,
                   &mRtcVirtualAddrChangeEvent
                   );
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "RTC: Failed to register virtual address change 
event\n"));
-    goto ErrEvent;
+    goto ErrSetMem;
   }
 
   return Status;
 
-ErrEvent:
-  gBS->UninstallProtocolInterface (Handle, &gEfiRealTimeClockArchProtocolGuid, 
NULL);
 ErrSetMem:
   gDS->RemoveMemorySpace (mArmadaRtcBase, SIZE_4KB);
 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109839): https://edk2.groups.io/g/devel/message/109839
Mute This Topic: https://groups.io/mt/102079658/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