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
.build
.pcd
.entity
;
21 import java
.util
.UUID
;
22 import org
.tianocore
.ModuleTypeDef
;
23 import org
.tianocore
.build
.autogen
.CommonDefinition
;
24 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
27 This class indicate an usage instance for a PCD token. This instance maybe a module
28 or platform setting. When a module produce or cosume a PCD token, then this module
29 is an usage instance for this PCD token.
31 public class UsageInstance
{
33 /// This parent that this usage instance belongs to.
35 public Token parentToken
;
38 /// The name of the module who contains this PCD.
40 public String moduleName
;
43 /// The GUID of the module who contains this PCD.
45 public UUID moduleGUID
;
48 /// The name of the package whose module contains this PCD.
50 public String packageName
;
53 /// The GUID of the package whose module contains this PCD.
55 public UUID packageGUID
;
58 /// The PCD type defined for module
60 public Token
.PCD_TYPE modulePcdType
;
63 /// The arch string of module contains this PCD
68 /// The version of module contains this PCD
70 public String version
;
73 /// The module type for this usage instance.
75 public int moduleType
;
78 /// The value of the PCD in this usage instance.
83 /// The maxDatumSize could be different for same PCD in different module
84 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
87 public int maxDatumSize
;
90 /// Autogen string for header file.
92 public String hAutogenStr
;
95 /// Auotgen string for C code file.
97 public String cAutogenStr
;
100 Constructure function
102 @param parentToken Member variable.
103 @param moduleName Member variable.
104 @param moduleGUID Member variable.
105 @param packageName Member variable.
106 @param packageGUID Member variable.
107 @param moduleType Member variable.
108 @param modulePcdType Member variable.
109 @param arch Member variable.
110 @param version Member variable.
111 @param value Member variable.
112 @param maxDatumSize Member variable.
114 public UsageInstance (Token parentToken
,
120 Token
.PCD_TYPE modulePcdType
,
125 this.parentToken
= parentToken
;
126 this.moduleName
= moduleName
;
127 this.moduleGUID
= moduleGUID
;
128 this.packageName
= packageName
;
129 this.packageGUID
= packageGUID
;
130 this.moduleType
= moduleType
;
131 this.modulePcdType
= modulePcdType
;
133 this.version
= version
;
135 this.maxDatumSize
= maxDatumSize
;
139 Get the primary key for usage instance array for every token.
141 @param moduleName the name of module
142 @param moduleGUID the GUID name of module
143 @param packageName the name of package who contains this module
144 @param packageGUID the GUID name of package
145 @param arch the archtecture string
146 @param version the version of this module
148 @return String primary key
150 public static String
getPrimaryKey(String moduleName
,
157 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in
158 // <ModuleSA> section, So currently no expect all paramter must be valid.
159 return(moduleName
+ "_" +
160 ((moduleGUID
!= null) ? moduleGUID
.toString() : "NullModuleGuid") + "_" +
161 ((packageName
!= null) ? packageName
: "NullPackageName") + "_" +
162 ((packageGUID
!= null) ? packageGUID
.toString() : "NullPackageGuid") + "_" +
163 ((arch
!= null) ? arch
: "NullArch") + "_" +
164 ((version
!= null) ? version
: "NullVersion"));
168 Get primary key string for this usage instance
170 @return String primary key string
172 public String
getPrimaryKey() {
173 return UsageInstance
.getPrimaryKey(moduleName
, moduleGUID
, packageName
, packageGUID
, arch
, version
);
177 Judget whether current module is PEI driver
181 public boolean isPeiPhaseComponent() {
182 if ((moduleType
== CommonDefinition
.ModuleTypePeiCore
) ||
183 (moduleType
== CommonDefinition
.ModuleTypePeim
)) {
189 public boolean isDxePhaseComponent() {
191 // BugBug: May need confirmation on which type of module can
192 // make use of Dynamic(EX) PCD entry.
194 if ((moduleType
== CommonDefinition
.ModuleTypeDxeDriver
) ||
195 (moduleType
== CommonDefinition
.ModuleTypeDxeRuntimeDriver
) ||
196 (moduleType
== CommonDefinition
.ModuleTypeDxeSalDriver
) ||
197 (moduleType
== CommonDefinition
.ModuleTypeDxeSmmDriver
) ||
198 (moduleType
== CommonDefinition
.ModuleTypeUefiDriver
) ||
199 (moduleType
== CommonDefinition
.ModuleTypeUefiApplication
)
207 Generate autogen string for header file and C code file.
209 @throws EntityException Fail to generate.
211 @param isBuildUsedLibrary whether the autogen is for library.
213 public void generateAutoGen(boolean isBuildUsedLibrary
)
214 throws EntityException
{
215 String guidStringCName
= null;
216 boolean isByteArray
= false;
217 String printDatum
= null;
218 String tokenNumberString
= null;
223 if (this.modulePcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
224 tokenNumberString
= Long
.toString(parentToken
.dynamicExTokenNumber
, 16);
226 tokenNumberString
= Long
.toString(parentToken
.tokenNumber
, 16);
229 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%s\r\n",
230 parentToken
.cName
, tokenNumberString
);
232 if (!isBuildUsedLibrary
&& !parentToken
.isDynamicPCD
) {
233 if (datum
.trim().charAt(0) == '{') {
238 if (parentToken
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
239 printDatum
= this.datum
+ "ULL";
241 printDatum
= this.datum
;
244 switch (modulePcdType
) {
246 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
248 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
249 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
252 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",
253 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
256 if (!isBuildUsedLibrary
) {
257 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
260 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
267 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
269 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
270 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
274 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
275 Token
.getAutogendatumTypeString(parentToken
.datumType
),
277 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
278 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
283 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",
284 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
286 if (!isBuildUsedLibrary
) {
287 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
291 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
295 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
296 Token
.getAutogendatumTypeString(parentToken
.datumType
),
302 case PATCHABLE_IN_MODULE
:
304 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
306 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",
307 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
311 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
312 Token
.getAutogendatumTypeString(parentToken
.datumType
),
314 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
315 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
321 // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro
323 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
324 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n",
325 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
329 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",
330 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
335 if (!isBuildUsedLibrary
) {
336 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
340 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
344 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
345 Token
.getAutogendatumTypeString(parentToken
.datumType
),
353 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
354 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
356 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
358 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
359 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
360 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
362 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
365 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",
366 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
368 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
373 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
374 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
376 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
377 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
379 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
383 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
384 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
385 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
387 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
391 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",
392 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
394 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
404 Get the autogen string for header file.
406 @return The string of header file.
408 public String
getHAutogenStr() {
413 Get the autogen string for C code file.
415 @return The string of C Code file.
417 public String
getCAutogenStr() {