Home | History | Annotate | Download | only in BaseS3IoLib
      1 /** @file
      2   I/O and MMIO Library Services that do I/O and also enable the I/O operatation
      3   to be replayed during an S3 resume.
      4 
      5   Copyright (c) 2006 -2012, Intel Corporation. All rights reserved.<BR>
      6 
      7   This program and the accompanying materials
      8   are licensed and made available under the terms and conditions
      9   of the BSD License which accompanies this distribution.  The
     10   full text of the license may be found at
     11   http://opensource.org/licenses/bsd-license.php
     12 
     13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     14   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     15 
     16 **/
     17 
     18 #include <Base.h>
     19 
     20 #include <Library/S3IoLib.h>
     21 #include <Library/DebugLib.h>
     22 #include <Library/IoLib.h>
     23 #include <Library/S3BootScriptLib.h>
     24 
     25 
     26 /**
     27   Saves an I/O port value to the boot script.
     28 
     29   This internal worker function saves an I/O port value in the S3 script
     30   to be replayed on S3 resume.
     31 
     32   If the saving process fails, then ASSERT().
     33 
     34   @param  Width         The width of I/O port.
     35   @param  Port          The I/O port to write.
     36   @param  Buffer        The buffer containing value.
     37 
     38 **/
     39 VOID
     40 InternalSaveIoWriteValueToBootScript (
     41   IN S3_BOOT_SCRIPT_LIB_WIDTH  Width,
     42   IN UINTN                  Port,
     43   IN VOID                   *Buffer
     44   )
     45 {
     46   RETURN_STATUS                Status;
     47 
     48   Status = S3BootScriptSaveIoWrite (
     49              Width,
     50              Port,
     51              1,
     52              Buffer
     53              );
     54   ASSERT (Status == RETURN_SUCCESS);
     55 }
     56 
     57 /**
     58   Saves an 8-bit I/O port value to the boot script.
     59 
     60   This internal worker function saves an 8-bit I/O port value in the S3 script
     61   to be replayed on S3 resume.
     62 
     63   If the saving process fails, then ASSERT().
     64 
     65   @param  Port          The I/O port to write.
     66   @param  Value         The value saved to boot script.
     67 
     68   @return Value.
     69 
     70 **/
     71 UINT8
     72 InternalSaveIoWrite8ValueToBootScript (
     73   IN UINTN              Port,
     74   IN UINT8              Value
     75   )
     76 {
     77   InternalSaveIoWriteValueToBootScript (S3BootScriptWidthUint8, Port, &Value);
     78 
     79   return Value;
     80 }
     81 
     82 /**
     83   Reads an 8-bit I/O port and saves the value in the S3 script to be replayed
     84   on S3 resume.
     85 
     86   Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
     87   This function must guarantee that all I/O read and write operations are
     88   serialized.
     89 
     90   If 8-bit I/O port operations are not supported, then ASSERT().
     91 
     92   @param  Port          The I/O port to read.
     93 
     94   @return The value read.
     95 
     96 **/
     97 UINT8
     98 EFIAPI
     99 S3IoRead8 (
    100   IN UINTN              Port
    101   )
    102 {
    103   return InternalSaveIoWrite8ValueToBootScript (Port, IoRead8 (Port));
    104 }
    105 
    106 /**
    107   Writes an 8-bit I/O port and saves the value in the S3 script to be replayed
    108   on S3 resume.
    109 
    110   Writes the 8-bit I/O port specified by Port with the value specified by Value
    111   and returns Value. This function must guarantee that all I/O read and write
    112   operations are serialized.
    113 
    114   If 8-bit I/O port operations are not supported, then ASSERT().
    115 
    116   @param  Port          The I/O port to write.
    117   @param  Value         The value to write to the I/O port.
    118 
    119   @return The value written the I/O port.
    120 
    121 **/
    122 UINT8
    123 EFIAPI
    124 S3IoWrite8 (
    125   IN UINTN              Port,
    126   IN UINT8              Value
    127   )
    128 {
    129   return InternalSaveIoWrite8ValueToBootScript (Port, IoWrite8 (Port, Value));
    130 }
    131 
    132 /**
    133   Reads an 8-bit I/O port, performs a bitwise OR, and writes the
    134   result back to the 8-bit I/O port and saves the value in the S3 script to be
    135   replayed on S3 resume.
    136 
    137   Reads the 8-bit I/O port specified by Port, performs a bitwise OR
    138   between the read result and the value specified by OrData, and writes the
    139   result to the 8-bit I/O port specified by Port. The value written to the I/O
    140   port is returned. This function must guarantee that all I/O read and write
    141   operations are serialized.
    142 
    143   If 8-bit I/O port operations are not supported, then ASSERT().
    144 
    145   @param  Port          The I/O port to write.
    146   @param  OrData        The value to OR with the read value from the I/O port.
    147 
    148   @return The value written back to the I/O port.
    149 
    150 **/
    151 UINT8
    152 EFIAPI
    153 S3IoOr8 (
    154   IN UINTN              Port,
    155   IN UINT8              OrData
    156   )
    157 {
    158   return InternalSaveIoWrite8ValueToBootScript (Port, IoOr8 (Port, OrData));
    159 }
    160 
    161 /**
    162   Reads an 8-bit I/O port, performs a bitwise AND, and writes the result back
    163   to the 8-bit I/O port  and saves the value in the S3 script to be replayed
    164   on S3 resume.
    165 
    166   Reads the 8-bit I/O port specified by Port, performs a bitwise AND between
    167   the read result and the value specified by AndData, and writes the result to
    168   the 8-bit I/O port specified by Port. The value written to the I/O port is
    169   returned. This function must guarantee that all I/O read and write operations
    170   are serialized.
    171 
    172   If 8-bit I/O port operations are not supported, then ASSERT().
    173 
    174   @param  Port          The I/O port to write.
    175   @param  AndData       The value to AND with the read value from the I/O port.
    176 
    177   @return The value written back to the I/O port.
    178 
    179 **/
    180 UINT8
    181 EFIAPI
    182 S3IoAnd8 (
    183   IN UINTN              Port,
    184   IN UINT8              AndData
    185   )
    186 {
    187   return InternalSaveIoWrite8ValueToBootScript (Port, IoAnd8 (Port, AndData));
    188 }
    189 
    190 /**
    191   Reads an 8-bit I/O port, performs a bitwise AND followed by a bitwise
    192   inclusive OR, and writes the result back to the 8-bit I/O port and saves
    193   the value in the S3 script to be replayed on S3 resume.
    194 
    195   Reads the 8-bit I/O port specified by Port, performs a bitwise AND between
    196   the read result and the value specified by AndData, performs a bitwise OR
    197   between the result of the AND operation and the value specified by OrData,
    198   and writes the result to the 8-bit I/O port specified by Port. The value
    199   written to the I/O port is returned. This function must guarantee that all
    200   I/O read and write operations are serialized.
    201 
    202   If 8-bit I/O port operations are not supported, then ASSERT().
    203 
    204   @param  Port          The I/O port to write.
    205   @param  AndData       The value to AND with the read value from the I/O port.
    206   @param  OrData        The value to OR with the result of the AND operation.
    207 
    208   @return The value written back to the I/O port.
    209 
    210 **/
    211 UINT8
    212 EFIAPI
    213 S3IoAndThenOr8 (
    214   IN UINTN              Port,
    215   IN UINT8              AndData,
    216   IN UINT8              OrData
    217   )
    218 {
    219   return InternalSaveIoWrite8ValueToBootScript (Port, IoAndThenOr8 (Port, AndData, OrData));
    220 }
    221 
    222 /**
    223   Reads a bit field of an I/O register and saves the value in the S3 script to
    224   be replayed on S3 resume.
    225 
    226   Reads the bit field in an 8-bit I/O register. The bit field is specified by
    227   the StartBit and the EndBit. The value of the bit field is returned.
    228 
    229   If 8-bit I/O port operations are not supported, then ASSERT().
    230   If StartBit is greater than 7, then ASSERT().
    231   If EndBit is greater than 7, then ASSERT().
    232   If EndBit is less than StartBit, then ASSERT().
    233 
    234   @param  Port          The I/O port to read.
    235   @param  StartBit      The ordinal of the least significant bit in the bit field.
    236                         Range 0..7.
    237   @param  EndBit        The ordinal of the most significant bit in the bit field.
    238                         Range 0..7.
    239 
    240   @return The value read.
    241 
    242 **/
    243 UINT8
    244 EFIAPI
    245 S3IoBitFieldRead8 (
    246   IN UINTN              Port,
    247   IN UINTN              StartBit,
    248   IN UINTN              EndBit
    249   )
    250 {
    251   return InternalSaveIoWrite8ValueToBootScript (Port, IoBitFieldRead8 (Port, StartBit, EndBit));
    252 }
    253 
    254 /**
    255   Writes a bit field to an I/O register and saves the value in the S3 script to
    256   be replayed on S3 resume.
    257 
    258   Writes Value to the bit field of the I/O register. The bit field is specified
    259   by the StartBit and the EndBit. All other bits in the destination I/O
    260   register are preserved. The value written to the I/O port is returned. Extra
    261   left bits in Value are stripped.
    262 
    263   If 8-bit I/O port operations are not supported, then ASSERT().
    264   If StartBit is greater than 7, then ASSERT().
    265   If EndBit is greater than 7, then ASSERT().
    266   If EndBit is less than StartBit, then ASSERT().
    267   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    268 
    269   @param  Port          The I/O port to write.
    270   @param  StartBit      The ordinal of the least significant bit in the bit field.
    271                         Range 0..7.
    272   @param  EndBit        The ordinal of the most significant bit in the bit field.
    273                         Range 0..7.
    274   @param  Value         New value of the bit field.
    275 
    276   @return The value written back to the I/O port.
    277 
    278 **/
    279 UINT8
    280 EFIAPI
    281 S3IoBitFieldWrite8 (
    282   IN UINTN              Port,
    283   IN UINTN              StartBit,
    284   IN UINTN              EndBit,
    285   IN UINT8              Value
    286   )
    287 {
    288   return InternalSaveIoWrite8ValueToBootScript (Port, IoBitFieldWrite8 (Port, StartBit, EndBit, Value));
    289 }
    290 
    291 /**
    292   Reads a bit field in an 8-bit port, performs a bitwise OR, and writes the
    293   result back to the bit field in the 8-bit port and saves the value in the
    294   S3 script to be replayed on S3 resume.
    295 
    296   Reads the 8-bit I/O port specified by Port, performs a bitwise OR
    297   between the read result and the value specified by OrData, and writes the
    298   result to the 8-bit I/O port specified by Port. The value written to the I/O
    299   port is returned. This function must guarantee that all I/O read and write
    300   operations are serialized. Extra left bits in OrData are stripped.
    301 
    302   If 8-bit I/O port operations are not supported, then ASSERT().
    303   If StartBit is greater than 7, then ASSERT().
    304   If EndBit is greater than 7, then ASSERT().
    305   If EndBit is less than StartBit, then ASSERT().
    306   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    307 
    308   @param  Port          The I/O port to write.
    309   @param  StartBit      The ordinal of the least significant bit in the bit field.
    310                         Range 0..7.
    311   @param  EndBit        The ordinal of the most significant bit in the bit field.
    312                         Range 0..7.
    313   @param  OrData        The value to OR with the read value from the I/O port.
    314 
    315   @return The value written back to the I/O port.
    316 
    317 **/
    318 UINT8
    319 EFIAPI
    320 S3IoBitFieldOr8 (
    321   IN UINTN              Port,
    322   IN UINTN              StartBit,
    323   IN UINTN              EndBit,
    324   IN UINT8              OrData
    325   )
    326 {
    327   return InternalSaveIoWrite8ValueToBootScript (Port, IoBitFieldOr8 (Port, StartBit, EndBit, OrData));
    328 }
    329 
    330 /**
    331   Reads a bit field in an 8-bit port, performs a bitwise AND, and writes the
    332   result back to the bit field in the 8-bit port  and saves the value in the
    333   S3 script to be replayed on S3 resume.
    334 
    335   Reads the 8-bit I/O port specified by Port, performs a bitwise AND between
    336   the read result and the value specified by AndData, and writes the result to
    337   the 8-bit I/O port specified by Port. The value written to the I/O port is
    338   returned. This function must guarantee that all I/O read and write operations
    339   are serialized. Extra left bits in AndData are stripped.
    340 
    341   If 8-bit I/O port operations are not supported, then ASSERT().
    342   If StartBit is greater than 7, then ASSERT().
    343   If EndBit is greater than 7, then ASSERT().
    344   If EndBit is less than StartBit, then ASSERT().
    345   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    346 
    347   @param  Port          The I/O port to write.
    348   @param  StartBit      The ordinal of the least significant bit in the bit field.
    349                         Range 0..7.
    350   @param  EndBit        The ordinal of the most significant bit in the bit field.
    351                         Range 0..7.
    352   @param  AndData       The value to AND with the read value from the I/O port.
    353 
    354   @return The value written back to the I/O port.
    355 
    356 **/
    357 UINT8
    358 EFIAPI
    359 S3IoBitFieldAnd8 (
    360   IN UINTN              Port,
    361   IN UINTN              StartBit,
    362   IN UINTN              EndBit,
    363   IN UINT8              AndData
    364   )
    365 {
    366   return InternalSaveIoWrite8ValueToBootScript (Port, IoBitFieldAnd8 (Port, StartBit, EndBit, AndData));
    367 }
    368 
    369 /**
    370   Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
    371   bitwise OR, and writes the result back to the bit field in the
    372   8-bit port and saves the value in the S3 script to be replayed on S3 resume.
    373 
    374   Reads the 8-bit I/O port specified by Port, performs a bitwise AND followed
    375   by a bitwise OR between the read result and the value specified by
    376   AndData, and writes the result to the 8-bit I/O port specified by Port. The
    377   value written to the I/O port is returned. This function must guarantee that
    378   all I/O read and write operations are serialized. Extra left bits in both
    379   AndData and OrData are stripped.
    380 
    381   If 8-bit I/O port operations are not supported, then ASSERT().
    382   If StartBit is greater than 7, then ASSERT().
    383   If EndBit is greater than 7, then ASSERT().
    384   If EndBit is less than StartBit, then ASSERT().
    385   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    386   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    387 
    388   @param  Port          The I/O port to write.
    389   @param  StartBit      The ordinal of the least significant bit in the bit field.
    390                         Range 0..7.
    391   @param  EndBit        The ordinal of the most significant bit in the bit field.
    392                         Range 0..7.
    393   @param  AndData       The value to AND with the read value from the I/O port.
    394   @param  OrData        The value to OR with the result of the AND operation.
    395 
    396   @return The value written back to the I/O port.
    397 
    398 **/
    399 UINT8
    400 EFIAPI
    401 S3IoBitFieldAndThenOr8 (
    402   IN UINTN              Port,
    403   IN UINTN              StartBit,
    404   IN UINTN              EndBit,
    405   IN UINT8              AndData,
    406   IN UINT8              OrData
    407   )
    408 {
    409   return InternalSaveIoWrite8ValueToBootScript (Port, IoBitFieldAndThenOr8 (Port, StartBit, EndBit, AndData, OrData));
    410 }
    411 
    412 /**
    413   Saves a 16-bit I/O port value to the boot script.
    414 
    415   This internal worker function saves a 16-bit I/O port value in the S3 script
    416   to be replayed on S3 resume.
    417 
    418   If the saving process fails, then ASSERT().
    419 
    420   @param  Port          The I/O port to write.
    421   @param  Value         The value saved to boot script.
    422 
    423   @return Value.
    424 
    425 **/
    426 UINT16
    427 InternalSaveIoWrite16ValueToBootScript (
    428   IN UINTN              Port,
    429   IN UINT16             Value
    430   )
    431 {
    432   InternalSaveIoWriteValueToBootScript (S3BootScriptWidthUint16, Port, &Value);
    433 
    434   return Value;
    435 }
    436 
    437 /**
    438   Reads a 16-bit I/O port and saves the value in the S3 script to be replayed
    439   on S3 resume.
    440 
    441   Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
    442   This function must guarantee that all I/O read and write operations are
    443   serialized.
    444 
    445   If 16-bit I/O port operations are not supported, then ASSERT().
    446 
    447   @param  Port          The I/O port to read.
    448 
    449   @return The value read.
    450 
    451 **/
    452 UINT16
    453 EFIAPI
    454 S3IoRead16 (
    455   IN UINTN              Port
    456   )
    457 {
    458   return InternalSaveIoWrite16ValueToBootScript (Port, IoRead16 (Port));
    459 }
    460 
    461 /**
    462   Writes a 16-bit I/O port and saves the value in the S3 script to be replayed
    463   on S3 resume.
    464 
    465   Writes the 16-bit I/O port specified by Port with the value specified by Value
    466   and returns Value. This function must guarantee that all I/O read and write
    467   operations are serialized.
    468 
    469   If 16-bit I/O port operations are not supported, then ASSERT().
    470 
    471   @param  Port          The I/O port to write.
    472   @param  Value         The value to write to the I/O port.
    473 
    474   @return The value written the I/O port.
    475 
    476 **/
    477 UINT16
    478 EFIAPI
    479 S3IoWrite16 (
    480   IN UINTN              Port,
    481   IN UINT16             Value
    482   )
    483 {
    484   return InternalSaveIoWrite16ValueToBootScript (Port, IoWrite16 (Port, Value));
    485 }
    486 
    487 /**
    488   Reads a 16-bit I/O port, performs a bitwise OR, and writes the
    489   result back to the 16-bit I/O port and saves the value in the S3 script to
    490   be replayed on S3 resume.
    491 
    492   Reads the 16-bit I/O port specified by Port, performs a bitwise OR
    493   between the read result and the value specified by OrData, and writes the
    494   result to the 16-bit I/O port specified by Port. The value written to the I/O
    495   port is returned. This function must guarantee that all I/O read and write
    496   operations are serialized.
    497 
    498   If 16-bit I/O port operations are not supported, then ASSERT().
    499 
    500   @param  Port          The I/O port to write.
    501   @param  OrData        The value to OR with the read value from the I/O port.
    502 
    503   @return The value written back to the I/O port.
    504 
    505 **/
    506 UINT16
    507 EFIAPI
    508 S3IoOr16 (
    509   IN UINTN              Port,
    510   IN UINT16             OrData
    511   )
    512 {
    513   return InternalSaveIoWrite16ValueToBootScript (Port, IoOr16 (Port, OrData));
    514 }
    515 
    516 /**
    517   Reads a 16-bit I/O port, performs a bitwise AND, and writes the result back
    518   to the 16-bit I/O port  and saves the value in the S3 script to be replayed
    519   on S3 resume.
    520 
    521   Reads the 16-bit I/O port specified by Port, performs a bitwise AND between
    522   the read result and the value specified by AndData, and writes the result to
    523   the 16-bit I/O port specified by Port. The value written to the I/O port is
    524   returned. This function must guarantee that all I/O read and write operations
    525   are serialized.
    526 
    527   If 16-bit I/O port operations are not supported, then ASSERT().
    528 
    529   @param  Port          The I/O port to write.
    530   @param  AndData       The value to AND with the read value from the I/O port.
    531 
    532   @return The value written back to the I/O port.
    533 
    534 **/
    535 UINT16
    536 EFIAPI
    537 S3IoAnd16 (
    538   IN UINTN              Port,
    539   IN UINT16             AndData
    540   )
    541 {
    542   return InternalSaveIoWrite16ValueToBootScript (Port, IoAnd16 (Port, AndData));
    543 }
    544 
    545 /**
    546   Reads a 16-bit I/O port, performs a bitwise AND followed by a bitwise
    547   inclusive OR, and writes the result back to the 16-bit I/O port and saves
    548   the value in the S3 script to be replayed on S3 resume.
    549 
    550   Reads the 16-bit I/O port specified by Port, performs a bitwise AND between
    551   the read result and the value specified by AndData, performs a bitwise OR
    552   between the result of the AND operation and the value specified by OrData,
    553   and writes the result to the 16-bit I/O port specified by Port. The value
    554   written to the I/O port is returned. This function must guarantee that all
    555   I/O read and write operations are serialized.
    556 
    557   If 16-bit I/O port operations are not supported, then ASSERT().
    558 
    559   @param  Port          The I/O port to write.
    560   @param  AndData       The value to AND with the read value from the I/O port.
    561   @param  OrData        The value to OR with the result of the AND operation.
    562 
    563   @return The value written back to the I/O port.
    564 
    565 **/
    566 UINT16
    567 EFIAPI
    568 S3IoAndThenOr16 (
    569   IN UINTN              Port,
    570   IN UINT16             AndData,
    571   IN UINT16             OrData
    572   )
    573 {
    574   return InternalSaveIoWrite16ValueToBootScript (Port, IoAndThenOr16 (Port, AndData, OrData));
    575 }
    576 
    577 /**
    578   Reads a bit field of an I/O register saves the value in the S3 script to be
    579   replayed on S3 resume.
    580 
    581   Reads the bit field in a 16-bit I/O register. The bit field is specified by
    582   the StartBit and the EndBit. The value of the bit field is returned.
    583 
    584   If 16-bit I/O port operations are not supported, then ASSERT().
    585   If StartBit is greater than 15, then ASSERT().
    586   If EndBit is greater than 15, then ASSERT().
    587   If EndBit is less than StartBit, then ASSERT().
    588 
    589   @param  Port          The I/O port to read.
    590   @param  StartBit      The ordinal of the least significant bit in the bit field.
    591                         Range 0..15.
    592   @param  EndBit        The ordinal of the most significant bit in the bit field.
    593                         Range 0..15.
    594 
    595   @return The value read.
    596 
    597 **/
    598 UINT16
    599 EFIAPI
    600 S3IoBitFieldRead16 (
    601   IN UINTN              Port,
    602   IN UINTN              StartBit,
    603   IN UINTN              EndBit
    604   )
    605 {
    606   return InternalSaveIoWrite16ValueToBootScript (Port, IoBitFieldRead16 (Port, StartBit, EndBit));
    607 }
    608 
    609 /**
    610   Writes a bit field to an I/O register and saves the value in the S3 script
    611   to be replayed on S3 resume.
    612 
    613   Writes Value to the bit field of the I/O register. The bit field is specified
    614   by the StartBit and the EndBit. All other bits in the destination I/O
    615   register are preserved. The value written to the I/O port is returned. Extra
    616   left bits in Value are stripped.
    617 
    618   If 16-bit I/O port operations are not supported, then ASSERT().
    619   If StartBit is greater than 15, then ASSERT().
    620   If EndBit is greater than 15, then ASSERT().
    621   If EndBit is less than StartBit, then ASSERT().
    622   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    623 
    624   @param  Port          The I/O port to write.
    625   @param  StartBit      The ordinal of the least significant bit in the bit field.
    626                         Range 0..15.
    627   @param  EndBit        The ordinal of the most significant bit in the bit field.
    628                         Range 0..15.
    629   @param  Value         New value of the bit field.
    630 
    631   @return The value written back to the I/O port.
    632 
    633 **/
    634 UINT16
    635 EFIAPI
    636 S3IoBitFieldWrite16 (
    637   IN UINTN              Port,
    638   IN UINTN              StartBit,
    639   IN UINTN              EndBit,
    640   IN UINT16             Value
    641   )
    642 {
    643   return InternalSaveIoWrite16ValueToBootScript (Port, IoBitFieldWrite16 (Port, StartBit, EndBit, Value));
    644 }
    645 
    646 /**
    647   Reads a bit field in a 16-bit port, performs a bitwise OR, and writes the
    648   result back to the bit field in the 16-bit port and saves the value in the
    649   S3 script to be replayed on S3 resume.
    650 
    651   Reads the 16-bit I/O port specified by Port, performs a bitwise OR
    652   between the read result and the value specified by OrData, and writes the
    653   result to the 16-bit I/O port specified by Port. The value written to the I/O
    654   port is returned. This function must guarantee that all I/O read and write
    655   operations are serialized. Extra left bits in OrData are stripped.
    656 
    657   If 16-bit I/O port operations are not supported, then ASSERT().
    658   If StartBit is greater than 15, then ASSERT().
    659   If EndBit is greater than 15, then ASSERT().
    660   If EndBit is less than StartBit, then ASSERT().
    661   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    662 
    663   @param  Port          The I/O port to write.
    664   @param  StartBit      The ordinal of the least significant bit in the bit field.
    665                         Range 0..15.
    666   @param  EndBit        The ordinal of the most significant bit in the bit field.
    667                         Range 0..15.
    668   @param  OrData        The value to OR with the read value from the I/O port.
    669 
    670   @return The value written back to the I/O port.
    671 
    672 **/
    673 UINT16
    674 EFIAPI
    675 S3IoBitFieldOr16 (
    676   IN UINTN              Port,
    677   IN UINTN              StartBit,
    678   IN UINTN              EndBit,
    679   IN UINT16             OrData
    680   )
    681 {
    682   return InternalSaveIoWrite16ValueToBootScript (Port, IoBitFieldOr16 (Port, StartBit, EndBit, OrData));
    683 }
    684 
    685 /**
    686   Reads a bit field in a 16-bit port, performs a bitwise AND, and writes the
    687   result back to the bit field in the 16-bit port and saves the value in the
    688   S3 script to be replayed on S3 resume.
    689 
    690   Reads the 16-bit I/O port specified by Port, performs a bitwise AND between
    691   the read result and the value specified by AndData, and writes the result to
    692   the 16-bit I/O port specified by Port. The value written to the I/O port is
    693   returned. This function must guarantee that all I/O read and write operations
    694   are serialized. Extra left bits in AndData are stripped.
    695 
    696   If 16-bit I/O port operations are not supported, then ASSERT().
    697   If StartBit is greater than 15, then ASSERT().
    698   If EndBit is greater than 15, then ASSERT().
    699   If EndBit is less than StartBit, then ASSERT().
    700   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    701 
    702   @param  Port          The I/O port to write.
    703   @param  StartBit      The ordinal of the least significant bit in the bit field.
    704                         Range 0..15.
    705   @param  EndBit        The ordinal of the most significant bit in the bit field.
    706                         Range 0..15.
    707   @param  AndData       The value to AND with the read value from the I/O port.
    708 
    709   @return The value written back to the I/O port.
    710 
    711 **/
    712 UINT16
    713 EFIAPI
    714 S3IoBitFieldAnd16 (
    715   IN UINTN              Port,
    716   IN UINTN              StartBit,
    717   IN UINTN              EndBit,
    718   IN UINT16             AndData
    719   )
    720 {
    721   return InternalSaveIoWrite16ValueToBootScript (Port, IoBitFieldAnd16 (Port, StartBit, EndBit, AndData));
    722 }
    723 
    724 /**
    725   Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
    726   bitwise OR, and writes the result back to the bit field in the
    727   16-bit port  and saves the value in the S3 script to be replayed on S3
    728   resume.
    729 
    730   Reads the 16-bit I/O port specified by Port, performs a bitwise AND followed
    731   by a bitwise OR between the read result and the value specified by
    732   AndData, and writes the result to the 16-bit I/O port specified by Port. The
    733   value written to the I/O port is returned. This function must guarantee that
    734   all I/O read and write operations are serialized. Extra left bits in both
    735   AndData and OrData are stripped.
    736 
    737   If 16-bit I/O port operations are not supported, then ASSERT().
    738   If StartBit is greater than 15, then ASSERT().
    739   If EndBit is greater than 15, then ASSERT().
    740   If EndBit is less than StartBit, then ASSERT().
    741   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    742   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    743 
    744   @param  Port          The I/O port to write.
    745   @param  StartBit      The ordinal of the least significant bit in the bit field.
    746                         Range 0..15.
    747   @param  EndBit        The ordinal of the most significant bit in the bit field.
    748                         Range 0..15.
    749   @param  AndData       The value to AND with the read value from the I/O port.
    750   @param  OrData        The value to OR with the result of the AND operation.
    751 
    752   @return The value written back to the I/O port.
    753 
    754 **/
    755 UINT16
    756 EFIAPI
    757 S3IoBitFieldAndThenOr16 (
    758   IN UINTN              Port,
    759   IN UINTN              StartBit,
    760   IN UINTN              EndBit,
    761   IN UINT16             AndData,
    762   IN UINT16             OrData
    763   )
    764 {
    765   return InternalSaveIoWrite16ValueToBootScript (Port, IoBitFieldAndThenOr16 (Port, StartBit, EndBit, AndData, OrData));
    766 }
    767 
    768 /**
    769   Saves a 32-bit I/O port value to the boot script.
    770 
    771   This internal worker function saves a 32-bit I/O port value in the S3 script
    772   to be replayed on S3 resume.
    773 
    774   If the saving process fails, then ASSERT().
    775 
    776   @param  Port          The I/O port to write.
    777   @param  Value         The value saved to boot script.
    778 
    779   @return Value.
    780 
    781 **/
    782 UINT32
    783 InternalSaveIoWrite32ValueToBootScript (
    784   IN UINTN              Port,
    785   IN UINT32             Value
    786   )
    787 {
    788   InternalSaveIoWriteValueToBootScript (S3BootScriptWidthUint32, Port, &Value);
    789 
    790   return Value;
    791 }
    792 
    793 /**
    794   Reads a 32-bit I/O port and saves the value in the S3 script to be replayed
    795   on S3 resume.
    796 
    797   Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
    798   This function must guarantee that all I/O read and write operations are
    799   serialized.
    800 
    801   If 32-bit I/O port operations are not supported, then ASSERT().
    802 
    803   @param  Port          The I/O port to read.
    804 
    805   @return The value read.
    806 
    807 **/
    808 UINT32
    809 EFIAPI
    810 S3IoRead32 (
    811   IN UINTN              Port
    812   )
    813 {
    814   return InternalSaveIoWrite32ValueToBootScript (Port, IoRead32 (Port));
    815 }
    816 
    817 /**
    818   Writes a 32-bit I/O port and saves the value in the S3 script to be replayed
    819   on S3 resume.
    820 
    821   Writes the 32-bit I/O port specified by Port with the value specified by Value
    822   and returns Value. This function must guarantee that all I/O read and write
    823   operations are serialized.
    824 
    825   If 32-bit I/O port operations are not supported, then ASSERT().
    826 
    827   @param  Port          The I/O port to write.
    828   @param  Value         The value to write to the I/O port.
    829 
    830   @return The value written the I/O port.
    831 
    832 **/
    833 UINT32
    834 EFIAPI
    835 S3IoWrite32 (
    836   IN UINTN              Port,
    837   IN UINT32             Value
    838   )
    839 {
    840   return InternalSaveIoWrite32ValueToBootScript (Port, IoWrite32 (Port, Value));
    841 }
    842 
    843 /**
    844   Reads a 32-bit I/O port, performs a bitwise OR, and writes the
    845   result back to the 32-bit I/O port and saves the value in the S3 script to
    846   be replayed on S3 resume.
    847 
    848   Reads the 32-bit I/O port specified by Port, performs a bitwise OR
    849   between the read result and the value specified by OrData, and writes the
    850   result to the 32-bit I/O port specified by Port. The value written to the I/O
    851   port is returned. This function must guarantee that all I/O read and write
    852   operations are serialized.
    853 
    854   If 32-bit I/O port operations are not supported, then ASSERT().
    855 
    856   @param  Port          The I/O port to write.
    857   @param  OrData        The value to OR with the read value from the I/O port.
    858 
    859   @return The value written back to the I/O port.
    860 
    861 **/
    862 UINT32
    863 EFIAPI
    864 S3IoOr32 (
    865   IN UINTN              Port,
    866   IN UINT32             OrData
    867   )
    868 {
    869   return InternalSaveIoWrite32ValueToBootScript (Port, IoOr32 (Port, OrData));
    870 }
    871 
    872 /**
    873   Reads a 32-bit I/O port, performs a bitwise AND, and writes the result back
    874   to the 32-bit I/O port and saves the value in the S3 script to be replayed
    875   on S3 resume.
    876 
    877   Reads the 32-bit I/O port specified by Port, performs a bitwise AND between
    878   the read result and the value specified by AndData, and writes the result to
    879   the 32-bit I/O port specified by Port. The value written to the I/O port is
    880   returned. This function must guarantee that all I/O read and write operations
    881   are serialized.
    882 
    883   If 32-bit I/O port operations are not supported, then ASSERT().
    884 
    885   @param  Port          The I/O port to write.
    886   @param  AndData       The value to AND with the read value from the I/O port.
    887 
    888   @return The value written back to the I/O port.
    889 
    890 **/
    891 UINT32
    892 EFIAPI
    893 S3IoAnd32 (
    894   IN UINTN              Port,
    895   IN UINT32             AndData
    896   )
    897 {
    898   return InternalSaveIoWrite32ValueToBootScript (Port, IoAnd32 (Port, AndData));
    899 }
    900 
    901 /**
    902   Reads a 32-bit I/O port, performs a bitwise AND followed by a bitwise
    903   inclusive OR, and writes the result back to the 32-bit I/O port and saves
    904   the value in the S3 script to be replayed on S3 resume.
    905 
    906   Reads the 32-bit I/O port specified by Port, performs a bitwise AND between
    907   the read result and the value specified by AndData, performs a bitwise OR
    908   between the result of the AND operation and the value specified by OrData,
    909   and writes the result to the 32-bit I/O port specified by Port. The value
    910   written to the I/O port is returned. This function must guarantee that all
    911   I/O read and write operations are serialized.
    912 
    913   If 32-bit I/O port operations are not supported, then ASSERT().
    914 
    915   @param  Port          The I/O port to write.
    916   @param  AndData       The value to AND with the read value from the I/O port.
    917   @param  OrData        The value to OR with the result of the AND operation.
    918 
    919   @return The value written back to the I/O port.
    920 
    921 **/
    922 UINT32
    923 EFIAPI
    924 S3IoAndThenOr32 (
    925   IN UINTN              Port,
    926   IN UINT32             AndData,
    927   IN UINT32             OrData
    928   )
    929 {
    930   return InternalSaveIoWrite32ValueToBootScript (Port, IoAndThenOr32 (Port, AndData, OrData));
    931 }
    932 
    933 /**
    934   Reads a bit field of an I/O register and saves the value in the S3 script to
    935   be replayed on S3 resume.
    936 
    937   Reads the bit field in a 32-bit I/O register. The bit field is specified by
    938   the StartBit and the EndBit. The value of the bit field is returned.
    939 
    940   If 32-bit I/O port operations are not supported, then ASSERT().
    941   If StartBit is greater than 31, then ASSERT().
    942   If EndBit is greater than 31, then ASSERT().
    943   If EndBit is less than StartBit, then ASSERT().
    944 
    945   @param  Port          The I/O port to read.
    946   @param  StartBit      The ordinal of the least significant bit in the bit field.
    947                         Range 0..31.
    948   @param  EndBit        The ordinal of the most significant bit in the bit field.
    949                         Range 0..31.
    950 
    951   @return The value read.
    952 
    953 **/
    954 UINT32
    955 EFIAPI
    956 S3IoBitFieldRead32 (
    957   IN UINTN              Port,
    958   IN UINTN              StartBit,
    959   IN UINTN              EndBit
    960   )
    961 {
    962   return InternalSaveIoWrite32ValueToBootScript (Port, IoBitFieldRead32 (Port, StartBit, EndBit));
    963 }
    964 
    965 /**
    966   Writes a bit field to an I/O register and saves the value in the S3 script to
    967   be replayed on S3 resume.
    968 
    969   Writes Value to the bit field of the I/O register. The bit field is specified
    970   by the StartBit and the EndBit. All other bits in the destination I/O
    971   register are preserved. The value written to the I/O port is returned. Extra
    972   left bits in Value are stripped.
    973 
    974   If 32-bit I/O port operations are not supported, then ASSERT().
    975   If StartBit is greater than 31, then ASSERT().
    976   If EndBit is greater than 31, then ASSERT().
    977   If EndBit is less than StartBit, then ASSERT().
    978   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
    979 
    980   @param  Port          The I/O port to write.
    981   @param  StartBit      The ordinal of the least significant bit in the bit field.
    982                         Range 0..31.
    983   @param  EndBit        The ordinal of the most significant bit in the bit field.
    984                         Range 0..31.
    985   @param  Value         New value of the bit field.
    986 
    987   @return The value written back to the I/O port.
    988 
    989 **/
    990 UINT32
    991 EFIAPI
    992 S3IoBitFieldWrite32 (
    993   IN UINTN              Port,
    994   IN UINTN              StartBit,
    995   IN UINTN              EndBit,
    996   IN UINT32             Value
    997   )
    998 {
    999   return InternalSaveIoWrite32ValueToBootScript (Port, IoBitFieldWrite32 (Port, StartBit, EndBit, Value));
   1000 }
   1001 
   1002 /**
   1003   Reads a bit field in a 32-bit port, performs a bitwise OR, and writes the
   1004   result back to the bit field in the 32-bit port and saves the value in the
   1005   S3 script to be replayed on S3 resume.
   1006 
   1007   Reads the 32-bit I/O port specified by Port, performs a bitwise OR
   1008   between the read result and the value specified by OrData, and writes the
   1009   result to the 32-bit I/O port specified by Port. The value written to the I/O
   1010   port is returned. This function must guarantee that all I/O read and write
   1011   operations are serialized. Extra left bits in OrData are stripped.
   1012 
   1013   If 32-bit I/O port operations are not supported, then ASSERT().
   1014   If StartBit is greater than 31, then ASSERT().
   1015   If EndBit is greater than 31, then ASSERT().
   1016   If EndBit is less than StartBit, then ASSERT().
   1017   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1018 
   1019   @param  Port          The I/O port to write.
   1020   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1021                         Range 0..31.
   1022   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1023                         Range 0..31.
   1024   @param  OrData        The value to OR with the read value from the I/O port.
   1025 
   1026   @return The value written back to the I/O port.
   1027 
   1028 **/
   1029 UINT32
   1030 EFIAPI
   1031 S3IoBitFieldOr32 (
   1032   IN UINTN              Port,
   1033   IN UINTN              StartBit,
   1034   IN UINTN              EndBit,
   1035   IN UINT32             OrData
   1036   )
   1037 {
   1038   return InternalSaveIoWrite32ValueToBootScript (Port, IoBitFieldOr32 (Port, StartBit, EndBit, OrData));
   1039 }
   1040 
   1041 /**
   1042   Reads a bit field in a 32-bit port, performs a bitwise AND, and writes the
   1043   result back to the bit field in the 32-bit port and saves the value in the
   1044   S3 script to be replayed on S3 resume.
   1045 
   1046   Reads the 32-bit I/O port specified by Port, performs a bitwise AND between
   1047   the read result and the value specified by AndData, and writes the result to
   1048   the 32-bit I/O port specified by Port. The value written to the I/O port is
   1049   returned. This function must guarantee that all I/O read and write operations
   1050   are serialized. Extra left bits in AndData are stripped.
   1051 
   1052   If 32-bit I/O port operations are not supported, then ASSERT().
   1053   If StartBit is greater than 31, then ASSERT().
   1054   If EndBit is greater than 31, then ASSERT().
   1055   If EndBit is less than StartBit, then ASSERT().
   1056   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1057 
   1058   @param  Port          The I/O port to write.
   1059   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1060                         Range 0..31.
   1061   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1062                         Range 0..31.
   1063   @param  AndData       The value to AND with the read value from the I/O port.
   1064 
   1065   @return The value written back to the I/O port.
   1066 
   1067 **/
   1068 UINT32
   1069 EFIAPI
   1070 S3IoBitFieldAnd32 (
   1071   IN UINTN              Port,
   1072   IN UINTN              StartBit,
   1073   IN UINTN              EndBit,
   1074   IN UINT32             AndData
   1075   )
   1076 {
   1077   return InternalSaveIoWrite32ValueToBootScript (Port, IoBitFieldAnd32 (Port, StartBit, EndBit, AndData));
   1078 }
   1079 
   1080 /**
   1081   Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
   1082   bitwise OR, and writes the result back to the bit field in the
   1083   32-bit port and saves the value in the S3 script to be replayed on S3
   1084   resume.
   1085 
   1086   Reads the 32-bit I/O port specified by Port, performs a bitwise AND followed
   1087   by a bitwise OR between the read result and the value specified by
   1088   AndData, and writes the result to the 32-bit I/O port specified by Port. The
   1089   value written to the I/O port is returned. This function must guarantee that
   1090   all I/O read and write operations are serialized. Extra left bits in both
   1091   AndData and OrData are stripped.
   1092 
   1093   If 32-bit I/O port operations are not supported, then ASSERT().
   1094   If StartBit is greater than 31, then ASSERT().
   1095   If EndBit is greater than 31, then ASSERT().
   1096   If EndBit is less than StartBit, then ASSERT().
   1097   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1098   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1099 
   1100   @param  Port          The I/O port to write.
   1101   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1102                         Range 0..31.
   1103   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1104                         Range 0..31.
   1105   @param  AndData       The value to AND with the read value from the I/O port.
   1106   @param  OrData        The value to OR with the result of the AND operation.
   1107 
   1108   @return The value written back to the I/O port.
   1109 
   1110 **/
   1111 UINT32
   1112 EFIAPI
   1113 S3IoBitFieldAndThenOr32 (
   1114   IN UINTN              Port,
   1115   IN UINTN              StartBit,
   1116   IN UINTN              EndBit,
   1117   IN UINT32             AndData,
   1118   IN UINT32             OrData
   1119   )
   1120 {
   1121   return InternalSaveIoWrite32ValueToBootScript (Port, IoBitFieldAndThenOr32 (Port, StartBit, EndBit, AndData, OrData));
   1122 }
   1123 
   1124 /**
   1125   Saves a 64-bit I/O port value to the boot script.
   1126 
   1127   This internal worker function saves a 64-bit I/O port value in the S3 script
   1128   to be replayed on S3 resume.
   1129 
   1130   If the saving process fails, then ASSERT().
   1131 
   1132   @param  Port          The I/O port to write.
   1133   @param  Value         The value saved to boot script.
   1134 
   1135   @return Value.
   1136 
   1137 **/
   1138 UINT64
   1139 InternalSaveIoWrite64ValueToBootScript (
   1140   IN UINTN              Port,
   1141   IN UINT64             Value
   1142   )
   1143 {
   1144   InternalSaveIoWriteValueToBootScript (S3BootScriptWidthUint64, Port, &Value);
   1145 
   1146   return Value;
   1147 }
   1148 
   1149 /**
   1150   Reads a 64-bit I/O port and saves the value in the S3 script to be replayed
   1151   on S3 resume.
   1152 
   1153   Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
   1154   This function must guarantee that all I/O read and write operations are
   1155   serialized.
   1156 
   1157   If 64-bit I/O port operations are not supported, then ASSERT().
   1158 
   1159   @param  Port          The I/O port to read.
   1160 
   1161   @return The value read.
   1162 
   1163 **/
   1164 UINT64
   1165 EFIAPI
   1166 S3IoRead64 (
   1167   IN UINTN              Port
   1168   )
   1169 {
   1170   return InternalSaveIoWrite64ValueToBootScript (Port, IoRead64 (Port));
   1171 }
   1172 
   1173 /**
   1174   Writes a 64-bit I/O port and saves the value in the S3 script to be replayed
   1175   on S3 resume.
   1176 
   1177   Writes the 64-bit I/O port specified by Port with the value specified by Value
   1178   and returns Value. This function must guarantee that all I/O read and write
   1179   operations are serialized.
   1180 
   1181   If 64-bit I/O port operations are not supported, then ASSERT().
   1182 
   1183   @param  Port          The I/O port to write.
   1184   @param  Value         The value to write to the I/O port.
   1185 
   1186   @return The value written the I/O port.
   1187 
   1188 **/
   1189 UINT64
   1190 EFIAPI
   1191 S3IoWrite64 (
   1192   IN UINTN              Port,
   1193   IN UINT64             Value
   1194   )
   1195 {
   1196   return InternalSaveIoWrite64ValueToBootScript (Port, IoWrite64 (Port, Value));
   1197 }
   1198 
   1199 /**
   1200   Reads a 64-bit I/O port, performs a bitwise OR, and writes the
   1201   result back to the 64-bit I/O port and saves the value in the S3 script to
   1202   be replayed on S3 resume.
   1203 
   1204   Reads the 64-bit I/O port specified by Port, performs a bitwise OR
   1205   between the read result and the value specified by OrData, and writes the
   1206   result to the 64-bit I/O port specified by Port. The value written to the I/O
   1207   port is returned. This function must guarantee that all I/O read and write
   1208   operations are serialized.
   1209 
   1210   If 64-bit I/O port operations are not supported, then ASSERT().
   1211 
   1212   @param  Port          The I/O port to write.
   1213   @param  OrData        The value to OR with the read value from the I/O port.
   1214 
   1215   @return The value written back to the I/O port.
   1216 
   1217 **/
   1218 UINT64
   1219 EFIAPI
   1220 S3IoOr64 (
   1221   IN UINTN              Port,
   1222   IN UINT64             OrData
   1223   )
   1224 {
   1225   return InternalSaveIoWrite64ValueToBootScript (Port, IoOr64 (Port, OrData));
   1226 }
   1227 
   1228 /**
   1229   Reads a 64-bit I/O port, performs a bitwise AND, and writes the result back
   1230   to the 64-bit I/O port and saves the value in the S3 script to be replayed
   1231   on S3 resume.
   1232 
   1233   Reads the 64-bit I/O port specified by Port, performs a bitwise AND between
   1234   the read result and the value specified by AndData, and writes the result to
   1235   the 64-bit I/O port specified by Port. The value written to the I/O port is
   1236   returned. This function must guarantee that all I/O read and write operations
   1237   are serialized.
   1238 
   1239   If 64-bit I/O port operations are not supported, then ASSERT().
   1240 
   1241   @param  Port          The I/O port to write.
   1242   @param  AndData       The value to AND with the read value from the I/O port.
   1243 
   1244   @return The value written back to the I/O port.
   1245 
   1246 **/
   1247 UINT64
   1248 EFIAPI
   1249 S3IoAnd64 (
   1250   IN UINTN              Port,
   1251   IN UINT64             AndData
   1252   )
   1253 {
   1254   return InternalSaveIoWrite64ValueToBootScript (Port, IoAnd64 (Port, AndData));
   1255 }
   1256 
   1257 /**
   1258   Reads a 64-bit I/O port, performs a bitwise AND followed by a bitwise
   1259   inclusive OR, and writes the result back to the 64-bit I/O port and saves
   1260   the value in the S3 script to be replayed on S3 resume.
   1261 
   1262   Reads the 64-bit I/O port specified by Port, performs a bitwise AND between
   1263   the read result and the value specified by AndData, performs a bitwise OR
   1264   between the result of the AND operation and the value specified by OrData,
   1265   and writes the result to the 64-bit I/O port specified by Port. The value
   1266   written to the I/O port is returned. This function must guarantee that all
   1267   I/O read and write operations are serialized.
   1268 
   1269   If 64-bit I/O port operations are not supported, then ASSERT().
   1270 
   1271   @param  Port          The I/O port to write.
   1272   @param  AndData       The value to AND with the read value from the I/O port.
   1273   @param  OrData        The value to OR with the result of the AND operation.
   1274 
   1275   @return The value written back to the I/O port.
   1276 
   1277 **/
   1278 UINT64
   1279 EFIAPI
   1280 S3IoAndThenOr64 (
   1281   IN UINTN              Port,
   1282   IN UINT64             AndData,
   1283   IN UINT64             OrData
   1284   )
   1285 {
   1286   return InternalSaveIoWrite64ValueToBootScript (Port, IoAndThenOr64 (Port, AndData, OrData));
   1287 }
   1288 
   1289 /**
   1290   Reads a bit field of an I/O register and saves the value in the S3 script to
   1291   be replayed on S3 resume.
   1292 
   1293   Reads the bit field in a 64-bit I/O register. The bit field is specified by
   1294   the StartBit and the EndBit. The value of the bit field is returned.
   1295 
   1296   If 64-bit I/O port operations are not supported, then ASSERT().
   1297   If StartBit is greater than 63, then ASSERT().
   1298   If EndBit is greater than 63, then ASSERT().
   1299   If EndBit is less than StartBit, then ASSERT().
   1300 
   1301   @param  Port          The I/O port to read.
   1302   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1303                         Range 0..63.
   1304   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1305                         Range 0..63.
   1306 
   1307   @return The value read.
   1308 
   1309 **/
   1310 UINT64
   1311 EFIAPI
   1312 S3IoBitFieldRead64 (
   1313   IN UINTN              Port,
   1314   IN UINTN              StartBit,
   1315   IN UINTN              EndBit
   1316   )
   1317 {
   1318   return InternalSaveIoWrite64ValueToBootScript (Port, IoBitFieldRead64 (Port, StartBit, EndBit));
   1319 }
   1320 
   1321 /**
   1322   Writes a bit field to an I/O register and saves the value in the S3 script to
   1323   be replayed on S3 resume.
   1324 
   1325   Writes Value to the bit field of the I/O register. The bit field is specified
   1326   by the StartBit and the EndBit. All other bits in the destination I/O
   1327   register are preserved. The value written to the I/O port is returned. Extra
   1328   left bits in Value are stripped.
   1329 
   1330   If 64-bit I/O port operations are not supported, then ASSERT().
   1331   If StartBit is greater than 63, then ASSERT().
   1332   If EndBit is greater than 63, then ASSERT().
   1333   If EndBit is less than StartBit, then ASSERT().
   1334   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1335 
   1336   @param  Port          The I/O port to write.
   1337   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1338                         Range 0..63.
   1339   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1340                         Range 0..63.
   1341   @param  Value         New value of the bit field.
   1342 
   1343   @return The value written back to the I/O port.
   1344 
   1345 **/
   1346 UINT64
   1347 EFIAPI
   1348 S3IoBitFieldWrite64 (
   1349   IN UINTN              Port,
   1350   IN UINTN              StartBit,
   1351   IN UINTN              EndBit,
   1352   IN UINT64             Value
   1353   )
   1354 {
   1355   return InternalSaveIoWrite64ValueToBootScript (Port, IoBitFieldWrite64 (Port, StartBit, EndBit, Value));
   1356 }
   1357 
   1358 /**
   1359   Reads a bit field in a 64-bit port, performs a bitwise OR, and writes the
   1360   result back to the bit field in the 64-bit port and saves the value in the
   1361   S3 script to be replayed on S3 resume.
   1362 
   1363   Reads the 64-bit I/O port specified by Port, performs a bitwise OR
   1364   between the read result and the value specified by OrData, and writes the
   1365   result to the 64-bit I/O port specified by Port. The value written to the I/O
   1366   port is returned. This function must guarantee that all I/O read and write
   1367   operations are serialized. Extra left bits in OrData are stripped.
   1368 
   1369   If 64-bit I/O port operations are not supported, then ASSERT().
   1370   If StartBit is greater than 63, then ASSERT().
   1371   If EndBit is greater than 63, then ASSERT().
   1372   If EndBit is less than StartBit, then ASSERT().
   1373   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1374 
   1375   @param  Port          The I/O port to write.
   1376   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1377                         Range 0..63.
   1378   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1379                         Range 0..63.
   1380   @param  OrData        The value to OR with the read value from the I/O port.
   1381 
   1382   @return The value written back to the I/O port.
   1383 
   1384 **/
   1385 UINT64
   1386 EFIAPI
   1387 S3IoBitFieldOr64 (
   1388   IN UINTN              Port,
   1389   IN UINTN              StartBit,
   1390   IN UINTN              EndBit,
   1391   IN UINT64             OrData
   1392   )
   1393 {
   1394   return InternalSaveIoWrite64ValueToBootScript (Port, IoBitFieldOr64 (Port, StartBit, EndBit, OrData));
   1395 }
   1396 
   1397 /**
   1398   Reads a bit field in a 64-bit port, performs a bitwise AND, and writes the
   1399   result back to the bit field in the 64-bit port and saves the value in the
   1400   S3 script to be replayed on S3 resume.
   1401 
   1402   Reads the 64-bit I/O port specified by Port, performs a bitwise AND between
   1403   the read result and the value specified by AndData, and writes the result to
   1404   the 64-bit I/O port specified by Port. The value written to the I/O port is
   1405   returned. This function must guarantee that all I/O read and write operations
   1406   are serialized. Extra left bits in AndData are stripped.
   1407 
   1408   If 64-bit I/O port operations are not supported, then ASSERT().
   1409   If StartBit is greater than 63, then ASSERT().
   1410   If EndBit is greater than 63, then ASSERT().
   1411   If EndBit is less than StartBit, then ASSERT().
   1412   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1413 
   1414   @param  Port          The I/O port to write.
   1415   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1416                         Range 0..63.
   1417   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1418                         Range 0..63.
   1419   @param  AndData       The value to AND with the read value from the I/O port.
   1420 
   1421   @return The value written back to the I/O port.
   1422 
   1423 **/
   1424 UINT64
   1425 EFIAPI
   1426 S3IoBitFieldAnd64 (
   1427   IN UINTN              Port,
   1428   IN UINTN              StartBit,
   1429   IN UINTN              EndBit,
   1430   IN UINT64             AndData
   1431   )
   1432 {
   1433   return InternalSaveIoWrite64ValueToBootScript (Port, IoBitFieldAnd64 (Port, StartBit, EndBit, AndData));
   1434 }
   1435 
   1436 /**
   1437   Reads a bit field in a 64-bit port, performs a bitwise AND followed by a
   1438   bitwise OR, and writes the result back to the bit field in the
   1439   64-bit port and saves the value in the S3 script to be replayed on S3
   1440   resume.
   1441 
   1442   Reads the 64-bit I/O port specified by Port, performs a bitwise AND followed
   1443   by a bitwise OR between the read result and the value specified by
   1444   AndData, and writes the result to the 64-bit I/O port specified by Port. The
   1445   value written to the I/O port is returned. This function must guarantee that
   1446   all I/O read and write operations are serialized. Extra left bits in both
   1447   AndData and OrData are stripped.
   1448 
   1449   If 64-bit I/O port operations are not supported, then ASSERT().
   1450   If StartBit is greater than 63, then ASSERT().
   1451   If EndBit is greater than 63, then ASSERT().
   1452   If EndBit is less than StartBit, then ASSERT().
   1453   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1454   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1455 
   1456   @param  Port          The I/O port to write.
   1457   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1458                         Range 0..63.
   1459   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1460                         Range 0..63.
   1461   @param  AndData       The value to AND with the read value from the I/O port.
   1462   @param  OrData        The value to OR with the result of the AND operation.
   1463 
   1464   @return The value written back to the I/O port.
   1465 
   1466 **/
   1467 UINT64
   1468 EFIAPI
   1469 S3IoBitFieldAndThenOr64 (
   1470   IN UINTN              Port,
   1471   IN UINTN              StartBit,
   1472   IN UINTN              EndBit,
   1473   IN UINT64             AndData,
   1474   IN UINT64             OrData
   1475   )
   1476 {
   1477   return InternalSaveIoWrite64ValueToBootScript (Port, IoBitFieldAndThenOr64 (Port, StartBit, EndBit, AndData, OrData));
   1478 }
   1479 
   1480 /**
   1481   Saves an MMIO register value to the boot script.
   1482 
   1483   This internal worker function saves an MMIO register value in the S3 script
   1484   to be replayed on S3 resume.
   1485 
   1486   If the saving process fails, then ASSERT().
   1487 
   1488   @param  Width         The width of MMIO register.
   1489   @param  Address       The MMIO register to write.
   1490   @param  Buffer        The buffer containing value.
   1491 
   1492 **/
   1493 VOID
   1494 InternalSaveMmioWriteValueToBootScript (
   1495   IN S3_BOOT_SCRIPT_LIB_WIDTH  Width,
   1496   IN UINTN                  Address,
   1497   IN VOID                   *Buffer
   1498   )
   1499 {
   1500   RETURN_STATUS            Status;
   1501 
   1502   Status = S3BootScriptSaveMemWrite (
   1503              Width,
   1504              Address,
   1505              1,
   1506              Buffer
   1507              );
   1508   ASSERT (Status == RETURN_SUCCESS);
   1509 }
   1510 
   1511 /**
   1512   Saves an 8-bit MMIO register value to the boot script.
   1513 
   1514   This internal worker function saves an 8-bit MMIO register value in the S3 script
   1515   to be replayed on S3 resume.
   1516 
   1517   If the saving process fails, then ASSERT().
   1518 
   1519   @param  Address       The MMIO register to write.
   1520   @param  Value         The value saved to boot script.
   1521 
   1522   @return Value.
   1523 
   1524 **/
   1525 UINT8
   1526 InternalSaveMmioWrite8ValueToBootScript (
   1527   IN UINTN              Address,
   1528   IN UINT8              Value
   1529   )
   1530 {
   1531   InternalSaveMmioWriteValueToBootScript (S3BootScriptWidthUint8, Address, &Value);
   1532 
   1533   return Value;
   1534 }
   1535 
   1536 /**
   1537   Reads an 8-bit MMIO register and saves the value in the S3 script to be
   1538   replayed on S3 resume.
   1539 
   1540   Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
   1541   returned. This function must guarantee that all MMIO read and write
   1542   operations are serialized.
   1543 
   1544   If 8-bit MMIO register operations are not supported, then ASSERT().
   1545 
   1546   @param  Address       The MMIO register to read.
   1547 
   1548   @return The value read.
   1549 
   1550 **/
   1551 UINT8
   1552 EFIAPI
   1553 S3MmioRead8 (
   1554   IN UINTN              Address
   1555   )
   1556 {
   1557   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioRead8 (Address));
   1558 }
   1559 
   1560 /**
   1561   Writes an 8-bit MMIO register and saves the value in the S3 script to be
   1562   replayed on S3 resume.
   1563 
   1564   Writes the 8-bit MMIO register specified by Address with the value specified
   1565   by Value and returns Value. This function must guarantee that all MMIO read
   1566   and write operations are serialized.
   1567 
   1568   If 8-bit MMIO register operations are not supported, then ASSERT().
   1569 
   1570   @param  Address       The MMIO register to write.
   1571   @param  Value         The value to write to the MMIO register.
   1572 
   1573   @return The value written the MMIO register.
   1574 
   1575 **/
   1576 UINT8
   1577 EFIAPI
   1578 S3MmioWrite8 (
   1579   IN UINTN              Address,
   1580   IN UINT8              Value
   1581   )
   1582 {
   1583   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioWrite8 (Address, Value));
   1584 }
   1585 
   1586 /**
   1587   Reads an 8-bit MMIO register, performs a bitwise OR, and writes the
   1588   result back to the 8-bit MMIO register and saves the value in the S3 script
   1589   to be replayed on S3 resume.
   1590 
   1591   Reads the 8-bit MMIO register specified by Address, performs a bitwise
   1592   inclusive OR between the read result and the value specified by OrData, and
   1593   writes the result to the 8-bit MMIO register specified by Address. The value
   1594   written to the MMIO register is returned. This function must guarantee that
   1595   all MMIO read and write operations are serialized.
   1596 
   1597   If 8-bit MMIO register operations are not supported, then ASSERT().
   1598 
   1599   @param  Address       The MMIO register to write.
   1600   @param  OrData        The value to OR with the read value from the MMIO register.
   1601 
   1602   @return The value written back to the MMIO register.
   1603 
   1604 **/
   1605 UINT8
   1606 EFIAPI
   1607 S3MmioOr8 (
   1608   IN UINTN              Address,
   1609   IN UINT8              OrData
   1610   )
   1611 {
   1612   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioOr8 (Address, OrData));
   1613 }
   1614 
   1615 /**
   1616   Reads an 8-bit MMIO register, performs a bitwise AND, and writes the result
   1617   back to the 8-bit MMIO register and saves the value in the S3 script to be
   1618   replayed on S3 resume.
   1619 
   1620   Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
   1621   between the read result and the value specified by AndData, and writes the
   1622   result to the 8-bit MMIO register specified by Address. The value written to
   1623   the MMIO register is returned. This function must guarantee that all MMIO
   1624   read and write operations are serialized.
   1625 
   1626   If 8-bit MMIO register operations are not supported, then ASSERT().
   1627 
   1628   @param  Address       The MMIO register to write.
   1629   @param  AndData       The value to AND with the read value from the MMIO register.
   1630 
   1631   @return The value written back to the MMIO register.
   1632 
   1633 **/
   1634 UINT8
   1635 EFIAPI
   1636 S3MmioAnd8 (
   1637   IN UINTN              Address,
   1638   IN UINT8              AndData
   1639   )
   1640 {
   1641   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioAnd8 (Address, AndData));
   1642 }
   1643 
   1644 /**
   1645   Reads an 8-bit MMIO register, performs a bitwise AND followed by a bitwise
   1646   inclusive OR, and writes the result back to the 8-bit MMIO register and saves
   1647   the value in the S3 script to be replayed on S3 resume.
   1648 
   1649   Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
   1650   between the read result and the value specified by AndData, performs a
   1651   bitwise OR between the result of the AND operation and the value specified by
   1652   OrData, and writes the result to the 8-bit MMIO register specified by
   1653   Address. The value written to the MMIO register is returned. This function
   1654   must guarantee that all MMIO read and write operations are serialized.
   1655 
   1656   If 8-bit MMIO register operations are not supported, then ASSERT().
   1657 
   1658   @param  Address       The MMIO register to write.
   1659   @param  AndData       The value to AND with the read value from the MMIO register.
   1660   @param  OrData        The value to OR with the result of the AND operation.
   1661 
   1662   @return The value written back to the MMIO register.
   1663 
   1664 **/
   1665 UINT8
   1666 EFIAPI
   1667 S3MmioAndThenOr8 (
   1668   IN UINTN              Address,
   1669   IN UINT8              AndData,
   1670   IN UINT8              OrData
   1671   )
   1672 {
   1673   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioAndThenOr8 (Address, AndData, OrData));
   1674 }
   1675 
   1676 /**
   1677   Reads a bit field of a MMIO register and saves the value in the S3 script to
   1678   be replayed on S3 resume.
   1679 
   1680   Reads the bit field in an 8-bit MMIO register. The bit field is specified by
   1681   the StartBit and the EndBit. The value of the bit field is returned.
   1682 
   1683   If 8-bit MMIO register operations are not supported, then ASSERT().
   1684   If StartBit is greater than 7, then ASSERT().
   1685   If EndBit is greater than 7, then ASSERT().
   1686   If EndBit is less than StartBit, then ASSERT().
   1687 
   1688   @param  Address       MMIO register to read.
   1689   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1690                         Range 0..7.
   1691   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1692                         Range 0..7.
   1693 
   1694   @return The value read.
   1695 
   1696 **/
   1697 UINT8
   1698 EFIAPI
   1699 S3MmioBitFieldRead8 (
   1700   IN UINTN              Address,
   1701   IN UINTN              StartBit,
   1702   IN UINTN              EndBit
   1703   )
   1704 {
   1705   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioBitFieldRead8 (Address, StartBit, EndBit));
   1706 }
   1707 
   1708 /**
   1709   Writes a bit field to an MMIO register and saves the value in the S3 script to
   1710   be replayed on S3 resume.
   1711 
   1712   Writes Value to the bit field of the MMIO register. The bit field is
   1713   specified by the StartBit and the EndBit. All other bits in the destination
   1714   MMIO register are preserved. The new value of the 8-bit register is returned.
   1715 
   1716   If 8-bit MMIO register operations are not supported, then ASSERT().
   1717   If StartBit is greater than 7, then ASSERT().
   1718   If EndBit is greater than 7, then ASSERT().
   1719   If EndBit is less than StartBit, then ASSERT().
   1720   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1721 
   1722   @param  Address       The MMIO register to write.
   1723   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1724                         Range 0..7.
   1725   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1726                         Range 0..7.
   1727   @param  Value         New value of the bit field.
   1728 
   1729   @return The value written back to the MMIO register.
   1730 
   1731 **/
   1732 UINT8
   1733 EFIAPI
   1734 S3MmioBitFieldWrite8 (
   1735   IN UINTN              Address,
   1736   IN UINTN              StartBit,
   1737   IN UINTN              EndBit,
   1738   IN UINT8              Value
   1739   )
   1740 {
   1741   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioBitFieldWrite8 (Address, StartBit, EndBit, Value));
   1742 }
   1743 
   1744 /**
   1745   Reads a bit field in an 8-bit MMIO register, performs a bitwise OR, and
   1746   writes the result back to the bit field in the 8-bit MMIO register and saves
   1747   the value in the S3 script to be replayed on S3 resume.
   1748 
   1749   Reads the 8-bit MMIO register specified by Address, performs a bitwise
   1750   inclusive OR between the read result and the value specified by OrData, and
   1751   writes the result to the 8-bit MMIO register specified by Address. The value
   1752   written to the MMIO register is returned. This function must guarantee that
   1753   all MMIO read and write operations are serialized. Extra left bits in OrData
   1754   are stripped.
   1755 
   1756   If 8-bit MMIO register operations are not supported, then ASSERT().
   1757   If StartBit is greater than 7, then ASSERT().
   1758   If EndBit is greater than 7, then ASSERT().
   1759   If EndBit is less than StartBit, then ASSERT().
   1760   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1761 
   1762   @param  Address       The MMIO register to write.
   1763   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1764                         Range 0..7.
   1765   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1766                         Range 0..7.
   1767   @param  OrData        The value to OR with the read value from the MMIO register.
   1768 
   1769   @return The value written back to the MMIO register.
   1770 
   1771 **/
   1772 UINT8
   1773 EFIAPI
   1774 S3MmioBitFieldOr8 (
   1775   IN UINTN              Address,
   1776   IN UINTN              StartBit,
   1777   IN UINTN              EndBit,
   1778   IN UINT8              OrData
   1779   )
   1780 {
   1781   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioBitFieldOr8 (Address, StartBit, EndBit, OrData));
   1782 }
   1783 
   1784 /**
   1785   Reads a bit field in an 8-bit MMIO register, performs a bitwise AND, and
   1786   writes the result back to the bit field in the 8-bit MMIO register and saves
   1787   the value in the S3 script to be replayed on S3 resume.
   1788 
   1789   Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
   1790   between the read result and the value specified by AndData, and writes the
   1791   result to the 8-bit MMIO register specified by Address. The value written to
   1792   the MMIO register is returned. This function must guarantee that all MMIO
   1793   read and write operations are serialized. Extra left bits in AndData are
   1794   stripped.
   1795 
   1796   If 8-bit MMIO register operations are not supported, then ASSERT().
   1797   If StartBit is greater than 7, then ASSERT().
   1798   If EndBit is greater than 7, then ASSERT().
   1799   If EndBit is less than StartBit, then ASSERT().
   1800   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1801 
   1802   @param  Address       The MMIO register to write.
   1803   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1804                         Range 0..7.
   1805   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1806                         Range 0..7.
   1807   @param  AndData       The value to AND with the read value from the MMIO register.
   1808 
   1809   @return The value written back to the MMIO register.
   1810 
   1811 **/
   1812 UINT8
   1813 EFIAPI
   1814 S3MmioBitFieldAnd8 (
   1815   IN UINTN              Address,
   1816   IN UINTN              StartBit,
   1817   IN UINTN              EndBit,
   1818   IN UINT8              AndData
   1819   )
   1820 {
   1821   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioBitFieldAnd8 (Address, StartBit, EndBit, AndData));
   1822 }
   1823 
   1824 /**
   1825   Reads a bit field in an 8-bit MMIO register, performs a bitwise AND followed
   1826   by a bitwise OR, and writes the result back to the bit field in the
   1827   8-bit MMIO register  and saves the value in the S3 script to be replayed
   1828   on S3 resume.
   1829 
   1830   Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
   1831   followed by a bitwise OR between the read result and the value
   1832   specified by AndData, and writes the result to the 8-bit MMIO register
   1833   specified by Address. The value written to the MMIO register is returned.
   1834   This function must guarantee that all MMIO read and write operations are
   1835   serialized. Extra left bits in both AndData and OrData are stripped.
   1836 
   1837   If 8-bit MMIO register operations are not supported, then ASSERT().
   1838   If StartBit is greater than 7, then ASSERT().
   1839   If EndBit is greater than 7, then ASSERT().
   1840   If EndBit is less than StartBit, then ASSERT().
   1841   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1842   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   1843 
   1844   @param  Address       The MMIO register to write.
   1845   @param  StartBit      The ordinal of the least significant bit in the bit field.
   1846                         Range 0..7.
   1847   @param  EndBit        The ordinal of the most significant bit in the bit field.
   1848                         Range 0..7.
   1849   @param  AndData       The value to AND with the read value from the MMIO register.
   1850   @param  OrData        The value to OR with the result of the AND operation.
   1851 
   1852   @return The value written back to the MMIO register.
   1853 
   1854 **/
   1855 UINT8
   1856 EFIAPI
   1857 S3MmioBitFieldAndThenOr8 (
   1858   IN UINTN              Address,
   1859   IN UINTN              StartBit,
   1860   IN UINTN              EndBit,
   1861   IN UINT8              AndData,
   1862   IN UINT8              OrData
   1863   )
   1864 {
   1865   return InternalSaveMmioWrite8ValueToBootScript (Address, MmioBitFieldAndThenOr8 (Address, StartBit, EndBit, AndData, OrData));
   1866 }
   1867 
   1868 /**
   1869   Saves a 16-bit MMIO register value to the boot script.
   1870 
   1871   This internal worker function saves a 16-bit MMIO register value in the S3 script
   1872   to be replayed on S3 resume.
   1873 
   1874   If the saving process fails, then ASSERT().
   1875 
   1876   @param  Address       The MMIO register to write.
   1877   @param  Value         The value saved to boot script.
   1878 
   1879   @return Value.
   1880 
   1881 **/
   1882 UINT16
   1883 InternalSaveMmioWrite16ValueToBootScript (
   1884   IN UINTN              Address,
   1885   IN UINT16             Value
   1886   )
   1887 {
   1888   InternalSaveMmioWriteValueToBootScript (S3BootScriptWidthUint16, Address, &Value);
   1889 
   1890   return Value;
   1891 }
   1892 
   1893 /**
   1894   Reads a 16-bit MMIO register and saves the value in the S3 script to be replayed
   1895   on S3 resume.
   1896 
   1897   Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
   1898   returned. This function must guarantee that all MMIO read and write
   1899   operations are serialized.
   1900 
   1901   If 16-bit MMIO register operations are not supported, then ASSERT().
   1902 
   1903   @param  Address       The MMIO register to read.
   1904 
   1905   @return The value read.
   1906 
   1907 **/
   1908 UINT16
   1909 EFIAPI
   1910 S3MmioRead16 (
   1911   IN UINTN              Address
   1912   )
   1913 {
   1914   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioRead16 (Address));
   1915 }
   1916 
   1917 /**
   1918   Writes a 16-bit MMIO register and saves the value in the S3 script to be replayed
   1919   on S3 resume.
   1920 
   1921   Writes the 16-bit MMIO register specified by Address with the value specified
   1922   by Value and returns Value. This function must guarantee that all MMIO read
   1923   and write operations are serialized and saves the value in the S3 script to be
   1924   replayed on S3 resume.
   1925 
   1926   If 16-bit MMIO register operations are not supported, then ASSERT().
   1927 
   1928   @param  Address       The MMIO register to write.
   1929   @param  Value         The value to write to the MMIO register.
   1930 
   1931   @return The value written the MMIO register.
   1932 
   1933 **/
   1934 UINT16
   1935 EFIAPI
   1936 S3MmioWrite16 (
   1937   IN UINTN              Address,
   1938   IN UINT16             Value
   1939   )
   1940 {
   1941   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioWrite16 (Address, Value));
   1942 }
   1943 
   1944 /**
   1945   Reads a 16-bit MMIO register, performs a bitwise OR, and writes the
   1946   result back to the 16-bit MMIO register and saves the value in the S3 script
   1947   to be replayed on S3 resume.
   1948 
   1949   Reads the 16-bit MMIO register specified by Address, performs a bitwise
   1950   inclusive OR between the read result and the value specified by OrData, and
   1951   writes the result to the 16-bit MMIO register specified by Address. The value
   1952   written to the MMIO register is returned. This function must guarantee that
   1953   all MMIO read and write operations are serialized.
   1954 
   1955   If 16-bit MMIO register operations are not supported, then ASSERT().
   1956 
   1957   @param  Address       The MMIO register to write.
   1958   @param  OrData        The value to OR with the read value from the MMIO register.
   1959 
   1960   @return The value written back to the MMIO register.
   1961 
   1962 **/
   1963 UINT16
   1964 EFIAPI
   1965 S3MmioOr16 (
   1966   IN UINTN              Address,
   1967   IN UINT16             OrData
   1968   )
   1969 {
   1970   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioOr16 (Address, OrData));
   1971 }
   1972 
   1973 /**
   1974   Reads a 16-bit MMIO register, performs a bitwise AND, and writes the result
   1975   back to the 16-bit MMIO register and saves the value in the S3 script to be
   1976   replayed on S3 resume.
   1977 
   1978   Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
   1979   between the read result and the value specified by AndData, and writes the
   1980   result to the 16-bit MMIO register specified by Address. The value written to
   1981   the MMIO register is returned. This function must guarantee that all MMIO
   1982   read and write operations are serialized.
   1983 
   1984   If 16-bit MMIO register operations are not supported, then ASSERT().
   1985 
   1986   @param  Address       The MMIO register to write.
   1987   @param  AndData       The value to AND with the read value from the MMIO register.
   1988 
   1989   @return The value written back to the MMIO register.
   1990 
   1991 **/
   1992 UINT16
   1993 EFIAPI
   1994 S3MmioAnd16 (
   1995   IN UINTN              Address,
   1996   IN UINT16             AndData
   1997   )
   1998 {
   1999   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioAnd16 (Address, AndData));
   2000 }
   2001 
   2002 /**
   2003   Reads a 16-bit MMIO register, performs a bitwise AND followed by a bitwise
   2004   inclusive OR, and writes the result back to the 16-bit MMIO register and
   2005   saves the value in the S3 script to be replayed on S3 resume.
   2006 
   2007   Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
   2008   between the read result and the value specified by AndData, performs a
   2009   bitwise OR between the result of the AND operation and the value specified by
   2010   OrData, and writes the result to the 16-bit MMIO register specified by
   2011   Address. The value written to the MMIO register is returned. This function
   2012   must guarantee that all MMIO read and write operations are serialized.
   2013 
   2014   If 16-bit MMIO register operations are not supported, then ASSERT().
   2015 
   2016   @param  Address       The MMIO register to write.
   2017   @param  AndData       The value to AND with the read value from the MMIO register.
   2018   @param  OrData        The value to OR with the result of the AND operation.
   2019 
   2020   @return The value written back to the MMIO register.
   2021 
   2022 **/
   2023 UINT16
   2024 EFIAPI
   2025 S3MmioAndThenOr16 (
   2026   IN UINTN              Address,
   2027   IN UINT16             AndData,
   2028   IN UINT16             OrData
   2029   )
   2030 {
   2031   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioAndThenOr16 (Address, AndData, OrData));
   2032 }
   2033 
   2034 /**
   2035   Reads a bit field of a MMIO register and saves the value in the S3 script to
   2036   be replayed on S3 resume.
   2037 
   2038   Reads the bit field in a 16-bit MMIO register. The bit field is specified by
   2039   the StartBit and the EndBit. The value of the bit field is returned.
   2040 
   2041   If 16-bit MMIO register operations are not supported, then ASSERT().
   2042   If StartBit is greater than 15, then ASSERT().
   2043   If EndBit is greater than 15, then ASSERT().
   2044   If EndBit is less than StartBit, then ASSERT().
   2045 
   2046   @param  Address       MMIO register to read.
   2047   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2048                         Range 0..15.
   2049   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2050                         Range 0..15.
   2051 
   2052   @return The value read.
   2053 
   2054 **/
   2055 UINT16
   2056 EFIAPI
   2057 S3MmioBitFieldRead16 (
   2058   IN UINTN              Address,
   2059   IN UINTN              StartBit,
   2060   IN UINTN              EndBit
   2061   )
   2062 {
   2063   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioBitFieldRead16 (Address, StartBit, EndBit));
   2064 }
   2065 
   2066 /**
   2067   Writes a bit field to a MMIO register and saves the value in the S3 script to
   2068   be replayed on S3 resume.
   2069 
   2070   Writes Value to the bit field of the MMIO register. The bit field is
   2071   specified by the StartBit and the EndBit. All other bits in the destination
   2072   MMIO register are preserved. The new value of the 16-bit register is returned.
   2073 
   2074   If 16-bit MMIO register operations are not supported, then ASSERT().
   2075   If StartBit is greater than 15, then ASSERT().
   2076   If EndBit is greater than 15, then ASSERT().
   2077   If EndBit is less than StartBit, then ASSERT().
   2078   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2079 
   2080   @param  Address       The MMIO register to write.
   2081   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2082                         Range 0..15.
   2083   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2084                         Range 0..15.
   2085   @param  Value         New value of the bit field.
   2086 
   2087   @return The value written back to the MMIO register.
   2088 
   2089 **/
   2090 UINT16
   2091 EFIAPI
   2092 S3MmioBitFieldWrite16 (
   2093   IN UINTN              Address,
   2094   IN UINTN              StartBit,
   2095   IN UINTN              EndBit,
   2096   IN UINT16             Value
   2097   )
   2098 {
   2099   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioBitFieldWrite16 (Address, StartBit, EndBit, Value));
   2100 }
   2101 
   2102 /**
   2103   Reads a bit field in a 16-bit MMIO register, performs a bitwise OR, and
   2104   writes the result back to the bit field in the 16-bit MMIO register and
   2105   saves the value in the S3 script to be replayed on S3 resume.
   2106 
   2107   Reads the 16-bit MMIO register specified by Address, performs a bitwise
   2108   inclusive OR between the read result and the value specified by OrData, and
   2109   writes the result to the 16-bit MMIO register specified by Address. The value
   2110   written to the MMIO register is returned. This function must guarantee that
   2111   all MMIO read and write operations are serialized. Extra left bits in OrData
   2112   are stripped.
   2113 
   2114   If 16-bit MMIO register operations are not supported, then ASSERT().
   2115   If StartBit is greater than 15, then ASSERT().
   2116   If EndBit is greater than 15, then ASSERT().
   2117   If EndBit is less than StartBit, then ASSERT().
   2118   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2119 
   2120   @param  Address       The MMIO register to write.
   2121   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2122                         Range 0..15.
   2123   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2124                         Range 0..15.
   2125   @param  OrData        The value to OR with the read value from the MMIO register.
   2126 
   2127   @return The value written back to the MMIO register.
   2128 
   2129 **/
   2130 UINT16
   2131 EFIAPI
   2132 S3MmioBitFieldOr16 (
   2133   IN UINTN              Address,
   2134   IN UINTN              StartBit,
   2135   IN UINTN              EndBit,
   2136   IN UINT16             OrData
   2137   )
   2138 {
   2139   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioBitFieldOr16 (Address, StartBit, EndBit, OrData));
   2140 }
   2141 
   2142 /**
   2143   Reads a bit field in a 16-bit MMIO register, performs a bitwise AND, and
   2144   writes the result back to the bit field in the 16-bit MMIO register and
   2145   saves the value in the S3 script to be replayed on S3 resume.
   2146 
   2147   Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
   2148   between the read result and the value specified by AndData, and writes the
   2149   result to the 16-bit MMIO register specified by Address. The value written to
   2150   the MMIO register is returned. This function must guarantee that all MMIO
   2151   read and write operations are serialized. Extra left bits in AndData are
   2152   stripped.
   2153 
   2154   If 16-bit MMIO register operations are not supported, then ASSERT().
   2155   If StartBit is greater than 15, then ASSERT().
   2156   If EndBit is greater than 15, then ASSERT().
   2157   If EndBit is less than StartBit, then ASSERT().
   2158   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2159 
   2160   @param  Address       The MMIO register to write.
   2161   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2162                         Range 0..15.
   2163   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2164                         Range 0..15.
   2165   @param  AndData       The value to AND with the read value from the MMIO register.
   2166 
   2167   @return The value written back to the MMIO register.
   2168 
   2169 **/
   2170 UINT16
   2171 EFIAPI
   2172 S3MmioBitFieldAnd16 (
   2173   IN UINTN              Address,
   2174   IN UINTN              StartBit,
   2175   IN UINTN              EndBit,
   2176   IN UINT16             AndData
   2177   )
   2178 {
   2179   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioBitFieldAnd16 (Address, StartBit, EndBit, AndData));
   2180 }
   2181 
   2182 /**
   2183   Reads a bit field in a 16-bit MMIO register, performs a bitwise AND followed
   2184   by a bitwise OR, and writes the result back to the bit field in the
   2185   16-bit MMIO register and saves the value in the S3 script to be replayed
   2186   on S3 resume.
   2187 
   2188   Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
   2189   followed by a bitwise OR between the read result and the value
   2190   specified by AndData, and writes the result to the 16-bit MMIO register
   2191   specified by Address. The value written to the MMIO register is returned.
   2192   This function must guarantee that all MMIO read and write operations are
   2193   serialized. Extra left bits in both AndData and OrData are stripped.
   2194 
   2195   If 16-bit MMIO register operations are not supported, then ASSERT().
   2196   If StartBit is greater than 15, then ASSERT().
   2197   If EndBit is greater than 15, then ASSERT().
   2198   If EndBit is less than StartBit, then ASSERT().
   2199   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2200   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2201 
   2202   @param  Address       The MMIO register to write.
   2203   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2204                         Range 0..15.
   2205   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2206                         Range 0..15.
   2207   @param  AndData       The value to AND with the read value from the MMIO register.
   2208   @param  OrData        The value to OR with the result of the AND operation.
   2209 
   2210   @return The value written back to the MMIO register.
   2211 
   2212 **/
   2213 UINT16
   2214 EFIAPI
   2215 S3MmioBitFieldAndThenOr16 (
   2216   IN UINTN              Address,
   2217   IN UINTN              StartBit,
   2218   IN UINTN              EndBit,
   2219   IN UINT16             AndData,
   2220   IN UINT16             OrData
   2221   )
   2222 {
   2223   return InternalSaveMmioWrite16ValueToBootScript (Address, MmioBitFieldAndThenOr16 (Address, StartBit, EndBit, AndData, OrData));
   2224 }
   2225 
   2226 /**
   2227   Saves a 32-bit MMIO register value to the boot script.
   2228 
   2229   This internal worker function saves a 32-bit MMIO register value in the S3 script
   2230   to be replayed on S3 resume.
   2231 
   2232   If the saving process fails, then ASSERT().
   2233 
   2234   @param  Address       The MMIO register to write.
   2235   @param  Value         The value saved to boot script.
   2236 
   2237   @return Value.
   2238 
   2239 **/
   2240 UINT32
   2241 InternalSaveMmioWrite32ValueToBootScript (
   2242   IN UINTN              Address,
   2243   IN UINT32             Value
   2244   )
   2245 {
   2246   InternalSaveMmioWriteValueToBootScript (S3BootScriptWidthUint32, Address, &Value);
   2247 
   2248   return Value;
   2249 }
   2250 
   2251 /**
   2252   Reads a 32-bit MMIO register saves the value in the S3 script to be
   2253   replayed on S3 resume.
   2254 
   2255   Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
   2256   returned. This function must guarantee that all MMIO read and write
   2257   operations are serialized.
   2258 
   2259   If 32-bit MMIO register operations are not supported, then ASSERT().
   2260 
   2261   @param  Address       The MMIO register to read.
   2262 
   2263   @return The value read.
   2264 
   2265 **/
   2266 UINT32
   2267 EFIAPI
   2268 S3MmioRead32 (
   2269   IN UINTN              Address
   2270   )
   2271 {
   2272   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioRead32 (Address));
   2273 }
   2274 
   2275 /**
   2276   Writes a 32-bit MMIO register and saves the value in the S3 script to be
   2277   replayed on S3 resume.
   2278 
   2279   Writes the 32-bit MMIO register specified by Address with the value specified
   2280   by Value and returns Value. This function must guarantee that all MMIO read
   2281   and write operations are serialized.
   2282 
   2283   If 32-bit MMIO register operations are not supported, then ASSERT().
   2284 
   2285   @param  Address       The MMIO register to write.
   2286   @param  Value         The value to write to the MMIO register.
   2287 
   2288   @return The value written the MMIO register.
   2289 
   2290 **/
   2291 UINT32
   2292 EFIAPI
   2293 S3MmioWrite32 (
   2294   IN UINTN              Address,
   2295   IN UINT32             Value
   2296   )
   2297 {
   2298   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioWrite32 (Address, Value));
   2299 }
   2300 
   2301 /**
   2302   Reads a 32-bit MMIO register, performs a bitwise OR, and writes the
   2303   result back to the 32-bit MMIO register and saves the value in the S3 script
   2304   to be replayed on S3 resume.
   2305 
   2306   Reads the 32-bit MMIO register specified by Address, performs a bitwise
   2307   inclusive OR between the read result and the value specified by OrData, and
   2308   writes the result to the 32-bit MMIO register specified by Address. The value
   2309   written to the MMIO register is returned. This function must guarantee that
   2310   all MMIO read and write operations are serialized.
   2311 
   2312   If 32-bit MMIO register operations are not supported, then ASSERT().
   2313 
   2314   @param  Address       The MMIO register to write.
   2315   @param  OrData        The value to OR with the read value from the MMIO register.
   2316 
   2317   @return The value written back to the MMIO register.
   2318 
   2319 **/
   2320 UINT32
   2321 EFIAPI
   2322 S3MmioOr32 (
   2323   IN UINTN              Address,
   2324   IN UINT32             OrData
   2325   )
   2326 {
   2327   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioOr32 (Address, OrData));
   2328 }
   2329 
   2330 /**
   2331   Reads a 32-bit MMIO register, performs a bitwise AND, and writes the result
   2332   back to the 32-bit MMIO register and saves the value in the S3 script to be
   2333   replayed on S3 resume.
   2334 
   2335   Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
   2336   between the read result and the value specified by AndData, and writes the
   2337   result to the 32-bit MMIO register specified by Address. The value written to
   2338   the MMIO register is returned. This function must guarantee that all MMIO
   2339   read and write operations are serialized.
   2340 
   2341   If 32-bit MMIO register operations are not supported, then ASSERT().
   2342 
   2343   @param  Address       The MMIO register to write.
   2344   @param  AndData       The value to AND with the read value from the MMIO register.
   2345 
   2346   @return The value written back to the MMIO register.
   2347 
   2348 **/
   2349 UINT32
   2350 EFIAPI
   2351 S3MmioAnd32 (
   2352   IN UINTN              Address,
   2353   IN UINT32             AndData
   2354   )
   2355 {
   2356   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioAnd32 (Address, AndData));
   2357 }
   2358 
   2359 /**
   2360   Reads a 32-bit MMIO register, performs a bitwise AND followed by a bitwise
   2361   inclusive OR, and writes the result back to the 32-bit MMIO register and
   2362   saves the value in the S3 script to be replayed on S3 resume.
   2363 
   2364   Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
   2365   between the read result and the value specified by AndData, performs a
   2366   bitwise OR between the result of the AND operation and the value specified by
   2367   OrData, and writes the result to the 32-bit MMIO register specified by
   2368   Address. The value written to the MMIO register is returned. This function
   2369   must guarantee that all MMIO read and write operations are serialized.
   2370 
   2371   If 32-bit MMIO register operations are not supported, then ASSERT().
   2372 
   2373   @param  Address       The MMIO register to write.
   2374   @param  AndData       The value to AND with the read value from the MMIO register.
   2375   @param  OrData        The value to OR with the result of the AND operation.
   2376 
   2377   @return The value written back to the MMIO register.
   2378 
   2379 **/
   2380 UINT32
   2381 EFIAPI
   2382 S3MmioAndThenOr32 (
   2383   IN UINTN              Address,
   2384   IN UINT32             AndData,
   2385   IN UINT32             OrData
   2386   )
   2387 {
   2388   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioAndThenOr32 (Address, AndData, OrData));
   2389 }
   2390 
   2391 /**
   2392   Reads a bit field of a MMIO register and saves the value in the S3 script
   2393   to be replayed on S3 resume.
   2394 
   2395   Reads the bit field in a 32-bit MMIO register. The bit field is specified by
   2396   the StartBit and the EndBit. The value of the bit field is returned.
   2397 
   2398   If 32-bit MMIO register operations are not supported, then ASSERT().
   2399   If StartBit is greater than 31, then ASSERT().
   2400   If EndBit is greater than 31, then ASSERT().
   2401   If EndBit is less than StartBit, then ASSERT().
   2402 
   2403   @param  Address       MMIO register to read.
   2404   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2405                         Range 0..31.
   2406   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2407                         Range 0..31.
   2408 
   2409   @return The value read.
   2410 
   2411 **/
   2412 UINT32
   2413 EFIAPI
   2414 S3MmioBitFieldRead32 (
   2415   IN UINTN              Address,
   2416   IN UINTN              StartBit,
   2417   IN UINTN              EndBit
   2418   )
   2419 {
   2420   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioBitFieldRead32 (Address, StartBit, EndBit));
   2421 }
   2422 
   2423 /**
   2424   Writes a bit field to a MMIO register and saves the value in the S3 script
   2425   to be replayed on S3 resume.
   2426 
   2427   Writes Value to the bit field of the MMIO register. The bit field is
   2428   specified by the StartBit and the EndBit. All other bits in the destination
   2429   MMIO register are preserved. The new value of the 32-bit register is returned.
   2430 
   2431   If 32-bit MMIO register operations are not supported, then ASSERT().
   2432   If StartBit is greater than 31, then ASSERT().
   2433   If EndBit is greater than 31, then ASSERT().
   2434   If EndBit is less than StartBit, then ASSERT().
   2435   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2436 
   2437   @param  Address       The MMIO register to write.
   2438   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2439                         Range 0..31.
   2440   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2441                         Range 0..31.
   2442   @param  Value         New value of the bit field.
   2443 
   2444   @return The value written back to the MMIO register.
   2445 
   2446 **/
   2447 UINT32
   2448 EFIAPI
   2449 S3MmioBitFieldWrite32 (
   2450   IN UINTN              Address,
   2451   IN UINTN              StartBit,
   2452   IN UINTN              EndBit,
   2453   IN UINT32             Value
   2454   )
   2455 {
   2456   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioBitFieldWrite32 (Address, StartBit, EndBit, Value));
   2457 }
   2458 
   2459 /**
   2460   Reads a bit field in a 32-bit MMIO register, performs a bitwise OR, and
   2461   writes the result back to the bit field in the 32-bit MMIO register and
   2462   saves the value in the S3 script to be replayed on S3 resume.
   2463 
   2464   Reads the 32-bit MMIO register specified by Address, performs a bitwise
   2465   inclusive OR between the read result and the value specified by OrData, and
   2466   writes the result to the 32-bit MMIO register specified by Address. The value
   2467   written to the MMIO register is returned. This function must guarantee that
   2468   all MMIO read and write operations are serialized. Extra left bits in OrData
   2469   are stripped.
   2470 
   2471   If 32-bit MMIO register operations are not supported, then ASSERT().
   2472   If StartBit is greater than 31, then ASSERT().
   2473   If EndBit is greater than 31, then ASSERT().
   2474   If EndBit is less than StartBit, then ASSERT().
   2475   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2476 
   2477   @param  Address       The MMIO register to write.
   2478   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2479                         Range 0..31.
   2480   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2481                         Range 0..31.
   2482   @param  OrData        The value to OR with the read value from the MMIO register.
   2483 
   2484   @return The value written back to the MMIO register.
   2485 
   2486 **/
   2487 UINT32
   2488 EFIAPI
   2489 S3MmioBitFieldOr32 (
   2490   IN UINTN              Address,
   2491   IN UINTN              StartBit,
   2492   IN UINTN              EndBit,
   2493   IN UINT32             OrData
   2494   )
   2495 {
   2496   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioBitFieldOr32 (Address, StartBit, EndBit, OrData));
   2497 }
   2498 
   2499 /**
   2500   Reads a bit field in a 32-bit MMIO register, performs a bitwise AND, and
   2501   writes the result back to the bit field in the 32-bit MMIO register and
   2502   saves the value in the S3 script to be replayed on S3 resume.
   2503 
   2504   Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
   2505   between the read result and the value specified by AndData, and writes the
   2506   result to the 32-bit MMIO register specified by Address. The value written to
   2507   the MMIO register is returned. This function must guarantee that all MMIO
   2508   read and write operations are serialized. Extra left bits in AndData are
   2509   stripped.
   2510 
   2511   If 32-bit MMIO register operations are not supported, then ASSERT().
   2512   If StartBit is greater than 31, then ASSERT().
   2513   If EndBit is greater than 31, then ASSERT().
   2514   If EndBit is less than StartBit, then ASSERT().
   2515   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2516 
   2517   @param  Address       The MMIO register to write.
   2518   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2519                         Range 0..31.
   2520   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2521                         Range 0..31.
   2522   @param  AndData       The value to AND with the read value from the MMIO register.
   2523 
   2524   @return The value written back to the MMIO register.
   2525 
   2526 **/
   2527 UINT32
   2528 EFIAPI
   2529 S3MmioBitFieldAnd32 (
   2530   IN UINTN              Address,
   2531   IN UINTN              StartBit,
   2532   IN UINTN              EndBit,
   2533   IN UINT32             AndData
   2534   )
   2535 {
   2536   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioBitFieldAnd32 (Address, StartBit, EndBit, AndData));
   2537 }
   2538 
   2539 /**
   2540   Reads a bit field in a 32-bit MMIO register, performs a bitwise AND followed
   2541   by a bitwise OR, and writes the result back to the bit field in the
   2542   32-bit MMIO register and saves the value in the S3 script to be replayed
   2543   on S3 resume.
   2544 
   2545   Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
   2546   followed by a bitwise OR between the read result and the value
   2547   specified by AndData, and writes the result to the 32-bit MMIO register
   2548   specified by Address. The value written to the MMIO register is returned.
   2549   This function must guarantee that all MMIO read and write operations are
   2550   serialized. Extra left bits in both AndData and OrData are stripped.
   2551 
   2552   If 32-bit MMIO register operations are not supported, then ASSERT().
   2553   If StartBit is greater than 31, then ASSERT().
   2554   If EndBit is greater than 31, then ASSERT().
   2555   If EndBit is less than StartBit, then ASSERT().
   2556   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2557   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2558 
   2559   @param  Address       The MMIO register to write.
   2560   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2561                         Range 0..31.
   2562   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2563                         Range 0..31.
   2564   @param  AndData       The value to AND with the read value from the MMIO register.
   2565   @param  OrData        The value to OR with the result of the AND operation.
   2566 
   2567   @return The value written back to the MMIO register.
   2568 
   2569 **/
   2570 UINT32
   2571 EFIAPI
   2572 S3MmioBitFieldAndThenOr32 (
   2573   IN UINTN              Address,
   2574   IN UINTN              StartBit,
   2575   IN UINTN              EndBit,
   2576   IN UINT32             AndData,
   2577   IN UINT32             OrData
   2578   )
   2579 {
   2580   return InternalSaveMmioWrite32ValueToBootScript (Address, MmioBitFieldAndThenOr32 (Address, StartBit, EndBit, AndData, OrData));
   2581 }
   2582 
   2583 /**
   2584   Saves a 64-bit MMIO register value to the boot script.
   2585 
   2586   This internal worker function saves a 64-bit MMIO register value in the S3 script
   2587   to be replayed on S3 resume.
   2588 
   2589   If the saving process fails, then ASSERT().
   2590 
   2591   @param  Address       The MMIO register to write.
   2592   @param  Value         The value saved to boot script.
   2593 
   2594   @return Value.
   2595 
   2596 **/
   2597 UINT64
   2598 InternalSaveMmioWrite64ValueToBootScript (
   2599   IN UINTN              Address,
   2600   IN UINT64             Value
   2601   )
   2602 {
   2603   InternalSaveMmioWriteValueToBootScript (S3BootScriptWidthUint64, Address, &Value);
   2604 
   2605   return Value;
   2606 }
   2607 
   2608 /**
   2609   Reads a 64-bit MMIO register and saves the value in the S3 script to be
   2610   replayed on S3 resume.
   2611 
   2612   Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
   2613   returned. This function must guarantee that all MMIO read and write
   2614   operations are serialized.
   2615 
   2616   If 64-bit MMIO register operations are not supported, then ASSERT().
   2617 
   2618   @param  Address       The MMIO register to read.
   2619 
   2620   @return The value read.
   2621 
   2622 **/
   2623 UINT64
   2624 EFIAPI
   2625 S3MmioRead64 (
   2626   IN UINTN              Address
   2627   )
   2628 {
   2629   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioRead64 (Address));
   2630 }
   2631 
   2632 /**
   2633   Writes a 64-bit MMIO register and saves the value in the S3 script to be
   2634   replayed on S3 resume.
   2635 
   2636   Writes the 64-bit MMIO register specified by Address with the value specified
   2637   by Value and returns Value. This function must guarantee that all MMIO read
   2638   and write operations are serialized.
   2639 
   2640   If 64-bit MMIO register operations are not supported, then ASSERT().
   2641 
   2642   @param  Address       The MMIO register to write.
   2643   @param  Value         The value to write to the MMIO register.
   2644 
   2645   @return The value written the MMIO register.
   2646 
   2647 **/
   2648 UINT64
   2649 EFIAPI
   2650 S3MmioWrite64 (
   2651   IN UINTN              Address,
   2652   IN UINT64             Value
   2653   )
   2654 {
   2655   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioWrite64 (Address, Value));
   2656 }
   2657 
   2658 /**
   2659   Reads a 64-bit MMIO register, performs a bitwise OR, and writes the
   2660   result back to the 64-bit MMIO register and saves the value in the S3 script
   2661   to be replayed on S3 resume.
   2662 
   2663   Reads the 64-bit MMIO register specified by Address, performs a bitwise
   2664   inclusive OR between the read result and the value specified by OrData, and
   2665   writes the result to the 64-bit MMIO register specified by Address. The value
   2666   written to the MMIO register is returned. This function must guarantee that
   2667   all MMIO read and write operations are serialized.
   2668 
   2669   If 64-bit MMIO register operations are not supported, then ASSERT().
   2670 
   2671   @param  Address       The MMIO register to write.
   2672   @param  OrData        The value to OR with the read value from the MMIO register.
   2673 
   2674   @return The value written back to the MMIO register.
   2675 
   2676 **/
   2677 UINT64
   2678 EFIAPI
   2679 S3MmioOr64 (
   2680   IN UINTN              Address,
   2681   IN UINT64             OrData
   2682   )
   2683 {
   2684   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioOr64 (Address, OrData));
   2685 }
   2686 
   2687 /**
   2688   Reads a 64-bit MMIO register, performs a bitwise AND, and writes the result
   2689   back to the 64-bit MMIO register and saves the value in the S3 script to be
   2690   replayed on S3 resume.
   2691 
   2692   Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
   2693   between the read result and the value specified by AndData, and writes the
   2694   result to the 64-bit MMIO register specified by Address. The value written to
   2695   the MMIO register is returned. This function must guarantee that all MMIO
   2696   read and write operations are serialized.
   2697 
   2698   If 64-bit MMIO register operations are not supported, then ASSERT().
   2699 
   2700   @param  Address       The MMIO register to write.
   2701   @param  AndData       The value to AND with the read value from the MMIO register.
   2702 
   2703   @return The value written back to the MMIO register.
   2704 
   2705 **/
   2706 UINT64
   2707 EFIAPI
   2708 S3MmioAnd64 (
   2709   IN UINTN              Address,
   2710   IN UINT64             AndData
   2711   )
   2712 {
   2713   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioAnd64 (Address, AndData));
   2714 }
   2715 
   2716 /**
   2717   Reads a 64-bit MMIO register, performs a bitwise AND followed by a bitwise
   2718   inclusive OR, and writes the result back to the 64-bit MMIO register and
   2719   saves the value in the S3 script to be replayed on S3 resume.
   2720 
   2721   Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
   2722   between the read result and the value specified by AndData, performs a
   2723   bitwise OR between the result of the AND operation and the value specified by
   2724   OrData, and writes the result to the 64-bit MMIO register specified by
   2725   Address. The value written to the MMIO register is returned. This function
   2726   must guarantee that all MMIO read and write operations are serialized.
   2727 
   2728   If 64-bit MMIO register operations are not supported, then ASSERT().
   2729 
   2730   @param  Address       The MMIO register to write.
   2731   @param  AndData       The value to AND with the read value from the MMIO register.
   2732   @param  OrData        The value to OR with the result of the AND operation.
   2733 
   2734   @return The value written back to the MMIO register.
   2735 
   2736 **/
   2737 UINT64
   2738 EFIAPI
   2739 S3MmioAndThenOr64 (
   2740   IN UINTN              Address,
   2741   IN UINT64             AndData,
   2742   IN UINT64             OrData
   2743   )
   2744 {
   2745   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioAndThenOr64 (Address, AndData, OrData));
   2746 }
   2747 
   2748 /**
   2749   Reads a bit field of a MMIO register saves the value in the S3 script to
   2750   be replayed on S3 resume.
   2751 
   2752   Reads the bit field in a 64-bit MMIO register. The bit field is specified by
   2753   the StartBit and the EndBit. The value of the bit field is returned.
   2754 
   2755   If 64-bit MMIO register operations are not supported, then ASSERT().
   2756   If StartBit is greater than 63, then ASSERT().
   2757   If EndBit is greater than 63, then ASSERT().
   2758   If EndBit is less than StartBit, then ASSERT().
   2759 
   2760   @param  Address       MMIO register to read.
   2761   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2762                         Range 0..63.
   2763   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2764                         Range 0..63.
   2765 
   2766   @return The value read.
   2767 
   2768 **/
   2769 UINT64
   2770 EFIAPI
   2771 S3MmioBitFieldRead64 (
   2772   IN UINTN              Address,
   2773   IN UINTN              StartBit,
   2774   IN UINTN              EndBit
   2775   )
   2776 {
   2777   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioBitFieldRead64 (Address, StartBit, EndBit));
   2778 }
   2779 
   2780 /**
   2781   Writes a bit field to a MMIO register and saves the value in the S3 script to
   2782   be replayed on S3 resume.
   2783 
   2784   Writes Value to the bit field of the MMIO register. The bit field is
   2785   specified by the StartBit and the EndBit. All other bits in the destination
   2786   MMIO register are preserved. The new value of the 64-bit register is returned.
   2787 
   2788   If 64-bit MMIO register operations are not supported, then ASSERT().
   2789   If StartBit is greater than 63, then ASSERT().
   2790   If EndBit is greater than 63, then ASSERT().
   2791   If EndBit is less than StartBit, then ASSERT().
   2792   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2793 
   2794   @param  Address       The MMIO register to write.
   2795   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2796                         Range 0..63.
   2797   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2798                         Range 0..63.
   2799   @param  Value         New value of the bit field.
   2800 
   2801   @return The value written back to the MMIO register.
   2802 
   2803 **/
   2804 UINT64
   2805 EFIAPI
   2806 S3MmioBitFieldWrite64 (
   2807   IN UINTN              Address,
   2808   IN UINTN              StartBit,
   2809   IN UINTN              EndBit,
   2810   IN UINT64             Value
   2811   )
   2812 {
   2813   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioBitFieldWrite64 (Address, StartBit, EndBit, Value));
   2814 }
   2815 
   2816 /**
   2817   Reads a bit field in a 64-bit MMIO register, performs a bitwise OR, and
   2818   writes the result back to the bit field in the 64-bit MMIO register and
   2819   saves the value in the S3 script to be replayed on S3 resume.
   2820 
   2821   Reads the 64-bit MMIO register specified by Address, performs a bitwise
   2822   inclusive OR between the read result and the value specified by OrData, and
   2823   writes the result to the 64-bit MMIO register specified by Address. The value
   2824   written to the MMIO register is returned. This function must guarantee that
   2825   all MMIO read and write operations are serialized. Extra left bits in OrData
   2826   are stripped.
   2827 
   2828   If 64-bit MMIO register operations are not supported, then ASSERT().
   2829   If StartBit is greater than 63, then ASSERT().
   2830   If EndBit is greater than 63, then ASSERT().
   2831   If EndBit is less than StartBit, then ASSERT().
   2832   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2833 
   2834   @param  Address       The MMIO register to write.
   2835   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2836                         Range 0..63.
   2837   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2838                         Range 0..63.
   2839   @param  OrData        The value to OR with the read value from the MMIO register.
   2840 
   2841   @return The value written back to the MMIO register.
   2842 
   2843 **/
   2844 UINT64
   2845 EFIAPI
   2846 S3MmioBitFieldOr64 (
   2847   IN UINTN              Address,
   2848   IN UINTN              StartBit,
   2849   IN UINTN              EndBit,
   2850   IN UINT64             OrData
   2851   )
   2852 {
   2853   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioBitFieldOr64 (Address, StartBit, EndBit, OrData));
   2854 }
   2855 
   2856 /**
   2857   Reads a bit field in a 64-bit MMIO register, performs a bitwise AND, and
   2858   writes the result back to the bit field in the 64-bit MMIO register and saves
   2859   the value in the S3 script to be replayed on S3 resume.
   2860 
   2861   Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
   2862   between the read result and the value specified by AndData, and writes the
   2863   result to the 64-bit MMIO register specified by Address. The value written to
   2864   the MMIO register is returned. This function must guarantee that all MMIO
   2865   read and write operations are serialized. Extra left bits in AndData are
   2866   stripped.
   2867 
   2868   If 64-bit MMIO register operations are not supported, then ASSERT().
   2869   If StartBit is greater than 63, then ASSERT().
   2870   If EndBit is greater than 63, then ASSERT().
   2871   If EndBit is less than StartBit, then ASSERT().
   2872   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2873 
   2874   @param  Address       The MMIO register to write.
   2875   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2876                         Range 0..63.
   2877   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2878                         Range 0..63.
   2879   @param  AndData       The value to AND with the read value from the MMIO register.
   2880 
   2881   @return The value written back to the MMIO register.
   2882 
   2883 **/
   2884 UINT64
   2885 EFIAPI
   2886 S3MmioBitFieldAnd64 (
   2887   IN UINTN              Address,
   2888   IN UINTN              StartBit,
   2889   IN UINTN              EndBit,
   2890   IN UINT64             AndData
   2891   )
   2892 {
   2893   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioBitFieldAnd64 (Address, StartBit, EndBit, AndData));
   2894 }
   2895 
   2896 /**
   2897   Reads a bit field in a 64-bit MMIO register, performs a bitwise AND followed
   2898   by a bitwise OR, and writes the result back to the bit field in the
   2899   64-bit MMIO register and saves the value in the S3 script to be replayed
   2900   on S3 resume.
   2901 
   2902   Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
   2903   followed by a bitwise OR between the read result and the value
   2904   specified by AndData, and writes the result to the 64-bit MMIO register
   2905   specified by Address. The value written to the MMIO register is returned.
   2906   This function must guarantee that all MMIO read and write operations are
   2907   serialized. Extra left bits in both AndData and OrData are stripped.
   2908 
   2909   If 64-bit MMIO register operations are not supported, then ASSERT().
   2910   If StartBit is greater than 63, then ASSERT().
   2911   If EndBit is greater than 63, then ASSERT().
   2912   If EndBit is less than StartBit, then ASSERT().
   2913   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2914   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
   2915 
   2916   @param  Address       The MMIO register to write.
   2917   @param  StartBit      The ordinal of the least significant bit in the bit field.
   2918                         Range 0..63.
   2919   @param  EndBit        The ordinal of the most significant bit in the bit field.
   2920                         Range 0..63.
   2921   @param  AndData       The value to AND with the read value from the MMIO register.
   2922   @param  OrData        The value to OR with the result of the AND operation.
   2923 
   2924   @return The value written back to the MMIO register.
   2925 
   2926 **/
   2927 UINT64
   2928 EFIAPI
   2929 S3MmioBitFieldAndThenOr64 (
   2930   IN UINTN              Address,
   2931   IN UINTN              StartBit,
   2932   IN UINTN              EndBit,
   2933   IN UINT64             AndData,
   2934   IN UINT64             OrData
   2935   )
   2936 {
   2937   return InternalSaveMmioWrite64ValueToBootScript (Address, MmioBitFieldAndThenOr64 (Address, StartBit, EndBit, AndData, OrData));
   2938 }
   2939 
   2940 /**
   2941   Copy data from MMIO region to system memory by using 8-bit access
   2942   and saves the value in the S3 script to be replayed on S3 resume.
   2943 
   2944   Copy data from MMIO region specified by starting address StartAddress
   2945   to system memory specified by Buffer by using 8-bit access. The total
   2946   number of byte to be copied is specified by Length. Buffer is returned.
   2947 
   2948   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   2949   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
   2950 
   2951 
   2952   @param  StartAddress    Starting address for the MMIO region to be copied from.
   2953   @param  Length          Size in bytes of the copy.
   2954   @param  Buffer          Pointer to a system memory buffer receiving the data read.
   2955 
   2956   @return Buffer
   2957 
   2958 **/
   2959 UINT8 *
   2960 EFIAPI
   2961 S3MmioReadBuffer8 (
   2962   IN  UINTN       StartAddress,
   2963   IN  UINTN       Length,
   2964   OUT UINT8       *Buffer
   2965   )
   2966 {
   2967   UINT8       *ReturnBuffer;
   2968   RETURN_STATUS  Status;
   2969 
   2970   ReturnBuffer = MmioReadBuffer8 (StartAddress, Length, Buffer);
   2971 
   2972   Status = S3BootScriptSaveMemWrite (
   2973              S3BootScriptWidthUint8,
   2974              StartAddress,
   2975              Length / sizeof (UINT8),
   2976              ReturnBuffer
   2977              );
   2978   ASSERT (Status == RETURN_SUCCESS);
   2979 
   2980   return ReturnBuffer;
   2981 }
   2982 
   2983 /**
   2984   Copy data from MMIO region to system memory by using 16-bit access
   2985   and saves the value in the S3 script to be replayed on S3 resume.
   2986 
   2987   Copy data from MMIO region specified by starting address StartAddress
   2988   to system memory specified by Buffer by using 16-bit access. The total
   2989   number of byte to be copied is specified by Length. Buffer is returned.
   2990 
   2991   If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
   2992 
   2993   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   2994   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
   2995 
   2996   If Length is not aligned on a 16-bit boundary, then ASSERT().
   2997   If Buffer is not aligned on a 16-bit boundary, then ASSERT().
   2998 
   2999   @param  StartAddress    Starting address for the MMIO region to be copied from.
   3000   @param  Length          Size in bytes of the copy.
   3001   @param  Buffer          Pointer to a system memory buffer receiving the data read.
   3002 
   3003   @return Buffer
   3004 
   3005 **/
   3006 UINT16 *
   3007 EFIAPI
   3008 S3MmioReadBuffer16 (
   3009   IN  UINTN       StartAddress,
   3010   IN  UINTN       Length,
   3011   OUT UINT16      *Buffer
   3012   )
   3013 {
   3014   UINT16       *ReturnBuffer;
   3015   RETURN_STATUS   Status;
   3016 
   3017   ReturnBuffer = MmioReadBuffer16 (StartAddress, Length, Buffer);
   3018 
   3019   Status = S3BootScriptSaveMemWrite (
   3020              S3BootScriptWidthUint16,
   3021              StartAddress,
   3022              Length / sizeof (UINT16),
   3023              ReturnBuffer
   3024              );
   3025   ASSERT (Status == RETURN_SUCCESS);
   3026 
   3027   return ReturnBuffer;
   3028 }
   3029 
   3030 /**
   3031   Copy data from MMIO region to system memory by using 32-bit access
   3032   and saves the value in the S3 script to be replayed on S3 resume.
   3033 
   3034   Copy data from MMIO region specified by starting address StartAddress
   3035   to system memory specified by Buffer by using 32-bit access. The total
   3036   number of byte to be copied is specified by Length. Buffer is returned.
   3037 
   3038   If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
   3039 
   3040   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   3041   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
   3042 
   3043   If Length is not aligned on a 32-bit boundary, then ASSERT().
   3044   If Buffer is not aligned on a 32-bit boundary, then ASSERT().
   3045 
   3046   @param  StartAddress    Starting address for the MMIO region to be copied from.
   3047   @param  Length          Size in bytes of the copy.
   3048   @param  Buffer          Pointer to a system memory buffer receiving the data read.
   3049 
   3050   @return Buffer
   3051 
   3052 **/
   3053 UINT32 *
   3054 EFIAPI
   3055 S3MmioReadBuffer32 (
   3056   IN  UINTN       StartAddress,
   3057   IN  UINTN       Length,
   3058   OUT UINT32      *Buffer
   3059   )
   3060 {
   3061   UINT32      *ReturnBuffer;
   3062   RETURN_STATUS  Status;
   3063 
   3064   ReturnBuffer = MmioReadBuffer32 (StartAddress, Length, Buffer);
   3065 
   3066   Status = S3BootScriptSaveMemWrite (
   3067              S3BootScriptWidthUint32,
   3068              StartAddress,
   3069              Length / sizeof (UINT32),
   3070              ReturnBuffer
   3071              );
   3072   ASSERT (Status == RETURN_SUCCESS);
   3073 
   3074   return ReturnBuffer;
   3075 }
   3076 
   3077 /**
   3078   Copy data from MMIO region to system memory by using 64-bit access
   3079   and saves the value in the S3 script to be replayed on S3 resume.
   3080 
   3081   Copy data from MMIO region specified by starting address StartAddress
   3082   to system memory specified by Buffer by using 64-bit access. The total
   3083   number of byte to be copied is specified by Length. Buffer is returned.
   3084 
   3085   If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
   3086 
   3087   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   3088   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
   3089 
   3090   If Length is not aligned on a 64-bit boundary, then ASSERT().
   3091   If Buffer is not aligned on a 64-bit boundary, then ASSERT().
   3092 
   3093   @param  StartAddress    Starting address for the MMIO region to be copied from.
   3094   @param  Length          Size in bytes of the copy.
   3095   @param  Buffer          Pointer to a system memory buffer receiving the data read.
   3096 
   3097   @return Buffer
   3098 
   3099 **/
   3100 UINT64 *
   3101 EFIAPI
   3102 S3MmioReadBuffer64 (
   3103   IN  UINTN       StartAddress,
   3104   IN  UINTN       Length,
   3105   OUT UINT64      *Buffer
   3106   )
   3107 {
   3108   UINT64      *ReturnBuffer;
   3109   RETURN_STATUS  Status;
   3110 
   3111   ReturnBuffer = MmioReadBuffer64 (StartAddress, Length, Buffer);
   3112 
   3113   Status = S3BootScriptSaveMemWrite (
   3114              S3BootScriptWidthUint64,
   3115              StartAddress,
   3116              Length / sizeof (UINT64),
   3117              ReturnBuffer
   3118              );
   3119   ASSERT (Status == RETURN_SUCCESS);
   3120 
   3121   return ReturnBuffer;
   3122 }
   3123 
   3124 
   3125 /**
   3126   Copy data from system memory to MMIO region by using 8-bit access
   3127   and saves the value in the S3 script to be replayed on S3 resume.
   3128 
   3129   Copy data from system memory specified by Buffer to MMIO region specified
   3130   by starting address StartAddress by using 8-bit access. The total number
   3131   of byte to be copied is specified by Length. Buffer is returned.
   3132 
   3133   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   3134   If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
   3135 
   3136 
   3137   @param  StartAddress    Starting address for the MMIO region to be copied to.
   3138   @param  Length     Size in bytes of the copy.
   3139   @param  Buffer          Pointer to a system memory buffer containing the data to write.
   3140 
   3141   @return Buffer
   3142 
   3143 **/
   3144 UINT8 *
   3145 EFIAPI
   3146 S3MmioWriteBuffer8 (
   3147   IN  UINTN         StartAddress,
   3148   IN  UINTN         Length,
   3149   IN  CONST UINT8   *Buffer
   3150   )
   3151 {
   3152   UINT8       *ReturnBuffer;
   3153   RETURN_STATUS  Status;
   3154 
   3155   ReturnBuffer = MmioWriteBuffer8 (StartAddress, Length, Buffer);
   3156 
   3157   Status = S3BootScriptSaveMemWrite (
   3158              S3BootScriptWidthUint8,
   3159              StartAddress,
   3160              Length / sizeof (UINT8),
   3161              ReturnBuffer
   3162              );
   3163   ASSERT (Status == RETURN_SUCCESS);
   3164 
   3165   return ReturnBuffer;
   3166 }
   3167 
   3168 /**
   3169   Copy data from system memory to MMIO region by using 16-bit access
   3170   and saves the value in the S3 script to be replayed on S3 resume.
   3171 
   3172   Copy data from system memory specified by Buffer to MMIO region specified
   3173   by starting address StartAddress by using 16-bit access. The total number
   3174   of byte to be copied is specified by Length. Buffer is returned.
   3175 
   3176   If StartAddress is not aligned on a 16-bit boundary, then ASSERT().
   3177 
   3178   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   3179   If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
   3180 
   3181   If Length is not aligned on a 16-bit boundary, then ASSERT().
   3182 
   3183   If Buffer is not aligned on a 16-bit boundary, then ASSERT().
   3184 
   3185   @param  StartAddress    Starting address for the MMIO region to be copied to.
   3186   @param  Length     Size in bytes of the copy.
   3187   @param  Buffer          Pointer to a system memory buffer containing the data to write.
   3188 
   3189   @return Buffer
   3190 
   3191 **/
   3192 UINT16 *
   3193 EFIAPI
   3194 S3MmioWriteBuffer16 (
   3195   IN  UINTN        StartAddress,
   3196   IN  UINTN        Length,
   3197   IN  CONST UINT16 *Buffer
   3198   )
   3199 {
   3200   UINT16      *ReturnBuffer;
   3201   RETURN_STATUS  Status;
   3202 
   3203   ReturnBuffer = MmioWriteBuffer16 (StartAddress, Length, Buffer);
   3204 
   3205   Status = S3BootScriptSaveMemWrite (
   3206              S3BootScriptWidthUint16,
   3207              StartAddress,
   3208              Length / sizeof (UINT16),
   3209              ReturnBuffer
   3210              );
   3211   ASSERT (Status == RETURN_SUCCESS);
   3212 
   3213   return ReturnBuffer;
   3214 }
   3215 
   3216 
   3217 /**
   3218   Copy data from system memory to MMIO region by using 32-bit access
   3219   and saves the value in the S3 script to be replayed on S3 resume.
   3220 
   3221   Copy data from system memory specified by Buffer to MMIO region specified
   3222   by starting address StartAddress by using 32-bit access. The total number
   3223   of byte to be copied is specified by Length. Buffer is returned.
   3224 
   3225   If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
   3226 
   3227   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   3228   If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
   3229 
   3230   If Length is not aligned on a 32-bit boundary, then ASSERT().
   3231 
   3232   If Buffer is not aligned on a 32-bit boundary, then ASSERT().
   3233 
   3234   @param  StartAddress    Starting address for the MMIO region to be copied to.
   3235   @param  Length     Size in bytes of the copy.
   3236   @param  Buffer          Pointer to a system memory buffer containing the data to write.
   3237 
   3238   @return Buffer
   3239 
   3240 **/
   3241 UINT32 *
   3242 EFIAPI
   3243 S3MmioWriteBuffer32 (
   3244   IN  UINTN        StartAddress,
   3245   IN  UINTN        Length,
   3246   IN  CONST UINT32 *Buffer
   3247   )
   3248 {
   3249   UINT32      *ReturnBuffer;
   3250   RETURN_STATUS  Status;
   3251 
   3252   ReturnBuffer = MmioWriteBuffer32 (StartAddress, Length, Buffer);
   3253 
   3254   Status = S3BootScriptSaveMemWrite (
   3255              S3BootScriptWidthUint32,
   3256              StartAddress,
   3257              Length / sizeof (UINT32),
   3258              ReturnBuffer
   3259              );
   3260   ASSERT (Status == RETURN_SUCCESS);
   3261 
   3262   return ReturnBuffer;
   3263 }
   3264 
   3265 /**
   3266   Copy data from system memory to MMIO region by using 64-bit access
   3267   and saves the value in the S3 script to be replayed on S3 resume.
   3268 
   3269   Copy data from system memory specified by Buffer to MMIO region specified
   3270   by starting address StartAddress by using 64-bit access. The total number
   3271   of byte to be copied is specified by Length. Buffer is returned.
   3272 
   3273   If StartAddress is not aligned on a 64-bit boundary, then ASSERT().
   3274 
   3275   If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
   3276   If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
   3277 
   3278   If Length is not aligned on a 64-bit boundary, then ASSERT().
   3279 
   3280   If Buffer is not aligned on a 64-bit boundary, then ASSERT().
   3281 
   3282   @param  StartAddress    Starting address for the MMIO region to be copied to.
   3283   @param  Length     Size in bytes of the copy.
   3284   @param  Buffer          Pointer to a system memory buffer containing the data to write.
   3285 
   3286   @return Buffer
   3287 
   3288 **/
   3289 UINT64 *
   3290 EFIAPI
   3291 S3MmioWriteBuffer64 (
   3292   IN  UINTN        StartAddress,
   3293   IN  UINTN        Length,
   3294   IN  CONST UINT64 *Buffer
   3295   )
   3296 {
   3297   UINT64      *ReturnBuffer;
   3298   RETURN_STATUS  Status;
   3299 
   3300   ReturnBuffer = MmioWriteBuffer64 (StartAddress, Length, Buffer);
   3301 
   3302   Status = S3BootScriptSaveMemWrite (
   3303              S3BootScriptWidthUint64,
   3304              StartAddress,
   3305              Length / sizeof (UINT64),
   3306              ReturnBuffer
   3307              );
   3308   ASSERT (Status == RETURN_SUCCESS);
   3309 
   3310   return ReturnBuffer;
   3311 }
   3312 
   3313