2 This module implement Pci register operation interface for
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 Operate the PCI register via PciIo function interface.
22 @param PciIoDevice Pointer to instance of PCI_IO_DEVICE
23 @param Command Operator command
24 @param Offset The address within the PCI configuration space for the PCI controller.
25 @param Operation Type of Operation
26 @param PtrCommand Return buffer holding old PCI command, if operation is not EFI_SET_REGISTER
28 @return status of PciIo operation
32 IN PCI_IO_DEVICE
*PciIoDevice
,
36 OUT UINT16
*PtrCommand
41 EFI_PCI_IO_PROTOCOL
*PciIo
;
44 PciIo
= &PciIoDevice
->PciIo
;
46 if (Operation
!= EFI_SET_REGISTER
) {
55 if (Operation
== EFI_GET_REGISTER
) {
56 *PtrCommand
= OldCommand
;
61 if (Operation
== EFI_ENABLE_REGISTER
) {
62 OldCommand
= (UINT16
) (OldCommand
| Command
);
63 } else if (Operation
== EFI_DISABLE_REGISTER
) {
64 OldCommand
= (UINT16
) (OldCommand
& ~(Command
));
79 check the cpability of this device supports
81 @param PciIoDevice Pointer to instance of PCI_IO_DEVICE
84 @retval FALSE Not support
87 PciCapabilitySupport (
88 IN PCI_IO_DEVICE
*PciIoDevice
92 if (PciIoDevice
->Pci
.Hdr
.Status
& EFI_PCI_STATUS_CAPABILITY
) {
102 @param PciIoDevice - A pointer to the PCI_IO_DEVICE.
103 @param CapId - The cap ID.
104 @param Offset - A pointer to the offset.
105 @param NextRegBlock - A pointer to the next block.
107 @retval EFI_UNSUPPORTED Pci device does not support
108 @retval EFI_NOT_FOUND Pci device support but can not find register block.
109 @retval EFI_SUCCESS Success to locate capability 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
)) {
140 EFI_PCI_CARDBUS_BRIDGE_CAPABILITY_PTR
,
149 EFI_PCI_CAPABILITY_PTR
,
156 while (CapabilityPtr
> 0x3F) {
158 // Mask it to DWORD alignment per PCI spec
160 CapabilityPtr
&= 0xFC;
169 CapabilityID
= (UINT8
) CapabilityEntry
;
171 if (CapabilityID
== CapId
) {
172 *Offset
= CapabilityPtr
;
173 if (NextRegBlock
!= NULL
) {
174 *NextRegBlock
= (UINT8
) (CapabilityEntry
>> 8);
180 CapabilityPtr
= (UINT8
) (CapabilityEntry
>> 8);
183 return EFI_NOT_FOUND
;