#include "devices/usb.h"
#include "devices/usb_hub.h"
#include "threads/synch.h"
#include "threads/malloc.h"
#include "devices/timer.h"
#include <kernel/bitmap.h>
#include <string.h>
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | desc_header |
struct | device_descriptor |
struct | device_qualifier |
struct | config_descriptor |
struct | interface_descriptor |
struct | endpoint_descriptor |
struct | host |
struct | class |
Defines | |
#define | ADDRS_PER_HOST 127 |
#define | ADDR_DEFAULT 0 |
#define | ADDR_FIRST 1 |
#define | SETUP_DESC_DEVICE 1 |
#define | SETUP_DESC_CONFIG 2 |
#define | SETUP_DESC_STRING 3 |
#define | SETUP_DESC_IFACE 4 |
#define | SETUP_DESC_ENDPOINT 5 |
#define | SETUP_DESC_DEVQUAL 6 |
#define | SETUP_DESC_SPDCONFIG 7 |
#define | SETUP_DESC_IFACEPWR 8 |
#define | USB_CLASS_HUB 0x09 |
#define | usb_lock() lock_acquire(&usb_sys_lock) |
#define | usb_unlock() lock_release(&usb_sys_lock) |
#define | MAX_USB_STR 128 |
Functions | |
static void | usb_scan_devices (struct host *h) |
static struct usb_dev * | usb_configure_default (struct host *h) |
static char * | usb_get_string (struct usb_dev *d, int ndx) |
static struct class * | usb_get_class_by_id (int id) |
static void | usb_setup_dev_addr (struct usb_dev *dev) |
static void | usb_config_dev (struct usb_dev *dev, int config_val) |
static int | usb_load_config (struct usb_dev *dev, int idx, void *data, int dsz) |
static int | usb_tx_all (struct usb_endpoint *eop, void *buf, int max_bytes, int bailout, bool in) |
static void | usb_attach_interfaces (struct usb_dev *dev) |
static void | usb_apply_class_to_interfaces (struct class *c) |
static size_t | wchar_to_ascii (char *dst, const char *src) |
void | uhci_init (void) |
void | ehci_init (void) |
void | usb_init (void) |
void | usb_register_host (struct usb_host *uh, host_info info) |
int | usb_register_class (struct usb_class *uc) |
static int | send_status (struct host *h, host_eop_info cfg_eop) |
int | usb_dev_bulk (struct usb_endpoint *eop, void *buf, int sz, int *tx) |
int | usb_dev_setup (struct usb_endpoint *eop, bool in, struct usb_setup_pkt *s, void *buf, int sz) |
Variables | |
static struct list | usb_dev_list |
static struct list | class_list |
static struct list | host_list |
static struct lock | usb_sys_lock |
#define ADDR_DEFAULT 0 |
#define ADDRS_PER_HOST 127 |
#define MAX_USB_STR 128 |
#define SETUP_DESC_CONFIG 2 |
#define SETUP_DESC_DEVICE 1 |
sometimes used for ''value'
Definition at line 17 of file usb.c.
Referenced by usb_configure_default().
#define SETUP_DESC_IFACE 4 |
#define SETUP_DESC_STRING 3 |
#define usb_lock | ( | ) | lock_acquire(&usb_sys_lock) |
#define usb_unlock | ( | ) | lock_release(&usb_sys_lock) |
void ehci_init | ( | void | ) |
Definition at line 28 of file usb_ehci.c.
References EHCI_REG_CAPLENGTH, EHCI_REG_CONFIGFLAG, NULL, pci_get_dev_by_class(), pci_io_enum(), PCI_MAJOR_SERIALBUS, PCI_MINOR_USB, pci_reg_read8(), pci_reg_write32(), PCI_USB_IFACE_EHCI, and printf().
Referenced by usb_init().
static int send_status | ( | struct host * | h, | |
host_eop_info | cfg_eop | |||
) | [static] |
Definition at line 241 of file usb.c.
References host::dev, NULL, printf(), usb_host::set_toggle, usb_host::tx_pkt, and USB_TOKEN_OUT.
Referenced by usb_configure_default(), usb_get_string(), and usb_load_config().
void uhci_init | ( | void | ) |
Definition at line 279 of file usb_uhci.c.
References uhci_info::attached_ports, uhci_info::dev, uhci_info::frame_list, uhci_info::io, NULL, uhci_info::num_ports, pci_get_dev_by_class(), pci_io_enum(), pci_io_size(), PCI_MAJOR_SERIALBUS, PCI_MINOR_USB, pci_reg_read16(), pci_reg_write16(), pci_reg_write32(), pci_reg_write8(), pci_register_irq(), PCI_USB_IFACE_UHCI, pci_write_config16(), printf(), timer_usleep(), uhci_create_info(), uhci_detect_ports(), uhci_enable_port(), uhci_irq(), UHCI_REG_FLBASEADD, UHCI_REG_FRNUM, UHCI_REG_LEGSUP, UHCI_REG_PORTSC1, UHCI_REG_PORTSC2, UHCI_REG_SOFMOD, UHCI_REG_USBCMD, UHCI_REG_USBINTR, UHCI_REGSZ, USB_CMD_CONFIGURE, USB_CMD_HCRESET, USB_CMD_MAX_PACKET, USB_CMD_RS, USB_INTR_IOC, USB_INTR_RESUME, USB_INTR_SHORT, USB_INTR_TIMEOUT, usb_register_host(), and vtop().
Referenced by usb_init().
static void usb_apply_class_to_interfaces | ( | struct class * | c | ) | [static] |
Scan all interfaces for interfaces that match class's class id Attach interfaces that match
Definition at line 688 of file usb.c.
References usb_iface::c_info, usb_iface::class, usb_iface::class_id, usb_iface::class_peers, usb_dev::interfaces, list_begin(), list_end(), list_entry, list_next(), list_push_back(), NULL, usb_iface::peers, and usb_dev_list.
Referenced by usb_register_class().
static void usb_attach_interfaces | ( | struct usb_dev * | dev | ) | [static] |
Asssociate interfaces on a device with their respective device classes
Definition at line 654 of file usb.c.
References usb_class::attached, usb_iface::c_info, usb_iface::class, usb_iface::class_id, usb_iface::class_peers, class::dev, usb_dev::interfaces, list_begin(), list_end(), list_entry, list_next(), list_push_back(), NULL, usb_iface::peers, usb_get_class_by_id(), and class::usb_ifaces.
Referenced by usb_scan_devices().
static void usb_config_dev | ( | struct usb_dev * | dev, | |
int | config_val | |||
) | [static] |
Set USB device configuration to desired configuration value
Definition at line 521 of file usb.c.
References host::dev, usb_setup_pkt::direction, usb_dev::h_cfg_eop, usb_dev::host, usb_setup_pkt::index, usb_setup_pkt::length, NULL, PANIC, usb_setup_pkt::recipient, REQ_STD_SET_CONFIG, usb_setup_pkt::request, usb_host::tx_pkt, usb_setup_pkt::type, USB_HOST_ERR_NONE, USB_SETUP_RECIP_DEV, USB_SETUP_TYPE_STD, USB_TOKEN_IN, USB_TOKEN_SETUP, and usb_setup_pkt::value.
Referenced by usb_configure_default().
Definition at line 255 of file usb.c.
References ADDR_DEFAULT, usb_iface::c_info, usb_dev::cfg_eop, usb_iface::class, usb_iface::class_id, usb_host::create_dev_channel, usb_host::create_eop, usb_dev::default_iface, usb_iface::dev, host::dev, device_descriptor::dev_class, device_descriptor::dev_proto, device_descriptor::dev_subclass, device_descriptor::device_id, usb_dev::device_id, usb_setup_pkt::direction, usb_endpoint::eop, usb_dev::h_cfg_eop, usb_dev::h_dev, usb_endpoint::h_eop, usb_dev::host, usb_endpoint::iface, usb_iface::iface_num, usb_dev::ignore_device, usb_setup_pkt::index, host::info, usb_dev::interfaces, usb_setup_pkt::length, list_init(), malloc(), device_descriptor::manufacturer, usb_dev::manufacturer, usb_endpoint::max_pkt, device_descriptor::max_pktsz, memset(), NULL, device_descriptor::num_configs, printf(), device_descriptor::product, usb_dev::product, device_descriptor::product_id, usb_dev::product_id, usb_iface::proto, usb_setup_pkt::recipient, usb_host::remove_dev_channel, usb_host::remove_eop, REQ_STD_GET_DESC, usb_setup_pkt::request, send_status(), SETUP_DESC_DEVICE, usb_iface::subclass_id, usb_host::tx_pkt, usb_setup_pkt::type, usb_config_dev(), usb_get_string(), USB_HOST_ERR_NONE, usb_load_config(), usb_setup_dev_addr(), USB_SETUP_RECIP_DEV, USB_SETUP_TYPE_STD, device_descriptor::usb_spec, USB_TOKEN_IN, USB_TOKEN_SETUP, usb_dev::usb_version, USB_VERSION_1_0, USB_VERSION_1_1, usb_setup_pkt::value, device_descriptor::vendor_id, and usb_dev::vendor_id.
Referenced by usb_scan_devices().
int usb_dev_bulk | ( | struct usb_endpoint * | eop, | |
void * | buf, | |||
int | sz, | |||
int * | tx | |||
) |
Definition at line 724 of file usb.c.
References ASSERT, host::dev, usb_iface::dev, usb_endpoint::direction, usb_endpoint::h_eop, usb_dev::host, usb_endpoint::iface, NULL, usb_host::tx_pkt, USB_TOKEN_IN, and USB_TOKEN_OUT.
Referenced by msc_get_geometry(), and msc_io().
int usb_dev_setup | ( | struct usb_endpoint * | eop, | |
bool | in, | |||
struct usb_setup_pkt * | s, | |||
void * | buf, | |||
int | sz | |||
) |
Definition at line 744 of file usb.c.
References ASSERT, host::dev, usb_iface::dev, usb_endpoint::h_eop, usb_dev::host, usb_endpoint::iface, NULL, printf(), usb_host::tx_pkt, USB_HOST_ERR_NONE, USB_TOKEN_IN, USB_TOKEN_OUT, and USB_TOKEN_SETUP.
Referenced by msc_bulk_reset(), and msc_reset_endpoint().
static struct class * usb_get_class_by_id | ( | int | id | ) | [static, read] |
Definition at line 633 of file usb.c.
References usb_class::class_id, class_list, class::dev, list_begin(), list_end(), list_entry, list_next(), NULL, and class::peers.
Referenced by usb_attach_interfaces(), and usb_register_class().
static char * usb_get_string | ( | struct usb_dev * | d, | |
int | ndx | |||
) | [static] |
Definition at line 590 of file usb.c.
References usb_dev::cfg_eop, host::dev, usb_setup_pkt::direction, usb_dev::h_cfg_eop, usb_dev::host, usb_setup_pkt::index, usb_setup_pkt::length, malloc(), MAX_USB_STR, NULL, usb_setup_pkt::recipient, REQ_STD_GET_DESC, usb_setup_pkt::request, send_status(), SETUP_DESC_STRING, strlcpy(), strlen(), usb_host::tx_pkt, usb_setup_pkt::type, USB_HOST_ERR_NONE, USB_SETUP_RECIP_DEV, USB_SETUP_TYPE_STD, USB_TOKEN_SETUP, usb_tx_all(), usb_setup_pkt::value, and wchar_to_ascii().
Referenced by usb_configure_default().
void usb_init | ( | void | ) |
Definition at line 153 of file usb.c.
References class_list, ehci_init(), host_list, list_init(), lock_init(), printf(), uhci_init(), usb_dev_list, usb_hub_init(), and usb_sys_lock.
Referenced by main().
static int usb_load_config | ( | struct usb_dev * | dev, | |
int | idx, | |||
void * | data, | |||
int | dsz | |||
) | [static] |
Load in data for 'idx' configuration into device structure XXX support multiple configurations
Definition at line 407 of file usb.c.
References usb_iface::c_info, usb_dev::cfg_eop, usb_iface::class, usb_iface::class_id, config_descriptor::config_val, usb_host::create_eop, usb_iface::dev, host::dev, usb_setup_pkt::direction, usb_iface::endpoints, usb_dev::h_cfg_eop, usb_dev::h_dev, interface_descriptor::hdr, config_descriptor::hdr, hex_dump(), usb_dev::host, interface_descriptor::iface_class, interface_descriptor::iface_num, usb_iface::iface_num, interface_descriptor::iface_proto, interface_descriptor::iface_subclass, usb_setup_pkt::index, usb_dev::interfaces, usb_setup_pkt::length, list_init(), list_push_back(), malloc(), config_descriptor::max_power, NULL, interface_descriptor::num_endpoints, config_descriptor::num_ifaces, PANIC, usb_iface::peers, printf(), usb_iface::proto, usb_dev::pwr, usb_setup_pkt::recipient, REQ_STD_GET_DESC, usb_setup_pkt::request, send_status(), SETUP_DESC_CONFIG, SETUP_DESC_IFACE, usb_iface::subclass_id, config_descriptor::total_length, usb_host::tx_pkt, desc_header::type, usb_setup_pkt::type, USB_HOST_ERR_NONE, USB_SETUP_RECIP_DEV, USB_SETUP_TYPE_STD, USB_TOKEN_SETUP, usb_tx_all(), and usb_setup_pkt::value.
Referenced by usb_configure_default().
int usb_register_class | ( | struct usb_class * | uc | ) |
Definition at line 189 of file usb.c.
References usb_class::class_id, class_list, class::dev, list_init(), list_push_back(), malloc(), NULL, class::peers, usb_apply_class_to_interfaces(), usb_get_class_by_id(), class::usb_ifaces, usb_lock, and usb_unlock.
Referenced by usb_hub_init(), and usb_storage_init().
Definition at line 171 of file usb.c.
References ADDRS_PER_HOST, bitmap_create(), host::dev, host_list, host::host_usb_devs, host::info, list_init(), list_push_back(), malloc(), host::peers, host::usb_dev_addrs, usb_lock, usb_scan_devices(), and usb_unlock.
Referenced by uhci_init().
static void usb_scan_devices | ( | struct host * | h | ) | [static] |
Definition at line 217 of file usb.c.
References usb_dev::addr, usb_dev::host_peers, host::host_usb_devs, usb_dev::ignore_device, list_push_back(), usb_dev::manufacturer, NULL, printf(), usb_dev::product, usb_dev::sys_peers, usb_attach_interfaces(), usb_configure_default(), and usb_dev_list.
Referenced by usb_register_host().
static void usb_setup_dev_addr | ( | struct usb_dev * | dev | ) | [static] |
Set a device address to something other than the default pipe
Definition at line 551 of file usb.c.
References usb_dev::addr, ASSERT, bitmap_scan_and_flip(), host::dev, usb_setup_pkt::direction, usb_dev::h_cfg_eop, usb_dev::h_dev, usb_dev::host, usb_setup_pkt::index, usb_setup_pkt::length, usb_host::modify_dev_channel, NULL, PANIC, usb_setup_pkt::recipient, REQ_STD_SET_ADDRESS, usb_setup_pkt::request, usb_host::tx_pkt, usb_setup_pkt::type, host::usb_dev_addrs, USB_HOST_ERR_NONE, USB_SETUP_RECIP_DEV, USB_SETUP_TYPE_STD, USB_TOKEN_IN, USB_TOKEN_SETUP, usb_dev::usb_version, and usb_setup_pkt::value.
Referenced by usb_configure_default().
static int usb_tx_all | ( | struct usb_endpoint * | eop, | |
void * | buf, | |||
int | max_bytes, | |||
int | bailout, | |||
bool | in | |||
) | [static] |
Definition at line 785 of file usb.c.
References host::dev, usb_iface::dev, usb_endpoint::h_eop, usb_dev::host, usb_endpoint::iface, usb_host::tx_pkt, USB_HOST_ERR_NONE, USB_TOKEN_IN, and USB_TOKEN_OUT.
Referenced by usb_get_string(), and usb_load_config().
static size_t wchar_to_ascii | ( | char * | dst, | |
const char * | src | |||
) | [static] |
convert a wchar string to ascii in place
Definition at line 769 of file usb.c.
Referenced by usb_get_string().
struct list class_list [static] |
Definition at line 128 of file usb.c.
Referenced by usb_get_class_by_id(), usb_init(), and usb_register_class().
struct list usb_dev_list [static] |
Definition at line 127 of file usb.c.
Referenced by usb_apply_class_to_interfaces(), usb_init(), and usb_scan_devices().
struct lock usb_sys_lock [static] |