From patchwork Fri Jun 7 18:52:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 802325 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp949264wro; Fri, 7 Jun 2024 11:56:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWLTRotd0Zl/YcoX64GIERqVsyq8pxB2KcqsHqRklxDITUQmpovyDAVATruBq50VeRWJN1Chc3NAHmrCHX3fq+/ X-Google-Smtp-Source: AGHT+IGHUjUvZsTRDoYK+UfCr+AUADlWFX0BXSe/oxl2bZBFWvG3s9zKpD6xpfgdyz16haMboZYn X-Received: by 2002:a17:906:378a:b0:a6e:8aa4:1fc1 with SMTP id a640c23a62f3a-a6e8aa4203dmr116170566b.28.1717786563186; Fri, 07 Jun 2024 11:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717786563; cv=none; d=google.com; s=arc-20160816; b=JdwBZoRSqiUwnL69r7eS/GmQVc+epZkk77U526UygzNAIX4WtICM+xVg4h50tKFQ1o LVQdvhUJTGLw2EYbb46EHH5VTfA3L1ZWpe6+W5tu5nGei/0r+i/q839gcYHaqOYYUPcV KSODQ1q0176eYJdbqj2R7qozpVX2a7u9BBEw94kuOsrIyDFt7N9YlMTVhsWcyaDtKCCq orEfFwSxAiqSbgRZUTuJynH3xfraG42QbLp/YG7dEJ8lG7aYoiAi/uMxhE7oV489kI33 9hWlMcVj+m5ynP+YKgKli+hqdXg5YGHLmHUq9an3E9p/a5WEbvL7yAhN2M3dGCxiLLuE TAkg== 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=lNg1Z/CsaR00v1N12op/GufUBvwkTJxlEZqdBxcA6RY=; fh=xLSOOz5Q0Mrmzd+lwBRTYS7D/8TpUWM8TEHgIjpMzow=; b=fYu5ONKjx/7xsL9v8RGzbDgq3ie3l+moe3pnf7xZ4YK45IwhlQLzewiQL402+E7ndD kLI8RJQgqymPZs0kxHtHfhbpwiF/DZejrG35FwGlzCJlKxhRBXEtHYx/GdLv2YQxsQWi 1vevX2pp4FHfJQm6WZTdWPNDIX4w9u4ZQM0QkAP+tEmZg5sM+40OiG+DB6naRi/HXmX2 uoeYraerZDYS2uR/R/xhvZEh0X2vrfIY3RDifz7m2PjwBM1nNHjFsLCPfqBFCvdhoUjM 3fewrB2aN+Wgqd/MfSUX4N30KyKduUTzjCfILG+eMkkQw+DGEuWyUXoaUWhmUQUwSmWt qcoA==; 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-a6c806d8180si212145766b.413.2024.06.07.11.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:56:03 -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 3B3D088473; Fri, 7 Jun 2024 20:54:21 +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 CA7D4884FC; Fri, 7 Jun 2024 20:54:20 +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 A12DB88485 for ; 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=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 709F21480; Fri, 7 Jun 2024 11:54:42 -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 224203F792; Fri, 7 Jun 2024 11:54:14 -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 14/31] lmb: notify of any changes to the LMB memory map Date: Sat, 8 Jun 2024 00:22:23 +0530 Message-Id: <20240607185240.1892031-15-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 LMB memory map update event to notify other interested listeners about a change in it's 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/lmb.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index 0a4f3d5bcd..313735dbe3 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -18,8 +19,13 @@ DECLARE_GLOBAL_DATA_PTR; +#define MAP_OP_RESERVE (u8)0x1 +#define MAP_OP_FREE (u8)0x2 + #define LMB_ALLOC_ANYWHERE 0 +extern bool is_addr_in_ram(uintptr_t addr); + #if !IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS) struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS]; struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS]; @@ -39,6 +45,19 @@ struct lmb lmb = { .reserved.cnt = 0, }; +static void lmb_map_update_notify(phys_addr_t addr, phys_size_t size, + u8 op) +{ + struct event_lmb_map_update lmb_map = {0}; + + lmb_map.base = addr; + lmb_map.size = size; + lmb_map.op = op; + + if (is_addr_in_ram((uintptr_t)addr)) + event_notify(EVT_LMB_MAP_UPDATE, &lmb_map, sizeof(lmb_map)); +} + static void lmb_dump_region(struct lmb_region *rgn, char *name) { unsigned long long base, size, end; @@ -450,7 +469,7 @@ long lmb_add(phys_addr_t base, phys_size_t size) return lmb_add_region(_rgn, base, size); } -long lmb_free(phys_addr_t base, phys_size_t size) +static long __lmb_free(phys_addr_t base, phys_size_t size) { struct lmb_region *rgn = &lmb.reserved; phys_addr_t rgnbegin, rgnend; @@ -500,11 +519,33 @@ long lmb_free(phys_addr_t base, phys_size_t size) rgn->region[i].flags); } +long lmb_free(phys_addr_t base, phys_size_t size) +{ + long ret; + + ret = __lmb_free(base, size); + if (ret < 0) + return ret; + + if (CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY)) + lmb_map_update_notify(base, size, MAP_OP_FREE); + + return 0; +} + long lmb_reserve_flags(phys_addr_t base, phys_size_t size, enum lmb_flags flags) { + long ret = 0; struct lmb_region *_rgn = &lmb.reserved; - return lmb_add_region_flags(_rgn, base, size, flags); + ret = lmb_add_region_flags(_rgn, base, size, flags); + if (ret < 0) + return -1; + + if (CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY)) + lmb_map_update_notify(base, size, MAP_OP_RESERVE); + + return ret; } long lmb_reserve(phys_addr_t base, phys_size_t size) @@ -563,6 +604,10 @@ static phys_addr_t __lmb_alloc_base(phys_size_t size, ulong align, if (lmb_add_region(&lmb.reserved, base, size) < 0) return 0; + + if (CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY)) + lmb_map_update_notify(base, size, + MAP_OP_RESERVE); return base; } res_base = lmb.reserved.region[rgn].base;