187ecb68bSpbrook /* 287ecb68bSpbrook * Misc ARM declarations 387ecb68bSpbrook * 487ecb68bSpbrook * Copyright (c) 2006 CodeSourcery. 587ecb68bSpbrook * Written by Paul Brook 687ecb68bSpbrook * 78e31bf38SMatthew Fernandez * This code is licensed under the LGPL. 887ecb68bSpbrook * 987ecb68bSpbrook */ 1087ecb68bSpbrook 11121d0712SMarkus Armbruster #ifndef HW_ARM_H 12121d0712SMarkus Armbruster #define HW_ARM_H 1387ecb68bSpbrook 14022c62cbSPaolo Bonzini #include "exec/memory.h" 15fcf5ef2aSThomas Huth #include "target/arm/cpu-qom.h" 165202ef94SIgor Mammedov #include "hw/irq.h" 17ac9d32e3SEric Auger #include "qemu/notify.h" 187d6f78cfSAvi Kivity 199776f636SPeter Crosthwaite typedef enum { 209776f636SPeter Crosthwaite ARM_ENDIANNESS_UNKNOWN = 0, 219776f636SPeter Crosthwaite ARM_ENDIANNESS_LE, 229776f636SPeter Crosthwaite ARM_ENDIANNESS_BE8, 239776f636SPeter Crosthwaite ARM_ENDIANNESS_BE32, 249776f636SPeter Crosthwaite } arm_endianness; 259776f636SPeter Crosthwaite 2687ecb68bSpbrook /* armv7m.c */ 2720c59c38SMichael Davidsaver DeviceState *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq, 288602beb7SIgor Mammedov const char *kernel_filename, const char *cpu_type); 293651c285SPeter Maydell /** 303651c285SPeter Maydell * armv7m_load_kernel: 313651c285SPeter Maydell * @cpu: CPU 323651c285SPeter Maydell * @kernel_filename: file to load 333651c285SPeter Maydell * @mem_size: mem_size: maximum image size to load 343651c285SPeter Maydell * 353651c285SPeter Maydell * Load the guest image for an ARMv7M system. This must be called by 363651c285SPeter Maydell * any ARMv7M board, either directly or via armv7m_init(). (This is 373651c285SPeter Maydell * necessary to ensure that the CPU resets correctly on system reset, 383651c285SPeter Maydell * as well as for kernel loading.) 393651c285SPeter Maydell */ 403651c285SPeter Maydell void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size); 4187ecb68bSpbrook 4287ecb68bSpbrook /* arm_boot.c */ 43f93eb9ffSbalrog struct arm_boot_info { 44de841deaSPeter Maydell uint64_t ram_size; 45f93eb9ffSbalrog const char *kernel_filename; 46f93eb9ffSbalrog const char *kernel_cmdline; 47f93eb9ffSbalrog const char *initrd_filename; 48412beee6SGrant Likely const char *dtb_filename; 49a8170e5eSAvi Kivity hwaddr loader_start; 50*3b77f6c3SIgor Mammedov hwaddr dtb_start; 51*3b77f6c3SIgor Mammedov hwaddr dtb_limit; 52*3b77f6c3SIgor Mammedov /* If set to True, arm_load_kernel() will not load DTB. 53*3b77f6c3SIgor Mammedov * It allows board to load DTB manually later. 54*3b77f6c3SIgor Mammedov * (default: False) 55*3b77f6c3SIgor Mammedov */ 56*3b77f6c3SIgor Mammedov bool skip_dtb_autoload; 579d5ba9bfSMark Langsdorf /* multicore boards that use the default secondary core boot functions 589d5ba9bfSMark Langsdorf * need to put the address of the secondary boot code, the boot reg, 599d5ba9bfSMark Langsdorf * and the GIC address in the next 3 values, respectively. boards that 609d5ba9bfSMark Langsdorf * have their own boot functions can use these values as they want. 619d5ba9bfSMark Langsdorf */ 62a8170e5eSAvi Kivity hwaddr smp_loader_start; 63a8170e5eSAvi Kivity hwaddr smp_bootreg_addr; 64a8170e5eSAvi Kivity hwaddr gic_cpu_if_addr; 65f93eb9ffSbalrog int nb_cpus; 66f93eb9ffSbalrog int board_id; 67c8e829b7SGreg Bellows /* ARM machines that support the ARM Security Extensions use this field to 68c8e829b7SGreg Bellows * control whether Linux is booted as secure(true) or non-secure(false). 69c8e829b7SGreg Bellows */ 70c8e829b7SGreg Bellows bool secure_boot; 71462a8bc6SStefan Weil int (*atag_board)(const struct arm_boot_info *info, void *p); 729d5ba9bfSMark Langsdorf /* multicore boards that use the default secondary core boot functions 739d5ba9bfSMark Langsdorf * can ignore these two function calls. If the default functions won't 749d5ba9bfSMark Langsdorf * work, then write_secondary_boot() should write a suitable blob of 759b574c29SAndreas Färber * code mimicking the secondary CPU startup process used by the board's 769d5ba9bfSMark Langsdorf * boot loader/boot ROM code, and secondary_cpu_reset_hook() should 779b574c29SAndreas Färber * perform any necessary CPU reset handling and set the PC for the 789d5ba9bfSMark Langsdorf * secondary CPUs to point at this boot blob. 799d5ba9bfSMark Langsdorf */ 809543b0cdSAndreas Färber void (*write_secondary_boot)(ARMCPU *cpu, 819d5ba9bfSMark Langsdorf const struct arm_boot_info *info); 825d309320SAndreas Färber void (*secondary_cpu_reset_hook)(ARMCPU *cpu, 839d5ba9bfSMark Langsdorf const struct arm_boot_info *info); 840fb79851SJohn Rigby /* if a board is able to create a dtb without a dtb file then it 850fb79851SJohn Rigby * sets get_dtb. This will only be used if no dtb file is provided 860fb79851SJohn Rigby * by the user. On success, sets *size to the length of the created 870fb79851SJohn Rigby * dtb, and returns a pointer to it. (The caller must free this memory 880fb79851SJohn Rigby * with g_free() when it has finished with it.) On failure, returns NULL. 890fb79851SJohn Rigby */ 900fb79851SJohn Rigby void *(*get_dtb)(const struct arm_boot_info *info, int *size); 913b1cceb8SPeter Maydell /* if a board needs to be able to modify a device tree provided by 923b1cceb8SPeter Maydell * the user it should implement this hook. 933b1cceb8SPeter Maydell */ 943b1cceb8SPeter Maydell void (*modify_dtb)(const struct arm_boot_info *info, void *fdt); 95f2d74978SPaul Brook /* Used internally by arm_boot.c */ 96f2d74978SPaul Brook int is_linux; 97fc53b7d4SPeter Maydell hwaddr initrd_start; 98a8170e5eSAvi Kivity hwaddr initrd_size; 99a8170e5eSAvi Kivity hwaddr entry; 10007abe45cSLaszlo Ersek 10107abe45cSLaszlo Ersek /* Boot firmware has been loaded, typically at address 0, with -bios or 10207abe45cSLaszlo Ersek * -pflash. It also implies that fw_cfg_find() will succeed. 10307abe45cSLaszlo Ersek */ 10407abe45cSLaszlo Ersek bool firmware_loaded; 10510b8ec73SPeter Crosthwaite 10610b8ec73SPeter Crosthwaite /* Address at which board specific loader/setup code exists. If enabled, 10710b8ec73SPeter Crosthwaite * this code-blob will run before anything else. It must return to the 10810b8ec73SPeter Crosthwaite * caller via the link register. There is no stack set up. Enabled by 10910b8ec73SPeter Crosthwaite * defining write_board_setup, which is responsible for loading the blob 11010b8ec73SPeter Crosthwaite * to the specified address. 11110b8ec73SPeter Crosthwaite */ 11210b8ec73SPeter Crosthwaite hwaddr board_setup_addr; 11310b8ec73SPeter Crosthwaite void (*write_board_setup)(ARMCPU *cpu, 11410b8ec73SPeter Crosthwaite const struct arm_boot_info *info); 115baf6b681SPeter Crosthwaite 116baf6b681SPeter Crosthwaite /* If set, the board specific loader/setup blob will be run from secure 117baf6b681SPeter Crosthwaite * mode, regardless of secure_boot. The blob becomes responsible for 118baf6b681SPeter Crosthwaite * changing to non-secure state if implementing a non-secure boot 119baf6b681SPeter Crosthwaite */ 120baf6b681SPeter Crosthwaite bool secure_board_setup; 1219776f636SPeter Crosthwaite 1229776f636SPeter Crosthwaite arm_endianness endianness; 123f93eb9ffSbalrog }; 124ac9d32e3SEric Auger 125ac9d32e3SEric Auger /** 126ac9d32e3SEric Auger * arm_load_kernel - Loads memory with everything needed to boot 127ac9d32e3SEric Auger * 128ac9d32e3SEric Auger * @cpu: handle to the first CPU object 129ac9d32e3SEric Auger * @info: handle to the boot info struct 130ac9d32e3SEric Auger * Registers a machine init done notifier that copies to memory 131ac9d32e3SEric Auger * everything needed to boot, depending on machine and user options: 132ac9d32e3SEric Auger * kernel image, boot loaders, initrd, dtb. Also registers the CPU 133ac9d32e3SEric Auger * reset handler. 134ac9d32e3SEric Auger * 135ac9d32e3SEric Auger * In case the machine file supports the platform bus device and its 136ac9d32e3SEric Auger * dynamically instantiable sysbus devices, this function must be called 137ac9d32e3SEric Auger * before sysbus-fdt arm_register_platform_bus_fdt_creator. Indeed the 138ac9d32e3SEric Auger * machine init done notifiers are called in registration reverse order. 139ac9d32e3SEric Auger */ 1403aaa8dfaSAndreas Färber void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info); 14187ecb68bSpbrook 142*3b77f6c3SIgor Mammedov AddressSpace *arm_boot_address_space(ARMCPU *cpu, 143*3b77f6c3SIgor Mammedov const struct arm_boot_info *info); 144*3b77f6c3SIgor Mammedov 145*3b77f6c3SIgor Mammedov /** 146*3b77f6c3SIgor Mammedov * arm_load_dtb() - load a device tree binary image into memory 147*3b77f6c3SIgor Mammedov * @addr: the address to load the image at 148*3b77f6c3SIgor Mammedov * @binfo: struct describing the boot environment 149*3b77f6c3SIgor Mammedov * @addr_limit: upper limit of the available memory area at @addr 150*3b77f6c3SIgor Mammedov * @as: address space to load image to 151*3b77f6c3SIgor Mammedov * 152*3b77f6c3SIgor Mammedov * Load a device tree supplied by the machine or by the user with the 153*3b77f6c3SIgor Mammedov * '-dtb' command line option, and put it at offset @addr in target 154*3b77f6c3SIgor Mammedov * memory. 155*3b77f6c3SIgor Mammedov * 156*3b77f6c3SIgor Mammedov * If @addr_limit contains a meaningful value (i.e., it is strictly greater 157*3b77f6c3SIgor Mammedov * than @addr), the device tree is only loaded if its size does not exceed 158*3b77f6c3SIgor Mammedov * the limit. 159*3b77f6c3SIgor Mammedov * 160*3b77f6c3SIgor Mammedov * Returns: the size of the device tree image on success, 161*3b77f6c3SIgor Mammedov * 0 if the image size exceeds the limit, 162*3b77f6c3SIgor Mammedov * -1 on errors. 163*3b77f6c3SIgor Mammedov * 164*3b77f6c3SIgor Mammedov * Note: Must not be called unless have_dtb(binfo) is true. 165*3b77f6c3SIgor Mammedov */ 166*3b77f6c3SIgor Mammedov int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, 167*3b77f6c3SIgor Mammedov hwaddr addr_limit, AddressSpace *as); 168*3b77f6c3SIgor Mammedov 169716536a9SAndrew Baumann /* Write a secure board setup routine with a dummy handler for SMCs */ 170716536a9SAndrew Baumann void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, 171716536a9SAndrew Baumann const struct arm_boot_info *info, 172716536a9SAndrew Baumann hwaddr mvbar_addr); 173716536a9SAndrew Baumann 17479383c9cSblueswir1 /* Multiplication factor to convert from system clock ticks to qemu timer 17579383c9cSblueswir1 ticks. */ 1767ee930d0Sblueswir1 extern int system_clock_scale; 17787ecb68bSpbrook 178121d0712SMarkus Armbruster #endif /* HW_ARM_H */ 179