2 PCI command register operations supporting functions implementation for PCI Bus module.
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5 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 Operate the PCI register via PciIo function interface.
20 @param PciIoDevice Pointer to instance of PCI_IO_DEVICE.
21 @param Command Operator command.
22 @param Offset The address within the PCI configuration space for the PCI controller.
23 @param Operation Type of Operation.
24 @param PtrCommand Return buffer holding old PCI command, if operation is not EFI_SET_REGISTER.
26 @return Status of PciIo operation.
31 IN PCI_IO_DEVICE
*PciIoDevice
,
35 OUT UINT16
*PtrCommand
40 EFI_PCI_IO_PROTOCOL
*PciIo
;
43 PciIo
= &PciIoDevice
->PciIo
;
45 if (Operation
!= EFI_SET_REGISTER
) {
46 Status
= PciIo
->Pci
.Read (
54 if (Operation
== EFI_GET_REGISTER
) {
55 *PtrCommand
= OldCommand
;
60 if (Operation
== EFI_ENABLE_REGISTER
) {
61 OldCommand
= (UINT16
) (OldCommand
| Command
);
62 } else if (Operation
== EFI_DISABLE_REGISTER
) {
63 OldCommand
= (UINT16
) (OldCommand
& ~(Command
));
68 return PciIo
->Pci
.Write (
78 Check the cpability supporting by given device.
80 @param PciIoDevice Pointer to instance of PCI_IO_DEVICE.
82 @retval TRUE Cpability supportted.
83 @retval FALSE Cpability not supportted.
87 PciCapabilitySupport (
88 IN PCI_IO_DEVICE
*PciIoDevice
91 if ((PciIoDevice
->Pci
.Hdr
.Status
& EFI_PCI_STATUS_CAPABILITY
) != 0) {
99 Locate capability register block per capability ID.
101 @param PciIoDevice A pointer to the PCI_IO_DEVICE.
102 @param CapId The capability ID.
103 @param Offset A pointer to the offset returned.
104 @param NextRegBlock A pointer to the next block returned.
106 @retval EFI_SUCCESS Successfuly located capability register block.
107 @retval EFI_UNSUPPORTED Pci device does not support capability.
108 @retval EFI_NOT_FOUND Pci device support but can not find register block.
112 LocateCapabilityRegBlock (
113 IN PCI_IO_DEVICE
*PciIoDevice
,
115 IN OUT UINT8
*Offset
,
116 OUT UINT8
*NextRegBlock OPTIONAL
120 UINT16 CapabilityEntry
;
124 // To check the cpability of this device supports
126 if (!PciCapabilitySupport (PciIoDevice
)) {
127 return EFI_UNSUPPORTED
;
131 CapabilityPtr
= *Offset
;
135 if (IS_CARDBUS_BRIDGE (&PciIoDevice
->Pci
)) {
137 PciIoDevice
->PciIo
.Pci
.Read (
140 EFI_PCI_CARDBUS_BRIDGE_CAPABILITY_PTR
,
146 PciIoDevice
->PciIo
.Pci
.Read (
149 PCI_CAPBILITY_POINTER_OFFSET
,
156 while ((CapabilityPtr
>= 0x40) && ((CapabilityPtr
& 0x03) == 0x00)) {
157 PciIoDevice
->PciIo
.Pci
.Read (
165 CapabilityID
= (UINT8
) CapabilityEntry
;
167 if (CapabilityID
== CapId
) {
168 *Offset
= CapabilityPtr
;
169 if (NextRegBlock
!= NULL
) {
170 *NextRegBlock
= (UINT8
) (CapabilityEntry
>> 8);
177 // Certain PCI device may incorrectly have capability pointing to itself,
178 // break to avoid dead loop.
180 if (CapabilityPtr
== (UINT8
) (CapabilityEntry
>> 8)) {
184 CapabilityPtr
= (UINT8
) (CapabilityEntry
>> 8);
187 return EFI_NOT_FOUND
;
191 Locate PciExpress capability register block per capability ID.
193 @param PciIoDevice A pointer to the PCI_IO_DEVICE.
194 @param CapId The capability ID.
195 @param Offset A pointer to the offset returned.
196 @param NextRegBlock A pointer to the next block returned.
198 @retval EFI_SUCCESS Successfuly located capability register block.
199 @retval EFI_UNSUPPORTED Pci device does not support capability.
200 @retval EFI_NOT_FOUND Pci device support but can not find register block.
204 LocatePciExpressCapabilityRegBlock (
205 IN PCI_IO_DEVICE
*PciIoDevice
,
207 IN OUT UINT32
*Offset
,
208 OUT UINT32
*NextRegBlock OPTIONAL
212 UINT32 CapabilityPtr
;
213 UINT32 CapabilityEntry
;
217 // To check the capability of this device supports
219 if (!PciIoDevice
->IsPciExp
) {
220 return EFI_UNSUPPORTED
;
224 CapabilityPtr
= *Offset
;
226 CapabilityPtr
= EFI_PCIE_CAPABILITY_BASE_OFFSET
;
229 while (CapabilityPtr
!= 0) {
231 // Mask it to DWORD alignment per PCI spec
233 CapabilityPtr
&= 0xFFC;
234 Status
= PciIoDevice
->PciIo
.Pci
.Read (
241 if (EFI_ERROR (Status
)) {
245 CapabilityID
= (UINT16
) CapabilityEntry
;
247 if (CapabilityID
== CapId
) {
248 *Offset
= CapabilityPtr
;
249 if (NextRegBlock
!= NULL
) {
250 *NextRegBlock
= (CapabilityEntry
>> 20) & 0xFFF;
256 CapabilityPtr
= (CapabilityEntry
>> 20) & 0xFFF;
259 return EFI_NOT_FOUND
;