qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

fw_cfg: import & use linux/qemu_fw_cfg.h

Use kernel common header for fw_cfg.

(unfortunately, optionrom.h must have its own define, since it's
actually an assembler header)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20180817155910.5722-2-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

authored by

Marc-André Lureau and committed by
Paolo Bonzini
5be5df72 039d7c4d

+125 -80
+1 -1
dump.c
··· 1742 1742 warn_report("guest note is not present"); 1743 1743 } else if (size < note_head_size || size > MAX_GUEST_NOTE_SIZE) { 1744 1744 warn_report("guest note size is invalid: %" PRIu32, size); 1745 - } else if (format != VMCOREINFO_FORMAT_ELF) { 1745 + } else if (format != FW_CFG_VMCOREINFO_FORMAT_ELF) { 1746 1746 warn_report("guest note format is unsupported: %" PRIu16, format); 1747 1747 } else { 1748 1748 s->guest_note = g_malloc(size + 1); /* +1 for adding \0 */
+3 -3
hw/misc/vmcoreinfo.c
··· 19 19 VMCoreInfoState *s = VMCOREINFO(dev); 20 20 21 21 s->has_vmcoreinfo = offset == 0 && len == sizeof(s->vmcoreinfo) 22 - && s->vmcoreinfo.guest_format != VMCOREINFO_FORMAT_NONE; 22 + && s->vmcoreinfo.guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE; 23 23 } 24 24 25 25 static void vmcoreinfo_reset(void *dev) ··· 28 28 29 29 s->has_vmcoreinfo = false; 30 30 memset(&s->vmcoreinfo, 0, sizeof(s->vmcoreinfo)); 31 - s->vmcoreinfo.host_format = cpu_to_le16(VMCOREINFO_FORMAT_ELF); 31 + s->vmcoreinfo.host_format = cpu_to_le16(FW_CFG_VMCOREINFO_FORMAT_ELF); 32 32 } 33 33 34 34 static void vmcoreinfo_realize(DeviceState *dev, Error **errp) ··· 53 53 return; 54 54 } 55 55 56 - fw_cfg_add_file_callback(fw_cfg, "etc/vmcoreinfo", 56 + fw_cfg_add_file_callback(fw_cfg, FW_CFG_VMCOREINFO_FILENAME, 57 57 NULL, fw_cfg_vmci_write, s, 58 58 &s->vmcoreinfo, sizeof(s->vmcoreinfo), false); 59 59
+2 -10
include/hw/misc/vmcoreinfo.h
··· 13 13 #define VMCOREINFO_H 14 14 15 15 #include "hw/qdev.h" 16 + #include "standard-headers/linux/qemu_fw_cfg.h" 16 17 17 18 #define VMCOREINFO_DEVICE "vmcoreinfo" 18 19 #define VMCOREINFO(obj) OBJECT_CHECK(VMCoreInfoState, (obj), VMCOREINFO_DEVICE) 19 20 20 - #define VMCOREINFO_FORMAT_NONE 0x0 21 - #define VMCOREINFO_FORMAT_ELF 0x1 22 - 23 - /* all fields are little-endian */ 24 - typedef struct FWCfgVMCoreInfo { 25 - uint16_t host_format; /* set on reset */ 26 - uint16_t guest_format; 27 - uint32_t size; 28 - uint64_t paddr; 29 - } QEMU_PACKED FWCfgVMCoreInfo; 21 + typedef struct fw_cfg_vmcoreinfo FWCfgVMCoreInfo; 30 22 31 23 typedef struct VMCoreInfoState { 32 24 DeviceClass parent_obj;
+3 -15
include/hw/nvram/fw_cfg.h
··· 2 2 #define FW_CFG_H 3 3 4 4 #include "exec/hwaddr.h" 5 - #include "hw/nvram/fw_cfg_keys.h" 5 + #include "standard-headers/linux/qemu_fw_cfg.h" 6 6 #include "hw/sysbus.h" 7 7 #include "sysemu/dma.h" 8 8 ··· 14 14 #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO) 15 15 #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM) 16 16 17 - typedef struct FWCfgFile { 18 - uint32_t size; /* file size */ 19 - uint16_t select; /* write this to 0x510 to read it */ 20 - uint16_t reserved; 21 - char name[FW_CFG_MAX_FILE_PATH]; 22 - } FWCfgFile; 17 + typedef struct fw_cfg_file FWCfgFile; 23 18 24 19 #define FW_CFG_ORDER_OVERRIDE_VGA 70 25 20 #define FW_CFG_ORDER_OVERRIDE_NIC 80 ··· 34 29 FWCfgFile f[]; 35 30 } FWCfgFiles; 36 31 37 - /* Control as first field allows for different structures selected by this 38 - * field, which might be useful in the future 39 - */ 40 - typedef struct FWCfgDmaAccess { 41 - uint32_t control; 42 - uint32_t length; 43 - uint64_t address; 44 - } QEMU_PACKED FWCfgDmaAccess; 32 + typedef struct fw_cfg_dma_access FWCfgDmaAccess; 45 33 46 34 typedef void (*FWCfgCallback)(void *opaque); 47 35 typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len);
-45
include/hw/nvram/fw_cfg_keys.h
··· 1 - #ifndef FW_CFG_KEYS_H 2 - #define FW_CFG_KEYS_H 3 - 4 - #define FW_CFG_SIGNATURE 0x00 5 - #define FW_CFG_ID 0x01 6 - #define FW_CFG_UUID 0x02 7 - #define FW_CFG_RAM_SIZE 0x03 8 - #define FW_CFG_NOGRAPHIC 0x04 9 - #define FW_CFG_NB_CPUS 0x05 10 - #define FW_CFG_MACHINE_ID 0x06 11 - #define FW_CFG_KERNEL_ADDR 0x07 12 - #define FW_CFG_KERNEL_SIZE 0x08 13 - #define FW_CFG_KERNEL_CMDLINE 0x09 14 - #define FW_CFG_INITRD_ADDR 0x0a 15 - #define FW_CFG_INITRD_SIZE 0x0b 16 - #define FW_CFG_BOOT_DEVICE 0x0c 17 - #define FW_CFG_NUMA 0x0d 18 - #define FW_CFG_BOOT_MENU 0x0e 19 - #define FW_CFG_MAX_CPUS 0x0f 20 - #define FW_CFG_KERNEL_ENTRY 0x10 21 - #define FW_CFG_KERNEL_DATA 0x11 22 - #define FW_CFG_INITRD_DATA 0x12 23 - #define FW_CFG_CMDLINE_ADDR 0x13 24 - #define FW_CFG_CMDLINE_SIZE 0x14 25 - #define FW_CFG_CMDLINE_DATA 0x15 26 - #define FW_CFG_SETUP_ADDR 0x16 27 - #define FW_CFG_SETUP_SIZE 0x17 28 - #define FW_CFG_SETUP_DATA 0x18 29 - #define FW_CFG_FILE_DIR 0x19 30 - 31 - #define FW_CFG_FILE_FIRST 0x20 32 - #define FW_CFG_FILE_SLOTS_MIN 0x10 33 - 34 - #define FW_CFG_WRITE_CHANNEL 0x4000 35 - #define FW_CFG_ARCH_LOCAL 0x8000 36 - #define FW_CFG_ENTRY_MASK (~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)) 37 - 38 - #define FW_CFG_INVALID 0xffff 39 - 40 - /* width in bytes of fw_cfg control register */ 41 - #define FW_CFG_CTL_SIZE 0x02 42 - 43 - #define FW_CFG_MAX_FILE_PATH 56 44 - 45 - #endif
+97
include/standard-headers/linux/qemu_fw_cfg.h
··· 1 + /* SPDX-License-Identifier: BSD-3-Clause */ 2 + #ifndef _LINUX_FW_CFG_H 3 + #define _LINUX_FW_CFG_H 4 + 5 + #include "standard-headers/linux/types.h" 6 + 7 + #define FW_CFG_ACPI_DEVICE_ID "QEMU0002" 8 + 9 + /* selector key values for "well-known" fw_cfg entries */ 10 + #define FW_CFG_SIGNATURE 0x00 11 + #define FW_CFG_ID 0x01 12 + #define FW_CFG_UUID 0x02 13 + #define FW_CFG_RAM_SIZE 0x03 14 + #define FW_CFG_NOGRAPHIC 0x04 15 + #define FW_CFG_NB_CPUS 0x05 16 + #define FW_CFG_MACHINE_ID 0x06 17 + #define FW_CFG_KERNEL_ADDR 0x07 18 + #define FW_CFG_KERNEL_SIZE 0x08 19 + #define FW_CFG_KERNEL_CMDLINE 0x09 20 + #define FW_CFG_INITRD_ADDR 0x0a 21 + #define FW_CFG_INITRD_SIZE 0x0b 22 + #define FW_CFG_BOOT_DEVICE 0x0c 23 + #define FW_CFG_NUMA 0x0d 24 + #define FW_CFG_BOOT_MENU 0x0e 25 + #define FW_CFG_MAX_CPUS 0x0f 26 + #define FW_CFG_KERNEL_ENTRY 0x10 27 + #define FW_CFG_KERNEL_DATA 0x11 28 + #define FW_CFG_INITRD_DATA 0x12 29 + #define FW_CFG_CMDLINE_ADDR 0x13 30 + #define FW_CFG_CMDLINE_SIZE 0x14 31 + #define FW_CFG_CMDLINE_DATA 0x15 32 + #define FW_CFG_SETUP_ADDR 0x16 33 + #define FW_CFG_SETUP_SIZE 0x17 34 + #define FW_CFG_SETUP_DATA 0x18 35 + #define FW_CFG_FILE_DIR 0x19 36 + 37 + #define FW_CFG_FILE_FIRST 0x20 38 + #define FW_CFG_FILE_SLOTS_MIN 0x10 39 + 40 + #define FW_CFG_WRITE_CHANNEL 0x4000 41 + #define FW_CFG_ARCH_LOCAL 0x8000 42 + #define FW_CFG_ENTRY_MASK (~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)) 43 + 44 + #define FW_CFG_INVALID 0xffff 45 + 46 + /* width in bytes of fw_cfg control register */ 47 + #define FW_CFG_CTL_SIZE 0x02 48 + 49 + /* fw_cfg "file name" is up to 56 characters (including terminating nul) */ 50 + #define FW_CFG_MAX_FILE_PATH 56 51 + 52 + /* size in bytes of fw_cfg signature */ 53 + #define FW_CFG_SIG_SIZE 4 54 + 55 + /* FW_CFG_ID bits */ 56 + #define FW_CFG_VERSION 0x01 57 + #define FW_CFG_VERSION_DMA 0x02 58 + 59 + /* fw_cfg file directory entry type */ 60 + struct fw_cfg_file { 61 + uint32_t size; 62 + uint16_t select; 63 + uint16_t reserved; 64 + char name[FW_CFG_MAX_FILE_PATH]; 65 + }; 66 + 67 + /* FW_CFG_DMA_CONTROL bits */ 68 + #define FW_CFG_DMA_CTL_ERROR 0x01 69 + #define FW_CFG_DMA_CTL_READ 0x02 70 + #define FW_CFG_DMA_CTL_SKIP 0x04 71 + #define FW_CFG_DMA_CTL_SELECT 0x08 72 + #define FW_CFG_DMA_CTL_WRITE 0x10 73 + 74 + #define FW_CFG_DMA_SIGNATURE 0x51454d5520434647ULL /* "QEMU CFG" */ 75 + 76 + /* Control as first field allows for different structures selected by this 77 + * field, which might be useful in the future 78 + */ 79 + struct fw_cfg_dma_access { 80 + uint32_t control; 81 + uint32_t length; 82 + uint64_t address; 83 + }; 84 + 85 + #define FW_CFG_VMCOREINFO_FILENAME "etc/vmcoreinfo" 86 + 87 + #define FW_CFG_VMCOREINFO_FORMAT_NONE 0x0 88 + #define FW_CFG_VMCOREINFO_FORMAT_ELF 0x1 89 + 90 + struct fw_cfg_vmcoreinfo { 91 + uint16_t host_format; 92 + uint16_t guest_format; 93 + uint32_t size; 94 + uint64_t paddr; 95 + }; 96 + 97 + #endif
+2 -2
pc-bios/optionrom/linuxboot_dma.c
··· 58 58 " jmp load_kernel\n" 59 59 ); 60 60 61 - #include "../../include/hw/nvram/fw_cfg_keys.h" 62 - 63 61 /* QEMU_CFG_DMA_CONTROL bits */ 64 62 #define BIOS_CFG_DMA_CTL_ERROR 0x01 65 63 #define BIOS_CFG_DMA_CTL_READ 0x02 ··· 72 70 #define uint64_t unsigned long long 73 71 #define uint32_t unsigned int 74 72 #define uint16_t unsigned short 73 + 74 + #include "../../include/standard-headers/linux/qemu_fw_cfg.h" 75 75 76 76 #define barrier() asm("" : : : "memory") 77 77
+14 -1
pc-bios/optionrom/optionrom.h
··· 19 19 */ 20 20 21 21 22 - #include "../../include/hw/nvram/fw_cfg_keys.h" 22 + #define FW_CFG_KERNEL_ADDR 0x07 23 + #define FW_CFG_KERNEL_SIZE 0x08 24 + #define FW_CFG_KERNEL_CMDLINE 0x09 25 + #define FW_CFG_INITRD_ADDR 0x0a 26 + #define FW_CFG_INITRD_SIZE 0x0b 27 + #define FW_CFG_KERNEL_ENTRY 0x10 28 + #define FW_CFG_KERNEL_DATA 0x11 29 + #define FW_CFG_INITRD_DATA 0x12 30 + #define FW_CFG_CMDLINE_ADDR 0x13 31 + #define FW_CFG_CMDLINE_SIZE 0x14 32 + #define FW_CFG_CMDLINE_DATA 0x15 33 + #define FW_CFG_SETUP_ADDR 0x16 34 + #define FW_CFG_SETUP_SIZE 0x17 35 + #define FW_CFG_SETUP_DATA 0x18 23 36 24 37 #define BIOS_CFG_IOPORT_CFG 0x510 25 38 #define BIOS_CFG_IOPORT_DATA 0x511
+1 -1
tests/boot-order-test.c
··· 14 14 #include "libqos/fw_cfg.h" 15 15 #include "libqtest.h" 16 16 #include "qapi/qmp/qdict.h" 17 - #include "hw/nvram/fw_cfg_keys.h" 17 + #include "standard-headers/linux/qemu_fw_cfg.h" 18 18 19 19 /* TODO actually test the results and get rid of this */ 20 20 #define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))
+1 -1
tests/fw_cfg-test.c
··· 13 13 #include "qemu/osdep.h" 14 14 15 15 #include "libqtest.h" 16 - #include "hw/nvram/fw_cfg_keys.h" 16 + #include "standard-headers/linux/qemu_fw_cfg.h" 17 17 #include "libqos/fw_cfg.h" 18 18 19 19 static uint64_t ram_size = 128 << 20;
+1 -1
tests/libqos/malloc-pc.c
··· 14 14 #include "libqos/malloc-pc.h" 15 15 #include "libqos/fw_cfg.h" 16 16 17 - #include "hw/nvram/fw_cfg_keys.h" 17 + #include "standard-headers/linux/qemu_fw_cfg.h" 18 18 19 19 #include "qemu-common.h" 20 20