Revise XML Schema to be valid.
[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
54 PcdRegisterCallBackOnSet,\r
55 PcdUnRegisterCallBackOnSet,\r
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
00b7af13 106 gPcdDatabase->PeiDb.Init.SystemSkuId = SkuId;\r
107 \r
108 return;\r
878ddf1f 109}\r
110\r
111\r
112\r
113UINT8\r
114EFIAPI\r
115DxePcdGet8 (\r
52e1905d 116 IN UINTN 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
52e1905d 129 IN UINTN 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
52e1905d 142 IN UINTN 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
52e1905d 155 IN UINTN 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
52e1905d 168 IN UINTN 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
52e1905d 179 IN UINTN 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
52e1905d 192 IN UINTN TokenNumber\r
878ddf1f 193 )\r
194{\r
52e1905d 195 UINT16 * SizeTable;\r
196\r
197 SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? gPcdDatabase->PeiDb.Init.SizeTable :\r
198 gPcdDatabase->DxeDb.Init.SizeTable;\r
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
212 IN UINTN 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
52e1905d 224 IN UINTN 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
52e1905d 236 IN UINTN 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
52e1905d 248 IN UINTN 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
52e1905d 263 IN UINTN 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
52e1905d 275 IN UINTN 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
52e1905d 287 IN UINTN 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
52e1905d 302 IN UINTN TokenNumber,\r
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
52e1905d 314 IN UINTN 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
52e1905d 326 IN UINTN 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
52e1905d 338 IN UINTN TokenNumber,\r
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
52e1905d 350 IN UINTN 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
52e1905d 363 IN UINTN TokenNumber,\r
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
375 IN CONST EFI_GUID *Guid,\r
52e1905d 376 IN UINTN ExTokenNumber,\r
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
394 IN CONST EFI_GUID *Guid,\r
52e1905d 395 IN UINTN 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
413 IN CONST EFI_GUID *Guid,\r
52e1905d 414 IN UINTN 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
432 IN CONST EFI_GUID *Guid,\r
52e1905d 433 IN UINTN 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
452 IN UINTN ExTokenNumber,\r
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
471 IN CONST EFI_GUID *Guid,\r
52e1905d 472 IN UINTN 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
490PcdRegisterCallBackOnSet (\r
491 IN UINTN TokenNumber,\r
492 IN CONST EFI_GUID *Guid, OPTIONAL\r
493 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
494 )\r
495{\r
496 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, TRUE);\r
497}\r
498\r
499\r
500\r
501EFI_STATUS\r
502EFIAPI\r
503PcdUnRegisterCallBackOnSet (\r
504 IN UINTN TokenNumber,\r
505 IN CONST EFI_GUID *Guid, OPTIONAL\r
506 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
507 )\r
508{\r
509 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, FALSE);\r
510}\r
511\r
512\r
513\r
514EFI_STATUS\r
515EFIAPI\r
516DxePcdGetNextToken (\r
517 IN CONST EFI_GUID *Guid, OPTIONAL\r
518 IN OUT UINTN *TokenNumber\r
519 )\r
520{\r
521 return DxeGetNextTokenWorker (TokenNumber, Guid);\r
522}\r
523\r