[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 12/26] usb/uhci: generalize initialization
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH 12/26] usb/uhci: generalize initialization |
Date: |
Wed, 16 Mar 2011 18:29:23 +0900 |
generalize initialization to make vendir/device id
customizable.
Signed-off-by: Isaku Yamahata <address@hidden>
---
hw/usb-uhci.c | 87 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 43 insertions(+), 44 deletions(-)
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index b384e1d..2fb2a85 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1115,12 +1115,25 @@ static USBPortOps uhci_port_ops = {
.wakeup = uhci_wakeup,
};
-static int usb_uhci_common_initfn(UHCIState *s)
+typedef struct UHCIDeviceInfo {
+ PCIDeviceInfo pci;
+ uint16_t vendor_id;
+ uint16_t device_id;
+ uint8_t revision_id;
+} UHCIDeviceInfo;
+
+static int usb_uhci_common_initfn(PCIDevice *dev)
{
+ UHCIDeviceInfo *uhci_info = DO_UPCAST(UHCIDeviceInfo, pci.qdev,
+ dev->qdev.info);
+ UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
uint8_t *pci_conf = s->dev.config;
int i;
- pci_conf[PCI_REVISION_ID] = 0x01; // revision number
+ pci_config_set_vendor_id(pci_conf, uhci_info->vendor_id);
+ pci_config_set_device_id(pci_conf, uhci_info->device_id);
+ pci_config_set_revision(pci_conf, uhci_info->revision_id);
+
pci_conf[PCI_CLASS_PROG] = 0x00;
pci_config_set_class(pci_conf, PCI_CLASS_SERIAL_USB);
/* TODO: reset value should be 0. */
@@ -1148,34 +1161,10 @@ static int usb_uhci_common_initfn(UHCIState *s)
return 0;
}
-static int usb_uhci_piix3_initfn(PCIDevice *dev)
-{
- UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
- uint8_t *pci_conf = s->dev.config;
-
- pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
- pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_2);
- return usb_uhci_common_initfn(s);
-}
-
-static int usb_uhci_piix4_initfn(PCIDevice *dev)
-{
- UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
- uint8_t *pci_conf = s->dev.config;
-
- pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
- pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_2);
- return usb_uhci_common_initfn(s);
-}
-
static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
{
UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
uint8_t *pci_conf = s->dev.config;
-
- pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_VIA);
- pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_VIA_UHCI);
-
/* USB misc control 1/2 */
pci_set_long(pci_conf + 0x40,0x00001000);
/* PM capability */
@@ -1183,33 +1172,43 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
/* USB legacy support */
pci_set_long(pci_conf + 0xc0,0x00002000);
- return usb_uhci_common_initfn(s);
+ return usb_uhci_common_initfn(dev);
}
-static PCIDeviceInfo uhci_info[] = {
+static UHCIDeviceInfo uhci_info[] = {
{
- .qdev.name = "piix3-usb-uhci",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_piix3_initfn,
- },{
- .qdev.name = "piix4-usb-uhci",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_piix4_initfn,
+ .pci.qdev.name = "piix3-usb-uhci",
+ .pci.qdev.size = sizeof(UHCIState),
+ .pci.qdev.vmsd = &vmstate_uhci,
+ .pci.init = usb_uhci_common_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82371SB_2,
+ .revision_id = 0x01,
},{
- .qdev.name = "vt82c686b-usb-uhci",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_vt82c686b_initfn,
+ .pci.qdev.name = "piix4-usb-uhci",
+ .pci.qdev.size = sizeof(UHCIState),
+ .pci.qdev.vmsd = &vmstate_uhci,
+ .pci.init = usb_uhci_common_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82371AB_2,
+ .revision_id = 0x01,
},{
- /* end of list */
- }
+ .pci.qdev.name = "vt82c686b-usb-uhci",
+ .pci.qdev.size = sizeof(UHCIState),
+ .pci.qdev.vmsd = &vmstate_uhci,
+ .pci.init = usb_uhci_vt82c686b_initfn,
+ .vendor_id = PCI_VENDOR_ID_VIA,
+ .device_id = PCI_DEVICE_ID_VIA_UHCI,
+ .revision_id = 0x01,
+ },
};
static void uhci_register(void)
{
- pci_qdev_register_many(uhci_info);
+ int i;
+ for (i = 0; i < ARRAY_SIZE(uhci_info); i++) {
+ pci_qdev_register(&uhci_info[i].pci);
+ }
}
device_init(uhci_register);
--
1.7.1.1
- [Qemu-devel] Re: [PATCH 04/26] pci: add accessor function to get irq levels, (continued)
[Qemu-devel] [PATCH 19/26] pc/piix_pci: factor out smram/pam logic, Isaku Yamahata, 2011/03/16
[Qemu-devel] [PATCH 12/26] usb/uhci: generalize initialization,
Isaku Yamahata <=
[Qemu-devel] [PATCH 26/26] pc q35 based chipset emulator, Isaku Yamahata, 2011/03/16
[Qemu-devel] [PATCH 05/26] piix_pci: eliminate PIIX3State::pci_irq_levels, Isaku Yamahata, 2011/03/16
[Qemu-devel] ACPI table loading [was: q35 chipset support for native pci express support], Michael Tokarev, 2011/03/16