From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org, lersek@redhat.com, leif.lindholm@linaro.org
Cc: jiewen.yao@intel.com, Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH 2/4] ArmVirtPkg/ArmVirtMemoryInitPeiLib: check for capsules before memory init
Date: Thu, 2 Mar 2017 16:15:03 +0000 [thread overview]
Message-ID: <1488471305-23752-3-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1488471305-23752-1-git-send-email-ard.biesheuvel@linaro.org>
Look for any capsules left in memory by the OS across reset before
releasing the memory for normal use, so that they can be preserved and
processed later.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c | 60 +++++++++++++++++++-
ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf | 9 ++-
2 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
index 6f3e54b7afcb..7f55f634e4e5 100644
--- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
+++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
@@ -17,11 +17,15 @@
#include <Library/ArmMmuLib.h>
#include <Library/ArmPlatformLib.h>
+#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
-#include <Library/CacheMaintenanceLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/PeiServicesTablePointerLib.h>
+
+#include <Ppi/Capsule.h>
VOID
BuildMemoryTypeInformationHob (
@@ -49,6 +53,58 @@ InitMmu (
}
}
+STATIC
+VOID
+CheckCapsule (
+ IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,
+ IN UINT64 UefiMemorySize
+ )
+{
+ EFI_STATUS Status;
+ EFI_PEI_SERVICES **PeiServices;
+ PEI_CAPSULE_PPI *Capsule;
+ VOID *CapsuleBuffer;
+ UINTN CapsuleBufferLength;
+
+ PeiServices = (EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
+ ASSERT (PeiServices != NULL);
+
+ //
+ // Check for persistent capsules
+ //
+ Status = PeiServicesLocatePpi (&gPeiCapsulePpiGuid, 0, NULL,
+ (VOID **)&Capsule);
+ if (Status == EFI_SUCCESS) {
+ Status = Capsule->CheckCapsuleUpdate (PeiServices);
+ if (Status == EFI_SUCCESS) {
+
+ CapsuleBuffer = (VOID *)((UINTN)FixedPcdGet32 (PcdCPUCoresStackBase) +
+ FixedPcdGet32 (PcdCPUCorePrimaryStackSize));
+ CapsuleBufferLength = (UINTN)UefiMemoryBase - (UINTN)CapsuleBuffer;
+
+ PeiServicesSetBootMode (BOOT_ON_FLASH_UPDATE);
+ Status = Capsule->Coalesce (PeiServices, &CapsuleBuffer,
+ &CapsuleBufferLength);
+ if (!EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "%a: Coalesced capsule @ %p (0x%lx) capsule\n",
+ __FUNCTION__, CapsuleBuffer, CapsuleBufferLength));
+ } else {
+ DEBUG ((DEBUG_WARN, "%a: failed to coalesce() capsule (Status == %r)\n",
+ __FUNCTION__, Status));
+ return;
+ }
+
+ Status = Capsule->CreateState (PeiServices, CapsuleBuffer,
+ CapsuleBufferLength);
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "%a: Capsule->CreateState failed (Status == %r)\n",
+ __FUNCTION__, Status));
+ }
+ }
+ }
+}
+
EFI_STATUS
EFIAPI
MemoryPeim (
@@ -109,6 +165,8 @@ MemoryPeim (
// Build Memory Allocation Hob
InitMmu ();
+ CheckCapsule (UefiMemoryBase, UefiMemorySize);
+
if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
// Optional feature that helps prevent EFI memory map fragmentation.
BuildMemoryTypeInformationHob ();
diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
index 028d6fb5ac28..4524afd2c7ed 100644
--- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
+++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
@@ -37,6 +37,8 @@ [LibraryClasses]
ArmMmuLib
ArmPlatformLib
CacheMaintenanceLib
+ PeiServicesLib
+ PeiServicesTablePointerLib
[Guids]
gEfiMemoryTypeInformationGuid
@@ -48,6 +50,8 @@ [FixedPcd]
gArmTokenSpaceGuid.PcdFdSize
gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
+ gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase
+ gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS
@@ -64,5 +68,8 @@ [Pcd]
gArmTokenSpaceGuid.PcdSystemMemorySize
gArmTokenSpaceGuid.PcdFdBaseAddress
+[Ppis]
+ gPeiCapsulePpiGuid
+
[Depex]
- TRUE
+ gPeiCapsulePpiGuid
--
2.7.4
next prev parent reply other threads:[~2017-03-02 16:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-02 16:15 [PATCH 0/4] ArmVirtPkg: implement basic capsule support Ard Biesheuvel
2017-03-02 16:15 ` [PATCH 1/4] ArmVirtPkg/ArmVirtPlatformLib: base boot mode on capsule presence Ard Biesheuvel
2017-03-02 16:15 ` Ard Biesheuvel [this message]
2017-03-02 16:15 ` [PATCH 3/4] ArmVirtPkg/PlatformBootManagerLib: process pending capsules Ard Biesheuvel
2017-03-02 16:15 ` [PATCH 4/4] ArmVirtPkg/ArmVirtQemu: enable basic capsule support Ard Biesheuvel
2017-03-02 17:09 ` [PATCH 0/4] ArmVirtPkg: implement " Laszlo Ersek
2017-03-02 17:22 ` Ard Biesheuvel
2017-03-02 18:56 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1488471305-23752-3-git-send-email-ard.biesheuvel@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox