|
| 1 | +.. virtio-console: |
| 2 | +
|
| 3 | +Virtio-Console High-Level design |
| 4 | +################################ |
| 5 | + |
| 6 | +The Virtio-console is a simple device for data input and output. The |
| 7 | +console's virtio device ID is ``3`` and can have from 1 to 16 ports. |
| 8 | +Each port has a pair of input and output virtqueues used to communicate |
| 9 | +information between the Front End (FE) and Back end (BE) drivers. |
| 10 | +Currently the size of each virtqueue is 64 (configurable in the source |
| 11 | +code). The FE driver will place empty buffers for incoming data onto |
| 12 | +the receiving virtqueue, and enqueue outgoing characters onto the |
| 13 | +transmitting virtqueue. |
| 14 | + |
| 15 | +A Virtio-console device has a pair of control IO virtqueues as well. The |
| 16 | +control virtqueues are used to communicate information between the |
| 17 | +device and the driver, including: ports being opened and closed on |
| 18 | +either side of the connection, indication from the host about whether a |
| 19 | +particular port is a console port, adding new ports, port |
| 20 | +hot-plug/unplug, indication from the guest about whether a port or a |
| 21 | +device was successfully added, or a port opened or closed. |
| 22 | + |
| 23 | +The virtio-console architecture diagram in ACRN is shown below. |
| 24 | + |
| 25 | +.. figure:: images/virtio-console-arch.png |
| 26 | + :align: center |
| 27 | + :width: 700px |
| 28 | + :name: virtio-console-arch |
| 29 | + |
| 30 | + Virtio-console architecture diagram |
| 31 | + |
| 32 | + |
| 33 | +Virtio-console is implemented as a virtio legacy device in the ACRN device |
| 34 | +model (DM), and is registered as a PCI virtio device to the guest OS. No changes |
| 35 | +are required in the frontend Linux virtio-console except that the guest |
| 36 | +(UOS) kernel should be built with ``CONFIG_VIRTIO_CONSOLE=y``. |
| 37 | + |
| 38 | +Currently the feature bits supported by the BE device are: |
| 39 | + |
| 40 | +.. list-table:: Feature bits supported by BE drivers |
| 41 | + :widths: 30 50 |
| 42 | + :header-rows: 0 |
| 43 | + |
| 44 | + * - VTCON_F_SIZE(bit 0) |
| 45 | + - configuration columns and rows are valid. |
| 46 | + * - VTCON_F_MULTIPORT(bit 1) |
| 47 | + - device supports multiple ports, and control virtqueues will be used. |
| 48 | + * - VTCON_F_EMERG_WRITE(bit 2) |
| 49 | + - device supports emergency write. |
| 50 | + |
| 51 | +Virtio-console supports redirecting guest output to various backend |
| 52 | +devices. Currently the following backend devices are supported in ACRN |
| 53 | +device model: STDIO, TTY, PTY and regular file. |
| 54 | + |
| 55 | +The device model configuration command syntax for virtio-console is:: |
| 56 | + |
| 57 | + virtio-console,[@]stdio|tty|pty|file:portname[=portpath]\ |
| 58 | + [,[@]stdio|tty|pty|file:portname[=portpath]] |
| 59 | + |
| 60 | +- Preceding with ``@`` marks the port as a console port, otherwise it is a |
| 61 | + normal virtio serial port |
| 62 | + |
| 63 | +- The ``portpath`` can be omitted when backend is stdio or pty |
| 64 | + |
| 65 | +- The ``stdio/tty/pty`` is tty capable, which means :kbd:`TAB` and |
| 66 | + :kbd:`BACKSPACE` are supported, as on a regular terminal |
| 67 | + |
| 68 | +- When tty is used, please make sure the redirected tty is sleeping, |
| 69 | + (e.g., by ``sleep 2d`` command), and will not read input from stdin before it |
| 70 | + is used by virtio-console to redirect guest output. |
| 71 | + |
| 72 | +- Claiming multiple virtio serial ports as consoles is supported, |
| 73 | + however the guest Linux OS will only use one of them, through the |
| 74 | + ``console=hvcN`` kernel parameter. For example, the following command |
| 75 | + defines two backend ports, which are both console ports, but the frontend |
| 76 | + driver will only use the second port named ``pty_port`` as its hvc |
| 77 | + console (specified by ``console=hvc1`` in the kernel command |
| 78 | + line):: |
| 79 | + |
| 80 | + -s n,virtio-console,@tty:tty_port=/dev/pts/0,@pty:pty_port \ |
| 81 | + -B "root=/dev/vda2 rw rootwait maxcpus=$2 nohpet console=hvc1 console=ttyS0 ..." |
| 82 | + |
| 83 | + |
| 84 | +Console Backend Use Cases |
| 85 | +************************* |
| 86 | + |
| 87 | +The following sections elaborate on each backend. |
| 88 | + |
| 89 | +STDIO |
| 90 | +===== |
| 91 | + |
| 92 | +1. Add a pci slot to the device model (``acrn-dm``) command line:: |
| 93 | + |
| 94 | + -s n,virtio-console,@stdio:stdio_port |
| 95 | + |
| 96 | +#. Add the ``console`` parameter to the guest OS kernel command line:: |
| 97 | + |
| 98 | + console=hvc0 |
| 99 | + |
| 100 | +PTY |
| 101 | +=== |
| 102 | + |
| 103 | +1. Add a pci slot to the device model (``acrn-dm``) command line:: |
| 104 | + |
| 105 | + -s n,virtio-console,@pty:pty_port |
| 106 | + |
| 107 | +#. Add the ``console`` parameter to the guest os kernel command line:: |
| 108 | + |
| 109 | + console=hvc0 |
| 110 | + |
| 111 | + One line of information, such as shown below, will be printed in the terminal |
| 112 | + after ``acrn-dm`` is launched (``/dev/pts/0`` may be different, |
| 113 | + depending on your use case): |
| 114 | + |
| 115 | + .. code-block: console |
| 116 | + |
| 117 | + virt-console backend redirected to /dev/pts/0 |
| 118 | + |
| 119 | +#. Use a terminal emulator, such as minicom or screen, to connect to the |
| 120 | + tty node:: |
| 121 | + |
| 122 | + minicom -D /dev/pts/0 |
| 123 | + |
| 124 | + or :: |
| 125 | + |
| 126 | + screen /dev/pts/0 |
| 127 | + |
| 128 | +TTY |
| 129 | +=== |
| 130 | + |
| 131 | +1. Identify your tty that will be used as the UOS console: |
| 132 | + |
| 133 | + - If you're connected to your device over the network via ssh, use |
| 134 | + the linux ``tty`` command, and it will report the node (may be |
| 135 | + different in your use case):: |
| 136 | + |
| 137 | + /dev/pts/0 |
| 138 | + sleep 2d |
| 139 | + |
| 140 | + - If you do not have network access to your device, use screen |
| 141 | + to create a new tty:: |
| 142 | + |
| 143 | + screen |
| 144 | + tty |
| 145 | + |
| 146 | + you will see (depending on your use case):: |
| 147 | + |
| 148 | + /dev/pts/0 |
| 149 | + |
| 150 | + Prevent the tty from responding by sleeping:: |
| 151 | + |
| 152 | + sleep 2d |
| 153 | + |
| 154 | + and detach the tty by pressing :kbd:`CTRL-A` :kbd:`d`. |
| 155 | + |
| 156 | +#. Add a pci slot to the device model (``acrn-dm``) command line |
| 157 | + (changing the ``dev/pts/X`` to match your use case):: |
| 158 | + |
| 159 | + -s n,virtio-console,@tty:tty_port=/dev/pts/X |
| 160 | + |
| 161 | +#. Add the console parameter to the guest OS kernel command line:: |
| 162 | + |
| 163 | + console=hvc0 |
| 164 | + |
| 165 | +#. Go back to the previous tty. For example, if you're using |
| 166 | + ``screen``, use:: |
| 167 | + |
| 168 | + screen -ls |
| 169 | + screen -r <pid_of_your_tty> |
| 170 | + |
| 171 | +FILE |
| 172 | +==== |
| 173 | + |
| 174 | +The File backend only supports console output to a file (no input). |
| 175 | + |
| 176 | +1. Add a pci slot to the device model (``acrn-dm``) command line, |
| 177 | + adjusting the ``</path/to/file>`` to your use case:: |
| 178 | + |
| 179 | + -s n,virtio-console,@file:file_port=</path/to/file> |
| 180 | + |
| 181 | +#. Add the console parameter to the guest OS kernel command line:: |
| 182 | + |
| 183 | + console=hvc0 |
0 commit comments