xref: /openbmc/qemu/hw/usb/hcd-ehci-sysbus.c (revision ccff63ca)
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 #include "hw/sysbus.h"
20 
21 typedef struct EHCISysBusState {
22     SysBusDevice busdev;
23     EHCIState ehci;
24 } EHCISysBusState;
25 
26 static const VMStateDescription vmstate_ehci_sysbus = {
27     .name        = "ehci-sysbus",
28     .version_id  = 2,
29     .minimum_version_id  = 1,
30     .fields      = (VMStateField[]) {
31         VMSTATE_STRUCT(ehci, EHCISysBusState, 2, vmstate_ehci, EHCIState),
32         VMSTATE_END_OF_LIST()
33     }
34 };
35 
36 static Property ehci_sysbus_properties[] = {
37     DEFINE_PROP_UINT32("maxframes", EHCISysBusState, ehci.maxframes, 128),
38     DEFINE_PROP_END_OF_LIST(),
39 };
40 
41 static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
42 {
43     EHCISysBusState *i = FROM_SYSBUS(EHCISysBusState, dev);
44     EHCIState *s = &i->ehci;
45 
46     s->capsbase = 0x100;
47     s->opregbase = 0x140;
48     s->dma = &dma_context_memory;
49 
50     usb_ehci_initfn(s, DEVICE(dev));
51     sysbus_init_irq(dev, &s->irq);
52     sysbus_init_mmio(dev, &s->mem);
53     return 0;
54 }
55 
56 static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
57 {
58     DeviceClass *dc = DEVICE_CLASS(klass);
59     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
60 
61     k->init = usb_ehci_sysbus_initfn;
62     dc->vmsd = &vmstate_ehci_sysbus;
63     dc->props = ehci_sysbus_properties;
64 }
65 
66 TypeInfo ehci_xlnx_type_info = {
67     .name          = "xlnx,ps7-usb",
68     .parent        = TYPE_SYS_BUS_DEVICE,
69     .instance_size = sizeof(EHCISysBusState),
70     .class_init    = ehci_sysbus_class_init,
71 };
72 
73 static void ehci_sysbus_register_types(void)
74 {
75     type_register_static(&ehci_xlnx_type_info);
76 }
77 
78 type_init(ehci_sysbus_register_types)
79