[efi] Generalise EFI entropy generation to non-x86 CPUs
[ipxe.git] / src / interface / efi / efi_usb.c
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 <stdio.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <errno.h>
31 #include <assert.h>
32 #include <ipxe/efi/efi.h>
33 #include <ipxe/efi/efi_utils.h>
34 #include <ipxe/efi/efi_driver.h>
35 #include <ipxe/efi/efi_usb.h>
36 #include <ipxe/usb.h>
37
38 /** @file
39 *
40 * EFI USB I/O PROTOCOL
41 *
42 */
43
44 /**
45 * Transcribe data direction (for debugging)
46 *
47 * @v direction Data direction
48 * @ret text Transcribed data direction
49 */
50 static const char * efi_usb_direction_name ( EFI_USB_DATA_DIRECTION direction ){
51
52 switch ( direction ) {
53 case EfiUsbDataIn: return "in";
54 case EfiUsbDataOut: return "out";
55 case EfiUsbNoData: return "none";
56 default: return "<UNKNOWN>";
57 }
58 }
59
60 /******************************************************************************
61 *
62 * Endpoints
63 *
64 ******************************************************************************
65 */
66
67 /**
68 * Poll USB bus
69 *
70 * @v usbdev EFI USB device
71 */
72 static void efi_usb_poll ( struct efi_usb_device *usbdev ) {
73 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
74 struct usb_bus *bus = usbdev->usb->port->hub->bus;
75 EFI_TPL tpl;
76
77 /* UEFI manages to ingeniously combine the worst aspects of
78 * both polling and interrupt-driven designs. There is no way
79 * to support proper interrupt-driven operation, since there
80 * is no way to hook in an interrupt service routine. A
81 * mockery of interrupts is provided by UEFI timers, which
82 * trigger at a preset rate and can fire at any time.
83 *
84 * We therefore have all of the downsides of a polling design
85 * (inefficiency and inability to sleep until something
86 * interesting happens) combined with all of the downsides of
87 * an interrupt-driven design (the complexity of code that
88 * could be preempted at any time).
89 *
90 * The UEFI specification expects us to litter the entire
91 * codebase with calls to RaiseTPL() as needed for sections of
92 * code that are not reentrant. Since this doesn't actually
93 * gain us any substantive benefits (since even with such
94 * calls we would still be suffering from the limitations of a
95 * polling design), we instead choose to wrap only calls to
96 * usb_poll(). This should be sufficient for most practical
97 * purposes.
98 *
99 * A "proper" solution would involve rearchitecting the whole
100 * codebase to support interrupt-driven operation.
101 */
102 tpl = bs->RaiseTPL ( TPL_NOTIFY );
103
104 /* Poll bus */
105 usb_poll ( bus );
106
107 /* Restore task priority level */
108 bs->RestoreTPL ( tpl );
109 }
110
111 /**
112 * Poll USB bus (from endpoint event timer)
113 *
114 * @v event EFI event
115 * @v context EFI USB endpoint
116 */
117 static VOID EFIAPI efi_usb_timer ( EFI_EVENT event __unused,
118 VOID *context ) {
119 struct efi_usb_endpoint *usbep = context;
120 struct usb_bus *bus = usbep->usbintf->usbdev->usb->port->hub->bus;
121
122 /* Poll bus */
123 usb_poll ( bus );
124
125 /* Refill endpoint */
126 usb_refill ( &usbep->ep );
127 }
128
129 /**
130 * Get endpoint MTU
131 *
132 * @v usbintf EFI USB interface
133 * @v endpoint Endpoint address
134 * @ret mtu Endpoint MTU, or negative error
135 */
136 static int efi_usb_mtu ( struct efi_usb_interface *usbintf,
137 unsigned int endpoint ) {
138 struct efi_usb_device *usbdev = usbintf->usbdev;
139 struct usb_interface_descriptor *interface;
140 struct usb_endpoint_descriptor *desc;
141
142 /* Locate cached interface descriptor */
143 interface = usb_interface_descriptor ( usbdev->config,
144 usbintf->interface,
145 usbintf->alternate );
146 if ( ! interface ) {
147 DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n",
148 usbintf->name, usbintf->alternate );
149 return -ENOENT;
150 }
151
152 /* Locate and copy cached endpoint descriptor */
153 for_each_interface_descriptor ( desc, usbdev->config, interface ) {
154 if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) &&
155 ( desc->endpoint == endpoint ) )
156 return USB_ENDPOINT_MTU ( le16_to_cpu ( desc->sizes ) );
157 }
158
159 DBGC ( usbdev, "USBDEV %s alt %d ep %02x has no descriptor\n",
160 usbintf->name, usbintf->alternate, endpoint );
161 return -ENOENT;
162 }
163
164 /**
165 * Open endpoint
166 *
167 * @v usbintf EFI USB interface
168 * @v endpoint Endpoint address
169 * @v attributes Endpoint attributes
170 * @v interval Interval (in milliseconds)
171 * @v driver Driver operations
172 * @ret rc Return status code
173 */
174 static int efi_usb_open ( struct efi_usb_interface *usbintf,
175 unsigned int endpoint, unsigned int attributes,
176 unsigned int interval,
177 struct usb_endpoint_driver_operations *driver ) {
178 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
179 struct efi_usb_device *usbdev = usbintf->usbdev;
180 struct efi_usb_endpoint *usbep;
181 unsigned int index = USB_ENDPOINT_IDX ( endpoint );
182 int mtu;
183 EFI_STATUS efirc;
184 int rc;
185
186 /* Get endpoint MTU */
187 mtu = efi_usb_mtu ( usbintf, endpoint );
188 if ( mtu < 0 ) {
189 rc = mtu;
190 goto err_mtu;
191 }
192
193 /* Allocate and initialise structure */
194 usbep = zalloc ( sizeof ( *usbep ) );
195 if ( ! usbep ) {
196 rc = -ENOMEM;
197 goto err_alloc;
198 }
199 usbep->usbintf = usbintf;
200 usb_endpoint_init ( &usbep->ep, usbdev->usb, driver );
201 usb_endpoint_describe ( &usbep->ep, endpoint, attributes, mtu, 0,
202 ( interval << 3 /* microframes */ ) );
203
204 /* Open endpoint */
205 if ( ( rc = usb_endpoint_open ( &usbep->ep ) ) != 0 ) {
206 DBGC ( usbdev, "USBDEV %s %s could not open: %s\n",
207 usbintf->name, usb_endpoint_name ( &usbep->ep ),
208 strerror ( rc ) );
209 goto err_open;
210 }
211
212 /* Record opened endpoint */
213 usbintf->endpoint[index] = usbep;
214 DBGC ( usbdev, "USBDEV %s %s opened\n",
215 usbintf->name, usb_endpoint_name ( &usbep->ep ) );
216
217 /* Create event */
218 if ( ( efirc = bs->CreateEvent ( ( EVT_TIMER | EVT_NOTIFY_SIGNAL ),
219 TPL_NOTIFY, efi_usb_timer, usbep,
220 &usbep->event ) ) != 0 ) {
221 rc = -EEFI ( efirc );
222 DBGC ( usbdev, "USBDEV %s %s could not create event: %s\n",
223 usbintf->name, usb_endpoint_name ( &usbep->ep ),
224 strerror ( rc ) );
225 goto err_event;
226 }
227
228 return 0;
229
230 bs->CloseEvent ( usbep->event );
231 err_event:
232 usbintf->endpoint[index] = usbep;
233 usb_endpoint_close ( &usbep->ep );
234 err_open:
235 free ( usbep );
236 err_alloc:
237 err_mtu:
238 return rc;
239 }
240
241 /**
242 * Close endpoint
243 *
244 * @v usbep EFI USB endpoint
245 */
246 static void efi_usb_close ( struct efi_usb_endpoint *usbep ) {
247 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
248 struct efi_usb_interface *usbintf = usbep->usbintf;
249 struct efi_usb_device *usbdev = usbintf->usbdev;
250 unsigned int index = USB_ENDPOINT_IDX ( usbep->ep.address );
251
252 /* Sanity check */
253 assert ( usbintf->endpoint[index] == usbep );
254
255 /* Cancel timer (if applicable) and close event */
256 bs->SetTimer ( usbep->event, TimerCancel, 0 );
257 bs->CloseEvent ( usbep->event );
258
259 /* Close endpoint */
260 usb_endpoint_close ( &usbep->ep );
261 DBGC ( usbdev, "USBDEV %s %s closed\n",
262 usbintf->name, usb_endpoint_name ( &usbep->ep ) );
263
264 /* Free endpoint */
265 free ( usbep );
266
267 /* Record closed endpoint */
268 usbintf->endpoint[index] = NULL;
269 }
270
271 /**
272 * Close all endpoints
273 *
274 * @v usbintf EFI USB interface
275 */
276 static void efi_usb_close_all ( struct efi_usb_interface *usbintf ) {
277 struct efi_usb_endpoint *usbep;
278 unsigned int i;
279
280 for ( i = 0 ; i < ( sizeof ( usbintf->endpoint ) /
281 sizeof ( usbintf->endpoint[0] ) ) ; i++ ) {
282 usbep = usbintf->endpoint[i];
283 if ( usbep )
284 efi_usb_close ( usbep );
285 }
286 }
287
288 /**
289 * Complete synchronous transfer
290 *
291 * @v ep USB endpoint
292 * @v iobuf I/O buffer
293 * @v rc Completion status code
294 */
295 static void efi_usb_sync_complete ( struct usb_endpoint *ep,
296 struct io_buffer *iobuf __unused, int rc ) {
297 struct efi_usb_endpoint *usbep =
298 container_of ( ep, struct efi_usb_endpoint, ep );
299
300 /* Record completion status */
301 usbep->rc = rc;
302 }
303
304 /** Synchronous endpoint operations */
305 static struct usb_endpoint_driver_operations efi_usb_sync_driver = {
306 .complete = efi_usb_sync_complete,
307 };
308
309 /**
310 * Perform synchronous transfer
311 *
312 * @v usbintf USB endpoint
313 * @v endpoint Endpoint address
314 * @v attributes Endpoint attributes
315 * @v timeout Timeout (in milliseconds)
316 * @v data Data buffer
317 * @v len Length of data buffer
318 * @ret rc Return status code
319 */
320 static int efi_usb_sync_transfer ( struct efi_usb_interface *usbintf,
321 unsigned int endpoint,
322 unsigned int attributes,
323 unsigned int timeout,
324 void *data, size_t *len ) {
325 struct efi_usb_device *usbdev = usbintf->usbdev;
326 struct efi_usb_endpoint *usbep;
327 struct io_buffer *iobuf;
328 unsigned int index = USB_ENDPOINT_IDX ( endpoint );
329 unsigned int i;
330 int rc;
331
332 /* Open endpoint, if applicable */
333 if ( ( ! usbintf->endpoint[index] ) &&
334 ( ( rc = efi_usb_open ( usbintf, endpoint, attributes, 0,
335 &efi_usb_sync_driver ) ) != 0 ) ) {
336 goto err_open;
337 }
338 usbep = usbintf->endpoint[index];
339
340 /* Allocate and construct I/O buffer */
341 iobuf = alloc_iob ( *len );
342 if ( ! iobuf ) {
343 rc = -ENOMEM;
344 goto err_alloc;
345 }
346 iob_put ( iobuf, *len );
347 if ( ! ( endpoint & USB_ENDPOINT_IN ) )
348 memcpy ( iobuf->data, data, *len );
349
350 /* Initialise completion status */
351 usbep->rc = -EINPROGRESS;
352
353 /* Enqueue transfer */
354 if ( ( rc = usb_stream ( &usbep->ep, iobuf, 0 ) ) != 0 ) {
355 DBGC ( usbdev, "USBDEV %s %s could not enqueue: %s\n",
356 usbintf->name, usb_endpoint_name ( &usbep->ep ),
357 strerror ( rc ) );
358 goto err_stream;
359 }
360
361 /* Wait for completion */
362 rc = -ETIMEDOUT;
363 for ( i = 0 ; ( ( timeout == 0 ) || ( i < timeout ) ) ; i++ ) {
364
365 /* Poll bus */
366 efi_usb_poll ( usbdev );
367
368 /* Check for completion */
369 if ( usbep->rc != -EINPROGRESS ) {
370 rc = usbep->rc;
371 break;
372 }
373
374 /* Delay */
375 mdelay ( 1 );
376 }
377
378 /* Check for errors */
379 if ( rc != 0 ) {
380 DBGC ( usbdev, "USBDEV %s %s failed: %s\n", usbintf->name,
381 usb_endpoint_name ( &usbep->ep ), strerror ( rc ) );
382 goto err_completion;
383 }
384
385 /* Copy completion to data buffer, if applicable */
386 assert ( iob_len ( iobuf ) <= *len );
387 if ( endpoint & USB_ENDPOINT_IN )
388 memcpy ( data, iobuf->data, iob_len ( iobuf ) );
389 *len = iob_len ( iobuf );
390
391 /* Free I/O buffer */
392 free_iob ( iobuf );
393
394 /* Leave endpoint open */
395 return 0;
396
397 err_completion:
398 err_stream:
399 free_iob ( iobuf );
400 err_alloc:
401 efi_usb_close ( usbep );
402 err_open:
403 return EFIRC ( rc );
404 }
405
406 /**
407 * Complete asynchronous transfer
408 *
409 * @v ep USB endpoint
410 * @v iobuf I/O buffer
411 * @v rc Completion status code
412 */
413 static void efi_usb_async_complete ( struct usb_endpoint *ep,
414 struct io_buffer *iobuf, int rc ) {
415 struct efi_usb_endpoint *usbep =
416 container_of ( ep, struct efi_usb_endpoint, ep );
417 UINT32 status;
418
419 /* Ignore packets cancelled when the endpoint closes */
420 if ( ! ep->open )
421 goto drop;
422
423 /* Construct status */
424 status = ( ( rc == 0 ) ? 0 : EFI_USB_ERR_STALL );
425
426 /* Report completion */
427 usbep->callback ( iobuf->data, iob_len ( iobuf ), usbep->context,
428 status );
429
430 drop:
431 /* Recycle I/O buffer */
432 usb_recycle ( &usbep->ep, iobuf );
433 }
434
435 /** Asynchronous endpoint operations */
436 static struct usb_endpoint_driver_operations efi_usb_async_driver = {
437 .complete = efi_usb_async_complete,
438 };
439
440 /**
441 * Start asynchronous transfer
442 *
443 * @v usbintf EFI USB interface
444 * @v endpoint Endpoint address
445 * @v interval Interval (in milliseconds)
446 * @v len Transfer length
447 * @v callback Callback function
448 * @v context Context for callback function
449 * @ret rc Return status code
450 */
451 static int efi_usb_async_start ( struct efi_usb_interface *usbintf,
452 unsigned int endpoint, unsigned int interval,
453 size_t len,
454 EFI_ASYNC_USB_TRANSFER_CALLBACK callback,
455 void *context ) {
456 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
457 struct efi_usb_device *usbdev = usbintf->usbdev;
458 struct efi_usb_endpoint *usbep;
459 unsigned int index = USB_ENDPOINT_IDX ( endpoint );
460 EFI_STATUS efirc;
461 int rc;
462
463 /* Open endpoint */
464 if ( ( rc = efi_usb_open ( usbintf, endpoint,
465 USB_ENDPOINT_ATTR_INTERRUPT, interval,
466 &efi_usb_async_driver ) ) != 0 )
467 goto err_open;
468 usbep = usbintf->endpoint[index];
469
470 /* Record callback parameters */
471 usbep->callback = callback;
472 usbep->context = context;
473
474 /* Prefill endpoint */
475 usb_refill_init ( &usbep->ep, 0, len, EFI_USB_ASYNC_FILL );
476 if ( ( rc = usb_prefill ( &usbep->ep ) ) != 0 ) {
477 DBGC ( usbdev, "USBDEV %s %s could not prefill: %s\n",
478 usbintf->name, usb_endpoint_name ( &usbep->ep ),
479 strerror ( rc ) );
480 goto err_prefill;
481 }
482
483 /* Start timer */
484 if ( ( efirc = bs->SetTimer ( usbep->event, TimerPeriodic,
485 ( interval * 10000 ) ) ) != 0 ) {
486 rc = -EEFI ( efirc );
487 DBGC ( usbdev, "USBDEV %s %s could not set timer: %s\n",
488 usbintf->name, usb_endpoint_name ( &usbep->ep ),
489 strerror ( rc ) );
490 goto err_timer;
491 }
492
493 return 0;
494
495 bs->SetTimer ( usbep->event, TimerCancel, 0 );
496 err_timer:
497 err_prefill:
498 efi_usb_close ( usbep );
499 err_open:
500 return rc;
501 }
502
503 /**
504 * Stop asynchronous transfer
505 *
506 * @v usbintf EFI USB interface
507 * @v endpoint Endpoint address
508 */
509 static void efi_usb_async_stop ( struct efi_usb_interface *usbintf,
510 unsigned int endpoint ) {
511 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
512 struct efi_usb_endpoint *usbep;
513 unsigned int index = USB_ENDPOINT_IDX ( endpoint );
514
515 /* Do nothing if endpoint is already closed */
516 usbep = usbintf->endpoint[index];
517 if ( ! usbep )
518 return;
519
520 /* Stop timer */
521 bs->SetTimer ( usbep->event, TimerCancel, 0 );
522
523 /* Close endpoint */
524 efi_usb_close ( usbep );
525 }
526
527 /******************************************************************************
528 *
529 * USB I/O protocol
530 *
531 ******************************************************************************
532 */
533
534 /**
535 * Perform control transfer
536 *
537 * @v usbio USB I/O protocol
538 * @v packet Setup packet
539 * @v direction Data direction
540 * @v timeout Timeout (in milliseconds)
541 * @v data Data buffer
542 * @v len Length of data
543 * @ret status Transfer status
544 * @ret efirc EFI status code
545 */
546 static EFI_STATUS EFIAPI
547 efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio,
548 EFI_USB_DEVICE_REQUEST *packet,
549 EFI_USB_DATA_DIRECTION direction,
550 UINT32 timeout, VOID *data, UINTN len,
551 UINT32 *status ) {
552 struct efi_usb_interface *usbintf =
553 container_of ( usbio, struct efi_usb_interface, usbio );
554 struct efi_usb_device *usbdev = usbintf->usbdev;
555 unsigned int request = ( packet->RequestType |
556 USB_REQUEST_TYPE ( packet->Request ) );
557 unsigned int value = le16_to_cpu ( packet->Value );
558 unsigned int index = le16_to_cpu ( packet->Index );
559 int rc;
560
561 DBGC2 ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %s %dms "
562 "%p+%zx\n", usbintf->name, request, value, index,
563 le16_to_cpu ( packet->Length ),
564 efi_usb_direction_name ( direction ), timeout, data,
565 ( ( size_t ) len ) );
566
567 /* Clear status */
568 *status = 0;
569
570 /* Block attempts to change the device configuration, since
571 * this is logically impossible to do given the constraints of
572 * the EFI_USB_IO_PROTOCOL design.
573 */
574 if ( ( request == USB_SET_CONFIGURATION ) &&
575 ( value != usbdev->config->config ) ) {
576 DBGC ( usbdev, "USBDEV %s cannot set configuration %d: not "
577 "logically possible\n", usbintf->name, index );
578 rc = -ENOTSUP;
579 goto err_change_config;
580 }
581
582 /* If we are selecting a new alternate setting then close all
583 * open endpoints.
584 */
585 if ( ( request == USB_SET_INTERFACE ) &&
586 ( value != usbintf->alternate ) )
587 efi_usb_close_all ( usbintf );
588
589 /* Issue control transfer */
590 if ( ( rc = usb_control ( usbdev->usb, request, value, index,
591 data, len ) ) != 0 ) {
592 DBGC ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %p+%zx "
593 "failed: %s\n", usbintf->name, request, value, index,
594 le16_to_cpu ( packet->Length ), data, ( ( size_t ) len ),
595 strerror ( rc ) );
596 /* Assume that any error represents a stall */
597 *status = EFI_USB_ERR_STALL;
598 goto err_control;
599 }
600
601 /* Update alternate setting, if applicable */
602 if ( request == USB_SET_INTERFACE ) {
603 usbintf->alternate = value;
604 DBGC ( usbdev, "USBDEV %s alt %d selected\n",
605 usbintf->name, usbintf->alternate );
606 }
607
608 err_control:
609 err_change_config:
610 return EFIRC ( rc );
611 }
612
613 /**
614 * Perform bulk transfer
615 *
616 * @v usbio USB I/O protocol
617 * @v endpoint Endpoint address
618 * @v data Data buffer
619 * @v len Length of data
620 * @v timeout Timeout (in milliseconds)
621 * @ret status Transfer status
622 * @ret efirc EFI status code
623 */
624 static EFI_STATUS EFIAPI
625 efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data,
626 UINTN *len, UINTN timeout, UINT32 *status ) {
627 struct efi_usb_interface *usbintf =
628 container_of ( usbio, struct efi_usb_interface, usbio );
629 struct efi_usb_device *usbdev = usbintf->usbdev;
630 size_t actual = *len;
631 int rc;
632
633 DBGC2 ( usbdev, "USBDEV %s bulk %s %p+%zx %dms\n", usbintf->name,
634 ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
635 ( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
636
637 /* Clear status */
638 *status = 0;
639
640 /* Perform synchronous transfer */
641 if ( ( rc = efi_usb_sync_transfer ( usbintf, endpoint,
642 USB_ENDPOINT_ATTR_BULK, timeout,
643 data, &actual ) ) != 0 ) {
644 /* Assume that any error represents a timeout */
645 *status = EFI_USB_ERR_TIMEOUT;
646 return rc;
647 }
648
649 return 0;
650 }
651
652 /**
653 * Perform synchronous interrupt transfer
654 *
655 * @v usbio USB I/O protocol
656 * @v endpoint Endpoint address
657 * @v data Data buffer
658 * @v len Length of data
659 * @v timeout Timeout (in milliseconds)
660 * @ret status Transfer status
661 * @ret efirc EFI status code
662 */
663 static EFI_STATUS EFIAPI
664 efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
665 VOID *data, UINTN *len, UINTN timeout,
666 UINT32 *status ) {
667 struct efi_usb_interface *usbintf =
668 container_of ( usbio, struct efi_usb_interface, usbio );
669 struct efi_usb_device *usbdev = usbintf->usbdev;
670 size_t actual = *len;
671 int rc;
672
673 DBGC2 ( usbdev, "USBDEV %s sync intr %s %p+%zx %dms\n", usbintf->name,
674 ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
675 ( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
676
677 /* Clear status */
678 *status = 0;
679
680 /* Perform synchronous transfer */
681 if ( ( rc = efi_usb_sync_transfer ( usbintf, endpoint,
682 USB_ENDPOINT_ATTR_INTERRUPT,
683 timeout, data, &actual ) ) != 0 ) {
684 /* Assume that any error represents a timeout */
685 *status = EFI_USB_ERR_TIMEOUT;
686 return rc;
687 }
688
689 return 0;
690 }
691
692 /**
693 * Perform asynchronous interrupt transfer
694 *
695 * @v usbio USB I/O protocol
696 * @v endpoint Endpoint address
697 * @v start Start (rather than stop) transfer
698 * @v interval Polling interval (in milliseconds)
699 * @v len Data length
700 * @v callback Callback function
701 * @v context Context for callback function
702 * @ret efirc EFI status code
703 */
704 static EFI_STATUS EFIAPI
705 efi_usb_async_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
706 BOOLEAN start, UINTN interval, UINTN len,
707 EFI_ASYNC_USB_TRANSFER_CALLBACK callback,
708 VOID *context ) {
709 struct efi_usb_interface *usbintf =
710 container_of ( usbio, struct efi_usb_interface, usbio );
711 struct efi_usb_device *usbdev = usbintf->usbdev;
712 int rc;
713
714 DBGC2 ( usbdev, "USBDEV %s async intr %s len %#zx int %d %p/%p\n",
715 usbintf->name,
716 ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ),
717 ( ( size_t ) len ), ( ( unsigned int ) interval ),
718 callback, context );
719
720 /* Start/stop transfer as applicable */
721 if ( start ) {
722
723 /* Start new transfer */
724 if ( ( rc = efi_usb_async_start ( usbintf, endpoint, interval,
725 len, callback,
726 context ) ) != 0 )
727 goto err_start;
728
729 } else {
730
731 /* Stop transfer */
732 efi_usb_async_stop ( usbintf, endpoint );
733
734 }
735
736 return 0;
737
738 err_start:
739 return EFIRC ( rc );
740 }
741
742 /**
743 * Perform synchronous isochronous transfer
744 *
745 * @v usbio USB I/O protocol
746 * @v endpoint Endpoint address
747 * @v data Data buffer
748 * @v len Length of data
749 * @ret status Transfer status
750 * @ret efirc EFI status code
751 */
752 static EFI_STATUS EFIAPI
753 efi_usb_isochronous_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
754 VOID *data, UINTN len, UINT32 *status ) {
755 struct efi_usb_interface *usbintf =
756 container_of ( usbio, struct efi_usb_interface, usbio );
757 struct efi_usb_device *usbdev = usbintf->usbdev;
758
759 DBGC2 ( usbdev, "USBDEV %s sync iso %s %p+%zx\n", usbintf->name,
760 ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
761 ( ( size_t ) len ) );
762
763 /* Clear status */
764 *status = 0;
765
766 /* Not supported */
767 return EFI_UNSUPPORTED;
768 }
769
770 /**
771 * Perform asynchronous isochronous transfers
772 *
773 * @v usbio USB I/O protocol
774 * @v endpoint Endpoint address
775 * @v data Data buffer
776 * @v len Length of data
777 * @v callback Callback function
778 * @v context Context for callback function
779 * @ret status Transfer status
780 * @ret efirc EFI status code
781 */
782 static EFI_STATUS EFIAPI
783 efi_usb_async_isochronous_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
784 VOID *data, UINTN len,
785 EFI_ASYNC_USB_TRANSFER_CALLBACK callback,
786 VOID *context ) {
787 struct efi_usb_interface *usbintf =
788 container_of ( usbio, struct efi_usb_interface, usbio );
789 struct efi_usb_device *usbdev = usbintf->usbdev;
790
791 DBGC2 ( usbdev, "USBDEV %s async iso %s %p+%zx %p/%p\n", usbintf->name,
792 ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
793 ( ( size_t ) len ), callback, context );
794
795 /* Not supported */
796 return EFI_UNSUPPORTED;
797 }
798
799 /**
800 * Get device descriptor
801 *
802 * @v usbio USB I/O protocol
803 * @ret efidesc EFI device descriptor
804 * @ret efirc EFI status code
805 */
806 static EFI_STATUS EFIAPI
807 efi_usb_get_device_descriptor ( EFI_USB_IO_PROTOCOL *usbio,
808 EFI_USB_DEVICE_DESCRIPTOR *efidesc ) {
809 struct efi_usb_interface *usbintf =
810 container_of ( usbio, struct efi_usb_interface, usbio );
811 struct efi_usb_device *usbdev = usbintf->usbdev;
812
813 DBGC2 ( usbdev, "USBDEV %s get device descriptor\n", usbintf->name );
814
815 /* Copy cached device descriptor */
816 memcpy ( efidesc, &usbdev->usb->device, sizeof ( *efidesc ) );
817
818 return 0;
819 }
820
821 /**
822 * Get configuration descriptor
823 *
824 * @v usbio USB I/O protocol
825 * @ret efidesc EFI interface descriptor
826 * @ret efirc EFI status code
827 */
828 static EFI_STATUS EFIAPI
829 efi_usb_get_config_descriptor ( EFI_USB_IO_PROTOCOL *usbio,
830 EFI_USB_CONFIG_DESCRIPTOR *efidesc ) {
831 struct efi_usb_interface *usbintf =
832 container_of ( usbio, struct efi_usb_interface, usbio );
833 struct efi_usb_device *usbdev = usbintf->usbdev;
834
835 DBGC2 ( usbdev, "USBDEV %s get configuration descriptor\n",
836 usbintf->name );
837
838 /* Copy cached configuration descriptor */
839 memcpy ( efidesc, usbdev->config, sizeof ( *efidesc ) );
840
841 return 0;
842 }
843
844 /**
845 * Get interface descriptor
846 *
847 * @v usbio USB I/O protocol
848 * @ret efidesc EFI interface descriptor
849 * @ret efirc EFI status code
850 */
851 static EFI_STATUS EFIAPI
852 efi_usb_get_interface_descriptor ( EFI_USB_IO_PROTOCOL *usbio,
853 EFI_USB_INTERFACE_DESCRIPTOR *efidesc ) {
854 struct efi_usb_interface *usbintf =
855 container_of ( usbio, struct efi_usb_interface, usbio );
856 struct efi_usb_device *usbdev = usbintf->usbdev;
857 struct usb_interface_descriptor *desc;
858
859 DBGC2 ( usbdev, "USBDEV %s get interface descriptor\n", usbintf->name );
860
861 /* Locate cached interface descriptor */
862 desc = usb_interface_descriptor ( usbdev->config, usbintf->interface,
863 usbintf->alternate );
864 if ( ! desc ) {
865 DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n",
866 usbintf->name, usbintf->alternate );
867 return -ENOENT;
868 }
869
870 /* Copy cached interface descriptor */
871 memcpy ( efidesc, desc, sizeof ( *efidesc ) );
872
873 return 0;
874 }
875
876 /**
877 * Get endpoint descriptor
878 *
879 * @v usbio USB I/O protocol
880 * @v address Endpoint index
881 * @ret efidesc EFI interface descriptor
882 * @ret efirc EFI status code
883 */
884 static EFI_STATUS EFIAPI
885 efi_usb_get_endpoint_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT8 index,
886 EFI_USB_ENDPOINT_DESCRIPTOR *efidesc ) {
887 struct efi_usb_interface *usbintf =
888 container_of ( usbio, struct efi_usb_interface, usbio );
889 struct efi_usb_device *usbdev = usbintf->usbdev;
890 struct usb_interface_descriptor *interface;
891 struct usb_endpoint_descriptor *desc;
892
893 DBGC2 ( usbdev, "USBDEV %s get endpoint %d descriptor\n",
894 usbintf->name, index );
895
896 /* Locate cached interface descriptor */
897 interface = usb_interface_descriptor ( usbdev->config,
898 usbintf->interface,
899 usbintf->alternate );
900 if ( ! interface ) {
901 DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n",
902 usbintf->name, usbintf->alternate );
903 return -ENOENT;
904 }
905
906 /* Locate and copy cached endpoint descriptor */
907 for_each_interface_descriptor ( desc, usbdev->config, interface ) {
908 if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) &&
909 ( index-- == 0 ) ) {
910 memcpy ( efidesc, desc, sizeof ( *efidesc ) );
911 return 0;
912 }
913 }
914 return -ENOENT;
915 }
916
917 /**
918 * Get string descriptor
919 *
920 * @v usbio USB I/O protocol
921 * @v language Language ID
922 * @v index String index
923 * @ret string String
924 * @ret efirc EFI status code
925 */
926 static EFI_STATUS EFIAPI
927 efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language,
928 UINT8 index, CHAR16 **string ) {
929 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
930 struct efi_usb_interface *usbintf =
931 container_of ( usbio, struct efi_usb_interface, usbio );
932 struct efi_usb_device *usbdev = usbintf->usbdev;
933 struct usb_descriptor_header header;
934 VOID *buffer;
935 size_t len;
936 EFI_STATUS efirc;
937 int rc;
938
939 DBGC2 ( usbdev, "USBDEV %s get string %d:%d descriptor\n",
940 usbintf->name, language, index );
941
942 /* Read descriptor header */
943 if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR,
944 index, language, &header,
945 sizeof ( header ) ) ) != 0 ) {
946 DBGC ( usbdev, "USBDEV %s could not get string %d:%d "
947 "descriptor header: %s\n", usbintf->name, language,
948 index, strerror ( rc ) );
949 goto err_get_header;
950 }
951 len = header.len;
952
953 /* Allocate buffer */
954 if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, len,
955 &buffer ) ) != 0 ) {
956 rc = -EEFI ( efirc );
957 goto err_alloc;
958 }
959
960 /* Read whole descriptor */
961 if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR,
962 index, language, buffer,
963 len ) ) != 0 ) {
964 DBGC ( usbdev, "USBDEV %s could not get string %d:%d "
965 "descriptor: %s\n", usbintf->name, language,
966 index, strerror ( rc ) );
967 goto err_get_descriptor;
968 }
969
970 /* Shuffle down and terminate string */
971 memmove ( buffer, ( buffer + sizeof ( header ) ),
972 ( len - sizeof ( header ) ) );
973 memset ( ( buffer + len - sizeof ( header ) ), 0, sizeof ( **string ) );
974
975 /* Return allocated string */
976 *string = buffer;
977 return 0;
978
979 err_get_descriptor:
980 bs->FreePool ( buffer );
981 err_alloc:
982 err_get_header:
983 return EFIRC ( rc );
984 }
985
986 /**
987 * Get supported languages
988 *
989 * @v usbio USB I/O protocol
990 * @ret languages Language ID table
991 * @ret len Length of language ID table
992 * @ret efirc EFI status code
993 */
994 static EFI_STATUS EFIAPI
995 efi_usb_get_supported_languages ( EFI_USB_IO_PROTOCOL *usbio,
996 UINT16 **languages, UINT16 *len ) {
997 struct efi_usb_interface *usbintf =
998 container_of ( usbio, struct efi_usb_interface, usbio );
999 struct efi_usb_device *usbdev = usbintf->usbdev;
1000
1001 DBGC2 ( usbdev, "USBDEV %s get supported languages\n", usbintf->name );
1002
1003 /* Return cached supported languages */
1004 *languages = ( ( ( void * ) usbdev->languages ) +
1005 sizeof ( *(usbdev->languages) ) );
1006 *len = usbdev->languages->len;
1007
1008 return 0;
1009 }
1010
1011 /**
1012 * Reset port
1013 *
1014 * @v usbio USB I/O protocol
1015 * @ret efirc EFI status code
1016 */
1017 static EFI_STATUS EFIAPI
1018 efi_usb_port_reset ( EFI_USB_IO_PROTOCOL *usbio ) {
1019 struct efi_usb_interface *usbintf =
1020 container_of ( usbio, struct efi_usb_interface, usbio );
1021 struct efi_usb_device *usbdev = usbintf->usbdev;
1022
1023 DBGC2 ( usbdev, "USBDEV %s reset port\n", usbintf->name );
1024
1025 /* This is logically impossible to do, since resetting the
1026 * port may destroy state belonging to other
1027 * EFI_USB_IO_PROTOCOL instances belonging to the same USB
1028 * device. (This is yet another artifact of the incredibly
1029 * poor design of the EFI_USB_IO_PROTOCOL.)
1030 */
1031 return EFI_INVALID_PARAMETER;
1032 }
1033
1034 /** USB I/O protocol */
1035 static EFI_USB_IO_PROTOCOL efi_usb_io_protocol = {
1036 .UsbControlTransfer = efi_usb_control_transfer,
1037 .UsbBulkTransfer = efi_usb_bulk_transfer,
1038 .UsbAsyncInterruptTransfer = efi_usb_async_interrupt_transfer,
1039 .UsbSyncInterruptTransfer = efi_usb_sync_interrupt_transfer,
1040 .UsbIsochronousTransfer = efi_usb_isochronous_transfer,
1041 .UsbAsyncIsochronousTransfer = efi_usb_async_isochronous_transfer,
1042 .UsbGetDeviceDescriptor = efi_usb_get_device_descriptor,
1043 .UsbGetConfigDescriptor = efi_usb_get_config_descriptor,
1044 .UsbGetInterfaceDescriptor = efi_usb_get_interface_descriptor,
1045 .UsbGetEndpointDescriptor = efi_usb_get_endpoint_descriptor,
1046 .UsbGetStringDescriptor = efi_usb_get_string_descriptor,
1047 .UsbGetSupportedLanguages = efi_usb_get_supported_languages,
1048 .UsbPortReset = efi_usb_port_reset,
1049 };
1050
1051 /******************************************************************************
1052 *
1053 * USB driver
1054 *
1055 ******************************************************************************
1056 */
1057
1058 /**
1059 * Install interface
1060 *
1061 * @v usbdev EFI USB device
1062 * @v interface Interface number
1063 * @ret rc Return status code
1064 */
1065 static int efi_usb_install ( struct efi_usb_device *usbdev,
1066 unsigned int interface ) {
1067 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1068 struct efi_device *efidev = usbdev->efidev;
1069 struct efi_usb_interface *usbintf;
1070 struct usb_device *usb;
1071 EFI_DEVICE_PATH_PROTOCOL *path_end;
1072 USB_DEVICE_PATH *usbpath;
1073 unsigned int path_count;
1074 size_t path_prefix_len;
1075 size_t path_len;
1076 EFI_STATUS efirc;
1077 int rc;
1078
1079 /* Calculate device path length */
1080 path_count = ( usb_depth ( usbdev->usb ) + 1 );
1081 path_prefix_len = efi_devpath_len ( efidev->path );
1082 path_len = ( path_prefix_len + ( path_count * sizeof ( *usbpath ) ) +
1083 sizeof ( *path_end ) );
1084
1085 /* Allocate and initialise structure */
1086 usbintf = zalloc ( sizeof ( *usbintf ) + path_len );
1087 if ( ! usbintf ) {
1088 rc = -ENOMEM;
1089 goto err_alloc;
1090 }
1091 snprintf ( usbintf->name, sizeof ( usbintf->name ), "%s[%d]",
1092 usbdev->name, interface );
1093 usbintf->usbdev = usbdev;
1094 usbintf->interface = interface;
1095 memcpy ( &usbintf->usbio, &efi_usb_io_protocol,
1096 sizeof ( usbintf->usbio ) );
1097 usbintf->path = ( ( ( void * ) usbintf ) + sizeof ( *usbintf ) );
1098
1099 /* Construct device path */
1100 memcpy ( usbintf->path, efidev->path, path_prefix_len );
1101 path_end = ( ( ( void * ) usbintf->path ) + path_len -
1102 sizeof ( *path_end ) );
1103 path_end->Type = END_DEVICE_PATH_TYPE;
1104 path_end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
1105 path_end->Length[0] = sizeof ( *path_end );
1106 usbpath = ( ( ( void * ) path_end ) - sizeof ( *usbpath ) );
1107 usbpath->InterfaceNumber = interface;
1108 for ( usb = usbdev->usb ; usb ; usbpath--, usb = usb->port->hub->usb ) {
1109 usbpath->Header.Type = MESSAGING_DEVICE_PATH;
1110 usbpath->Header.SubType = MSG_USB_DP;
1111 usbpath->Header.Length[0] = sizeof ( *usbpath );
1112 usbpath->ParentPortNumber = usb->port->address;
1113 }
1114
1115 /* Add to list of interfaces */
1116 list_add_tail ( &usbintf->list, &usbdev->interfaces );
1117
1118 /* Install protocols */
1119 if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1120 &usbintf->handle,
1121 &efi_usb_io_protocol_guid, &usbintf->usbio,
1122 &efi_device_path_protocol_guid, usbintf->path,
1123 NULL ) ) != 0 ) {
1124 rc = -EEFI ( efirc );
1125 DBGC ( usbdev, "USBDEV %s could not install protocols: %s\n",
1126 usbintf->name, strerror ( rc ) );
1127 goto err_install_protocol;
1128 }
1129
1130 DBGC ( usbdev, "USBDEV %s installed as %s\n",
1131 usbintf->name, efi_handle_name ( usbintf->handle ) );
1132 return 0;
1133
1134 efi_usb_close_all ( usbintf );
1135 bs->UninstallMultipleProtocolInterfaces (
1136 usbintf->handle,
1137 &efi_usb_io_protocol_guid, &usbintf->usbio,
1138 &efi_device_path_protocol_guid, usbintf->path,
1139 NULL );
1140 err_install_protocol:
1141 list_del ( &usbintf->list );
1142 free ( usbintf );
1143 err_alloc:
1144 return rc;
1145 }
1146
1147 /**
1148 * Uninstall interface
1149 *
1150 * @v usbintf EFI USB interface
1151 */
1152 static void efi_usb_uninstall ( struct efi_usb_interface *usbintf ) {
1153 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1154
1155 /* Close all endpoints */
1156 efi_usb_close_all ( usbintf );
1157
1158 /* Uninstall protocols */
1159 bs->UninstallMultipleProtocolInterfaces (
1160 usbintf->handle,
1161 &efi_usb_io_protocol_guid, &usbintf->usbio,
1162 &efi_device_path_protocol_guid, usbintf->path,
1163 NULL );
1164
1165 /* Remove from list of interfaces */
1166 list_del ( &usbintf->list );
1167
1168 /* Free interface */
1169 free ( usbintf );
1170 }
1171
1172 /**
1173 * Uninstall all interfaces
1174 *
1175 * @v usbdev EFI USB device
1176 */
1177 static void efi_usb_uninstall_all ( struct efi_usb_device *efiusb ) {
1178 struct efi_usb_interface *usbintf;
1179
1180 /* Uninstall all interfaces */
1181 while ( ( usbintf = list_first_entry ( &efiusb->interfaces,
1182 struct efi_usb_interface,
1183 list ) ) ) {
1184 efi_usb_uninstall ( usbintf );
1185 }
1186 }
1187
1188 /**
1189 * Probe device
1190 *
1191 * @v func USB function
1192 * @v config Configuration descriptor
1193 * @ret rc Return status code
1194 */
1195 static int efi_usb_probe ( struct usb_function *func,
1196 struct usb_configuration_descriptor *config ) {
1197 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1198 struct usb_device *usb = func->usb;
1199 struct efi_usb_device *usbdev;
1200 struct efi_usb_interface *usbintf;
1201 struct efi_device *efidev;
1202 struct usb_descriptor_header header;
1203 size_t config_len;
1204 unsigned int i;
1205 int rc;
1206
1207 /* Find parent EFI device */
1208 efidev = efidev_parent ( &func->dev );
1209 if ( ! efidev ) {
1210 rc = -ENOTTY;
1211 goto err_no_efidev;
1212 }
1213
1214 /* Get configuration length */
1215 config_len = le16_to_cpu ( config->len );
1216
1217 /* Get supported languages descriptor header */
1218 if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, 0, 0,
1219 &header, sizeof ( header ) ) ) != 0 ) {
1220 /* Assume no strings are present */
1221 header.len = 0;
1222 }
1223
1224 /* Allocate and initialise structure */
1225 usbdev = zalloc ( sizeof ( *usbdev ) + config_len + header.len );
1226 if ( ! usbdev ) {
1227 rc = -ENOMEM;
1228 goto err_alloc;
1229 }
1230 usb_func_set_drvdata ( func, usbdev );
1231 usbdev->name = func->name;
1232 usbdev->usb = usb;
1233 usbdev->efidev = efidev;
1234 usbdev->config = ( ( ( void * ) usbdev ) + sizeof ( *usbdev ) );
1235 memcpy ( usbdev->config, config, config_len );
1236 usbdev->languages = ( ( ( void * ) usbdev->config ) + config_len );
1237 INIT_LIST_HEAD ( &usbdev->interfaces );
1238
1239 /* Get supported languages descriptor */
1240 if ( header.len &&
1241 ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, 0, 0,
1242 usbdev->languages,
1243 header.len ) ) != 0 ) {
1244 DBGC ( usbdev, "USBDEV %s could not get supported languages: "
1245 "%s\n", usbdev->name, strerror ( rc ) );
1246 goto err_get_languages;
1247 }
1248
1249 /* Install interfaces */
1250 for ( i = 0 ; i < func->desc.count ; i++ ) {
1251 if ( ( rc = efi_usb_install ( usbdev,
1252 func->interface[i] ) ) != 0 )
1253 goto err_install;
1254 }
1255
1256 /* Connect any external drivers */
1257 list_for_each_entry ( usbintf, &usbdev->interfaces, list )
1258 bs->ConnectController ( usbintf->handle, NULL, NULL, TRUE );
1259
1260 return 0;
1261
1262 err_install:
1263 efi_usb_uninstall_all ( usbdev );
1264 assert ( list_empty ( &usbdev->interfaces ) );
1265 err_get_languages:
1266 free ( usbdev );
1267 err_alloc:
1268 err_no_efidev:
1269 return rc;
1270 }
1271
1272 /**
1273 * Remove device
1274 *
1275 * @v func USB function
1276 */
1277 static void efi_usb_remove ( struct usb_function *func ) {
1278 struct efi_usb_device *usbdev = usb_func_get_drvdata ( func );
1279
1280 /* Uninstall all interfaces */
1281 efi_usb_uninstall_all ( usbdev );
1282 assert ( list_empty ( &usbdev->interfaces ) );
1283
1284 /* Free device */
1285 free ( usbdev );
1286 }
1287
1288 /** USB I/O protocol device IDs */
1289 static struct usb_device_id efi_usb_ids[] = {
1290 {
1291 .name = "usbio",
1292 .vendor = USB_ANY_ID,
1293 .product = USB_ANY_ID,
1294 },
1295 };
1296
1297 /** USB I/O protocol driver */
1298 struct usb_driver usbio_driver __usb_driver = {
1299 .ids = efi_usb_ids,
1300 .id_count = ( sizeof ( efi_usb_ids ) / sizeof ( efi_usb_ids[0] ) ),
1301 .class = USB_CLASS_ID ( USB_ANY_ID, USB_ANY_ID, USB_ANY_ID ),
1302 .score = USB_SCORE_FALLBACK,
1303 .probe = efi_usb_probe,
1304 .remove = efi_usb_remove,
1305 };