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