lmb: add lmb_is_reserved_flags
authorPatrick Delaunay <patrick.delaunay@foss.st.com>
Fri, 7 May 2021 12:50:30 +0000 (14:50 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 7 Jun 2021 14:48:40 +0000 (10:48 -0400)
Add a new function lmb_is_reserved_flags to check if
an address is reserved with a specific flags.

This function can be used to check if an address was
reserved with no-map flags with:

lmb_is_reserved_flags(lmb, addr, LMB_NOMAP);

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
include/lmb.h
lib/lmb.c

index e900b3d..3c4afdf 100644 (file)
@@ -100,6 +100,15 @@ extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
                                  phys_size_t size);
 extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
 extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
+/**
+ * lmb_is_reserved_flags - test if tha address is in reserved region with a bitfield flag
+ *
+ * @lmb                the logical memory block struct
+ * @addr       address to be tested
+ * @flags      flags bitfied to be tested
+ * @return 0 if not reserved or reserved without the requested flag else 1
+ */
+int lmb_is_reserved_flags(struct lmb *lmb, phys_addr_t addr, int flags);
 extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
 
 extern void lmb_dump_all(struct lmb *lmb);
index 69700bf..a0fb8c7 100644 (file)
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -443,7 +443,7 @@ phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr)
        return 0;
 }
 
-int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr)
+int lmb_is_reserved_flags(struct lmb *lmb, phys_addr_t addr, int flags)
 {
        int i;
 
@@ -451,11 +451,16 @@ int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr)
                phys_addr_t upper = lmb->reserved.region[i].base +
                        lmb->reserved.region[i].size - 1;
                if ((addr >= lmb->reserved.region[i].base) && (addr <= upper))
-                       return 1;
+                       return (lmb->reserved.region[i].flags & flags) == flags;
        }
        return 0;
 }
 
+int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr)
+{
+       return lmb_is_reserved_flags(lmb, addr, LMB_NONE);
+}
+
 __weak void board_lmb_reserve(struct lmb *lmb)
 {
        /* please define platform specific board_lmb_reserve() */