]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Update IoRead to support UINT64 also.
authorlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 10 Dec 2012 12:54:02 +0000 (12:54 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 10 Dec 2012 12:54:02 +0000 (12:54 +0000)
2. To be consistent, update PciCfgRead to support full S3BootScriptWidth(Uint8, FifoUint8 and FullUint8) like PciCfgWrite.
3. Use BuildLoopData() to get the addressStride and BufferStride to do PCI CFG operations.
4. Correct, refine and enhance some comments and debug messages.

Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13987 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptExecute.c

index 01ca7df7cecbe58b326eb819191770706759fde0..914e7a518c28e811b97043789253b3ba8bed7dc9 100644 (file)
@@ -287,7 +287,7 @@ BuildLoopData (
 }\r
 \r
 /**\r
-  Translates boot script to MDE library interface.\r
+  Perform IO read operation\r
   \r
   @param[in]  Width   Width of the operation.\r
   @param[in]  Address Address of the operation.\r
@@ -331,26 +331,57 @@ ScriptIoRead (
     switch (Width) {\r
 \r
     case S3BootScriptWidthUint8:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint8 = IoRead8 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFifoUint8:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint8 = IoRead8 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFillUint8:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8Read - 0x%08x\n", Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%08x\n", (UINTN) Address));\r
       *Out.Uint8 = IoRead8 ((UINTN) Address);\r
       break;\r
 \r
     case S3BootScriptWidthUint16:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint16 = IoRead16 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFifoUint16:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint16 = IoRead16 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFillUint16:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16Read - 0x%08x\n", Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%08x\n", (UINTN) Address));\r
       *Out.Uint16 = IoRead16 ((UINTN) Address);\r
       break;\r
 \r
     case S3BootScriptWidthUint32:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint32 = IoRead32 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFifoUint32:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint32 = IoRead32 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFillUint32:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32Read - 0x%08x\n", Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%08x\n", (UINTN) Address));\r
       *Out.Uint32 = IoRead32 ((UINTN) Address);\r
       break;\r
 \r
+    case S3BootScriptWidthUint64:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint64 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint64 = IoRead64 ((UINTN) Address);\r
+      break;\r
+    case S3BootScriptWidthFifoUint64:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint64 = IoRead64 ((UINTN) Address);\r
+      break;\r
+    case S3BootScriptWidthFillUint64:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint64 - 0x%08x\n", (UINTN) Address));\r
+      *Out.Uint64 = IoRead64 ((UINTN) Address);\r
+      break;\r
+\r
     default:\r
       return EFI_INVALID_PARAMETER;\r
     }\r
@@ -360,7 +391,7 @@ ScriptIoRead (
 }\r
 \r
 /**\r
-  Perform a write operation\r
+  Perform IO write operation\r
   \r
   @param[in]  Width Width of the operation.\r
   @param[in]  Address Address of the operation.\r
@@ -463,7 +494,7 @@ ScriptIoWrite (
   return EFI_SUCCESS;\r
 }\r
 /**\r
-  Interprete the IO write entry in S3 boot script and perform the write operation\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_IO_WRITE OP code.\r
   \r
   @param Script       Pointer to the node which is to be interpreted.\r
 \r
@@ -490,7 +521,8 @@ BootScriptExecuteIoWrite (
   Address = IoWrite.Address;\r
   Count = IoWrite.Count;\r
   Buffer = Script + sizeof (EFI_BOOT_SCRIPT_IO_WRITE);\r
-  \r
+\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecuteIoWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN)Address, Count, (UINTN)Width));\r
   return ScriptIoWrite(Width, Address, Count, Buffer);\r
 }\r
 /**\r
@@ -534,30 +566,54 @@ ScriptMemoryRead (
   for (; Count > 0; Count--, Address += AddressStride, Out.Buf += BufferStride) {\r
     switch (Width) {\r
     case S3BootScriptWidthUint8:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint8 = MmioRead8 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFifoUint8:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint8 = MmioRead8 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFillUint8:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x\n", (UINTN)Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%08x\n", (UINTN)Address));\r
       *Out.Uint8 = MmioRead8 ((UINTN) Address);\r
       break;\r
 \r
     case S3BootScriptWidthUint16:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint16 = MmioRead16 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFifoUint16:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint16 = MmioRead16 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFillUint16:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x\n", (UINTN)Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%08x\n", (UINTN)Address));\r
       *Out.Uint16 = MmioRead16 ((UINTN) Address);\r
       break;\r
 \r
     case S3BootScriptWidthUint32:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint32 = MmioRead32 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFifoUint32:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint32 = MmioRead32 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFillUint32:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x\n", (UINTN)Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%08x\n", (UINTN)Address));\r
       *Out.Uint32 = MmioRead32 ((UINTN) Address);\r
       break;\r
 \r
     case S3BootScriptWidthUint64:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint64 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint64 = MmioRead64 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFifoUint64:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x\n", (UINTN)Address));\r
+      *Out.Uint64 = MmioRead64 ((UINTN) Address);\r
+      break;\r
     case S3BootScriptWidthFillUint64:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint64 - 0x%08x\n", (UINTN)Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint64 - 0x%08x\n", (UINTN)Address));\r
       *Out.Uint64 = MmioRead64 ((UINTN) Address);\r
       break;\r
 \r
@@ -569,7 +625,7 @@ ScriptMemoryRead (
   return EFI_SUCCESS;\r
 }\r
 /**\r
-  Translates boot script to MDE library interface.\r
+  Perform memory write operation\r
   \r
   @param   Width   Width of the operation.\r
   @param   Address Address of the operation.\r
@@ -696,16 +752,17 @@ BootScriptExecuteMemoryWrite (
   Count   = MemWrite.Count;\r
   Buffer  = Script + sizeof(EFI_BOOT_SCRIPT_MEM_WRITE);\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecuteMemoryWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN)Address, (UINTN)Count, (UINTN)Width));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecuteMemoryWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN)Address, Count, (UINTN)Width));\r
   return ScriptMemoryWrite (Width,Address, Count,  Buffer);\r
   \r
 }  \r
 /**\r
-  Translates boot script to MDE library interface for PCI configuration read operation\r
+  Performance PCI configuration read operation\r
 \r
   @param  Width   Width of the operation.\r
   @param  Address Address of the operation.\r
-  @param  Buffer  Pointer to the buffer reaf from PCI config space\r
+  @param  Count   Count of the number of accesses to perform.\r
+  @param  Buffer  Pointer to the buffer read from PCI config space\r
   \r
   @retval EFI_SUCCESS The read succeed.\r
   @retval EFI_INVALID_PARAMETER if Width is not defined  \r
@@ -715,37 +772,82 @@ EFI_STATUS
 ScriptPciCfgRead (\r
   IN  S3_BOOT_SCRIPT_LIB_WIDTH    Width,\r
   IN  UINT64                       Address,\r
+  IN  UINTN                        Count,\r
   OUT VOID                        *Buffer\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+  UINTN       AddressStride;\r
+  UINTN       BufferStride;\r
+  PTR         Out;\r
+  UINTN       PciAddress;\r
+\r
+  Out.Buf = (UINT8 *) Buffer;\r
+\r
+  PciAddress = PCI_ADDRESS_ENCODE (Address);\r
+\r
+  Status = BuildLoopData (Width, PciAddress, &AddressStride, &BufferStride);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Loop for each iteration and move the data\r
+  //\r
+  for (; Count > 0; Count--, PciAddress += AddressStride, Out.Buf += BufferStride) {\r
     switch (Width) {\r
     case S3BootScriptWidthUint8:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%016lx\n", Address));\r
-      * (UINT8 *) Buffer = PciRead8 (PCI_ADDRESS_ENCODE(Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x\n", PciAddress));\r
+      *Out.Uint8 = PciRead8 (PciAddress);\r
+      break;\r
+    case S3BootScriptWidthFifoUint8:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x\n", PciAddress));\r
+      *Out.Uint8 = PciRead8 (PciAddress);\r
+      break;\r
+    case S3BootScriptWidthFillUint8:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%08x\n", PciAddress));\r
+      *Out.Uint8 = PciRead8 (PciAddress);\r
       break;\r
 \r
     case S3BootScriptWidthUint16:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%016lx\n", Address));\r
-      * (UINT16 *) Buffer = PciRead16 (PCI_ADDRESS_ENCODE(Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x\n", PciAddress));\r
+      *Out.Uint16 = PciRead16 (PciAddress);\r
+      break;\r
+    case S3BootScriptWidthFifoUint16:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x\n", PciAddress));\r
+      *Out.Uint16 = PciRead16 (PciAddress);\r
+      break;\r
+    case S3BootScriptWidthFillUint16:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%08x\n", PciAddress));\r
+      *Out.Uint16 = PciRead16 (PciAddress);\r
       break;\r
 \r
     case S3BootScriptWidthUint32:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%016lx\n", Address));\r
-      * (UINT32 *) Buffer = PciRead32 (PCI_ADDRESS_ENCODE(Address));\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x\n", PciAddress));\r
+      *Out.Uint32 = PciRead32 (PciAddress);\r
+      break;\r
+    case S3BootScriptWidthFifoUint32:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x\n", PciAddress));\r
+      *Out.Uint32 = PciRead32 (PciAddress);\r
+      break;\r
+    case S3BootScriptWidthFillUint32:\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%08x\n", PciAddress));\r
+      *Out.Uint32 = PciRead32 (PciAddress);\r
       break;\r
 \r
     default:\r
       return EFI_INVALID_PARAMETER;\r
+    }\r
   }\r
-    return EFI_SUCCESS;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Translates boot script to MDE library interface for PCI configuration write operation\r
+  Performance PCI configuration write operation\r
 \r
   @param  Width   Width of the operation.\r
   @param  Address Address of the operation.\r
-  @param  Buffer  Pointer to the buffer reaf from PCI config space\r
+  @param  Count   Count of the number of accesses to perform.\r
+  @param  Buffer  Pointer to the buffer write to PCI config space\r
   \r
   @retval EFI_SUCCESS The write succeed.\r
   @retval EFI_INVALID_PARAMETER if Width is not defined  \r
@@ -755,40 +857,83 @@ EFI_STATUS
 ScriptPciCfgWrite (\r
   IN  S3_BOOT_SCRIPT_LIB_WIDTH     Width,\r
   IN  UINT64                       Address,\r
-  OUT VOID                         *Buffer\r
+  IN  UINTN                        Count,\r
+  IN  VOID                         *Buffer\r
   )\r
 {\r
-  switch (Width) {\r
-    case S3BootScriptWidthUint8:\r
-    case S3BootScriptWidthFifoUint8:\r
-    case S3BootScriptWidthFillUint8:      \r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%016lx (0x%02x)\n", Address, (UINTN)*(UINT8 *) Buffer));\r
-      PciWrite8 (PCI_ADDRESS_ENCODE(Address), *(UINT8 *) Buffer);\r
-      break;\r
-    case S3BootScriptWidthUint16:\r
-    case S3BootScriptWidthFifoUint16:\r
-    case S3BootScriptWidthFillUint16:       \r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%016lx (0x%04x)\n", Address, (UINTN)*(UINT16 *) Buffer));\r
-      PciWrite16 (PCI_ADDRESS_ENCODE(Address), *(UINT16 *) Buffer);\r
-      break;\r
-    case S3BootScriptWidthUint32:\r
-    case S3BootScriptWidthFifoUint32:\r
-    case S3BootScriptWidthFillUint32:       \r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%016lx (0x%08x)\n", Address, (UINTN)*(UINT32 *) Buffer));\r
-      PciWrite32 (PCI_ADDRESS_ENCODE(Address), *(UINT32 *) Buffer);\r
-      break;\r
-    default:\r
-      return EFI_INVALID_PARAMETER;\r
+  EFI_STATUS  Status;\r
+  UINTN       AddressStride;\r
+  UINTN       BufferStride;\r
+  UINTN       OriginalPciAddress;\r
+  PTR         In;\r
+  PTR         OriginalIn;\r
+  UINTN       PciAddress;\r
+\r
+  In.Buf = (UINT8 *) Buffer;\r
+\r
+  PciAddress = PCI_ADDRESS_ENCODE (Address);\r
+\r
+  Status = BuildLoopData (Width, PciAddress, &AddressStride, &BufferStride);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
-    return EFI_SUCCESS;\r
+  //\r
+  // Loop for each iteration and move the data\r
+  //\r
+  OriginalPciAddress = PciAddress;\r
+  OriginalIn.Buf = In.Buf;\r
+  for (; Count > 0; Count--, PciAddress += AddressStride, In.Buf += BufferStride) {\r
+    switch (Width) {\r
+      case S3BootScriptWidthUint8:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", PciAddress, (UINTN)*In.Uint8));\r
+        PciWrite8 (PciAddress, *In.Uint8);\r
+        break;      \r
+      case S3BootScriptWidthFifoUint8:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", OriginalPciAddress, (UINTN)*In.Uint8));\r
+        PciWrite8 (OriginalPciAddress, *In.Uint8);\r
+        break;      \r
+      case S3BootScriptWidthFillUint8:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", PciAddress, (UINTN)*OriginalIn.Uint8));\r
+        PciWrite8 (PciAddress, *OriginalIn.Uint8);\r
+        break;\r
+      case S3BootScriptWidthUint16:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", PciAddress, (UINTN)*In.Uint16));\r
+        PciWrite16 (PciAddress, *In.Uint16);\r
+        break;      \r
+      case S3BootScriptWidthFifoUint16:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", OriginalPciAddress, (UINTN)*In.Uint16));\r
+        PciWrite16 (OriginalPciAddress, *In.Uint16);\r
+        break;      \r
+      case S3BootScriptWidthFillUint16:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", PciAddress, (UINTN)*OriginalIn.Uint16));\r
+        PciWrite16 (PciAddress, *OriginalIn.Uint16);\r
+        break;\r
+      case S3BootScriptWidthUint32:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", PciAddress, (UINTN)*In.Uint32));\r
+        PciWrite32 (PciAddress, *In.Uint32);\r
+        break;      \r
+      case S3BootScriptWidthFifoUint32:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", OriginalPciAddress, (UINTN)*In.Uint32));\r
+        PciWrite32 (OriginalPciAddress, *In.Uint32);\r
+        break;      \r
+      case S3BootScriptWidthFillUint32:\r
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%08x (0x%08x)\n", (UINTN)PciAddress, (UINTN)*OriginalIn.Uint32));\r
+        PciWrite32 (PciAddress, *OriginalIn.Uint32);\r
+        break;\r
+      default:\r
+        return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  return EFI_SUCCESS;\r
 }\r
 /**\r
-  Perform pci configure 2 read operation.\r
+  Performance PCI configuration 2 read operation\r
   \r
   @param     Width                      Width of the operation.\r
   @param     Segment                    Pci segment number\r
   @param     Address                    Address of the operation.\r
-  @param     Buffer                     Pointer to the buffer to write to I/O space.  \r
+  @param     Count                      Count of the number of accesses to perform.\r
+  @param     Buffer                     Pointer to the buffer to read from PCI config space.\r
 \r
   @retval    EFI_SUCCESS                The data was written to the EFI System.\r
   @retval    EFI_INVALID_PARAMETER      Width is invalid for this EFI System.\r
@@ -803,20 +948,22 @@ ScriptPciCfg2Read (
   IN  S3_BOOT_SCRIPT_LIB_WIDTH    Width,\r
   IN  UINT16                   Segment,  \r
   IN  UINT64                   Address,\r
+  IN  UINTN                    Count,\r
   OUT VOID                     *Buffer\r
   )\r
 {\r
   ASSERT (Segment==0);\r
   \r
-  return ScriptPciCfgRead (Width, Address, Buffer);\r
+  return ScriptPciCfgRead (Width, Address, Count, Buffer);\r
 }\r
 /**\r
-  Perform pci configure write operation.\r
+  Performance PCI configuration 2 write operation\r
   \r
   @param     Width                      Width of the operation.\r
   @param     Segment                    Pci segment number\r
   @param     Address                    Address of the operation.\r
-  @param     Buffer                     Pointer to the buffer to write to I/O space.  \r
+  @param     Count                      Count of the number of accesses to perform.\r
+  @param     Buffer                     Pointer to the buffer to write to PCI config space.\r
 \r
   @retval    EFI_SUCCESS                The data was written to the EFI System.\r
   @retval    EFI_INVALID_PARAMETER      Width is invalid for this EFI System.\r
@@ -833,14 +980,15 @@ ScriptPciCfg2Write (
   IN  S3_BOOT_SCRIPT_LIB_WIDTH    Width,\r
   IN  UINT16                   Segment,  \r
   IN  UINT64                   Address,\r
-  OUT VOID                     *Buffer\r
+  IN  UINTN                    Count,\r
+  IN  VOID                     *Buffer\r
   )\r
 {\r
   ASSERT (Segment==0);\r
-  return ScriptPciCfgWrite (Width, Address, Buffer);\r
+  return ScriptPciCfgWrite (Width, Address, Count, Buffer);\r
 }\r
 /**\r
-  Perform Pci configuration Write operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE OP code.\r
   \r
   @param  Script        The pointer of typed node in boot script table \r
   \r
@@ -851,50 +999,24 @@ BootScriptExecutePciCfgWrite (
   IN UINT8                    *Script\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT8       *Buffer;\r
-  UINTN       DataWidth;\r
-  UINTN       Index;\r
-  UINT64      PciAddress;\r
-  UINT8       Reg;\r
-  EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE  PciConfigWrite;\r
-\r
-  CopyMem ((VOID*)&PciConfigWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE));\r
-  Status      = EFI_SUCCESS;\r
-\r
-  PciAddress  = PciConfigWrite.Address;\r
-  DataWidth   = (UINT32)(0x01 << (PciConfigWrite.Width));\r
-  Buffer      = Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE);\r
+  VOID                              *Buffer;\r
+  S3_BOOT_SCRIPT_LIB_WIDTH          Width;\r
+  UINT64                            Address;\r
+  UINTN                             Count;\r
+  EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE  PciCfgWrite;\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfgWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN)PciAddress, (UINTN)PciConfigWrite.Count, (UINTN)DataWidth));\r
-\r
-  for (Index = 0; Index < PciConfigWrite.Count; Index++) {\r
-    Status = ScriptPciCfgWrite (\r
-               (S3_BOOT_SCRIPT_LIB_WIDTH) PciConfigWrite.Width,\r
-               PciAddress,\r
-               Buffer\r
-               );\r
+  CopyMem ((VOID*)&PciCfgWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE));\r
 \r
-   if ( S3BootScriptWidthFillUint8 !=  PciConfigWrite.Width ||\r
-        S3BootScriptWidthFillUint16 != PciConfigWrite.Width || \r
-        S3BootScriptWidthFillUint32 != PciConfigWrite.Width ||\r
-        S3BootScriptWidthFillUint64 != PciConfigWrite.Width){\r
-      Reg         = (UINT8) ((UINT8) PciAddress + DataWidth);\r
-      PciAddress  = (PciAddress & 0xFFFFFFFFFFFFFF00ULL) + Reg;\r
-    }\r
-\r
-    if (S3BootScriptWidthFifoUint8 != PciConfigWrite.Width ||\r
-        S3BootScriptWidthFifoUint16 != PciConfigWrite.Width || \r
-        S3BootScriptWidthFifoUint32 != PciConfigWrite.Width ||\r
-        S3BootScriptWidthFifoUint64 != PciConfigWrite.Width) {\r
-      Buffer += DataWidth;\r
-    }\r
-  }\r
+  Width   = (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfgWrite.Width;\r
+  Address = PciCfgWrite.Address;\r
+  Count   = PciCfgWrite.Count;\r
+  Buffer  = Script + sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE);\r
 \r
-  return Status;\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfgWrite - 0x%08x, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (Address), Count, (UINTN)Width));\r
+  return ScriptPciCfgWrite (Width, Address, Count, Buffer);\r
 }\r
 /**\r
-  Excute the script to perform IO modification operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_IO_READ_WRITE OP code.\r
 \r
   @param Script   The pointer of typed node in boot script table \r
   @param AndMask  Mask value for 'and' operation\r
@@ -918,7 +1040,7 @@ BootScriptExecuteIoReadWrite (
   \r
   CopyMem((VOID*)&IoReadWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecuteIoReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)IoReadWrite.Address, (UINT64)AndMask, (UINT64)OrMask));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecuteIoReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)IoReadWrite.Address, AndMask, OrMask));\r
 \r
   Status = ScriptIoRead (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) IoReadWrite.Width,\r
@@ -938,7 +1060,7 @@ BootScriptExecuteIoReadWrite (
   return Status;\r
 }\r
 /**\r
-  Excute the script to perform memory modification operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_READ_WRITE OP code.\r
 \r
   @param Script    The pointer of typed node in boot script table \r
   @param AndMask   Mask value for 'and' operation\r
@@ -962,7 +1084,7 @@ BootScriptExecuteMemoryReadWrite (
   \r
   CopyMem((VOID*)&MemReadWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_MEM_READ_WRITE));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecuteMemoryReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)MemReadWrite.Address, (UINT64)AndMask, (UINT64)OrMask));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecuteMemoryReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)MemReadWrite.Address, AndMask, OrMask));\r
   \r
   Status = ScriptMemoryRead (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) MemReadWrite.Width,\r
@@ -982,7 +1104,7 @@ BootScriptExecuteMemoryReadWrite (
   return Status;\r
 }\r
 /**\r
-  Excute the script to perform PCI IO modification operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CFG_READ_WRITE OP code.\r
 \r
   @param Script   The pointer of typed node in boot script table \r
   @param AndMask  Mask value for 'and' operation\r
@@ -1004,11 +1126,12 @@ BootScriptExecutePciCfgReadWrite (
   \r
   CopyMem((VOID*)&PciCfgReadWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfgReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)PciCfgReadWrite.Address, (UINT64)AndMask, (UINT64)OrMask));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfgReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfgReadWrite.Address), AndMask, OrMask));\r
   \r
   Status = ScriptPciCfgRead (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfgReadWrite.Width,\r
              PciCfgReadWrite.Address,\r
+             1,\r
              &Data\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -1020,13 +1143,14 @@ BootScriptExecutePciCfgReadWrite (
   Status = ScriptPciCfgWrite (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfgReadWrite.Width,\r
              PciCfgReadWrite.Address,\r
+             1,\r
              &Data\r
              );\r
 \r
   return Status;\r
 }\r
 /**\r
-  To Execute SMBUS command. \r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_SMBUS_EXECUTE OP code.\r
 \r
   @param Script  The pointer of typed node in boot script table \r
  \r
@@ -1057,7 +1181,7 @@ BootScriptExecuteSmbusExecute (
            );\r
 }\r
 /**\r
-  Execute stall operation in boot script table.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_STALL OP code.\r
 \r
   @param Script      The pointer of typed node in boot script table \r
   \r
@@ -1078,10 +1202,10 @@ BootScriptExecuteStall (
   return EFI_SUCCESS;\r
 }\r
 /**\r
To execute assigned function.\r
 Interprete the boot script node with EFI_BOOT_SCRIPT_DISPATCH OP code.\r
   \r
- @param Script  The pointer of typed node in boot script table \r
- @retval EFI_SUCCESS  The operation was executed successfully\r
 @param Script  The pointer of typed node in boot script table \r
 @retval EFI_SUCCESS  The operation was executed successfully\r
 **/\r
 EFI_STATUS\r
 BootScriptExecuteDispatch (\r
@@ -1102,7 +1226,7 @@ BootScriptExecuteDispatch (
   return Status;\r
 }\r
 /**\r
-  Execute dispach2 opertion code which is to invoke a spcified function with one parameter. \r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_DISPATCH_2 OP code.\r
 \r
   @param  Script       The pointer of typed node in boot script table \r
   @retval EFI_SUCCESS  The operation was executed successfully\r
@@ -1127,7 +1251,7 @@ BootScriptExecuteDispatch2 (
   return Status;\r
 }\r
 /**\r
-  Excute the script to poll memory.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_POLL OP code.\r
 \r
   @param  Script  The pointer of typed node in boot script table \r
   @param  AndMask  Mask value for 'and' operation\r
@@ -1152,7 +1276,7 @@ BootScriptExecuteMemPoll (
   \r
   CopyMem ((VOID*)&MemPoll, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_MEM_POLL));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecuteMemPoll - 0x%08x\n", (UINTN)MemPoll.Address));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecuteMemPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)MemPoll.Address, AndMask, OrMask));\r
 \r
   Data = 0;\r
   Status = ScriptMemoryRead (\r
@@ -1187,7 +1311,7 @@ BootScriptExecuteMemPoll (
   }\r
 }\r
 /**\r
-  Execute the boot script to interpret the  Store arbitrary information. \r
+  Execute the boot script to interpret the Store arbitrary information.\r
   This opcode is a no-op on dispatch and is only used for debugging script issues.\r
 \r
   @param Script       The pointer of node in boot script table \r
@@ -1328,7 +1452,7 @@ CheckAndOrMask (
   return;\r
 }\r
 /**\r
-  Excute the script to poll Io port for some time\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_IO_POLL OP code.\r
 \r
   @param  Script  The pointer of typed node in boot script table \r
   @param  AndMask  Mask value for 'and' operation\r
@@ -1352,7 +1476,7 @@ BootScriptExecuteIoPoll (
   \r
   CopyMem ((VOID*)&IoPoll, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_IO_POLL));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecuteIoPoll - 0x%08x\n", (UINTN)IoPoll.Address));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecuteIoPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)IoPoll.Address, AndMask, OrMask));\r
 \r
   Data = 0;\r
   Status = ScriptIoRead (\r
@@ -1385,7 +1509,7 @@ BootScriptExecuteIoPoll (
   }\r
 }\r
 /**\r
-  Perform Pci configuration Write operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE OP code.\r
 \r
   @param    Script              The pointer of S3 boot script\r
 \r
@@ -1397,52 +1521,28 @@ BootScriptExecutePciCfg2Write (
   IN UINT8             *Script\r
   )\r
 {\r
-  UINT8       Reg;\r
-  UINT8       *Buffer;\r
-  UINTN       DataWidth;\r
-  UINTN       Index;\r
-  UINT16      Segment;\r
-  UINT64      PciAddress;\r
-  EFI_STATUS  Status;\r
-  EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE  PciCfg2Write;\r
+  VOID                              *Buffer;\r
+  S3_BOOT_SCRIPT_LIB_WIDTH          Width;\r
+  UINT16                            Segment;\r
+  UINT64                            Address;\r
+  UINTN                             Count;\r
+  EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE PciCfg2Write;\r
   \r
   CopyMem ((VOID*)&PciCfg2Write, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE));\r
-  Status      = EFI_SUCCESS;\r
-  Segment     = PciCfg2Write.Segment;\r
-  PciAddress  = PciCfg2Write.Address;\r
-  DataWidth   = (UINT32)(0x01 << (PciCfg2Write.Width));\r
-  Buffer      = Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE);\r
-\r
-  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfg2Write - 0x%08x\n", (UINTN)PciAddress));\r
-\r
-  for (Index = 0; Index < PciCfg2Write.Count; Index++) {\r
-    Status = ScriptPciCfg2Write (\r
-               (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2Write.Width,\r
-               Segment,\r
-               PciAddress,\r
-               Buffer\r
-               );\r
-    if (S3BootScriptWidthFillUint8  != PciCfg2Write.Width ||\r
-        S3BootScriptWidthFillUint16 != PciCfg2Write.Width || \r
-        S3BootScriptWidthFillUint32 != PciCfg2Write.Width ||\r
-        S3BootScriptWidthFillUint64 != PciCfg2Write.Width){\r
-      Reg         = (UINT8) ((UINT8) PciAddress + DataWidth);\r
-      PciAddress  = (PciAddress & 0xFFFFFFFFFFFFFF00ULL) + Reg;\r
-    }\r
 \r
-    if (S3BootScriptWidthFifoUint8  != PciCfg2Write.Width ||\r
-        S3BootScriptWidthFifoUint16 != PciCfg2Write.Width || \r
-        S3BootScriptWidthFifoUint32 != PciCfg2Write.Width ||\r
-        S3BootScriptWidthFifoUint64 != PciCfg2Write.Width) {\r
-      Buffer += DataWidth;\r
-    }\r
-  }\r
-  return Status;\r
+  Width   = (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfg2Write.Width;\r
+  Segment = PciCfg2Write.Segment;\r
+  Address = PciCfg2Write.Address;\r
+  Count   = PciCfg2Write.Count;\r
+  Buffer  = Script + sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE);\r
+\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfg2Write - 0x%04x, 0x%08x, 0x%08x, 0x%08x\n", Segment, PCI_ADDRESS_ENCODE (Address), Count, (UINTN)Width));\r
+  return ScriptPciCfg2Write (Width, Segment, Address, Count, Buffer);\r
 }\r
 \r
 \r
 /**\r
-  Perform pci configuration read & Write operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE OP code.\r
   \r
   @param     Script                     The pointer of S3 boot script\r
   @param     AndMask                    Mask value for 'and' operation\r
@@ -1463,12 +1563,13 @@ BootScriptExecutePciCfg2ReadWrite (
   EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE PciCfg2ReadWrite;\r
   CopyMem ((VOID*)&PciCfg2ReadWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfg2ReadWrite - 0x%08x\n", (UINTN)PciCfg2ReadWrite.Address));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfg2ReadWrite - 0x%04x, 0x%08x, 0x%016lx, 0x%016lx\n", PciCfg2ReadWrite.Segment, PCI_ADDRESS_ENCODE (PciCfg2ReadWrite.Address), AndMask, OrMask));\r
   \r
   Status = ScriptPciCfg2Read (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2ReadWrite.Width,\r
              PciCfg2ReadWrite.Segment,\r
              PciCfg2ReadWrite.Address,\r
+             1,\r
              &Data\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -1480,12 +1581,13 @@ BootScriptExecutePciCfg2ReadWrite (
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2ReadWrite.Width,\r
              PciCfg2ReadWrite.Segment,\r
              PciCfg2ReadWrite.Address,\r
+             1,\r
              &Data\r
              );\r
   return Status;\r
 }\r
 /**\r
-  To perform poll pci configure operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_POLL OP code.\r
   \r
   @param     Script                     The pointer of S3 boot script\r
   @param     AndMask                    Mask value for 'and' operation\r
@@ -1508,12 +1610,13 @@ BootScriptPciCfgPoll (
   EFI_BOOT_SCRIPT_PCI_CONFIG_POLL PciCfgPoll;\r
   CopyMem ((VOID*)&PciCfgPoll, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_POLL));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptPciCfgPoll - 0x%08x\n", (UINTN)PciCfgPoll.Address));\r
+  DEBUG ((EFI_D_INFO, "BootScriptPciCfgPoll - 0x%08x, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfgPoll.Address), AndMask, OrMask));\r
   \r
   Data = 0;\r
   Status = ScriptPciCfgRead (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfgPoll.Width,\r
              PciCfgPoll.Address,\r
+             1,\r
              &Data\r
              );\r
   if ((!EFI_ERROR (Status)) &&(Data & AndMask) == OrMask) {\r
@@ -1526,6 +1629,7 @@ BootScriptPciCfgPoll (
     Status = ScriptPciCfgRead (\r
                (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfgPoll.Width,\r
                PciCfgPoll.Address,\r
+               1,\r
                &Data\r
                );\r
     if ((!EFI_ERROR (Status)) &&\r
@@ -1542,7 +1646,7 @@ BootScriptPciCfgPoll (
 }\r
 \r
 /**\r
-  To perform poll pci configure operation.\r
+  Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL OP code.\r
   \r
   @param     Script                     The pointer of S3 Boot Script\r
   @param     AndMask                    Mask value for 'and' operation\r
@@ -1568,12 +1672,13 @@ BootScriptPciCfg2Poll (
   Data = 0;\r
   CopyMem ((VOID*)&PciCfg2Poll, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL));\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptPciCfg2Poll - 0x%08x\n", (UINTN)PciCfg2Poll.Address));\r
+  DEBUG ((EFI_D_INFO, "BootScriptPciCfg2Poll - 0x%04x, 0x%08x, 0x%016lx, 0x%016lx\n", PciCfg2Poll.Segment, PCI_ADDRESS_ENCODE (PciCfg2Poll.Address), AndMask, OrMask));\r
  \r
   Status = ScriptPciCfg2Read (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2Poll.Width,\r
              PciCfg2Poll.Segment,\r
              PciCfg2Poll.Address,\r
+             1,\r
              &Data\r
              );\r
   if ((!EFI_ERROR (Status)) && (Data & AndMask) == OrMask) {\r
@@ -1588,6 +1693,7 @@ BootScriptPciCfg2Poll (
                (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2Poll.Width,\r
                PciCfg2Poll.Segment,               \r
                PciCfg2Poll.Address,\r
+               1,\r
                &Data\r
                );\r
     if ((!EFI_ERROR (Status)) &&  (Data & AndMask) == OrMask) {\r