]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c
1) Add type cast for better coding style.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciIo.c
index 86c9135afd6929b6a1e34afe2e70403f4f9379d7..15d6443fd34784019459a9e489174d7c2ac09131 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI PCI IO protocol functions implementation for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -46,26 +46,6 @@ EFI_PCI_IO_PROTOCOL  mPciIoInterface = {
   NULL\r
 };\r
 \r
-/**\r
-  Report a error Status code of PCI bus driver controller.\r
-\r
-  @param PciIoDevice Pci device instance.\r
-  @param Code        Status code value.\r
-\r
-**/\r
-EFI_STATUS\r
-ReportErrorStatusCode (\r
-  IN PCI_IO_DEVICE               *PciIoDevice,\r
-  IN EFI_STATUS_CODE_VALUE       Code\r
-  )\r
-{\r
-  return REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
-          EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
-          Code,\r
-          PciIoDevice->DevicePath\r
-          );\r
-}\r
-\r
 /**\r
   Initializes a PCI I/O Instance.\r
 \r
@@ -105,7 +85,7 @@ PciIoVerifyBarAccess (
   IN UINT64                          *Offset\r
   )\r
 {\r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -166,7 +146,7 @@ PciIoVerifyConfigAccess (
 {\r
   UINT64  ExtendOffset;\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -235,7 +215,7 @@ PciIoPollMem (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -292,7 +272,11 @@ PciIoPollMem (
                                            );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -338,7 +322,7 @@ PciIoPollIo (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width > EfiPciIoWidthUint64) {\r
+  if ((UINT32)Width > EfiPciIoWidthUint64) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -391,7 +375,11 @@ PciIoPollIo (
                                            );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -433,7 +421,7 @@ PciIoMemRead (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -466,7 +454,11 @@ PciIoMemRead (
                                               );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -508,7 +500,7 @@ PciIoMemWrite (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -540,7 +532,11 @@ PciIoMemWrite (
                                               );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_WRITE_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_WRITE_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -582,7 +578,7 @@ PciIoIoRead (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -614,7 +610,11 @@ PciIoIoRead (
                                               );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -656,7 +656,7 @@ PciIoIoWrite (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -688,7 +688,11 @@ PciIoIoWrite (
                                               );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_WRITE_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_WRITE_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -753,7 +757,11 @@ PciIoConfigRead (
                                                );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -818,7 +826,11 @@ PciIoConfigWrite (
                                               );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_WRITE_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_WRITE_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -869,7 +881,7 @@ PciIoCopyMem (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -913,7 +925,11 @@ PciIoCopyMem (
                                           );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -954,7 +970,7 @@ PciIoMap (
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Operation < 0 || Operation >= EfiPciIoOperationMaximum) {\r
+  if ((UINT32)Operation >= EfiPciIoOperationMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -976,7 +992,11 @@ PciIoMap (
                                           );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -1010,7 +1030,11 @@ PciIoUnmap (
                                           );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -1071,7 +1095,11 @@ PciIoAllocateBuffer (
                                           );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -1109,7 +1137,11 @@ PciIoFreeBuffer (
                                           );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -1141,7 +1173,11 @@ PciIoFlush (
                                            PciIoDevice->PciRootBridgeIo\r
                                            );\r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -1268,6 +1304,13 @@ ModifyRootBridgeAttributes (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Mask off attributes not supported by PCI root bridge.\r
+  //\r
+  Attributes &= ~(UINT64)(EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE |\r
+                          EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM |\r
+                          EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE);\r
+\r
   //\r
   // Record the new attribute of the Root Bridge\r
   //\r
@@ -1405,7 +1448,7 @@ SupportPaletteSnoopAttributes (
     //\r
     if (Operation == EfiPciIoAttributeOperationEnable) {\r
       PCI_DISABLE_COMMAND_REGISTER (Temp, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
-      Temp->Attributes &= (~EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
+      Temp->Attributes &= (~(UINT64)EFI_PCI_COMMAND_VGA_PALETTE_SNOOP);\r
     } else {\r
       return EFI_UNSUPPORTED;\r
     }\r
@@ -1522,6 +1565,20 @@ PciIoAttributes (
       );\r
   }\r
 \r
+  //\r
+  // Check VGA and VGA16, they can not be set at the same time\r
+  //\r
+  if (((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO) != 0         &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16) != 0)         ||\r
+      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO) != 0         &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16) != 0) ||\r
+      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) != 0 &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16) != 0)         ||\r
+      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) != 0 &&\r
+       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16) != 0) ) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // If no attributes can be supported, then return.\r
   // Otherwise, set the attributes that it can support.\r
@@ -1542,20 +1599,6 @@ PciIoAttributes (
   Command       = 0;\r
   BridgeControl = 0;\r
 \r
-  //\r
-  // Check VGA and VGA16, they can not be set at the same time\r
-  //\r
-  if (((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO) != 0         &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16) != 0)         ||\r
-      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO) != 0         &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16) != 0) ||\r
-      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) != 0 &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_IO_16) != 0)         ||\r
-      ((Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO) != 0 &&\r
-       (Attributes & EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16) != 0) ) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   //\r
   // For PPB & P2C, set relevant attribute bits\r
   //\r
@@ -1695,7 +1738,11 @@ PciIoAttributes (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR,\r
+      PciIoDevice->DevicePath\r
+      );\r
   }\r
 \r
   return Status;\r
@@ -1732,14 +1779,10 @@ PciIoGetBarAttributes (
   OUT VOID                           **Resources OPTIONAL\r
   )\r
 {\r
-\r
   UINT8                             *Configuration;\r
-  UINT8                             NumConfig;\r
   PCI_IO_DEVICE                     *PciIoDevice;\r
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Ptr;\r
-  EFI_ACPI_END_TAG_DESCRIPTOR       *PtrEnd;\r
-\r
-  NumConfig   = 0;\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *AddressSpace;\r
+  EFI_ACPI_END_TAG_DESCRIPTOR       *End;\r
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
@@ -1747,7 +1790,7 @@ PciIoGetBarAttributes (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (BarIndex >= PCI_MAX_BAR) {\r
+  if ((BarIndex >= PCI_MAX_BAR) || (PciIoDevice->PciBar[BarIndex].BarType == PciBarTypeUnknown)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -1760,102 +1803,93 @@ PciIoGetBarAttributes (
   }\r
 \r
   if (Resources != NULL) {\r
-\r
-    if (PciIoDevice->PciBar[BarIndex].BarType != PciBarTypeUnknown) {\r
-      NumConfig = 1;\r
-    }\r
-\r
-    Configuration = AllocateZeroPool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) * NumConfig + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR));\r
+    Configuration = AllocateZeroPool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR));\r
     if (Configuration == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;\r
+    AddressSpace = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;\r
 \r
-    if (NumConfig == 1) {\r
-      Ptr->Desc         = ACPI_ADDRESS_SPACE_DESCRIPTOR;\r
-      Ptr->Len          = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3);\r
+    AddressSpace->Desc         = ACPI_ADDRESS_SPACE_DESCRIPTOR;\r
+    AddressSpace->Len          = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3);\r
 \r
-      Ptr->AddrRangeMin = PciIoDevice->PciBar[BarIndex].BaseAddress;\r
-      Ptr->AddrLen      = PciIoDevice->PciBar[BarIndex].Length;\r
-      Ptr->AddrRangeMax = PciIoDevice->PciBar[BarIndex].Alignment;\r
+    AddressSpace->AddrRangeMin = PciIoDevice->PciBar[BarIndex].BaseAddress;\r
+    AddressSpace->AddrLen      = PciIoDevice->PciBar[BarIndex].Length;\r
+    AddressSpace->AddrRangeMax = PciIoDevice->PciBar[BarIndex].Alignment;\r
 \r
-      switch (PciIoDevice->PciBar[BarIndex].BarType) {\r
-      case PciBarTypeIo16:\r
-      case PciBarTypeIo32:\r
-        //\r
-        // Io\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_IO;\r
-        break;\r
-\r
-      case PciBarTypeMem32:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // 32 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 32;\r
-        break;\r
+    switch (PciIoDevice->PciBar[BarIndex].BarType) {\r
+    case PciBarTypeIo16:\r
+    case PciBarTypeIo32:\r
+      //\r
+      // Io\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_IO;\r
+      break;\r
 \r
-      case PciBarTypePMem32:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // prefechable\r
-        //\r
-        Ptr->SpecificFlag = 0x6;\r
-        //\r
-        // 32 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 32;\r
-        break;\r
+    case PciBarTypeMem32:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // 32 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 32;\r
+      break;\r
 \r
-      case PciBarTypeMem64:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // 64 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 64;\r
-        break;\r
+    case PciBarTypePMem32:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // prefechable\r
+      //\r
+      AddressSpace->SpecificFlag = 0x6;\r
+      //\r
+      // 32 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 32;\r
+      break;\r
 \r
-      case PciBarTypePMem64:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // prefechable\r
-        //\r
-        Ptr->SpecificFlag = 0x6;\r
-        //\r
-        // 64 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 64;\r
-        break;\r
+    case PciBarTypeMem64:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // 64 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 64;\r
+      break;\r
 \r
-      default:\r
-        break;\r
-      }\r
+    case PciBarTypePMem64:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // prefechable\r
+      //\r
+      AddressSpace->SpecificFlag = 0x6;\r
+      //\r
+      // 64 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 64;\r
+      break;\r
 \r
-      Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) ((UINT8 *) Ptr + sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR));\r
+    default:\r
+      break;\r
     }\r
 \r
     //\r
     // put the checksum\r
     //\r
-    PtrEnd            = (EFI_ACPI_END_TAG_DESCRIPTOR *) ((UINT8 *) Ptr);\r
-    PtrEnd->Desc      = ACPI_END_TAG_DESCRIPTOR;\r
-    PtrEnd->Checksum  = 0;\r
+    End           = (EFI_ACPI_END_TAG_DESCRIPTOR *) (AddressSpace + 1);\r
+    End->Desc     = ACPI_END_TAG_DESCRIPTOR;\r
+    End->Checksum = 0;\r
 \r
-    *Resources        = Configuration;\r
+    *Resources    = Configuration;\r
   }\r
 \r
   return EFI_SUCCESS;\r