]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/EhciDxe/EhciDebug.c
1. Sync Tcp4 protocol definitions to match UEFI 2.1
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / EhciDebug.c
1 /** @file
2
3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 EhciDebug.c
15
16 Abstract:
17 This file provides the information dump support for EHCI when in debug mode.
18 You can dynamically adjust the debug level by changing variable mEhcDebugLevel
19 and mEhcErrorLevel.
20
21 Revision History
22
23 **/
24
25
26 #include "Ehci.h"
27
28 #ifdef EFI_DEBUG
29 UINTN mEhcDebugMask = USB_DEBUG_FORCE_OUTPUT;
30
31
32 /**
33 EHCI's debug output function. It determines whether
34 to output by the mask and level
35
36 @param Level The output level
37 @param Format The format parameters to the print
38 @param ... The variable length parameters after format
39
40 @return None
41
42 **/
43 VOID
44 EhciDebugPrint (
45 IN UINTN Level,
46 IN CHAR8 *Format,
47 ...
48 )
49 {
50
51 VA_LIST Marker;
52
53 VA_START (Marker, Format);
54
55 if (Level & mEhcDebugMask) {
56 if (mEhcDebugMask & USB_DEBUG_FORCE_OUTPUT) {
57 DebugVPrint (DEBUG_ERROR, Format, Marker);
58 } else {
59 DebugVPrint (DEBUG_INFO, Format, Marker);
60 }
61 }
62
63 VA_END (Marker);
64 }
65
66
67 /**
68 EHCI's debug output function. It determines whether
69 to output by the mask and level
70
71 @param Format The format parameters to the print
72 @param ... The variable length parameters after format
73
74 @return None
75
76 **/
77 VOID
78 EhcDebug (
79 IN CHAR8 *Format,
80 ...
81 )
82 {
83 VA_LIST Marker;
84
85 VA_START (Marker, Format);
86 DebugVPrint (DEBUG_INFO, Format, Marker);
87 VA_END (Marker);
88 }
89
90
91 /**
92 EHCI's error output function. It determines whether
93 to output by the mask and level
94
95 @param Format The format parameters to the print
96 @param ... The variable length parameters after format
97
98 @return None
99
100 **/
101 VOID
102 EhcError (
103 IN CHAR8 *Format,
104 ...
105 )
106 {
107
108 VA_LIST Marker;
109
110 VA_START (Marker, Format);
111 DebugVPrint (DEBUG_ERROR, Format, Marker);
112 VA_END (Marker);
113 }
114
115
116 /**
117 Dump the status byte in QTD/QH to a more friendly
118 format
119
120 @param State The state in the QTD/QH
121 @param Level The output level
122
123 @return None
124
125 **/
126 STATIC
127 VOID
128 EhcDumpStatus (
129 IN UINT32 State,
130 IN UINTN Level
131 )
132 {
133 if (EHC_BIT_IS_SET (State, QTD_STAT_DO_PING)) {
134 EhciDebugPrint (Level, " Do_Ping");
135 } else {
136 EhciDebugPrint (Level, " Do_Out");
137 }
138
139 if (EHC_BIT_IS_SET (State, QTD_STAT_DO_CS)) {
140 EhciDebugPrint (Level, " Do_CS");
141 } else {
142 EhciDebugPrint (Level, " Do_SS");
143 }
144
145 if (EHC_BIT_IS_SET (State, QTD_STAT_TRANS_ERR)) {
146 EhciDebugPrint (Level, " Transfer_Error");
147 }
148
149 if (EHC_BIT_IS_SET (State, QTD_STAT_BABBLE_ERR)) {
150 EhciDebugPrint (Level, " Babble_Error");
151 }
152
153 if (EHC_BIT_IS_SET (State, QTD_STAT_BUFF_ERR)) {
154 EhciDebugPrint (Level, " Buffer_Error");
155 }
156
157 if (EHC_BIT_IS_SET (State, QTD_STAT_HALTED)) {
158 EhciDebugPrint (Level, " Halted");
159 }
160
161 if (EHC_BIT_IS_SET (State, QTD_STAT_ACTIVE)) {
162 EhciDebugPrint (Level, " Active");
163 }
164
165 EhciDebugPrint (Level, "\n");
166 }
167
168
169 /**
170 Dump the fields of a QTD
171
172 @param Qtd The QTD to dump
173 @param Msg The message to print before the dump
174
175 @return None
176
177 **/
178 VOID
179 EhcDumpQtd (
180 IN EHC_QTD *Qtd,
181 IN UINT8 *Msg
182 )
183 {
184 QTD_HW *QtdHw;
185 UINTN Index;
186 UINTN Level;
187
188 Level = EHC_DEBUG_QTD;
189
190 if (Msg != NULL) {
191 EhciDebugPrint (Level, Msg);
192 }
193
194 EhciDebugPrint (Level, "Queue TD @ 0x%x, data length %d\n", Qtd, Qtd->DataLen);
195
196 QtdHw = &Qtd->QtdHw;
197
198 EhciDebugPrint (Level, "Next QTD : %x\n", QtdHw->NextQtd);
199 EhciDebugPrint (Level, "AltNext QTD : %x\n", QtdHw->AltNext);
200 EhciDebugPrint (Level, "Status : %x\n", QtdHw->Status);
201 EhcDumpStatus (QtdHw->Status, Level);
202
203 if (QtdHw->Pid == QTD_PID_SETUP) {
204 EhciDebugPrint (Level, "PID : Setup\n");
205
206 } else if (QtdHw->Pid == QTD_PID_INPUT) {
207 EhciDebugPrint (Level, "PID : IN\n");
208
209 } else if (QtdHw->Pid == QTD_PID_OUTPUT) {
210 EhciDebugPrint (Level, "PID : OUT\n");
211
212 }
213
214 EhciDebugPrint (Level, "Error Count : %d\n", QtdHw->ErrCnt);
215 EhciDebugPrint (Level, "Current Page : %d\n", QtdHw->CurPage);
216 EhciDebugPrint (Level, "IOC : %d\n", QtdHw->IOC);
217 EhciDebugPrint (Level, "Total Bytes : %d\n", QtdHw->TotalBytes);
218 EhciDebugPrint (Level, "Data Toggle : %d\n", QtdHw->DataToggle);
219
220 for (Index = 0; Index < 5; Index++) {
221 EhciDebugPrint (Level, "Page[%d] : 0x%x\n", Index, QtdHw->Page[Index]);
222 }
223 }
224
225
226 /**
227 Dump the queue head
228
229 @param Qh The queue head to dump
230 @param Msg The message to print before the dump
231 @param DumpBuf Whether to dump the memory buffer of the associated QTD
232
233 @return None
234
235 **/
236 VOID
237 EhcDumpQh (
238 IN EHC_QH *Qh,
239 IN UINT8 *Msg,
240 IN BOOLEAN DumpBuf
241 )
242 {
243 EHC_QTD *Qtd;
244 QH_HW *QhHw;
245 LIST_ENTRY *Entry;
246 UINTN Index;
247 UINTN Level;
248
249 Level = EHC_DEBUG_QH;
250
251 if (Msg != NULL) {
252 EhciDebugPrint (Level, Msg);
253 }
254
255 EhciDebugPrint (Level, "Queue head @ 0x%x, interval %d, next qh %x\n",
256 Qh, Qh->Interval, Qh->NextQh);
257
258 QhHw = &Qh->QhHw;
259
260 EhciDebugPrint (Level, "Hoziontal link: %x\n", QhHw->HorizonLink);
261 EhciDebugPrint (Level, "Device address: %d\n", QhHw->DeviceAddr);
262 EhciDebugPrint (Level, "Inactive : %d\n", QhHw->Inactive);
263 EhciDebugPrint (Level, "EP number : %d\n", QhHw->EpNum);
264 EhciDebugPrint (Level, "EP speed : %d\n", QhHw->EpSpeed);
265 EhciDebugPrint (Level, "DT control : %d\n", QhHw->DtCtrl);
266 EhciDebugPrint (Level, "Reclaim head : %d\n", QhHw->ReclaimHead);
267 EhciDebugPrint (Level, "Max packet len: %d\n", QhHw->MaxPacketLen);
268 EhciDebugPrint (Level, "Ctrl EP : %d\n", QhHw->CtrlEp);
269 EhciDebugPrint (Level, "Nak reload : %d\n", QhHw->NakReload);
270
271 EhciDebugPrint (Level, "SMask : %x\n", QhHw->SMask);
272 EhciDebugPrint (Level, "CMask : %x\n", QhHw->CMask);
273 EhciDebugPrint (Level, "Hub address : %d\n", QhHw->HubAddr);
274 EhciDebugPrint (Level, "Hub port : %d\n", QhHw->PortNum);
275 EhciDebugPrint (Level, "Multiplier : %d\n", QhHw->Multiplier);
276
277 EhciDebugPrint (Level, "Cur QTD : %x\n", QhHw->CurQtd);
278
279 EhciDebugPrint (Level, "Next QTD : %x\n", QhHw->NextQtd);
280 EhciDebugPrint (Level, "AltNext QTD : %x\n", QhHw->AltQtd);
281 EhciDebugPrint (Level, "Status : %x\n", QhHw->Status);
282 EhcDumpStatus (QhHw->Status, Level);
283
284 if (QhHw->Pid == QTD_PID_SETUP) {
285 EhciDebugPrint (Level, "PID : Setup\n");
286
287 } else if (QhHw->Pid == QTD_PID_INPUT) {
288 EhciDebugPrint (Level, "PID : IN\n");
289
290 } else if (QhHw->Pid == QTD_PID_OUTPUT) {
291 EhciDebugPrint (Level, "PID : OUT\n");
292 }
293
294 EhciDebugPrint (Level, "Error Count : %d\n", QhHw->ErrCnt);
295 EhciDebugPrint (Level, "Current Page : %d\n", QhHw->CurPage);
296 EhciDebugPrint (Level, "IOC : %d\n", QhHw->IOC);
297 EhciDebugPrint (Level, "Total Bytes : %d\n", QhHw->TotalBytes);
298 EhciDebugPrint (Level, "Data Toggle : %d\n", QhHw->DataToggle);
299
300 for (Index = 0; Index < 5; Index++) {
301 EhciDebugPrint (Level, "Page[%d] : 0x%x\n", Index, QhHw->Page[Index]);
302 }
303
304 EhciDebugPrint (Level, "\n");
305
306 EFI_LIST_FOR_EACH (Entry, &Qh->Qtds) {
307 Qtd = EFI_LIST_CONTAINER (Entry, EHC_QTD, QtdList);
308 EhcDumpQtd (Qtd, NULL);
309
310 if (DumpBuf && (Qtd->DataLen != 0)) {
311 EhcDumpBuf (Qtd->Data, Qtd->DataLen);
312 }
313 }
314 }
315
316
317 /**
318 Dump the buffer in the form of hex
319
320 @param Buf The buffer to dump
321 @param Len The length of buffer
322
323 @return None
324
325 **/
326 VOID
327 EhcDumpBuf (
328 IN UINT8 *Buf,
329 IN UINTN Len
330 )
331 {
332 UINTN Index;
333
334 for (Index = 0; Index < Len; Index++) {
335 if (Index % 16 == 0) {
336 EhciDebugPrint (EHC_DEBUG_BUF, "\n");
337 }
338
339 EhciDebugPrint (EHC_DEBUG_BUF, "%02x ", Buf[Index]);
340 }
341
342 EhciDebugPrint (EHC_DEBUG_BUF, "\n");
343 }
344
345 #endif