From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::242; helo=mail-wm0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (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 481FF2035D0EC for ; Tue, 31 Oct 2017 03:49:25 -0700 (PDT) Received: by mail-wm0-x242.google.com with SMTP id r68so22230678wmr.3 for ; Tue, 31 Oct 2017 03:53:16 -0700 (PDT) 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=W2b0UqcBMZPA2cR1/rHMrhSAaY0bVMqU1/OKdimufDg=; b=KG6vBEp4b3jReQqaszfgOVKH+O3zmOYCN/MmzbIJVzA9WOlYOFnzoThG5AKEfaAmGX C7ihjUcx0/UVPBQUWgMWBAt45ha3MdNAX0xqnGId8rSbOUd+zdeDFOsbeu2oAnwXqVLI UE7gOJrDDRwNVALaopkbAQjIIQi2gIwFWmPZQ= 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=W2b0UqcBMZPA2cR1/rHMrhSAaY0bVMqU1/OKdimufDg=; b=b6teDcxR+wnWSiPO2h8MywHqzzGiyb95IqvMflHYn+zUksBMFvyRV2UwULAw+FL7sl DN9hacHz6AwxwUJ+PYIe0xF36k6ycxkSJh2u4LbBUF4jtzHsIStJzcPzbtXMSFKAf5dK F5CcI2F54AGeiAF6N/S8iQ1f5r8EODCoE9ATJkejMky3DkXmF0GKJh6fyWZyruf2DjCq ktZjES1OxP67yJPYvJv1lPFuXYVQuepo9waLZZdjB2Hcu1so6F9gh/OrKBADTjbAmwzn 12dVFngCJMSLDCJQT20UmR/f44sknBnCpIlJHSrzMd6lAHCPNCvRzUdKx10Xqyy4f83Z pTPw== X-Gm-Message-State: AMCzsaWQX9RKKafgsuIW6EQrtETPm9joKc1Q4I51znD6GzTqLW8zHj+U mok2EmsnIWf5PP/T3AqgPAndhu8Mm7M= X-Google-Smtp-Source: ABhQp+RRpoypNusdnE2zRXgD6wYKqIHTyN4kx/vPuqtQNHVdlp2NMR+uht5eJH3ZyqUvkr/mA1OCqg== X-Received: by 10.28.130.140 with SMTP id e134mr1687760wmd.159.1509447195395; Tue, 31 Oct 2017 03:53:15 -0700 (PDT) Received: from localhost.localdomain ([105.129.222.2]) by smtp.gmail.com with ESMTPSA id o14sm460985wra.54.2017.10.31.03.53.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Oct 2017 03:53:14 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Cc: graeme.gregory@linaro.org, daniel.thompson@linaro.org, masami.hiramatsu@linaro.org, methavanitpong.pipat@socionext.com, Ard Biesheuvel Date: Tue, 31 Oct 2017 10:52:09 +0000 Message-Id: <20171031105218.30208-19-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171031105218.30208-1-ard.biesheuvel@linaro.org> References: <20171031105218.30208-1-ard.biesheuvel@linaro.org> Subject: [PATCH edk2-platforms v3 18/27] SynQuacer/SynQuacerMemoryInitPeiLib: add capsule support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Oct 2017 10:49:25 -0000 Add support for dealing with capsules left in memory by the OS before reboot. This needs to be done early, before the memory is reused, which is why the initial handling must reside here. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c | 52 ++++++++++++++++++++ Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.inf | 4 +- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c index ed616c3bedee..69dd96bb5877 100644 --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c @@ -22,10 +22,12 @@ #include #include #include +#include #include #include +#include #include #define ARM_MEMORY_REGION(Base, Size) \ @@ -177,6 +179,11 @@ MemoryPeim ( { EFI_STATUS Status; ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; + EFI_PEI_SERVICES **PeiServices; + PEI_CAPSULE_PPI *Capsule; + VOID *CapsuleBuffer; + UINTN CapsuleBufferLength; + BOOLEAN HaveCapsule; Status = DeclareDram (&VirtualMemoryTable); ASSERT_EFI_ERROR (Status); @@ -184,12 +191,57 @@ MemoryPeim ( return Status; } + PeiServices = (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (); + ASSERT (PeiServices != NULL); + + Status = PeiServicesLocatePpi (&gPeiCapsulePpiGuid, 0, NULL, + (VOID **)&Capsule); + ASSERT_EFI_ERROR (Status); + + // + // Check for persistent capsules + // + HaveCapsule = FALSE; + Status = Capsule->CheckCapsuleUpdate (PeiServices); + if (!EFI_ERROR (Status)) { + + // + // Coalesce the capsule into unused memory. CreateState() below will copy + // it to a properly allocated buffer. + // + CapsuleBuffer = (VOID *)PcdGet64 (PcdSystemMemoryBase); + CapsuleBufferLength = UefiMemoryBase - PcdGet64 (PcdSystemMemoryBase); + + PeiServicesSetBootMode (BOOT_ON_FLASH_UPDATE); + + Status = Capsule->Coalesce (PeiServices, &CapsuleBuffer, + &CapsuleBufferLength); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: Coalesced capsule @ %p (0x%lx)\n", + __FUNCTION__, CapsuleBuffer, CapsuleBufferLength)); + HaveCapsule = TRUE; + } else { + DEBUG ((DEBUG_WARN, "%a: failed to coalesce() capsule (Status == %r)\n", + __FUNCTION__, Status)); + } + } + Status = ArmConfigureMmu (VirtualMemoryTable, NULL, NULL); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { return Status; } + if (HaveCapsule) { + Status = Capsule->CreateState (PeiServices, CapsuleBuffer, + CapsuleBufferLength); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: Capsule->CreateState failed (Status == %r)\n", + __FUNCTION__, Status)); + } + } + if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) { // Optional feature that helps prevent EFI memory map fragmentation. BuildMemoryTypeInformationHob (); diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.inf b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.inf index f433d9a57079..c6071557fd41 100644 --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.inf +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.inf @@ -39,6 +39,7 @@ [LibraryClasses] DebugLib MemoryAllocationLib PeiServicesLib + PeiServicesTablePointerLib [FeaturePcd] gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob @@ -64,7 +65,8 @@ [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase [Ppis] + gPeiCapsulePpiGuid ## CONSUMES gSynQuacerDramInfoPpiGuid ## CONSUMES [Depex] - gSynQuacerDramInfoPpiGuid + gPeiCapsulePpiGuid AND gSynQuacerDramInfoPpiGuid -- 2.11.0