]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common: Introduce `ukplat_memregion_list_insert_at_idx`
authorSergiu Moga <sergiu.moga@protonmail.com>
Wed, 17 May 2023 09:25:23 +0000 (12:25 +0300)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 10:18:44 +0000 (10:18 +0000)
Implement the equivalent of `ukplat_memregion_list_insert` but one
that is aware of the index where it is inserting the memory region.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #848

plat/common/include/uk/plat/common/memory.h

index 599e21cbaae7139ff4f4d39219f6bd8abb01367a..def09e39d8b177bbc7a6a53924e2881111f078bd 100644 (file)
@@ -112,6 +112,33 @@ ukplat_memregion_list_insert(struct ukplat_memregion_list *list,
        return (int)i;
 }
 
+/**
+ * Inserts the region into the memory region list by index. The list is kept in
+ * ascending order of physical base addresses. Order is only preserved among
+ * ranges that do not overlap.
+ *
+ * NOTE:This function assumes that the caller knows what they are doing, as
+ *     it is expected that the memory region descriptor list is always
+ *     ordered. USE WITH CAUTION!
+ */
+static inline int
+ukplat_memregion_list_insert_at_idx(struct ukplat_memregion_list *list,
+                                   const struct ukplat_memregion_desc *mrd,
+                                   __u32 idx)
+{
+       struct ukplat_memregion_desc *p;
+
+       if (unlikely(list->count == list->capacity))
+               return -ENOMEM;
+
+       p = &list->mrds[idx];
+       memmove(p + 1, p, sizeof(*p) * (list->count - idx));
+
+       *p = *mrd;
+       list->count++;
+       return (int)idx;
+}
+
 /**
  * Insert a new region into the memory region list. This extends
  * ukplat_memregion_list_insert to carve out the area of any pre-existing