]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/PCD/Dxe/Pcd.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Pcd.c
... / ...
CommitLineData
1/** @file\r
2 PCD DXE driver manage all PCD entry initialized in PEI phase and DXE phase, and\r
3 produce the implementation of native PCD protocol and EFI_PCD_PROTOCOL defined in\r
4 PI 1.2 Vol3.\r
5\r
6Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
7This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "Service.h"\r
18\r
19//\r
20// Just pre-allocate a memory buffer that is big enough to\r
21// host all distinct TokenSpace guid in both\r
22// PEI ExMap and DXE ExMap.\r
23//\r
24EFI_GUID *TmpTokenSpaceBuffer[PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE] = { 0 };\r
25\r
26///\r
27/// PCD database lock.\r
28///\r
29EFI_LOCK mPcdDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE(TPL_NOTIFY);\r
30\r
31///\r
32/// PCD_PROTOCOL the EDKII native implementation which support dynamic \r
33/// type and dynamicEx type PCDs.\r
34///\r
35PCD_PROTOCOL mPcdInstance = {\r
36 DxePcdSetSku,\r
37\r
38 DxePcdGet8,\r
39 DxePcdGet16,\r
40 DxePcdGet32,\r
41 DxePcdGet64,\r
42 DxePcdGetPtr,\r
43 DxePcdGetBool,\r
44 DxePcdGetSize,\r
45\r
46 DxePcdGet8Ex,\r
47 DxePcdGet16Ex,\r
48 DxePcdGet32Ex,\r
49 DxePcdGet64Ex,\r
50 DxePcdGetPtrEx,\r
51 DxePcdGetBoolEx,\r
52 DxePcdGetSizeEx,\r
53\r
54 DxePcdSet8,\r
55 DxePcdSet16,\r
56 DxePcdSet32,\r
57 DxePcdSet64,\r
58 DxePcdSetPtr,\r
59 DxePcdSetBool,\r
60\r
61 DxePcdSet8Ex,\r
62 DxePcdSet16Ex,\r
63 DxePcdSet32Ex,\r
64 DxePcdSet64Ex,\r
65 DxePcdSetPtrEx,\r
66 DxePcdSetBoolEx,\r
67\r
68 DxeRegisterCallBackOnSet,\r
69 DxeUnRegisterCallBackOnSet,\r
70 DxePcdGetNextToken,\r
71 DxePcdGetNextTokenSpace\r
72};\r
73\r
74///\r
75/// EFI_PCD_PROTOCOL is defined in PI 1.2 Vol 3 which only support dynamicEx type\r
76/// PCD.\r
77///\r
78EFI_PCD_PROTOCOL mEfiPcdInstance = {\r
79 DxePcdSetSku,\r
80 DxePcdGet8Ex,\r
81 DxePcdGet16Ex,\r
82 DxePcdGet32Ex,\r
83 DxePcdGet64Ex,\r
84 DxePcdGetPtrEx,\r
85 DxePcdGetBoolEx,\r
86 DxePcdGetSizeEx,\r
87 DxePcdSet8Ex,\r
88 DxePcdSet16Ex,\r
89 DxePcdSet32Ex,\r
90 DxePcdSet64Ex,\r
91 DxePcdSetPtrEx,\r
92 DxePcdSetBoolEx,\r
93 (EFI_PCD_PROTOCOL_CALLBACK_ON_SET) DxeRegisterCallBackOnSet,\r
94 (EFI_PCD_PROTOCOL_CANCEL_CALLBACK) DxeUnRegisterCallBackOnSet,\r
95 DxePcdGetNextToken,\r
96 DxePcdGetNextTokenSpace\r
97};\r
98\r
99EFI_HANDLE mPcdHandle = NULL;\r
100\r
101/**\r
102 Main entry for PCD DXE driver.\r
103 \r
104 This routine initialize the PCD database and install PCD_PROTOCOL.\r
105 \r
106 @param ImageHandle Image handle for PCD DXE driver.\r
107 @param SystemTable Pointer to SystemTable.\r
108\r
109 @return Status of gBS->InstallProtocolInterface()\r
110\r
111**/\r
112EFI_STATUS\r
113EFIAPI\r
114PcdDxeInit (\r
115 IN EFI_HANDLE ImageHandle,\r
116 IN EFI_SYSTEM_TABLE *SystemTable\r
117 )\r
118{\r
119 EFI_STATUS Status;\r
120 \r
121 //\r
122 // Make sure the Pcd Protocol is not already installed in the system\r
123 //\r
124\r
125 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gPcdProtocolGuid);\r
126\r
127 BuildPcdDxeDataBase ();\r
128\r
129 //\r
130 // Install PCD_PROTOCOL to handle dynamic type PCD\r
131 // Install EFI_PCD_PROTOCOL to handle dynamicEx type PCD\r
132 //\r
133 Status = gBS->InstallMultipleProtocolInterfaces (\r
134 &mPcdHandle,\r
135 &gPcdProtocolGuid, &mPcdInstance,\r
136 &gEfiPcdProtocolGuid, &mEfiPcdInstance,\r
137 NULL\r
138 );\r
139 \r
140 ASSERT_EFI_ERROR (Status);\r
141\r
142 return Status;\r
143\r
144}\r
145\r
146/**\r
147 Sets the SKU value for subsequent calls to set or get PCD token values.\r
148\r
149 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values. \r
150 SetSku() is normally called only once by the system.\r
151\r
152 For each item (token), the database can hold a single value that applies to all SKUs, \r
153 or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r
154 SKU-specific values are called SKU enabled. \r
155 \r
156 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255. \r
157 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r
158 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r
159 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r
160 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been \r
161 set for that Id, the results are unpredictable.\r
162\r
163 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and \r
164 set values associated with a PCD token.\r
165\r
166**/\r
167VOID\r
168EFIAPI\r
169DxePcdSetSku (\r
170 IN UINTN SkuId\r
171 )\r
172{\r
173 mPcdDatabase->PeiDb.Init.SystemSkuId = (SKU_ID) SkuId;\r
174 \r
175 return;\r
176}\r
177\r
178/**\r
179 Retrieves an 8-bit value for a given PCD token.\r
180\r
181 Retrieves the current byte-sized value for a PCD token number. \r
182 If the TokenNumber is invalid, the results are unpredictable.\r
183 \r
184 @param[in] TokenNumber The PCD token number. \r
185\r
186 @return The UINT8 value.\r
187 \r
188**/\r
189UINT8\r
190EFIAPI\r
191DxePcdGet8 (\r
192 IN UINTN TokenNumber\r
193 )\r
194{\r
195 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
196}\r
197\r
198/**\r
199 Retrieves an 16-bit value for a given PCD token.\r
200\r
201 Retrieves the current 16-bits value for a PCD token number. \r
202 If the TokenNumber is invalid, the results are unpredictable.\r
203 \r
204 @param[in] TokenNumber The PCD token number. \r
205\r
206 @return The UINT16 value.\r
207 \r
208**/\r
209UINT16\r
210EFIAPI\r
211DxePcdGet16 (\r
212 IN UINTN TokenNumber\r
213 )\r
214{\r
215 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
216}\r
217\r
218/**\r
219 Retrieves an 32-bit value for a given PCD token.\r
220\r
221 Retrieves the current 32-bits value for a PCD token number. \r
222 If the TokenNumber is invalid, the results are unpredictable.\r
223 \r
224 @param[in] TokenNumber The PCD token number. \r
225\r
226 @return The UINT32 value.\r
227 \r
228**/\r
229UINT32\r
230EFIAPI\r
231DxePcdGet32 (\r
232 IN UINTN TokenNumber\r
233 )\r
234{\r
235 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
236}\r
237\r
238/**\r
239 Retrieves an 64-bit value for a given PCD token.\r
240\r
241 Retrieves the current 64-bits value for a PCD token number. \r
242 If the TokenNumber is invalid, the results are unpredictable.\r
243 \r
244 @param[in] TokenNumber The PCD token number. \r
245\r
246 @return The UINT64 value.\r
247 \r
248**/\r
249UINT64\r
250EFIAPI\r
251DxePcdGet64 (\r
252 IN UINTN TokenNumber\r
253 )\r
254{\r
255 return ReadUnaligned64(GetWorker (TokenNumber, sizeof (UINT64)));\r
256}\r
257\r
258/**\r
259 Retrieves a pointer to a value for a given PCD token.\r
260\r
261 Retrieves the current pointer to the buffer for a PCD token number. \r
262 Do not make any assumptions about the alignment of the pointer that \r
263 is returned by this function call. If the TokenNumber is invalid, \r
264 the results are unpredictable.\r
265\r
266 @param[in] TokenNumber The PCD token number. \r
267\r
268 @return The pointer to the buffer to be retrived.\r
269 \r
270**/\r
271VOID *\r
272EFIAPI\r
273DxePcdGetPtr (\r
274 IN UINTN TokenNumber\r
275 )\r
276{\r
277 return GetWorker (TokenNumber, 0);\r
278}\r
279\r
280/**\r
281 Retrieves a Boolean value for a given PCD token.\r
282\r
283 Retrieves the current boolean value for a PCD token number. \r
284 Do not make any assumptions about the alignment of the pointer that \r
285 is returned by this function call. If the TokenNumber is invalid, \r
286 the results are unpredictable.\r
287\r
288 @param[in] TokenNumber The PCD token number. \r
289\r
290 @return The Boolean value.\r
291 \r
292**/\r
293BOOLEAN\r
294EFIAPI\r
295DxePcdGetBool (\r
296 IN UINTN TokenNumber\r
297 )\r
298{\r
299 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
300}\r
301\r
302/**\r
303 Retrieves the size of the value for a given PCD token.\r
304\r
305 Retrieves the current size of a particular PCD token. \r
306 If the TokenNumber is invalid, the results are unpredictable.\r
307\r
308 @param[in] TokenNumber The PCD token number. \r
309\r
310 @return The size of the value for the PCD token.\r
311 \r
312**/\r
313UINTN\r
314EFIAPI\r
315DxePcdGetSize (\r
316 IN UINTN TokenNumber\r
317 )\r
318{\r
319 UINTN Size;\r
320 UINT32 *LocalTokenNumberTable;\r
321 BOOLEAN IsPeiDb;\r
322 UINTN MaxSize;\r
323 UINTN TmpTokenNumber;\r
324 //\r
325 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
326 // We have to decrement TokenNumber by 1 to make it usable\r
327 // as the array index.\r
328 //\r
329 TokenNumber--;\r
330\r
331 //\r
332 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber\r
333 // \r
334 TmpTokenNumber = TokenNumber;\r
335\r
336 // EBC compiler is very choosy. It may report warning about comparison\r
337 // between UINTN and 0 . So we add 1 in each size of the \r
338 // comparison.\r
339 ASSERT (TokenNumber + 1 < PCD_TOTAL_TOKEN_NUMBER + 1);\r
340\r
341 // EBC compiler is very choosy. It may report warning about comparison\r
342 // between UINTN and 0 . So we add 1 in each size of the \r
343 // comparison.\r
344 IsPeiDb = (BOOLEAN) (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);\r
345 \r
346 TokenNumber = IsPeiDb ? TokenNumber : \r
347 (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);\r
348\r
349 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable \r
350 : mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
351\r
352 Size = (LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
353\r
354 if (Size == 0) {\r
355 //\r
356 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
357 //\r
358 return GetPtrTypeSize (TmpTokenNumber, &MaxSize);\r
359 } else {\r
360 return Size;\r
361 }\r
362\r
363}\r
364\r
365/**\r
366 Retrieves an 8-bit value for a given PCD token.\r
367\r
368 Retrieves the 8-bit value of a particular PCD token. \r
369 If the TokenNumber is invalid or the token space\r
370 specified by Guid does not exist, the results are \r
371 unpredictable.\r
372\r
373 @param[in] Guid The token space for the token number.\r
374 @param[in] ExTokenNumber The PCD token number. \r
375\r
376 @return The size 8-bit value for the PCD token.\r
377 \r
378**/\r
379UINT8\r
380EFIAPI\r
381DxePcdGet8Ex (\r
382 IN CONST EFI_GUID *Guid,\r
383 IN UINTN ExTokenNumber\r
384 )\r
385{\r
386 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));\r
387}\r
388\r
389/**\r
390 Retrieves an 16-bit value for a given PCD token.\r
391\r
392 Retrieves the 16-bit value of a particular PCD token. \r
393 If the TokenNumber is invalid or the token space\r
394 specified by Guid does not exist, the results are \r
395 unpredictable.\r
396\r
397 @param[in] Guid The token space for the token number.\r
398 @param[in] ExTokenNumber The PCD token number. \r
399\r
400 @return The size 16-bit value for the PCD token.\r
401 \r
402**/\r
403UINT16\r
404EFIAPI\r
405DxePcdGet16Ex (\r
406 IN CONST EFI_GUID *Guid,\r
407 IN UINTN ExTokenNumber\r
408 )\r
409{\r
410 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));\r
411}\r
412\r
413/**\r
414 Retrieves an 32-bit value for a given PCD token.\r
415\r
416 Retrieves the 32-bit value of a particular PCD token. \r
417 If the TokenNumber is invalid or the token space\r
418 specified by Guid does not exist, the results are \r
419 unpredictable.\r
420\r
421 @param[in] Guid The token space for the token number.\r
422 @param[in] ExTokenNumber The PCD token number. \r
423\r
424 @return The size 32-bit value for the PCD token.\r
425 \r
426**/\r
427UINT32\r
428EFIAPI\r
429DxePcdGet32Ex (\r
430 IN CONST EFI_GUID *Guid,\r
431 IN UINTN ExTokenNumber\r
432 )\r
433{\r
434 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));\r
435}\r
436\r
437/**\r
438 Retrieves an 64-bit value for a given PCD token.\r
439\r
440 Retrieves the 64-bit value of a particular PCD token. \r
441 If the TokenNumber is invalid or the token space\r
442 specified by Guid does not exist, the results are \r
443 unpredictable.\r
444\r
445 @param[in] Guid The token space for the token number.\r
446 @param[in] ExTokenNumber The PCD token number. \r
447\r
448 @return The size 64-bit value for the PCD token.\r
449 \r
450**/\r
451UINT64\r
452EFIAPI\r
453DxePcdGet64Ex (\r
454 IN CONST EFI_GUID *Guid,\r
455 IN UINTN ExTokenNumber\r
456 )\r
457{\r
458 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));\r
459}\r
460\r
461/**\r
462 Retrieves a pointer to a value for a given PCD token.\r
463\r
464 Retrieves the current pointer to the buffer for a PCD token number. \r
465 Do not make any assumptions about the alignment of the pointer that \r
466 is returned by this function call. If the TokenNumber is invalid, \r
467 the results are unpredictable.\r
468\r
469 @param[in] Guid The token space for the token number.\r
470 @param[in] ExTokenNumber The PCD token number. \r
471\r
472 @return The pointer to the buffer to be retrived.\r
473 \r
474**/\r
475VOID *\r
476EFIAPI\r
477DxePcdGetPtrEx (\r
478 IN CONST EFI_GUID *Guid,\r
479 IN UINTN ExTokenNumber\r
480 )\r
481{\r
482 return ExGetWorker (Guid, ExTokenNumber, 0);\r
483}\r
484\r
485/**\r
486 Retrieves an Boolean value for a given PCD token.\r
487\r
488 Retrieves the Boolean value of a particular PCD token. \r
489 If the TokenNumber is invalid or the token space\r
490 specified by Guid does not exist, the results are \r
491 unpredictable.\r
492\r
493 @param[in] Guid The token space for the token number.\r
494 @param[in] ExTokenNumber The PCD token number. \r
495\r
496 @return The size Boolean value for the PCD token.\r
497 \r
498**/\r
499BOOLEAN\r
500EFIAPI\r
501DxePcdGetBoolEx (\r
502 IN CONST EFI_GUID *Guid,\r
503 IN UINTN ExTokenNumber\r
504 )\r
505{\r
506 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));\r
507}\r
508\r
509/**\r
510 Retrieves the size of the value for a given PCD token.\r
511\r
512 Retrieves the current size of a particular PCD token. \r
513 If the TokenNumber is invalid, the results are unpredictable.\r
514\r
515 @param[in] Guid The token space for the token number.\r
516 @param[in] ExTokenNumber The PCD token number. \r
517\r
518 @return The size of the value for the PCD token.\r
519 \r
520**/\r
521UINTN\r
522EFIAPI\r
523DxePcdGetSizeEx (\r
524 IN CONST EFI_GUID *Guid,\r
525 IN UINTN ExTokenNumber\r
526 )\r
527{\r
528 return DxePcdGetSize(GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber));\r
529}\r
530\r
531/**\r
532 Sets an 8-bit value for a given PCD token.\r
533\r
534 When the PCD service sets a value, it will check to ensure that the \r
535 size of the value being set is compatible with the Token's existing definition. \r
536 If it is not, an error will be returned.\r
537\r
538 @param[in] TokenNumber The PCD token number. \r
539 @param[in] Value The value to set for the PCD token.\r
540\r
541 @retval EFI_SUCCESS Procedure returned successfully.\r
542 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
543 being set was incompatible with a call to this function. \r
544 Use GetSize() to retrieve the size of the target data.\r
545 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
546 \r
547**/\r
548EFI_STATUS\r
549EFIAPI\r
550DxePcdSet8 (\r
551 IN UINTN TokenNumber,\r
552 IN UINT8 Value\r
553 )\r
554{\r
555 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
556}\r
557\r
558/**\r
559 Sets an 16-bit value for a given PCD token.\r
560\r
561 When the PCD service sets a value, it will check to ensure that the \r
562 size of the value being set is compatible with the Token's existing definition. \r
563 If it is not, an error will be returned.\r
564\r
565 @param[in] TokenNumber The PCD token number. \r
566 @param[in] Value The value to set for the PCD token.\r
567\r
568 @retval EFI_SUCCESS Procedure returned successfully.\r
569 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
570 being set was incompatible with a call to this function. \r
571 Use GetSize() to retrieve the size of the target data.\r
572 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
573 \r
574**/\r
575EFI_STATUS\r
576EFIAPI\r
577DxePcdSet16 (\r
578 IN UINTN TokenNumber,\r
579 IN UINT16 Value\r
580 )\r
581{\r
582 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
583}\r
584\r
585/**\r
586 Sets an 32-bit value for a given PCD token.\r
587\r
588 When the PCD service sets a value, it will check to ensure that the \r
589 size of the value being set is compatible with the Token's existing definition. \r
590 If it is not, an error will be returned.\r
591\r
592 @param[in] TokenNumber The PCD token number. \r
593 @param[in] Value The value to set for the PCD token.\r
594\r
595 @retval EFI_SUCCESS Procedure returned successfully.\r
596 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
597 being set was incompatible with a call to this function. \r
598 Use GetSize() to retrieve the size of the target data.\r
599 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
600 \r
601**/\r
602EFI_STATUS\r
603EFIAPI\r
604DxePcdSet32 (\r
605 IN UINTN TokenNumber,\r
606 IN UINT32 Value\r
607 )\r
608{\r
609 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
610}\r
611\r
612/**\r
613 Sets an 64-bit value for a given PCD token.\r
614\r
615 When the PCD service sets a value, it will check to ensure that the \r
616 size of the value being set is compatible with the Token's existing definition. \r
617 If it is not, an error will be returned.\r
618\r
619 @param[in] TokenNumber The PCD token number. \r
620 @param[in] Value The value to set for the PCD token.\r
621\r
622 @retval EFI_SUCCESS Procedure returned successfully.\r
623 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
624 being set was incompatible with a call to this function. \r
625 Use GetSize() to retrieve the size of the target data.\r
626 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
627 \r
628**/\r
629EFI_STATUS\r
630EFIAPI\r
631DxePcdSet64 (\r
632 IN UINTN TokenNumber,\r
633 IN UINT64 Value\r
634 )\r
635{\r
636 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
637}\r
638\r
639/**\r
640 Sets a value of a specified size for a given PCD token.\r
641\r
642 When the PCD service sets a value, it will check to ensure that the \r
643 size of the value being set is compatible with the Token's existing definition. \r
644 If it is not, an error will be returned.\r
645\r
646 @param[in] TokenNumber The PCD token number. \r
647 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
648 On input, if the SizeOfValue is greater than the maximum size supported \r
649 for this TokenNumber then the output value of SizeOfValue will reflect \r
650 the maximum size supported for this TokenNumber.\r
651 @param[in] Buffer The buffer to set for the PCD token.\r
652\r
653 @retval EFI_SUCCESS Procedure returned successfully.\r
654 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
655 being set was incompatible with a call to this function. \r
656 Use GetSize() to retrieve the size of the target data.\r
657 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
658 \r
659**/\r
660EFI_STATUS\r
661EFIAPI\r
662DxePcdSetPtr (\r
663 IN UINTN TokenNumber,\r
664 IN OUT UINTN *SizeOfBuffer,\r
665 IN VOID *Buffer\r
666 )\r
667{\r
668 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
669}\r
670\r
671/**\r
672 Sets an Boolean value for a given PCD token.\r
673\r
674 When the PCD service sets a value, it will check to ensure that the \r
675 size of the value being set is compatible with the Token's existing definition. \r
676 If it is not, an error will be returned.\r
677\r
678 @param[in] TokenNumber The PCD token number. \r
679 @param[in] Value The value to set for the PCD token.\r
680\r
681 @retval EFI_SUCCESS Procedure returned successfully.\r
682 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
683 being set was incompatible with a call to this function. \r
684 Use GetSize() to retrieve the size of the target data.\r
685 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
686 \r
687**/\r
688EFI_STATUS\r
689EFIAPI\r
690DxePcdSetBool (\r
691 IN UINTN TokenNumber,\r
692 IN BOOLEAN Value\r
693 )\r
694{\r
695 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
696}\r
697\r
698/**\r
699 Sets an 8-bit value for a given PCD token.\r
700\r
701 When the PCD service sets a value, it will check to ensure that the \r
702 size of the value being set is compatible with the Token's existing definition. \r
703 If it is not, an error will be returned.\r
704\r
705 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
706 @param[in] ExTokenNumber The PCD token number. \r
707 @param[in] Value The value to set for the PCD token.\r
708\r
709 @retval EFI_SUCCESS Procedure returned successfully.\r
710 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
711 being set was incompatible with a call to this function. \r
712 Use GetSize() to retrieve the size of the target data.\r
713 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
714 \r
715**/\r
716EFI_STATUS\r
717EFIAPI\r
718DxePcdSet8Ex (\r
719 IN CONST EFI_GUID *Guid,\r
720 IN UINTN ExTokenNumber,\r
721 IN UINT8 Value\r
722 )\r
723{\r
724 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
725}\r
726\r
727/**\r
728 Sets an 16-bit value for a given PCD token.\r
729\r
730 When the PCD service sets a value, it will check to ensure that the \r
731 size of the value being set is compatible with the Token's existing definition. \r
732 If it is not, an error will be returned.\r
733\r
734 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
735 @param[in] ExTokenNumber The PCD token number. \r
736 @param[in] Value The value to set for the PCD token.\r
737\r
738 @retval EFI_SUCCESS Procedure returned successfully.\r
739 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
740 being set was incompatible with a call to this function. \r
741 Use GetSize() to retrieve the size of the target data.\r
742 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
743 \r
744**/\r
745EFI_STATUS\r
746EFIAPI\r
747DxePcdSet16Ex (\r
748 IN CONST EFI_GUID *Guid,\r
749 IN UINTN ExTokenNumber,\r
750 IN UINT16 Value\r
751 )\r
752{\r
753 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
754}\r
755\r
756/**\r
757 Sets an 32-bit value for a given PCD token.\r
758\r
759 When the PCD service sets a value, it will check to ensure that the \r
760 size of the value being set is compatible with the Token's existing definition. \r
761 If it is not, an error will be returned.\r
762\r
763 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
764 @param[in] ExTokenNumber The PCD token number. \r
765 @param[in] Value The value to set for the PCD token.\r
766\r
767 @retval EFI_SUCCESS Procedure returned successfully.\r
768 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
769 being set was incompatible with a call to this function. \r
770 Use GetSize() to retrieve the size of the target data.\r
771 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
772 \r
773**/\r
774EFI_STATUS\r
775EFIAPI\r
776DxePcdSet32Ex (\r
777 IN CONST EFI_GUID *Guid,\r
778 IN UINTN ExTokenNumber,\r
779 IN UINT32 Value\r
780 )\r
781{\r
782 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
783}\r
784\r
785/**\r
786 Sets an 64-bit value for a given PCD token.\r
787\r
788 When the PCD service sets a value, it will check to ensure that the \r
789 size of the value being set is compatible with the Token's existing definition. \r
790 If it is not, an error will be returned.\r
791\r
792 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
793 @param[in] ExTokenNumber The PCD token number. \r
794 @param[in] Value The value to set for the PCD token.\r
795\r
796 @retval EFI_SUCCESS Procedure returned successfully.\r
797 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
798 being set was incompatible with a call to this function. \r
799 Use GetSize() to retrieve the size of the target data.\r
800 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
801 \r
802**/\r
803EFI_STATUS\r
804EFIAPI\r
805DxePcdSet64Ex (\r
806 IN CONST EFI_GUID *Guid,\r
807 IN UINTN ExTokenNumber,\r
808 IN UINT64 Value\r
809 )\r
810{\r
811 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
812}\r
813\r
814/**\r
815 Sets a value of a specified size for a given PCD token.\r
816\r
817 When the PCD service sets a value, it will check to ensure that the \r
818 size of the value being set is compatible with the Token's existing definition. \r
819 If it is not, an error will be returned.\r
820\r
821 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
822 @param[in] ExTokenNumber The PCD token number. \r
823 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
824 On input, if the SizeOfValue is greater than the maximum size supported \r
825 for this TokenNumber then the output value of SizeOfValue will reflect \r
826 the maximum size supported for this TokenNumber.\r
827 @param[in] Buffer The buffer to set for the PCD token.\r
828\r
829 @retval EFI_SUCCESS Procedure returned successfully.\r
830 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
831 being set was incompatible with a call to this function. \r
832 Use GetSize() to retrieve the size of the target data.\r
833 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
834 \r
835**/\r
836EFI_STATUS\r
837EFIAPI\r
838DxePcdSetPtrEx (\r
839 IN CONST EFI_GUID *Guid,\r
840 IN UINTN ExTokenNumber,\r
841 IN OUT UINTN *SizeOfBuffer,\r
842 IN VOID *Buffer\r
843 )\r
844{\r
845 return ExSetWorker(ExTokenNumber, Guid, Buffer, SizeOfBuffer, TRUE);\r
846}\r
847\r
848/**\r
849 Sets an Boolean value for a given PCD token.\r
850\r
851 When the PCD service sets a value, it will check to ensure that the \r
852 size of the value being set is compatible with the Token's existing definition. \r
853 If it is not, an error will be returned.\r
854\r
855 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
856 @param[in] ExTokenNumber The PCD token number. \r
857 @param[in] Value The value to set for the PCD token.\r
858\r
859 @retval EFI_SUCCESS Procedure returned successfully.\r
860 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
861 being set was incompatible with a call to this function. \r
862 Use GetSize() to retrieve the size of the target data.\r
863 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
864 \r
865**/\r
866EFI_STATUS\r
867EFIAPI\r
868DxePcdSetBoolEx (\r
869 IN CONST EFI_GUID *Guid,\r
870 IN UINTN ExTokenNumber,\r
871 IN BOOLEAN Value\r
872 )\r
873{\r
874 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
875}\r
876\r
877/**\r
878 Specifies a function to be called anytime the value of a designated token is changed.\r
879\r
880 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
881 @param[in] TokenNumber The PCD token number. \r
882 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
883\r
884 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
885 for the CallBackToken requested.\r
886 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
887\r
888**/\r
889EFI_STATUS\r
890EFIAPI\r
891DxeRegisterCallBackOnSet (\r
892 IN CONST EFI_GUID *Guid, OPTIONAL\r
893 IN UINTN TokenNumber,\r
894 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
895 )\r
896{\r
897 EFI_STATUS Status;\r
898 \r
899 if (CallBackFunction == NULL) {\r
900 return EFI_INVALID_PARAMETER;\r
901 }\r
902 //\r
903 // Aquire lock to prevent reentrance from TPL_CALLBACK level\r
904 //\r
905 EfiAcquireLock (&mPcdDatabaseLock);\r
906\r
907 Status = DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
908\r
909 EfiReleaseLock (&mPcdDatabaseLock);\r
910 \r
911 return Status;\r
912}\r
913\r
914/**\r
915 Cancels a previously set callback function for a particular PCD token number.\r
916\r
917 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
918 @param[in] TokenNumber The PCD token number. \r
919 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
920\r
921 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
922 for the CallBackToken requested.\r
923 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
924\r
925**/\r
926EFI_STATUS\r
927EFIAPI\r
928DxeUnRegisterCallBackOnSet (\r
929 IN CONST EFI_GUID *Guid, OPTIONAL\r
930 IN UINTN TokenNumber,\r
931 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
932 )\r
933{\r
934 EFI_STATUS Status;\r
935 \r
936 if (CallBackFunction == NULL) {\r
937 return EFI_INVALID_PARAMETER;\r
938 }\r
939\r
940 //\r
941 // Aquire lock to prevent reentrance from TPL_CALLBACK level\r
942 //\r
943 EfiAcquireLock (&mPcdDatabaseLock);\r
944 \r
945 Status = DxeUnRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
946\r
947 EfiReleaseLock (&mPcdDatabaseLock);\r
948 \r
949 return Status;\r
950}\r
951\r
952/**\r
953 Retrieves the next valid token number in a given namespace. \r
954 \r
955 This is useful since the PCD infrastructure contains a sparse list of token numbers, \r
956 and one cannot a priori know what token numbers are valid in the database. \r
957 \r
958 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned. \r
959 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned. \r
960 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned. \r
961 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned. \r
962 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid. \r
963 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned. \r
964 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned. \r
965 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
966\r
967\r
968 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token. \r
969 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is \r
970 being made to retrieve tokens from the default token space.\r
971 @param[in, out] TokenNumber \r
972 A pointer to the PCD token number to use to find the subsequent token number. \r
973\r
974 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number \r
975 is already the last valid token number in the PCD database. \r
976 In the later case, *TokenNumber is updated with the value of 0.\r
977 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.\r
978\r
979**/\r
980EFI_STATUS\r
981EFIAPI\r
982DxePcdGetNextToken (\r
983 IN CONST EFI_GUID *Guid, OPTIONAL\r
984 IN OUT UINTN *TokenNumber\r
985 )\r
986{\r
987 EFI_STATUS Status;\r
988 BOOLEAN PeiExMapTableEmpty;\r
989 BOOLEAN DxeExMapTableEmpty;\r
990\r
991 Status = EFI_NOT_FOUND;\r
992 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;\r
993 DxeExMapTableEmpty = DXE_EXMAP_TABLE_EMPTY;\r
994\r
995 //\r
996 // Scan the local token space\r
997 //\r
998 if (Guid == NULL) {\r
999 // EBC compiler is very choosy. It may report warning about comparison\r
1000 // between UINTN and 0 . So we add 1 in each size of the \r
1001 // comparison.\r
1002 if (((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) && (*TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1)) ||\r
1003 ((*TokenNumber + 1 > (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER + 1)))) {\r
1004 return EFI_NOT_FOUND;\r
1005 }\r
1006 \r
1007 (*TokenNumber)++;\r
1008 if ((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) &&\r
1009 (*TokenNumber <= PEI_LOCAL_TOKEN_NUMBER)) {\r
1010 //\r
1011 // The first Non-Ex type Token Number for DXE PCD \r
1012 // database is PEI_LOCAL_TOKEN_NUMBER\r
1013 //\r
1014 *TokenNumber = PEI_LOCAL_TOKEN_NUMBER;\r
1015 } else if (*TokenNumber + 1 > DXE_NEX_TOKEN_NUMBER + PEI_LOCAL_TOKEN_NUMBER + 1) {\r
1016 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
1017 }\r
1018 return EFI_SUCCESS;\r
1019 }\r
1020\r
1021 if (PeiExMapTableEmpty && DxeExMapTableEmpty) {\r
1022 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
1023 return EFI_NOT_FOUND;\r
1024 }\r
1025\r
1026 if (!PeiExMapTableEmpty) {\r
1027 Status = ExGetNextTokeNumber (\r
1028 Guid,\r
1029 TokenNumber,\r
1030 mPcdDatabase->PeiDb.Init.GuidTable,\r
1031 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),\r
1032 mPcdDatabase->PeiDb.Init.ExMapTable,\r
1033 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)\r
1034 );\r
1035 }\r
1036\r
1037 if (Status == EFI_SUCCESS) {\r
1038 return Status;\r
1039 }\r
1040\r
1041 if (!DxeExMapTableEmpty) {\r
1042 Status = ExGetNextTokeNumber (\r
1043 Guid,\r
1044 TokenNumber,\r
1045 mPcdDatabase->DxeDb.Init.GuidTable,\r
1046 sizeof(mPcdDatabase->DxeDb.Init.GuidTable),\r
1047 mPcdDatabase->DxeDb.Init.ExMapTable,\r
1048 sizeof(mPcdDatabase->DxeDb.Init.ExMapTable)\r
1049 );\r
1050 }\r
1051\r
1052 return Status;\r
1053}\r
1054\r
1055/**\r
1056 Get all token space guid table which is different with given token space guid.\r
1057\r
1058 @param ExMapTableSize The size of guid table\r
1059 @param ExMapTable Token space guid table that want to be scaned.\r
1060 @param GuidTable Guid table\r
1061\r
1062 @return all token space guid table which is different with given token space guid.\r
1063\r
1064**/\r
1065EFI_GUID **\r
1066GetDistinctTokenSpace (\r
1067 IN OUT UINTN *ExMapTableSize,\r
1068 IN DYNAMICEX_MAPPING *ExMapTable,\r
1069 IN EFI_GUID *GuidTable\r
1070 )\r
1071{\r
1072 EFI_GUID **DistinctTokenSpace;\r
1073 UINTN OldGuidIndex;\r
1074 UINTN TsIdx;\r
1075 UINTN Idx;\r
1076\r
1077\r
1078 DistinctTokenSpace = AllocateZeroPool (*ExMapTableSize * sizeof (EFI_GUID *));\r
1079 ASSERT (DistinctTokenSpace != NULL);\r
1080\r
1081 TsIdx = 0;\r
1082 OldGuidIndex = ExMapTable[0].ExGuidIndex;\r
1083 DistinctTokenSpace[TsIdx] = &GuidTable[OldGuidIndex];\r
1084 for (Idx = 1; Idx < *ExMapTableSize; Idx++) {\r
1085 if (ExMapTable[Idx].ExGuidIndex != OldGuidIndex) {\r
1086 OldGuidIndex = ExMapTable[Idx].ExGuidIndex;\r
1087 DistinctTokenSpace[++TsIdx] = &GuidTable[OldGuidIndex];\r
1088 }\r
1089 }\r
1090\r
1091 //\r
1092 // The total number of Distinct Token Space\r
1093 // is TsIdx + 1 because we use TsIdx as a index\r
1094 // to the DistinctTokenSpace[]\r
1095 //\r
1096 *ExMapTableSize = TsIdx + 1;\r
1097 return DistinctTokenSpace;\r
1098 \r
1099}\r
1100 \r
1101/**\r
1102 Get next token space in PCD database according to given token space guid.\r
1103 \r
1104 @param Guid Given token space guid. If NULL, then Guid will be set to \r
1105 the first PCD token space in PCD database, If not NULL, then\r
1106 Guid will be set to next PCD token space.\r
1107\r
1108 @retval EFI_UNSUPPORTED \r
1109 @retval EFI_NOT_FOUND If PCD database has no token space table or can not find given\r
1110 token space in PCD database.\r
1111 @retval EFI_SUCCESS Success to get next token space guid.\r
1112**/\r
1113EFI_STATUS\r
1114EFIAPI\r
1115DxePcdGetNextTokenSpace (\r
1116 IN OUT CONST EFI_GUID **Guid\r
1117 )\r
1118{\r
1119 UINTN Idx;\r
1120 UINTN Idx2;\r
1121 UINTN Idx3;\r
1122 UINTN PeiTokenSpaceTableSize;\r
1123 UINTN DxeTokenSpaceTableSize;\r
1124 EFI_GUID **PeiTokenSpaceTable;\r
1125 EFI_GUID **DxeTokenSpaceTable;\r
1126 BOOLEAN Match;\r
1127 BOOLEAN PeiExMapTableEmpty;\r
1128 BOOLEAN DxeExMapTableEmpty;\r
1129\r
1130 ASSERT (Guid != NULL);\r
1131 \r
1132 PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;\r
1133 DxeExMapTableEmpty = DXE_EXMAP_TABLE_EMPTY;\r
1134\r
1135 if (PeiExMapTableEmpty && DxeExMapTableEmpty) {\r
1136 if (*Guid != NULL) {\r
1137 return EFI_NOT_FOUND;\r
1138 } else {\r
1139 return EFI_SUCCESS;\r
1140 }\r
1141 }\r
1142 \r
1143 \r
1144 if (TmpTokenSpaceBuffer[0] == NULL) {\r
1145 PeiTokenSpaceTableSize = 0;\r
1146\r
1147 if (!PeiExMapTableEmpty) {\r
1148 PeiTokenSpaceTableSize = PEI_EXMAPPING_TABLE_SIZE;\r
1149 PeiTokenSpaceTable = GetDistinctTokenSpace (&PeiTokenSpaceTableSize,\r
1150 mPcdDatabase->PeiDb.Init.ExMapTable,\r
1151 mPcdDatabase->PeiDb.Init.GuidTable\r
1152 );\r
1153 CopyMem (TmpTokenSpaceBuffer, PeiTokenSpaceTable, sizeof (EFI_GUID*) * PeiTokenSpaceTableSize);\r
1154 }\r
1155\r
1156 if (!DxeExMapTableEmpty) {\r
1157 DxeTokenSpaceTableSize = DXE_EXMAPPING_TABLE_SIZE;\r
1158 DxeTokenSpaceTable = GetDistinctTokenSpace (&DxeTokenSpaceTableSize,\r
1159 mPcdDatabase->DxeDb.Init.ExMapTable,\r
1160 mPcdDatabase->DxeDb.Init.GuidTable\r
1161 );\r
1162\r
1163 //\r
1164 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable\r
1165 //\r
1166 for (Idx2 = 0, Idx3 = PeiTokenSpaceTableSize; Idx2 < DxeTokenSpaceTableSize; Idx2++) {\r
1167 Match = FALSE;\r
1168 for (Idx = 0; Idx < PeiTokenSpaceTableSize; Idx++) {\r
1169 if (CompareGuid (TmpTokenSpaceBuffer[Idx], DxeTokenSpaceTable[Idx2])) {\r
1170 Match = TRUE;\r
1171 break;\r
1172 }\r
1173 }\r
1174 if (!Match) {\r
1175 TmpTokenSpaceBuffer[Idx3++] = DxeTokenSpaceTable[Idx2];\r
1176 }\r
1177 }\r
1178 }\r
1179 }\r
1180\r
1181 if (*Guid == NULL) {\r
1182 *Guid = TmpTokenSpaceBuffer[0];\r
1183 return EFI_SUCCESS;\r
1184 }\r
1185 \r
1186 for (Idx = 0; Idx < (PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE); Idx++) {\r
1187 if(CompareGuid (*Guid, TmpTokenSpaceBuffer[Idx])) {\r
1188 Idx++;\r
1189 *Guid = TmpTokenSpaceBuffer[Idx];\r
1190 return EFI_SUCCESS;\r
1191 }\r
1192 }\r
1193\r
1194 return EFI_NOT_FOUND;\r
1195}\r
1196\r
1197\r