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
105 UsbGetDeviceDescriptor (
106 IN EFI_USB_IO_PROTOCOL
*This
,
107 OUT EFI_USB_DEVICE_DESCRIPTOR
*DeviceDescriptor
113 UsbGetActiveConfigDescriptor (
114 IN EFI_USB_IO_PROTOCOL
*This
,
115 OUT EFI_USB_CONFIG_DESCRIPTOR
*ConfigurationDescriptor
121 UsbGetInterfaceDescriptor (
122 IN EFI_USB_IO_PROTOCOL
*This
,
123 OUT EFI_USB_INTERFACE_DESCRIPTOR
*InterfaceDescriptor
129 UsbGetEndpointDescriptor (
130 IN EFI_USB_IO_PROTOCOL
*This
,
131 IN UINT8 EndpointIndex
,
132 OUT EFI_USB_ENDPOINT_DESCRIPTOR
*EndpointDescriptor
138 UsbGetStringDescriptor (
139 IN EFI_USB_IO_PROTOCOL
*This
,
141 IN UINT8 StringIndex
,
148 UsbGetSupportedLanguages (
149 IN EFI_USB_IO_PROTOCOL
*This
,
150 OUT UINT16
**LangIDTable
,
151 OUT UINT16
*TableSize
155 // USB I/O Interface structure
157 STATIC EFI_USB_IO_PROTOCOL UsbIoInterface
= {
160 UsbAsyncInterruptTransfer
,
161 UsbSyncInterruptTransfer
,
162 UsbIsochronousTransfer
,
163 UsbAsyncIsochronousTransfer
,
164 UsbGetDeviceDescriptor
,
165 UsbGetActiveConfigDescriptor
,
166 UsbGetInterfaceDescriptor
,
167 UsbGetEndpointDescriptor
,
168 UsbGetStringDescriptor
,
169 UsbGetSupportedLanguages
,
174 InitializeUsbIoInstance (
175 IN USB_IO_CONTROLLER_DEVICE
*UsbIoController
181 Initialize the instance of UsbIo controller
185 UsbIoController - A pointer to controller structure of UsbIo
192 // Copy EFI_USB_IO protocol instance
195 &UsbIoController
->UsbIo
,
197 sizeof (EFI_USB_IO_PROTOCOL
)
207 IN EFI_USB_IO_PROTOCOL
*This
,
208 IN EFI_USB_DEVICE_REQUEST
*Request
,
209 IN EFI_USB_DATA_DIRECTION Direction
,
211 IN OUT VOID
*Data
, OPTIONAL
212 IN UINTN DataLength
, OPTIONAL
218 This function is used to manage a USB device with a control transfer pipe.
221 This - Indicates calling context.
222 Request - A pointer to the USB device request that will be sent to
224 Direction - Indicates the data direction.
225 Data - A pointer to the buffer of data that will be transmitted
226 to USB device or received from USB device.
227 Timeout - Indicates the transfer should be completed within this time
229 DataLength - The size, in bytes, of the data buffer specified by Data.
230 Status - A pointer to the result of the USB transfer.
234 EFI_INVALID_PARAMETER
241 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
243 EFI_STATUS RetStatus
;
244 USB_IO_DEVICE
*UsbIoDev
;
245 UINT8 MaxPacketLength
;
246 UINT32 TransferResult
;
247 BOOLEAN Disconnected
;
249 // Parameters Checking
251 if (Status
== NULL
) {
252 return EFI_INVALID_PARAMETER
;
256 // leave the HostController's ControlTransfer
257 // to perform other parameters checking
259 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
260 UsbIoDev
= UsbIoController
->UsbDevice
;
262 MaxPacketLength
= UsbIoDev
->DeviceDescriptor
.MaxPacketSize0
;
265 if (Request
->Request
== USB_DEV_CLEAR_FEATURE
&&
266 Request
->RequestType
== 0x02 &&
267 Request
->Value
== EfiUsbEndpointHalt
) {
269 //Reduce the remove delay time for system response
271 IsDeviceDisconnected (UsbIoController
, &Disconnected
);
272 if (!EFI_ERROR (Status
) && Disconnected
== TRUE
) {
273 DEBUG ((gUSBErrorLevel
, "Device is disconnected when trying reset\n"));
274 return EFI_DEVICE_ERROR
;
278 // using HostController's ControlTransfer to complete the request
280 RetStatus
= UsbVirtualHcControlTransfer (
281 UsbIoDev
->BusController
,
282 UsbIoDev
->DeviceAddress
,
283 UsbIoDev
->DeviceSpeed
,
290 UsbIoDev
->Translator
,
294 *Status
= TransferResult
;
296 if (Request
->Request
== USB_DEV_CLEAR_FEATURE
&&
297 Request
->RequestType
== 0x02 &&
298 Request
->Value
== EfiUsbEndpointHalt
) {
300 // This is a UsbClearEndpointHalt request
301 // Need to clear data toggle
302 // Request.Index == EndpointAddress
304 if (!EFI_ERROR (RetStatus
) && TransferResult
== EFI_USB_NOERROR
) {
307 (UINT8
) Request
->Index
,
319 IN EFI_USB_IO_PROTOCOL
*This
,
320 IN UINT8 DeviceEndpoint
,
322 IN OUT UINTN
*DataLength
,
329 This function is used to manage a USB device with the bulk transfer pipe.
332 This - Indicates calling context.
333 DeviceEndpoint - The destination USB device endpoint to which the device
334 request is being sent.
335 Data - A pointer to the buffer of data that will be transmitted
336 to USB device or received from USB device.
337 DataLength - On input, the size, in bytes, of the data buffer
338 specified by Data. On output, the number of bytes that
339 were actually transferred.
340 Timeout - Indicates the transfer should be completed within this
342 Status - This parameter indicates the USB transfer status.
346 EFI_INVALID_PARAMETER
353 USB_IO_DEVICE
*UsbIoDev
;
354 UINTN MaxPacketLength
;
357 EFI_STATUS RetStatus
;
358 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
359 ENDPOINT_DESC_LIST_ENTRY
*EndPointListEntry
;
360 UINT8 DataBuffersNumber
;
361 UINT32 TransferResult
;
363 DataBuffersNumber
= 1;
364 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
365 UsbIoDev
= UsbIoController
->UsbDevice
;
368 // Parameters Checking
370 if ((DeviceEndpoint
& 0x7F) == 0) {
371 return EFI_INVALID_PARAMETER
;
374 if ((DeviceEndpoint
& 0x7F) > 15) {
375 return EFI_INVALID_PARAMETER
;
378 if (Status
== NULL
) {
379 return EFI_INVALID_PARAMETER
;
382 EndPointListEntry
= FindEndPointListEntry (
387 if (EndPointListEntry
== NULL
) {
388 return EFI_INVALID_PARAMETER
;
391 if ((EndPointListEntry
->EndpointDescriptor
.Attributes
& 0x03) != 0x02) {
392 return EFI_INVALID_PARAMETER
;
396 // leave the HostController's BulkTransfer
397 // to perform other parameters checking
399 GetDeviceEndPointMaxPacketLength (
411 OldToggle
= DataToggle
;
414 // using HostController's BulkTransfer to complete the request
416 RetStatus
= UsbVirtualHcBulkTransfer (
417 UsbIoDev
->BusController
,
418 UsbIoDev
->DeviceAddress
,
420 UsbIoDev
->DeviceSpeed
,
427 UsbIoDev
->Translator
,
431 if (OldToggle
!= DataToggle
) {
433 // Write the toggle back
442 *Status
= TransferResult
;
450 UsbSyncInterruptTransfer (
451 IN EFI_USB_IO_PROTOCOL
*This
,
452 IN UINT8 DeviceEndpoint
,
454 IN OUT UINTN
*DataLength
,
461 Usb Sync Interrupt Transfer
464 This - Indicates calling context.
465 DeviceEndpoint - The destination USB device endpoint to which the device
466 request is being sent.
467 Data - A pointer to the buffer of data that will be transmitted
468 to USB device or received from USB device.
469 DataLength - On input, the size, in bytes, of the data buffer
470 specified by Data. On output, the number of bytes that
471 were actually transferred.
472 Timeout - Indicates the transfer should be completed within this
474 Status - This parameter indicates the USB transfer status.
478 EFI_INVALID_PARAMETER
485 USB_IO_DEVICE
*UsbIoDev
;
486 UINTN MaxPacketLength
;
489 EFI_STATUS RetStatus
;
490 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
491 ENDPOINT_DESC_LIST_ENTRY
*EndPointListEntry
;
494 // Parameters Checking
496 if ((DeviceEndpoint
& 0x7F) == 0) {
497 return EFI_INVALID_PARAMETER
;
500 if ((DeviceEndpoint
& 0x7F) > 15) {
501 return EFI_INVALID_PARAMETER
;
504 if (Status
== NULL
) {
505 return EFI_INVALID_PARAMETER
;
508 EndPointListEntry
= FindEndPointListEntry (
513 if (EndPointListEntry
== NULL
) {
514 return EFI_INVALID_PARAMETER
;
517 if ((EndPointListEntry
->EndpointDescriptor
.Attributes
& 0x03) != 0x03) {
518 return EFI_INVALID_PARAMETER
;
522 // leave the HostController's SyncInterruptTransfer
523 // to perform other parameters checking
525 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
526 UsbIoDev
= UsbIoController
->UsbDevice
;
527 GetDeviceEndPointMaxPacketLength (
539 OldToggle
= DataToggle
;
541 // using HostController's SyncInterruptTransfer to complete the request
543 RetStatus
= UsbVirtualHcSyncInterruptTransfer (
544 UsbIoDev
->BusController
,
545 UsbIoDev
->DeviceAddress
,
547 UsbIoDev
->DeviceSpeed
,
553 UsbIoDev
->Translator
,
557 if (OldToggle
!= DataToggle
) {
559 // Write the toggle back
574 UsbAsyncInterruptTransfer (
575 IN EFI_USB_IO_PROTOCOL
*This
,
576 IN UINT8 DeviceEndpoint
,
577 IN BOOLEAN IsNewTransfer
,
578 IN UINTN PollingInterval
, OPTIONAL
579 IN UINTN DataLength
, OPTIONAL
580 IN EFI_ASYNC_USB_TRANSFER_CALLBACK InterruptCallBack
, OPTIONAL
581 IN VOID
*Context OPTIONAL
586 Usb Async Interrput Transfer
589 This - Indicates calling context.
590 DeviceEndpoint - The destination USB device endpoint to which the
591 device request is being sent.
592 IsNewTransfer - If TRUE, a new transfer will be submitted to USB
593 controller. If FALSE, the interrupt transfer is
594 deleted from the device's interrupt transfer queue.
595 PollingInterval - Indicates the periodic rate, in milliseconds, that
596 the transfer is to be executed.
597 DataLength - Specifies the length, in bytes, of the data to be
598 received from the USB device.
599 InterruptCallBack - The Callback function. This function is called if
600 the asynchronous interrupt transfer is completed.
601 Context - Passed to InterruptCallback
604 EFI_INVALID_PARAMETER
609 USB_IO_DEVICE
*UsbIoDev
;
610 UINTN MaxPacketLength
;
612 EFI_STATUS RetStatus
;
613 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
614 ENDPOINT_DESC_LIST_ENTRY
*EndpointListEntry
;
619 if ((DeviceEndpoint
& 0x7F) == 0) {
620 return EFI_INVALID_PARAMETER
;
623 if ((DeviceEndpoint
& 0x7F) > 15) {
624 return EFI_INVALID_PARAMETER
;
627 EndpointListEntry
= FindEndPointListEntry (
632 if (EndpointListEntry
== NULL
) {
633 return EFI_INVALID_PARAMETER
;
636 if ((EndpointListEntry
->EndpointDescriptor
.Attributes
& 0x03) != 0x03) {
637 return EFI_INVALID_PARAMETER
;
640 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
641 UsbIoDev
= UsbIoController
->UsbDevice
;
643 if (!IsNewTransfer
) {
645 // Delete this transfer
647 UsbVirtualHcAsyncInterruptTransfer (
648 UsbIoDev
->BusController
,
649 UsbIoDev
->DeviceAddress
,
651 UsbIoDev
->DeviceSpeed
,
657 UsbIoDev
->Translator
,
663 // We need to store the toggle value
674 GetDeviceEndPointMaxPacketLength (
686 RetStatus
= UsbVirtualHcAsyncInterruptTransfer (
687 UsbIoDev
->BusController
,
688 UsbIoDev
->DeviceAddress
,
690 UsbIoDev
->DeviceSpeed
,
696 UsbIoDev
->Translator
,
707 UsbIsochronousTransfer (
708 IN EFI_USB_IO_PROTOCOL
*This
,
709 IN UINT8 DeviceEndpoint
,
717 Usb Isochronous Transfer
720 This - Indicates calling context.
721 DeviceEndpoint - The destination USB device endpoint to which the
722 device request is being sent.
723 Data - A pointer to the buffer of data that will be
724 transmitted to USB device or received from USB device.
725 DataLength - The size, in bytes, of the data buffer specified by
727 Status - This parameter indicates the USB transfer status.
731 EFI_INVALID_PARAMETER
739 // Currently we don't support this transfer
741 return EFI_UNSUPPORTED
;
747 UsbAsyncIsochronousTransfer (
748 IN EFI_USB_IO_PROTOCOL
*This
,
749 IN UINT8 DeviceEndpoint
,
752 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
753 IN VOID
*Context OPTIONAL
759 Usb Async Isochronous Transfer
763 This - EFI_USB_IO_PROTOCOL
764 DeviceEndpoint - DeviceEndpoint number
765 Data - Data to transfer
766 DataLength - DataLength
767 IsochronousCallBack - Isochronous CallBack function
768 Context - Passed to IsochronousCallBack function
771 EFI_UNSUPPORTED - Unsupported now
776 // Currently we don't support this transfer
778 return EFI_UNSUPPORTED
;
781 // Here is new definitions
786 UsbGetDeviceDescriptor (
787 IN EFI_USB_IO_PROTOCOL
*This
,
788 OUT EFI_USB_DEVICE_DESCRIPTOR
*DeviceDescriptor
793 Retrieves the USB Device Descriptor.
796 This - Indicates the calling context.
797 DeviceDescriptor - A pointer to the caller allocated USB Device
802 EFI_INVALID_PARAMETER
807 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
808 USB_IO_DEVICE
*UsbIoDev
;
811 // This function just wrapps UsbGetDeviceDescriptor.
814 if (DeviceDescriptor
== NULL
) {
815 return EFI_INVALID_PARAMETER
;
818 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
819 UsbIoDev
= UsbIoController
->UsbDevice
;
821 if (!UsbIoDev
->IsConfigured
) {
822 return EFI_NOT_FOUND
;
827 &UsbIoDev
->DeviceDescriptor
,
828 sizeof (EFI_USB_DEVICE_DESCRIPTOR
)
837 UsbGetActiveConfigDescriptor (
838 IN EFI_USB_IO_PROTOCOL
*This
,
839 OUT EFI_USB_CONFIG_DESCRIPTOR
*ConfigurationDescriptor
844 Retrieves the current USB configuration Descriptor.
847 This - Indicates the calling context.
848 ConfigurationDescriptor - A pointer to the caller allocated USB active
849 Configuration Descriptor.
853 EFI_INVALID_PARAMETER
858 USB_IO_DEVICE
*UsbIoDev
;
859 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
862 // This function just wrapps UsbGetActiveConfigDescriptor.
864 if (ConfigurationDescriptor
== NULL
) {
865 return EFI_INVALID_PARAMETER
;
868 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
869 UsbIoDev
= UsbIoController
->UsbDevice
;
871 if (!UsbIoDev
->IsConfigured
) {
872 return EFI_NOT_FOUND
;
876 ConfigurationDescriptor
,
877 &(UsbIoDev
->ActiveConfig
->CongfigDescriptor
),
878 sizeof (EFI_USB_CONFIG_DESCRIPTOR
)
887 UsbGetInterfaceDescriptor (
888 IN EFI_USB_IO_PROTOCOL
*This
,
889 OUT EFI_USB_INTERFACE_DESCRIPTOR
*InterfaceDescriptor
894 Retrieves the interface Descriptor for that controller.
897 This - Indicates the calling context.
898 InterfaceDescriptor - A pointer to the caller allocated USB interface
903 EFI_INVALID_PARAMETER
908 INTERFACE_DESC_LIST_ENTRY
*InterfaceListEntry
;
910 if (InterfaceDescriptor
== NULL
) {
911 return EFI_INVALID_PARAMETER
;
914 InterfaceListEntry
= FindInterfaceListEntry (This
);
916 if (InterfaceListEntry
== NULL
) {
917 return EFI_NOT_FOUND
;
922 &(InterfaceListEntry
->InterfaceDescriptor
),
923 sizeof (EFI_USB_INTERFACE_DESCRIPTOR
)
932 UsbGetEndpointDescriptor (
933 IN EFI_USB_IO_PROTOCOL
*This
,
934 IN UINT8 EndpointIndex
,
935 OUT EFI_USB_ENDPOINT_DESCRIPTOR
*EndpointDescriptor
940 Retrieves the endpoint Descriptor for a given endpoint.
943 This - Indicates the calling context.
944 EndpointIndex - Indicates which endpoint descriptor to retrieve.
945 The valid range is 0..15.
946 EndpointDescriptor - A pointer to the caller allocated USB Endpoint
947 Descriptor of a USB controller.
950 EFI_SUCCESS - The endpoint descriptor was retrieved successfully.
951 EFI_INVALID_PARAMETER - EndpointIndex is not valid.
952 - EndpointDescriptor is NULL.
953 EFI_NOT_FOUND - The endpoint descriptor cannot be found.
954 The device may not be correctly configured.
958 INTERFACE_DESC_LIST_ENTRY
*InterfaceListEntry
;
959 LIST_ENTRY
*EndpointListHead
;
960 ENDPOINT_DESC_LIST_ENTRY
*EndpointListEntry
;
962 if (EndpointDescriptor
== NULL
) {
963 return EFI_INVALID_PARAMETER
;
966 if (EndpointIndex
> 15) {
967 return EFI_INVALID_PARAMETER
;
970 InterfaceListEntry
= FindInterfaceListEntry (This
);
972 if (InterfaceListEntry
== NULL
) {
973 return EFI_NOT_FOUND
;
976 EndpointListHead
= (LIST_ENTRY
*) (&InterfaceListEntry
->EndpointDescListHead
);
977 EndpointListEntry
= (ENDPOINT_DESC_LIST_ENTRY
*) (EndpointListHead
->ForwardLink
);
979 if (EndpointIndex
>= InterfaceListEntry
->InterfaceDescriptor
.NumEndpoints
) {
980 return EFI_NOT_FOUND
;
983 // Loop all endpoint descriptor to get match one.
985 while (EndpointIndex
!= 0) {
986 EndpointListEntry
= (ENDPOINT_DESC_LIST_ENTRY
*) (EndpointListEntry
->Link
.ForwardLink
);
992 &EndpointListEntry
->EndpointDescriptor
,
993 sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
)
1002 UsbGetSupportedLanguages (
1003 IN EFI_USB_IO_PROTOCOL
*This
,
1004 OUT UINT16
**LangIDTable
,
1005 OUT UINT16
*TableSize
1009 Routine Description:
1010 Get all the languages that the USB device supports
1013 This - Indicates the calling context.
1014 LangIDTable - Language ID for the string the caller wants to get.
1015 TableSize - The size, in bytes, of the table LangIDTable.
1023 USB_IO_DEVICE
*UsbIoDev
;
1024 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
1028 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
1029 UsbIoDev
= UsbIoController
->UsbDevice
;
1034 // Loop language table
1036 while (UsbIoDev
->LangID
[Index
]) {
1042 return EFI_NOT_FOUND
;
1045 *LangIDTable
= UsbIoDev
->LangID
;
1046 *TableSize
= (UINT16
) Index
;
1054 UsbGetStringDescriptor (
1055 IN EFI_USB_IO_PROTOCOL
*This
,
1057 IN UINT8 StringIndex
,
1062 Routine Description:
1063 Get a given string descriptor
1066 This - Indicates the calling context.
1067 LangID - The Language ID for the string being retrieved.
1068 StringIndex - The ID of the string being retrieved.
1069 String - A pointer to a buffer allocated by this function
1070 with AllocatePool() to store the string. If this
1071 function returns EFI_SUCCESS, it stores the string
1072 the caller wants to get. The caller should release
1073 the string buffer with FreePool() after the string
1074 is not used any more.
1078 EFI_OUT_OF_RESOURCES
1085 EFI_USB_STRING_DESCRIPTOR
*StrDescriptor
;
1089 USB_IO_DEVICE
*UsbIoDev
;
1092 USB_IO_CONTROLLER_DEVICE
*UsbIoController
;
1094 if (StringIndex
== 0) {
1095 return EFI_NOT_FOUND
;
1098 // Search LanguageID, check if it is supported by this device
1101 return EFI_NOT_FOUND
;
1104 UsbIoController
= USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This
);
1105 UsbIoDev
= UsbIoController
->UsbDevice
;
1109 while (UsbIoDev
->LangID
[Index
]) {
1110 if (UsbIoDev
->LangID
[Index
] == LangID
) {
1119 return EFI_NOT_FOUND
;
1122 // Get String Length
1124 Result
= UsbGetString (
1132 if (EFI_ERROR (Result
)) {
1133 return EFI_NOT_FOUND
;
1136 StrDescriptor
= (EFI_USB_STRING_DESCRIPTOR
*) &TempBuffer
;
1138 if (StrDescriptor
->Length
== 0) {
1139 return EFI_UNSUPPORTED
;
1142 Buffer
= AllocateZeroPool (StrDescriptor
->Length
);
1143 if (Buffer
== NULL
) {
1144 return EFI_OUT_OF_RESOURCES
;
1147 Result
= UsbGetString (
1152 StrDescriptor
->Length
,
1156 if (EFI_ERROR (Result
)) {
1157 gBS
->FreePool (Buffer
);
1158 return EFI_NOT_FOUND
;
1161 StrDescriptor
= (EFI_USB_STRING_DESCRIPTOR
*) Buffer
;
1164 // UsbString is a UNICODE string
1166 UsbString
= AllocateZeroPool (StrDescriptor
->Length
);
1167 if (UsbString
== NULL
) {
1168 gBS
->FreePool (Buffer
);
1169 return EFI_OUT_OF_RESOURCES
;
1175 StrDescriptor
->Length
- 2
1178 *String
= UsbString
;
1180 gBS
->FreePool (Buffer
);