Files | |
file | ports.c |
Hub ports functions. | |
file | ports.h |
Hub ports related functions. | |
file | usbhub.c |
usb hub main functionality | |
file | usbhub.h |
Hub driver. | |
file | usbhub_private.h |
Hub driver private definitions. | |
file | utils.c |
various utilities | |
Data Structures | |
struct | add_device_phase1 |
Information for fibril for device discovery. More... | |
struct | usb_hub_info_t |
Information about attached hub. More... | |
struct | usb_hub_port_t |
Information about single port on a hub. More... | |
Defines | |
#define | NAME "usbhub" |
Typedefs | |
typedef usb_hub_info_t | usb_hub_info_t |
typedef uint32_t | usb_hub_status_t |
structure holding hub status and changes flags. | |
typedef uint32_t | usb_port_status_t |
structure holding port status and changes flags. | |
Functions | |
static int | add_device_phase1_worker_fibril (void *arg) |
Fibril for adding a new device. | |
static int | create_add_device_fibril (usb_hub_info_t *hub, size_t port, usb_speed_t speed) |
Start device adding when connection change is detected. | |
static int | enable_port_callback (int port_no, void *arg) |
Callback for enabling a specific port. | |
static int | get_port_status (usb_pipe_t *ctrl_pipe, size_t port, usb_port_status_t *status) |
Retrieve port status. | |
bool | hub_port_changes_callback (usb_device_t *dev, uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) |
Callback for polling hub for changes. | |
int | main (int argc, char *argv[]) |
Main entry point. | |
usb_hub_descriptor_t * | usb_create_deserialized_hub_desriptor (void *serialized_descriptor) |
create deserialized desriptor structure out of serialized descriptor | |
void * | usb_create_serialized_hub_descriptor (usb_hub_descriptor_t *descriptor) |
create uint8_t array with serialized descriptor | |
void | usb_deserialize_hub_desriptor (void *serialized_descriptor, usb_hub_descriptor_t *descriptor) |
deserialize descriptor into given pointer | |
int | usb_hub_add_device (usb_device_t *usb_dev) |
Initialize hub device driver fibril. | |
static int | usb_hub_clear_feature (usb_pipe_t *pipe, usb_hub_class_feature_t feature) |
Clear feature on hub port. | |
static int | usb_hub_clear_port_feature (usb_pipe_t *pipe, int port_index, usb_hub_class_feature_t feature) |
Clear feature on hub port. | |
static usb_device_request_setup_packet_t * | usb_hub_create_disable_port_request (uint16_t port) |
disable specified port | |
static usb_device_request_setup_packet_t * | usb_hub_create_enable_port_request (uint16_t port) |
enable specified port | |
static usb_device_request_setup_packet_t * | usb_hub_create_port_status_request (uint16_t port) |
create request for usb hub port status | |
static usb_device_request_setup_packet_t * | usb_hub_create_reset_port_request (uint16_t port) |
disable specified port | |
static usb_hub_info_t * | usb_hub_info_create (usb_device_t *usb_dev) |
create usb_hub_info_t structure | |
static bool | usb_hub_is_status (usb_hub_status_t status, int idx) |
get i`th bit of hub status | |
static void | usb_hub_polling_terminated_callback (usb_device_t *device, bool was_error, void *data) |
callback called from hub polling fibril when the fibril terminates | |
static void | usb_hub_port_init (usb_hub_port_t *port) |
Initialize hub port information. | |
static void | usb_hub_port_over_current (usb_hub_info_t *hub, uint16_t port, uint32_t status) |
Process over current condition on port. | |
static void | usb_hub_port_reset_completed (usb_hub_info_t *hub, uint16_t port, uint32_t status) |
Process port reset change. | |
static void | usb_hub_process_global_interrupt (usb_hub_info_t *hub_info) |
process hub interrupts | |
static int | usb_hub_process_hub_specific_info (usb_hub_info_t *hub_info) |
Load hub-specific information into hub_info structure and process if needed. | |
void | usb_hub_process_port_interrupt (usb_hub_info_t *hub, uint16_t port) |
Process interrupts on given hub port. | |
static void | usb_hub_removed_device (usb_hub_info_t *hub, uint16_t port) |
routine called when a device on port has been removed | |
static int | usb_hub_set_configuration (usb_hub_info_t *hub_info) |
Set configuration of hub. | |
static void | usb_hub_set_descriptor_request (usb_device_request_setup_packet_t *request) |
Set the device request to be a get hub descriptor request. | |
static void | usb_hub_set_disable_port_feature_request (usb_device_request_setup_packet_t *request, uint16_t port, uint16_t feature_selector) |
set the device request to be a port feature clear request | |
static void | usb_hub_set_disable_port_request (usb_device_request_setup_packet_t *request, uint16_t port) |
set the device request to be a port disable request | |
static void | usb_hub_set_enable_port_feature_request (usb_device_request_setup_packet_t *request, uint16_t port, uint16_t feature_selector) |
set the device request to be a port feature enable request | |
static void | usb_hub_set_enable_port_request (usb_device_request_setup_packet_t *request, uint16_t port) |
set the device request to be a port enable request | |
static int | usb_hub_set_feature (usb_pipe_t *pipe, usb_hub_class_feature_t feature) |
Clear feature on hub port. | |
static void | usb_hub_set_hub_status_request (usb_device_request_setup_packet_t *request) |
set values in request to be it a port status request | |
static int | usb_hub_set_port_feature (usb_pipe_t *pipe, int port_index, usb_hub_class_feature_t feature) |
Clear feature on hub port. | |
static void | usb_hub_set_port_status_request (usb_device_request_setup_packet_t *request, uint16_t port) |
set values in request to be it a port status request | |
static void | usb_hub_set_power_port_request (usb_device_request_setup_packet_t *request, uint16_t port) |
set the device request to be a port disable request | |
static void | usb_hub_set_reset_port_request (usb_device_request_setup_packet_t *request, uint16_t port) |
set the device request to be a port disable request | |
static int | usb_hub_start_hub_fibril (usb_hub_info_t *hub_info) |
create and start fibril with hub control loop | |
static void | usb_hub_status_set_bit (usb_hub_status_t *status, int idx, bool value) |
set i`th bit of hub status | |
static void | usb_hub_unset_power_port_request (usb_device_request_setup_packet_t *request, uint16_t port) |
set the device request to be a port disable request | |
static bool | usb_port_high_speed (usb_port_status_t status) |
high speed device on the port indicator | |
static bool | usb_port_is_status (usb_port_status_t status, int idx) |
get i`th bit of port status | |
static bool | usb_port_low_speed (usb_port_status_t status) |
low speed device on the port indicator | |
static void | usb_port_set_high_speed (usb_port_status_t *status, bool high_speed) |
set high speed device bit in port status | |
static void | usb_port_set_low_speed (usb_port_status_t *status, bool low_speed) |
set low speed device connected bit in port status | |
static usb_speed_t | usb_port_speed (usb_port_status_t status) |
speed getter for port status | |
static void | usb_port_status_set_bit (usb_port_status_t *status, int idx, bool value) |
set i`th bit of port status | |
static int | usb_process_hub_local_power_change (usb_hub_info_t *hub_info, usb_hub_status_t status) |
process hub local power change | |
static int | usb_process_hub_over_current (usb_hub_info_t *hub_info, usb_hub_status_t status) |
process hub over current change | |
void | usb_serialize_hub_descriptor (usb_hub_descriptor_t *descriptor, void *serialized_descriptor) |
serialize descriptor into given buffer | |
Variables | |
static usb_endpoint_description_t | hub_status_change_endpoint_description |
Hub status-change endpoint description. | |
static const int | non_handled_changes [] |
port status changes that are not explicitly handled by any function here and must be cleared by hand | |
static const unsigned int | non_handled_changes_count = 2 |
count of port status changes that are not explicitly handled by any function here and must be cleared by hand | |
static usb_driver_t | usb_hub_driver |
static usb hub driver information | |
static usb_driver_ops_t | usb_hub_driver_ops |
usb hub driver operations | |
static usb_endpoint_description_t * | usb_hub_endpoints [] |
hub endpoints, excluding control endpoint | |
size_t | USB_HUB_MAX_DESCRIPTOR_SIZE = 71 |
Maximum size of usb hub descriptor in bytes. |
typedef uint32_t usb_hub_status_t |
structure holding hub status and changes flags.
should not be accessed directly, use supplied getter/setter methods.
For more information refer to table 11.16.2.5 in "Universal Serial Bus Specification Revision 1.1"
Definition at line 58 of file port_status.h.
typedef uint32_t usb_port_status_t |
structure holding port status and changes flags.
should not be accessed directly, use supplied getter/setter methods.
For more information refer to table 11-15 in "Universal Serial Bus Specification Revision 1.1"
Definition at line 48 of file port_status.h.
static int add_device_phase1_worker_fibril | ( | void * | arg | ) | [static] |
Fibril for adding a new device.
Separate fibril is needed because the port reset completion is announced via interrupt pipe and thus we cannot block here.
arg | Pointer to struct add_device_phase1. |
static int create_add_device_fibril | ( | usb_hub_info_t * | hub, | |
size_t | port, | |||
usb_speed_t | speed | |||
) | [static] |
static int enable_port_callback | ( | int | port_no, | |
void * | arg | |||
) | [static] |
Callback for enabling a specific port.
We wait on a CV until port is reseted. That is announced via change on interrupt pipe.
port_no | Port number (starting at 1). | |
arg | Custom argument, points to usb_hub_info_t . |
static int get_port_status | ( | usb_pipe_t * | ctrl_pipe, | |
size_t | port, | |||
usb_port_status_t * | status | |||
) | [static] |
bool hub_port_changes_callback | ( | usb_device_t * | dev, | |
uint8_t * | change_bitmap, | |||
size_t | change_bitmap_size, | |||
void * | arg | |||
) |
Callback for polling hub for changes.
dev | Device where the change occured. | |
change_bitmap | Bitmap of changed ports. | |
change_bitmap_size | Size of the bitmap in bytes. | |
arg | Custom argument, points to usb_hub_info_t . |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
usb_hub_descriptor_t * usb_create_deserialized_hub_desriptor | ( | void * | serialized_descriptor | ) |
create deserialized desriptor structure out of serialized descriptor
The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur.
sdescriptor | serialized descriptor |
void * usb_create_serialized_hub_descriptor | ( | usb_hub_descriptor_t * | descriptor | ) |
void usb_deserialize_hub_desriptor | ( | void * | serialized_descriptor, | |
usb_hub_descriptor_t * | descriptor | |||
) |
int usb_hub_add_device | ( | usb_device_t * | usb_dev | ) |
static int usb_hub_clear_feature | ( | usb_pipe_t * | pipe, | |
usb_hub_class_feature_t | feature | |||
) | [inline, static] |
Clear feature on hub port.
pipe | pipe to hub control endpoint | |
feature | Feature selector |
Definition at line 132 of file usbhub_private.h.
static int usb_hub_clear_port_feature | ( | usb_pipe_t * | pipe, | |
int | port_index, | |||
usb_hub_class_feature_t | feature | |||
) | [inline, static] |
Clear feature on hub port.
hc | Host controller telephone | |
address | Hub address | |
port_index | Port | |
feature | Feature selector |
Definition at line 86 of file usbhub_private.h.
static usb_device_request_setup_packet_t* usb_hub_create_disable_port_request | ( | uint16_t | port | ) | [inline, static] |
static usb_device_request_setup_packet_t* usb_hub_create_enable_port_request | ( | uint16_t | port | ) | [inline, static] |
static usb_device_request_setup_packet_t* usb_hub_create_port_status_request | ( | uint16_t | port | ) | [inline, static] |
create request for usb hub port status
port |
Definition at line 94 of file port_status.h.
static usb_device_request_setup_packet_t* usb_hub_create_reset_port_request | ( | uint16_t | port | ) | [inline, static] |
static usb_hub_info_t * usb_hub_info_create | ( | usb_device_t * | usb_dev | ) | [static] |
create usb_hub_info_t structure
Does only basic copying of known information into new structure.
usb_dev | usb device structure |
static bool usb_hub_is_status | ( | usb_hub_status_t | status, | |
int | idx | |||
) | [inline, static] |
get i`th bit of hub status
status | ||
idx |
Definition at line 280 of file port_status.h.
static void usb_hub_polling_terminated_callback | ( | usb_device_t * | device, | |
bool | was_error, | |||
void * | data | |||
) | [static] |
callback called from hub polling fibril when the fibril terminates
Should perform a cleanup - deletes hub_info.
device | usb device afected | |
was_error | indicates that the fibril is stoped due to an error | |
data | pointer to usb_hub_info_t structure |
static void usb_hub_port_init | ( | usb_hub_port_t * | port | ) | [inline, static] |
static void usb_hub_port_over_current | ( | usb_hub_info_t * | hub, | |
uint16_t | port, | |||
uint32_t | status | |||
) | [static] |
static void usb_hub_port_reset_completed | ( | usb_hub_info_t * | hub, | |
uint16_t | port, | |||
uint32_t | status | |||
) | [static] |
static void usb_hub_process_global_interrupt | ( | usb_hub_info_t * | hub_info | ) | [static] |
static int usb_hub_process_hub_specific_info | ( | usb_hub_info_t * | hub_info | ) | [static] |
Load hub-specific information into hub_info structure and process if needed.
Particularly read port count and initialize structure holding port information. If there are non-removable devices, start initializing them. This function is hub-specific and should be run only after the hub is configured using usb_hub_set_configuration function.
hub_info | hub representation |
void usb_hub_process_port_interrupt | ( | usb_hub_info_t * | hub, | |
uint16_t | port | |||
) |
static void usb_hub_removed_device | ( | usb_hub_info_t * | hub, | |
uint16_t | port | |||
) | [static] |
routine called when a device on port has been removed
If the device on port had default address, it releases default address. Otherwise does not do anything, because DDF does not allow to remove device from it`s device tree.
hub | hub representation | |
port | port number, starting from 1 |
remove device from device manager - not yet implemented in devide manager
static int usb_hub_set_configuration | ( | usb_hub_info_t * | hub_info | ) | [static] |
static void usb_hub_set_descriptor_request | ( | usb_device_request_setup_packet_t * | request | ) | [inline, static] |
Set the device request to be a get hub descriptor request.
request | ||
addr |
Definition at line 66 of file usbhub_private.h.
static void usb_hub_set_disable_port_feature_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port, | |||
uint16_t | feature_selector | |||
) | [inline, static] |
set the device request to be a port feature clear request
request | ||
port | ||
feature_selector |
Definition at line 123 of file port_status.h.
static void usb_hub_set_disable_port_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port | |||
) | [inline, static] |
set the device request to be a port disable request
request | ||
port |
Definition at line 167 of file port_status.h.
static void usb_hub_set_enable_port_feature_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port, | |||
uint16_t | feature_selector | |||
) | [inline, static] |
set the device request to be a port feature enable request
request | ||
port | ||
feature_selector |
Definition at line 107 of file port_status.h.
static void usb_hub_set_enable_port_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port | |||
) | [inline, static] |
set the device request to be a port enable request
request | ||
port |
Definition at line 139 of file port_status.h.
static int usb_hub_set_feature | ( | usb_pipe_t * | pipe, | |
usb_hub_class_feature_t | feature | |||
) | [inline, static] |
Clear feature on hub port.
pipe | pipe to hub control endpoint | |
feature | Feature selector |
Definition at line 153 of file usbhub_private.h.
static void usb_hub_set_hub_status_request | ( | usb_device_request_setup_packet_t * | request | ) | [inline, static] |
set values in request to be it a port status request
request | ||
port |
Definition at line 79 of file port_status.h.
static int usb_hub_set_port_feature | ( | usb_pipe_t * | pipe, | |
int | port_index, | |||
usb_hub_class_feature_t | feature | |||
) | [inline, static] |
Clear feature on hub port.
hc | Host controller telephone | |
address | Hub address | |
port_index | Port | |
feature | Feature selector |
Definition at line 110 of file usbhub_private.h.
static void usb_hub_set_port_status_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port | |||
) | [inline, static] |
set values in request to be it a port status request
request | ||
port |
Definition at line 65 of file port_status.h.
static void usb_hub_set_power_port_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port | |||
) | [inline, static] |
set the device request to be a port disable request
request | ||
port |
Definition at line 223 of file port_status.h.
static void usb_hub_set_reset_port_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port | |||
) | [inline, static] |
set the device request to be a port disable request
request | ||
port |
Definition at line 195 of file port_status.h.
static int usb_hub_start_hub_fibril | ( | usb_hub_info_t * | hub_info | ) | [static] |
static void usb_hub_status_set_bit | ( | usb_hub_status_t * | status, | |
int | idx, | |||
bool | value | |||
) | [inline, static] |
set i`th bit of hub status
status | ||
idx | ||
value |
Definition at line 291 of file port_status.h.
static void usb_hub_unset_power_port_request | ( | usb_device_request_setup_packet_t * | request, | |
uint16_t | port | |||
) | [inline, static] |
set the device request to be a port disable request
request | ||
port |
Definition at line 238 of file port_status.h.
static bool usb_port_high_speed | ( | usb_port_status_t | status | ) | [inline, static] |
high speed device on the port indicator
status |
Definition at line 326 of file port_status.h.
static bool usb_port_is_status | ( | usb_port_status_t | status, | |
int | idx | |||
) | [inline, static] |
get i`th bit of port status
status | ||
idx |
Definition at line 255 of file port_status.h.
static bool usb_port_low_speed | ( | usb_port_status_t | status | ) | [inline, static] |
low speed device on the port indicator
status |
Definition at line 304 of file port_status.h.
static void usb_port_set_high_speed | ( | usb_port_status_t * | status, | |
bool | high_speed | |||
) | [inline, static] |
set high speed device bit in port status
status | ||
high_speed | value of the bit |
Definition at line 336 of file port_status.h.
static void usb_port_set_low_speed | ( | usb_port_status_t * | status, | |
bool | low_speed | |||
) | [inline, static] |
set low speed device connected bit in port status
status | ||
low_speed | value of the bit |
Definition at line 314 of file port_status.h.
static usb_speed_t usb_port_speed | ( | usb_port_status_t | status | ) | [inline, static] |
speed getter for port status
status |
Definition at line 346 of file port_status.h.
static void usb_port_status_set_bit | ( | usb_port_status_t * | status, | |
int | idx, | |||
bool | value | |||
) | [inline, static] |
set i`th bit of port status
status | ||
idx | ||
value |
Definition at line 266 of file port_status.h.
static int usb_process_hub_local_power_change | ( | usb_hub_info_t * | hub_info, | |
usb_hub_status_t | status | |||
) | [static] |
static int usb_process_hub_over_current | ( | usb_hub_info_t * | hub_info, | |
usb_hub_status_t | status | |||
) | [static] |
void usb_serialize_hub_descriptor | ( | usb_hub_descriptor_t * | descriptor, | |
void * | serialized_descriptor | |||
) |
Initial value:
{ .transfer_type = USB_TRANSFER_INTERRUPT, .direction = USB_DIRECTION_IN, .interface_class = USB_CLASS_HUB, .interface_subclass = 0, .interface_protocol = 0, .flags = 0 }
For more information see section 11.15.1 of USB 1.1 specification.
usb_driver_ops_t usb_hub_driver_ops [static] |
Initial value:
{ .add_device = usb_hub_add_device }
The most important one is add_device, which is set to usb_hub_add_device.