]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptExecute.c
MdeModulePkg: Refine casting expression result to bigger size
[mirror_edk2.git] / MdeModulePkg / Library / PiDxeS3BootScriptLib / BootScriptExecute.c
index cba331a3bda30d41dc5ef231c4838a64a58d528e..b865d4452fc823ee681a02bfdb695ce6e7c366a2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  Interpret and execute the S3 data in S3 boot script. \r
+  Interpret and execute the S3 data in S3 boot script.\r
 \r
-  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
@@ -23,7 +23,7 @@
   Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus\r
   slave devices accept this transaction or that this function returns with error.\r
 \r
-  @param  SmbusAddress            Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, \r
+  @param  SmbusAddress            Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length,\r
                                   and PEC.\r
   @param  Operation               Signifies which particular SMBus hardware protocol instance that\r
                                   it will use to execute the SMBus transactions. This SMBus\r
@@ -120,7 +120,7 @@ SmbusExecute (
       return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  return Status;  \r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -130,7 +130,7 @@ SmbusExecute (
   @param Width          Width of the operation.\r
   @param Address        Address of the operation.\r
   @param AddressStride  Instride for stepping input buffer.\r
-  @param BufferStride   Outstride for stepping output buffer.  \r
+  @param BufferStride   Outstride for stepping output buffer.\r
 \r
   @retval EFI_SUCCESS  Successful translation.\r
   @retval EFI_INVALID_PARAMETER Width or Address is invalid.\r
@@ -170,18 +170,18 @@ BuildLoopData (
 \r
 /**\r
   Perform IO read operation\r
-  \r
+\r
   @param[in]  Width   Width of the operation.\r
   @param[in]  Address Address of the operation.\r
   @param[in]  Count   Count of the number of accesses to perform.\r
-  @param[out] Buffer  Pointer to the buffer to read from I/O space.  \r
+  @param[out] Buffer  Pointer to the buffer to read from I/O 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
                                 Buffer is NULL.\r
                                 The Buffer is not aligned for the given Width.\r
-                                Address is outside the legal range of I/O ports.  \r
-                                \r
+                                Address is outside the legal range of I/O ports.\r
+\r
 **/\r
 EFI_STATUS\r
 ScriptIoRead (\r
@@ -274,18 +274,18 @@ ScriptIoRead (
 \r
 /**\r
   Perform IO write operation\r
-  \r
+\r
   @param[in]  Width Width of the operation.\r
   @param[in]  Address Address of the operation.\r
   @param[in]  Count Count of the number of accesses to perform.\r
-  @param[in]  Buffer Pointer to the buffer to write to I/O space.  \r
+  @param[in]  Buffer Pointer to the buffer to write to I/O 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
                                 Buffer is NULL.\r
                                 The Buffer is not aligned for the given Width.\r
-                                Address is outside the legal range of I/O ports.  \r
-                                \r
+                                Address is outside the legal range of I/O ports.\r
+\r
 **/\r
 EFI_STATUS\r
 ScriptIoWrite (\r
@@ -322,11 +322,11 @@ ScriptIoWrite (
       case S3BootScriptWidthUint8:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*In.Uint8));\r
         IoWrite8 ((UINTN) Address, *In.Uint8);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint8:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint8));\r
         IoWrite8 ((UINTN) OriginalAddress, *In.Uint8);\r
-        break;       \r
+        break;\r
       case S3BootScriptWidthFillUint8:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint8));\r
         IoWrite8 ((UINTN) Address, *OriginalIn.Uint8);\r
@@ -334,11 +334,11 @@ ScriptIoWrite (
       case S3BootScriptWidthUint16:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*In.Uint16));\r
         IoWrite16 ((UINTN) Address, *In.Uint16);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint16:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint16));\r
         IoWrite16 ((UINTN) OriginalAddress, *In.Uint16);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFillUint16:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint16));\r
         IoWrite16 ((UINTN) Address, *OriginalIn.Uint16);\r
@@ -346,7 +346,7 @@ ScriptIoWrite (
       case S3BootScriptWidthUint32:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", (UINTN)Address, (UINTN)*In.Uint32));\r
         IoWrite32 ((UINTN) Address, *In.Uint32);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint32:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint32));\r
         IoWrite32 ((UINTN) OriginalAddress, *In.Uint32);\r
@@ -358,11 +358,11 @@ ScriptIoWrite (
       case S3BootScriptWidthUint64:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *In.Uint64));\r
         IoWrite64 ((UINTN) Address, *In.Uint64);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint64:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x (0x%016lx)\n", (UINTN)OriginalAddress, *In.Uint64));\r
         IoWrite64 ((UINTN) OriginalAddress, *In.Uint64);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFillUint64:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *OriginalIn.Uint64));\r
         IoWrite64 ((UINTN) Address, *OriginalIn.Uint64);\r
@@ -371,25 +371,25 @@ ScriptIoWrite (
         return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
-  \r
+\r
 \r
   return EFI_SUCCESS;\r
 }\r
 /**\r
   Interprete the boot script node with EFI_BOOT_SCRIPT_IO_WRITE OP code.\r
-  \r
+\r
   @param Script       Pointer to the node which is to be interpreted.\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
                                 Buffer is NULL.\r
                                 The Buffer is not aligned for the given Width.\r
-                                Address is outside the legal range of I/O ports.  \r
-                                \r
+                                Address is outside the legal range of I/O ports.\r
+\r
 **/\r
 EFI_STATUS\r
 BootScriptExecuteIoWrite (\r
-  IN UINT8                    *Script    \r
+  IN UINT8                    *Script\r
   )\r
 {\r
   S3_BOOT_SCRIPT_LIB_WIDTH   Width;\r
@@ -397,7 +397,7 @@ BootScriptExecuteIoWrite (
   UINTN                      Count;\r
   VOID                      *Buffer;\r
   EFI_BOOT_SCRIPT_IO_WRITE   IoWrite;\r
-  \r
+\r
   CopyMem ((VOID*)&IoWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_IO_WRITE));\r
   Width = (S3_BOOT_SCRIPT_LIB_WIDTH) IoWrite.Width;\r
   Address = IoWrite.Address;\r
@@ -409,19 +409,19 @@ BootScriptExecuteIoWrite (
 }\r
 /**\r
   Perform memory read operation\r
-  \r
+\r
   @param  Width Width of the operation.\r
   @param  Address Address of the operation.\r
   @param  Count Count of the number of accesses to perform.\r
-  @param  Buffer Pointer to the buffer read from memory.  \r
+  @param  Buffer Pointer to the buffer read from memory.\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
                                 Buffer is NULL.\r
                                 The Buffer is not aligned for the given Width.\r
-  @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count \r
-                          is not valid for this EFI System.  \r
-                                \r
+  @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count\r
+                          is not valid for this EFI System.\r
+\r
 **/\r
 EFI_STATUS\r
 ScriptMemoryRead (\r
@@ -508,19 +508,19 @@ ScriptMemoryRead (
 }\r
 /**\r
   Perform memory write operation\r
-  \r
+\r
   @param   Width   Width of the operation.\r
   @param   Address Address of the operation.\r
   @param   Count   Count of the number of accesses to perform.\r
-  @param   Buffer  Pointer to the buffer write to memory.      \r
+  @param   Buffer  Pointer to the buffer write to memory.\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
                                 Buffer is NULL.\r
                                 The Buffer is not aligned for the given Width.\r
-  @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count \r
-                          is not valid for this EFI System.  \r
-                                \r
+  @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count\r
+                          is not valid for this EFI System.\r
+\r
 **/\r
 EFI_STATUS\r
 ScriptMemoryWrite (\r
@@ -532,7 +532,7 @@ ScriptMemoryWrite (
 {\r
   EFI_STATUS  Status;\r
   UINTN       AddressStride;\r
-  UINT64      OriginalAddress;  \r
+  UINT64      OriginalAddress;\r
   UINTN       BufferStride;\r
   PTR         In;\r
   PTR         OriginalIn;\r
@@ -547,17 +547,17 @@ ScriptMemoryWrite (
   // Loop for each iteration and move the data\r
   //\r
   OriginalAddress = Address;\r
-  OriginalIn.Buf = In.Buf;  \r
+  OriginalIn.Buf = In.Buf;\r
   for (; Count > 0; Count--, Address += AddressStride, In.Buf += BufferStride) {\r
     switch (Width) {\r
       case S3BootScriptWidthUint8:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*In.Uint8));\r
         MmioWrite8 ((UINTN) Address, *In.Uint8);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint8:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint8));\r
         MmioWrite8 ((UINTN) OriginalAddress, *In.Uint8);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFillUint8:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint8));\r
         MmioWrite8 ((UINTN) Address, *OriginalIn.Uint8);\r
@@ -565,11 +565,11 @@ ScriptMemoryWrite (
       case S3BootScriptWidthUint16:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*In.Uint16));\r
         MmioWrite16 ((UINTN) Address, *In.Uint16);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint16:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint16));\r
         MmioWrite16 ((UINTN) OriginalAddress, *In.Uint16);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFillUint16:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint16));\r
         MmioWrite16 ((UINTN) Address, *OriginalIn.Uint16);\r
@@ -577,11 +577,11 @@ ScriptMemoryWrite (
       case S3BootScriptWidthUint32:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", (UINTN)Address, (UINTN)*In.Uint32));\r
         MmioWrite32 ((UINTN) Address, *In.Uint32);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint32:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint32));\r
         MmioWrite32 ((UINTN) OriginalAddress, *In.Uint32);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFillUint32:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%08x (0x%08x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint32));\r
         MmioWrite32 ((UINTN) Address, *OriginalIn.Uint32);\r
@@ -589,11 +589,11 @@ ScriptMemoryWrite (
       case S3BootScriptWidthUint64:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *In.Uint64));\r
         MmioWrite64 ((UINTN) Address, *In.Uint64);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFifoUint64:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x (0x%016lx)\n", (UINTN)OriginalAddress, *In.Uint64));\r
         MmioWrite64 ((UINTN) OriginalAddress, *In.Uint64);\r
-        break;      \r
+        break;\r
       case S3BootScriptWidthFillUint64:\r
         DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *OriginalIn.Uint64));\r
         MmioWrite64 ((UINTN) Address, *OriginalIn.Uint64);\r
@@ -608,14 +608,14 @@ ScriptMemoryWrite (
   Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_WRITE OP code.\r
 \r
   @param[in]  Script Pointer to the node which is to be interpreted.\r
-  \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
                                 Buffer is NULL.\r
                                 The Buffer is not aligned for the given Width.\r
-  @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count \r
-                          is not valid for this EFI System.  \r
-                                \r
+  @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count\r
+                          is not valid for this EFI System.\r
+\r
 **/\r
 EFI_STATUS\r
 BootScriptExecuteMemoryWrite (\r
@@ -627,7 +627,7 @@ BootScriptExecuteMemoryWrite (
   UINT64           Address;\r
   UINTN            Count;\r
   EFI_BOOT_SCRIPT_MEM_WRITE  MemWrite;\r
-  \r
+\r
   CopyMem((VOID*)&MemWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE));\r
   Width   = (S3_BOOT_SCRIPT_LIB_WIDTH)MemWrite.Width;\r
   Address = MemWrite.Address;\r
@@ -636,24 +636,26 @@ BootScriptExecuteMemoryWrite (
 \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
+}\r
 /**\r
-  Performance PCI configuration read operation\r
+  Performance PCI configuration 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  Count   Count of the number of accesses to perform.\r
   @param  Buffer  Pointer to the buffer read from PCI config space\r
-  \r
+\r
   @retval EFI_SUCCESS The read succeed.\r
-  @retval EFI_INVALID_PARAMETER if Width is not defined  \r
+  @retval EFI_INVALID_PARAMETER if Width is not defined\r
   @note  A known Limitations in the implementation which is 64bits operations are not supported.\r
 \r
 **/\r
 EFI_STATUS\r
-ScriptPciCfgRead (\r
+ScriptPciCfg2Read (\r
   IN  S3_BOOT_SCRIPT_LIB_WIDTH    Width,\r
+  IN  UINT16                       Segment,\r
   IN  UINT64                       Address,\r
   IN  UINTN                        Count,\r
   OUT VOID                        *Buffer\r
@@ -663,11 +665,11 @@ ScriptPciCfgRead (
   UINTN       AddressStride;\r
   UINTN       BufferStride;\r
   PTR         Out;\r
-  UINT      PciAddress;\r
+  UINT64      PciAddress;\r
 \r
   Out.Buf = (UINT8 *) Buffer;\r
 \r
-  PciAddress = PCI_ADDRESS_ENCODE (Address);\r
+  PciAddress = PCI_ADDRESS_ENCODE (Segment, Address);\r
 \r
   Status = BuildLoopData (Width, PciAddress, &AddressStride, &BufferStride);\r
   if (EFI_ERROR (Status)) {\r
@@ -679,42 +681,42 @@ ScriptPciCfgRead (
   for (; Count > 0; Count--, PciAddress += AddressStride, Out.Buf += BufferStride) {\r
     switch (Width) {\r
     case S3BootScriptWidthUint8:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%08x\n", PciAddress));\r
-      *Out.Uint8 = PciRead8 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint8 = PciSegmentRead8 (PciAddress);\r
       break;\r
     case S3BootScriptWidthFifoUint8:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x\n", PciAddress));\r
-      *Out.Uint8 = PciRead8 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint8 = PciSegmentRead8 (PciAddress);\r
       break;\r
     case S3BootScriptWidthFillUint8:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%08x\n", PciAddress));\r
-      *Out.Uint8 = PciRead8 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint8 = PciSegmentRead8 (PciAddress);\r
       break;\r
 \r
     case S3BootScriptWidthUint16:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%08x\n", PciAddress));\r
-      *Out.Uint16 = PciRead16 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint16 = PciSegmentRead16 (PciAddress);\r
       break;\r
     case S3BootScriptWidthFifoUint16:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x\n", PciAddress));\r
-      *Out.Uint16 = PciRead16 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint16 = PciSegmentRead16 (PciAddress);\r
       break;\r
     case S3BootScriptWidthFillUint16:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%08x\n", PciAddress));\r
-      *Out.Uint16 = PciRead16 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint16 = PciSegmentRead16 (PciAddress);\r
       break;\r
 \r
     case S3BootScriptWidthUint32:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%08x\n", PciAddress));\r
-      *Out.Uint32 = PciRead32 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint32 = PciSegmentRead32 (PciAddress);\r
       break;\r
     case S3BootScriptWidthFifoUint32:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x\n", PciAddress));\r
-      *Out.Uint32 = PciRead32 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint32 = PciSegmentRead32 (PciAddress);\r
       break;\r
     case S3BootScriptWidthFillUint32:\r
-      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%08x\n", PciAddress));\r
-      *Out.Uint32 = PciRead32 (PciAddress);\r
+      DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%016lx\n", PciAddress));\r
+      *Out.Uint32 = PciSegmentRead32 (PciAddress);\r
       break;\r
 \r
     default:\r
@@ -725,21 +727,23 @@ ScriptPciCfgRead (
 }\r
 \r
 /**\r
-  Performance PCI configuration write operation\r
+  Performance PCI configuration 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  Count   Count of the number of accesses to perform.\r
   @param  Buffer  Pointer to the buffer write to PCI config space\r
-  \r
+\r
   @retval EFI_SUCCESS The write succeed.\r
-  @retval EFI_INVALID_PARAMETER if Width is not defined  \r
+  @retval EFI_INVALID_PARAMETER if Width is not defined\r
   @note  A known Limitations in the implementation which is 64bits operations are not supported.\r
 \r
 **/\r
 EFI_STATUS\r
-ScriptPciCfgWrite (\r
+ScriptPciCfg2Write (\r
   IN  S3_BOOT_SCRIPT_LIB_WIDTH     Width,\r
+  IN  UINT16                       Segment,\r
   IN  UINT64                       Address,\r
   IN  UINTN                        Count,\r
   IN  VOID                         *Buffer\r
@@ -748,14 +752,14 @@ ScriptPciCfgWrite (
   EFI_STATUS  Status;\r
   UINTN       AddressStride;\r
   UINTN       BufferStride;\r
-  UINT      OriginalPciAddress;\r
+  UINT64      OriginalPciAddress;\r
   PTR         In;\r
   PTR         OriginalIn;\r
-  UINT      PciAddress;\r
+  UINT64      PciAddress;\r
 \r
   In.Buf = (UINT8 *) Buffer;\r
 \r
-  PciAddress = PCI_ADDRESS_ENCODE (Address);\r
+  PciAddress = PCI_ADDRESS_ENCODE (Segment, Address);\r
 \r
   Status = BuildLoopData (Width, PciAddress, &AddressStride, &BufferStride);\r
   if (EFI_ERROR (Status)) {\r
@@ -769,40 +773,40 @@ ScriptPciCfgWrite (
   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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint8 - 0x%016lx (0x%02x)\n", PciAddress, (UINTN)*In.Uint8));\r
+        PciSegmentWrite8 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint8 - 0x%016lx (0x%02x)\n", OriginalPciAddress, (UINTN)*In.Uint8));\r
+        PciSegmentWrite8 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint8 - 0x%016lx (0x%02x)\n", PciAddress, (UINTN)*OriginalIn.Uint8));\r
+        PciSegmentWrite8 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint16 - 0x%016lx (0x%04x)\n", PciAddress, (UINTN)*In.Uint16));\r
+        PciSegmentWrite16 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint16 - 0x%016lx (0x%04x)\n", OriginalPciAddress, (UINTN)*In.Uint16));\r
+        PciSegmentWrite16 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint16 - 0x%016lx (0x%04x)\n", PciAddress, (UINTN)*OriginalIn.Uint16));\r
+        PciSegmentWrite16 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthUint32 - 0x%016lx (0x%08x)\n", PciAddress, (UINTN)*In.Uint32));\r
+        PciSegmentWrite32 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFifoUint32 - 0x%016lx (0x%08x)\n", OriginalPciAddress, (UINTN)*In.Uint32));\r
+        PciSegmentWrite32 (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
+        DEBUG ((EFI_D_INFO, "S3BootScriptWidthFillUint32 - 0x%016lx (0x%08x)\n", (UINTN)PciAddress, (UINTN)*OriginalIn.Uint32));\r
+        PciSegmentWrite32 (PciAddress, *OriginalIn.Uint32);\r
         break;\r
       default:\r
         return EFI_INVALID_PARAMETER;\r
@@ -811,10 +815,9 @@ ScriptPciCfgWrite (
   return EFI_SUCCESS;\r
 }\r
 /**\r
-  Performance PCI configuration read operation\r
-  \r
+  Performance PCI configuration 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     Count                      Count of the number of accesses to perform.\r
   @param     Buffer                     Pointer to the buffer to read from PCI config space.\r
@@ -824,27 +827,22 @@ ScriptPciCfgWrite (
                                         Buffer is NULL.\r
                                         The Buffer is not aligned for the given Width.\r
                                         Address is outside the legal range of I/O ports.\r
-  @note  A known Limitations in the implementation which is the 'Segment' parameter is assumed as \r
-         Zero, or else, assert.\r
+\r
 **/\r
 EFI_STATUS\r
-ScriptPciCfg2Read (\r
+ScriptPciCfgRead (\r
   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, Count, Buffer);\r
+  return ScriptPciCfg2Read (Width, 0, Address, Count, Buffer);\r
 }\r
 /**\r
-  Performance PCI configuration write operation\r
-  \r
+  Performance PCI configuration 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     Count                      Count of the number of accesses to perform.\r
   @param     Buffer                     Pointer to the buffer to write to PCI config space.\r
@@ -854,28 +852,24 @@ ScriptPciCfg2Read (
                                         Buffer is NULL.\r
                                         The Buffer is not aligned for the given Width.\r
                                         Address is outside the legal range of I/O ports.\r
-  @note  A known Limitations in the implementation which is the 'Segment' parameter is assumed as \r
-         Zero, or else, assert.\r
-                                \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ScriptPciCfg2Write (\r
+ScriptPciCfgWrite (\r
   IN  S3_BOOT_SCRIPT_LIB_WIDTH    Width,\r
-  IN  UINT16                   Segment,  \r
   IN  UINT64                   Address,\r
   IN  UINTN                    Count,\r
   IN  VOID                     *Buffer\r
   )\r
 {\r
-  ASSERT (Segment==0);\r
-  return ScriptPciCfgWrite (Width, Address, Count, Buffer);\r
+  return ScriptPciCfg2Write (Width, 0, Address, Count, Buffer);\r
 }\r
 /**\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
+\r
+  @param  Script        The pointer of typed node in boot script table\r
+\r
   @retval EFI_SUCCESS  The operation was executed successfully\r
 **/\r
 EFI_STATUS\r
@@ -896,13 +890,13 @@ BootScriptExecutePciCfgWrite (
   Count   = PciCfgWrite.Count;\r
   Buffer  = Script + sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE);\r
 \r
-  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfgWrite - 0x%08x, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (Address), Count, (UINTN)Width));\r
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfgWrite - 0x%016lx, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (0, Address), Count, (UINTN)Width));\r
   return ScriptPciCfgWrite (Width, Address, Count, Buffer);\r
 }\r
 /**\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 Script   The pointer of typed node in boot script table\r
   @param AndMask  Mask value for 'and' operation\r
   @param OrMask   Mask value for 'or' operation\r
 \r
@@ -919,9 +913,9 @@ BootScriptExecuteIoReadWrite (
   EFI_STATUS  Status;\r
   UINT64      Data;\r
   EFI_BOOT_SCRIPT_IO_READ_WRITE IoReadWrite;\r
-  \r
+\r
   Data = 0;\r
-  \r
+\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, AndMask, OrMask));\r
@@ -946,7 +940,7 @@ BootScriptExecuteIoReadWrite (
 /**\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 Script    The pointer of typed node in boot script table\r
   @param AndMask   Mask value for 'and' operation\r
   @param OrMask    Mask value for 'or' operation\r
 \r
@@ -963,13 +957,13 @@ BootScriptExecuteMemoryReadWrite (
   EFI_STATUS  Status;\r
   UINT64      Data;\r
   EFI_BOOT_SCRIPT_MEM_READ_WRITE  MemReadWrite;\r
-  \r
+\r
   Data = 0;\r
-  \r
+\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, AndMask, OrMask));\r
-  \r
+\r
   Status = ScriptMemoryRead (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) MemReadWrite.Width,\r
              MemReadWrite.Address,\r
@@ -990,7 +984,7 @@ BootScriptExecuteMemoryReadWrite (
 /**\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 Script   The pointer of typed node in boot script table\r
   @param AndMask  Mask value for 'and' operation\r
   @param OrMask   Mask value for 'or' operation\r
 \r
@@ -1012,8 +1006,8 @@ 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", PCI_ADDRESS_ENCODE (PciCfgReadWrite.Address), AndMask, OrMask));\r
-  \r
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfgReadWrite - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (0, PciCfgReadWrite.Address), AndMask, OrMask));\r
+\r
   Status = ScriptPciCfgRead (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfgReadWrite.Width,\r
              PciCfgReadWrite.Address,\r
@@ -1038,11 +1032,11 @@ BootScriptExecutePciCfgReadWrite (
 /**\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
+  @param Script  The pointer of typed node in boot script table\r
+\r
   @retval EFI_SUCCESS      The operation was executed successfully\r
   @retval EFI_UNSUPPORTED  Cannot locate smbus ppi or occur error of script execution\r
-  @retval Others           Result of script execution \r
+  @retval Others           Result of script execution\r
 **/\r
 EFI_STATUS\r
 BootScriptExecuteSmbusExecute (\r
@@ -1052,7 +1046,7 @@ BootScriptExecuteSmbusExecute (
   UINTN                    SmBusAddress;\r
   UINTN                    DataSize;\r
   EFI_BOOT_SCRIPT_SMBUS_EXECUTE SmbusExecuteEntry;\r
-  \r
+\r
   CopyMem ((VOID*)&SmbusExecuteEntry, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_SMBUS_EXECUTE ));\r
 \r
   DEBUG ((EFI_D_INFO, "BootScriptExecuteSmbusExecute - 0x%08x, 0x%08x\n", (UINTN)SmbusExecuteEntry.SmBusAddress, (UINTN)SmbusExecuteEntry.Operation));\r
@@ -1069,8 +1063,8 @@ BootScriptExecuteSmbusExecute (
 /**\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
+  @param Script      The pointer of typed node in boot script table\r
+\r
   @retval EFI_SUCCESS The operation was executed successfully\r
 **/\r
 EFI_STATUS\r
@@ -1079,7 +1073,7 @@ BootScriptExecuteStall (
   )\r
 {\r
   EFI_BOOT_SCRIPT_STALL    Stall;\r
-  \r
+\r
   CopyMem ((VOID*)&Stall, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_STALL));\r
 \r
   DEBUG ((EFI_D_INFO, "BootScriptExecuteStall - 0x%08x\n", (UINTN)Stall.Duration));\r
@@ -1089,8 +1083,8 @@ BootScriptExecuteStall (
 }\r
 /**\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
+\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
@@ -1101,7 +1095,7 @@ BootScriptExecuteDispatch (
   EFI_STATUS                Status;\r
   DISPATCH_ENTRYPOINT_FUNC  EntryFunc;\r
   EFI_BOOT_SCRIPT_DISPATCH  ScriptDispatch;\r
-  \r
+\r
   CopyMem ((VOID*)&ScriptDispatch, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_DISPATCH));\r
   EntryFunc = (DISPATCH_ENTRYPOINT_FUNC) (UINTN) (ScriptDispatch.EntryPoint);\r
 \r
@@ -1114,7 +1108,7 @@ BootScriptExecuteDispatch (
 /**\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
+  @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
@@ -1125,11 +1119,11 @@ BootScriptExecuteDispatch2 (
   EFI_STATUS                Status;\r
   DISPATCH_ENTRYPOINT_FUNC  EntryFunc;\r
   EFI_BOOT_SCRIPT_DISPATCH_2  ScriptDispatch2;\r
-  \r
+\r
   CopyMem ((VOID*)&ScriptDispatch2, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_DISPATCH_2));\r
 \r
   DEBUG ((EFI_D_INFO, "BootScriptExecuteDispatch2 - 0x%08x(0x%08x)\n", (UINTN)ScriptDispatch2.EntryPoint, (UINTN)ScriptDispatch2.Context));\r
-  \r
+\r
   EntryFunc = (DISPATCH_ENTRYPOINT_FUNC) (UINTN) (ScriptDispatch2.EntryPoint);\r
 \r
   Status    = EntryFunc (NULL, (VOID *) (UINTN) ScriptDispatch2.Context);\r
@@ -1139,11 +1133,11 @@ BootScriptExecuteDispatch2 (
 /**\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  Script  The pointer of typed node in boot script table\r
   @param  AndMask  Mask value for 'and' operation\r
   @param  OrMask   Mask value for 'or' operation\r
-  \r
-  @retval EFI_DEVICE_ERROR Data polled from memory does not equal to \r
+\r
+  @retval EFI_DEVICE_ERROR Data polled from memory does not equal to\r
                            the epecting data within the Loop Times.\r
   @retval EFI_SUCCESS      The operation was executed successfully\r
 **/\r
@@ -1151,15 +1145,15 @@ EFI_STATUS
 BootScriptExecuteMemPoll (\r
   IN UINT8                        *Script,\r
   IN UINT64                        AndMask,\r
-  IN UINT64                        OrMask  \r
+  IN UINT64                        OrMask\r
   )\r
 {\r
-  \r
+\r
   UINT64        Data;\r
   UINT64        LoopTimes;\r
   EFI_STATUS    Status;\r
   EFI_BOOT_SCRIPT_MEM_POLL       MemPoll;\r
-  \r
+\r
   CopyMem ((VOID*)&MemPoll, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_MEM_POLL));\r
 \r
   DEBUG ((EFI_D_INFO, "BootScriptExecuteMemPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)MemPoll.Address, AndMask, OrMask));\r
@@ -1200,8 +1194,8 @@ BootScriptExecuteMemPoll (
   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
\r
+  @param Script       The pointer of node in boot script table\r
+\r
 **/\r
 VOID\r
 BootScriptExecuteInformation (\r
@@ -1226,10 +1220,10 @@ BootScriptExecuteInformation (
 }\r
 \r
 /**\r
-  Execute the boot script to interpret the Label information. \r
+  Execute the boot script to interpret the Label information.\r
+\r
+  @param Script       The pointer of node in boot script table\r
 \r
-  @param Script       The pointer of node in boot script table \r
\r
 **/\r
 VOID\r
 BootScriptExecuteLabel (\r
@@ -1255,7 +1249,7 @@ BootScriptExecuteLabel (
 \r
 /**\r
   calculate the mask value for 'and' and 'or' operation\r
-  @param ScriptHeader   The pointer of header of node in boot script table \r
+  @param ScriptHeader   The pointer of header of node in boot script table\r
   @param AndMask  The Mask value for 'and' operation\r
   @param OrMask   The Mask value for 'or' operation\r
   @param Script   Pointer to the entry.\r
@@ -1287,32 +1281,32 @@ CheckAndOrMask (
   case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE:\r
     Size = sizeof (EFI_BOOT_SCRIPT_MEM_POLL);\r
     break;\r
-  \r
+\r
   case EFI_BOOT_SCRIPT_IO_POLL_OPCODE:\r
     Size = sizeof (EFI_BOOT_SCRIPT_IO_POLL);\r
-    break;    \r
-  \r
+    break;\r
+\r
   case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE:\r
     Size = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE);\r
     break;\r
-  \r
+\r
   case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:\r
     Size = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL);\r
     break;\r
-  \r
+\r
   case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE:\r
     Size = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL);\r
     break;\r
-  \r
+\r
   default:\r
     return;\r
   }\r
-  \r
+\r
   DataPtr = Script + Size;\r
 \r
   switch (ScriptHeader->Width) {\r
   case S3BootScriptWidthUint8:\r
-    *AndMask  = (UINT64) *(DataPtr + 1);\r
+    *AndMask  = (UINT64) (*(UINT8*) (DataPtr + 1));\r
     *OrMask   = (UINT64) (*DataPtr);\r
     break;\r
 \r
@@ -1340,11 +1334,11 @@ CheckAndOrMask (
 /**\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  Script  The pointer of typed node in boot script table\r
   @param  AndMask  Mask value for 'and' operation\r
   @param  OrMask   Mask value for 'or' operation\r
-  \r
-  @retval EFI_DEVICE_ERROR Data polled from memory does not equal to \r
+\r
+  @retval EFI_DEVICE_ERROR Data polled from memory does not equal to\r
                            the epecting data within the Loop Times.\r
   @retval EFI_SUCCESS      The operation was executed successfully\r
 **/\r
@@ -1359,7 +1353,7 @@ BootScriptExecuteIoPoll (
   UINT64        Data;\r
   UINT64        LoopTimes;\r
   EFI_BOOT_SCRIPT_IO_POLL       IoPoll;\r
-  \r
+\r
   CopyMem ((VOID*)&IoPoll, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_IO_POLL));\r
 \r
   DEBUG ((EFI_D_INFO, "BootScriptExecuteIoPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)IoPoll.Address, AndMask, OrMask));\r
@@ -1385,7 +1379,7 @@ BootScriptExecuteIoPoll (
                );\r
     if ((!EFI_ERROR (Status)) &&(Data & AndMask) == OrMask) {\r
       return EFI_SUCCESS;\r
-    } \r
+    }\r
   }\r
 \r
   if (LoopTimes < IoPoll.Delay) {\r
@@ -1413,7 +1407,7 @@ BootScriptExecutePciCfg2Write (
   UINT64                            Address;\r
   UINTN                             Count;\r
   EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE PciCfg2Write;\r
-  \r
+\r
   CopyMem ((VOID*)&PciCfg2Write, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE));\r
 \r
   Width   = (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfg2Write.Width;\r
@@ -1422,14 +1416,14 @@ BootScriptExecutePciCfg2Write (
   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
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfg2Write - 0x%016lx, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (Segment, Address), Count, (UINTN)Width));\r
   return ScriptPciCfg2Write (Width, Segment, Address, Count, Buffer);\r
 }\r
 \r
 \r
 /**\r
   Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE OP code.\r
-  \r
+\r
   @param     Script                     The pointer of S3 boot script\r
   @param     AndMask                    Mask value for 'and' operation\r
   @param     OrMask                     Mask value for 'or' operation\r
@@ -1452,8 +1446,8 @@ BootScriptExecutePciCfg2ReadWrite (
 \r
   CopyMem ((VOID*)&PciCfg2ReadWrite, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE));\r
 \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
+  DEBUG ((EFI_D_INFO, "BootScriptExecutePciCfg2ReadWrite - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfg2ReadWrite.Segment, PciCfg2ReadWrite.Address), AndMask, OrMask));\r
+\r
   Status = ScriptPciCfg2Read (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2ReadWrite.Width,\r
              PciCfg2ReadWrite.Segment,\r
@@ -1477,20 +1471,20 @@ BootScriptExecutePciCfg2ReadWrite (
 }\r
 /**\r
   Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_POLL OP code.\r
-  \r
+\r
   @param     Script                     The pointer of S3 boot script\r
   @param     AndMask                    Mask value for 'and' operation\r
   @param     OrMask                     Mask value for 'or' operation\r
 \r
   @retval    EFI_SUCCESS                The operation was executed successfully\r
-  @retval    EFI_DEVICE_ERROR           Data polled from Pci configuration space does not equal to \r
+  @retval    EFI_DEVICE_ERROR           Data polled from Pci configuration space does not equal to\r
                                         epecting data within the Loop Times.\r
 **/\r
 EFI_STATUS\r
 BootScriptPciCfgPoll (\r
   IN UINT8                         *Script,\r
   IN UINT64                        AndMask,\r
-  IN UINT64                        OrMask  \r
+  IN UINT64                        OrMask\r
   )\r
 {\r
   UINT64        Data;\r
@@ -1499,8 +1493,8 @@ 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, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfgPoll.Address), AndMask, OrMask));\r
-  \r
+  DEBUG ((EFI_D_INFO, "BootScriptPciCfgPoll - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (0, PciCfgPoll.Address), AndMask, OrMask));\r
+\r
   Data = 0;\r
   Status = ScriptPciCfgRead (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfgPoll.Width,\r
@@ -1536,13 +1530,13 @@ BootScriptPciCfgPoll (
 \r
 /**\r
   Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL OP code.\r
-  \r
+\r
   @param     Script                     The pointer of S3 Boot Script\r
   @param     AndMask                    Mask value for 'and' operation\r
   @param     OrMask                     Mask value for 'or' operation\r
 \r
   @retval    EFI_SUCCESS                The operation was executed successfully\r
-  @retval    EFI_DEVICE_ERROR           Data polled from Pci configuration space does not equal to \r
+  @retval    EFI_DEVICE_ERROR           Data polled from Pci configuration space does not equal to\r
                                         epecting data within the Loop Times.\r
 \r
 **/\r
@@ -1550,7 +1544,7 @@ EFI_STATUS
 BootScriptPciCfg2Poll (\r
   IN UINT8                        *Script,\r
   IN UINT64                        AndMask,\r
-  IN UINT64                        OrMask  \r
+  IN UINT64                        OrMask\r
   )\r
 {\r
   EFI_STATUS    Status;\r
@@ -1561,8 +1555,8 @@ BootScriptPciCfg2Poll (
   Data = 0;\r
   CopyMem ((VOID*)&PciCfg2Poll, (VOID*)Script, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL));\r
 \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
+  DEBUG ((EFI_D_INFO, "BootScriptPciCfg2Poll - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfg2Poll.Segment, PciCfg2Poll.Address), AndMask, OrMask));\r
+\r
   Status = ScriptPciCfg2Read (\r
              (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2Poll.Width,\r
              PciCfg2Poll.Segment,\r
@@ -1580,7 +1574,7 @@ BootScriptPciCfg2Poll (
     Data = 0;\r
     Status = ScriptPciCfg2Read (\r
                (S3_BOOT_SCRIPT_LIB_WIDTH) PciCfg2Poll.Width,\r
-               PciCfg2Poll.Segment,               \r
+               PciCfg2Poll.Segment,\r
                PciCfg2Poll.Address,\r
                1,\r
                &Data\r
@@ -1595,18 +1589,15 @@ BootScriptPciCfg2Poll (
   } else {\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
+\r
 }\r
 \r
 /**\r
   Executes the S3 boot script table.\r
\r
+\r
   @retval RETURN_SUCCESS           The boot script table was executed successfully.\r
-  @retval RETURN_UNSUPPORTED       Invalid script table or opcode.  \r
-  \r
-  @note  A known Limitations in the implementation: When interpreting the opcode  EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE\r
-         EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as \r
-         Zero, or else, assert.\r
+  @retval RETURN_UNSUPPORTED       Invalid script table or opcode.\r
+\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -1623,7 +1614,7 @@ S3BootScriptExecute (
   EFI_BOOT_SCRIPT_COMMON_HEADER  ScriptHeader;\r
   EFI_BOOT_SCRIPT_TABLE_HEADER   TableHeader;\r
   Script = mS3BootScriptTablePtr->TableBase;\r
-  if (Script != 0) {    \r
+  if (Script != 0) {\r
     CopyMem ((VOID*)&TableHeader, Script, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r
   } else {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1635,7 +1626,7 @@ S3BootScriptExecute (
   }\r
 \r
   DEBUG ((EFI_D_INFO, "TableHeader - 0x%08x\n", Script));\r
-  \r
+\r
   StartAddress  = (UINTN) Script;\r
   TableLength   = TableHeader.TableLength;\r
   Script    =    Script + TableHeader.Length;\r
@@ -1643,11 +1634,12 @@ S3BootScriptExecute (
   AndMask       = 0;\r
   OrMask        = 0;\r
 \r
+  DEBUG ((EFI_D_INFO, "TableHeader.Version - 0x%04x\n", (UINTN)TableHeader.Version));\r
   DEBUG ((EFI_D_INFO, "TableHeader.TableLength - 0x%08x\n", (UINTN)TableLength));\r
 \r
   while ((UINTN) Script < (UINTN) (StartAddress + TableLength)) {\r
     DEBUG ((EFI_D_INFO, "ExecuteBootScript - %08x\n", (UINTN)Script));\r
-    \r
+\r
     CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER));\r
     switch (ScriptHeader.OpCode) {\r
 \r
@@ -1712,7 +1704,7 @@ S3BootScriptExecute (
     case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r
       DEBUG ((EFI_D_INFO, "EFI_BOOT_SCRIPT_INFORMATION_OPCODE\n"));\r
       BootScriptExecuteInformation (Script);\r
-      break;    \r
+      break;\r
 \r
     case S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE:\r
       DEBUG ((EFI_D_INFO, "S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE\n"));\r
@@ -1743,21 +1735,21 @@ S3BootScriptExecute (
       DEBUG ((EFI_D_INFO, "EFI_BOOT_SCRIPT_MEM_POLL_OPCODE\n"));\r
       CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
       Status = BootScriptExecuteMemPoll (Script, AndMask, OrMask);\r
-      \r
+\r
       break;\r
-    \r
+\r
     case EFI_BOOT_SCRIPT_IO_POLL_OPCODE:\r
       DEBUG ((EFI_D_INFO, "EFI_BOOT_SCRIPT_IO_POLL_OPCODE\n"));\r
       CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
       Status = BootScriptExecuteIoPoll (Script, AndMask, OrMask);\r
       break;\r
-      \r
+\r
     case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE:\r
       DEBUG ((EFI_D_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE\n"));\r
       CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
       Status = BootScriptPciCfgPoll (Script, AndMask, OrMask);\r
       break;\r
-      \r
+\r
     case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:\r
      DEBUG ((EFI_D_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE\n"));\r
      CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r