mbox series

[v3,0/6] lmb: use a single API for all allocations

Message ID 20250526091253.400802-1-sughosh.ganu@linaro.org
Headers show
Series lmb: use a single API for all allocations | expand

Message

Sughosh Ganu May 26, 2025, 9:12 a.m. UTC
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