BaseMemoryLib: Add missing ASSERT()s for some interfaces.
[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 PeiRegisterCallBackOnSet,
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 VOID
87 EFIAPI
88 PeiPcdSetSku (
89 IN SKU_ID SkuId
90 )
91 {
92
93 GetPcdDatabase()->Init.SystemSkuId = SkuId;
94
95 return;
96 }
97
98
99
100 UINT8
101 EFIAPI
102 PeiPcdGet8 (
103 IN PCD_TOKEN_NUMBER TokenNumber
104 )
105 {
106 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));
107 }
108
109
110
111 UINT16
112 EFIAPI
113 PeiPcdGet16 (
114 IN PCD_TOKEN_NUMBER TokenNumber
115 )
116 {
117 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));
118 }
119
120
121
122 UINT32
123 EFIAPI
124 PeiPcdGet32 (
125 IN PCD_TOKEN_NUMBER TokenNumber
126 )
127 {
128 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));
129 }
130
131
132
133 UINT64
134 EFIAPI
135 PeiPcdGet64 (
136 IN PCD_TOKEN_NUMBER TokenNumber
137 )
138 {
139 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));
140 }
141
142
143
144 VOID *
145 EFIAPI
146 PeiPcdGetPtr (
147 IN PCD_TOKEN_NUMBER TokenNumber
148 )
149 {
150 return GetWorker (TokenNumber, 0);
151 }
152
153
154
155 BOOLEAN
156 EFIAPI
157 PeiPcdGetBool (
158 IN PCD_TOKEN_NUMBER TokenNumber
159 )
160 {
161 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));
162 }
163
164
165
166 UINTN
167 EFIAPI
168 PeiPcdGetSize (
169 IN PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER 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 PCD_TOKEN_NUMBER TokenNumber,
318 IN UINTN SizeOfBuffer,
319 IN VOID *Buffer
320 )
321 {
322 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);
323 }
324
325
326
327 EFI_STATUS
328 EFIAPI
329 PeiPcdSetBool (
330 IN PCD_TOKEN_NUMBER TokenNumber,
331 IN BOOLEAN Value
332 )
333 {
334 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
335 }
336
337
338
339 EFI_STATUS
340 EFIAPI
341 PeiPcdSet8Ex (
342 IN CONST EFI_GUID *Guid,
343 IN PCD_TOKEN_NUMBER ExTokenNumber,
344 IN UINT8 Value
345 )
346 {
347 return ExSetWorker(
348 ExTokenNumber,
349 Guid,
350 &Value,
351 sizeof (Value),
352 FALSE
353 );
354 }
355
356
357
358 EFI_STATUS
359 EFIAPI
360 PeiPcdSet16Ex (
361 IN CONST EFI_GUID *Guid,
362 IN PCD_TOKEN_NUMBER ExTokenNumber,
363 IN UINT16 Value
364 )
365 {
366 return ExSetWorker(
367 ExTokenNumber,
368 Guid,
369 &Value,
370 sizeof (Value),
371 FALSE
372 );
373 }
374
375
376
377 EFI_STATUS
378 EFIAPI
379 PeiPcdSet32Ex (
380 IN CONST EFI_GUID *Guid,
381 IN PCD_TOKEN_NUMBER ExTokenNumber,
382 IN UINT32 Value
383 )
384 {
385 return ExSetWorker(
386 ExTokenNumber,
387 Guid,
388 &Value,
389 sizeof (Value),
390 FALSE
391 );
392 }
393
394
395
396 EFI_STATUS
397 EFIAPI
398 PeiPcdSet64Ex (
399 IN CONST EFI_GUID *Guid,
400 IN PCD_TOKEN_NUMBER ExTokenNumber,
401 IN UINT64 Value
402 )
403 {
404 return ExSetWorker(
405 ExTokenNumber,
406 Guid,
407 &Value,
408 sizeof (Value),
409 FALSE
410 );
411 }
412
413
414
415 EFI_STATUS
416 EFIAPI
417 PeiPcdSetPtrEx (
418 IN CONST EFI_GUID *Guid,
419 IN PCD_TOKEN_NUMBER ExTokenNumber,
420 IN UINTN SizeOfBuffer,
421 IN VOID *Value
422 )
423 {
424 return ExSetWorker(
425 ExTokenNumber,
426 Guid,
427 Value,
428 SizeOfBuffer,
429 TRUE
430 );
431 }
432
433
434
435 EFI_STATUS
436 EFIAPI
437 PeiPcdSetBoolEx (
438 IN CONST EFI_GUID *Guid,
439 IN PCD_TOKEN_NUMBER ExTokenNumber,
440 IN BOOLEAN Value
441 )
442 {
443 return ExSetWorker(
444 ExTokenNumber,
445 Guid,
446 &Value,
447 sizeof (Value),
448 FALSE
449 );
450 }
451
452
453
454
455 EFI_STATUS
456 EFIAPI
457 PeiRegisterCallBackOnSet (
458 IN PCD_TOKEN_NUMBER ExTokenNumber,
459 IN CONST EFI_GUID *Guid, OPTIONAL
460 IN PCD_PPI_CALLBACK CallBackFunction
461 )
462 {
463 ASSERT (CallBackFunction != NULL);
464
465 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);
466 }
467
468
469
470 EFI_STATUS
471 EFIAPI
472 PcdUnRegisterCallBackOnSet (
473 IN PCD_TOKEN_NUMBER ExTokenNumber,
474 IN CONST EFI_GUID *Guid, OPTIONAL
475 IN PCD_PPI_CALLBACK CallBackFunction
476 )
477 {
478 ASSERT (CallBackFunction != NULL);
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 PCD_TOKEN_NUMBER *TokenNumber
490 )
491 {
492 UINTN GuidTableIdx;
493 PEI_PCD_DATABASE *PeiPcdDb;
494 EFI_GUID *MatchGuid;
495 DYNAMICEX_MAPPING *ExMapTable;
496 UINTN i;
497 BOOLEAN Found;
498
499 if (Guid == NULL) {
500 (*TokenNumber)++;
501
502 if (*TokenNumber >= PEI_NEX_TOKEN_NUMBER) {
503 *TokenNumber = 0;
504 }
505
506 } else {
507
508 if (PEI_EXMAP_TABLE_EMPTY) {
509 *TokenNumber = (UINTN) PCD_INVALID_TOKEN_NUMBER;
510 return EFI_NOT_FOUND;
511 }
512
513 //
514 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
515 // 1) ExGuid
516 // 2) ExTokenNumber
517 //
518 PeiPcdDb = GetPcdDatabase ();
519
520 MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid);
521
522 if (MatchGuid == NULL) {
523 *TokenNumber = (UINTN) PCD_INVALID_TOKEN_NUMBER;
524 return EFI_NOT_FOUND;
525 }
526
527 GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;
528
529 ExMapTable = PeiPcdDb->Init.ExMapTable;
530
531 Found = FALSE;
532 for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {
533 if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {
534 Found = TRUE;
535 break;
536 }
537 }
538
539 if (Found) {
540 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
541 *TokenNumber = ExMapTable[i].ExTokenNumber;
542 return EFI_SUCCESS;
543 }
544
545 for ( ; ExMapTable[i].ExGuidIndex == GuidTableIdx; i++) {
546 if (ExMapTable[i].ExTokenNumber == *TokenNumber) {
547 i++;
548 if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {
549 *TokenNumber = ExMapTable[i].ExTokenNumber;
550 return EFI_SUCCESS;
551 } else {
552 *TokenNumber = (UINTN) PCD_INVALID_TOKEN_NUMBER;
553 return EFI_SUCCESS;
554 }
555 }
556 }
557
558 return EFI_NOT_FOUND;
559 }
560
561 }
562
563 return EFI_SUCCESS;
564 }
565
566 EFI_GUID *
567 EFIAPI
568 PeiPcdGetNextTokenSpaceGuid (
569 IN CONST EFI_GUID *Guid
570 )
571 {
572 UINTN GuidTableIdx;
573 EFI_GUID *MatchGuid;
574 PEI_PCD_DATABASE *PeiPcdDb;
575 DYNAMICEX_MAPPING *ExMapTable;
576 UINTN i;
577 BOOLEAN Found;
578
579 if (PEI_EXMAP_TABLE_EMPTY) {
580 return NULL;
581 }
582
583 //
584 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
585 // 1) ExGuid
586 // 2) ExTokenNumber
587 //
588 PeiPcdDb = GetPcdDatabase ();
589
590 MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid);
591
592 if (MatchGuid == NULL) {
593 return NULL;
594 }
595
596 GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;
597
598 ExMapTable = PeiPcdDb->Init.ExMapTable;
599
600 Found = FALSE;
601 for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {
602 if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {
603 Found = TRUE;
604 break;
605 }
606 }
607
608 if (Found) {
609 for ( ; i < PEI_EXMAPPING_TABLE_SIZE; i++ ) {
610 if (ExMapTable[i].ExGuidIndex != GuidTableIdx ) {
611 if (i < PEI_EXMAPPING_TABLE_SIZE) {
612 return &PeiPcdDb->Init.GuidTable[ExMapTable[i].ExGuidIndex];
613 } else {
614 return NULL;
615 }
616 }
617 }
618 }
619
620 return NULL;
621
622 }
623