2 * QEMU USB EHCI Emulation
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.1 of the License, or (at your option) any later version.
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.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "qemu/osdep.h"
19 #include "hw/usb/hcd-ehci.h"
20 #include "migration/vmstate.h"
21 #include "qemu/module.h"
23 static const VMStateDescription vmstate_ehci_sysbus
= {
24 .name
= "ehci-sysbus",
26 .minimum_version_id
= 1,
27 .fields
= (VMStateField
[]) {
28 VMSTATE_STRUCT(ehci
, EHCISysBusState
, 2, vmstate_ehci
, EHCIState
),
33 static Property ehci_sysbus_properties
[] = {
34 DEFINE_PROP_UINT32("maxframes", EHCISysBusState
, ehci
.maxframes
, 128),
35 DEFINE_PROP_END_OF_LIST(),
38 static void usb_ehci_sysbus_realize(DeviceState
*dev
, Error
**errp
)
40 SysBusDevice
*d
= SYS_BUS_DEVICE(dev
);
41 EHCISysBusState
*i
= SYS_BUS_EHCI(dev
);
42 EHCIState
*s
= &i
->ehci
;
44 usb_ehci_realize(s
, dev
, errp
);
45 sysbus_init_irq(d
, &s
->irq
);
48 static void usb_ehci_sysbus_reset(DeviceState
*dev
)
50 SysBusDevice
*d
= SYS_BUS_DEVICE(dev
);
51 EHCISysBusState
*i
= SYS_BUS_EHCI(d
);
52 EHCIState
*s
= &i
->ehci
;
57 static void ehci_sysbus_init(Object
*obj
)
59 SysBusDevice
*d
= SYS_BUS_DEVICE(obj
);
60 EHCISysBusState
*i
= SYS_BUS_EHCI(obj
);
61 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_GET_CLASS(obj
);
62 EHCIState
*s
= &i
->ehci
;
64 s
->capsbase
= sec
->capsbase
;
65 s
->opregbase
= sec
->opregbase
;
66 s
->portscbase
= sec
->portscbase
;
67 s
->portnr
= sec
->portnr
;
68 s
->as
= &address_space_memory
;
70 usb_ehci_init(s
, DEVICE(obj
));
71 sysbus_init_mmio(d
, &s
->mem
);
74 static void ehci_sysbus_class_init(ObjectClass
*klass
, void *data
)
76 DeviceClass
*dc
= DEVICE_CLASS(klass
);
77 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_CLASS(klass
);
79 sec
->portscbase
= 0x44;
80 sec
->portnr
= NB_PORTS
;
82 dc
->realize
= usb_ehci_sysbus_realize
;
83 dc
->vmsd
= &vmstate_ehci_sysbus
;
84 dc
->props
= ehci_sysbus_properties
;
85 dc
->reset
= usb_ehci_sysbus_reset
;
86 set_bit(DEVICE_CATEGORY_USB
, dc
->categories
);
89 static const TypeInfo ehci_type_info
= {
90 .name
= TYPE_SYS_BUS_EHCI
,
91 .parent
= TYPE_SYS_BUS_DEVICE
,
92 .instance_size
= sizeof(EHCISysBusState
),
93 .instance_init
= ehci_sysbus_init
,
95 .class_init
= ehci_sysbus_class_init
,
96 .class_size
= sizeof(SysBusEHCIClass
),
99 static void ehci_platform_class_init(ObjectClass
*oc
, void *data
)
101 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_CLASS(oc
);
102 DeviceClass
*dc
= DEVICE_CLASS(oc
);
105 sec
->opregbase
= 0x20;
106 set_bit(DEVICE_CATEGORY_USB
, dc
->categories
);
109 static const TypeInfo ehci_platform_type_info
= {
110 .name
= TYPE_PLATFORM_EHCI
,
111 .parent
= TYPE_SYS_BUS_EHCI
,
112 .class_init
= ehci_platform_class_init
,
115 static void ehci_xlnx_class_init(ObjectClass
*oc
, void *data
)
117 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_CLASS(oc
);
118 DeviceClass
*dc
= DEVICE_CLASS(oc
);
120 set_bit(DEVICE_CATEGORY_USB
, dc
->categories
);
121 sec
->capsbase
= 0x100;
122 sec
->opregbase
= 0x140;
125 static const TypeInfo ehci_xlnx_type_info
= {
126 .name
= "xlnx,ps7-usb",
127 .parent
= TYPE_SYS_BUS_EHCI
,
128 .class_init
= ehci_xlnx_class_init
,
131 static void ehci_exynos4210_class_init(ObjectClass
*oc
, void *data
)
133 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_CLASS(oc
);
134 DeviceClass
*dc
= DEVICE_CLASS(oc
);
137 sec
->opregbase
= 0x10;
138 set_bit(DEVICE_CATEGORY_USB
, dc
->categories
);
141 static const TypeInfo ehci_exynos4210_type_info
= {
142 .name
= TYPE_EXYNOS4210_EHCI
,
143 .parent
= TYPE_SYS_BUS_EHCI
,
144 .class_init
= ehci_exynos4210_class_init
,
147 static void ehci_tegra2_class_init(ObjectClass
*oc
, void *data
)
149 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_CLASS(oc
);
150 DeviceClass
*dc
= DEVICE_CLASS(oc
);
152 sec
->capsbase
= 0x100;
153 sec
->opregbase
= 0x140;
154 set_bit(DEVICE_CATEGORY_USB
, dc
->categories
);
157 static const TypeInfo ehci_tegra2_type_info
= {
158 .name
= TYPE_TEGRA2_EHCI
,
159 .parent
= TYPE_SYS_BUS_EHCI
,
160 .class_init
= ehci_tegra2_class_init
,
163 static void ehci_ppc4xx_init(Object
*o
)
165 EHCISysBusState
*s
= SYS_BUS_EHCI(o
);
167 s
->ehci
.companion_enable
= true;
170 static void ehci_ppc4xx_class_init(ObjectClass
*oc
, void *data
)
172 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_CLASS(oc
);
173 DeviceClass
*dc
= DEVICE_CLASS(oc
);
176 sec
->opregbase
= 0x10;
177 set_bit(DEVICE_CATEGORY_USB
, dc
->categories
);
180 static const TypeInfo ehci_ppc4xx_type_info
= {
181 .name
= TYPE_PPC4xx_EHCI
,
182 .parent
= TYPE_SYS_BUS_EHCI
,
183 .class_init
= ehci_ppc4xx_class_init
,
184 .instance_init
= ehci_ppc4xx_init
,
188 * Faraday FUSBH200 USB 2.0 EHCI
193 * @FUSBH200_REG_EOF_ASTR: EOF/Async. Sleep Timer Register
194 * @FUSBH200_REG_BMCSR: Bus Monitor Control/Status Register
196 enum FUSBH200EHCIRegs
{
197 FUSBH200_REG_EOF_ASTR
= 0x34,
198 FUSBH200_REG_BMCSR
= 0x40,
201 static uint64_t fusbh200_ehci_read(void *opaque
, hwaddr addr
, unsigned size
)
203 EHCIState
*s
= opaque
;
204 hwaddr off
= s
->opregbase
+ s
->portscbase
+ 4 * s
->portnr
+ addr
;
207 case FUSBH200_REG_EOF_ASTR
:
209 case FUSBH200_REG_BMCSR
:
210 /* High-Speed, VBUS valid, interrupt level-high active */
211 return (2 << 9) | (1 << 8) | (1 << 3);
217 static void fusbh200_ehci_write(void *opaque
, hwaddr addr
, uint64_t val
,
222 static const MemoryRegionOps fusbh200_ehci_mmio_ops
= {
223 .read
= fusbh200_ehci_read
,
224 .write
= fusbh200_ehci_write
,
225 .valid
.min_access_size
= 4,
226 .valid
.max_access_size
= 4,
227 .endianness
= DEVICE_LITTLE_ENDIAN
,
230 static void fusbh200_ehci_init(Object
*obj
)
232 EHCISysBusState
*i
= SYS_BUS_EHCI(obj
);
233 FUSBH200EHCIState
*f
= FUSBH200_EHCI(obj
);
234 EHCIState
*s
= &i
->ehci
;
236 memory_region_init_io(&f
->mem_vendor
, OBJECT(f
), &fusbh200_ehci_mmio_ops
, s
,
238 memory_region_add_subregion(&s
->mem
,
239 s
->opregbase
+ s
->portscbase
+ 4 * s
->portnr
,
243 static void fusbh200_ehci_class_init(ObjectClass
*oc
, void *data
)
245 SysBusEHCIClass
*sec
= SYS_BUS_EHCI_CLASS(oc
);
246 DeviceClass
*dc
= DEVICE_CLASS(oc
);
249 sec
->opregbase
= 0x10;
250 sec
->portscbase
= 0x20;
252 set_bit(DEVICE_CATEGORY_USB
, dc
->categories
);
255 static const TypeInfo ehci_fusbh200_type_info
= {
256 .name
= TYPE_FUSBH200_EHCI
,
257 .parent
= TYPE_SYS_BUS_EHCI
,
258 .instance_size
= sizeof(FUSBH200EHCIState
),
259 .instance_init
= fusbh200_ehci_init
,
260 .class_init
= fusbh200_ehci_class_init
,
263 static void ehci_sysbus_register_types(void)
265 type_register_static(&ehci_type_info
);
266 type_register_static(&ehci_platform_type_info
);
267 type_register_static(&ehci_xlnx_type_info
);
268 type_register_static(&ehci_exynos4210_type_info
);
269 type_register_static(&ehci_tegra2_type_info
);
270 type_register_static(&ehci_ppc4xx_type_info
);
271 type_register_static(&ehci_fusbh200_type_info
);
274 type_init(ehci_sysbus_register_types
)