]> git.proxmox.com Git - mirror_qemu.git/blame - hw/usb/hcd-ehci-pci.c
i386: Add x-force-features option for testing
[mirror_qemu.git] / hw / usb / hcd-ehci-pci.c
CommitLineData
0bf96f94
GH
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
75a49fc6 7 * version 2.1 of the License, or (at your option) any later version.
0bf96f94
GH
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 *
75a49fc6 14 * You should have received a copy of the GNU Lesser General Public License
0bf96f94
GH
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
e532b2e0 18#include "qemu/osdep.h"
0bf96f94 19#include "hw/usb/hcd-ehci.h"
0b8fa32f 20#include "qemu/module.h"
1de7afc9 21#include "qemu/range.h"
0bf96f94 22
df013187
GH
23typedef struct EHCIPCIInfo {
24 const char *name;
25 uint16_t vendor_id;
26 uint16_t device_id;
27 uint8_t revision;
ec56214f 28 bool companion;
df013187
GH
29} EHCIPCIInfo;
30
9af21dbe 31static void usb_ehci_pci_realize(PCIDevice *dev, Error **errp)
0bf96f94 32{
5aa3ca9f 33 EHCIPCIState *i = PCI_EHCI(dev);
0bf96f94
GH
34 EHCIState *s = &i->ehci;
35 uint8_t *pci_conf = dev->config;
36
37 pci_set_byte(&pci_conf[PCI_CLASS_PROG], 0x20);
38
39 /* capabilities pointer */
40 pci_set_byte(&pci_conf[PCI_CAPABILITY_LIST], 0x00);
41 /* pci_set_byte(&pci_conf[PCI_CAPABILITY_LIST], 0x50); */
42
43 pci_set_byte(&pci_conf[PCI_INTERRUPT_PIN], 4); /* interrupt pin D */
44 pci_set_byte(&pci_conf[PCI_MIN_GNT], 0);
45 pci_set_byte(&pci_conf[PCI_MAX_LAT], 0);
46
47 /* pci_conf[0x50] = 0x01; *//* power management caps */
48
49 pci_set_byte(&pci_conf[USB_SBRN], USB_RELEASE_2); /* release # (2.1.4) */
50 pci_set_byte(&pci_conf[0x61], 0x20); /* frame length adjustment (2.1.5) */
51 pci_set_word(&pci_conf[0x62], 0x00); /* port wake up capability (2.1.6) */
52
53 pci_conf[0x64] = 0x00;
54 pci_conf[0x65] = 0x00;
55 pci_conf[0x66] = 0x00;
56 pci_conf[0x67] = 0x00;
57 pci_conf[0x68] = 0x01;
58 pci_conf[0x69] = 0x00;
59 pci_conf[0x6a] = 0x00;
60 pci_conf[0x6b] = 0x00; /* USBLEGSUP */
61 pci_conf[0x6c] = 0x00;
62 pci_conf[0x6d] = 0x00;
63 pci_conf[0x6e] = 0x00;
64 pci_conf[0x6f] = 0xc0; /* USBLEFCTLSTS */
65
9e64f8a3 66 s->irq = pci_allocate_irq(dev);
df32fd1c 67 s->as = pci_get_address_space(dev);
0bf96f94 68
08f4c90b 69 usb_ehci_realize(s, DEVICE(dev), NULL);
0bf96f94 70 pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mem);
0bf96f94
GH
71}
72
d4614cc3
AF
73static void usb_ehci_pci_init(Object *obj)
74{
ec56214f 75 DeviceClass *dc = OBJECT_GET_CLASS(DeviceClass, obj, TYPE_DEVICE);
d4614cc3
AF
76 EHCIPCIState *i = PCI_EHCI(obj);
77 EHCIState *s = &i->ehci;
78
79 s->caps[0x09] = 0x68; /* EECP */
80
81 s->capsbase = 0x00;
82 s->opregbase = 0x20;
cc8d6a84
KJS
83 s->portscbase = 0x44;
84 s->portnr = NB_PORTS;
d4614cc3 85
ec56214f
GH
86 if (!dc->hotpluggable) {
87 s->companion_enable = true;
88 }
89
d4614cc3
AF
90 usb_ehci_init(s, DEVICE(obj));
91}
92
d710e1e7
LQ
93static void usb_ehci_pci_finalize(Object *obj)
94{
95 EHCIPCIState *i = PCI_EHCI(obj);
96 EHCIState *s = &i->ehci;
97
98 usb_ehci_finalize(s);
99}
100
96e14926
GA
101static void usb_ehci_pci_exit(PCIDevice *dev)
102{
103 EHCIPCIState *i = PCI_EHCI(dev);
104 EHCIState *s = &i->ehci;
105
106 usb_ehci_unrealize(s, DEVICE(dev), NULL);
107
012aef07
MA
108 g_free(s->irq);
109 s->irq = NULL;
96e14926
GA
110}
111
4e289b1b
GA
112static void usb_ehci_pci_reset(DeviceState *dev)
113{
114 PCIDevice *pci_dev = PCI_DEVICE(dev);
115 EHCIPCIState *i = PCI_EHCI(pci_dev);
116 EHCIState *s = &i->ehci;
117
118 ehci_reset(s);
119}
120
55903f1d
GH
121static void usb_ehci_pci_write_config(PCIDevice *dev, uint32_t addr,
122 uint32_t val, int l)
123{
5aa3ca9f 124 EHCIPCIState *i = PCI_EHCI(dev);
55903f1d
GH
125 bool busmaster;
126
127 pci_default_write_config(dev, addr, val, l);
128
129 if (!range_covers_byte(addr, l, PCI_COMMAND)) {
130 return;
131 }
132 busmaster = pci_get_word(dev->config + PCI_COMMAND) & PCI_COMMAND_MASTER;
df32fd1c 133 i->ehci.as = busmaster ? pci_get_address_space(dev) : &address_space_memory;
55903f1d
GH
134}
135
0bf96f94
GH
136static Property ehci_pci_properties[] = {
137 DEFINE_PROP_UINT32("maxframes", EHCIPCIState, ehci.maxframes, 128),
138 DEFINE_PROP_END_OF_LIST(),
139};
140
141static const VMStateDescription vmstate_ehci_pci = {
142 .name = "ehci",
143 .version_id = 2,
144 .minimum_version_id = 1,
6e3d652a 145 .fields = (VMStateField[]) {
0bf96f94
GH
146 VMSTATE_PCI_DEVICE(pcidev, EHCIPCIState),
147 VMSTATE_STRUCT(ehci, EHCIPCIState, 2, vmstate_ehci, EHCIState),
9d153047 148 VMSTATE_END_OF_LIST()
0bf96f94
GH
149 }
150};
151
152static void ehci_class_init(ObjectClass *klass, void *data)
153{
154 DeviceClass *dc = DEVICE_CLASS(klass);
155 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
156
9af21dbe 157 k->realize = usb_ehci_pci_realize;
96e14926 158 k->exit = usb_ehci_pci_exit;
0bf96f94 159 k->class_id = PCI_CLASS_SERIAL_USB;
55903f1d 160 k->config_write = usb_ehci_pci_write_config;
9d153047 161 dc->vmsd = &vmstate_ehci_pci;
0bf96f94 162 dc->props = ehci_pci_properties;
4e289b1b 163 dc->reset = usb_ehci_pci_reset;
0bf96f94
GH
164}
165
5aa3ca9f
AF
166static const TypeInfo ehci_pci_type_info = {
167 .name = TYPE_PCI_EHCI,
168 .parent = TYPE_PCI_DEVICE,
169 .instance_size = sizeof(EHCIPCIState),
d4614cc3 170 .instance_init = usb_ehci_pci_init,
d710e1e7 171 .instance_finalize = usb_ehci_pci_finalize,
5aa3ca9f
AF
172 .abstract = true,
173 .class_init = ehci_class_init,
fd3b02c8
EH
174 .interfaces = (InterfaceInfo[]) {
175 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
176 { },
177 },
5aa3ca9f
AF
178};
179
180static void ehci_data_class_init(ObjectClass *klass, void *data)
181{
182 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
125ee0ed 183 DeviceClass *dc = DEVICE_CLASS(klass);
5aa3ca9f
AF
184 EHCIPCIInfo *i = data;
185
186 k->vendor_id = i->vendor_id;
187 k->device_id = i->device_id;
188 k->revision = i->revision;
125ee0ed 189 set_bit(DEVICE_CATEGORY_USB, dc->categories);
ec56214f
GH
190 if (i->companion) {
191 dc->hotpluggable = false;
192 }
5aa3ca9f
AF
193}
194
df013187
GH
195static struct EHCIPCIInfo ehci_pci_info[] = {
196 {
197 .name = "usb-ehci",
198 .vendor_id = PCI_VENDOR_ID_INTEL,
199 .device_id = PCI_DEVICE_ID_INTEL_82801D, /* ich4 */
200 .revision = 0x10,
201 },{
ba07630c 202 .name = "ich9-usb-ehci1", /* 00:1d.7 */
df013187
GH
203 .vendor_id = PCI_VENDOR_ID_INTEL,
204 .device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1,
205 .revision = 0x03,
ec56214f 206 .companion = true,
ba07630c
GH
207 },{
208 .name = "ich9-usb-ehci2", /* 00:1a.7 */
209 .vendor_id = PCI_VENDOR_ID_INTEL,
210 .device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI2,
211 .revision = 0x03,
ec56214f 212 .companion = true,
df013187 213 }
0bf96f94
GH
214};
215
216static void ehci_pci_register_types(void)
217{
df013187 218 TypeInfo ehci_type_info = {
5aa3ca9f
AF
219 .parent = TYPE_PCI_EHCI,
220 .class_init = ehci_data_class_init,
df013187
GH
221 };
222 int i;
223
5aa3ca9f
AF
224 type_register_static(&ehci_pci_type_info);
225
df013187
GH
226 for (i = 0; i < ARRAY_SIZE(ehci_pci_info); i++) {
227 ehci_type_info.name = ehci_pci_info[i].name;
228 ehci_type_info.class_data = ehci_pci_info + i;
229 type_register(&ehci_type_info);
230 }
0bf96f94
GH
231}
232
233type_init(ehci_pci_register_types)