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 |
878ddf1f |
22 | \r |
23 | import org.tianocore.build.autogen.CommonDefinition;\r |
8840ad58 |
24 | import org.tianocore.build.pcd.action.ActionMessage;\r |
25 | import org.tianocore.build.pcd.exception.EntityException;\r |
878ddf1f |
26 | \r |
27 | /**\r |
28 | This class indicate an usage instance for a PCD token. This instance maybe a module\r |
29 | or platform setting. When a module produce or cosume a PCD token, then this module\r |
30 | is an usage instance for this PCD token.\r |
31 | **/\r |
32 | public class UsageInstance {\r |
38ee8d9e |
33 | ///\r |
34 | /// The module type of usage instance.\r |
35 | /// \r |
36 | public enum MODULE_TYPE {SEC, PEI_CORE, PEIM, DXE_CORE, DXE_DRIVERS, OTHER_COMPONENTS}\r |
37 | \r |
38 | ///\r |
39 | /// This parent that this usage instance belongs to.\r |
40 | ///\r |
41 | public Token parentToken;\r |
42 | \r |
43 | ///\r |
44 | /// The name of the module who contains this PCD.\r |
45 | ///\r |
46 | public String moduleName;\r |
47 | \r |
48 | ///\r |
49 | /// The GUID of the module who contains this PCD. \r |
50 | /// \r |
51 | public UUID moduleGUID;\r |
52 | \r |
53 | ///\r |
54 | /// The name of the package whose module contains this PCD.\r |
55 | ///\r |
56 | public String packageName;\r |
57 | \r |
58 | ///\r |
59 | /// The GUID of the package whose module contains this PCD.\r |
60 | /// \r |
61 | public UUID packageGUID;\r |
62 | \r |
63 | ///\r |
64 | /// The PCD type defined for module \r |
65 | /// \r |
66 | public Token.PCD_TYPE modulePcdType;\r |
67 | \r |
68 | ///\r |
69 | /// The arch string of module contains this PCD\r |
70 | ///\r |
71 | public String arch;\r |
72 | \r |
73 | ///\r |
74 | /// The version of module contains this PCD\r |
75 | /// \r |
76 | public String version;\r |
77 | \r |
78 | ///\r |
79 | /// The module type for this usage instance.\r |
80 | ///\r |
81 | public MODULE_TYPE moduleType;\r |
82 | \r |
83 | ///\r |
84 | /// The value of the PCD in this usage instance. \r |
85 | /// \r |
86 | public String datum;\r |
87 | \r |
88 | ///\r |
89 | /// The maxDatumSize could be different for same PCD in different module\r |
90 | /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule\r |
91 | /// type.\r |
92 | /// \r |
93 | public int maxDatumSize;\r |
94 | \r |
95 | ///\r |
96 | /// Autogen string for header file.\r |
97 | ///\r |
98 | public String hAutogenStr;\r |
99 | \r |
100 | ///\r |
101 | /// Auotgen string for C code file.\r |
102 | /// \r |
103 | public String cAutogenStr;\r |
104 | \r |
105 | /**\r |
106 | Constructure function\r |
107 | \r |
108 | @param parentToken Member variable.\r |
109 | @param moduleName Member variable.\r |
110 | @param moduleGUID Member variable.\r |
111 | @param packageName Member variable.\r |
112 | @param packageGUID Member variable.\r |
113 | @param moduleType Member variable.\r |
114 | @param modulePcdType Member variable.\r |
115 | @param arch Member variable.\r |
116 | @param version Member variable.\r |
117 | @param value Member variable.\r |
118 | @param maxDatumSize Member variable.\r |
119 | */\r |
120 | public UsageInstance (Token parentToken,\r |
121 | String moduleName,\r |
122 | UUID moduleGUID,\r |
123 | String packageName,\r |
124 | UUID packageGUID,\r |
125 | MODULE_TYPE moduleType,\r |
126 | Token.PCD_TYPE modulePcdType,\r |
127 | String arch,\r |
128 | String version,\r |
129 | String value,\r |
130 | int maxDatumSize) {\r |
131 | this.parentToken = parentToken;\r |
132 | this.moduleName = moduleName;\r |
133 | this.moduleGUID = moduleGUID;\r |
134 | this.packageName = packageName;\r |
135 | this.packageGUID = packageGUID;\r |
136 | this.moduleType = moduleType;\r |
137 | this.modulePcdType = modulePcdType;\r |
138 | this.arch = arch;\r |
139 | this.version = version;\r |
140 | this.datum = value;\r |
141 | this.maxDatumSize = maxDatumSize;\r |
142 | }\r |
143 | \r |
144 | /**\r |
145 | Get the primary key for usage instance array for every token.\r |
146 | \r |
147 | @param moduleName the name of module\r |
148 | @param moduleGUID the GUID name of module\r |
149 | @param packageName the name of package who contains this module\r |
150 | @param packageGUID the GUID name of package\r |
151 | @param arch the archtecture string\r |
152 | @param version the version of this module\r |
153 | \r |
154 | @return String primary key\r |
155 | */\r |
156 | public static String getPrimaryKey(String moduleName, \r |
157 | UUID moduleGUID, \r |
158 | String packageName, \r |
159 | UUID packageGUID,\r |
160 | String arch,\r |
161 | String version) {\r |
162 | //\r |
163 | // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in\r |
164 | // <ModuleSA> section, So currently no expect all paramter must be valid.\r |
165 | return(moduleName + "_" +\r |
166 | ((moduleGUID != null) ? moduleGUID.toString() : "NullModuleGuid") + "_" +\r |
167 | ((packageName != null) ? packageName : "NullPackageName") + "_" +\r |
168 | ((packageGUID != null) ? packageGUID.toString() : "NullPackageGuid") + "_" +\r |
169 | ((arch != null) ? arch : "NullArch") + "_" +\r |
170 | ((version != null) ? version : "NullVersion"));\r |
171 | }\r |
172 | \r |
173 | /**\r |
174 | Get primary key string for this usage instance\r |
175 | \r |
176 | @return String primary key string\r |
177 | **/\r |
178 | public String getPrimaryKey() {\r |
179 | return UsageInstance.getPrimaryKey(moduleName, moduleGUID, packageName, packageGUID, arch, version);\r |
180 | }\r |
181 | \r |
182 | /**\r |
183 | Judget whether current module is PEI driver\r |
184 | \r |
185 | @return boolean\r |
186 | */\r |
187 | public boolean isPeiPhaseComponent() {\r |
188 | if ((moduleType == MODULE_TYPE.PEI_CORE) ||\r |
189 | (moduleType == MODULE_TYPE.PEIM)) {\r |
190 | return true;\r |
191 | }\r |
192 | return false;\r |
193 | }\r |
194 | \r |
195 | /**\r |
196 | Generate autogen string for header file and C code file.\r |
197 | \r |
198 | @throws EntityException Fail to generate.\r |
199 | \r |
200 | @param isBuildUsedLibrary whether the autogen is for library.\r |
201 | */\r |
202 | public void generateAutoGen(boolean isBuildUsedLibrary) \r |
8840ad58 |
203 | throws EntityException {\r |
38ee8d9e |
204 | String guidStringArray[] = null;\r |
205 | String guidString = null;\r |
2435723a |
206 | boolean isByteArray = false;\r |
1cf9cdcc |
207 | String printDatum = null;\r |
38ee8d9e |
208 | \r |
209 | hAutogenStr = "";\r |
210 | cAutogenStr = "";\r |
211 | \r |
212 | if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r |
213 | hAutogenStr += String.format("#define _PCD_LOCAL_TOKEN_%s 0x%016x\r\n", \r |
214 | parentToken.cName, parentToken.tokenNumber);\r |
215 | hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n", \r |
216 | parentToken.cName, parentToken.dynamicExTokenNumber);\r |
217 | } else {\r |
218 | hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n", \r |
219 | parentToken.cName, parentToken.tokenNumber);\r |
220 | }\r |
221 | \r |
2435723a |
222 | if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {\r |
223 | if (datum.trim().charAt(0) == '{') {\r |
224 | isByteArray = true;\r |
225 | }\r |
226 | }\r |
227 | \r |
1cf9cdcc |
228 | if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {\r |
229 | printDatum = this.datum + "ULL";\r |
230 | } else {\r |
231 | printDatum = this.datum;\r |
232 | }\r |
233 | \r |
38ee8d9e |
234 | switch (modulePcdType) {\r |
235 | case FEATURE_FLAG:\r |
236 | if (isBuildUsedLibrary) {\r |
237 | hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r |
238 | parentToken.cName);\r |
239 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r |
240 | parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
241 | parentToken.cName,\r |
242 | parentToken.cName);\r |
243 | } else {\r |
244 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
245 | parentToken.cName, \r |
1cf9cdcc |
246 | printDatum);\r |
38ee8d9e |
247 | hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r |
248 | parentToken.cName);\r |
249 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r |
250 | parentToken.cName,\r |
251 | parentToken.cName);\r |
252 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",\r |
253 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
254 | parentToken.cName,\r |
255 | parentToken.cName);\r |
256 | }\r |
257 | break;\r |
258 | case FIXED_AT_BUILD:\r |
259 | if (isBuildUsedLibrary) {\r |
260 | hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r |
261 | Token.getAutogendatumTypeString(parentToken.datumType),\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 |
268 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
269 | parentToken.cName, \r |
1cf9cdcc |
270 | printDatum);\r |
2435723a |
271 | if (isByteArray) {\r |
272 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",\r |
273 | parentToken.cName,\r |
274 | parentToken.cName);\r |
275 | hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",\r |
276 | parentToken.cName);\r |
277 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",\r |
278 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
279 | parentToken.cName,\r |
280 | parentToken.cName);\r |
281 | } else {\r |
282 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r |
283 | Token.getAutogendatumTypeString(parentToken.datumType),\r |
284 | parentToken.cName,\r |
285 | parentToken.cName);\r |
286 | hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r |
287 | Token.getAutogendatumTypeString(parentToken.datumType),\r |
288 | parentToken.cName);\r |
289 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",\r |
290 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
291 | parentToken.cName,\r |
292 | parentToken.cName);\r |
293 | }\r |
38ee8d9e |
294 | }\r |
295 | break;\r |
296 | case PATCHABLE_IN_MODULE:\r |
297 | if (isBuildUsedLibrary) {\r |
298 | hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r |
299 | Token.getAutogendatumTypeString(parentToken.datumType),\r |
300 | parentToken.cName);\r |
301 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r |
302 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
303 | parentToken.cName,\r |
304 | parentToken.cName);\r |
305 | } else {\r |
306 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r |
307 | parentToken.cName, \r |
1cf9cdcc |
308 | printDatum);\r |
2435723a |
309 | if (isByteArray) {\r |
310 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",\r |
311 | parentToken.cName,\r |
312 | parentToken.cName);\r |
313 | hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",\r |
314 | parentToken.cName);\r |
315 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",\r |
316 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
317 | parentToken.cName,\r |
318 | parentToken.cName); \r |
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 |
324 | hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r |
325 | Token.getAutogendatumTypeString(parentToken.datumType),\r |
326 | parentToken.cName);\r |
327 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r |
328 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
329 | parentToken.cName,\r |
330 | parentToken.cName); \r |
331 | }\r |
38ee8d9e |
332 | }\r |
333 | \r |
334 | break;\r |
335 | case DYNAMIC:\r |
336 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r |
337 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
338 | parentToken.cName,\r |
339 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r |
340 | parentToken.cName);\r |
341 | break;\r |
342 | case DYNAMIC_EX:\r |
343 | guidStringArray = parentToken.tokenSpaceName.toString().split("-");\r |
344 | guidString = String.format("{ 0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",\r |
345 | guidStringArray[0],\r |
346 | guidStringArray[1],\r |
347 | guidStringArray[2],\r |
348 | (guidStringArray[3].substring(0, 2)),\r |
349 | (guidStringArray[3].substring(2, 4)),\r |
350 | (guidStringArray[4].substring(0, 2)),\r |
351 | (guidStringArray[4].substring(2, 4)),\r |
352 | (guidStringArray[4].substring(4, 6)),\r |
353 | (guidStringArray[4].substring(6, 8)),\r |
354 | (guidStringArray[4].substring(8, 10)),\r |
355 | (guidStringArray[4].substring(10, 12)));\r |
356 | \r |
357 | hAutogenStr += String.format("extern EFI_GUID _gPcd_DynamicEx_TokenSpaceGuid_%s;\r\n",\r |
358 | parentToken.cName);\r |
359 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_LOCAL_TOKEN_%s)\r\n",\r |
360 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r |
361 | parentToken.cName,\r |
362 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r |
363 | parentToken.cName,\r |
364 | parentToken.cName);\r |
365 | \r |
366 | if (!isBuildUsedLibrary) {\r |
367 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID _gPcd_DynamicEx_TokenSpaceGuid_%s = %s;\r\n",\r |
368 | parentToken.cName,\r |
369 | guidString);\r |
370 | }\r |
371 | break;\r |
372 | }\r |
373 | }\r |
374 | \r |
375 | /**\r |
376 | Get the autogen string for header file.\r |
377 | \r |
378 | @return The string of header file.\r |
379 | **/\r |
380 | public String getHAutogenStr() {\r |
381 | return hAutogenStr;\r |
382 | }\r |
878ddf1f |
383 | \r |
38ee8d9e |
384 | /**\r |
385 | Get the autogen string for C code file.\r |
386 | \r |
387 | @return The string of C Code file.\r |
388 | **/\r |
389 | public String getCAutogenStr() {\r |
390 | return cAutogenStr;\r |
878ddf1f |
391 | }\r |
878ddf1f |
392 | }\r |
393 | \r |