1 /* 2 * QEMU USB EHCI Emulation 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or(at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include "hw/usb/hcd-ehci.h" 19 20 static const VMStateDescription vmstate_ehci_sysbus = { 21 .name = "ehci-sysbus", 22 .version_id = 2, 23 .minimum_version_id = 1, 24 .fields = (VMStateField[]) { 25 VMSTATE_STRUCT(ehci, EHCISysBusState, 2, vmstate_ehci, EHCIState), 26 VMSTATE_END_OF_LIST() 27 } 28 }; 29 30 static Property ehci_sysbus_properties[] = { 31 DEFINE_PROP_UINT32("maxframes", EHCISysBusState, ehci.maxframes, 128), 32 DEFINE_PROP_END_OF_LIST(), 33 }; 34 35 static int usb_ehci_sysbus_initfn(SysBusDevice *dev) 36 { 37 EHCISysBusState *i = SYS_BUS_EHCI(dev); 38 SysBusEHCIClass *sec = SYS_BUS_EHCI_GET_CLASS(dev); 39 EHCIState *s = &i->ehci; 40 41 s->capsbase = sec->capsbase; 42 s->opregbase = sec->opregbase; 43 s->dma = &dma_context_memory; 44 45 usb_ehci_initfn(s, DEVICE(dev)); 46 sysbus_init_irq(dev, &s->irq); 47 sysbus_init_mmio(dev, &s->mem); 48 return 0; 49 } 50 51 static void ehci_sysbus_class_init(ObjectClass *klass, void *data) 52 { 53 DeviceClass *dc = DEVICE_CLASS(klass); 54 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 55 56 k->init = usb_ehci_sysbus_initfn; 57 dc->vmsd = &vmstate_ehci_sysbus; 58 dc->props = ehci_sysbus_properties; 59 } 60 61 static const TypeInfo ehci_type_info = { 62 .name = TYPE_SYS_BUS_EHCI, 63 .parent = TYPE_SYS_BUS_DEVICE, 64 .instance_size = sizeof(EHCISysBusState), 65 .abstract = true, 66 .class_init = ehci_sysbus_class_init, 67 .class_size = sizeof(SysBusEHCIClass), 68 }; 69 70 static void ehci_xlnx_class_init(ObjectClass *oc, void *data) 71 { 72 SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); 73 74 sec->capsbase = 0x100; 75 sec->opregbase = 0x140; 76 } 77 78 static const TypeInfo ehci_xlnx_type_info = { 79 .name = "xlnx,ps7-usb", 80 .parent = TYPE_SYS_BUS_EHCI, 81 .class_init = ehci_xlnx_class_init, 82 }; 83 84 static void ehci_exynos4210_class_init(ObjectClass *oc, void *data) 85 { 86 SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); 87 88 sec->capsbase = 0x0; 89 sec->opregbase = 0x10; 90 } 91 92 static const TypeInfo ehci_exynos4210_type_info = { 93 .name = TYPE_EXYNOS4210_EHCI, 94 .parent = TYPE_SYS_BUS_EHCI, 95 .class_init = ehci_exynos4210_class_init, 96 }; 97 98 static void ehci_sysbus_register_types(void) 99 { 100 type_register_static(&ehci_type_info); 101 type_register_static(&ehci_xlnx_type_info); 102 type_register_static(&ehci_exynos4210_type_info); 103 } 104 105 type_init(ehci_sysbus_register_types) 106