Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 156854
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
r80721 r99404 19 19 #include <Library/DebugLib.h> 20 20 21 #define SETUP_PID 22 #define INPUT_PID 23 #define OUTPUT_PID 24 #define ERROR_PID 25 #define DATA0_PID 26 #define DATA1_PID 27 #define DATA2_PID 28 #define MDATA_PID 29 #define ACK_PID 30 #define NAK_PID 31 #define STALL_PID 32 #define NYET_PID 33 34 #define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A35 #define USB_DEBUG_PORT_MAX_PACKET_SIZE 0x0836 37 #define USB_DEBUG_PORT_IN_USE 38 #define USB_DEBUG_PORT_ENABLE 39 #define USB_DEBUG_PORT_OWNER 40 41 #define USB_PORT_LINE_STATUS_LS 0x40042 #define USB_PORT_LINE_STATUS_MASK 0xC0021 #define SETUP_PID 0x2D 22 #define INPUT_PID 0x69 23 #define OUTPUT_PID 0xE1 24 #define ERROR_PID 0x55 25 #define DATA0_PID 0xC3 26 #define DATA1_PID 0x4B 27 #define DATA2_PID 0x87 28 #define MDATA_PID 0x0F 29 #define ACK_PID 0xD2 30 #define NAK_PID 0x5A 31 #define STALL_PID 0x1E 32 #define NYET_PID 0x96 33 34 #define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A 35 #define USB_DEBUG_PORT_MAX_PACKET_SIZE 0x08 36 37 #define USB_DEBUG_PORT_IN_USE BIT10 38 #define USB_DEBUG_PORT_ENABLE BIT28 39 #define USB_DEBUG_PORT_OWNER BIT30 40 41 #define USB_PORT_LINE_STATUS_LS 0x400 42 #define USB_PORT_LINE_STATUS_MASK 0xC00 43 43 44 44 // … … 47 47 // 48 48 typedef struct _USB_DEBUG_PORT_DESCRIPTOR { 49 UINT8 50 UINT8 51 UINT8 52 UINT8 53 } USB_DEBUG_PORT_DESCRIPTOR;54 55 USB_DEVICE_REQUEST mDebugCommunicationLibUsbGetDebugDescriptor = {49 UINT8 Length; 50 UINT8 DescriptorType; 51 UINT8 DebugInEndpoint; 52 UINT8 DebugOutEndpoint; 53 } USB_DEBUG_PORT_DESCRIPTOR; 54 55 USB_DEVICE_REQUEST mDebugCommunicationLibUsbGetDebugDescriptor = { 56 56 0x80, 57 57 USB_REQ_GET_DESCRIPTOR, 58 58 (UINT16)(0x0A << 8), 59 59 0x0000, 60 sizeof (USB_DEBUG_PORT_DESCRIPTOR)61 62 63 USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = {60 sizeof (USB_DEBUG_PORT_DESCRIPTOR) 61 }; 62 63 USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = { 64 64 0x0, 65 65 USB_REQ_SET_FEATURE, … … 67 67 0x0000, 68 68 0x0 69 70 71 USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = {69 }; 70 71 USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = { 72 72 0x0, 73 73 USB_REQ_SET_ADDRESS, … … 75 75 0x0000, 76 76 0x0 77 77 }; 78 78 79 79 // … … 82 82 // 83 83 typedef struct _USB_DEBUG_PORT_REGISTER { 84 UINT32 85 UINT8 86 UINT8 87 UINT8 88 UINT8 89 UINT8 90 UINT8 91 UINT8 92 UINT8 93 UINT8 94 } USB_DEBUG_PORT_REGISTER;84 UINT32 ControlStatus; 85 UINT8 TokenPid; 86 UINT8 SendPid; 87 UINT8 ReceivedPid; 88 UINT8 Reserved1; 89 UINT8 DataBuffer[8]; 90 UINT8 UsbEndPoint; 91 UINT8 UsbAddress; 92 UINT8 Reserved2; 93 UINT8 Reserved3; 94 } USB_DEBUG_PORT_REGISTER; 95 95 96 96 // 97 97 // The state machine of usb debug port 98 98 // 99 #define USBDBG_NO_DEV 0// No device present at debug port100 #define USBDBG_NO_DBG_CAB 1// The device attached is not usb debug cable101 #define USBDBG_DBG_CAB 2// The device attached is usb debug cable102 #define USBDBG_INIT_DONE 4// The usb debug cable device is initialized103 #define USBDBG_RESET 8// The system is reset99 #define USBDBG_NO_DEV 0 // No device present at debug port 100 #define USBDBG_NO_DBG_CAB 1 // The device attached is not usb debug cable 101 #define USBDBG_DBG_CAB 2 // The device attached is usb debug cable 102 #define USBDBG_INIT_DONE 4 // The usb debug cable device is initialized 103 #define USBDBG_RESET 8 // The system is reset 104 104 105 105 #pragma pack(1) … … 108 108 // important datum which are used across various phases. 109 109 // 110 typedef struct _USB_DEBUG_PORT_HANDLE {110 typedef struct _USB_DEBUG_PORT_HANDLE { 111 111 // 112 112 // The usb debug port memory BAR number in EHCI configuration space. 113 113 // 114 UINT8 115 UINT8 114 UINT8 DebugPortBarNumber; 115 UINT8 Initialized; 116 116 // 117 117 // The offset of usb debug port registers in EHCI memory range. 118 118 // 119 UINT16 119 UINT16 DebugPortOffset; 120 120 // 121 121 // The usb debug port memory BAR address. 122 122 // 123 UINT32 123 UINT32 UsbDebugPortMemoryBase; 124 124 // 125 125 // The EHCI memory BAR address. 126 126 // 127 UINT32 127 UINT32 EhciMemoryBase; 128 128 // 129 129 // The usb debug device In endpoint. 130 130 // 131 UINT8 131 UINT8 InEndpoint; 132 132 // 133 133 // The usb debug device Out endpoint. 134 134 // 135 UINT8 135 UINT8 OutEndpoint; 136 136 // 137 137 // The Bulk In endpoint toggle bit. 138 138 // 139 UINT8 139 UINT8 BulkInToggle; 140 140 // 141 141 // The Bulk Out endpoint toggle bit. 142 142 // 143 UINT8 143 UINT8 BulkOutToggle; 144 144 // 145 145 // The available data length in the following data buffer. 146 146 // 147 UINT8 147 UINT8 DataCount; 148 148 // 149 149 // The data buffer. Maximum length is 8 bytes. 150 150 // 151 UINT8 151 UINT8 Data[8]; 152 152 } USB_DEBUG_PORT_HANDLE; 153 153 #pragma pack() … … 156 156 // The global variable which can be used after memory is ready. 157 157 // 158 USB_DEBUG_PORT_HANDLE 158 USB_DEBUG_PORT_HANDLE mDebugCommunicationLibUsbDebugPortHandle; 159 159 160 160 /** … … 171 171 EFIAPI 172 172 CalculateUsbDebugPortBar ( 173 OUT UINT16 174 OUT UINT8 175 )173 OUT UINT16 *DebugPortOffset, 174 OUT UINT8 *DebugPortBarNumbar 175 ) 176 176 { 177 UINT16 178 UINT16 179 UINT16 180 UINT8 181 UINT8 182 UINT8 183 UINT8 184 UINT8 185 186 VendorId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET);187 DeviceId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET);177 UINT16 PciStatus; 178 UINT16 VendorId; 179 UINT16 DeviceId; 180 UINT8 ProgInterface; 181 UINT8 SubClassCode; 182 UINT8 BaseCode; 183 UINT8 CapabilityPtr; 184 UINT8 CapabilityId; 185 186 VendorId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET); 187 DeviceId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET); 188 188 189 189 if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) { … … 191 191 } 192 192 193 ProgInterface = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET);194 SubClassCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);195 BaseCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);193 ProgInterface = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET); 194 SubClassCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1); 195 BaseCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2); 196 196 197 197 if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) { … … 202 202 // Enable Ehci Host Controller MMIO Space. 203 203 // 204 PciStatus = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET);204 PciStatus = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET); 205 205 206 206 if ((PciStatus & EFI_PCI_STATUS_CAPABILITY) == 0) { … … 214 214 // Get Pointer To Capability List 215 215 // 216 CapabilityPtr = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET);216 CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET); 217 217 218 218 // … … 220 220 // 221 221 while (CapabilityPtr != 0) { 222 CapabilityId = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr);222 CapabilityId = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr); 223 223 if (CapabilityId == PCI_CAPABILITY_ID_DEBUG_PORT) { 224 224 break; 225 225 } 226 CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 1); 226 227 CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 1); 227 228 } 228 229 … … 237 238 // Get The Base Address Of Debug Port Register In Debug Port Capability Register 238 239 // 239 *DebugPortOffset = (UINT16)(PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) & 0x1FFF);240 *DebugPortBarNumbar = (UINT8)((PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) >> 13) - 1);240 *DebugPortOffset = (UINT16)(PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 2) & 0x1FFF); 241 *DebugPortBarNumbar = (UINT8)((PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 2) >> 13) - 1); 241 242 242 243 return RETURN_SUCCESS; … … 262 263 EFIAPI 263 264 UsbDebugPortIn ( 264 IN USB_DEBUG_PORT_REGISTER 265 IN OUT UINT8 266 OUT UINT8*Length,267 IN UINT8 268 IN UINT8 269 IN UINT8 270 IN UINT8 265 IN USB_DEBUG_PORT_REGISTER *DebugPortRegister, 266 IN OUT UINT8 *Buffer, 267 OUT UINT8 *Length, 268 IN UINT8 Token, 269 IN UINT8 Addr, 270 IN UINT8 Ep, 271 IN UINT8 DataToggle 271 272 ) 272 273 { 273 UINTN 274 UINTN Index; 274 275 275 276 if (Length == NULL) { 276 277 return RETURN_INVALID_PARAMETER; 277 278 } 279 278 280 *Length = 0; 279 281 … … 291 293 // Clearing W/R bit to indicate it's a READ operation 292 294 // 293 MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~BIT4);295 MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32) ~BIT4); 294 296 295 297 // 296 298 // Setting GO bit as well as clearing DONE bit 297 299 // 298 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5);300 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5); 299 301 300 302 // 301 303 // Wait for completing the request 302 304 // 303 while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) { 304 if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 305 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) { 305 while ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) { 306 if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 307 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 308 { 306 309 return RETURN_DEVICE_ERROR; 307 310 } … … 311 314 // Clearing DONE bit by writing 1 312 315 // 313 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);316 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16); 314 317 315 318 // 316 319 // Check if the request is executed successfully or not. 317 320 // 318 if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {321 if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) { 319 322 return RETURN_DEVICE_ERROR; 320 323 } … … 323 326 // Make sure the received data are not beyond the allowable maximum length - 8 byte 324 327 // 325 if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {328 if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) { 326 329 return RETURN_DEVICE_ERROR; 327 330 } 328 331 329 *Length = (UINT8)(MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & 0xF);332 *Length = (UINT8)(MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & 0xF); 330 333 if (*Length > 8) { 331 334 return RETURN_DEVICE_ERROR; … … 335 338 Buffer[Index] = DebugPortRegister->DataBuffer[Index]; 336 339 } 340 337 341 return RETURN_SUCCESS; 338 342 } … … 357 361 EFIAPI 358 362 UsbDebugPortOut ( 359 IN USB_DEBUG_PORT_REGISTER 360 IN UINT8 361 IN UINT8 362 IN UINT8 363 IN UINT8 364 IN UINT8 365 IN UINT8 363 IN USB_DEBUG_PORT_REGISTER *DebugPortRegister, 364 IN UINT8 *Buffer, 365 IN UINT8 Length, 366 IN UINT8 Token, 367 IN UINT8 Addr, 368 IN UINT8 Ep, 369 IN UINT8 DataToggle 366 370 ) 367 371 { 368 UINT8 372 UINT8 Index; 369 373 370 374 if (Length > 8) { … … 378 382 DebugPortRegister->SendPid = DATA0_PID; 379 383 } 384 380 385 DebugPortRegister->UsbAddress = (UINT8)(Addr & 0x7F); 381 386 DebugPortRegister->UsbEndPoint = (UINT8)(Ep & 0xF); … … 384 389 // Fill in the data length and corresponding data. 385 390 // 386 MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~0xF);387 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, Length & 0xF);391 MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32) ~0xF); 392 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, Length & 0xF); 388 393 for (Index = 0; Index < Length; Index++) { 389 394 DebugPortRegister->DataBuffer[Index] = Buffer[Index]; … … 393 398 // Setting W/R bit to indicate it's a WRITE operation 394 399 // 395 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT4);400 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT4); 396 401 // 397 402 // Setting GO bit as well as clearing DONE bit 398 403 // 399 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT5);404 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT5); 400 405 401 406 // 402 407 // Wait for completing the request 403 408 // 404 while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & BIT16) == 0) { 405 if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 406 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) { 409 while ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & BIT16) == 0) { 410 if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 411 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 412 { 407 413 return RETURN_DEVICE_ERROR; 408 414 } … … 412 418 // Clearing DONE bit by writing 1 413 419 // 414 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);420 MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16); 415 421 416 422 // 417 423 // Check if the request is executed successfully or not. 418 424 // 419 if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {425 if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) { 420 426 return RETURN_DEVICE_ERROR; 421 427 } … … 424 430 // Make sure the sent data are not beyond the allowable maximum length - 8 byte 425 431 // 426 if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {432 if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) { 427 433 return RETURN_DEVICE_ERROR; 428 434 } … … 449 455 EFIAPI 450 456 UsbDebugPortControlTransfer ( 451 IN USB_DEBUG_PORT_REGISTER 452 IN USB_DEVICE_REQUEST 453 IN UINT8 454 IN UINT8 455 OUT UINT8*Data,456 IN OUT UINT8 457 IN USB_DEBUG_PORT_REGISTER *DebugPortRegister, 458 IN USB_DEVICE_REQUEST *SetupPacket, 459 IN UINT8 Addr, 460 IN UINT8 Ep, 461 OUT UINT8 *Data, 462 IN OUT UINT8 *DataLength 457 463 ) 458 464 { 459 RETURN_STATUS 460 UINT8 461 UINT8 465 RETURN_STATUS Status; 466 UINT8 Temp; 467 UINT8 ReturnStatus[8]; 462 468 463 469 // 464 470 // Setup Phase 465 471 // 466 Status = UsbDebugPortOut (DebugPortRegister, (UINT8 *)SetupPacket, (UINT8)sizeof(USB_DEVICE_REQUEST), SETUP_PID, Addr, Ep, 0);467 if (RETURN_ERROR (Status)) {472 Status = UsbDebugPortOut (DebugPortRegister, (UINT8 *)SetupPacket, (UINT8)sizeof (USB_DEVICE_REQUEST), SETUP_PID, Addr, Ep, 0); 473 if (RETURN_ERROR (Status)) { 468 474 return Status; 469 475 } … … 477 483 // Get Data From Device 478 484 // 479 Status = UsbDebugPortIn (DebugPortRegister, Data, DataLength, INPUT_PID, Addr, Ep, 1);480 if (RETURN_ERROR (Status)) {485 Status = UsbDebugPortIn (DebugPortRegister, Data, DataLength, INPUT_PID, Addr, Ep, 1); 486 if (RETURN_ERROR (Status)) { 481 487 return Status; 482 488 } … … 485 491 // Send Data To Device 486 492 // 487 Status = UsbDebugPortOut (DebugPortRegister, Data, *DataLength, OUTPUT_PID, Addr, Ep, 1);488 if (RETURN_ERROR (Status)) {493 Status = UsbDebugPortOut (DebugPortRegister, Data, *DataLength, OUTPUT_PID, Addr, Ep, 1); 494 if (RETURN_ERROR (Status)) { 489 495 return Status; 490 496 } … … 499 505 // For READ operation, Data Toggle in Status Phase Should be 1. 500 506 // 501 Status = UsbDebugPortOut (DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1);507 Status = UsbDebugPortOut (DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1); 502 508 } else { 503 509 // 504 510 // For WRITE operation, Data Toggle in Status Phase Should be 1. 505 511 // 506 Status = UsbDebugPortIn (DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);512 Status = UsbDebugPortIn (DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1); 507 513 } 508 514 … … 525 531 BOOLEAN 526 532 EFIAPI 527 NeedReinitializeHardware (528 IN USB_DEBUG_PORT_HANDLE *Handle533 NeedReinitializeHardware ( 534 IN USB_DEBUG_PORT_HANDLE *Handle 529 535 ) 530 536 { 531 UINT16 PciCmd;532 UINT32 UsbDebugPortMemoryBase;533 UINT32 EhciMemoryBase;534 BOOLEAN Status;535 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;537 UINT16 PciCmd; 538 UINT32 UsbDebugPortMemoryBase; 539 UINT32 EhciMemoryBase; 540 BOOLEAN Status; 541 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister; 536 542 537 543 Status = FALSE; 538 544 539 EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);545 EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET); 540 546 if (EhciMemoryBase != Handle->EhciMemoryBase) { 541 547 Handle->EhciMemoryBase = EhciMemoryBase; 542 Status = TRUE;543 } 544 545 UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle->DebugPortBarNumber * 4);548 Status = TRUE; 549 } 550 551 UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle->DebugPortBarNumber * 4); 546 552 if (UsbDebugPortMemoryBase != Handle->UsbDebugPortMemoryBase) { 547 553 Handle->UsbDebugPortMemoryBase = UsbDebugPortMemoryBase; 548 Status = TRUE;554 Status = TRUE; 549 555 } 550 556 … … 552 558 // Enable Ehci Memory Space Access 553 559 // 554 PciCmd = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);560 PciCmd = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET); 555 561 if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) { 556 562 PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER; 557 PciWrite16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);563 PciWrite16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd); 558 564 Status = TRUE; 559 565 } … … 563 569 // 564 570 UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset); 565 if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) 566 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) { 571 if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) 572 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) 573 { 567 574 Status = TRUE; 568 575 } … … 573 580 Status = TRUE; 574 581 } 582 575 583 return Status; 576 584 } … … 594 602 EFIAPI 595 603 InitializeUsbDebugHardware ( 596 IN USB_DEBUG_PORT_HANDLE *Handle597 )604 IN USB_DEBUG_PORT_HANDLE *Handle 605 ) 598 606 { 599 RETURN_STATUS Status;600 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;601 USB_DEBUG_PORT_DESCRIPTOR UsbDebugPortDescriptor;602 UINT32 *PortStatus;603 UINT32 *UsbCmd;604 UINT32 *UsbStatus;605 UINT32 *UsbHCSParam;606 UINT8 DebugPortNumber;607 UINT8 Length;607 RETURN_STATUS Status; 608 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister; 609 USB_DEBUG_PORT_DESCRIPTOR UsbDebugPortDescriptor; 610 UINT32 *PortStatus; 611 UINT32 *UsbCmd; 612 UINT32 *UsbStatus; 613 UINT32 *UsbHCSParam; 614 UINT8 DebugPortNumber; 615 UINT8 Length; 608 616 609 617 UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset); 610 UsbHCSParam = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x04);611 UsbCmd = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x20);612 UsbStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x24);618 UsbHCSParam = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x04); 619 UsbCmd = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x20); 620 UsbStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x24); 613 621 614 622 // 615 623 // Check if the debug port is enabled and owned by myself. 616 624 // 617 if (((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) 618 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) || (Handle->Initialized == USBDBG_RESET)) { 625 if (((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) 626 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) || (Handle->Initialized == USBDBG_RESET)) 627 { 619 628 DEBUG (( 620 EFI_D_INFO,629 DEBUG_INFO, 621 630 "UsbDbg: Need to reset the host controller. ControlStatus = %08x\n", 622 MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)631 MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) 623 632 )); 624 633 // 625 634 // If the host controller is halted, then reset and restart it. 626 635 // 627 if ((MmioRead32 ((UINTN)UsbStatus) & BIT12) != 0) {628 DEBUG (( EFI_D_INFO, "UsbDbg: Reset the host controller.\n"));636 if ((MmioRead32 ((UINTN)UsbStatus) & BIT12) != 0) { 637 DEBUG ((DEBUG_INFO, "UsbDbg: Reset the host controller.\n")); 629 638 // 630 639 // reset the host controller. 631 640 // 632 MmioOr32 ((UINTN)UsbCmd, BIT1);641 MmioOr32 ((UINTN)UsbCmd, BIT1); 633 642 // 634 643 // ensure that the host controller is reset. 635 644 // 636 while ((MmioRead32((UINTN)UsbCmd) & BIT1) != 0); 637 638 MmioOr32((UINTN)UsbCmd, BIT0); 645 while ((MmioRead32 ((UINTN)UsbCmd) & BIT1) != 0) { 646 } 647 648 MmioOr32 ((UINTN)UsbCmd, BIT0); 639 649 // ensure that the host controller is started (HALTED bit must be cleared) 640 while ((MmioRead32((UINTN)UsbStatus) & BIT12) != 0); 650 while ((MmioRead32 ((UINTN)UsbStatus) & BIT12) != 0) { 651 } 641 652 } 642 653 … … 644 655 // First get the ownership of port 0. 645 656 // 646 MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE);657 MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE); 647 658 648 659 MicroSecondDelay (200000); 649 660 } 661 650 662 // 651 663 // Find out which port is used as debug port. 652 664 // 653 DebugPortNumber = (UINT8)((MmioRead32 ((UINTN)UsbHCSParam) & 0x00F00000) >> 20);665 DebugPortNumber = (UINT8)((MmioRead32 ((UINTN)UsbHCSParam) & 0x00F00000) >> 20); 654 666 // 655 667 // Should find a device is connected at debug port 656 668 // 657 669 PortStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4); 658 if (!(MmioRead32 ((UINTN)PortStatus) & BIT0)) {670 if (!(MmioRead32 ((UINTN)PortStatus) & BIT0)) { 659 671 Handle->Initialized = USBDBG_NO_DEV; 660 672 return RETURN_NOT_FOUND; 661 673 } 662 674 663 if (Handle->Initialized != USBDBG_INIT_DONE || 664 (MmioRead32 ((UINTN) &UsbDebugPortRegister->ControlStatus) & USB_DEBUG_PORT_ENABLE) == 0) { 665 DEBUG ((EFI_D_INFO, "UsbDbg: Reset the debug port.\n")); 675 if ((Handle->Initialized != USBDBG_INIT_DONE) || 676 ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & USB_DEBUG_PORT_ENABLE) == 0)) 677 { 678 DEBUG ((DEBUG_INFO, "UsbDbg: Reset the debug port.\n")); 666 679 // 667 680 // Reset the debug port 668 681 // 669 MmioOr32 ((UINTN)PortStatus, BIT8);682 MmioOr32 ((UINTN)PortStatus, BIT8); 670 683 MicroSecondDelay (500000); 671 MmioAnd32((UINTN)PortStatus, (UINT32)~BIT8); 672 while (MmioRead32((UINTN)PortStatus) & BIT8); 684 MmioAnd32 ((UINTN)PortStatus, (UINT32) ~BIT8); 685 while (MmioRead32 ((UINTN)PortStatus) & BIT8) { 686 } 673 687 674 688 // 675 689 // The port enabled bit should be set by HW. 676 690 // 677 if ((MmioRead32 ((UINTN)PortStatus) & BIT2) == 0) {691 if ((MmioRead32 ((UINTN)PortStatus) & BIT2) == 0) { 678 692 Handle->Initialized = USBDBG_NO_DBG_CAB; 679 693 return RETURN_DEVICE_ERROR; … … 683 697 // Enable Usb Debug Port Capability 684 698 // 685 MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE);699 MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE); 686 700 687 701 // … … 695 709 // 696 710 Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugAddress, 0x0, 0x0, NULL, NULL); 697 if (RETURN_ERROR (Status)) {711 if (RETURN_ERROR (Status)) { 698 712 // 699 713 // The device can not work well. … … 711 725 // Get debug descriptor. 712 726 // 713 Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbGetDebugDescriptor, 0x7F, 0x0, (UINT8 *)&UsbDebugPortDescriptor, &Length);714 if (RETURN_ERROR (Status)) {727 Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbGetDebugDescriptor, 0x7F, 0x0, (UINT8 *)&UsbDebugPortDescriptor, &Length); 728 if (RETURN_ERROR (Status)) { 715 729 // 716 730 // The device is not a usb debug device. … … 720 734 } 721 735 722 if (Length != sizeof (USB_DEBUG_PORT_DESCRIPTOR)) {736 if (Length != sizeof (USB_DEBUG_PORT_DESCRIPTOR)) { 723 737 Handle->Initialized = USBDBG_NO_DBG_CAB; 724 738 return RETURN_DEVICE_ERROR; … … 735 749 // 736 750 Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugFeature, 0x7F, 0x0, NULL, NULL); 737 if (RETURN_ERROR (Status)) {751 if (RETURN_ERROR (Status)) { 738 752 // 739 753 // The device can not work well. … … 755 769 756 770 /** 757 Read data from debug device and save the data s inbuffer.771 Read data from debug device and save the data in a buffer. 758 772 759 773 Reads NumberOfBytes data bytes from a debug device into the buffer … … 774 788 EFIAPI 775 789 DebugPortReadBuffer ( 776 IN DEBUG_PORT_HANDLE 777 IN UINT8 778 IN UINTN 779 IN UINTN 790 IN DEBUG_PORT_HANDLE Handle, 791 IN UINT8 *Buffer, 792 IN UINTN NumberOfBytes, 793 IN UINTN Timeout 780 794 ) 781 795 { 782 USB_DEBUG_PORT_HANDLE 783 RETURN_STATUS 784 UINT8 785 786 if ( NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {796 USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle; 797 RETURN_STATUS Status; 798 UINT8 Index; 799 800 if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) { 787 801 return 0; 788 802 } … … 798 812 } 799 813 800 if (NeedReinitializeHardware (UsbDebugPortHandle)) {814 if (NeedReinitializeHardware (UsbDebugPortHandle)) { 801 815 Status = InitializeUsbDebugHardware (UsbDebugPortHandle); 802 if (RETURN_ERROR (Status)) {816 if (RETURN_ERROR (Status)) { 803 817 return 0; 804 818 } … … 816 830 return 0; 817 831 } 832 818 833 UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Index + 1]; 819 834 } 835 820 836 UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1); 821 837 return 1; … … 843 859 EFIAPI 844 860 DebugPortWriteBuffer ( 845 IN DEBUG_PORT_HANDLE 846 IN UINT8 847 IN UINTN 861 IN DEBUG_PORT_HANDLE Handle, 862 IN UINT8 *Buffer, 863 IN UINTN NumberOfBytes 848 864 ) 849 865 { 850 USB_DEBUG_PORT_HANDLE 851 USB_DEBUG_PORT_REGISTER 852 RETURN_STATUS 853 UINT8 854 UINTN 855 UINT8 856 857 if ( NumberOfBytes == 0 || Buffer == NULL) {866 USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle; 867 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister; 868 RETURN_STATUS Status; 869 UINT8 Sent; 870 UINTN Total; 871 UINT8 ReceivedPid; 872 873 if ((NumberOfBytes == 0) || (Buffer == NULL)) { 858 874 return 0; 859 875 } … … 872 888 } 873 889 874 if (NeedReinitializeHardware (UsbDebugPortHandle)) {890 if (NeedReinitializeHardware (UsbDebugPortHandle)) { 875 891 Status = InitializeUsbDebugHardware (UsbDebugPortHandle); 876 if (RETURN_ERROR (Status)) {892 if (RETURN_ERROR (Status)) { 877 893 return 0; 878 894 } … … 888 904 } 889 905 890 Status = UsbDebugPortOut (UsbDebugPortRegister, Buffer + Total, Sent, OUTPUT_PID, 0x7F, UsbDebugPortHandle->OutEndpoint, UsbDebugPortHandle->BulkOutToggle);891 892 if (RETURN_ERROR (Status)) {906 Status = UsbDebugPortOut (UsbDebugPortRegister, Buffer + Total, Sent, OUTPUT_PID, 0x7F, UsbDebugPortHandle->OutEndpoint, UsbDebugPortHandle->BulkOutToggle); 907 908 if (RETURN_ERROR (Status)) { 893 909 return Total; 894 910 } 895 911 896 ReceivedPid = (MmioRead8 ((UINTN)&UsbDebugPortRegister->ReceivedPid));912 ReceivedPid = (MmioRead8 ((UINTN)&UsbDebugPortRegister->ReceivedPid)); 897 913 // 898 914 // If received a NAK_PID on write transaction, it means the usb debug device is busy and can not handle this transaction. … … 904 920 UsbDebugPortHandle->BulkOutToggle ^= 1; 905 921 } 922 906 923 Total += Sent; 907 924 } 925 908 926 return Total; 909 927 } … … 925 943 EFIAPI 926 944 DebugPortPollBuffer ( 927 IN DEBUG_PORT_HANDLE 945 IN DEBUG_PORT_HANDLE Handle 928 946 ) 929 947 { 930 USB_DEBUG_PORT_HANDLE 931 USB_DEBUG_PORT_REGISTER 932 UINT8 933 UINT8 934 RETURN_STATUS 948 USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle; 949 USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister; 950 UINT8 Length; 951 UINT8 Index; 952 RETURN_STATUS Status; 935 953 936 954 // … … 944 962 } 945 963 946 if (NeedReinitializeHardware (UsbDebugPortHandle)) {947 Status = InitializeUsbDebugHardware (UsbDebugPortHandle);948 if (RETURN_ERROR (Status)) {964 if (NeedReinitializeHardware (UsbDebugPortHandle)) { 965 Status = InitializeUsbDebugHardware (UsbDebugPortHandle); 966 if (RETURN_ERROR (Status)) { 949 967 return FALSE; 950 968 } … … 963 981 UsbDebugPortRegister->TokenPid = INPUT_PID; 964 982 if (UsbDebugPortHandle->BulkInToggle == 0) { 965 UsbDebugPortRegister->SendPid 983 UsbDebugPortRegister->SendPid = DATA0_PID; 966 984 } else { 967 UsbDebugPortRegister->SendPid = DATA1_PID; 968 } 985 UsbDebugPortRegister->SendPid = DATA1_PID; 986 } 987 969 988 UsbDebugPortRegister->UsbAddress = 0x7F; 970 989 UsbDebugPortRegister->UsbEndPoint = UsbDebugPortHandle->InEndpoint & 0x0F; … … 973 992 // Clearing W/R bit to indicate it's a READ operation 974 993 // 975 MmioAnd32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)~BIT4);994 MmioAnd32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32) ~BIT4); 976 995 // 977 996 // Setting GO bit as well as clearing DONE bit 978 997 // 979 MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5);998 MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5); 980 999 981 1000 // 982 1001 // Wait for completing the request 983 1002 // 984 while ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) { 985 if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 986 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) { 1003 while ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) { 1004 if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 1005 != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) 1006 { 987 1007 return FALSE; 988 1008 } 989 1009 } 990 1010 991 if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) {1011 if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) { 992 1012 return FALSE; 993 1013 } 994 1014 995 Length = (UINT8)(MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF);1015 Length = (UINT8)(MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF); 996 1016 997 1017 if (Length > 8) { … … 1008 1028 UsbDebugPortHandle->Data[Index] = UsbDebugPortRegister->DataBuffer[Index]; 1009 1029 } 1030 1010 1031 UsbDebugPortHandle->DataCount = Length; 1011 1032 … … 1044 1065 ) 1045 1066 { 1046 RETURN_STATUS 1047 USB_DEBUG_PORT_HANDLE 1067 RETURN_STATUS Status; 1068 USB_DEBUG_PORT_HANDLE Handle; 1048 1069 1049 1070 // … … 1052 1073 ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB_DEBUG_PORT_HANDLE)); 1053 1074 1054 if (Function == NULL && Context != NULL) { 1055 return (DEBUG_PORT_HANDLE *) Context; 1056 } 1057 ZeroMem(&Handle, sizeof (USB_DEBUG_PORT_HANDLE)); 1058 1059 Status = CalculateUsbDebugPortBar(&Handle.DebugPortOffset, &Handle.DebugPortBarNumber); 1075 if ((Function == NULL) && (Context != NULL)) { 1076 return (DEBUG_PORT_HANDLE *)Context; 1077 } 1078 1079 ZeroMem (&Handle, sizeof (USB_DEBUG_PORT_HANDLE)); 1080 1081 Status = CalculateUsbDebugPortBar (&Handle.DebugPortOffset, &Handle.DebugPortBarNumber); 1060 1082 if (RETURN_ERROR (Status)) { 1061 DEBUG (( EFI_D_ERROR, "UsbDbg: the pci device pointed by PcdUsbEhciPciAddress is not EHCI host controller or does not support debug port capability!\n"));1083 DEBUG ((DEBUG_ERROR, "UsbDbg: the pci device pointed by PcdUsbEhciPciAddress is not EHCI host controller or does not support debug port capability!\n")); 1062 1084 goto Exit; 1063 1085 } 1064 1086 1065 Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);1087 Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET); 1066 1088 1067 1089 if (Handle.EhciMemoryBase == 0) { … … 1069 1091 // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero 1070 1092 // 1071 PciWrite32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, PcdGet32(PcdUsbEhciMemorySpaceBase));1072 Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);1073 } 1074 1075 Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);1093 PciWrite32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, PcdGet32 (PcdUsbEhciMemorySpaceBase)); 1094 Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET); 1095 } 1096 1097 Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4); 1076 1098 1077 1099 if (Handle.UsbDebugPortMemoryBase == 0) { … … 1079 1101 // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero 1080 1102 // 1081 PciWrite32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4, PcdGet32(PcdUsbDebugPortMemorySpaceBase));1082 Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);1103 PciWrite32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4, PcdGet32 (PcdUsbDebugPortMemorySpaceBase)); 1104 Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4); 1083 1105 } 1084 1106 1085 1107 Handle.Initialized = USBDBG_RESET; 1086 1108 1087 if (NeedReinitializeHardware (&Handle)) {1088 DEBUG (( EFI_D_ERROR, "UsbDbg: Start EHCI debug port initialization!\n"));1109 if (NeedReinitializeHardware (&Handle)) { 1110 DEBUG ((DEBUG_ERROR, "UsbDbg: Start EHCI debug port initialization!\n")); 1089 1111 Status = InitializeUsbDebugHardware (&Handle); 1090 if (RETURN_ERROR (Status)) {1091 DEBUG (( EFI_D_ERROR, "UsbDbg: Failed, please check if USB debug cable is plugged into EHCI debug port correctly!\n"));1112 if (RETURN_ERROR (Status)) { 1113 DEBUG ((DEBUG_ERROR, "UsbDbg: Failed, please check if USB debug cable is plugged into EHCI debug port correctly!\n")); 1092 1114 goto Exit; 1093 1115 } … … 1099 1121 Function (Context, &Handle); 1100 1122 } else { 1101 CopyMem (&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE));1123 CopyMem (&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE)); 1102 1124 } 1103 1125 1104 1126 return (DEBUG_PORT_HANDLE)(UINTN)&mDebugCommunicationLibUsbDebugPortHandle; 1105 1127 } 1106
Note:
See TracChangeset
for help on using the changeset viewer.