]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/UhciDxe/UhciReg.c
3 The UHCI register operation routines.
5 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
16 @param PciIo The EFI_PCI_IO_PROTOCOL to use.
17 @param Offset Register offset to USB_BAR_INDEX.
19 @return Content of register.
24 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
31 Status
= PciIo
->Io
.Read (
40 if (EFI_ERROR (Status
)) {
41 DEBUG ((EFI_D_ERROR
, "UhciReadReg: PciIo Io.Read error: %r at offset %d\n", Status
, Offset
));
51 Write data to UHCI register.
53 @param PciIo The EFI_PCI_IO_PROTOCOL to use.
54 @param Offset Register offset to USB_BAR_INDEX.
55 @param Data Data to write.
60 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
67 Status
= PciIo
->Io
.Write (
76 if (EFI_ERROR (Status
)) {
77 DEBUG ((EFI_D_ERROR
, "UhciWriteReg: PciIo Io.Write error: %r at offset %d\n", Status
, Offset
));
83 Set a bit of the UHCI Register.
85 @param PciIo The EFI_PCI_IO_PROTOCOL to use.
86 @param Offset Register offset to USB_BAR_INDEX.
87 @param Bit The bit to set.
92 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
99 Data
= UhciReadReg (PciIo
, Offset
);
100 Data
= (UINT16
) (Data
|Bit
);
101 UhciWriteReg (PciIo
, Offset
, Data
);
106 Clear a bit of the UHCI Register.
108 @param PciIo The PCI_IO protocol to access the PCI.
109 @param Offset Register offset to USB_BAR_INDEX.
110 @param Bit The bit to clear.
115 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
122 Data
= UhciReadReg (PciIo
, Offset
);
123 Data
= (UINT16
) (Data
& ~Bit
);
124 UhciWriteReg (PciIo
, Offset
, Data
);
129 Clear all the interrutp status bits, these bits
132 @param Uhc The UHCI device.
136 UhciAckAllInterrupt (
140 UhciWriteReg (Uhc
->PciIo
, USBSTS_OFFSET
, 0x3F);
143 // If current HC is halted, re-enable it. Host Controller Process Error
144 // is a temporary error status.
146 if (!UhciIsHcWorking (Uhc
->PciIo
)) {
147 DEBUG ((EFI_D_ERROR
, "UhciAckAllInterrupt: re-enable the UHCI from system error\n"));
148 Uhc
->Usb2Hc
.SetState (&Uhc
->Usb2Hc
, EfiUsbHcStateOperational
);
154 Stop the host controller.
156 @param Uhc The UHCI device.
157 @param Timeout Max time allowed.
159 @retval EFI_SUCCESS The host controller is stopped.
160 @retval EFI_TIMEOUT Failed to stop the host controller.
172 UhciClearRegBit (Uhc
->PciIo
, USBCMD_OFFSET
, USBCMD_RS
);
175 // ensure the HC is in halt status after send the stop command
176 // Timeout is in us unit.
178 for (Index
= 0; Index
< (Timeout
/ 50) + 1; Index
++) {
179 UsbSts
= UhciReadReg (Uhc
->PciIo
, USBSTS_OFFSET
);
181 if ((UsbSts
& USBSTS_HCH
) == USBSTS_HCH
) {
193 Check whether the host controller operates well.
195 @param PciIo The PCI_IO protocol to use.
197 @retval TRUE Host controller is working.
198 @retval FALSE Host controller is halted or system error.
203 IN EFI_PCI_IO_PROTOCOL
*PciIo
208 UsbSts
= UhciReadReg (PciIo
, USBSTS_OFFSET
);
210 if ((UsbSts
& (USBSTS_HCPE
| USBSTS_HSE
| USBSTS_HCH
)) != 0) {
211 DEBUG ((EFI_D_ERROR
, "UhciIsHcWorking: current USB state is %x\n", UsbSts
));
220 Set the UHCI frame list base address. It can't use
221 UhciWriteReg which access memory in UINT16.
223 @param PciIo The EFI_PCI_IO_PROTOCOL to use.
224 @param Addr Address to set.
228 UhciSetFrameListBaseAddr (
229 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
236 Data
= (UINT32
) ((UINTN
) Addr
& 0xFFFFF000);
238 Status
= PciIo
->Io
.Write (
242 (UINT64
) USB_FRAME_BASE_OFFSET
,
247 if (EFI_ERROR (Status
)) {
248 DEBUG ((EFI_D_ERROR
, "UhciSetFrameListBaseAddr: PciIo Io.Write error: %r\n", Status
));
254 Disable USB Emulation.
256 @param PciIo The EFI_PCI_IO_PROTOCOL protocol to use.
260 UhciTurnOffUsbEmulation (
261 IN EFI_PCI_IO_PROTOCOL
*PciIo
271 USB_EMULATION_OFFSET
,