Revision: 13987
          http://edk2.svn.sourceforge.net/edk2/?rev=13987&view=rev
Author:   lzeng14
Date:     2012-12-10 12:54:02 +0000 (Mon, 10 Dec 2012)
Log Message:
-----------
1. Update IoRead to support UINT64 also.
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 <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptExecute.c

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

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to