Skip to content

Commit

Permalink
UefiCpuPkg/RegisterCpuFeaturesLib: Support combo CPU feature style.
Browse files Browse the repository at this point in the history
Current code assume only one dependence (before or after) for one
feature. Enhance code logic to support feature has two dependence
(before and after) type.

Cc: Ruiyu Ni <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong <[email protected]>
Reviewed-by: Ruiyu Ni <[email protected]>
  • Loading branch information
ydong10 committed Oct 26, 2018
1 parent 901ae29 commit 1475b83
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,11 @@ AnalysisProcessorFeatures (
// If feature has dependence with the next feature (ONLY care core/package dependency).
// and feature initialize succeed, add sync semaphere here.
//
BeforeDep = DetectFeatureScope (CpuFeatureInOrder, TRUE);
if (NextCpuFeatureInOrder != NULL) {
AfterDep = DetectFeatureScope (NextCpuFeatureInOrder, FALSE);
BeforeDep = DetectFeatureScope (CpuFeatureInOrder, TRUE, NextCpuFeatureInOrder->FeatureMask);
AfterDep = DetectFeatureScope (NextCpuFeatureInOrder, FALSE, CpuFeatureInOrder->FeatureMask);
} else {
BeforeDep = DetectFeatureScope (CpuFeatureInOrder, TRUE, NULL);
AfterDep = NoneDepType;
}
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,17 @@ DumpCpuFeature (
/**
Return feature dependence result.
@param[in] CpuFeature Pointer to CPU feature.
@param[in] Before Check before dependence or after.
@param[in] CpuFeature Pointer to CPU feature.
@param[in] Before Check before dependence or after.
@param[in] NextCpuFeatureMask Pointer to next CPU feature Mask.
@retval return the dependence result.
**/
CPU_FEATURE_DEPENDENCE_TYPE
DetectFeatureScope (
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before
IN BOOLEAN Before,
IN CHAR8 *NextCpuFeatureMask
);

/**
Expand Down
99 changes: 37 additions & 62 deletions UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,90 +115,69 @@ IsBitMaskMatchCheck (
/**
Return feature dependence result.
@param[in] CpuFeature Pointer to CPU feature.
@param[in] Before Check before dependence or after.
@param[in] CpuFeature Pointer to CPU feature.
@param[in] Before Check before dependence or after.
@param[in] NextCpuFeatureMask Pointer to next CPU feature Mask.
@retval return the dependence result.
**/
CPU_FEATURE_DEPENDENCE_TYPE
DetectFeatureScope (
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before
IN BOOLEAN Before,
IN CHAR8 *NextCpuFeatureMask
)
{
//
// if need to check before type dependence but the feature after current feature is not
// exist, means this before type dependence not valid, just return NoneDepType.
// Just like Feature A has a dependence of feature B, but Feature B not installed, so
// Feature A maybe insert to the last entry of the list. In this case, for below code,
// Featrure A has depend of feature B, but it is the last entry of the list, so the
// NextCpuFeatureMask is NULL, so the dependence for feature A here is useless and code
// just return NoneDepType.
//
if (NextCpuFeatureMask == NULL) {
return NoneDepType;
}

if (Before) {
if (CpuFeature->PackageBeforeFeatureBitMask != NULL) {
if ((CpuFeature->PackageBeforeFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->PackageBeforeFeatureBitMask)) {
return PackageDepType;
}

if (CpuFeature->CoreBeforeFeatureBitMask != NULL) {
if ((CpuFeature->CoreBeforeFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->CoreBeforeFeatureBitMask)) {
return CoreDepType;
}

if (CpuFeature->BeforeFeatureBitMask != NULL) {
if ((CpuFeature->BeforeFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->BeforeFeatureBitMask)) {
return ThreadDepType;
}

return NoneDepType;
}

if (CpuFeature->PackageAfterFeatureBitMask != NULL) {
if ((CpuFeature->PackageAfterFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->PackageAfterFeatureBitMask)) {
return PackageDepType;
}

if (CpuFeature->CoreAfterFeatureBitMask != NULL) {
if ((CpuFeature->CoreAfterFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->CoreAfterFeatureBitMask)) {
return CoreDepType;
}

if (CpuFeature->AfterFeatureBitMask != NULL) {
if ((CpuFeature->AfterFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->AfterFeatureBitMask)) {
return ThreadDepType;
}

return NoneDepType;
}

/**
Clear dependence for the specified type.
@param[in] CpuFeature Cpu feature need to clear.
@param[in] Before Before or after dependence relationship.
**/
VOID
ClearFeatureScope (
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before
)
{
if (Before) {
if (CpuFeature->BeforeFeatureBitMask != NULL) {
FreePool (CpuFeature->BeforeFeatureBitMask);
CpuFeature->BeforeFeatureBitMask = NULL;
}
if (CpuFeature->CoreBeforeFeatureBitMask != NULL) {
FreePool (CpuFeature->CoreBeforeFeatureBitMask);
CpuFeature->CoreBeforeFeatureBitMask = NULL;
}
if (CpuFeature->PackageBeforeFeatureBitMask != NULL) {
FreePool (CpuFeature->PackageBeforeFeatureBitMask);
CpuFeature->PackageBeforeFeatureBitMask = NULL;
}
} else {
if (CpuFeature->PackageAfterFeatureBitMask != NULL) {
FreePool (CpuFeature->PackageAfterFeatureBitMask);
CpuFeature->PackageAfterFeatureBitMask = NULL;
}
if (CpuFeature->CoreAfterFeatureBitMask != NULL) {
FreePool (CpuFeature->CoreAfterFeatureBitMask);
CpuFeature->CoreAfterFeatureBitMask = NULL;
}
if (CpuFeature->AfterFeatureBitMask != NULL) {
FreePool (CpuFeature->AfterFeatureBitMask);
CpuFeature->AfterFeatureBitMask = NULL;
}
}
}

/**
Base on dependence relationship to asjust feature dependence.
Expand All @@ -209,6 +188,7 @@ ClearFeatureScope (
@param[in, out] PreviousFeature CPU feature current before the find one.
@param[in, out] CurrentFeature Cpu feature need to adjust.
@param[in] FindFeature Cpu feature which current feature depends.
@param[in] Before Before or after dependence relationship.
@retval TRUE means the current feature dependence has been adjusted.
Expand All @@ -221,14 +201,15 @@ BOOLEAN
AdjustFeaturesDependence (
IN OUT CPU_FEATURES_ENTRY *PreviousFeature,
IN OUT CPU_FEATURES_ENTRY *CurrentFeature,
IN CPU_FEATURES_ENTRY *FindFeature,
IN BOOLEAN Before
)
{
CPU_FEATURE_DEPENDENCE_TYPE PreDependType;
CPU_FEATURE_DEPENDENCE_TYPE CurrentDependType;

PreDependType = DetectFeatureScope(PreviousFeature, Before);
CurrentDependType = DetectFeatureScope(CurrentFeature, Before);
PreDependType = DetectFeatureScope(PreviousFeature, Before, FindFeature->FeatureMask);
CurrentDependType = DetectFeatureScope(CurrentFeature, Before, FindFeature->FeatureMask);

//
// If previous feature has no dependence with the find featue.
Expand All @@ -243,10 +224,8 @@ AdjustFeaturesDependence (
// processors and clear the dependence for the other one.
//
if (PreDependType >= CurrentDependType) {
ClearFeatureScope (CurrentFeature, Before);
return TRUE;
} else {
ClearFeatureScope (PreviousFeature, Before);
return FALSE;
}
}
Expand All @@ -271,6 +250,7 @@ AdjustEntry (
LIST_ENTRY *PreviousEntry;
CPU_FEATURES_ENTRY *PreviousFeature;
CPU_FEATURES_ENTRY *CurrentFeature;
CPU_FEATURES_ENTRY *FindFeature;

//
// For CPU feature which has core or package type dependence, later code need to insert
Expand Down Expand Up @@ -308,8 +288,9 @@ AdjustEntry (
// If exist the previous or next entry, need to check it before insert curent entry.
//
PreviousFeature = CPU_FEATURE_ENTRY_FROM_LINK (PreviousEntry);
FindFeature = CPU_FEATURE_ENTRY_FROM_LINK (FindEntry);

if (AdjustFeaturesDependence (PreviousFeature, CurrentFeature, Before)) {
if (AdjustFeaturesDependence (PreviousFeature, CurrentFeature, FindFeature, Before)) {
//
// Return TRUE means current feature dependence has been cleared and the previous
// feature dependence has been kept and used. So insert current feature before (or after)
Expand Down Expand Up @@ -486,47 +467,41 @@ CheckCpuFeaturesDependency (
if (CpuFeature->BeforeFeatureBitMask != NULL) {
Swapped = InsertToBeforeEntry (FeatureList, CurrentEntry, CpuFeature->BeforeFeatureBitMask);
if (Swapped) {
CurrentEntry = NextEntry;
continue;
}
}

if (CpuFeature->AfterFeatureBitMask != NULL) {
Swapped = InsertToAfterEntry (FeatureList, CurrentEntry, CpuFeature->AfterFeatureBitMask);
if (Swapped) {
CurrentEntry = NextEntry;
continue;
}
}

if (CpuFeature->CoreBeforeFeatureBitMask != NULL) {
Swapped = InsertToBeforeEntry (FeatureList, CurrentEntry, CpuFeature->CoreBeforeFeatureBitMask);
if (Swapped) {
CurrentEntry = NextEntry;
continue;
}
}

if (CpuFeature->CoreAfterFeatureBitMask != NULL) {
Swapped = InsertToAfterEntry (FeatureList, CurrentEntry, CpuFeature->CoreAfterFeatureBitMask);
if (Swapped) {
CurrentEntry = NextEntry;
continue;
}
}

if (CpuFeature->PackageBeforeFeatureBitMask != NULL) {
Swapped = InsertToBeforeEntry (FeatureList, CurrentEntry, CpuFeature->PackageBeforeFeatureBitMask);
if (Swapped) {
CurrentEntry = NextEntry;
continue;
}
}

if (CpuFeature->PackageAfterFeatureBitMask != NULL) {
Swapped = InsertToAfterEntry (FeatureList, CurrentEntry, CpuFeature->PackageAfterFeatureBitMask);
if (Swapped) {
CurrentEntry = NextEntry;
continue;
}
}
Expand Down

0 comments on commit 1475b83

Please sign in to comment.