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