Check in the Pcd service Driver/PEIM according to the new way of generating PCD Database
[mirror_edk2.git] / EdkModulePkg / Universal / PCD / Pei / Pcd.c
CommitLineData
52e1905d 1/** @file PCD PEIM\r
878ddf1f 2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name: Pcd.c\r
14\r
15**/\r
16\r
878ddf1f 17#include "Service.h"\r
18\r
19\r
20PCD_PPI mPcdPpiInstance = {\r
21 PeiPcdSetSku,\r
22\r
23 PeiPcdGet8,\r
24 PeiPcdGet16, \r
25 PeiPcdGet32, \r
26 PeiPcdGet64, \r
27 PeiPcdGetPtr, \r
28 PeiPcdGetBool, \r
29 PeiPcdGetSize,\r
30\r
31 PeiPcdGet8Ex,\r
32 PeiPcdGet16Ex, \r
33 PeiPcdGet32Ex, \r
34 PeiPcdGet64Ex, \r
35 PeiPcdGetPtrEx, \r
36 PeiPcdGetBoolEx, \r
37 PeiPcdGetSizeEx,\r
38 \r
39 PeiPcdSet8,\r
40 PeiPcdSet16, \r
41 PeiPcdSet32, \r
42 PeiPcdSet64, \r
43 PeiPcdSetPtr, \r
44 PeiPcdSetBool, \r
45\r
46 PeiPcdSet8Ex,\r
47 PeiPcdSet16Ex, \r
48 PeiPcdSet32Ex, \r
49 PeiPcdSet64Ex, \r
50 PeiPcdSetPtrEx, \r
51 PeiPcdSetBoolEx,\r
52\r
53 PcdRegisterCallBackOnSet,\r
54 PcdUnRegisterCallBackOnSet,\r
55 PeiPcdGetNextToken\r
56};\r
57\r
58\r
59\r
60STATIC EFI_PEI_PPI_DESCRIPTOR mPpiPCD = {\r
61 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
62 &gPcdPpiGuid,\r
63 &mPcdPpiInstance\r
64};\r
65\r
66\r
67\r
68EFI_STATUS\r
69EFIAPI\r
70PcdPeimInit (\r
71 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
72 IN EFI_PEI_SERVICES **PeiServices\r
73 )\r
74{\r
75 EFI_STATUS Status;\r
878ddf1f 76\r
52e1905d 77 BuildPcdDatabase ();\r
78 \r
878ddf1f 79 Status = PeiCoreInstallPpi (&mPpiPCD);\r
80\r
81 ASSERT_EFI_ERROR (Status);\r
82 \r
83 return EFI_SUCCESS;\r
84}\r
85\r
878ddf1f 86EFI_STATUS\r
87EFIAPI\r
88PeiPcdSetSku (\r
89 IN UINTN SkuId\r
90 )\r
91{\r
878ddf1f 92\r
52e1905d 93 GetPcdDatabase()->Init.SystemSkuId = (SKU_ID) SkuId;\r
878ddf1f 94\r
52e1905d 95 return EFI_SUCCESS;\r
878ddf1f 96}\r
97\r
98\r
99\r
100UINT8\r
101EFIAPI\r
102PeiPcdGet8 (\r
103 IN UINTN TokenNumber\r
104 )\r
105{\r
52e1905d 106 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
878ddf1f 107}\r
108\r
109\r
110\r
111UINT16\r
112EFIAPI\r
113PeiPcdGet16 (\r
114 IN UINTN TokenNumber\r
115 )\r
116{\r
52e1905d 117 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
878ddf1f 118}\r
119\r
120\r
121\r
122UINT32\r
123EFIAPI\r
124PeiPcdGet32 (\r
125 IN UINTN TokenNumber\r
126 )\r
127{\r
52e1905d 128 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
878ddf1f 129}\r
130\r
131\r
132\r
133UINT64\r
134EFIAPI\r
135PeiPcdGet64 (\r
136 IN UINTN TokenNumber\r
137 )\r
138{\r
52e1905d 139 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
878ddf1f 140}\r
141\r
142\r
143\r
144VOID *\r
145EFIAPI\r
146PeiPcdGetPtr (\r
147 IN UINTN TokenNumber\r
148 )\r
149{\r
52e1905d 150 return GetWorker (TokenNumber, 0);\r
878ddf1f 151}\r
152\r
153\r
154\r
155BOOLEAN\r
156EFIAPI\r
157PeiPcdGetBool (\r
158 IN UINTN TokenNumber\r
159 )\r
160{\r
52e1905d 161 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
878ddf1f 162}\r
163\r
164\r
165\r
166UINTN\r
167EFIAPI\r
168PeiPcdGetSize (\r
169 IN UINTN TokenNumber\r
170 )\r
171{\r
52e1905d 172 ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);\r
173\r
174 return GetPcdDatabase()->Init.SizeTable[TokenNumber];\r
878ddf1f 175}\r
176\r
177\r
178\r
179UINT8\r
180EFIAPI\r
181PeiPcdGet8Ex (\r
182 IN CONST EFI_GUID *Guid,\r
52e1905d 183 IN UINTN ExTokenNumber\r
878ddf1f 184 )\r
185{\r
52e1905d 186 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
878ddf1f 187}\r
188\r
189\r
190\r
191UINT16\r
192EFIAPI\r
193PeiPcdGet16Ex (\r
194 IN CONST EFI_GUID *Guid,\r
52e1905d 195 IN UINTN ExTokenNumber\r
878ddf1f 196 )\r
197{\r
52e1905d 198 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
878ddf1f 199}\r
200\r
201\r
202\r
203UINT32\r
204EFIAPI\r
205PeiPcdGet32Ex (\r
206 IN CONST EFI_GUID *Guid,\r
52e1905d 207 IN UINTN ExTokenNumber\r
878ddf1f 208 )\r
209{\r
52e1905d 210 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
878ddf1f 211}\r
212\r
213\r
214\r
215UINT64\r
216EFIAPI\r
217PeiPcdGet64Ex (\r
218 IN CONST EFI_GUID *Guid,\r
52e1905d 219 IN UINTN ExTokenNumber\r
878ddf1f 220 )\r
221{\r
52e1905d 222 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
878ddf1f 223}\r
224\r
225\r
226\r
227VOID *\r
228EFIAPI\r
229PeiPcdGetPtrEx (\r
230 IN CONST EFI_GUID *Guid,\r
52e1905d 231 IN UINTN ExTokenNumber\r
878ddf1f 232 )\r
233{\r
52e1905d 234 return ExGetWorker (Guid, ExTokenNumber, 0);\r
878ddf1f 235}\r
236\r
237\r
238\r
239BOOLEAN\r
240EFIAPI\r
241PeiPcdGetBoolEx (\r
242 IN CONST EFI_GUID *Guid,\r
52e1905d 243 IN UINTN ExTokenNumber\r
878ddf1f 244 )\r
245{\r
52e1905d 246 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
878ddf1f 247}\r
248\r
249\r
250\r
251UINTN\r
252EFIAPI\r
253PeiPcdGetSizeEx (\r
254 IN CONST EFI_GUID *Guid,\r
52e1905d 255 IN UINTN ExTokenNumber\r
878ddf1f 256 )\r
257{\r
52e1905d 258 EX_PCD_ENTRY_ATTRIBUTE Attr;\r
259\r
260 GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);\r
261 \r
262 return Attr.Size;\r
878ddf1f 263}\r
264\r
265\r
266\r
267EFI_STATUS\r
268EFIAPI\r
269PeiPcdSet8 (\r
270 IN UINTN TokenNumber,\r
271 IN UINT8 Value\r
272 )\r
273{\r
52e1905d 274 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 275}\r
276\r
277\r
278\r
279EFI_STATUS\r
280EFIAPI\r
281PeiPcdSet16 (\r
282 IN UINTN TokenNumber,\r
283 IN UINT16 Value\r
284 )\r
285{\r
52e1905d 286 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 287}\r
288\r
289\r
290\r
291EFI_STATUS\r
292EFIAPI\r
293PeiPcdSet32 (\r
294 IN UINTN TokenNumber,\r
295 IN UINT32 Value\r
296 )\r
297{\r
52e1905d 298 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 299}\r
300\r
301\r
302\r
303EFI_STATUS\r
304EFIAPI\r
305PeiPcdSet64 (\r
306 IN UINTN TokenNumber,\r
307 IN UINT64 Value\r
308 )\r
309{\r
52e1905d 310 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 311}\r
312\r
313\r
314EFI_STATUS\r
315EFIAPI\r
316PeiPcdSetPtr (\r
317 IN UINTN TokenNumber,\r
318 IN CONST VOID *Value\r
319 )\r
320{\r
52e1905d 321 //\r
322 // BugBug, please change the Size to Input size when sync with spec\r
323 //\r
324 //ASSERT (sizeof (Value) == GetPcdDatabase()->Init.SizeTable[TokenNumber]);\r
325\r
326 return SetWorker (TokenNumber, (VOID *) Value, GetPcdDatabase()->Init.SizeTable[TokenNumber], TRUE);\r
878ddf1f 327}\r
328\r
329\r
330\r
331EFI_STATUS\r
332EFIAPI\r
333PeiPcdSetBool (\r
334 IN UINTN TokenNumber,\r
335 IN BOOLEAN Value\r
336 )\r
337{\r
52e1905d 338 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);\r
878ddf1f 339}\r
340\r
341\r
342\r
343EFI_STATUS\r
344EFIAPI\r
345PeiPcdSet8Ex (\r
346 IN CONST EFI_GUID *Guid,\r
52e1905d 347 IN UINTN ExTokenNumber,\r
878ddf1f 348 IN UINT8 Value\r
349 )\r
350{\r
52e1905d 351 return ExSetWorker(\r
352 ExTokenNumber, \r
353 Guid,\r
354 &Value, \r
355 sizeof (Value), \r
356 FALSE\r
357 );\r
878ddf1f 358}\r
359\r
360\r
361\r
362EFI_STATUS\r
363EFIAPI\r
364PeiPcdSet16Ex (\r
365 IN CONST EFI_GUID *Guid,\r
52e1905d 366 IN UINTN ExTokenNumber,\r
878ddf1f 367 IN UINT16 Value\r
368 )\r
369{\r
52e1905d 370 return ExSetWorker(\r
371 ExTokenNumber, \r
372 Guid,\r
373 &Value, \r
374 sizeof (Value), \r
375 FALSE\r
376 );\r
878ddf1f 377}\r
378\r
379\r
380\r
381EFI_STATUS\r
382EFIAPI\r
383PeiPcdSet32Ex (\r
384 IN CONST EFI_GUID *Guid,\r
52e1905d 385 IN UINTN ExTokenNumber,\r
878ddf1f 386 IN UINT32 Value\r
387 )\r
388{\r
52e1905d 389 return ExSetWorker(\r
390 ExTokenNumber, \r
391 Guid,\r
392 &Value, \r
393 sizeof (Value), \r
394 FALSE\r
395 );\r
878ddf1f 396}\r
397\r
398\r
399\r
400EFI_STATUS\r
401EFIAPI\r
402PeiPcdSet64Ex (\r
403 IN CONST EFI_GUID *Guid,\r
52e1905d 404 IN UINTN ExTokenNumber,\r
878ddf1f 405 IN UINT64 Value\r
406 )\r
407{\r
52e1905d 408 return ExSetWorker(\r
409 ExTokenNumber, \r
410 Guid,\r
411 &Value, \r
412 sizeof (Value), \r
413 FALSE\r
414 );\r
878ddf1f 415}\r
416\r
417\r
418\r
419EFI_STATUS\r
420EFIAPI\r
421PeiPcdSetPtrEx (\r
422 IN CONST EFI_GUID *Guid,\r
52e1905d 423 IN UINTN ExTokenNumber,\r
878ddf1f 424 IN CONST VOID *Value\r
425 )\r
426{\r
52e1905d 427 return ExSetWorker(\r
428 ExTokenNumber, \r
429 Guid,\r
430 (VOID *) Value, \r
431 sizeof (Value), \r
432 TRUE\r
433 );\r
878ddf1f 434}\r
435\r
436\r
437\r
438EFI_STATUS\r
439EFIAPI\r
440PeiPcdSetBoolEx (\r
441 IN CONST EFI_GUID *Guid,\r
52e1905d 442 IN UINTN ExTokenNumber,\r
878ddf1f 443 IN BOOLEAN Value\r
444 )\r
445{\r
52e1905d 446 return ExSetWorker(\r
447 ExTokenNumber, \r
448 Guid,\r
449 &Value, \r
450 sizeof (Value), \r
451 FALSE\r
452 );\r
878ddf1f 453}\r
454\r
455\r
456\r
457\r
458EFI_STATUS\r
459EFIAPI\r
460PcdRegisterCallBackOnSet (\r
52e1905d 461 IN UINTN ExTokenNumber,\r
878ddf1f 462 IN CONST EFI_GUID *Guid, OPTIONAL\r
463 IN PCD_PPI_CALLBACK CallBackFunction\r
464 )\r
465{\r
52e1905d 466 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r
878ddf1f 467}\r
468\r
469\r
470\r
471EFI_STATUS\r
472EFIAPI\r
473PcdUnRegisterCallBackOnSet (\r
52e1905d 474 IN UINTN ExTokenNumber,\r
878ddf1f 475 IN CONST EFI_GUID *Guid, OPTIONAL\r
476 IN PCD_PPI_CALLBACK CallBackFunction\r
477 )\r
478{\r
52e1905d 479 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r
878ddf1f 480}\r
481\r
482\r
483\r
484EFI_STATUS\r
485EFIAPI\r
486PeiPcdGetNextToken (\r
487 IN CONST EFI_GUID *Guid, OPTIONAL\r
488 IN OUT UINTN *TokenNumber\r
489 )\r
490{\r
52e1905d 491 if (Guid == NULL) {\r
492 *TokenNumber++;\r
493\r
494 if (*TokenNumber >= PEI_LOCAL_TOKEN_NUMBER) {\r
495 *TokenNumber = 0;\r
496 }\r
497 }\r
498\r
499 //\r
500 // BugBug: Haven't implemented the portion to get Next Token for GuidSpace is not Local GuidSpace.\r
501 //\r
502\r
503 return EFI_SUCCESS;\r
878ddf1f 504}\r
505\r
506\r