From patchwork Thu Jun 12 06:56:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 895748 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp3163000wrb; Wed, 11 Jun 2025 23:56:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXlJ1wEU13wwUC1qmZHkFbPumHAoaAjg7F9Ze8e3NlgfEGuTBAKd7t7n301oj3ptEoJuZrhKw==@linaro.org X-Google-Smtp-Source: AGHT+IF9DqvNrq1i3q3Q9pUjyzNyKBRZw3vdRaqZnV22KUgcjQe5EjdMG71tbL1UW8yZ1TZkmWYs X-Received: by 2002:a17:906:9f86:b0:ade:f72:435 with SMTP id a640c23a62f3a-adea26ed2a6mr276443366b.36.1749711407045; Wed, 11 Jun 2025 23:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749711407; cv=none; d=google.com; s=arc-20240605; b=Set+rOF+HgcUat2K08YQDmzgViDEud3vBU71qw+6COtYi0tzcq7iro/AnO9l7lKPbH E7kBpU/TSuNYpLbYZwkmBbrK2u35r8q4FUy+39w6JbYC2GZREVq8KBF6TVn2sr7iQCiA Fcn2LD+1RU7k0J1PuxpLu5yygKdAp2WFqoAf9h5wTPgmdA+On/0gHfJQ5vTmqAZYLl6a N+jI1btmS0svxxhFJHp2UOde+RwRHyU1qT1RVc4BX0enWuGw2GBw5zqJ1AwcHTRav9F+ k89zi6fxwFHDSY/tTaEDLpB9x8bsIgkT5n0eaz0cMKfoD3MKdH4o367CbtUQba3sB52H tcbg== 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=PBdhWc+6QiPGJ7cyjNGGrM0Uq4WBMCrHX8h9yn/ao4w=; fh=89MlnLdazmnhKnYeHaI4JcicUnUrLLJuTd/r2dh4RLc=; b=ZtH1DJTN3nAdzJvVJqcwIU1VD0S7tK2c3yEfE8z1HBjRFWvq9sd0ugsiAyiqXs7cNd RtkutgOR3sw4ZCsK3Y4SxpYEoulfGfu8UDcIPjRmIfkIK3Ue446YCefkEF6DEnO77lc9 SyuFx9uOShIxajuYdjVjSaUdzUJG0cJEuUjrRenmYbSuh1/5WzEoGyI+f0vIhcXbTGsB M8jvL5/IDjoQ2CYF82He24yD838CXinNwP4ioV3yTMJ5wOJDNBNfCd+TYLbbqL8ZrRfZ qi5qKy1fIlIizDkTfhRKHQSYO187M1/6NB6X+yqBjszngcbQdD3crLW+2B+HZ/vOGtpa 07TA==; 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-adeadf4bf8bsi93406366b.596.2025.06.11.23.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 23:56:47 -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 ED46782A4B; Thu, 12 Jun 2025 08:56:45 +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 4C3D682B20; Thu, 12 Jun 2025 08:56:44 +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 0BE15828A2 for ; Thu, 12 Jun 2025 08:56:42 +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 72BF71595; Wed, 11 Jun 2025 23:56:21 -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 5B3743F66E; Wed, 11 Jun 2025 23:56:38 -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 v4 0/7] lmb: use a single API for all allocations Date: Thu, 12 Jun 2025 12:26:17 +0530 Message-Id: <20250612065624.751014-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. In addition, there is a patch which refactors code in lmb_overlaps_region() and lmb_can_reserve_region() so that both functionalities can be put in a single function, lmb_overlap_checks(). Finally, a new patch has been added which checks the return value of the lmb allocation function before copying the device-tree to the allocated address. Changes since V3: * s/addr/dest_addr in load_serial() for use with the lmb API - patch 1 * mach-apple: Check the return value of the lmb allocation API, and set the env variables only when the API returns success - patch 2 * mach-snapdragon: Check the return value of the lmb allocation API, and set the env variables only when the API returns success - patch 2 * New patch for checking the return value of allocation before copy of device-tree - patch 6 Sughosh Ganu (7): 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 mach-snapdragon: add a check before copying FDT to fdt_addr_r doc: add lmb documentation arch/arm/mach-apple/board.c | 27 +++-- arch/arm/mach-mediatek/tzcfg.c | 8 +- arch/arm/mach-snapdragon/board.c | 41 ++++--- 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 | 9 +- 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, 580 insertions(+), 280 deletions(-) delete mode 100644 doc/api/lmb.rst create mode 100644 doc/develop/lmb.rst