2 Private Header file for Usb Host Controller PEIM
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _RECOVERY_UHC_H_
11 #define _RECOVERY_UHC_H_
16 #include <Ppi/UsbController.h>
17 #include <Ppi/UsbHostController.h>
18 #include <Ppi/IoMmu.h>
19 #include <Ppi/EndOfPeiPhase.h>
21 #include <Library/DebugLib.h>
22 #include <Library/PeimEntryPoint.h>
23 #include <Library/PeiServicesLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/TimerLib.h>
26 #include <Library/IoLib.h>
27 #include <Library/PeiServicesLib.h>
29 #define USB_SLOW_SPEED_DEVICE 0x01
30 #define USB_FULL_SPEED_DEVICE 0x02
33 // One memory block uses 16 page
35 #define NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES 16
37 #define USBCMD 0 /* Command Register Offset 00-01h */
38 #define USBCMD_RS BIT0 /* Run/Stop */
39 #define USBCMD_HCRESET BIT1 /* Host reset */
40 #define USBCMD_GRESET BIT2 /* Global reset */
41 #define USBCMD_EGSM BIT3 /* Global Suspend Mode */
42 #define USBCMD_FGR BIT4 /* Force Global Resume */
43 #define USBCMD_SWDBG BIT5 /* SW Debug mode */
44 #define USBCMD_CF BIT6 /* Config Flag (sw only) */
45 #define USBCMD_MAXP BIT7 /* Max Packet (0 = 32, 1 = 64) */
48 #define USBSTS 2 /* Status Register Offset 02-03h */
49 #define USBSTS_USBINT BIT0 /* Interrupt due to IOC */
50 #define USBSTS_ERROR BIT1 /* Interrupt due to error */
51 #define USBSTS_RD BIT2 /* Resume Detect */
52 #define USBSTS_HSE BIT3 /* Host System Error - basically PCI problems */
53 #define USBSTS_HCPE BIT4 /* Host Controller Process Error - the scripts were buggy */
54 #define USBSTS_HCH BIT5 /* HC Halted */
56 /* Interrupt enable register */
57 #define USBINTR 4 /* Interrupt Enable Register 04-05h */
58 #define USBINTR_TIMEOUT BIT0 /* Timeout/CRC error enable */
59 #define USBINTR_RESUME BIT1 /* Resume interrupt enable */
60 #define USBINTR_IOC BIT2 /* Interrupt On Complete enable */
61 #define USBINTR_SP BIT3 /* Short packet interrupt enable */
63 /* Frame Number Register Offset 06-08h */
66 /* Frame List Base Address Register Offset 08-0Bh */
67 #define USBFLBASEADD 8
69 /* Start of Frame Modify Register Offset 0Ch */
72 /* USB port status and control registers */
73 #define USBPORTSC1 0x10 /*Port 1 offset 10-11h */
74 #define USBPORTSC2 0x12 /*Port 2 offset 12-13h */
76 #define USBPORTSC_CCS BIT0 /* Current Connect Status ("device present") */
77 #define USBPORTSC_CSC BIT1 /* Connect Status Change */
78 #define USBPORTSC_PED BIT2 /* Port Enable / Disable */
79 #define USBPORTSC_PEDC BIT3 /* Port Enable / Disable Change */
80 #define USBPORTSC_LSL BIT4 /* Line Status Low bit*/
81 #define USBPORTSC_LSH BIT5 /* Line Status High bit*/
82 #define USBPORTSC_RD BIT6 /* Resume Detect */
83 #define USBPORTSC_LSDA BIT8 /* Low Speed Device Attached */
84 #define USBPORTSC_PR BIT9 /* Port Reset */
85 #define USBPORTSC_SUSP BIT12 /* Suspend */
87 #define SETUP_PACKET_ID 0x2D
88 #define INPUT_PACKET_ID 0x69
89 #define OUTPUT_PACKET_ID 0xE1
90 #define ERROR_PACKET_ID 0x55
92 #define STALL_1_MICRO_SECOND 1
93 #define STALL_1_MILLI_SECOND 1000
99 UINT32 FrameListPtrTerminate
: 1;
100 UINT32 FrameListPtrQSelect
: 1;
101 UINT32 FrameListRsvd
: 2;
102 UINT32 FrameListPtr
: 28;
106 UINT32 QHHorizontalTerminate
: 1;
107 UINT32 QHHorizontalQSelect
: 1;
108 UINT32 QHHorizontalRsvd
: 2;
109 UINT32 QHHorizontalPtr
: 28;
110 UINT32 QHVerticalTerminate
: 1;
111 UINT32 QHVerticalQSelect
: 1;
112 UINT32 QHVerticalRsvd
: 2;
113 UINT32 QHVerticalPtr
: 28;
117 QUEUE_HEAD QueueHead
;
127 UINT32 TDLinkPtrTerminate
: 1;
128 UINT32 TDLinkPtrQSelect
: 1;
129 UINT32 TDLinkPtrDepthSelect
: 1;
130 UINT32 TDLinkPtrRsvd
: 1;
131 UINT32 TDLinkPtr
: 28;
132 UINT32 TDStatusActualLength
: 11;
133 UINT32 TDStatusRsvd
: 5;
135 UINT32 TDStatusIOC
: 1;
136 UINT32 TDStatusIOS
: 1;
137 UINT32 TDStatusLS
: 1;
138 UINT32 TDStatusErr
: 2;
139 UINT32 TDStatusSPD
: 1;
140 UINT32 TDStatusRsvd2
: 2;
141 UINT32 TDTokenPID
: 8;
142 UINT32 TDTokenDevAddr
: 7;
143 UINT32 TDTokenEndPt
: 4;
144 UINT32 TDTokenDataToggle
: 1;
145 UINT32 TDTokenRsvd
: 1;
146 UINT32 TDTokenMaxLen
: 11;
155 UINT16 TDBufferLength
;
161 typedef struct _MEMORY_MANAGE_HEADER MEMORY_MANAGE_HEADER
;
163 struct _MEMORY_MANAGE_HEADER
{
165 UINTN BitArraySizeInBytes
;
166 UINT8
*MemoryBlockPtr
;
167 UINTN MemoryBlockSizeInBytes
;
168 MEMORY_MANAGE_HEADER
*Next
;
171 #define USB_UHC_DEV_SIGNATURE SIGNATURE_32 ('p', 'u', 'h', 'c')
174 PEI_USB_HOST_CONTROLLER_PPI UsbHostControllerPpi
;
175 EDKII_IOMMU_PPI
*IoMmu
;
176 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor
;
178 // EndOfPei callback is used to stop the UHC DMA operation
179 // after exit PEI phase.
181 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList
;
183 UINT32 UsbHostControllerBaseAddress
;
184 FRAMELIST_ENTRY
*FrameListEntry
;
188 // Header1 used for QH,TD memory blocks management
190 MEMORY_MANAGE_HEADER
*Header1
;
194 #define PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS(a) CR (a, USB_UHC_DEV, UsbHostControllerPpi, USB_UHC_DEV_SIGNATURE)
195 #define PEI_RECOVERY_USB_UHC_DEV_FROM_THIS_NOTIFY(a) CR (a, USB_UHC_DEV, EndOfPeiNotifyList, USB_UHC_DEV_SIGNATURE)
198 Submits control transfer to a target USB device.
200 @param PeiServices The pointer of EFI_PEI_SERVICES.
201 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
202 @param DeviceAddress The target device address.
203 @param DeviceSpeed Target device speed.
204 @param MaximumPacketLength Maximum packet size the default control transfer
205 endpoint is capable of sending or receiving.
206 @param Request USB device request to send.
207 @param TransferDirection Specifies the data direction for the data stage.
208 @param Data Data buffer to be transmitted or received from USB device.
209 @param DataLength The size (in bytes) of the data buffer.
210 @param TimeOut Indicates the maximum timeout, in millisecond.
211 @param TransferResult Return the result of this control transfer.
213 @retval EFI_SUCCESS Transfer was completed successfully.
214 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
215 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
216 @retval EFI_TIMEOUT Transfer failed due to timeout.
217 @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
223 IN EFI_PEI_SERVICES
**PeiServices
,
224 IN PEI_USB_HOST_CONTROLLER_PPI
* This
,
225 IN UINT8 DeviceAddress
,
226 IN UINT8 DeviceSpeed
,
227 IN UINT8 MaximumPacketLength
,
228 IN EFI_USB_DEVICE_REQUEST
* Request
,
229 IN EFI_USB_DATA_DIRECTION TransferDirection
,
230 IN OUT VOID
*Data OPTIONAL
,
231 IN OUT UINTN
*DataLength OPTIONAL
,
233 OUT UINT32
*TransferResult
237 Submits bulk transfer to a bulk endpoint of a USB device.
239 @param PeiServices The pointer of EFI_PEI_SERVICES.
240 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
241 @param DeviceAddress Target device address.
242 @param EndPointAddress Endpoint number and its direction in bit 7.
243 @param MaximumPacketLength Maximum packet size the endpoint is capable of
244 sending or receiving.
245 @param Data Array of pointers to the buffers of data to transmit
246 from or receive into.
247 @param DataLength The lenght of the data buffer.
248 @param DataToggle On input, the initial data toggle for the transfer;
249 On output, it is updated to to next data toggle to use of
250 the subsequent bulk transfer.
251 @param TimeOut Indicates the maximum time, in millisecond, which the
252 transfer is allowed to complete.
253 @param TransferResult A pointer to the detailed result information of the
256 @retval EFI_SUCCESS The transfer was completed successfully.
257 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
258 @retval EFI_INVALID_PARAMETER Parameters are invalid.
259 @retval EFI_TIMEOUT The transfer failed due to timeout.
260 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
266 IN EFI_PEI_SERVICES
**PeiServices
,
267 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
268 IN UINT8 DeviceAddress
,
269 IN UINT8 EndPointAddress
,
270 IN UINT8 MaximumPacketLength
,
272 IN OUT UINTN
*DataLength
,
273 IN OUT UINT8
*DataToggle
,
275 OUT UINT32
*TransferResult
279 Retrieves the number of root hub ports.
281 @param[in] PeiServices The pointer to the PEI Services Table.
282 @param[in] This The pointer to this instance of the
283 PEI_USB_HOST_CONTROLLER_PPI.
284 @param[out] PortNumber The pointer to the number of the root hub ports.
286 @retval EFI_SUCCESS The port number was retrieved successfully.
287 @retval EFI_INVALID_PARAMETER PortNumber is NULL.
292 UhcGetRootHubPortNumber (
293 IN EFI_PEI_SERVICES
**PeiServices
,
294 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
295 OUT UINT8
*PortNumber
299 Retrieves the current status of a USB root hub port.
301 @param PeiServices The pointer of EFI_PEI_SERVICES.
302 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
303 @param PortNumber The root hub port to retrieve the state from.
304 @param PortStatus Variable to receive the port state.
306 @retval EFI_SUCCESS The status of the USB root hub port specified.
307 by PortNumber was returned in PortStatus.
308 @retval EFI_INVALID_PARAMETER PortNumber is invalid.
313 UhcGetRootHubPortStatus (
314 IN EFI_PEI_SERVICES
**PeiServices
,
315 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
317 OUT EFI_USB_PORT_STATUS
*PortStatus
321 Sets a feature for the specified root hub port.
323 @param PeiServices The pointer of EFI_PEI_SERVICES
324 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI
325 @param PortNumber Root hub port to set.
326 @param PortFeature Feature to set.
328 @retval EFI_SUCCESS The feature specified by PortFeature was set.
329 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
330 @retval EFI_TIMEOUT The time out occurred.
335 UhcSetRootHubPortFeature (
336 IN EFI_PEI_SERVICES
**PeiServices
,
337 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
339 IN EFI_USB_PORT_FEATURE PortFeature
343 Clears a feature for the specified root hub port.
345 @param PeiServices The pointer of EFI_PEI_SERVICES.
346 @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
347 @param PortNumber Specifies the root hub port whose feature
348 is requested to be cleared.
349 @param PortFeature Indicates the feature selector associated with the
350 feature clear request.
352 @retval EFI_SUCCESS The feature specified by PortFeature was cleared
353 for the USB root hub port specified by PortNumber.
354 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
359 UhcClearRootHubPortFeature (
360 IN EFI_PEI_SERVICES
**PeiServices
,
361 IN PEI_USB_HOST_CONTROLLER_PPI
*This
,
363 IN EFI_USB_PORT_FEATURE PortFeature
369 @param UhcDev UHCI Device.
371 @retval EFI_SUCCESS UHCI successfully initialized.
372 @retval EFI_OUT_OF_RESOURCES Resource can not be allocated.
377 IN USB_UHC_DEV
*UhcDev
381 Create Frame List Structure.
383 @param UhcDev UHCI device.
385 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
386 @retval EFI_SUCCESS Success.
395 Read a 16bit width data from Uhc HC IO space register.
397 @param UhcDev The UHCI device.
398 @param Port The IO space address of the register.
400 @retval the register content read.
405 IN USB_UHC_DEV
*UhcDev
,
410 Write a 16bit width data into Uhc HC IO space register.
412 @param UhcDev The UHCI device.
413 @param Port The IO space address of the register.
414 @param Data The data written into the register.
419 IN USB_UHC_DEV
*UhcDev
,
425 Write a 32bit width data into Uhc HC IO space register.
427 @param UhcDev The UHCI device.
428 @param Port The IO space address of the register.
429 @param Data The data written into the register.
434 IN USB_UHC_DEV
*UhcDev
,
440 Clear the content of UHCI's Status Register.
442 @param UhcDev The UHCI device.
443 @param StatusAddr The IO space address of the register.
448 IN USB_UHC_DEV
*UhcDev
,
453 Check whether the host controller operates well.
455 @param UhcDev The UHCI device.
456 @param StatusRegAddr The io address of status register.
458 @retval TRUE Host controller is working.
459 @retval FALSE Host controller is halted or system error.
464 IN USB_UHC_DEV
*UhcDev
,
465 IN UINT32 StatusRegAddr
469 Set Frame List Base Address.
471 @param UhcDev The UHCI device.
472 @param FrameListRegAddr The address of frame list register.
473 @param Addr The address of frame list table.
477 SetFrameListBaseAddress (
478 IN USB_UHC_DEV
*UhcDev
,
479 IN UINT32 FrameListRegAddr
,
484 Create QH and initialize.
486 @param UhcDev The UHCI device.
487 @param PtrQH Place to store QH_STRUCT pointer.
489 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
490 @retval EFI_SUCCESS Success.
495 IN USB_UHC_DEV
*UhcDev
,
496 OUT QH_STRUCT
**PtrQH
500 Set the horizontal link pointer in QH.
502 @param PtrQH Place to store QH_STRUCT pointer.
503 @param PtrNext Place to the next QH_STRUCT.
507 SetQHHorizontalLinkPtr (
513 Set a QH or TD horizontally to be connected with a specific QH.
515 @param PtrQH Place to store QH_STRUCT pointer.
516 @param IsQH Specify QH or TD is connected.
520 SetQHHorizontalQHorTDSelect (
526 Set the horizontal validor bit in QH.
528 @param PtrQH Place to store QH_STRUCT pointer.
529 @param IsValid Specify the horizontal linker is valid or not.
533 SetQHHorizontalValidorInvalid (
539 Set the vertical link pointer in QH.
541 @param PtrQH Place to store QH_STRUCT pointer.
542 @param PtrNext Place to the next QH_STRUCT.
546 SetQHVerticalLinkPtr (
552 Set a QH or TD vertically to be connected with a specific QH.
554 @param PtrQH Place to store QH_STRUCT pointer.
555 @param IsQH Specify QH or TD is connected.
559 SetQHVerticalQHorTDSelect (
565 Set the vertical validor bit in QH.
567 @param PtrQH Place to store QH_STRUCT pointer.
568 @param IsValid Specify the vertical linker is valid or not.
572 SetQHVerticalValidorInvalid (
579 Allocate TD or QH Struct.
581 @param UhcDev The UHCI device.
582 @param Size The size of allocation.
583 @param PtrStruct Place to store TD_STRUCT pointer.
585 @return EFI_SUCCESS Allocate successfully.
586 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
590 AllocateTDorQHStruct (
591 IN USB_UHC_DEV
*UhcDev
,
599 @param UhcDev The UHCI device.
600 @param PtrTD Place to store TD_STRUCT pointer.
602 @return EFI_SUCCESS Allocate successfully.
603 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
608 IN USB_UHC_DEV
*UhcDev
,
609 OUT TD_STRUCT
**PtrTD
613 Generate Setup Stage TD.
615 @param UhcDev The UHCI device.
616 @param DevAddr Device address.
617 @param Endpoint Endpoint number.
618 @param DeviceSpeed Device Speed.
619 @param DevRequest CPU memory address of request structure buffer to transfer.
620 @param RequestPhy PCI memory address of request structure buffer to transfer.
621 @param RequestLen Request length.
622 @param PtrTD TD_STRUCT generated.
624 @return EFI_SUCCESS Generate setup stage TD successfully.
625 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
630 IN USB_UHC_DEV
*UhcDev
,
633 IN UINT8 DeviceSpeed
,
634 IN UINT8
*DevRequest
,
635 IN UINT8
*RequestPhy
,
637 OUT TD_STRUCT
**PtrTD
641 Generate Data Stage TD.
643 @param UhcDev The UHCI device.
644 @param DevAddr Device address.
645 @param Endpoint Endpoint number.
646 @param PtrData CPU memory address of user data buffer to transfer.
647 @param DataPhy PCI memory address of user data buffer to transfer.
648 @param Len Data length.
649 @param PktID PacketID.
650 @param Toggle Data toggle value.
651 @param DeviceSpeed Device Speed.
652 @param PtrTD TD_STRUCT generated.
654 @return EFI_SUCCESS Generate data stage TD successfully.
655 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
660 IN USB_UHC_DEV
*UhcDev
,
668 IN UINT8 DeviceSpeed
,
669 OUT TD_STRUCT
**PtrTD
673 Generate Status Stage TD.
675 @param UhcDev The UHCI device.
676 @param DevAddr Device address.
677 @param Endpoint Endpoint number.
678 @param PktID PacketID.
679 @param DeviceSpeed Device Speed.
680 @param PtrTD TD_STRUCT generated.
682 @return EFI_SUCCESS Generate status stage TD successfully.
683 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
688 IN USB_UHC_DEV
*UhcDev
,
692 IN UINT8 DeviceSpeed
,
693 OUT TD_STRUCT
**PtrTD
697 Set the link pointer validor bit in TD.
699 @param PtrTDStruct Place to store TD_STRUCT pointer.
700 @param IsValid Specify the linker pointer is valid or not.
704 SetTDLinkPtrValidorInvalid (
705 IN TD_STRUCT
*PtrTDStruct
,
710 Set the Link Pointer pointing to a QH or TD.
712 @param PtrTDStruct Place to store TD_STRUCT pointer.
713 @param IsQH Specify QH or TD is connected.
717 SetTDLinkPtrQHorTDSelect (
718 IN TD_STRUCT
*PtrTDStruct
,
723 Set the traverse is depth-first or breadth-first.
725 @param PtrTDStruct Place to store TD_STRUCT pointer.
726 @param IsDepth Specify the traverse is depth-first or breadth-first.
730 SetTDLinkPtrDepthorBreadth (
731 IN TD_STRUCT
*PtrTDStruct
,
736 Set TD Link Pointer in TD.
738 @param PtrTDStruct Place to store TD_STRUCT pointer.
739 @param PtrNext Place to the next TD_STRUCT.
744 IN TD_STRUCT
*PtrTDStruct
,
751 @param PtrTDStruct Place to store TD_STRUCT pointer.
753 @retval Get TD Link Pointer in TD.
758 IN TD_STRUCT
*PtrTDStruct
763 Enable/Disable short packet detection mechanism.
765 @param PtrTDStruct Place to store TD_STRUCT pointer.
766 @param IsEnable Enable or disable short packet detection mechanism.
770 EnableorDisableTDShortPacket (
771 IN TD_STRUCT
*PtrTDStruct
,
776 Set the max error counter in TD.
778 @param PtrTDStruct Place to store TD_STRUCT pointer.
779 @param MaxErrors The number of allowable error.
783 SetTDControlErrorCounter (
784 IN TD_STRUCT
*PtrTDStruct
,
789 Set the TD is targeting a low-speed device or not.
791 @param PtrTDStruct Place to store TD_STRUCT pointer.
792 @param IsLowSpeedDevice Whether The device is low-speed.
796 SetTDLoworFullSpeedDevice (
797 IN TD_STRUCT
*PtrTDStruct
,
798 IN BOOLEAN IsLowSpeedDevice
802 Set the TD is isochronous transfer type or not.
804 @param PtrTDStruct Place to store TD_STRUCT pointer.
805 @param IsIsochronous Whether the transaction isochronous transfer type.
809 SetTDControlIsochronousorNot (
810 IN TD_STRUCT
*PtrTDStruct
,
811 IN BOOLEAN IsIsochronous
815 Set if UCHI should issue an interrupt on completion of the frame
816 in which this TD is executed
818 @param PtrTDStruct Place to store TD_STRUCT pointer.
819 @param IsSet Whether HC should issue an interrupt on completion.
823 SetorClearTDControlIOC (
824 IN TD_STRUCT
*PtrTDStruct
,
829 Set if the TD is active and can be executed.
831 @param PtrTDStruct Place to store TD_STRUCT pointer.
832 @param IsActive Whether the TD is active and can be executed.
836 SetTDStatusActiveorInactive (
837 IN TD_STRUCT
*PtrTDStruct
,
842 Specifies the maximum number of data bytes allowed for the transfer.
844 @param PtrTDStruct Place to store TD_STRUCT pointer.
845 @param MaxLen The maximum number of data bytes allowed.
847 @retval The allowed maximum number of data.
850 SetTDTokenMaxLength (
851 IN TD_STRUCT
*PtrTDStruct
,
856 Set the data toggle bit to DATA1.
858 @param PtrTDStruct Place to store TD_STRUCT pointer.
862 SetTDTokenDataToggle1 (
863 IN TD_STRUCT
*PtrTDStruct
867 Set the data toggle bit to DATA0.
869 @param PtrTDStruct Place to store TD_STRUCT pointer.
873 SetTDTokenDataToggle0 (
874 IN TD_STRUCT
*PtrTDStruct
878 Set EndPoint Number the TD is targeting at.
880 @param PtrTDStruct Place to store TD_STRUCT pointer.
881 @param EndPoint The Endport number of the target.
886 IN TD_STRUCT
*PtrTDStruct
,
891 Set Device Address the TD is targeting at.
893 @param PtrTDStruct Place to store TD_STRUCT pointer.
894 @param DevAddr The Device Address of the target.
898 SetTDTokenDeviceAddress (
899 IN TD_STRUCT
*PtrTDStruct
,
904 Set Packet Identification the TD is targeting at.
906 @param PtrTDStruct Place to store TD_STRUCT pointer.
907 @param PacketID The Packet Identification of the target.
912 IN TD_STRUCT
*PtrTDStruct
,
917 Set the beginning address of the data buffer that will be used
918 during the transaction.
920 @param PtrTDStruct Place to store TD_STRUCT pointer.
925 IN TD_STRUCT
*PtrTDStruct
929 Detect whether the TD is active.
931 @param PtrTDStruct Place to store TD_STRUCT pointer.
933 @retval The TD is active or not.
938 IN TD_STRUCT
*PtrTDStruct
942 Detect whether the TD is stalled.
944 @param PtrTDStruct Place to store TD_STRUCT pointer.
946 @retval The TD is stalled or not.
951 IN TD_STRUCT
*PtrTDStruct
955 Detect whether Data Buffer Error is happened.
957 @param PtrTDStruct Place to store TD_STRUCT pointer.
959 @retval The Data Buffer Error is happened or not.
963 IsTDStatusBufferError (
964 IN TD_STRUCT
*PtrTDStruct
968 Detect whether Babble Error is happened.
970 @param PtrTDStruct Place to store TD_STRUCT pointer.
972 @retval The Babble Error is happened or not.
976 IsTDStatusBabbleError (
977 IN TD_STRUCT
*PtrTDStruct
981 Detect whether NAK is received.
983 @param PtrTDStruct Place to store TD_STRUCT pointer.
985 @retval The NAK is received or not.
989 IsTDStatusNAKReceived (
990 IN TD_STRUCT
*PtrTDStruct
994 Detect whether CRC/Time Out Error is encountered.
996 @param PtrTDStruct Place to store TD_STRUCT pointer.
998 @retval The CRC/Time Out Error is encountered or not.
1002 IsTDStatusCRCTimeOutError (
1003 IN TD_STRUCT
*PtrTDStruct
1007 Detect whether Bitstuff Error is received.
1009 @param PtrTDStruct Place to store TD_STRUCT pointer.
1011 @retval The Bitstuff Error is received or not.
1015 IsTDStatusBitStuffError (
1016 IN TD_STRUCT
*PtrTDStruct
1020 Retrieve the actual number of bytes that were tansferred.
1022 @param PtrTDStruct Place to store TD_STRUCT pointer.
1024 @retval The actual number of bytes that were tansferred.
1028 GetTDStatusActualLength (
1029 IN TD_STRUCT
*PtrTDStruct
1033 Retrieve the information of whether the Link Pointer field is valid or not.
1035 @param PtrTDStruct Place to store TD_STRUCT pointer.
1037 @retval The linker pointer field is valid or not.
1041 GetTDLinkPtrValidorInvalid (
1042 IN TD_STRUCT
*PtrTDStruct
1046 Count TD Number from PtrFirstTD.
1048 @param PtrFirstTD Place to store TD_STRUCT pointer.
1050 @retval The queued TDs number.
1055 IN TD_STRUCT
*PtrFirstTD
1061 @param PtrQH Place to store QH_STRUCT pointer.
1062 @param PtrTD Place to store TD_STRUCT pointer.
1067 IN QH_STRUCT
*PtrQH
,
1074 @param PtrPreTD Place to store TD_STRUCT pointer.
1075 @param PtrTD Place to store TD_STRUCT pointer.
1080 IN TD_STRUCT
*PtrPreTD
,
1085 Execute Control Transfer.
1087 @param UhcDev The UCHI device.
1088 @param PtrTD A pointer to TD_STRUCT data.
1089 @param ActualLen Actual transfer Length.
1090 @param TimeOut TimeOut value.
1091 @param TransferResult Transfer Result.
1093 @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
1094 @return EFI_TIMEOUT The transfer failed due to time out.
1095 @return EFI_SUCCESS The transfer finished OK.
1099 ExecuteControlTransfer (
1100 IN USB_UHC_DEV
*UhcDev
,
1101 IN TD_STRUCT
*PtrTD
,
1102 OUT UINTN
*ActualLen
,
1104 OUT UINT32
*TransferResult
1108 Execute Bulk Transfer.
1110 @param UhcDev The UCHI device.
1111 @param PtrTD A pointer to TD_STRUCT data.
1112 @param ActualLen Actual transfer Length.
1113 @param DataToggle DataToggle value.
1114 @param TimeOut TimeOut value.
1115 @param TransferResult Transfer Result.
1117 @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
1118 @return EFI_TIMEOUT The transfer failed due to time out.
1119 @return EFI_SUCCESS The transfer finished OK.
1124 IN USB_UHC_DEV
*UhcDev
,
1125 IN TD_STRUCT
*PtrTD
,
1126 IN OUT UINTN
*ActualLen
,
1127 IN UINT8
*DataToggle
,
1129 OUT UINT32
*TransferResult
1135 @param UhcDev The UCHI device.
1136 @param PtrFirstTD Place to store TD_STRUCT pointer.
1141 IN USB_UHC_DEV
*UhcDev
,
1142 IN TD_STRUCT
*PtrFirstTD
1148 @param PtrTD A pointer to TD_STRUCT data.
1149 @param Result The result to return.
1150 @param ErrTDPos The Error TD position.
1151 @param ActualTransferSize Actual transfer size.
1153 @retval The TD is executed successfully or not.
1158 IN TD_STRUCT
*PtrTD
,
1160 OUT UINTN
*ErrTDPos
,
1161 OUT UINTN
*ActualTransferSize
1165 Create Memory Block.
1167 @param UhcDev The UCHI device.
1168 @param MemoryHeader The Pointer to allocated memory block.
1169 @param MemoryBlockSizeInPages The page size of memory block to be allocated.
1171 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1172 @retval EFI_SUCCESS Success.
1177 IN USB_UHC_DEV
*UhcDev
,
1178 OUT MEMORY_MANAGE_HEADER
**MemoryHeader
,
1179 IN UINTN MemoryBlockSizeInPages
1183 Initialize UHCI memory management.
1185 @param UhcDev The UCHI device.
1187 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1188 @retval EFI_SUCCESS Success.
1192 InitializeMemoryManagement (
1193 IN USB_UHC_DEV
*UhcDev
1197 Initialize UHCI memory management.
1199 @param UhcDev The UCHI device.
1200 @param Pool Buffer pointer to store the buffer pointer.
1201 @param AllocSize The size of the pool to be allocated.
1203 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1204 @retval EFI_SUCCESS Success.
1209 IN USB_UHC_DEV
*UhcDev
,
1215 Alloc Memory In MemoryBlock.
1217 @param MemoryHeader The pointer to memory manage header.
1218 @param Pool Buffer pointer to store the buffer pointer.
1219 @param NumberOfMemoryUnit The size of the pool to be allocated.
1221 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1222 @retval EFI_SUCCESS Success.
1226 AllocMemInMemoryBlock (
1227 IN MEMORY_MANAGE_HEADER
*MemoryHeader
,
1229 IN UINTN NumberOfMemoryUnit
1235 @param UhcDev The UHCI device.
1236 @param Pool A pointer to store the buffer address.
1237 @param AllocSize The size of the pool to be freed.
1242 IN USB_UHC_DEV
*UhcDev
,
1248 Insert a new memory header into list.
1250 @param MemoryHeader A pointer to the memory header list.
1251 @param NewMemoryHeader A new memory header to be inserted into the list.
1255 InsertMemoryHeaderToList (
1256 IN MEMORY_MANAGE_HEADER
*MemoryHeader
,
1257 IN MEMORY_MANAGE_HEADER
*NewMemoryHeader
1262 Map address of request structure buffer.
1264 @param Uhc The UHCI device.
1265 @param Request The user request buffer.
1266 @param MappedAddr Mapped address of request.
1267 @param Map Identificaion of this mapping to return.
1269 @return EFI_SUCCESS Success.
1270 @return EFI_DEVICE_ERROR Fail to map the user request.
1274 UhciMapUserRequest (
1275 IN USB_UHC_DEV
*Uhc
,
1276 IN OUT VOID
*Request
,
1277 OUT UINT8
**MappedAddr
,
1282 Map address of user data buffer.
1284 @param Uhc The UHCI device.
1285 @param Direction Direction of the data transfer.
1286 @param Data The user data buffer.
1287 @param Len Length of the user data.
1288 @param PktId Packet identificaion.
1289 @param MappedAddr Mapped address to return.
1290 @param Map Identificaion of this mapping to return.
1292 @return EFI_SUCCESS Success.
1293 @return EFI_DEVICE_ERROR Fail to map the user data.
1298 IN USB_UHC_DEV
*Uhc
,
1299 IN EFI_USB_DATA_DIRECTION Direction
,
1303 OUT UINT8
**MappedAddr
,
1308 Provides the controller-specific addresses required to access system memory from a
1311 @param IoMmu Pointer to IOMMU PPI.
1312 @param Operation Indicates if the bus master is going to read or write to system memory.
1313 @param HostAddress The system memory address to map to the PCI controller.
1314 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
1316 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
1317 access the hosts HostAddress.
1318 @param Mapping A resulting value to pass to Unmap().
1320 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
1321 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
1322 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1323 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1324 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
1329 IN EDKII_IOMMU_PPI
*IoMmu
,
1330 IN EDKII_IOMMU_OPERATION Operation
,
1331 IN VOID
*HostAddress
,
1332 IN OUT UINTN
*NumberOfBytes
,
1333 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
1338 Completes the Map() operation and releases any corresponding resources.
1340 @param IoMmu Pointer to IOMMU PPI.
1341 @param Mapping The mapping value returned from Map().
1346 IN EDKII_IOMMU_PPI
*IoMmu
,
1351 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
1352 OperationBusMasterCommonBuffer64 mapping.
1354 @param IoMmu Pointer to IOMMU PPI.
1355 @param Pages The number of pages to allocate.
1356 @param HostAddress A pointer to store the base system memory address of the
1358 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
1359 access the hosts HostAddress.
1360 @param Mapping A resulting value to pass to Unmap().
1362 @retval EFI_SUCCESS The requested memory pages were allocated.
1363 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
1364 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
1365 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1366 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
1370 IoMmuAllocateBuffer (
1371 IN EDKII_IOMMU_PPI
*IoMmu
,
1373 OUT VOID
**HostAddress
,
1374 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
1382 @param IoMmu Pointer to pointer to IOMMU PPI.
1387 OUT EDKII_IOMMU_PPI
**IoMmu