From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com [IPv6:2a00:1450:400c:c09::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 27B37821F3 for ; Thu, 2 Mar 2017 08:15:20 -0800 (PST) Received: by mail-wm0-x22c.google.com with SMTP id n11so28648014wma.1 for ; Thu, 02 Mar 2017 08:15:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A8Xw0cURSFXmebgSJtoXTj3rOm2Y3DFwoF0Z4LmK2lY=; b=XbMJdf9lzocX/Gps3E/mqq/kVWBfuEWRgpNzJ+vFZitwiESRGpoUT9O/pnd0kKjl0y oWWWYnRquCsfKkWNnwd7BygggjoTJcMn3JG/ZCPTehreGBCb8/EqyvnZzFowK5r4kCGg 5gXnOE/D+QIeT4xNIdq8cS4hSFKh4ExucqebA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A8Xw0cURSFXmebgSJtoXTj3rOm2Y3DFwoF0Z4LmK2lY=; b=cxFOORAbWZPh4TuVCHFlz8db5Xvyyz86wMIUlT809KRDvfKGekXqztymEj+NUvUELu hc92I03qNCAckoHWEvbqt2q2Qnktv2tuD6qMCOCoYeR+uUEnW+CGl7rORK0M2g8oaDBL mT0DmyiR6iSU2ITgkbJGIo09WU3uq6k0D3tOuClygtiL4Yznk/0m4QBM1rl+Mk3tS7yF X16BTMw1MwoYmjGz/0nfNxmypVn3RawavBxs9rAAKnVAlm9s/VE8xhBC5v1Bx4PB9yHO u5aOIK2x+N5+uOGBZrGb1oaGj5m8U1N9KixmXehQAv5aCgmO7LKsgEkCKLpRAFBDSqm7 MKrw== X-Gm-Message-State: AMke39lTOwswFyg5KK8T9WKXabUspYD5QEJuJzx4eXfbaEvLHcLQg6ZZGa70aL7er1lNRyaw X-Received: by 10.28.31.139 with SMTP id f133mr8883151wmf.25.1488471318723; Thu, 02 Mar 2017 08:15:18 -0800 (PST) Received: from localhost.localdomain ([105.147.1.203]) by smtp.gmail.com with ESMTPSA id n13sm11412650wra.17.2017.03.02.08.15.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Mar 2017 08:15:18 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com, leif.lindholm@linaro.org Cc: jiewen.yao@intel.com, Ard Biesheuvel Date: Thu, 2 Mar 2017 16:15:03 +0000 Message-Id: <1488471305-23752-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488471305-23752-1-git-send-email-ard.biesheuvel@linaro.org> References: <1488471305-23752-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [PATCH 2/4] ArmVirtPkg/ArmVirtMemoryInitPeiLib: check for capsules before memory init X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Mar 2017 16:15:20 -0000 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 --- 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 #include +#include #include #include #include #include -#include +#include +#include + +#include 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