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: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-Google-Smtp-Source: AB8JxZrl4GVz/7zIgDg/h92QMDwJENkcA0hYycDUjhO0JPm5MnS7PMMlQXEV3xaj/msGUKyj/IZfJg== 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 Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Michael D Kinney , Liming Gao , Star Zeng , Eric Dong , Dandan Bi 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: [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: , X-List-Received-Date: Tue, 22 May 2018 14:09:07 -0000 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(+) 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; +} -- 2.17.0