usb.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* USB core: device enumeration, descriptor parsing, hub recursion, bus
  2. scans and the hotplug watcher. Controller-specific work (transfers, root
  3. ports) goes through the usb_hcd_ops vtable (uhci.c / ohci.c / ehci.c /
  4. xhci.c). */
  5. #ifndef USB_H
  6. #define USB_H
  7. #include "usb_hcd.h"
  8. /* `lsusb` command: full scan, print the tree. */
  9. void usb_enumerate_and_print(void);
  10. /* Find + bring up every host controller; 0 when at least one is available. */
  11. int usb_hcd_init(void);
  12. const char *usb_hcd_name(void);
  13. /* Name of the controller type behind one global controller index. */
  14. const char *usb_hcd_name_ctrl(unsigned int ctrl);
  15. /* Full bus scan: resets every connected root port, re-enumerates and calls
  16. the probe for each interface (probe may be NULL to print instead).
  17. Returns 0, -1 (no controller) or -2 (a scan is already running); every
  18. completed scan bumps the generation counter. */
  19. int usb_scan(usb_probe_fn probe);
  20. /* Cheap periodic watcher: enumerates devices on root ports whose connect
  21. state changed since the last call (internally throttled). Returns the
  22. number of ports with a new device. */
  23. int usb_hotplug_poll(usb_probe_fn probe);
  24. /* Incremented by every scan; consumers re-init when it changes. */
  25. unsigned int usb_generation(void);
  26. /* Root-port query (used to watch the port the mouse hangs off). */
  27. int usb_port_connected(unsigned int ctrl, unsigned int port);
  28. /* Control request helpers. rt is the raw bmRequestType (standard 0x80/0x00,
  29. class 0xA0/0x20, other 0xA3/0x23); the rest is the raw setup fields. */
  30. int usb_control_in(unsigned int ctrl, unsigned int addr, unsigned int mps,
  31. int low_speed, unsigned char rt, unsigned char req,
  32. unsigned short value, unsigned short index,
  33. unsigned char *buf, unsigned int len);
  34. int usb_control_out(unsigned int ctrl, unsigned int addr, unsigned int mps,
  35. int low_speed, unsigned char rt, unsigned char req,
  36. unsigned short value, unsigned short index);
  37. int usb_control_out_data(unsigned int ctrl, unsigned int addr,
  38. unsigned int mps, int low_speed, unsigned char rt,
  39. unsigned char req, unsigned short value,
  40. unsigned short index, const unsigned char *buf,
  41. unsigned int len);
  42. /* Bulk transfers: bulk_in is start-or-poll (see usb_hcd.h). */
  43. int usb_bulk_out(unsigned int ctrl, unsigned int addr, unsigned int ep,
  44. unsigned int mps, const unsigned char *buf,
  45. unsigned int len);
  46. int usb_bulk_in(unsigned int ctrl, unsigned int addr, unsigned int ep,
  47. unsigned int mps, unsigned char *buf, unsigned int len);
  48. /* 1 when the controller behind `ctrl` implements both bulk directions.
  49. * UHCI/OHCI do not, so device drivers that need bulk must check this. */
  50. int usb_bulk_supported(unsigned int ctrl);
  51. /* Device-level probe for drivers that do not use HID interfaces (the
  52. * USB Ethernet and mass-storage drivers parse the whole configuration
  53. * themselves). Return 1 when the device was claimed. Several probes may
  54. * register; each is called (in registration order) for every non-hub
  55. * device during a scan, before the per-interface HID probe. */
  56. typedef int (*usb_device_probe_fn)(unsigned int ctrl, unsigned int addr,
  57. unsigned int mps, int low_speed,
  58. unsigned int port, unsigned int vendor,
  59. unsigned int product);
  60. void usb_register_device_probe(usb_device_probe_fn fn);
  61. /* Interrupt-IN endpoints (slots 0..USB_HCD_INT_SLOTS-1; usbhid assigns
  62. one per HID interface it claims). */
  63. int usb_int_in_start(unsigned int ctrl, unsigned int slot, unsigned int addr,
  64. unsigned int ep, unsigned int mps, int low_speed);
  65. int usb_int_in_poll(unsigned int slot, unsigned char *buf, unsigned int len);
  66. void usb_int_in_stop(unsigned int slot);
  67. #endif