]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - DuetPkg/AcpiResetDxe/Reset.c
Do not lock the volume when the volume maps to a file instead of a physical disk.
[mirror_edk2.git] / DuetPkg / AcpiResetDxe / Reset.c
... / ...
CommitLineData
1/*++ @file\r
2 Reset Architectural Protocol implementation.\r
3\r
4Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13--*/\r
14\r
15#include <PiDxe.h>\r
16\r
17#include <Protocol/Reset.h>\r
18\r
19#include <Guid/AcpiDescription.h>\r
20\r
21#include <Library/BaseLib.h>\r
22#include <Library/IoLib.h>\r
23#include <Library/PciLib.h>\r
24#include <Library/HobLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/BaseMemoryLib.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28\r
29///\r
30/// Handle for the Reset Architectural Protocol\r
31///\r
32EFI_HANDLE mResetHandle = NULL;\r
33\r
34///\r
35/// Copy of ACPI Description HOB in runtime memory\r
36///\r
37EFI_ACPI_DESCRIPTION mAcpiDescription;\r
38\r
39/**\r
40 Reset the system.\r
41\r
42 @param[in] ResetType Warm or cold\r
43 @param[in] ResetStatus Possible cause of reset\r
44 @param[in] DataSize Size of ResetData in bytes\r
45 @param[in] ResetData Optional Unicode string\r
46\r
47**/\r
48VOID\r
49EFIAPI\r
50EfiAcpiResetSystem (\r
51 IN EFI_RESET_TYPE ResetType,\r
52 IN EFI_STATUS ResetStatus,\r
53 IN UINTN DataSize,\r
54 IN VOID *ResetData OPTIONAL\r
55 )\r
56{\r
57 UINT8 Dev;\r
58 UINT8 Func;\r
59 UINT8 Register;\r
60 \r
61 switch (ResetType) {\r
62 case EfiResetShutdown:\r
63 //\r
64 // 1. Write SLP_TYPa\r
65 //\r
66 if ((mAcpiDescription.PM1a_CNT_BLK.Address != 0) && (mAcpiDescription.SLP_TYPa != 0)) {\r
67 switch (mAcpiDescription.PM1a_CNT_BLK.AddressSpaceId) {\r
68 case EFI_ACPI_3_0_SYSTEM_IO:\r
69 IoAndThenOr16 ((UINTN)mAcpiDescription.PM1a_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPa << 10)));\r
70 break;\r
71 case EFI_ACPI_3_0_SYSTEM_MEMORY:\r
72 MmioAndThenOr16 ((UINTN)mAcpiDescription.PM1a_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPa << 10)));\r
73 break;\r
74 }\r
75 }\r
76\r
77 //\r
78 // 2. Write SLP_TYPb\r
79 //\r
80 if ((mAcpiDescription.PM1b_CNT_BLK.Address != 0) && (mAcpiDescription.SLP_TYPb != 0)) {\r
81 switch (mAcpiDescription.PM1b_CNT_BLK.AddressSpaceId) {\r
82 case EFI_ACPI_3_0_SYSTEM_IO:\r
83 IoAndThenOr16 ((UINTN)mAcpiDescription.PM1b_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPb << 10)));\r
84 break;\r
85 case EFI_ACPI_3_0_SYSTEM_MEMORY:\r
86 MmioAndThenOr16 ((UINTN)mAcpiDescription.PM1b_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPb << 10)));\r
87 break;\r
88 }\r
89 }\r
90 //\r
91 // If Shutdown fails, then let fall through to reset \r
92 //\r
93 case EfiResetWarm:\r
94 case EfiResetCold:\r
95 if ((mAcpiDescription.RESET_REG.Address != 0) &&\r
96 ((mAcpiDescription.RESET_REG.AddressSpaceId == EFI_ACPI_3_0_SYSTEM_IO) ||\r
97 (mAcpiDescription.RESET_REG.AddressSpaceId == EFI_ACPI_3_0_SYSTEM_MEMORY) ||\r
98 (mAcpiDescription.RESET_REG.AddressSpaceId == EFI_ACPI_3_0_PCI_CONFIGURATION_SPACE))) {\r
99 //\r
100 // Use ACPI System Reset\r
101 //\r
102 switch (mAcpiDescription.RESET_REG.AddressSpaceId) {\r
103 case EFI_ACPI_3_0_SYSTEM_IO:\r
104 //\r
105 // Send reset request through I/O port register\r
106 //\r
107 IoWrite8 ((UINTN)mAcpiDescription.RESET_REG.Address, mAcpiDescription.RESET_VALUE);\r
108 //\r
109 // Halt \r
110 //\r
111 CpuDeadLoop ();\r
112 case EFI_ACPI_3_0_SYSTEM_MEMORY:\r
113 //\r
114 // Send reset request through MMIO register\r
115 //\r
116 MmioWrite8 ((UINTN)mAcpiDescription.RESET_REG.Address, mAcpiDescription.RESET_VALUE);\r
117 //\r
118 // Halt \r
119 //\r
120 CpuDeadLoop ();\r
121 case EFI_ACPI_3_0_PCI_CONFIGURATION_SPACE:\r
122 //\r
123 // Send reset request through PCI register\r
124 //\r
125 Register = (UINT8)mAcpiDescription.RESET_REG.Address;\r
126 Func = (UINT8) (RShiftU64 (mAcpiDescription.RESET_REG.Address, 16) & 0x7);\r
127 Dev = (UINT8) (RShiftU64 (mAcpiDescription.RESET_REG.Address, 32) & 0x1F);\r
128 PciWrite8 (PCI_LIB_ADDRESS (0, Dev, Func, Register), mAcpiDescription.RESET_VALUE);\r
129 //\r
130 // Halt \r
131 //\r
132 CpuDeadLoop ();\r
133 }\r
134 }\r
135\r
136 //\r
137 // If system comes here, means ACPI reset is not supported, so do Legacy System Reset, assume 8042 available\r
138 //\r
139 IoWrite8 (0x64, 0xfe);\r
140 CpuDeadLoop ();\r
141 }\r
142\r
143 //\r
144 // Given we should have reset getting here would be bad\r
145 //\r
146 ASSERT (FALSE);\r
147 CpuDeadLoop();\r
148}\r
149\r
150/**\r
151 Initialize the state information for the Reset Architectural Protocol.\r
152\r
153 @param[in] ImageHandle Image handle of the loaded driver\r
154 @param[in] SystemTable Pointer to the System Table\r
155\r
156 @retval EFI_SUCCESS Thread can be successfully created\r
157 @retval EFI_UNSUPPORTED Cannot find the info to reset system\r
158\r
159**/\r
160EFI_STATUS\r
161EFIAPI\r
162InitializeReset (\r
163 IN EFI_HANDLE ImageHandle,\r
164 IN EFI_SYSTEM_TABLE *SystemTable\r
165 )\r
166{\r
167 EFI_STATUS Status;\r
168 EFI_HOB_GUID_TYPE *HobAcpiDescription;\r
169\r
170 //\r
171 // Make sure the Reset Architectural Protocol is not already installed in the system\r
172 //\r
173 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiResetArchProtocolGuid);\r
174\r
175 //\r
176 // Get ACPI Description HOB\r
177 //\r
178 HobAcpiDescription = GetFirstGuidHob (&gEfiAcpiDescriptionGuid);\r
179 if (HobAcpiDescription == NULL) {\r
180 return EFI_UNSUPPORTED;\r
181 }\r
182\r
183 //\r
184 // Copy it to Runtime Memory\r
185 //\r
186 ASSERT (sizeof (EFI_ACPI_DESCRIPTION) == GET_GUID_HOB_DATA_SIZE (HobAcpiDescription));\r
187 CopyMem (&mAcpiDescription, GET_GUID_HOB_DATA (HobAcpiDescription), sizeof (EFI_ACPI_DESCRIPTION));\r
188\r
189 DEBUG ((DEBUG_INFO, "ACPI Reset Base - %lx\n", mAcpiDescription.RESET_REG.Address));\r
190 DEBUG ((DEBUG_INFO, "ACPI Reset Value - %02x\n", (UINTN)mAcpiDescription.RESET_VALUE));\r
191 DEBUG ((DEBUG_INFO, "IAPC support - %x\n", (UINTN)(mAcpiDescription.IAPC_BOOT_ARCH)));\r
192 \r
193 //\r
194 // Hook the runtime service table\r
195 //\r
196 SystemTable->RuntimeServices->ResetSystem = EfiAcpiResetSystem;\r
197\r
198 //\r
199 // Install the Reset Architectural Protocol onto a new handle\r
200 //\r
201 Status = gBS->InstallMultipleProtocolInterfaces (\r
202 &mResetHandle,\r
203 &gEfiResetArchProtocolGuid, NULL,\r
204 NULL\r
205 );\r
206 ASSERT_EFI_ERROR (Status);\r
207\r
208 return Status;\r
209}\r