[PATCH 3/5] lmb: Move lmb property arrays in struct lmb

Patrick Delaunay patrick.delaunay at foss.st.com
Tue Feb 2 13:59:10 CET 2021


Move lmb property arrays to struct lmb and manage the array size in
a the new element 'max' of struct lmb_region. This modification allows
to update its size independently in the next patch.

see Linux kernel commit bf23c51f1f49 ("memblock: Move memblock arrays
to static storage in memblock.c and make their size a variable")

Signed-off-by: Patrick Delaunay <patrick.delaunay at foss.st.com>
---

 include/lmb.h | 31 ++++++++++++++++++++++++++++++-
 lib/lmb.c     |  8 +++++++-
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/include/lmb.h b/include/lmb.h
index a3247544c1..df543028d5 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -14,19 +14,48 @@
 
 #define MAX_LMB_REGIONS 8
 
+/**
+ * struct lmb_property - Description of one region.
+ *
+ * @base: Base address of the region.
+ * @size: Size of the region
+ */
 struct lmb_property {
 	phys_addr_t base;
 	phys_size_t size;
 };
 
+/**
+ * struct lmb_region - Description of a set of region.
+ *
+ * @cnt: Number of regions.
+ * @max: Size of the region array, max value of cnt.
+ * @region: Address of the region properties array
+ */
 struct lmb_region {
 	unsigned long cnt;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	unsigned long max;
+	struct lmb_property *region;
 };
 
+/**
+ * struct lmb - Logical memory block handle.
+ *
+ * Clients provide storage for Logical memory block (lmb) handles.
+ * The content of the structure is managed by the lmb library.
+ * A lmb struct is  initialized by lmb_init() functions.
+ * The lmb struct is passed to all other lmb APIs.
+ *
+ * @memory: Description of memory regions.
+ * @reserved: Description of reserved regions.
+ * @memory_regions: Array of the memory regions (statically allocated)
+ * @reserved_regions: Array of the reserved regions (statically allocated)
+ */
 struct lmb {
 	struct lmb_region memory;
 	struct lmb_region reserved;
+	struct lmb_property memory_regions[MAX_LMB_REGIONS + 1];
+	struct lmb_property reserved_regions[MAX_LMB_REGIONS + 1];
 };
 
 extern void lmb_init(struct lmb *lmb);
diff --git a/lib/lmb.c b/lib/lmb.c
index 5cf419f439..c97be0a064 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -95,7 +95,13 @@ static void lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1,
 
 void lmb_init(struct lmb *lmb)
 {
+	/* Hookup the initial arrays */
+	lmb->memory.region = lmb->memory_regions;
+	lmb->memory.max = ARRAY_SIZE(lmb->memory_regions) - 1;
 	lmb->memory.cnt = 0;
+
+	lmb->reserved.region = lmb->reserved_regions;
+	lmb->reserved.max = ARRAY_SIZE(lmb->reserved_regions) - 1;
 	lmb->reserved.cnt = 0;
 }
 
@@ -179,7 +185,7 @@ static long lmb_add_region(struct lmb_region *rgn, phys_addr_t base, phys_size_t
 
 	if (coalesced)
 		return coalesced;
-	if (rgn->cnt >= MAX_LMB_REGIONS)
+	if (rgn->cnt >= rgn->max)
 		return -1;
 
 	/* Couldn't coalesce the LMB, so add it to the sorted table. */
-- 
2.17.1



More information about the U-Boot mailing list