4 This class indicate an usage instance for a PCD token. This instance maybe a module
5 or platform setting. When a module produce or cosume a PCD token, then this module
6 is an usage instance for this PCD token.
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 package org
.tianocore
.pcd
.entity
;
20 import org
.tianocore
.pcd
.entity
.CommonDefinition
;
21 import org
.tianocore
.pcd
.entity
.UsageIdentification
;
24 This class indicate an usage instance for a PCD token. This instance maybe a module
25 or platform setting. When a module produce or cosume a PCD token, then this module
26 is an usage instance for this PCD token.
28 public class UsageInstance
{
30 /// This parent that this usage instance belongs to.
32 public Token parentToken
;
35 /// ModuleIdentification for Usage Instance
37 public UsageIdentification usageId
;
40 /// Arch also is a key for a UsageInstance
45 /// The PCD type defined for module
47 public Token
.PCD_TYPE modulePcdType
;
50 /// The value of the PCD in this usage instance.
55 /// The maxDatumSize could be different for same PCD in different module
56 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
59 public int maxDatumSize
;
62 /// Autogen string for header file.
64 public String hAutogenStr
;
67 /// Auotgen string for C code file.
69 public String cAutogenStr
;
72 Constructure function for UsageInstance
74 @param parentToken The token instance for this usgaInstance
75 @param usageId The identification for usage instance
76 @param modulePcdType The PCD type for this usage instance
77 @param value The value of this PCD in this usage instance
78 @param maxDatumSize The max datum size of this PCD in this usage
81 public UsageInstance(Token parentToken
,
82 UsageIdentification usageId
,
83 Token
.PCD_TYPE modulePcdType
,
86 this.parentToken
= parentToken
;
87 this.usageId
= usageId
;
88 this.modulePcdType
= modulePcdType
;
90 this.maxDatumSize
= maxDatumSize
;
94 Get the primary key for usage instance array for every token.
96 @param usageId The identification of UsageInstance
98 @retval String The primary key for this usage instance
100 public static String
getPrimaryKey(UsageIdentification usageId
) {
101 return usageId
.toString();
105 Get primary key string for this usage instance
107 @return String primary key string
109 public String
getPrimaryKey() {
110 return UsageInstance
.getPrimaryKey(usageId
);
114 Judget whether current module is PEI driver
116 @return boolean whether current module is PEI driver
118 public boolean isPeiPhaseComponent() {
119 int moduleType
= CommonDefinition
.getModuleType(usageId
.moduleType
);
121 if ((moduleType
== CommonDefinition
.ModuleTypePeiCore
) ||
122 (moduleType
== CommonDefinition
.ModuleTypePeim
)) {
129 Judge whether current module is DXE driver.
131 @return boolean whether current module is DXE driver
133 public boolean isDxePhaseComponent() {
134 int moduleType
= CommonDefinition
.getModuleType(usageId
.moduleType
);
136 if ((moduleType
== CommonDefinition
.ModuleTypeDxeDriver
) ||
137 (moduleType
== CommonDefinition
.ModuleTypeDxeRuntimeDriver
) ||
138 (moduleType
== CommonDefinition
.ModuleTypeDxeSalDriver
) ||
139 (moduleType
== CommonDefinition
.ModuleTypeDxeSmmDriver
) ||
140 (moduleType
== CommonDefinition
.ModuleTypeUefiDriver
) ||
141 (moduleType
== CommonDefinition
.ModuleTypeUefiApplication
)
149 Generate autogen string for header file and C code file.
151 @param isBuildUsedLibrary whether the autogen is for library.
153 public void generateAutoGen(boolean isBuildUsedLibrary
) {
154 String guidStringCName
= null;
155 boolean isByteArray
= false;
156 String printDatum
= null;
157 String tokenNumberString
= null;
162 if (this.modulePcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
164 // For DYNAMIC_EX type PCD, use original token number in SPD or FPD to generate autogen
166 tokenNumberString
= Long
.toString(parentToken
.dynamicExTokenNumber
, 16);
169 // For Others type PCD, use autogenerated token number to generate autogen
171 tokenNumberString
= Long
.toString(parentToken
.tokenNumber
, 16);
174 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%s\r\n", parentToken
.cName
, tokenNumberString
);
177 // Judge the value of this PCD is byte array type
179 if (!isBuildUsedLibrary
&& !parentToken
.isDynamicPCD
) {
180 if (datum
.trim().charAt(0) == '{') {
186 // "ULL" should be added to value's tail for UINT64 value
188 if (parentToken
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
189 printDatum
= this.datum
+ "ULL";
191 printDatum
= this.datum
;
194 switch (modulePcdType
) {
197 // Example autogen string for following generation:
198 // "extern const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken";
200 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
203 // Example autogen string for following generation:
204 // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_FixedAtBuild_PcdSampleToken";
206 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
207 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
211 // Example autogen string for following generation:
212 // "//#define _PCD_SET_MODE_8_PcdSampleToken ASSERT(FALSE) If is not allowed to set value...";
214 hAutogenStr
+= String
.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) If is not allowed to set value for a FEATURE_FLAG PCD\r\n",
215 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
218 if (!isBuildUsedLibrary
) {
220 // Example autogen string for following generation:
221 // "#define _PCD_VALUE_PcdSampleToken 0x1000"
223 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
227 // Example autogen string for following generation:
228 // "GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken = _PCD_VALUE_PcdSampleToken;"
230 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
238 // Example autogen string for following generation:
239 // "extern const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken";
241 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
244 // Example autogen string for following generation:
245 // "#define _PCD_GET_MODE_8_PcdSampleToken (VOID*)_gPcd_FixedAtBuild_PcdSampleToken";
247 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
248 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
253 // Example autogen string for following generation:
254 // "extern const UINT8 _gPcd_FixedAtBuild_PcdSampleToken";
256 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
257 Token
.getAutogendatumTypeString(parentToken
.datumType
),
260 // Example autogen string for following generation:
261 // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_FixedAtBuild_PcdSampleToken";
263 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
264 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
270 // Example autogen string for following generation:
271 // "//#define _PCD_SET_MODE_8_PcdSampleToken ASSERT(FALSE) If is not allowed to set value...";
273 hAutogenStr
+= String
.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\r\n",
274 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
276 if (!isBuildUsedLibrary
) {
277 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
280 // Example autogen string for following generation:
281 // "#define _PCD_VALUE_PcdSampleToken (VOID*)_gPcd_FixedAtBuild_PcdSampleToken"
283 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
287 // Example autogen string for following generation:
288 // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = 'dfdf';"
290 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = %s;\r\n",
295 // Example autogen string for following generation:
296 // "#define _PCD_VALUE_PcdSampleToken 0x222"
298 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
302 // Example autogen string for following generation:
303 // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
305 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
306 Token
.getAutogendatumTypeString(parentToken
.datumType
),
312 // Example autogen string for following generation:
313 // "#define _PCD_VALUE_PcdSampleToken 0x222"
315 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
319 // Example autogen string for following generation:
320 // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
322 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
323 Token
.getAutogendatumTypeString(parentToken
.datumType
),
329 case PATCHABLE_IN_MODULE
:
330 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
332 // Example autogen string for following generation:
333 // "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken[];"
335 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
338 // Example autogen string for following generation:
339 // "#define _PCD_GET_MODE_8_PcdSampleToken (VOID*)_gPcd_BinaryPatch_PcdSampleToken"
341 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",
342 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
346 // Example autogen string for following generation:
347 // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_PcdSampleToken, (Buffer), (SizeOfBuffer))"
349 hAutogenStr
+= String
.format("#define _PCD_PATCHABLE_%s_SIZE %d\r\n",
351 parentToken
.datumSize
);
352 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) "+
353 "LibPatchPcdSetPtr (_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, "+
354 "(SizeOfBuffer), (Buffer))\r\n",
355 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
362 // Example autogen string for following generation:
363 // "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken;"
365 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
366 Token
.getAutogendatumTypeString(parentToken
.datumType
),
369 // Example autogen string for following generation:
370 // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_BinaryPatch_PcdSampleToken"
372 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
373 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
377 // Example autogen string for following generation:
378 // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) (_gPcd_BinaryPatch_PcdSampleToken = (Value))"
380 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",
381 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
386 if (!isBuildUsedLibrary
) {
387 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
388 printDatum
= parentToken
.getByteArrayForPointerDatum(printDatum
);
391 // Example autogen string for following generation:
392 // "#define _PCD_VALUE_PcdSampleToken 0x111"
394 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
397 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
399 // Example autogen string for following generation:
400 // "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
402 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[%d] = _PCD_VALUE_%s;\r\n",
404 parentToken
.datumSize
,
408 // Example autogen string for following generation:
409 // "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
411 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
412 Token
.getAutogendatumTypeString(parentToken
.datumType
),
421 // Example autogen string for following generation:
422 // "#define _PCD_GET_MODE_8_PcdSampleToken LibPcdGet%s(_PCD_TOKEN_PcdSampleToken)"
424 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
425 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
427 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
429 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
431 // Example autogen string for following generation:
432 // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_PcdSampleToken, (SizeOfBuffer), (Buffer))"
434 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
435 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
437 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
441 // Example autogen string for following generation:
442 // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) LibPcdSet%s(_PCD_TOKEN_PcdSampleToken, (Value))"
444 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",
445 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
447 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
452 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
453 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
456 // Example autogen string for following generation:
457 // "#define _PCD_GET_MODE_8_PcdSampleToken LibPcdGetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken)"
459 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
460 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
462 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
466 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
468 // Example autogen string for following generation:
469 // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) LibPcdSetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken, (SizeOfBuffer), (Buffer))"
471 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
472 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
474 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
479 // Example autogen string for following generation:
480 // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) LibPcdSetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken, (Value))"
482 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",
483 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
485 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
495 Get the autogen string for header file.
497 @return The string of header file.
499 public String
getHAutogenStr() {
504 Get the autogen string for C code file.
506 @return The string of C Code file.
508 public String
getCAutogenStr() {