TianoCore EDK2 master
Loading...
Searching...
No Matches
UhciReg.c
Go to the documentation of this file.
1
10#include "Uhci.h"
11
21UINT16
24 IN UINT32 Offset
25 )
26{
27 UINT16 Data;
28 EFI_STATUS Status;
29
30 Status = PciIo->Io.Read (
31 PciIo,
32 EfiPciIoWidthUint16,
33 USB_BAR_INDEX,
34 Offset,
35 1,
36 &Data
37 );
38
39 if (EFI_ERROR (Status)) {
40 DEBUG ((DEBUG_ERROR, "UhciReadReg: PciIo Io.Read error: %r at offset %d\n", Status, Offset));
41
42 Data = 0xFFFF;
43 }
44
45 return Data;
46}
47
56VOID
59 IN UINT32 Offset,
60 IN UINT16 Data
61 )
62{
63 EFI_STATUS Status;
64
65 Status = PciIo->Io.Write (
66 PciIo,
67 EfiPciIoWidthUint16,
68 USB_BAR_INDEX,
69 Offset,
70 1,
71 &Data
72 );
73
74 if (EFI_ERROR (Status)) {
75 DEBUG ((DEBUG_ERROR, "UhciWriteReg: PciIo Io.Write error: %r at offset %d\n", Status, Offset));
76 }
77}
78
87VOID
90 IN UINT32 Offset,
91 IN UINT16 Bit
92 )
93{
94 UINT16 Data;
95
96 Data = UhciReadReg (PciIo, Offset);
97 Data = (UINT16)(Data |Bit);
98 UhciWriteReg (PciIo, Offset, Data);
99}
100
109VOID
111 IN EFI_PCI_IO_PROTOCOL *PciIo,
112 IN UINT32 Offset,
113 IN UINT16 Bit
114 )
115{
116 UINT16 Data;
117
118 Data = UhciReadReg (PciIo, Offset);
119 Data = (UINT16)(Data & ~Bit);
120 UhciWriteReg (PciIo, Offset, Data);
121}
122
130VOID
132 IN USB_HC_DEV *Uhc
133 )
134{
135 UhciWriteReg (Uhc->PciIo, USBSTS_OFFSET, 0x3F);
136
137 //
138 // If current HC is halted, re-enable it. Host Controller Process Error
139 // is a temporary error status.
140 //
141 if (!UhciIsHcWorking (Uhc->PciIo)) {
142 DEBUG ((DEBUG_ERROR, "UhciAckAllInterrupt: re-enable the UHCI from system error\n"));
143 Uhc->Usb2Hc.SetState (&Uhc->Usb2Hc, EfiUsbHcStateOperational);
144 }
145}
146
159 IN USB_HC_DEV *Uhc,
160 IN UINTN Timeout
161 )
162{
163 UINT16 UsbSts;
164 UINTN Index;
165
166 UhciClearRegBit (Uhc->PciIo, USBCMD_OFFSET, USBCMD_RS);
167
168 //
169 // ensure the HC is in halt status after send the stop command
170 // Timeout is in us unit.
171 //
172 for (Index = 0; Index < (Timeout / 50) + 1; Index++) {
173 UsbSts = UhciReadReg (Uhc->PciIo, USBSTS_OFFSET);
174
175 if ((UsbSts & USBSTS_HCH) == USBSTS_HCH) {
176 return EFI_SUCCESS;
177 }
178
179 gBS->Stall (50);
180 }
181
182 return EFI_TIMEOUT;
183}
184
194BOOLEAN
197 )
198{
199 UINT16 UsbSts;
200
201 UsbSts = UhciReadReg (PciIo, USBSTS_OFFSET);
202
203 if ((UsbSts & (USBSTS_HCPE | USBSTS_HSE | USBSTS_HCH)) != 0) {
204 DEBUG ((DEBUG_ERROR, "UhciIsHcWorking: current USB state is %x\n", UsbSts));
205 return FALSE;
206 }
207
208 return TRUE;
209}
210
219VOID
221 IN EFI_PCI_IO_PROTOCOL *PciIo,
222 IN VOID *Addr
223 )
224{
225 EFI_STATUS Status;
226 UINT32 Data;
227
228 Data = (UINT32)((UINTN)Addr & 0xFFFFF000);
229
230 Status = PciIo->Io.Write (
231 PciIo,
232 EfiPciIoWidthUint32,
233 USB_BAR_INDEX,
234 (UINT64)USB_FRAME_BASE_OFFSET,
235 1,
236 &Data
237 );
238
239 if (EFI_ERROR (Status)) {
240 DEBUG ((DEBUG_ERROR, "UhciSetFrameListBaseAddr: PciIo Io.Write error: %r\n", Status));
241 }
242}
243
250VOID
253 )
254{
255 UINT16 Command;
256
257 Command = 0;
258
259 PciIo->Pci.Write (
260 PciIo,
261 EfiPciIoWidthUint16,
262 USB_EMULATION_OFFSET,
263 1,
264 &Command
265 );
266}
UINT64 UINTN
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
@ EfiUsbHcStateOperational
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
BOOLEAN UhciIsHcWorking(IN EFI_PCI_IO_PROTOCOL *PciIo)
Definition: UhciReg.c:195
EFI_STATUS UhciStopHc(IN USB_HC_DEV *Uhc, IN UINTN Timeout)
Definition: UhciReg.c:158
VOID UhciClearRegBit(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT32 Offset, IN UINT16 Bit)
Definition: UhciReg.c:110
VOID UhciTurnOffUsbEmulation(IN EFI_PCI_IO_PROTOCOL *PciIo)
Definition: UhciReg.c:251
VOID UhciWriteReg(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT32 Offset, IN UINT16 Data)
Definition: UhciReg.c:57
VOID UhciSetRegBit(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT32 Offset, IN UINT16 Bit)
Definition: UhciReg.c:88
VOID UhciSetFrameListBaseAddr(IN EFI_PCI_IO_PROTOCOL *PciIo, IN VOID *Addr)
Definition: UhciReg.c:220
UINT16 UhciReadReg(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT32 Offset)
Definition: UhciReg.c:22
VOID UhciAckAllInterrupt(IN USB_HC_DEV *Uhc)
Definition: UhciReg.c:131