From patchwork Fri Nov 10 14:21:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 118551 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp2259081edl; Fri, 10 Nov 2017 06:23:15 -0800 (PST) X-Google-Smtp-Source: AGs4zMYC1NnmWdQnWfD8XGeRa3MCqI0xX2qYWFmc4BbZ9jVRPd8n34zUGKPIwPsIGJe/Knubzv1V X-Received: by 10.98.109.134 with SMTP id i128mr578701pfc.66.1510323795309; Fri, 10 Nov 2017 06:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510323795; cv=none; d=google.com; s=arc-20160816; b=GVGNrYcSPOZepmPLP8SmPlGCVRk3CwuOruLep1+2wn3Gtp6cE7tQa7SZaOJ0LhSNyy 3EVRmdvDswWp9zs67AxT87csMdfEOQChttTxc8ztc2zM8u0h+PolBwT82LG36wmmIDbj 70QyT5jVKGq46iH+YoQt0KV+vSHj0lpRvF5aVYddmO6NHw3AZrmDoFbWZmuo3ebO1lOX 5vU1FCnWQjAWAaUOxIaJGPyAEwq5fRWTVGoRxMw+utNk88lUiO9GFrp76uviDEm5rDxB ft7BK3sQH7Dd1S/GW0hcvA5UUlDTN/W58gnbPkd2aCeVuNSJPGg6VwiHn150uWTzT+hx fVmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=yte71l5BIM/24m36b030FA9HFkPND331D8k+RtIhUuU=; b=H2d9G8EPq2MUSCDy9WMSHchRwNLuNL2vRjOmkkM7SJgou6dSCmp8K3wyB0T6pCQaFh yitQfx7cyCLvUdq+wi0HtomYMCBjSd14bs2jd5EUHCfAb099dfwpfslESCY0gzKflnMm LiP4YD34CIY6hGh3bU3IMslhBGS0Ao9w0b6oj/r6XhgHTwayZOdjyj3oon7NKAztrDVH KzizVkZ6fZQigr1jntMSh0nTL3DbK7n3jMA9lJNRrCY7twDK7dB8aFIDV7ZbJHt5zCdP 4e7VojJ7AT7Aug/ZnCVeEo9E0eG01niehTRAXQ/+60P6g471Tcg+rWL6uh5LAQB8bp1C Gy5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RBYBWJot; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id p3si8723924pgs.362.2017.11.10.06.23.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 06:23:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RBYBWJot; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3E1F920355229; Fri, 10 Nov 2017 06:18:34 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::244; helo=mail-wm0-x244.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) (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 6902320355206 for ; Fri, 10 Nov 2017 06:18:31 -0800 (PST) Received: by mail-wm0-x244.google.com with SMTP id p75so3073553wmg.3 for ; Fri, 10 Nov 2017 06:22:34 -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=Y5UDfaBTsgJADu7C8mSV3x8sjiF3kUBLpPWCg6uNqFI=; b=RBYBWJotL7cL0n6E8dMboQFOnTr7eCFT9n2m+sWV/c2Cszq6w/pTtU1Csta4NuvKys cN6y94ZgNexrDHbb9GupiBj9qs+VURGsYABKCQJ7Mwg8TuX6epUKx203/Tzv9vCcG8D6 SGt2vSR1sxPPefXs6ksCX5HRtISMmgDtwSbNU= 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=Y5UDfaBTsgJADu7C8mSV3x8sjiF3kUBLpPWCg6uNqFI=; b=V4KrkePhqLkmKEOTwCzIggz6HNssibkGc0NwhIdn6Nmn7kEnwSddQnimFa90+Vs6Hp iAnjNNNgaS249u/R2L2w210u6YUuj2kG1HNrJAIPJjywLCfPESngEYye4WKW8EWB/dfN sK866MCVIGdjFcTIrCAYn3p25Aps0O8b4+y1dVA+4d5l4VCS45YffIQryDws4xurde+9 D3Ri5T4PSZcc545ooR27ulOeGI18fajzyGra608dXssVE5AYSLNu177TYFX9/jQHuSwq 2haMwmbpKKUEL5rNy+vxzq+azlMbpYp12TQcxqztA77ReFcy2kptl5OgBd+ae65uaAxo cWRQ== X-Gm-Message-State: AJaThX6rsPK2gTmX5yUdZhBYQvjSVo0/fB+6gQMuqcfalCjP15i1q2EL awN16JEGpuU5fETf7UnaM83+wqJ/LD0= X-Received: by 10.28.61.213 with SMTP id k204mr355921wma.110.1510323752865; Fri, 10 Nov 2017 06:22:32 -0800 (PST) Received: from localhost.localdomain ([160.167.170.128]) by smtp.gmail.com with ESMTPSA id e131sm1036477wmg.15.2017.11.10.06.22.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 06:22:32 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, daniel.thompson@linaro.org Date: Fri, 10 Nov 2017 14:21:10 +0000 Message-Id: <20171110142127.12018-18-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171110142127.12018-1-ard.biesheuvel@linaro.org> References: <20171110142127.12018-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms v4 17/34] 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: , Cc: masahisa.kojima@linaro.org, masami.hiramatsu@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c index b682d631d0c2..b44c58d61062 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 db3e3b3792e4..6c3420a525d6 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 @@ -62,7 +63,8 @@ [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase [Ppis] + gPeiCapsulePpiGuid ## CONSUMES gSynQuacerDramInfoPpiGuid ## CONSUMES [Depex] - gSynQuacerDramInfoPpiGuid + gPeiCapsulePpiGuid AND gSynQuacerDramInfoPpiGuid