]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c
ArmPkg: implement ResetSystemLib using PSCI 0.2 calls
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPsciResetSystemLib / ArmVirtPsciResetSystemLib.c
CommitLineData
9180ab73
OM
1/** @file\r
2 Support ResetSystem Runtime call using PSCI calls\r
3\r
4 Note: A similar library is implemented in\r
5 ArmPkg/Library/ArmPsciResetSystemLib. Similar issues might\r
6 exist in this implementation too.\r
7\r
8 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
9 Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>\r
10 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
11\r
12 This program and the accompanying materials\r
13 are licensed and made available under the terms and conditions of the BSD License\r
14 which accompanies this distribution. The full text of the license may be found at\r
15 http://opensource.org/licenses/bsd-license.php\r
16\r
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
20**/\r
21\r
22#include <PiDxe.h>\r
23\r
24#include <Library/BaseLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/EfiResetSystemLib.h>\r
27#include <Library/ArmSmcLib.h>\r
28#include <Library/ArmHvcLib.h>\r
93f9a23f 29#include <Library/UefiBootServicesTableLib.h>\r
9180ab73
OM
30\r
31#include <IndustryStandard/ArmStdSmc.h>\r
32\r
93f9a23f
AB
33#include <Protocol/FdtClient.h>\r
34\r
9180ab73
OM
35STATIC UINT32 mArmPsciMethod;\r
36\r
37RETURN_STATUS\r
38EFIAPI\r
39ArmPsciResetSystemLibConstructor (\r
40 VOID\r
41 )\r
42{\r
93f9a23f
AB
43 EFI_STATUS Status;\r
44 FDT_CLIENT_PROTOCOL *FdtClient;\r
45 CONST VOID *Prop;\r
46\r
47 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
48 (VOID **)&FdtClient);\r
49 ASSERT_EFI_ERROR (Status);\r
50\r
51 Status = FdtClient->FindCompatibleNodeProperty (FdtClient, "arm,psci-0.2",\r
52 "method", &Prop, NULL);\r
53 if (EFI_ERROR (Status)) {\r
54 return Status;\r
55 }\r
56\r
57 if (AsciiStrnCmp (Prop, "hvc", 3) == 0) {\r
58 mArmPsciMethod = 1;\r
59 } else if (AsciiStrnCmp (Prop, "smc", 3) == 0) {\r
60 mArmPsciMethod = 2;\r
61 } else {\r
62 DEBUG ((EFI_D_ERROR, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__,\r
63 Prop));\r
64 return EFI_NOT_FOUND;\r
65 }\r
66 return EFI_SUCCESS;\r
9180ab73
OM
67}\r
68\r
69/**\r
70 Resets the entire platform.\r
71\r
72 @param ResetType The type of reset to perform.\r
73 @param ResetStatus The status code for the reset.\r
74 @param DataSize The size, in bytes, of WatchdogData.\r
75 @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or\r
76 EfiResetShutdown the data buffer starts with a Null-terminated\r
77 Unicode string, optionally followed by additional binary data.\r
78\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82LibResetSystem (\r
83 IN EFI_RESET_TYPE ResetType,\r
84 IN EFI_STATUS ResetStatus,\r
85 IN UINTN DataSize,\r
86 IN CHAR16 *ResetData OPTIONAL\r
87 )\r
88{\r
89 ARM_SMC_ARGS ArmSmcArgs;\r
90 ARM_HVC_ARGS ArmHvcArgs;\r
91\r
92 switch (ResetType) {\r
93\r
94 case EfiResetPlatformSpecific:\r
95 // Map the platform specific reset as reboot\r
96 case EfiResetWarm:\r
97 // Map a warm reset into a cold reset\r
98 case EfiResetCold:\r
99 // Send a PSCI 0.2 SYSTEM_RESET command\r
100 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r
101 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r
102 break;\r
103 case EfiResetShutdown:\r
104 // Send a PSCI 0.2 SYSTEM_OFF command\r
105 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r
106 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r
107 break;\r
108 default:\r
109 ASSERT (FALSE);\r
110 return EFI_UNSUPPORTED;\r
111 }\r
112\r
113 switch (mArmPsciMethod) {\r
114 case 1:\r
115 ArmCallHvc (&ArmHvcArgs);\r
116 break;\r
117\r
118 case 2:\r
119 ArmCallSmc (&ArmSmcArgs);\r
120 break;\r
121\r
122 default:\r
123 DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r
124 return EFI_UNSUPPORTED;\r
125 }\r
126\r
127 // We should never be here\r
128 DEBUG ((EFI_D_ERROR, "%a: PSCI Reset failed\n", __FUNCTION__));\r
129 CpuDeadLoop ();\r
130 return EFI_UNSUPPORTED;\r
131}\r
132\r
133/**\r
134 Initialize any infrastructure required for LibResetSystem () to function.\r
135\r
136 @param ImageHandle The firmware allocated handle for the EFI image.\r
137 @param SystemTable A pointer to the EFI System Table.\r
138\r
139 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
140\r
141**/\r
142EFI_STATUS\r
143EFIAPI\r
144LibInitializeResetSystem (\r
145 IN EFI_HANDLE ImageHandle,\r
146 IN EFI_SYSTEM_TABLE *SystemTable\r
147 )\r
148{\r
149 return EFI_SUCCESS;\r
150}\r