[PATCH v2 2/2] xen/common: Move Arm's bootfdt.c to common

Oleksii Kurochko posted 2 patches 3 months, 2 weeks ago
[PATCH v2 2/2] xen/common: Move Arm's bootfdt.c to common
Posted by Oleksii Kurochko 3 months, 2 weeks ago
From: Shawn Anastasio <sanastasio@raptorengineering.com>

Move Arm's bootfdt.c to xen/common so that it can be used by other
device tree architectures like PPC and RISCV.

Remove stubs for process_shm_node() and early_print_info_shmem()
from $xen/arch/arm/include/asm/static-shmem.h.
These stubs are removed to avoid introducing them for architectures
that do not support CONFIG_STATIC_SHM.
The process_shm_node() stub is now implemented in common code to
maintain the current behavior of early_scan_code() on ARM.
The early_print_info_shmem() stub is only used in early_print_info(),
so it's now guarded with #ifdef CONFIG_STATIC_SHM ... #endif.

Suggested-by: Julien Grall <julien@xen.org>
Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Julien Grall <jgrall@amazon.com>
---
Changes in V9:
 - add Acked-by: Julien Grall <jgrall@amazon.com>
---
Changes in V8:
 - Fix the change log for this patch ( accidentally the change log of the previous
   patch was copied to this ).
 - Drop the stub of process_shm_node() and early_print_info_shmem() in
   xen/arch/arm/include/asm/static-shmem.h as it is moved to common code to not
   re-introduce the same stub for each architecture which doesn't support
   CONFIG_STATIC_SHM now.
 - Drop Acked-by: Julien Grall <julien@xen.org> as after the Ack additional changes were
   done so an additional review is needed.
---
Changes in V7:
 - Nothing changed. Only rebase.
---
Changes in V6:
 - update the version of the patch to v6.
---
Changes in v5:
 - After rebase the Shawn's patch v4 on top of current staging the following
   was done:
   - add guard #ifdef CONFIG_STATIC_SHM around inclusion of <asm/static-shmem.h>
     in common/device-tree/bootfdt.c.
   - add stub for process_shm_node() in case CONFIG_STATIC_SHM isn't enabled.
   - add guard around #ifdef CONFIG_STATIC_SHM aroud early_print_info_shmem() in
     early_print_info().
---
Changes in v4:
  - move function prototypes to patch 2's xen/include/bootfdt.h
  - clean up #includes
---
 xen/arch/arm/Makefile                         |  1 -
 xen/arch/arm/include/asm/setup.h              | 13 ----------
 xen/arch/arm/include/asm/static-shmem.h       |  9 -------
 xen/common/device-tree/Makefile               |  1 +
 .../arm => common/device-tree}/bootfdt.c      | 24 +++++++++++++++----
 xen/include/xen/bootfdt.h                     | 14 +++++++++++
 6 files changed, 34 insertions(+), 28 deletions(-)
 rename xen/{arch/arm => common/device-tree}/bootfdt.c (98%)

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 45dc29ea53..da9c979dc4 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -10,7 +10,6 @@ obj-$(CONFIG_TEE) += tee/
 obj-$(CONFIG_HAS_VPCI) += vpci.o
 
 obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
-obj-y += bootfdt.init.o
 obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h
index 1748be29e5..64c227d171 100644
--- a/xen/arch/arm/include/asm/setup.h
+++ b/xen/arch/arm/include/asm/setup.h
@@ -41,19 +41,6 @@ void fw_unreserved_regions(paddr_t s, paddr_t e,
                            void (*cb)(paddr_t ps, paddr_t pe),
                            unsigned int first);
 
-bool check_reserved_regions_overlap(paddr_t region_start, paddr_t region_size);
-
-struct bootmodule *add_boot_module(bootmodule_kind kind,
-                                   paddr_t start, paddr_t size, bool domU);
-struct bootmodule *boot_module_find_by_kind(bootmodule_kind kind);
-struct bootmodule * boot_module_find_by_addr_and_kind(bootmodule_kind kind,
-                                                             paddr_t start);
-void add_boot_cmdline(const char *name, const char *cmdline,
-                      bootmodule_kind kind, paddr_t start, bool domU);
-struct bootcmdline *boot_cmdline_find_by_kind(bootmodule_kind kind);
-struct bootcmdline * boot_cmdline_find_by_name(const char *name);
-const char *boot_module_kind_as_string(bootmodule_kind kind);
-
 void init_pdx(void);
 void setup_mm(void);
 
diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include/asm/static-shmem.h
index 806ee41cfc..fd0867c4f2 100644
--- a/xen/arch/arm/include/asm/static-shmem.h
+++ b/xen/arch/arm/include/asm/static-shmem.h
@@ -80,15 +80,6 @@ static inline int process_shm_chosen(struct domain *d,
     return 0;
 }
 
-static inline int process_shm_node(const void *fdt, int node,
-                                   uint32_t address_cells, uint32_t size_cells)
-{
-    printk("CONFIG_STATIC_SHM must be enabled for parsing static shared memory nodes\n");
-    return -EINVAL;
-}
-
-static inline void early_print_info_shmem(void) {};
-
 static inline void init_sharedmem_pages(void) {};
 
 static inline int remove_shm_from_rangeset(const struct kernel_info *kinfo,
diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makefile
index f813f7555f..990abd571a 100644
--- a/xen/common/device-tree/Makefile
+++ b/xen/common/device-tree/Makefile
@@ -1,2 +1,3 @@
+obj-y += bootfdt.init.o
 obj-y += bootinfo.init.o
 obj-y += device-tree.o
diff --git a/xen/arch/arm/bootfdt.c b/xen/common/device-tree/bootfdt.c
similarity index 98%
rename from xen/arch/arm/bootfdt.c
rename to xen/common/device-tree/bootfdt.c
index 6e060111d9..f7998979c1 100644
--- a/xen/arch/arm/bootfdt.c
+++ b/xen/common/device-tree/bootfdt.c
@@ -4,18 +4,20 @@
  *
  * Copyright (C) 2012-2014 Citrix Systems, Inc.
  */
-#include <xen/types.h>
-#include <xen/lib.h>
-#include <xen/kernel.h>
-#include <xen/init.h>
-#include <xen/efi.h>
+
+#include <xen/bootfdt.h>
 #include <xen/device_tree.h>
+#include <xen/efi.h>
+#include <xen/init.h>
+#include <xen/kernel.h>
 #include <xen/lib.h>
 #include <xen/libfdt/libfdt-xen.h>
 #include <xen/sort.h>
 #include <xsm/xsm.h>
 #include <asm/setup.h>
+#ifdef CONFIG_STATIC_SHM
 #include <asm/static-shmem.h>
+#endif
 
 static void __init __maybe_unused build_assertions(void)
 {
@@ -436,6 +438,16 @@ static int __init process_domain_node(const void *fdt, int node,
                                    MEMBANK_STATIC_DOMAIN);
 }
 
+#ifndef CONFIG_STATIC_SHM
+static inline int process_shm_node(const void *fdt, int node,
+                                   uint32_t address_cells, uint32_t size_cells)
+{
+    printk("CONFIG_STATIC_SHM must be enabled for parsing static shared"
+            " memory nodes\n");
+    return -EINVAL;
+}
+#endif
+
 static int __init early_scan_node(const void *fdt,
                                   int node, const char *name, int depth,
                                   u32 address_cells, u32 size_cells,
@@ -495,7 +507,9 @@ static void __init early_print_info(void)
                mem_resv->bank[i].start,
                mem_resv->bank[i].start + mem_resv->bank[i].size - 1);
     }
+#ifdef CONFIG_STATIC_SHM
     early_print_info_shmem();
+#endif
     printk("\n");
     for ( i = 0 ; i < cmds->nr_mods; i++ )
         printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start,
diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h
index c39428d5f5..16fa05f38f 100644
--- a/xen/include/xen/bootfdt.h
+++ b/xen/include/xen/bootfdt.h
@@ -157,6 +157,20 @@ struct bootinfo {
 
 extern struct bootinfo bootinfo;
 
+bool check_reserved_regions_overlap(paddr_t region_start,
+                                    paddr_t region_size);
+
+struct bootmodule *add_boot_module(bootmodule_kind kind,
+                                   paddr_t start, paddr_t size, bool domU);
+struct bootmodule *boot_module_find_by_kind(bootmodule_kind kind);
+struct bootmodule * boot_module_find_by_addr_and_kind(bootmodule_kind kind,
+                                                             paddr_t start);
+void add_boot_cmdline(const char *name, const char *cmdline,
+                      bootmodule_kind kind, paddr_t start, bool domU);
+struct bootcmdline *boot_cmdline_find_by_kind(bootmodule_kind kind);
+struct bootcmdline * boot_cmdline_find_by_name(const char *name);
+const char *boot_module_kind_as_string(bootmodule_kind kind);
+
 void populate_boot_allocator(void);
 
 size_t boot_fdt_info(const void *fdt, paddr_t paddr);
-- 
2.45.2