]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common/memory: Add memregion descriptor print function
authorSergiu Moga <sergiu@unikraft.io>
Fri, 6 Oct 2023 09:25:47 +0000 (12:25 +0300)
committerRazvan Deaconescu <razvand@unikraft.io>
Fri, 20 Oct 2023 16:35:55 +0000 (19:35 +0300)
Implement a basic printing function for memory regions.
`ukplat_memregion_print_desc`'s implementation will be conditioned
by whether `CONFIG_LIBUKDEBUG_PRINTD` is enabled or not.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1060

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

index 0a585e9155820cb45bd4e1b073edc0bd36160fc8..ef2970df265e850833673cb38ba3714a5d5ce04f 100644 (file)
@@ -328,6 +328,55 @@ ukplat_memregion_list_delete(struct ukplat_memregion_list *list, __u32 idx)
        list->count--;
 }
 
+#if CONFIG_LIBUKDEBUG_PRINTD
+static inline void
+ukplat_memregion_print_desc(struct ukplat_memregion_desc *mrd)
+{
+       const char *type;
+
+       switch (mrd->type) {
+       case UKPLAT_MEMRT_RESERVED:
+               type = "rsvd";
+               break;
+       case UKPLAT_MEMRT_KERNEL:
+               type = "krnl";
+               break;
+       case UKPLAT_MEMRT_INITRD:
+               type = "ramd";
+               break;
+       case UKPLAT_MEMRT_CMDLINE:
+               type = "cmdl";
+               break;
+       case UKPLAT_MEMRT_DEVICETREE:
+               type = "dtb ";
+               break;
+       case UKPLAT_MEMRT_STACK:
+               type = "stck";
+               break;
+       default:
+               type = "";
+               break;
+       }
+
+       uk_pr_debug(" %012lx-%012lx %012lx %c%c%c %016lx %s %s\n",
+                  mrd->pbase, mrd->pbase + mrd->len, mrd->len,
+                  (mrd->flags & UKPLAT_MEMRF_READ) ? 'r' : '-',
+                  (mrd->flags & UKPLAT_MEMRF_WRITE) ? 'w' : '-',
+                  (mrd->flags & UKPLAT_MEMRF_EXECUTE) ? 'x' : '-',
+                  mrd->vbase,
+                  type,
+#if CONFIG_UKPLAT_MEMRNAME
+                  mrd->name
+#else /* !CONFIG_UKPLAT_MEMRNAME */
+                  ""
+#endif /* !CONFIG_UKPLAT_MEMRNAME */
+                  );
+}
+#else  /* !CONFIG_LIBUKDEBUG_PRINTD */
+static inline void
+ukplat_memregion_print_desc(struct ukplat_memregion_desc *mrd __unused) { }
+#endif /* !CONFIG_LIBUKDEBUG_PRINTD */
+
 /**
  * Coalesces the memory regions of a given memory region descriptor list.
  *