]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/PciCfgOnPciCfg2Thunk/PciCfgOnPciCfg2Thunk.c
592a571f13dbc8a53f95fcb19b021af64aa43978
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / PciCfgOnPciCfg2Thunk / PciCfgOnPciCfg2Thunk.c
1 /** @file
2 Module produce PciCfgPpi on top of PciCfgPpi2.
3
4 PIWG's PI specification replaces Inte's EFI Specification 1.10.
5 EFI_PEI_PCI_CFG_PPI defined in Inte's EFI Specification 1.10 is replaced by
6 EFI_PEI_PCI_CFG2_PPI in PI 1.0.
7 This module produces PciCfgPpi on top of PciCfgPpi2. This module is used on platform when both of
8 these two conditions are true:
9 1) Framework module is present that consumes PCI CFG AND
10 2) PI module is present that produces PCI CFG2 but not PCI CFG
11
12 The Usage of this module is rare since EDK II module IntelFrameworkModulePkg\Universal\PcatSingleSegmentPciCfgPei\PcatSingleSegmentPciCfgPei.inf
13 that produce PCI CFG2 can also produce PCI CFG by setting Pcd Feature Flag gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciCfgDisable
14 to FALSE.
15
16
17 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
18 All rights reserved. This program and the accompanying materials
19 are licensed and made available under the terms and conditions of the BSD License
20 which accompanies this distribution. The full text of the license may be found at
21 http://opensource.org/licenses/bsd-license.php
22
23 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
24 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 Module Name:
26 **/
27
28 #include <PiPei.h>
29 #include <Ppi/PciCfg.h>
30 #include <Ppi/PciCfg2.h>
31 #include <Library/DebugLib.h>
32
33 //
34 // Function Prototypes
35 //
36
37 /**
38 Reads from a given location in the PCI configuration space.
39
40 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
41
42 @param This Pointer to local data for the interface.
43
44 @param Width The width of the access. Enumerated in bytes.
45 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
46
47 @param Address The physical address of the access. The format of
48 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
49
50 @param Buffer A pointer to the buffer of data..
51
52
53 @retval EFI_SUCCESS The function completed successfully.
54
55 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
56
57 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
58 time.
59
60 **/
61 EFI_STATUS
62 EFIAPI
63 PciCfgRead (
64 IN EFI_PEI_SERVICES **PeiServices,
65 IN EFI_PEI_PCI_CFG_PPI *This,
66 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
67 IN UINT64 Address,
68 IN OUT VOID *Buffer
69 );
70
71 /**
72 Write to a given location in the PCI configuration space.
73
74 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
75
76 @param This Pointer to local data for the interface.
77
78 @param Width The width of the access. Enumerated in bytes.
79 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
80
81 @param Address The physical address of the access. The format of
82 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
83
84 @param Buffer A pointer to the buffer of data..
85
86
87 @retval EFI_SUCCESS The function completed successfully.
88
89 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
90
91 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
92 time.
93
94 **/
95 EFI_STATUS
96 EFIAPI
97 PciCfgWrite (
98 IN EFI_PEI_SERVICES **PeiServices,
99 IN EFI_PEI_PCI_CFG_PPI *This,
100 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
101 IN UINT64 Address,
102 IN OUT VOID *Buffer
103 );
104
105 /**
106 PCI read-modify-write operation.
107
108 @param PeiServices An indirect pointer to the PEI Services Table
109 published by the PEI Foundation.
110
111 @param This Pointer to local data for the interface.
112
113 @param Width The width of the access. Enumerated in bytes. Type
114 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
115
116 @param Address The physical address of the access.
117
118 @param SetBits Points to value to bitwise-OR with the read configuration value.
119 The size of the value is determined by Width.
120
121 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
122 The size of the value is determined by Width.
123
124
125 @retval EFI_SUCCESS The function completed successfully.
126
127 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
128
129 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
130 the operation at this time.
131
132 **/
133 EFI_STATUS
134 EFIAPI
135 PciCfgModify (
136 IN EFI_PEI_SERVICES **PeiServices,
137 IN EFI_PEI_PCI_CFG_PPI *This,
138 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
139 IN UINT64 Address,
140 IN UINTN SetBits,
141 IN UINTN ClearBits
142 );
143
144 //
145 // Module globals
146 //
147 EFI_PEI_PCI_CFG_PPI mPciCfgPpi = {
148 PciCfgRead,
149 PciCfgWrite,
150 PciCfgModify,
151 };
152
153 EFI_PEI_PPI_DESCRIPTOR mPpiListPciCfg = {
154 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
155 &gEfiPciCfgPpiInServiceTableGuid,
156 &mPciCfgPpi
157 };
158
159 /**
160
161 Standard PEIM entry point.
162
163 @param FfsHeadher The FFS file header
164 @param PeiServices General purpose services available to every PEIM.
165
166
167 @retval EFI_SUCCESS if the interface could be successfully
168 installed
169
170 --*/
171 EFI_STATUS
172 EFIAPI
173 PeimInitializePciCfg (
174 IN EFI_PEI_FILE_HANDLE FfsHeader,
175 IN CONST EFI_PEI_SERVICES **PeiServices
176 )
177 {
178 //
179 // Publish the PciCfgToPciCfg2 Thunk capability to other modules
180 //
181 return (*PeiServices)->InstallPpi (PeiServices, &mPpiListPciCfg);
182 }
183
184 /**
185 Reads from a given location in the PCI configuration space.
186
187 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
188
189 @param This Pointer to local data for the interface.
190
191 @param Width The width of the access. Enumerated in bytes.
192 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
193
194 @param Address The physical address of the access. The format of
195 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
196
197 @param Buffer A pointer to the buffer of data..
198
199
200 @retval EFI_SUCCESS The function completed successfully.
201
202 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
203
204 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
205 time.
206
207 **/
208 EFI_STATUS
209 EFIAPI
210 PciCfgRead (
211 IN EFI_PEI_SERVICES **PeiServices,
212 IN EFI_PEI_PCI_CFG_PPI *This,
213 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
214 IN UINT64 Address,
215 IN OUT VOID *Buffer
216 )
217 {
218 EFI_PEI_PCI_CFG2_PPI *PciCfg2;
219
220 PciCfg2 = (*PeiServices)->PciCfg;
221
222 return PciCfg2->Read ((CONST EFI_PEI_SERVICES **)PeiServices, PciCfg2, Width, Address, Buffer);
223 }
224
225
226 /**
227 Write to a given location in the PCI configuration space.
228
229 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
230
231 @param This Pointer to local data for the interface.
232
233 @param Width The width of the access. Enumerated in bytes.
234 See EFI_PEI_PCI_CFG_PPI_WIDTH above.
235
236 @param Address The physical address of the access. The format of
237 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
238
239 @param Buffer A pointer to the buffer of data..
240
241
242 @retval EFI_SUCCESS The function completed successfully.
243
244 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
245
246 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this
247 time.
248
249 **/
250 EFI_STATUS
251 EFIAPI
252 PciCfgWrite (
253 IN EFI_PEI_SERVICES **PeiServices,
254 IN EFI_PEI_PCI_CFG_PPI *This,
255 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
256 IN UINT64 Address,
257 IN OUT VOID *Buffer
258 )
259 {
260 EFI_PEI_PCI_CFG2_PPI *PciCfg2;
261
262 PciCfg2 = (*PeiServices)->PciCfg;
263
264 return PciCfg2->Write ((CONST EFI_PEI_SERVICES **)PeiServices, PciCfg2, Width, Address, Buffer);
265 }
266
267 /**
268 PCI read-modify-write operation.
269
270 @param PeiServices An indirect pointer to the PEI Services Table
271 published by the PEI Foundation.
272
273 @param This Pointer to local data for the interface.
274
275 @param Width The width of the access. Enumerated in bytes. Type
276 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
277
278 @param Address The physical address of the access.
279
280 @param SetBits Points to value to bitwise-OR with the read configuration value.
281 The size of the value is determined by Width.
282
283 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.
284 The size of the value is determined by Width.
285
286
287 @retval EFI_SUCCESS The function completed successfully.
288
289 @retval EFI_DEVICE_ERROR There was a problem with the transaction.
290
291 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting
292 the operation at this time.
293
294 **/
295 EFI_STATUS
296 EFIAPI
297 PciCfgModify (
298 IN EFI_PEI_SERVICES **PeiServices,
299 IN EFI_PEI_PCI_CFG_PPI *This,
300 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
301 IN UINT64 Address,
302 IN UINTN SetBits,
303 IN UINTN ClearBits
304 )
305 {
306 EFI_PEI_PCI_CFG2_PPI *PciCfg2;
307
308 PciCfg2 = (*PeiServices)->PciCfg;
309
310 return PciCfg2->Modify ((CONST EFI_PEI_SERVICES **)PeiServices, PciCfg2, Width, Address, &SetBits, &ClearBits);
311 }