]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Misc.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / Misc.c
CommitLineData
3eb9473e 1/*++\r
2\r
5d36285d 3Copyright (c) 2004 - 2009, Intel Corporation \r
3eb9473e 4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 misc.c\r
15\r
16Abstract:\r
17 \r
18--*/\r
19\r
20#include "Tiano.h"\r
21#include "pei.h"\r
22#include "cpuio.h"\r
23#include "pcicfg.h"\r
24#include "pcicfg2.h"\r
25#include EFI_PROTOCOL_CONSUMER (PciRootBridgeIo)\r
26\r
27//\r
28// Modular variable used by common libiary in PEI phase\r
29//\r
30EFI_GUID mPeiCpuIoPpiGuid = PEI_CPU_IO_PPI_GUID;\r
31#if (PI_SPECIFICATION_VERSION < 0x00010000)\r
32EFI_GUID mPeiPciCfgPpiGuid = PEI_PCI_CFG_PPI_GUID;\r
33PEI_PCI_CFG_PPI *PciCfgPpi = NULL;\r
34#else\r
35EFI_GUID mPeiPciCfgPpiGuid = EFI_PEI_PCI_CFG2_PPI_GUID;\r
36EFI_PEI_PCI_CFG2_PPI *PciCfgPpi = NULL;\r
37#endif\r
38EFI_PEI_SERVICES **mPeiServices = NULL;\r
39PEI_CPU_IO_PPI *CpuIoPpi = NULL;\r
40\r
41//\r
42// Modular variable used by common libiary in DXE phase\r
43//\r
44EFI_SYSTEM_TABLE *mST = NULL;\r
45EFI_BOOT_SERVICES *mBS = NULL;\r
46EFI_RUNTIME_SERVICES *mRT = NULL;\r
47\r
48EFI_STATUS\r
49EfiInitializeCommonDriverLib (\r
50 IN EFI_HANDLE ImageHandle,\r
51 IN VOID *SystemTable\r
52 )\r
53/*++\r
54\r
55Routine Description:\r
56\r
57 Initialize lib function calling phase: PEI or DXE\r
58 \r
59Arguments:\r
60\r
61 ImageHandle - The firmware allocated handle for the EFI image.\r
62 \r
63 SystemTable - A pointer to the EFI System Table.\r
64\r
65Returns: \r
66\r
67 EFI_STATUS always returns EFI_SUCCESS\r
68\r
69--*/\r
70{\r
71 EFI_STATUS Status;\r
72\r
73 mPeiServices = NULL;\r
74 CpuIoPpi = NULL;\r
75 PciCfgPpi = NULL;\r
76\r
77 if (ImageHandle == NULL) {\r
78 //\r
79 // The function is called in PEI phase, use PEI interfaces\r
80 //\r
81 mPeiServices = (EFI_PEI_SERVICES **) SystemTable;\r
82 ASSERT (mPeiServices == NULL);\r
83\r
84 CpuIoPpi = (**mPeiServices).CpuIo;\r
85 PciCfgPpi = (**mPeiServices).PciCfg;\r
86\r
87 } else {\r
88 //\r
89 // ImageHandle is not NULL. The function is called in DXE phase\r
90 //\r
91 mST = SystemTable;\r
92 ASSERT (mST != NULL);\r
93\r
94 mBS = mST->BootServices;\r
95 mRT = mST->RuntimeServices;\r
96 ASSERT (mBS != NULL);\r
97 ASSERT (mRT != NULL);\r
98\r
99 //\r
100 // Should be at EFI_D_INFO, but lets us know things are running\r
101 //\r
102 DEBUG ((EFI_D_INFO, "EfiInitializeCommonDriverLib: Started in DXE\n"));\r
103 return EFI_SUCCESS;\r
104 }\r
105\r
106 return EFI_SUCCESS;\r
107}\r
108\r
109\r
110EFI_STATUS\r
111EfiCommonIoWrite (\r
112 IN UINT8 Width,\r
113 IN UINTN Address,\r
114 IN UINTN Count,\r
115 IN OUT VOID *Buffer\r
116 )\r
117/*++\r
118\r
119Routine Description:\r
120\r
121 Io write operation.\r
122\r
123Arguments:\r
124\r
125 Width - Width of write operation\r
126 Address - Start IO address to write\r
127 Count - Write count\r
128 Buffer - Buffer to write to the address\r
129\r
130Returns: \r
131\r
132 Status code\r
133\r
134--*/\r
135{\r
136 EFI_STATUS Status;\r
137 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo;\r
138\r
139 if (mPeiServices == NULL) {\r
140 //\r
141 // The function is called in PEI phase, use PEI interfaces\r
142 //\r
143 Status = CpuIoPpi->Io.Write (\r
144 mPeiServices,\r
145 CpuIoPpi,\r
146 Width,\r
147 Address,\r
148 Count,\r
149 Buffer\r
150 );\r
151 } else {\r
152 //\r
153 // The function is called in DXE phase\r
154 //\r
155 Status = mBS->LocateProtocol (\r
156 &gEfiPciRootBridgeIoProtocolGuid,\r
157 NULL,\r
158 (VOID **) &RootBridgeIo\r
159 );\r
160 if (EFI_ERROR (Status)) {\r
161 return Status;\r
162 }\r
163\r
164 Status = RootBridgeIo->Io.Write (RootBridgeIo, Width, Address, Count, Buffer);\r
165 }\r
166\r
167 return Status;\r
168}\r
169\r
170\r
171EFI_STATUS\r
172EfiCommonIoRead (\r
173 IN UINT8 Width,\r
174 IN UINTN Address,\r
175 IN UINTN Count,\r
176 IN OUT VOID *Buffer\r
177 )\r
178/*++\r
179\r
180Routine Description:\r
181\r
182 Io read operation.\r
183\r
184Arguments:\r
185\r
186 Width - Width of read operation\r
187 Address - Start IO address to read\r
188 Count - Read count\r
189 Buffer - Buffer to store result\r
190\r
191Returns: \r
192\r
193 Status code\r
194\r
195--*/\r
196{\r
197 EFI_STATUS Status;\r
198 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo;\r
199\r
200 if (mPeiServices == NULL) {\r
201 //\r
202 // The function is called in PEI phase, use PEI interfaces\r
203 //\r
204 Status = CpuIoPpi->Io.Read (\r
205 mPeiServices,\r
206 CpuIoPpi,\r
207 Width,\r
208 Address,\r
209 Count,\r
210 Buffer\r
211 );\r
212 } else {\r
213 //\r
214 // The function is called in DXE phase\r
215 //\r
216 Status = mBS->LocateProtocol (\r
217 &gEfiPciRootBridgeIoProtocolGuid,\r
218 NULL,\r
219 (VOID **) &RootBridgeIo\r
220 );\r
221 if (EFI_ERROR (Status)) {\r
222 return Status;\r
223 }\r
224\r
225 Status = RootBridgeIo->Io.Read (RootBridgeIo, Width, Address, Count, Buffer);\r
226 }\r
227\r
228 return Status;\r
229}\r
230\r
231\r
232EFI_STATUS\r
233EfiCommonPciWrite (\r
234 IN UINT8 Width,\r
235 IN UINT64 Address,\r
236 IN UINTN Count,\r
237 IN OUT VOID *Buffer\r
238 )\r
239/*++\r
240\r
241Routine Description:\r
242\r
243 Pci write operation\r
244\r
245Arguments:\r
246\r
247 Width - Width of PCI write\r
248 Address - PCI address to write\r
249 Count - Write count\r
250 Buffer - Buffer to write to the address\r
251\r
252Returns: \r
253\r
254 Status code\r
255\r
256--*/\r
257{\r
258 EFI_STATUS Status;\r
259 UINTN Index;\r
260 UINT8 *Buffer8;\r
261 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo;\r
262\r
263 if (mPeiServices == NULL) {\r
264 //\r
265 // The function is called in PEI phase, use PEI interfaces\r
266 //\r
267 Buffer8 = Buffer;\r
268 for (Index = 0; Index < Count; Index++) {\r
269 Status = PciCfgPpi->Write (\r
270 mPeiServices,\r
271 PciCfgPpi,\r
272 Width,\r
273 Address,\r
274 Buffer8\r
275 );\r
276\r
277 if (EFI_ERROR (Status)) {\r
278 return Status;\r
279 }\r
280\r
281 Buffer8 += Width;\r
282 }\r
283\r
284 } else {\r
285 //\r
286 // The function is called in DXE phase\r
287 //\r
288 Status = mBS->LocateProtocol (\r
289 &gEfiPciRootBridgeIoProtocolGuid,\r
290 NULL,\r
291 (VOID **) &RootBridgeIo\r
292 );\r
293 if (EFI_ERROR (Status)) {\r
294 return Status;\r
295 }\r
296\r
297 Status = RootBridgeIo->Pci.Write (\r
298 RootBridgeIo,\r
299 Width,\r
300 Address,\r
301 Count,\r
302 Buffer\r
303 );\r
304 }\r
305\r
306 return EFI_SUCCESS;\r
307}\r
308\r
309EFI_STATUS\r
310EfiCommonPciRead (\r
311 IN UINT8 Width,\r
312 IN UINT64 Address,\r
313 IN UINTN Count,\r
314 IN OUT VOID *Buffer\r
315 )\r
316/*++\r
317\r
318Routine Description:\r
319\r
320 Pci read operation\r
321\r
322Arguments:\r
323\r
324 Width - Width of PCI read\r
325 Address - PCI address to read\r
326 Count - Read count\r
327 Buffer - Output buffer for the read\r
328\r
329Returns: \r
330\r
331 Status code\r
332\r
333--*/\r
334{\r
335 EFI_STATUS Status;\r
336 UINTN Index;\r
337 UINT8 *Buffer8;\r
338 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo;\r
339\r
5d36285d 340 if (mPeiServices != NULL) {\r
3eb9473e 341 //\r
342 // The function is called in PEI phase, use PEI interfaces\r
343 //\r
344 Buffer8 = Buffer;\r
345 for (Index = 0; Index < Count; Index++) {\r
346 Status = PciCfgPpi->Read (\r
347 mPeiServices,\r
348 PciCfgPpi,\r
349 Width,\r
350 Address,\r
351 Buffer8\r
352 );\r
353\r
354 if (EFI_ERROR (Status)) {\r
355 return Status;\r
356 }\r
357\r
358 Buffer8 += Width;\r
359 }\r
360\r
361 } else {\r
362 //\r
363 // The function is called in DXE phase\r
364 //\r
365 Status = mBS->LocateProtocol (\r
366 &gEfiPciRootBridgeIoProtocolGuid,\r
367 NULL,\r
368 (VOID **) &RootBridgeIo\r
369 );\r
370 if (EFI_ERROR (Status)) {\r
371 return Status;\r
372 }\r
373\r
374 Status = RootBridgeIo->Pci.Read (\r
375 RootBridgeIo,\r
376 Width,\r
377 Address,\r
378 Count,\r
379 Buffer\r
380 );\r
381 }\r
382\r
383 return EFI_SUCCESS;\r
384}\r