5340ef5471bb222d9296b138d9fe7eab1fe65490
[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 VOID
101 EFIAPI
102 DxePcdSetSku (
103 IN SKU_ID SkuId
104 )
105 {
106 gPcdDatabase->PeiDb.Init.SystemSkuId = SkuId;
107
108 return;
109 }
110
111
112
113 UINT8
114 EFIAPI
115 DxePcdGet8 (
116 IN UINTN TokenNumber
117 )
118 {
119 ASSERT (sizeof (UINT8) == DxePcdGetSize (TokenNumber));
120
121 return *((UINT8 *) GetWorker (TokenNumber));
122 }
123
124
125
126 UINT16
127 EFIAPI
128 DxePcdGet16 (
129 IN UINTN TokenNumber
130 )
131 {
132 ASSERT (sizeof (UINT16) == DxePcdGetSize (TokenNumber));
133
134 return ReadUnaligned16 (GetWorker (TokenNumber));
135 }
136
137
138
139 UINT32
140 EFIAPI
141 DxePcdGet32 (
142 IN UINTN TokenNumber
143 )
144 {
145 ASSERT (sizeof (UINT32) == DxePcdGetSize (TokenNumber));
146
147 return ReadUnaligned32 (GetWorker (TokenNumber));
148 }
149
150
151
152 UINT64
153 EFIAPI
154 DxePcdGet64 (
155 IN UINTN TokenNumber
156 )
157 {
158 ASSERT (sizeof (UINT64) == DxePcdGetSize (TokenNumber));
159
160 return ReadUnaligned64(GetWorker (TokenNumber));
161 }
162
163
164
165 VOID *
166 EFIAPI
167 DxePcdGetPtr (
168 IN UINTN TokenNumber
169 )
170 {
171 return GetWorker (TokenNumber);
172 }
173
174
175
176 BOOLEAN
177 EFIAPI
178 DxePcdGetBool (
179 IN UINTN TokenNumber
180 )
181 {
182 ASSERT (sizeof (BOOLEAN) == DxePcdGetSize (TokenNumber));
183
184 return *((BOOLEAN *) GetWorker (TokenNumber));
185 }
186
187
188
189 UINTN
190 EFIAPI
191 DxePcdGetSize (
192 IN UINTN TokenNumber
193 )
194 {
195 UINT16 * SizeTable;
196
197 SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? gPcdDatabase->PeiDb.Init.SizeTable :
198 gPcdDatabase->DxeDb.Init.SizeTable;
199
200
201 TokenNumber = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TokenNumber : (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);
202
203 return SizeTable[TokenNumber];
204 }
205
206
207
208 UINT8
209 EFIAPI
210 DxePcdGet8Ex (
211 IN CONST EFI_GUID *Guid,
212 IN UINTN ExTokenNumber
213 )
214 {
215 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));
216 }
217
218
219
220 UINT16
221 EFIAPI
222 DxePcdGet16Ex (
223 IN CONST EFI_GUID *Guid,
224 IN UINTN ExTokenNumber
225 )
226 {
227 return *((UINT16 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));
228 }
229
230
231
232 UINT32
233 EFIAPI
234 DxePcdGet32Ex (
235 IN CONST EFI_GUID *Guid,
236 IN UINTN ExTokenNumber
237 )
238 {
239 return *((UINT32 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));
240 }
241
242
243
244 UINT64
245 EFIAPI
246 DxePcdGet64Ex (
247 IN CONST EFI_GUID *Guid,
248 IN UINTN ExTokenNumber
249 )
250 {
251 //
252 // BugBug: Must be changed to ReadUnaligned64
253 //
254 return *((UINT64 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));
255 }
256
257
258
259 VOID *
260 EFIAPI
261 DxePcdGetPtrEx (
262 IN CONST EFI_GUID *Guid,
263 IN UINTN ExTokenNumber
264 )
265 {
266 return ExGetWorker (Guid, ExTokenNumber, 0);
267 }
268
269
270
271 BOOLEAN
272 EFIAPI
273 DxePcdGetBoolEx (
274 IN CONST EFI_GUID *Guid,
275 IN UINTN ExTokenNumber
276 )
277 {
278 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));
279 }
280
281
282
283 UINTN
284 EFIAPI
285 DxePcdGetSizeEx (
286 IN CONST EFI_GUID *Guid,
287 IN UINTN ExTokenNumber
288 )
289 {
290 EX_PCD_ENTRY_ATTRIBUTE Attr;
291
292 GetExPcdTokenAttributes (Guid, ExTokenNumber, &Attr);
293
294 return Attr.Size;
295 }
296
297
298
299 EFI_STATUS
300 EFIAPI
301 DxePcdSet8 (
302 IN UINTN TokenNumber,
303 IN UINT8 Value
304 )
305 {
306 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
307 }
308
309
310
311 EFI_STATUS
312 EFIAPI
313 DxePcdSet16 (
314 IN UINTN TokenNumber,
315 IN UINT16 Value
316 )
317 {
318 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
319 }
320
321
322
323 EFI_STATUS
324 EFIAPI
325 DxePcdSet32 (
326 IN UINTN TokenNumber,
327 IN UINT32 Value
328 )
329 {
330 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
331 }
332
333
334
335 EFI_STATUS
336 EFIAPI
337 DxePcdSet64 (
338 IN UINTN TokenNumber,
339 IN UINT64 Value
340 )
341 {
342 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
343 }
344
345
346
347 EFI_STATUS
348 EFIAPI
349 DxePcdSetPtr (
350 IN UINTN TokenNumber,
351 IN UINTN SizeOfBuffer,
352 IN VOID *Buffer
353 )
354 {
355 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);
356 }
357
358
359
360 EFI_STATUS
361 EFIAPI
362 DxePcdSetBool (
363 IN UINTN TokenNumber,
364 IN BOOLEAN Value
365 )
366 {
367 return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
368 }
369
370
371
372 EFI_STATUS
373 EFIAPI
374 DxePcdSet8Ex (
375 IN CONST EFI_GUID *Guid,
376 IN UINTN ExTokenNumber,
377 IN UINT8 Value
378 )
379 {
380 return ExSetWorker(
381 ExTokenNumber,
382 Guid,
383 &Value,
384 sizeof (Value),
385 FALSE
386 );
387 }
388
389
390
391 EFI_STATUS
392 EFIAPI
393 DxePcdSet16Ex (
394 IN CONST EFI_GUID *Guid,
395 IN UINTN ExTokenNumber,
396 IN UINT16 Value
397 )
398 {
399 return ExSetWorker(
400 ExTokenNumber,
401 Guid,
402 &Value,
403 sizeof (Value),
404 FALSE
405 );
406 }
407
408
409
410 EFI_STATUS
411 EFIAPI
412 DxePcdSet32Ex (
413 IN CONST EFI_GUID *Guid,
414 IN UINTN ExTokenNumber,
415 IN UINT32 Value
416 )
417 {
418 return ExSetWorker(
419 ExTokenNumber,
420 Guid,
421 &Value,
422 sizeof (Value),
423 FALSE
424 );
425 }
426
427
428
429 EFI_STATUS
430 EFIAPI
431 DxePcdSet64Ex (
432 IN CONST EFI_GUID *Guid,
433 IN UINTN ExTokenNumber,
434 IN UINT64 Value
435 )
436 {
437 return ExSetWorker(
438 ExTokenNumber,
439 Guid,
440 &Value,
441 sizeof (Value),
442 FALSE
443 );
444 }
445
446
447
448 EFI_STATUS
449 EFIAPI
450 DxePcdSetPtrEx (
451 IN CONST EFI_GUID *Guid,
452 IN UINTN ExTokenNumber,
453 IN UINTN SizeOfBuffer,
454 IN VOID *Buffer
455 )
456 {
457 return ExSetWorker(
458 ExTokenNumber,
459 Guid,
460 Buffer,
461 SizeOfBuffer,
462 TRUE
463 );
464 }
465
466
467
468 EFI_STATUS
469 EFIAPI
470 DxePcdSetBoolEx (
471 IN CONST EFI_GUID *Guid,
472 IN UINTN ExTokenNumber,
473 IN BOOLEAN Value
474 )
475 {
476 return ExSetWorker(
477 ExTokenNumber,
478 Guid,
479 &Value,
480 sizeof (Value),
481 TRUE
482 );
483 }
484
485
486
487
488 EFI_STATUS
489 EFIAPI
490 PcdRegisterCallBackOnSet (
491 IN UINTN TokenNumber,
492 IN CONST EFI_GUID *Guid, OPTIONAL
493 IN PCD_PROTOCOL_CALLBACK CallBackFunction
494 )
495 {
496 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, TRUE);
497 }
498
499
500
501 EFI_STATUS
502 EFIAPI
503 PcdUnRegisterCallBackOnSet (
504 IN UINTN TokenNumber,
505 IN CONST EFI_GUID *Guid, OPTIONAL
506 IN PCD_PROTOCOL_CALLBACK CallBackFunction
507 )
508 {
509 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction, FALSE);
510 }
511
512
513
514 EFI_STATUS
515 EFIAPI
516 DxePcdGetNextToken (
517 IN CONST EFI_GUID *Guid, OPTIONAL
518 IN OUT UINTN *TokenNumber
519 )
520 {
521 return DxeGetNextTokenWorker (TokenNumber, Guid);
522 }
523