From patchwork Mon May 26 09:12:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 892605 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e53:0:b0:3a3:61c9:c5d4 with SMTP id j19csp1103655wrz; Mon, 26 May 2025 02:13:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWYPqC65GUFp9rUJkbrSXWHIMel80CdsBAqEuyLGm/obusmBmQSqCwwGdhqxkKeOlYX81e9MA==@linaro.org X-Google-Smtp-Source: AGHT+IGte2z2NRywfIdPaP/im1Qdl35QCJYvtcWP1GaCgjWEA+iFSc3m9g18uH5x5dVMX8ndNhsX X-Received: by 2002:a17:907:60d0:b0:ad5:bf7a:964 with SMTP id a640c23a62f3a-ad85b0b2999mr591672766b.8.1748250796984; Mon, 26 May 2025 02:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1748250796; cv=none; d=google.com; s=arc-20240605; b=IYr7IJcV2MjotpFKxDyOxAQvLT3cplUCXMYvpAyLiwgoJP760GdBGHisqfO+PXf8W2 y87cWJqHB85nnMePFjVL6FFhD5YRHI+hhoLutDgvcYJdhgK5on8z6+zOIYbOjkEhSBap pBMSVm93Lwy5Mda79GehF9z6+jDAb9PadxHPCWmOTc+JwAORyzxSQqEr/RZ3iQPyR+Ex Xb96tqy0ONNkHN4x446c+y9jZ495JBi5GZdhqYfCNzdI9pTlyrKNrg1WzeU3aR/MCML8 LwtqDzFDM/gPvIRokzBggmbvinBBXGs8o5j7wBlNZOSaamjqlxy/WBsKBDD3BDstDHw7 +IwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=+5A/zaLrHf0dn22uyOsKUY8ht3+UknVeUyjGZivyX30=; fh=89MlnLdazmnhKnYeHaI4JcicUnUrLLJuTd/r2dh4RLc=; b=BEWVfJDvJa/NOUxoC4uKwsZ2Dpk/xl0204w83DNp1fvgqx8JWJACqLTKEku+ekybeU 4qXPB13GzeZOcKDqKe2+6bLlr9tl4ujAvtcCSAaoYdqqJsZDI1VRZcGfYkibbJ9FSZk8 FNeJLZ7GC7ZdjVz9AXiN5qTfSKnyrkvJSm2AexE8ZGbgBQsC4DY+dMtsGa8lfhm4fIq6 /7BAo8O2SOKZ6XZP4xK9Uq3nOk7gFBgNMPInJ0ryNIDW4deXkHp5YPHSC1q1Ym7Zpxoz VMKxQLgLjaWvoTg0FffO5YvQ91gbzhMzLR+z3NIxPI1NmUi0C/xD9q4i8EOXyZBMWJvT yPxg==; 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-ad52d515c6asi1629418266b.635.2025.05.26.02.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 02:13:16 -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 E073582CED; Mon, 26 May 2025 11:13:15 +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 874F582CF8; Mon, 26 May 2025 11:13:14 +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_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_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 4139C82C57 for ; Mon, 26 May 2025 11:13:12 +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 0A8EC153B; Mon, 26 May 2025 02:12:56 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.164.21.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A64533F673; Mon, 26 May 2025 02:13:08 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Tom Rini , Casey Connolly , Neil Armstrong , Mark Kettenis , Weijie Gao , Heinrich Schuchardt , Simon Glass Subject: [PATCH v3 0/6] lmb: use a single API for all allocations Date: Mon, 26 May 2025 14:42:47 +0530 Message-Id: <20250526091253.400802-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 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 The LMB module has a bunch for API's which are used for allocating memory. There are a couple of API's for requesting memory, and two more for reserving regions of memory. Replace these different API's with a single one, lmb_alloc_mem(). The type of allocation to be made is specified through one of the parameters to the function. Additionally, the two API's for reserving regions of memory, lmb_reserve() and lmb_alloc_addr() are the same with one difference. One can reserve any memory region with lmb_reserve(), while lmb_alloc_addr() actually checks that the memory region being requested is part of the LMB memory map. Reserving memory that is not part of the LMB memory map is pretty futile -- the allocation functions do not allocate memory which has not been added to the LMB memory map. This series also removes the functionality allowing for reserving memory regions outside the LMB memory map. Any request for reserving a region of memory outside the LMB memory map now returns an -EINVAL error. Certain places in the common code using the LMB API's were not checking the return value of the functions. Checks have been added for them. There are some calls being made from the architecture/platform specific code which too do not check the return value. Those have been kept the same, as I do not have the platform with me to check if it causes any issues on those platforms. Finally, this version has a new patch which combines the functionality of the earlier lmb_overlaps_region() and lmb_can_reserve_region() into a single function. The first was used for allocation checks, while the second function was used to check if a reservation request could be satisfied. A new function, lmb_overlap_checks() has been added, which caters to both these scenarios. Changes since V2: * Changed the API name to lmb_alloc_mem() based on suggestion from Ilias - patch 1 * Changed the API name to lmb_alloc_mem() based on suggestion from Ilias - patch 2 * New patch based on suggestion from Ilias - patch 5 * Reflect the changed name of the API (lmb_alloc_mem) - patch 6 Sughosh Ganu (6): lmb: replace lmb_reserve() and lmb_alloc_addr() API's lmb: replace the lmb_alloc() and lmb_alloc_base() API's lmb: staticise lmb_add_memory() lmb: use a single function to free up memory lmb: use a single function to check for allocation and reservation requests doc: add lmb documentation arch/arm/mach-apple/board.c | 27 +++-- arch/arm/mach-mediatek/tzcfg.c | 8 +- arch/arm/mach-snapdragon/board.c | 13 ++- arch/powerpc/cpu/mpc85xx/mp.c | 4 +- arch/powerpc/lib/misc.c | 5 +- boot/bootm.c | 27 +++-- boot/image-board.c | 56 ++++++---- boot/image-fdt.c | 69 ++++++++---- cmd/booti.c | 10 +- cmd/bootz.c | 10 +- cmd/load.c | 7 +- doc/api/index.rst | 1 - doc/api/lmb.rst | 7 -- doc/develop/index.rst | 1 + doc/develop/lmb.rst | 166 +++++++++++++++++++++++++++ fs/fs.c | 5 +- include/lmb.h | 105 ++++++++---------- lib/efi_loader/efi_memory.c | 22 ++-- lib/lmb.c | 185 +++++++++++++++++-------------- test/lib/lmb.c | 102 +++++++++++------ 20 files changed, 566 insertions(+), 264 deletions(-) delete mode 100644 doc/api/lmb.rst create mode 100644 doc/develop/lmb.rst