From: Haozhong Zhang <haozhong.zh...@intel.com> Expose some data structures and functions of BIOS linker loader which will be used by later commits.
Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> --- hw/acpi/bios-linker-loader.c | 83 +---------------------------------- include/hw/acpi/bios-linker-loader.h | 85 ++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 82 deletions(-) diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c index d963ebe..e9c19cf 100644 --- a/hw/acpi/bios-linker-loader.c +++ b/hw/acpi/bios-linker-loader.c @@ -21,91 +21,10 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "hw/acpi/bios-linker-loader.h" -#include "hw/nvram/fw_cfg.h" #include "qemu/bswap.h" /* - * Linker/loader is a paravirtualized interface that passes commands to guest. - * The commands can be used to request guest to - * - allocate memory chunks and initialize them from QEMU FW CFG files - * - link allocated chunks by storing pointer to one chunk into another - * - calculate ACPI checksum of part of the chunk and store into same chunk - */ -#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH - -struct BiosLinkerLoaderEntry { - uint32_t command; - union { - /* - * COMMAND_ALLOCATE - allocate a table from @alloc.file - * subject to @alloc.align alignment (must be power of 2) - * and @alloc.zone (can be HIGH or FSEG) requirements. - * - * Must appear exactly once for each file, and before - * this file is referenced by any other command. - */ - struct { - char file[BIOS_LINKER_LOADER_FILESZ]; - uint32_t align; - uint8_t zone; - } alloc; - - /* - * COMMAND_ADD_POINTER - patch the table (originating from - * @dest_file) at @pointer.offset, by adding a pointer to the table - * originating from @src_file. 1,2,4 or 8 byte unsigned - * addition is used depending on @pointer.size. - */ - struct { - char dest_file[BIOS_LINKER_LOADER_FILESZ]; - char src_file[BIOS_LINKER_LOADER_FILESZ]; - uint32_t offset; - uint8_t size; - } pointer; - - /* - * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by - * @cksum_start and @cksum_length fields, - * and then add the value at @cksum.offset. - * Checksum simply sums -X for each byte X in the range - * using 8-bit math. - */ - struct { - char file[BIOS_LINKER_LOADER_FILESZ]; - uint32_t offset; - uint32_t start; - uint32_t length; - } cksum; - - /* padding */ - char pad[124]; - }; -} QEMU_PACKED; -typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry; - -enum { - BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1, - BIOS_LINKER_LOADER_COMMAND_ADD_POINTER = 0x2, - BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3, -}; - -enum { - BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1, - BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2, -}; - -/* - * BiosLinkerFileEntry: - * - * An internal type used for book-keeping file entries - */ -typedef struct BiosLinkerFileEntry { - char *name; /* file name */ - GArray *blob; /* data accosiated with @name */ -} BiosLinkerFileEntry; - -/* * bios_linker_loader_init: allocate a new linker object instance. * * After initialization, linker commands can be added, and will @@ -137,7 +56,7 @@ void bios_linker_loader_cleanup(BIOSLinker *linker) g_free(linker); } -static const BiosLinkerFileEntry * +const BiosLinkerFileEntry * bios_linker_find_file(const BIOSLinker *linker, const char *name) { int i; diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-linker-loader.h index fa1e5d1..52c1e44 100644 --- a/include/hw/acpi/bios-linker-loader.h +++ b/include/hw/acpi/bios-linker-loader.h @@ -1,12 +1,93 @@ #ifndef BIOS_LINKER_LOADER_H #define BIOS_LINKER_LOADER_H +#include "hw/nvram/fw_cfg.h" typedef struct BIOSLinker { GArray *cmd_blob; GArray *file_list; } BIOSLinker; +/* + * Linker/loader is a paravirtualized interface that passes commands to guest. + * The commands can be used to request guest to + * - allocate memory chunks and initialize them from QEMU FW CFG files + * - link allocated chunks by storing pointer to one chunk into another + * - calculate ACPI checksum of part of the chunk and store into same chunk + */ +#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH + +struct BiosLinkerLoaderEntry { + uint32_t command; + union { + /* + * COMMAND_ALLOCATE - allocate a table from @alloc.file + * subject to @alloc.align alignment (must be power of 2) + * and @alloc.zone (can be HIGH or FSEG) requirements. + * + * Must appear exactly once for each file, and before + * this file is referenced by any other command. + */ + struct { + char file[BIOS_LINKER_LOADER_FILESZ]; + uint32_t align; + uint8_t zone; + } alloc; + + /* + * COMMAND_ADD_POINTER - patch the table (originating from + * @dest_file) at @pointer.offset, by adding a pointer to the table + * originating from @src_file. 1,2,4 or 8 byte unsigned + * addition is used depending on @pointer.size. + */ + struct { + char dest_file[BIOS_LINKER_LOADER_FILESZ]; + char src_file[BIOS_LINKER_LOADER_FILESZ]; + uint32_t offset; + uint8_t size; + } pointer; + + /* + * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by + * @cksum_start and @cksum_length fields, + * and then add the value at @cksum.offset. + * Checksum simply sums -X for each byte X in the range + * using 8-bit math. + */ + struct { + char file[BIOS_LINKER_LOADER_FILESZ]; + uint32_t offset; + uint32_t start; + uint32_t length; + } cksum; + + /* padding */ + char pad[124]; + }; +} QEMU_PACKED; +typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry; + +enum { + BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1, + BIOS_LINKER_LOADER_COMMAND_ADD_POINTER = 0x2, + BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3, +}; + +enum { + BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1, + BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2, +}; + +/* + * BiosLinkerFileEntry: + * + * An internal type used for book-keeping file entries + */ +typedef struct BiosLinkerFileEntry { + char *name; /* file name */ + GArray *blob; /* data accosiated with @name */ +} BiosLinkerFileEntry; + BIOSLinker *bios_linker_loader_init(void); void bios_linker_loader_alloc(BIOSLinker *linker, @@ -27,4 +108,8 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker, uint32_t src_offset); void bios_linker_loader_cleanup(BIOSLinker *linker); + +const BiosLinkerFileEntry * +bios_linker_find_file(const BIOSLinker *linker, const char *name); + #endif -- 1.8.3.1