Skip to content

USB driver and terminal enhancements#70

Draft
Dreaded-Gnu wants to merge 144 commits into
bolthur:developfrom
Dreaded-Gnu:usb
Draft

USB driver and terminal enhancements#70
Dreaded-Gnu wants to merge 144 commits into
bolthur:developfrom
Dreaded-Gnu:usb

Conversation

@Dreaded-Gnu

@Dreaded-Gnu Dreaded-Gnu commented May 25, 2026

Copy link
Copy Markdown
Contributor

Pull request to add initial usb support

Closes #54
Closes #67

Things to be addressed:

  • USB
    • Finish hid driver
      • Add detach handler
      • Add deallocate handler
    • Finish keyboard driver
      • Add detach handler
      • Add deallocate handler
      • Route key presses to console input
        • Route input change to all processes reading /dev/stdin of current terminal
        • Fix return from console on return to e.g. login terminal
        • Fix getc used by getpass
        • Push to console async to prevent block
      • Implement stall handling
      • Implement set keyboard led
    • Implement mouse driver
      • Add attach handler
      • Add detach handler
      • Add deallocate handler
      • Implement stall handling
    • Finish hub driver
      • Add detach handler
      • Add deallocate handler
      • Add check change handler
      • Add check connection handler
      • Add child detach handler
      • Add child reset handler
      • Implement connect / disconnect watcher
    • hcd driver
      • Implement timeout handling
      • Implement handling for data toggle errors
      • Add setup packet handling before interrupt polling when no free channel is available
      • Implement check for polling already in progress or queued
    • Make whole usb stack work async like hcd
      • Split up usbd functions into single files
      • Rework usbd rpc functions to work async
      • Rework usbd code base to work async
      • Rework hid and keyboard code base to work with async usbd
      • Rework hub code base to work with async usbd
      • Rework hcd server in terms of polling to assign channel to some interrupt endpoint with interval calling then usbd server which shall invoke then the keyboard / mouse driver, when some data was transferred
      • Add proper error handling when attaching fails, since when it fails somewhere in the middle, device memory won't be destroyed
      • Attach roothub as rpc to prevent possible race condition
      • Get hub attach to work properly
      • Fix behaviour, that call chain is ending up in attach roothub finished
      • Add rpc to get device string information to usbd
      • Merge hcd_control_message_t and usb_control_message_t
      • Prevent floating shared memory when polling
  • Deduplicate and cleanup
    • Deduplicate mmio sequence and mailbox code by platform library
    • Move vfs static helper from header into own libvfs
  • Make console printing async
    • Change console write to invoke terminal rpc directly
    • Fix malformed fpu registers during task switch
    • Fix sometimes missing console output
    • Fix random data aborts in kernel
    • Fix randomly failing keyboard driver, somehow related to broken stack pointer / stack pointer alignment issue
    • Adjust nested rpc from same origin to prepend a rpc and mark current as inactive
    • Fix randomly hanging boot process in stage 1
  • Weird behaviours / implementations
    • Fix sometimes invoked rpc with invalid data.
    • Fix unstable usb setup hanging sometimes, looks like a race condition
    • Investigate hanging keyboard / mouse on simultaneous pull
    • Allow sleeps in rpc, by prepending sleep before current active rpc
  • Cleanup printing mess
  • Implement regular necessary rpc for daemons like exit or fork
  • Test on real hardware

- Removed test code at the end of init_stage2
- Added call to configuration_handle in init_stage3
- Added libhcd defines
- Added peripheral usb defines
- Fixed dynamic link flags
- Changed usb servers to link statically
- Replaced early startup print in usb servers by startup print
- Moved debug output in iomem dma into defined checks
- Started with error response for hcd
- Extended response enum by einval
- Added call to dwhci_init within main
- Created dwhci init and query vendor
- Added function to power on usb device
- Added call to power on usb device in dwhci init
- Added rpc init and rpc handle interrupt to dwhci
- Added bind of interrupt within rpc init
- Added call to rpc init before setup of hcd interface
- Added function to disable and enable interrupts
- Added empty functions to init core and init host
- Replaced magic interrupt numbers by defines
- Added whitelist of usb interrupt to raspi target in kernel
- Added new generic libhcd and libusb to server folder
- Adjusted include guards of raspi platform lib files
- Added new empty submit control message rpc to hcd server later used by usbd
- Added enable rpc, send of device file and wait for rpc to hcd server
- Added hct_submit_control_message_t type for hcd rpc
- Filled submit_control_message rpc with a bit of logic to at least read message from mailbox
…init

- Generated usb device structure used by usbd
…force cache drain

- some ongoing const changes
- Added define for hcd device path
- Replaced magic string in hcd server by define
- Adjusted message for hcd submit control message to expect it put into shared area
- Created helpers to transfer packet size from number into type and vice versa
- Created helper to translate usb speed into strings
- Added hub structures to libusb
- Extended libhcd by power registers and completed host port registers
- Temporarily commented out dma for usb
- Made fd_iomem non static since it is required in new root hub function
- Added new dwhci function to write host port
- Added dwhciroothub function necessary for root hub init
- Revised submit_control_message rpc to map shared memory and perform root hub process if set
- First iteration of usbd yet without enumeration of connected devices
- Added populate of device path, yet without any rpc bound to it
- Added some newlines where it was missing in STARTUP_PRINT
- Started working on hub driver while working on usbd necessary for enumeration
- Added rpc structures for register and unregister device handler
- Added rpc handler for register and unregister device handler
- Added new libusb library to abstract communication with usbd a bit
- Added two new rpcs, one for performing control message and one to get description
- Added init of usb library to hub driver
- Started implementing usb hub init
- Cleaned up usb library to reduce the message sizes
- Replaced pass of libusb_device_t by pass of necessary stuff
- Created new usbd endpoints for fetching endpoint and interface
- Revised startup to startup usbd and all related daemons before starting hcd
-
- Added sleep to stage 3 init
- Added documentation to dwhci functions
- Encapsulated all startup prints by dwhci enable debug define in dwhci
- Cleaned up dwhci include
- Temporarily enabled data abort exception printing
- Fixed usbd_read_string to use wctob to translate wide char to char
…orted

- Updated readme regarding qemu commands
- Added qemu cdc lan to usbd_get_description
- Splitted up usb server related stuff from libusb into libusbd
- Added hub rpc defines
- Updated device_info of hub main used for registering path
- Created empty rpc for check change, check connection, child detach, child reset and detach
- Adjusted hub init to bind rpc handlers
- Added new hid device acting as connector between usbd and keyboard and mouse
- Reokaced device driver hub define by enum
- Added hid, keyboard and mouse to device driver enum
- Extended image.nim to generate home user directory
- Added plain kasan library with minimum necessary functions doing nothing right now
- Added sanitize option kernel-address when building with debug symbols
- Added own heap implementation for kasan
- Added extra linker scripts when sanitizer is active with fixed sanitizer memory
- Added new has sanitizer conditional to kernel configure.ac
- Revised raspi Makefile.am to link kasan and ubsan only when sanitizer is set
- Added switch between linker script with and without sanitizer depending on conditional
- Added __bootstrap to firmware_startup_init and initrd_startup_init
- Adjusted map temporary to perform startup map when virtual memory wasn't yet initialized
- Removed unnecessary kasan heap and list code
- Removed also unnecessary sanitizer linker scripts
- Updated raspi memory map by area for kasan
- Implemented kasan functions for detecting issues
- Remove automatic memset from alloc and added memset where it was missing
- Added new helper to get heap state
- Added init of kasan within normal heap init
- Added call to kasan poison shadow when extending the heap
- Fixed kasan read error within strlen implementation
- Fixed memset issue and added call to kasan_check_memory
- Added call to kasan_check_memory within memcpy
- Revised aligned_alloc and free to call kasan hooks if activated
- Integrated unmap of initrd in kernel after control has been passed to boot
- Introduced new helper to get file handler of a server
- Added libusb dependency and ldadd to hid Makefile.am
- Ported global header from hub
- Finished main of hid server
- Added printing of surrounding memory to kasan with respect of mapped areas
- Removed sanitizer defines from heap header and move last remaining into kasan
- Added plain rpc to keyboard and mouse
- Added main logic to keyboard and mouse
- Created new libhid abstracting away hid operations
- Removed usb storage from stage3 until hid, mouse and keyboard are done and a basic stack is there
- Created handler management functions
- Implemented register and unregister handler
- Fixed defined checks in libhid
- Fixed register of usbd handler in hid
…o debug symbols

- Started working on hid attach logic
- Added new rpc call to get configuration data from usbd by device number
- Added new rpc call to get device status from usbd by device number
- Created usb wrapper to fetch configuration data
- Created usb wrapper to fetch device status
- Replaced libhid_interface_type_t by libusb_hid_usage_page_desktop_t
- Continued working on hid attach
- Added handler_call_attach helper to hid handler logic
- Replaced RPC_CUSTOM_START within usbd call.c by GENERIC_ATTACH
- Fixed tree usage in hid handler logic
- Started adding logic to keyboard attach
- Started adding logic to mouse attach
- Added store of hub device to attach into a hub list
…of heap

- Added defines for kernel area process replace start and end
- Updated memory map
- Moved typedefs from hid attach into header hid of process hid
- Moved hid destroy device into hid.c and added removal from hid list
- Added save of device_number within hid device and hub device
- Added documentation to attach hub functions before moving them
- Added cache of descriptor in hub device instance
- Added free of descriptor on error within hub attach
- Added structures and enums for keyboard and mouse
- Implemented list of keyboard and list of mouse to specific driver with append method
- Moved static hub attach functions into hub.c
- Refactored some variable names in rpc functions
…ge async function

- Cleaned up some output and renamed some local variables in usbd control message finished rpc
- Reworked usbd rpc get descriptor rpc to use async function
- Some const and nullptr changes in terminal psf
- Replaced remaining NULL by nullptr
- Fixed allocator attribute
- Replaced usages by new libvfs functions
…ponse status only in case result is positive

- Added set of result to attach result in usbd attach rpc
- Removed old iomem includes below server/platform/raspi
- Adjusted includes where iomem is used
- Fixed a bunch of places where call of iomem_release_mmio_sequence was missing ( leaks )
- Fixed bunch of include paths after running cppcheck
- Added attribute __malloc__ to mmio prepare sequence and prepare mailbox
- Removed read of manufacturer from usbd attach
- Removed read of serial number from usbd attach
- Removed read of configuration from usbd attach
- Marked functions to be reworked to async for async attach
- Specified iomem_mailbox_release as wanted deallocator for iomem_prepare_mailbox
- Specified iomem_release_mmio_sequence as wanted deallocator for iomem_prepare_mmio_sequence
- Fixed build issues after tweaking iomem library
- Adjusted calls to usbd_attach_device to pass either data or 0
- Transformed usbd_async_context_t into usbd_attach_context_t
- Created static helper in attach to create or destroy a context
- Created empty callbacks for specific attach steps
- Moved attach context create and destroy into context file
- Added functions to create and destroy descriptor context
- Extended usbd control message async by context parameter
- Extended usbd descriptor get async by context parameter
- Extended usbd descriptor read device by parameters callback and context
- Added empty functions for read device step 1 and read device finished
- Moved logic for attaching roothub into rpc
- Created new function to fire roothub attach
- Added cleanup of rpc to dwhci interrupt handler
- Some auto and const replacements
- Added wait for ramdisk within authentication server to prevent lock up
- Prevented destroy of active backup when it's an interrupt in syscall rpc ret
- Changed syscall rpc raise to populate response in backup context when thread is current and rpc already active
- Adjusted timer invoke to not pass entry id as origin data id which may result in lockups since this is designed for rpc only
- Removed unnecessary code with replacements of rpc when backup is different and data id bigger to preserve the order in queue
- Started adding rpc logic to deactivate active rpc when a nested interrupt is detected ( currently commented out )
- Surrounded DEBUG_OUTPUT in DUMP_REGISTER by curved brackets
…rpc_raise

- Replaced some NULL by nullptr in rpc syscall
- Added pass of context, origin and data info to usb_attach_device of libusb
- Removed rpc cleanup in hcd interrupt handler since that happens automatically
- Reworked hub attach to asynchronous port enumeration to prevent lockups
- Replaced return to return everywhere in attach process with RPC_VFS_IOCTL
- Removed with_return flag from usbd attach contexts since everything works via rpc
- Changed esotheric rpc return to use async data instead of some weird context id
- Added missing calls to rpc cleanup in keyboard key handler
- Introduced two new methods to usbd to get, enable or disable enumeration mode
- Added enable of enumeration mode before firing roothub attach
- Added disable of enumeration mode when roothub was successfully attached
- Added check for enumeration mode in interrupt polling returning EAGAIN
- Extended keyboard key handler by enumeration active check
- Started creating a control message context for deduplicating code
- Encapsulated debug printings by defines where it made sense
- Dropped request and request size from roothub attach
- Some const changes in keyboard key rpc
- Added libutil to mouse driver
- Implemented mouse attach
- Added mouse rpc for polling
- Added error handling to poll async calls with reset of running poll
- Adjusted keyboard code to poll depending on global enumerating flag queried if true
- Added set of enumerating to true as soon as an EAGAIN drops in for keyboard and mouse
- Fixed mouse x / y and wheel types to signed 8 bit integer
- Adjusted transfer of buffer into device in key handling with detach afterwards
- Implemented mouse rpc callback to populate device
- Const and nullptr changes
- Adjusted rpc_generic_prepare_invoke to adjust backup thread state when a timer is active
- Deactivated usbd, mouse and keyboard debug output
- Added handling of any other error by printing error in mouse and keyboard
- Changed push to console from sync to async
- Transformed poll async into sync function
- Removed last usb pid and previous transferred packet from interrupt poll message
- Removed last usb pid and last packet count from keyboard and mouse device
- Added define for charactersitic interval section to libhcd
- Added hcd server as allowed origin to usbd
- Added usbd server as allowed origin to keyboard and mouse
- Moved start polling into mouse and keyboard attach and removed manual polling
- Fixed channel count read out in dwhci init with channel preparation
- Added support for channel polling via interval and frames
- Started reworking usbd poll rpc
- Introduced some new generic interrupt request to usbd responsible for routing back changes
…ture

- Dropped last_poll and running_poll from keyboard and mouse structures
- Reworked dwhci for channel based interrupt polling
- Adjusted keyboard key handler and mouse handler to not detach shared memory
- Reworked usbd interrupt poll to use usb_interrupt_poll_t
- Implemented generic interrupt poll handler
…nce it is the same structure

- Encapsulated output by defined checks and removed debugging output
- Added new interrupt poll return containing read bytes in message to prevent shared memory
- Added duplication of data in dwhci queue add entry to be able to free up poll shared memory
- Adjusted control message handling to acquire shared memory for copy over of result
- Removed not any longer necessary delay in stage1
- Replaced casted null by 0 in libusbd control message functions
- Removed not necessary enumerating functions and rpc from usbd
- Replaced fetch of roothub in hub shall attach by parameter for roothub device number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speed up printing to console Implement usb driver

1 participant