]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/PCD/Pei/Pcd.c
MdeModulePkg PCD: Enable Firmware to retrieve the default setting
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
CommitLineData
fc547e08 1/** @file \r
5944a83b 2 All Pcd Ppi services are implemented here.\r
fc547e08 3 \r
2db48a1f 4Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
bfb4c2ba
CS
5(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT 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 22PCD_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 65EFI_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
91GET_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
101EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance = {\r
102 PeiGetPcdInfoGetInfoEx,\r
103 PeiGetPcdInfoGetSku\r
104};\r
105\r
17e7fa8f 106EFI_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
119EFI_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
144VOID\r
145EFIAPI\r
146PcdSetNvStoreDefaultIdCallBack (\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
fc547e08 231/**\r
232 Main entry for PCD PEIM driver.\r
233 \r
8a541f0a 234 This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.\r
80408db0 235\r
8bd22b8a
LG
236 @param FileHandle Handle of the file being invoked.\r
237 @param PeiServices Describes the list of possible PEI Services.\r
80408db0 238\r
fc547e08 239 @return Status of install PCD_PPI\r
240\r
241**/\r
80408db0 242EFI_STATUS\r
243EFIAPI\r
244PcdPeimInit (\r
8bd22b8a
LG
245 IN EFI_PEI_FILE_HANDLE FileHandle,\r
246 IN CONST EFI_PEI_SERVICES **PeiServices\r
80408db0 247 )\r
248{\r
a78d3a27 249 EFI_STATUS Status;\r
96d6d004 250\r
a78d3a27 251 BuildPcdDatabase (FileHandle);\r
80408db0 252\r
8a541f0a 253 //\r
17e7fa8f 254 // Install PCD_PPI and EFI_PEI_PCD_PPI.\r
8a541f0a 255 //\r
17e7fa8f 256 Status = PeiServicesInstallPpi (&mPpiList[0]);\r
8a541f0a 257 ASSERT_EFI_ERROR (Status);\r
96d6d004
SZ
258\r
259 //\r
85d0b97d 260 // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.\r
96d6d004 261 //\r
85d0b97d
SZ
262 Status = PeiServicesInstallPpi (&mPpiList2[0]);\r
263 ASSERT_EFI_ERROR (Status);\r
96d6d004 264\r
219247e1
LG
265 Status = PeiRegisterCallBackOnSet (\r
266 &gEfiMdeModulePkgTokenSpaceGuid,\r
267 PcdToken(PcdSetNvStoreDefaultId),\r
268 PcdSetNvStoreDefaultIdCallBack\r
269 );\r
270 ASSERT_EFI_ERROR (Status);\r
271\r
8a541f0a 272 return Status;\r
80408db0 273}\r
274\r
96d6d004
SZ
275/**\r
276 Retrieve additional information associated with a PCD token in the default token space.\r
277\r
278 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
279 human readable name that is associated with the token.\r
280\r
281 @param[in] TokenNumber The PCD token number.\r
282 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
283 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
284\r
285 @retval EFI_SUCCESS The PCD information was returned successfully.\r
286 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
287**/\r
288EFI_STATUS\r
289EFIAPI\r
290PeiGetPcdInfoGetInfo (\r
291 IN UINTN TokenNumber,\r
292 OUT EFI_PCD_INFO *PcdInfo\r
293 )\r
294{\r
295 return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r
296}\r
297\r
298/**\r
299 Retrieve additional information associated with a PCD token.\r
300\r
301 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
302 human readable name that is associated with the token.\r
303\r
304 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
305 @param[in] TokenNumber The PCD token number.\r
306 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
307 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
308\r
309 @retval EFI_SUCCESS The PCD information was returned successfully.\r
310 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
311**/\r
312EFI_STATUS\r
313EFIAPI\r
314PeiGetPcdInfoGetInfoEx (\r
315 IN CONST EFI_GUID *Guid,\r
316 IN UINTN TokenNumber,\r
317 OUT EFI_PCD_INFO *PcdInfo\r
318 )\r
319{\r
320 return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r
321}\r
322\r
323/**\r
324 Retrieve the currently set SKU Id.\r
325\r
326 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
327 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
328 Id is returned.\r
329**/\r
330UINTN\r
331EFIAPI\r
332PeiGetPcdInfoGetSku (\r
333 VOID\r
334 )\r
335{\r
b6e89910 336 return (UINTN) GetPcdDatabase()->SystemSkuId;\r
96d6d004
SZ
337}\r
338\r
fc547e08 339/**\r
340 Sets the SKU value for subsequent calls to set or get PCD token values.\r
341\r
342 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values. \r
343 SetSku() is normally called only once by the system.\r
344\r
345 For each item (token), the database can hold a single value that applies to all SKUs, \r
346 or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r
347 SKU-specific values are called SKU enabled. \r
348 \r
120ca3ce 349 The SKU Id of zero is reserved as a default.\r
fc547e08 350 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r
351 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r
352 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r
353 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been \r
354 set for that Id, the results are unpredictable.\r
355\r
356 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and \r
357 set values associated with a PCD token.\r
358\r
fc547e08 359**/\r
80408db0 360VOID\r
361EFIAPI\r
362PeiPcdSetSku (\r
363 IN UINTN SkuId\r
364 )\r
365{\r
85d0b97d
SZ
366 PEI_PCD_DATABASE *PeiPcdDb;\r
367 SKU_ID *SkuIdTable;\r
368 UINTN Index;\r
369\r
370 PeiPcdDb = GetPcdDatabase();\r
2db48a1f
SZ
371\r
372 if (SkuId == PeiPcdDb->SystemSkuId) {\r
373 //\r
374 // The input SKU Id is equal to current SKU Id, return directly.\r
375 //\r
376 return;\r
377 }\r
378\r
379 if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r
380 DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r
381 DEBUG ((\r
382 DEBUG_ERROR,\r
383 "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
384 PeiPcdDb->SystemSkuId,\r
385 (SKU_ID) SkuId\r
386 ));\r
387 ASSERT (FALSE);\r
388 return;\r
389 }\r
390\r
85d0b97d
SZ
391 SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
392 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
393 if (SkuId == SkuIdTable[Index + 1]) {\r
2db48a1f 394 DEBUG ((EFI_D_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r
85d0b97d
SZ
395 PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r
396 return;\r
397 }\r
398 }\r
80408db0 399\r
85d0b97d 400 //\r
2db48a1f 401 // Invalid input SkuId, the default SKU Id will be still used for the system.\r
85d0b97d 402 //\r
2db48a1f 403 DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
80408db0 404 return;\r
405}\r
406\r
fc547e08 407/**\r
408 Retrieves an 8-bit value for a given PCD token.\r
80408db0 409\r
fc547e08 410 Retrieves the current byte-sized value for a PCD token number. \r
411 If the TokenNumber is invalid, the results are unpredictable.\r
412 \r
413 @param[in] TokenNumber The PCD token number. \r
80408db0 414\r
fc547e08 415 @return The UINT8 value.\r
416 \r
417**/\r
80408db0 418UINT8\r
419EFIAPI\r
420PeiPcdGet8 (\r
421 IN UINTN TokenNumber\r
422 )\r
423{\r
424 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
425}\r
426\r
fc547e08 427/**\r
428 Retrieves an 16-bit value for a given PCD token.\r
80408db0 429\r
fc547e08 430 Retrieves the current 16-bits value for a PCD token number. \r
431 If the TokenNumber is invalid, the results are unpredictable.\r
432 \r
433 @param[in] TokenNumber The PCD token number. \r
80408db0 434\r
fc547e08 435 @return The UINT16 value.\r
436 \r
437**/\r
80408db0 438UINT16\r
439EFIAPI\r
440PeiPcdGet16 (\r
441 IN UINTN TokenNumber\r
442 )\r
443{\r
444 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
445}\r
446\r
fc547e08 447/**\r
448 Retrieves an 32-bit value for a given PCD token.\r
80408db0 449\r
fc547e08 450 Retrieves the current 32-bits value for a PCD token number. \r
451 If the TokenNumber is invalid, the results are unpredictable.\r
452 \r
453 @param[in] TokenNumber The PCD token number. \r
80408db0 454\r
fc547e08 455 @return The UINT32 value.\r
456 \r
457**/\r
80408db0 458UINT32\r
459EFIAPI\r
460PeiPcdGet32 (\r
461 IN UINTN TokenNumber\r
462 )\r
463{\r
464 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
465}\r
466\r
fc547e08 467/**\r
468 Retrieves an 64-bit value for a given PCD token.\r
80408db0 469\r
fc547e08 470 Retrieves the current 64-bits value for a PCD token number. \r
471 If the TokenNumber is invalid, the results are unpredictable.\r
472 \r
473 @param[in] TokenNumber The PCD token number. \r
80408db0 474\r
fc547e08 475 @return The UINT64 value.\r
476 \r
477**/\r
80408db0 478UINT64\r
479EFIAPI\r
480PeiPcdGet64 (\r
481 IN UINTN TokenNumber\r
482 )\r
483{\r
484 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
485}\r
486\r
fc547e08 487/**\r
488 Retrieves a pointer to a value for a given PCD token.\r
489\r
490 Retrieves the current pointer to the buffer for a PCD token number. \r
491 Do not make any assumptions about the alignment of the pointer that \r
492 is returned by this function call. If the TokenNumber is invalid, \r
493 the results are unpredictable.\r
80408db0 494\r
fc547e08 495 @param[in] TokenNumber The PCD token number. \r
80408db0 496\r
3fd8027e 497 @return The pointer to the buffer to be retrieved.\r
fc547e08 498 \r
499**/\r
80408db0 500VOID *\r
501EFIAPI\r
502PeiPcdGetPtr (\r
503 IN UINTN TokenNumber\r
504 )\r
505{\r
506 return GetWorker (TokenNumber, 0);\r
507}\r
508\r
fc547e08 509/**\r
510 Retrieves a Boolean value for a given PCD token.\r
80408db0 511\r
fc547e08 512 Retrieves the current boolean value for a PCD token number. \r
513 Do not make any assumptions about the alignment of the pointer that \r
514 is returned by this function call. If the TokenNumber is invalid, \r
515 the results are unpredictable.\r
80408db0 516\r
fc547e08 517 @param[in] TokenNumber The PCD token number. \r
518\r
519 @return The Boolean value.\r
520 \r
521**/\r
80408db0 522BOOLEAN\r
523EFIAPI\r
524PeiPcdGetBool (\r
525 IN UINTN TokenNumber\r
526 )\r
527{\r
528 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
529}\r
530\r
fc547e08 531/**\r
532 Retrieves the size of the value for a given PCD token.\r
533\r
534 Retrieves the current size of a particular PCD token. \r
535 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 536\r
fc547e08 537 @param[in] TokenNumber The PCD token number. \r
80408db0 538\r
fc547e08 539 @return The size of the value for the PCD token.\r
540 \r
541**/\r
80408db0 542UINTN\r
543EFIAPI\r
544PeiPcdGetSize (\r
545 IN UINTN TokenNumber\r
546 )\r
547{\r
548 PEI_PCD_DATABASE *PeiPcdDb;\r
549 UINTN Size;\r
550 UINTN MaxSize;\r
419db80b 551 UINT32 LocalTokenCount;\r
80408db0 552\r
419db80b
BF
553 PeiPcdDb = GetPcdDatabase ();\r
554 LocalTokenCount = PeiPcdDb->LocalTokenCount;\r
80408db0 555 //\r
556 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
557 // We have to decrement TokenNumber by 1 to make it usable\r
558 // as the array index.\r
559 //\r
560 TokenNumber--;\r
561\r
562 // EBC compiler is very choosy. It may report warning about comparison\r
563 // between UINTN and 0 . So we add 1 in each size of the \r
564 // comparison.\r
419db80b 565 ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));\r
80408db0 566\r
419db80b 567 Size = (*((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber) & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
80408db0 568\r
569 if (Size == 0) {\r
570 //\r
571 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
572 //\r
573 return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);\r
574 } else {\r
575 return Size;\r
576 }\r
577\r
578}\r
579\r
fc547e08 580/**\r
581 Retrieves an 8-bit value for a given PCD token.\r
80408db0 582\r
fc547e08 583 Retrieves the 8-bit value of a particular PCD token. \r
584 If the TokenNumber is invalid or the token space\r
585 specified by Guid does not exist, the results are \r
586 unpredictable.\r
80408db0 587\r
fc547e08 588 @param[in] Guid The token space for the token number.\r
589 @param[in] ExTokenNumber The PCD token number. \r
590\r
591 @return The size 8-bit value for the PCD token.\r
592 \r
593**/\r
80408db0 594UINT8\r
595EFIAPI\r
596PeiPcdGet8Ex (\r
597 IN CONST EFI_GUID *Guid,\r
598 IN UINTN ExTokenNumber\r
599 )\r
600{\r
601 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
602}\r
603\r
fc547e08 604/**\r
605 Retrieves an 16-bit value for a given PCD token.\r
80408db0 606\r
fc547e08 607 Retrieves the 16-bit value of a particular PCD token. \r
608 If the TokenNumber is invalid or the token space\r
609 specified by Guid does not exist, the results are \r
610 unpredictable.\r
80408db0 611\r
fc547e08 612 @param[in] Guid The token space for the token number.\r
613 @param[in] ExTokenNumber The PCD token number. \r
614\r
615 @return The size 16-bit value for the PCD token.\r
616 \r
617**/\r
80408db0 618UINT16\r
619EFIAPI\r
620PeiPcdGet16Ex (\r
621 IN CONST EFI_GUID *Guid,\r
622 IN UINTN ExTokenNumber\r
623 )\r
624{\r
625 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
626}\r
627\r
fc547e08 628/**\r
629 Retrieves an 32-bit value for a given PCD token.\r
630\r
631 Retrieves the 32-bit value of a particular PCD token. \r
632 If the TokenNumber is invalid or the token space\r
633 specified by Guid does not exist, the results are \r
634 unpredictable.\r
80408db0 635\r
fc547e08 636 @param[in] Guid The token space for the token number.\r
637 @param[in] ExTokenNumber The PCD token number. \r
80408db0 638\r
fc547e08 639 @return The size 32-bit value for the PCD token.\r
640 \r
641**/\r
80408db0 642UINT32\r
643EFIAPI\r
644PeiPcdGet32Ex (\r
645 IN CONST EFI_GUID *Guid,\r
646 IN UINTN ExTokenNumber\r
647 )\r
648{\r
649 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
650}\r
651\r
fc547e08 652/**\r
653 Retrieves an 64-bit value for a given PCD token.\r
654\r
655 Retrieves the 64-bit value of a particular PCD token. \r
656 If the TokenNumber is invalid or the token space\r
657 specified by Guid does not exist, the results are \r
658 unpredictable.\r
80408db0 659\r
fc547e08 660 @param[in] Guid The token space for the token number.\r
661 @param[in] ExTokenNumber The PCD token number. \r
80408db0 662\r
fc547e08 663 @return The size 64-bit value for the PCD token.\r
664 \r
665**/\r
80408db0 666UINT64\r
667EFIAPI\r
668PeiPcdGet64Ex (\r
669 IN CONST EFI_GUID *Guid,\r
670 IN UINTN ExTokenNumber\r
671 )\r
672{\r
673 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
674}\r
675\r
fc547e08 676/**\r
677 Retrieves a pointer to a value for a given PCD token.\r
80408db0 678\r
fc547e08 679 Retrieves the current pointer to the buffer for a PCD token number. \r
680 Do not make any assumptions about the alignment of the pointer that \r
681 is returned by this function call. If the TokenNumber is invalid, \r
682 the results are unpredictable.\r
80408db0 683\r
fc547e08 684 @param[in] Guid The token space for the token number.\r
685 @param[in] ExTokenNumber The PCD token number. \r
686\r
3fd8027e 687 @return The pointer to the buffer to be retrieved.\r
fc547e08 688 \r
689**/\r
80408db0 690VOID *\r
691EFIAPI\r
692PeiPcdGetPtrEx (\r
693 IN CONST EFI_GUID *Guid,\r
694 IN UINTN ExTokenNumber\r
695 )\r
696{\r
697 return ExGetWorker (Guid, ExTokenNumber, 0);\r
698}\r
699\r
fc547e08 700/**\r
701 Retrieves an Boolean value for a given PCD token.\r
702\r
703 Retrieves the Boolean value of a particular PCD token. \r
704 If the TokenNumber is invalid or the token space\r
705 specified by Guid does not exist, the results are \r
706 unpredictable.\r
80408db0 707\r
fc547e08 708 @param[in] Guid The token space for the token number.\r
709 @param[in] ExTokenNumber The PCD token number. \r
80408db0 710\r
fc547e08 711 @return The size Boolean value for the PCD token.\r
712 \r
713**/\r
80408db0 714BOOLEAN\r
715EFIAPI\r
716PeiPcdGetBoolEx (\r
717 IN CONST EFI_GUID *Guid,\r
718 IN UINTN ExTokenNumber\r
719 )\r
720{\r
721 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
722}\r
723\r
fc547e08 724/**\r
725 Retrieves the size of the value for a given PCD token.\r
726\r
727 Retrieves the current size of a particular PCD token. \r
728 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 729\r
fc547e08 730 @param[in] Guid The token space for the token number.\r
731 @param[in] ExTokenNumber The PCD token number. \r
80408db0 732\r
fc547e08 733 @return The size of the value for the PCD token.\r
734 \r
735**/\r
80408db0 736UINTN\r
737EFIAPI\r
738PeiPcdGetSizeEx (\r
739 IN CONST EFI_GUID *Guid,\r
740 IN UINTN ExTokenNumber\r
741 )\r
742{\r
80408db0 743 return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r
744}\r
745\r
fc547e08 746/**\r
747 Sets an 8-bit value for a given PCD token.\r
80408db0 748\r
fc547e08 749 When the PCD service sets a value, it will check to ensure that the \r
750 size of the value being set is compatible with the Token's existing definition. \r
751 If it is not, an error will be returned.\r
80408db0 752\r
fc547e08 753 @param[in] TokenNumber The PCD token number. \r
754 @param[in] Value The value to set for the PCD token.\r
755\r
756 @retval EFI_SUCCESS Procedure returned successfully.\r
757 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
758 being set was incompatible with a call to this function. \r
759 Use GetSize() to retrieve the size of the target data.\r
760 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
761 \r
762**/\r
80408db0 763EFI_STATUS\r
764EFIAPI\r
765PeiPcdSet8 (\r
766 IN UINTN TokenNumber,\r
767 IN UINT8 Value\r
768 )\r
769{\r
770 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
771}\r
772\r
fc547e08 773/**\r
774 Sets an 16-bit value for a given PCD token.\r
775\r
776 When the PCD service sets a value, it will check to ensure that the \r
777 size of the value being set is compatible with the Token's existing definition. \r
778 If it is not, an error will be returned.\r
80408db0 779\r
fc547e08 780 @param[in] TokenNumber The PCD token number. \r
781 @param[in] Value The value to set for the PCD token.\r
80408db0 782\r
fc547e08 783 @retval EFI_SUCCESS Procedure returned successfully.\r
784 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
785 being set was incompatible with a call to this function. \r
786 Use GetSize() to retrieve the size of the target data.\r
787 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
788 \r
789**/\r
80408db0 790EFI_STATUS\r
791EFIAPI\r
792PeiPcdSet16 (\r
793 IN UINTN TokenNumber,\r
794 IN UINT16 Value\r
795 )\r
796{\r
797 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
798}\r
799\r
fc547e08 800/**\r
801 Sets an 32-bit value for a given PCD token.\r
80408db0 802\r
fc547e08 803 When the PCD service sets a value, it will check to ensure that the \r
804 size of the value being set is compatible with the Token's existing definition. \r
805 If it is not, an error will be returned.\r
80408db0 806\r
fc547e08 807 @param[in] TokenNumber The PCD token number. \r
808 @param[in] Value The value to set for the PCD token.\r
809\r
810 @retval EFI_SUCCESS Procedure returned successfully.\r
811 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
812 being set was incompatible with a call to this function. \r
813 Use GetSize() to retrieve the size of the target data.\r
814 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
815 \r
816**/\r
80408db0 817EFI_STATUS\r
818EFIAPI\r
819PeiPcdSet32 (\r
820 IN UINTN TokenNumber,\r
821 IN UINT32 Value\r
822 )\r
823{\r
824 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
825}\r
826\r
fc547e08 827/**\r
828 Sets an 64-bit value for a given PCD token.\r
829\r
830 When the PCD service sets a value, it will check to ensure that the \r
831 size of the value being set is compatible with the Token's existing definition. \r
832 If it is not, an error will be returned.\r
80408db0 833\r
fc547e08 834 @param[in] TokenNumber The PCD token number. \r
835 @param[in] Value The value to set for the PCD token.\r
80408db0 836\r
fc547e08 837 @retval EFI_SUCCESS Procedure returned successfully.\r
838 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
839 being set was incompatible with a call to this function. \r
840 Use GetSize() to retrieve the size of the target data.\r
841 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
842 \r
843**/\r
80408db0 844EFI_STATUS\r
845EFIAPI\r
846PeiPcdSet64 (\r
847 IN UINTN TokenNumber,\r
848 IN UINT64 Value\r
849 )\r
850{\r
851 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
852}\r
853\r
fc547e08 854/**\r
855 Sets a value of a specified size for a given PCD token.\r
856\r
857 When the PCD service sets a value, it will check to ensure that the \r
858 size of the value being set is compatible with the Token's existing definition. \r
859 If it is not, an error will be returned.\r
860\r
861 @param[in] TokenNumber The PCD token number. \r
862 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
863 On input, if the SizeOfValue is greater than the maximum size supported \r
864 for this TokenNumber then the output value of SizeOfValue will reflect \r
865 the maximum size supported for this TokenNumber.\r
866 @param[in] Buffer The buffer to set for the PCD token.\r
867\r
868 @retval EFI_SUCCESS Procedure returned successfully.\r
869 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
870 being set was incompatible with a call to this function. \r
871 Use GetSize() to retrieve the size of the target data.\r
872 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
873 \r
874**/\r
80408db0 875EFI_STATUS\r
876EFIAPI\r
877PeiPcdSetPtr (\r
878 IN UINTN TokenNumber,\r
879 IN OUT UINTN *SizeOfBuffer,\r
880 IN VOID *Buffer\r
881 )\r
882{\r
883 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
884}\r
885\r
fc547e08 886/**\r
887 Sets an Boolean value for a given PCD token.\r
80408db0 888\r
fc547e08 889 When the PCD service sets a value, it will check to ensure that the \r
890 size of the value being set is compatible with the Token's existing definition. \r
891 If it is not, an error will be returned.\r
80408db0 892\r
fc547e08 893 @param[in] TokenNumber The PCD token number. \r
894 @param[in] Value The value to set for the PCD token.\r
895\r
896 @retval EFI_SUCCESS Procedure returned successfully.\r
897 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
898 being set was incompatible with a call to this function. \r
899 Use GetSize() to retrieve the size of the target data.\r
900 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
901 \r
902**/\r
80408db0 903EFI_STATUS\r
904EFIAPI\r
905PeiPcdSetBool (\r
906 IN UINTN TokenNumber,\r
907 IN BOOLEAN Value\r
908 )\r
909{\r
910 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
911}\r
912\r
fc547e08 913/**\r
914 Sets an 8-bit value for a given PCD token.\r
80408db0 915\r
fc547e08 916 When the PCD service sets a value, it will check to ensure that the \r
917 size of the value being set is compatible with the Token's existing definition. \r
918 If it is not, an error will be returned.\r
80408db0 919\r
fc547e08 920 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
921 @param[in] ExTokenNumber The PCD token number. \r
922 @param[in] Value The value to set for the PCD token.\r
923\r
924 @retval EFI_SUCCESS Procedure returned successfully.\r
925 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
926 being set was incompatible with a call to this function. \r
927 Use GetSize() to retrieve the size of the target data.\r
928 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
929 \r
930**/\r
80408db0 931EFI_STATUS\r
932EFIAPI\r
933PeiPcdSet8Ex (\r
934 IN CONST EFI_GUID *Guid,\r
935 IN UINTN ExTokenNumber,\r
936 IN UINT8 Value\r
937 )\r
938{\r
939 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
940}\r
941\r
fc547e08 942/**\r
943 Sets an 16-bit value for a given PCD token.\r
944\r
945 When the PCD service sets a value, it will check to ensure that the \r
946 size of the value being set is compatible with the Token's existing definition. \r
947 If it is not, an error will be returned.\r
80408db0 948\r
fc547e08 949 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
950 @param[in] ExTokenNumber The PCD token number. \r
951 @param[in] Value The value to set for the PCD token.\r
80408db0 952\r
fc547e08 953 @retval EFI_SUCCESS Procedure returned successfully.\r
954 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
955 being set was incompatible with a call to this function. \r
956 Use GetSize() to retrieve the size of the target data.\r
957 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
958 \r
959**/\r
80408db0 960EFI_STATUS\r
961EFIAPI\r
962PeiPcdSet16Ex (\r
963 IN CONST EFI_GUID *Guid,\r
964 IN UINTN ExTokenNumber,\r
965 IN UINT16 Value\r
966 )\r
967{\r
968 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
969}\r
970\r
fc547e08 971/**\r
972 Sets an 32-bit value for a given PCD token.\r
973\r
974 When the PCD service sets a value, it will check to ensure that the \r
975 size of the value being set is compatible with the Token's existing definition. \r
976 If it is not, an error will be returned.\r
80408db0 977\r
fc547e08 978 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
979 @param[in] ExTokenNumber The PCD token number. \r
980 @param[in] Value The value to set for the PCD token.\r
80408db0 981\r
fc547e08 982 @retval EFI_SUCCESS Procedure returned successfully.\r
983 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
984 being set was incompatible with a call to this function. \r
985 Use GetSize() to retrieve the size of the target data.\r
986 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
987 \r
988**/\r
80408db0 989EFI_STATUS\r
990EFIAPI\r
991PeiPcdSet32Ex (\r
992 IN CONST EFI_GUID *Guid,\r
993 IN UINTN ExTokenNumber,\r
994 IN UINT32 Value\r
995 )\r
996{\r
997 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
998}\r
999\r
fc547e08 1000/**\r
1001 Sets an 64-bit value for a given PCD token.\r
80408db0 1002\r
fc547e08 1003 When the PCD service sets a value, it will check to ensure that the \r
1004 size of the value being set is compatible with the Token's existing definition. \r
1005 If it is not, an error will be returned.\r
80408db0 1006\r
fc547e08 1007 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1008 @param[in] ExTokenNumber The PCD token number. \r
1009 @param[in] Value The value to set for the PCD token.\r
1010\r
1011 @retval EFI_SUCCESS Procedure returned successfully.\r
1012 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1013 being set was incompatible with a call to this function. \r
1014 Use GetSize() to retrieve the size of the target data.\r
1015 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1016 \r
1017**/\r
80408db0 1018EFI_STATUS\r
1019EFIAPI\r
1020PeiPcdSet64Ex (\r
1021 IN CONST EFI_GUID *Guid,\r
1022 IN UINTN ExTokenNumber,\r
1023 IN UINT64 Value\r
1024 )\r
1025{\r
1026 return ExSetValueWorker (ExTokenNumber, Guid, &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] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1037 @param[in] ExTokenNumber The PCD token number. \r
1038 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
1039 On input, if the SizeOfValue is greater than the maximum size supported \r
1040 for this TokenNumber then the output value of SizeOfValue will reflect \r
1041 the maximum size supported for this TokenNumber.\r
1042 @param[in] Value The buffer to set for the PCD token.\r
1043\r
1044 @retval EFI_SUCCESS Procedure returned successfully.\r
1045 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1046 being set was incompatible with a call to this function. \r
1047 Use GetSize() to retrieve the size of the target data.\r
1048 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1049 \r
1050**/\r
80408db0 1051EFI_STATUS\r
1052EFIAPI\r
1053PeiPcdSetPtrEx (\r
fc547e08 1054 IN CONST EFI_GUID *Guid,\r
1055 IN UINTN ExTokenNumber,\r
1056 IN OUT UINTN *SizeOfBuffer,\r
1057 IN VOID *Value\r
80408db0 1058 )\r
1059{\r
1060 return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r
1061}\r
1062\r
fc547e08 1063/**\r
1064 Sets an Boolean value for a given PCD token.\r
1065\r
1066 When the PCD service sets a value, it will check to ensure that the \r
1067 size of the value being set is compatible with the Token's existing definition. \r
1068 If it is not, an error will be returned.\r
80408db0 1069\r
fc547e08 1070 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1071 @param [in] ExTokenNumber The PCD token number. \r
1072 @param [in] Value The value to set for the PCD token.\r
80408db0 1073\r
fc547e08 1074 @retval EFI_SUCCESS Procedure returned successfully.\r
1075 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
1076 being set was incompatible with a call to this function. \r
1077 Use GetSize() to retrieve the size of the target data.\r
1078 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
1079 \r
1080**/\r
80408db0 1081EFI_STATUS\r
1082EFIAPI\r
1083PeiPcdSetBoolEx (\r
1084 IN CONST EFI_GUID *Guid,\r
1085 IN UINTN ExTokenNumber,\r
1086 IN BOOLEAN Value\r
1087 )\r
1088{\r
1089 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
1090}\r
1091\r
fc547e08 1092/**\r
1093 Specifies a function to be called anytime the value of a designated token is changed.\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] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
80408db0 1098\r
fc547e08 1099 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
1100 for the CallBackToken requested.\r
1101 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
80408db0 1102\r
fc547e08 1103**/\r
80408db0 1104EFI_STATUS\r
1105EFIAPI\r
1106PeiRegisterCallBackOnSet (\r
1107 IN CONST EFI_GUID *Guid, OPTIONAL\r
1108 IN UINTN ExTokenNumber,\r
1109 IN PCD_PPI_CALLBACK CallBackFunction\r
1110 )\r
1111{\r
f806dd27 1112 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1113 return EFI_UNSUPPORTED;\r
1114 }\r
1115\r
e4a3922f 1116 if (CallBackFunction == NULL) {\r
1117 return EFI_INVALID_PARAMETER;\r
1118 }\r
1119\r
80408db0 1120 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r
1121}\r
1122\r
fc547e08 1123/**\r
1124 Cancels a previously set callback function for a particular PCD token number.\r
80408db0 1125\r
fc547e08 1126 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1127 @param[in] ExTokenNumber The PCD token number. \r
1128 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
80408db0 1129\r
fc547e08 1130 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
1131 for the CallBackToken requested.\r
1132 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
1133\r
1134**/\r
80408db0 1135EFI_STATUS\r
1136EFIAPI\r
1137PcdUnRegisterCallBackOnSet (\r
1138 IN CONST EFI_GUID *Guid, OPTIONAL\r
1139 IN UINTN ExTokenNumber,\r
1140 IN PCD_PPI_CALLBACK CallBackFunction\r
1141 )\r
1142{\r
f806dd27 1143 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1144 return EFI_UNSUPPORTED;\r
1145 }\r
1146\r
e4a3922f 1147 if (CallBackFunction == NULL) {\r
1148 return EFI_INVALID_PARAMETER;\r
1149 }\r
1150\r
80408db0 1151 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r
1152}\r
1153\r
fc547e08 1154/**\r
90e06556 1155 Retrieves the next valid token number in a given namespace. \r
1156 \r
1157 This is useful since the PCD infrastructure contains a sparse list of token numbers, \r
1158 and one cannot a priori know what token numbers are valid in the database. \r
1159 \r
1160 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned. \r
1161 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned. \r
1162 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned. \r
1163 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned. \r
1164 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid. \r
1165 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned. \r
1166 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned. \r
1167 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
1168\r
1169\r
1170 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value. \r
1171 This is an optional parameter that may be NULL. If this parameter is NULL, then a request \r
1172 is being made to retrieve tokens from the default token space.\r
1173 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.\r
1174 \r
419db80b
BF
1175 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.\r
1176 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r
fc547e08 1177\r
1178**/\r
80408db0 1179EFI_STATUS\r
1180EFIAPI\r
1181PeiPcdGetNextToken (\r
1182 IN CONST EFI_GUID *Guid, OPTIONAL\r
1183 IN OUT UINTN *TokenNumber\r
1184 )\r
1185{\r
1186 UINTN GuidTableIdx;\r
1187 PEI_PCD_DATABASE *PeiPcdDb;\r
1188 EFI_GUID *MatchGuid;\r
419db80b 1189 EFI_GUID *GuidTable;\r
80408db0 1190 DYNAMICEX_MAPPING *ExMapTable;\r
fc547e08 1191 UINTN Index;\r
80408db0 1192 BOOLEAN Found;\r
1193 BOOLEAN PeiExMapTableEmpty;\r
419db80b 1194 UINTN PeiNexTokenNumber; \r
80408db0 1195\r
f806dd27 1196 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1197 return EFI_UNSUPPORTED;\r
1198 }\r
1199\r
419db80b
BF
1200 PeiPcdDb = GetPcdDatabase ();\r
1201 PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;\r
1202 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
80408db0 1203\r
419db80b
BF
1204 if (PeiPcdDb->ExTokenCount == 0) {\r
1205 PeiExMapTableEmpty = TRUE;\r
1206 } else {\r
1207 PeiExMapTableEmpty = FALSE;\r
1208 }\r
80408db0 1209 if (Guid == NULL) {\r
419db80b 1210 if (*TokenNumber > PeiNexTokenNumber) {\r
80408db0 1211 return EFI_NOT_FOUND;\r
1212 }\r
1213 (*TokenNumber)++;\r
419db80b 1214 if (*TokenNumber > PeiNexTokenNumber) {\r
80408db0 1215 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
419db80b 1216 return EFI_NOT_FOUND;\r
80408db0 1217 }\r
1218 return EFI_SUCCESS;\r
1219 } else {\r
1220 if (PeiExMapTableEmpty) {\r
419db80b 1221 return EFI_NOT_FOUND;\r
80408db0 1222 }\r
419db80b
BF
1223\r
1224 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);\r
80408db0 1225\r
1226 if (MatchGuid == NULL) {\r
80408db0 1227 return EFI_NOT_FOUND;\r
1228 }\r
1229\r
419db80b 1230 GuidTableIdx = MatchGuid - GuidTable;\r
80408db0 1231\r
419db80b 1232 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
80408db0 1233\r
1234 Found = FALSE;\r
1235 //\r
1236 // Locate the GUID in ExMapTable first.\r
1237 //\r
419db80b 1238 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
fc547e08 1239 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
80408db0 1240 Found = TRUE;\r
1241 break;\r
1242 }\r
1243 }\r
1244\r
1245 if (Found) {\r
bfb4c2ba
CS
1246 //\r
1247 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first\r
1248 // token number in found token space.\r
1249 //\r
80408db0 1250 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
fc547e08 1251 *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
80408db0 1252 return EFI_SUCCESS;\r
1253 }\r
1254\r
419db80b 1255 for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {\r
bfb4c2ba 1256 if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {\r
419db80b
BF
1257 break;\r
1258 }\r
1259 }\r
1260\r
1261 while (Index < PeiPcdDb->ExTokenCount) {\r
1262 Index++;\r
1263 if (Index == PeiPcdDb->ExTokenCount) {\r
1264 //\r
1265 // Exceed the length of ExMap Table\r
1266 //\r
1267 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
1268 return EFI_NOT_FOUND;\r
1269 } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
1270 //\r
1271 // Found the next match\r
1272 //\r
1273 *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
1274 return EFI_SUCCESS;\r
80408db0 1275 }\r
1276 }\r
80408db0 1277 }\r
1278 }\r
1279\r
1280 return EFI_NOT_FOUND;\r
1281}\r
1282\r
fc547e08 1283/**\r
1284 Retrieves the next valid PCD token namespace for a given namespace.\r
1285\r
419db80b
BF
1286 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid\r
1287 token namespaces on a platform.\r
1288\r
1289 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token\r
1290 namespace from which the search will start. On output, it designates the next valid\r
1291 token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r
1292 space of the current platform is returned. If the search cannot locate the next valid\r
1293 token namespace, an error is returned and the value of *Guid is undefined.\r
1294 \r
1295 @retval EFI_SUCCESS The PCD service retrieved the value requested.\r
1296 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.\r
80408db0 1297\r
fc547e08 1298**/\r
80408db0 1299EFI_STATUS\r
1300EFIAPI\r
1301PeiPcdGetNextTokenSpace (\r
1302 IN OUT CONST EFI_GUID **Guid\r
1303 )\r
1304{\r
1305 UINTN GuidTableIdx;\r
1306 EFI_GUID *MatchGuid;\r
1307 PEI_PCD_DATABASE *PeiPcdDb;\r
1308 DYNAMICEX_MAPPING *ExMapTable;\r
fc547e08 1309 UINTN Index;\r
419db80b 1310 UINTN Index2;\r
80408db0 1311 BOOLEAN Found;\r
1312 BOOLEAN PeiExMapTableEmpty;\r
419db80b 1313 EFI_GUID *GuidTable;\r
80408db0 1314\r
f806dd27 1315 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1316 return EFI_UNSUPPORTED;\r
1317 }\r
1318\r
1319 ASSERT (Guid != NULL);\r
1320\r
419db80b 1321 PeiPcdDb = GetPcdDatabase ();\r
80408db0 1322\r
419db80b
BF
1323 if (PeiPcdDb->ExTokenCount == 0) {\r
1324 PeiExMapTableEmpty = TRUE;\r
1325 } else {\r
1326 PeiExMapTableEmpty = FALSE;\r
1327 }\r
1328 \r
80408db0 1329 if (PeiExMapTableEmpty) {\r
419db80b 1330 return EFI_NOT_FOUND;\r
80408db0 1331 }\r
1332\r
419db80b
BF
1333 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
1334 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
1335 \r
80408db0 1336 if (*Guid == NULL) {\r
1337 //\r
1338 // return the first Token Space Guid.\r
1339 //\r
419db80b 1340 *Guid = GuidTable + ExMapTable[0].ExGuidIndex;\r
80408db0 1341 return EFI_SUCCESS;\r
1342 }\r
1343\r
419db80b 1344 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);\r
80408db0 1345\r
1346 if (MatchGuid == NULL) {\r
1347 return EFI_NOT_FOUND;\r
1348 }\r
1349 \r
419db80b 1350 GuidTableIdx = MatchGuid - GuidTable;\r
80408db0 1351\r
1352 Found = FALSE;\r
419db80b 1353 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
fc547e08 1354 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
80408db0 1355 Found = TRUE;\r
1356 break;\r
1357 }\r
1358 }\r
1359\r
1360 if (Found) {\r
fc547e08 1361 Index++;\r
419db80b
BF
1362 for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {\r
1363 if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {\r
1364 Found = FALSE;\r
1365 for (Index2 = 0 ; Index2 < Index; Index2++) {\r
1366 if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {\r
1367 //\r
1368 // This token namespace should have been found and output at preceding getting.\r
1369 //\r
1370 Found = TRUE;\r
1371 break;\r
1372 }\r
1373 }\r
1374 if (!Found) {\r
1375 *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;\r
1376 return EFI_SUCCESS;\r
1377 }\r
80408db0 1378 }\r
1379 }\r
1380 *Guid = NULL;\r
80408db0 1381 }\r
1382\r
1383 return EFI_NOT_FOUND;\r
1384\r
1385}\r
1386\r
fc547e08 1387/**\r
1388 Get PCD value's size for POINTER type PCD.\r
1389 \r
419db80b 1390 The POINTER type PCD's value will be stored into a buffer in specified size.\r
fc547e08 1391 The max size of this PCD's value is described in PCD's definition in DEC file.\r
1392\r
1393 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
3fd8027e 1394 @param MaxSize Maximum size of PCD's value\r
fc547e08 1395 @param Database Pcd database in PEI phase.\r
1396\r
1397 @return PCD value's size for POINTER type PCD.\r
1398\r
1399**/\r
80408db0 1400UINTN\r
1401GetPtrTypeSize (\r
1402 IN UINTN LocalTokenNumberTableIdx,\r
1403 OUT UINTN *MaxSize,\r
1404 IN PEI_PCD_DATABASE *Database\r
1405 )\r
1406{\r
1407 INTN SizeTableIdx;\r
1408 UINTN LocalTokenNumber;\r
1409 SKU_ID *SkuIdTable;\r
1410 SIZE_INFO *SizeTable;\r
fc547e08 1411 UINTN Index;\r
80408db0 1412\r
1413 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
1414\r
419db80b 1415 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
80408db0 1416\r
1417 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
1418 \r
419db80b 1419 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
80408db0 1420\r
1421 *MaxSize = SizeTable[SizeTableIdx];\r
1422 //\r
1423 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
1424 // PCD entry.\r
1425 //\r
fc547e08 1426 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
80408db0 1427 //\r
419db80b 1428 // We have only two entry for VPD enabled PCD entry:\r
80408db0 1429 // 1) MAX Size.\r
419db80b 1430 // 2) Current Size\r
80408db0 1431 // We consider current size is equal to MAX size.\r
1432 //\r
1433 return *MaxSize;\r
1434 } else {\r
1435 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
1436 //\r
1437 // We have only two entry for Non-Sku enabled PCD entry:\r
1438 // 1) MAX SIZE\r
1439 // 2) Current Size\r
1440 //\r
1441 return SizeTable[SizeTableIdx + 1];\r
1442 } else {\r
1443 //\r
1444 // We have these entry for SKU enabled PCD entry\r
1445 // 1) MAX SIZE\r
1446 // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
1447 //\r
1448 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
fc547e08 1449 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
419db80b 1450 if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
fc547e08 1451 return SizeTable[SizeTableIdx + 1 + Index];\r
80408db0 1452 }\r
1453 }\r
1454 return SizeTable[SizeTableIdx + 1];\r
1455 }\r
1456 }\r
1457}\r
1458\r
fc547e08 1459/**\r
1460 Set PCD value's size for POINTER type PCD.\r
1461 \r
419db80b 1462 The POINTER type PCD's value will be stored into a buffer in specified size.\r
fc547e08 1463 The max size of this PCD's value is described in PCD's definition in DEC file.\r
1464\r
1465 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
3fd8027e 1466 @param CurrentSize Maximum size of PCD's value\r
fc547e08 1467 @param Database Pcd database in PEI phase.\r
80408db0 1468\r
3fd8027e 1469 @retval TRUE Success to set PCD's value size, which is not exceed maximum size\r
1470 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size\r
80408db0 1471\r
fc547e08 1472**/\r
80408db0 1473BOOLEAN\r
1474SetPtrTypeSize (\r
1475 IN UINTN LocalTokenNumberTableIdx,\r
1476 IN OUT UINTN *CurrentSize,\r
1477 IN PEI_PCD_DATABASE *Database\r
1478 )\r
1479{\r
1480 INTN SizeTableIdx;\r
1481 UINTN LocalTokenNumber;\r
1482 SKU_ID *SkuIdTable;\r
1483 SIZE_INFO *SizeTable;\r
fc547e08 1484 UINTN Index;\r
80408db0 1485 UINTN MaxSize;\r
1486 \r
1487 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
1488\r
419db80b 1489 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
80408db0 1490\r
1491 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
419db80b
BF
1492\r
1493 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
80408db0 1494\r
1495 MaxSize = SizeTable[SizeTableIdx];\r
1496 //\r
1497 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
1498 // PCD entry.\r
1499 //\r
fc547e08 1500 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
80408db0 1501 //\r
1502 // We shouldn't come here as we don't support SET for VPD\r
1503 //\r
1504 ASSERT (FALSE);\r
1505 return FALSE;\r
1506 } else {\r
1507 if ((*CurrentSize > MaxSize) ||\r
1508 (*CurrentSize == MAX_ADDRESS)) {\r
1509 *CurrentSize = MaxSize;\r
1510 return FALSE;\r
5944a83b 1511 }\r
80408db0 1512 \r
1513 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
1514 //\r
1515 // We have only two entry for Non-Sku enabled PCD entry:\r
1516 // 1) MAX SIZE\r
1517 // 2) Current Size\r
1518 //\r
1519 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
1520 return TRUE;\r
1521 } else {\r
1522 //\r
1523 // We have these entry for SKU enabled PCD entry\r
1524 // 1) MAX SIZE\r
1525 // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
1526 //\r
1527 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
fc547e08 1528 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
419db80b 1529 if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
fc547e08 1530 SizeTable[SizeTableIdx + 1 + Index] = (SIZE_INFO) *CurrentSize;\r
80408db0 1531 return TRUE;\r
1532 }\r
1533 }\r
1534 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
1535 return TRUE;\r
1536 }\r
1537 }\r
1538\r
1539}\r