]>
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 |
11e7b0f6 | 214 | String guidStringCName = null;\r |
2435723a | 215 | boolean isByteArray = false;\r |
1cf9cdcc | 216 | String printDatum = null;\r |
38ee8d9e | 217 | \r |
218 | hAutogenStr = "";\r | |
219 | cAutogenStr = "";\r | |
220 | \r | |
221 | if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r | |
38ee8d9e | 222 | hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n", \r |
223 | parentToken.cName, parentToken.dynamicExTokenNumber);\r | |
224 | } else {\r | |
225 | hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n", \r | |
226 | parentToken.cName, parentToken.tokenNumber);\r | |
227 | }\r | |
228 | \r | |
2435723a | 229 | if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {\r |
230 | if (datum.trim().charAt(0) == '{') {\r | |
231 | isByteArray = true;\r | |
232 | }\r | |
233 | }\r | |
234 | \r | |
1cf9cdcc | 235 | if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {\r |
236 | printDatum = this.datum + "ULL";\r | |
237 | } else {\r | |
238 | printDatum = this.datum;\r | |
239 | }\r | |
240 | \r | |
38ee8d9e | 241 | switch (modulePcdType) {\r |
242 | case FEATURE_FLAG:\r | |
16d3e132 | 243 | hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r |
244 | parentToken.cName);\r | |
57a38e69 | 245 | hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r |
16d3e132 | 246 | parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
247 | parentToken.cName,\r | |
248 | parentToken.cName);\r | |
57a38e69 | 249 | 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 |
250 | parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
251 | parentToken.cName);\r | |
16d3e132 | 252 | \r |
253 | if (!isBuildUsedLibrary) {\r | |
38ee8d9e | 254 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
255 | parentToken.cName, \r | |
1cf9cdcc | 256 | printDatum);\r |
38ee8d9e | 257 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r |
258 | parentToken.cName,\r | |
259 | parentToken.cName);\r | |
38ee8d9e | 260 | }\r |
261 | break;\r | |
262 | case FIXED_AT_BUILD:\r | |
16d3e132 | 263 | if (isByteArray) {\r |
264 | hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",\r | |
265 | parentToken.cName);\r | |
57a38e69 | 266 | hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n", \r |
16d3e132 | 267 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
268 | parentToken.cName,\r | |
269 | parentToken.cName);\r | |
270 | } else {\r | |
38ee8d9e | 271 | hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r |
272 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
273 | parentToken.cName);\r | |
57a38e69 | 274 | hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", \r |
38ee8d9e | 275 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
276 | parentToken.cName,\r | |
277 | parentToken.cName);\r | |
16d3e132 | 278 | }\r |
279 | \r | |
57a38e69 | 280 | 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 |
281 | parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
282 | parentToken.cName);\r | |
16d3e132 | 283 | if (!isBuildUsedLibrary) {\r |
38ee8d9e | 284 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
285 | parentToken.cName, \r | |
1cf9cdcc | 286 | printDatum);\r |
2435723a | 287 | if (isByteArray) {\r |
288 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",\r | |
289 | parentToken.cName,\r | |
290 | parentToken.cName);\r | |
2435723a | 291 | } else {\r |
292 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r | |
293 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
294 | parentToken.cName,\r | |
295 | parentToken.cName);\r | |
2435723a | 296 | }\r |
38ee8d9e | 297 | }\r |
298 | break;\r | |
299 | case PATCHABLE_IN_MODULE:\r | |
16d3e132 | 300 | if (isByteArray) {\r |
301 | hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",\r | |
302 | parentToken.cName);\r | |
57a38e69 | 303 | hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",\r |
16d3e132 | 304 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
305 | parentToken.cName,\r | |
306 | parentToken.cName); \r | |
307 | } else {\r | |
38ee8d9e | 308 | hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r |
309 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
310 | parentToken.cName);\r | |
57a38e69 | 311 | hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r |
38ee8d9e | 312 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
313 | parentToken.cName,\r | |
16d3e132 | 314 | parentToken.cName); \r |
315 | }\r | |
316 | \r | |
57a38e69 | 317 | //\r |
318 | // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro\r | |
319 | // \r | |
320 | if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r | |
321 | hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n",\r | |
322 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
323 | parentToken.cName,\r | |
324 | parentToken.cName);\r | |
325 | } else {\r | |
326 | hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",\r | |
327 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
328 | parentToken.cName,\r | |
329 | parentToken.cName);\r | |
330 | }\r | |
331 | \r | |
16d3e132 | 332 | if (!isBuildUsedLibrary) {\r |
38ee8d9e | 333 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
334 | parentToken.cName, \r | |
1cf9cdcc | 335 | printDatum);\r |
2435723a | 336 | if (isByteArray) {\r |
337 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",\r | |
338 | parentToken.cName,\r | |
339 | parentToken.cName);\r | |
2435723a | 340 | } else {\r |
341 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r | |
342 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
343 | parentToken.cName,\r | |
344 | parentToken.cName);\r | |
2435723a | 345 | }\r |
38ee8d9e | 346 | }\r |
347 | \r | |
348 | break;\r | |
349 | case DYNAMIC:\r | |
57a38e69 | 350 | hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r |
38ee8d9e | 351 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
352 | parentToken.cName,\r | |
353 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
354 | parentToken.cName);\r | |
57a38e69 | 355 | if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r |
356 | hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r | |
357 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
358 | parentToken.cName,\r | |
359 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
360 | parentToken.cName);\r | |
361 | } else {\r | |
362 | hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",\r | |
363 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
364 | parentToken.cName,\r | |
365 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
366 | parentToken.cName);\r | |
367 | }\r | |
38ee8d9e | 368 | break;\r |
369 | case DYNAMIC_EX:\r | |
11e7b0f6 | 370 | guidStringCName = "_gPcd_TokenSpaceGuid_" +\r |
371 | parentToken.tokenSpaceName.toString().replaceAll("-", "_");\r | |
57a38e69 | 372 | \r |
373 | hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",\r | |
38ee8d9e | 374 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
375 | parentToken.cName,\r | |
376 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
a49b34c0 | 377 | guidStringCName,\r |
38ee8d9e | 378 | parentToken.cName);\r |
379 | \r | |
57a38e69 | 380 | if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r |
381 | hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r | |
382 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
383 | parentToken.cName,\r | |
384 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
385 | guidStringCName,\r | |
386 | parentToken.cName);\r | |
387 | } else {\r | |
388 | hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",\r | |
389 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
390 | parentToken.cName,\r | |
391 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
392 | guidStringCName,\r | |
393 | parentToken.cName);\r | |
394 | \r | |
395 | }\r | |
38ee8d9e | 396 | break;\r |
397 | }\r | |
398 | }\r | |
399 | \r | |
400 | /**\r | |
401 | Get the autogen string for header file.\r | |
402 | \r | |
403 | @return The string of header file.\r | |
404 | **/\r | |
405 | public String getHAutogenStr() {\r | |
406 | return hAutogenStr;\r | |
407 | }\r | |
878ddf1f | 408 | \r |
38ee8d9e | 409 | /**\r |
410 | Get the autogen string for C code file.\r | |
411 | \r | |
412 | @return The string of C Code file.\r | |
413 | **/\r | |
414 | public String getCAutogenStr() {\r | |
415 | return cAutogenStr;\r | |
878ddf1f | 416 | }\r |
878ddf1f | 417 | }\r |
418 | \r |