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