public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Wenyi Xie <xiewenyi2@huawei.com>
Subject: [edk2-devel] [edk2-platforms PATCH 1/7] Hisilicon/DS3231RealTimeClockLib: remove superfluous instance init steps
Date: Fri, 20 Oct 2023 14:18:57 +0200	[thread overview]
Message-ID: <20231020121903.44986-2-lersek@redhat.com> (raw)
In-Reply-To: <20231020121903.44986-1-lersek@redhat.com>

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/DS3231RealTimeClockLib accordingly.

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

Build-tested only (with the D03 and D05 platforms).

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Wenyi Xie <xiewenyi2@huawei.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4565
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 Platform/Hisilicon/D03/Library/DS3231RealTimeClockLib/DS3231RealTimeClockLib.c | 27 +++-----------------
 1 file changed, 3 insertions(+), 24 deletions(-)

diff --git a/Platform/Hisilicon/D03/Library/DS3231RealTimeClockLib/DS3231RealTimeClockLib.c b/Platform/Hisilicon/D03/Library/DS3231RealTimeClockLib/DS3231RealTimeClockLib.c
index 3a84b6e9297b..be143c47577b 100644
--- a/Platform/Hisilicon/D03/Library/DS3231RealTimeClockLib/DS3231RealTimeClockLib.c
+++ b/Platform/Hisilicon/D03/Library/DS3231RealTimeClockLib/DS3231RealTimeClockLib.c
@@ -25,11 +25,8 @@
 #include <Library/IoLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/PcdLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
 #include <Library/TimerLib.h>
 #include <Library/TimeBaseLib.h>
-#include <Protocol/RealTimeClock.h>
 #include <Library/I2CLib.h>
 #include "DS3231RealTimeClock.h"
 #include <Library/CpldD03.h>
@@ -433,19 +430,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;
-
-
-  (VOID)gRT->GetTime (&EfiTime, NULL);
+  (VOID)LibGetTime (&EfiTime, NULL);
   if((EfiTime.Year < 2015) || (EfiTime.Year > 2099)){
       EfiTime.Year          = 2015;
       EfiTime.Month         = 1;
@@ -454,20 +441,12 @@ LibRtcInitialize (
       EfiTime.Minute        = 0;
       EfiTime.Second        = 0;
       EfiTime.Nanosecond    = 0;
-      Status = gRT->SetTime(&EfiTime);
+      Status = LibSetTime(&EfiTime);
       if (EFI_ERROR(Status))
       {
         DEBUG((EFI_D_ERROR, "[%a]:[%dL] Status : %r\n", __FUNCTION__, __LINE__, Status));
       }
   }
 
-  // Install the protocol
-  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 (#109836): https://edk2.groups.io/g/devel/message/109836
Mute This Topic: https://groups.io/mt/102079654/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2023-10-20 12:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20 12:18 [edk2-devel] [edk2-platforms PATCH 0/7] drop needless init steps in RealTimeClockLib instances Laszlo Ersek
2023-10-20 12:18 ` Laszlo Ersek [this message]
2023-10-20 12:18 ` [edk2-devel] [edk2-platforms PATCH 2/7] LoongArchQemuPkg/LsRealTimeClockLib: remove superfluous instance init steps Laszlo Ersek
2023-10-23  6:52   ` Chao Li
2023-10-20 12:18 ` [edk2-devel] [edk2-platforms PATCH 3/7] Hisilicon/M41T83RealTimeClockLib: " Laszlo Ersek
2023-10-20 12:19 ` [edk2-devel] [edk2-platforms PATCH 4/7] Hisilicon/RX8900RealTimeClockLib: " Laszlo Ersek
2023-10-20 12:19 ` [edk2-devel] [edk2-platforms PATCH 5/7] Silicon/Marvell/RealTimeClockLib: " Laszlo Ersek
2023-10-20 12:19 ` [edk2-devel] [edk2-platforms PATCH 6/7] FT2000-4Pkg/RealTimeClockLib: " Laszlo Ersek
2023-10-20 12:19 ` [edk2-devel] [edk2-platforms PATCH 7/7] Omap35xxPkg/RealTimeClockLib: " Laszlo Ersek
2023-10-20 12:26 ` [edk2-devel] [edk2-platforms PATCH 0/7] drop needless init steps in RealTimeClockLib instances Ard Biesheuvel
2023-10-24 13:20 ` Laszlo Ersek

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=20231020121903.44986-2-lersek@redhat.com \
    --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