driver.bus.usb.core¶
USB host controller management and device enumeration core.
Overview¶
This unit is the central coordination layer of the USB subsystem. It manages a list of registered host controllers, drives device enumeration, dispatches transfers, and provides a completion hook system for asynchronous notifications. Upper-layer drivers interact with attached USB devices exclusively through this unit's transfer API.
Dependencies¶
driver.bus.usb.typesdriver.mgrsyslogcore.memory
Functions and Procedures¶
init¶
Initialises internal host controller and completion hook tables.register_hc / unregister_hc¶
Adds or removes a host controller from the managed list. Called by UHCI/OHCI/EHCI/xHCI drivers after they have initialised their hardware.get_hc_count¶
Returns the number of currently registered host controllers.get_hc¶
Returns a pointer to the host controller at the given index.scan_ports¶
Iterates all registered host controllers and triggers port scanning on each. For each populated port, callsenumerate_device.
poll_all¶
Calls the poll callback on every registered host controller. Intended to be called periodically from the kernel main loop or a timer interrupt.enumerate_device¶
Runs the USB enumeration sequence for a newly detected device: assigns an address, reads descriptors, sets the active configuration, and callsdriver.mgr.register_device with a USB bus identifier so that class drivers are loaded.
usb_rescan_port¶
Re-enumerates a single port, used for hotplug events.usb_remove_device¶
Tears down a device: cancels pending transfers, notifies class drivers via completion hooks, and frees device memory.register_completion_hook / fire_completion_hooks¶
procedure register_completion_hook(hook: TUSBCompletionHook);
procedure fire_completion_hooks(transfer: PUSBTransfer);
fire_completion_hooks iterates all registered hooks and calls each with the completed transfer.
usb_control_msg¶
function usb_control_msg(device: PUSBDevice; setup: TUSBSetupPacket; data: pointer; length: uint32): TUSBTransferStatus;
usb_get_descriptor¶
function usb_get_descriptor(device: PUSBDevice; desc_type, desc_index: uint8; buf: pointer; length: uint16): TUSBTransferStatus;
usb_control_msg for standard GET_DESCRIPTOR requests.
usb_set_address¶
Issues a SET_ADDRESS control request to assign the device its bus address.usb_set_configuration¶
Issues a SET_CONFIGURATION control request to activate a configuration.usb_interrupt_transfer¶
function usb_interrupt_transfer(device: PUSBDevice; endpoint: PUSBEndpoint; data: pointer; length: uint32): PUSBTransfer;
usb_bulk_transfer¶
function usb_bulk_transfer(device: PUSBDevice; endpoint: PUSBEndpoint; data: pointer; length: uint32): PUSBTransfer;
usb_bulk_transfer_wait¶
function usb_bulk_transfer_wait(device: PUSBDevice; endpoint: PUSBEndpoint; data: pointer; length: uint32): TUSBTransferStatus;
usb_clear_halt¶
Issues a CLEAR_FEATURE(ENDPOINT_HALT) request to clear a stalled endpoint.usb_find_interface / usb_find_interface_n¶
function usb_find_interface(device: PUSBDevice; class_code, subclass, protocol: uint8): PUSBInterfaceDescriptor;
function usb_find_interface_n(device: PUSBDevice; class_code, subclass, protocol: uint8; n: uint8): PUSBInterfaceDescriptor;
_n returns the nth match.
usb_count_endpoints / usb_find_endpoint¶
function usb_count_endpoints(iface: PUSBInterfaceDescriptor): uint8;
function usb_find_endpoint(iface: PUSBInterfaceDescriptor; direction: TUSBDirection; transfer_type: TUSBPipeType): PUSBEndpointDescriptor;
Notes¶
- The enumeration pipeline assigns device addresses starting from 1 and increments for each newly attached device.
- Class driver loading is performed by calling
driver.mgr.register_devicewithbus = biUSBand identifier fields set from the interface descriptor (class, subclass, protocol). poll_allmust be called regularly; it is the mechanism by which interrupt transfer completions are detected for host controllers that do not use hardware interrupts.