X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FUefiLib%2FUefiLib.c;h=765235c51519f3c80bbf66c693a2e353582bb4eb;hp=85fdc6ebe3e43a114f3f48418d4814a6b8179593;hb=d958721a06dce3aa0fc941c115db86e3f91254f7;hpb=511710d68f477e0210ae1830769e5d0cde4ea36a diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c index 85fdc6ebe3..765235c515 100644 --- a/MdePkg/Library/UefiLib/UefiLib.c +++ b/MdePkg/Library/UefiLib/UefiLib.c @@ -1,7 +1,7 @@ /** @file Mde UEFI library functions. - Copyright (c) 2006, Intel Corporation
+ Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -24,13 +24,20 @@ @retval FALSE Language 1 and language 2 are not the same. **/ +STATIC BOOLEAN CompareIso639LanguageCode ( IN CONST CHAR8 *Language1, IN CONST CHAR8 *Language2 ) { - return (BOOLEAN) (ReadUnaligned24 ((CONST UINT32 *) Language1) == ReadUnaligned24 ((CONST UINT32 *) Language2)); + UINT32 Name1; + UINT32 Name2; + + Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1); + Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2); + + return (BOOLEAN) (Name1 == Name2); } /** @@ -93,7 +100,7 @@ EfiCreateProtocolNotifyEvent( IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext, OPTIONAL - OUT VOID *Registration + OUT VOID **Registration ) { EFI_STATUS Status; @@ -155,7 +162,7 @@ EfiNamedEventListen ( IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN CONST VOID *NotifyContext, OPTIONAL - OUT VOID *Registration OPTIONAL + OUT VOID *Registration OPTIONAL ) { EFI_STATUS Status; @@ -236,6 +243,34 @@ EfiNamedEventSignal ( return EFI_SUCCESS; } +/** + Returns the current TPL. + + This function returns the current TPL. There is no EFI service to directly + retrieve the current TPL. Instead, the RaiseTPL() function is used to raise + the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level + can then immediately be restored back to the current TPL level with a call + to RestoreTPL(). + + @param VOID + + @retvale EFI_TPL The current TPL. + +**/ +EFI_TPL +EFIAPI +EfiGetCurrentTpl ( + VOID + ) +{ + EFI_TPL Tpl; + + Tpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL); + gBS->RestoreTPL (Tpl); + + return Tpl; +} + /** This function initializes a basic mutual exclusion lock to the released state @@ -347,6 +382,130 @@ EfiReleaseLock ( gBS->RestoreTPL (Tpl); } +/** + Tests whether a controller is managed by a specific driver. + + This function tests whether a specific driver manages ControllerHandle by + opening on DriverBindingHandle a protocol specified by ProtocolGuid with + attribute EFI_OPEN_PROTOCOL_BY_DRIVER. This library function is used to + implement the Component Name Protocol for EFI Drivers. + If ProtocolGuid is NULL, then ASSERT(). + + @param ControllerHandle A handle for a controller to test. + @param DriverBindingHandle Specifies the driver binding handle for the + driver. + @param ProtocolGuid Supplies GUID for the protocol opened by the + driver on the controller. + + @retval EFI_SUCCESS ControllerHandle is managed by the specific + driver. + @retval EFI_UNSUPPORTED ControllerHandle is not managed by the specific + driver. + +**/ +EFI_STATUS +EFIAPI +EfiTestManagedDevice ( + IN CONST EFI_HANDLE ControllerHandle, + IN CONST EFI_HANDLE DriverBindingHandle, + IN CONST EFI_GUID *ProtocolGuid + ) +{ + EFI_STATUS Status; + VOID *ManagedInterface; + + ASSERT (ProtocolGuid != NULL); + + Status = gBS->OpenProtocol ( + ControllerHandle, + (EFI_GUID *) ProtocolGuid, + &ManagedInterface, + DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (!EFI_ERROR (Status)) { + gBS->CloseProtocol ( + ControllerHandle, + (EFI_GUID *) ProtocolGuid, + DriverBindingHandle, + ControllerHandle + ); + return EFI_UNSUPPORTED; + } + + if (Status != EFI_ALREADY_STARTED) { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + +/** + Tests whether a child handle is a children device of the controller. + + This function tests whether ChildHandle is one of the children of + ControllerHandle which are consuming a protocol specified by ProtocolGuid + with the attribute bit EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER set. This + library function is used to implement the Component Name Protocol for EFI + Drivers. + If ProtocolGuid is NULL, then ASSERT(). + + @param ControllerHandle A handle for a (parent) controller to test. + @param ChildHandle A child handle to test. + @param ConsumsedGuid Supplies GUID for the protocol consumed by + children from controller. + + @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle. + @retval EFI_UNSUPPORTED ChildHandle is not a child of the + ControllerHandle. + +**/ +EFI_STATUS +EFIAPI +EfiTestChildHandle ( + IN CONST EFI_HANDLE ControllerHandle, + IN CONST EFI_HANDLE ChildHandle, + IN CONST EFI_GUID *ProtocolGuid + ) +{ + EFI_STATUS Status; + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; + UINTN EntryCount; + UINTN Index; + + ASSERT (ProtocolGuid != NULL); + + // + // Retrieve the list of agents that are consuming the specific protocol + // on ControllerHandle. + // + Status = gBS->OpenProtocolInformation ( + ControllerHandle, + (EFI_GUID *) ProtocolGuid, + &OpenInfoBuffer, + &EntryCount + ); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + // + // Inspect if ChildHandle is one of the agents. + // + Status = EFI_UNSUPPORTED; + for (Index = 0; Index < EntryCount; Index++) { + if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) && + (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { + Status = EFI_SUCCESS; + break; + } + } + + FreePool (OpenInfoBuffer); + return Status; +} + /** This function looks up a Unicode string in UnicodeStringTable. If Language is a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable @@ -648,3 +807,4 @@ FreeUnicodeStringTable ( return EFI_SUCCESS; } +