DxeEmuLib.c 1.9 KB

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