Check in the Pcd service Driver/PEIM according to the new way of generating PCD Database
[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
100EFI_STATUS\r
101EFIAPI\r
102DxePcdSetSku (\r
52e1905d 103 IN UINTN SkuId\r
878ddf1f 104 )\r
105{\r
52e1905d 106 return gPcdDatabase->PeiDb.Init.SystemSkuId = (SKU_ID) SkuId;\r
878ddf1f 107}\r
108\r
109\r
110\r
111UINT8\r
112EFIAPI\r
113DxePcdGet8 (\r
52e1905d 114 IN UINTN TokenNumber\r
878ddf1f 115 )\r
116{\r
52e1905d 117 ASSERT (sizeof (UINT8) == DxePcdGetSize (TokenNumber));\r
118 \r
119 return *((UINT8 *) GetWorker (TokenNumber));\r
878ddf1f 120}\r
121\r
122\r
123\r
124UINT16\r
125EFIAPI\r
126DxePcdGet16 (\r
52e1905d 127 IN UINTN TokenNumber\r
878ddf1f 128 )\r
129{\r
52e1905d 130 ASSERT (sizeof (UINT16) == DxePcdGetSize (TokenNumber));\r
131 \r
132 return ReadUnaligned16 (GetWorker (TokenNumber));\r
878ddf1f 133}\r
134\r
135\r
136\r
137UINT32\r
138EFIAPI\r
139DxePcdGet32 (\r
52e1905d 140 IN UINTN TokenNumber\r
878ddf1f 141 )\r
142{\r
52e1905d 143 ASSERT (sizeof (UINT32) == DxePcdGetSize (TokenNumber));\r
144 \r
145 return ReadUnaligned32 (GetWorker (TokenNumber));\r
878ddf1f 146}\r
147\r
148\r
149\r
150UINT64\r
151EFIAPI\r
152DxePcdGet64 (\r
52e1905d 153 IN UINTN TokenNumber\r
878ddf1f 154 )\r
155{\r
52e1905d 156 ASSERT (sizeof (UINT64) == DxePcdGetSize (TokenNumber));\r
157 \r
158 return ReadUnaligned64(GetWorker (TokenNumber));\r
878ddf1f 159}\r
160\r
161\r
162\r
163VOID *\r
164EFIAPI\r
165DxePcdGetPtr (\r
52e1905d 166 IN UINTN TokenNumber\r
878ddf1f 167 )\r
168{\r
52e1905d 169 return GetWorker (TokenNumber);\r
878ddf1f 170}\r
171\r
172\r
173\r
174BOOLEAN\r
175EFIAPI\r
176DxePcdGetBool (\r
52e1905d 177 IN UINTN TokenNumber\r
878ddf1f 178 )\r
179{\r
52e1905d 180 ASSERT (sizeof (BOOLEAN) == DxePcdGetSize (TokenNumber));\r
181 \r
182 return *((BOOLEAN *) GetWorker (TokenNumber));\r
878ddf1f 183}\r
184\r
185\r
186\r
187UINTN\r
188EFIAPI\r
189DxePcdGetSize (\r
52e1905d 190 IN UINTN TokenNumber\r
878ddf1f 191 )\r
192{\r
52e1905d 193 UINT16 * SizeTable;\r
194\r
195 SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? gPcdDatabase->PeiDb.Init.SizeTable :\r
196 gPcdDatabase->DxeDb.Init.SizeTable;\r
197\r
198\r
199 TokenNumber = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TokenNumber : (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);\r
200\r
201 return SizeTable[TokenNumber];\r
878ddf1f 202}\r
203\r
204\r
205\r
206UINT8\r
207EFIAPI\r
208DxePcdGet8Ex (\r
52e1905d 209 IN CONST EFI_GUID *Guid,\r
210 IN UINTN ExTokenNumber\r
878ddf1f 211 )\r
212{\r
52e1905d 213 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));\r
878ddf1f 214}\r
215\r
216\r
217\r
218UINT16\r
219EFIAPI\r
220DxePcdGet16Ex (\r
221 IN CONST EFI_GUID *Guid,\r
52e1905d 222 IN UINTN ExTokenNumber\r
878ddf1f 223 )\r
224{\r
52e1905d 225 return *((UINT16 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));\r
878ddf1f 226}\r
227\r
228\r
229\r
230UINT32\r
231EFIAPI\r
232DxePcdGet32Ex (\r
233 IN CONST EFI_GUID *Guid,\r
52e1905d 234 IN UINTN ExTokenNumber\r
878ddf1f 235 )\r
236{\r
52e1905d 237 return *((UINT32 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));\r
878ddf1f 238}\r
239\r
240\r
241\r
242UINT64\r
243EFIAPI\r
244DxePcdGet64Ex (\r
245 IN CONST EFI_GUID *Guid,\r
52e1905d 246 IN UINTN ExTokenNumber\r
878ddf1f 247 )\r
248{\r
52e1905d 249 //\r
250 // BugBug: Must be changed to ReadUnaligned64\r
251 //\r
252 return *((UINT64 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));\r
878ddf1f 253}\r
254\r
255\r
256\r
257VOID *\r
258EFIAPI\r
259DxePcdGetPtrEx (\r
260 IN CONST EFI_GUID *Guid,\r
52e1905d 261 IN UINTN ExTokenNumber\r
878ddf1f 262 )\r
263{\r
52e1905d 264 return ExGetWorker (Guid, ExTokenNumber, 0);\r
878ddf1f 265}\r
266\r
267\r
268\r
269BOOLEAN\r
270EFIAPI\r
271DxePcdGetBoolEx (\r
272 IN CONST EFI_GUID *Guid,\r
52e1905d 273 IN UINTN ExTokenNumber\r
878ddf1f 274 )\r
275{\r
52e1905d 276 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));\r
878ddf1f 277}\r
278\r
279\r
280\r
281UINTN\r
282EFIAPI\r
283DxePcdGetSizeEx (\r
284 IN CONST EFI_GUID *Guid,\r
52e1905d 285 IN UINTN ExTokenNumber\r
878ddf1f 286 )\r
287{\r
52e1905d 288 EX_PCD_ENTRY_ATTRIBUTE Attr;\r
289 \r
290 GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);\r
291\r
292 return Attr.Size;\r
878ddf1f 293}\r
294\r
295\r
296\r
297EFI_STATUS\r
298EFIAPI\r
299DxePcdSet8 (\r
52e1905d 300 IN UINTN TokenNumber,\r
301 IN UINT8 Value\r
878ddf1f 302 )\r
303{\r
52e1905d 304 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 305}\r
306\r
307\r
308\r
309EFI_STATUS\r
310EFIAPI\r
311DxePcdSet16 (\r
52e1905d 312 IN UINTN TokenNumber,\r
878ddf1f 313 IN UINT16 Value\r
314 )\r
315{\r
52e1905d 316 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 317}\r
318\r
319\r
320\r
321EFI_STATUS\r
322EFIAPI\r
323DxePcdSet32 (\r
52e1905d 324 IN UINTN TokenNumber,\r
878ddf1f 325 IN UINT32 Value\r
326 )\r
327{\r
52e1905d 328 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 329}\r
330\r
331\r
332\r
333EFI_STATUS\r
334EFIAPI\r
335DxePcdSet64 (\r
52e1905d 336 IN UINTN TokenNumber,\r
337 IN UINT64 Value\r
878ddf1f 338 )\r
339{\r
52e1905d 340 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 341}\r
342\r
343\r
344\r
345EFI_STATUS\r
346EFIAPI\r
347DxePcdSetPtr (\r
52e1905d 348 IN UINTN TokenNumber,\r
349 IN CONST VOID *Value\r
878ddf1f 350 )\r
351{\r
52e1905d 352 //\r
353 // BugBug, please change the Size to Input size when sync with spec\r
354 //\r
355 //ASSERT (sizeof (Value) == DxePcdGetSize (TokenNumber));\r
356\r
357 return SetWorker (TokenNumber, (VOID *)Value, DxePcdGetSize (TokenNumber), TRUE);\r
878ddf1f 358}\r
359\r
360\r
361\r
362EFI_STATUS\r
363EFIAPI\r
364DxePcdSetBool (\r
52e1905d 365 IN UINTN TokenNumber,\r
366 IN BOOLEAN Value\r
878ddf1f 367 )\r
368{\r
52e1905d 369 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 370}\r
371\r
372\r
373\r
374EFI_STATUS\r
375EFIAPI\r
376DxePcdSet8Ex (\r
377 IN CONST EFI_GUID *Guid,\r
52e1905d 378 IN UINTN ExTokenNumber,\r
379 IN UINT8 Value\r
878ddf1f 380 )\r
381{\r
52e1905d 382 return ExSetWorker(\r
383 ExTokenNumber, \r
384 Guid,\r
385 &Value, \r
386 sizeof (Value), \r
387 FALSE\r
388 );\r
878ddf1f 389}\r
390\r
391\r
392\r
393EFI_STATUS\r
394EFIAPI\r
395DxePcdSet16Ex (\r
396 IN CONST EFI_GUID *Guid,\r
52e1905d 397 IN UINTN ExTokenNumber,\r
878ddf1f 398 IN UINT16 Value\r
399 )\r
400{\r
52e1905d 401 return ExSetWorker(\r
402 ExTokenNumber, \r
403 Guid,\r
404 &Value, \r
405 sizeof (Value), \r
406 FALSE\r
407 );\r
878ddf1f 408}\r
409\r
410\r
411\r
412EFI_STATUS\r
413EFIAPI\r
414DxePcdSet32Ex (\r
415 IN CONST EFI_GUID *Guid,\r
52e1905d 416 IN UINTN ExTokenNumber,\r
878ddf1f 417 IN UINT32 Value\r
418 )\r
419{\r
52e1905d 420 return ExSetWorker(\r
421 ExTokenNumber, \r
422 Guid,\r
423 &Value, \r
424 sizeof (Value), \r
425 FALSE\r
426 );\r
878ddf1f 427}\r
428\r
429\r
430\r
431EFI_STATUS\r
432EFIAPI\r
433DxePcdSet64Ex (\r
434 IN CONST EFI_GUID *Guid,\r
52e1905d 435 IN UINTN ExTokenNumber,\r
878ddf1f 436 IN UINT64 Value\r
437 )\r
438{\r
52e1905d 439 return ExSetWorker(\r
440 ExTokenNumber, \r
441 Guid,\r
442 &Value, \r
443 sizeof (Value), \r
444 FALSE\r
445 );\r
878ddf1f 446}\r
447\r
448\r
449\r
450EFI_STATUS\r
451EFIAPI\r
452DxePcdSetPtrEx (\r
453 IN CONST EFI_GUID *Guid,\r
52e1905d 454 IN UINTN ExTokenNumber,\r
878ddf1f 455 IN CONST VOID *Value\r
456 )\r
457{\r
52e1905d 458 return ExSetWorker(\r
459 ExTokenNumber, \r
460 Guid,\r
461 (VOID *) Value, \r
462 sizeof (Value), \r
463 TRUE\r
464 );\r
878ddf1f 465}\r
466\r
467\r
468\r
469EFI_STATUS\r
470EFIAPI\r
471DxePcdSetBoolEx (\r
472 IN CONST EFI_GUID *Guid,\r
52e1905d 473 IN UINTN ExTokenNumber,\r
878ddf1f 474 IN BOOLEAN Value\r
475 )\r
476{\r
52e1905d 477 return ExSetWorker(\r
478 ExTokenNumber, \r
479 Guid,\r
480 &Value, \r
481 sizeof (Value), \r
482 TRUE\r
483 );\r
878ddf1f 484}\r
485\r
486\r
487\r
488\r
489EFI_STATUS\r
490EFIAPI\r
491PcdRegisterCallBackOnSet (\r
492 IN UINTN TokenNumber,\r
493 IN CONST EFI_GUID *Guid, OPTIONAL\r
494 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
495 )\r
496{\r
497 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, TRUE);\r
498}\r
499\r
500\r
501\r
502EFI_STATUS\r
503EFIAPI\r
504PcdUnRegisterCallBackOnSet (\r
505 IN UINTN TokenNumber,\r
506 IN CONST EFI_GUID *Guid, OPTIONAL\r
507 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
508 )\r
509{\r
510 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, FALSE);\r
511}\r
512\r
513\r
514\r
515EFI_STATUS\r
516EFIAPI\r
517DxePcdGetNextToken (\r
518 IN CONST EFI_GUID *Guid, OPTIONAL\r
519 IN OUT UINTN *TokenNumber\r
520 )\r
521{\r
522 return DxeGetNextTokenWorker (TokenNumber, Guid);\r
523}\r
524\r