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 Reads from a given location in the PCI configuration space.
29 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
31 @param This Pointer to local data for the interface.
33 @param Width The width of the access. Enumerated in bytes.
34 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
36 @param Address The physical address of the access. The format of
37 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
39 @param Buffer A pointer to the buffer of data..
42 @retval EFI_SUCCESS The function completed successfully.
44 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
46 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
53 IN CONST EFI_PEI_SERVICES
**PeiServices
,
54 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
55 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
61 Write to a given location in the PCI configuration space.
63 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
65 @param This Pointer to local data for the interface.
67 @param Width The width of the access. Enumerated in bytes.
68 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
70 @param Address The physical address of the access. The format of
71 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
73 @param Buffer A pointer to the buffer of data..
76 @retval EFI_SUCCESS The function completed successfully.
78 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
80 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
87 IN CONST EFI_PEI_SERVICES
**PeiServices
,
88 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
89 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
96 PCI read-modify-write operation.
98 @param PeiServices An indirect pointer to the PEI Services Table
99 published by the PEI Foundation.
101 @param This Pointer to local data for the interface.
103 @param Width The width of the access. Enumerated in bytes. Type
104 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
106 @param Address The physical address of the access.
108 @param SetBits Points to value to bitwise-OR with the read configuration value.
110 The size of the value is determined by Width.
112 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
113 The size of the value is determined by Width.
116 @retval EFI_SUCCESS The function completed successfully.
118 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
120 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
121 the operation at this time.
127 IN CONST EFI_PEI_SERVICES
**PeiServices
,
128 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
129 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
138 @par Ppi Description:
139 The EFI_PEI_PCI_CFG2_PPI interfaces are used to abstract
140 accesses to PCI controllers behind a PCI root bridge
143 @param Read PCI read services. See the Read() function description.
145 @param Write PCI write services. See the Write() function description.
147 @param Modify PCI read-modify-write services. See the Modify() function description.
149 @param Segment The PCI bus segment which the specified functions will access.
152 GLOBAL_REMOVE_IF_UNREFERENCED
153 EFI_PEI_PCI_CFG2_PPI gPciCfg2Ppi
= {
159 GLOBAL_REMOVE_IF_UNREFERENCED
160 EFI_PEI_PPI_DESCRIPTOR gPciCfg2PpiList
= {
161 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
168 Convert EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS to PCI_LIB_ADDRESS.
170 @param Address PCI address with
171 EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS format.
173 @return The PCI address with PCI_LIB_ADDRESS format.
177 PciCfgAddressConvert (
178 EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*Address
181 if (Address
->ExtendedRegister
== 0) {
182 return PCI_LIB_ADDRESS (Address
->Bus
, Address
->Device
, Address
->Function
, Address
->Register
);
185 return PCI_LIB_ADDRESS (Address
->Bus
, Address
->Device
, Address
->Function
, Address
->ExtendedRegister
);
190 Reads from a given location in the PCI configuration space.
192 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
194 @param This Pointer to local data for the interface.
196 @param Width The width of the access. Enumerated in bytes.
197 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
199 @param Address The physical address of the access. The format of
200 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
202 @param Buffer A pointer to the buffer of data..
205 @retval EFI_SUCCESS The function completed successfully.
207 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
209 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
216 IN CONST EFI_PEI_SERVICES
**PeiServices
,
217 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
218 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
225 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
227 if (Width
== EfiPeiPciCfgWidthUint8
) {
228 *((UINT8
*) Buffer
) = PciRead8 (PciLibAddress
);
229 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
230 *((UINT16
*) Buffer
) = PciRead16 (PciLibAddress
);
231 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
232 *((UINT32
*) Buffer
) = PciRead32 (PciLibAddress
);
234 return EFI_INVALID_PARAMETER
;
241 Write to a given location in the PCI configuration space.
243 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
245 @param This Pointer to local data for the interface.
247 @param Width The width of the access. Enumerated in bytes.
248 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
250 @param Address The physical address of the access. The format of
251 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
253 @param Buffer A pointer to the buffer of data..
256 @retval EFI_SUCCESS The function completed successfully.
258 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
260 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
267 IN CONST EFI_PEI_SERVICES
**PeiServices
,
268 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
269 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
276 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
278 if (Width
== EfiPeiPciCfgWidthUint8
) {
279 PciWrite8 (PciLibAddress
, *((UINT8
*) Buffer
));
280 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
281 PciWrite16 (PciLibAddress
, *((UINT16
*) Buffer
));
282 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
283 PciWrite32 (PciLibAddress
, *((UINT32
*) Buffer
));
285 return EFI_INVALID_PARAMETER
;
293 PCI read-modify-write operation.
295 @param PeiServices An indirect pointer to the PEI Services Table
296 published by the PEI Foundation.
298 @param This Pointer to local data for the interface.
300 @param Width The width of the access. Enumerated in bytes. Type
301 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
303 @param Address The physical address of the access.
305 @param SetBits Points to value to bitwise-OR with the read configuration value.
307 The size of the value is determined by Width.
309 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
310 The size of the value is determined by Width.
313 @retval EFI_SUCCESS The function completed successfully.
315 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
317 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
318 the operation at this time.
324 IN CONST EFI_PEI_SERVICES
**PeiServices
,
325 IN CONST EFI_PEI_PCI_CFG2_PPI
*This
,
326 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width
,
338 PciLibAddress
= PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS
*) &Address
);
340 if (Width
== EfiPeiPciCfgWidthUint8
) {
341 PciAndThenOr8 (PciLibAddress
, (UINT8
) (~(*(UINT8
*) ClearBits
)), *((UINT8
*) SetBits
));
342 } else if (Width
== EfiPeiPciCfgWidthUint16
) {
343 ClearValue16
= (UINT16
) (~ReadUnaligned16 ((UINT16
*) ClearBits
));
344 SetValue16
= ReadUnaligned16 ((UINT16
*) SetBits
);
345 PciAndThenOr16 (PciLibAddress
, ClearValue16
, SetValue16
);
346 } else if (Width
== EfiPeiPciCfgWidthUint32
) {
347 ClearValue32
= (UINT32
) (~ReadUnaligned32 ((UINT32
*) ClearBits
));
348 SetValue32
= ReadUnaligned32 ((UINT32
*) SetBits
);
349 PciAndThenOr32 (PciLibAddress
, ClearValue32
, SetValue32
);
351 return EFI_INVALID_PARAMETER
;
357 Module's entry function.
358 This routine will install EFI_PEI_PCI_CFG2_PPI.
360 @param FileHandle Handle of the file being invoked.
361 @param PeiServices Describes the list of possible PEI Services.
363 @return Whether success to install service.
367 PeimInitializePciCfg (
368 IN EFI_PEI_FILE_HANDLE FileHandle
,
369 IN CONST EFI_PEI_SERVICES
**PeiServices
374 ASSERT ((**PeiServices
).Hdr
.Revision
>= PEI_SERVICES_REVISION
);
376 (**(EFI_PEI_SERVICES
**)PeiServices
).PciCfg
= &gPciCfg2Ppi
;
377 Status
= (**PeiServices
).InstallPpi ((CONST EFI_PEI_SERVICES
**)PeiServices
, &gPciCfg2PpiList
);