From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 8A3D8D811CA for ; Fri, 12 Jan 2024 11:45:02 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=6FMHgPNst30ftMWvhLccp7hEx9vwOgc/8Hso3HX586E=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1705059901; v=1; b=WqFOoccFaslDwe9jTwPxvt4bfHakBaWQ/svLQNARIc5wpDn/Eu1DZBNUZ5QFuqNWIQgb4mAt 7nUI40TU3henAr+C4WbrKIYv9hwNTI+YNPHHpJ6q/ivtCkU+xyAhW+rwXPv+2THlY5whRnF+jig 2za2ujqFjOxylRgIfNrC7tfM= X-Received: by 127.0.0.2 with SMTP id jGclYY7687511x8W8SwOp1Fw; Fri, 12 Jan 2024 03:45:01 -0800 X-Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by mx.groups.io with SMTP id smtpd.web11.5265.1705059900642479512 for ; Fri, 12 Jan 2024 03:45:00 -0800 X-Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5989407dd3cso1167404eaf.0 for ; Fri, 12 Jan 2024 03:45:00 -0800 (PST) X-Gm-Message-State: 6Kqj3MKuVCYOjcDtgiHat6Xpx7686176AA= X-Google-Smtp-Source: AGHT+IGNJEBQqmmPF9jK9xBkvX7+ODO4DkYpfjGf8tY3bn9Dyg777FPZZj3yAlWORBhGXWLpnyVAL2iGDZDPBNRD74E= X-Received: by 2002:a4a:a983:0:b0:598:9a54:3f32 with SMTP id w3-20020a4aa983000000b005989a543f32mr556814oom.3.1705059899791; Fri, 12 Jan 2024 03:44:59 -0800 (PST) MIME-Version: 1.0 References: <20231221005427.13932-1-ndhillon@marvell.com> <20231221005427.13932-6-ndhillon@marvell.com> In-Reply-To: <20231221005427.13932-6-ndhillon@marvell.com> From: "Marcin Wojtas via groups.io" Date: Fri, 12 Jan 2024 12:44:49 +0100 Message-ID: Subject: Re: [edk2-devel] [edk2-platforms PATCH v2 5/8] Silicon/Marvell: RTC driver To: devel@edk2.groups.io, ndhillon@marvell.com Cc: quic_llindhol@quicinc.com, marcin.s.wojtas@gmail.com, sbalcerak@marvell.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mw@semihalf.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=WqFOoccF; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none +marcin.s.wojtas@gmail.com Hi Narinder, czw., 21 gru 2023 o 01:54 Narinder Dhillon napisa=C5= =82(a): > > From: Narinder Dhillon > > Marvell Odyssey SoC does not have RTC on chip. This patch provides a > dummy RTC driver to generate architectural protocol and help boot > Odyssey SoC. > > Signed-off-by: Narinder Dhillon > --- > .../Marvell/Drivers/Null/RtcNull/RtcNullDxe.c | 280 ++++++++++++++++++ > .../Marvell/Drivers/Null/RtcNull/RtcNullDxe.h | 37 +++ > .../Drivers/Null/RtcNull/RtcNullDxe.inf | 46 +++ Instead of the custom Null driver you should use the generic solution - it should be enough to add EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf { RealTimeClockLib|EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualR= ealTimeClockLib.inf in the .dsc file, and INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf in the .fdf file, to achieve the same result. Best regards, Marcin Best regards, Marcin > 3 files changed, 363 insertions(+) > create mode 100644 Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.c > create mode 100644 Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.h > create mode 100644 Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.inf > > diff --git a/Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.c b/Silicon/= Marvell/Drivers/Null/RtcNull/RtcNullDxe.c > new file mode 100644 > index 0000000000..8a7956f35d > --- /dev/null > +++ b/Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.c > @@ -0,0 +1,280 @@ > +/** @file > +* > +* SPDX-License-Identifier: BSD-2-Clause-Patent > +* https://spdx.org/licenses > +* > +* Copyright (C) 2022 Marvell > +* > +* Source file for NULL RTC Driver > +* > +**/ > + > +#include // Base defines > +#include // DEBUG > +#include // AllocateRuntimeZero= Pool > +#include // ZeroMem > +#include // gBS > +#include // EfiConvertPointer > +#include // gRT > + > +#include "RtcNullDxe.h" > + > +// all variables used across the driver > +RTC_NULL_PRIVATE_DATA *mRtcPrivateData; > +STATIC EFI_EVENT mRtcVirtualAddressChangeEvent; > + > +STATIC CONST INTN DayOfMonth[12] =3D > + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31= , 30, 31 }; > + > +STATIC > +BOOLEAN > +IsLeapYear(IN EFI_TIME *Time) > +{ > + if (Time->Year % 4 =3D=3D 0) { > + if (Time->Year % 100 =3D=3D 0) { > + if (Time->Year % 400 =3D=3D 0) { > + return TRUE; > + } else { > + return FALSE; > + } > + } else { > + return TRUE; > + } > + } else { > + return FALSE; > + } > +} > + > +BOOLEAN DayValid(IN EFI_TIME *Time) > +{ > + if (Time->Day < 1 || > + Time->Day > DayOfMonth[Time->Month - 1] || > + (Time->Month =3D=3D 2 && (!IsLeapYear (Time) && Time->Day > 28))) { > + return FALSE; > + } > + > + return TRUE; > +} > + > +EFI_STATUS > +GetDateTime( > + IN RTC_NULL_PRIVATE_DATA *PrivateData, > + OUT EFI_TIME *Time) > +{ > + > + if (PrivateData =3D=3D NULL || Time =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + ZeroMem(Time, sizeof(EFI_TIME)); > + > + return EFI_SUCCESS; > +} > + > +EFI_STATUS > +SetDateTime(IN RTC_NULL_PRIVATE_DATA *PrivateData, > + IN EFI_TIME *Time) > +{ > + if (PrivateData =3D=3D NULL || Time =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if ( (Time->Month < 1) || (Time->Month > 12) || > + (Time->Second > 59) || (Time->Minute > 59) || > + (Time->Hour > 23) || (!DayValid(Time)) || > + (Time->Year < 1998) || (Time->Year > 2099) || > + (Time->Nanosecond > 999999999) || > + (Time->TimeZone < -1440) || ((Time->TimeZone > 1440) && > + (Time->TimeZone !=3D 2047))) { > + return EFI_INVALID_PARAMETER; > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Returns the current time and date information, and the time-keeping ca= pabilities > + of the hardware platform. > + > + @param Time A pointer to storage to receive a snapsh= ot of the current time. > + @param Capabilities An optional pointer to a buffer to recei= ve the real time clock > + device's capabilities. > + > + @retval EFI_SUCCESS The operation completed successfully. > + @retval EFI_INVALID_PARAMETER Time is NULL. > + @retval EFI_DEVICE_ERROR The time could not be retrieved due to h= ardware error. > + > +**/ > +EFI_STATUS > + EFIAPI > +GetTime(OUT EFI_TIME * Time, OUT EFI_TIME_CAPABILITIES * Capabilities) > +{ > + if (Time =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (mRtcPrivateData->Initialized =3D=3D FALSE) { > + return EFI_UNSUPPORTED; > + } > + > + return GetDateTime (mRtcPrivateData, Time); > +} > + > + > + > +/** > + Sets the current local time and date information. > + > + @param Time A pointer to the current time. > + > + @retval EFI_SUCCESS The operation completed successfully. > + @retval EFI_INVALID_PARAMETER A time field is out of range. > + @retval EFI_DEVICE_ERROR The time could not be set due due to har= dware error. > + > +**/ > +EFI_STATUS EFIAPI SetTime(IN EFI_TIME * Time) > +{ > + if (Time =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (mRtcPrivateData->Initialized =3D=3D FALSE) { > + return EFI_UNSUPPORTED; > + } > + > + return SetDateTime (mRtcPrivateData, Time); > +} > + > + > +/** > + Returns the current wakeup alarm clock setting. > + > + @param Enabled Indicates if the alarm is currently enab= led or disabled. > + @param Pending Indicates if the alarm signal is pending= and requires acknowledgement. > + @param Time The current alarm setting. > + > + @retval EFI_SUCCESS The alarm settings were returned. > + @retval EFI_INVALID_PARAMETER Any parameter is NULL. > + @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved d= ue to a hardware error. > + > +**/ > +EFI_STATUS > + EFIAPI > +GetWakeupTime(OUT BOOLEAN * Enabled, > + OUT BOOLEAN * Pending, OUT EFI_TIME * Time) > +{ > + return EFI_UNSUPPORTED; > +} > + > + > +/** > + Sets the system wakeup alarm clock time. > + > + @param Enabled Enable or disable the wakeup alarm. > + @param Time If Enable is TRUE, the time to set the w= akeup alarm for. > + > + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm= was enabled. If > + Enable is FALSE, then the wakeup alarm w= as disabled. > + @retval EFI_INVALID_PARAMETER A time field is out of range. > + @retval EFI_DEVICE_ERROR The wakeup time could not be set due to = a hardware error. > + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this = platform. > + > +**/ > +EFI_STATUS EFIAPI SetWakeupTime(IN BOOLEAN Enabled, OUT EFI_TIME * Time) > +{ > + return EFI_UNSUPPORTED; > +} > + > + > +// Convert the mSmbus as well since the SmbusLib leaves this to the runt= ine DXEs > + > +EFIAPI VOID > +RtcVirtualNotifyEvent(IN EFI_EVENT Event, IN VOID * Context) > +{ > + EfiConvertPointer (0x0, (VOID **) &mRtcPrivateData); > +} > + > +/** > + The Entry Point of module. It follows the standard UEFI driver model. > + > + @param[in] ImageHandle The firmware allocated handle for the EFI im= age. > + @param[in] SystemTable A pointer to the EFI System Table. > + > + @retval EFI_SUCCESS The entry point is executed successfully. > + @retval other Some error occurs when executing this entry poin= t. > + > +**/ > +EFI_STATUS > + EFIAPI > +RtcNullDxeInitialize ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE * SystemTable) > +{ > + EFI_TIME Time; > + RTC_NULL_PRIVATE_DATA *Private =3D NULL; > + EFI_STATUS Status =3D EFI_SUCCESS; > + > + DEBUG ((DEBUG_INFO, "RtcNullDxeInitialize\n")); > + > + /* Allocate the private data */ > + Private =3D AllocateRuntimeZeroPool (sizeof (RTC_NULL_PRIVATE_DATA)); > + > + if (Private =3D=3D NULL) { > + Status =3D EFI_OUT_OF_RESOURCES; > + DEBUG ((DEBUG_ERROR, "RtcDxeInitialize: %r\n", Status)); > + goto Exit; > + } > + > + mRtcPrivateData =3D Private; > + > + Private->Initialized =3D FALSE; > + Private->Bus =3D 0xFF; > + Private->SlaveAddr =3D 0xFF; > + > + /* Check clock and init it to UNIX start time */ > + Status =3D GetDateTime (mRtcPrivateData, &Time); > + > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "RtcNullDxeInitialize: %r\n", Status)); > + goto Exit; > + } > + > + if (Time.Year =3D=3D 1900) { > + Time.Day =3D 1; > + Time.Month =3D 1; > + Time.Year =3D 1998; > + Time.Second =3D 0; > + Time.Minute =3D 0; > + Time.Hour =3D 0; > + Time.Daylight =3D 0; > + Time.TimeZone =3D 0; > + > + Status =3D SetDateTime (mRtcPrivateData, &Time); > + > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "RtcDxeInitialize: %r\n", Status)); > + goto Exit; > + } > + } > + > +Exit: > + gRT->GetTime =3D GetTime; > + gRT->SetTime =3D SetTime; > + gRT->GetWakeupTime =3D GetWakeupTime; > + gRT->SetWakeupTime =3D SetWakeupTime; > + > + Status =3D gBS->InstallMultipleProtocolInterfaces (&Private->RtcHandle= , > + &gEfiRealTimeClockArc= hProtocolGuid, > + NULL, > + NULL); > + > + Status =3D gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, > + TPL_NOTIFY, > + RtcVirtualNotifyEvent, > + NULL, > + &gEfiEventVirtualAddressChangeGuid, > + &mRtcVirtualAddressChangeEvent); > + ASSERT_EFI_ERROR(Status); > + > + return Status; > +} > diff --git a/Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.h b/Silicon/= Marvell/Drivers/Null/RtcNull/RtcNullDxe.h > new file mode 100644 > index 0000000000..dca99ef8f9 > --- /dev/null > +++ b/Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.h > @@ -0,0 +1,37 @@ > +/** @file > +* > +* SPDX-License-Identifier: BSD-2-Clause-Patent > +* https://spdx.org/licenses > +* > +* Copyright (C) 2022 Marvell > +* > +* Header file for NULL RTC Driver > +* > +**/ > + > +#ifndef _RTC_NULL_DXE_H_ > +#define _RTC_NULL_DXE_H_ > + > +#include > + > +#include > +#include > +#include > +#include // gBS > +#include // ZeroMem > + > +// > +// Private data for driver. > +// > +#define RTC_NULL_DXE_PRIVATE_DATA_SIGNATURE SIGNATURE_32( 'R', 'T', 'C'= , '_' ) > + > +typedef struct { > + UINT32 Signature; > + UINT8 Bus; > + UINT8 SlaveAddr; > + EFI_HANDLE RtcHandle; > + BOOLEAN Initialized; > +} RTC_NULL_PRIVATE_DATA; > + > + > +#endif //_RTC_NULL_DXE_H_ > diff --git a/Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.inf b/Silico= n/Marvell/Drivers/Null/RtcNull/RtcNullDxe.inf > new file mode 100644 > index 0000000000..d262e971fc > --- /dev/null > +++ b/Silicon/Marvell/Drivers/Null/RtcNull/RtcNullDxe.inf > @@ -0,0 +1,46 @@ > +#/** @file > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# https://spdx.org/licenses > +# > +# Copyright (C) 2022 Marvell > +# Module description file of RTC NULL driver. > +# > +#**/ > + > +[Defines] > + INF_VERSION =3D 0x00010005 > + BASE_NAME =3D RtcNullDxe > + FILE_GUID =3D 9c0a0971-b0f6-442e-ac01-0a3eb52c457= d > + MODULE_TYPE =3D DXE_RUNTIME_DRIVER > + VERSION_STRING =3D 1.0 > + > + ENTRY_POINT =3D RtcNullDxeInitialize > + > + > +[Sources] > + RtcNullDxe.c > + RtcNullDxe.h > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + > +[LibraryClasses] > + DebugLib > + MemoryAllocationLib > + UefiDriverEntryPoint > + BaseMemoryLib > + UefiBootServicesTableLib > + UefiRuntimeLib > + UefiRuntimeServicesTableLib > + > +[Guids] > + gEfiEventVirtualAddressChangeGuid > + > +[Protocols] > + gEfiRealTimeClockArchProtocolGuid ## PRODUCES > + > +[Depex] > + TRUE > + > -- > 2.34.1 > > > >=20 > > -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113721): https://edk2.groups.io/g/devel/message/113721 Mute This Topic: https://groups.io/mt/103292513/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-