4 This module contains all classes releted to PCD token.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.build
.pcd
.entity
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
20 import java
.util
.UUID
;
22 import org
.tianocore
.build
.pcd
.action
.ActionMessage
;
24 /** This class is to descript a PCD token object. The information of a token mainly
25 comes from MSA, SPD and setting produced by platform developer.
29 /// Enumeration macro defintion for PCD type.
30 /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed
32 public enum PCD_TYPE
{FEATURE_FLAG
, FIXED_AT_BUILD
, PATCHABLE_IN_MODULE
, DYNAMIC
,
36 /// Enumeration macro definition for datum type. All type mainly comes from ProcessBind.h.
37 /// Wizard maybe expand this type as "int, unsigned int, short, unsigned short etc" in
40 public enum DATUM_TYPE
{UINT8
, UINT16
, UINT32
, UINT64
, BOOLEAN
, POINTER
, UNKNOWN
}
43 /// Enumeration macor defintion for usage of PCD
45 public enum PCD_USAGE
{ALWAYS_PRODUCED
, ALWAYS_CONSUMED
, SOMETIMES_PRODUCED
,
46 SOMETIMES_CONSUMED
, UNKNOWN
}
49 /// cName is to identify a PCD entry and will be used for generating autogen.h/autogen.c.
50 /// cName will be defined in MSA, SPD and FPD, can be regarded as primary key with token space guid.
55 /// Token space name is the guid defined by token itself in package or module level. This
56 /// name mainly for DynamicEx type. For other PCD type token, his token space name is the
57 /// assignedtokenSpaceName as follows.
58 /// tokenSpaceName is defined in MSA, SPD, FPD, can be regarded as primary key with cName.
60 public UUID tokenSpaceName
;
63 /// tokenNumber is allocated by platform. tokenNumber indicate an index for this token in
64 /// platform token space.
65 /// tokenNumber is defined in SPD, FPD.
67 public int tokenNumber
;
70 /// The token space name assigned by platform. For Non-DynamicEx driver this value is same.
71 /// assignedtokenSpaceName is defined in FPD.
73 public UUID assignedtokenSpaceName
;
76 /// The token number assigned by platform. The number indiect the offset of this token in platform
78 /// AssgiendtokenNumber is defined in FPD.
80 public int assignedtokenNumber
;
83 /// pcdType is the PCD item type defined by platform developer.
85 public PCD_TYPE pcdType
;
88 /// PCDtype is set by platform developer. It is final PCD type of this token.
89 /// SupportedPcdType is defined in SPD.
91 public PCD_TYPE
[] supportedpcdType
;
94 /// datumSize is to descript the fix size or max size for this token.
95 /// datumSize is defined in SPD.
100 /// datum type is to descript what type can be expressed by a PCD token.
101 /// datumType is defined in SPD.
103 public DATUM_TYPE datumType
;
106 /// Isplatform is to descript whether this token is defined in platform level.
107 /// If token is belong to platform level. The value can be different for every
108 /// module. All are determined by platform developer.
110 public boolean isPlatform
;
113 /// hiiEnabled is to indicate whether the token support Hii functionality.
114 /// hiiEnabled is defined in FPD.
116 public boolean hiiEnabled
;
119 /// variableName is valid only when this token support Hii functionality. variableName
120 /// indicates the value of token is associated with what variable.
121 /// variableName is defined in FPD.
123 public String variableName
;
126 /// variableGuid is the GUID this token associated with.
127 /// variableGuid is defined in FPD.
129 public UUID variableGuid
;
132 /// Variable offset indicate the associated variable's offset in NV storage.
133 /// variableOffset is defined in FPD.
135 public int variableOffset
;
138 /// skuEnabled is to indicate whether the token support Sku functionality.
139 /// skuEnabled is defined in FPD.
141 public boolean skuEnabled
;
144 /// skuDataArrayEnabled is to indicate wheter use the skuData array or default value.
146 public boolean skuDataArrayEnabled
;
149 /// skuData contains all value for SkuNumber of token.
150 /// skuData is defined in FPD.
152 public List
<SkuInstance
> skuData
;
155 /// maxSkuCount indicate the max count of sku data.
156 /// maxSkuCount is defined in FPD.
158 public int maxSkuCount
;
161 /// SkuId is the id of current selected SKU.
162 /// SkuId is defined in FPD.
167 /// datum is the value set by platform developer.
168 /// datum is defined in FPD.
173 /// Default value of this token.
174 /// This default value is defined in SPD level.
176 public Object defaultValue
;
179 /// BUGBUG: fix comment
180 /// vpdEnabled is defined in FPD.
182 public boolean vpdEnabled
;
185 /// BUGBUG: fix comment
186 /// vpdOffset is defined in FPD.
188 public long vpdOffset
;
191 /// producers array record all module private information who produce this PCD token.
193 public List
<UsageInstance
> producers
;
196 /// consumers array record all module private information who consume this PCD token.
198 public List
<UsageInstance
> consumers
;
201 Constructure function.
203 Initialize the value of token.
205 @param cName The cName of this token
206 @param tokenSpaceName The tokenSpaceName of this token, it is a GUID.
207 @param assignedtokenSpaceName The assignedtokenSpaceName of this token, it is a GUID.
210 public Token(String cName
, UUID tokenSpaceName
, UUID assignedtokenSpaceName
) {
211 UUID nullUUID
= new UUID(0, 0);
214 this.tokenSpaceName
=(tokenSpaceName
== null) ? nullUUID
: tokenSpaceName
;
215 this.assignedtokenSpaceName
=(assignedtokenSpaceName
== null) ? nullUUID
: assignedtokenSpaceName
;
216 this.tokenNumber
= 0;
217 this.assignedtokenNumber
= 0;
218 this.pcdType
= PCD_TYPE
.UNKNOWN
;
219 this.supportedpcdType
= null;
220 this.isPlatform
= false;
221 this.datumType
= DATUM_TYPE
.UNKNOWN
;
223 this.defaultValue
= null;
225 this.hiiEnabled
= false;
226 this.variableGuid
= null;
227 this.variableName
= "";
228 this.variableOffset
= -1;
229 this.skuEnabled
= false;
230 this.skuDataArrayEnabled
= false;
232 this.maxSkuCount
= -1;
233 this.skuData
= new ArrayList
<SkuInstance
>();
234 this.vpdEnabled
= false;
237 this.producers
= new ArrayList
<UsageInstance
>();
238 this.consumers
= new ArrayList
<UsageInstance
>();
242 Use "TokencName + "-" + SpaceTokenName" as primary key when adding token into database
244 @param cName Token name.
245 @param tokenSpaceName The token space guid defined in MSA or SPD
246 @param platformtokenSpaceName The token space guid for current platform token space,
248 @return primary key for this token in token database.
250 public static String
getPrimaryKeyString(String cName
, UUID tokenSpaceName
,
251 UUID platformtokenSpaceName
) {
252 UUID nullUUID
= new UUID(0, 0);
254 if (platformtokenSpaceName
== nullUUID
) {
255 return cName
+ "-" + tokenSpaceName
.toString();
257 return cName
+ "-" + platformtokenSpaceName
.toString();
262 Judge datumType is valid
264 @param type The datumType want to be judged.
266 @retval TRUE - The type is valid.
267 @retval FALSE - The type is invalid.
269 public static boolean isValiddatumType(DATUM_TYPE type
) {
270 if ((type
.ordinal() < DATUM_TYPE
.UINT8
.ordinal() ) ||
271 (type
.ordinal() > DATUM_TYPE
.POINTER
.ordinal())) {
278 Judge pcdType is valid
280 @param type The PCdType want to be judged.
282 @retval TRUE - The type is valid.
283 @retval FALSE - The type is invalid.
285 public static boolean isValidpcdType(PCD_TYPE type
) {
286 if ((type
.ordinal() < PCD_TYPE
.FEATURE_FLAG
.ordinal() ) ||
287 (type
.ordinal() > PCD_TYPE
.DYNAMIC_EX
.ordinal())) {
294 Add an usage instance for token
296 @param usageInstance The usage instance
298 @retval TRUE - Success to add usage instance.
299 @retval FALSE - Fail to add usage instance
301 public boolean addUsageInstance(UsageInstance usageInstance
) {
302 if (usageInstance
.usage
== PCD_USAGE
.UNKNOWN
) {
306 if ((usageInstance
.usage
== PCD_USAGE
.ALWAYS_PRODUCED
) ||
307 (usageInstance
.usage
== PCD_USAGE
.SOMETIMES_PRODUCED
)) {
308 producers
.add(usageInstance
);
310 consumers
.add(usageInstance
);
316 Judge whether exist an usage instance for this token
318 @param moduleName Use xmlFilePath as keyword to search the usage instance
320 @retval PCD_USAGE - if UsageInstance exists.
321 @retval UNKNOWN - if UsageInstance does not exist, return UNKONW.
323 public PCD_USAGE
isUsageInstanceExist(String moduleName
) {
325 UsageInstance usageInstance
;
327 if (moduleName
== null) {
328 ActionMessage
.warning(this, "Error parameter for isUsageInstanceExist() function!");
329 return PCD_USAGE
.UNKNOWN
;
332 if (moduleName
.length() == 0) {
333 return PCD_USAGE
.UNKNOWN
;
337 // Searching the usage instance in module's producer and consumer according to
340 for (index
= 0; index
< producers
.size(); index
++) {
341 usageInstance
=(UsageInstance
)producers
.get(index
);
342 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
343 return usageInstance
.usage
;
347 for (index
= 0; index
< consumers
.size(); index
++) {
348 usageInstance
=(UsageInstance
)consumers
.get(index
);
349 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
350 return usageInstance
.usage
;
353 return PCD_USAGE
.UNKNOWN
;
357 Get usage instance according to a MSA file name
359 @param moduleName The file path string of MSA file.
361 @return usage instance object.
363 public UsageInstance
getUsageInstance(String moduleName
) {
365 UsageInstance usageInstance
;
367 if (moduleName
== null) {
368 ActionMessage
.warning(this, "Error parameter for isUsageInstanceExist() function!");
372 if (moduleName
.length() == 0) {
376 if (producers
.size() != 0) {
377 for (usageIndex
= 0; usageIndex
< producers
.size(); usageIndex
++) {
378 usageInstance
=(UsageInstance
)producers
.get(usageIndex
);
379 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
380 return usageInstance
;
385 if (consumers
.size() != 0) {
386 for (usageIndex
= 0; usageIndex
< consumers
.size(); usageIndex
++) {
387 usageInstance
=(UsageInstance
)consumers
.get(usageIndex
);
388 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
389 return usageInstance
;
397 Get the PCD_TYPE according to the string of PCD_TYPE
399 @param pcdTypeStr The string of PCD_TYPE
403 public static PCD_TYPE
getpcdTypeFromString(String pcdTypeStr
) {
404 if (pcdTypeStr
== null) {
405 return PCD_TYPE
.UNKNOWN
;
408 if (pcdTypeStr
.equalsIgnoreCase("FEATURE_FLAG")) {
409 return PCD_TYPE
.FEATURE_FLAG
;
410 } else if (pcdTypeStr
.equalsIgnoreCase("FIXED_AT_BUILD")) {
411 return PCD_TYPE
.FIXED_AT_BUILD
;
412 } else if (pcdTypeStr
.equalsIgnoreCase("PATCHABLE_IN_MODULE")) {
413 return PCD_TYPE
.PATCHABLE_IN_MODULE
;
414 } else if (pcdTypeStr
.equalsIgnoreCase("DYNAMIC")) {
415 return PCD_TYPE
.DYNAMIC
;
416 } else if (pcdTypeStr
.equalsIgnoreCase("DYNAMIC_EX")) {
417 return PCD_TYPE
.DYNAMIC_EX
;
419 return PCD_TYPE
.UNKNOWN
;
424 Get the string of given datumType. This string will be used for generating autogen files
426 @param datumType Given datumType
428 @return The string of datum type.
430 public static String
getStringOfdatumType(DATUM_TYPE datumType
) {
449 Get the datumType according to a string.
451 @param datumTypeStr The string of datumType
455 public static DATUM_TYPE
getdatumTypeFromString(String datumTypeStr
) {
456 if (datumTypeStr
.equalsIgnoreCase("UINT8")) {
457 return DATUM_TYPE
.UINT8
;
458 } else if (datumTypeStr
.equalsIgnoreCase("UINT16")) {
459 return DATUM_TYPE
.UINT16
;
460 } else if (datumTypeStr
.equalsIgnoreCase("UINT32")) {
461 return DATUM_TYPE
.UINT32
;
462 } else if (datumTypeStr
.equalsIgnoreCase("UINT64")) {
463 return DATUM_TYPE
.UINT64
;
464 } else if (datumTypeStr
.equalsIgnoreCase("VOID*")) {
465 return DATUM_TYPE
.POINTER
;
466 } else if (datumTypeStr
.equalsIgnoreCase("BOOLEAN")) {
467 return DATUM_TYPE
.BOOLEAN
;
469 return DATUM_TYPE
.UNKNOWN
;
473 Get string of given pcdType
475 @param pcdType The given PcdType
477 @return The string of PCD_TYPE.
479 public static String
getStringOfpcdType(PCD_TYPE pcdType
) {
482 return "FEATURE_FLAG";
484 return "FIXED_AT_BUILD";
485 case PATCHABLE_IN_MODULE
:
486 return "PATCHABLE_IN_MODULE";
496 Get the PCD_USAGE according to a string
498 @param usageStr The string of PCD_USAGE
500 @return The PCD_USAGE
502 public static PCD_USAGE
getUsageFromString(String usageStr
) {
503 if (usageStr
== null) {
504 return PCD_USAGE
.UNKNOWN
;
507 if (usageStr
.equalsIgnoreCase("ALWAYS_PRODUCED")) {
508 return PCD_USAGE
.ALWAYS_PRODUCED
;
509 } else if (usageStr
.equalsIgnoreCase("SOMETIMES_PRODUCED")) {
510 return PCD_USAGE
.SOMETIMES_PRODUCED
;
511 } else if (usageStr
.equalsIgnoreCase("ALWAYS_CONSUMED")) {
512 return PCD_USAGE
.ALWAYS_CONSUMED
;
513 } else if (usageStr
.equalsIgnoreCase("SOMETIMES_CONSUMED")) {
514 return PCD_USAGE
.SOMETIMES_CONSUMED
;
517 return PCD_USAGE
.UNKNOWN
;
521 Get the string of given PCD_USAGE
523 @param usage The given PCD_USAGE
525 @return The string of PDC_USAGE.
527 public static String
getStringOfUsage(PCD_USAGE usage
) {
529 case ALWAYS_PRODUCED
:
530 return "ALWAYS_PRODUCED";
531 case ALWAYS_CONSUMED
:
532 return "ALWAYS_CONSUMED";
533 case SOMETIMES_PRODUCED
:
534 return "SOMETIMES_PRODUCED";
535 case SOMETIMES_CONSUMED
:
536 return "SOMETIMES_CONSUMED";
542 Get the Defined datumType string for autogen. The string is for generating some MACROs in Autogen.h
544 @param datumType The given datumType
546 @return string of datum type for autogen.
548 public static String
GetAutogenDefinedatumTypeString(DATUM_TYPE datumType
) {
569 Get the datumType String for Autogen. This string will be used for generating defintions of PCD token in autogen
571 @param datumType The given datumType
573 @return string of datum type.
575 public static String
getAutogendatumTypeString(DATUM_TYPE datumType
) {
594 Get the datumType string for generating some MACROs in autogen file of Library
596 @param datumType The given datumType
598 @return String of datum for genrating bit charater.
600 public static String
getAutogenLibrarydatumTypeString(DATUM_TYPE datumType
) {
620 UUID defined in Schems is object, this function is to tranlate this object
623 @param uuidObj The object comes from schema.
625 @return The traslated UUID instance.
627 public static UUID
getGUIDFromSchemaObject(Object uuidObj
) {
629 if (uuidObj
.toString().equalsIgnoreCase("0")) {
630 uuid
= new UUID(0,0);
632 uuid
= UUID
.fromString(uuidObj
.toString());