Skip to content

Conversation

@pamaury
Copy link
Contributor

@pamaury pamaury commented Oct 20, 2025

Currently there is a UsbBackend struct which wraps around rusb and provides some utility functions. In the future, we may want some transports to implement USB in a different way (e.g. QEMU implements USB over a virtual channel). To do, the first step is to create an abstraction over the existing rusb implementation.

This PR split UsbBackend into two: a context trait and a device trait. The rusb implementation becomes just a particular implementation of those traits.

@pamaury pamaury changed the title [DRAFT][opentitanlib] Introduce abstract over the USB backend [DRAFT][opentitanlib] Introduce abstraction over the USB backend Oct 20, 2025
@pamaury pamaury marked this pull request as ready for review October 21, 2025 13:07
@pamaury pamaury requested a review from a team as a code owner October 21, 2025 13:07
@pamaury pamaury force-pushed the ott_usb_backends branch 2 times, most recently from f414fa0 to d29a1bc Compare October 21, 2025 13:54
Currently there is a UsbBackend struct which wraps around rusb
and provides some utility functions. In the future, we may want
some transports to implement USB in a different way (e.g. QEMU
implements USB over a virtual channel). To do, the first step
is to create an abstraction over the existing `rusb` implementation.

This PR split UsbBackend into two: a context trait and a device trait.
The `rusb` implementation becomes just a particular implementation of
those traits.

Signed-off-by: Amaury Pouly <[email protected]>
@cfrantz
Copy link
Contributor

cfrantz commented Oct 23, 2025

Overall, this looks like nice straightforward wrapper around the functionality of a client usb library.

My only concern is that the wrapper exposes the underlying rusb::ConfigurationDescriptor, which itself exposes the other rusb descriptor types (Interface, Endpoint, etc). These rusb descriptor types appear to be structs that hold a pointer to some C-struct from libusb.

If you write a fake usb shim to speak directly to qemu, what will you do to provide access to the various descriptors?

@pamaury
Copy link
Contributor Author

pamaury commented Oct 23, 2025

Overall, this looks like nice straightforward wrapper around the functionality of a client usb library.

My only concern is that the wrapper exposes the underlying rusb::ConfigurationDescriptor, which itself exposes the other rusb descriptor types (Interface, Endpoint, etc). These rusb descriptor types appear to be structs that hold a pointer to some C-struct from libusb.

If you write a fake usb shim to speak directly to qemu, what will you do to provide access to the various descriptors?

You are correct, I mistakenly assumed that rusb provided a generic implementation of tge descriptors but this is indeed tied to libusb which is not good. This means that we need to provide a way to parse the descriptors which is... not ideal.

Out of curiosity, I looked at nusb and they do provide a generic interface but maybe it's too much to import a dependency just for that? Or we can reimplement just the bare minimum of descriptor parsing ourselves.

@jwnrt
Copy link
Contributor

jwnrt commented Oct 24, 2025

Out of curiosity, I looked at nusb and they do provide a generic interface but maybe it's too much to import a dependency just for that? Or we can reimplement just the bare minimum of descriptor parsing ourselves.

Aside: we were considering nusb for master for its async API and to help with concerns about LGPL dependencies (libusb).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants