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