]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PlatformPei/PlatformPeim.c
ca33ae5313c87515f552db59f449a0d6d601c22f
[mirror_edk2.git] / ArmPlatformPkg / PlatformPei / PlatformPeim.c
1 /** @file
2 *
3 * Copyright (c) 2011, ARM Limited. All rights reserved.
4 *
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
15 #include <PiPei.h>
16
17 //
18 // The protocols, PPI and GUID defintions for this module
19 //
20 #include <Ppi/ArmGlobalVariable.h>
21 #include <Ppi/MasterBootMode.h>
22 #include <Ppi/BootInRecoveryMode.h>
23 #include <Ppi/GuidedSectionExtraction.h>
24 //
25 // The Library classes this module consumes
26 //
27 #include <Library/ArmPlatformLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/HobLib.h>
31 #include <Library/PeimEntryPoint.h>
32 #include <Library/PeiServicesLib.h>
33 #include <Library/PcdLib.h>
34
35 #include <Guid/ArmGlobalVariableHob.h>
36
37 EFI_STATUS
38 EFIAPI
39 InitializePlatformPeim (
40 IN EFI_PEI_FILE_HANDLE FileHandle,
41 IN CONST EFI_PEI_SERVICES **PeiServices
42 );
43
44 EFI_STATUS
45 EFIAPI
46 PlatformPeim (
47 VOID
48 );
49
50 //
51 // Module globals
52 //
53 EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode = {
54 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
55 &gEfiPeiMasterBootModePpiGuid,
56 NULL
57 };
58
59 EFI_PEI_PPI_DESCRIPTOR mPpiListRecoveryBootMode = {
60 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
61 &gEfiPeiBootInRecoveryModePpiGuid,
62 NULL
63 };
64
65 VOID
66 EFIAPI
67 BuildGlobalVariableHob (
68 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,
69 IN UINT32 GlobalVariableSize
70 )
71 {
72 EFI_STATUS Status;
73 ARM_HOB_GLOBAL_VARIABLE *Hob;
74
75 Status = PeiServicesCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE), (VOID**)&Hob);
76 if (!EFI_ERROR(Status)) {
77 CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);
78 Hob->GlobalVariableBase = GlobalVariableBase;
79 Hob->GlobalVariableSize = GlobalVariableSize;
80 }
81 }
82
83 /*++
84
85 Routine Description:
86
87
88
89 Arguments:
90
91 FileHandle - Handle of the file being invoked.
92 PeiServices - Describes the list of possible PEI Services.
93
94 Returns:
95
96 Status - EFI_SUCCESS if the boot mode could be set
97
98 --*/
99 EFI_STATUS
100 EFIAPI
101 InitializePlatformPeim (
102 IN EFI_PEI_FILE_HANDLE FileHandle,
103 IN CONST EFI_PEI_SERVICES **PeiServices
104 )
105 {
106 EFI_STATUS Status;
107 UINTN BootMode;
108 ARM_GLOBAL_VARIABLE_PPI *ArmGlobalVariablePpi;
109 EFI_PHYSICAL_ADDRESS GlobalVariableBase;
110
111 DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));
112
113 PlatformPeim ();
114
115 Status = PeiServicesLocatePpi (&gArmGlobalVariablePpiGuid, 0, NULL, (VOID**)&ArmGlobalVariablePpi);
116 if (!EFI_ERROR(Status)) {
117 Status = ArmGlobalVariablePpi->GetGlobalVariableMemory (&GlobalVariableBase);
118
119 if (!EFI_ERROR(Status)) {
120 // Declare the Global Variable HOB
121 BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));
122 }
123 }
124
125 BootMode = ArmPlatformGetBootMode ();
126 Status = (**PeiServices).SetBootMode (PeiServices, (UINT8) BootMode);
127 ASSERT_EFI_ERROR (Status);
128
129 Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListBootMode);
130 ASSERT_EFI_ERROR (Status);
131
132 if (BootMode == BOOT_IN_RECOVERY_MODE) {
133 Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListRecoveryBootMode);
134 ASSERT_EFI_ERROR (Status);
135 }
136
137 return Status;
138 }