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