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, 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 ((UINT64) ((((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().
281 @param Address PCI configuration register to write.
282 @param StartBit The ordinal of the least significant bit in the bit field.
284 @param EndBit The ordinal of the most significant bit in the bit field.
286 @param Value New value of the bit field.
288 @return The value written back to the PCI configuration register.
293 S3PciBitFieldWrite8 (
300 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldWrite8 (Address
, StartBit
, EndBit
, Value
));
304 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and
305 writes the result back to the bit field in the 8-bit port and saves the value
306 in the S3 script to be replayed on S3 resume.
308 Reads the 8-bit PCI configuration register specified by Address, performs a
309 bitwise OR between the read result and the value specified by
310 OrData, and writes the result to the 8-bit PCI configuration register
311 specified by Address. The value written to the PCI configuration register is
312 returned. This function must guarantee that all PCI read and write operations
313 are serialized. Extra left bits in OrData are stripped.
315 If Address > 0x0FFFFFFF, then ASSERT().
316 If StartBit is greater than 7, then ASSERT().
317 If EndBit is greater than 7, then ASSERT().
318 If EndBit is less than StartBit, then ASSERT().
320 @param Address PCI configuration register to write.
321 @param StartBit The ordinal of the least significant bit in the bit field.
323 @param EndBit The ordinal of the most significant bit in the bit field.
325 @param OrData The value to OR with the PCI configuration register.
327 @return The value written back to the PCI configuration register.
339 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldOr8 (Address
, StartBit
, EndBit
, OrData
));
343 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise
344 AND, and writes the result back to the bit field in the 8-bit register and
345 saves the value in the S3 script to be replayed on S3 resume.
347 Reads the 8-bit PCI configuration register specified by Address, performs a
348 bitwise AND between the read result and the value specified by AndData, and
349 writes the result to the 8-bit PCI configuration register specified by
350 Address. The value written to the PCI configuration register is returned.
351 This function must guarantee that all PCI read and write operations are
352 serialized. Extra left bits in AndData are stripped.
354 If Address > 0x0FFFFFFF, then ASSERT().
355 If StartBit is greater than 7, then ASSERT().
356 If EndBit is greater than 7, then ASSERT().
357 If EndBit is less than StartBit, then ASSERT().
359 @param Address PCI configuration register to write.
360 @param StartBit The ordinal of the least significant bit in the bit field.
362 @param EndBit The ordinal of the most significant bit in the bit field.
364 @param AndData The value to AND with the PCI configuration register.
366 @return The value written back to the PCI configuration register.
378 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldAnd8 (Address
, StartBit
, EndBit
, AndData
));
382 Reads a bit field in an 8-bit Address, performs a bitwise AND followed by a
383 bitwise OR, and writes the result back to the bit field in the
384 8-bit port and saves the value in the S3 script to be replayed on S3 resume.
386 Reads the 8-bit PCI configuration register specified by Address, performs a
387 bitwise AND followed by a bitwise OR between the read result and
388 the value specified by AndData, and writes the result to the 8-bit PCI
389 configuration register specified by Address. The value written to the PCI
390 configuration register is returned. This function must guarantee that all PCI
391 read and write operations are serialized. Extra left bits in both AndData and
394 If Address > 0x0FFFFFFF, then ASSERT().
395 If StartBit is greater than 7, then ASSERT().
396 If EndBit is greater than 7, then ASSERT().
397 If EndBit is less than StartBit, then ASSERT().
399 @param Address PCI configuration register to write.
400 @param StartBit The ordinal of the least significant bit in the bit field.
402 @param EndBit The ordinal of the most significant bit in the bit field.
404 @param AndData The value to AND with the PCI configuration register.
405 @param OrData The value to OR with the result of the AND operation.
407 @return The value written back to the PCI configuration register.
412 S3PciBitFieldAndThenOr8 (
420 return InternalSavePciWrite8ValueToBootScript (Address
, PciBitFieldAndThenOr8 (Address
, StartBit
, EndBit
, AndData
, OrData
));
424 Saves a 16-bit PCI configuration value to the boot script.
426 This internal worker function saves a 16-bit PCI configuration value in
427 the S3 script to be replayed on S3 resume.
429 If the saving process fails, then ASSERT().
431 @param Address Address that encodes the PCI Bus, Device, Function and
433 @param Value The value to write.
439 InternalSavePciWrite16ValueToBootScript (
444 InternalSavePciWriteValueToBootScript (S3BootScriptWidthUint16
, Address
, &Value
);
450 Reads a 16-bit PCI configuration register and saves the value in the S3
451 script to be replayed on S3 resume.
453 Reads and returns the 16-bit PCI configuration register specified by Address.
454 This function must guarantee that all PCI read and write operations are
457 If Address > 0x0FFFFFFF, then ASSERT().
458 If Address is not aligned on a 16-bit boundary, then ASSERT().
460 @param Address Address that encodes the PCI Bus, Device, Function and
463 @return The read value from the PCI configuration register.
472 return InternalSavePciWrite16ValueToBootScript (Address
, PciRead16 (Address
));
476 Writes a 16-bit PCI configuration register and saves the value in the S3
477 script to be replayed on S3 resume.
479 Writes the 16-bit PCI configuration register specified by Address with the
480 value specified by Value. Value is returned. This function must guarantee
481 that all PCI read and write operations are serialized.
483 If Address > 0x0FFFFFFF, then ASSERT().
484 If Address is not aligned on a 16-bit boundary, then ASSERT().
486 @param Address Address that encodes the PCI Bus, Device, Function and
488 @param Value The value to write.
490 @return The value written to the PCI configuration register.
500 return InternalSavePciWrite16ValueToBootScript (Address
, PciWrite16 (Address
, Value
));
504 Performs a bitwise OR of a 16-bit PCI configuration register with
505 a 16-bit value and saves the value in the S3 script to be replayed on S3 resume.
507 Reads the 16-bit PCI configuration register specified by Address, performs a
508 bitwise OR between the read result and the value specified by
509 OrData, and writes the result to the 16-bit PCI configuration register
510 specified by Address. The value written to the PCI configuration register is
511 returned. This function must guarantee that all PCI read and write operations
514 If Address > 0x0FFFFFFF, then ASSERT().
515 If Address is not aligned on a 16-bit boundary, then ASSERT().
517 @param Address Address that encodes the PCI Bus, Device, Function and
519 @param OrData The value to OR with the PCI configuration register.
521 @return The value written back to the PCI configuration register.
531 return InternalSavePciWrite16ValueToBootScript (Address
, PciOr16 (Address
, OrData
));
535 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
536 value and saves the value in the S3 script to be replayed on S3 resume.
538 Reads the 16-bit PCI configuration register specified by Address, performs a
539 bitwise AND between the read result and the value specified by AndData, and
540 writes the result to the 16-bit PCI configuration register specified by
541 Address. The value written to the PCI configuration register is returned.
542 This function must guarantee that all PCI read and write operations are
545 If Address > 0x0FFFFFFF, then ASSERT().
546 If Address is not aligned on a 16-bit boundary, then ASSERT().
548 @param Address Address that encodes the PCI Bus, Device, Function and
550 @param AndData The value to AND with the PCI configuration register.
552 @return The value written back to the PCI configuration register.
562 return InternalSavePciWrite16ValueToBootScript (Address
, PciAnd16 (Address
, AndData
));
566 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
567 value, followed a bitwise OR with another 16-bit value and saves
568 the value in the S3 script to be replayed on S3 resume.
570 Reads the 16-bit PCI configuration register specified by Address, performs a
571 bitwise AND between the read result and the value specified by AndData,
572 performs a bitwise OR between the result of the AND operation and
573 the value specified by OrData, and writes the result to the 16-bit PCI
574 configuration register specified by Address. The value written to the PCI
575 configuration register is returned. This function must guarantee that all PCI
576 read and write operations are serialized.
578 If Address > 0x0FFFFFFF, then ASSERT().
579 If Address is not aligned on a 16-bit boundary, then ASSERT().
581 @param Address Address that encodes the PCI Bus, Device, Function and
583 @param AndData The value to AND with the PCI configuration register.
584 @param OrData The value to OR with the result of the AND operation.
586 @return The value written back to the PCI configuration register.
597 return InternalSavePciWrite16ValueToBootScript (Address
, PciAndThenOr16 (Address
, AndData
, OrData
));
601 Reads a bit field of a PCI configuration register and saves the value in
602 the S3 script to be replayed on S3 resume.
604 Reads the bit field in a 16-bit PCI configuration register. The bit field is
605 specified by the StartBit and the EndBit. The value of the bit field is
608 If Address > 0x0FFFFFFF, then ASSERT().
609 If Address is not aligned on a 16-bit boundary, then ASSERT().
610 If StartBit is greater than 15, then ASSERT().
611 If EndBit is greater than 15, then ASSERT().
612 If EndBit is less than StartBit, then ASSERT().
614 @param Address PCI configuration register to read.
615 @param StartBit The ordinal of the least significant bit in the bit field.
617 @param EndBit The ordinal of the most significant bit in the bit field.
620 @return The value of the bit field read from the PCI configuration register.
625 S3PciBitFieldRead16 (
631 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldRead16 (Address
, StartBit
, EndBit
));
635 Writes a bit field to a PCI configuration register and saves the value in
636 the S3 script to be replayed on S3 resume.
638 Writes Value to the bit field of the PCI configuration register. The bit
639 field is specified by the StartBit and the EndBit. All other bits in the
640 destination PCI configuration register are preserved. The new value of the
641 16-bit register is returned.
643 If Address > 0x0FFFFFFF, then ASSERT().
644 If Address is not aligned on a 16-bit boundary, then ASSERT().
645 If StartBit is greater than 15, then ASSERT().
646 If EndBit is greater than 15, then ASSERT().
647 If EndBit is less than StartBit, then ASSERT().
649 @param Address PCI configuration register to write.
650 @param StartBit The ordinal of the least significant bit in the bit field.
652 @param EndBit The ordinal of the most significant bit in the bit field.
654 @param Value New value of the bit field.
656 @return The value written back to the PCI configuration register.
661 S3PciBitFieldWrite16 (
668 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldWrite16 (Address
, StartBit
, EndBit
, Value
));
672 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, and
673 writes the result back to the bit field in the 16-bit port and saves the value
674 in the S3 script to be replayed on S3 resume.
676 Reads the 16-bit PCI configuration register specified by Address, performs a
677 bitwise OR between the read result and the value specified by
678 OrData, and writes the result to the 16-bit PCI configuration register
679 specified by Address. The value written to the PCI configuration register is
680 returned. This function must guarantee that all PCI read and write operations
681 are serialized. Extra left bits in OrData are stripped.
683 If Address > 0x0FFFFFFF, then ASSERT().
684 If Address is not aligned on a 16-bit boundary, then ASSERT().
685 If StartBit is greater than 15, then ASSERT().
686 If EndBit is greater than 15, then ASSERT().
687 If EndBit is less than StartBit, then ASSERT().
689 @param Address PCI configuration register to write.
690 @param StartBit The ordinal of the least significant bit in the bit field.
692 @param EndBit The ordinal of the most significant bit in the bit field.
694 @param OrData The value to OR with the PCI configuration register.
696 @return The value written back to the PCI configuration register.
708 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldOr16 (Address
, StartBit
, EndBit
, OrData
));
712 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
713 AND, and writes the result back to the bit field in the 16-bit register and
714 saves the value in the S3 script to be replayed on S3 resume.
716 Reads the 16-bit PCI configuration register specified by Address, performs a
717 bitwise AND between the read result and the value specified by AndData, and
718 writes the result to the 16-bit PCI configuration register specified by
719 Address. The value written to the PCI configuration register is returned.
720 This function must guarantee that all PCI read and write operations are
721 serialized. Extra left bits in AndData are stripped.
723 If Address > 0x0FFFFFFF, then ASSERT().
724 If Address is not aligned on a 16-bit boundary, then ASSERT().
725 If StartBit is greater than 15, then ASSERT().
726 If EndBit is greater than 15, then ASSERT().
727 If EndBit is less than StartBit, then ASSERT().
729 @param Address PCI configuration register to write.
730 @param StartBit The ordinal of the least significant bit in the bit field.
732 @param EndBit The ordinal of the most significant bit in the bit field.
734 @param AndData The value to AND with the PCI configuration register.
736 @return The value written back to the PCI configuration register.
748 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldAnd16 (Address
, StartBit
, EndBit
, AndData
));
752 Reads a bit field in a 16-bit Address, performs a bitwise AND followed by a
753 bitwise OR, and writes the result back to the bit field in the
754 16-bit port and saves the value in the S3 script to be replayed on S3 resume.
756 Reads the 16-bit PCI configuration register specified by Address, performs a
757 bitwise AND followed by a bitwise OR between the read result and
758 the value specified by AndData, and writes the result to the 16-bit PCI
759 configuration register specified by Address. The value written to the PCI
760 configuration register is returned. This function must guarantee that all PCI
761 read and write operations are serialized. Extra left bits in both AndData and
764 If Address > 0x0FFFFFFF, then ASSERT().
765 If Address is not aligned on a 16-bit boundary, then ASSERT().
766 If StartBit is greater than 15, then ASSERT().
767 If EndBit is greater than 15, then ASSERT().
768 If EndBit is less than StartBit, then ASSERT().
770 @param Address PCI configuration register to write.
771 @param StartBit The ordinal of the least significant bit in the bit field.
773 @param EndBit The ordinal of the most significant bit in the bit field.
775 @param AndData The value to AND with the PCI configuration register.
776 @param OrData The value to OR with the result of the AND operation.
778 @return The value written back to the PCI configuration register.
783 S3PciBitFieldAndThenOr16 (
791 return InternalSavePciWrite16ValueToBootScript (Address
, PciBitFieldAndThenOr16 (Address
, StartBit
, EndBit
, AndData
, OrData
));
795 Saves a 32-bit PCI configuration value to the boot script.
797 This internal worker function saves a 32-bit PCI configuration value in the S3 script
798 to be replayed on S3 resume.
800 If the saving process fails, then ASSERT().
802 @param Address Address that encodes the PCI Bus, Device, Function and
804 @param Value The value to write.
810 InternalSavePciWrite32ValueToBootScript (
815 InternalSavePciWriteValueToBootScript (S3BootScriptWidthUint32
, Address
, &Value
);
821 Reads a 32-bit PCI configuration register and saves the value in the S3
822 script to be replayed on S3 resume.
824 Reads and returns the 32-bit PCI configuration register specified by Address.
825 This function must guarantee that all PCI read and write operations are
828 If Address > 0x0FFFFFFF, then ASSERT().
829 If Address is not aligned on a 32-bit boundary, then ASSERT().
831 @param Address Address that encodes the PCI Bus, Device, Function and
834 @return The read value from the PCI configuration register.
843 return InternalSavePciWrite32ValueToBootScript (Address
, PciRead32 (Address
));
847 Writes a 32-bit PCI configuration register and saves the value in the S3
848 script to be replayed on S3 resume.
850 Writes the 32-bit PCI configuration register specified by Address with the
851 value specified by Value. Value is returned. This function must guarantee
852 that all PCI read and write operations are serialized.
854 If Address > 0x0FFFFFFF, then ASSERT().
855 If Address is not aligned on a 32-bit boundary, then ASSERT().
857 @param Address Address that encodes the PCI Bus, Device, Function and
859 @param Value The value to write.
861 @return The value written to the PCI configuration register.
871 return InternalSavePciWrite32ValueToBootScript (Address
, PciWrite32 (Address
, Value
));
875 Performs a bitwise OR of a 32-bit PCI configuration register with
876 a 32-bit value and saves the value in the S3 script to be replayed on S3 resume.
878 Reads the 32-bit PCI configuration register specified by Address, performs a
879 bitwise OR between the read result and the value specified by
880 OrData, and writes the result to the 32-bit PCI configuration register
881 specified by Address. The value written to the PCI configuration register is
882 returned. This function must guarantee that all PCI read and write operations
885 If Address > 0x0FFFFFFF, then ASSERT().
886 If Address is not aligned on a 32-bit boundary, then ASSERT().
888 @param Address Address that encodes the PCI Bus, Device, Function and
890 @param OrData The value to OR with the PCI configuration register.
892 @return The value written back to the PCI configuration register.
902 return InternalSavePciWrite32ValueToBootScript (Address
, PciOr32 (Address
, OrData
));
906 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
907 value and saves the value in the S3 script to be replayed on S3 resume.
909 Reads the 32-bit PCI configuration register specified by Address, performs a
910 bitwise AND between the read result and the value specified by AndData, and
911 writes the result to the 32-bit PCI configuration register specified by
912 Address. The value written to the PCI configuration register is returned.
913 This function must guarantee that all PCI read and write operations are
916 If Address > 0x0FFFFFFF, then ASSERT().
917 If Address is not aligned on a 32-bit boundary, then ASSERT().
919 @param Address Address that encodes the PCI Bus, Device, Function and
921 @param AndData The value to AND with the PCI configuration register.
923 @return The value written back to the PCI configuration register.
933 return InternalSavePciWrite32ValueToBootScript (Address
, PciAnd32 (Address
, AndData
));
937 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
938 value, followed a bitwise OR with another 32-bit value and saves
939 the value in the S3 script to be replayed on S3 resume.
941 Reads the 32-bit PCI configuration register specified by Address, performs a
942 bitwise AND between the read result and the value specified by AndData,
943 performs a bitwise OR between the result of the AND operation and
944 the value specified by OrData, and writes the result to the 32-bit PCI
945 configuration register specified by Address. The value written to the PCI
946 configuration register is returned. This function must guarantee that all PCI
947 read and write operations are serialized.
949 If Address > 0x0FFFFFFF, then ASSERT().
950 If Address is not aligned on a 32-bit boundary, then ASSERT().
952 @param Address Address that encodes the PCI Bus, Device, Function and
954 @param AndData The value to AND with the PCI configuration register.
955 @param OrData The value to OR with the result of the AND operation.
957 @return The value written back to the PCI configuration register.
968 return InternalSavePciWrite32ValueToBootScript (Address
, PciAndThenOr32 (Address
, AndData
, OrData
));
972 Reads a bit field of a PCI configuration register and saves the value in
973 the S3 script to be replayed on S3 resume.
975 Reads the bit field in a 32-bit PCI configuration register. The bit field is
976 specified by the StartBit and the EndBit. The value of the bit field is
979 If Address > 0x0FFFFFFF, then ASSERT().
980 If Address is not aligned on a 32-bit boundary, then ASSERT().
981 If StartBit is greater than 31, then ASSERT().
982 If EndBit is greater than 31, then ASSERT().
983 If EndBit is less than StartBit, then ASSERT().
985 @param Address PCI configuration register to read.
986 @param StartBit The ordinal of the least significant bit in the bit field.
988 @param EndBit The ordinal of the most significant bit in the bit field.
991 @return The value of the bit field read from the PCI configuration register.
996 S3PciBitFieldRead32 (
1002 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldRead32 (Address
, StartBit
, EndBit
));
1006 Writes a bit field to a PCI configuration register and saves the value in
1007 the S3 script to be replayed on S3 resume.
1009 Writes Value to the bit field of the PCI configuration register. The bit
1010 field is specified by the StartBit and the EndBit. All other bits in the
1011 destination PCI configuration register are preserved. The new value of the
1012 32-bit register is returned.
1014 If Address > 0x0FFFFFFF, then ASSERT().
1015 If Address is not aligned on a 32-bit boundary, then ASSERT().
1016 If StartBit is greater than 31, then ASSERT().
1017 If EndBit is greater than 31, then ASSERT().
1018 If EndBit is less than StartBit, then ASSERT().
1020 @param Address PCI configuration register to write.
1021 @param StartBit The ordinal of the least significant bit in the bit field.
1023 @param EndBit The ordinal of the most significant bit in the bit field.
1025 @param Value New value of the bit field.
1027 @return The value written back to the PCI configuration register.
1032 S3PciBitFieldWrite32 (
1039 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldWrite32 (Address
, StartBit
, EndBit
, Value
));
1043 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and
1044 writes the result back to the bit field in the 32-bit port and saves the value
1045 in the S3 script to be replayed on S3 resume.
1047 Reads the 32-bit PCI configuration register specified by Address, performs a
1048 bitwise OR between the read result and the value specified by
1049 OrData, and writes the result to the 32-bit PCI configuration register
1050 specified by Address. The value written to the PCI configuration register is
1051 returned. This function must guarantee that all PCI read and write operations
1052 are serialized. Extra left bits in OrData are stripped.
1054 If Address > 0x0FFFFFFF, then ASSERT().
1055 If Address is not aligned on a 32-bit boundary, then ASSERT().
1056 If StartBit is greater than 31, then ASSERT().
1057 If EndBit is greater than 31, then ASSERT().
1058 If EndBit is less than StartBit, then ASSERT().
1060 @param Address PCI configuration register to write.
1061 @param StartBit The ordinal of the least significant bit in the bit field.
1063 @param EndBit The ordinal of the most significant bit in the bit field.
1065 @param OrData The value to OR with the PCI configuration register.
1067 @return The value written back to the PCI configuration register.
1079 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldOr32 (Address
, StartBit
, EndBit
, OrData
));
1083 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise
1084 AND, and writes the result back to the bit field in the 32-bit register and
1085 saves the value in the S3 script to be replayed on S3 resume.
1087 Reads the 32-bit PCI configuration register specified by Address, performs a
1088 bitwise AND between the read result and the value specified by AndData, and
1089 writes the result to the 32-bit PCI configuration register specified by
1090 Address. The value written to the PCI configuration register is returned.
1091 This function must guarantee that all PCI read and write operations are
1092 serialized. Extra left bits in AndData are stripped.
1094 If Address > 0x0FFFFFFF, then ASSERT().
1095 If Address is not aligned on a 32-bit boundary, then ASSERT().
1096 If StartBit is greater than 31, then ASSERT().
1097 If EndBit is greater than 31, then ASSERT().
1098 If EndBit is less than StartBit, then ASSERT().
1100 @param Address PCI configuration register to write.
1101 @param StartBit The ordinal of the least significant bit in the bit field.
1103 @param EndBit The ordinal of the most significant bit in the bit field.
1105 @param AndData The value to AND with the PCI configuration register.
1107 @return The value written back to the PCI configuration register.
1112 S3PciBitFieldAnd32 (
1119 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldAnd32 (Address
, StartBit
, EndBit
, AndData
));
1123 Reads a bit field in a 32-bit Address, performs a bitwise AND followed by a
1124 bitwise OR, and writes the result back to the bit field in the
1125 32-bit port and saves the value in the S3 script to be replayed on S3 resume.
1127 Reads the 32-bit PCI configuration register specified by Address, performs a
1128 bitwise AND followed by a bitwise OR between the read result and
1129 the value specified by AndData, and writes the result to the 32-bit PCI
1130 configuration register specified by Address. The value written to the PCI
1131 configuration register is returned. This function must guarantee that all PCI
1132 read and write operations are serialized. Extra left bits in both AndData and
1133 OrData are stripped.
1135 If Address > 0x0FFFFFFF, then ASSERT().
1136 If Address is not aligned on a 32-bit boundary, then ASSERT().
1137 If StartBit is greater than 31, then ASSERT().
1138 If EndBit is greater than 31, then ASSERT().
1139 If EndBit is less than StartBit, then ASSERT().
1141 @param Address PCI configuration register to write.
1142 @param StartBit The ordinal of the least significant bit in the bit field.
1144 @param EndBit The ordinal of the most significant bit in the bit field.
1146 @param AndData The value to AND with the PCI configuration register.
1147 @param OrData The value to OR with the result of the AND operation.
1149 @return The value written back to the PCI configuration register.
1154 S3PciBitFieldAndThenOr32 (
1162 return InternalSavePciWrite32ValueToBootScript (Address
, PciBitFieldAndThenOr32 (Address
, StartBit
, EndBit
, AndData
, OrData
));
1166 Reads a range of PCI configuration registers into a caller supplied buffer
1167 and saves the value in the S3 script to be replayed on S3 resume.
1169 Reads the range of PCI configuration registers specified by StartAddress and
1170 Size into the buffer specified by Buffer. This function only allows the PCI
1171 configuration registers from a single PCI function to be read. Size is
1172 returned. When possible 32-bit PCI configuration read cycles are used to read
1173 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit
1174 and 16-bit PCI configuration read cycles may be used at the beginning and the
1177 If StartAddress > 0x0FFFFFFF, then ASSERT().
1178 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1179 If Size > 0 and Buffer is NULL, then ASSERT().
1181 @param StartAddress Starting address that encodes the PCI Bus, Device,
1182 Function and Register.
1183 @param Size Size in bytes of the transfer.
1184 @param Buffer Pointer to a buffer receiving the data read.
1192 IN UINTN StartAddress
,
1197 RETURN_STATUS Status
;
1199 Status
= S3BootScriptSavePciCfgWrite (
1200 S3BootScriptWidthUint8
,
1201 PCILIB_TO_COMMON_ADDRESS (StartAddress
),
1202 PciReadBuffer (StartAddress
, Size
, Buffer
),
1205 ASSERT (Status
== RETURN_SUCCESS
);
1211 Copies the data in a caller supplied buffer to a specified range of PCI
1212 configuration space and saves the value in the S3 script to be replayed on S3
1215 Writes the range of PCI configuration registers specified by StartAddress and
1216 Size from the buffer specified by Buffer. This function only allows the PCI
1217 configuration registers from a single PCI function to be written. Size is
1218 returned. When possible 32-bit PCI configuration write cycles are used to
1219 write from StartAdress to StartAddress + Size. Due to alignment restrictions,
1220 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
1221 and the end of the range.
1223 If StartAddress > 0x0FFFFFFF, then ASSERT().
1224 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1225 If Size > 0 and Buffer is NULL, then ASSERT().
1227 @param StartAddress Starting address that encodes the PCI Bus, Device,
1228 Function and Register.
1229 @param Size Size in bytes of the transfer.
1230 @param Buffer Pointer to a buffer containing the data to write.
1238 IN UINTN StartAddress
,
1243 RETURN_STATUS Status
;
1245 Status
= S3BootScriptSavePciCfgWrite (
1246 S3BootScriptWidthUint8
,
1247 PCILIB_TO_COMMON_ADDRESS (StartAddress
),
1248 PciWriteBuffer (StartAddress
, Size
, Buffer
),
1251 ASSERT (Status
== RETURN_SUCCESS
);