]>
Commit | Line | Data |
---|---|---|
fc547e08 | 1 | /** @file \r |
5944a83b | 2 | All Pcd Ppi services are implemented here.\r |
fc547e08 | 3 | \r |
2db48a1f | 4 | Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r |
bfb4c2ba CS |
5 | (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
80408db0 | 13 | \r |
80408db0 | 14 | **/\r |
15 | \r | |
80408db0 | 16 | #include "Service.h"\r |
17 | \r | |
17e7fa8f | 18 | ///\r |
19 | /// Instance of PCD_PPI protocol is EDKII native implementation.\r | |
20 | /// This protocol instance support dynamic and dynamicEx type PCDs.\r | |
21 | ///\r | |
80408db0 | 22 | PCD_PPI mPcdPpiInstance = {\r |
23 | PeiPcdSetSku,\r | |
24 | \r | |
25 | PeiPcdGet8,\r | |
26 | PeiPcdGet16, \r | |
27 | PeiPcdGet32, \r | |
28 | PeiPcdGet64, \r | |
29 | PeiPcdGetPtr, \r | |
30 | PeiPcdGetBool, \r | |
31 | PeiPcdGetSize,\r | |
32 | \r | |
33 | PeiPcdGet8Ex,\r | |
34 | PeiPcdGet16Ex, \r | |
35 | PeiPcdGet32Ex, \r | |
36 | PeiPcdGet64Ex, \r | |
37 | PeiPcdGetPtrEx, \r | |
38 | PeiPcdGetBoolEx, \r | |
39 | PeiPcdGetSizeEx,\r | |
40 | \r | |
41 | PeiPcdSet8,\r | |
42 | PeiPcdSet16, \r | |
43 | PeiPcdSet32, \r | |
44 | PeiPcdSet64, \r | |
45 | PeiPcdSetPtr, \r | |
46 | PeiPcdSetBool, \r | |
47 | \r | |
48 | PeiPcdSet8Ex,\r | |
49 | PeiPcdSet16Ex, \r | |
50 | PeiPcdSet32Ex, \r | |
51 | PeiPcdSet64Ex, \r | |
52 | PeiPcdSetPtrEx, \r | |
53 | PeiPcdSetBoolEx,\r | |
54 | \r | |
55 | PeiRegisterCallBackOnSet,\r | |
56 | PcdUnRegisterCallBackOnSet,\r | |
57 | PeiPcdGetNextToken,\r | |
58 | PeiPcdGetNextTokenSpace\r | |
59 | };\r | |
60 | \r | |
17e7fa8f | 61 | ///\r |
62 | /// Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.\r | |
63 | /// This PPI instance only support dyanmicEx type PCD.\r | |
64 | ///\r | |
c896d682 | 65 | EFI_PEI_PCD_PPI mEfiPcdPpiInstance = {\r |
66 | PeiPcdSetSku,\r | |
67 | \r | |
68 | PeiPcdGet8Ex,\r | |
69 | PeiPcdGet16Ex,\r | |
70 | PeiPcdGet32Ex,\r | |
71 | PeiPcdGet64Ex,\r | |
72 | PeiPcdGetPtrEx,\r | |
73 | PeiPcdGetBoolEx,\r | |
74 | PeiPcdGetSizeEx,\r | |
75 | PeiPcdSet8Ex,\r | |
76 | PeiPcdSet16Ex,\r | |
77 | PeiPcdSet32Ex,\r | |
78 | PeiPcdSet64Ex,\r | |
79 | PeiPcdSetPtrEx,\r | |
80 | PeiPcdSetBoolEx,\r | |
81 | (EFI_PEI_PCD_PPI_CALLBACK_ON_SET) PeiRegisterCallBackOnSet,\r | |
82 | (EFI_PEI_PCD_PPI_CANCEL_CALLBACK) PcdUnRegisterCallBackOnSet,\r | |
83 | PeiPcdGetNextToken,\r | |
84 | PeiPcdGetNextTokenSpace\r | |
85 | };\r | |
86 | \r | |
96d6d004 SZ |
87 | ///\r |
88 | /// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.\r | |
89 | /// This protocol instance support dynamic and dynamicEx type PCDs.\r | |
90 | ///\r | |
91 | GET_PCD_INFO_PPI mGetPcdInfoInstance = {\r | |
92 | PeiGetPcdInfoGetInfo,\r | |
93 | PeiGetPcdInfoGetInfoEx,\r | |
94 | PeiGetPcdInfoGetSku\r | |
95 | };\r | |
96 | \r | |
97 | ///\r | |
98 | /// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.\r | |
99 | /// This PPI instance only support dyanmicEx type PCD.\r | |
100 | ///\r | |
101 | EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance = {\r | |
102 | PeiGetPcdInfoGetInfoEx,\r | |
103 | PeiGetPcdInfoGetSku\r | |
104 | };\r | |
105 | \r | |
17e7fa8f | 106 | EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r |
107 | {\r | |
108 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r | |
109 | &gPcdPpiGuid,\r | |
110 | &mPcdPpiInstance\r | |
111 | },\r | |
112 | {\r | |
113 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
114 | &gEfiPeiPcdPpiGuid,\r | |
115 | &mEfiPcdPpiInstance\r | |
116 | }\r | |
c896d682 | 117 | };\r |
118 | \r | |
96d6d004 SZ |
119 | EFI_PEI_PPI_DESCRIPTOR mPpiList2[] = {\r |
120 | {\r | |
121 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r | |
122 | &gGetPcdInfoPpiGuid,\r | |
123 | &mGetPcdInfoInstance\r | |
124 | },\r | |
125 | {\r | |
126 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
127 | &gEfiGetPcdInfoPpiGuid,\r | |
128 | &mEfiGetPcdInfoInstance\r | |
129 | }\r | |
130 | };\r | |
131 | \r | |
219247e1 LG |
132 | /**\r |
133 | Callback on SET PcdSetNvStoreDefaultId\r | |
134 | \r | |
135 | Once PcdSetNvStoreDefaultId is set, the default NV storage will be found from\r | |
136 | PcdNvStoreDefaultValueBuffer, and built into VariableHob.\r | |
137 | \r | |
138 | @param[in] CallBackGuid The PCD token GUID being set.\r | |
139 | @param[in] CallBackToken The PCD token number being set.\r | |
140 | @param[in, out] TokenData A pointer to the token data being set.\r | |
141 | @param[in] TokenDataSize The size, in bytes, of the data being set.\r | |
142 | \r | |
143 | **/\r | |
144 | VOID\r | |
145 | EFIAPI\r | |
146 | PcdSetNvStoreDefaultIdCallBack (\r | |
147 | IN CONST EFI_GUID *CallBackGuid, OPTIONAL\r | |
148 | IN UINTN CallBackToken,\r | |
149 | IN OUT VOID *TokenData,\r | |
150 | IN UINTN TokenDataSize\r | |
151 | )\r | |
152 | {\r | |
153 | EFI_STATUS Status;\r | |
154 | UINT16 DefaultId;\r | |
155 | SKU_ID SkuId;\r | |
156 | UINTN FullSize;\r | |
157 | UINTN Index;\r | |
158 | UINT8 *DataBuffer;\r | |
159 | UINT8 *VarStoreHobData;\r | |
160 | UINT8 *BufferEnd;\r | |
161 | BOOLEAN IsFound;\r | |
162 | VARIABLE_STORE_HEADER *NvStoreBuffer;\r | |
163 | PCD_DEFAULT_DATA *DataHeader;\r | |
164 | PCD_DEFAULT_INFO *DefaultInfo;\r | |
165 | PCD_DATA_DELTA *DeltaData;\r | |
166 | \r | |
167 | DefaultId = *(UINT16 *) TokenData;\r | |
168 | SkuId = GetPcdDatabase()->SystemSkuId;\r | |
169 | IsFound = FALSE;\r | |
170 | \r | |
171 | if (PeiPcdGetSizeEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer)) > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {\r | |
172 | DataBuffer = (UINT8 *) PeiPcdGetPtrEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer));\r | |
173 | FullSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *) DataBuffer)->Length;\r | |
174 | DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER));\r | |
175 | //\r | |
176 | // The first section data includes NV storage default setting.\r | |
177 | //\r | |
178 | NvStoreBuffer = (VARIABLE_STORE_HEADER *) ((UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize);\r | |
179 | VarStoreHobData = (UINT8 *) BuildGuidHob (&NvStoreBuffer->Signature, NvStoreBuffer->Size);\r | |
180 | ASSERT (VarStoreHobData != NULL);\r | |
181 | CopyMem (VarStoreHobData, NvStoreBuffer, NvStoreBuffer->Size);\r | |
182 | //\r | |
183 | // Find the matched SkuId and DefaultId in the first section\r | |
184 | //\r | |
185 | DefaultInfo = &(DataHeader->DefaultInfo[0]);\r | |
186 | BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r | |
187 | while ((UINT8 *) DefaultInfo < BufferEnd) {\r | |
188 | if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r | |
189 | IsFound = TRUE;\r | |
190 | break;\r | |
191 | }\r | |
192 | DefaultInfo ++;\r | |
193 | }\r | |
194 | //\r | |
195 | // Find the matched SkuId and DefaultId in the remaining section\r | |
196 | //\r | |
197 | Index = sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER) + ((DataHeader->DataSize + 7) & (~7));\r | |
198 | DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r | |
199 | while (!IsFound && Index < FullSize && DataHeader->DataSize != 0xFFFFFFFF) {\r | |
200 | DefaultInfo = &(DataHeader->DefaultInfo[0]);\r | |
201 | BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r | |
202 | while ((UINT8 *) DefaultInfo < BufferEnd) {\r | |
203 | if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r | |
204 | IsFound = TRUE;\r | |
205 | break;\r | |
206 | }\r | |
207 | DefaultInfo ++;\r | |
208 | }\r | |
209 | if (IsFound) {\r | |
210 | DeltaData = (PCD_DATA_DELTA *) BufferEnd;\r | |
211 | BufferEnd = (UINT8 *) DataHeader + DataHeader->DataSize;\r | |
212 | while ((UINT8 *) DeltaData < BufferEnd) {\r | |
213 | *(VarStoreHobData + DeltaData->Offset) = (UINT8) DeltaData->Value;\r | |
214 | DeltaData ++;\r | |
215 | }\r | |
216 | break;\r | |
217 | }\r | |
218 | Index = (Index + DataHeader->DataSize + 7) & (~7) ;\r | |
219 | DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r | |
220 | }\r | |
221 | }\r | |
222 | \r | |
223 | Status = PcdUnRegisterCallBackOnSet (\r | |
224 | &gEfiMdeModulePkgTokenSpaceGuid,\r | |
225 | PcdToken(PcdSetNvStoreDefaultId),\r | |
226 | PcdSetNvStoreDefaultIdCallBack\r | |
227 | );\r | |
228 | ASSERT_EFI_ERROR (Status);\r | |
229 | }\r | |
230 | \r | |
7c736265 LG |
231 | /**\r |
232 | Report Pei PCD database of all SKUs as Guid HOB so that DxePcd can access it.\r | |
233 | \r | |
234 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r | |
235 | @param NotifyDescriptor Address of the notification descriptor data structure.\r | |
236 | @param Ppi Address of the PPI that was installed.\r | |
237 | \r | |
238 | @retval EFI_SUCCESS Successfully update the Boot records.\r | |
239 | **/\r | |
240 | EFI_STATUS\r | |
241 | EFIAPI\r | |
242 | EndOfPeiSignalPpiNotifyCallback (\r | |
243 | IN EFI_PEI_SERVICES **PeiServices,\r | |
244 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
245 | IN VOID *Ppi\r | |
246 | )\r | |
247 | {\r | |
248 | PEI_PCD_DATABASE *Database;\r | |
249 | EFI_BOOT_MODE BootMode;\r | |
250 | EFI_STATUS Status;\r | |
251 | UINTN Instance;\r | |
252 | EFI_PEI_FV_HANDLE VolumeHandle;\r | |
253 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
254 | VOID *PcdDb;\r | |
255 | UINT32 Length;\r | |
256 | PEI_PCD_DATABASE *PeiPcdDb;\r | |
257 | \r | |
258 | Status = PeiServicesGetBootMode(&BootMode);\r | |
259 | ASSERT_EFI_ERROR (Status);\r | |
260 | \r | |
261 | //\r | |
262 | // Don't need to report it on S3 boot.\r | |
263 | //\r | |
264 | if (BootMode == BOOT_ON_S3_RESUME) {\r | |
265 | return EFI_SUCCESS;\r | |
266 | }\r | |
267 | \r | |
268 | PeiPcdDb = GetPcdDatabase();\r | |
269 | if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r | |
270 | //\r | |
271 | // SkuId has been set. Don't need to report it to DXE phase.\r | |
272 | //\r | |
273 | return EFI_SUCCESS;\r | |
274 | }\r | |
275 | \r | |
276 | //\r | |
277 | // Get full PCD database from PcdPeim FileHandle\r | |
278 | //\r | |
279 | Instance = 0;\r | |
280 | FileHandle = NULL;\r | |
281 | while (TRUE) {\r | |
282 | //\r | |
283 | // Traverse all firmware volume instances\r | |
284 | //\r | |
285 | Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r | |
286 | //\r | |
287 | // Error should not happen\r | |
288 | //\r | |
289 | ASSERT_EFI_ERROR (Status);\r | |
290 | \r | |
291 | //\r | |
292 | // Find PcdDb file from the beginning in this firmware volume.\r | |
293 | //\r | |
294 | FileHandle = NULL;\r | |
295 | Status = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r | |
296 | if (!EFI_ERROR (Status)) {\r | |
297 | //\r | |
298 | // Find PcdPeim FileHandle in this volume\r | |
299 | //\r | |
300 | break;\r | |
301 | }\r | |
302 | //\r | |
303 | // We cannot find PcdPeim in this firmware volume, then search the next volume.\r | |
304 | //\r | |
305 | Instance++;\r | |
306 | }\r | |
307 | \r | |
308 | //\r | |
309 | // Find PEI PcdDb and Build second PcdDB GuidHob\r | |
310 | //\r | |
311 | Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r | |
312 | ASSERT_EFI_ERROR (Status);\r | |
313 | Length = PeiPcdDb->LengthForAllSkus;\r | |
314 | Database = BuildGuidHob (&gPcdDataBaseHobGuid, Length);\r | |
315 | CopyMem (Database, PcdDb, Length);\r | |
316 | \r | |
317 | return EFI_SUCCESS;\r | |
318 | }\r | |
319 | \r | |
320 | EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiSignalPpiNotifyList[] = {\r | |
321 | {\r | |
322 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
323 | &gEfiEndOfPeiSignalPpiGuid,\r | |
324 | EndOfPeiSignalPpiNotifyCallback\r | |
325 | }\r | |
326 | };\r | |
327 | \r | |
fc547e08 | 328 | /**\r |
329 | Main entry for PCD PEIM driver.\r | |
330 | \r | |
8a541f0a | 331 | This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.\r |
80408db0 | 332 | \r |
8bd22b8a LG |
333 | @param FileHandle Handle of the file being invoked.\r |
334 | @param PeiServices Describes the list of possible PEI Services.\r | |
80408db0 | 335 | \r |
fc547e08 | 336 | @return Status of install PCD_PPI\r |
337 | \r | |
338 | **/\r | |
80408db0 | 339 | EFI_STATUS\r |
340 | EFIAPI\r | |
341 | PcdPeimInit (\r | |
8bd22b8a LG |
342 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
343 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
80408db0 | 344 | )\r |
345 | {\r | |
a78d3a27 | 346 | EFI_STATUS Status;\r |
96d6d004 | 347 | \r |
a78d3a27 | 348 | BuildPcdDatabase (FileHandle);\r |
80408db0 | 349 | \r |
8a541f0a | 350 | //\r |
17e7fa8f | 351 | // Install PCD_PPI and EFI_PEI_PCD_PPI.\r |
8a541f0a | 352 | //\r |
17e7fa8f | 353 | Status = PeiServicesInstallPpi (&mPpiList[0]);\r |
8a541f0a | 354 | ASSERT_EFI_ERROR (Status);\r |
96d6d004 SZ |
355 | \r |
356 | //\r | |
85d0b97d | 357 | // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.\r |
96d6d004 | 358 | //\r |
85d0b97d SZ |
359 | Status = PeiServicesInstallPpi (&mPpiList2[0]);\r |
360 | ASSERT_EFI_ERROR (Status);\r | |
96d6d004 | 361 | \r |
7c736265 LG |
362 | Status = PeiServicesNotifyPpi (&mEndOfPeiSignalPpiNotifyList[0]);\r |
363 | ASSERT_EFI_ERROR (Status);\r | |
364 | \r | |
219247e1 LG |
365 | Status = PeiRegisterCallBackOnSet (\r |
366 | &gEfiMdeModulePkgTokenSpaceGuid,\r | |
367 | PcdToken(PcdSetNvStoreDefaultId),\r | |
368 | PcdSetNvStoreDefaultIdCallBack\r | |
369 | );\r | |
370 | ASSERT_EFI_ERROR (Status);\r | |
371 | \r | |
8a541f0a | 372 | return Status;\r |
80408db0 | 373 | }\r |
374 | \r | |
96d6d004 SZ |
375 | /**\r |
376 | Retrieve additional information associated with a PCD token in the default token space.\r | |
377 | \r | |
378 | This includes information such as the type of value the TokenNumber is associated with as well as possible\r | |
379 | human readable name that is associated with the token.\r | |
380 | \r | |
381 | @param[in] TokenNumber The PCD token number.\r | |
382 | @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r | |
383 | The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r | |
384 | \r | |
385 | @retval EFI_SUCCESS The PCD information was returned successfully.\r | |
386 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
387 | **/\r | |
388 | EFI_STATUS\r | |
389 | EFIAPI\r | |
390 | PeiGetPcdInfoGetInfo (\r | |
391 | IN UINTN TokenNumber,\r | |
392 | OUT EFI_PCD_INFO *PcdInfo\r | |
393 | )\r | |
394 | {\r | |
395 | return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r | |
396 | }\r | |
397 | \r | |
398 | /**\r | |
399 | Retrieve additional information associated with a PCD token.\r | |
400 | \r | |
401 | This includes information such as the type of value the TokenNumber is associated with as well as possible\r | |
402 | human readable name that is associated with the token.\r | |
403 | \r | |
404 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r | |
405 | @param[in] TokenNumber The PCD token number.\r | |
406 | @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r | |
407 | The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r | |
408 | \r | |
409 | @retval EFI_SUCCESS The PCD information was returned successfully.\r | |
410 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
411 | **/\r | |
412 | EFI_STATUS\r | |
413 | EFIAPI\r | |
414 | PeiGetPcdInfoGetInfoEx (\r | |
415 | IN CONST EFI_GUID *Guid,\r | |
416 | IN UINTN TokenNumber,\r | |
417 | OUT EFI_PCD_INFO *PcdInfo\r | |
418 | )\r | |
419 | {\r | |
420 | return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r | |
421 | }\r | |
422 | \r | |
423 | /**\r | |
424 | Retrieve the currently set SKU Id.\r | |
425 | \r | |
426 | @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r | |
427 | default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r | |
428 | Id is returned.\r | |
429 | **/\r | |
430 | UINTN\r | |
431 | EFIAPI\r | |
432 | PeiGetPcdInfoGetSku (\r | |
433 | VOID\r | |
434 | )\r | |
435 | {\r | |
b6e89910 | 436 | return (UINTN) GetPcdDatabase()->SystemSkuId;\r |
96d6d004 SZ |
437 | }\r |
438 | \r | |
fc547e08 | 439 | /**\r |
440 | Sets the SKU value for subsequent calls to set or get PCD token values.\r | |
441 | \r | |
442 | SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values. \r | |
443 | SetSku() is normally called only once by the system.\r | |
444 | \r | |
445 | For each item (token), the database can hold a single value that applies to all SKUs, \r | |
446 | or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r | |
447 | SKU-specific values are called SKU enabled. \r | |
448 | \r | |
120ca3ce | 449 | The SKU Id of zero is reserved as a default.\r |
fc547e08 | 450 | For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r |
451 | single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r | |
452 | last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r | |
453 | the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been \r | |
454 | set for that Id, the results are unpredictable.\r | |
455 | \r | |
456 | @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and \r | |
457 | set values associated with a PCD token.\r | |
458 | \r | |
fc547e08 | 459 | **/\r |
80408db0 | 460 | VOID\r |
461 | EFIAPI\r | |
462 | PeiPcdSetSku (\r | |
463 | IN UINTN SkuId\r | |
464 | )\r | |
465 | {\r | |
85d0b97d SZ |
466 | PEI_PCD_DATABASE *PeiPcdDb;\r |
467 | SKU_ID *SkuIdTable;\r | |
468 | UINTN Index;\r | |
7c736265 LG |
469 | EFI_STATUS Status;\r |
470 | UINTN Instance;\r | |
471 | EFI_PEI_FV_HANDLE VolumeHandle;\r | |
472 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
473 | VOID *PcdDb;\r | |
474 | UINT32 Length;\r | |
475 | PCD_DATABASE_SKU_DELTA *SkuDelta;\r | |
476 | PCD_DATA_DELTA *SkuDeltaData;\r | |
85d0b97d | 477 | \r |
f71503c3 LG |
478 | DEBUG ((DEBUG_INFO, "PcdPei - SkuId 0x%lx is to be set.\n", (SKU_ID) SkuId));\r |
479 | \r | |
85d0b97d | 480 | PeiPcdDb = GetPcdDatabase();\r |
2db48a1f SZ |
481 | \r |
482 | if (SkuId == PeiPcdDb->SystemSkuId) {\r | |
483 | //\r | |
484 | // The input SKU Id is equal to current SKU Id, return directly.\r | |
485 | //\r | |
f71503c3 | 486 | DEBUG ((DEBUG_INFO, "PcdPei - SkuId is same to current system Sku.\n"));\r |
2db48a1f SZ |
487 | return;\r |
488 | }\r | |
489 | \r | |
490 | if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r | |
491 | DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r | |
492 | DEBUG ((\r | |
493 | DEBUG_ERROR,\r | |
494 | "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r | |
495 | PeiPcdDb->SystemSkuId,\r | |
496 | (SKU_ID) SkuId\r | |
497 | ));\r | |
498 | ASSERT (FALSE);\r | |
499 | return;\r | |
500 | }\r | |
501 | \r | |
85d0b97d SZ |
502 | SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r |
503 | for (Index = 0; Index < SkuIdTable[0]; Index++) {\r | |
504 | if (SkuId == SkuIdTable[Index + 1]) {\r | |
f71503c3 | 505 | DEBUG ((DEBUG_INFO, "PcdPei - SkuId is found in SkuId table.\n"));\r |
7c736265 LG |
506 | break;\r |
507 | }\r | |
508 | }\r | |
509 | \r | |
510 | if (Index < SkuIdTable[0]) {\r | |
511 | //\r | |
512 | // Get full PCD database from PcdPeim FileHandle\r | |
513 | //\r | |
514 | Instance = 0;\r | |
515 | FileHandle = NULL;\r | |
516 | while (TRUE) {\r | |
517 | //\r | |
518 | // Traverse all firmware volume instances\r | |
519 | //\r | |
520 | Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r | |
521 | //\r | |
522 | // Error should not happen\r | |
523 | //\r | |
524 | ASSERT_EFI_ERROR (Status);\r | |
525 | \r | |
526 | //\r | |
527 | // Find PcdDb file from the beginning in this firmware volume.\r | |
528 | //\r | |
529 | FileHandle = NULL;\r | |
530 | Status = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r | |
531 | if (!EFI_ERROR (Status)) {\r | |
532 | //\r | |
533 | // Find PcdPeim FileHandle in this volume\r | |
534 | //\r | |
535 | break;\r | |
536 | }\r | |
537 | //\r | |
538 | // We cannot find PcdPeim in this firmware volume, then search the next volume.\r | |
539 | //\r | |
540 | Instance++;\r | |
541 | }\r | |
542 | \r | |
543 | //\r | |
544 | // Find the delta data between the different Skus\r | |
545 | //\r | |
546 | Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r | |
547 | ASSERT_EFI_ERROR (Status);\r | |
548 | Length = PeiPcdDb->LengthForAllSkus;\r | |
549 | Index = (PeiPcdDb->Length + 7) & (~7);\r | |
550 | SkuDelta = NULL;\r | |
551 | while (Index < Length) {\r | |
552 | SkuDelta = (PCD_DATABASE_SKU_DELTA *) ((UINT8 *) PcdDb + Index);\r | |
553 | if (SkuDelta->SkuId == SkuId && SkuDelta->SkuIdCompared == 0) {\r | |
554 | break;\r | |
555 | }\r | |
556 | Index = (Index + SkuDelta->Length + 7) & (~7);\r | |
557 | }\r | |
558 | \r | |
559 | //\r | |
560 | // Patch the delta data into current PCD database\r | |
561 | //\r | |
562 | if (Index < Length && SkuDelta != NULL) {\r | |
563 | SkuDeltaData = (PCD_DATA_DELTA *) (SkuDelta + 1);\r | |
564 | while ((UINT8 *) SkuDeltaData < (UINT8 *) SkuDelta + SkuDelta->Length) {\r | |
565 | *((UINT8 *) PeiPcdDb + SkuDeltaData->Offset) = (UINT8) SkuDeltaData->Value;\r | |
566 | SkuDeltaData ++;\r | |
567 | }\r | |
85d0b97d | 568 | PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r |
7c736265 | 569 | DEBUG ((DEBUG_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r |
85d0b97d SZ |
570 | return;\r |
571 | }\r | |
572 | }\r | |
80408db0 | 573 | \r |
85d0b97d | 574 | //\r |
2db48a1f | 575 | // Invalid input SkuId, the default SKU Id will be still used for the system.\r |
85d0b97d | 576 | //\r |
f71503c3 | 577 | DEBUG ((DEBUG_ERROR, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r |
7c736265 | 578 | \r |
80408db0 | 579 | return;\r |
580 | }\r | |
581 | \r | |
fc547e08 | 582 | /**\r |
583 | Retrieves an 8-bit value for a given PCD token.\r | |
80408db0 | 584 | \r |
fc547e08 | 585 | Retrieves the current byte-sized value for a PCD token number. \r |
586 | If the TokenNumber is invalid, the results are unpredictable.\r | |
587 | \r | |
588 | @param[in] TokenNumber The PCD token number. \r | |
80408db0 | 589 | \r |
fc547e08 | 590 | @return The UINT8 value.\r |
591 | \r | |
592 | **/\r | |
80408db0 | 593 | UINT8\r |
594 | EFIAPI\r | |
595 | PeiPcdGet8 (\r | |
596 | IN UINTN TokenNumber\r | |
597 | )\r | |
598 | {\r | |
599 | return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r | |
600 | }\r | |
601 | \r | |
fc547e08 | 602 | /**\r |
603 | Retrieves an 16-bit value for a given PCD token.\r | |
80408db0 | 604 | \r |
fc547e08 | 605 | Retrieves the current 16-bits value for a PCD token number. \r |
606 | If the TokenNumber is invalid, the results are unpredictable.\r | |
607 | \r | |
608 | @param[in] TokenNumber The PCD token number. \r | |
80408db0 | 609 | \r |
fc547e08 | 610 | @return The UINT16 value.\r |
611 | \r | |
612 | **/\r | |
80408db0 | 613 | UINT16\r |
614 | EFIAPI\r | |
615 | PeiPcdGet16 (\r | |
616 | IN UINTN TokenNumber\r | |
617 | )\r | |
618 | {\r | |
619 | return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r | |
620 | }\r | |
621 | \r | |
fc547e08 | 622 | /**\r |
623 | Retrieves an 32-bit value for a given PCD token.\r | |
80408db0 | 624 | \r |
fc547e08 | 625 | Retrieves the current 32-bits value for a PCD token number. \r |
626 | If the TokenNumber is invalid, the results are unpredictable.\r | |
627 | \r | |
628 | @param[in] TokenNumber The PCD token number. \r | |
80408db0 | 629 | \r |
fc547e08 | 630 | @return The UINT32 value.\r |
631 | \r | |
632 | **/\r | |
80408db0 | 633 | UINT32\r |
634 | EFIAPI\r | |
635 | PeiPcdGet32 (\r | |
636 | IN UINTN TokenNumber\r | |
637 | )\r | |
638 | {\r | |
639 | return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r | |
640 | }\r | |
641 | \r | |
fc547e08 | 642 | /**\r |
643 | Retrieves an 64-bit value for a given PCD token.\r | |
80408db0 | 644 | \r |
fc547e08 | 645 | Retrieves the current 64-bits value for a PCD token number. \r |
646 | If the TokenNumber is invalid, the results are unpredictable.\r | |
647 | \r | |
648 | @param[in] TokenNumber The PCD token number. \r | |
80408db0 | 649 | \r |
fc547e08 | 650 | @return The UINT64 value.\r |
651 | \r | |
652 | **/\r | |
80408db0 | 653 | UINT64\r |
654 | EFIAPI\r | |
655 | PeiPcdGet64 (\r | |
656 | IN UINTN TokenNumber\r | |
657 | )\r | |
658 | {\r | |
659 | return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r | |
660 | }\r | |
661 | \r | |
fc547e08 | 662 | /**\r |
663 | Retrieves a pointer to a value for a given PCD token.\r | |
664 | \r | |
665 | Retrieves the current pointer to the buffer for a PCD token number. \r | |
666 | Do not make any assumptions about the alignment of the pointer that \r | |
667 | is returned by this function call. If the TokenNumber is invalid, \r | |
668 | the results are unpredictable.\r | |
80408db0 | 669 | \r |
fc547e08 | 670 | @param[in] TokenNumber The PCD token number. \r |
80408db0 | 671 | \r |
3fd8027e | 672 | @return The pointer to the buffer to be retrieved.\r |
fc547e08 | 673 | \r |
674 | **/\r | |
80408db0 | 675 | VOID *\r |
676 | EFIAPI\r | |
677 | PeiPcdGetPtr (\r | |
678 | IN UINTN TokenNumber\r | |
679 | )\r | |
680 | {\r | |
681 | return GetWorker (TokenNumber, 0);\r | |
682 | }\r | |
683 | \r | |
fc547e08 | 684 | /**\r |
685 | Retrieves a Boolean value for a given PCD token.\r | |
80408db0 | 686 | \r |
fc547e08 | 687 | Retrieves the current boolean value for a PCD token number. \r |
688 | Do not make any assumptions about the alignment of the pointer that \r | |
689 | is returned by this function call. If the TokenNumber is invalid, \r | |
690 | the results are unpredictable.\r | |
80408db0 | 691 | \r |
fc547e08 | 692 | @param[in] TokenNumber The PCD token number. \r |
693 | \r | |
694 | @return The Boolean value.\r | |
695 | \r | |
696 | **/\r | |
80408db0 | 697 | BOOLEAN\r |
698 | EFIAPI\r | |
699 | PeiPcdGetBool (\r | |
700 | IN UINTN TokenNumber\r | |
701 | )\r | |
702 | {\r | |
703 | return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r | |
704 | }\r | |
705 | \r | |
fc547e08 | 706 | /**\r |
707 | Retrieves the size of the value for a given PCD token.\r | |
708 | \r | |
709 | Retrieves the current size of a particular PCD token. \r | |
710 | If the TokenNumber is invalid, the results are unpredictable.\r | |
80408db0 | 711 | \r |
fc547e08 | 712 | @param[in] TokenNumber The PCD token number. \r |
80408db0 | 713 | \r |
fc547e08 | 714 | @return The size of the value for the PCD token.\r |
715 | \r | |
716 | **/\r | |
80408db0 | 717 | UINTN\r |
718 | EFIAPI\r | |
719 | PeiPcdGetSize (\r | |
720 | IN UINTN TokenNumber\r | |
721 | )\r | |
722 | {\r | |
723 | PEI_PCD_DATABASE *PeiPcdDb;\r | |
724 | UINTN Size;\r | |
725 | UINTN MaxSize;\r | |
419db80b | 726 | UINT32 LocalTokenCount;\r |
80408db0 | 727 | \r |
419db80b BF |
728 | PeiPcdDb = GetPcdDatabase ();\r |
729 | LocalTokenCount = PeiPcdDb->LocalTokenCount;\r | |
80408db0 | 730 | //\r |
731 | // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r | |
732 | // We have to decrement TokenNumber by 1 to make it usable\r | |
733 | // as the array index.\r | |
734 | //\r | |
735 | TokenNumber--;\r | |
736 | \r | |
737 | // EBC compiler is very choosy. It may report warning about comparison\r | |
738 | // between UINTN and 0 . So we add 1 in each size of the \r | |
739 | // comparison.\r | |
419db80b | 740 | ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));\r |
80408db0 | 741 | \r |
419db80b | 742 | Size = (*((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber) & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r |
80408db0 | 743 | \r |
744 | if (Size == 0) {\r | |
745 | //\r | |
746 | // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r | |
747 | //\r | |
748 | return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);\r | |
749 | } else {\r | |
750 | return Size;\r | |
751 | }\r | |
752 | \r | |
753 | }\r | |
754 | \r | |
fc547e08 | 755 | /**\r |
756 | Retrieves an 8-bit value for a given PCD token.\r | |
80408db0 | 757 | \r |
fc547e08 | 758 | Retrieves the 8-bit value of a particular PCD token. \r |
759 | If the TokenNumber is invalid or the token space\r | |
760 | specified by Guid does not exist, the results are \r | |
761 | unpredictable.\r | |
80408db0 | 762 | \r |
fc547e08 | 763 | @param[in] Guid The token space for the token number.\r |
764 | @param[in] ExTokenNumber The PCD token number. \r | |
765 | \r | |
766 | @return The size 8-bit value for the PCD token.\r | |
767 | \r | |
768 | **/\r | |
80408db0 | 769 | UINT8\r |
770 | EFIAPI\r | |
771 | PeiPcdGet8Ex (\r | |
772 | IN CONST EFI_GUID *Guid,\r | |
773 | IN UINTN ExTokenNumber\r | |
774 | )\r | |
775 | {\r | |
776 | return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r | |
777 | }\r | |
778 | \r | |
fc547e08 | 779 | /**\r |
780 | Retrieves an 16-bit value for a given PCD token.\r | |
80408db0 | 781 | \r |
fc547e08 | 782 | Retrieves the 16-bit value of a particular PCD token. \r |
783 | If the TokenNumber is invalid or the token space\r | |
784 | specified by Guid does not exist, the results are \r | |
785 | unpredictable.\r | |
80408db0 | 786 | \r |
fc547e08 | 787 | @param[in] Guid The token space for the token number.\r |
788 | @param[in] ExTokenNumber The PCD token number. \r | |
789 | \r | |
790 | @return The size 16-bit value for the PCD token.\r | |
791 | \r | |
792 | **/\r | |
80408db0 | 793 | UINT16\r |
794 | EFIAPI\r | |
795 | PeiPcdGet16Ex (\r | |
796 | IN CONST EFI_GUID *Guid,\r | |
797 | IN UINTN ExTokenNumber\r | |
798 | )\r | |
799 | {\r | |
800 | return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r | |
801 | }\r | |
802 | \r | |
fc547e08 | 803 | /**\r |
804 | Retrieves an 32-bit value for a given PCD token.\r | |
805 | \r | |
806 | Retrieves the 32-bit value of a particular PCD token. \r | |
807 | If the TokenNumber is invalid or the token space\r | |
808 | specified by Guid does not exist, the results are \r | |
809 | unpredictable.\r | |
80408db0 | 810 | \r |
fc547e08 | 811 | @param[in] Guid The token space for the token number.\r |
812 | @param[in] ExTokenNumber The PCD token number. \r | |
80408db0 | 813 | \r |
fc547e08 | 814 | @return The size 32-bit value for the PCD token.\r |
815 | \r | |
816 | **/\r | |
80408db0 | 817 | UINT32\r |
818 | EFIAPI\r | |
819 | PeiPcdGet32Ex (\r | |
820 | IN CONST EFI_GUID *Guid,\r | |
821 | IN UINTN ExTokenNumber\r | |
822 | )\r | |
823 | {\r | |
824 | return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r | |
825 | }\r | |
826 | \r | |
fc547e08 | 827 | /**\r |
828 | Retrieves an 64-bit value for a given PCD token.\r | |
829 | \r | |
830 | Retrieves the 64-bit value of a particular PCD token. \r | |
831 | If the TokenNumber is invalid or the token space\r | |
832 | specified by Guid does not exist, the results are \r | |
833 | unpredictable.\r | |
80408db0 | 834 | \r |
fc547e08 | 835 | @param[in] Guid The token space for the token number.\r |
836 | @param[in] ExTokenNumber The PCD token number. \r | |
80408db0 | 837 | \r |
fc547e08 | 838 | @return The size 64-bit value for the PCD token.\r |
839 | \r | |
840 | **/\r | |
80408db0 | 841 | UINT64\r |
842 | EFIAPI\r | |
843 | PeiPcdGet64Ex (\r | |
844 | IN CONST EFI_GUID *Guid,\r | |
845 | IN UINTN ExTokenNumber\r | |
846 | )\r | |
847 | {\r | |
848 | return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r | |
849 | }\r | |
850 | \r | |
fc547e08 | 851 | /**\r |
852 | Retrieves a pointer to a value for a given PCD token.\r | |
80408db0 | 853 | \r |
fc547e08 | 854 | Retrieves the current pointer to the buffer for a PCD token number. \r |
855 | Do not make any assumptions about the alignment of the pointer that \r | |
856 | is returned by this function call. If the TokenNumber is invalid, \r | |
857 | the results are unpredictable.\r | |
80408db0 | 858 | \r |
fc547e08 | 859 | @param[in] Guid The token space for the token number.\r |
860 | @param[in] ExTokenNumber The PCD token number. \r | |
861 | \r | |
3fd8027e | 862 | @return The pointer to the buffer to be retrieved.\r |
fc547e08 | 863 | \r |
864 | **/\r | |
80408db0 | 865 | VOID *\r |
866 | EFIAPI\r | |
867 | PeiPcdGetPtrEx (\r | |
868 | IN CONST EFI_GUID *Guid,\r | |
869 | IN UINTN ExTokenNumber\r | |
870 | )\r | |
871 | {\r | |
872 | return ExGetWorker (Guid, ExTokenNumber, 0);\r | |
873 | }\r | |
874 | \r | |
fc547e08 | 875 | /**\r |
876 | Retrieves an Boolean value for a given PCD token.\r | |
877 | \r | |
878 | Retrieves the Boolean value of a particular PCD token. \r | |
879 | If the TokenNumber is invalid or the token space\r | |
880 | specified by Guid does not exist, the results are \r | |
881 | unpredictable.\r | |
80408db0 | 882 | \r |
fc547e08 | 883 | @param[in] Guid The token space for the token number.\r |
884 | @param[in] ExTokenNumber The PCD token number. \r | |
80408db0 | 885 | \r |
fc547e08 | 886 | @return The size Boolean value for the PCD token.\r |
887 | \r | |
888 | **/\r | |
80408db0 | 889 | BOOLEAN\r |
890 | EFIAPI\r | |
891 | PeiPcdGetBoolEx (\r | |
892 | IN CONST EFI_GUID *Guid,\r | |
893 | IN UINTN ExTokenNumber\r | |
894 | )\r | |
895 | {\r | |
896 | return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r | |
897 | }\r | |
898 | \r | |
fc547e08 | 899 | /**\r |
900 | Retrieves the size of the value for a given PCD token.\r | |
901 | \r | |
902 | Retrieves the current size of a particular PCD token. \r | |
903 | If the TokenNumber is invalid, the results are unpredictable.\r | |
80408db0 | 904 | \r |
fc547e08 | 905 | @param[in] Guid The token space for the token number.\r |
906 | @param[in] ExTokenNumber The PCD token number. \r | |
80408db0 | 907 | \r |
fc547e08 | 908 | @return The size of the value for the PCD token.\r |
909 | \r | |
910 | **/\r | |
80408db0 | 911 | UINTN\r |
912 | EFIAPI\r | |
913 | PeiPcdGetSizeEx (\r | |
914 | IN CONST EFI_GUID *Guid,\r | |
915 | IN UINTN ExTokenNumber\r | |
916 | )\r | |
917 | {\r | |
80408db0 | 918 | return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r |
919 | }\r | |
920 | \r | |
fc547e08 | 921 | /**\r |
922 | Sets an 8-bit value for a given PCD token.\r | |
80408db0 | 923 | \r |
fc547e08 | 924 | When the PCD service sets a value, it will check to ensure that the \r |
925 | size of the value being set is compatible with the Token's existing definition. \r | |
926 | If it is not, an error will be returned.\r | |
80408db0 | 927 | \r |
fc547e08 | 928 | @param[in] TokenNumber The PCD token number. \r |
929 | @param[in] Value The value to set for the PCD token.\r | |
930 | \r | |
931 | @retval EFI_SUCCESS Procedure returned successfully.\r | |
932 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
933 | being set was incompatible with a call to this function. \r | |
934 | Use GetSize() to retrieve the size of the target data.\r | |
935 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
936 | \r | |
937 | **/\r | |
80408db0 | 938 | EFI_STATUS\r |
939 | EFIAPI\r | |
940 | PeiPcdSet8 (\r | |
941 | IN UINTN TokenNumber,\r | |
942 | IN UINT8 Value\r | |
943 | )\r | |
944 | {\r | |
945 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r | |
946 | }\r | |
947 | \r | |
fc547e08 | 948 | /**\r |
949 | Sets an 16-bit value for a given PCD token.\r | |
950 | \r | |
951 | When the PCD service sets a value, it will check to ensure that the \r | |
952 | size of the value being set is compatible with the Token's existing definition. \r | |
953 | If it is not, an error will be returned.\r | |
80408db0 | 954 | \r |
fc547e08 | 955 | @param[in] TokenNumber The PCD token number. \r |
956 | @param[in] Value The value to set for the PCD token.\r | |
80408db0 | 957 | \r |
fc547e08 | 958 | @retval EFI_SUCCESS Procedure returned successfully.\r |
959 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
960 | being set was incompatible with a call to this function. \r | |
961 | Use GetSize() to retrieve the size of the target data.\r | |
962 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
963 | \r | |
964 | **/\r | |
80408db0 | 965 | EFI_STATUS\r |
966 | EFIAPI\r | |
967 | PeiPcdSet16 (\r | |
968 | IN UINTN TokenNumber,\r | |
969 | IN UINT16 Value\r | |
970 | )\r | |
971 | {\r | |
972 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r | |
973 | }\r | |
974 | \r | |
fc547e08 | 975 | /**\r |
976 | Sets an 32-bit value for a given PCD token.\r | |
80408db0 | 977 | \r |
fc547e08 | 978 | When the PCD service sets a value, it will check to ensure that the \r |
979 | size of the value being set is compatible with the Token's existing definition. \r | |
980 | If it is not, an error will be returned.\r | |
80408db0 | 981 | \r |
fc547e08 | 982 | @param[in] TokenNumber The PCD token number. \r |
983 | @param[in] Value The value to set for the PCD token.\r | |
984 | \r | |
985 | @retval EFI_SUCCESS Procedure returned successfully.\r | |
986 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
987 | being set was incompatible with a call to this function. \r | |
988 | Use GetSize() to retrieve the size of the target data.\r | |
989 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
990 | \r | |
991 | **/\r | |
80408db0 | 992 | EFI_STATUS\r |
993 | EFIAPI\r | |
994 | PeiPcdSet32 (\r | |
995 | IN UINTN TokenNumber,\r | |
996 | IN UINT32 Value\r | |
997 | )\r | |
998 | {\r | |
999 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r | |
1000 | }\r | |
1001 | \r | |
fc547e08 | 1002 | /**\r |
1003 | Sets an 64-bit value for a given PCD token.\r | |
1004 | \r | |
1005 | When the PCD service sets a value, it will check to ensure that the \r | |
1006 | size of the value being set is compatible with the Token's existing definition. \r | |
1007 | If it is not, an error will be returned.\r | |
80408db0 | 1008 | \r |
fc547e08 | 1009 | @param[in] TokenNumber The PCD token number. \r |
1010 | @param[in] Value The value to set for the PCD token.\r | |
80408db0 | 1011 | \r |
fc547e08 | 1012 | @retval EFI_SUCCESS Procedure returned successfully.\r |
1013 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1014 | being set was incompatible with a call to this function. \r | |
1015 | Use GetSize() to retrieve the size of the target data.\r | |
1016 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1017 | \r | |
1018 | **/\r | |
80408db0 | 1019 | EFI_STATUS\r |
1020 | EFIAPI\r | |
1021 | PeiPcdSet64 (\r | |
1022 | IN UINTN TokenNumber,\r | |
1023 | IN UINT64 Value\r | |
1024 | )\r | |
1025 | {\r | |
1026 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r | |
1027 | }\r | |
1028 | \r | |
fc547e08 | 1029 | /**\r |
1030 | Sets a value of a specified size for a given PCD token.\r | |
1031 | \r | |
1032 | When the PCD service sets a value, it will check to ensure that the \r | |
1033 | size of the value being set is compatible with the Token's existing definition. \r | |
1034 | If it is not, an error will be returned.\r | |
1035 | \r | |
1036 | @param[in] TokenNumber The PCD token number. \r | |
1037 | @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r | |
1038 | On input, if the SizeOfValue is greater than the maximum size supported \r | |
1039 | for this TokenNumber then the output value of SizeOfValue will reflect \r | |
1040 | the maximum size supported for this TokenNumber.\r | |
1041 | @param[in] Buffer The buffer to set for the PCD token.\r | |
1042 | \r | |
1043 | @retval EFI_SUCCESS Procedure returned successfully.\r | |
1044 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1045 | being set was incompatible with a call to this function. \r | |
1046 | Use GetSize() to retrieve the size of the target data.\r | |
1047 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1048 | \r | |
1049 | **/\r | |
80408db0 | 1050 | EFI_STATUS\r |
1051 | EFIAPI\r | |
1052 | PeiPcdSetPtr (\r | |
1053 | IN UINTN TokenNumber,\r | |
1054 | IN OUT UINTN *SizeOfBuffer,\r | |
1055 | IN VOID *Buffer\r | |
1056 | )\r | |
1057 | {\r | |
1058 | return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r | |
1059 | }\r | |
1060 | \r | |
fc547e08 | 1061 | /**\r |
1062 | Sets an Boolean value for a given PCD token.\r | |
80408db0 | 1063 | \r |
fc547e08 | 1064 | When the PCD service sets a value, it will check to ensure that the \r |
1065 | size of the value being set is compatible with the Token's existing definition. \r | |
1066 | If it is not, an error will be returned.\r | |
80408db0 | 1067 | \r |
fc547e08 | 1068 | @param[in] TokenNumber The PCD token number. \r |
1069 | @param[in] Value The value to set for the PCD token.\r | |
1070 | \r | |
1071 | @retval EFI_SUCCESS Procedure returned successfully.\r | |
1072 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1073 | being set was incompatible with a call to this function. \r | |
1074 | Use GetSize() to retrieve the size of the target data.\r | |
1075 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1076 | \r | |
1077 | **/\r | |
80408db0 | 1078 | EFI_STATUS\r |
1079 | EFIAPI\r | |
1080 | PeiPcdSetBool (\r | |
1081 | IN UINTN TokenNumber,\r | |
1082 | IN BOOLEAN Value\r | |
1083 | )\r | |
1084 | {\r | |
1085 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r | |
1086 | }\r | |
1087 | \r | |
fc547e08 | 1088 | /**\r |
1089 | Sets an 8-bit value for a given PCD token.\r | |
80408db0 | 1090 | \r |
fc547e08 | 1091 | When the PCD service sets a value, it will check to ensure that the \r |
1092 | size of the value being set is compatible with the Token's existing definition. \r | |
1093 | If it is not, an error will be returned.\r | |
80408db0 | 1094 | \r |
fc547e08 | 1095 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
1096 | @param[in] ExTokenNumber The PCD token number. \r | |
1097 | @param[in] Value The value to set for the PCD token.\r | |
1098 | \r | |
1099 | @retval EFI_SUCCESS Procedure returned successfully.\r | |
1100 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1101 | being set was incompatible with a call to this function. \r | |
1102 | Use GetSize() to retrieve the size of the target data.\r | |
1103 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1104 | \r | |
1105 | **/\r | |
80408db0 | 1106 | EFI_STATUS\r |
1107 | EFIAPI\r | |
1108 | PeiPcdSet8Ex (\r | |
1109 | IN CONST EFI_GUID *Guid,\r | |
1110 | IN UINTN ExTokenNumber,\r | |
1111 | IN UINT8 Value\r | |
1112 | )\r | |
1113 | {\r | |
1114 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r | |
1115 | }\r | |
1116 | \r | |
fc547e08 | 1117 | /**\r |
1118 | Sets an 16-bit value for a given PCD token.\r | |
1119 | \r | |
1120 | When the PCD service sets a value, it will check to ensure that the \r | |
1121 | size of the value being set is compatible with the Token's existing definition. \r | |
1122 | If it is not, an error will be returned.\r | |
80408db0 | 1123 | \r |
fc547e08 | 1124 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
1125 | @param[in] ExTokenNumber The PCD token number. \r | |
1126 | @param[in] Value The value to set for the PCD token.\r | |
80408db0 | 1127 | \r |
fc547e08 | 1128 | @retval EFI_SUCCESS Procedure returned successfully.\r |
1129 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1130 | being set was incompatible with a call to this function. \r | |
1131 | Use GetSize() to retrieve the size of the target data.\r | |
1132 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1133 | \r | |
1134 | **/\r | |
80408db0 | 1135 | EFI_STATUS\r |
1136 | EFIAPI\r | |
1137 | PeiPcdSet16Ex (\r | |
1138 | IN CONST EFI_GUID *Guid,\r | |
1139 | IN UINTN ExTokenNumber,\r | |
1140 | IN UINT16 Value\r | |
1141 | )\r | |
1142 | {\r | |
1143 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r | |
1144 | }\r | |
1145 | \r | |
fc547e08 | 1146 | /**\r |
1147 | Sets an 32-bit value for a given PCD token.\r | |
1148 | \r | |
1149 | When the PCD service sets a value, it will check to ensure that the \r | |
1150 | size of the value being set is compatible with the Token's existing definition. \r | |
1151 | If it is not, an error will be returned.\r | |
80408db0 | 1152 | \r |
fc547e08 | 1153 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
1154 | @param[in] ExTokenNumber The PCD token number. \r | |
1155 | @param[in] Value The value to set for the PCD token.\r | |
80408db0 | 1156 | \r |
fc547e08 | 1157 | @retval EFI_SUCCESS Procedure returned successfully.\r |
1158 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1159 | being set was incompatible with a call to this function. \r | |
1160 | Use GetSize() to retrieve the size of the target data.\r | |
1161 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1162 | \r | |
1163 | **/\r | |
80408db0 | 1164 | EFI_STATUS\r |
1165 | EFIAPI\r | |
1166 | PeiPcdSet32Ex (\r | |
1167 | IN CONST EFI_GUID *Guid,\r | |
1168 | IN UINTN ExTokenNumber,\r | |
1169 | IN UINT32 Value\r | |
1170 | )\r | |
1171 | {\r | |
1172 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r | |
1173 | }\r | |
1174 | \r | |
fc547e08 | 1175 | /**\r |
1176 | Sets an 64-bit value for a given PCD token.\r | |
80408db0 | 1177 | \r |
fc547e08 | 1178 | When the PCD service sets a value, it will check to ensure that the \r |
1179 | size of the value being set is compatible with the Token's existing definition. \r | |
1180 | If it is not, an error will be returned.\r | |
80408db0 | 1181 | \r |
fc547e08 | 1182 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
1183 | @param[in] ExTokenNumber The PCD token number. \r | |
1184 | @param[in] Value The value to set for the PCD token.\r | |
1185 | \r | |
1186 | @retval EFI_SUCCESS Procedure returned successfully.\r | |
1187 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1188 | being set was incompatible with a call to this function. \r | |
1189 | Use GetSize() to retrieve the size of the target data.\r | |
1190 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1191 | \r | |
1192 | **/\r | |
80408db0 | 1193 | EFI_STATUS\r |
1194 | EFIAPI\r | |
1195 | PeiPcdSet64Ex (\r | |
1196 | IN CONST EFI_GUID *Guid,\r | |
1197 | IN UINTN ExTokenNumber,\r | |
1198 | IN UINT64 Value\r | |
1199 | )\r | |
1200 | {\r | |
1201 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r | |
1202 | }\r | |
1203 | \r | |
fc547e08 | 1204 | /**\r |
1205 | Sets a value of a specified size for a given PCD token.\r | |
1206 | \r | |
1207 | When the PCD service sets a value, it will check to ensure that the \r | |
1208 | size of the value being set is compatible with the Token's existing definition. \r | |
1209 | If it is not, an error will be returned.\r | |
1210 | \r | |
1211 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r | |
1212 | @param[in] ExTokenNumber The PCD token number. \r | |
1213 | @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r | |
1214 | On input, if the SizeOfValue is greater than the maximum size supported \r | |
1215 | for this TokenNumber then the output value of SizeOfValue will reflect \r | |
1216 | the maximum size supported for this TokenNumber.\r | |
1217 | @param[in] Value The buffer to set for the PCD token.\r | |
1218 | \r | |
1219 | @retval EFI_SUCCESS Procedure returned successfully.\r | |
1220 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1221 | being set was incompatible with a call to this function. \r | |
1222 | Use GetSize() to retrieve the size of the target data.\r | |
1223 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1224 | \r | |
1225 | **/\r | |
80408db0 | 1226 | EFI_STATUS\r |
1227 | EFIAPI\r | |
1228 | PeiPcdSetPtrEx (\r | |
fc547e08 | 1229 | IN CONST EFI_GUID *Guid,\r |
1230 | IN UINTN ExTokenNumber,\r | |
1231 | IN OUT UINTN *SizeOfBuffer,\r | |
1232 | IN VOID *Value\r | |
80408db0 | 1233 | )\r |
1234 | {\r | |
1235 | return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r | |
1236 | }\r | |
1237 | \r | |
fc547e08 | 1238 | /**\r |
1239 | Sets an Boolean value for a given PCD token.\r | |
1240 | \r | |
1241 | When the PCD service sets a value, it will check to ensure that the \r | |
1242 | size of the value being set is compatible with the Token's existing definition. \r | |
1243 | If it is not, an error will be returned.\r | |
80408db0 | 1244 | \r |
fc547e08 | 1245 | @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
1246 | @param [in] ExTokenNumber The PCD token number. \r | |
1247 | @param [in] Value The value to set for the PCD token.\r | |
80408db0 | 1248 | \r |
fc547e08 | 1249 | @retval EFI_SUCCESS Procedure returned successfully.\r |
1250 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r | |
1251 | being set was incompatible with a call to this function. \r | |
1252 | Use GetSize() to retrieve the size of the target data.\r | |
1253 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r | |
1254 | \r | |
1255 | **/\r | |
80408db0 | 1256 | EFI_STATUS\r |
1257 | EFIAPI\r | |
1258 | PeiPcdSetBoolEx (\r | |
1259 | IN CONST EFI_GUID *Guid,\r | |
1260 | IN UINTN ExTokenNumber,\r | |
1261 | IN BOOLEAN Value\r | |
1262 | )\r | |
1263 | {\r | |
1264 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r | |
1265 | }\r | |
1266 | \r | |
fc547e08 | 1267 | /**\r |
1268 | Specifies a function to be called anytime the value of a designated token is changed.\r | |
80408db0 | 1269 | \r |
fc547e08 | 1270 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
1271 | @param[in] ExTokenNumber The PCD token number. \r | |
1272 | @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r | |
80408db0 | 1273 | \r |
fc547e08 | 1274 | @retval EFI_SUCCESS The PCD service has successfully established a call event \r |
1275 | for the CallBackToken requested.\r | |
1276 | @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r | |
80408db0 | 1277 | \r |
fc547e08 | 1278 | **/\r |
80408db0 | 1279 | EFI_STATUS\r |
1280 | EFIAPI\r | |
1281 | PeiRegisterCallBackOnSet (\r | |
1282 | IN CONST EFI_GUID *Guid, OPTIONAL\r | |
1283 | IN UINTN ExTokenNumber,\r | |
1284 | IN PCD_PPI_CALLBACK CallBackFunction\r | |
1285 | )\r | |
1286 | {\r | |
f806dd27 | 1287 | if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r |
80408db0 | 1288 | return EFI_UNSUPPORTED;\r |
1289 | }\r | |
1290 | \r | |
e4a3922f | 1291 | if (CallBackFunction == NULL) {\r |
1292 | return EFI_INVALID_PARAMETER;\r | |
1293 | }\r | |
1294 | \r | |
80408db0 | 1295 | return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r |
1296 | }\r | |
1297 | \r | |
fc547e08 | 1298 | /**\r |
1299 | Cancels a previously set callback function for a particular PCD token number.\r | |
80408db0 | 1300 | \r |
fc547e08 | 1301 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
1302 | @param[in] ExTokenNumber The PCD token number. \r | |
1303 | @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r | |
80408db0 | 1304 | \r |
fc547e08 | 1305 | @retval EFI_SUCCESS The PCD service has successfully established a call event \r |
1306 | for the CallBackToken requested.\r | |
1307 | @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r | |
1308 | \r | |
1309 | **/\r | |
80408db0 | 1310 | EFI_STATUS\r |
1311 | EFIAPI\r | |
1312 | PcdUnRegisterCallBackOnSet (\r | |
1313 | IN CONST EFI_GUID *Guid, OPTIONAL\r | |
1314 | IN UINTN ExTokenNumber,\r | |
1315 | IN PCD_PPI_CALLBACK CallBackFunction\r | |
1316 | )\r | |
1317 | {\r | |
f806dd27 | 1318 | if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r |
80408db0 | 1319 | return EFI_UNSUPPORTED;\r |
1320 | }\r | |
1321 | \r | |
e4a3922f | 1322 | if (CallBackFunction == NULL) {\r |
1323 | return EFI_INVALID_PARAMETER;\r | |
1324 | }\r | |
1325 | \r | |
80408db0 | 1326 | return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r |
1327 | }\r | |
1328 | \r | |
fc547e08 | 1329 | /**\r |
90e06556 | 1330 | Retrieves the next valid token number in a given namespace. \r |
1331 | \r | |
1332 | This is useful since the PCD infrastructure contains a sparse list of token numbers, \r | |
1333 | and one cannot a priori know what token numbers are valid in the database. \r | |
1334 | \r | |
1335 | If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned. \r | |
1336 | If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned. \r | |
1337 | If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned. \r | |
1338 | If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned. \r | |
1339 | The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid. \r | |
1340 | If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned. \r | |
1341 | If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned. \r | |
1342 | If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r | |
1343 | \r | |
1344 | \r | |
1345 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value. \r | |
1346 | This is an optional parameter that may be NULL. If this parameter is NULL, then a request \r | |
1347 | is being made to retrieve tokens from the default token space.\r | |
1348 | @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.\r | |
1349 | \r | |
419db80b BF |
1350 | @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.\r |
1351 | @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r | |
fc547e08 | 1352 | \r |
1353 | **/\r | |
80408db0 | 1354 | EFI_STATUS\r |
1355 | EFIAPI\r | |
1356 | PeiPcdGetNextToken (\r | |
1357 | IN CONST EFI_GUID *Guid, OPTIONAL\r | |
1358 | IN OUT UINTN *TokenNumber\r | |
1359 | )\r | |
1360 | {\r | |
1361 | UINTN GuidTableIdx;\r | |
1362 | PEI_PCD_DATABASE *PeiPcdDb;\r | |
1363 | EFI_GUID *MatchGuid;\r | |
419db80b | 1364 | EFI_GUID *GuidTable;\r |
80408db0 | 1365 | DYNAMICEX_MAPPING *ExMapTable;\r |
fc547e08 | 1366 | UINTN Index;\r |
80408db0 | 1367 | BOOLEAN Found;\r |
1368 | BOOLEAN PeiExMapTableEmpty;\r | |
419db80b | 1369 | UINTN PeiNexTokenNumber; \r |
80408db0 | 1370 | \r |
f806dd27 | 1371 | if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r |
80408db0 | 1372 | return EFI_UNSUPPORTED;\r |
1373 | }\r | |
1374 | \r | |
419db80b BF |
1375 | PeiPcdDb = GetPcdDatabase ();\r |
1376 | PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;\r | |
1377 | GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r | |
80408db0 | 1378 | \r |
419db80b BF |
1379 | if (PeiPcdDb->ExTokenCount == 0) {\r |
1380 | PeiExMapTableEmpty = TRUE;\r | |
1381 | } else {\r | |
1382 | PeiExMapTableEmpty = FALSE;\r | |
1383 | }\r | |
80408db0 | 1384 | if (Guid == NULL) {\r |
419db80b | 1385 | if (*TokenNumber > PeiNexTokenNumber) {\r |
80408db0 | 1386 | return EFI_NOT_FOUND;\r |
1387 | }\r | |
1388 | (*TokenNumber)++;\r | |
419db80b | 1389 | if (*TokenNumber > PeiNexTokenNumber) {\r |
80408db0 | 1390 | *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r |
419db80b | 1391 | return EFI_NOT_FOUND;\r |
80408db0 | 1392 | }\r |
1393 | return EFI_SUCCESS;\r | |
1394 | } else {\r | |
1395 | if (PeiExMapTableEmpty) {\r | |
419db80b | 1396 | return EFI_NOT_FOUND;\r |
80408db0 | 1397 | }\r |
419db80b BF |
1398 | \r |
1399 | MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);\r | |
80408db0 | 1400 | \r |
1401 | if (MatchGuid == NULL) {\r | |
80408db0 | 1402 | return EFI_NOT_FOUND;\r |
1403 | }\r | |
1404 | \r | |
419db80b | 1405 | GuidTableIdx = MatchGuid - GuidTable;\r |
80408db0 | 1406 | \r |
419db80b | 1407 | ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r |
80408db0 | 1408 | \r |
1409 | Found = FALSE;\r | |
1410 | //\r | |
1411 | // Locate the GUID in ExMapTable first.\r | |
1412 | //\r | |
419db80b | 1413 | for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r |
fc547e08 | 1414 | if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r |
80408db0 | 1415 | Found = TRUE;\r |
1416 | break;\r | |
1417 | }\r | |
1418 | }\r | |
1419 | \r | |
1420 | if (Found) {\r | |
bfb4c2ba CS |
1421 | //\r |
1422 | // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first\r | |
1423 | // token number in found token space.\r | |
1424 | //\r | |
80408db0 | 1425 | if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r |
fc547e08 | 1426 | *TokenNumber = ExMapTable[Index].ExTokenNumber;\r |
80408db0 | 1427 | return EFI_SUCCESS;\r |
1428 | }\r | |
1429 | \r | |
419db80b | 1430 | for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {\r |
bfb4c2ba | 1431 | if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {\r |
419db80b BF |
1432 | break;\r |
1433 | }\r | |
1434 | }\r | |
1435 | \r | |
1436 | while (Index < PeiPcdDb->ExTokenCount) {\r | |
1437 | Index++;\r | |
1438 | if (Index == PeiPcdDb->ExTokenCount) {\r | |
1439 | //\r | |
1440 | // Exceed the length of ExMap Table\r | |
1441 | //\r | |
1442 | *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r | |
1443 | return EFI_NOT_FOUND;\r | |
1444 | } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r | |
1445 | //\r | |
1446 | // Found the next match\r | |
1447 | //\r | |
1448 | *TokenNumber = ExMapTable[Index].ExTokenNumber;\r | |
1449 | return EFI_SUCCESS;\r | |
80408db0 | 1450 | }\r |
1451 | }\r | |
80408db0 | 1452 | }\r |
1453 | }\r | |
1454 | \r | |
1455 | return EFI_NOT_FOUND;\r | |
1456 | }\r | |
1457 | \r | |
fc547e08 | 1458 | /**\r |
1459 | Retrieves the next valid PCD token namespace for a given namespace.\r | |
1460 | \r | |
419db80b BF |
1461 | Gets the next valid token namespace for a given namespace. This is useful to traverse the valid\r |
1462 | token namespaces on a platform.\r | |
1463 | \r | |
1464 | @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token\r | |
1465 | namespace from which the search will start. On output, it designates the next valid\r | |
1466 | token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r | |
1467 | space of the current platform is returned. If the search cannot locate the next valid\r | |
1468 | token namespace, an error is returned and the value of *Guid is undefined.\r | |
1469 | \r | |
1470 | @retval EFI_SUCCESS The PCD service retrieved the value requested.\r | |
1471 | @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.\r | |
80408db0 | 1472 | \r |
fc547e08 | 1473 | **/\r |
80408db0 | 1474 | EFI_STATUS\r |
1475 | EFIAPI\r | |
1476 | PeiPcdGetNextTokenSpace (\r | |
1477 | IN OUT CONST EFI_GUID **Guid\r | |
1478 | )\r | |
1479 | {\r | |
1480 | UINTN GuidTableIdx;\r | |
1481 | EFI_GUID *MatchGuid;\r | |
1482 | PEI_PCD_DATABASE *PeiPcdDb;\r | |
1483 | DYNAMICEX_MAPPING *ExMapTable;\r | |
fc547e08 | 1484 | UINTN Index;\r |
419db80b | 1485 | UINTN Index2;\r |
80408db0 | 1486 | BOOLEAN Found;\r |
1487 | BOOLEAN PeiExMapTableEmpty;\r | |
419db80b | 1488 | EFI_GUID *GuidTable;\r |
80408db0 | 1489 | \r |
f806dd27 | 1490 | if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r |
80408db0 | 1491 | return EFI_UNSUPPORTED;\r |
1492 | }\r | |
1493 | \r | |
1494 | ASSERT (Guid != NULL);\r | |
1495 | \r | |
419db80b | 1496 | PeiPcdDb = GetPcdDatabase ();\r |
80408db0 | 1497 | \r |
419db80b BF |
1498 | if (PeiPcdDb->ExTokenCount == 0) {\r |
1499 | PeiExMapTableEmpty = TRUE;\r | |
1500 | } else {\r | |
1501 | PeiExMapTableEmpty = FALSE;\r | |
1502 | }\r | |
1503 | \r | |
80408db0 | 1504 | if (PeiExMapTableEmpty) {\r |
419db80b | 1505 | return EFI_NOT_FOUND;\r |
80408db0 | 1506 | }\r |
1507 | \r | |
419db80b BF |
1508 | ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r |
1509 | GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r | |
1510 | \r | |
80408db0 | 1511 | if (*Guid == NULL) {\r |
1512 | //\r | |
1513 | // return the first Token Space Guid.\r | |
1514 | //\r | |
419db80b | 1515 | *Guid = GuidTable + ExMapTable[0].ExGuidIndex;\r |
80408db0 | 1516 | return EFI_SUCCESS;\r |
1517 | }\r | |
1518 | \r | |
419db80b | 1519 | MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);\r |
80408db0 | 1520 | \r |
1521 | if (MatchGuid == NULL) {\r | |
1522 | return EFI_NOT_FOUND;\r | |
1523 | }\r | |
1524 | \r | |
419db80b | 1525 | GuidTableIdx = MatchGuid - GuidTable;\r |
80408db0 | 1526 | \r |
1527 | Found = FALSE;\r | |
419db80b | 1528 | for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r |
fc547e08 | 1529 | if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r |
80408db0 | 1530 | Found = TRUE;\r |
1531 | break;\r | |
1532 | }\r | |
1533 | }\r | |
1534 | \r | |
1535 | if (Found) {\r | |
fc547e08 | 1536 | Index++;\r |
419db80b BF |
1537 | for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {\r |
1538 | if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {\r | |
1539 | Found = FALSE;\r | |
1540 | for (Index2 = 0 ; Index2 < Index; Index2++) {\r | |
1541 | if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {\r | |
1542 | //\r | |
1543 | // This token namespace should have been found and output at preceding getting.\r | |
1544 | //\r | |
1545 | Found = TRUE;\r | |
1546 | break;\r | |
1547 | }\r | |
1548 | }\r | |
1549 | if (!Found) {\r | |
1550 | *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;\r | |
1551 | return EFI_SUCCESS;\r | |
1552 | }\r | |
80408db0 | 1553 | }\r |
1554 | }\r | |
1555 | *Guid = NULL;\r | |
80408db0 | 1556 | }\r |
1557 | \r | |
1558 | return EFI_NOT_FOUND;\r | |
1559 | \r | |
1560 | }\r | |
1561 | \r | |
fc547e08 | 1562 | /**\r |
1563 | Get PCD value's size for POINTER type PCD.\r | |
1564 | \r | |
419db80b | 1565 | The POINTER type PCD's value will be stored into a buffer in specified size.\r |
fc547e08 | 1566 | The max size of this PCD's value is described in PCD's definition in DEC file.\r |
1567 | \r | |
1568 | @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r | |
3fd8027e | 1569 | @param MaxSize Maximum size of PCD's value\r |
fc547e08 | 1570 | @param Database Pcd database in PEI phase.\r |
1571 | \r | |
1572 | @return PCD value's size for POINTER type PCD.\r | |
1573 | \r | |
1574 | **/\r | |
80408db0 | 1575 | UINTN\r |
1576 | GetPtrTypeSize (\r | |
1577 | IN UINTN LocalTokenNumberTableIdx,\r | |
1578 | OUT UINTN *MaxSize,\r | |
1579 | IN PEI_PCD_DATABASE *Database\r | |
1580 | )\r | |
1581 | {\r | |
1582 | INTN SizeTableIdx;\r | |
1583 | UINTN LocalTokenNumber;\r | |
80408db0 | 1584 | SIZE_INFO *SizeTable;\r |
80408db0 | 1585 | \r |
1586 | SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r | |
1587 | \r | |
419db80b | 1588 | LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r |
80408db0 | 1589 | \r |
1590 | ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r | |
1591 | \r | |
419db80b | 1592 | SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r |
80408db0 | 1593 | \r |
1594 | *MaxSize = SizeTable[SizeTableIdx];\r | |
1595 | //\r | |
1596 | // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r | |
1597 | // PCD entry.\r | |
1598 | //\r | |
fc547e08 | 1599 | if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r |
80408db0 | 1600 | //\r |
419db80b | 1601 | // We have only two entry for VPD enabled PCD entry:\r |
80408db0 | 1602 | // 1) MAX Size.\r |
419db80b | 1603 | // 2) Current Size\r |
80408db0 | 1604 | // We consider current size is equal to MAX size.\r |
1605 | //\r | |
1606 | return *MaxSize;\r | |
1607 | } else {\r | |
7c736265 LG |
1608 | //\r |
1609 | // We have only two entry for Non-Sku enabled PCD entry:\r | |
1610 | // 1) MAX SIZE\r | |
1611 | // 2) Current Size\r | |
1612 | //\r | |
1613 | return SizeTable[SizeTableIdx + 1];\r | |
80408db0 | 1614 | }\r |
1615 | }\r | |
1616 | \r | |
fc547e08 | 1617 | /**\r |
1618 | Set PCD value's size for POINTER type PCD.\r | |
1619 | \r | |
419db80b | 1620 | The POINTER type PCD's value will be stored into a buffer in specified size.\r |
fc547e08 | 1621 | The max size of this PCD's value is described in PCD's definition in DEC file.\r |
1622 | \r | |
1623 | @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r | |
3fd8027e | 1624 | @param CurrentSize Maximum size of PCD's value\r |
fc547e08 | 1625 | @param Database Pcd database in PEI phase.\r |
80408db0 | 1626 | \r |
3fd8027e | 1627 | @retval TRUE Success to set PCD's value size, which is not exceed maximum size\r |
1628 | @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size\r | |
80408db0 | 1629 | \r |
fc547e08 | 1630 | **/\r |
80408db0 | 1631 | BOOLEAN\r |
1632 | SetPtrTypeSize (\r | |
1633 | IN UINTN LocalTokenNumberTableIdx,\r | |
1634 | IN OUT UINTN *CurrentSize,\r | |
1635 | IN PEI_PCD_DATABASE *Database\r | |
1636 | )\r | |
1637 | {\r | |
1638 | INTN SizeTableIdx;\r | |
1639 | UINTN LocalTokenNumber;\r | |
80408db0 | 1640 | SIZE_INFO *SizeTable;\r |
80408db0 | 1641 | UINTN MaxSize;\r |
1642 | \r | |
1643 | SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r | |
1644 | \r | |
419db80b | 1645 | LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r |
80408db0 | 1646 | \r |
1647 | ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r | |
419db80b BF |
1648 | \r |
1649 | SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r | |
80408db0 | 1650 | \r |
1651 | MaxSize = SizeTable[SizeTableIdx];\r | |
1652 | //\r | |
1653 | // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r | |
1654 | // PCD entry.\r | |
1655 | //\r | |
fc547e08 | 1656 | if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r |
80408db0 | 1657 | //\r |
1658 | // We shouldn't come here as we don't support SET for VPD\r | |
1659 | //\r | |
1660 | ASSERT (FALSE);\r | |
1661 | return FALSE;\r | |
1662 | } else {\r | |
1663 | if ((*CurrentSize > MaxSize) ||\r | |
1664 | (*CurrentSize == MAX_ADDRESS)) {\r | |
1665 | *CurrentSize = MaxSize;\r | |
1666 | return FALSE;\r | |
5944a83b | 1667 | }\r |
80408db0 | 1668 | \r |
7c736265 LG |
1669 | //\r |
1670 | // We have only two entry for Non-Sku enabled PCD entry:\r | |
1671 | // 1) MAX SIZE\r | |
1672 | // 2) Current Size\r | |
1673 | //\r | |
1674 | SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r | |
1675 | return TRUE;\r | |
80408db0 | 1676 | }\r |
1677 | \r | |
1678 | }\r |