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 A2E447803CD for ; Thu, 21 Dec 2023 00:54:39 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=DWzfJf8idCae5HLUDCJDgm1gNE47E+4iQBaxRj0jfxw=; 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=1703120078; v=1; b=lOPRl1as4a4hgAlfglzr1JYPISemnQJzssWWRq6yzSPepxdk3ikBSPTN8rjBq74jYEAnPVBE pksDo2JxERDuDJNhahGpUrAJ0WWU96SOCj+InfSw8+xSOaih59kcY8wMbNU8yq9C+3UR7AzPQd/ VxY+D/w11TgVEru+f5chzVls= X-Received: by 127.0.0.2 with SMTP id DAA9YY7687511xaYDZy6xau7; Wed, 20 Dec 2023 16:54:38 -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: zuBtR0f7lhEJEb8dM6PQcITkx7686176AA= Content-Transfer-Encoding: 8bit Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=lOPRl1as; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=marvell.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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/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 // AllocateRuntimeZeroPool +#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] = + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + +STATIC +BOOLEAN +IsLeapYear(IN EFI_TIME *Time) +{ + if (Time->Year % 4 == 0) { + if (Time->Year % 100 == 0) { + if (Time->Year % 400 == 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 == 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 == NULL || Time == 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 == NULL || Time == 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 != 2047))) { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** + Returns the current time and date information, and the time-keeping capabilities + 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 hardware error. + +**/ +EFI_STATUS + EFIAPI +GetTime(OUT EFI_TIME * Time, OUT EFI_TIME_CAPABILITIES * Capabilities) +{ + if (Time == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (mRtcPrivateData->Initialized == 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 hardware error. + +**/ +EFI_STATUS EFIAPI SetTime(IN EFI_TIME * Time) +{ + if (Time == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (mRtcPrivateData->Initialized == FALSE) { + return EFI_UNSUPPORTED; + } + + return SetDateTime (mRtcPrivateData, Time); +} + + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enabled 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 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 wakeup alarm for. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was 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 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 runtine 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 image. + @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 = NULL; + EFI_STATUS Status = EFI_SUCCESS; + + DEBUG ((DEBUG_INFO, "RtcNullDxeInitialize\n")); + + /* Allocate the private data */ + Private = AllocateRuntimeZeroPool (sizeof (RTC_NULL_PRIVATE_DATA)); + + if (Private == NULL) { + Status = EFI_OUT_OF_RESOURCES; + DEBUG ((DEBUG_ERROR, "RtcDxeInitialize: %r\n", Status)); + goto Exit; + } + + mRtcPrivateData = Private; + + Private->Initialized = FALSE; + Private->Bus = 0xFF; + Private->SlaveAddr = 0xFF; + + /* Check clock and init it to UNIX start time */ + Status = GetDateTime (mRtcPrivateData, &Time); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "RtcNullDxeInitialize: %r\n", Status)); + goto Exit; + } + + if (Time.Year == 1900) { + Time.Day = 1; + Time.Month = 1; + Time.Year = 1998; + Time.Second = 0; + Time.Minute = 0; + Time.Hour = 0; + Time.Daylight = 0; + Time.TimeZone = 0; + + Status = SetDateTime (mRtcPrivateData, &Time); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "RtcDxeInitialize: %r\n", Status)); + goto Exit; + } + } + +Exit: + gRT->GetTime = GetTime; + gRT->SetTime = SetTime; + gRT->GetWakeupTime = GetWakeupTime; + gRT->SetWakeupTime = SetWakeupTime; + + Status = gBS->InstallMultipleProtocolInterfaces (&Private->RtcHandle, + &gEfiRealTimeClockArchProtocolGuid, + NULL, + NULL); + + Status = 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/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 = 0x00010005 + BASE_NAME = RtcNullDxe + FILE_GUID = 9c0a0971-b0f6-442e-ac01-0a3eb52c457d + MODULE_TYPE = DXE_RUNTIME_DRIVER + VERSION_STRING = 1.0 + + ENTRY_POINT = 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 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-