You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usbio.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifndef _USBIO_H
  2. #define _USBIO_H
  3. /** @file
  4. *
  5. * EFI_USB_IO_PROTOCOL pseudo Host Controller Interface driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <ipxe/list.h>
  10. #include <ipxe/device.h>
  11. #include <ipxe/efi/efi.h>
  12. #include <ipxe/efi/Protocol/UsbIo.h>
  13. #include <ipxe/efi/Protocol/DevicePath.h>
  14. #include <ipxe/usb.h>
  15. /** USB I/O maximum transfer size
  16. *
  17. * The API provides no way to discover the maximum transfer size.
  18. * Assume the 16kB supported by EHCI.
  19. */
  20. #define USBIO_MTU 16384
  21. /** USB I/O interrupt ring buffer size
  22. *
  23. * This is a policy decision.
  24. */
  25. #define USBIO_INTR_COUNT 4
  26. /** A USB interrupt ring buffer */
  27. struct usbio_interrupt_ring {
  28. /** USB I/O endpoint */
  29. struct usbio_endpoint *endpoint;
  30. /** Producer counter */
  31. unsigned int prod;
  32. /** Consumer counter */
  33. unsigned int cons;
  34. /** Data buffers */
  35. void *data[USBIO_INTR_COUNT];
  36. /** Lengths */
  37. size_t len[USBIO_INTR_COUNT];
  38. };
  39. /** USB I/O ring buffer size
  40. *
  41. * This is a policy decision.
  42. */
  43. #define USBIO_RING_COUNT 64
  44. /** A USB I/O endpoint */
  45. struct usbio_endpoint {
  46. /** USB I/O device */
  47. struct usbio_device *usbio;
  48. /** USB endpoint */
  49. struct usb_endpoint *ep;
  50. /** List of endpoints */
  51. struct list_head list;
  52. /** USB I/O endpoint operations */
  53. struct usbio_operations *op;
  54. /** Containing interface number */
  55. unsigned int interface;
  56. /** EFI handle */
  57. EFI_HANDLE handle;
  58. /** USB I/O protocol */
  59. EFI_USB_IO_PROTOCOL *io;
  60. /** Producer counter */
  61. unsigned int prod;
  62. /** Consumer counter */
  63. unsigned int cons;
  64. /** I/O buffers */
  65. struct io_buffer *iobuf[USBIO_RING_COUNT];
  66. /** Flags */
  67. uint8_t flags[USBIO_RING_COUNT];
  68. /** Interrupt ring buffer (if applicable) */
  69. struct usbio_interrupt_ring *intr;
  70. };
  71. /** USB I/O transfer flags */
  72. enum usbio_flags {
  73. /** This is a message transfer */
  74. USBIO_MESSAGE = 0x01,
  75. /** This transfer requires zero-length packet termination */
  76. USBIO_ZLEN = 0x02,
  77. };
  78. /** USB I/O endpoint operations */
  79. struct usbio_operations {
  80. /** Open endpoint
  81. *
  82. * @v endpoint Endpoint
  83. * @ret rc Return status code
  84. */
  85. int ( * open ) ( struct usbio_endpoint *endpoint );
  86. /** Close endpoint
  87. *
  88. * @v endpoint Endpoint
  89. */
  90. void ( * close ) ( struct usbio_endpoint *endpoint );
  91. /** Poll endpoint
  92. *
  93. * @v endpoint Endpoint
  94. */
  95. void ( * poll ) ( struct usbio_endpoint *endpoint );
  96. };
  97. /** A USB I/O protocol interface */
  98. struct usbio_interface {
  99. /** EFI device handle */
  100. EFI_HANDLE handle;
  101. /** USB I/O protocol */
  102. EFI_USB_IO_PROTOCOL *io;
  103. /** Usage count */
  104. unsigned int count;
  105. };
  106. /** A USB I/O protocol device
  107. *
  108. * We model each externally-provided USB I/O protocol device as a host
  109. * controller containing a root hub with a single port.
  110. */
  111. struct usbio_device {
  112. /** EFI device handle */
  113. EFI_HANDLE handle;
  114. /** USB I/O protocol */
  115. EFI_USB_IO_PROTOCOL *io;
  116. /** Generic device */
  117. struct device dev;
  118. /** Configuration descriptor */
  119. struct usb_configuration_descriptor *config;
  120. /** Device path */
  121. EFI_DEVICE_PATH_PROTOCOL *path;
  122. /** Final component of USB device path */
  123. USB_DEVICE_PATH *usbpath;
  124. /** First interface number */
  125. uint8_t first;
  126. /** USB I/O protocol interfaces */
  127. struct usbio_interface *interface;
  128. /** USB bus */
  129. struct usb_bus *bus;
  130. /** List of endpoints */
  131. struct list_head endpoints;
  132. };
  133. #endif /* _USBIO_H */