xref: /openbmc/qemu/include/hw/arm/boot.h (revision 6c3a9247)
1 /*
2  * ARM kernel loader.
3  *
4  * Copyright (c) 2006 CodeSourcery.
5  * Written by Paul Brook
6  *
7  * This code is licensed under the LGPL.
8  *
9  */
10 
11 #ifndef HW_ARM_BOOT_H
12 #define HW_ARM_BOOT_H
13 
14 #include "target/arm/cpu-qom.h"
15 #include "qemu/notify.h"
16 
17 typedef enum {
18     ARM_ENDIANNESS_UNKNOWN = 0,
19     ARM_ENDIANNESS_LE,
20     ARM_ENDIANNESS_BE8,
21     ARM_ENDIANNESS_BE32,
22 } arm_endianness;
23 
24 /**
25  * armv7m_load_kernel:
26  * @cpu: CPU
27  * @kernel_filename: file to load
28  * @mem_size: mem_size: maximum image size to load
29  *
30  * Load the guest image for an ARMv7M system. This must be called by
31  * any ARMv7M board. (This is necessary to ensure that the CPU resets
32  * correctly on system reset, as well as for kernel loading.)
33  */
34 void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size);
35 
36 /* arm_boot.c */
37 struct arm_boot_info {
38     uint64_t ram_size;
39     const char *kernel_filename;
40     const char *kernel_cmdline;
41     const char *initrd_filename;
42     const char *dtb_filename;
43     hwaddr loader_start;
44     hwaddr dtb_start;
45     hwaddr dtb_limit;
46     /* If set to True, arm_load_kernel() will not load DTB.
47      * It allows board to load DTB manually later.
48      * (default: False)
49      */
50     bool skip_dtb_autoload;
51     /* multicore boards that use the default secondary core boot functions
52      * need to put the address of the secondary boot code, the boot reg,
53      * and the GIC address in the next 3 values, respectively. boards that
54      * have their own boot functions can use these values as they want.
55      */
56     hwaddr smp_loader_start;
57     hwaddr smp_bootreg_addr;
58     hwaddr gic_cpu_if_addr;
59     int board_id;
60     /* ARM machines that support the ARM Security Extensions use this field to
61      * control whether Linux is booted as secure(true) or non-secure(false).
62      */
63     bool secure_boot;
64     int (*atag_board)(const struct arm_boot_info *info, void *p);
65     /* multicore boards that use the default secondary core boot functions
66      * can ignore these two function calls. If the default functions won't
67      * work, then write_secondary_boot() should write a suitable blob of
68      * code mimicking the secondary CPU startup process used by the board's
69      * boot loader/boot ROM code, and secondary_cpu_reset_hook() should
70      * perform any necessary CPU reset handling and set the PC for the
71      * secondary CPUs to point at this boot blob.
72      *
73      * These hooks won't be called if secondary CPUs are booting via
74      * emulated PSCI (see psci_conduit below).
75      */
76     void (*write_secondary_boot)(ARMCPU *cpu,
77                                  const struct arm_boot_info *info);
78     void (*secondary_cpu_reset_hook)(ARMCPU *cpu,
79                                      const struct arm_boot_info *info);
80     /* if a board is able to create a dtb without a dtb file then it
81      * sets get_dtb. This will only be used if no dtb file is provided
82      * by the user. On success, sets *size to the length of the created
83      * dtb, and returns a pointer to it. (The caller must free this memory
84      * with g_free() when it has finished with it.) On failure, returns NULL.
85      */
86     void *(*get_dtb)(const struct arm_boot_info *info, int *size);
87     /* if a board needs to be able to modify a device tree provided by
88      * the user it should implement this hook.
89      */
90     void (*modify_dtb)(const struct arm_boot_info *info, void *fdt);
91     /*
92      * If a board wants to use the QEMU emulated-firmware PSCI support,
93      * it should set this to QEMU_PSCI_CONDUIT_HVC or QEMU_PSCI_CONDUIT_SMC
94      * as appropriate. arm_load_kernel() will set the psci-conduit and
95      * start-powered-off properties on the CPUs accordingly.
96      * Note that if the guest image is started at the same exception level
97      * as the conduit specifies calls should go to (eg guest firmware booted
98      * to EL3) then PSCI will not be enabled.
99      */
100     int psci_conduit;
101     /* Used internally by arm_boot.c */
102     int is_linux;
103     hwaddr initrd_start;
104     hwaddr initrd_size;
105     hwaddr entry;
106 
107     /* Boot firmware has been loaded, typically at address 0, with -bios or
108      * -pflash. It also implies that fw_cfg_find() will succeed.
109      */
110     bool firmware_loaded;
111 
112     /* Address at which board specific loader/setup code exists. If enabled,
113      * this code-blob will run before anything else. It must return to the
114      * caller via the link register. There is no stack set up. Enabled by
115      * defining write_board_setup, which is responsible for loading the blob
116      * to the specified address.
117      */
118     hwaddr board_setup_addr;
119     void (*write_board_setup)(ARMCPU *cpu,
120                               const struct arm_boot_info *info);
121 
122     /*
123      * If set, the board specific loader/setup blob will be run from secure
124      * mode, regardless of secure_boot. The blob becomes responsible for
125      * changing to non-secure state if implementing a non-secure boot,
126      * including setting up EL3/Secure registers such as the NSACR as
127      * required by the Linux booting ABI before the switch to non-secure.
128      */
129     bool secure_board_setup;
130 
131     arm_endianness endianness;
132 };
133 
134 /**
135  * arm_load_kernel - Loads memory with everything needed to boot
136  *
137  * @cpu: handle to the first CPU object
138  * @info: handle to the boot info struct
139  * Registers a machine init done notifier that copies to memory
140  * everything needed to boot, depending on machine and user options:
141  * kernel image, boot loaders, initrd, dtb. Also registers the CPU
142  * reset handler.
143  *
144  * In case the machine file supports the platform bus device and its
145  * dynamically instantiable sysbus devices, this function must be called
146  * before sysbus-fdt arm_register_platform_bus_fdt_creator. Indeed the
147  * machine init done notifiers are called in registration reverse order.
148  */
149 void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info);
150 
151 AddressSpace *arm_boot_address_space(ARMCPU *cpu,
152                                      const struct arm_boot_info *info);
153 
154 /**
155  * arm_load_dtb() - load a device tree binary image into memory
156  * @addr:       the address to load the image at
157  * @binfo:      struct describing the boot environment
158  * @addr_limit: upper limit of the available memory area at @addr
159  * @as:         address space to load image to
160  *
161  * Load a device tree supplied by the machine or by the user  with the
162  * '-dtb' command line option, and put it at offset @addr in target
163  * memory.
164  *
165  * If @addr_limit contains a meaningful value (i.e., it is strictly greater
166  * than @addr), the device tree is only loaded if its size does not exceed
167  * the limit.
168  *
169  * Returns: the size of the device tree image on success,
170  *          0 if the image size exceeds the limit,
171  *          -1 on errors.
172  *
173  * Note: Must not be called unless have_dtb(binfo) is true.
174  */
175 int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
176                  hwaddr addr_limit, AddressSpace *as, MachineState *ms);
177 
178 /* Write a secure board setup routine with a dummy handler for SMCs */
179 void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
180                                             const struct arm_boot_info *info,
181                                             hwaddr mvbar_addr);
182 
183 #endif /* HW_ARM_BOOT_H */
184