Check in the Pcd service Driver/PEIM according to the new way of generating PCD Database
[mirror_edk2.git] / EdkModulePkg / Universal / PCD / Dxe / Pcd.c
1 /** @file
2 PCD DXE driver
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 "Service.h"
19
20
21 PCD_PROTOCOL mPcdInstance = {
22 DxePcdSetSku,
23
24 DxePcdGet8,
25 DxePcdGet16,
26 DxePcdGet32,
27 DxePcdGet64,
28 DxePcdGetPtr,
29 DxePcdGetBool,
30 DxePcdGetSize,
31
32 DxePcdGet8Ex,
33 DxePcdGet16Ex,
34 DxePcdGet32Ex,
35 DxePcdGet64Ex,
36 DxePcdGetPtrEx,
37 DxePcdGetBoolEx,
38 DxePcdGetSizeEx,
39
40 DxePcdSet8,
41 DxePcdSet16,
42 DxePcdSet32,
43 DxePcdSet64,
44 DxePcdSetPtr,
45 DxePcdSetBool,
46
47 DxePcdSet8Ex,
48 DxePcdSet16Ex,
49 DxePcdSet32Ex,
50 DxePcdSet64Ex,
51 DxePcdSetPtrEx,
52 DxePcdSetBoolEx,
53
54 PcdRegisterCallBackOnSet,
55 PcdUnRegisterCallBackOnSet,
56 DxePcdGetNextToken
57 };
58
59
60 //
61 // Static global to reduce the code size
62 //
63 static EFI_HANDLE NewHandle = NULL;
64
65 EFI_STATUS
66 EFIAPI
67 PcdDxeInit (
68 IN EFI_HANDLE ImageHandle,
69 IN EFI_SYSTEM_TABLE *SystemTable
70 )
71 {
72 EFI_STATUS Status;
73
74 //
75 // Make sure the Pcd Protocol is not already installed in the system
76 //
77
78 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gPcdProtocolGuid);
79
80 BuildPcdDxeDataBase ();
81
82 //
83 // BugBug Check if PcdDatabase is already installed.
84 //
85
86 Status = gBS->InstallProtocolInterface (
87 &NewHandle,
88 &gPcdProtocolGuid,
89 EFI_NATIVE_INTERFACE,
90 &mPcdInstance
91 );
92
93 ASSERT_EFI_ERROR (Status);
94
95 return EFI_SUCCESS;
96
97 }
98
99
100 EFI_STATUS
101 EFIAPI
102 DxePcdSetSku (
103 IN UINTN SkuId
104 )
105 {
106 return gPcdDatabase->PeiDb.Init.SystemSkuId = (SKU_ID) SkuId;
107 }
108
109
110
111 UINT8
112 EFIAPI
113 DxePcdGet8 (
114 IN UINTN TokenNumber
115 )
116 {
117 ASSERT (sizeof (UINT8) == DxePcdGetSize (TokenNumber));
118
119 return *((UINT8 *) GetWorker (TokenNumber));
120 }
121
122
123
124 UINT16
125 EFIAPI
126 DxePcdGet16 (
127 IN UINTN TokenNumber
128 )
129 {
130 ASSERT (sizeof (UINT16) == DxePcdGetSize (TokenNumber));
131
132 return ReadUnaligned16 (GetWorker (TokenNumber));
133 }
134
135
136
137 UINT32
138 EFIAPI
139 DxePcdGet32 (
140 IN UINTN TokenNumber
141 )
142 {
143 ASSERT (sizeof (UINT32) == DxePcdGetSize (TokenNumber));
144
145 return ReadUnaligned32 (GetWorker (TokenNumber));
146 }
147
148
149
150 UINT64
151 EFIAPI
152 DxePcdGet64 (
153 IN UINTN TokenNumber
154 )
155 {
156 ASSERT (sizeof (UINT64) == DxePcdGetSize (TokenNumber));
157
158 return ReadUnaligned64(GetWorker (TokenNumber));
159 }
160
161
162
163 VOID *
164 EFIAPI
165 DxePcdGetPtr (
166 IN UINTN TokenNumber
167 )
168 {
169 return GetWorker (TokenNumber);
170 }
171
172
173
174 BOOLEAN
175 EFIAPI
176 DxePcdGetBool (
177 IN UINTN TokenNumber
178 )
179 {
180 ASSERT (sizeof (BOOLEAN) == DxePcdGetSize (TokenNumber));
181
182 return *((BOOLEAN *) GetWorker (TokenNumber));
183 }
184
185
186
187 UINTN
188 EFIAPI
189 DxePcdGetSize (
190 IN UINTN TokenNumber
191 )
192 {
193 UINT16 * SizeTable;
194
195 SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? gPcdDatabase->PeiDb.Init.SizeTable :
196 gPcdDatabase->DxeDb.Init.SizeTable;
197
198
199 TokenNumber = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TokenNumber : (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);
200
201 return SizeTable[TokenNumber];
202 }
203
204
205
206 UINT8
207 EFIAPI
208 DxePcdGet8Ex (
209 IN CONST EFI_GUID *Guid,
210 IN UINTN ExTokenNumber
211 )
212 {
213 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));
214 }
215
216
217
218 UINT16
219 EFIAPI
220 DxePcdGet16Ex (
221 IN CONST EFI_GUID *Guid,
222 IN UINTN ExTokenNumber
223 )
224 {
225 return *((UINT16 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));
226 }
227
228
229
230 UINT32
231 EFIAPI
232 DxePcdGet32Ex (
233 IN CONST EFI_GUID *Guid,
234 IN UINTN ExTokenNumber
235 )
236 {
237 return *((UINT32 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));
238 }
239
240
241
242 UINT64
243 EFIAPI
244 DxePcdGet64Ex (
245 IN CONST EFI_GUID *Guid,
246 IN UINTN ExTokenNumber
247 )
248 {
249 //
250 // BugBug: Must be changed to ReadUnaligned64
251 //
252 return *((UINT64 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));
253 }
254
255
256
257 VOID *
258 EFIAPI
259 DxePcdGetPtrEx (
260 IN CONST EFI_GUID *Guid,
261 IN UINTN ExTokenNumber
262 )
263 {
264 return ExGetWorker (Guid, ExTokenNumber, 0);
265 }
266
267
268
269 BOOLEAN
270 EFIAPI
271 DxePcdGetBoolEx (
272 IN CONST EFI_GUID *Guid,
273 IN UINTN ExTokenNumber
274 )
275 {
276 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));
277 }
278
279
280
281 UINTN
282 EFIAPI
283 DxePcdGetSizeEx (
284 IN CONST EFI_GUID *Guid,
285 IN UINTN ExTokenNumber
286 )
287 {
288 EX_PCD_ENTRY_ATTRIBUTE Attr;
289
290 GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);
291
292 return Attr.Size;
293 }
294
295
296
297 EFI_STATUS
298 EFIAPI
299 DxePcdSet8 (
300 IN UINTN TokenNumber,
301 IN UINT8 Value
302 )
303 {
304 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
305 }
306
307
308
309 EFI_STATUS
310 EFIAPI
311 DxePcdSet16 (
312 IN UINTN TokenNumber,
313 IN UINT16 Value
314 )
315 {
316 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
317 }
318
319
320
321 EFI_STATUS
322 EFIAPI
323 DxePcdSet32 (
324 IN UINTN TokenNumber,
325 IN UINT32 Value
326 )
327 {
328 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
329 }
330
331
332
333 EFI_STATUS
334 EFIAPI
335 DxePcdSet64 (
336 IN UINTN TokenNumber,
337 IN UINT64 Value
338 )
339 {
340 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
341 }
342
343
344
345 EFI_STATUS
346 EFIAPI
347 DxePcdSetPtr (
348 IN UINTN TokenNumber,
349 IN CONST VOID *Value
350 )
351 {
352 //
353 // BugBug, please change the Size to Input size when sync with spec
354 //
355 //ASSERT (sizeof (Value) == DxePcdGetSize (TokenNumber));
356
357 return SetWorker (TokenNumber, (VOID *)Value, DxePcdGetSize (TokenNumber), TRUE);
358 }
359
360
361
362 EFI_STATUS
363 EFIAPI
364 DxePcdSetBool (
365 IN UINTN TokenNumber,
366 IN BOOLEAN Value
367 )
368 {
369 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
370 }
371
372
373
374 EFI_STATUS
375 EFIAPI
376 DxePcdSet8Ex (
377 IN CONST EFI_GUID *Guid,
378 IN UINTN ExTokenNumber,
379 IN UINT8 Value
380 )
381 {
382 return ExSetWorker(
383 ExTokenNumber,
384 Guid,
385 &Value,
386 sizeof (Value),
387 FALSE
388 );
389 }
390
391
392
393 EFI_STATUS
394 EFIAPI
395 DxePcdSet16Ex (
396 IN CONST EFI_GUID *Guid,
397 IN UINTN ExTokenNumber,
398 IN UINT16 Value
399 )
400 {
401 return ExSetWorker(
402 ExTokenNumber,
403 Guid,
404 &Value,
405 sizeof (Value),
406 FALSE
407 );
408 }
409
410
411
412 EFI_STATUS
413 EFIAPI
414 DxePcdSet32Ex (
415 IN CONST EFI_GUID *Guid,
416 IN UINTN ExTokenNumber,
417 IN UINT32 Value
418 )
419 {
420 return ExSetWorker(
421 ExTokenNumber,
422 Guid,
423 &Value,
424 sizeof (Value),
425 FALSE
426 );
427 }
428
429
430
431 EFI_STATUS
432 EFIAPI
433 DxePcdSet64Ex (
434 IN CONST EFI_GUID *Guid,
435 IN UINTN ExTokenNumber,
436 IN UINT64 Value
437 )
438 {
439 return ExSetWorker(
440 ExTokenNumber,
441 Guid,
442 &Value,
443 sizeof (Value),
444 FALSE
445 );
446 }
447
448
449
450 EFI_STATUS
451 EFIAPI
452 DxePcdSetPtrEx (
453 IN CONST EFI_GUID *Guid,
454 IN UINTN ExTokenNumber,
455 IN CONST VOID *Value
456 )
457 {
458 return ExSetWorker(
459 ExTokenNumber,
460 Guid,
461 (VOID *) Value,
462 sizeof (Value),
463 TRUE
464 );
465 }
466
467
468
469 EFI_STATUS
470 EFIAPI
471 DxePcdSetBoolEx (
472 IN CONST EFI_GUID *Guid,
473 IN UINTN ExTokenNumber,
474 IN BOOLEAN Value
475 )
476 {
477 return ExSetWorker(
478 ExTokenNumber,
479 Guid,
480 &Value,
481 sizeof (Value),
482 TRUE
483 );
484 }
485
486
487
488
489 EFI_STATUS
490 EFIAPI
491 PcdRegisterCallBackOnSet (
492 IN UINTN TokenNumber,
493 IN CONST EFI_GUID *Guid, OPTIONAL
494 IN PCD_PROTOCOL_CALLBACK CallBackFunction
495 )
496 {
497 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, TRUE);
498 }
499
500
501
502 EFI_STATUS
503 EFIAPI
504 PcdUnRegisterCallBackOnSet (
505 IN UINTN TokenNumber,
506 IN CONST EFI_GUID *Guid, OPTIONAL
507 IN PCD_PROTOCOL_CALLBACK CallBackFunction
508 )
509 {
510 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, FALSE);
511 }
512
513
514
515 EFI_STATUS
516 EFIAPI
517 DxePcdGetNextToken (
518 IN CONST EFI_GUID *Guid, OPTIONAL
519 IN OUT UINTN *TokenNumber
520 )
521 {
522 return DxeGetNextTokenWorker (TokenNumber, Guid);
523 }
524