[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 13/19] xen/dt: Move bootinfo functions to a new bootinfo.h
Part of an unpicking process to extract bootfdt contents independent of bootinfo to a separate file for x86 to take. With this, bootfdt.h can be cleanly included from x86. A later patch extracts the definitions so the functions may be called too. Not a functional change. Signed-off-by: Alejandro Vallejo <agarciav@xxxxxxx> --- xen/arch/arm/domain_build.c | 1 + xen/arch/arm/mmu/mm.c | 1 + xen/arch/riscv/mm.c | 2 +- xen/arch/riscv/setup.c | 2 +- xen/common/device-tree/bootfdt.c | 1 + xen/common/device-tree/bootinfo.c | 2 +- xen/common/device-tree/dom0less-build.c | 2 +- xen/common/device-tree/domain-build.c | 2 +- xen/common/device-tree/kernel.c | 2 +- xen/include/xen/bootfdt.h | 206 ----------------------- xen/include/xen/bootinfo.h | 212 ++++++++++++++++++++++++ xen/include/xen/device_tree.h | 2 +- xen/include/xen/fdt-domain-build.h | 2 +- xen/include/xen/fdt-kernel.h | 2 +- 14 files changed, 224 insertions(+), 215 deletions(-) create mode 100644 xen/include/xen/bootinfo.h diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 11cc03e5db..c53da76682 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include <xen/init.h> +#include <xen/bootinfo.h> #include <xen/compile.h> #include <xen/fdt-domain-build.h> #include <xen/fdt-kernel.h> diff --git a/xen/arch/arm/mmu/mm.c b/xen/arch/arm/mmu/mm.c index 9c50479c63..77f82757bb 100644 --- a/xen/arch/arm/mmu/mm.c +++ b/xen/arch/arm/mmu/mm.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/macros.h> diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index d3ece9f132..040db73d00 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/bug.h> #include <xen/compiler.h> #include <xen/init.h> diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 4e416f6e44..0a2d0dc1eb 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -2,7 +2,7 @@ #include <xen/acpi.h> #include <xen/bug.h> -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/compile.h> #include <xen/device_tree.h> #include <xen/init.h> diff --git a/xen/common/device-tree/bootfdt.c b/xen/common/device-tree/bootfdt.c index 529c91e603..fb4ac06390 100644 --- a/xen/common/device-tree/bootfdt.c +++ b/xen/common/device-tree/bootfdt.c @@ -6,6 +6,7 @@ */ #include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/device_tree.h> #include <xen/efi.h> #include <xen/init.h> diff --git a/xen/common/device-tree/bootinfo.c b/xen/common/device-tree/bootinfo.c index 717cfa0962..69491bdb0b 100644 --- a/xen/common/device-tree/bootinfo.c +++ b/xen/common/device-tree/bootinfo.c @@ -10,7 +10,7 @@ */ #include <xen/acpi.h> -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/bug.h> #include <xen/device_tree.h> #include <xen/init.h> diff --git a/xen/common/device-tree/dom0less-build.c b/xen/common/device-tree/dom0less-build.c index 39cb2cd5c7..c798807560 100644 --- a/xen/common/device-tree/dom0less-build.c +++ b/xen/common/device-tree/dom0less-build.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/device_tree.h> #include <xen/domain.h> #include <xen/domain_page.h> diff --git a/xen/common/device-tree/domain-build.c b/xen/common/device-tree/domain-build.c index 6b8b8d7cac..e5d34dd89d 100644 --- a/xen/common/device-tree/domain-build.c +++ b/xen/common/device-tree/domain-build.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/fdt-domain-build.h> #include <xen/init.h> #include <xen/lib.h> diff --git a/xen/common/device-tree/kernel.c b/xen/common/device-tree/kernel.c index cb04cd9d50..d02440cc2d 100644 --- a/xen/common/device-tree/kernel.c +++ b/xen/common/device-tree/kernel.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/device_tree.h> #include <xen/fdt-kernel.h> #include <xen/errno.h> diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index 079259c719..766956e102 100644 --- a/xen/include/xen/bootfdt.h +++ b/xen/include/xen/bootfdt.h @@ -4,9 +4,6 @@ #include <xen/byteorder.h> #include <xen/types.h> -#include <xen/kernel.h> -#include <xen/macros.h> -#include <xen/xmalloc.h> #if __has_include(<asm/bootfdt.h>) #include <asm/bootfdt.h> @@ -14,15 +11,10 @@ #define MIN_FDT_ALIGN 8 -#define NR_MEM_BANKS 256 -#define NR_SHMEM_BANKS 32 - /* Default #address and #size cells */ #define DT_ROOT_NODE_ADDR_CELLS_DEFAULT 2 #define DT_ROOT_NODE_SIZE_CELLS_DEFAULT 1 -#define MAX_MODULES 32 /* Current maximum useful modules */ - #define DEVICE_TREE_MAX_DEPTH 16 /* Helper to read a big number; size is in cells (not bytes) */ @@ -75,77 +67,6 @@ typedef enum { BOOTMOD_UNKNOWN } bootmodule_kind; -enum membank_type { - /* - * The MEMBANK_DEFAULT type refers to either reserved memory for the - * device/firmware (when the bank is in 'reserved_mem') or any RAM (when - * the bank is in 'mem'). - */ - MEMBANK_DEFAULT, - /* - * The MEMBANK_STATIC_DOMAIN type is used to indicate whether the memory - * bank is bound to a static Xen domain. It is only valid when the bank - * is in reserved_mem. - */ - MEMBANK_STATIC_DOMAIN, - /* - * The MEMBANK_STATIC_HEAP type is used to indicate whether the memory - * bank is reserved as static heap. It is only valid when the bank is - * in reserved_mem. - */ - MEMBANK_STATIC_HEAP, - /* - * The MEMBANK_FDT_RESVMEM type is used to indicate whether the memory - * bank is from the FDT reserve map. - */ - MEMBANK_FDT_RESVMEM, -}; - -enum region_type { - MEMORY, - RESERVED_MEMORY, - STATIC_SHARED_MEMORY -}; - -/* Indicates the maximum number of characters(\0 included) for shm_id */ -#define MAX_SHM_ID_LENGTH 16 - -struct shmem_membank_extra { - char shm_id[MAX_SHM_ID_LENGTH]; - unsigned int nr_shm_borrowers; -}; - -struct membank { - paddr_t start; - paddr_t size; - union { - enum membank_type type; -#ifdef CONFIG_STATIC_SHM - struct shmem_membank_extra *shmem_extra; -#endif - }; -}; - -struct membanks { - __struct_group(membanks_hdr, common, , - unsigned int nr_banks; - unsigned int max_banks; - enum region_type type; - ); - struct membank bank[]; -}; - -struct meminfo { - struct membanks_hdr common; - struct membank bank[NR_MEM_BANKS]; -}; - -struct shared_meminfo { - struct membanks_hdr common; - struct membank bank[NR_SHMEM_BANKS]; - struct shmem_membank_extra extra[NR_SHMEM_BANKS]; -}; - /* * The domU flag is set for kernels and ramdisks of "xen,domain" nodes. * The purpose of the domU flag is to avoid getting confused in @@ -165,133 +86,6 @@ struct bootmodule { #endif }; -/* DT_MAX_NAME is the node name max length according the DT spec */ -#define DT_MAX_NAME 41 -struct bootcmdline { - bootmodule_kind kind; - bool domU; - paddr_t start; - char dt_name[DT_MAX_NAME]; - char cmdline[BOOTMOD_MAX_CMDLINE]; -}; - -struct bootmodules { - int nr_mods; - struct bootmodule module[MAX_MODULES]; -}; - -struct bootcmdlines { - unsigned int nr_mods; - struct bootcmdline cmdline[MAX_MODULES]; -}; - -struct bootinfo { - struct meminfo mem; - /* The reserved regions are only used when booting using Device-Tree */ - struct meminfo reserved_mem; - struct bootmodules modules; - struct bootcmdlines cmdlines; -#ifdef CONFIG_ACPI - struct meminfo acpi; -#endif -#ifdef CONFIG_STATIC_SHM - struct shared_meminfo shmem; -#endif -}; - -#ifdef CONFIG_ACPI -#define BOOTINFO_ACPI_INIT \ - .acpi.common.max_banks = NR_MEM_BANKS, \ - .acpi.common.type = MEMORY, -#else -#define BOOTINFO_ACPI_INIT -#endif - -#ifdef CONFIG_STATIC_SHM -#define BOOTINFO_SHMEM_INIT \ - .shmem.common.max_banks = NR_SHMEM_BANKS, \ - .shmem.common.type = STATIC_SHARED_MEMORY, -#else -#define BOOTINFO_SHMEM_INIT -#endif - -#define BOOTINFO_INIT \ -{ \ - .mem.common.max_banks = NR_MEM_BANKS, \ - .mem.common.type = MEMORY, \ - .reserved_mem.common.max_banks = NR_MEM_BANKS, \ - .reserved_mem.common.type = RESERVED_MEMORY, \ - BOOTINFO_ACPI_INIT \ - BOOTINFO_SHMEM_INIT \ -} - -extern struct bootinfo bootinfo; - -bool check_reserved_regions_overlap(paddr_t region_start, - paddr_t region_size, - bool allow_memreserve_overlap); - -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); - -const char *boot_fdt_cmdline(const void *fdt); - -static inline struct membanks *bootinfo_get_reserved_mem(void) -{ - return container_of(&bootinfo.reserved_mem.common, struct membanks, common); -} - -static inline struct membanks *bootinfo_get_mem(void) -{ - return container_of(&bootinfo.mem.common, struct membanks, common); -} - -#ifdef CONFIG_ACPI -static inline struct membanks *bootinfo_get_acpi(void) -{ - return container_of(&bootinfo.acpi.common, struct membanks, common); -} -#endif - -#ifdef CONFIG_STATIC_SHM -static inline struct membanks *bootinfo_get_shmem(void) -{ - return container_of(&bootinfo.shmem.common, struct membanks, common); -} - -static inline struct shmem_membank_extra *bootinfo_get_shmem_extra(void) -{ - return bootinfo.shmem.extra; -} -#endif - -static inline struct membanks *membanks_xzalloc(unsigned int nr, - enum region_type type) -{ - struct membanks *banks = xzalloc_flex_struct(struct membanks, bank, nr); - - if ( !banks ) - goto out; - - banks->max_banks = nr; - banks->type = type; - - out: - return banks; -} - /* * Interpret the property `prop_name` of `node` as a u32. * diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h new file mode 100644 index 0000000000..bf7516ec1f --- /dev/null +++ b/xen/include/xen/bootinfo.h @@ -0,0 +1,212 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef XEN_BOOTINFO_H +#define XEN_BOOTINFO_H + +#include <xen/bootfdt.h> +#include <xen/kernel.h> +#include <xen/macros.h> +#include <xen/xmalloc.h> + +#define NR_MEM_BANKS 256 +#define NR_SHMEM_BANKS 32 + +#define MAX_MODULES 32 /* Current maximum useful modules */ + +enum membank_type { + /* + * The MEMBANK_DEFAULT type refers to either reserved memory for the + * device/firmware (when the bank is in 'reserved_mem') or any RAM (when + * the bank is in 'mem'). + */ + MEMBANK_DEFAULT, + /* + * The MEMBANK_STATIC_DOMAIN type is used to indicate whether the memory + * bank is bound to a static Xen domain. It is only valid when the bank + * is in reserved_mem. + */ + MEMBANK_STATIC_DOMAIN, + /* + * The MEMBANK_STATIC_HEAP type is used to indicate whether the memory + * bank is reserved as static heap. It is only valid when the bank is + * in reserved_mem. + */ + MEMBANK_STATIC_HEAP, + /* + * The MEMBANK_FDT_RESVMEM type is used to indicate whether the memory + * bank is from the FDT reserve map. + */ + MEMBANK_FDT_RESVMEM, +}; + +enum region_type { + MEMORY, + RESERVED_MEMORY, + STATIC_SHARED_MEMORY +}; + +/* Indicates the maximum number of characters(\0 included) for shm_id */ +#define MAX_SHM_ID_LENGTH 16 + +struct shmem_membank_extra { + char shm_id[MAX_SHM_ID_LENGTH]; + unsigned int nr_shm_borrowers; +}; + +struct membank { + paddr_t start; + paddr_t size; + union { + enum membank_type type; +#ifdef CONFIG_STATIC_SHM + struct shmem_membank_extra *shmem_extra; +#endif + }; +}; + +struct membanks { + __struct_group(membanks_hdr, common, , + unsigned int nr_banks; + unsigned int max_banks; + enum region_type type; + ); + struct membank bank[]; +}; + +struct meminfo { + struct membanks_hdr common; + struct membank bank[NR_MEM_BANKS]; +}; + +struct shared_meminfo { + struct membanks_hdr common; + struct membank bank[NR_SHMEM_BANKS]; + struct shmem_membank_extra extra[NR_SHMEM_BANKS]; +}; + +/* DT_MAX_NAME is the node name max length according the DT spec */ +#define DT_MAX_NAME 41 +struct bootcmdline { + bootmodule_kind kind; + bool domU; + paddr_t start; + char dt_name[DT_MAX_NAME]; + char cmdline[BOOTMOD_MAX_CMDLINE]; +}; + +struct bootmodules { + int nr_mods; + struct bootmodule module[MAX_MODULES]; +}; + +struct bootcmdlines { + unsigned int nr_mods; + struct bootcmdline cmdline[MAX_MODULES]; +}; + +struct bootinfo { + struct meminfo mem; + /* The reserved regions are only used when booting using Device-Tree */ + struct meminfo reserved_mem; + struct bootmodules modules; + struct bootcmdlines cmdlines; +#ifdef CONFIG_ACPI + struct meminfo acpi; +#endif +#ifdef CONFIG_STATIC_SHM + struct shared_meminfo shmem; +#endif +}; + +#ifdef CONFIG_ACPI +#define BOOTINFO_ACPI_INIT \ + .acpi.common.max_banks = NR_MEM_BANKS, \ + .acpi.common.type = MEMORY, +#else +#define BOOTINFO_ACPI_INIT +#endif + +#ifdef CONFIG_STATIC_SHM +#define BOOTINFO_SHMEM_INIT \ + .shmem.common.max_banks = NR_SHMEM_BANKS, \ + .shmem.common.type = STATIC_SHARED_MEMORY, +#else +#define BOOTINFO_SHMEM_INIT +#endif + +#define BOOTINFO_INIT \ +{ \ + .mem.common.max_banks = NR_MEM_BANKS, \ + .mem.common.type = MEMORY, \ + .reserved_mem.common.max_banks = NR_MEM_BANKS, \ + .reserved_mem.common.type = RESERVED_MEMORY, \ + BOOTINFO_ACPI_INIT \ + BOOTINFO_SHMEM_INIT \ +} + +extern struct bootinfo bootinfo; + +bool check_reserved_regions_overlap(paddr_t region_start, + paddr_t region_size, + bool allow_memreserve_overlap); + +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); +const char *boot_fdt_cmdline(const void *fdt); + +static inline struct membanks *bootinfo_get_reserved_mem(void) +{ + return container_of(&bootinfo.reserved_mem.common, struct membanks, common); +} + +static inline struct membanks *bootinfo_get_mem(void) +{ + return container_of(&bootinfo.mem.common, struct membanks, common); +} + +#ifdef CONFIG_ACPI +static inline struct membanks *bootinfo_get_acpi(void) +{ + return container_of(&bootinfo.acpi.common, struct membanks, common); +} +#endif + +#ifdef CONFIG_STATIC_SHM +static inline struct membanks *bootinfo_get_shmem(void) +{ + return container_of(&bootinfo.shmem.common, struct membanks, common); +} + +static inline struct shmem_membank_extra *bootinfo_get_shmem_extra(void) +{ + return bootinfo.shmem.extra; +} +#endif + +static inline struct membanks *membanks_xzalloc(unsigned int nr, + enum region_type type) +{ + struct membanks *banks = xzalloc_flex_struct(struct membanks, bank, nr); + + if ( !banks ) + goto out; + + banks->max_banks = nr; + banks->type = type; + + out: + return banks; +} + +#endif /* XEN_BOOTINFO_H */ diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 0a22b1ba1d..7d1c8bc305 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -10,7 +10,7 @@ #ifndef __XEN_DEVICE_TREE_H__ #define __XEN_DEVICE_TREE_H__ -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/byteorder.h> #include <asm/device.h> diff --git a/xen/include/xen/fdt-domain-build.h b/xen/include/xen/fdt-domain-build.h index 45981dbec0..60565fdbf9 100644 --- a/xen/include/xen/fdt-domain-build.h +++ b/xen/include/xen/fdt-domain-build.h @@ -3,7 +3,7 @@ #ifndef __XEN_FDT_DOMAIN_BUILD_H__ #define __XEN_FDT_DOMAIN_BUILD_H__ -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/device_tree.h> #include <xen/fdt-kernel.h> #include <xen/mm.h> diff --git a/xen/include/xen/fdt-kernel.h b/xen/include/xen/fdt-kernel.h index 2f0ee42ebc..cb7ddc9807 100644 --- a/xen/include/xen/fdt-kernel.h +++ b/xen/include/xen/fdt-kernel.h @@ -7,7 +7,7 @@ #ifndef __XEN_FDT_KERNEL_H__ #define __XEN_FDT_KERNEL_H__ -#include <xen/bootfdt.h> +#include <xen/bootinfo.h> #include <xen/device_tree.h> #include <xen/types.h> -- 2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |