|
| 1 | +.. _usb_virtualization: |
| 2 | + |
| 3 | +USB Virtualization |
| 4 | +################## |
| 5 | + |
| 6 | +Universal Serial Bus (USB) is an industry standard that |
| 7 | +establishes specifications for cables, connectors, and protocols for |
| 8 | +connection, communication, and power supply between personal computers |
| 9 | +and their peripheral devices. |
| 10 | + |
| 11 | +.. figure:: images/usb-image51.png |
| 12 | + :align: center |
| 13 | + :name: usb-virt-arch |
| 14 | + |
| 15 | + USB architecture overview |
| 16 | + |
| 17 | + |
| 18 | +The ACRN USB virtualization includes |
| 19 | +emulation of three components, described here and shown in |
| 20 | +:numref:`usb-virt-arch`: |
| 21 | + |
| 22 | +- **xHCI DM** (Host Controller Interface) provides multiple |
| 23 | + instances of virtual xHCI controllers to share among multiple User |
| 24 | + OSes, each USB port can be assigned and dedicated to a VM by user |
| 25 | + settings. |
| 26 | + |
| 27 | +- **xDCI controller** (Device Controller Interface) |
| 28 | + can be passed through to the |
| 29 | + specific User OS with I/O MMU assistance. |
| 30 | + |
| 31 | +- **DRD DM** (Dual Role Device) emulates the PHY MUX control |
| 32 | + logic. The sysfs interface in UOS is used to trap the switch operation |
| 33 | + into DM, and the the sysfs interface in SOS is used to operate on the physical |
| 34 | + registers to switch between DCI and HCI role. |
| 35 | + |
| 36 | + On Intel Apollo Lake platform, the sysfs interface path is |
| 37 | + ``/sys/class/usb_role/intel_xhci_usb_sw/role``. If user echos string |
| 38 | + ``device`` to role node, the usb phy will be connected with xDCI controller as |
| 39 | + device mode. Similarly, by echoing ``host``, the usb phy will be |
| 40 | + connected with xHCI controller as host mode. |
| 41 | + |
| 42 | +An xHCI register access from UOS will induce EPT trap from UOS to |
| 43 | +DM, and the xHCI DM or DRD DM will emulate hardware behaviors to make |
| 44 | +the subsystem run. |
| 45 | + |
| 46 | +USB host virtualization |
| 47 | +*********************** |
| 48 | + |
| 49 | +USB host virtualization is implemented as shown in |
| 50 | +:numref:`xhci-dm-arch`: |
| 51 | + |
| 52 | +.. figure:: images/usb-image10.png |
| 53 | + :align: center |
| 54 | + :name: xhci-dm-arch |
| 55 | + |
| 56 | + xHCI DM software architecture |
| 57 | + |
| 58 | +The yellow-colored components make up the ACRN USB stack supporting xHCI |
| 59 | +DM: |
| 60 | + |
| 61 | +- **xHCI DM** emulates the xHCI controller logic following the xHCI spec; |
| 62 | + |
| 63 | +- **USB core** is a middle abstract layer to isolate the USB controller |
| 64 | + emulators and USB device emulators. |
| 65 | + |
| 66 | +- **USB Port Mapper** maps the specific native physical USB |
| 67 | + ports to virtual USB ports. It communicate with |
| 68 | + native USB ports though libusb. |
| 69 | + |
| 70 | +All the USB data buffers from UOS (User OS) are in the form of TRB |
| 71 | +(Transfer Request Blocks), according to xHCI spec. xHCI DM will fetch |
| 72 | +these data buffers when the related xHCI doorbell registers are set. |
| 73 | +These data will convert to *struct usb_data_xfer* and, through USB core, |
| 74 | +forward to the USB port mapper module which will communicate with native USB |
| 75 | +stack over libusb. |
| 76 | + |
| 77 | +The device model configuration command syntax for xHCI is as follows:: |
| 78 | + |
| 79 | + -s <slot>,xhci,[bus1-port1,bus2-port2] |
| 80 | + |
| 81 | +- *slot*: virtual PCI slot number in DM |
| 82 | +- *bus-port*: specify which physical USB ports need to map to UOS. |
| 83 | + |
| 84 | +A simple example:: |
| 85 | + |
| 86 | + -s 7,xhci,1-2,2-2 |
| 87 | + |
| 88 | +This configuration means the virtual xHCI will appear in PCI slot 7 |
| 89 | +in UOS, and any physical USB device attached on 1-2 or 2-2 will be |
| 90 | +detected by UOS and used as expected. |
| 91 | + |
| 92 | +USB DRD virtualization |
| 93 | +********************** |
| 94 | + |
| 95 | +USB DRD (Dual Role Device) emulation works as shown in this figure: |
| 96 | + |
| 97 | +.. figure:: images/usb-image31.png |
| 98 | + :align: center |
| 99 | + |
| 100 | + xHCI DRD DM software architecture |
| 101 | + |
| 102 | +ACRN emulates the DRD hardware logic of an Intel Apollo Lake platform to |
| 103 | +support the dual role requirement. The DRD feature is implemented as xHCI |
| 104 | +vendor extended capability. ACRN emulates |
| 105 | +the same way, so the native driver can be reused in UOS. When UOS DRD |
| 106 | +driver reads or writes the related xHCI extended registers, these access will |
| 107 | +be captured by xHCI DM. xHCI DM uses the native DRD related |
| 108 | +sysfs interface to do the Host/Device mode switch operations. |
| 109 | + |
| 110 | +The device model configuration command syntax for xHCI DRD is as |
| 111 | +follows:: |
| 112 | + |
| 113 | + -s <slot>,xhci,[bus1-port1,bus2-port2],cap=platform |
| 114 | + |
| 115 | +- *cap*: cap means virtual xHCI capability. This parameter |
| 116 | + indicates virtual xHCI should emulate the named platform’s xHCI |
| 117 | + capabilities. |
| 118 | + |
| 119 | +A simple example:: |
| 120 | + |
| 121 | + -s 7,xhci,1-2,2-2,cap=apl |
| 122 | + |
| 123 | +This configuration means the virtual xHCI should emulate xHCI |
| 124 | +capabilities for the Intel Apollo Lake platform, which supports DRD |
| 125 | +feature. |
| 126 | + |
| 127 | +Interface Specification |
| 128 | +*********************** |
| 129 | + |
| 130 | +.. note:: reference doxygen-generated API content |
0 commit comments