Added some additional comments in the files, as well as fixed some of them.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / entity / UsageInstance.java
CommitLineData
878ddf1f 1/** @file\r
2 UsageInstance class.\r
3\r
4 This class indicate an usage instance for a PCD token. This instance maybe a module\r
5 or platform setting. When a module produce or cosume a PCD token, then this module\r
6 is an usage instance for this PCD token.\r
7 \r
8Copyright (c) 2006, Intel Corporation\r
9All rights reserved. This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13 \r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/ \r
18package org.tianocore.build.pcd.entity;\r
19\r
20\r
8840ad58 21import java.util.UUID;\r
03b1a72d 22import org.tianocore.ModuleTypeDef;\r
136adffc 23import org.tianocore.build.autogen.CommonDefinition;\r
8840ad58 24import org.tianocore.build.pcd.exception.EntityException;\r
878ddf1f 25\r
26/**\r
27 This class indicate an usage instance for a PCD token. This instance maybe a module\r
28 or platform setting. When a module produce or cosume a PCD token, then this module\r
29 is an usage instance for this PCD token.\r
30**/\r
31public class UsageInstance {\r
38ee8d9e 32 ///\r
33 /// This parent that this usage instance belongs to.\r
34 ///\r
35 public Token parentToken;\r
36\r
37 ///\r
38 /// The name of the module who contains this PCD.\r
39 ///\r
40 public String moduleName;\r
41\r
42 ///\r
43 /// The GUID of the module who contains this PCD. \r
44 /// \r
45 public UUID moduleGUID;\r
46\r
47 ///\r
48 /// The name of the package whose module contains this PCD.\r
49 ///\r
50 public String packageName;\r
51\r
52 ///\r
53 /// The GUID of the package whose module contains this PCD.\r
54 /// \r
55 public UUID packageGUID;\r
56\r
57 ///\r
58 /// The PCD type defined for module \r
59 /// \r
60 public Token.PCD_TYPE modulePcdType;\r
61\r
62 ///\r
63 /// The arch string of module contains this PCD\r
64 ///\r
65 public String arch;\r
66\r
67 ///\r
68 /// The version of module contains this PCD\r
69 /// \r
70 public String version;\r
71\r
72 ///\r
73 /// The module type for this usage instance.\r
74 ///\r
136adffc 75 public int moduleType;\r
38ee8d9e 76\r
77 ///\r
78 /// The value of the PCD in this usage instance. \r
79 /// \r
80 public String datum;\r
81\r
82 ///\r
83 /// The maxDatumSize could be different for same PCD in different module\r
84 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule\r
85 /// type.\r
86 /// \r
87 public int maxDatumSize;\r
88\r
89 ///\r
90 /// Autogen string for header file.\r
91 ///\r
92 public String hAutogenStr;\r
93\r
94 ///\r
95 /// Auotgen string for C code file.\r
96 /// \r
97 public String cAutogenStr;\r
98\r
99 /**\r
100 Constructure function\r
101 \r
102 @param parentToken Member variable.\r
103 @param moduleName Member variable.\r
104 @param moduleGUID Member variable.\r
105 @param packageName Member variable.\r
106 @param packageGUID Member variable.\r
107 @param moduleType Member variable.\r
108 @param modulePcdType Member variable.\r
109 @param arch Member variable.\r
110 @param version Member variable.\r
111 @param value Member variable.\r
112 @param maxDatumSize Member variable.\r
113 */\r
114 public UsageInstance (Token parentToken,\r
115 String moduleName,\r
116 UUID moduleGUID,\r
117 String packageName,\r
118 UUID packageGUID,\r
136adffc 119 int moduleType,\r
38ee8d9e 120 Token.PCD_TYPE modulePcdType,\r
121 String arch,\r
122 String version,\r
123 String value,\r
124 int maxDatumSize) {\r
125 this.parentToken = parentToken;\r
126 this.moduleName = moduleName;\r
127 this.moduleGUID = moduleGUID;\r
128 this.packageName = packageName;\r
129 this.packageGUID = packageGUID;\r
130 this.moduleType = moduleType;\r
131 this.modulePcdType = modulePcdType;\r
132 this.arch = arch;\r
133 this.version = version;\r
134 this.datum = value;\r
135 this.maxDatumSize = maxDatumSize;\r
136 }\r
137\r
138 /**\r
139 Get the primary key for usage instance array for every token.\r
140 \r
141 @param moduleName the name of module\r
142 @param moduleGUID the GUID name of module\r
143 @param packageName the name of package who contains this module\r
144 @param packageGUID the GUID name of package\r
145 @param arch the archtecture string\r
146 @param version the version of this module\r
147 \r
148 @return String primary key\r
149 */\r
150 public static String getPrimaryKey(String moduleName, \r
151 UUID moduleGUID, \r
152 String packageName, \r
153 UUID packageGUID,\r
154 String arch,\r
155 String version) {\r
156 //\r
157 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in\r
158 // <ModuleSA> section, So currently no expect all paramter must be valid.\r
159 return(moduleName + "_" +\r
160 ((moduleGUID != null) ? moduleGUID.toString() : "NullModuleGuid") + "_" +\r
161 ((packageName != null) ? packageName : "NullPackageName") + "_" +\r
162 ((packageGUID != null) ? packageGUID.toString() : "NullPackageGuid") + "_" +\r
163 ((arch != null) ? arch : "NullArch") + "_" +\r
164 ((version != null) ? version : "NullVersion"));\r
165 }\r
166\r
167 /**\r
168 Get primary key string for this usage instance\r
169 \r
170 @return String primary key string\r
171 **/\r
172 public String getPrimaryKey() {\r
173 return UsageInstance.getPrimaryKey(moduleName, moduleGUID, packageName, packageGUID, arch, version);\r
174 }\r
175\r
176 /**\r
177 Judget whether current module is PEI driver\r
178 \r
179 @return boolean\r
180 */\r
181 public boolean isPeiPhaseComponent() {\r
136adffc 182 if ((moduleType == CommonDefinition.ModuleTypePeiCore) ||\r
183 (moduleType == CommonDefinition.ModuleTypePeim)) {\r
38ee8d9e 184 return true;\r
185 }\r
186 return false;\r
187 }\r
58f1099f 188 \r
189 public boolean isDxePhaseComponent() {\r
190 //\r
191 // BugBug: May need confirmation on which type of module can\r
192 // make use of Dynamic(EX) PCD entry.\r
193 //\r
136adffc 194 if ((moduleType == CommonDefinition.ModuleTypeDxeDriver) ||\r
195 (moduleType == CommonDefinition.ModuleTypeDxeRuntimeDriver) ||\r
196 (moduleType == CommonDefinition.ModuleTypeDxeSalDriver) ||\r
197 (moduleType == CommonDefinition.ModuleTypeDxeSmmDriver) ||\r
198 (moduleType == CommonDefinition.ModuleTypeUefiDriver) ||\r
199 (moduleType == CommonDefinition.ModuleTypeUefiApplication)\r
58f1099f 200 ) {\r
201 return true;\r
202 }\r
203 return false;\r
204 }\r
38ee8d9e 205\r
206 /**\r
207 Generate autogen string for header file and C code file.\r
208 \r
209 @throws EntityException Fail to generate.\r
210 \r
211 @param isBuildUsedLibrary whether the autogen is for library.\r
212 */\r
213 public void generateAutoGen(boolean isBuildUsedLibrary) \r
a49b34c0 214 throws EntityException {\r
51da9e80 215 String guidStringCName = null;\r
216 boolean isByteArray = false;\r
217 String printDatum = null;\r
218 String tokenNumberString = null;\r
38ee8d9e 219\r
220 hAutogenStr = "";\r
221 cAutogenStr = "";\r
222\r
223 if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
51da9e80 224 tokenNumberString = Long.toString(parentToken.dynamicExTokenNumber, 16);\r
38ee8d9e 225 } else {\r
51da9e80 226 tokenNumberString = Long.toString(parentToken.tokenNumber, 16);\r
38ee8d9e 227 }\r
228\r
51da9e80 229 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%s\r\n", \r
230 parentToken.cName, tokenNumberString);\r
231 \r
2435723a 232 if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {\r
233 if (datum.trim().charAt(0) == '{') {\r
234 isByteArray = true;\r
235 }\r
236 }\r
237\r
1cf9cdcc 238 if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {\r
239 printDatum = this.datum + "ULL";\r
240 } else {\r
241 printDatum = this.datum;\r
242 }\r
243\r
38ee8d9e 244 switch (modulePcdType) {\r
245 case FEATURE_FLAG:\r
16d3e132 246 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r
247 parentToken.cName);\r
57a38e69 248 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r
16d3e132 249 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
250 parentToken.cName,\r
251 parentToken.cName);\r
57a38e69 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",\r
253 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
254 parentToken.cName);\r
16d3e132 255\r
256 if (!isBuildUsedLibrary) {\r
38ee8d9e 257 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
258 parentToken.cName, \r
1cf9cdcc 259 printDatum);\r
38ee8d9e 260 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
261 parentToken.cName,\r
262 parentToken.cName);\r
38ee8d9e 263 }\r
264 break;\r
265 case FIXED_AT_BUILD:\r
16d3e132 266 if (isByteArray) {\r
267 hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",\r
268 parentToken.cName);\r
57a38e69 269 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n", \r
16d3e132 270 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
271 parentToken.cName,\r
272 parentToken.cName);\r
273 } else {\r
38ee8d9e 274 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r
275 Token.getAutogendatumTypeString(parentToken.datumType),\r
276 parentToken.cName);\r
57a38e69 277 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", \r
38ee8d9e 278 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
279 parentToken.cName,\r
280 parentToken.cName);\r
16d3e132 281 }\r
282\r
57a38e69 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",\r
284 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
285 parentToken.cName);\r
16d3e132 286 if (!isBuildUsedLibrary) {\r
38ee8d9e 287 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
288 parentToken.cName, \r
1cf9cdcc 289 printDatum);\r
2435723a 290 if (isByteArray) {\r
291 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",\r
292 parentToken.cName,\r
293 parentToken.cName);\r
2435723a 294 } else {\r
295 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
296 Token.getAutogendatumTypeString(parentToken.datumType),\r
297 parentToken.cName,\r
298 parentToken.cName);\r
2435723a 299 }\r
38ee8d9e 300 }\r
301 break;\r
302 case PATCHABLE_IN_MODULE:\r
16d3e132 303 if (isByteArray) {\r
304 hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",\r
305 parentToken.cName);\r
57a38e69 306 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",\r
16d3e132 307 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
308 parentToken.cName,\r
309 parentToken.cName); \r
310 } else {\r
38ee8d9e 311 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r
312 Token.getAutogendatumTypeString(parentToken.datumType),\r
313 parentToken.cName);\r
57a38e69 314 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r
38ee8d9e 315 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
316 parentToken.cName,\r
16d3e132 317 parentToken.cName); \r
318 }\r
319\r
57a38e69 320 //\r
321 // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro\r
322 // \r
323 if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
324 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n",\r
325 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
326 parentToken.cName,\r
327 parentToken.cName);\r
328 } else {\r
329 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",\r
330 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
331 parentToken.cName,\r
332 parentToken.cName);\r
333 }\r
334 \r
16d3e132 335 if (!isBuildUsedLibrary) {\r
38ee8d9e 336 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
337 parentToken.cName, \r
1cf9cdcc 338 printDatum);\r
2435723a 339 if (isByteArray) {\r
340 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",\r
341 parentToken.cName,\r
342 parentToken.cName);\r
2435723a 343 } else {\r
344 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r
345 Token.getAutogendatumTypeString(parentToken.datumType),\r
346 parentToken.cName,\r
347 parentToken.cName);\r
2435723a 348 }\r
38ee8d9e 349 }\r
350\r
351 break;\r
352 case DYNAMIC:\r
57a38e69 353 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r
38ee8d9e 354 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
355 parentToken.cName,\r
356 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
357 parentToken.cName);\r
57a38e69 358 if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
359 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r
360 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
361 parentToken.cName,\r
362 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
363 parentToken.cName);\r
364 } else {\r
365 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",\r
366 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
367 parentToken.cName,\r
368 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
369 parentToken.cName);\r
370 }\r
38ee8d9e 371 break;\r
372 case DYNAMIC_EX:\r
11e7b0f6 373 guidStringCName = "_gPcd_TokenSpaceGuid_" +\r
374 parentToken.tokenSpaceName.toString().replaceAll("-", "_");\r
57a38e69 375\r
376 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",\r
38ee8d9e 377 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
378 parentToken.cName,\r
379 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
a49b34c0 380 guidStringCName,\r
38ee8d9e 381 parentToken.cName);\r
382\r
57a38e69 383 if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
384 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r
385 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
386 parentToken.cName,\r
387 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
388 guidStringCName,\r
389 parentToken.cName);\r
390 } else {\r
391 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",\r
392 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
393 parentToken.cName,\r
394 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
395 guidStringCName,\r
396 parentToken.cName);\r
397\r
398 }\r
38ee8d9e 399 break;\r
400 }\r
401 }\r
402\r
403 /**\r
404 Get the autogen string for header file.\r
405 \r
406 @return The string of header file.\r
407 **/\r
408 public String getHAutogenStr() {\r
409 return hAutogenStr;\r
410 }\r
878ddf1f 411\r
38ee8d9e 412 /**\r
413 Get the autogen string for C code file.\r
414 \r
415 @return The string of C Code file.\r
416 **/\r
417 public String getCAutogenStr() {\r
418 return cAutogenStr;\r
878ddf1f 419 }\r
878ddf1f 420}\r
421\r