From patchwork Fri Jun 7 18:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 802324 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp949227wro; Fri, 7 Jun 2024 11:55:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXRp+VSVc4/5SZakdhkQgiZTGv3Uob5tuM2eSf51say1zETWRgUduKBQpAPruSvQXWNy3Q7On9q82cOXvNJmU51 X-Google-Smtp-Source: AGHT+IFJNQh7MP1JKeKFZgdiDl8vleGeYHJTbFS8qfM3uvMMClVn3bBO84H8GHbylM4nT8rYvxxz X-Received: by 2002:ac2:5302:0:b0:51f:4d57:6812 with SMTP id 2adb3069b0e04-52bb9f786b3mr2630048e87.19.1717786552770; Fri, 07 Jun 2024 11:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717786552; cv=none; d=google.com; s=arc-20160816; b=K4+QQfyG8M3EQpZfZMbEU+x55q6J4KtADmnP+wspesIPGTtWRxdoGdt+FvyT2Pqw5F /Oijf2Ryl7exm/CUYx48qXVRHFxfyVorA8ld+uihywVaKmijTAvwupFvm3ErTzax5XAw 8aR67U2XVUG5/XVO0uio3REBPOGatM533wHuMpMj3bLlbpTu2gon642E+nSoqgqoC3o2 QZaGa51VJh0OVmsA0DObI/uTGQZxBr7rwTyl/4tZDhYlnPjvcd0RBhioaa197rgmLo+k X2nORBpa/n2FIhnF83ri01z/Aap6mbDy7geBNztNSXlstvcP6tC8vRK3EbgY5/hlkr+g CPmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=CzHaoUdpzSLYlHC6znUMbXCR3GaBWRv4QHCeXODwD8o=; fh=xLSOOz5Q0Mrmzd+lwBRTYS7D/8TpUWM8TEHgIjpMzow=; b=RH8SFvG6RYg92maCH6GJH0pz7EIqst524ttpvooT6qE6STW+oUjT+swBbv5U2Xt74T 1CYS4it7X3Tb1wjz/NKF0bZ/hnH4AJzDsnqkVBqkHqi3hG3qh9T7lPzW5Y80lEa2Hjam 68ZqHzmLNoXGo1UvPAv3i59hFJRAiq2jL87pL1GEuv9kIcYwW0nP4o3f2jMgSyiAhrVm 9FtAHxle53cKtqy4fCbq2aRCMEiF/WMmoGG1VbEuIZHTHse+ar84h/m3TO0UTkJaXGEc 2DrVvcfnVDtFO847ajZcoPYnhlBfgUHYII8D2QXiSFwSK+HowAM/HUYJMBcV+3R6UcBm JZig==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6ef650c33dsi42947866b.299.2024.06.07.11.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:55:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D18A5884AA; Fri, 7 Jun 2024 20:54:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 178C788506; Fri, 7 Jun 2024 20:54:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 216A0884EE for ; Fri, 7 Jun 2024 20:54:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0E8601480; Fri, 7 Jun 2024 11:54:39 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DA4AF3F792; Fri, 7 Jun 2024 11:54:11 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Fabio Estevam , Sughosh Ganu Subject: [RFC PATCH 13/31] efi_memory: notify of any changes to the EFI memory map Date: Sat, 8 Jun 2024 00:22:22 +0530 Message-Id: <20240607185240.1892031-14-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607185240.1892031-1-sughosh.ganu@linaro.org> References: <20240607185240.1892031-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean In U-Boot, LMB and EFI are two primary modules who provide memory allocation and reservation API's. Both these modules operate with the same regions of memory for allocations. Use the EFI memory map update event to notify other interested listeners about a change in the EFI memory map. This can then be used by the other module to allocate memory only from available regions, instead of overwriting already allocated memory. Signed-off-by: Sughosh Ganu --- lib/efi_loader/efi_memory.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 12cf23fa3f..435e580fb3 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY LOGC_EFI #include +#include #include #include #include @@ -36,6 +37,9 @@ struct efi_mem_list { #define EFI_CARVE_OVERLAPS_NONRAM -3 #define EFI_CARVE_OUT_OF_RESOURCES -4 +#define MAP_OP_RESERVE (u8)0x1 +#define MAP_OP_FREE (u8)0x2 + /* This list contains all memory map items */ static LIST_HEAD(efi_mem); @@ -66,6 +70,22 @@ struct efi_pool_allocation { char data[] __aligned(ARCH_DMA_MINALIGN); }; +#if CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY) +extern bool is_addr_in_ram(uintptr_t addr); + +static void efi_map_update_notify(u64 addr, u64 size, u8 op) +{ + struct event_efi_mem_map_update efi_map = {0}; + + efi_map.base = addr; + efi_map.size = size; + efi_map.op = op; + + if (is_addr_in_ram((uintptr_t)addr)) + event_notify(EVT_EFI_MEM_MAP_UPDATE, &efi_map, sizeof(efi_map)); +} +#endif /* MEM_MAP_UPDATE_NOTIFY */ + /** * checksum() - calculate checksum for memory allocated from pool * @@ -375,6 +395,11 @@ static efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, } } + if (CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY)) + efi_map_update_notify(start, pages << EFI_PAGE_SHIFT, + memory_type == EFI_CONVENTIONAL_MEMORY ? + MAP_OP_FREE : MAP_OP_RESERVE); + return EFI_SUCCESS; }