From nobody Tue May 7 21:00:24 2024 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+95925+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+95925+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1667521521; cv=none; d=zohomail.com; s=zohoarc; b=nsOMo91Fch+4aIVjX65IpO4tWjOnhMJdp/BJ+r4pXIonmqunbR/YByU00YzMB1HSX06s3PO5DVfWn4bK2IFE1SlRRNveW14FkvVoQVcv0YFx2QAOhVuhcKQ9abhgu+da9zSvJ1Ey8TJJzDSp3exU7FIxuALxsoqNfBIdbJz5NEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667521521; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=cexM8yT3GAb9ryMFrnhNOXGFoxjVfYrsC+Quik+Koo4=; b=jWkxnzxZ2C0j6uqHsiT5Gu04OriEbJYEWRyff8Wexb7GsoZ89XrGO30NPcdANaC4OS5Z0qOb+M2pqYW/g01JPY68+i2yVXo2XT1p6Svt+tTlYWGOWjz6xrjQrmOmW9mVeU+cEkkOpoUV2FGf2PhiUgPQE8/7Dj2AdIRwnQCBgm8= 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+95925+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 1667521521615179.87588929611218; Thu, 3 Nov 2022 17:25:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9a8UYY1788612xDVP84xKmjY; Thu, 03 Nov 2022 17:25:21 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web10.5966.1667521520470320144 for ; Thu, 03 Nov 2022 17:25:20 -0700 X-Received: from localhost.localdomain (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id 830C820B929F; Thu, 3 Nov 2022 17:25:19 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 830C820B929F From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Michael D Kinney , Sean Brogan Subject: [edk2-devel] [PATCH v1 1/2] UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib Date: Thu, 3 Nov 2022 20:24:39 -0400 Message-Id: <20221104002440.2316-2-mikuback@linux.microsoft.com> In-Reply-To: <20221104002440.2316-1-mikuback@linux.microsoft.com> References: <20221104002440.2316-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,mikuback@linux.microsoft.com X-Gm-Message-State: Jm8YCxdy7AEdi1pjMzhyacGsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1667521521; bh=8G/FSWB3D83Oz3INnzh3NIHkzYbAuNd0x6eb4EpJO4Q=; h=Cc:Date:From:Reply-To:Subject:To; b=iaLjQ1ugyo+LPFhj51nISW902MdTckE6bm841TJbKEahPWlqVR59pAjWgJQ1qyttE1p MRXxHpTUICVJIfeydUkpyCZAclr7WXuVKtJG02FimbWDi0iu6x64LpFav7ErUU2fq9azC nRl0iyScIuVdI0G4A9uu5oBBlwZYBY8n4+M= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1667521523471100001 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki This library supports a Boot Services table library implementation that allows code dependent upon UefiBootServicesTableLib to operate in an isolated execution environment such as within the context of a host-based unit test framework. The unit test should initialize the Boot Services database with any required elements (e.g. protocols, events, handles, etc.) prior to the services being invoked by code under test. It is strongly recommended to clean any global databases (e.g. protocol, event, handles, etc.) after every unit test so the tests execute in a predictable manner from a clean state. This library is being moved here from PrmPkg so it can be made more generally available to other packages and improved upon for others use. Cc: Michael D Kinney Cc: Sean Brogan Signed-off-by: Michael Kubacki Reviewed-by: Michael D Kinney --- UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLib.c | 119 ++ UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLibEventTimer.c | 180 +++ UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLibImage.c | 163 ++ UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLibMemory.c | 145 ++ UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLibMisc.c | 198 +++ UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLibProtocol.c | 1650 ++++++++++++++++++++ UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLibTpl.c | 43 + UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLib.h | 1042 ++++++++++++ UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLib.inf | 46 + UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLib.uni | 12 + UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefi= BootServicesTableLibProtocol.h | 120 ++ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc = | 1 + UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc = | 1 + 13 files changed, 3720 insertions(+) diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLib.c b/UnitTestFrameworkPkg/Library/UnitTestU= efiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c new file mode 100644 index 000000000000..a6fc13e7d21e --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLib.c @@ -0,0 +1,119 @@ +/** @file + This library supports a Boot Services table library implementation that = allows code dependent + upon UefiBootServicesTableLib to operate in an isolated execution enviro= nment such as within + the context of a host-based unit test framework. + + The unit test should initialize the Boot Services database with any requ= ired elements + (e.g. protocols, events, handles, etc.) prior to the services being invo= ked by code under test. + + It is strongly recommended to clean any global databases (e.g. protocol,= event, handles, etc.) after + every unit test so the tests execute in a predictable manner from a clea= n state. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestUefiBootServicesTableLib.h" + +EFI_HANDLE gImageHandle =3D NULL; +EFI_SYSTEM_TABLE *gST =3D NULL; + +STATIC EFI_BOOT_SERVICES mBootServices =3D { + { + EFI_BOOT_SERVICES_SIGNATURE, = // Signature + EFI_BOOT_SERVICES_REVISION, = // Revision + sizeof (EFI_BOOT_SERVICES), = // HeaderSize + 0, = // CRC32 + 0 = // Reserved + }, + (EFI_RAISE_TPL)UnitTestRaiseTpl, = // RaiseTPL + (EFI_RESTORE_TPL)UnitTestRestoreTpl, = // RestoreTPL + (EFI_ALLOCATE_PAGES)UnitTestAllocatePages, = // AllocatePages + (EFI_FREE_PAGES)UnitTestFreePages, = // FreePages + (EFI_GET_MEMORY_MAP)UnitTestGetMemoryMap, = // GetMemoryMap + (EFI_ALLOCATE_POOL)UnitTestAllocatePool, = // AllocatePool + (EFI_FREE_POOL)UnitTestFreePool, = // FreePool + (EFI_CREATE_EVENT)UnitTestCreateEvent, = // CreateEvent + (EFI_SET_TIMER)UnitTestSetTimer, = // SetTimer + (EFI_WAIT_FOR_EVENT)UnitTestWaitForEvent, = // WaitForEvent + (EFI_SIGNAL_EVENT)UnitTestSignalEvent, = // SignalEvent + (EFI_CLOSE_EVENT)UnitTestCloseEvent, = // CloseEvent + (EFI_CHECK_EVENT)UnitTestCheckEvent, = // CheckEvent + (EFI_INSTALL_PROTOCOL_INTERFACE)UnitTestInstallProtocolInterface, = // InstallProtocolInterface + (EFI_REINSTALL_PROTOCOL_INTERFACE)UnitTestReinstallProtocolInterface, = // ReinstallProtocolInterface + (EFI_UNINSTALL_PROTOCOL_INTERFACE)UnitTestUninstallProtocolInterface, = // UninstallProtocolInterface + (EFI_HANDLE_PROTOCOL)UnitTestHandleProtocol, = // HandleProtocol + (VOID *)NULL, = // Reserved + (EFI_REGISTER_PROTOCOL_NOTIFY)UnitTestRegisterProtocolNotify, = // RegisterProtocolNotify + (EFI_LOCATE_HANDLE)UnitTestLocateHandle, = // LocateHandle + (EFI_LOCATE_DEVICE_PATH)UnitTestLocateDevicePath, = // LocateDevicePath + (EFI_INSTALL_CONFIGURATION_TABLE)UnitTestInstallConfigurationTable, = // InstallConfigurationTable + (EFI_IMAGE_LOAD)UnitTestLoadImage, = // LoadImage + (EFI_IMAGE_START)UnitTestStartImage, = // StartImage + (EFI_EXIT)UnitTestExit, = // Exit + (EFI_IMAGE_UNLOAD)UnitTestUnloadImage, = // UnloadImage + (EFI_EXIT_BOOT_SERVICES)UnitTestExitBootServices, = // ExitBootServices + (EFI_GET_NEXT_MONOTONIC_COUNT)UnitTestGetNextMonotonicCount, = // GetNextMonotonicCount + (EFI_STALL)UnitTestStall, = // Stall + (EFI_SET_WATCHDOG_TIMER)UnitTestSetWatchdogTimer, = // SetWatchdogTimer + (EFI_CONNECT_CONTROLLER)UnitTestConnectController, = // ConnectController + (EFI_DISCONNECT_CONTROLLER)UnitTestDisconnectController, = // DisconnectController + (EFI_OPEN_PROTOCOL)UnitTestOpenProtocol, = // OpenProtocol + (EFI_CLOSE_PROTOCOL)UnitTestCloseProtocol, = // CloseProtocol + (EFI_OPEN_PROTOCOL_INFORMATION)UnitTestOpenProtocolInformation, = // OpenProtocolInformation + (EFI_PROTOCOLS_PER_HANDLE)UnitTestProtocolsPerHandle, = // ProtocolsPerHandle + (EFI_LOCATE_HANDLE_BUFFER)UnitTestLocateHandleBuffer, = // LocateHandleBuffer + (EFI_LOCATE_PROTOCOL)UnitTestLocateProtocol, = // LocateProtocol + (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)UnitTestInstallMultipleProtoco= lInterfaces, // InstallMultipleProtocolInterfaces + (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)UnitTestUninstallMultiplePro= tocolInterfaces, // UninstallMultipleProtocolInterfaces + (EFI_CALCULATE_CRC32)UnitTestCalculateCrc32, = // CalculateCrc32 + (EFI_COPY_MEM)CopyMem, = // CopyMem + (EFI_SET_MEM)SetMem, = // SetMem + (EFI_CREATE_EVENT_EX)UnitTestCreateEventEx = // CreateEventEx +}; + +EFI_BOOT_SERVICES *gBS =3D &mBootServices; + +/** + The constructor function caches the pointer of Boot Services Table. + + The constructor function caches the pointer of Boot Services Table throu= gh System Table. + It will ASSERT() if the pointer of System Table is NULL. + It will ASSERT() if the pointer of Boot Services Table is NULL. + It will always return EFI_SUCCESS. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +UnitTestUefiBootServicesTableLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + // + // Cache the Image Handle + // + gImageHandle =3D ImageHandle; + ASSERT (gImageHandle !=3D NULL); + + // + // Cache pointer to the EFI System Table + // + + // Note: The system table is not implemented + gST =3D NULL; + + // + // Cache pointer to the EFI Boot Services Table + // + gBS =3D SystemTable->BootServices; + ASSERT (gBS !=3D NULL); + + return EFI_SUCCESS; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLibEventTimer.c b/UnitTestFrameworkPkg/Library= /UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibEventTime= r.c new file mode 100644 index 000000000000..dc02c4ef9a8e --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLibEventTimer.c @@ -0,0 +1,180 @@ +/** @file + Implementation of event and timer related services in the UEFI Boot Serv= ices table for use in unit tests. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestUefiBootServicesTableLib.h" + +/** + Creates an event. + + @param Type The type of event to create and its mode = and + attributes + @param NotifyTpl The task priority level of event notifica= tions + @param NotifyFunction Pointer to the events notification functi= on + @param NotifyContext Pointer to the notification functions con= text + corresponds to parameter "Context" in the + notification function + @param Event Pointer to the newly created event if the= call + succeeds undefined otherwise + + @retval EFI_SUCCESS The event structure was created + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value + @retval EFI_OUT_OF_RESOURCES The event could not be allocated + +**/ +EFI_STATUS +EFIAPI +UnitTestCreateEvent ( + IN UINT32 Type, + IN EFI_TPL NotifyTpl, + IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL + IN VOID *NotifyContext, OPTIONAL + OUT EFI_EVENT *Event + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Sets the type of timer and the trigger time for a timer event. + + @param UserEvent The timer event that is to be signaled at= the + specified time + @param Type The type of time that is specified in + TriggerTime + @param TriggerTime The number of 100ns units until the timer + expires + + @retval EFI_SUCCESS The event has been set to be signaled at = the + requested time + @retval EFI_INVALID_PARAMETER Event or Type is not valid + +**/ +EFI_STATUS +EFIAPI +UnitTestSetTimer ( + IN EFI_EVENT UserEvent, + IN EFI_TIMER_DELAY Type, + IN UINT64 TriggerTime + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Stops execution until an event is signaled. + + @param NumberOfEvents The number of events in the UserEvents ar= ray + @param UserEvents An array of EFI_EVENT + @param UserIndex Pointer to the index of the event which + satisfied the wait condition + + @retval EFI_SUCCESS The event indicated by Index was signaled. + @retval EFI_INVALID_PARAMETER The event indicated by Index has a notifi= cation + function or Event was not a valid type + @retval EFI_UNSUPPORTED The current TPL is not TPL_APPLICATION + +**/ +EFI_STATUS +EFIAPI +UnitTestWaitForEvent ( + IN UINTN NumberOfEvents, + IN EFI_EVENT *UserEvents, + OUT UINTN *UserIndex + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Signals the event. Queues the event to be notified if needed. + + @param UserEvent The event to signal . + + @retval EFI_INVALID_PARAMETER Parameters are not valid. + @retval EFI_SUCCESS The event was signaled. + +**/ +EFI_STATUS +EFIAPI +UnitTestSignalEvent ( + IN EFI_EVENT UserEvent + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Closes an event and frees the event structure. + + @param UserEvent Event to close + + @retval EFI_INVALID_PARAMETER Parameters are not valid. + @retval EFI_SUCCESS The event has been closed + +**/ +EFI_STATUS +EFIAPI +UnitTestCloseEvent ( + IN EFI_EVENT UserEvent + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Check the status of an event. + + @param UserEvent The event to check + + @retval EFI_SUCCESS The event is in the signaled state + @retval EFI_NOT_READY The event is not in the signaled state + @retval EFI_INVALID_PARAMETER Event is of type EVT_NOTIFY_SIGNAL + +**/ +EFI_STATUS +EFIAPI +UnitTestCheckEvent ( + IN EFI_EVENT UserEvent + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Creates an event in a group. + + @param Type The type of event to create and its mode = and + attributes + @param NotifyTpl The task priority level of event notifica= tions + @param NotifyFunction Pointer to the events notification functi= on + @param NotifyContext Pointer to the notification functions con= text + corresponds to parameter "Context" in the + notification function + @param EventGroup GUID for EventGroup if NULL act the same = as + gBS->CreateEvent(). + @param Event Pointer to the newly created event if the= call + succeeds undefined otherwise + + @retval EFI_SUCCESS The event structure was created + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value + @retval EFI_OUT_OF_RESOURCES The event could not be allocated + +**/ +EFI_STATUS +EFIAPI +UnitTestCreateEventEx ( + IN UINT32 Type, + IN EFI_TPL NotifyTpl, + IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL + IN CONST VOID *NotifyContext, OPTIONAL + IN CONST EFI_GUID *EventGroup, OPTIONAL + OUT EFI_EVENT *Event + ) +{ + return EFI_NOT_AVAILABLE_YET; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLibImage.c b/UnitTestFrameworkPkg/Library/Unit= TestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibImage.c new file mode 100644 index 000000000000..144cc33e25c0 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLibImage.c @@ -0,0 +1,163 @@ +/** @file + Implementation of image related services in the UEFI Boot Services table= for use in unit tests. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestUefiBootServicesTableLib.h" + +/** + Loads an EFI image into memory and returns a handle to the image. + + @param BootPolicy If TRUE, indicates that the request orig= inates + from the boot manager, and that the boot + manager is attempting to load FilePath a= s a + boot selection. + @param ParentImageHandle The caller's image handle. + @param FilePath The specific file path from which the im= age is + loaded. + @param SourceBuffer If not NULL, a pointer to the memory loc= ation + containing a copy of the image to be loa= ded. + @param SourceSize The size in bytes of SourceBuffer. + @param ImageHandle Pointer to the returned image handle tha= t is + created when the image is successfully l= oaded. + + @retval EFI_SUCCESS The image was loaded into memory. + @retval EFI_NOT_FOUND The FilePath was not found. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid val= ue. + @retval EFI_UNSUPPORTED The image type is not supported, or the = device + path cannot be parsed to locate the prop= er + protocol for loading the file. + @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient + resources. + @retval EFI_LOAD_ERROR Image was not loaded because the image f= ormat was corrupt or not + understood. + @retval EFI_DEVICE_ERROR Image was not loaded because the device = returned a read error. + @retval EFI_ACCESS_DENIED Image was not loaded because the platfor= m policy prohibits the + image from being loaded. NULL is returne= d in *ImageHandle. + @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was = created with a + valid EFI_LOADED_IMAGE_PROTOCOL. However= , the current + platform policy specifies that the image= should not be started. + +**/ +EFI_STATUS +EFIAPI +UnitTestLoadImage ( + IN BOOLEAN BootPolicy, + IN EFI_HANDLE ParentImageHandle, + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + IN VOID *SourceBuffer OPTIONAL, + IN UINTN SourceSize, + OUT EFI_HANDLE *ImageHandle + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Transfer control to a loaded image's entry point. + + @param ImageHandle Handle of image to be started. + @param ExitDataSize Pointer of the size to ExitData + @param ExitData Pointer to a pointer to a data buffer th= at + includes a Null-terminated string, + optionally followed by additional binary= data. + The string is a description that the cal= ler may + use to further indicate the reason for t= he + image's exit. + + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate + @retval EFI_SECURITY_VIOLATION The current platform policy specifies th= at the image should not be started. + @retval EFI_SUCCESS Successfully transfer control to the ima= ge's + entry point. + +**/ +EFI_STATUS +EFIAPI +UnitTestStartImage ( + IN EFI_HANDLE ImageHandle, + OUT UINTN *ExitDataSize, + OUT CHAR16 **ExitData OPTIONAL + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Terminates the currently loaded EFI image and returns control to boot se= rvices. + + @param ImageHandle Handle that identifies the image. This + parameter is passed to the image on entr= y. + @param Status The image's exit code. + @param ExitDataSize The size, in bytes, of ExitData. Ignored= if + ExitStatus is EFI_SUCCESS. + @param ExitData Pointer to a data buffer that includes a + Null-terminated Unicode string, optional= ly + followed by additional binary data. The = string + is a description that the caller may use= to + further indicate the reason for the imag= e's + exit. + + @retval EFI_INVALID_PARAMETER Image handle is NULL or it is not current + image. + @retval EFI_SUCCESS Successfully terminates the currently lo= aded + EFI image. + @retval EFI_ACCESS_DENIED Should never reach there. + @retval EFI_OUT_OF_RESOURCES Could not allocate pool + +**/ +EFI_STATUS +EFIAPI +UnitTestExit ( + IN EFI_HANDLE ImageHandle, + IN EFI_STATUS Status, + IN UINTN ExitDataSize, + IN CHAR16 *ExitData OPTIONAL + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Unloads an image. + + @param ImageHandle Handle that identifies the image to be + unloaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_UNSUPPORTED The image has been started, and does not= support + unload. + @retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +UnitTestUnloadImage ( + IN EFI_HANDLE ImageHandle + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Terminates all boot services. + + @param ImageHandle Handle that identifies the exiting image. + @param MapKey Key to the latest memory map. + + @retval EFI_SUCCESS Boot Services terminated + @retval EFI_INVALID_PARAMETER MapKey is incorrect. + +**/ +EFI_STATUS +EFIAPI +UnitTestExitBootServices ( + IN EFI_HANDLE ImageHandle, + IN UINTN MapKey + ) +{ + return EFI_NOT_AVAILABLE_YET; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLibMemory.c b/UnitTestFrameworkPkg/Library/Uni= tTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMemory.c new file mode 100644 index 000000000000..abbb12974a55 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLibMemory.c @@ -0,0 +1,145 @@ +/** @file + Implementation of memory related services in the UEFI Boot Services tabl= e for use in unit tests. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestUefiBootServicesTableLib.h" + +/** + Allocates pages from the memory map. + + @param Type The type of allocation to perform + @param MemoryType The type of memory to turn the allocated = pages + into + @param NumberOfPages The number of pages to allocate + @param Memory A pointer to receive the base allocated m= emory + address + + @return Status. On success, Memory is filled in with the base address al= located + @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined= in + spec. + @retval EFI_NOT_FOUND Could not allocate pages match the requir= ement. + @retval EFI_OUT_OF_RESOURCES No enough pages to allocate. + @retval EFI_SUCCESS Pages successfully allocated. + +**/ +EFI_STATUS +EFIAPI +UnitTestAllocatePages ( + IN EFI_ALLOCATE_TYPE Type, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN NumberOfPages, + IN OUT EFI_PHYSICAL_ADDRESS *Memory + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Frees previous allocated pages. + + @param Memory Base address of memory being freed + @param NumberOfPages The number of pages to free + + @retval EFI_NOT_FOUND Could not find the entry that covers the = range + @retval EFI_INVALID_PARAMETER Address not aligned + @return EFI_SUCCESS -Pages successfully freed. + +**/ +EFI_STATUS +EFIAPI +UnitTestFreePages ( + IN EFI_PHYSICAL_ADDRESS Memory, + IN UINTN NumberOfPages + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + This function returns a copy of the current memory map. The map is an ar= ray of + memory descriptors, each of which describes a contiguous block of memory. + + @param MemoryMapSize A pointer to the size, in bytes, of the + MemoryMap buffer. On input, this is the s= ize of + the buffer allocated by the caller. On o= utput, + it is the size of the buffer returned by = the + firmware if the buffer was large enough,= or the + size of the buffer needed to contain the= map if + the buffer was too small. + @param MemoryMap A pointer to the buffer in which firmware= places + the current memory map. + @param MapKey A pointer to the location in which firmwa= re + returns the key for the current memory ma= p. + @param DescriptorSize A pointer to the location in which firmwa= re + returns the size, in bytes, of an individ= ual + EFI_MEMORY_DESCRIPTOR. + @param DescriptorVersion A pointer to the location in which firmwa= re + returns the version number associated wit= h the + EFI_MEMORY_DESCRIPTOR. + + @retval EFI_SUCCESS The memory map was returned in the Memory= Map + buffer. + @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The c= urrent + buffer size needed to hold the memory map= is + returned in MemoryMapSize. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. + +**/ +EFI_STATUS +EFIAPI +UnitTestGetMemoryMap ( + IN OUT UINTN *MemoryMapSize, + IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, + OUT UINTN *MapKey, + OUT UINTN *DescriptorSize, + OUT UINT32 *DescriptorVersion + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Allocate pool of a particular type. + + @param PoolType Type of pool to allocate + @param Size The amount of pool to allocate + @param Buffer The address to return a pointer to the al= located + pool + + @retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL + @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation = failed. + @retval EFI_SUCCESS Pool successfully allocated. + +**/ +EFI_STATUS +EFIAPI +UnitTestAllocatePool ( + IN EFI_MEMORY_TYPE PoolType, + IN UINTN Size, + OUT VOID **Buffer + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Frees pool. + + @param Buffer The allocated pool entry to free + + @retval EFI_INVALID_PARAMETER Buffer is not a valid value. + @retval EFI_SUCCESS Pool successfully freed. + +**/ +EFI_STATUS +EFIAPI +UnitTestFreePool ( + IN VOID *Buffer + ) +{ + return EFI_NOT_AVAILABLE_YET; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLibMisc.c b/UnitTestFrameworkPkg/Library/UnitT= estUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMisc.c new file mode 100644 index 000000000000..121496b3b994 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLibMisc.c @@ -0,0 +1,198 @@ +/** @file + Implementation of miscellaneous services in the UEFI Boot Services table= for use in unit tests. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestUefiBootServicesTableLib.h" + +/** + Returns a monotonically increasing count for the platform. + + @param[out] Count The pointer to returned value. + + @retval EFI_SUCCESS The next monotonic count was returned. + @retval EFI_INVALID_PARAMETER Count is NULL. + @retval EFI_DEVICE_ERROR The device is not functioning properly. + +**/ +EFI_STATUS +EFIAPI +UnitTestGetNextMonotonicCount ( + OUT UINT64 *Count + ) +{ + STATIC UINT64 StaticCount =3D 0; + + *Count =3D StaticCount++; + + return EFI_SUCCESS; +} + +/** + Introduces a fine-grained stall. + + @param Microseconds The number of microseconds to stall execu= tion. + + @retval EFI_SUCCESS Execution was stalled for at least the re= quested + amount of microseconds. + @retval EFI_NOT_AVAILABLE_YET gMetronome is not available yet + +**/ +EFI_STATUS +EFIAPI +UnitTestStall ( + IN UINTN Microseconds + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Sets the system's watchdog timer. + + @param Timeout The number of seconds to set the watchdog timer = to. + A value of zero disables the timer. + @param WatchdogCode The numeric code to log on a watchdog timer time= out + event. The firmware reserves codes 0x0000 to 0xF= FFF. + Loaders and operating systems may use other time= out + codes. + @param DataSize The size, in bytes, of WatchdogData. + @param WatchdogData A data buffer that includes a Null-terminated Un= icode + string, optionally followed by additional binary= data. + The string is a description that the call may us= e to + further indicate the reason to be logged with a + watchdog event. + + @return EFI_SUCCESS Timeout has been set + @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet + @return EFI_UNSUPPORTED System does not have a timer (currentl= y not used) + @return EFI_DEVICE_ERROR Could not complete due to hardware err= or + +**/ +EFI_STATUS +EFIAPI +UnitTestSetWatchdogTimer ( + IN UINTN Timeout, + IN UINT64 WatchdogCode, + IN UINTN DataSize, + IN CHAR16 *WatchdogData OPTIONAL + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Connects one or more drivers to a controller. + + @param ControllerHandle The handle of the controller to which driv= er(s) are to be connected. + @param DriverImageHandle A pointer to an ordered list handles that = support the + EFI_DRIVER_BINDING_PROTOCOL. + @param RemainingDevicePath A pointer to the device path that specifie= s a child of the + controller specified by ControllerHandle. + @param Recursive If TRUE, then ConnectController() is calle= d recursively + until the entire tree of controllers below= the controller specified + by ControllerHandle have been created. If = FALSE, then + the tree of controllers is only expanded o= ne level. + + @retval EFI_SUCCESS 1) One or more drivers were connected to C= ontrollerHandle. + 2) No drivers were connected to Controller= Handle, but + RemainingDevicePath is not NULL, and it is= an End Device + Path Node. + @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. + @retval EFI_NOT_FOUND 1) There are no EFI_DRIVER_BINDING_PROTOCO= L instances + present in the system. + 2) No drivers were connected to Controller= Handle. + @retval EFI_SECURITY_VIOLATION + The user has no permission to start UEFI d= evice drivers on the device path + associated with the ControllerHandle or sp= ecified by the RemainingDevicePath. + +**/ +EFI_STATUS +EFIAPI +UnitTestConnectController ( + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE *DriverImageHandle OPTIONAL, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL, + IN BOOLEAN Recursive + ) +{ + return EFI_SUCCESS; // Return success for now +} + +/** + Disconnects a controller from a driver + + @param ControllerHandle ControllerHandle The handl= e of + the controller from which + driver(s) are to be + disconnected. + @param DriverImageHandle DriverImageHandle The driv= er to + disconnect from Controller= Handle. + @param ChildHandle ChildHandle The handle of = the + child to destroy. + + @retval EFI_SUCCESS One or more drivers were + disconnected from the cont= roller. + @retval EFI_SUCCESS On entry, no drivers are m= anaging + ControllerHandle. + @retval EFI_SUCCESS DriverImageHandle is not N= ULL, + and on entry DriverImageHa= ndle is + not managing ControllerHan= dle. + @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. + @retval EFI_INVALID_PARAMETER DriverImageHandle is not N= ULL, + and it is not a valid EFI_= HANDLE. + @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, a= nd it + is not a valid EFI_HANDLE. + @retval EFI_OUT_OF_RESOURCES There are not enough resou= rces + available to disconnect any + drivers from ControllerHan= dle. + @retval EFI_DEVICE_ERROR The controller could not be + disconnected because of a = device + error. + +**/ +EFI_STATUS +EFIAPI +UnitTestDisconnectController ( + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE DriverImageHandle OPTIONAL, + IN EFI_HANDLE ChildHandle OPTIONAL + ) +{ + return EFI_SUCCESS; // Return success for now +} + +/** + Computes and returns a 32-bit CRC for a data buffer. + + @param[in] Data A pointer to the buffer on which the 32-bi= t CRC is to be computed. + @param[in] DataSize The number of bytes in the buffer Data. + @param[out] Crc32 The 32-bit CRC that was computed for the d= ata buffer specified by Data + and DataSize. + + @retval EFI_SUCCESS The 32-bit CRC was computed for the data b= uffer and returned in + Crc32. + @retval EFI_INVALID_PARAMETER Data is NULL. + @retval EFI_INVALID_PARAMETER Crc32 is NULL. + @retval EFI_INVALID_PARAMETER DataSize is 0. + +**/ +EFI_STATUS +EFIAPI +UnitTestCalculateCrc32 ( + IN VOID *Data, + IN UINTN DataSize, + OUT UINT32 *Crc32 + ) +{ + if ((Data =3D=3D NULL) || (Crc32 =3D=3D NULL) || (DataSize =3D=3D 0)) { + return EFI_INVALID_PARAMETER; + } + + *Crc32 =3D CalculateCrc32 (Data, DataSize); + + return EFI_SUCCESS; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLibProtocol.c b/UnitTestFrameworkPkg/Library/U= nitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.c new file mode 100644 index 000000000000..437082d516ea --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLibProtocol.c @@ -0,0 +1,1650 @@ +/** @file + Implementation of protocol related services in the UEFI Boot Services ta= ble for use in unit tests. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestUefiBootServicesTableLibProtocol.h" + +STATIC LIST_ENTRY mProtocolDatabase =3D INITIALIZE_LIST_HEAD_VARIAB= LE (mProtocolDatabase); +STATIC LIST_ENTRY gHandleList =3D INITIALIZE_LIST_HEAD_VARIAB= LE (gHandleList); +STATIC UINT64 gHandleDatabaseKey =3D 0; +STATIC UINTN mEfiLocateHandleRequest =3D 0; + +// +// Helper Functions +// + +/** + Check whether a handle is a valid EFI_HANDLE + + @param UserHandle The handle to check + + @retval EFI_INVALID_PARAMETER The handle is NULL or not a valid EFI_HAN= DLE. + @retval EFI_SUCCESS The handle is valid EFI_HANDLE. + +**/ +EFI_STATUS +UnitTestValidateHandle ( + IN EFI_HANDLE UserHandle + ) +{ + IHANDLE *Handle; + LIST_ENTRY *Link; + + if (UserHandle =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + for (Link =3D gHandleList.BackLink; Link !=3D &gHandleList; Link =3D Lin= k->BackLink) { + Handle =3D CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE); + if (Handle =3D=3D (IHANDLE *)UserHandle) { + return EFI_SUCCESS; + } + } + + return EFI_INVALID_PARAMETER; +} + +/** + Finds the protocol entry for the requested protocol. + + @param Protocol The ID of the protocol + @param Create Create a new entry if not found + + @return Protocol entry + +**/ +PROTOCOL_ENTRY * +UnitTestFindProtocolEntry ( + IN EFI_GUID *Protocol, + IN BOOLEAN Create + ) +{ + LIST_ENTRY *Link; + PROTOCOL_ENTRY *Item; + PROTOCOL_ENTRY *ProtEntry; + + // + // Search the database for the matching GUID + // + + ProtEntry =3D NULL; + for (Link =3D mProtocolDatabase.ForwardLink; + Link !=3D &mProtocolDatabase; + Link =3D Link->ForwardLink) + { + Item =3D CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATUR= E); + if (CompareGuid (&Item->ProtocolID, Protocol)) { + // + // This is the protocol entry + // + + ProtEntry =3D Item; + break; + } + } + + // + // If the protocol entry was not found and Create is TRUE, then + // allocate a new entry + // + if ((ProtEntry =3D=3D NULL) && Create) { + ProtEntry =3D AllocatePool (sizeof (PROTOCOL_ENTRY)); + + if (ProtEntry !=3D NULL) { + // + // Initialize new protocol entry structure + // + ProtEntry->Signature =3D PROTOCOL_ENTRY_SIGNATURE; + CopyGuid ((VOID *)&ProtEntry->ProtocolID, Protocol); + InitializeListHead (&ProtEntry->Protocols); + InitializeListHead (&ProtEntry->Notify); + + // + // Add it to protocol database + // + InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries); + } + } + + return ProtEntry; +} + +/** + Finds the protocol instance for the requested handle and protocol. + Note: This function doesn't do parameters checking, it's caller's respon= sibility + to pass in valid parameters. + + @param Handle The handle to search the protocol on + @param Protocol GUID of the protocol + @param Interface The interface for the protocol being sear= ched + + @return Protocol instance (NULL: Not found) + +**/ +PROTOCOL_INTERFACE * +UnitTestFindProtocolInterface ( + IN IHANDLE *Handle, + IN EFI_GUID *Protocol, + IN VOID *Interface + ) +{ + PROTOCOL_INTERFACE *Prot; + PROTOCOL_ENTRY *ProtEntry; + LIST_ENTRY *Link; + + Prot =3D NULL; + + // + // Lookup the protocol entry for this protocol ID + // + + ProtEntry =3D UnitTestFindProtocolEntry (Protocol, FALSE); + if (ProtEntry !=3D NULL) { + // + // Look at each protocol interface for any matches + // + for (Link =3D Handle->Protocols.ForwardLink; Link !=3D &Handle->Protoc= ols; Link =3D Link->ForwardLink) { + // + // If this protocol interface matches, remove it + // + Prot =3D CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGN= ATURE); + if ((Prot->Interface =3D=3D Interface) && (Prot->Protocol =3D=3D Pro= tEntry)) { + break; + } + + Prot =3D NULL; + } + } + + return Prot; +} + +/** + Signal event for every protocol in protocol entry. + + @param ProtEntry Protocol entry + +**/ +VOID +UnitTestNotifyProtocolEntry ( + IN PROTOCOL_ENTRY *ProtEntry + ) +{ + PROTOCOL_NOTIFY *ProtNotify; + LIST_ENTRY *Link; + + for (Link =3D ProtEntry->Notify.ForwardLink; Link !=3D &ProtEntry->Notif= y; Link =3D Link->ForwardLink) { + ProtNotify =3D CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNAT= URE); + UnitTestSignalEvent (ProtNotify->Event); + } +} + +/** + Routine to get the next Handle, when you are searching for all handles. + + @param Position Information about which Handle to seach f= or. + @param Interface Return the interface structure for the ma= tching + protocol. + + @return An pointer to IHANDLE if the next Position is not the end of the= list. + Otherwise,NULL is returned. + +**/ +IHANDLE * +UnitTestGetNextLocateAllHandles ( + IN OUT LOCATE_POSITION *Position, + OUT VOID **Interface + ) +{ + IHANDLE *Handle; + + // + // Next handle + // + Position->Position =3D Position->Position->ForwardLink; + + // + // If not at the end of the list, get the handle + // + Handle =3D NULL; + *Interface =3D NULL; + if (Position->Position !=3D &gHandleList) { + Handle =3D CR (Position->Position, IHANDLE, AllHandles, EFI_HANDLE_SIG= NATURE); + } + + return Handle; +} + +/** + Routine to get the next Handle, when you are searching for register prot= ocol + notifies. + + @param Position Information about which Handle to seach f= or. + @param Interface Return the interface structure for the ma= tching + protocol. + + @return An pointer to IHANDLE if the next Position is not the end of the= list. + Otherwise,NULL is returned. + +**/ +IHANDLE * +UnitTestGetNextLocateByRegisterNotify ( + IN OUT LOCATE_POSITION *Position, + OUT VOID **Interface + ) +{ + IHANDLE *Handle; + PROTOCOL_NOTIFY *ProtNotify; + PROTOCOL_INTERFACE *Prot; + LIST_ENTRY *Link; + + Handle =3D NULL; + *Interface =3D NULL; + ProtNotify =3D Position->SearchKey; + + // + // If this is the first request, get the next handle + // + if (ProtNotify !=3D NULL) { + ASSERT (ProtNotify->Signature =3D=3D PROTOCOL_NOTIFY_SIGNATURE); + Position->SearchKey =3D NULL; + + // + // If not at the end of the list, get the next handle + // + Link =3D ProtNotify->Position->ForwardLink; + if (Link !=3D &ProtNotify->Protocol->Protocols) { + Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_IN= TERFACE_SIGNATURE); + Handle =3D Prot->Handle; + *Interface =3D Prot->Interface; + } + } + + return Handle; +} + +/** + Routine to get the next Handle, when you are searching for a given proto= col. + + @param Position Information about which Handle to seach f= or. + @param Interface Return the interface structure for the ma= tching + protocol. + + @return An pointer to IHANDLE if the next Position is not the end of the= list. + Otherwise,NULL is returned. + +**/ +IHANDLE * +UnitTestGetNextLocateByProtocol ( + IN OUT LOCATE_POSITION *Position, + OUT VOID **Interface + ) +{ + IHANDLE *Handle; + LIST_ENTRY *Link; + PROTOCOL_INTERFACE *Prot; + + Handle =3D NULL; + *Interface =3D NULL; + for ( ; ;) { + // + // Next entry + // + Link =3D Position->Position->ForwardLink; + Position->Position =3D Link; + + // + // If not at the end, return the handle + // + if (Link =3D=3D &Position->ProtEntry->Protocols) { + Handle =3D NULL; + break; + } + + // + // Get the handle + // + Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTE= RFACE_SIGNATURE); + Handle =3D Prot->Handle; + *Interface =3D Prot->Interface; + + // + // If this handle has not been returned this request, then + // return it now + // + if (Handle->LocateRequest !=3D mEfiLocateHandleRequest) { + Handle->LocateRequest =3D mEfiLocateHandleRequest; + break; + } + } + + return Handle; +} + +/** + Attempts to disconnect all drivers that are using the protocol interface= being queried. + If failed, reconnect all drivers disconnected. + Note: This function doesn't do parameters checking, it's caller's respon= sibility + to pass in valid parameters. + + @param UserHandle The handle on which the protocol is insta= lled + @param Prot The protocol to disconnect drivers from + + @retval EFI_SUCCESS Drivers using the protocol interface are = all + disconnected + @retval EFI_ACCESS_DENIED Failed to disconnect one or all of the dr= ivers + +**/ +EFI_STATUS +UnitTestDisconnectControllersUsingProtocolInterface ( + IN EFI_HANDLE UserHandle, + IN PROTOCOL_INTERFACE *Prot + ) +{ + EFI_STATUS Status; + BOOLEAN ItemFound; + LIST_ENTRY *Link; + OPEN_PROTOCOL_DATA *OpenData; + + Status =3D EFI_SUCCESS; + + // + // Attempt to disconnect all drivers from this protocol interface + // + do { + ItemFound =3D FALSE; + for (Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenList; L= ink =3D Link->ForwardLink) { + OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_= SIGNATURE); + if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) !=3D 0) { + Status =3D UnitTestDisconnectController (UserHandle, OpenData->Age= ntHandle, NULL); + if (!EFI_ERROR (Status)) { + ItemFound =3D TRUE; + } + + break; + } + } + } while (ItemFound); + + if (!EFI_ERROR (Status)) { + // + // Attempt to remove BY_HANDLE_PROTOCOL and GET_PROTOCOL and TEST_PROT= OCOL Open List items + // + for (Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenList;) { + OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_= SIGNATURE); + if ((OpenData->Attributes & + (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_P= ROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) !=3D 0) + { + Link =3D RemoveEntryList (&OpenData->Link); + Prot->OpenListCount--; + FreePool (OpenData); + } else { + Link =3D Link->ForwardLink; + } + } + } + + // + // If there are errors or still has open items in the list, then reconne= ct all the drivers and return an error + // + if (EFI_ERROR (Status) || (Prot->OpenListCount > 0)) { + UnitTestConnectController (UserHandle, NULL, NULL, TRUE); + Status =3D EFI_ACCESS_DENIED; + } + + return Status; +} + +/** + Removes Protocol from the protocol list (but not the handle list). + + @param Handle The handle to remove protocol on. + @param Protocol GUID of the protocol to be moved + @param Interface The interface of the protocol + + @return Protocol Entry + +**/ +PROTOCOL_INTERFACE * +UnitTestRemoveInterfaceFromProtocol ( + IN IHANDLE *Handle, + IN EFI_GUID *Protocol, + IN VOID *Interface + ) +{ + PROTOCOL_INTERFACE *Prot; + PROTOCOL_NOTIFY *ProtNotify; + PROTOCOL_ENTRY *ProtEntry; + LIST_ENTRY *Link; + + Prot =3D UnitTestFindProtocolInterface (Handle, Protocol, Interface); + if (Prot !=3D NULL) { + ProtEntry =3D Prot->Protocol; + + // + // If there's a protocol notify location pointing to this entry, back = it up one + // + for (Link =3D ProtEntry->Notify.ForwardLink; Link !=3D &ProtEntry->Not= ify; Link =3D Link->ForwardLink) { + ProtNotify =3D CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGN= ATURE); + + if (ProtNotify->Position =3D=3D &Prot->ByProtocol) { + ProtNotify->Position =3D Prot->ByProtocol.BackLink; + } + } + + // + // Remove the protocol interface entry + // + RemoveEntryList (&Prot->ByProtocol); + } + + return Prot; +} + +// +// Boot Services Function Implementation +// + +/** + Locate a certain GUID protocol interface in a Handle's protocols. + + @param UserHandle The handle to obtain the protocol interfa= ce on + @param Protocol The GUID of the protocol + + @return The requested protocol interface for the handle + +**/ +PROTOCOL_INTERFACE * +UnitTestGetProtocolInterface ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol + ) +{ + EFI_STATUS Status; + PROTOCOL_ENTRY *ProtEntry; + PROTOCOL_INTERFACE *Prot; + IHANDLE *Handle; + LIST_ENTRY *Link; + + Status =3D UnitTestValidateHandle (UserHandle); + if (EFI_ERROR (Status)) { + return NULL; + } + + Handle =3D (IHANDLE *)UserHandle; + + // + // Look at each protocol interface for a match + // + for (Link =3D Handle->Protocols.ForwardLink; Link !=3D &Handle->Protocol= s; Link =3D Link->ForwardLink) { + Prot =3D CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_S= IGNATURE); + ProtEntry =3D Prot->Protocol; + if (CompareGuid (&ProtEntry->ProtocolID, Protocol)) { + return Prot; + } + } + + return NULL; +} + +/** + Installs a protocol interface into the boot services environment. + + @param UserHandle The handle to install the protocol handle= r on, + or NULL if a new handle is to be allocated + @param Protocol The protocol to add to the handle + @param InterfaceType Indicates whether Interface is supplied in + native form. + @param Interface The interface for the protocol being added + @param Notify indicates whether notify the notification= list + for this protocol + + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate + @retval EFI_SUCCESS Protocol interface successfully installed + +**/ +EFI_STATUS +UnitTestInstallProtocolInterfaceNotify ( + IN OUT EFI_HANDLE *UserHandle, + IN EFI_GUID *Protocol, + IN EFI_INTERFACE_TYPE InterfaceType, + IN VOID *Interface, + IN BOOLEAN Notify + ) +{ + PROTOCOL_INTERFACE *Prot; + PROTOCOL_ENTRY *ProtEntry; + IHANDLE *Handle; + EFI_STATUS Status; + VOID *ExistingInterface; + + // + // returns EFI_INVALID_PARAMETER if InterfaceType is invalid. + // Also added check for invalid UserHandle and Protocol pointers. + // + if ((UserHandle =3D=3D NULL) || (Protocol =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (InterfaceType !=3D EFI_NATIVE_INTERFACE) { + return EFI_INVALID_PARAMETER; + } + + // + // Print debug message + // + UT_LOG_INFO ("InstallProtocolInterface: %g %p\n", Protocol, Interface); + + Status =3D EFI_OUT_OF_RESOURCES; + Prot =3D NULL; + Handle =3D NULL; + + if (*UserHandle !=3D NULL) { + Status =3D UnitTestHandleProtocol (*UserHandle, Protocol, (VOID **)&Ex= istingInterface); + if (!EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + } + + // + // Lookup the Protocol Entry for the requested protocol + // + ProtEntry =3D UnitTestFindProtocolEntry (Protocol, TRUE); + if (ProtEntry =3D=3D NULL) { + goto Done; + } + + // + // Allocate a new protocol interface structure + // + Prot =3D AllocateZeroPool (sizeof (PROTOCOL_INTERFACE)); + if (Prot =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Done; + } + + // + // If caller didn't supply a handle, allocate a new one + // + Handle =3D (IHANDLE *)*UserHandle; + if (Handle =3D=3D NULL) { + Handle =3D AllocateZeroPool (sizeof (IHANDLE)); + if (Handle =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Done; + } + + // + // Initialize new handler structure + // + Handle->Signature =3D EFI_HANDLE_SIGNATURE; + InitializeListHead (&Handle->Protocols); + + // + // Initialize the Key to show that the handle has been created/modified + // + gHandleDatabaseKey++; + Handle->Key =3D gHandleDatabaseKey; + + // + // Add this handle to the list global list of all handles + // in the system + // + InsertTailList (&gHandleList, &Handle->AllHandles); + } else { + Status =3D UnitTestValidateHandle (Handle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "InstallProtocolInterface: input handle at 0x%x= is invalid\n", Handle)); + goto Done; + } + } + + // + // Each interface that is added must be unique + // + ASSERT (UnitTestFindProtocolInterface (Handle, Protocol, Interface) =3D= =3D NULL); + + // + // Initialize the protocol interface structure + // + Prot->Signature =3D PROTOCOL_INTERFACE_SIGNATURE; + Prot->Handle =3D Handle; + Prot->Protocol =3D ProtEntry; + Prot->Interface =3D Interface; + + // + // Initialize OpenProtocol Data base + // + InitializeListHead (&Prot->OpenList); + Prot->OpenListCount =3D 0; + + // + // Add this protocol interface to the head of the supported + // protocol list for this handle + // + InsertHeadList (&Handle->Protocols, &Prot->Link); + + // + // Add this protocol interface to the tail of the + // protocol entry + // + InsertTailList (&ProtEntry->Protocols, &Prot->ByProtocol); + + // + // Notify the notification list for this protocol + // + if (Notify) { + UnitTestNotifyProtocolEntry (ProtEntry); + } + + Status =3D EFI_SUCCESS; + +Done: + if (!EFI_ERROR (Status)) { + // + // Return the new handle back to the caller + // + *UserHandle =3D Handle; + } else { + // + // There was an error, clean up + // + if (Prot !=3D NULL) { + UnitTestFreePool (Prot); + } + + DEBUG ((DEBUG_ERROR, "InstallProtocolInterface: %g %p failed with %r\n= ", Protocol, Interface, Status)); + } + + return Status; +} + +/** + Wrapper function to UnitTestInstallProtocolInterfaceNotify. This is the= public API which + Calls the private one which contains a BOOLEAN parameter for notificatio= ns + + @param UserHandle The handle to install the protocol handle= r on, + or NULL if a new handle is to be allocated + @param Protocol The protocol to add to the handle + @param InterfaceType Indicates whether Interface is supplied in + native form. + @param Interface The interface for the protocol being added + + @return Status code + +**/ +EFI_STATUS +EFIAPI +UnitTestInstallProtocolInterface ( + IN OUT EFI_HANDLE *UserHandle, + IN EFI_GUID *Protocol, + IN EFI_INTERFACE_TYPE InterfaceType, + IN VOID *Interface + ) +{ + return UnitTestInstallProtocolInterfaceNotify ( + UserHandle, + Protocol, + InterfaceType, + Interface, + TRUE + ); +} + +/** + Reinstall a protocol interface on a device handle. The OldInterface for= Protocol is replaced by the NewInterface. + + @param UserHandle Handle on which the interface is to be + reinstalled + @param Protocol The numeric ID of the interface + @param OldInterface A pointer to the old interface + @param NewInterface A pointer to the new interface + + @retval EFI_SUCCESS The protocol interface was installed + @retval EFI_NOT_FOUND The OldInterface on the handle was not fo= und + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value + +**/ +EFI_STATUS +EFIAPI +UnitTestReinstallProtocolInterface ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + IN VOID *OldInterface, + IN VOID *NewInterface + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Uninstalls all instances of a protocol:interfacer from a handle. + If the last protocol interface is remove from the handle, the + handle is freed. + + @param UserHandle The handle to remove the protocol handler= from + @param Protocol The protocol, of protocol:interface, to r= emove + @param Interface The interface, of protocol:interface, to = remove + + @retval EFI_INVALID_PARAMETER Protocol is NULL. + @retval EFI_SUCCESS Protocol interface successfully uninstall= ed. + +**/ +EFI_STATUS +EFIAPI +UnitTestUninstallProtocolInterface ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + IN VOID *Interface + ) +{ + EFI_STATUS Status; + IHANDLE *Handle; + PROTOCOL_INTERFACE *Prot; + + // + // Check that Protocol is valid + // + if (Protocol =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Check that UserHandle is a valid handle + // + Status =3D UnitTestValidateHandle (UserHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Check that Protocol exists on UserHandle, and Interface matches the i= nterface in the database + // + Prot =3D UnitTestFindProtocolInterface (UserHandle, Protocol, Interface); + if (Prot =3D=3D NULL) { + Status =3D EFI_NOT_FOUND; + goto Done; + } + + // + // Attempt to disconnect all drivers that are using the protocol interfa= ce that is about to be removed + // + Status =3D UnitTestDisconnectControllersUsingProtocolInterface ( + UserHandle, + Prot + ); + if (EFI_ERROR (Status)) { + // + // One or more drivers refused to release, so return the error + // + goto Done; + } + + // + // Remove the protocol interface from the protocol + // + Status =3D EFI_NOT_FOUND; + Handle =3D (IHANDLE *)UserHandle; + Prot =3D UnitTestRemoveInterfaceFromProtocol (Handle, Protocol, Interf= ace); + + if (Prot !=3D NULL) { + // + // Update the Key to show that the handle has been created/modified + // + gHandleDatabaseKey++; + Handle->Key =3D gHandleDatabaseKey; + + // + // Remove the protocol interface from the handle + // + RemoveEntryList (&Prot->Link); + + // + // Free the memory + // + Prot->Signature =3D 0; + FreePool (Prot); + Status =3D EFI_SUCCESS; + } + + // + // If there are no more handlers for the handle, free the handle + // + if (IsListEmpty (&Handle->Protocols)) { + Handle->Signature =3D 0; + RemoveEntryList (&Handle->AllHandles); + FreePool (Handle); + } + +Done: + return Status; +} + +/** + Queries a handle to determine if it supports a specified protocol. + + @param UserHandle The handle being queried. + @param Protocol The published unique identifier of the pr= otocol. + @param Interface Supplies the address where a pointer to t= he + corresponding Protocol Interface is retur= ned. + + @return The requested protocol interface for the handle + +**/ +EFI_STATUS +EFIAPI +UnitTestHandleProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT VOID **Interface + ) +{ + return UnitTestOpenProtocol ( + UserHandle, + Protocol, + Interface, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); +} + +/** + Add a new protocol notification record for the request protocol. + + @param Protocol The requested protocol to add the notify + registration + @param Event The event to signal + @param Registration Returns the registration record + + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_SUCCESS Successfully returned the registration re= cord + that has been added + +**/ +EFI_STATUS +EFIAPI +UnitTestRegisterProtocolNotify ( + IN EFI_GUID *Protocol, + IN EFI_EVENT Event, + OUT VOID **Registration + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Locates the requested handle(s) and returns them in Buffer. + + @param SearchType The type of search to perform to locate t= he + handles + @param Protocol The protocol to search for + @param SearchKey Dependant on SearchType + @param BufferSize On input the size of Buffer. On output t= he + size of data returned. + @param Buffer The buffer to return the results in + + @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is + returned in BufferSize. + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_SUCCESS Successfully found the requested handle(s= ) and + returns them in Buffer. + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateHandle ( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *BufferSize, + OUT EFI_HANDLE *Buffer + ) +{ + EFI_STATUS Status; + LOCATE_POSITION Position; + PROTOCOL_NOTIFY *ProtNotify; + UNIT_TEST_GET_NEXT GetNext; + UINTN ResultSize; + IHANDLE *Handle; + IHANDLE **ResultBuffer; + VOID *Interface; + + if (BufferSize =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if ((*BufferSize > 0) && (Buffer =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + GetNext =3D NULL; + + // + // Set initial position + // + Position.Protocol =3D Protocol; + Position.SearchKey =3D SearchKey; + Position.Position =3D &gHandleList; + + ResultSize =3D 0; + ResultBuffer =3D (IHANDLE **)Buffer; + Status =3D EFI_SUCCESS; + + // + // Get the search function based on type + // + switch (SearchType) { + case AllHandles: + GetNext =3D UnitTestGetNextLocateAllHandles; + break; + + case ByRegisterNotify: + // + // Must have SearchKey for locate ByRegisterNotify + // + if (SearchKey =3D=3D NULL) { + Status =3D EFI_INVALID_PARAMETER; + break; + } + + GetNext =3D UnitTestGetNextLocateByRegisterNotify; + break; + + case ByProtocol: + GetNext =3D UnitTestGetNextLocateByProtocol; + if (Protocol =3D=3D NULL) { + Status =3D EFI_INVALID_PARAMETER; + break; + } + + // + // Look up the protocol entry and set the head pointer + // + Position.ProtEntry =3D UnitTestFindProtocolEntry (Protocol, FALSE); + if (Position.ProtEntry =3D=3D NULL) { + Status =3D EFI_NOT_FOUND; + break; + } + + Position.Position =3D &Position.ProtEntry->Protocols; + break; + + default: + Status =3D EFI_INVALID_PARAMETER; + break; + } + + if (EFI_ERROR (Status)) { + return Status; + } + + ASSERT (GetNext !=3D NULL); + // + // Enumerate out the matching handles + // + mEfiLocateHandleRequest +=3D 1; + for ( ; ;) { + // + // Get the next handle. If no more handles, stop + // + Handle =3D GetNext (&Position, &Interface); + if (NULL =3D=3D Handle) { + break; + } + + // + // Increase the resulting buffer size, and if this handle + // fits return it + // + ResultSize +=3D sizeof (Handle); + if (ResultSize <=3D *BufferSize) { + *ResultBuffer =3D Handle; + ResultBuffer +=3D 1; + } + } + + // + // If the result is a zero length buffer, then there were no + // matching handles + // + if (ResultSize =3D=3D 0) { + Status =3D EFI_NOT_FOUND; + } else { + // + // Return the resulting buffer size. If it's larger than what + // was passed, then set the error code + // + if (ResultSize > *BufferSize) { + Status =3D EFI_BUFFER_TOO_SMALL; + } + + *BufferSize =3D ResultSize; + + if ((SearchType =3D=3D ByRegisterNotify) && !EFI_ERROR (Status)) { + // + // If this is a search by register notify and a handle was + // returned, update the register notification position + // + ASSERT (SearchKey !=3D NULL); + ProtNotify =3D SearchKey; + ProtNotify->Position =3D ProtNotify->Position->ForwardLink; + } + } + + return Status; +} + +/** + Locates the handle to a device on the device path that best matches the = specified protocol. + + @param Protocol The protocol to search for. + @param DevicePath On input, a pointer to a pointer to the d= evice + path. On output, the device path pointer = is + modified to point to the remaining part o= f the + devicepath. + @param Device A pointer to the returned device handle. + + @retval EFI_SUCCESS The resulting handle was returned. + @retval EFI_NOT_FOUND No handles matched the search. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateDevicePath ( + IN EFI_GUID *Protocol, + IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, + OUT EFI_HANDLE *Device + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Boot Service called to add, modify, or remove a system configuration tab= le from + the EFI System Table. + + @param Guid Pointer to the GUID for the entry to add, update,= or + remove + @param Table Pointer to the configuration table for the entry = to add, + update, or remove, may be NULL. + + @return EFI_SUCCESS Guid, Table pair added, updated, or re= moved. + @return EFI_INVALID_PARAMETER Input GUID not valid. + @return EFI_NOT_FOUND Attempted to delete non-existant entry + @return EFI_OUT_OF_RESOURCES Not enough memory available + +**/ +EFI_STATUS +EFIAPI +UnitTestInstallConfigurationTable ( + IN EFI_GUID *Guid, + IN VOID *Table + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Locates the installed protocol handler for the handle, and + invokes it to obtain the protocol interface. Usage information + is registered in the protocol data base. + + @param UserHandle The handle to obtain the protocol interfa= ce on + @param Protocol The ID of the protocol + @param Interface The location to return the protocol inter= face + @param ImageHandle The handle of the Image that is opening t= he + protocol interface specified by Protocol = and + Interface. + @param ControllerHandle The controller handle that is requiring t= his + interface. + @param Attributes The open mode of the protocol interface + specified by Handle and Protocol. + + @retval EFI_INVALID_PARAMETER Protocol is NULL. + @retval EFI_SUCCESS Get the protocol interface. + +**/ +EFI_STATUS +EFIAPI +UnitTestOpenProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT VOID **Interface OPTIONAL, + IN EFI_HANDLE ImageHandle, + IN EFI_HANDLE ControllerHandle, + IN UINT32 Attributes + ) +{ + EFI_STATUS Status; + PROTOCOL_INTERFACE *Prot; + LIST_ENTRY *Link; + OPEN_PROTOCOL_DATA *OpenData; + BOOLEAN ByDriver; + BOOLEAN Exclusive; + BOOLEAN Disconnect; + BOOLEAN ExactMatch; + + // + // Check for invalid Protocol + // + if (Protocol =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Check for invalid Interface + // + if ((Attributes !=3D EFI_OPEN_PROTOCOL_TEST_PROTOCOL) && (Interface =3D= =3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + // + // Check for invalid UserHandle + // + Status =3D UnitTestValidateHandle (UserHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Check for invalid Attributes + // + switch (Attributes) { + case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: + Status =3D UnitTestValidateHandle (ImageHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D UnitTestValidateHandle (ControllerHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + if (UserHandle =3D=3D ControllerHandle) { + return EFI_INVALID_PARAMETER; + } + + break; + case EFI_OPEN_PROTOCOL_BY_DRIVER: + case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: + Status =3D UnitTestValidateHandle (ImageHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D UnitTestValidateHandle (ControllerHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + break; + case EFI_OPEN_PROTOCOL_EXCLUSIVE: + Status =3D UnitTestValidateHandle (ImageHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + break; + case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: + case EFI_OPEN_PROTOCOL_GET_PROTOCOL: + case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: + break; + default: + return EFI_INVALID_PARAMETER; + } + + // + // Look at each protocol interface for a match + // + Prot =3D UnitTestGetProtocolInterface (UserHandle, Protocol); + if (Prot =3D=3D NULL) { + Status =3D EFI_UNSUPPORTED; + goto Done; + } + + Status =3D EFI_SUCCESS; + + ByDriver =3D FALSE; + Exclusive =3D FALSE; + for ( Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenList; Li= nk =3D Link->ForwardLink) { + OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_= SIGNATURE); + ExactMatch =3D (BOOLEAN)((OpenData->AgentHandle =3D=3D ImageHandle) && + (OpenData->Attributes =3D=3D Attributes) && + (OpenData->ControllerHandle =3D=3D ControllerH= andle)); + if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) !=3D 0) { + ByDriver =3D TRUE; + if (ExactMatch) { + Status =3D EFI_ALREADY_STARTED; + goto Done; + } + } + + if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) !=3D 0) { + Exclusive =3D TRUE; + } else if (ExactMatch) { + OpenData->OpenCount++; + Status =3D EFI_SUCCESS; + goto Done; + } + } + + // + // ByDriver TRUE -> A driver is managing (UserHandle, Protocol) + // ByDriver FALSE -> There are no drivers managing (UserHandle, Protoco= l) + // Exclusive TRUE -> Something has exclusive access to (UserHandle, Pro= tocol) + // Exclusive FALSE -> Nothing has exclusive access to (UserHandle, Proto= col) + // + + switch (Attributes) { + case EFI_OPEN_PROTOCOL_BY_DRIVER: + if (Exclusive || ByDriver) { + Status =3D EFI_ACCESS_DENIED; + goto Done; + } + + break; + case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: + case EFI_OPEN_PROTOCOL_EXCLUSIVE: + if (Exclusive) { + Status =3D EFI_ACCESS_DENIED; + goto Done; + } + + if (ByDriver) { + do { + Disconnect =3D FALSE; + for (Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenL= ist; Link =3D Link->ForwardLink) { + OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL= _DATA_SIGNATURE); + if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) !=3D = 0) { + Disconnect =3D TRUE; + Status =3D UnitTestDisconnectController (UserHandle, Ope= nData->AgentHandle, NULL); + if (EFI_ERROR (Status)) { + Status =3D EFI_ACCESS_DENIED; + goto Done; + } else { + break; + } + } + } + } while (Disconnect); + } + + break; + case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: + case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: + case EFI_OPEN_PROTOCOL_GET_PROTOCOL: + case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: + break; + } + + if (ImageHandle =3D=3D NULL) { + Status =3D EFI_SUCCESS; + goto Done; + } + + // + // Create new entry + // + OpenData =3D AllocatePool (sizeof (OPEN_PROTOCOL_DATA)); + if (OpenData =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + } else { + OpenData->Signature =3D OPEN_PROTOCOL_DATA_SIGNATURE; + OpenData->AgentHandle =3D ImageHandle; + OpenData->ControllerHandle =3D ControllerHandle; + OpenData->Attributes =3D Attributes; + OpenData->OpenCount =3D 1; + InsertTailList (&Prot->OpenList, &OpenData->Link); + Prot->OpenListCount++; + Status =3D EFI_SUCCESS; + } + +Done: + + if (Attributes !=3D EFI_OPEN_PROTOCOL_TEST_PROTOCOL) { + // + // Keep Interface unmodified in case of any Error + // except EFI_ALREADY_STARTED and EFI_UNSUPPORTED. + // + if (!EFI_ERROR (Status) || (Status =3D=3D EFI_ALREADY_STARTED)) { + // + // According to above logic, if 'Prot' is NULL, then the 'Status' mu= st be + // EFI_UNSUPPORTED. Here the 'Status' is not EFI_UNSUPPORTED, so 'Pr= ot' + // must be not NULL. + // + // The ASSERT here is for addressing a false positive NULL pointer + // dereference issue raised from static analysis. + // + ASSERT (Prot !=3D NULL); + // + // EFI_ALREADY_STARTED is not an error for bus driver. + // Return the corresponding protocol interface. + // + *Interface =3D Prot->Interface; + } else if (Status =3D=3D EFI_UNSUPPORTED) { + // + // Return NULL Interface if Unsupported Protocol. + // + *Interface =3D NULL; + } + } + + return Status; +} + +/** + Closes a protocol on a handle that was opened using OpenProtocol(). + + @param UserHandle The handle for the protocol interface tha= t was + previously opened with OpenProtocol(), an= d is + now being closed. + @param Protocol The published unique identifier of the pr= otocol. + It is the caller's responsibility to pass= in a + valid GUID. + @param AgentHandle The handle of the agent that is closing t= he + protocol interface. + @param ControllerHandle If the agent that opened a protocol is a = driver + that follows the EFI Driver Model, then t= his + parameter is the controller handle that r= equired + the protocol interface. If the agent does= not + follow the EFI Driver Model, then this pa= rameter + is optional and may be NULL. + + @retval EFI_SUCCESS The protocol instance was closed. + @retval EFI_INVALID_PARAMETER Handle, AgentHandle or ControllerHandle i= s not a + valid EFI_HANDLE. + @retval EFI_NOT_FOUND Can not find the specified protocol or + AgentHandle. + +**/ +EFI_STATUS +EFIAPI +UnitTestCloseProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + IN EFI_HANDLE AgentHandle, + IN EFI_HANDLE ControllerHandle + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Return information about Opened protocols in the system + + @param UserHandle The handle to close the protocol interfac= e on + @param Protocol The ID of the protocol + @param EntryBuffer A pointer to a buffer of open protocol + information in the form of + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY struc= tures. + @param EntryCount Number of EntryBuffer entries + +**/ +EFI_STATUS +EFIAPI +UnitTestOpenProtocolInformation ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, + OUT UINTN *EntryCount + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Retrieves the list of protocol interface GUIDs that are installed on a h= andle in a buffer allocated + from pool. + + @param UserHandle The handle from which to retrieve the lis= t of + protocol interface GUIDs. + @param ProtocolBuffer A pointer to the list of protocol interfa= ce GUID + pointers that are installed on Handle. + @param ProtocolBufferCount A pointer to the number of GUID pointers = present + in ProtocolBuffer. + + @retval EFI_SUCCESS The list of protocol interface GUIDs inst= alled + on Handle was returned in ProtocolBuffer.= The + number of protocol interface GUIDs was re= turned + in ProtocolBufferCount. + @retval EFI_INVALID_PARAMETER Handle is NULL. + @retval EFI_INVALID_PARAMETER Handle is not a valid EFI_HANDLE. + @retval EFI_INVALID_PARAMETER ProtocolBuffer is NULL. + @retval EFI_INVALID_PARAMETER ProtocolBufferCount is NULL. + @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the + results. + +**/ +EFI_STATUS +EFIAPI +UnitTestProtocolsPerHandle ( + IN EFI_HANDLE UserHandle, + OUT EFI_GUID ***ProtocolBuffer, + OUT UINTN *ProtocolBufferCount + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Function returns an array of handles that support the requested protocol + in a buffer allocated from pool. This is a version of UnitTestLocateHand= le() + that allocates a buffer for the caller. + + @param SearchType Specifies which handle(s) are to be retur= ned. + @param Protocol Provides the protocol to search by. Th= is + parameter is only valid for SearchType + ByProtocol. + @param SearchKey Supplies the search key depending on the + SearchType. + @param NumberHandles The number of handles returned in Buffer. + @param Buffer A pointer to the buffer to return the req= uested + array of handles that support Protocol. + + @retval EFI_SUCCESS The result array of handles was returned. + @retval EFI_NOT_FOUND No handles match the search. + @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the + matching results. + @retval EFI_INVALID_PARAMETER One or more parameters are not valid. + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateHandleBuffer ( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *NumberHandles, + OUT EFI_HANDLE **Buffer + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + + if (NumberHandles =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + BufferSize =3D 0; + *NumberHandles =3D 0; + *Buffer =3D NULL; + Status =3D UnitTestLocateHandle ( + SearchType, + Protocol, + SearchKey, + &BufferSize, + *Buffer + ); + // + // LocateHandleBuffer() returns incorrect status code if SearchType is + // invalid. + // + // Add code to correctly handle expected errors from UnitTestLocateHandl= e(). + // + if (EFI_ERROR (Status) && (Status !=3D EFI_BUFFER_TOO_SMALL)) { + if (Status !=3D EFI_INVALID_PARAMETER) { + Status =3D EFI_NOT_FOUND; + } + + return Status; + } + + *Buffer =3D AllocatePool (BufferSize); + if (*Buffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status =3D UnitTestLocateHandle ( + SearchType, + Protocol, + SearchKey, + &BufferSize, + *Buffer + ); + + *NumberHandles =3D BufferSize / sizeof (EFI_HANDLE); + if (EFI_ERROR (Status)) { + *NumberHandles =3D 0; + } + + return Status; +} + +/** + Return the first Protocol Interface that matches the Protocol GUID. If + Registration is passed in, return a Protocol Instance that was just add + to the system. If Registration is NULL return the first Protocol Interfa= ce + you find. + + @param Protocol The protocol to search for + @param Registration Optional Registration Key returned from + RegisterProtocolNotify() + @param Interface Return the Protocol interface (instance). + + @retval EFI_SUCCESS If a valid Interface is returned + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_NOT_FOUND Protocol interface not found + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateProtocol ( + IN EFI_GUID *Protocol, + IN VOID *Registration OPTIONAL, + OUT VOID **Interface + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Installs a list of protocol interface into the boot services environment. + This function calls InstallProtocolInterface() in a loop. If any error + occurs all the protocols added by this function are removed. This is + basically a lib function to save space. + + @param Handle The handle to install the protocol handle= rs on, + or NULL if a new handle is to be allocated + @param ... EFI_GUID followed by protocol instance. A= NULL + terminates the list. The pairs are the + arguments to InstallProtocolInterface(). = All the + protocols are added to Handle. + + @retval EFI_SUCCESS All the protocol interface was installed. + @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to in= stall all the protocols. + @retval EFI_ALREADY_STARTED A Device Path Protocol instance was passe= d in that is already present in + the handle database. + @retval EFI_INVALID_PARAMETER Handle is NULL. + @retval EFI_INVALID_PARAMETER Protocol is already installed on the hand= le specified by Handle. + +**/ +EFI_STATUS +EFIAPI +UnitTestInstallMultipleProtocolInterfaces ( + IN OUT EFI_HANDLE *Handle, + ... + ) +{ + return EFI_NOT_AVAILABLE_YET; +} + +/** + Uninstalls a list of protocol interface in the boot services environment. + This function calls UninstallProtocolInterface() in a loop. This is + basically a lib function to save space. + + @param Handle The handle to uninstall the protocol + @param ... EFI_GUID followed by protocol instance. A= NULL + terminates the list. The pairs are the + arguments to UninstallProtocolInterface()= . All + the protocols are added to Handle. + + @return Status code + +**/ +EFI_STATUS +EFIAPI +UnitTestUninstallMultipleProtocolInterfaces ( + IN EFI_HANDLE Handle, + ... + ) +{ + EFI_STATUS Status; + VA_LIST Args; + EFI_GUID *Protocol; + VOID *Interface; + UINTN Index; + + VA_START (Args, Handle); + for (Index =3D 0, Status =3D EFI_SUCCESS; !EFI_ERROR (Status); Index++) { + // + // If protocol is NULL, then it's the end of the list + // + Protocol =3D VA_ARG (Args, EFI_GUID *); + if (Protocol =3D=3D NULL) { + break; + } + + Interface =3D VA_ARG (Args, VOID *); + + // + // Uninstall it + // + Status =3D UnitTestUninstallProtocolInterface (Handle, Protocol, Inter= face); + } + + VA_END (Args); + + // + // If there was an error, add all the interfaces that were + // uninstalled without any errors + // + if (EFI_ERROR (Status)) { + // + // Reset the va_arg back to the first argument. + // + VA_START (Args, Handle); + for ( ; Index > 1; Index--) { + Protocol =3D VA_ARG (Args, EFI_GUID *); + Interface =3D VA_ARG (Args, VOID *); + UnitTestInstallProtocolInterface (&Handle, Protocol, EFI_NATIVE_INTE= RFACE, Interface); + } + + VA_END (Args); + Status =3D EFI_INVALID_PARAMETER; + } + + return Status; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLibTpl.c b/UnitTestFrameworkPkg/Library/UnitTe= stUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibTpl.c new file mode 100644 index 000000000000..2837a463aa14 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLibTpl.c @@ -0,0 +1,43 @@ +/** @file + Implementation of Task Priority Level (TPL) related services in the UEFI= Boot Services table for use in unit tests. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "UnitTestUefiBootServicesTableLib.h" + +/** + Raise the task priority level to the new level. + High level is implemented by disabling processor interrupts. + + @param NewTpl New task priority level + + @return The previous task priority level + +**/ +EFI_TPL +EFIAPI +UnitTestRaiseTpl ( + IN EFI_TPL NewTpl + ) +{ + return TPL_APPLICATION; +} + +/** + Lowers the task priority to the previous value. If the new + priority unmasks events at a higher priority, they are dispatched. + + @param NewTpl New, lower, task priority + +**/ +VOID +EFIAPI +UnitTestRestoreTpl ( + IN EFI_TPL NewTpl + ) +{ + return; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLib.h b/UnitTestFrameworkPkg/Library/UnitTestU= efiBootServicesTableLib/UnitTestUefiBootServicesTableLib.h new file mode 100644 index 000000000000..82853bb61a1c --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLib.h @@ -0,0 +1,1042 @@ +/** @file + An internal header file for the Unit Test instance of the UEFI Boot Serv= ices Table Library. + + This file includes common header files, defines internal structure and f= unctions used by + the library implementation. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_H_ +#define UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include + +/** + Raise the task priority level to the new level. + High level is implemented by disabling processor interrupts. + + @param NewTpl New task priority level + + @return The previous task priority level + +**/ +EFI_TPL +EFIAPI +UnitTestRaiseTpl ( + IN EFI_TPL NewTpl + ); + +/** + Lowers the task priority to the previous value. If the new + priority unmasks events at a higher priority, they are dispatched. + + @param NewTpl New, lower, task priority + +**/ +VOID +EFIAPI +UnitTestRestoreTpl ( + IN EFI_TPL NewTpl + ); + +/** + Allocates pages from the memory map. + + @param Type The type of allocation to perform + @param MemoryType The type of memory to turn the allocated = pages + into + @param NumberOfPages The number of pages to allocate + @param Memory A pointer to receive the base allocated m= emory + address + + @return Status. On success, Memory is filled in with the base address al= located + @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined= in + spec. + @retval EFI_NOT_FOUND Could not allocate pages match the requir= ement. + @retval EFI_OUT_OF_RESOURCES No enough pages to allocate. + @retval EFI_SUCCESS Pages successfully allocated. + +**/ +EFI_STATUS +EFIAPI +UnitTestAllocatePages ( + IN EFI_ALLOCATE_TYPE Type, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN NumberOfPages, + IN OUT EFI_PHYSICAL_ADDRESS *Memory + ); + +/** + Frees previous allocated pages. + + @param Memory Base address of memory being freed + @param NumberOfPages The number of pages to free + + @retval EFI_NOT_FOUND Could not find the entry that covers the = range + @retval EFI_INVALID_PARAMETER Address not aligned + @return EFI_SUCCESS -Pages successfully freed. + +**/ +EFI_STATUS +EFIAPI +UnitTestFreePages ( + IN EFI_PHYSICAL_ADDRESS Memory, + IN UINTN NumberOfPages + ); + +/** + This function returns a copy of the current memory map. The map is an ar= ray of + memory descriptors, each of which describes a contiguous block of memory. + + @param MemoryMapSize A pointer to the size, in bytes, of the + MemoryMap buffer. On input, this is the s= ize of + the buffer allocated by the caller. On o= utput, + it is the size of the buffer returned by = the + firmware if the buffer was large enough,= or the + size of the buffer needed to contain the= map if + the buffer was too small. + @param MemoryMap A pointer to the buffer in which firmware= places + the current memory map. + @param MapKey A pointer to the location in which firmwa= re + returns the key for the current memory ma= p. + @param DescriptorSize A pointer to the location in which firmwa= re + returns the size, in bytes, of an individ= ual + EFI_MEMORY_DESCRIPTOR. + @param DescriptorVersion A pointer to the location in which firmwa= re + returns the version number associated wit= h the + EFI_MEMORY_DESCRIPTOR. + + @retval EFI_SUCCESS The memory map was returned in the Memory= Map + buffer. + @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The c= urrent + buffer size needed to hold the memory map= is + returned in MemoryMapSize. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. + +**/ +EFI_STATUS +EFIAPI +UnitTestGetMemoryMap ( + IN OUT UINTN *MemoryMapSize, + IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, + OUT UINTN *MapKey, + OUT UINTN *DescriptorSize, + OUT UINT32 *DescriptorVersion + ); + +/** + Allocate pool of a particular type. + + @param PoolType Type of pool to allocate + @param Size The amount of pool to allocate + @param Buffer The address to return a pointer to the al= located + pool + + @retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL + @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation = failed. + @retval EFI_SUCCESS Pool successfully allocated. + +**/ +EFI_STATUS +EFIAPI +UnitTestAllocatePool ( + IN EFI_MEMORY_TYPE PoolType, + IN UINTN Size, + OUT VOID **Buffer + ); + +/** + Frees pool. + + @param Buffer The allocated pool entry to free + + @retval EFI_INVALID_PARAMETER Buffer is not a valid value. + @retval EFI_SUCCESS Pool successfully freed. + +**/ +EFI_STATUS +EFIAPI +UnitTestFreePool ( + IN VOID *Buffer + ); + +/** + Frees pool. + + @param Buffer The allocated pool entry to free + @param PoolType Pointer to pool type + + @retval EFI_INVALID_PARAMETER Buffer is not a valid value. + @retval EFI_SUCCESS Pool successfully freed. + +**/ +EFI_STATUS +EFIAPI +UnitTestInternalFreePool ( + IN VOID *Buffer, + OUT EFI_MEMORY_TYPE *PoolType OPTIONAL + ); + +/** + Creates an event. + + @param Type The type of event to create and its mode = and + attributes + @param NotifyTpl The task priority level of event notifica= tions + @param NotifyFunction Pointer to the events notification functi= on + @param NotifyContext Pointer to the notification functions con= text; + corresponds to parameter "Context" in the + notification function + @param Event Pointer to the newly created event if the= call + succeeds; undefined otherwise + + @retval EFI_SUCCESS The event structure was created + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value + @retval EFI_OUT_OF_RESOURCES The event could not be allocated + +**/ +EFI_STATUS +EFIAPI +UnitTestCreateEvent ( + IN UINT32 Type, + IN EFI_TPL NotifyTpl, + IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL + IN VOID *NotifyContext, OPTIONAL + OUT EFI_EVENT *Event + ); + +/** + Sets the type of timer and the trigger time for a timer event. + + @param UserEvent The timer event that is to be signaled at= the + specified time + @param Type The type of time that is specified in + TriggerTime + @param TriggerTime The number of 100ns units until the timer + expires + + @retval EFI_SUCCESS The event has been set to be signaled at = the + requested time + @retval EFI_INVALID_PARAMETER Event or Type is not valid + +**/ +EFI_STATUS +EFIAPI +UnitTestSetTimer ( + IN EFI_EVENT UserEvent, + IN EFI_TIMER_DELAY Type, + IN UINT64 TriggerTime + ); + +/** + Stops execution until an event is signaled. + + @param NumberOfEvents The number of events in the UserEvents ar= ray + @param UserEvents An array of EFI_EVENT + @param UserIndex Pointer to the index of the event which + satisfied the wait condition + + @retval EFI_SUCCESS The event indicated by Index was signaled. + @retval EFI_INVALID_PARAMETER The event indicated by Index has a notifi= cation + function or Event was not a valid type + @retval EFI_UNSUPPORTED The current TPL is not TPL_APPLICATION + +**/ +EFI_STATUS +EFIAPI +UnitTestWaitForEvent ( + IN UINTN NumberOfEvents, + IN EFI_EVENT *UserEvents, + OUT UINTN *UserIndex + ); + +/** + Signals the event. Queues the event to be notified if needed. + + @param UserEvent The event to signal . + + @retval EFI_INVALID_PARAMETER Parameters are not valid. + @retval EFI_SUCCESS The event was signaled. + +**/ +EFI_STATUS +EFIAPI +UnitTestSignalEvent ( + IN EFI_EVENT UserEvent + ); + +/** + Closes an event and frees the event structure. + + @param UserEvent Event to close + + @retval EFI_INVALID_PARAMETER Parameters are not valid. + @retval EFI_SUCCESS The event has been closed + +**/ +EFI_STATUS +EFIAPI +UnitTestCloseEvent ( + IN EFI_EVENT UserEvent + ); + +/** + Check the status of an event. + + @param UserEvent The event to check + + @retval EFI_SUCCESS The event is in the signaled state + @retval EFI_NOT_READY The event is not in the signaled state + @retval EFI_INVALID_PARAMETER Event is of type EVT_NOTIFY_SIGNAL + +**/ +EFI_STATUS +EFIAPI +UnitTestCheckEvent ( + IN EFI_EVENT UserEvent + ); + +/** + Wrapper function to UnitTestInstallProtocolInterfaceNotify. This is the= public API which + Calls the private one which contains a BOOLEAN parameter for notificatio= ns + + @param UserHandle The handle to install the protocol handle= r on, + or NULL if a new handle is to be allocated + @param Protocol The protocol to add to the handle + @param InterfaceType Indicates whether Interface is supplied in + native form. + @param Interface The interface for the protocol being added + + @return Status code + +**/ +EFI_STATUS +EFIAPI +UnitTestInstallProtocolInterface ( + IN OUT EFI_HANDLE *UserHandle, + IN EFI_GUID *Protocol, + IN EFI_INTERFACE_TYPE InterfaceType, + IN VOID *Interface + ); + +/** + Reinstall a protocol interface on a device handle. The OldInterface for= Protocol is replaced by the NewInterface. + + @param UserHandle Handle on which the interface is to be + reinstalled + @param Protocol The numeric ID of the interface + @param OldInterface A pointer to the old interface + @param NewInterface A pointer to the new interface + + @retval EFI_SUCCESS The protocol interface was installed + @retval EFI_NOT_FOUND The OldInterface on the handle was not fo= und + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value + +**/ +EFI_STATUS +EFIAPI +UnitTestReinstallProtocolInterface ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + IN VOID *OldInterface, + IN VOID *NewInterface + ); + +/** + Uninstalls all instances of a protocol:interfacer from a handle. + If the last protocol interface is remove from the handle, the + handle is freed. + + @param UserHandle The handle to remove the protocol handler= from + @param Protocol The protocol, of protocol:interface, to r= emove + @param Interface The interface, of protocol:interface, to = remove + + @retval EFI_INVALID_PARAMETER Protocol is NULL. + @retval EFI_SUCCESS Protocol interface successfully uninstall= ed. + +**/ +EFI_STATUS +EFIAPI +UnitTestUninstallProtocolInterface ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + IN VOID *Interface + ); + +/** + Queries a handle to determine if it supports a specified protocol. + + @param UserHandle The handle being queried. + @param Protocol The published unique identifier of the pr= otocol. + @param Interface Supplies the address where a pointer to t= he + corresponding Protocol Interface is retur= ned. + + @return The requested protocol interface for the handle + +**/ +EFI_STATUS +EFIAPI +UnitTestHandleProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT VOID **Interface + ); + +/** + Add a new protocol notification record for the request protocol. + + @param Protocol The requested protocol to add the notify + registration + @param Event The event to signal + @param Registration Returns the registration record + + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_SUCCESS Successfully returned the registration re= cord + that has been added + +**/ +EFI_STATUS +EFIAPI +UnitTestRegisterProtocolNotify ( + IN EFI_GUID *Protocol, + IN EFI_EVENT Event, + OUT VOID **Registration + ); + +/** + Locates the requested handle(s) and returns them in Buffer. + + @param SearchType The type of search to perform to locate t= he + handles + @param Protocol The protocol to search for + @param SearchKey Dependant on SearchType + @param BufferSize On input the size of Buffer. On output t= he + size of data returned. + @param Buffer The buffer to return the results in + + @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is + returned in BufferSize. + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_SUCCESS Successfully found the requested handle(s= ) and + returns them in Buffer. + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateHandle ( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *BufferSize, + OUT EFI_HANDLE *Buffer + ); + +/** + Locates the handle to a device on the device path that best matches the = specified protocol. + + @param Protocol The protocol to search for. + @param DevicePath On input, a pointer to a pointer to the d= evice + path. On output, the device path pointer = is + modified to point to the remaining part o= f the + devicepath. + @param Device A pointer to the returned device handle. + + @retval EFI_SUCCESS The resulting handle was returned. + @retval EFI_NOT_FOUND No handles matched the search. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateDevicePath ( + IN EFI_GUID *Protocol, + IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, + OUT EFI_HANDLE *Device + ); + +/** + Boot Service called to add, modify, or remove a system configuration tab= le from + the EFI System Table. + + @param Guid Pointer to the GUID for the entry to add, update,= or + remove + @param Table Pointer to the configuration table for the entry = to add, + update, or remove, may be NULL. + + @return EFI_SUCCESS Guid, Table pair added, updated, or re= moved. + @return EFI_INVALID_PARAMETER Input GUID not valid. + @return EFI_NOT_FOUND Attempted to delete non-existant entry + @return EFI_OUT_OF_RESOURCES Not enough memory available + +**/ +EFI_STATUS +EFIAPI +UnitTestInstallConfigurationTable ( + IN EFI_GUID *Guid, + IN VOID *Table + ); + +/** + Loads an EFI image into memory and returns a handle to the image. + + @param BootPolicy If TRUE, indicates that the request orig= inates + from the boot manager, and that the boot + manager is attempting to load FilePath a= s a + boot selection. + @param ParentImageHandle The caller's image handle. + @param FilePath The specific file path from which the im= age is + loaded. + @param SourceBuffer If not NULL, a pointer to the memory loc= ation + containing a copy of the image to be loa= ded. + @param SourceSize The size in bytes of SourceBuffer. + @param ImageHandle Pointer to the returned image handle tha= t is + created when the image is successfully l= oaded. + + @retval EFI_SUCCESS The image was loaded into memory. + @retval EFI_NOT_FOUND The FilePath was not found. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid val= ue. + @retval EFI_UNSUPPORTED The image type is not supported, or the = device + path cannot be parsed to locate the prop= er + protocol for loading the file. + @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient + resources. + @retval EFI_LOAD_ERROR Image was not loaded because the image f= ormat was corrupt or not + understood. + @retval EFI_DEVICE_ERROR Image was not loaded because the device = returned a read error. + @retval EFI_ACCESS_DENIED Image was not loaded because the platfor= m policy prohibits the + image from being loaded. NULL is returne= d in *ImageHandle. + @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was = created with a + valid EFI_LOADED_IMAGE_PROTOCOL. However= , the current + platform policy specifies that the image= should not be started. + +**/ +EFI_STATUS +EFIAPI +UnitTestLoadImage ( + IN BOOLEAN BootPolicy, + IN EFI_HANDLE ParentImageHandle, + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + IN VOID *SourceBuffer OPTIONAL, + IN UINTN SourceSize, + OUT EFI_HANDLE *ImageHandle + ); + +/** + Transfer control to a loaded image's entry point. + + @param ImageHandle Handle of image to be started. + @param ExitDataSize Pointer of the size to ExitData + @param ExitData Pointer to a pointer to a data buffer th= at + includes a Null-terminated string, + optionally followed by additional binary= data. + The string is a description that the cal= ler may + use to further indicate the reason for t= he + image's exit. + + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate + @retval EFI_SECURITY_VIOLATION The current platform policy specifies th= at the image should not be started. + @retval EFI_SUCCESS Successfully transfer control to the ima= ge's + entry point. + +**/ +EFI_STATUS +EFIAPI +UnitTestStartImage ( + IN EFI_HANDLE ImageHandle, + OUT UINTN *ExitDataSize, + OUT CHAR16 **ExitData OPTIONAL + ); + +/** + Terminates the currently loaded EFI image and returns control to boot se= rvices. + + @param ImageHandle Handle that identifies the image. This + parameter is passed to the image on entr= y. + @param Status The image's exit code. + @param ExitDataSize The size, in bytes, of ExitData. Ignored= if + ExitStatus is EFI_SUCCESS. + @param ExitData Pointer to a data buffer that includes a + Null-terminated Unicode string, optional= ly + followed by additional binary data. The = string + is a description that the caller may use= to + further indicate the reason for the imag= e's + exit. + + @retval EFI_INVALID_PARAMETER Image handle is NULL or it is not current + image. + @retval EFI_SUCCESS Successfully terminates the currently lo= aded + EFI image. + @retval EFI_ACCESS_DENIED Should never reach there. + @retval EFI_OUT_OF_RESOURCES Could not allocate pool + +**/ +EFI_STATUS +EFIAPI +UnitTestExit ( + IN EFI_HANDLE ImageHandle, + IN EFI_STATUS Status, + IN UINTN ExitDataSize, + IN CHAR16 *ExitData OPTIONAL + ); + +/** + Unloads an image. + + @param ImageHandle Handle that identifies the image to be + unloaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_UNSUPPORTED The image has been started, and does not= support + unload. + @retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +UnitTestUnloadImage ( + IN EFI_HANDLE ImageHandle + ); + +/** + Terminates all boot services. + + @param ImageHandle Handle that identifies the exiting image. + @param MapKey Key to the latest memory map. + + @retval EFI_SUCCESS Boot Services terminated + @retval EFI_INVALID_PARAMETER MapKey is incorrect. + +**/ +EFI_STATUS +EFIAPI +UnitTestExitBootServices ( + IN EFI_HANDLE ImageHandle, + IN UINTN MapKey + ); + +/** + Returns a monotonically increasing count for the platform. + + @param[out] Count The pointer to returned value. + + @retval EFI_SUCCESS The next monotonic count was returned. + @retval EFI_INVALID_PARAMETER Count is NULL. + @retval EFI_DEVICE_ERROR The device is not functioning properly. + +**/ +EFI_STATUS +EFIAPI +UnitTestGetNextMonotonicCount ( + OUT UINT64 *Count + ); + +/** + Introduces a fine-grained stall. + + @param Microseconds The number of microseconds to stall execu= tion. + + @retval EFI_SUCCESS Execution was stalled for at least the re= quested + amount of microseconds. + @retval EFI_NOT_AVAILABLE_YET gMetronome is not available yet + +**/ +EFI_STATUS +EFIAPI +UnitTestStall ( + IN UINTN Microseconds + ); + +/** + Sets the system's watchdog timer. + + @param Timeout The number of seconds to set the watchdog timer = to. + A value of zero disables the timer. + @param WatchdogCode The numeric code to log on a watchdog timer time= out + event. The firmware reserves codes 0x0000 to 0xF= FFF. + Loaders and operating systems may use other time= out + codes. + @param DataSize The size, in bytes, of WatchdogData. + @param WatchdogData A data buffer that includes a Null-terminated Un= icode + string, optionally followed by additional binary= data. + The string is a description that the call may us= e to + further indicate the reason to be logged with a + watchdog event. + + @return EFI_SUCCESS Timeout has been set + @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet + @return EFI_UNSUPPORTED System does not have a timer (currentl= y not used) + @return EFI_DEVICE_ERROR Could not complete due to hardware err= or + +**/ +EFI_STATUS +EFIAPI +UnitTestSetWatchdogTimer ( + IN UINTN Timeout, + IN UINT64 WatchdogCode, + IN UINTN DataSize, + IN CHAR16 *WatchdogData OPTIONAL + ); + +/** + Connects one or more drivers to a controller. + + @param ControllerHandle The handle of the controller to which driv= er(s) are to be connected. + @param DriverImageHandle A pointer to an ordered list handles that = support the + EFI_DRIVER_BINDING_PROTOCOL. + @param RemainingDevicePath A pointer to the device path that specifie= s a child of the + controller specified by ControllerHandle. + @param Recursive If TRUE, then ConnectController() is calle= d recursively + until the entire tree of controllers below= the controller specified + by ControllerHandle have been created. If = FALSE, then + the tree of controllers is only expanded o= ne level. + + @retval EFI_SUCCESS 1) One or more drivers were connected to C= ontrollerHandle. + 2) No drivers were connected to Controller= Handle, but + RemainingDevicePath is not NULL, and it is= an End Device + Path Node. + @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. + @retval EFI_NOT_FOUND 1) There are no EFI_DRIVER_BINDING_PROTOCO= L instances + present in the system. + 2) No drivers were connected to Controller= Handle. + @retval EFI_SECURITY_VIOLATION + The user has no permission to start UEFI d= evice drivers on the device path + associated with the ControllerHandle or sp= ecified by the RemainingDevicePath. + +**/ +EFI_STATUS +EFIAPI +UnitTestConnectController ( + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE *DriverImageHandle OPTIONAL, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL, + IN BOOLEAN Recursive + ); + +/** + Disconnects a controller from a driver + + @param ControllerHandle ControllerHandle The handl= e of + the controller from which + driver(s) are to be + disconnected. + @param DriverImageHandle DriverImageHandle The driv= er to + disconnect from Controller= Handle. + @param ChildHandle ChildHandle The handle of = the + child to destroy. + + @retval EFI_SUCCESS One or more drivers were + disconnected from the cont= roller. + @retval EFI_SUCCESS On entry, no drivers are m= anaging + ControllerHandle. + @retval EFI_SUCCESS DriverImageHandle is not N= ULL, + and on entry DriverImageHa= ndle is + not managing ControllerHan= dle. + @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. + @retval EFI_INVALID_PARAMETER DriverImageHandle is not N= ULL, + and it is not a valid EFI_= HANDLE. + @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, a= nd it + is not a valid EFI_HANDLE. + @retval EFI_OUT_OF_RESOURCES There are not enough resou= rces + available to disconnect any + drivers from ControllerHan= dle. + @retval EFI_DEVICE_ERROR The controller could not be + disconnected because of a = device + error. + +**/ +EFI_STATUS +EFIAPI +UnitTestDisconnectController ( + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE DriverImageHandle OPTIONAL, + IN EFI_HANDLE ChildHandle OPTIONAL + ); + +/** + Locates the installed protocol handler for the handle, and + invokes it to obtain the protocol interface. Usage information + is registered in the protocol data base. + + @param UserHandle The handle to obtain the protocol interfa= ce on + @param Protocol The ID of the protocol + @param Interface The location to return the protocol inter= face + @param ImageHandle The handle of the Image that is opening t= he + protocol interface specified by Protocol = and + Interface. + @param ControllerHandle The controller handle that is requiring t= his + interface. + @param Attributes The open mode of the protocol interface + specified by Handle and Protocol. + + @retval EFI_INVALID_PARAMETER Protocol is NULL. + @retval EFI_SUCCESS Get the protocol interface. + +**/ +EFI_STATUS +EFIAPI +UnitTestOpenProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT VOID **Interface OPTIONAL, + IN EFI_HANDLE ImageHandle, + IN EFI_HANDLE ControllerHandle, + IN UINT32 Attributes + ); + +/** + Closes a protocol on a handle that was opened using OpenProtocol(). + + @param UserHandle The handle for the protocol interface tha= t was + previously opened with OpenProtocol(), an= d is + now being closed. + @param Protocol The published unique identifier of the pr= otocol. + It is the caller's responsibility to pass= in a + valid GUID. + @param AgentHandle The handle of the agent that is closing t= he + protocol interface. + @param ControllerHandle If the agent that opened a protocol is a = driver + that follows the EFI Driver Model, then t= his + parameter is the controller handle that r= equired + the protocol interface. If the agent does= not + follow the EFI Driver Model, then this pa= rameter + is optional and may be NULL. + + @retval EFI_SUCCESS The protocol instance was closed. + @retval EFI_INVALID_PARAMETER Handle, AgentHandle or ControllerHandle i= s not a + valid EFI_HANDLE. + @retval EFI_NOT_FOUND Can not find the specified protocol or + AgentHandle. + +**/ +EFI_STATUS +EFIAPI +UnitTestCloseProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + IN EFI_HANDLE AgentHandle, + IN EFI_HANDLE ControllerHandle + ); + +/** + Return information about Opened protocols in the system + + @param UserHandle The handle to close the protocol interfac= e on + @param Protocol The ID of the protocol + @param EntryBuffer A pointer to a buffer of open protocol + information in the form of + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY struc= tures. + @param EntryCount Number of EntryBuffer entries + +**/ +EFI_STATUS +EFIAPI +UnitTestOpenProtocolInformation ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, + OUT UINTN *EntryCount + ); + +/** + Retrieves the list of protocol interface GUIDs that are installed on a h= andle in a buffer allocated + from pool. + + @param UserHandle The handle from which to retrieve the lis= t of + protocol interface GUIDs. + @param ProtocolBuffer A pointer to the list of protocol interfa= ce GUID + pointers that are installed on Handle. + @param ProtocolBufferCount A pointer to the number of GUID pointers = present + in ProtocolBuffer. + + @retval EFI_SUCCESS The list of protocol interface GUIDs inst= alled + on Handle was returned in ProtocolBuffer.= The + number of protocol interface GUIDs was re= turned + in ProtocolBufferCount. + @retval EFI_INVALID_PARAMETER Handle is NULL. + @retval EFI_INVALID_PARAMETER Handle is not a valid EFI_HANDLE. + @retval EFI_INVALID_PARAMETER ProtocolBuffer is NULL. + @retval EFI_INVALID_PARAMETER ProtocolBufferCount is NULL. + @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the + results. + +**/ +EFI_STATUS +EFIAPI +UnitTestProtocolsPerHandle ( + IN EFI_HANDLE UserHandle, + OUT EFI_GUID ***ProtocolBuffer, + OUT UINTN *ProtocolBufferCount + ); + +/** + Function returns an array of handles that support the requested protocol + in a buffer allocated from pool. This is a version of UnitTestLocateHand= le() + that allocates a buffer for the caller. + + @param SearchType Specifies which handle(s) are to be retur= ned. + @param Protocol Provides the protocol to search by. Th= is + parameter is only valid for SearchType + ByProtocol. + @param SearchKey Supplies the search key depending on the + SearchType. + @param NumberHandles The number of handles returned in Buffer. + @param Buffer A pointer to the buffer to return the req= uested + array of handles that support Protocol. + + @retval EFI_SUCCESS The result array of handles was returned. + @retval EFI_NOT_FOUND No handles match the search. + @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the + matching results. + @retval EFI_INVALID_PARAMETER One or more parameters are not valid. + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateHandleBuffer ( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *NumberHandles, + OUT EFI_HANDLE **Buffer + ); + +/** + Return the first Protocol Interface that matches the Protocol GUID. If + Registration is passed in, return a Protocol Instance that was just add + to the system. If Registration is NULL return the first Protocol Interfa= ce + you find. + + @param Protocol The protocol to search for + @param Registration Optional Registration Key returned from + RegisterProtocolNotify() + @param Interface Return the Protocol interface (instance). + + @retval EFI_SUCCESS If a valid Interface is returned + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_NOT_FOUND Protocol interface not found + +**/ +EFI_STATUS +EFIAPI +UnitTestLocateProtocol ( + IN EFI_GUID *Protocol, + IN VOID *Registration OPTIONAL, + OUT VOID **Interface + ); + +/** + Installs a list of protocol interface into the boot services environment. + This function calls InstallProtocolInterface() in a loop. If any error + occurs all the protocols added by this function are removed. This is + basically a lib function to save space. + + @param Handle The handle to install the protocol handle= rs on, + or NULL if a new handle is to be allocated + @param ... EFI_GUID followed by protocol instance. A= NULL + terminates the list. The pairs are the + arguments to InstallProtocolInterface(). = All the + protocols are added to Handle. + + @retval EFI_SUCCESS All the protocol interface was installed. + @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to in= stall all the protocols. + @retval EFI_ALREADY_STARTED A Device Path Protocol instance was passe= d in that is already present in + the handle database. + @retval EFI_INVALID_PARAMETER Handle is NULL. + @retval EFI_INVALID_PARAMETER Protocol is already installed on the hand= le specified by Handle. + +**/ +EFI_STATUS +EFIAPI +UnitTestInstallMultipleProtocolInterfaces ( + IN OUT EFI_HANDLE *Handle, + ... + ); + +/** + Uninstalls a list of protocol interface in the boot services environment. + This function calls UninstallProtocolInterface() in a loop. This is + basically a lib function to save space. + + @param Handle The handle to uninstall the protocol + @param ... EFI_GUID followed by protocol instance. A= NULL + terminates the list. The pairs are the + arguments to UninstallProtocolInterface()= . All + the protocols are added to Handle. + + @return Status code + +**/ +EFI_STATUS +EFIAPI +UnitTestUninstallMultipleProtocolInterfaces ( + IN EFI_HANDLE Handle, + ... + ); + +/** + Computes and returns a 32-bit CRC for a data buffer. + + @param[in] Data A pointer to the buffer on which the 32-bi= t CRC is to be computed. + @param[in] DataSize The number of bytes in the buffer Data. + @param[out] Crc32 The 32-bit CRC that was computed for the d= ata buffer specified by Data + and DataSize. + + @retval EFI_SUCCESS The 32-bit CRC was computed for the data b= uffer and returned in + Crc32. + @retval EFI_INVALID_PARAMETER Data is NULL. + @retval EFI_INVALID_PARAMETER Crc32 is NULL. + @retval EFI_INVALID_PARAMETER DataSize is 0. + +**/ +EFI_STATUS +EFIAPI +UnitTestCalculateCrc32 ( + IN VOID *Data, + IN UINTN DataSize, + OUT UINT32 *Crc32 + ); + +/** + Creates an event in a group. + + @param Type The type of event to create and its mode = and + attributes + @param NotifyTpl The task priority level of event notifica= tions + @param NotifyFunction Pointer to the events notification functi= on + @param NotifyContext Pointer to the notification functions con= text; + corresponds to parameter "Context" in the + notification function + @param EventGroup GUID for EventGroup if NULL act the same = as + gBS->CreateEvent(). + @param Event Pointer to the newly created event if the= call + succeeds; undefined otherwise + + @retval EFI_SUCCESS The event structure was created + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value + @retval EFI_OUT_OF_RESOURCES The event could not be allocated + +**/ +EFI_STATUS +EFIAPI +UnitTestCreateEventEx ( + IN UINT32 Type, + IN EFI_TPL NotifyTpl, + IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL + IN CONST VOID *NotifyContext, OPTIONAL + IN CONST EFI_GUID *EventGroup, OPTIONAL + OUT EFI_EVENT *Event + ); + +#endif diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLib.inf b/UnitTestFrameworkPkg/Library/UnitTes= tUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.inf new file mode 100644 index 000000000000..b694dd0232ee --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLib.inf @@ -0,0 +1,46 @@ +## @file +# UEFI Boot Services Table Library for unit tests implementation. +# +# Copyright (c) Microsoft Corporation +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D UnitTestUefiBootServicesTableLib + MODULE_UNI_FILE =3D UefiBootServicesTableLibTest.uni + FILE_GUID =3D AA3A0651-89EB-4951-9D68-50F27360EBC2 + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D UefiBootServicesTableLib|DXE_CORE DXE= _DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_= CORE + + CONSTRUCTOR =3D UnitTestUefiBootServicesTableLibConst= ructor + +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + UnitTestUefiBootServicesTableLib.h + UnitTestUefiBootServicesTableLib.c + UnitTestUefiBootServicesTableLibEventTimer.c + UnitTestUefiBootServicesTableLibImage.c + UnitTestUefiBootServicesTableLibMemory.c + UnitTestUefiBootServicesTableLibProtocol.h + UnitTestUefiBootServicesTableLibProtocol.c + UnitTestUefiBootServicesTableLibMisc.c + UnitTestUefiBootServicesTableLibTpl.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UnitTestLib + +[UserExtensions.TianoCore."ExtraFiles"] + TimerExtra.uni diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLib.uni b/UnitTestFrameworkPkg/Library/UnitTes= tUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.uni new file mode 100644 index 000000000000..1f742bb6d8e9 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLib.uni @@ -0,0 +1,12 @@ +// /** @file +// UEFI Boot Services Table Library for unit tests implementation. +// +// Copyright (c) Microsoft Corporation +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "UEFI Boot Service= s Table Library for unit tests" + +#string STR_MODULE_DESCRIPTION #language en-US "UEFI Boot Service= s Table Library for unit tests." diff --git a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/= UnitTestUefiBootServicesTableLibProtocol.h b/UnitTestFrameworkPkg/Library/U= nitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.h new file mode 100644 index 000000000000..fe91e0e39639 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTes= tUefiBootServicesTableLibProtocol.h @@ -0,0 +1,120 @@ +/** @file + An internal header file for the Unit Test instance of the UEFI Boot Serv= ices Table Library. + + This file includes common header files, defines internal structure and f= unctions used by + the library implementation. + +Copyright (c) Microsoft Corporation +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_PROTOCOL_H_ +#define UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_PROTOCOL_H_ + +#include "UnitTestUefiBootServicesTableLib.h" + +#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l') + +/// +/// IHANDLE - contains a list of protocol handles +/// +typedef struct { + UINTN Signature; + /// All handles list of IHANDLE + LIST_ENTRY AllHandles; + /// List of PROTOCOL_INTERFACE's for this handle + LIST_ENTRY Protocols; + UINTN LocateRequest; + /// The Handle Database Key value when this handle was last created or m= odified + UINT64 Key; +} IHANDLE; + +#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature =3D=3D EFI_HANDLE_SIGNA= TURE) + +#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e') + +/// +/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol +/// database. Each handler that supports this protocol is listed, along +/// with a list of registered notifies. +/// +typedef struct { + UINTN Signature; + /// Link Entry inserted to mProtocolDatabase + LIST_ENTRY AllEntries; + /// ID of the protocol + EFI_GUID ProtocolID; + /// All protocol interfaces + LIST_ENTRY Protocols; + /// Registered notification handlers + LIST_ENTRY Notify; +} PROTOCOL_ENTRY; + +#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c') + +/// +/// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked +/// with a protocol interface structure +/// +typedef struct { + UINTN Signature; + /// Link on IHANDLE.Protocols + LIST_ENTRY Link; + /// Back pointer + IHANDLE *Handle; + /// Link on PROTOCOL_ENTRY.Protocols + LIST_ENTRY ByProtocol; + /// The protocol ID + PROTOCOL_ENTRY *Protocol; + /// The interface value + VOID *Interface; + /// OPEN_PROTOCOL_DATA list + LIST_ENTRY OpenList; + UINTN OpenListCount; +} PROTOCOL_INTERFACE; + +#define OPEN_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('p','o','d','l') + +typedef struct { + UINTN Signature; + /// Link on PROTOCOL_INTERFACE.OpenList + LIST_ENTRY Link; + + EFI_HANDLE AgentHandle; + EFI_HANDLE ControllerHandle; + UINT32 Attributes; + UINT32 OpenCount; +} OPEN_PROTOCOL_DATA; + +#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n') + +/// +/// PROTOCOL_NOTIFY - used for each register notification for a protocol +/// +typedef struct { + UINTN Signature; + PROTOCOL_ENTRY *Protocol; + /// All notifications for this protocol + LIST_ENTRY Link; + /// Event to notify + EFI_EVENT Event; + /// Last position notified + LIST_ENTRY *Position; +} PROTOCOL_NOTIFY; + +typedef struct { + EFI_GUID *Protocol; + VOID *SearchKey; + LIST_ENTRY *Position; + PROTOCOL_ENTRY *ProtEntry; +} LOCATE_POSITION; + +typedef +IHANDLE * +(*UNIT_TEST_GET_NEXT) ( + IN OUT LOCATE_POSITION *Position, + OUT VOID **Interface + ); + +#endif diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc b/UnitTestFramew= orkPkg/UnitTestFrameworkPkg.dsc index e4f9fb6eb604..a76e31d97d5d 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc @@ -34,6 +34,7 @@ [Components] UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbC= lass.inf UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/Unit= TestPersistenceLibSimpleFileSystem.inf UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertL= ib.inf + UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUe= fiBootServicesTableLib.inf =20 UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestD= xe.inf UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestP= ei.inf diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index f249813713a8..9beeaef1ba5e 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -17,6 +17,7 @@ [LibraryClasses.common.HOST_APPLICATION] UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.i= nf DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.= inf MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationL= ibPosix/MemoryAllocationLibPosix.inf + UefiBootServicesTableLib|UnitTestFrameworkPkg/Library/UnitTestUefiBootSe= rvicesTableLib/UnitTestUefiBootServicesTableLib.inf =20 [BuildOptions] GCC:*_*_*_CC_FLAGS =3D -fno-pie --=20 2.28.0.windows.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 (#95925): https://edk2.groups.io/g/devel/message/95925 Mute This Topic: https://groups.io/mt/94796663/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- From nobody Tue May 7 21:00:24 2024 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+95926+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+95926+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1667521527; cv=none; d=zohomail.com; s=zohoarc; b=H+3o165PMG2VPF2AX9jdvekY7CvLmm+dfDHgmyiwnoSV1Cm9rebEWK33IKAruhJyxG3zGTXDhzNuPVqLJu2N5waciDxpuEAfGnl3tvVcufcUBZ0RxicSRC1DcNLsn/5gM0rBFvnjrsE1F704BaRKHOUgospb5Q88OyiGsP0gwrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667521527; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=V0w4QaEdF5lH9NpPTHs5RmTbKLy3zlfgE8zyZweYhdo=; b=G0XX6Iujw8NDehuZC2/BGHzwSLCO34PwKejpb0KB29frDhahHbqIoUW0myRB3AUxMU2Dcs5J+RmDXnS1L6gEmqvXc/TmPBC94D9eefSLPargR9jyGOA3jOLWjqE5hFdalzWidHe6I/L0qa6Z3n+Io3F/0hgYHQwV+oKp3vQIOoc= 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+95926+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 1667521527643914.1538278580032; Thu, 3 Nov 2022 17:25:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id A5DQYY1788612xVSRQ9wG65p; Thu, 03 Nov 2022 17:25:26 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web09.5871.1667521525683158932 for ; Thu, 03 Nov 2022 17:25:25 -0700 X-Received: from localhost.localdomain (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id 7D07120B929F; Thu, 3 Nov 2022 17:25:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7D07120B929F From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Michael D Kinney , Sean Brogan Subject: [edk2-devel] [PATCH v1 2/2] PrmPkg: Use UnitTestFrameworkPkg UEFI BS library Date: Thu, 3 Nov 2022 20:24:40 -0400 Message-Id: <20221104002440.2316-3-mikuback@linux.microsoft.com> In-Reply-To: <20221104002440.2316-1-mikuback@linux.microsoft.com> References: <20221104002440.2316-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,mikuback@linux.microsoft.com X-Gm-Message-State: KFLLEqGlOuy8Q8INBEVhX5yqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1667521526; bh=En+Bj6z5FLYrE/1IYKvmnsoI3qhkm3mmKwcYr4IipiI=; h=Cc:Date:From:Reply-To:Subject:To; b=O7YkoAjcFStRgGPDWe011A/YfHEKt9yXtxFzo5BqZEpn3NpqFch+ZJpEk8xVIoDEOSq G24CaZZClzxXfpCxcwkVlGjLNRUYb+YXKt3u9ctyxdhH2VI7/snvAOe+ZiyWvaf209KiO WzLBzX9OG9H2kX55+QLKxcUSBMjvoQyROZE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1667521529524100003 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki Updates PrmPkg to use UnitTestUefiBootServicesTableLib from UnitTestFrameworkPkg instead of UefiBootServicesTableLibUnitTest in PrmPkg. Cc: Michael D Kinney Cc: Sean Brogan Signed-off-by: Michael Kubacki Reviewed-by: Michael D Kinney --- PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTest.c | 119 -- PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTestEventTimer.c | 180 --- PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTestImage.c | 163 -- PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTestMemory.c | 145 -- PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTestMisc.c | 198 --- PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTestProtocol.c | 1650 -------------------- PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTestTpl.c | 43 - PrmPkg/PrmPkg.dsc = | 1 - PrmPkg/Test/PrmPkgHostTest.dsc = | 6 - PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibTest.uni | 12 - PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTest.h | 1042 ------------ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTest.inf | 46 - PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServ= icesTableLibUnitTestProtocol.h | 120 -- 13 files changed, 3725 deletions(-) diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTest.c b/PrmPkg/Test/UnitTest/Library/UefiBootS= ervicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c deleted file mode 100644 index ea3235e448a2..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTest.c +++ /dev/null @@ -1,119 +0,0 @@ -/** @file - This library supports a Boot Services table library implementation that = allows code dependent - upon UefiBootServicesTableLib to operate in an isolated execution enviro= nment such as within - the context of a host-based unit test framework. - - The unit test should initialize the Boot Services database with any requ= ired elements - (e.g. protocols, events, handles, etc.) prior to the services being invo= ked by code under test. - - It is strongly recommended to clean any global databases (e.g. protocol,= event, handles, etc.) after - every unit test so the tests execute in a predictable manner from a clea= n state. - - Copyright (c) Microsoft Corporation - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "UefiBootServicesTableLibUnitTest.h" - -EFI_HANDLE gImageHandle =3D NULL; -EFI_SYSTEM_TABLE *gST =3D NULL; - -STATIC EFI_BOOT_SERVICES mBootServices =3D { - { - EFI_BOOT_SERVICES_SIGNATURE, = // Signature - EFI_BOOT_SERVICES_REVISION, = // Revision - sizeof (EFI_BOOT_SERVICES), = // HeaderSize - 0, = // CRC32 - 0 = // Reserved - }, - (EFI_RAISE_TPL)UnitTestRaiseTpl, = // RaiseTPL - (EFI_RESTORE_TPL)UnitTestRestoreTpl, = // RestoreTPL - (EFI_ALLOCATE_PAGES)UnitTestAllocatePages, = // AllocatePages - (EFI_FREE_PAGES)UnitTestFreePages, = // FreePages - (EFI_GET_MEMORY_MAP)UnitTestGetMemoryMap, = // GetMemoryMap - (EFI_ALLOCATE_POOL)UnitTestAllocatePool, = // AllocatePool - (EFI_FREE_POOL)UnitTestFreePool, = // FreePool - (EFI_CREATE_EVENT)UnitTestCreateEvent, = // CreateEvent - (EFI_SET_TIMER)UnitTestSetTimer, = // SetTimer - (EFI_WAIT_FOR_EVENT)UnitTestWaitForEvent, = // WaitForEvent - (EFI_SIGNAL_EVENT)UnitTestSignalEvent, = // SignalEvent - (EFI_CLOSE_EVENT)UnitTestCloseEvent, = // CloseEvent - (EFI_CHECK_EVENT)UnitTestCheckEvent, = // CheckEvent - (EFI_INSTALL_PROTOCOL_INTERFACE)UnitTestInstallProtocolInterface, = // InstallProtocolInterface - (EFI_REINSTALL_PROTOCOL_INTERFACE)UnitTestReinstallProtocolInterface, = // ReinstallProtocolInterface - (EFI_UNINSTALL_PROTOCOL_INTERFACE)UnitTestUninstallProtocolInterface, = // UninstallProtocolInterface - (EFI_HANDLE_PROTOCOL)UnitTestHandleProtocol, = // HandleProtocol - (VOID *)NULL, = // Reserved - (EFI_REGISTER_PROTOCOL_NOTIFY)UnitTestRegisterProtocolNotify, = // RegisterProtocolNotify - (EFI_LOCATE_HANDLE)UnitTestLocateHandle, = // LocateHandle - (EFI_LOCATE_DEVICE_PATH)UnitTestLocateDevicePath, = // LocateDevicePath - (EFI_INSTALL_CONFIGURATION_TABLE)UnitTestInstallConfigurationTable, = // InstallConfigurationTable - (EFI_IMAGE_LOAD)UnitTestLoadImage, = // LoadImage - (EFI_IMAGE_START)UnitTestStartImage, = // StartImage - (EFI_EXIT)UnitTestExit, = // Exit - (EFI_IMAGE_UNLOAD)UnitTestUnloadImage, = // UnloadImage - (EFI_EXIT_BOOT_SERVICES)UnitTestExitBootServices, = // ExitBootServices - (EFI_GET_NEXT_MONOTONIC_COUNT)UnitTestGetNextMonotonicCount, = // GetNextMonotonicCount - (EFI_STALL)UnitTestStall, = // Stall - (EFI_SET_WATCHDOG_TIMER)UnitTestSetWatchdogTimer, = // SetWatchdogTimer - (EFI_CONNECT_CONTROLLER)UnitTestConnectController, = // ConnectController - (EFI_DISCONNECT_CONTROLLER)UnitTestDisconnectController, = // DisconnectController - (EFI_OPEN_PROTOCOL)UnitTestOpenProtocol, = // OpenProtocol - (EFI_CLOSE_PROTOCOL)UnitTestCloseProtocol, = // CloseProtocol - (EFI_OPEN_PROTOCOL_INFORMATION)UnitTestOpenProtocolInformation, = // OpenProtocolInformation - (EFI_PROTOCOLS_PER_HANDLE)UnitTestProtocolsPerHandle, = // ProtocolsPerHandle - (EFI_LOCATE_HANDLE_BUFFER)UnitTestLocateHandleBuffer, = // LocateHandleBuffer - (EFI_LOCATE_PROTOCOL)UnitTestLocateProtocol, = // LocateProtocol - (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)UnitTestInstallMultipleProtoco= lInterfaces, // InstallMultipleProtocolInterfaces - (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)UnitTestUninstallMultiplePro= tocolInterfaces, // UninstallMultipleProtocolInterfaces - (EFI_CALCULATE_CRC32)UnitTestCalculateCrc32, = // CalculateCrc32 - (EFI_COPY_MEM)CopyMem, = // CopyMem - (EFI_SET_MEM)SetMem, = // SetMem - (EFI_CREATE_EVENT_EX)UnitTestCreateEventEx = // CreateEventEx -}; - -EFI_BOOT_SERVICES *gBS =3D &mBootServices; - -/** - The constructor function caches the pointer of Boot Services Table. - - The constructor function caches the pointer of Boot Services Table throu= gh System Table. - It will ASSERT() if the pointer of System Table is NULL. - It will ASSERT() if the pointer of Boot Services Table is NULL. - It will always return EFI_SUCCESS. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -EFI_STATUS -EFIAPI -UefiBootServicesTableLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - // - // Cache the Image Handle - // - gImageHandle =3D ImageHandle; - ASSERT (gImageHandle !=3D NULL); - - // - // Cache pointer to the EFI System Table - // - - // Note: The system table is not implemented - gST =3D NULL; - - // - // Cache pointer to the EFI Boot Services Table - // - gBS =3D SystemTable->BootServices; - ASSERT (gBS !=3D NULL); - - return EFI_SUCCESS; -} diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTestEventTimer.c b/PrmPkg/Test/UnitTest/Library= /UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestEventTime= r.c deleted file mode 100644 index c1ec801bca42..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTestEventTimer.c +++ /dev/null @@ -1,180 +0,0 @@ -/** @file - Implementation of event and timer related services in the UEFI Boot Serv= ices table for use in unit tests. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "UefiBootServicesTableLibUnitTest.h" - -/** - Creates an event. - - @param Type The type of event to create and its mode = and - attributes - @param NotifyTpl The task priority level of event notifica= tions - @param NotifyFunction Pointer to the events notification functi= on - @param NotifyContext Pointer to the notification functions con= text - corresponds to parameter "Context" in the - notification function - @param Event Pointer to the newly created event if the= call - succeeds undefined otherwise - - @retval EFI_SUCCESS The event structure was created - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value - @retval EFI_OUT_OF_RESOURCES The event could not be allocated - -**/ -EFI_STATUS -EFIAPI -UnitTestCreateEvent ( - IN UINT32 Type, - IN EFI_TPL NotifyTpl, - IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL - IN VOID *NotifyContext, OPTIONAL - OUT EFI_EVENT *Event - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Sets the type of timer and the trigger time for a timer event. - - @param UserEvent The timer event that is to be signaled at= the - specified time - @param Type The type of time that is specified in - TriggerTime - @param TriggerTime The number of 100ns units until the timer - expires - - @retval EFI_SUCCESS The event has been set to be signaled at = the - requested time - @retval EFI_INVALID_PARAMETER Event or Type is not valid - -**/ -EFI_STATUS -EFIAPI -UnitTestSetTimer ( - IN EFI_EVENT UserEvent, - IN EFI_TIMER_DELAY Type, - IN UINT64 TriggerTime - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Stops execution until an event is signaled. - - @param NumberOfEvents The number of events in the UserEvents ar= ray - @param UserEvents An array of EFI_EVENT - @param UserIndex Pointer to the index of the event which - satisfied the wait condition - - @retval EFI_SUCCESS The event indicated by Index was signaled. - @retval EFI_INVALID_PARAMETER The event indicated by Index has a notifi= cation - function or Event was not a valid type - @retval EFI_UNSUPPORTED The current TPL is not TPL_APPLICATION - -**/ -EFI_STATUS -EFIAPI -UnitTestWaitForEvent ( - IN UINTN NumberOfEvents, - IN EFI_EVENT *UserEvents, - OUT UINTN *UserIndex - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Signals the event. Queues the event to be notified if needed. - - @param UserEvent The event to signal . - - @retval EFI_INVALID_PARAMETER Parameters are not valid. - @retval EFI_SUCCESS The event was signaled. - -**/ -EFI_STATUS -EFIAPI -UnitTestSignalEvent ( - IN EFI_EVENT UserEvent - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Closes an event and frees the event structure. - - @param UserEvent Event to close - - @retval EFI_INVALID_PARAMETER Parameters are not valid. - @retval EFI_SUCCESS The event has been closed - -**/ -EFI_STATUS -EFIAPI -UnitTestCloseEvent ( - IN EFI_EVENT UserEvent - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Check the status of an event. - - @param UserEvent The event to check - - @retval EFI_SUCCESS The event is in the signaled state - @retval EFI_NOT_READY The event is not in the signaled state - @retval EFI_INVALID_PARAMETER Event is of type EVT_NOTIFY_SIGNAL - -**/ -EFI_STATUS -EFIAPI -UnitTestCheckEvent ( - IN EFI_EVENT UserEvent - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Creates an event in a group. - - @param Type The type of event to create and its mode = and - attributes - @param NotifyTpl The task priority level of event notifica= tions - @param NotifyFunction Pointer to the events notification functi= on - @param NotifyContext Pointer to the notification functions con= text - corresponds to parameter "Context" in the - notification function - @param EventGroup GUID for EventGroup if NULL act the same = as - gBS->CreateEvent(). - @param Event Pointer to the newly created event if the= call - succeeds undefined otherwise - - @retval EFI_SUCCESS The event structure was created - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value - @retval EFI_OUT_OF_RESOURCES The event could not be allocated - -**/ -EFI_STATUS -EFIAPI -UnitTestCreateEventEx ( - IN UINT32 Type, - IN EFI_TPL NotifyTpl, - IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL - IN CONST VOID *NotifyContext, OPTIONAL - IN CONST EFI_GUID *EventGroup, OPTIONAL - OUT EFI_EVENT *Event - ) -{ - return EFI_NOT_AVAILABLE_YET; -} diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTestImage.c b/PrmPkg/Test/UnitTest/Library/Uefi= BootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestImage.c deleted file mode 100644 index a5799ff92d0c..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTestImage.c +++ /dev/null @@ -1,163 +0,0 @@ -/** @file - Implementation of image related services in the UEFI Boot Services table= for use in unit tests. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "UefiBootServicesTableLibUnitTest.h" - -/** - Loads an EFI image into memory and returns a handle to the image. - - @param BootPolicy If TRUE, indicates that the request orig= inates - from the boot manager, and that the boot - manager is attempting to load FilePath a= s a - boot selection. - @param ParentImageHandle The caller's image handle. - @param FilePath The specific file path from which the im= age is - loaded. - @param SourceBuffer If not NULL, a pointer to the memory loc= ation - containing a copy of the image to be loa= ded. - @param SourceSize The size in bytes of SourceBuffer. - @param ImageHandle Pointer to the returned image handle tha= t is - created when the image is successfully l= oaded. - - @retval EFI_SUCCESS The image was loaded into memory. - @retval EFI_NOT_FOUND The FilePath was not found. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid val= ue. - @retval EFI_UNSUPPORTED The image type is not supported, or the = device - path cannot be parsed to locate the prop= er - protocol for loading the file. - @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient - resources. - @retval EFI_LOAD_ERROR Image was not loaded because the image f= ormat was corrupt or not - understood. - @retval EFI_DEVICE_ERROR Image was not loaded because the device = returned a read error. - @retval EFI_ACCESS_DENIED Image was not loaded because the platfor= m policy prohibits the - image from being loaded. NULL is returne= d in *ImageHandle. - @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was = created with a - valid EFI_LOADED_IMAGE_PROTOCOL. However= , the current - platform policy specifies that the image= should not be started. - -**/ -EFI_STATUS -EFIAPI -UnitTestLoadImage ( - IN BOOLEAN BootPolicy, - IN EFI_HANDLE ParentImageHandle, - IN EFI_DEVICE_PATH_PROTOCOL *FilePath, - IN VOID *SourceBuffer OPTIONAL, - IN UINTN SourceSize, - OUT EFI_HANDLE *ImageHandle - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Transfer control to a loaded image's entry point. - - @param ImageHandle Handle of image to be started. - @param ExitDataSize Pointer of the size to ExitData - @param ExitData Pointer to a pointer to a data buffer th= at - includes a Null-terminated string, - optionally followed by additional binary= data. - The string is a description that the cal= ler may - use to further indicate the reason for t= he - image's exit. - - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate - @retval EFI_SECURITY_VIOLATION The current platform policy specifies th= at the image should not be started. - @retval EFI_SUCCESS Successfully transfer control to the ima= ge's - entry point. - -**/ -EFI_STATUS -EFIAPI -UnitTestStartImage ( - IN EFI_HANDLE ImageHandle, - OUT UINTN *ExitDataSize, - OUT CHAR16 **ExitData OPTIONAL - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Terminates the currently loaded EFI image and returns control to boot se= rvices. - - @param ImageHandle Handle that identifies the image. This - parameter is passed to the image on entr= y. - @param Status The image's exit code. - @param ExitDataSize The size, in bytes, of ExitData. Ignored= if - ExitStatus is EFI_SUCCESS. - @param ExitData Pointer to a data buffer that includes a - Null-terminated Unicode string, optional= ly - followed by additional binary data. The = string - is a description that the caller may use= to - further indicate the reason for the imag= e's - exit. - - @retval EFI_INVALID_PARAMETER Image handle is NULL or it is not current - image. - @retval EFI_SUCCESS Successfully terminates the currently lo= aded - EFI image. - @retval EFI_ACCESS_DENIED Should never reach there. - @retval EFI_OUT_OF_RESOURCES Could not allocate pool - -**/ -EFI_STATUS -EFIAPI -UnitTestExit ( - IN EFI_HANDLE ImageHandle, - IN EFI_STATUS Status, - IN UINTN ExitDataSize, - IN CHAR16 *ExitData OPTIONAL - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Unloads an image. - - @param ImageHandle Handle that identifies the image to be - unloaded. - - @retval EFI_SUCCESS The image has been unloaded. - @retval EFI_UNSUPPORTED The image has been started, and does not= support - unload. - @retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle. - -**/ -EFI_STATUS -EFIAPI -UnitTestUnloadImage ( - IN EFI_HANDLE ImageHandle - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Terminates all boot services. - - @param ImageHandle Handle that identifies the exiting image. - @param MapKey Key to the latest memory map. - - @retval EFI_SUCCESS Boot Services terminated - @retval EFI_INVALID_PARAMETER MapKey is incorrect. - -**/ -EFI_STATUS -EFIAPI -UnitTestExitBootServices ( - IN EFI_HANDLE ImageHandle, - IN UINTN MapKey - ) -{ - return EFI_NOT_AVAILABLE_YET; -} diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTestMemory.c b/PrmPkg/Test/UnitTest/Library/Uef= iBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMemory.c deleted file mode 100644 index 2c9a1989f2d1..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTestMemory.c +++ /dev/null @@ -1,145 +0,0 @@ -/** @file - Implementation of memory related services in the UEFI Boot Services tabl= e for use in unit tests. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "UefiBootServicesTableLibUnitTest.h" - -/** - Allocates pages from the memory map. - - @param Type The type of allocation to perform - @param MemoryType The type of memory to turn the allocated = pages - into - @param NumberOfPages The number of pages to allocate - @param Memory A pointer to receive the base allocated m= emory - address - - @return Status. On success, Memory is filled in with the base address al= located - @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined= in - spec. - @retval EFI_NOT_FOUND Could not allocate pages match the requir= ement. - @retval EFI_OUT_OF_RESOURCES No enough pages to allocate. - @retval EFI_SUCCESS Pages successfully allocated. - -**/ -EFI_STATUS -EFIAPI -UnitTestAllocatePages ( - IN EFI_ALLOCATE_TYPE Type, - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN NumberOfPages, - IN OUT EFI_PHYSICAL_ADDRESS *Memory - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Frees previous allocated pages. - - @param Memory Base address of memory being freed - @param NumberOfPages The number of pages to free - - @retval EFI_NOT_FOUND Could not find the entry that covers the = range - @retval EFI_INVALID_PARAMETER Address not aligned - @return EFI_SUCCESS -Pages successfully freed. - -**/ -EFI_STATUS -EFIAPI -UnitTestFreePages ( - IN EFI_PHYSICAL_ADDRESS Memory, - IN UINTN NumberOfPages - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - This function returns a copy of the current memory map. The map is an ar= ray of - memory descriptors, each of which describes a contiguous block of memory. - - @param MemoryMapSize A pointer to the size, in bytes, of the - MemoryMap buffer. On input, this is the s= ize of - the buffer allocated by the caller. On o= utput, - it is the size of the buffer returned by = the - firmware if the buffer was large enough,= or the - size of the buffer needed to contain the= map if - the buffer was too small. - @param MemoryMap A pointer to the buffer in which firmware= places - the current memory map. - @param MapKey A pointer to the location in which firmwa= re - returns the key for the current memory ma= p. - @param DescriptorSize A pointer to the location in which firmwa= re - returns the size, in bytes, of an individ= ual - EFI_MEMORY_DESCRIPTOR. - @param DescriptorVersion A pointer to the location in which firmwa= re - returns the version number associated wit= h the - EFI_MEMORY_DESCRIPTOR. - - @retval EFI_SUCCESS The memory map was returned in the Memory= Map - buffer. - @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The c= urrent - buffer size needed to hold the memory map= is - returned in MemoryMapSize. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. - -**/ -EFI_STATUS -EFIAPI -UnitTestGetMemoryMap ( - IN OUT UINTN *MemoryMapSize, - IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, - OUT UINTN *MapKey, - OUT UINTN *DescriptorSize, - OUT UINT32 *DescriptorVersion - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Allocate pool of a particular type. - - @param PoolType Type of pool to allocate - @param Size The amount of pool to allocate - @param Buffer The address to return a pointer to the al= located - pool - - @retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL - @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation = failed. - @retval EFI_SUCCESS Pool successfully allocated. - -**/ -EFI_STATUS -EFIAPI -UnitTestAllocatePool ( - IN EFI_MEMORY_TYPE PoolType, - IN UINTN Size, - OUT VOID **Buffer - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Frees pool. - - @param Buffer The allocated pool entry to free - - @retval EFI_INVALID_PARAMETER Buffer is not a valid value. - @retval EFI_SUCCESS Pool successfully freed. - -**/ -EFI_STATUS -EFIAPI -UnitTestFreePool ( - IN VOID *Buffer - ) -{ - return EFI_NOT_AVAILABLE_YET; -} diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTestMisc.c b/PrmPkg/Test/UnitTest/Library/UefiB= ootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMisc.c deleted file mode 100644 index ab7936544801..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTestMisc.c +++ /dev/null @@ -1,198 +0,0 @@ -/** @file - Implementation of miscellaneous services in the UEFI Boot Services table= for use in unit tests. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "UefiBootServicesTableLibUnitTest.h" - -/** - Returns a monotonically increasing count for the platform. - - @param[out] Count The pointer to returned value. - - @retval EFI_SUCCESS The next monotonic count was returned. - @retval EFI_INVALID_PARAMETER Count is NULL. - @retval EFI_DEVICE_ERROR The device is not functioning properly. - -**/ -EFI_STATUS -EFIAPI -UnitTestGetNextMonotonicCount ( - OUT UINT64 *Count - ) -{ - STATIC UINT64 StaticCount =3D 0; - - *Count =3D StaticCount++; - - return EFI_SUCCESS; -} - -/** - Introduces a fine-grained stall. - - @param Microseconds The number of microseconds to stall execu= tion. - - @retval EFI_SUCCESS Execution was stalled for at least the re= quested - amount of microseconds. - @retval EFI_NOT_AVAILABLE_YET gMetronome is not available yet - -**/ -EFI_STATUS -EFIAPI -UnitTestStall ( - IN UINTN Microseconds - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Sets the system's watchdog timer. - - @param Timeout The number of seconds to set the watchdog timer = to. - A value of zero disables the timer. - @param WatchdogCode The numeric code to log on a watchdog timer time= out - event. The firmware reserves codes 0x0000 to 0xF= FFF. - Loaders and operating systems may use other time= out - codes. - @param DataSize The size, in bytes, of WatchdogData. - @param WatchdogData A data buffer that includes a Null-terminated Un= icode - string, optionally followed by additional binary= data. - The string is a description that the call may us= e to - further indicate the reason to be logged with a - watchdog event. - - @return EFI_SUCCESS Timeout has been set - @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet - @return EFI_UNSUPPORTED System does not have a timer (currentl= y not used) - @return EFI_DEVICE_ERROR Could not complete due to hardware err= or - -**/ -EFI_STATUS -EFIAPI -UnitTestSetWatchdogTimer ( - IN UINTN Timeout, - IN UINT64 WatchdogCode, - IN UINTN DataSize, - IN CHAR16 *WatchdogData OPTIONAL - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Connects one or more drivers to a controller. - - @param ControllerHandle The handle of the controller to which driv= er(s) are to be connected. - @param DriverImageHandle A pointer to an ordered list handles that = support the - EFI_DRIVER_BINDING_PROTOCOL. - @param RemainingDevicePath A pointer to the device path that specifie= s a child of the - controller specified by ControllerHandle. - @param Recursive If TRUE, then ConnectController() is calle= d recursively - until the entire tree of controllers below= the controller specified - by ControllerHandle have been created. If = FALSE, then - the tree of controllers is only expanded o= ne level. - - @retval EFI_SUCCESS 1) One or more drivers were connected to C= ontrollerHandle. - 2) No drivers were connected to Controller= Handle, but - RemainingDevicePath is not NULL, and it is= an End Device - Path Node. - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. - @retval EFI_NOT_FOUND 1) There are no EFI_DRIVER_BINDING_PROTOCO= L instances - present in the system. - 2) No drivers were connected to Controller= Handle. - @retval EFI_SECURITY_VIOLATION - The user has no permission to start UEFI d= evice drivers on the device path - associated with the ControllerHandle or sp= ecified by the RemainingDevicePath. - -**/ -EFI_STATUS -EFIAPI -UnitTestConnectController ( - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE *DriverImageHandle OPTIONAL, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL, - IN BOOLEAN Recursive - ) -{ - return EFI_SUCCESS; // Return success for now -} - -/** - Disconnects a controller from a driver - - @param ControllerHandle ControllerHandle The handl= e of - the controller from which - driver(s) are to be - disconnected. - @param DriverImageHandle DriverImageHandle The driv= er to - disconnect from Controller= Handle. - @param ChildHandle ChildHandle The handle of = the - child to destroy. - - @retval EFI_SUCCESS One or more drivers were - disconnected from the cont= roller. - @retval EFI_SUCCESS On entry, no drivers are m= anaging - ControllerHandle. - @retval EFI_SUCCESS DriverImageHandle is not N= ULL, - and on entry DriverImageHa= ndle is - not managing ControllerHan= dle. - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. - @retval EFI_INVALID_PARAMETER DriverImageHandle is not N= ULL, - and it is not a valid EFI_= HANDLE. - @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, a= nd it - is not a valid EFI_HANDLE. - @retval EFI_OUT_OF_RESOURCES There are not enough resou= rces - available to disconnect any - drivers from ControllerHan= dle. - @retval EFI_DEVICE_ERROR The controller could not be - disconnected because of a = device - error. - -**/ -EFI_STATUS -EFIAPI -UnitTestDisconnectController ( - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE DriverImageHandle OPTIONAL, - IN EFI_HANDLE ChildHandle OPTIONAL - ) -{ - return EFI_SUCCESS; // Return success for now -} - -/** - Computes and returns a 32-bit CRC for a data buffer. - - @param[in] Data A pointer to the buffer on which the 32-bi= t CRC is to be computed. - @param[in] DataSize The number of bytes in the buffer Data. - @param[out] Crc32 The 32-bit CRC that was computed for the d= ata buffer specified by Data - and DataSize. - - @retval EFI_SUCCESS The 32-bit CRC was computed for the data b= uffer and returned in - Crc32. - @retval EFI_INVALID_PARAMETER Data is NULL. - @retval EFI_INVALID_PARAMETER Crc32 is NULL. - @retval EFI_INVALID_PARAMETER DataSize is 0. - -**/ -EFI_STATUS -EFIAPI -UnitTestCalculateCrc32 ( - IN VOID *Data, - IN UINTN DataSize, - OUT UINT32 *Crc32 - ) -{ - if ((Data =3D=3D NULL) || (Crc32 =3D=3D NULL) || (DataSize =3D=3D 0)) { - return EFI_INVALID_PARAMETER; - } - - *Crc32 =3D CalculateCrc32 (Data, DataSize); - - return EFI_SUCCESS; -} diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTestProtocol.c b/PrmPkg/Test/UnitTest/Library/U= efiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.c deleted file mode 100644 index 799b153a445f..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTestProtocol.c +++ /dev/null @@ -1,1650 +0,0 @@ -/** @file - Implementation of protocol related services in the UEFI Boot Services ta= ble for use in unit tests. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "UefiBootServicesTableLibUnitTestProtocol.h" - -STATIC LIST_ENTRY mProtocolDatabase =3D INITIALIZE_LIST_HEAD_VARIAB= LE (mProtocolDatabase); -STATIC LIST_ENTRY gHandleList =3D INITIALIZE_LIST_HEAD_VARIAB= LE (gHandleList); -STATIC UINT64 gHandleDatabaseKey =3D 0; -STATIC UINTN mEfiLocateHandleRequest =3D 0; - -// -// Helper Functions -// - -/** - Check whether a handle is a valid EFI_HANDLE - - @param UserHandle The handle to check - - @retval EFI_INVALID_PARAMETER The handle is NULL or not a valid EFI_HAN= DLE. - @retval EFI_SUCCESS The handle is valid EFI_HANDLE. - -**/ -EFI_STATUS -UnitTestValidateHandle ( - IN EFI_HANDLE UserHandle - ) -{ - IHANDLE *Handle; - LIST_ENTRY *Link; - - if (UserHandle =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - for (Link =3D gHandleList.BackLink; Link !=3D &gHandleList; Link =3D Lin= k->BackLink) { - Handle =3D CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE); - if (Handle =3D=3D (IHANDLE *)UserHandle) { - return EFI_SUCCESS; - } - } - - return EFI_INVALID_PARAMETER; -} - -/** - Finds the protocol entry for the requested protocol. - - @param Protocol The ID of the protocol - @param Create Create a new entry if not found - - @return Protocol entry - -**/ -PROTOCOL_ENTRY * -UnitTestFindProtocolEntry ( - IN EFI_GUID *Protocol, - IN BOOLEAN Create - ) -{ - LIST_ENTRY *Link; - PROTOCOL_ENTRY *Item; - PROTOCOL_ENTRY *ProtEntry; - - // - // Search the database for the matching GUID - // - - ProtEntry =3D NULL; - for (Link =3D mProtocolDatabase.ForwardLink; - Link !=3D &mProtocolDatabase; - Link =3D Link->ForwardLink) - { - Item =3D CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATUR= E); - if (CompareGuid (&Item->ProtocolID, Protocol)) { - // - // This is the protocol entry - // - - ProtEntry =3D Item; - break; - } - } - - // - // If the protocol entry was not found and Create is TRUE, then - // allocate a new entry - // - if ((ProtEntry =3D=3D NULL) && Create) { - ProtEntry =3D AllocatePool (sizeof (PROTOCOL_ENTRY)); - - if (ProtEntry !=3D NULL) { - // - // Initialize new protocol entry structure - // - ProtEntry->Signature =3D PROTOCOL_ENTRY_SIGNATURE; - CopyGuid ((VOID *)&ProtEntry->ProtocolID, Protocol); - InitializeListHead (&ProtEntry->Protocols); - InitializeListHead (&ProtEntry->Notify); - - // - // Add it to protocol database - // - InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries); - } - } - - return ProtEntry; -} - -/** - Finds the protocol instance for the requested handle and protocol. - Note: This function doesn't do parameters checking, it's caller's respon= sibility - to pass in valid parameters. - - @param Handle The handle to search the protocol on - @param Protocol GUID of the protocol - @param Interface The interface for the protocol being sear= ched - - @return Protocol instance (NULL: Not found) - -**/ -PROTOCOL_INTERFACE * -UnitTestFindProtocolInterface ( - IN IHANDLE *Handle, - IN EFI_GUID *Protocol, - IN VOID *Interface - ) -{ - PROTOCOL_INTERFACE *Prot; - PROTOCOL_ENTRY *ProtEntry; - LIST_ENTRY *Link; - - Prot =3D NULL; - - // - // Lookup the protocol entry for this protocol ID - // - - ProtEntry =3D UnitTestFindProtocolEntry (Protocol, FALSE); - if (ProtEntry !=3D NULL) { - // - // Look at each protocol interface for any matches - // - for (Link =3D Handle->Protocols.ForwardLink; Link !=3D &Handle->Protoc= ols; Link =3D Link->ForwardLink) { - // - // If this protocol interface matches, remove it - // - Prot =3D CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGN= ATURE); - if ((Prot->Interface =3D=3D Interface) && (Prot->Protocol =3D=3D Pro= tEntry)) { - break; - } - - Prot =3D NULL; - } - } - - return Prot; -} - -/** - Signal event for every protocol in protocol entry. - - @param ProtEntry Protocol entry - -**/ -VOID -UnitTestNotifyProtocolEntry ( - IN PROTOCOL_ENTRY *ProtEntry - ) -{ - PROTOCOL_NOTIFY *ProtNotify; - LIST_ENTRY *Link; - - for (Link =3D ProtEntry->Notify.ForwardLink; Link !=3D &ProtEntry->Notif= y; Link =3D Link->ForwardLink) { - ProtNotify =3D CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNAT= URE); - UnitTestSignalEvent (ProtNotify->Event); - } -} - -/** - Routine to get the next Handle, when you are searching for all handles. - - @param Position Information about which Handle to seach f= or. - @param Interface Return the interface structure for the ma= tching - protocol. - - @return An pointer to IHANDLE if the next Position is not the end of the= list. - Otherwise,NULL is returned. - -**/ -IHANDLE * -UnitTestGetNextLocateAllHandles ( - IN OUT LOCATE_POSITION *Position, - OUT VOID **Interface - ) -{ - IHANDLE *Handle; - - // - // Next handle - // - Position->Position =3D Position->Position->ForwardLink; - - // - // If not at the end of the list, get the handle - // - Handle =3D NULL; - *Interface =3D NULL; - if (Position->Position !=3D &gHandleList) { - Handle =3D CR (Position->Position, IHANDLE, AllHandles, EFI_HANDLE_SIG= NATURE); - } - - return Handle; -} - -/** - Routine to get the next Handle, when you are searching for register prot= ocol - notifies. - - @param Position Information about which Handle to seach f= or. - @param Interface Return the interface structure for the ma= tching - protocol. - - @return An pointer to IHANDLE if the next Position is not the end of the= list. - Otherwise,NULL is returned. - -**/ -IHANDLE * -UnitTestGetNextLocateByRegisterNotify ( - IN OUT LOCATE_POSITION *Position, - OUT VOID **Interface - ) -{ - IHANDLE *Handle; - PROTOCOL_NOTIFY *ProtNotify; - PROTOCOL_INTERFACE *Prot; - LIST_ENTRY *Link; - - Handle =3D NULL; - *Interface =3D NULL; - ProtNotify =3D Position->SearchKey; - - // - // If this is the first request, get the next handle - // - if (ProtNotify !=3D NULL) { - ASSERT (ProtNotify->Signature =3D=3D PROTOCOL_NOTIFY_SIGNATURE); - Position->SearchKey =3D NULL; - - // - // If not at the end of the list, get the next handle - // - Link =3D ProtNotify->Position->ForwardLink; - if (Link !=3D &ProtNotify->Protocol->Protocols) { - Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_IN= TERFACE_SIGNATURE); - Handle =3D Prot->Handle; - *Interface =3D Prot->Interface; - } - } - - return Handle; -} - -/** - Routine to get the next Handle, when you are searching for a given proto= col. - - @param Position Information about which Handle to seach f= or. - @param Interface Return the interface structure for the ma= tching - protocol. - - @return An pointer to IHANDLE if the next Position is not the end of the= list. - Otherwise,NULL is returned. - -**/ -IHANDLE * -UnitTestGetNextLocateByProtocol ( - IN OUT LOCATE_POSITION *Position, - OUT VOID **Interface - ) -{ - IHANDLE *Handle; - LIST_ENTRY *Link; - PROTOCOL_INTERFACE *Prot; - - Handle =3D NULL; - *Interface =3D NULL; - for ( ; ;) { - // - // Next entry - // - Link =3D Position->Position->ForwardLink; - Position->Position =3D Link; - - // - // If not at the end, return the handle - // - if (Link =3D=3D &Position->ProtEntry->Protocols) { - Handle =3D NULL; - break; - } - - // - // Get the handle - // - Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTE= RFACE_SIGNATURE); - Handle =3D Prot->Handle; - *Interface =3D Prot->Interface; - - // - // If this handle has not been returned this request, then - // return it now - // - if (Handle->LocateRequest !=3D mEfiLocateHandleRequest) { - Handle->LocateRequest =3D mEfiLocateHandleRequest; - break; - } - } - - return Handle; -} - -/** - Attempts to disconnect all drivers that are using the protocol interface= being queried. - If failed, reconnect all drivers disconnected. - Note: This function doesn't do parameters checking, it's caller's respon= sibility - to pass in valid parameters. - - @param UserHandle The handle on which the protocol is insta= lled - @param Prot The protocol to disconnect drivers from - - @retval EFI_SUCCESS Drivers using the protocol interface are = all - disconnected - @retval EFI_ACCESS_DENIED Failed to disconnect one or all of the dr= ivers - -**/ -EFI_STATUS -UnitTestDisconnectControllersUsingProtocolInterface ( - IN EFI_HANDLE UserHandle, - IN PROTOCOL_INTERFACE *Prot - ) -{ - EFI_STATUS Status; - BOOLEAN ItemFound; - LIST_ENTRY *Link; - OPEN_PROTOCOL_DATA *OpenData; - - Status =3D EFI_SUCCESS; - - // - // Attempt to disconnect all drivers from this protocol interface - // - do { - ItemFound =3D FALSE; - for (Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenList; L= ink =3D Link->ForwardLink) { - OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_= SIGNATURE); - if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) !=3D 0) { - Status =3D UnitTestDisconnectController (UserHandle, OpenData->Age= ntHandle, NULL); - if (!EFI_ERROR (Status)) { - ItemFound =3D TRUE; - } - - break; - } - } - } while (ItemFound); - - if (!EFI_ERROR (Status)) { - // - // Attempt to remove BY_HANDLE_PROTOCOL and GET_PROTOCOL and TEST_PROT= OCOL Open List items - // - for (Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenList;) { - OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_= SIGNATURE); - if ((OpenData->Attributes & - (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_P= ROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) !=3D 0) - { - Link =3D RemoveEntryList (&OpenData->Link); - Prot->OpenListCount--; - FreePool (OpenData); - } else { - Link =3D Link->ForwardLink; - } - } - } - - // - // If there are errors or still has open items in the list, then reconne= ct all the drivers and return an error - // - if (EFI_ERROR (Status) || (Prot->OpenListCount > 0)) { - UnitTestConnectController (UserHandle, NULL, NULL, TRUE); - Status =3D EFI_ACCESS_DENIED; - } - - return Status; -} - -/** - Removes Protocol from the protocol list (but not the handle list). - - @param Handle The handle to remove protocol on. - @param Protocol GUID of the protocol to be moved - @param Interface The interface of the protocol - - @return Protocol Entry - -**/ -PROTOCOL_INTERFACE * -UnitTestRemoveInterfaceFromProtocol ( - IN IHANDLE *Handle, - IN EFI_GUID *Protocol, - IN VOID *Interface - ) -{ - PROTOCOL_INTERFACE *Prot; - PROTOCOL_NOTIFY *ProtNotify; - PROTOCOL_ENTRY *ProtEntry; - LIST_ENTRY *Link; - - Prot =3D UnitTestFindProtocolInterface (Handle, Protocol, Interface); - if (Prot !=3D NULL) { - ProtEntry =3D Prot->Protocol; - - // - // If there's a protocol notify location pointing to this entry, back = it up one - // - for (Link =3D ProtEntry->Notify.ForwardLink; Link !=3D &ProtEntry->Not= ify; Link =3D Link->ForwardLink) { - ProtNotify =3D CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGN= ATURE); - - if (ProtNotify->Position =3D=3D &Prot->ByProtocol) { - ProtNotify->Position =3D Prot->ByProtocol.BackLink; - } - } - - // - // Remove the protocol interface entry - // - RemoveEntryList (&Prot->ByProtocol); - } - - return Prot; -} - -// -// Boot Services Function Implementation -// - -/** - Locate a certain GUID protocol interface in a Handle's protocols. - - @param UserHandle The handle to obtain the protocol interfa= ce on - @param Protocol The GUID of the protocol - - @return The requested protocol interface for the handle - -**/ -PROTOCOL_INTERFACE * -UnitTestGetProtocolInterface ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol - ) -{ - EFI_STATUS Status; - PROTOCOL_ENTRY *ProtEntry; - PROTOCOL_INTERFACE *Prot; - IHANDLE *Handle; - LIST_ENTRY *Link; - - Status =3D UnitTestValidateHandle (UserHandle); - if (EFI_ERROR (Status)) { - return NULL; - } - - Handle =3D (IHANDLE *)UserHandle; - - // - // Look at each protocol interface for a match - // - for (Link =3D Handle->Protocols.ForwardLink; Link !=3D &Handle->Protocol= s; Link =3D Link->ForwardLink) { - Prot =3D CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_S= IGNATURE); - ProtEntry =3D Prot->Protocol; - if (CompareGuid (&ProtEntry->ProtocolID, Protocol)) { - return Prot; - } - } - - return NULL; -} - -/** - Installs a protocol interface into the boot services environment. - - @param UserHandle The handle to install the protocol handle= r on, - or NULL if a new handle is to be allocated - @param Protocol The protocol to add to the handle - @param InterfaceType Indicates whether Interface is supplied in - native form. - @param Interface The interface for the protocol being added - @param Notify indicates whether notify the notification= list - for this protocol - - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate - @retval EFI_SUCCESS Protocol interface successfully installed - -**/ -EFI_STATUS -UnitTestInstallProtocolInterfaceNotify ( - IN OUT EFI_HANDLE *UserHandle, - IN EFI_GUID *Protocol, - IN EFI_INTERFACE_TYPE InterfaceType, - IN VOID *Interface, - IN BOOLEAN Notify - ) -{ - PROTOCOL_INTERFACE *Prot; - PROTOCOL_ENTRY *ProtEntry; - IHANDLE *Handle; - EFI_STATUS Status; - VOID *ExistingInterface; - - // - // returns EFI_INVALID_PARAMETER if InterfaceType is invalid. - // Also added check for invalid UserHandle and Protocol pointers. - // - if ((UserHandle =3D=3D NULL) || (Protocol =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - if (InterfaceType !=3D EFI_NATIVE_INTERFACE) { - return EFI_INVALID_PARAMETER; - } - - // - // Print debug message - // - UT_LOG_INFO ("InstallProtocolInterface: %g %p\n", Protocol, Interface); - - Status =3D EFI_OUT_OF_RESOURCES; - Prot =3D NULL; - Handle =3D NULL; - - if (*UserHandle !=3D NULL) { - Status =3D UnitTestHandleProtocol (*UserHandle, Protocol, (VOID **)&Ex= istingInterface); - if (!EFI_ERROR (Status)) { - return EFI_INVALID_PARAMETER; - } - } - - // - // Lookup the Protocol Entry for the requested protocol - // - ProtEntry =3D UnitTestFindProtocolEntry (Protocol, TRUE); - if (ProtEntry =3D=3D NULL) { - goto Done; - } - - // - // Allocate a new protocol interface structure - // - Prot =3D AllocateZeroPool (sizeof (PROTOCOL_INTERFACE)); - if (Prot =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto Done; - } - - // - // If caller didn't supply a handle, allocate a new one - // - Handle =3D (IHANDLE *)*UserHandle; - if (Handle =3D=3D NULL) { - Handle =3D AllocateZeroPool (sizeof (IHANDLE)); - if (Handle =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto Done; - } - - // - // Initialize new handler structure - // - Handle->Signature =3D EFI_HANDLE_SIGNATURE; - InitializeListHead (&Handle->Protocols); - - // - // Initialize the Key to show that the handle has been created/modified - // - gHandleDatabaseKey++; - Handle->Key =3D gHandleDatabaseKey; - - // - // Add this handle to the list global list of all handles - // in the system - // - InsertTailList (&gHandleList, &Handle->AllHandles); - } else { - Status =3D UnitTestValidateHandle (Handle); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "InstallProtocolInterface: input handle at 0x%x= is invalid\n", Handle)); - goto Done; - } - } - - // - // Each interface that is added must be unique - // - ASSERT (UnitTestFindProtocolInterface (Handle, Protocol, Interface) =3D= =3D NULL); - - // - // Initialize the protocol interface structure - // - Prot->Signature =3D PROTOCOL_INTERFACE_SIGNATURE; - Prot->Handle =3D Handle; - Prot->Protocol =3D ProtEntry; - Prot->Interface =3D Interface; - - // - // Initialize OpenProtocol Data base - // - InitializeListHead (&Prot->OpenList); - Prot->OpenListCount =3D 0; - - // - // Add this protocol interface to the head of the supported - // protocol list for this handle - // - InsertHeadList (&Handle->Protocols, &Prot->Link); - - // - // Add this protocol interface to the tail of the - // protocol entry - // - InsertTailList (&ProtEntry->Protocols, &Prot->ByProtocol); - - // - // Notify the notification list for this protocol - // - if (Notify) { - UnitTestNotifyProtocolEntry (ProtEntry); - } - - Status =3D EFI_SUCCESS; - -Done: - if (!EFI_ERROR (Status)) { - // - // Return the new handle back to the caller - // - *UserHandle =3D Handle; - } else { - // - // There was an error, clean up - // - if (Prot !=3D NULL) { - UnitTestFreePool (Prot); - } - - DEBUG ((DEBUG_ERROR, "InstallProtocolInterface: %g %p failed with %r\n= ", Protocol, Interface, Status)); - } - - return Status; -} - -/** - Wrapper function to UnitTestInstallProtocolInterfaceNotify. This is the= public API which - Calls the private one which contains a BOOLEAN parameter for notificatio= ns - - @param UserHandle The handle to install the protocol handle= r on, - or NULL if a new handle is to be allocated - @param Protocol The protocol to add to the handle - @param InterfaceType Indicates whether Interface is supplied in - native form. - @param Interface The interface for the protocol being added - - @return Status code - -**/ -EFI_STATUS -EFIAPI -UnitTestInstallProtocolInterface ( - IN OUT EFI_HANDLE *UserHandle, - IN EFI_GUID *Protocol, - IN EFI_INTERFACE_TYPE InterfaceType, - IN VOID *Interface - ) -{ - return UnitTestInstallProtocolInterfaceNotify ( - UserHandle, - Protocol, - InterfaceType, - Interface, - TRUE - ); -} - -/** - Reinstall a protocol interface on a device handle. The OldInterface for= Protocol is replaced by the NewInterface. - - @param UserHandle Handle on which the interface is to be - reinstalled - @param Protocol The numeric ID of the interface - @param OldInterface A pointer to the old interface - @param NewInterface A pointer to the new interface - - @retval EFI_SUCCESS The protocol interface was installed - @retval EFI_NOT_FOUND The OldInterface on the handle was not fo= und - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value - -**/ -EFI_STATUS -EFIAPI -UnitTestReinstallProtocolInterface ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - IN VOID *OldInterface, - IN VOID *NewInterface - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Uninstalls all instances of a protocol:interfacer from a handle. - If the last protocol interface is remove from the handle, the - handle is freed. - - @param UserHandle The handle to remove the protocol handler= from - @param Protocol The protocol, of protocol:interface, to r= emove - @param Interface The interface, of protocol:interface, to = remove - - @retval EFI_INVALID_PARAMETER Protocol is NULL. - @retval EFI_SUCCESS Protocol interface successfully uninstall= ed. - -**/ -EFI_STATUS -EFIAPI -UnitTestUninstallProtocolInterface ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - IN VOID *Interface - ) -{ - EFI_STATUS Status; - IHANDLE *Handle; - PROTOCOL_INTERFACE *Prot; - - // - // Check that Protocol is valid - // - if (Protocol =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Check that UserHandle is a valid handle - // - Status =3D UnitTestValidateHandle (UserHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Check that Protocol exists on UserHandle, and Interface matches the i= nterface in the database - // - Prot =3D UnitTestFindProtocolInterface (UserHandle, Protocol, Interface); - if (Prot =3D=3D NULL) { - Status =3D EFI_NOT_FOUND; - goto Done; - } - - // - // Attempt to disconnect all drivers that are using the protocol interfa= ce that is about to be removed - // - Status =3D UnitTestDisconnectControllersUsingProtocolInterface ( - UserHandle, - Prot - ); - if (EFI_ERROR (Status)) { - // - // One or more drivers refused to release, so return the error - // - goto Done; - } - - // - // Remove the protocol interface from the protocol - // - Status =3D EFI_NOT_FOUND; - Handle =3D (IHANDLE *)UserHandle; - Prot =3D UnitTestRemoveInterfaceFromProtocol (Handle, Protocol, Interf= ace); - - if (Prot !=3D NULL) { - // - // Update the Key to show that the handle has been created/modified - // - gHandleDatabaseKey++; - Handle->Key =3D gHandleDatabaseKey; - - // - // Remove the protocol interface from the handle - // - RemoveEntryList (&Prot->Link); - - // - // Free the memory - // - Prot->Signature =3D 0; - FreePool (Prot); - Status =3D EFI_SUCCESS; - } - - // - // If there are no more handlers for the handle, free the handle - // - if (IsListEmpty (&Handle->Protocols)) { - Handle->Signature =3D 0; - RemoveEntryList (&Handle->AllHandles); - FreePool (Handle); - } - -Done: - return Status; -} - -/** - Queries a handle to determine if it supports a specified protocol. - - @param UserHandle The handle being queried. - @param Protocol The published unique identifier of the pr= otocol. - @param Interface Supplies the address where a pointer to t= he - corresponding Protocol Interface is retur= ned. - - @return The requested protocol interface for the handle - -**/ -EFI_STATUS -EFIAPI -UnitTestHandleProtocol ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - OUT VOID **Interface - ) -{ - return UnitTestOpenProtocol ( - UserHandle, - Protocol, - Interface, - gImageHandle, - NULL, - EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL - ); -} - -/** - Add a new protocol notification record for the request protocol. - - @param Protocol The requested protocol to add the notify - registration - @param Event The event to signal - @param Registration Returns the registration record - - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_SUCCESS Successfully returned the registration re= cord - that has been added - -**/ -EFI_STATUS -EFIAPI -UnitTestRegisterProtocolNotify ( - IN EFI_GUID *Protocol, - IN EFI_EVENT Event, - OUT VOID **Registration - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Locates the requested handle(s) and returns them in Buffer. - - @param SearchType The type of search to perform to locate t= he - handles - @param Protocol The protocol to search for - @param SearchKey Dependant on SearchType - @param BufferSize On input the size of Buffer. On output t= he - size of data returned. - @param Buffer The buffer to return the results in - - @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is - returned in BufferSize. - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_SUCCESS Successfully found the requested handle(s= ) and - returns them in Buffer. - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateHandle ( - IN EFI_LOCATE_SEARCH_TYPE SearchType, - IN EFI_GUID *Protocol OPTIONAL, - IN VOID *SearchKey OPTIONAL, - IN OUT UINTN *BufferSize, - OUT EFI_HANDLE *Buffer - ) -{ - EFI_STATUS Status; - LOCATE_POSITION Position; - PROTOCOL_NOTIFY *ProtNotify; - UNIT_TEST_GET_NEXT GetNext; - UINTN ResultSize; - IHANDLE *Handle; - IHANDLE **ResultBuffer; - VOID *Interface; - - if (BufferSize =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - if ((*BufferSize > 0) && (Buffer =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - GetNext =3D NULL; - - // - // Set initial position - // - Position.Protocol =3D Protocol; - Position.SearchKey =3D SearchKey; - Position.Position =3D &gHandleList; - - ResultSize =3D 0; - ResultBuffer =3D (IHANDLE **)Buffer; - Status =3D EFI_SUCCESS; - - // - // Get the search function based on type - // - switch (SearchType) { - case AllHandles: - GetNext =3D UnitTestGetNextLocateAllHandles; - break; - - case ByRegisterNotify: - // - // Must have SearchKey for locate ByRegisterNotify - // - if (SearchKey =3D=3D NULL) { - Status =3D EFI_INVALID_PARAMETER; - break; - } - - GetNext =3D UnitTestGetNextLocateByRegisterNotify; - break; - - case ByProtocol: - GetNext =3D UnitTestGetNextLocateByProtocol; - if (Protocol =3D=3D NULL) { - Status =3D EFI_INVALID_PARAMETER; - break; - } - - // - // Look up the protocol entry and set the head pointer - // - Position.ProtEntry =3D UnitTestFindProtocolEntry (Protocol, FALSE); - if (Position.ProtEntry =3D=3D NULL) { - Status =3D EFI_NOT_FOUND; - break; - } - - Position.Position =3D &Position.ProtEntry->Protocols; - break; - - default: - Status =3D EFI_INVALID_PARAMETER; - break; - } - - if (EFI_ERROR (Status)) { - return Status; - } - - ASSERT (GetNext !=3D NULL); - // - // Enumerate out the matching handles - // - mEfiLocateHandleRequest +=3D 1; - for ( ; ;) { - // - // Get the next handle. If no more handles, stop - // - Handle =3D GetNext (&Position, &Interface); - if (NULL =3D=3D Handle) { - break; - } - - // - // Increase the resulting buffer size, and if this handle - // fits return it - // - ResultSize +=3D sizeof (Handle); - if (ResultSize <=3D *BufferSize) { - *ResultBuffer =3D Handle; - ResultBuffer +=3D 1; - } - } - - // - // If the result is a zero length buffer, then there were no - // matching handles - // - if (ResultSize =3D=3D 0) { - Status =3D EFI_NOT_FOUND; - } else { - // - // Return the resulting buffer size. If it's larger than what - // was passed, then set the error code - // - if (ResultSize > *BufferSize) { - Status =3D EFI_BUFFER_TOO_SMALL; - } - - *BufferSize =3D ResultSize; - - if ((SearchType =3D=3D ByRegisterNotify) && !EFI_ERROR (Status)) { - // - // If this is a search by register notify and a handle was - // returned, update the register notification position - // - ASSERT (SearchKey !=3D NULL); - ProtNotify =3D SearchKey; - ProtNotify->Position =3D ProtNotify->Position->ForwardLink; - } - } - - return Status; -} - -/** - Locates the handle to a device on the device path that best matches the = specified protocol. - - @param Protocol The protocol to search for. - @param DevicePath On input, a pointer to a pointer to the d= evice - path. On output, the device path pointer = is - modified to point to the remaining part o= f the - devicepath. - @param Device A pointer to the returned device handle. - - @retval EFI_SUCCESS The resulting handle was returned. - @retval EFI_NOT_FOUND No handles matched the search. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateDevicePath ( - IN EFI_GUID *Protocol, - IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, - OUT EFI_HANDLE *Device - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Boot Service called to add, modify, or remove a system configuration tab= le from - the EFI System Table. - - @param Guid Pointer to the GUID for the entry to add, update,= or - remove - @param Table Pointer to the configuration table for the entry = to add, - update, or remove, may be NULL. - - @return EFI_SUCCESS Guid, Table pair added, updated, or re= moved. - @return EFI_INVALID_PARAMETER Input GUID not valid. - @return EFI_NOT_FOUND Attempted to delete non-existant entry - @return EFI_OUT_OF_RESOURCES Not enough memory available - -**/ -EFI_STATUS -EFIAPI -UnitTestInstallConfigurationTable ( - IN EFI_GUID *Guid, - IN VOID *Table - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Locates the installed protocol handler for the handle, and - invokes it to obtain the protocol interface. Usage information - is registered in the protocol data base. - - @param UserHandle The handle to obtain the protocol interfa= ce on - @param Protocol The ID of the protocol - @param Interface The location to return the protocol inter= face - @param ImageHandle The handle of the Image that is opening t= he - protocol interface specified by Protocol = and - Interface. - @param ControllerHandle The controller handle that is requiring t= his - interface. - @param Attributes The open mode of the protocol interface - specified by Handle and Protocol. - - @retval EFI_INVALID_PARAMETER Protocol is NULL. - @retval EFI_SUCCESS Get the protocol interface. - -**/ -EFI_STATUS -EFIAPI -UnitTestOpenProtocol ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - OUT VOID **Interface OPTIONAL, - IN EFI_HANDLE ImageHandle, - IN EFI_HANDLE ControllerHandle, - IN UINT32 Attributes - ) -{ - EFI_STATUS Status; - PROTOCOL_INTERFACE *Prot; - LIST_ENTRY *Link; - OPEN_PROTOCOL_DATA *OpenData; - BOOLEAN ByDriver; - BOOLEAN Exclusive; - BOOLEAN Disconnect; - BOOLEAN ExactMatch; - - // - // Check for invalid Protocol - // - if (Protocol =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Check for invalid Interface - // - if ((Attributes !=3D EFI_OPEN_PROTOCOL_TEST_PROTOCOL) && (Interface =3D= =3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - // - // Check for invalid UserHandle - // - Status =3D UnitTestValidateHandle (UserHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Check for invalid Attributes - // - switch (Attributes) { - case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: - Status =3D UnitTestValidateHandle (ImageHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D UnitTestValidateHandle (ControllerHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - if (UserHandle =3D=3D ControllerHandle) { - return EFI_INVALID_PARAMETER; - } - - break; - case EFI_OPEN_PROTOCOL_BY_DRIVER: - case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: - Status =3D UnitTestValidateHandle (ImageHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D UnitTestValidateHandle (ControllerHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - break; - case EFI_OPEN_PROTOCOL_EXCLUSIVE: - Status =3D UnitTestValidateHandle (ImageHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - break; - case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: - case EFI_OPEN_PROTOCOL_GET_PROTOCOL: - case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: - break; - default: - return EFI_INVALID_PARAMETER; - } - - // - // Look at each protocol interface for a match - // - Prot =3D UnitTestGetProtocolInterface (UserHandle, Protocol); - if (Prot =3D=3D NULL) { - Status =3D EFI_UNSUPPORTED; - goto Done; - } - - Status =3D EFI_SUCCESS; - - ByDriver =3D FALSE; - Exclusive =3D FALSE; - for ( Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenList; Li= nk =3D Link->ForwardLink) { - OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_= SIGNATURE); - ExactMatch =3D (BOOLEAN)((OpenData->AgentHandle =3D=3D ImageHandle) && - (OpenData->Attributes =3D=3D Attributes) && - (OpenData->ControllerHandle =3D=3D ControllerH= andle)); - if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) !=3D 0) { - ByDriver =3D TRUE; - if (ExactMatch) { - Status =3D EFI_ALREADY_STARTED; - goto Done; - } - } - - if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) !=3D 0) { - Exclusive =3D TRUE; - } else if (ExactMatch) { - OpenData->OpenCount++; - Status =3D EFI_SUCCESS; - goto Done; - } - } - - // - // ByDriver TRUE -> A driver is managing (UserHandle, Protocol) - // ByDriver FALSE -> There are no drivers managing (UserHandle, Protoco= l) - // Exclusive TRUE -> Something has exclusive access to (UserHandle, Pro= tocol) - // Exclusive FALSE -> Nothing has exclusive access to (UserHandle, Proto= col) - // - - switch (Attributes) { - case EFI_OPEN_PROTOCOL_BY_DRIVER: - if (Exclusive || ByDriver) { - Status =3D EFI_ACCESS_DENIED; - goto Done; - } - - break; - case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: - case EFI_OPEN_PROTOCOL_EXCLUSIVE: - if (Exclusive) { - Status =3D EFI_ACCESS_DENIED; - goto Done; - } - - if (ByDriver) { - do { - Disconnect =3D FALSE; - for (Link =3D Prot->OpenList.ForwardLink; Link !=3D &Prot->OpenL= ist; Link =3D Link->ForwardLink) { - OpenData =3D CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL= _DATA_SIGNATURE); - if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) !=3D = 0) { - Disconnect =3D TRUE; - Status =3D UnitTestDisconnectController (UserHandle, Ope= nData->AgentHandle, NULL); - if (EFI_ERROR (Status)) { - Status =3D EFI_ACCESS_DENIED; - goto Done; - } else { - break; - } - } - } - } while (Disconnect); - } - - break; - case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: - case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: - case EFI_OPEN_PROTOCOL_GET_PROTOCOL: - case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: - break; - } - - if (ImageHandle =3D=3D NULL) { - Status =3D EFI_SUCCESS; - goto Done; - } - - // - // Create new entry - // - OpenData =3D AllocatePool (sizeof (OPEN_PROTOCOL_DATA)); - if (OpenData =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - } else { - OpenData->Signature =3D OPEN_PROTOCOL_DATA_SIGNATURE; - OpenData->AgentHandle =3D ImageHandle; - OpenData->ControllerHandle =3D ControllerHandle; - OpenData->Attributes =3D Attributes; - OpenData->OpenCount =3D 1; - InsertTailList (&Prot->OpenList, &OpenData->Link); - Prot->OpenListCount++; - Status =3D EFI_SUCCESS; - } - -Done: - - if (Attributes !=3D EFI_OPEN_PROTOCOL_TEST_PROTOCOL) { - // - // Keep Interface unmodified in case of any Error - // except EFI_ALREADY_STARTED and EFI_UNSUPPORTED. - // - if (!EFI_ERROR (Status) || (Status =3D=3D EFI_ALREADY_STARTED)) { - // - // According to above logic, if 'Prot' is NULL, then the 'Status' mu= st be - // EFI_UNSUPPORTED. Here the 'Status' is not EFI_UNSUPPORTED, so 'Pr= ot' - // must be not NULL. - // - // The ASSERT here is for addressing a false positive NULL pointer - // dereference issue raised from static analysis. - // - ASSERT (Prot !=3D NULL); - // - // EFI_ALREADY_STARTED is not an error for bus driver. - // Return the corresponding protocol interface. - // - *Interface =3D Prot->Interface; - } else if (Status =3D=3D EFI_UNSUPPORTED) { - // - // Return NULL Interface if Unsupported Protocol. - // - *Interface =3D NULL; - } - } - - return Status; -} - -/** - Closes a protocol on a handle that was opened using OpenProtocol(). - - @param UserHandle The handle for the protocol interface tha= t was - previously opened with OpenProtocol(), an= d is - now being closed. - @param Protocol The published unique identifier of the pr= otocol. - It is the caller's responsibility to pass= in a - valid GUID. - @param AgentHandle The handle of the agent that is closing t= he - protocol interface. - @param ControllerHandle If the agent that opened a protocol is a = driver - that follows the EFI Driver Model, then t= his - parameter is the controller handle that r= equired - the protocol interface. If the agent does= not - follow the EFI Driver Model, then this pa= rameter - is optional and may be NULL. - - @retval EFI_SUCCESS The protocol instance was closed. - @retval EFI_INVALID_PARAMETER Handle, AgentHandle or ControllerHandle i= s not a - valid EFI_HANDLE. - @retval EFI_NOT_FOUND Can not find the specified protocol or - AgentHandle. - -**/ -EFI_STATUS -EFIAPI -UnitTestCloseProtocol ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - IN EFI_HANDLE AgentHandle, - IN EFI_HANDLE ControllerHandle - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Return information about Opened protocols in the system - - @param UserHandle The handle to close the protocol interfac= e on - @param Protocol The ID of the protocol - @param EntryBuffer A pointer to a buffer of open protocol - information in the form of - EFI_OPEN_PROTOCOL_INFORMATION_ENTRY struc= tures. - @param EntryCount Number of EntryBuffer entries - -**/ -EFI_STATUS -EFIAPI -UnitTestOpenProtocolInformation ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, - OUT UINTN *EntryCount - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Retrieves the list of protocol interface GUIDs that are installed on a h= andle in a buffer allocated - from pool. - - @param UserHandle The handle from which to retrieve the lis= t of - protocol interface GUIDs. - @param ProtocolBuffer A pointer to the list of protocol interfa= ce GUID - pointers that are installed on Handle. - @param ProtocolBufferCount A pointer to the number of GUID pointers = present - in ProtocolBuffer. - - @retval EFI_SUCCESS The list of protocol interface GUIDs inst= alled - on Handle was returned in ProtocolBuffer.= The - number of protocol interface GUIDs was re= turned - in ProtocolBufferCount. - @retval EFI_INVALID_PARAMETER Handle is NULL. - @retval EFI_INVALID_PARAMETER Handle is not a valid EFI_HANDLE. - @retval EFI_INVALID_PARAMETER ProtocolBuffer is NULL. - @retval EFI_INVALID_PARAMETER ProtocolBufferCount is NULL. - @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the - results. - -**/ -EFI_STATUS -EFIAPI -UnitTestProtocolsPerHandle ( - IN EFI_HANDLE UserHandle, - OUT EFI_GUID ***ProtocolBuffer, - OUT UINTN *ProtocolBufferCount - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Function returns an array of handles that support the requested protocol - in a buffer allocated from pool. This is a version of UnitTestLocateHand= le() - that allocates a buffer for the caller. - - @param SearchType Specifies which handle(s) are to be retur= ned. - @param Protocol Provides the protocol to search by. Th= is - parameter is only valid for SearchType - ByProtocol. - @param SearchKey Supplies the search key depending on the - SearchType. - @param NumberHandles The number of handles returned in Buffer. - @param Buffer A pointer to the buffer to return the req= uested - array of handles that support Protocol. - - @retval EFI_SUCCESS The result array of handles was returned. - @retval EFI_NOT_FOUND No handles match the search. - @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the - matching results. - @retval EFI_INVALID_PARAMETER One or more parameters are not valid. - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateHandleBuffer ( - IN EFI_LOCATE_SEARCH_TYPE SearchType, - IN EFI_GUID *Protocol OPTIONAL, - IN VOID *SearchKey OPTIONAL, - IN OUT UINTN *NumberHandles, - OUT EFI_HANDLE **Buffer - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - - if (NumberHandles =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - if (Buffer =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - BufferSize =3D 0; - *NumberHandles =3D 0; - *Buffer =3D NULL; - Status =3D UnitTestLocateHandle ( - SearchType, - Protocol, - SearchKey, - &BufferSize, - *Buffer - ); - // - // LocateHandleBuffer() returns incorrect status code if SearchType is - // invalid. - // - // Add code to correctly handle expected errors from UnitTestLocateHandl= e(). - // - if (EFI_ERROR (Status) && (Status !=3D EFI_BUFFER_TOO_SMALL)) { - if (Status !=3D EFI_INVALID_PARAMETER) { - Status =3D EFI_NOT_FOUND; - } - - return Status; - } - - *Buffer =3D AllocatePool (BufferSize); - if (*Buffer =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Status =3D UnitTestLocateHandle ( - SearchType, - Protocol, - SearchKey, - &BufferSize, - *Buffer - ); - - *NumberHandles =3D BufferSize / sizeof (EFI_HANDLE); - if (EFI_ERROR (Status)) { - *NumberHandles =3D 0; - } - - return Status; -} - -/** - Return the first Protocol Interface that matches the Protocol GUID. If - Registration is passed in, return a Protocol Instance that was just add - to the system. If Registration is NULL return the first Protocol Interfa= ce - you find. - - @param Protocol The protocol to search for - @param Registration Optional Registration Key returned from - RegisterProtocolNotify() - @param Interface Return the Protocol interface (instance). - - @retval EFI_SUCCESS If a valid Interface is returned - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_NOT_FOUND Protocol interface not found - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateProtocol ( - IN EFI_GUID *Protocol, - IN VOID *Registration OPTIONAL, - OUT VOID **Interface - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Installs a list of protocol interface into the boot services environment. - This function calls InstallProtocolInterface() in a loop. If any error - occurs all the protocols added by this function are removed. This is - basically a lib function to save space. - - @param Handle The handle to install the protocol handle= rs on, - or NULL if a new handle is to be allocated - @param ... EFI_GUID followed by protocol instance. A= NULL - terminates the list. The pairs are the - arguments to InstallProtocolInterface(). = All the - protocols are added to Handle. - - @retval EFI_SUCCESS All the protocol interface was installed. - @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to in= stall all the protocols. - @retval EFI_ALREADY_STARTED A Device Path Protocol instance was passe= d in that is already present in - the handle database. - @retval EFI_INVALID_PARAMETER Handle is NULL. - @retval EFI_INVALID_PARAMETER Protocol is already installed on the hand= le specified by Handle. - -**/ -EFI_STATUS -EFIAPI -UnitTestInstallMultipleProtocolInterfaces ( - IN OUT EFI_HANDLE *Handle, - ... - ) -{ - return EFI_NOT_AVAILABLE_YET; -} - -/** - Uninstalls a list of protocol interface in the boot services environment. - This function calls UninstallProtocolInterface() in a loop. This is - basically a lib function to save space. - - @param Handle The handle to uninstall the protocol - @param ... EFI_GUID followed by protocol instance. A= NULL - terminates the list. The pairs are the - arguments to UninstallProtocolInterface()= . All - the protocols are added to Handle. - - @return Status code - -**/ -EFI_STATUS -EFIAPI -UnitTestUninstallMultipleProtocolInterfaces ( - IN EFI_HANDLE Handle, - ... - ) -{ - EFI_STATUS Status; - VA_LIST Args; - EFI_GUID *Protocol; - VOID *Interface; - UINTN Index; - - VA_START (Args, Handle); - for (Index =3D 0, Status =3D EFI_SUCCESS; !EFI_ERROR (Status); Index++) { - // - // If protocol is NULL, then it's the end of the list - // - Protocol =3D VA_ARG (Args, EFI_GUID *); - if (Protocol =3D=3D NULL) { - break; - } - - Interface =3D VA_ARG (Args, VOID *); - - // - // Uninstall it - // - Status =3D UnitTestUninstallProtocolInterface (Handle, Protocol, Inter= face); - } - - VA_END (Args); - - // - // If there was an error, add all the interfaces that were - // uninstalled without any errors - // - if (EFI_ERROR (Status)) { - // - // Reset the va_arg back to the first argument. - // - VA_START (Args, Handle); - for ( ; Index > 1; Index--) { - Protocol =3D VA_ARG (Args, EFI_GUID *); - Interface =3D VA_ARG (Args, VOID *); - UnitTestInstallProtocolInterface (&Handle, Protocol, EFI_NATIVE_INTE= RFACE, Interface); - } - - VA_END (Args); - Status =3D EFI_INVALID_PARAMETER; - } - - return Status; -} diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTestTpl.c b/PrmPkg/Test/UnitTest/Library/UefiBo= otServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestTpl.c deleted file mode 100644 index 5b7b6700f874..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTestTpl.c +++ /dev/null @@ -1,43 +0,0 @@ -/** @file - Implementation of Task Priority Level (TPL) related services in the UEFI= Boot Services table for use in unit tests. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "UefiBootServicesTableLibUnitTest.h" - -/** - Raise the task priority level to the new level. - High level is implemented by disabling processor interrupts. - - @param NewTpl New task priority level - - @return The previous task priority level - -**/ -EFI_TPL -EFIAPI -UnitTestRaiseTpl ( - IN EFI_TPL NewTpl - ) -{ - return TPL_APPLICATION; -} - -/** - Lowers the task priority to the previous value. If the new - priority unmasks events at a higher priority, they are dispatched. - - @param NewTpl New, lower, task priority - -**/ -VOID -EFIAPI -UnitTestRestoreTpl ( - IN EFI_TPL NewTpl - ) -{ - return; -} diff --git a/PrmPkg/PrmPkg.dsc b/PrmPkg/PrmPkg.dsc index 3fb7490acaff..677100504584 100644 --- a/PrmPkg/PrmPkg.dsc +++ b/PrmPkg/PrmPkg.dsc @@ -100,7 +100,6 @@ [Components] $(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModule/Library/D= xeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.= inf $(PLATFORM_PACKAGE)/Samples/PrmSampleContextBufferModule/Library/DxeCont= extBufferModuleConfigLib/DxeContextBufferModuleConfigLib.inf $(PLATFORM_PACKAGE)/Samples/PrmSampleHardwareAccessModule/Library/DxeHar= dwareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.inf - $(PLATFORM_PACKAGE)/Test/UnitTest/Library/UefiBootServicesTableLibUnitTe= st/UefiBootServicesTableLibUnitTest.inf =20 # # PRM Module Discovery Library diff --git a/PrmPkg/Test/PrmPkgHostTest.dsc b/PrmPkg/Test/PrmPkgHostTest.dsc index 67fb4f5bd0d2..75d9046cc2e2 100644 --- a/PrmPkg/Test/PrmPkgHostTest.dsc +++ b/PrmPkg/Test/PrmPkgHostTest.dsc @@ -24,14 +24,8 @@ [LibraryClasses] PrmContextBufferLib|PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextB= ufferLib.inf PrmModuleDiscoveryLib|PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModu= leDiscoveryLib.inf PrmPeCoffLib|PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.inf - UefiBootServicesTableLib|PrmPkg/Test/UnitTest/Library/UefiBootServicesTa= bleLibUnitTest/UefiBootServicesTableLibUnitTest.inf =20 [Components] - # - # Unit test helper libraries - # - PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTest.inf - # # Unit test host applications # diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibTest.uni b/PrmPkg/Test/UnitTest/Library/UefiBootSer= vicesTableLibUnitTest/UefiBootServicesTableLibTest.uni deleted file mode 100644 index 1f742bb6d8e9..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibTest.uni +++ /dev/null @@ -1,12 +0,0 @@ -// /** @file -// UEFI Boot Services Table Library for unit tests implementation. -// -// Copyright (c) Microsoft Corporation -// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// -// **/ - -#string STR_MODULE_ABSTRACT #language en-US "UEFI Boot Service= s Table Library for unit tests" - -#string STR_MODULE_DESCRIPTION #language en-US "UEFI Boot Service= s Table Library for unit tests." diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTest.h b/PrmPkg/Test/UnitTest/Library/UefiBootS= ervicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.h deleted file mode 100644 index 82853bb61a1c..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTest.h +++ /dev/null @@ -1,1042 +0,0 @@ -/** @file - An internal header file for the Unit Test instance of the UEFI Boot Serv= ices Table Library. - - This file includes common header files, defines internal structure and f= unctions used by - the library implementation. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_H_ -#define UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include - -/** - Raise the task priority level to the new level. - High level is implemented by disabling processor interrupts. - - @param NewTpl New task priority level - - @return The previous task priority level - -**/ -EFI_TPL -EFIAPI -UnitTestRaiseTpl ( - IN EFI_TPL NewTpl - ); - -/** - Lowers the task priority to the previous value. If the new - priority unmasks events at a higher priority, they are dispatched. - - @param NewTpl New, lower, task priority - -**/ -VOID -EFIAPI -UnitTestRestoreTpl ( - IN EFI_TPL NewTpl - ); - -/** - Allocates pages from the memory map. - - @param Type The type of allocation to perform - @param MemoryType The type of memory to turn the allocated = pages - into - @param NumberOfPages The number of pages to allocate - @param Memory A pointer to receive the base allocated m= emory - address - - @return Status. On success, Memory is filled in with the base address al= located - @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined= in - spec. - @retval EFI_NOT_FOUND Could not allocate pages match the requir= ement. - @retval EFI_OUT_OF_RESOURCES No enough pages to allocate. - @retval EFI_SUCCESS Pages successfully allocated. - -**/ -EFI_STATUS -EFIAPI -UnitTestAllocatePages ( - IN EFI_ALLOCATE_TYPE Type, - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN NumberOfPages, - IN OUT EFI_PHYSICAL_ADDRESS *Memory - ); - -/** - Frees previous allocated pages. - - @param Memory Base address of memory being freed - @param NumberOfPages The number of pages to free - - @retval EFI_NOT_FOUND Could not find the entry that covers the = range - @retval EFI_INVALID_PARAMETER Address not aligned - @return EFI_SUCCESS -Pages successfully freed. - -**/ -EFI_STATUS -EFIAPI -UnitTestFreePages ( - IN EFI_PHYSICAL_ADDRESS Memory, - IN UINTN NumberOfPages - ); - -/** - This function returns a copy of the current memory map. The map is an ar= ray of - memory descriptors, each of which describes a contiguous block of memory. - - @param MemoryMapSize A pointer to the size, in bytes, of the - MemoryMap buffer. On input, this is the s= ize of - the buffer allocated by the caller. On o= utput, - it is the size of the buffer returned by = the - firmware if the buffer was large enough,= or the - size of the buffer needed to contain the= map if - the buffer was too small. - @param MemoryMap A pointer to the buffer in which firmware= places - the current memory map. - @param MapKey A pointer to the location in which firmwa= re - returns the key for the current memory ma= p. - @param DescriptorSize A pointer to the location in which firmwa= re - returns the size, in bytes, of an individ= ual - EFI_MEMORY_DESCRIPTOR. - @param DescriptorVersion A pointer to the location in which firmwa= re - returns the version number associated wit= h the - EFI_MEMORY_DESCRIPTOR. - - @retval EFI_SUCCESS The memory map was returned in the Memory= Map - buffer. - @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The c= urrent - buffer size needed to hold the memory map= is - returned in MemoryMapSize. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. - -**/ -EFI_STATUS -EFIAPI -UnitTestGetMemoryMap ( - IN OUT UINTN *MemoryMapSize, - IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, - OUT UINTN *MapKey, - OUT UINTN *DescriptorSize, - OUT UINT32 *DescriptorVersion - ); - -/** - Allocate pool of a particular type. - - @param PoolType Type of pool to allocate - @param Size The amount of pool to allocate - @param Buffer The address to return a pointer to the al= located - pool - - @retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL - @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation = failed. - @retval EFI_SUCCESS Pool successfully allocated. - -**/ -EFI_STATUS -EFIAPI -UnitTestAllocatePool ( - IN EFI_MEMORY_TYPE PoolType, - IN UINTN Size, - OUT VOID **Buffer - ); - -/** - Frees pool. - - @param Buffer The allocated pool entry to free - - @retval EFI_INVALID_PARAMETER Buffer is not a valid value. - @retval EFI_SUCCESS Pool successfully freed. - -**/ -EFI_STATUS -EFIAPI -UnitTestFreePool ( - IN VOID *Buffer - ); - -/** - Frees pool. - - @param Buffer The allocated pool entry to free - @param PoolType Pointer to pool type - - @retval EFI_INVALID_PARAMETER Buffer is not a valid value. - @retval EFI_SUCCESS Pool successfully freed. - -**/ -EFI_STATUS -EFIAPI -UnitTestInternalFreePool ( - IN VOID *Buffer, - OUT EFI_MEMORY_TYPE *PoolType OPTIONAL - ); - -/** - Creates an event. - - @param Type The type of event to create and its mode = and - attributes - @param NotifyTpl The task priority level of event notifica= tions - @param NotifyFunction Pointer to the events notification functi= on - @param NotifyContext Pointer to the notification functions con= text; - corresponds to parameter "Context" in the - notification function - @param Event Pointer to the newly created event if the= call - succeeds; undefined otherwise - - @retval EFI_SUCCESS The event structure was created - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value - @retval EFI_OUT_OF_RESOURCES The event could not be allocated - -**/ -EFI_STATUS -EFIAPI -UnitTestCreateEvent ( - IN UINT32 Type, - IN EFI_TPL NotifyTpl, - IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL - IN VOID *NotifyContext, OPTIONAL - OUT EFI_EVENT *Event - ); - -/** - Sets the type of timer and the trigger time for a timer event. - - @param UserEvent The timer event that is to be signaled at= the - specified time - @param Type The type of time that is specified in - TriggerTime - @param TriggerTime The number of 100ns units until the timer - expires - - @retval EFI_SUCCESS The event has been set to be signaled at = the - requested time - @retval EFI_INVALID_PARAMETER Event or Type is not valid - -**/ -EFI_STATUS -EFIAPI -UnitTestSetTimer ( - IN EFI_EVENT UserEvent, - IN EFI_TIMER_DELAY Type, - IN UINT64 TriggerTime - ); - -/** - Stops execution until an event is signaled. - - @param NumberOfEvents The number of events in the UserEvents ar= ray - @param UserEvents An array of EFI_EVENT - @param UserIndex Pointer to the index of the event which - satisfied the wait condition - - @retval EFI_SUCCESS The event indicated by Index was signaled. - @retval EFI_INVALID_PARAMETER The event indicated by Index has a notifi= cation - function or Event was not a valid type - @retval EFI_UNSUPPORTED The current TPL is not TPL_APPLICATION - -**/ -EFI_STATUS -EFIAPI -UnitTestWaitForEvent ( - IN UINTN NumberOfEvents, - IN EFI_EVENT *UserEvents, - OUT UINTN *UserIndex - ); - -/** - Signals the event. Queues the event to be notified if needed. - - @param UserEvent The event to signal . - - @retval EFI_INVALID_PARAMETER Parameters are not valid. - @retval EFI_SUCCESS The event was signaled. - -**/ -EFI_STATUS -EFIAPI -UnitTestSignalEvent ( - IN EFI_EVENT UserEvent - ); - -/** - Closes an event and frees the event structure. - - @param UserEvent Event to close - - @retval EFI_INVALID_PARAMETER Parameters are not valid. - @retval EFI_SUCCESS The event has been closed - -**/ -EFI_STATUS -EFIAPI -UnitTestCloseEvent ( - IN EFI_EVENT UserEvent - ); - -/** - Check the status of an event. - - @param UserEvent The event to check - - @retval EFI_SUCCESS The event is in the signaled state - @retval EFI_NOT_READY The event is not in the signaled state - @retval EFI_INVALID_PARAMETER Event is of type EVT_NOTIFY_SIGNAL - -**/ -EFI_STATUS -EFIAPI -UnitTestCheckEvent ( - IN EFI_EVENT UserEvent - ); - -/** - Wrapper function to UnitTestInstallProtocolInterfaceNotify. This is the= public API which - Calls the private one which contains a BOOLEAN parameter for notificatio= ns - - @param UserHandle The handle to install the protocol handle= r on, - or NULL if a new handle is to be allocated - @param Protocol The protocol to add to the handle - @param InterfaceType Indicates whether Interface is supplied in - native form. - @param Interface The interface for the protocol being added - - @return Status code - -**/ -EFI_STATUS -EFIAPI -UnitTestInstallProtocolInterface ( - IN OUT EFI_HANDLE *UserHandle, - IN EFI_GUID *Protocol, - IN EFI_INTERFACE_TYPE InterfaceType, - IN VOID *Interface - ); - -/** - Reinstall a protocol interface on a device handle. The OldInterface for= Protocol is replaced by the NewInterface. - - @param UserHandle Handle on which the interface is to be - reinstalled - @param Protocol The numeric ID of the interface - @param OldInterface A pointer to the old interface - @param NewInterface A pointer to the new interface - - @retval EFI_SUCCESS The protocol interface was installed - @retval EFI_NOT_FOUND The OldInterface on the handle was not fo= und - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value - -**/ -EFI_STATUS -EFIAPI -UnitTestReinstallProtocolInterface ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - IN VOID *OldInterface, - IN VOID *NewInterface - ); - -/** - Uninstalls all instances of a protocol:interfacer from a handle. - If the last protocol interface is remove from the handle, the - handle is freed. - - @param UserHandle The handle to remove the protocol handler= from - @param Protocol The protocol, of protocol:interface, to r= emove - @param Interface The interface, of protocol:interface, to = remove - - @retval EFI_INVALID_PARAMETER Protocol is NULL. - @retval EFI_SUCCESS Protocol interface successfully uninstall= ed. - -**/ -EFI_STATUS -EFIAPI -UnitTestUninstallProtocolInterface ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - IN VOID *Interface - ); - -/** - Queries a handle to determine if it supports a specified protocol. - - @param UserHandle The handle being queried. - @param Protocol The published unique identifier of the pr= otocol. - @param Interface Supplies the address where a pointer to t= he - corresponding Protocol Interface is retur= ned. - - @return The requested protocol interface for the handle - -**/ -EFI_STATUS -EFIAPI -UnitTestHandleProtocol ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - OUT VOID **Interface - ); - -/** - Add a new protocol notification record for the request protocol. - - @param Protocol The requested protocol to add the notify - registration - @param Event The event to signal - @param Registration Returns the registration record - - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_SUCCESS Successfully returned the registration re= cord - that has been added - -**/ -EFI_STATUS -EFIAPI -UnitTestRegisterProtocolNotify ( - IN EFI_GUID *Protocol, - IN EFI_EVENT Event, - OUT VOID **Registration - ); - -/** - Locates the requested handle(s) and returns them in Buffer. - - @param SearchType The type of search to perform to locate t= he - handles - @param Protocol The protocol to search for - @param SearchKey Dependant on SearchType - @param BufferSize On input the size of Buffer. On output t= he - size of data returned. - @param Buffer The buffer to return the results in - - @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is - returned in BufferSize. - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_SUCCESS Successfully found the requested handle(s= ) and - returns them in Buffer. - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateHandle ( - IN EFI_LOCATE_SEARCH_TYPE SearchType, - IN EFI_GUID *Protocol OPTIONAL, - IN VOID *SearchKey OPTIONAL, - IN OUT UINTN *BufferSize, - OUT EFI_HANDLE *Buffer - ); - -/** - Locates the handle to a device on the device path that best matches the = specified protocol. - - @param Protocol The protocol to search for. - @param DevicePath On input, a pointer to a pointer to the d= evice - path. On output, the device path pointer = is - modified to point to the remaining part o= f the - devicepath. - @param Device A pointer to the returned device handle. - - @retval EFI_SUCCESS The resulting handle was returned. - @retval EFI_NOT_FOUND No handles matched the search. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid valu= e. - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateDevicePath ( - IN EFI_GUID *Protocol, - IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, - OUT EFI_HANDLE *Device - ); - -/** - Boot Service called to add, modify, or remove a system configuration tab= le from - the EFI System Table. - - @param Guid Pointer to the GUID for the entry to add, update,= or - remove - @param Table Pointer to the configuration table for the entry = to add, - update, or remove, may be NULL. - - @return EFI_SUCCESS Guid, Table pair added, updated, or re= moved. - @return EFI_INVALID_PARAMETER Input GUID not valid. - @return EFI_NOT_FOUND Attempted to delete non-existant entry - @return EFI_OUT_OF_RESOURCES Not enough memory available - -**/ -EFI_STATUS -EFIAPI -UnitTestInstallConfigurationTable ( - IN EFI_GUID *Guid, - IN VOID *Table - ); - -/** - Loads an EFI image into memory and returns a handle to the image. - - @param BootPolicy If TRUE, indicates that the request orig= inates - from the boot manager, and that the boot - manager is attempting to load FilePath a= s a - boot selection. - @param ParentImageHandle The caller's image handle. - @param FilePath The specific file path from which the im= age is - loaded. - @param SourceBuffer If not NULL, a pointer to the memory loc= ation - containing a copy of the image to be loa= ded. - @param SourceSize The size in bytes of SourceBuffer. - @param ImageHandle Pointer to the returned image handle tha= t is - created when the image is successfully l= oaded. - - @retval EFI_SUCCESS The image was loaded into memory. - @retval EFI_NOT_FOUND The FilePath was not found. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid val= ue. - @retval EFI_UNSUPPORTED The image type is not supported, or the = device - path cannot be parsed to locate the prop= er - protocol for loading the file. - @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient - resources. - @retval EFI_LOAD_ERROR Image was not loaded because the image f= ormat was corrupt or not - understood. - @retval EFI_DEVICE_ERROR Image was not loaded because the device = returned a read error. - @retval EFI_ACCESS_DENIED Image was not loaded because the platfor= m policy prohibits the - image from being loaded. NULL is returne= d in *ImageHandle. - @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was = created with a - valid EFI_LOADED_IMAGE_PROTOCOL. However= , the current - platform policy specifies that the image= should not be started. - -**/ -EFI_STATUS -EFIAPI -UnitTestLoadImage ( - IN BOOLEAN BootPolicy, - IN EFI_HANDLE ParentImageHandle, - IN EFI_DEVICE_PATH_PROTOCOL *FilePath, - IN VOID *SourceBuffer OPTIONAL, - IN UINTN SourceSize, - OUT EFI_HANDLE *ImageHandle - ); - -/** - Transfer control to a loaded image's entry point. - - @param ImageHandle Handle of image to be started. - @param ExitDataSize Pointer of the size to ExitData - @param ExitData Pointer to a pointer to a data buffer th= at - includes a Null-terminated string, - optionally followed by additional binary= data. - The string is a description that the cal= ler may - use to further indicate the reason for t= he - image's exit. - - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate - @retval EFI_SECURITY_VIOLATION The current platform policy specifies th= at the image should not be started. - @retval EFI_SUCCESS Successfully transfer control to the ima= ge's - entry point. - -**/ -EFI_STATUS -EFIAPI -UnitTestStartImage ( - IN EFI_HANDLE ImageHandle, - OUT UINTN *ExitDataSize, - OUT CHAR16 **ExitData OPTIONAL - ); - -/** - Terminates the currently loaded EFI image and returns control to boot se= rvices. - - @param ImageHandle Handle that identifies the image. This - parameter is passed to the image on entr= y. - @param Status The image's exit code. - @param ExitDataSize The size, in bytes, of ExitData. Ignored= if - ExitStatus is EFI_SUCCESS. - @param ExitData Pointer to a data buffer that includes a - Null-terminated Unicode string, optional= ly - followed by additional binary data. The = string - is a description that the caller may use= to - further indicate the reason for the imag= e's - exit. - - @retval EFI_INVALID_PARAMETER Image handle is NULL or it is not current - image. - @retval EFI_SUCCESS Successfully terminates the currently lo= aded - EFI image. - @retval EFI_ACCESS_DENIED Should never reach there. - @retval EFI_OUT_OF_RESOURCES Could not allocate pool - -**/ -EFI_STATUS -EFIAPI -UnitTestExit ( - IN EFI_HANDLE ImageHandle, - IN EFI_STATUS Status, - IN UINTN ExitDataSize, - IN CHAR16 *ExitData OPTIONAL - ); - -/** - Unloads an image. - - @param ImageHandle Handle that identifies the image to be - unloaded. - - @retval EFI_SUCCESS The image has been unloaded. - @retval EFI_UNSUPPORTED The image has been started, and does not= support - unload. - @retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle. - -**/ -EFI_STATUS -EFIAPI -UnitTestUnloadImage ( - IN EFI_HANDLE ImageHandle - ); - -/** - Terminates all boot services. - - @param ImageHandle Handle that identifies the exiting image. - @param MapKey Key to the latest memory map. - - @retval EFI_SUCCESS Boot Services terminated - @retval EFI_INVALID_PARAMETER MapKey is incorrect. - -**/ -EFI_STATUS -EFIAPI -UnitTestExitBootServices ( - IN EFI_HANDLE ImageHandle, - IN UINTN MapKey - ); - -/** - Returns a monotonically increasing count for the platform. - - @param[out] Count The pointer to returned value. - - @retval EFI_SUCCESS The next monotonic count was returned. - @retval EFI_INVALID_PARAMETER Count is NULL. - @retval EFI_DEVICE_ERROR The device is not functioning properly. - -**/ -EFI_STATUS -EFIAPI -UnitTestGetNextMonotonicCount ( - OUT UINT64 *Count - ); - -/** - Introduces a fine-grained stall. - - @param Microseconds The number of microseconds to stall execu= tion. - - @retval EFI_SUCCESS Execution was stalled for at least the re= quested - amount of microseconds. - @retval EFI_NOT_AVAILABLE_YET gMetronome is not available yet - -**/ -EFI_STATUS -EFIAPI -UnitTestStall ( - IN UINTN Microseconds - ); - -/** - Sets the system's watchdog timer. - - @param Timeout The number of seconds to set the watchdog timer = to. - A value of zero disables the timer. - @param WatchdogCode The numeric code to log on a watchdog timer time= out - event. The firmware reserves codes 0x0000 to 0xF= FFF. - Loaders and operating systems may use other time= out - codes. - @param DataSize The size, in bytes, of WatchdogData. - @param WatchdogData A data buffer that includes a Null-terminated Un= icode - string, optionally followed by additional binary= data. - The string is a description that the call may us= e to - further indicate the reason to be logged with a - watchdog event. - - @return EFI_SUCCESS Timeout has been set - @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet - @return EFI_UNSUPPORTED System does not have a timer (currentl= y not used) - @return EFI_DEVICE_ERROR Could not complete due to hardware err= or - -**/ -EFI_STATUS -EFIAPI -UnitTestSetWatchdogTimer ( - IN UINTN Timeout, - IN UINT64 WatchdogCode, - IN UINTN DataSize, - IN CHAR16 *WatchdogData OPTIONAL - ); - -/** - Connects one or more drivers to a controller. - - @param ControllerHandle The handle of the controller to which driv= er(s) are to be connected. - @param DriverImageHandle A pointer to an ordered list handles that = support the - EFI_DRIVER_BINDING_PROTOCOL. - @param RemainingDevicePath A pointer to the device path that specifie= s a child of the - controller specified by ControllerHandle. - @param Recursive If TRUE, then ConnectController() is calle= d recursively - until the entire tree of controllers below= the controller specified - by ControllerHandle have been created. If = FALSE, then - the tree of controllers is only expanded o= ne level. - - @retval EFI_SUCCESS 1) One or more drivers were connected to C= ontrollerHandle. - 2) No drivers were connected to Controller= Handle, but - RemainingDevicePath is not NULL, and it is= an End Device - Path Node. - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. - @retval EFI_NOT_FOUND 1) There are no EFI_DRIVER_BINDING_PROTOCO= L instances - present in the system. - 2) No drivers were connected to Controller= Handle. - @retval EFI_SECURITY_VIOLATION - The user has no permission to start UEFI d= evice drivers on the device path - associated with the ControllerHandle or sp= ecified by the RemainingDevicePath. - -**/ -EFI_STATUS -EFIAPI -UnitTestConnectController ( - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE *DriverImageHandle OPTIONAL, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL, - IN BOOLEAN Recursive - ); - -/** - Disconnects a controller from a driver - - @param ControllerHandle ControllerHandle The handl= e of - the controller from which - driver(s) are to be - disconnected. - @param DriverImageHandle DriverImageHandle The driv= er to - disconnect from Controller= Handle. - @param ChildHandle ChildHandle The handle of = the - child to destroy. - - @retval EFI_SUCCESS One or more drivers were - disconnected from the cont= roller. - @retval EFI_SUCCESS On entry, no drivers are m= anaging - ControllerHandle. - @retval EFI_SUCCESS DriverImageHandle is not N= ULL, - and on entry DriverImageHa= ndle is - not managing ControllerHan= dle. - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. - @retval EFI_INVALID_PARAMETER DriverImageHandle is not N= ULL, - and it is not a valid EFI_= HANDLE. - @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, a= nd it - is not a valid EFI_HANDLE. - @retval EFI_OUT_OF_RESOURCES There are not enough resou= rces - available to disconnect any - drivers from ControllerHan= dle. - @retval EFI_DEVICE_ERROR The controller could not be - disconnected because of a = device - error. - -**/ -EFI_STATUS -EFIAPI -UnitTestDisconnectController ( - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE DriverImageHandle OPTIONAL, - IN EFI_HANDLE ChildHandle OPTIONAL - ); - -/** - Locates the installed protocol handler for the handle, and - invokes it to obtain the protocol interface. Usage information - is registered in the protocol data base. - - @param UserHandle The handle to obtain the protocol interfa= ce on - @param Protocol The ID of the protocol - @param Interface The location to return the protocol inter= face - @param ImageHandle The handle of the Image that is opening t= he - protocol interface specified by Protocol = and - Interface. - @param ControllerHandle The controller handle that is requiring t= his - interface. - @param Attributes The open mode of the protocol interface - specified by Handle and Protocol. - - @retval EFI_INVALID_PARAMETER Protocol is NULL. - @retval EFI_SUCCESS Get the protocol interface. - -**/ -EFI_STATUS -EFIAPI -UnitTestOpenProtocol ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - OUT VOID **Interface OPTIONAL, - IN EFI_HANDLE ImageHandle, - IN EFI_HANDLE ControllerHandle, - IN UINT32 Attributes - ); - -/** - Closes a protocol on a handle that was opened using OpenProtocol(). - - @param UserHandle The handle for the protocol interface tha= t was - previously opened with OpenProtocol(), an= d is - now being closed. - @param Protocol The published unique identifier of the pr= otocol. - It is the caller's responsibility to pass= in a - valid GUID. - @param AgentHandle The handle of the agent that is closing t= he - protocol interface. - @param ControllerHandle If the agent that opened a protocol is a = driver - that follows the EFI Driver Model, then t= his - parameter is the controller handle that r= equired - the protocol interface. If the agent does= not - follow the EFI Driver Model, then this pa= rameter - is optional and may be NULL. - - @retval EFI_SUCCESS The protocol instance was closed. - @retval EFI_INVALID_PARAMETER Handle, AgentHandle or ControllerHandle i= s not a - valid EFI_HANDLE. - @retval EFI_NOT_FOUND Can not find the specified protocol or - AgentHandle. - -**/ -EFI_STATUS -EFIAPI -UnitTestCloseProtocol ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - IN EFI_HANDLE AgentHandle, - IN EFI_HANDLE ControllerHandle - ); - -/** - Return information about Opened protocols in the system - - @param UserHandle The handle to close the protocol interfac= e on - @param Protocol The ID of the protocol - @param EntryBuffer A pointer to a buffer of open protocol - information in the form of - EFI_OPEN_PROTOCOL_INFORMATION_ENTRY struc= tures. - @param EntryCount Number of EntryBuffer entries - -**/ -EFI_STATUS -EFIAPI -UnitTestOpenProtocolInformation ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, - OUT UINTN *EntryCount - ); - -/** - Retrieves the list of protocol interface GUIDs that are installed on a h= andle in a buffer allocated - from pool. - - @param UserHandle The handle from which to retrieve the lis= t of - protocol interface GUIDs. - @param ProtocolBuffer A pointer to the list of protocol interfa= ce GUID - pointers that are installed on Handle. - @param ProtocolBufferCount A pointer to the number of GUID pointers = present - in ProtocolBuffer. - - @retval EFI_SUCCESS The list of protocol interface GUIDs inst= alled - on Handle was returned in ProtocolBuffer.= The - number of protocol interface GUIDs was re= turned - in ProtocolBufferCount. - @retval EFI_INVALID_PARAMETER Handle is NULL. - @retval EFI_INVALID_PARAMETER Handle is not a valid EFI_HANDLE. - @retval EFI_INVALID_PARAMETER ProtocolBuffer is NULL. - @retval EFI_INVALID_PARAMETER ProtocolBufferCount is NULL. - @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the - results. - -**/ -EFI_STATUS -EFIAPI -UnitTestProtocolsPerHandle ( - IN EFI_HANDLE UserHandle, - OUT EFI_GUID ***ProtocolBuffer, - OUT UINTN *ProtocolBufferCount - ); - -/** - Function returns an array of handles that support the requested protocol - in a buffer allocated from pool. This is a version of UnitTestLocateHand= le() - that allocates a buffer for the caller. - - @param SearchType Specifies which handle(s) are to be retur= ned. - @param Protocol Provides the protocol to search by. Th= is - parameter is only valid for SearchType - ByProtocol. - @param SearchKey Supplies the search key depending on the - SearchType. - @param NumberHandles The number of handles returned in Buffer. - @param Buffer A pointer to the buffer to return the req= uested - array of handles that support Protocol. - - @retval EFI_SUCCESS The result array of handles was returned. - @retval EFI_NOT_FOUND No handles match the search. - @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the - matching results. - @retval EFI_INVALID_PARAMETER One or more parameters are not valid. - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateHandleBuffer ( - IN EFI_LOCATE_SEARCH_TYPE SearchType, - IN EFI_GUID *Protocol OPTIONAL, - IN VOID *SearchKey OPTIONAL, - IN OUT UINTN *NumberHandles, - OUT EFI_HANDLE **Buffer - ); - -/** - Return the first Protocol Interface that matches the Protocol GUID. If - Registration is passed in, return a Protocol Instance that was just add - to the system. If Registration is NULL return the first Protocol Interfa= ce - you find. - - @param Protocol The protocol to search for - @param Registration Optional Registration Key returned from - RegisterProtocolNotify() - @param Interface Return the Protocol interface (instance). - - @retval EFI_SUCCESS If a valid Interface is returned - @retval EFI_INVALID_PARAMETER Invalid parameter - @retval EFI_NOT_FOUND Protocol interface not found - -**/ -EFI_STATUS -EFIAPI -UnitTestLocateProtocol ( - IN EFI_GUID *Protocol, - IN VOID *Registration OPTIONAL, - OUT VOID **Interface - ); - -/** - Installs a list of protocol interface into the boot services environment. - This function calls InstallProtocolInterface() in a loop. If any error - occurs all the protocols added by this function are removed. This is - basically a lib function to save space. - - @param Handle The handle to install the protocol handle= rs on, - or NULL if a new handle is to be allocated - @param ... EFI_GUID followed by protocol instance. A= NULL - terminates the list. The pairs are the - arguments to InstallProtocolInterface(). = All the - protocols are added to Handle. - - @retval EFI_SUCCESS All the protocol interface was installed. - @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to in= stall all the protocols. - @retval EFI_ALREADY_STARTED A Device Path Protocol instance was passe= d in that is already present in - the handle database. - @retval EFI_INVALID_PARAMETER Handle is NULL. - @retval EFI_INVALID_PARAMETER Protocol is already installed on the hand= le specified by Handle. - -**/ -EFI_STATUS -EFIAPI -UnitTestInstallMultipleProtocolInterfaces ( - IN OUT EFI_HANDLE *Handle, - ... - ); - -/** - Uninstalls a list of protocol interface in the boot services environment. - This function calls UninstallProtocolInterface() in a loop. This is - basically a lib function to save space. - - @param Handle The handle to uninstall the protocol - @param ... EFI_GUID followed by protocol instance. A= NULL - terminates the list. The pairs are the - arguments to UninstallProtocolInterface()= . All - the protocols are added to Handle. - - @return Status code - -**/ -EFI_STATUS -EFIAPI -UnitTestUninstallMultipleProtocolInterfaces ( - IN EFI_HANDLE Handle, - ... - ); - -/** - Computes and returns a 32-bit CRC for a data buffer. - - @param[in] Data A pointer to the buffer on which the 32-bi= t CRC is to be computed. - @param[in] DataSize The number of bytes in the buffer Data. - @param[out] Crc32 The 32-bit CRC that was computed for the d= ata buffer specified by Data - and DataSize. - - @retval EFI_SUCCESS The 32-bit CRC was computed for the data b= uffer and returned in - Crc32. - @retval EFI_INVALID_PARAMETER Data is NULL. - @retval EFI_INVALID_PARAMETER Crc32 is NULL. - @retval EFI_INVALID_PARAMETER DataSize is 0. - -**/ -EFI_STATUS -EFIAPI -UnitTestCalculateCrc32 ( - IN VOID *Data, - IN UINTN DataSize, - OUT UINT32 *Crc32 - ); - -/** - Creates an event in a group. - - @param Type The type of event to create and its mode = and - attributes - @param NotifyTpl The task priority level of event notifica= tions - @param NotifyFunction Pointer to the events notification functi= on - @param NotifyContext Pointer to the notification functions con= text; - corresponds to parameter "Context" in the - notification function - @param EventGroup GUID for EventGroup if NULL act the same = as - gBS->CreateEvent(). - @param Event Pointer to the newly created event if the= call - succeeds; undefined otherwise - - @retval EFI_SUCCESS The event structure was created - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value - @retval EFI_OUT_OF_RESOURCES The event could not be allocated - -**/ -EFI_STATUS -EFIAPI -UnitTestCreateEventEx ( - IN UINT32 Type, - IN EFI_TPL NotifyTpl, - IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL - IN CONST VOID *NotifyContext, OPTIONAL - IN CONST EFI_GUID *EventGroup, OPTIONAL - OUT EFI_EVENT *Event - ); - -#endif diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTest.inf b/PrmPkg/Test/UnitTest/Library/UefiBoo= tServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.inf deleted file mode 100644 index 3b85dbb1b715..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTest.inf +++ /dev/null @@ -1,46 +0,0 @@ -## @file -# UEFI Boot Services Table Library for unit tests implementation. -# -# Copyright (c) Microsoft Corporation -# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D UefiBootServicesTableLibUnitTest - MODULE_UNI_FILE =3D UefiBootServicesTableLibTest.uni - FILE_GUID =3D 725E1CCD-07F1-4964-9A3E-9AA6DCC51DE6 - MODULE_TYPE =3D UEFI_DRIVER - VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D UefiBootServicesTableLib|DXE_CORE DXE= _DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_= CORE - - CONSTRUCTOR =3D UefiBootServicesTableLibUnitTestConst= ructor - -# -# VALID_ARCHITECTURES =3D IA32 X64 EBC -# - -[Sources] - UefiBootServicesTableLibUnitTest.h - UefiBootServicesTableLibUnitTest.c - UefiBootServicesTableLibUnitTestEventTimer.c - UefiBootServicesTableLibUnitTestImage.c - UefiBootServicesTableLibUnitTestMemory.c - UefiBootServicesTableLibUnitTestProtocol.h - UefiBootServicesTableLibUnitTestProtocol.c - UefiBootServicesTableLibUnitTestMisc.c - UefiBootServicesTableLibUnitTestTpl.c - -[Packages] - MdePkg/MdePkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - MemoryAllocationLib - UnitTestLib - -[UserExtensions.TianoCore."ExtraFiles"] - TimerExtra.uni diff --git a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/= UefiBootServicesTableLibUnitTestProtocol.h b/PrmPkg/Test/UnitTest/Library/U= efiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.h deleted file mode 100644 index 6428090071d6..000000000000 --- a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBoo= tServicesTableLibUnitTestProtocol.h +++ /dev/null @@ -1,120 +0,0 @@ -/** @file - An internal header file for the Unit Test instance of the UEFI Boot Serv= ices Table Library. - - This file includes common header files, defines internal structure and f= unctions used by - the library implementation. - -Copyright (c) Microsoft Corporation -SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_PROTOCOL_H_ -#define UEFI_BOOT_SERVICES_TABLE_LIB_UNIT_TEST_PROTOCOL_H_ - -#include "UefiBootServicesTableLibUnitTest.h" - -#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l') - -/// -/// IHANDLE - contains a list of protocol handles -/// -typedef struct { - UINTN Signature; - /// All handles list of IHANDLE - LIST_ENTRY AllHandles; - /// List of PROTOCOL_INTERFACE's for this handle - LIST_ENTRY Protocols; - UINTN LocateRequest; - /// The Handle Database Key value when this handle was last created or m= odified - UINT64 Key; -} IHANDLE; - -#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature =3D=3D EFI_HANDLE_SIGNA= TURE) - -#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e') - -/// -/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol -/// database. Each handler that supports this protocol is listed, along -/// with a list of registered notifies. -/// -typedef struct { - UINTN Signature; - /// Link Entry inserted to mProtocolDatabase - LIST_ENTRY AllEntries; - /// ID of the protocol - EFI_GUID ProtocolID; - /// All protocol interfaces - LIST_ENTRY Protocols; - /// Registered notification handlers - LIST_ENTRY Notify; -} PROTOCOL_ENTRY; - -#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c') - -/// -/// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked -/// with a protocol interface structure -/// -typedef struct { - UINTN Signature; - /// Link on IHANDLE.Protocols - LIST_ENTRY Link; - /// Back pointer - IHANDLE *Handle; - /// Link on PROTOCOL_ENTRY.Protocols - LIST_ENTRY ByProtocol; - /// The protocol ID - PROTOCOL_ENTRY *Protocol; - /// The interface value - VOID *Interface; - /// OPEN_PROTOCOL_DATA list - LIST_ENTRY OpenList; - UINTN OpenListCount; -} PROTOCOL_INTERFACE; - -#define OPEN_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('p','o','d','l') - -typedef struct { - UINTN Signature; - /// Link on PROTOCOL_INTERFACE.OpenList - LIST_ENTRY Link; - - EFI_HANDLE AgentHandle; - EFI_HANDLE ControllerHandle; - UINT32 Attributes; - UINT32 OpenCount; -} OPEN_PROTOCOL_DATA; - -#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n') - -/// -/// PROTOCOL_NOTIFY - used for each register notification for a protocol -/// -typedef struct { - UINTN Signature; - PROTOCOL_ENTRY *Protocol; - /// All notifications for this protocol - LIST_ENTRY Link; - /// Event to notify - EFI_EVENT Event; - /// Last position notified - LIST_ENTRY *Position; -} PROTOCOL_NOTIFY; - -typedef struct { - EFI_GUID *Protocol; - VOID *SearchKey; - LIST_ENTRY *Position; - PROTOCOL_ENTRY *ProtEntry; -} LOCATE_POSITION; - -typedef -IHANDLE * -(*UNIT_TEST_GET_NEXT) ( - IN OUT LOCATE_POSITION *Position, - OUT VOID **Interface - ); - -#endif --=20 2.28.0.windows.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 (#95926): https://edk2.groups.io/g/devel/message/95926 Mute This Topic: https://groups.io/mt/94796668/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-