1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2024 Christopher Clark <christopher.w.clark@gmail.com>
4  * Copyright (c) 2024 Apertus Solutions, LLC
5  * Author: Daniel P. Smith <dpsmith@apertussolutions.com>
6  */
7 
8 #ifndef X86_BOOTINFO_H
9 #define X86_BOOTINFO_H
10 
11 #include <xen/bootfdt.h>
12 #include <xen/init.h>
13 #include <xen/multiboot.h>
14 #include <xen/types.h>
15 
16 /* Max number of boot modules a bootloader can provide in addition to Xen */
17 #define MAX_NR_BOOTMODS 63
18 
19 /* Max number of boot domains that Xen can construct */
20 #define MAX_NR_BOOTDOMS 1
21 
22 /*
23  * Xen internal representation of information provided by the
24  * bootloader/environment, or derived from the information.
25  */
26 struct boot_info {
27     const char *loader;
28     const char *cmdline;
29     const char *kextra;
30 
31     paddr_t memmap_addr;
32     size_t memmap_length;
33 
34     unsigned int nr_modules;
35     struct boot_module mods[MAX_NR_BOOTMODS + 1];
36     struct boot_domain domains[MAX_NR_BOOTDOMS];
37 };
38 
39 /*
40  * next_boot_module_index:
41  *     Finds the next boot module of type t, starting at array index start.
42  *
43  * Returns:
44  *      Success - index in boot_module array
45  *      Failure - a value greater than MAX_NR_BOOTMODS
46  */
next_boot_module_index(const struct boot_info * bi,boot_module_kind k,unsigned int start)47 static inline unsigned int __init next_boot_module_index(
48     const struct boot_info *bi, boot_module_kind k, unsigned int start)
49 {
50     unsigned int i;
51 
52     if ( k == BOOTMOD_XEN )
53         return bi->nr_modules;
54 
55     for ( i = start; i < bi->nr_modules; i++ )
56     {
57         if ( bi->mods[i].kind == k )
58             return i;
59     }
60 
61     return MAX_NR_BOOTMODS + 1;
62 }
63 
64 /*
65  * first_boot_module_index:
66  *     Finds the first boot module of type t.
67  *
68  * Returns:
69  *      Success - index in boot_module array
70  *      Failure - a value greater than MAX_NR_BOOTMODS
71  */
72 #define first_boot_module_index(bi, t)          \
73     next_boot_module_index(bi, t, 0)
74 
75 #define for_each_boot_module_by_type(i, b, t)           \
76     for ( (i) = first_boot_module_index(b, t);          \
77           (i) <= (b)->nr_modules;                       \
78           (i) = next_boot_module_index(b, t, i + 1) )
79 
80 #endif /* X86_BOOTINFO_H */
81 
82 /*
83  * Local variables:
84  * mode: C
85  * c-file-style: "BSD"
86  * c-basic-offset: 4
87  * tab-width: 4
88  * indent-tabs-mode: nil
89  * End:
90  */
91