blob: 369bc86296baf5b33e89cb90bdb7bc5cd549d88e [file] [log] [blame]
andrewfish949f3882011-05-11 18:31:20 +00001/*++ @file
2 Reset Architectural Protocol as defined in UEFI/PI under Emulation
3
4Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
5Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.
jljustend18d8a12011-06-28 16:50:26 +00006This program and the accompanying materials
7are licensed and made available under the terms and conditions of the BSD License
8which accompanies this distribution. The full text of the license may be found at
9http://opensource.org/licenses/bsd-license.php
10
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
andrewfish949f3882011-05-11 18:31:20 +000013
14**/
15
16#include <PiDxe.h>
17
18#include <Library/BaseLib.h>
19#include <Library/DebugLib.h>
20#include <Library/UefiLib.h>
21#include <Library/UefiDriverEntryPoint.h>
22#include <Library/MemoryAllocationLib.h>
23#include <Library/UefiBootServicesTableLib.h>
24#include <Library/EmuThunkLib.h>
25
26#include <Protocol/Reset.h>
27
28
29VOID
30EFIAPI
31EmuResetSystem (
32 IN EFI_RESET_TYPE ResetType,
33 IN EFI_STATUS ResetStatus,
34 IN UINTN DataSize,
35 IN VOID *ResetData OPTIONAL
36 )
37{
38 EFI_STATUS Status;
39 UINTN HandleCount;
40 EFI_HANDLE *HandleBuffer;
41 UINTN Index;
42
43 //
44 // Disconnect all
45 //
46 Status = gBS->LocateHandleBuffer (
47 AllHandles,
48 NULL,
49 NULL,
50 &HandleCount,
51 &HandleBuffer
52 );
53 if (!EFI_ERROR (Status)) {
54 for (Index = 0; Index < HandleCount; Index++) {
55 Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
56 }
jljustend18d8a12011-06-28 16:50:26 +000057
andrewfish949f3882011-05-11 18:31:20 +000058 gBS->FreePool (HandleBuffer);
59 }
60
61
62 //
63 // Discard ResetType, always return 0 as exit code
64 //
65 gEmuThunk->Exit (0);
66
67 //
68 // Should never go here
69 //
70 ASSERT (FALSE);
71
72 return;
73}
74
75
76
77EFI_STATUS
78EFIAPI
79InitializeEmuReset (
80 IN EFI_HANDLE ImageHandle,
81 IN EFI_SYSTEM_TABLE *SystemTable
82 )
83/*++
84
85Routine Description:
86
87
88Arguments:
89
90 ImageHandle of the loaded driver
91 Pointer to the System Table
92
93Returns:
94
95 Status
96**/
97{
98 EFI_STATUS Status;
99 EFI_HANDLE Handle;
100
101 SystemTable->RuntimeServices->ResetSystem = EmuResetSystem;
102
103 Handle = NULL;
104 Status = gBS->InstallMultipleProtocolInterfaces (
105 &Handle,
106 &gEfiResetArchProtocolGuid,
107 NULL,
108 NULL
109 );
110 ASSERT_EFI_ERROR (Status);
111
112 return Status;
113}
114