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 40B6D7803CC for ; Thu, 20 Jul 2023 21:07:39 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=M3WbKCfhSLygvIlC/7xvXEDnQaPM5KBMJpPpiOEgbfI=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:X-Received: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; s=20140610; t=1689887257; v=1; b=wHA/baJvOt6SYFTh5cpXO4l7ZzVO54Def8NDKZCaFy9Ublf2JrFjm03wt9QrmzclQZMti/ml x19t10vXN9mniqSUk1++nUk1LjLkFlfxLvPg12u8Yvu1d775SGsmKtOrJWyiezXR5n8i4+/eNoG OKImh87tozeLSqM0xafu/CG8= X-Received: by 127.0.0.2 with SMTP id WyNhYY7687511x5gzDCedZqq; Thu, 20 Jul 2023 14:07:37 -0700 X-Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mx.groups.io with SMTP id smtpd.web11.1809.1689887257164528710 for ; Thu, 20 Jul 2023 14:07:37 -0700 X-Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1b8baa836a5so9414025ad.1 for ; Thu, 20 Jul 2023 14:07:37 -0700 (PDT) X-Gm-Message-State: 2bxpXAkqyY8NJmaUi6hVa7Ncx7686176AA= X-Google-Smtp-Source: APBJJlF3xLOM6wZmq836ByCnmqOeLoUS3EDP1TpWYu0tM4J51U2t/NY4dEK6DqZ8aB6wmljnTl3u8Q== X-Received: by 2002:a17:903:2613:b0:1ad:f138:b2f6 with SMTP id jd19-20020a170903261300b001adf138b2f6mr166626plb.16.1689887256370; Thu, 20 Jul 2023 14:07:36 -0700 (PDT) X-Received: from MININT-0U7P5GU.redmond.corp.microsoft.com ([2001:4898:80e8:37:e07c:3f9b:2f13:3c64]) by smtp.gmail.com with ESMTPSA id d1-20020a170902aa8100b001b9ecee9f81sm1855943plr.129.2023.07.20.14.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 14:07:36 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Dandan Bi , Liming Gao , Debkumar De , Catharine West , Mike Turner Subject: [edk2-devel] [PATCH v1 3/4] MdeModulePkg: PeiMain: Introduce implementation of delayed dispatch Date: Thu, 20 Jul 2023 14:07:27 -0700 Message-ID: <20230720210729.774-4-kuqin12@gmail.com> In-Reply-To: <20230720210729.774-1-kuqin12@gmail.com> References: <20230720210729.774-1-kuqin12@gmail.com> MIME-Version: 1.0 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,kuqin12@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: 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="wHA/baJv"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.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 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4496 This change adds the implementation that fits the needs and description of PI spec defined Delayed Dispatch PPI in Pei Core. The PPI would allow minimal delay for registered callbacks. As well as allowing other functions to wait for GUIDed delayed dispatch callbacks. Cc: Jian J Wang Cc: Dandan Bi Cc: Liming Gao Cc: Debkumar De Cc: Catharine West Co-authored-by: Mike Turner Signed-off-by: Kun Qin --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 353 ++++++++++++++++++++ MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 3 + MdeModulePkg/Core/Pei/PeiMain.h | 76 +++++ MdeModulePkg/Core/Pei/PeiMain.inf | 7 + MdeModulePkg/MdeModulePkg.dec | 15 + 5 files changed, 454 insertions(+) diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Pei/Dispatcher/Dispatcher.c index 5f32ebb560ae..50e59bdbe732 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -3,12 +3,339 @@ =0D Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
=0D (C) Copyright 2016 Hewlett Packard Enterprise Development LP
=0D +Copyright (c) Microsoft Corporation.=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D =0D #include "PeiMain.h"=0D =0D +/**=0D + DelayedDispatchDispatcher=0D +=0D + ayed Dispach cycle (ie one pass) through each entry, calling functions w= hen their=0D + e has expired. When UniqueId is specified, if there are any of the spec= ified entries=0D + the dispatch queue during dispatch, repeat the DelayedDispatch cycle.=0D +=0D + @param DelayedDispatchTable Pointer to dispatch table=0D + @param OPTIONAL UniqueId used to insure particular time is = met.=0D +=0D + @return BOOLEAN=0D +**/=0D +BOOLEAN=0D +DelayedDispatchDispatcher (=0D + IN DELAYED_DISPATCH_TABLE *DelayedDispatchTable,=0D + IN EFI_GUID *UniqueId OPTIONAL=0D + );=0D +=0D +/**=0D + DelayedDispatch End of PEI callback function. Insure that all of the del= ayed dispatch=0D + entries are complete before exiting PEI.=0D +=0D + @param[in] PeiServices - Pointer to PEI Services Table.=0D + @param[in] NotifyDesc - Pointer to the descriptor for the Notificatio= n event that=0D + caused this function to execute.=0D + @param[in] Ppi - Pointer to the PPI data associated with this = function.=0D +=0D + @retval EFI_STATUS - Always return EFI_SUCCESS=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiDelayedDispatchOnEndOfPei (=0D + IN EFI_PEI_SERVICES **PeiServices,=0D + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,=0D + IN VOID *Ppi=0D + );=0D +=0D +EFI_DELAYED_DISPATCH_PPI mDelayedDispatchPpi =3D { PeiDelayedDispatchReg= ister, PeiDelayedDispatchWaitOnUniqueId };=0D +EFI_PEI_PPI_DESCRIPTOR mDelayedDispatchDesc =3D {=0D + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),=0D + &gEfiPeiDelayedDispatchPpiGuid,=0D + &mDelayedDispatchPpi=0D +};=0D +=0D +EFI_PEI_NOTIFY_DESCRIPTOR mDelayedDispatchNotifyDesc =3D {=0D + EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINAT= E_LIST,=0D + &gEfiEndOfPeiSignalPpiGuid,=0D + PeiDelayedDispatchOnEndOfPei=0D +};=0D +=0D +/**=0D + Helper function to look up DELAYED_DISPATCH_TABLE published in HOB.=0D +=0D + @return Pointer to DELAYED_DISPATCH_TABLE from HOB=0D +**/=0D +DELAYED_DISPATCH_TABLE *=0D +GetDelayedDispatchTable (=0D + VOID=0D + )=0D +{=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D +=0D + GuidHob =3D GetFirstGuidHob (&gEfiDelayedDispatchTableGuid);=0D + if (NULL =3D=3D GuidHob) {=0D + DEBUG ((DEBUG_ERROR, "Delayed Dispatch PPI ERROR - Delayed Dispatch Ho= b not available.\n"));=0D + ASSERT (FALSE);=0D + return NULL;=0D + }=0D +=0D + return (DELAYED_DISPATCH_TABLE *)GET_GUID_HOB_DATA (GuidHob);=0D +}=0D +=0D +/**=0D +Register a callback to be called after a minimum delay has occurred.=0D +=0D +This service is the single member function of the EFI_DELAYED_DISPATCH_PPI= =0D +=0D + @param[in] This Pointer to the EFI_DELAYED_DISPATCH_PPI instan= ce=0D + @param[in] Function Function to call back=0D + @param[in] Context Context data=0D + @param[in] UniqueId GUID for this Delayed Dispatch request.=0D + @param[in] Delay Delay interval=0D +=0D + @retval EFI_SUCCESS Function successfully loaded=0D + @retval EFI_INVALID_PARAMETER One of the Arguments is not supported= =0D + @retval EFI_OUT_OF_RESOURCES No more entries=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiDelayedDispatchRegister (=0D + IN EFI_DELAYED_DISPATCH_PPI *This,=0D + IN EFI_DELAYED_DISPATCH_FUNCTION Function,=0D + IN UINT64 Context,=0D + IN EFI_GUID *UniqueId OPTIONAL,=0D + IN UINT32 Delay=0D + )=0D +{=0D + DELAYED_DISPATCH_TABLE *DelayedDispatchTable;=0D + DELAYED_DISPATCH_ENTRY *Entry;=0D +=0D + // Check input parameters=0D + if ((NULL =3D=3D Function) || (Delay > FixedPcdGet32 (PcdDelayedDispatch= MaxDelayUs)) || (NULL =3D=3D This)) {=0D + DEBUG ((DEBUG_ERROR, "%a Invalid parameter\n", __func__));=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + // Get delayed dispatch table=0D + DelayedDispatchTable =3D GetDelayedDispatchTable ();=0D + if (NULL =3D=3D DelayedDispatchTable) {=0D + DEBUG ((DEBUG_ERROR, "%a Unable to locate dispatch table\n", __func__)= );=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + // Check for available entry slots=0D + if (DelayedDispatchTable->Count >=3D FixedPcdGet32 (PcdDelayedDispatchMa= xEntries)) {=0D + ASSERT (DelayedDispatchTable->Count < FixedPcdGet32 (PcdDelayedDispatc= hMaxEntries));=0D + DEBUG ((DEBUG_ERROR, "%a Too many entries requested\n", __func__));=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + Entry =3D &(DelayedDispatchTable->Entry[DelayedDispatchTab= le->Count]);=0D + Entry->Function =3D Function;=0D + Entry->Context =3D Context;=0D + Entry->DispatchTime =3D GET_TIME_IN_US () + Delay;=0D + if (NULL !=3D UniqueId) {=0D + CopyGuid (&Entry->UniqueId, UniqueId);=0D + } else {=0D + ZeroMem (&Entry->UniqueId, sizeof (EFI_GUID));=0D + }=0D +=0D + Entry->MicrosecondDelay =3D Delay;=0D + DelayedDispatchTable->Count++;=0D +=0D + DEBUG ((DEBUG_INFO, "%a Adding dispatch Entry\n", __func__));=0D + DEBUG ((DEBUG_INFO, " Requested Delay =3D %d\n", Delay));=0D + DEBUG ((DEBUG_INFO, " Trigger Time =3D %d\n", Entry->DispatchTime));= =0D + DEBUG ((DEBUG_INFO, " Context =3D 0x%08lx\n", Entry->Context));=0D + DEBUG ((DEBUG_INFO, " Function =3D %p\n", Entry->Function));=0D + DEBUG ((DEBUG_INFO, " GuidHandle =3D %g\n", &(Entry->UniqueId)));=0D +=0D + if (0 =3D=3D Delay) {=0D + // Force early dispatch point=0D + DelayedDispatchDispatcher (DelayedDispatchTable, NULL);=0D + }=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + DelayedDispatchDispatcher=0D +=0D + ayed Dispach cycle (ie one pass) through each entry, calling functions w= hen their=0D + e has expired. When UniqueId is specified, if there are any of the spec= ified entries=0D + the dispatch queue during dispatch, repeat the DelayedDispatch cycle.=0D +=0D + @param DelayedDispatchTable Pointer to dispatch table=0D + @param OPTIONAL UniqueId used to insure particular time is = met.=0D +=0D + @return BOOLEAN=0D +**/=0D +BOOLEAN=0D +DelayedDispatchDispatcher (=0D + IN DELAYED_DISPATCH_TABLE *DelayedDispatchTable,=0D + IN EFI_GUID *UniqueId OPTIONAL=0D + )=0D +{=0D + BOOLEAN Dispatched;=0D + UINT32 TimeCurrent;=0D + UINT32 MaxDispatchTime;=0D + UINTN Index1;=0D + BOOLEAN UniqueIdPresent;=0D + DELAYED_DISPATCH_ENTRY *Entry;=0D +=0D + Dispatched =3D FALSE;=0D + UniqueIdPresent =3D TRUE;=0D + MaxDispatchTime =3D GET_TIME_IN_US () + FixedPcdGet32 (PcdDelayedDispatc= hCompletionTimeoutUs);=0D + while ((DelayedDispatchTable->Count > 0) && (UniqueIdPresent)) {=0D + UniqueIdPresent =3D FALSE;=0D + DelayedDispatchTable->DispCount++;=0D +=0D + // If dispatching is messed up, clear DelayedDispatchTable and exit.=0D + TimeCurrent =3D GET_TIME_IN_US ();=0D + if (TimeCurrent > MaxDispatchTime) {=0D + DEBUG ((DEBUG_ERROR, "%a - DelayedDispatch Completion timeout!\n", _= _func__));=0D + ReportStatusCode ((EFI_ERROR_MAJOR | EFI_ERROR_CODE), (EFI_SOFTWARE_= PEI_CORE | EFI_SW_EC_ABORTED));=0D + ASSERT (FALSE);=0D + DelayedDispatchTable->Count =3D 0;=0D + break;=0D + }=0D +=0D + // Check each entry in the table for possible dispatch=0D + for (Index1 =3D 0; Index1 < DelayedDispatchTable->Count;) {=0D + Entry =3D &(DelayedDispatchTable->Entry[Index1]);=0D + // If UniqueId is present, insure there is an additional check of th= e table.=0D + if (NULL !=3D UniqueId) {=0D + if (CompareGuid (UniqueId, &Entry->UniqueId)) {=0D + UniqueIdPresent =3D TRUE;=0D + }=0D + }=0D +=0D + TimeCurrent =3D GET_TIME_IN_US ();=0D + if (TimeCurrent >=3D Entry->DispatchTime) {=0D + // Time expired, invoked the function=0D + DEBUG ((=0D + DEBUG_ERROR,=0D + "Delayed dispatch entry %d @ %p, Target=3D%d, Act=3D%d Disp=3D%d= \n",=0D + Index1,=0D + Entry->Function,=0D + Entry->DispatchTime,=0D + TimeCurrent,=0D + DelayedDispatchTable->DispCount=0D + ));=0D + Dispatched =3D TRUE;=0D + Entry->MicrosecondDelay =3D 0;=0D + Entry->Function (=0D + &Entry->Context,=0D + &Entry->MicrosecondDelay=0D + );=0D + DEBUG ((DEBUG_ERROR, "Delayed dispatch Function returned delay=3D%= d\n", Entry->MicrosecondDelay));=0D + if (0 =3D=3D Entry->MicrosecondDelay) {=0D + // NewTime =3D 0 =3D delete this entry from the table=0D + DelayedDispatchTable->Count--;=0D + CopyMem (Entry, Entry+1, sizeof (DELAYED_DISPATCH_ENTRY) * (Dela= yedDispatchTable->Count - Index1));=0D + } else {=0D + if (Entry->MicrosecondDelay > FixedPcdGet32 (PcdDelayedDispatchM= axDelayUs)) {=0D + DEBUG ((DEBUG_ERROR, "%a Illegal new delay %d requested\n", __= func__, Entry->MicrosecondDelay));=0D + ASSERT (FALSE);=0D + Entry->MicrosecondDelay =3D FixedPcdGet32 (PcdDelayedDispatchM= axDelayUs);=0D + }=0D +=0D + // NewTime !=3D 0 - update the time from us to Dispatch time=0D + Entry->DispatchTime =3D GET_TIME_IN_US () + Entry->MicrosecondD= elay;=0D + Index1++;=0D + }=0D + } else {=0D + Index1++;=0D + }=0D + }=0D + }=0D +=0D + return Dispatched;=0D +}=0D +=0D +/**=0D + Wait on a registered Delayed Dispatch unit that has a UniqueId. Continu= e=0D + to dispatch all registered delayed dispatch entries until *ALL* entries = with=0D + UniqueId have completed.=0D +=0D + @param[in] This The Delayed Dispatch PPI pointer.=0D + @param[in] UniqueId UniqueId of delayed dispatch entry.=0D +=0D + @retval EFI_SUCCESS The operation succeeds.=0D + @retval EFI_INVALID_PARAMETER The parameters are invalid.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiDelayedDispatchWaitOnUniqueId (=0D + IN EFI_DELAYED_DISPATCH_PPI *This,=0D + IN EFI_GUID *UniqueId=0D + )=0D +{=0D + PERF_FUNCTION_BEGIN ();=0D + DELAYED_DISPATCH_TABLE *DelayedDispatchTable;=0D +=0D + // Get delayed dispatch table=0D + DelayedDispatchTable =3D GetDelayedDispatchTable ();=0D + if (NULL =3D=3D DelayedDispatchTable) {=0D + PERF_FUNCTION_END ();=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + if ((NULL =3D=3D UniqueId) || (IsZeroGuid (UniqueId))) {=0D + ASSERT (FALSE);=0D + PERF_FUNCTION_END ();=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "Delayed dispatch on %g. Count=3D%d, DispatchCount= =3D%d\n", UniqueId, DelayedDispatchTable->Count, DelayedDispatchTable->Disp= Count));=0D + PERF_EVENT_SIGNAL_BEGIN (UniqueId);=0D + DelayedDispatchDispatcher (DelayedDispatchTable, UniqueId);=0D + PERF_EVENT_SIGNAL_END (UniqueId);=0D +=0D + PERF_FUNCTION_END ();=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + DelayedDispatch End of PEI callback function. Insure that all of the del= ayed dispatch=0D + entries are complete before exiting PEI.=0D +=0D + @param[in] PeiServices - Pointer to PEI Services Table.=0D + @param[in] NotifyDesc - Pointer to the descriptor for the Notificatio= n event that=0D + caused this function to execute.=0D + @param[in] Ppi - Pointer to the PPI data associated with this = function.=0D +=0D + @retval EFI_STATUS - Always return EFI_SUCCESS=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiDelayedDispatchOnEndOfPei (=0D + IN EFI_PEI_SERVICES **PeiServices,=0D + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,=0D + IN VOID *Ppi=0D + )=0D +{=0D + DELAYED_DISPATCH_TABLE *DelayedDispatchTable;=0D +=0D + // Get delayed dispatch table=0D + DelayedDispatchTable =3D GetDelayedDispatchTable ();=0D + if (NULL =3D=3D DelayedDispatchTable) {=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + PERF_INMODULE_BEGIN ("PerfDelayedDispatchEndOfPei");=0D + while (DelayedDispatchTable->Count > 0) {=0D + DelayedDispatchDispatcher (DelayedDispatchTable, NULL);=0D + }=0D +=0D + DEBUG ((DEBUG_ERROR, "%a Count of dispatch cycles is %d\n", __func__, De= layedDispatchTable->DispCount));=0D + PERF_INMODULE_END ("PerfDelayedDispatchEndOfPei");=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D /**=0D =0D Discover all PEIMs and optional Apriori file in one FV. There is at most= one=0D @@ -1365,12 +1692,31 @@ PeiDispatcher ( EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;=0D EFI_FV_FILE_INFO FvFileInfo;=0D PEI_CORE_FV_HANDLE *CoreFvHandle;=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + UINT32 TableSize;=0D =0D PeiServices =3D (CONST EFI_PEI_SERVICES **)&Private->Ps;=0D PeimEntryPoint =3D NULL;=0D PeimFileHandle =3D NULL;=0D EntryPoint =3D 0;=0D =0D + if (NULL =3D=3D Private->DelayedDispatchTable) {=0D + GuidHob =3D GetFirstGuidHob (&gEfiDelayedDispatchTableGuid);=0D + if (NULL !=3D GuidHob) {=0D + Private->DelayedDispatchTable =3D (DELAYED_DISPATCH_TABLE *)(GET_GUI= D_HOB_DATA (GuidHob));=0D + } else {=0D + TableSize =3D sizeof (DELAYED_DISPATCH_TABLE) + = ((FixedPcdGet32 (PcdDelayedDispatchMaxEntries) - 1) * sizeof (DELAYED_DISPA= TCH_ENTRY));=0D + Private->DelayedDispatchTable =3D BuildGuidHob (&gEfiDelayedDispatch= TableGuid, TableSize);=0D + if (NULL !=3D Private->DelayedDispatchTable) {=0D + ZeroMem (Private->DelayedDispatchTable, TableSize);=0D + Status =3D PeiServicesInstallPpi (&mDelayedDispatchDesc);=0D + ASSERT_EFI_ERROR (Status);=0D + Status =3D PeiServicesNotifyPpi (&mDelayedDispatchNotifyDesc);=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D + }=0D + }=0D +=0D if ((Private->PeiMemoryInstalled) &&=0D (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes) ||=0D (Private->HobList.HandoffInformationTable->BootMode !=3D BOOT_ON_S3= _RESUME) ||=0D @@ -1621,6 +1967,13 @@ PeiDispatcher ( }=0D }=0D }=0D +=0D + // Dispatch pending delalyed dispatch requests=0D + if (NULL !=3D Private->DelayedDispatchTable) {=0D + if (DelayedDispatchDispatcher (Private->DelayedDispatchTable, NU= LL)) {=0D + ProcessDispatchNotifyList (Private);=0D + }=0D + }=0D }=0D =0D //=0D diff --git a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c b/MdeModulePkg/Core/Pe= i/PeiMain/PeiMain.c index bf1719d7941a..e5643adf7027 100644 --- a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c +++ b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c @@ -277,6 +277,9 @@ PeiCore ( OldCoreData->TempFileHandles =3D (EFI_PEI_FILE_HANDLE *)((UINT8 *)= OldCoreData->TempFileHandles - OldCoreData->HeapOffset);=0D }=0D =0D + // Force relocating the dispatch table=0D + OldCoreData->DelayedDispatchTable =3D NULL;=0D +=0D //=0D // Fixup for PeiService's address=0D //=0D diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMai= n.h index 556beddad533..3b8bbe7f25a1 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.h +++ b/MdeModulePkg/Core/Pei/PeiMain.h @@ -11,6 +11,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =0D #include =0D #include =0D +#include =0D +#include =0D #include =0D #include =0D #include =0D @@ -41,6 +43,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -207,6 +210,29 @@ EFI_STATUS =0D #define PEI_CORE_HANDLE_SIGNATURE SIGNATURE_32('P','e','i','C')=0D =0D +#define GET_TIME_IN_US() ((UINT32)DivU64x32(GetTimeInNanoSecond(GetPerfor= manceCounter ()), 1000))=0D +=0D +//=0D +// Internal structure for delayed dispatch entries.=0D +//=0D +#pragma pack (push, 1)=0D +=0D +typedef struct {=0D + EFI_GUID UniqueId;=0D + UINT64 Context;=0D + EFI_DELAYED_DISPATCH_FUNCTION Function;=0D + UINT32 DispatchTime;=0D + UINT32 MicrosecondDelay;=0D +} DELAYED_DISPATCH_ENTRY;=0D +=0D +typedef struct {=0D + UINT32 Count;=0D + UINT32 DispCount;=0D + DELAYED_DISPATCH_ENTRY Entry[1]; // Actual size based on PCD PcdD= elayedDispatchMaxEntries;=0D +} DELAYED_DISPATCH_TABLE;=0D +=0D +#pragma pack (pop)=0D +=0D ///=0D /// Pei Core private data structure instance=0D ///=0D @@ -307,6 +333,11 @@ struct _PEI_CORE_INSTANCE { // Those Memory Range will be migrated into physical memory.=0D //=0D HOLE_MEMORY_DATA HoleData[HOLE_MAX_NUMBER];=0D +=0D + //=0D + // Table of delayed dispatch requests=0D + //=0D + DELAYED_DISPATCH_TABLE *DelayedDispatchTable;=0D };=0D =0D ///=0D @@ -2038,4 +2069,49 @@ PeiReinitializeFv ( IN PEI_CORE_INSTANCE *PrivateData=0D );=0D =0D +/**=0D +Register a callback to be called after a minimum delay has occurred.=0D +=0D +This service is the single member function of the EFI_DELAYED_DISPATCH_PPI= =0D +=0D + @param[in] This Pointer to the EFI_DELAYED_DISPATCH_PPI instan= ce=0D + @param[in] Function Function to call back=0D + @param[in] Context Context data=0D + @param[in] UniqueId GUID for this Delayed Dispatch request.=0D + @param[in] Delay Delay interval=0D +=0D + @retval EFI_SUCCESS Function successfully loaded=0D + @retval EFI_INVALID_PARAMETER One of the Arguments is not supported= =0D + @retval EFI_OUT_OF_RESOURCES No more entries=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiDelayedDispatchRegister (=0D + IN EFI_DELAYED_DISPATCH_PPI *This,=0D + IN EFI_DELAYED_DISPATCH_FUNCTION Function,=0D + IN UINT64 Context,=0D + IN EFI_GUID *UniqueId OPTIONAL,=0D + IN UINT32 Delay=0D + );=0D +=0D +/**=0D + Wait on a registered Delayed Dispatch unit that has a UniqueId. Continu= e=0D + to dispatch all registered delayed dispatch entries until *ALL* entries = with=0D + UniqueId have completed.=0D +=0D + @param[in] This The Delayed Dispatch PPI pointer.=0D + @param[in] UniqueId UniqueId of delayed dispatch entry.=0D +=0D + @retval EFI_SUCCESS The operation succeeds.=0D + @retval EFI_INVALID_PARAMETER The parameters are invalid.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiDelayedDispatchWaitOnUniqueId (=0D + IN EFI_DELAYED_DISPATCH_PPI *This,=0D + IN EFI_GUID *UniqueId=0D + );=0D +=0D #endif=0D diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiM= ain.inf index 0cf357371a16..73738c939ac7 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -66,6 +66,7 @@ [LibraryClasses] PeCoffLib=0D PeiServicesTablePointerLib=0D PcdLib=0D + TimerLib=0D =0D [Guids]=0D gPeiAprioriFileNameGuid ## SOMETIMES_CONSUMES ## File=0D @@ -78,6 +79,7 @@ [Guids] gEfiFirmwareFileSystem3Guid=0D gStatusCodeCallbackGuid=0D gEdkiiMigratedFvInfoGuid ## SOMETIMES_PRODUCES = ## HOB=0D + gEfiDelayedDispatchTableGuid ## SOMETIMES_PRODUCES = ## HOB=0D =0D [Ppis]=0D gEfiPeiStatusCodePpiGuid ## SOMETIMES_CONSUMES # Pe= iReportStatusService is not ready if this PPI doesn't exist=0D @@ -100,6 +102,8 @@ [Ppis] gEfiPeiReset2PpiGuid ## SOMETIMES_CONSUMES=0D gEfiSecHobDataPpiGuid ## SOMETIMES_CONSUMES=0D gEfiPeiCoreFvLocationPpiGuid ## SOMETIMES_CONSUMES=0D + gEfiPeiDelayedDispatchPpiGuid ## SOMETIMES_CONSUMES=0D + gEfiEndOfPeiSignalPpiGuid ## CONSUMES=0D =0D [Pcd]=0D gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize = ## CONSUMES=0D @@ -112,6 +116,9 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot = ## CONSUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack = ## CONSUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdMigrateTemporaryRamFirmwareVolumes = ## CONSUMES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchMaxDelayUs = ## CONSUMES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchCompletionTimeoutUs = ## CONSUMES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchMaxEntries = ## CONSUMES=0D =0D # [BootMode]=0D # S3_RESUME ## SOMETIMES_CONSUMES=0D diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 0ff058b0a9da..2f4bd2f2b773 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -418,6 +418,9 @@ [Guids] ## Include/Guid/MigratedFvInfo.h=0D gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4,= 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } }=0D =0D + ## Delayed Dispatch table GUID=0D + gEfiDelayedDispatchTableGuid =3D { 0x4b733449, 0x8eff, 0x488c, {0x92, 0x= 1a, 0x15, 0x4a, 0xda, 0x25, 0x18, 0x07}}=0D +=0D #=0D # GUID defined in UniversalPayload=0D #=0D @@ -991,6 +994,18 @@ [PcdsFixedAtBuild] # @ValidList 0x80000006 | 0x03058002=0D gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable|0x03058002|UINT32= |0x30001040=0D =0D + ## Delayed Dispatch Maximum Delay in us (microseconds)=0D + # Maximum delay for any particular delay request - 5 seconds=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchMaxDelayUs|5000000|UINT= 32|0x3000104A=0D +=0D + ## Delayed Dispatch timeout in us (microseconds)=0D + # Maximum delay when waiting for completion (ie EndOfPei) - 10 seconds=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchCompletionTimeoutUs|100= 00000|UINT32|0x3000104B=0D +=0D + ## Delayed Dispatch Max Entries=0D + # Maximum number of delayed dispatch entries=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdDelayedDispatchMaxEntries|8|UINT32|0x3= 000104C=0D +=0D ## Mask to control the NULL address detection in code for different phas= es.=0D # If enabled, accessing NULL address in UEFI or SMM code can be caught.=

=0D # BIT0 - Enable NULL pointer detection for UEFI.
=0D --=20 2.41.0.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107114): https://edk2.groups.io/g/devel/message/107114 Mute This Topic: https://groups.io/mt/100264778/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-