Add basic xHCI driver and USB devices enumeration

This commit is contained in:
2026-08-07 21:11:08 +03:00
parent a2128de3e2
commit 4813725cf3
12 changed files with 721 additions and 117 deletions
+44
View File
@@ -0,0 +1,44 @@
#include "src/kernel/usb.h"
#include "src/kernel/log.h"
#include "src/kernel/stream.h"
#include "src/kernel/xhci.h"
typedef struct __attribute__((packed)) {
uint8_t length;
uint8_t descriptor_type; // 0x01 for device descriptor
uint16_t usb_version; // BCD, e.g. 0x0200 for USB 2.0
uint8_t device_class;
uint8_t device_subclass;
uint8_t device_protocol;
uint8_t max_packet_size; // for ep0
uint16_t vendor_id;
uint16_t product_id;
uint16_t device_version;
uint8_t manufacturer_str;
uint8_t product_str;
uint8_t serial_str;
uint8_t num_configurations;
} usb_device_descriptor_t;
static usb_device_descriptor_t device_descriptor __attribute__((aligned(64)));
void usb_init() {
LOG_LN("Enumerating devices...");
usb_enumerate(kernel_log);
LOG_LN("Done.");
}
void usb_enumerate(stream_t *out) {
for (uint8_t i = 0; i < xhci_port_count(); i++) {
if (!xhci_port_connected(i)) {
continue;
}
xhci_slot_t slot = xhci_attach(i);
xhci_control_transfer(slot, 0x0012000001000680ULL, &device_descriptor, sizeof(usb_device_descriptor_t));
PRINT_LN(out, "%hx:%hx class=%hx subclass=%hx protocol=%hx", device_descriptor.vendor_id, device_descriptor.product_id,
device_descriptor.device_class, device_descriptor.device_subclass, device_descriptor.device_protocol);
}
}