From patchwork Fri Jun 7 18:52:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 802327 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp949385wro; Fri, 7 Jun 2024 11:56:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW7RJr5R8QoxZhyHgSOQLcRTzXpLFmN5eKTHGrWR9WHHo4BGqi852AbPiS5y7p4u8F14p+C4Bd1mQsm3NSNyC11 X-Google-Smtp-Source: AGHT+IHEqGY1j8EUa4HzG0kg6FrMpZenfnm9sEFc1AP2coP0pqISB2fXQN5SPh39xHBblPcMiqaq X-Received: by 2002:a50:cd49:0:b0:57c:5c4f:a356 with SMTP id 4fb4d7f45d1cf-57c5c4fa4bcmr1457876a12.8.1717786584263; Fri, 07 Jun 2024 11:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717786584; cv=none; d=google.com; s=arc-20160816; b=tlqBdYYa/RLRzO54QAdTzIqMeGKcp7HJq0QLpaehkNbokD7oqC3D1Hf1AzxhpW7g9a Isoz00fk4t1TrmBI2xN4Lyso9NLQbfl54Hg6WVAIM82iZaeNNtQqvNF7qhYC/E3ZdRYo dSqhSbFA5KqFD8/TyDJACp+bJA8I0kQop53X12/01qMENV961CU/0XHEJ6M41wOkoZSt BNdyjlYtYbBrL7fAPyAofR16pED4dCuxoz8qYH5rvTtNS13cqM4W/2ylgAZzAYhjee4g jfS0i5b5AQaZLNqeXZd/MffSZJ2zpIfXVOPF5zaEu44Dde5Bq+S8gHIMfZEjBAovrLrE Kwcg== 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=fTb82zALQcDtYjbW6LHI40RXVN7le9DTSt+ucZ4icQA=; fh=xLSOOz5Q0Mrmzd+lwBRTYS7D/8TpUWM8TEHgIjpMzow=; b=g2voQOEeejF9FHc+d8YyEsInyuWY/S9PFuuvLeVD6r7OA624eA5LV779kI8EIMSAN8 6QSYidkvXz0SGaNqZ4z/m9WaWfEyxFxUxlxgk4Y9zPRZEhWg/SyqHXTwUU0hYJSp6AXx bcUEO/TRLSdScAhyg9P9E71epPouVyJnwvPOGLi2rSPKy2a19qTvt4NYC1SGHICgkMZx fyHTsoFb93bJM2EiC4wxLwdcElXdVvbqO7oLAxroJ4FLRK4010tn7Rpui8d2uHy5AbU3 SV/z/72Dfbo9n98l99aBftcI7h2Wcddr5O+vKHraog31d5B3mbbRN03sQbyZkFfCPn6k yA2A==; 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 4fb4d7f45d1cf-57aae1fda53si2112580a12.251.2024.06.07.11.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:56:24 -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 F2E998850D; Fri, 7 Jun 2024 20:54:27 +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 DB3AC8850B; Fri, 7 Jun 2024 20:54:26 +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 D130588521 for ; Fri, 7 Jun 2024 20:54:24 +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 BDB581480; Fri, 7 Jun 2024 11:54:48 -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 943F93F792; Fri, 7 Jun 2024 11:54:21 -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 16/31] lmb: add an event handler to update memory map Date: Sat, 8 Jun 2024 00:22:25 +0530 Message-Id: <20240607185240.1892031-17-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 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 LMB module to update it's memory map accordingly when such changes happen. As a consequence, any subsequent memory request would honour the updated memory map and allocations would only happen from available memory. Signed-off-by: Sughosh Ganu --- lib/Kconfig | 1 + lib/lmb.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index 9ea02ae006..9e465a748b 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1111,6 +1111,7 @@ config LMB bool "Enable the logical memory blocks library (lmb)" default y if ARC || ARM || M68K || MICROBLAZE || MIPS || \ NIOS2 || PPC || RISCV || SANDBOX || SH || X86 || XTENSA + select EVENT help Support the library logical memory blocks. diff --git a/lib/lmb.c b/lib/lmb.c index 313735dbe3..3059609aea 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -16,6 +16,7 @@ #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -719,3 +720,36 @@ __weak void arch_lmb_reserve(void) { /* please define platform specific arch_lmb_reserve() */ } + +#if CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY) +static long lmb_reserve_nooverwrite(phys_addr_t base, phys_size_t size) +{ + struct lmb_region *_rgn = &lmb.reserved; + + return lmb_add_region_flags(_rgn, base, size, LMB_NOOVERWRITE); +} + +static int efi_mem_map_update_sync(void *ctx, struct event *event) +{ + u8 op; + long ret; + phys_addr_t addr; + phys_size_t size; + struct event_efi_mem_map_update *efi_map = &event->data.efi_mem_map; + + addr = virt_to_phys((void *)(uintptr_t)efi_map->base); + size = efi_map->size; + op = efi_map->op; + + if (op != MAP_OP_RESERVE && op != MAP_OP_FREE) { + log_debug("Invalid map update op received (%d)\n", op); + return -1; + } + + ret = op == MAP_OP_RESERVE ? lmb_reserve_nooverwrite(addr, size) : + __lmb_free(addr, size); + + return !ret ? 0 : -1; +} +EVENT_SPY_FULL(EVT_EFI_MEM_MAP_UPDATE, efi_mem_map_update_sync); +#endif /* MEM_MAP_UPDATE_NOTIFY */