Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EHCI USB Controllers Support #1059

Open
wants to merge 64 commits into
base: theseus_main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
53bec8c
Port of the `pci` crate
NathanRoyer Jul 25, 2023
d716bd7
Allow clippy::unnecessary_cast caused by platform abstraction
NathanRoyer Jul 25, 2023
66e4ddb
Document Makefile edits
NathanRoyer Jul 25, 2023
ee27c46
`pci` doc
NathanRoyer Jul 25, 2023
84860ad
Use volatile read/writes in `pci` [aarch64]
NathanRoyer Jul 27, 2023
8ae8816
Store the PCI config space in Once on aarch64
NathanRoyer Jul 27, 2023
68c618e
Remove unneeded qemu flags
NathanRoyer Jul 27, 2023
d6f72b3
Merge remote-tracking branch 'theseus-os/theseus_main' into pci-port
NathanRoyer Aug 1, 2023
aec3809
fix: allocate the PCI config space as device memory
NathanRoyer Aug 4, 2023
be56bc6
Improve pci_address_and_shift (documentation + structs)
NathanRoyer Aug 4, 2023
fb937fa
Use MMIO_FLAGS in aarch64-specific PCI code
NathanRoyer Aug 4, 2023
c12a3e4
Merge remote-tracking branch 'theseus-os/theseus_main' into usb-ehci
NathanRoyer Aug 21, 2023
fdc8a69
EHCI: got a keyboard device descriptor
NathanRoyer Aug 21, 2023
fe4e868
Prepare USB Allocator structure
NathanRoyer Aug 22, 2023
26ef6dd
Merge remote-tracking branch 'theseus-os/theseus_main' into usb-ehci
NathanRoyer Sep 26, 2023
99f1850
Improve EHCI driver structure
NathanRoyer Oct 6, 2023
998ddde
Define all standard descriptor types
NathanRoyer Oct 11, 2023
dfd7766
Nice API for standard requests
NathanRoyer Oct 19, 2023
5484a98
Read USB keyboard state using control transfers
NathanRoyer Oct 31, 2023
4085bb5
Handle PCI interrupts by detecting which device caused them
NathanRoyer Nov 1, 2023
a88b5fe
Detect keystrokes using interrupt transfers
NathanRoyer Nov 1, 2023
9d70cc2
Re-organize USB work into one crate
NathanRoyer Nov 2, 2023
7c34a9d
Better USB allocation types
NathanRoyer Nov 4, 2023
d9d9202
Fix STATUS stage of EHCI requests
NathanRoyer Nov 6, 2023
3c983d1
New ControllerApi / InterfaceApi traits
NathanRoyer Nov 6, 2023
e3e58ec
Added support for legacy interrupt dispatch in `pci`
NathanRoyer Nov 7, 2023
64cdae2
Handle USB EHCI interrupts
NathanRoyer Nov 7, 2023
a52bf0a
Improve PCI/USB interface
NathanRoyer Nov 8, 2023
fce5474
Restrict visibility of USB internals
NathanRoyer Nov 8, 2023
f0dfb3d
Remove sketchy macros
NathanRoyer Nov 8, 2023
d833752
Remove USB crate
NathanRoyer Nov 8, 2023
2511eb2
More reverts
NathanRoyer Nov 8, 2023
61e1c04
Added USB specification links
NathanRoyer Nov 21, 2023
113e46e
PCI for USB: improvements
NathanRoyer Nov 21, 2023
2b30225
EHCI: Reset ports during init (regardless of port change register state)
NathanRoyer Nov 21, 2023
eb2595b
PCI for USB: improvements
NathanRoyer Nov 21, 2023
37f911c
PCI for USB: API fixes
NathanRoyer Nov 21, 2023
b263f2e
Move PCI interrupt numbers to arm_boards
NathanRoyer Nov 21, 2023
818c55f
PCI for USB: API fixes
NathanRoyer Nov 21, 2023
7948c06
Move PCI interrupt numbers to arm_boards
NathanRoyer Nov 21, 2023
ac87fac
Resolve conflict (generic timer was moved to its own crate)
NathanRoyer Nov 21, 2023
0b58f17
Merge branch 'theseus_main' into usb-premod
NathanRoyer Nov 21, 2023
962e7e9
Resolve conflict (generic timer was moved to its own crate)
NathanRoyer Nov 21, 2023
3aa2ddf
Clippy Lint
NathanRoyer Nov 21, 2023
5c487ea
Merge fixes
NathanRoyer Nov 21, 2023
4949795
Improve PCI interrupt handler registration function
NathanRoyer Dec 6, 2023
9473e75
Improved PCI crate doc, replaced RwLocks with Mutexes
NathanRoyer Dec 6, 2023
c289c39
Merge branch 'usb-premod' into usb-ehci
NathanRoyer Dec 6, 2023
2a4cfbc
Fix Merge
NathanRoyer Dec 6, 2023
cb7cb55
Fix Clippy warnings
NathanRoyer Dec 6, 2023
dd0f1be
Merge remote-tracking branch 'theseus-os/theseus_main' into usb-ehci
NathanRoyer Dec 13, 2023
2189627
New PCI terminology for legacy interrupts
NathanRoyer Dec 13, 2023
e366ee6
Enable USB driver for x86
NathanRoyer Dec 13, 2023
d66e2ae
Update PCI functions
NathanRoyer Dec 13, 2023
8c65c0d
Make PCI intx handler registration lazy on all platforms
NathanRoyer Dec 22, 2023
442c7b2
Finish previous commit
NathanRoyer Dec 22, 2023
af01933
Fix function documentation
NathanRoyer Dec 22, 2023
fba4509
Remove `interrupts::init_pci_intx`
NathanRoyer Dec 22, 2023
ccef912
Merge remote-tracking branch 'theseus-os/theseus_main' into usb-ehci
NathanRoyer Dec 27, 2023
c38f86b
Add Makefile option for emulated USB HID devices
NathanRoyer Dec 27, 2023
fe48652
Improve USB driver documentation
NathanRoyer Dec 27, 2023
fcbd600
Improve doc & safety of usb::descriptors::Configuration::find_desc
NathanRoyer Jan 4, 2024
457a809
Doc improvements
NathanRoyer Jan 4, 2024
71b6a41
hot fix
NathanRoyer Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 60 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ debug ?= none
net ?= none
merge_sections ?= yes
bootloader ?= grub
usb_hid ?= no

## aarch64 only supports booting via UEFI
ifeq ($(ARCH),aarch64)
Expand Down Expand Up @@ -773,6 +774,12 @@ help:
@echo -e "\t Configure which bootloader to pack into the final \".iso\" file."
@echo -e "\t 'grub': Use the GRUB bootloader. Default value."
@echo -e "\t 'limine': Use the Limine bootloader. See setup instructions in the README."

@echo -e "\nThe following key-value options are available to emulate USB devices:"
@echo -e " usb_hid=yes|no"
@echo -e "\t Enables or disables the emulation of USB HID devices."
@echo -e "\t 'no': No USB HID device; enables PS/2 input on x86. Default value."
@echo -e "\t 'yes': Creates a virtual USB controller with keyboard and mouse plugged in."

@echo -e "\nThe following key-value options are available to customize the build process:"
@echo -e " merge_sections=yes|no"
Expand Down Expand Up @@ -949,13 +956,18 @@ else ifeq ($(ARCH),aarch64)
QEMU_FLAGS += -machine virt,gic-version=3
QEMU_FLAGS += -device ramfb
QEMU_FLAGS += -cpu cortex-a72
QEMU_FLAGS += -usb
QEMU_FLAGS += -device usb-ehci,id=ehci
QEMU_FLAGS += -device usb-kbd
else
QEMU_FLAGS += -cpu Broadwell
endif

## USB devices
ifeq ($(usb_hid),yes)
QEMU_FLAGS += -usb
QEMU_FLAGS += -device usb-ehci,id=ehci
QEMU_FLAGS += -device usb-kbd,bus=ehci.0
QEMU_FLAGS += -device usb-mouse,bus=ehci.0
endif

## Currently, kvm by itself can cause problems, but it works with the "host" option (above).
ifeq ($(kvm),yes)
$(error Error: the 'kvm=yes' option is currently broken. Use 'host=yes' instead")
Expand Down
1 change: 1 addition & 0 deletions kernel/device_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ serial_port = { path = "../serial_port" }
console = { path = "../console" }
logger = { path = "../logger" }
pci = { path = "../pci" }
usb = { path = "../usb" }
derive_more = "0.99.0"
mpmc = "0.1.6"
log = "0.4.8"
Expand Down
30 changes: 23 additions & 7 deletions kernel/device_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,35 @@ pub fn init(
}
}

if dev.class == 0x0C {
// Serial Bus Controller
if dev.subclass == 0x03 {
// USB controller
// Note: only aarch64 is supported due to use of legacy PCI interrupts
// #[cfg(target_arch = "aarch64")]
if dev.prog_if == 0x20 {
// EHCI
usb::init_pci(dev, usb::ControllerType::Ehci)?;
continue;
}
}
}

// If this is a network device, initialize it as such.
// Look for networking controllers, specifically ethernet cards
// No NIC support on aarch64 at the moment
#[cfg(target_arch = "x86_64")]
if dev.class == 0x02 && dev.subclass == 0x00 {
if dev.vendor_id == e1000::INTEL_VEND && dev.device_id == e1000::E1000_DEV {
info!("e1000 PCI device found at: {:?}", dev.location);
let nic = e1000::E1000Nic::init(dev)?;
let interface = net::register_device(nic);
nic.lock().init_interrupts(interface)?;
// The e1000 driver clashes with the USB driver
// if dev.vendor_id == e1000::INTEL_VEND && dev.device_id == e1000::E1000_DEV {
// info!("e1000 PCI device found at: {:?}", dev.location);
// let nic = e1000::E1000Nic::init(dev)?;
// let interface = net::register_device(nic);
// nic.lock().init_interrupts(interface)?;
//
// continue;
// }

continue;
}
if dev.vendor_id == ixgbe::INTEL_VEND && dev.device_id == ixgbe::INTEL_82599 {
info!("ixgbe PCI device found at: {:?}", dev.location);

Expand Down
19 changes: 19 additions & 0 deletions kernel/usb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
authors = ["Nathan Royer <[email protected]>"]
name = "usb"
description = "USB controllers and classes support"
version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4.8"
zerocopy = "0.5.0"
volatile = "0.2.7"
bilge = "0.2.0"

sync_irq = { path = "../../libs/sync_irq" }
memory = { path = "../memory" }
waker = { path = "../waker" }
spawn = { path = "../spawn" }
sleep = { path = "../sleep" }
pci = { path = "../pci" }
Loading