Add in GetNextToken and Register Callback Function funtionality for DXE Driver.
[mirror_edk2.git] / EdkModulePkg / Universal / PCD / Dxe / Pcd.c
CommitLineData
878ddf1f 1/** @file\r
2PCD DXE driver\r
3\r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13\r
14Module Name: Pcd.c\r
15\r
16**/\r
17\r
878ddf1f 18#include "Service.h"\r
19\r
20\r
21PCD_PROTOCOL mPcdInstance = {\r
22 DxePcdSetSku,\r
23\r
24 DxePcdGet8,\r
25 DxePcdGet16,\r
26 DxePcdGet32,\r
27 DxePcdGet64,\r
28 DxePcdGetPtr,\r
29 DxePcdGetBool,\r
30 DxePcdGetSize,\r
31\r
32 DxePcdGet8Ex,\r
33 DxePcdGet16Ex,\r
34 DxePcdGet32Ex,\r
35 DxePcdGet64Ex,\r
36 DxePcdGetPtrEx,\r
37 DxePcdGetBoolEx,\r
38 DxePcdGetSizeEx,\r
39\r
40 DxePcdSet8,\r
41 DxePcdSet16,\r
42 DxePcdSet32,\r
43 DxePcdSet64,\r
44 DxePcdSetPtr,\r
45 DxePcdSetBool,\r
46\r
47 DxePcdSet8Ex,\r
48 DxePcdSet16Ex,\r
49 DxePcdSet32Ex,\r
50 DxePcdSet64Ex,\r
51 DxePcdSetPtrEx,\r
52 DxePcdSetBoolEx,\r
53\r
4c114006 54 DxeRegisterCallBackOnSet,\r
55 DxeUnRegisterCallBackOnSet,\r
878ddf1f 56 DxePcdGetNextToken\r
57};\r
58\r
59\r
60//\r
61// Static global to reduce the code size\r
62//\r
63static EFI_HANDLE NewHandle = NULL;\r
64\r
65EFI_STATUS\r
66EFIAPI\r
67PcdDxeInit (\r
68 IN EFI_HANDLE ImageHandle,\r
69 IN EFI_SYSTEM_TABLE *SystemTable\r
70 )\r
71{\r
52e1905d 72 EFI_STATUS Status;\r
73\r
74 //\r
75 // Make sure the Pcd Protocol is not already installed in the system\r
76 //\r
77 \r
78 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gPcdProtocolGuid);\r
878ddf1f 79 \r
52e1905d 80 BuildPcdDxeDataBase ();\r
81\r
82 //\r
83 // BugBug Check if PcdDatabase is already installed.\r
84 //\r
878ddf1f 85 \r
86 Status = gBS->InstallProtocolInterface (\r
87 &NewHandle,\r
88 &gPcdProtocolGuid,\r
89 EFI_NATIVE_INTERFACE,\r
90 &mPcdInstance\r
91 );\r
92\r
93 ASSERT_EFI_ERROR (Status);\r
94\r
95 return EFI_SUCCESS;\r
96\r
97}\r
98\r
99\r
00b7af13 100VOID\r
878ddf1f 101EFIAPI\r
102DxePcdSetSku (\r
00b7af13 103 IN SKU_ID SkuId\r
878ddf1f 104 )\r
105{\r
4c114006 106 mPcdDatabase->PeiDb.Init.SystemSkuId = SkuId;\r
00b7af13 107 \r
108 return;\r
878ddf1f 109}\r
110\r
111\r
112\r
113UINT8\r
114EFIAPI\r
115DxePcdGet8 (\r
4c114006 116 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 117 )\r
118{\r
52e1905d 119 ASSERT (sizeof (UINT8) == DxePcdGetSize (TokenNumber));\r
120 \r
121 return *((UINT8 *) GetWorker (TokenNumber));\r
878ddf1f 122}\r
123\r
124\r
125\r
126UINT16\r
127EFIAPI\r
128DxePcdGet16 (\r
4c114006 129 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 130 )\r
131{\r
52e1905d 132 ASSERT (sizeof (UINT16) == DxePcdGetSize (TokenNumber));\r
133 \r
134 return ReadUnaligned16 (GetWorker (TokenNumber));\r
878ddf1f 135}\r
136\r
137\r
138\r
139UINT32\r
140EFIAPI\r
141DxePcdGet32 (\r
4c114006 142 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 143 )\r
144{\r
52e1905d 145 ASSERT (sizeof (UINT32) == DxePcdGetSize (TokenNumber));\r
146 \r
147 return ReadUnaligned32 (GetWorker (TokenNumber));\r
878ddf1f 148}\r
149\r
150\r
151\r
152UINT64\r
153EFIAPI\r
154DxePcdGet64 (\r
4c114006 155 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 156 )\r
157{\r
52e1905d 158 ASSERT (sizeof (UINT64) == DxePcdGetSize (TokenNumber));\r
159 \r
160 return ReadUnaligned64(GetWorker (TokenNumber));\r
878ddf1f 161}\r
162\r
163\r
164\r
165VOID *\r
166EFIAPI\r
167DxePcdGetPtr (\r
4c114006 168 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 169 )\r
170{\r
52e1905d 171 return GetWorker (TokenNumber);\r
878ddf1f 172}\r
173\r
174\r
175\r
176BOOLEAN\r
177EFIAPI\r
178DxePcdGetBool (\r
4c114006 179 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 180 )\r
181{\r
52e1905d 182 ASSERT (sizeof (BOOLEAN) == DxePcdGetSize (TokenNumber));\r
183 \r
184 return *((BOOLEAN *) GetWorker (TokenNumber));\r
878ddf1f 185}\r
186\r
187\r
188\r
189UINTN\r
190EFIAPI\r
191DxePcdGetSize (\r
4c114006 192 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 193 )\r
194{\r
52e1905d 195 UINT16 * SizeTable;\r
196\r
4c114006 197 SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? mPcdDatabase->PeiDb.Init.SizeTable :\r
198 mPcdDatabase->DxeDb.Init.SizeTable;\r
52e1905d 199\r
200\r
201 TokenNumber = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TokenNumber : (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);\r
202\r
203 return SizeTable[TokenNumber];\r
878ddf1f 204}\r
205\r
206\r
207\r
208UINT8\r
209EFIAPI\r
210DxePcdGet8Ex (\r
52e1905d 211 IN CONST EFI_GUID *Guid,\r
4c114006 212 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 213 )\r
214{\r
52e1905d 215 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));\r
878ddf1f 216}\r
217\r
218\r
219\r
220UINT16\r
221EFIAPI\r
222DxePcdGet16Ex (\r
223 IN CONST EFI_GUID *Guid,\r
4c114006 224 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 225 )\r
226{\r
52e1905d 227 return *((UINT16 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));\r
878ddf1f 228}\r
229\r
230\r
231\r
232UINT32\r
233EFIAPI\r
234DxePcdGet32Ex (\r
235 IN CONST EFI_GUID *Guid,\r
4c114006 236 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 237 )\r
238{\r
52e1905d 239 return *((UINT32 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));\r
878ddf1f 240}\r
241\r
242\r
243\r
244UINT64\r
245EFIAPI\r
246DxePcdGet64Ex (\r
247 IN CONST EFI_GUID *Guid,\r
4c114006 248 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 249 )\r
250{\r
52e1905d 251 //\r
252 // BugBug: Must be changed to ReadUnaligned64\r
253 //\r
254 return *((UINT64 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));\r
878ddf1f 255}\r
256\r
257\r
258\r
259VOID *\r
260EFIAPI\r
261DxePcdGetPtrEx (\r
262 IN CONST EFI_GUID *Guid,\r
4c114006 263 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 264 )\r
265{\r
52e1905d 266 return ExGetWorker (Guid, ExTokenNumber, 0);\r
878ddf1f 267}\r
268\r
269\r
270\r
271BOOLEAN\r
272EFIAPI\r
273DxePcdGetBoolEx (\r
274 IN CONST EFI_GUID *Guid,\r
4c114006 275 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 276 )\r
277{\r
52e1905d 278 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));\r
878ddf1f 279}\r
280\r
281\r
282\r
283UINTN\r
284EFIAPI\r
285DxePcdGetSizeEx (\r
286 IN CONST EFI_GUID *Guid,\r
4c114006 287 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 288 )\r
289{\r
52e1905d 290 EX_PCD_ENTRY_ATTRIBUTE Attr;\r
291 \r
292 GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);\r
293\r
294 return Attr.Size;\r
878ddf1f 295}\r
296\r
297\r
298\r
299EFI_STATUS\r
300EFIAPI\r
301DxePcdSet8 (\r
4c114006 302 IN PCD_TOKEN_NUMBER TokenNumber,\r
52e1905d 303 IN UINT8 Value\r
878ddf1f 304 )\r
305{\r
52e1905d 306 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 307}\r
308\r
309\r
310\r
311EFI_STATUS\r
312EFIAPI\r
313DxePcdSet16 (\r
4c114006 314 IN PCD_TOKEN_NUMBER TokenNumber,\r
878ddf1f 315 IN UINT16 Value\r
316 )\r
317{\r
52e1905d 318 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 319}\r
320\r
321\r
322\r
323EFI_STATUS\r
324EFIAPI\r
325DxePcdSet32 (\r
4c114006 326 IN PCD_TOKEN_NUMBER TokenNumber,\r
878ddf1f 327 IN UINT32 Value\r
328 )\r
329{\r
52e1905d 330 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 331}\r
332\r
333\r
334\r
335EFI_STATUS\r
336EFIAPI\r
337DxePcdSet64 (\r
4c114006 338 IN PCD_TOKEN_NUMBER TokenNumber,\r
52e1905d 339 IN UINT64 Value\r
878ddf1f 340 )\r
341{\r
52e1905d 342 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 343}\r
344\r
345\r
346\r
347EFI_STATUS\r
348EFIAPI\r
349DxePcdSetPtr (\r
4c114006 350 IN PCD_TOKEN_NUMBER TokenNumber,\r
00b7af13 351 IN UINTN SizeOfBuffer,\r
352 IN VOID *Buffer\r
878ddf1f 353 )\r
354{\r
00b7af13 355 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
878ddf1f 356}\r
357\r
358\r
359\r
360EFI_STATUS\r
361EFIAPI\r
362DxePcdSetBool (\r
4c114006 363 IN PCD_TOKEN_NUMBER TokenNumber,\r
52e1905d 364 IN BOOLEAN Value\r
878ddf1f 365 )\r
366{\r
52e1905d 367 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 368}\r
369\r
370\r
371\r
372EFI_STATUS\r
373EFIAPI\r
374DxePcdSet8Ex (\r
4c114006 375 IN CONST EFI_GUID *Guid,\r
376 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
52e1905d 377 IN UINT8 Value\r
878ddf1f 378 )\r
379{\r
52e1905d 380 return ExSetWorker(\r
381 ExTokenNumber, \r
382 Guid,\r
383 &Value, \r
384 sizeof (Value), \r
385 FALSE\r
386 );\r
878ddf1f 387}\r
388\r
389\r
390\r
391EFI_STATUS\r
392EFIAPI\r
393DxePcdSet16Ex (\r
4c114006 394 IN CONST EFI_GUID *Guid,\r
395 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 396 IN UINT16 Value\r
397 )\r
398{\r
52e1905d 399 return ExSetWorker(\r
400 ExTokenNumber, \r
401 Guid,\r
402 &Value, \r
403 sizeof (Value), \r
404 FALSE\r
405 );\r
878ddf1f 406}\r
407\r
408\r
409\r
410EFI_STATUS\r
411EFIAPI\r
412DxePcdSet32Ex (\r
4c114006 413 IN CONST EFI_GUID *Guid,\r
414 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 415 IN UINT32 Value\r
416 )\r
417{\r
52e1905d 418 return ExSetWorker(\r
419 ExTokenNumber, \r
420 Guid,\r
421 &Value, \r
422 sizeof (Value), \r
423 FALSE\r
424 );\r
878ddf1f 425}\r
426\r
427\r
428\r
429EFI_STATUS\r
430EFIAPI\r
431DxePcdSet64Ex (\r
4c114006 432 IN CONST EFI_GUID *Guid,\r
433 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 434 IN UINT64 Value\r
435 )\r
436{\r
52e1905d 437 return ExSetWorker(\r
438 ExTokenNumber, \r
439 Guid,\r
440 &Value, \r
441 sizeof (Value), \r
442 FALSE\r
443 );\r
878ddf1f 444}\r
445\r
446\r
447\r
448EFI_STATUS\r
449EFIAPI\r
450DxePcdSetPtrEx (\r
00b7af13 451 IN CONST EFI_GUID *Guid,\r
4c114006 452 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
00b7af13 453 IN UINTN SizeOfBuffer,\r
454 IN VOID *Buffer\r
878ddf1f 455 )\r
456{\r
52e1905d 457 return ExSetWorker(\r
458 ExTokenNumber, \r
459 Guid,\r
00b7af13 460 Buffer, \r
461 SizeOfBuffer, \r
52e1905d 462 TRUE\r
463 );\r
878ddf1f 464}\r
465\r
466\r
467\r
468EFI_STATUS\r
469EFIAPI\r
470DxePcdSetBoolEx (\r
4c114006 471 IN CONST EFI_GUID *Guid,\r
472 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 473 IN BOOLEAN Value\r
474 )\r
475{\r
52e1905d 476 return ExSetWorker(\r
477 ExTokenNumber, \r
478 Guid,\r
479 &Value, \r
480 sizeof (Value), \r
481 TRUE\r
482 );\r
878ddf1f 483}\r
484\r
485\r
486\r
487\r
488EFI_STATUS\r
489EFIAPI\r
4c114006 490DxeRegisterCallBackOnSet (\r
491 IN PCD_TOKEN_NUMBER TokenNumber,\r
492 IN CONST EFI_GUID *Guid, OPTIONAL\r
878ddf1f 493 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
494 )\r
495{\r
4c114006 496 ASSERT (CallBackFunction != NULL);\r
497 \r
498 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 499}\r
500\r
501\r
502\r
503EFI_STATUS\r
504EFIAPI\r
4c114006 505DxeUnRegisterCallBackOnSet (\r
506 IN PCD_TOKEN_NUMBER TokenNumber,\r
507 IN CONST EFI_GUID *Guid, OPTIONAL\r
878ddf1f 508 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
509 )\r
510{\r
4c114006 511 ASSERT (CallBackFunction != NULL);\r
512 \r
513 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 514}\r
515\r
516\r
517\r
518EFI_STATUS\r
519EFIAPI\r
520DxePcdGetNextToken (\r
4c114006 521 IN CONST EFI_GUID *Guid, OPTIONAL\r
522 IN OUT PCD_TOKEN_NUMBER *TokenNumber\r
878ddf1f 523 )\r
524{\r
4c114006 525 PCD_TOKEN_NUMBER ExTokenNumber;\r
526 \r
527 //\r
528 // Scan the local token space\r
529 //\r
530 if (Guid == NULL) {\r
531 *TokenNumber++;\r
532 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
533 return EFI_SUCCESS;\r
534 } else {\r
535 if (*TokenNumber >= PEI_NEX_TOKEN_NUMBER &&\r
536 *TokenNumber < PEI_LOCAL_TOKEN_NUMBER) {\r
537 //\r
538 // The first Non-Ex type Token Number for DXE PCD \r
539 // database is PEI_LOCAL_TOKEN_NUMBER\r
540 //\r
541 *TokenNumber = PEI_LOCAL_TOKEN_NUMBER;\r
542 return EFI_SUCCESS;\r
543 } else if (*TokenNumber >= DXE_NEX_TOKEN_NUMBER + PEI_LOCAL_TOKEN_NUMBER) {\r
544 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
545 return EFI_SUCCESS;\r
546 }\r
547 }\r
548 }\r
549\r
550 if (PEI_EXMAP_TABLE_EMPTY && PEI_EXMAP_TABLE_EMPTY) {\r
551 *TokenNumber = (UINTN) PCD_INVALID_TOKEN_NUMBER;\r
552 return EFI_NOT_FOUND;\r
553 }\r
554\r
555 ExTokenNumber = *TokenNumber;\r
556 if (!PEI_EXMAP_TABLE_EMPTY) {\r
557 ExTokenNumber = ExGetNextTokeNumber (\r
558 Guid,\r
559 ExTokenNumber,\r
560 mPcdDatabase->PeiDb.Init.GuidTable,\r
561 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),\r
562 mPcdDatabase->PeiDb.Init.ExMapTable,\r
563 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)\r
564 );\r
565 }\r
566\r
567 if (!DXE_EXMAP_TABLE_EMPTY) {\r
568 ExTokenNumber = ExGetNextTokeNumber (\r
569 Guid,\r
570 ExTokenNumber,\r
571 mPcdDatabase->PeiDb.Init.GuidTable,\r
572 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),\r
573 mPcdDatabase->PeiDb.Init.ExMapTable,\r
574 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)\r
575 );\r
576 }\r
577\r
578 *TokenNumber = ExTokenNumber;\r
579\r
580 return EFI_SUCCESS;\r
878ddf1f 581}\r
582\r