2 EFI PCI IO protocol functions implementation for PCI Bus module.
4 Copyright (c) 2006 - 2009, 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.
18 // Pci Io Protocol Interface
20 EFI_PCI_IO_PROTOCOL mPciIoInterface
= {
43 PciIoGetBarAttributes
,
44 PciIoSetBarAttributes
,
50 Report a error Status code of PCI bus driver controller.
52 @param PciIoDevice Pci device instance.
53 @param Code Status code value.
57 ReportErrorStatusCode (
58 IN PCI_IO_DEVICE
*PciIoDevice
,
59 IN EFI_STATUS_CODE_VALUE Code
62 return REPORT_STATUS_CODE_WITH_DEVICE_PATH (
63 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
65 PciIoDevice
->DevicePath
70 Initializes a PCI I/O Instance.
72 @param PciIoDevice Pci device instance.
76 InitializePciIoInstance (
77 IN PCI_IO_DEVICE
*PciIoDevice
80 CopyMem (&PciIoDevice
->PciIo
, &mPciIoInterface
, sizeof (EFI_PCI_IO_PROTOCOL
));
84 Verifies access to a PCI Base Address Register (BAR).
86 @param PciIoDevice Pci device instance.
87 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
88 base address for the memory or I/O operation to perform.
89 @param Type Operation type could be memory or I/O.
90 @param Width Signifies the width of the memory or I/O operations.
91 @param Count The number of memory or I/O operations to perform.
92 @param Offset The offset within the PCI configuration space for the PCI controller.
94 @retval EFI_INVALID_PARAMETER Invalid Width/BarIndex or Bar type.
95 @retval EFI_SUCCESS Successfully verified.
99 PciIoVerifyBarAccess (
100 IN PCI_IO_DEVICE
*PciIoDevice
,
102 IN PCI_BAR_TYPE Type
,
103 IN IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
108 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
109 return EFI_INVALID_PARAMETER
;
112 if (BarIndex
== EFI_PCI_IO_PASS_THROUGH_BAR
) {
117 // BarIndex 0-5 is legal
119 if (BarIndex
>= PCI_MAX_BAR
) {
120 return EFI_INVALID_PARAMETER
;
123 if (!CheckBarType (PciIoDevice
, BarIndex
, Type
)) {
124 return EFI_INVALID_PARAMETER
;
128 // If Width is EfiPciIoWidthFifoUintX then convert to EfiPciIoWidthUintX
129 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
131 if (Width
>= EfiPciWidthFifoUint8
&& Width
<= EfiPciWidthFifoUint64
) {
135 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
137 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PciIoDevice
->PciBar
[BarIndex
].Length
) {
138 return EFI_INVALID_PARAMETER
;
141 *Offset
= *Offset
+ PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
147 Verifies access to a PCI Configuration Header.
149 @param PciIoDevice Pci device instance.
150 @param Width Signifies the width of the memory or I/O operations.
151 @param Count The number of memory or I/O operations to perform.
152 @param Offset The offset within the PCI configuration space for the PCI controller.
154 @retval EFI_INVALID_PARAMETER Invalid Width
155 @retval EFI_UNSUPPORTED Offset overflowed.
156 @retval EFI_SUCCESS Successfully verified.
160 PciIoVerifyConfigAccess (
161 IN PCI_IO_DEVICE
*PciIoDevice
,
162 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
169 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
170 return EFI_INVALID_PARAMETER
;
174 // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
176 Width
= (EFI_PCI_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
178 if (PciIoDevice
->IsPciExp
) {
179 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_EXP_MAX_CONFIG_OFFSET
) {
180 return EFI_UNSUPPORTED
;
183 ExtendOffset
= LShiftU64 (*Offset
, 32);
184 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
185 *Offset
= (*Offset
) | ExtendOffset
;
188 if ((*Offset
+ Count
* (UINTN
)(1 << Width
)) - 1 >= PCI_MAX_CONFIG_OFFSET
) {
189 return EFI_UNSUPPORTED
;
192 *Offset
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, *Offset
);
199 Reads from the memory space of a PCI controller. Returns either when the polling exit criteria is
200 satisfied or after a defined duration.
202 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
203 @param Width Signifies the width of the memory or I/O operations.
204 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
205 base address for the memory operation to perform.
206 @param Offset The offset within the selected BAR to start the memory operation.
207 @param Mask Mask used for the polling criteria.
208 @param Value The comparison value used for the polling exit criteria.
209 @param Delay The number of 100 ns units to poll.
210 @param Result Pointer to the last value read from the memory location.
212 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.
213 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
214 @retval EFI_UNSUPPORTED Offset is not valid for the BarIndex of this PCI controller.
215 @retval EFI_TIMEOUT Delay expired before a match occurred.
216 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
217 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
223 IN EFI_PCI_IO_PROTOCOL
*This
,
224 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
234 PCI_IO_DEVICE
*PciIoDevice
;
236 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
238 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
239 return EFI_INVALID_PARAMETER
;
242 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, 1, &Offset
);
243 if (EFI_ERROR (Status
)) {
244 return EFI_UNSUPPORTED
;
247 if (Width
> EfiPciIoWidthUint64
) {
248 return EFI_INVALID_PARAMETER
;
251 Status
= PciIoDevice
->PciRootBridgeIo
->PollMem (
252 PciIoDevice
->PciRootBridgeIo
,
253 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
261 if (EFI_ERROR (Status
)) {
262 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
269 Reads from the memory space of a PCI controller. Returns either when the polling exit criteria is
270 satisfied or after a defined duration.
272 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
273 @param Width Signifies the width of the memory or I/O operations.
274 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
275 base address for the memory operation to perform.
276 @param Offset The offset within the selected BAR to start the memory operation.
277 @param Mask Mask used for the polling criteria.
278 @param Value The comparison value used for the polling exit criteria.
279 @param Delay The number of 100 ns units to poll.
280 @param Result Pointer to the last value read from the memory location.
282 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.
283 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
284 @retval EFI_UNSUPPORTED Offset is not valid for the BarIndex of this PCI controller.
285 @retval EFI_TIMEOUT Delay expired before a match occurred.
286 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
287 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
293 IN EFI_PCI_IO_PROTOCOL
*This
,
294 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
304 PCI_IO_DEVICE
*PciIoDevice
;
306 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
308 if (Width
< 0 || Width
> EfiPciIoWidthUint64
) {
309 return EFI_INVALID_PARAMETER
;
312 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, 1, &Offset
);
313 if (EFI_ERROR (Status
)) {
314 return EFI_UNSUPPORTED
;
317 Status
= PciIoDevice
->PciRootBridgeIo
->PollIo (
318 PciIoDevice
->PciRootBridgeIo
,
319 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
327 if (EFI_ERROR (Status
)) {
328 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
335 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
337 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
338 @param Width Signifies the width of the memory or I/O operations.
339 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
340 base address for the memory or I/O operation to perform.
341 @param Offset The offset within the selected BAR to start the memory or I/O operation.
342 @param Count The number of memory or I/O operations to perform.
343 @param Buffer For read operations, the destination buffer to store the results. For write
344 operations, the source buffer to write data from.
346 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
347 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
348 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
349 valid for the PCI BAR specified by BarIndex.
350 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
351 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
357 IN EFI_PCI_IO_PROTOCOL
*This
,
358 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
366 PCI_IO_DEVICE
*PciIoDevice
;
368 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
370 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
371 return EFI_INVALID_PARAMETER
;
374 if (Buffer
== NULL
) {
375 return EFI_INVALID_PARAMETER
;
378 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
379 if (EFI_ERROR (Status
)) {
380 return EFI_UNSUPPORTED
;
383 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Read (
384 PciIoDevice
->PciRootBridgeIo
,
385 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
391 if (EFI_ERROR (Status
)) {
392 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
399 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
401 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
402 @param Width Signifies the width of the memory or I/O operations.
403 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
404 base address for the memory or I/O operation to perform.
405 @param Offset The offset within the selected BAR to start the memory or I/O operation.
406 @param Count The number of memory or I/O operations to perform.
407 @param Buffer For read operations, the destination buffer to store the results. For write
408 operations, the source buffer to write data from.
410 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
411 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
412 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
413 valid for the PCI BAR specified by BarIndex.
414 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
415 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
421 IN EFI_PCI_IO_PROTOCOL
*This
,
422 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
430 PCI_IO_DEVICE
*PciIoDevice
;
432 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
434 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
435 return EFI_INVALID_PARAMETER
;
438 if (Buffer
== NULL
) {
439 return EFI_INVALID_PARAMETER
;
442 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeMem
, Width
, Count
, &Offset
);
443 if (EFI_ERROR (Status
)) {
444 return EFI_UNSUPPORTED
;
447 Status
= PciIoDevice
->PciRootBridgeIo
->Mem
.Write (
448 PciIoDevice
->PciRootBridgeIo
,
449 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
455 if (EFI_ERROR (Status
)) {
456 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
463 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
465 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
466 @param Width Signifies the width of the memory or I/O operations.
467 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
468 base address for the memory or I/O operation to perform.
469 @param Offset The offset within the selected BAR to start the memory or I/O operation.
470 @param Count The number of memory or I/O operations to perform.
471 @param Buffer For read operations, the destination buffer to store the results. For write
472 operations, the source buffer to write data from.
474 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
475 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
476 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
477 valid for the PCI BAR specified by BarIndex.
478 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
479 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
485 IN EFI_PCI_IO_PROTOCOL
*This
,
486 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
494 PCI_IO_DEVICE
*PciIoDevice
;
496 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
498 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
499 return EFI_INVALID_PARAMETER
;
502 if (Buffer
== NULL
) {
503 return EFI_INVALID_PARAMETER
;
506 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
507 if (EFI_ERROR (Status
)) {
508 return EFI_UNSUPPORTED
;
511 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Read (
512 PciIoDevice
->PciRootBridgeIo
,
513 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
519 if (EFI_ERROR (Status
)) {
520 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
527 Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
529 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
530 @param Width Signifies the width of the memory or I/O operations.
531 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
532 base address for the memory or I/O operation to perform.
533 @param Offset The offset within the selected BAR to start the memory or I/O operation.
534 @param Count The number of memory or I/O operations to perform.
535 @param Buffer For read operations, the destination buffer to store the results. For write
536 operations, the source buffer to write data from.
538 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
539 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
540 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
541 valid for the PCI BAR specified by BarIndex.
542 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
543 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
549 IN EFI_PCI_IO_PROTOCOL
*This
,
550 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
558 PCI_IO_DEVICE
*PciIoDevice
;
560 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
562 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
563 return EFI_INVALID_PARAMETER
;
566 if (Buffer
== NULL
) {
567 return EFI_INVALID_PARAMETER
;
570 Status
= PciIoVerifyBarAccess (PciIoDevice
, BarIndex
, PciBarTypeIo
, Width
, Count
, &Offset
);
571 if (EFI_ERROR (Status
)) {
572 return EFI_UNSUPPORTED
;
575 Status
= PciIoDevice
->PciRootBridgeIo
->Io
.Write (
576 PciIoDevice
->PciRootBridgeIo
,
577 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
583 if (EFI_ERROR (Status
)) {
584 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
591 Enable a PCI driver to access PCI controller registers in PCI configuration space.
593 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
594 @param Width Signifies the width of the memory operations.
595 @param Offset The offset within the PCI configuration space for the PCI controller.
596 @param Count The number of PCI configuration operations to perform.
597 @param Buffer For read operations, the destination buffer to store the results. For write
598 operations, the source buffer to write data from.
601 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
602 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
603 valid for the PCI configuration header of the PCI controller.
604 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
605 @retval EFI_INVALID_PARAMETER Buffer is NULL or Width is invalid.
611 IN EFI_PCI_IO_PROTOCOL
*This
,
612 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
619 PCI_IO_DEVICE
*PciIoDevice
;
622 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
625 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
626 if (EFI_ERROR (Status
)) {
630 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Read (
631 PciIoDevice
->PciRootBridgeIo
,
632 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
638 if (EFI_ERROR (Status
)) {
639 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_READ_ERROR
);
646 Enable a PCI driver to access PCI controller registers in PCI configuration space.
648 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
649 @param Width Signifies the width of the memory operations.
650 @param Offset The offset within the PCI configuration space for the PCI controller.
651 @param Count The number of PCI configuration operations to perform.
652 @param Buffer For read operations, the destination buffer to store the results. For write
653 operations, the source buffer to write data from.
656 @retval EFI_SUCCESS The data was read from or written to the PCI controller.
657 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
658 valid for the PCI configuration header of the PCI controller.
659 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
660 @retval EFI_INVALID_PARAMETER Buffer is NULL or Width is invalid.
666 IN EFI_PCI_IO_PROTOCOL
*This
,
667 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
674 PCI_IO_DEVICE
*PciIoDevice
;
677 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
680 Status
= PciIoVerifyConfigAccess (PciIoDevice
, Width
, Count
, &Address
);
681 if (EFI_ERROR (Status
)) {
685 Status
= PciIoDevice
->PciRootBridgeIo
->Pci
.Write (
686 PciIoDevice
->PciRootBridgeIo
,
687 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
693 if (EFI_ERROR (Status
)) {
694 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_WRITE_ERROR
);
701 Enables a PCI driver to copy one region of PCI memory space to another region of PCI
704 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
705 @param Width Signifies the width of the memory operations.
706 @param DestBarIndex The BAR index in the standard PCI Configuration header to use as the
707 base address for the memory operation to perform.
708 @param DestOffset The destination offset within the BAR specified by DestBarIndex to
709 start the memory writes for the copy operation.
710 @param SrcBarIndex The BAR index in the standard PCI Configuration header to use as the
711 base address for the memory operation to perform.
712 @param SrcOffset The source offset within the BAR specified by SrcBarIndex to start
713 the memory reads for the copy operation.
714 @param Count The number of memory operations to perform. Bytes moved is Width
715 size * Count, starting at DestOffset and SrcOffset.
717 @retval EFI_SUCCESS The data was copied from one memory region to another memory region.
718 @retval EFI_UNSUPPORTED DestBarIndex not valid for this PCI controller.
719 @retval EFI_UNSUPPORTED SrcBarIndex not valid for this PCI controller.
720 @retval EFI_UNSUPPORTED The address range specified by DestOffset, Width, and Count
721 is not valid for the PCI BAR specified by DestBarIndex.
722 @retval EFI_UNSUPPORTED The address range specified by SrcOffset, Width, and Count is
723 not valid for the PCI BAR specified by SrcBarIndex.
724 @retval EFI_INVALID_PARAMETER Width is invalid.
725 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
731 IN EFI_PCI_IO_PROTOCOL
*This
,
732 IN EFI_PCI_IO_PROTOCOL_WIDTH Width
,
733 IN UINT8 DestBarIndex
,
734 IN UINT64 DestOffset
,
735 IN UINT8 SrcBarIndex
,
741 PCI_IO_DEVICE
*PciIoDevice
;
743 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
745 if (Width
< 0 || Width
>= EfiPciIoWidthMaximum
) {
746 return EFI_INVALID_PARAMETER
;
749 if (Width
== EfiPciIoWidthFifoUint8
||
750 Width
== EfiPciIoWidthFifoUint16
||
751 Width
== EfiPciIoWidthFifoUint32
||
752 Width
== EfiPciIoWidthFifoUint64
||
753 Width
== EfiPciIoWidthFillUint8
||
754 Width
== EfiPciIoWidthFillUint16
||
755 Width
== EfiPciIoWidthFillUint32
||
756 Width
== EfiPciIoWidthFillUint64
) {
757 return EFI_INVALID_PARAMETER
;
760 Status
= PciIoVerifyBarAccess (PciIoDevice
, DestBarIndex
, PciBarTypeMem
, Width
, Count
, &DestOffset
);
761 if (EFI_ERROR (Status
)) {
762 return EFI_UNSUPPORTED
;
765 Status
= PciIoVerifyBarAccess (PciIoDevice
, SrcBarIndex
, PciBarTypeMem
, Width
, Count
, &SrcOffset
);
766 if (EFI_ERROR (Status
)) {
767 return EFI_UNSUPPORTED
;
770 Status
= PciIoDevice
->PciRootBridgeIo
->CopyMem (
771 PciIoDevice
->PciRootBridgeIo
,
772 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
778 if (EFI_ERROR (Status
)) {
779 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
786 Provides the PCI controller-specific addresses needed to access system memory.
788 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
789 @param Operation Indicates if the bus master is going to read or write to system memory.
790 @param HostAddress The system memory address to map to the PCI controller.
791 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
793 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
794 access the hosts HostAddress.
795 @param Mapping A resulting value to pass to Unmap().
797 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
798 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
799 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
800 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
801 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
807 IN EFI_PCI_IO_PROTOCOL
*This
,
808 IN EFI_PCI_IO_PROTOCOL_OPERATION Operation
,
809 IN VOID
*HostAddress
,
810 IN OUT UINTN
*NumberOfBytes
,
811 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
816 PCI_IO_DEVICE
*PciIoDevice
;
818 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
820 if (Operation
< 0 || Operation
>= EfiPciIoOperationMaximum
) {
821 return EFI_INVALID_PARAMETER
;
824 if (HostAddress
== NULL
|| NumberOfBytes
== NULL
|| DeviceAddress
== NULL
|| Mapping
== NULL
) {
825 return EFI_INVALID_PARAMETER
;
828 if ((PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) != 0) {
829 Operation
= (EFI_PCI_IO_PROTOCOL_OPERATION
) (Operation
+ EfiPciOperationBusMasterRead64
);
832 Status
= PciIoDevice
->PciRootBridgeIo
->Map (
833 PciIoDevice
->PciRootBridgeIo
,
834 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION
) Operation
,
841 if (EFI_ERROR (Status
)) {
842 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
849 Completes the Map() operation and releases any corresponding resources.
851 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
852 @param Mapping The mapping value returned from Map().
854 @retval EFI_SUCCESS The range was unmapped.
855 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
861 IN EFI_PCI_IO_PROTOCOL
*This
,
866 PCI_IO_DEVICE
*PciIoDevice
;
868 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
870 Status
= PciIoDevice
->PciRootBridgeIo
->Unmap (
871 PciIoDevice
->PciRootBridgeIo
,
875 if (EFI_ERROR (Status
)) {
876 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
883 Allocates pages that are suitable for an EfiPciIoOperationBusMasterCommonBuffer
886 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
887 @param Type This parameter is not used and must be ignored.
888 @param MemoryType The type of memory to allocate, EfiBootServicesData or
889 EfiRuntimeServicesData.
890 @param Pages The number of pages to allocate.
891 @param HostAddress A pointer to store the base system memory address of the
893 @param Attributes The requested bit mask of attributes for the allocated range.
895 @retval EFI_SUCCESS The requested memory pages were allocated.
896 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
897 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
898 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
899 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
904 PciIoAllocateBuffer (
905 IN EFI_PCI_IO_PROTOCOL
*This
,
906 IN EFI_ALLOCATE_TYPE Type
,
907 IN EFI_MEMORY_TYPE MemoryType
,
909 OUT VOID
**HostAddress
,
914 PCI_IO_DEVICE
*PciIoDevice
;
917 (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE
| EFI_PCI_ATTRIBUTE_MEMORY_CACHED
))) != 0){
918 return EFI_UNSUPPORTED
;
921 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
923 if ((PciIoDevice
->Attributes
& EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
) != 0) {
924 Attributes
|= EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE
;
927 Status
= PciIoDevice
->PciRootBridgeIo
->AllocateBuffer (
928 PciIoDevice
->PciRootBridgeIo
,
936 if (EFI_ERROR (Status
)) {
937 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
944 Frees memory that was allocated with AllocateBuffer().
946 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
947 @param Pages The number of pages to free.
948 @param HostAddress The base system memory address of the allocated range.
950 @retval EFI_SUCCESS The requested memory pages were freed.
951 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
952 was not allocated with AllocateBuffer().
958 IN EFI_PCI_IO_PROTOCOL
*This
,
964 PCI_IO_DEVICE
*PciIoDevice
;
966 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
968 Status
= PciIoDevice
->PciRootBridgeIo
->FreeBuffer (
969 PciIoDevice
->PciRootBridgeIo
,
974 if (EFI_ERROR (Status
)) {
975 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
982 Flushes all PCI posted write transactions from a PCI host bridge to system memory.
984 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
986 @retval EFI_SUCCESS The PCI posted write transactions were flushed from the PCI host
987 bridge to system memory.
988 @retval EFI_DEVICE_ERROR The PCI posted write transactions were not flushed from the PCI
989 host bridge due to a hardware error.
995 IN EFI_PCI_IO_PROTOCOL
*This
999 PCI_IO_DEVICE
*PciIoDevice
;
1001 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1003 Status
= PciIoDevice
->PciRootBridgeIo
->Flush (
1004 PciIoDevice
->PciRootBridgeIo
1006 if (EFI_ERROR (Status
)) {
1007 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1014 Retrieves this PCI controller's current PCI bus number, device number, and function number.
1016 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1017 @param SegmentNumber The PCI controller's current PCI segment number.
1018 @param BusNumber The PCI controller's current PCI bus number.
1019 @param DeviceNumber The PCI controller's current PCI device number.
1020 @param FunctionNumber The PCI controller's current PCI function number.
1022 @retval EFI_SUCCESS The PCI controller location was returned.
1023 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1029 IN EFI_PCI_IO_PROTOCOL
*This
,
1036 PCI_IO_DEVICE
*PciIoDevice
;
1038 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1040 if (Segment
== NULL
|| Bus
== NULL
|| Device
== NULL
|| Function
== NULL
) {
1041 return EFI_INVALID_PARAMETER
;
1044 *Segment
= PciIoDevice
->PciRootBridgeIo
->SegmentNumber
;
1045 *Bus
= PciIoDevice
->BusNumber
;
1046 *Device
= PciIoDevice
->DeviceNumber
;
1047 *Function
= PciIoDevice
->FunctionNumber
;
1053 Check BAR type for PCI resource.
1055 @param PciIoDevice PCI device instance.
1056 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
1057 base address for the memory or I/O operation to perform.
1058 @param BarType Memory or I/O.
1060 @retval TRUE Pci device's bar type is same with input BarType.
1061 @retval TRUE Pci device's bar type is not same with input BarType.
1066 IN PCI_IO_DEVICE
*PciIoDevice
,
1068 IN PCI_BAR_TYPE BarType
1075 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem32
&&
1076 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem32
&&
1077 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypePMem64
&&
1078 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeMem64
) {
1085 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo32
&&
1086 PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeIo16
){
1100 Set/Disable new attributes to a Root Bridge.
1102 @param PciIoDevice Pci device instance.
1103 @param Attributes New attribute want to be set.
1104 @param Operation Set or Disable.
1106 @retval EFI_UNSUPPORTED If root bridge does not support change attribute.
1107 @retval EFI_SUCCESS Successfully set new attributs.
1111 ModifyRootBridgeAttributes (
1112 IN PCI_IO_DEVICE
*PciIoDevice
,
1113 IN UINT64 Attributes
,
1114 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1117 UINT64 PciRootBridgeSupports
;
1118 UINT64 PciRootBridgeAttributes
;
1119 UINT64 NewPciRootBridgeAttributes
;
1123 // Get the current attributes of this PCI device's PCI Root Bridge
1125 Status
= PciIoDevice
->PciRootBridgeIo
->GetAttributes (
1126 PciIoDevice
->PciRootBridgeIo
,
1127 &PciRootBridgeSupports
,
1128 &PciRootBridgeAttributes
1130 if (EFI_ERROR (Status
)) {
1131 return EFI_UNSUPPORTED
;
1135 // Record the new attribute of the Root Bridge
1137 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1138 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
| Attributes
;
1140 NewPciRootBridgeAttributes
= PciRootBridgeAttributes
& (~Attributes
);
1144 // Call the PCI Root Bridge to attempt to modify the attributes
1146 if ((NewPciRootBridgeAttributes
^ PciRootBridgeAttributes
) != 0) {
1148 Status
= PciIoDevice
->PciRootBridgeIo
->SetAttributes (
1149 PciIoDevice
->PciRootBridgeIo
,
1150 NewPciRootBridgeAttributes
,
1154 if (EFI_ERROR (Status
)) {
1156 // The PCI Root Bridge could not modify the attributes, so return the error.
1158 return EFI_UNSUPPORTED
;
1163 // Also update the attributes for this Root Bridge structure
1165 PciIoDevice
->Attributes
= NewPciRootBridgeAttributes
;
1171 Check whether this device can be enable/disable to snoop.
1173 @param PciIoDevice Pci device instance.
1174 @param Operation Enable/Disable.
1176 @retval EFI_UNSUPPORTED Pci device is not GFX device or not support snoop.
1177 @retval EFI_SUCCESS Snoop can be supported.
1181 SupportPaletteSnoopAttributes (
1182 IN PCI_IO_DEVICE
*PciIoDevice
,
1183 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
1186 PCI_IO_DEVICE
*Temp
;
1190 // Snoop attribute can be only modified by GFX
1192 if (!IS_PCI_GFX (&PciIoDevice
->Pci
)) {
1193 return EFI_UNSUPPORTED
;
1197 // Get the boot VGA on the same segement
1199 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1203 // If there is no VGA device on the segement, set
1204 // this graphics card to decode the palette range
1210 // Check these two agents are on the same path
1212 if (!PciDevicesOnTheSamePath (Temp
, PciIoDevice
)) {
1214 // they are not on the same path, so snoop can be enabled or disabled
1219 // Check if they are on the same bus
1221 if (Temp
->Parent
== PciIoDevice
->Parent
) {
1223 PCI_READ_COMMAND_REGISTER (Temp
, &VGACommand
);
1226 // If they are on the same bus, either one can
1227 // be set to snoop, the other set to decode
1229 if ((VGACommand
& EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
) != 0) {
1231 // VGA has set to snoop, so GFX can be only set to disable snoop
1233 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1234 return EFI_UNSUPPORTED
;
1238 // VGA has disabled to snoop, so GFX can be only enabled
1240 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1241 return EFI_UNSUPPORTED
;
1249 // If they are on the same path but on the different bus
1250 // The first agent is set to snoop, the second one set to
1254 if (Temp
->BusNumber
< PciIoDevice
->BusNumber
) {
1256 // GFX should be set to decode
1258 if (Operation
== EfiPciIoAttributeOperationDisable
) {
1259 PCI_ENABLE_COMMAND_REGISTER (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1260 Temp
->Attributes
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1262 return EFI_UNSUPPORTED
;
1267 // GFX should be set to snoop
1269 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1270 PCI_DISABLE_COMMAND_REGISTER (Temp
, EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1271 Temp
->Attributes
&= (~EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
);
1273 return EFI_UNSUPPORTED
;
1282 Performs an operation on the attributes that this PCI controller supports. The operations include
1283 getting the set of supported attributes, retrieving the current attributes, setting the current
1284 attributes, enabling attributes, and disabling attributes.
1286 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1287 @param Operation The operation to perform on the attributes for this PCI controller.
1288 @param Attributes The mask of attributes that are used for Set, Enable, and Disable
1290 @param Result A pointer to the result mask of attributes that are returned for the Get
1291 and Supported operations.
1293 @retval EFI_SUCCESS The operation on the PCI controller's attributes was completed.
1294 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1295 @retval EFI_UNSUPPORTED one or more of the bits set in
1296 Attributes are not supported by this PCI controller or one of
1297 its parent bridges when Operation is Set, Enable or Disable.
1303 IN EFI_PCI_IO_PROTOCOL
* This
,
1304 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1305 IN UINT64 Attributes
,
1306 OUT UINT64
*Result OPTIONAL
1311 PCI_IO_DEVICE
*PciIoDevice
;
1312 PCI_IO_DEVICE
*UpStreamBridge
;
1313 PCI_IO_DEVICE
*Temp
;
1316 UINT64 UpStreamAttributes
;
1317 UINT16 BridgeControl
;
1320 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1322 switch (Operation
) {
1323 case EfiPciIoAttributeOperationGet
:
1324 if (Result
== NULL
) {
1325 return EFI_INVALID_PARAMETER
;
1328 *Result
= PciIoDevice
->Attributes
;
1331 case EfiPciIoAttributeOperationSupported
:
1332 if (Result
== NULL
) {
1333 return EFI_INVALID_PARAMETER
;
1336 *Result
= PciIoDevice
->Supports
;
1339 case EfiPciIoAttributeOperationSet
:
1340 Status
= PciIoDevice
->PciIo
.Attributes (
1341 &(PciIoDevice
->PciIo
),
1342 EfiPciIoAttributeOperationEnable
,
1346 if (EFI_ERROR (Status
)) {
1347 return EFI_UNSUPPORTED
;
1350 Status
= PciIoDevice
->PciIo
.Attributes (
1351 &(PciIoDevice
->PciIo
),
1352 EfiPciIoAttributeOperationDisable
,
1353 (~Attributes
) & (PciIoDevice
->Supports
),
1356 if (EFI_ERROR (Status
)) {
1357 return EFI_UNSUPPORTED
;
1362 case EfiPciIoAttributeOperationEnable
:
1363 case EfiPciIoAttributeOperationDisable
:
1367 return EFI_INVALID_PARAMETER
;
1370 // Just a trick for ENABLE attribute
1371 // EFI_PCI_DEVICE_ENABLE is not defined in UEFI spec, which is the internal usage.
1372 // So, this logic doesn't confrom to UEFI spec, which should be removed.
1373 // But this trick logic is still kept for some binary drivers that depend on it.
1375 if ((Attributes
& EFI_PCI_DEVICE_ENABLE
) == EFI_PCI_DEVICE_ENABLE
) {
1376 Attributes
&= (PciIoDevice
->Supports
);
1379 // Raise the EFI_P_PC_ENABLE Status code
1381 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
1383 EFI_IO_BUS_PCI
| EFI_P_PC_ENABLE
,
1384 PciIoDevice
->DevicePath
1389 // If no attributes can be supported, then return.
1390 // Otherwise, set the attributes that it can support.
1392 Supports
= (PciIoDevice
->Supports
) & Attributes
;
1393 if (Supports
!= Attributes
) {
1394 return EFI_UNSUPPORTED
;
1398 // For Root Bridge, just call RootBridgeIo to set attributes;
1400 if (PciIoDevice
->Parent
== NULL
) {
1401 Status
= ModifyRootBridgeAttributes (PciIoDevice
, Attributes
, Operation
);
1409 // Check VGA and VGA16, they can not be set at the same time
1411 if (((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) != 0 &&
1412 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
) != 0) ||
1413 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO
) != 0 &&
1414 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
) != 0) ||
1415 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) != 0 &&
1416 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
) != 0) ||
1417 ((Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
) != 0 &&
1418 (Attributes
& EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
) != 0) ) {
1419 return EFI_UNSUPPORTED
;
1423 // For PPB & P2C, set relevant attribute bits
1425 if (IS_PCI_BRIDGE (&PciIoDevice
->Pci
) || IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
1427 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) != 0) {
1428 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA
;
1431 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_ISA_IO
) != 0) {
1432 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_ISA
;
1435 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) != 0) {
1436 Command
|= EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
;
1439 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
| EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
)) != 0) {
1440 BridgeControl
|= EFI_PCI_BRIDGE_CONTROL_VGA_16
;
1445 // Do with the attributes on VGA
1446 // Only for VGA's legacy resource, we just can enable once.
1449 (EFI_PCI_IO_ATTRIBUTE_VGA_IO
|
1450 EFI_PCI_IO_ATTRIBUTE_VGA_IO_16
|
1451 EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
)) != 0) {
1453 // Check if a VGA has been enabled before enabling a new one
1455 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1457 // Check if there have been an active VGA device on the same segment
1459 Temp
= ActiveVGADeviceOnTheSameSegment (PciIoDevice
);
1460 if (Temp
!= NULL
&& Temp
!= PciIoDevice
) {
1462 // An active VGA has been detected, so can not enable another
1464 return EFI_UNSUPPORTED
;
1470 // Do with the attributes on GFX
1472 if ((Attributes
& (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO
| EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16
)) != 0) {
1474 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1476 // Check if snoop can be enabled in current configuration
1478 Status
= SupportPaletteSnoopAttributes (PciIoDevice
, Operation
);
1480 if (EFI_ERROR (Status
)) {
1483 // Enable operation is forbidden, so mask the bit in attributes
1484 // so as to keep consistent with the actual Status
1486 // Attributes &= (~EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO);
1490 return EFI_UNSUPPORTED
;
1496 // It can be supported, so get ready to set the bit
1498 Command
|= EFI_PCI_COMMAND_VGA_PALETTE_SNOOP
;
1502 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_IO
) != 0) {
1503 Command
|= EFI_PCI_COMMAND_IO_SPACE
;
1506 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_MEMORY
) != 0) {
1507 Command
|= EFI_PCI_COMMAND_MEMORY_SPACE
;
1510 if ((Attributes
& EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
) != 0) {
1511 Command
|= EFI_PCI_COMMAND_BUS_MASTER
;
1514 // The upstream bridge should be also set to revelant attribute
1515 // expect for IO, Mem and BusMaster
1517 UpStreamAttributes
= Attributes
&
1518 (~(EFI_PCI_IO_ATTRIBUTE_IO
|
1519 EFI_PCI_IO_ATTRIBUTE_MEMORY
|
1520 EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
1523 UpStreamBridge
= PciIoDevice
->Parent
;
1525 if (Operation
== EfiPciIoAttributeOperationEnable
) {
1527 // Enable relevant attributes to command register and bridge control register
1529 Status
= PCI_ENABLE_COMMAND_REGISTER (PciIoDevice
, Command
);
1530 if (BridgeControl
!= 0) {
1531 Status
= PCI_ENABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, BridgeControl
);
1534 PciIoDevice
->Attributes
|= Attributes
;
1537 // Enable attributes of the upstream bridge
1539 Status
= UpStreamBridge
->PciIo
.Attributes (
1540 &(UpStreamBridge
->PciIo
),
1541 EfiPciIoAttributeOperationEnable
,
1548 // Disable relevant attributes to command register and bridge control register
1550 Status
= PCI_DISABLE_COMMAND_REGISTER (PciIoDevice
, Command
);
1551 if (BridgeControl
!= 0) {
1552 Status
= PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice
, BridgeControl
);
1555 PciIoDevice
->Attributes
&= (~Attributes
);
1556 Status
= EFI_SUCCESS
;
1560 if (EFI_ERROR (Status
)) {
1561 ReportErrorStatusCode (PciIoDevice
, EFI_IO_BUS_PCI
| EFI_IOB_EC_CONTROLLER_ERROR
);
1568 Gets the attributes that this PCI controller supports setting on a BAR using
1569 SetBarAttributes(), and retrieves the list of resource descriptors for a BAR.
1571 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1572 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
1573 base address for resource range. The legal range for this field is 0..5.
1574 @param Supports A pointer to the mask of attributes that this PCI controller supports
1575 setting for this BAR with SetBarAttributes().
1576 @param Resources A pointer to the ACPI 2.0 resource descriptors that describe the current
1577 configuration of this BAR of the PCI controller.
1579 @retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI
1580 controller supports are returned in Supports. If Resources
1581 is not NULL, then the ACPI 2.0 resource descriptors that the PCI
1582 controller is currently using are returned in Resources.
1583 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
1584 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
1585 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to allocate
1591 PciIoGetBarAttributes (
1592 IN EFI_PCI_IO_PROTOCOL
* This
,
1594 OUT UINT64
*Supports
, OPTIONAL
1595 OUT VOID
**Resources OPTIONAL
1599 UINT8
*Configuration
;
1601 PCI_IO_DEVICE
*PciIoDevice
;
1602 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Ptr
;
1603 EFI_ACPI_END_TAG_DESCRIPTOR
*PtrEnd
;
1607 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1609 if (Supports
== NULL
&& Resources
== NULL
) {
1610 return EFI_INVALID_PARAMETER
;
1613 if (BarIndex
>= PCI_MAX_BAR
) {
1614 return EFI_UNSUPPORTED
;
1618 // This driver does not support modifications to the WRITE_COMBINE or
1619 // CACHED attributes for BAR ranges.
1621 if (Supports
!= NULL
) {
1622 *Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1625 if (Resources
!= NULL
) {
1627 if (PciIoDevice
->PciBar
[BarIndex
].BarType
!= PciBarTypeUnknown
) {
1631 Configuration
= AllocateZeroPool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * NumConfig
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
));
1632 if (Configuration
== NULL
) {
1633 return EFI_OUT_OF_RESOURCES
;
1636 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) Configuration
;
1638 if (NumConfig
== 1) {
1639 Ptr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
1640 Ptr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) - 3;
1642 Ptr
->AddrRangeMin
= PciIoDevice
->PciBar
[BarIndex
].BaseAddress
;
1643 Ptr
->AddrLen
= PciIoDevice
->PciBar
[BarIndex
].Length
;
1644 Ptr
->AddrRangeMax
= PciIoDevice
->PciBar
[BarIndex
].Alignment
;
1646 switch (PciIoDevice
->PciBar
[BarIndex
].BarType
) {
1647 case PciBarTypeIo16
:
1648 case PciBarTypeIo32
:
1652 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_IO
;
1655 case PciBarTypeMem32
:
1659 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1663 Ptr
->AddrSpaceGranularity
= 32;
1666 case PciBarTypePMem32
:
1670 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1674 Ptr
->SpecificFlag
= 0x6;
1678 Ptr
->AddrSpaceGranularity
= 32;
1681 case PciBarTypeMem64
:
1685 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1689 Ptr
->AddrSpaceGranularity
= 64;
1692 case PciBarTypePMem64
:
1696 Ptr
->ResType
= ACPI_ADDRESS_SPACE_TYPE_MEM
;
1700 Ptr
->SpecificFlag
= 0x6;
1704 Ptr
->AddrSpaceGranularity
= 64;
1711 Ptr
= (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*) ((UINT8
*) Ptr
+ sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
));
1717 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) ((UINT8
*) Ptr
);
1718 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
1719 PtrEnd
->Checksum
= 0;
1721 *Resources
= Configuration
;
1728 Sets the attributes for a range of a BAR on a PCI controller.
1730 @param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
1731 @param Attributes The mask of attributes to set for the resource range specified by
1732 BarIndex, Offset, and Length.
1733 @param BarIndex The BAR index of the standard PCI Configuration header to use as the
1734 base address for resource range. The legal range for this field is 0..5.
1735 @param Offset A pointer to the BAR relative base address of the resource range to be
1736 modified by the attributes specified by Attributes.
1737 @param Length A pointer to the length of the resource range to be modified by the
1738 attributes specified by Attributes.
1740 @retval EFI_SUCCESS The set of attributes specified by Attributes for the resource
1741 range specified by BarIndex, Offset, and Length were
1742 set on the PCI controller, and the actual resource range is returned
1743 in Offset and Length.
1744 @retval EFI_INVALID_PARAMETER Offset or Length is NULL.
1745 @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
1746 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the attributes on the
1747 resource range specified by BarIndex, Offset, and
1753 PciIoSetBarAttributes (
1754 IN EFI_PCI_IO_PROTOCOL
*This
,
1755 IN UINT64 Attributes
,
1757 IN OUT UINT64
*Offset
,
1758 IN OUT UINT64
*Length
1762 PCI_IO_DEVICE
*PciIoDevice
;
1763 UINT64 NonRelativeOffset
;
1766 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_IO_THIS (This
);
1769 // Make sure Offset and Length are not NULL
1771 if (Offset
== NULL
|| Length
== NULL
) {
1772 return EFI_INVALID_PARAMETER
;
1775 if (PciIoDevice
->PciBar
[BarIndex
].BarType
== PciBarTypeUnknown
) {
1776 return EFI_UNSUPPORTED
;
1779 // This driver does not support setting the WRITE_COMBINE or the CACHED attributes.
1780 // If Attributes is not 0, then return EFI_UNSUPPORTED.
1782 Supports
= PciIoDevice
->Supports
& EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED
& EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE
;
1784 if (Attributes
!= (Attributes
& Supports
)) {
1785 return EFI_UNSUPPORTED
;
1788 // Attributes must be supported. Make sure the BAR range describd by BarIndex, Offset, and
1789 // Length are valid for this PCI device.
1791 NonRelativeOffset
= *Offset
;
1792 Status
= PciIoVerifyBarAccess (
1800 if (EFI_ERROR (Status
)) {
1801 return EFI_UNSUPPORTED
;
1808 Program parent bridge's attribute recurrently.
1810 @param PciIoDevice Child Pci device instance
1811 @param Operation The operation to perform on the attributes for this PCI controller.
1812 @param Attributes The mask of attributes that are used for Set, Enable, and Disable
1815 @retval EFI_SUCCESS The operation on the PCI controller's attributes was completed.
1816 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1817 @retval EFI_UNSUPPORTED one or more of the bits set in
1818 Attributes are not supported by this PCI controller or one of
1819 its parent bridges when Operation is Set, Enable or Disable.
1823 UpStreamBridgesAttributes (
1824 IN PCI_IO_DEVICE
*PciIoDevice
,
1825 IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
,
1826 IN UINT64 Attributes
1829 PCI_IO_DEVICE
*Parent
;
1830 EFI_PCI_IO_PROTOCOL
*PciIo
;
1832 Parent
= PciIoDevice
->Parent
;
1834 while (Parent
!= NULL
&& IS_PCI_BRIDGE (&Parent
->Pci
)) {
1837 // Get the PciIo Protocol
1839 PciIo
= &Parent
->PciIo
;
1841 PciIo
->Attributes (PciIo
, Operation
, Attributes
, NULL
);
1843 Parent
= Parent
->Parent
;
1850 Test whether two Pci devices has same parent bridge.
1852 @param PciDevice1 The first pci device for testing.
1853 @param PciDevice2 The second pci device for testing.
1855 @retval TRUE Two Pci device has the same parent bridge.
1856 @retval FALSE Two Pci device has not the same parent bridge.
1860 PciDevicesOnTheSamePath (
1861 IN PCI_IO_DEVICE
*PciDevice1
,
1862 IN PCI_IO_DEVICE
*PciDevice2
1868 if (PciDevice1
->Parent
== PciDevice2
->Parent
) {
1872 Existed1
= PciDeviceExisted (PciDevice1
->Parent
, PciDevice2
);
1873 Existed2
= PciDeviceExisted (PciDevice2
->Parent
, PciDevice1
);
1875 return (BOOLEAN
) (Existed1
|| Existed2
);