2 Provide common routines used by BasePciSegmentLibSegmentInfo and
3 DxeRuntimePciSegmentLibSegmentInfo libraries.
5 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are
7 licensed and made available under the terms and conditions of
8 the BSD License which accompanies this distribution. The full
9 text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "PciSegmentLibCommon.h"
26 UINT32 Reserved2
: 16;
27 } PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
;
30 Internal function that converts PciSegmentLib format address that encodes the PCI Bus, Device,
31 Function and Register to ECAM (Enhanced Configuration Access Mechanism) address.
33 @param Address The address that encodes the PCI Bus, Device, Function and
35 @param SegmentInfo An array of PCI_SEGMENT_INFO holding the segment information.
36 @param Count Number of segments.
41 PciSegmentLibGetEcamAddress (
43 IN CONST PCI_SEGMENT_INFO
*SegmentInfo
,
48 if (SegmentInfo
->SegmentNumber
== ((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Segment
) {
56 (((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Reserved1
== 0) &&
57 (((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Reserved2
== 0)
59 ASSERT (((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Bus
>= SegmentInfo
->StartBusNumber
);
60 ASSERT (((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Bus
<= SegmentInfo
->EndBusNumber
);
62 Address
= SegmentInfo
->BaseAddress
+ PCI_ECAM_ADDRESS (
63 ((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Bus
,
64 ((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Device
,
65 ((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Function
,
66 ((PCI_SEGMENT_LIB_ADDRESS_STRUCTURE
*)&Address
)->Register
);
68 if (sizeof (UINTN
) == sizeof (UINT32
)) {
69 ASSERT (Address
< BASE_4GB
);
72 return PciSegmentLibVirtualAddress ((UINTN
)Address
);
76 Reads an 8-bit PCI configuration register.
78 Reads and returns the 8-bit PCI configuration register specified by Address.
79 This function must guarantee that all PCI read and write operations are serialized.
81 If any reserved bits in Address are set, then ASSERT().
83 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
85 @return The 8-bit PCI configuration register specified by Address.
95 PCI_SEGMENT_INFO
*SegmentInfo
;
97 SegmentInfo
= GetPciSegmentInfo (&Count
);
98 return MmioRead8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
));
102 Writes an 8-bit PCI configuration register.
104 Writes the 8-bit PCI configuration register specified by Address with the value specified by Value.
105 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
107 If any reserved bits in Address are set, then ASSERT().
109 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
110 @param Value The value to write.
112 @return The value written to the PCI configuration register.
123 PCI_SEGMENT_INFO
*SegmentInfo
;
125 SegmentInfo
= GetPciSegmentInfo (&Count
);
126 return MmioWrite8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), Value
);
130 Performs a bitwise OR of an 8-bit PCI configuration register with an 8-bit value.
132 Reads the 8-bit PCI configuration register specified by Address,
133 performs a bitwise OR between the read result and the value specified by OrData,
134 and writes the result to the 8-bit PCI configuration register specified by Address.
135 The value written to the PCI configuration register is returned.
136 This function must guarantee that all PCI read and write operations are serialized.
138 If any reserved bits in Address are set, then ASSERT().
140 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
141 @param OrData The value to OR with the PCI configuration register.
143 @return The value written to the PCI configuration register.
154 PCI_SEGMENT_INFO
*SegmentInfo
;
156 SegmentInfo
= GetPciSegmentInfo (&Count
);
157 return MmioOr8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), OrData
);
161 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit value.
163 Reads the 8-bit PCI configuration register specified by Address,
164 performs a bitwise AND between the read result and the value specified by AndData,
165 and writes the result to the 8-bit PCI configuration register specified by Address.
166 The value written to the PCI configuration register is returned.
167 This function must guarantee that all PCI read and write operations are serialized.
168 If any reserved bits in Address are set, then ASSERT().
170 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
171 @param AndData The value to AND with the PCI configuration register.
173 @return The value written to the PCI configuration register.
184 PCI_SEGMENT_INFO
*SegmentInfo
;
186 SegmentInfo
= GetPciSegmentInfo (&Count
);
187 return MmioAnd8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), AndData
);
191 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit value,
192 followed a bitwise OR with another 8-bit value.
194 Reads the 8-bit PCI configuration register specified by Address,
195 performs a bitwise AND between the read result and the value specified by AndData,
196 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
197 and writes the result to the 8-bit PCI configuration register specified by Address.
198 The value written to the PCI configuration register is returned.
199 This function must guarantee that all PCI read and write operations are serialized.
201 If any reserved bits in Address are set, then ASSERT().
203 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
204 @param AndData The value to AND with the PCI configuration register.
205 @param OrData The value to OR with the PCI configuration register.
207 @return The value written to the PCI configuration register.
212 PciSegmentAndThenOr8 (
219 PCI_SEGMENT_INFO
*SegmentInfo
;
221 SegmentInfo
= GetPciSegmentInfo (&Count
);
222 return MmioAndThenOr8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), AndData
, OrData
);
226 Reads a bit field of a PCI configuration register.
228 Reads the bit field in an 8-bit PCI configuration register. The bit field is
229 specified by the StartBit and the EndBit. The value of the bit field is
232 If any reserved bits in Address are set, then ASSERT().
233 If StartBit is greater than 7, then ASSERT().
234 If EndBit is greater than 7, then ASSERT().
235 If EndBit is less than StartBit, then ASSERT().
237 @param Address PCI configuration register to read.
238 @param StartBit The ordinal of the least significant bit in the bit field.
240 @param EndBit The ordinal of the most significant bit in the bit field.
243 @return The value of the bit field read from the PCI configuration register.
248 PciSegmentBitFieldRead8 (
255 PCI_SEGMENT_INFO
*SegmentInfo
;
257 SegmentInfo
= GetPciSegmentInfo (&Count
);
258 return MmioBitFieldRead8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
);
262 Writes a bit field to a PCI configuration register.
264 Writes Value to the bit field of the PCI configuration register. The bit
265 field is specified by the StartBit and the EndBit. All other bits in the
266 destination PCI configuration register are preserved. The new value of the
267 8-bit register is returned.
269 If any reserved bits in Address are set, then ASSERT().
270 If StartBit is greater than 7, then ASSERT().
271 If EndBit is greater than 7, then ASSERT().
272 If EndBit is less than StartBit, then ASSERT().
273 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
275 @param Address PCI configuration register to write.
276 @param StartBit The ordinal of the least significant bit in the bit field.
278 @param EndBit The ordinal of the most significant bit in the bit field.
280 @param Value New value of the bit field.
282 @return The value written back to the PCI configuration register.
287 PciSegmentBitFieldWrite8 (
295 PCI_SEGMENT_INFO
*SegmentInfo
;
297 SegmentInfo
= GetPciSegmentInfo (&Count
);
298 return MmioBitFieldWrite8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, Value
);
302 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and
303 writes the result back to the bit field in the 8-bit port.
305 Reads the 8-bit PCI configuration register specified by Address, performs a
306 bitwise OR between the read result and the value specified by
307 OrData, and writes the result to the 8-bit PCI configuration register
308 specified by Address. The value written to the PCI configuration register is
309 returned. This function must guarantee that all PCI read and write operations
310 are serialized. Extra left bits in OrData are stripped.
312 If any reserved bits in Address are set, then ASSERT().
313 If StartBit is greater than 7, then ASSERT().
314 If EndBit is greater than 7, then ASSERT().
315 If EndBit is less than StartBit, then ASSERT().
316 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
318 @param Address PCI configuration register to write.
319 @param StartBit The ordinal of the least significant bit in the bit field.
321 @param EndBit The ordinal of the most significant bit in the bit field.
323 @param OrData The value to OR with the PCI configuration register.
325 @return The value written back to the PCI configuration register.
330 PciSegmentBitFieldOr8 (
338 PCI_SEGMENT_INFO
*SegmentInfo
;
340 SegmentInfo
= GetPciSegmentInfo (&Count
);
341 return MmioBitFieldOr8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), 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.
348 Reads the 8-bit PCI configuration register specified by Address, performs a
349 bitwise AND between the read result and the value specified by AndData, and
350 writes the result to the 8-bit PCI configuration register specified by
351 Address. The value written to the PCI configuration register is returned.
352 This function must guarantee that all PCI read and write operations are
353 serialized. Extra left bits in AndData are stripped.
355 If any reserved bits in Address are set, then ASSERT().
356 If StartBit is greater than 7, then ASSERT().
357 If EndBit is greater than 7, then ASSERT().
358 If EndBit is less than StartBit, then ASSERT().
359 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
361 @param Address PCI configuration register to write.
362 @param StartBit The ordinal of the least significant bit in the bit field.
364 @param EndBit The ordinal of the most significant bit in the bit field.
366 @param AndData The value to AND with the PCI configuration register.
368 @return The value written back to the PCI configuration register.
373 PciSegmentBitFieldAnd8 (
381 PCI_SEGMENT_INFO
*SegmentInfo
;
383 SegmentInfo
= GetPciSegmentInfo (&Count
);
384 return MmioBitFieldAnd8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, AndData
);
388 Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
389 bitwise OR, and writes the result back to the bit field in the 8-bit port.
391 Reads the 8-bit PCI configuration register specified by Address, performs a
392 bitwise AND followed by a bitwise OR between the read result and
393 the value specified by AndData, and writes the result to the 8-bit PCI
394 configuration register specified by Address. The value written to the PCI
395 configuration register is returned. This function must guarantee that all PCI
396 read and write operations are serialized. Extra left bits in both AndData and
399 If any reserved bits in Address are set, then ASSERT().
400 If StartBit is greater than 7, then ASSERT().
401 If EndBit is greater than 7, then ASSERT().
402 If EndBit is less than StartBit, then ASSERT().
403 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
404 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
406 @param Address PCI configuration register to write.
407 @param StartBit The ordinal of the least significant bit in the bit field.
409 @param EndBit The ordinal of the most significant bit in the bit field.
411 @param AndData The value to AND with the PCI configuration register.
412 @param OrData The value to OR with the result of the AND operation.
414 @return The value written back to the PCI configuration register.
419 PciSegmentBitFieldAndThenOr8 (
428 PCI_SEGMENT_INFO
*SegmentInfo
;
430 SegmentInfo
= GetPciSegmentInfo (&Count
);
431 return MmioBitFieldAndThenOr8 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, AndData
, OrData
);
435 Reads a 16-bit PCI configuration register.
437 Reads and returns the 16-bit PCI configuration register specified by Address.
438 This function must guarantee that all PCI read and write operations are serialized.
440 If any reserved bits in Address are set, then ASSERT().
441 If Address is not aligned on a 16-bit boundary, then ASSERT().
443 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
445 @return The 16-bit PCI configuration register specified by Address.
455 PCI_SEGMENT_INFO
*SegmentInfo
;
457 SegmentInfo
= GetPciSegmentInfo (&Count
);
458 return MmioRead16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
));
462 Writes a 16-bit PCI configuration register.
464 Writes the 16-bit PCI configuration register specified by Address with the value specified by Value.
465 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
467 If any reserved bits in Address are set, then ASSERT().
468 If Address is not aligned on a 16-bit boundary, then ASSERT().
470 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
471 @param Value The value to write.
473 @return The parameter of Value.
484 PCI_SEGMENT_INFO
*SegmentInfo
;
486 SegmentInfo
= GetPciSegmentInfo (&Count
);
487 return MmioWrite16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), Value
);
491 Performs a bitwise OR of a 16-bit PCI configuration register with
494 Reads the 16-bit PCI configuration register specified by Address, performs a
495 bitwise OR between the read result and the value specified by OrData, and
496 writes the result to the 16-bit PCI configuration register specified by Address.
497 The value written to the PCI configuration register is returned. This function
498 must guarantee that all PCI read and write operations are serialized.
500 If any reserved bits in Address are set, then ASSERT().
501 If Address is not aligned on a 16-bit boundary, then ASSERT().
503 @param Address Address that encodes the PCI Segment, Bus, Device, Function and
505 @param OrData The value to OR with the PCI configuration register.
507 @return The value written back to the PCI configuration register.
518 PCI_SEGMENT_INFO
*SegmentInfo
;
520 SegmentInfo
= GetPciSegmentInfo (&Count
);
521 return MmioOr16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), OrData
);
525 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit value.
527 Reads the 16-bit PCI configuration register specified by Address,
528 performs a bitwise AND between the read result and the value specified by AndData,
529 and writes the result to the 16-bit PCI configuration register specified by Address.
530 The value written to the PCI configuration register is returned.
531 This function must guarantee that all PCI read and write operations are serialized.
533 If any reserved bits in Address are set, then ASSERT().
534 If Address is not aligned on a 16-bit boundary, then ASSERT().
536 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
537 @param AndData The value to AND with the PCI configuration register.
539 @return The value written to the PCI configuration register.
550 PCI_SEGMENT_INFO
*SegmentInfo
;
552 SegmentInfo
= GetPciSegmentInfo (&Count
);
553 return MmioAnd16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), AndData
);
557 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit value,
558 followed a bitwise OR with another 16-bit value.
560 Reads the 16-bit PCI configuration register specified by Address,
561 performs a bitwise AND between the read result and the value specified by AndData,
562 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
563 and writes the result to the 16-bit PCI configuration register specified by Address.
564 The value written to the PCI configuration register is returned.
565 This function must guarantee that all PCI read and write operations are serialized.
567 If any reserved bits in Address are set, then ASSERT().
568 If Address is not aligned on a 16-bit boundary, then ASSERT().
570 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
571 @param AndData The value to AND with the PCI configuration register.
572 @param OrData The value to OR with the PCI configuration register.
574 @return The value written to the PCI configuration register.
579 PciSegmentAndThenOr16 (
586 PCI_SEGMENT_INFO
*SegmentInfo
;
588 SegmentInfo
= GetPciSegmentInfo (&Count
);
589 return MmioAndThenOr16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), AndData
, OrData
);
593 Reads a bit field of a PCI configuration register.
595 Reads the bit field in a 16-bit PCI configuration register. The bit field is
596 specified by the StartBit and the EndBit. The value of the bit field is
599 If any reserved bits in Address are set, then ASSERT().
600 If Address is not aligned on a 16-bit boundary, then ASSERT().
601 If StartBit is greater than 15, then ASSERT().
602 If EndBit is greater than 15, then ASSERT().
603 If EndBit is less than StartBit, then ASSERT().
605 @param Address PCI configuration register to read.
606 @param StartBit The ordinal of the least significant bit in the bit field.
608 @param EndBit The ordinal of the most significant bit in the bit field.
611 @return The value of the bit field read from the PCI configuration register.
616 PciSegmentBitFieldRead16 (
623 PCI_SEGMENT_INFO
*SegmentInfo
;
625 SegmentInfo
= GetPciSegmentInfo (&Count
);
626 return MmioBitFieldRead16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
);
630 Writes a bit field to a PCI configuration register.
632 Writes Value to the bit field of the PCI configuration register. The bit
633 field is specified by the StartBit and the EndBit. All other bits in the
634 destination PCI configuration register are preserved. The new value of the
635 16-bit register is returned.
637 If any reserved bits in Address are set, then ASSERT().
638 If Address is not aligned on a 16-bit boundary, then ASSERT().
639 If StartBit is greater than 15, then ASSERT().
640 If EndBit is greater than 15, then ASSERT().
641 If EndBit is less than StartBit, then ASSERT().
642 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
644 @param Address PCI configuration register to write.
645 @param StartBit The ordinal of the least significant bit in the bit field.
647 @param EndBit The ordinal of the most significant bit in the bit field.
649 @param Value New value of the bit field.
651 @return The value written back to the PCI configuration register.
656 PciSegmentBitFieldWrite16 (
664 PCI_SEGMENT_INFO
*SegmentInfo
;
666 SegmentInfo
= GetPciSegmentInfo (&Count
);
667 return MmioBitFieldWrite16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, Value
);
671 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, writes
672 the result back to the bit field in the 16-bit port.
674 Reads the 16-bit PCI configuration register specified by Address, performs a
675 bitwise OR between the read result and the value specified by
676 OrData, and writes the result to the 16-bit PCI configuration register
677 specified by Address. The value written to the PCI configuration register is
678 returned. This function must guarantee that all PCI read and write operations
679 are serialized. Extra left bits in OrData are stripped.
681 If any reserved bits in Address are set, then ASSERT().
682 If Address is not aligned on a 16-bit boundary, then ASSERT().
683 If StartBit is greater than 15, then ASSERT().
684 If EndBit is greater than 15, then ASSERT().
685 If EndBit is less than StartBit, then ASSERT().
686 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
688 @param Address PCI configuration register to write.
689 @param StartBit The ordinal of the least significant bit in the bit field.
691 @param EndBit The ordinal of the most significant bit in the bit field.
693 @param OrData The value to OR with the PCI configuration register.
695 @return The value written back to the PCI configuration register.
700 PciSegmentBitFieldOr16 (
708 PCI_SEGMENT_INFO
*SegmentInfo
;
710 SegmentInfo
= GetPciSegmentInfo (&Count
);
711 return MmioBitFieldOr16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, OrData
);
715 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
716 AND, writes the result back to the bit field in the 16-bit register.
718 Reads the 16-bit PCI configuration register specified by Address, performs a
719 bitwise AND between the read result and the value specified by AndData, and
720 writes the result to the 16-bit PCI configuration register specified by
721 Address. The value written to the PCI configuration register is returned.
722 This function must guarantee that all PCI read and write operations are
723 serialized. Extra left bits in AndData are stripped.
725 If any reserved bits in Address are set, then ASSERT().
726 If Address is not aligned on a 16-bit boundary, then ASSERT().
727 If StartBit is greater than 15, then ASSERT().
728 If EndBit is greater than 15, then ASSERT().
729 If EndBit is less than StartBit, then ASSERT().
730 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
732 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
733 @param StartBit The ordinal of the least significant bit in the bit field.
735 @param EndBit The ordinal of the most significant bit in the bit field.
737 @param AndData The value to AND with the PCI configuration register.
739 @return The value written back to the PCI configuration register.
744 PciSegmentBitFieldAnd16 (
752 PCI_SEGMENT_INFO
*SegmentInfo
;
754 SegmentInfo
= GetPciSegmentInfo (&Count
);
755 return MmioBitFieldAnd16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, AndData
);
759 Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
760 bitwise OR, and writes the result back to the bit field in the
763 Reads the 16-bit PCI configuration register specified by Address, performs a
764 bitwise AND followed by a bitwise OR between the read result and
765 the value specified by AndData, and writes the result to the 16-bit PCI
766 configuration register specified by Address. The value written to the PCI
767 configuration register is returned. This function must guarantee that all PCI
768 read and write operations are serialized. Extra left bits in both AndData and
771 If any reserved bits in Address are set, then ASSERT().
772 If StartBit is greater than 15, then ASSERT().
773 If EndBit is greater than 15, then ASSERT().
774 If EndBit is less than StartBit, then ASSERT().
775 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
776 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
778 @param Address PCI configuration register to write.
779 @param StartBit The ordinal of the least significant bit in the bit field.
781 @param EndBit The ordinal of the most significant bit in the bit field.
783 @param AndData The value to AND with the PCI configuration register.
784 @param OrData The value to OR with the result of the AND operation.
786 @return The value written back to the PCI configuration register.
791 PciSegmentBitFieldAndThenOr16 (
800 PCI_SEGMENT_INFO
*SegmentInfo
;
801 SegmentInfo
= GetPciSegmentInfo (&Count
);
802 return MmioBitFieldAndThenOr16 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, AndData
, OrData
);
806 Reads a 32-bit PCI configuration register.
808 Reads and returns the 32-bit PCI configuration register specified by Address.
809 This function must guarantee that all PCI read and write operations are serialized.
811 If any reserved bits in Address are set, then ASSERT().
812 If Address is not aligned on a 32-bit boundary, then ASSERT().
814 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
816 @return The 32-bit PCI configuration register specified by Address.
826 PCI_SEGMENT_INFO
*SegmentInfo
;
828 SegmentInfo
= GetPciSegmentInfo (&Count
);
829 return MmioRead32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
));
833 Writes a 32-bit PCI configuration register.
835 Writes the 32-bit PCI configuration register specified by Address with the value specified by Value.
836 Value is returned. This function must guarantee that all PCI read and write operations are serialized.
838 If any reserved bits in Address are set, then ASSERT().
839 If Address is not aligned on a 32-bit boundary, then ASSERT().
841 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
842 @param Value The value to write.
844 @return The parameter of Value.
855 PCI_SEGMENT_INFO
*SegmentInfo
;
857 SegmentInfo
= GetPciSegmentInfo (&Count
);
858 return MmioWrite32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), Value
);
862 Performs a bitwise OR of a 32-bit PCI configuration register with a 32-bit value.
864 Reads the 32-bit PCI configuration register specified by Address,
865 performs a bitwise OR between the read result and the value specified by OrData,
866 and writes the result to the 32-bit PCI configuration register specified by Address.
867 The value written to the PCI configuration register is returned.
868 This function must guarantee that all PCI read and write operations are serialized.
870 If any reserved bits in Address are set, then ASSERT().
871 If Address is not aligned on a 32-bit boundary, then ASSERT().
873 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
874 @param OrData The value to OR with the PCI configuration register.
876 @return The value written to the PCI configuration register.
887 PCI_SEGMENT_INFO
*SegmentInfo
;
889 SegmentInfo
= GetPciSegmentInfo (&Count
);
890 return MmioOr32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), OrData
);
894 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit value.
896 Reads the 32-bit PCI configuration register specified by Address,
897 performs a bitwise AND between the read result and the value specified by AndData,
898 and writes the result to the 32-bit PCI configuration register specified by Address.
899 The value written to the PCI configuration register is returned.
900 This function must guarantee that all PCI read and write operations are serialized.
902 If any reserved bits in Address are set, then ASSERT().
903 If Address is not aligned on a 32-bit boundary, then ASSERT().
905 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
906 @param AndData The value to AND with the PCI configuration register.
908 @return The value written to the PCI configuration register.
919 PCI_SEGMENT_INFO
*SegmentInfo
;
921 SegmentInfo
= GetPciSegmentInfo (&Count
);
922 return MmioAnd32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), AndData
);
926 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit value,
927 followed a bitwise OR with another 32-bit value.
929 Reads the 32-bit PCI configuration register specified by Address,
930 performs a bitwise AND between the read result and the value specified by AndData,
931 performs a bitwise OR between the result of the AND operation and the value specified by OrData,
932 and writes the result to the 32-bit PCI configuration register specified by Address.
933 The value written to the PCI configuration register is returned.
934 This function must guarantee that all PCI read and write operations are serialized.
936 If any reserved bits in Address are set, then ASSERT().
937 If Address is not aligned on a 32-bit boundary, then ASSERT().
939 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
940 @param AndData The value to AND with the PCI configuration register.
941 @param OrData The value to OR with the PCI configuration register.
943 @return The value written to the PCI configuration register.
948 PciSegmentAndThenOr32 (
955 PCI_SEGMENT_INFO
*SegmentInfo
;
957 SegmentInfo
= GetPciSegmentInfo (&Count
);
958 return MmioAndThenOr32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), AndData
, OrData
);
962 Reads a bit field of a PCI configuration register.
964 Reads the bit field in a 32-bit PCI configuration register. The bit field is
965 specified by the StartBit and the EndBit. The value of the bit field is
968 If any reserved bits in Address are set, then ASSERT().
969 If Address is not aligned on a 32-bit boundary, then ASSERT().
970 If StartBit is greater than 31, then ASSERT().
971 If EndBit is greater than 31, then ASSERT().
972 If EndBit is less than StartBit, then ASSERT().
974 @param Address PCI configuration register to read.
975 @param StartBit The ordinal of the least significant bit in the bit field.
977 @param EndBit The ordinal of the most significant bit in the bit field.
980 @return The value of the bit field read from the PCI configuration register.
985 PciSegmentBitFieldRead32 (
992 PCI_SEGMENT_INFO
*SegmentInfo
;
994 SegmentInfo
= GetPciSegmentInfo (&Count
);
995 return MmioBitFieldRead32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
);
999 Writes a bit field to a PCI configuration register.
1001 Writes Value to the bit field of the PCI configuration register. The bit
1002 field is specified by the StartBit and the EndBit. All other bits in the
1003 destination PCI configuration register are preserved. The new value of the
1004 32-bit register is returned.
1006 If any reserved bits in Address are set, then ASSERT().
1007 If Address is not aligned on a 32-bit boundary, then ASSERT().
1008 If StartBit is greater than 31, then ASSERT().
1009 If EndBit is greater than 31, then ASSERT().
1010 If EndBit is less than StartBit, then ASSERT().
1011 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1013 @param Address PCI configuration register to write.
1014 @param StartBit The ordinal of the least significant bit in the bit field.
1016 @param EndBit The ordinal of the most significant bit in the bit field.
1018 @param Value New value of the bit field.
1020 @return The value written back to the PCI configuration register.
1025 PciSegmentBitFieldWrite32 (
1033 PCI_SEGMENT_INFO
*SegmentInfo
;
1035 SegmentInfo
= GetPciSegmentInfo (&Count
);
1036 return MmioBitFieldWrite32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, Value
);
1040 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and
1041 writes the result back to the bit field in the 32-bit port.
1043 Reads the 32-bit PCI configuration register specified by Address, performs a
1044 bitwise OR between the read result and the value specified by
1045 OrData, and writes the result to the 32-bit PCI configuration register
1046 specified by Address. The value written to the PCI configuration register is
1047 returned. This function must guarantee that all PCI read and write operations
1048 are serialized. Extra left bits in OrData are stripped.
1050 If any reserved bits in Address are set, then ASSERT().
1051 If StartBit is greater than 31, then ASSERT().
1052 If EndBit is greater than 31, then ASSERT().
1053 If EndBit is less than StartBit, then ASSERT().
1054 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1056 @param Address PCI configuration register to write.
1057 @param StartBit The ordinal of the least significant bit in the bit field.
1059 @param EndBit The ordinal of the most significant bit in the bit field.
1061 @param OrData The value to OR with the PCI configuration register.
1063 @return The value written back to the PCI configuration register.
1068 PciSegmentBitFieldOr32 (
1076 PCI_SEGMENT_INFO
*SegmentInfo
;
1078 SegmentInfo
= GetPciSegmentInfo (&Count
);
1079 return MmioBitFieldOr32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), 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.
1087 Reads the 32-bit PCI configuration register specified by Address, performs a bitwise
1088 AND between the read result and the value specified by AndData, and writes the result
1089 to the 32-bit PCI configuration register specified by Address. The value written to
1090 the PCI configuration register is returned. This function must guarantee that all PCI
1091 read and write operations are serialized. Extra left bits in AndData are stripped.
1092 If any reserved bits in Address are set, then ASSERT().
1093 If Address is not aligned on a 32-bit boundary, then ASSERT().
1094 If StartBit is greater than 31, then ASSERT().
1095 If EndBit is greater than 31, then ASSERT().
1096 If EndBit is less than StartBit, then ASSERT().
1097 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1099 @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register.
1100 @param StartBit The ordinal of the least significant bit in the bit field.
1102 @param EndBit The ordinal of the most significant bit in the bit field.
1104 @param AndData The value to AND with the PCI configuration register.
1106 @return The value written back to the PCI configuration register.
1111 PciSegmentBitFieldAnd32 (
1119 PCI_SEGMENT_INFO
*SegmentInfo
;
1121 SegmentInfo
= GetPciSegmentInfo (&Count
);
1122 return MmioBitFieldAnd32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, AndData
);
1126 Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
1127 bitwise OR, and writes the result back to the bit field in the
1130 Reads the 32-bit PCI configuration register specified by Address, performs a
1131 bitwise AND followed by a bitwise OR between the read result and
1132 the value specified by AndData, and writes the result to the 32-bit PCI
1133 configuration register specified by Address. The value written to the PCI
1134 configuration register is returned. This function must guarantee that all PCI
1135 read and write operations are serialized. Extra left bits in both AndData and
1136 OrData are stripped.
1138 If any reserved bits in Address are set, then ASSERT().
1139 If StartBit is greater than 31, then ASSERT().
1140 If EndBit is greater than 31, then ASSERT().
1141 If EndBit is less than StartBit, then ASSERT().
1142 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1143 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1145 @param Address PCI configuration register to write.
1146 @param StartBit The ordinal of the least significant bit in the bit field.
1148 @param EndBit The ordinal of the most significant bit in the bit field.
1150 @param AndData The value to AND with the PCI configuration register.
1151 @param OrData The value to OR with the result of the AND operation.
1153 @return The value written back to the PCI configuration register.
1158 PciSegmentBitFieldAndThenOr32 (
1167 PCI_SEGMENT_INFO
*SegmentInfo
;
1168 SegmentInfo
= GetPciSegmentInfo (&Count
);
1169 return MmioBitFieldAndThenOr32 (PciSegmentLibGetEcamAddress (Address
, SegmentInfo
, Count
), StartBit
, EndBit
, AndData
, OrData
);
1173 Reads a range of PCI configuration registers into a caller supplied buffer.
1175 Reads the range of PCI configuration registers specified by StartAddress and
1176 Size into the buffer specified by Buffer. This function only allows the PCI
1177 configuration registers from a single PCI function to be read. Size is
1178 returned. When possible 32-bit PCI configuration read cycles are used to read
1179 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit
1180 and 16-bit PCI configuration read cycles may be used at the beginning and the
1183 If any reserved bits in StartAddress are set, then ASSERT().
1184 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1185 If Size > 0 and Buffer is NULL, then ASSERT().
1187 @param StartAddress Starting address that encodes the PCI Segment, Bus, Device,
1188 Function and Register.
1189 @param Size Size in bytes of the transfer.
1190 @param Buffer Pointer to a buffer receiving the data read.
1197 PciSegmentReadBuffer (
1198 IN UINT64 StartAddress
,
1205 PCI_SEGMENT_INFO
*SegmentInfo
;
1208 ASSERT (((StartAddress
& 0xFFF) + Size
) <= 0x1000);
1210 SegmentInfo
= GetPciSegmentInfo (&Count
);
1211 Address
= PciSegmentLibGetEcamAddress (StartAddress
, SegmentInfo
, Count
);
1217 ASSERT (Buffer
!= NULL
);
1220 // Save Size for return
1224 if ((Address
& BIT0
) != 0) {
1226 // Read a byte if StartAddress is byte aligned
1228 *(volatile UINT8
*)Buffer
= MmioRead8 (Address
);
1229 Address
+= sizeof (UINT8
);
1230 Size
-= sizeof (UINT8
);
1231 Buffer
= (UINT8
*)Buffer
+ 1;
1234 if (Size
>= sizeof (UINT16
) && (Address
& BIT1
) != 0) {
1236 // Read a word if StartAddress is word aligned
1238 WriteUnaligned16 (Buffer
, MmioRead16 (Address
));
1239 Address
+= sizeof (UINT16
);
1240 Size
-= sizeof (UINT16
);
1241 Buffer
= (UINT16
*)Buffer
+ 1;
1244 while (Size
>= sizeof (UINT32
)) {
1246 // Read as many double words as possible
1248 WriteUnaligned32 (Buffer
, MmioRead32 (Address
));
1249 Address
+= sizeof (UINT32
);
1250 Size
-= sizeof (UINT32
);
1251 Buffer
= (UINT32
*)Buffer
+ 1;
1254 if (Size
>= sizeof (UINT16
)) {
1256 // Read the last remaining word if exist
1258 WriteUnaligned16 (Buffer
, MmioRead16 (Address
));
1259 Address
+= sizeof (UINT16
);
1260 Size
-= sizeof (UINT16
);
1261 Buffer
= (UINT16
*)Buffer
+ 1;
1264 if (Size
>= sizeof (UINT8
)) {
1266 // Read the last remaining byte if exist
1268 *(volatile UINT8
*)Buffer
= MmioRead8 (Address
);
1275 Copies the data in a caller supplied buffer to a specified range of PCI
1276 configuration space.
1278 Writes the range of PCI configuration registers specified by StartAddress and
1279 Size from the buffer specified by Buffer. This function only allows the PCI
1280 configuration registers from a single PCI function to be written. Size is
1281 returned. When possible 32-bit PCI configuration write cycles are used to
1282 write from StartAdress to StartAddress + Size. Due to alignment restrictions,
1283 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
1284 and the end of the range.
1286 If any reserved bits in StartAddress are set, then ASSERT().
1287 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1288 If Size > 0 and Buffer is NULL, then ASSERT().
1290 @param StartAddress Starting address that encodes the PCI Segment, Bus, Device,
1291 Function and Register.
1292 @param Size Size in bytes of the transfer.
1293 @param Buffer Pointer to a buffer containing the data to write.
1295 @return The parameter of Size.
1300 PciSegmentWriteBuffer (
1301 IN UINT64 StartAddress
,
1308 PCI_SEGMENT_INFO
*SegmentInfo
;
1311 ASSERT (((StartAddress
& 0xFFF) + Size
) <= 0x1000);
1313 SegmentInfo
= GetPciSegmentInfo (&Count
);
1314 Address
= PciSegmentLibGetEcamAddress (StartAddress
, SegmentInfo
, Count
);
1320 ASSERT (Buffer
!= NULL
);
1323 // Save Size for return
1327 if ((Address
& BIT0
) != 0) {
1329 // Write a byte if StartAddress is byte aligned
1331 MmioWrite8 (Address
, *(UINT8
*)Buffer
);
1332 Address
+= sizeof (UINT8
);
1333 Size
-= sizeof (UINT8
);
1334 Buffer
= (UINT8
*)Buffer
+ 1;
1337 if (Size
>= sizeof (UINT16
) && (Address
& BIT1
) != 0) {
1339 // Write a word if StartAddress is word aligned
1341 MmioWrite16 (Address
, ReadUnaligned16 (Buffer
));
1342 Address
+= sizeof (UINT16
);
1343 Size
-= sizeof (UINT16
);
1344 Buffer
= (UINT16
*)Buffer
+ 1;
1347 while (Size
>= sizeof (UINT32
)) {
1349 // Write as many double words as possible
1351 MmioWrite32 (Address
, ReadUnaligned32 (Buffer
));
1352 Address
+= sizeof (UINT32
);
1353 Size
-= sizeof (UINT32
);
1354 Buffer
= (UINT32
*)Buffer
+ 1;
1357 if (Size
>= sizeof (UINT16
)) {
1359 // Write the last remaining word if exist
1361 MmioWrite16 (Address
, ReadUnaligned16 (Buffer
));
1362 Address
+= sizeof (UINT16
);
1363 Size
-= sizeof (UINT16
);
1364 Buffer
= (UINT16
*)Buffer
+ 1;
1367 if (Size
>= sizeof (UINT8
)) {
1369 // Write the last remaining byte if exist
1371 MmioWrite8 (Address
, *(UINT8
*)Buffer
);