10d09e41aSPaolo Bonzini #ifndef LOADER_H 20d09e41aSPaolo Bonzini #define LOADER_H 3a88b362cSLaszlo Ersek #include "hw/nvram/fw_cfg.h" 40d09e41aSPaolo Bonzini 50d09e41aSPaolo Bonzini /* loader.c */ 6a1483f88SMichael S. Tsirkin /** 7a1483f88SMichael S. Tsirkin * get_image_size: retrieve size of an image file 8a1483f88SMichael S. Tsirkin * @filename: Path to the image file 9a1483f88SMichael S. Tsirkin * 10a1483f88SMichael S. Tsirkin * Returns the size of the image file on success, -1 otherwise. 11a1483f88SMichael S. Tsirkin * On error, errno is also set as appropriate. 12a1483f88SMichael S. Tsirkin */ 13f3839fdaSLi Zhijian int64_t get_image_size(const char *filename); 1406192329SPeter Maydell /** 1506192329SPeter Maydell * load_image_size: load an image file into specified buffer 1606192329SPeter Maydell * @filename: Path to the image file 1706192329SPeter Maydell * @addr: Buffer to load image into 1806192329SPeter Maydell * @size: Size of buffer in bytes 1906192329SPeter Maydell * 2006192329SPeter Maydell * Load an image file from disk into the specified buffer. 2106192329SPeter Maydell * If the image is larger than the specified buffer, only 2206192329SPeter Maydell * @size bytes are read (this is not considered an error). 2306192329SPeter Maydell * 2406192329SPeter Maydell * Prefer to use the GLib function g_file_get_contents() rather 2506192329SPeter Maydell * than a "get_image_size()/g_malloc()/load_image_size()" sequence. 2606192329SPeter Maydell * 2706192329SPeter Maydell * Returns the number of bytes read, or -1 on error. On error, 2806192329SPeter Maydell * errno is also set as appropriate. 2906192329SPeter Maydell */ 30ea87616dSBenjamin Herrenschmidt ssize_t load_image_size(const char *filename, void *addr, size_t size); 3193ffc7c7SAlistair Francis 3293ffc7c7SAlistair Francis /**load_image_targphys_as: 3393ffc7c7SAlistair Francis * @filename: Path to the image file 3493ffc7c7SAlistair Francis * @addr: Address to load the image to 3593ffc7c7SAlistair Francis * @max_sz: The maximum size of the image to load 3693ffc7c7SAlistair Francis * @as: The AddressSpace to load the ELF to. The value of address_space_memory 3793ffc7c7SAlistair Francis * is used if nothing is supplied here. 3893ffc7c7SAlistair Francis * 3993ffc7c7SAlistair Francis * Load a fixed image into memory. 4093ffc7c7SAlistair Francis * 4193ffc7c7SAlistair Francis * Returns the size of the loaded image on success, -1 otherwise. 4293ffc7c7SAlistair Francis */ 43af975131SJamie Iles ssize_t load_image_targphys_as(const char *filename, 4493ffc7c7SAlistair Francis hwaddr addr, uint64_t max_sz, AddressSpace *as); 4593ffc7c7SAlistair Francis 46e4a25ed9SSu Hang /**load_targphys_hex_as: 47e4a25ed9SSu Hang * @filename: Path to the .hex file 48e4a25ed9SSu Hang * @entry: Store the entry point given by the .hex file 49e4a25ed9SSu Hang * @as: The AddressSpace to load the .hex file to. The value of 50e4a25ed9SSu Hang * address_space_memory is used if nothing is supplied here. 51e4a25ed9SSu Hang * 52e4a25ed9SSu Hang * Load a fixed .hex file into memory. 53e4a25ed9SSu Hang * 54e4a25ed9SSu Hang * Returns the size of the loaded .hex file on success, -1 otherwise. 55e4a25ed9SSu Hang */ 56af975131SJamie Iles ssize_t load_targphys_hex_as(const char *filename, hwaddr *entry, 57af975131SJamie Iles AddressSpace *as); 58e4a25ed9SSu Hang 5993ffc7c7SAlistair Francis /** load_image_targphys: 6093ffc7c7SAlistair Francis * Same as load_image_targphys_as(), but doesn't allow the caller to specify 6193ffc7c7SAlistair Francis * an AddressSpace. 6293ffc7c7SAlistair Francis */ 63af975131SJamie Iles ssize_t load_image_targphys(const char *filename, hwaddr, 640d09e41aSPaolo Bonzini uint64_t max_sz); 6593ffc7c7SAlistair Francis 6676151cacSPeter Maydell /** 6776151cacSPeter Maydell * load_image_mr: load an image into a memory region 6876151cacSPeter Maydell * @filename: Path to the image file 6976151cacSPeter Maydell * @mr: Memory Region to load into 7076151cacSPeter Maydell * 7176151cacSPeter Maydell * Load the specified file into the memory region. 7276151cacSPeter Maydell * The file loaded is registered as a ROM, so its contents will be 7376151cacSPeter Maydell * reinstated whenever the system is reset. 7476151cacSPeter Maydell * If the file is larger than the memory region's size the call will fail. 7576151cacSPeter Maydell * Returns -1 on failure, or the size of the file. 7676151cacSPeter Maydell */ 77af975131SJamie Iles ssize_t load_image_mr(const char *filename, MemoryRegion *mr); 787d48a0f7SLaszlo Ersek 797d48a0f7SLaszlo Ersek /* This is the limit on the maximum uncompressed image size that 80*a376a8d5SAni Sinha * load_image_gzipped_buffer() will read. It prevents 817d48a0f7SLaszlo Ersek * g_malloc() in those functions from allocating a huge amount of memory. 827d48a0f7SLaszlo Ersek */ 837d48a0f7SLaszlo Ersek #define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20) 847d48a0f7SLaszlo Ersek 85af975131SJamie Iles ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz, 867d48a0f7SLaszlo Ersek uint8_t **buffer); 87ff114228SArd Biesheuvel /** 88ff114228SArd Biesheuvel * unpack_efi_zboot_image: 89ff114228SArd Biesheuvel * @buffer: pointer to a variable holding the address of a buffer containing the 90ff114228SArd Biesheuvel * image 91ff114228SArd Biesheuvel * @size: pointer to a variable holding the size of the buffer 92ff114228SArd Biesheuvel * 93ff114228SArd Biesheuvel * Check whether the buffer contains a EFI zboot image, and if it does, extract 94ff114228SArd Biesheuvel * the compressed payload and decompress it into a new buffer. If successful, 95ff114228SArd Biesheuvel * the old buffer is freed, and the *buffer and size variables pointed to by the 96ff114228SArd Biesheuvel * function arguments are updated to refer to the newly populated buffer. 97ff114228SArd Biesheuvel * 98ff114228SArd Biesheuvel * Returns 0 if the image could not be identified as a EFI zboot image. 99ff114228SArd Biesheuvel * Returns -1 if the buffer contents were identified as a EFI zboot image, but 100ff114228SArd Biesheuvel * unpacking failed for any reason. 101ff114228SArd Biesheuvel * Returns the size of the decompressed payload if decompression was performed 102ff114228SArd Biesheuvel * successfully. 103ff114228SArd Biesheuvel */ 104ff114228SArd Biesheuvel ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size); 105ff114228SArd Biesheuvel 10618674b26SAlexey Kardashevskiy #define ELF_LOAD_FAILED -1 10718674b26SAlexey Kardashevskiy #define ELF_LOAD_NOT_ELF -2 10818674b26SAlexey Kardashevskiy #define ELF_LOAD_WRONG_ARCH -3 10918674b26SAlexey Kardashevskiy #define ELF_LOAD_WRONG_ENDIAN -4 11041a26351SStefano Garzarella #define ELF_LOAD_TOO_BIG -5 1118975eb89SLuc Michel const char *load_elf_strerror(ssize_t error); 112140b7ce5SPeter Crosthwaite 113a2480ffaSMichael Clark /** load_elf_ram_sym: 114140b7ce5SPeter Crosthwaite * @filename: Path of ELF file 1154366e1dbSLiam Merwick * @elf_note_fn: optional function to parse ELF Note type 1164366e1dbSLiam Merwick * passed via @translate_opaque 117140b7ce5SPeter Crosthwaite * @translate_fn: optional function to translate load addresses 118140b7ce5SPeter Crosthwaite * @translate_opaque: opaque data passed to @translate_fn 119140b7ce5SPeter Crosthwaite * @pentry: Populated with program entry point. Ignored if NULL. 120140b7ce5SPeter Crosthwaite * @lowaddr: Populated with lowest loaded address. Ignored if NULL. 121140b7ce5SPeter Crosthwaite * @highaddr: Populated with highest loaded address. Ignored if NULL. 1226cdda0ffSAleksandar Markovic * @pflags: Populated with ELF processor-specific flags. Ignore if NULL. 123140b7ce5SPeter Crosthwaite * @bigendian: Expected ELF endianness. 0 for LE otherwise BE 124140b7ce5SPeter Crosthwaite * @elf_machine: Expected ELF machine type 125140b7ce5SPeter Crosthwaite * @clear_lsb: Set to mask off LSB of addresses (Some architectures use 126140b7ce5SPeter Crosthwaite * this for non-address data) 1277ef295eaSPeter Crosthwaite * @data_swab: Set to order of byte swapping for data. 0 for no swap, 1 1287ef295eaSPeter Crosthwaite * for swapping bytes within halfwords, 2 for bytes within 1297ef295eaSPeter Crosthwaite * words and 3 for within doublewords. 13070bb1d16SAlistair Francis * @as: The AddressSpace to load the ELF to. The value of address_space_memory 13170bb1d16SAlistair Francis * is used if nothing is supplied here. 13234f1b23fSFarhan Ali * @load_rom : Load ELF binary as ROM 133a2480ffaSMichael Clark * @sym_cb: Callback function for symbol table entries 134140b7ce5SPeter Crosthwaite * 135140b7ce5SPeter Crosthwaite * Load an ELF file's contents to the emulated system's address space. 136140b7ce5SPeter Crosthwaite * Clients may optionally specify a callback to perform address 137140b7ce5SPeter Crosthwaite * translations. @pentry, @lowaddr and @highaddr are optional pointers 138140b7ce5SPeter Crosthwaite * which will be populated with various load information. @bigendian and 139140b7ce5SPeter Crosthwaite * @elf_machine give the expected endianness and machine for the ELF the 140140b7ce5SPeter Crosthwaite * load will fail if the target ELF does not match. Some architectures 141140b7ce5SPeter Crosthwaite * have some architecture-specific behaviours that come into effect when 142140b7ce5SPeter Crosthwaite * their particular values for @elf_machine are set. 1438cf6e9daSAlistair Francis * If @elf_machine is EM_NONE then the machine type will be read from the 1448cf6e9daSAlistair Francis * ELF header and no checks will be carried out against the machine type. 145140b7ce5SPeter Crosthwaite */ 146a2480ffaSMichael Clark typedef void (*symbol_fn_t)(const char *st_name, int st_info, 147a2480ffaSMichael Clark uint64_t st_value, uint64_t st_size); 148a2480ffaSMichael Clark 1498975eb89SLuc Michel ssize_t load_elf_ram_sym(const char *filename, 1504366e1dbSLiam Merwick uint64_t (*elf_note_fn)(void *, void *, bool), 151a2480ffaSMichael Clark uint64_t (*translate_fn)(void *, uint64_t), 152a2480ffaSMichael Clark void *translate_opaque, uint64_t *pentry, 1538975eb89SLuc Michel uint64_t *lowaddr, uint64_t *highaddr, 1548975eb89SLuc Michel uint32_t *pflags, int big_endian, int elf_machine, 1556cdda0ffSAleksandar Markovic int clear_lsb, int data_swab, 156a2480ffaSMichael Clark AddressSpace *as, bool load_rom, symbol_fn_t sym_cb); 157a2480ffaSMichael Clark 158a2480ffaSMichael Clark /** load_elf_ram: 159a2480ffaSMichael Clark * Same as load_elf_ram_sym(), but doesn't allow the caller to specify a 160a2480ffaSMichael Clark * symbol callback function 161a2480ffaSMichael Clark */ 1628975eb89SLuc Michel ssize_t load_elf_ram(const char *filename, 1634366e1dbSLiam Merwick uint64_t (*elf_note_fn)(void *, void *, bool), 16434f1b23fSFarhan Ali uint64_t (*translate_fn)(void *, uint64_t), 1658975eb89SLuc Michel void *translate_opaque, uint64_t *pentry, 1668975eb89SLuc Michel uint64_t *lowaddr, uint64_t *highaddr, uint32_t *pflags, 1678975eb89SLuc Michel int big_endian, int elf_machine, int clear_lsb, 1688975eb89SLuc Michel int data_swab, AddressSpace *as, bool load_rom); 16934f1b23fSFarhan Ali 17034f1b23fSFarhan Ali /** load_elf_as: 17134f1b23fSFarhan Ali * Same as load_elf_ram(), but always loads the elf as ROM 17234f1b23fSFarhan Ali */ 1738975eb89SLuc Michel ssize_t load_elf_as(const char *filename, 1744366e1dbSLiam Merwick uint64_t (*elf_note_fn)(void *, void *, bool), 17570bb1d16SAlistair Francis uint64_t (*translate_fn)(void *, uint64_t), 17670bb1d16SAlistair Francis void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, 1776cdda0ffSAleksandar Markovic uint64_t *highaddr, uint32_t *pflags, int big_endian, 1786cdda0ffSAleksandar Markovic int elf_machine, int clear_lsb, int data_swab, 1796cdda0ffSAleksandar Markovic AddressSpace *as); 180140b7ce5SPeter Crosthwaite 18170bb1d16SAlistair Francis /** load_elf: 18270bb1d16SAlistair Francis * Same as load_elf_as(), but doesn't allow the caller to specify an 18370bb1d16SAlistair Francis * AddressSpace. 18470bb1d16SAlistair Francis */ 1858975eb89SLuc Michel ssize_t load_elf(const char *filename, 1864366e1dbSLiam Merwick uint64_t (*elf_note_fn)(void *, void *, bool), 1874366e1dbSLiam Merwick uint64_t (*translate_fn)(void *, uint64_t), 1880d09e41aSPaolo Bonzini void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, 1896cdda0ffSAleksandar Markovic uint64_t *highaddr, uint32_t *pflags, int big_endian, 1906cdda0ffSAleksandar Markovic int elf_machine, int clear_lsb, int data_swab); 19104ae712aSPeter Crosthwaite 19204ae712aSPeter Crosthwaite /** load_elf_hdr: 19304ae712aSPeter Crosthwaite * @filename: Path of ELF file 19404ae712aSPeter Crosthwaite * @hdr: Buffer to populate with header data. Header data will not be 19504ae712aSPeter Crosthwaite * filled if set to NULL. 19604ae712aSPeter Crosthwaite * @is64: Set to true if the ELF is 64bit. Ignored if set to NULL 19704ae712aSPeter Crosthwaite * @errp: Populated with an error in failure cases 19804ae712aSPeter Crosthwaite * 19904ae712aSPeter Crosthwaite * Inspect an ELF file's header. Read its full header contents into a 20004ae712aSPeter Crosthwaite * buffer and/or determine if the ELF is 64bit. 20104ae712aSPeter Crosthwaite */ 20204ae712aSPeter Crosthwaite void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp); 20304ae712aSPeter Crosthwaite 204af975131SJamie Iles ssize_t load_aout(const char *filename, hwaddr addr, int max_sz, 2050d09e41aSPaolo Bonzini int bswap_needed, hwaddr target_page_size); 2065e774eb3SAlistair Francis 207f831f955SNick Hudson #define LOAD_UIMAGE_LOADADDR_INVALID (-1) 208f831f955SNick Hudson 2095e774eb3SAlistair Francis /** load_uimage_as: 2105e774eb3SAlistair Francis * @filename: Path of uimage file 2115e774eb3SAlistair Francis * @ep: Populated with program entry point. Ignored if NULL. 212f831f955SNick Hudson * @loadaddr: load address if none specified in the image or when loading a 213f831f955SNick Hudson * ramdisk. Populated with the load address. Ignored if NULL or 214f831f955SNick Hudson * LOAD_UIMAGE_LOADADDR_INVALID (images which do not specify a load 215f831f955SNick Hudson * address will not be loadable). 2165e774eb3SAlistair Francis * @is_linux: Is set to true if the image loaded is Linux. Ignored if NULL. 2175e774eb3SAlistair Francis * @translate_fn: optional function to translate load addresses 2185e774eb3SAlistair Francis * @translate_opaque: opaque data passed to @translate_fn 2195e774eb3SAlistair Francis * @as: The AddressSpace to load the ELF to. The value of address_space_memory 2205e774eb3SAlistair Francis * is used if nothing is supplied here. 2215e774eb3SAlistair Francis * 2225e774eb3SAlistair Francis * Loads a u-boot image into memory. 2235e774eb3SAlistair Francis * 2245e774eb3SAlistair Francis * Returns the size of the loaded image on success, -1 otherwise. 2255e774eb3SAlistair Francis */ 226af975131SJamie Iles ssize_t load_uimage_as(const char *filename, hwaddr *ep, 2275e774eb3SAlistair Francis hwaddr *loadaddr, int *is_linux, 2285e774eb3SAlistair Francis uint64_t (*translate_fn)(void *, uint64_t), 2295e774eb3SAlistair Francis void *translate_opaque, AddressSpace *as); 2305e774eb3SAlistair Francis 2315e774eb3SAlistair Francis /** load_uimage: 2325e774eb3SAlistair Francis * Same as load_uimage_as(), but doesn't allow the caller to specify an 2335e774eb3SAlistair Francis * AddressSpace. 2345e774eb3SAlistair Francis */ 235af975131SJamie Iles ssize_t load_uimage(const char *filename, hwaddr *ep, 23625bda50aSMax Filippov hwaddr *loadaddr, int *is_linux, 23725bda50aSMax Filippov uint64_t (*translate_fn)(void *, uint64_t), 23825bda50aSMax Filippov void *translate_opaque); 2390d09e41aSPaolo Bonzini 24084aee0deSSoren Brinkmann /** 24197df5feeSPeter Maydell * load_ramdisk_as: 24284aee0deSSoren Brinkmann * @filename: Path to the ramdisk image 24384aee0deSSoren Brinkmann * @addr: Memory address to load the ramdisk to 24484aee0deSSoren Brinkmann * @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks) 24597df5feeSPeter Maydell * @as: The AddressSpace to load the ELF to. The value of address_space_memory 24697df5feeSPeter Maydell * is used if nothing is supplied here. 24784aee0deSSoren Brinkmann * 24884aee0deSSoren Brinkmann * Load a ramdisk image with U-Boot header to the specified memory 24984aee0deSSoren Brinkmann * address. 25084aee0deSSoren Brinkmann * 25184aee0deSSoren Brinkmann * Returns the size of the loaded image on success, -1 otherwise. 25284aee0deSSoren Brinkmann */ 253af975131SJamie Iles ssize_t load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz, 25497df5feeSPeter Maydell AddressSpace *as); 25597df5feeSPeter Maydell 25697df5feeSPeter Maydell /** 25797df5feeSPeter Maydell * load_ramdisk: 25897df5feeSPeter Maydell * Same as load_ramdisk_as(), but doesn't allow the caller to specify 25997df5feeSPeter Maydell * an AddressSpace. 26097df5feeSPeter Maydell */ 261af975131SJamie Iles ssize_t load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz); 26284aee0deSSoren Brinkmann 26351b58561SPaul Burton ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen); 26451b58561SPaul Burton 2650d09e41aSPaolo Bonzini ssize_t read_targphys(const char *name, 2660d09e41aSPaolo Bonzini int fd, hwaddr dst_addr, size_t nbytes); 2670d09e41aSPaolo Bonzini void pstrcpy_targphys(const char *name, 2680d09e41aSPaolo Bonzini hwaddr dest, int buf_size, 2690d09e41aSPaolo Bonzini const char *source); 2700d09e41aSPaolo Bonzini 271af975131SJamie Iles ssize_t rom_add_file(const char *file, const char *fw_dir, 272ac41881bSMichael S. Tsirkin hwaddr addr, int32_t bootindex, 273e265ee43SPhilippe Mathieu-Daudé bool has_option_rom, MemoryRegion *mr, AddressSpace *as); 274339240b5SPaolo Bonzini MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len, 275339240b5SPaolo Bonzini size_t max_len, hwaddr addr, 276339240b5SPaolo Bonzini const char *fw_file_name, 2776f6f4aecSMarc-André Lureau FWCfgCallback fw_callback, 278baf2d5bfSMichael S. Tsirkin void *callback_opaque, AddressSpace *as, 279baf2d5bfSMichael S. Tsirkin bool read_only); 280fef28891SStefano Garzarella int rom_add_elf_program(const char *name, GMappedFile *mapped_file, void *data, 281fef28891SStefano Garzarella size_t datasize, size_t romsize, hwaddr addr, 282fef28891SStefano Garzarella AddressSpace *as); 2836b3f7f63SEric Auger int rom_check_and_register_reset(void); 284a88b362cSLaszlo Ersek void rom_set_fw(FWCfgState *f); 285bab47d9aSGerd Hoffmann void rom_set_order_override(int order); 286bab47d9aSGerd Hoffmann void rom_reset_order_override(void); 287e2336043SStefan Hajnoczi 288e2336043SStefan Hajnoczi /** 289e2336043SStefan Hajnoczi * rom_transaction_begin: 290e2336043SStefan Hajnoczi * 291e2336043SStefan Hajnoczi * Call this before of a series of rom_add_*() calls. Call 292e2336043SStefan Hajnoczi * rom_transaction_end() afterwards to commit or abort. These functions are 293e2336043SStefan Hajnoczi * useful for undoing a series of rom_add_*() calls if image file loading fails 294e2336043SStefan Hajnoczi * partway through. 295e2336043SStefan Hajnoczi */ 296e2336043SStefan Hajnoczi void rom_transaction_begin(void); 297e2336043SStefan Hajnoczi 298e2336043SStefan Hajnoczi /** 299e2336043SStefan Hajnoczi * rom_transaction_end: 300e2336043SStefan Hajnoczi * @commit: true to commit added roms, false to drop added roms 301e2336043SStefan Hajnoczi * 302e2336043SStefan Hajnoczi * Call this after a series of rom_add_*() calls. See rom_transaction_begin(). 303e2336043SStefan Hajnoczi */ 304e2336043SStefan Hajnoczi void rom_transaction_end(bool commit); 305e2336043SStefan Hajnoczi 3060d09e41aSPaolo Bonzini int rom_copy(uint8_t *dest, hwaddr addr, size_t size); 3070f0f8b61SThomas Huth void *rom_ptr(hwaddr addr, size_t size); 3081228c459SPeter Maydell /** 3091228c459SPeter Maydell * rom_ptr_for_as: Return a pointer to ROM blob data for the address 3101228c459SPeter Maydell * @as: AddressSpace to look for the ROM blob in 3111228c459SPeter Maydell * @addr: Address within @as 3121228c459SPeter Maydell * @size: size of data required in bytes 3131228c459SPeter Maydell * 3141228c459SPeter Maydell * Returns: pointer into the data which backs the matching ROM blob, 3151228c459SPeter Maydell * or NULL if no blob covers the address range. 3161228c459SPeter Maydell * 3171228c459SPeter Maydell * This function looks for a ROM blob which covers the specified range 3181228c459SPeter Maydell * of bytes of length @size starting at @addr within the address space 3191228c459SPeter Maydell * @as. This is useful for code which runs as part of board 3201228c459SPeter Maydell * initialization or CPU reset which wants to read data that is part 3211228c459SPeter Maydell * of a user-supplied guest image or other guest memory contents, but 3221228c459SPeter Maydell * which runs before the ROM loader's reset function has copied the 3231228c459SPeter Maydell * blobs into guest memory. 3241228c459SPeter Maydell * 3251228c459SPeter Maydell * rom_ptr_for_as() will look not just for blobs loaded directly to 3261228c459SPeter Maydell * the specified address, but also for blobs which were loaded to an 3271228c459SPeter Maydell * alias of the region at a different location in the AddressSpace. 3281228c459SPeter Maydell * In other words, if a machine model has RAM at address 0x0000_0000 3291228c459SPeter Maydell * which is aliased to also appear at 0x1000_0000, rom_ptr_for_as() 3301228c459SPeter Maydell * will return the correct data whether the guest image was linked and 3311228c459SPeter Maydell * loaded at 0x0000_0000 or 0x1000_0000. Contrast rom_ptr(), which 3321228c459SPeter Maydell * will only return data if the image load address is an exact match 3331228c459SPeter Maydell * with the queried address. 3341228c459SPeter Maydell * 3351228c459SPeter Maydell * New code should prefer to use rom_ptr_for_as() instead of 3361228c459SPeter Maydell * rom_ptr(). 3371228c459SPeter Maydell */ 3381228c459SPeter Maydell void *rom_ptr_for_as(AddressSpace *as, hwaddr addr, size_t size); 3390d09e41aSPaolo Bonzini 3400d09e41aSPaolo Bonzini #define rom_add_file_fixed(_f, _a, _i) \ 3413e76099aSAlistair Francis rom_add_file(_f, NULL, _a, _i, false, NULL, NULL) 3420d09e41aSPaolo Bonzini #define rom_add_blob_fixed(_f, _b, _l, _a) \ 343baf2d5bfSMichael S. Tsirkin rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, NULL, true) 34476151cacSPeter Maydell #define rom_add_file_mr(_f, _mr, _i) \ 3453e76099aSAlistair Francis rom_add_file(_f, NULL, 0, _i, false, _mr, NULL) 3463e76099aSAlistair Francis #define rom_add_file_as(_f, _as, _i) \ 3473e76099aSAlistair Francis rom_add_file(_f, NULL, 0, _i, false, NULL, _as) 34893ffc7c7SAlistair Francis #define rom_add_file_fixed_as(_f, _a, _i, _as) \ 34993ffc7c7SAlistair Francis rom_add_file(_f, NULL, _a, _i, false, NULL, _as) 3505e774eb3SAlistair Francis #define rom_add_blob_fixed_as(_f, _b, _l, _a, _as) \ 351baf2d5bfSMichael S. Tsirkin rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, _as, true) 3520d09e41aSPaolo Bonzini 353af975131SJamie Iles ssize_t rom_add_vga(const char *file); 354af975131SJamie Iles ssize_t rom_add_option(const char *file, int32_t bootindex); 3550d09e41aSPaolo Bonzini 35651b58561SPaul Burton /* This is the usual maximum in uboot, so if a uImage overflows this, it would 35751b58561SPaul Burton * overflow on real hardware too. */ 35851b58561SPaul Burton #define UBOOT_MAX_GUNZIP_BYTES (64 << 20) 35951b58561SPaul Burton 3605fc983afSAlex Bennée typedef struct RomGap { 3615fc983afSAlex Bennée hwaddr base; 3625fc983afSAlex Bennée size_t size; 3635fc983afSAlex Bennée } RomGap; 3645fc983afSAlex Bennée 3655fc983afSAlex Bennée /** 3665fc983afSAlex Bennée * rom_find_largest_gap_between: return largest gap between ROMs in given range 3675fc983afSAlex Bennée * 3685fc983afSAlex Bennée * Given a range of addresses, this function finds the largest 3695fc983afSAlex Bennée * contiguous subrange which has no ROMs loaded to it. That is, 3705fc983afSAlex Bennée * it finds the biggest gap which is free for use for other things. 3715fc983afSAlex Bennée */ 3725fc983afSAlex Bennée RomGap rom_find_largest_gap_between(hwaddr base, size_t size); 3735fc983afSAlex Bennée 3740d09e41aSPaolo Bonzini #endif 375