Skip to contentSkip to conversation

microvm: add usb support

PATCH Superseded Gerd Hoffmann 1 participant 3 messages Sep 21, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover microvm: add usb support

This depends on the xhci sysfs patch series by
Sai Pavan Boddu <[email protected]>

Gerd Hoffmann (2):
microvm: add irq table
microvm: add usb support

 include/hw/i386/microvm.h | 25 +++++++++++++++++++++++++
 hw/i386/acpi-microvm.c    | 20 ++++++++++++++++++++
 hw/i386/microvm.c         | 12 ++++++++++++
 3 files changed, 57 insertions(+)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/2 microvm: add irq table

Add a comment with a table listing the IRQs,
both legacy pc and microvm side-by-side.

---
 include/hw/i386/microvm.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
include/hw/i386/microvm.h +22 -0
index be2d95af4d74..27eadd6c535c 100644
@@ -27,6 +27,28 @@
 #include "hw/acpi/acpi_dev_interface.h"
 #include "qom/object.h"
 
+/*
+ *  IRQ    |  pc        | microvm (acpi=on)
+ * --------+------------+------------------
+ *   0     |  pit       |
+ *   1     |  kbd       |
+ *   2     |  cascade   |
+ *   3     |  serial 1  |
+ *   4     |  serial 0  | serial
+ *   5     |  -         |
+ *   6     |  floppy    |
+ *   7     |  parallel  |
+ *   8     |  rtc       | rtc (rtc=on)
+ *   9     |  acpi      | acpi (ged)
+ *  10     |  pci lnk   |
+ *  11     |  pci lnk   |
+ *  12     |  ps2       |
+ *  13     |  fpu       |
+ *  14     |  ide 0     |
+ *  15     |  ide 1     |
+ *  16-23  |  pci gsi   | virtio
+ */
+
 /* Platform virtio definitions */
 #define VIRTIO_MMIO_BASE      0xfeb00000
 #define VIRTIO_NUM_TRANSPORTS 8
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/2 microvm: add usb support

In reply to Gerd Hoffmann

Wire up "usb=on" machine option. When enabled add a sysbus xhci controller with 8 ports. Declare it in the ACPI DSDT table so the guest OS finds it.

---
 include/hw/i386/microvm.h |  5 ++++-
 hw/i386/acpi-microvm.c    | 20 ++++++++++++++++++++
 hw/i386/microvm.c         | 12 ++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
include/hw/i386/microvm.h +4 -1
index 27eadd6c535c..e255e787b6d5 100644
@@ -40,7 +40,7 @@
  *   7     |  parallel  |
  *   8     |  rtc       | rtc (rtc=on)
  *   9     |  acpi      | acpi (ged)
- *  10     |  pci lnk   |
+ *  10     |  pci lnk   | xhci (usb=on)
  *  11     |  pci lnk   |
  *  12     |  ps2       |
  *  13     |  fpu       |
@@ -59,6 +59,9 @@
 #define GED_MMIO_BASE_REGS    (GED_MMIO_BASE + 0x200)
 #define GED_MMIO_IRQ          9
 
+#define MICROVM_XHCI_BASE     0xfe900000
+#define MICROVM_XHCI_IRQ      10
+
 /* Machine type options */
 #define MICROVM_MACHINE_PIT                 "pit"
 #define MICROVM_MACHINE_PIC                 "pic"
hw/i386/acpi-microvm.c +20 -0
index df39c5d3bd90..a2b6c4478f3b 100644
@@ -87,6 +87,25 @@ static void acpi_dsdt_add_virtio(Aml *scope,
     }
 }
 
+static void acpi_dsdt_add_xhci(Aml *scope, MicrovmMachineState *mms)
+{
+    if (!machine_usb(MACHINE(mms))) {
+        return;
+    }
+
+    Aml *dev = aml_device("XHCI");
+    aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0D10")));
+
+    uint32_t irq = MICROVM_XHCI_IRQ;
+    Aml *crs = aml_resource_template();
+    aml_append(crs, aml_memory32_fixed(MICROVM_XHCI_BASE, 0x4000,
+                                       AML_READ_WRITE));
+    aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
+                                  AML_EXCLUSIVE, &irq, 1));
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
 static void
 build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
                    MicrovmMachineState *mms)
@@ -112,6 +131,7 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
                   GED_MMIO_IRQ, AML_SYSTEM_MEMORY, GED_MMIO_BASE);
     acpi_dsdt_add_power_button(sb_scope);
     acpi_dsdt_add_virtio(sb_scope, mms);
+    acpi_dsdt_add_xhci(sb_scope, mms);
     aml_append(dsdt, sb_scope);
 
     /* ACPI 5.0: Table 7-209 System State Package */
hw/i386/microvm.c +12 -0
index 60d32722301f..592dc51ce7bf 100644
@@ -147,6 +147,18 @@ static void microvm_devices_init(MicrovmMachineState *mms)
         x86ms->acpi_dev = HOTPLUG_HANDLER(dev);
     }
 
+    if (x86_machine_is_acpi_enabled(x86ms) && machine_usb(MACHINE(mms))) {
+        DeviceState *dev = qdev_new("sysbus-xhci");
+        qdev_prop_set_uint32(dev, "intrs", 1);
+        qdev_prop_set_uint32(dev, "slots", 64); /* MAXSLOTS */
+        qdev_prop_set_uint32(dev, "p2", 8);
+        qdev_prop_set_uint32(dev, "p3", 8);
+        sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
+        sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MICROVM_XHCI_BASE);
+        sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
+                           x86ms->gsi[MICROVM_XHCI_IRQ]);
+    }
+
     if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) {
         qemu_irq *i8259;
 
Signature · 1 line
2.27.0