usb_hcd.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* USB host controller driver (HCD) interface.
  2. *
  3. * usb.c drives enumeration, bus scans and the transfer consumers (USB mouse
  4. * + keyboard, USB Ethernet) through this vtable; uhci.c/ohci.c/ehci.c/xhci.c
  5. * each implement it for their controller type. One "controller instance" is
  6. * one PCI function (MCP79 exposes four OHCI ones, for example). A machine
  7. * with EHCI and UHCI/OHCI companions drives all of them: high-speed devices
  8. * enumerate on EHCI, the rest on the companions. */
  9. #ifndef USB_HCD_H
  10. #define USB_HCD_H
  11. #define USB_HCD_MAX_CTRL 4
  12. /* Interrupt-IN endpoints serviced concurrently; usbhid manages which
  13. slot carries which device (mice + keyboards, composite devices). */
  14. #define USB_HCD_INT_SLOTS 6
  15. /* One interface of one device, filled in during a scan and passed to the
  16. * scan probe. ep_addr is 0 when the interface has no interrupt-IN endpoint. */
  17. struct usb_iface_info {
  18. unsigned int ctrl; /* controller instance index */
  19. unsigned int addr; /* device address on that controller's bus */
  20. unsigned int mps; /* device EP0 max packet size */
  21. int low_speed;
  22. unsigned int port; /* root port the device hangs off (0xFF: behind a hub) */
  23. unsigned int vendor, product;
  24. unsigned int cls, subcls, proto; /* interface class/subclass/protocol */
  25. unsigned int iface_num;
  26. unsigned int config_value;
  27. unsigned int ep_addr; /* endpoint address byte (0x81 = EP1 IN) */
  28. unsigned int ep_mps;
  29. unsigned int ep_interval;
  30. };
  31. /* Called once per interface during a scan; return 1 when claimed. */
  32. typedef int (*usb_probe_fn)(const struct usb_iface_info *info);
  33. struct usb_hcd_ops {
  34. const char *name;
  35. /* Find + reset the controller(s). Returns the number of instances
  36. * found (0 = none). Idempotent: only brings hardware up on the
  37. * first successful call. */
  38. int (*init)(void);
  39. unsigned int (*count)(void);
  40. /* PCI location and register base of one instance (for the `lsusb`
  41. * header). *mmio is 1 for a memory-mapped register block. */
  42. void (*info)(unsigned int ctrl, unsigned int *bus, unsigned int *dev,
  43. unsigned int *func, unsigned int *base, int *mmio);
  44. /* Control transfer on endpoint 0. Returns bytes transferred
  45. * (>= 0) or -1. mps = EP0 max packet size (used to split the data
  46. * stage). dir_in: 1 = IN data stage, 0 = OUT or no data stage. */
  47. int (*control_transfer)(unsigned int ctrl, unsigned int addr,
  48. unsigned int mps, int low_speed,
  49. const unsigned char *setup, unsigned char *data,
  50. unsigned int len, int dir_in);
  51. /* Root hub ports of one instance. Port numbers are 0-based. */
  52. unsigned int (*port_count)(unsigned int ctrl);
  53. int (*port_connected)(unsigned int ctrl, unsigned int port);
  54. int (*port_low_speed)(unsigned int ctrl, unsigned int port);
  55. int (*port_reset)(unsigned int ctrl, unsigned int port);
  56. /* Returns 1 (and clears the hardware latch) when a connection change
  57. * was detected since the last call. */
  58. int (*port_take_change)(unsigned int ctrl, unsigned int port);
  59. /* Interrupt-IN endpoints (one slot per HID device; see
  60. * USB_HCD_INT_SLOTS). The transfer stays armed in the schedule;
  61. * the controller retries NAKs itself. poll: > 0 report bytes
  62. * (auto re-armed), 0 nothing yet, -1 error (still armed, toggle
  63. * preserved; the caller may count errors and re-init). */
  64. int (*int_in_start)(unsigned int ctrl, unsigned int slot,
  65. unsigned int addr, unsigned int ep,
  66. unsigned int mps, int low_speed);
  67. int (*int_in_poll)(unsigned int slot, unsigned char *buf,
  68. unsigned int len);
  69. void (*int_in_stop)(unsigned int slot);
  70. /* Bulk transfers (USB Ethernet / mass storage). bulk_in is
  71. * start-or-poll: the first call arms the transfer and returns 0;
  72. * later calls return the completed length, 0 while it is still in
  73. * progress, or -1. The transfer is armed with exactly that call's
  74. * length, so a device that ends an exact multiple of the max packet
  75. * size without a zero-length packet still completes; the next call
  76. * after a completion arms a new transfer with its own length. The
  77. * delivered chunk is copied into the caller's buffer before the
  78. * return. May be NULL. */
  79. int (*bulk_out)(unsigned int ctrl, unsigned int addr,
  80. unsigned int ep, unsigned int mps,
  81. const unsigned char *buf, unsigned int len);
  82. int (*bulk_in)(unsigned int ctrl, unsigned int addr,
  83. unsigned int ep, unsigned int mps,
  84. unsigned char *buf, unsigned int len);
  85. /* Abort a bulk transfer and reset the host-side endpoint state
  86. * (data toggle, armed qTD/ring), so the next bulk_in/out starts
  87. * clean after a timeout or a BOT reset. May be NULL. */
  88. void (*bulk_reset)(unsigned int ctrl, unsigned int addr,
  89. unsigned int ep, int dir_in);
  90. /* Optional: print raw root-port status during `lsusb` (print mode
  91. * only). Used by EHCI to show PORTSC while debugging routing. */
  92. void (*print_ports)(unsigned int ctrl);
  93. };
  94. extern const struct usb_hcd_ops usb_uhci_ops;
  95. extern const struct usb_hcd_ops usb_ohci_ops;
  96. extern const struct usb_hcd_ops usb_ehci_ops;
  97. extern const struct usb_hcd_ops usb_xhci_ops;
  98. #endif