]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiIoLibCpuIo/IoLib.c
Removed MdePkg usage of ModuleName: in file headers
[mirror_edk2.git] / MdePkg / Library / PeiIoLibCpuIo / IoLib.c
CommitLineData
11f43dfd 1/** @file\r
2 I/O Library.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
11f43dfd 13**/\r
14\r
15//\r
16// The package level header files this module uses\r
17//\r
18#include <PiPei.h>\r
19//\r
20// The Library classes this module consumes\r
21//\r
22#include <Library/IoLib.h>\r
23#include <Library/DebugLib.h>\r
24#include <Library/BaseLib.h>\r
25#include <Library/PeiServicesTablePointerLib.h>\r
26\r
27/**\r
28 Reads an 8-bit I/O port.\r
29\r
30 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r
31 This function must guarantee that all I/O read and write operations are\r
32 serialized.\r
33\r
34 If 8-bit I/O port operations are not supported, then ASSERT().\r
35\r
36 @param Port The I/O port to read.\r
37\r
38 @return The value read.\r
39\r
40**/\r
41UINT8\r
42EFIAPI\r
43IoRead8 (\r
44 IN UINTN Port\r
45 )\r
46{\r
47 EFI_PEI_SERVICES **PeiServices;\r
48 EFI_PEI_CPU_IO_PPI *CpuIo;\r
49\r
50 PeiServices = GetPeiServicesTablePointer ();\r
51 CpuIo = (*PeiServices)->CpuIo;\r
52 ASSERT (CpuIo != NULL);\r
53\r
54 return CpuIo->IoRead8 (PeiServices, CpuIo, (UINT64) Port);\r
55}\r
56\r
57/**\r
58 Writes an 8-bit I/O port.\r
59\r
60 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
61 and returns Value. This function must guarantee that all I/O read and write\r
62 operations are serialized.\r
63\r
64 If 8-bit I/O port operations are not supported, then ASSERT().\r
65\r
66 @param Port The I/O port to write.\r
67 @param Value The value to write to the I/O port.\r
68\r
69 @return The value written the I/O port.\r
70\r
71**/\r
72UINT8\r
73EFIAPI\r
74IoWrite8 (\r
75 IN UINTN Port,\r
76 IN UINT8 Value\r
77 )\r
78{\r
79 EFI_PEI_SERVICES **PeiServices;\r
80 EFI_PEI_CPU_IO_PPI *CpuIo;\r
81\r
82 PeiServices = GetPeiServicesTablePointer ();\r
83 CpuIo = (*PeiServices)->CpuIo;\r
84 ASSERT (CpuIo != NULL);\r
85\r
86 CpuIo->IoWrite8 (PeiServices, CpuIo, (UINT64) Port, Value);\r
87 return Value;\r
88}\r
89\r
90/**\r
91 Reads a 16-bit I/O port.\r
92\r
93 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
94 This function must guarantee that all I/O read and write operations are\r
95 serialized.\r
96\r
97 If 16-bit I/O port operations are not supported, then ASSERT().\r
98\r
99 @param Port The I/O port to read.\r
100\r
101 @return The value read.\r
102\r
103**/\r
104UINT16\r
105EFIAPI\r
106IoRead16 (\r
107 IN UINTN Port\r
108 )\r
109{\r
110 EFI_PEI_SERVICES **PeiServices;\r
111 EFI_PEI_CPU_IO_PPI *CpuIo;\r
112\r
113 PeiServices = GetPeiServicesTablePointer ();\r
114 CpuIo = (*PeiServices)->CpuIo;\r
115 ASSERT (CpuIo != NULL);\r
116 //\r
117 // Make sure Port is aligned on a 16-bit boundary.\r
118 //\r
119 ASSERT ((Port & 1) == 0);\r
120 return CpuIo->IoRead16 (PeiServices, CpuIo, (UINT64) Port);\r
121}\r
122\r
123/**\r
124 Writes a 16-bit I/O port.\r
125\r
126 Writes the 16-bit I/O port specified by Port with the value specified by Value\r
127 and returns Value. This function must guarantee that all I/O read and write\r
128 operations are serialized.\r
129\r
130 If 16-bit I/O port operations are not supported, then ASSERT().\r
131\r
132 @param Port The I/O port to write.\r
133 @param Value The value to write to the I/O port.\r
134\r
135 @return The value written the I/O port.\r
136\r
137**/\r
138UINT16\r
139EFIAPI\r
140IoWrite16 (\r
141 IN UINTN Port,\r
142 IN UINT16 Value\r
143 )\r
144{\r
145 EFI_PEI_SERVICES **PeiServices;\r
146 EFI_PEI_CPU_IO_PPI *CpuIo;\r
147\r
148 PeiServices = GetPeiServicesTablePointer ();\r
149 CpuIo = (*PeiServices)->CpuIo;\r
150 ASSERT (CpuIo != NULL);\r
151 //\r
152 // Make sure Port is aligned on a 16-bit boundary.\r
153 //\r
154 ASSERT ((Port & 1) == 0);\r
155 CpuIo->IoWrite16 (PeiServices, CpuIo, (UINT64) Port, Value);\r
156 return Value;\r
157}\r
158\r
159/**\r
160 Reads a 32-bit I/O port.\r
161\r
162 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
163 This function must guarantee that all I/O read and write operations are\r
164 serialized.\r
165\r
166 If 32-bit I/O port operations are not supported, then ASSERT().\r
167\r
168 @param Port The I/O port to read.\r
169\r
170 @return The value read.\r
171\r
172**/\r
173UINT32\r
174EFIAPI\r
175IoRead32 (\r
176 IN UINTN Port\r
177 )\r
178{\r
179 EFI_PEI_SERVICES **PeiServices;\r
180 EFI_PEI_CPU_IO_PPI *CpuIo;\r
181\r
182 PeiServices = GetPeiServicesTablePointer ();\r
183 CpuIo = (*PeiServices)->CpuIo;\r
184 ASSERT (CpuIo != NULL);\r
185 //\r
186 // Make sure Port is aligned on a 32-bit boundary.\r
187 //\r
188 ASSERT ((Port & 3) == 0);\r
189 return CpuIo->IoRead32 (PeiServices, CpuIo, (UINT64) Port);\r
190}\r
191\r
192/**\r
193 Writes a 32-bit I/O port.\r
194\r
195 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
196 and returns Value. This function must guarantee that all I/O read and write\r
197 operations are serialized.\r
198\r
199 If 32-bit I/O port operations are not supported, then ASSERT().\r
200\r
201 @param Port The I/O port to write.\r
202 @param Value The value to write to the I/O port.\r
203\r
204 @return The value written the I/O port.\r
205\r
206**/\r
207UINT32\r
208EFIAPI\r
209IoWrite32 (\r
210 IN UINTN Port,\r
211 IN UINT32 Value\r
212 )\r
213{\r
214 EFI_PEI_SERVICES **PeiServices;\r
215 EFI_PEI_CPU_IO_PPI *CpuIo;\r
216\r
217 PeiServices = GetPeiServicesTablePointer ();\r
218 CpuIo = (*PeiServices)->CpuIo;\r
219 ASSERT (CpuIo != NULL);\r
220 //\r
221 // Make sure Port is aligned on a 32-bit boundary.\r
222 //\r
223 ASSERT ((Port & 3) == 0);\r
224 CpuIo->IoWrite32 (PeiServices, CpuIo, (UINT64) Port, Value);\r
225 return Value;\r
226}\r
227\r
228/**\r
229 Reads a 64-bit I/O port.\r
230\r
231 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.\r
232 This function must guarantee that all I/O read and write operations are\r
233 serialized.\r
234\r
235 If 64-bit I/O port operations are not supported, then ASSERT().\r
236\r
237 @param Port The I/O port to read.\r
238\r
239 @return The value read.\r
240\r
241**/\r
242UINT64\r
243EFIAPI\r
244IoRead64 (\r
245 IN UINTN Port\r
246 )\r
247{\r
248 EFI_PEI_SERVICES **PeiServices;\r
249 EFI_PEI_CPU_IO_PPI *CpuIo;\r
250\r
251 PeiServices = GetPeiServicesTablePointer ();\r
252 CpuIo = (*PeiServices)->CpuIo;\r
253 ASSERT (CpuIo != NULL);\r
254 //\r
255 // Make sure Port is aligned on a 64-bit boundary.\r
256 //\r
257 ASSERT ((Port & 7) == 0);\r
258 return CpuIo->IoRead64 (PeiServices, CpuIo, (UINT64) Port);\r
259}\r
260\r
261/**\r
262 Writes a 64-bit I/O port.\r
263\r
264 Writes the 64-bit I/O port specified by Port with the value specified by Value\r
265 and returns Value. This function must guarantee that all I/O read and write\r
266 operations are serialized.\r
267\r
268 If 64-bit I/O port operations are not supported, then ASSERT().\r
269\r
270 @param Port The I/O port to write.\r
271 @param Value The value to write to the I/O port.\r
272\r
273 @return The value written the I/O port.\r
274\r
275**/\r
276UINT64\r
277EFIAPI\r
278IoWrite64 (\r
279 IN UINTN Port,\r
280 IN UINT64 Value\r
281 )\r
282{\r
283 EFI_PEI_SERVICES **PeiServices;\r
284 EFI_PEI_CPU_IO_PPI *CpuIo;\r
285\r
286 PeiServices = GetPeiServicesTablePointer ();\r
287 CpuIo = (*PeiServices)->CpuIo;\r
288 ASSERT (CpuIo != NULL);\r
289 //\r
290 // Make sure Port is aligned on a 64-bit boundary.\r
291 //\r
292 ASSERT ((Port & 7) == 0);\r
293 CpuIo->IoWrite64 (PeiServices, CpuIo, (UINT64) Port, Value);\r
294 return Value;;\r
295}\r
296\r
297/**\r
298 Reads an 8-bit MMIO register.\r
299\r
300 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r
301 returned. This function must guarantee that all MMIO read and write\r
302 operations are serialized.\r
303\r
304 If 8-bit MMIO register operations are not supported, then ASSERT().\r
305\r
306 @param Address The MMIO register to read.\r
307\r
308 @return The value read.\r
309\r
310**/\r
311UINT8\r
312EFIAPI\r
313MmioRead8 (\r
314 IN UINTN Address\r
315 )\r
316{\r
317 EFI_PEI_SERVICES **PeiServices;\r
318 EFI_PEI_CPU_IO_PPI *CpuIo;\r
319\r
320 PeiServices = GetPeiServicesTablePointer ();\r
321 CpuIo = (*PeiServices)->CpuIo;\r
322 ASSERT (CpuIo != NULL);\r
323\r
324 return CpuIo->MemRead8 (PeiServices, CpuIo, (UINT64) Address);\r
325}\r
326\r
327/**\r
328 Writes an 8-bit MMIO register.\r
329\r
330 Writes the 8-bit MMIO register specified by Address with the value specified\r
331 by Value and returns Value. This function must guarantee that all MMIO read\r
332 and write operations are serialized.\r
333\r
334 If 8-bit MMIO register operations are not supported, then ASSERT().\r
335\r
336 @param Address The MMIO register to write.\r
337 @param Value The value to write to the MMIO register.\r
338\r
339**/\r
340UINT8\r
341EFIAPI\r
342MmioWrite8 (\r
343 IN UINTN Address,\r
344 IN UINT8 Value\r
345 )\r
346{\r
347 EFI_PEI_SERVICES **PeiServices;\r
348 EFI_PEI_CPU_IO_PPI *CpuIo;\r
349\r
350 PeiServices = GetPeiServicesTablePointer ();\r
351 CpuIo = (*PeiServices)->CpuIo;\r
352 ASSERT (CpuIo != NULL);\r
353\r
354 CpuIo->MemWrite8 (PeiServices, CpuIo, (UINT64) Address, Value);\r
355 return Value;\r
356}\r
357\r
358/**\r
359 Reads a 16-bit MMIO register.\r
360\r
361 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
362 returned. This function must guarantee that all MMIO read and write\r
363 operations are serialized.\r
364\r
365 If 16-bit MMIO register operations are not supported, then ASSERT().\r
366\r
367 @param Address The MMIO register to read.\r
368\r
369 @return The value read.\r
370\r
371**/\r
372UINT16\r
373EFIAPI\r
374MmioRead16 (\r
375 IN UINTN Address\r
376 )\r
377{\r
378 EFI_PEI_SERVICES **PeiServices;\r
379 EFI_PEI_CPU_IO_PPI *CpuIo;\r
380\r
381 PeiServices = GetPeiServicesTablePointer ();\r
382 CpuIo = (*PeiServices)->CpuIo;\r
383 ASSERT (CpuIo != NULL);\r
384 //\r
385 // Make sure Address is aligned on a 16-bit boundary.\r
386 //\r
387 ASSERT ((Address & 1) == 0);\r
388 return CpuIo->MemRead16 (PeiServices, CpuIo, (UINT64) Address);\r
389\r
390}\r
391\r
392/**\r
393 Writes a 16-bit MMIO register.\r
394\r
395 Writes the 16-bit MMIO register specified by Address with the value specified\r
396 by Value and returns Value. This function must guarantee that all MMIO read\r
397 and write operations are serialized.\r
398\r
399 If 16-bit MMIO register operations are not supported, then ASSERT().\r
400\r
401 @param Address The MMIO register to write.\r
402 @param Value The value to write to the MMIO register.\r
403\r
404**/\r
405UINT16\r
406EFIAPI\r
407MmioWrite16 (\r
408 IN UINTN Address,\r
409 IN UINT16 Value\r
410 )\r
411{\r
412 EFI_PEI_SERVICES **PeiServices;\r
413 EFI_PEI_CPU_IO_PPI *CpuIo;\r
414\r
415 PeiServices = GetPeiServicesTablePointer ();\r
416 CpuIo = (*PeiServices)->CpuIo;\r
417 ASSERT (CpuIo != NULL);\r
418 //\r
419 // Make sure Address is aligned on a 16-bit boundary.\r
420 //\r
421 ASSERT ((Address & 1) == 0);\r
422 CpuIo->MemWrite16 (PeiServices, CpuIo, (UINT64) Address, Value);\r
423 return Value;\r
424}\r
425\r
426/**\r
427 Reads a 32-bit MMIO register.\r
428\r
429 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
430 returned. This function must guarantee that all MMIO read and write\r
431 operations are serialized.\r
432\r
433 If 32-bit MMIO register operations are not supported, then ASSERT().\r
434\r
435 @param Address The MMIO register to read.\r
436\r
437 @return The value read.\r
438\r
439**/\r
440UINT32\r
441EFIAPI\r
442MmioRead32 (\r
443 IN UINTN Address\r
444 )\r
445{\r
446 EFI_PEI_SERVICES **PeiServices;\r
447 EFI_PEI_CPU_IO_PPI *CpuIo;\r
448\r
449 PeiServices = GetPeiServicesTablePointer ();\r
450 CpuIo = (*PeiServices)->CpuIo;\r
451 ASSERT (CpuIo != NULL);\r
452 //\r
453 // Make sure Address is aligned on a 32-bit boundary.\r
454 //\r
455 ASSERT ((Address & 3) == 0);\r
456 return CpuIo->MemRead32 (PeiServices, CpuIo, (UINT64) Address);\r
457\r
458}\r
459\r
460/**\r
461 Writes a 32-bit MMIO register.\r
462\r
463 Writes the 32-bit MMIO register specified by Address with the value specified\r
464 by Value and returns Value. This function must guarantee that all MMIO read\r
465 and write operations are serialized.\r
466\r
467 If 32-bit MMIO register operations are not supported, then ASSERT().\r
468\r
469 @param Address The MMIO register to write.\r
470 @param Value The value to write to the MMIO register.\r
471\r
472**/\r
473UINT32\r
474EFIAPI\r
475MmioWrite32 (\r
476 IN UINTN Address,\r
477 IN UINT32 Value\r
478 )\r
479{\r
480 EFI_PEI_SERVICES **PeiServices;\r
481 EFI_PEI_CPU_IO_PPI *CpuIo;\r
482\r
483 PeiServices = GetPeiServicesTablePointer ();\r
484 CpuIo = (*PeiServices)->CpuIo;\r
485 ASSERT (CpuIo != NULL);\r
486 //\r
487 // Make sure Address is aligned on a 32-bit boundary.\r
488 //\r
489 ASSERT ((Address & 3) == 0);\r
490 CpuIo->MemWrite32 (PeiServices, CpuIo, (UINT64) Address, Value);\r
491 return Value;\r
492}\r
493\r
494/**\r
495 Reads a 64-bit MMIO register.\r
496\r
497 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
498 returned. This function must guarantee that all MMIO read and write\r
499 operations are serialized.\r
500\r
501 If 64-bit MMIO register operations are not supported, then ASSERT().\r
502\r
503 @param Address The MMIO register to read.\r
504\r
505 @return The value read.\r
506\r
507**/\r
508UINT64\r
509EFIAPI\r
510MmioRead64 (\r
511 IN UINTN Address\r
512 )\r
513{\r
514 EFI_PEI_SERVICES **PeiServices;\r
515 EFI_PEI_CPU_IO_PPI *CpuIo;\r
516\r
517 PeiServices = GetPeiServicesTablePointer ();\r
518 CpuIo = (*PeiServices)->CpuIo;\r
519 ASSERT (CpuIo != NULL);\r
520 //\r
521 // Make sure Address is aligned on a 64-bit boundary.\r
522 //\r
523 ASSERT ((Address & 7) == 0);\r
524 return CpuIo->MemRead64 (PeiServices, CpuIo, (UINT64) Address);\r
525\r
526}\r
527\r
528/**\r
529 Writes a 64-bit MMIO register.\r
530\r
531 Writes the 64-bit MMIO register specified by Address with the value specified\r
532 by Value and returns Value. This function must guarantee that all MMIO read\r
533 and write operations are serialized.\r
534\r
535 If 64-bit MMIO register operations are not supported, then ASSERT().\r
536\r
537 @param Address The MMIO register to write.\r
538 @param Value The value to write to the MMIO register.\r
539\r
540**/\r
541UINT64\r
542EFIAPI\r
543MmioWrite64 (\r
544 IN UINTN Address,\r
545 IN UINT64 Value\r
546 )\r
547{\r
548 EFI_PEI_SERVICES **PeiServices;\r
549 EFI_PEI_CPU_IO_PPI *CpuIo;\r
550\r
551 PeiServices = GetPeiServicesTablePointer ();\r
552 CpuIo = (*PeiServices)->CpuIo;\r
553 ASSERT (CpuIo != NULL);\r
554 //\r
555 // Make sure Address is aligned on a 64-bit boundary.\r
556 //\r
557 ASSERT ((Address & 7) == 0);\r
558 CpuIo->MemWrite64 (PeiServices, CpuIo, (UINT64) Address, Value);\r
559 return Value;\r
560}\r