]>
Commit | Line | Data |
---|---|---|
c98d6f47 | 1 | /** @file\r |
2 | Module produces PciCfgPpi2 on top of PciCfgPpi. It also updates the \r | |
3 | PciCfg2Ppi pointer in the EFI_PEI_SERVICES upon a installation of\r | |
4 | EcpPeiPciCfgPpi. EcpPeiPciCfgPpi is installed in a framework module which\r | |
5 | produce PciCfgPpi originally. This framework module is updated based on the \r | |
6 | following rule:\r | |
7 | Search pattern:\r | |
8 | PeiServices->PciCfg = <*>;\r | |
9 | Replace pattern:\r | |
10 | {\r | |
11 | static EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {\r | |
12 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
13 | &gEcpPeiPciCfgPpiGuid,\r | |
14 | <*>\r | |
15 | };\r | |
16 | (**PeiServices).InstallPpi (PeiServices, gEcpPeiPciCfgPpiList);\r | |
17 | }\r | |
18 | \r | |
19 | PIWG's PI specification replaces Inte's EFI Specification 1.10.\r | |
20 | EFI_PEI_PCI_CFG_PPI defined in Inte's EFI Specification 1.10 is replaced by\r | |
21 | EFI_PEI_PCI_CFG2_PPI in PI 1.0.\r | |
22 | This module produces PciCfgPpi on top of PciCfgPpi2. This module is used on platform when both of\r | |
23 | these two conditions are true:\r | |
24 | 1) Framework module present that produces PCI CFG PPI AND\r | |
25 | 2) PI module that produces PCI CFG2 is not present\r | |
4259256b | 26 | \r |
27 | Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r | |
28 | All rights reserved. This program and the accompanying materials\r | |
29 | are licensed and made available under the terms and conditions of the BSD License\r | |
30 | which accompanies this distribution. The full text of the license may be found at\r | |
31 | http://opensource.org/licenses/bsd-license.php\r | |
32 | \r | |
33 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
34 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
4259256b | 35 | \r |
c98d6f47 | 36 | **/\r |
4259256b | 37 | \r |
38 | #include <PiPei.h>\r | |
39 | #include <Ppi/PciCfg.h>\r | |
40 | #include <Ppi/PciCfg2.h>\r | |
41 | #include <Ppi/EcpPciCfg.h>\r | |
42 | #include <Library/DebugLib.h>\r | |
43 | \r | |
44 | //\r | |
c98d6f47 | 45 | // Function Prototypes \r |
4259256b | 46 | //\r |
c98d6f47 | 47 | \r |
48 | /**\r | |
49 | Notification service to be called when gEcpPeiPciCfgPpiGuid is installed.\r | |
50 | \r | |
51 | @param PeiServices Indirect reference to the PEI Services Table.\r | |
52 | @param NotifyDescriptor Address of the notification descriptor data structure. Type\r | |
53 | EFI_PEI_NOTIFY_DESCRIPTOR is defined above.\r | |
54 | @param Ppi Address of the PPI that was installed.\r | |
55 | \r | |
56 | @retval EFI_STATUS This function will install a PPI to PPI database. The status\r | |
57 | code will be the code for (*PeiServices)->InstallPpi.\r | |
58 | \r | |
59 | **/\r | |
4259256b | 60 | EFI_STATUS\r |
61 | EFIAPI\r | |
62 | EcpPciCfgPpiNotifyCallback (\r | |
63 | IN EFI_PEI_SERVICES **PeiServices,\r | |
64 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
65 | IN VOID *Ppi\r | |
66 | );\r | |
67 | \r | |
68 | //\r | |
69 | // Function Prototypes\r | |
70 | //\r | |
c98d6f47 | 71 | /**\r |
72 | Reads from a given location in the PCI configuration space.\r | |
73 | \r | |
74 | @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r | |
75 | \r | |
76 | @param This Pointer to local data for the interface.\r | |
77 | \r | |
78 | @param Width The width of the access. Enumerated in bytes.\r | |
79 | See EFI_PEI_PCI_CFG_PPI_WIDTH above.\r | |
80 | \r | |
81 | @param Address The physical address of the access. The format of\r | |
82 | the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.\r | |
83 | \r | |
84 | @param Buffer A pointer to the buffer of data..\r | |
85 | \r | |
86 | \r | |
87 | @retval EFI_SUCCESS The function completed successfully.\r | |
88 | \r | |
89 | @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r | |
90 | \r | |
91 | @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this\r | |
92 | time.\r | |
93 | \r | |
94 | **/\r | |
4259256b | 95 | EFI_STATUS\r |
96 | EFIAPI\r | |
97 | PciCfg2Read (\r | |
98 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
99 | IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r | |
100 | IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r | |
101 | IN UINT64 Address,\r | |
102 | IN OUT VOID *Buffer\r | |
103 | );\r | |
104 | \r | |
c98d6f47 | 105 | /**\r |
106 | Write to a given location in the PCI configuration space.\r | |
107 | \r | |
108 | @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r | |
109 | \r | |
110 | @param This Pointer to local data for the interface.\r | |
111 | \r | |
112 | @param Width The width of the access. Enumerated in bytes.\r | |
113 | See EFI_PEI_PCI_CFG_PPI_WIDTH above.\r | |
114 | \r | |
115 | @param Address The physical address of the access. The format of\r | |
116 | the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.\r | |
117 | \r | |
118 | @param Buffer A pointer to the buffer of data..\r | |
119 | \r | |
120 | \r | |
121 | @retval EFI_SUCCESS The function completed successfully.\r | |
122 | \r | |
123 | @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r | |
124 | \r | |
125 | @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this\r | |
126 | time.\r | |
127 | \r | |
128 | **/\r | |
4259256b | 129 | EFI_STATUS\r |
130 | EFIAPI\r | |
131 | PciCfg2Write (\r | |
132 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
133 | IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r | |
134 | IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r | |
135 | IN UINT64 Address,\r | |
136 | IN OUT VOID *Buffer\r | |
137 | );\r | |
138 | \r | |
c98d6f47 | 139 | /**\r |
140 | PCI read-modify-write operation.\r | |
141 | \r | |
142 | @param PeiServices An indirect pointer to the PEI Services Table\r | |
143 | published by the PEI Foundation.\r | |
144 | \r | |
145 | @param This Pointer to local data for the interface.\r | |
146 | \r | |
147 | @param Width The width of the access. Enumerated in bytes. Type\r | |
148 | EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().\r | |
149 | \r | |
150 | @param Address The physical address of the access.\r | |
151 | \r | |
152 | @param SetBits Points to value to bitwise-OR with the read configuration value.\r | |
153 | The size of the value is determined by Width.\r | |
154 | \r | |
155 | @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.\r | |
156 | The size of the value is determined by Width.\r | |
157 | \r | |
158 | \r | |
159 | @retval EFI_SUCCESS The function completed successfully.\r | |
160 | \r | |
161 | @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r | |
162 | \r | |
163 | @retval EFI_DEVICE_NOT_READY The device is not capable of supporting\r | |
164 | the operation at this time.\r | |
165 | \r | |
166 | **/\r | |
4259256b | 167 | EFI_STATUS\r |
168 | EFIAPI\r | |
169 | PciCfg2Modify (\r | |
170 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
171 | IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r | |
172 | IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r | |
173 | IN UINT64 Address,\r | |
174 | IN CONST VOID *SetBits,\r | |
175 | IN CONST VOID *ClearBits\r | |
176 | );\r | |
177 | \r | |
178 | //\r | |
179 | // Module globals\r | |
180 | //\r | |
181 | EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnEcpPciCfgList = {\r | |
182 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
183 | &gEcpPeiPciCfgPpiGuid,\r | |
184 | EcpPciCfgPpiNotifyCallback \r | |
185 | };\r | |
186 | \r | |
187 | EFI_PEI_PCI_CFG2_PPI mPciCfg2Ppi = {\r | |
188 | PciCfg2Read,\r | |
189 | PciCfg2Write,\r | |
190 | PciCfg2Modify,\r | |
191 | 0\r | |
192 | };\r | |
193 | \r | |
194 | EFI_PEI_PPI_DESCRIPTOR mPpiListPciCfg2 = {\r | |
195 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
196 | &gEfiPciCfg2PpiGuid,\r | |
197 | &mPciCfg2Ppi\r | |
198 | };\r | |
199 | \r | |
200 | \r | |
c98d6f47 | 201 | /**\r |
4259256b | 202 | \r |
c98d6f47 | 203 | Standard PEIM entry point.\r |
4259256b | 204 | \r |
c98d6f47 | 205 | @param FfsHeadher The FFS file header\r |
206 | @param PeiServices General purpose services available to every PEIM.\r | |
4259256b | 207 | \r |
4259256b | 208 | \r |
c98d6f47 | 209 | @retval EFI_SUCCESS if the interface could be successfully\r |
210 | installed\r | |
4259256b | 211 | \r |
212 | --*/\r | |
c98d6f47 | 213 | EFI_STATUS\r |
214 | EFIAPI\r | |
215 | PeimInitializePciCfg2 (\r | |
216 | IN EFI_FFS_FILE_HEADER *FfsHeader,\r | |
217 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
218 | )\r | |
4259256b | 219 | {\r |
220 | EFI_STATUS Status;\r | |
c98d6f47 | 221 | VOID *Ppi;\r |
222 | \r | |
223 | //\r | |
224 | // Make sure no other module has install the first instance of gEfiPciCfg2PpiGuid.\r | |
225 | //\r | |
226 | Status = (*PeiServices)->LocatePpi (PeiServices, &gEfiPciCfg2PpiGuid, 0, NULL, &Ppi);\r | |
227 | ASSERT (Status == EFI_NOT_FOUND);\r | |
4259256b | 228 | \r |
229 | //\r | |
230 | // Register a notification for ECP PCI CFG PPI\r | |
231 | //\r | |
232 | Status = (*PeiServices)->NotifyPpi (PeiServices, &mNotifyOnEcpPciCfgList);\r | |
233 | ASSERT_EFI_ERROR (Status);\r | |
234 | return Status;\r | |
235 | }\r | |
236 | \r | |
c98d6f47 | 237 | \r |
238 | /**\r | |
239 | Notification service to be called when gEcpPeiPciCfgPpiGuid is installed.\r | |
240 | \r | |
241 | @param PeiServices Indirect reference to the PEI Services Table.\r | |
242 | @param NotifyDescriptor Address of the notification descriptor data structure. Type\r | |
243 | EFI_PEI_NOTIFY_DESCRIPTOR is defined above.\r | |
244 | @param Ppi Address of the PPI that was installed.\r | |
245 | \r | |
246 | @retval EFI_STATUS This function will install a PPI to PPI database. The status\r | |
247 | code will be the code for (*PeiServices)->InstallPpi.\r | |
248 | \r | |
249 | **/\r | |
4259256b | 250 | EFI_STATUS\r |
251 | EFIAPI\r | |
252 | EcpPciCfgPpiNotifyCallback (\r | |
253 | IN EFI_PEI_SERVICES **PeiServices,\r | |
254 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
255 | IN VOID *Ppi\r | |
256 | )\r | |
257 | {\r | |
258 | //\r | |
259 | // When ECP PCI CFG PPI is installed, publish the PCI CFG2 PPI in the \r | |
260 | // PEI Services Table and the PPI database\r | |
261 | //\r | |
262 | (*PeiServices)->PciCfg = &mPciCfg2Ppi;\r | |
263 | return (*PeiServices)->InstallPpi ((CONST EFI_PEI_SERVICES **)PeiServices, &mPpiListPciCfg2);\r | |
264 | }\r | |
265 | \r | |
c98d6f47 | 266 | /**\r |
267 | Reads from a given location in the PCI configuration space.\r | |
268 | \r | |
269 | @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r | |
270 | \r | |
271 | @param This Pointer to local data for the interface.\r | |
272 | \r | |
273 | @param Width The width of the access. Enumerated in bytes.\r | |
274 | See EFI_PEI_PCI_CFG_PPI_WIDTH above.\r | |
275 | \r | |
276 | @param Address The physical address of the access. The format of\r | |
277 | the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.\r | |
278 | \r | |
279 | @param Buffer A pointer to the buffer of data..\r | |
280 | \r | |
281 | \r | |
282 | @retval EFI_SUCCESS The function completed successfully.\r | |
283 | \r | |
284 | @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r | |
285 | \r | |
286 | @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this\r | |
287 | time.\r | |
288 | \r | |
289 | **/\r | |
4259256b | 290 | EFI_STATUS\r |
291 | EFIAPI\r | |
292 | PciCfg2Read (\r | |
293 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
294 | IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r | |
295 | IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r | |
296 | IN UINT64 Address,\r | |
297 | IN OUT VOID *Buffer\r | |
298 | )\r | |
299 | {\r | |
300 | EFI_STATUS Status;\r | |
301 | EFI_PEI_PCI_CFG_PPI *PciCfg;\r | |
302 | \r | |
303 | Status = (*PeiServices)->LocatePpi (\r | |
304 | PeiServices,\r | |
305 | &gEcpPeiPciCfgPpiGuid,\r | |
306 | 0,\r | |
307 | NULL,\r | |
308 | (VOID **)&PciCfg\r | |
309 | );\r | |
310 | ASSERT_EFI_ERROR (Status);\r | |
311 | \r | |
312 | return PciCfg->Read ((EFI_PEI_SERVICES **)PeiServices, PciCfg, Width, Address, Buffer);\r | |
313 | }\r | |
314 | \r | |
c98d6f47 | 315 | /**\r |
316 | Write to a given location in the PCI configuration space.\r | |
317 | \r | |
318 | @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r | |
319 | \r | |
320 | @param This Pointer to local data for the interface.\r | |
321 | \r | |
322 | @param Width The width of the access. Enumerated in bytes.\r | |
323 | See EFI_PEI_PCI_CFG_PPI_WIDTH above.\r | |
324 | \r | |
325 | @param Address The physical address of the access. The format of\r | |
326 | the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.\r | |
327 | \r | |
328 | @param Buffer A pointer to the buffer of data..\r | |
329 | \r | |
330 | \r | |
331 | @retval EFI_SUCCESS The function completed successfully.\r | |
332 | \r | |
333 | @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r | |
334 | \r | |
335 | @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this\r | |
336 | time.\r | |
337 | \r | |
338 | **/\r | |
4259256b | 339 | EFI_STATUS\r |
340 | EFIAPI\r | |
341 | PciCfg2Write (\r | |
342 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
343 | IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r | |
344 | IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r | |
345 | IN UINT64 Address,\r | |
346 | IN OUT VOID *Buffer\r | |
347 | )\r | |
348 | {\r | |
349 | EFI_STATUS Status;\r | |
350 | EFI_PEI_PCI_CFG_PPI *PciCfg;\r | |
351 | \r | |
352 | Status = (*PeiServices)->LocatePpi (\r | |
353 | PeiServices,\r | |
354 | &gEcpPeiPciCfgPpiGuid,\r | |
355 | 0,\r | |
356 | NULL,\r | |
357 | (VOID **)&PciCfg\r | |
358 | );\r | |
359 | ASSERT_EFI_ERROR (Status);\r | |
360 | \r | |
361 | return PciCfg->Write ((EFI_PEI_SERVICES **)PeiServices, PciCfg, Width, Address, Buffer);\r | |
362 | }\r | |
363 | \r | |
c98d6f47 | 364 | /**\r |
365 | PCI read-modify-write operation.\r | |
366 | \r | |
367 | @param PeiServices An indirect pointer to the PEI Services Table\r | |
368 | published by the PEI Foundation.\r | |
369 | \r | |
370 | @param This Pointer to local data for the interface.\r | |
371 | \r | |
372 | @param Width The width of the access. Enumerated in bytes. Type\r | |
373 | EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().\r | |
374 | \r | |
375 | @param Address The physical address of the access.\r | |
376 | \r | |
377 | @param SetBits Points to value to bitwise-OR with the read configuration value.\r | |
378 | The size of the value is determined by Width.\r | |
379 | \r | |
380 | @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.\r | |
381 | The size of the value is determined by Width.\r | |
382 | \r | |
383 | \r | |
384 | @retval EFI_SUCCESS The function completed successfully.\r | |
385 | \r | |
386 | @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r | |
387 | \r | |
388 | @retval EFI_DEVICE_NOT_READY The device is not capable of supporting\r | |
389 | the operation at this time.\r | |
390 | \r | |
391 | **/\r | |
4259256b | 392 | EFI_STATUS\r |
393 | EFIAPI\r | |
394 | PciCfg2Modify (\r | |
395 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
396 | IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r | |
397 | IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r | |
398 | IN UINT64 Address,\r | |
399 | IN CONST VOID *SetBits,\r | |
400 | IN CONST VOID *ClearBits\r | |
401 | )\r | |
402 | {\r | |
403 | EFI_STATUS Status;\r | |
404 | EFI_PEI_PCI_CFG_PPI *PciCfg;\r | |
405 | \r | |
406 | Status = (*PeiServices)->LocatePpi (\r | |
407 | PeiServices,\r | |
408 | &gEcpPeiPciCfgPpiGuid,\r | |
409 | 0,\r | |
410 | NULL,\r | |
411 | (VOID **)&PciCfg\r | |
412 | );\r | |
413 | ASSERT_EFI_ERROR (Status);\r | |
414 | \r | |
415 | return PciCfg->Modify ((EFI_PEI_SERVICES **)PeiServices, PciCfg, Width, Address, *(UINTN *)SetBits, *(UINTN *)ClearBits);\r | |
416 | }\r |