xref: /openbmc/qemu/hw/usb/hcd-ehci-sysbus.c (revision 1f32989d)
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 
49     usb_ehci_initfn(s, DEVICE(dev));
50     sysbus_init_irq(dev, &s->irq);
51     sysbus_init_mmio(dev, &s->mem);
52     return 0;
53 }
54 
55 static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
56 {
57     DeviceClass *dc = DEVICE_CLASS(klass);
58     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
59 
60     k->init = usb_ehci_sysbus_initfn;
61     dc->vmsd = &vmstate_ehci_sysbus;
62     dc->props = ehci_sysbus_properties;
63 }
64 
65 TypeInfo ehci_xlnx_type_info = {
66     .name          = "xlnx,ps7-usb",
67     .parent        = TYPE_SYS_BUS_DEVICE,
68     .instance_size = sizeof(EHCISysBusState),
69     .class_init    = ehci_sysbus_class_init,
70 };
71 
72 static void ehci_sysbus_register_types(void)
73 {
74     type_register_static(&ehci_xlnx_type_info);
75 }
76 
77 type_init(ehci_sysbus_register_types)
78