hw/usb: Add TI TUSB73X0 XHCI controller model
cover hw/usb: Add TI TUSB73X0 XHCI controller model
Hi,
This adds a new USB XHCI model. The biggest change is really making some XHCI PCI config dynamic and the MSIX init has some changes to support a separate BAR (hopefully now it has better error handling.
Thanks,
Nick
Nicholas Piggin (2):
hw/usb: Make PCI device more configurable
hw/usb: Add TI TUSB73X0 XHCI controller model
hw/usb/hcd-xhci-pci.h | 9 ++++ include/hw/pci/pci_ids.h | 1 + include/hw/usb/xhci.h | 1 + hw/usb/hcd-xhci-nec.c | 10 +++++ hw/usb/hcd-xhci-pci.c | 69 ++++++++++++++++++++++++----- hw/usb/hcd-xhci-ti.c | 94 ++++++++++++++++++++++++++++++++++++++++ hw/usb/Kconfig | 5 +++ hw/usb/meson.build | 1 + 8 files changed, 180 insertions(+), 10 deletions(-) create mode 100644 hw/usb/hcd-xhci-ti.c
Signature · 1 line
2.45.2
PATCH 1/2 hw/usb: Make PCI device more configurable
To prepare to support another USB PCI Host Controller, make some PCI configuration dynamic.
--- hw/usb/hcd-xhci-pci.h | 9 ++++++ hw/usb/hcd-xhci-nec.c | 10 +++++++ hw/usb/hcd-xhci-pci.c | 69 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 78 insertions(+), 10 deletions(-)
hw/usb/hcd-xhci-pci.h +9 -0
@@ -40,6 +40,15 @@ typedef struct XHCIPciState {XHCIState xhci;OnOffAuto msi;OnOffAuto msix; +uint8_t cache_line_size; +uint8_t pm_cap_off; +uint8_t pcie_cap_off; +uint8_t msi_cap_off; +uint8_t msix_cap_off; +int msix_bar_nr; +uint64_t msix_bar_size; +uint32_t msix_table_off; + uint32_t msix_pba_off; } XHCIPciState;#endif
hw/usb/hcd-xhci-nec.c +10 -0
@@ -54,6 +54,16 @@ static void nec_xhci_instance_init(Object *obj) pci->xhci.flags = nec->flags; pci->xhci.numintrs = nec->intrs; pci->xhci.numslots = nec->slots; + + pci->cache_line_size =0x10 ; + pci->pm_cap_off =0 ; + pci->pcie_cap_off =0xa0 ; + pci->msi_cap_off =0x70 ; + pci->msix_cap_off =0x90 ; + pci->msix_bar_nr =0 ; + pci->msix_bar_size =0 ; + pci->msix_table_off =0x3000 ; + pci->msix_pba_off =0x3800 ; }static void nec_xhci_class_init (ObjectClass *klass,void *data)
hw/usb/hcd-xhci-pci.c +59 -10
110 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH 2/2 hw/usb: Add TI TUSB73X0 XHCI controller model
In reply to Nicholas PigginThis controller is accepted by IBM Power firmware when the subsystem IDs are set to Power servers. Firmware is picky about device support so the NEC driver does not work.
The TI HW has some interesting differences from NEC, notably a separate BAR for MSIX, and PM capabilities. The spec is freely available without sign-up.
--- include/hw/pci/pci_ids.h | 1 + include/hw/usb/xhci.h | 1 + hw/usb/hcd-xhci-ti.c | 94 ++++++++++++++++++++++++++++++++++++++++ hw/usb/Kconfig | 5 +++ hw/usb/meson.build | 1 + 5 files changed, 102 insertions(+) create mode 100644 hw/usb/hcd-xhci-ti.c
include/hw/pci/pci_ids.h +1 -0
@@ -182,6 +182,7 @@#define PCI_VENDOR_ID_HP 0x103c#define PCI_VENDOR_ID_TI 0x104c +#define PCI_DEVICE_ID_TI_TUSB73X0 0x8241#define PCI_VENDOR_ID_MOTOROLA 0x1057#define PCI_DEVICE_ID_MOTOROLA_MPC106 0x0002
include/hw/usb/xhci.h +1 -0
@@ -3,6 +3,7 @@#define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci" +#define TYPE_TI_XHCI "ti-usb-xhci"#define TYPE_QEMU_XHCI "qemu-xhci"#define TYPE_XHCI_SYSBUS "sysbus-xhci"
hw/usb/hcd-xhci-ti.c new file +94 -0
94 lines not on this page · raw message
hw/usb/Kconfig +5 -0
@@ -49,6 +49,11 @@ config USB_XHCI_NEC default y if PCI_DEVICES select USB_XHCI_PCI +config USB_XHCI_TI + bool + default y if PCI_DEVICES + select USB_XHCI_PCI + config USB_XHCI_SYSBUS bool select USB_XHCI
hw/usb/meson.build +1 -0
@@ -23,6 +23,7 @@ system_ss.add(when: 'CONFIG_USB_XHCI', if_true: files('hcd-xhci.c')) system_ss.add(when: 'CONFIG_USB_XHCI_PCI', if_true: files('hcd-xhci-pci.c')) system_ss.add(when: 'CONFIG_USB_XHCI_SYSBUS', if_true: files('hcd-xhci-sysbus.c')) system_ss.add(when: 'CONFIG_USB_XHCI_NEC', if_true: files('hcd-xhci-nec.c')) +system_ss.add(when: 'CONFIG_USB_XHCI_TI', if_true: files('hcd-xhci-ti.c')) system_ss.add(when: 'CONFIG_USB_DWC2', if_true: files('hcd-dwc2.c')) system_ss.add(when: 'CONFIG_USB_DWC3', if_true: files('hcd-dwc3.c'))
Signature · 1 line
2.45.2
Hi Nick,
Quoted 93 lines · Nicholas Piggin
This controller is accepted by IBM Power firmware when the subsystem IDs are set to Power servers. Firmware is picky about device support so the NEC driver does not work.
The TI HW has some interesting differences from NEC, notably a separate BAR for MSIX, and PM capabilities. The spec is freely available without sign-up.
Signed-off-by Nicholas Piggin <[email protected]>--- include/hw/pci/pci_ids.h | 1 + include/hw/usb/xhci.h | 1 + hw/usb/hcd-xhci-ti.c | 94 ++++++++++++++++++++++++++++++++++++++++ hw/usb/Kconfig | 5 +++ hw/usb/meson.build | 1 + 5 files changed, 102 insertions(+)create mode 100644
hw/usb/hcd-xhci-ti.cinclude/hw/pci/pci_ids.h +1
-0@@ -182,6 +182,7 @@#define PCI_VENDOR_ID_HP 0x103c#define PCI_VENDOR_ID_TI 0x104c +#define PCI_DEVICE_ID_TI_TUSB73X0 0x8241#define PCI_VENDOR_ID_MOTOROLA 0x1057#define PCI_DEVICE_ID_MOTOROLA_MPC106 0x0002include/hw/usb/xhci.h +1
-0@@ -3,6 +3,7 @@#define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci" +#define TYPE_TI_XHCI "ti-usb-xhci"#define TYPE_QEMU_XHCI "qemu-xhci"#define TYPE_XHCI_SYSBUS "sysbus-xhci"hw/usb/hcd-xhci-ti.c new file +45
-0@@ -0,0 +1,94 @@ +/* +* USB xHCI controller emulation +* Datasheet https://www.ti.com/product/TUSB7340 +* +* Copyright (c) 2011 Securiforest +* Date: 2011-05-11 ; Author: Hector Martin <[email protected]> +* Based on usb-xhci-nec.c, emulates TI TUSB73X0 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "hw/usb.h" +#include "qemu/module.h" +#include "hw/pci/pci.h" +#include "hw/qdev-properties.h" + +#include "hcd-xhci-pci.h" + +OBJECT_DECLARE_SIMPLE_TYPE(XHCITiState, TI_XHCI) + +struct XHCITiState { +/*< private >*/ +XHCIPciState parent_obj; +/*< public >*/ +uint32_t flags; +uint32_t intrs; +uint32_t slots; +}; + +static Property ti_xhci_properties[] = { +DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIPciState, msi,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_ON_OFF_AUTO ("msix" , XHCIPciState, msix,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_UINT32 ("intrs" , XHCITiState, intrs,8 ),
hw/usb/hcd-xhci-ti.c line 55
Quoted 10 lines
hw/usb/hcd-xhci-ti.c new file +10
-0+DEFINE_PROP_UINT32 ("slots" , XHCITiState, slots,XHCI_MAXSLOTS ), + DEFINE_PROP_END_OF_LIST(), +}; + +static void ti_xhci_instance_init (Object *obj) +{ +XHCIPciState *pci =XHCI_PCI (obj); +XHCITiState *ti =TI_XHCI (obj); + + pci->xhci.flags = ti->flags;
ti->flags doesn't seem initialized / used.
Quoted 67 lines
hw/usb/hcd-xhci-ti.c new file +39
-0+ pci->xhci.numintrs = ti->intrs; + pci->xhci.numslots = ti->slots; + + pci->cache_line_size =0x0 ; + pci->pm_cap_off =0x40 ; + pci->pcie_cap_off =0x70 ; + pci->msi_cap_off =0x48 ; + pci->msix_cap_off =0xc0 ; + pci->msix_bar_nr =0x2 ; + pci->msix_bar_size =0x800000 ; + pci->msix_table_off =0x0 ; + pci->msix_pba_off =0x1000 ; +} + +static void ti_xhci_class_init (ObjectClass *klass,void *data) +{ +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +device_class_set_props (dc, ti_xhci_properties); + k->vendor_id =PCI_VENDOR_ID_TI ; + k->device_id =PCI_DEVICE_ID_TI_TUSB73X0 ; + k->revision =0x02 ; +} + +static const TypeInfo ti_xhci_info = { + .name =TYPE_TI_XHCI , + .parent =TYPE_XHCI_PCI , + .instance_size =sizeof (XHCITiState), + .instance_init = ti_xhci_instance_init, + .class_init = ti_xhci_class_init, +}; + +static void ti_xhci_register_types (void ) +{ +type_register_static (&ti_xhci_info); +} + +type_init (ti_xhci_register_types)hw/usb/Kconfig +5
-0@@ -49,6 +49,11 @@ config USB_XHCI_NEC default y if PCI_DEVICES select USB_XHCI_PCI +config USB_XHCI_TI + bool + default y if PCI_DEVICES + select USB_XHCI_PCI + config USB_XHCI_SYSBUS bool select USB_XHCIhw/usb/meson.build +1
-0@@ -23,6 +23,7 @@ system_ss.add(when: 'CONFIG_USB_XHCI', if_true: files('hcd-xhci.c')) system_ss.add(when: 'CONFIG_USB_XHCI_PCI', if_true: files('hcd-xhci-pci.c')) system_ss.add(when: 'CONFIG_USB_XHCI_SYSBUS', if_true: files('hcd-xhci-sysbus.c')) system_ss.add(when: 'CONFIG_USB_XHCI_NEC', if_true: files('hcd-xhci-nec.c')) +system_ss.add(when: 'CONFIG_USB_XHCI_TI', if_true: files('hcd-xhci-ti.c')) system_ss.add(when: 'CONFIG_USB_DWC2', if_true: files('hcd-dwc2.c')) system_ss.add(when: 'CONFIG_USB_DWC3', if_true: files('hcd-dwc3.c'))
Quoted 100 lines · Philippe Mathieu-Daudé
Hi Nick,
Quoted 97 lines · Nicholas Piggin
This controller is accepted by IBM Power firmware when the subsystem IDs are set to Power servers. Firmware is picky about device support so the NEC driver does not work.
The TI HW has some interesting differences from NEC, notably a separate BAR for MSIX, and PM capabilities. The spec is freely available without sign-up.
Signed-off-by Nicholas Piggin <[email protected]>--- include/hw/pci/pci_ids.h | 1 + include/hw/usb/xhci.h | 1 + hw/usb/hcd-xhci-ti.c | 94 ++++++++++++++++++++++++++++++++++++++++ hw/usb/Kconfig | 5 +++ hw/usb/meson.build | 1 + 5 files changed, 102 insertions(+)create mode 100644
hw/usb/hcd-xhci-ti.cinclude/hw/pci/pci_ids.h +1
-0@@ -182,6 +182,7 @@#define PCI_VENDOR_ID_HP 0x103c#define PCI_VENDOR_ID_TI 0x104c +#define PCI_DEVICE_ID_TI_TUSB73X0 0x8241#define PCI_VENDOR_ID_MOTOROLA 0x1057#define PCI_DEVICE_ID_MOTOROLA_MPC106 0x0002include/hw/usb/xhci.h +1
-0@@ -3,6 +3,7 @@#define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci" +#define TYPE_TI_XHCI "ti-usb-xhci"#define TYPE_QEMU_XHCI "qemu-xhci"#define TYPE_XHCI_SYSBUS "sysbus-xhci"hw/usb/hcd-xhci-ti.c new file +49
-0@@ -0,0 +1,94 @@ +/* +* USB xHCI controller emulation +* Datasheet https://www.ti.com/product/TUSB7340 +* +* Copyright (c) 2011 Securiforest +* Date: 2011-05-11 ; Author: Hector Martin <[email protected]> +* Based on usb-xhci-nec.c, emulates TI TUSB73X0 +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "hw/usb.h" +#include "qemu/module.h" +#include "hw/pci/pci.h" +#include "hw/qdev-properties.h" + +#include "hcd-xhci-pci.h" + +OBJECT_DECLARE_SIMPLE_TYPE(XHCITiState, TI_XHCI) + +struct XHCITiState { +/*< private >*/ +XHCIPciState parent_obj; +/*< public >*/ +uint32_t flags; +uint32_t intrs; +uint32_t slots; +}; + +static Property ti_xhci_properties[] = { +DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIPciState, msi,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_ON_OFF_AUTO ("msix" , XHCIPciState, msix,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_UINT32 ("intrs" , XHCITiState, intrs,8 ), +DEFINE_PROP_UINT32 ("slots" , XHCITiState, slots,XHCI_MAXSLOTS ), +DEFINE_PROP_END_OF_LIST (), +}; +
Quoted 8 lines
hw/usb/hcd-xhci-ti.c line 55
Quoted 6 lines
hw/usb/hcd-xhci-ti.c new file +6
-0+static void ti_xhci_instance_init (Object *obj) +{ +XHCIPciState *pci =XHCI_PCI (obj); +XHCITiState *ti =TI_XHCI (obj); + + pci->xhci.flags = ti->flags;
ti->flagsdoesn't seem initialized / used.
Aha, because you removed the last flags from nec driver and I copied this from there :P
Good catch. Shall we just remove the flags from XHCINecState?
Thanks,
Nick