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