2 Provides the definition of Usb Hc Protocol and OHCI controller
3 private data structure.
5 Copyright (c) 2013-2016 Intel Corporation.
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 #include <Protocol/UsbHostController.h>
26 #include <Protocol/PciIo.h>
28 #include <Guid/EventGroup.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/MemoryAllocationLib.h>
37 #include <IndustryStandard/Pci.h>
40 typedef struct _USB_OHCI_HC_DEV USB_OHCI_HC_DEV
;
44 #include "OhciSched.h"
46 #include "Descriptor.h"
47 #include "ComponentName.h"
48 #include "OhciDebug.h"
50 extern EFI_DRIVER_BINDING_PROTOCOL gOhciDriverBinding
;
51 extern EFI_COMPONENT_NAME_PROTOCOL gOhciComponentName
;
52 extern EFI_COMPONENT_NAME2_PROTOCOL gOhciComponentName2
;
54 #define USB_OHCI_HC_DEV_SIGNATURE SIGNATURE_32('o','h','c','i')
56 typedef struct _HCCA_MEMORY_BLOCK
{
57 UINT32 HccaInterruptTable
[32]; // 32-bit Physical Address to ED_DESCRIPTOR
58 UINT16 HccaFrameNumber
;
60 UINT32 HccaDoneHead
; // 32-bit Physical Address to TD_DESCRIPTOR
65 struct _USB_OHCI_HC_DEV
{
67 EFI_USB_HC_PROTOCOL UsbHc
;
68 EFI_USB2_HC_PROTOCOL Usb2Hc
;
69 EFI_PCI_IO_PROTOCOL
*PciIo
;
70 UINT64 OriginalPciAttributes
;
72 HCCA_MEMORY_BLOCK
*HccaMemoryBlock
;
74 VOID
*HccaMemoryMapping
;
75 UINTN HccaMemoryPages
;
77 ED_DESCRIPTOR
*IntervalList
[6][32];
78 INTERRUPT_CONTEXT_ENTRY
*InterruptContextList
;
83 EFI_EVENT HouseKeeperTimer
;
85 // ExitBootServicesEvent is used to stop the OHC DMA operation
86 // after exit boot service.
88 EFI_EVENT ExitBootServiceEvent
;
90 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
93 #define USB_OHCI_HC_DEV_FROM_THIS(a) CR(a, USB_OHCI_HC_DEV, UsbHc, USB_OHCI_HC_DEV_SIGNATURE)
94 #define USB2_OHCI_HC_DEV_FROM_THIS(a) CR(a, USB_OHCI_HC_DEV, Usb2Hc, USB_OHCI_HC_DEV_SIGNATURE)
101 Provides software reset for the USB host controller.
103 @param This This EFI_USB_HC_PROTOCOL instance.
104 @param Attributes A bit mask of the reset operation to perform.
106 @retval EFI_SUCCESS The reset operation succeeded.
107 @retval EFI_INVALID_PARAMETER Attributes is not valid.
108 @retval EFI_UNSUPPOURTED The type of reset specified by Attributes is
109 not currently supported by the host controller.
110 @retval EFI_DEVICE_ERROR Host controller isn't halted to reset.
116 IN EFI_USB_HC_PROTOCOL
*This
,
120 Retrieve the current state of the USB host controller.
122 @param This This EFI_USB_HC_PROTOCOL instance.
123 @param State Variable to return the current host controller
126 @retval EFI_SUCCESS Host controller state was returned in State.
127 @retval EFI_INVALID_PARAMETER State is NULL.
128 @retval EFI_DEVICE_ERROR An error was encountered while attempting to
129 retrieve the host controller's current state.
136 IN EFI_USB_HC_PROTOCOL
*This
,
137 OUT EFI_USB_HC_STATE
*State
140 Sets the USB host controller to a specific state.
142 @param This This EFI_USB_HC_PROTOCOL instance.
143 @param State The state of the host controller that will be set.
145 @retval EFI_SUCCESS The USB host controller was successfully placed
146 in the state specified by State.
147 @retval EFI_INVALID_PARAMETER State is invalid.
148 @retval EFI_DEVICE_ERROR Failed to set the state due to device error.
155 IN EFI_USB_HC_PROTOCOL
*This
,
156 IN EFI_USB_HC_STATE State
160 Submits control transfer to a target USB device.
162 @param This A pointer to the EFI_USB_HC_PROTOCOL instance.
163 @param DeviceAddress Represents the address of the target device on the USB,
164 which is assigned during USB enumeration.
165 @param IsSlowDevice Indicates whether the target device is slow device
166 or full-speed device.
167 @param MaxPaketLength Indicates the maximum packet size that the
168 default control transfer endpoint is capable of
169 sending or receiving.
170 @param Request A pointer to the USB device request that will be sent
172 @param TransferDirection Specifies the data direction for the transfer.
173 There are three values available, DataIn, DataOut
175 @param Data A pointer to the buffer of data that will be transmitted
176 to USB device or received from USB device.
177 @param DataLength Indicates the size, in bytes, of the data buffer
179 @param TimeOut Indicates the maximum time, in microseconds,
180 which the transfer is allowed to complete.
181 @param TransferResult A pointer to the detailed result information generated
182 by this control transfer.
184 @retval EFI_SUCCESS The control transfer was completed successfully.
185 @retval EFI_OUT_OF_RESOURCES The control transfer could not be completed due to a lack of resources.
186 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
187 @retval EFI_TIMEOUT The control transfer failed due to timeout.
188 @retval EFI_DEVICE_ERROR The control transfer failed due to host controller or device error.
189 Caller should check TranferResult for detailed error information.
196 OhciControlTransfer (
197 IN EFI_USB_HC_PROTOCOL
*This
,
198 IN UINT8 DeviceAddress
,
199 IN BOOLEAN IsSlowDevice
,
200 IN UINT8 MaxPacketLength
,
201 IN EFI_USB_DEVICE_REQUEST
*Request
,
202 IN EFI_USB_DATA_DIRECTION TransferDirection
,
203 IN OUT VOID
*Data OPTIONAL
,
204 IN OUT UINTN
*DataLength OPTIONAL
,
206 OUT UINT32
*TransferResult
210 Submits bulk transfer to a bulk endpoint of a USB device.
212 @param This A pointer to the EFI_USB_HC_PROTOCOL instance.
213 @param DeviceAddress Represents the address of the target device on the USB,
214 which is assigned during USB enumeration.
215 @param EndPointAddress The combination of an endpoint number and an
216 endpoint direction of the target USB device.
217 Each endpoint address supports data transfer in
218 one direction except the control endpoint
219 (whose default endpoint address is 0).
220 It is the caller's responsibility to make sure that
221 the EndPointAddress represents a bulk endpoint.
222 @param MaximumPacketLength Indicates the maximum packet size the target endpoint
223 is capable of sending or receiving.
224 @param Data A pointer to the buffer of data that will be transmitted
225 to USB device or received from USB device.
226 @param DataLength When input, indicates the size, in bytes, of the data buffer
227 specified by Data. When output, indicates the actually
228 transferred data size.
229 @param DataToggle A pointer to the data toggle value. On input, it indicates
230 the initial data toggle value the bulk transfer should adopt;
231 on output, it is updated to indicate the data toggle value
232 of the subsequent bulk transfer.
233 @param TimeOut Indicates the maximum time, in microseconds, which the
234 transfer is allowed to complete.
235 TransferResult A pointer to the detailed result information of the
238 @retval EFI_SUCCESS The bulk transfer was completed successfully.
239 @retval EFI_OUT_OF_RESOURCES The bulk transfer could not be submitted due to lack of resource.
240 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
241 @retval EFI_TIMEOUT The bulk transfer failed due to timeout.
242 @retval EFI_DEVICE_ERROR The bulk transfer failed due to host controller or device error.
243 Caller should check TranferResult for detailed error information.
251 IN EFI_USB_HC_PROTOCOL
*This
,
252 IN UINT8 DeviceAddress
,
253 IN UINT8 EndPointAddress
,
254 IN UINT8 MaxPacketLength
,
256 IN OUT UINTN
*DataLength
,
257 IN OUT UINT8
*DataToggle
,
259 OUT UINT32
*TransferResult
263 Submits an interrupt transfer to an interrupt endpoint of a USB device.
265 @param Ohc Device private data
266 @param DeviceAddress Represents the address of the target device on the USB,
267 which is assigned during USB enumeration.
268 @param EndPointAddress The combination of an endpoint number and an endpoint
269 direction of the target USB device. Each endpoint address
270 supports data transfer in one direction except the
271 control endpoint (whose default endpoint address is 0).
272 It is the caller's responsibility to make sure that
273 the EndPointAddress represents an interrupt endpoint.
274 @param IsSlowDevice Indicates whether the target device is slow device
275 or full-speed device.
276 @param MaxPacketLength Indicates the maximum packet size the target endpoint
277 is capable of sending or receiving.
278 @param IsNewTransfer If TRUE, an asynchronous interrupt pipe is built between
279 the host and the target interrupt endpoint.
280 If FALSE, the specified asynchronous interrupt pipe
282 @param DataToggle A pointer to the data toggle value. On input, it is valid
283 when IsNewTransfer is TRUE, and it indicates the initial
284 data toggle value the asynchronous interrupt transfer
286 On output, it is valid when IsNewTransfer is FALSE,
287 and it is updated to indicate the data toggle value of
288 the subsequent asynchronous interrupt transfer.
289 @param PollingInterval Indicates the interval, in milliseconds, that the
290 asynchronous interrupt transfer is polled.
291 This parameter is required when IsNewTransfer is TRUE.
292 @param UCBuffer Uncacheable buffer
293 @param DataLength Indicates the length of data to be received at the
294 rate specified by PollingInterval from the target
295 asynchronous interrupt endpoint. This parameter
296 is only required when IsNewTransfer is TRUE.
297 @param CallBackFunction The Callback function.This function is called at the
298 rate specified by PollingInterval.This parameter is
299 only required when IsNewTransfer is TRUE.
300 @param Context The context that is passed to the CallBackFunction.
301 This is an optional parameter and may be NULL.
302 @param IsPeriodic Periodic interrupt or not
303 @param OutputED The correspoding ED carried out
304 @param OutputTD The correspoding TD carried out
307 @retval EFI_SUCCESS The asynchronous interrupt transfer request has been successfully
308 submitted or canceled.
309 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
310 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
315 OhciInterruptTransfer (
316 IN USB_OHCI_HC_DEV
*Ohc
,
317 IN UINT8 DeviceAddress
,
318 IN UINT8 EndPointAddress
,
319 IN BOOLEAN IsSlowDevice
,
320 IN UINT8 MaxPacketLength
,
321 IN BOOLEAN IsNewTransfer
,
322 IN OUT UINT8
*DataToggle OPTIONAL
,
323 IN UINTN PollingInterval OPTIONAL
,
324 IN VOID
*UCBuffer OPTIONAL
,
325 IN UINTN DataLength OPTIONAL
,
326 IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction OPTIONAL
,
327 IN VOID
*Context OPTIONAL
,
328 IN BOOLEAN IsPeriodic OPTIONAL
,
329 OUT ED_DESCRIPTOR
**OutputED OPTIONAL
,
330 OUT TD_DESCRIPTOR
**OutputTD OPTIONAL
334 Submits an asynchronous interrupt transfer to an interrupt endpoint of a USB device.
336 @param This A pointer to the EFI_USB_HC_PROTOCOL instance.
337 @param DeviceAddress Represents the address of the target device on the USB,
338 which is assigned during USB enumeration.
339 @param EndPointAddress The combination of an endpoint number and an endpoint
340 direction of the target USB device. Each endpoint address
341 supports data transfer in one direction except the
342 control endpoint (whose default endpoint address is 0).
343 It is the caller's responsibility to make sure that
344 the EndPointAddress represents an interrupt endpoint.
345 @param IsSlowDevice Indicates whether the target device is slow device
346 or full-speed device.
347 @param MaxiumPacketLength Indicates the maximum packet size the target endpoint
348 is capable of sending or receiving.
349 @param IsNewTransfer If TRUE, an asynchronous interrupt pipe is built between
350 the host and the target interrupt endpoint.
351 If FALSE, the specified asynchronous interrupt pipe
353 @param DataToggle A pointer to the data toggle value. On input, it is valid
354 when IsNewTransfer is TRUE, and it indicates the initial
355 data toggle value the asynchronous interrupt transfer
357 On output, it is valid when IsNewTransfer is FALSE,
358 and it is updated to indicate the data toggle value of
359 the subsequent asynchronous interrupt transfer.
360 @param PollingInterval Indicates the interval, in milliseconds, that the
361 asynchronous interrupt transfer is polled.
362 This parameter is required when IsNewTransfer is TRUE.
363 @param DataLength Indicates the length of data to be received at the
364 rate specified by PollingInterval from the target
365 asynchronous interrupt endpoint. This parameter
366 is only required when IsNewTransfer is TRUE.
367 @param CallBackFunction The Callback function.This function is called at the
368 rate specified by PollingInterval.This parameter is
369 only required when IsNewTransfer is TRUE.
370 @param Context The context that is passed to the CallBackFunction.
371 This is an optional parameter and may be NULL.
373 @retval EFI_SUCCESS The asynchronous interrupt transfer request has been successfully
374 submitted or canceled.
375 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
376 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
383 OhciAsyncInterruptTransfer (
384 IN EFI_USB_HC_PROTOCOL
*This
,
385 IN UINT8 DeviceAddress
,
386 IN UINT8 EndPointAddress
,
387 IN BOOLEAN IsSlowDevice
,
388 IN UINT8 MaxPacketLength
,
389 IN BOOLEAN IsNewTransfer
,
390 IN OUT UINT8
*DataToggle OPTIONAL
,
391 IN UINTN PollingInterval OPTIONAL
,
392 IN UINTN DataLength OPTIONAL
,
393 IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction OPTIONAL
,
394 IN VOID
*Context OPTIONAL
398 Submits synchronous interrupt transfer to an interrupt endpoint
401 @param This A pointer to the EFI_USB_HC_PROTOCOL instance.
402 @param DeviceAddress Represents the address of the target device on the USB,
403 which is assigned during USB enumeration.
404 @param EndPointAddress The combination of an endpoint number and an endpoint
405 direction of the target USB device. Each endpoint
406 address supports data transfer in one direction
407 except the control endpoint (whose default
408 endpoint address is 0). It is the caller's responsibility
409 to make sure that the EndPointAddress represents
410 an interrupt endpoint.
411 @param IsSlowDevice Indicates whether the target device is slow device
412 or full-speed device.
413 @param MaxPacketLength Indicates the maximum packet size the target endpoint
414 is capable of sending or receiving.
415 @param Data A pointer to the buffer of data that will be transmitted
416 to USB device or received from USB device.
417 @param DataLength On input, the size, in bytes, of the data buffer specified
418 by Data. On output, the number of bytes transferred.
419 @param DataToggle A pointer to the data toggle value. On input, it indicates
420 the initial data toggle value the synchronous interrupt
421 transfer should adopt;
422 on output, it is updated to indicate the data toggle value
423 of the subsequent synchronous interrupt transfer.
424 @param TimeOut Indicates the maximum time, in microseconds, which the
425 transfer is allowed to complete.
426 @param TransferResult A pointer to the detailed result information from
427 the synchronous interrupt transfer.
429 @retval EFI_UNSUPPORTED This interface not available.
430 @retval EFI_INVALID_PARAMETER Parameters not follow spec
437 OhciSyncInterruptTransfer (
438 IN EFI_USB_HC_PROTOCOL
*This
,
439 IN UINT8 DeviceAddress
,
440 IN UINT8 EndPointAddress
,
441 IN BOOLEAN IsSlowDevice
,
442 IN UINT8 MaxPacketLength
,
444 IN OUT UINTN
*DataLength
,
445 IN OUT UINT8
*DataToggle
,
447 OUT UINT32
*TransferResult
451 Submits isochronous transfer to a target USB device.
453 @param This A pointer to the EFI_USB_HC_PROTOCOL instance.
454 @param DeviceAddress Represents the address of the target device on the USB,
455 which is assigned during USB enumeration.
456 @param EndPointAddress End point address
457 @param MaximumPacketLength Indicates the maximum packet size that the
458 default control transfer endpoint is capable of
459 sending or receiving.
460 @param Data A pointer to the buffer of data that will be transmitted
461 to USB device or received from USB device.
462 @param DataLength Indicates the size, in bytes, of the data buffer
464 @param TransferResult A pointer to the detailed result information generated
465 by this control transfer.
467 @retval EFI_UNSUPPORTED This interface not available
468 @retval EFI_INVALID_PARAMETER Data is NULL or DataLength is 0 or TransferResult is NULL
475 OhciIsochronousTransfer (
476 IN EFI_USB_HC_PROTOCOL
*This
,
477 IN UINT8 DeviceAddress
,
478 IN UINT8 EndPointAddress
,
479 IN UINT8 MaximumPacketLength
,
481 IN OUT UINTN DataLength
,
482 OUT UINT32
*TransferResult
486 Submits Async isochronous transfer to a target USB device.
488 @param his A pointer to the EFI_USB_HC_PROTOCOL instance.
489 @param DeviceAddress Represents the address of the target device on the USB,
490 which is assigned during USB enumeration.
491 @param EndPointAddress End point address
492 @param MaximumPacketLength Indicates the maximum packet size that the
493 default control transfer endpoint is capable of
494 sending or receiving.
495 @param Data A pointer to the buffer of data that will be transmitted
496 to USB device or received from USB device.
497 @param IsochronousCallBack When the transfer complete, the call back function will be called
498 @param Context Pass to the call back function as parameter
500 @retval EFI_UNSUPPORTED This interface not available
501 @retval EFI_INVALID_PARAMETER Data is NULL or Datalength is 0
507 OhciAsyncIsochronousTransfer (
508 IN EFI_USB_HC_PROTOCOL
*This
,
509 IN UINT8 DeviceAddress
,
510 IN UINT8 EndPointAddress
,
511 IN UINT8 MaximumPacketLength
,
513 IN OUT UINTN DataLength
,
514 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
515 IN VOID
*Context OPTIONAL
520 Retrieves the number of root hub ports.
522 @param This A pointer to the EFI_USB_HC_PROTOCOL instance.
523 @param NumOfPorts A pointer to the number of the root hub ports.
525 @retval EFI_SUCCESS The port number was retrieved successfully.
529 OhciGetRootHubNumOfPorts (
530 IN EFI_USB_HC_PROTOCOL
*This
,
531 OUT UINT8
*NumOfPorts
535 Retrieves the current status of a USB root hub port.
537 @param This A pointer to the EFI_USB_HC_PROTOCOL.
538 @param PortNumber Specifies the root hub port from which the status
539 is to be retrieved. This value is zero-based. For example,
540 if a root hub has two ports, then the first port is numbered 0,
541 and the second port is numbered 1.
542 @param PortStatus A pointer to the current port status bits and
543 port status change bits.
545 @retval EFI_SUCCESS The status of the USB root hub port specified by PortNumber
546 was returned in PortStatus.
547 @retval EFI_INVALID_PARAMETER Port number not valid
553 OhciGetRootHubPortStatus (
554 IN EFI_USB_HC_PROTOCOL
*This
,
556 OUT EFI_USB_PORT_STATUS
*PortStatus
561 Sets a feature for the specified root hub port.
563 @param This A pointer to the EFI_USB_HC_PROTOCOL.
564 @param PortNumber Specifies the root hub port whose feature
565 is requested to be set.
566 @param PortFeature Indicates the feature selector associated
567 with the feature set request.
569 @retval EFI_SUCCESS The feature specified by PortFeature was set for the
570 USB root hub port specified by PortNumber.
571 @retval EFI_DEVICE_ERROR Set feature failed because of hardware issue
572 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
576 OhciSetRootHubPortFeature (
577 IN EFI_USB_HC_PROTOCOL
*This
,
579 IN EFI_USB_PORT_FEATURE PortFeature
583 Clears a feature for the specified root hub port.
585 @param This A pointer to the EFI_USB_HC_PROTOCOL instance.
586 @param PortNumber Specifies the root hub port whose feature
587 is requested to be cleared.
588 @param PortFeature Indicates the feature selector associated with the
589 feature clear request.
591 @retval EFI_SUCCESS The feature specified by PortFeature was cleared for the
592 USB root hub port specified by PortNumber.
593 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
594 @retval EFI_DEVICE_ERROR Some error happened when clearing feature
598 OhciClearRootHubPortFeature (
599 IN EFI_USB_HC_PROTOCOL
*This
,
601 IN EFI_USB_PORT_FEATURE PortFeature
606 Test to see if this driver supports ControllerHandle. Any
607 ControllerHandle that has UsbHcProtocol installed will be supported.
609 @param This Protocol instance pointer.
610 @param Controller Handle of device to test.
611 @param RemainingDevicePath Not used.
613 @return EFI_SUCCESS This driver supports this device.
614 @return EFI_UNSUPPORTED This driver does not support this device.
620 OHCIDriverBindingSupported (
621 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
622 IN EFI_HANDLE Controller
,
623 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
627 Starting the Usb OHCI Driver.
629 @param This Protocol instance pointer.
630 @param Controller Handle of device to test.
631 @param RemainingDevicePath Not used.
633 @retval EFI_SUCCESS This driver supports this device.
634 @retval EFI_UNSUPPORTED This driver does not support this device.
635 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
636 EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
641 OHCIDriverBindingStart (
642 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
643 IN EFI_HANDLE Controller
,
644 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
648 Stop this driver on ControllerHandle. Support stopping any child handles
649 created by this driver.
651 @param This Protocol instance pointer.
652 @param Controller Handle of device to stop driver on.
653 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
654 @param ChildHandleBuffer List of handles for the children we need to stop.
662 OHCIDriverBindingStop (
663 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
664 IN EFI_HANDLE Controller
,
665 IN UINTN NumberOfChildren
,
666 IN EFI_HANDLE
*ChildHandleBuffer