]> git.proxmox.com Git - mirror_edk2.git/blame - SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
SourceLevelDebugPkg: Check if PcdUsbEhciPciAddress is set correctly to avoid assertion
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugCommunicationLibUsb / DebugCommunicationLibUsb.c
CommitLineData
18b144ea 1/** @file\r
2 Debug Port Library implementation based on usb debug port.\r
3\r
83283ef1 4 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
18b144ea 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Base.h>\r
16#include <IndustryStandard/Pci.h>\r
17#include <IndustryStandard/Usb.h>\r
18#include <Library/IoLib.h>\r
19#include <Library/PciLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/TimerLib.h>\r
22#include <Library/DebugCommunicationLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/BaseLib.h>\r
e2104834 25#include <Library/DebugLib.h>\r
18b144ea 26\r
27#define SETUP_PID 0x2D\r
28#define INPUT_PID 0x69\r
29#define OUTPUT_PID 0xE1\r
30#define ERROR_PID 0x55\r
31#define DATA0_PID 0xC3\r
32#define DATA1_PID 0x4B\r
33#define DATA2_PID 0x87\r
34#define MDATA_PID 0x0F\r
35#define ACK_PID 0xD2\r
36#define NAK_PID 0x5A\r
37#define STALL_PID 0x1E\r
38#define NYET_PID 0x96\r
39\r
40#define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A\r
41#define USB_DEBUG_PORT_MAX_PACKET_SIZE 0x08\r
42\r
43#define USB_DEBUG_PORT_IN_USE BIT10\r
44#define USB_DEBUG_PORT_ENABLE BIT28\r
45#define USB_DEBUG_PORT_OWNER BIT30\r
46\r
47#define USB_PORT_LINE_STATUS_LS 0x400\r
48#define USB_PORT_LINE_STATUS_MASK 0xC00\r
49\r
50//\r
51// Usb debug device descriptor, which is defined at\r
52// USB2 Debug Device Specification.\r
53//\r
54typedef struct _USB_DEBUG_PORT_DESCRIPTOR {\r
55 UINT8 Length;\r
56 UINT8 DescriptorType;\r
57 UINT8 DebugInEndpoint;\r
58 UINT8 DebugOutEndpoint;\r
59}USB_DEBUG_PORT_DESCRIPTOR;\r
60\r
61USB_DEVICE_REQUEST mGetDebugDescriptor = {\r
62 0x80,\r
63 USB_REQ_GET_DESCRIPTOR,\r
64 (UINT16)(0x0A << 8),\r
65 0x0000,\r
66 sizeof(USB_DEBUG_PORT_DESCRIPTOR)\r
67 };\r
68\r
69USB_DEVICE_REQUEST mSetDebugFeature = {\r
70 0x0,\r
71 USB_REQ_SET_FEATURE,\r
72 (UINT16)(0x06),\r
73 0x0000,\r
74 0x0\r
75 };\r
76\r
77USB_DEVICE_REQUEST mSetDebugAddress = {\r
78 0x0,\r
79 USB_REQ_SET_ADDRESS,\r
80 (UINT16)(0x7F),\r
81 0x0000,\r
82 0x0\r
83 };\r
84\r
85//\r
86// Usb debug port register file, which is defined at\r
87// EHCI Specification.\r
88//\r
89typedef struct _USB_DEBUG_PORT_REGISTER {\r
90 UINT32 ControlStatus;\r
91 UINT8 TokenPid;\r
92 UINT8 SendPid;\r
93 UINT8 ReceivedPid;\r
94 UINT8 Reserved1;\r
95 UINT8 DataBuffer[8];\r
96 UINT8 UsbEndPoint;\r
97 UINT8 UsbAddress;\r
98 UINT8 Reserved2;\r
99 UINT8 Reserved3;\r
100}USB_DEBUG_PORT_REGISTER;\r
101\r
102#pragma pack(1)\r
103//\r
104// The internal data structure of DEBUG_PORT_HANDLE, which stores some\r
105// important datum which are used across various phases.\r
106//\r
107typedef struct _USB_DEBUG_PORT_HANDLE{\r
108 //\r
109 // The usb debug port memory BAR number in EHCI configuration space.\r
110 //\r
111 UINT8 DebugPortBarNumber;\r
e2104834 112 BOOLEAN Initialized;\r
18b144ea 113 //\r
114 // The offset of usb debug port registers in EHCI memory range.\r
115 //\r
116 UINT16 DebugPortOffset;\r
117 //\r
118 // The usb debug port memory BAR address.\r
119 //\r
120 UINTN UsbDebugPortMemoryBase;\r
121 //\r
122 // The EHCI memory BAR address.\r
123 //\r
124 UINTN EhciMemoryBase;\r
125 //\r
126 // The Bulk In endpoint toggle bit.\r
127 //\r
128 UINT8 BulkInToggle;\r
129 //\r
130 // The Bulk Out endpoint toggle bit.\r
131 //\r
132 UINT8 BulkOutToggle;\r
133 //\r
134 // The available data length in the following data buffer.\r
135 //\r
136 UINT8 DataCount;\r
137 //\r
138 // The data buffer. Maximum length is 8 bytes.\r
139 //\r
140 UINT8 Data[8];\r
141} USB_DEBUG_PORT_HANDLE;\r
142#pragma pack()\r
143\r
144//\r
145// The global variable which can be used after memory is ready.\r
146//\r
147USB_DEBUG_PORT_HANDLE mUsbDebugPortHandle;\r
148\r
149/**\r
150 Calculate the usb debug port bar address.\r
151\r
152 @param DebugPortOffset Get usb debug port offset in the usb debug port memory space.\r
153 @param DebugPortBarNumbar Get the bar number at which usb debug port is located.\r
154\r
155 @retval RETURN_UNSUPPORTED The usb host controller does not supported usb debug port capability.\r
156 @retval RETURN_SUCCESS Get bar and offset successfully.\r
157\r
158**/\r
159RETURN_STATUS\r
160EFIAPI\r
161CalculateUsbDebugPortBar (\r
162 OUT UINT16 *DebugPortOffset,\r
163 OUT UINT8 *DebugPortBarNumbar\r
164 )\r
165{\r
166 UINT16 PciStatus;\r
f98c2685 167 UINT16 VendorId;\r
168 UINT16 DeviceId;\r
169 UINT8 ProgInterface;\r
170 UINT8 SubClassCode;\r
171 UINT8 BaseCode;\r
18b144ea 172 UINT8 CapabilityPtr;\r
173 UINT8 CapabilityId;\r
174\r
f98c2685 175 VendorId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET);\r
176 DeviceId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET);\r
177 \r
178 if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {\r
179 return RETURN_UNSUPPORTED;\r
180 }\r
181\r
182 ProgInterface = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET);\r
183 SubClassCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);\r
184 BaseCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);\r
185 \r
186 if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {\r
187 return RETURN_UNSUPPORTED;\r
188 }\r
189\r
18b144ea 190 //\r
191 // Enable Ehci Host Controller MMIO Space.\r
192 //\r
193 PciStatus = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET);\r
194\r
195 if ((PciStatus & EFI_PCI_STATUS_CAPABILITY) == 0) {\r
196 //\r
197 // The Pci Device Doesn't Support Capability Pointer.\r
198 //\r
199 return RETURN_UNSUPPORTED;\r
200 }\r
201\r
202 //\r
203 // Get Pointer To Capability List\r
204 //\r
205 CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET);\r
206\r
207 //\r
208 // Find Capability ID 0xA, Which Is For Debug Port\r
209 //\r
210 while (CapabilityPtr != 0) {\r
211 CapabilityId = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr);\r
212 if (CapabilityId == PCI_CAPABILITY_ID_DEBUG_PORT) {\r
213 break;\r
214 }\r
215 CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 1);\r
216 }\r
217\r
218 //\r
219 // No Debug Port Capability Found\r
220 //\r
221 if (CapabilityPtr == 0) {\r
222 return RETURN_UNSUPPORTED;\r
223 }\r
224\r
225 //\r
226 // Get The Base Address Of Debug Port Register In Debug Port Capability Register\r
227 //\r
228 *DebugPortOffset = (UINT16)(PciRead16(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) & 0x1FFF);\r
229 *DebugPortBarNumbar = (UINT8)((PciRead16(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) >> 13) - 1);\r
230\r
231 return RETURN_SUCCESS;\r
232}\r
233\r
234/**\r
235 Do a usb IN transaction by usb debug port.\r
236\r
237 @param DebugPortRegister Pointer to the base address of usb debug port register interface.\r
238 @param Buffer Pointer to the buffer receiving data.\r
239 @param Length Number of bytes of the received data.\r
240 @param Token The token PID for each USB transaction.\r
241 @param Addr The usb device address for usb transaction.\r
242 @param Ep The endpoint for usb transaction.\r
243 @param DataToggle The toggle bit used at usb transaction.\r
244\r
245 @retval RETURN_SUCCESS The IN transaction is executed successfully.\r
246 @retval RETURN_INVALID_PARAMETER The parameters passed in are invalid.\r
247 @retval RETURN_DEVICE_ERROR The IN transaction comes across error.\r
248\r
249**/\r
250RETURN_STATUS\r
251EFIAPI\r
252UsbDebugPortIn (\r
253 IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,\r
254 IN OUT UINT8 *Buffer,\r
255 OUT UINT8 *Length,\r
256 IN UINT8 Token,\r
257 IN UINT8 Addr,\r
258 IN UINT8 Ep,\r
259 IN UINT8 DataToggle\r
260 )\r
261{\r
262 UINTN Index;\r
263\r
264 if (Length == NULL) {\r
265 return RETURN_INVALID_PARAMETER;\r
266 }\r
267 *Length = 0;\r
268\r
269 DebugPortRegister->TokenPid = Token;\r
270 if (DataToggle != 0) {\r
271 DebugPortRegister->SendPid = DATA1_PID;\r
272 } else {\r
273 DebugPortRegister->SendPid = DATA0_PID;\r
274 }\r
275\r
276 DebugPortRegister->UsbAddress = (UINT8)(Addr & 0x7F);\r
277 DebugPortRegister->UsbEndPoint = (UINT8)(Ep & 0xF);\r
278\r
279 //\r
280 // Clearing W/R bit to indicate it's a READ operation\r
281 //\r
282 MmioAnd32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~BIT4);\r
283\r
284 //\r
285 // Setting GO bit as well as clearing DONE bit\r
286 //\r
287 MmioOr32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5);\r
288\r
289 //\r
290 // Wait for completing the request\r
291 //\r
292 while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0);\r
293\r
294 //\r
295 // Check if the request is executed successfully or not.\r
296 //\r
297 if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {\r
298 return RETURN_DEVICE_ERROR;\r
299 }\r
300\r
301 //\r
302 // Make sure the received data are not beyond the allowable maximum length - 8 byte\r
303 //\r
304 if (((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {\r
305 return RETURN_DEVICE_ERROR;\r
306 }\r
307\r
308 *Length = (UINT8)(MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & 0xF);\r
ec99fa8e 309 if (*Length > 8) {\r
310 return RETURN_DEVICE_ERROR;\r
311 }\r
312\r
18b144ea 313 for (Index = 0; Index < *Length; Index++) {\r
314 Buffer[Index] = DebugPortRegister->DataBuffer[Index];\r
315 }\r
316 return RETURN_SUCCESS;\r
317}\r
318\r
319/**\r
320 Do a usb SETUP/OUT transaction by usb debug port.\r
321\r
322 @param DebugPortRegister Pointer to the base address of usb debug port register interface.\r
323 @param Buffer Pointer to the buffer receiving data.\r
324 @param Length Number of bytes of the received data.\r
325 @param Token The token PID for each USB transaction.\r
326 @param Addr The usb device address for usb transaction.\r
327 @param Ep The endpoint for usb transaction.\r
328 @param DataToggle The toggle bit used at usb transaction.\r
329\r
330 @retval RETURN_SUCCESS The IN transaction is executed successfully.\r
331 @retval RETURN_INVALID_PARAMETER The parameters passed in are invalid.\r
332 @retval RETURN_DEVICE_ERROR The IN transaction comes across error.\r
333\r
334**/\r
335RETURN_STATUS\r
336EFIAPI\r
337UsbDebugPortOut (\r
338 IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,\r
339 IN UINT8 *Buffer,\r
340 IN UINT8 Length,\r
341 IN UINT8 Token,\r
342 IN UINT8 Addr,\r
343 IN UINT8 Ep,\r
344 IN UINT8 DataToggle\r
345 )\r
346{\r
347 UINT8 Index;\r
348\r
349 if (Length > 8) {\r
350 return RETURN_INVALID_PARAMETER;\r
351 }\r
352\r
353 DebugPortRegister->TokenPid = Token;\r
354 if (DataToggle != 0) {\r
355 DebugPortRegister->SendPid = DATA1_PID;\r
356 } else {\r
357 DebugPortRegister->SendPid = DATA0_PID;\r
358 }\r
359 DebugPortRegister->UsbAddress = (UINT8)(Addr & 0x7F);\r
360 DebugPortRegister->UsbEndPoint = (UINT8)(Ep & 0xF);\r
361\r
362 //\r
363 // Fill in the data length and corresponding data.\r
364 //\r
365 MmioAnd32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~0xF);\r
366 MmioOr32((UINTN)&DebugPortRegister->ControlStatus, Length & 0xF);\r
367 for (Index = 0; Index < Length; Index++) {\r
368 DebugPortRegister->DataBuffer[Index] = Buffer[Index];\r
369 }\r
370\r
371 //\r
372 // Setting W/R bit to indicate it's a WRITE operation\r
373 //\r
374 MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT4);\r
375 //\r
376 // Setting GO bit as well as clearing DONE bit\r
377 //\r
378 MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT5);\r
379\r
380 //\r
381 // Wait for completing the request\r
382 //\r
383 while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & BIT16) == 0);\r
384\r
385 //\r
386 // Check if the request is executed successfully or not.\r
387 //\r
388 if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {\r
389 return RETURN_DEVICE_ERROR;\r
390 }\r
391\r
392 //\r
393 // Make sure the sent data are not beyond the allowable maximum length - 8 byte\r
394 //\r
395 if (((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {\r
396 return RETURN_DEVICE_ERROR;\r
397 }\r
398\r
399 return RETURN_SUCCESS;\r
400}\r
401\r
402/**\r
403 Do a usb control transfer by usb debug port.\r
404\r
405 @param DebugPortRegister Pointer to the base address of usb debug port register interface.\r
406 @param SetupPacket The token PID for each USB transaction.\r
407 @param Addr The usb device address for usb transaction.\r
408 @param Ep The endpoint for usb transaction.\r
409 @param Data Pointer to the buffer receiving data.\r
410 @param DataLength Number of bytes of the received data.\r
411\r
412 @retval RETURN_SUCCESS The IN transaction is executed successfully.\r
413 @retval RETURN_INVALID_PARAMETER The parameters passed in are invalid.\r
414 @retval RETURN_DEVICE_ERROR The IN transaction comes across error.\r
415\r
416**/\r
417RETURN_STATUS\r
418EFIAPI\r
419UsbDebugPortControlTransfer (\r
420 IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,\r
421 IN USB_DEVICE_REQUEST *SetupPacket,\r
422 IN UINT8 Addr,\r
423 IN UINT8 Ep,\r
424 OUT UINT8 *Data,\r
425 IN OUT UINT8 *DataLength\r
426 )\r
427{\r
428 RETURN_STATUS Status;\r
429 UINT8 Temp;\r
83283ef1 430 UINT8 ReturnStatus[8];\r
18b144ea 431\r
432 //\r
433 // Setup Phase\r
434 //\r
435 Status = UsbDebugPortOut(DebugPortRegister, (UINT8 *)SetupPacket, (UINT8)sizeof(USB_DEVICE_REQUEST), SETUP_PID, Addr, Ep, 0);\r
436 if (RETURN_ERROR(Status)) {\r
437 return Status;\r
438 }\r
439\r
440 //\r
441 // Data Phase\r
442 //\r
83283ef1 443 if (DataLength != 0) {\r
18b144ea 444 if ((SetupPacket->RequestType & BIT7) != 0) {\r
445 //\r
446 // Get Data From Device\r
447 //\r
448 Status = UsbDebugPortIn(DebugPortRegister, Data, DataLength, INPUT_PID, Addr, Ep, 1);\r
449 if (RETURN_ERROR(Status)) {\r
450 return Status;\r
451 }\r
452 } else {\r
453 //\r
454 // Send Data To Device\r
455 //\r
456 Status = UsbDebugPortOut(DebugPortRegister, Data, *DataLength, OUTPUT_PID, Addr, Ep, 1);\r
457 if (RETURN_ERROR(Status)) {\r
458 return Status;\r
459 }\r
460 }\r
461 }\r
462\r
463 //\r
464 // Status Phase\r
465 //\r
466 if ((SetupPacket->RequestType & BIT7) != 0) {\r
467 //\r
468 // For READ operation, Data Toggle in Status Phase Should be 1.\r
469 //\r
470 Status = UsbDebugPortOut(DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1);\r
471 } else {\r
472 //\r
473 // For WRITE operation, Data Toggle in Status Phase Should be 1.\r
474 //\r
83283ef1 475 Status = UsbDebugPortIn(DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);\r
18b144ea 476 }\r
477\r
478 return Status;\r
479}\r
480\r
481/**\r
482 Check if it needs to re-initialize usb debug port hardware.\r
483\r
484 During different phases switch, such as SEC to PEI or PEI to DXE or DXE to SMM, we should check\r
485 whether the usb debug port hardware configuration is changed. Such case can be triggerred by\r
486 Pci bus resource allocation and so on.\r
487\r
488 @param Handle Debug port handle.\r
489\r
490 @retval TRUE The usb debug port hardware configuration is changed.\r
491 @retval FALSE The usb debug port hardware configuration is not changed.\r
492\r
493**/\r
494BOOLEAN\r
495EFIAPI\r
496NeedReinitializeHardware(\r
497 IN USB_DEBUG_PORT_HANDLE *Handle\r
498 )\r
499{\r
500 UINT16 PciCmd;\r
501 UINTN UsbDebugPortMemoryBase;\r
502 UINTN EhciMemoryBase;\r
503 BOOLEAN Status;\r
504 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;\r
505\r
506 Status = FALSE;\r
507\r
508 EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);\r
509 if (EhciMemoryBase != Handle->EhciMemoryBase) {\r
510 Handle->EhciMemoryBase = EhciMemoryBase;\r
511 Status = TRUE;\r
512 }\r
513\r
514 UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle->DebugPortBarNumber * 4);\r
515 if (UsbDebugPortMemoryBase != Handle->UsbDebugPortMemoryBase) {\r
516 Handle->UsbDebugPortMemoryBase = UsbDebugPortMemoryBase;\r
517 Status = TRUE;\r
518 }\r
519\r
520 //\r
521 // Enable Ehci Memory Space Access\r
522 //\r
523 PciCmd = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);\r
524 if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) {\r
525 Status = TRUE;\r
526 }\r
527\r
528 //\r
529 // Check if the debug port is enabled and owned by myself.\r
530 //\r
531 UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);\r
532 if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) &\r
533 (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) == 0) {\r
534 Status = TRUE;\r
535 }\r
536 return Status;\r
537}\r
538\r
539/**\r
540 Initialize usb debug port hardware.\r
541\r
542 1. reset ehci host controller.\r
543 2. set right port to debug port.\r
544 3. find a usb debug device is attached by getting debug device descriptor.\r
545 4. set address for the usb debug device.\r
546 5. configure the usb debug device to debug mode.\r
547\r
548 @param Handle Debug port handle.\r
549\r
550 @retval TRUE The usb debug port hardware configuration is changed.\r
551 @retval FALSE The usb debug port hardware configuration is not changed.\r
552\r
553**/\r
554RETURN_STATUS\r
555EFIAPI\r
556InitializeUsbDebugHardware (\r
557 IN USB_DEBUG_PORT_HANDLE *Handle\r
558)\r
559{\r
560 RETURN_STATUS Status;\r
561 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;\r
562 USB_DEBUG_PORT_DESCRIPTOR UsbDebugPortDescriptor;\r
563 UINT16 PciCmd;\r
564 UINT32 *PortStatus;\r
565 UINT32 *UsbCmd;\r
566 UINT32 *UsbStatus;\r
567 UINT32 *UsbHCSParam;\r
568 UINT8 DebugPortNumber;\r
569 UINT8 Length;\r
570\r
571 UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);\r
572 PciCmd = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);\r
573 UsbHCSParam = (UINT32 *)(Handle->EhciMemoryBase + 0x04);\r
574 UsbCmd = (UINT32 *)(Handle->EhciMemoryBase + 0x20);\r
575 UsbStatus = (UINT32 *)(Handle->EhciMemoryBase + 0x24);\r
576\r
577 //\r
578 // initialize the data toggle used by bulk in/out endpoint.\r
579 //\r
580 Handle->BulkInToggle = 0;\r
581 Handle->BulkOutToggle = 0;\r
582\r
583 //\r
584 // Enable Ehci Memory Space Access\r
585 //\r
586 if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) {\r
587 PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER;\r
588 PciWrite16(PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);\r
589 }\r
590\r
591 //\r
592 // If the host controller is not halted, then halt it.\r
593 //\r
594 if ((MmioRead32((UINTN)UsbStatus) & BIT12) == 0) {\r
595 MmioAnd32((UINTN)UsbCmd, (UINT32)~BIT0);\r
596 while ((MmioRead32((UINTN)UsbStatus) & BIT12) == 0);\r
597 }\r
598 //\r
599 // reset the host controller.\r
600 //\r
601 MmioOr32((UINTN)UsbCmd, BIT1);\r
602 //\r
603 // ensure that the host controller is reset.\r
604 //\r
605 while (MmioRead32((UINTN)UsbCmd) & BIT1);\r
606\r
607 //\r
608 // Start the host controller if it's not running\r
609 //\r
610 if (MmioRead32((UINTN)UsbStatus) & BIT12) {\r
611 MmioOr32((UINTN)UsbCmd, BIT0);\r
612 // ensure that the host controller is started (HALTED bit must be cleared)\r
613 while (MmioRead32((UINTN)UsbStatus) & BIT12);\r
614 }\r
615\r
616 //\r
617 // First get the ownership of port 0.\r
618 //\r
619 MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_OWNER);\r
620\r
621 MicroSecondDelay (200000);\r
622\r
623 //\r
624 // Find out which port is used as debug port.\r
625 //\r
626 DebugPortNumber = (UINT8)((MmioRead32((UINTN)UsbHCSParam) & 0x00F00000) >> 20);\r
627 //\r
628 // Should find a non low-speed device is connected\r
629 //\r
630 PortStatus = (UINT32 *)(Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4);\r
631 if (!(MmioRead32((UINTN)PortStatus) & BIT0) || ((MmioRead32((UINTN)PortStatus) & USB_PORT_LINE_STATUS_MASK) == USB_PORT_LINE_STATUS_LS)) {\r
632 return RETURN_NOT_FOUND;\r
633 }\r
634\r
635 //\r
636 // Reset the debug port\r
637 //\r
638 MmioOr32((UINTN)PortStatus, BIT8);\r
639 MicroSecondDelay (200000);\r
640 MmioAnd32((UINTN)PortStatus, (UINT32)~BIT8);\r
641 while (MmioRead32((UINTN)PortStatus) & BIT8);\r
642\r
643 //\r
644 // The port enabled bit should be set by HW.\r
645 //\r
646 if ((MmioRead32((UINTN)PortStatus) & BIT2) == 0) {\r
647 return RETURN_DEVICE_ERROR;\r
648 }\r
649\r
650 //\r
651 // Enable Usb Debug Port Capability\r
652 //\r
653 MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE);\r
654\r
655 //\r
656 // Start to communicate with Usb Debug Device to see if the attached device is usb debug device or not.\r
657 //\r
658 Length = (UINT8)sizeof (USB_DEBUG_PORT_DESCRIPTOR);\r
659\r
660 //\r
661 // It's not a dedicated usb debug device, should use address 0 to get debug descriptor.\r
662 //\r
663 Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mGetDebugDescriptor, 0x0, 0x0, (UINT8*)&UsbDebugPortDescriptor, &Length);\r
664 if (RETURN_ERROR(Status)) {\r
665 //\r
666 // The device is not a usb debug device.\r
667 //\r
668 return Status;\r
669 }\r
ec99fa8e 670\r
671 if (Length != sizeof(USB_DEBUG_PORT_DESCRIPTOR)) {\r
672 return RETURN_DEVICE_ERROR;\r
673 }\r
674\r
18b144ea 675 //\r
676 // set usb debug device address as 0x7F.\r
677 //\r
83283ef1 678 Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mSetDebugAddress, 0x0, 0x0, NULL, NULL);\r
18b144ea 679 if (RETURN_ERROR(Status)) {\r
680 //\r
681 // The device can not work well.\r
682 //\r
683 return Status;\r
684 }\r
685\r
686 //\r
687 // enable the usb debug feature.\r
688 //\r
689 Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mSetDebugFeature, 0x7F, 0x0, NULL, NULL);\r
690\r
691 return Status;\r
692}\r
693\r
694/**\r
695 Read data from debug device and save the datas in buffer.\r
696\r
697 Reads NumberOfBytes data bytes from a debug device into the buffer\r
698 specified by Buffer. The number of bytes actually read is returned.\r
699 If the return value is less than NumberOfBytes, then the rest operation failed.\r
700 If NumberOfBytes is zero, then return 0.\r
701\r
702 @param Handle Debug port handle.\r
703 @param Buffer Pointer to the data buffer to store the data read from the debug device.\r
704 @param NumberOfBytes Number of bytes which will be read.\r
705 @param Timeout Timeout value for reading from debug device. It unit is Microsecond.\r
706\r
707 @retval 0 Read data failed, no data is to be read.\r
708 @retval >0 Actual number of bytes read from debug device.\r
709\r
710**/\r
711UINTN\r
712EFIAPI\r
713DebugPortReadBuffer (\r
714 IN DEBUG_PORT_HANDLE Handle,\r
715 IN UINT8 *Buffer,\r
716 IN UINTN NumberOfBytes,\r
717 IN UINTN Timeout\r
718 )\r
719{\r
720 USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;\r
721 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;\r
722 RETURN_STATUS Status;\r
723 UINT8 Received;\r
724 UINTN Total;\r
725 UINTN Remaining;\r
726 UINT8 Index;\r
727 UINT8 Length;\r
728\r
729 if (NumberOfBytes == 0 || Buffer == NULL) {\r
730 return 0;\r
731 }\r
732\r
733 Received = 0;\r
734 Total = 0;\r
735 Remaining = 0;\r
736\r
737 //\r
738 // If Handle is NULL, it means memory is ready for use.\r
739 // Use global variable to store handle value.\r
740 //\r
741 if (Handle == NULL) {\r
742 UsbDebugPortHandle = &mUsbDebugPortHandle;\r
743 } else {\r
744 UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;\r
745 }\r
746\r
e2104834 747 //\r
748 // Check if debug port is ready\r
749 //\r
750 if (!UsbDebugPortHandle->Initialized) {\r
751 return 0;\r
752 }\r
753\r
18b144ea 754 if (NeedReinitializeHardware(UsbDebugPortHandle)) {\r
755 Status = InitializeUsbDebugHardware (UsbDebugPortHandle);\r
756 if (RETURN_ERROR(Status)) {\r
757 return 0;\r
758 }\r
759 }\r
760\r
761 UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);\r
762\r
763 //\r
764 // First read data from buffer, then read debug port hw to get received data.\r
765 //\r
766 if (UsbDebugPortHandle->DataCount > 0) {\r
767 if (NumberOfBytes <= UsbDebugPortHandle->DataCount) {\r
768 Total = NumberOfBytes;\r
769 } else {\r
770 Total = UsbDebugPortHandle->DataCount;\r
771 }\r
772\r
773 for (Index = 0; Index < Total; Index++) {\r
774 Buffer[Index] = UsbDebugPortHandle->Data[Index];\r
775 }\r
776\r
777 for (Index = 0; Index < UsbDebugPortHandle->DataCount - Total; Index++) {\r
778 if (Total + Index >= 8) {\r
779 return 0;\r
780 }\r
781 UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Total + Index];\r
782 }\r
783 UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - (UINT8)Total);\r
784 }\r
785\r
786 //\r
787 // If Timeout is equal to 0, then it means it should always wait until all datum required are received.\r
788 //\r
789 if (Timeout == 0) {\r
790 Timeout = 0xFFFFFFFF;\r
791 }\r
792\r
793 //\r
794 // Read remaining data by executing one or more usb debug transfer transactions at usb debug port hw.\r
795 //\r
796 while ((Total < NumberOfBytes) && (Timeout != 0)) {\r
797 Remaining = NumberOfBytes - Total;\r
798 if (Remaining >= USB_DEBUG_PORT_MAX_PACKET_SIZE) {\r
799 Status = UsbDebugPortIn(UsbDebugPortRegister, Buffer + Total, &Received, INPUT_PID, 0x7f, 0x82, UsbDebugPortHandle->BulkInToggle);\r
800\r
801 if (RETURN_ERROR(Status)) {\r
802 return Total;\r
803 }\r
804 } else {\r
805 Status = UsbDebugPortIn(UsbDebugPortRegister, &UsbDebugPortHandle->Data[0], &Received, INPUT_PID, 0x7f, 0x82, UsbDebugPortHandle->BulkInToggle);\r
806\r
807 if (RETURN_ERROR(Status)) {\r
808 return Total;\r
809 }\r
810\r
811 UsbDebugPortHandle->DataCount = Received;\r
812\r
813 if (Remaining <= Received) {\r
814 Length = (UINT8)Remaining;\r
815 } else {\r
816 Length = (UINT8)Received;\r
817 }\r
818\r
819 //\r
820 // Copy required data from the data buffer to user buffer.\r
821 //\r
822 for (Index = 0; Index < Length; Index++) {\r
823 (Buffer + Total)[Index] = UsbDebugPortHandle->Data[Index];\r
824 UsbDebugPortHandle->DataCount--;\r
825 }\r
826\r
827 //\r
828 // reorder the data buffer to make available data arranged from the beginning of the data buffer.\r
829 //\r
830 for (Index = 0; Index < Received - Length; Index++) {\r
831 if (Length + Index >= 8) {\r
832 return 0;\r
833 }\r
834 UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Length + Index];\r
835 }\r
836 //\r
837 // fixup the real received length in Buffer.\r
838 //\r
839 Received = Length;\r
840 }\r
841 UsbDebugPortHandle->BulkInToggle ^= 1;\r
842\r
843 Total += Received;\r
844 Timeout -= 100;\r
845 }\r
846\r
847 return Total;\r
848}\r
849\r
850/**\r
851 Write data from buffer to debug device.\r
852\r
853 Writes NumberOfBytes data bytes from Buffer to the debug device.\r
854 The number of bytes actually written to the debug device is returned.\r
855 If the return value is less than NumberOfBytes, then the write operation failed.\r
856 If NumberOfBytes is zero, then return 0.\r
857\r
858 @param Handle Debug port handle.\r
859 @param Buffer Pointer to the data buffer to be written.\r
860 @param NumberOfBytes Number of bytes to written to the debug device.\r
861\r
862 @retval 0 NumberOfBytes is 0.\r
863 @retval >0 The number of bytes written to the debug device.\r
864 If this value is less than NumberOfBytes, then the read operation failed.\r
865\r
866**/\r
867UINTN\r
868EFIAPI\r
869DebugPortWriteBuffer (\r
870 IN DEBUG_PORT_HANDLE Handle,\r
871 IN UINT8 *Buffer,\r
872 IN UINTN NumberOfBytes\r
873 )\r
874{\r
875 USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;\r
876 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;\r
877 RETURN_STATUS Status;\r
878 UINT8 Sent;\r
879 UINTN Total;\r
880 UINT8 ReceivedPid;\r
881\r
882 if (NumberOfBytes == 0 || Buffer == NULL) {\r
883 return 0;\r
884 }\r
885\r
886 Sent = 0;\r
887 Total = 0;\r
888\r
889 //\r
890 // If Handle is NULL, it means memory is ready for use.\r
891 // Use global variable to store handle value.\r
892 //\r
893 if (Handle == NULL) {\r
894 UsbDebugPortHandle = &mUsbDebugPortHandle;\r
895 } else {\r
896 UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;\r
897 }\r
898\r
e2104834 899 //\r
900 // Check if debug port is ready\r
901 //\r
902 if (!UsbDebugPortHandle->Initialized) {\r
903 return 0;\r
904 }\r
905\r
18b144ea 906 if (NeedReinitializeHardware(UsbDebugPortHandle)) {\r
907 Status = InitializeUsbDebugHardware (UsbDebugPortHandle);\r
908 if (RETURN_ERROR(Status)) {\r
909 return 0;\r
910 }\r
911 }\r
912\r
913 UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);\r
914\r
915 while ((Total < NumberOfBytes)) {\r
916 if (NumberOfBytes - Total > USB_DEBUG_PORT_MAX_PACKET_SIZE) {\r
917 Sent = USB_DEBUG_PORT_MAX_PACKET_SIZE;\r
918 } else {\r
919 Sent = (UINT8)(NumberOfBytes - Total);\r
920 }\r
921\r
922 Status = UsbDebugPortOut(UsbDebugPortRegister, Buffer + Total, Sent, OUTPUT_PID, 0x7F, 0x01, UsbDebugPortHandle->BulkOutToggle);\r
923\r
924 if (RETURN_ERROR(Status)) {\r
925 return Total;\r
926 }\r
927\r
928 ReceivedPid = (MmioRead8((UINTN)&UsbDebugPortRegister->ReceivedPid));\r
929 //\r
930 // If received a NAK_PID on write transaction, it means the usb debug device is busy and can not handle this transaction.\r
931 // should send the packet again.\r
932 //\r
933 if (ReceivedPid == NAK_PID) {\r
934 Sent = 0;\r
935 } else {\r
936 UsbDebugPortHandle->BulkOutToggle ^= 1;\r
937 }\r
938 Total += Sent;\r
939 }\r
940 return Total;\r
941}\r
942\r
943/**\r
944 Polls a debug device to see if there is any data waiting to be read.\r
945\r
946 Polls a debug device to see if there is any data waiting to be read.\r
947 If there is data waiting to be read from the debug device, then TRUE is returned.\r
948 If there is no data waiting to be read from the debug device, then FALSE is returned.\r
949\r
950 @param Handle Debug port handle.\r
951\r
952 @retval TRUE Data is waiting to be read from the debug device.\r
953 @retval FALSE There is no data waiting to be read from the serial device.\r
954\r
955**/\r
956BOOLEAN\r
957EFIAPI\r
958DebugPortPollBuffer (\r
959 IN DEBUG_PORT_HANDLE Handle\r
960 )\r
961{\r
962 USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;\r
963 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;\r
964 UINT8 Length;\r
965 UINT8 Index;\r
966 RETURN_STATUS Status;\r
967\r
968 //\r
969 // If Handle is NULL, it means memory is ready for use.\r
970 // Use global variable to store handle value.\r
971 //\r
972 if (Handle == NULL) {\r
973 UsbDebugPortHandle = &mUsbDebugPortHandle;\r
974 } else {\r
975 UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;\r
976 }\r
977\r
e2104834 978 //\r
979 // Check if debug port is ready\r
980 //\r
981 if (!UsbDebugPortHandle->Initialized) {\r
982 return 0;\r
983 }\r
984\r
18b144ea 985 if (NeedReinitializeHardware(UsbDebugPortHandle)) {\r
986 Status = InitializeUsbDebugHardware(UsbDebugPortHandle);\r
987 if (RETURN_ERROR(Status)) {\r
988 return FALSE;\r
989 }\r
990 }\r
991\r
992 //\r
993 // If the data buffer is not empty, then return TRUE directly.\r
994 // else initialize a usb read transaction and read data to the data buffer.\r
995 //\r
996 if (UsbDebugPortHandle->DataCount != 0) {\r
997 return TRUE;\r
998 }\r
999\r
1000 UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);\r
1001\r
1002 UsbDebugPortRegister->TokenPid = INPUT_PID;\r
1003 if (UsbDebugPortHandle->BulkInToggle == 0) {\r
1004 UsbDebugPortRegister->SendPid = DATA0_PID;\r
1005 } else {\r
1006 UsbDebugPortRegister->SendPid = DATA1_PID;\r
1007 }\r
1008 UsbDebugPortRegister->UsbAddress = 0x7F;\r
1009 UsbDebugPortRegister->UsbEndPoint = 0x82 & 0x0F;\r
1010\r
1011 //\r
1012 // Clearing W/R bit to indicate it's a READ operation\r
1013 //\r
1014 MmioAnd32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)~BIT4);\r
1015 //\r
1016 // Setting GO bit as well as clearing DONE bit\r
1017 //\r
1018 MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5);\r
1019\r
1020 //\r
1021 // Wait for completing the request\r
1022 //\r
1023 while ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0);\r
1024\r
1025 if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) {\r
1026 return FALSE;\r
1027 }\r
1028\r
1029 Length = (UINT8)(MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF);\r
1030\r
1031 if (Length > 8) {\r
1032 return FALSE;\r
1033 }\r
1034\r
1035 UsbDebugPortHandle->BulkInToggle ^= 1;\r
1036\r
1037 if (Length == 0) {\r
1038 return FALSE;\r
1039 }\r
1040\r
1041 for (Index = 0; Index < Length; Index++) {\r
1042 UsbDebugPortHandle->Data[Index] = UsbDebugPortRegister->DataBuffer[Index];\r
1043 }\r
1044 UsbDebugPortHandle->DataCount = Length;\r
1045\r
1046 return TRUE;\r
1047}\r
1048\r
1049/**\r
1050 Initialize the debug port.\r
1051\r
1052 If Function is not NULL, Debug Communication Libary will call this function\r
1053 by passing in the Context to be the first parameter. If needed, Debug Communication\r
1054 Library will create one debug port handle to be the second argument passing in\r
1055 calling the Function, otherwise it will pass NULL to be the second argument of\r
1056 Function.\r
1057\r
1058 If Function is NULL, and Context is not NULL, the Debug Communication Library could\r
1059 a) Return the same handle as passed in (as Context parameter).\r
1060 b) Ignore the input Context parameter and create new hanlde to be returned.\r
1061\r
1062 If parameter Function is NULL and Context is NULL, Debug Communication Library could\r
1063 created a new handle if needed and return it, otherwise it will return NULL.\r
1064\r
1065 @param[in] Context Context needed by callback function; it was optional.\r
1066 @param[in] Function Continue function called by Debug Communication library;\r
1067 it was optional.\r
1068\r
1069 @return The debug port handle created by Debug Communication Library if Function\r
1070 is not NULL.\r
1071\r
1072**/\r
1073DEBUG_PORT_HANDLE\r
1074EFIAPI\r
1075DebugPortInitialize (\r
1076 IN VOID *Context,\r
1077 IN DEBUG_PORT_CONTINUE Function\r
1078 )\r
1079{\r
1080 RETURN_STATUS Status;\r
1081 USB_DEBUG_PORT_HANDLE Handle;\r
1082\r
1083 if (Function == NULL && Context != NULL) {\r
1084 return (DEBUG_PORT_HANDLE *) Context;\r
1085 }\r
1086\r
1087 ZeroMem(&Handle, sizeof (USB_DEBUG_PORT_HANDLE));\r
1088\r
1089 Status = CalculateUsbDebugPortBar(&Handle.DebugPortOffset, &Handle.DebugPortBarNumber);\r
1090 if (RETURN_ERROR (Status)) {\r
f98c2685 1091 DEBUG ((EFI_D_ERROR, "USB Debug Port: the pci device pointed by PcdUsbEhciPciAddress is not EHCI host controller or does not support debug port capability!\n"));\r
e2104834 1092 goto Exit;\r
18b144ea 1093 }\r
1094\r
1095 Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);\r
1096\r
1097 if (Handle.EhciMemoryBase == 0) {\r
1098 //\r
1099 // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero\r
1100 //\r
1101 PciWrite32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, PcdGet32(PcdUsbEhciMemorySpaceBase));\r
1102 Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);\r
1103 }\r
1104\r
1105 Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);\r
1106\r
1107 if (Handle.UsbDebugPortMemoryBase == 0) {\r
1108 //\r
1109 // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero\r
1110 //\r
1111 PciWrite32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4, PcdGet32(PcdUsbDebugPortMemorySpaceBase));\r
1112 Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);\r
1113 }\r
1114\r
1115 Status = InitializeUsbDebugHardware (&Handle);\r
1116 if (RETURN_ERROR(Status)) {\r
e2104834 1117 DEBUG ((EFI_D_ERROR, "USB Debug Port: Initialization failed, please check if USB debug cable is plugged into EHCI debug port correctly!\n"));\r
1118 goto Exit;\r
18b144ea 1119 }\r
1120\r
e2104834 1121 //\r
1122 // Set debug port initialized successfully flag\r
1123 //\r
1124 Handle.Initialized = TRUE;\r
1125\r
1126Exit:\r
1127\r
18b144ea 1128 if (Function != NULL) {\r
1129 Function (Context, &Handle);\r
1130 } else {\r
1131 CopyMem(&mUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE));\r
1132 }\r
1133\r
1134 return (DEBUG_PORT_HANDLE)(UINTN)&mUsbDebugPortHandle;\r
1135}\r
1136\r