[PATCH v4 0/7] lmb: use a single API for all allocations

Sughosh Ganu sughosh.ganu at linaro.org
Thu Jun 12 08:56:17 CEST 2025


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

-- 
2.34.1




More information about the U-Boot mailing list