xref: /qemu/include/hw/loader.h (revision ff11422804cd03494cc98691eecd3909ea09ab6f)
1ca20cf32SBlue Swirl #ifndef LOADER_H
2ca20cf32SBlue Swirl #define LOADER_H
3a88b362cSLaszlo Ersek #include "hw/nvram/fw_cfg.h"
4ca20cf32SBlue Swirl 
5ca20cf32SBlue Swirl /* 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,
6480a2ba3dSMark Langsdorf                             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
807d48a0f7SLaszlo Ersek  * load_image_gzipped_buffer() and load_image_gzipped() 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);
87af975131SJamie Iles ssize_t load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
8818674b26SAlexey Kardashevskiy 
89*ff114228SArd Biesheuvel /**
90*ff114228SArd Biesheuvel  * unpack_efi_zboot_image:
91*ff114228SArd Biesheuvel  * @buffer: pointer to a variable holding the address of a buffer containing the
92*ff114228SArd Biesheuvel  *          image
93*ff114228SArd Biesheuvel  * @size: pointer to a variable holding the size of the buffer
94*ff114228SArd Biesheuvel  *
95*ff114228SArd Biesheuvel  * Check whether the buffer contains a EFI zboot image, and if it does, extract
96*ff114228SArd Biesheuvel  * the compressed payload and decompress it into a new buffer. If successful,
97*ff114228SArd Biesheuvel  * the old buffer is freed, and the *buffer and size variables pointed to by the
98*ff114228SArd Biesheuvel  * function arguments are updated to refer to the newly populated buffer.
99*ff114228SArd Biesheuvel  *
100*ff114228SArd Biesheuvel  * Returns 0 if the image could not be identified as a EFI zboot image.
101*ff114228SArd Biesheuvel  * Returns -1 if the buffer contents were identified as a EFI zboot image, but
102*ff114228SArd Biesheuvel  * unpacking failed for any reason.
103*ff114228SArd Biesheuvel  * Returns the size of the decompressed payload if decompression was performed
104*ff114228SArd Biesheuvel  * successfully.
105*ff114228SArd Biesheuvel  */
106*ff114228SArd Biesheuvel ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size);
107*ff114228SArd Biesheuvel 
10818674b26SAlexey Kardashevskiy #define ELF_LOAD_FAILED       -1
10918674b26SAlexey Kardashevskiy #define ELF_LOAD_NOT_ELF      -2
11018674b26SAlexey Kardashevskiy #define ELF_LOAD_WRONG_ARCH   -3
11118674b26SAlexey Kardashevskiy #define ELF_LOAD_WRONG_ENDIAN -4
11241a26351SStefano Garzarella #define ELF_LOAD_TOO_BIG      -5
1138975eb89SLuc Michel const char *load_elf_strerror(ssize_t error);
114140b7ce5SPeter Crosthwaite 
115a2480ffaSMichael Clark /** load_elf_ram_sym:
116140b7ce5SPeter Crosthwaite  * @filename: Path of ELF file
1174366e1dbSLiam Merwick  * @elf_note_fn: optional function to parse ELF Note type
1184366e1dbSLiam Merwick  *               passed via @translate_opaque
119140b7ce5SPeter Crosthwaite  * @translate_fn: optional function to translate load addresses
120140b7ce5SPeter Crosthwaite  * @translate_opaque: opaque data passed to @translate_fn
121140b7ce5SPeter Crosthwaite  * @pentry: Populated with program entry point. Ignored if NULL.
122140b7ce5SPeter Crosthwaite  * @lowaddr: Populated with lowest loaded address. Ignored if NULL.
123140b7ce5SPeter Crosthwaite  * @highaddr: Populated with highest loaded address. Ignored if NULL.
1246cdda0ffSAleksandar Markovic  * @pflags: Populated with ELF processor-specific flags. Ignore if NULL.
125140b7ce5SPeter Crosthwaite  * @bigendian: Expected ELF endianness. 0 for LE otherwise BE
126140b7ce5SPeter Crosthwaite  * @elf_machine: Expected ELF machine type
127140b7ce5SPeter Crosthwaite  * @clear_lsb: Set to mask off LSB of addresses (Some architectures use
128140b7ce5SPeter Crosthwaite  *             this for non-address data)
1297ef295eaSPeter Crosthwaite  * @data_swab: Set to order of byte swapping for data. 0 for no swap, 1
1307ef295eaSPeter Crosthwaite  *             for swapping bytes within halfwords, 2 for bytes within
1317ef295eaSPeter Crosthwaite  *             words and 3 for within doublewords.
13270bb1d16SAlistair Francis  * @as: The AddressSpace to load the ELF to. The value of address_space_memory
13370bb1d16SAlistair Francis  *      is used if nothing is supplied here.
13434f1b23fSFarhan Ali  * @load_rom : Load ELF binary as ROM
135a2480ffaSMichael Clark  * @sym_cb: Callback function for symbol table entries
136140b7ce5SPeter Crosthwaite  *
137140b7ce5SPeter Crosthwaite  * Load an ELF file's contents to the emulated system's address space.
138140b7ce5SPeter Crosthwaite  * Clients may optionally specify a callback to perform address
139140b7ce5SPeter Crosthwaite  * translations. @pentry, @lowaddr and @highaddr are optional pointers
140140b7ce5SPeter Crosthwaite  * which will be populated with various load information. @bigendian and
141140b7ce5SPeter Crosthwaite  * @elf_machine give the expected endianness and machine for the ELF the
142140b7ce5SPeter Crosthwaite  * load will fail if the target ELF does not match. Some architectures
143140b7ce5SPeter Crosthwaite  * have some architecture-specific behaviours that come into effect when
144140b7ce5SPeter Crosthwaite  * their particular values for @elf_machine are set.
1458cf6e9daSAlistair Francis  * If @elf_machine is EM_NONE then the machine type will be read from the
1468cf6e9daSAlistair Francis  * ELF header and no checks will be carried out against the machine type.
147140b7ce5SPeter Crosthwaite  */
148a2480ffaSMichael Clark typedef void (*symbol_fn_t)(const char *st_name, int st_info,
149a2480ffaSMichael Clark                             uint64_t st_value, uint64_t st_size);
150a2480ffaSMichael Clark 
1518975eb89SLuc Michel ssize_t load_elf_ram_sym(const char *filename,
1524366e1dbSLiam Merwick                          uint64_t (*elf_note_fn)(void *, void *, bool),
153a2480ffaSMichael Clark                          uint64_t (*translate_fn)(void *, uint64_t),
154a2480ffaSMichael Clark                          void *translate_opaque, uint64_t *pentry,
1558975eb89SLuc Michel                          uint64_t *lowaddr, uint64_t *highaddr,
1568975eb89SLuc Michel                          uint32_t *pflags, int big_endian, int elf_machine,
1576cdda0ffSAleksandar Markovic                          int clear_lsb, int data_swab,
158a2480ffaSMichael Clark                          AddressSpace *as, bool load_rom, symbol_fn_t sym_cb);
159a2480ffaSMichael Clark 
160a2480ffaSMichael Clark /** load_elf_ram:
161a2480ffaSMichael Clark  * Same as load_elf_ram_sym(), but doesn't allow the caller to specify a
162a2480ffaSMichael Clark  * symbol callback function
163a2480ffaSMichael Clark  */
1648975eb89SLuc Michel ssize_t load_elf_ram(const char *filename,
1654366e1dbSLiam Merwick                      uint64_t (*elf_note_fn)(void *, void *, bool),
16634f1b23fSFarhan Ali                      uint64_t (*translate_fn)(void *, uint64_t),
1678975eb89SLuc Michel                      void *translate_opaque, uint64_t *pentry,
1688975eb89SLuc Michel                      uint64_t *lowaddr, uint64_t *highaddr, uint32_t *pflags,
1698975eb89SLuc Michel                      int big_endian, int elf_machine, int clear_lsb,
1708975eb89SLuc Michel                      int data_swab, AddressSpace *as, bool load_rom);
17134f1b23fSFarhan Ali 
17234f1b23fSFarhan Ali /** load_elf_as:
17334f1b23fSFarhan Ali  * Same as load_elf_ram(), but always loads the elf as ROM
17434f1b23fSFarhan Ali  */
1758975eb89SLuc Michel ssize_t load_elf_as(const char *filename,
1764366e1dbSLiam Merwick                     uint64_t (*elf_note_fn)(void *, void *, bool),
17770bb1d16SAlistair Francis                     uint64_t (*translate_fn)(void *, uint64_t),
17870bb1d16SAlistair Francis                     void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
1796cdda0ffSAleksandar Markovic                     uint64_t *highaddr, uint32_t *pflags, int big_endian,
1806cdda0ffSAleksandar Markovic                     int elf_machine, int clear_lsb, int data_swab,
1816cdda0ffSAleksandar Markovic                     AddressSpace *as);
182140b7ce5SPeter Crosthwaite 
18370bb1d16SAlistair Francis /** load_elf:
18470bb1d16SAlistair Francis  * Same as load_elf_as(), but doesn't allow the caller to specify an
18570bb1d16SAlistair Francis  * AddressSpace.
18670bb1d16SAlistair Francis  */
1878975eb89SLuc Michel ssize_t load_elf(const char *filename,
1884366e1dbSLiam Merwick                  uint64_t (*elf_note_fn)(void *, void *, bool),
1894366e1dbSLiam Merwick                  uint64_t (*translate_fn)(void *, uint64_t),
190409dbce5SAurelien Jarno                  void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
1916cdda0ffSAleksandar Markovic                  uint64_t *highaddr, uint32_t *pflags, int big_endian,
1926cdda0ffSAleksandar Markovic                  int elf_machine, int clear_lsb, int data_swab);
19304ae712aSPeter Crosthwaite 
19404ae712aSPeter Crosthwaite /** load_elf_hdr:
19504ae712aSPeter Crosthwaite  * @filename: Path of ELF file
19604ae712aSPeter Crosthwaite  * @hdr: Buffer to populate with header data. Header data will not be
19704ae712aSPeter Crosthwaite  * filled if set to NULL.
19804ae712aSPeter Crosthwaite  * @is64: Set to true if the ELF is 64bit. Ignored if set to NULL
19904ae712aSPeter Crosthwaite  * @errp: Populated with an error in failure cases
20004ae712aSPeter Crosthwaite  *
20104ae712aSPeter Crosthwaite  * Inspect an ELF file's header. Read its full header contents into a
20204ae712aSPeter Crosthwaite  * buffer and/or determine if the ELF is 64bit.
20304ae712aSPeter Crosthwaite  */
20404ae712aSPeter Crosthwaite void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
20504ae712aSPeter Crosthwaite 
206af975131SJamie Iles ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
207a8170e5eSAvi Kivity                   int bswap_needed, hwaddr target_page_size);
2085e774eb3SAlistair Francis 
209f831f955SNick Hudson #define LOAD_UIMAGE_LOADADDR_INVALID (-1)
210f831f955SNick Hudson 
2115e774eb3SAlistair Francis /** load_uimage_as:
2125e774eb3SAlistair Francis  * @filename: Path of uimage file
2135e774eb3SAlistair Francis  * @ep: Populated with program entry point. Ignored if NULL.
214f831f955SNick Hudson  * @loadaddr: load address if none specified in the image or when loading a
215f831f955SNick Hudson  *            ramdisk. Populated with the load address. Ignored if NULL or
216f831f955SNick Hudson  *            LOAD_UIMAGE_LOADADDR_INVALID (images which do not specify a load
217f831f955SNick Hudson  *            address will not be loadable).
2185e774eb3SAlistair Francis  * @is_linux: Is set to true if the image loaded is Linux. Ignored if NULL.
2195e774eb3SAlistair Francis  * @translate_fn: optional function to translate load addresses
2205e774eb3SAlistair Francis  * @translate_opaque: opaque data passed to @translate_fn
2215e774eb3SAlistair Francis  * @as: The AddressSpace to load the ELF to. The value of address_space_memory
2225e774eb3SAlistair Francis  *      is used if nothing is supplied here.
2235e774eb3SAlistair Francis  *
2245e774eb3SAlistair Francis  * Loads a u-boot image into memory.
2255e774eb3SAlistair Francis  *
2265e774eb3SAlistair Francis  * Returns the size of the loaded image on success, -1 otherwise.
2275e774eb3SAlistair Francis  */
228af975131SJamie Iles ssize_t load_uimage_as(const char *filename, hwaddr *ep,
2295e774eb3SAlistair Francis                        hwaddr *loadaddr, int *is_linux,
2305e774eb3SAlistair Francis                        uint64_t (*translate_fn)(void *, uint64_t),
2315e774eb3SAlistair Francis                        void *translate_opaque, AddressSpace *as);
2325e774eb3SAlistair Francis 
2335e774eb3SAlistair Francis /** load_uimage:
2345e774eb3SAlistair Francis  * Same as load_uimage_as(), but doesn't allow the caller to specify an
2355e774eb3SAlistair Francis  * AddressSpace.
2365e774eb3SAlistair Francis  */
237af975131SJamie Iles ssize_t load_uimage(const char *filename, hwaddr *ep,
23825bda50aSMax Filippov                     hwaddr *loadaddr, int *is_linux,
23925bda50aSMax Filippov                     uint64_t (*translate_fn)(void *, uint64_t),
24025bda50aSMax Filippov                     void *translate_opaque);
241ca20cf32SBlue Swirl 
24284aee0deSSoren Brinkmann /**
24397df5feeSPeter Maydell  * load_ramdisk_as:
24484aee0deSSoren Brinkmann  * @filename: Path to the ramdisk image
24584aee0deSSoren Brinkmann  * @addr: Memory address to load the ramdisk to
24684aee0deSSoren Brinkmann  * @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks)
24797df5feeSPeter Maydell  * @as: The AddressSpace to load the ELF to. The value of address_space_memory
24897df5feeSPeter Maydell  *      is used if nothing is supplied here.
24984aee0deSSoren Brinkmann  *
25084aee0deSSoren Brinkmann  * Load a ramdisk image with U-Boot header to the specified memory
25184aee0deSSoren Brinkmann  * address.
25284aee0deSSoren Brinkmann  *
25384aee0deSSoren Brinkmann  * Returns the size of the loaded image on success, -1 otherwise.
25484aee0deSSoren Brinkmann  */
255af975131SJamie Iles ssize_t load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz,
25697df5feeSPeter Maydell                         AddressSpace *as);
25797df5feeSPeter Maydell 
25897df5feeSPeter Maydell /**
25997df5feeSPeter Maydell  * load_ramdisk:
26097df5feeSPeter Maydell  * Same as load_ramdisk_as(), but doesn't allow the caller to specify
26197df5feeSPeter Maydell  * an AddressSpace.
26297df5feeSPeter Maydell  */
263af975131SJamie Iles ssize_t load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz);
26484aee0deSSoren Brinkmann 
26551b58561SPaul Burton ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen);
26651b58561SPaul Burton 
267725e14e9SMarkus Armbruster ssize_t read_targphys(const char *name,
268a8170e5eSAvi Kivity                       int fd, hwaddr dst_addr, size_t nbytes);
2693c178e72SGerd Hoffmann void pstrcpy_targphys(const char *name,
270a8170e5eSAvi Kivity                       hwaddr dest, int buf_size,
271ca20cf32SBlue Swirl                       const char *source);
27245a50b16SGerd Hoffmann 
273af975131SJamie Iles ssize_t rom_add_file(const char *file, const char *fw_dir,
274ac41881bSMichael S. Tsirkin                      hwaddr addr, int32_t bootindex,
2753e76099aSAlistair Francis                      bool option_rom, MemoryRegion *mr, AddressSpace *as);
276339240b5SPaolo Bonzini MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
277339240b5SPaolo Bonzini                            size_t max_len, hwaddr addr,
278339240b5SPaolo Bonzini                            const char *fw_file_name,
2796f6f4aecSMarc-André Lureau                            FWCfgCallback fw_callback,
280baf2d5bfSMichael S. Tsirkin                            void *callback_opaque, AddressSpace *as,
281baf2d5bfSMichael S. Tsirkin                            bool read_only);
282fef28891SStefano Garzarella int rom_add_elf_program(const char *name, GMappedFile *mapped_file, void *data,
283fef28891SStefano Garzarella                         size_t datasize, size_t romsize, hwaddr addr,
284fef28891SStefano Garzarella                         AddressSpace *as);
2856b3f7f63SEric Auger int rom_check_and_register_reset(void);
286a88b362cSLaszlo Ersek void rom_set_fw(FWCfgState *f);
287bab47d9aSGerd Hoffmann void rom_set_order_override(int order);
288bab47d9aSGerd Hoffmann void rom_reset_order_override(void);
289e2336043SStefan Hajnoczi 
290e2336043SStefan Hajnoczi /**
291e2336043SStefan Hajnoczi  * rom_transaction_begin:
292e2336043SStefan Hajnoczi  *
293e2336043SStefan Hajnoczi  * Call this before of a series of rom_add_*() calls.  Call
294e2336043SStefan Hajnoczi  * rom_transaction_end() afterwards to commit or abort.  These functions are
295e2336043SStefan Hajnoczi  * useful for undoing a series of rom_add_*() calls if image file loading fails
296e2336043SStefan Hajnoczi  * partway through.
297e2336043SStefan Hajnoczi  */
298e2336043SStefan Hajnoczi void rom_transaction_begin(void);
299e2336043SStefan Hajnoczi 
300e2336043SStefan Hajnoczi /**
301e2336043SStefan Hajnoczi  * rom_transaction_end:
302e2336043SStefan Hajnoczi  * @commit: true to commit added roms, false to drop added roms
303e2336043SStefan Hajnoczi  *
304e2336043SStefan Hajnoczi  * Call this after a series of rom_add_*() calls.  See rom_transaction_begin().
305e2336043SStefan Hajnoczi  */
306e2336043SStefan Hajnoczi void rom_transaction_end(bool commit);
307e2336043SStefan Hajnoczi 
308a8170e5eSAvi Kivity int rom_copy(uint8_t *dest, hwaddr addr, size_t size);
3090f0f8b61SThomas Huth void *rom_ptr(hwaddr addr, size_t size);
3101228c459SPeter Maydell /**
3111228c459SPeter Maydell  * rom_ptr_for_as: Return a pointer to ROM blob data for the address
3121228c459SPeter Maydell  * @as: AddressSpace to look for the ROM blob in
3131228c459SPeter Maydell  * @addr: Address within @as
3141228c459SPeter Maydell  * @size: size of data required in bytes
3151228c459SPeter Maydell  *
3161228c459SPeter Maydell  * Returns: pointer into the data which backs the matching ROM blob,
3171228c459SPeter Maydell  * or NULL if no blob covers the address range.
3181228c459SPeter Maydell  *
3191228c459SPeter Maydell  * This function looks for a ROM blob which covers the specified range
3201228c459SPeter Maydell  * of bytes of length @size starting at @addr within the address space
3211228c459SPeter Maydell  * @as. This is useful for code which runs as part of board
3221228c459SPeter Maydell  * initialization or CPU reset which wants to read data that is part
3231228c459SPeter Maydell  * of a user-supplied guest image or other guest memory contents, but
3241228c459SPeter Maydell  * which runs before the ROM loader's reset function has copied the
3251228c459SPeter Maydell  * blobs into guest memory.
3261228c459SPeter Maydell  *
3271228c459SPeter Maydell  * rom_ptr_for_as() will look not just for blobs loaded directly to
3281228c459SPeter Maydell  * the specified address, but also for blobs which were loaded to an
3291228c459SPeter Maydell  * alias of the region at a different location in the AddressSpace.
3301228c459SPeter Maydell  * In other words, if a machine model has RAM at address 0x0000_0000
3311228c459SPeter Maydell  * which is aliased to also appear at 0x1000_0000, rom_ptr_for_as()
3321228c459SPeter Maydell  * will return the correct data whether the guest image was linked and
3331228c459SPeter Maydell  * loaded at 0x0000_0000 or 0x1000_0000.  Contrast rom_ptr(), which
3341228c459SPeter Maydell  * will only return data if the image load address is an exact match
3351228c459SPeter Maydell  * with the queried address.
3361228c459SPeter Maydell  *
3371228c459SPeter Maydell  * New code should prefer to use rom_ptr_for_as() instead of
3381228c459SPeter Maydell  * rom_ptr().
3391228c459SPeter Maydell  */
3401228c459SPeter Maydell void *rom_ptr_for_as(AddressSpace *as, hwaddr addr, size_t size);
3411ce6be24SMarkus Armbruster void hmp_info_roms(Monitor *mon, const QDict *qdict);
34245a50b16SGerd Hoffmann 
3432e55e842SGleb Natapov #define rom_add_file_fixed(_f, _a, _i)          \
3443e76099aSAlistair Francis     rom_add_file(_f, NULL, _a, _i, false, NULL, NULL)
34545a50b16SGerd Hoffmann #define rom_add_blob_fixed(_f, _b, _l, _a)      \
346baf2d5bfSMichael S. Tsirkin     rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, NULL, true)
34776151cacSPeter Maydell #define rom_add_file_mr(_f, _mr, _i)            \
3483e76099aSAlistair Francis     rom_add_file(_f, NULL, 0, _i, false, _mr, NULL)
3493e76099aSAlistair Francis #define rom_add_file_as(_f, _as, _i)            \
3503e76099aSAlistair Francis     rom_add_file(_f, NULL, 0, _i, false, NULL, _as)
35193ffc7c7SAlistair Francis #define rom_add_file_fixed_as(_f, _a, _i, _as)          \
35293ffc7c7SAlistair Francis     rom_add_file(_f, NULL, _a, _i, false, NULL, _as)
3535e774eb3SAlistair Francis #define rom_add_blob_fixed_as(_f, _b, _l, _a, _as)      \
354baf2d5bfSMichael S. Tsirkin     rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, _as, true)
35545a50b16SGerd Hoffmann 
356af975131SJamie Iles ssize_t rom_add_vga(const char *file);
357af975131SJamie Iles ssize_t rom_add_option(const char *file, int32_t bootindex);
35845a50b16SGerd Hoffmann 
35951b58561SPaul Burton /* This is the usual maximum in uboot, so if a uImage overflows this, it would
36051b58561SPaul Burton  * overflow on real hardware too. */
36151b58561SPaul Burton #define UBOOT_MAX_GUNZIP_BYTES (64 << 20)
36251b58561SPaul Burton 
3635fc983afSAlex Bennée typedef struct RomGap {
3645fc983afSAlex Bennée     hwaddr base;
3655fc983afSAlex Bennée     size_t size;
3665fc983afSAlex Bennée } RomGap;
3675fc983afSAlex Bennée 
3685fc983afSAlex Bennée /**
3695fc983afSAlex Bennée  * rom_find_largest_gap_between: return largest gap between ROMs in given range
3705fc983afSAlex Bennée  *
3715fc983afSAlex Bennée  * Given a range of addresses, this function finds the largest
3725fc983afSAlex Bennée  * contiguous subrange which has no ROMs loaded to it. That is,
3735fc983afSAlex Bennée  * it finds the biggest gap which is free for use for other things.
3745fc983afSAlex Bennée  */
3755fc983afSAlex Bennée RomGap rom_find_largest_gap_between(hwaddr base, size_t size);
3765fc983afSAlex Bennée 
377ca20cf32SBlue Swirl #endif
378