usb_hcd.h 4.1 KB

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