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.
16 #include <Ppi/PciCfg2.h>
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PciLib.h>
21 #include <Library/PeimEntryPoint.h>
23 #include <IndustryStandard\Pci.h>
26 Convert EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS to PCI_LIB_ADDRESS.
28 @param Address PCI address with
29 EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS format.
31 @return The PCI address with PCI_LIB_ADDRESS format.
36 PciCfgAddressConvert (
37 EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*Address
40 if (Address
->ExtendedRegister
== 0) {
41 return PCI_LIB_ADDRESS (Address
->Bus
, Address
->Device
, Address
->Function
, Address
->Register
);
44 return PCI_LIB_ADDRESS (Address
->Bus
, Address
->Device
, Address
->Function
, Address
->ExtendedRegister
);
48 Reads from a given location in the PCI configuration space.
50 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
52 @param This Pointer to local data for the interface.
54 @param Width The width of the access. Enumerated in bytes.
55 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
57 @param Address The physical address of the access. The format of
58 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
60 @param Buffer A pointer to the buffer of data..
63 @retval EFI_SUCCESS The function completed successfully.
65 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
67 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
74 IN CONST EFI_PEI_SERVICES
**PeiServices
,
75 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
76 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
82 Write to a given location in the PCI configuration space.
84 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
86 @param This Pointer to local data for the interface.
88 @param Width The width of the access. Enumerated in bytes.
89 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
91 @param Address The physical address of the access. The format of
92 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
94 @param Buffer A pointer to the buffer of data..
97 @retval EFI_SUCCESS The function completed successfully.
99 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
101 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
108 IN CONST EFI_PEI_SERVICES
**PeiServices
,
109 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
110 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
117 PCI read-modify-write operation.
119 @param PeiServices An indirect pointer to the PEI Services Table
120 published by the PEI Foundation.
122 @param This Pointer to local data for the interface.
124 @param Width The width of the access. Enumerated in bytes. Type
125 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
127 @param Address The physical address of the access.
129 @param SetBits Points to value to bitwise-OR with the read configuration value.
131 The size of the value is determined by Width.
133 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
134 The size of the value is determined by Width.
137 @retval EFI_SUCCESS The function completed successfully.
139 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
141 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
142 the operation at this time.
148 IN CONST EFI_PEI_SERVICES
**PeiServices
,
149 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
150 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
152 IN CONST VOID
*SetBits
,
153 IN CONST VOID
*ClearBits
159 @par Ppi Description:
160 The EFI_PEI_PCI_CFG2_PPI interfaces are used to abstract
161 accesses to PCI controllers behind a PCI root bridge
164 @param Read PCI read services. See the Read() function description.
166 @param Write PCI write services. See the Write() function description.
168 @param Modify PCI read-modify-write services. See the Modify() function description.
170 @param Segment The PCI bus segment which the specified functions will access.
173 GLOBAL_REMOVE_IF_UNREFERENCED
174 EFI_PEI_PCI_CFG2_PPI gPciCfg2Ppi
= {
180 GLOBAL_REMOVE_IF_UNREFERENCED
181 EFI_PEI_PPI_DESCRIPTOR gPciCfg2PpiList
= {
182 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
188 Reads from a given location in the PCI configuration space.
190 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
192 @param This Pointer to local data for the interface.
194 @param Width The width of the access. Enumerated in bytes.
195 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
197 @param Address The physical address of the access. The format of
198 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
200 @param Buffer A pointer to the buffer of data..
203 @retval EFI_SUCCESS The function completed successfully.
205 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
207 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
214 IN CONST EFI_PEI_SERVICES
**PeiServices
,
215 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
216 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
223 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
225 if (Width
== EfiPeiPciCfgWidthUint8
) {
226 *((UINT8
*) Buffer
) = PciRead8 (PciLibAddress
);
227 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
228 *((UINT16
*) Buffer
) = PciRead16 (PciLibAddress
);
229 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
230 *((UINT32
*) Buffer
) = PciRead32 (PciLibAddress
);
232 return EFI_INVALID_PARAMETER
;
239 Write to a given location in the PCI configuration space.
241 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
243 @param This Pointer to local data for the interface.
245 @param Width The width of the access. Enumerated in bytes.
246 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
248 @param Address The physical address of the access. The format of
249 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
251 @param Buffer A pointer to the buffer of data..
254 @retval EFI_SUCCESS The function completed successfully.
256 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
258 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
265 IN CONST EFI_PEI_SERVICES
**PeiServices
,
266 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
267 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
274 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
276 if (Width
== EfiPeiPciCfgWidthUint8
) {
277 PciWrite8 (PciLibAddress
, *((UINT8
*) Buffer
));
278 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
279 PciWrite16 (PciLibAddress
, *((UINT16
*) Buffer
));
280 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
281 PciWrite32 (PciLibAddress
, *((UINT32
*) Buffer
));
283 return EFI_INVALID_PARAMETER
;
291 PCI read-modify-write operation.
293 @param PeiServices An indirect pointer to the PEI Services Table
294 published by the PEI Foundation.
296 @param This Pointer to local data for the interface.
298 @param Width The width of the access. Enumerated in bytes. Type
299 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
301 @param Address The physical address of the access.
303 @param SetBits Points to value to bitwise-OR with the read configuration value.
305 The size of the value is determined by Width.
307 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
308 The size of the value is determined by Width.
311 @retval EFI_SUCCESS The function completed successfully.
313 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
315 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
316 the operation at this time.
322 IN CONST EFI_PEI_SERVICES
**PeiServices
,
323 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
324 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
326 IN CONST VOID
*SetBits
,
327 IN CONST VOID
*ClearBits
332 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
334 if (Width
== EfiPeiPciCfgWidthUint8
) {
335 PciAndThenOr8 (PciLibAddress
, ~(*(UINT8
*)ClearBits
), *((UINT8
*) SetBits
));
336 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
337 PciAndThenOr16 (PciLibAddress
, ~ReadUnaligned16 ((UINT16
*) ClearBits
), ReadUnaligned16 ((UINT16
*) SetBits
));
338 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
339 PciAndThenOr32 (PciLibAddress
, ~ReadUnaligned32 ((UINT32
*) ClearBits
), ReadUnaligned32 ((UINT32
*) SetBits
));
341 return EFI_INVALID_PARAMETER
;
349 PeimInitializePciCfg (
350 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
351 IN EFI_PEI_SERVICES
**PeiServices
356 ASSERT ((**PeiServices
).Hdr
.Revision
>= PEI_SERVICES_REVISION
);
358 (**PeiServices
).PciCfg
= &gPciCfg2Ppi
;
359 Status
= (**PeiServices
).InstallPpi (PeiServices
, &gPciCfg2PpiList
);