Try to clarify the gcc story a little bit.
[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
9d6d8b24 119 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
878ddf1f 120}\r
121\r
122\r
123\r
124UINT16\r
125EFIAPI\r
126DxePcdGet16 (\r
4c114006 127 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 128 )\r
129{\r
9d6d8b24 130 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
878ddf1f 131}\r
132\r
133\r
134\r
135UINT32\r
136EFIAPI\r
137DxePcdGet32 (\r
4c114006 138 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 139 )\r
140{\r
9d6d8b24 141 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
878ddf1f 142}\r
143\r
144\r
145\r
146UINT64\r
147EFIAPI\r
148DxePcdGet64 (\r
4c114006 149 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 150 )\r
151{\r
9d6d8b24 152 return ReadUnaligned64(GetWorker (TokenNumber, sizeof (UINT64)));\r
878ddf1f 153}\r
154\r
155\r
156\r
157VOID *\r
158EFIAPI\r
159DxePcdGetPtr (\r
4c114006 160 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 161 )\r
162{\r
9d6d8b24 163 return GetWorker (TokenNumber, 0);\r
878ddf1f 164}\r
165\r
166\r
167\r
168BOOLEAN\r
169EFIAPI\r
170DxePcdGetBool (\r
4c114006 171 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 172 )\r
173{\r
9d6d8b24 174 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
878ddf1f 175}\r
176\r
177\r
178\r
179UINTN\r
180EFIAPI\r
181DxePcdGetSize (\r
4c114006 182 IN PCD_TOKEN_NUMBER TokenNumber\r
878ddf1f 183 )\r
184{\r
52e1905d 185 UINT16 * SizeTable;\r
186\r
4c114006 187 SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? mPcdDatabase->PeiDb.Init.SizeTable :\r
188 mPcdDatabase->DxeDb.Init.SizeTable;\r
52e1905d 189\r
190\r
191 TokenNumber = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TokenNumber : (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);\r
192\r
193 return SizeTable[TokenNumber];\r
878ddf1f 194}\r
195\r
196\r
197\r
198UINT8\r
199EFIAPI\r
200DxePcdGet8Ex (\r
52e1905d 201 IN CONST EFI_GUID *Guid,\r
4c114006 202 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 203 )\r
204{\r
52e1905d 205 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));\r
878ddf1f 206}\r
207\r
208\r
209\r
210UINT16\r
211EFIAPI\r
212DxePcdGet16Ex (\r
213 IN CONST EFI_GUID *Guid,\r
4c114006 214 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 215 )\r
216{\r
9d6d8b24 217 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));\r
878ddf1f 218}\r
219\r
220\r
221\r
222UINT32\r
223EFIAPI\r
224DxePcdGet32Ex (\r
225 IN CONST EFI_GUID *Guid,\r
4c114006 226 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 227 )\r
228{\r
9d6d8b24 229 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));\r
878ddf1f 230}\r
231\r
232\r
233\r
234UINT64\r
235EFIAPI\r
236DxePcdGet64Ex (\r
237 IN CONST EFI_GUID *Guid,\r
4c114006 238 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 239 )\r
240{\r
9d6d8b24 241 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));\r
878ddf1f 242}\r
243\r
244\r
245\r
246VOID *\r
247EFIAPI\r
248DxePcdGetPtrEx (\r
249 IN CONST EFI_GUID *Guid,\r
4c114006 250 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 251 )\r
252{\r
52e1905d 253 return ExGetWorker (Guid, ExTokenNumber, 0);\r
878ddf1f 254}\r
255\r
256\r
257\r
258BOOLEAN\r
259EFIAPI\r
260DxePcdGetBoolEx (\r
261 IN CONST EFI_GUID *Guid,\r
4c114006 262 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 263 )\r
264{\r
52e1905d 265 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));\r
878ddf1f 266}\r
267\r
268\r
269\r
270UINTN\r
271EFIAPI\r
272DxePcdGetSizeEx (\r
273 IN CONST EFI_GUID *Guid,\r
4c114006 274 IN PCD_TOKEN_NUMBER ExTokenNumber\r
878ddf1f 275 )\r
276{\r
9d6d8b24 277 return DxePcdGetSize(GetExPcdTokenNumber (Guid, ExTokenNumber));\r
878ddf1f 278}\r
279\r
280\r
281\r
282EFI_STATUS\r
283EFIAPI\r
284DxePcdSet8 (\r
4c114006 285 IN PCD_TOKEN_NUMBER TokenNumber,\r
52e1905d 286 IN UINT8 Value\r
878ddf1f 287 )\r
288{\r
52e1905d 289 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 290}\r
291\r
292\r
293\r
294EFI_STATUS\r
295EFIAPI\r
296DxePcdSet16 (\r
4c114006 297 IN PCD_TOKEN_NUMBER TokenNumber,\r
878ddf1f 298 IN UINT16 Value\r
299 )\r
300{\r
52e1905d 301 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 302}\r
303\r
304\r
305\r
306EFI_STATUS\r
307EFIAPI\r
308DxePcdSet32 (\r
4c114006 309 IN PCD_TOKEN_NUMBER TokenNumber,\r
878ddf1f 310 IN UINT32 Value\r
311 )\r
312{\r
52e1905d 313 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 314}\r
315\r
316\r
317\r
318EFI_STATUS\r
319EFIAPI\r
320DxePcdSet64 (\r
4c114006 321 IN PCD_TOKEN_NUMBER TokenNumber,\r
52e1905d 322 IN UINT64 Value\r
878ddf1f 323 )\r
324{\r
52e1905d 325 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 326}\r
327\r
328\r
329\r
330EFI_STATUS\r
331EFIAPI\r
332DxePcdSetPtr (\r
4c114006 333 IN PCD_TOKEN_NUMBER TokenNumber,\r
00b7af13 334 IN UINTN SizeOfBuffer,\r
335 IN VOID *Buffer\r
878ddf1f 336 )\r
337{\r
00b7af13 338 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
878ddf1f 339}\r
340\r
341\r
342\r
343EFI_STATUS\r
344EFIAPI\r
345DxePcdSetBool (\r
4c114006 346 IN PCD_TOKEN_NUMBER TokenNumber,\r
52e1905d 347 IN BOOLEAN Value\r
878ddf1f 348 )\r
349{\r
52e1905d 350 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 351}\r
352\r
353\r
354\r
355EFI_STATUS\r
356EFIAPI\r
357DxePcdSet8Ex (\r
4c114006 358 IN CONST EFI_GUID *Guid,\r
359 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
52e1905d 360 IN UINT8 Value\r
878ddf1f 361 )\r
362{\r
52e1905d 363 return ExSetWorker(\r
364 ExTokenNumber, \r
365 Guid,\r
366 &Value, \r
367 sizeof (Value), \r
368 FALSE\r
369 );\r
878ddf1f 370}\r
371\r
372\r
373\r
374EFI_STATUS\r
375EFIAPI\r
376DxePcdSet16Ex (\r
4c114006 377 IN CONST EFI_GUID *Guid,\r
378 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 379 IN UINT16 Value\r
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
395DxePcdSet32Ex (\r
4c114006 396 IN CONST EFI_GUID *Guid,\r
397 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 398 IN UINT32 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
414DxePcdSet64Ex (\r
4c114006 415 IN CONST EFI_GUID *Guid,\r
416 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 417 IN UINT64 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
433DxePcdSetPtrEx (\r
00b7af13 434 IN CONST EFI_GUID *Guid,\r
4c114006 435 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
00b7af13 436 IN UINTN SizeOfBuffer,\r
437 IN VOID *Buffer\r
878ddf1f 438 )\r
439{\r
52e1905d 440 return ExSetWorker(\r
441 ExTokenNumber, \r
442 Guid,\r
00b7af13 443 Buffer, \r
444 SizeOfBuffer, \r
52e1905d 445 TRUE\r
446 );\r
878ddf1f 447}\r
448\r
449\r
450\r
451EFI_STATUS\r
452EFIAPI\r
453DxePcdSetBoolEx (\r
4c114006 454 IN CONST EFI_GUID *Guid,\r
455 IN PCD_TOKEN_NUMBER ExTokenNumber,\r
878ddf1f 456 IN BOOLEAN Value\r
457 )\r
458{\r
52e1905d 459 return ExSetWorker(\r
460 ExTokenNumber, \r
461 Guid,\r
462 &Value, \r
463 sizeof (Value), \r
464 TRUE\r
465 );\r
878ddf1f 466}\r
467\r
468\r
469\r
470\r
471EFI_STATUS\r
472EFIAPI\r
4c114006 473DxeRegisterCallBackOnSet (\r
474 IN PCD_TOKEN_NUMBER TokenNumber,\r
475 IN CONST EFI_GUID *Guid, OPTIONAL\r
878ddf1f 476 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
477 )\r
478{\r
4c114006 479 ASSERT (CallBackFunction != NULL);\r
480 \r
481 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 482}\r
483\r
484\r
485\r
486EFI_STATUS\r
487EFIAPI\r
4c114006 488DxeUnRegisterCallBackOnSet (\r
489 IN PCD_TOKEN_NUMBER TokenNumber,\r
490 IN CONST EFI_GUID *Guid, OPTIONAL\r
878ddf1f 491 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
492 )\r
493{\r
4c114006 494 ASSERT (CallBackFunction != NULL);\r
495 \r
496 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 497}\r
498\r
499\r
500\r
501EFI_STATUS\r
502EFIAPI\r
503DxePcdGetNextToken (\r
4c114006 504 IN CONST EFI_GUID *Guid, OPTIONAL\r
505 IN OUT PCD_TOKEN_NUMBER *TokenNumber\r
878ddf1f 506 )\r
507{\r
4c114006 508 PCD_TOKEN_NUMBER ExTokenNumber;\r
509 \r
510 //\r
511 // Scan the local token space\r
512 //\r
513 if (Guid == NULL) {\r
dcec7651 514 (*TokenNumber)++;\r
4c114006 515 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
516 return EFI_SUCCESS;\r
517 } else {\r
518 if (*TokenNumber >= PEI_NEX_TOKEN_NUMBER &&\r
519 *TokenNumber < PEI_LOCAL_TOKEN_NUMBER) {\r
520 //\r
521 // The first Non-Ex type Token Number for DXE PCD \r
522 // database is PEI_LOCAL_TOKEN_NUMBER\r
523 //\r
524 *TokenNumber = PEI_LOCAL_TOKEN_NUMBER;\r
525 return EFI_SUCCESS;\r
526 } else if (*TokenNumber >= DXE_NEX_TOKEN_NUMBER + PEI_LOCAL_TOKEN_NUMBER) {\r
527 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
528 return EFI_SUCCESS;\r
529 }\r
530 }\r
531 }\r
532\r
533 if (PEI_EXMAP_TABLE_EMPTY && PEI_EXMAP_TABLE_EMPTY) {\r
534 *TokenNumber = (UINTN) PCD_INVALID_TOKEN_NUMBER;\r
535 return EFI_NOT_FOUND;\r
536 }\r
537\r
538 ExTokenNumber = *TokenNumber;\r
539 if (!PEI_EXMAP_TABLE_EMPTY) {\r
540 ExTokenNumber = ExGetNextTokeNumber (\r
541 Guid,\r
542 ExTokenNumber,\r
543 mPcdDatabase->PeiDb.Init.GuidTable,\r
544 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),\r
545 mPcdDatabase->PeiDb.Init.ExMapTable,\r
546 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)\r
547 );\r
548 }\r
549\r
550 if (!DXE_EXMAP_TABLE_EMPTY) {\r
551 ExTokenNumber = ExGetNextTokeNumber (\r
552 Guid,\r
553 ExTokenNumber,\r
554 mPcdDatabase->PeiDb.Init.GuidTable,\r
555 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),\r
556 mPcdDatabase->PeiDb.Init.ExMapTable,\r
557 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)\r
558 );\r
559 }\r
560\r
561 *TokenNumber = ExTokenNumber;\r
562\r
563 return EFI_SUCCESS;\r
878ddf1f 564}\r
565\r