summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--MAINTAINERS174
-rw-r--r--Makefile5
-rw-r--r--Makefile.objs11
-rw-r--r--arch_init.c8
-rw-r--r--block.c49
-rw-r--r--block/iscsi.c4
-rw-r--r--block/qcow2-refcount.c25
-rw-r--r--blockdev-nbd.c2
-rw-r--r--blockdev.c3
-rwxr-xr-xconfigure262
-rw-r--r--default-configs/alpha-softmmu.mak1
-rw-r--r--default-configs/arm-softmmu.mak30
-rw-r--r--default-configs/cris-softmmu.mak1
-rw-r--r--default-configs/i386-softmmu.mak19
-rw-r--r--default-configs/lm32-softmmu.mak3
-rw-r--r--default-configs/m68k-softmmu.mak1
-rw-r--r--default-configs/microblaze-softmmu.mak2
-rw-r--r--default-configs/microblazeel-softmmu.mak2
-rw-r--r--default-configs/mips-softmmu.mak4
-rw-r--r--default-configs/mips64-softmmu.mak4
-rw-r--r--default-configs/mips64el-softmmu.mak4
-rw-r--r--default-configs/mipsel-softmmu.mak4
-rw-r--r--default-configs/moxie-softmmu.mak4
-rw-r--r--default-configs/pci.mak1
-rw-r--r--default-configs/ppc-softmmu.mak6
-rw-r--r--default-configs/ppc64-softmmu.mak8
-rw-r--r--default-configs/ppcemb-softmmu.mak6
-rw-r--r--default-configs/s390x-softmmu.mak1
-rw-r--r--default-configs/sh4-softmmu.mak3
-rw-r--r--default-configs/sh4eb-softmmu.mak3
-rw-r--r--default-configs/sparc-softmmu.mak8
-rw-r--r--default-configs/sparc64-softmmu.mak2
-rw-r--r--default-configs/x86_64-softmmu.mak19
-rw-r--r--docs/usb2.txt20
-rw-r--r--exec.c2
-rw-r--r--gdbstub.c2
-rw-r--r--hw/9pfs/virtio-9p-device.c6
-rw-r--r--hw/9pfs/virtio-9p-handle.c2
-rw-r--r--hw/9pfs/virtio-9p-local.c2
-rw-r--r--hw/9pfs/virtio-9p-posix-acl.c2
-rw-r--r--hw/9pfs/virtio-9p-proxy.c2
-rw-r--r--hw/9pfs/virtio-9p-synth.c2
-rw-r--r--hw/9pfs/virtio-9p-xattr-user.c2
-rw-r--r--hw/9pfs/virtio-9p-xattr.c2
-rw-r--r--hw/9pfs/virtio-9p.c4
-rw-r--r--hw/9pfs/virtio-9p.h2
-rw-r--r--hw/Makefile.objs250
-rw-r--r--hw/acpi/Makefile.objs2
-rw-r--r--hw/acpi/core.c (renamed from hw/acpi.c)4
-rw-r--r--hw/acpi/ich9.c (renamed from hw/acpi_ich9.c)6
-rw-r--r--hw/acpi/piix4.c (renamed from hw/acpi_piix4.c)10
-rw-r--r--hw/alpha/Makefile.objs7
-rw-r--r--hw/alpha/alpha_sys.h (renamed from hw/alpha_sys.h)2
-rw-r--r--hw/alpha/dp264.c8
-rw-r--r--hw/alpha/pci.c2
-rw-r--r--hw/alpha/typhoon.c (renamed from hw/alpha_typhoon.c)4
-rw-r--r--hw/arm/Makefile.objs31
-rw-r--r--hw/arm/armv7m.c2
-rw-r--r--hw/arm/boot.c2
-rw-r--r--hw/arm/collie.c8
-rw-r--r--hw/arm/exynos4210.c4
-rw-r--r--hw/arm/exynos4_boards.c4
-rw-r--r--hw/arm/gumstix.c6
-rw-r--r--hw/arm/highbank.c4
-rw-r--r--hw/arm/integratorcp.c4
-rw-r--r--hw/arm/kzm.c8
-rw-r--r--hw/arm/mainstone.c8
-rw-r--r--hw/arm/musicpal.c10
-rw-r--r--hw/arm/nseries.c28
-rw-r--r--hw/arm/omap1.c6
-rw-r--r--hw/arm/omap2.c8
-rw-r--r--hw/arm/omap_sx1.c6
-rw-r--r--hw/arm/palm.c6
-rw-r--r--hw/arm/pic_cpu.c2
-rw-r--r--hw/arm/pxa2xx.c6
-rw-r--r--hw/arm/pxa2xx_gpio.c2
-rw-r--r--hw/arm/pxa2xx_pic.c2
-rw-r--r--hw/arm/realview.c8
-rw-r--r--hw/arm/spitz.c12
-rw-r--r--hw/arm/stellaris.c6
-rw-r--r--hw/arm/strongarm.c (renamed from hw/strongarm.c)4
-rw-r--r--hw/arm/strongarm.h (renamed from hw/strongarm.h)0
-rw-r--r--hw/arm/tosa.c10
-rw-r--r--hw/arm/versatilepb.c8
-rw-r--r--hw/arm/vexpress.c8
-rw-r--r--hw/arm/xilinx_zynq.c7
-rw-r--r--hw/arm/z2.c10
-rw-r--r--hw/audio/Makefile.objs20
-rw-r--r--hw/audio/ac97.c (renamed from hw/ac97.c)2
-rw-r--r--hw/audio/adlib.c (renamed from hw/adlib.c)6
-rw-r--r--hw/audio/cs4231.c (renamed from hw/cs4231.c)0
-rw-r--r--hw/audio/cs4231a.c (renamed from hw/cs4231a.c)4
-rw-r--r--hw/audio/es1370.c (renamed from hw/es1370.c)2
-rw-r--r--hw/audio/fmopl.c (renamed from hw/fmopl.c)2
-rw-r--r--hw/audio/fmopl.h (renamed from hw/fmopl.h)0
-rw-r--r--hw/audio/gus.c (renamed from hw/gus.c)8
-rw-r--r--hw/audio/gusemu.h (renamed from hw/gusemu.h)0
-rw-r--r--hw/audio/gusemu_hal.c (renamed from hw/gusemu_hal.c)4
-rw-r--r--hw/audio/gusemu_mixer.c (renamed from hw/gusemu_mixer.c)4
-rw-r--r--hw/audio/gustate.h (renamed from hw/gustate.h)0
-rw-r--r--hw/audio/hda-codec.c (renamed from hw/hda-audio.c)4
-rw-r--r--hw/audio/intel-hda-defs.h (renamed from hw/intel-hda-defs.h)0
-rw-r--r--hw/audio/intel-hda.c (renamed from hw/intel-hda.c)6
-rw-r--r--hw/audio/intel-hda.h (renamed from hw/intel-hda.h)0
-rw-r--r--hw/audio/lm4549.c (renamed from hw/lm4549.c)2
-rw-r--r--hw/audio/lm4549.h (renamed from hw/lm4549.h)0
-rw-r--r--hw/audio/marvell_88w8618.c (renamed from hw/marvell_88w8618_audio.c)2
-rw-r--r--hw/audio/milkymist-ac97.c (renamed from hw/milkymist-ac97.c)0
-rw-r--r--hw/audio/pcspk.c (renamed from hw/pcspk.c)8
-rw-r--r--hw/audio/pl041.c (renamed from hw/pl041.c)4
-rw-r--r--hw/audio/pl041.h (renamed from hw/pl041.h)0
-rw-r--r--hw/audio/pl041.hx (renamed from hw/pl041.hx)0
-rw-r--r--hw/audio/sb16.c (renamed from hw/sb16.c)4
-rw-r--r--hw/audio/wm8750.c (renamed from hw/wm8750.c)2
-rw-r--r--hw/block/Makefile.objs15
-rw-r--r--hw/block/block.c (renamed from hw/block-common.c)2
-rw-r--r--hw/block/cdrom.c (renamed from hw/cdrom.c)2
-rw-r--r--hw/block/dataplane/Makefile.objs1
-rw-r--r--hw/block/dataplane/ioq.c (renamed from hw/dataplane/ioq.c)0
-rw-r--r--hw/block/dataplane/ioq.h (renamed from hw/dataplane/ioq.h)0
-rw-r--r--hw/block/dataplane/virtio-blk.c (renamed from hw/dataplane/virtio-blk.c)6
-rw-r--r--hw/block/dataplane/virtio-blk.h (renamed from hw/dataplane/virtio-blk.h)2
-rw-r--r--hw/block/ecc.c (renamed from hw/ecc.c)2
-rw-r--r--hw/block/fdc.c (renamed from hw/fdc.c)4
-rw-r--r--hw/block/hd-geometry.c (renamed from hw/hd-geometry.c)2
-rw-r--r--hw/block/m25p80.c (renamed from hw/m25p80.c)2
-rw-r--r--hw/block/nand.c (renamed from hw/nand.c)3
-rw-r--r--hw/block/onenand.c (renamed from hw/onenand.c)5
-rw-r--r--hw/block/pc_sysfw.c (renamed from hw/pc_sysfw.c)4
-rw-r--r--hw/block/pflash_cfi01.c (renamed from hw/pflash_cfi01.c)32
-rw-r--r--hw/block/pflash_cfi02.c (renamed from hw/pflash_cfi02.c)2
-rw-r--r--hw/block/tc58128.c (renamed from hw/tc58128.c)2
-rw-r--r--hw/block/virtio-blk.c (renamed from hw/virtio-blk.c)11
-rw-r--r--hw/block/xen_blkif.h (renamed from hw/xen_blkif.h)0
-rw-r--r--hw/block/xen_disk.c (renamed from hw/xen_disk.c)80
-rw-r--r--hw/bt/Makefile.objs3
-rw-r--r--hw/bt/core.c (renamed from hw/bt.c)0
-rw-r--r--hw/bt/hci-csr.c (renamed from hw/bt-hci-csr.c)0
-rw-r--r--hw/bt/hci.c (renamed from hw/bt-hci.c)0
-rw-r--r--hw/bt/hid.c (renamed from hw/bt-hid.c)2
-rw-r--r--hw/bt/l2cap.c (renamed from hw/bt-l2cap.c)0
-rw-r--r--hw/bt/sdp.c (renamed from hw/bt-sdp.c)0
-rw-r--r--hw/char/Makefile.objs27
-rw-r--r--hw/char/cadence_uart.c (renamed from hw/cadence_uart.c)1
-rw-r--r--hw/char/debugcon.c (renamed from hw/debugcon.c)4
-rw-r--r--hw/char/escc.c (renamed from hw/escc.c)2
-rw-r--r--hw/char/etraxfs_ser.c (renamed from hw/etraxfs_ser.c)2
-rw-r--r--hw/char/exynos4210_uart.c (renamed from hw/exynos4210_uart.c)2
-rw-r--r--hw/char/grlib_apbuart.c (renamed from hw/grlib_apbuart.c)0
-rw-r--r--hw/char/imx_serial.c (renamed from hw/imx_serial.c)2
-rw-r--r--hw/char/ipack.c (renamed from hw/ipack.c)2
-rw-r--r--hw/char/ipack.h (renamed from hw/ipack.h)0
-rw-r--r--hw/char/ipoctal232.c (renamed from hw/ipoctal232.c)2
-rw-r--r--hw/char/lm32_juart.c (renamed from hw/lm32_juart.c)2
-rw-r--r--hw/char/lm32_uart.c (renamed from hw/lm32_uart.c)0
-rw-r--r--hw/char/mcf_uart.c (renamed from hw/mcf_uart.c)2
-rw-r--r--hw/char/milkymist-uart.c (renamed from hw/milkymist-uart.c)0
-rw-r--r--hw/char/omap_uart.c (renamed from hw/omap_uart.c)4
-rw-r--r--hw/char/parallel.c (renamed from hw/parallel.c)4
-rw-r--r--hw/char/pl011.c (renamed from hw/pl011.c)0
-rw-r--r--hw/char/sclpconsole.c (renamed from hw/s390x/sclpconsole.c)2
-rw-r--r--hw/char/serial-isa.c (renamed from hw/serial-isa.c)4
-rw-r--r--hw/char/serial-pci.c (renamed from hw/serial-pci.c)2
-rw-r--r--hw/char/serial.c (renamed from hw/serial.c)2
-rw-r--r--hw/char/sh_serial.c (renamed from hw/sh_serial.c)2
-rw-r--r--hw/char/spapr_vty.c (renamed from hw/spapr_vty.c)4
-rw-r--r--hw/char/tpci200.c (renamed from hw/tpci200.c)2
-rw-r--r--hw/char/virtio-console.c (renamed from hw/virtio-console.c)2
-rw-r--r--hw/char/virtio-serial-bus.c (renamed from hw/virtio-serial-bus.c)2
-rw-r--r--hw/char/xen_console.c (renamed from hw/xen_console.c)2
-rw-r--r--hw/char/xilinx_uartlite.c (renamed from hw/xilinx_uartlite.c)0
-rw-r--r--hw/core/Makefile.objs14
-rw-r--r--hw/core/empty_slot.c (renamed from hw/empty_slot.c)0
-rw-r--r--hw/core/irq.c (renamed from hw/irq.c)0
-rw-r--r--hw/core/loader.c (renamed from hw/loader.c)4
-rw-r--r--hw/core/null-machine.c (renamed from hw/null-machine.c)0
-rw-r--r--hw/core/ptimer.c (renamed from hw/ptimer.c)0
-rw-r--r--hw/core/qdev-addr.c (renamed from hw/qdev-addr.c)0
-rw-r--r--hw/core/qdev-properties-system.c (renamed from hw/qdev-properties-system.c)2
-rw-r--r--hw/core/qdev-properties.c (renamed from hw/qdev-properties.c)2
-rw-r--r--hw/core/qdev.c (renamed from hw/qdev.c)0
-rw-r--r--hw/core/stream.c (renamed from hw/stream.c)0
-rw-r--r--hw/core/sysbus.c (renamed from hw/sysbus.c)0
-rw-r--r--hw/core/uboot_image.h (renamed from hw/uboot_image.h)0
-rw-r--r--hw/cpu/Makefile.objs4
-rw-r--r--hw/cpu/a15mpcore.c (renamed from hw/a15mpcore.c)0
-rw-r--r--hw/cpu/a9mpcore.c (renamed from hw/a9mpcore.c)0
-rw-r--r--hw/cpu/arm11mpcore.c (renamed from hw/arm11mpcore.c)0
-rw-r--r--hw/cris/Makefile.objs10
-rw-r--r--hw/cris/axis_dev88.c6
-rw-r--r--hw/cris/boot.c2
-rw-r--r--hw/cris/boot.h (renamed from hw/cris-boot.h)0
-rw-r--r--hw/cris/pic_cpu.c2
-rw-r--r--hw/dataplane/Makefile.objs1
-rw-r--r--hw/display/Makefile.objs34
-rw-r--r--hw/display/ads7846.c (renamed from hw/ads7846.c)0
-rw-r--r--hw/display/blizzard.c (renamed from hw/blizzard.c)14
-rw-r--r--hw/display/blizzard_template.h (renamed from hw/blizzard_template.h)2
-rw-r--r--hw/display/cirrus_vga.c (renamed from hw/cirrus_vga.c)38
-rw-r--r--hw/display/cirrus_vga_rop.h (renamed from hw/cirrus_vga_rop.h)8
-rw-r--r--hw/display/cirrus_vga_rop2.h (renamed from hw/cirrus_vga_rop2.h)0
-rw-r--r--hw/display/cirrus_vga_template.h (renamed from hw/cirrus_vga_template.h)0
-rw-r--r--hw/display/exynos4210_fimd.c (renamed from hw/exynos4210_fimd.c)5
-rw-r--r--hw/display/framebuffer.c (renamed from hw/framebuffer.c)2
-rw-r--r--hw/display/framebuffer.h (renamed from hw/framebuffer.h)0
-rw-r--r--hw/display/g364fb.c (renamed from hw/g364fb.c)0
-rw-r--r--hw/display/jazz_led.c (renamed from hw/jazz_led.c)0
-rw-r--r--hw/display/milkymist-tmu2.c (renamed from hw/milkymist-tmu2.c)0
-rw-r--r--hw/display/milkymist-vgafb.c (renamed from hw/milkymist-vgafb.c)12
-rw-r--r--hw/display/milkymist-vgafb_template.h (renamed from hw/milkymist-vgafb_template.h)2
-rw-r--r--hw/display/omap_dss.c (renamed from hw/omap_dss.c)2
-rw-r--r--hw/display/omap_lcd_template.h (renamed from hw/omap_lcd_template.h)0
-rw-r--r--hw/display/omap_lcdc.c (renamed from hw/omap_lcdc.c)12
-rw-r--r--hw/display/pl110.c (renamed from hw/pl110.c)12
-rw-r--r--hw/display/pl110_template.h (renamed from hw/pl110_template.h)12
-rw-r--r--hw/display/pxa2xx_lcd.c (renamed from hw/pxa2xx_lcd.c)14
-rw-r--r--hw/display/pxa2xx_template.h (renamed from hw/pxa2xx_template.h)0
-rw-r--r--hw/display/qxl-logger.c (renamed from hw/qxl-logger.c)2
-rw-r--r--hw/display/qxl-render.c (renamed from hw/qxl-render.c)2
-rw-r--r--hw/display/qxl.c (renamed from hw/qxl.c)2
-rw-r--r--hw/display/qxl.h (renamed from hw/qxl.h)2
-rw-r--r--hw/display/sm501.c (renamed from hw/sm501.c)18
-rw-r--r--hw/display/sm501_template.h (renamed from hw/sm501_template.h)0
-rw-r--r--hw/display/ssd0303.c (renamed from hw/ssd0303.c)2
-rw-r--r--hw/display/ssd0323.c (renamed from hw/ssd0323.c)0
-rw-r--r--hw/display/tc6393xb.c (renamed from hw/tc6393xb.c)14
-rw-r--r--hw/display/tc6393xb_template.h (renamed from hw/tc6393xb_template.h)0
-rw-r--r--hw/display/tcx.c (renamed from hw/tcx.c)0
-rw-r--r--hw/display/vga-isa-mm.c (renamed from hw/vga-isa-mm.c)4
-rw-r--r--hw/display/vga-isa.c (renamed from hw/vga-isa.c)4
-rw-r--r--hw/display/vga-pci.c (renamed from hw/vga-pci.c)2
-rw-r--r--hw/display/vga.c (renamed from hw/vga.c)22
-rw-r--r--hw/display/vga.h (renamed from hw/vga.h)0
-rw-r--r--hw/display/vga_int.h (renamed from hw/vga_int.h)0
-rw-r--r--hw/display/vga_template.h (renamed from hw/vga_template.h)0
-rw-r--r--hw/display/vmware_vga.c (renamed from hw/vmware_vga.c)2
-rw-r--r--hw/display/xenfb.c (renamed from hw/xenfb.c)2
-rw-r--r--hw/dma/Makefile.objs13
-rw-r--r--hw/dma/etraxfs_dma.c (renamed from hw/etraxfs_dma.c)2
-rw-r--r--hw/dma/i82374.c (renamed from hw/i82374.c)2
-rw-r--r--hw/dma/i8257.c (renamed from hw/dma.c)2
-rw-r--r--hw/dma/omap_dma.c (renamed from hw/omap_dma.c)4
-rw-r--r--hw/dma/pl080.c (renamed from hw/pl080.c)0
-rw-r--r--hw/dma/pl330.c (renamed from hw/pl330.c)5
-rw-r--r--hw/dma/puv3_dma.c (renamed from hw/puv3_dma.c)2
-rw-r--r--hw/dma/pxa2xx_dma.c (renamed from hw/pxa2xx_dma.c)2
-rw-r--r--hw/dma/rc4030.c (renamed from hw/rc4030.c)2
-rw-r--r--hw/dma/soc_dma.c (renamed from hw/soc_dma.c)2
-rw-r--r--hw/dma/sparc32_dma.c (renamed from hw/sparc32_dma.c)4
-rw-r--r--hw/dma/sun4m_iommu.c (renamed from hw/sun4m_iommu.c)5
-rw-r--r--hw/dma/xilinx_axidma.c (renamed from hw/xilinx_axidma.c)0
-rw-r--r--hw/gpio/Makefile.objs6
-rw-r--r--hw/gpio/max7310.c (renamed from hw/max7310.c)2
-rw-r--r--hw/gpio/omap_gpio.c (renamed from hw/omap_gpio.c)2
-rw-r--r--hw/gpio/pl061.c (renamed from hw/pl061.c)0
-rw-r--r--hw/gpio/puv3_gpio.c (renamed from hw/puv3_gpio.c)2
-rw-r--r--hw/gpio/zaurus.c (renamed from hw/zaurus.c)2
-rw-r--r--hw/i2c/Makefile.objs7
-rw-r--r--hw/i2c/bitbang_i2c.c (renamed from hw/bitbang_i2c.c)2
-rw-r--r--hw/i2c/bitbang_i2c.h (renamed from hw/bitbang_i2c.h)2
-rw-r--r--hw/i2c/core.c (renamed from hw/i2c.c)2
-rw-r--r--hw/i2c/exynos4210_i2c.c (renamed from hw/exynos4210_i2c.c)2
-rw-r--r--hw/i2c/omap_i2c.c (renamed from hw/omap_i2c.c)4
-rw-r--r--hw/i2c/pm_smbus.c (renamed from hw/pm_smbus.c)6
-rw-r--r--hw/i2c/smbus.c (renamed from hw/smbus.c)4
-rw-r--r--hw/i2c/smbus_eeprom.c (renamed from hw/smbus_eeprom.c)4
-rw-r--r--hw/i2c/smbus_ich9.c (renamed from hw/smbus_ich9.c)10
-rw-r--r--hw/i2c/versatile_i2c.c (renamed from hw/versatile_i2c.c)2
-rw-r--r--hw/i386/Makefile.objs18
-rw-r--r--hw/i386/kvm/Makefile.objs1
-rw-r--r--hw/i386/kvm/apic.c (renamed from hw/kvm/apic.c)2
-rw-r--r--hw/i386/kvm/clock.c (renamed from hw/kvm/clock.c)0
-rw-r--r--hw/i386/kvm/i8254.c (renamed from hw/kvm/i8254.c)4
-rw-r--r--hw/i386/kvm/i8259.c (renamed from hw/kvm/i8259.c)4
-rw-r--r--hw/i386/kvm/ioapic.c (renamed from hw/kvm/ioapic.c)6
-rw-r--r--hw/i386/kvm/pci-assign.c (renamed from hw/kvm/pci-assign.c)2
-rw-r--r--hw/i386/kvmvapic.c2
-rw-r--r--hw/i386/multiboot.c4
-rw-r--r--hw/i386/multiboot.h (renamed from hw/multiboot.h)0
-rw-r--r--hw/i386/pc.c26
-rw-r--r--hw/i386/pc_piix.c8
-rw-r--r--hw/i386/pc_q35.c10
-rw-r--r--hw/i386/smbios.c2
-rw-r--r--hw/i386/xen_domainbuild.c4
-rw-r--r--hw/i386/xen_domainbuild.h (renamed from hw/xen_domainbuild.h)2
-rw-r--r--hw/i386/xen_machine_pv.c6
-rw-r--r--hw/ide/Makefile.objs2
-rw-r--r--hw/ide/ahci.c2
-rw-r--r--hw/ide/atapi.c2
-rw-r--r--hw/ide/cmd646.c4
-rw-r--r--hw/ide/core.c6
-rw-r--r--hw/ide/ich.c4
-rw-r--r--hw/ide/internal.h6
-rw-r--r--hw/ide/isa.c4
-rw-r--r--hw/ide/macio.c2
-rw-r--r--hw/ide/microdrive.c2
-rw-r--r--hw/ide/pci.c4
-rw-r--r--hw/ide/piix.c4
-rw-r--r--hw/ide/qdev.c2
-rw-r--r--hw/ide/via.c4
-rw-r--r--hw/input/Makefile.objs13
-rw-r--r--hw/input/adb.c (renamed from hw/adb.c)2
-rw-r--r--hw/input/hid.c (renamed from hw/hid.c)2
-rw-r--r--hw/input/lm832x.c (renamed from hw/lm832x.c)2
-rw-r--r--hw/input/milkymist-softusb.c (renamed from hw/milkymist-softusb.c)2
-rw-r--r--hw/input/pckbd.c (renamed from hw/pckbd.c)6
-rw-r--r--hw/input/pl050.c (renamed from hw/pl050.c)7
-rw-r--r--hw/input/ps2.c (renamed from hw/ps2.c)2
-rw-r--r--hw/input/pxa2xx_keypad.c (renamed from hw/pxa2xx_keypad.c)2
-rw-r--r--hw/input/stellaris_input.c (renamed from hw/stellaris_input.c)2
-rw-r--r--hw/input/tsc2005.c (renamed from hw/tsc2005.c)2
-rw-r--r--hw/input/tsc210x.c (renamed from hw/tsc210x.c)4
-rw-r--r--hw/input/vmmouse.c (renamed from hw/vmmouse.c)4
-rw-r--r--hw/intc/Makefile.objs23
-rw-r--r--hw/intc/apic.c (renamed from hw/apic.c)10
-rw-r--r--hw/intc/apic_common.c (renamed from hw/apic_common.c)4
-rw-r--r--hw/intc/arm_gic.c (renamed from hw/arm_gic.c)2
-rw-r--r--hw/intc/arm_gic_common.c (renamed from hw/arm_gic_common.c)114
-rw-r--r--hw/intc/arm_gic_kvm.c (renamed from hw/kvm/arm_gic.c)2
-rw-r--r--hw/intc/armv7m_nvic.c (renamed from hw/armv7m_nvic.c)8
-rw-r--r--hw/intc/etraxfs_pic.c (renamed from hw/etraxfs_pic.c)0
-rw-r--r--hw/intc/exynos4210_combiner.c (renamed from hw/exynos4210_combiner.c)2
-rw-r--r--hw/intc/exynos4210_gic.c (renamed from hw/exynos4210_gic.c)2
-rw-r--r--hw/intc/gic_internal.h (renamed from hw/arm_gic_internal.h)42
-rw-r--r--hw/intc/grlib_irqmp.c (renamed from hw/grlib_irqmp.c)2
-rw-r--r--hw/intc/heathrow_pic.c (renamed from hw/heathrow_pic.c)0
-rw-r--r--hw/intc/i8259.c (renamed from hw/i8259.c)6
-rw-r--r--hw/intc/i8259_common.c (renamed from hw/i8259_common.c)4
-rw-r--r--hw/intc/imx_avic.c (renamed from hw/imx_avic.c)0
-rw-r--r--hw/intc/ioapic.c (renamed from hw/ioapic.c)7
-rw-r--r--hw/intc/ioapic_common.c (renamed from hw/ioapic_common.c)4
-rw-r--r--hw/intc/lm32_pic.c (renamed from hw/lm32_pic.c)4
-rw-r--r--hw/intc/omap_intc.c (renamed from hw/omap_intc.c)2
-rw-r--r--hw/intc/openpic.c (renamed from hw/openpic.c)4
-rw-r--r--hw/intc/pl190.c (renamed from hw/pl190.c)0
-rw-r--r--hw/intc/puv3_intc.c (renamed from hw/puv3_intc.c)2
-rw-r--r--hw/intc/realview_gic.c (renamed from hw/realview_gic.c)0
-rw-r--r--hw/intc/sbi.c (renamed from hw/sbi.c)0
-rw-r--r--hw/intc/sh_intc.c (renamed from hw/sh_intc.c)4
-rw-r--r--hw/intc/slavio_intctl.c (renamed from hw/slavio_intctl.c)2
-rw-r--r--hw/intc/sun4c_intctl.c (renamed from hw/sun4c_intctl.c)2
-rw-r--r--hw/intc/xilinx_intc.c (renamed from hw/xilinx_intc.c)0
-rw-r--r--hw/isa/Makefile.objs9
-rw-r--r--hw/isa/apm.c (renamed from hw/apm.c)2
-rw-r--r--hw/isa/i82378.c (renamed from hw/i82378.c)6
-rw-r--r--hw/isa/isa-bus.c (renamed from hw/isa-bus.c)2
-rw-r--r--hw/isa/isa_mmio.c (renamed from hw/isa_mmio.c)2
-rw-r--r--hw/isa/lpc_ich9.c (renamed from hw/lpc_ich9.c)15
-rw-r--r--hw/isa/pc87312.c (renamed from hw/pc87312.c)2
-rw-r--r--hw/isa/piix4.c (renamed from hw/piix4.c)4
-rw-r--r--hw/isa/vt82c686.c (renamed from hw/vt82c686.c)18
-rw-r--r--hw/kvm/Makefile.objs1
-rw-r--r--hw/lm32/Makefile.objs20
-rw-r--r--hw/lm32/lm32.h (renamed from hw/lm32.h)0
-rw-r--r--hw/lm32/lm32_boards.c8
-rw-r--r--hw/lm32/lm32_hwsetup.h (renamed from hw/lm32_hwsetup.h)0
-rw-r--r--hw/lm32/milkymist-hw.h (renamed from hw/milkymist-hw.h)0
-rw-r--r--hw/lm32/milkymist.c8
-rw-r--r--hw/m68k/Makefile.objs4
-rw-r--r--hw/m68k/an5206.c2
-rw-r--r--hw/m68k/mcf5206.c2
-rw-r--r--hw/m68k/mcf5208.c2
-rw-r--r--hw/m68k/mcf_intc.c2
-rw-r--r--hw/microblaze/Makefile.objs5
-rw-r--r--hw/microblaze/boot.c2
-rw-r--r--hw/microblaze/boot.h (renamed from hw/microblaze_boot.h)0
-rw-r--r--hw/microblaze/petalogix_ml605_mmu.c13
-rw-r--r--hw/microblaze/petalogix_s3adsp1800_mmu.c8
-rw-r--r--hw/microblaze/pic_cpu.c2
-rw-r--r--hw/microblaze/pic_cpu.h (renamed from hw/microblaze_pic_cpu.h)0
-rw-r--r--hw/mips/Makefile.objs6
-rw-r--r--hw/mips/addr.c2
-rw-r--r--hw/mips/cputimer.c2
-rw-r--r--hw/mips/gt64xxx_pci.c (renamed from hw/gt64xxx.c)4
-rw-r--r--hw/mips/mips_fulong2e.c22
-rw-r--r--hw/mips/mips_int.c2
-rw-r--r--hw/mips/mips_jazz.c22
-rw-r--r--hw/mips/mips_malta.c20
-rw-r--r--hw/mips/mips_mipssim.c10
-rw-r--r--hw/mips/mips_r4k.c18
-rw-r--r--hw/misc/Makefile.objs40
-rw-r--r--hw/misc/a9scu.c (renamed from hw/a9scu.c)0
-rw-r--r--hw/misc/applesmc.c (renamed from hw/applesmc.c)2
-rw-r--r--hw/misc/arm_l2x0.c (renamed from hw/arm_l2x0.c)0
-rw-r--r--hw/misc/arm_sysctl.c (renamed from hw/arm_sysctl.c)2
-rw-r--r--hw/misc/cbus.c (renamed from hw/cbus.c)2
-rw-r--r--hw/misc/debugexit.c (renamed from hw/debugexit.c)2
-rw-r--r--hw/misc/eccmemctl.c (renamed from hw/eccmemctl.c)0
-rw-r--r--hw/misc/exynos4210_pmu.c (renamed from hw/exynos4210_pmu.c)0
-rw-r--r--hw/misc/imx_ccm.c (renamed from hw/imx_ccm.c)2
-rw-r--r--hw/misc/ivshmem.c (renamed from hw/ivshmem.c)2
-rw-r--r--hw/misc/lm32_sys.c (renamed from hw/lm32_sys.c)0
-rw-r--r--hw/misc/macio/Makefile.objs3
-rw-r--r--hw/misc/macio/cuda.c (renamed from hw/cuda.c)2
-rw-r--r--hw/misc/macio/mac_dbdma.c (renamed from hw/mac_dbdma.c)4
-rw-r--r--hw/misc/macio/macio.c (renamed from hw/macio.c)4
-rw-r--r--hw/misc/max111x.c (renamed from hw/max111x.c)0
-rw-r--r--hw/misc/milkymist-hpdmc.c (renamed from hw/milkymist-hpdmc.c)0
-rw-r--r--hw/misc/milkymist-pfpu.c (renamed from hw/milkymist-pfpu.c)0
-rw-r--r--hw/misc/mst_fpga.c (renamed from hw/mst_fpga.c)0
-rw-r--r--hw/misc/omap_clk.c (renamed from hw/omap_clk.c)2
-rw-r--r--hw/misc/omap_gpmc.c (renamed from hw/omap_gpmc.c)4
-rw-r--r--hw/misc/omap_l4.c (renamed from hw/omap_l4.c)2
-rw-r--r--hw/misc/omap_sdrc.c (renamed from hw/omap_sdrc.c)2
-rw-r--r--hw/misc/omap_tap.c (renamed from hw/omap_tap.c)2
-rw-r--r--hw/misc/pc-testdev.c (renamed from hw/pc-testdev.c)2
-rw-r--r--hw/misc/puv3_pm.c (renamed from hw/puv3_pm.c)2
-rw-r--r--hw/misc/pxa2xx_pcmcia.c (renamed from hw/pxa2xx_pcmcia.c)2
-rw-r--r--hw/misc/sga.c (renamed from hw/sga.c)2
-rw-r--r--hw/misc/slavio_misc.c (renamed from hw/slavio_misc.c)0
-rw-r--r--hw/misc/tmp105.c (renamed from hw/tmp105.c)4
-rw-r--r--hw/misc/tmp105.h (renamed from hw/tmp105.h)4
-rw-r--r--hw/misc/vfio.c (renamed from hw/vfio_pci.c)0
-rw-r--r--hw/misc/vmport.c (renamed from hw/vmport.c)4
-rw-r--r--hw/misc/zynq_slcr.c (renamed from hw/zynq_slcr.c)0
-rw-r--r--hw/moxie/Makefile.objs3
-rw-r--r--hw/moxie/moxiesim.c6
-rw-r--r--hw/net/Makefile.objs33
-rw-r--r--hw/net/cadence_gem.c (renamed from hw/cadence_gem.c)0
-rw-r--r--hw/net/dp8393x.c (renamed from hw/dp8393x.c)2
-rw-r--r--hw/net/e1000.c (renamed from hw/e1000.c)2
-rw-r--r--hw/net/e1000_regs.h (renamed from hw/e1000_hw.h)0
-rw-r--r--hw/net/eepro100.c (renamed from hw/eepro100.c)2
-rw-r--r--hw/net/etraxfs_eth.c (renamed from hw/etraxfs_eth.c)2
-rw-r--r--hw/net/lan9118.c (renamed from hw/lan9118.c)2
-rw-r--r--hw/net/lance.c (renamed from hw/lance.c)4
-rw-r--r--hw/net/mcf_fec.c (renamed from hw/mcf_fec.c)2
-rw-r--r--hw/net/milkymist-minimac2.c (renamed from hw/milkymist-minimac2.c)0
-rw-r--r--hw/net/mipsnet.c (renamed from hw/mipsnet.c)0
-rw-r--r--hw/net/ne2000-isa.c (renamed from hw/ne2000-isa.c)6
-rw-r--r--hw/net/ne2000.c (renamed from hw/ne2000.c)2
-rw-r--r--hw/net/ne2000.h (renamed from hw/ne2000.h)0
-rw-r--r--hw/net/opencores_eth.c (renamed from hw/opencores_eth.c)0
-rw-r--r--hw/net/pcnet-pci.c (renamed from hw/pcnet-pci.c)2
-rw-r--r--hw/net/pcnet.c (renamed from hw/pcnet.c)2
-rw-r--r--hw/net/pcnet.h (renamed from hw/pcnet.h)0
-rw-r--r--hw/net/rtl8139.c (renamed from hw/rtl8139.c)0
-rw-r--r--hw/net/smc91c111.c (renamed from hw/smc91c111.c)2
-rw-r--r--hw/net/spapr_llan.c (renamed from hw/spapr_llan.c)4
-rw-r--r--hw/net/stellaris_enet.c (renamed from hw/stellaris_enet.c)0
-rw-r--r--hw/net/vhost_net.c (renamed from hw/vhost_net.c)6
-rw-r--r--hw/net/virtio-net.c (renamed from hw/virtio-net.c)6
-rw-r--r--hw/net/vmware_utils.h (renamed from hw/vmware_utils.h)0
-rw-r--r--hw/net/vmxnet3.c (renamed from hw/vmxnet3.c)20
-rw-r--r--hw/net/vmxnet3.h (renamed from hw/vmxnet3.h)11
-rw-r--r--hw/net/vmxnet_debug.h (renamed from hw/vmxnet_debug.h)0
-rw-r--r--hw/net/vmxnet_rx_pkt.c (renamed from hw/vmxnet_rx_pkt.c)0
-rw-r--r--hw/net/vmxnet_rx_pkt.h (renamed from hw/vmxnet_rx_pkt.h)0
-rw-r--r--hw/net/vmxnet_tx_pkt.c (renamed from hw/vmxnet_tx_pkt.c)0
-rw-r--r--hw/net/vmxnet_tx_pkt.h (renamed from hw/vmxnet_tx_pkt.h)0
-rw-r--r--hw/net/xen_nic.c (renamed from hw/xen_nic.c)2
-rw-r--r--hw/net/xgmac.c (renamed from hw/xgmac.c)0
-rw-r--r--hw/net/xilinx_axienet.c (renamed from hw/xilinx_axienet.c)0
-rw-r--r--hw/net/xilinx_ethlite.c (renamed from hw/xilinx_ethlite.c)0
-rw-r--r--hw/nvram/Makefile.objs5
-rw-r--r--hw/nvram/ds1225y.c (renamed from hw/ds1225y.c)0
-rw-r--r--hw/nvram/eeprom93xx.c (renamed from hw/eeprom93xx.c)2
-rw-r--r--hw/nvram/fw_cfg.c (renamed from hw/fw_cfg.c)4
-rw-r--r--hw/nvram/mac_nvram.c (renamed from hw/mac_nvram.c)2
-rw-r--r--hw/nvram/spapr_nvram.c (renamed from hw/spapr_nvram.c)4
-rw-r--r--hw/openrisc/openrisc_sim.c2
-rw-r--r--hw/pci-bridge/Makefile.objs3
-rw-r--r--hw/pci-bridge/i82801b11.c (renamed from hw/i82801b11.c)2
-rw-r--r--hw/pci-bridge/ioh3420.c (renamed from hw/ioh3420.c)2
-rw-r--r--hw/pci-bridge/ioh3420.h (renamed from hw/ioh3420.h)0
-rw-r--r--hw/pci-bridge/pci_bridge_dev.c (renamed from hw/pci_bridge_dev.c)0
-rw-r--r--hw/pci-bridge/xio3130_downstream.c (renamed from hw/xio3130_downstream.c)2
-rw-r--r--hw/pci-bridge/xio3130_downstream.h (renamed from hw/xio3130_downstream.h)0
-rw-r--r--hw/pci-bridge/xio3130_upstream.c (renamed from hw/xio3130_upstream.c)2
-rw-r--r--hw/pci-bridge/xio3130_upstream.h (renamed from hw/xio3130_upstream.h)0
-rw-r--r--hw/pci-host/Makefile.objs18
-rw-r--r--hw/pci-host/apb.c (renamed from hw/apb_pci.c)10
-rw-r--r--hw/pci-host/bonito.c (renamed from hw/bonito.c)4
-rw-r--r--hw/pci-host/dec.c (renamed from hw/dec_pci.c)2
-rw-r--r--hw/pci-host/dec.h (renamed from hw/dec_pci.h)0
-rw-r--r--hw/pci-host/grackle.c (renamed from hw/grackle_pci.c)0
-rw-r--r--hw/pci-host/pam.c (renamed from hw/pam.c)2
-rw-r--r--hw/pci-host/piix.c (renamed from hw/piix_pci.c)8
-rw-r--r--hw/pci-host/ppce500.c (renamed from hw/ppce500_pci.c)2
-rw-r--r--hw/pci-host/prep.c (renamed from hw/prep_pci.c)2
-rw-r--r--hw/pci-host/q35.c (renamed from hw/q35.c)2
-rw-r--r--hw/pci-host/uninorth.c (renamed from hw/unin_pci.c)0
-rw-r--r--hw/pci-host/versatile.c (renamed from hw/versatile_pci.c)0
-rw-r--r--hw/pci/Makefile.objs4
-rw-r--r--hw/pci/pci-hotplug.c8
-rw-r--r--hw/ppc/Makefile.objs18
-rw-r--r--hw/ppc/e500.c8
-rw-r--r--hw/ppc/e500plat.c2
-rw-r--r--hw/ppc/mac.h2
-rw-r--r--hw/ppc/mac_newworld.c14
-rw-r--r--hw/ppc/mac_oldworld.c12
-rw-r--r--hw/ppc/mpc8544ds.c2
-rw-r--r--hw/ppc/ppc.c4
-rw-r--r--hw/ppc/ppc405.h (renamed from hw/ppc405.h)2
-rw-r--r--hw/ppc/ppc405_boards.c8
-rw-r--r--hw/ppc/ppc405_uc.c6
-rw-r--r--hw/ppc/ppc440_bamboo.c6
-rw-r--r--hw/ppc/ppc4xx_devs.c4
-rw-r--r--hw/ppc/ppc4xx_pci.c (renamed from hw/ppc4xx_pci.c)4
-rw-r--r--hw/ppc/ppc_booke.c4
-rw-r--r--hw/ppc/prep.c16
-rw-r--r--hw/ppc/spapr.c10
-rw-r--r--hw/ppc/spapr_events.c4
-rw-r--r--hw/ppc/spapr_hcall.c2
-rw-r--r--hw/ppc/spapr_iommu.c2
-rw-r--r--hw/ppc/spapr_pci.c (renamed from hw/spapr_pci.c)4
-rw-r--r--hw/ppc/spapr_rtas.c4
-rw-r--r--hw/ppc/spapr_vio.c6
-rw-r--r--hw/ppc/virtex_ml507.c12
-rw-r--r--hw/ppc/xics.c4
-rw-r--r--hw/s390x/Makefile.objs2
-rw-r--r--hw/s390x/s390-virtio-bus.c10
-rw-r--r--hw/s390x/s390-virtio-bus.h12
-rw-r--r--hw/s390x/s390-virtio.c2
-rw-r--r--hw/s390x/virtio-ccw.c8
-rw-r--r--hw/s390x/virtio-ccw.h14
-rw-r--r--hw/scsi/Makefile.objs8
-rw-r--r--hw/scsi/esp-pci.c (renamed from hw/esp-pci.c)4
-rw-r--r--hw/scsi/esp.c (renamed from hw/esp.c)2
-rw-r--r--hw/scsi/lsi53c895a.c (renamed from hw/lsi53c895a.c)2
-rw-r--r--hw/scsi/megasas.c (renamed from hw/megasas.c)6
-rw-r--r--hw/scsi/mfi.h (renamed from hw/mfi.h)0
-rw-r--r--hw/scsi/scsi-bus.c (renamed from hw/scsi-bus.c)12
-rw-r--r--hw/scsi/scsi-disk.c (renamed from hw/scsi-disk.c)6
-rw-r--r--hw/scsi/scsi-generic.c (renamed from hw/scsi-generic.c)4
-rw-r--r--hw/scsi/spapr_vscsi.c (renamed from hw/spapr_vscsi.c)12
-rw-r--r--hw/scsi/srp.h (renamed from hw/srp.h)0
-rw-r--r--hw/scsi/viosrp.h (renamed from hw/ppc-viosrp.h)0
-rw-r--r--hw/scsi/virtio-scsi.c (renamed from hw/virtio-scsi.c)8
-rw-r--r--hw/sd/Makefile.objs8
-rw-r--r--hw/sd/milkymist-memcard.c (renamed from hw/milkymist-memcard.c)0
-rw-r--r--hw/sd/omap_mmc.c (renamed from hw/omap_mmc.c)2
-rw-r--r--hw/sd/pl181.c (renamed from hw/pl181.c)0
-rw-r--r--hw/sd/pxa2xx_mmci.c (renamed from hw/pxa2xx_mmci.c)2
-rw-r--r--hw/sd/sd.c (renamed from hw/sd.c)2
-rw-r--r--hw/sd/sdhci.c (renamed from hw/sdhci.c)2
-rw-r--r--hw/sd/sdhci.h (renamed from hw/sdhci.h)0
-rw-r--r--hw/sd/ssi-sd.c (renamed from hw/ssi-sd.c)0
-rw-r--r--hw/sh4/Makefile.objs7
-rw-r--r--hw/sh4/r2d.c8
-rw-r--r--hw/sh4/sh7750.c8
-rw-r--r--hw/sh4/sh7750_regnames.c6
-rw-r--r--hw/sh4/sh7750_regnames.h (renamed from hw/sh7750_regnames.h)0
-rw-r--r--hw/sh4/sh7750_regs.h (renamed from hw/sh7750_regs.h)0
-rw-r--r--hw/sh4/sh_pci.c (renamed from hw/sh_pci.c)2
-rw-r--r--hw/sh4/shix.c2
-rw-r--r--hw/sparc/Makefile.objs9
-rw-r--r--hw/sparc/leon3.c2
-rw-r--r--hw/sparc/sun4m.c20
-rw-r--r--hw/sparc64/Makefile.objs5
-rw-r--r--hw/sparc64/sun4u.c14
-rw-r--r--hw/ssi/Makefile.objs6
-rw-r--r--hw/ssi/omap_spi.c (renamed from hw/omap_spi.c)2
-rw-r--r--hw/ssi/pl022.c (renamed from hw/pl022.c)0
-rw-r--r--hw/ssi/ssi.c (renamed from hw/ssi.c)0
-rw-r--r--hw/ssi/xilinx_spi.c (renamed from hw/xilinx_spi.c)0
-rw-r--r--hw/ssi/xilinx_spips.c (renamed from hw/xilinx_spips.c)0
-rw-r--r--hw/timer/Makefile.objs28
-rw-r--r--hw/timer/arm_mptimer.c (renamed from hw/arm_mptimer.c)5
-rw-r--r--hw/timer/arm_timer.c (renamed from hw/arm_timer.c)0
-rw-r--r--hw/timer/cadence_ttc.c (renamed from hw/cadence_ttc.c)0
-rw-r--r--hw/timer/ds1338.c (renamed from hw/ds1338.c)2
-rw-r--r--hw/timer/etraxfs_timer.c (renamed from hw/etraxfs_timer.c)0
-rw-r--r--hw/timer/exynos4210_mct.c (renamed from hw/exynos4210_mct.c)2
-rw-r--r--hw/timer/exynos4210_pwm.c (renamed from hw/exynos4210_pwm.c)2
-rw-r--r--hw/timer/exynos4210_rtc.c (renamed from hw/exynos4210_rtc.c)2
-rw-r--r--hw/timer/grlib_gptimer.c (renamed from hw/grlib_gptimer.c)0
-rw-r--r--hw/timer/hpet.c (renamed from hw/hpet.c)8
-rw-r--r--hw/timer/i8254.c (renamed from hw/i8254.c)8
-rw-r--r--hw/timer/i8254_common.c (renamed from hw/i8254_common.c)8
-rw-r--r--hw/timer/imx_timer.c (renamed from hw/imx_timer.c)2
-rw-r--r--hw/timer/lm32_timer.c (renamed from hw/lm32_timer.c)0
-rw-r--r--hw/timer/m48t59.c (renamed from hw/m48t59.c)4
-rw-r--r--hw/timer/mc146818rtc.c (renamed from hw/mc146818rtc.c)4
-rw-r--r--hw/timer/milkymist-sysctl.c (renamed from hw/milkymist-sysctl.c)0
-rw-r--r--hw/timer/omap_gptimer.c (renamed from hw/omap_gptimer.c)2
-rw-r--r--hw/timer/omap_synctimer.c (renamed from hw/omap_synctimer.c)2
-rw-r--r--hw/timer/pl031.c (renamed from hw/pl031.c)0
-rw-r--r--hw/timer/puv3_ost.c (renamed from hw/puv3_ost.c)2
-rw-r--r--hw/timer/pxa2xx_timer.c (renamed from hw/pxa2xx_timer.c)2
-rw-r--r--hw/timer/sh_timer.c (renamed from hw/sh_timer.c)2
-rw-r--r--hw/timer/slavio_timer.c (renamed from hw/slavio_timer.c)2
-rw-r--r--hw/timer/tusb6010.c (renamed from hw/tusb6010.c)4
-rw-r--r--hw/timer/twl92230.c (renamed from hw/twl92230.c)2
-rw-r--r--hw/timer/xilinx_timer.c (renamed from hw/xilinx_timer.c)0
-rw-r--r--hw/unicore32/puv3.c4
-rw-r--r--hw/usb/Makefile.objs8
-rw-r--r--hw/usb/bus.c2
-rw-r--r--hw/usb/ccid-card-emulated.c (renamed from hw/ccid-card-emulated.c)2
-rw-r--r--hw/usb/ccid-card-passthru.c (renamed from hw/ccid-card-passthru.c)2
-rw-r--r--hw/usb/ccid.h (renamed from hw/ccid.h)0
-rw-r--r--hw/usb/dev-audio.c2
-rw-r--r--hw/usb/dev-hid.c4
-rw-r--r--hw/usb/dev-hub.c12
-rw-r--r--hw/usb/dev-smartcard-reader.c2
-rw-r--r--hw/usb/dev-storage.c4
-rw-r--r--hw/usb/dev-uas.c4
-rw-r--r--hw/usb/hcd-xhci.c28
-rw-r--r--hw/usb/redirect.c37
-rw-r--r--hw/virtio/Makefile.objs7
-rw-r--r--hw/virtio/dataplane/Makefile.objs1
-rw-r--r--hw/virtio/dataplane/hostmem.c (renamed from hw/dataplane/hostmem.c)2
-rw-r--r--hw/virtio/dataplane/vring.c (renamed from hw/dataplane/vring.c)2
-rw-r--r--hw/virtio/vhost.c (renamed from hw/vhost.c)2
-rw-r--r--hw/virtio/virtio-balloon.c (renamed from hw/virtio-balloon.c)8
-rw-r--r--hw/virtio/virtio-bus.c (renamed from hw/virtio-bus.c)4
-rw-r--r--hw/virtio/virtio-pci.c (renamed from hw/virtio-pci.c)16
-rw-r--r--hw/virtio/virtio-pci.h (renamed from hw/virtio-pci.h)16
-rw-r--r--hw/virtio/virtio-rng.c (renamed from hw/virtio-rng.c)4
-rw-r--r--hw/virtio/virtio.c (renamed from hw/virtio.c)4
-rw-r--r--hw/watchdog/Makefile.objs3
-rw-r--r--hw/watchdog/watchdog.c (renamed from hw/watchdog.c)2
-rw-r--r--hw/watchdog/wdt_i6300esb.c (renamed from hw/wdt_i6300esb.c)2
-rw-r--r--hw/watchdog/wdt_ib700.c (renamed from hw/wdt_ib700.c)6
-rw-r--r--hw/xen/Makefile.objs6
-rw-r--r--hw/xen/xen-host-pci-device.c (renamed from hw/xen-host-pci-device.c)2
-rw-r--r--hw/xen/xen-host-pci-device.h (renamed from hw/xen-host-pci-device.h)0
-rw-r--r--hw/xen/xen_apic.c (renamed from hw/xen_apic.c)4
-rw-r--r--hw/xen/xen_backend.c (renamed from hw/xen_backend.c)17
-rw-r--r--hw/xen/xen_devconfig.c (renamed from hw/xen_devconfig.c)2
-rw-r--r--hw/xen/xen_platform.c (renamed from hw/xen_platform.c)6
-rw-r--r--hw/xen/xen_pt.c (renamed from hw/xen_pt.c)6
-rw-r--r--hw/xen/xen_pt.h (renamed from hw/xen_pt.h)4
-rw-r--r--hw/xen/xen_pt_config_init.c (renamed from hw/xen_pt_config_init.c)4
-rw-r--r--hw/xen/xen_pt_msi.c (renamed from hw/xen_pt_msi.c)6
-rw-r--r--hw/xtensa/xtensa_bootparam.h (renamed from hw/xtensa_bootparam.h)0
-rw-r--r--hw/xtensa/xtensa_lx60.c6
-rw-r--r--include/block/block_int.h3
-rw-r--r--include/block/scsi.h (renamed from hw/scsi-defs.h)0
-rw-r--r--include/exec/memory-internal.h2
-rw-r--r--include/hw/acpi/acpi.h (renamed from hw/acpi.h)0
-rw-r--r--include/hw/acpi/ich9.h (renamed from hw/acpi_ich9.h)2
-rw-r--r--include/hw/arm.h (renamed from hw/arm-misc.h)0
-rw-r--r--include/hw/arm/devices.h (renamed from hw/devices.h)0
-rw-r--r--include/hw/arm/exynos4210.h (renamed from hw/exynos4210.h)0
-rw-r--r--include/hw/arm/imx.h (renamed from hw/imx.h)0
-rw-r--r--include/hw/arm/omap.h (renamed from hw/omap.h)0
-rw-r--r--include/hw/arm/primecell.h (renamed from hw/primecell.h)0
-rw-r--r--include/hw/arm/pxa.h (renamed from hw/pxa.h)0
-rw-r--r--include/hw/arm/sharpsl.h (renamed from hw/sharpsl.h)0
-rw-r--r--include/hw/arm/soc_dma.h (renamed from hw/soc_dma.h)0
-rw-r--r--include/hw/audio/audio.h (renamed from hw/audiodev.h)0
-rw-r--r--include/hw/audio/pcspk.h (renamed from hw/pcspk.h)2
-rw-r--r--include/hw/block/block.h (renamed from hw/block-common.h)0
-rw-r--r--include/hw/block/fdc.h (renamed from hw/fdc.h)0
-rw-r--r--include/hw/block/flash.h (renamed from hw/flash.h)0
-rw-r--r--include/hw/boards.h (renamed from hw/boards.h)0
-rw-r--r--include/hw/bt.h (renamed from hw/bt.h)0
-rw-r--r--include/hw/char/escc.h (renamed from hw/escc.h)0
-rw-r--r--include/hw/char/serial.h (renamed from hw/serial.h)0
-rw-r--r--include/hw/cris/etraxfs.h (renamed from hw/etraxfs.h)2
-rw-r--r--include/hw/cris/etraxfs_dma.h (renamed from hw/etraxfs_dma.h)0
-rw-r--r--include/hw/elf_ops.h (renamed from hw/elf_ops.h)0
-rw-r--r--include/hw/empty_slot.h (renamed from hw/empty_slot.h)0
-rw-r--r--include/hw/hw.h (renamed from hw/hw.h)0
-rw-r--r--include/hw/i2c/i2c.h (renamed from hw/i2c.h)0
-rw-r--r--include/hw/i2c/pm_smbus.h (renamed from hw/pm_smbus.h)0
-rw-r--r--include/hw/i2c/smbus.h (renamed from hw/smbus.h)2
-rw-r--r--include/hw/i386/apic-msidef.h (renamed from hw/apic-msidef.h)0
-rw-r--r--include/hw/i386/apic.h (renamed from hw/apic.h)0
-rw-r--r--include/hw/i386/apic_internal.h (renamed from hw/apic_internal.h)0
-rw-r--r--include/hw/i386/ich9.h (renamed from hw/ich9.h)13
-rw-r--r--include/hw/i386/ioapic.h (renamed from hw/ioapic.h)0
-rw-r--r--include/hw/i386/ioapic_internal.h (renamed from hw/ioapic_internal.h)0
-rw-r--r--include/hw/i386/pc.h (renamed from hw/pc.h)6
-rw-r--r--include/hw/i386/smbios.h (renamed from hw/smbios.h)0
-rw-r--r--include/hw/ide.h (renamed from hw/ide.h)2
-rw-r--r--include/hw/input/adb.h (renamed from hw/adb.h)0
-rw-r--r--include/hw/input/hid.h (renamed from hw/hid.h)0
-rw-r--r--include/hw/input/ps2.h (renamed from hw/ps2.h)0
-rw-r--r--include/hw/irq.h (renamed from hw/irq.h)0
-rw-r--r--include/hw/isa/apm.h (renamed from hw/apm.h)0
-rw-r--r--include/hw/isa/i8259_internal.h (renamed from hw/i8259_internal.h)4
-rw-r--r--include/hw/isa/isa.h (renamed from hw/isa.h)0
-rw-r--r--include/hw/isa/pc87312.h (renamed from hw/pc87312.h)2
-rw-r--r--include/hw/isa/vt82c686.h (renamed from hw/vt82c686.h)0
-rw-r--r--include/hw/kvm/clock.h (renamed from hw/kvm/clock.h)0
-rw-r--r--include/hw/lm32/lm32_juart.h (renamed from hw/lm32_juart.h)0
-rw-r--r--include/hw/lm32/lm32_pic.h (renamed from hw/lm32_pic.h)0
-rw-r--r--include/hw/loader.h (renamed from hw/loader.h)0
-rw-r--r--include/hw/m68k/mcf.h (renamed from hw/mcf.h)0
-rw-r--r--include/hw/mips/bios.h (renamed from hw/mips-bios.h)0
-rw-r--r--include/hw/mips/cpudevs.h (renamed from hw/mips_cpudevs.h)0
-rw-r--r--include/hw/mips/mips.h (renamed from hw/mips.h)0
-rw-r--r--include/hw/misc/tmp105_regs.h (renamed from hw/tmp105_regs.h)0
-rw-r--r--include/hw/nvram/eeprom93xx.h (renamed from hw/eeprom93xx.h)0
-rw-r--r--include/hw/nvram/fw_cfg.h (renamed from hw/fw_cfg.h)0
-rw-r--r--include/hw/pci-host/apb.h (renamed from hw/apb_pci.h)0
-rw-r--r--include/hw/pci-host/pam.h (renamed from hw/pam.h)0
-rw-r--r--include/hw/pci-host/ppce500.h (renamed from hw/ppce500_pci.h)0
-rw-r--r--include/hw/pci-host/q35.h (renamed from hw/q35.h)13
-rw-r--r--include/hw/pci-host/spapr.h (renamed from hw/spapr_pci.h)2
-rw-r--r--include/hw/pci/msi.h (renamed from hw/pci/msi.h)0
-rw-r--r--include/hw/pci/msix.h (renamed from hw/pci/msix.h)0
-rw-r--r--include/hw/pci/pci.h (renamed from hw/pci/pci.h)2
-rw-r--r--include/hw/pci/pci_bridge.h (renamed from hw/pci/pci_bridge.h)0
-rw-r--r--include/hw/pci/pci_bus.h (renamed from hw/pci/pci_bus.h)0
-rw-r--r--include/hw/pci/pci_host.h (renamed from hw/pci/pci_host.h)0
-rw-r--r--include/hw/pci/pci_ids.h (renamed from hw/pci/pci_ids.h)0
-rw-r--r--include/hw/pci/pci_regs.h (renamed from hw/pci/pci_regs.h)0
-rw-r--r--include/hw/pci/pcie.h (renamed from hw/pci/pcie.h)0
-rw-r--r--include/hw/pci/pcie_aer.h (renamed from hw/pci/pcie_aer.h)0
-rw-r--r--include/hw/pci/pcie_host.h (renamed from hw/pci/pcie_host.h)0
-rw-r--r--include/hw/pci/pcie_port.h (renamed from hw/pci/pcie_port.h)0
-rw-r--r--include/hw/pci/pcie_regs.h (renamed from hw/pci/pcie_regs.h)0
-rw-r--r--include/hw/pci/shpc.h (renamed from hw/pci/shpc.h)0
-rw-r--r--include/hw/pci/slotid_cap.h (renamed from hw/pci/slotid_cap.h)0
-rw-r--r--include/hw/pcmcia.h (renamed from hw/pcmcia.h)0
-rw-r--r--include/hw/ppc/mac_dbdma.h (renamed from hw/mac_dbdma.h)0
-rw-r--r--include/hw/ppc/openpic.h (renamed from hw/openpic.h)0
-rw-r--r--include/hw/ppc/ppc.h (renamed from hw/ppc.h)0
-rw-r--r--include/hw/ppc/ppc4xx.h (renamed from hw/ppc4xx.h)0
-rw-r--r--include/hw/ppc/spapr.h (renamed from hw/spapr.h)2
-rw-r--r--include/hw/ppc/spapr_vio.h (renamed from hw/spapr_vio.h)0
-rw-r--r--include/hw/ppc/xics.h (renamed from hw/xics.h)0
-rw-r--r--include/hw/ptimer.h (renamed from hw/ptimer.h)0
-rw-r--r--include/hw/qdev-addr.h (renamed from hw/qdev-addr.h)0
-rw-r--r--include/hw/qdev-core.h (renamed from hw/qdev-core.h)0
-rw-r--r--include/hw/qdev-dma.h (renamed from hw/qdev-dma.h)0
-rw-r--r--include/hw/qdev-properties.h (renamed from hw/qdev-properties.h)0
-rw-r--r--include/hw/qdev.h (renamed from hw/qdev.h)0
-rw-r--r--include/hw/s390x/event-facility.h (renamed from hw/s390x/event-facility.h)0
-rw-r--r--include/hw/s390x/sclp.h (renamed from hw/s390x/sclp.h)0
-rw-r--r--include/hw/scsi/esp.h (renamed from hw/esp.h)2
-rw-r--r--include/hw/scsi/scsi.h (renamed from hw/scsi.h)5
-rw-r--r--include/hw/sd.h (renamed from hw/sd.h)0
-rw-r--r--include/hw/sh4/sh.h (renamed from hw/sh.h)2
-rw-r--r--include/hw/sh4/sh_intc.h (renamed from hw/sh_intc.h)0
-rw-r--r--include/hw/sparc/firmware_abi.h (renamed from hw/firmware_abi.h)0
-rw-r--r--include/hw/sparc/grlib.h (renamed from hw/grlib.h)0
-rw-r--r--include/hw/sparc/sparc32_dma.h (renamed from hw/sparc32_dma.h)0
-rw-r--r--include/hw/sparc/sun4m.h (renamed from hw/sun4m.h)4
-rw-r--r--include/hw/ssi.h (renamed from hw/ssi.h)0
-rw-r--r--include/hw/stream.h (renamed from hw/stream.h)0
-rw-r--r--include/hw/sysbus.h (renamed from hw/sysbus.h)0
-rw-r--r--include/hw/timer/hpet.h (renamed from hw/hpet_emul.h)0
-rw-r--r--include/hw/timer/i8254.h (renamed from hw/i8254.h)2
-rw-r--r--include/hw/timer/i8254_internal.h (renamed from hw/i8254_internal.h)4
-rw-r--r--include/hw/timer/m48t59.h (renamed from hw/nvram.h)0
-rw-r--r--include/hw/timer/mc146818rtc.h (renamed from hw/mc146818rtc.h)4
-rw-r--r--include/hw/timer/mc146818rtc_regs.h (renamed from hw/mc146818rtc_regs.h)0
-rw-r--r--include/hw/unicore32/puv3.h (renamed from hw/puv3.h)0
-rw-r--r--include/hw/usb.h (renamed from hw/usb.h)1
-rw-r--r--include/hw/virtio/dataplane/hostmem.h (renamed from hw/dataplane/hostmem.h)0
-rw-r--r--include/hw/virtio/dataplane/vring.h (renamed from hw/dataplane/vring.h)2
-rw-r--r--include/hw/virtio/vhost.h (renamed from hw/vhost.h)2
-rw-r--r--include/hw/virtio/virtio-9p.h (renamed from hw/9pfs/virtio-9p-device.h)0
-rw-r--r--include/hw/virtio/virtio-balloon.h (renamed from hw/virtio-balloon.h)2
-rw-r--r--include/hw/virtio/virtio-blk.h (renamed from hw/virtio-blk.h)11
-rw-r--r--include/hw/virtio/virtio-bus.h (renamed from hw/virtio-bus.h)2
-rw-r--r--include/hw/virtio/virtio-net.h (renamed from hw/virtio-net.h)2
-rw-r--r--include/hw/virtio/virtio-rng.h (renamed from hw/virtio-rng.h)0
-rw-r--r--include/hw/virtio/virtio-scsi.h (renamed from hw/virtio-scsi.h)4
-rw-r--r--include/hw/virtio/virtio-serial.h (renamed from hw/virtio-serial.h)2
-rw-r--r--include/hw/virtio/virtio.h (renamed from hw/virtio.h)2
-rw-r--r--include/hw/xen/xen.h (renamed from hw/xen.h)0
-rw-r--r--include/hw/xen/xen_backend.h (renamed from hw/xen_backend.h)4
-rw-r--r--include/hw/xen/xen_common.h (renamed from hw/xen_common.h)2
-rw-r--r--include/hw/xilinx.h (renamed from hw/xilinx.h)0
-rw-r--r--include/migration/vmstate.h36
-rw-r--r--include/net/vhost_net.h (renamed from hw/vhost_net.h)0
-rw-r--r--include/qapi/qmp/qstring.h1
-rw-r--r--include/sysemu/watchdog.h (renamed from hw/watchdog.h)0
-rw-r--r--linux-user/strace.c2
-rw-r--r--main-loop.c25
-rw-r--r--monitor.c68
-rw-r--r--net/tap.c2
-rw-r--r--pc-bios/optionrom/optionrom.h2
-rw-r--r--qemu-char.c135
-rw-r--r--qga/commands-win32.c56
-rw-r--r--qga/main.c8
-rw-r--r--qga/qapi-schema.json18
-rw-r--r--qobject/qstring.c8
-rw-r--r--target-arm/arm-semi.c2
-rw-r--r--target-arm/kvm.c2
-rw-r--r--target-i386/cpu.c4
-rw-r--r--target-i386/cpu.h2
-rw-r--r--target-i386/kvm.c4
-rw-r--r--target-i386/machine.c4
-rw-r--r--target-lm32/op_helper.c4
-rw-r--r--target-lm32/translate.c2
-rw-r--r--target-ppc/kvm.c6
-rw-r--r--target-s390x/translate.c1
-rw-r--r--target-sh4/helper.c2
-rw-r--r--tests/Makefile14
-rw-r--r--tests/rtc-test.c2
-rw-r--r--tests/test-visitor-serialization.c12
-rw-r--r--tests/tmp105-test.c2
-rw-r--r--tpm/tpm_passthrough.c2
-rw-r--r--tpm/tpm_tis.c2
-rw-r--r--tpm/tpm_tis.h2
-rw-r--r--trace-events1
-rw-r--r--vl.c12
-rw-r--r--xen-all.c6
-rw-r--r--xen-mapcache.c2
-rw-r--r--xen-stub.c2
796 files changed, 2286 insertions, 2016 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index db14ffc16c..4dfd8bf7ab 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -59,37 +59,45 @@ Alpha
 M: Richard Henderson <rth@twiddle.net>
 S: Maintained
 F: target-alpha/
+F: hw/alpha/
 
 ARM
 M: Paul Brook <paul@codesourcery.com>
 M: Peter Maydell <peter.maydell@linaro.org>
 S: Maintained
 F: target-arm/
+F: hw/arm/
+F: hw/cpu/a*mpcore.c
 
 CRIS
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
 S: Maintained
 F: target-cris/
+F: hw/cris/
 
 LM32
 M: Michael Walle <michael@walle.cc>
 S: Maintained
 F: target-lm32/
+F: hw/lm32/
 
 M68K
 M: Paul Brook <paul@codesourcery.com>
 S: Odd Fixes
 F: target-m68k/
+F: hw/m68k/
 
 MicroBlaze
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
 S: Maintained
 F: target-microblaze/
+F: hw/microblaze/
 
 MIPS
 M: Aurelien Jarno <aurelien@aurel32.net>
 S: Odd Fixes
 F: target-mips/
+F: hw/mips/
 
 Moxie
 M: Anthony Green <green@moxielogic.com>
@@ -101,38 +109,46 @@ M: Alexander Graf <agraf@suse.de>
 L: qemu-ppc@nongnu.org
 S: Maintained
 F: target-ppc/
+F: hw/ppc/
 
 S390
 M: Richard Henderson <rth@twiddle.net>
 M: Alexander Graf <agraf@suse.de>
 S: Maintained
 F: target-s390x/
+F: hw/s390x/
 
 SH4
 M: Aurelien Jarno <aurelien@aurel32.net>
 S: Odd Fixes
 F: target-sh4/
+F: hw/sh4/
 
 SPARC
 M: Blue Swirl <blauwirbel@gmail.com>
 S: Maintained
 F: target-sparc/
+F: hw/sparc/
+F: hw/sparc64/
 
 UniCore32
 M: Guan Xuetao <gxt@mprc.pku.edu.cn>
 S: Maintained
 F: target-unicore32/
+F: hw/unicore32/
 
 X86
 M: qemu-devel@nongnu.org
 S: Odd Fixes
 F: target-i386/
+F: hw/i386/
 
 Xtensa
 M: Max Filippov <jcmvbkbc@gmail.com>
 W: http://wiki.osll.spb.ru/doku.php?id=etc:users:jcmvbkbc:qemu-target-xtensa
 S: Maintained
 F: target-xtensa/
+F: hw/xtensa/
 
 Guest CPU Cores (KVM):
 ----------------------
@@ -205,156 +221,156 @@ M: Maksim Kozlov <m.kozlov@samsung.com>
 M: Igor Mitsyanko <i.mitsyanko@samsung.com>
 M: Dmitry Solodkiy <d.solodkiy@samsung.com>
 S: Maintained
-F: hw/exynos*
+F: hw/*/exynos*
 
 Calxeda Highbank
 M: Mark Langsdorf <mark.langsdorf@calxeda.com>
 S: Supported
-F: hw/highbank.c
-F: hw/xgmac.c
+F: hw/arm/highbank.c
+F: hw/net/xgmac.c
 
 Gumstix
 M: qemu-devel@nongnu.org
 S: Orphan
-F: hw/gumstix.c
+F: hw/arm/gumstix.c
 
 i.MX31
 M: Peter Chubb <peter.chubb@nicta.com.au>
 S: Odd fixes
-F: hw/imx*
-F: hw/kzm.c
+F: hw/*/imx*
+F: hw/arm/kzm.c
 
 Integrator CP
 M: Paul Brook <paul@codesourcery.com>
 M: Peter Maydell <peter.maydell@linaro.org>
 S: Maintained
-F: hw/integratorcp.c
+F: hw/arm/integratorcp.c
 
 Mainstone
 M: qemu-devel@nongnu.org
 S: Orphan
-F: hw/mainstone.c
+F: hw/arm/mainstone.c
 
 Musicpal
 M: Jan Kiszka <jan.kiszka@web.de>
 S: Maintained
-F: hw/musicpal.c
+F: hw/arm/musicpal.c
 
 nSeries
 M: Andrzej Zaborowski <balrogg@gmail.com>
 S: Maintained
-F: hw/nseries.c
+F: hw/arm/nseries.c
 
 Palm
 M: Andrzej Zaborowski <balrogg@gmail.com>
 S: Maintained
-F: hw/palm.c
+F: hw/arm/palm.c
 
 Real View
 M: Paul Brook <paul@codesourcery.com>
 M: Peter Maydell <peter.maydell@linaro.org>
 S: Maintained
-F: hw/realview*
+F: hw/arm/realview*
 
 Spitz
 M: Andrzej Zaborowski <balrogg@gmail.com>
 S: Maintained
-F: hw/spitz.c
+F: hw/arm/spitz.c
 
 Stellaris
 M: Paul Brook <paul@codesourcery.com>
 M: Peter Maydell <peter.maydell@linaro.org>
 S: Maintained
-F: hw/stellaris.c
+F: hw/*/stellaris*
 
 Versatile PB
 M: Paul Brook <paul@codesourcery.com>
 M: Peter Maydell <peter.maydell@linaro.org>
 S: Maintained
-F: hw/versatilepb.c
+F: hw/*/versatile*
 
 Xilinx Zynq
 M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
 S: Maintained
-F: hw/xilinx_zynq.c
-F: hw/zynq_slcr.c
-F: hw/cadence_*
-F: hw/xilinx_spips.c
+F: hw/arm/xilinx_zynq.c
+F: hw/misc/zynq_slcr.c
+F: hw/*/cadence_*
+F: hw/ssi/xilinx_spips.c
 
 CRIS Machines
 -------------
 Axis Dev88
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
 S: Maintained
-F: hw/axis_dev88.c
+F: hw/cris/axis_dev88.c
 
 etraxfs
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
 S: Maintained
-F: hw/etraxfs.c
+F: hw/cris/etraxfs.c
 
 LM32 Machines
 -------------
 EVR32 and uclinux BSP
 M: Michael Walle <michael@walle.cc>
 S: Maintained
-F: hw/lm32_boards.c
+F: hw/lm32/lm32_boards.c
 
 milkymist
 M: Michael Walle <michael@walle.cc>
 S: Maintained
-F: hw/milkymist.c
+F: hw/lm32/milkymist.c
 
 M68K Machines
 -------------
 an5206
 M: Paul Brook <paul@codesourcery.com>
 S: Maintained
-F: hw/an5206.c
+F: hw/m68k/an5206.c
 
 dummy_m68k
 M: Paul Brook <paul@codesourcery.com>
 S: Maintained
-F: hw/dummy_m68k.c
+F: hw/m68k/dummy_m68k.c
 
 mcf5208
 M: Paul Brook <paul@codesourcery.com>
 S: Maintained
-F: hw/mcf5208.c
+F: hw/m68k/mcf5208.c
 
 MicroBlaze Machines
 -------------------
 petalogix_s3adsp1800
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
 S: Maintained
-F: hw/petalogix_s3adsp1800.c
+F: hw/microblaze/petalogix_s3adsp1800.c
 
 petalogix_ml605
 M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
 S: Maintained
-F: hw/petalogix_ml605_mmu.c
+F: hw/microblaze/petalogix_ml605_mmu.c
 
 MIPS Machines
 -------------
 Jazz
 M: Hervé Poussineau <hpoussin@reactos.org>
 S: Maintained
-F: hw/mips_jazz.c
+F: hw/mips/mips_jazz.c
 
 Malta
 M: Aurelien Jarno <aurelien@aurel32.net>
 S: Maintained
-F: hw/mips_malta.c
+F: hw/mips/mips_malta.c
 
 Mipssim
 M: qemu-devel@nongnu.org
 S: Orphan
-F: hw/mips_mipssim.c
+F: hw/mips/mips_mipssim.c
 
 R4000
 M: Aurelien Jarno <aurelien@aurel32.net>
 S: Maintained
-F: hw/mips_r4k.c
+F: hw/mips/mips_r4k.c
 
 PowerPC Machines
 ----------------
@@ -362,13 +378,13 @@ PowerPC Machines
 M: Alexander Graf <agraf@suse.de>
 L: qemu-ppc@nongnu.org
 S: Odd Fixes
-F: hw/ppc405_boards.c
+F: hw/ppc/ppc405_boards.c
 
 Bamboo
 M: Alexander Graf <agraf@suse.de>
 L: qemu-ppc@nongnu.org
 S: Odd Fixes
-F: hw/ppc440_bamboo.c
+F: hw/ppc/ppc440_bamboo.c
 
 e500
 M: Alexander Graf <agraf@suse.de>
@@ -384,80 +400,82 @@ M: Scott Wood <scottwood@freescale.com>
 L: qemu-ppc@nongnu.org
 S: Supported
 F: hw/ppc/mpc8544ds.c
-F: hw/mpc8544_guts.c
+F: hw/ppc/mpc8544_guts.c
 
 New World
 M: Alexander Graf <agraf@suse.de>
 L: qemu-ppc@nongnu.org
 S: Maintained
 F: hw/ppc/mac_newworld.c
-F: hw/unin_pci.c
-F: hw/dec_pci.[hc]
+F: hw/pci/devices/host-uninorth.c
+F: hw/pci/devices/host-dec.[hc]
+F: hw/misc/macio/
 
 Old World
 M: Alexander Graf <agraf@suse.de>
 L: qemu-ppc@nongnu.org
 S: Maintained
 F: hw/ppc/mac_oldworld.c
-F: hw/grackle_pci.c
+F: hw/pci/devices/host-grackle.c
+F: hw/misc/macio/
 
 PReP
 M: Andreas Färber <andreas.faerber@web.de>
 L: qemu-ppc@nongnu.org
 S: Odd Fixes
 F: hw/ppc/prep.c
-F: hw/prep_pci.[hc]
-F: hw/pc87312.[hc]
+F: hw/pci/devices/host-prep.[hc]
+F: hw/isa/pc87312.[hc]
 
 sPAPR
 M: David Gibson <david@gibson.dropbear.id.au>
 M: Alexander Graf <agraf@suse.de>
 L: qemu-ppc@nongnu.org
 S: Supported
-F: hw/spapr*
+F: hw/*/spapr*
 
 virtex_ml507
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
 L: qemu-ppc@nongnu.org
 S: Odd Fixes
-F: hw/virtex_ml507.c
+F: hw/pci/virtex_ml507.c
 
 SH4 Machines
 ------------
 R2D
 M: Magnus Damm <magnus.damm@gmail.com>
 S: Maintained
-F: hw/r2d.c
+F: hw/sh/r2d.c
 
 Shix
 M: Magnus Damm <magnus.damm@gmail.com>
 S: Orphan
-F: hw/shix.c
+F: hw/sh/shix.c
 
 SPARC Machines
 --------------
 Sun4m
 M: Blue Swirl <blauwirbel@gmail.com>
 S: Maintained
-F: hw/sun4m.c
+F: hw/sparc/sun4m.c
 
 Sun4u
 M: Blue Swirl <blauwirbel@gmail.com>
 S: Maintained
-F: hw/sun4u.c
+F: hw/sparc64/sun4u.c
 
 Leon3
 M: Fabien Chouteau <chouteau@adacore.com>
 S: Maintained
-F: hw/leon3.c
-F: hw/grlib*
+F: hw/sparc/leon3.c
+F: hw/*/grlib*
 
 S390 Machines
 -------------
 S390 Virtio
 M: Alexander Graf <agraf@suse.de>
 S: Maintained
-F: hw/s390-*.c
+F: hw/s390/s390-*.c
 
 S390 Virtio-ccw
 M: Cornelia Huck <cornelia.huck@de.ibm.com>
@@ -472,7 +490,7 @@ UniCore32 Machines
 PKUnity-3 SoC initramfs-with-busybox
 M: Guan Xuetao <gxt@mprc.pku.edu.cn>
 S: Maintained
-F: hw/puv3*
+F: hw/*/puv3*
 F: hw/unicore32/
 
 X86 Machines
@@ -480,90 +498,91 @@ X86 Machines
 PC
 M: Anthony Liguori <aliguori@us.ibm.com>
 S: Supported
-F: hw/pc.[ch]
-F: hw/pc_piix.c
+F: hw/i386/pc.[ch]
+F: hw/i386/pc_piix.c
 
 Xtensa Machines
 ---------------
 sim
 M: Max Filippov <jcmvbkbc@gmail.com>
 S: Maintained
-F: hw/xtensa_sim.c
+F: hw/xtensa/xtensa_sim.c
 
 Avnet LX60
 M: Max Filippov <jcmvbkbc@gmail.com>
 S: Maintained
-F: hw/xtensa_lx60.c
+F: hw/xtensa/xtensa_lx60.c
 
 Devices
 -------
 IDE
 M: Kevin Wolf <kwolf@redhat.com>
 S: Odd Fixes
+F: include/hw/ide.h
 F: hw/ide/
 
 OMAP
 M: Peter Maydell <peter.maydell@linaro.org>
 S: Maintained
-F: hw/omap*
+F: hw/*/omap*
 
 PCI
 M: Michael S. Tsirkin <mst@redhat.com>
 S: Supported
+F: include/hw/pci/*
 F: hw/pci/*
-F: hw/pci*
-F: hw/piix*
+F: hw/acpi/*
 
 ppc4xx
 M: Alexander Graf <agraf@suse.de>
 L: qemu-ppc@nongnu.org
 S: Odd Fixes
-F: hw/ppc4xx*.[hc]
+F: hw/ppc/ppc4*.c
 
 ppce500
 M: Alexander Graf <agraf@suse.de>
 M: Scott Wood <scottwood@freescale.com>
 L: qemu-ppc@nongnu.org
 S: Supported
-F: hw/ppce500_*
+F: hw/ppc/e500_*
 
 SCSI
 M: Paolo Bonzini <pbonzini@redhat.com>
 S: Supported
-F: hw/virtio-scsi.*
-F: hw/scsi*
+F: include/hw/scsi*
+F: hw/scsi/*
 T: git git://github.com/bonzini/qemu.git scsi-next
 
 LSI53C895A
 M: Paul Brook <paul@codesourcery.com>
 S: Odd Fixes
-F: hw/lsi53c895a.c
+F: hw/scsi/lsi53c895a.c
 
 SSI
 M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
 S: Maintained
-F: hw/ssi.*
-F: hw/m25p80.c
+F: hw/ssi/*
+F: hw/block/m25p80.c
 
 USB
 M: Gerd Hoffmann <kraxel@redhat.com>
 S: Maintained
-F: hw/usb*
+F: hw/usb/*
 
 VFIO
 M: Alex Williamson <alex.williamson@redhat.com>
 S: Supported
-F: hw/vfio*
+F: hw/pci/vfio.c
 
 vhost
 M: Michael S. Tsirkin <mst@redhat.com>
 S: Supported
-F: hw/vhost*
+F: hw/*/*vhost*
 
 virtio
 M: Anthony Liguori <aliguori@us.ibm.com>
 S: Supported
-F: hw/virtio*
+F: hw/*/virtio*
 
 virtio-9p
 M: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
@@ -576,7 +595,7 @@ virtio-blk
 M: Kevin Wolf <kwolf@redhat.com>
 M: Stefan Hajnoczi <stefanha@redhat.com>
 S: Supported
-F: hw/virtio-blk*
+F: hw/block/virtio-blk.c
 
 virtio-ccw
 M: Cornelia Huck <cornelia.huck@de.ibm.com>
@@ -587,20 +606,15 @@ T: git git://github.com/cohuck/qemu virtio-ccw-upstr
 virtio-serial
 M: Amit Shah <amit.shah@redhat.com>
 S: Supported
-F: hw/virtio-serial*
-F: hw/virtio-console*
+F: hw/char/virtio-serial-bus.c
+F: hw/char/virtio-console.c
 
 Xilinx EDK
 M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
 S: Maintained
-F: hw/xilinx_axi*
-F: hw/xilinx_uartlite.c
-F: hw/xilinx_intc.c
-F: hw/xilinx_ethlite.c
-F: hw/xilinx_timer.c
-F: hw/xilinx.h
-F: hw/xilinx_spi.c
+F: hw/*/xilinx_*
+F: include/hw/xilinx.h
 
 Subsystems
 ----------
@@ -608,6 +622,7 @@ Audio
 M: Vassili Karpov (malc) <av1474@comtv.ru>
 S: Maintained
 F: audio/
+F: hw/audio/
 
 Block
 M: Kevin Wolf <kwolf@redhat.com>
@@ -615,6 +630,7 @@ M: Stefan Hajnoczi <stefanha@redhat.com>
 S: Supported
 F: block*
 F: block/
+F: hw/block/
 
 Character Devices
 M: Anthony Liguori <aliguori@us.ibm.com>
@@ -646,7 +662,7 @@ S: Supported
 F: ui/qemu-spice.h
 F: ui/spice-*.c
 F: audio/spiceaudio.c
-F: hw/qxl*
+F: hw/display/qxl*
 
 Graphics
 M: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/Makefile b/Makefile
index 80344d9436..0b6e6a137f 100644
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,10 @@ config-all-devices.mak:
 	$(call quiet-command,echo '# no devices' > $@,"  GEN   $@")
 else
 config-all-devices.mak: $(SUBDIR_DEVICES_MAK)
-	$(call quiet-command,cat $(SUBDIR_DEVICES_MAK) | grep =y | sort -u > $@,"  GEN   $@")
+	$(call quiet-command, sed -n \
+             's|^\([^=]*\)=\(.*\)$$|\1:=$$(findstring y,$$(\1)\2)|p' \
+             $(SUBDIR_DEVICES_MAK) | sort -u > $@, \
+             "  GEN   $@")
 endif
 
 -include $(SUBDIR_DEVICES_MAK_DEP)
diff --git a/Makefile.objs b/Makefile.objs
index f99841ce54..e568c018b3 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -16,16 +16,7 @@ block-obj-y += qapi-types.o qapi-visit.o
 
 block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
 block-obj-y += qemu-coroutine-sleep.o
-ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
-block-obj-$(CONFIG_POSIX) += coroutine-ucontext.o
-else
-ifeq ($(CONFIG_SIGALTSTACK_COROUTINE),y)
-block-obj-$(CONFIG_POSIX) += coroutine-sigaltstack.o
-else
-block-obj-$(CONFIG_POSIX) += coroutine-gthread.o
-endif
-endif
-block-obj-$(CONFIG_WIN32) += coroutine-win32.o
+block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
 
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 # Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
diff --git a/arch_init.c b/arch_init.c
index c2cbc71c31..769ce77e61 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -35,15 +35,15 @@
 #include "qemu/bitmap.h"
 #include "sysemu/arch_init.h"
 #include "audio/audio.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "sysemu/kvm.h"
 #include "migration/migration.h"
 #include "exec/gdbstub.h"
-#include "hw/smbios.h"
+#include "hw/i386/smbios.h"
 #include "exec/address-spaces.h"
-#include "hw/pcspk.h"
+#include "hw/audio/pcspk.h"
 #include "migration/page_cache.h"
 #include "qemu/config-file.h"
 #include "qmp-commands.h"
diff --git a/block.c b/block.c
index 0ae2e93982..602d8a443e 100644
--- a/block.c
+++ b/block.c
@@ -140,8 +140,6 @@ void bdrv_io_limits_disable(BlockDriverState *bs)
 
     bs->slice_start = 0;
     bs->slice_end   = 0;
-    bs->slice_time  = 0;
-    memset(&bs->io_base, 0, sizeof(bs->io_base));
 }
 
 static void bdrv_block_timer(void *opaque)
@@ -1433,11 +1431,10 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
     bs_dest->enable_write_cache = bs_src->enable_write_cache;
 
     /* i/o timing parameters */
-    bs_dest->slice_time         = bs_src->slice_time;
     bs_dest->slice_start        = bs_src->slice_start;
     bs_dest->slice_end          = bs_src->slice_end;
+    bs_dest->slice_submitted    = bs_src->slice_submitted;
     bs_dest->io_limits          = bs_src->io_limits;
-    bs_dest->io_base            = bs_src->io_base;
     bs_dest->throttled_reqs     = bs_src->throttled_reqs;
     bs_dest->block_timer        = bs_src->block_timer;
     bs_dest->io_limits_enabled  = bs_src->io_limits_enabled;
@@ -3750,6 +3747,7 @@ static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors,
                  bool is_write, double elapsed_time, uint64_t *wait)
 {
     uint64_t bps_limit = 0;
+    uint64_t extension;
     double   bytes_limit, bytes_base, bytes_res;
     double   slice_time, wait_time;
 
@@ -3768,9 +3766,9 @@ static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors,
     slice_time = bs->slice_end - bs->slice_start;
     slice_time /= (NANOSECONDS_PER_SECOND);
     bytes_limit = bps_limit * slice_time;
-    bytes_base  = bs->nr_bytes[is_write] - bs->io_base.bytes[is_write];
+    bytes_base  = bs->slice_submitted.bytes[is_write];
     if (bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL]) {
-        bytes_base += bs->nr_bytes[!is_write] - bs->io_base.bytes[!is_write];
+        bytes_base += bs->slice_submitted.bytes[!is_write];
     }
 
     /* bytes_base: the bytes of data which have been read/written; and
@@ -3797,10 +3795,12 @@ static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors,
      * info can be kept until the timer fire, so it is increased and tuned
      * based on the result of experiment.
      */
-    bs->slice_time = wait_time * BLOCK_IO_SLICE_TIME * 10;
-    bs->slice_end += bs->slice_time - 3 * BLOCK_IO_SLICE_TIME;
+    extension = wait_time * NANOSECONDS_PER_SECOND;
+    extension = DIV_ROUND_UP(extension, BLOCK_IO_SLICE_TIME) *
+                BLOCK_IO_SLICE_TIME;
+    bs->slice_end += extension;
     if (wait) {
-        *wait = wait_time * BLOCK_IO_SLICE_TIME * 10;
+        *wait = wait_time * NANOSECONDS_PER_SECOND;
     }
 
     return true;
@@ -3828,9 +3828,9 @@ static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,
     slice_time = bs->slice_end - bs->slice_start;
     slice_time /= (NANOSECONDS_PER_SECOND);
     ios_limit  = iops_limit * slice_time;
-    ios_base   = bs->nr_ops[is_write] - bs->io_base.ios[is_write];
+    ios_base   = bs->slice_submitted.ios[is_write];
     if (bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL]) {
-        ios_base += bs->nr_ops[!is_write] - bs->io_base.ios[!is_write];
+        ios_base += bs->slice_submitted.ios[!is_write];
     }
 
     if (ios_base + 1 <= ios_limit) {
@@ -3841,7 +3841,7 @@ static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,
         return false;
     }
 
-    /* Calc approx time to dispatch */
+    /* Calc approx time to dispatch, in seconds */
     wait_time = (ios_base + 1) / iops_limit;
     if (wait_time > elapsed_time) {
         wait_time = wait_time - elapsed_time;
@@ -3849,10 +3849,10 @@ static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,
         wait_time = 0;
     }
 
-    bs->slice_time = wait_time * BLOCK_IO_SLICE_TIME * 10;
-    bs->slice_end += bs->slice_time - 3 * BLOCK_IO_SLICE_TIME;
+    /* Exceeded current slice, extend it by another slice time */
+    bs->slice_end += BLOCK_IO_SLICE_TIME;
     if (wait) {
-        *wait = wait_time * BLOCK_IO_SLICE_TIME * 10;
+        *wait = wait_time * NANOSECONDS_PER_SECOND;
     }
 
     return true;
@@ -3867,19 +3867,10 @@ static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors,
     int      bps_ret, iops_ret;
 
     now = qemu_get_clock_ns(vm_clock);
-    if ((bs->slice_start < now)
-        && (bs->slice_end > now)) {
-        bs->slice_end = now + bs->slice_time;
-    } else {
-        bs->slice_time  =  5 * BLOCK_IO_SLICE_TIME;
+    if (now > bs->slice_end) {
         bs->slice_start = now;
-        bs->slice_end   = now + bs->slice_time;
-
-        bs->io_base.bytes[is_write]  = bs->nr_bytes[is_write];
-        bs->io_base.bytes[!is_write] = bs->nr_bytes[!is_write];
-
-        bs->io_base.ios[is_write]    = bs->nr_ops[is_write];
-        bs->io_base.ios[!is_write]   = bs->nr_ops[!is_write];
+        bs->slice_end   = now + BLOCK_IO_SLICE_TIME;
+        memset(&bs->slice_submitted, 0, sizeof(bs->slice_submitted));
     }
 
     elapsed_time  = now - bs->slice_start;
@@ -3907,6 +3898,10 @@ static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors,
         *wait = 0;
     }
 
+    bs->slice_submitted.bytes[is_write] += (int64_t)nb_sectors *
+                                           BDRV_SECTOR_SIZE;
+    bs->slice_submitted.ios[is_write]++;
+
     return false;
 }
 
diff --git a/block/iscsi.c b/block/iscsi.c
index 51a2889452..92d6eae76f 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -31,14 +31,14 @@
 #include "qemu/error-report.h"
 #include "block/block_int.h"
 #include "trace.h"
-#include "hw/scsi-defs.h"
+#include "block/scsi.h"
 
 #include <iscsi/iscsi.h>
 #include <iscsi/scsi-lowlevel.h>
 
 #ifdef __linux__
 #include <scsi/sg.h>
-#include <hw/scsi-defs.h>
+#include <block/scsi.h>
 #endif
 
 typedef struct IscsiLun {
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index c38e970bf2..b32738f8d9 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -747,10 +747,9 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
     if (l1_table_offset != s->l1_table_offset) {
         l1_table = g_malloc0(align_offset(l1_size2, 512));
         l1_allocated = 1;
-        if (bdrv_pread(bs->file, l1_table_offset,
-                       l1_table, l1_size2) != l1_size2)
-        {
-            ret = -EIO;
+
+        ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2);
+        if (ret < 0) {
             goto fail;
         }
 
@@ -802,7 +801,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
                         }
 
                         if (refcount < 0) {
-                            ret = -EIO;
+                            ret = refcount;
                             goto fail;
                         }
                     }
@@ -833,7 +832,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
                 refcount = get_refcount(bs, l2_offset >> s->cluster_bits);
             }
             if (refcount < 0) {
-                ret = -EIO;
+                ret = refcount;
                 goto fail;
             } else if (refcount == 1) {
                 l2_offset |= QCOW_OFLAG_COPIED;
@@ -852,14 +851,16 @@ fail:
     }
 
     /* Update L1 only if it isn't deleted anyway (addend = -1) */
-    if (addend >= 0 && l1_modified) {
-        for(i = 0; i < l1_size; i++)
+    if (ret == 0 && addend >= 0 && l1_modified) {
+        for (i = 0; i < l1_size; i++) {
             cpu_to_be64s(&l1_table[i]);
-        if (bdrv_pwrite_sync(bs->file, l1_table_offset, l1_table,
-                        l1_size2) < 0)
-            goto fail;
-        for(i = 0; i < l1_size; i++)
+        }
+
+        ret = bdrv_pwrite_sync(bs->file, l1_table_offset, l1_table, l1_size2);
+
+        for (i = 0; i < l1_size; i++) {
             be64_to_cpus(&l1_table[i]);
+        }
     }
     if (l1_allocated)
         g_free(l1_table);
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index dc4e9a2462..95f10c81e3 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -10,7 +10,7 @@
  */
 
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "monitor/monitor.h"
 #include "qapi/qmp/qerror.h"
 #include "sysemu/sysemu.h"
diff --git a/blockdev.c b/blockdev.c
index 8cdc9ce16a..8a1652b722 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -31,7 +31,7 @@
  */
 
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "block/blockjob.h"
 #include "monitor/monitor.h"
 #include "qapi/qmp/qerror.h"
@@ -1069,7 +1069,6 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
     }
 
     bs->io_limits = io_limits;
-    bs->slice_time = BLOCK_IO_SLICE_TIME;
 
     if (!bs->io_limits_enabled && bdrv_io_limits_enabled(bs)) {
         bdrv_io_limits_enable(bs);
diff --git a/configure b/configure
index d685275c61..1ed939a3ac 100755
--- a/configure
+++ b/configure
@@ -27,6 +27,17 @@ printf " '%s'" "$0" "$@" >> config.log
 echo >> config.log
 echo "#" >> config.log
 
+error_exit() {
+    echo
+    echo "ERROR: $1"
+    while test -n "$2"; do
+        echo "       $2"
+        shift
+    done
+    echo
+    exit 1
+}
+
 do_cc() {
     # Run the compiler, capturing its output to the log.
     echo $cc "$@" >> config.log
@@ -46,11 +57,10 @@ do_cc() {
     esac
     echo $cc -Werror "$@" >> config.log
     $cc -Werror "$@" >> config.log 2>&1 && return $?
-    echo "ERROR: configure test passed without -Werror but failed with -Werror."
-    echo "This is probably a bug in the configure script. The failing command"
-    echo "will be at the bottom of config.log."
-    echo "You can run configure with --disable-werror to bypass this check."
-    exit 1
+    error_exit "configure test passed without -Werror but failed with -Werror." \
+        "This is probably a bug in the configure script. The failing command" \
+        "will be at the bottom of config.log." \
+        "You can run configure with --disable-werror to bypass this check."
 }
 
 compile_object() {
@@ -494,11 +504,10 @@ SunOS)
         LDFLAGS="-L/opt/SUNWspro/prod/lib -R/opt/SUNWspro/prod/lib $LDFLAGS"
         LIBS="-lsunmath $LIBS"
       else
-        echo "QEMU will not link correctly on Solaris 8/X86 or 9/x86 without"
-        echo "libsunmath from the Sun Studio compilers tools, due to a lack of"
-        echo "C99 math features in libm.so in Solaris 8/x86 and Solaris 9/x86"
-        echo "Studio 11 can be downloaded from www.sun.com."
-        exit 1
+        error_exit "QEMU will not link correctly on Solaris 8/X86 or 9/x86 without" \
+            "libsunmath from the Sun Studio compilers tools, due to a lack of" \
+            "C99 math features in libm.so in Solaris 8/x86 and Solaris 9/x86" \
+            "Studio 11 can be downloaded from www.sun.com."
       fi
     fi
   fi
@@ -1185,8 +1194,7 @@ if test "$ARCH" = "unknown"; then
         echo "Unsupported CPU = $cpu, will use TCG with TCI (experimental)"
         ARCH=tci
     else
-        echo "Unsupported CPU = $cpu, try --enable-tcg-interpreter"
-        exit 1
+        error_exit "Unsupported CPU = $cpu, try --enable-tcg-interpreter"
     fi
 fi
 
@@ -1198,8 +1206,7 @@ EOF
 if compile_object ; then
   : C compiler works ok
 else
-    echo "ERROR: \"$cc\" either does not exist or does not work"
-    exit 1
+    error_exit "\"$cc\" either does not exist or does not work"
 fi
 
 # Consult white-list to determine whether to enable werror
@@ -1254,8 +1261,7 @@ fi
 
 if test "$static" = "yes" ; then
   if test "$pie" = "yes" ; then
-    echo "static and pie are mutually incompatible"
-    exit 1
+    error_exit "static and pie are mutually incompatible"
   else
     pie="no"
   fi
@@ -1294,8 +1300,7 @@ EOF
     fi
   else
     if test "$pie" = "yes"; then
-      echo "PIE not available due to missing toolchain support"
-      exit 1
+      error_exit "PIE not available due to missing toolchain support"
     else
       echo "Disabling PIE due to missing toolchain support"
       pie="no"
@@ -1310,40 +1315,36 @@ if test "$solaris" = "yes" ; then
   if has $install; then
     :
   else
-    echo "Solaris install program not found. Use --install=/usr/ucb/install or"
-    echo "install fileutils from www.blastwave.org using pkg-get -i fileutils"
-    echo "to get ginstall which is used by default (which lives in /opt/csw/bin)"
-    exit 1
+    error_exit "Solaris install program not found. Use --install=/usr/ucb/install or" \
+        "install fileutils from www.blastwave.org using pkg-get -i fileutils" \
+        "to get ginstall which is used by default (which lives in /opt/csw/bin)"
   fi
   if test "`path_of $install`" = "/usr/sbin/install" ; then
-    echo "Error: Solaris /usr/sbin/install is not an appropriate install program."
-    echo "try ginstall from the GNU fileutils available from www.blastwave.org"
-    echo "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
-    exit 1
+    error_exit "Solaris /usr/sbin/install is not an appropriate install program." \
+        "try ginstall from the GNU fileutils available from www.blastwave.org" \
+        "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
   fi
   if has ar; then
     :
   else
-    echo "Error: No path includes ar"
     if test -f /usr/ccs/bin/ar ; then
-      echo "Add /usr/ccs/bin to your path and rerun configure"
+      error_exit "No path includes ar" \
+          "Add /usr/ccs/bin to your path and rerun configure"
     fi
-    exit 1
+    error_exit "No path includes ar"
   fi
 fi
 
 if ! has $python; then
-  echo "Python not found. Use --python=/path/to/python"
-  exit 1
+  error_exit "Python not found. Use --python=/path/to/python"
 fi
 
 # Note that if the Python conditional here evaluates True we will exit
 # with status 1 which is a shell 'false' value.
 if ! "$python" -c 'import sys; sys.exit(sys.version_info < (2,4) or sys.version_info >= (3,))'; then
-  echo "Cannot use '$python', Python 2.4 or later is required."
-  echo "Note that Python 3 or later is not yet supported."
-  echo "Use --python=/path/to/python to specify a supported Python."
-  exit 1
+  error_exit "Cannot use '$python', Python 2.4 or later is required." \
+      "Note that Python 3 or later is not yet supported." \
+      "Use --python=/path/to/python to specify a supported Python."
 fi
 
 if test -z "${target_list+xxx}" ; then
@@ -1362,11 +1363,8 @@ esac
 feature_not_found() {
   feature=$1
 
-  echo "ERROR"
-  echo "ERROR: User requested feature $feature"
-  echo "ERROR: configure was not able to find it"
-  echo "ERROR"
-  exit 1;
+  error_exit "User requested feature $feature" \
+      "configure was not able to find it"
 }
 
 if test -z "$cross_prefix" ; then
@@ -1408,8 +1406,7 @@ fi
 # pkg-config probe
 
 if ! has "$pkg_config_exe"; then
-  echo "Error: pkg-config binary '$pkg_config_exe' not found"
-  exit 1
+  error_exit "pkg-config binary '$pkg_config_exe' not found"
 fi
 
 ##########################################
@@ -1448,11 +1445,8 @@ EOF
     if compile_prog "" "-lz" ; then
         :
     else
-        echo
-        echo "Error: zlib check failed"
-        echo "Make sure to have the zlib libs and headers installed."
-        echo
-        exit 1
+        error_exit "zlib check failed" \
+            "Make sure to have the zlib libs and headers installed."
     fi
 fi
 
@@ -1629,14 +1623,12 @@ if test "$xen_pci_passthrough" != "no"; then
     xen_pci_passthrough=yes
   else
     if test "$xen_pci_passthrough" = "yes"; then
-      echo "ERROR"
-      echo "ERROR: User requested feature Xen PCI Passthrough"
-      echo "ERROR: but this feature require /sys from Linux"
       if test "$xen_ctrl_version" -lt 340; then
-        echo "ERROR: This feature does not work with Xen 3.3"
+        error_exit "User requested feature Xen PCI Passthrough" \
+            "This feature does not work with Xen 3.3"
       fi
-      echo "ERROR"
-      exit 1;
+      error_exit "User requested feature Xen PCI Passthrough" \
+          " but this feature requires /sys from Linux"
     fi
     xen_pci_passthrough=no
   fi
@@ -2010,11 +2002,8 @@ EOF
     if compile_prog "$cfl" "$lib" ; then
         :
     else
-        echo
-        echo "Error: $drv check failed"
-        echo "Make sure to have the $drv libs and headers installed."
-        echo
-        exit 1
+        error_exit "$drv check failed" \
+            "Make sure to have the $drv libs and headers installed."
     fi
 }
 
@@ -2029,11 +2018,8 @@ for drv in $audio_drv_list; do
 
     fmod)
     if test -z $fmod_lib || test -z $fmod_inc; then
-        echo
-        echo "Error: You must specify path to FMOD library and headers"
-        echo "Example: --fmod-inc=/path/include/fmod --fmod-lib=/path/lib/libfmod-3.74.so"
-        echo
-        exit 1
+        error_exit "You must specify path to FMOD library and headers" \
+            "Example: --fmod-inc=/path/include/fmod --fmod-lib=/path/lib/libfmod-3.74.so"
     fi
     audio_drv_probe $drv fmod.h $fmod_lib "return FSOUND_GetVersion();" "-I $fmod_inc"
     libs_softmmu="$fmod_lib $libs_softmmu"
@@ -2076,11 +2062,8 @@ for drv in $audio_drv_list; do
 
     *)
     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
-        echo
-        echo "Error: Unknown driver '$drv' selected"
-        echo "Possible drivers are: $audio_possible_drivers"
-        echo
-        exit 1
+        error_exit "Unknown driver '$drv' selected" \
+            "Possible drivers are: $audio_possible_drivers"
     }
     ;;
     esac
@@ -2209,8 +2192,7 @@ then
     LIBS="$glib_libs $LIBS"
     libs_qga="$glib_libs $libs_qga"
 else
-    echo "glib-$glib_req_ver required to compile QEMU"
-    exit 1
+    error_exit "glib-$glib_req_ver required to compile QEMU"
 fi
 
 ##########################################
@@ -2227,11 +2209,10 @@ if test "$pixman" = ""; then
 fi
 if test "$pixman" = "none"; then
   if test "$want_tools" != "no" -o "$softmmu" != "no"; then
-    echo "ERROR: pixman disabled but system emulation or tools build"
-    echo "       enabled.  You can turn off pixman only if you also"
-    echo "       disable all system emulation targets and the tools"
-    echo "       build with '--disable-tools --disable-system'."
-    exit 1
+    error_exit "pixman disabled but system emulation or tools build" \
+        "enabled.  You can turn off pixman only if you also" \
+        "disable all system emulation targets and the tools" \
+        "build with '--disable-tools --disable-system'."
   fi
   pixman_cflags=
   pixman_libs=
@@ -2240,12 +2221,11 @@ elif test "$pixman" = "system"; then
   pixman_libs=`$pkg_config --libs pixman-1 2>/dev/null`
 else
   if test ! -d ${source_path}/pixman/pixman; then
-    echo "ERROR: pixman not present. Your options:"
-    echo "  (1) Preferred: Install the pixman devel package (any recent"
-    echo "      distro should have packages as Xorg needs pixman too)."
-    echo "  (2) Fetch the pixman submodule, using:"
-    echo "      git submodule update --init pixman"
-    exit 1
+    error_exit "pixman not present. Your options:" \
+        "  (1) Preferred: Install the pixman devel package (any recent" \
+        "      distro should have packages as Xorg needs pixman too)." \
+        "  (2) Fetch the pixman submodule, using:" \
+        "      git submodule update --init pixman"
   fi
   mkdir -p pixman/pixman
   pixman_cflags="-I\$(SRC_PATH)/pixman/pixman -I\$(BUILD_DIR)/pixman/pixman"
@@ -2304,11 +2284,8 @@ else
 fi
 
 if test "$mingw32" != yes -a "$pthread" = no; then
-  echo
-  echo "Error: pthread check failed"
-  echo "Make sure to have the pthread libs and headers installed."
-  echo
-  exit 1
+  error_exit "pthread check failed" \
+      "Make sure to have the pthread libs and headers installed."
 fi
 
 ##########################################
@@ -2363,8 +2340,7 @@ fi
 
 if test "$virtio_blk_data_plane" = "yes" -a \
 	"$linux_aio" != "yes" ; then
-  echo "Error: virtio-blk-data-plane requires Linux AIO, please try --enable-linux-aio"
-  exit 1
+  error_exit "virtio-blk-data-plane requires Linux AIO, please try --enable-linux-aio"
 elif test -z "$virtio_blk_data_plane" ; then
   virtio_blk_data_plane=$linux_aio
 fi
@@ -2861,10 +2837,7 @@ elif compile_prog "" "-lm" ; then
   LIBS="-lm $LIBS"
   libs_qga="-lm $libs_qga"
 else
-  echo
-  echo "Error: libm check failed"
-  echo
-  exit 1
+  error_exit "libm check failed"
 fi
 
 ##########################################
@@ -3040,11 +3013,8 @@ fi
 
 $python "$source_path/scripts/tracetool.py" "--backend=$trace_backend" --check-backend  > /dev/null 2> /dev/null
 if test "$?" -ne 0 ; then
-  echo
-  echo "Error: invalid trace backend"
-  echo "Please choose a supported trace backend."
-  echo
-  exit 1
+  error_exit "invalid trace backend" \
+      "Please choose a supported trace backend."
 fi
 
 ##########################################
@@ -3059,10 +3029,7 @@ EOF
     LIBS="-lust -lurcu-bp $LIBS"
     libs_qga="-lust -lurcu-bp $libs_qga"
   else
-    echo
-    echo "Error: Trace backend 'ust' missing libust header files"
-    echo
-    exit 1
+    error_exit "Trace backend 'ust' missing libust header files"
   fi
 fi
 
@@ -3070,10 +3037,7 @@ fi
 # For 'dtrace' backend, test if 'dtrace' command is present
 if test "$trace_backend" = "dtrace"; then
   if ! has 'dtrace' ; then
-    echo
-    echo "Error: dtrace command is not found in PATH $PATH"
-    echo
-    exit 1
+    error_exit "dtrace command is not found in PATH $PATH"
   fi
   trace_backend_stap="no"
   if has 'stap' ; then
@@ -3107,34 +3071,58 @@ fi
 ##########################################
 # check and set a backend for coroutine
 
-# default is ucontext, but always fallback to gthread
-# windows autodetected by make
-if test "$coroutine" = "" -o "$coroutine" = "ucontext"; then
-  if test "$darwin" != "yes"; then
-    cat > $TMPC << EOF
+# We prefer ucontext, but it's not always possible. The fallback
+# is sigcontext. gthread is not selectable except explicitly, because
+# it is not functional enough to run QEMU proper. (It is occasionally
+# useful for debugging purposes.)  On Windows the only valid backend
+# is the Windows-specific one.
+
+ucontext_works=no
+if test "$darwin" != "yes"; then
+  cat > $TMPC << EOF
 #include <ucontext.h>
 #ifdef __stub_makecontext
 #error Ignoring glibc stub makecontext which will always fail
 #endif
 int main(void) { makecontext(0, 0, 0); return 0; }
 EOF
-    if compile_prog "" "" ; then
-        coroutine_backend=ucontext
-    else
-	coroutine_backend=gthread
-    fi
+  if compile_prog "" "" ; then
+    ucontext_works=yes
+  fi
+fi
+
+if test "$coroutine" = ""; then
+  if test "$mingw32" = "yes"; then
+    coroutine=win32
+  elif test "$ucontext_works" = "yes"; then
+    coroutine=ucontext
+  else
+    coroutine=sigaltstack
   fi
-elif test "$coroutine" = "gthread" ; then
-  coroutine_backend=gthread
-elif test "$coroutine" = "windows" ; then
-  coroutine_backend=windows
-elif test "$coroutine" = "sigaltstack" ; then
-  coroutine_backend=sigaltstack
 else
-  echo
-  echo "Error: unknown coroutine backend $coroutine"
-  echo
-  exit 1
+  case $coroutine in
+  windows)
+    if test "$mingw32" != "yes"; then
+      error_exit "'windows' coroutine backend only valid for Windows"
+    fi
+    # Unfortunately the user visible backend name doesn't match the
+    # coroutine-*.c filename for this case, so we have to adjust it here.
+    coroutine=win32
+    ;;
+  ucontext)
+    if test "$ucontext_works" != "yes"; then
+      feature_not_found "ucontext"
+    fi
+    ;;
+  gthread|sigaltstack)
+    if test "$mingw32" = "yes"; then
+      error_exit "only the 'windows' coroutine backend is valid for Windows"
+    fi
+    ;;
+  *)
+    error_exit "unknown coroutine backend $coroutine"
+    ;;
+  esac
 fi
 
 ##########################################
@@ -3319,8 +3307,7 @@ if test "$softmmu" = yes ; then
       tools="$tools fsdev/virtfs-proxy-helper\$(EXESUF)"
     else
       if test "$virtfs" = yes; then
-        echo "VirtFS is supported only on Linux and requires libcap-devel and libattr-devel"
-        exit 1
+        error_exit "VirtFS is supported only on Linux and requires libcap-devel and libattr-devel"
       fi
       virtfs=no
     fi
@@ -3442,7 +3429,7 @@ echo "GLX support       $glx"
 echo "libiscsi support  $libiscsi"
 echo "build guest agent $guest_agent"
 echo "seccomp support   $seccomp"
-echo "coroutine backend $coroutine_backend"
+echo "coroutine backend $coroutine"
 echo "GlusterFS support $glusterfs"
 echo "virtio-blk-data-plane $virtio_blk_data_plane"
 echo "gcov              $gcov_tool"
@@ -3775,11 +3762,7 @@ if test "$rbd" = "yes" ; then
   echo "CONFIG_RBD=y" >> $config_host_mak
 fi
 
-if test "$coroutine_backend" = "ucontext" ; then
-  echo "CONFIG_UCONTEXT_COROUTINE=y" >> $config_host_mak
-elif test "$coroutine_backend" = "sigaltstack" ; then
-  echo "CONFIG_SIGALTSTACK_COROUTINE=y" >> $config_host_mak
-fi
+echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
 
 if test "$open_by_handle_at" = "yes" ; then
   echo "CONFIG_OPEN_BY_HANDLE=y" >> $config_host_mak
@@ -3814,7 +3797,7 @@ if test "$glusterfs" = "yes" ; then
 fi
 
 if test "$virtio_blk_data_plane" = "yes" ; then
-  echo "CONFIG_VIRTIO_BLK_DATA_PLANE=y" >> $config_host_mak
+  echo 'CONFIG_VIRTIO_BLK_DATA_PLANE=$(CONFIG_VIRTIO)' >> $config_host_mak
 fi
 
 # USB host support
@@ -3967,22 +3950,20 @@ case "$target" in
     ;;
   ${target_arch2}-linux-user)
     if test "$linux" != "yes" ; then
-      echo "ERROR: Target '$target' is only available on a Linux host"
-      exit 1
+      error_exit "Target '$target' is only available on a Linux host"
     fi
     target_user_only="yes"
     target_linux_user="yes"
     ;;
   ${target_arch2}-bsd-user)
     if test "$bsd" != "yes" ; then
-      echo "ERROR: Target '$target' is only available on a BSD host"
-      exit 1
+      error_exit "Target '$target' is only available on a BSD host"
     fi
     target_user_only="yes"
     target_bsd_user="yes"
     ;;
   *)
-    echo "ERROR: Target '$target' not recognised"
+    error_exit "Target '$target' not recognised"
     exit 1
     ;;
 esac
@@ -4113,8 +4094,7 @@ case "$target_arch2" in
     TARGET_ARCH=xtensa
   ;;
   *)
-    echo "Unsupported target CPU"
-    exit 1
+    error_exit "Unsupported target CPU"
   ;;
 esac
 # TARGET_BASE_ARCH needs to be defined after TARGET_ARCH
diff --git a/default-configs/alpha-softmmu.mak b/default-configs/alpha-softmmu.mak
index 2dbee94c89..18e5337a77 100644
--- a/default-configs/alpha-softmmu.mak
+++ b/default-configs/alpha-softmmu.mak
@@ -13,3 +13,4 @@ CONFIG_IDE_QDEV=y
 CONFIG_VMWARE_VGA=y
 CONFIG_IDE_CMD646=y
 CONFIG_I8259=y
+CONFIG_MC146818RTC=y
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index ab8703578e..31725a97f9 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -16,7 +16,9 @@ CONFIG_TWL92230=y
 CONFIG_TSC2005=y
 CONFIG_LM832X=y
 CONFIG_TMP105=y
+CONFIG_STELLARIS=y
 CONFIG_STELLARIS_INPUT=y
+CONFIG_STELLARIS_ENET=y
 CONFIG_SSD0303=y
 CONFIG_SSD0323=y
 CONFIG_ADS7846=y
@@ -29,8 +31,17 @@ CONFIG_SMC91C111=y
 CONFIG_DS1338=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
+CONFIG_MICRODRIVE=y
+CONFIG_USB_MUSB=y
 
+CONFIG_ARM5MPCORE=y
+CONFIG_ARM9MPCORE=y
+CONFIG_ARM15MPCORE=y
+
+CONFIG_ARM_GIC=y
+CONFIG_ARM_GIC_KVM=$(CONFIG_KVM)
 CONFIG_ARM_TIMER=y
+CONFIG_ARM_MPTIMER=y
 CONFIG_PL011=y
 CONFIG_PL022=y
 CONFIG_PL031=y
@@ -45,6 +56,25 @@ CONFIG_PL310=y
 CONFIG_PL330=y
 CONFIG_CADENCE=y
 CONFIG_XGMAC=y
+CONFIG_EXYNOS4=y
+CONFIG_PXA2XX=y
+CONFIG_BITBANG_I2C=y
+CONFIG_FRAMEBUFFER=y
+CONFIG_XILINX_SPIPS=y
+
+CONFIG_A9SCU=y
+CONFIG_MARVELL_88W8618=y
+CONFIG_OMAP=y
+CONFIG_TSC210X=y
+CONFIG_BLIZZARD=y
+CONFIG_ONENAND=y
+CONFIG_TUSB6010=y
+CONFIG_IMX=y
+CONFIG_MAINSTONE=y
+CONFIG_NSERIES=y
+CONFIG_REALVIEW=y
+CONFIG_ZAURUS=y
+CONFIG_ZYNQ=y
 
 CONFIG_VERSATILE_PCI=y
 CONFIG_VERSATILE_I2C=y
diff --git a/default-configs/cris-softmmu.mak b/default-configs/cris-softmmu.mak
index 1a479cd8d3..d970d50158 100644
--- a/default-configs/cris-softmmu.mak
+++ b/default-configs/cris-softmmu.mak
@@ -1,5 +1,6 @@
 # Default configuration for cris-softmmu
 
+CONFIG_ETRAXFS=y
 CONFIG_NAND=y
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI02=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index df9e126c1f..4ac0694470 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -3,6 +3,7 @@
 include pci.mak
 include usb.mak
 CONFIG_VGA=y
+CONFIG_QXL=$(CONFIG_SPICE)
 CONFIG_VGA_PCI=y
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
@@ -16,7 +17,7 @@ CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
@@ -28,3 +29,19 @@ CONFIG_I8259=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_TPM_TIS=y
 CONFIG_TPM_PASSTHROUGH=y
+CONFIG_PCI_HOTPLUG=y
+CONFIG_MC146818RTC=y
+CONFIG_PAM=y
+CONFIG_PCI_PIIX=y
+CONFIG_PCI_HOTPLUG=y
+CONFIG_WDT_IB700=y
+CONFIG_PC_SYSFW=y
+CONFIG_XEN_I386=$(CONFIG_XEN)
+CONFIG_ISA_DEBUG=y
+CONFIG_ISA_TESTDEV=y
+CONFIG_VMPORT=y
+CONFIG_SGA=y
+CONFIG_LPC_ICH9=y
+CONFIG_Q35=y
+CONFIG_APIC=y
+CONFIG_IOAPIC=y
diff --git a/default-configs/lm32-softmmu.mak b/default-configs/lm32-softmmu.mak
index 0d19974b40..ef0f4bae72 100644
--- a/default-configs/lm32-softmmu.mak
+++ b/default-configs/lm32-softmmu.mak
@@ -1,5 +1,8 @@
 # Default configuration for lm32-softmmu
 
+CONFIG_LM32=y
+CONFIG_MILKYMIST=y
+CONFIG_FRAMEBUFFER=y
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
diff --git a/default-configs/m68k-softmmu.mak b/default-configs/m68k-softmmu.mak
index 778ea82a10..51fe5bb321 100644
--- a/default-configs/m68k-softmmu.mak
+++ b/default-configs/m68k-softmmu.mak
@@ -2,5 +2,6 @@
 
 include pci.mak
 include usb.mak
+CONFIG_COLDFIRE=y
 CONFIG_GDBSTUB_XML=y
 CONFIG_PTIMER=y
diff --git a/default-configs/microblaze-softmmu.mak b/default-configs/microblaze-softmmu.mak
index 2f442e5aea..ce2630818a 100644
--- a/default-configs/microblaze-softmmu.mak
+++ b/default-configs/microblaze-softmmu.mak
@@ -5,5 +5,7 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
 CONFIG_XILINX=y
 CONFIG_XILINX_AXI=y
+CONFIG_XILINX_SPI=y
+CONFIG_XILINX_ETHLITE=y
 CONFIG_SSI=y
 CONFIG_SSI_M25P80=y
diff --git a/default-configs/microblazeel-softmmu.mak b/default-configs/microblazeel-softmmu.mak
index af9a3cde0d..acf22c5bb3 100644
--- a/default-configs/microblazeel-softmmu.mak
+++ b/default-configs/microblazeel-softmmu.mak
@@ -5,5 +5,7 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
 CONFIG_XILINX=y
 CONFIG_XILINX_AXI=y
+CONFIG_XILINX_SPI=y
+CONFIG_XILINX_ETHLITE=y
 CONFIG_SSI=y
 CONFIG_SSI_M25P80=y
diff --git a/default-configs/mips-softmmu.mak b/default-configs/mips-softmmu.mak
index 4f04a33732..b764360a55 100644
--- a/default-configs/mips-softmmu.mak
+++ b/default-configs/mips-softmmu.mak
@@ -18,7 +18,7 @@ CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_PIIX4=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
@@ -32,3 +32,5 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_G364FB=y
 CONFIG_I8259=y
 CONFIG_JAZZ_LED=y
+CONFIG_MC146818RTC=y
+CONFIG_VT82C686=y
diff --git a/default-configs/mips64-softmmu.mak b/default-configs/mips64-softmmu.mak
index a5b6c3c36a..0e4e65d5eb 100644
--- a/default-configs/mips64-softmmu.mak
+++ b/default-configs/mips64-softmmu.mak
@@ -18,7 +18,7 @@ CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_PIIX4=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
@@ -32,3 +32,5 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_G364FB=y
 CONFIG_I8259=y
 CONFIG_JAZZ_LED=y
+CONFIG_MC146818RTC=y
+CONFIG_VT82C686=y
diff --git a/default-configs/mips64el-softmmu.mak b/default-configs/mips64el-softmmu.mak
index a0e6de8e68..0a6c4f7ba2 100644
--- a/default-configs/mips64el-softmmu.mak
+++ b/default-configs/mips64el-softmmu.mak
@@ -18,7 +18,7 @@ CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_PIIX4=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
@@ -34,3 +34,5 @@ CONFIG_FULONG=y
 CONFIG_G364FB=y
 CONFIG_I8259=y
 CONFIG_JAZZ_LED=y
+CONFIG_MC146818RTC=y
+CONFIG_VT82C686=y
diff --git a/default-configs/mipsel-softmmu.mak b/default-configs/mipsel-softmmu.mak
index 753dd76a21..9f9c6daa56 100644
--- a/default-configs/mipsel-softmmu.mak
+++ b/default-configs/mipsel-softmmu.mak
@@ -18,7 +18,7 @@ CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_PIIX4=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
@@ -32,3 +32,5 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_G364FB=y
 CONFIG_I8259=y
 CONFIG_JAZZ_LED=y
+CONFIG_MC146818RTC=y
+CONFIG_VT82C686=y
diff --git a/default-configs/moxie-softmmu.mak b/default-configs/moxie-softmmu.mak
index 8ede8d5b23..1a954764f3 100644
--- a/default-configs/moxie-softmmu.mak
+++ b/default-configs/moxie-softmmu.mak
@@ -1 +1,5 @@
 # Default configuration for moxie-softmmu
+
+CONFIG_MC146818RTC=y
+CONFIG_SERIAL=y
+CONFIG_VGA=y
diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index ce56d58055..f5f100ecb0 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -23,3 +23,4 @@ CONFIG_ESP_PCI=y
 CONFIG_SERIAL=y
 CONFIG_SERIAL_PCI=y
 CONFIG_IPACK=y
+CONFIG_WDT_IB6300ESB=y
diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak
index c209a8da65..50034fc87f 100644
--- a/default-configs/ppc-softmmu.mak
+++ b/default-configs/ppc-softmmu.mak
@@ -13,7 +13,7 @@ CONFIG_PARALLEL=y
 CONFIG_I8254=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_I82374=y
 CONFIG_OPENPIC=y
 CONFIG_PREP_PCI=y
@@ -40,4 +40,8 @@ CONFIG_PFLASH_CFI02=y
 CONFIG_PTIMER=y
 CONFIG_I8259=y
 CONFIG_XILINX=y
+CONFIG_XILINX_ETHLITE=y
+CONFIG_OPENPIC=y
 CONFIG_E500=$(CONFIG_FDT)
+# For PReP
+CONFIG_MC146818RTC=y
diff --git a/default-configs/ppc64-softmmu.mak b/default-configs/ppc64-softmmu.mak
index 8d490bd72e..6398d60362 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -13,7 +13,7 @@ CONFIG_PARALLEL=y
 CONFIG_I8254=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_I82374=y
 CONFIG_OPENPIC=y
 CONFIG_PREP_PCI=y
@@ -40,5 +40,11 @@ CONFIG_PFLASH_CFI02=y
 CONFIG_PTIMER=y
 CONFIG_I8259=y
 CONFIG_XILINX=y
+CONFIG_XILINX_ETHLITE=y
+CONFIG_OPENPIC=y
 CONFIG_PSERIES=$(CONFIG_FDT)
 CONFIG_E500=$(CONFIG_FDT)
+# For pSeries
+CONFIG_PCI_HOTPLUG=y
+# For PReP
+CONFIG_MC146818RTC=y
diff --git a/default-configs/ppcemb-softmmu.mak b/default-configs/ppcemb-softmmu.mak
index 7f13421d93..05b50d6f00 100644
--- a/default-configs/ppcemb-softmmu.mak
+++ b/default-configs/ppcemb-softmmu.mak
@@ -12,7 +12,7 @@ CONFIG_SERIAL=y
 CONFIG_I8254=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_OPENPIC=y
 CONFIG_PREP_PCI=y
 CONFIG_MACIO=y
@@ -35,4 +35,8 @@ CONFIG_PFLASH_CFI02=y
 CONFIG_PTIMER=y
 CONFIG_I8259=y
 CONFIG_XILINX=y
+CONFIG_XILINX_ETHLITE=y
+CONFIG_OPENPIC=y
 CONFIG_E500=$(CONFIG_FDT)
+# For PReP
+CONFIG_MC146818RTC=y
diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak
index 3005729204..81fbc68654 100644
--- a/default-configs/s390x-softmmu.mak
+++ b/default-configs/s390x-softmmu.mak
@@ -1 +1,2 @@
 CONFIG_VIRTIO=y
+CONFIG_SCLPCONSOLE=y
diff --git a/default-configs/sh4-softmmu.mak b/default-configs/sh4-softmmu.mak
index e08b2ee106..f6bf62d1c2 100644
--- a/default-configs/sh4-softmmu.mak
+++ b/default-configs/sh4-softmmu.mak
@@ -6,3 +6,6 @@ CONFIG_SERIAL=y
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_ISA_MMIO=y
+CONFIG_SH4=y
+CONFIG_IDE_MMIO=y
+CONFIG_SM501=y
diff --git a/default-configs/sh4eb-softmmu.mak b/default-configs/sh4eb-softmmu.mak
index 3a8453552b..c1d513d099 100644
--- a/default-configs/sh4eb-softmmu.mak
+++ b/default-configs/sh4eb-softmmu.mak
@@ -6,3 +6,6 @@ CONFIG_SERIAL=y
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_ISA_MMIO=y
+CONFIG_SH4=y
+CONFIG_IDE_MMIO=y
+CONFIG_SM501=y
diff --git a/default-configs/sparc-softmmu.mak b/default-configs/sparc-softmmu.mak
index b0310c51e2..8fc93dd643 100644
--- a/default-configs/sparc-softmmu.mak
+++ b/default-configs/sparc-softmmu.mak
@@ -8,3 +8,11 @@ CONFIG_PTIMER=y
 CONFIG_FDC=y
 CONFIG_EMPTY_SLOT=y
 CONFIG_PCNET_COMMON=y
+CONFIG_LANCE=y
+CONFIG_TCX=y
+CONFIG_SLAVIO=y
+CONFIG_CS4231=y
+CONFIG_GRLIB=y
+CONFIG_STP2000=y
+CONFIG_ECCMEMCTL=y
+CONFIG_SUN4M=y
diff --git a/default-configs/sparc64-softmmu.mak b/default-configs/sparc64-softmmu.mak
index 2145b6b29f..9b08ee8a20 100644
--- a/default-configs/sparc64-softmmu.mak
+++ b/default-configs/sparc64-softmmu.mak
@@ -13,3 +13,5 @@ CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
+CONFIG_PCI_APB=y
+CONFIG_MC146818RTC=y
diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
index ab3cd5fc35..bf4091c4dd 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -3,6 +3,7 @@
 include pci.mak
 include usb.mak
 CONFIG_VGA=y
+CONFIG_QXL=$(CONFIG_SPICE)
 CONFIG_VGA_PCI=y
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
@@ -16,7 +17,7 @@ CONFIG_PCKBD=y
 CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
-CONFIG_DMA=y
+CONFIG_I8257=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
@@ -28,3 +29,19 @@ CONFIG_I8259=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_TPM_TIS=y
 CONFIG_TPM_PASSTHROUGH=y
+CONFIG_PCI_HOTPLUG=y
+CONFIG_MC146818RTC=y
+CONFIG_PAM=y
+CONFIG_PCI_PIIX=y
+CONFIG_PCI_HOTPLUG=y
+CONFIG_WDT_IB700=y
+CONFIG_PC_SYSFW=y
+CONFIG_XEN_I386=$(CONFIG_XEN)
+CONFIG_ISA_DEBUG=y
+CONFIG_ISA_TESTDEV=y
+CONFIG_VMPORT=y
+CONFIG_SGA=y
+CONFIG_LPC_ICH9=y
+CONFIG_Q35=y
+CONFIG_APIC=y
+CONFIG_IOAPIC=y
diff --git a/docs/usb2.txt b/docs/usb2.txt
index 43dacdec28..c7a445afcd 100644
--- a/docs/usb2.txt
+++ b/docs/usb2.txt
@@ -11,7 +11,7 @@ one USB 2.0 bus driven by the EHCI controller.  Devices must be
 attached to the correct controller manually.
 
 The '-usb' switch will make qemu create the UHCI controller as part of
-the PIIX3 chipset.  The USB 1.1 bus will carry the name "usb.0".
+the PIIX3 chipset.  The USB 1.1 bus will carry the name "usb-bus.0".
 
 You can use the standard -device switch to add a EHCI controller to
 your virtual machine.  It is strongly recommended to specify an ID for
@@ -27,7 +27,7 @@ a complete example:
         -drive if=none,id=usbstick,file=/path/to/image   \
         -usb                                             \
         -device usb-ehci,id=ehci                         \
-        -device usb-tablet,bus=usb.0                     \
+        -device usb-tablet,bus=usb-bus.0                 \
         -device usb-storage,bus=ehci.0,drive=usbstick
 
 This attaches a usb tablet to the UHCI adapter and a usb mass storage
@@ -88,22 +88,22 @@ ports (1-4), the emulated (1.1) USB hub has eight ports.
 
 Plugging a tablet into UHCI port 1 works like this:
 
-        -device usb-tablet,bus=usb.0,port=1
+        -device usb-tablet,bus=usb-bus.0,port=1
 
 Plugging a hub into UHCI port 2 works like this:
 
-        -device usb-hub,bus=usb.0,port=2
+        -device usb-hub,bus=usb-bus.0,port=2
 
 Plugging a virtual usb stick into port 4 of the hub just plugged works
 this way:
 
-        -device usb-storage,bus=usb.0,port=2.4,drive=...
+        -device usb-storage,bus=usb-bus.0,port=2.4,drive=...
 
 You can do basically the same in the monitor using the device_add
 command.  If you want to unplug devices too you should specify some
 unique id which you can use to refer to the device ...
 
-        (qemu) device_add usb-tablet,bus=usb.0,port=1,id=my-tablet
+        (qemu) device_add usb-tablet,bus=usb-bus.0,port=1,id=my-tablet
         (qemu) device_del my-tablet
 
 ... when unplugging it with device_del.
@@ -148,10 +148,10 @@ using for testing is bus 1 + port 1 for 2.0 devices and bus 3 + port 1
 for 1.1 devices.  Passing through any device plugged into that port
 and also assign them to the correct bus can be done this way:
 
-    qemu -M pc ${otheroptions}                           \
-        -usb                                             \
-        -device usb-ehci,id=ehci                         \
-        -device usb-host,bus=usb.0,hostbus=3,hostport=1  \
+    qemu -M pc ${otheroptions}                               \
+        -usb                                                 \
+        -device usb-ehci,id=ehci                             \
+        -device usb-host,bus=usb-bus.0,hostbus=3,hostport=1  \
         -device usb-host,bus=ehci.0,hostbus=1,hostport=1
 
 enjoy,
diff --git a/exec.c b/exec.c
index 786987a016..fa1e0c3d73 100644
--- a/exec.c
+++ b/exec.c
@@ -31,7 +31,7 @@
 #include "hw/qdev.h"
 #include "qemu/osdep.h"
 #include "sysemu/kvm.h"
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 #include "qemu/timer.h"
 #include "qemu/config-file.h"
 #include "exec/memory.h"
diff --git a/gdbstub.c b/gdbstub.c
index a0288a77fb..22ab12c68c 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1607,7 +1607,7 @@ static int cpu_gdb_write_register(CPUS390XState *env, uint8_t *mem_buf, int n)
 }
 #elif defined (TARGET_LM32)
 
-#include "hw/lm32_pic.h"
+#include "hw/lm32/lm32_pic.h"
 #define NUM_CORE_REGS (32 + 7)
 
 static int cpu_gdb_read_register(CPULM32State *env, uint8_t *mem_buf, int n)
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index d321c802f2..b476b810c5 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -11,12 +11,12 @@
  *
  */
 
-#include "hw/virtio.h"
-#include "hw/pc.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-9p.h"
+#include "hw/i386/pc.h"
 #include "qemu/sockets.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
-#include "virtio-9p-device.h"
 #include "virtio-9p-xattr.h"
 #include "virtio-9p-coth.h"
 
diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
index e30fdb6730..fe8e0ed19d 100644
--- a/hw/9pfs/virtio-9p-handle.c
+++ b/hw/9pfs/virtio-9p-handle.c
@@ -11,7 +11,7 @@
  *
  */
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "virtio-9p-xattr.h"
 #include <arpa/inet.h>
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
index f1b1c83a22..be898eccd9 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -11,7 +11,7 @@
  *
  */
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "virtio-9p-xattr.h"
 #include <arpa/inet.h>
diff --git a/hw/9pfs/virtio-9p-posix-acl.c b/hw/9pfs/virtio-9p-posix-acl.c
index 08bb0e8bca..339c5ecae4 100644
--- a/hw/9pfs/virtio-9p-posix-acl.c
+++ b/hw/9pfs/virtio-9p-posix-acl.c
@@ -13,7 +13,7 @@
 
 #include <sys/types.h>
 #include "qemu/xattr.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "fsdev/file-op-9p.h"
 #include "virtio-9p-xattr.h"
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index 730027900e..8ba2959dbb 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -11,7 +11,7 @@
  */
 #include <sys/socket.h>
 #include <sys/un.h>
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "qemu/error-report.h"
 #include "fsdev/qemu-fsdev.h"
diff --git a/hw/9pfs/virtio-9p-synth.c b/hw/9pfs/virtio-9p-synth.c
index e95a856d25..840e4ebb5a 100644
--- a/hw/9pfs/virtio-9p-synth.c
+++ b/hw/9pfs/virtio-9p-synth.c
@@ -12,7 +12,7 @@
  *
  */
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "virtio-9p-xattr.h"
 #include "fsdev/qemu-fsdev.h"
diff --git a/hw/9pfs/virtio-9p-xattr-user.c b/hw/9pfs/virtio-9p-xattr-user.c
index 5bb6020070..e0c92ebf9e 100644
--- a/hw/9pfs/virtio-9p-xattr-user.c
+++ b/hw/9pfs/virtio-9p-xattr-user.c
@@ -12,7 +12,7 @@
  */
 
 #include <sys/types.h>
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "fsdev/file-op-9p.h"
 #include "virtio-9p-xattr.h"
diff --git a/hw/9pfs/virtio-9p-xattr.c b/hw/9pfs/virtio-9p-xattr.c
index a83960676d..90ae565c19 100644
--- a/hw/9pfs/virtio-9p-xattr.c
+++ b/hw/9pfs/virtio-9p-xattr.c
@@ -11,7 +11,7 @@
  *
  */
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "virtio-9p.h"
 #include "fsdev/file-op-9p.h"
 #include "virtio-9p-xattr.h"
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 5cc4c92012..db2ae32fe8 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -11,8 +11,8 @@
  *
  */
 
-#include "hw/virtio.h"
-#include "hw/pc.h"
+#include "hw/virtio/virtio.h"
+#include "hw/i386/pc.h"
 #include "qemu/sockets.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 52b1c6997f..95a8ec3ba9 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -6,7 +6,7 @@
 #include <sys/time.h>
 #include <utime.h>
 #include <sys/resource.h>
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "fsdev/file-op-9p.h"
 #include "fsdev/virtio-9p-marshal.h"
 #include "qemu/thread.h"
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index d0b2ecb97f..1cb86fa323 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -1,219 +1,31 @@
-# core qdev-related obj files, also used by *-user:
-common-obj-y += qdev.o qdev-properties.o
-# irq.o needed for qdev GPIO handling:
-common-obj-y += irq.o
-
-ifeq ($(CONFIG_SOFTMMU),y)
-common-obj-y += usb/ ide/ pci/
-common-obj-y += loader.o
-common-obj-$(CONFIG_VIRTIO) += virtio-console.o
-common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
-common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
-common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
-common-obj-y += fw_cfg.o
-common-obj-$(CONFIG_PCI) += pci_bridge_dev.o
-common-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
-common-obj-$(CONFIG_PCI) += i82801b11.o
-common-obj-y += watchdog.o
-common-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
-common-obj-$(CONFIG_ECC) += ecc.o
-common-obj-$(CONFIG_NAND) += nand.o
-common-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
-common-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
-
-common-obj-$(CONFIG_M48T59) += m48t59.o
-common-obj-$(CONFIG_ESCC) += escc.o
-common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
-
-common-obj-$(CONFIG_SERIAL) += serial.o serial-isa.o
-common-obj-$(CONFIG_SERIAL_PCI) += serial-pci.o
-common-obj-$(CONFIG_PARALLEL) += parallel.o
-common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
-common-obj-$(CONFIG_PCSPK) += pcspk.o
-common-obj-$(CONFIG_PCKBD) += pckbd.o
-common-obj-$(CONFIG_FDC) += fdc.o
-common-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o acpi_ich9.o smbus_ich9.o
-common-obj-$(CONFIG_APM) += pm_smbus.o apm.o
-common-obj-$(CONFIG_DMA) += dma.o
-common-obj-$(CONFIG_I82374) += i82374.o
-common-obj-$(CONFIG_HPET) += hpet.o
-common-obj-$(CONFIG_APPLESMC) += applesmc.o
-ifeq ($(CONFIG_USB_SMARTCARD),y)
-common-obj-y += ccid-card-passthru.o
-common-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o
-endif
-common-obj-$(CONFIG_I8259) += i8259_common.o i8259.o
-common-obj-$(CONFIG_SDHCI) += sdhci.o
-common-obj-y += pam.o
-
-# PPC devices
-common-obj-$(CONFIG_PREP_PCI) += prep_pci.o
-common-obj-$(CONFIG_I82378) += i82378.o
-common-obj-$(CONFIG_PC87312) += pc87312.o
-# Mac shared devices
-common-obj-$(CONFIG_MACIO) += macio.o
-common-obj-$(CONFIG_CUDA) += cuda.o
-common-obj-$(CONFIG_ADB) += adb.o
-common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o
-common-obj-$(CONFIG_MAC_DBDMA) += mac_dbdma.o
-# OldWorld PowerMac
-common-obj-$(CONFIG_HEATHROW_PIC) += heathrow_pic.o
-common-obj-$(CONFIG_GRACKLE_PCI) += grackle_pci.o
-# NewWorld PowerMac
-common-obj-$(CONFIG_UNIN_PCI) += unin_pci.o
-common-obj-$(CONFIG_DEC_PCI) += dec_pci.o
-# PowerPC E500 boards
-common-obj-$(CONFIG_PPCE500_PCI) += ppce500_pci.o
-
-# MIPS devices
-common-obj-$(CONFIG_PIIX4) += piix4.o
-common-obj-$(CONFIG_G364FB) += g364fb.o
-common-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
-
-# Xilinx devices
-common-obj-$(CONFIG_XILINX) += xilinx_intc.o
-common-obj-$(CONFIG_XILINX) += xilinx_timer.o
-common-obj-$(CONFIG_XILINX) += xilinx_uartlite.o
-common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o
-common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o
-common-obj-$(CONFIG_XILINX_AXI) += stream.o
-
-# PKUnity SoC devices
-common-obj-$(CONFIG_PUV3) += puv3_intc.o
-common-obj-$(CONFIG_PUV3) += puv3_ost.o
-common-obj-$(CONFIG_PUV3) += puv3_gpio.o
-common-obj-$(CONFIG_PUV3) += puv3_pm.o
-common-obj-$(CONFIG_PUV3) += puv3_dma.o
-
-# ARM devices
-common-obj-$(CONFIG_ARM_TIMER) += arm_timer.o
-common-obj-$(CONFIG_PL011) += pl011.o
-common-obj-$(CONFIG_PL022) += pl022.o
-common-obj-$(CONFIG_PL031) += pl031.o
-common-obj-$(CONFIG_PL041) += pl041.o lm4549.o
-common-obj-$(CONFIG_PL050) += pl050.o
-common-obj-$(CONFIG_PL061) += pl061.o
-common-obj-$(CONFIG_PL080) += pl080.o
-common-obj-$(CONFIG_PL110) += pl110.o
-common-obj-$(CONFIG_PL181) += pl181.o
-common-obj-$(CONFIG_PL190) += pl190.o
-common-obj-$(CONFIG_PL310) += arm_l2x0.o
-common-obj-$(CONFIG_PL330) += pl330.o
-common-obj-$(CONFIG_VERSATILE_PCI) += versatile_pci.o
-common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o
-common-obj-$(CONFIG_CADENCE) += cadence_uart.o
-common-obj-$(CONFIG_CADENCE) += cadence_ttc.o
-common-obj-$(CONFIG_CADENCE) += cadence_gem.o
-common-obj-$(CONFIG_XGMAC) += xgmac.o
-
-# PCI watchdog devices
-common-obj-$(CONFIG_PCI) += wdt_i6300esb.o
-
-# IndustryPack
-common-obj-$(CONFIG_IPACK) += tpci200.o ipoctal232.o ipack.o
-
-# PCI network cards
-common-obj-$(CONFIG_NE2000_PCI) += ne2000.o
-common-obj-$(CONFIG_EEPRO100_PCI) += eepro100.o
-common-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o
-common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
-common-obj-$(CONFIG_E1000_PCI) += e1000.o
-common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
-common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o
-common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o
-
-common-obj-$(CONFIG_SMC91C111) += smc91c111.o
-common-obj-$(CONFIG_LAN9118) += lan9118.o
-common-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o
-common-obj-$(CONFIG_OPENCORES_ETH) += opencores_eth.o
-
-# SCSI layer
-common-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
-common-obj-$(CONFIG_MEGASAS_SCSI_PCI) += megasas.o
-common-obj-$(CONFIG_ESP) += esp.o
-common-obj-$(CONFIG_ESP_PCI) += esp-pci.o
-
-common-obj-y += sysbus.o isa-bus.o
-common-obj-y += qdev-addr.o
-
-# VGA
-common-obj-$(CONFIG_VGA_PCI) += vga-pci.o
-common-obj-$(CONFIG_VGA_ISA) += vga-isa.o
-common-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
-common-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
-common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
-common-obj-$(CONFIG_VGA_CIRRUS) += cirrus_vga.o
-
-common-obj-$(CONFIG_RC4030) += rc4030.o
-common-obj-$(CONFIG_DP8393X) += dp8393x.o
-common-obj-$(CONFIG_DS1225Y) += ds1225y.o
-common-obj-$(CONFIG_MIPSNET) += mipsnet.o
-
-common-obj-y += null-machine.o
-
-# Sound
-sound-obj-y =
-sound-obj-$(CONFIG_SB16) += sb16.o
-sound-obj-$(CONFIG_ES1370) += es1370.o
-sound-obj-$(CONFIG_AC97) += ac97.o
-sound-obj-$(CONFIG_ADLIB) += fmopl.o adlib.o
-sound-obj-$(CONFIG_GUS) += gus.o gusemu_hal.o gusemu_mixer.o
-sound-obj-$(CONFIG_CS4231A) += cs4231a.o
-sound-obj-$(CONFIG_HDA) += intel-hda.o hda-audio.o
-
-$(obj)/adlib.o $(obj)/fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0
-
-common-obj-$(CONFIG_SOUND) += $(sound-obj-y)
-
-common-obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/
-
-common-obj-y += usb/
-common-obj-$(CONFIG_PTIMER) += ptimer.o
-common-obj-$(CONFIG_MAX7310) += max7310.o
-common-obj-$(CONFIG_WM8750) += wm8750.o
-common-obj-$(CONFIG_TWL92230) += twl92230.o
-common-obj-$(CONFIG_TSC2005) += tsc2005.o
-common-obj-$(CONFIG_LM832X) += lm832x.o
-common-obj-$(CONFIG_TMP105) += tmp105.o
-common-obj-$(CONFIG_STELLARIS_INPUT) += stellaris_input.o
-common-obj-$(CONFIG_SSD0303) += ssd0303.o
-common-obj-$(CONFIG_SSD0323) += ssd0323.o
-common-obj-$(CONFIG_ADS7846) += ads7846.o
-common-obj-$(CONFIG_MAX111X) += max111x.o
-common-obj-$(CONFIG_DS1338) += ds1338.o
-common-obj-y += i2c.o smbus.o smbus_eeprom.o
-common-obj-y += eeprom93xx.o
-common-obj-y += scsi-disk.o cdrom.o hd-geometry.o block-common.o
-common-obj-y += scsi-generic.o scsi-bus.o
-common-obj-y += hid.o
-common-obj-$(CONFIG_SSI) += ssi.o
-common-obj-$(CONFIG_SSI_M25P80) += m25p80.o
-common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
-common-obj-$(CONFIG_SD) += sd.o
-common-obj-y += bt.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
-common-obj-y += bt-hci-csr.o
-common-obj-y += ps2.o
-common-obj-y += qdev-properties-system.o
-
-# xen backend driver support
-common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
-common-obj-$(CONFIG_XEN_BACKEND) += xen_console.o xenfb.o xen_disk.o xen_nic.o
-
-# Per-target files
-# virtio has to be here due to weird dependency between PCI and virtio-net.
-# need to fix this properly
-obj-$(CONFIG_VIRTIO) += dataplane/
-obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o
-obj-$(CONFIG_VIRTIO) += virtio-serial-bus.o virtio-scsi.o
-obj-$(CONFIG_SOFTMMU) += vhost_net.o
-obj-$(CONFIG_VHOST_NET) += vhost.o
-obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/
-obj-$(CONFIG_VGA) += vga.o
-
-# Inter-VM PCI shared memory & VFIO PCI device assignment
-ifeq ($(CONFIG_PCI), y)
-obj-$(CONFIG_KVM) += ivshmem.o
-obj-$(CONFIG_LINUX) += vfio_pci.o
-endif
-
-endif
+devices-dirs-$(CONFIG_REALLY_VIRTFS) += 9pfs/
+devices-dirs-$(CONFIG_ACPI) += acpi/
+devices-dirs-$(CONFIG_SOFTMMU) += audio/
+devices-dirs-$(CONFIG_SOFTMMU) += block/
+devices-dirs-$(CONFIG_SOFTMMU) += bt/
+devices-dirs-$(CONFIG_SOFTMMU) += char/
+devices-dirs-$(CONFIG_SOFTMMU) += cpu/
+devices-dirs-$(CONFIG_SOFTMMU) += display/
+devices-dirs-$(CONFIG_SOFTMMU) += dma/
+devices-dirs-$(CONFIG_SOFTMMU) += gpio/
+devices-dirs-$(CONFIG_SOFTMMU) += i2c/
+devices-dirs-$(CONFIG_SOFTMMU) += ide/
+devices-dirs-$(CONFIG_SOFTMMU) += input/
+devices-dirs-$(CONFIG_SOFTMMU) += intc/
+devices-dirs-$(CONFIG_SOFTMMU) += isa/
+devices-dirs-$(CONFIG_SOFTMMU) += misc/
+devices-dirs-$(CONFIG_SOFTMMU) += net/
+devices-dirs-$(CONFIG_SOFTMMU) += nvram/
+devices-dirs-$(CONFIG_SOFTMMU) += pci/
+devices-dirs-$(CONFIG_PCI) += pci-bridge/ pci-host/
+devices-dirs-$(CONFIG_SOFTMMU) += scsi/
+devices-dirs-$(CONFIG_SOFTMMU) += sd/
+devices-dirs-$(CONFIG_SOFTMMU) += ssi/
+devices-dirs-$(CONFIG_SOFTMMU) += timer/
+devices-dirs-$(CONFIG_SOFTMMU) += usb/
+devices-dirs-$(CONFIG_SOFTMMU) += virtio/
+devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
+devices-dirs-$(CONFIG_SOFTMMU) += xen/
+devices-dirs-y += core/
+common-obj-y += $(devices-dirs-y)
+obj-y += $(devices-dirs-y)
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
new file mode 100644
index 0000000000..a0b63b5626
--- /dev/null
+++ b/hw/acpi/Makefile.objs
@@ -0,0 +1,2 @@
+common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o
+
diff --git a/hw/acpi.c b/hw/acpi/core.c
index 856da81f0c..64b871846d 100644
--- a/hw/acpi.c
+++ b/hw/acpi/core.c
@@ -20,8 +20,8 @@
  */
 #include "sysemu/sysemu.h"
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/acpi.h"
+#include "hw/i386/pc.h"
+#include "hw/acpi/acpi.h"
 #include "monitor/monitor.h"
 #include "qemu/config-file.h"
 #include "qapi/opts-visitor.h"
diff --git a/hw/acpi_ich9.c b/hw/acpi/ich9.c
index 7b34a03866..e663d297a1 100644
--- a/hw/acpi_ich9.c
+++ b/hw/acpi/ich9.c
@@ -24,15 +24,15 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
-#include "hw/acpi.h"
+#include "hw/acpi/acpi.h"
 #include "sysemu/kvm.h"
 #include "exec/address-spaces.h"
 
-#include "hw/ich9.h"
+#include "hw/i386/ich9.h"
 
 //#define DEBUG
 
diff --git a/hw/acpi_piix4.c b/hw/acpi/piix4.c
index 48a32b5aa0..88386d7ea7 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi/piix4.c
@@ -19,15 +19,15 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/apm.h"
-#include "hw/pm_smbus.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/apm.h"
+#include "hw/i2c/pm_smbus.h"
 #include "hw/pci/pci.h"
-#include "hw/acpi.h"
+#include "hw/acpi/acpi.h"
 #include "sysemu/sysemu.h"
 #include "qemu/range.h"
 #include "exec/ioport.h"
-#include "hw/fw_cfg.h"
+#include "hw/nvram/fw_cfg.h"
 #include "exec/address-spaces.h"
 
 //#define DEBUG
diff --git a/hw/alpha/Makefile.objs b/hw/alpha/Makefile.objs
index db868d2ea6..5c742756f0 100644
--- a/hw/alpha/Makefile.objs
+++ b/hw/alpha/Makefile.objs
@@ -1,6 +1 @@
-obj-y = mc146818rtc.o
-obj-y += alpha_typhoon.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
-obj-y += dp264.o pci.o
+obj-y += dp264.o pci.o typhoon.o
diff --git a/hw/alpha_sys.h b/hw/alpha/alpha_sys.h
index b4ebd2a9cc..50e7730caa 100644
--- a/hw/alpha_sys.h
+++ b/hw/alpha/alpha_sys.h
@@ -6,7 +6,7 @@
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
 #include "hw/ide.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/irq.h"
 
 
diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 13aaa57b90..8695efb8ef 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -10,12 +10,12 @@
 #include "elf.h"
 #include "hw/loader.h"
 #include "hw/boards.h"
-#include "hw/alpha_sys.h"
+#include "alpha_sys.h"
 #include "sysemu/sysemu.h"
-#include "hw/mc146818rtc.h"
+#include "hw/timer/mc146818rtc.h"
 #include "hw/ide.h"
-#include "hw/i8254.h"
-#include "hw/serial.h"
+#include "hw/timer/i8254.h"
+#include "hw/char/serial.h"
 
 #define MAX_IDE_BUS 2
 
diff --git a/hw/alpha/pci.c b/hw/alpha/pci.c
index 84628686ad..7327d488fd 100644
--- a/hw/alpha/pci.c
+++ b/hw/alpha/pci.c
@@ -7,7 +7,7 @@
  */
 
 #include "config.h"
-#include "hw/alpha_sys.h"
+#include "alpha_sys.h"
 #include "qemu/log.h"
 #include "sysemu/sysemu.h"
 
diff --git a/hw/alpha_typhoon.c b/hw/alpha/typhoon.c
index b1e0044a35..faec8dcebd 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -9,9 +9,9 @@
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "hw/hw.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "sysemu/sysemu.h"
-#include "hw/alpha_sys.h"
+#include "alpha_sys.h"
 #include "exec/address-spaces.h"
 
 
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index f5f7d0e539..9e3a06fc18 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -1,36 +1,7 @@
-obj-y += zynq_slcr.o
-obj-y += xilinx_spips.o
-obj-y += arm_gic.o arm_gic_common.o
-obj-y += a9scu.o
-obj-y += realview_gic.o arm_sysctl.o arm11mpcore.o a9mpcore.o
-obj-y += exynos4210_gic.o exynos4210_combiner.o
-obj-y += exynos4210_uart.o exynos4210_pwm.o
-obj-y += exynos4210_pmu.o exynos4210_mct.o exynos4210_fimd.o
-obj-y += exynos4210_rtc.o exynos4210_i2c.o
-obj-y += arm_mptimer.o a15mpcore.o
-obj-y += armv7m_nvic.o stellaris_enet.o
-obj-y += pxa2xx_timer.o pxa2xx_dma.o
-obj-y += pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o pxa2xx_keypad.o
-obj-y += zaurus.o ide/microdrive.o tc6393xb.o
-obj-y += omap_lcdc.o omap_dma.o omap_clk.o omap_mmc.o omap_i2c.o \
-                omap_gpio.o omap_intc.o omap_uart.o
-obj-y += omap_dss.o soc_dma.o omap_gptimer.o omap_synctimer.o \
-                omap_gpmc.o omap_sdrc.o omap_spi.o omap_tap.o omap_l4.o
-obj-y += tsc210x.o
-obj-y += blizzard.o onenand.o cbus.o tusb6010.o usb/hcd-musb.o
-obj-y += mst_fpga.o
-obj-y += bitbang_i2c.o marvell_88w8618_audio.o
-obj-y += framebuffer.o
-obj-y += strongarm.o
-obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o
-obj-$(CONFIG_KVM) += kvm/arm_gic.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 obj-y += boot.o collie.o exynos4_boards.o gumstix.o highbank.o
 obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o
 obj-y += omap_sx1.o palm.o pic_cpu.o realview.o spitz.o stellaris.o
 obj-y += tosa.o versatilepb.o vexpress.o xilinx_zynq.o z2.o
 
 obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o
-obj-y += omap1.o omap2.o
+obj-y += omap1.o omap2.o strongarm.o
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
index 1d5bb592c4..a4bdd5f30f 100644
--- a/hw/arm/armv7m.c
+++ b/hw/arm/armv7m.c
@@ -8,7 +8,7 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "hw/loader.h"
 #include "elf.h"
 
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 43253fd34a..c79c590171 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -9,7 +9,7 @@
 
 #include "config.h"
 #include "hw/hw.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
diff --git a/hw/arm/collie.c b/hw/arm/collie.c
index 17fddc8d5b..5420bb4ba8 100644
--- a/hw/arm/collie.c
+++ b/hw/arm/collie.c
@@ -11,10 +11,10 @@
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "hw/boards.h"
-#include "hw/devices.h"
-#include "hw/strongarm.h"
-#include "hw/arm-misc.h"
-#include "hw/flash.h"
+#include "hw/arm/devices.h"
+#include "strongarm.h"
+#include "hw/arm.h"
+#include "hw/block/flash.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
index 4592514bb2..78b8b7407a 100644
--- a/hw/arm/exynos4210.c
+++ b/hw/arm/exynos4210.c
@@ -24,9 +24,9 @@
 #include "hw/boards.h"
 #include "sysemu/sysemu.h"
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "hw/loader.h"
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 #include "hw/usb/hcd-ehci.h"
 
 #define EXYNOS4210_CHIPID_ADDR         0x10000000
diff --git a/hw/arm/exynos4_boards.c b/hw/arm/exynos4_boards.c
index 473da349bd..ba14a1fd09 100644
--- a/hw/arm/exynos4_boards.c
+++ b/hw/arm/exynos4_boards.c
@@ -24,9 +24,9 @@
 #include "sysemu/sysemu.h"
 #include "hw/sysbus.h"
 #include "net/net.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "exec/address-spaces.h"
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 #include "hw/boards.h"
 
 #undef DEBUG
diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c
index 8859b7392f..4d800c9547 100644
--- a/hw/arm/gumstix.c
+++ b/hw/arm/gumstix.c
@@ -35,10 +35,10 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "net/net.h"
-#include "hw/flash.h"
-#include "hw/devices.h"
+#include "hw/block/flash.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
index a622224dcc..58f73c1bd3 100644
--- a/hw/arm/highbank.c
+++ b/hw/arm/highbank.c
@@ -18,8 +18,8 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
 #include "hw/loader.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/arm/integratorcp.c b/hw/arm/integratorcp.c
index e0ba327a55..8d0fb7584a 100644
--- a/hw/arm/integratorcp.c
+++ b/hw/arm/integratorcp.c
@@ -8,9 +8,9 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "net/net.h"
 #include "exec/address-spaces.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/arm/kzm.c b/hw/arm/kzm.c
index ec50a319ac..46264cdeac 100644
--- a/hw/arm/kzm.c
+++ b/hw/arm/kzm.c
@@ -16,13 +16,13 @@
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 #include "hw/hw.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/serial.h"
-#include "hw/imx.h"
+#include "hw/char/serial.h"
+#include "hw/arm/imx.h"
 
     /* Memory map for Kzm Emulation Baseboard:
      * 0x00000000-0x00003fff 16k secure ROM       IGNORED
diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
index aea908f036..b78e6f00d3 100644
--- a/hw/arm/mainstone.c
+++ b/hw/arm/mainstone.c
@@ -12,12 +12,12 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "hw/hw.h"
-#include "hw/pxa.h"
-#include "hw/arm-misc.h"
+#include "hw/arm/pxa.h"
+#include "hw/arm.h"
 #include "net/net.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index ea8473db3e..97b13405e6 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -10,18 +10,18 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "qemu/timer.h"
 #include "hw/ptimer.h"
 #include "block/block.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "ui/console.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "ui/pixel_ops.h"
diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
index 6747c1c547..ba8dc3e01a 100644
--- a/hw/arm/nseries.c
+++ b/hw/arm/nseries.c
@@ -20,14 +20,14 @@
 
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
-#include "hw/omap.h"
-#include "hw/arm-misc.h"
+#include "hw/arm/omap.h"
+#include "hw/arm.h"
 #include "hw/irq.h"
 #include "ui/console.h"
 #include "hw/boards.h"
-#include "hw/i2c.h"
-#include "hw/devices.h"
-#include "hw/flash.h"
+#include "hw/i2c/i2c.h"
+#include "hw/arm/devices.h"
+#include "hw/block/flash.h"
 #include "hw/hw.h"
 #include "hw/bt.h"
 #include "hw/loader.h"
@@ -129,8 +129,6 @@ static void n800_mmc_cs_cb(void *opaque, int line, int level)
     /* TODO: this seems to actually be connected to the menelaus, to
      * which also both MMC slots connect.  */
     omap_mmc_enable((struct omap_mmc_s *) opaque, !level);
-
-    printf("%s: MMC slot %i active\n", __FUNCTION__, level + 1);
 }
 
 static void n8x0_gpio_setup(struct n800_s *s)
@@ -428,9 +426,6 @@ struct mipid_s {
 
 static void mipid_reset(struct mipid_s *s)
 {
-    if (!s->sleep)
-        fprintf(stderr, "%s: Display off\n", __FUNCTION__);
-
     s->pm = 0;
     s->cmd = 0;
 
@@ -578,11 +573,9 @@ static uint32_t mipid_txrx(void *opaque, uint32_t cmd, int len)
 
     case 0x28:	/* DISPOFF */
         s->onoff = 0;
-        fprintf(stderr, "%s: Display off\n", __FUNCTION__);
         break;
     case 0x29:	/* DISPON */
         s->onoff = 1;
-        fprintf(stderr, "%s: Display on\n", __FUNCTION__);
         break;
 
     case 0x2a:	/* CASET */
@@ -669,7 +662,8 @@ static uint32_t mipid_txrx(void *opaque, uint32_t cmd, int len)
 
     default:
     bad_cmd:
-        fprintf(stderr, "%s: unknown command %02x\n", __FUNCTION__, s->cmd);
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: unknown command %02x\n", __func__, s->cmd);
         break;
     }
 
@@ -1347,7 +1341,6 @@ static void n8x0_init(QEMUMachineInitArgs *args,
 
     if (option_rom[0].name &&
         (args->boot_device[0] == 'n' || !args->kernel_filename)) {
-        int rom_size;
         uint8_t nolo_tags[0x10000];
         /* No, wait, better start at the ROM.  */
         s->mpu->cpu->env.regs[15] = OMAP2_Q2_BASE + 0x400000;
@@ -1361,10 +1354,9 @@ static void n8x0_init(QEMUMachineInitArgs *args,
          *
          * The code above is for loading the `zImage' file from Nokia
          * images.  */
-        rom_size = load_image_targphys(option_rom[0].name,
-                                       OMAP2_Q2_BASE + 0x400000,
-                                       sdram_size - 0x400000);
-        printf("%i bytes of image loaded\n", rom_size);
+        load_image_targphys(option_rom[0].name,
+                            OMAP2_Q2_BASE + 0x400000,
+                            sdram_size - 0x400000);
 
         n800_setup_nolo_tags(nolo_tags);
         cpu_physical_memory_write(OMAP2_SRAM_BASE, nolo_tags, 0x10000);
diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
index 3245c62e68..17caa61822 100644
--- a/hw/arm/omap1.c
+++ b/hw/arm/omap1.c
@@ -17,10 +17,10 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/arm-misc.h"
-#include "hw/omap.h"
+#include "hw/arm.h"
+#include "hw/arm/omap.h"
 #include "sysemu/sysemu.h"
-#include "hw/soc_dma.h"
+#include "hw/arm/soc_dma.h"
 #include "sysemu/blockdev.h"
 #include "qemu/range.h"
 #include "hw/sysbus.h"
diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c
index 0a2cd7bab6..010c483e8c 100644
--- a/hw/arm/omap2.c
+++ b/hw/arm/omap2.c
@@ -20,13 +20,13 @@
 
 #include "sysemu/blockdev.h"
 #include "hw/hw.h"
-#include "hw/arm-misc.h"
-#include "hw/omap.h"
+#include "hw/arm.h"
+#include "hw/arm/omap.h"
 #include "sysemu/sysemu.h"
 #include "qemu/timer.h"
 #include "char/char.h"
-#include "hw/flash.h"
-#include "hw/soc_dma.h"
+#include "hw/block/flash.h"
+#include "hw/arm/soc_dma.h"
 #include "hw/sysbus.h"
 #include "audio/audio.h"
 
diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
index 85982334bd..aa85602aa6 100644
--- a/hw/arm/omap_sx1.c
+++ b/hw/arm/omap_sx1.c
@@ -27,10 +27,10 @@
  */
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 #include "hw/boards.h"
-#include "hw/arm-misc.h"
-#include "hw/flash.h"
+#include "hw/arm.h"
+#include "hw/block/flash.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/arm/palm.c b/hw/arm/palm.c
index baeb585067..0bc11aed2b 100644
--- a/hw/arm/palm.c
+++ b/hw/arm/palm.c
@@ -20,10 +20,10 @@
 #include "audio/audio.h"
 #include "sysemu/sysemu.h"
 #include "ui/console.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 #include "hw/boards.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/arm/pic_cpu.c b/hw/arm/pic_cpu.c
index 3a3f06566b..787767f51f 100644
--- a/hw/arm/pic_cpu.c
+++ b/hw/arm/pic_cpu.c
@@ -8,7 +8,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "sysemu/kvm.h"
 
 /* Input 0 is IRQ and input 1 is FIQ.  */
diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
index b7ca511d45..bbecc770ed 100644
--- a/hw/arm/pxa2xx.c
+++ b/hw/arm/pxa2xx.c
@@ -8,10 +8,10 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "sysemu/sysemu.h"
-#include "hw/serial.h"
-#include "hw/i2c.h"
+#include "hw/char/serial.h"
+#include "hw/i2c/i2c.h"
 #include "hw/ssi.h"
 #include "char/char.h"
 #include "sysemu/blockdev.h"
diff --git a/hw/arm/pxa2xx_gpio.c b/hw/arm/pxa2xx_gpio.c
index 55ebcd724a..fa31575edd 100644
--- a/hw/arm/pxa2xx_gpio.c
+++ b/hw/arm/pxa2xx_gpio.c
@@ -9,7 +9,7 @@
 
 #include "hw/hw.h"
 #include "hw/sysbus.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 
 #define PXA2XX_GPIO_BANKS	4
 
diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c
index 25e90895e1..835d07c341 100644
--- a/hw/arm/pxa2xx_pic.c
+++ b/hw/arm/pxa2xx_pic.c
@@ -9,7 +9,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "hw/sysbus.h"
 
 #define ICIP	0x00	/* Interrupt Controller IRQ Pending register */
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index 5fb490c832..afd52d31be 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -8,14 +8,14 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
-#include "hw/primecell.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/primecell.h"
+#include "hw/arm/devices.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index f5832bea93..fa434dc68e 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -11,16 +11,16 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
-#include "hw/arm-misc.h"
+#include "hw/arm/pxa.h"
+#include "hw/arm.h"
 #include "sysemu/sysemu.h"
 #include "hw/pcmcia.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "hw/ssi.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "qemu/timer.h"
-#include "hw/devices.h"
-#include "hw/sharpsl.h"
+#include "hw/arm/devices.h"
+#include "hw/arm/sharpsl.h"
 #include "ui/console.h"
 #include "block/block.h"
 #include "audio/audio.h"
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index f4ce7945f3..952087ce2d 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -9,10 +9,10 @@
 
 #include "hw/sysbus.h"
 #include "hw/ssi.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
 #include "qemu/timer.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "net/net.h"
 #include "hw/boards.h"
 #include "exec/address-spaces.h"
diff --git a/hw/strongarm.c b/hw/arm/strongarm.c
index 49f9577e32..5873a3c956 100644
--- a/hw/strongarm.c
+++ b/hw/arm/strongarm.c
@@ -27,9 +27,9 @@
  *  GNU GPL, version 2 or (at your option) any later version.
  */
 #include "hw/sysbus.h"
-#include "hw/strongarm.h"
+#include "strongarm.h"
 #include "qemu/error-report.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "char/char.h"
 #include "sysemu/sysemu.h"
 #include "hw/ssi.h"
diff --git a/hw/strongarm.h b/hw/arm/strongarm.h
index 2893f94445..2893f94445 100644
--- a/hw/strongarm.h
+++ b/hw/arm/strongarm.h
diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
index 747888c64e..c4362d4313 100644
--- a/hw/arm/tosa.c
+++ b/hw/arm/tosa.c
@@ -12,14 +12,14 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
-#include "hw/sharpsl.h"
+#include "hw/arm/pxa.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
+#include "hw/arm/sharpsl.h"
 #include "hw/pcmcia.h"
 #include "block/block.h"
 #include "hw/boards.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "hw/ssi.h"
 #include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index baaa265888..d9be604481 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -8,16 +8,16 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/pci/pci.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "hw/boards.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 
 #define VERSATILE_FLASH_ADDR 0x34000000
 #define VERSATILE_FLASH_SIZE (64 * 1024 * 1024)
diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index 2e1a5d0e5b..96e098579f 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -22,15 +22,15 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
-#include "hw/primecell.h"
-#include "hw/devices.h"
+#include "hw/arm.h"
+#include "hw/arm/primecell.h"
+#include "hw/arm/devices.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "exec/address-spaces.h"
 #include "sysemu/blockdev.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 
 #define VEXPRESS_BOARD_ID 0x8e0
 #define VEXPRESS_FLASH_SIZE (64 * 1024 * 1024)
diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
index 6f362865f9..8d65f796f9 100644
--- a/hw/arm/xilinx_zynq.c
+++ b/hw/arm/xilinx_zynq.c
@@ -16,12 +16,12 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "net/net.h"
 #include "exec/address-spaces.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/blockdev.h"
 #include "hw/loader.h"
 #include "hw/ssi.h"
@@ -86,8 +86,7 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
         spi = (SSIBus *)qdev_get_child_bus(dev, bus_name);
 
         for (j = 0; j < num_ss; ++j) {
-            flash_dev = ssi_create_slave_no_init(spi, "n25q128");
-            qdev_init_nofail(flash_dev);
+            flash_dev = ssi_create_slave(spi, "n25q128");
 
             cs_line = qdev_get_gpio_in(flash_dev, 0);
             sysbus_connect_irq(busdev, i * num_ss + j + 1, cs_line);
diff --git a/hw/arm/z2.c b/hw/arm/z2.c
index cbb6d8085e..3e272088f5 100644
--- a/hw/arm/z2.c
+++ b/hw/arm/z2.c
@@ -12,14 +12,14 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
-#include "hw/arm-misc.h"
-#include "hw/devices.h"
-#include "hw/i2c.h"
+#include "hw/arm/pxa.h"
+#include "hw/arm.h"
+#include "hw/arm/devices.h"
+#include "hw/i2c/i2c.h"
 #include "hw/ssi.h"
 #include "hw/boards.h"
 #include "sysemu/sysemu.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/blockdev.h"
 #include "ui/console.h"
 #include "audio/audio.h"
diff --git a/hw/audio/Makefile.objs b/hw/audio/Makefile.objs
new file mode 100644
index 0000000000..237510204b
--- /dev/null
+++ b/hw/audio/Makefile.objs
@@ -0,0 +1,20 @@
+# Sound
+sound-obj-y =
+sound-obj-$(CONFIG_SB16) += sb16.o
+sound-obj-$(CONFIG_ES1370) += es1370.o
+sound-obj-$(CONFIG_AC97) += ac97.o
+sound-obj-$(CONFIG_ADLIB) += fmopl.o adlib.o
+sound-obj-$(CONFIG_GUS) += gus.o gusemu_hal.o gusemu_mixer.o
+sound-obj-$(CONFIG_CS4231A) += cs4231a.o
+sound-obj-$(CONFIG_HDA) += intel-hda.o hda-codec.o
+
+common-obj-$(CONFIG_SOUND) += $(sound-obj-y)
+common-obj-$(CONFIG_PCSPK) += pcspk.o
+common-obj-$(CONFIG_WM8750) += wm8750.o
+common-obj-$(CONFIG_PL041) += pl041.o lm4549.o
+
+common-obj-$(CONFIG_CS4231) += cs4231.o
+common-obj-$(CONFIG_MARVELL_88W8618) += marvell_88w8618.o
+common-obj-$(CONFIG_MILKYMIST) += milkymist-ac97.o
+
+$(obj)/adlib.o $(obj)/fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0
diff --git a/hw/ac97.c b/hw/audio/ac97.c
index c7d601fdb7..ab68ec6204 100644
--- a/hw/ac97.c
+++ b/hw/audio/ac97.c
@@ -18,7 +18,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "audio/audio.h"
 #include "hw/pci/pci.h"
 #include "sysemu/dma.h"
diff --git a/hw/adlib.c b/hw/audio/adlib.c
index e6bce59512..4a58e6efb7 100644
--- a/hw/adlib.c
+++ b/hw/audio/adlib.c
@@ -23,9 +23,9 @@
  */
 
 #include "hw/hw.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "audio/audio.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 //#define DEBUG
 
@@ -47,7 +47,7 @@
 void YMF262UpdateOneQEMU (int which, INT16 *dst, int length);
 #define SHIFT 2
 #else
-#include "hw/fmopl.h"
+#include "fmopl.h"
 #define SHIFT 1
 #endif
 
diff --git a/hw/cs4231.c b/hw/audio/cs4231.c
index 2975336057..2975336057 100644
--- a/hw/cs4231.c
+++ b/hw/audio/cs4231.c
diff --git a/hw/cs4231a.c b/hw/audio/cs4231a.c
index f005f25899..5711b62f83 100644
--- a/hw/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -22,9 +22,9 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "audio/audio.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/qdev.h"
 #include "qemu/timer.h"
 
diff --git a/hw/es1370.c b/hw/audio/es1370.c
index e64cf23099..9fe57087bf 100644
--- a/hw/es1370.c
+++ b/hw/audio/es1370.c
@@ -27,7 +27,7 @@
 #define SILENT_ES1370
 
 #include "hw/hw.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "audio/audio.h"
 #include "hw/pci/pci.h"
 #include "sysemu/dma.h"
diff --git a/hw/fmopl.c b/hw/audio/fmopl.c
index e50ba6c0ec..f0a023477d 100644
--- a/hw/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -39,7 +39,7 @@
 #include <stdarg.h>
 #include <math.h>
 //#include "driver.h"		/* use M.A.M.E. */
-#include "hw/fmopl.h"
+#include "fmopl.h"
 
 #ifndef PI
 #define PI 3.14159265358979323846
diff --git a/hw/fmopl.h b/hw/audio/fmopl.h
index 24ba5f4802..24ba5f4802 100644
--- a/hw/fmopl.h
+++ b/hw/audio/fmopl.h
diff --git a/hw/gus.c b/hw/audio/gus.c
index d2682249ca..0604d6eac3 100644
--- a/hw/gus.c
+++ b/hw/audio/gus.c
@@ -22,11 +22,11 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "audio/audio.h"
-#include "hw/isa.h"
-#include "hw/gusemu.h"
-#include "hw/gustate.h"
+#include "hw/isa/isa.h"
+#include "gusemu.h"
+#include "gustate.h"
 
 #define dolog(...) AUD_log ("audio", __VA_ARGS__)
 #ifdef DEBUG
diff --git a/hw/gusemu.h b/hw/audio/gusemu.h
index 331bb6fec0..331bb6fec0 100644
--- a/hw/gusemu.h
+++ b/hw/audio/gusemu.h
diff --git a/hw/gusemu_hal.c b/hw/audio/gusemu_hal.c
index 0eee617652..6096690735 100644
--- a/hw/gusemu_hal.c
+++ b/hw/audio/gusemu_hal.c
@@ -26,8 +26,8 @@
  * TODO: check mixer: see 7.20 of sdk for panning pos (applies to all gus models?)?
  */
 
-#include "hw/gustate.h"
-#include "hw/gusemu.h"
+#include "gustate.h"
+#include "gusemu.h"
 
 #define GUSregb(position) (*            (gusptr+(position)))
 #define GUSregw(position) (*(GUSword *) (gusptr+(position)))
diff --git a/hw/gusemu_mixer.c b/hw/audio/gusemu_mixer.c
index 816c58a7ed..6d8d9ced11 100644
--- a/hw/gusemu_mixer.c
+++ b/hw/audio/gusemu_mixer.c
@@ -22,8 +22,8 @@
  * THE SOFTWARE.
  */
 
-#include "hw/gusemu.h"
-#include "hw/gustate.h"
+#include "gusemu.h"
+#include "gustate.h"
 
 #define GUSregb(position)  (*            (gusptr+(position)))
 #define GUSregw(position)  (*(GUSword *) (gusptr+(position)))
diff --git a/hw/gustate.h b/hw/audio/gustate.h
index ece903abb9..ece903abb9 100644
--- a/hw/gustate.h
+++ b/hw/audio/gustate.h
diff --git a/hw/hda-audio.c b/hw/audio/hda-codec.c
index 6bdd8209fb..362d8c0cc0 100644
--- a/hw/hda-audio.c
+++ b/hw/audio/hda-codec.c
@@ -19,8 +19,8 @@
 
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
-#include "hw/intel-hda.h"
-#include "hw/intel-hda-defs.h"
+#include "intel-hda.h"
+#include "intel-hda-defs.h"
 #include "audio/audio.h"
 
 /* -------------------------------------------------------------------------- */
diff --git a/hw/intel-hda-defs.h b/hw/audio/intel-hda-defs.h
index 2e37e5b874..2e37e5b874 100644
--- a/hw/intel-hda-defs.h
+++ b/hw/audio/intel-hda-defs.h
diff --git a/hw/intel-hda.c b/hw/audio/intel-hda.c
index 728b60fb9a..3d8077ac0d 100644
--- a/hw/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -21,9 +21,9 @@
 #include "hw/pci/pci.h"
 #include "hw/pci/msi.h"
 #include "qemu/timer.h"
-#include "hw/audiodev.h"
-#include "hw/intel-hda.h"
-#include "hw/intel-hda-defs.h"
+#include "hw/audio/audio.h"
+#include "intel-hda.h"
+#include "intel-hda-defs.h"
 #include "sysemu/dma.h"
 
 /* --------------------------------------------------------------------- */
diff --git a/hw/intel-hda.h b/hw/audio/intel-hda.h
index 2544f0a344..2544f0a344 100644
--- a/hw/intel-hda.h
+++ b/hw/audio/intel-hda.h
diff --git a/hw/lm4549.c b/hw/audio/lm4549.c
index 67335cba61..d75f7ec21f 100644
--- a/hw/lm4549.c
+++ b/hw/audio/lm4549.c
@@ -15,7 +15,7 @@
 
 #include "hw/hw.h"
 #include "audio/audio.h"
-#include "hw/lm4549.h"
+#include "lm4549.h"
 
 #if 0
 #define LM4549_DEBUG  1
diff --git a/hw/lm4549.h b/hw/audio/lm4549.h
index 812a7a4440..812a7a4440 100644
--- a/hw/lm4549.h
+++ b/hw/audio/lm4549.h
diff --git a/hw/marvell_88w8618_audio.c b/hw/audio/marvell_88w8618.c
index e042046e4f..f9b68fd311 100644
--- a/hw/marvell_88w8618_audio.c
+++ b/hw/audio/marvell_88w8618.c
@@ -11,7 +11,7 @@
  */
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "hw/sysbus.h"
 #include "audio/audio.h"
 
diff --git a/hw/milkymist-ac97.c b/hw/audio/milkymist-ac97.c
index e08e9dca16..e08e9dca16 100644
--- a/hw/milkymist-ac97.c
+++ b/hw/audio/milkymist-ac97.c
diff --git a/hw/pcspk.c b/hw/audio/pcspk.c
index d533415950..34e0df7485 100644
--- a/hw/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -23,12 +23,12 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 #include "audio/audio.h"
 #include "qemu/timer.h"
-#include "hw/i8254.h"
-#include "hw/pcspk.h"
+#include "hw/timer/i8254.h"
+#include "hw/audio/pcspk.h"
 
 #define PCSPK_BUF_LEN 1792
 #define PCSPK_SAMPLE_RATE 32000
diff --git a/hw/pl041.c b/hw/audio/pl041.c
index 92dddc2923..653ab4fbb4 100644
--- a/hw/pl041.c
+++ b/hw/audio/pl041.c
@@ -22,8 +22,8 @@
 
 #include "hw/sysbus.h"
 
-#include "hw/pl041.h"
-#include "hw/lm4549.h"
+#include "pl041.h"
+#include "lm4549.h"
 
 #if 0
 #define PL041_DEBUG_LEVEL 1
diff --git a/hw/pl041.h b/hw/audio/pl041.h
index 427ab6d6f8..427ab6d6f8 100644
--- a/hw/pl041.h
+++ b/hw/audio/pl041.h
diff --git a/hw/pl041.hx b/hw/audio/pl041.hx
index dd7188cbcb..dd7188cbcb 100644
--- a/hw/pl041.hx
+++ b/hw/audio/pl041.hx
diff --git a/hw/sb16.c b/hw/audio/sb16.c
index bd51cebfd8..783b6b4351 100644
--- a/hw/sb16.c
+++ b/hw/audio/sb16.c
@@ -22,9 +22,9 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "audio/audio.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/qdev.h"
 #include "qemu/timer.h"
 #include "qemu/host-utils.h"
diff --git a/hw/wm8750.c b/hw/audio/wm8750.c
index 0904cf496d..6b5a3499bb 100644
--- a/hw/wm8750.c
+++ b/hw/audio/wm8750.c
@@ -8,7 +8,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "audio/audio.h"
 
 #define IN_PORT_N	3
diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs
new file mode 100644
index 0000000000..e4329a08a9
--- /dev/null
+++ b/hw/block/Makefile.objs
@@ -0,0 +1,15 @@
+common-obj-y += block.o cdrom.o hd-geometry.o
+common-obj-$(CONFIG_FDC) += fdc.o
+common-obj-$(CONFIG_SSI_M25P80) += m25p80.o
+common-obj-$(CONFIG_NAND) += nand.o
+common-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
+common-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+common-obj-$(CONFIG_XEN_BACKEND) += xen_disk.o
+common-obj-$(CONFIG_ECC) += ecc.o
+common-obj-$(CONFIG_ONENAND) += onenand.o
+common-obj-$(CONFIG_PC_SYSFW) += pc_sysfw.o
+
+obj-$(CONFIG_SH4) += tc58128.o
+
+obj-$(CONFIG_VIRTIO) += virtio-blk.o
+obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += dataplane/
diff --git a/hw/block-common.c b/hw/block/block.c
index d21ec3ada1..33dd3f33b6 100644
--- a/hw/block-common.c
+++ b/hw/block/block.c
@@ -8,7 +8,7 @@
  */
 
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "qemu/error-report.h"
 
 void blkconf_serial(BlockConf *conf, char **serial)
diff --git a/hw/cdrom.c b/hw/block/cdrom.c
index a018eec40a..38469fa928 100644
--- a/hw/cdrom.c
+++ b/hw/block/cdrom.c
@@ -26,7 +26,7 @@
    here.  */
 
 #include "qemu-common.h"
-#include "hw/scsi.h"
+#include "hw/scsi/scsi.h"
 
 static void lba_to_msf(uint8_t *buf, int lba)
 {
diff --git a/hw/block/dataplane/Makefile.objs b/hw/block/dataplane/Makefile.objs
new file mode 100644
index 0000000000..9da2eb82ba
--- /dev/null
+++ b/hw/block/dataplane/Makefile.objs
@@ -0,0 +1 @@
+obj-y += ioq.o virtio-blk.o
diff --git a/hw/dataplane/ioq.c b/hw/block/dataplane/ioq.c
index f709f87ed6..f709f87ed6 100644
--- a/hw/dataplane/ioq.c
+++ b/hw/block/dataplane/ioq.c
diff --git a/hw/dataplane/ioq.h b/hw/block/dataplane/ioq.h
index b49b5de7f4..b49b5de7f4 100644
--- a/hw/dataplane/ioq.h
+++ b/hw/block/dataplane/ioq.h
diff --git a/hw/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 1242d61e71..5baef2391a 100644
--- a/hw/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -16,12 +16,12 @@
 #include "qemu/iov.h"
 #include "qemu/thread.h"
 #include "qemu/error-report.h"
-#include "vring.h"
+#include "hw/virtio/dataplane/vring.h"
 #include "ioq.h"
 #include "migration/migration.h"
 #include "block/block.h"
-#include "hw/virtio-blk.h"
-#include "hw/dataplane/virtio-blk.h"
+#include "hw/virtio/virtio-blk.h"
+#include "virtio-blk.h"
 #include "block/aio.h"
 
 enum {
diff --git a/hw/dataplane/virtio-blk.h b/hw/block/dataplane/virtio-blk.h
index 1e8fdfe418..c90e99f48f 100644
--- a/hw/dataplane/virtio-blk.h
+++ b/hw/block/dataplane/virtio-blk.h
@@ -15,7 +15,7 @@
 #ifndef HW_DATAPLANE_VIRTIO_BLK_H
 #define HW_DATAPLANE_VIRTIO_BLK_H
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 
 typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane;
 
diff --git a/hw/ecc.c b/hw/block/ecc.c
index 8c97c33deb..8c888cc12a 100644
--- a/hw/ecc.c
+++ b/hw/block/ecc.c
@@ -12,7 +12,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 
 /*
  * Pre-calculated 256-way 1 byte column parity.  Table borrowed from Linux.
diff --git a/hw/fdc.c b/hw/block/fdc.c
index a4bb1290ef..1ed874f074 100644
--- a/hw/fdc.c
+++ b/hw/block/fdc.c
@@ -28,10 +28,10 @@
  */
 
 #include "hw/hw.h"
-#include "hw/fdc.h"
+#include "hw/block/fdc.h"
 #include "qemu/error-report.h"
 #include "qemu/timer.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/sysbus.h"
 #include "hw/qdev-addr.h"
 #include "sysemu/blockdev.h"
diff --git a/hw/hd-geometry.c b/hw/block/hd-geometry.c
index c30514364f..6feb4f8175 100644
--- a/hw/hd-geometry.c
+++ b/hw/block/hd-geometry.c
@@ -31,7 +31,7 @@
  */
 
 #include "block/block.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "trace.h"
 
 struct partition {
diff --git a/hw/m25p80.c b/hw/block/m25p80.c
index 55e9d0d37a..cd560e3747 100644
--- a/hw/m25p80.c
+++ b/hw/block/m25p80.c
@@ -24,7 +24,7 @@
 #include "hw/hw.h"
 #include "sysemu/blockdev.h"
 #include "hw/ssi.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 
 #ifdef M25P80_ERR_DEBUG
 #define DB_PRINT(...) do { \
diff --git a/hw/nand.c b/hw/block/nand.c
index de3e502596..087ca14ed1 100644
--- a/hw/nand.c
+++ b/hw/block/nand.c
@@ -19,7 +19,7 @@
 #ifndef NAND_IO
 
 # include "hw/hw.h"
-# include "hw/flash.h"
+# include "hw/block/flash.h"
 # include "sysemu/blockdev.h"
 # include "hw/sysbus.h"
 #include "qemu/error-report.h"
@@ -297,6 +297,7 @@ static void nand_command(NANDFlashState *s)
         break;
 
     case NAND_CMD_BLOCKERASE2:
+        s->addr &= (1ull << s->addrlen * 8) - 1;
         if (nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP)
             s->addr <<= 16;
         else
diff --git a/hw/onenand.c b/hw/block/onenand.c
index ddba366ef5..8b511a79dc 100644
--- a/hw/onenand.c
+++ b/hw/block/onenand.c
@@ -20,7 +20,7 @@
 
 #include "qemu-common.h"
 #include "hw/hw.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "hw/irq.h"
 #include "sysemu/blockdev.h"
 #include "exec/memory.h"
@@ -185,7 +185,8 @@ static const VMStateDescription vmstate_onenand = {
         VMSTATE_UINT8(ecc.cp, OneNANDState),
         VMSTATE_UINT16_ARRAY(ecc.lp, OneNANDState, 2),
         VMSTATE_UINT16(ecc.count, OneNANDState),
-        VMSTATE_BUFFER_UNSAFE(otp, OneNANDState, 0, ((64 + 2) << PAGE_SHIFT)),
+        VMSTATE_BUFFER_POINTER_UNSAFE(otp, OneNANDState, 0,
+            ((64 + 2) << PAGE_SHIFT)),
         VMSTATE_END_OF_LIST()
     }
 };
diff --git a/hw/pc_sysfw.c b/hw/block/pc_sysfw.c
index 3e01528e78..0d95c8a926 100644
--- a/hw/pc_sysfw.c
+++ b/hw/block/pc_sysfw.c
@@ -27,11 +27,11 @@
 #include "qemu/error-report.h"
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "sysemu/sysemu.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/kvm.h"
 
 #define BIOS_FILENAME "bios.bin"
diff --git a/hw/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 5d57babe07..3ff20e0c6f 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -37,7 +37,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "block/block.h"
 #include "qemu/timer.h"
 #include "exec/address-spaces.h"
@@ -67,8 +67,7 @@ struct pflash_t {
     uint64_t sector_len;
     uint8_t width;
     uint8_t be;
-    int wcycle; /* if 0, the flash is read normally */
-    int bypass;
+    uint8_t wcycle; /* if 0, the flash is read normally */
     int ro;
     uint8_t cmd;
     uint8_t status;
@@ -78,7 +77,7 @@ struct pflash_t {
     uint16_t ident3;
     uint8_t cfi_len;
     uint8_t cfi_table[0x52];
-    hwaddr counter;
+    uint64_t counter;
     unsigned int writeblock_size;
     QEMUTimer *timer;
     MemoryRegion mem;
@@ -86,6 +85,19 @@ struct pflash_t {
     void *storage;
 };
 
+static const VMStateDescription vmstate_pflash = {
+    .name = "pflash_cfi01",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT8(wcycle, pflash_t),
+        VMSTATE_UINT8(cmd, pflash_t),
+        VMSTATE_UINT8(status, pflash_t),
+        VMSTATE_UINT64(counter, pflash_t),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void pflash_timer (void *opaque)
 {
     pflash_t *pfl = opaque;
@@ -93,12 +105,8 @@ static void pflash_timer (void *opaque)
     DPRINTF("%s: command %02x done\n", __func__, pfl->cmd);
     /* Reset flash */
     pfl->status ^= 0x80;
-    if (pfl->bypass) {
-        pfl->wcycle = 2;
-    } else {
-        memory_region_rom_device_set_readable(&pfl->mem, true);
-        pfl->wcycle = 0;
-    }
+    memory_region_rom_device_set_readable(&pfl->mem, true);
+    pfl->wcycle = 0;
     pfl->cmd = 0;
 }
 
@@ -228,7 +236,7 @@ static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
     uint8_t *p = pfl->storage;
 
     DPRINTF("%s: block write offset " TARGET_FMT_plx
-            " value %x counter " TARGET_FMT_plx "\n",
+            " value %x counter %016" PRIx64 "\n",
             __func__, offset, value, pfl->counter);
     switch (width) {
     case 1:
@@ -452,7 +460,6 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,
  reset_flash:
     memory_region_rom_device_set_readable(&pfl->mem, true);
 
-    pfl->bypass = 0;
     pfl->wcycle = 0;
     pfl->cmd = 0;
 }
@@ -707,6 +714,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data)
 
     k->init = pflash_cfi01_init;
     dc->props = pflash_cfi01_properties;
+    dc->vmsd = &vmstate_pflash;
 }
 
 
diff --git a/hw/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 37b4fcc234..9a7fa707ca 100644
--- a/hw/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -36,7 +36,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "qemu/timer.h"
 #include "block/block.h"
 #include "exec/address-spaces.h"
diff --git a/hw/tc58128.c b/hw/block/tc58128.c
index f76f96d9e7..a3929d444f 100644
--- a/hw/tc58128.c
+++ b/hw/block/tc58128.c
@@ -1,5 +1,5 @@
 #include "hw/hw.h"
-#include "hw/sh.h"
+#include "hw/sh4/sh.h"
 #include "hw/loader.h"
 
 #define CE1  0x0100
diff --git a/hw/virtio-blk.c b/hw/block/virtio-blk.c
index f2143fded3..6efb2f063d 100644
--- a/hw/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -14,14 +14,17 @@
 #include "qemu-common.h"
 #include "qemu/error-report.h"
 #include "trace.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "sysemu/blockdev.h"
-#include "hw/virtio-blk.h"
-#include "hw/scsi-defs.h"
+#include "hw/virtio/virtio-blk.h"
+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
+# include "dataplane/virtio-blk.h"
+#endif
+#include "block/scsi.h"
 #ifdef __linux__
 # include <scsi/sg.h>
 #endif
-#include "hw/virtio-bus.h"
+#include "hw/virtio/virtio-bus.h"
 
 typedef struct VirtIOBlockReq
 {
diff --git a/hw/xen_blkif.h b/hw/block/xen_blkif.h
index c0f4136228..c0f4136228 100644
--- a/hw/xen_blkif.h
+++ b/hw/block/xen_blkif.h
diff --git a/hw/xen_disk.c b/hw/block/xen_disk.c
index 83329e2e69..0ac65d4e8f 100644
--- a/hw/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -36,8 +36,8 @@
 #include <sys/uio.h>
 
 #include "hw/hw.h"
-#include "hw/xen_backend.h"
-#include "hw/xen_blkif.h"
+#include "hw/xen/xen_backend.h"
+#include "xen_blkif.h"
 #include "sysemu/blockdev.h"
 
 /* ------------------------------------------------------------- */
@@ -700,7 +700,7 @@ static void blk_alloc(struct XenDevice *xendev)
 static int blk_init(struct XenDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
-    int index, qflags, info = 0;
+    int info = 0;
 
     /* read xenstore entries */
     if (blkdev->params == NULL) {
@@ -743,10 +743,7 @@ static int blk_init(struct XenDevice *xendev)
     }
 
     /* read-only ? */
-    qflags = BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
-    if (strcmp(blkdev->mode, "w") == 0) {
-        qflags |= BDRV_O_RDWR;
-    } else {
+    if (strcmp(blkdev->mode, "w")) {
         info  |= VDISK_READONLY;
     }
 
@@ -755,6 +752,41 @@ static int blk_init(struct XenDevice *xendev)
         info  |= VDISK_CDROM;
     }
 
+    blkdev->file_blk  = BLOCK_SIZE;
+
+    /* fill info
+     * blk_connect supplies sector-size and sectors
+     */
+    xenstore_write_be_int(&blkdev->xendev, "feature-flush-cache", 1);
+    xenstore_write_be_int(&blkdev->xendev, "feature-persistent", 1);
+    xenstore_write_be_int(&blkdev->xendev, "info", info);
+    return 0;
+
+out_error:
+    g_free(blkdev->params);
+    blkdev->params = NULL;
+    g_free(blkdev->mode);
+    blkdev->mode = NULL;
+    g_free(blkdev->type);
+    blkdev->type = NULL;
+    g_free(blkdev->dev);
+    blkdev->dev = NULL;
+    g_free(blkdev->devtype);
+    blkdev->devtype = NULL;
+    return -1;
+}
+
+static int blk_connect(struct XenDevice *xendev)
+{
+    struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
+    int pers, index, qflags;
+
+    /* read-only ? */
+    qflags = BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
+    if (strcmp(blkdev->mode, "w") == 0) {
+        qflags |= BDRV_O_RDWR;
+    }
+
     /* init qemu block driver */
     index = (blkdev->xendev.dev - 202 * 256) / 16;
     blkdev->dinfo = drive_get(IF_XEN, 0, index);
@@ -770,7 +802,7 @@ static int blk_init(struct XenDevice *xendev)
             }
         }
         if (!blkdev->bs) {
-            goto out_error;
+            return -1;
         }
     } else {
         /* setup via qemu cmdline -> already setup for us */
@@ -778,7 +810,6 @@ static int blk_init(struct XenDevice *xendev)
         blkdev->bs = blkdev->dinfo->bdrv;
     }
     bdrv_attach_dev_nofail(blkdev->bs, blkdev);
-    blkdev->file_blk  = BLOCK_SIZE;
     blkdev->file_size = bdrv_getlength(blkdev->bs);
     if (blkdev->file_size < 0) {
         xen_be_printf(&blkdev->xendev, 1, "bdrv_getlength: %d (%s) | drv %s\n",
@@ -792,33 +823,10 @@ static int blk_init(struct XenDevice *xendev)
                   blkdev->type, blkdev->fileproto, blkdev->filename,
                   blkdev->file_size, blkdev->file_size >> 20);
 
-    /* fill info */
-    xenstore_write_be_int(&blkdev->xendev, "feature-flush-cache", 1);
-    xenstore_write_be_int(&blkdev->xendev, "feature-persistent", 1);
-    xenstore_write_be_int(&blkdev->xendev, "info",            info);
-    xenstore_write_be_int(&blkdev->xendev, "sector-size",     blkdev->file_blk);
-    xenstore_write_be_int(&blkdev->xendev, "sectors",
-                          blkdev->file_size / blkdev->file_blk);
-    return 0;
-
-out_error:
-    g_free(blkdev->params);
-    blkdev->params = NULL;
-    g_free(blkdev->mode);
-    blkdev->mode = NULL;
-    g_free(blkdev->type);
-    blkdev->type = NULL;
-    g_free(blkdev->dev);
-    blkdev->dev = NULL;
-    g_free(blkdev->devtype);
-    blkdev->devtype = NULL;
-    return -1;
-}
-
-static int blk_connect(struct XenDevice *xendev)
-{
-    struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
-    int pers;
+    /* Fill in number of sector size and number of sectors */
+    xenstore_write_be_int(&blkdev->xendev, "sector-size", blkdev->file_blk);
+    xenstore_write_be_int64(&blkdev->xendev, "sectors",
+                            blkdev->file_size / blkdev->file_blk);
 
     if (xenstore_read_fe_int(&blkdev->xendev, "ring-ref", &blkdev->ring_ref) == -1) {
         return -1;
diff --git a/hw/bt/Makefile.objs b/hw/bt/Makefile.objs
new file mode 100644
index 0000000000..867a7d2e8a
--- /dev/null
+++ b/hw/bt/Makefile.objs
@@ -0,0 +1,3 @@
+common-obj-y += core.o l2cap.o sdp.o hci.o hid.o
+common-obj-y += hci-csr.o
+
diff --git a/hw/bt.c b/hw/bt/core.c
index 24ef4de49d..24ef4de49d 100644
--- a/hw/bt.c
+++ b/hw/bt/core.c
diff --git a/hw/bt-hci-csr.c b/hw/bt/hci-csr.c
index 55c819b085..55c819b085 100644
--- a/hw/bt-hci-csr.c
+++ b/hw/bt/hci-csr.c
diff --git a/hw/bt-hci.c b/hw/bt/hci.c
index a76edea2c9..a76edea2c9 100644
--- a/hw/bt-hci.c
+++ b/hw/bt/hci.c
diff --git a/hw/bt-hid.c b/hw/bt/hid.c
index 69ccf9b432..af494e1e06 100644
--- a/hw/bt-hid.c
+++ b/hw/bt/hid.c
@@ -21,7 +21,7 @@
 #include "qemu-common.h"
 #include "qemu/timer.h"
 #include "ui/console.h"
-#include "hw/hid.h"
+#include "hw/input/hid.h"
 #include "hw/bt.h"
 
 enum hid_transaction_req {
diff --git a/hw/bt-l2cap.c b/hw/bt/l2cap.c
index 521587a112..521587a112 100644
--- a/hw/bt-l2cap.c
+++ b/hw/bt/l2cap.c
diff --git a/hw/bt-sdp.c b/hw/bt/sdp.c
index 218e075df7..218e075df7 100644
--- a/hw/bt-sdp.c
+++ b/hw/bt/sdp.c
diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs
new file mode 100644
index 0000000000..f8f3dbca3e
--- /dev/null
+++ b/hw/char/Makefile.objs
@@ -0,0 +1,27 @@
+common-obj-$(CONFIG_IPACK) += tpci200.o ipoctal232.o ipack.o
+common-obj-$(CONFIG_ESCC) += escc.o
+common-obj-$(CONFIG_PARALLEL) += parallel.o
+common-obj-$(CONFIG_PL011) += pl011.o
+common-obj-$(CONFIG_SERIAL) += serial.o serial-isa.o
+common-obj-$(CONFIG_SERIAL_PCI) += serial-pci.o
+common-obj-$(CONFIG_VIRTIO) += virtio-console.o
+common-obj-$(CONFIG_XILINX) += xilinx_uartlite.o
+common-obj-$(CONFIG_XEN_BACKEND) += xen_console.o
+common-obj-$(CONFIG_CADENCE) += cadence_uart.o
+
+obj-$(CONFIG_EXYNOS4) += exynos4210_uart.o
+obj-$(CONFIG_COLDFIRE) += mcf_uart.o
+obj-$(CONFIG_OMAP) += omap_uart.o
+obj-$(CONFIG_SH4) += sh_serial.o
+obj-$(CONFIG_PSERIES) += spapr_vty.o
+
+common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o
+common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o
+common-obj-$(CONFIG_GRLIB) += grlib_apbuart.o
+common-obj-$(CONFIG_IMX) += imx_serial.o
+common-obj-$(CONFIG_LM32) += lm32_juart.o
+common-obj-$(CONFIG_LM32) += lm32_uart.o
+common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o
+common-obj-$(CONFIG_SCLPCONSOLE) += sclpconsole.o
+
+obj-$(CONFIG_VIRTIO) += virtio-serial-bus.o
diff --git a/hw/cadence_uart.c b/hw/char/cadence_uart.c
index 5426f10018..421ec998d6 100644
--- a/hw/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -157,6 +157,7 @@ static void uart_rx_reset(UartState *s)
 {
     s->rx_wpos = 0;
     s->rx_count = 0;
+    qemu_chr_accept_input(s->chr);
 
     s->r[R_SR] |= UART_SR_INTR_REMPTY;
     s->r[R_SR] &= ~UART_SR_INTR_RFUL;
diff --git a/hw/debugcon.c b/hw/char/debugcon.c
index cab7691b12..0588eebb77 100644
--- a/hw/debugcon.c
+++ b/hw/char/debugcon.c
@@ -26,8 +26,8 @@
 
 #include "hw/hw.h"
 #include "char/char.h"
-#include "hw/isa.h"
-#include "hw/pc.h"
+#include "hw/isa/isa.h"
+#include "hw/i386/pc.h"
 
 #define TYPE_ISA_DEBUGCON_DEVICE "isa-debugcon"
 #define ISA_DEBUGCON_DEVICE(obj) \
diff --git a/hw/escc.c b/hw/char/escc.c
index baf0219304..067b055fee 100644
--- a/hw/escc.c
+++ b/hw/char/escc.c
@@ -24,7 +24,7 @@
 
 #include "hw/hw.h"
 #include "hw/sysbus.h"
-#include "hw/escc.h"
+#include "hw/char/escc.h"
 #include "char/char.h"
 #include "ui/console.h"
 #include "trace.h"
diff --git a/hw/etraxfs_ser.c b/hw/char/etraxfs_ser.c
index 7e24d34230..b7499d775b 100644
--- a/hw/etraxfs_ser.c
+++ b/hw/char/etraxfs_ser.c
@@ -78,7 +78,6 @@ static uint64_t
 ser_read(void *opaque, hwaddr addr, unsigned int size)
 {
     struct etrax_serial *s = opaque;
-    D(CPUCRISState *env = s->env);
     uint32_t r = 0;
 
     addr >>= 2;
@@ -116,7 +115,6 @@ ser_write(void *opaque, hwaddr addr,
     struct etrax_serial *s = opaque;
     uint32_t value = val64;
     unsigned char ch = val64;
-    D(CPUCRISState *env = s->env);
 
     D(qemu_log("%s " TARGET_FMT_plx "=%x\n",  __func__, addr, value));
     addr >>= 2;
diff --git a/hw/exynos4210_uart.c b/hw/char/exynos4210_uart.c
index 006f3d44fb..8b4e72ca11 100644
--- a/hw/exynos4210_uart.c
+++ b/hw/char/exynos4210_uart.c
@@ -23,7 +23,7 @@
 #include "sysemu/sysemu.h"
 #include "char/char.h"
 
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 
 #undef DEBUG_UART
 #undef DEBUG_UART_EXTEND
diff --git a/hw/grlib_apbuart.c b/hw/char/grlib_apbuart.c
index 62f799083c..62f799083c 100644
--- a/hw/grlib_apbuart.c
+++ b/hw/char/grlib_apbuart.c
diff --git a/hw/imx_serial.c b/hw/char/imx_serial.c
index 746723cd6e..d7ec2090fd 100644
--- a/hw/imx_serial.c
+++ b/hw/char/imx_serial.c
@@ -21,7 +21,7 @@
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
 #include "char/char.h"
-#include "hw/imx.h"
+#include "hw/arm/imx.h"
 
 //#define DEBUG_SERIAL 1
 #ifdef DEBUG_SERIAL
diff --git a/hw/ipack.c b/hw/char/ipack.c
index b1f46c10a4..e15540d5cd 100644
--- a/hw/ipack.c
+++ b/hw/char/ipack.c
@@ -8,7 +8,7 @@
  * later version.
  */
 
-#include "hw/ipack.h"
+#include "ipack.h"
 
 IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot)
 {
diff --git a/hw/ipack.h b/hw/char/ipack.h
index f2b7a12e05..f2b7a12e05 100644
--- a/hw/ipack.h
+++ b/hw/char/ipack.h
diff --git a/hw/ipoctal232.c b/hw/char/ipoctal232.c
index 685fee2d2e..fcd0af31b4 100644
--- a/hw/ipoctal232.c
+++ b/hw/char/ipoctal232.c
@@ -8,7 +8,7 @@
  * later version.
  */
 
-#include "hw/ipack.h"
+#include "ipack.h"
 #include "qemu/bitops.h"
 #include "char/char.h"
 
diff --git a/hw/lm32_juart.c b/hw/char/lm32_juart.c
index 472e9c25fd..93f0d1534e 100644
--- a/hw/lm32_juart.c
+++ b/hw/char/lm32_juart.c
@@ -22,7 +22,7 @@
 #include "trace.h"
 #include "char/char.h"
 
-#include "hw/lm32_juart.h"
+#include "hw/lm32/lm32_juart.h"
 
 enum {
     LM32_JUART_MIN_SAVE_VERSION = 0,
diff --git a/hw/lm32_uart.c b/hw/char/lm32_uart.c
index 32bc37ac96..32bc37ac96 100644
--- a/hw/lm32_uart.c
+++ b/hw/char/lm32_uart.c
diff --git a/hw/mcf_uart.c b/hw/char/mcf_uart.c
index e5de801671..6724b1b718 100644
--- a/hw/mcf_uart.c
+++ b/hw/char/mcf_uart.c
@@ -6,7 +6,7 @@
  * This code is licensed under the GPL
  */
 #include "hw/hw.h"
-#include "hw/mcf.h"
+#include "hw/m68k/mcf.h"
 #include "char/char.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/milkymist-uart.c b/hw/char/milkymist-uart.c
index f3bdf6991a..f3bdf6991a 100644
--- a/hw/milkymist-uart.c
+++ b/hw/char/milkymist-uart.c
diff --git a/hw/omap_uart.c b/hw/char/omap_uart.c
index af51ce7534..26c14266fc 100644
--- a/hw/omap_uart.c
+++ b/hw/char/omap_uart.c
@@ -19,8 +19,8 @@
  */
 #include "char/char.h"
 #include "hw/hw.h"
-#include "hw/omap.h"
-#include "hw/serial.h"
+#include "hw/arm/omap.h"
+#include "hw/char/serial.h"
 #include "exec/address-spaces.h"
 
 /* UARTs */
diff --git a/hw/parallel.c b/hw/char/parallel.c
index 0b9af43d8b..863a6fb4a9 100644
--- a/hw/parallel.c
+++ b/hw/char/parallel.c
@@ -24,8 +24,8 @@
  */
 #include "hw/hw.h"
 #include "char/char.h"
-#include "hw/isa.h"
-#include "hw/pc.h"
+#include "hw/isa/isa.h"
+#include "hw/i386/pc.h"
 #include "sysemu/sysemu.h"
 
 //#define DEBUG_PARALLEL
diff --git a/hw/pl011.c b/hw/char/pl011.c
index 332d5b970c..332d5b970c 100644
--- a/hw/pl011.c
+++ b/hw/char/pl011.c
diff --git a/hw/s390x/sclpconsole.c b/hw/char/sclpconsole.c
index 5c881e5f3f..42ed54c9ab 100644
--- a/hw/s390x/sclpconsole.c
+++ b/hw/char/sclpconsole.c
@@ -234,7 +234,7 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr)
     return rc;
 }
 
-static void trigger_ascii_console_data(void *env, int n, int level)
+static void trigger_ascii_console_data(void *opaque, int n, int level)
 {
     sclp_service_interrupt(0);
 }
diff --git a/hw/serial-isa.c b/hw/char/serial-isa.c
index a630a7d506..ed140d04a6 100644
--- a/hw/serial-isa.c
+++ b/hw/char/serial-isa.c
@@ -23,8 +23,8 @@
  * THE SOFTWARE.
  */
 
-#include "hw/serial.h"
-#include "hw/isa.h"
+#include "hw/char/serial.h"
+#include "hw/isa/isa.h"
 
 typedef struct ISASerialState {
     ISADevice dev;
diff --git a/hw/serial-pci.c b/hw/char/serial-pci.c
index 954657ba32..2138e35851 100644
--- a/hw/serial-pci.c
+++ b/hw/char/serial-pci.c
@@ -25,7 +25,7 @@
 
 /* see docs/specs/pci-serial.txt */
 
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "hw/pci/pci.h"
 
 #define PCI_SERIAL_MAX_PORTS 4
diff --git a/hw/serial.c b/hw/char/serial.c
index 0ccc499285..1151bf1bab 100644
--- a/hw/serial.c
+++ b/hw/char/serial.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "char/char.h"
 #include "qemu/timer.h"
 #include "exec/address-spaces.h"
diff --git a/hw/sh_serial.c b/hw/char/sh_serial.c
index 462969557c..450c7d8551 100644
--- a/hw/sh_serial.c
+++ b/hw/char/sh_serial.c
@@ -25,7 +25,7 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/sh.h"
+#include "hw/sh4/sh.h"
 #include "char/char.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/spapr_vty.c b/hw/char/spapr_vty.c
index be08571d23..9df018a230 100644
--- a/hw/spapr_vty.c
+++ b/hw/char/spapr_vty.c
@@ -1,7 +1,7 @@
 #include "hw/qdev.h"
 #include "char/char.h"
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
 
 #define VTERM_BUFSIZE   16
 
diff --git a/hw/tpci200.c b/hw/char/tpci200.c
index e3408ef4ba..01706020be 100644
--- a/hw/tpci200.c
+++ b/hw/char/tpci200.c
@@ -8,7 +8,7 @@
  * later version.
  */
 
-#include "hw/ipack.h"
+#include "ipack.h"
 #include "hw/pci/pci.h"
 #include "qemu/bitops.h"
 #include <stdio.h>
diff --git a/hw/virtio-console.c b/hw/char/virtio-console.c
index 284180f4e1..31f672c9a3 100644
--- a/hw/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -13,7 +13,7 @@
 #include "char/char.h"
 #include "qemu/error-report.h"
 #include "trace.h"
-#include "hw/virtio-serial.h"
+#include "hw/virtio/virtio-serial.h"
 
 typedef struct VirtConsole {
     VirtIOSerialPort port;
diff --git a/hw/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index a9cb114649..1dba8ab2c6 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -23,7 +23,7 @@
 #include "qemu/queue.h"
 #include "hw/sysbus.h"
 #include "trace.h"
-#include "hw/virtio-serial.h"
+#include "hw/virtio/virtio-serial.h"
 
 static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
 {
diff --git a/hw/xen_console.c b/hw/char/xen_console.c
index c56ef4737f..efc32320fa 100644
--- a/hw/xen_console.c
+++ b/hw/char/xen_console.c
@@ -31,7 +31,7 @@
 
 #include "hw/hw.h"
 #include "char/char.h"
-#include "hw/xen_backend.h"
+#include "hw/xen/xen_backend.h"
 
 #include <xen/io/console.h>
 
diff --git a/hw/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c
index 079f4d4e1a..079f4d4e1a 100644
--- a/hw/xilinx_uartlite.c
+++ b/hw/char/xilinx_uartlite.c
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
new file mode 100644
index 0000000000..94109f32e2
--- /dev/null
+++ b/hw/core/Makefile.objs
@@ -0,0 +1,14 @@
+# core qdev-related obj files, also used by *-user:
+common-obj-y += qdev.o qdev-properties.o
+# irq.o needed for qdev GPIO handling:
+common-obj-y += irq.o
+
+common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
+common-obj-$(CONFIG_XILINX_AXI) += stream.o
+common-obj-$(CONFIG_PTIMER) += ptimer.o
+common-obj-$(CONFIG_SOFTMMU) += sysbus.o
+common-obj-$(CONFIG_SOFTMMU) += null-machine.o
+common-obj-$(CONFIG_SOFTMMU) += loader.o
+common-obj-$(CONFIG_SOFTMMU) += qdev-addr.o
+common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
+
diff --git a/hw/empty_slot.c b/hw/core/empty_slot.c
index 5234a4ddc6..5234a4ddc6 100644
--- a/hw/empty_slot.c
+++ b/hw/core/empty_slot.c
diff --git a/hw/irq.c b/hw/core/irq.c
index 20785428ef..20785428ef 100644
--- a/hw/irq.c
+++ b/hw/core/irq.c
diff --git a/hw/loader.c b/hw/core/loader.c
index 6ce66fb5bb..7507914297 100644
--- a/hw/loader.c
+++ b/hw/core/loader.c
@@ -46,9 +46,9 @@
 #include "disas/disas.h"
 #include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
-#include "hw/uboot_image.h"
+#include "uboot_image.h"
 #include "hw/loader.h"
-#include "hw/fw_cfg.h"
+#include "hw/nvram/fw_cfg.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/null-machine.c b/hw/core/null-machine.c
index bdf109fef1..bdf109fef1 100644
--- a/hw/null-machine.c
+++ b/hw/core/null-machine.c
diff --git a/hw/ptimer.c b/hw/core/ptimer.c
index 4bc96c9fa2..4bc96c9fa2 100644
--- a/hw/ptimer.c
+++ b/hw/core/ptimer.c
diff --git a/hw/qdev-addr.c b/hw/core/qdev-addr.c
index 80a38bb017..80a38bb017 100644
--- a/hw/qdev-addr.c
+++ b/hw/core/qdev-addr.c
diff --git a/hw/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index a22b155b6f..8c2e15205c 100644
--- a/hw/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -14,7 +14,7 @@
 #include "hw/qdev.h"
 #include "qapi/qmp/qerror.h"
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "net/hub.h"
 #include "qapi/visitor.h"
 #include "char/char.h"
diff --git a/hw/qdev-properties.c b/hw/core/qdev-properties.c
index 168c4663e9..9a0872d3b9 100644
--- a/hw/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -2,7 +2,7 @@
 #include "hw/qdev.h"
 #include "qapi/qmp/qerror.h"
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "net/hub.h"
 #include "qapi/visitor.h"
 #include "char/char.h"
diff --git a/hw/qdev.c b/hw/core/qdev.c
index e2bb37dc37..e2bb37dc37 100644
--- a/hw/qdev.c
+++ b/hw/core/qdev.c
diff --git a/hw/stream.c b/hw/core/stream.c
index a07d6a56d3..a07d6a56d3 100644
--- a/hw/stream.c
+++ b/hw/core/stream.c
diff --git a/hw/sysbus.c b/hw/core/sysbus.c
index 9004d8c543..9004d8c543 100644
--- a/hw/sysbus.c
+++ b/hw/core/sysbus.c
diff --git a/hw/uboot_image.h b/hw/core/uboot_image.h
index 9fc2760b53..9fc2760b53 100644
--- a/hw/uboot_image.h
+++ b/hw/core/uboot_image.h
diff --git a/hw/cpu/Makefile.objs b/hw/cpu/Makefile.objs
new file mode 100644
index 0000000000..a49ca04282
--- /dev/null
+++ b/hw/cpu/Makefile.objs
@@ -0,0 +1,4 @@
+obj-$(CONFIG_ARM11MPCORE) += arm11mpcore.o
+obj-$(CONFIG_ARM9MPCORE) += a9mpcore.o
+obj-$(CONFIG_ARM15MPCORE) += a15mpcore.o
+
diff --git a/hw/a15mpcore.c b/hw/cpu/a15mpcore.c
index 648656d5b4..648656d5b4 100644
--- a/hw/a15mpcore.c
+++ b/hw/cpu/a15mpcore.c
diff --git a/hw/a9mpcore.c b/hw/cpu/a9mpcore.c
index 0a1a10f37a..0a1a10f37a 100644
--- a/hw/a9mpcore.c
+++ b/hw/cpu/a9mpcore.c
diff --git a/hw/arm11mpcore.c b/hw/cpu/arm11mpcore.c
index 90dceade71..90dceade71 100644
--- a/hw/arm11mpcore.c
+++ b/hw/cpu/arm11mpcore.c
diff --git a/hw/cris/Makefile.objs b/hw/cris/Makefile.objs
index a94c62450d..776db7c5cd 100644
--- a/hw/cris/Makefile.objs
+++ b/hw/cris/Makefile.objs
@@ -1,13 +1,3 @@
-# IO blocks
-obj-y += etraxfs_dma.o
-obj-y += etraxfs_pic.o
-obj-y += etraxfs_eth.o
-obj-y += etraxfs_timer.o
-obj-y += etraxfs_ser.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
-# Boards
 obj-y += pic_cpu.o
 obj-y += boot.o
 obj-y += axis_dev88.o
diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
index eccd423abf..7475671308 100644
--- a/hw/cris/axis_dev88.c
+++ b/hw/cris/axis_dev88.c
@@ -24,12 +24,12 @@
 
 #include "hw/sysbus.h"
 #include "net/net.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "hw/boards.h"
-#include "hw/etraxfs.h"
+#include "hw/cris/etraxfs.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "hw/cris-boot.h"
+#include "boot.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/cris/boot.c b/hw/cris/boot.c
index c330e22a86..622f353c9a 100644
--- a/hw/cris/boot.c
+++ b/hw/cris/boot.c
@@ -25,7 +25,7 @@
 #include "hw/hw.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "hw/cris-boot.h"
+#include "boot.h"
 
 static void main_cpu_reset(void *opaque)
 {
diff --git a/hw/cris-boot.h b/hw/cris/boot.h
index c4d3fa6f6f..c4d3fa6f6f 100644
--- a/hw/cris-boot.h
+++ b/hw/cris/boot.h
diff --git a/hw/cris/pic_cpu.c b/hw/cris/pic_cpu.c
index 85c68c0497..bd47bf1a5d 100644
--- a/hw/cris/pic_cpu.c
+++ b/hw/cris/pic_cpu.c
@@ -24,7 +24,7 @@
 
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/etraxfs.h"
+#include "hw/cris/etraxfs.h"
 
 #define D(x)
 
diff --git a/hw/dataplane/Makefile.objs b/hw/dataplane/Makefile.objs
deleted file mode 100644
index 701111ccb9..0000000000
--- a/hw/dataplane/Makefile.objs
+++ /dev/null
@@ -1 +0,0 @@
-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += hostmem.o vring.o ioq.o virtio-blk.o
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
new file mode 100644
index 0000000000..3f7027d46b
--- /dev/null
+++ b/hw/display/Makefile.objs
@@ -0,0 +1,34 @@
+common-obj-$(CONFIG_ADS7846) += ads7846.o
+common-obj-$(CONFIG_VGA_CIRRUS) += cirrus_vga.o
+common-obj-$(CONFIG_G364FB) += g364fb.o
+common-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
+common-obj-$(CONFIG_PL110) += pl110.o
+common-obj-$(CONFIG_SSD0303) += ssd0303.o
+common-obj-$(CONFIG_SSD0323) += ssd0323.o
+common-obj-$(CONFIG_XEN_BACKEND) += xenfb.o
+
+common-obj-$(CONFIG_VGA_PCI) += vga-pci.o
+common-obj-$(CONFIG_VGA_ISA) += vga-isa.o
+common-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
+common-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
+
+common-obj-$(CONFIG_BLIZZARD) += blizzard.o
+common-obj-$(CONFIG_EXYNOS4) += exynos4210_fimd.o
+common-obj-$(CONFIG_FRAMEBUFFER) += framebuffer.o
+common-obj-$(CONFIG_MILKYMIST) += milkymist-vgafb.o
+common-obj-$(CONFIG_ZAURUS) += tc6393xb.o
+
+ifeq ($(CONFIG_GLX),y)
+common-obj-$(CONFIG_MILKYMIST) += milkymist-tmu2.o
+endif
+
+obj-$(CONFIG_OMAP) += omap_dss.o
+obj-$(CONFIG_OMAP) += omap_lcdc.o
+obj-$(CONFIG_PXA2XX) += pxa2xx_lcd.o
+obj-$(CONFIG_SM501) += sm501.o
+obj-$(CONFIG_TCX) += tcx.o
+
+obj-$(CONFIG_VGA) += vga.o
+
+common-obj-$(CONFIG_QXL) += qxl-logger.o qxl-render.o
+obj-$(CONFIG_QXL) += qxl.o
diff --git a/hw/ads7846.c b/hw/display/ads7846.c
index 5da3dc5b2c..5da3dc5b2c 100644
--- a/hw/ads7846.c
+++ b/hw/display/ads7846.c
diff --git a/hw/blizzard.c b/hw/display/blizzard.c
index 020d3de431..175c5cdd00 100644
--- a/hw/blizzard.c
+++ b/hw/display/blizzard.c
@@ -20,8 +20,8 @@
 
 #include "qemu-common.h"
 #include "ui/console.h"
-#include "hw/devices.h"
-#include "hw/vga_int.h"
+#include "hw/arm/devices.h"
+#include "vga_int.h"
 #include "ui/pixel_ops.h"
 
 typedef void (*blizzard_fn_t)(uint8_t *, const uint8_t *, unsigned int);
@@ -946,15 +946,15 @@ static void blizzard_screen_dump(void *opaque, const char *filename,
 }
 
 #define DEPTH 8
-#include "hw/blizzard_template.h"
+#include "blizzard_template.h"
 #define DEPTH 15
-#include "hw/blizzard_template.h"
+#include "blizzard_template.h"
 #define DEPTH 16
-#include "hw/blizzard_template.h"
+#include "blizzard_template.h"
 #define DEPTH 24
-#include "hw/blizzard_template.h"
+#include "blizzard_template.h"
 #define DEPTH 32
-#include "hw/blizzard_template.h"
+#include "blizzard_template.h"
 
 void *s1d13745_init(qemu_irq gpio_int)
 {
diff --git a/hw/blizzard_template.h b/hw/display/blizzard_template.h
index 42f4e90b04..a8a8899478 100644
--- a/hw/blizzard_template.h
+++ b/hw/display/blizzard_template.h
@@ -55,7 +55,7 @@ static void glue(blizzard_draw_line16_, DEPTH)(PIXEL_TYPE *dest,
     unsigned int r, g, b;
     const uint16_t *end = (const void *) src + width;
     while (src < end) {
-        data = lduw_raw(src ++);
+        data = *src ++;
         b = (data & 0x1f) << 3;
         data >>= 5;
         g = (data & 0x3f) << 2;
diff --git a/hw/cirrus_vga.c b/hw/display/cirrus_vga.c
index 7a4d63436e..bf2181afd8 100644
--- a/hw/cirrus_vga.c
+++ b/hw/display/cirrus_vga.c
@@ -29,7 +29,7 @@
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "ui/console.h"
-#include "hw/vga_int.h"
+#include "vga_int.h"
 #include "hw/loader.h"
 
 /*
@@ -288,63 +288,63 @@ static void cirrus_bitblt_fill_nop(CirrusVGAState *s,
 
 #define ROP_NAME 0
 #define ROP_FN(d, s) 0
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME src_and_dst
 #define ROP_FN(d, s) (s) & (d)
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME src_and_notdst
 #define ROP_FN(d, s) (s) & (~(d))
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME notdst
 #define ROP_FN(d, s) ~(d)
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME src
 #define ROP_FN(d, s) s
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME 1
 #define ROP_FN(d, s) ~0
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME notsrc_and_dst
 #define ROP_FN(d, s) (~(s)) & (d)
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME src_xor_dst
 #define ROP_FN(d, s) (s) ^ (d)
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME src_or_dst
 #define ROP_FN(d, s) (s) | (d)
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME notsrc_or_notdst
 #define ROP_FN(d, s) (~(s)) | (~(d))
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME src_notxor_dst
 #define ROP_FN(d, s) ~((s) ^ (d))
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME src_or_notdst
 #define ROP_FN(d, s) (s) | (~(d))
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME notsrc
 #define ROP_FN(d, s) (~(s))
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME notsrc_or_dst
 #define ROP_FN(d, s) (~(s)) | (d)
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 #define ROP_NAME notsrc_and_notdst
 #define ROP_FN(d, s) (~(s)) & (~(d))
-#include "hw/cirrus_vga_rop.h"
+#include "cirrus_vga_rop.h"
 
 static const cirrus_bitblt_rop_t cirrus_fwd_rop[16] = {
     cirrus_bitblt_rop_fwd_0,
@@ -2166,13 +2166,13 @@ static void cirrus_cursor_invalidate(VGACommonState *s1)
 }
 
 #define DEPTH 8
-#include "hw/cirrus_vga_template.h"
+#include "cirrus_vga_template.h"
 
 #define DEPTH 16
-#include "hw/cirrus_vga_template.h"
+#include "cirrus_vga_template.h"
 
 #define DEPTH 32
-#include "hw/cirrus_vga_template.h"
+#include "cirrus_vga_template.h"
 
 static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y)
 {
diff --git a/hw/cirrus_vga_rop.h b/hw/display/cirrus_vga_rop.h
index 894610cc22..9c7bb09286 100644
--- a/hw/cirrus_vga_rop.h
+++ b/hw/display/cirrus_vga_rop.h
@@ -191,16 +191,16 @@ glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
 }
 
 #define DEPTH 8
-#include "hw/cirrus_vga_rop2.h"
+#include "cirrus_vga_rop2.h"
 
 #define DEPTH 16
-#include "hw/cirrus_vga_rop2.h"
+#include "cirrus_vga_rop2.h"
 
 #define DEPTH 24
-#include "hw/cirrus_vga_rop2.h"
+#include "cirrus_vga_rop2.h"
 
 #define DEPTH 32
-#include "hw/cirrus_vga_rop2.h"
+#include "cirrus_vga_rop2.h"
 
 #undef ROP_NAME
 #undef ROP_OP
diff --git a/hw/cirrus_vga_rop2.h b/hw/display/cirrus_vga_rop2.h
index d28bcc6f25..d28bcc6f25 100644
--- a/hw/cirrus_vga_rop2.h
+++ b/hw/display/cirrus_vga_rop2.h
diff --git a/hw/cirrus_vga_template.h b/hw/display/cirrus_vga_template.h
index 3b28280588..3b28280588 100644
--- a/hw/cirrus_vga_template.h
+++ b/hw/display/cirrus_vga_template.h
diff --git a/hw/exynos4210_fimd.c b/hw/display/exynos4210_fimd.c
index bf316c62ab..49cca4bf94 100644
--- a/hw/exynos4210_fimd.c
+++ b/hw/display/exynos4210_fimd.c
@@ -23,7 +23,6 @@
  */
 
 #include "qemu-common.h"
-#include "exec/cpu-all.h"
 #include "hw/sysbus.h"
 #include "ui/console.h"
 #include "ui/pixel_ops.h"
@@ -783,7 +782,7 @@ static void glue(draw_line_palette_, N)(Exynos4210fimdWindow *w, uint8_t *src, \
     rgba p, p_old; \
     int i; \
     do { \
-        data = ldq_raw((void *)src); \
+        memcpy(&data, src, sizeof(data)); \
         src += 8; \
         fimd_swap_data(swap, &data); \
         for (i = (64 / (N) - 1); i >= 0; i--) { \
@@ -812,7 +811,7 @@ static void glue(draw_line_, N)(Exynos4210fimdWindow *w, uint8_t *src, \
     rgba p, p_old; \
     int i; \
     do { \
-        data = ldq_raw((void *)src); \
+        memcpy(&data, src, sizeof(data)); \
         src += 8; \
         fimd_swap_data(swap, &data); \
         for (i = (64 / (N) - 1); i >= 0; i--) { \
diff --git a/hw/framebuffer.c b/hw/display/framebuffer.c
index 7326a98a41..6be31db2b5 100644
--- a/hw/framebuffer.c
+++ b/hw/display/framebuffer.c
@@ -19,7 +19,7 @@
 
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/framebuffer.h"
+#include "framebuffer.h"
 
 /* Render an image from a shared memory framebuffer.  */
    
diff --git a/hw/framebuffer.h b/hw/display/framebuffer.h
index 6eae035b7d..6eae035b7d 100644
--- a/hw/framebuffer.h
+++ b/hw/display/framebuffer.h
diff --git a/hw/g364fb.c b/hw/display/g364fb.c
index f7014e9dd8..f7014e9dd8 100644
--- a/hw/g364fb.c
+++ b/hw/display/g364fb.c
diff --git a/hw/jazz_led.c b/hw/display/jazz_led.c
index 05528c7c81..05528c7c81 100644
--- a/hw/jazz_led.c
+++ b/hw/display/jazz_led.c
diff --git a/hw/milkymist-tmu2.c b/hw/display/milkymist-tmu2.c
index b723a04cc9..b723a04cc9 100644
--- a/hw/milkymist-tmu2.c
+++ b/hw/display/milkymist-tmu2.c
diff --git a/hw/milkymist-vgafb.c b/hw/display/milkymist-vgafb.c
index 98762ecd21..3219041c81 100644
--- a/hw/milkymist-vgafb.c
+++ b/hw/display/milkymist-vgafb.c
@@ -26,20 +26,20 @@
 #include "hw/sysbus.h"
 #include "trace.h"
 #include "ui/console.h"
-#include "hw/framebuffer.h"
+#include "framebuffer.h"
 #include "ui/pixel_ops.h"
 #include "qemu/error-report.h"
 
 #define BITS 8
-#include "hw/milkymist-vgafb_template.h"
+#include "milkymist-vgafb_template.h"
 #define BITS 15
-#include "hw/milkymist-vgafb_template.h"
+#include "milkymist-vgafb_template.h"
 #define BITS 16
-#include "hw/milkymist-vgafb_template.h"
+#include "milkymist-vgafb_template.h"
 #define BITS 24
-#include "hw/milkymist-vgafb_template.h"
+#include "milkymist-vgafb_template.h"
 #define BITS 32
-#include "hw/milkymist-vgafb_template.h"
+#include "milkymist-vgafb_template.h"
 
 enum {
     R_CTRL = 0,
diff --git a/hw/milkymist-vgafb_template.h b/hw/display/milkymist-vgafb_template.h
index 1d33ee8b50..e0036e16cf 100644
--- a/hw/milkymist-vgafb_template.h
+++ b/hw/display/milkymist-vgafb_template.h
@@ -61,7 +61,7 @@ static void glue(draw_line_, BITS)(void *opaque, uint8_t *d, const uint8_t *s,
     uint8_t r, g, b;
 
     while (width--) {
-        rgb565 = lduw_raw(s);
+        memcpy(&rgb565, s, sizeof(rgb565));
         r = ((rgb565 >> 11) & 0x1f) << 3;
         g = ((rgb565 >>  5) & 0x3f) << 2;
         b = ((rgb565 >>  0) & 0x1f) << 3;
diff --git a/hw/omap_dss.c b/hw/display/omap_dss.c
index 948ad8fcc5..ea3afcef5e 100644
--- a/hw/omap_dss.c
+++ b/hw/display/omap_dss.c
@@ -19,7 +19,7 @@
  */
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 
 struct omap_dss_s {
     qemu_irq irq;
diff --git a/hw/omap_lcd_template.h b/hw/display/omap_lcd_template.h
index 2fb96f83ae..2fb96f83ae 100644
--- a/hw/omap_lcd_template.h
+++ b/hw/display/omap_lcd_template.h
diff --git a/hw/omap_lcdc.c b/hw/display/omap_lcdc.c
index 4f5b0947cf..be7e9c0d74 100644
--- a/hw/omap_lcdc.c
+++ b/hw/display/omap_lcdc.c
@@ -18,8 +18,8 @@
  */
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/omap.h"
-#include "hw/framebuffer.h"
+#include "hw/arm/omap.h"
+#include "framebuffer.h"
 #include "ui/pixel_ops.h"
 
 struct omap_lcd_panel_s {
@@ -70,13 +70,13 @@ static void omap_lcd_interrupts(struct omap_lcd_panel_s *s)
 #define draw_line_func drawfn
 
 #define DEPTH 8
-#include "hw/omap_lcd_template.h"
+#include "omap_lcd_template.h"
 #define DEPTH 15
-#include "hw/omap_lcd_template.h"
+#include "omap_lcd_template.h"
 #define DEPTH 16
-#include "hw/omap_lcd_template.h"
+#include "omap_lcd_template.h"
 #define DEPTH 32
-#include "hw/omap_lcd_template.h"
+#include "omap_lcd_template.h"
 
 static draw_line_func draw_line_table2[33] = {
     [0 ... 32]	= NULL,
diff --git a/hw/pl110.c b/hw/display/pl110.c
index fbef675f9c..295434eded 100644
--- a/hw/pl110.c
+++ b/hw/display/pl110.c
@@ -9,7 +9,7 @@
 
 #include "hw/sysbus.h"
 #include "ui/console.h"
-#include "hw/framebuffer.h"
+#include "framebuffer.h"
 #include "ui/pixel_ops.h"
 
 #define PL110_CR_EN   0x001
@@ -111,15 +111,15 @@ static const unsigned char *idregs[] = {
 };
 
 #define BITS 8
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define BITS 15
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define BITS 16
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define BITS 24
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define BITS 32
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 
 static int pl110_enabled(pl110_state *s)
 {
diff --git a/hw/pl110_template.h b/hw/display/pl110_template.h
index ec4bfd6f8c..e738e4a241 100644
--- a/hw/pl110_template.h
+++ b/hw/display/pl110_template.h
@@ -27,20 +27,20 @@
 #undef RGB
 #define BORDER bgr
 #define ORDER 0
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define ORDER 1
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define ORDER 2
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #undef BORDER
 #define RGB
 #define BORDER rgb
 #define ORDER 0
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define ORDER 1
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #define ORDER 2
-#include "hw/pl110_template.h"
+#include "pl110_template.h"
 #undef BORDER
 
 static drawfn glue(pl110_draw_fn_,BITS)[48] =
diff --git a/hw/pxa2xx_lcd.c b/hw/display/pxa2xx_lcd.c
index f2b0c93661..c9bd42e023 100644
--- a/hw/pxa2xx_lcd.c
+++ b/hw/display/pxa2xx_lcd.c
@@ -12,11 +12,11 @@
 
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "ui/pixel_ops.h"
 /* FIXME: For graphic_rotate. Should probably be done in common code.  */
 #include "sysemu/sysemu.h"
-#include "hw/framebuffer.h"
+#include "framebuffer.h"
 
 struct DMAChannel {
     uint32_t branch;
@@ -981,15 +981,15 @@ static const VMStateDescription vmstate_pxa2xx_lcdc = {
 };
 
 #define BITS 8
-#include "hw/pxa2xx_template.h"
+#include "pxa2xx_template.h"
 #define BITS 15
-#include "hw/pxa2xx_template.h"
+#include "pxa2xx_template.h"
 #define BITS 16
-#include "hw/pxa2xx_template.h"
+#include "pxa2xx_template.h"
 #define BITS 24
-#include "hw/pxa2xx_template.h"
+#include "pxa2xx_template.h"
 #define BITS 32
-#include "hw/pxa2xx_template.h"
+#include "pxa2xx_template.h"
 
 PXA2xxLCDState *pxa2xx_lcdc_init(MemoryRegion *sysmem,
                                  hwaddr base, qemu_irq irq)
diff --git a/hw/pxa2xx_template.h b/hw/display/pxa2xx_template.h
index 1cbe36cb80..1cbe36cb80 100644
--- a/hw/pxa2xx_template.h
+++ b/hw/display/pxa2xx_template.h
diff --git a/hw/qxl-logger.c b/hw/display/qxl-logger.c
index 84f9aa1eda..3cd85d9b97 100644
--- a/hw/qxl-logger.c
+++ b/hw/display/qxl-logger.c
@@ -20,7 +20,7 @@
  */
 
 #include "qemu/timer.h"
-#include "hw/qxl.h"
+#include "qxl.h"
 
 static const char *qxl_type[] = {
     [ QXL_CMD_NOP ]     = "nop",
diff --git a/hw/qxl-render.c b/hw/display/qxl-render.c
index 8cd9be434d..f511a622c6 100644
--- a/hw/qxl-render.c
+++ b/hw/display/qxl-render.c
@@ -19,7 +19,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hw/qxl.h"
+#include "qxl.h"
 
 static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect)
 {
diff --git a/hw/qxl.c b/hw/display/qxl.c
index b66b41442a..930b7cf2ad 100644
--- a/hw/qxl.c
+++ b/hw/display/qxl.c
@@ -27,7 +27,7 @@
 #include "sysemu/sysemu.h"
 #include "trace.h"
 
-#include "hw/qxl.h"
+#include "qxl.h"
 
 /*
  * NOTE: SPICE_RING_PROD_ITEM accesses memory on the pci bar and as
diff --git a/hw/qxl.h b/hw/display/qxl.h
index 36f1a2502b..8e9b0c299e 100644
--- a/hw/qxl.h
+++ b/hw/display/qxl.h
@@ -6,7 +6,7 @@
 #include "ui/console.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
-#include "hw/vga_int.h"
+#include "vga_int.h"
 #include "qemu/thread.h"
 
 #include "ui/qemu-spice.h"
diff --git a/hw/sm501.c b/hw/display/sm501.c
index 93a06c90b9..6b660ac1c0 100644
--- a/hw/sm501.c
+++ b/hw/display/sm501.c
@@ -24,9 +24,9 @@
 
 #include <stdio.h>
 #include "hw/hw.h"
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "ui/console.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/sysbus.h"
 #include "hw/qdev-addr.h"
 #include "qemu/range.h"
@@ -1171,28 +1171,28 @@ typedef void draw_hwc_line_func(SM501State * s, int crt, uint8_t * palette,
                                 int c_y, uint8_t *d, int width);
 
 #define DEPTH 8
-#include "hw/sm501_template.h"
+#include "sm501_template.h"
 
 #define DEPTH 15
-#include "hw/sm501_template.h"
+#include "sm501_template.h"
 
 #define BGR_FORMAT
 #define DEPTH 15
-#include "hw/sm501_template.h"
+#include "sm501_template.h"
 
 #define DEPTH 16
-#include "hw/sm501_template.h"
+#include "sm501_template.h"
 
 #define BGR_FORMAT
 #define DEPTH 16
-#include "hw/sm501_template.h"
+#include "sm501_template.h"
 
 #define DEPTH 32
-#include "hw/sm501_template.h"
+#include "sm501_template.h"
 
 #define BGR_FORMAT
 #define DEPTH 32
-#include "hw/sm501_template.h"
+#include "sm501_template.h"
 
 static draw_line_func * draw_line8_funcs[] = {
     draw_line8_8,
diff --git a/hw/sm501_template.h b/hw/display/sm501_template.h
index 2d4a3d8b48..2d4a3d8b48 100644
--- a/hw/sm501_template.h
+++ b/hw/display/sm501_template.h
diff --git a/hw/ssd0303.c b/hw/display/ssd0303.c
index 68d1f24b06..183a87835c 100644
--- a/hw/ssd0303.c
+++ b/hw/display/ssd0303.c
@@ -10,7 +10,7 @@
 /* The controller can support a variety of different displays, but we only
    implement one.  Most of the commends relating to brightness and geometry
    setup are ignored. */
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "ui/console.h"
 
 //#define DEBUG_SSD0303 1
diff --git a/hw/ssd0323.c b/hw/display/ssd0323.c
index 5cf2f7058f..5cf2f7058f 100644
--- a/hw/ssd0323.c
+++ b/hw/display/ssd0323.c
diff --git a/hw/tc6393xb.c b/hw/display/tc6393xb.c
index 79c971b439..e252ce945f 100644
--- a/hw/tc6393xb.c
+++ b/hw/display/tc6393xb.c
@@ -11,8 +11,8 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "hw/hw.h"
-#include "hw/devices.h"
-#include "hw/flash.h"
+#include "hw/arm/devices.h"
+#include "hw/block/flash.h"
 #include "ui/console.h"
 #include "ui/pixel_ops.h"
 #include "sysemu/blockdev.h"
@@ -421,15 +421,15 @@ static void tc6393xb_nand_writeb(TC6393xbState *s, hwaddr addr, uint32_t value)
 }
 
 #define BITS 8
-#include "hw/tc6393xb_template.h"
+#include "tc6393xb_template.h"
 #define BITS 15
-#include "hw/tc6393xb_template.h"
+#include "tc6393xb_template.h"
 #define BITS 16
-#include "hw/tc6393xb_template.h"
+#include "tc6393xb_template.h"
 #define BITS 24
-#include "hw/tc6393xb_template.h"
+#include "tc6393xb_template.h"
 #define BITS 32
-#include "hw/tc6393xb_template.h"
+#include "tc6393xb_template.h"
 
 static void tc6393xb_draw_graphic(TC6393xbState *s, int full_update)
 {
diff --git a/hw/tc6393xb_template.h b/hw/display/tc6393xb_template.h
index 154aafd400..154aafd400 100644
--- a/hw/tc6393xb_template.h
+++ b/hw/display/tc6393xb_template.h
diff --git a/hw/tcx.c b/hw/display/tcx.c
index c44068e7c9..c44068e7c9 100644
--- a/hw/tcx.c
+++ b/hw/display/tcx.c
diff --git a/hw/vga-isa-mm.c b/hw/display/vga-isa-mm.c
index 02356d4d58..1c50070216 100644
--- a/hw/vga-isa-mm.c
+++ b/hw/display/vga-isa-mm.c
@@ -23,8 +23,8 @@
  */
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/pc.h"
-#include "hw/vga_int.h"
+#include "hw/i386/pc.h"
+#include "vga_int.h"
 #include "ui/pixel_ops.h"
 #include "qemu/timer.h"
 
diff --git a/hw/vga-isa.c b/hw/display/vga-isa.c
index 9e293217d0..90959ebc2c 100644
--- a/hw/vga-isa.c
+++ b/hw/display/vga-isa.c
@@ -25,8 +25,8 @@
  */
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/pc.h"
-#include "hw/vga_int.h"
+#include "hw/i386/pc.h"
+#include "vga_int.h"
 #include "ui/pixel_ops.h"
 #include "qemu/timer.h"
 #include "hw/loader.h"
diff --git a/hw/vga-pci.c b/hw/display/vga-pci.c
index 05fa9bcb64..a9c69b6ac7 100644
--- a/hw/vga-pci.c
+++ b/hw/display/vga-pci.c
@@ -26,7 +26,7 @@
 #include "hw/hw.h"
 #include "ui/console.h"
 #include "hw/pci/pci.h"
-#include "hw/vga_int.h"
+#include "vga_int.h"
 #include "ui/pixel_ops.h"
 #include "qemu/timer.h"
 #include "hw/loader.h"
diff --git a/hw/vga.c b/hw/display/vga.c
index 59bfb220f5..c1b67bbbf8 100644
--- a/hw/vga.c
+++ b/hw/display/vga.c
@@ -22,14 +22,14 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/vga.h"
+#include "vga.h"
 #include "ui/console.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
-#include "hw/vga_int.h"
+#include "vga_int.h"
 #include "ui/pixel_ops.h"
 #include "qemu/timer.h"
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 #include "trace.h"
 
 //#define DEBUG_VGA
@@ -986,28 +986,28 @@ typedef void vga_draw_line_func(VGACommonState *s1, uint8_t *d,
                                 const uint8_t *s, int width);
 
 #define DEPTH 8
-#include "hw/vga_template.h"
+#include "vga_template.h"
 
 #define DEPTH 15
-#include "hw/vga_template.h"
+#include "vga_template.h"
 
 #define BGR_FORMAT
 #define DEPTH 15
-#include "hw/vga_template.h"
+#include "vga_template.h"
 
 #define DEPTH 16
-#include "hw/vga_template.h"
+#include "vga_template.h"
 
 #define BGR_FORMAT
 #define DEPTH 16
-#include "hw/vga_template.h"
+#include "vga_template.h"
 
 #define DEPTH 32
-#include "hw/vga_template.h"
+#include "vga_template.h"
 
 #define BGR_FORMAT
 #define DEPTH 32
-#include "hw/vga_template.h"
+#include "vga_template.h"
 
 static unsigned int rgb_to_pixel8_dup(unsigned int r, unsigned int g, unsigned b)
 {
diff --git a/hw/vga.h b/hw/display/vga.h
index d917046da6..d917046da6 100644
--- a/hw/vga.h
+++ b/hw/display/vga.h
diff --git a/hw/vga_int.h b/hw/display/vga_int.h
index 260f7d6948..260f7d6948 100644
--- a/hw/vga_int.h
+++ b/hw/display/vga_int.h
diff --git a/hw/vga_template.h b/hw/display/vga_template.h
index f6f6a01d84..f6f6a01d84 100644
--- a/hw/vga_template.h
+++ b/hw/display/vga_template.h
diff --git a/hw/vmware_vga.c b/hw/display/vmware_vga.c
index 5b9ce8f96b..bcad47a68d 100644
--- a/hw/vmware_vga.c
+++ b/hw/display/vmware_vga.c
@@ -31,7 +31,7 @@
 #define HW_FILL_ACCEL
 #define HW_MOUSE_ACCEL
 
-#include "hw/vga_int.h"
+#include "vga_int.h"
 
 /* See http://vmware-svga.sf.net/ for some documentation on VMWare SVGA */
 
diff --git a/hw/xenfb.c b/hw/display/xenfb.c
index 7c46a2fa1e..8e4266142d 100644
--- a/hw/xenfb.c
+++ b/hw/display/xenfb.c
@@ -38,7 +38,7 @@
 #include "hw/hw.h"
 #include "ui/console.h"
 #include "char/char.h"
-#include "hw/xen_backend.h"
+#include "hw/xen/xen_backend.h"
 
 #include <xen/event_channel.h>
 #include <xen/io/fbif.h>
diff --git a/hw/dma/Makefile.objs b/hw/dma/Makefile.objs
new file mode 100644
index 0000000000..0e65ed0d74
--- /dev/null
+++ b/hw/dma/Makefile.objs
@@ -0,0 +1,13 @@
+common-obj-$(CONFIG_PUV3) += puv3_dma.o
+common-obj-$(CONFIG_RC4030) += rc4030.o
+common-obj-$(CONFIG_PL080) += pl080.o
+common-obj-$(CONFIG_PL330) += pl330.o
+common-obj-$(CONFIG_I82374) += i82374.o
+common-obj-$(CONFIG_I8257) += i8257.o
+common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o
+common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o
+common-obj-$(CONFIG_STP2000) += sparc32_dma.o
+common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o
+
+obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o
+obj-$(CONFIG_PXA2XX) += pxa2xx_dma.o
diff --git a/hw/etraxfs_dma.c b/hw/dma/etraxfs_dma.c
index a84ec1f23c..6a8c222502 100644
--- a/hw/etraxfs_dma.c
+++ b/hw/dma/etraxfs_dma.c
@@ -28,7 +28,7 @@
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
 
-#include "hw/etraxfs_dma.h"
+#include "hw/cris/etraxfs_dma.h"
 
 #define D(x)
 
diff --git a/hw/i82374.c b/hw/dma/i82374.c
index 22115e4fcf..835639d43c 100644
--- a/hw/i82374.c
+++ b/hw/dma/i82374.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 //#define DEBUG_I82374
 
diff --git a/hw/dma.c b/hw/dma/i8257.c
index fd1161ca31..eb60d45178 100644
--- a/hw/dma.c
+++ b/hw/dma/i8257.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "qemu/main-loop.h"
 
 /* #define DEBUG_DMA */
diff --git a/hw/omap_dma.c b/hw/dma/omap_dma.c
index 0c5902f6f9..184fcee1a7 100644
--- a/hw/omap_dma.c
+++ b/hw/dma/omap_dma.c
@@ -19,9 +19,9 @@
  */
 #include "qemu-common.h"
 #include "qemu/timer.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 #include "hw/irq.h"
-#include "hw/soc_dma.h"
+#include "hw/arm/soc_dma.h"
 
 struct omap_dma_channel_s {
     /* transfer data */
diff --git a/hw/pl080.c b/hw/dma/pl080.c
index 00b66b45b0..00b66b45b0 100644
--- a/hw/pl080.c
+++ b/hw/dma/pl080.c
diff --git a/hw/pl330.c b/hw/dma/pl330.c
index 1a04773a71..8b33138f30 100644
--- a/hw/pl330.c
+++ b/hw/dma/pl330.c
@@ -14,7 +14,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "sysbus.h"
+#include "hw/sysbus.h"
 #include "qemu/timer.h"
 #include "sysemu/dma.h"
 
@@ -870,9 +870,8 @@ static void pl330_dmasev(PL330Chan *ch, uint8_t opcode, uint8_t *args, int len)
         ch->parent->int_status |= (1 << ev_id);
         DB_PRINT("event interrupt raised %d\n", ev_id);
         qemu_irq_raise(ch->parent->irq[ev_id]);
-    } else {
-        ch->parent->ev_status |= (1 << ev_id);
     }
+    ch->parent->ev_status |= (1 << ev_id);
 }
 
 static void pl330_dmast(PL330Chan *ch, uint8_t opcode, uint8_t *args, int len)
diff --git a/hw/puv3_dma.c b/hw/dma/puv3_dma.c
index c05a14ea16..32844b5f75 100644
--- a/hw/puv3_dma.c
+++ b/hw/dma/puv3_dma.c
@@ -12,7 +12,7 @@
 #include "hw/sysbus.h"
 
 #undef DEBUG_PUV3
-#include "hw/puv3.h"
+#include "hw/unicore32/puv3.h"
 
 #define PUV3_DMA_CH_NR          (6)
 #define PUV3_DMA_CH_MASK        (0xff)
diff --git a/hw/pxa2xx_dma.c b/hw/dma/pxa2xx_dma.c
index 1db21c99ab..6e4c1f6d62 100644
--- a/hw/pxa2xx_dma.c
+++ b/hw/dma/pxa2xx_dma.c
@@ -9,7 +9,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "hw/sysbus.h"
 
 #define PXA255_DMA_NUM_CHANNELS 16
diff --git a/hw/rc4030.c b/hw/dma/rc4030.c
index b065515e67..03f92f1ab6 100644
--- a/hw/rc4030.c
+++ b/hw/dma/rc4030.c
@@ -23,7 +23,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/mips.h"
+#include "hw/mips/mips.h"
 #include "qemu/timer.h"
 
 /********************************************************/
diff --git a/hw/soc_dma.c b/hw/dma/soc_dma.c
index db5d609388..5e3491d373 100644
--- a/hw/soc_dma.c
+++ b/hw/dma/soc_dma.c
@@ -19,7 +19,7 @@
  */
 #include "qemu-common.h"
 #include "qemu/timer.h"
-#include "hw/soc_dma.h"
+#include "hw/arm/soc_dma.h"
 
 static void transfer_mem2mem(struct soc_dma_ch_s *ch)
 {
diff --git a/hw/sparc32_dma.c b/hw/dma/sparc32_dma.c
index 18e368ec98..fd21533f15 100644
--- a/hw/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -26,8 +26,8 @@
  */
 
 #include "hw/hw.h"
-#include "hw/sparc32_dma.h"
-#include "hw/sun4m.h"
+#include "hw/sparc/sparc32_dma.h"
+#include "hw/sparc/sun4m.h"
 #include "hw/sysbus.h"
 #include "trace.h"
 
diff --git a/hw/sun4m_iommu.c b/hw/dma/sun4m_iommu.c
index 33e77b02a3..8312bff5fe 100644
--- a/hw/sun4m_iommu.c
+++ b/hw/dma/sun4m_iommu.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/sun4m.h"
+#include "hw/sparc/sun4m.h"
 #include "hw/sysbus.h"
 #include "trace.h"
 
@@ -258,8 +258,7 @@ static uint32_t iommu_page_get_flags(IOMMUState *s, hwaddr addr)
     iopte = s->regs[IOMMU_BASE] << 4;
     addr &= ~s->iostart;
     iopte += (addr >> (IOMMU_PAGE_SHIFT - 2)) & ~3;
-    cpu_physical_memory_read(iopte, (uint8_t *)&ret, 4);
-    tswap32s(&ret);
+    ret = ldl_be_phys(iopte);
     trace_sun4m_iommu_page_get_flags(pa, iopte, ret);
     return ret;
 }
diff --git a/hw/xilinx_axidma.c b/hw/dma/xilinx_axidma.c
index 8db1a74acf..8db1a74acf 100644
--- a/hw/xilinx_axidma.c
+++ b/hw/dma/xilinx_axidma.c
diff --git a/hw/gpio/Makefile.objs b/hw/gpio/Makefile.objs
new file mode 100644
index 0000000000..2c8b51f09a
--- /dev/null
+++ b/hw/gpio/Makefile.objs
@@ -0,0 +1,6 @@
+common-obj-$(CONFIG_MAX7310) += max7310.o
+common-obj-$(CONFIG_PL061) += pl061.o
+common-obj-$(CONFIG_PUV3) += puv3_gpio.o
+common-obj-$(CONFIG_ZAURUS) += zaurus.o
+
+obj-$(CONFIG_OMAP) += omap_gpio.o
diff --git a/hw/max7310.c b/hw/gpio/max7310.c
index e5cb810a27..59b287703e 100644
--- a/hw/max7310.c
+++ b/hw/gpio/max7310.c
@@ -7,7 +7,7 @@
  * This file is licensed under GNU GPL.
  */
 
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 
 typedef struct {
     I2CSlave i2c;
diff --git a/hw/omap_gpio.c b/hw/gpio/omap_gpio.c
index c79f61c2ba..f5eeaea549 100644
--- a/hw/omap_gpio.c
+++ b/hw/gpio/omap_gpio.c
@@ -19,7 +19,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 #include "hw/sysbus.h"
 
 struct omap_gpio_s {
diff --git a/hw/pl061.c b/hw/gpio/pl061.c
index 74bc109488..74bc109488 100644
--- a/hw/pl061.c
+++ b/hw/gpio/pl061.c
diff --git a/hw/puv3_gpio.c b/hw/gpio/puv3_gpio.c
index b2a790b683..5bab97e95a 100644
--- a/hw/puv3_gpio.c
+++ b/hw/gpio/puv3_gpio.c
@@ -12,7 +12,7 @@
 #include "hw/sysbus.h"
 
 #undef DEBUG_PUV3
-#include "hw/puv3.h"
+#include "hw/unicore32/puv3.h"
 
 typedef struct {
     SysBusDevice busdev;
diff --git a/hw/zaurus.c b/hw/gpio/zaurus.c
index 7d3258cc66..d853ea1310 100644
--- a/hw/zaurus.c
+++ b/hw/gpio/zaurus.c
@@ -16,7 +16,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/sharpsl.h"
+#include "hw/arm/sharpsl.h"
 #include "hw/sysbus.h"
 
 #undef REG_FMT
diff --git a/hw/i2c/Makefile.objs b/hw/i2c/Makefile.objs
new file mode 100644
index 0000000000..648278e7c4
--- /dev/null
+++ b/hw/i2c/Makefile.objs
@@ -0,0 +1,7 @@
+common-obj-y += core.o smbus.o smbus_eeprom.o
+common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o
+common-obj-$(CONFIG_ACPI) += smbus_ich9.o
+common-obj-$(CONFIG_APM) += pm_smbus.o
+common-obj-$(CONFIG_BITBANG_I2C) += bitbang_i2c.o
+common-obj-$(CONFIG_EXYNOS4) += exynos4210_i2c.o
+obj-$(CONFIG_OMAP) += omap_i2c.o
diff --git a/hw/bitbang_i2c.c b/hw/i2c/bitbang_i2c.c
index b8e6d3a103..854b8e1940 100644
--- a/hw/bitbang_i2c.c
+++ b/hw/i2c/bitbang_i2c.c
@@ -10,7 +10,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "hw/hw.h"
-#include "hw/bitbang_i2c.h"
+#include "bitbang_i2c.h"
 #include "hw/sysbus.h"
 
 //#define DEBUG_BITBANG_I2C
diff --git a/hw/bitbang_i2c.h b/hw/i2c/bitbang_i2c.h
index e86062742c..2866ac351b 100644
--- a/hw/bitbang_i2c.h
+++ b/hw/i2c/bitbang_i2c.h
@@ -1,7 +1,7 @@
 #ifndef BITBANG_I2C_H
 #define BITBANG_I2C_H
 
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 
 typedef struct bitbang_i2c_interface bitbang_i2c_interface;
 
diff --git a/hw/i2c.c b/hw/i2c/core.c
index ad361cc57f..0c4fc1dbaa 100644
--- a/hw/i2c.c
+++ b/hw/i2c/core.c
@@ -7,7 +7,7 @@
  * This code is licensed under the LGPL.
  */
 
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 
 struct i2c_bus
 {
diff --git a/hw/exynos4210_i2c.c b/hw/i2c/exynos4210_i2c.c
index 9e428759a1..196f88907d 100644
--- a/hw/exynos4210_i2c.c
+++ b/hw/i2c/exynos4210_i2c.c
@@ -22,7 +22,7 @@
 
 #include "qemu/timer.h"
 #include "hw/sysbus.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 
 #ifndef EXYNOS4_I2C_DEBUG
 #define EXYNOS4_I2C_DEBUG                 0
diff --git a/hw/omap_i2c.c b/hw/i2c/omap_i2c.c
index 92f7b371ea..efb2254aea 100644
--- a/hw/omap_i2c.c
+++ b/hw/i2c/omap_i2c.c
@@ -17,8 +17,8 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/i2c.h"
-#include "hw/omap.h"
+#include "hw/i2c/i2c.h"
+#include "hw/arm/omap.h"
 #include "hw/sysbus.h"
 
 
diff --git a/hw/pm_smbus.c b/hw/i2c/pm_smbus.c
index 790061065c..0b5bb89976 100644
--- a/hw/pm_smbus.c
+++ b/hw/i2c/pm_smbus.c
@@ -18,9 +18,9 @@
  * <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/pm_smbus.h"
-#include "hw/smbus.h"
+#include "hw/i386/pc.h"
+#include "hw/i2c/pm_smbus.h"
+#include "hw/i2c/smbus.h"
 
 /* no save/load? */
 
diff --git a/hw/smbus.c b/hw/i2c/smbus.c
index 9626415bca..25d2d04163 100644
--- a/hw/smbus.c
+++ b/hw/i2c/smbus.c
@@ -10,8 +10,8 @@
 /* TODO: Implement PEC.  */
 
 #include "hw/hw.h"
-#include "hw/i2c.h"
-#include "hw/smbus.h"
+#include "hw/i2c/i2c.h"
+#include "hw/i2c/smbus.h"
 
 //#define DEBUG_SMBUS 1
 
diff --git a/hw/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c
index dff8403d6c..0154283762 100644
--- a/hw/smbus_eeprom.c
+++ b/hw/i2c/smbus_eeprom.c
@@ -23,8 +23,8 @@
  */
 
 #include "hw/hw.h"
-#include "hw/i2c.h"
-#include "hw/smbus.h"
+#include "hw/i2c/i2c.h"
+#include "hw/i2c/smbus.h"
 
 //#define DEBUG
 
diff --git a/hw/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index 732ebd3bb0..ca229789f4 100644
--- a/hw/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -25,14 +25,14 @@
  *
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/pm_smbus.h"
+#include "hw/i386/pc.h"
+#include "hw/i2c/pm_smbus.h"
 #include "hw/pci/pci.h"
 #include "sysemu/sysemu.h"
-#include "hw/i2c.h"
-#include "hw/smbus.h"
+#include "hw/i2c/i2c.h"
+#include "hw/i2c/smbus.h"
 
-#include "hw/ich9.h"
+#include "hw/i386/ich9.h"
 
 #define TYPE_ICH9_SMB_DEVICE "ICH9 SMB"
 #define ICH9_SMB_DEVICE(obj) \
diff --git a/hw/versatile_i2c.c b/hw/i2c/versatile_i2c.c
index d0444aecac..e09c83dda2 100644
--- a/hw/versatile_i2c.c
+++ b/hw/i2c/versatile_i2c.c
@@ -22,7 +22,7 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/bitbang_i2c.h"
+#include "bitbang_i2c.h"
 
 typedef struct {
     SysBusDevice busdev;
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index a78c0b2921..205d22e4aa 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -1,20 +1,4 @@
-obj-y += mc146818rtc.o
-obj-y += apic_common.o apic.o
-obj-y += sga.o ioapic_common.o ioapic.o piix_pci.o
-obj-y += vmport.o
-obj-y += pci/pci-hotplug.o wdt_ib700.o
-obj-y += debugcon.o debugexit.o
-obj-y += pc_sysfw.o
-obj-y += lpc_ich9.o q35.o
-obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o
-obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
-obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
-obj-y += kvm/
-obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
-obj-y += pc-testdev.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
+obj-$(CONFIG_KVM) += kvm/
 obj-y += multiboot.o smbios.o
 obj-y += pc.o pc_piix.o pc_q35.o
 obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
diff --git a/hw/i386/kvm/Makefile.objs b/hw/i386/kvm/Makefile.objs
new file mode 100644
index 0000000000..d8bce209bf
--- /dev/null
+++ b/hw/i386/kvm/Makefile.objs
@@ -0,0 +1 @@
+obj-y += clock.o apic.o i8259.o ioapic.o i8254.o pci-assign.o
diff --git a/hw/kvm/apic.c b/hw/i386/kvm/apic.c
index d994ea7c97..c6ff9821e3 100644
--- a/hw/kvm/apic.c
+++ b/hw/i386/kvm/apic.c
@@ -9,7 +9,7 @@
  * This work is licensed under the terms of the GNU GPL version 2.
  * See the COPYING file in the top-level directory.
  */
-#include "hw/apic_internal.h"
+#include "hw/i386/apic_internal.h"
 #include "hw/pci/msi.h"
 #include "sysemu/kvm.h"
 
diff --git a/hw/kvm/clock.c b/hw/i386/kvm/clock.c
index fa40e283f7..fa40e283f7 100644
--- a/hw/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
diff --git a/hw/kvm/i8254.c b/hw/i386/kvm/i8254.c
index 04ad649b0e..da90711853 100644
--- a/hw/kvm/i8254.c
+++ b/hw/i386/kvm/i8254.c
@@ -24,8 +24,8 @@
  */
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
-#include "hw/i8254.h"
-#include "hw/i8254_internal.h"
+#include "hw/timer/i8254.h"
+#include "hw/timer/i8254_internal.h"
 #include "sysemu/kvm.h"
 
 #define KVM_PIT_REINJECT_BIT 0
diff --git a/hw/kvm/i8259.c b/hw/i386/kvm/i8259.c
index 5ae8b6819b..ea77be8638 100644
--- a/hw/kvm/i8259.c
+++ b/hw/i386/kvm/i8259.c
@@ -9,8 +9,8 @@
  * This work is licensed under the terms of the GNU GPL version 2.
  * See the COPYING file in the top-level directory.
  */
-#include "hw/i8259_internal.h"
-#include "hw/apic_internal.h"
+#include "hw/isa/i8259_internal.h"
+#include "hw/i386/apic_internal.h"
 #include "sysemu/kvm.h"
 
 static void kvm_pic_get(PICCommonState *s)
diff --git a/hw/kvm/ioapic.c b/hw/i386/kvm/ioapic.c
index 23877d4259..a3bd519b4d 100644
--- a/hw/kvm/ioapic.c
+++ b/hw/i386/kvm/ioapic.c
@@ -10,9 +10,9 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "hw/pc.h"
-#include "hw/ioapic_internal.h"
-#include "hw/apic_internal.h"
+#include "hw/i386/pc.h"
+#include "hw/i386/ioapic_internal.h"
+#include "hw/i386/apic_internal.h"
 #include "sysemu/kvm.h"
 
 /* PC Utility function */
diff --git a/hw/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index da64b5b86f..c1e08ec1a0 100644
--- a/hw/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -27,7 +27,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "qemu/error-report.h"
 #include "ui/console.h"
 #include "hw/loader.h"
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index cc95e5c3f0..ed9b448d07 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -11,7 +11,7 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/cpus.h"
 #include "sysemu/kvm.h"
-#include "hw/apic_internal.h"
+#include "hw/i386/apic_internal.h"
 
 #define VAPIC_IO_PORT           0x7e
 
diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
index 3cb228f0ca..d696507940 100644
--- a/hw/i386/multiboot.c
+++ b/hw/i386/multiboot.c
@@ -23,8 +23,8 @@
  */
 
 #include "hw/hw.h"
-#include "hw/fw_cfg.h"
-#include "hw/multiboot.h"
+#include "hw/nvram/fw_cfg.h"
+#include "multiboot.h"
 #include "hw/loader.h"
 #include "elf.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/multiboot.h b/hw/i386/multiboot.h
index 98fb1b776c..98fb1b776c 100644
--- a/hw/multiboot.h
+++ b/hw/i386/multiboot.h
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ebbf059225..8d75b34218 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -22,30 +22,30 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/serial.h"
-#include "hw/apic.h"
-#include "hw/fdc.h"
+#include "hw/i386/pc.h"
+#include "hw/char/serial.h"
+#include "hw/i386/apic.h"
+#include "hw/block/fdc.h"
 #include "hw/ide.h"
 #include "hw/pci/pci.h"
 #include "monitor/monitor.h"
-#include "hw/fw_cfg.h"
-#include "hw/hpet_emul.h"
-#include "hw/smbios.h"
+#include "hw/nvram/fw_cfg.h"
+#include "hw/timer/hpet.h"
+#include "hw/i386/smbios.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "hw/multiboot.h"
-#include "hw/mc146818rtc.h"
-#include "hw/i8254.h"
-#include "hw/pcspk.h"
+#include "multiboot.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/timer/i8254.h"
+#include "hw/audio/pcspk.h"
 #include "hw/pci/msi.h"
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
 #include "kvm_i386.h"
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "ui/qemu-spice.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 0abc9f11e3..cff8013b83 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -25,8 +25,8 @@
 #include <glib.h>
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/apic.h"
+#include "hw/i386/pc.h"
+#include "hw/i386/apic.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_ids.h"
 #include "hw/usb.h"
@@ -39,8 +39,8 @@
 #include "hw/sysbus.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/blockdev.h"
-#include "hw/smbus.h"
-#include "hw/xen.h"
+#include "hw/i2c/smbus.h"
+#include "hw/xen/xen.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 #include "cpu.h"
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 4f5f347309..6ac1a89ad7 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -29,15 +29,15 @@
  */
 #include "hw/hw.h"
 #include "sysemu/arch_init.h"
-#include "hw/smbus.h"
+#include "hw/i2c/smbus.h"
 #include "hw/boards.h"
-#include "hw/mc146818rtc.h"
-#include "hw/xen.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/xen/xen.h"
 #include "sysemu/kvm.h"
 #include "hw/kvm/clock.h"
-#include "hw/q35.h"
+#include "hw/pci-host/q35.h"
 #include "exec/address-spaces.h"
-#include "hw/ich9.h"
+#include "hw/i386/ich9.h"
 #include "hw/ide/pci.h"
 #include "hw/ide/ahci.h"
 #include "hw/usb.h"
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index 672ee9b0e7..c00bb2fad8 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -14,7 +14,7 @@
  */
 
 #include "sysemu/sysemu.h"
-#include "hw/smbios.h"
+#include "hw/i386/smbios.h"
 #include "hw/loader.h"
 
 /*
diff --git a/hw/i386/xen_domainbuild.c b/hw/i386/xen_domainbuild.c
index d477061545..4e2cf95ae5 100644
--- a/hw/i386/xen_domainbuild.c
+++ b/hw/i386/xen_domainbuild.c
@@ -1,6 +1,6 @@
 #include <signal.h>
-#include "hw/xen_backend.h"
-#include "hw/xen_domainbuild.h"
+#include "hw/xen/xen_backend.h"
+#include "xen_domainbuild.h"
 #include "qemu/timer.h"
 #include "qemu/log.h"
 
diff --git a/hw/xen_domainbuild.h b/hw/i386/xen_domainbuild.h
index 681cbe5fd8..29a91ea7b1 100644
--- a/hw/xen_domainbuild.h
+++ b/hw/i386/xen_domainbuild.h
@@ -1,7 +1,7 @@
 #ifndef QEMU_HW_XEN_DOMAINBUILD_H
 #define QEMU_HW_XEN_DOMAINBUILD_H 1
 
-#include "hw/xen_common.h"
+#include "hw/xen/xen_common.h"
 
 int xenstore_domain_init1(const char *kernel, const char *ramdisk,
                           const char *cmdline);
diff --git a/hw/i386/xen_machine_pv.c b/hw/i386/xen_machine_pv.c
index 37ba34e5a9..f829a52232 100644
--- a/hw/i386/xen_machine_pv.c
+++ b/hw/i386/xen_machine_pv.c
@@ -23,10 +23,10 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/boards.h"
-#include "hw/xen_backend.h"
-#include "hw/xen_domainbuild.h"
+#include "hw/xen/xen_backend.h"
+#include "xen_domainbuild.h"
 #include "sysemu/blockdev.h"
 
 static void xen_init_pv(QEMUMachineInitArgs *args)
diff --git a/hw/ide/Makefile.objs b/hw/ide/Makefile.objs
index 5c8c22aad7..729e9bd0db 100644
--- a/hw/ide/Makefile.objs
+++ b/hw/ide/Makefile.objs
@@ -5,6 +5,8 @@ common-obj-$(CONFIG_IDE_ISA) += isa.o
 common-obj-$(CONFIG_IDE_PIIX) += piix.o
 common-obj-$(CONFIG_IDE_CMD646) += cmd646.o
 common-obj-$(CONFIG_IDE_MACIO) += macio.o
+common-obj-$(CONFIG_IDE_MMIO) += mmio.o
 common-obj-$(CONFIG_IDE_VIA) += via.o
+common-obj-$(CONFIG_MICRODRIVE) += microdrive.o
 common-obj-$(CONFIG_AHCI) += ahci.o
 common-obj-$(CONFIG_AHCI) += ich.o
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index ad0094f532..d0ae8afba2 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -23,7 +23,7 @@
 
 #include <hw/hw.h>
 #include <hw/pci/msi.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
 #include <hw/sysbus.h>
 
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 861fd2bec3..05e60b1cdc 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -24,7 +24,7 @@
  */
 
 #include "hw/ide/internal.h"
-#include "hw/scsi.h"
+#include "hw/scsi/scsi.h"
 
 static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret);
 
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index 745ef94deb..541d4ef335 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -23,9 +23,9 @@
  * THE SOFTWARE.
  */
 #include <hw/hw.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
-#include <hw/isa.h>
+#include <hw/isa/isa.h>
 #include "block/block.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 3743dc3b55..87d67b7bcb 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -23,14 +23,14 @@
  * THE SOFTWARE.
  */
 #include <hw/hw.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
-#include <hw/isa.h>
+#include <hw/isa/isa.h>
 #include "qemu/error-report.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "sysemu/blockdev.h"
 
 #include <hw/ide/internal.h>
diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index cc30adc701..ed1f1a287e 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -62,9 +62,9 @@
 
 #include <hw/hw.h>
 #include <hw/pci/msi.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
-#include <hw/isa.h>
+#include <hw/isa/isa.h>
 #include "block/block.h"
 #include "sysemu/dma.h"
 
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index d80360e85b..2c89b50c5e 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -7,12 +7,12 @@
  * non-internal declarations are in hw/ide.h
  */
 #include <hw/ide.h>
-#include <hw/isa.h>
+#include <hw/isa/isa.h>
 #include "exec/iorange.h"
 #include "sysemu/dma.h"
 #include "sysemu/sysemu.h"
-#include "hw/block-common.h"
-#include "hw/scsi-defs.h"
+#include "hw/block/block.h"
+#include "block/scsi.h"
 
 /* debug IDE devices */
 //#define DEBUG_IDE
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index fb7bb8201d..e0d47bf7cf 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -23,8 +23,8 @@
  * THE SOFTWARE.
  */
 #include <hw/hw.h>
-#include <hw/pc.h>
-#include <hw/isa.h>
+#include <hw/i386/pc.h>
+#include <hw/isa/isa.h>
 #include "block/block.h"
 #include "sysemu/dma.h"
 
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 375c46f9da..64b2406ab0 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -24,7 +24,7 @@
  */
 #include "hw/hw.h"
 #include "hw/ppc/mac.h"
-#include "hw/mac_dbdma.h"
+#include "hw/ppc/mac_dbdma.h"
 #include "block/block.h"
 #include "sysemu/dma.h"
 
diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
index 642774ef98..92c1df0460 100644
--- a/hw/ide/microdrive.c
+++ b/hw/ide/microdrive.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include <hw/hw.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pcmcia.h>
 #include "block/block.h"
 #include "sysemu/dma.h"
diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 59fd53992a..a310975391 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -23,9 +23,9 @@
  * THE SOFTWARE.
  */
 #include <hw/hw.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
-#include <hw/isa.h>
+#include <hw/isa/isa.h>
 #include "block/block.h"
 #include "sysemu/dma.h"
 
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 4d3e82266c..1de284d0e3 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -24,9 +24,9 @@
  */
 
 #include <hw/hw.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
-#include <hw/isa.h>
+#include <hw/isa/isa.h>
 #include "sysemu/blockdev.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index fd06da7003..8a9a891769 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -21,7 +21,7 @@
 #include "qemu/error-report.h"
 #include <hw/ide/internal.h>
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "sysemu/sysemu.h"
 
 /* --------------------------------- */
diff --git a/hw/ide/via.c b/hw/ide/via.c
index f40c1adc8c..9d6a644391 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -24,9 +24,9 @@
  * THE SOFTWARE.
  */
 #include <hw/hw.h>
-#include <hw/pc.h>
+#include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
-#include <hw/isa.h>
+#include <hw/isa/isa.h>
 #include "block/block.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
new file mode 100644
index 0000000000..e8c80b9de2
--- /dev/null
+++ b/hw/input/Makefile.objs
@@ -0,0 +1,13 @@
+common-obj-$(CONFIG_ADB) += adb.o
+common-obj-y += hid.o
+common-obj-$(CONFIG_LM832X) += lm832x.o
+common-obj-$(CONFIG_PCKBD) += pckbd.o
+common-obj-$(CONFIG_PL050) += pl050.o
+common-obj-y += ps2.o
+common-obj-$(CONFIG_STELLARIS_INPUT) += stellaris_input.o
+common-obj-$(CONFIG_TSC2005) += tsc2005.o
+common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
+
+obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
+obj-$(CONFIG_PXA2XX) += pxa2xx_keypad.o
+obj-$(CONFIG_TSC210X) += tsc210x.o
diff --git a/hw/adb.c b/hw/input/adb.c
index fd9052c16b..a75d3fd7b9 100644
--- a/hw/adb.c
+++ b/hw/input/adb.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/adb.h"
+#include "hw/input/adb.h"
 #include "ui/console.h"
 
 /* debug ADB */
diff --git a/hw/hid.c b/hw/input/hid.c
index 28b34747ff..5fbde98f65 100644
--- a/hw/hid.c
+++ b/hw/input/hid.c
@@ -25,7 +25,7 @@
 #include "hw/hw.h"
 #include "ui/console.h"
 #include "qemu/timer.h"
-#include "hw/hid.h"
+#include "hw/input/hid.h"
 
 #define HID_USAGE_ERROR_ROLLOVER        0x01
 #define HID_USAGE_POSTFAIL              0x02
diff --git a/hw/lm832x.c b/hw/input/lm832x.c
index a064dfd172..bacbeb2343 100644
--- a/hw/lm832x.c
+++ b/hw/input/lm832x.c
@@ -19,7 +19,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "qemu/timer.h"
 #include "ui/console.h"
 
diff --git a/hw/milkymist-softusb.c b/hw/input/milkymist-softusb.c
index 90a0ae5769..3edab4ff0b 100644
--- a/hw/milkymist-softusb.c
+++ b/hw/input/milkymist-softusb.c
@@ -25,7 +25,7 @@
 #include "hw/sysbus.h"
 #include "trace.h"
 #include "ui/console.h"
-#include "hw/hid.h"
+#include "hw/input/hid.h"
 #include "qemu/error-report.h"
 
 enum {
diff --git a/hw/pckbd.c b/hw/input/pckbd.c
index cc63df0570..08ceb9fe8a 100644
--- a/hw/pckbd.c
+++ b/hw/input/pckbd.c
@@ -22,9 +22,9 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/isa.h"
-#include "hw/pc.h"
-#include "hw/ps2.h"
+#include "hw/isa/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/input/ps2.h"
 #include "sysemu/sysemu.h"
 
 /* debug PC keyboard */
diff --git a/hw/pl050.c b/hw/input/pl050.c
index bc31ab6885..7dd8a59dd4 100644
--- a/hw/pl050.c
+++ b/hw/input/pl050.c
@@ -8,7 +8,7 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/ps2.h"
+#include "hw/input/ps2.h"
 
 typedef struct {
     SysBusDevice busdev;
@@ -24,14 +24,13 @@ typedef struct {
 
 static const VMStateDescription vmstate_pl050 = {
     .name = "pl050",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32(cr, pl050_state),
         VMSTATE_UINT32(clk, pl050_state),
         VMSTATE_UINT32(last, pl050_state),
         VMSTATE_INT32(pending, pl050_state),
-        VMSTATE_INT32(is_mouse, pl050_state),
         VMSTATE_END_OF_LIST()
     }
 };
diff --git a/hw/ps2.c b/hw/input/ps2.c
index 233a087a5e..34120796b1 100644
--- a/hw/ps2.c
+++ b/hw/input/ps2.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/ps2.h"
+#include "hw/input/ps2.h"
 #include "ui/console.h"
 #include "sysemu/sysemu.h"
 
diff --git a/hw/pxa2xx_keypad.c b/hw/input/pxa2xx_keypad.c
index 32ea7a5d34..1fd5f2076a 100644
--- a/hw/pxa2xx_keypad.c
+++ b/hw/input/pxa2xx_keypad.c
@@ -12,7 +12,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "ui/console.h"
 
 /*
diff --git a/hw/stellaris_input.c b/hw/input/stellaris_input.c
index 4e407922a0..f83fc3f288 100644
--- a/hw/stellaris_input.c
+++ b/hw/input/stellaris_input.c
@@ -7,7 +7,7 @@
  * This code is licensed under the GPL.
  */
 #include "hw/hw.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "ui/console.h"
 
 typedef struct {
diff --git a/hw/tsc2005.c b/hw/input/tsc2005.c
index a771cd5e52..34ee1fb3cf 100644
--- a/hw/tsc2005.c
+++ b/hw/input/tsc2005.c
@@ -21,7 +21,7 @@
 #include "hw/hw.h"
 #include "qemu/timer.h"
 #include "ui/console.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 
 #define TSC_CUT_RESOLUTION(value, p)	((value) >> (16 - (p ? 12 : 10)))
 
diff --git a/hw/tsc210x.c b/hw/input/tsc210x.c
index b93e502e05..e6c217c8db 100644
--- a/hw/tsc210x.c
+++ b/hw/input/tsc210x.c
@@ -23,8 +23,8 @@
 #include "audio/audio.h"
 #include "qemu/timer.h"
 #include "ui/console.h"
-#include "hw/omap.h"	/* For I2SCodec and uWireSlave */
-#include "hw/devices.h"
+#include "hw/arm/omap.h"	/* For I2SCodec and uWireSlave */
+#include "hw/arm/devices.h"
 
 #define TSC_DATA_REGISTERS_PAGE		0x0
 #define TSC_CONTROL_REGISTERS_PAGE	0x1
diff --git a/hw/vmmouse.c b/hw/input/vmmouse.c
index a9d227e17d..f4f9c9373d 100644
--- a/hw/vmmouse.c
+++ b/hw/input/vmmouse.c
@@ -23,8 +23,8 @@
  */
 #include "hw/hw.h"
 #include "ui/console.h"
-#include "hw/ps2.h"
-#include "hw/pc.h"
+#include "hw/input/ps2.h"
+#include "hw/i386/pc.h"
 #include "hw/qdev.h"
 
 /* debug only vmmouse */
diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs
new file mode 100644
index 0000000000..718d97ae8a
--- /dev/null
+++ b/hw/intc/Makefile.objs
@@ -0,0 +1,23 @@
+common-obj-$(CONFIG_HEATHROW_PIC) += heathrow_pic.o
+common-obj-$(CONFIG_I8259) += i8259_common.o i8259.o
+common-obj-$(CONFIG_PL190) += pl190.o
+common-obj-$(CONFIG_PUV3) += puv3_intc.o
+common-obj-$(CONFIG_XILINX) += xilinx_intc.o
+common-obj-$(CONFIG_ETRAXFS) += etraxfs_pic.o
+common-obj-$(CONFIG_IMX) += imx_avic.o
+common-obj-$(CONFIG_LM32) += lm32_pic.o
+common-obj-$(CONFIG_REALVIEW) += realview_gic.o
+common-obj-$(CONFIG_SLAVIO) += sbi.o slavio_intctl.o sun4c_intctl.o
+common-obj-$(CONFIG_IOAPIC) += ioapic_common.o
+common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o
+
+obj-$(CONFIG_APIC) += apic.o apic_common.o
+obj-$(CONFIG_ARM_GIC) += arm_gic.o
+obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o
+obj-$(CONFIG_STELLARIS) += armv7m_nvic.o
+obj-$(CONFIG_EXYNOS4) += exynos4210_gic.o exynos4210_combiner.o
+obj-$(CONFIG_GRLIB) += grlib_irqmp.o
+obj-$(CONFIG_IOAPIC) += ioapic.o
+obj-$(CONFIG_OMAP) += omap_intc.o
+obj-$(CONFIG_OPENPIC) += openpic.o
+obj-$(CONFIG_SH4) += sh_intc.o
diff --git a/hw/apic.c b/hw/intc/apic.c
index d2395f04dd..2d79a9ea7f 100644
--- a/hw/apic.c
+++ b/hw/intc/apic.c
@@ -17,14 +17,14 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>
  */
 #include "qemu/thread.h"
-#include "hw/apic_internal.h"
-#include "hw/apic.h"
-#include "hw/ioapic.h"
+#include "hw/i386/apic_internal.h"
+#include "hw/i386/apic.h"
+#include "hw/i386/ioapic.h"
 #include "hw/pci/msi.h"
 #include "qemu/host-utils.h"
 #include "trace.h"
-#include "hw/pc.h"
-#include "hw/apic-msidef.h"
+#include "hw/i386/pc.h"
+#include "hw/i386/apic-msidef.h"
 
 #define MAX_APIC_WORDS 8
 
diff --git a/hw/apic_common.c b/hw/intc/apic_common.c
index 37985097ca..e0ae07afd5 100644
--- a/hw/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -17,8 +17,8 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>
  */
-#include "hw/apic.h"
-#include "hw/apic_internal.h"
+#include "hw/i386/apic.h"
+#include "hw/i386/apic_internal.h"
 #include "trace.h"
 #include "sysemu/kvm.h"
 
diff --git a/hw/arm_gic.c b/hw/intc/arm_gic.c
index bcb072bbcf..bae65721fd 100644
--- a/hw/arm_gic.c
+++ b/hw/intc/arm_gic.c
@@ -19,7 +19,7 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/arm_gic_internal.h"
+#include "gic_internal.h"
 
 //#define DEBUG_GIC
 
diff --git a/hw/arm_gic_common.c b/hw/intc/arm_gic_common.c
index f2dc8bf555..08560f23a3 100644
--- a/hw/arm_gic_common.c
+++ b/hw/intc/arm_gic_common.c
@@ -18,92 +18,67 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hw/arm_gic_internal.h"
+#include "gic_internal.h"
 
-static void gic_save(QEMUFile *f, void *opaque)
+static void gic_pre_save(void *opaque)
 {
     GICState *s = (GICState *)opaque;
     ARMGICCommonClass *c = ARM_GIC_COMMON_GET_CLASS(s);
-    int i;
-    int j;
 
     if (c->pre_save) {
         c->pre_save(s);
     }
-
-    qemu_put_be32(f, s->enabled);
-    for (i = 0; i < s->num_cpu; i++) {
-        qemu_put_be32(f, s->cpu_enabled[i]);
-        for (j = 0; j < GIC_INTERNAL; j++) {
-            qemu_put_be32(f, s->priority1[j][i]);
-        }
-        for (j = 0; j < s->num_irq; j++) {
-            qemu_put_be32(f, s->last_active[j][i]);
-        }
-        qemu_put_be32(f, s->priority_mask[i]);
-        qemu_put_be32(f, s->running_irq[i]);
-        qemu_put_be32(f, s->running_priority[i]);
-        qemu_put_be32(f, s->current_pending[i]);
-    }
-    for (i = 0; i < s->num_irq - GIC_INTERNAL; i++) {
-        qemu_put_be32(f, s->priority2[i]);
-    }
-    for (i = 0; i < s->num_irq; i++) {
-        qemu_put_be32(f, s->irq_target[i]);
-        qemu_put_byte(f, s->irq_state[i].enabled);
-        qemu_put_byte(f, s->irq_state[i].pending);
-        qemu_put_byte(f, s->irq_state[i].active);
-        qemu_put_byte(f, s->irq_state[i].level);
-        qemu_put_byte(f, s->irq_state[i].model);
-        qemu_put_byte(f, s->irq_state[i].trigger);
-    }
 }
 
-static int gic_load(QEMUFile *f, void *opaque, int version_id)
+static int gic_post_load(void *opaque, int version_id)
 {
     GICState *s = (GICState *)opaque;
     ARMGICCommonClass *c = ARM_GIC_COMMON_GET_CLASS(s);
-    int i;
-    int j;
-
-    if (version_id != 3) {
-        return -EINVAL;
-    }
-
-    s->enabled = qemu_get_be32(f);
-    for (i = 0; i < s->num_cpu; i++) {
-        s->cpu_enabled[i] = qemu_get_be32(f);
-        for (j = 0; j < GIC_INTERNAL; j++) {
-            s->priority1[j][i] = qemu_get_be32(f);
-        }
-        for (j = 0; j < s->num_irq; j++) {
-            s->last_active[j][i] = qemu_get_be32(f);
-        }
-        s->priority_mask[i] = qemu_get_be32(f);
-        s->running_irq[i] = qemu_get_be32(f);
-        s->running_priority[i] = qemu_get_be32(f);
-        s->current_pending[i] = qemu_get_be32(f);
-    }
-    for (i = 0; i < s->num_irq - GIC_INTERNAL; i++) {
-        s->priority2[i] = qemu_get_be32(f);
-    }
-    for (i = 0; i < s->num_irq; i++) {
-        s->irq_target[i] = qemu_get_be32(f);
-        s->irq_state[i].enabled = qemu_get_byte(f);
-        s->irq_state[i].pending = qemu_get_byte(f);
-        s->irq_state[i].active = qemu_get_byte(f);
-        s->irq_state[i].level = qemu_get_byte(f);
-        s->irq_state[i].model = qemu_get_byte(f);
-        s->irq_state[i].trigger = qemu_get_byte(f);
-    }
 
     if (c->post_load) {
         c->post_load(s);
     }
-
     return 0;
 }
 
+static const VMStateDescription vmstate_gic_irq_state = {
+    .name = "arm_gic_irq_state",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT8(enabled, gic_irq_state),
+        VMSTATE_UINT8(pending, gic_irq_state),
+        VMSTATE_UINT8(active, gic_irq_state),
+        VMSTATE_UINT8(level, gic_irq_state),
+        VMSTATE_BOOL(model, gic_irq_state),
+        VMSTATE_BOOL(trigger, gic_irq_state),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_gic = {
+    .name = "arm_gic",
+    .version_id = 4,
+    .minimum_version_id = 4,
+    .pre_save = gic_pre_save,
+    .post_load = gic_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_BOOL(enabled, GICState),
+        VMSTATE_BOOL_ARRAY(cpu_enabled, GICState, NCPU),
+        VMSTATE_STRUCT_ARRAY(irq_state, GICState, GIC_MAXIRQ, 1,
+                             vmstate_gic_irq_state, gic_irq_state),
+        VMSTATE_UINT8_ARRAY(irq_target, GICState, GIC_MAXIRQ),
+        VMSTATE_UINT8_2DARRAY(priority1, GICState, GIC_INTERNAL, NCPU),
+        VMSTATE_UINT8_ARRAY(priority2, GICState, GIC_MAXIRQ - GIC_INTERNAL),
+        VMSTATE_UINT16_2DARRAY(last_active, GICState, GIC_MAXIRQ, NCPU),
+        VMSTATE_UINT16_ARRAY(priority_mask, GICState, NCPU),
+        VMSTATE_UINT16_ARRAY(running_irq, GICState, NCPU),
+        VMSTATE_UINT16_ARRAY(running_priority, GICState, NCPU),
+        VMSTATE_UINT16_ARRAY(current_pending, GICState, NCPU),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void arm_gic_common_realize(DeviceState *dev, Error **errp)
 {
     GICState *s = ARM_GIC_COMMON(dev);
@@ -131,8 +106,6 @@ static void arm_gic_common_realize(DeviceState *dev, Error **errp)
                    num_irq);
         return;
     }
-
-    register_savevm(NULL, "arm_gic", -1, 3, gic_save, gic_load, s);
 }
 
 static void arm_gic_common_reset(DeviceState *dev)
@@ -149,7 +122,7 @@ static void arm_gic_common_reset(DeviceState *dev)
         s->current_pending[i] = 1023;
         s->running_irq[i] = 1023;
         s->running_priority[i] = 0x100;
-        s->cpu_enabled[i] = 0;
+        s->cpu_enabled[i] = false;
     }
     for (i = 0; i < 16; i++) {
         GIC_SET_ENABLED(i, ALL_CPU_MASK);
@@ -161,7 +134,7 @@ static void arm_gic_common_reset(DeviceState *dev)
             s->irq_target[i] = 1;
         }
     }
-    s->enabled = 0;
+    s->enabled = false;
 }
 
 static Property arm_gic_common_properties[] = {
@@ -182,6 +155,7 @@ static void arm_gic_common_class_init(ObjectClass *klass, void *data)
     dc->reset = arm_gic_common_reset;
     dc->realize = arm_gic_common_realize;
     dc->props = arm_gic_common_properties;
+    dc->vmsd = &vmstate_gic;
     dc->no_user = 1;
 }
 
diff --git a/hw/kvm/arm_gic.c b/hw/intc/arm_gic_kvm.c
index 22b40b4f84..b7564568dc 100644
--- a/hw/kvm/arm_gic.c
+++ b/hw/intc/arm_gic_kvm.c
@@ -21,7 +21,7 @@
 #include "hw/sysbus.h"
 #include "sysemu/kvm.h"
 #include "kvm_arm.h"
-#include "hw/arm_gic_internal.h"
+#include "gic_internal.h"
 
 #define TYPE_KVM_ARM_GIC "kvm-arm-gic"
 #define KVM_ARM_GIC(obj) \
diff --git a/hw/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index d198cfd96e..566b4bfa41 100644
--- a/hw/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -12,9 +12,9 @@
 
 #include "hw/sysbus.h"
 #include "qemu/timer.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #include "exec/address-spaces.h"
-#include "hw/arm_gic_internal.h"
+#include "gic_internal.h"
 
 typedef struct {
     GICState gic;
@@ -458,10 +458,10 @@ static void armv7m_nvic_reset(DeviceState *dev)
      * as enabled by default, and with a priority mask which allows
      * all interrupts through.
      */
-    s->gic.cpu_enabled[0] = 1;
+    s->gic.cpu_enabled[0] = true;
     s->gic.priority_mask[0] = 0x100;
     /* The NVIC as a whole is always enabled. */
-    s->gic.enabled = 1;
+    s->gic.enabled = true;
     systick_reset(s);
 }
 
diff --git a/hw/etraxfs_pic.c b/hw/intc/etraxfs_pic.c
index 635103c001..635103c001 100644
--- a/hw/etraxfs_pic.c
+++ b/hw/intc/etraxfs_pic.c
diff --git a/hw/exynos4210_combiner.c b/hw/intc/exynos4210_combiner.c
index 5818f10132..6874287302 100644
--- a/hw/exynos4210_combiner.c
+++ b/hw/intc/exynos4210_combiner.c
@@ -29,7 +29,7 @@
 
 #include "hw/sysbus.h"
 
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 
 //#define DEBUG_COMBINER
 
diff --git a/hw/exynos4210_gic.c b/hw/intc/exynos4210_gic.c
index 807849c574..bad6dde652 100644
--- a/hw/exynos4210_gic.c
+++ b/hw/intc/exynos4210_gic.c
@@ -23,7 +23,7 @@
 #include "hw/sysbus.h"
 #include "qemu-common.h"
 #include "hw/irq.h"
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 
 enum ExtGicId {
     EXT_GIC_ID_MDMA_LCD0 = 66,
diff --git a/hw/arm_gic_internal.h b/hw/intc/gic_internal.h
index 3e1928b7eb..99a3bc362b 100644
--- a/hw/arm_gic_internal.h
+++ b/hw/intc/gic_internal.h
@@ -45,14 +45,14 @@
 #define GIC_SET_ACTIVE(irq, cm) s->irq_state[irq].active |= (cm)
 #define GIC_CLEAR_ACTIVE(irq, cm) s->irq_state[irq].active &= ~(cm)
 #define GIC_TEST_ACTIVE(irq, cm) ((s->irq_state[irq].active & (cm)) != 0)
-#define GIC_SET_MODEL(irq) s->irq_state[irq].model = 1
-#define GIC_CLEAR_MODEL(irq) s->irq_state[irq].model = 0
+#define GIC_SET_MODEL(irq) s->irq_state[irq].model = true
+#define GIC_CLEAR_MODEL(irq) s->irq_state[irq].model = false
 #define GIC_TEST_MODEL(irq) s->irq_state[irq].model
 #define GIC_SET_LEVEL(irq, cm) s->irq_state[irq].level = (cm)
 #define GIC_CLEAR_LEVEL(irq, cm) s->irq_state[irq].level &= ~(cm)
 #define GIC_TEST_LEVEL(irq, cm) ((s->irq_state[irq].level & (cm)) != 0)
-#define GIC_SET_TRIGGER(irq) s->irq_state[irq].trigger = 1
-#define GIC_CLEAR_TRIGGER(irq) s->irq_state[irq].trigger = 0
+#define GIC_SET_TRIGGER(irq) s->irq_state[irq].trigger = true
+#define GIC_CLEAR_TRIGGER(irq) s->irq_state[irq].trigger = false
 #define GIC_TEST_TRIGGER(irq) s->irq_state[irq].trigger
 #define GIC_GET_PRIORITY(irq, cpu) (((irq) < GIC_INTERNAL) ?            \
                                     s->priority1[irq][cpu] :            \
@@ -61,30 +61,30 @@
 
 typedef struct gic_irq_state {
     /* The enable bits are only banked for per-cpu interrupts.  */
-    unsigned enabled:NCPU;
-    unsigned pending:NCPU;
-    unsigned active:NCPU;
-    unsigned level:NCPU;
-    unsigned model:1; /* 0 = N:N, 1 = 1:N */
-    unsigned trigger:1; /* nonzero = edge triggered.  */
+    uint8_t enabled;
+    uint8_t pending;
+    uint8_t active;
+    uint8_t level;
+    bool model; /* 0 = N:N, 1 = 1:N */
+    bool trigger; /* nonzero = edge triggered.  */
 } gic_irq_state;
 
 typedef struct GICState {
     SysBusDevice busdev;
     qemu_irq parent_irq[NCPU];
-    int enabled;
-    int cpu_enabled[NCPU];
+    bool enabled;
+    bool cpu_enabled[NCPU];
 
     gic_irq_state irq_state[GIC_MAXIRQ];
-    int irq_target[GIC_MAXIRQ];
-    int priority1[GIC_INTERNAL][NCPU];
-    int priority2[GIC_MAXIRQ - GIC_INTERNAL];
-    int last_active[GIC_MAXIRQ][NCPU];
-
-    int priority_mask[NCPU];
-    int running_irq[NCPU];
-    int running_priority[NCPU];
-    int current_pending[NCPU];
+    uint8_t irq_target[GIC_MAXIRQ];
+    uint8_t priority1[GIC_INTERNAL][NCPU];
+    uint8_t priority2[GIC_MAXIRQ - GIC_INTERNAL];
+    uint16_t last_active[GIC_MAXIRQ][NCPU];
+
+    uint16_t priority_mask[NCPU];
+    uint16_t running_irq[NCPU];
+    uint16_t running_priority[NCPU];
+    uint16_t current_pending[NCPU];
 
     uint32_t num_cpu;
 
diff --git a/hw/grlib_irqmp.c b/hw/intc/grlib_irqmp.c
index 7ee469d191..68dfe6a4bb 100644
--- a/hw/grlib_irqmp.c
+++ b/hw/intc/grlib_irqmp.c
@@ -27,7 +27,7 @@
 #include "hw/sysbus.h"
 #include "cpu.h"
 
-#include "hw/grlib.h"
+#include "hw/sparc/grlib.h"
 
 #include "trace.h"
 
diff --git a/hw/heathrow_pic.c b/hw/intc/heathrow_pic.c
index beb9661182..beb9661182 100644
--- a/hw/heathrow_pic.c
+++ b/hw/intc/heathrow_pic.c
diff --git a/hw/i8259.c b/hw/intc/i8259.c
index 1d8275232a..ce14bd0f94 100644
--- a/hw/i8259.c
+++ b/hw/intc/i8259.c
@@ -22,11 +22,11 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 #include "monitor/monitor.h"
 #include "qemu/timer.h"
-#include "hw/i8259_internal.h"
+#include "hw/isa/i8259_internal.h"
 
 /* debug PIC */
 //#define DEBUG_PIC
diff --git a/hw/i8259_common.c b/hw/intc/i8259_common.c
index 98052db1fa..996ba9dfdb 100644
--- a/hw/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -22,8 +22,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "hw/pc.h"
-#include "hw/i8259_internal.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/i8259_internal.h"
 
 void pic_reset_common(PICCommonState *s)
 {
diff --git a/hw/imx_avic.c b/hw/intc/imx_avic.c
index 4e280b6ab9..4e280b6ab9 100644
--- a/hw/imx_avic.c
+++ b/hw/intc/imx_avic.c
diff --git a/hw/ioapic.c b/hw/intc/ioapic.c
index 78629fac6c..c6f09f4331 100644
--- a/hw/ioapic.c
+++ b/hw/intc/ioapic.c
@@ -21,10 +21,9 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/apic.h"
-#include "hw/ioapic.h"
-#include "hw/ioapic_internal.h"
+#include "hw/i386/pc.h"
+#include "hw/i386/ioapic.h"
+#include "hw/i386/ioapic_internal.h"
 
 //#define DEBUG_IOAPIC
 
diff --git a/hw/ioapic_common.c b/hw/intc/ioapic_common.c
index d4aff29544..42c7adc691 100644
--- a/hw/ioapic_common.c
+++ b/hw/intc/ioapic_common.c
@@ -19,8 +19,8 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hw/ioapic.h"
-#include "hw/ioapic_internal.h"
+#include "hw/i386/ioapic.h"
+#include "hw/i386/ioapic_internal.h"
 #include "hw/sysbus.h"
 
 void ioapic_reset_common(DeviceState *dev)
diff --git a/hw/lm32_pic.c b/hw/intc/lm32_pic.c
index d17c310d5c..b4e80c8d8c 100644
--- a/hw/lm32_pic.c
+++ b/hw/intc/lm32_pic.c
@@ -20,11 +20,11 @@
 #include <assert.h>
 
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
 #include "trace.h"
-#include "hw/lm32_pic.h"
+#include "hw/lm32/lm32_pic.h"
 
 struct LM32PicState {
     SysBusDevice busdev;
diff --git a/hw/omap_intc.c b/hw/intc/omap_intc.c
index 7da9c3548c..875eba4e3e 100644
--- a/hw/omap_intc.c
+++ b/hw/intc/omap_intc.c
@@ -18,7 +18,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 #include "hw/sysbus.h"
 
 /* Interrupt Handlers */
diff --git a/hw/openpic.c b/hw/intc/openpic.c
index 03a7075c39..c78871445b 100644
--- a/hw/openpic.c
+++ b/hw/intc/openpic.c
@@ -36,11 +36,11 @@
 #include "hw/hw.h"
 #include "hw/ppc/mac.h"
 #include "hw/pci/pci.h"
-#include "hw/openpic.h"
+#include "hw/ppc/openpic.h"
 #include "hw/sysbus.h"
 #include "hw/pci/msi.h"
 #include "qemu/bitops.h"
-#include "hw/ppc.h"
+#include "hw/ppc/ppc.h"
 
 //#define DEBUG_OPENPIC
 
diff --git a/hw/pl190.c b/hw/intc/pl190.c
index 9610673d94..9610673d94 100644
--- a/hw/pl190.c
+++ b/hw/intc/pl190.c
diff --git a/hw/puv3_intc.c b/hw/intc/puv3_intc.c
index 6bc9e1a752..0cd5e9eae0 100644
--- a/hw/puv3_intc.c
+++ b/hw/intc/puv3_intc.c
@@ -11,7 +11,7 @@
 #include "hw/sysbus.h"
 
 #undef DEBUG_PUV3
-#include "hw/puv3.h"
+#include "hw/unicore32/puv3.h"
 
 typedef struct {
     SysBusDevice busdev;
diff --git a/hw/realview_gic.c b/hw/intc/realview_gic.c
index 0ec30caa06..0ec30caa06 100644
--- a/hw/realview_gic.c
+++ b/hw/intc/realview_gic.c
diff --git a/hw/sbi.c b/hw/intc/sbi.c
index 8795749de8..8795749de8 100644
--- a/hw/sbi.c
+++ b/hw/intc/sbi.c
diff --git a/hw/sh_intc.c b/hw/intc/sh_intc.c
index 29e3d8f127..050bfb63ce 100644
--- a/hw/sh_intc.c
+++ b/hw/intc/sh_intc.c
@@ -8,9 +8,9 @@
  * This code is licensed under the GPL.
  */
 
-#include "hw/sh_intc.h"
+#include "hw/sh4/sh_intc.h"
 #include "hw/hw.h"
-#include "hw/sh.h"
+#include "hw/sh4/sh.h"
 
 //#define DEBUG_INTC
 //#define DEBUG_INTC_SOURCES
diff --git a/hw/slavio_intctl.c b/hw/intc/slavio_intctl.c
index b60592b35d..b367752fd3 100644
--- a/hw/slavio_intctl.c
+++ b/hw/intc/slavio_intctl.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/sun4m.h"
+#include "hw/sparc/sun4m.h"
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
 #include "trace.h"
diff --git a/hw/sun4c_intctl.c b/hw/intc/sun4c_intctl.c
index 9d443d1b10..1096375670 100644
--- a/hw/sun4c_intctl.c
+++ b/hw/intc/sun4c_intctl.c
@@ -23,7 +23,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/sun4m.h"
+#include "hw/sparc/sun4m.h"
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
 
diff --git a/hw/xilinx_intc.c b/hw/intc/xilinx_intc.c
index b106e724ab..b106e724ab 100644
--- a/hw/xilinx_intc.c
+++ b/hw/intc/xilinx_intc.c
diff --git a/hw/isa/Makefile.objs b/hw/isa/Makefile.objs
new file mode 100644
index 0000000000..193746a73e
--- /dev/null
+++ b/hw/isa/Makefile.objs
@@ -0,0 +1,9 @@
+common-obj-y += isa-bus.o
+common-obj-$(CONFIG_APM) += apm.o
+common-obj-$(CONFIG_I82378) += i82378.o
+common-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
+common-obj-$(CONFIG_PC87312) += pc87312.o
+common-obj-$(CONFIG_PIIX4) += piix4.o
+common-obj-$(CONFIG_VT82C686) += vt82c686.o
+
+obj-$(CONFIG_LPC_ICH9) += lpc_ich9.o
diff --git a/hw/apm.c b/hw/isa/apm.c
index e2846f99c8..5f21d21473 100644
--- a/hw/apm.c
+++ b/hw/isa/apm.c
@@ -20,7 +20,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
-#include "hw/apm.h"
+#include "hw/isa/apm.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 
diff --git a/hw/i82378.c b/hw/isa/i82378.c
index 6f8c48b9ae..cced9aff26 100644
--- a/hw/i82378.c
+++ b/hw/isa/i82378.c
@@ -18,9 +18,9 @@
  */
 
 #include "hw/pci/pci.h"
-#include "hw/pc.h"
-#include "hw/i8254.h"
-#include "hw/pcspk.h"
+#include "hw/i386/pc.h"
+#include "hw/timer/i8254.h"
+#include "hw/audio/pcspk.h"
 
 //#define DEBUG_I82378
 
diff --git a/hw/isa-bus.c b/hw/isa/isa-bus.c
index 67ff8fd314..7860b17d66 100644
--- a/hw/isa-bus.c
+++ b/hw/isa/isa-bus.c
@@ -20,7 +20,7 @@
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "exec/address-spaces.h"
 
 static ISABus *isabus;
diff --git a/hw/isa_mmio.c b/hw/isa/isa_mmio.c
index a7860e7459..d4dbf13831 100644
--- a/hw/isa_mmio.c
+++ b/hw/isa/isa_mmio.c
@@ -23,7 +23,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "exec/address-spaces.h"
 
 static void isa_mmio_writeb (void *opaque, hwaddr addr,
diff --git a/hw/lpc_ich9.c b/hw/isa/lpc_ich9.c
index ff0a3092d5..d116075933 100644
--- a/hw/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -30,18 +30,17 @@
 #include "qemu-common.h"
 #include "hw/hw.h"
 #include "qemu/range.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/sysbus.h"
-#include "hw/pc.h"
-#include "hw/apm.h"
-#include "hw/ioapic.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/apm.h"
+#include "hw/i386/ioapic.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci_bridge.h"
-#include "hw/ich9.h"
-#include "hw/acpi.h"
-#include "hw/acpi_ich9.h"
-#include "hw/pam.h"
+#include "hw/i386/ich9.h"
+#include "hw/acpi/acpi.h"
+#include "hw/acpi/ich9.h"
 #include "hw/pci/pci_bus.h"
 #include "exec/address-spaces.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/pc87312.c b/hw/isa/pc87312.c
index c4e4c6273b..9f5e185685 100644
--- a/hw/pc87312.c
+++ b/hw/isa/pc87312.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/pc87312.h"
+#include "hw/isa/pc87312.h"
 #include "qemu/error-report.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/piix4.c b/hw/isa/piix4.c
index 0f5cd014e5..d750413a7e 100644
--- a/hw/piix4.c
+++ b/hw/isa/piix4.c
@@ -23,9 +23,9 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/sysbus.h"
 
 PCIDevice *piix4_dev;
diff --git a/hw/vt82c686.c b/hw/isa/vt82c686.c
index 9d9b64eedd..52619276bd 100644
--- a/hw/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -11,17 +11,17 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/vt82c686.h"
-#include "hw/i2c.h"
-#include "hw/smbus.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/vt82c686.h"
+#include "hw/i2c/i2c.h"
+#include "hw/i2c/smbus.h"
 #include "hw/pci/pci.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/sysbus.h"
-#include "hw/mips.h"
-#include "hw/apm.h"
-#include "hw/acpi.h"
-#include "hw/pm_smbus.h"
+#include "hw/mips/mips.h"
+#include "hw/isa/apm.h"
+#include "hw/acpi/acpi.h"
+#include "hw/i2c/pm_smbus.h"
 #include "sysemu/sysemu.h"
 #include "qemu/timer.h"
 #include "exec/address-spaces.h"
diff --git a/hw/kvm/Makefile.objs b/hw/kvm/Makefile.objs
deleted file mode 100644
index f620d7ff85..0000000000
--- a/hw/kvm/Makefile.objs
+++ /dev/null
@@ -1 +0,0 @@
-obj-$(CONFIG_KVM) += clock.o apic.o i8259.o ioapic.o i8254.o pci-assign.o
diff --git a/hw/lm32/Makefile.objs b/hw/lm32/Makefile.objs
index 68ca90a3e2..ea6418ae59 100644
--- a/hw/lm32/Makefile.objs
+++ b/hw/lm32/Makefile.objs
@@ -1,23 +1,3 @@
-# LM32 peripherals
-obj-y += lm32_pic.o
-obj-y += lm32_juart.o
-obj-y += lm32_timer.o
-obj-y += lm32_uart.o
-obj-y += lm32_sys.o
-obj-y += milkymist-ac97.o
-obj-y += milkymist-hpdmc.o
-obj-y += milkymist-memcard.o
-obj-y += milkymist-minimac2.o
-obj-y += milkymist-pfpu.o
-obj-y += milkymist-softusb.o
-obj-y += milkymist-sysctl.o
-obj-$(CONFIG_GLX) += milkymist-tmu2.o
-obj-y += milkymist-uart.o
-obj-y += milkymist-vgafb.o
-obj-y += framebuffer.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 # LM32 boards
 obj-y += lm32_boards.o
 obj-y += milkymist.o
diff --git a/hw/lm32.h b/hw/lm32/lm32.h
index 236686ef2b..236686ef2b 100644
--- a/hw/lm32.h
+++ b/hw/lm32/lm32.h
diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index db92948092..6555a97e2e 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -19,14 +19,14 @@
 
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/flash.h"
-#include "hw/devices.h"
+#include "hw/block/flash.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "sysemu/blockdev.h"
 #include "elf.h"
-#include "hw/lm32_hwsetup.h"
-#include "hw/lm32.h"
+#include "lm32_hwsetup.h"
+#include "lm32.h"
 #include "exec/address-spaces.h"
 
 typedef struct {
diff --git a/hw/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h
index 3449bd8dfc..3449bd8dfc 100644
--- a/hw/lm32_hwsetup.h
+++ b/hw/lm32/lm32_hwsetup.h
diff --git a/hw/milkymist-hw.h b/hw/lm32/milkymist-hw.h
index 4e86c4e832..4e86c4e832 100644
--- a/hw/milkymist-hw.h
+++ b/hw/lm32/milkymist-hw.h
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index b347cf964c..d02ca0cc04 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -19,15 +19,15 @@
 
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/sysemu.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "elf.h"
 #include "sysemu/blockdev.h"
-#include "hw/milkymist-hw.h"
-#include "hw/lm32.h"
+#include "milkymist-hw.h"
+#include "lm32.h"
 #include "exec/address-spaces.h"
 
 #define BIOS_FILENAME    "mmone-bios.bin"
diff --git a/hw/m68k/Makefile.objs b/hw/m68k/Makefile.objs
index ede32a7c4e..c4352e783a 100644
--- a/hw/m68k/Makefile.objs
+++ b/hw/m68k/Makefile.objs
@@ -1,7 +1,3 @@
-obj-y = mcf_uart.o mcf_fec.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 obj-y += an5206.o mcf5208.o
 obj-y += dummy_m68k.o
 
diff --git a/hw/m68k/an5206.c b/hw/m68k/an5206.c
index 7c21c66cde..c4a5626a53 100644
--- a/hw/m68k/an5206.c
+++ b/hw/m68k/an5206.c
@@ -7,7 +7,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/mcf.h"
+#include "hw/m68k/mcf.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "elf.h"
diff --git a/hw/m68k/mcf5206.c b/hw/m68k/mcf5206.c
index 58cd8d46c9..bcc619d74b 100644
--- a/hw/m68k/mcf5206.c
+++ b/hw/m68k/mcf5206.c
@@ -6,7 +6,7 @@
  * This code is licensed under the GPL
  */
 #include "hw/hw.h"
-#include "hw/mcf.h"
+#include "hw/m68k/mcf.h"
 #include "qemu/timer.h"
 #include "hw/ptimer.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
index 748bf56983..05efde7ceb 100644
--- a/hw/m68k/mcf5208.c
+++ b/hw/m68k/mcf5208.c
@@ -6,7 +6,7 @@
  * This code is licensed under the GPL
  */
 #include "hw/hw.h"
-#include "hw/mcf.h"
+#include "hw/m68k/mcf.h"
 #include "qemu/timer.h"
 #include "hw/ptimer.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/m68k/mcf_intc.c b/hw/m68k/mcf_intc.c
index fff27b34aa..cfe660d0a4 100644
--- a/hw/m68k/mcf_intc.c
+++ b/hw/m68k/mcf_intc.c
@@ -6,7 +6,7 @@
  * This code is licensed under the GPL
  */
 #include "hw/hw.h"
-#include "hw/mcf.h"
+#include "hw/m68k/mcf.h"
 #include "exec/address-spaces.h"
 
 typedef struct {
diff --git a/hw/microblaze/Makefile.objs b/hw/microblaze/Makefile.objs
index 9e7f249941..c65e2aabf1 100644
--- a/hw/microblaze/Makefile.objs
+++ b/hw/microblaze/Makefile.objs
@@ -1,8 +1,3 @@
-obj-y += xilinx_spi.o
-obj-y += xilinx_ethlite.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 obj-y += petalogix_s3adsp1800_mmu.o
 obj-y += petalogix_ml605_mmu.o
 obj-y += boot.o
diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c
index e13b3e13bb..23cb11d70e 100644
--- a/hw/microblaze/boot.c
+++ b/hw/microblaze/boot.c
@@ -31,7 +31,7 @@
 #include "hw/loader.h"
 #include "elf.h"
 
-#include "hw/microblaze_boot.h"
+#include "boot.h"
 
 static struct
 {
diff --git a/hw/microblaze_boot.h b/hw/microblaze/boot.h
index b14ef2b992..b14ef2b992 100644
--- a/hw/microblaze_boot.h
+++ b/hw/microblaze/boot.h
diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c
index cfc02207ab..f61818b42b 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -28,18 +28,18 @@
 #include "hw/sysbus.h"
 #include "hw/hw.h"
 #include "net/net.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/sysemu.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
 #include "hw/xilinx.h"
 #include "sysemu/blockdev.h"
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "exec/address-spaces.h"
 #include "hw/ssi.h"
 
-#include "hw/microblaze_boot.h"
-#include "hw/microblaze_pic_cpu.h"
+#include "boot.h"
+#include "pic_cpu.h"
 
 #include "hw/stream.h"
 
@@ -158,8 +158,7 @@ petalogix_ml605_init(QEMUMachineInitArgs *args)
         for (i = 0; i < NUM_SPI_FLASHES; i++) {
             qemu_irq cs_line;
 
-            dev = ssi_create_slave_no_init(spi, "n25q128");
-            qdev_init_nofail(dev);
+            dev = ssi_create_slave(spi, "n25q128");
             cs_line = qdev_get_gpio_in(dev, 0);
             sysbus_connect_irq(busdev, i+1, cs_line);
         }
diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c
index 24983621e5..eedd60e38c 100644
--- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
+++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
@@ -26,16 +26,16 @@
 #include "hw/sysbus.h"
 #include "hw/hw.h"
 #include "net/net.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/sysemu.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
 #include "hw/xilinx.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
-#include "hw/microblaze_boot.h"
-#include "hw/microblaze_pic_cpu.h"
+#include "boot.h"
+#include "pic_cpu.h"
 
 #define LMB_BRAM_SIZE  (128 * 1024)
 #define FLASH_SIZE     (16 * 1024 * 1024)
diff --git a/hw/microblaze/pic_cpu.c b/hw/microblaze/pic_cpu.c
index 6248de92bb..16902f7880 100644
--- a/hw/microblaze/pic_cpu.c
+++ b/hw/microblaze/pic_cpu.c
@@ -23,7 +23,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/microblaze_pic_cpu.h"
+#include "pic_cpu.h"
 
 #define D(x)
 
diff --git a/hw/microblaze_pic_cpu.h b/hw/microblaze/pic_cpu.h
index 43090a48ef..43090a48ef 100644
--- a/hw/microblaze_pic_cpu.h
+++ b/hw/microblaze/pic_cpu.h
diff --git a/hw/mips/Makefile.objs b/hw/mips/Makefile.objs
index 1e3bca1c37..0a652f8521 100644
--- a/hw/mips/Makefile.objs
+++ b/hw/mips/Makefile.objs
@@ -1,8 +1,4 @@
-obj-y += gt64xxx.o mc146818rtc.o
-obj-$(CONFIG_FULONG) += bonito.o vt82c686.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 obj-y += mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
 obj-y += addr.o cputimer.o mips_int.o
 obj-$(CONFIG_FULONG) += mips_fulong2e.o
+obj-y += gt64xxx_pci.o
diff --git a/hw/mips/addr.c b/hw/mips/addr.c
index cddc25cf3f..99488f1d2a 100644
--- a/hw/mips/addr.c
+++ b/hw/mips/addr.c
@@ -21,7 +21,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/mips_cpudevs.h"
+#include "hw/mips/cpudevs.h"
 
 uint64_t cpu_mips_kseg0_to_phys(void *opaque, uint64_t addr)
 {
diff --git a/hw/mips/cputimer.c b/hw/mips/cputimer.c
index 9ad13f3924..e0266bf15a 100644
--- a/hw/mips/cputimer.c
+++ b/hw/mips/cputimer.c
@@ -21,7 +21,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/mips_cpudevs.h"
+#include "hw/mips/cpudevs.h"
 #include "qemu/timer.h"
 
 #define TIMER_FREQ	100 * 1000 * 1000
diff --git a/hw/gt64xxx.c b/hw/mips/gt64xxx_pci.c
index 37be9c2a56..189e865a65 100644
--- a/hw/gt64xxx.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -23,10 +23,10 @@
  */
 
 #include "hw/hw.h"
-#include "hw/mips.h"
+#include "hw/mips/mips.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "exec/address-spaces.h"
 
 //#define DEBUG
diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
index 766aa9dfb5..3cf27fa822 100644
--- a/hw/mips/mips_fulong2e.c
+++ b/hw/mips/mips_fulong2e.c
@@ -19,28 +19,28 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/serial.h"
-#include "hw/fdc.h"
+#include "hw/i386/pc.h"
+#include "hw/char/serial.h"
+#include "hw/block/fdc.h"
 #include "net/net.h"
 #include "hw/boards.h"
-#include "hw/smbus.h"
+#include "hw/i2c/smbus.h"
 #include "block/block.h"
-#include "hw/flash.h"
-#include "hw/mips.h"
-#include "hw/mips_cpudevs.h"
+#include "hw/block/flash.h"
+#include "hw/mips/mips.h"
+#include "hw/mips/cpudevs.h"
 #include "hw/pci/pci.h"
 #include "char/char.h"
 #include "sysemu/sysemu.h"
 #include "audio/audio.h"
 #include "qemu/log.h"
 #include "hw/loader.h"
-#include "hw/mips-bios.h"
+#include "hw/mips/bios.h"
 #include "hw/ide.h"
 #include "elf.h"
-#include "hw/vt82c686.h"
-#include "hw/mc146818rtc.h"
-#include "hw/i8254.h"
+#include "hw/isa/vt82c686.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/timer/i8254.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/mips/mips_int.c b/hw/mips/mips_int.c
index 0e5e86699c..7dbd24d3d6 100644
--- a/hw/mips/mips_int.c
+++ b/hw/mips/mips_int.c
@@ -21,7 +21,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/mips_cpudevs.h"
+#include "hw/mips/cpudevs.h"
 #include "cpu.h"
 
 static void cpu_mips_irq_request(void *opaque, int irq, int level)
diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c
index daeb985b1d..fd3a5f93f9 100644
--- a/hw/mips/mips_jazz.c
+++ b/hw/mips/mips_jazz.c
@@ -23,22 +23,22 @@
  */
 
 #include "hw/hw.h"
-#include "hw/mips.h"
-#include "hw/mips_cpudevs.h"
-#include "hw/pc.h"
-#include "hw/serial.h"
-#include "hw/isa.h"
-#include "hw/fdc.h"
+#include "hw/mips/mips.h"
+#include "hw/mips/cpudevs.h"
+#include "hw/i386/pc.h"
+#include "hw/char/serial.h"
+#include "hw/isa/isa.h"
+#include "hw/block/fdc.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/arch_init.h"
 #include "hw/boards.h"
 #include "net/net.h"
-#include "hw/esp.h"
-#include "hw/mips-bios.h"
+#include "hw/scsi/esp.h"
+#include "hw/mips/bios.h"
 #include "hw/loader.h"
-#include "hw/mc146818rtc.h"
-#include "hw/i8254.h"
-#include "hw/pcspk.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/timer/i8254.h"
+#include "hw/audio/pcspk.h"
 #include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 9a67dce207..a3e936b77f 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -23,28 +23,28 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/serial.h"
-#include "hw/fdc.h"
+#include "hw/i386/pc.h"
+#include "hw/char/serial.h"
+#include "hw/block/fdc.h"
 #include "net/net.h"
 #include "hw/boards.h"
-#include "hw/smbus.h"
+#include "hw/i2c/smbus.h"
 #include "block/block.h"
-#include "hw/flash.h"
-#include "hw/mips.h"
-#include "hw/mips_cpudevs.h"
+#include "hw/block/flash.h"
+#include "hw/mips/mips.h"
+#include "hw/mips/cpudevs.h"
 #include "hw/pci/pci.h"
 #include "char/char.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/arch_init.h"
 #include "hw/boards.h"
 #include "qemu/log.h"
-#include "hw/mips-bios.h"
+#include "hw/mips/bios.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "hw/mc146818rtc.h"
-#include "hw/i8254.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/timer/i8254.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "hw/sysbus.h"             /* SysBusDevice */
diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c
index 4935c78c01..d1681ec2fe 100644
--- a/hw/mips/mips_mipssim.c
+++ b/hw/mips/mips_mipssim.c
@@ -25,14 +25,14 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/mips.h"
-#include "hw/mips_cpudevs.h"
-#include "hw/serial.h"
-#include "hw/isa.h"
+#include "hw/mips/mips.h"
+#include "hw/mips/cpudevs.h"
+#include "hw/char/serial.h"
+#include "hw/isa/isa.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/mips-bios.h"
+#include "hw/mips/bios.h"
 #include "hw/loader.h"
 #include "elf.h"
 #include "hw/sysbus.h"
diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index 539a562620..4646ab6db7 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -8,22 +8,22 @@
  * the standard PC ISA addresses.
 */
 #include "hw/hw.h"
-#include "hw/mips.h"
-#include "hw/mips_cpudevs.h"
-#include "hw/pc.h"
-#include "hw/serial.h"
-#include "hw/isa.h"
+#include "hw/mips/mips.h"
+#include "hw/mips/cpudevs.h"
+#include "hw/i386/pc.h"
+#include "hw/char/serial.h"
+#include "hw/isa/isa.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "qemu/log.h"
-#include "hw/mips-bios.h"
+#include "hw/mips/bios.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "hw/mc146818rtc.h"
-#include "hw/i8254.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/timer/i8254.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
new file mode 100644
index 0000000000..03699c3365
--- /dev/null
+++ b/hw/misc/Makefile.objs
@@ -0,0 +1,40 @@
+common-obj-$(CONFIG_APPLESMC) += applesmc.o
+common-obj-$(CONFIG_MAX111X) += max111x.o
+common-obj-$(CONFIG_TMP105) += tmp105.o
+common-obj-$(CONFIG_ISA_DEBUG) += debugexit.o
+common-obj-$(CONFIG_SGA) += sga.o
+common-obj-$(CONFIG_ISA_TESTDEV) += pc-testdev.o
+
+obj-$(CONFIG_VMPORT) += vmport.o
+
+# ARM devices
+common-obj-$(CONFIG_PL310) += arm_l2x0.o
+
+# PKUnity SoC devices
+common-obj-$(CONFIG_PUV3) += puv3_pm.o
+
+common-obj-$(CONFIG_MACIO) += macio/
+
+ifeq ($(CONFIG_PCI), y)
+obj-$(CONFIG_KVM) += ivshmem.o
+obj-$(CONFIG_LINUX) += vfio.o
+endif
+
+obj-$(CONFIG_REALVIEW) += arm_sysctl.o
+obj-$(CONFIG_A9SCU) += a9scu.o
+obj-$(CONFIG_NSERIES) += cbus.o
+obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
+obj-$(CONFIG_EXYNOS4) += exynos4210_pmu.o
+obj-$(CONFIG_IMX) += imx_ccm.o
+obj-$(CONFIG_LM32) += lm32_sys.o
+obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o
+obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o
+obj-$(CONFIG_MAINSTONE) += mst_fpga.o
+obj-$(CONFIG_OMAP) += omap_clk.o
+obj-$(CONFIG_OMAP) += omap_gpmc.o
+obj-$(CONFIG_OMAP) += omap_l4.o
+obj-$(CONFIG_OMAP) += omap_sdrc.o
+obj-$(CONFIG_OMAP) += omap_tap.o
+obj-$(CONFIG_PXA2XX) += pxa2xx_pcmcia.o
+obj-$(CONFIG_SLAVIO) += slavio_misc.o
+obj-$(CONFIG_ZYNQ) += zynq_slcr.o
diff --git a/hw/a9scu.c b/hw/misc/a9scu.c
index 05897c2fa2..05897c2fa2 100644
--- a/hw/a9scu.c
+++ b/hw/misc/a9scu.c
diff --git a/hw/applesmc.c b/hw/misc/applesmc.c
index 44b9bacd88..c29558bdd5 100644
--- a/hw/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -31,7 +31,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "ui/console.h"
 #include "qemu/timer.h"
 
diff --git a/hw/arm_l2x0.c b/hw/misc/arm_l2x0.c
index eb4427d9c4..eb4427d9c4 100644
--- a/hw/arm_l2x0.c
+++ b/hw/misc/arm_l2x0.c
diff --git a/hw/arm_sysctl.c b/hw/misc/arm_sysctl.c
index 25fc6eac94..c8b55a8349 100644
--- a/hw/arm_sysctl.c
+++ b/hw/misc/arm_sysctl.c
@@ -11,7 +11,7 @@
 #include "qemu/timer.h"
 #include "qemu/bitops.h"
 #include "hw/sysbus.h"
-#include "hw/primecell.h"
+#include "hw/arm/primecell.h"
 #include "sysemu/sysemu.h"
 
 #define LOCK_VALUE 0xa05f
diff --git a/hw/cbus.c b/hw/misc/cbus.c
index 29b467b61f..3d9027f692 100644
--- a/hw/cbus.c
+++ b/hw/misc/cbus.c
@@ -22,7 +22,7 @@
 
 #include "qemu-common.h"
 #include "hw/irq.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "sysemu/sysemu.h"
 
 //#define DEBUG
diff --git a/hw/debugexit.c b/hw/misc/debugexit.c
index ba67a8fb41..59bed5bff5 100644
--- a/hw/debugexit.c
+++ b/hw/misc/debugexit.c
@@ -8,7 +8,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 #define TYPE_ISA_DEBUG_EXIT_DEVICE "isa-debug-exit"
 #define ISA_DEBUG_EXIT_DEVICE(obj) \
diff --git a/hw/eccmemctl.c b/hw/misc/eccmemctl.c
index 6f4a407cbf..6f4a407cbf 100644
--- a/hw/eccmemctl.c
+++ b/hw/misc/eccmemctl.c
diff --git a/hw/exynos4210_pmu.c b/hw/misc/exynos4210_pmu.c
index ba5aa8d0e4..ba5aa8d0e4 100644
--- a/hw/exynos4210_pmu.c
+++ b/hw/misc/exynos4210_pmu.c
diff --git a/hw/imx_ccm.c b/hw/misc/imx_ccm.c
index ad7aad3397..c153a24310 100644
--- a/hw/imx_ccm.c
+++ b/hw/misc/imx_ccm.c
@@ -13,7 +13,7 @@
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
-#include "hw/imx.h"
+#include "hw/arm/imx.h"
 
 #define CKIH_FREQ 26000000 /* 26MHz crystal input */
 #define CKIL_FREQ    32768 /* nominal 32khz clock */
diff --git a/hw/ivshmem.c b/hw/misc/ivshmem.c
index af2789e9ac..f92ce19dde 100644
--- a/hw/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -17,7 +17,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/msix.h"
 #include "sysemu/kvm.h"
diff --git a/hw/lm32_sys.c b/hw/misc/lm32_sys.c
index 33a3b80ce7..33a3b80ce7 100644
--- a/hw/lm32_sys.c
+++ b/hw/misc/lm32_sys.c
diff --git a/hw/misc/macio/Makefile.objs b/hw/misc/macio/Makefile.objs
new file mode 100644
index 0000000000..ef7ac249ec
--- /dev/null
+++ b/hw/misc/macio/Makefile.objs
@@ -0,0 +1,3 @@
+common-obj-y += macio.o
+common-obj-$(CONFIG_CUDA) += cuda.o
+common-obj-$(CONFIG_MAC_DBDMA) += mac_dbdma.o
diff --git a/hw/cuda.c b/hw/misc/macio/cuda.c
index 2ae430d326..f797796a36 100644
--- a/hw/cuda.c
+++ b/hw/misc/macio/cuda.c
@@ -24,7 +24,7 @@
  */
 #include "hw/hw.h"
 #include "hw/ppc/mac.h"
-#include "hw/adb.h"
+#include "hw/input/adb.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 
diff --git a/hw/mac_dbdma.c b/hw/misc/macio/mac_dbdma.c
index 61d2f35c8e..a2363bbdf2 100644
--- a/hw/mac_dbdma.c
+++ b/hw/misc/macio/mac_dbdma.c
@@ -37,8 +37,8 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/isa.h"
-#include "hw/mac_dbdma.h"
+#include "hw/isa/isa.h"
+#include "hw/ppc/mac_dbdma.h"
 #include "qemu/main-loop.h"
 
 /* debug DBDMA */
diff --git a/hw/macio.c b/hw/misc/macio/macio.c
index e91143e331..2f389dd7cc 100644
--- a/hw/macio.c
+++ b/hw/misc/macio/macio.c
@@ -25,8 +25,8 @@
 #include "hw/hw.h"
 #include "hw/ppc/mac.h"
 #include "hw/pci/pci.h"
-#include "hw/mac_dbdma.h"
-#include "hw/escc.h"
+#include "hw/ppc/mac_dbdma.h"
+#include "hw/char/escc.h"
 
 #define TYPE_MACIO "macio"
 #define MACIO(obj) OBJECT_CHECK(MacIOState, (obj), TYPE_MACIO)
diff --git a/hw/max111x.c b/hw/misc/max111x.c
index d477ecdb29..d477ecdb29 100644
--- a/hw/max111x.c
+++ b/hw/misc/max111x.c
diff --git a/hw/milkymist-hpdmc.c b/hw/misc/milkymist-hpdmc.c
index d922f6ffad..d922f6ffad 100644
--- a/hw/milkymist-hpdmc.c
+++ b/hw/misc/milkymist-hpdmc.c
diff --git a/hw/milkymist-pfpu.c b/hw/misc/milkymist-pfpu.c
index ad44b4db22..ad44b4db22 100644
--- a/hw/milkymist-pfpu.c
+++ b/hw/misc/milkymist-pfpu.c
diff --git a/hw/mst_fpga.c b/hw/misc/mst_fpga.c
index 1dd15054d0..1dd15054d0 100644
--- a/hw/mst_fpga.c
+++ b/hw/misc/mst_fpga.c
diff --git a/hw/omap_clk.c b/hw/misc/omap_clk.c
index c7b5c11626..80a3c50e1e 100644
--- a/hw/omap_clk.c
+++ b/hw/misc/omap_clk.c
@@ -19,7 +19,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 
 struct clk {
     const char *name;
diff --git a/hw/omap_gpmc.c b/hw/misc/omap_gpmc.c
index ebb259c283..91adb66c2b 100644
--- a/hw/omap_gpmc.c
+++ b/hw/misc/omap_gpmc.c
@@ -19,8 +19,8 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/flash.h"
-#include "hw/omap.h"
+#include "hw/block/flash.h"
+#include "hw/arm/omap.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/omap_l4.c b/hw/misc/omap_l4.c
index cbe8a06033..ac8251f736 100644
--- a/hw/omap_l4.c
+++ b/hw/misc/omap_l4.c
@@ -18,7 +18,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 
 struct omap_l4_s {
     MemoryRegion *address_space;
diff --git a/hw/omap_sdrc.c b/hw/misc/omap_sdrc.c
index 510e6cc580..e38b571054 100644
--- a/hw/omap_sdrc.c
+++ b/hw/misc/omap_sdrc.c
@@ -18,7 +18,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 
 /* SDRAM Controller Subsystem */
 struct omap_sdrc_s {
diff --git a/hw/omap_tap.c b/hw/misc/omap_tap.c
index 181ecee1a5..99b70d5a75 100644
--- a/hw/omap_tap.c
+++ b/hw/misc/omap_tap.c
@@ -19,7 +19,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 
 /* TEST-Chip-level TAP */
 static uint64_t omap_tap_read(void *opaque, hwaddr addr,
diff --git a/hw/pc-testdev.c b/hw/misc/pc-testdev.c
index 8236bce0c7..32df175c10 100644
--- a/hw/pc-testdev.c
+++ b/hw/misc/pc-testdev.c
@@ -41,7 +41,7 @@
 #endif
 #include "hw/hw.h"
 #include "hw/qdev.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 #define IOMEM_LEN    0x10000
 
diff --git a/hw/puv3_pm.c b/hw/misc/puv3_pm.c
index 6b8d94dd07..0aacdc2fce 100644
--- a/hw/puv3_pm.c
+++ b/hw/misc/puv3_pm.c
@@ -12,7 +12,7 @@
 #include "hw/sysbus.h"
 
 #undef DEBUG_PUV3
-#include "hw/puv3.h"
+#include "hw/unicore32/puv3.h"
 
 typedef struct {
     SysBusDevice busdev;
diff --git a/hw/pxa2xx_pcmcia.c b/hw/misc/pxa2xx_pcmcia.c
index 66fefba58c..323d458491 100644
--- a/hw/pxa2xx_pcmcia.c
+++ b/hw/misc/pxa2xx_pcmcia.c
@@ -12,7 +12,7 @@
 
 #include "hw/hw.h"
 #include "hw/pcmcia.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 
 
 struct PXA2xxPCMCIAState {
diff --git a/hw/sga.c b/hw/misc/sga.c
index 4b1d4e5369..5cf4b86c4f 100644
--- a/hw/sga.c
+++ b/hw/misc/sga.c
@@ -25,7 +25,7 @@
  *
  */
 #include "hw/pci/pci.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/loader.h"
 #include "sysemu/sysemu.h"
 
diff --git a/hw/slavio_misc.c b/hw/misc/slavio_misc.c
index a7a9368864..a7a9368864 100644
--- a/hw/slavio_misc.c
+++ b/hw/misc/slavio_misc.c
diff --git a/hw/tmp105.c b/hw/misc/tmp105.c
index 47e5437e0d..155e03df80 100644
--- a/hw/tmp105.c
+++ b/hw/misc/tmp105.c
@@ -19,8 +19,8 @@
  */
 
 #include "hw/hw.h"
-#include "hw/i2c.h"
-#include "hw/tmp105.h"
+#include "hw/i2c/i2c.h"
+#include "tmp105.h"
 #include "qapi/visitor.h"
 
 static void tmp105_interrupt_update(TMP105State *s)
diff --git a/hw/tmp105.h b/hw/misc/tmp105.h
index 9a9632c54b..9ba05ecc9c 100644
--- a/hw/tmp105.h
+++ b/hw/misc/tmp105.h
@@ -14,8 +14,8 @@
 #ifndef QEMU_TMP105_H
 #define QEMU_TMP105_H
 
-#include "hw/i2c.h"
-#include "hw/tmp105_regs.h"
+#include "hw/i2c/i2c.h"
+#include "hw/misc/tmp105_regs.h"
 
 #define TYPE_TMP105 "tmp105"
 #define TMP105(obj) OBJECT_CHECK(TMP105State, (obj), TYPE_TMP105)
diff --git a/hw/vfio_pci.c b/hw/misc/vfio.c
index 693a9ffdda..693a9ffdda 100644
--- a/hw/vfio_pci.c
+++ b/hw/misc/vfio.c
diff --git a/hw/vmport.c b/hw/misc/vmport.c
index cc1466ae96..0d07ea1fc5 100644
--- a/hw/vmport.c
+++ b/hw/misc/vmport.c
@@ -22,8 +22,8 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/isa.h"
-#include "hw/pc.h"
+#include "hw/isa/isa.h"
+#include "hw/i386/pc.h"
 #include "sysemu/kvm.h"
 #include "hw/qdev.h"
 
diff --git a/hw/zynq_slcr.c b/hw/misc/zynq_slcr.c
index 8418327261..8418327261 100644
--- a/hw/zynq_slcr.c
+++ b/hw/misc/zynq_slcr.c
diff --git a/hw/moxie/Makefile.objs b/hw/moxie/Makefile.objs
index a5f1742936..bfc90012fd 100644
--- a/hw/moxie/Makefile.objs
+++ b/hw/moxie/Makefile.objs
@@ -1,5 +1,2 @@
 # moxie boards
-obj-y = serial.o mc146818rtc.o vga.o
-
-obj-y := $(addprefix ../,$(obj-y))
 obj-y += moxiesim.o
diff --git a/hw/moxie/moxiesim.c b/hw/moxie/moxiesim.c
index e1e88a9c30..70bf28f2fd 100644
--- a/hw/moxie/moxiesim.c
+++ b/hw/moxie/moxiesim.c
@@ -26,13 +26,13 @@
  */
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "exec/address-spaces.h"
 
 #define PHYS_MEM_BASE 0x80000000
diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
new file mode 100644
index 0000000000..951cca3a4b
--- /dev/null
+++ b/hw/net/Makefile.objs
@@ -0,0 +1,33 @@
+common-obj-$(CONFIG_DP8393X) += dp8393x.o
+common-obj-$(CONFIG_XEN_BACKEND) += xen_nic.o
+
+# PCI network cards
+common-obj-$(CONFIG_NE2000_PCI) += ne2000.o
+common-obj-$(CONFIG_EEPRO100_PCI) += eepro100.o
+common-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o
+common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
+common-obj-$(CONFIG_E1000_PCI) += e1000.o
+common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
+common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o
+common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o
+
+common-obj-$(CONFIG_SMC91C111) += smc91c111.o
+common-obj-$(CONFIG_LAN9118) += lan9118.o
+common-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o
+common-obj-$(CONFIG_OPENCORES_ETH) += opencores_eth.o
+common-obj-$(CONFIG_XGMAC) += xgmac.o
+common-obj-$(CONFIG_MIPSNET) += mipsnet.o
+common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o
+
+common-obj-$(CONFIG_CADENCE) += cadence_gem.o
+common-obj-$(CONFIG_STELLARIS_ENET) += stellaris_enet.o
+common-obj-$(CONFIG_LANCE) += lance.o
+
+obj-$(CONFIG_ETRAXFS) += etraxfs_eth.o
+obj-$(CONFIG_COLDFIRE) += mcf_fec.o
+obj-$(CONFIG_MILKYMIST) += milkymist-minimac2.o
+obj-$(CONFIG_PSERIES) += spapr_llan.o
+obj-$(CONFIG_XILINX_ETHLITE) += xilinx_ethlite.o
+
+obj-$(CONFIG_VIRTIO) += virtio-net.o
+obj-y += vhost_net.o
diff --git a/hw/cadence_gem.c b/hw/net/cadence_gem.c
index e177057e49..e177057e49 100644
--- a/hw/cadence_gem.c
+++ b/hw/net/cadence_gem.c
diff --git a/hw/dp8393x.c b/hw/net/dp8393x.c
index 8b5ca6a4ec..2289f089ad 100644
--- a/hw/dp8393x.c
+++ b/hw/net/dp8393x.c
@@ -20,7 +20,7 @@
 #include "hw/hw.h"
 #include "qemu/timer.h"
 #include "net/net.h"
-#include "hw/mips.h"
+#include "hw/mips/mips.h"
 
 //#define DEBUG_SONIC
 
diff --git a/hw/e1000.c b/hw/net/e1000.c
index 3f18041b47..e6f46f0c51 100644
--- a/hw/e1000.c
+++ b/hw/net/e1000.c
@@ -33,7 +33,7 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
 
-#include "hw/e1000_hw.h"
+#include "e1000_regs.h"
 
 #define E1000_DEBUG
 
diff --git a/hw/e1000_hw.h b/hw/net/e1000_regs.h
index c9cb79e64d..c9cb79e64d 100644
--- a/hw/e1000_hw.h
+++ b/hw/net/e1000_regs.h
diff --git a/hw/eepro100.c b/hw/net/eepro100.c
index 68d729c17a..dc99ea6ea0 100644
--- a/hw/eepro100.c
+++ b/hw/net/eepro100.c
@@ -44,7 +44,7 @@
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
-#include "hw/eeprom93xx.h"
+#include "hw/nvram/eeprom93xx.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
 
diff --git a/hw/etraxfs_eth.c b/hw/net/etraxfs_eth.c
index 591bee245c..1039913e0f 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/net/etraxfs_eth.c
@@ -25,7 +25,7 @@
 #include <stdio.h>
 #include "hw/sysbus.h"
 #include "net/net.h"
-#include "hw/etraxfs.h"
+#include "hw/cris/etraxfs.h"
 
 #define D(x)
 
diff --git a/hw/lan9118.c b/hw/net/lan9118.c
index 403fb868ae..04cf267f13 100644
--- a/hw/lan9118.c
+++ b/hw/net/lan9118.c
@@ -12,7 +12,7 @@
 
 #include "hw/sysbus.h"
 #include "net/net.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "sysemu/sysemu.h"
 #include "hw/ptimer.h"
 /* For crc32 */
diff --git a/hw/lance.c b/hw/net/lance.c
index acfffaed31..187497c0ce 100644
--- a/hw/lance.c
+++ b/hw/net/lance.c
@@ -39,8 +39,8 @@
 #include "net/net.h"
 #include "qemu/timer.h"
 #include "qemu/sockets.h"
-#include "hw/sun4m.h"
-#include "hw/pcnet.h"
+#include "hw/sparc/sun4m.h"
+#include "pcnet.h"
 #include "trace.h"
 
 typedef struct {
diff --git a/hw/mcf_fec.c b/hw/net/mcf_fec.c
index 0227bd852c..9b6805267d 100644
--- a/hw/mcf_fec.c
+++ b/hw/net/mcf_fec.c
@@ -7,7 +7,7 @@
  */
 #include "hw/hw.h"
 #include "net/net.h"
-#include "hw/mcf.h"
+#include "hw/m68k/mcf.h"
 /* For crc32 */
 #include <zlib.h>
 #include "exec/address-spaces.h"
diff --git a/hw/milkymist-minimac2.c b/hw/net/milkymist-minimac2.c
index 29618e8efa..29618e8efa 100644
--- a/hw/milkymist-minimac2.c
+++ b/hw/net/milkymist-minimac2.c
diff --git a/hw/mipsnet.c b/hw/net/mipsnet.c
index ac6193a89e..ac6193a89e 100644
--- a/hw/mipsnet.c
+++ b/hw/net/mipsnet.c
diff --git a/hw/ne2000-isa.c b/hw/net/ne2000-isa.c
index 47c00c3a76..a093aa8bea 100644
--- a/hw/ne2000-isa.c
+++ b/hw/net/ne2000-isa.c
@@ -22,11 +22,11 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 #include "hw/qdev.h"
 #include "net/net.h"
-#include "hw/ne2000.h"
+#include "ne2000.h"
 #include "exec/address-spaces.h"
 
 typedef struct ISANE2000State {
diff --git a/hw/ne2000.c b/hw/net/ne2000.c
index 7f458311c6..33ee03e68e 100644
--- a/hw/ne2000.c
+++ b/hw/net/ne2000.c
@@ -24,7 +24,7 @@
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
-#include "hw/ne2000.h"
+#include "ne2000.h"
 #include "hw/loader.h"
 #include "sysemu/sysemu.h"
 
diff --git a/hw/ne2000.h b/hw/net/ne2000.h
index b31ae030f9..b31ae030f9 100644
--- a/hw/ne2000.h
+++ b/hw/net/ne2000.h
diff --git a/hw/opencores_eth.c b/hw/net/opencores_eth.c
index be64bf2a68..be64bf2a68 100644
--- a/hw/opencores_eth.c
+++ b/hw/net/opencores_eth.c
diff --git a/hw/pcnet-pci.c b/hw/net/pcnet-pci.c
index 61af57ed51..9df2b87543 100644
--- a/hw/pcnet-pci.c
+++ b/hw/net/pcnet-pci.c
@@ -33,7 +33,7 @@
 #include "qemu/timer.h"
 #include "sysemu/dma.h"
 
-#include "hw/pcnet.h"
+#include "pcnet.h"
 
 //#define PCNET_DEBUG
 //#define PCNET_DEBUG_IO
diff --git a/hw/pcnet.c b/hw/net/pcnet.c
index b0b462b02e..b606d2be3b 100644
--- a/hw/pcnet.c
+++ b/hw/net/pcnet.c
@@ -41,7 +41,7 @@
 #include "qemu/sockets.h"
 #include "sysemu/sysemu.h"
 
-#include "hw/pcnet.h"
+#include "pcnet.h"
 
 //#define PCNET_DEBUG
 //#define PCNET_DEBUG_IO
diff --git a/hw/pcnet.h b/hw/net/pcnet.h
index 9dee6f3e2c..9dee6f3e2c 100644
--- a/hw/pcnet.h
+++ b/hw/net/pcnet.h
diff --git a/hw/rtl8139.c b/hw/net/rtl8139.c
index 9369507422..9369507422 100644
--- a/hw/rtl8139.c
+++ b/hw/net/rtl8139.c
diff --git a/hw/smc91c111.c b/hw/net/smc91c111.c
index c2feae6eb8..f659256d6e 100644
--- a/hw/smc91c111.c
+++ b/hw/net/smc91c111.c
@@ -9,7 +9,7 @@
 
 #include "hw/sysbus.h"
 #include "net/net.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 /* For crc32 */
 #include <zlib.h>
 
diff --git a/hw/spapr_llan.c b/hw/net/spapr_llan.c
index 19701e7e40..34332f2452 100644
--- a/hw/spapr_llan.c
+++ b/hw/net/spapr_llan.c
@@ -27,8 +27,8 @@
 #include "hw/hw.h"
 #include "net/net.h"
 #include "hw/qdev.h"
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
 
 #include <libfdt.h>
 
diff --git a/hw/stellaris_enet.c b/hw/net/stellaris_enet.c
index 59b84564a0..59b84564a0 100644
--- a/hw/stellaris_enet.c
+++ b/hw/net/stellaris_enet.c
diff --git a/hw/vhost_net.c b/hw/net/vhost_net.c
index d3218a07f4..8c5384cf76 100644
--- a/hw/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -16,8 +16,8 @@
 #include "net/net.h"
 #include "net/tap.h"
 
-#include "hw/virtio-net.h"
-#include "hw/vhost_net.h"
+#include "hw/virtio/virtio-net.h"
+#include "net/vhost_net.h"
 #include "qemu/error-report.h"
 
 #include "config.h"
@@ -36,7 +36,7 @@
 
 #include <stdio.h>
 
-#include "hw/vhost.h"
+#include "hw/virtio/vhost.h"
 
 struct vhost_net {
     struct vhost_dev dev;
diff --git a/hw/virtio-net.c b/hw/net/virtio-net.c
index 5917740d9d..bc8fd43b4b 100644
--- a/hw/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -12,14 +12,14 @@
  */
 
 #include "qemu/iov.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "net/net.h"
 #include "net/checksum.h"
 #include "net/tap.h"
 #include "qemu/error-report.h"
 #include "qemu/timer.h"
-#include "hw/virtio-net.h"
-#include "hw/vhost_net.h"
+#include "hw/virtio/virtio-net.h"
+#include "net/vhost_net.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
diff --git a/hw/vmware_utils.h b/hw/net/vmware_utils.h
index 5307e2ccc9..5307e2ccc9 100644
--- a/hw/vmware_utils.h
+++ b/hw/net/vmware_utils.h
diff --git a/hw/vmxnet3.c b/hw/net/vmxnet3.c
index bdd256e9d5..5f483e7f1e 100644
--- a/hw/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -15,17 +15,16 @@
  *
  */
 
-#include "hw.h"
-#include "pci/pci.h"
+#include "hw/hw.h"
+#include "hw/pci/pci.h"
 #include "net/net.h"
-#include "virtio-net.h"
 #include "net/tap.h"
 #include "net/checksum.h"
 #include "sysemu/sysemu.h"
 #include "qemu-common.h"
 #include "qemu/bswap.h"
-#include "pci/msix.h"
-#include "pci/msi.h"
+#include "hw/pci/msix.h"
+#include "hw/pci/msi.h"
 
 #include "vmxnet3.h"
 #include "vmxnet_debug.h"
@@ -1033,6 +1032,7 @@ vmxnet3_indicate_packet(VMXNET3State *s)
         is_head = false;
         ready_rxcd_pa = new_rxcd_pa;
         new_rxcd_pa = 0;
+        num_frags++;
     }
 
     if (0 != ready_rxcd_pa) {
@@ -1324,6 +1324,10 @@ static void vmxnet3_activate_device(VMXNET3State *s)
     s->max_rx_frags =
         VMXNET3_READ_DRV_SHARED16(s->drv_shmem, devRead.misc.maxNumRxSG);
 
+    if (s->max_rx_frags == 0) {
+        s->max_rx_frags = 1;
+    }
+
     VMW_CFPRN("Max RX fragments is %u", s->max_rx_frags);
 
     s->event_int_idx =
@@ -1524,6 +1528,12 @@ static uint64_t vmxnet3_get_command_status(VMXNET3State *s)
         VMW_CFPRN("Device active: %" PRIx64, ret);
         break;
 
+    case VMXNET3_CMD_RESET_DEV:
+    case VMXNET3_CMD_QUIESCE_DEV:
+    case VMXNET3_CMD_GET_QUEUE_STATUS:
+        ret = 0;
+        break;
+
     case VMXNET3_CMD_GET_LINK:
         ret = s->link_status_and_speed;
         VMW_CFPRN("Link and speed: %" PRIx64, ret);
diff --git a/hw/vmxnet3.h b/hw/net/vmxnet3.h
index 7db0c8f5e0..4eae7c76be 100644
--- a/hw/vmxnet3.h
+++ b/hw/net/vmxnet3.h
@@ -37,10 +37,8 @@
 #define __packed QEMU_PACKED
 
 #if defined(HOST_WORDS_BIGENDIAN)
-#define const_cpu_to_le64(x) bswap_64(x)
 #define __BIG_ENDIAN_BITFIELD
 #else
-#define const_cpu_to_le64(x) (x)
 #endif
 
 /*
@@ -137,10 +135,10 @@ struct UPT1_RSSConf {
 
 /* features */
 enum {
-    UPT1_F_RXCSUM        = const_cpu_to_le64(0x0001), /* rx csum verification */
-    UPT1_F_RSS        = const_cpu_to_le64(0x0002),
-    UPT1_F_RXVLAN        = const_cpu_to_le64(0x0004), /* VLAN tag stripping */
-    UPT1_F_LRO        = const_cpu_to_le64(0x0008),
+    UPT1_F_RXCSUM        = 0x0001, /* rx csum verification */
+    UPT1_F_RSS           = 0x0002,
+    UPT1_F_RXVLAN        = 0x0004, /* VLAN tag stripping */
+    UPT1_F_LRO           = 0x0008,
 };
 
 /* all registers are 32 bit wide */
@@ -752,7 +750,6 @@ struct Vmxnet3_DriverShared {
 #undef __le32
 #undef __le64
 #undef __packed
-#undef const_cpu_to_le64
 #if defined(HOST_WORDS_BIGENDIAN)
 #undef __BIG_ENDIAN_BITFIELD
 #endif
diff --git a/hw/vmxnet_debug.h b/hw/net/vmxnet_debug.h
index 96dae0f916..96dae0f916 100644
--- a/hw/vmxnet_debug.h
+++ b/hw/net/vmxnet_debug.h
diff --git a/hw/vmxnet_rx_pkt.c b/hw/net/vmxnet_rx_pkt.c
index a40e346293..a40e346293 100644
--- a/hw/vmxnet_rx_pkt.c
+++ b/hw/net/vmxnet_rx_pkt.c
diff --git a/hw/vmxnet_rx_pkt.h b/hw/net/vmxnet_rx_pkt.h
index 6b2c60ef10..6b2c60ef10 100644
--- a/hw/vmxnet_rx_pkt.h
+++ b/hw/net/vmxnet_rx_pkt.h
diff --git a/hw/vmxnet_tx_pkt.c b/hw/net/vmxnet_tx_pkt.c
index b1e795b3b2..b1e795b3b2 100644
--- a/hw/vmxnet_tx_pkt.c
+++ b/hw/net/vmxnet_tx_pkt.c
diff --git a/hw/vmxnet_tx_pkt.h b/hw/net/vmxnet_tx_pkt.h
index 57121a6fe5..57121a6fe5 100644
--- a/hw/vmxnet_tx_pkt.h
+++ b/hw/net/vmxnet_tx_pkt.h
diff --git a/hw/xen_nic.c b/hw/net/xen_nic.c
index b6d36793b3..63918ae1a0 100644
--- a/hw/xen_nic.c
+++ b/hw/net/xen_nic.c
@@ -39,7 +39,7 @@
 #include "net/net.h"
 #include "net/checksum.h"
 #include "net/util.h"
-#include "hw/xen_backend.h"
+#include "hw/xen/xen_backend.h"
 
 #include <xen/io/netif.h>
 
diff --git a/hw/xgmac.c b/hw/net/xgmac.c
index 5275f4810d..5275f4810d 100644
--- a/hw/xgmac.c
+++ b/hw/net/xgmac.c
diff --git a/hw/xilinx_axienet.c b/hw/net/xilinx_axienet.c
index 07c4badd98..07c4badd98 100644
--- a/hw/xilinx_axienet.c
+++ b/hw/net/xilinx_axienet.c
diff --git a/hw/xilinx_ethlite.c b/hw/net/xilinx_ethlite.c
index b2e35237f8..b2e35237f8 100644
--- a/hw/xilinx_ethlite.c
+++ b/hw/net/xilinx_ethlite.c
diff --git a/hw/nvram/Makefile.objs b/hw/nvram/Makefile.objs
new file mode 100644
index 0000000000..e9a66940e0
--- /dev/null
+++ b/hw/nvram/Makefile.objs
@@ -0,0 +1,5 @@
+common-obj-$(CONFIG_DS1225Y) += ds1225y.o
+common-obj-y += eeprom93xx.o
+common-obj-y += fw_cfg.o
+common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o
+obj-$(CONFIG_PSERIES) += spapr_nvram.o
diff --git a/hw/ds1225y.c b/hw/nvram/ds1225y.c
index 488f1d7241..488f1d7241 100644
--- a/hw/ds1225y.c
+++ b/hw/nvram/ds1225y.c
diff --git a/hw/eeprom93xx.c b/hw/nvram/eeprom93xx.c
index 39f560553d..08f4df586c 100644
--- a/hw/eeprom93xx.c
+++ b/hw/nvram/eeprom93xx.c
@@ -36,7 +36,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/eeprom93xx.h"
+#include "hw/nvram/eeprom93xx.h"
 
 /* Debug EEPROM emulation. */
 //~ #define DEBUG_EEPROM
diff --git a/hw/fw_cfg.c b/hw/nvram/fw_cfg.c
index 63a199876c..97bba874e3 100644
--- a/hw/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -23,8 +23,8 @@
  */
 #include "hw/hw.h"
 #include "sysemu/sysemu.h"
-#include "hw/isa.h"
-#include "hw/fw_cfg.h"
+#include "hw/isa/isa.h"
+#include "hw/nvram/fw_cfg.h"
 #include "hw/sysbus.h"
 #include "trace.h"
 #include "qemu/error-report.h"
diff --git a/hw/mac_nvram.c b/hw/nvram/mac_nvram.c
index ed32bde5ab..5223330838 100644
--- a/hw/mac_nvram.c
+++ b/hw/nvram/mac_nvram.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/firmware_abi.h"
+#include "hw/sparc/firmware_abi.h"
 #include "sysemu/sysemu.h"
 #include "hw/ppc/mac.h"
 
diff --git a/hw/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index 680cdba928..0cc6cba0e3 100644
--- a/hw/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -26,8 +26,8 @@
 
 #include "sysemu/device_tree.h"
 #include "hw/sysbus.h"
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
 
 typedef struct sPAPRNVRAM {
     VIOsPAPRDevice sdev;
diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
index db2aac8cf8..49bab1f0f0 100644
--- a/hw/openrisc/openrisc_sim.c
+++ b/hw/openrisc/openrisc_sim.c
@@ -21,7 +21,7 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
 #include "elf.h"
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "net/net.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
diff --git a/hw/pci-bridge/Makefile.objs b/hw/pci-bridge/Makefile.objs
new file mode 100644
index 0000000000..5dd92d28a0
--- /dev/null
+++ b/hw/pci-bridge/Makefile.objs
@@ -0,0 +1,3 @@
+common-obj-y += pci_bridge_dev.o
+common-obj-y += ioh3420.o xio3130_upstream.o xio3130_downstream.o
+common-obj-y += i82801b11.o
diff --git a/hw/i82801b11.c b/hw/pci-bridge/i82801b11.c
index 8b4a9c6e54..5807a92d7f 100644
--- a/hw/i82801b11.c
+++ b/hw/pci-bridge/i82801b11.c
@@ -42,7 +42,7 @@
  */
 
 #include "hw/pci/pci.h"
-#include "hw/ich9.h"
+#include "hw/i386/ich9.h"
 
 
 /*****************************************************************************/
diff --git a/hw/ioh3420.c b/hw/pci-bridge/ioh3420.c
index 5cff61e095..bb541ebb12 100644
--- a/hw/ioh3420.c
+++ b/hw/pci-bridge/ioh3420.c
@@ -23,7 +23,7 @@
 #include "hw/pci/pci_ids.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/pcie.h"
-#include "hw/ioh3420.h"
+#include "ioh3420.h"
 
 #define PCI_DEVICE_ID_IOH_EPORT         0x3420  /* D0:F0 express mode */
 #define PCI_DEVICE_ID_IOH_REV           0x2
diff --git a/hw/ioh3420.h b/hw/pci-bridge/ioh3420.h
index 7776e5b02d..7776e5b02d 100644
--- a/hw/ioh3420.h
+++ b/hw/pci-bridge/ioh3420.h
diff --git a/hw/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index 971b432474..971b432474 100644
--- a/hw/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
diff --git a/hw/xio3130_downstream.c b/hw/pci-bridge/xio3130_downstream.c
index b868f56ff9..1810dd23f2 100644
--- a/hw/xio3130_downstream.c
+++ b/hw/pci-bridge/xio3130_downstream.c
@@ -22,7 +22,7 @@
 #include "hw/pci/pci_ids.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/pcie.h"
-#include "hw/xio3130_downstream.h"
+#include "xio3130_downstream.h"
 
 #define PCI_DEVICE_ID_TI_XIO3130D       0x8233  /* downstream port */
 #define XIO3130_REVISION                0x1
diff --git a/hw/xio3130_downstream.h b/hw/pci-bridge/xio3130_downstream.h
index 8426d9ffa6..8426d9ffa6 100644
--- a/hw/xio3130_downstream.h
+++ b/hw/pci-bridge/xio3130_downstream.h
diff --git a/hw/xio3130_upstream.c b/hw/pci-bridge/xio3130_upstream.c
index cd5d97d211..8e0d97a644 100644
--- a/hw/xio3130_upstream.c
+++ b/hw/pci-bridge/xio3130_upstream.c
@@ -22,7 +22,7 @@
 #include "hw/pci/pci_ids.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/pcie.h"
-#include "hw/xio3130_upstream.h"
+#include "xio3130_upstream.h"
 
 #define PCI_DEVICE_ID_TI_XIO3130U       0x8232  /* upstream port */
 #define XIO3130_REVISION                0x2
diff --git a/hw/xio3130_upstream.h b/hw/pci-bridge/xio3130_upstream.h
index 08c1d5f75b..08c1d5f75b 100644
--- a/hw/xio3130_upstream.h
+++ b/hw/pci-bridge/xio3130_upstream.h
diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs
new file mode 100644
index 0000000000..909e702eef
--- /dev/null
+++ b/hw/pci-host/Makefile.objs
@@ -0,0 +1,18 @@
+common-obj-y += pam.o
+
+# PPC devices
+common-obj-$(CONFIG_PREP_PCI) += prep.o
+common-obj-$(CONFIG_GRACKLE_PCI) += grackle.o
+# NewWorld PowerMac
+common-obj-$(CONFIG_UNIN_PCI) += uninorth.o
+common-obj-$(CONFIG_DEC_PCI) += dec.o
+# PowerPC E500 boards
+common-obj-$(CONFIG_PPCE500_PCI) += ppce500.o
+
+# ARM devices
+common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o
+
+common-obj-$(CONFIG_PCI_APB) += apb.o
+common-obj-$(CONFIG_FULONG) += bonito.o
+common-obj-$(CONFIG_PCI_PIIX) += piix.o
+common-obj-$(CONFIG_PCI_Q35) += q35.o
diff --git a/hw/apb_pci.c b/hw/pci-host/apb.c
index 754ca6ca8f..b4981d7005 100644
--- a/hw/apb_pci.c
+++ b/hw/pci-host/apb.c
@@ -31,7 +31,7 @@
 #include "hw/pci/pci_host.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/pci/pci_bus.h"
-#include "hw/apb_pci.h"
+#include "hw/pci-host/apb.h"
 #include "sysemu/sysemu.h"
 #include "exec/address-spaces.h"
 
@@ -92,7 +92,7 @@ static void apb_config_writel (void *opaque, hwaddr addr,
 {
     APBState *s = opaque;
 
-    APB_DPRINTF("%s: addr " TARGET_FMT_lx " val %" PRIx64 "\n", __func__, addr, val);
+    APB_DPRINTF("%s: addr " TARGET_FMT_plx " val %" PRIx64 "\n", __func__, addr, val);
 
     switch (addr & 0xffff) {
     case 0x30 ... 0x4f: /* DMA error registers */
@@ -201,7 +201,7 @@ static uint64_t apb_config_readl (void *opaque,
         val = 0;
         break;
     }
-    APB_DPRINTF("%s: addr " TARGET_FMT_lx " -> %x\n", __func__, addr, val);
+    APB_DPRINTF("%s: addr " TARGET_FMT_plx " -> %x\n", __func__, addr, val);
 
     return val;
 }
@@ -218,7 +218,7 @@ static void apb_pci_config_write(void *opaque, hwaddr addr,
     APBState *s = opaque;
 
     val = qemu_bswap_len(val, size);
-    APB_DPRINTF("%s: addr " TARGET_FMT_lx " val %" PRIx64 "\n", __func__, addr, val);
+    APB_DPRINTF("%s: addr " TARGET_FMT_plx " val %" PRIx64 "\n", __func__, addr, val);
     pci_data_write(s->bus, addr, val, size);
 }
 
@@ -230,7 +230,7 @@ static uint64_t apb_pci_config_read(void *opaque, hwaddr addr,
 
     ret = pci_data_read(s->bus, addr, size);
     ret = qemu_bswap_len(ret, size);
-    APB_DPRINTF("%s: addr " TARGET_FMT_lx " -> %x\n", __func__, addr, ret);
+    APB_DPRINTF("%s: addr " TARGET_FMT_plx " -> %x\n", __func__, addr, ret);
     return ret;
 }
 
diff --git a/hw/bonito.c b/hw/pci-host/bonito.c
index e58655a64d..974150bfc1 100644
--- a/hw/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -41,8 +41,8 @@
 
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
-#include "hw/pc.h"
-#include "hw/mips.h"
+#include "hw/i386/pc.h"
+#include "hw/mips/mips.h"
 #include "hw/pci/pci_host.h"
 #include "sysemu/sysemu.h"
 #include "exec/address-spaces.h"
diff --git a/hw/dec_pci.c b/hw/pci-host/dec.c
index 6ec3d226bd..cff458b574 100644
--- a/hw/dec_pci.c
+++ b/hw/pci-host/dec.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/dec_pci.h"
+#include "dec.h"
 #include "hw/sysbus.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
diff --git a/hw/dec_pci.h b/hw/pci-host/dec.h
index 17dc0c2b0a..17dc0c2b0a 100644
--- a/hw/dec_pci.h
+++ b/hw/pci-host/dec.h
diff --git a/hw/grackle_pci.c b/hw/pci-host/grackle.c
index 69344d9f6a..69344d9f6a 100644
--- a/hw/grackle_pci.c
+++ b/hw/pci-host/grackle.c
diff --git a/hw/pam.c b/hw/pci-host/pam.c
index 6c0061e06e..7181bd68eb 100644
--- a/hw/pam.c
+++ b/hw/pci-host/pam.c
@@ -27,7 +27,7 @@
  * THE SOFTWARE.
  */
 #include "sysemu/sysemu.h"
-#include "hw/pam.h"
+#include "hw/pci-host/pam.h"
 
 void smram_update(MemoryRegion *smram_region, uint8_t smram,
                   uint8_t smm_enabled)
diff --git a/hw/piix_pci.c b/hw/pci-host/piix.c
index 83fcfa497c..f9e68c3099 100644
--- a/hw/piix_pci.c
+++ b/hw/pci-host/piix.c
@@ -23,14 +23,14 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/sysbus.h"
 #include "qemu/range.h"
-#include "hw/xen.h"
-#include "hw/pam.h"
+#include "hw/xen/xen.h"
+#include "hw/pci-host/pam.h"
 #include "sysemu/sysemu.h"
 
 /*
diff --git a/hw/ppce500_pci.c b/hw/pci-host/ppce500.c
index abc7ebe1bf..5e7ad94388 100644
--- a/hw/ppce500_pci.c
+++ b/hw/pci-host/ppce500.c
@@ -19,7 +19,7 @@
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
 #include "qemu/bswap.h"
-#include "hw/ppce500_pci.h"
+#include "hw/pci-host/ppce500.h"
 
 #ifdef DEBUG_PCI
 #define pci_debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
diff --git a/hw/prep_pci.c b/hw/pci-host/prep.c
index 58df2452cd..61302539ab 100644
--- a/hw/prep_pci.c
+++ b/hw/pci-host/prep.c
@@ -27,7 +27,7 @@
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "exec/address-spaces.h"
 
 #define TYPE_RAVEN_PCI_DEVICE "raven"
diff --git a/hw/q35.c b/hw/pci-host/q35.c
index 6ea081aaa3..8467f86450 100644
--- a/hw/q35.c
+++ b/hw/pci-host/q35.c
@@ -28,7 +28,7 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/q35.h"
+#include "hw/pci-host/q35.h"
 
 /****************************************************************************
  * Q35 host
diff --git a/hw/unin_pci.c b/hw/pci-host/uninorth.c
index fff235d523..fff235d523 100644
--- a/hw/unin_pci.c
+++ b/hw/pci-host/uninorth.c
diff --git a/hw/versatile_pci.c b/hw/pci-host/versatile.c
index d67ca796fb..d67ca796fb 100644
--- a/hw/versatile_pci.c
+++ b/hw/pci-host/versatile.c
diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs
index 1cd6cde2ee..a7fb9d0c11 100644
--- a/hw/pci/Makefile.objs
+++ b/hw/pci/Makefile.objs
@@ -4,6 +4,8 @@ common-obj-$(CONFIG_PCI) += shpc.o
 common-obj-$(CONFIG_PCI) += slotid_cap.o
 common-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
 common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o
-common-obj-$(CONFIG_NO_PCI) += pci-stub.o
 
+common-obj-$(CONFIG_NO_PCI) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
+
+obj-$(CONFIG_PCI_HOTPLUG) += pci-hotplug.o
diff --git a/hw/pci/pci-hotplug.c b/hw/pci/pci-hotplug.c
index f38df30540..12287d1efc 100644
--- a/hw/pci/pci-hotplug.c
+++ b/hw/pci/pci-hotplug.c
@@ -26,10 +26,10 @@
 #include "hw/boards.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "monitor/monitor.h"
-#include "hw/scsi.h"
-#include "hw/virtio-blk.h"
+#include "hw/scsi/scsi.h"
+#include "hw/virtio/virtio-blk.h"
 #include "qemu/config-file.h"
 #include "sysemu/blockdev.h"
 #include "qapi/error.h"
@@ -99,7 +99,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
     dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
     dinfo->bus = scsibus->busnr;
     scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
-                                        false, -1);
+                                        false, -1, NULL);
     if (!scsidev) {
         return -1;
     }
diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
index 4de02098e2..be00d1da3b 100644
--- a/hw/ppc/Makefile.objs
+++ b/hw/ppc/Makefile.objs
@@ -1,26 +1,12 @@
-# PREP target
-obj-y += mc146818rtc.o
-# IBM pSeries (sPAPR)
-obj-$(CONFIG_PSERIES) += spapr_vty.o spapr_llan.o spapr_vscsi.o
-obj-$(CONFIG_PSERIES) += spapr_pci.o pci/pci-hotplug.o
-obj-$(CONFIG_PSERIES) += spapr_nvram.o
-# PowerPC 4xx boards
-obj-y += ppc4xx_pci.o
-# PowerPC OpenPIC
-obj-y += openpic.o
-
-# Xilinx PPC peripherals
-obj-y += xilinx_ethlite.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 # shared objects
 obj-y += ppc.o ppc_booke.o
 # IBM pSeries (sPAPR)
 obj-$(CONFIG_PSERIES) += spapr.o xics.o spapr_vio.o spapr_events.o
 obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
+obj-$(CONFIG_PSERIES) += spapr_pci.o
 # PowerPC 4xx boards
 obj-y += ppc405_boards.o ppc4xx_devs.o ppc405_uc.o ppc440_bamboo.o
+obj-y += ppc4xx_pci.o
 # PReP
 obj-y += prep.o
 # OldWorld PowerMac
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index fef9c5d842..c1bdb6be98 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -21,21 +21,21 @@
 #include "net/net.h"
 #include "qemu/config-file.h"
 #include "hw/hw.h"
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "hw/pci/pci.h"
 #include "hw/boards.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "sysemu/device_tree.h"
-#include "hw/openpic.h"
-#include "hw/ppc.h"
+#include "hw/ppc/openpic.h"
+#include "hw/ppc/ppc.h"
 #include "hw/loader.h"
 #include "elf.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 #include "qemu/host-utils.h"
-#include "hw/ppce500_pci.h"
+#include "hw/pci-host/ppce500.h"
 
 #define BINARY_DEVICE_TREE_FILE    "mpc8544ds.dtb"
 #define UIMAGE_LOAD_BASE           0
diff --git a/hw/ppc/e500plat.c b/hw/ppc/e500plat.c
index 4b3057528c..7292ce1290 100644
--- a/hw/ppc/e500plat.c
+++ b/hw/ppc/e500plat.c
@@ -15,7 +15,7 @@
 #include "hw/boards.h"
 #include "sysemu/device_tree.h"
 #include "hw/pci/pci.h"
-#include "hw/openpic.h"
+#include "hw/ppc/openpic.h"
 
 static void e500plat_fixup_devtree(PPCE500Params *params, void *fdt)
 {
diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index b17107b797..54efaed627 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -28,7 +28,7 @@
 #include "exec/memory.h"
 #include "hw/sysbus.h"
 #include "hw/ide/internal.h"
-#include "hw/adb.h"
+#include "hw/input/adb.h"
 
 /* SMP is not enabled, for now */
 #define MAX_CPUS 1
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index a08a6b2086..4a9b8837e3 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -47,18 +47,18 @@
  *
  */
 #include "hw/hw.h"
-#include "hw/ppc.h"
+#include "hw/ppc/ppc.h"
 #include "hw/ppc/mac.h"
-#include "hw/adb.h"
-#include "hw/mac_dbdma.h"
-#include "hw/nvram.h"
+#include "hw/input/adb.h"
+#include "hw/ppc/mac_dbdma.h"
+#include "hw/timer/m48t59.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/fw_cfg.h"
-#include "hw/escc.h"
-#include "hw/openpic.h"
+#include "hw/nvram/fw_cfg.h"
+#include "hw/char/escc.h"
+#include "hw/ppc/openpic.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
 #include "elf.h"
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 2778e45879..3acca94432 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -24,17 +24,17 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/ppc.h"
+#include "hw/ppc/ppc.h"
 #include "mac.h"
-#include "hw/adb.h"
-#include "hw/nvram.h"
+#include "hw/input/adb.h"
+#include "hw/timer/m48t59.h"
 #include "sysemu/sysemu.h"
 #include "net/net.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/pci/pci.h"
 #include "hw/boards.h"
-#include "hw/fw_cfg.h"
-#include "hw/escc.h"
+#include "hw/nvram/fw_cfg.h"
+#include "hw/char/escc.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
 #include "elf.h"
diff --git a/hw/ppc/mpc8544ds.c b/hw/ppc/mpc8544ds.c
index cf29788c4d..444da0246d 100644
--- a/hw/ppc/mpc8544ds.c
+++ b/hw/ppc/mpc8544ds.c
@@ -14,7 +14,7 @@
 #include "e500.h"
 #include "hw/boards.h"
 #include "sysemu/device_tree.h"
-#include "hw/openpic.h"
+#include "hw/ppc/openpic.h"
 
 static void mpc8544ds_fixup_devtree(PPCE500Params *params, void *fdt)
 {
diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index 85bc821d94..fb57b42ea0 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -22,10 +22,10 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/ppc.h"
+#include "hw/ppc/ppc.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
-#include "hw/nvram.h"
+#include "hw/timer/m48t59.h"
 #include "qemu/log.h"
 #include "hw/loader.h"
 #include "sysemu/kvm.h"
diff --git a/hw/ppc405.h b/hw/ppc/ppc405.h
index 45c2159aa6..1c5f04fae1 100644
--- a/hw/ppc405.h
+++ b/hw/ppc/ppc405.h
@@ -25,7 +25,7 @@
 #if !defined(PPC_405_H)
 #define PPC_405_H
 
-#include "hw/ppc4xx.h"
+#include "hw/ppc/ppc4xx.h"
 
 /* Bootinfo as set-up by u-boot */
 typedef struct ppc4xx_bd_info_t ppc4xx_bd_info_t;
diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index ba443cf8ef..8e56b16648 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -22,10 +22,10 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/ppc.h"
-#include "hw/ppc405.h"
-#include "hw/nvram.h"
-#include "hw/flash.h"
+#include "hw/ppc/ppc.h"
+#include "ppc405.h"
+#include "hw/timer/m48t59.h"
+#include "hw/block/flash.h"
 #include "sysemu/sysemu.h"
 #include "block/block.h"
 #include "hw/boards.h"
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
index 56bae8f6e0..c6c909e05e 100644
--- a/hw/ppc/ppc405_uc.c
+++ b/hw/ppc/ppc405_uc.c
@@ -22,9 +22,9 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/ppc.h"
-#include "hw/ppc405.h"
-#include "hw/serial.h"
+#include "hw/ppc/ppc.h"
+#include "ppc405.h"
+#include "hw/char/serial.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "qemu/log.h"
diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c
index 66911b58c6..a55e7170cc 100644
--- a/hw/ppc/ppc440_bamboo.c
+++ b/hw/ppc/ppc440_bamboo.c
@@ -23,9 +23,9 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "exec/address-spaces.h"
-#include "hw/serial.h"
-#include "hw/ppc.h"
-#include "hw/ppc405.h"
+#include "hw/char/serial.h"
+#include "hw/ppc/ppc.h"
+#include "ppc405.h"
 #include "sysemu/sysemu.h"
 #include "hw/sysbus.h"
 
diff --git a/hw/ppc/ppc4xx_devs.c b/hw/ppc/ppc4xx_devs.c
index 49ec728a7b..d8e3dae25c 100644
--- a/hw/ppc/ppc4xx_devs.c
+++ b/hw/ppc/ppc4xx_devs.c
@@ -22,8 +22,8 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/ppc.h"
-#include "hw/ppc4xx.h"
+#include "hw/ppc/ppc.h"
+#include "hw/ppc/ppc4xx.h"
 #include "qemu/log.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/ppc4xx_pci.c b/hw/ppc/ppc4xx_pci.c
index 854e17048f..599539bc1d 100644
--- a/hw/ppc4xx_pci.c
+++ b/hw/ppc/ppc4xx_pci.c
@@ -20,8 +20,8 @@
  * 4xx SoCs, such as the 440EP. */
 
 #include "hw/hw.h"
-#include "hw/ppc.h"
-#include "hw/ppc4xx.h"
+#include "hw/ppc/ppc.h"
+#include "hw/ppc/ppc4xx.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
 #include "exec/address-spaces.h"
diff --git a/hw/ppc/ppc_booke.c b/hw/ppc/ppc_booke.c
index 30375c0c41..585f53b912 100644
--- a/hw/ppc/ppc_booke.c
+++ b/hw/ppc/ppc_booke.c
@@ -22,10 +22,10 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/ppc.h"
+#include "hw/ppc/ppc.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
-#include "hw/nvram.h"
+#include "hw/timer/m48t59.h"
 #include "qemu/log.h"
 #include "hw/loader.h"
 
diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index 292091180d..cceab3ead9 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -22,22 +22,22 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/nvram.h"
-#include "hw/pc.h"
-#include "hw/serial.h"
-#include "hw/fdc.h"
+#include "hw/timer/m48t59.h"
+#include "hw/i386/pc.h"
+#include "hw/char/serial.h"
+#include "hw/block/fdc.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
-#include "hw/ppc.h"
+#include "hw/ppc/ppc.h"
 #include "hw/boards.h"
 #include "qemu/log.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
-#include "hw/mc146818rtc.h"
-#include "hw/pc87312.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/isa/pc87312.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/arch_init.h"
 #include "exec/address-spaces.h"
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 7b2a11fbe4..7a425011da 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -34,13 +34,13 @@
 #include "kvm_ppc.h"
 
 #include "hw/boards.h"
-#include "hw/ppc.h"
+#include "hw/ppc/ppc.h"
 #include "hw/loader.h"
 
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
-#include "hw/spapr_pci.h"
-#include "hw/xics.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
+#include "hw/pci-host/spapr.h"
+#include "hw/ppc/xics.h"
 #include "hw/pci/msi.h"
 
 #include "sysemu/kvm.h"
diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
index ce78f0922e..ff87ac31d1 100644
--- a/hw/ppc/spapr_events.c
+++ b/hw/ppc/spapr_events.c
@@ -30,8 +30,8 @@
 #include "hw/qdev.h"
 #include "sysemu/device_tree.h"
 
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
 
 #include <libfdt.h>
 
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 22cfb7e674..f518aee216 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -2,7 +2,7 @@
 #include "cpu.h"
 #include "sysemu/sysemu.h"
 #include "helper_regs.h"
-#include "hw/spapr.h"
+#include "hw/ppc/spapr.h"
 #include "mmu-hash64.h"
 
 static target_ulong compute_tlbie_rb(target_ulong v, target_ulong r,
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 8d500bf6be..d2782cfb39 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -23,7 +23,7 @@
 #include "sysemu/dma.h"
 #include "exec/address-spaces.h"
 
-#include "hw/spapr.h"
+#include "hw/ppc/spapr.h"
 
 #include <libfdt.h>
 
diff --git a/hw/spapr_pci.c b/hw/ppc/spapr_pci.c
index 3e0d8d12fb..62ff323f73 100644
--- a/hw/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -27,8 +27,8 @@
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "hw/pci/pci_host.h"
-#include "hw/spapr.h"
-#include "hw/spapr_pci.h"
+#include "hw/ppc/spapr.h"
+#include "hw/pci-host/spapr.h"
 #include "exec/address-spaces.h"
 #include <libfdt.h>
 #include "trace.h"
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index a24e853d4d..b71b59c5cf 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -30,8 +30,8 @@
 #include "hw/qdev.h"
 #include "sysemu/device_tree.h"
 
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
 
 #include <libfdt.h>
 
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index 6eb3ab5482..4dbc31541b 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -30,9 +30,9 @@
 #include "sysemu/device_tree.h"
 #include "kvm_ppc.h"
 
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
-#include "hw/xics.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
+#include "hw/ppc/xics.h"
 
 #ifdef CONFIG_FDT
 #include <libfdt.h>
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index 41eab1697c..92b43947f7 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -24,10 +24,10 @@
 
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/serial.h"
-#include "hw/flash.h"
+#include "hw/char/serial.h"
+#include "hw/block/flash.h"
 #include "sysemu/sysemu.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/boards.h"
 #include "sysemu/device_tree.h"
 #include "hw/loader.h"
@@ -35,9 +35,9 @@
 #include "qemu/log.h"
 #include "exec/address-spaces.h"
 
-#include "hw/ppc.h"
-#include "hw/ppc4xx.h"
-#include "hw/ppc405.h"
+#include "hw/ppc/ppc.h"
+#include "hw/ppc/ppc4xx.h"
+#include "ppc405.h"
 
 #include "sysemu/blockdev.h"
 #include "hw/xilinx.h"
diff --git a/hw/ppc/xics.c b/hw/ppc/xics.c
index 374da5bbfd..8e1e85edfd 100644
--- a/hw/ppc/xics.c
+++ b/hw/ppc/xics.c
@@ -27,8 +27,8 @@
 
 #include "hw/hw.h"
 #include "trace.h"
-#include "hw/spapr.h"
-#include "hw/xics.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/xics.h"
 
 /*
  * ICP: Presentation layer
diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index 9f2f41989c..77e1218447 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -2,7 +2,7 @@ obj-y = s390-virtio-bus.o s390-virtio.o
 obj-y += s390-virtio-hcall.o
 obj-y += sclp.o
 obj-y += event-facility.o
-obj-y += sclpquiesce.o sclpconsole.o
+obj-y += sclpquiesce.o
 obj-y += ipl.o
 obj-y += css.o
 obj-y += s390-virtio-ccw.o
diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index 8c529c14d0..ddf15a21d3 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -24,15 +24,15 @@
 #include "monitor/monitor.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "hw/virtio.h"
-#include "hw/virtio-rng.h"
-#include "hw/virtio-serial.h"
-#include "hw/virtio-net.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-rng.h"
+#include "hw/virtio/virtio-serial.h"
+#include "hw/virtio/virtio-net.h"
 #include "hw/sysbus.h"
 #include "sysemu/kvm.h"
 
 #include "hw/s390x/s390-virtio-bus.h"
-#include "hw/virtio-bus.h"
+#include "hw/virtio/virtio-bus.h"
 
 /* #define DEBUG_S390 */
 
diff --git a/hw/s390x/s390-virtio-bus.h b/hw/s390x/s390-virtio-bus.h
index ebe8794204..c557132166 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -19,12 +19,12 @@
 #ifndef HW_S390_VIRTIO_BUS_H
 #define HW_S390_VIRTIO_BUS_H 1
 
-#include "hw/virtio-blk.h"
-#include "hw/virtio-net.h"
-#include "hw/virtio-rng.h"
-#include "hw/virtio-serial.h"
-#include "hw/virtio-scsi.h"
-#include "hw/virtio-bus.h"
+#include "hw/virtio/virtio-blk.h"
+#include "hw/virtio/virtio-net.h"
+#include "hw/virtio/virtio-rng.h"
+#include "hw/virtio/virtio-serial.h"
+#include "hw/virtio/virtio-scsi.h"
+#include "hw/virtio/virtio-bus.h"
 
 #define VIRTIO_DEV_OFFS_TYPE		0	/* 8 bits */
 #define VIRTIO_DEV_OFFS_NUM_VQ		1	/* 8 bits */
diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index ca275bd9d7..f82c0e1964 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -29,7 +29,7 @@
 #include "hw/boards.h"
 #include "monitor/monitor.h"
 #include "hw/loader.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "hw/sysbus.h"
 #include "sysemu/kvm.h"
 #include "exec/address-spaces.h"
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 5dce791406..4dec0cd861 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -15,12 +15,12 @@
 #include "sysemu/sysemu.h"
 #include "net/net.h"
 #include "monitor/monitor.h"
-#include "hw/virtio.h"
-#include "hw/virtio-serial.h"
-#include "hw/virtio-net.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-serial.h"
+#include "hw/virtio/virtio-net.h"
 #include "hw/sysbus.h"
 #include "qemu/bitops.h"
-#include "hw/virtio-bus.h"
+#include "hw/virtio/virtio-bus.h"
 
 #include "ioinst.h"
 #include "css.h"
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index d580510283..46e9a558af 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -12,13 +12,13 @@
 #ifndef HW_S390X_VIRTIO_CCW_H
 #define HW_S390X_VIRTIO_CCW_H
 
-#include <hw/virtio-blk.h>
-#include <hw/virtio-net.h>
-#include <hw/virtio-serial.h>
-#include <hw/virtio-scsi.h>
-#include "hw/virtio-balloon.h"
-#include <hw/virtio-rng.h>
-#include <hw/virtio-bus.h>
+#include <hw/virtio/virtio-blk.h>
+#include <hw/virtio/virtio-net.h>
+#include <hw/virtio/virtio-serial.h>
+#include <hw/virtio/virtio-scsi.h>
+#include <hw/virtio/virtio-balloon.h>
+#include <hw/virtio/virtio-rng.h>
+#include <hw/virtio/virtio-bus.h>
 
 #define VIRTUAL_CSSID 0xfe
 
diff --git a/hw/scsi/Makefile.objs b/hw/scsi/Makefile.objs
new file mode 100644
index 0000000000..aab0e9b494
--- /dev/null
+++ b/hw/scsi/Makefile.objs
@@ -0,0 +1,8 @@
+common-obj-y += scsi-disk.o
+common-obj-y += scsi-generic.o scsi-bus.o
+common-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
+common-obj-$(CONFIG_MEGASAS_SCSI_PCI) += megasas.o
+common-obj-$(CONFIG_ESP) += esp.o
+common-obj-$(CONFIG_ESP_PCI) += esp-pci.o
+obj-$(CONFIG_PSERIES) += spapr_vscsi.o
+obj-$(CONFIG_VIRTIO) += virtio-scsi.o
diff --git a/hw/esp-pci.c b/hw/scsi/esp-pci.c
index 7599b39d8d..3ca5c8c673 100644
--- a/hw/esp-pci.c
+++ b/hw/scsi/esp-pci.c
@@ -24,8 +24,8 @@
  */
 
 #include "hw/pci/pci.h"
-#include "hw/eeprom93xx.h"
-#include "hw/esp.h"
+#include "hw/nvram/eeprom93xx.h"
+#include "hw/scsi/esp.h"
 #include "trace.h"
 #include "qemu/log.h"
 
diff --git a/hw/esp.c b/hw/scsi/esp.c
index 5365eacec0..17adbecf8c 100644
--- a/hw/esp.c
+++ b/hw/scsi/esp.c
@@ -24,7 +24,7 @@
  */
 
 #include "hw/sysbus.h"
-#include "hw/esp.h"
+#include "hw/scsi/esp.h"
 #include "trace.h"
 #include "qemu/log.h"
 
diff --git a/hw/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index 5a8bf4d0e9..c601b2943d 100644
--- a/hw/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -14,7 +14,7 @@
 
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
-#include "hw/scsi.h"
+#include "hw/scsi/scsi.h"
 #include "sysemu/dma.h"
 
 //#define DEBUG_LSI
diff --git a/hw/megasas.c b/hw/scsi/megasas.c
index 9b815d4b8f..14b0552045 100644
--- a/hw/megasas.c
+++ b/hw/scsi/megasas.c
@@ -23,11 +23,11 @@
 #include "sysemu/dma.h"
 #include "hw/pci/msix.h"
 #include "qemu/iov.h"
-#include "hw/scsi.h"
-#include "hw/scsi-defs.h"
+#include "hw/scsi/scsi.h"
+#include "block/scsi.h"
 #include "trace.h"
 
-#include "hw/mfi.h"
+#include "mfi.h"
 
 #define MEGASAS_VERSION "1.70"
 #define MEGASAS_MAX_FRAMES 2048         /* Firmware limit at 65535 */
diff --git a/hw/mfi.h b/hw/scsi/mfi.h
index cd8355badf..cd8355badf 100644
--- a/hw/mfi.h
+++ b/hw/scsi/mfi.h
diff --git a/hw/scsi-bus.c b/hw/scsi/scsi-bus.c
index 08787c2a9b..6239ee1465 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -1,7 +1,7 @@
 #include "hw/hw.h"
 #include "qemu/error-report.h"
-#include "hw/scsi.h"
-#include "hw/scsi-defs.h"
+#include "hw/scsi/scsi.h"
+#include "block/scsi.h"
 #include "hw/qdev.h"
 #include "sysemu/blockdev.h"
 #include "trace.h"
@@ -207,7 +207,8 @@ static int scsi_qdev_exit(DeviceState *qdev)
 
 /* handle legacy '-drive if=scsi,...' cmd line args */
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
-                                      int unit, bool removable, int bootindex)
+                                      int unit, bool removable, int bootindex,
+                                      const char *serial)
 {
     const char *driver;
     DeviceState *dev;
@@ -221,6 +222,9 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
     if (object_property_find(OBJECT(dev), "removable", NULL)) {
         qdev_prop_set_bit(dev, "removable", removable);
     }
+    if (serial) {
+        qdev_prop_set_string(dev, "serial", serial);
+    }
     if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
         qdev_free(dev);
         return NULL;
@@ -243,7 +247,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
             continue;
         }
         qemu_opts_loc_restore(dinfo->opts);
-        if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1)) {
+        if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL)) {
             res = -1;
             break;
         }
diff --git a/hw/scsi-disk.c b/hw/scsi/scsi-disk.c
index c5c7bf3dfa..f52bd11d42 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -30,11 +30,11 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
 
 #include "qemu-common.h"
 #include "qemu/error-report.h"
-#include "hw/scsi.h"
-#include "hw/scsi-defs.h"
+#include "hw/scsi/scsi.h"
+#include "block/scsi.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "sysemu/dma.h"
 
 #ifdef __linux
diff --git a/hw/scsi-generic.c b/hw/scsi/scsi-generic.c
index 4d04caccce..2a9a561127 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -13,7 +13,7 @@
 
 #include "qemu-common.h"
 #include "qemu/error-report.h"
-#include "hw/scsi.h"
+#include "hw/scsi/scsi.h"
 #include "sysemu/blockdev.h"
 
 #ifdef __linux__
@@ -35,7 +35,7 @@ do { fprintf(stderr, "scsi-generic: " fmt , ## __VA_ARGS__); } while (0)
 #include <sys/stat.h>
 #include <unistd.h>
 #include <scsi/sg.h>
-#include "hw/scsi-defs.h"
+#include "block/scsi.h"
 
 #define SCSI_SENSE_BUF_SIZE 96
 
diff --git a/hw/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c
index 27940949ce..999a463a84 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/scsi/spapr_vscsi.c
@@ -32,13 +32,13 @@
  *  - Maybe do autosense (PAPR seems to mandate it, linux doesn't care)
  */
 #include "hw/hw.h"
-#include "hw/scsi.h"
-#include "hw/scsi-defs.h"
-#include "hw/srp.h"
+#include "hw/scsi/scsi.h"
+#include "block/scsi.h"
+#include "srp.h"
 #include "hw/qdev.h"
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
-#include "hw/ppc-viosrp.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
+#include "viosrp.h"
 
 #include <libfdt.h>
 
diff --git a/hw/srp.h b/hw/scsi/srp.h
index 5e0cad5c19..5e0cad5c19 100644
--- a/hw/srp.h
+++ b/hw/scsi/srp.h
diff --git a/hw/ppc-viosrp.h b/hw/scsi/viosrp.h
index d8e365db1e..d8e365db1e 100644
--- a/hw/ppc-viosrp.h
+++ b/hw/scsi/viosrp.h
diff --git a/hw/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 06a58a6a63..ead7cda13d 100644
--- a/hw/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -13,11 +13,11 @@
  *
  */
 
-#include "hw/virtio-scsi.h"
+#include "hw/virtio/virtio-scsi.h"
 #include "qemu/error-report.h"
-#include <hw/scsi.h>
-#include <hw/scsi-defs.h>
-#include "hw/virtio-bus.h"
+#include <hw/scsi/scsi.h>
+#include <block/scsi.h>
+#include <hw/virtio/virtio-bus.h>
 
 #define VIRTIO_SCSI_VQ_SIZE     128
 #define VIRTIO_SCSI_CDB_SIZE    32
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
new file mode 100644
index 0000000000..f1aed83d9d
--- /dev/null
+++ b/hw/sd/Makefile.objs
@@ -0,0 +1,8 @@
+common-obj-$(CONFIG_PL181) += pl181.o
+common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
+common-obj-$(CONFIG_SD) += sd.o
+common-obj-$(CONFIG_SDHCI) += sdhci.o
+
+obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
+obj-$(CONFIG_OMAP) += omap_mmc.o
+obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
diff --git a/hw/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
index d5944bca69..d5944bca69 100644
--- a/hw/milkymist-memcard.c
+++ b/hw/sd/milkymist-memcard.c
diff --git a/hw/omap_mmc.c b/hw/sd/omap_mmc.c
index 6e48110c9e..d4079cde0b 100644
--- a/hw/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -17,7 +17,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 #include "hw/sd.h"
 
 struct omap_mmc_s {
diff --git a/hw/pl181.c b/hw/sd/pl181.c
index 2527296776..2527296776 100644
--- a/hw/pl181.c
+++ b/hw/sd/pl181.c
diff --git a/hw/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
index 0df83cc1df..2db1cabb7a 100644
--- a/hw/pxa2xx_mmci.c
+++ b/hw/sd/pxa2xx_mmci.c
@@ -11,7 +11,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "hw/sd.h"
 #include "hw/qdev.h"
 
diff --git a/hw/sd.c b/hw/sd/sd.c
index a895123867..66c4014fbe 100644
--- a/hw/sd.c
+++ b/hw/sd/sd.c
@@ -478,7 +478,7 @@ static const VMStateDescription sd_vmstate = {
         VMSTATE_UINT64(data_start, SDState),
         VMSTATE_UINT32(data_offset, SDState),
         VMSTATE_UINT8_ARRAY(data, SDState, 512),
-        VMSTATE_BUFFER_UNSAFE(buf, SDState, 1, 512),
+        VMSTATE_BUFFER_POINTER_UNSAFE(buf, SDState, 1, 512),
         VMSTATE_BOOL(enable, SDState),
         VMSTATE_END_OF_LIST()
     }
diff --git a/hw/sdhci.c b/hw/sd/sdhci.c
index 4a29e6cf7f..91dc9b082d 100644
--- a/hw/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -29,7 +29,7 @@
 #include "block/block_int.h"
 #include "qemu/bitops.h"
 
-#include "hw/sdhci.h"
+#include "sdhci.h"
 
 /* host controller debug messages */
 #ifndef SDHC_DEBUG
diff --git a/hw/sdhci.h b/hw/sd/sdhci.h
index a560c3c93f..a560c3c93f 100644
--- a/hw/sdhci.h
+++ b/hw/sd/sdhci.h
diff --git a/hw/ssi-sd.c b/hw/sd/ssi-sd.c
index 4d3c4f6445..4d3c4f6445 100644
--- a/hw/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
diff --git a/hw/sh4/Makefile.objs b/hw/sh4/Makefile.objs
index 72b6a1fcb4..2393702c57 100644
--- a/hw/sh4/Makefile.objs
+++ b/hw/sh4/Makefile.objs
@@ -1,9 +1,4 @@
-obj-y = tc58128.o
-obj-y += sh_timer.o sh_serial.o sh_intc.o sh_pci.o sm501.o
-obj-y += ide/mmio.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 obj-y += shix.o r2d.o
 
 obj-y += sh7750.o sh7750_regnames.o
+obj-y += sh_pci.o
diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index faa03d2069..256a58c601 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -25,17 +25,17 @@
 
 #include "hw/sysbus.h"
 #include "hw/hw.h"
-#include "hw/sh.h"
-#include "hw/devices.h"
+#include "hw/sh4/sh.h"
+#include "hw/arm/devices.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
-#include "hw/sh7750_regs.h"
+#include "sh7750_regs.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
 #include "hw/usb.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/sh4/sh7750.c b/hw/sh4/sh7750.c
index e4d37ad6ac..2218b9ce6a 100644
--- a/hw/sh4/sh7750.c
+++ b/hw/sh4/sh7750.c
@@ -24,11 +24,11 @@
  */
 #include <stdio.h>
 #include "hw/hw.h"
-#include "hw/sh.h"
+#include "hw/sh4/sh.h"
 #include "sysemu/sysemu.h"
-#include "hw/sh7750_regs.h"
-#include "hw/sh7750_regnames.h"
-#include "hw/sh_intc.h"
+#include "sh7750_regs.h"
+#include "sh7750_regnames.h"
+#include "hw/sh4/sh_intc.h"
 #include "cpu.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/sh4/sh7750_regnames.c b/hw/sh4/sh7750_regnames.c
index 389698d24a..52ac1cc781 100644
--- a/hw/sh4/sh7750_regnames.c
+++ b/hw/sh4/sh7750_regnames.c
@@ -1,7 +1,7 @@
 #include "hw/hw.h"
-#include "hw/sh.h"
-#include "hw/sh7750_regs.h"
-#include "hw/sh7750_regnames.h"
+#include "hw/sh4/sh.h"
+#include "sh7750_regs.h"
+#include "sh7750_regnames.h"
 
 #define REGNAME(r) {r, #r},
 
diff --git a/hw/sh7750_regnames.h b/hw/sh4/sh7750_regnames.h
index 7463709b4c..7463709b4c 100644
--- a/hw/sh7750_regnames.h
+++ b/hw/sh4/sh7750_regnames.h
diff --git a/hw/sh7750_regs.h b/hw/sh4/sh7750_regs.h
index 534aa48403..534aa48403 100644
--- a/hw/sh7750_regs.h
+++ b/hw/sh4/sh7750_regs.h
diff --git a/hw/sh_pci.c b/hw/sh4/sh_pci.c
index e3e7550ae7..d213a90580 100644
--- a/hw/sh_pci.c
+++ b/hw/sh4/sh_pci.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "hw/sysbus.h"
-#include "hw/sh.h"
+#include "hw/sh4/sh.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
 #include "qemu/bswap.h"
diff --git a/hw/sh4/shix.c b/hw/sh4/shix.c
index 192579d065..c23d4afb10 100644
--- a/hw/sh4/shix.c
+++ b/hw/sh4/shix.c
@@ -28,7 +28,7 @@
    More information in target-sh4/README.sh4
 */
 #include "hw/hw.h"
-#include "hw/sh.h"
+#include "hw/sh4/sh.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
diff --git a/hw/sparc/Makefile.objs b/hw/sparc/Makefile.objs
index 71bbddf8c3..c987b5b5df 100644
--- a/hw/sparc/Makefile.objs
+++ b/hw/sparc/Makefile.objs
@@ -1,10 +1 @@
-obj-y = lance.o tcx.o sun4m_iommu.o slavio_intctl.o
-obj-y += slavio_timer.o slavio_misc.o sparc32_dma.o
-obj-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o
-
-# GRLIB
-obj-y += grlib_gptimer.o grlib_irqmp.o grlib_apbuart.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 obj-y += sun4m.o leon3.o
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index bf06bf4b51..3b27d4019a 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -32,7 +32,7 @@
 #include "trace.h"
 #include "exec/address-spaces.h"
 
-#include "hw/grlib.h"
+#include "hw/sparc/grlib.h"
 
 /* Default system clock.  */
 #define CPU_CLK (40 * 1000 * 1000)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 9ebda02aa1..31beb32885 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -23,19 +23,19 @@
  */
 #include "hw/sysbus.h"
 #include "qemu/timer.h"
-#include "hw/sun4m.h"
-#include "hw/nvram.h"
-#include "hw/sparc32_dma.h"
-#include "hw/fdc.h"
+#include "hw/sparc/sun4m.h"
+#include "hw/timer/m48t59.h"
+#include "hw/sparc/sparc32_dma.h"
+#include "hw/block/fdc.h"
 #include "sysemu/sysemu.h"
 #include "net/net.h"
 #include "hw/boards.h"
-#include "hw/firmware_abi.h"
-#include "hw/esp.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
-#include "hw/fw_cfg.h"
-#include "hw/escc.h"
+#include "hw/sparc/firmware_abi.h"
+#include "hw/scsi/esp.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
+#include "hw/nvram/fw_cfg.h"
+#include "hw/char/escc.h"
 #include "hw/empty_slot.h"
 #include "hw/qdev-addr.h"
 #include "hw/loader.h"
diff --git a/hw/sparc64/Makefile.objs b/hw/sparc64/Makefile.objs
index 4df0d90ec2..a84cfe3ec7 100644
--- a/hw/sparc64/Makefile.objs
+++ b/hw/sparc64/Makefile.objs
@@ -1,6 +1 @@
-obj-y = apb_pci.o
-obj-y += mc146818rtc.o
-
-obj-y := $(addprefix ../,$(obj-y))
-
 obj-y += sun4u.o
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 4c39cf6607..0d29620094 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -23,17 +23,17 @@
  */
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
-#include "hw/apb_pci.h"
-#include "hw/pc.h"
-#include "hw/serial.h"
-#include "hw/nvram.h"
-#include "hw/fdc.h"
+#include "hw/pci-host/apb.h"
+#include "hw/i386/pc.h"
+#include "hw/char/serial.h"
+#include "hw/timer/m48t59.h"
+#include "hw/block/fdc.h"
 #include "net/net.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "hw/firmware_abi.h"
-#include "hw/fw_cfg.h"
+#include "hw/sparc/firmware_abi.h"
+#include "hw/nvram/fw_cfg.h"
 #include "hw/sysbus.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
diff --git a/hw/ssi/Makefile.objs b/hw/ssi/Makefile.objs
new file mode 100644
index 0000000000..9555825aca
--- /dev/null
+++ b/hw/ssi/Makefile.objs
@@ -0,0 +1,6 @@
+common-obj-$(CONFIG_PL022) += pl022.o
+common-obj-$(CONFIG_SSI) += ssi.o
+common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o
+common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o
+
+obj-$(CONFIG_OMAP) += omap_spi.o
diff --git a/hw/omap_spi.c b/hw/ssi/omap_spi.c
index 1cbd98d338..11403c411b 100644
--- a/hw/omap_spi.c
+++ b/hw/ssi/omap_spi.c
@@ -20,7 +20,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #include "hw/hw.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 
 /* Multichannel SPI */
 struct omap_mcspi_s {
diff --git a/hw/pl022.c b/hw/ssi/pl022.c
index 536c2166fe..536c2166fe 100644
--- a/hw/pl022.c
+++ b/hw/ssi/pl022.c
diff --git a/hw/ssi.c b/hw/ssi/ssi.c
index 1264d9da23..1264d9da23 100644
--- a/hw/ssi.c
+++ b/hw/ssi/ssi.c
diff --git a/hw/xilinx_spi.c b/hw/ssi/xilinx_spi.c
index f6bd3bac23..f6bd3bac23 100644
--- a/hw/xilinx_spi.c
+++ b/hw/ssi/xilinx_spi.c
diff --git a/hw/xilinx_spips.c b/hw/ssi/xilinx_spips.c
index b2397f4a42..b2397f4a42 100644
--- a/hw/xilinx_spips.c
+++ b/hw/ssi/xilinx_spips.c
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
new file mode 100644
index 0000000000..e4bd17fbb7
--- /dev/null
+++ b/hw/timer/Makefile.objs
@@ -0,0 +1,28 @@
+common-obj-$(CONFIG_ARM_TIMER) += arm_timer.o
+common-obj-$(CONFIG_CADENCE) += cadence_ttc.o
+common-obj-$(CONFIG_DS1338) += ds1338.o
+common-obj-$(CONFIG_HPET) += hpet.o
+common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
+common-obj-$(CONFIG_M48T59) += m48t59.o
+common-obj-$(CONFIG_PL031) += pl031.o
+common-obj-$(CONFIG_PUV3) += puv3_ost.o
+common-obj-$(CONFIG_TWL92230) += twl92230.o
+common-obj-$(CONFIG_XILINX) += xilinx_timer.o
+common-obj-$(CONFIG_SLAVIO) += slavio_timer.o
+common-obj-$(CONFIG_ETRAXFS) += etraxfs_timer.o
+common-obj-$(CONFIG_GRLIB) += grlib_gptimer.o
+common-obj-$(CONFIG_IMX) += imx_timer.o
+common-obj-$(CONFIG_LM32) += lm32_timer.o
+common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o
+
+obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o
+obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o
+obj-$(CONFIG_EXYNOS4) += exynos4210_rtc.o
+obj-$(CONFIG_OMAP) += omap_gptimer.o
+obj-$(CONFIG_OMAP) += omap_synctimer.o
+obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o
+obj-$(CONFIG_SH4) += sh_timer.o
+obj-$(CONFIG_TUSB6010) += tusb6010.o
+
+obj-$(CONFIG_ARM_MPTIMER) += arm_mptimer.o
+obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
diff --git a/hw/arm_mptimer.c b/hw/timer/arm_mptimer.c
index f59a9f11f0..317f5e43ed 100644
--- a/hw/arm_mptimer.c
+++ b/hw/timer/arm_mptimer.c
@@ -253,14 +253,15 @@ static int arm_mptimer_init(SysBusDevice *dev)
 
 static const VMStateDescription vmstate_timerblock = {
     .name = "arm_mptimer_timerblock",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32(count, TimerBlock),
         VMSTATE_UINT32(load, TimerBlock),
         VMSTATE_UINT32(control, TimerBlock),
         VMSTATE_UINT32(status, TimerBlock),
         VMSTATE_INT64(tick, TimerBlock),
+        VMSTATE_TIMER(timer, TimerBlock),
         VMSTATE_END_OF_LIST()
     }
 };
diff --git a/hw/arm_timer.c b/hw/timer/arm_timer.c
index 644987046a..644987046a 100644
--- a/hw/arm_timer.c
+++ b/hw/timer/arm_timer.c
diff --git a/hw/cadence_ttc.c b/hw/timer/cadence_ttc.c
index ba584f4719..ba584f4719 100644
--- a/hw/cadence_ttc.c
+++ b/hw/timer/cadence_ttc.c
diff --git a/hw/ds1338.c b/hw/timer/ds1338.c
index ae7ca9f82d..8987cdc9e0 100644
--- a/hw/ds1338.c
+++ b/hw/timer/ds1338.c
@@ -10,7 +10,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 
 /* Size of NVRAM including both the user-accessible area and the
  * secondary register area.
diff --git a/hw/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
index 3cd9476bb1..3cd9476bb1 100644
--- a/hw/etraxfs_timer.c
+++ b/hw/timer/etraxfs_timer.c
diff --git a/hw/exynos4210_mct.c b/hw/timer/exynos4210_mct.c
index 862c96212b..87ce75b643 100644
--- a/hw/exynos4210_mct.c
+++ b/hw/timer/exynos4210_mct.c
@@ -57,7 +57,7 @@
 #include "qemu-common.h"
 #include "hw/ptimer.h"
 
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 
 //#define DEBUG_MCT
 
diff --git a/hw/exynos4210_pwm.c b/hw/timer/exynos4210_pwm.c
index 6d74cd4db5..185ccb9a74 100644
--- a/hw/exynos4210_pwm.c
+++ b/hw/timer/exynos4210_pwm.c
@@ -25,7 +25,7 @@
 #include "qemu-common.h"
 #include "hw/ptimer.h"
 
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 
 //#define DEBUG_PWM
 
diff --git a/hw/exynos4210_rtc.c b/hw/timer/exynos4210_rtc.c
index d170ca755a..bceee44cb2 100644
--- a/hw/exynos4210_rtc.c
+++ b/hw/timer/exynos4210_rtc.c
@@ -34,7 +34,7 @@
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 
-#include "hw/exynos4210.h"
+#include "hw/arm/exynos4210.h"
 
 #define DEBUG_RTC 0
 
diff --git a/hw/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
index 7043a34684..7043a34684 100644
--- a/hw/grlib_gptimer.c
+++ b/hw/timer/grlib_gptimer.c
diff --git a/hw/hpet.c b/hw/timer/hpet.c
index 6bfbf3a68c..95dd01d147 100644
--- a/hw/hpet.c
+++ b/hw/timer/hpet.c
@@ -25,13 +25,13 @@
  */
 
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "ui/console.h"
 #include "qemu/timer.h"
-#include "hw/hpet_emul.h"
+#include "hw/timer/hpet.h"
 #include "hw/sysbus.h"
-#include "hw/mc146818rtc.h"
-#include "hw/i8254.h"
+#include "hw/timer/mc146818rtc.h"
+#include "hw/timer/i8254.h"
 
 //#define HPET_DEBUG
 #ifdef HPET_DEBUG
diff --git a/hw/i8254.c b/hw/timer/i8254.c
index 67bfc6a806..20c0c3601d 100644
--- a/hw/i8254.c
+++ b/hw/timer/i8254.c
@@ -22,11 +22,11 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 #include "qemu/timer.h"
-#include "hw/i8254.h"
-#include "hw/i8254_internal.h"
+#include "hw/timer/i8254.h"
+#include "hw/timer/i8254_internal.h"
 
 //#define DEBUG_PIT
 
diff --git a/hw/i8254_common.c b/hw/timer/i8254_common.c
index c6c0c80c24..5342df4a34 100644
--- a/hw/i8254_common.c
+++ b/hw/timer/i8254_common.c
@@ -23,11 +23,11 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 #include "qemu/timer.h"
-#include "hw/i8254.h"
-#include "hw/i8254_internal.h"
+#include "hw/timer/i8254.h"
+#include "hw/timer/i8254_internal.h"
 
 /* val must be 0 or 1 */
 void pit_set_gate(ISADevice *dev, int channel, int val)
diff --git a/hw/imx_timer.c b/hw/timer/imx_timer.c
index a8c311141e..03197e3f54 100644
--- a/hw/imx_timer.c
+++ b/hw/timer/imx_timer.c
@@ -15,7 +15,7 @@
 #include "qemu/timer.h"
 #include "hw/ptimer.h"
 #include "hw/sysbus.h"
-#include "hw/imx.h"
+#include "hw/arm/imx.h"
 
 //#define DEBUG_TIMER 1
 #ifdef DEBUG_TIMER
diff --git a/hw/lm32_timer.c b/hw/timer/lm32_timer.c
index e06fac7082..e06fac7082 100644
--- a/hw/lm32_timer.c
+++ b/hw/timer/lm32_timer.c
diff --git a/hw/m48t59.c b/hw/timer/m48t59.c
index 39a9d808cd..5019e0632b 100644
--- a/hw/m48t59.c
+++ b/hw/timer/m48t59.c
@@ -22,11 +22,11 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
-#include "hw/nvram.h"
+#include "hw/timer/m48t59.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "hw/sysbus.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "exec/address-spaces.h"
 
 //#define DEBUG_NVRAM
diff --git a/hw/mc146818rtc.c b/hw/timer/mc146818rtc.c
index a2119ad2f1..69e6844ff4 100644
--- a/hw/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -24,11 +24,11 @@
 #include "hw/hw.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
-#include "hw/mc146818rtc.h"
+#include "hw/timer/mc146818rtc.h"
 #include "qapi/visitor.h"
 
 #ifdef TARGET_I386
-#include "hw/apic.h"
+#include "hw/i386/apic.h"
 #endif
 
 //#define DEBUG_CMOS
diff --git a/hw/milkymist-sysctl.c b/hw/timer/milkymist-sysctl.c
index e083a280c4..e083a280c4 100644
--- a/hw/milkymist-sysctl.c
+++ b/hw/timer/milkymist-sysctl.c
diff --git a/hw/omap_gptimer.c b/hw/timer/omap_gptimer.c
index 8485ee84f5..9b0e9dd567 100644
--- a/hw/omap_gptimer.c
+++ b/hw/timer/omap_gptimer.c
@@ -19,7 +19,7 @@
  */
 #include "hw/hw.h"
 #include "qemu/timer.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 
 /* GP timers */
 struct omap_gp_timer_s {
diff --git a/hw/omap_synctimer.c b/hw/timer/omap_synctimer.c
index 13e7280e69..a24f35c277 100644
--- a/hw/omap_synctimer.c
+++ b/hw/timer/omap_synctimer.c
@@ -19,7 +19,7 @@
  */
 #include "hw/hw.h"
 #include "qemu/timer.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 struct omap_synctimer_s {
     MemoryRegion iomem;
     uint32_t val;
diff --git a/hw/pl031.c b/hw/timer/pl031.c
index 764940be7e..764940be7e 100644
--- a/hw/pl031.c
+++ b/hw/timer/pl031.c
diff --git a/hw/puv3_ost.c b/hw/timer/puv3_ost.c
index 10a522adbb..0c3d827978 100644
--- a/hw/puv3_ost.c
+++ b/hw/timer/puv3_ost.c
@@ -12,7 +12,7 @@
 #include "hw/ptimer.h"
 
 #undef DEBUG_PUV3
-#include "hw/puv3.h"
+#include "hw/unicore32/puv3.h"
 
 /* puv3 ostimer implementation. */
 typedef struct {
diff --git a/hw/pxa2xx_timer.c b/hw/timer/pxa2xx_timer.c
index c173fe4c11..8ea2416dd7 100644
--- a/hw/pxa2xx_timer.c
+++ b/hw/timer/pxa2xx_timer.c
@@ -10,7 +10,7 @@
 #include "hw/hw.h"
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
-#include "hw/pxa.h"
+#include "hw/arm/pxa.h"
 #include "hw/sysbus.h"
 
 #define OSMR0	0x00
diff --git a/hw/sh_timer.c b/hw/timer/sh_timer.c
index b4503230a9..f92ff4f73f 100644
--- a/hw/sh_timer.c
+++ b/hw/timer/sh_timer.c
@@ -9,7 +9,7 @@
  */
 
 #include "hw/hw.h"
-#include "hw/sh.h"
+#include "hw/sh4/sh.h"
 #include "qemu/timer.h"
 #include "exec/address-spaces.h"
 #include "hw/ptimer.h"
diff --git a/hw/slavio_timer.c b/hw/timer/slavio_timer.c
index 83f22a0366..1145a87603 100644
--- a/hw/slavio_timer.c
+++ b/hw/timer/slavio_timer.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/sun4m.h"
+#include "hw/sparc/sun4m.h"
 #include "qemu/timer.h"
 #include "hw/ptimer.h"
 #include "hw/sysbus.h"
diff --git a/hw/tusb6010.c b/hw/timer/tusb6010.c
index a5251a34ac..533938a9b4 100644
--- a/hw/tusb6010.c
+++ b/hw/timer/tusb6010.c
@@ -21,9 +21,9 @@
 #include "qemu-common.h"
 #include "qemu/timer.h"
 #include "hw/usb.h"
-#include "hw/omap.h"
+#include "hw/arm/omap.h"
 #include "hw/irq.h"
-#include "hw/devices.h"
+#include "hw/arm/devices.h"
 #include "hw/sysbus.h"
 
 typedef struct TUSBState {
diff --git a/hw/twl92230.c b/hw/timer/twl92230.c
index 7d020c4cba..b730d853f7 100644
--- a/hw/twl92230.c
+++ b/hw/timer/twl92230.c
@@ -21,7 +21,7 @@
 
 #include "hw/hw.h"
 #include "qemu/timer.h"
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 #include "sysemu/sysemu.h"
 #include "ui/console.h"
 
diff --git a/hw/xilinx_timer.c b/hw/timer/xilinx_timer.c
index 0c39cff089..0c39cff089 100644
--- a/hw/xilinx_timer.c
+++ b/hw/timer/xilinx_timer.c
diff --git a/hw/unicore32/puv3.c b/hw/unicore32/puv3.c
index 78ab13f9ed..7c8fc364c8 100644
--- a/hw/unicore32/puv3.c
+++ b/hw/unicore32/puv3.c
@@ -16,10 +16,10 @@
 #include "hw/sysbus.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 
 #undef DEBUG_PUV3
-#include "hw/puv3.h"
+#include "hw/unicore32/puv3.h"
 
 #define KERNEL_LOAD_ADDR        0x03000000
 #define KERNEL_MAX_SIZE         0x00800000 /* Just a guess */
diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs
index e63e287ce0..f9695e7d8a 100644
--- a/hw/usb/Makefile.objs
+++ b/hw/usb/Makefile.objs
@@ -7,6 +7,7 @@ common-obj-$(CONFIG_USB_UHCI) += hcd-uhci.o
 common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o
 common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o hcd-ehci-sysbus.o
 common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o
+common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o
 
 # emulated usb devices
 common-obj-y += dev-hub.o
@@ -21,7 +22,12 @@ common-obj-$(CONFIG_USB_NETWORK)      += dev-network.o
 # FIXME: make configurable too
 CONFIG_USB_BLUETOOTH := y
 common-obj-$(CONFIG_USB_BLUETOOTH)    += dev-bluetooth.o
-common-obj-$(CONFIG_USB_SMARTCARD)    += dev-smartcard-reader.o
+
+ifeq ($(CONFIG_USB_SMARTCARD),y)
+common-obj-y                          += dev-smartcard-reader.o
+common-obj-y                          += ccid-card-passthru.o
+common-obj-$(CONFIG_SMARTCARD_NSS)    += ccid-card-emulated.o
+endif
 
 # usb redirection
 common-obj-$(CONFIG_USB_REDIR) += redirect.o quirks.o
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index e58cd9ade2..b10c290cf4 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -341,8 +341,10 @@ void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
     if (upstream) {
         snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
                  upstream->path, portnr);
+        downstream->hubcount = upstream->hubcount + 1;
     } else {
         snprintf(downstream->path, sizeof(downstream->path), "%d", portnr);
+        downstream->hubcount = 0;
     }
 }
 
diff --git a/hw/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
index c8f8ba3792..29dcd7acbf 100644
--- a/hw/ccid-card-emulated.c
+++ b/hw/usb/ccid-card-emulated.c
@@ -34,7 +34,7 @@
 #include "qemu/thread.h"
 #include "char/char.h"
 #include "monitor/monitor.h"
-#include "hw/ccid.h"
+#include "ccid.h"
 
 #define DPRINTF(card, lvl, fmt, ...) \
 do {\
diff --git a/hw/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index 984bd0bf4c..5e017ae0ca 100644
--- a/hw/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -11,7 +11,7 @@
 #include "char/char.h"
 #include "qemu/sockets.h"
 #include "monitor/monitor.h"
-#include "hw/ccid.h"
+#include "ccid.h"
 #include "libcacard/vscard_common.h"
 
 #define DPRINTF(card, lvl, fmt, ...)                    \
diff --git a/hw/ccid.h b/hw/usb/ccid.h
index 9334da8acd..9334da8acd 100644
--- a/hw/ccid.h
+++ b/hw/usb/ccid.h
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index b8c79b85e9..44fc43f4c4 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -33,7 +33,7 @@
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
 #include "hw/hw.h"
-#include "hw/audiodev.h"
+#include "hw/audio/audio.h"
 #include "audio/audio.h"
 
 #define USBAUDIO_VENDOR_NUM     0x46f4 /* CRC16() of "QEMU" */
diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index 9701048887..b48899d500 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -27,7 +27,7 @@
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
 #include "qemu/timer.h"
-#include "hw/hid.h"
+#include "hw/input/hid.h"
 
 /* HID interface requests */
 #define GET_REPORT   0xa101
@@ -236,7 +236,7 @@ static const USBDescDevice desc_device_tablet2 = {
             .bNumInterfaces        = 1,
             .bConfigurationValue   = 1,
             .iConfiguration        = STR_CONFIG_TABLET,
-            .bmAttributes          = 0xa0,
+            .bmAttributes          = 0x80,
             .bMaxPower             = 50,
             .nif = 1,
             .ifs = &desc_iface_tablet2,
diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
index 504c98c350..0b71abd028 100644
--- a/hw/usb/dev-hub.c
+++ b/hw/usb/dev-hub.c
@@ -25,6 +25,7 @@
 #include "trace.h"
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
+#include "qemu/error-report.h"
 
 #define NUM_PORTS 8
 
@@ -32,6 +33,7 @@ typedef struct USBHubPort {
     USBPort port;
     uint16_t wPortStatus;
     uint16_t wPortChange;
+    uint16_t wPortChange_reported;
 } USBHubPort;
 
 typedef struct USBHubState {
@@ -466,8 +468,11 @@ static void usb_hub_handle_data(USBDevice *dev, USBPacket *p)
             status = 0;
             for(i = 0; i < NUM_PORTS; i++) {
                 port = &s->ports[i];
-                if (port->wPortChange)
+                if (port->wPortChange &&
+                    port->wPortChange_reported != port->wPortChange) {
                     status |= (1 << (i + 1));
+                }
+                port->wPortChange_reported = port->wPortChange;
             }
             if (status != 0) {
                 for(i = 0; i < n; i++) {
@@ -514,6 +519,11 @@ static int usb_hub_initfn(USBDevice *dev)
     USBHubPort *port;
     int i;
 
+    if (dev->port->hubcount == 5) {
+        error_report("usb hub chain too deep");
+        return -1;
+    }
+
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
     s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index caebc1c3ff..db8ce02151 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -40,7 +40,7 @@
 #include "hw/usb/desc.h"
 #include "monitor/monitor.h"
 
-#include "hw/ccid.h"
+#include "ccid.h"
 
 #define DPRINTF(s, lvl, fmt, ...) \
 do { \
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index d3f01aa2a7..06f0171c46 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -12,7 +12,7 @@
 #include "qemu/config-file.h"
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
-#include "hw/scsi.h"
+#include "hw/scsi/scsi.h"
 #include "ui/console.h"
 #include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
@@ -625,7 +625,7 @@ static int usb_msd_initfn_storage(USBDevice *dev)
     usb_desc_init(dev);
     scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage);
     scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable,
-                                            s->conf.bootindex);
+                                            s->conf.bootindex, s->serial);
     if (!scsi_dev) {
         return -1;
     }
diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index 1ac5117ba7..c8c42eefb5 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -16,8 +16,8 @@
 
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
-#include "hw/scsi.h"
-#include "hw/scsi-defs.h"
+#include "hw/scsi/scsi.h"
+#include "block/scsi.h"
 
 /* --------------------------------------------------------------------- */
 
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 5aa342bda5..efd4b0dbde 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -452,7 +452,6 @@ struct XHCIState {
     MemoryRegion mem_oper;
     MemoryRegion mem_runtime;
     MemoryRegion mem_doorbell;
-    const char *name;
     unsigned int devaddr;
 
     /* properties */
@@ -1172,8 +1171,6 @@ static void xhci_set_ep_state(XHCIState *xhci, XHCIEPContext *epctx,
     uint32_t ctx[5];
     uint32_t ctx2[2];
 
-    fprintf(stderr, "%s: epid %d, state %d\n",
-            __func__, epctx->epid, state);
     xhci_dma_read_u32s(xhci, epctx->pctx, ctx, sizeof(ctx));
     ctx[0] &= ~EP_STATE_MASK;
     ctx[0] |= state;
@@ -2568,7 +2565,7 @@ static void xhci_process_commands(XHCIState *xhci)
         }
         break;
         default:
-            fprintf(stderr, "xhci: unimplemented command %d\n", type);
+            trace_usb_xhci_unimplemented("command", type);
             event.ccode = CC_TRB_ERROR;
             break;
         }
@@ -2767,7 +2764,7 @@ static uint64_t xhci_cap_read(void *ptr, hwaddr reg, unsigned size)
         ret = 0x00000000; /* reserved */
         break;
     default:
-        fprintf(stderr, "xhci_cap_read: reg %d unimplemented\n", (int)reg);
+        trace_usb_xhci_unimplemented("cap read", reg);
         ret = 0;
     }
 
@@ -2790,8 +2787,7 @@ static uint64_t xhci_port_read(void *ptr, hwaddr reg, unsigned size)
         break;
     case 0x0c: /* reserved */
     default:
-        fprintf(stderr, "xhci_port_read (port %d): reg 0x%x unimplemented\n",
-                port->portnr, (uint32_t)reg);
+        trace_usb_xhci_unimplemented("port read", reg);
         ret = 0;
     }
 
@@ -2831,8 +2827,7 @@ static void xhci_port_write(void *ptr, hwaddr reg,
     case 0x04: /* PORTPMSC */
     case 0x08: /* PORTLI */
     default:
-        fprintf(stderr, "xhci_port_write (port %d): reg 0x%x unimplemented\n",
-                port->portnr, (uint32_t)reg);
+        trace_usb_xhci_unimplemented("port write", reg);
     }
 }
 
@@ -2870,7 +2865,7 @@ static uint64_t xhci_oper_read(void *ptr, hwaddr reg, unsigned size)
         ret = xhci->config;
         break;
     default:
-        fprintf(stderr, "xhci_oper_read: reg 0x%x unimplemented\n", (int)reg);
+        trace_usb_xhci_unimplemented("oper read", reg);
         ret = 0;
     }
 
@@ -2935,7 +2930,7 @@ static void xhci_oper_write(void *ptr, hwaddr reg,
         xhci->config = val & 0xff;
         break;
     default:
-        fprintf(stderr, "xhci_oper_write: reg 0x%x unimplemented\n", (int)reg);
+        trace_usb_xhci_unimplemented("oper write", reg);
     }
 }
 
@@ -2951,8 +2946,7 @@ static uint64_t xhci_runtime_read(void *ptr, hwaddr reg,
             ret = xhci_mfindex_get(xhci) & 0x3fff;
             break;
         default:
-            fprintf(stderr, "xhci_runtime_read: reg 0x%x unimplemented\n",
-                    (int)reg);
+            trace_usb_xhci_unimplemented("runtime read", reg);
             break;
         }
     } else {
@@ -2996,7 +2990,7 @@ static void xhci_runtime_write(void *ptr, hwaddr reg,
     trace_usb_xhci_runtime_write(reg, val);
 
     if (reg < 0x20) {
-        fprintf(stderr, "%s: reg 0x%x unimplemented\n", __func__, (int)reg);
+        trace_usb_xhci_unimplemented("runtime write", reg);
         return;
     }
 
@@ -3038,8 +3032,7 @@ static void xhci_runtime_write(void *ptr, hwaddr reg,
         xhci_events_update(xhci, v);
         break;
     default:
-        fprintf(stderr, "xhci_oper_write: reg 0x%x unimplemented\n",
-                (int)reg);
+        trace_usb_xhci_unimplemented("oper write", reg);
     }
 }
 
@@ -3290,6 +3283,9 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
     if (xhci->numintrs > MAXINTRS) {
         xhci->numintrs = MAXINTRS;
     }
+    while (xhci->numintrs & (xhci->numintrs - 1)) {   /* ! power of 2 */
+        xhci->numintrs++;
+    }
     if (xhci->numintrs < 1) {
         xhci->numintrs = 1;
     }
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index d02a7b94c4..0ddb0818d8 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -104,6 +104,8 @@ struct USBRedirDevice {
     /* Data passed from chardev the fd_read cb to the usbredirparser read cb */
     const uint8_t *read_buf;
     int read_buf_size;
+    /* Active chardev-watch-tag */
+    guint watch;
     /* For async handling of close */
     QEMUBH *chardev_close_bh;
     /* To delay the usb attach in case of quick chardev close + open */
@@ -254,9 +256,21 @@ static int usbredir_read(void *priv, uint8_t *data, int count)
     return count;
 }
 
+static gboolean usbredir_write_unblocked(GIOChannel *chan, GIOCondition cond,
+                                         void *opaque)
+{
+    USBRedirDevice *dev = opaque;
+
+    dev->watch = 0;
+    usbredirparser_do_write(dev->parser);
+
+    return FALSE;
+}
+
 static int usbredir_write(void *priv, uint8_t *data, int count)
 {
     USBRedirDevice *dev = priv;
+    int r;
 
     if (!dev->cs->be_open) {
         return 0;
@@ -267,7 +281,17 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
         return 0;
     }
 
-    return qemu_chr_fe_write(dev->cs, data, count);
+    r = qemu_chr_fe_write(dev->cs, data, count);
+    if (r < count) {
+        if (!dev->watch) {
+            dev->watch = qemu_chr_fe_add_watch(dev->cs, G_IO_OUT,
+                                               usbredir_write_unblocked, dev);
+        }
+        if (r < 0) {
+            r = 0;
+        }
+    }
+    return r;
 }
 
 /*
@@ -1085,6 +1109,10 @@ static void usbredir_chardev_close_bh(void *opaque)
         usbredirparser_destroy(dev->parser);
         dev->parser = NULL;
     }
+    if (dev->watch) {
+        g_source_remove(dev->watch);
+        dev->watch = 0;
+    }
 }
 
 static void usbredir_create_parser(USBRedirDevice *dev)
@@ -1317,6 +1345,9 @@ static void usbredir_handle_destroy(USBDevice *udev)
     if (dev->parser) {
         usbredirparser_destroy(dev->parser);
     }
+    if (dev->watch) {
+        g_source_remove(dev->watch);
+    }
 
     free(dev->filter_rules);
 }
@@ -1973,6 +2004,10 @@ static int usbredir_post_load(void *priv, int version_id)
 {
     USBRedirDevice *dev = priv;
 
+    if (dev->parser == NULL) {
+        return 0;
+    }
+
     switch (dev->device_info.speed) {
     case usb_redir_speed_low:
         dev->dev.speed = USB_SPEED_LOW;
diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
new file mode 100644
index 0000000000..c7e801344b
--- /dev/null
+++ b/hw/virtio/Makefile.objs
@@ -0,0 +1,7 @@
+common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
+common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
+common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
+common-obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += dataplane/
+
+obj-$(CONFIG_VIRTIO) += virtio.o virtio-balloon.o 
+obj-$(CONFIG_VHOST_NET) += vhost.o
diff --git a/hw/virtio/dataplane/Makefile.objs b/hw/virtio/dataplane/Makefile.objs
new file mode 100644
index 0000000000..a91bf33c8b
--- /dev/null
+++ b/hw/virtio/dataplane/Makefile.objs
@@ -0,0 +1 @@
+common-obj-y += hostmem.o vring.o
diff --git a/hw/dataplane/hostmem.c b/hw/virtio/dataplane/hostmem.c
index 380537e06d..37292ffd00 100644
--- a/hw/dataplane/hostmem.c
+++ b/hw/virtio/dataplane/hostmem.c
@@ -12,7 +12,7 @@
  */
 
 #include "exec/address-spaces.h"
-#include "hostmem.h"
+#include "hw/virtio/dataplane/hostmem.h"
 
 static int hostmem_lookup_cmp(const void *phys_, const void *region_)
 {
diff --git a/hw/dataplane/vring.c b/hw/virtio/dataplane/vring.c
index e3b225315f..e0d6e83625 100644
--- a/hw/dataplane/vring.c
+++ b/hw/virtio/dataplane/vring.c
@@ -15,7 +15,7 @@
  */
 
 #include "trace.h"
-#include "vring.h"
+#include "hw/virtio/dataplane/vring.h"
 #include "qemu/error-report.h"
 
 /* Map the guest's vring to host memory */
diff --git a/hw/vhost.c b/hw/virtio/vhost.c
index 4d6aee3ecd..636fad0f74 100644
--- a/hw/vhost.c
+++ b/hw/virtio/vhost.c
@@ -14,7 +14,7 @@
  */
 
 #include <sys/ioctl.h>
-#include "hw/vhost.h"
+#include "hw/virtio/vhost.h"
 #include "hw/hw.h"
 #include "qemu/range.h"
 #include <linux/vhost.h>
diff --git a/hw/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index b382bd440d..c2c446eb9b 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -16,11 +16,11 @@
 #include "qemu/iov.h"
 #include "qemu/timer.h"
 #include "qemu-common.h"
-#include "hw/virtio.h"
-#include "hw/pc.h"
+#include "hw/virtio/virtio.h"
+#include "hw/i386/pc.h"
 #include "cpu.h"
 #include "sysemu/balloon.h"
-#include "hw/virtio-balloon.h"
+#include "hw/virtio/virtio-balloon.h"
 #include "sysemu/kvm.h"
 #include "exec/address-spaces.h"
 #include "qapi/visitor.h"
@@ -29,7 +29,7 @@
 #include <sys/mman.h>
 #endif
 
-#include "hw/virtio-bus.h"
+#include "hw/virtio/virtio-bus.h"
 
 static void balloon_page(void *addr, int deflate)
 {
diff --git a/hw/virtio-bus.c b/hw/virtio/virtio-bus.c
index 6c2aab00eb..1596a1c92f 100644
--- a/hw/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -25,8 +25,8 @@
 #include "hw/hw.h"
 #include "qemu/error-report.h"
 #include "hw/qdev.h"
-#include "hw/virtio-bus.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio.h"
 
 /* #define DEBUG_VIRTIO_BUS */
 
diff --git a/hw/virtio-pci.c b/hw/virtio/virtio-pci.c
index fb20722eaa..2b22588093 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -17,12 +17,12 @@
 
 #include <inttypes.h>
 
-#include "hw/virtio.h"
-#include "hw/virtio-blk.h"
-#include "hw/virtio-net.h"
-#include "hw/virtio-serial.h"
-#include "hw/virtio-scsi.h"
-#include "hw/virtio-balloon.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-blk.h"
+#include "hw/virtio/virtio-net.h"
+#include "hw/virtio/virtio-serial.h"
+#include "hw/virtio/virtio-scsi.h"
+#include "hw/virtio/virtio-balloon.h"
 #include "hw/pci/pci.h"
 #include "qemu/error-report.h"
 #include "hw/pci/msi.h"
@@ -30,9 +30,9 @@
 #include "hw/loader.h"
 #include "sysemu/kvm.h"
 #include "sysemu/blockdev.h"
-#include "hw/virtio-pci.h"
+#include "virtio-pci.h"
 #include "qemu/range.h"
-#include "hw/virtio-bus.h"
+#include "hw/virtio/virtio-bus.h"
 
 /* from Linux's linux/virtio_pci.h */
 
diff --git a/hw/virtio-pci.h b/hw/virtio/virtio-pci.h
index f99f2eb80e..fb83155016 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -16,14 +16,14 @@
 #define QEMU_VIRTIO_PCI_H
 
 #include "hw/pci/msi.h"
-#include "hw/virtio-blk.h"
-#include "hw/virtio-net.h"
-#include "hw/virtio-rng.h"
-#include "hw/virtio-serial.h"
-#include "hw/virtio-scsi.h"
-#include "hw/virtio-balloon.h"
-#include "hw/virtio-bus.h"
-#include "hw/9pfs/virtio-9p-device.h"
+#include "hw/virtio/virtio-blk.h"
+#include "hw/virtio/virtio-net.h"
+#include "hw/virtio/virtio-rng.h"
+#include "hw/virtio/virtio-serial.h"
+#include "hw/virtio/virtio-scsi.h"
+#include "hw/virtio/virtio-balloon.h"
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-9p.h"
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
diff --git a/hw/virtio-rng.c b/hw/virtio/virtio-rng.c
index fa8e8f3f9a..6079b2a3a9 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -12,8 +12,8 @@
 #include "qemu/iov.h"
 #include "hw/qdev.h"
 #include "qapi/qmp/qerror.h"
-#include "hw/virtio.h"
-#include "hw/virtio-rng.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-rng.h"
 #include "qemu/rng.h"
 
 static bool is_guest_ready(VirtIORNG *vrng)
diff --git a/hw/virtio.c b/hw/virtio/virtio.c
index 26fbc790ec..1c2282c54f 100644
--- a/hw/virtio.c
+++ b/hw/virtio/virtio.c
@@ -15,9 +15,9 @@
 
 #include "trace.h"
 #include "qemu/error-report.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "qemu/atomic.h"
-#include "hw/virtio-bus.h"
+#include "hw/virtio/virtio-bus.h"
 
 /* The alignment to use between consumer and producer parts of vring.
  * x86 pagesize again. */
diff --git a/hw/watchdog/Makefile.objs b/hw/watchdog/Makefile.objs
new file mode 100644
index 0000000000..4b0374a555
--- /dev/null
+++ b/hw/watchdog/Makefile.objs
@@ -0,0 +1,3 @@
+common-obj-y += watchdog.o
+common-obj-$(CONFIG_WDT_IB6300ESB) += wdt_i6300esb.o
+common-obj-$(CONFIG_WDT_IB700) += wdt_ib700.o
diff --git a/hw/watchdog.c b/hw/watchdog/watchdog.c
index 072d256882..cb4e1f9e47 100644
--- a/hw/watchdog.c
+++ b/hw/watchdog/watchdog.c
@@ -26,7 +26,7 @@
 #include "qapi/qmp/types.h"
 #include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
-#include "hw/watchdog.h"
+#include "sysemu/watchdog.h"
 
 /* Possible values for action parameter. */
 #define WDT_RESET        1	/* Hard reset. */
diff --git a/hw/wdt_i6300esb.c b/hw/watchdog/wdt_i6300esb.c
index f13e507fcf..1407fbadb2 100644
--- a/hw/wdt_i6300esb.c
+++ b/hw/watchdog/wdt_i6300esb.c
@@ -23,7 +23,7 @@
 
 #include "qemu-common.h"
 #include "qemu/timer.h"
-#include "hw/watchdog.h"
+#include "sysemu/watchdog.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 
diff --git a/hw/wdt_ib700.c b/hw/watchdog/wdt_ib700.c
index 6c52808ac0..b8c4be85ff 100644
--- a/hw/wdt_ib700.c
+++ b/hw/watchdog/wdt_ib700.c
@@ -21,10 +21,10 @@
 
 #include "qemu-common.h"
 #include "qemu/timer.h"
-#include "hw/watchdog.h"
+#include "sysemu/watchdog.h"
 #include "hw/hw.h"
-#include "hw/isa.h"
-#include "hw/pc.h"
+#include "hw/isa/isa.h"
+#include "hw/i386/pc.h"
 
 /*#define IB700_DEBUG 1*/
 
diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs
new file mode 100644
index 0000000000..20175602b6
--- /dev/null
+++ b/hw/xen/Makefile.objs
@@ -0,0 +1,6 @@
+# xen backend driver support
+common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
+
+obj-$(CONFIG_XEN_I386) += xen_platform.o xen_apic.o
+obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
+obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
diff --git a/hw/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
index ff2e876b3d..743b37b991 100644
--- a/hw/xen-host-pci-device.c
+++ b/hw/xen/xen-host-pci-device.c
@@ -7,7 +7,7 @@
  */
 
 #include "qemu-common.h"
-#include "hw/xen-host-pci-device.h"
+#include "xen-host-pci-device.h"
 
 #define XEN_HOST_PCI_MAX_EXT_CAP \
     ((PCIE_CONFIG_SPACE_SIZE - PCI_CONFIG_SPACE_SIZE) / (PCI_CAP_SIZEOF + 4))
diff --git a/hw/xen-host-pci-device.h b/hw/xen/xen-host-pci-device.h
index c2486f0c19..c2486f0c19 100644
--- a/hw/xen-host-pci-device.h
+++ b/hw/xen/xen-host-pci-device.h
diff --git a/hw/xen_apic.c b/hw/xen/xen_apic.c
index 8f387b6403..a2eb8a159a 100644
--- a/hw/xen_apic.c
+++ b/hw/xen/xen_apic.c
@@ -9,9 +9,9 @@
  * This work is licensed under the terms of the GNU GPL version 2 or
  * later. See the COPYING file in the top-level directory.
  */
-#include "hw/apic_internal.h"
+#include "hw/i386/apic_internal.h"
 #include "hw/pci/msi.h"
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 
 static uint64_t xen_apic_mem_read(void *opaque, hwaddr addr,
                                   unsigned size)
diff --git a/hw/xen_backend.c b/hw/xen/xen_backend.c
index 24381b55e5..2a8c9f5d1a 100644
--- a/hw/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -37,7 +37,7 @@
 #include "hw/hw.h"
 #include "char/char.h"
 #include "qemu/log.h"
-#include "hw/xen_backend.h"
+#include "hw/xen/xen_backend.h"
 
 #include <xen/grant_table.h>
 
@@ -85,12 +85,20 @@ char *xenstore_read_str(const char *base, const char *node)
 
 int xenstore_write_int(const char *base, const char *node, int ival)
 {
-    char val[32];
+    char val[12];
 
     snprintf(val, sizeof(val), "%d", ival);
     return xenstore_write_str(base, node, val);
 }
 
+int xenstore_write_int64(const char *base, const char *node, int64_t ival)
+{
+    char val[21];
+
+    snprintf(val, sizeof(val), "%"PRId64, ival);
+    return xenstore_write_str(base, node, val);
+}
+
 int xenstore_read_int(const char *base, const char *node, int *ival)
 {
     char *val;
@@ -114,6 +122,11 @@ int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival)
     return xenstore_write_int(xendev->be, node, ival);
 }
 
+int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, int64_t ival)
+{
+    return xenstore_write_int64(xendev->be, node, ival);
+}
+
 char *xenstore_read_be_str(struct XenDevice *xendev, const char *node)
 {
     return xenstore_read_str(xendev->be, node);
diff --git a/hw/xen_devconfig.c b/hw/xen/xen_devconfig.c
index cdcaf62f26..fa998eff04 100644
--- a/hw/xen_devconfig.c
+++ b/hw/xen/xen_devconfig.c
@@ -1,4 +1,4 @@
-#include "hw/xen_backend.h"
+#include "hw/xen/xen_backend.h"
 #include "sysemu/blockdev.h"
 
 /* ------------------------------------------------------------- */
diff --git a/hw/xen_platform.c b/hw/xen/xen_platform.c
index 5e11c950ab..b6c6793e1e 100644
--- a/hw/xen_platform.c
+++ b/hw/xen/xen_platform.c
@@ -26,11 +26,11 @@
 #include <assert.h>
 
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
 #include "hw/irq.h"
-#include "hw/xen_common.h"
-#include "hw/xen_backend.h"
+#include "hw/xen/xen_common.h"
+#include "hw/xen/xen_backend.h"
 #include "trace.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/xen_pt.c b/hw/xen/xen_pt.c
index ce695d0e64..c199818dc6 100644
--- a/hw/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -55,9 +55,9 @@
 #include <sys/ioctl.h>
 
 #include "hw/pci/pci.h"
-#include "hw/xen.h"
-#include "hw/xen_backend.h"
-#include "hw/xen_pt.h"
+#include "hw/xen/xen.h"
+#include "hw/xen/xen_backend.h"
+#include "xen_pt.h"
 #include "qemu/range.h"
 #include "exec/address-spaces.h"
 
diff --git a/hw/xen_pt.h b/hw/xen/xen_pt.h
index 1cd9f44704..942dc60cc7 100644
--- a/hw/xen_pt.h
+++ b/hw/xen/xen_pt.h
@@ -2,9 +2,9 @@
 #define XEN_PT_H
 
 #include "qemu-common.h"
-#include "hw/xen_common.h"
+#include "hw/xen/xen_common.h"
 #include "hw/pci/pci.h"
-#include "hw/xen-host-pci-device.h"
+#include "xen-host-pci-device.h"
 
 void xen_pt_log(const PCIDevice *d, const char *f, ...) GCC_FMT_ATTR(2, 3);
 
diff --git a/hw/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c
index 55838216d9..01872db5b7 100644
--- a/hw/xen_pt_config_init.c
+++ b/hw/xen/xen_pt_config_init.c
@@ -13,8 +13,8 @@
  */
 
 #include "qemu/timer.h"
-#include "hw/xen_backend.h"
-#include "hw/xen_pt.h"
+#include "hw/xen/xen_backend.h"
+#include "xen_pt.h"
 
 #define XEN_PT_MERGE_VALUE(value, data, val_mask) \
     (((value) & (val_mask)) | ((data) & ~(val_mask)))
diff --git a/hw/xen_pt_msi.c b/hw/xen/xen_pt_msi.c
index a54ee2bfd9..db2c84237f 100644
--- a/hw/xen_pt_msi.c
+++ b/hw/xen/xen_pt_msi.c
@@ -11,9 +11,9 @@
 
 #include <sys/mman.h>
 
-#include "hw/xen_backend.h"
-#include "hw/xen_pt.h"
-#include "hw/apic-msidef.h"
+#include "hw/xen/xen_backend.h"
+#include "xen_pt.h"
+#include "hw/i386/apic-msidef.h"
 
 
 #define XEN_PT_AUTO_ASSIGN -1
diff --git a/hw/xtensa_bootparam.h b/hw/xtensa/xtensa_bootparam.h
index 38ef32bdb6..38ef32bdb6 100644
--- a/hw/xtensa_bootparam.h
+++ b/hw/xtensa/xtensa_bootparam.h
diff --git a/hw/xtensa/xtensa_lx60.c b/hw/xtensa/xtensa_lx60.c
index f2a63d82da..2682eda2ad 100644
--- a/hw/xtensa/xtensa_lx60.c
+++ b/hw/xtensa/xtensa_lx60.c
@@ -31,13 +31,13 @@
 #include "elf.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
-#include "hw/serial.h"
+#include "hw/char/serial.h"
 #include "net/net.h"
 #include "hw/sysbus.h"
-#include "hw/flash.h"
+#include "hw/block/flash.h"
 #include "sysemu/blockdev.h"
 #include "char/char.h"
-#include "hw/xtensa_bootparam.h"
+#include "xtensa_bootparam.h"
 
 typedef struct LxBoardDesc {
     size_t flash_size;
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 0986a2d6ac..9aa98b5d12 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -252,11 +252,10 @@ struct BlockDriverState {
     unsigned int copy_on_read_in_flight;
 
     /* the time for latest disk I/O */
-    int64_t slice_time;
     int64_t slice_start;
     int64_t slice_end;
     BlockIOLimit io_limits;
-    BlockIOBaseValue  io_base;
+    BlockIOBaseValue slice_submitted;
     CoQueue      throttled_reqs;
     QEMUTimer    *block_timer;
     bool         io_limits_enabled;
diff --git a/hw/scsi-defs.h b/include/block/scsi.h
index 9ab045b613..9ab045b613 100644
--- a/hw/scsi-defs.h
+++ b/include/block/scsi.h
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index 1da240039d..977467bb57 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -20,7 +20,7 @@
 #define MEMORY_INTERNAL_H
 
 #ifndef CONFIG_USER_ONLY
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 
 typedef struct PhysPageEntry PhysPageEntry;
 
diff --git a/hw/acpi.h b/include/hw/acpi/acpi.h
index e18ef28fd3..e18ef28fd3 100644
--- a/hw/acpi.h
+++ b/include/hw/acpi/acpi.h
diff --git a/hw/acpi_ich9.h b/include/hw/acpi/ich9.h
index 91c3aeb7ea..85b82ee50c 100644
--- a/hw/acpi_ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -21,7 +21,7 @@
 #ifndef HW_ACPI_ICH9_H
 #define HW_ACPI_ICH9_H
 
-#include "hw/acpi.h"
+#include "hw/acpi/acpi.h"
 
 typedef struct ICH9LPCPMRegs {
     /*
diff --git a/hw/arm-misc.h b/include/hw/arm.h
index 7b2b02daaf..7b2b02daaf 100644
--- a/hw/arm-misc.h
+++ b/include/hw/arm.h
diff --git a/hw/devices.h b/include/hw/arm/devices.h
index c60bcabae3..c60bcabae3 100644
--- a/hw/devices.h
+++ b/include/hw/arm/devices.h
diff --git a/hw/exynos4210.h b/include/hw/arm/exynos4210.h
index bb9a1dddc8..bb9a1dddc8 100644
--- a/hw/exynos4210.h
+++ b/include/hw/arm/exynos4210.h
diff --git a/hw/imx.h b/include/hw/arm/imx.h
index ea9e093277..ea9e093277 100644
--- a/hw/imx.h
+++ b/include/hw/arm/imx.h
diff --git a/hw/omap.h b/include/hw/arm/omap.h
index 188cda8771..188cda8771 100644
--- a/hw/omap.h
+++ b/include/hw/arm/omap.h
diff --git a/hw/primecell.h b/include/hw/arm/primecell.h
index 7337c3b3ca..7337c3b3ca 100644
--- a/hw/primecell.h
+++ b/include/hw/arm/primecell.h
diff --git a/hw/pxa.h b/include/hw/arm/pxa.h
index 668232cead..668232cead 100644
--- a/hw/pxa.h
+++ b/include/hw/arm/pxa.h
diff --git a/hw/sharpsl.h b/include/hw/arm/sharpsl.h
index 13981a6d03..13981a6d03 100644
--- a/hw/sharpsl.h
+++ b/include/hw/arm/sharpsl.h
diff --git a/hw/soc_dma.h b/include/hw/arm/soc_dma.h
index 7379731afd..7379731afd 100644
--- a/hw/soc_dma.h
+++ b/include/hw/arm/soc_dma.h
diff --git a/hw/audiodev.h b/include/hw/audio/audio.h
index 428274f929..428274f929 100644
--- a/hw/audiodev.h
+++ b/include/hw/audio/audio.h
diff --git a/hw/pcspk.h b/include/hw/audio/pcspk.h
index f448d221da..ce8ef4f9ea 100644
--- a/hw/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -26,7 +26,7 @@
 #define HW_PCSPK_H
 
 #include "hw/hw.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
 {
diff --git a/hw/block-common.h b/include/hw/block/block.h
index dd115320c9..dd115320c9 100644
--- a/hw/block-common.h
+++ b/include/hw/block/block.h
diff --git a/hw/fdc.h b/include/hw/block/fdc.h
index a8f6f7c850..a8f6f7c850 100644
--- a/hw/fdc.h
+++ b/include/hw/block/fdc.h
diff --git a/hw/flash.h b/include/hw/block/flash.h
index 920d7596e3..920d7596e3 100644
--- a/hw/flash.h
+++ b/include/hw/block/flash.h
diff --git a/hw/boards.h b/include/hw/boards.h
index 425bdc74a8..425bdc74a8 100644
--- a/hw/boards.h
+++ b/include/hw/boards.h
diff --git a/hw/bt.h b/include/hw/bt.h
index 830af94735..830af94735 100644
--- a/hw/bt.h
+++ b/include/hw/bt.h
diff --git a/hw/escc.h b/include/hw/char/escc.h
index bda3213317..bda3213317 100644
--- a/hw/escc.h
+++ b/include/hw/char/escc.h
diff --git a/hw/serial.h b/include/hw/char/serial.h
index e884499607..e884499607 100644
--- a/hw/serial.h
+++ b/include/hw/char/serial.h
diff --git a/hw/etraxfs.h b/include/hw/cris/etraxfs.h
index 0df4fdd2e9..ab30559c79 100644
--- a/hw/etraxfs.h
+++ b/include/hw/cris/etraxfs.h
@@ -26,7 +26,7 @@
 #define HW_EXTRAXFS_H 1
 
 #include "net/net.h"
-#include "hw/etraxfs_dma.h"
+#include "hw/cris/etraxfs_dma.h"
 
 qemu_irq *cris_pic_init_cpu(CPUCRISState *env);
 
diff --git a/hw/etraxfs_dma.h b/include/hw/cris/etraxfs_dma.h
index 38104a67b5..38104a67b5 100644
--- a/hw/etraxfs_dma.h
+++ b/include/hw/cris/etraxfs_dma.h
diff --git a/hw/elf_ops.h b/include/hw/elf_ops.h
index acc701e3a4..acc701e3a4 100644
--- a/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
diff --git a/hw/empty_slot.h b/include/hw/empty_slot.h
index 6079602cdf..6079602cdf 100644
--- a/hw/empty_slot.h
+++ b/include/hw/empty_slot.h
diff --git a/hw/hw.h b/include/hw/hw.h
index 1fb9afa322..1fb9afa322 100644
--- a/hw/hw.h
+++ b/include/hw/hw.h
diff --git a/hw/i2c.h b/include/hw/i2c/i2c.h
index 461392f374..461392f374 100644
--- a/hw/i2c.h
+++ b/include/hw/i2c/i2c.h
diff --git a/hw/pm_smbus.h b/include/hw/i2c/pm_smbus.h
index e3069bf7d4..e3069bf7d4 100644
--- a/hw/pm_smbus.h
+++ b/include/hw/i2c/pm_smbus.h
diff --git a/hw/smbus.h b/include/hw/i2c/smbus.h
index c3db620e00..d764d759c4 100644
--- a/hw/smbus.h
+++ b/include/hw/i2c/smbus.h
@@ -25,7 +25,7 @@
  * THE SOFTWARE.
  */
 
-#include "hw/i2c.h"
+#include "hw/i2c/i2c.h"
 
 #define TYPE_SMBUS_DEVICE "smbus-device"
 #define SMBUS_DEVICE(obj) \
diff --git a/hw/apic-msidef.h b/include/hw/i386/apic-msidef.h
index 6e2eb71f2f..6e2eb71f2f 100644
--- a/hw/apic-msidef.h
+++ b/include/hw/i386/apic-msidef.h
diff --git a/hw/apic.h b/include/hw/i386/apic.h
index 1d48e027c3..1d48e027c3 100644
--- a/hw/apic.h
+++ b/include/hw/i386/apic.h
diff --git a/hw/apic_internal.h b/include/hw/i386/apic_internal.h
index 578241f861..578241f861 100644
--- a/hw/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
diff --git a/hw/ich9.h b/include/hw/i386/ich9.h
index e7d2df7280..51d59819ab 100644
--- a/hw/ich9.h
+++ b/include/hw/i386/ich9.h
@@ -3,17 +3,16 @@
 
 #include "hw/hw.h"
 #include "qemu/range.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/sysbus.h"
-#include "hw/pc.h"
-#include "hw/apm.h"
-#include "hw/ioapic.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/apm.h"
+#include "hw/i386/ioapic.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci_bridge.h"
-#include "hw/acpi.h"
-#include "hw/acpi_ich9.h"
-#include "hw/pam.h"
+#include "hw/acpi/acpi.h"
+#include "hw/acpi/ich9.h"
 #include "hw/pci/pci_bus.h"
 
 void ich9_lpc_set_irq(void *opaque, int irq_num, int level);
diff --git a/hw/ioapic.h b/include/hw/i386/ioapic.h
index 86e63dac74..86e63dac74 100644
--- a/hw/ioapic.h
+++ b/include/hw/i386/ioapic.h
diff --git a/hw/ioapic_internal.h b/include/hw/i386/ioapic_internal.h
index 25576c819e..25576c819e 100644
--- a/hw/ioapic_internal.h
+++ b/include/hw/i386/ioapic_internal.h
diff --git a/hw/pc.h b/include/hw/i386/pc.h
index 55964ced93..5d40914f49 100644
--- a/hw/pc.h
+++ b/include/hw/i386/pc.h
@@ -4,11 +4,11 @@
 #include "qemu-common.h"
 #include "exec/memory.h"
 #include "exec/ioport.h"
-#include "hw/isa.h"
-#include "hw/fdc.h"
+#include "hw/isa/isa.h"
+#include "hw/block/fdc.h"
 #include "net/net.h"
 #include "exec/memory.h"
-#include "hw/ioapic.h"
+#include "hw/i386/ioapic.h"
 
 /* PC-style peripherals (also used by other machines).  */
 
diff --git a/hw/smbios.h b/include/hw/i386/smbios.h
index 94e3641f9a..94e3641f9a 100644
--- a/hw/smbios.h
+++ b/include/hw/i386/smbios.h
diff --git a/hw/ide.h b/include/hw/ide.h
index 35444a39f9..507e6d33cb 100644
--- a/hw/ide.h
+++ b/include/hw/ide.h
@@ -1,7 +1,7 @@
 #ifndef HW_IDE_H
 #define HW_IDE_H
 
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/pci/pci.h"
 #include "exec/memory.h"
 
diff --git a/hw/adb.h b/include/hw/input/adb.h
index bdfccd4041..bdfccd4041 100644
--- a/hw/adb.h
+++ b/include/hw/input/adb.h
diff --git a/hw/hid.h b/include/hw/input/hid.h
index 56c71ed5ae..56c71ed5ae 100644
--- a/hw/hid.h
+++ b/include/hw/input/hid.h
diff --git a/hw/ps2.h b/include/hw/input/ps2.h
index 7c45ce7ced..7c45ce7ced 100644
--- a/hw/ps2.h
+++ b/include/hw/input/ps2.h
diff --git a/hw/irq.h b/include/hw/irq.h
index 610e6b7623..610e6b7623 100644
--- a/hw/irq.h
+++ b/include/hw/irq.h
diff --git a/hw/apm.h b/include/hw/isa/apm.h
index 3edea5f623..3edea5f623 100644
--- a/hw/apm.h
+++ b/include/hw/isa/apm.h
diff --git a/hw/i8259_internal.h b/include/hw/isa/i8259_internal.h
index 2813ec1baa..d3ddb27f4f 100644
--- a/hw/i8259_internal.h
+++ b/include/hw/isa/i8259_internal.h
@@ -26,8 +26,8 @@
 #define QEMU_I8259_INTERNAL_H
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 
 typedef struct PICCommonState PICCommonState;
 
diff --git a/hw/isa.h b/include/hw/isa/isa.h
index 82da37c11d..82da37c11d 100644
--- a/hw/isa.h
+++ b/include/hw/isa/isa.h
diff --git a/hw/pc87312.h b/include/hw/isa/pc87312.h
index ad087c73e5..befc8bdc62 100644
--- a/hw/pc87312.h
+++ b/include/hw/isa/pc87312.h
@@ -25,7 +25,7 @@
 #ifndef QEMU_PC87312_H
 #define QEMU_PC87312_H
 
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 
 #define TYPE_PC87312 "pc87312"
diff --git a/hw/vt82c686.h b/include/hw/isa/vt82c686.h
index 6ef876d260..6ef876d260 100644
--- a/hw/vt82c686.h
+++ b/include/hw/isa/vt82c686.h
diff --git a/hw/kvm/clock.h b/include/hw/kvm/clock.h
index 252ea13461..252ea13461 100644
--- a/hw/kvm/clock.h
+++ b/include/hw/kvm/clock.h
diff --git a/hw/lm32_juart.h b/include/hw/lm32/lm32_juart.h
index 67fc5866ea..67fc5866ea 100644
--- a/hw/lm32_juart.h
+++ b/include/hw/lm32/lm32_juart.h
diff --git a/hw/lm32_pic.h b/include/hw/lm32/lm32_pic.h
index 555680304e..555680304e 100644
--- a/hw/lm32_pic.h
+++ b/include/hw/lm32/lm32_pic.h
diff --git a/hw/loader.h b/include/hw/loader.h
index 0958f06934..0958f06934 100644
--- a/hw/loader.h
+++ b/include/hw/loader.h
diff --git a/hw/mcf.h b/include/hw/m68k/mcf.h
index fbc8dc26df..fbc8dc26df 100644
--- a/hw/mcf.h
+++ b/include/hw/m68k/mcf.h
diff --git a/hw/mips-bios.h b/include/hw/mips/bios.h
index b4b88ac43d..b4b88ac43d 100644
--- a/hw/mips-bios.h
+++ b/include/hw/mips/bios.h
diff --git a/hw/mips_cpudevs.h b/include/hw/mips/cpudevs.h
index 6bea24bf10..6bea24bf10 100644
--- a/hw/mips_cpudevs.h
+++ b/include/hw/mips/cpudevs.h
diff --git a/hw/mips.h b/include/hw/mips/mips.h
index 291e85f6b9..291e85f6b9 100644
--- a/hw/mips.h
+++ b/include/hw/mips/mips.h
diff --git a/hw/tmp105_regs.h b/include/hw/misc/tmp105_regs.h
index 9b55abaf90..9b55abaf90 100644
--- a/hw/tmp105_regs.h
+++ b/include/hw/misc/tmp105_regs.h
diff --git a/hw/eeprom93xx.h b/include/hw/nvram/eeprom93xx.h
index 8ba0e287f2..8ba0e287f2 100644
--- a/hw/eeprom93xx.h
+++ b/include/hw/nvram/eeprom93xx.h
diff --git a/hw/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index 05c8df186f..05c8df186f 100644
--- a/hw/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
diff --git a/hw/apb_pci.h b/include/hw/pci-host/apb.h
index 736db6118e..736db6118e 100644
--- a/hw/apb_pci.h
+++ b/include/hw/pci-host/apb.h
diff --git a/hw/pam.h b/include/hw/pci-host/pam.h
index 8e9e349b1d..8e9e349b1d 100644
--- a/hw/pam.h
+++ b/include/hw/pci-host/pam.h
diff --git a/hw/ppce500_pci.h b/include/hw/pci-host/ppce500.h
index 61f773ef30..61f773ef30 100644
--- a/hw/ppce500_pci.h
+++ b/include/hw/pci-host/ppce500.h
diff --git a/hw/q35.h b/include/hw/pci-host/q35.h
index d766bb7b02..e182c820ac 100644
--- a/hw/q35.h
+++ b/include/hw/pci-host/q35.h
@@ -24,16 +24,15 @@
 
 #include "hw/hw.h"
 #include "qemu/range.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "hw/sysbus.h"
-#include "hw/pc.h"
-#include "hw/apm.h"
-#include "hw/apic.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/apm.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pcie_host.h"
-#include "hw/acpi.h"
-#include "hw/acpi_ich9.h"
-#include "hw/pam.h"
+#include "hw/acpi/acpi.h"
+#include "hw/acpi/ich9.h"
+#include "hw/pci-host/pam.h"
 
 #define TYPE_Q35_HOST_DEVICE "q35-pcihost"
 #define Q35_HOST_DEVICE(obj) \
diff --git a/hw/spapr_pci.h b/include/hw/pci-host/spapr.h
index 8bd8a663c5..b21080cd58 100644
--- a/hw/spapr_pci.h
+++ b/include/hw/pci-host/spapr.h
@@ -25,7 +25,7 @@
 
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_host.h"
-#include "hw/xics.h"
+#include "hw/ppc/xics.h"
 
 #define SPAPR_MSIX_MAX_DEVS 32
 
diff --git a/hw/pci/msi.h b/include/hw/pci/msi.h
index 81a3848a31..81a3848a31 100644
--- a/hw/pci/msi.h
+++ b/include/hw/pci/msi.h
diff --git a/hw/pci/msix.h b/include/hw/pci/msix.h
index e648410535..e648410535 100644
--- a/hw/pci/msix.h
+++ b/include/hw/pci/msix.h
diff --git a/hw/pci/pci.h b/include/hw/pci/pci.h
index 9ea67a3832..05315c0475 100644
--- a/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -8,7 +8,7 @@
 #include "sysemu/dma.h"
 
 /* PCI includes legacy ISA access.  */
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 #include "hw/pci/pcie.h"
 
diff --git a/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h
index 1868f7aea8..1868f7aea8 100644
--- a/hw/pci/pci_bridge.h
+++ b/include/hw/pci/pci_bridge.h
diff --git a/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h
index 6ee443cf88..6ee443cf88 100644
--- a/hw/pci/pci_bus.h
+++ b/include/hw/pci/pci_bus.h
diff --git a/hw/pci/pci_host.h b/include/hw/pci/pci_host.h
index 236cd0f75c..236cd0f75c 100644
--- a/hw/pci/pci_host.h
+++ b/include/hw/pci/pci_host.h
diff --git a/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h
index d8dc2f1bf7..d8dc2f1bf7 100644
--- a/hw/pci/pci_ids.h
+++ b/include/hw/pci/pci_ids.h
diff --git a/hw/pci/pci_regs.h b/include/hw/pci/pci_regs.h
index 56a404be6e..56a404be6e 100644
--- a/hw/pci/pci_regs.h
+++ b/include/hw/pci/pci_regs.h
diff --git a/hw/pci/pcie.h b/include/hw/pci/pcie.h
index c010007c5e..c010007c5e 100644
--- a/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
diff --git a/hw/pci/pcie_aer.h b/include/hw/pci/pcie_aer.h
index bcac80a7b0..bcac80a7b0 100644
--- a/hw/pci/pcie_aer.h
+++ b/include/hw/pci/pcie_aer.h
diff --git a/hw/pci/pcie_host.h b/include/hw/pci/pcie_host.h
index 1228e36cb2..1228e36cb2 100644
--- a/hw/pci/pcie_host.h
+++ b/include/hw/pci/pcie_host.h
diff --git a/hw/pci/pcie_port.h b/include/hw/pci/pcie_port.h
index d89aa615c5..d89aa615c5 100644
--- a/hw/pci/pcie_port.h
+++ b/include/hw/pci/pcie_port.h
diff --git a/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h
index 4d123d9fcc..4d123d9fcc 100644
--- a/hw/pci/pcie_regs.h
+++ b/include/hw/pci/pcie_regs.h
diff --git a/hw/pci/shpc.h b/include/hw/pci/shpc.h
index 467911a558..467911a558 100644
--- a/hw/pci/shpc.h
+++ b/include/hw/pci/shpc.h
diff --git a/hw/pci/slotid_cap.h b/include/hw/pci/slotid_cap.h
index 70db0470b0..70db0470b0 100644
--- a/hw/pci/slotid_cap.h
+++ b/include/hw/pci/slotid_cap.h
diff --git a/hw/pcmcia.h b/include/hw/pcmcia.h
index f91669305e..f91669305e 100644
--- a/hw/pcmcia.h
+++ b/include/hw/pcmcia.h
diff --git a/hw/mac_dbdma.h b/include/hw/ppc/mac_dbdma.h
index 691263eede..691263eede 100644
--- a/hw/mac_dbdma.h
+++ b/include/hw/ppc/mac_dbdma.h
diff --git a/hw/openpic.h b/include/hw/ppc/openpic.h
index 9dcaf0e7cd..9dcaf0e7cd 100644
--- a/hw/openpic.h
+++ b/include/hw/ppc/openpic.h
diff --git a/hw/ppc.h b/include/hw/ppc/ppc.h
index acaf0d6580..acaf0d6580 100644
--- a/hw/ppc.h
+++ b/include/hw/ppc/ppc.h
diff --git a/hw/ppc4xx.h b/include/hw/ppc/ppc4xx.h
index 91d84bad63..91d84bad63 100644
--- a/hw/ppc4xx.h
+++ b/include/hw/ppc/ppc4xx.h
diff --git a/hw/spapr.h b/include/hw/ppc/spapr.h
index 3a1f69f2a9..864bee9d00 100644
--- a/hw/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -2,7 +2,7 @@
 #define __HW_SPAPR_H__
 
 #include "sysemu/dma.h"
-#include "hw/xics.h"
+#include "hw/ppc/xics.h"
 
 struct VIOsPAPRBus;
 struct sPAPRPHBState;
diff --git a/hw/spapr_vio.h b/include/hw/ppc/spapr_vio.h
index f98ec0a2e5..f98ec0a2e5 100644
--- a/hw/spapr_vio.h
+++ b/include/hw/ppc/spapr_vio.h
diff --git a/hw/xics.h b/include/hw/ppc/xics.h
index 6bce0424df..6bce0424df 100644
--- a/hw/xics.h
+++ b/include/hw/ppc/xics.h
diff --git a/hw/ptimer.h b/include/hw/ptimer.h
index 28fcaf17f8..28fcaf17f8 100644
--- a/hw/ptimer.h
+++ b/include/hw/ptimer.h
diff --git a/hw/qdev-addr.h b/include/hw/qdev-addr.h
index 79708e6751..79708e6751 100644
--- a/hw/qdev-addr.h
+++ b/include/hw/qdev-addr.h
diff --git a/hw/qdev-core.h b/include/hw/qdev-core.h
index 547fbc7e0d..547fbc7e0d 100644
--- a/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
diff --git a/hw/qdev-dma.h b/include/hw/qdev-dma.h
index 6812735e3d..6812735e3d 100644
--- a/hw/qdev-dma.h
+++ b/include/hw/qdev-dma.h
diff --git a/hw/qdev-properties.h b/include/hw/qdev-properties.h
index a37933998a..a37933998a 100644
--- a/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
diff --git a/hw/qdev.h b/include/hw/qdev.h
index 5cb8b080a6..5cb8b080a6 100644
--- a/hw/qdev.h
+++ b/include/hw/qdev.h
diff --git a/hw/s390x/event-facility.h b/include/hw/s390x/event-facility.h
index 791ab2a6de..791ab2a6de 100644
--- a/hw/s390x/event-facility.h
+++ b/include/hw/s390x/event-facility.h
diff --git a/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
index 231a38aa09..231a38aa09 100644
--- a/hw/s390x/sclp.h
+++ b/include/hw/s390x/sclp.h
diff --git a/hw/esp.h b/include/hw/scsi/esp.h
index 830673be8f..e079fb8d16 100644
--- a/hw/esp.h
+++ b/include/hw/scsi/esp.h
@@ -1,7 +1,7 @@
 #ifndef QEMU_HW_ESP_H
 #define QEMU_HW_ESP_H
 
-#include "hw/scsi.h"
+#include "hw/scsi/scsi.h"
 
 /* esp.c */
 #define ESP_MAX_DEVS 7
diff --git a/hw/scsi.h b/include/hw/scsi/scsi.h
index 33e2e0bdf1..3bda1c42c1 100644
--- a/hw/scsi.h
+++ b/include/hw/scsi/scsi.h
@@ -3,7 +3,7 @@
 
 #include "hw/qdev.h"
 #include "block/block.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "sysemu/sysemu.h"
 
 #define MAX_SCSI_DEVS	255
@@ -160,7 +160,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
 }
 
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
-                                      int unit, bool removable, int bootindex);
+                                      int unit, bool removable, int bootindex,
+                                      const char *serial);
 int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
 
 /*
diff --git a/hw/sd.h b/include/hw/sd.h
index d9b97e4466..d9b97e4466 100644
--- a/hw/sd.h
+++ b/include/hw/sd.h
diff --git a/hw/sh.h b/include/hw/sh4/sh.h
index 6230954eac..87c378f1eb 100644
--- a/hw/sh.h
+++ b/include/hw/sh4/sh.h
@@ -2,7 +2,7 @@
 #define QEMU_SH_H
 /* Definitions for SH board emulation.  */
 
-#include "hw/sh_intc.h"
+#include "hw/sh4/sh_intc.h"
 
 #define A7ADDR(x) ((x) & 0x1fffffff)
 #define P4ADDR(x) ((x) | 0xe0000000)
diff --git a/hw/sh_intc.h b/include/hw/sh4/sh_intc.h
index b7ddcb096a..b7ddcb096a 100644
--- a/hw/sh_intc.h
+++ b/include/hw/sh4/sh_intc.h
diff --git a/hw/firmware_abi.h b/include/hw/sparc/firmware_abi.h
index 5e6e5d4d34..5e6e5d4d34 100644
--- a/hw/firmware_abi.h
+++ b/include/hw/sparc/firmware_abi.h
diff --git a/hw/grlib.h b/include/hw/sparc/grlib.h
index 470ce72250..470ce72250 100644
--- a/hw/grlib.h
+++ b/include/hw/sparc/grlib.h
diff --git a/hw/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index 9497b13d34..9497b13d34 100644
--- a/hw/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
diff --git a/hw/sun4m.h b/include/hw/sparc/sun4m.h
index 0d2cfb807b..a587700a8b 100644
--- a/hw/sun4m.h
+++ b/include/hw/sparc/sun4m.h
@@ -2,6 +2,8 @@
 #define SUN4M_H
 
 #include "qemu-common.h"
+#include "exec/hwaddr.h"
+#include "qapi/qmp/types.h"
 
 /* Devices used by sparc32 system.  */
 
@@ -31,6 +33,6 @@ void sun4m_pic_info(Monitor *mon, const QDict *qdict);
 void sun4m_irq_info(Monitor *mon, const QDict *qdict);
 
 /* sparc32_dma.c */
-#include "hw/sparc32_dma.h"
+#include "hw/sparc/sparc32_dma.h"
 
 #endif
diff --git a/hw/ssi.h b/include/hw/ssi.h
index fdae317295..fdae317295 100644
--- a/hw/ssi.h
+++ b/include/hw/ssi.h
diff --git a/hw/stream.h b/include/hw/stream.h
index f6137d6e25..f6137d6e25 100644
--- a/hw/stream.h
+++ b/include/hw/stream.h
diff --git a/hw/sysbus.h b/include/hw/sysbus.h
index 7c2e3163fb..7c2e3163fb 100644
--- a/hw/sysbus.h
+++ b/include/hw/sysbus.h
diff --git a/hw/hpet_emul.h b/include/hw/timer/hpet.h
index 757f79fdd2..757f79fdd2 100644
--- a/hw/hpet_emul.h
+++ b/include/hw/timer/hpet.h
diff --git a/hw/i8254.h b/include/hw/timer/i8254.h
index 7d4432e722..75bb530ad9 100644
--- a/hw/i8254.h
+++ b/include/hw/timer/i8254.h
@@ -26,7 +26,7 @@
 #define HW_I8254_H
 
 #include "hw/hw.h"
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 
 #define PIT_FREQ 1193182
 
diff --git a/hw/i8254_internal.h b/include/hw/timer/i8254_internal.h
index 30d5b1b950..e0cff0cf5a 100644
--- a/hw/i8254_internal.h
+++ b/include/hw/timer/i8254_internal.h
@@ -26,8 +26,8 @@
 #define QEMU_I8254_INTERNAL_H
 
 #include "hw/hw.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 
 typedef struct PITChannelState {
     int count; /* can be 65536 */
diff --git a/hw/nvram.h b/include/hw/timer/m48t59.h
index 59337faaad..59337faaad 100644
--- a/hw/nvram.h
+++ b/include/hw/timer/m48t59.h
diff --git a/hw/mc146818rtc.h b/include/hw/timer/mc146818rtc.h
index 967403edb5..854ea3f5b5 100644
--- a/hw/mc146818rtc.h
+++ b/include/hw/timer/mc146818rtc.h
@@ -1,8 +1,8 @@
 #ifndef MC146818RTC_H
 #define MC146818RTC_H
 
-#include "hw/isa.h"
-#include "hw/mc146818rtc_regs.h"
+#include "hw/isa/isa.h"
+#include "hw/timer/mc146818rtc_regs.h"
 
 ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq);
 void rtc_set_memory(ISADevice *dev, int addr, int val);
diff --git a/hw/mc146818rtc_regs.h b/include/hw/timer/mc146818rtc_regs.h
index ccdee42b3c..ccdee42b3c 100644
--- a/hw/mc146818rtc_regs.h
+++ b/include/hw/timer/mc146818rtc_regs.h
diff --git a/hw/puv3.h b/include/hw/unicore32/puv3.h
index f37adcb665..f37adcb665 100644
--- a/hw/puv3.h
+++ b/include/hw/unicore32/puv3.h
diff --git a/hw/usb.h b/include/hw/usb.h
index 1b10684dde..4d9d05e9bc 100644
--- a/hw/usb.h
+++ b/include/hw/usb.h
@@ -337,6 +337,7 @@ typedef struct USBPortOps {
 struct USBPort {
     USBDevice *dev;
     int speedmask;
+    int hubcount;
     char path[16];
     USBPortOps *ops;
     void *opaque;
diff --git a/hw/dataplane/hostmem.h b/include/hw/virtio/dataplane/hostmem.h
index b2cf09333f..b2cf09333f 100644
--- a/hw/dataplane/hostmem.h
+++ b/include/hw/virtio/dataplane/hostmem.h
diff --git a/hw/dataplane/vring.h b/include/hw/virtio/dataplane/vring.h
index defb1efcda..9380cb5413 100644
--- a/hw/dataplane/vring.h
+++ b/include/hw/virtio/dataplane/vring.h
@@ -20,7 +20,7 @@
 #include <linux/virtio_ring.h>
 #include "qemu-common.h"
 #include "hostmem.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 
 typedef struct {
     HostMem hostmem;                /* guest memory mapper */
diff --git a/hw/vhost.h b/include/hw/virtio/vhost.h
index f062d48807..b373be0387 100644
--- a/hw/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -2,7 +2,7 @@
 #define VHOST_H
 
 #include "hw/hw.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "exec/memory.h"
 
 /* Generic structures common for any vhost based device. */
diff --git a/hw/9pfs/virtio-9p-device.h b/include/hw/virtio/virtio-9p.h
index 65789db131..65789db131 100644
--- a/hw/9pfs/virtio-9p-device.h
+++ b/include/hw/virtio/virtio-9p.h
diff --git a/hw/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
index d898315414..3b459bbdd7 100644
--- a/hw/virtio-balloon.h
+++ b/include/hw/virtio/virtio-balloon.h
@@ -15,7 +15,7 @@
 #ifndef _QEMU_VIRTIO_BALLOON_H
 #define _QEMU_VIRTIO_BALLOON_H
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "hw/pci/pci.h"
 
 #define TYPE_VIRTIO_BALLOON "virtio-balloon"
diff --git a/hw/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index 8c6c78b191..c10d069b25 100644
--- a/hw/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -14,11 +14,8 @@
 #ifndef _QEMU_VIRTIO_BLK_H
 #define _QEMU_VIRTIO_BLK_H
 
-#include "hw/virtio.h"
-#include "hw/block-common.h"
-#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
-#include "dataplane/virtio-blk.h"
-#endif
+#include "hw/virtio/virtio.h"
+#include "hw/block/block.h"
 
 #define TYPE_VIRTIO_BLK "virtio-blk"
 #define VIRTIO_BLK(obj) \
@@ -115,6 +112,8 @@ struct VirtIOBlkConf
     uint32_t data_plane;
 };
 
+struct VirtIOBlockDataPlane;
+
 typedef struct VirtIOBlock {
     VirtIODevice parent_obj;
     BlockDriverState *bs;
@@ -126,7 +125,7 @@ typedef struct VirtIOBlock {
     unsigned short sector_mask;
     VMChangeStateEntry *change;
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
-    VirtIOBlockDataPlane *dataplane;
+    struct VirtIOBlockDataPlane *dataplane;
 #endif
 } VirtIOBlock;
 
diff --git a/hw/virtio-bus.h b/include/hw/virtio/virtio-bus.h
index ae0f7078b4..311e8c78bd 100644
--- a/hw/virtio-bus.h
+++ b/include/hw/virtio/virtio-bus.h
@@ -27,7 +27,7 @@
 
 #include "hw/qdev.h"
 #include "sysemu/sysemu.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 
 #define TYPE_VIRTIO_BUS "virtio-bus"
 #define VIRTIO_BUS_GET_CLASS(obj) \
diff --git a/hw/virtio-net.h b/include/hw/virtio/virtio-net.h
index 4d1a8cdca0..d2cc996872 100644
--- a/hw/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -14,7 +14,7 @@
 #ifndef _QEMU_VIRTIO_NET_H
 #define _QEMU_VIRTIO_NET_H
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "hw/pci/pci.h"
 
 #define ETH_ALEN    6
diff --git a/hw/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 3711c97a70..3711c97a70 100644
--- a/hw/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
diff --git a/hw/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index 31e97bbe38..c9d92ca2e8 100644
--- a/hw/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -14,9 +14,9 @@
 #ifndef _QEMU_VIRTIO_SCSI_H
 #define _QEMU_VIRTIO_SCSI_H
 
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 #include "hw/pci/pci.h"
-#include "hw/scsi.h"
+#include "hw/scsi/scsi.h"
 
 #define TYPE_VIRTIO_SCSI "virtio-scsi"
 #define VIRTIO_SCSI(obj) \
diff --git a/hw/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index 516400f22d..098deeac4a 100644
--- a/hw/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -16,7 +16,7 @@
 #define _QEMU_VIRTIO_SERIAL_H
 
 #include "hw/qdev.h"
-#include "hw/virtio.h"
+#include "hw/virtio/virtio.h"
 
 /* == Interface shared between the guest kernel and qemu == */
 
diff --git a/hw/virtio.h b/include/hw/virtio/virtio.h
index fdbe9313a0..7e24b2b69a 100644
--- a/hw/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -20,7 +20,7 @@
 #include "sysemu/sysemu.h"
 #include "qemu/event_notifier.h"
 #ifdef CONFIG_VIRTFS
-#include "hw/9pfs/virtio-9p-device.h"
+#include "hw/virtio/virtio-9p.h"
 #endif
 
 /* from Linux's linux/virtio_config.h */
diff --git a/hw/xen.h b/include/hw/xen/xen.h
index 6235f91fe0..6235f91fe0 100644
--- a/hw/xen.h
+++ b/include/hw/xen/xen.h
diff --git a/hw/xen_backend.h b/include/hw/xen/xen_backend.h
index 6d5c699c51..3b7d96d7a5 100644
--- a/hw/xen_backend.h
+++ b/include/hw/xen/xen_backend.h
@@ -1,7 +1,7 @@
 #ifndef QEMU_HW_XEN_BACKEND_H
 #define QEMU_HW_XEN_BACKEND_H 1
 
-#include "hw/xen_common.h"
+#include "hw/xen/xen_common.h"
 #include "sysemu/sysemu.h"
 #include "net/net.h"
 
@@ -63,11 +63,13 @@ extern const char *xen_protocol;
 /* xenstore helper functions */
 int xenstore_write_str(const char *base, const char *node, const char *val);
 int xenstore_write_int(const char *base, const char *node, int ival);
+int xenstore_write_int64(const char *base, const char *node, int64_t ival);
 char *xenstore_read_str(const char *base, const char *node);
 int xenstore_read_int(const char *base, const char *node, int *ival);
 
 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val);
 int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival);
+int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, int64_t ival);
 char *xenstore_read_be_str(struct XenDevice *xendev, const char *node);
 int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival);
 char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node);
diff --git a/hw/xen_common.h b/include/hw/xen/xen_common.h
index c37bde3f7e..2d5a25bf40 100644
--- a/hw/xen_common.h
+++ b/include/hw/xen/xen_common.h
@@ -15,7 +15,7 @@
 #include <xen/io/xenbus.h>
 
 #include "hw/hw.h"
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 #include "qemu/queue.h"
 
 /*
diff --git a/hw/xilinx.h b/include/hw/xilinx.h
index 6c1ee21c54..6c1ee21c54 100644
--- a/hw/xilinx.h
+++ b/include/hw/xilinx.h
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 65918a9abe..ebc4d09141 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -164,6 +164,7 @@ extern const VMStateInfo vmstate_info_buffer;
 extern const VMStateInfo vmstate_info_unused_buffer;
 extern const VMStateInfo vmstate_info_bitmap;
 
+#define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
 
@@ -179,6 +180,10 @@ extern const VMStateInfo vmstate_info_bitmap;
     (offsetof(_state, _field) +                                      \
      type_check_array(_type, typeof_field(_state, _field), _num))
 
+#define vmstate_offset_2darray(_state, _field, _type, _n1, _n2)      \
+    (offsetof(_state, _field) +                                      \
+     type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
+
 #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
     (offsetof(_state, _field[_start]))
 
@@ -224,6 +229,16 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
 }
 
+#define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
+    .name       = (stringify(_field)),                                      \
+    .version_id = (_version),                                               \
+    .num        = (_n1) * (_n2),                                            \
+    .info       = &(_info),                                                 \
+    .size       = sizeof(_type),                                            \
+    .flags      = VMS_ARRAY,                                                \
+    .offset     = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
+}
+
 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
     .name         = (stringify(_field)),                              \
     .field_exists = (_test),                                          \
@@ -436,6 +451,15 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset     = offsetof(_state, _field),                          \
 }
 
+#define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .size       = (_size),                                           \
+    .info       = &vmstate_info_buffer,                              \
+    .flags      = VMS_BUFFER|VMS_POINTER,                            \
+    .offset     = offsetof(_state, _field),                          \
+}
+
 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
     .name         = "unused",                                        \
     .field_exists = (_test),                                         \
@@ -583,15 +607,27 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
 
+#define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
+    VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
+
 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
     VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
 
+#define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)                      \
+    VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
+
+#define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
+    VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
+
 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
 
 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
     VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
 
+#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)                       \
+    VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
+
 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
 
diff --git a/hw/vhost_net.h b/include/net/vhost_net.h
index 2d936bb5f5..2d936bb5f5 100644
--- a/hw/vhost_net.h
+++ b/include/net/vhost_net.h
diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h
index 0e690f4849..1bc3666107 100644
--- a/include/qapi/qmp/qstring.h
+++ b/include/qapi/qmp/qstring.h
@@ -26,6 +26,7 @@ typedef struct QString {
 QString *qstring_new(void);
 QString *qstring_from_str(const char *str);
 QString *qstring_from_substr(const char *str, int start, int end);
+size_t qstring_get_length(const QString *qstring);
 const char *qstring_get_str(const QString *qstring);
 void qstring_append_int(QString *qstring, int64_t value);
 void qstring_append(QString *qstring, const char *str);
diff --git a/hw/watchdog.h b/include/sysemu/watchdog.h
index 3e9a970686..3e9a970686 100644
--- a/hw/watchdog.h
+++ b/include/sysemu/watchdog.h
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 0fbae3c2f6..ea6c1d24e6 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -143,7 +143,7 @@ print_signal(abi_ulong arg, int last)
     case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
     }
     if (signal_name == NULL) {
-        print_raw_param("%ld", arg, 1);
+        print_raw_param("%ld", arg, last);
         return;
     }
     gemu_log("%s%s", signal_name, get_comma(last));
diff --git a/main-loop.c b/main-loop.c
index eb80ff369f..f46aece8b8 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -188,14 +188,39 @@ static void glib_pollfds_poll(void)
     }
 }
 
+#define MAX_MAIN_LOOP_SPIN (1000)
+
 static int os_host_main_loop_wait(uint32_t timeout)
 {
     int ret;
+    static int spin_counter;
 
     glib_pollfds_fill(&timeout);
 
+    /* If the I/O thread is very busy or we are incorrectly busy waiting in
+     * the I/O thread, this can lead to starvation of the BQL such that the
+     * VCPU threads never run.  To make sure we can detect the later case,
+     * print a message to the screen.  If we run into this condition, create
+     * a fake timeout in order to give the VCPU threads a chance to run.
+     */
+    if (spin_counter > MAX_MAIN_LOOP_SPIN) {
+        static bool notified;
+
+        if (!notified) {
+            fprintf(stderr,
+                    "main-loop: WARNING: I/O thread spun for %d iterations\n",
+                    MAX_MAIN_LOOP_SPIN);
+            notified = true;
+        }
+
+        timeout = 1;
+    }
+
     if (timeout > 0) {
+        spin_counter = 0;
         qemu_mutex_unlock_iothread();
+    } else {
+        spin_counter++;
     }
 
     ret = g_poll((GPollFD *)gpollfds->data, gpollfds->len, timeout);
diff --git a/monitor.c b/monitor.c
index 4ec1db980c..c897e8033f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -26,9 +26,9 @@
 #include "monitor/qdev.h"
 #include "hw/usb.h"
 #include "hw/pcmcia.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
-#include "hw/watchdog.h"
+#include "sysemu/watchdog.h"
 #include "hw/loader.h"
 #include "exec/gdbstub.h"
 #include "net/net.h"
@@ -71,9 +71,9 @@
 
 /* for pic/irq_info */
 #if defined(TARGET_SPARC)
-#include "hw/sun4m.h"
+#include "hw/sparc/sun4m.h"
 #endif
-#include "hw/lm32_pic.h"
+#include "hw/lm32/lm32_pic.h"
 
 //#define DEBUG
 //#define DEBUG_COMPLETION
@@ -188,8 +188,8 @@ struct Monitor {
     int reset_seen;
     int flags;
     int suspend_cnt;
-    uint8_t outbuf[1024];
-    int outbuf_index;
+    bool skip_flush;
+    QString *outbuf;
     ReadLineState *rs;
     MonitorControl *mc;
     CPUArchState *mon_cpu;
@@ -271,45 +271,56 @@ static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
 void monitor_flush(Monitor *mon)
 {
     int rc;
+    size_t len;
+    const char *buf;
+
+    if (mon->skip_flush) {
+        return;
+    }
 
-    if (mon && mon->outbuf_index != 0 && !mon->mux_out) {
-        rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
-        if (rc == mon->outbuf_index) {
+    buf = qstring_get_str(mon->outbuf);
+    len = qstring_get_length(mon->outbuf);
+
+    if (mon && len && !mon->mux_out) {
+        rc = qemu_chr_fe_write(mon->chr, (const uint8_t *) buf, len);
+        if (rc == len) {
             /* all flushed */
-            mon->outbuf_index = 0;
+            QDECREF(mon->outbuf);
+            mon->outbuf = qstring_new();
             return;
         }
         if (rc > 0) {
             /* partinal write */
-            memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index - rc);
-            mon->outbuf_index -= rc;
+            QString *tmp = qstring_from_str(buf + rc);
+            QDECREF(mon->outbuf);
+            mon->outbuf = tmp;
         }
         qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon);
     }
 }
 
-/* flush at every end of line or if the buffer is full */
+/* flush at every end of line */
 static void monitor_puts(Monitor *mon, const char *str)
 {
     char c;
 
     for(;;) {
-        assert(mon->outbuf_index < sizeof(mon->outbuf) - 1);
         c = *str++;
         if (c == '\0')
             break;
-        if (c == '\n')
-            mon->outbuf[mon->outbuf_index++] = '\r';
-        mon->outbuf[mon->outbuf_index++] = c;
-        if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1)
-            || c == '\n')
+        if (c == '\n') {
+            qstring_append_chr(mon->outbuf, '\r');
+        }
+        qstring_append_chr(mon->outbuf, c);
+        if (c == '\n') {
             monitor_flush(mon);
+        }
     }
 }
 
 void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
-    char buf[4096];
+    char *buf;
 
     if (!mon)
         return;
@@ -318,8 +329,9 @@ void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
         return;
     }
 
-    vsnprintf(buf, sizeof(buf), fmt, ap);
+    buf = g_strdup_vprintf(fmt, ap);
     monitor_puts(mon, buf);
+    g_free(buf);
 }
 
 void monitor_printf(Monitor *mon, const char *fmt, ...)
@@ -668,11 +680,10 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
 {
     char *output = NULL;
     Monitor *old_mon, hmp;
-    CharDriverState mchar;
 
     memset(&hmp, 0, sizeof(hmp));
-    qemu_chr_init_mem(&mchar);
-    hmp.chr = &mchar;
+    hmp.outbuf = qstring_new();
+    hmp.skip_flush = true;
 
     old_mon = cur_mon;
     cur_mon = &hmp;
@@ -690,16 +701,14 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
     handle_user_command(&hmp, command_line);
     cur_mon = old_mon;
 
-    if (qemu_chr_mem_osize(hmp.chr) > 0) {
-        QString *str = qemu_chr_mem_to_qs(hmp.chr);
-        output = g_strdup(qstring_get_str(str));
-        QDECREF(str);
+    if (qstring_get_length(hmp.outbuf) > 0) {
+        output = g_strdup(qstring_get_str(hmp.outbuf));
     } else {
         output = g_strdup("");
     }
 
 out:
-    qemu_chr_close_mem(hmp.chr);
+    QDECREF(hmp.outbuf);
     return output;
 }
 
@@ -4749,6 +4758,7 @@ void monitor_init(CharDriverState *chr, int flags)
     }
 
     mon = g_malloc0(sizeof(*mon));
+    mon->outbuf = qstring_new();
 
     mon->chr = chr;
     mon->flags = flags;
diff --git a/net/tap.c b/net/tap.c
index e7c84811ac..17bdf014a9 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -42,7 +42,7 @@
 
 #include "net/tap.h"
 
-#include "hw/vhost_net.h"
+#include "net/vhost_net.h"
 
 typedef struct TAPState {
     NetClientState nc;
diff --git a/pc-bios/optionrom/optionrom.h b/pc-bios/optionrom/optionrom.h
index 3daf7da495..ce436085d9 100644
--- a/pc-bios/optionrom/optionrom.h
+++ b/pc-bios/optionrom/optionrom.h
@@ -20,7 +20,7 @@
 
 
 #define NO_QEMU_PROTOS
-#include "../../hw/fw_cfg.h"
+#include "../../include/hw/nvram/fw_cfg.h"
 
 #define BIOS_CFG_IOPORT_CFG	0x510
 #define BIOS_CFG_IOPORT_DATA	0x511
diff --git a/qemu-char.c b/qemu-char.c
index e5eb8dd2ef..eae17fc61c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -594,65 +594,59 @@ int recv_all(int fd, void *_buf, int len1, bool single_read)
 
 typedef struct IOWatchPoll
 {
+    GSource parent;
+
+    GIOChannel *channel;
     GSource *src;
-    int max_size;
 
     IOCanReadHandler *fd_can_read;
+    GSourceFunc fd_read;
     void *opaque;
-
-    QTAILQ_ENTRY(IOWatchPoll) node;
 } IOWatchPoll;
 
-static QTAILQ_HEAD(, IOWatchPoll) io_watch_poll_list =
-    QTAILQ_HEAD_INITIALIZER(io_watch_poll_list);
-
 static IOWatchPoll *io_watch_poll_from_source(GSource *source)
 {
-    IOWatchPoll *i;
-
-    QTAILQ_FOREACH(i, &io_watch_poll_list, node) {
-        if (i->src == source) {
-            return i;
-        }
-    }
-
-    return NULL;
+    return container_of(source, IOWatchPoll, parent);
 }
 
 static gboolean io_watch_poll_prepare(GSource *source, gint *timeout_)
 {
     IOWatchPoll *iwp = io_watch_poll_from_source(source);
-
-    iwp->max_size = iwp->fd_can_read(iwp->opaque);
-    if (iwp->max_size == 0) {
+    bool now_active = iwp->fd_can_read(iwp->opaque) > 0;
+    bool was_active = iwp->src != NULL;
+    if (was_active == now_active) {
         return FALSE;
     }
 
-    return g_io_watch_funcs.prepare(source, timeout_);
+    if (now_active) {
+        iwp->src = g_io_create_watch(iwp->channel, G_IO_IN | G_IO_ERR | G_IO_HUP);
+        g_source_set_callback(iwp->src, iwp->fd_read, iwp->opaque, NULL);
+        g_source_attach(iwp->src, NULL);
+    } else {
+        g_source_destroy(iwp->src);
+        g_source_unref(iwp->src);
+        iwp->src = NULL;
+    }
+    return FALSE;
 }
 
 static gboolean io_watch_poll_check(GSource *source)
 {
-    IOWatchPoll *iwp = io_watch_poll_from_source(source);
-
-    if (iwp->max_size == 0) {
-        return FALSE;
-    }
-
-    return g_io_watch_funcs.check(source);
+    return FALSE;
 }
 
 static gboolean io_watch_poll_dispatch(GSource *source, GSourceFunc callback,
                                        gpointer user_data)
 {
-    return g_io_watch_funcs.dispatch(source, callback, user_data);
+    abort();
 }
 
 static void io_watch_poll_finalize(GSource *source)
 {
     IOWatchPoll *iwp = io_watch_poll_from_source(source);
-    QTAILQ_REMOVE(&io_watch_poll_list, iwp, node);
-    g_io_watch_funcs.finalize(source);
+    g_source_destroy(iwp->src);
+    g_source_unref(iwp->src);
+    iwp->src = NULL;
 }
 
 static GSourceFuncs io_watch_poll_funcs = {
@@ -669,24 +663,15 @@ static guint io_add_watch_poll(GIOChannel *channel,
                                gpointer user_data)
 {
     IOWatchPoll *iwp;
-    GSource *src;
-    guint tag;
 
-    src = g_io_create_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP);
-    g_source_set_funcs(src, &io_watch_poll_funcs);
-    g_source_set_callback(src, (GSourceFunc)fd_read, user_data, NULL);
-    tag = g_source_attach(src, NULL);
-    g_source_unref(src);
-
-    iwp = g_malloc0(sizeof(*iwp));
-    iwp->src = src;
-    iwp->max_size = 0;
+    iwp = (IOWatchPoll *) g_source_new(&io_watch_poll_funcs, sizeof(IOWatchPoll));
     iwp->fd_can_read = fd_can_read;
     iwp->opaque = user_data;
+    iwp->channel = channel;
+    iwp->fd_read = (GSourceFunc) fd_read;
+    iwp->src = NULL;
 
-    QTAILQ_INSERT_HEAD(&io_watch_poll_list, iwp, node);
-
-    return tag;
+    return g_source_attach(&iwp->parent, NULL);
 }
 
 #ifndef _WIN32
@@ -2796,70 +2781,6 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
     return NULL;
 }
 
-/***********************************************************/
-/* Memory chardev */
-typedef struct {
-    size_t outbuf_size;
-    size_t outbuf_capacity;
-    uint8_t *outbuf;
-} MemoryDriver;
-
-static int mem_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
-{
-    MemoryDriver *d = chr->opaque;
-
-    /* TODO: the QString implementation has the same code, we should
-     * introduce a generic way to do this in cutils.c */
-    if (d->outbuf_capacity < d->outbuf_size + len) {
-        /* grow outbuf */
-        d->outbuf_capacity += len;
-        d->outbuf_capacity *= 2;
-        d->outbuf = g_realloc(d->outbuf, d->outbuf_capacity);
-    }
-
-    memcpy(d->outbuf + d->outbuf_size, buf, len);
-    d->outbuf_size += len;
-
-    return len;
-}
-
-void qemu_chr_init_mem(CharDriverState *chr)
-{
-    MemoryDriver *d;
-
-    d = g_malloc(sizeof(*d));
-    d->outbuf_size = 0;
-    d->outbuf_capacity = 4096;
-    d->outbuf = g_malloc0(d->outbuf_capacity);
-
-    memset(chr, 0, sizeof(*chr));
-    chr->opaque = d;
-    chr->chr_write = mem_chr_write;
-}
-
-QString *qemu_chr_mem_to_qs(CharDriverState *chr)
-{
-    MemoryDriver *d = chr->opaque;
-    return qstring_from_substr((char *) d->outbuf, 0, d->outbuf_size - 1);
-}
-
-/* NOTE: this driver can not be closed with qemu_chr_delete()! */
-void qemu_chr_close_mem(CharDriverState *chr)
-{
-    MemoryDriver *d = chr->opaque;
-
-    g_free(d->outbuf);
-    g_free(chr->opaque);
-    chr->opaque = NULL;
-    chr->chr_write = NULL;
-}
-
-size_t qemu_chr_mem_osize(const CharDriverState *chr)
-{
-    const MemoryDriver *d = chr->opaque;
-    return d->outbuf_size;
-}
-
 /*********************************************************/
 /* Ring buffer chardev */
 
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index b19be9db48..24e4ad0319 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -22,6 +22,12 @@
 #define SHTDN_REASON_FLAG_PLANNED 0x80000000
 #endif
 
+/* multiple of 100 nanoseconds elapsed between windows baseline
+ *    (1/1/1601) and Unix Epoch (1/1/1970), accounting for leap years */
+#define W32_FT_OFFSET (10000000ULL * 60 * 60 * 24 * \
+                       (365 * (1970 - 1601) +       \
+                        (1970 - 1601) / 4 - 3))
+
 static void acquire_privilege(const char *name, Error **err)
 {
     HANDLE token;
@@ -280,13 +286,57 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **err)
 
 int64_t qmp_guest_get_time(Error **errp)
 {
-    error_set(errp, QERR_UNSUPPORTED);
-    return -1;
+    SYSTEMTIME ts = {0};
+    int64_t time_ns;
+    FILETIME tf;
+
+    GetSystemTime(&ts);
+    if (ts.wYear < 1601 || ts.wYear > 30827) {
+        error_setg(errp, "Failed to get time");
+        return -1;
+    }
+
+    if (!SystemTimeToFileTime(&ts, &tf)) {
+        error_setg(errp, "Failed to convert system time: %d", (int)GetLastError());
+        return -1;
+    }
+
+    time_ns = ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime)
+                - W32_FT_OFFSET) * 100;
+
+    return time_ns;
 }
 
 void qmp_guest_set_time(int64_t time_ns, Error **errp)
 {
-    error_set(errp, QERR_UNSUPPORTED);
+    SYSTEMTIME ts;
+    FILETIME tf;
+    LONGLONG time;
+
+    if (time_ns < 0 || time_ns / 100 > INT64_MAX - W32_FT_OFFSET) {
+        error_setg(errp, "Time %" PRId64 "is invalid", time_ns);
+        return;
+    }
+
+    time = time_ns / 100 + W32_FT_OFFSET;
+
+    tf.dwLowDateTime = (DWORD) time;
+    tf.dwHighDateTime = (DWORD) (time >> 32);
+
+    if (!FileTimeToSystemTime(&tf, &ts)) {
+        error_setg(errp, "Failed to convert system time %d", (int)GetLastError());
+        return;
+    }
+
+    acquire_privilege(SE_SYSTEMTIME_NAME, errp);
+    if (error_is_set(errp)) {
+        return;
+    }
+
+    if (!SetSystemTime(&ts)) {
+        error_setg(errp, "Failed to set time to guest: %d", (int)GetLastError());
+        return;
+    }
 }
 
 GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
diff --git a/qga/main.c b/qga/main.c
index 74ef7885b2..1841759db2 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -889,9 +889,13 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp)
     g_assert(!ga_is_frozen(s));
 
     handle = s->pstate.fd_counter++;
-    if (s->pstate.fd_counter < 0) {
-        s->pstate.fd_counter = 0;
+
+    /* This should never happen on a reasonable timeframe, as guest-file-open
+     * would have to be issued 2^63 times */
+    if (s->pstate.fd_counter == INT64_MAX) {
+        abort();
     }
+
     if (!write_persistent_state(&s->pstate, s->pstate_filepath)) {
         error_setg(errp, "failed to commit persistent state to disk");
     }
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index dac4e6f95f..7155b7ab55 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -2,6 +2,17 @@
 
 ##
 #
+# General note concerning the use of guest agent interfaces:
+#
+# "unsupported" is a higher-level error than the errors that individual
+# commands might document. The caller should always be prepared to receive
+# QERR_UNSUPPORTED, even if the given command doesn't specify it, or doesn't
+# document any failure mode at all.
+#
+##
+
+##
+#
 # Echo back a unique integer value, and prepend to response a
 # leading sentinel byte (0xFF) the client can check scan for.
 #
@@ -562,9 +573,10 @@
 #
 # @online: Whether the VCPU is enabled.
 #
-# @can-offline: Whether offlining the VCPU is possible. This member is always
-#               filled in by the guest agent when the structure is returned,
-#               and always ignored on input (hence it can be omitted then).
+# @can-offline: #optional Whether offlining the VCPU is possible. This member
+#               is always filled in by the guest agent when the structure is
+#               returned, and always ignored on input (hence it can be omitted
+#               then).
 #
 # Since: 1.5
 ##
diff --git a/qobject/qstring.c b/qobject/qstring.c
index 5f7376c336..607b7a142c 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -32,6 +32,14 @@ QString *qstring_new(void)
 }
 
 /**
+ * qstring_get_length(): Get the length of a QString
+ */
+size_t qstring_get_length(const QString *qstring)
+{
+    return qstring->length;
+}
+
+/**
  * qstring_from_substr(): Create a new QString from a C string substring
  *
  * Return string reference
diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c
index 847318d1f4..77718c4caa 100644
--- a/target-arm/arm-semi.c
+++ b/target-arm/arm-semi.c
@@ -34,7 +34,7 @@
 #else
 #include "qemu-common.h"
 #include "exec/gdbstub.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 #endif
 
 #define TARGET_SYS_OPEN        0x01
diff --git a/target-arm/kvm.c b/target-arm/kvm.c
index 82e2e084c3..6bfb10350b 100644
--- a/target-arm/kvm.c
+++ b/target-arm/kvm.c
@@ -21,7 +21,7 @@
 #include "sysemu/kvm.h"
 #include "kvm_arm.h"
 #include "cpu.h"
-#include "hw/arm-misc.h"
+#include "hw/arm.h"
 
 const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
     KVM_CAP_LAST_INFO
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 69c3570a15..356378c110 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -42,9 +42,9 @@
 
 #include "sysemu/sysemu.h"
 #ifndef CONFIG_USER_ONLY
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 #include "hw/sysbus.h"
-#include "hw/apic_internal.h"
+#include "hw/i386/apic_internal.h"
 #endif
 
 static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 069a2e2cf9..2b4e3193f3 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1164,7 +1164,7 @@ static inline void cpu_clone_regs(CPUX86State *env, target_ulong newsp)
 #include "svm.h"
 
 #if !defined(CONFIG_USER_ONLY)
-#include "hw/apic.h"
+#include "hw/i386/apic.h"
 #endif
 
 static inline bool cpu_has_work(CPUState *cs)
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index df30fa6ed6..397afebecb 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -28,8 +28,8 @@
 #include "exec/gdbstub.h"
 #include "qemu/host-utils.h"
 #include "qemu/config-file.h"
-#include "hw/pc.h"
-#include "hw/apic.h"
+#include "hw/i386/pc.h"
+#include "hw/i386/apic.h"
 #include "exec/ioport.h"
 #include "hyperv.h"
 #include "hw/pci/pci.h"
diff --git a/target-i386/machine.c b/target-i386/machine.c
index b80a5f4470..ee85e57435 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -1,7 +1,7 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 
 #include "cpu.h"
 #include "sysemu/kvm.h"
diff --git a/target-lm32/op_helper.c b/target-lm32/op_helper.c
index 7ff991e28e..f106873ad8 100644
--- a/target-lm32/op_helper.c
+++ b/target-lm32/op_helper.c
@@ -3,8 +3,8 @@
 #include "helper.h"
 #include "qemu/host-utils.h"
 
-#include "hw/lm32_pic.h"
-#include "hw/lm32_juart.h"
+#include "hw/lm32/lm32_pic.h"
+#include "hw/lm32/lm32_juart.h"
 
 #if !defined(CONFIG_USER_ONLY)
 #define MMUSUFFIX _mmu
diff --git a/target-lm32/translate.c b/target-lm32/translate.c
index e885bb3aeb..af9ce8c337 100644
--- a/target-lm32/translate.c
+++ b/target-lm32/translate.c
@@ -22,7 +22,7 @@
 #include "helper.h"
 #include "tcg-op.h"
 
-#include "hw/lm32_pic.h"
+#include "hw/lm32/lm32_pic.h"
 
 #define GEN_HELPER 1
 #include "helper.h"
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 597066f5a0..5e9dddbb54 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -31,12 +31,12 @@
 #include "sysemu/cpus.h"
 #include "sysemu/device_tree.h"
 #include "hw/sysbus.h"
-#include "hw/spapr.h"
+#include "hw/ppc/spapr.h"
 #include "mmu-hash64.h"
 
 #include "hw/sysbus.h"
-#include "hw/spapr.h"
-#include "hw/spapr_vio.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_vio.h"
 
 //#define DEBUG_KVM
 
diff --git a/target-s390x/translate.c b/target-s390x/translate.c
index a4f2194ec7..0c3cf68e1d 100644
--- a/target-s390x/translate.c
+++ b/target-s390x/translate.c
@@ -3088,6 +3088,7 @@ static ExitStatus op_srnm(DisasContext *s, DisasOps *o)
         break;
     case 0xb9: /* SRNMT */
         pos = 4, len = 3;
+        break;
     default:
         tcg_abort();
     }
diff --git a/target-sh4/helper.c b/target-sh4/helper.c
index 0a9cb3ac98..ce10ca84ee 100644
--- a/target-sh4/helper.c
+++ b/target-sh4/helper.c
@@ -26,7 +26,7 @@
 #include "cpu.h"
 
 #if !defined(CONFIG_USER_ONLY)
-#include "hw/sh_intc.h"
+#include "hw/sh4/sh_intc.h"
 #endif
 
 #if defined(CONFIG_USER_ONLY)
diff --git a/tests/Makefile b/tests/Makefile
index 567e36e777..7fa15c6c08 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -24,19 +24,7 @@ gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
 gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c
 check-unit-y += tests/test-coroutine$(EXESUF)
-ifeq ($(CONFIG_WIN32),y)
-gcov-files-test-coroutine-y = coroutine-win32.c
-else
-ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
-gcov-files-test-coroutine-y = coroutine-ucontext.c
-else
-ifeq ($(CONFIG_SIGALTSTACK_COROUTINE),y)
-gcov-files-test-coroutine-y = coroutine-sigaltstack.c
-else
-gcov-files-test-coroutine-y = coroutine-gthread.c
-endif
-endif
-endif
+gcov-files-test-coroutine-y = coroutine-$(CONFIG_COROUTINE_BACKEND).c
 check-unit-y += tests/test-visitor-serialization$(EXESUF)
 check-unit-y += tests/test-iov$(EXESUF)
 gcov-files-test-iov-y = util/iov.c
diff --git a/tests/rtc-test.c b/tests/rtc-test.c
index 9ab583b860..3395d7f50b 100644
--- a/tests/rtc-test.c
+++ b/tests/rtc-test.c
@@ -11,7 +11,7 @@
  *
  */
 #include "libqtest.h"
-#include "hw/mc146818rtc_regs.h"
+#include "hw/timer/mc146818rtc_regs.h"
 
 #include <glib.h>
 #include <stdio.h>
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
index 3c6b8df607..e84926f97c 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -258,6 +258,7 @@ static void test_primitives(gconstpointer opaque)
     g_assert(pt_copy != NULL);
     if (pt->type == PTYPE_STRING) {
         g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string);
+        g_free((char *)pt_copy->value.string);
     } else if (pt->type == PTYPE_NUMBER) {
         /* we serialize with %f for our reference visitors, so rather than fuzzy
          * floating math to test "equality", just compare the formatted values
@@ -275,6 +276,7 @@ static void test_primitives(gconstpointer opaque)
 
     ops->cleanup(serialize_data);
     g_free(args);
+    g_free(pt_copy);
 }
 
 static void test_struct(gconstpointer opaque)
@@ -660,6 +662,7 @@ static void qmp_deserialize(void **native_out, void *datap,
 
     QDECREF(output_json);
     d->qiv = qmp_input_visitor_new(obj);
+    qobject_decref(obj);
     visit(qmp_input_get_visitor(d->qiv), native_out, errp);
 }
 
@@ -668,9 +671,12 @@ static void qmp_cleanup(void *datap)
     QmpSerializeData *d = datap;
     qmp_output_visitor_cleanup(d->qov);
     qmp_input_visitor_cleanup(d->qiv);
+
+    g_free(d);
 }
 
 typedef struct StringSerializeData {
+    char *string;
     StringOutputVisitor *sov;
     StringInputVisitor *siv;
 } StringSerializeData;
@@ -690,15 +696,19 @@ static void string_deserialize(void **native_out, void *datap,
 {
     StringSerializeData *d = datap;
 
-    d->siv = string_input_visitor_new(string_output_get_string(d->sov));
+    d->string = string_output_get_string(d->sov);
+    d->siv = string_input_visitor_new(d->string);
     visit(string_input_get_visitor(d->siv), native_out, errp);
 }
 
 static void string_cleanup(void *datap)
 {
     StringSerializeData *d = datap;
+
     string_output_visitor_cleanup(d->sov);
     string_input_visitor_cleanup(d->siv);
+    g_free(d->string);
+    g_free(d);
 }
 
 /* visitor registration, test harness */
diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c
index a6ad213de8..2869129df3 100644
--- a/tests/tmp105-test.c
+++ b/tests/tmp105-test.c
@@ -8,7 +8,7 @@
  */
 #include "libqtest.h"
 #include "libi2c.h"
-#include "hw/tmp105_regs.h"
+#include "hw/misc/tmp105_regs.h"
 
 #include <glib.h>
 
diff --git a/tpm/tpm_passthrough.c b/tpm/tpm_passthrough.c
index 80a48d68cd..1fdd66d356 100644
--- a/tpm/tpm_passthrough.c
+++ b/tpm/tpm_passthrough.c
@@ -30,7 +30,7 @@
 #include "backends/tpm.h"
 #include "tpm_int.h"
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "tpm_tis.h"
 #include "tpm_backend.h"
 
diff --git a/tpm/tpm_tis.c b/tpm/tpm_tis.c
index 367f734dc4..f0a4584607 100644
--- a/tpm/tpm_tis.c
+++ b/tpm/tpm_tis.c
@@ -24,7 +24,7 @@
 #include "block/block.h"
 #include "exec/address-spaces.h"
 #include "hw/hw.h"
-#include "hw/pc.h"
+#include "hw/i386/pc.h"
 #include "hw/pci/pci_ids.h"
 #include "tpm/tpm_tis.h"
 #include "qemu-common.h"
diff --git a/tpm/tpm_tis.h b/tpm/tpm_tis.h
index 7f216e56b2..1be4ddc8a1 100644
--- a/tpm/tpm_tis.h
+++ b/tpm/tpm_tis.h
@@ -17,7 +17,7 @@
 #ifndef TPM_TPM_TIS_H
 #define TPM_TPM_TIS_H
 
-#include "hw/isa.h"
+#include "hw/isa/isa.h"
 #include "qemu-common.h"
 
 #define TPM_TIS_ADDR_BASE           0xFED40000
diff --git a/trace-events b/trace-events
index 7f34112424..412f7e40f8 100644
--- a/trace-events
+++ b/trace-events
@@ -380,6 +380,7 @@ usb_xhci_xfer_nak(void *xfer) "%p"
 usb_xhci_xfer_retry(void *xfer) "%p"
 usb_xhci_xfer_success(void *xfer, uint32_t bytes) "%p: len %d"
 usb_xhci_xfer_error(void *xfer, uint32_t ret) "%p: ret %d"
+usb_xhci_unimplemented(const char *item, int nr) "%s (0x%x)"
 
 # hw/usb/desc.c
 usb_desc_device(int addr, int len, int ret) "dev %d query device, len %d, ret %d"
diff --git a/vl.c b/vl.c
index a8bba043a2..d694a9039b 100644
--- a/vl.c
+++ b/vl.c
@@ -117,12 +117,12 @@ int main(int argc, char **argv)
 #include "hw/boards.h"
 #include "hw/usb.h"
 #include "hw/pcmcia.h"
-#include "hw/pc.h"
-#include "hw/isa.h"
+#include "hw/i386/pc.h"
+#include "hw/isa/isa.h"
 #include "hw/bt.h"
-#include "hw/watchdog.h"
-#include "hw/smbios.h"
-#include "hw/xen.h"
+#include "sysemu/watchdog.h"
+#include "hw/i386/smbios.h"
+#include "hw/xen/xen.h"
 #include "hw/qdev.h"
 #include "hw/loader.h"
 #include "monitor/qdev.h"
@@ -137,7 +137,7 @@ int main(int argc, char **argv)
 #include "char/char.h"
 #include "qemu/cache-utils.h"
 #include "sysemu/blockdev.h"
-#include "hw/block-common.h"
+#include "hw/block/block.h"
 #include "migration/block.h"
 #include "tpm/tpm.h"
 #include "sysemu/dma.h"
diff --git a/xen-all.c b/xen-all.c
index 8c05843faf..31f28fc1ae 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -11,9 +11,9 @@
 #include <sys/mman.h>
 
 #include "hw/pci/pci.h"
-#include "hw/pc.h"
-#include "hw/xen_common.h"
-#include "hw/xen_backend.h"
+#include "hw/i386/pc.h"
+#include "hw/xen/xen_common.h"
+#include "hw/xen/xen_backend.h"
 #include "qmp-commands.h"
 
 #include "char/char.h"
diff --git a/xen-mapcache.c b/xen-mapcache.c
index 5a626cdf84..eda914a75c 100644
--- a/xen-mapcache.c
+++ b/xen-mapcache.c
@@ -12,7 +12,7 @@
 
 #include <sys/resource.h>
 
-#include "hw/xen_backend.h"
+#include "hw/xen/xen_backend.h"
 #include "sysemu/blockdev.h"
 #include "qemu/bitmap.h"
 
diff --git a/xen-stub.c b/xen-stub.c
index 1ee841137e..6f0516aa3e 100644
--- a/xen-stub.c
+++ b/xen-stub.c
@@ -9,7 +9,7 @@
  */
 
 #include "qemu-common.h"
-#include "hw/xen.h"
+#include "hw/xen/xen.h"
 #include "exec/memory.h"
 #include "qmp-commands.h"