@@ -132,6 +132,7 @@ typedef struct UHCIPort {
struct UHCIState {
PCIDevice dev;
+ MemoryRegion io_bar;
USBBus bus;
uint16_t cmd; /* cmd register */
uint16_t status;
@@ -1083,19 +1084,38 @@ static void uhci_frame_timer(void *opaque)
qemu_mod_timer(s->frame_timer, s->expire_time);
}
-static void uhci_map(PCIDevice *pci_dev, int region_num,
- pcibus_t addr, pcibus_t size, int type)
+static uint64_t uhci_ioport_read(void *opaque, target_phys_addr_t addr,
+ unsigned size)
{
- UHCIState *s = (UHCIState *)pci_dev;
-
- register_ioport_write(addr, 32, 2, uhci_ioport_writew, s);
- register_ioport_read(addr, 32, 2, uhci_ioport_readw, s);
- register_ioport_write(addr, 32, 4, uhci_ioport_writel, s);
- register_ioport_read(addr, 32, 4, uhci_ioport_readl, s);
- register_ioport_write(addr, 32, 1, uhci_ioport_writeb, s);
- register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
+ UHCIState *s = opaque;
+
+ switch (size) {
+ case 1: return uhci_ioport_readb(s, addr);
+ case 2: return uhci_ioport_readw(s, addr);
+ case 4: return uhci_ioport_readl(s, addr);
+ default: abort();
+ }
+}
+
+static void uhci_ioport_write(void *opaque, target_phys_addr_t addr,
+ uint64_t data, unsigned size)
+{
+ UHCIState *s = opaque;
+
+ switch (size) {
+ case 1: return uhci_ioport_writeb(s, addr, data);
+ case 2: return uhci_ioport_writew(s, addr, data);
+ case 4: return uhci_ioport_writel(s, addr, data);
+ default: abort();
+ }
}
+static MemoryRegionOps uhci_ioport_ops = {
+ .read = uhci_ioport_read,
+ .write = uhci_ioport_write,
+ .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
static void uhci_device_destroy(USBBus *bus, USBDevice *dev)
{
UHCIState *s = container_of(bus, UHCIState, bus);
@@ -1137,10 +1157,11 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
qemu_register_reset(uhci_reset, s);
+ memory_region_init_io(&s->io_bar, &uhci_ioport_ops, s, "uhci", 0x20);
/* Use region 4 for consistency with real hardware. BSD guests seem
to rely on this. */
- pci_register_bar(&s->dev, 4, 0x20,
- PCI_BASE_ADDRESS_SPACE_IO, uhci_map);
+ pci_register_bar_region(&s->dev, 4,
+ PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar);
return 0;
}
@@ -1160,12 +1181,22 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
return usb_uhci_common_initfn(dev);
}
+static int usb_uhci_exit(PCIDevice *dev)
+{
+ UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
+
+ memory_region_destroy(&s->io_bar);
+ return 0;
+}
+
+
static PCIDeviceInfo uhci_info[] = {
{
.qdev.name = "piix3-usb-uhci",
.qdev.size = sizeof(UHCIState),
.qdev.vmsd = &vmstate_uhci,
.init = usb_uhci_common_initfn,
+ .exit = usb_uhci_exit,
.vendor_id = PCI_VENDOR_ID_INTEL,
.device_id = PCI_DEVICE_ID_INTEL_82371SB_2,
.revision = 0x01,
@@ -1175,6 +1206,7 @@ static PCIDeviceInfo uhci_info[] = {
.qdev.size = sizeof(UHCIState),
.qdev.vmsd = &vmstate_uhci,
.init = usb_uhci_common_initfn,
+ .exit = usb_uhci_exit,
.vendor_id = PCI_VENDOR_ID_INTEL,
.device_id = PCI_DEVICE_ID_INTEL_82371AB_2,
.revision = 0x01,
@@ -1184,6 +1216,7 @@ static PCIDeviceInfo uhci_info[] = {
.qdev.size = sizeof(UHCIState),
.qdev.vmsd = &vmstate_uhci,
.init = usb_uhci_vt82c686b_initfn,
+ .exit = usb_uhci_exit,
.vendor_id = PCI_VENDOR_ID_VIA,
.device_id = PCI_DEVICE_ID_VIA_UHCI,
.revision = 0x01,
Signed-off-by: Avi Kivity <avi@redhat.com> --- hw/usb-uhci.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 45 insertions(+), 12 deletions(-)