]>
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 | |
245 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r | |
246 | parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
247 | parentToken.cName,\r | |
248 | parentToken.cName);\r | |
249 | \r | |
250 | if (!isBuildUsedLibrary) {\r | |
38ee8d9e | 251 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
252 | parentToken.cName, \r | |
1cf9cdcc | 253 | printDatum);\r |
38ee8d9e | 254 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r |
255 | parentToken.cName,\r | |
256 | parentToken.cName);\r | |
38ee8d9e | 257 | }\r |
258 | break;\r | |
259 | case FIXED_AT_BUILD:\r | |
16d3e132 | 260 | if (isByteArray) {\r |
261 | hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",\r | |
262 | parentToken.cName);\r | |
263 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n", \r | |
264 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
265 | parentToken.cName,\r | |
266 | parentToken.cName);\r | |
267 | } else {\r | |
38ee8d9e | 268 | hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r |
269 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
270 | parentToken.cName);\r | |
16d3e132 | 271 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", \r |
38ee8d9e | 272 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
273 | parentToken.cName,\r | |
274 | parentToken.cName);\r | |
16d3e132 | 275 | }\r |
276 | \r | |
277 | if (!isBuildUsedLibrary) {\r | |
38ee8d9e | 278 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
279 | parentToken.cName, \r | |
1cf9cdcc | 280 | printDatum);\r |
2435723a | 281 | if (isByteArray) {\r |
282 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",\r | |
283 | parentToken.cName,\r | |
284 | parentToken.cName);\r | |
2435723a | 285 | } else {\r |
286 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r | |
287 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
288 | parentToken.cName,\r | |
289 | parentToken.cName);\r | |
2435723a | 290 | }\r |
38ee8d9e | 291 | }\r |
292 | break;\r | |
293 | case PATCHABLE_IN_MODULE:\r | |
16d3e132 | 294 | if (isByteArray) {\r |
295 | hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",\r | |
296 | parentToken.cName);\r | |
297 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",\r | |
298 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
299 | parentToken.cName,\r | |
300 | parentToken.cName); \r | |
301 | } else {\r | |
38ee8d9e | 302 | hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r |
303 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
304 | parentToken.cName);\r | |
305 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r | |
306 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
307 | parentToken.cName,\r | |
16d3e132 | 308 | parentToken.cName); \r |
309 | }\r | |
310 | \r | |
311 | if (!isBuildUsedLibrary) {\r | |
38ee8d9e | 312 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
313 | parentToken.cName, \r | |
1cf9cdcc | 314 | printDatum);\r |
2435723a | 315 | if (isByteArray) {\r |
316 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",\r | |
317 | parentToken.cName,\r | |
318 | parentToken.cName);\r | |
2435723a | 319 | } else {\r |
320 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r | |
321 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
322 | parentToken.cName,\r | |
323 | parentToken.cName);\r | |
2435723a | 324 | }\r |
38ee8d9e | 325 | }\r |
326 | \r | |
327 | break;\r | |
328 | case DYNAMIC:\r | |
329 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r | |
330 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
331 | parentToken.cName,\r | |
332 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
333 | parentToken.cName);\r | |
334 | break;\r | |
335 | case DYNAMIC_EX:\r | |
11e7b0f6 | 336 | guidStringCName = "_gPcd_TokenSpaceGuid_" +\r |
337 | parentToken.tokenSpaceName.toString().replaceAll("-", "_");\r | |
38ee8d9e | 338 | \r |
a49b34c0 | 339 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",\r |
38ee8d9e | 340 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
341 | parentToken.cName,\r | |
342 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
a49b34c0 | 343 | guidStringCName,\r |
38ee8d9e | 344 | parentToken.cName);\r |
345 | \r | |
38ee8d9e | 346 | break;\r |
347 | }\r | |
348 | }\r | |
349 | \r | |
350 | /**\r | |
351 | Get the autogen string for header file.\r | |
352 | \r | |
353 | @return The string of header file.\r | |
354 | **/\r | |
355 | public String getHAutogenStr() {\r | |
356 | return hAutogenStr;\r | |
357 | }\r | |
878ddf1f | 358 | \r |
38ee8d9e | 359 | /**\r |
360 | Get the autogen string for C code file.\r | |
361 | \r | |
362 | @return The string of C Code file.\r | |
363 | **/\r | |
364 | public String getCAutogenStr() {\r | |
365 | return cAutogenStr;\r | |
878ddf1f | 366 | }\r |
878ddf1f | 367 | }\r |
368 | \r |