From patchwork Thu Jul 4 07:35:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 809948 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1043970wru; Thu, 4 Jul 2024 00:43:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXUwQdanGJ5b91G6U+72xf9Kb0eZt6kHJXTenk4OnKNmX3lpazeE8IdOSLec1lBsxzGs8Pidf3B5umhsJwxRQqr X-Google-Smtp-Source: AGHT+IEneVo31EGA1/L6Yl3862cgiwXO8ZuwrttnI7Ma9EZujikY3Qv9tqVzcauFF+7ixIVOIqTR X-Received: by 2002:a17:906:3698:b0:a77:b7fe:66c8 with SMTP id a640c23a62f3a-a77bd9e46b4mr56443166b.15.1720079023384; Thu, 04 Jul 2024 00:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720079023; cv=none; d=google.com; s=arc-20160816; b=tJo7fZqyBBAmD/G89LskhibbU8jvlHM3uTWD1BwkyUTgoS0pyJZ6p98vC4uY+FunpI 6i6nn1MVvt2zhCqxpkk5J2A9HbvP/KgIoNzw7n17M5j1pYH2jCriLolBpLVnCS85Lky9 XRzw1r/sJrzHNxATHMC8dHh9FFQPRpRXmflTLzTFj2Xyp5vogK813OcfiBtJdjZcGIEb 0SxlqfVUb+OTipVmt2H755kpADt1yYsX/7LJCoV04OAee3WV3VNnm60fXjkMCNVWI/Ne TTNr4ixZPqYSA+XWO2aN8ddJ+oHTnDBBX0UIxvfkVJtDT13i5jz3r+D/GYYN8207ycta CtaQ== 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=8SXPuVgvOm8dd/aRlbTDeZLKSWvAjrZcHUVtHhY92VQ=; fh=ez1zzjhC0XWyqTp7tWutqrA/nFdALDnQKrnQnXYhk5Q=; b=Z91/OOP0YRAk12xtHoGrtCnGORYdpWqjl2t9T8Iw9UHkD8cYCMCkTGbJ+aV7A32vZC D/8fy6q0SbCngsWXBMrupe04Z9nC1R9INInCDvylcIOoN66qmyqeNYCib/GsELgFBkvN yI4Il7qnoGlxZRG1mT2yb0qxLPhyNYjyHkzehd4L+NSpp/8wS1Iqcn4chW5gO00VNonm c7AnXfDXgwmpC5m2OUvc69nf8vtFlv4/+DjbDCtIYP6qwNXftP5B9On7H3vqyqSJ8Cqs bztVAeQXESgcozKx/mlkJNC+7sUlQuohgkxPbvSVilSl3uQY5E2unSbGHE4EwCpwmtTQ S2sA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a72aaef6624si612439466b.172.2024.07.04.00.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 00:43:43 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 2C9C488972; Thu, 4 Jul 2024 09:38:39 +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 431DD88966; Thu, 4 Jul 2024 09:38:38 +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 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 E9B3688986 for ; Thu, 4 Jul 2024 09:38:35 +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 73129DA7; Thu, 4 Jul 2024 00:39:00 -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 36A6C3F762; Thu, 4 Jul 2024 00:38:31 -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 , Michal Simek , Sughosh Ganu Subject: [RFC PATCH v2 41/48] efi_memory: add an event handler to update memory map Date: Thu, 4 Jul 2024 13:05:37 +0530 Message-Id: <20240704073544.670249-42-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240704073544.670249-1-sughosh.ganu@linaro.org> References: <20240704073544.670249-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 There are events that would be used to notify other interested modules of any changes in available and occupied memory. This would happen when a module allocates or reserves memory, or frees up memory. These changes in memory map should be notified to other interested modules so that the allocated memory does not get overwritten. Add an event handler in the EFI memory module to update the EFI memory map accordingly when such changes happen. As a consequence, any subsequent memory request would honour the updated memory map and only available memory would be allocated from. Signed-off-by: Sughosh Ganu --- Changes since V1: * Handle the addition of memory to the LMB memory map. * Pass the overlap_only_ram parameter to the efi_add_memory_map_pg() based on the type of operation. lib/efi_loader/Kconfig | 1 + lib/efi_loader/efi_memory.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index bdf5732974..2d90bcef2f 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -16,6 +16,7 @@ config EFI_LOADER select CHARSET # We need to send DM events, dynamically, in the EFI block driver select DM_EVENT + select EVENT select EVENT_DYNAMIC select LIB_UUID select LMB diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 5691b5da03..bd12504f72 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -45,6 +45,10 @@ static LIST_HEAD(efi_mem); void *efi_bounce_buffer; #endif +#define MAP_OP_RESERVE (u8)0x1 +#define MAP_OP_FREE (u8)0x2 +#define MAP_OP_ADD (u8)0x3 + /** * struct efi_pool_allocation - memory block allocated from pool * @@ -928,3 +932,33 @@ int efi_memory_init(void) return 0; } + +#if CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY) +static int lmb_mem_map_update_sync(void *ctx, struct event *event) +{ + u8 op; + u64 addr; + u64 pages; + efi_status_t status; + struct event_lmb_map_update *lmb_map = &event->data.lmb_map; + + addr = (uintptr_t)map_sysmem(lmb_map->base, 0); + pages = efi_size_in_pages(lmb_map->size + (addr & EFI_PAGE_MASK)); + op = lmb_map->op; + addr &= ~EFI_PAGE_MASK; + + if (op != MAP_OP_RESERVE && op != MAP_OP_FREE && op != MAP_OP_ADD) { + log_debug("Invalid map update op received (%d)\n", op); + return -1; + } + + status = efi_add_memory_map_pg(addr, pages, + op == MAP_OP_RESERVE ? + EFI_BOOT_SERVICES_DATA : + EFI_CONVENTIONAL_MEMORY, + op == MAP_OP_RESERVE ? true : false); + + return status == EFI_SUCCESS ? 0 : -1; +} +EVENT_SPY_FULL(EVT_LMB_MAP_UPDATE, lmb_mem_map_update_sync); +#endif /* MEM_MAP_UPDATE_NOTIFY */