2 Implements all interfaces for EFI_PCI_IO_PROTOCOL.
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // Pci Io Protocol Interface
21 EFI_PCI_IO_PROTOCOL mPciIoInterface
= {
44 PciIoGetBarAttributes
,
45 PciIoSetBarAttributes
,
51 report a error Status code of PCI bus driver controller.
53 @param PciIoDevice Pci device instance.
54 @param Code status code.
58 ReportErrorStatusCode (
59 IN PCI_IO_DEVICE
*PciIoDevice
,
60 IN EFI_STATUS_CODE_VALUE Code
64 // PCI I/O Support Function Prototypes
69 report a error Status code of PCI bus driver controller.
71 @param PciIoDevice Pci device instance.
72 @param Code status code.
75 ReportErrorStatusCode (
76 IN PCI_IO_DEVICE
*PciIoDevice
,
77 IN EFI_STATUS_CODE_VALUE Code
80 return REPORT_STATUS_CODE_WITH_DEVICE_PATH (
81 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
83 PciIoDevice
->DevicePath
88 Initializes a PCI I/O Instance.
90 @param PciIoDevice Pci device instance.
94 InitializePciIoInstance (
95 PCI_IO_DEVICE
*PciIoDevice
98 CopyMem (&PciIoDevice
->PciIo
, &mPciIoInterface
, sizeof (EFI_PCI_IO_PROTOCOL
));
102 Verifies access to a PCI Base Address Register (BAR)
104 @param PciIoDevice Pci device instance
105 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
106 base address for the memory or I/O operation to perform.
107 @param Type Operation type could be memory or I/O
108 @param Width Signifies the width of the memory or I/O operations.
109 @param Count The number of memory or I/O operations to perform.
110 @param Offset The offset within the PCI configuration space for the PCI controller.
112 @retval EFI_INVALID_PARAMETER Invalid Width/BarIndex or Bar type.
113 @retval EFI_SUCCESS Success Operation.
116 PciIoVerifyBarAccess (
117 PCI_IO_DEVICE
*PciIoDevice
,
120 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
125 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
126 return EFI_INVALID_PARAMETER
;
129 if (BarIndex
== EFI_PCI_IO_PASS_THROUGH_BAR
) {
134 // BarIndex 0-5 is legal
136 if (BarIndex
>= PCI_MAX_BAR
) {
137 return EFI_INVALID_PARAMETER
;
140 if (!CheckBarType (PciIoDevice
, BarIndex
, Type
)) {
141 return EFI_INVALID_PARAMETER
;
145 // If Width is EfiPciIoWidthFifoUintX then convert to EfiPciIoWidthUintX
146 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
148 if (Width
>= EfiPciWidthFifoUint8
&& Width
<= EfiPciWidthFifoUint64
) {
152 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
154 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PciIoDevice
->PciBar
[BarIndex
].Length
) {
155 return EFI_INVALID_PARAMETER
;
158 *Offset
= *Offset
+ PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
164 Verifies access to a PCI Config Header
166 @param PciIoDevice Pci device instance
167 @param Width Signifies the width of the memory or I/O operations.
168 @param Count The number of memory or I/O operations to perform.
169 @param Offset The offset within the PCI configuration space for the PCI controller.
171 @retval EFI_INVALID_PARAMETER Invalid Width
172 @retval EFI_UNSUPPORTED Offset overflow
173 @retval EFI_SUCCESS Success operation
176 PciIoVerifyConfigAccess (
177 PCI_IO_DEVICE
*PciIoDevice
,
178 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
185 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
186 return EFI_INVALID_PARAMETER
;
190 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
192 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
194 if (PciIoDevice
->IsPciExp
) {
195 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_EXP_MAX_CONFIG_OFFSET
) {
196 return EFI_UNSUPPORTED
;
199 ExtendOffset
= LShiftU64 (*Offset
, 32);
200 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
201 *Offset
= (*Offset
) | ExtendOffset
;
204 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_MAX_CONFIG_OFFSET
) {
205 return EFI_UNSUPPORTED
;
208 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, *Offset
);
215 Reads from the I/O space of a PCI Root Bridge. Returns when either the polling exit criteria is
216 satisfied or after a defined duration.
218 @param This Pointer to protocol instance of EFI_PCI_IO_PROTOCOL
219 @param Width Signifies the width of the memory or I/O operations.
220 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
221 base address for the memory or I/O operation to perform.
222 @param Offset The offset within the PCI configuration space for the PCI controller.
223 @param Mask Mask used for the polling criteria.
224 @param Value The comparison value used for the polling exit criteria.
225 @param Delay The number of 100 ns units to poll.
226 @param Result Pointer to the last value read from the memory location.
228 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.
229 @retval EFI_TIMEOUT Delay expired before a match occurred.
230 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
231 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
236 IN EFI_PCI_IO_PROTOCOL
*This
,
237 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
247 PCI_IO_DEVICE
*PciIoDevice
;
249 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
251 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
252 return EFI_INVALID_PARAMETER
;
255 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, 1, &Offset
);
256 if (EFI_ERROR (Status
)) {
257 return EFI_UNSUPPORTED
;
260 if (Width
> EfiPciIoWidthUint64
) {
261 return EFI_INVALID_PARAMETER
;
264 Status
= PciIoDevice
->PciRootBridgeIo
->PollMem (
265 PciIoDevice
->PciRootBridgeIo
,
266 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
274 if (EFI_ERROR (Status
)) {
275 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
282 Reads from the I/O space of a PCI Root Bridge. Returns when either the polling exit criteria is
283 satisfied or after a defined duration.
285 @param This A pointer to the EFI_PCI_IO_PROTOCOL.
286 @param Width Signifies the width of the memory or I/O operations.
287 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
288 base address for the memory or I/O operation to perform.
289 @param Offset The offset within the selected BAR to start the memory or I/O operation.
290 @param Mask Mask used for the polling criteria.
291 @param Value The comparison value used for the polling exit criteria.
292 @param Delay The number of 100 ns units to poll.
293 @param Result Pointer to the last value read from the memory location.
295 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.
296 @retval EFI_TIMEOUT Delay expired before a match occurred.
297 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
298 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
304 IN EFI_PCI_IO_PROTOCOL
*This
,
305 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
315 PCI_IO_DEVICE
*PciIoDevice
;
317 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
319 if (Width
< 0 || Width
> EfiPciIoWidthUint64
) {
320 return EFI_INVALID_PARAMETER
;
323 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, 1, &Offset
);
324 if (EFI_ERROR (Status
)) {
325 return EFI_UNSUPPORTED
;
328 Status
= PciIoDevice
->PciRootBridgeIo
->PollIo (
329 PciIoDevice
->PciRootBridgeIo
,
330 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
338 if (EFI_ERROR (Status
)) {
339 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
346 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
348 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
349 @param Width Signifies the width of the memory or I/O operations.
350 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
351 base address for the memory or I/O operation to perform.
352 @param Offset The offset within the selected BAR to start the memory or I/O operation.
353 @param Count The number of memory or I/O operations to perform.
354 @param Buffer For read operations, the destination buffer to store the results. For write
355 operations, the source buffer to write data from.
357 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
358 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
359 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
360 valid for the PCI BAR specified by BarIndex.
361 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
362 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
368 IN EFI_PCI_IO_PROTOCOL
*This
,
369 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
377 PCI_IO_DEVICE
*PciIoDevice
;
379 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
381 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
382 return EFI_INVALID_PARAMETER
;
385 if (Buffer
== NULL
) {
386 return EFI_INVALID_PARAMETER
;
389 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
390 if (EFI_ERROR (Status
)) {
391 return EFI_UNSUPPORTED
;
394 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Read (
395 PciIoDevice
->PciRootBridgeIo
,
396 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
402 if (EFI_ERROR (Status
)) {
403 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
410 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
412 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
413 @param Width Signifies the width of the memory or I/O operations.
414 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
415 base address for the memory or I/O operation to perform.
416 @param Offset The offset within the selected BAR to start the memory or I/O operation.
417 @param Count The number of memory or I/O operations to perform.
418 @param Buffer For read operations, the destination buffer to store the results. For write
419 operations, the source buffer to write data from.
421 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
422 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
423 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
424 valid for the PCI BAR specified by BarIndex.
425 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
426 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
432 IN EFI_PCI_IO_PROTOCOL
*This
,
433 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
441 PCI_IO_DEVICE
*PciIoDevice
;
443 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
445 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
446 return EFI_INVALID_PARAMETER
;
449 if (Buffer
== NULL
) {
450 return EFI_INVALID_PARAMETER
;
453 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
454 if (EFI_ERROR (Status
)) {
455 return EFI_UNSUPPORTED
;
458 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Write (
459 PciIoDevice
->PciRootBridgeIo
,
460 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
466 if (EFI_ERROR (Status
)) {
467 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
474 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
476 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
477 @param Width Signifies the width of the memory or I/O operations.
478 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
479 base address for the memory or I/O operation to perform.
480 @param Offset The offset within the selected BAR to start the memory or I/O operation.
481 @param Count The number of memory or I/O operations to perform.
482 @param Buffer For read operations, the destination buffer to store the results. For write
483 operations, the source buffer to write data from.
485 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
486 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
487 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
488 valid for the PCI BAR specified by BarIndex.
489 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
490 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
496 IN EFI_PCI_IO_PROTOCOL
*This
,
497 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
505 PCI_IO_DEVICE
*PciIoDevice
;
507 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
509 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
510 return EFI_INVALID_PARAMETER
;
513 if (Buffer
== NULL
) {
514 return EFI_INVALID_PARAMETER
;
517 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
518 if (EFI_ERROR (Status
)) {
519 return EFI_UNSUPPORTED
;
522 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Read (
523 PciIoDevice
->PciRootBridgeIo
,
524 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
530 if (EFI_ERROR (Status
)) {
531 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
538 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
540 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
541 @param Width Signifies the width of the memory or I/O operations.
542 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
543 base address for the memory or I/O operation to perform.
544 @param Offset The offset within the selected BAR to start the memory or I/O operation.
545 @param Count The number of memory or I/O operations to perform.
546 @param Buffer For read operations, the destination buffer to store the results. For write
547 operations, the source buffer to write data from.
549 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
550 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
551 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
552 valid for the PCI BAR specified by BarIndex.
553 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
554 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
560 IN EFI_PCI_IO_PROTOCOL
*This
,
561 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
569 PCI_IO_DEVICE
*PciIoDevice
;
571 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
573 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
574 return EFI_INVALID_PARAMETER
;
577 if (Buffer
== NULL
) {
578 return EFI_INVALID_PARAMETER
;
581 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
582 if (EFI_ERROR (Status
)) {
583 return EFI_UNSUPPORTED
;
586 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Write (
587 PciIoDevice
->PciRootBridgeIo
,
588 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
594 if (EFI_ERROR (Status
)) {
595 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
602 Enable a PCI driver to access PCI controller registers in PCI configuration space.
604 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
605 @param Width Signifies the width of the memory operations.
606 @param Offset The offset within the PCI configuration space for the PCI controller.
607 @param Count The number of PCI configuration operations to perform.
608 @param Buffer For read operations, the destination buffer to store the results. For write
609 operations, the source buffer to write data from.
612 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
613 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
614 valid for the PCI configuration header of the PCI controller.
615 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
616 @retval EFI_INVALID_PARAMETER Buffer is NULL or Width is invalid.
622 IN EFI_PCI_IO_PROTOCOL
*This
,
623 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
630 PCI_IO_DEVICE
*PciIoDevice
;
633 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
636 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
637 if (EFI_ERROR (Status
)) {
641 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Read (
642 PciIoDevice
->PciRootBridgeIo
,
643 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
649 if (EFI_ERROR (Status
)) {
650 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
657 Enable a PCI driver to access PCI controller registers in PCI configuration space.
659 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
660 @param Width Signifies the width of the memory operations.
661 @param Offset The offset within the PCI configuration space for the PCI controller.
662 @param Count The number of PCI configuration operations to perform.
663 @param Buffer For read operations, the destination buffer to store the results. For write
664 operations, the source buffer to write data from.
667 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
668 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
669 valid for the PCI configuration header of the PCI controller.
670 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
671 @retval EFI_INVALID_PARAMETER Buffer is NULL or Width is invalid.
677 IN EFI_PCI_IO_PROTOCOL
*This
,
678 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
685 PCI_IO_DEVICE
*PciIoDevice
;
688 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
691 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
692 if (EFI_ERROR (Status
)) {
696 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Write (
697 PciIoDevice
->PciRootBridgeIo
,
698 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
704 if (EFI_ERROR (Status
)) {
705 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
712 Enables a PCI driver to copy one region of PCI memory space to another region of PCI
715 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
716 @param Width Signifies the width of the memory operations.
717 @param DestBarIndex The BAR index in the standard PCI Configuration header to use as the
718 base address for the memory operation to perform.
719 @param DestOffset The destination offset within the BAR specified by DestBarIndex to
720 start the memory writes for the copy operation.
721 @param SrcBarIndex The BAR index in the standard PCI Configuration header to use as the
722 base address for the memory operation to perform.
723 @param SrcOffset The source offset within the BAR specified by SrcBarIndex to start
724 the memory reads for the copy operation.
725 @param Count The number of memory operations to perform. Bytes moved is Width
726 size * Count, starting at DestOffset and SrcOffset.
728 @retval EFI_SUCCESS The data was copied from one memory region to another memory region.
729 @retval EFI_UNSUPPORTED DestBarIndex not valid for this PCI controller.
730 @retval EFI_UNSUPPORTED SrcBarIndex not valid for this PCI controller.
731 @retval EFI_UNSUPPORTED The address range specified by DestOffset, Width, and Count
732 is not valid for the PCI BAR specified by DestBarIndex.
733 @retval EFI_UNSUPPORTED The address range specified by SrcOffset, Width, and Count is
734 not valid for the PCI BAR specified by SrcBarIndex.
735 @retval EFI_INVALID_PARAMETER Width is invalid.
736 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
742 IN EFI_PCI_IO_PROTOCOL
*This
,
743 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
744 IN UINT8 DestBarIndex
,
745 IN UINT64 DestOffset
,
746 IN UINT8 SrcBarIndex
,
752 PCI_IO_DEVICE
*PciIoDevice
;
754 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
756 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
757 return EFI_INVALID_PARAMETER
;
760 if (Width
== EfiPciIoWidthFifoUint8
||
761 Width
== EfiPciIoWidthFifoUint16
||
762 Width
== EfiPciIoWidthFifoUint32
||
763 Width
== EfiPciIoWidthFifoUint64
||
764 Width
== EfiPciIoWidthFillUint8
||
765 Width
== EfiPciIoWidthFillUint16
||
766 Width
== EfiPciIoWidthFillUint32
||
767 Width
== EfiPciIoWidthFillUint64
) {
768 return EFI_INVALID_PARAMETER
;
771 Status
= PciIoVerifyBarAccess (PciIoDevice
, DestBarIndex
, PciBarTypeMem
, Width
, Count
, &DestOffset
);
772 if (EFI_ERROR (Status
)) {
773 return EFI_UNSUPPORTED
;
776 Status
= PciIoVerifyBarAccess (PciIoDevice
, SrcBarIndex
, PciBarTypeMem
, Width
, Count
, &SrcOffset
);
777 if (EFI_ERROR (Status
)) {
778 return EFI_UNSUPPORTED
;
781 Status
= PciIoDevice
->PciRootBridgeIo
->CopyMem (
782 PciIoDevice
->PciRootBridgeIo
,
783 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
789 if (EFI_ERROR (Status
)) {
790 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
797 Provides the PCI controller-Cspecific addresses needed to access system memory.
799 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
800 @param Operation Indicates if the bus master is going to read or write to system memory.
801 @param HostAddress The system memory address to map to the PCI controller.
802 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
804 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
805 access the hosts HostAddress.
806 @param Mapping A resulting value to pass to Unmap().
808 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
809 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
810 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
811 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
812 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
818 IN EFI_PCI_IO_PROTOCOL
*This
,
819 IN EFI_PCI_IO_PROTOCOL_OPERATION Operation
,
820 IN VOID
*HostAddress
,
821 IN OUT UINTN
*NumberOfBytes
,
822 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
827 PCI_IO_DEVICE
*PciIoDevice
;
829 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
831 if (Operation
< 0 || Operation
>= EfiPciIoOperationMaximum
) {
832 return EFI_INVALID_PARAMETER
;
835 if (HostAddress
== NULL
|| NumberOfBytes
== NULL
|| DeviceAddress
== NULL
|| Mapping
== NULL
) {
836 return EFI_INVALID_PARAMETER
;
839 if ((PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) != 0) {
840 Operation
= (EFI_PCI_IO_PROTOCOL_OPERATION
) (Operation
+ EfiPciOperationBusMasterRead64
);
843 Status
= PciIoDevice
->PciRootBridgeIo
->Map (
844 PciIoDevice
->PciRootBridgeIo
,
845 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION
) Operation
,
852 if (EFI_ERROR (Status
)) {
853 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
860 Completes the Map() operation and releases any corresponding resources.
862 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
863 @param Mapping The mapping value returned from Map().
865 @retval EFI_SUCCESS The range was unmapped.
866 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
872 IN EFI_PCI_IO_PROTOCOL
*This
,
877 PCI_IO_DEVICE
*PciIoDevice
;
879 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
881 Status
= PciIoDevice
->PciRootBridgeIo
->Unmap (
882 PciIoDevice
->PciRootBridgeIo
,
886 if (EFI_ERROR (Status
)) {
887 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
894 Allocates pages that are suitable for an EfiPciIoOperationBusMasterCommonBuffer
897 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
898 @param Type This parameter is not used and must be ignored.
899 @param MemoryType The type of memory to allocate, EfiBootServicesData or
900 EfiRuntimeServicesData.
901 @param Pages The number of pages to allocate.
902 @param HostAddress A pointer to store the base system memory address of the
904 @param Attributes The requested bit mask of attributes for the allocated range.
906 @retval EFI_SUCCESS The requested memory pages were allocated.
907 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
908 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
909 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
910 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
915 PciIoAllocateBuffer (
916 IN EFI_PCI_IO_PROTOCOL
*This
,
917 IN EFI_ALLOCATE_TYPE Type
,
918 IN EFI_MEMORY_TYPE MemoryType
,
920 OUT VOID
**HostAddress
,
925 PCI_IO_DEVICE
*PciIoDevice
;
928 (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE
| EFI_PCI_ATTRIBUTE_MEMORY_CACHED
))) != 0){
929 return EFI_UNSUPPORTED
;
932 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
934 if ((PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) != 0) {
935 Attributes
|= EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
938 Status
= PciIoDevice
->PciRootBridgeIo
->AllocateBuffer (
939 PciIoDevice
->PciRootBridgeIo
,
947 if (EFI_ERROR (Status
)) {
948 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
955 Frees memory that was allocated with AllocateBuffer().
957 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
958 @param Pages The number of pages to free.
959 @param HostAddress The base system memory address of the allocated range.
961 @retval EFI_SUCCESS The requested memory pages were freed.
962 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
963 was not allocated with AllocateBuffer().
969 IN EFI_PCI_IO_PROTOCOL
*This
,
975 PCI_IO_DEVICE
*PciIoDevice
;
977 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
979 Status
= PciIoDevice
->PciRootBridgeIo
->FreeBuffer (
980 PciIoDevice
->PciRootBridgeIo
,
985 if (EFI_ERROR (Status
)) {
986 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
993 Flushes all PCI posted write transactions from a PCI host bridge to system memory.
995 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
997 @retval EFI_SUCCESS The PCI posted write transactions were flushed from the PCI host
998 bridge to system memory.
999 @retval EFI_DEVICE_ERROR The PCI posted write transactions were not flushed from the PCI
1000 host bridge due to a hardware error.
1006 IN EFI_PCI_IO_PROTOCOL
*This
1010 PCI_IO_DEVICE
*PciIoDevice
;
1012 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1014 Status
= PciIoDevice
->PciRootBridgeIo
->Flush (
1015 PciIoDevice
->PciRootBridgeIo
1017 if (EFI_ERROR (Status
)) {
1018 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1025 Retrieves this PCI controller's current PCI bus number, device number, and function number.
1027 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1028 @param SegmentNumber The PCI controller's current PCI segment number.
1029 @param BusNumber The PCI controller's current PCI bus number.
1030 @param DeviceNumber The PCI controller's current PCI device number.
1031 @param FunctionNumber The PCI controller's current PCI function number.
1033 @retval EFI_SUCCESS The PCI controller location was returned.
1034 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1040 IN EFI_PCI_IO_PROTOCOL
*This
,
1047 PCI_IO_DEVICE
*PciIoDevice
;
1049 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1051 if (Segment
== NULL
|| Bus
== NULL
|| Device
== NULL
|| Function
== NULL
) {
1052 return EFI_INVALID_PARAMETER
;
1055 *Segment
= PciIoDevice
->PciRootBridgeIo
->SegmentNumber
;
1056 *Bus
= PciIoDevice
->BusNumber
;
1057 *Device
= PciIoDevice
->DeviceNumber
;
1058 *Function
= PciIoDevice
->FunctionNumber
;
1064 Check BAR type for PCI resource.
1066 @param PciIoDevice PCI device instance
1067 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
1068 base address for the memory or I/O operation to perform.
1069 @param BarType Memory or I/O
1071 @return whether Pci device's bar type is same with input BarType.
1075 IN PCI_IO_DEVICE
*PciIoDevice
,
1077 PCI_BAR_TYPE BarType
1084 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem32
&&
1085 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem32
&&
1086 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem64
&&
1087 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem64
) {
1094 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo32
&&
1095 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo16
){
1109 Set/Disable new attributes to a Root Bridge
1111 @param PciIoDevice Pci device instance
1112 @param Attributes New attribute want to be set
1113 @param Operation Set or Disable
1115 @retval EFI_UNSUPPORTED If root bridge does not support change attribute
1116 @retval EFI_SUCCESS Success operation.
1119 ModifyRootBridgeAttributes (
1120 IN PCI_IO_DEVICE
*PciIoDevice
,
1121 IN UINT64 Attributes
,
1122 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1125 UINT64 PciRootBridgeSupports
;
1126 UINT64 PciRootBridgeAttributes
;
1127 UINT64 NewPciRootBridgeAttributes
;
1131 // Get the current attributes of this PCI device's PCI Root Bridge
1133 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1134 PciIoDevice
->PciRootBridgeIo
,
1135 &PciRootBridgeSupports
,
1136 &PciRootBridgeAttributes
1138 if (EFI_ERROR (Status
)) {
1139 return EFI_UNSUPPORTED
;
1143 // Record the new attribute of the Root Bridge
1145 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1146 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
| Attributes
;
1148 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
& (~Attributes
);
1152 // Call the PCI Root Bridge to attempt to modify the attributes
1154 if ((NewPciRootBridgeAttributes
^ PciRootBridgeAttributes
) != 0) {
1156 Status
= PciIoDevice
->PciRootBridgeIo
->SetAttributes (
1157 PciIoDevice
->PciRootBridgeIo
,
1158 NewPciRootBridgeAttributes
,
1162 if (EFI_ERROR (Status
)) {
1164 // The PCI Root Bridge could not modify the attributes, so return the error.
1166 return EFI_UNSUPPORTED
;
1171 // Also update the attributes for this Root Bridge structure
1173 PciIoDevice
->Attributes
= NewPciRootBridgeAttributes
;
1179 Check whether this device can be enable/disable to snoop
1181 @param PciIoDevice Pci device instance
1182 @param Operation Enable/Disable
1184 @retval EFI_UNSUPPORTED Pci device is not GFX device or not support snoop
1185 @retval EFI_SUCCESS Snoop can be supported.
1188 SupportPaletteSnoopAttributes (
1189 IN PCI_IO_DEVICE
*PciIoDevice
,
1190 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1193 PCI_IO_DEVICE
*Temp
;
1197 // Snoop attribute can be only modified by GFX
1199 if (!IS_PCI_GFX (&PciIoDevice
->Pci
)) {
1200 return EFI_UNSUPPORTED
;
1204 // Get the boot VGA on the same segement
1206 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1210 // If there is no VGA device on the segement, set
1211 // this graphics card to decode the palette range
1217 // Check these two agents are on the same path
1219 if (!PciDevicesOnTheSamePath (Temp
, PciIoDevice
)) {
1221 // they are not on the same path, so snoop can be enabled or disabled
1226 // Check if they are on the same bus
1228 if (Temp
->Parent
== PciIoDevice
->Parent
) {
1230 PCI_READ_COMMAND_REGISTER (Temp
, &VGACommand
);
1233 // If they are on the same bus, either one can
1234 // be set to snoop, the other set to decode
1236 if ((VGACommand
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) != 0) {
1238 // VGA has set to snoop, so GFX can be only set to disable snoop
1240 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1241 return EFI_UNSUPPORTED
;
1245 // VGA has disabled to snoop, so GFX can be only enabled
1247 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1248 return EFI_UNSUPPORTED
;
1256 // If they are on the same path but on the different bus
1257 // The first agent is set to snoop, the second one set to
1261 if (Temp
->BusNumber
< PciIoDevice
->BusNumber
) {
1263 // GFX should be set to decode
1265 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1266 PCI_ENABLE_COMMAND_REGISTER (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1267 Temp
->Attributes
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1269 return EFI_UNSUPPORTED
;
1274 // GFX should be set to snoop
1276 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1277 PCI_DISABLE_COMMAND_REGISTER (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1278 Temp
->Attributes
&= (~EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1280 return EFI_UNSUPPORTED
;
1289 Performs an operation on the attributes that this PCI controller supports. The operations include
1290 getting the set of supported attributes, retrieving the current attributes, setting the current
1291 attributes, enabling attributes, and disabling attributes.
1293 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1294 @param Operation The operation to perform on the attributes for this PCI controller.
1295 @param Attributes The mask of attributes that are used for Set, Enable, and Disable
1297 @param Result A pointer to the result mask of attributes that are returned for the Get
1298 and Supported operations.
1300 @retval EFI_SUCCESS The operation on the PCI controller's attributes was completed.
1301 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1302 @retval EFI_UNSUPPORTED one or more of the bits set in
1303 Attributes are not supported by this PCI controller or one of
1304 its parent bridges when Operation is Set, Enable or Disable.
1310 IN EFI_PCI_IO_PROTOCOL
* This
,
1311 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1312 IN UINT64 Attributes
,
1313 OUT UINT64
*Result OPTIONAL
1318 PCI_IO_DEVICE
*PciIoDevice
;
1319 PCI_IO_DEVICE
*UpStreamBridge
;
1320 PCI_IO_DEVICE
*Temp
;
1323 UINT64 UpStreamAttributes
;
1324 UINT16 BridgeControl
;
1327 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1329 switch (Operation
) {
1330 case EfiPciIoAttributeOperationGet
:
1331 if (Result
== NULL
) {
1332 return EFI_INVALID_PARAMETER
;
1335 *Result
= PciIoDevice
->Attributes
;
1338 case EfiPciIoAttributeOperationSupported
:
1339 if (Result
== NULL
) {
1340 return EFI_INVALID_PARAMETER
;
1343 *Result
= PciIoDevice
->Supports
;
1346 case EfiPciIoAttributeOperationSet
:
1347 Status
= PciIoDevice
->PciIo
.Attributes (
1348 &(PciIoDevice
->PciIo
),
1349 EfiPciIoAttributeOperationEnable
,
1353 if (EFI_ERROR (Status
)) {
1354 return EFI_UNSUPPORTED
;
1357 Status
= PciIoDevice
->PciIo
.Attributes (
1358 &(PciIoDevice
->PciIo
),
1359 EfiPciIoAttributeOperationDisable
,
1360 (~Attributes
) & (PciIoDevice
->Supports
),
1363 if (EFI_ERROR (Status
)) {
1364 return EFI_UNSUPPORTED
;
1369 case EfiPciIoAttributeOperationEnable
:
1370 case EfiPciIoAttributeOperationDisable
:
1374 return EFI_INVALID_PARAMETER
;
1377 // Just a trick for ENABLE attribute
1378 // EFI_PCI_DEVICE_ENABLE is not defined in UEFI spec, which is the internal usage.
1379 // So, this logic doesn't confrom to UEFI spec, which should be removed.
1380 // But this trick logic is still kept for some binary drivers that depend on it.
1382 if ((Attributes
& EFI_PCI_DEVICE_ENABLE
) == EFI_PCI_DEVICE_ENABLE
) {
1383 Attributes
&= (PciIoDevice
->Supports
);
1386 // Raise the EFI_P_PC_ENABLE Status code
1388 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
1390 EFI_IO_BUS_PCI
| EFI_P_PC_ENABLE
,
1391 PciIoDevice
->DevicePath
1396 // If no attributes can be supported, then return.
1397 // Otherwise, set the attributes that it can support.
1399 Supports
= (PciIoDevice
->Supports
) & Attributes
;
1400 if (Supports
!= Attributes
) {
1401 return EFI_UNSUPPORTED
;
1405 // For Root Bridge, just call RootBridgeIo to set attributes;
1407 if (PciIoDevice
->Parent
== NULL
) {
1408 Status
= ModifyRootBridgeAttributes (PciIoDevice
, Attributes
, Operation
);
1416 // Check VGA and VGA16, they can not be set at the same time
1418 if (((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) != 0 &&
1419 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
) != 0) ||
1420 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) != 0 &&
1421 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
) != 0) ||
1422 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) != 0 &&
1423 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
) != 0) ||
1424 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) != 0 &&
1425 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
) != 0) ) {
1426 return EFI_UNSUPPORTED
;
1430 // For PPB & P2C, set relevant attribute bits
1432 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1434 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) != 0) {
1435 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA
;
1438 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_ISA_IO
) != 0) {
1439 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_ISA
;
1442 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) != 0) {
1443 Command
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
1446 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) != 0) {
1447 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1452 // Do with the attributes on VGA
1453 // Only for VGA's legacy resource, we just can enable once.
1456 (EFI_PCI_IO_ATTRIBUTE_VGA_IO
|
1457 EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
|
1458 EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
)) != 0) {
1460 // Check if a VGA has been enabled before enabling a new one
1462 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1464 // Check if there have been an active VGA device on the same segment
1466 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1467 if (Temp
!= NULL
&& Temp
!= PciIoDevice
) {
1469 // An active VGA has been detected, so can not enable another
1471 return EFI_UNSUPPORTED
;
1477 // Do with the attributes on GFX
1479 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) != 0) {
1481 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1483 // Check if snoop can be enabled in current configuration
1485 Status
= SupportPaletteSnoopAttributes (PciIoDevice
, Operation
);
1487 if (EFI_ERROR (Status
)) {
1490 // Enable operation is forbidden, so mask the bit in attributes
1491 // so as to keep consistent with the actual Status
1493 // Attributes &= (~EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO);
1497 return EFI_UNSUPPORTED
;
1503 // It can be supported, so get ready to set the bit
1505 Command
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1509 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) != 0) {
1510 Command
|= EFI_PCI_COMMAND_IO_SPACE
;
1513 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_MEMORY
) != 0) {
1514 Command
|= EFI_PCI_COMMAND_MEMORY_SPACE
;
1517 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
) != 0) {
1518 Command
|= EFI_PCI_COMMAND_BUS_MASTER
;
1521 // The upstream bridge should be also set to revelant attribute
1522 // expect for IO, Mem and BusMaster
1524 UpStreamAttributes
= Attributes
&
1525 (~(EFI_PCI_IO_ATTRIBUTE_IO
|
1526 EFI_PCI_IO_ATTRIBUTE_MEMORY
|
1527 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
1530 UpStreamBridge
= PciIoDevice
->Parent
;
1532 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1534 // Enable relevant attributes to command register and bridge control register
1536 Status
= PCI_ENABLE_COMMAND_REGISTER (PciIoDevice
, Command
);
1537 if (BridgeControl
!= 0) {
1538 Status
= PCI_ENABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, BridgeControl
);
1541 PciIoDevice
->Attributes
|= Attributes
;
1544 // Enable attributes of the upstream bridge
1546 Status
= UpStreamBridge
->PciIo
.Attributes (
1547 &(UpStreamBridge
->PciIo
),
1548 EfiPciIoAttributeOperationEnable
,
1555 // Disable relevant attributes to command register and bridge control register
1557 Status
= PCI_DISABLE_COMMAND_REGISTER (PciIoDevice
, Command
);
1558 if (BridgeControl
!= 0) {
1559 Status
= PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, BridgeControl
);
1562 PciIoDevice
->Attributes
&= (~Attributes
);
1563 Status
= EFI_SUCCESS
;
1567 if (EFI_ERROR (Status
)) {
1568 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1575 Gets the attributes that this PCI controller supports setting on a BAR using
1576 SetBarAttributes(), and retrieves the list of resource descriptors for a BAR.
1578 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1579 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
1580 base address for resource range. The legal range for this field is 0..5.
1581 @param Supports A pointer to the mask of attributes that this PCI controller supports
1582 setting for this BAR with SetBarAttributes().
1583 @param Resources A pointer to the ACPI 2.0 resource descriptors that describe the current
1584 configuration of this BAR of the PCI controller.
1586 @retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI
1587 controller supports are returned in Supports. If Resources
1588 is not NULL, then the ACPI 2.0 resource descriptors that the PCI
1589 controller is currently using are returned in Resources.
1590 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
1591 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
1592 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to allocate
1598 PciIoGetBarAttributes (
1599 IN EFI_PCI_IO_PROTOCOL
* This
,
1601 OUT UINT64
*Supports
, OPTIONAL
1602 OUT VOID
**Resources OPTIONAL
1606 UINT8
*Configuration
;
1608 PCI_IO_DEVICE
*PciIoDevice
;
1609 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1610 EFI_ACPI_END_TAG_DESCRIPTOR
*PtrEnd
;
1614 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1616 if (Supports
== NULL
&& Resources
== NULL
) {
1617 return EFI_INVALID_PARAMETER
;
1620 if (BarIndex
>= PCI_MAX_BAR
) {
1621 return EFI_UNSUPPORTED
;
1625 // This driver does not support modifications to the WRITE_COMBINE or
1626 // CACHED attributes for BAR ranges.
1628 if (Supports
!= NULL
) {
1629 *Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1632 if (Resources
!= NULL
) {
1634 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeUnknown
) {
1638 Configuration
= AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1639 if (Configuration
== NULL
) {
1640 return EFI_OUT_OF_RESOURCES
;
1645 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
)
1648 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1650 if (NumConfig
== 1) {
1651 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1652 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1654 Ptr
->AddrRangeMin
= PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
1655 Ptr
->AddrLen
= PciIoDevice
->PciBar
[BarIndex
].Length
;
1656 Ptr
->AddrRangeMax
= PciIoDevice
->PciBar
[BarIndex
].Alignment
;
1658 switch (PciIoDevice
->PciBar
[BarIndex
].BarType
) {
1659 case PciBarTypeIo16
:
1660 case PciBarTypeIo32
:
1664 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_IO
;
1667 case PciBarTypeMem32
:
1671 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1675 Ptr
->AddrSpaceGranularity
= 32;
1678 case PciBarTypePMem32
:
1682 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1686 Ptr
->SpecificFlag
= 0x6;
1690 Ptr
->AddrSpaceGranularity
= 32;
1693 case PciBarTypeMem64
:
1697 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1701 Ptr
->AddrSpaceGranularity
= 64;
1704 case PciBarTypePMem64
:
1708 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1712 Ptr
->SpecificFlag
= 0x6;
1716 Ptr
->AddrSpaceGranularity
= 64;
1723 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) ((UINT8
*) Ptr
+ sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
));
1729 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) ((UINT8
*) Ptr
);
1730 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1731 PtrEnd
->Checksum
= 0;
1733 *Resources
= Configuration
;
1740 Sets the attributes for a range of a BAR on a PCI controller.
1742 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1743 @param Attributes The mask of attributes to set for the resource range specified by
1744 BarIndex, Offset, and Length.
1745 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
1746 base address for resource range. The legal range for this field is 0..5.
1747 @param Offset A pointer to the BAR relative base address of the resource range to be
1748 modified by the attributes specified by Attributes.
1749 @param Length A pointer to the length of the resource range to be modified by the
1750 attributes specified by Attributes.
1752 @retval EFI_SUCCESS The set of attributes specified by Attributes for the resource
1753 range specified by BarIndex, Offset, and Length were
1754 set on the PCI controller, and the actual resource range is returned
1755 in Offset and Length.
1756 @retval EFI_INVALID_PARAMETER Offset or Length is NULL.
1757 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
1758 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the attributes on the
1759 resource range specified by BarIndex, Offset, and
1765 PciIoSetBarAttributes (
1766 IN EFI_PCI_IO_PROTOCOL
*This
,
1767 IN UINT64 Attributes
,
1769 IN OUT UINT64
*Offset
,
1770 IN OUT UINT64
*Length
1774 PCI_IO_DEVICE
*PciIoDevice
;
1775 UINT64 NonRelativeOffset
;
1778 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1781 // Make sure Offset and Length are not NULL
1783 if (Offset
== NULL
|| Length
== NULL
) {
1784 return EFI_INVALID_PARAMETER
;
1787 if (PciIoDevice
->PciBar
[BarIndex
].BarType
== PciBarTypeUnknown
) {
1788 return EFI_UNSUPPORTED
;
1791 // This driver does not support setting the WRITE_COMBINE or the CACHED attributes.
1792 // If Attributes is not 0, then return EFI_UNSUPPORTED.
1794 Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1796 if (Attributes
!= (Attributes
& Supports
)) {
1797 return EFI_UNSUPPORTED
;
1800 // Attributes must be supported. Make sure the BAR range describd by BarIndex, Offset, and
1801 // Length are valid for this PCI device.
1803 NonRelativeOffset
= *Offset
;
1804 Status
= PciIoVerifyBarAccess (
1812 if (EFI_ERROR (Status
)) {
1813 return EFI_UNSUPPORTED
;
1820 Program parent bridge's attribute recurrently.
1822 @param PciIoDevice Child Pci device instance
1823 @param Operation The operation to perform on the attributes for this PCI controller.
1824 @param Attributes The mask of attributes that are used for Set, Enable, and Disable
1827 @retval EFI_SUCCESS The operation on the PCI controller's attributes was completed.
1828 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1829 @retval EFI_UNSUPPORTED one or more of the bits set in
1830 Attributes are not supported by this PCI controller or one of
1831 its parent bridges when Operation is Set, Enable or Disable.
1835 UpStreamBridgesAttributes (
1836 IN PCI_IO_DEVICE
*PciIoDevice
,
1837 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1838 IN UINT64 Attributes
1841 PCI_IO_DEVICE
*Parent
;
1842 EFI_PCI_IO_PROTOCOL
*PciIo
;
1844 Parent
= PciIoDevice
->Parent
;
1846 while (Parent
!= NULL
&& IS_PCI_BRIDGE (&Parent
->Pci
)) {
1849 // Get the PciIo Protocol
1851 PciIo
= &Parent
->PciIo
;
1853 PciIo
->Attributes (PciIo
, Operation
, Attributes
, NULL
);
1855 Parent
= Parent
->Parent
;
1862 Test whether two Pci device has same parent bridge.
1864 @param PciDevice1 the frist pci device for testing
1865 @param PciDevice2 the second pci device for testing
1867 @return whether two Pci device has same parent bridge.
1870 PciDevicesOnTheSamePath (
1871 IN PCI_IO_DEVICE
*PciDevice1
,
1872 IN PCI_IO_DEVICE
*PciDevice2
1878 if (PciDevice1
->Parent
== PciDevice2
->Parent
) {
1882 Existed1
= PciDeviceExisted (PciDevice1
->Parent
, PciDevice2
);
1883 Existed2
= PciDeviceExisted (PciDevice2
->Parent
, PciDevice1
);
1885 return (BOOLEAN
) (Existed1
|| Existed2
);