Fixed calculation error of pkt->header_size in fill_pkt_tcp_info()
[qemu.git] / hw / usb / hcd-xhci-sysbus.c
bloba14e4381960ef5d34d0567ed1b58eb55375a3e61
1 /*
2 * USB xHCI controller for system-bus interface
3 * Based on hcd-echi-sysbus.c
5 * SPDX-FileCopyrightText: 2020 Xilinx
6 * SPDX-FileContributor: Author: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10 #include "qemu/osdep.h"
11 #include "hw/qdev-properties.h"
12 #include "migration/vmstate.h"
13 #include "trace.h"
14 #include "qapi/error.h"
15 #include "hcd-xhci-sysbus.h"
16 #include "hw/acpi/aml-build.h"
17 #include "hw/irq.h"
19 static bool xhci_sysbus_intr_raise(XHCIState *xhci, int n, bool level)
21 XHCISysbusState *s = container_of(xhci, XHCISysbusState, xhci);
23 qemu_set_irq(s->irq[n], level);
25 return false;
28 void xhci_sysbus_reset(DeviceState *dev)
30 XHCISysbusState *s = XHCI_SYSBUS(dev);
32 device_legacy_reset(DEVICE(&s->xhci));
35 static void xhci_sysbus_realize(DeviceState *dev, Error **errp)
37 XHCISysbusState *s = XHCI_SYSBUS(dev);
39 object_property_set_link(OBJECT(&s->xhci), "host", OBJECT(s), NULL);
40 if (!qdev_realize(DEVICE(&s->xhci), NULL, errp)) {
41 return;
43 s->irq = g_new0(qemu_irq, s->xhci.numintrs);
44 qdev_init_gpio_out_named(dev, s->irq, SYSBUS_DEVICE_GPIO_IRQ,
45 s->xhci.numintrs);
46 if (s->xhci.dma_mr) {
47 s->xhci.as = g_malloc0(sizeof(AddressSpace));
48 address_space_init(s->xhci.as, s->xhci.dma_mr, NULL);
49 } else {
50 s->xhci.as = &address_space_memory;
53 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->xhci.mem);
56 static void xhci_sysbus_instance_init(Object *obj)
58 XHCISysbusState *s = XHCI_SYSBUS(obj);
60 object_initialize_child(obj, "xhci-core", &s->xhci, TYPE_XHCI);
61 qdev_alias_all_properties(DEVICE(&s->xhci), obj);
63 object_property_add_link(obj, "dma", TYPE_MEMORY_REGION,
64 (Object **)&s->xhci.dma_mr,
65 qdev_prop_allow_set_link_before_realize,
66 OBJ_PROP_LINK_STRONG);
67 s->xhci.intr_update = NULL;
68 s->xhci.intr_raise = xhci_sysbus_intr_raise;
71 void xhci_sysbus_build_aml(Aml *scope, uint32_t mmio, unsigned int irq)
73 Aml *dev = aml_device("XHCI");
74 Aml *crs = aml_resource_template();
76 aml_append(crs, aml_memory32_fixed(mmio, XHCI_LEN_REGS, AML_READ_WRITE));
77 aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
78 AML_EXCLUSIVE, &irq, 1));
80 aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0D10")));
81 aml_append(dev, aml_name_decl("_CRS", crs));
82 aml_append(scope, dev);
85 static Property xhci_sysbus_props[] = {
86 DEFINE_PROP_UINT32("intrs", XHCISysbusState, xhci.numintrs, XHCI_MAXINTRS),
87 DEFINE_PROP_UINT32("slots", XHCISysbusState, xhci.numslots, XHCI_MAXSLOTS),
88 DEFINE_PROP_END_OF_LIST(),
91 static const VMStateDescription vmstate_xhci_sysbus = {
92 .name = "xhci-sysbus",
93 .version_id = 1,
94 .fields = (VMStateField[]) {
95 VMSTATE_STRUCT(xhci, XHCISysbusState, 1, vmstate_xhci, XHCIState),
96 VMSTATE_END_OF_LIST()
100 static void xhci_sysbus_class_init(ObjectClass *klass, void *data)
102 DeviceClass *dc = DEVICE_CLASS(klass);
104 dc->reset = xhci_sysbus_reset;
105 dc->realize = xhci_sysbus_realize;
106 dc->vmsd = &vmstate_xhci_sysbus;
107 device_class_set_props(dc, xhci_sysbus_props);
110 static const TypeInfo xhci_sysbus_info = {
111 .name = TYPE_XHCI_SYSBUS,
112 .parent = TYPE_SYS_BUS_DEVICE,
113 .instance_size = sizeof(XHCISysbusState),
114 .class_init = xhci_sysbus_class_init,
115 .instance_init = xhci_sysbus_instance_init
118 static void xhci_sysbus_register_types(void)
120 type_register_static(&xhci_sysbus_info);
123 type_init(xhci_sysbus_register_types);