]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
get the definition for EFI_PEI_PCI_CFG_PPI_WIDTH from PciCfg2.h
[mirror_edk2.git] / MdeModulePkg / Universal / CapsuleRuntimeDxe / CapsuleService.c
... / ...
CommitLineData
1/** @file\r
2 Capsule Runtime Service.\r
3\r
4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This 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 "CapsuleService.h"\r
16\r
17EFI_STATUS\r
18EFIAPI\r
19UpdateCapsule (\r
20 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
21 IN UINTN CapsuleCount,\r
22 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r
23 )\r
24/*++\r
25\r
26Routine Description:\r
27\r
28 This code finds whether the capsules need reset to update, if not, update immediately.\r
29\r
30Arguments:\r
31\r
32 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
33 CapsuleCount The number of capsule\r
34 ScatterGatherList Physical address of datablock list points to capsule\r
35\r
36Returns:\r
37\r
38 EFI STATUS\r
39 EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is\r
40 not set, the capsule has been successfully processed by the firmware.\r
41 If it set, the ScattlerGatherList is successfully to be set.\r
42 EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported.\r
43 EFI_DEVICE_ERROR Failed to SetVariable or ProcessFirmwareVolume.\r
44\r
45--*/\r
46{\r
47 UINTN ArrayNumber;\r
48 EFI_STATUS Status;\r
49 EFI_CAPSULE_HEADER *CapsuleHeader;\r
50\r
51 if (CapsuleCount < 1) {\r
52 return EFI_INVALID_PARAMETER;\r
53 }\r
54\r
55 CapsuleHeader = NULL;\r
56\r
57 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
58 //\r
59 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r
60 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r
61 //\r
62 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
63 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
64 return EFI_INVALID_PARAMETER;\r
65 }\r
66 //\r
67 // Check Capsule image without populate flag by firmware support capsule function \r
68 //\r
69 if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
70 (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
71 return EFI_UNSUPPORTED;\r
72 }\r
73 }\r
74\r
75 //\r
76 // Assume that capsules have the same flags on reseting or not.\r
77 //\r
78 CapsuleHeader = CapsuleHeaderArray[0];\r
79\r
80 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
81 //\r
82 // Check if the platform supports update capsule across a system reset\r
83 //\r
84 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r
85 return EFI_UNSUPPORTED;\r
86 }\r
87 //\r
88 // ScatterGatherList is only referenced if the capsules are defined to persist across\r
89 // system reset. \r
90 //\r
91 if (ScatterGatherList == (EFI_PHYSICAL_ADDRESS) (UINTN) NULL) {\r
92 return EFI_INVALID_PARAMETER;\r
93 } else {\r
94 //\r
95 // ScatterGatherList is only referenced if the capsules are defined to persist across\r
96 // system reset. Set its value into NV storage to let pre-boot driver to pick it up \r
97 // after coming through a system reset.\r
98 //\r
99 Status = EfiSetVariable (\r
100 EFI_CAPSULE_VARIABLE_NAME,\r
101 &gEfiCapsuleVendorGuid,\r
102 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
103 sizeof (UINTN),\r
104 (VOID *) &ScatterGatherList\r
105 );\r
106 if (Status != EFI_SUCCESS) {\r
107 return Status;\r
108 }\r
109 //\r
110 // Successfully set the capsule image address into variable.\r
111 //\r
112 return EFI_SUCCESS;\r
113 }\r
114 }\r
115\r
116 //\r
117 // The rest occurs in the condition of non-reset mode\r
118 // Now Runtime mode doesn't support the non-reset capsule image.\r
119 //\r
120 if (EfiAtRuntime ()) {\r
121 return EFI_UNSUPPORTED;\r
122 }\r
123\r
124 //\r
125 // Here should be in the boot-time for non-reset capsule image\r
126 // Default process to Update Capsule image into Flash.\r
127 //\r
128 for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r
129 Status = ProcessCapsuleImage (CapsuleHeaderArray[ArrayNumber]);\r
130 if (EFI_ERROR (Status)) {\r
131 return Status;\r
132 }\r
133 }\r
134\r
135 return EFI_SUCCESS;\r
136}\r
137\r
138\r
139\r
140EFI_STATUS\r
141EFIAPI\r
142QueryCapsuleCapabilities (\r
143 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
144 IN UINTN CapsuleCount,\r
145 OUT UINT64 *MaxiumCapsuleSize,\r
146 OUT EFI_RESET_TYPE *ResetType\r
147 )\r
148/*++\r
149\r
150Routine Description:\r
151\r
152 This code is to query about capsule capability.\r
153\r
154Arguments:\r
155\r
156 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
157 CapsuleCount The number of capsule\r
158 MaxiumCapsuleSize Max capsule size is supported\r
159 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.\r
160 If reset is needed, return EfiResetWarm.\r
161\r
162Returns:\r
163\r
164 EFI STATUS\r
165 EFI_SUCCESS Valid answer returned\r
166 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.\r
167 EFI_UNSUPPORTED The capsule type is not supported.\r
168\r
169--*/\r
170{\r
171 UINTN ArrayNumber;\r
172 EFI_CAPSULE_HEADER *CapsuleHeader;\r
173\r
174 if (CapsuleCount < 1) {\r
175 return EFI_INVALID_PARAMETER;\r
176 }\r
177\r
178 if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {\r
179 return EFI_INVALID_PARAMETER;\r
180 }\r
181\r
182 CapsuleHeader = NULL;\r
183\r
184 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
185 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
186 //\r
187 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r
188 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r
189 //\r
190 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
191 return EFI_INVALID_PARAMETER;\r
192 }\r
193 //\r
194 // Check Capsule image without populate flag by firmware support capsule function \r
195 //\r
196 if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
197 (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
198 return EFI_UNSUPPORTED;\r
199 }\r
200 }\r
201\r
202 //\r
203 //Assume that capsules have the same flags on reseting or not.\r
204 //\r
205 CapsuleHeader = CapsuleHeaderArray[0];\r
206 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
207 //\r
208 //Check if the platform supports update capsule across a system reset\r
209 //\r
210 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r
211 return EFI_UNSUPPORTED;\r
212 }\r
213 *ResetType = EfiResetWarm;\r
214 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule);\r
215 } else {\r
216 *ResetType = EfiResetCold;\r
217 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);\r
218 }\r
219 return EFI_SUCCESS;\r
220}\r
221\r
222\r
223EFI_STATUS\r
224EFIAPI\r
225CapsuleServiceInitialize (\r
226 IN EFI_HANDLE ImageHandle,\r
227 IN EFI_SYSTEM_TABLE *SystemTable\r
228 )\r
229/*++\r
230\r
231Routine Description:\r
232\r
233 This code is capsule runtime service initialization.\r
234\r
235Arguments:\r
236\r
237 ImageHandle The image handle\r
238 SystemTable The system table.\r
239\r
240Returns:\r
241\r
242 EFI STATUS\r
243\r
244--*/\r
245{\r
246 EFI_STATUS Status;\r
247 EFI_HANDLE NewHandle;\r
248\r
249 SystemTable->RuntimeServices->UpdateCapsule = UpdateCapsule;\r
250 SystemTable->RuntimeServices->QueryCapsuleCapabilities = QueryCapsuleCapabilities;\r
251\r
252 //\r
253 // Now install the Capsule Architectural Protocol on a new handle\r
254 //\r
255 NewHandle = NULL;\r
256\r
257 Status = gBS->InstallMultipleProtocolInterfaces (\r
258 &NewHandle,\r
259 &gEfiCapsuleArchProtocolGuid,\r
260 NULL,\r
261 NULL\r
262 );\r
263 ASSERT_EFI_ERROR (Status);\r
264\r
265 return EFI_SUCCESS;\r
266}\r