2 Private Header file for Usb Host Controller PEIM
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 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.
17 #ifndef _RECOVERY_UHC_H_
18 #define _RECOVERY_UHC_H_
23 #include <Ppi/UsbController.h>
24 #include <Ppi/UsbHostController.h>
25 #include <Ppi/IoMmu.h>
26 #include <Ppi/EndOfPeiPhase.h>
28 #include <Library/DebugLib.h>
29 #include <Library/PeimEntryPoint.h>
30 #include <Library/PeiServicesLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/TimerLib.h>
33 #include <Library/IoLib.h>
34 #include <Library/PeiServicesLib.h>
36 #define USB_SLOW_SPEED_DEVICE 0x01
37 #define USB_FULL_SPEED_DEVICE 0x02
40 // One memory block uses 16 page
42 #define NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES 16
44 #define USBCMD 0 /* Command Register Offset 00-01h */
45 #define USBCMD_RS BIT0 /* Run/Stop */
46 #define USBCMD_HCRESET BIT1 /* Host reset */
47 #define USBCMD_GRESET BIT2 /* Global reset */
48 #define USBCMD_EGSM BIT3 /* Global Suspend Mode */
49 #define USBCMD_FGR BIT4 /* Force Global Resume */
50 #define USBCMD_SWDBG BIT5 /* SW Debug mode */
51 #define USBCMD_CF BIT6 /* Config Flag (sw only) */
52 #define USBCMD_MAXP BIT7 /* Max Packet (0 = 32, 1 = 64) */
55 #define USBSTS 2 /* Status Register Offset 02-03h */
56 #define USBSTS_USBINT BIT0 /* Interrupt due to IOC */
57 #define USBSTS_ERROR BIT1 /* Interrupt due to error */
58 #define USBSTS_RD BIT2 /* Resume Detect */
59 #define USBSTS_HSE BIT3 /* Host System Error - basically PCI problems */
60 #define USBSTS_HCPE BIT4 /* Host Controller Process Error - the scripts were buggy */
61 #define USBSTS_HCH BIT5 /* HC Halted */
63 /* Interrupt enable register */
64 #define USBINTR 4 /* Interrupt Enable Register 04-05h */
65 #define USBINTR_TIMEOUT BIT0 /* Timeout/CRC error enable */
66 #define USBINTR_RESUME BIT1 /* Resume interrupt enable */
67 #define USBINTR_IOC BIT2 /* Interrupt On Complete enable */
68 #define USBINTR_SP BIT3 /* Short packet interrupt enable */
70 /* Frame Number Register Offset 06-08h */
73 /* Frame List Base Address Register Offset 08-0Bh */
74 #define USBFLBASEADD 8
76 /* Start of Frame Modify Register Offset 0Ch */
79 /* USB port status and control registers */
80 #define USBPORTSC1 0x10 /*Port 1 offset 10-11h */
81 #define USBPORTSC2 0x12 /*Port 2 offset 12-13h */
83 #define USBPORTSC_CCS BIT0 /* Current Connect Status ("device present") */
84 #define USBPORTSC_CSC BIT1 /* Connect Status Change */
85 #define USBPORTSC_PED BIT2 /* Port Enable / Disable */
86 #define USBPORTSC_PEDC BIT3 /* Port Enable / Disable Change */
87 #define USBPORTSC_LSL BIT4 /* Line Status Low bit*/
88 #define USBPORTSC_LSH BIT5 /* Line Status High bit*/
89 #define USBPORTSC_RD BIT6 /* Resume Detect */
90 #define USBPORTSC_LSDA BIT8 /* Low Speed Device Attached */
91 #define USBPORTSC_PR BIT9 /* Port Reset */
92 #define USBPORTSC_SUSP BIT12 /* Suspend */
94 #define SETUP_PACKET_ID 0x2D
95 #define INPUT_PACKET_ID 0x69
96 #define OUTPUT_PACKET_ID 0xE1
97 #define ERROR_PACKET_ID 0x55
99 #define STALL_1_MICRO_SECOND 1
100 #define STALL_1_MILLI_SECOND 1000
106 UINT32 FrameListPtrTerminate
: 1;
107 UINT32 FrameListPtrQSelect
: 1;
108 UINT32 FrameListRsvd
: 2;
109 UINT32 FrameListPtr
: 28;
113 UINT32 QHHorizontalTerminate
: 1;
114 UINT32 QHHorizontalQSelect
: 1;
115 UINT32 QHHorizontalRsvd
: 2;
116 UINT32 QHHorizontalPtr
: 28;
117 UINT32 QHVerticalTerminate
: 1;
118 UINT32 QHVerticalQSelect
: 1;
119 UINT32 QHVerticalRsvd
: 2;
120 UINT32 QHVerticalPtr
: 28;
124 QUEUE_HEAD QueueHead
;
134 UINT32 TDLinkPtrTerminate
: 1;
135 UINT32 TDLinkPtrQSelect
: 1;
136 UINT32 TDLinkPtrDepthSelect
: 1;
137 UINT32 TDLinkPtrRsvd
: 1;
138 UINT32 TDLinkPtr
: 28;
139 UINT32 TDStatusActualLength
: 11;
140 UINT32 TDStatusRsvd
: 5;
142 UINT32 TDStatusIOC
: 1;
143 UINT32 TDStatusIOS
: 1;
144 UINT32 TDStatusLS
: 1;
145 UINT32 TDStatusErr
: 2;
146 UINT32 TDStatusSPD
: 1;
147 UINT32 TDStatusRsvd2
: 2;
148 UINT32 TDTokenPID
: 8;
149 UINT32 TDTokenDevAddr
: 7;
150 UINT32 TDTokenEndPt
: 4;
151 UINT32 TDTokenDataToggle
: 1;
152 UINT32 TDTokenRsvd
: 1;
153 UINT32 TDTokenMaxLen
: 11;
162 UINT16 TDBufferLength
;
168 typedef struct _MEMORY_MANAGE_HEADER MEMORY_MANAGE_HEADER
;
170 struct _MEMORY_MANAGE_HEADER
{
172 UINTN BitArraySizeInBytes
;
173 UINT8
*MemoryBlockPtr
;
174 UINTN MemoryBlockSizeInBytes
;
175 MEMORY_MANAGE_HEADER
*Next
;
178 #define USB_UHC_DEV_SIGNATURE SIGNATURE_32 ('p', 'u', 'h', 'c')
181 PEI_USB_HOST_CONTROLLER_PPI UsbHostControllerPpi
;
182 EDKII_IOMMU_PPI
*IoMmu
;
183 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor
;
185 // EndOfPei callback is used to stop the UHC DMA operation
186 // after exit PEI phase.
188 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList
;
190 UINT32 UsbHostControllerBaseAddress
;
191 FRAMELIST_ENTRY
*FrameListEntry
;
195 // Header1 used for QH,TD memory blocks management
197 MEMORY_MANAGE_HEADER
*Header1
;
201 #define PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS(a) CR (a, USB_UHC_DEV, UsbHostControllerPpi, USB_UHC_DEV_SIGNATURE)
202 #define PEI_RECOVERY_USB_UHC_DEV_FROM_THIS_NOTIFY(a) CR (a, USB_UHC_DEV, EndOfPeiNotifyList, USB_UHC_DEV_SIGNATURE)
205 Submits control transfer to a target USB device.
207 @param PeiServices The pointer of EFI_PEI_SERVICES.
208 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
209 @param DeviceAddress The target device address.
210 @param DeviceSpeed Target device speed.
211 @param MaximumPacketLength Maximum packet size the default control transfer
212 endpoint is capable of sending or receiving.
213 @param Request USB device request to send.
214 @param TransferDirection Specifies the data direction for the data stage.
215 @param Data Data buffer to be transmitted or received from USB device.
216 @param DataLength The size (in bytes) of the data buffer.
217 @param TimeOut Indicates the maximum timeout, in millisecond.
218 @param TransferResult Return the result of this control transfer.
220 @retval EFI_SUCCESS Transfer was completed successfully.
221 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
222 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
223 @retval EFI_TIMEOUT Transfer failed due to timeout.
224 @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
230 IN EFI_PEI_SERVICES
**PeiServices
,
231 IN PEI_USB_HOST_CONTROLLER_PPI
* This
,
232 IN UINT8 DeviceAddress
,
233 IN UINT8 DeviceSpeed
,
234 IN UINT8 MaximumPacketLength
,
235 IN EFI_USB_DEVICE_REQUEST
* Request
,
236 IN EFI_USB_DATA_DIRECTION TransferDirection
,
237 IN OUT VOID
*Data OPTIONAL
,
238 IN OUT UINTN
*DataLength OPTIONAL
,
240 OUT UINT32
*TransferResult
244 Submits bulk transfer to a bulk endpoint of a USB device.
246 @param PeiServices The pointer of EFI_PEI_SERVICES.
247 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
248 @param DeviceAddress Target device address.
249 @param EndPointAddress Endpoint number and its direction in bit 7.
250 @param MaximumPacketLength Maximum packet size the endpoint is capable of
251 sending or receiving.
252 @param Data Array of pointers to the buffers of data to transmit
253 from or receive into.
254 @param DataLength The lenght of the data buffer.
255 @param DataToggle On input, the initial data toggle for the transfer;
256 On output, it is updated to to next data toggle to use of
257 the subsequent bulk transfer.
258 @param TimeOut Indicates the maximum time, in millisecond, which the
259 transfer is allowed to complete.
260 @param TransferResult A pointer to the detailed result information of the
263 @retval EFI_SUCCESS The transfer was completed successfully.
264 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
265 @retval EFI_INVALID_PARAMETER Parameters are invalid.
266 @retval EFI_TIMEOUT The transfer failed due to timeout.
267 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
273 IN EFI_PEI_SERVICES
**PeiServices
,
274 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
275 IN UINT8 DeviceAddress
,
276 IN UINT8 EndPointAddress
,
277 IN UINT8 MaximumPacketLength
,
279 IN OUT UINTN
*DataLength
,
280 IN OUT UINT8
*DataToggle
,
282 OUT UINT32
*TransferResult
286 Retrieves the number of root hub ports.
288 @param[in] PeiServices The pointer to the PEI Services Table.
289 @param[in] This The pointer to this instance of the
290 PEI_USB_HOST_CONTROLLER_PPI.
291 @param[out] PortNumber The pointer to the number of the root hub ports.
293 @retval EFI_SUCCESS The port number was retrieved successfully.
294 @retval EFI_INVALID_PARAMETER PortNumber is NULL.
299 UhcGetRootHubPortNumber (
300 IN EFI_PEI_SERVICES
**PeiServices
,
301 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
302 OUT UINT8
*PortNumber
306 Retrieves the current status of a USB root hub port.
308 @param PeiServices The pointer of EFI_PEI_SERVICES.
309 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
310 @param PortNumber The root hub port to retrieve the state from.
311 @param PortStatus Variable to receive the port state.
313 @retval EFI_SUCCESS The status of the USB root hub port specified.
314 by PortNumber was returned in PortStatus.
315 @retval EFI_INVALID_PARAMETER PortNumber is invalid.
320 UhcGetRootHubPortStatus (
321 IN EFI_PEI_SERVICES
**PeiServices
,
322 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
324 OUT EFI_USB_PORT_STATUS
*PortStatus
328 Sets a feature for the specified root hub port.
330 @param PeiServices The pointer of EFI_PEI_SERVICES
331 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI
332 @param PortNumber Root hub port to set.
333 @param PortFeature Feature to set.
335 @retval EFI_SUCCESS The feature specified by PortFeature was set.
336 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
337 @retval EFI_TIMEOUT The time out occurred.
342 UhcSetRootHubPortFeature (
343 IN EFI_PEI_SERVICES
**PeiServices
,
344 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
346 IN EFI_USB_PORT_FEATURE PortFeature
350 Clears a feature for the specified root hub port.
352 @param PeiServices The pointer of EFI_PEI_SERVICES.
353 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
354 @param PortNumber Specifies the root hub port whose feature
355 is requested to be cleared.
356 @param PortFeature Indicates the feature selector associated with the
357 feature clear request.
359 @retval EFI_SUCCESS The feature specified by PortFeature was cleared
360 for the USB root hub port specified by PortNumber.
361 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
366 UhcClearRootHubPortFeature (
367 IN EFI_PEI_SERVICES
**PeiServices
,
368 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
370 IN EFI_USB_PORT_FEATURE PortFeature
376 @param UhcDev UHCI Device.
378 @retval EFI_SUCCESS UHCI successfully initialized.
379 @retval EFI_OUT_OF_RESOURCES Resource can not be allocated.
384 IN USB_UHC_DEV
*UhcDev
388 Create Frame List Structure.
390 @param UhcDev UHCI device.
392 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
393 @retval EFI_SUCCESS Success.
402 Read a 16bit width data from Uhc HC IO space register.
404 @param UhcDev The UHCI device.
405 @param Port The IO space address of the register.
407 @retval the register content read.
412 IN USB_UHC_DEV
*UhcDev
,
417 Write a 16bit width data into Uhc HC IO space register.
419 @param UhcDev The UHCI device.
420 @param Port The IO space address of the register.
421 @param Data The data written into the register.
426 IN USB_UHC_DEV
*UhcDev
,
432 Write a 32bit width data into Uhc HC IO space register.
434 @param UhcDev The UHCI device.
435 @param Port The IO space address of the register.
436 @param Data The data written into the register.
441 IN USB_UHC_DEV
*UhcDev
,
447 Clear the content of UHCI's Status Register.
449 @param UhcDev The UHCI device.
450 @param StatusAddr The IO space address of the register.
455 IN USB_UHC_DEV
*UhcDev
,
460 Check whether the host controller operates well.
462 @param UhcDev The UHCI device.
463 @param StatusRegAddr The io address of status register.
465 @retval TRUE Host controller is working.
466 @retval FALSE Host controller is halted or system error.
471 IN USB_UHC_DEV
*UhcDev
,
472 IN UINT32 StatusRegAddr
476 Get Current Frame Number.
478 @param UhcDev The UHCI device.
479 @param FrameNumberAddr The address of frame list register.
481 @retval The content of the frame list register.
485 GetCurrentFrameNumber (
486 IN USB_UHC_DEV
*UhcDev
,
487 IN UINT32 FrameNumberAddr
491 Set Frame List Base Address.
493 @param UhcDev The UHCI device.
494 @param FrameListRegAddr The address of frame list register.
495 @param Addr The address of frame list table.
499 SetFrameListBaseAddress (
500 IN USB_UHC_DEV
*UhcDev
,
501 IN UINT32 FrameListRegAddr
,
506 Create QH and initialize.
508 @param UhcDev The UHCI device.
509 @param PtrQH Place to store QH_STRUCT pointer.
511 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
512 @retval EFI_SUCCESS Success.
517 IN USB_UHC_DEV
*UhcDev
,
518 OUT QH_STRUCT
**PtrQH
522 Set the horizontal link pointer in QH.
524 @param PtrQH Place to store QH_STRUCT pointer.
525 @param PtrNext Place to the next QH_STRUCT.
529 SetQHHorizontalLinkPtr (
535 Get the horizontal link pointer in QH.
537 @param PtrQH Place to store QH_STRUCT pointer.
539 @retval The horizontal link pointer in QH.
543 GetQHHorizontalLinkPtr (
548 Set a QH or TD horizontally to be connected with a specific QH.
550 @param PtrQH Place to store QH_STRUCT pointer.
551 @param IsQH Specify QH or TD is connected.
555 SetQHHorizontalQHorTDSelect (
561 Set the horizontal validor bit in QH.
563 @param PtrQH Place to store QH_STRUCT pointer.
564 @param IsValid Specify the horizontal linker is valid or not.
568 SetQHHorizontalValidorInvalid (
574 Set the vertical link pointer in QH.
576 @param PtrQH Place to store QH_STRUCT pointer.
577 @param PtrNext Place to the next QH_STRUCT.
581 SetQHVerticalLinkPtr (
587 Set a QH or TD vertically to be connected with a specific QH.
589 @param PtrQH Place to store QH_STRUCT pointer.
590 @param IsQH Specify QH or TD is connected.
594 SetQHVerticalQHorTDSelect (
600 Set the vertical validor bit in QH.
602 @param PtrQH Place to store QH_STRUCT pointer.
603 @param IsValid Specify the vertical linker is valid or not.
607 SetQHVerticalValidorInvalid (
613 Get the vertical validor bit in QH.
615 @param PtrQH Place to store QH_STRUCT pointer.
617 @retval The vertical linker is valid or not.
621 GetQHHorizontalValidorInvalid (
626 Allocate TD or QH Struct.
628 @param UhcDev The UHCI device.
629 @param Size The size of allocation.
630 @param PtrStruct Place to store TD_STRUCT pointer.
632 @return EFI_SUCCESS Allocate successfully.
633 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
637 AllocateTDorQHStruct (
638 IN USB_UHC_DEV
*UhcDev
,
646 @param UhcDev The UHCI device.
647 @param PtrTD Place to store TD_STRUCT pointer.
649 @return EFI_SUCCESS Allocate successfully.
650 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
655 IN USB_UHC_DEV
*UhcDev
,
656 OUT TD_STRUCT
**PtrTD
660 Generate Setup Stage TD.
662 @param UhcDev The UHCI device.
663 @param DevAddr Device address.
664 @param Endpoint Endpoint number.
665 @param DeviceSpeed Device Speed.
666 @param DevRequest CPU memory address of request structure buffer to transfer.
667 @param RequestPhy PCI memory address of request structure buffer to transfer.
668 @param RequestLen Request length.
669 @param PtrTD TD_STRUCT generated.
671 @return EFI_SUCCESS Generate setup stage TD successfully.
672 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
677 IN USB_UHC_DEV
*UhcDev
,
680 IN UINT8 DeviceSpeed
,
681 IN UINT8
*DevRequest
,
682 IN UINT8
*RequestPhy
,
684 OUT TD_STRUCT
**PtrTD
688 Generate Data Stage TD.
690 @param UhcDev The UHCI device.
691 @param DevAddr Device address.
692 @param Endpoint Endpoint number.
693 @param PtrData CPU memory address of user data buffer to transfer.
694 @param DataPhy PCI memory address of user data buffer to transfer.
695 @param Len Data length.
696 @param PktID PacketID.
697 @param Toggle Data toggle value.
698 @param DeviceSpeed Device Speed.
699 @param PtrTD TD_STRUCT generated.
701 @return EFI_SUCCESS Generate data stage TD successfully.
702 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
707 IN USB_UHC_DEV
*UhcDev
,
715 IN UINT8 DeviceSpeed
,
716 OUT TD_STRUCT
**PtrTD
720 Generate Status Stage TD.
722 @param UhcDev The UHCI device.
723 @param DevAddr Device address.
724 @param Endpoint Endpoint number.
725 @param PktID PacketID.
726 @param DeviceSpeed Device Speed.
727 @param PtrTD TD_STRUCT generated.
729 @return EFI_SUCCESS Generate status stage TD successfully.
730 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
735 IN USB_UHC_DEV
*UhcDev
,
739 IN UINT8 DeviceSpeed
,
740 OUT TD_STRUCT
**PtrTD
744 Set the link pointer validor bit in TD.
746 @param PtrTDStruct Place to store TD_STRUCT pointer.
747 @param IsValid Specify the linker pointer is valid or not.
751 SetTDLinkPtrValidorInvalid (
752 IN TD_STRUCT
*PtrTDStruct
,
757 Set the Link Pointer pointing to a QH or TD.
759 @param PtrTDStruct Place to store TD_STRUCT pointer.
760 @param IsQH Specify QH or TD is connected.
764 SetTDLinkPtrQHorTDSelect (
765 IN TD_STRUCT
*PtrTDStruct
,
770 Set the traverse is depth-first or breadth-first.
772 @param PtrTDStruct Place to store TD_STRUCT pointer.
773 @param IsDepth Specify the traverse is depth-first or breadth-first.
777 SetTDLinkPtrDepthorBreadth (
778 IN TD_STRUCT
*PtrTDStruct
,
783 Set TD Link Pointer in TD.
785 @param PtrTDStruct Place to store TD_STRUCT pointer.
786 @param PtrNext Place to the next TD_STRUCT.
791 IN TD_STRUCT
*PtrTDStruct
,
798 @param PtrTDStruct Place to store TD_STRUCT pointer.
800 @retval Get TD Link Pointer in TD.
805 IN TD_STRUCT
*PtrTDStruct
809 Get the information about whether the Link Pointer field pointing to
812 @param PtrTDStruct Place to store TD_STRUCT pointer.
814 @retval whether the Link Pointer field pointing to a QH or a TD.
819 IN TD_STRUCT
*PtrTDStruct
823 Enable/Disable short packet detection mechanism.
825 @param PtrTDStruct Place to store TD_STRUCT pointer.
826 @param IsEnable Enable or disable short packet detection mechanism.
830 EnableorDisableTDShortPacket (
831 IN TD_STRUCT
*PtrTDStruct
,
836 Set the max error counter in TD.
838 @param PtrTDStruct Place to store TD_STRUCT pointer.
839 @param MaxErrors The number of allowable error.
843 SetTDControlErrorCounter (
844 IN TD_STRUCT
*PtrTDStruct
,
849 Set the TD is targeting a low-speed device or not.
851 @param PtrTDStruct Place to store TD_STRUCT pointer.
852 @param IsLowSpeedDevice Whether The device is low-speed.
856 SetTDLoworFullSpeedDevice (
857 IN TD_STRUCT
*PtrTDStruct
,
858 IN BOOLEAN IsLowSpeedDevice
862 Set the TD is isochronous transfer type or not.
864 @param PtrTDStruct Place to store TD_STRUCT pointer.
865 @param IsIsochronous Whether the transaction isochronous transfer type.
869 SetTDControlIsochronousorNot (
870 IN TD_STRUCT
*PtrTDStruct
,
871 IN BOOLEAN IsIsochronous
875 Set if UCHI should issue an interrupt on completion of the frame
876 in which this TD is executed
878 @param PtrTDStruct Place to store TD_STRUCT pointer.
879 @param IsSet Whether HC should issue an interrupt on completion.
883 SetorClearTDControlIOC (
884 IN TD_STRUCT
*PtrTDStruct
,
889 Set if the TD is active and can be executed.
891 @param PtrTDStruct Place to store TD_STRUCT pointer.
892 @param IsActive Whether the TD is active and can be executed.
896 SetTDStatusActiveorInactive (
897 IN TD_STRUCT
*PtrTDStruct
,
902 Specifies the maximum number of data bytes allowed for the transfer.
904 @param PtrTDStruct Place to store TD_STRUCT pointer.
905 @param MaxLen The maximum number of data bytes allowed.
907 @retval The allowed maximum number of data.
910 SetTDTokenMaxLength (
911 IN TD_STRUCT
*PtrTDStruct
,
916 Set the data toggle bit to DATA1.
918 @param PtrTDStruct Place to store TD_STRUCT pointer.
922 SetTDTokenDataToggle1 (
923 IN TD_STRUCT
*PtrTDStruct
927 Set the data toggle bit to DATA0.
929 @param PtrTDStruct Place to store TD_STRUCT pointer.
933 SetTDTokenDataToggle0 (
934 IN TD_STRUCT
*PtrTDStruct
938 Set EndPoint Number the TD is targeting at.
940 @param PtrTDStruct Place to store TD_STRUCT pointer.
941 @param EndPoint The Endport number of the target.
946 IN TD_STRUCT
*PtrTDStruct
,
951 Set Device Address the TD is targeting at.
953 @param PtrTDStruct Place to store TD_STRUCT pointer.
954 @param DevAddr The Device Address of the target.
958 SetTDTokenDeviceAddress (
959 IN TD_STRUCT
*PtrTDStruct
,
964 Set Packet Identification the TD is targeting at.
966 @param PtrTDStruct Place to store TD_STRUCT pointer.
967 @param PacketID The Packet Identification of the target.
972 IN TD_STRUCT
*PtrTDStruct
,
977 Set the beginning address of the data buffer that will be used
978 during the transaction.
980 @param PtrTDStruct Place to store TD_STRUCT pointer.
985 IN TD_STRUCT
*PtrTDStruct
989 Detect whether the TD is active.
991 @param PtrTDStruct Place to store TD_STRUCT pointer.
993 @retval The TD is active or not.
998 IN TD_STRUCT
*PtrTDStruct
1002 Detect whether the TD is stalled.
1004 @param PtrTDStruct Place to store TD_STRUCT pointer.
1006 @retval The TD is stalled or not.
1011 IN TD_STRUCT
*PtrTDStruct
1015 Detect whether Data Buffer Error is happened.
1017 @param PtrTDStruct Place to store TD_STRUCT pointer.
1019 @retval The Data Buffer Error is happened or not.
1023 IsTDStatusBufferError (
1024 IN TD_STRUCT
*PtrTDStruct
1028 Detect whether Babble Error is happened.
1030 @param PtrTDStruct Place to store TD_STRUCT pointer.
1032 @retval The Babble Error is happened or not.
1036 IsTDStatusBabbleError (
1037 IN TD_STRUCT
*PtrTDStruct
1041 Detect whether NAK is received.
1043 @param PtrTDStruct Place to store TD_STRUCT pointer.
1045 @retval The NAK is received or not.
1049 IsTDStatusNAKReceived (
1050 IN TD_STRUCT
*PtrTDStruct
1054 Detect whether CRC/Time Out Error is encountered.
1056 @param PtrTDStruct Place to store TD_STRUCT pointer.
1058 @retval The CRC/Time Out Error is encountered or not.
1062 IsTDStatusCRCTimeOutError (
1063 IN TD_STRUCT
*PtrTDStruct
1067 Detect whether Bitstuff Error is received.
1069 @param PtrTDStruct Place to store TD_STRUCT pointer.
1071 @retval The Bitstuff Error is received or not.
1075 IsTDStatusBitStuffError (
1076 IN TD_STRUCT
*PtrTDStruct
1080 Retrieve the actual number of bytes that were tansferred.
1082 @param PtrTDStruct Place to store TD_STRUCT pointer.
1084 @retval The actual number of bytes that were tansferred.
1088 GetTDStatusActualLength (
1089 IN TD_STRUCT
*PtrTDStruct
1093 Retrieve the information of whether the Link Pointer field is valid or not.
1095 @param PtrTDStruct Place to store TD_STRUCT pointer.
1097 @retval The linker pointer field is valid or not.
1101 GetTDLinkPtrValidorInvalid (
1102 IN TD_STRUCT
*PtrTDStruct
1106 Count TD Number from PtrFirstTD.
1108 @param PtrFirstTD Place to store TD_STRUCT pointer.
1110 @retval The queued TDs number.
1115 IN TD_STRUCT
*PtrFirstTD
1121 @param PtrQH Place to store QH_STRUCT pointer.
1122 @param PtrTD Place to store TD_STRUCT pointer.
1127 IN QH_STRUCT
*PtrQH
,
1134 @param PtrPreTD Place to store TD_STRUCT pointer.
1135 @param PtrTD Place to store TD_STRUCT pointer.
1140 IN TD_STRUCT
*PtrPreTD
,
1145 Execute Control Transfer.
1147 @param UhcDev The UCHI device.
1148 @param PtrTD A pointer to TD_STRUCT data.
1149 @param ActualLen Actual transfer Length.
1150 @param TimeOut TimeOut value.
1151 @param TransferResult Transfer Result.
1153 @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
1154 @return EFI_TIMEOUT The transfer failed due to time out.
1155 @return EFI_SUCCESS The transfer finished OK.
1159 ExecuteControlTransfer (
1160 IN USB_UHC_DEV
*UhcDev
,
1161 IN TD_STRUCT
*PtrTD
,
1162 OUT UINTN
*ActualLen
,
1164 OUT UINT32
*TransferResult
1168 Execute Bulk Transfer.
1170 @param UhcDev The UCHI device.
1171 @param PtrTD A pointer to TD_STRUCT data.
1172 @param ActualLen Actual transfer Length.
1173 @param DataToggle DataToggle value.
1174 @param TimeOut TimeOut value.
1175 @param TransferResult Transfer Result.
1177 @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
1178 @return EFI_TIMEOUT The transfer failed due to time out.
1179 @return EFI_SUCCESS The transfer finished OK.
1184 IN USB_UHC_DEV
*UhcDev
,
1185 IN TD_STRUCT
*PtrTD
,
1186 IN OUT UINTN
*ActualLen
,
1187 IN UINT8
*DataToggle
,
1189 OUT UINT32
*TransferResult
1195 @param UhcDev The UCHI device.
1196 @param PtrFirstTD Place to store TD_STRUCT pointer.
1201 IN USB_UHC_DEV
*UhcDev
,
1202 IN TD_STRUCT
*PtrFirstTD
1208 @param PtrTD A pointer to TD_STRUCT data.
1209 @param Result The result to return.
1210 @param ErrTDPos The Error TD position.
1211 @param ActualTransferSize Actual transfer size.
1213 @retval The TD is executed successfully or not.
1218 IN TD_STRUCT
*PtrTD
,
1220 OUT UINTN
*ErrTDPos
,
1221 OUT UINTN
*ActualTransferSize
1225 Create Memory Block.
1227 @param UhcDev The UCHI device.
1228 @param MemoryHeader The Pointer to allocated memory block.
1229 @param MemoryBlockSizeInPages The page size of memory block to be allocated.
1231 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1232 @retval EFI_SUCCESS Success.
1237 IN USB_UHC_DEV
*UhcDev
,
1238 OUT MEMORY_MANAGE_HEADER
**MemoryHeader
,
1239 IN UINTN MemoryBlockSizeInPages
1243 Initialize UHCI memory management.
1245 @param UhcDev The UCHI device.
1247 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1248 @retval EFI_SUCCESS Success.
1252 InitializeMemoryManagement (
1253 IN USB_UHC_DEV
*UhcDev
1257 Initialize UHCI memory management.
1259 @param UhcDev The UCHI device.
1260 @param Pool Buffer pointer to store the buffer pointer.
1261 @param AllocSize The size of the pool to be allocated.
1263 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1264 @retval EFI_SUCCESS Success.
1269 IN USB_UHC_DEV
*UhcDev
,
1275 Alloc Memory In MemoryBlock.
1277 @param MemoryHeader The pointer to memory manage header.
1278 @param Pool Buffer pointer to store the buffer pointer.
1279 @param NumberOfMemoryUnit The size of the pool to be allocated.
1281 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1282 @retval EFI_SUCCESS Success.
1286 AllocMemInMemoryBlock (
1287 IN MEMORY_MANAGE_HEADER
*MemoryHeader
,
1289 IN UINTN NumberOfMemoryUnit
1295 @param UhcDev The UHCI device.
1296 @param Pool A pointer to store the buffer address.
1297 @param AllocSize The size of the pool to be freed.
1302 IN USB_UHC_DEV
*UhcDev
,
1308 Insert a new memory header into list.
1310 @param MemoryHeader A pointer to the memory header list.
1311 @param NewMemoryHeader A new memory header to be inserted into the list.
1315 InsertMemoryHeaderToList (
1316 IN MEMORY_MANAGE_HEADER
*MemoryHeader
,
1317 IN MEMORY_MANAGE_HEADER
*NewMemoryHeader
1321 Judge the memory block in the memory header is empty or not.
1323 @param MemoryHeaderPtr A pointer to the memory header list.
1325 @retval Whether the memory block in the memory header is empty or not.
1329 IsMemoryBlockEmptied (
1330 IN MEMORY_MANAGE_HEADER
*MemoryHeaderPtr
1334 remove a memory header from list.
1336 @param FirstMemoryHeader A pointer to the memory header list.
1337 @param FreeMemoryHeader A memory header to be removed into the list.
1342 IN MEMORY_MANAGE_HEADER
*FirstMemoryHeader
,
1343 IN MEMORY_MANAGE_HEADER
*FreeMemoryHeader
1347 Map address of request structure buffer.
1349 @param Uhc The UHCI device.
1350 @param Request The user request buffer.
1351 @param MappedAddr Mapped address of request.
1352 @param Map Identificaion of this mapping to return.
1354 @return EFI_SUCCESS Success.
1355 @return EFI_DEVICE_ERROR Fail to map the user request.
1359 UhciMapUserRequest (
1360 IN USB_UHC_DEV
*Uhc
,
1361 IN OUT VOID
*Request
,
1362 OUT UINT8
**MappedAddr
,
1367 Map address of user data buffer.
1369 @param Uhc The UHCI device.
1370 @param Direction Direction of the data transfer.
1371 @param Data The user data buffer.
1372 @param Len Length of the user data.
1373 @param PktId Packet identificaion.
1374 @param MappedAddr Mapped address to return.
1375 @param Map Identificaion of this mapping to return.
1377 @return EFI_SUCCESS Success.
1378 @return EFI_DEVICE_ERROR Fail to map the user data.
1383 IN USB_UHC_DEV
*Uhc
,
1384 IN EFI_USB_DATA_DIRECTION Direction
,
1388 OUT UINT8
**MappedAddr
,
1393 Provides the controller-specific addresses required to access system memory from a
1396 @param IoMmu Pointer to IOMMU PPI.
1397 @param Operation Indicates if the bus master is going to read or write to system memory.
1398 @param HostAddress The system memory address to map to the PCI controller.
1399 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
1401 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
1402 access the hosts HostAddress.
1403 @param Mapping A resulting value to pass to Unmap().
1405 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
1406 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
1407 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1408 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1409 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
1414 IN EDKII_IOMMU_PPI
*IoMmu
,
1415 IN EDKII_IOMMU_OPERATION Operation
,
1416 IN VOID
*HostAddress
,
1417 IN OUT UINTN
*NumberOfBytes
,
1418 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
1423 Completes the Map() operation and releases any corresponding resources.
1425 @param IoMmu Pointer to IOMMU PPI.
1426 @param Mapping The mapping value returned from Map().
1431 IN EDKII_IOMMU_PPI
*IoMmu
,
1436 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
1437 OperationBusMasterCommonBuffer64 mapping.
1439 @param IoMmu Pointer to IOMMU PPI.
1440 @param Pages The number of pages to allocate.
1441 @param HostAddress A pointer to store the base system memory address of the
1443 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
1444 access the hosts HostAddress.
1445 @param Mapping A resulting value to pass to Unmap().
1447 @retval EFI_SUCCESS The requested memory pages were allocated.
1448 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
1449 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
1450 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1451 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
1455 IoMmuAllocateBuffer (
1456 IN EDKII_IOMMU_PPI
*IoMmu
,
1458 OUT VOID
**HostAddress
,
1459 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
1464 Frees memory that was allocated with AllocateBuffer().
1466 @param IoMmu Pointer to IOMMU PPI.
1467 @param Pages The number of pages to free.
1468 @param HostAddress The base system memory address of the allocated range.
1469 @param Mapping The mapping value returned from Map().
1474 IN EDKII_IOMMU_PPI
*IoMmu
,
1476 IN VOID
*HostAddress
,
1483 @param IoMmu Pointer to pointer to IOMMU PPI.
1488 OUT EDKII_IOMMU_PPI
**IoMmu