3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include "PciCfgInternal.h"
18 The EFI_PEI_PCI_CFG2_PPI interfaces are used to abstract
19 accesses to PCI controllers behind a PCI root bridge
22 @param Read PCI read services. See the Read() function description.
24 @param Write PCI write services. See the Write() function description.
26 @param Modify PCI read-modify-write services. See the Modify() function description.
28 @param Segment The PCI bus segment which the specified functions will access.
31 GLOBAL_REMOVE_IF_UNREFERENCED
32 EFI_PEI_PCI_CFG2_PPI gPciCfg2Ppi
= {
38 GLOBAL_REMOVE_IF_UNREFERENCED
39 EFI_PEI_PPI_DESCRIPTOR gPciCfg2PpiList
= {
40 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
48 The EFI_PEI_PCI_CFG_PPI interfaces are used to abstract accesses to PCI
49 controllers behind a PCI root bridge controller.
51 @param Read PCI read services. See the Read() function description.
53 @param Write PCI write services. See the Write() function description.
55 @param Modify PCI read-modify-write services. See the Modify() function description.
57 @param Segment The PCI bus segment which the specified functions will access.
60 GLOBAL_REMOVE_IF_UNREFERENCED
61 EFI_PEI_PCI_CFG_PPI gPciCfgPpi
= {
67 GLOBAL_REMOVE_IF_UNREFERENCED
68 EFI_PEI_PPI_DESCRIPTOR gPciCfgPpiList
= {
69 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
70 &gEfiPciCfgPpiInServiceTableGuid
,
75 Reads from a given location in the PCI configuration space.
77 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
79 @param This Pointer to local data for the interface.
81 @param Width The width of the access. Enumerated in bytes.
82 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
84 @param Address The physical address of the access. The format of
85 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
87 @param Buffer A pointer to the buffer of data..
90 @retval EFI_SUCCESS The function completed successfully.
92 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
94 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
101 IN CONST EFI_PEI_SERVICES
**PeiServices
,
102 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
103 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
110 PciLibAddress
= COMMON_TO_PCILIB_ADDRESS (Address
);
112 if (Width
== EfiPeiPciCfgWidthUint8
) {
113 *((UINT8
*) Buffer
) = PciRead8 (PciLibAddress
);
114 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
115 *((UINT16
*) Buffer
) = PciRead16 (PciLibAddress
);
116 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
117 *((UINT32
*) Buffer
) = PciRead32 (PciLibAddress
);
119 return EFI_INVALID_PARAMETER
;
126 Write to a given location in the PCI configuration space.
128 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
130 @param This Pointer to local data for the interface.
132 @param Width The width of the access. Enumerated in bytes.
133 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
135 @param Address The physical address of the access. The format of
136 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
138 @param Buffer A pointer to the buffer of data..
141 @retval EFI_SUCCESS The function completed successfully.
143 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
145 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
152 IN CONST EFI_PEI_SERVICES
**PeiServices
,
153 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
154 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
161 PciLibAddress
= COMMON_TO_PCILIB_ADDRESS (Address
);
163 if (Width
== EfiPeiPciCfgWidthUint8
) {
164 PciWrite8 (PciLibAddress
, *((UINT8
*) Buffer
));
165 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
166 PciWrite16 (PciLibAddress
, *((UINT16
*) Buffer
));
167 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
168 PciWrite32 (PciLibAddress
, *((UINT32
*) Buffer
));
170 return EFI_INVALID_PARAMETER
;
178 PCI read-modify-write operation.
180 @param PeiServices An indirect pointer to the PEI Services Table
181 published by the PEI Foundation.
183 @param This Pointer to local data for the interface.
185 @param Width The width of the access. Enumerated in bytes. Type
186 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
188 @param Address The physical address of the access.
190 @param SetBits Points to value to bitwise-OR with the read configuration value.
192 The size of the value is determined by Width.
194 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
195 The size of the value is determined by Width.
198 @retval EFI_SUCCESS The function completed successfully.
200 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
202 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
203 the operation at this time.
209 IN CONST EFI_PEI_SERVICES
**PeiServices
,
210 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
211 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
213 IN CONST VOID
*SetBits
,
214 IN CONST VOID
*ClearBits
219 PciLibAddress
= COMMON_TO_PCILIB_ADDRESS (Address
);
221 if (Width
== EfiPeiPciCfgWidthUint8
) {
222 PciAndThenOr8 (PciLibAddress
, ~(*(UINT8
*)ClearBits
), *((UINT8
*) SetBits
));
223 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
224 PciAndThenOr16 (PciLibAddress
, ~ReadUnaligned16 ((UINT16
*) ClearBits
), ReadUnaligned16 ((UINT16
*) SetBits
));
225 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
226 PciAndThenOr32 (PciLibAddress
, ~ReadUnaligned32 ((UINT32
*) ClearBits
), ReadUnaligned32 ((UINT32
*) SetBits
));
228 return EFI_INVALID_PARAMETER
;
236 PeimInitializePciCfg (
237 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
238 IN EFI_PEI_SERVICES
**PeiServices
243 Status
= EFI_SUCCESS
;
245 if ((**PeiServices
).Hdr
.Revision
< PEI_SERVICES_REVISION
) {
247 // BugBug: Curently, the FrameworkPkg does not define
248 // FRAMEWORK_PEI_SERVICES. So, In order to install
249 // the PeiServices.PciCfg(), we casttype
250 // EFI_PEI_PCI_CFG_PPI to EFI_PEI_PCI_CFG2_PPI.
251 // After defining the FRAMEWORK_PEI_SERVICES. this should
254 // FrameworkPeiServices = (FRAMEWORK_PEI_SERVICES **) PeiServices;
255 // (**FrameworkPeiServices).PciCfg = &mPciCfgPpi;
257 (**PeiServices
).PciCfg
= (EFI_PEI_PCI_CFG2_PPI
*) &gPciCfgPpi
;
259 (**PeiServices
).PciCfg
= &gPciCfg2Ppi
;
262 if (!FeaturePcdGet (PcdPciCfgDisable
)) {
263 Status
= (**PeiServices
).InstallPpi (PeiServices
, &gPciCfgPpiList
);
265 if (!FeaturePcdGet (PcdPciCfg2Disable
)) {
266 Status
= (**PeiServices
).InstallPpi (PeiServices
, &gPciCfg2PpiList
);