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