3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 PCI I/O Abstraction Driver
31 ReportErrorStatusCode (
32 IN PCI_IO_DEVICE
*PciIoDevice
,
33 IN EFI_STATUS_CODE_VALUE Code
37 // PCI I/O Support Function Prototypes
41 // Pci Io Protocol Interface
43 static EFI_PCI_IO_PROTOCOL PciIoInterface
= {
66 PciIoGetBarAttributes
,
67 PciIoSetBarAttributes
,
74 ReportErrorStatusCode (
75 IN PCI_IO_DEVICE
*PciIoDevice
,
76 IN EFI_STATUS_CODE_VALUE Code
82 report a error Status code of PCI bus driver controller
91 // TODO: PciIoDevice - add argument and description to function comment
92 // TODO: Code - add argument and description to function comment
94 return REPORT_STATUS_CODE_WITH_DEVICE_PATH (
95 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
97 PciIoDevice
->DevicePath
102 InitializePciIoInstance (
103 PCI_IO_DEVICE
*PciIoDevice
109 Initializes a PCI I/O Instance
118 // TODO: PciIoDevice - add argument and description to function comment
119 // TODO: EFI_SUCCESS - add return value to function comment
121 CopyMem (&PciIoDevice
->PciIo
, &PciIoInterface
, sizeof (EFI_PCI_IO_PROTOCOL
));
126 PciIoVerifyBarAccess (
127 PCI_IO_DEVICE
*PciIoDevice
,
130 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
138 Verifies access to a PCI Base Address Register (BAR)
147 // TODO: PciIoDevice - add argument and description to function comment
148 // TODO: BarIndex - add argument and description to function comment
149 // TODO: Type - add argument and description to function comment
150 // TODO: Width - add argument and description to function comment
151 // TODO: Count - add argument and description to function comment
152 // TODO: Offset - add argument and description to function comment
153 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
154 // TODO: EFI_SUCCESS - add return value to function comment
155 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
156 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
157 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
158 // TODO: EFI_SUCCESS - add return value to function comment
160 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
161 return EFI_INVALID_PARAMETER
;
164 if (BarIndex
== EFI_PCI_IO_PASS_THROUGH_BAR
) {
169 // BarIndex 0-5 is legal
171 if (BarIndex
>= PCI_MAX_BAR
) {
172 return EFI_INVALID_PARAMETER
;
175 if (!CheckBarType (PciIoDevice
, BarIndex
, Type
)) {
176 return EFI_INVALID_PARAMETER
;
180 // If Width is EfiPciIoWidthFifoUintX then convert to EfiPciIoWidthUintX
181 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
183 if (Width
>= EfiPciWidthFifoUint8
&& Width
<= EfiPciWidthFifoUint64
) {
189 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PciIoDevice
->PciBar
[BarIndex
].Length
) {
190 return EFI_INVALID_PARAMETER
;
193 *Offset
= *Offset
+ PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
199 PciIoVerifyConfigAccess (
200 PCI_IO_DEVICE
*PciIoDevice
,
201 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
209 Verifies access to a PCI Config Header
218 // TODO: PciIoDevice - add argument and description to function comment
219 // TODO: Width - add argument and description to function comment
220 // TODO: Count - add argument and description to function comment
221 // TODO: Offset - add argument and description to function comment
222 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
223 // TODO: EFI_UNSUPPORTED - add return value to function comment
224 // TODO: EFI_UNSUPPORTED - add return value to function comment
225 // TODO: EFI_SUCCESS - add return value to function comment
229 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
230 return EFI_INVALID_PARAMETER
;
234 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
238 if (PciIoDevice
->IsPciExp
) {
239 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_EXP_MAX_CONFIG_OFFSET
) {
240 return EFI_UNSUPPORTED
;
243 ExtendOffset
= LShiftU64 (*Offset
, 32);
244 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
245 *Offset
= (*Offset
) | ExtendOffset
;
248 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_MAX_CONFIG_OFFSET
) {
249 return EFI_UNSUPPORTED
;
252 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, *Offset
);
261 IN EFI_PCI_IO_PROTOCOL
*This
,
262 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
283 // TODO: This - add argument and description to function comment
284 // TODO: Width - add argument and description to function comment
285 // TODO: BarIndex - add argument and description to function comment
286 // TODO: Offset - add argument and description to function comment
287 // TODO: Mask - add argument and description to function comment
288 // TODO: Value - add argument and description to function comment
289 // TODO: Delay - add argument and description to function comment
290 // TODO: Result - add argument and description to function comment
291 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
292 // TODO: EFI_UNSUPPORTED - add return value to function comment
293 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
296 PCI_IO_DEVICE
*PciIoDevice
;
298 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
300 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
301 return EFI_INVALID_PARAMETER
;
304 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, 1, &Offset
);
305 if (EFI_ERROR (Status
)) {
306 return EFI_UNSUPPORTED
;
309 if (Width
> EfiPciIoWidthUint64
) {
310 return EFI_INVALID_PARAMETER
;
313 Status
= PciIoDevice
->PciRootBridgeIo
->PollMem (
314 PciIoDevice
->PciRootBridgeIo
,
315 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
323 if (EFI_ERROR (Status
)) {
324 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
333 IN EFI_PCI_IO_PROTOCOL
*This
,
334 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
355 // TODO: This - add argument and description to function comment
356 // TODO: Width - add argument and description to function comment
357 // TODO: BarIndex - add argument and description to function comment
358 // TODO: Offset - add argument and description to function comment
359 // TODO: Mask - add argument and description to function comment
360 // TODO: Value - add argument and description to function comment
361 // TODO: Delay - add argument and description to function comment
362 // TODO: Result - add argument and description to function comment
363 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
364 // TODO: EFI_UNSUPPORTED - add return value to function comment
365 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
368 PCI_IO_DEVICE
*PciIoDevice
;
370 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
372 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
373 return EFI_INVALID_PARAMETER
;
376 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, 1, &Offset
);
377 if (EFI_ERROR (Status
)) {
378 return EFI_UNSUPPORTED
;
381 if (Width
> EfiPciIoWidthUint64
) {
382 return EFI_INVALID_PARAMETER
;
385 Status
= PciIoDevice
->PciRootBridgeIo
->PollIo (
386 PciIoDevice
->PciRootBridgeIo
,
387 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
395 if (EFI_ERROR (Status
)) {
396 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
405 IN EFI_PCI_IO_PROTOCOL
*This
,
406 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
416 Performs a PCI Memory Read Cycle
425 // TODO: This - add argument and description to function comment
426 // TODO: Width - add argument and description to function comment
427 // TODO: BarIndex - add argument and description to function comment
428 // TODO: Offset - add argument and description to function comment
429 // TODO: Count - add argument and description to function comment
430 // TODO: Buffer - add argument and description to function comment
431 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
432 // TODO: EFI_UNSUPPORTED - add return value to function comment
435 PCI_IO_DEVICE
*PciIoDevice
;
437 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
439 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
440 return EFI_INVALID_PARAMETER
;
443 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
444 if (EFI_ERROR (Status
)) {
445 return EFI_UNSUPPORTED
;
448 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Read (
449 PciIoDevice
->PciRootBridgeIo
,
450 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
456 if (EFI_ERROR (Status
)) {
457 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
466 IN EFI_PCI_IO_PROTOCOL
*This
,
467 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
477 Performs a PCI Memory Write Cycle
486 // TODO: This - add argument and description to function comment
487 // TODO: Width - add argument and description to function comment
488 // TODO: BarIndex - add argument and description to function comment
489 // TODO: Offset - add argument and description to function comment
490 // TODO: Count - add argument and description to function comment
491 // TODO: Buffer - add argument and description to function comment
492 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
493 // TODO: EFI_UNSUPPORTED - add return value to function comment
496 PCI_IO_DEVICE
*PciIoDevice
;
498 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
500 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
501 return EFI_INVALID_PARAMETER
;
504 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
505 if (EFI_ERROR (Status
)) {
506 return EFI_UNSUPPORTED
;
509 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Write (
510 PciIoDevice
->PciRootBridgeIo
,
511 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
517 if (EFI_ERROR (Status
)) {
518 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
527 IN EFI_PCI_IO_PROTOCOL
*This
,
528 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
538 Performs a PCI I/O Read Cycle
547 // TODO: This - add argument and description to function comment
548 // TODO: Width - add argument and description to function comment
549 // TODO: BarIndex - add argument and description to function comment
550 // TODO: Offset - add argument and description to function comment
551 // TODO: Count - add argument and description to function comment
552 // TODO: Buffer - add argument and description to function comment
553 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
554 // TODO: EFI_UNSUPPORTED - add return value to function comment
557 PCI_IO_DEVICE
*PciIoDevice
;
559 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
561 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
562 return EFI_INVALID_PARAMETER
;
565 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
566 if (EFI_ERROR (Status
)) {
567 return EFI_UNSUPPORTED
;
570 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Read (
571 PciIoDevice
->PciRootBridgeIo
,
572 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
578 if (EFI_ERROR (Status
)) {
579 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
588 IN EFI_PCI_IO_PROTOCOL
*This
,
589 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
599 Performs a PCI I/O Write Cycle
608 // TODO: This - add argument and description to function comment
609 // TODO: Width - add argument and description to function comment
610 // TODO: BarIndex - add argument and description to function comment
611 // TODO: Offset - add argument and description to function comment
612 // TODO: Count - add argument and description to function comment
613 // TODO: Buffer - add argument and description to function comment
614 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
615 // TODO: EFI_UNSUPPORTED - add return value to function comment
618 PCI_IO_DEVICE
*PciIoDevice
;
620 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
622 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
623 return EFI_INVALID_PARAMETER
;
626 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
627 if (EFI_ERROR (Status
)) {
628 return EFI_UNSUPPORTED
;
631 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Write (
632 PciIoDevice
->PciRootBridgeIo
,
633 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
639 if (EFI_ERROR (Status
)) {
640 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
649 IN EFI_PCI_IO_PROTOCOL
*This
,
650 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
659 Performs a PCI Configuration Read Cycle
668 // TODO: This - add argument and description to function comment
669 // TODO: Width - add argument and description to function comment
670 // TODO: Offset - add argument and description to function comment
671 // TODO: Count - add argument and description to function comment
672 // TODO: Buffer - add argument and description to function comment
675 PCI_IO_DEVICE
*PciIoDevice
;
678 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
681 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
682 if (EFI_ERROR (Status
)) {
686 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Read (
687 PciIoDevice
->PciRootBridgeIo
,
688 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
694 if (EFI_ERROR (Status
)) {
695 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
704 IN EFI_PCI_IO_PROTOCOL
*This
,
705 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
714 Performs a PCI Configuration Write Cycle
723 // TODO: This - add argument and description to function comment
724 // TODO: Width - add argument and description to function comment
725 // TODO: Offset - add argument and description to function comment
726 // TODO: Count - add argument and description to function comment
727 // TODO: Buffer - add argument and description to function comment
730 PCI_IO_DEVICE
*PciIoDevice
;
733 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
736 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
737 if (EFI_ERROR (Status
)) {
741 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Write (
742 PciIoDevice
->PciRootBridgeIo
,
743 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
749 if (EFI_ERROR (Status
)) {
750 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
759 IN EFI_PCI_IO_PROTOCOL
*This
,
760 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
761 IN UINT8 DestBarIndex
,
762 IN UINT64 DestOffset
,
763 IN UINT8 SrcBarIndex
,
780 // TODO: This - add argument and description to function comment
781 // TODO: Width - add argument and description to function comment
782 // TODO: DestBarIndex - add argument and description to function comment
783 // TODO: DestOffset - add argument and description to function comment
784 // TODO: SrcBarIndex - add argument and description to function comment
785 // TODO: SrcOffset - add argument and description to function comment
786 // TODO: Count - add argument and description to function comment
787 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
788 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
789 // TODO: EFI_UNSUPPORTED - add return value to function comment
790 // TODO: EFI_UNSUPPORTED - add return value to function comment
793 PCI_IO_DEVICE
*PciIoDevice
;
795 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
797 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
798 return EFI_INVALID_PARAMETER
;
801 if (Width
== EfiPciIoWidthFifoUint8
||
802 Width
== EfiPciIoWidthFifoUint16
||
803 Width
== EfiPciIoWidthFifoUint32
||
804 Width
== EfiPciIoWidthFifoUint64
||
805 Width
== EfiPciIoWidthFillUint8
||
806 Width
== EfiPciIoWidthFillUint16
||
807 Width
== EfiPciIoWidthFillUint32
||
808 Width
== EfiPciIoWidthFillUint64
) {
809 return EFI_INVALID_PARAMETER
;
812 Status
= PciIoVerifyBarAccess (PciIoDevice
, DestBarIndex
, PciBarTypeMem
, Width
, Count
, &DestOffset
);
813 if (EFI_ERROR (Status
)) {
814 return EFI_UNSUPPORTED
;
817 Status
= PciIoVerifyBarAccess (PciIoDevice
, SrcBarIndex
, PciBarTypeMem
, Width
, Count
, &SrcOffset
);
818 if (EFI_ERROR (Status
)) {
819 return EFI_UNSUPPORTED
;
822 Status
= PciIoDevice
->PciRootBridgeIo
->CopyMem (
823 PciIoDevice
->PciRootBridgeIo
,
824 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
830 if (EFI_ERROR (Status
)) {
831 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
840 IN EFI_PCI_IO_PROTOCOL
*This
,
841 IN EFI_PCI_IO_PROTOCOL_OPERATION Operation
,
842 IN VOID
*HostAddress
,
843 IN OUT UINTN
*NumberOfBytes
,
844 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
851 Maps a memory region for DMA
860 // TODO: This - add argument and description to function comment
861 // TODO: Operation - add argument and description to function comment
862 // TODO: HostAddress - add argument and description to function comment
863 // TODO: NumberOfBytes - add argument and description to function comment
864 // TODO: DeviceAddress - add argument and description to function comment
865 // TODO: Mapping - add argument and description to function comment
866 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
867 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
870 PCI_IO_DEVICE
*PciIoDevice
;
872 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
874 if (Operation
< 0 || Operation
>= EfiPciIoOperationMaximum
) {
875 return EFI_INVALID_PARAMETER
;
878 if (HostAddress
== NULL
|| NumberOfBytes
== NULL
|| DeviceAddress
== NULL
|| Mapping
== NULL
) {
879 return EFI_INVALID_PARAMETER
;
882 if (PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) {
883 Operation
= Operation
+ EfiPciOperationBusMasterRead64
;
886 Status
= PciIoDevice
->PciRootBridgeIo
->Map (
887 PciIoDevice
->PciRootBridgeIo
,
888 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION
) Operation
,
895 if (EFI_ERROR (Status
)) {
896 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
905 IN EFI_PCI_IO_PROTOCOL
*This
,
912 Unmaps a memory region for DMA
921 // TODO: This - add argument and description to function comment
922 // TODO: Mapping - add argument and description to function comment
925 PCI_IO_DEVICE
*PciIoDevice
;
927 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
929 Status
= PciIoDevice
->PciRootBridgeIo
->Unmap (
930 PciIoDevice
->PciRootBridgeIo
,
934 if (EFI_ERROR (Status
)) {
935 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
943 PciIoAllocateBuffer (
944 IN EFI_PCI_IO_PROTOCOL
*This
,
945 IN EFI_ALLOCATE_TYPE Type
,
946 IN EFI_MEMORY_TYPE MemoryType
,
948 OUT VOID
**HostAddress
,
955 Allocates a common buffer for DMA
964 // TODO: This - add argument and description to function comment
965 // TODO: Type - add argument and description to function comment
966 // TODO: MemoryType - add argument and description to function comment
967 // TODO: Pages - add argument and description to function comment
968 // TODO: HostAddress - add argument and description to function comment
969 // TODO: Attributes - add argument and description to function comment
970 // TODO: EFI_UNSUPPORTED - add return value to function comment
973 PCI_IO_DEVICE
*PciIoDevice
;
976 (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE
| EFI_PCI_ATTRIBUTE_MEMORY_CACHED
))) {
977 return EFI_UNSUPPORTED
;
980 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
982 if (PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) {
983 Attributes
|= EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
986 Status
= PciIoDevice
->PciRootBridgeIo
->AllocateBuffer (
987 PciIoDevice
->PciRootBridgeIo
,
995 if (EFI_ERROR (Status
)) {
996 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1005 IN EFI_PCI_IO_PROTOCOL
*This
,
1007 IN VOID
*HostAddress
1011 Routine Description:
1013 Frees a common buffer
1022 // TODO: This - add argument and description to function comment
1023 // TODO: Pages - add argument and description to function comment
1024 // TODO: HostAddress - add argument and description to function comment
1027 PCI_IO_DEVICE
*PciIoDevice
;
1029 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1031 Status
= PciIoDevice
->PciRootBridgeIo
->FreeBuffer (
1032 PciIoDevice
->PciRootBridgeIo
,
1037 if (EFI_ERROR (Status
)) {
1038 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1047 IN EFI_PCI_IO_PROTOCOL
*This
1051 Routine Description:
1053 Flushes a DMA buffer
1062 // TODO: This - add argument and description to function comment
1065 PCI_IO_DEVICE
*PciIoDevice
;
1067 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1069 Status
= PciIoDevice
->PciRootBridgeIo
->Flush (
1070 PciIoDevice
->PciRootBridgeIo
1072 if (EFI_ERROR (Status
)) {
1073 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1082 IN EFI_PCI_IO_PROTOCOL
*This
,
1090 Routine Description:
1092 Gets a PCI device's current bus number, device number, and function number.
1101 // TODO: This - add argument and description to function comment
1102 // TODO: Segment - add argument and description to function comment
1103 // TODO: Bus - add argument and description to function comment
1104 // TODO: Device - add argument and description to function comment
1105 // TODO: Function - add argument and description to function comment
1106 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1107 // TODO: EFI_SUCCESS - add return value to function comment
1109 PCI_IO_DEVICE
*PciIoDevice
;
1111 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1113 if (Segment
== NULL
|| Bus
== NULL
|| Device
== NULL
|| Function
== NULL
) {
1114 return EFI_INVALID_PARAMETER
;
1117 *Segment
= PciIoDevice
->PciRootBridgeIo
->SegmentNumber
;
1118 *Bus
= PciIoDevice
->BusNumber
;
1119 *Device
= PciIoDevice
->DeviceNumber
;
1120 *Function
= PciIoDevice
->FunctionNumber
;
1127 IN PCI_IO_DEVICE
*PciIoDevice
,
1129 PCI_BAR_TYPE BarType
1133 Routine Description:
1135 Sets a PCI controllers attributes on a resource range
1144 // TODO: PciIoDevice - add argument and description to function comment
1145 // TODO: BarIndex - add argument and description to function comment
1146 // TODO: BarType - add argument and description to function comment
1152 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem32
&&
1153 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem32
&&
1154 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem64
&&
1155 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem64
) {
1162 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo32
&&
1163 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo16
){
1177 ModifyRootBridgeAttributes (
1178 IN PCI_IO_DEVICE
*PciIoDevice
,
1179 IN UINT64 Attributes
,
1180 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1184 Routine Description:
1186 Set new attributes to a Root Bridge
1195 // TODO: PciIoDevice - add argument and description to function comment
1196 // TODO: Attributes - add argument and description to function comment
1197 // TODO: Operation - add argument and description to function comment
1198 // TODO: EFI_UNSUPPORTED - add return value to function comment
1199 // TODO: EFI_UNSUPPORTED - add return value to function comment
1200 // TODO: EFI_SUCCESS - add return value to function comment
1202 UINT64 PciRootBridgeSupports
;
1203 UINT64 PciRootBridgeAttributes
;
1204 UINT64 NewPciRootBridgeAttributes
;
1208 // Get the current attributes of this PCI device's PCI Root Bridge
1210 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1211 PciIoDevice
->PciRootBridgeIo
,
1212 &PciRootBridgeSupports
,
1213 &PciRootBridgeAttributes
1215 if (EFI_ERROR (Status
)) {
1216 return EFI_UNSUPPORTED
;
1220 // Record the new attribute of the Root Bridge
1222 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1223 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
| Attributes
;
1225 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
& (~Attributes
);
1229 // Call the PCI Root Bridge to attempt to modify the attributes
1231 if (NewPciRootBridgeAttributes
^ PciRootBridgeAttributes
) {
1233 Status
= PciIoDevice
->PciRootBridgeIo
->SetAttributes (
1234 PciIoDevice
->PciRootBridgeIo
,
1235 NewPciRootBridgeAttributes
,
1239 if (EFI_ERROR (Status
)) {
1241 // The PCI Root Bridge could not modify the attributes, so return the error.
1243 return EFI_UNSUPPORTED
;
1248 // Also update the attributes for this Root Bridge structure
1250 PciIoDevice
->Attributes
= NewPciRootBridgeAttributes
;
1256 SupportPaletteSnoopAttributes (
1257 IN PCI_IO_DEVICE
*PciIoDevice
,
1258 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1262 Routine Description:
1264 Check whether this device can be enable/disable to snoop
1273 // TODO: PciIoDevice - add argument and description to function comment
1274 // TODO: Operation - add argument and description to function comment
1275 // TODO: EFI_UNSUPPORTED - add return value to function comment
1276 // TODO: EFI_SUCCESS - add return value to function comment
1277 // TODO: EFI_SUCCESS - add return value to function comment
1278 // TODO: EFI_UNSUPPORTED - add return value to function comment
1279 // TODO: EFI_UNSUPPORTED - add return value to function comment
1280 // TODO: EFI_SUCCESS - add return value to function comment
1281 // TODO: EFI_UNSUPPORTED - add return value to function comment
1282 // TODO: EFI_UNSUPPORTED - add return value to function comment
1283 // TODO: EFI_SUCCESS - add return value to function comment
1285 PCI_IO_DEVICE
*Temp
;
1289 // Snoop attribute can be only modified by GFX
1291 if (!IS_PCI_GFX (&PciIoDevice
->Pci
)) {
1292 return EFI_UNSUPPORTED
;
1296 // Get the boot VGA on the same segement
1298 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1302 // If there is no VGA device on the segement, set
1303 // this graphics card to decode the palette range
1309 // Check these two agents are on the same path
1311 if (!PciDevicesOnTheSamePath (Temp
, PciIoDevice
)) {
1313 // they are not on the same path, so snoop can be enabled or disabled
1318 // Check if they are on the same bus
1320 if (Temp
->Parent
== PciIoDevice
->Parent
) {
1322 PciReadCommandRegister (Temp
, &VGACommand
);
1325 // If they are on the same bus, either one can
1326 // be set to snoop, the other set to decode
1328 if (VGACommand
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) {
1330 // VGA has set to snoop, so GFX can be only set to disable snoop
1332 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1333 return EFI_UNSUPPORTED
;
1337 // VGA has disabled to snoop, so GFX can be only enabled
1339 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1340 return EFI_UNSUPPORTED
;
1348 // If they are on the same path but on the different bus
1349 // The first agent is set to snoop, the second one set to
1353 if (Temp
->BusNumber
> PciIoDevice
->BusNumber
) {
1355 // GFX should be set to decode
1357 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1358 PciEnableCommandRegister (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1359 Temp
->Attributes
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1361 return EFI_UNSUPPORTED
;
1366 // GFX should be set to snoop
1368 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1369 PciDisableCommandRegister (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1370 Temp
->Attributes
&= (~EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1372 return EFI_UNSUPPORTED
;
1383 IN EFI_PCI_IO_PROTOCOL
* This
,
1384 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1385 IN UINT64 Attributes
,
1386 OUT UINT64
*Result OPTIONAL
1390 Routine Description:
1400 // TODO: This - add argument and description to function comment
1401 // TODO: Operation - add argument and description to function comment
1402 // TODO: Attributes - add argument and description to function comment
1403 // TODO: Result - add argument and description to function comment
1404 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1405 // TODO: EFI_SUCCESS - add return value to function comment
1406 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1407 // TODO: EFI_SUCCESS - add return value to function comment
1408 // TODO: EFI_UNSUPPORTED - add return value to function comment
1409 // TODO: EFI_UNSUPPORTED - add return value to function comment
1410 // TODO: EFI_SUCCESS - add return value to function comment
1411 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1412 // TODO: EFI_UNSUPPORTED - add return value to function comment
1413 // TODO: EFI_UNSUPPORTED - add return value to function comment
1414 // TODO: EFI_UNSUPPORTED - add return value to function comment
1418 PCI_IO_DEVICE
*PciIoDevice
;
1419 PCI_IO_DEVICE
*UpStreamBridge
;
1420 PCI_IO_DEVICE
*Temp
;
1423 UINT64 UpStreamAttributes
;
1424 UINT16 BridgeControl
;
1427 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1429 switch (Operation
) {
1430 case EfiPciIoAttributeOperationGet
:
1431 if (Result
== NULL
) {
1432 return EFI_INVALID_PARAMETER
;
1435 *Result
= PciIoDevice
->Attributes
;
1438 case EfiPciIoAttributeOperationSupported
:
1439 if (Result
== NULL
) {
1440 return EFI_INVALID_PARAMETER
;
1443 *Result
= PciIoDevice
->Supports
;
1446 case EfiPciIoAttributeOperationSet
:
1447 Status
= PciIoDevice
->PciIo
.Attributes (
1448 &(PciIoDevice
->PciIo
),
1449 EfiPciIoAttributeOperationEnable
,
1453 if (EFI_ERROR (Status
)) {
1454 return EFI_UNSUPPORTED
;
1457 Status
= PciIoDevice
->PciIo
.Attributes (
1458 &(PciIoDevice
->PciIo
),
1459 EfiPciIoAttributeOperationDisable
,
1460 (~Attributes
) & (PciIoDevice
->Supports
),
1463 if (EFI_ERROR (Status
)) {
1464 return EFI_UNSUPPORTED
;
1469 case EfiPciIoAttributeOperationEnable
:
1470 case EfiPciIoAttributeOperationDisable
:
1474 return EFI_INVALID_PARAMETER
;
1477 // Just a trick for ENABLE attribute
1479 if ((Attributes
& EFI_PCI_DEVICE_ENABLE
) == EFI_PCI_DEVICE_ENABLE
) {
1480 Attributes
&= (PciIoDevice
->Supports
);
1483 // Raise the EFI_P_PC_ENABLE Status code
1485 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
1487 EFI_IO_BUS_PCI
| EFI_P_PC_ENABLE
,
1488 PciIoDevice
->DevicePath
1493 // If no attributes can be supported, then return.
1494 // Otherwise, set the attributes that it can support.
1496 Supports
= (PciIoDevice
->Supports
) & Attributes
;
1497 if (Supports
!= Attributes
) {
1498 return EFI_UNSUPPORTED
;
1502 // For Root Bridge, just call RootBridgeIo to set attributes;
1504 if (!PciIoDevice
->Parent
) {
1505 Status
= ModifyRootBridgeAttributes (PciIoDevice
, Attributes
, Operation
);
1513 // For PPB & P2C, set relevant attribute bits
1515 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1517 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) {
1518 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA
;
1521 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_ISA_IO
) {
1522 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_ISA
;
1525 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) {
1526 Command
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
1531 // Do with the attributes on VGA
1533 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) ||
1534 (IS_PCI_VGA(&PciIoDevice
->Pci
) &&
1535 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) ||
1536 (Attributes
& EFI_PCI_IO_ATTRIBUTE_MEMORY
)))) {
1538 // Check if a VGA has been enabled before enabling a new one
1540 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1542 // Check if there have been an active VGA device on the same segment
1544 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1545 if (Temp
&& Temp
!= PciIoDevice
) {
1547 // An active VGA has been detected, so can not enable another
1549 return EFI_UNSUPPORTED
;
1555 // Do with the attributes on GFX
1557 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) {
1559 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1561 // Check if snoop can be enabled in current configuration
1563 Status
= SupportPaletteSnoopAttributes (PciIoDevice
, Operation
);
1565 if (EFI_ERROR (Status
)) {
1568 // Enable operation is forbidden, so mask the bit in attributes
1569 // so as to keep consistent with the actual Status
1571 // Attributes &= (~EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO);
1575 return EFI_UNSUPPORTED
;
1581 // It can be supported, so get ready to set the bit
1583 Command
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1587 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) {
1588 Command
|= EFI_PCI_COMMAND_IO_SPACE
;
1591 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_MEMORY
) {
1592 Command
|= EFI_PCI_COMMAND_MEMORY_SPACE
;
1595 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
) {
1596 Command
|= EFI_PCI_COMMAND_BUS_MASTER
;
1599 // The upstream bridge should be also set to revelant attribute
1600 // expect for IO, Mem and BusMaster
1602 UpStreamAttributes
= Attributes
&
1603 (~(EFI_PCI_IO_ATTRIBUTE_IO
|
1604 EFI_PCI_IO_ATTRIBUTE_MEMORY
|
1605 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
1608 UpStreamBridge
= PciIoDevice
->Parent
;
1610 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1612 // Enable relevant attributes to command register and bridge control register
1614 Status
= PciEnableCommandRegister (PciIoDevice
, Command
);
1615 if (BridgeControl
) {
1616 Status
= PciEnableBridgeControlRegister (PciIoDevice
, BridgeControl
);
1619 PciIoDevice
->Attributes
|= Attributes
;
1622 // Enable attributes of the upstream bridge
1624 Status
= UpStreamBridge
->PciIo
.Attributes (
1625 &(UpStreamBridge
->PciIo
),
1626 EfiPciIoAttributeOperationEnable
,
1633 // Disable relevant attributes to command register and bridge control register
1635 Status
= PciDisableCommandRegister (PciIoDevice
, Command
);
1636 if (BridgeControl
) {
1637 Status
= PciDisableBridgeControlRegister (PciIoDevice
, BridgeControl
);
1640 PciIoDevice
->Attributes
&= (~Attributes
);
1641 Status
= EFI_SUCCESS
;
1645 if (EFI_ERROR (Status
)) {
1646 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1654 PciIoGetBarAttributes (
1655 IN EFI_PCI_IO_PROTOCOL
* This
,
1657 OUT UINT64
*Supports
, OPTIONAL
1658 OUT VOID
**Resources OPTIONAL
1662 Routine Description:
1672 // TODO: This - add argument and description to function comment
1673 // TODO: BarIndex - add argument and description to function comment
1674 // TODO: Supports - add argument and description to function comment
1675 // TODO: Resources - add argument and description to function comment
1676 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1677 // TODO: EFI_UNSUPPORTED - add return value to function comment
1678 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
1679 // TODO: EFI_SUCCESS - add return value to function comment
1682 UINT8
*Configuration
;
1684 PCI_IO_DEVICE
*PciIoDevice
;
1685 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1686 EFI_ACPI_END_TAG_DESCRIPTOR
*PtrEnd
;
1690 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1692 if (Supports
== NULL
&& Resources
== NULL
) {
1693 return EFI_INVALID_PARAMETER
;
1696 if (BarIndex
>= PCI_MAX_BAR
) {
1697 return EFI_UNSUPPORTED
;
1701 // This driver does not support modifications to the WRITE_COMBINE or
1702 // CACHED attributes for BAR ranges.
1704 if (Supports
!= NULL
) {
1705 *Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1708 if (Resources
!= NULL
) {
1710 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeUnknown
) {
1714 Configuration
= AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1715 if (Configuration
== NULL
) {
1716 return EFI_OUT_OF_RESOURCES
;
1721 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
)
1724 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1726 if (NumConfig
== 1) {
1727 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1728 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1730 Ptr
->AddrRangeMin
= PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
1731 Ptr
->AddrLen
= PciIoDevice
->PciBar
[BarIndex
].Length
;
1732 Ptr
->AddrRangeMax
= PciIoDevice
->PciBar
[BarIndex
].Alignment
;
1734 switch (PciIoDevice
->PciBar
[BarIndex
].BarType
) {
1735 case PciBarTypeIo16
:
1736 case PciBarTypeIo32
:
1740 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_IO
;
1743 case PciBarTypeMem32
:
1747 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1751 Ptr
->AddrSpaceGranularity
= 32;
1754 case PciBarTypePMem32
:
1758 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1762 Ptr
->SpecificFlag
= 0x6;
1766 Ptr
->AddrSpaceGranularity
= 32;
1769 case PciBarTypeMem64
:
1773 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1777 Ptr
->AddrSpaceGranularity
= 64;
1780 case PciBarTypePMem64
:
1784 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1788 Ptr
->SpecificFlag
= 0x6;
1792 Ptr
->AddrSpaceGranularity
= 64;
1799 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) ((UINT8
*) Ptr
+ sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
));
1805 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) ((UINT8
*) Ptr
);
1806 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1807 PtrEnd
->Checksum
= 0;
1809 *Resources
= Configuration
;
1817 PciIoSetBarAttributes (
1818 IN EFI_PCI_IO_PROTOCOL
*This
,
1819 IN UINT64 Attributes
,
1821 IN OUT UINT64
*Offset
,
1822 IN OUT UINT64
*Length
1826 Routine Description:
1836 // TODO: This - add argument and description to function comment
1837 // TODO: Attributes - add argument and description to function comment
1838 // TODO: BarIndex - add argument and description to function comment
1839 // TODO: Offset - add argument and description to function comment
1840 // TODO: Length - add argument and description to function comment
1841 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1842 // TODO: EFI_UNSUPPORTED - add return value to function comment
1843 // TODO: EFI_UNSUPPORTED - add return value to function comment
1844 // TODO: EFI_UNSUPPORTED - add return value to function comment
1845 // TODO: EFI_SUCCESS - add return value to function comment
1848 PCI_IO_DEVICE
*PciIoDevice
;
1849 UINT64 NonRelativeOffset
;
1852 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1855 // Make sure Offset and Length are not NULL
1857 if (Offset
== NULL
|| Length
== NULL
) {
1858 return EFI_INVALID_PARAMETER
;
1861 if (PciIoDevice
->PciBar
[BarIndex
].BarType
== PciBarTypeUnknown
) {
1862 return EFI_UNSUPPORTED
;
1865 // This driver does not support setting the WRITE_COMBINE or the CACHED attributes.
1866 // If Attributes is not 0, then return EFI_UNSUPPORTED.
1868 Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1870 if (Attributes
!= (Attributes
& Supports
)) {
1871 return EFI_UNSUPPORTED
;
1874 // Attributes must be supported. Make sure the BAR range describd by BarIndex, Offset, and
1875 // Length are valid for this PCI device.
1877 NonRelativeOffset
= *Offset
;
1878 Status
= PciIoVerifyBarAccess (
1886 if (EFI_ERROR (Status
)) {
1887 return EFI_UNSUPPORTED
;
1894 UpStreamBridgesAttributes (
1895 IN PCI_IO_DEVICE
*PciIoDevice
,
1896 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1897 IN UINT64 Attributes
1901 Routine Description:
1910 // TODO: PciIoDevice - add argument and description to function comment
1911 // TODO: Operation - add argument and description to function comment
1912 // TODO: Attributes - add argument and description to function comment
1913 // TODO: EFI_SUCCESS - add return value to function comment
1915 PCI_IO_DEVICE
*Parent
;
1916 EFI_PCI_IO_PROTOCOL
*PciIo
;
1918 Parent
= PciIoDevice
->Parent
;
1920 while (Parent
&& IS_PCI_BRIDGE (&Parent
->Pci
)) {
1923 // Get the PciIo Protocol
1925 PciIo
= &Parent
->PciIo
;
1927 PciIo
->Attributes (PciIo
, Operation
, Attributes
, NULL
);
1929 Parent
= Parent
->Parent
;
1936 PciDevicesOnTheSamePath (
1937 IN PCI_IO_DEVICE
*PciDevice1
,
1938 IN PCI_IO_DEVICE
*PciDevice2
1942 Routine Description:
1951 // TODO: PciDevice1 - add argument and description to function comment
1952 // TODO: PciDevice2 - add argument and description to function comment
1955 if (PciDevice1
->Parent
== PciDevice2
->Parent
) {
1959 if (PciDevice1
->BusNumber
> PciDevice2
->BusNumber
) {
1960 return PciDeviceExisted (PciDevice1
->Parent
, PciDevice2
);
1963 return PciDeviceExisted (PciDevice2
->Parent
, PciDevice1
);