usb.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /* Device-level probe for drivers that do not use HID interfaces (the
  49. * USB Ethernet driver parses the whole configuration itself). Return 1
  50. * when the device was claimed. Called for every non-hub device during a
  51. * scan, before the per-interface HID probe. */
  52. typedef int (*usb_device_probe_fn)(unsigned int ctrl, unsigned int addr,
  53. unsigned int mps, int low_speed,
  54. unsigned int port, unsigned int vendor,
  55. unsigned int product);
  56. void usb_register_device_probe(usb_device_probe_fn fn);
  57. /* Interrupt-IN endpoints (slots 0..USB_HCD_INT_SLOTS-1; usbhid assigns
  58. one per HID interface it claims). */
  59. int usb_int_in_start(unsigned int ctrl, unsigned int slot, unsigned int addr,
  60. unsigned int ep, unsigned int mps, int low_speed);
  61. int usb_int_in_poll(unsigned int slot, unsigned char *buf, unsigned int len);
  62. void usb_int_in_stop(unsigned int slot);
  63. #endif