]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c
1) Add PcatSingleSegmentPciCfg2Pei in MdeModulePkg.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / PcatSingleSegmentPciCfgPei / PciCfg2.c
1 /**
2
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
8
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.
11
12 **/
13
14 #include "PciCfgInternal.h"
15
16 /**
17 @par Ppi Description:
18 The EFI_PEI_PCI_CFG2_PPI interfaces are used to abstract
19 accesses to PCI controllers behind a PCI root bridge
20 controller.
21
22 @param Read PCI read services. See the Read() function description.
23
24 @param Write PCI write services. See the Write() function description.
25
26 @param Modify PCI read-modify-write services. See the Modify() function description.
27
28 @param Segment The PCI bus segment which the specified functions will access.
29
30 **/
31 GLOBAL_REMOVE_IF_UNREFERENCED
32 EFI_PEI_PCI_CFG2_PPI gPciCfg2Ppi = {
33 PciCfg2Read,
34 PciCfg2Write,
35 PciCfg2Modify
36 };
37
38 GLOBAL_REMOVE_IF_UNREFERENCED
39 EFI_PEI_PPI_DESCRIPTOR gPciCfg2PpiList = {
40 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
41 &gEfiPciCfg2PpiGuid,
42 &gPciCfg2Ppi
43 };
44
45
46 /**
47 @par Ppi Description:
48 The EFI_PEI_PCI_CFG_PPI interfaces are used to abstract accesses to PCI
49 controllers behind a PCI root bridge controller.
50
51 @param Read PCI read services. See the Read() function description.
52
53 @param Write PCI write services. See the Write() function description.
54
55 @param Modify PCI read-modify-write services. See the Modify() function description.
56
57 @param Segment The PCI bus segment which the specified functions will access.
58
59 **/
60 GLOBAL_REMOVE_IF_UNREFERENCED
61 EFI_PEI_PCI_CFG_PPI gPciCfgPpi = {
62 PciCfgRead,
63 PciCfgWrite,
64 PciCfgModify
65 };
66
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,
71 &gPciCfgPpi
72 };
73
74 /**
75 Reads from a given location in the PCI configuration space.
76
77 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
78
79 @param This Pointer to local data for the interface.
80
81 @param Width The width of the access. Enumerated in bytes.
82 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
83
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.
86
87 @param Buffer A pointer to the buffer of data..
88
89
90 @retval EFI_SUCCESS The function completed successfully.
91
92 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
93
94 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
95 time.
96
97 **/
98 EFI_STATUS
99 EFIAPI
100 PciCfg2Read (
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,
104 IN UINT64 Address,
105 IN OUT VOID *Buffer
106 )
107 {
108 UINTN PciLibAddress;
109
110 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);
111
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);
118 } else {
119 return EFI_INVALID_PARAMETER;
120 }
121
122 return EFI_SUCCESS;
123 }
124
125 /**
126 Write to a given location in the PCI configuration space.
127
128 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
129
130 @param This Pointer to local data for the interface.
131
132 @param Width The width of the access. Enumerated in bytes.
133 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
134
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.
137
138 @param Buffer A pointer to the buffer of data..
139
140
141 @retval EFI_SUCCESS The function completed successfully.
142
143 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
144
145 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
146 time.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 PciCfg2Write (
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,
155 IN UINT64 Address,
156 IN OUT VOID *Buffer
157 )
158 {
159 UINTN PciLibAddress;
160
161 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);
162
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));
169 } else {
170 return EFI_INVALID_PARAMETER;
171 }
172
173 return EFI_SUCCESS;
174 }
175
176
177 /**
178 PCI read-modify-write operation.
179
180 @param PeiServices An indirect pointer to the PEI Services Table
181 published by the PEI Foundation.
182
183 @param This Pointer to local data for the interface.
184
185 @param Width The width of the access. Enumerated in bytes. Type
186 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
187
188 @param Address The physical address of the access.
189
190 @param SetBits Points to value to bitwise-OR with the read configuration value.
191
192 The size of the value is determined by Width.
193
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.
196
197
198 @retval EFI_SUCCESS The function completed successfully.
199
200 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
201
202 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
203 the operation at this time.
204
205 **/
206 EFI_STATUS
207 EFIAPI
208 PciCfg2Modify (
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,
212 IN UINT64 Address,
213 IN CONST VOID *SetBits,
214 IN CONST VOID *ClearBits
215 )
216 {
217 UINTN PciLibAddress;
218
219 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);
220
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));
227 } else {
228 return EFI_INVALID_PARAMETER;
229 }
230 return EFI_SUCCESS;
231 }
232
233
234 EFI_STATUS
235 EFIAPI
236 PeimInitializePciCfg (
237 IN EFI_FFS_FILE_HEADER *FfsHeader,
238 IN EFI_PEI_SERVICES **PeiServices
239 )
240 {
241 EFI_STATUS Status;
242
243 Status = EFI_SUCCESS;
244
245 if ((**PeiServices).Hdr.Revision < PEI_SERVICES_REVISION) {
246 //
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
252 // be updated as:
253 //
254 // FrameworkPeiServices = (FRAMEWORK_PEI_SERVICES **) PeiServices;
255 // (**FrameworkPeiServices).PciCfg = &mPciCfgPpi;
256 //
257 (**PeiServices).PciCfg = (EFI_PEI_PCI_CFG2_PPI *) &gPciCfgPpi;
258 } else {
259 (**PeiServices).PciCfg = &gPciCfg2Ppi;
260 }
261
262 if (!FeaturePcdGet (PcdPciCfgDisable)) {
263 Status = (**PeiServices).InstallPpi (PeiServices, &gPciCfgPpiList);
264 }
265 if (!FeaturePcdGet (PcdPciCfg2Disable)) {
266 Status = (**PeiServices).InstallPpi (PeiServices, &gPciCfg2PpiList);
267 }
268
269 return Status;
270 }