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

hw/i386/pc: Extract the port92 device

This device is only used by the PC machines. The pc.c file is
already big enough, with 2255 lines. By removing 113 lines of
it, we reduced it by 5%. It is now a bit easier to navigate
the file.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Philippe Mathieu-Daudé and committed by
Paolo Bonzini
d3e07dc8 1820b70e

+131 -114
+1
hw/i386/Makefile.objs
··· 13 13 obj-$(CONFIG_XEN) += ../xenpv/ xen/ 14 14 obj-$(CONFIG_VMPORT) += vmport.o 15 15 obj-$(CONFIG_VMMOUSE) += vmmouse.o 16 + obj-$(CONFIG_PC) += port92.o 16 17 17 18 obj-y += kvmvapic.o 18 19 obj-$(CONFIG_PC) += acpi-build.o
-113
hw/i386/pc.c
··· 673 673 qemu_register_reset(pc_cmos_init_late, &arg); 674 674 } 675 675 676 - #define TYPE_PORT92 "port92" 677 - #define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) 678 - 679 - /* port 92 stuff: could be split off */ 680 - typedef struct Port92State { 681 - ISADevice parent_obj; 682 - 683 - MemoryRegion io; 684 - uint8_t outport; 685 - qemu_irq a20_out; 686 - } Port92State; 687 - 688 - static void port92_write(void *opaque, hwaddr addr, uint64_t val, 689 - unsigned size) 690 - { 691 - Port92State *s = opaque; 692 - int oldval = s->outport; 693 - 694 - trace_port92_write(val); 695 - s->outport = val; 696 - qemu_set_irq(s->a20_out, (val >> 1) & 1); 697 - if ((val & 1) && !(oldval & 1)) { 698 - qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); 699 - } 700 - } 701 - 702 - static uint64_t port92_read(void *opaque, hwaddr addr, 703 - unsigned size) 704 - { 705 - Port92State *s = opaque; 706 - uint32_t ret; 707 - 708 - ret = s->outport; 709 - trace_port92_read(ret); 710 - return ret; 711 - } 712 - 713 - static const VMStateDescription vmstate_port92_isa = { 714 - .name = "port92", 715 - .version_id = 1, 716 - .minimum_version_id = 1, 717 - .fields = (VMStateField[]) { 718 - VMSTATE_UINT8(outport, Port92State), 719 - VMSTATE_END_OF_LIST() 720 - } 721 - }; 722 - 723 - static void port92_reset(DeviceState *d) 724 - { 725 - Port92State *s = PORT92(d); 726 - 727 - s->outport &= ~1; 728 - } 729 - 730 - static const MemoryRegionOps port92_ops = { 731 - .read = port92_read, 732 - .write = port92_write, 733 - .impl = { 734 - .min_access_size = 1, 735 - .max_access_size = 1, 736 - }, 737 - .endianness = DEVICE_LITTLE_ENDIAN, 738 - }; 739 - 740 - static void port92_initfn(Object *obj) 741 - { 742 - Port92State *s = PORT92(obj); 743 - 744 - memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); 745 - 746 - s->outport = 0; 747 - 748 - qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); 749 - } 750 - 751 - static void port92_realizefn(DeviceState *dev, Error **errp) 752 - { 753 - ISADevice *isadev = ISA_DEVICE(dev); 754 - Port92State *s = PORT92(dev); 755 - 756 - isa_register_ioport(isadev, &s->io, 0x92); 757 - } 758 - 759 - static void port92_class_initfn(ObjectClass *klass, void *data) 760 - { 761 - DeviceClass *dc = DEVICE_CLASS(klass); 762 - 763 - dc->realize = port92_realizefn; 764 - dc->reset = port92_reset; 765 - dc->vmsd = &vmstate_port92_isa; 766 - /* 767 - * Reason: unlike ordinary ISA devices, this one needs additional 768 - * wiring: its A20 output line needs to be wired up with 769 - * qdev_connect_gpio_out_named(). 770 - */ 771 - dc->user_creatable = false; 772 - } 773 - 774 - static const TypeInfo port92_info = { 775 - .name = TYPE_PORT92, 776 - .parent = TYPE_ISA_DEVICE, 777 - .instance_size = sizeof(Port92State), 778 - .instance_init = port92_initfn, 779 - .class_init = port92_class_initfn, 780 - }; 781 - 782 - static void port92_register_types(void) 783 - { 784 - type_register_static(&port92_info); 785 - } 786 - 787 - type_init(port92_register_types) 788 - 789 676 static void handle_a20_line_change(void *opaque, int irq, int level) 790 677 { 791 678 X86CPU *cpu = opaque;
+126
hw/i386/port92.c
··· 1 + /* 2 + * QEMU I/O port 0x92 (System Control Port A, to handle Fast Gate A20) 3 + * 4 + * Copyright (c) 2003-2004 Fabrice Bellard 5 + * 6 + * SPDX-License-Identifier: MIT 7 + */ 8 + 9 + #include "qemu/osdep.h" 10 + #include "sysemu/runstate.h" 11 + #include "migration/vmstate.h" 12 + #include "hw/irq.h" 13 + #include "hw/i386/pc.h" 14 + #include "trace.h" 15 + 16 + #define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) 17 + 18 + typedef struct Port92State { 19 + ISADevice parent_obj; 20 + 21 + MemoryRegion io; 22 + uint8_t outport; 23 + qemu_irq a20_out; 24 + } Port92State; 25 + 26 + static void port92_write(void *opaque, hwaddr addr, uint64_t val, 27 + unsigned size) 28 + { 29 + Port92State *s = opaque; 30 + int oldval = s->outport; 31 + 32 + trace_port92_write(val); 33 + s->outport = val; 34 + qemu_set_irq(s->a20_out, (val >> 1) & 1); 35 + if ((val & 1) && !(oldval & 1)) { 36 + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); 37 + } 38 + } 39 + 40 + static uint64_t port92_read(void *opaque, hwaddr addr, 41 + unsigned size) 42 + { 43 + Port92State *s = opaque; 44 + uint32_t ret; 45 + 46 + ret = s->outport; 47 + trace_port92_read(ret); 48 + 49 + return ret; 50 + } 51 + 52 + static const VMStateDescription vmstate_port92_isa = { 53 + .name = "port92", 54 + .version_id = 1, 55 + .minimum_version_id = 1, 56 + .fields = (VMStateField[]) { 57 + VMSTATE_UINT8(outport, Port92State), 58 + VMSTATE_END_OF_LIST() 59 + } 60 + }; 61 + 62 + static void port92_reset(DeviceState *d) 63 + { 64 + Port92State *s = PORT92(d); 65 + 66 + s->outport &= ~1; 67 + } 68 + 69 + static const MemoryRegionOps port92_ops = { 70 + .read = port92_read, 71 + .write = port92_write, 72 + .impl = { 73 + .min_access_size = 1, 74 + .max_access_size = 1, 75 + }, 76 + .endianness = DEVICE_LITTLE_ENDIAN, 77 + }; 78 + 79 + static void port92_initfn(Object *obj) 80 + { 81 + Port92State *s = PORT92(obj); 82 + 83 + memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); 84 + 85 + s->outport = 0; 86 + 87 + qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); 88 + } 89 + 90 + static void port92_realizefn(DeviceState *dev, Error **errp) 91 + { 92 + ISADevice *isadev = ISA_DEVICE(dev); 93 + Port92State *s = PORT92(dev); 94 + 95 + isa_register_ioport(isadev, &s->io, 0x92); 96 + } 97 + 98 + static void port92_class_initfn(ObjectClass *klass, void *data) 99 + { 100 + DeviceClass *dc = DEVICE_CLASS(klass); 101 + 102 + dc->realize = port92_realizefn; 103 + dc->reset = port92_reset; 104 + dc->vmsd = &vmstate_port92_isa; 105 + /* 106 + * Reason: unlike ordinary ISA devices, this one needs additional 107 + * wiring: its A20 output line needs to be wired up with 108 + * qdev_connect_gpio_out_named(). 109 + */ 110 + dc->user_creatable = false; 111 + } 112 + 113 + static const TypeInfo port92_info = { 114 + .name = TYPE_PORT92, 115 + .parent = TYPE_ISA_DEVICE, 116 + .instance_size = sizeof(Port92State), 117 + .instance_init = port92_initfn, 118 + .class_init = port92_class_initfn, 119 + }; 120 + 121 + static void port92_register_types(void) 122 + { 123 + type_register_static(&port92_info); 124 + } 125 + 126 + type_init(port92_register_types)
+1 -1
hw/i386/trace-events
··· 116 116 x86_gsi_interrupt(int irqn, int level) "GSI interrupt #%d level:%d" 117 117 x86_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" 118 118 119 - # pc.c 119 + # port92.c 120 120 port92_read(uint8_t val) "port92: read 0x%02x" 121 121 port92_write(uint8_t val) "port92: write 0x%02x"
+3
include/hw/i386/pc.h
··· 196 196 ISADevice *pc_find_fdc0(void); 197 197 int cmos_get_fd_drive_type(FloppyDriveType fd0); 198 198 199 + /* port92.c */ 199 200 #define PORT92_A20_LINE "a20" 201 + 202 + #define TYPE_PORT92 "port92" 200 203 201 204 /* pc_sysfw.c */ 202 205 void pc_system_flash_create(PCMachineState *pcms);