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