From nobody Tue Feb 10 00:59:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112783+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112783+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=marvell.com ARC-Seal: i=1; a=rsa-sha256; t=1703120077; cv=none; d=zohomail.com; s=zohoarc; b=IVxXahSHYWhqqcOHvwM8JPuucKkCHNXp1E+pJ+sbwKCuCt049DfXHmeM+jYC5ZhuvmlkcyaHhfBDOktia8FieqT2QAHbQhO0t1k6PXPxK5y+OE/nno/xDOLFrRBymZCGFmnXP1AccESfPlVy0ICqamoC97eM5a+BwIjPFAZLSzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703120077; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=YneV/WszFz0sSIRdzPnEpwv+Na8xAbIquUS6YD8PrYc=; b=huUwB+oEh6OTuB7UFvdOVhQM4Ia5I1mnrpfHWwd/Svct7IwxOMV4Ps5iGBQD3moqNDkfslLBKfFgj2SEKF+uQxSjrcnGDswTrnwik1Y9Vmxj+PoKr0C3/8Zl4RfljmqZog+KFrzddUsYV27LVhWOYirAgZVXR8GcdCSwIky94Fw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112783+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 170312007714512.335224538692955; Wed, 20 Dec 2023 16:54:37 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=quKomW33SM0XN/hR3+x5mJJiLQHV9h663zBoGAmqO6s=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1703120076; v=1; b=Oj8CvSh/jx34HQclI9xDTCWQZ34e82HlRTJtmVNxLpbe6fZ0N/K5tIQKhh5ppVNAgvprbdlw H7hr78h68HY67zBz7C8FdIqksbedw9lacYGSgNZUY6aLEN0OMCjv8hPIkHmHqHOWZZST6HaBfft sJnavsUzQxh+vz8zBN3PvlVU= X-Received: by 127.0.0.2 with SMTP id usDmYY1788612x6KUNn2WYQ2; Wed, 20 Dec 2023 16:54:36 -0800 X-Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.148.174]) by mx.groups.io with SMTP id smtpd.web11.41320.1703120076402504397 for ; Wed, 20 Dec 2023 16:54:36 -0800 X-Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BKH2Ed8004000; Wed, 20 Dec 2023 16:54:36 -0800 X-Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3v3tbcvg8e-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 16:54:35 -0800 (PST) X-Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 20 Dec 2023 16:54:34 -0800 X-Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 20 Dec 2023 16:54:34 -0800 X-Received: from MRVL-5Lp9he46Ey.marvell.com (unknown [10.193.15.34]) by maili.marvell.com (Postfix) with ESMTP id C60BE3F706F; Wed, 20 Dec 2023 16:54:33 -0800 (PST) From: "Narinder Dhillon" To: CC: , , , Narinder Dhillon Subject: [edk2-devel] [edk2-platforms PATCH v2 5/8] Silicon/Marvell: RTC driver Date: Wed, 20 Dec 2023 16:54:24 -0800 Message-ID: <20231221005427.13932-6-ndhillon@marvell.com> In-Reply-To: <20231221005427.13932-1-ndhillon@marvell.com> References: <20231221005427.13932-1-ndhillon@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dT57FHKy7WFpv-KTY2nFL0ZidmHmjDrt X-Proofpoint-GUID: dT57FHKy7WFpv-KTY2nFL0ZidmHmjDrt 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,ndhillon@marvell.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: mPeaj1V0ZkdXUo9yzBijD5JRx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1703120077755100009 Content-Type: text/plain; charset="utf-8" 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 +++ 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/Ma= rvell/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 // AllocateRuntimeZeroPo= ol +#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 capa= bilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapshot= of the current time. + @param Capabilities An optional pointer to a buffer to receive= 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 har= dware 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 hardw= are 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 enable= d or disabled. + @param Pending Indicates if the alarm signal is pending a= nd 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 due= 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 wak= eup alarm for. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm w= as enabled. If + Enable is FALSE, then the wakeup alarm was= 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 pl= atform. + +**/ +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 runtin= e 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 imag= e. + @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 point. + +**/ +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, + &gEfiRealTimeClockArchP= rotocolGuid, + 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/Ma= rvell/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/Silicon/= 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-0a3eb52c457d + 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 + --=20 2.34.1 -=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 (#112783): https://edk2.groups.io/g/devel/message/112783 Mute This Topic: https://groups.io/mt/103292513/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-