From patchwork Thu Jul 4 07:35:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 809947 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1043935wru; Thu, 4 Jul 2024 00:43:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUVkvwVdGtsETnwf9HUcCpYSrsZgTtHVZAJrXMnxP2zNXULtTahJuRLGAxn0jYrri2rP4uCgIXCJK+t1gHMXsLP X-Google-Smtp-Source: AGHT+IEe6c3tZAn4MYhfSXMS7MN8s0kPT61PNls7H8sE0p9PsdSbYnwGL8U5X3ef0+UgwO+hdavZ X-Received: by 2002:a05:6402:34cc:b0:57d:15ee:3d18 with SMTP id 4fb4d7f45d1cf-58e59c391b5mr560793a12.20.1720079013009; Thu, 04 Jul 2024 00:43:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720079012; cv=none; d=google.com; s=arc-20160816; b=uaD58JIJGidKUA0VmcMUegkcIH420KbWtrRQQfuv3G1klUJdXjwVMfqf7B0dO0F4vV AooZ1+xd9hKLS5HbnyGGEWh7DSRb8j3IIE2DnPiDvvpQDQpDzC3Y8gv9aSwjVss8fVcr dXqLgaIh9/Ei57x+muS86xxtABwmBCtmD2oWxY9kbC+55yL/CYJolxAHDFEjXqCqeukv pFnqxmMQ8avWCL8vhj+miG+Sg1c2ASiuT9x8N5hGVZyTOc7dSNGnoSbwUCStchvE2K87 CzYG3o0JqfihDWDZG5hMH7V3pWoFcXMf66xiSadHzMpvgzAVH3soUIPjr7FgWJuNbSVv QA7A== 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=jJXCLuAJl1oAXtEm/G6oB3CpYQD3KdDp80G11lgUpmA=; fh=ez1zzjhC0XWyqTp7tWutqrA/nFdALDnQKrnQnXYhk5Q=; b=wFB5lMPsczTqAOZ3AtQ03lRLTCiKV3dof+VZLG3ljpNG2lJqSs1ytIvZqPaPfDg47N j1eWYGAGg1zq9B6R/R0+x1HnNGJVqgmdSYJ3/ZWRPcvZXAIFMjUbnJicT+7lPbqaxcdz MO0jmhM+jtAG8NBME9QnzgeJJ9h4HjyE0aw92nfkFcSLeMMWoNwLGUTkx6iSW5jq5eLr 7PiaMlpjDMq0ZDGMoQxVZX/S+HFCMu+/rCboEkXS0p9u23tAJwzfObJECMs51bS13Kl9 8rbGrFyE/ypj4y936JE8PyaAH/nSo4ljc/wPh8jzxKHxwWp2BeRZ0VChbsy0IAJDzaBR e9qQ==; 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 4fb4d7f45d1cf-58e13e8dde4si604669a12.668.2024.07.04.00.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 00:43:32 -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 C9C548897F; Thu, 4 Jul 2024 09:38:34 +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 6DD7888973; Thu, 4 Jul 2024 09:38:34 +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 3647688972 for ; Thu, 4 Jul 2024 09:38:32 +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 AD16A1063; Thu, 4 Jul 2024 00:38:56 -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 732163F762; Thu, 4 Jul 2024 00:38:28 -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 40/48] lmb: notify of any changes to the LMB memory map Date: Thu, 4 Jul 2024 13:05:36 +0530 Message-Id: <20240704073544.670249-41-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 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 keep track of available and used memory. Signed-off-by: Sughosh Ganu --- Changes since V1: * Notify addition of memory to the LMB memory map. * Add a function lmb_notify() to check if notification has to be sent. lib/lmb.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index d2edb3525a..387ec2ac65 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -21,12 +22,36 @@ DECLARE_GLOBAL_DATA_PTR; +#define MAP_OP_RESERVE (u8)0x1 +#define MAP_OP_FREE (u8)0x2 +#define MAP_OP_ADD (u8)0x3 + #define LMB_ALLOC_ANYWHERE 0 #define LMB_ALIST_INITIAL_SIZE 4 struct alist lmb_free_mem; struct alist lmb_used_mem; +extern bool is_addr_in_ram(uintptr_t addr); + +static bool lmb_notify(enum lmb_flags flags) +{ + return !(flags & LMB_NONOTIFY); +} + +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 alist *lmb_rgn_lst, char *name) { struct lmb_region *rgn = lmb_rgn_lst->data; @@ -463,9 +488,17 @@ static long lmb_add_region(struct alist *lmb_rgn_lst, phys_addr_t base, /* This routine may be called with relocation disabled. */ long lmb_add(phys_addr_t base, phys_size_t size) { + long ret; struct alist *lmb_rgn_lst = &lmb_free_mem; - return lmb_add_region(lmb_rgn_lst, base, size); + ret = lmb_add_region(lmb_rgn_lst, base, size); + if (ret) + return ret; + + if (CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY)) + lmb_map_update_notify(base, size, MAP_OP_ADD); + + return 0; } static long __lmb_free(phys_addr_t base, phys_size_t size) @@ -521,7 +554,16 @@ static long __lmb_free(phys_addr_t base, phys_size_t size) long lmb_free(phys_addr_t base, phys_size_t size) { - return __lmb_free(base, 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_free_flags(phys_addr_t base, phys_size_t size, @@ -532,9 +574,17 @@ long lmb_free_flags(phys_addr_t base, phys_size_t size, long lmb_reserve_flags(phys_addr_t base, phys_size_t size, enum lmb_flags flags) { + long ret = 0; struct alist *lmb_rgn_lst = &lmb_used_mem; - return lmb_add_region_flags(lmb_rgn_lst, base, size, flags); + ret = lmb_add_region_flags(lmb_rgn_lst, base, size, flags); + if (ret < 0) + return -1; + + if (CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY) && lmb_notify(flags)) + lmb_map_update_notify(base, size, MAP_OP_RESERVE); + + return ret; } long lmb_reserve(phys_addr_t base, phys_size_t size) @@ -596,6 +646,11 @@ static phys_addr_t __lmb_alloc_base(phys_size_t size, ulong align, if (lmb_add_region_flags(&lmb_used_mem, base, size, flags) < 0) return 0; + + if (CONFIG_IS_ENABLED(MEM_MAP_UPDATE_NOTIFY) && + lmb_notify(flags)) + lmb_map_update_notify(base, size, + MAP_OP_RESERVE); return base; }