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