3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 USB I/O Abstraction Driver
27 // USB I/O Support Function Prototypes
33 IN EFI_USB_IO_PROTOCOL
*This
,
34 IN EFI_USB_DEVICE_REQUEST
*Request
,
35 IN EFI_USB_DATA_DIRECTION Direction
,
37 IN OUT VOID
*Data
, OPTIONAL
38 IN UINTN DataLength
, OPTIONAL
46 IN EFI_USB_IO_PROTOCOL
*This
,
47 IN UINT8 DeviceEndpoint
,
49 IN OUT UINTN
*DataLength
,
57 UsbAsyncInterruptTransfer (
58 IN EFI_USB_IO_PROTOCOL
* This
,
59 IN UINT8 DeviceEndpoint
,
60 IN BOOLEAN IsNewTransfer
,
61 IN UINTN PollingInterval
, OPTIONAL
62 IN UINTN DataLength
, OPTIONAL
63 IN EFI_ASYNC_USB_TRANSFER_CALLBACK InterruptCallBack
, OPTIONAL
64 IN VOID
*Context OPTIONAL
70 UsbSyncInterruptTransfer (
71 IN EFI_USB_IO_PROTOCOL
*This
,
72 IN UINT8 DeviceEndpoint
,
74 IN OUT UINTN
*DataLength
,
82 UsbIsochronousTransfer (
83 IN EFI_USB_IO_PROTOCOL
*This
,
84 IN UINT8 DeviceEndpoint
,
93 UsbAsyncIsochronousTransfer (
94 IN EFI_USB_IO_PROTOCOL
* This
,
95 IN UINT8 DeviceEndpoint
,
98 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
99 IN VOID
*Context OPTIONAL
106 IN EFI_USB_IO_PROTOCOL
*This
112 UsbGetDeviceDescriptor (
113 IN EFI_USB_IO_PROTOCOL
*This
,
114 OUT EFI_USB_DEVICE_DESCRIPTOR
*DeviceDescriptor
120 UsbGetActiveConfigDescriptor (
121 IN EFI_USB_IO_PROTOCOL
*This
,
122 OUT EFI_USB_CONFIG_DESCRIPTOR
*ConfigurationDescriptor
128 UsbGetInterfaceDescriptor (
129 IN EFI_USB_IO_PROTOCOL
*This
,
130 OUT EFI_USB_INTERFACE_DESCRIPTOR
*InterfaceDescriptor
136 UsbGetEndpointDescriptor (
137 IN EFI_USB_IO_PROTOCOL
*This
,
138 IN UINT8 EndpointIndex
,
139 OUT EFI_USB_ENDPOINT_DESCRIPTOR
*EndpointDescriptor
145 UsbGetStringDescriptor (
146 IN EFI_USB_IO_PROTOCOL
*This
,
148 IN UINT8 StringIndex
,
155 UsbGetSupportedLanguages (
156 IN EFI_USB_IO_PROTOCOL
*This
,
157 OUT UINT16
**LangIDTable
,
158 OUT UINT16
*TableSize
162 // USB I/O Interface structure
164 STATIC EFI_USB_IO_PROTOCOL UsbIoInterface
= {
167 UsbAsyncInterruptTransfer
,
168 UsbSyncInterruptTransfer
,
169 UsbIsochronousTransfer
,
170 UsbAsyncIsochronousTransfer
,
171 UsbGetDeviceDescriptor
,
172 UsbGetActiveConfigDescriptor
,
173 UsbGetInterfaceDescriptor
,
174 UsbGetEndpointDescriptor
,
175 UsbGetStringDescriptor
,
176 UsbGetSupportedLanguages
,
181 InitializeUsbIoInstance (
182 IN USB_IO_CONTROLLER_DEVICE
*UsbIoController
186 // Copy EFI_USB_IO protocol instance
189 &UsbIoController
->UsbIo
,
191 sizeof (EFI_USB_IO_PROTOCOL
)
201 IN EFI_USB_IO_PROTOCOL
*This
,
202 IN EFI_USB_DEVICE_REQUEST
*Request
,
203 IN EFI_USB_DATA_DIRECTION Direction
,
205 IN OUT VOID
*Data
, OPTIONAL
206 IN UINTN DataLength
, OPTIONAL
212 This function is used to manage a USB device with a control transfer pipe.
215 This - Indicates calling context.
216 Request - A pointer to the USB device request that will be sent to
218 Direction - Indicates the data direction.
219 Data - A pointer to the buffer of data that will be transmitted
220 to USB device or received from USB device.
221 Timeout - Indicates the transfer should be completed within this time
223 DataLength - The size, in bytes, of the data buffer specified by Data.
224 Status - A pointer to the result of the USB transfer.
228 EFI_INVALID_PARAMETER
235 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
237 EFI_STATUS RetStatus
;
238 USB_IO_DEVICE
*UsbIoDev
;
239 UINT8 MaxPacketLength
;
240 UINT32 TransferResult
;
241 BOOLEAN Disconnected
;
243 // Parameters Checking
245 if (Status
== NULL
) {
246 return EFI_INVALID_PARAMETER
;
250 // leave the HostController's ControlTransfer
251 // to perform other parameters checking
253 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
254 UsbIoDev
= UsbIoController
->UsbDevice
;
256 MaxPacketLength
= UsbIoDev
->DeviceDescriptor
.MaxPacketSize0
;
259 if (Request
->Request
== USB_DEV_CLEAR_FEATURE
&&
260 Request
->RequestType
== 0x02 &&
261 Request
->Value
== EfiUsbEndpointHalt
) {
263 //Reduce the remove delay time for system response
265 IsDeviceDisconnected (UsbIoController
, &Disconnected
);
266 if (!EFI_ERROR (Status
) && Disconnected
== TRUE
) {
267 DEBUG ((gUSBErrorLevel
, "Device is disconnected when trying reset\n"));
268 return EFI_DEVICE_ERROR
;
272 // using HostController's ControlTransfer to complete the request
274 RetStatus
= UsbVirtualHcControlTransfer (
275 UsbIoDev
->BusController
,
276 UsbIoDev
->DeviceAddress
,
277 UsbIoDev
->DeviceSpeed
,
284 UsbIoDev
->Translator
,
288 *Status
= TransferResult
;
290 if (Request
->Request
== USB_DEV_CLEAR_FEATURE
&&
291 Request
->RequestType
== 0x02 &&
292 Request
->Value
== EfiUsbEndpointHalt
) {
294 // This is a UsbClearEndpointHalt request
295 // Need to clear data toggle
296 // Request.Index == EndpointAddress
298 if (!EFI_ERROR (RetStatus
) && TransferResult
== EFI_USB_NOERROR
) {
301 (UINT8
) Request
->Index
,
313 IN EFI_USB_IO_PROTOCOL
*This
,
314 IN UINT8 DeviceEndpoint
,
316 IN OUT UINTN
*DataLength
,
323 This function is used to manage a USB device with the bulk transfer pipe.
326 This - Indicates calling context.
327 DeviceEndpoint - The destination USB device endpoint to which the device
328 request is being sent.
329 Data - A pointer to the buffer of data that will be transmitted
330 to USB device or received from USB device.
331 DataLength - On input, the size, in bytes, of the data buffer
332 specified by Data. On output, the number of bytes that
333 were actually transferred.
334 Timeout - Indicates the transfer should be completed within this
336 Status - This parameter indicates the USB transfer status.
340 EFI_INVALID_PARAMETER
347 USB_IO_DEVICE
*UsbIoDev
;
348 UINTN MaxPacketLength
;
351 EFI_STATUS RetStatus
;
353 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
354 ENDPOINT_DESC_LIST_ENTRY
*EndPointListEntry
;
355 UINT32 TransferResult
;
356 UINT8 DataBuffersNumber
;
358 DataBuffersNumber
= 1;
359 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
360 UsbIoDev
= UsbIoController
->UsbDevice
;
363 // Parameters Checking
365 if ((DeviceEndpoint
& 0x7F) == 0) {
366 return EFI_INVALID_PARAMETER
;
369 if ((DeviceEndpoint
& 0x7F) > 15) {
370 return EFI_INVALID_PARAMETER
;
373 if (Status
== NULL
) {
374 return EFI_INVALID_PARAMETER
;
377 EndPointListEntry
= FindEndPointListEntry (
382 if (EndPointListEntry
== NULL
) {
383 return EFI_INVALID_PARAMETER
;
386 if ((EndPointListEntry
->EndpointDescriptor
.Attributes
& 0x03) != 0x02) {
387 return EFI_INVALID_PARAMETER
;
391 // leave the HostController's BulkTransfer
392 // to perform other parameters checking
394 GetDeviceEndPointMaxPacketLength (
406 OldToggle
= DataToggle
;
409 // using HostController's BulkTransfer to complete the request
411 RetStatus
= UsbVirtualHcBulkTransfer (
412 UsbIoDev
->BusController
,
413 UsbIoDev
->DeviceAddress
,
415 UsbIoDev
->DeviceSpeed
,
422 UsbIoDev
->Translator
,
426 if (OldToggle
!= DataToggle
) {
428 // Write the toggle back
437 *Status
= TransferResult
;
445 UsbSyncInterruptTransfer (
446 IN EFI_USB_IO_PROTOCOL
*This
,
447 IN UINT8 DeviceEndpoint
,
449 IN OUT UINTN
*DataLength
,
456 Usb Sync Interrupt Transfer
459 This - Indicates calling context.
460 DeviceEndpoint - The destination USB device endpoint to which the device
461 request is being sent.
462 Data - A pointer to the buffer of data that will be transmitted
463 to USB device or received from USB device.
464 DataLength - On input, the size, in bytes, of the data buffer
465 specified by Data. On output, the number of bytes that
466 were actually transferred.
467 Timeout - Indicates the transfer should be completed within this
469 Status - This parameter indicates the USB transfer status.
473 EFI_INVALID_PARAMETER
480 USB_IO_DEVICE
*UsbIoDev
;
481 UINTN MaxPacketLength
;
484 EFI_STATUS RetStatus
;
485 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
486 ENDPOINT_DESC_LIST_ENTRY
*EndPointListEntry
;
489 // Parameters Checking
491 if ((DeviceEndpoint
& 0x7F) == 0) {
492 return EFI_INVALID_PARAMETER
;
495 if ((DeviceEndpoint
& 0x7F) > 15) {
496 return EFI_INVALID_PARAMETER
;
499 if (Status
== NULL
) {
500 return EFI_INVALID_PARAMETER
;
503 EndPointListEntry
= FindEndPointListEntry (
508 if (EndPointListEntry
== NULL
) {
509 return EFI_INVALID_PARAMETER
;
512 if ((EndPointListEntry
->EndpointDescriptor
.Attributes
& 0x03) != 0x03) {
513 return EFI_INVALID_PARAMETER
;
517 // leave the HostController's SyncInterruptTransfer
518 // to perform other parameters checking
520 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
521 UsbIoDev
= UsbIoController
->UsbDevice
;
522 GetDeviceEndPointMaxPacketLength (
534 OldToggle
= DataToggle
;
536 // using HostController's SyncInterruptTransfer to complete the request
538 RetStatus
= UsbVirtualHcSyncInterruptTransfer (
539 UsbIoDev
->BusController
,
540 UsbIoDev
->DeviceAddress
,
542 UsbIoDev
->DeviceSpeed
,
548 UsbIoDev
->Translator
,
552 if (OldToggle
!= DataToggle
) {
554 // Write the toggle back
569 UsbAsyncInterruptTransfer (
570 IN EFI_USB_IO_PROTOCOL
*This
,
571 IN UINT8 DeviceEndpoint
,
572 IN BOOLEAN IsNewTransfer
,
573 IN UINTN PollingInterval
, OPTIONAL
574 IN UINTN DataLength
, OPTIONAL
575 IN EFI_ASYNC_USB_TRANSFER_CALLBACK InterruptCallBack
, OPTIONAL
576 IN VOID
*Context OPTIONAL
581 Usb Async Interrput Transfer
584 This - Indicates calling context.
585 DeviceEndpoint - The destination USB device endpoint to which the
586 device request is being sent.
587 IsNewTransfer - If TRUE, a new transfer will be submitted to USB
588 controller. If FALSE, the interrupt transfer is
589 deleted from the device's interrupt transfer queue.
590 PollingInterval - Indicates the periodic rate, in milliseconds, that
591 the transfer is to be executed.
592 DataLength - Specifies the length, in bytes, of the data to be
593 received from the USB device.
594 InterruptCallBack - The Callback function. This function is called if
595 the asynchronous interrupt transfer is completed.
596 Context - Passed to InterruptCallback
599 EFI_INVALID_PARAMETER
604 USB_IO_DEVICE
*UsbIoDev
;
605 UINTN MaxPacketLength
;
607 EFI_STATUS RetStatus
;
608 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
609 ENDPOINT_DESC_LIST_ENTRY
*EndpointListEntry
;
614 if ((DeviceEndpoint
& 0x7F) == 0) {
615 return EFI_INVALID_PARAMETER
;
618 if ((DeviceEndpoint
& 0x7F) > 15) {
619 return EFI_INVALID_PARAMETER
;
622 EndpointListEntry
= FindEndPointListEntry (
627 if (EndpointListEntry
== NULL
) {
628 return EFI_INVALID_PARAMETER
;
631 if ((EndpointListEntry
->EndpointDescriptor
.Attributes
& 0x03) != 0x03) {
632 return EFI_INVALID_PARAMETER
;
635 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
636 UsbIoDev
= UsbIoController
->UsbDevice
;
638 if (!IsNewTransfer
) {
640 // Delete this transfer
642 UsbVirtualHcAsyncInterruptTransfer (
643 UsbIoDev
->BusController
,
644 UsbIoDev
->DeviceAddress
,
646 UsbIoDev
->DeviceSpeed
,
652 UsbIoDev
->Translator
,
658 // We need to store the toggle value
669 GetDeviceEndPointMaxPacketLength (
681 RetStatus
= UsbVirtualHcAsyncInterruptTransfer (
682 UsbIoDev
->BusController
,
683 UsbIoDev
->DeviceAddress
,
685 UsbIoDev
->DeviceSpeed
,
691 UsbIoDev
->Translator
,
702 UsbIsochronousTransfer (
703 IN EFI_USB_IO_PROTOCOL
*This
,
704 IN UINT8 DeviceEndpoint
,
712 Usb Isochronous Transfer
715 This - Indicates calling context.
716 DeviceEndpoint - The destination USB device endpoint to which the
717 device request is being sent.
718 Data - A pointer to the buffer of data that will be
719 transmitted to USB device or received from USB device.
720 DataLength - The size, in bytes, of the data buffer specified by
722 Status - This parameter indicates the USB transfer status.
726 EFI_INVALID_PARAMETER
734 // Currently we don't support this transfer
736 return EFI_UNSUPPORTED
;
742 UsbAsyncIsochronousTransfer (
743 IN EFI_USB_IO_PROTOCOL
*This
,
744 IN UINT8 DeviceEndpoint
,
747 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
748 IN VOID
*Context OPTIONAL
754 Usb Async Isochronous Transfer
758 This - EFI_USB_IO_PROTOCOL
759 DeviceEndpoint - DeviceEndpoint number
760 Data - Data to transfer
761 DataLength - DataLength
762 IsochronousCallBack - Isochronous CallBack function
763 Context - Passed to IsochronousCallBack function
766 EFI_UNSUPPORTED - Unsupported now
771 // Currently we don't support this transfer
773 return EFI_UNSUPPORTED
;
776 // Here is new definitions
781 UsbGetDeviceDescriptor (
782 IN EFI_USB_IO_PROTOCOL
*This
,
783 OUT EFI_USB_DEVICE_DESCRIPTOR
*DeviceDescriptor
788 Retrieves the USB Device Descriptor.
791 This - Indicates the calling context.
792 DeviceDescriptor - A pointer to the caller allocated USB Device
797 EFI_INVALID_PARAMETER
802 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
803 USB_IO_DEVICE
*UsbIoDev
;
806 // This function just wrapps UsbGetDeviceDescriptor.
809 if (DeviceDescriptor
== NULL
) {
810 return EFI_INVALID_PARAMETER
;
813 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
814 UsbIoDev
= UsbIoController
->UsbDevice
;
816 if (!UsbIoDev
->IsConfigured
) {
817 return EFI_NOT_FOUND
;
822 &UsbIoDev
->DeviceDescriptor
,
823 sizeof (EFI_USB_DEVICE_DESCRIPTOR
)
832 UsbGetActiveConfigDescriptor (
833 IN EFI_USB_IO_PROTOCOL
*This
,
834 OUT EFI_USB_CONFIG_DESCRIPTOR
*ConfigurationDescriptor
839 Retrieves the current USB configuration Descriptor.
842 This - Indicates the calling context.
843 ConfigurationDescriptor - A pointer to the caller allocated USB active
844 Configuration Descriptor.
848 EFI_INVALID_PARAMETER
853 USB_IO_DEVICE
*UsbIoDev
;
854 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
857 // This function just wrapps UsbGetActiveConfigDescriptor.
859 if (ConfigurationDescriptor
== NULL
) {
860 return EFI_INVALID_PARAMETER
;
863 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
864 UsbIoDev
= UsbIoController
->UsbDevice
;
866 if (!UsbIoDev
->IsConfigured
) {
867 return EFI_NOT_FOUND
;
871 ConfigurationDescriptor
,
872 &(UsbIoDev
->ActiveConfig
->CongfigDescriptor
),
873 sizeof (EFI_USB_CONFIG_DESCRIPTOR
)
882 UsbGetInterfaceDescriptor (
883 IN EFI_USB_IO_PROTOCOL
*This
,
884 OUT EFI_USB_INTERFACE_DESCRIPTOR
*InterfaceDescriptor
889 Retrieves the interface Descriptor for that controller.
892 This - Indicates the calling context.
893 InterfaceDescriptor - A pointer to the caller allocated USB interface
898 EFI_INVALID_PARAMETER
903 INTERFACE_DESC_LIST_ENTRY
*InterfaceListEntry
;
905 if (InterfaceDescriptor
== NULL
) {
906 return EFI_INVALID_PARAMETER
;
909 InterfaceListEntry
= FindInterfaceListEntry (This
);
911 if (InterfaceListEntry
== NULL
) {
912 return EFI_NOT_FOUND
;
917 &(InterfaceListEntry
->InterfaceDescriptor
),
918 sizeof (EFI_USB_INTERFACE_DESCRIPTOR
)
927 UsbGetEndpointDescriptor (
928 IN EFI_USB_IO_PROTOCOL
*This
,
929 IN UINT8 EndpointIndex
,
930 OUT EFI_USB_ENDPOINT_DESCRIPTOR
*EndpointDescriptor
935 Retrieves the endpoint Descriptor for a given endpoint.
938 This - Indicates the calling context.
939 EndpointIndex - Indicates which endpoint descriptor to retrieve.
940 The valid range is 0..15.
941 EndpointDescriptor - A pointer to the caller allocated USB Endpoint
942 Descriptor of a USB controller.
945 EFI_SUCCESS - The endpoint descriptor was retrieved successfully.
946 EFI_INVALID_PARAMETER - EndpointIndex is not valid.
947 - EndpointDescriptor is NULL.
948 EFI_NOT_FOUND - The endpoint descriptor cannot be found.
949 The device may not be correctly configured.
953 INTERFACE_DESC_LIST_ENTRY
*InterfaceListEntry
;
954 LIST_ENTRY
*EndpointListHead
;
955 ENDPOINT_DESC_LIST_ENTRY
*EndpointListEntry
;
957 if (EndpointDescriptor
== NULL
) {
958 return EFI_INVALID_PARAMETER
;
961 if (EndpointIndex
> 15) {
962 return EFI_INVALID_PARAMETER
;
965 InterfaceListEntry
= FindInterfaceListEntry (This
);
967 if (InterfaceListEntry
== NULL
) {
968 return EFI_NOT_FOUND
;
971 EndpointListHead
= (LIST_ENTRY
*) (&InterfaceListEntry
->EndpointDescListHead
);
972 EndpointListEntry
= (ENDPOINT_DESC_LIST_ENTRY
*) (EndpointListHead
->ForwardLink
);
974 if (EndpointIndex
>= InterfaceListEntry
->InterfaceDescriptor
.NumEndpoints
) {
975 return EFI_NOT_FOUND
;
978 // Loop all endpoint descriptor to get match one.
980 while (EndpointIndex
!= 0) {
981 EndpointListEntry
= (ENDPOINT_DESC_LIST_ENTRY
*) (EndpointListEntry
->Link
.ForwardLink
);
987 &EndpointListEntry
->EndpointDescriptor
,
988 sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
)
997 UsbGetSupportedLanguages (
998 IN EFI_USB_IO_PROTOCOL
*This
,
999 OUT UINT16
**LangIDTable
,
1000 OUT UINT16
*TableSize
1004 Routine Description:
1005 Get all the languages that the USB device supports
1008 This - Indicates the calling context.
1009 LangIDTable - Language ID for the string the caller wants to get.
1010 TableSize - The size, in bytes, of the table LangIDTable.
1018 USB_IO_DEVICE
*UsbIoDev
;
1019 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
1023 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
1024 UsbIoDev
= UsbIoController
->UsbDevice
;
1029 // Loop language table
1031 while (UsbIoDev
->LangID
[Index
]) {
1037 return EFI_NOT_FOUND
;
1040 *LangIDTable
= UsbIoDev
->LangID
;
1041 *TableSize
= (UINT16
) Index
;
1049 UsbGetStringDescriptor (
1050 IN EFI_USB_IO_PROTOCOL
*This
,
1052 IN UINT8 StringIndex
,
1057 Routine Description:
1058 Get a given string descriptor
1061 This - Indicates the calling context.
1062 LangID - The Language ID for the string being retrieved.
1063 StringIndex - The ID of the string being retrieved.
1064 String - A pointer to a buffer allocated by this function
1065 with AllocatePool() to store the string. If this
1066 function returns EFI_SUCCESS, it stores the string
1067 the caller wants to get. The caller should release
1068 the string buffer with FreePool() after the string
1069 is not used any more.
1073 EFI_OUT_OF_RESOURCES
1080 EFI_USB_STRING_DESCRIPTOR
*StrDescriptor
;
1084 USB_IO_DEVICE
*UsbIoDev
;
1087 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
1089 if (StringIndex
== 0) {
1090 return EFI_NOT_FOUND
;
1093 // Search LanguageID, check if it is supported by this device
1096 return EFI_NOT_FOUND
;
1099 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
1100 UsbIoDev
= UsbIoController
->UsbDevice
;
1104 while (UsbIoDev
->LangID
[Index
]) {
1105 if (UsbIoDev
->LangID
[Index
] == LangID
) {
1114 return EFI_NOT_FOUND
;
1117 // Get String Length
1119 Result
= UsbGetString (
1127 if (EFI_ERROR (Result
)) {
1128 return EFI_NOT_FOUND
;
1131 StrDescriptor
= (EFI_USB_STRING_DESCRIPTOR
*) &TempBuffer
;
1133 if (StrDescriptor
->Length
== 0) {
1134 return EFI_UNSUPPORTED
;
1137 Buffer
= AllocateZeroPool (StrDescriptor
->Length
);
1138 if (Buffer
== NULL
) {
1139 return EFI_OUT_OF_RESOURCES
;
1142 Result
= UsbGetString (
1147 StrDescriptor
->Length
,
1151 if (EFI_ERROR (Result
)) {
1152 gBS
->FreePool (Buffer
);
1153 return EFI_NOT_FOUND
;
1156 StrDescriptor
= (EFI_USB_STRING_DESCRIPTOR
*) Buffer
;
1159 // UsbString is a UNICODE string
1161 UsbString
= AllocateZeroPool (StrDescriptor
->Length
);
1162 if (UsbString
== NULL
) {
1163 gBS
->FreePool (Buffer
);
1164 return EFI_OUT_OF_RESOURCES
;
1170 StrDescriptor
->Length
- 2
1173 *String
= UsbString
;
1175 gBS
->FreePool (Buffer
);