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