Skip to content

rust: add support for USB device drivers#884

Open
YakoYakoYokuYoku wants to merge 10 commits into
Rust-for-Linux:rustfrom
YakoYakoYokuYoku:usb-support
Open

rust: add support for USB device drivers#884
YakoYakoYokuYoku wants to merge 10 commits into
Rust-for-Linux:rustfrom
YakoYakoYokuYoku:usb-support

Conversation

@YakoYakoYokuYoku

Copy link
Copy Markdown

Introduces a basic API for USB devices, drivers and interfaces. Features will be added on demand.

@adamrk adamrk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @YakoYakoYokuYoku, thanks for working on this! I left some initial comments.

Comment thread rust/kernel/usb.rs Outdated
Comment thread rust/kernel/usb.rs
Comment thread rust/kernel/usb.rs Outdated
Comment thread rust/kernel/usb.rs
Comment thread rust/kernel/usb.rs
Comment thread rust/kernel/usb.rs Outdated
Comment thread rust/kernel/usb.rs
Comment thread rust/kernel/usb.rs Outdated
Comment thread rust/kernel/usb.rs
@YakoYakoYokuYoku YakoYakoYokuYoku force-pushed the usb-support branch 2 times, most recently from fd24f28 to 53c7103 Compare October 12, 2022 13:48
@YakoYakoYokuYoku YakoYakoYokuYoku force-pushed the usb-support branch 6 times, most recently from bc035c5 to e4bae40 Compare January 31, 2023 19:04
@YakoYakoYokuYoku

Copy link
Copy Markdown
Author

@adamrk, @nbdd0121, want to take a look at this again?

Many places of the kernel make use of `gfp_t` and its flags to perform
certain types of allocations. On the other hand the `kernel` crate does
not expose them for consumers, in particular, they are needed for the
USB abstractions. For now `gfp_t` and some common flags will be
available through `kernel` while in the future more flags can be added.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
The XArray is an abstract data type which behaves like a very large
array of pointers. Add a Rust abstraction for this data type.

The initial implementation uses explicit locking on get operations and
returns a guard which blocks mutation, ensuring that the referenced
object remains alive. To avoid excessive serialization, users are
expected to use an inner type that can be efficiently cloned (such as
Arc<T>), and eagerly clone and drop the guard to unblock other users
after a lookup.

Future variants may support using RCU instead to avoid mutex locking.

This abstraction also introduces a reservation mechanism, which can be
used by alloc-capable XArrays to reserve a free slot without immediately
filling it, and then do so at a later time. If the reservation is
dropped without being filled, the slot is freed again for other users,
which eliminates the need for explicit cleanup code.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Signed-off-by: Asahi Lina <lina@asahilina.net>
Introduces APIs for USB devices and interfaces. Driver traits and
implementations are aimed at interfaces only.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Adds an API for creating, filling and submitting USB Request Blocks.
With support for URB contexts, specialized trait for transport buffers,
which mimics ForeignWrapper and completion routines.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Adds a few useful descriptors for querying data upon USB abstract types.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Adds a sample USB driver that catches incoming bulk requests and writes
their transport data to a miscellaneous device.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
@Frostie314159

Copy link
Copy Markdown

Are there any updates on the state of this PR, since it fails to build after syncing with master.

@YakoYakoYokuYoku

Copy link
Copy Markdown
Author

Are there any updates on the state of this PR, since it fails to build after syncing with master.

I've forgot to bring any updates, happens that I've been waiting for some of the dependencies of kernel::usb to be merged and I haven't seen anyone interested in this up until your comment.

But, if you want to see the fix, let me know. Also there's a thread on Zulip on the topic of USB bindings.

@Frostie314159

Copy link
Copy Markdown

Which dependencies are you referring to?

@YakoYakoYokuYoku

Copy link
Copy Markdown
Author

I was referring to the dependency on kernel::{device, driver, file}, as these are not present in rust-next. If they were there I'd probably do an RFC series on the mailing list. Although I could try to send those too in the RFC.

@linkmauve

Copy link
Copy Markdown

There have been USB abstractions in the kernel since e7e2296, this PR can likely be closed now.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants