1 /** @file
2   Driver entry for KbcReset driver.
3 
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 
14 #include <PiDxe.h>
15 
16 #include <Library/DebugLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/ResetSystemLib.h>
19 
20 #include <Protocol/Reset.h>
21 
22 //
23 // The handle onto which the Reset Architectural Protocol is installed
24 //
25 EFI_HANDLE  mResetHandle = NULL;
26 
27 /**
28   Reset the system.
29 
30   @param ResetType       warm or cold
31   @param ResetStatus     possible cause of reset
32   @param DataSize        Size of ResetData in bytes
33   @param ResetData       Optional Unicode string
34 
35 **/
36 VOID
37 EFIAPI
KbcResetSystem(IN EFI_RESET_TYPE ResetType,IN EFI_STATUS ResetStatus,IN UINTN DataSize,IN VOID * ResetData OPTIONAL)38 KbcResetSystem (
39   IN EFI_RESET_TYPE   ResetType,
40   IN EFI_STATUS       ResetStatus,
41   IN UINTN            DataSize,
42   IN VOID             *ResetData OPTIONAL
43   )
44 {
45   switch (ResetType) {
46   case EfiResetWarm:
47     ResetWarm ();
48     break;
49   case EfiResetCold:
50     ResetCold ();
51     break;
52   case EfiResetShutdown:
53     ResetShutdown ();
54     break;
55   default:
56     return;
57   }
58 
59   //
60   // Given we should have reset getting here would be bad
61   //
62   ASSERT (FALSE);
63 }
64 
65 /**
66   Initialize the state information for the Reset Architectural Protocol.
67 
68   @param ImageHandle     Handle of the loaded driver
69   @param SystemTable     Pointer to the System Table
70 
71   @retval EFI_SUCCESS           Thread can be successfully created
72   @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure
73   @retval EFI_DEVICE_ERROR      Cannot create the timer service
74 
75 **/
76 EFI_STATUS
77 EFIAPI
InitializeReset(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)78 InitializeReset (
79   IN EFI_HANDLE        ImageHandle,
80   IN EFI_SYSTEM_TABLE  *SystemTable
81   )
82 {
83   EFI_STATUS  Status;
84 
85   //
86   // Make sure the Reset Architectural Protocol is not already installed in the system
87   //
88   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiResetArchProtocolGuid);
89 
90   //
91   // Hook the runtime service table
92   //
93   SystemTable->RuntimeServices->ResetSystem = KbcResetSystem;
94 
95   //
96   // Now install the Reset RT AP on a new handle
97   //
98   Status = gBS->InstallMultipleProtocolInterfaces (
99                   &mResetHandle,
100                   &gEfiResetArchProtocolGuid, NULL,
101                   NULL
102                   );
103   ASSERT_EFI_ERROR (Status);
104 
105   return Status;
106 }
107