2 PCI configuration Library Services that do PCI configuration and also enable
3 the PCI operations to be replayed during an S3 resume. This library class
4 maps directly on top of the PciLib class.
6 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions
10 of the BSD License which accompanies this distribution. The
11 full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Library/DebugLib.h>
23 #include <Library/S3BootScriptLib.h>
24 #include <Library/PciLib.h>
25 #include <Library/S3PciLib.h>
27 #define PCILIB_TO_COMMON_ADDRESS(Address) \
28 ((((UINTN) ((Address>>20) & 0xff)) << 24) + (((UINTN) ((Address>>15) & 0x1f)) << 16) + (((UINTN) ((Address>>12) & 0x07)) << 8) + ((UINTN) (Address & 0xfff )))
31 Saves a PCI configuration value to the boot script.
33 This internal worker function saves a PCI configuration value in
34 the S3 script to be replayed on S3 resume.
36 If the saving process fails, then ASSERT().
38 @param Width The width of PCI configuration.
39 @param Address Address that encodes the PCI Bus, Device, Function and
41 @param Buffer The buffer containing value.
45 InternalSavePciWriteValueToBootScript (
46 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
53 Status
= S3BootScriptSavePciCfgWrite (
55 PCILIB_TO_COMMON_ADDRESS(Address
),
59 ASSERT (Status
== RETURN_SUCCESS
);
63 Saves an 8-bit PCI configuration value to the boot script.
65 This internal worker function saves an 8-bit PCI configuration value in
66 the S3 script to be replayed on S3 resume.
68 If the saving process fails, then ASSERT().
70 @param Address Address that encodes the PCI Bus, Device, Function and
72 @param Value The value saved to boot script.
78 InternalSavePciWrite8ValueToBootScript (
83 InternalSavePciWriteValueToBootScript (S3BootScriptWidthUint8
, Address
, &Value
);
89 Reads an 8-bit PCI configuration register and saves the value in the S3
90 script to be replayed on S3 resume.
92 Reads and returns the 8-bit PCI configuration register specified by Address.
93 This function must guarantee that all PCI read and write operations are
96 If Address > 0x0FFFFFFF, then ASSERT().
98 @param Address Address that encodes the PCI Bus, Device, Function and
101 @return The read value from the PCI configuration register.
110 return InternalSavePciWrite8ValueToBootScript (Address
, PciRead8 (Address
));
114 Writes an 8-bit PCI configuration register and saves the value in the S3
115 script to be replayed on S3 resume.
117 Writes the 8-bit PCI configuration register specified by Address with the
118 value specified by Value. Value is returned. This function must guarantee
119 that all PCI read and write operations are serialized.
121 If Address > 0x0FFFFFFF, then ASSERT().
123 @param Address Address that encodes the PCI Bus, Device, Function and
125 @param Value The value to write.
127 @return The value written to the PCI configuration register.
137 return InternalSavePciWrite8ValueToBootScript (Address
, PciWrite8 (Address
, Value
));
141 Performs a bitwise OR of an 8-bit PCI configuration register with
142 an 8-bit value and saves the value in the S3 script to be replayed on S3 resume.
144 Reads the 8-bit PCI configuration register specified by Address, performs a
145 bitwise OR between the read result and the value specified by
146 OrData, and writes the result to the 8-bit PCI configuration register
147 specified by Address. The value written to the PCI configuration register is
148 returned. This function must guarantee that all PCI read and write operations
151 If Address > 0x0FFFFFFF, then ASSERT().
153 @param Address Address that encodes the PCI Bus, Device, Function and
155 @param OrData The value to OR with the PCI configuration register.
157 @return The value written back to the PCI configuration register.
167 return InternalSavePciWrite8ValueToBootScript (Address
, PciOr8 (Address
, OrData
));
171 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
172 value and saves the value in the S3 script to be replayed on S3 resume.
174 Reads the 8-bit PCI configuration register specified by Address, performs a
175 bitwise AND between the read result and the value specified by AndData, and
176 writes the result to the 8-bit PCI configuration register specified by
177 Address. The value written to the PCI configuration register is returned.
178 This function must guarantee that all PCI read and write operations are
181 If Address > 0x0FFFFFFF, then ASSERT().
183 @param Address Address that encodes the PCI Bus, Device, Function and
185 @param AndData The value to AND with the PCI configuration register.
187 @return The value written back to the PCI configuration register.
197 return InternalSavePciWrite8ValueToBootScript (Address
, PciAnd8 (Address
, AndData
));
201 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
202 value, followed a bitwise OR with another 8-bit value and saves
203 the value in the S3 script to be replayed on S3 resume.
205 Reads the 8-bit PCI configuration register specified by Address, performs a
206 bitwise AND between the read result and the value specified by AndData,
207 performs a bitwise OR between the result of the AND operation and
208 the value specified by OrData, and writes the result to the 8-bit PCI
209 configuration register specified by Address. The value written to the PCI
210 configuration register is returned. This function must guarantee that all PCI
211 read and write operations are serialized.
213 If Address > 0x0FFFFFFF, then ASSERT().
215 @param Address Address that encodes the PCI Bus, Device, Function and
217 @param AndData The value to AND with the PCI configuration register.
218 @param OrData The value to OR with the result of the AND operation.
220 @return The value written back to the PCI configuration register.
231 return InternalSavePciWrite8ValueToBootScript (Address
, PciAndThenOr8 (Address
, AndData
, OrData
));
235 Reads a bit field of a PCI configuration register and saves the value in
236 the S3 script to be replayed on S3 resume.
238 Reads the bit field in an 8-bit PCI configuration register. The bit field is
239 specified by the StartBit and the EndBit. The value of the bit field is
242 If Address > 0x0FFFFFFF, then ASSERT().
243 If StartBit is greater than 7, then ASSERT().
244 If EndBit is greater than 7, then ASSERT().
245 If EndBit is less than StartBit, then ASSERT().
247 @param Address PCI configuration register to read.
248 @param StartBit The ordinal of the least significant bit in the bit field.
250 @param EndBit The ordinal of the most significant bit in the bit field.
253 @return The value of the bit field read from the PCI configuration register.
264 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldRead8 (Address
, StartBit
, EndBit
));
268 Writes a bit field to a PCI configuration register and saves the value in
269 the S3 script to be replayed on S3 resume.
271 Writes Value to the bit field of the PCI configuration register. The bit
272 field is specified by the StartBit and the EndBit. All other bits in the
273 destination PCI configuration register are preserved. The new value of the
274 8-bit register is returned.
276 If Address > 0x0FFFFFFF, then ASSERT().
277 If StartBit is greater than 7, then ASSERT().
278 If EndBit is greater than 7, then ASSERT().
279 If EndBit is less than StartBit, then ASSERT().
280 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
282 @param Address PCI configuration register to write.
283 @param StartBit The ordinal of the least significant bit in the bit field.
285 @param EndBit The ordinal of the most significant bit in the bit field.
287 @param Value New value of the bit field.
289 @return The value written back to the PCI configuration register.
294 S3PciBitFieldWrite8 (
301 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldWrite8 (Address
, StartBit
, EndBit
, Value
));
305 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and
306 writes the result back to the bit field in the 8-bit port and saves the value
307 in the S3 script to be replayed on S3 resume.
309 Reads the 8-bit PCI configuration register specified by Address, performs a
310 bitwise OR between the read result and the value specified by
311 OrData, and writes the result to the 8-bit PCI configuration register
312 specified by Address. The value written to the PCI configuration register is
313 returned. This function must guarantee that all PCI read and write operations
314 are serialized. Extra left bits in OrData are stripped.
316 If Address > 0x0FFFFFFF, then ASSERT().
317 If StartBit is greater than 7, then ASSERT().
318 If EndBit is greater than 7, then ASSERT().
319 If EndBit is less than StartBit, then ASSERT().
320 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
322 @param Address PCI configuration register to write.
323 @param StartBit The ordinal of the least significant bit in the bit field.
325 @param EndBit The ordinal of the most significant bit in the bit field.
327 @param OrData The value to OR with the PCI configuration register.
329 @return The value written back to the PCI configuration register.
341 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldOr8 (Address
, StartBit
, EndBit
, OrData
));
345 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise
346 AND, and writes the result back to the bit field in the 8-bit register and
347 saves the value in the S3 script to be replayed on S3 resume.
349 Reads the 8-bit PCI configuration register specified by Address, performs a
350 bitwise AND between the read result and the value specified by AndData, and
351 writes the result to the 8-bit PCI configuration register specified by
352 Address. The value written to the PCI configuration register is returned.
353 This function must guarantee that all PCI read and write operations are
354 serialized. Extra left bits in AndData are stripped.
356 If Address > 0x0FFFFFFF, then ASSERT().
357 If StartBit is greater than 7, then ASSERT().
358 If EndBit is greater than 7, then ASSERT().
359 If EndBit is less than StartBit, then ASSERT().
360 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
362 @param Address PCI configuration register to write.
363 @param StartBit The ordinal of the least significant bit in the bit field.
365 @param EndBit The ordinal of the most significant bit in the bit field.
367 @param AndData The value to AND with the PCI configuration register.
369 @return The value written back to the PCI configuration register.
381 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldAnd8 (Address
, StartBit
, EndBit
, AndData
));
385 Reads a bit field in an 8-bit Address, performs a bitwise AND followed by a
386 bitwise OR, and writes the result back to the bit field in the
387 8-bit port and saves the value in the S3 script to be replayed on S3 resume.
389 Reads the 8-bit PCI configuration register specified by Address, performs a
390 bitwise AND followed by a bitwise OR between the read result and
391 the value specified by AndData, and writes the result to the 8-bit PCI
392 configuration register specified by Address. The value written to the PCI
393 configuration register is returned. This function must guarantee that all PCI
394 read and write operations are serialized. Extra left bits in both AndData and
397 If Address > 0x0FFFFFFF, then ASSERT().
398 If StartBit is greater than 7, then ASSERT().
399 If EndBit is greater than 7, then ASSERT().
400 If EndBit is less than StartBit, then ASSERT().
401 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
402 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
404 @param Address PCI configuration register to write.
405 @param StartBit The ordinal of the least significant bit in the bit field.
407 @param EndBit The ordinal of the most significant bit in the bit field.
409 @param AndData The value to AND with the PCI configuration register.
410 @param OrData The value to OR with the result of the AND operation.
412 @return The value written back to the PCI configuration register.
417 S3PciBitFieldAndThenOr8 (
425 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldAndThenOr8 (Address
, StartBit
, EndBit
, AndData
, OrData
));
429 Saves a 16-bit PCI configuration value to the boot script.
431 This internal worker function saves a 16-bit PCI configuration value in
432 the S3 script to be replayed on S3 resume.
434 If the saving process fails, then ASSERT().
436 @param Address Address that encodes the PCI Bus, Device, Function and
438 @param Value The value to write.
444 InternalSavePciWrite16ValueToBootScript (
449 InternalSavePciWriteValueToBootScript (S3BootScriptWidthUint16
, Address
, &Value
);
455 Reads a 16-bit PCI configuration register and saves the value in the S3
456 script to be replayed on S3 resume.
458 Reads and returns the 16-bit PCI configuration register specified by Address.
459 This function must guarantee that all PCI read and write operations are
462 If Address > 0x0FFFFFFF, then ASSERT().
463 If Address is not aligned on a 16-bit boundary, then ASSERT().
465 @param Address Address that encodes the PCI Bus, Device, Function and
468 @return The read value from the PCI configuration register.
477 return InternalSavePciWrite16ValueToBootScript (Address
, PciRead16 (Address
));
481 Writes a 16-bit PCI configuration register and saves the value in the S3
482 script to be replayed on S3 resume.
484 Writes the 16-bit PCI configuration register specified by Address with the
485 value specified by Value. Value is returned. This function must guarantee
486 that all PCI read and write operations are serialized.
488 If Address > 0x0FFFFFFF, then ASSERT().
489 If Address is not aligned on a 16-bit boundary, then ASSERT().
491 @param Address Address that encodes the PCI Bus, Device, Function and
493 @param Value The value to write.
495 @return The value written to the PCI configuration register.
505 return InternalSavePciWrite16ValueToBootScript (Address
, PciWrite16 (Address
, Value
));
509 Performs a bitwise OR of a 16-bit PCI configuration register with
510 a 16-bit value and saves the value in the S3 script to be replayed on S3 resume.
512 Reads the 16-bit PCI configuration register specified by Address, performs a
513 bitwise OR between the read result and the value specified by
514 OrData, and writes the result to the 16-bit PCI configuration register
515 specified by Address. The value written to the PCI configuration register is
516 returned. This function must guarantee that all PCI read and write operations
519 If Address > 0x0FFFFFFF, then ASSERT().
520 If Address is not aligned on a 16-bit boundary, then ASSERT().
522 @param Address Address that encodes the PCI Bus, Device, Function and
524 @param OrData The value to OR with the PCI configuration register.
526 @return The value written back to the PCI configuration register.
536 return InternalSavePciWrite16ValueToBootScript (Address
, PciOr16 (Address
, OrData
));
540 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
541 value and saves the value in the S3 script to be replayed on S3 resume.
543 Reads the 16-bit PCI configuration register specified by Address, performs a
544 bitwise AND between the read result and the value specified by AndData, and
545 writes the result to the 16-bit PCI configuration register specified by
546 Address. The value written to the PCI configuration register is returned.
547 This function must guarantee that all PCI read and write operations are
550 If Address > 0x0FFFFFFF, then ASSERT().
551 If Address is not aligned on a 16-bit boundary, then ASSERT().
553 @param Address Address that encodes the PCI Bus, Device, Function and
555 @param AndData The value to AND with the PCI configuration register.
557 @return The value written back to the PCI configuration register.
567 return InternalSavePciWrite16ValueToBootScript (Address
, PciAnd16 (Address
, AndData
));
571 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
572 value, followed a bitwise OR with another 16-bit value and saves
573 the value in the S3 script to be replayed on S3 resume.
575 Reads the 16-bit PCI configuration register specified by Address, performs a
576 bitwise AND between the read result and the value specified by AndData,
577 performs a bitwise OR between the result of the AND operation and
578 the value specified by OrData, and writes the result to the 16-bit PCI
579 configuration register specified by Address. The value written to the PCI
580 configuration register is returned. This function must guarantee that all PCI
581 read and write operations are serialized.
583 If Address > 0x0FFFFFFF, then ASSERT().
584 If Address is not aligned on a 16-bit boundary, then ASSERT().
586 @param Address Address that encodes the PCI Bus, Device, Function and
588 @param AndData The value to AND with the PCI configuration register.
589 @param OrData The value to OR with the result of the AND operation.
591 @return The value written back to the PCI configuration register.
602 return InternalSavePciWrite16ValueToBootScript (Address
, PciAndThenOr16 (Address
, AndData
, OrData
));
606 Reads a bit field of a PCI configuration register and saves the value in
607 the S3 script to be replayed on S3 resume.
609 Reads the bit field in a 16-bit PCI configuration register. The bit field is
610 specified by the StartBit and the EndBit. The value of the bit field is
613 If Address > 0x0FFFFFFF, then ASSERT().
614 If Address is not aligned on a 16-bit boundary, then ASSERT().
615 If StartBit is greater than 15, then ASSERT().
616 If EndBit is greater than 15, then ASSERT().
617 If EndBit is less than StartBit, then ASSERT().
619 @param Address PCI configuration register to read.
620 @param StartBit The ordinal of the least significant bit in the bit field.
622 @param EndBit The ordinal of the most significant bit in the bit field.
625 @return The value of the bit field read from the PCI configuration register.
630 S3PciBitFieldRead16 (
636 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldRead16 (Address
, StartBit
, EndBit
));
640 Writes a bit field to a PCI configuration register and saves the value in
641 the S3 script to be replayed on S3 resume.
643 Writes Value to the bit field of the PCI configuration register. The bit
644 field is specified by the StartBit and the EndBit. All other bits in the
645 destination PCI configuration register are preserved. The new value of the
646 16-bit register is returned.
648 If Address > 0x0FFFFFFF, then ASSERT().
649 If Address is not aligned on a 16-bit boundary, then ASSERT().
650 If StartBit is greater than 15, then ASSERT().
651 If EndBit is greater than 15, then ASSERT().
652 If EndBit is less than StartBit, then ASSERT().
653 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
655 @param Address PCI configuration register to write.
656 @param StartBit The ordinal of the least significant bit in the bit field.
658 @param EndBit The ordinal of the most significant bit in the bit field.
660 @param Value New value of the bit field.
662 @return The value written back to the PCI configuration register.
667 S3PciBitFieldWrite16 (
674 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldWrite16 (Address
, StartBit
, EndBit
, Value
));
678 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, and
679 writes the result back to the bit field in the 16-bit port and saves the value
680 in the S3 script to be replayed on S3 resume.
682 Reads the 16-bit PCI configuration register specified by Address, performs a
683 bitwise OR between the read result and the value specified by
684 OrData, and writes the result to the 16-bit PCI configuration register
685 specified by Address. The value written to the PCI configuration register is
686 returned. This function must guarantee that all PCI read and write operations
687 are serialized. Extra left bits in OrData are stripped.
689 If Address > 0x0FFFFFFF, then ASSERT().
690 If Address is not aligned on a 16-bit boundary, then ASSERT().
691 If StartBit is greater than 15, then ASSERT().
692 If EndBit is greater than 15, then ASSERT().
693 If EndBit is less than StartBit, then ASSERT().
694 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
696 @param Address PCI configuration register to write.
697 @param StartBit The ordinal of the least significant bit in the bit field.
699 @param EndBit The ordinal of the most significant bit in the bit field.
701 @param OrData The value to OR with the PCI configuration register.
703 @return The value written back to the PCI configuration register.
715 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldOr16 (Address
, StartBit
, EndBit
, OrData
));
719 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
720 AND, and writes the result back to the bit field in the 16-bit register and
721 saves the value in the S3 script to be replayed on S3 resume.
723 Reads the 16-bit PCI configuration register specified by Address, performs a
724 bitwise AND between the read result and the value specified by AndData, and
725 writes the result to the 16-bit PCI configuration register specified by
726 Address. The value written to the PCI configuration register is returned.
727 This function must guarantee that all PCI read and write operations are
728 serialized. Extra left bits in AndData are stripped.
730 If Address > 0x0FFFFFFF, then ASSERT().
731 If Address is not aligned on a 16-bit boundary, then ASSERT().
732 If StartBit is greater than 15, then ASSERT().
733 If EndBit is greater than 15, then ASSERT().
734 If EndBit is less than StartBit, then ASSERT().
735 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
737 @param Address PCI configuration register to write.
738 @param StartBit The ordinal of the least significant bit in the bit field.
740 @param EndBit The ordinal of the most significant bit in the bit field.
742 @param AndData The value to AND with the PCI configuration register.
744 @return The value written back to the PCI configuration register.
756 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldAnd16 (Address
, StartBit
, EndBit
, AndData
));
760 Reads a bit field in a 16-bit Address, performs a bitwise AND followed by a
761 bitwise OR, and writes the result back to the bit field in the
762 16-bit port and saves the value in the S3 script to be replayed on S3 resume.
764 Reads the 16-bit PCI configuration register specified by Address, performs a
765 bitwise AND followed by a bitwise OR between the read result and
766 the value specified by AndData, and writes the result to the 16-bit PCI
767 configuration register specified by Address. The value written to the PCI
768 configuration register is returned. This function must guarantee that all PCI
769 read and write operations are serialized. Extra left bits in both AndData and
772 If Address > 0x0FFFFFFF, then ASSERT().
773 If Address is not aligned on a 16-bit boundary, then ASSERT().
774 If StartBit is greater than 15, then ASSERT().
775 If EndBit is greater than 15, then ASSERT().
776 If EndBit is less than StartBit, then ASSERT().
777 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
778 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
780 @param Address PCI configuration register to write.
781 @param StartBit The ordinal of the least significant bit in the bit field.
783 @param EndBit The ordinal of the most significant bit in the bit field.
785 @param AndData The value to AND with the PCI configuration register.
786 @param OrData The value to OR with the result of the AND operation.
788 @return The value written back to the PCI configuration register.
793 S3PciBitFieldAndThenOr16 (
801 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldAndThenOr16 (Address
, StartBit
, EndBit
, AndData
, OrData
));
805 Saves a 32-bit PCI configuration value to the boot script.
807 This internal worker function saves a 32-bit PCI configuration value in the S3 script
808 to be replayed on S3 resume.
810 If the saving process fails, then ASSERT().
812 @param Address Address that encodes the PCI Bus, Device, Function and
814 @param Value The value to write.
820 InternalSavePciWrite32ValueToBootScript (
825 InternalSavePciWriteValueToBootScript (S3BootScriptWidthUint32
, Address
, &Value
);
831 Reads a 32-bit PCI configuration register and saves the value in the S3
832 script to be replayed on S3 resume.
834 Reads and returns the 32-bit PCI configuration register specified by Address.
835 This function must guarantee that all PCI read and write operations are
838 If Address > 0x0FFFFFFF, then ASSERT().
839 If Address is not aligned on a 32-bit boundary, then ASSERT().
841 @param Address Address that encodes the PCI Bus, Device, Function and
844 @return The read value from the PCI configuration register.
853 return InternalSavePciWrite32ValueToBootScript (Address
, PciRead32 (Address
));
857 Writes a 32-bit PCI configuration register and saves the value in the S3
858 script to be replayed on S3 resume.
860 Writes the 32-bit PCI configuration register specified by Address with the
861 value specified by Value. Value is returned. This function must guarantee
862 that all PCI read and write operations are serialized.
864 If Address > 0x0FFFFFFF, then ASSERT().
865 If Address is not aligned on a 32-bit boundary, then ASSERT().
867 @param Address Address that encodes the PCI Bus, Device, Function and
869 @param Value The value to write.
871 @return The value written to the PCI configuration register.
881 return InternalSavePciWrite32ValueToBootScript (Address
, PciWrite32 (Address
, Value
));
885 Performs a bitwise OR of a 32-bit PCI configuration register with
886 a 32-bit value and saves the value in the S3 script to be replayed on S3 resume.
888 Reads the 32-bit PCI configuration register specified by Address, performs a
889 bitwise OR between the read result and the value specified by
890 OrData, and writes the result to the 32-bit PCI configuration register
891 specified by Address. The value written to the PCI configuration register is
892 returned. This function must guarantee that all PCI read and write operations
895 If Address > 0x0FFFFFFF, then ASSERT().
896 If Address is not aligned on a 32-bit boundary, then ASSERT().
898 @param Address Address that encodes the PCI Bus, Device, Function and
900 @param OrData The value to OR with the PCI configuration register.
902 @return The value written back to the PCI configuration register.
912 return InternalSavePciWrite32ValueToBootScript (Address
, PciOr32 (Address
, OrData
));
916 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
917 value and saves the value in the S3 script to be replayed on S3 resume.
919 Reads the 32-bit PCI configuration register specified by Address, performs a
920 bitwise AND between the read result and the value specified by AndData, and
921 writes the result to the 32-bit PCI configuration register specified by
922 Address. The value written to the PCI configuration register is returned.
923 This function must guarantee that all PCI read and write operations are
926 If Address > 0x0FFFFFFF, then ASSERT().
927 If Address is not aligned on a 32-bit boundary, then ASSERT().
929 @param Address Address that encodes the PCI Bus, Device, Function and
931 @param AndData The value to AND with the PCI configuration register.
933 @return The value written back to the PCI configuration register.
943 return InternalSavePciWrite32ValueToBootScript (Address
, PciAnd32 (Address
, AndData
));
947 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
948 value, followed a bitwise OR with another 32-bit value and saves
949 the value in the S3 script to be replayed on S3 resume.
951 Reads the 32-bit PCI configuration register specified by Address, performs a
952 bitwise AND between the read result and the value specified by AndData,
953 performs a bitwise OR between the result of the AND operation and
954 the value specified by OrData, and writes the result to the 32-bit PCI
955 configuration register specified by Address. The value written to the PCI
956 configuration register is returned. This function must guarantee that all PCI
957 read and write operations are serialized.
959 If Address > 0x0FFFFFFF, then ASSERT().
960 If Address is not aligned on a 32-bit boundary, then ASSERT().
962 @param Address Address that encodes the PCI Bus, Device, Function and
964 @param AndData The value to AND with the PCI configuration register.
965 @param OrData The value to OR with the result of the AND operation.
967 @return The value written back to the PCI configuration register.
978 return InternalSavePciWrite32ValueToBootScript (Address
, PciAndThenOr32 (Address
, AndData
, OrData
));
982 Reads a bit field of a PCI configuration register and saves the value in
983 the S3 script to be replayed on S3 resume.
985 Reads the bit field in a 32-bit PCI configuration register. The bit field is
986 specified by the StartBit and the EndBit. The value of the bit field is
989 If Address > 0x0FFFFFFF, then ASSERT().
990 If Address is not aligned on a 32-bit boundary, then ASSERT().
991 If StartBit is greater than 31, then ASSERT().
992 If EndBit is greater than 31, then ASSERT().
993 If EndBit is less than StartBit, then ASSERT().
995 @param Address PCI configuration register to read.
996 @param StartBit The ordinal of the least significant bit in the bit field.
998 @param EndBit The ordinal of the most significant bit in the bit field.
1001 @return The value of the bit field read from the PCI configuration register.
1006 S3PciBitFieldRead32 (
1012 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldRead32 (Address
, StartBit
, EndBit
));
1016 Writes a bit field to a PCI configuration register and saves the value in
1017 the S3 script to be replayed on S3 resume.
1019 Writes Value to the bit field of the PCI configuration register. The bit
1020 field is specified by the StartBit and the EndBit. All other bits in the
1021 destination PCI configuration register are preserved. The new value of the
1022 32-bit register is returned.
1024 If Address > 0x0FFFFFFF, then ASSERT().
1025 If Address is not aligned on a 32-bit boundary, then ASSERT().
1026 If StartBit is greater than 31, then ASSERT().
1027 If EndBit is greater than 31, then ASSERT().
1028 If EndBit is less than StartBit, then ASSERT().
1029 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1031 @param Address PCI configuration register to write.
1032 @param StartBit The ordinal of the least significant bit in the bit field.
1034 @param EndBit The ordinal of the most significant bit in the bit field.
1036 @param Value New value of the bit field.
1038 @return The value written back to the PCI configuration register.
1043 S3PciBitFieldWrite32 (
1050 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldWrite32 (Address
, StartBit
, EndBit
, Value
));
1054 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and
1055 writes the result back to the bit field in the 32-bit port and saves the value
1056 in the S3 script to be replayed on S3 resume.
1058 Reads the 32-bit PCI configuration register specified by Address, performs a
1059 bitwise OR between the read result and the value specified by
1060 OrData, and writes the result to the 32-bit PCI configuration register
1061 specified by Address. The value written to the PCI configuration register is
1062 returned. This function must guarantee that all PCI read and write operations
1063 are serialized. Extra left bits in OrData are stripped.
1065 If Address > 0x0FFFFFFF, then ASSERT().
1066 If Address is not aligned on a 32-bit boundary, then ASSERT().
1067 If StartBit is greater than 31, then ASSERT().
1068 If EndBit is greater than 31, then ASSERT().
1069 If EndBit is less than StartBit, then ASSERT().
1070 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1072 @param Address PCI configuration register to write.
1073 @param StartBit The ordinal of the least significant bit in the bit field.
1075 @param EndBit The ordinal of the most significant bit in the bit field.
1077 @param OrData The value to OR with the PCI configuration register.
1079 @return The value written back to the PCI configuration register.
1091 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldOr32 (Address
, StartBit
, EndBit
, OrData
));
1095 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise
1096 AND, and writes the result back to the bit field in the 32-bit register and
1097 saves the value in the S3 script to be replayed on S3 resume.
1099 Reads the 32-bit PCI configuration register specified by Address, performs a
1100 bitwise AND between the read result and the value specified by AndData, and
1101 writes the result to the 32-bit PCI configuration register specified by
1102 Address. The value written to the PCI configuration register is returned.
1103 This function must guarantee that all PCI read and write operations are
1104 serialized. Extra left bits in AndData are stripped.
1106 If Address > 0x0FFFFFFF, then ASSERT().
1107 If Address is not aligned on a 32-bit boundary, then ASSERT().
1108 If StartBit is greater than 31, then ASSERT().
1109 If EndBit is greater than 31, then ASSERT().
1110 If EndBit is less than StartBit, then ASSERT().
1111 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1113 @param Address PCI configuration register to write.
1114 @param StartBit The ordinal of the least significant bit in the bit field.
1116 @param EndBit The ordinal of the most significant bit in the bit field.
1118 @param AndData The value to AND with the PCI configuration register.
1120 @return The value written back to the PCI configuration register.
1125 S3PciBitFieldAnd32 (
1132 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldAnd32 (Address
, StartBit
, EndBit
, AndData
));
1136 Reads a bit field in a 32-bit Address, performs a bitwise AND followed by a
1137 bitwise OR, and writes the result back to the bit field in the
1138 32-bit port and saves the value in the S3 script to be replayed on S3 resume.
1140 Reads the 32-bit PCI configuration register specified by Address, performs a
1141 bitwise AND followed by a bitwise OR between the read result and
1142 the value specified by AndData, and writes the result to the 32-bit PCI
1143 configuration register specified by Address. The value written to the PCI
1144 configuration register is returned. This function must guarantee that all PCI
1145 read and write operations are serialized. Extra left bits in both AndData and
1146 OrData are stripped.
1148 If Address > 0x0FFFFFFF, then ASSERT().
1149 If Address is not aligned on a 32-bit boundary, then ASSERT().
1150 If StartBit is greater than 31, then ASSERT().
1151 If EndBit is greater than 31, then ASSERT().
1152 If EndBit is less than StartBit, then ASSERT().
1153 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1154 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1156 @param Address PCI configuration register to write.
1157 @param StartBit The ordinal of the least significant bit in the bit field.
1159 @param EndBit The ordinal of the most significant bit in the bit field.
1161 @param AndData The value to AND with the PCI configuration register.
1162 @param OrData The value to OR with the result of the AND operation.
1164 @return The value written back to the PCI configuration register.
1169 S3PciBitFieldAndThenOr32 (
1177 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldAndThenOr32 (Address
, StartBit
, EndBit
, AndData
, OrData
));
1181 Reads a range of PCI configuration registers into a caller supplied buffer
1182 and saves the value in the S3 script to be replayed on S3 resume.
1184 Reads the range of PCI configuration registers specified by StartAddress and
1185 Size into the buffer specified by Buffer. This function only allows the PCI
1186 configuration registers from a single PCI function to be read. Size is
1187 returned. When possible 32-bit PCI configuration read cycles are used to read
1188 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit
1189 and 16-bit PCI configuration read cycles may be used at the beginning and the
1192 If StartAddress > 0x0FFFFFFF, then ASSERT().
1193 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1194 If Size > 0 and Buffer is NULL, then ASSERT().
1196 @param StartAddress Starting address that encodes the PCI Bus, Device,
1197 Function and Register.
1198 @param Size Size in bytes of the transfer.
1199 @param Buffer Pointer to a buffer receiving the data read.
1207 IN UINTN StartAddress
,
1212 RETURN_STATUS Status
;
1214 Status
= S3BootScriptSavePciCfgWrite (
1215 S3BootScriptWidthUint8
,
1216 PCILIB_TO_COMMON_ADDRESS (StartAddress
),
1217 PciReadBuffer (StartAddress
, Size
, Buffer
),
1220 ASSERT (Status
== RETURN_SUCCESS
);
1226 Copies the data in a caller supplied buffer to a specified range of PCI
1227 configuration space and saves the value in the S3 script to be replayed on S3
1230 Writes the range of PCI configuration registers specified by StartAddress and
1231 Size from the buffer specified by Buffer. This function only allows the PCI
1232 configuration registers from a single PCI function to be written. Size is
1233 returned. When possible 32-bit PCI configuration write cycles are used to
1234 write from StartAdress to StartAddress + Size. Due to alignment restrictions,
1235 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
1236 and the end of the range.
1238 If StartAddress > 0x0FFFFFFF, then ASSERT().
1239 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1240 If Size > 0 and Buffer is NULL, then ASSERT().
1242 @param StartAddress Starting address that encodes the PCI Bus, Device,
1243 Function and Register.
1244 @param Size Size in bytes of the transfer.
1245 @param Buffer Pointer to a buffer containing the data to write.
1253 IN UINTN StartAddress
,
1258 RETURN_STATUS Status
;
1260 Status
= S3BootScriptSavePciCfgWrite (
1261 S3BootScriptWidthUint8
,
1262 PCILIB_TO_COMMON_ADDRESS (StartAddress
),
1263 PciWriteBuffer (StartAddress
, Size
, Buffer
),
1266 ASSERT (Status
== RETURN_SUCCESS
);