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