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.
22 ReportErrorStatusCode (
23 IN PCI_IO_DEVICE
*PciIoDevice
,
24 IN EFI_STATUS_CODE_VALUE Code
28 // PCI I/O Support Function Prototypes
32 // Pci Io Protocol Interface
34 static EFI_PCI_IO_PROTOCOL PciIoInterface
= {
57 PciIoGetBarAttributes
,
58 PciIoSetBarAttributes
,
65 ReportErrorStatusCode (
66 IN PCI_IO_DEVICE
*PciIoDevice
,
67 IN EFI_STATUS_CODE_VALUE Code
73 report a error Status code of PCI bus driver controller
82 // TODO: PciIoDevice - add argument and description to function comment
83 // TODO: Code - add argument and description to function comment
85 return REPORT_STATUS_CODE_WITH_DEVICE_PATH (
86 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
88 PciIoDevice
->DevicePath
93 InitializePciIoInstance (
94 PCI_IO_DEVICE
*PciIoDevice
100 Initializes a PCI I/O Instance
109 // TODO: PciIoDevice - add argument and description to function comment
110 // TODO: EFI_SUCCESS - add return value to function comment
112 CopyMem (&PciIoDevice
->PciIo
, &PciIoInterface
, sizeof (EFI_PCI_IO_PROTOCOL
));
117 PciIoVerifyBarAccess (
118 PCI_IO_DEVICE
*PciIoDevice
,
121 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
129 Verifies access to a PCI Base Address Register (BAR)
138 // TODO: PciIoDevice - add argument and description to function comment
139 // TODO: BarIndex - add argument and description to function comment
140 // TODO: Type - add argument and description to function comment
141 // TODO: Width - add argument and description to function comment
142 // TODO: Count - add argument and description to function comment
143 // TODO: Offset - add argument and description to function comment
144 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
145 // TODO: EFI_SUCCESS - add return value to function comment
146 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
147 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
148 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
149 // TODO: EFI_SUCCESS - add return value to function comment
151 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
152 return EFI_INVALID_PARAMETER
;
155 if (BarIndex
== EFI_PCI_IO_PASS_THROUGH_BAR
) {
160 // BarIndex 0-5 is legal
162 if (BarIndex
>= PCI_MAX_BAR
) {
163 return EFI_INVALID_PARAMETER
;
166 if (!CheckBarType (PciIoDevice
, BarIndex
, Type
)) {
167 return EFI_INVALID_PARAMETER
;
171 // If Width is EfiPciIoWidthFifoUintX then convert to EfiPciIoWidthUintX
172 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
174 if (Width
>= EfiPciWidthFifoUint8
&& Width
<= EfiPciWidthFifoUint64
) {
178 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
180 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PciIoDevice
->PciBar
[BarIndex
].Length
) {
181 return EFI_INVALID_PARAMETER
;
184 *Offset
= *Offset
+ PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
190 PciIoVerifyConfigAccess (
191 PCI_IO_DEVICE
*PciIoDevice
,
192 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
200 Verifies access to a PCI Config Header
209 // TODO: PciIoDevice - add argument and description to function comment
210 // TODO: Width - add argument and description to function comment
211 // TODO: Count - add argument and description to function comment
212 // TODO: Offset - add argument and description to function comment
213 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
214 // TODO: EFI_UNSUPPORTED - add return value to function comment
215 // TODO: EFI_UNSUPPORTED - add return value to function comment
216 // TODO: EFI_SUCCESS - add return value to function comment
220 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
221 return EFI_INVALID_PARAMETER
;
225 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
227 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
229 if (PciIoDevice
->IsPciExp
) {
230 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_EXP_MAX_CONFIG_OFFSET
) {
231 return EFI_UNSUPPORTED
;
234 ExtendOffset
= LShiftU64 (*Offset
, 32);
235 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
236 *Offset
= (*Offset
) | ExtendOffset
;
239 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_MAX_CONFIG_OFFSET
) {
240 return EFI_UNSUPPORTED
;
243 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, *Offset
);
252 IN EFI_PCI_IO_PROTOCOL
*This
,
253 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
274 // TODO: This - add argument and description to function comment
275 // TODO: Width - add argument and description to function comment
276 // TODO: BarIndex - add argument and description to function comment
277 // TODO: Offset - add argument and description to function comment
278 // TODO: Mask - add argument and description to function comment
279 // TODO: Value - add argument and description to function comment
280 // TODO: Delay - add argument and description to function comment
281 // TODO: Result - add argument and description to function comment
282 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
283 // TODO: EFI_UNSUPPORTED - add return value to function comment
284 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
287 PCI_IO_DEVICE
*PciIoDevice
;
289 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
291 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
292 return EFI_INVALID_PARAMETER
;
295 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, 1, &Offset
);
296 if (EFI_ERROR (Status
)) {
297 return EFI_UNSUPPORTED
;
300 if (Width
> EfiPciIoWidthUint64
) {
301 return EFI_INVALID_PARAMETER
;
304 Status
= PciIoDevice
->PciRootBridgeIo
->PollMem (
305 PciIoDevice
->PciRootBridgeIo
,
306 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
314 if (EFI_ERROR (Status
)) {
315 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
324 IN EFI_PCI_IO_PROTOCOL
*This
,
325 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
346 // TODO: This - add argument and description to function comment
347 // TODO: Width - add argument and description to function comment
348 // TODO: BarIndex - add argument and description to function comment
349 // TODO: Offset - add argument and description to function comment
350 // TODO: Mask - add argument and description to function comment
351 // TODO: Value - add argument and description to function comment
352 // TODO: Delay - add argument and description to function comment
353 // TODO: Result - add argument and description to function comment
354 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
355 // TODO: EFI_UNSUPPORTED - add return value to function comment
356 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
359 PCI_IO_DEVICE
*PciIoDevice
;
361 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
363 if (Width
< 0 || Width
> EfiPciIoWidthUint64
) {
364 return EFI_INVALID_PARAMETER
;
367 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, 1, &Offset
);
368 if (EFI_ERROR (Status
)) {
369 return EFI_UNSUPPORTED
;
372 Status
= PciIoDevice
->PciRootBridgeIo
->PollIo (
373 PciIoDevice
->PciRootBridgeIo
,
374 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
382 if (EFI_ERROR (Status
)) {
383 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
392 IN EFI_PCI_IO_PROTOCOL
*This
,
393 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
403 Performs a PCI Memory Read Cycle
412 // TODO: This - add argument and description to function comment
413 // TODO: Width - add argument and description to function comment
414 // TODO: BarIndex - add argument and description to function comment
415 // TODO: Offset - add argument and description to function comment
416 // TODO: Count - add argument and description to function comment
417 // TODO: Buffer - add argument and description to function comment
418 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
419 // TODO: EFI_UNSUPPORTED - add return value to function comment
422 PCI_IO_DEVICE
*PciIoDevice
;
424 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
426 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
427 return EFI_INVALID_PARAMETER
;
430 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
431 if (EFI_ERROR (Status
)) {
432 return EFI_UNSUPPORTED
;
435 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Read (
436 PciIoDevice
->PciRootBridgeIo
,
437 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
443 if (EFI_ERROR (Status
)) {
444 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
453 IN EFI_PCI_IO_PROTOCOL
*This
,
454 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
464 Performs a PCI Memory Write Cycle
473 // TODO: This - add argument and description to function comment
474 // TODO: Width - add argument and description to function comment
475 // TODO: BarIndex - add argument and description to function comment
476 // TODO: Offset - add argument and description to function comment
477 // TODO: Count - add argument and description to function comment
478 // TODO: Buffer - add argument and description to function comment
479 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
480 // TODO: EFI_UNSUPPORTED - add return value to function comment
483 PCI_IO_DEVICE
*PciIoDevice
;
485 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
487 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
488 return EFI_INVALID_PARAMETER
;
491 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
492 if (EFI_ERROR (Status
)) {
493 return EFI_UNSUPPORTED
;
496 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Write (
497 PciIoDevice
->PciRootBridgeIo
,
498 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
504 if (EFI_ERROR (Status
)) {
505 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
514 IN EFI_PCI_IO_PROTOCOL
*This
,
515 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
525 Performs a PCI I/O Read Cycle
534 // TODO: This - add argument and description to function comment
535 // TODO: Width - add argument and description to function comment
536 // TODO: BarIndex - add argument and description to function comment
537 // TODO: Offset - add argument and description to function comment
538 // TODO: Count - add argument and description to function comment
539 // TODO: Buffer - add argument and description to function comment
540 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
541 // TODO: EFI_UNSUPPORTED - add return value to function comment
544 PCI_IO_DEVICE
*PciIoDevice
;
546 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
548 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
549 return EFI_INVALID_PARAMETER
;
552 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
553 if (EFI_ERROR (Status
)) {
554 return EFI_UNSUPPORTED
;
557 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Read (
558 PciIoDevice
->PciRootBridgeIo
,
559 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
565 if (EFI_ERROR (Status
)) {
566 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
575 IN EFI_PCI_IO_PROTOCOL
*This
,
576 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
586 Performs a PCI I/O Write Cycle
595 // TODO: This - add argument and description to function comment
596 // TODO: Width - add argument and description to function comment
597 // TODO: BarIndex - add argument and description to function comment
598 // TODO: Offset - add argument and description to function comment
599 // TODO: Count - add argument and description to function comment
600 // TODO: Buffer - add argument and description to function comment
601 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
602 // TODO: EFI_UNSUPPORTED - add return value to function comment
605 PCI_IO_DEVICE
*PciIoDevice
;
607 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
609 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
610 return EFI_INVALID_PARAMETER
;
613 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
614 if (EFI_ERROR (Status
)) {
615 return EFI_UNSUPPORTED
;
618 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Write (
619 PciIoDevice
->PciRootBridgeIo
,
620 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
626 if (EFI_ERROR (Status
)) {
627 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
636 IN EFI_PCI_IO_PROTOCOL
*This
,
637 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
646 Performs a PCI Configuration Read Cycle
655 // TODO: This - add argument and description to function comment
656 // TODO: Width - add argument and description to function comment
657 // TODO: Offset - add argument and description to function comment
658 // TODO: Count - add argument and description to function comment
659 // TODO: Buffer - add argument and description to function comment
662 PCI_IO_DEVICE
*PciIoDevice
;
665 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
668 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
669 if (EFI_ERROR (Status
)) {
673 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Read (
674 PciIoDevice
->PciRootBridgeIo
,
675 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
681 if (EFI_ERROR (Status
)) {
682 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
691 IN EFI_PCI_IO_PROTOCOL
*This
,
692 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
701 Performs a PCI Configuration Write Cycle
710 // TODO: This - add argument and description to function comment
711 // TODO: Width - add argument and description to function comment
712 // TODO: Offset - add argument and description to function comment
713 // TODO: Count - add argument and description to function comment
714 // TODO: Buffer - add argument and description to function comment
717 PCI_IO_DEVICE
*PciIoDevice
;
720 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
723 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
724 if (EFI_ERROR (Status
)) {
728 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Write (
729 PciIoDevice
->PciRootBridgeIo
,
730 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
736 if (EFI_ERROR (Status
)) {
737 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
746 IN EFI_PCI_IO_PROTOCOL
*This
,
747 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
748 IN UINT8 DestBarIndex
,
749 IN UINT64 DestOffset
,
750 IN UINT8 SrcBarIndex
,
767 // TODO: This - add argument and description to function comment
768 // TODO: Width - add argument and description to function comment
769 // TODO: DestBarIndex - add argument and description to function comment
770 // TODO: DestOffset - add argument and description to function comment
771 // TODO: SrcBarIndex - add argument and description to function comment
772 // TODO: SrcOffset - add argument and description to function comment
773 // TODO: Count - add argument and description to function comment
774 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
775 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
776 // TODO: EFI_UNSUPPORTED - add return value to function comment
777 // TODO: EFI_UNSUPPORTED - add return value to function comment
780 PCI_IO_DEVICE
*PciIoDevice
;
782 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
784 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
785 return EFI_INVALID_PARAMETER
;
788 if (Width
== EfiPciIoWidthFifoUint8
||
789 Width
== EfiPciIoWidthFifoUint16
||
790 Width
== EfiPciIoWidthFifoUint32
||
791 Width
== EfiPciIoWidthFifoUint64
||
792 Width
== EfiPciIoWidthFillUint8
||
793 Width
== EfiPciIoWidthFillUint16
||
794 Width
== EfiPciIoWidthFillUint32
||
795 Width
== EfiPciIoWidthFillUint64
) {
796 return EFI_INVALID_PARAMETER
;
799 Status
= PciIoVerifyBarAccess (PciIoDevice
, DestBarIndex
, PciBarTypeMem
, Width
, Count
, &DestOffset
);
800 if (EFI_ERROR (Status
)) {
801 return EFI_UNSUPPORTED
;
804 Status
= PciIoVerifyBarAccess (PciIoDevice
, SrcBarIndex
, PciBarTypeMem
, Width
, Count
, &SrcOffset
);
805 if (EFI_ERROR (Status
)) {
806 return EFI_UNSUPPORTED
;
809 Status
= PciIoDevice
->PciRootBridgeIo
->CopyMem (
810 PciIoDevice
->PciRootBridgeIo
,
811 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
817 if (EFI_ERROR (Status
)) {
818 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
827 IN EFI_PCI_IO_PROTOCOL
*This
,
828 IN EFI_PCI_IO_PROTOCOL_OPERATION Operation
,
829 IN VOID
*HostAddress
,
830 IN OUT UINTN
*NumberOfBytes
,
831 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
838 Maps a memory region for DMA
847 // TODO: This - add argument and description to function comment
848 // TODO: Operation - add argument and description to function comment
849 // TODO: HostAddress - add argument and description to function comment
850 // TODO: NumberOfBytes - add argument and description to function comment
851 // TODO: DeviceAddress - add argument and description to function comment
852 // TODO: Mapping - add argument and description to function comment
853 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
854 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
857 PCI_IO_DEVICE
*PciIoDevice
;
859 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
861 if (Operation
< 0 || Operation
>= EfiPciIoOperationMaximum
) {
862 return EFI_INVALID_PARAMETER
;
865 if (HostAddress
== NULL
|| NumberOfBytes
== NULL
|| DeviceAddress
== NULL
|| Mapping
== NULL
) {
866 return EFI_INVALID_PARAMETER
;
869 if (PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) {
870 Operation
= (EFI_PCI_IO_PROTOCOL_OPERATION
) (Operation
+ EfiPciOperationBusMasterRead64
);
873 Status
= PciIoDevice
->PciRootBridgeIo
->Map (
874 PciIoDevice
->PciRootBridgeIo
,
875 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION
) Operation
,
882 if (EFI_ERROR (Status
)) {
883 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
892 IN EFI_PCI_IO_PROTOCOL
*This
,
899 Unmaps a memory region for DMA
908 // TODO: This - add argument and description to function comment
909 // TODO: Mapping - add argument and description to function comment
912 PCI_IO_DEVICE
*PciIoDevice
;
914 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
916 Status
= PciIoDevice
->PciRootBridgeIo
->Unmap (
917 PciIoDevice
->PciRootBridgeIo
,
921 if (EFI_ERROR (Status
)) {
922 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
930 PciIoAllocateBuffer (
931 IN EFI_PCI_IO_PROTOCOL
*This
,
932 IN EFI_ALLOCATE_TYPE Type
,
933 IN EFI_MEMORY_TYPE MemoryType
,
935 OUT VOID
**HostAddress
,
942 Allocates a common buffer for DMA
951 // TODO: This - add argument and description to function comment
952 // TODO: Type - add argument and description to function comment
953 // TODO: MemoryType - add argument and description to function comment
954 // TODO: Pages - add argument and description to function comment
955 // TODO: HostAddress - add argument and description to function comment
956 // TODO: Attributes - add argument and description to function comment
957 // TODO: EFI_UNSUPPORTED - add return value to function comment
960 PCI_IO_DEVICE
*PciIoDevice
;
963 (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE
| EFI_PCI_ATTRIBUTE_MEMORY_CACHED
))) {
964 return EFI_UNSUPPORTED
;
967 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
969 if (PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) {
970 Attributes
|= EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
973 Status
= PciIoDevice
->PciRootBridgeIo
->AllocateBuffer (
974 PciIoDevice
->PciRootBridgeIo
,
982 if (EFI_ERROR (Status
)) {
983 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
992 IN EFI_PCI_IO_PROTOCOL
*This
,
1000 Frees a common buffer
1009 // TODO: This - add argument and description to function comment
1010 // TODO: Pages - add argument and description to function comment
1011 // TODO: HostAddress - add argument and description to function comment
1014 PCI_IO_DEVICE
*PciIoDevice
;
1016 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1018 Status
= PciIoDevice
->PciRootBridgeIo
->FreeBuffer (
1019 PciIoDevice
->PciRootBridgeIo
,
1024 if (EFI_ERROR (Status
)) {
1025 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1034 IN EFI_PCI_IO_PROTOCOL
*This
1038 Routine Description:
1040 Flushes a DMA buffer
1049 // TODO: This - add argument and description to function comment
1052 PCI_IO_DEVICE
*PciIoDevice
;
1054 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1056 Status
= PciIoDevice
->PciRootBridgeIo
->Flush (
1057 PciIoDevice
->PciRootBridgeIo
1059 if (EFI_ERROR (Status
)) {
1060 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1069 IN EFI_PCI_IO_PROTOCOL
*This
,
1077 Routine Description:
1079 Gets a PCI device's current bus number, device number, and function number.
1088 // TODO: This - add argument and description to function comment
1089 // TODO: Segment - add argument and description to function comment
1090 // TODO: Bus - add argument and description to function comment
1091 // TODO: Device - add argument and description to function comment
1092 // TODO: Function - add argument and description to function comment
1093 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1094 // TODO: EFI_SUCCESS - add return value to function comment
1096 PCI_IO_DEVICE
*PciIoDevice
;
1098 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1100 if (Segment
== NULL
|| Bus
== NULL
|| Device
== NULL
|| Function
== NULL
) {
1101 return EFI_INVALID_PARAMETER
;
1104 *Segment
= PciIoDevice
->PciRootBridgeIo
->SegmentNumber
;
1105 *Bus
= PciIoDevice
->BusNumber
;
1106 *Device
= PciIoDevice
->DeviceNumber
;
1107 *Function
= PciIoDevice
->FunctionNumber
;
1114 IN PCI_IO_DEVICE
*PciIoDevice
,
1116 PCI_BAR_TYPE BarType
1120 Routine Description:
1122 Sets a PCI controllers attributes on a resource range
1131 // TODO: PciIoDevice - add argument and description to function comment
1132 // TODO: BarIndex - add argument and description to function comment
1133 // TODO: BarType - add argument and description to function comment
1139 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem32
&&
1140 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem32
&&
1141 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem64
&&
1142 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem64
) {
1149 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo32
&&
1150 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo16
){
1164 ModifyRootBridgeAttributes (
1165 IN PCI_IO_DEVICE
*PciIoDevice
,
1166 IN UINT64 Attributes
,
1167 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1171 Routine Description:
1173 Set new attributes to a Root Bridge
1182 // TODO: PciIoDevice - add argument and description to function comment
1183 // TODO: Attributes - add argument and description to function comment
1184 // TODO: Operation - add argument and description to function comment
1185 // TODO: EFI_UNSUPPORTED - add return value to function comment
1186 // TODO: EFI_UNSUPPORTED - add return value to function comment
1187 // TODO: EFI_SUCCESS - add return value to function comment
1189 UINT64 PciRootBridgeSupports
;
1190 UINT64 PciRootBridgeAttributes
;
1191 UINT64 NewPciRootBridgeAttributes
;
1195 // Get the current attributes of this PCI device's PCI Root Bridge
1197 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1198 PciIoDevice
->PciRootBridgeIo
,
1199 &PciRootBridgeSupports
,
1200 &PciRootBridgeAttributes
1202 if (EFI_ERROR (Status
)) {
1203 return EFI_UNSUPPORTED
;
1207 // Record the new attribute of the Root Bridge
1209 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1210 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
| Attributes
;
1212 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
& (~Attributes
);
1216 // Call the PCI Root Bridge to attempt to modify the attributes
1218 if (NewPciRootBridgeAttributes
^ PciRootBridgeAttributes
) {
1220 Status
= PciIoDevice
->PciRootBridgeIo
->SetAttributes (
1221 PciIoDevice
->PciRootBridgeIo
,
1222 NewPciRootBridgeAttributes
,
1226 if (EFI_ERROR (Status
)) {
1228 // The PCI Root Bridge could not modify the attributes, so return the error.
1230 return EFI_UNSUPPORTED
;
1235 // Also update the attributes for this Root Bridge structure
1237 PciIoDevice
->Attributes
= NewPciRootBridgeAttributes
;
1243 SupportPaletteSnoopAttributes (
1244 IN PCI_IO_DEVICE
*PciIoDevice
,
1245 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1249 Routine Description:
1251 Check whether this device can be enable/disable to snoop
1260 // TODO: PciIoDevice - add argument and description to function comment
1261 // TODO: Operation - add argument and description to function comment
1262 // TODO: EFI_UNSUPPORTED - add return value to function comment
1263 // TODO: EFI_SUCCESS - add return value to function comment
1264 // TODO: EFI_SUCCESS - add return value to function comment
1265 // TODO: EFI_UNSUPPORTED - add return value to function comment
1266 // TODO: EFI_UNSUPPORTED - add return value to function comment
1267 // TODO: EFI_SUCCESS - add return value to function comment
1268 // TODO: EFI_UNSUPPORTED - add return value to function comment
1269 // TODO: EFI_UNSUPPORTED - add return value to function comment
1270 // TODO: EFI_SUCCESS - add return value to function comment
1272 PCI_IO_DEVICE
*Temp
;
1276 // Snoop attribute can be only modified by GFX
1278 if (!IS_PCI_GFX (&PciIoDevice
->Pci
)) {
1279 return EFI_UNSUPPORTED
;
1283 // Get the boot VGA on the same segement
1285 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1289 // If there is no VGA device on the segement, set
1290 // this graphics card to decode the palette range
1296 // Check these two agents are on the same path
1298 if (!PciDevicesOnTheSamePath (Temp
, PciIoDevice
)) {
1300 // they are not on the same path, so snoop can be enabled or disabled
1305 // Check if they are on the same bus
1307 if (Temp
->Parent
== PciIoDevice
->Parent
) {
1309 PciReadCommandRegister (Temp
, &VGACommand
);
1312 // If they are on the same bus, either one can
1313 // be set to snoop, the other set to decode
1315 if (VGACommand
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) {
1317 // VGA has set to snoop, so GFX can be only set to disable snoop
1319 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1320 return EFI_UNSUPPORTED
;
1324 // VGA has disabled to snoop, so GFX can be only enabled
1326 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1327 return EFI_UNSUPPORTED
;
1335 // If they are on the same path but on the different bus
1336 // The first agent is set to snoop, the second one set to
1340 if (Temp
->BusNumber
< PciIoDevice
->BusNumber
) {
1342 // GFX should be set to decode
1344 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1345 PciEnableCommandRegister (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1346 Temp
->Attributes
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1348 return EFI_UNSUPPORTED
;
1353 // GFX should be set to snoop
1355 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1356 PciDisableCommandRegister (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1357 Temp
->Attributes
&= (~EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1359 return EFI_UNSUPPORTED
;
1370 IN EFI_PCI_IO_PROTOCOL
* This
,
1371 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1372 IN UINT64 Attributes
,
1373 OUT UINT64
*Result OPTIONAL
1377 Routine Description:
1387 // TODO: This - add argument and description to function comment
1388 // TODO: Operation - add argument and description to function comment
1389 // TODO: Attributes - add argument and description to function comment
1390 // TODO: Result - add argument and description to function comment
1391 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1392 // TODO: EFI_SUCCESS - add return value to function comment
1393 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1394 // TODO: EFI_SUCCESS - add return value to function comment
1395 // TODO: EFI_UNSUPPORTED - add return value to function comment
1396 // TODO: EFI_UNSUPPORTED - add return value to function comment
1397 // TODO: EFI_SUCCESS - add return value to function comment
1398 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1399 // TODO: EFI_UNSUPPORTED - add return value to function comment
1400 // TODO: EFI_UNSUPPORTED - add return value to function comment
1401 // TODO: EFI_UNSUPPORTED - add return value to function comment
1405 PCI_IO_DEVICE
*PciIoDevice
;
1406 PCI_IO_DEVICE
*UpStreamBridge
;
1407 PCI_IO_DEVICE
*Temp
;
1410 UINT64 UpStreamAttributes
;
1411 UINT16 BridgeControl
;
1414 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1416 switch (Operation
) {
1417 case EfiPciIoAttributeOperationGet
:
1418 if (Result
== NULL
) {
1419 return EFI_INVALID_PARAMETER
;
1422 *Result
= PciIoDevice
->Attributes
;
1425 case EfiPciIoAttributeOperationSupported
:
1426 if (Result
== NULL
) {
1427 return EFI_INVALID_PARAMETER
;
1430 *Result
= PciIoDevice
->Supports
;
1433 case EfiPciIoAttributeOperationSet
:
1434 Status
= PciIoDevice
->PciIo
.Attributes (
1435 &(PciIoDevice
->PciIo
),
1436 EfiPciIoAttributeOperationEnable
,
1440 if (EFI_ERROR (Status
)) {
1441 return EFI_UNSUPPORTED
;
1444 Status
= PciIoDevice
->PciIo
.Attributes (
1445 &(PciIoDevice
->PciIo
),
1446 EfiPciIoAttributeOperationDisable
,
1447 (~Attributes
) & (PciIoDevice
->Supports
),
1450 if (EFI_ERROR (Status
)) {
1451 return EFI_UNSUPPORTED
;
1456 case EfiPciIoAttributeOperationEnable
:
1457 case EfiPciIoAttributeOperationDisable
:
1461 return EFI_INVALID_PARAMETER
;
1464 // Just a trick for ENABLE attribute
1466 if ((Attributes
& EFI_PCI_DEVICE_ENABLE
) == EFI_PCI_DEVICE_ENABLE
) {
1467 Attributes
&= (PciIoDevice
->Supports
);
1470 // Raise the EFI_P_PC_ENABLE Status code
1472 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
1474 EFI_IO_BUS_PCI
| EFI_P_PC_ENABLE
,
1475 PciIoDevice
->DevicePath
1480 // If no attributes can be supported, then return.
1481 // Otherwise, set the attributes that it can support.
1483 Supports
= (PciIoDevice
->Supports
) & Attributes
;
1484 if (Supports
!= Attributes
) {
1485 return EFI_UNSUPPORTED
;
1489 // For Root Bridge, just call RootBridgeIo to set attributes;
1491 if (!PciIoDevice
->Parent
) {
1492 Status
= ModifyRootBridgeAttributes (PciIoDevice
, Attributes
, Operation
);
1500 // Check VGA and VGA16, they can not be set at the same time
1502 if (((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) &&
1503 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) ||
1504 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) &&
1505 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) ||
1506 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) &&
1507 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) ||
1508 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) &&
1509 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) ) {
1510 return EFI_UNSUPPORTED
;
1514 // For PPB & P2C, set relevant attribute bits
1516 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1518 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) {
1519 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA
;
1522 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_ISA_IO
) {
1523 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_ISA
;
1526 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) {
1527 Command
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
1530 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) {
1531 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1536 // Do with the attributes on VGA
1537 // Only for VGA's legacy resource, we just can enable once.
1540 (EFI_PCI_IO_ATTRIBUTE_VGA_IO
|
1541 EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
|
1542 EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
)) {
1544 // Check if a VGA has been enabled before enabling a new one
1546 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1548 // Check if there have been an active VGA device on the same segment
1550 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1551 if (Temp
&& Temp
!= PciIoDevice
) {
1553 // An active VGA has been detected, so can not enable another
1555 return EFI_UNSUPPORTED
;
1561 // Do with the attributes on GFX
1563 if (Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) {
1565 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1567 // Check if snoop can be enabled in current configuration
1569 Status
= SupportPaletteSnoopAttributes (PciIoDevice
, Operation
);
1571 if (EFI_ERROR (Status
)) {
1574 // Enable operation is forbidden, so mask the bit in attributes
1575 // so as to keep consistent with the actual Status
1577 // Attributes &= (~EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO);
1581 return EFI_UNSUPPORTED
;
1587 // It can be supported, so get ready to set the bit
1589 Command
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1593 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) {
1594 Command
|= EFI_PCI_COMMAND_IO_SPACE
;
1597 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_MEMORY
) {
1598 Command
|= EFI_PCI_COMMAND_MEMORY_SPACE
;
1601 if (Attributes
& EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
) {
1602 Command
|= EFI_PCI_COMMAND_BUS_MASTER
;
1605 // The upstream bridge should be also set to revelant attribute
1606 // expect for IO, Mem and BusMaster
1608 UpStreamAttributes
= Attributes
&
1609 (~(EFI_PCI_IO_ATTRIBUTE_IO
|
1610 EFI_PCI_IO_ATTRIBUTE_MEMORY
|
1611 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
1614 UpStreamBridge
= PciIoDevice
->Parent
;
1616 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1618 // Enable relevant attributes to command register and bridge control register
1620 Status
= PciEnableCommandRegister (PciIoDevice
, Command
);
1621 if (BridgeControl
) {
1622 Status
= PciEnableBridgeControlRegister (PciIoDevice
, BridgeControl
);
1625 PciIoDevice
->Attributes
|= Attributes
;
1628 // Enable attributes of the upstream bridge
1630 Status
= UpStreamBridge
->PciIo
.Attributes (
1631 &(UpStreamBridge
->PciIo
),
1632 EfiPciIoAttributeOperationEnable
,
1639 // Disable relevant attributes to command register and bridge control register
1641 Status
= PciDisableCommandRegister (PciIoDevice
, Command
);
1642 if (BridgeControl
) {
1643 Status
= PciDisableBridgeControlRegister (PciIoDevice
, BridgeControl
);
1646 PciIoDevice
->Attributes
&= (~Attributes
);
1647 Status
= EFI_SUCCESS
;
1651 if (EFI_ERROR (Status
)) {
1652 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1660 PciIoGetBarAttributes (
1661 IN EFI_PCI_IO_PROTOCOL
* This
,
1663 OUT UINT64
*Supports
, OPTIONAL
1664 OUT VOID
**Resources OPTIONAL
1668 Routine Description:
1678 // TODO: This - add argument and description to function comment
1679 // TODO: BarIndex - add argument and description to function comment
1680 // TODO: Supports - add argument and description to function comment
1681 // TODO: Resources - add argument and description to function comment
1682 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1683 // TODO: EFI_UNSUPPORTED - add return value to function comment
1684 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
1685 // TODO: EFI_SUCCESS - add return value to function comment
1688 UINT8
*Configuration
;
1690 PCI_IO_DEVICE
*PciIoDevice
;
1691 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1692 EFI_ACPI_END_TAG_DESCRIPTOR
*PtrEnd
;
1696 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1698 if (Supports
== NULL
&& Resources
== NULL
) {
1699 return EFI_INVALID_PARAMETER
;
1702 if (BarIndex
>= PCI_MAX_BAR
) {
1703 return EFI_UNSUPPORTED
;
1707 // This driver does not support modifications to the WRITE_COMBINE or
1708 // CACHED attributes for BAR ranges.
1710 if (Supports
!= NULL
) {
1711 *Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1714 if (Resources
!= NULL
) {
1716 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeUnknown
) {
1720 Configuration
= AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1721 if (Configuration
== NULL
) {
1722 return EFI_OUT_OF_RESOURCES
;
1727 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
)
1730 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1732 if (NumConfig
== 1) {
1733 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1734 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1736 Ptr
->AddrRangeMin
= PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
1737 Ptr
->AddrLen
= PciIoDevice
->PciBar
[BarIndex
].Length
;
1738 Ptr
->AddrRangeMax
= PciIoDevice
->PciBar
[BarIndex
].Alignment
;
1740 switch (PciIoDevice
->PciBar
[BarIndex
].BarType
) {
1741 case PciBarTypeIo16
:
1742 case PciBarTypeIo32
:
1746 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_IO
;
1749 case PciBarTypeMem32
:
1753 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1757 Ptr
->AddrSpaceGranularity
= 32;
1760 case PciBarTypePMem32
:
1764 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1768 Ptr
->SpecificFlag
= 0x6;
1772 Ptr
->AddrSpaceGranularity
= 32;
1775 case PciBarTypeMem64
:
1779 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1783 Ptr
->AddrSpaceGranularity
= 64;
1786 case PciBarTypePMem64
:
1790 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1794 Ptr
->SpecificFlag
= 0x6;
1798 Ptr
->AddrSpaceGranularity
= 64;
1805 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) ((UINT8
*) Ptr
+ sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
));
1811 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) ((UINT8
*) Ptr
);
1812 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1813 PtrEnd
->Checksum
= 0;
1815 *Resources
= Configuration
;
1823 PciIoSetBarAttributes (
1824 IN EFI_PCI_IO_PROTOCOL
*This
,
1825 IN UINT64 Attributes
,
1827 IN OUT UINT64
*Offset
,
1828 IN OUT UINT64
*Length
1832 Routine Description:
1842 // TODO: This - add argument and description to function comment
1843 // TODO: Attributes - add argument and description to function comment
1844 // TODO: BarIndex - add argument and description to function comment
1845 // TODO: Offset - add argument and description to function comment
1846 // TODO: Length - add argument and description to function comment
1847 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1848 // TODO: EFI_UNSUPPORTED - add return value to function comment
1849 // TODO: EFI_UNSUPPORTED - add return value to function comment
1850 // TODO: EFI_UNSUPPORTED - add return value to function comment
1851 // TODO: EFI_SUCCESS - add return value to function comment
1854 PCI_IO_DEVICE
*PciIoDevice
;
1855 UINT64 NonRelativeOffset
;
1858 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1861 // Make sure Offset and Length are not NULL
1863 if (Offset
== NULL
|| Length
== NULL
) {
1864 return EFI_INVALID_PARAMETER
;
1867 if (PciIoDevice
->PciBar
[BarIndex
].BarType
== PciBarTypeUnknown
) {
1868 return EFI_UNSUPPORTED
;
1871 // This driver does not support setting the WRITE_COMBINE or the CACHED attributes.
1872 // If Attributes is not 0, then return EFI_UNSUPPORTED.
1874 Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1876 if (Attributes
!= (Attributes
& Supports
)) {
1877 return EFI_UNSUPPORTED
;
1880 // Attributes must be supported. Make sure the BAR range describd by BarIndex, Offset, and
1881 // Length are valid for this PCI device.
1883 NonRelativeOffset
= *Offset
;
1884 Status
= PciIoVerifyBarAccess (
1892 if (EFI_ERROR (Status
)) {
1893 return EFI_UNSUPPORTED
;
1900 UpStreamBridgesAttributes (
1901 IN PCI_IO_DEVICE
*PciIoDevice
,
1902 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1903 IN UINT64 Attributes
1907 Routine Description:
1916 // TODO: PciIoDevice - add argument and description to function comment
1917 // TODO: Operation - add argument and description to function comment
1918 // TODO: Attributes - add argument and description to function comment
1919 // TODO: EFI_SUCCESS - add return value to function comment
1921 PCI_IO_DEVICE
*Parent
;
1922 EFI_PCI_IO_PROTOCOL
*PciIo
;
1924 Parent
= PciIoDevice
->Parent
;
1926 while (Parent
&& IS_PCI_BRIDGE (&Parent
->Pci
)) {
1929 // Get the PciIo Protocol
1931 PciIo
= &Parent
->PciIo
;
1933 PciIo
->Attributes (PciIo
, Operation
, Attributes
, NULL
);
1935 Parent
= Parent
->Parent
;
1942 PciDevicesOnTheSamePath (
1943 IN PCI_IO_DEVICE
*PciDevice1
,
1944 IN PCI_IO_DEVICE
*PciDevice2
1948 Routine Description:
1957 // TODO: PciDevice1 - add argument and description to function comment
1958 // TODO: PciDevice2 - add argument and description to function comment
1963 if (PciDevice1
->Parent
== PciDevice2
->Parent
) {
1967 Existed1
= PciDeviceExisted (PciDevice1
->Parent
, PciDevice2
);
1968 Existed2
= PciDeviceExisted (PciDevice2
->Parent
, PciDevice1
);
1970 return (BOOLEAN
) (Existed1
|| Existed2
);