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

hw/i386/vmport: Define enum for all commands

No functional change.

Defining an enum for all VMPort commands have the following advantages:
* It gets rid of the error-prone requirement to update VMPORT_ENTRIES
when new VMPort commands are added to QEMU.
* It makes it clear to know by looking at one place at the source, what
are all the VMPort commands supported by QEMU.

Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200312165431.82118-9-liran.alon@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Liran Alon and committed by
Paolo Bonzini
dcd938f0 d8f23d61

+18 -22
+6 -12
hw/i386/vmmouse.c
··· 34 34 /* debug only vmmouse */ 35 35 //#define DEBUG_VMMOUSE 36 36 37 - /* VMMouse Commands */ 38 - #define VMMOUSE_GETVERSION 10 39 - #define VMMOUSE_DATA 39 40 - #define VMMOUSE_STATUS 40 41 - #define VMMOUSE_COMMAND 41 42 - 43 37 #define VMMOUSE_READ_ID 0x45414552 44 38 #define VMMOUSE_DISABLE 0x000000f5 45 39 #define VMMOUSE_REQUEST_RELATIVE 0x4c455252 ··· 217 211 command = data[2] & 0xFFFF; 218 212 219 213 switch (command) { 220 - case VMMOUSE_STATUS: 214 + case VMPORT_CMD_VMMOUSE_STATUS: 221 215 data[0] = vmmouse_get_status(s); 222 216 break; 223 - case VMMOUSE_COMMAND: 217 + case VMPORT_CMD_VMMOUSE_COMMAND: 224 218 switch (data[1]) { 225 219 case VMMOUSE_DISABLE: 226 220 vmmouse_disable(s); ··· 239 233 break; 240 234 } 241 235 break; 242 - case VMMOUSE_DATA: 236 + case VMPORT_CMD_VMMOUSE_DATA: 243 237 vmmouse_data(s, data, data[1]); 244 238 break; 245 239 default: ··· 296 290 return; 297 291 } 298 292 299 - vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s); 300 - vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s); 301 - vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s); 293 + vmport_register(VMPORT_CMD_VMMOUSE_STATUS, vmmouse_ioport_read, s); 294 + vmport_register(VMPORT_CMD_VMMOUSE_COMMAND, vmmouse_ioport_read, s); 295 + vmport_register(VMPORT_CMD_VMMOUSE_DATA, vmmouse_ioport_read, s); 302 296 } 303 297 304 298 static Property vmmouse_properties[] = {
+2 -9
hw/i386/vmport.c
··· 37 37 #include "cpu.h" 38 38 #include "trace.h" 39 39 40 - #define VMPORT_CMD_GETVERSION 0x0a 41 - #define VMPORT_CMD_GETRAMSIZE 0x14 42 - 43 - #define VMPORT_ENTRIES 0x2c 44 40 #define VMPORT_MAGIC 0x564D5868 45 41 46 42 /* Compatibility flags for migration */ ··· 71 67 72 68 static VMPortState *port_state; 73 69 74 - void vmport_register(unsigned char command, VMPortReadFunc *func, void *opaque) 70 + void vmport_register(VMPortCommand command, VMPortReadFunc *func, void *opaque) 75 71 { 76 - if (command >= VMPORT_ENTRIES) { 77 - return; 78 - } 79 - 72 + assert(command < VMPORT_ENTRIES); 80 73 trace_vmport_register(command, func, opaque); 81 74 port_state->func[command] = func; 82 75 port_state->opaque[command] = opaque;
+10 -1
include/hw/i386/vmport.h
··· 6 6 #define TYPE_VMPORT "vmport" 7 7 typedef uint32_t (VMPortReadFunc)(void *opaque, uint32_t address); 8 8 9 + typedef enum { 10 + VMPORT_CMD_GETVERSION = 10, 11 + VMPORT_CMD_GETRAMSIZE = 20, 12 + VMPORT_CMD_VMMOUSE_DATA = 39, 13 + VMPORT_CMD_VMMOUSE_STATUS = 40, 14 + VMPORT_CMD_VMMOUSE_COMMAND = 41, 15 + VMPORT_ENTRIES 16 + } VMPortCommand; 17 + 9 18 static inline void vmport_init(ISABus *bus) 10 19 { 11 20 isa_create_simple(bus, TYPE_VMPORT); 12 21 } 13 22 14 - void vmport_register(unsigned char command, VMPortReadFunc *func, void *opaque); 23 + void vmport_register(VMPortCommand command, VMPortReadFunc *func, void *opaque); 15 24 16 25 #endif