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