]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / Library / DxeEmuLib / DxeEmuLib.c
CommitLineData
949f388f 1/*++ @file\r
2\r
3Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
d18d8a1d 4Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
e3ba31da 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
949f388f 6\r
7**/\r
8\r
9#include <PiDxe.h>\r
10\r
11#include <Library/DebugLib.h>\r
12#include <Library/HobLib.h>\r
13#include <Library/EmuThunkLib.h>\r
c4671a67 14#include <Library/BaseMemoryLib.h>\r
949f388f 15\r
16EMU_THUNK_PROTOCOL *gEmuThunk = NULL;\r
17\r
18\r
19/**\r
20 The constructor function caches the pointer of EMU Thunk protocol.\r
21\r
22 @param ImageHandle The firmware allocated handle for the EFI image.\r
23 @param SystemTable A pointer to the EFI System Table.\r
24\r
25 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
26\r
27**/\r
28EFI_STATUS\r
29EFIAPI\r
30DxeEmuLibConstructor (\r
31 IN EFI_HANDLE ImageHandle,\r
32 IN EFI_SYSTEM_TABLE *SystemTable\r
33 )\r
34{\r
35 EFI_HOB_GUID_TYPE *GuidHob;\r
36\r
37 GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);\r
38 ASSERT (GuidHob != NULL);\r
d18d8a1d 39\r
949f388f 40 gEmuThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
41 ASSERT (gEmuThunk != NULL);\r
d18d8a1d 42\r
949f388f 43 return EFI_SUCCESS;\r
44}\r
c4671a67 45\r
46\r
47/**\r
d18d8a1d 48 Serach the EMU IO Thunk database for a matching EMU IO Thunk\r
c4671a67 49 Protocol instance.\r
50\r
51 @param Protocol Protocol to search for.\r
52 @param Instance Instance of protocol to search for.\r
53\r
54 @retval NULL Protocol and Instance not found.\r
55 @retval other EMU IO Thunk protocol that matched.\r
56\r
57**/\r
58EMU_IO_THUNK_PROTOCOL *\r
59EFIAPI\r
60GetIoThunkInstance (\r
61 IN EFI_GUID *Protocol,\r
62 IN UINTN Instance\r
63 )\r
64{\r
65 EFI_STATUS Status;\r
66 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
d18d8a1d 67\r
c4671a67 68 for (Status = EFI_SUCCESS, EmuIoThunk = NULL; !EFI_ERROR (Status); ) {\r
69 Status = gEmuThunk->GetNextProtocol (FALSE, &EmuIoThunk);\r
70 if (EFI_ERROR (Status)) {\r
71 break;\r
72 }\r
d18d8a1d 73\r
c4671a67 74 if (EmuIoThunk->Instance == Instance) {\r
75 if (CompareGuid (EmuIoThunk->Protocol, Protocol)) {\r
76 return EmuIoThunk;\r
77 }\r
78 }\r
79 }\r
d18d8a1d 80\r
c4671a67 81 return NULL;\r
79e4f2a5 82}\r