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
> EfiPciIoWidthUint64
) {
373 return EFI_INVALID_PARAMETER
;
376 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, 1, &Offset
);
377 if (EFI_ERROR (Status
)) {
378 return EFI_UNSUPPORTED
;
381 Status
= PciIoDevice
->PciRootBridgeIo
->PollIo (
382 PciIoDevice
->PciRootBridgeIo
,
383 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
391 if (EFI_ERROR (Status
)) {
392 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
401 IN EFI_PCI_IO_PROTOCOL
*This
,
402 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
412 Performs a PCI Memory Read Cycle
421 // TODO: This - add argument and description to function comment
422 // TODO: Width - add argument and description to function comment
423 // TODO: BarIndex - add argument and description to function comment
424 // TODO: Offset - add argument and description to function comment
425 // TODO: Count - add argument and description to function comment
426 // TODO: Buffer - add argument and description to function comment
427 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
428 // TODO: EFI_UNSUPPORTED - add return value to function comment
431 PCI_IO_DEVICE
*PciIoDevice
;
433 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
435 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
436 return EFI_INVALID_PARAMETER
;
439 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
440 if (EFI_ERROR (Status
)) {
441 return EFI_UNSUPPORTED
;
444 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Read (
445 PciIoDevice
->PciRootBridgeIo
,
446 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
452 if (EFI_ERROR (Status
)) {
453 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
462 IN EFI_PCI_IO_PROTOCOL
*This
,
463 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
473 Performs a PCI Memory Write Cycle
482 // TODO: This - add argument and description to function comment
483 // TODO: Width - add argument and description to function comment
484 // TODO: BarIndex - add argument and description to function comment
485 // TODO: Offset - add argument and description to function comment
486 // TODO: Count - add argument and description to function comment
487 // TODO: Buffer - add argument and description to function comment
488 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
489 // TODO: EFI_UNSUPPORTED - add return value to function comment
492 PCI_IO_DEVICE
*PciIoDevice
;
494 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
496 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
497 return EFI_INVALID_PARAMETER
;
500 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
501 if (EFI_ERROR (Status
)) {
502 return EFI_UNSUPPORTED
;
505 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Write (
506 PciIoDevice
->PciRootBridgeIo
,
507 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
513 if (EFI_ERROR (Status
)) {
514 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
523 IN EFI_PCI_IO_PROTOCOL
*This
,
524 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
534 Performs a PCI I/O Read Cycle
543 // TODO: This - add argument and description to function comment
544 // TODO: Width - add argument and description to function comment
545 // TODO: BarIndex - add argument and description to function comment
546 // TODO: Offset - add argument and description to function comment
547 // TODO: Count - add argument and description to function comment
548 // TODO: Buffer - add argument and description to function comment
549 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
550 // TODO: EFI_UNSUPPORTED - add return value to function comment
553 PCI_IO_DEVICE
*PciIoDevice
;
555 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
557 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
558 return EFI_INVALID_PARAMETER
;
561 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
562 if (EFI_ERROR (Status
)) {
563 return EFI_UNSUPPORTED
;
566 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Read (
567 PciIoDevice
->PciRootBridgeIo
,
568 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
574 if (EFI_ERROR (Status
)) {
575 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
584 IN EFI_PCI_IO_PROTOCOL
*This
,
585 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
595 Performs a PCI I/O Write Cycle
604 // TODO: This - add argument and description to function comment
605 // TODO: Width - add argument and description to function comment
606 // TODO: BarIndex - add argument and description to function comment
607 // TODO: Offset - add argument and description to function comment
608 // TODO: Count - add argument and description to function comment
609 // TODO: Buffer - add argument and description to function comment
610 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
611 // TODO: EFI_UNSUPPORTED - add return value to function comment
614 PCI_IO_DEVICE
*PciIoDevice
;
616 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
618 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
619 return EFI_INVALID_PARAMETER
;
622 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
623 if (EFI_ERROR (Status
)) {
624 return EFI_UNSUPPORTED
;
627 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Write (
628 PciIoDevice
->PciRootBridgeIo
,
629 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
635 if (EFI_ERROR (Status
)) {
636 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
645 IN EFI_PCI_IO_PROTOCOL
*This
,
646 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
655 Performs a PCI Configuration Read Cycle
664 // TODO: This - add argument and description to function comment
665 // TODO: Width - add argument and description to function comment
666 // TODO: Offset - add argument and description to function comment
667 // TODO: Count - add argument and description to function comment
668 // TODO: Buffer - add argument and description to function comment
671 PCI_IO_DEVICE
*PciIoDevice
;
674 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
677 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
678 if (EFI_ERROR (Status
)) {
682 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Read (
683 PciIoDevice
->PciRootBridgeIo
,
684 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
690 if (EFI_ERROR (Status
)) {
691 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
700 IN EFI_PCI_IO_PROTOCOL
*This
,
701 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
710 Performs a PCI Configuration Write Cycle
719 // TODO: This - add argument and description to function comment
720 // TODO: Width - add argument and description to function comment
721 // TODO: Offset - add argument and description to function comment
722 // TODO: Count - add argument and description to function comment
723 // TODO: Buffer - add argument and description to function comment
726 PCI_IO_DEVICE
*PciIoDevice
;
729 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
732 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
733 if (EFI_ERROR (Status
)) {
737 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Write (
738 PciIoDevice
->PciRootBridgeIo
,
739 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
745 if (EFI_ERROR (Status
)) {
746 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
755 IN EFI_PCI_IO_PROTOCOL
*This
,
756 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
757 IN UINT8 DestBarIndex
,
758 IN UINT64 DestOffset
,
759 IN UINT8 SrcBarIndex
,
776 // TODO: This - add argument and description to function comment
777 // TODO: Width - add argument and description to function comment
778 // TODO: DestBarIndex - add argument and description to function comment
779 // TODO: DestOffset - add argument and description to function comment
780 // TODO: SrcBarIndex - add argument and description to function comment
781 // TODO: SrcOffset - add argument and description to function comment
782 // TODO: Count - add argument and description to function comment
783 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
784 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
785 // TODO: EFI_UNSUPPORTED - add return value to function comment
786 // TODO: EFI_UNSUPPORTED - add return value to function comment
789 PCI_IO_DEVICE
*PciIoDevice
;
791 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
793 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
794 return EFI_INVALID_PARAMETER
;
797 if (Width
== EfiPciIoWidthFifoUint8
||
798 Width
== EfiPciIoWidthFifoUint16
||
799 Width
== EfiPciIoWidthFifoUint32
||
800 Width
== EfiPciIoWidthFifoUint64
||
801 Width
== EfiPciIoWidthFillUint8
||
802 Width
== EfiPciIoWidthFillUint16
||
803 Width
== EfiPciIoWidthFillUint32
||
804 Width
== EfiPciIoWidthFillUint64
) {
805 return EFI_INVALID_PARAMETER
;
808 Status
= PciIoVerifyBarAccess (PciIoDevice
, DestBarIndex
, PciBarTypeMem
, Width
, Count
, &DestOffset
);
809 if (EFI_ERROR (Status
)) {
810 return EFI_UNSUPPORTED
;
813 Status
= PciIoVerifyBarAccess (PciIoDevice
, SrcBarIndex
, PciBarTypeMem
, Width
, Count
, &SrcOffset
);
814 if (EFI_ERROR (Status
)) {
815 return EFI_UNSUPPORTED
;
818 Status
= PciIoDevice
->PciRootBridgeIo
->CopyMem (
819 PciIoDevice
->PciRootBridgeIo
,
820 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
826 if (EFI_ERROR (Status
)) {
827 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
836 IN EFI_PCI_IO_PROTOCOL
*This
,
837 IN EFI_PCI_IO_PROTOCOL_OPERATION Operation
,
838 IN VOID
*HostAddress
,
839 IN OUT UINTN
*NumberOfBytes
,
840 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
847 Maps a memory region for DMA
856 // TODO: This - add argument and description to function comment
857 // TODO: Operation - add argument and description to function comment
858 // TODO: HostAddress - add argument and description to function comment
859 // TODO: NumberOfBytes - add argument and description to function comment
860 // TODO: DeviceAddress - add argument and description to function comment
861 // TODO: Mapping - add argument and description to function comment
862 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
863 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
866 PCI_IO_DEVICE
*PciIoDevice
;
868 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
870 if (Operation
< 0 || Operation
>= EfiPciIoOperationMaximum
) {
871 return EFI_INVALID_PARAMETER
;
874 if (HostAddress
== NULL
|| NumberOfBytes
== NULL
|| DeviceAddress
== NULL
|| Mapping
== NULL
) {
875 return EFI_INVALID_PARAMETER
;
878 if (PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) {
879 Operation
= Operation
+ EfiPciOperationBusMasterRead64
;
882 Status
= PciIoDevice
->PciRootBridgeIo
->Map (
883 PciIoDevice
->PciRootBridgeIo
,
884 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION
) Operation
,
891 if (EFI_ERROR (Status
)) {
892 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
901 IN EFI_PCI_IO_PROTOCOL
*This
,
908 Unmaps a memory region for DMA
917 // TODO: This - add argument and description to function comment
918 // TODO: Mapping - add argument and description to function comment
921 PCI_IO_DEVICE
*PciIoDevice
;
923 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
925 Status
= PciIoDevice
->PciRootBridgeIo
->Unmap (
926 PciIoDevice
->PciRootBridgeIo
,
930 if (EFI_ERROR (Status
)) {
931 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
939 PciIoAllocateBuffer (
940 IN EFI_PCI_IO_PROTOCOL
*This
,
941 IN EFI_ALLOCATE_TYPE Type
,
942 IN EFI_MEMORY_TYPE MemoryType
,
944 OUT VOID
**HostAddress
,
951 Allocates a common buffer for DMA
960 // TODO: This - add argument and description to function comment
961 // TODO: Type - add argument and description to function comment
962 // TODO: MemoryType - add argument and description to function comment
963 // TODO: Pages - add argument and description to function comment
964 // TODO: HostAddress - add argument and description to function comment
965 // TODO: Attributes - add argument and description to function comment
966 // TODO: EFI_UNSUPPORTED - add return value to function comment
969 PCI_IO_DEVICE
*PciIoDevice
;
972 (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE
| EFI_PCI_ATTRIBUTE_MEMORY_CACHED
))) {
973 return EFI_UNSUPPORTED
;
976 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
978 if (PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) {
979 Attributes
|= EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
982 Status
= PciIoDevice
->PciRootBridgeIo
->AllocateBuffer (
983 PciIoDevice
->PciRootBridgeIo
,
991 if (EFI_ERROR (Status
)) {
992 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1001 IN EFI_PCI_IO_PROTOCOL
*This
,
1003 IN VOID
*HostAddress
1007 Routine Description:
1009 Frees a common buffer
1018 // TODO: This - add argument and description to function comment
1019 // TODO: Pages - add argument and description to function comment
1020 // TODO: HostAddress - add argument and description to function comment
1023 PCI_IO_DEVICE
*PciIoDevice
;
1025 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1027 Status
= PciIoDevice
->PciRootBridgeIo
->FreeBuffer (
1028 PciIoDevice
->PciRootBridgeIo
,
1033 if (EFI_ERROR (Status
)) {
1034 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1043 IN EFI_PCI_IO_PROTOCOL
*This
1047 Routine Description:
1049 Flushes a DMA buffer
1058 // TODO: This - add argument and description to function comment
1061 PCI_IO_DEVICE
*PciIoDevice
;
1063 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1065 Status
= PciIoDevice
->PciRootBridgeIo
->Flush (
1066 PciIoDevice
->PciRootBridgeIo
1068 if (EFI_ERROR (Status
)) {
1069 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1078 IN EFI_PCI_IO_PROTOCOL
*This
,
1086 Routine Description:
1088 Gets a PCI device's current bus number, device number, and function number.
1097 // TODO: This - add argument and description to function comment
1098 // TODO: Segment - add argument and description to function comment
1099 // TODO: Bus - add argument and description to function comment
1100 // TODO: Device - add argument and description to function comment
1101 // TODO: Function - add argument and description to function comment
1102 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1103 // TODO: EFI_SUCCESS - add return value to function comment
1105 PCI_IO_DEVICE
*PciIoDevice
;
1107 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1109 if (Segment
== NULL
|| Bus
== NULL
|| Device
== NULL
|| Function
== NULL
) {
1110 return EFI_INVALID_PARAMETER
;
1113 *Segment
= PciIoDevice
->PciRootBridgeIo
->SegmentNumber
;
1114 *Bus
= PciIoDevice
->BusNumber
;
1115 *Device
= PciIoDevice
->DeviceNumber
;
1116 *Function
= PciIoDevice
->FunctionNumber
;
1123 IN PCI_IO_DEVICE
*PciIoDevice
,
1125 PCI_BAR_TYPE BarType
1129 Routine Description:
1131 Sets a PCI controllers attributes on a resource range
1140 // TODO: PciIoDevice - add argument and description to function comment
1141 // TODO: BarIndex - add argument and description to function comment
1142 // TODO: BarType - add argument and description to function comment
1148 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem32
&&
1149 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem32
&&
1150 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem64
&&
1151 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem64
) {
1158 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo32
&&
1159 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo16
){
1173 ModifyRootBridgeAttributes (
1174 IN PCI_IO_DEVICE
*PciIoDevice
,
1175 IN UINT64 Attributes
,
1176 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1180 Routine Description:
1182 Set new attributes to a Root Bridge
1191 // TODO: PciIoDevice - add argument and description to function comment
1192 // TODO: Attributes - add argument and description to function comment
1193 // TODO: Operation - add argument and description to function comment
1194 // TODO: EFI_UNSUPPORTED - add return value to function comment
1195 // TODO: EFI_UNSUPPORTED - add return value to function comment
1196 // TODO: EFI_SUCCESS - add return value to function comment
1198 UINT64 PciRootBridgeSupports
;
1199 UINT64 PciRootBridgeAttributes
;
1200 UINT64 NewPciRootBridgeAttributes
;
1204 // Get the current attributes of this PCI device's PCI Root Bridge
1206 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1207 PciIoDevice
->PciRootBridgeIo
,
1208 &PciRootBridgeSupports
,
1209 &PciRootBridgeAttributes
1211 if (EFI_ERROR (Status
)) {
1212 return EFI_UNSUPPORTED
;
1216 // Record the new attribute of the Root Bridge
1218 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1219 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
| Attributes
;
1221 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
& (~Attributes
);
1225 // Call the PCI Root Bridge to attempt to modify the attributes
1227 if (NewPciRootBridgeAttributes
^ PciRootBridgeAttributes
) {
1229 Status
= PciIoDevice
->PciRootBridgeIo
->SetAttributes (
1230 PciIoDevice
->PciRootBridgeIo
,
1231 NewPciRootBridgeAttributes
,
1235 if (EFI_ERROR (Status
)) {
1237 // The PCI Root Bridge could not modify the attributes, so return the error.
1239 return EFI_UNSUPPORTED
;
1244 // Also update the attributes for this Root Bridge structure
1246 PciIoDevice
->Attributes
= NewPciRootBridgeAttributes
;
1252 SupportPaletteSnoopAttributes (
1253 IN PCI_IO_DEVICE
*PciIoDevice
,
1254 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1258 Routine Description:
1260 Check whether this device can be enable/disable to snoop
1269 // TODO: PciIoDevice - add argument and description to function comment
1270 // TODO: Operation - add argument and description to function comment
1271 // TODO: EFI_UNSUPPORTED - add return value to function comment
1272 // TODO: EFI_SUCCESS - add return value to function comment
1273 // TODO: EFI_SUCCESS - add return value to function comment
1274 // TODO: EFI_UNSUPPORTED - add return value 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_UNSUPPORTED - add return value to function comment
1278 // TODO: EFI_UNSUPPORTED - add return value to function comment
1279 // TODO: EFI_SUCCESS - add return value to function comment
1281 PCI_IO_DEVICE
*Temp
;
1285 // Snoop attribute can be only modified by GFX
1287 if (!IS_PCI_GFX (&PciIoDevice
->Pci
)) {
1288 return EFI_UNSUPPORTED
;
1292 // Get the boot VGA on the same segement
1294 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1298 // If there is no VGA device on the segement, set
1299 // this graphics card to decode the palette range
1305 // Check these two agents are on the same path
1307 if (!PciDevicesOnTheSamePath (Temp
, PciIoDevice
)) {
1309 // they are not on the same path, so snoop can be enabled or disabled
1314 // Check if they are on the same bus
1316 if (Temp
->Parent
== PciIoDevice
->Parent
) {
1318 PciReadCommandRegister (Temp
, &VGACommand
);
1321 // If they are on the same bus, either one can
1322 // be set to snoop, the other set to decode
1324 if (VGACommand
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) {
1326 // VGA has set to snoop, so GFX can be only set to disable snoop
1328 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1329 return EFI_UNSUPPORTED
;
1333 // VGA has disabled to snoop, so GFX can be only enabled
1335 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1336 return EFI_UNSUPPORTED
;
1344 // If they are on the same path but on the different bus
1345 // The first agent is set to snoop, the second one set to
1349 if (Temp
->BusNumber
> PciIoDevice
->BusNumber
) {
1351 // GFX should be set to decode
1353 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1354 PciEnableCommandRegister (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1355 Temp
->Attributes
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1357 return EFI_UNSUPPORTED
;
1362 // GFX should be set to snoop
1364 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1365 PciDisableCommandRegister (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1366 Temp
->Attributes
&= (~EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1368 return EFI_UNSUPPORTED
;
1379 IN EFI_PCI_IO_PROTOCOL
* This
,
1380 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1381 IN UINT64 Attributes
,
1382 OUT UINT64
*Result OPTIONAL
1386 Routine Description:
1396 // TODO: This - add argument and description to function comment
1397 // TODO: Operation - add argument and description to function comment
1398 // TODO: Attributes - add argument and description to function comment
1399 // TODO: Result - add argument and description to function comment
1400 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1401 // TODO: EFI_SUCCESS - add return value to function comment
1402 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1403 // TODO: EFI_SUCCESS - add return value to function comment
1404 // TODO: EFI_UNSUPPORTED - add return value to function comment
1405 // TODO: EFI_UNSUPPORTED - add return value to function comment
1406 // TODO: EFI_SUCCESS - add return value to function comment
1407 // TODO: EFI_INVALID_PARAMETER - 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_UNSUPPORTED - add return value to function comment
1414 PCI_IO_DEVICE
*PciIoDevice
;
1415 PCI_IO_DEVICE
*UpStreamBridge
;
1416 PCI_IO_DEVICE
*Temp
;
1419 UINT64 UpStreamAttributes
;
1420 UINT16 BridgeControl
;
1423 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1425 switch (Operation
) {
1426 case EfiPciIoAttributeOperationGet
:
1427 if (Result
== NULL
) {
1428 return EFI_INVALID_PARAMETER
;
1431 *Result
= PciIoDevice
->Attributes
;
1434 case EfiPciIoAttributeOperationSupported
:
1435 if (Result
== NULL
) {
1436 return EFI_INVALID_PARAMETER
;
1439 *Result
= PciIoDevice
->Supports
;
1442 case EfiPciIoAttributeOperationSet
:
1443 Status
= PciIoDevice
->PciIo
.Attributes (
1444 &(PciIoDevice
->PciIo
),
1445 EfiPciIoAttributeOperationEnable
,
1449 if (EFI_ERROR (Status
)) {
1450 return EFI_UNSUPPORTED
;
1453 Status
= PciIoDevice
->PciIo
.Attributes (
1454 &(PciIoDevice
->PciIo
),
1455 EfiPciIoAttributeOperationDisable
,
1456 (~Attributes
) & (PciIoDevice
->Supports
),
1459 if (EFI_ERROR (Status
)) {
1460 return EFI_UNSUPPORTED
;
1465 case EfiPciIoAttributeOperationEnable
:
1466 case EfiPciIoAttributeOperationDisable
:
1470 return EFI_INVALID_PARAMETER
;
1473 // Just a trick for ENABLE attribute
1475 if ((Attributes
& EFI_PCI_DEVICE_ENABLE
) == EFI_PCI_DEVICE_ENABLE
) {
1476 Attributes
&= (PciIoDevice
->Supports
);
1479 // Raise the EFI_P_PC_ENABLE Status code
1481 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
1483 EFI_IO_BUS_PCI
| EFI_P_PC_ENABLE
,
1484 PciIoDevice
->DevicePath
1489 // If no attributes can be supported, then return.
1490 // Otherwise, set the attributes that it can support.
1492 Supports
= (PciIoDevice
->Supports
) & Attributes
;
1493 if (Supports
!= Attributes
) {
1494 return EFI_UNSUPPORTED
;
1498 // For Root Bridge, just call RootBridgeIo to set attributes;
1500 if (!PciIoDevice
->Parent
) {
1501 Status
= ModifyRootBridgeAttributes (PciIoDevice
, Attributes
, Operation
);
1509 // Check VGA and VGA16, they can not be set at the same time
1511 if (((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) &&
1512 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) ||
1513 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) &&
1514 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) ||
1515 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) &&
1516 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) ||
1517 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) &&
1518 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) ) {
1519 return EFI_UNSUPPORTED
;
1523 // For PPB & P2C, set relevant attribute bits
1525 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1527 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) {
1528 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA
;
1531 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_ISA_IO
) {
1532 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_ISA
;
1535 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) {
1536 Command
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
1539 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) {
1540 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1545 // Do with the attributes on VGA
1546 // Only for VGA's legacy resource, we just can enable once.
1549 (EFI_PCI_IO_ATTRIBUTE_VGA_IO
|
1550 EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
|
1551 EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
)) {
1553 // Check if a VGA has been enabled before enabling a new one
1555 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1557 // Check if there have been an active VGA device on the same segment
1559 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1560 if (Temp
&& Temp
!= PciIoDevice
) {
1562 // An active VGA has been detected, so can not enable another
1564 return EFI_UNSUPPORTED
;
1570 // Do with the attributes on GFX
1572 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) {
1574 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1576 // Check if snoop can be enabled in current configuration
1578 Status
= SupportPaletteSnoopAttributes (PciIoDevice
, Operation
);
1580 if (EFI_ERROR (Status
)) {
1583 // Enable operation is forbidden, so mask the bit in attributes
1584 // so as to keep consistent with the actual Status
1586 // Attributes &= (~EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO);
1590 return EFI_UNSUPPORTED
;
1596 // It can be supported, so get ready to set the bit
1598 Command
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1602 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) {
1603 Command
|= EFI_PCI_COMMAND_IO_SPACE
;
1606 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_MEMORY
) {
1607 Command
|= EFI_PCI_COMMAND_MEMORY_SPACE
;
1610 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
) {
1611 Command
|= EFI_PCI_COMMAND_BUS_MASTER
;
1614 // The upstream bridge should be also set to revelant attribute
1615 // expect for IO, Mem and BusMaster
1617 UpStreamAttributes
= Attributes
&
1618 (~(EFI_PCI_IO_ATTRIBUTE_IO
|
1619 EFI_PCI_IO_ATTRIBUTE_MEMORY
|
1620 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
1623 UpStreamBridge
= PciIoDevice
->Parent
;
1625 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1627 // Enable relevant attributes to command register and bridge control register
1629 Status
= PciEnableCommandRegister (PciIoDevice
, Command
);
1630 if (BridgeControl
) {
1631 Status
= PciEnableBridgeControlRegister (PciIoDevice
, BridgeControl
);
1634 PciIoDevice
->Attributes
|= Attributes
;
1637 // Enable attributes of the upstream bridge
1639 Status
= UpStreamBridge
->PciIo
.Attributes (
1640 &(UpStreamBridge
->PciIo
),
1641 EfiPciIoAttributeOperationEnable
,
1648 // Disable relevant attributes to command register and bridge control register
1650 Status
= PciDisableCommandRegister (PciIoDevice
, Command
);
1651 if (BridgeControl
) {
1652 Status
= PciDisableBridgeControlRegister (PciIoDevice
, BridgeControl
);
1655 PciIoDevice
->Attributes
&= (~Attributes
);
1656 Status
= EFI_SUCCESS
;
1660 if (EFI_ERROR (Status
)) {
1661 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1669 PciIoGetBarAttributes (
1670 IN EFI_PCI_IO_PROTOCOL
* This
,
1672 OUT UINT64
*Supports
, OPTIONAL
1673 OUT VOID
**Resources OPTIONAL
1677 Routine Description:
1687 // TODO: This - add argument and description to function comment
1688 // TODO: BarIndex - add argument and description to function comment
1689 // TODO: Supports - add argument and description to function comment
1690 // TODO: Resources - add argument and description to function comment
1691 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1692 // TODO: EFI_UNSUPPORTED - add return value to function comment
1693 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
1694 // TODO: EFI_SUCCESS - add return value to function comment
1697 UINT8
*Configuration
;
1699 PCI_IO_DEVICE
*PciIoDevice
;
1700 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1701 EFI_ACPI_END_TAG_DESCRIPTOR
*PtrEnd
;
1705 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1707 if (Supports
== NULL
&& Resources
== NULL
) {
1708 return EFI_INVALID_PARAMETER
;
1711 if (BarIndex
>= PCI_MAX_BAR
) {
1712 return EFI_UNSUPPORTED
;
1716 // This driver does not support modifications to the WRITE_COMBINE or
1717 // CACHED attributes for BAR ranges.
1719 if (Supports
!= NULL
) {
1720 *Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1723 if (Resources
!= NULL
) {
1725 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeUnknown
) {
1729 Configuration
= AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1730 if (Configuration
== NULL
) {
1731 return EFI_OUT_OF_RESOURCES
;
1736 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
)
1739 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1741 if (NumConfig
== 1) {
1742 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1743 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1745 Ptr
->AddrRangeMin
= PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
1746 Ptr
->AddrLen
= PciIoDevice
->PciBar
[BarIndex
].Length
;
1747 Ptr
->AddrRangeMax
= PciIoDevice
->PciBar
[BarIndex
].Alignment
;
1749 switch (PciIoDevice
->PciBar
[BarIndex
].BarType
) {
1750 case PciBarTypeIo16
:
1751 case PciBarTypeIo32
:
1755 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_IO
;
1758 case PciBarTypeMem32
:
1762 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1766 Ptr
->AddrSpaceGranularity
= 32;
1769 case PciBarTypePMem32
:
1773 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1777 Ptr
->SpecificFlag
= 0x6;
1781 Ptr
->AddrSpaceGranularity
= 32;
1784 case PciBarTypeMem64
:
1788 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1792 Ptr
->AddrSpaceGranularity
= 64;
1795 case PciBarTypePMem64
:
1799 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1803 Ptr
->SpecificFlag
= 0x6;
1807 Ptr
->AddrSpaceGranularity
= 64;
1814 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) ((UINT8
*) Ptr
+ sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
));
1820 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) ((UINT8
*) Ptr
);
1821 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1822 PtrEnd
->Checksum
= 0;
1824 *Resources
= Configuration
;
1832 PciIoSetBarAttributes (
1833 IN EFI_PCI_IO_PROTOCOL
*This
,
1834 IN UINT64 Attributes
,
1836 IN OUT UINT64
*Offset
,
1837 IN OUT UINT64
*Length
1841 Routine Description:
1851 // TODO: This - add argument and description to function comment
1852 // TODO: Attributes - add argument and description to function comment
1853 // TODO: BarIndex - add argument and description to function comment
1854 // TODO: Offset - add argument and description to function comment
1855 // TODO: Length - add argument and description to function comment
1856 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1857 // TODO: EFI_UNSUPPORTED - add return value to function comment
1858 // TODO: EFI_UNSUPPORTED - add return value to function comment
1859 // TODO: EFI_UNSUPPORTED - add return value to function comment
1860 // TODO: EFI_SUCCESS - add return value to function comment
1863 PCI_IO_DEVICE
*PciIoDevice
;
1864 UINT64 NonRelativeOffset
;
1867 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1870 // Make sure Offset and Length are not NULL
1872 if (Offset
== NULL
|| Length
== NULL
) {
1873 return EFI_INVALID_PARAMETER
;
1876 if (PciIoDevice
->PciBar
[BarIndex
].BarType
== PciBarTypeUnknown
) {
1877 return EFI_UNSUPPORTED
;
1880 // This driver does not support setting the WRITE_COMBINE or the CACHED attributes.
1881 // If Attributes is not 0, then return EFI_UNSUPPORTED.
1883 Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1885 if (Attributes
!= (Attributes
& Supports
)) {
1886 return EFI_UNSUPPORTED
;
1889 // Attributes must be supported. Make sure the BAR range describd by BarIndex, Offset, and
1890 // Length are valid for this PCI device.
1892 NonRelativeOffset
= *Offset
;
1893 Status
= PciIoVerifyBarAccess (
1901 if (EFI_ERROR (Status
)) {
1902 return EFI_UNSUPPORTED
;
1909 UpStreamBridgesAttributes (
1910 IN PCI_IO_DEVICE
*PciIoDevice
,
1911 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1912 IN UINT64 Attributes
1916 Routine Description:
1925 // TODO: PciIoDevice - add argument and description to function comment
1926 // TODO: Operation - add argument and description to function comment
1927 // TODO: Attributes - add argument and description to function comment
1928 // TODO: EFI_SUCCESS - add return value to function comment
1930 PCI_IO_DEVICE
*Parent
;
1931 EFI_PCI_IO_PROTOCOL
*PciIo
;
1933 Parent
= PciIoDevice
->Parent
;
1935 while (Parent
&& IS_PCI_BRIDGE (&Parent
->Pci
)) {
1938 // Get the PciIo Protocol
1940 PciIo
= &Parent
->PciIo
;
1942 PciIo
->Attributes (PciIo
, Operation
, Attributes
, NULL
);
1944 Parent
= Parent
->Parent
;
1951 PciDevicesOnTheSamePath (
1952 IN PCI_IO_DEVICE
*PciDevice1
,
1953 IN PCI_IO_DEVICE
*PciDevice2
1957 Routine Description:
1966 // TODO: PciDevice1 - add argument and description to function comment
1967 // TODO: PciDevice2 - add argument and description to function comment
1970 if (PciDevice1
->Parent
== PciDevice2
->Parent
) {
1974 if (PciDevice1
->BusNumber
> PciDevice2
->BusNumber
) {
1975 return PciDeviceExisted (PciDevice1
->Parent
, PciDevice2
);
1978 return PciDeviceExisted (PciDevice2
->Parent
, PciDevice1
);