]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
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
.pcd
.exception
.EntityException
;
26 This class indicate an usage instance for a PCD token. This instance maybe a module
27 or platform setting. When a module produce or cosume a PCD token, then this module
28 is an usage instance for this PCD token.
30 public class UsageInstance
{
32 /// This parent that this usage instance belongs to.
34 public Token parentToken
;
37 /// The name of the module who contains this PCD.
39 public String moduleName
;
42 /// The GUID of the module who contains this PCD.
44 public UUID moduleGUID
;
47 /// The name of the package whose module contains this PCD.
49 public String packageName
;
52 /// The GUID of the package whose module contains this PCD.
54 public UUID packageGUID
;
57 /// The PCD type defined for module
59 public Token
.PCD_TYPE modulePcdType
;
62 /// The arch string of module contains this PCD
67 /// The version of module contains this PCD
69 public String version
;
72 /// The module type for this usage instance.
74 public ModuleTypeDef
.Enum moduleType
;
77 /// The value of the PCD in this usage instance.
82 /// The maxDatumSize could be different for same PCD in different module
83 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
86 public int maxDatumSize
;
89 /// Autogen string for header file.
91 public String hAutogenStr
;
94 /// Auotgen string for C code file.
96 public String cAutogenStr
;
101 @param parentToken Member variable.
102 @param moduleName Member variable.
103 @param moduleGUID Member variable.
104 @param packageName Member variable.
105 @param packageGUID Member variable.
106 @param moduleType Member variable.
107 @param modulePcdType Member variable.
108 @param arch Member variable.
109 @param version Member variable.
110 @param value Member variable.
111 @param maxDatumSize Member variable.
113 public UsageInstance (Token parentToken
,
118 ModuleTypeDef
.Enum moduleType
,
119 Token
.PCD_TYPE modulePcdType
,
124 this.parentToken
= parentToken
;
125 this.moduleName
= moduleName
;
126 this.moduleGUID
= moduleGUID
;
127 this.packageName
= packageName
;
128 this.packageGUID
= packageGUID
;
129 this.moduleType
= moduleType
;
130 this.modulePcdType
= modulePcdType
;
132 this.version
= version
;
134 this.maxDatumSize
= maxDatumSize
;
138 Get the primary key for usage instance array for every token.
140 @param moduleName the name of module
141 @param moduleGUID the GUID name of module
142 @param packageName the name of package who contains this module
143 @param packageGUID the GUID name of package
144 @param arch the archtecture string
145 @param version the version of this module
147 @return String primary key
149 public static String
getPrimaryKey(String moduleName
,
156 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in
157 // <ModuleSA> section, So currently no expect all paramter must be valid.
158 return(moduleName
+ "_" +
159 ((moduleGUID
!= null) ? moduleGUID
.toString() : "NullModuleGuid") + "_" +
160 ((packageName
!= null) ? packageName
: "NullPackageName") + "_" +
161 ((packageGUID
!= null) ? packageGUID
.toString() : "NullPackageGuid") + "_" +
162 ((arch
!= null) ? arch
: "NullArch") + "_" +
163 ((version
!= null) ? version
: "NullVersion"));
167 Get primary key string for this usage instance
169 @return String primary key string
171 public String
getPrimaryKey() {
172 return UsageInstance
.getPrimaryKey(moduleName
, moduleGUID
, packageName
, packageGUID
, arch
, version
);
176 Judget whether current module is PEI driver
180 public boolean isPeiPhaseComponent() {
181 if ((moduleType
== ModuleTypeDef
.PEI_CORE
) ||
182 (moduleType
== ModuleTypeDef
.PEIM
)) {
188 public boolean isDxePhaseComponent() {
190 // BugBug: May need confirmation on which type of module can
191 // make use of Dynamic(EX) PCD entry.
193 if ((moduleType
== ModuleTypeDef
.DXE_DRIVER
) ||
194 (moduleType
== ModuleTypeDef
.DXE_RUNTIME_DRIVER
) ||
195 (moduleType
== ModuleTypeDef
.DXE_SAL_DRIVER
) ||
196 (moduleType
== ModuleTypeDef
.DXE_SMM_DRIVER
) ||
197 (moduleType
== ModuleTypeDef
.UEFI_DRIVER
) ||
198 (moduleType
== ModuleTypeDef
.UEFI_APPLICATION
)
206 Generate autogen string for header file and C code file.
208 @throws EntityException Fail to generate.
210 @param isBuildUsedLibrary whether the autogen is for library.
212 public void generateAutoGen(boolean isBuildUsedLibrary
)
213 throws EntityException
{
214 String guidStringCName
= null;
215 boolean isByteArray
= false;
216 String printDatum
= null;
217 String tokenNumberString
= null;
222 if (this.modulePcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
223 tokenNumberString
= Long
.toString(parentToken
.dynamicExTokenNumber
, 16);
225 tokenNumberString
= Long
.toString(parentToken
.tokenNumber
, 16);
228 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%s\r\n",
229 parentToken
.cName
, tokenNumberString
);
231 if (!isBuildUsedLibrary
&& !parentToken
.isDynamicPCD
) {
232 if (datum
.trim().charAt(0) == '{') {
237 if (parentToken
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
238 printDatum
= this.datum
+ "ULL";
240 printDatum
= this.datum
;
243 switch (modulePcdType
) {
245 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
247 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
248 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
251 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",
252 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
255 if (!isBuildUsedLibrary
) {
256 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
259 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
266 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
268 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
269 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
273 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
274 Token
.getAutogendatumTypeString(parentToken
.datumType
),
276 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
277 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
282 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",
283 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
285 if (!isBuildUsedLibrary
) {
286 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
290 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
294 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
295 Token
.getAutogendatumTypeString(parentToken
.datumType
),
301 case PATCHABLE_IN_MODULE
:
303 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
305 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",
306 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
310 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
311 Token
.getAutogendatumTypeString(parentToken
.datumType
),
313 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
314 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
320 // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro
322 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
323 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n",
324 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
328 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",
329 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
334 if (!isBuildUsedLibrary
) {
335 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
339 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
343 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
344 Token
.getAutogendatumTypeString(parentToken
.datumType
),
352 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
353 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
355 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
357 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
358 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
359 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
361 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
364 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",
365 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
367 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
372 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
373 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
375 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
376 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
378 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
382 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
383 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
384 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
386 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
390 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",
391 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
393 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
403 Get the autogen string for header file.
405 @return The string of header file.
407 public String
getHAutogenStr() {
412 Get the autogen string for C code file.
414 @return The string of C Code file.
416 public String
getCAutogenStr() {