2 The multiple segments PCI configuration Library Services that carry out
3 PCI configuration and enable the PCI operations to be replayed during an
4 S3 resume. This library class maps directly on top of the PciSegmentLib class.
6 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/DebugLib.h>
14 #include <Library/S3BootScriptLib.h>
15 #include <Library/PciSegmentLib.h>
18 Macro that converts address in PciSegmentLib format to the new address that can be pass
19 to the S3 Boot Script Library functions. The Segment is dropped.
21 @param Address Address in PciSegmentLib format.
23 @retval New address that can be pass to the S3 Boot Script Library functions.
25 #define PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS(Address) \
26 ((((UINT32)(Address) >> 20) & 0xff) << 24) | \
27 ((((UINT32)(Address) >> 15) & 0x1f) << 16) | \
28 ((((UINT32)(Address) >> 12) & 0x07) << 8) | \
29 LShiftU64 ((Address) & 0xfff, 32) // Always put Register in high four bytes.
32 Saves a PCI configuration value to the boot script.
34 This internal worker function saves a PCI configuration value in
35 the S3 script to be replayed on S3 resume.
37 If the saving process fails, then ASSERT().
39 @param Width The width of PCI configuration.
40 @param Address Address that encodes the PCI Bus, Device, Function and
42 @param Buffer The buffer containing value.
46 InternalSavePciSegmentWriteValueToBootScript (
47 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
54 Status
= S3BootScriptSavePciCfg2Write (
56 RShiftU64 ((Address
), 32) & 0xffff,
57 PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS (Address
),
61 ASSERT_RETURN_ERROR (Status
);
65 Saves an 8-bit PCI configuration value to the boot script.
67 This internal worker function saves an 8-bit PCI configuration value in
68 the S3 script to be replayed on S3 resume.
70 If the saving process fails, then ASSERT().
72 @param Address Address that encodes the PCI Bus, Device, Function and
74 @param Value The value saved to boot script.
80 InternalSavePciSegmentWrite8ValueToBootScript (
85 InternalSavePciSegmentWriteValueToBootScript (S3BootScriptWidthUint8
, Address
, &Value
);
91 Reads an 8-bit PCI configuration register, and saves the value in the S3 script to
92 be replayed on S3 resume.
94 Reads and returns the 8-bit PCI configuration register specified by Address.
95 This function must guarantee that all PCI read and write operations are serialized.
97 If any reserved bits in Address are set, then ASSERT().
99 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
101 @return The 8-bit PCI configuration register specified by Address.
110 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentRead8 (Address
));
114 Writes an 8-bit PCI configuration register, and saves the value in the S3 script to
115 be replayed on S3 resume.
117 Writes the 8-bit PCI configuration register specified by Address with the value specified by Value.
118 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
120 If any reserved bits in Address are set, then ASSERT().
122 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
123 @param Value The value to write.
125 @return The value written to the PCI configuration register.
135 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentWrite8 (Address
, Value
));
139 Performs a bitwise OR of an 8-bit PCI configuration register with an 8-bit value, and saves
140 the value in the S3 script to be replayed on S3 resume.
142 Reads the 8-bit PCI configuration register specified by Address,
143 performs a bitwise OR between the read result and the value specified by OrData,
144 and writes the result to the 8-bit PCI configuration register specified by Address.
145 The value written to the PCI configuration register is returned.
146 This function must guarantee that all PCI read and write operations are serialized.
148 If any reserved bits in Address are set, then ASSERT().
150 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
151 @param OrData The value to OR with the PCI configuration register.
153 @return The value written to the PCI configuration register.
163 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentOr8 (Address
, OrData
));
167 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit value, and
168 saves the value in the S3 script to be replayed on S3 resume.
170 Reads the 8-bit PCI configuration register specified by Address,
171 performs a bitwise AND between the read result and the value specified by AndData,
172 and writes the result to the 8-bit PCI configuration register specified by Address.
173 The value written to the PCI configuration register is returned.
174 This function must guarantee that all PCI read and write operations are serialized.
175 If any reserved bits in Address are set, then ASSERT().
177 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
178 @param AndData The value to AND with the PCI configuration register.
180 @return The value written to the PCI configuration register.
190 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentAnd8 (Address
, AndData
));
194 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit value,
195 followed a bitwise OR with another 8-bit value, and saves the value in the S3 script to
196 be replayed on S3 resume.
198 Reads the 8-bit PCI configuration register specified by Address,
199 performs a bitwise AND between the read result and the value specified by AndData,
200 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
201 and writes the result to the 8-bit PCI configuration register specified by Address.
202 The value written to the PCI configuration register is returned.
203 This function must guarantee that all PCI read and write operations are serialized.
205 If any reserved bits in Address are set, then ASSERT().
207 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
208 @param AndData The value to AND with the PCI configuration register.
209 @param OrData The value to OR with the PCI configuration register.
211 @return The value written to the PCI configuration register.
216 S3PciSegmentAndThenOr8 (
222 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentAndThenOr8 (Address
, AndData
, OrData
));
226 Reads a bit field of a PCI configuration register, and saves the value in the
227 S3 script to be replayed on S3 resume.
229 Reads the bit field in an 8-bit PCI configuration register. The bit field is
230 specified by the StartBit and the EndBit. The value of the bit field is
233 If any reserved bits in Address are set, then ASSERT().
234 If StartBit is greater than 7, then ASSERT().
235 If EndBit is greater than 7, then ASSERT().
236 If EndBit is less than StartBit, then ASSERT().
238 @param Address PCI configuration register to read.
239 @param StartBit The ordinal of the least significant bit in the bit field.
241 @param EndBit The ordinal of the most significant bit in the bit field.
244 @return The value of the bit field read from the PCI configuration register.
249 S3PciSegmentBitFieldRead8 (
255 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentBitFieldRead8 (Address
, StartBit
, EndBit
));
259 Writes a bit field to a PCI configuration register, and saves the value in
260 the S3 script to be replayed on S3 resume.
262 Writes Value to the bit field of the PCI configuration register. The bit
263 field is specified by the StartBit and the EndBit. All other bits in the
264 destination PCI configuration register are preserved. The new value of the
265 8-bit register is returned.
267 If any reserved bits in Address are set, then ASSERT().
268 If StartBit is greater than 7, then ASSERT().
269 If EndBit is greater than 7, then ASSERT().
270 If EndBit is less than StartBit, then ASSERT().
271 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
273 @param Address PCI configuration register to write.
274 @param StartBit The ordinal of the least significant bit in the bit field.
276 @param EndBit The ordinal of the most significant bit in the bit field.
278 @param Value New value of the bit field.
280 @return The value written back to the PCI configuration register.
285 S3PciSegmentBitFieldWrite8 (
292 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentBitFieldWrite8 (Address
, StartBit
, EndBit
, Value
));
296 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, writes
297 the result back to the bit field in the 8-bit port, and saves the value in the
298 S3 script to be replayed on S3 resume.
300 Reads the 8-bit PCI configuration register specified by Address, performs a
301 bitwise OR between the read result and the value specified by
302 OrData, and writes the result to the 8-bit PCI configuration register
303 specified by Address. The value written to the PCI configuration register is
304 returned. This function must guarantee that all PCI read and write operations
305 are serialized. Extra left bits in OrData are stripped.
307 If any reserved bits in Address are set, then ASSERT().
308 If StartBit is greater than 7, then ASSERT().
309 If EndBit is greater than 7, then ASSERT().
310 If EndBit is less than StartBit, then ASSERT().
311 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
313 @param Address PCI configuration register to write.
314 @param StartBit The ordinal of the least significant bit in the bit field.
316 @param EndBit The ordinal of the most significant bit in the bit field.
318 @param OrData The value to OR with the PCI configuration register.
320 @return The value written back to the PCI configuration register.
325 S3PciSegmentBitFieldOr8 (
332 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentBitFieldOr8 (Address
, StartBit
, EndBit
, OrData
));
336 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise
337 AND, writes the result back to the bit field in the 8-bit register, and
338 saves the value in the S3 script to be replayed on S3 resume.
340 Reads the 8-bit PCI configuration register specified by Address, performs a
341 bitwise AND between the read result and the value specified by AndData, and
342 writes the result to the 8-bit PCI configuration register specified by
343 Address. The value written to the PCI configuration register is returned.
344 This function must guarantee that all PCI read and write operations are
345 serialized. Extra left bits in AndData are stripped.
347 If any reserved bits in Address are set, then ASSERT().
348 If StartBit is greater than 7, then ASSERT().
349 If EndBit is greater than 7, then ASSERT().
350 If EndBit is less than StartBit, then ASSERT().
351 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
353 @param Address PCI configuration register to write.
354 @param StartBit The ordinal of the least significant bit in the bit field.
356 @param EndBit The ordinal of the most significant bit in the bit field.
358 @param AndData The value to AND with the PCI configuration register.
360 @return The value written back to the PCI configuration register.
365 S3PciSegmentBitFieldAnd8 (
372 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentBitFieldAnd8 (Address
, StartBit
, EndBit
, AndData
));
376 Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
377 bitwise OR, writes the result back to the bit field in the 8-bit port,
378 and saves the value in the S3 script to be replayed on S3 resume.
380 Reads the 8-bit PCI configuration register specified by Address, performs a
381 bitwise AND followed by a bitwise OR between the read result and
382 the value specified by AndData, and writes the result to the 8-bit PCI
383 configuration register specified by Address. The value written to the PCI
384 configuration register is returned. This function must guarantee that all PCI
385 read and write operations are serialized. Extra left bits in both AndData and
388 If any reserved bits in Address are set, then ASSERT().
389 If StartBit is greater than 7, then ASSERT().
390 If EndBit is greater than 7, then ASSERT().
391 If EndBit is less than StartBit, then ASSERT().
392 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
393 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
395 @param Address PCI configuration register to write.
396 @param StartBit The ordinal of the least significant bit in the bit field.
398 @param EndBit The ordinal of the most significant bit in the bit field.
400 @param AndData The value to AND with the PCI configuration register.
401 @param OrData The value to OR with the result of the AND operation.
403 @return The value written back to the PCI configuration register.
408 S3PciSegmentBitFieldAndThenOr8 (
416 return InternalSavePciSegmentWrite8ValueToBootScript (Address
, PciSegmentBitFieldAndThenOr8 (Address
, StartBit
, EndBit
, AndData
, OrData
));
420 Saves a 16-bit PCI configuration value to the boot script.
422 This internal worker function saves a 16-bit PCI configuration value in
423 the S3 script to be replayed on S3 resume.
425 If the saving process fails, then ASSERT().
427 @param Address Address that encodes the PCI Bus, Device, Function and
429 @param Value The value saved to boot script.
435 InternalSavePciSegmentWrite16ValueToBootScript (
440 InternalSavePciSegmentWriteValueToBootScript (S3BootScriptWidthUint16
, Address
, &Value
);
446 Reads a 16-bit PCI configuration register, and saves the value in the S3 script
447 to be replayed on S3 resume.
449 Reads and returns the 16-bit PCI configuration register specified by Address.
450 This function must guarantee that all PCI read and write operations are serialized.
452 If any reserved bits in Address are set, then ASSERT().
453 If Address is not aligned on a 16-bit boundary, then ASSERT().
455 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
457 @return The 16-bit PCI configuration register specified by Address.
466 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentRead16 (Address
));
470 Writes a 16-bit PCI configuration register, and saves the value in the S3 script to
471 be replayed on S3 resume.
473 Writes the 16-bit PCI configuration register specified by Address with the value specified by Value.
474 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
476 If any reserved bits in Address are set, then ASSERT().
477 If Address is not aligned on a 16-bit boundary, then ASSERT().
479 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
480 @param Value The value to write.
482 @return The parameter of Value.
487 S3PciSegmentWrite16 (
492 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentWrite16 (Address
, Value
));
496 Performs a bitwise OR of a 16-bit PCI configuration register with a 16-bit
497 value, and saves the value in the S3 script to be replayed on S3 resume.
499 Reads the 16-bit PCI configuration register specified by Address, performs a
500 bitwise OR between the read result and the value specified by OrData, and
501 writes the result to the 16-bit PCI configuration register specified by Address.
502 The value written to the PCI configuration register is returned. This function
503 must guarantee that all PCI read and write operations are serialized.
505 If any reserved bits in Address are set, then ASSERT().
506 If Address is not aligned on a 16-bit boundary, then ASSERT().
508 @param Address Address that encodes the PCI Segment, Bus, Device, Function and
510 @param OrData The value to OR with the PCI configuration register.
512 @return The value written back to the PCI configuration register.
522 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentOr16 (Address
, OrData
));
526 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit value, and
527 saves the value in the S3 script to be replayed on S3 resume.
529 Reads the 16-bit PCI configuration register specified by Address,
530 performs a bitwise AND between the read result and the value specified by AndData,
531 and writes the result to the 16-bit PCI configuration register specified by Address.
532 The value written to the PCI configuration register is returned.
533 This function must guarantee that all PCI read and write operations are serialized.
535 If any reserved bits in Address are set, then ASSERT().
536 If Address is not aligned on a 16-bit boundary, then ASSERT().
538 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
539 @param AndData The value to AND with the PCI configuration register.
541 @return The value written to the PCI configuration register.
551 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentAnd16 (Address
, AndData
));
555 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit value,
556 followed a bitwise OR with another 16-bit value, and saves the value in the S3 script to
557 be replayed on S3 resume.
559 Reads the 16-bit PCI configuration register specified by Address,
560 performs a bitwise AND between the read result and the value specified by AndData,
561 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
562 and writes the result to the 16-bit PCI configuration register specified by Address.
563 The value written to the PCI configuration register is returned.
564 This function must guarantee that all PCI read and write operations are serialized.
566 If any reserved bits in Address are set, then ASSERT().
567 If Address is not aligned on a 16-bit boundary, then ASSERT().
569 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
570 @param AndData The value to AND with the PCI configuration register.
571 @param OrData The value to OR with the PCI configuration register.
573 @return The value written to the PCI configuration register.
578 S3PciSegmentAndThenOr16 (
584 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentAndThenOr16 (Address
, AndData
, OrData
));
588 Reads a bit field of a PCI configuration register, and saves the value in the
589 S3 script to be replayed on S3 resume.
591 Reads the bit field in a 16-bit PCI configuration register. The bit field is
592 specified by the StartBit and the EndBit. The value of the bit field is
595 If any reserved bits in Address are set, then ASSERT().
596 If Address is not aligned on a 16-bit boundary, then ASSERT().
597 If StartBit is greater than 15, then ASSERT().
598 If EndBit is greater than 15, then ASSERT().
599 If EndBit is less than StartBit, then ASSERT().
601 @param Address PCI configuration register to read.
602 @param StartBit The ordinal of the least significant bit in the bit field.
604 @param EndBit The ordinal of the most significant bit in the bit field.
607 @return The value of the bit field read from the PCI configuration register.
612 S3PciSegmentBitFieldRead16 (
618 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentBitFieldRead16 (Address
, StartBit
, EndBit
));
622 Writes a bit field to a PCI configuration register, and saves the value in
623 the S3 script to be replayed on S3 resume.
625 Writes Value to the bit field of the PCI configuration register. The bit
626 field is specified by the StartBit and the EndBit. All other bits in the
627 destination PCI configuration register are preserved. The new value of the
628 16-bit register is returned.
630 If any reserved bits in Address are set, then ASSERT().
631 If Address is not aligned on a 16-bit boundary, then ASSERT().
632 If StartBit is greater than 15, then ASSERT().
633 If EndBit is greater than 15, then ASSERT().
634 If EndBit is less than StartBit, then ASSERT().
635 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
637 @param Address PCI configuration register to write.
638 @param StartBit The ordinal of the least significant bit in the bit field.
640 @param EndBit The ordinal of the most significant bit in the bit field.
642 @param Value New value of the bit field.
644 @return The value written back to the PCI configuration register.
649 S3PciSegmentBitFieldWrite16 (
656 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentBitFieldWrite16 (Address
, StartBit
, EndBit
, Value
));
660 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, writes
661 the result back to the bit field in the 16-bit port, and saves the value in the
662 S3 script to be replayed on S3 resume.
664 Reads the 16-bit PCI configuration register specified by Address, performs a
665 bitwise OR between the read result and the value specified by
666 OrData, and writes the result to the 16-bit PCI configuration register
667 specified by Address. The value written to the PCI configuration register is
668 returned. This function must guarantee that all PCI read and write operations
669 are serialized. Extra left bits in OrData are stripped.
671 If any reserved bits in Address are set, then ASSERT().
672 If Address is not aligned on a 16-bit boundary, then ASSERT().
673 If StartBit is greater than 15, then ASSERT().
674 If EndBit is greater than 15, then ASSERT().
675 If EndBit is less than StartBit, then ASSERT().
676 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
678 @param Address PCI configuration register to write.
679 @param StartBit The ordinal of the least significant bit in the bit field.
681 @param EndBit The ordinal of the most significant bit in the bit field.
683 @param OrData The value to OR with the PCI configuration register.
685 @return The value written back to the PCI configuration register.
690 S3PciSegmentBitFieldOr16 (
697 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentBitFieldOr16 (Address
, StartBit
, EndBit
, OrData
));
701 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
702 AND, writes the result back to the bit field in the 16-bit register, and
703 saves the value in the S3 script to be replayed on S3 resume.
705 Reads the 16-bit PCI configuration register specified by Address, performs a
706 bitwise AND between the read result and the value specified by AndData, and
707 writes the result to the 16-bit PCI configuration register specified by
708 Address. The value written to the PCI configuration register is returned.
709 This function must guarantee that all PCI read and write operations are
710 serialized. Extra left bits in AndData are stripped.
712 If any reserved bits in Address are set, then ASSERT().
713 If Address is not aligned on a 16-bit boundary, then ASSERT().
714 If StartBit is greater than 15, then ASSERT().
715 If EndBit is greater than 15, then ASSERT().
716 If EndBit is less than StartBit, then ASSERT().
717 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
719 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
720 @param StartBit The ordinal of the least significant bit in the bit field.
722 @param EndBit The ordinal of the most significant bit in the bit field.
724 @param AndData The value to AND with the PCI configuration register.
726 @return The value written back to the PCI configuration register.
731 S3PciSegmentBitFieldAnd16 (
738 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentBitFieldAnd16 (Address
, StartBit
, EndBit
, AndData
));
742 Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
743 bitwise OR, writes the result back to the bit field in the 16-bit port,
744 and saves the value in the S3 script to be replayed on S3 resume.
746 Reads the 16-bit PCI configuration register specified by Address, performs a
747 bitwise AND followed by a bitwise OR between the read result and
748 the value specified by AndData, and writes the result to the 16-bit PCI
749 configuration register specified by Address. The value written to the PCI
750 configuration register is returned. This function must guarantee that all PCI
751 read and write operations are serialized. Extra left bits in both AndData and
754 If any reserved bits in Address are set, then ASSERT().
755 If StartBit is greater than 15, then ASSERT().
756 If EndBit is greater than 15, then ASSERT().
757 If EndBit is less than StartBit, then ASSERT().
758 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
759 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
761 @param Address PCI configuration register to write.
762 @param StartBit The ordinal of the least significant bit in the bit field.
764 @param EndBit The ordinal of the most significant bit in the bit field.
766 @param AndData The value to AND with the PCI configuration register.
767 @param OrData The value to OR with the result of the AND operation.
769 @return The value written back to the PCI configuration register.
774 S3PciSegmentBitFieldAndThenOr16 (
782 return InternalSavePciSegmentWrite16ValueToBootScript (Address
, PciSegmentBitFieldAndThenOr16 (Address
, StartBit
, EndBit
, AndData
, OrData
));
786 Saves a 32-bit PCI configuration value to the boot script.
788 This internal worker function saves a 32-bit PCI configuration value in the S3 script
789 to be replayed on S3 resume.
791 If the saving process fails, then ASSERT().
793 @param Address Address that encodes the PCI Bus, Device, Function and
795 @param Value The value saved to boot script.
801 InternalSavePciSegmentWrite32ValueToBootScript (
806 InternalSavePciSegmentWriteValueToBootScript (S3BootScriptWidthUint32
, Address
, &Value
);
812 Reads a 32-bit PCI configuration register, and saves the value in the S3 script
813 to be replayed on S3 resume.
815 Reads and returns the 32-bit PCI configuration register specified by Address.
816 This function must guarantee that all PCI read and write operations are serialized.
818 If any reserved bits in Address are set, then ASSERT().
819 If Address is not aligned on a 32-bit boundary, then ASSERT().
821 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
823 @return The 32-bit PCI configuration register specified by Address.
832 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentRead32 (Address
));
836 Writes a 32-bit PCI configuration register, and saves the value in the S3 script to
837 be replayed on S3 resume.
839 Writes the 32-bit PCI configuration register specified by Address with the value specified by Value.
840 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
842 If any reserved bits in Address are set, then ASSERT().
843 If Address is not aligned on a 32-bit boundary, then ASSERT().
845 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
846 @param Value The value to write.
848 @return The parameter of Value.
853 S3PciSegmentWrite32 (
858 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentWrite32 (Address
, Value
));
862 Performs a bitwise OR of a 32-bit PCI configuration register with a 32-bit
863 value, and saves the value in the S3 script to be replayed on S3 resume.
865 Reads the 32-bit PCI configuration register specified by Address, performs a
866 bitwise OR between the read result and the value specified by OrData, and
867 writes the result to the 32-bit PCI configuration register specified by Address.
868 The value written to the PCI configuration register is returned. This function
869 must guarantee that all PCI read and write operations are serialized.
871 If any reserved bits in Address are set, then ASSERT().
872 If Address is not aligned on a 32-bit boundary, then ASSERT().
874 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and
876 @param OrData The value to OR with the PCI configuration register.
878 @return The value written back to the PCI configuration register.
888 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentOr32 (Address
, OrData
));
892 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit value, and
893 saves the value in the S3 script to be replayed on S3 resume.
895 Reads the 32-bit PCI configuration register specified by Address,
896 performs a bitwise AND between the read result and the value specified by AndData,
897 and writes the result to the 32-bit PCI configuration register specified by Address.
898 The value written to the PCI configuration register is returned.
899 This function must guarantee that all PCI read and write operations are serialized.
901 If any reserved bits in Address are set, then ASSERT().
902 If Address is not aligned on a 32-bit boundary, then ASSERT().
904 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
905 @param AndData The value to AND with the PCI configuration register.
907 @return The value written to the PCI configuration register.
917 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentAnd32 (Address
, AndData
));
921 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit value,
922 followed a bitwise OR with another 32-bit value, and saves the value in the S3 script to
923 be replayed on S3 resume.
925 Reads the 32-bit PCI configuration register specified by Address,
926 performs a bitwise AND between the read result and the value specified by AndData,
927 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
928 and writes the result to the 32-bit PCI configuration register specified by Address.
929 The value written to the PCI configuration register is returned.
930 This function must guarantee that all PCI read and write operations are serialized.
932 If any reserved bits in Address are set, then ASSERT().
933 If Address is not aligned on a 32-bit boundary, then ASSERT().
935 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
936 @param AndData The value to AND with the PCI configuration register.
937 @param OrData The value to OR with the PCI configuration register.
939 @return The value written to the PCI configuration register.
944 S3PciSegmentAndThenOr32 (
950 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentAndThenOr32 (Address
, AndData
, OrData
));
954 Reads a bit field of a PCI configuration register, and saves the value in the
955 S3 script to be replayed on S3 resume.
957 Reads the bit field in a 32-bit PCI configuration register. The bit field is
958 specified by the StartBit and the EndBit. The value of the bit field is
961 If any reserved bits in Address are set, then ASSERT().
962 If Address is not aligned on a 32-bit boundary, then ASSERT().
963 If StartBit is greater than 31, then ASSERT().
964 If EndBit is greater than 31, then ASSERT().
965 If EndBit is less than StartBit, then ASSERT().
967 @param Address PCI configuration register to read.
968 @param StartBit The ordinal of the least significant bit in the bit field.
970 @param EndBit The ordinal of the most significant bit in the bit field.
973 @return The value of the bit field read from the PCI configuration register.
978 S3PciSegmentBitFieldRead32 (
984 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentBitFieldRead32 (Address
, StartBit
, EndBit
));
988 Writes a bit field to a PCI configuration register, and saves the value in
989 the S3 script to be replayed on S3 resume.
991 Writes Value to the bit field of the PCI configuration register. The bit
992 field is specified by the StartBit and the EndBit. All other bits in the
993 destination PCI configuration register are preserved. The new value of the
994 32-bit register is returned.
996 If any reserved bits in Address are set, then ASSERT().
997 If Address is not aligned on a 32-bit boundary, then ASSERT().
998 If StartBit is greater than 31, then ASSERT().
999 If EndBit is greater than 31, then ASSERT().
1000 If EndBit is less than StartBit, then ASSERT().
1001 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1003 @param Address PCI configuration register to write.
1004 @param StartBit The ordinal of the least significant bit in the bit field.
1006 @param EndBit The ordinal of the most significant bit in the bit field.
1008 @param Value New value of the bit field.
1010 @return The value written back to the PCI configuration register.
1015 S3PciSegmentBitFieldWrite32 (
1022 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentBitFieldWrite32 (Address
, StartBit
, EndBit
, Value
));
1026 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, writes
1027 the result back to the bit field in the 32-bit port, and saves the value in the
1028 S3 script to be replayed on S3 resume.
1030 Reads the 32-bit PCI configuration register specified by Address, performs a
1031 bitwise OR between the read result and the value specified by
1032 OrData, and writes the result to the 32-bit PCI configuration register
1033 specified by Address. The value written to the PCI configuration register is
1034 returned. This function must guarantee that all PCI read and write operations
1035 are serialized. Extra left bits in OrData are stripped.
1037 If any reserved bits in Address are set, then ASSERT().
1038 If Address is not aligned on a 32-bit boundary, then ASSERT().
1039 If StartBit is greater than 31, then ASSERT().
1040 If EndBit is greater than 31, then ASSERT().
1041 If EndBit is less than StartBit, then ASSERT().
1042 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1044 @param Address PCI configuration register to write.
1045 @param StartBit The ordinal of the least significant bit in the bit field.
1047 @param EndBit The ordinal of the most significant bit in the bit field.
1049 @param OrData The value to OR with the PCI configuration register.
1051 @return The value written back to the PCI configuration register.
1056 S3PciSegmentBitFieldOr32 (
1063 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentBitFieldOr32 (Address
, StartBit
, EndBit
, OrData
));
1067 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise
1068 AND, and writes the result back to the bit field in the 32-bit register, and
1069 saves the value in the S3 script to be replayed on S3 resume.
1071 Reads the 32-bit PCI configuration register specified by Address, performs a
1072 bitwise AND between the read result and the value specified by AndData, and
1073 writes the result to the 32-bit PCI configuration register specified by
1074 Address. The value written to the PCI configuration register is returned.
1075 This function must guarantee that all PCI read and write operations are
1076 serialized. Extra left bits in AndData are stripped.
1078 If any reserved bits in Address are set, then ASSERT().
1079 If Address is not aligned on a 32-bit boundary, then ASSERT().
1080 If StartBit is greater than 31, then ASSERT().
1081 If EndBit is greater than 31, then ASSERT().
1082 If EndBit is less than StartBit, then ASSERT().
1083 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1085 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
1086 @param StartBit The ordinal of the least significant bit in the bit field.
1088 @param EndBit The ordinal of the most significant bit in the bit field.
1090 @param AndData The value to AND with the PCI configuration register.
1092 @return The value written back to the PCI configuration register.
1097 S3PciSegmentBitFieldAnd32 (
1104 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentBitFieldAnd32 (Address
, StartBit
, EndBit
, AndData
));
1108 Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
1109 bitwise OR, writes the result back to the bit field in the 32-bit port,
1110 and saves the value in the S3 script to be replayed on S3 resume.
1112 Reads the 32-bit PCI configuration register specified by Address, performs a
1113 bitwise AND followed by a bitwise OR between the read result and
1114 the value specified by AndData, and writes the result to the 32-bit PCI
1115 configuration register specified by Address. The value written to the PCI
1116 configuration register is returned. This function must guarantee that all PCI
1117 read and write operations are serialized. Extra left bits in both AndData and
1118 OrData are stripped.
1120 If any reserved bits in Address are set, then ASSERT().
1121 If StartBit is greater than 31, then ASSERT().
1122 If EndBit is greater than 31, then ASSERT().
1123 If EndBit is less than StartBit, then ASSERT().
1124 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1125 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1127 @param Address PCI configuration register to write.
1128 @param StartBit The ordinal of the least significant bit in the bit field.
1130 @param EndBit The ordinal of the most significant bit in the bit field.
1132 @param AndData The value to AND with the PCI configuration register.
1133 @param OrData The value to OR with the result of the AND operation.
1135 @return The value written back to the PCI configuration register.
1140 S3PciSegmentBitFieldAndThenOr32 (
1148 return InternalSavePciSegmentWrite32ValueToBootScript (Address
, PciSegmentBitFieldAndThenOr32 (Address
, StartBit
, EndBit
, AndData
, OrData
));
1152 Reads a range of PCI configuration registers into a caller supplied buffer,
1153 and saves the value in the S3 script to be replayed on S3 resume.
1155 Reads the range of PCI configuration registers specified by StartAddress and
1156 Size into the buffer specified by Buffer. This function only allows the PCI
1157 configuration registers from a single PCI function to be read. Size is
1158 returned. When possible 32-bit PCI configuration read cycles are used to read
1159 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit
1160 and 16-bit PCI configuration read cycles may be used at the beginning and the
1163 If any reserved bits in StartAddress are set, then ASSERT().
1164 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1165 If Size > 0 and Buffer is NULL, then ASSERT().
1167 @param StartAddress Starting address that encodes the PCI Segment, Bus, Device,
1168 Function and Register.
1169 @param Size Size in bytes of the transfer.
1170 @param Buffer Pointer to a buffer receiving the data read.
1177 S3PciSegmentReadBuffer (
1178 IN UINT64 StartAddress
,
1183 RETURN_STATUS Status
;
1185 Status
= S3BootScriptSavePciCfg2Write (
1186 S3BootScriptWidthUint8
,
1187 RShiftU64 (StartAddress
, 32) & 0xffff,
1188 PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS (StartAddress
),
1189 PciSegmentReadBuffer (StartAddress
, Size
, Buffer
),
1192 ASSERT_RETURN_ERROR (Status
);
1197 Copies the data in a caller supplied buffer to a specified range of PCI
1198 configuration space, and saves the value in the S3 script to be replayed on S3
1201 Writes the range of PCI configuration registers specified by StartAddress and
1202 Size from the buffer specified by Buffer. This function only allows the PCI
1203 configuration registers from a single PCI function to be written. Size is
1204 returned. When possible 32-bit PCI configuration write cycles are used to
1205 write from StartAdress to StartAddress + Size. Due to alignment restrictions,
1206 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
1207 and the end of the range.
1209 If any reserved bits in StartAddress are set, then ASSERT().
1210 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1211 If Size > 0 and Buffer is NULL, then ASSERT().
1213 @param StartAddress Starting address that encodes the PCI Segment, Bus, Device,
1214 Function and Register.
1215 @param Size Size in bytes of the transfer.
1216 @param Buffer Pointer to a buffer containing the data to write.
1218 @return The parameter of Size.
1223 S3PciSegmentWriteBuffer (
1224 IN UINT64 StartAddress
,
1229 RETURN_STATUS Status
;
1231 Status
= S3BootScriptSavePciCfg2Write (
1232 S3BootScriptWidthUint8
,
1233 RShiftU64 (StartAddress
, 32) & 0xffff,
1234 PCI_SEGMENT_LIB_ADDRESS_TO_S3_BOOT_SCRIPT_PCI_ADDRESS (StartAddress
),
1235 PciSegmentWriteBuffer (StartAddress
, Size
, Buffer
),
1238 ASSERT_RETURN_ERROR (Status
);