Skip to content

Commit ab4ed95

Browse files
committed
[opentitanlib,qemu] Implement a minimal USB host
This virtual host talks to the QEMU usbdev driver. At the moment, this host perform the initial handshake, turns on vbus, waits for a device connection and retrieve the device descriptor. Signed-off-by: Amaury Pouly <[email protected]>
1 parent 19ca9ac commit ab4ed95

File tree

2 files changed

+751
-2
lines changed

2 files changed

+751
-2
lines changed

sw/host/opentitanlib/src/transport/qemu/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::transport::qemu::monitor::{Chardev, ChardevKind, Monitor};
3434
use crate::transport::qemu::reset::QemuReset;
3535
use crate::transport::qemu::spi::QemuSpi;
3636
use crate::transport::qemu::uart::QemuUart;
37-
use crate::transport::qemu::usbdev::QemuVbusSense;
37+
use crate::transport::qemu::usbdev::{QemuUsbHost, QemuVbusSense};
3838
use crate::transport::{
3939
Capabilities, Capability, Transport, TransportError, TransportInterfaceType,
4040
};
@@ -73,6 +73,8 @@ pub struct Qemu {
7373
/// VBUS sense pin (actually goes via the `usbdev-cmd` chardev).
7474
vbus_sense: Option<Rc<dyn GpioPin>>,
7575

76+
_usb_host: Option<Rc<QemuUsbHost>>,
77+
7678
/// QEMU log modelled as a UART.
7779
log: Option<Rc<dyn Uart>>,
7880

@@ -152,6 +154,25 @@ impl Qemu {
152154
}
153155
};
154156

157+
// USBDEV host:
158+
let usb_host = match find_chardev(&chardevs, "usbdev-host") {
159+
Some(ChardevKind::Pty { path }) => {
160+
let tty = serialport::new(
161+
path.to_str().context("TTY path not UTF8")?,
162+
CONSOLE_BAUDRATE,
163+
)
164+
.open_native()
165+
.context("failed to open QEMU usbdev-host PTY")?;
166+
167+
let usb_host = Rc::new(QemuUsbHost::new(tty));
168+
Some(usb_host)
169+
}
170+
_ => {
171+
log::info!("could not find pty chardev with id=usbdev-host, skipping USBDEV");
172+
None
173+
}
174+
};
175+
155176
// QEMU log, not really a UART but modelled as one:
156177
let log = match find_chardev(&chardevs, "log") {
157178
Some(ChardevKind::Pty { path }) => {
@@ -237,6 +258,7 @@ impl Qemu {
237258
reset,
238259
uarts,
239260
vbus_sense,
261+
_usb_host: usb_host,
240262
log,
241263
spi,
242264
i2cs,

0 commit comments

Comments
 (0)