iPXE
usbio.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdlib.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <assert.h>
30 #include <ipxe/efi/efi.h>
31 #include <ipxe/efi/efi_driver.h>
32 #include <ipxe/efi/efi_utils.h>
34 #include <ipxe/usb.h>
35 #include "usbio.h"
36 
37 /** @file
38  *
39  * EFI_USB_IO_PROTOCOL pseudo Host Controller Interface driver
40  *
41  *
42  * The EFI_USB_IO_PROTOCOL is an almost unbelievably poorly designed
43  * abstraction of a USB device. It would be just about forgivable for
44  * an API to support only synchronous operation for bulk OUT
45  * endpoints. It is imbecilic to support only synchronous operation
46  * for bulk IN endpoints. This apparently intern-designed API
47  * throttles a typical NIC down to 1.5% of its maximum throughput.
48  * That isn't a typo. It really is that slow.
49  *
50  * We can't even work around this stupidity by talking to the host
51  * controller abstraction directly, because an identical limitation
52  * exists in the EFI_USB2_HC_PROTOCOL.
53  *
54  * Unless you derive therapeutic value from watching download progress
55  * indicators lethargically creep through every single integer from 0
56  * to 100, you should use iPXE's native USB host controller drivers
57  * instead. (Or just upgrade from UEFI to "legacy" BIOS, which will
58  * produce a similar speed increase.)
59  *
60  *
61  * For added excitement, the EFI_USB_IO_PROTOCOL makes the
62  * (demonstrably incorrect) assumption that a USB driver needs to
63  * attach to exactly one interface within a USB device, and provides a
64  * helper method to retrieve "the" interface descriptor. Since pretty
65  * much every USB network device requires binding to a pair of
66  * control+data interfaces, this aspect of EFI_USB_IO_PROTOCOL is of
67  * no use to us.
68  *
69  * We have our own existing code for reading USB descriptors, so we
70  * don't actually care that the UsbGetInterfaceDescriptor() method
71  * provided by EFI_USB_IO_PROTOCOL is useless for network devices. We
72  * can read the descriptors ourselves (via UsbControlTransfer()) and
73  * get all of the information we need this way. We can even work
74  * around the fact that EFI_USB_IO_PROTOCOL provides separate handles
75  * for each of the two interfaces comprising our network device.
76  *
77  * However, if we discover that we need to select an alternative
78  * device configuration (e.g. for devices exposing both RNDIS and
79  * ECM), then all hell breaks loose. EFI_USB_IO_PROTOCOL starts to
80  * panic because its cached interface and endpoint descriptors will no
81  * longer be valid. As mentioned above, the cached descriptors are
82  * useless for network devices anyway so we _really_ don't care about
83  * this, but EFI_USB_IO_PROTOCOL certainly cares. It prints out a
84  * manic warning message containing no fewer than six exclamation
85  * marks and then literally commits seppuku in the middle of the
86  * UsbControlTransfer() method by attempting to uninstall itself.
87  * Quite how the caller is supposed to react when asked to stop using
88  * the EFI_USB_IO_PROTOCOL instance while in the middle of an
89  * uninterruptible call to said instance is left as an exercise for
90  * the interested reader.
91  *
92  * There is no sensible way to work around this, so we just
93  * preemptively fail if asked to change the device configuration, on
94  * the basis that reporting a sarcastic error message is often
95  * preferable to jumping through a NULL pointer and crashing the
96  * system.
97  */
98 
99 /* Disambiguate the various error causes */
100 #define ENOTSUP_MORONIC_SPECIFICATION \
101  __einfo_error ( EINFO_ENOTSUP_MORONIC_SPECIFICATION )
102 #define EINFO_ENOTSUP_MORONIC_SPECIFICATION \
103  __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \
104  "EFI_USB_IO_PROTOCOL was designed by morons" )
105 
106 /******************************************************************************
107  *
108  * Device model
109  *
110  ******************************************************************************
111  */
112 
113 /**
114  * Determine endpoint interface number
115  *
116  * @v usbio USB I/O device
117  * @v ep USB Endpoint
118  * @ret interface Interface number, or negative error
119  */
120 static int usbio_interface ( struct usbio_device *usbio,
121  struct usb_endpoint *ep ) {
122  EFI_HANDLE handle = usbio->handle;
123  struct usb_device *usb = ep->usb;
127  struct usb_function *func;
128  unsigned int i;
129 
130  /* The control endpoint is not part of a described interface */
131  if ( ep->address == USB_EP0_ADDRESS )
132  return 0;
133 
134  /* Iterate over all interface descriptors looking for a match */
135  config = usbio->config;
137 
138  /* Skip non-interface descriptors */
139  if ( interface->header.type != USB_INTERFACE_DESCRIPTOR )
140  continue;
141 
142  /* Iterate over all endpoint descriptors looking for a match */
143  for_each_interface_descriptor ( endpoint, config, interface ) {
144 
145  /* Skip non-endpoint descriptors */
146  if ( endpoint->header.type != USB_ENDPOINT_DESCRIPTOR )
147  continue;
148 
149  /* Check endpoint address */
150  if ( endpoint->endpoint != ep->address )
151  continue;
152 
153  /* Check interface belongs to this function */
154  list_for_each_entry ( func, &usb->functions, list ) {
155 
156  /* Skip non-matching functions */
157  if ( func->interface[0] != usbio->first )
158  continue;
159 
160  /* Iterate over all interfaces for a match */
161  for ( i = 0 ; i < func->desc.count ; i++ ) {
162  if ( interface->interface ==
163  func->interface[i] )
164  return interface->interface;
165  }
166  }
167  }
168  }
169 
170  DBGC ( usbio, "USBIO %s cannot find interface for %s",
172  return -ENOENT;
173 }
174 
175 /**
176  * Open USB I/O interface
177  *
178  * @v usbio USB I/O device
179  * @v interface Interface number
180  * @ret rc Return status code
181  */
182 static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) {
184  EFI_HANDLE handle = usbio->handle;
185  struct usbio_interface *intf = &usbio->interface[interface];
188  USB_DEVICE_PATH *usbpath;
189  union {
190  void *interface;
192  } u;
193  EFI_STATUS efirc;
194  int rc;
195 
196  /* Sanity check */
197  assert ( interface < usbio->config->interfaces );
198 
199  /* If interface is already open, just increment the usage count */
200  if ( intf->count ) {
201  intf->count++;
202  return 0;
203  }
204 
205  /* Construct device path for this interface */
206  path = usbio->path;
207  usbpath = usbio->usbpath;
208  usbpath->InterfaceNumber = interface;
209  end = efi_devpath_end ( path );
210 
211  /* Locate handle for this endpoint's interface */
212  if ( ( efirc = bs->LocateDevicePath ( &efi_usb_io_protocol_guid, &path,
213  &intf->handle ) ) != 0 ) {
214  rc = -EEFI ( efirc );
215  DBGC ( usbio, "USBIO %s could not locate ",
216  efi_handle_name ( handle ) );
217  DBGC ( usbio, "%s: %s\n",
218  efi_devpath_text ( usbio->path ), strerror ( rc ) );
219  return rc;
220  }
221 
222  /* Check that expected path was located */
223  if ( path != end ) {
224  DBGC ( usbio, "USBIO %s located incomplete ",
225  efi_handle_name ( handle ) );
226  DBGC ( usbio, "%s\n", efi_handle_name ( intf->handle ) );
227  return -EXDEV;
228  }
229 
230  /* Open USB I/O protocol on this handle */
231  if ( ( efirc = bs->OpenProtocol ( intf->handle,
233  &u.interface, efi_image_handle,
234  intf->handle,
237  rc = -EEFI ( efirc );
238  DBGC ( usbio, "USBIO %s cannot open ",
239  efi_handle_name ( handle ) );
240  DBGC ( usbio, "%s: %s\n",
241  efi_handle_name ( intf->handle ), strerror ( rc ) );
242  DBGC_EFI_OPENERS ( usbio, intf->handle,
244  return rc;
245  }
246  intf->io = u.io;
247 
248  /* Increment usage count */
249  intf->count++;
250 
251  return 0;
252 }
253 
254 /**
255  * Close USB I/O interface
256  *
257  * @v usbio USB I/O device
258  * @v interface Interface number
259  */
260 static void usbio_close ( struct usbio_device *usbio, unsigned int interface ) {
262  struct usbio_interface *intf = &usbio->interface[interface];
263 
264  /* Sanity checks */
265  assert ( interface < usbio->config->interfaces );
266  assert ( intf->count > 0 );
267 
268  /* Decrement usage count */
269  intf->count--;
270 
271  /* Do nothing if interface is still in use */
272  if ( intf->count )
273  return;
274 
275  /* Close USB I/O protocol */
277  efi_image_handle, intf->handle );
278 }
279 
280 /******************************************************************************
281  *
282  * Control endpoints
283  *
284  ******************************************************************************
285  */
286 
287 /**
288  * Open control endpoint
289  *
290  * @v endpoint Endpoint
291  * @ret rc Return status code
292  */
293 static int usbio_control_open ( struct usbio_endpoint *endpoint __unused ) {
294 
295  /* Nothing to do */
296  return 0;
297 }
298 
299 /**
300  * Close control endpoint
301  *
302  * @v endpoint Endpoint
303  */
304 static void usbio_control_close ( struct usbio_endpoint *endpoint __unused ) {
305 
306  /* Nothing to do */
307 }
308 
309 /**
310  * Poll control endpoint
311  *
312  * @v endpoint Endpoint
313  */
314 static void usbio_control_poll ( struct usbio_endpoint *endpoint ) {
315  struct usbio_device *usbio = endpoint->usbio;
316  struct usb_endpoint *ep = endpoint->ep;
317  EFI_HANDLE handle = usbio->handle;
319  union {
320  struct usb_setup_packet setup;
322  } *msg;
324  struct io_buffer *iobuf;
325  unsigned int index;
326  unsigned int flags;
327  unsigned int recipient;
328  unsigned int interface;
330  void *data;
331  size_t len;
332  UINT32 status;
333  EFI_STATUS efirc;
334  int rc;
335 
336  /* Do nothing if ring is empty */
337  if ( endpoint->cons == endpoint->prod )
338  return;
339 
340  /* Consume next transfer */
341  index = ( endpoint->cons++ % USBIO_RING_COUNT );
342  iobuf = endpoint->iobuf[index];
343  flags = endpoint->flags[index];
344 
345  /* Sanity check */
346  if ( ! ( flags & USBIO_MESSAGE ) ) {
347  DBGC ( usbio, "USBIO %s %s non-message transfer\n",
349  rc = -ENOTSUP;
350  goto err_not_message;
351  }
352 
353  /* Construct transfer */
354  msg = iob_push ( iobuf, sizeof ( *msg ) );
355  iob_pull ( iobuf, sizeof ( *msg ) );
356  request = le16_to_cpu ( msg->setup.request );
357  len = iob_len ( iobuf );
358  if ( len ) {
359  data = iobuf->data;
360  direction = ( ( request & USB_DIR_IN ) ?
362  } else {
363  data = NULL;
365  }
366 
367  /* Determine interface for this transfer */
368  recipient = ( request & USB_RECIP_MASK );
369  if ( recipient == USB_RECIP_INTERFACE ) {
370  /* Recipient is an interface: use interface number directly */
371  interface = le16_to_cpu ( msg->setup.index );
372  } else {
373  /* Route all other requests through the first interface */
374  interface = 0;
375  }
376 
377  /* Open interface */
378  if ( ( rc = usbio_open ( usbio, interface ) ) != 0 )
379  goto err_open;
380  io = usbio->interface[interface].io;
381 
382  /* Due to the design of EFI_USB_IO_PROTOCOL, attempting to set
383  * the configuration to a non-default value is basically a
384  * self-destruct button.
385  */
386  if ( ( request == USB_SET_CONFIGURATION ) &&
387  ( le16_to_cpu ( msg->setup.value ) != usbio->config->config ) ) {
389  DBGC ( usbio, "USBIO %s cannot change configuration: %s\n",
390  efi_handle_name ( handle ), strerror ( rc ) );
391  goto err_moronic_specification;
392  }
393 
394  /* Submit transfer */
395  if ( ( efirc = io->UsbControlTransfer ( io, &msg->efi, direction, 0,
396  data, len, &status ) ) != 0 ) {
397  rc = -EEFI ( efirc );
398  DBGC ( usbio, "USBIO %s %s could not submit control transfer ",
400  DBGC ( usbio, "via %s: %s (status %04x)\n",
402  strerror ( rc ), status );
403  goto err_transfer;
404  }
405 
406  /* Close interface */
407  usbio_close ( usbio, interface );
408 
409  /* Complete transfer */
410  usb_complete ( ep, iobuf );
411 
412  return;
413 
414  err_transfer:
415  err_moronic_specification:
416  usbio_close ( usbio, interface );
417  err_open:
418  err_not_message:
419  usb_complete_err ( ep, iobuf, rc );
420 }
421 
422 /** Control endpoint operations */
425  .close = usbio_control_close,
426  .poll = usbio_control_poll,
427 };
428 
429 /******************************************************************************
430  *
431  * Bulk IN endpoints
432  *
433  ******************************************************************************
434  */
435 
436 /**
437  * Open bulk IN endpoint
438  *
439  * @v endpoint Endpoint
440  * @ret rc Return status code
441  */
442 static int usbio_bulk_in_open ( struct usbio_endpoint *endpoint __unused ) {
443 
444  /* Nothing to do */
445  return 0;
446 }
447 
448 /**
449  * Close bulk IN endpoint
450  *
451  * @v endpoint Endpoint
452  */
453 static void usbio_bulk_in_close ( struct usbio_endpoint *endpoint __unused ) {
454 
455  /* Nothing to do */
456 }
457 
458 /**
459  * Poll bulk IN endpoint
460  *
461  * @v endpoint Endpoint
462  */
463 static void usbio_bulk_in_poll ( struct usbio_endpoint *endpoint ) {
464  struct usbio_device *usbio = endpoint->usbio;
465  struct usb_endpoint *ep = endpoint->ep;
466  EFI_USB_IO_PROTOCOL *io = endpoint->io;
467  EFI_HANDLE handle = usbio->handle;
468  struct io_buffer *iobuf;
469  unsigned int index;
470  UINTN len;
471  UINT32 status;
472  EFI_STATUS efirc;
473  int rc;
474 
475  /* Do nothing if ring is empty */
476  if ( endpoint->cons == endpoint->prod )
477  return;
478 
479  /* Attempt (but do not yet consume) next transfer */
480  index = ( endpoint->cons % USBIO_RING_COUNT );
481  iobuf = endpoint->iobuf[index];
482 
483  /* Construct transfer */
484  len = iob_len ( iobuf );
485 
486  /* Upon being turned on, the EFI_USB_IO_PROTOCOL did nothing
487  * for several minutes before firing a small ARP packet a few
488  * millimetres into the ether.
489  */
490  efirc = io->UsbBulkTransfer ( io, ep->address, iobuf->data,
491  &len, 1, &status );
492  if ( efirc == EFI_TIMEOUT )
493  return;
494 
495  /* Consume transfer */
496  endpoint->cons++;
497 
498  /* Check for failure */
499  if ( efirc != 0 ) {
500  rc = -EEFI ( efirc );
501  DBGC2 ( usbio, "USBIO %s %s could not submit bulk IN transfer: "
502  "%s (status %04x)\n", efi_handle_name ( handle ),
503  usb_endpoint_name ( ep ), strerror ( rc ), status );
504  usb_complete_err ( ep, iobuf, rc );
505  return;
506  }
507 
508  /* Update length */
509  iob_put ( iobuf, ( len - iob_len ( iobuf ) ) );
510 
511  /* Complete transfer */
512  usb_complete ( ep, iobuf );
513 }
514 
515 /** Bulk endpoint operations */
518  .close = usbio_bulk_in_close,
519  .poll = usbio_bulk_in_poll,
520 };
521 
522 /******************************************************************************
523  *
524  * Bulk OUT endpoints
525  *
526  ******************************************************************************
527  */
528 
529 /**
530  * Open bulk OUT endpoint
531  *
532  * @v endpoint Endpoint
533  * @ret rc Return status code
534  */
535 static int usbio_bulk_out_open ( struct usbio_endpoint *endpoint __unused ) {
536 
537  /* Nothing to do */
538  return 0;
539 }
540 
541 /**
542  * Close bulk OUT endpoint
543  *
544  * @v endpoint Endpoint
545  */
546 static void usbio_bulk_out_close ( struct usbio_endpoint *endpoint __unused ) {
547 
548  /* Nothing to do */
549 }
550 
551 /**
552  * Poll bulk OUT endpoint
553  *
554  * @v endpoint Endpoint
555  */
556 static void usbio_bulk_out_poll ( struct usbio_endpoint *endpoint ) {
557  struct usbio_device *usbio = endpoint->usbio;
558  struct usb_endpoint *ep = endpoint->ep;
559  EFI_USB_IO_PROTOCOL *io = endpoint->io;
560  EFI_HANDLE handle = usbio->handle;
561  struct io_buffer *iobuf;
562  unsigned int index;
563  unsigned int flags;
564  UINTN len;
565  UINT32 status;
566  EFI_STATUS efirc;
567  int rc;
568 
569  /* Do nothing if ring is empty */
570  if ( endpoint->cons == endpoint->prod )
571  return;
572 
573  /* Consume next transfer */
574  index = ( endpoint->cons++ % USBIO_RING_COUNT );
575  iobuf = endpoint->iobuf[index];
576  flags = endpoint->flags[index];
577 
578  /* Construct transfer */
579  len = iob_len ( iobuf );
580 
581  /* Submit transfer */
582  if ( ( efirc = io->UsbBulkTransfer ( io, ep->address, iobuf->data,
583  &len, 0, &status ) ) != 0 ) {
584  rc = -EEFI ( efirc );
585  DBGC ( usbio, "USBIO %s %s could not submit bulk OUT transfer: "
586  "%s (status %04x)\n", efi_handle_name ( handle ),
587  usb_endpoint_name ( ep ), strerror ( rc ), status );
588  goto err;
589  }
590 
591  /* Update length */
592  iob_put ( iobuf, ( len - iob_len ( iobuf ) ) );
593 
594  /* Submit zero-length transfer if required */
595  len = 0;
596  if ( ( flags & USBIO_ZLEN ) &&
597  ( efirc = io->UsbBulkTransfer ( io, ep->address, NULL, &len, 0,
598  &status ) ) != 0 ) {
599  rc = -EEFI ( efirc );
600  DBGC ( usbio, "USBIO %s %s could not submit zero-length "
601  "transfer: %s (status %04x)\n",
603  strerror ( rc ), status );
604  goto err;
605  }
606 
607  /* Complete transfer */
608  usb_complete ( ep, iobuf );
609 
610  return;
611 
612  err:
613  usb_complete_err ( ep, iobuf, rc );
614 }
615 
616 /** Bulk endpoint operations */
619  .close = usbio_bulk_out_close,
620  .poll = usbio_bulk_out_poll,
621 };
622 
623 /******************************************************************************
624  *
625  * Interrupt endpoints
626  *
627  ******************************************************************************
628  *
629  * The EFI_USB_IO_PROTOCOL provides two ways to interact with
630  * interrupt endpoints, neither of which naturally model the hardware
631  * interaction. The UsbSyncInterruptTransfer() method allows imposes
632  * a 1ms overhead for every interrupt transfer (which could result in
633  * up to a 50% decrease in overall throughput for the device). The
634  * UsbAsyncInterruptTransfer() method provides no way for us to
635  * prevent transfers when no I/O buffers are available.
636  *
637  * We work around this design by utilising a small, fixed ring buffer
638  * into which the interrupt callback delivers the data. This aims to
639  * provide buffer space even if no I/O buffers have yet been enqueued.
640  * The scheme is not guaranteed since the fixed ring buffer may also
641  * become full. However:
642  *
643  * - devices which send a constant stream of interrupts (and which
644  * therefore might exhaust the fixed ring buffer) tend to be
645  * responding to every interrupt request, and can tolerate lost
646  * packets, and
647  *
648  * - devices which cannot tolerate lost interrupt packets tend to send
649  * only a few small messages.
650  *
651  * The scheme should therefore work in practice.
652  */
653 
654 /**
655  * Interrupt endpoint callback
656  *
657  * @v data Received data
658  * @v len Length of received data
659  * @v context Callback context
660  * @v status Transfer status
661  * @ret efirc EFI status code
662  */
664  VOID *context,
665  UINT32 status ) {
666  struct usbio_interrupt_ring *intr = context;
667  struct usbio_endpoint *endpoint = intr->endpoint;
668  struct usbio_device *usbio = endpoint->usbio;
669  struct usb_endpoint *ep = endpoint->ep;
670  EFI_HANDLE handle = usbio->handle;
671  unsigned int fill;
672  unsigned int index;
673 
674  /* Sanity check */
675  assert ( len <= ep->mtu );
676 
677  /* Do nothing if ring is empty */
678  fill = ( intr->prod - intr->cons );
679  if ( fill >= USBIO_INTR_COUNT ) {
680  DBGC ( usbio, "USBIO %s %s dropped interrupt completion\n",
682  return 0;
683  }
684 
685  /* Do nothing if transfer was unsuccessful */
686  if ( status != 0 ) {
687  DBGC ( usbio, "USBIO %s %s interrupt completion status %04x\n",
689  status );
690  return 0; /* Unclear what failure actually means here */
691  }
692 
693  /* Copy data to buffer and increment producer counter */
694  index = ( intr->prod % USBIO_INTR_COUNT );
695  memcpy ( intr->data[index], data, len );
696  intr->len[index] = len;
697  intr->prod++;
698 
699  return 0;
700 }
701 
702 /**
703  * Open interrupt endpoint
704  *
705  * @v endpoint Endpoint
706  * @ret rc Return status code
707  */
708 static int usbio_interrupt_open ( struct usbio_endpoint *endpoint ) {
709  struct usbio_device *usbio = endpoint->usbio;
710  struct usbio_interrupt_ring *intr;
711  struct usb_endpoint *ep = endpoint->ep;
712  EFI_USB_IO_PROTOCOL *io = endpoint->io;
713  EFI_HANDLE handle = usbio->handle;
714  unsigned int interval;
715  unsigned int i;
716  void *data;
717  EFI_STATUS efirc;
718  int rc;
719 
720  /* Allocate interrupt ring buffer */
721  intr = zalloc ( sizeof ( *intr ) + ( USBIO_INTR_COUNT * ep->mtu ) );
722  if ( ! intr ) {
723  rc = -ENOMEM;
724  goto err_alloc;
725  }
726  endpoint->intr = intr;
727  intr->endpoint = endpoint;
728  data = ( ( ( void * ) intr ) + sizeof ( *intr ) );
729  for ( i = 0 ; i < USBIO_INTR_COUNT ; i++ ) {
730  intr->data[i] = data;
731  data += ep->mtu;
732  }
733 
734  /* Determine polling interval */
735  interval = ( ep->interval >> 3 /* microframes -> milliseconds */ );
736  if ( ! interval )
737  interval = 1; /* May not be zero */
738 
739  /* Add to periodic schedule */
740  if ( ( efirc = io->UsbAsyncInterruptTransfer ( io, ep->address, TRUE,
741  interval, ep->mtu,
743  intr ) ) != 0 ) {
744  rc = -EEFI ( efirc );
745  DBGC ( usbio, "USBIO %s %s could not schedule interrupt "
746  "transfer: %s\n", efi_handle_name ( handle ),
747  usb_endpoint_name ( ep ), strerror ( rc ) );
748  goto err_schedule;
749  }
750 
751  return 0;
752 
753  io->UsbAsyncInterruptTransfer ( io, ep->address, FALSE, 0, 0,
754  NULL, NULL );
755  err_schedule:
756  free ( intr );
757  err_alloc:
758  return rc;
759 }
760 
761 /**
762  * Close interrupt endpoint
763  *
764  * @v endpoint Endpoint
765  */
766 static void usbio_interrupt_close ( struct usbio_endpoint *endpoint ) {
767  struct usb_endpoint *ep = endpoint->ep;
768  EFI_USB_IO_PROTOCOL *io = endpoint->io;
769 
770  /* Remove from periodic schedule */
771  io->UsbAsyncInterruptTransfer ( io, ep->address, FALSE, 0, 0,
772  NULL, NULL );
773 
774  /* Free interrupt ring buffer */
775  free ( endpoint->intr );
776 }
777 
778 /**
779  * Poll interrupt endpoint
780  *
781  * @v endpoint Endpoint
782  */
783 static void usbio_interrupt_poll ( struct usbio_endpoint *endpoint ) {
785  struct usb_endpoint *ep = endpoint->ep;
786  struct io_buffer *iobuf;
787  unsigned int index;
788  unsigned int intr_index;
789  size_t len;
790 
791  /* Do nothing if ring is empty */
792  if ( endpoint->cons == endpoint->prod )
793  return;
794 
795  /* Do nothing if interrupt ring is empty */
796  if ( intr->cons == intr->prod )
797  return;
798 
799  /* Consume next transfer */
800  index = ( endpoint->cons++ % USBIO_RING_COUNT );
801  iobuf = endpoint->iobuf[index];
802 
803  /* Populate I/O buffer */
804  intr_index = ( intr->cons++ % USBIO_INTR_COUNT );
805  len = intr->len[intr_index];
806  assert ( len <= iob_len ( iobuf ) );
807  iob_put ( iobuf, ( len - iob_len ( iobuf ) ) );
808  memcpy ( iobuf->data, intr->data[intr_index], len );
809 
810  /* Complete transfer */
811  usb_complete ( ep, iobuf );
812 }
813 
814 /** Interrupt endpoint operations */
817  .close = usbio_interrupt_close,
818  .poll = usbio_interrupt_poll,
819 };
820 
821 /******************************************************************************
822  *
823  * Endpoint operations
824  *
825  ******************************************************************************
826  */
827 
828 /**
829  * Open endpoint
830  *
831  * @v ep USB endpoint
832  * @ret rc Return status code
833  */
834 static int usbio_endpoint_open ( struct usb_endpoint *ep ) {
835  struct usb_bus *bus = ep->usb->port->hub->bus;
836  struct usbio_device *usbio = usb_bus_get_hostdata ( bus );
837  struct usbio_endpoint *endpoint;
839  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
840  int interface;
841  int rc;
842 
843  /* Allocate and initialise structure */
844  endpoint = zalloc ( sizeof ( *endpoint ) );
845  if ( ! endpoint ) {
846  rc = -ENOMEM;
847  goto err_alloc;
848  }
849  usb_endpoint_set_hostdata ( ep, endpoint );
850  endpoint->usbio = usbio;
851  endpoint->ep = ep;
852 
853  /* Identify endpoint operations */
854  if ( attr == USB_ENDPOINT_ATTR_CONTROL ) {
855  endpoint->op = &usbio_control_operations;
856  } else if ( attr == USB_ENDPOINT_ATTR_BULK ) {
857  endpoint->op = ( ( ep->address & USB_DIR_IN ) ?
860  } else if ( attr == USB_ENDPOINT_ATTR_INTERRUPT ) {
861  endpoint->op = &usbio_interrupt_operations;
862  } else {
863  rc = -ENOTSUP;
864  goto err_operations;
865  }
866 
867  /* Identify interface for this endpoint */
868  interface = usbio_interface ( usbio, ep );
869  if ( interface < 0 ) {
870  rc = interface;
871  goto err_interface;
872  }
873  endpoint->interface = interface;
874 
875  /* Open interface */
876  if ( ( rc = usbio_open ( usbio, interface ) ) != 0 )
877  goto err_open_interface;
878  endpoint->handle = usbio->interface[interface].handle;
879  endpoint->io = usbio->interface[interface].io;
880  DBGC ( usbio, "USBIO %s %s using ",
882  DBGC ( usbio, "%s\n", efi_handle_name ( endpoint->handle ) );
883 
884  /* Open endpoint */
885  if ( ( rc = endpoint->op->open ( endpoint ) ) != 0 )
886  goto err_open_endpoint;
887 
888  /* Add to list of endpoints */
889  list_add_tail ( &endpoint->list, &usbio->endpoints );
890 
891  return 0;
892 
893  list_del ( &endpoint->list );
894  endpoint->op->close ( endpoint );
895  err_open_endpoint:
896  usbio_close ( usbio, interface );
897  err_open_interface:
898  err_interface:
899  err_operations:
900  free ( endpoint );
901  err_alloc:
902  return rc;
903 }
904 
905 /**
906  * Close endpoint
907  *
908  * @v ep USB endpoint
909  */
910 static void usbio_endpoint_close ( struct usb_endpoint *ep ) {
911  struct usbio_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
912  struct usbio_device *usbio = endpoint->usbio;
913  struct io_buffer *iobuf;
914  unsigned int index;
915 
916  /* Remove from list of endpoints */
917  list_del ( &endpoint->list );
918 
919  /* Close endpoint */
920  endpoint->op->close ( endpoint );
921 
922  /* Close interface */
923  usbio_close ( usbio, endpoint->interface );
924 
925  /* Cancel any incomplete transfers */
926  while ( endpoint->cons != endpoint->prod ) {
927  index = ( endpoint->cons++ % USBIO_RING_COUNT );
928  iobuf = endpoint->iobuf[index];
929  usb_complete_err ( ep, iobuf, -ECANCELED );
930  }
931 
932  /* Free endpoint */
933  free ( endpoint );
934 }
935 
936 /**
937  * Reset endpoint
938  *
939  * @v ep USB endpoint
940  * @ret rc Return status code
941  */
942 static int usbio_endpoint_reset ( struct usb_endpoint *ep __unused ) {
943 
944  /* Nothing to do */
945  return 0;
946 }
947 
948 /**
949  * Update MTU
950  *
951  * @v ep USB endpoint
952  * @ret rc Return status code
953  */
954 static int usbio_endpoint_mtu ( struct usb_endpoint *ep __unused ) {
955 
956  /* Nothing to do */
957  return 0;
958 }
959 
960 /**
961  * Enqueue transfer
962  *
963  * @v ep USB endpoint
964  * @v iobuf I/O buffer
965  * @v flags Transfer flags
966  * @ret rc Return status code
967  */
968 static int usbio_endpoint_enqueue ( struct usb_endpoint *ep,
969  struct io_buffer *iobuf,
970  unsigned int flags ) {
971  struct usbio_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
972  unsigned int fill;
973  unsigned int index;
974 
975  /* Fail if shutdown is in progress */
977  return -ECANCELED;
978 
979  /* Fail if transfer ring is full */
980  fill = ( endpoint->prod - endpoint->cons );
981  if ( fill >= USBIO_RING_COUNT )
982  return -ENOBUFS;
983 
984  /* Add to ring */
985  index = ( endpoint->prod++ % USBIO_RING_COUNT );
986  endpoint->iobuf[index] = iobuf;
987  endpoint->flags[index] = flags;
988 
989  return 0;
990 }
991 
992 /**
993  * Enqueue message transfer
994  *
995  * @v ep USB endpoint
996  * @v iobuf I/O buffer
997  * @ret rc Return status code
998  */
1000  struct io_buffer *iobuf ) {
1001  struct usb_setup_packet *setup;
1002 
1003  /* Adjust I/O buffer to start of data payload */
1004  assert ( iob_len ( iobuf ) >= sizeof ( *setup ) );
1005  iob_pull ( iobuf, sizeof ( *setup ) );
1006 
1007  /* Enqueue transfer */
1008  return usbio_endpoint_enqueue ( ep, iobuf, USBIO_MESSAGE );
1009 }
1010 
1011 /**
1012  * Enqueue stream transfer
1013  *
1014  * @v ep USB endpoint
1015  * @v iobuf I/O buffer
1016  * @v zlp Append a zero-length packet
1017  * @ret rc Return status code
1018  */
1019 static int usbio_endpoint_stream ( struct usb_endpoint *ep,
1020  struct io_buffer *iobuf, int zlp ) {
1021 
1022  /* Enqueue transfer */
1023  return usbio_endpoint_enqueue ( ep, iobuf, ( zlp ? USBIO_ZLEN : 0 ) );
1024 }
1025 
1026 /**
1027  * Poll for completions
1028  *
1029  * @v endpoint Endpoint
1030  */
1031 static void usbio_endpoint_poll ( struct usbio_endpoint *endpoint ) {
1032 
1033  /* Do nothing if shutdown is in progress */
1035  return;
1036 
1037  /* Poll endpoint */
1038  endpoint->op->poll ( endpoint );
1039 }
1040 
1041 /******************************************************************************
1042  *
1043  * Device operations
1044  *
1045  ******************************************************************************
1046  */
1047 
1048 /**
1049  * Open device
1050  *
1051  * @v usb USB device
1052  * @ret rc Return status code
1053  */
1054 static int usbio_device_open ( struct usb_device *usb ) {
1055  struct usbio_device *usbio =
1056  usb_bus_get_hostdata ( usb->port->hub->bus );
1057 
1058  usb_set_hostdata ( usb, usbio );
1059  return 0;
1060 }
1061 
1062 /**
1063  * Close device
1064  *
1065  * @v usb USB device
1066  */
1067 static void usbio_device_close ( struct usb_device *usb __unused ) {
1068 
1069  /* Nothing to do */
1070 }
1071 
1072 /**
1073  * Assign device address
1074  *
1075  * @v usb USB device
1076  * @ret rc Return status code
1077  */
1078 static int usbio_device_address ( struct usb_device *usb __unused ) {
1079 
1080  /* Nothing to do */
1081  return 0;
1082 }
1083 
1084 /******************************************************************************
1085  *
1086  * Hub operations
1087  *
1088  ******************************************************************************
1089  */
1090 
1091 /**
1092  * Open hub
1093  *
1094  * @v hub USB hub
1095  * @ret rc Return status code
1096  */
1097 static int usbio_hub_open ( struct usb_hub *hub ) {
1098 
1099  /* Disallow non-root hubs */
1100  if ( hub->usb )
1101  return -ENOTSUP;
1102 
1103  /* Nothing to do */
1104  return 0;
1105 }
1106 
1107 /**
1108  * Close hub
1109  *
1110  * @v hub USB hub
1111  */
1112 static void usbio_hub_close ( struct usb_hub *hub __unused ) {
1113 
1114  /* Nothing to do */
1115 }
1116 
1117 /******************************************************************************
1118  *
1119  * Root hub operations
1120  *
1121  ******************************************************************************
1122  */
1123 
1124 /**
1125  * Open root hub
1126  *
1127  * @v hub USB hub
1128  * @ret rc Return status code
1129  */
1130 static int usbio_root_open ( struct usb_hub *hub __unused ) {
1131 
1132  /* Nothing to do */
1133  return 0;
1134 }
1135 
1136 /**
1137  * Close root hub
1138  *
1139  * @v hub USB hub
1140  */
1141 static void usbio_root_close ( struct usb_hub *hub __unused ) {
1142 
1143  /* Nothing to do */
1144 }
1145 
1146 /**
1147  * Enable port
1148  *
1149  * @v hub USB hub
1150  * @v port USB port
1151  * @ret rc Return status code
1152  */
1153 static int usbio_root_enable ( struct usb_hub *hub __unused,
1154  struct usb_port *port __unused ) {
1155 
1156  /* Nothing to do */
1157  return 0;
1158 }
1159 
1160 /**
1161  * Disable port
1162  *
1163  * @v hub USB hub
1164  * @v port USB port
1165  * @ret rc Return status code
1166  */
1167 static int usbio_root_disable ( struct usb_hub *hub __unused,
1168  struct usb_port *port __unused ) {
1169 
1170  /* Nothing to do */
1171  return 0;
1172 }
1173 
1174 /**
1175  * Update root hub port speed
1176  *
1177  * @v hub USB hub
1178  * @v port USB port
1179  * @ret rc Return status code
1180  */
1181 static int usbio_root_speed ( struct usb_hub *hub __unused,
1182  struct usb_port *port ) {
1183 
1184  /* Not actually exposed via EFI_USB_IO_PROTOCOL */
1185  port->speed = USB_SPEED_HIGH;
1186  return 0;
1187 }
1188 
1189 /**
1190  * Clear transaction translator buffer
1191  *
1192  * @v hub USB hub
1193  * @v port USB port
1194  * @v ep USB endpoint
1195  * @ret rc Return status code
1196  */
1197 static int usbio_root_clear_tt ( struct usb_hub *hub __unused,
1198  struct usb_port *port __unused,
1199  struct usb_endpoint *ep __unused ) {
1200 
1201  /* Should never be called; this is a root hub */
1202  return -ENOTSUP;
1203 }
1204 
1205 /******************************************************************************
1206  *
1207  * Bus operations
1208  *
1209  ******************************************************************************
1210  */
1211 
1212 /**
1213  * Open USB bus
1214  *
1215  * @v bus USB bus
1216  * @ret rc Return status code
1217  */
1218 static int usbio_bus_open ( struct usb_bus *bus __unused ) {
1219 
1220  /* Nothing to do */
1221  return 0;
1222 }
1223 
1224 /**
1225  * Close USB bus
1226  *
1227  * @v bus USB bus
1228  */
1229 static void usbio_bus_close ( struct usb_bus *bus __unused ) {
1230 
1231  /* Nothing to do */
1232 }
1233 
1234 /**
1235  * Poll USB bus
1236  *
1237  * @v bus USB bus
1238  */
1239 static void usbio_bus_poll ( struct usb_bus *bus ) {
1240  struct usbio_device *usbio = usb_bus_get_hostdata ( bus );
1241  struct usbio_endpoint *endpoint;
1242 
1243  /* Poll all endpoints. We trust that completion handlers are
1244  * minimal and will not do anything that could plausibly
1245  * affect the endpoint list itself.
1246  */
1247  list_for_each_entry ( endpoint, &usbio->endpoints, list )
1248  usbio_endpoint_poll ( endpoint );
1249 }
1250 
1251 /******************************************************************************
1252  *
1253  * EFI driver interface
1254  *
1255  ******************************************************************************
1256  */
1257 
1258 /** USB I/O host controller driver operations */
1260  .endpoint = {
1262  .close = usbio_endpoint_close,
1263  .reset = usbio_endpoint_reset,
1264  .mtu = usbio_endpoint_mtu,
1265  .message = usbio_endpoint_message,
1266  .stream = usbio_endpoint_stream,
1267  },
1268  .device = {
1269  .open = usbio_device_open,
1270  .close = usbio_device_close,
1271  .address = usbio_device_address,
1272  },
1273  .bus = {
1274  .open = usbio_bus_open,
1275  .close = usbio_bus_close,
1276  .poll = usbio_bus_poll,
1277  },
1278  .hub = {
1279  .open = usbio_hub_open,
1280  .close = usbio_hub_close,
1281  },
1282  .root = {
1283  .open = usbio_root_open,
1284  .close = usbio_root_close,
1285  .enable = usbio_root_enable,
1286  .disable = usbio_root_disable,
1287  .speed = usbio_root_speed,
1288  .clear_tt = usbio_root_clear_tt,
1289  },
1290 };
1291 
1292 /**
1293  * Check to see if driver supports a device
1294  *
1295  * @v handle EFI device handle
1296  * @ret rc Return status code
1297  */
1302  struct usb_function_descriptor desc;
1303  struct usb_driver *driver;
1304  struct usb_device_id *id;
1305  union {
1306  void *interface;
1307  EFI_USB_IO_PROTOCOL *io;
1308  } usb;
1309  EFI_STATUS efirc;
1310  int rc;
1311 
1312  /* Get protocol */
1313  if ( ( efirc = bs->OpenProtocol ( handle, &efi_usb_io_protocol_guid,
1314  &usb.interface, efi_image_handle,
1315  handle,
1317  rc = -EEFI ( efirc );
1318  DBGCP ( handle, "USB %s is not a USB device\n",
1319  efi_handle_name ( handle ) );
1320  goto err_open_protocol;
1321  }
1322 
1323  /* Get device descriptor */
1324  if ( ( efirc = usb.io->UsbGetDeviceDescriptor ( usb.io,
1325  &device ) ) != 0 ) {
1326  rc = -EEFI ( efirc );
1327  DBGC ( handle, "USB %s could not get device descriptor: "
1328  "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
1329  goto err_get_device_descriptor;
1330  }
1331  memset ( &desc, 0, sizeof ( desc ) );
1332  desc.vendor = device.IdVendor;
1333  desc.product = device.IdProduct;
1334 
1335  /* Get interface descriptor */
1336  if ( ( efirc = usb.io->UsbGetInterfaceDescriptor ( usb.io,
1337  &interface ) ) !=0){
1338  rc = -EEFI ( efirc );
1339  DBGC ( handle, "USB %s could not get interface descriptor: "
1340  "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
1341  goto err_get_interface_descriptor;
1342  }
1343  desc.class.class.class = interface.InterfaceClass;
1344  desc.class.class.subclass = interface.InterfaceSubClass;
1345  desc.class.class.protocol = interface.InterfaceProtocol;
1346 
1347  /* Look for a driver for this interface */
1348  driver = usb_find_driver ( &desc, &id );
1349  if ( ! driver ) {
1350  rc = -ENOTSUP;
1351  goto err_unsupported;
1352  }
1353 
1354  /* Success */
1355  rc = 0;
1356 
1357  err_unsupported:
1358  err_get_interface_descriptor:
1359  err_get_device_descriptor:
1362  err_open_protocol:
1363  return rc;
1364 }
1365 
1366 /**
1367  * Fetch configuration descriptor
1368  *
1369  * @v usbio USB I/O device
1370  * @ret rc Return status code
1371  */
1372 static int usbio_config ( struct usbio_device *usbio ) {
1373  EFI_HANDLE handle = usbio->handle;
1374  EFI_USB_IO_PROTOCOL *io = usbio->io;
1376  EFI_USB_CONFIG_DESCRIPTOR partial;
1377  union {
1378  struct usb_setup_packet setup;
1380  } msg;
1381  UINT32 status;
1382  size_t len;
1383  unsigned int count;
1384  unsigned int value;
1385  unsigned int i;
1386  EFI_STATUS efirc;
1387  int rc;
1388 
1389  /* Get device descriptor */
1390  if ( ( efirc = io->UsbGetDeviceDescriptor ( io, &device ) ) != 0 ) {
1391  rc = -EEFI ( efirc );
1392  DBGC ( usbio, "USB %s could not get device descriptor: "
1393  "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
1394  goto err_get_device_descriptor;
1395  }
1396  count = device.NumConfigurations;
1397 
1398  /* Get current partial configuration descriptor */
1399  if ( ( efirc = io->UsbGetConfigDescriptor ( io, &partial ) ) != 0 ) {
1400  rc = -EEFI ( efirc );
1401  DBGC ( usbio, "USB %s could not get partial configuration "
1402  "descriptor: %s\n", efi_handle_name ( handle ),
1403  strerror ( rc ) );
1404  goto err_get_configuration_descriptor;
1405  }
1406  len = le16_to_cpu ( partial.TotalLength );
1407 
1408  /* Allocate configuration descriptor */
1409  usbio->config = malloc ( len );
1410  if ( ! usbio->config ) {
1411  rc = -ENOMEM;
1412  goto err_alloc;
1413  }
1414 
1415  /* There is, naturally, no way to retrieve the entire device
1416  * configuration descriptor via EFI_USB_IO_PROTOCOL. Worse,
1417  * there is no way to even retrieve the index of the current
1418  * configuration descriptor. We have to iterate over all
1419  * possible configuration descriptors looking for the
1420  * descriptor that matches the current configuration value.
1421  */
1422  for ( i = 0 ; i < count ; i++ ) {
1423 
1424  /* Construct request */
1425  msg.setup.request = cpu_to_le16 ( USB_GET_DESCRIPTOR );
1426  value = ( ( USB_CONFIGURATION_DESCRIPTOR << 8 ) | i );
1427  msg.setup.value = cpu_to_le16 ( value );
1428  msg.setup.index = 0;
1429  msg.setup.len = cpu_to_le16 ( len );
1430 
1431  /* Get full configuration descriptor */
1432  if ( ( efirc = io->UsbControlTransfer ( io, &msg.efi,
1433  EfiUsbDataIn, 0,
1434  usbio->config, len,
1435  &status ) ) != 0 ) {
1436  rc = -EEFI ( efirc );
1437  DBGC ( usbio, "USB %s could not get configuration %d "
1438  "descriptor: %s\n", efi_handle_name ( handle ),
1439  i, strerror ( rc ) );
1440  goto err_control_transfer;
1441  }
1442 
1443  /* Ignore unless this is the current configuration */
1444  if ( usbio->config->config != partial.ConfigurationValue )
1445  continue;
1446 
1447  /* Check length */
1448  if ( le16_to_cpu ( usbio->config->len ) != len ) {
1449  DBGC ( usbio, "USB %s configuration descriptor length "
1450  "mismatch\n", efi_handle_name ( handle ) );
1451  rc = -EINVAL;
1452  goto err_len;
1453  }
1454 
1455  return 0;
1456  }
1457 
1458  /* No match found */
1459  DBGC ( usbio, "USB %s could not find current configuration "
1460  "descriptor\n", efi_handle_name ( handle ) );
1461  rc = -ENOENT;
1462 
1463  err_len:
1464  err_control_transfer:
1465  free ( usbio->config );
1466  err_alloc:
1467  err_get_configuration_descriptor:
1468  err_get_device_descriptor:
1469  return rc;
1470 }
1471 
1472 /**
1473  * Construct device path for opening other interfaces
1474  *
1475  * @v usbio USB I/O device
1476  * @ret rc Return status code
1477  */
1478 static int usbio_path ( struct usbio_device *usbio ) {
1480  EFI_HANDLE handle = usbio->handle;
1483  USB_DEVICE_PATH *usbpath;
1484  union {
1485  void *interface;
1487  } u;
1488  size_t len;
1489  EFI_STATUS efirc;
1490  int rc;
1491 
1492  /* Open device path protocol */
1493  if ( ( efirc = bs->OpenProtocol ( handle,
1495  &u.interface, efi_image_handle,
1496  handle,
1498  rc = -EEFI ( efirc );
1499  DBGC ( usbio, "USBIO %s cannot open device path protocol: "
1500  "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
1501  goto err_open_protocol;
1502  }
1503  path = u.interface;
1504 
1505  /* Locate end of device path and sanity check */
1506  len = efi_devpath_len ( path );
1507  if ( len < sizeof ( *usbpath ) ) {
1508  DBGC ( usbio, "USBIO %s underlength device path\n",
1509  efi_handle_name ( handle ) );
1510  rc = -EINVAL;
1511  goto err_underlength;
1512  }
1513  usbpath = ( ( ( void * ) path ) + len - sizeof ( *usbpath ) );
1514  if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) &&
1515  ( usbpath->Header.SubType == MSG_USB_DP ) ) ) {
1516  DBGC ( usbio, "USBIO %s not a USB device path: ",
1517  efi_handle_name ( handle ) );
1518  DBGC ( usbio, "%s\n", efi_devpath_text ( path ) );
1519  rc = -EINVAL;
1520  goto err_non_usb;
1521  }
1522 
1523  /* Allocate copy of device path */
1524  usbio->path = malloc ( len + sizeof ( *end ) );
1525  if ( ! usbio->path ) {
1526  rc = -ENOMEM;
1527  goto err_alloc;
1528  }
1529  memcpy ( usbio->path, path, ( len + sizeof ( *end ) ) );
1530  usbio->usbpath = ( ( ( void * ) usbio->path ) + len -
1531  sizeof ( *usbpath ) );
1532 
1533  /* Close protocol */
1536 
1537  return 0;
1538 
1539  free ( usbio->path );
1540  err_alloc:
1541  err_non_usb:
1542  err_underlength:
1545  err_open_protocol:
1546  return rc;
1547 }
1548 
1549 /**
1550  * Construct interface list
1551  *
1552  * @v usbio USB I/O device
1553  * @ret rc Return status code
1554  */
1555 static int usbio_interfaces ( struct usbio_device *usbio ) {
1556  EFI_HANDLE handle = usbio->handle;
1557  EFI_USB_IO_PROTOCOL *io = usbio->io;
1559  unsigned int first;
1560  unsigned int count;
1561  EFI_STATUS efirc;
1562  int rc;
1563 
1564  /* Get interface descriptor */
1565  if ( ( efirc = io->UsbGetInterfaceDescriptor ( io, &interface ) ) != 0){
1566  rc = -EEFI ( efirc );
1567  DBGC ( usbio, "USB %s could not get interface descriptor: "
1568  "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
1569  goto err_get_interface_descriptor;
1570  }
1571 
1572  /* Record first interface number */
1573  first = interface.InterfaceNumber;
1574  count = usbio->config->interfaces;
1575  assert ( first < count );
1576  usbio->first = first;
1577 
1578  /* Allocate interface list */
1579  usbio->interface = zalloc ( count * sizeof ( usbio->interface[0] ) );
1580  if ( ! usbio->interface ) {
1581  rc = -ENOMEM;
1582  goto err_alloc;
1583  }
1584 
1585  /* Use already-opened protocol for control transfers and for
1586  * the first interface.
1587  */
1588  usbio->interface[0].handle = handle;
1589  usbio->interface[0].io = io;
1590  usbio->interface[0].count = 1;
1591  usbio->interface[first].handle = handle;
1592  usbio->interface[first].io = io;
1593  usbio->interface[first].count = 1;
1594 
1595  return 0;
1596 
1597  free ( usbio->interface );
1598  err_alloc:
1599  err_get_interface_descriptor:
1600  return rc;
1601 }
1602 
1603 /**
1604  * Attach driver to device
1605  *
1606  * @v efidev EFI device
1607  * @ret rc Return status code
1608  */
1609 static int usbio_start ( struct efi_device *efidev ) {
1611  EFI_HANDLE handle = efidev->device;
1612  struct usbio_device *usbio;
1613  struct usb_port *port;
1614  union {
1615  void *interface;
1616  EFI_USB_IO_PROTOCOL *io;
1617  } u;
1618  EFI_STATUS efirc;
1619  int rc;
1620 
1621  /* Allocate and initialise structure */
1622  usbio = zalloc ( sizeof ( *usbio ) );
1623  if ( ! usbio ) {
1624  rc = -ENOMEM;
1625  goto err_alloc;
1626  }
1627  efidev_set_drvdata ( efidev, usbio );
1628  usbio->handle = handle;
1629  INIT_LIST_HEAD ( &usbio->endpoints );
1630 
1631  /* Open USB I/O protocol */
1632  if ( ( efirc = bs->OpenProtocol ( handle, &efi_usb_io_protocol_guid,
1633  &u.interface, efi_image_handle,
1634  handle,
1637  rc = -EEFI ( efirc );
1638  DBGC ( usbio, "USBIO %s cannot open USB I/O protocol: %s\n",
1639  efi_handle_name ( handle ), strerror ( rc ) );
1641  goto err_open_usbio;
1642  }
1643  usbio->io = u.io;
1644 
1645  /* Describe generic device */
1646  efi_device_info ( handle, "USB", &usbio->dev );
1647  usbio->dev.parent = &efidev->dev;
1648  list_add ( &usbio->dev.siblings, &efidev->dev.children );
1649  INIT_LIST_HEAD ( &usbio->dev.children );
1650 
1651  /* Fetch configuration descriptor */
1652  if ( ( rc = usbio_config ( usbio ) ) != 0 )
1653  goto err_config;
1654 
1655  /* Construct device path */
1656  if ( ( rc = usbio_path ( usbio ) ) != 0 )
1657  goto err_path;
1658 
1659  /* Construct interface list */
1660  if ( ( rc = usbio_interfaces ( usbio ) ) != 0 )
1661  goto err_interfaces;
1662 
1663  /* Allocate USB bus */
1664  usbio->bus = alloc_usb_bus ( &usbio->dev, 1 /* single "port" */,
1666  if ( ! usbio->bus ) {
1667  rc = -ENOMEM;
1668  goto err_alloc_bus;
1669  }
1670  usb_bus_set_hostdata ( usbio->bus, usbio );
1671  usb_hub_set_drvdata ( usbio->bus->hub, usbio );
1672 
1673  /* Set port protocol */
1674  port = usb_port ( usbio->bus->hub, 1 );
1675  port->protocol = USB_PROTO_2_0;
1676 
1677  /* Register USB bus */
1678  if ( ( rc = register_usb_bus ( usbio->bus ) ) != 0 )
1679  goto err_register;
1680 
1681  return 0;
1682 
1683  unregister_usb_bus ( usbio->bus );
1684  err_register:
1685  free_usb_bus ( usbio->bus );
1686  err_alloc_bus:
1687  free ( usbio->interface );
1688  err_interfaces:
1689  free ( usbio->path );
1690  err_path:
1691  free ( usbio->config );
1692  err_config:
1693  list_del ( &usbio->dev.siblings );
1696  err_open_usbio:
1697  free ( usbio );
1698  err_alloc:
1699  return rc;
1700 }
1701 
1702 /**
1703  * Detach driver from device
1704  *
1705  * @v efidev EFI device
1706  */
1707 static void usbio_stop ( struct efi_device *efidev ) {
1709  EFI_HANDLE handle = efidev->device;
1710  struct usbio_device *usbio = efidev_get_drvdata ( efidev );
1711 
1712  unregister_usb_bus ( usbio->bus );
1713  free_usb_bus ( usbio->bus );
1714  free ( usbio->interface );
1715  free ( usbio->path );
1716  free ( usbio->config );
1717  list_del ( &usbio->dev.siblings );
1720  free ( usbio );
1721 }
1722 
1723 /** EFI USB I/O driver */
1724 struct efi_driver usbio_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
1725  .name = "USBIO",
1726  .supported = usbio_supported,
1727  .start = usbio_start,
1728  .stop = usbio_stop,
1729 };
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
A USB driver.
Definition: usb.h:1363
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
#define EINVAL
Invalid argument.
Definition: errno.h:428
static void usbio_bulk_out_poll(struct usbio_endpoint *endpoint)
Poll bulk OUT endpoint.
Definition: usbio.c:556
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition: usb.h:561
A USB I/O protocol interface.
Definition: usbio.h:112
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
static int usbio_root_open(struct usb_hub *hub __unused)
Open root hub.
Definition: usbio.c:1130
A USB device ID.
Definition: usb.h:1317
struct usbio_interrupt_ring * intr
Interrupt ring buffer (if applicable)
Definition: usbio.h:80
static int usbio_device_address(struct usb_device *usb __unused)
Assign device address.
Definition: usbio.c:1078
#define iob_put(iobuf, len)
Definition: iobuf.h:116
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:157
uint8_t class
Class code.
Definition: usb.h:147
#define USB_RECIP_MASK
Request recipient mask.
Definition: usb.h:95
struct usbio_device * usbio
USB I/O device.
Definition: usbio.h:55
static void usbio_interrupt_poll(struct usbio_endpoint *endpoint)
Poll interrupt endpoint.
Definition: usbio.c:783
struct device dev
Generic device.
Definition: usbio.h:132
EFI driver interface.
static int usbio_endpoint_open(struct usb_endpoint *ep)
Open endpoint.
Definition: usbio.c:834
uint8_t interface[0]
List of interface numbers.
Definition: usb.h:680
A USB hub.
Definition: usb.h:824
static void usbio_bus_close(struct usb_bus *bus __unused)
Close USB bus.
Definition: usbio.c:1229
#define USB_RECIP_INTERFACE
Request recipient is an interface.
Definition: usb.h:101
static int usbio_path(struct usbio_device *usbio)
Construct device path for opening other interfaces.
Definition: usbio.c:1478
unsigned int count
Number of interfaces.
Definition: usb.h:648
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
Definition: usb.c:2031
Error codes.
#define USB_GET_DESCRIPTOR
Get descriptor.
Definition: usb.h:122
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
USB 2.0.
Definition: usb.h:22
#define iob_push(iobuf, len)
Definition: iobuf.h:80
static void usbio_device_close(struct usb_device *usb __unused)
Close device.
Definition: usbio.c:1067
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:767
uint8_t attr
Type and attributes.
Definition: librm.h:256
static void usbio_control_close(struct usbio_endpoint *endpoint __unused)
Close control endpoint.
Definition: usbio.c:304
static void usbio_root_close(struct usb_hub *hub __unused)
Close root hub.
Definition: usbio.c:1141
static void usbio_bulk_in_close(struct usbio_endpoint *endpoint __unused)
Close bulk IN endpoint.
Definition: usbio.c:453
EFI_USB_IO_PROTOCOL pseudo Host Controller Interface driver.
static int usbio_interface(struct usbio_device *usbio, struct usb_endpoint *ep)
Determine endpoint interface number.
Definition: usbio.c:120
EFI_USB_IO_ASYNC_INTERRUPT_TRANSFER UsbAsyncInterruptTransfer
Definition: UsbIo.h:491
static void usbio_hub_close(struct usb_hub *hub __unused)
Close hub.
Definition: usbio.c:1112
#define DBGC(...)
Definition: compiler.h:505
static struct usbio_operations usbio_control_operations
Control endpoint operations.
Definition: usbio.c:423
static int usbio_start(struct efi_device *efidev)
Attach driver to device.
Definition: usbio.c:1609
uint16_t vendor
Vendor ID.
Definition: usb.h:642
#define ENOENT
No such file or directory.
Definition: errno.h:514
Standard Interface Descriptor USB 2.0 spec, Section 9.6.5.
Definition: Usb.h:147
unsigned int UINT32
Definition: ProcessorBind.h:56
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
The EFI_USB_IO_PROTOCOL provides four basic transfers types described in the USB 1....
Definition: UsbIo.h:485
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:379
size_t efi_devpath_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_utils.c:59
uint8_t interfaces
Number of interfaces.
Definition: usb.h:201
static void usbio_endpoint_close(struct usb_endpoint *ep)
Close endpoint.
Definition: usbio.c:910
#define for_each_config_descriptor(desc, config)
Iterate over all configuration descriptors.
Definition: usb.h:371
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1275
uint8_t direction
Direction.
Definition: ena.h:14
#define USB_ENDPOINT_ATTR_BULK
Bulk endpoint transfer type.
Definition: usb.h:275
uint8_t endpoint
Endpoint address.
Definition: usb.h:253
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:260
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:51
uint16_t device
Device ID.
Definition: ena.h:24
EFI_USB_DATA_DIRECTION
USB data transfer direction.
Definition: UsbIo.h:52
static void usbio_close(struct usbio_device *usbio, unsigned int interface)
Close USB I/O interface.
Definition: usbio.c:260
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static int usbio_bus_open(struct usb_bus *bus __unused)
Open USB bus.
Definition: usbio.c:1218
#define USBIO_RING_COUNT
USB I/O ring buffer size.
Definition: usbio.h:50
union usb_class_descriptor class
Class.
Definition: usb.h:646
#define MESSAGING_DEVICE_PATH
Messaging Device Paths.
Definition: DevicePath.h:315
EFI_USB_IO_PROTOCOL * io
USB I/O protocol.
Definition: usbio.h:116
struct device * parent
Bus device.
Definition: device.h:85
struct efi_driver usbio_driver __efi_driver(EFI_DRIVER_NORMAL)
EFI USB I/O driver.
#define EXDEV
Improper link.
Definition: errno.h:684
static int usbio_endpoint_reset(struct usb_endpoint *ep __unused)
Reset endpoint.
Definition: usbio.c:942
EFI utilities.
static void usbio_bus_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usbio.c:1239
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static void usbio_interrupt_close(struct usbio_endpoint *endpoint)
Close interrupt endpoint.
Definition: usbio.c:766
static void usbio_bulk_in_poll(struct usbio_endpoint *endpoint)
Poll bulk IN endpoint.
Definition: usbio.c:463
A USB interrupt ring buffer.
Definition: usbio.h:33
uint8_t flags[USBIO_RING_COUNT]
Flags.
Definition: usbio.h:77
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1028
#define USBIO_MTU
USB I/O maximum transfer size.
Definition: usbio.h:24
static void usbio_endpoint_poll(struct usbio_endpoint *endpoint)
Poll for completions.
Definition: usbio.c:1031
uint8_t status
Status.
Definition: ena.h:16
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
uint16_t product
Product ID.
Definition: usb.h:644
A USB port.
Definition: usb.h:796
static int usbio_root_speed(struct usb_hub *hub __unused, struct usb_port *port)
Update root hub port speed.
Definition: usbio.c:1181
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
A USB endpoint.
Definition: usb.h:389
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:830
unsigned int interface
Containing interface number.
Definition: usbio.h:64
void(* poll)(struct usbio_endpoint *endpoint)
Poll endpoint.
Definition: usbio.h:108
static int usbio_endpoint_message(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
Definition: usbio.c:999
void * memcpy(void *dest, const void *src, size_t len) __nonnull
u8 port
Port number.
Definition: CIB_PRM.h:31
A USB interface descriptor.
Definition: usb.h:230
A USB function descriptor.
Definition: usb.h:640
static int usbio_interrupt_open(struct usbio_endpoint *endpoint)
Open interrupt endpoint.
Definition: usbio.c:708
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2102
Format of Setup Data for USB Device Requests USB 2.0 spec, Section 9.3.
Definition: Usb.h:99
struct usb_port * port
USB port.
Definition: usb.h:710
Assertions.
struct usb_driver * usb_find_driver(struct usb_function_descriptor *desc, struct usb_device_id **id)
Find USB device driver.
Definition: usb.c:1130
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static int usbio_endpoint_enqueue(struct usb_endpoint *ep, struct io_buffer *iobuf, unsigned int flags)
Enqueue transfer.
Definition: usbio.c:968
An object interface.
Definition: interface.h:109
EFI_HANDLE handle
EFI handle.
Definition: usbio.h:66
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
This transfer requires zero-length packet termination.
Definition: usbio.h:88
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static int usbio_control_open(struct usbio_endpoint *endpoint __unused)
Open control endpoint.
Definition: usbio.c:293
struct list_head endpoints
List of endpoints.
Definition: usbio.h:150
static struct usbio_operations usbio_bulk_in_operations
Bulk endpoint operations.
Definition: usbio.c:516
unsigned int count
Usage count.
Definition: usbio.h:118
static int usbio_config(struct usbio_device *usbio)
Fetch configuration descriptor.
Definition: usbio.c:1372
static int usbio_endpoint_mtu(struct usb_endpoint *ep __unused)
Update MTU.
Definition: usbio.c:954
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:83
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:366
#define USB_CONFIGURATION_DESCRIPTOR
A USB configuration descriptor.
Definition: usb.h:213
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
uint8_t id
Request identifier.
Definition: ena.h:12
A USB device.
Definition: usb.h:706
struct usb_bus * bus
USB bus.
Definition: usbio.h:148
uint8_t type
Descriptor type.
Definition: usb.h:162
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:414
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
EFI_USB_IO_PROTOCOL * io
USB I/O protocol.
Definition: usbio.h:68
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI_GUID efi_usb_io_protocol_guid
USB I/O protocol GUID.
Definition: efi_guid.c:296
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static int usbio_supported(EFI_HANDLE handle)
Check to see if driver supports a device.
Definition: usbio.c:1298
#define EFIAPI
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
uint8_t first
First interface number.
Definition: usbio.h:143
void(* close)(struct usbio_endpoint *endpoint)
Close endpoint.
Definition: usbio.h:103
UINT8 InterfaceNumber
USB Interface Number.
Definition: DevicePath.h:422
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:83
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
Definition: usbio.h:138
static int usbio_bulk_in_open(struct usbio_endpoint *endpoint __unused)
Open bulk IN endpoint.
Definition: usbio.c:442
static void usbio_control_poll(struct usbio_endpoint *endpoint)
Poll control endpoint.
Definition: usbio.c:314
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
An EFI device.
Definition: efi_driver.h:17
Standard Endpoint Descriptor USB 2.0 spec, Section 9.6.6.
Definition: Usb.h:163
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
struct usbio_operations * op
USB I/O endpoint operations.
Definition: usbio.h:61
struct usb_device * usb
USB device.
Definition: usb.h:661
#define le16_to_cpu(value)
Definition: byteswap.h:112
#define VOID
Undeclared type.
Definition: Base.h:319
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
A USB setup data packet.
Definition: usb.h:68
struct usb_configuration_descriptor * config
Configuration descriptor.
Definition: usbio.h:135
struct usbio_endpoint * endpoint
USB I/O endpoint.
Definition: usbio.h:35
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
#define TRUE
Definition: tlan.h:46
uint8_t protocol
Protocol code.
Definition: usb.h:151
static int usbio_hub_open(struct usb_hub *hub)
Open hub.
Definition: usbio.c:1097
EFI_USB_IO_CONTROL_TRANSFER UsbControlTransfer
Definition: UsbIo.h:489
EFI API.
unsigned int prod
Producer counter.
Definition: usbio.h:71
EFI_USB_IO_BULK_TRANSFER UsbBulkTransfer
Definition: UsbIo.h:490
size_t mtu
Maximum transfer size.
Definition: usb.h:397
EFI Usb I/O Protocol as defined in UEFI specification.
static int usbio_endpoint_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
Definition: usbio.c:1019
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
An EFI driver.
Definition: efi_driver.h:31
A USB I/O endpoint.
Definition: usbio.h:53
UINT16 TotalLength
Definition: Usb.h:135
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
A USB configuration descriptor.
Definition: usb.h:195
uint8_t subclass
Subclass code.
Definition: usb.h:149
struct usbio_interface * interface
USB I/O protocol interfaces.
Definition: usbio.h:145
#define USBIO_INTR_COUNT
USB I/O interrupt ring buffer size.
Definition: usbio.h:30
A USB endpoint descriptor.
Definition: usb.h:249
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1039
static int usbio_bulk_out_open(struct usbio_endpoint *endpoint __unused)
Open bulk OUT endpoint.
Definition: usbio.c:535
USB_DEVICE_PATH * usbpath
Final component of USB device path.
Definition: usbio.h:140
uint32_t len
Length.
Definition: ena.h:14
uint8_t config
Configuration value.
Definition: usb.h:203
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
EFI_USB_IO_GET_DEVICE_DESCRIPTOR UsbGetDeviceDescriptor
Definition: UsbIo.h:499
#define DBGC2(...)
Definition: compiler.h:522
static int usbio_device_open(struct usb_device *usb)
Open device.
Definition: usbio.c:1054
Universal Serial Bus (USB)
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2067
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
EFI_USB_IO_PROTOCOL * io
USB I/O protocol.
Definition: usbio.h:130
unsigned int cons
Consumer counter.
Definition: usbio.h:73
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1064
void * data
Start of data.
Definition: iobuf.h:44
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
static int usbio_root_disable(struct usb_hub *hub __unused, struct usb_port *port __unused)
Disable port.
Definition: usbio.c:1167
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct usb_hub * hub
USB hub.
Definition: usb.h:798
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:59
int(* open)(struct usbio_endpoint *endpoint)
Open endpoint.
Definition: usbio.h:98
uint16_t count
Number of entries.
Definition: ena.h:22
High speed (480Mbps)
Definition: usb.h:52
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:728
unsigned int interval
Interval (in microframes)
Definition: usb.h:401
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
UINT8 ConfigurationValue
Definition: Usb.h:137
uint8_t fill
Length pair.
Definition: deflate.h:12
#define cpu_to_le16(value)
Definition: byteswap.h:106
static struct usbio_operations usbio_interrupt_operations
Interrupt endpoint operations.
Definition: usbio.c:815
Standard Configuration Descriptor USB 2.0 spec, Section 9.6.3.
Definition: Usb.h:132
const char * name
Name.
Definition: efi_driver.h:33
uint32_t end
Ending offset.
Definition: netvsc.h:18
USB host controller operations.
Definition: usb.h:1008
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition: usb.h:272
struct list_head list
List of endpoints.
Definition: usbio.h:59
#define DBGCP(...)
Definition: compiler.h:539
#define FALSE
Definition: tlan.h:45
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:251
struct usb_hub * hub
Root hub.
Definition: usb.h:972
struct usb_endpoint * ep
USB endpoint.
Definition: usbio.h:57
uint16_t len
Total length.
Definition: usb.h:199
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:52
struct usb_function_descriptor desc
Function descriptor.
Definition: usb.h:663
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:920
struct usb_device * usb
USB device.
Definition: usb.h:391
static void usbio_stop(struct efi_device *efidev)
Detach driver from device.
Definition: usbio.c:1707
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:943
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
static int usbio_root_clear_tt(struct usb_hub *hub __unused, struct usb_port *port __unused, struct usb_endpoint *ep __unused)
Clear transaction translator buffer.
Definition: usbio.c:1197
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
EFI_HANDLE handle
EFI device handle.
Definition: usbio.h:128
union @16 u
A USB function.
Definition: usb.h:657
static EFI_STATUS EFIAPI usbio_interrupt_callback(VOID *data, UINTN len, VOID *context, UINT32 status)
Interrupt endpoint callback.
Definition: usbio.c:663
static struct usbio_operations usbio_bulk_out_operations
Bulk endpoint operations.
Definition: usbio.c:617
struct usb_bus * bus
USB bus.
Definition: usb.h:828
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:72
A USB I/O protocol device.
Definition: usbio.h:126
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
USB I/O endpoint operations.
Definition: usbio.h:92
struct device dev
Generic device.
Definition: efi_driver.h:19
struct list_head functions
List of functions.
Definition: usb.h:720
EFI_HANDLE handle
EFI device handle.
Definition: usbio.h:114
uint16_t handle
Handle.
Definition: smbios.h:16
#define USB_EP0_ADDRESS
Control endpoint address.
Definition: usb.h:486
static int usbio_root_enable(struct usb_hub *hub __unused, struct usb_port *port __unused)
Enable port.
Definition: usbio.c:1153
#define USB_SET_CONFIGURATION
Set configuration.
Definition: usb.h:131
static int usbio_interfaces(struct usbio_device *usbio)
Construct interface list.
Definition: usbio.c:1555
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
EFI_USB_IO_GET_INTERFACE_DESCRIPTOR UsbGetInterfaceDescriptor
Definition: UsbIo.h:501
Standard Device Descriptor USB 2.0 spec, Section 9.6.1.
Definition: Usb.h:111
String functions.
struct list_head list
List of functions within this USB device.
Definition: usb.h:667
A USB bus.
Definition: usb.h:949
unsigned int attributes
Attributes.
Definition: usb.h:395
static int usbio_open(struct usbio_device *usbio, unsigned int interface)
Open USB I/O interface.
Definition: usbio.c:182
uint8_t interface
Interface number.
Definition: usb.h:234
uint8_t bus
Bus.
Definition: edd.h:14
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23
unsigned int address
Endpoint address.
Definition: usb.h:393
This is a message transfer.
Definition: usbio.h:86
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2126
#define MSG_USB_DP
USB Device Path SubType.
Definition: DevicePath.h:412
struct io_buffer * iobuf[USBIO_RING_COUNT]
I/O buffers.
Definition: usbio.h:75
struct usb_class class
Class.
Definition: usb.h:629
Definition: efi.h:55
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:569
static void usbio_bulk_out_close(struct usbio_endpoint *endpoint __unused)
Close bulk OUT endpoint.
Definition: usbio.c:546
EFI_LOCATE_DEVICE_PATH LocateDevicePath
Definition: UefiSpec.h:1877
EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end(EFI_DEVICE_PATH_PROTOCOL *path)
Find end of device path.
Definition: efi_utils.c:41
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:211
#define EFI_TIMEOUT
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:138
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572
EFI_USB_IO_GET_CONFIG_DESCRIPTOR UsbGetConfigDescriptor
Definition: UsbIo.h:500
void * memset(void *dest, int character, size_t len) __nonnull
#define ENOTSUP_MORONIC_SPECIFICATION
Definition: usbio.c:100
#define EFI_DRIVER_NORMAL
Normal drivers.
Definition: efi_driver.h:63
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:45
A persistent I/O buffer.
Definition: iobuf.h:32
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285
uint8_t flags
Flags.
Definition: ena.h:18