]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbio.c
Fix the CLASSPATH
[mirror_edk2.git] / EdkModulePkg / Bus / Usb / UsbBus / Dxe / usbio.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12 Module Name:\r
13\r
14 UsbIo.c\r
15\r
16 Abstract:\r
17\r
18 USB I/O Abstraction Driver\r
19\r
20 Revision History\r
21\r
22--*/\r
23\r
24#include "usbbus.h"\r
25\r
26//\r
27// USB I/O Support Function Prototypes\r
28//\r
29STATIC\r
30EFI_STATUS\r
31EFIAPI\r
32UsbControlTransfer (\r
33 IN EFI_USB_IO_PROTOCOL *This,\r
34 IN EFI_USB_DEVICE_REQUEST *Request,\r
35 IN EFI_USB_DATA_DIRECTION Direction,\r
36 IN UINT32 Timeout,\r
37 IN OUT VOID *Data, OPTIONAL\r
38 IN UINTN DataLength, OPTIONAL\r
39 OUT UINT32 *Status\r
40 );\r
41\r
42STATIC\r
43EFI_STATUS\r
44EFIAPI\r
45UsbBulkTransfer (\r
46 IN EFI_USB_IO_PROTOCOL *This,\r
47 IN UINT8 DeviceEndpoint,\r
48 IN OUT VOID *Data,\r
49 IN OUT UINTN *DataLength,\r
50 IN UINTN Timeout,\r
51 OUT UINT32 *Status\r
52 );\r
53\r
54STATIC\r
55EFI_STATUS\r
56EFIAPI\r
57UsbAsyncInterruptTransfer (\r
58 IN EFI_USB_IO_PROTOCOL * This,\r
59 IN UINT8 DeviceEndpoint,\r
60 IN BOOLEAN IsNewTransfer,\r
61 IN UINTN PollingInterval, OPTIONAL\r
62 IN UINTN DataLength, OPTIONAL\r
63 IN EFI_ASYNC_USB_TRANSFER_CALLBACK InterruptCallBack, OPTIONAL\r
64 IN VOID *Context OPTIONAL\r
65 );\r
66\r
67STATIC\r
68EFI_STATUS\r
69EFIAPI\r
70UsbSyncInterruptTransfer (\r
71 IN EFI_USB_IO_PROTOCOL *This,\r
72 IN UINT8 DeviceEndpoint,\r
73 IN OUT VOID *Data,\r
74 IN OUT UINTN *DataLength,\r
75 IN UINTN Timeout,\r
76 OUT UINT32 *Status\r
77 );\r
78\r
79STATIC\r
80EFI_STATUS\r
81EFIAPI\r
82UsbIsochronousTransfer (\r
83 IN EFI_USB_IO_PROTOCOL *This,\r
84 IN UINT8 DeviceEndpoint,\r
85 IN OUT VOID *Data,\r
86 IN UINTN DataLength,\r
87 OUT UINT32 *Status\r
88 );\r
89\r
90STATIC\r
91EFI_STATUS\r
92EFIAPI\r
93UsbAsyncIsochronousTransfer (\r
94 IN EFI_USB_IO_PROTOCOL * This,\r
95 IN UINT8 DeviceEndpoint,\r
96 IN OUT VOID *Data,\r
97 IN UINTN DataLength,\r
98 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack,\r
99 IN VOID *Context OPTIONAL\r
100 );\r
101\r
102extern\r
103EFI_STATUS\r
104EFIAPI\r
105UsbPortReset (\r
106 IN EFI_USB_IO_PROTOCOL *This\r
107 );\r
108\r
109STATIC\r
110EFI_STATUS\r
111EFIAPI\r
112UsbGetDeviceDescriptor (\r
113 IN EFI_USB_IO_PROTOCOL *This,\r
114 OUT EFI_USB_DEVICE_DESCRIPTOR *DeviceDescriptor\r
115 );\r
116\r
117STATIC\r
118EFI_STATUS\r
119EFIAPI\r
120UsbGetActiveConfigDescriptor (\r
121 IN EFI_USB_IO_PROTOCOL *This,\r
122 OUT EFI_USB_CONFIG_DESCRIPTOR *ConfigurationDescriptor\r
123 );\r
124\r
125STATIC\r
126EFI_STATUS\r
127EFIAPI\r
128UsbGetInterfaceDescriptor (\r
129 IN EFI_USB_IO_PROTOCOL *This,\r
130 OUT EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescriptor\r
131 );\r
132\r
133STATIC\r
134EFI_STATUS\r
135EFIAPI\r
136UsbGetEndpointDescriptor (\r
137 IN EFI_USB_IO_PROTOCOL *This,\r
138 IN UINT8 EndpointIndex,\r
139 OUT EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor\r
140 );\r
141\r
142STATIC\r
143EFI_STATUS\r
144EFIAPI\r
145UsbGetStringDescriptor (\r
146 IN EFI_USB_IO_PROTOCOL *This,\r
147 IN UINT16 LangID,\r
148 IN UINT8 StringIndex,\r
149 OUT CHAR16 **String\r
150 );\r
151\r
152STATIC\r
153EFI_STATUS\r
154EFIAPI\r
155UsbGetSupportedLanguages (\r
156 IN EFI_USB_IO_PROTOCOL *This,\r
157 OUT UINT16 **LangIDTable,\r
158 OUT UINT16 *TableSize\r
159 );\r
160\r
161//\r
162// USB I/O Interface structure\r
163//\r
164STATIC EFI_USB_IO_PROTOCOL UsbIoInterface = {\r
165 UsbControlTransfer,\r
166 UsbBulkTransfer,\r
167 UsbAsyncInterruptTransfer,\r
168 UsbSyncInterruptTransfer,\r
169 UsbIsochronousTransfer,\r
170 UsbAsyncIsochronousTransfer,\r
171 UsbGetDeviceDescriptor,\r
172 UsbGetActiveConfigDescriptor,\r
173 UsbGetInterfaceDescriptor,\r
174 UsbGetEndpointDescriptor,\r
175 UsbGetStringDescriptor,\r
176 UsbGetSupportedLanguages,\r
177 UsbPortReset\r
178};\r
179\r
180VOID\r
181InitializeUsbIoInstance (\r
182 IN USB_IO_CONTROLLER_DEVICE *UsbIoController\r
183 )\r
71a62114 184/*++\r
185\r
186Routine Description:\r
187\r
188 Initialize the instance of UsbIo controller\r
189\r
190Arguments:\r
191\r
192 UsbIoController - A pointer to controller structure of UsbIo\r
193\r
194Returns:\r
195\r
196--*/\r
878ddf1f 197{\r
198 //\r
199 // Copy EFI_USB_IO protocol instance\r
200 //\r
201 CopyMem (\r
202 &UsbIoController->UsbIo,\r
203 &UsbIoInterface,\r
204 sizeof (EFI_USB_IO_PROTOCOL)\r
205 );\r
206}\r
207//\r
208// Implementation\r
209//\r
210STATIC\r
211EFI_STATUS\r
212EFIAPI\r
213UsbControlTransfer (\r
214 IN EFI_USB_IO_PROTOCOL *This,\r
215 IN EFI_USB_DEVICE_REQUEST *Request,\r
216 IN EFI_USB_DATA_DIRECTION Direction,\r
217 IN UINT32 Timeout,\r
218 IN OUT VOID *Data, OPTIONAL\r
219 IN UINTN DataLength, OPTIONAL\r
220 OUT UINT32 *Status\r
221 )\r
222/*++\r
223\r
224 Routine Description:\r
225 This function is used to manage a USB device with a control transfer pipe.\r
226\r
227 Arguments:\r
228 This - Indicates calling context.\r
229 Request - A pointer to the USB device request that will be sent to\r
230 the USB device.\r
231 Direction - Indicates the data direction.\r
232 Data - A pointer to the buffer of data that will be transmitted\r
233 to USB device or received from USB device.\r
234 Timeout - Indicates the transfer should be completed within this time\r
235 frame.\r
236 DataLength - The size, in bytes, of the data buffer specified by Data.\r
237 Status - A pointer to the result of the USB transfer.\r
238\r
239 Returns:\r
240 EFI_SUCCESS\r
241 EFI_INVALID_PARAMETER\r
242 EFI_OUT_OF_RESOURCES\r
243 EFI_TIMEOUT\r
244 EFI_DEVICE_ERROR\r
245\r
246--*/\r
247{\r
248 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
562d2849 249\r
878ddf1f 250 EFI_STATUS RetStatus;\r
562d2849 251 USB_IO_DEVICE *UsbIoDev;\r
878ddf1f 252 UINT8 MaxPacketLength;\r
253 UINT32 TransferResult;\r
254 BOOLEAN Disconnected;\r
255 //\r
256 // Parameters Checking\r
257 //\r
258 if (Status == NULL) {\r
259 return EFI_INVALID_PARAMETER;\r
260 }\r
261 \r
262 //\r
263 // leave the HostController's ControlTransfer\r
264 // to perform other parameters checking\r
265 //\r
266 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
562d2849 267 UsbIoDev = UsbIoController->UsbDevice;\r
268\r
269 MaxPacketLength = UsbIoDev->DeviceDescriptor.MaxPacketSize0;\r
878ddf1f 270\r
271 \r
272 if (Request->Request == USB_DEV_CLEAR_FEATURE && \r
273 Request->RequestType == 0x02 && \r
274 Request->Value == EfiUsbEndpointHalt) {\r
275 //\r
276 //Reduce the remove delay time for system response\r
277 //\r
278 IsDeviceDisconnected (UsbIoController, &Disconnected);\r
279 if (!EFI_ERROR (Status) && Disconnected == TRUE) {\r
280 DEBUG ((gUSBErrorLevel, "Device is disconnected when trying reset\n"));\r
281 return EFI_DEVICE_ERROR;\r
282 }\r
283 }\r
878ddf1f 284 //\r
285 // using HostController's ControlTransfer to complete the request\r
286 //\r
562d2849 287 RetStatus = UsbVirtualHcControlTransfer (\r
288 UsbIoDev->BusController,\r
289 UsbIoDev->DeviceAddress,\r
290 UsbIoDev->DeviceSpeed,\r
291 MaxPacketLength,\r
292 Request,\r
293 Direction,\r
294 Data,\r
295 &DataLength,\r
296 (UINTN) Timeout,\r
297 UsbIoDev->Translator,\r
298 &TransferResult\r
299 );\r
300\r
878ddf1f 301 *Status = TransferResult;\r
302\r
303 if (Request->Request == USB_DEV_CLEAR_FEATURE && \r
304 Request->RequestType == 0x02 && \r
305 Request->Value == EfiUsbEndpointHalt) {\r
306 //\r
307 // This is a UsbClearEndpointHalt request\r
308 // Need to clear data toggle\r
309 // Request.Index == EndpointAddress\r
310 //\r
311 if (!EFI_ERROR (RetStatus) && TransferResult == EFI_USB_NOERROR) {\r
312 SetDataToggleBit (\r
313 This,\r
314 (UINT8) Request->Index,\r
315 0\r
316 );\r
317 }\r
318 }\r
319 return RetStatus;\r
320}\r
321\r
322STATIC\r
323EFI_STATUS\r
324EFIAPI\r
325UsbBulkTransfer (\r
326 IN EFI_USB_IO_PROTOCOL *This,\r
327 IN UINT8 DeviceEndpoint,\r
328 IN OUT VOID *Data,\r
329 IN OUT UINTN *DataLength,\r
330 IN UINTN Timeout,\r
331 OUT UINT32 *Status\r
332 )\r
333/*++\r
334\r
335 Routine Description:\r
336 This function is used to manage a USB device with the bulk transfer pipe.\r
337\r
338 Arguments:\r
339 This - Indicates calling context.\r
340 DeviceEndpoint - The destination USB device endpoint to which the device\r
341 request is being sent.\r
342 Data - A pointer to the buffer of data that will be transmitted\r
343 to USB device or received from USB device.\r
344 DataLength - On input, the size, in bytes, of the data buffer\r
345 specified by Data. On output, the number of bytes that\r
346 were actually transferred.\r
347 Timeout - Indicates the transfer should be completed within this\r
348 time frame.\r
349 Status - This parameter indicates the USB transfer status.\r
350\r
351 Returns:\r
352 EFI_SUCCESS\r
353 EFI_INVALID_PARAMETER\r
354 EFI_OUT_OF_RESOURCES\r
355 EFI_TIMEOUT\r
356 EFI_DEVICE_ERROR\r
357\r
358--*/\r
359{\r
360 USB_IO_DEVICE *UsbIoDev;\r
562d2849 361 UINTN MaxPacketLength;\r
878ddf1f 362 UINT8 DataToggle;\r
363 UINT8 OldToggle;\r
364 EFI_STATUS RetStatus;\r
878ddf1f 365 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
366 ENDPOINT_DESC_LIST_ENTRY *EndPointListEntry;\r
562d2849 367 UINT8 DataBuffersNumber;\r
71a62114 368 UINT32 TransferResult;\r
562d2849 369 \r
370 DataBuffersNumber = 1;\r
371 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
372 UsbIoDev = UsbIoController->UsbDevice;\r
878ddf1f 373\r
374 //\r
375 // Parameters Checking\r
376 //\r
377 if ((DeviceEndpoint & 0x7F) == 0) {\r
378 return EFI_INVALID_PARAMETER;\r
379 }\r
380\r
381 if ((DeviceEndpoint & 0x7F) > 15) {\r
382 return EFI_INVALID_PARAMETER;\r
383 }\r
384\r
385 if (Status == NULL) {\r
386 return EFI_INVALID_PARAMETER;\r
387 }\r
388\r
389 EndPointListEntry = FindEndPointListEntry (\r
390 This,\r
391 DeviceEndpoint\r
392 );\r
393\r
394 if (EndPointListEntry == NULL) {\r
395 return EFI_INVALID_PARAMETER;\r
396 }\r
397\r
398 if ((EndPointListEntry->EndpointDescriptor.Attributes & 0x03) != 0x02) {\r
399 return EFI_INVALID_PARAMETER;\r
400 }\r
401 \r
402 //\r
403 // leave the HostController's BulkTransfer\r
404 // to perform other parameters checking\r
405 //\r
406 GetDeviceEndPointMaxPacketLength (\r
407 This,\r
408 DeviceEndpoint,\r
409 &MaxPacketLength\r
410 );\r
411\r
412 GetDataToggleBit (\r
413 This,\r
414 DeviceEndpoint,\r
415 &DataToggle\r
416 );\r
417\r
418 OldToggle = DataToggle;\r
419\r
420 //\r
421 // using HostController's BulkTransfer to complete the request\r
422 //\r
562d2849 423 RetStatus = UsbVirtualHcBulkTransfer (\r
424 UsbIoDev->BusController,\r
425 UsbIoDev->DeviceAddress,\r
426 DeviceEndpoint,\r
427 UsbIoDev->DeviceSpeed,\r
428 MaxPacketLength,\r
429 DataBuffersNumber,\r
430 &Data,\r
431 DataLength,\r
432 &DataToggle,\r
433 Timeout,\r
434 UsbIoDev->Translator,\r
435 &TransferResult\r
436 );\r
878ddf1f 437\r
438 if (OldToggle != DataToggle) {\r
439 //\r
440 // Write the toggle back\r
441 //\r
442 SetDataToggleBit (\r
443 This,\r
444 DeviceEndpoint,\r
445 DataToggle\r
446 );\r
447 }\r
448\r
449 *Status = TransferResult;\r
450\r
451 return RetStatus;\r
452}\r
453\r
454STATIC\r
455EFI_STATUS\r
456EFIAPI\r
457UsbSyncInterruptTransfer (\r
458 IN EFI_USB_IO_PROTOCOL *This,\r
459 IN UINT8 DeviceEndpoint,\r
460 IN OUT VOID *Data,\r
461 IN OUT UINTN *DataLength,\r
462 IN UINTN Timeout,\r
463 OUT UINT32 *Status\r
464 )\r
465/*++\r
466\r
467 Routine Description:\r
468 Usb Sync Interrupt Transfer\r
469\r
470 Arguments:\r
471 This - Indicates calling context.\r
472 DeviceEndpoint - The destination USB device endpoint to which the device\r
473 request is being sent.\r
474 Data - A pointer to the buffer of data that will be transmitted\r
475 to USB device or received from USB device.\r
476 DataLength - On input, the size, in bytes, of the data buffer\r
477 specified by Data. On output, the number of bytes that\r
478 were actually transferred.\r
479 Timeout - Indicates the transfer should be completed within this\r
480 time frame.\r
481 Status - This parameter indicates the USB transfer status.\r
482\r
483 Returns:\r
484 EFI_SUCCESS\r
485 EFI_INVALID_PARAMETER\r
486 EFI_OUT_OF_RESOURCES\r
487 EFI_TIMEOUT\r
488 EFI_DEVICE_ERROR\r
489\r
490--*/\r
491{\r
562d2849 492 USB_IO_DEVICE *UsbIoDev;\r
493 UINTN MaxPacketLength;\r
494 UINT8 DataToggle;\r
495 UINT8 OldToggle;\r
496 EFI_STATUS RetStatus;\r
497 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
498 ENDPOINT_DESC_LIST_ENTRY *EndPointListEntry;\r
878ddf1f 499\r
500 //\r
501 // Parameters Checking\r
502 //\r
503 if ((DeviceEndpoint & 0x7F) == 0) {\r
504 return EFI_INVALID_PARAMETER;\r
505 }\r
506\r
507 if ((DeviceEndpoint & 0x7F) > 15) {\r
508 return EFI_INVALID_PARAMETER;\r
509 }\r
510\r
511 if (Status == NULL) {\r
512 return EFI_INVALID_PARAMETER;\r
513 }\r
514\r
515 EndPointListEntry = FindEndPointListEntry (\r
516 This,\r
517 DeviceEndpoint\r
518 );\r
519\r
520 if (EndPointListEntry == NULL) {\r
521 return EFI_INVALID_PARAMETER;\r
522 }\r
523\r
524 if ((EndPointListEntry->EndpointDescriptor.Attributes & 0x03) != 0x03) {\r
525 return EFI_INVALID_PARAMETER;\r
526 }\r
527 \r
528 //\r
529 // leave the HostController's SyncInterruptTransfer\r
530 // to perform other parameters checking\r
531 //\r
532 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
533 UsbIoDev = UsbIoController->UsbDevice;\r
878ddf1f 534 GetDeviceEndPointMaxPacketLength (\r
535 This,\r
536 DeviceEndpoint,\r
537 &MaxPacketLength\r
538 );\r
539\r
540 GetDataToggleBit (\r
541 This,\r
542 DeviceEndpoint,\r
543 &DataToggle\r
544 );\r
545\r
546 OldToggle = DataToggle;\r
547 //\r
548 // using HostController's SyncInterruptTransfer to complete the request\r
549 //\r
562d2849 550 RetStatus = UsbVirtualHcSyncInterruptTransfer (\r
551 UsbIoDev->BusController,\r
552 UsbIoDev->DeviceAddress,\r
553 DeviceEndpoint,\r
554 UsbIoDev->DeviceSpeed,\r
555 MaxPacketLength,\r
556 Data,\r
557 DataLength,\r
558 &DataToggle,\r
559 Timeout,\r
560 UsbIoDev->Translator,\r
561 Status\r
562 );\r
878ddf1f 563\r
564 if (OldToggle != DataToggle) {\r
565 //\r
566 // Write the toggle back\r
567 //\r
568 SetDataToggleBit (\r
569 This,\r
570 DeviceEndpoint,\r
571 DataToggle\r
572 );\r
573 }\r
574\r
575 return RetStatus;\r
576}\r
577\r
578STATIC\r
579EFI_STATUS\r
580EFIAPI\r
581UsbAsyncInterruptTransfer (\r
582 IN EFI_USB_IO_PROTOCOL *This,\r
583 IN UINT8 DeviceEndpoint,\r
584 IN BOOLEAN IsNewTransfer,\r
585 IN UINTN PollingInterval, OPTIONAL\r
586 IN UINTN DataLength, OPTIONAL\r
587 IN EFI_ASYNC_USB_TRANSFER_CALLBACK InterruptCallBack, OPTIONAL\r
588 IN VOID *Context OPTIONAL\r
589 )\r
590/*++\r
591\r
592 Routine Description:\r
593 Usb Async Interrput Transfer\r
594\r
595 Arguments:\r
596 This - Indicates calling context.\r
597 DeviceEndpoint - The destination USB device endpoint to which the\r
598 device request is being sent.\r
599 IsNewTransfer - If TRUE, a new transfer will be submitted to USB\r
600 controller. If FALSE, the interrupt transfer is\r
601 deleted from the device's interrupt transfer queue.\r
602 PollingInterval - Indicates the periodic rate, in milliseconds, that\r
603 the transfer is to be executed.\r
604 DataLength - Specifies the length, in bytes, of the data to be\r
605 received from the USB device.\r
562d2849 606 InterruptCallBack - The Callback function. This function is called if\r
878ddf1f 607 the asynchronous interrupt transfer is completed.\r
608 Context - Passed to InterruptCallback \r
609 Returns:\r
610 EFI_SUCCESS\r
611 EFI_INVALID_PARAMETER\r
612 EFI_OUT_OF_RESOURCES\r
613\r
614--*/\r
615{\r
562d2849 616 USB_IO_DEVICE *UsbIoDev;\r
617 UINTN MaxPacketLength;\r
618 UINT8 DataToggle;\r
619 EFI_STATUS RetStatus;\r
620 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
621 ENDPOINT_DESC_LIST_ENTRY *EndpointListEntry;\r
878ddf1f 622\r
623 //\r
624 // Check endpoint\r
625 //\r
626 if ((DeviceEndpoint & 0x7F) == 0) {\r
627 return EFI_INVALID_PARAMETER;\r
628 }\r
629\r
630 if ((DeviceEndpoint & 0x7F) > 15) {\r
631 return EFI_INVALID_PARAMETER;\r
632 }\r
633\r
634 EndpointListEntry = FindEndPointListEntry (\r
635 This,\r
636 DeviceEndpoint\r
637 );\r
638\r
639 if (EndpointListEntry == NULL) {\r
640 return EFI_INVALID_PARAMETER;\r
641 }\r
642\r
643 if ((EndpointListEntry->EndpointDescriptor.Attributes & 0x03) != 0x03) {\r
644 return EFI_INVALID_PARAMETER;\r
645 }\r
646\r
647 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
648 UsbIoDev = UsbIoController->UsbDevice;\r
878ddf1f 649\r
650 if (!IsNewTransfer) {\r
651 //\r
652 // Delete this transfer\r
653 //\r
562d2849 654 UsbVirtualHcAsyncInterruptTransfer (\r
655 UsbIoDev->BusController,\r
656 UsbIoDev->DeviceAddress,\r
657 DeviceEndpoint,\r
658 UsbIoDev->DeviceSpeed,\r
659 0,\r
660 FALSE,\r
661 &DataToggle,\r
662 PollingInterval,\r
663 DataLength,\r
664 UsbIoDev->Translator,\r
665 NULL,\r
666 NULL\r
667 );\r
878ddf1f 668\r
669 //\r
670 // We need to store the toggle value\r
671 //\r
672 SetDataToggleBit (\r
673 This,\r
674 DeviceEndpoint,\r
675 DataToggle\r
676 );\r
677\r
678 return EFI_SUCCESS;\r
679 }\r
680\r
681 GetDeviceEndPointMaxPacketLength (\r
682 This,\r
683 DeviceEndpoint,\r
684 &MaxPacketLength\r
685 );\r
686\r
687 GetDataToggleBit (\r
688 This,\r
689 DeviceEndpoint,\r
690 &DataToggle\r
691 );\r
692\r
562d2849 693 RetStatus = UsbVirtualHcAsyncInterruptTransfer (\r
694 UsbIoDev->BusController,\r
695 UsbIoDev->DeviceAddress,\r
696 DeviceEndpoint,\r
697 UsbIoDev->DeviceSpeed,\r
698 MaxPacketLength,\r
699 TRUE,\r
700 &DataToggle,\r
701 PollingInterval,\r
702 DataLength,\r
703 UsbIoDev->Translator,\r
704 InterruptCallBack,\r
705 Context\r
706 );\r
878ddf1f 707\r
708 return RetStatus;\r
709}\r
710\r
711STATIC\r
712EFI_STATUS\r
713EFIAPI\r
714UsbIsochronousTransfer (\r
715 IN EFI_USB_IO_PROTOCOL *This,\r
716 IN UINT8 DeviceEndpoint,\r
717 IN OUT VOID *Data,\r
718 IN UINTN DataLength,\r
719 OUT UINT32 *Status\r
720 )\r
721/*++\r
722\r
723 Routine Description:\r
724 Usb Isochronous Transfer\r
725\r
726 Arguments:\r
727 This - Indicates calling context.\r
728 DeviceEndpoint - The destination USB device endpoint to which the\r
729 device request is being sent.\r
730 Data - A pointer to the buffer of data that will be\r
731 transmitted to USB device or received from USB device.\r
732 DataLength - The size, in bytes, of the data buffer specified by\r
733 Data.\r
734 Status - This parameter indicates the USB transfer status.\r
735\r
736 Returns:\r
737 EFI_SUCCESS\r
738 EFI_INVALID_PARAMETER\r
739 EFI_OUT_OF_RESOURCES\r
740 EFI_TIMEOUT\r
741 EFI_DEVICE_ERROR\r
742 EFI_UNSUPPORTED\r
743--*/\r
744{\r
745 //\r
746 // Currently we don't support this transfer\r
747 //\r
748 return EFI_UNSUPPORTED;\r
749}\r
750\r
751STATIC\r
752EFI_STATUS\r
753EFIAPI\r
754UsbAsyncIsochronousTransfer (\r
755 IN EFI_USB_IO_PROTOCOL *This,\r
756 IN UINT8 DeviceEndpoint,\r
757 IN OUT VOID *Data,\r
758 IN UINTN DataLength,\r
759 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack,\r
760 IN VOID *Context OPTIONAL\r
761 )\r
762/*++\r
763\r
764Routine Description:\r
765\r
766 Usb Async Isochronous Transfer\r
767\r
768Arguments:\r
769\r
770 This - EFI_USB_IO_PROTOCOL\r
771 DeviceEndpoint - DeviceEndpoint number\r
772 Data - Data to transfer\r
773 DataLength - DataLength\r
774 IsochronousCallBack - Isochronous CallBack function\r
775 Context - Passed to IsochronousCallBack function\r
776Returns:\r
777\r
778 EFI_UNSUPPORTED - Unsupported now\r
779\r
780--*/\r
781{\r
782 //\r
783 // Currently we don't support this transfer\r
784 //\r
785 return EFI_UNSUPPORTED;\r
786}\r
787//\r
788// Here is new definitions\r
789//\r
790STATIC\r
791EFI_STATUS\r
792EFIAPI\r
793UsbGetDeviceDescriptor (\r
794 IN EFI_USB_IO_PROTOCOL *This,\r
795 OUT EFI_USB_DEVICE_DESCRIPTOR *DeviceDescriptor\r
796 )\r
797/*++\r
798\r
799 Routine Description:\r
800 Retrieves the USB Device Descriptor.\r
801\r
802 Arguments:\r
803 This - Indicates the calling context.\r
804 DeviceDescriptor - A pointer to the caller allocated USB Device\r
805 Descriptor.\r
806\r
807 Returns:\r
808 EFI_SUCCESS\r
809 EFI_INVALID_PARAMETER\r
810 EFI_NOT_FOUND\r
811\r
812--*/\r
813{\r
814 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
815 USB_IO_DEVICE *UsbIoDev;\r
816\r
817 //\r
818 // This function just wrapps UsbGetDeviceDescriptor.\r
819 //\r
820 \r
821 if (DeviceDescriptor == NULL) {\r
822 return EFI_INVALID_PARAMETER;\r
823 }\r
824\r
825 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
826 UsbIoDev = UsbIoController->UsbDevice;\r
827\r
828 if (!UsbIoDev->IsConfigured) {\r
829 return EFI_NOT_FOUND;\r
830 }\r
831\r
832 CopyMem (\r
833 DeviceDescriptor,\r
834 &UsbIoDev->DeviceDescriptor,\r
835 sizeof (EFI_USB_DEVICE_DESCRIPTOR)\r
836 );\r
837\r
838 return EFI_SUCCESS;\r
839}\r
840\r
841STATIC\r
842EFI_STATUS\r
843EFIAPI\r
844UsbGetActiveConfigDescriptor (\r
845 IN EFI_USB_IO_PROTOCOL *This,\r
846 OUT EFI_USB_CONFIG_DESCRIPTOR *ConfigurationDescriptor\r
847 )\r
848/*++\r
849\r
850 Routine Description:\r
851 Retrieves the current USB configuration Descriptor.\r
852\r
853 Arguments:\r
854 This - Indicates the calling context.\r
855 ConfigurationDescriptor - A pointer to the caller allocated USB active\r
856 Configuration Descriptor.\r
857\r
858 Returns:\r
859 EFI_SUCCESS\r
860 EFI_INVALID_PARAMETER\r
861 EFI_NOT_FOUND\r
862\r
863--*/\r
864{\r
865 USB_IO_DEVICE *UsbIoDev;\r
866 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
867\r
868 //\r
869 // This function just wrapps UsbGetActiveConfigDescriptor.\r
870 //\r
871 if (ConfigurationDescriptor == NULL) {\r
872 return EFI_INVALID_PARAMETER;\r
873 }\r
874\r
875 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
876 UsbIoDev = UsbIoController->UsbDevice;\r
877\r
878 if (!UsbIoDev->IsConfigured) {\r
879 return EFI_NOT_FOUND;\r
880 }\r
881\r
882 CopyMem (\r
883 ConfigurationDescriptor,\r
884 &(UsbIoDev->ActiveConfig->CongfigDescriptor),\r
885 sizeof (EFI_USB_CONFIG_DESCRIPTOR)\r
886 );\r
887\r
888 return EFI_SUCCESS;\r
889}\r
890\r
891STATIC\r
892EFI_STATUS\r
893EFIAPI\r
894UsbGetInterfaceDescriptor (\r
895 IN EFI_USB_IO_PROTOCOL *This,\r
896 OUT EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescriptor\r
897 )\r
898/*++\r
899\r
900 Routine Description:\r
901 Retrieves the interface Descriptor for that controller.\r
902\r
903 Arguments:\r
904 This - Indicates the calling context.\r
905 InterfaceDescriptor - A pointer to the caller allocated USB interface\r
906 Descriptor.\r
907\r
908 Returns:\r
909 EFI_SUCCESS\r
910 EFI_INVALID_PARAMETER\r
911 EFI_NOT_FOUND\r
912\r
913--*/\r
914{\r
915 INTERFACE_DESC_LIST_ENTRY *InterfaceListEntry;\r
916\r
917 if (InterfaceDescriptor == NULL) {\r
918 return EFI_INVALID_PARAMETER;\r
919 }\r
920\r
921 InterfaceListEntry = FindInterfaceListEntry (This);\r
922\r
923 if (InterfaceListEntry == NULL) {\r
924 return EFI_NOT_FOUND;\r
925 }\r
926\r
927 CopyMem (\r
928 InterfaceDescriptor,\r
929 &(InterfaceListEntry->InterfaceDescriptor),\r
930 sizeof (EFI_USB_INTERFACE_DESCRIPTOR)\r
931 );\r
932\r
933 return EFI_SUCCESS;\r
934}\r
935\r
936STATIC\r
937EFI_STATUS\r
938EFIAPI\r
939UsbGetEndpointDescriptor (\r
940 IN EFI_USB_IO_PROTOCOL *This,\r
941 IN UINT8 EndpointIndex,\r
942 OUT EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor\r
943 )\r
944/*++\r
945\r
946 Routine Description:\r
947 Retrieves the endpoint Descriptor for a given endpoint.\r
948\r
949 Arguments:\r
950 This - Indicates the calling context.\r
951 EndpointIndex - Indicates which endpoint descriptor to retrieve.\r
952 The valid range is 0..15.\r
953 EndpointDescriptor - A pointer to the caller allocated USB Endpoint\r
954 Descriptor of a USB controller.\r
955\r
956 Returns:\r
957 EFI_SUCCESS - The endpoint descriptor was retrieved successfully.\r
958 EFI_INVALID_PARAMETER - EndpointIndex is not valid.\r
959 - EndpointDescriptor is NULL.\r
960 EFI_NOT_FOUND - The endpoint descriptor cannot be found.\r
961 The device may not be correctly configured.\r
962\r
963--*/\r
964{\r
965 INTERFACE_DESC_LIST_ENTRY *InterfaceListEntry;\r
966 LIST_ENTRY *EndpointListHead;\r
967 ENDPOINT_DESC_LIST_ENTRY *EndpointListEntry;\r
968\r
969 if (EndpointDescriptor == NULL) {\r
970 return EFI_INVALID_PARAMETER;\r
971 }\r
972\r
973 if (EndpointIndex > 15) {\r
974 return EFI_INVALID_PARAMETER;\r
975 }\r
976\r
977 InterfaceListEntry = FindInterfaceListEntry (This);\r
978\r
979 if (InterfaceListEntry == NULL) {\r
980 return EFI_NOT_FOUND;\r
981 }\r
982\r
983 EndpointListHead = (LIST_ENTRY *) (&InterfaceListEntry->EndpointDescListHead);\r
984 EndpointListEntry = (ENDPOINT_DESC_LIST_ENTRY *) (EndpointListHead->ForwardLink);\r
985\r
986 if (EndpointIndex >= InterfaceListEntry->InterfaceDescriptor.NumEndpoints) {\r
987 return EFI_NOT_FOUND;\r
988 }\r
989 //\r
990 // Loop all endpoint descriptor to get match one.\r
991 //\r
992 while (EndpointIndex != 0) {\r
993 EndpointListEntry = (ENDPOINT_DESC_LIST_ENTRY *) (EndpointListEntry->Link.ForwardLink);\r
994 EndpointIndex--;\r
995 }\r
996\r
997 CopyMem (\r
998 EndpointDescriptor,\r
999 &EndpointListEntry->EndpointDescriptor,\r
1000 sizeof (EFI_USB_ENDPOINT_DESCRIPTOR)\r
1001 );\r
1002\r
1003 return EFI_SUCCESS;\r
1004}\r
1005\r
1006STATIC\r
1007EFI_STATUS\r
1008EFIAPI\r
1009UsbGetSupportedLanguages (\r
1010 IN EFI_USB_IO_PROTOCOL *This,\r
1011 OUT UINT16 **LangIDTable,\r
1012 OUT UINT16 *TableSize\r
1013 )\r
1014/*++\r
1015\r
1016 Routine Description:\r
1017 Get all the languages that the USB device supports\r
1018\r
1019 Arguments:\r
1020 This - Indicates the calling context.\r
1021 LangIDTable - Language ID for the string the caller wants to get.\r
1022 TableSize - The size, in bytes, of the table LangIDTable.\r
1023\r
1024 Returns:\r
1025 EFI_SUCCESS\r
1026 EFI_NOT_FOUND\r
1027\r
1028--*/\r
1029{\r
1030 USB_IO_DEVICE *UsbIoDev;\r
1031 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
1032 UINTN Index;\r
1033 BOOLEAN Found;\r
1034\r
1035 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
1036 UsbIoDev = UsbIoController->UsbDevice;\r
1037\r
1038 Found = FALSE;\r
1039 Index = 0;\r
1040 //\r
1041 // Loop language table\r
1042 //\r
1043 while (UsbIoDev->LangID[Index]) {\r
1044 Found = TRUE;\r
1045 Index++;\r
1046 }\r
1047\r
1048 if (!Found) {\r
1049 return EFI_NOT_FOUND;\r
1050 }\r
1051\r
1052 *LangIDTable = UsbIoDev->LangID;\r
1053 *TableSize = (UINT16) Index;\r
1054\r
1055 return EFI_SUCCESS;\r
1056}\r
1057\r
1058STATIC\r
1059EFI_STATUS\r
1060EFIAPI\r
1061UsbGetStringDescriptor (\r
1062 IN EFI_USB_IO_PROTOCOL *This,\r
1063 IN UINT16 LangID,\r
1064 IN UINT8 StringIndex,\r
1065 OUT CHAR16 **String\r
1066 )\r
1067/*++\r
1068\r
1069 Routine Description:\r
1070 Get a given string descriptor\r
1071\r
1072 Arguments:\r
1073 This - Indicates the calling context.\r
1074 LangID - The Language ID for the string being retrieved.\r
1075 StringIndex - The ID of the string being retrieved.\r
1076 String - A pointer to a buffer allocated by this function\r
1077 with AllocatePool() to store the string. If this\r
1078 function returns EFI_SUCCESS, it stores the string\r
1079 the caller wants to get. The caller should release\r
1080 the string buffer with FreePool() after the string\r
1081 is not used any more.\r
1082 Returns:\r
1083 EFI_SUCCESS\r
1084 EFI_NOT_FOUND\r
1085 EFI_OUT_OF_RESOURCES\r
562d2849 1086 EFI_UNSUPPORTED\r
878ddf1f 1087\r
1088--*/\r
1089{\r
1090 UINT32 Status;\r
1091 EFI_STATUS Result;\r
1092 EFI_USB_STRING_DESCRIPTOR *StrDescriptor;\r
1093 UINT8 *Buffer;\r
1094 CHAR16 *UsbString;\r
1095 UINT16 TempBuffer;\r
1096 USB_IO_DEVICE *UsbIoDev;\r
1097 UINT8 Index;\r
1098 BOOLEAN Found;\r
1099 USB_IO_CONTROLLER_DEVICE *UsbIoController;\r
1100\r
1101 if (StringIndex == 0) {\r
1102 return EFI_NOT_FOUND;\r
1103 }\r
1104 //\r
1105 // Search LanguageID, check if it is supported by this device\r
1106 //\r
1107 if (LangID == 0) {\r
1108 return EFI_NOT_FOUND;\r
1109 }\r
1110\r
1111 UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);\r
1112 UsbIoDev = UsbIoController->UsbDevice;\r
1113\r
1114 Found = FALSE;\r
1115 Index = 0;\r
1116 while (UsbIoDev->LangID[Index]) {\r
1117 if (UsbIoDev->LangID[Index] == LangID) {\r
1118 Found = TRUE;\r
1119 break;\r
1120 }\r
1121\r
1122 Index++;\r
1123 }\r
1124\r
1125 if (!Found) {\r
1126 return EFI_NOT_FOUND;\r
1127 }\r
1128 //\r
1129 // Get String Length\r
1130 //\r
1131 Result = UsbGetString (\r
1132 This,\r
1133 LangID,\r
1134 StringIndex,\r
1135 &TempBuffer,\r
1136 2,\r
1137 &Status\r
1138 );\r
1139 if (EFI_ERROR (Result)) {\r
1140 return EFI_NOT_FOUND;\r
1141 }\r
1142\r
1143 StrDescriptor = (EFI_USB_STRING_DESCRIPTOR *) &TempBuffer;\r
1144\r
1145 if (StrDescriptor->Length == 0) {\r
1146 return EFI_UNSUPPORTED;\r
1147 }\r
1148\r
1149 Buffer = AllocateZeroPool (StrDescriptor->Length);\r
1150 if (Buffer == NULL) {\r
1151 return EFI_OUT_OF_RESOURCES;\r
1152 }\r
1153\r
1154 Result = UsbGetString (\r
1155 This,\r
1156 LangID,\r
1157 StringIndex,\r
1158 Buffer,\r
1159 StrDescriptor->Length,\r
1160 &Status\r
1161 );\r
1162\r
1163 if (EFI_ERROR (Result)) {\r
1164 gBS->FreePool (Buffer);\r
1165 return EFI_NOT_FOUND;\r
1166 }\r
1167\r
1168 StrDescriptor = (EFI_USB_STRING_DESCRIPTOR *) Buffer;\r
1169\r
1170 //\r
1171 // UsbString is a UNICODE string\r
1172 //\r
1173 UsbString = AllocateZeroPool (StrDescriptor->Length);\r
1174 if (UsbString == NULL) {\r
1175 gBS->FreePool (Buffer);\r
1176 return EFI_OUT_OF_RESOURCES;\r
1177 }\r
1178\r
1179 CopyMem (\r
1180 (VOID *) UsbString,\r
1181 Buffer + 2,\r
1182 StrDescriptor->Length - 2\r
1183 );\r
1184\r
1185 *String = UsbString;\r
1186\r
1187 gBS->FreePool (Buffer);\r
1188\r
1189 return EFI_SUCCESS;\r
1190}\r