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
;
23 import org
.tianocore
.ModuleTypeDef
;
24 import org
.tianocore
.build
.autogen
.CommonDefinition
;
25 import org
.tianocore
.build
.id
.ModuleIdentification
;
26 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
29 This class indicate an usage instance for a PCD token. This instance maybe a module
30 or platform setting. When a module produce or cosume a PCD token, then this module
31 is an usage instance for this PCD token.
33 public class UsageInstance
{
35 /// This parent that this usage instance belongs to.
37 public Token parentToken
;
40 /// ModuleIdentification for Usage Instance
42 public ModuleIdentification moduleId
;
45 /// Arch also is a key for a UsageInstance
50 /// The PCD type defined for module
52 public Token
.PCD_TYPE modulePcdType
;
55 /// The value of the PCD in this usage instance.
60 /// The maxDatumSize could be different for same PCD in different module
61 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
64 public int maxDatumSize
;
67 /// Autogen string for header file.
69 public String hAutogenStr
;
72 /// Auotgen string for C code file.
74 public String cAutogenStr
;
77 Constructure function for UsageInstance
79 @param parentToken The token instance for this usgaInstance
80 @param id The identification for usage instance
81 @param modulePcdType The PCD type for this usage instance
82 @param value The value of this PCD in this usage instance
83 @param maxDatumSize The max datum size of this PCD in this usage
86 public UsageInstance(Token parentToken
,
87 ModuleIdentification moduleId
,
88 Token
.PCD_TYPE modulePcdType
,
92 this.parentToken
= parentToken
;
93 this.moduleId
= moduleId
;
94 this.modulePcdType
= modulePcdType
;
97 this.maxDatumSize
= maxDatumSize
;
101 Get the primary key for usage instance array for every token.
103 @param moduleId The module Identification for generating primary key
104 @param arch Arch string
106 @retval String The primary key for this usage instance
108 public static String
getPrimaryKey(ModuleIdentification moduleId
,
110 String moduleName
= moduleId
.getName();
111 String moduleGuid
= moduleId
.getGuid();
112 String packageName
= moduleId
.getPackage().getName();
113 String packageGuid
= moduleId
.getPackage().getGuid();
114 String version
= moduleId
.getVersion();
117 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in
118 // <ModuleSA> section, So currently no expect all paramter must be valid.
119 // BUGBUG: Because currently we can not get version from MSA, So ignore verison.
121 return(moduleName
+ "_" +
122 ((moduleGuid
!= null) ? moduleGuid
.toLowerCase() : "NullModuleGuid") + "_" +
123 ((packageName
!= null) ? packageName
: "NullPackageName") + "_" +
124 ((packageGuid
!= null) ? packageGuid
.toLowerCase() : "NullPackageGuid") + "_" +
125 ((arch
!= null) ? arch
: "NullArch") + "_" +
130 Get primary key string for this usage instance
132 @return String primary key string
134 public String
getPrimaryKey() {
135 return UsageInstance
.getPrimaryKey(moduleId
, arch
);
139 Judget whether current module is PEI driver
141 @return boolean whether current module is PEI driver
143 public boolean isPeiPhaseComponent() {
144 int moduleType
= CommonDefinition
.getModuleType(moduleId
.getModuleType());
146 if ((moduleType
== CommonDefinition
.ModuleTypePeiCore
) ||
147 (moduleType
== CommonDefinition
.ModuleTypePeim
)) {
154 Judge whether current module is DXE driver.
156 @return boolean whether current module is DXE driver
158 public boolean isDxePhaseComponent() {
159 int moduleType
= CommonDefinition
.getModuleType(moduleId
.getModuleType());
161 if ((moduleType
== CommonDefinition
.ModuleTypeDxeDriver
) ||
162 (moduleType
== CommonDefinition
.ModuleTypeDxeRuntimeDriver
) ||
163 (moduleType
== CommonDefinition
.ModuleTypeDxeSalDriver
) ||
164 (moduleType
== CommonDefinition
.ModuleTypeDxeSmmDriver
) ||
165 (moduleType
== CommonDefinition
.ModuleTypeUefiDriver
) ||
166 (moduleType
== CommonDefinition
.ModuleTypeUefiApplication
)
174 Generate autogen string for header file and C code file.
176 @param isBuildUsedLibrary whether the autogen is for library.
178 public void generateAutoGen(boolean isBuildUsedLibrary
) {
179 String guidStringCName
= null;
180 boolean isByteArray
= false;
181 String printDatum
= null;
182 String tokenNumberString
= null;
187 if (this.modulePcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
189 // For DYNAMIC_EX type PCD, use original token number in SPD or FPD to generate autogen
191 tokenNumberString
= Long
.toString(parentToken
.dynamicExTokenNumber
, 16);
194 // For Others type PCD, use autogenerated token number to generate autogen
196 tokenNumberString
= Long
.toString(parentToken
.tokenNumber
, 16);
199 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%s\r\n", parentToken
.cName
, tokenNumberString
);
202 // Judge the value of this PCD is byte array type
204 if (!isBuildUsedLibrary
&& !parentToken
.isDynamicPCD
) {
205 if (datum
.trim().charAt(0) == '{') {
211 // "ULL" should be added to value's tail for UINT64 value
213 if (parentToken
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
214 printDatum
= this.datum
+ "ULL";
216 printDatum
= this.datum
;
219 switch (modulePcdType
) {
221 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
223 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
224 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
227 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",
228 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
231 if (!isBuildUsedLibrary
) {
232 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
235 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
242 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
244 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
245 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
249 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
250 Token
.getAutogendatumTypeString(parentToken
.datumType
),
252 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
253 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
258 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",
259 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
261 if (!isBuildUsedLibrary
) {
262 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
264 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
267 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = %s;\r\n",
271 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
274 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
275 Token
.getAutogendatumTypeString(parentToken
.datumType
),
280 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
283 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
284 Token
.getAutogendatumTypeString(parentToken
.datumType
),
290 case PATCHABLE_IN_MODULE
:
292 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
294 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",
295 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
299 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
300 Token
.getAutogendatumTypeString(parentToken
.datumType
),
302 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
303 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
309 // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro
311 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
312 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n",
313 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
317 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",
318 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
323 if (!isBuildUsedLibrary
) {
324 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
328 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
332 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
333 Token
.getAutogendatumTypeString(parentToken
.datumType
),
341 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
342 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
344 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
346 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
347 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
348 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
350 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
353 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",
354 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
356 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
361 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
362 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
364 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
365 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
367 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
371 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
372 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
373 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
375 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
379 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",
380 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
382 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
392 Get the autogen string for header file.
394 @return The string of header file.
396 public String
getHAutogenStr() {
401 Get the autogen string for C code file.
403 @return The string of C Code file.
405 public String
getCAutogenStr() {