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