From patchwork Tue May 20 12:06:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 891316 Delivered-To: patch@linaro.org Received: by 2002:adf:e88a:0:b0:3a3:61c9:c5d4 with SMTP id d10csp1561113wrm; Tue, 20 May 2025 05:06:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWO28v6o4TrE3XGORk9Y6DlSnhx4U+CnGkU9YNqVxPscyHRfx7/lXt802bmxNQx9js5FRf+zg==@linaro.org X-Google-Smtp-Source: AGHT+IH1WzKz2RLy9KK7ChEs0X1aF3O4ZyWSa3YAswKPYaI10OwfxOMBU6lyNcpBx/BlIC7zNPZ7 X-Received: by 2002:a05:600c:4e14:b0:43d:563:6fef with SMTP id 5b1f17b1804b1-442ff031969mr131894585e9.21.1747742784032; Tue, 20 May 2025 05:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747742784; cv=none; d=google.com; s=arc-20240605; b=GLsLXgpcZpGQAyXmcxd8dPKqsLNoyjdqN9N+lcy/QK2RuhxTetf62lQqMtxxsR3xbl 0Yuay/UwAfgBkQNoCEq+2+MlWaHH0KffmMo13Cfql+s+Bc85NGE3IAk9hIIjpiJDvcC7 OW/DDEGcMifSUsyhg9ReG8BYqAoV/80x3rI+UQiPuEwlb40Leasgt717wlara27jJdgt MdQA5CGUSKhK04Y3lTt0aSBKRNEV66c2WUJzUIHFjRhsW6iNunhUS9ghY+XEkXVkhPA7 Qv+BuueSzCDtL709u0fQdmueNtkYmuZkKcpf0AbwMXKubv8zINZLh9ohsyYAynHoY2Sz BdoA== 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=7hrsIck1MPMWUYyTIsAcEFk5SxmcPmn/tDNQXtytUpo=; fh=89MlnLdazmnhKnYeHaI4JcicUnUrLLJuTd/r2dh4RLc=; b=lHjPJT71kOum4XxO1QOdotlEdvP8zNH7zIDxmKwxF4VDcIH8v8j7b8nWjBrSFiOCfX viZb8ORvnizk4/ILz8N0CsmFIgaTsVNwEx8soSGUi1AfLbuLKEgO8k+ABnwqG4rUTQCA lZwTyikc5QHE51jBYIjGN83BLXpydUTJtWWvR6CjAWV8S9606vZdHERFQT4p1qw5pNOR lWC6MZrgUHCVuaZzrxchBRMB3tdCxiAX3ckhsuvpI6iNhBvx/dDGel+QkbPPRsLLb0cT ksBqQe9rHAaHdImx7nmz8zp3d8aeVzuayV2YCcfd7VFc1KnvC8oKaS+4Va64ZSzuWwZ0 A4GQ==; 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 ffacd0b85a97d-3a365bc0b16si5662207f8f.198.2025.05.20.05.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 05:06:24 -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 E7C8B82B00; Tue, 20 May 2025 14:06:22 +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 6BDD582BB4; Tue, 20 May 2025 14:06:21 +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 00D6582A8D for ; Tue, 20 May 2025 14:06: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 DF7091516; Tue, 20 May 2025 05:06:04 -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 814953F5A1; Tue, 20 May 2025 05:06:15 -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 v2 0/5] lmb: use a single API for all allocations Date: Tue, 20 May 2025 17:36:01 +0530 Message-Id: <20250520120606.173228-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_allocate_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. Changes since V1: * Check the return value of the lmb API in some of the common, non-arch code that got missed out in the earlier version. Done where applicable. (patch 1) * Declare a local variable of type phys_addr_t and use that while calling the API, instead of casting the parameter to a void *. Done where applicable. (patch 1) * Keep the value of of_start as a pointer instead of an user-address in boot_relocate_fdt(). (patch 1) * Made changes to the documentation for the lmb_allocate_mem() API to highlight function parameters and other important constants. (patch 1) * Check the return value of the lmb API in some of the common, non-arch code that got missed out in the earlier version. Done where applicable. (patch 2) * Declare a local variable of type phys_addr_t and use that while calling the API, instead of casting the parameter to a void *. Done where applicable. (patch 2) * Optimize the use of the lmb API in boot_ramdisk_high(). (patch 2) * s/desired_addr/high_addr in boot_relocate_fdt(). (patch 2) * Fallthrough the LMB_MEM_ALLOC_ANY case in lmb_allocate_mem() as suggested by Ilias. (patch 2) Sughosh Ganu (5): 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 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 | 70 +++++++++---- 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 | 169 +++++++++++++++++-------------- test/lib/lmb.c | 102 +++++++++++++------ 20 files changed, 559 insertions(+), 256 deletions(-) delete mode 100644 doc/api/lmb.rst create mode 100644 doc/develop/lmb.rst