]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiUsbLib/UsbDxeLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / UefiUsbLib / UsbDxeLib.c
... / ...
CommitLineData
1/** @file\r
2\r
3 The library provides the USB Standard Device Requests defined\r
4 in Usb specification 9.4 section.\r
5\r
6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#include "UefiUsbLibInternal.h"\r
12\r
13/**\r
14 Get the descriptor of the specified USB device.\r
15\r
16 Submit a USB get descriptor request for the USB device specified by UsbIo, Value,\r
17 and Index, and return the descriptor in the buffer specified by Descriptor.\r
18 The status of the transfer is returned in Status.\r
19 If UsbIo is NULL, then ASSERT().\r
20 If Descriptor is NULL, then ASSERT().\r
21 If Status is NULL, then ASSERT().\r
22\r
23 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
24 @param Value The device request value.\r
25 @param Index The device request index.\r
26 @param DescriptorLength The size, in bytes, of Descriptor.\r
27 @param Descriptor A pointer to the descriptor buffer to get.\r
28 @param Status A pointer to the status of the transfer.\r
29\r
30 @retval EFI_SUCCESS The request executed successfully.\r
31 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the\r
32 buffer specified by DescriptorLength and Descriptor\r
33 is not large enough to hold the result of the request.\r
34 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
35 @retval EFI_DEVICE_ERROR The request failed due to a device error. The transfer\r
36 status is returned in Status.\r
37\r
38**/\r
39EFI_STATUS\r
40EFIAPI\r
41UsbGetDescriptor (\r
42 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
43 IN UINT16 Value,\r
44 IN UINT16 Index,\r
45 IN UINT16 DescriptorLength,\r
46 OUT VOID *Descriptor,\r
47 OUT UINT32 *Status\r
48 )\r
49{\r
50 EFI_USB_DEVICE_REQUEST DevReq;\r
51\r
52 ASSERT (UsbIo != NULL);\r
53 ASSERT (Descriptor != NULL);\r
54 ASSERT (Status != NULL);\r
55\r
56 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
57\r
58 DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;\r
59 DevReq.Request = USB_REQ_GET_DESCRIPTOR;\r
60 DevReq.Value = Value;\r
61 DevReq.Index = Index;\r
62 DevReq.Length = DescriptorLength;\r
63\r
64 return UsbIo->UsbControlTransfer (\r
65 UsbIo,\r
66 &DevReq,\r
67 EfiUsbDataIn,\r
68 PcdGet32 (PcdUsbTransferTimeoutValue),\r
69 Descriptor,\r
70 DescriptorLength,\r
71 Status\r
72 );\r
73}\r
74\r
75/**\r
76 Set the descriptor of the specified USB device.\r
77\r
78 Submit a USB set descriptor request for the USB device specified by UsbIo,\r
79 Value, and Index, and set the descriptor using the buffer specified by DesriptorLength\r
80 and Descriptor. The status of the transfer is returned in Status.\r
81 If UsbIo is NULL, then ASSERT().\r
82 If Descriptor is NULL, then ASSERT().\r
83 If Status is NULL, then ASSERT().\r
84\r
85 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
86 @param Value The device request value.\r
87 @param Index The device request index.\r
88 @param DescriptorLength The size, in bytes, of Descriptor.\r
89 @param Descriptor A pointer to the descriptor buffer to set.\r
90 @param Status A pointer to the status of the transfer.\r
91\r
92 @retval EFI_SUCCESS The request executed successfully.\r
93 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
94 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
95 The transfer status is returned in Status.\r
96\r
97**/\r
98EFI_STATUS\r
99EFIAPI\r
100UsbSetDescriptor (\r
101 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
102 IN UINT16 Value,\r
103 IN UINT16 Index,\r
104 IN UINT16 DescriptorLength,\r
105 IN VOID *Descriptor,\r
106 OUT UINT32 *Status\r
107 )\r
108{\r
109 EFI_USB_DEVICE_REQUEST DevReq;\r
110\r
111 ASSERT (UsbIo != NULL);\r
112 ASSERT (Descriptor != NULL);\r
113 ASSERT (Status != NULL);\r
114\r
115 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
116\r
117 DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;\r
118 DevReq.Request = USB_REQ_SET_DESCRIPTOR;\r
119 DevReq.Value = Value;\r
120 DevReq.Index = Index;\r
121 DevReq.Length = DescriptorLength;\r
122\r
123 return UsbIo->UsbControlTransfer (\r
124 UsbIo,\r
125 &DevReq,\r
126 EfiUsbDataOut,\r
127 PcdGet32 (PcdUsbTransferTimeoutValue),\r
128 Descriptor,\r
129 DescriptorLength,\r
130 Status\r
131 );\r
132}\r
133\r
134/**\r
135 Get the interface setting of the specified USB device.\r
136\r
137 Submit a USB get interface request for the USB device specified by UsbIo,\r
138 and Interface, and place the result in the buffer specified by AlternateSetting.\r
139 The status of the transfer is returned in Status.\r
140 If UsbIo is NULL, then ASSERT().\r
141 If AlternateSetting is NULL, then ASSERT().\r
142 If Status is NULL, then ASSERT().\r
143\r
144 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
145 @param Interface The interface index value.\r
146 @param AlternateSetting A pointer to the alternate setting to be retrieved.\r
147 @param Status A pointer to the status of the transfer.\r
148\r
149 @retval EFI_SUCCESS The request executed successfully.\r
150 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
151 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
152 The transfer status is returned in Status.\r
153\r
154**/\r
155EFI_STATUS\r
156EFIAPI\r
157UsbGetInterface (\r
158 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
159 IN UINT16 Interface,\r
160 OUT UINT16 *AlternateSetting,\r
161 OUT UINT32 *Status\r
162 )\r
163{\r
164 EFI_USB_DEVICE_REQUEST DevReq;\r
165\r
166 ASSERT (UsbIo != NULL);\r
167 ASSERT (AlternateSetting != NULL);\r
168 ASSERT (Status != NULL);\r
169\r
170 *AlternateSetting = 0;\r
171\r
172 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
173\r
174 DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;\r
175 DevReq.Request = USB_REQ_GET_INTERFACE;\r
176 DevReq.Index = Interface;\r
177 DevReq.Length = 1;\r
178\r
179 return UsbIo->UsbControlTransfer (\r
180 UsbIo,\r
181 &DevReq,\r
182 EfiUsbDataIn,\r
183 PcdGet32 (PcdUsbTransferTimeoutValue),\r
184 AlternateSetting,\r
185 1,\r
186 Status\r
187 );\r
188}\r
189\r
190/**\r
191 Set the interface setting of the specified USB device.\r
192\r
193 Submit a USB set interface request for the USB device specified by UsbIo, and\r
194 Interface, and set the alternate setting to the value specified by AlternateSetting.\r
195 The status of the transfer is returned in Status.\r
196 If UsbIo is NULL, then ASSERT().\r
197 If Status is NULL, then ASSERT().\r
198\r
199 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
200 @param Interface The interface index value.\r
201 @param AlternateSetting The alternate setting to be set.\r
202 @param Status A pointer to the status of the transfer.\r
203\r
204 @retval EFI_SUCCESS The request executed successfully.\r
205 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
206 @retval EFI_SUCCESS The request failed due to a device error.\r
207 The transfer status is returned in Status.\r
208\r
209**/\r
210EFI_STATUS\r
211EFIAPI\r
212UsbSetInterface (\r
213 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
214 IN UINT16 Interface,\r
215 IN UINT16 AlternateSetting,\r
216 OUT UINT32 *Status\r
217 )\r
218{\r
219 EFI_USB_DEVICE_REQUEST DevReq;\r
220\r
221 ASSERT (UsbIo != NULL);\r
222 ASSERT (Status != NULL);\r
223\r
224 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
225\r
226 DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;\r
227 DevReq.Request = USB_REQ_SET_INTERFACE;\r
228 DevReq.Value = AlternateSetting;\r
229 DevReq.Index = Interface;\r
230\r
231 return UsbIo->UsbControlTransfer (\r
232 UsbIo,\r
233 &DevReq,\r
234 EfiUsbNoData,\r
235 PcdGet32 (PcdUsbTransferTimeoutValue),\r
236 NULL,\r
237 0,\r
238 Status\r
239 );\r
240}\r
241\r
242/**\r
243 Get the device configuration.\r
244\r
245 Submit a USB get configuration request for the USB device specified by UsbIo\r
246 and place the result in the buffer specified by ConfigurationValue. The status\r
247 of the transfer is returned in Status.\r
248 If UsbIo is NULL, then ASSERT().\r
249 If ConfigurationValue is NULL, then ASSERT().\r
250 If Status is NULL, then ASSERT().\r
251\r
252 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
253 @param ConfigurationValue A pointer to the device configuration to be retrieved.\r
254 @param Status A pointer to the status of the transfer.\r
255\r
256 @retval EFI_SUCCESS The request executed successfully.\r
257 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
258 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
259 The transfer status is returned in Status.\r
260\r
261**/\r
262EFI_STATUS\r
263EFIAPI\r
264UsbGetConfiguration (\r
265 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
266 OUT UINT16 *ConfigurationValue,\r
267 OUT UINT32 *Status\r
268 )\r
269{\r
270 EFI_USB_DEVICE_REQUEST DevReq;\r
271\r
272 ASSERT (UsbIo != NULL);\r
273 ASSERT (ConfigurationValue != NULL);\r
274 ASSERT (Status != NULL);\r
275\r
276 *ConfigurationValue = 0;\r
277\r
278 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
279\r
280 DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;\r
281 DevReq.Request = USB_REQ_GET_CONFIG;\r
282 DevReq.Length = 1;\r
283\r
284 return UsbIo->UsbControlTransfer (\r
285 UsbIo,\r
286 &DevReq,\r
287 EfiUsbDataIn,\r
288 PcdGet32 (PcdUsbTransferTimeoutValue),\r
289 ConfigurationValue,\r
290 1,\r
291 Status\r
292 );\r
293}\r
294\r
295/**\r
296 Set the device configuration.\r
297\r
298 Submit a USB set configuration request for the USB device specified by UsbIo\r
299 and set the device configuration to the value specified by ConfigurationValue.\r
300 The status of the transfer is returned in Status.\r
301 If UsbIo is NULL, then ASSERT().\r
302 If Status is NULL, then ASSERT().\r
303\r
304 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
305 @param ConfigurationValue The device configuration value to be set.\r
306 @param Status A pointer to the status of the transfer.\r
307\r
308 @retval EFI_SUCCESS The request executed successfully.\r
309 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
310 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
311 The transfer status is returned in Status.\r
312\r
313**/\r
314EFI_STATUS\r
315EFIAPI\r
316UsbSetConfiguration (\r
317 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
318 IN UINT16 ConfigurationValue,\r
319 OUT UINT32 *Status\r
320 )\r
321{\r
322 EFI_USB_DEVICE_REQUEST DevReq;\r
323\r
324 ASSERT (UsbIo != NULL);\r
325 ASSERT (Status != NULL);\r
326\r
327 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
328\r
329 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;\r
330 DevReq.Request = USB_REQ_SET_CONFIG;\r
331 DevReq.Value = ConfigurationValue;\r
332\r
333 return UsbIo->UsbControlTransfer (\r
334 UsbIo,\r
335 &DevReq,\r
336 EfiUsbNoData,\r
337 PcdGet32 (PcdUsbTransferTimeoutValue),\r
338 NULL,\r
339 0,\r
340 Status\r
341 );\r
342}\r
343\r
344/**\r
345 Set the specified feature of the specified device.\r
346\r
347 Submit a USB set device feature request for the USB device specified by UsbIo,\r
348 Recipient, and Target to the value specified by Value. The status of the\r
349 transfer is returned in Status.\r
350 If UsbIo is NULL, then ASSERT().\r
351 If Status is NULL, then ASSERT().\r
352\r
353 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
354 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
355 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry\r
356 Standard include file Usb.h.\r
357 @param Value The value of the feature to be set.\r
358 @param Target The index of the device to be set.\r
359 @param Status A pointer to the status of the transfer.\r
360\r
361 @retval EFI_SUCCESS The request executed successfully.\r
362 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
363 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
364 The transfer status is returned in Status.\r
365\r
366**/\r
367EFI_STATUS\r
368EFIAPI\r
369UsbSetFeature (\r
370 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
371 IN USB_TYPES_DEFINITION Recipient,\r
372 IN UINT16 Value,\r
373 IN UINT16 Target,\r
374 OUT UINT32 *Status\r
375 )\r
376{\r
377 EFI_USB_DEVICE_REQUEST DevReq;\r
378\r
379 ASSERT (UsbIo != NULL);\r
380 ASSERT (Status != NULL);\r
381\r
382 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
383\r
384 switch (Recipient) {\r
385 case USB_TARGET_DEVICE:\r
386 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;\r
387 break;\r
388\r
389 case USB_TARGET_INTERFACE:\r
390 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;\r
391 break;\r
392\r
393 case USB_TARGET_ENDPOINT:\r
394 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;\r
395 break;\r
396\r
397 default:\r
398 break;\r
399 }\r
400\r
401 //\r
402 // Fill device request, see USB1.1 spec\r
403 //\r
404 DevReq.Request = USB_REQ_SET_FEATURE;\r
405 DevReq.Value = Value;\r
406 DevReq.Index = Target;\r
407\r
408 return UsbIo->UsbControlTransfer (\r
409 UsbIo,\r
410 &DevReq,\r
411 EfiUsbNoData,\r
412 PcdGet32 (PcdUsbTransferTimeoutValue),\r
413 NULL,\r
414 0,\r
415 Status\r
416 );\r
417}\r
418\r
419/**\r
420 Clear the specified feature of the specified device.\r
421\r
422 Submit a USB clear device feature request for the USB device specified by UsbIo,\r
423 Recipient, and Target to the value specified by Value. The status of the transfer\r
424 is returned in Status.\r
425 If UsbIo is NULL, then ASSERT().\r
426 If Status is NULL, then ASSERT().\r
427\r
428 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
429 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
430 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
431 include file Usb.h.\r
432 @param Value The value of the feature to be cleared.\r
433 @param Target The index of the device to be cleared.\r
434 @param Status A pointer to the status of the transfer.\r
435\r
436 @retval EFI_SUCCESS The request executed successfully.\r
437 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
438 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
439 The transfer status is returned in Status.\r
440\r
441**/\r
442EFI_STATUS\r
443EFIAPI\r
444UsbClearFeature (\r
445 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
446 IN USB_TYPES_DEFINITION Recipient,\r
447 IN UINT16 Value,\r
448 IN UINT16 Target,\r
449 OUT UINT32 *Status\r
450 )\r
451{\r
452 EFI_USB_DEVICE_REQUEST DevReq;\r
453\r
454 ASSERT (UsbIo != NULL);\r
455 ASSERT (Status != NULL);\r
456\r
457 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
458\r
459 switch (Recipient) {\r
460 case USB_TARGET_DEVICE:\r
461 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;\r
462 break;\r
463\r
464 case USB_TARGET_INTERFACE:\r
465 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;\r
466 break;\r
467\r
468 case USB_TARGET_ENDPOINT:\r
469 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;\r
470 break;\r
471\r
472 default:\r
473 break;\r
474 }\r
475\r
476 //\r
477 // Fill device request, see USB1.1 spec\r
478 //\r
479 DevReq.Request = USB_REQ_CLEAR_FEATURE;\r
480 DevReq.Value = Value;\r
481 DevReq.Index = Target;\r
482\r
483 return UsbIo->UsbControlTransfer (\r
484 UsbIo,\r
485 &DevReq,\r
486 EfiUsbNoData,\r
487 PcdGet32 (PcdUsbTransferTimeoutValue),\r
488 NULL,\r
489 0,\r
490 Status\r
491 );\r
492}\r
493\r
494/**\r
495 Get the status of the specified device.\r
496\r
497 Submit a USB device get status request for the USB device specified by UsbIo,\r
498 Recipient, and Target and place the result in the buffer specified by DeviceStatus.\r
499 The status of the transfer is returned in Status.\r
500 If UsbIo is NULL, then ASSERT().\r
501 If DeviceStatus is NULL, then ASSERT().\r
502 If Status is NULL, then ASSERT().\r
503\r
504 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
505 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
506 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
507 include file Usb.h.\r
508 @param Target The index of the device to be get the status of.\r
509 @param DeviceStatus A pointer to the device status to be retrieved.\r
510 @param Status A pointer to the status of the transfer.\r
511\r
512 @retval EFI_SUCCESS The request executed successfully.\r
513 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
514 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
515 The transfer status is returned in Status.\r
516\r
517**/\r
518EFI_STATUS\r
519EFIAPI\r
520UsbGetStatus (\r
521 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
522 IN USB_TYPES_DEFINITION Recipient,\r
523 IN UINT16 Target,\r
524 OUT UINT16 *DeviceStatus,\r
525 OUT UINT32 *Status\r
526 )\r
527{\r
528 EFI_USB_DEVICE_REQUEST DevReq;\r
529\r
530 ASSERT (UsbIo != NULL);\r
531 ASSERT (DeviceStatus != NULL);\r
532 ASSERT (Status != NULL);\r
533\r
534 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
535\r
536 switch (Recipient) {\r
537 case USB_TARGET_DEVICE:\r
538 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;\r
539 break;\r
540\r
541 case USB_TARGET_INTERFACE:\r
542 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;\r
543 break;\r
544\r
545 case USB_TARGET_ENDPOINT:\r
546 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;\r
547 break;\r
548\r
549 default:\r
550 break;\r
551 }\r
552\r
553 //\r
554 // Fill device request, see USB1.1 spec\r
555 //\r
556 DevReq.Request = USB_REQ_GET_STATUS;\r
557 DevReq.Value = 0;\r
558 DevReq.Index = Target;\r
559 DevReq.Length = 2;\r
560\r
561 return UsbIo->UsbControlTransfer (\r
562 UsbIo,\r
563 &DevReq,\r
564 EfiUsbDataIn,\r
565 PcdGet32 (PcdUsbTransferTimeoutValue),\r
566 DeviceStatus,\r
567 2,\r
568 Status\r
569 );\r
570}\r
571\r
572/**\r
573 Clear halt feature of the specified usb endpoint.\r
574\r
575 Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.\r
576 If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.\r
577 If the endpoint descriptor is found, then clear the halt feature of this USB endpoint.\r
578 The status of the transfer is returned in Status.\r
579 If UsbIo is NULL, then ASSERT().\r
580 If Status is NULL, then ASSERT().\r
581\r
582 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
583 @param Endpoint The endpoint address.\r
584 @param Status A pointer to the status of the transfer.\r
585\r
586 @retval EFI_SUCCESS The request executed successfully.\r
587 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
588 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
589 The transfer status is returned in Status.\r
590 @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found\r
591\r
592**/\r
593EFI_STATUS\r
594EFIAPI\r
595UsbClearEndpointHalt (\r
596 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
597 IN UINT8 Endpoint,\r
598 OUT UINT32 *Status\r
599 )\r
600{\r
601 EFI_STATUS Result;\r
602 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r
603 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
604 UINT8 Index;\r
605\r
606 ASSERT (UsbIo != NULL);\r
607 ASSERT (Status != NULL);\r
608\r
609 ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r
610 //\r
611 // First search the endpoint descriptor for that endpoint addr\r
612 //\r
613 Result = UsbIo->UsbGetInterfaceDescriptor (\r
614 UsbIo,\r
615 &InterfaceDescriptor\r
616 );\r
617 if (EFI_ERROR (Result)) {\r
618 return Result;\r
619 }\r
620\r
621 for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {\r
622 Result = UsbIo->UsbGetEndpointDescriptor (\r
623 UsbIo,\r
624 Index,\r
625 &EndpointDescriptor\r
626 );\r
627 if (EFI_ERROR (Result)) {\r
628 continue;\r
629 }\r
630\r
631 if (EndpointDescriptor.EndpointAddress == Endpoint) {\r
632 break;\r
633 }\r
634 }\r
635\r
636 if (Index == InterfaceDescriptor.NumEndpoints) {\r
637 //\r
638 // No such endpoint\r
639 //\r
640 return EFI_NOT_FOUND;\r
641 }\r
642\r
643 Result = UsbClearFeature (\r
644 UsbIo,\r
645 USB_TARGET_ENDPOINT,\r
646 USB_FEATURE_ENDPOINT_HALT,\r
647 EndpointDescriptor.EndpointAddress,\r
648 Status\r
649 );\r
650\r
651 return Result;\r
652}\r