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().replace('-', '_');
257 return cName
+ "_" + platformtokenSpaceName
.toString().replace('-', '_');
261 public String
getPrimaryKeyString () {
262 return cName
+ "_" + tokenSpaceName
.toString().replace('-', '_');
266 Judge datumType is valid
268 @param type The datumType want to be judged.
270 @retval TRUE - The type is valid.
271 @retval FALSE - The type is invalid.
273 public static boolean isValiddatumType(DATUM_TYPE type
) {
274 if ((type
.ordinal() < DATUM_TYPE
.UINT8
.ordinal() ) ||
275 (type
.ordinal() > DATUM_TYPE
.POINTER
.ordinal())) {
282 Judge pcdType is valid
284 @param type The PCdType want to be judged.
286 @retval TRUE - The type is valid.
287 @retval FALSE - The type is invalid.
289 public static boolean isValidpcdType(PCD_TYPE type
) {
290 if ((type
.ordinal() < PCD_TYPE
.FEATURE_FLAG
.ordinal() ) ||
291 (type
.ordinal() > PCD_TYPE
.DYNAMIC_EX
.ordinal())) {
298 Add an usage instance for token
300 @param usageInstance The usage instance
302 @retval TRUE - Success to add usage instance.
303 @retval FALSE - Fail to add usage instance
305 public boolean addUsageInstance(UsageInstance usageInstance
) {
306 if (usageInstance
.usage
== PCD_USAGE
.UNKNOWN
) {
310 if ((usageInstance
.usage
== PCD_USAGE
.ALWAYS_PRODUCED
) ||
311 (usageInstance
.usage
== PCD_USAGE
.SOMETIMES_PRODUCED
)) {
312 producers
.add(usageInstance
);
314 consumers
.add(usageInstance
);
320 Judge whether exist an usage instance for this token
322 @param moduleName Use xmlFilePath as keyword to search the usage instance
324 @retval PCD_USAGE - if UsageInstance exists.
325 @retval UNKNOWN - if UsageInstance does not exist, return UNKONW.
327 public PCD_USAGE
isUsageInstanceExist(String moduleName
) {
329 UsageInstance usageInstance
;
331 if (moduleName
== null) {
332 ActionMessage
.warning(this, "Error parameter for isUsageInstanceExist() function!");
333 return PCD_USAGE
.UNKNOWN
;
336 if (moduleName
.length() == 0) {
337 return PCD_USAGE
.UNKNOWN
;
341 // Searching the usage instance in module's producer and consumer according to
344 for (index
= 0; index
< producers
.size(); index
++) {
345 usageInstance
=(UsageInstance
)producers
.get(index
);
346 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
347 return usageInstance
.usage
;
351 for (index
= 0; index
< consumers
.size(); index
++) {
352 usageInstance
=(UsageInstance
)consumers
.get(index
);
353 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
354 return usageInstance
.usage
;
357 return PCD_USAGE
.UNKNOWN
;
361 Get usage instance according to a MSA file name
363 @param moduleName The file path string of MSA file.
365 @return usage instance object.
367 public UsageInstance
getUsageInstance(String moduleName
) {
369 UsageInstance usageInstance
;
371 if (moduleName
== null) {
372 ActionMessage
.warning(this, "Error parameter for isUsageInstanceExist() function!");
376 if (moduleName
.length() == 0) {
380 if (producers
.size() != 0) {
381 for (usageIndex
= 0; usageIndex
< producers
.size(); usageIndex
++) {
382 usageInstance
=(UsageInstance
)producers
.get(usageIndex
);
383 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
384 return usageInstance
;
389 if (consumers
.size() != 0) {
390 for (usageIndex
= 0; usageIndex
< consumers
.size(); usageIndex
++) {
391 usageInstance
=(UsageInstance
)consumers
.get(usageIndex
);
392 if (usageInstance
.moduleName
.equalsIgnoreCase(moduleName
)) {
393 return usageInstance
;
401 Get the PCD_TYPE according to the string of PCD_TYPE
403 @param pcdTypeStr The string of PCD_TYPE
407 public static PCD_TYPE
getpcdTypeFromString(String pcdTypeStr
) {
408 if (pcdTypeStr
== null) {
409 return PCD_TYPE
.UNKNOWN
;
412 if (pcdTypeStr
.equalsIgnoreCase("FEATURE_FLAG")) {
413 return PCD_TYPE
.FEATURE_FLAG
;
414 } else if (pcdTypeStr
.equalsIgnoreCase("FIXED_AT_BUILD")) {
415 return PCD_TYPE
.FIXED_AT_BUILD
;
416 } else if (pcdTypeStr
.equalsIgnoreCase("PATCHABLE_IN_MODULE")) {
417 return PCD_TYPE
.PATCHABLE_IN_MODULE
;
418 } else if (pcdTypeStr
.equalsIgnoreCase("DYNAMIC")) {
419 return PCD_TYPE
.DYNAMIC
;
420 } else if (pcdTypeStr
.equalsIgnoreCase("DYNAMIC_EX")) {
421 return PCD_TYPE
.DYNAMIC_EX
;
423 return PCD_TYPE
.UNKNOWN
;
428 Get the string of given datumType. This string will be used for generating autogen files
430 @param datumType Given datumType
432 @return The string of datum type.
434 public static String
getStringOfdatumType(DATUM_TYPE datumType
) {
453 Get the datumType according to a string.
455 @param datumTypeStr The string of datumType
459 public static DATUM_TYPE
getdatumTypeFromString(String datumTypeStr
) {
460 if (datumTypeStr
.equalsIgnoreCase("UINT8")) {
461 return DATUM_TYPE
.UINT8
;
462 } else if (datumTypeStr
.equalsIgnoreCase("UINT16")) {
463 return DATUM_TYPE
.UINT16
;
464 } else if (datumTypeStr
.equalsIgnoreCase("UINT32")) {
465 return DATUM_TYPE
.UINT32
;
466 } else if (datumTypeStr
.equalsIgnoreCase("UINT64")) {
467 return DATUM_TYPE
.UINT64
;
468 } else if (datumTypeStr
.equalsIgnoreCase("VOID*")) {
469 return DATUM_TYPE
.POINTER
;
470 } else if (datumTypeStr
.equalsIgnoreCase("BOOLEAN")) {
471 return DATUM_TYPE
.BOOLEAN
;
473 return DATUM_TYPE
.UNKNOWN
;
477 Get string of given pcdType
479 @param pcdType The given PcdType
481 @return The string of PCD_TYPE.
483 public static String
getStringOfpcdType(PCD_TYPE pcdType
) {
486 return "FEATURE_FLAG";
488 return "FIXED_AT_BUILD";
489 case PATCHABLE_IN_MODULE
:
490 return "PATCHABLE_IN_MODULE";
500 Get the PCD_USAGE according to a string
502 @param usageStr The string of PCD_USAGE
504 @return The PCD_USAGE
506 public static PCD_USAGE
getUsageFromString(String usageStr
) {
507 if (usageStr
== null) {
508 return PCD_USAGE
.UNKNOWN
;
511 if (usageStr
.equalsIgnoreCase("ALWAYS_PRODUCED")) {
512 return PCD_USAGE
.ALWAYS_PRODUCED
;
513 } else if (usageStr
.equalsIgnoreCase("SOMETIMES_PRODUCED")) {
514 return PCD_USAGE
.SOMETIMES_PRODUCED
;
515 } else if (usageStr
.equalsIgnoreCase("ALWAYS_CONSUMED")) {
516 return PCD_USAGE
.ALWAYS_CONSUMED
;
517 } else if (usageStr
.equalsIgnoreCase("SOMETIMES_CONSUMED")) {
518 return PCD_USAGE
.SOMETIMES_CONSUMED
;
521 return PCD_USAGE
.UNKNOWN
;
525 Get the string of given PCD_USAGE
527 @param usage The given PCD_USAGE
529 @return The string of PDC_USAGE.
531 public static String
getStringOfUsage(PCD_USAGE usage
) {
533 case ALWAYS_PRODUCED
:
534 return "ALWAYS_PRODUCED";
535 case ALWAYS_CONSUMED
:
536 return "ALWAYS_CONSUMED";
537 case SOMETIMES_PRODUCED
:
538 return "SOMETIMES_PRODUCED";
539 case SOMETIMES_CONSUMED
:
540 return "SOMETIMES_CONSUMED";
546 Get the Defined datumType string for autogen. The string is for generating some MACROs in Autogen.h
548 @param datumType The given datumType
550 @return string of datum type for autogen.
552 public static String
GetAutogenDefinedatumTypeString(DATUM_TYPE datumType
) {
573 Get the datumType String for Autogen. This string will be used for generating defintions of PCD token in autogen
575 @param datumType The given datumType
577 @return string of datum type.
579 public static String
getAutogendatumTypeString(DATUM_TYPE datumType
) {
598 Get the datumType string for generating some MACROs in autogen file of Library
600 @param datumType The given datumType
602 @return String of datum for genrating bit charater.
604 public static String
getAutogenLibrarydatumTypeString(DATUM_TYPE datumType
) {
624 UUID defined in Schems is object, this function is to tranlate this object
627 @param uuidObj The object comes from schema.
629 @return The traslated UUID instance.
631 public static UUID
getGUIDFromSchemaObject(Object uuidObj
) {
633 if (uuidObj
.toString().equalsIgnoreCase("0")) {
634 uuid
= new UUID(0,0);
636 uuid
= UUID
.fromString(uuidObj
.toString());
643 // BugBug: We need change this algorithm accordingly when schema is updated
644 // to support no default value.
646 public boolean hasDefaultValue () {
656 if (datum
.toString().compareTo("NoDefault") == 0) {
663 public boolean isStringType () {
664 String str
= datum
.toString();
666 if (datumType
== Token
.DATUM_TYPE
.POINTER
&&
667 str
.startsWith("L\"") &&
668 str
.endsWith("\"")) {
675 public String
getStringTypeString () {
676 return datum
.toString().substring(2, datum
.toString().length() - 1);