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
;
21 import java
.util
.UUID
;
23 import org
.tianocore
.ModuleTypeDef
;
24 import org
.tianocore
.pcd
.entity
.CommonDefinition
;
25 import org
.tianocore
.pcd
.entity
.UsageIdentification
;
26 import org
.tianocore
.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 UsageIdentification usageId
;
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 UsageIdentification usageId
,
88 Token
.PCD_TYPE modulePcdType
,
91 this.parentToken
= parentToken
;
92 this.usageId
= usageId
;
93 this.modulePcdType
= modulePcdType
;
95 this.maxDatumSize
= maxDatumSize
;
99 Get the primary key for usage instance array for every token.
101 @param usageId The identification of UsageInstance
103 @retval String The primary key for this usage instance
105 public static String
getPrimaryKey(UsageIdentification usageId
) {
106 return usageId
.toString();
110 Get primary key string for this usage instance
112 @return String primary key string
114 public String
getPrimaryKey() {
115 return UsageInstance
.getPrimaryKey(usageId
);
119 Judget whether current module is PEI driver
121 @return boolean whether current module is PEI driver
123 public boolean isPeiPhaseComponent() {
124 int moduleType
= CommonDefinition
.getModuleType(usageId
.moduleType
);
126 if ((moduleType
== CommonDefinition
.ModuleTypePeiCore
) ||
127 (moduleType
== CommonDefinition
.ModuleTypePeim
)) {
134 Judge whether current module is DXE driver.
136 @return boolean whether current module is DXE driver
138 public boolean isDxePhaseComponent() {
139 int moduleType
= CommonDefinition
.getModuleType(usageId
.moduleType
);
141 if ((moduleType
== CommonDefinition
.ModuleTypeDxeDriver
) ||
142 (moduleType
== CommonDefinition
.ModuleTypeDxeRuntimeDriver
) ||
143 (moduleType
== CommonDefinition
.ModuleTypeDxeSalDriver
) ||
144 (moduleType
== CommonDefinition
.ModuleTypeDxeSmmDriver
) ||
145 (moduleType
== CommonDefinition
.ModuleTypeUefiDriver
) ||
146 (moduleType
== CommonDefinition
.ModuleTypeUefiApplication
)
154 Generate autogen string for header file and C code file.
156 @param isBuildUsedLibrary whether the autogen is for library.
158 public void generateAutoGen(boolean isBuildUsedLibrary
) {
159 String guidStringCName
= null;
160 boolean isByteArray
= false;
161 String printDatum
= null;
162 String tokenNumberString
= null;
167 if (this.modulePcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
169 // For DYNAMIC_EX type PCD, use original token number in SPD or FPD to generate autogen
171 tokenNumberString
= Long
.toString(parentToken
.dynamicExTokenNumber
, 16);
174 // For Others type PCD, use autogenerated token number to generate autogen
176 tokenNumberString
= Long
.toString(parentToken
.tokenNumber
, 16);
179 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%s\r\n", parentToken
.cName
, tokenNumberString
);
182 // Judge the value of this PCD is byte array type
184 if (!isBuildUsedLibrary
&& !parentToken
.isDynamicPCD
) {
185 if (datum
.trim().charAt(0) == '{') {
191 // "ULL" should be added to value's tail for UINT64 value
193 if (parentToken
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
194 printDatum
= this.datum
+ "ULL";
196 printDatum
= this.datum
;
199 switch (modulePcdType
) {
201 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
203 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
204 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
207 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",
208 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
211 if (!isBuildUsedLibrary
) {
212 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
215 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
222 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
224 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
225 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
229 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
230 Token
.getAutogendatumTypeString(parentToken
.datumType
),
232 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
233 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
238 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",
239 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
241 if (!isBuildUsedLibrary
) {
242 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
244 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
247 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = %s;\r\n",
251 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
254 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
255 Token
.getAutogendatumTypeString(parentToken
.datumType
),
260 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
263 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
264 Token
.getAutogendatumTypeString(parentToken
.datumType
),
270 case PATCHABLE_IN_MODULE
:
272 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
274 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",
275 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
279 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
280 Token
.getAutogendatumTypeString(parentToken
.datumType
),
282 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
283 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
289 // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro
291 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
292 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n",
293 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
297 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",
298 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
303 if (!isBuildUsedLibrary
) {
304 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
308 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
312 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
313 Token
.getAutogendatumTypeString(parentToken
.datumType
),
321 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
322 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
324 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
326 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
327 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
328 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
330 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
333 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",
334 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
336 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
341 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
342 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
344 hAutogenStr
+= String
.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
345 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
347 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
351 if (parentToken
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
352 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
353 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
355 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
359 hAutogenStr
+= String
.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",
360 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
362 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
372 Get the autogen string for header file.
374 @return The string of header file.
376 public String
getHAutogenStr() {
381 Get the autogen string for C code file.
383 @return The string of C Code file.
385 public String
getCAutogenStr() {