From patchwork Tue May 22 14:08:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 136551 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1683046lji; Tue, 22 May 2018 07:09:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr4gk1p473TcmrYl2orAjKZ0F/kIlYumdZ0l8D+vp0yendBQGyyDgq9eLQfOFna+MVq11Bm X-Received: by 2002:a17:902:14cb:: with SMTP id y11-v6mr24471866plg.229.1526998151617; Tue, 22 May 2018 07:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526998151; cv=none; d=google.com; s=arc-20160816; b=oXkGVcX0PeQmH4Rx+q2o8rBTNokNzgd4GRHkj6MtFU3jDhRJDMYdC5Y5UWZyhZhp4/ hdfa2VEvROLC+Sxy8Jc7TA0wKlxET86jd1w5W4J1S26QHe6R8h+NRlNA1qorZQ5ySKSB 0sWUtkQw1FPNVlWpvKsdp0mLr9D7x7th2C5F+DcO0Q4fj+dfGiD7ajqiIW2PhEDUFHcF vzcaZfEf/aUFWCIlhgmsilHyl74WSxz4S4H85WIXpyq7arKOfhLxEkD2LFwOQzuqYTt6 qKKyHwdBJh9AZk1TFIy7YnMBckc5+/YQ0tyu610zAl1ezEPaIIzGaO42u+XshmszjgO9 AqeA== 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=kY5llQbt3MBmY07PWnRld/hnBmLkwZlQmSbXpsyPdOY=; b=UugNQmtyCtI7EIoqwq7CtNb8diEqSWa665BLQB9UVQD1pY+NiPpgMDbRqk0Cx2c1e8 W2uAzQYOCmv/5rpf6KNo8dttPaYrHLCGNh4Yg6zDeQ8ESyExNtABctLyMizwTdyFWrK9 psVNH4NeBxaRmkZxdiCQ36iFW9bvKfcKshHz1EgtKXnd+9+2zN0pV0MOsA4JG9FyWX5/ bcYuUCpgujx2hejjDuZxnSpBPEyg/fQ/pfICjV3dMCs9MC1ns77EuK+t1BMRtIQ20qv8 VT4/Yn6deqWBTATEmvJcygaxA10jnJelxyxPy2PybPb11wmt51j7NbnqpVg71XJWk+po vGeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TCPKksGi; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id a23-v6si16287378pls.571.2018.05.22.07.09.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 07:09:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TCPKksGi; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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 9A90C203BBB85; Tue, 22 May 2018 07:09:07 -0700 (PDT) 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:c0c::242; helo=mail-wr0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::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 1860C203B992C for ; Tue, 22 May 2018 07:09:07 -0700 (PDT) Received: by mail-wr0-x242.google.com with SMTP id w3-v6so12746042wrl.12 for ; Tue, 22 May 2018 07:09:06 -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=ZC5QBrtv23WgGxbJieOYq5dVBsba/B5Edhq//D6cVRM=; b=TCPKksGiS3LwTARl3LcoWay2uoy7XsC1x/dkanpFv/8MPnZs4tzQiq95V88TZS6cO1 Dr7upgx4Prit2YuSuT3lPh+FeA/wpQWAm6GZ0+dbWZzN4YM+ol3tEyh+jm3oasH3bfyJ yVvXVUAYdjPsX2wvIHecF4ZIguiSrzrR3u5b4= 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=ZC5QBrtv23WgGxbJieOYq5dVBsba/B5Edhq//D6cVRM=; b=D+qbkVaBdrj8ZXlQh4Gw78QBZFUwpyKtwzvrdkiUQtAvIBhonk5SRlEpJVWo/h5iNI N7ZQ71umGYRRnjlQ7r1DBxJlwU0GiEeKCtQOs/zfcW8EVedsG47sYvwGPIBAtqzr0311 XWnUt/MlWYijASwwUT4lGg7iV5WbnE3FNpOetU0opSxYAIAm7wNPFZtJDzkyaTKE3azM o9P1c88FeLaiUpmcxC0RKTFYyWgnEwkVuuwCHTdRnFRx9Iw0PKWsNeOI+/H9WYZ2G6Kg mY8LuulKqdTxsvEuW7+CWl7Xpmp98cMeVbGDF0vG+XZlMIqROrgijkczn3bMbqCNqdsv CAkQ== X-Gm-Message-State: ALKqPweB7il2z9RYhFTR/g/CyJMnzziYKgmI+IGeMB9ClmUfHo5jBVA7 GyBr7vrr5kFK3DM/EAcGVcL4TvH27S8= X-Received: by 2002:adf:9c01:: with SMTP id f1-v6mr18278525wrc.171.1526998145371; Tue, 22 May 2018 07:09:05 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id r6-v6sm17755545wrg.73.2018.05.22.07.09.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 07:09:04 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 22 May 2018 16:08:48 +0200 Message-Id: <20180522140850.30369-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180522140850.30369-1-ard.biesheuvel@linaro.org> References: <20180522140850.30369-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 4/6] IntelFrameworkPkg/FrameworkUefiLib: add EfiAllocatePeiAccessiblePages routine X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Dong , Ard Biesheuvel , Liming Gao , Dandan Bi , Leif Lindholm , Michael D Kinney , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Add the newly introduced EfiAllocatePeiAccessiblePages() routine which allocates memory in a way that guarantees that PEI can access it after a warm reboot. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) -- 2.17.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c index 443a73917215..a488fe780b04 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c @@ -1687,3 +1687,51 @@ EfiLocateProtocolBuffer ( return EFI_SUCCESS; } + +/** + Allocates one or more 4KB pages of a given type from a memory region that is + accessible to PEI. + + Allocates the number of 4KB pages of type 'MemoryType' and returns a + pointer to the allocated buffer. The buffer returned is aligned on a 4KB + boundary. If Pages is 0, then NULL is returned. If there is not enough + memory remaining to satisfy the request, then NULL is returned. + + @param[in] MemoryType The memory type to allocate + @param[in] Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +EfiAllocatePeiAccessiblePages ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Memory; + EFI_ALLOCATE_TYPE AllocType; + + if (Pages == 0) { + return NULL; + } + +#ifdef MDE_CPU_X64 + // + // On X64 systems, a X64 build of DXE may be combined with a 32-bit build of + // PEI, and so we need to allocate below 4 GB to ensure that the allocation + // is accessible by PEI. + // + AllocType = AllocateMaxAddress; + Memory = MAX_UINT32; +#else + AllocType = AllocateAnyPages; +#endif + Status = gBS->AllocatePages (AllocType, MemoryType, Pages, &Memory); + if (EFI_ERROR (Status)) { + return NULL; + } + return (VOID *)(UINTN)Memory; +}