VirtualBox

Ignore:
Timestamp:
Apr 14, 2023 3:17:44 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156854
Message:

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c

    r80721 r99404  
    1919#include <Library/DebugLib.h>
    2020
    21 #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
     21#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
    4343
    4444//
     
    4747//
    4848typedef struct _USB_DEBUG_PORT_DESCRIPTOR {
    49   UINT8          Length;
    50   UINT8          DescriptorType;
    51   UINT8          DebugInEndpoint;
    52   UINT8          DebugOutEndpoint;
    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
     55USB_DEVICE_REQUEST  mDebugCommunicationLibUsbGetDebugDescriptor = {
    5656  0x80,
    5757  USB_REQ_GET_DESCRIPTOR,
    5858  (UINT16)(0x0A << 8),
    5959  0x0000,
    60   sizeof(USB_DEBUG_PORT_DESCRIPTOR)
    61   };
    62 
    63 USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = {
     60  sizeof (USB_DEBUG_PORT_DESCRIPTOR)
     61};
     62
     63USB_DEVICE_REQUEST  mDebugCommunicationLibUsbSetDebugFeature = {
    6464  0x0,
    6565  USB_REQ_SET_FEATURE,
     
    6767  0x0000,
    6868  0x0
    69   };
    70 
    71 USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = {
     69};
     70
     71USB_DEVICE_REQUEST  mDebugCommunicationLibUsbSetDebugAddress = {
    7272  0x0,
    7373  USB_REQ_SET_ADDRESS,
     
    7575  0x0000,
    7676  0x0
    77   };
     77};
    7878
    7979//
     
    8282//
    8383typedef struct _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;
     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;
    9595
    9696//
    9797// The state machine of usb debug port
    9898//
    99 #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
     99#define USBDBG_NO_DEV         // No device present at debug port
     100#define USBDBG_NO_DBG_CAB     // The device attached is not usb debug cable
     101#define USBDBG_DBG_CAB        // The device attached is usb debug cable
     102#define USBDBG_INIT_DONE      // The usb debug cable device is initialized
     103#define USBDBG_RESET          // The system is reset
    104104
    105105#pragma pack(1)
     
    108108// important datum which are used across various phases.
    109109//
    110 typedef struct _USB_DEBUG_PORT_HANDLE{
     110typedef struct _USB_DEBUG_PORT_HANDLE {
    111111  //
    112112  // The usb debug port memory BAR number in EHCI configuration space.
    113113  //
    114   UINT8        DebugPortBarNumber;
    115   UINT8        Initialized;
     114  UINT8     DebugPortBarNumber;
     115  UINT8     Initialized;
    116116  //
    117117  // The offset of usb debug port registers in EHCI memory range.
    118118  //
    119   UINT16       DebugPortOffset;
     119  UINT16    DebugPortOffset;
    120120  //
    121121  // The usb debug port memory BAR address.
    122122  //
    123   UINT32       UsbDebugPortMemoryBase;
     123  UINT32    UsbDebugPortMemoryBase;
    124124  //
    125125  // The EHCI memory BAR address.
    126126  //
    127   UINT32       EhciMemoryBase;
     127  UINT32    EhciMemoryBase;
    128128  //
    129129  // The usb debug device In endpoint.
    130130  //
    131   UINT8        InEndpoint;
     131  UINT8     InEndpoint;
    132132  //
    133133  // The usb debug device Out endpoint.
    134134  //
    135   UINT8        OutEndpoint;
     135  UINT8     OutEndpoint;
    136136  //
    137137  // The Bulk In endpoint toggle bit.
    138138  //
    139   UINT8        BulkInToggle;
     139  UINT8     BulkInToggle;
    140140  //
    141141  // The Bulk Out endpoint toggle bit.
    142142  //
    143   UINT8        BulkOutToggle;
     143  UINT8     BulkOutToggle;
    144144  //
    145145  // The available data length in the following data buffer.
    146146  //
    147   UINT8        DataCount;
     147  UINT8     DataCount;
    148148  //
    149149  // The data buffer. Maximum length is 8 bytes.
    150150  //
    151   UINT8        Data[8];
     151  UINT8     Data[8];
    152152} USB_DEBUG_PORT_HANDLE;
    153153#pragma pack()
     
    156156// The global variable which can be used after memory is ready.
    157157//
    158 USB_DEBUG_PORT_HANDLE     mDebugCommunicationLibUsbDebugPortHandle;
     158USB_DEBUG_PORT_HANDLE  mDebugCommunicationLibUsbDebugPortHandle;
    159159
    160160/**
     
    171171EFIAPI
    172172CalculateUsbDebugPortBar (
    173   OUT UINT16     *DebugPortOffset,
    174   OUT UINT8      *DebugPortBarNumbar
    175  )
     173  OUT UINT16  *DebugPortOffset,
     174  OUT UINT8   *DebugPortBarNumbar
     175  )
    176176{
    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);
     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);
    188188
    189189  if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {
     
    191191  }
    192192
    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);
    196196
    197197  if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {
     
    202202  // Enable Ehci Host Controller MMIO Space.
    203203  //
    204   PciStatus = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET);
     204  PciStatus = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET);
    205205
    206206  if ((PciStatus & EFI_PCI_STATUS_CAPABILITY) == 0) {
     
    214214  // Get Pointer To Capability List
    215215  //
    216   CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET);
     216  CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET);
    217217
    218218  //
     
    220220  //
    221221  while (CapabilityPtr != 0) {
    222     CapabilityId = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr);
     222    CapabilityId = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr);
    223223    if (CapabilityId == PCI_CAPABILITY_ID_DEBUG_PORT) {
    224224      break;
    225225    }
    226     CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 1);
     226
     227    CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 1);
    227228  }
    228229
     
    237238  // Get The Base Address Of Debug Port Register In Debug Port Capability Register
    238239  //
    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);
    241242
    242243  return RETURN_SUCCESS;
     
    262263EFIAPI
    263264UsbDebugPortIn (
    264   IN      USB_DEBUG_PORT_REGISTER         *DebugPortRegister,
    265   IN  OUT UINT8                           *Buffer,
    266       OUT UINT8                           *Length,
    267   IN      UINT8                           Token,
    268   IN      UINT8                           Addr,
    269   IN      UINT8                           Ep,
    270   IN      UINT8                           DataToggle
     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
    271272  )
    272273{
    273   UINTN                   Index;
     274  UINTN  Index;
    274275
    275276  if (Length == NULL) {
    276277    return RETURN_INVALID_PARAMETER;
    277278  }
     279
    278280  *Length = 0;
    279281
     
    291293  // Clearing W/R bit to indicate it's a READ operation
    292294  //
    293   MmioAnd32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~BIT4);
     295  MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32) ~BIT4);
    294296
    295297  //
    296298  // Setting GO bit as well as clearing DONE bit
    297299  //
    298   MmioOr32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5);
     300  MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5);
    299301
    300302  //
    301303  // Wait for completing the request
    302304  //
    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    {
    306309      return RETURN_DEVICE_ERROR;
    307310    }
     
    311314  // Clearing DONE bit by writing 1
    312315  //
    313   MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT16);
     316  MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);
    314317
    315318  //
    316319  // Check if the request is executed successfully or not.
    317320  //
    318   if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
     321  if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
    319322    return RETURN_DEVICE_ERROR;
    320323  }
     
    323326  // Make sure the received data are not beyond the allowable maximum length - 8 byte
    324327  //
    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) {
    326329    return RETURN_DEVICE_ERROR;
    327330  }
    328331
    329   *Length = (UINT8)(MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & 0xF);
     332  *Length = (UINT8)(MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & 0xF);
    330333  if (*Length > 8) {
    331334    return RETURN_DEVICE_ERROR;
     
    335338    Buffer[Index] = DebugPortRegister->DataBuffer[Index];
    336339  }
     340
    337341  return RETURN_SUCCESS;
    338342}
     
    357361EFIAPI
    358362UsbDebugPortOut (
    359   IN  USB_DEBUG_PORT_REGISTER         *DebugPortRegister,
    360   IN  UINT8                           *Buffer,
    361   IN  UINT8                           Length,
    362   IN  UINT8                           Token,
    363   IN  UINT8                           Addr,
    364   IN  UINT8                           Ep,
    365   IN  UINT8                           DataToggle
     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
    366370  )
    367371{
    368   UINT8             Index;
     372  UINT8  Index;
    369373
    370374  if (Length > 8) {
     
    378382    DebugPortRegister->SendPid = DATA0_PID;
    379383  }
     384
    380385  DebugPortRegister->UsbAddress  = (UINT8)(Addr & 0x7F);
    381386  DebugPortRegister->UsbEndPoint = (UINT8)(Ep & 0xF);
     
    384389  // Fill in the data length and corresponding data.
    385390  //
    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);
    388393  for (Index = 0; Index < Length; Index++) {
    389394    DebugPortRegister->DataBuffer[Index] = Buffer[Index];
     
    393398  // Setting W/R bit to indicate it's a WRITE operation
    394399  //
    395   MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT4);
     400  MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT4);
    396401  //
    397402  // Setting GO bit as well as clearing DONE bit
    398403  //
    399   MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT5);
     404  MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT5);
    400405
    401406  //
    402407  // Wait for completing the request
    403408  //
    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    {
    407413      return RETURN_DEVICE_ERROR;
    408414    }
     
    412418  // Clearing DONE bit by writing 1
    413419  //
    414   MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT16);
     420  MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);
    415421
    416422  //
    417423  // Check if the request is executed successfully or not.
    418424  //
    419   if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
     425  if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
    420426    return RETURN_DEVICE_ERROR;
    421427  }
     
    424430  // Make sure the sent data are not beyond the allowable maximum length - 8 byte
    425431  //
    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) {
    427433    return RETURN_DEVICE_ERROR;
    428434  }
     
    449455EFIAPI
    450456UsbDebugPortControlTransfer (
    451   IN      USB_DEBUG_PORT_REGISTER         *DebugPortRegister,
    452   IN      USB_DEVICE_REQUEST              *SetupPacket,
    453   IN      UINT8                           Addr,
    454   IN      UINT8                           Ep,
    455       OUT UINT8                           *Data,
    456   IN  OUT UINT8                           *DataLength
     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
    457463  )
    458464{
    459   RETURN_STATUS          Status;
    460   UINT8                  Temp;
    461   UINT8                  ReturnStatus[8];
     465  RETURN_STATUS  Status;
     466  UINT8          Temp;
     467  UINT8          ReturnStatus[8];
    462468
    463469  //
    464470  // Setup Phase
    465471  //
    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)) {
    468474    return Status;
    469475  }
     
    477483      // Get Data From Device
    478484      //
    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)) {
    481487        return Status;
    482488      }
     
    485491      // Send Data To Device
    486492      //
    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)) {
    489495        return Status;
    490496      }
     
    499505    // For READ operation, Data Toggle in Status Phase Should be 1.
    500506    //
    501     Status = UsbDebugPortOut(DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1);
     507    Status = UsbDebugPortOut (DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1);
    502508  } else {
    503509    //
    504510    // For WRITE operation, Data Toggle in Status Phase Should be 1.
    505511    //
    506     Status = UsbDebugPortIn(DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);
     512    Status = UsbDebugPortIn (DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);
    507513  }
    508514
     
    525531BOOLEAN
    526532EFIAPI
    527 NeedReinitializeHardware(
    528   IN USB_DEBUG_PORT_HANDLE *Handle
     533NeedReinitializeHardware (
     534  IN USB_DEBUG_PORT_HANDLE  *Handle
    529535  )
    530536{
    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;
    536542
    537543  Status = FALSE;
    538544
    539   EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
     545  EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
    540546  if (EhciMemoryBase != Handle->EhciMemoryBase) {
    541547    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);
    546552  if (UsbDebugPortMemoryBase != Handle->UsbDebugPortMemoryBase) {
    547553    Handle->UsbDebugPortMemoryBase = UsbDebugPortMemoryBase;
    548     Status = TRUE;
     554    Status                         = TRUE;
    549555  }
    550556
     
    552558  // Enable Ehci Memory Space Access
    553559  //
    554   PciCmd    = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);
     560  PciCmd = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);
    555561  if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) {
    556562    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);
    558564    Status = TRUE;
    559565  }
     
    563569  //
    564570  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  {
    567574    Status = TRUE;
    568575  }
     
    573580    Status = TRUE;
    574581  }
     582
    575583  return Status;
    576584}
     
    594602EFIAPI
    595603InitializeUsbDebugHardware (
    596   IN USB_DEBUG_PORT_HANDLE *Handle
    597 )
     604  IN USB_DEBUG_PORT_HANDLE  *Handle
     605  )
    598606{
    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;
    608616
    609617  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);
    613621
    614622  //
    615623  // Check if the debug port is enabled and owned by myself.
    616624  //
    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  {
    619628    DEBUG ((
    620       EFI_D_INFO,
     629      DEBUG_INFO,
    621630      "UsbDbg: Need to reset the host controller. ControlStatus = %08x\n",
    622       MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus)
     631      MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)
    623632      ));
    624633    //
    625634    // If the host controller is halted, then reset and restart it.
    626635    //
    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"));
    629638      //
    630639      // reset the host controller.
    631640      //
    632       MmioOr32((UINTN)UsbCmd, BIT1);
     641      MmioOr32 ((UINTN)UsbCmd, BIT1);
    633642      //
    634643      // ensure that the host controller is reset.
    635644      //
    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);
    639649      // 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      }
    641652    }
    642653
     
    644655    // First get the ownership of port 0.
    645656    //
    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);
    647658
    648659    MicroSecondDelay (200000);
    649660  }
     661
    650662  //
    651663  // Find out which port is used as debug port.
    652664  //
    653   DebugPortNumber = (UINT8)((MmioRead32((UINTN)UsbHCSParam) & 0x00F00000) >> 20);
     665  DebugPortNumber = (UINT8)((MmioRead32 ((UINTN)UsbHCSParam) & 0x00F00000) >> 20);
    654666  //
    655667  // Should find a device is connected at debug port
    656668  //
    657669  PortStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4);
    658   if (!(MmioRead32((UINTN)PortStatus) & BIT0)) {
     670  if (!(MmioRead32 ((UINTN)PortStatus) & BIT0)) {
    659671    Handle->Initialized = USBDBG_NO_DEV;
    660672    return RETURN_NOT_FOUND;
    661673  }
    662674
    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"));
    666679    //
    667680    // Reset the debug port
    668681    //
    669     MmioOr32((UINTN)PortStatus, BIT8);
     682    MmioOr32 ((UINTN)PortStatus, BIT8);
    670683    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    }
    673687
    674688    //
    675689    // The port enabled bit should be set by HW.
    676690    //
    677     if ((MmioRead32((UINTN)PortStatus) & BIT2) == 0) {
     691    if ((MmioRead32 ((UINTN)PortStatus) & BIT2) == 0) {
    678692      Handle->Initialized = USBDBG_NO_DBG_CAB;
    679693      return RETURN_DEVICE_ERROR;
     
    683697    // Enable Usb Debug Port Capability
    684698    //
    685     MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE);
     699    MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE);
    686700
    687701    //
     
    695709    //
    696710    Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugAddress, 0x0, 0x0, NULL, NULL);
    697     if (RETURN_ERROR(Status)) {
     711    if (RETURN_ERROR (Status)) {
    698712      //
    699713      // The device can not work well.
     
    711725    // Get debug descriptor.
    712726    //
    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)) {
    715729      //
    716730      // The device is not a usb debug device.
     
    720734    }
    721735
    722     if (Length != sizeof(USB_DEBUG_PORT_DESCRIPTOR)) {
     736    if (Length != sizeof (USB_DEBUG_PORT_DESCRIPTOR)) {
    723737      Handle->Initialized = USBDBG_NO_DBG_CAB;
    724738      return RETURN_DEVICE_ERROR;
     
    735749    //
    736750    Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugFeature, 0x7F, 0x0, NULL, NULL);
    737     if (RETURN_ERROR(Status)) {
     751    if (RETURN_ERROR (Status)) {
    738752      //
    739753      // The device can not work well.
     
    755769
    756770/**
    757   Read data from debug device and save the datas in buffer.
     771  Read data from debug device and save the data in a buffer.
    758772
    759773  Reads NumberOfBytes data bytes from a debug device into the buffer
     
    774788EFIAPI
    775789DebugPortReadBuffer (
    776   IN   DEBUG_PORT_HANDLE    Handle,
    777   IN   UINT8                *Buffer,
    778   IN   UINTN                NumberOfBytes,
    779   IN   UINTN                Timeout
     790  IN   DEBUG_PORT_HANDLE  Handle,
     791  IN   UINT8              *Buffer,
     792  IN   UINTN              NumberOfBytes,
     793  IN   UINTN              Timeout
    780794  )
    781795{
    782   USB_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;
    783   RETURN_STATUS             Status;
    784   UINT8                     Index;
    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)) {
    787801    return 0;
    788802  }
     
    798812  }
    799813
    800   if (NeedReinitializeHardware(UsbDebugPortHandle)) {
     814  if (NeedReinitializeHardware (UsbDebugPortHandle)) {
    801815    Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
    802     if (RETURN_ERROR(Status)) {
     816    if (RETURN_ERROR (Status)) {
    803817      return 0;
    804818    }
     
    816830        return 0;
    817831      }
     832
    818833      UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Index + 1];
    819834    }
     835
    820836    UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);
    821837    return 1;
     
    843859EFIAPI
    844860DebugPortWriteBuffer (
    845   IN   DEBUG_PORT_HANDLE    Handle,
    846   IN   UINT8                *Buffer,
    847   IN   UINTN                NumberOfBytes
     861  IN   DEBUG_PORT_HANDLE  Handle,
     862  IN   UINT8              *Buffer,
     863  IN   UINTN              NumberOfBytes
    848864  )
    849865{
    850   USB_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;
    851   USB_DEBUG_PORT_REGISTER   *UsbDebugPortRegister;
    852   RETURN_STATUS             Status;
    853   UINT8                     Sent;
    854   UINTN                     Total;
    855   UINT8                     ReceivedPid;
    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)) {
    858874    return 0;
    859875  }
     
    872888  }
    873889
    874   if (NeedReinitializeHardware(UsbDebugPortHandle)) {
     890  if (NeedReinitializeHardware (UsbDebugPortHandle)) {
    875891    Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
    876     if (RETURN_ERROR(Status)) {
     892    if (RETURN_ERROR (Status)) {
    877893      return 0;
    878894    }
     
    888904    }
    889905
    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)) {
    893909      return Total;
    894910    }
    895911
    896     ReceivedPid = (MmioRead8((UINTN)&UsbDebugPortRegister->ReceivedPid));
     912    ReceivedPid = (MmioRead8 ((UINTN)&UsbDebugPortRegister->ReceivedPid));
    897913    //
    898914    // If received a NAK_PID on write transaction, it means the usb debug device is busy and can not handle this transaction.
     
    904920      UsbDebugPortHandle->BulkOutToggle ^= 1;
    905921    }
     922
    906923    Total += Sent;
    907924  }
     925
    908926  return Total;
    909927}
     
    925943EFIAPI
    926944DebugPortPollBuffer (
    927   IN DEBUG_PORT_HANDLE      Handle
     945  IN DEBUG_PORT_HANDLE  Handle
    928946  )
    929947{
    930   USB_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;
    931   USB_DEBUG_PORT_REGISTER   *UsbDebugPortRegister;
    932   UINT8                     Length;
    933   UINT8                     Index;
    934   RETURN_STATUS             Status;
     948  USB_DEBUG_PORT_HANDLE    *UsbDebugPortHandle;
     949  USB_DEBUG_PORT_REGISTER  *UsbDebugPortRegister;
     950  UINT8                    Length;
     951  UINT8                    Index;
     952  RETURN_STATUS            Status;
    935953
    936954  //
     
    944962  }
    945963
    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)) {
    949967      return FALSE;
    950968    }
     
    963981  UsbDebugPortRegister->TokenPid = INPUT_PID;
    964982  if (UsbDebugPortHandle->BulkInToggle == 0) {
    965     UsbDebugPortRegister->SendPid  = DATA0_PID;
     983    UsbDebugPortRegister->SendPid = DATA0_PID;
    966984  } else {
    967     UsbDebugPortRegister->SendPid  = DATA1_PID;
    968   }
     985    UsbDebugPortRegister->SendPid = DATA1_PID;
     986  }
     987
    969988  UsbDebugPortRegister->UsbAddress  = 0x7F;
    970989  UsbDebugPortRegister->UsbEndPoint = UsbDebugPortHandle->InEndpoint & 0x0F;
     
    973992  // Clearing W/R bit to indicate it's a READ operation
    974993  //
    975   MmioAnd32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)~BIT4);
     994  MmioAnd32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32) ~BIT4);
    976995  //
    977996  // Setting GO bit as well as clearing DONE bit
    978997  //
    979   MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5);
     998  MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5);
    980999
    9811000  //
    9821001  // Wait for completing the request
    9831002  //
    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    {
    9871007      return FALSE;
    9881008    }
    9891009  }
    9901010
    991   if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) {
     1011  if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) {
    9921012    return FALSE;
    9931013  }
    9941014
    995   Length = (UINT8)(MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF);
     1015  Length = (UINT8)(MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF);
    9961016
    9971017  if (Length > 8) {
     
    10081028    UsbDebugPortHandle->Data[Index] = UsbDebugPortRegister->DataBuffer[Index];
    10091029  }
     1030
    10101031  UsbDebugPortHandle->DataCount = Length;
    10111032
     
    10441065  )
    10451066{
    1046   RETURN_STATUS             Status;
    1047   USB_DEBUG_PORT_HANDLE     Handle;
     1067  RETURN_STATUS          Status;
     1068  USB_DEBUG_PORT_HANDLE  Handle;
    10481069
    10491070  //
     
    10521073  ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB_DEBUG_PORT_HANDLE));
    10531074
    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);
    10601082  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"));
    10621084    goto Exit;
    10631085  }
    10641086
    1065   Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
     1087  Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
    10661088
    10671089  if (Handle.EhciMemoryBase == 0) {
     
    10691091    // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero
    10701092    //
    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);
    10761098
    10771099  if (Handle.UsbDebugPortMemoryBase == 0) {
     
    10791101    // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero
    10801102    //
    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);
    10831105  }
    10841106
    10851107  Handle.Initialized = USBDBG_RESET;
    10861108
    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"));
    10891111    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"));
    10921114      goto Exit;
    10931115    }
     
    10991121    Function (Context, &Handle);
    11001122  } else {
    1101     CopyMem(&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE));
     1123    CopyMem (&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE));
    11021124  }
    11031125
    11041126  return (DEBUG_PORT_HANDLE)(UINTN)&mDebugCommunicationLibUsbDebugPortHandle;
    11051127}
    1106 
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette