* [PATCH v5 1/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei
2019-06-10 5:20 [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Gao, Zhichao
@ 2019-06-10 5:20 ` Gao, Zhichao
2019-06-10 5:20 ` [PATCH v5 2/5] MdeMoudlePkg/CapsulePei: Fix coding style issue Gao, Zhichao
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Gao, Zhichao @ 2019-06-10 5:20 UTC (permalink / raw)
To: devel
Cc: Bret Barkelew, Jian J Wang, Hao A Wu, Ray Ni, Star Zeng,
Liming Gao, Sean Brogan, Michael Turner, Leif Lindholm,
Zhichao gao
From: Bret Barkelew <Bret.Barkelew@microsoft.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1853
Code change form Mu project:
https://github.com/microsoft/mu_basecore/blob/release/201903/
MdeModulePkg/Universal/CapsulePei/UefiCapsule.c#L801
Separate the capsule check function from GetCapsuleDescriptors
to AreCapsulesStaged. The original one is unclear.
Avoid querying the capsule variable twice. Use a fixed array
to cache the SG list during count the number of SG list. Then
allocate memory buffer to save the SG list from array.
Using MemoryAllocationLib instead of memory function in Pei
services.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Zhichao gao <zhichao.gao@intel.com>
---
MdeModulePkg/Universal/CapsulePei/Capsule.h | 1 +
.../Universal/CapsulePei/CapsulePei.inf | 1 +
.../Universal/CapsulePei/UefiCapsule.c | 325 +++++++++---------
3 files changed, 172 insertions(+), 155 deletions(-)
diff --git a/MdeModulePkg/Universal/CapsulePei/Capsule.h b/MdeModulePkg/Universal/CapsulePei/Capsule.h
index baf40423af..3d9cab02c4 100644
--- a/MdeModulePkg/Universal/CapsulePei/Capsule.h
+++ b/MdeModulePkg/Universal/CapsulePei/Capsule.h
@@ -30,6 +30,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/PcdLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/DebugAgentLib.h>
+#include <Library/MemoryAllocationLib.h>
#include <IndustryStandard/PeImage.h>
#include "Common/CommonHeader.h"
diff --git a/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf b/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf
index 5d43df3075..786c411633 100644
--- a/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf
+++ b/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf
@@ -43,6 +43,7 @@
BaseLib
HobLib
BaseMemoryLib
+ MemoryAllocationLib
PeiServicesLib
PeimEntryPoint
DebugLib
diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
index e967599e96..7c8c7a0f45 100644
--- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
+++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
@@ -791,18 +791,84 @@ BuildMemoryResourceDescriptor (
}
/**
- Checks for the presence of capsule descriptors.
- Get capsule descriptors from variable CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...
- and save to DescriptorBuffer.
+ Check if the capsules are staged.
- @param DescriptorBuffer Pointer to the capsule descriptors
+ @param UpdateCapsules A pointer to return the check result.
+
+ @retval EFI_INVALID_PARAMETER The parameter is null.
+ @retval EFI_SUCCESS The Capsules are staged.
- @retval EFI_SUCCESS a valid capsule is present
- @retval EFI_NOT_FOUND if a valid capsule is not present
**/
EFI_STATUS
-GetCapsuleDescriptors (
- IN EFI_PHYSICAL_ADDRESS *DescriptorBuffer
+EFIAPI
+AreCapsulesStaged(
+ OUT BOOLEAN *UpdateCapsules
+ )
+{
+ EFI_STATUS Status;
+ UINTN Size;
+ EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;
+ EFI_PHYSICAL_ADDRESS CapsuleDataPtr64 = 0;
+
+ if (UpdateCapsules == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a Invalid parameters. Inputs can't be NULL\n", __FUNCTION__));
+ ASSERT (UpdateCapsules != NULL);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *UpdateCapsules = FALSE;
+
+ Status = PeiServicesLocatePpi(
+ &gEfiPeiReadOnlyVariable2PpiGuid,
+ 0,
+ NULL,
+ (VOID **)&PPIVariableServices
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to find ReadOnlyVariable2PPI\n"));
+ return Status;
+ }
+
+ //
+ // Check for Update capsule
+ //
+ Size = sizeof (CapsuleDataPtr64);
+ Status = PPIVariableServices->GetVariable (
+ PPIVariableServices,
+ EFI_CAPSULE_VARIABLE_NAME,
+ &gEfiCapsuleVendorGuid,
+ NULL,
+ &Size,
+ (VOID *)&CapsuleDataPtr64
+ );
+
+ if (!EFI_ERROR (Status)) {
+ *UpdateCapsules = TRUE;
+ }
+
+ return EFI_SUCCESS;
+}
+
+#define MAX_SG_LIST_HEADS (20)
+
+/**
+ Check all the variables for SG list heads and get the count and addresses.
+
+ @param ListLength A pointer would return the SG list length.
+ @param HeadList A ponter to the capsule SG list.
+
+ @retval EFI_SUCCESS a valid capsule is present
+ @retval EFI_NOT_FOUND if a valid capsule is not present
+ @retval EFI_INVALID_PARAMETER the input parameter is invalid
+ @retval EFI_OUT_OF_RESOURCES fail to allocate memory
+
+**/
+EFI_STATUS
+EFIAPI
+GetScatterGatherHeadEntries(
+ OUT UINTN *ListLength,
+ OUT EFI_PHYSICAL_ADDRESS **HeadList
)
{
EFI_STATUS Status;
@@ -815,6 +881,7 @@ GetCapsuleDescriptors (
CHAR16 *TempVarName;
EFI_PHYSICAL_ADDRESS CapsuleDataPtr64;
EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;
+ EFI_PHYSICAL_ADDRESS TempList[MAX_SG_LIST_HEADS];
Index = 0;
TempVarName = NULL;
@@ -822,87 +889,96 @@ GetCapsuleDescriptors (
ValidIndex = 0;
CapsuleDataPtr64 = 0;
+ if ((ListLength == NULL) || (HeadList == NULL)) {
+ DEBUG ((DEBUG_ERROR, "%a Invalid parameters. Inputs can't be NULL\n", __FUNCTION__));
+ ASSERT (ListLength != NULL);
+ ASSERT (HeadList != NULL);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *ListLength = 0;
+ *HeadList = NULL;
+
Status = PeiServicesLocatePpi (
&gEfiPeiReadOnlyVariable2PpiGuid,
0,
NULL,
- (VOID **) &PPIVariableServices
+ (VOID **)&PPIVariableServices
);
- if (Status == EFI_SUCCESS) {
- StrCpyS (CapsuleVarName, sizeof(CapsuleVarName)/sizeof(CHAR16), EFI_CAPSULE_VARIABLE_NAME);
- TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to find ReadOnlyVariable2PPI\n"));
+ return Status;
+ }
+
+ //
+ // setup var name buffer for update capsules
+ //
+ StrCpyS (CapsuleVarName, sizeof (CapsuleVarName) / sizeof (CHAR16), EFI_CAPSULE_VARIABLE_NAME);
+ TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
+ while (ValidIndex < MAX_SG_LIST_HEADS) {
+ if (Index != 0) {
+ UnicodeValueToStringS (
+ TempVarName,
+ (sizeof (CapsuleVarName) - ((StrLen (CapsuleVarName) + 1) * sizeof (CHAR16))),
+ 0,
+ Index,
+ 0
+ );
+ }
Size = sizeof (CapsuleDataPtr64);
- while (1) {
- if (Index == 0) {
- //
- // For the first Capsule Image
- //
- Status = PPIVariableServices->GetVariable (
- PPIVariableServices,
- CapsuleVarName,
- &gEfiCapsuleVendorGuid,
- NULL,
- &Size,
- (VOID *) &CapsuleDataPtr64
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "Capsule -- capsule variable not set\n"));
- return EFI_NOT_FOUND;
- }
- //
- // We have a chicken/egg situation where the memory init code needs to
- // know the boot mode prior to initializing memory. For this case, our
- // validate function will fail. We can detect if this is the case if blocklist
- // pointer is null. In that case, return success since we know that the
- // variable is set.
- //
- if (DescriptorBuffer == NULL) {
- return EFI_SUCCESS;
- }
- } else {
- UnicodeValueToStringS (
- TempVarName,
- sizeof (CapsuleVarName) - ((UINTN)TempVarName - (UINTN)CapsuleVarName),
- 0,
- Index,
- 0
- );
- Status = PPIVariableServices->GetVariable (
- PPIVariableServices,
- CapsuleVarName,
- &gEfiCapsuleVendorGuid,
- NULL,
- &Size,
- (VOID *) &CapsuleDataPtr64
- );
- if (EFI_ERROR (Status)) {
- break;
- }
+ Status = PPIVariableServices->GetVariable (
+ PPIVariableServices,
+ CapsuleVarName,
+ &gEfiCapsuleVendorGuid,
+ NULL,
+ &Size,
+ (VOID *)&CapsuleDataPtr64
+ );
- //
- // If this BlockList has been linked before, skip this variable
- //
- Flag = FALSE;
- for (TempIndex = 0; TempIndex < ValidIndex; TempIndex++) {
- if (DescriptorBuffer[TempIndex] == CapsuleDataPtr64) {
- Flag = TRUE;
- break;
- }
- }
- if (Flag) {
- Index ++;
- continue;
- }
+ if (EFI_ERROR (Status)) {
+ if (Status != EFI_NOT_FOUND) {
+ DEBUG ((DEBUG_ERROR, "Unexpected error getting Capsule Update variable. Status = %r\n"));
}
+ break;
+ }
- //
- // Cache BlockList which has been processed
- //
- DescriptorBuffer[ValidIndex++] = CapsuleDataPtr64;
- Index ++;
+ //
+ // If this BlockList has been linked before, skip this variable
+ //
+ Flag = FALSE;
+ for (TempIndex = 0; TempIndex < ValidIndex; TempIndex++) {
+ if (TempList[TempIndex] == CapsuleDataPtr64) {
+ Flag = TRUE;
+ break;
+ }
}
+ if (Flag) {
+ Index++;
+ continue;
+ }
+
+ //
+ // add it to the cached list
+ //
+ TempList[ValidIndex++] = CapsuleDataPtr64;
+ Index++;
+ }
+
+ if (ValidIndex == 0) {
+ DEBUG ((DEBUG_ERROR, "%a didn't find any SG lists in variables\n", __FUNCTION__));
+ return EFI_NOT_FOUND;
}
+ *HeadList = AllocateZeroPool ((ValidIndex + 1) * sizeof (EFI_PHYSICAL_ADDRESS));
+ if (*HeadList == NULL) {
+ DEBUG ((DEBUG_ERROR, "Failed to allocate memory\n"));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CopyMem (*HeadList, TempList, (ValidIndex) * sizeof (EFI_PHYSICAL_ADDRESS));
+ *ListLength = ValidIndex;
+
return EFI_SUCCESS;
}
@@ -937,15 +1013,9 @@ CapsuleCoalesce (
IN OUT UINTN *MemorySize
)
{
- UINTN Index;
- UINTN Size;
- UINTN VariableCount;
- CHAR16 CapsuleVarName[30];
- CHAR16 *TempVarName;
- EFI_PHYSICAL_ADDRESS CapsuleDataPtr64;
EFI_STATUS Status;
EFI_BOOT_MODE BootMode;
- EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;
+ UINTN ListLength;
EFI_PHYSICAL_ADDRESS *VariableArrayAddress;
MEMORY_RESOURCE_DESCRIPTOR *MemoryResource;
#ifdef MDE_CPU_IA32
@@ -955,10 +1025,8 @@ CapsuleCoalesce (
EFI_CAPSULE_LONG_MODE_BUFFER LongModeBuffer;
#endif
- Index = 0;
- VariableCount = 0;
- CapsuleVarName[0] = 0;
- CapsuleDataPtr64 = 0;
+ ListLength = 0;
+ VariableArrayAddress = NULL;
//
// Someone should have already ascertained the boot mode. If it's not
@@ -972,74 +1040,11 @@ CapsuleCoalesce (
}
//
- // User may set the same ScatterGatherList with several different variables,
- // so cache all ScatterGatherList for check later.
+ // Get SG list entries
//
- Status = PeiServicesLocatePpi (
- &gEfiPeiReadOnlyVariable2PpiGuid,
- 0,
- NULL,
- (VOID **) &PPIVariableServices
- );
+ Status = GetScatterGatherHeadEntries (&ListLength, &VariableArrayAddress);
if (EFI_ERROR (Status)) {
- goto Done;
- }
- Size = sizeof (CapsuleDataPtr64);
- StrCpyS (CapsuleVarName, sizeof(CapsuleVarName)/sizeof(CHAR16), EFI_CAPSULE_VARIABLE_NAME);
- TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
- while (TRUE) {
- if (Index > 0) {
- UnicodeValueToStringS (
- TempVarName,
- sizeof (CapsuleVarName) - ((UINTN)TempVarName - (UINTN)CapsuleVarName),
- 0,
- Index,
- 0
- );
- }
- Status = PPIVariableServices->GetVariable (
- PPIVariableServices,
- CapsuleVarName,
- &gEfiCapsuleVendorGuid,
- NULL,
- &Size,
- (VOID *) &CapsuleDataPtr64
- );
- if (EFI_ERROR (Status)) {
- //
- // There is no capsule variables, quit
- //
- DEBUG ((DEBUG_INFO,"Capsule variable Index = %d\n", Index));
- break;
- }
- VariableCount++;
- Index++;
- }
-
- DEBUG ((DEBUG_INFO,"Capsule variable count = %d\n", VariableCount));
-
- //
- // The last entry is the end flag.
- //
- Status = PeiServicesAllocatePool (
- (VariableCount + 1) * sizeof (EFI_PHYSICAL_ADDRESS),
- (VOID **)&VariableArrayAddress
- );
-
- if (Status != EFI_SUCCESS) {
- DEBUG ((DEBUG_ERROR, "AllocatePages Failed!, Status = %x\n", Status));
- goto Done;
- }
-
- ZeroMem (VariableArrayAddress, (VariableCount + 1) * sizeof (EFI_PHYSICAL_ADDRESS));
-
- //
- // Find out if we actually have a capsule.
- // GetCapsuleDescriptors depends on variable PPI, so it should run in 32-bit environment.
- //
- Status = GetCapsuleDescriptors (VariableArrayAddress);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "Fail to find capsule variables.\n"));
+ DEBUG ((DEBUG_ERROR, "%a failed to get Scatter Gather List Head Entries. Status = %r\n", __FUNCTION__, Status));
goto Done;
}
@@ -1118,7 +1123,17 @@ CheckCapsuleUpdate (
)
{
EFI_STATUS Status;
- Status = GetCapsuleDescriptors (NULL);
+ BOOLEAN Update;
+
+ Status = AreCapsulesStaged (&Update);
+
+ if (!EFI_ERROR (Status)) {
+ if (Update) {
+ Status = EFI_SUCCESS;
+ } else {
+ Status = EFI_NOT_FOUND;
+ }
+ }
return Status;
}
/**
--
2.21.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 2/5] MdeMoudlePkg/CapsulePei: Fix coding style issue
2019-06-10 5:20 [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Gao, Zhichao
2019-06-10 5:20 ` [PATCH v5 1/5] " Gao, Zhichao
@ 2019-06-10 5:20 ` Gao, Zhichao
2019-06-10 5:20 ` [PATCH v5 3/5] MdeMoudlePkg/CapsulePei: Optimize AreCapsulesStaged Gao, Zhichao
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Gao, Zhichao @ 2019-06-10 5:20 UTC (permalink / raw)
To: devel
Cc: Jian J Wang, Hao A Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
Michael Turner, Bret Barkelew, Leif Lindholm, Zhichao gao
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1853
Remove API specifier AreCapsulesStaged and GetScatterGatherHeadEntries
because they are internal used.
Add space between function name and bracket.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Zhichao gao <zhichao.gao@intel.com>
---
MdeModulePkg/Universal/CapsulePei/UefiCapsule.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
index 7c8c7a0f45..b224e200fe 100644
--- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
+++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
@@ -1,7 +1,7 @@
/** @file
Capsule update PEIM for UEFI2.0
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -800,8 +800,7 @@ BuildMemoryResourceDescriptor (
**/
EFI_STATUS
-EFIAPI
-AreCapsulesStaged(
+AreCapsulesStaged (
OUT BOOLEAN *UpdateCapsules
)
{
@@ -865,8 +864,7 @@ AreCapsulesStaged(
**/
EFI_STATUS
-EFIAPI
-GetScatterGatherHeadEntries(
+GetScatterGatherHeadEntries (
OUT UINTN *ListLength,
OUT EFI_PHYSICAL_ADDRESS **HeadList
)
--
2.21.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 3/5] MdeMoudlePkg/CapsulePei: Optimize AreCapsulesStaged
2019-06-10 5:20 [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Gao, Zhichao
2019-06-10 5:20 ` [PATCH v5 1/5] " Gao, Zhichao
2019-06-10 5:20 ` [PATCH v5 2/5] MdeMoudlePkg/CapsulePei: Fix coding style issue Gao, Zhichao
@ 2019-06-10 5:20 ` Gao, Zhichao
2019-06-10 5:20 ` [PATCH v5 4/5] MdeMoudlePkg/CapsulePei: Optimize GetScatterGatherHeadEntries Gao, Zhichao
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Gao, Zhichao @ 2019-06-10 5:20 UTC (permalink / raw)
To: devel
Cc: Jian J Wang, Hao A Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
Michael Turner, Bret Barkelew, Leif Lindholm, Zhichao gao
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1853
AreCapsulesStaged do not need to return the status, only boolean
result is useful. So directly return a boolean value.
Cannot initialize the variable at its definition.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Zhichao gao <zhichao.gao@intel.com>
---
.../Universal/CapsulePei/UefiCapsule.c | 42 ++++++-------------
1 file changed, 13 insertions(+), 29 deletions(-)
diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
index b224e200fe..ce6d95a786 100644
--- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
+++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
@@ -793,29 +793,21 @@ BuildMemoryResourceDescriptor (
/**
Check if the capsules are staged.
- @param UpdateCapsules A pointer to return the check result.
-
- @retval EFI_INVALID_PARAMETER The parameter is null.
- @retval EFI_SUCCESS The Capsules are staged.
+ @retval TRUE The capsules are staged.
+ @retval FALSE The capsules are not staged.
**/
-EFI_STATUS
+BOOLEAN
AreCapsulesStaged (
- OUT BOOLEAN *UpdateCapsules
+ VOID
)
{
EFI_STATUS Status;
UINTN Size;
EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;
- EFI_PHYSICAL_ADDRESS CapsuleDataPtr64 = 0;
-
- if (UpdateCapsules == NULL) {
- DEBUG ((DEBUG_ERROR, "%a Invalid parameters. Inputs can't be NULL\n", __FUNCTION__));
- ASSERT (UpdateCapsules != NULL);
- return EFI_INVALID_PARAMETER;
- }
+ EFI_PHYSICAL_ADDRESS CapsuleDataPtr64;
- *UpdateCapsules = FALSE;
+ CapsuleDataPtr64 = 0;
Status = PeiServicesLocatePpi(
&gEfiPeiReadOnlyVariable2PpiGuid,
@@ -826,7 +818,7 @@ AreCapsulesStaged (
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to find ReadOnlyVariable2PPI\n"));
- return Status;
+ return FALSE;
}
//
@@ -843,10 +835,10 @@ AreCapsulesStaged (
);
if (!EFI_ERROR (Status)) {
- *UpdateCapsules = TRUE;
+ return TRUE;
}
- return EFI_SUCCESS;
+ return FALSE;
}
#define MAX_SG_LIST_HEADS (20)
@@ -1120,19 +1112,11 @@ CheckCapsuleUpdate (
IN EFI_PEI_SERVICES **PeiServices
)
{
- EFI_STATUS Status;
- BOOLEAN Update;
-
- Status = AreCapsulesStaged (&Update);
-
- if (!EFI_ERROR (Status)) {
- if (Update) {
- Status = EFI_SUCCESS;
- } else {
- Status = EFI_NOT_FOUND;
- }
+ if (AreCapsulesStaged ()) {
+ return EFI_SUCCESS;
+ } else {
+ return EFI_NOT_FOUND;
}
- return Status;
}
/**
This function will look at a capsule and determine if it's a test pattern.
--
2.21.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 4/5] MdeMoudlePkg/CapsulePei: Optimize GetScatterGatherHeadEntries
2019-06-10 5:20 [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Gao, Zhichao
` (2 preceding siblings ...)
2019-06-10 5:20 ` [PATCH v5 3/5] MdeMoudlePkg/CapsulePei: Optimize AreCapsulesStaged Gao, Zhichao
@ 2019-06-10 5:20 ` Gao, Zhichao
2019-06-10 5:20 ` [PATCH v5 5/5] MdeMoudlePkg/CapsulePei: No need to remain space for null-terminate Gao, Zhichao
2019-06-13 7:49 ` [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Wu, Hao A
5 siblings, 0 replies; 9+ messages in thread
From: Gao, Zhichao @ 2019-06-10 5:20 UTC (permalink / raw)
To: devel
Cc: Jian J Wang, Hao A Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
Michael Turner, Bret Barkelew, Leif Lindholm, Zhichao gao
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1853
Rename the MACRO from MAX_SG_LIST_HEADS to DEFAULT_SG_LIST_HEADS.
GetScatterGatherHeadEntries: use allocated buffer instead of fixed
array to handle the condition which the SG list is larger then the
array size.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Zhichao gao <zhichao.gao@intel.com>
---
.../Universal/CapsulePei/UefiCapsule.c | 51 ++++++++++++++-----
1 file changed, 37 insertions(+), 14 deletions(-)
diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
index ce6d95a786..3ac95b7be6 100644
--- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
+++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
@@ -10,6 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Capsule.h"
+#define DEFAULT_SG_LIST_HEADS (20)
+
#ifdef MDE_CPU_IA32
//
// Global Descriptor Table (GDT)
@@ -841,8 +843,6 @@ AreCapsulesStaged (
return FALSE;
}
-#define MAX_SG_LIST_HEADS (20)
-
/**
Check all the variables for SG list heads and get the count and addresses.
@@ -861,17 +861,19 @@ GetScatterGatherHeadEntries (
OUT EFI_PHYSICAL_ADDRESS **HeadList
)
{
- EFI_STATUS Status;
- UINTN Size;
- UINTN Index;
- UINTN TempIndex;
- UINTN ValidIndex;
- BOOLEAN Flag;
- CHAR16 CapsuleVarName[30];
- CHAR16 *TempVarName;
- EFI_PHYSICAL_ADDRESS CapsuleDataPtr64;
- EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;
- EFI_PHYSICAL_ADDRESS TempList[MAX_SG_LIST_HEADS];
+ EFI_STATUS Status;
+ UINTN Size;
+ UINTN Index;
+ UINTN TempIndex;
+ UINTN ValidIndex;
+ BOOLEAN Flag;
+ CHAR16 CapsuleVarName[30];
+ CHAR16 *TempVarName;
+ EFI_PHYSICAL_ADDRESS CapsuleDataPtr64;
+ EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;
+ EFI_PHYSICAL_ADDRESS *TempList;
+ EFI_PHYSICAL_ADDRESS *EnlargedTempList;
+ UINTN TempListLength;
Index = 0;
TempVarName = NULL;
@@ -901,12 +903,22 @@ GetScatterGatherHeadEntries (
return Status;
}
+ //
+ // Allocate memory for sg list head
+ //
+ TempListLength = DEFAULT_SG_LIST_HEADS * sizeof (EFI_PHYSICAL_ADDRESS);
+ TempList = AllocateZeroPool (TempListLength);
+ if (TempList == NULL) {
+ DEBUG((DEBUG_ERROR, "Failed to allocate memory\n"));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
//
// setup var name buffer for update capsules
//
StrCpyS (CapsuleVarName, sizeof (CapsuleVarName) / sizeof (CHAR16), EFI_CAPSULE_VARIABLE_NAME);
TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
- while (ValidIndex < MAX_SG_LIST_HEADS) {
+ while (TRUE) {
if (Index != 0) {
UnicodeValueToStringS (
TempVarName,
@@ -948,6 +960,17 @@ GetScatterGatherHeadEntries (
continue;
}
+ //
+ // The TempList is full, enlarge it
+ //
+ if ((ValidIndex + 1) >= TempListLength) {
+ EnlargedTempList = AllocateZeroPool (TempListLength * 2);
+ CopyMem (EnlargedTempList, TempList, TempListLength);
+ FreePool (TempList);
+ TempList = EnlargedTempList;
+ TempListLength *= 2;
+ }
+
//
// add it to the cached list
//
--
2.21.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 5/5] MdeMoudlePkg/CapsulePei: No need to remain space for null-terminate
2019-06-10 5:20 [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Gao, Zhichao
` (3 preceding siblings ...)
2019-06-10 5:20 ` [PATCH v5 4/5] MdeMoudlePkg/CapsulePei: Optimize GetScatterGatherHeadEntries Gao, Zhichao
@ 2019-06-10 5:20 ` Gao, Zhichao
2019-06-10 11:14 ` Leif Lindholm
2019-06-13 7:49 ` [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Wu, Hao A
5 siblings, 1 reply; 9+ messages in thread
From: Gao, Zhichao @ 2019-06-10 5:20 UTC (permalink / raw)
To: devel
Cc: Jian J Wang, Hao A Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
Michael Turner, Bret Barkelew, Leif Lindholm, Zhichao gao
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1853
UnicodeValueToStringS would remain two bytes for the first
parameter to set the null- terminate. So remove this change
in Mu.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Zhichao gao <zhichao.gao@intel.com>
---
MdeModulePkg/Universal/CapsulePei/UefiCapsule.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
index 3ac95b7be6..fabf30926c 100644
--- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
+++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
@@ -922,7 +922,7 @@ GetScatterGatherHeadEntries (
if (Index != 0) {
UnicodeValueToStringS (
TempVarName,
- (sizeof (CapsuleVarName) - ((StrLen (CapsuleVarName) + 1) * sizeof (CHAR16))),
+ (sizeof(CapsuleVarName) - ((UINTN)TempVarName - (UINTN)CapsuleVarName)),
0,
Index,
0
--
2.21.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v5 5/5] MdeMoudlePkg/CapsulePei: No need to remain space for null-terminate
2019-06-10 5:20 ` [PATCH v5 5/5] MdeMoudlePkg/CapsulePei: No need to remain space for null-terminate Gao, Zhichao
@ 2019-06-10 11:14 ` Leif Lindholm
0 siblings, 0 replies; 9+ messages in thread
From: Leif Lindholm @ 2019-06-10 11:14 UTC (permalink / raw)
To: Zhichao Gao
Cc: devel, Jian J Wang, Hao A Wu, Ray Ni, Star Zeng, Liming Gao,
Sean Brogan, Michael Turner, Bret Barkelew
Many thanks for reworking this series.
This will make the code much more accessible in the future.
One very minor comment below:
On Mon, Jun 10, 2019 at 01:20:36PM +0800, Zhichao Gao wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1853
>
> UnicodeValueToStringS would remain two bytes for the first
> parameter to set the null- terminate. So remove this change
> in Mu.
>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Cc: Leif Lindholm <leif.lindholm@linaro.org>
> Signed-off-by: Zhichao gao <zhichao.gao@intel.com>
> ---
> MdeModulePkg/Universal/CapsulePei/UefiCapsule.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
> index 3ac95b7be6..fabf30926c 100644
> --- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
> +++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
> @@ -922,7 +922,7 @@ GetScatterGatherHeadEntries (
> if (Index != 0) {
> UnicodeValueToStringS (
> TempVarName,
> - (sizeof (CapsuleVarName) - ((StrLen (CapsuleVarName) + 1) * sizeof (CHAR16))),
> + (sizeof(CapsuleVarName) - ((UINTN)TempVarName - (UINTN)CapsuleVarName)),
Could you add the space back after sizeof before committing?
With that - for the series:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
> 0,
> Index,
> 0
> --
> 2.21.0.windows.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei
2019-06-10 5:20 [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Gao, Zhichao
` (4 preceding siblings ...)
2019-06-10 5:20 ` [PATCH v5 5/5] MdeMoudlePkg/CapsulePei: No need to remain space for null-terminate Gao, Zhichao
@ 2019-06-13 7:49 ` Wu, Hao A
2019-06-24 1:21 ` [edk2-devel] " Wu, Hao A
5 siblings, 1 reply; 9+ messages in thread
From: Wu, Hao A @ 2019-06-13 7:49 UTC (permalink / raw)
To: Gao, Zhichao, devel@edk2.groups.io
Cc: Wang, Jian J, Ni, Ray, Zeng, Star, Gao, Liming, Sean Brogan,
Michael Turner, Bret Barkelew, Leif Lindholm
> -----Original Message-----
> From: Gao, Zhichao
> Sent: Monday, June 10, 2019 1:21 PM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming; Sean Brogan;
> Michael Turner; Bret Barkelew; Leif Lindholm
> Subject: [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the
> CapsulePei
>
> v1:
> Sperate the capsule check function from GetCapsuleDescriptors
> and name it to AreCapsulesStaged.
> Rename GetCapsuleDescriptors to GetScatterGatherHeadEntries.
> And optimize its to remove the duplicated code.
>
> V2:
> Clarify the changes of the patch and descript in the commit
> message.
>
> V3:
> Add the code change repo location in Mu and add description of
> the changes on it.
> Do not need to remain 2 byte for the null-terminate while using
> UnicodeValueToStringS.
>
> V4:
> Separate the patch into 2 part. first part is changes from MU.
> Second part is the substantial change on it.
>
> V5:
> Separate the substantial change in 2/2 base on the purpose.
With the comment from Leif handled, for the series:
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Best Regards,
Hao Wu
>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Cc: Leif Lindholm <leif.lindholm@linaro.org>
>
> Bret Barkelew (1):
> MdeModulePkg/CapsulePei: Optimize the CapsulePei
>
> Zhichao Gao (4):
> MdeMoudlePkg/CapsulePei: Fix coding style issue
> MdeMoudlePkg/CapsulePei: Optimize AreCapsulesStaged
> MdeMoudlePkg/CapsulePei: Optimize GetScatterGatherHeadEntries
> MdeMoudlePkg/CapsulePei: No need to remain space for null-terminate
>
> MdeModulePkg/Universal/CapsulePei/Capsule.h | 1 +
> .../Universal/CapsulePei/CapsulePei.inf | 1 +
> .../Universal/CapsulePei/UefiCapsule.c | 356 +++++++++---------
> 3 files changed, 190 insertions(+), 168 deletions(-)
>
> --
> 2.21.0.windows.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [edk2-devel] [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei
2019-06-13 7:49 ` [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the CapsulePei Wu, Hao A
@ 2019-06-24 1:21 ` Wu, Hao A
0 siblings, 0 replies; 9+ messages in thread
From: Wu, Hao A @ 2019-06-24 1:21 UTC (permalink / raw)
To: devel@edk2.groups.io, Wu, Hao A, Gao, Zhichao
Cc: Wang, Jian J, Ni, Ray, Zeng, Star, Gao, Liming, Sean Brogan,
Michael Turner, Bret Barkelew, Leif Lindholm
> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Wu, Hao A
> Sent: Thursday, June 13, 2019 3:49 PM
> To: Gao, Zhichao; devel@edk2.groups.io
> Cc: Wang, Jian J; Ni, Ray; Zeng, Star; Gao, Liming; Sean Brogan; Michael
> Turner; Bret Barkelew; Leif Lindholm
> Subject: Re: [edk2-devel] [PATCH v5 0/5] MdeModulePkg/CapsulePei:
> Optimize the CapsulePei
>
> > -----Original Message-----
> > From: Gao, Zhichao
> > Sent: Monday, June 10, 2019 1:21 PM
> > To: devel@edk2.groups.io
> > Cc: Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming; Sean Brogan;
> > Michael Turner; Bret Barkelew; Leif Lindholm
> > Subject: [PATCH v5 0/5] MdeModulePkg/CapsulePei: Optimize the
> > CapsulePei
> >
> > v1:
> > Sperate the capsule check function from GetCapsuleDescriptors
> > and name it to AreCapsulesStaged.
> > Rename GetCapsuleDescriptors to GetScatterGatherHeadEntries.
> > And optimize its to remove the duplicated code.
> >
> > V2:
> > Clarify the changes of the patch and descript in the commit
> > message.
> >
> > V3:
> > Add the code change repo location in Mu and add description of
> > the changes on it.
> > Do not need to remain 2 byte for the null-terminate while using
> > UnicodeValueToStringS.
> >
> > V4:
> > Separate the patch into 2 part. first part is changes from MU.
> > Second part is the substantial change on it.
> >
> > V5:
> > Separate the substantial change in 2/2 base on the purpose.
>
>
> With the comment from Leif handled, for the series:
> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Series pushed via commits ba3aa1c4e7..be5903ad1e.
Best Regards,
Hao Wu
>
> Best Regards,
> Hao Wu
>
>
> >
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Hao A Wu <hao.a.wu@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Star Zeng <star.zeng@intel.com>
> > Cc: Liming Gao <liming.gao@intel.com>
> > Cc: Sean Brogan <sean.brogan@microsoft.com>
> > Cc: Michael Turner <Michael.Turner@microsoft.com>
> > Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> > Cc: Leif Lindholm <leif.lindholm@linaro.org>
> >
> > Bret Barkelew (1):
> > MdeModulePkg/CapsulePei: Optimize the CapsulePei
> >
> > Zhichao Gao (4):
> > MdeMoudlePkg/CapsulePei: Fix coding style issue
> > MdeMoudlePkg/CapsulePei: Optimize AreCapsulesStaged
> > MdeMoudlePkg/CapsulePei: Optimize GetScatterGatherHeadEntries
> > MdeMoudlePkg/CapsulePei: No need to remain space for null-terminate
> >
> > MdeModulePkg/Universal/CapsulePei/Capsule.h | 1 +
> > .../Universal/CapsulePei/CapsulePei.inf | 1 +
> > .../Universal/CapsulePei/UefiCapsule.c | 356 +++++++++---------
> > 3 files changed, 190 insertions(+), 168 deletions(-)
> >
> > --
> > 2.21.0.windows.1
>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread