]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/PcdEmulator/PcdEmulator.c
Initial import.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / PcdEmulator / PcdEmulator.c
1 /*++
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 Module Name:
13 PcdEmulator.c
14
15 Abstract:
16 Platform Configuration Database (PCD) Protocol
17
18 --*/
19
20 #include <PcdEmulator.h>
21
22 UINTN mSkuId = 0;
23
24 STATIC UINTN
25 GetPcdDataEntryCount (
26 VOID
27 ) {
28 return gEmulatedPcdDatabaseEx->Count;
29 }
30
31 EFI_STATUS
32 EFIAPI
33 PcdEmulatorSetSku (
34 IN UINTN SkuId
35 )
36 {
37 mSkuId = SkuId;
38 return EFI_SUCCESS;
39 }
40
41 UINT8
42 EFIAPI
43 PcdEmulatorGet8 (
44 IN UINTN TokenNumber
45 )
46 {
47 EMULATED_PCD_ENTRY_EX *Pcd;
48
49 Pcd = GetPcdEntry (TokenNumber);
50 ASSERT (Pcd != NULL);
51 ASSERT (Pcd->DatumSize == 1);
52
53 return (UINT8)Pcd->Datum;
54 }
55
56 UINT16
57 EFIAPI
58 PcdEmulatorGet16 (
59 IN UINTN TokenNumber
60 )
61 {
62 EMULATED_PCD_ENTRY_EX *Pcd;
63
64 Pcd = GetPcdEntry (TokenNumber);
65 ASSERT (Pcd != NULL);
66 ASSERT (Pcd->DatumSize == 2);
67
68 return (UINT16)Pcd->Datum;
69 }
70
71 UINT32
72 EFIAPI
73 PcdEmulatorGet32 (
74 IN UINTN TokenNumber
75 )
76 {
77 EMULATED_PCD_ENTRY_EX *Pcd;
78
79 Pcd = GetPcdEntry (TokenNumber);
80 ASSERT (Pcd != NULL);
81 ASSERT (Pcd->DatumSize == 4);
82
83 return (UINT32)Pcd->Datum;
84 }
85
86 UINT64
87 EFIAPI
88 PcdEmulatorGet64 (
89 IN UINTN TokenNumber
90 )
91 {
92 EMULATED_PCD_ENTRY_EX *Pcd;
93
94 Pcd = GetPcdEntry (TokenNumber);
95 ASSERT (Pcd != NULL);
96 ASSERT (Pcd->DatumSize == sizeof (UINT64));
97
98 return (UINT64)Pcd->Datum;
99 }
100
101 VOID *
102 EFIAPI
103 PcdEmulatorGetPtr (
104 IN UINTN TokenNumber
105 )
106 {
107 EMULATED_PCD_ENTRY_EX *Pcd;
108
109 Pcd = GetPcdEntry (TokenNumber);
110 ASSERT (Pcd != NULL);
111
112 return (VOID *)(UINTN)Pcd->ExtendedData;
113 }
114
115 BOOLEAN
116 EFIAPI
117 PcdEmulatorGetBoolean (
118 IN UINTN TokenNumber
119 )
120 {
121 EMULATED_PCD_ENTRY_EX *Pcd;
122
123 Pcd = GetPcdEntry (TokenNumber);
124 ASSERT (Pcd != NULL);
125 ASSERT (Pcd->DatumSize == 1);
126
127 return (BOOLEAN)Pcd->Datum;
128 }
129
130 UINTN
131 EFIAPI
132 PcdEmulatorGetSize (
133 IN UINTN TokenNumber
134 )
135 {
136 EMULATED_PCD_ENTRY_EX *Pcd;
137
138 Pcd = GetPcdEntry (TokenNumber);
139 ASSERT (Pcd != NULL);
140 return Pcd->DatumSize;
141 }
142
143 UINT8
144 EFIAPI
145 PcdEmulatorGet8Ex (
146 IN CONST EFI_GUID *PcdDataBaseName,
147 IN UINTN TokenNumber
148 )
149 {
150 ASSERT (FALSE);
151 return 0;
152 }
153
154 UINT16
155 EFIAPI
156 PcdEmulatorGet16Ex (
157 IN CONST EFI_GUID *PcdDataBaseName,
158 IN UINTN TokenNumber
159 )
160 {
161 ASSERT (FALSE);
162 return 0;
163 }
164
165 UINT32
166 EFIAPI
167 PcdEmulatorGet32Ex (
168 IN CONST EFI_GUID *PcdDataBaseName,
169 IN UINTN TokenNumber
170 )
171 {
172 ASSERT (FALSE);
173 return 0;
174 }
175
176 UINT64
177 EFIAPI
178 PcdEmulatorGet64Ex (
179 IN CONST EFI_GUID *PcdDataBaseName,
180 IN UINTN TokenNumber
181 )
182 {
183 ASSERT (FALSE);
184 return 0;
185 }
186
187 VOID *
188 EFIAPI
189 PcdEmulatorGetPtrEx (
190 IN CONST EFI_GUID *PcdDataBaseName,
191 IN UINTN TokenNumber
192 )
193 {
194 ASSERT (FALSE);
195 return 0;
196 }
197
198 BOOLEAN
199 EFIAPI
200 PcdEmulatorGetBooleanEx (
201 IN CONST EFI_GUID *PcdDataBaseName,
202 IN UINTN TokenNumber
203 )
204 {
205 ASSERT (FALSE);
206 return 0;
207 }
208
209 UINTN
210 EFIAPI
211 PcdEmulatorGetSizeEx (
212 IN CONST EFI_GUID *PcdDataBaseName,
213 IN UINTN TokenNumber
214 )
215 {
216 EMULATED_PCD_ENTRY_EX *Pcd;
217
218 Pcd = GetPcdEntry (TokenNumber);
219 ASSERT (Pcd != NULL);
220 return Pcd->DatumSize;
221 }
222
223
224 EFI_STATUS
225 EFIAPI
226 PcdEmulatorSet8 (
227 IN UINTN TokenNumber,
228 IN UINT8 Value
229 )
230 {
231
232 EMULATED_PCD_ENTRY_EX *Pcd;
233
234 Pcd = GetPcdEntry (TokenNumber);
235 ASSERT (Pcd != NULL);
236
237 ASSERT (Pcd->DatumSize == sizeof (UINT8));
238
239 Pcd->Datum = Value;
240
241 return EFI_SUCCESS;
242 }
243
244 EFI_STATUS
245 EFIAPI
246 PcdEmulatorSet16 (
247 IN UINTN TokenNumber,
248 IN UINT16 Value
249 )
250 {
251
252 ASSERT (FALSE);
253
254 return EFI_SUCCESS;
255 }
256
257 EFI_STATUS
258 EFIAPI
259 PcdEmulatorSet32 (
260 IN UINTN TokenNumber,
261 IN UINT32 Value
262 )
263 {
264
265 EMULATED_PCD_ENTRY_EX *Pcd;
266
267 Pcd = GetPcdEntry (TokenNumber);
268 ASSERT (Pcd != NULL);
269
270 ASSERT (Pcd->DatumSize == sizeof (UINT32));
271
272 Pcd->Datum = Value;
273
274 return EFI_SUCCESS;
275 }
276
277 EFI_STATUS
278 EFIAPI
279 PcdEmulatorSet64 (
280 IN UINTN TokenNumber,
281 IN UINT64 Value
282 )
283 {
284
285 ASSERT (FALSE);
286
287 return EFI_SUCCESS;
288 }
289
290 EFI_STATUS
291 EFIAPI
292 PcdEmulatorSetPtr (
293 IN UINTN TokenNumber,
294 IN CONST VOID *Value
295 )
296 {
297
298 ASSERT (FALSE);
299
300 return EFI_SUCCESS;
301 }
302
303 EFI_STATUS
304 EFIAPI
305 PcdEmulatorSetBoolean (
306 IN UINTN TokenNumber,
307 IN BOOLEAN Value
308 )
309 {
310
311 ASSERT (FALSE);
312
313 return EFI_SUCCESS;
314 }
315
316 EFI_STATUS
317 EFIAPI
318 PcdEmulatorSet8Ex (
319 IN CONST EFI_GUID *Guid,
320 IN UINTN TokenNumber,
321 IN UINT8 Value
322 )
323 {
324
325 ASSERT (FALSE);
326
327 return EFI_SUCCESS;
328 }
329
330 EFI_STATUS
331 EFIAPI
332 PcdEmulatorSet16Ex (
333 IN CONST EFI_GUID *Guid,
334 IN UINTN TokenNumber,
335 IN UINT16 Value
336 )
337 {
338
339 ASSERT (FALSE);
340
341 return EFI_SUCCESS;
342 }
343
344 EFI_STATUS
345 EFIAPI
346 PcdEmulatorSet32Ex (
347 IN CONST EFI_GUID *Guid,
348 IN UINTN TokenNumber,
349 IN UINT32 Value
350 )
351 {
352
353 ASSERT (FALSE);
354
355 return EFI_SUCCESS;
356 }
357
358 EFI_STATUS
359 EFIAPI
360 PcdEmulatorSet64Ex (
361 IN CONST EFI_GUID *Guid,
362 IN UINTN TokenNumber,
363 IN UINT64 Value
364 )
365 {
366
367 ASSERT (FALSE);
368
369 return EFI_SUCCESS;
370 }
371
372 EFI_STATUS
373 EFIAPI
374 PcdEmulatorSetPtrEx (
375 IN CONST EFI_GUID *Guid,
376 IN UINTN TokenNumber,
377 IN CONST VOID *Value
378 )
379 {
380
381 ASSERT (FALSE);
382
383 return EFI_SUCCESS;
384 }
385
386 EFI_STATUS
387 EFIAPI
388 PcdEmulatorSetBooleanEx (
389 IN CONST EFI_GUID *Guid,
390 IN UINTN TokenNumber,
391 IN BOOLEAN Value
392 )
393 {
394
395 ASSERT (FALSE);
396
397 return EFI_SUCCESS;
398 }
399
400 EFI_STATUS
401 EFIAPI
402 PcdEmulatorCallBackOnSet (
403 IN UINTN TokenNumber,
404 IN CONST EFI_GUID *Guid, OPTIONAL
405 IN PCD_PROTOCOL_CALLBACK CallBackFunction
406 )
407 {
408 EMULATED_PCD_ENTRY_EX *Pcd;
409
410 Pcd = GetPcdEntry (TokenNumber);
411 ASSERT (Pcd != NULL);
412
413 if (Pcd->CallBackListSize == Pcd->CallBackEntries) {
414 return EFI_OUT_OF_RESOURCES;
415 }
416
417 Pcd->CallBackList[Pcd->CallBackEntries++] = CallBackFunction;
418
419 return EFI_SUCCESS;
420 }
421
422 EFI_STATUS
423 EFIAPI
424 PcdEmulatorUnregisterCallBackOnSet (
425 IN UINTN TokenNumber,
426 IN CONST EFI_GUID *Guid, OPTIONAL
427 IN PCD_PROTOCOL_CALLBACK CallBackfunction
428 )
429 {
430 EMULATED_PCD_ENTRY_EX *Pcd;
431 UINT32 Index;
432
433 Pcd = GetPcdEntry (TokenNumber);
434 ASSERT (Pcd != NULL);
435
436 for (Index = 0; Index < Pcd->CallBackListSize; Index++) {
437 if (Pcd->CallBackList[Index] == CallBackfunction) {
438 Pcd->CallBackList[Index] = NULL;
439 return EFI_SUCCESS;
440 }
441 }
442
443 return EFI_NOT_FOUND;
444 }
445
446 EFI_STATUS
447 EFIAPI
448 PcdEmulatorGetNextToken (
449 IN CONST EFI_GUID *Guid, OPTIONAL
450 IN UINTN *Token
451 )
452 {
453 EMULATED_PCD_ENTRY_EX *Pcd;
454 EMULATED_PCD_ENTRY_EX *LastPcdEntry;
455
456 if (*Token == PCD_INVALID_TOKEN) {
457 //
458 // BugBug: Due to variable size array, ensure we convert this to a reasonable database
459 // that can accomodate array references for simplicity's sake
460 *Token = gEmulatedPcdEntryEx[0].Token;
461 return EFI_SUCCESS;
462 }
463
464 Pcd = GetPcdEntry (*Token);
465 if (Pcd == NULL) {
466 return EFI_NOT_FOUND;
467 }
468
469 LastPcdEntry = gEmulatedPcdEntryEx + GetPcdDataEntryCount ();
470 if (++Pcd >= LastPcdEntry) {
471 return EFI_NOT_FOUND;
472 }
473
474 *Token = Pcd->Token;
475 return EFI_SUCCESS;
476 }
477
478 PCD_PROTOCOL mPcdProtocolInstance = {
479 PcdEmulatorSetSku,
480
481 PcdEmulatorGet8,
482 PcdEmulatorGet16,
483 PcdEmulatorGet32,
484 PcdEmulatorGet64,
485 PcdEmulatorGetPtr,
486 PcdEmulatorGetBoolean,
487 PcdEmulatorGetSize,
488
489 PcdEmulatorGet8Ex,
490 PcdEmulatorGet16Ex,
491 PcdEmulatorGet32Ex,
492 PcdEmulatorGet64Ex,
493 PcdEmulatorGetPtrEx,
494 PcdEmulatorGetBooleanEx,
495 PcdEmulatorGetSizeEx,
496
497 PcdEmulatorSet8,
498 PcdEmulatorSet16,
499 PcdEmulatorSet32,
500 PcdEmulatorSet64,
501 PcdEmulatorSetPtr,
502 PcdEmulatorSetBoolean,
503
504 PcdEmulatorSet8Ex,
505 PcdEmulatorSet16Ex,
506 PcdEmulatorSet32Ex,
507 PcdEmulatorSet64Ex,
508 PcdEmulatorSetPtrEx,
509 PcdEmulatorSetBooleanEx,
510
511 PcdEmulatorCallBackOnSet,
512 PcdEmulatorUnregisterCallBackOnSet,
513 PcdEmulatorGetNextToken
514 };
515
516
517 EFI_STATUS
518 EFIAPI
519 PcdEmulatorEntry (
520 IN EFI_HANDLE ImageHandle,
521 IN EFI_SYSTEM_TABLE *SystemTable
522 )
523 {
524 EFI_STATUS Status;
525 EFI_HOB_GUID_TYPE *GuidHob;
526
527 GuidHob = GetFirstGuidHob (&gPcdHobGuid);
528 gEmulatedPcdDatabaseEx = (EMULATED_PCD_DATABASE_EX *) GET_GUID_HOB_DATA(GuidHob);
529 ASSERT (gEmulatedPcdDatabaseEx != NULL);
530 gEmulatedPcdEntryEx = gEmulatedPcdDatabaseEx->Entry;
531
532 Status = gBS->InstallMultipleProtocolInterfaces (
533 &ImageHandle,
534 &gPcdProtocolGuid, &mPcdProtocolInstance,
535 NULL
536 );
537 ASSERT_EFI_ERROR (Status);
538 return Status;
539 }
540
541
542 EMULATED_PCD_ENTRY_EX *
543 GetPcdEntry (
544 IN UINTN TokenNumber
545 )
546 {
547 UINTN Index;
548 UINTN Count;
549
550 Count = GetPcdDataEntryCount ();
551 for (Index = 0; Index < Count; Index++) {
552 if (gEmulatedPcdEntryEx[Index].Token == TokenNumber) {
553 return &gEmulatedPcdEntryEx[Index];
554 }
555 }
556 return NULL;
557 }