Reset.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*++ @file
  2. Reset Architectural Protocol as defined in UEFI/PI under Emulation
  3. Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
  4. Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <PiDxe.h>
  8. #include <Library/BaseLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/UefiLib.h>
  11. #include <Library/UefiDriverEntryPoint.h>
  12. #include <Library/MemoryAllocationLib.h>
  13. #include <Library/UefiBootServicesTableLib.h>
  14. #include <Library/EmuThunkLib.h>
  15. #include <Protocol/Reset.h>
  16. VOID
  17. EFIAPI
  18. EmuResetSystem (
  19. IN EFI_RESET_TYPE ResetType,
  20. IN EFI_STATUS ResetStatus,
  21. IN UINTN DataSize,
  22. IN VOID *ResetData OPTIONAL
  23. )
  24. {
  25. EFI_STATUS Status;
  26. UINTN HandleCount;
  27. EFI_HANDLE *HandleBuffer;
  28. UINTN Index;
  29. //
  30. // Disconnect all
  31. //
  32. Status = gBS->LocateHandleBuffer (
  33. AllHandles,
  34. NULL,
  35. NULL,
  36. &HandleCount,
  37. &HandleBuffer
  38. );
  39. if (!EFI_ERROR (Status)) {
  40. for (Index = 0; Index < HandleCount; Index++) {
  41. Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
  42. }
  43. gBS->FreePool (HandleBuffer);
  44. }
  45. //
  46. // Discard ResetType, always return 0 as exit code
  47. //
  48. gEmuThunk->Exit (0);
  49. //
  50. // Should never go here
  51. //
  52. ASSERT (FALSE);
  53. return;
  54. }
  55. EFI_STATUS
  56. EFIAPI
  57. InitializeEmuReset (
  58. IN EFI_HANDLE ImageHandle,
  59. IN EFI_SYSTEM_TABLE *SystemTable
  60. )
  61. /*++
  62. Routine Description:
  63. Arguments:
  64. ImageHandle of the loaded driver
  65. Pointer to the System Table
  66. Returns:
  67. Status
  68. **/
  69. {
  70. EFI_STATUS Status;
  71. EFI_HANDLE Handle;
  72. SystemTable->RuntimeServices->ResetSystem = EmuResetSystem;
  73. Handle = NULL;
  74. Status = gBS->InstallMultipleProtocolInterfaces (
  75. &Handle,
  76. &gEfiResetArchProtocolGuid,
  77. NULL,
  78. NULL
  79. );
  80. ASSERT_EFI_ERROR (Status);
  81. return Status;
  82. }