2 Installs Single Segment Pci Configuration PPI.
4 Copyright (c) 2006 - 2007, 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.
17 #include <Ppi/PciCfg2.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/PciLib.h>
22 #include <Library/PeimEntryPoint.h>
24 #include <IndustryStandard/Pci.h>
27 Convert EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS to PCI_LIB_ADDRESS.
29 @param Address PCI address with
30 EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS format.
32 @return The PCI address with PCI_LIB_ADDRESS format.
37 PciCfgAddressConvert (
38 EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*Address
41 if (Address
->ExtendedRegister
== 0) {
42 return PCI_LIB_ADDRESS (Address
->Bus
, Address
->Device
, Address
->Function
, Address
->Register
);
45 return PCI_LIB_ADDRESS (Address
->Bus
, Address
->Device
, Address
->Function
, Address
->ExtendedRegister
);
49 Reads from a given location in the PCI configuration space.
51 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
53 @param This Pointer to local data for the interface.
55 @param Width The width of the access. Enumerated in bytes.
56 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
58 @param Address The physical address of the access. The format of
59 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
61 @param Buffer A pointer to the buffer of data..
64 @retval EFI_SUCCESS The function completed successfully.
66 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
68 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
75 IN CONST EFI_PEI_SERVICES
**PeiServices
,
76 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
77 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
83 Write to a given location in the PCI configuration space.
85 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
87 @param This Pointer to local data for the interface.
89 @param Width The width of the access. Enumerated in bytes.
90 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
92 @param Address The physical address of the access. The format of
93 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
95 @param Buffer A pointer to the buffer of data..
98 @retval EFI_SUCCESS The function completed successfully.
100 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
102 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
109 IN CONST EFI_PEI_SERVICES
**PeiServices
,
110 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
111 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
118 PCI read-modify-write operation.
120 @param PeiServices An indirect pointer to the PEI Services Table
121 published by the PEI Foundation.
123 @param This Pointer to local data for the interface.
125 @param Width The width of the access. Enumerated in bytes. Type
126 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
128 @param Address The physical address of the access.
130 @param SetBits Points to value to bitwise-OR with the read configuration value.
132 The size of the value is determined by Width.
134 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
135 The size of the value is determined by Width.
138 @retval EFI_SUCCESS The function completed successfully.
140 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
142 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
143 the operation at this time.
149 IN CONST EFI_PEI_SERVICES
**PeiServices
,
150 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
151 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
160 @par Ppi Description:
161 The EFI_PEI_PCI_CFG2_PPI interfaces are used to abstract
162 accesses to PCI controllers behind a PCI root bridge
165 @param Read PCI read services. See the Read() function description.
167 @param Write PCI write services. See the Write() function description.
169 @param Modify PCI read-modify-write services. See the Modify() function description.
171 @param Segment The PCI bus segment which the specified functions will access.
174 GLOBAL_REMOVE_IF_UNREFERENCED
175 EFI_PEI_PCI_CFG2_PPI gPciCfg2Ppi
= {
181 GLOBAL_REMOVE_IF_UNREFERENCED
182 EFI_PEI_PPI_DESCRIPTOR gPciCfg2PpiList
= {
183 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
189 Reads from a given location in the PCI configuration space.
191 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
193 @param This Pointer to local data for the interface.
195 @param Width The width of the access. Enumerated in bytes.
196 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
198 @param Address The physical address of the access. The format of
199 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
201 @param Buffer A pointer to the buffer of data..
204 @retval EFI_SUCCESS The function completed successfully.
206 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
208 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
215 IN CONST EFI_PEI_SERVICES
**PeiServices
,
216 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
217 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
224 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
226 if (Width
== EfiPeiPciCfgWidthUint8
) {
227 *((UINT8
*) Buffer
) = PciRead8 (PciLibAddress
);
228 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
229 *((UINT16
*) Buffer
) = PciRead16 (PciLibAddress
);
230 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
231 *((UINT32
*) Buffer
) = PciRead32 (PciLibAddress
);
233 return EFI_INVALID_PARAMETER
;
240 Write to a given location in the PCI configuration space.
242 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
244 @param This Pointer to local data for the interface.
246 @param Width The width of the access. Enumerated in bytes.
247 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
249 @param Address The physical address of the access. The format of
250 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
252 @param Buffer A pointer to the buffer of data..
255 @retval EFI_SUCCESS The function completed successfully.
257 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
259 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
266 IN CONST EFI_PEI_SERVICES
**PeiServices
,
267 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
268 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
275 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
277 if (Width
== EfiPeiPciCfgWidthUint8
) {
278 PciWrite8 (PciLibAddress
, *((UINT8
*) Buffer
));
279 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
280 PciWrite16 (PciLibAddress
, *((UINT16
*) Buffer
));
281 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
282 PciWrite32 (PciLibAddress
, *((UINT32
*) Buffer
));
284 return EFI_INVALID_PARAMETER
;
292 PCI read-modify-write operation.
294 @param PeiServices An indirect pointer to the PEI Services Table
295 published by the PEI Foundation.
297 @param This Pointer to local data for the interface.
299 @param Width The width of the access. Enumerated in bytes. Type
300 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
302 @param Address The physical address of the access.
304 @param SetBits Points to value to bitwise-OR with the read configuration value.
306 The size of the value is determined by Width.
308 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
309 The size of the value is determined by Width.
312 @retval EFI_SUCCESS The function completed successfully.
314 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
316 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
317 the operation at this time.
323 IN CONST EFI_PEI_SERVICES
**PeiServices
,
324 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
325 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
337 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
339 if (Width
== EfiPeiPciCfgWidthUint8
) {
340 PciAndThenOr8 (PciLibAddress
, (UINT8
) (~(*(UINT8
*) ClearBits
)), *((UINT8
*) SetBits
));
341 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
342 ClearValue16
= (UINT16
) (~ReadUnaligned16 ((UINT16
*) ClearBits
));
343 SetValue16
= ReadUnaligned16 ((UINT16
*) SetBits
);
344 PciAndThenOr16 (PciLibAddress
, ClearValue16
, SetValue16
);
345 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
346 ClearValue32
= (UINT32
) (~ReadUnaligned32 ((UINT32
*) ClearBits
));
347 SetValue32
= ReadUnaligned32 ((UINT32
*) SetBits
);
348 PciAndThenOr32 (PciLibAddress
, ClearValue32
, SetValue32
);
350 return EFI_INVALID_PARAMETER
;
358 PeimInitializePciCfg (
359 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
360 IN EFI_PEI_SERVICES
**PeiServices
365 ASSERT ((**PeiServices
).Hdr
.Revision
>= PEI_SERVICES_REVISION
);
367 (**PeiServices
).PciCfg
= &gPciCfg2Ppi
;
368 Status
= (**PeiServices
).InstallPpi ((CONST EFI_PEI_SERVICES
**)PeiServices
, &gPciCfg2PpiList
);