]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibArmVirt.c
MdePkg/BaseIoLibIntrinsic: make BaseIoLibIntrinsic safe for ArmVirt/KVM
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibArmVirt.c
1 /** @file
2 I/O Library for ARM.
3
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
7 Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>
8
9 This program and the accompanying materials are licensed and made available
10 under the terms and conditions of the BSD License which accompanies this
11 distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php.
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 **/
18
19 #include "BaseIoLibIntrinsicInternal.h"
20
21 /**
22 Reads an 8-bit MMIO register.
23
24 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
25 returned. This function must guarantee that all MMIO read and write
26 operations are serialized.
27
28 @param Address The MMIO register to read.
29
30 @return The value read.
31
32 **/
33 UINT8
34 EFIAPI
35 MmioRead8Internal (
36 IN UINTN Address
37 );
38
39 /**
40 Writes an 8-bit MMIO register.
41
42 Writes the 8-bit MMIO register specified by Address with the value specified
43 by Value and returns Value. This function must guarantee that all MMIO read
44 and write operations are serialized.
45
46 @param Address The MMIO register to write.
47 @param Value The value to write to the MMIO register.
48
49 **/
50 VOID
51 EFIAPI
52 MmioWrite8Internal (
53 IN UINTN Address,
54 IN UINT8 Value
55 );
56
57 /**
58 Reads a 16-bit MMIO register.
59
60 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
61 returned. This function must guarantee that all MMIO read and write
62 operations are serialized.
63
64 @param Address The MMIO register to read.
65
66 @return The value read.
67
68 **/
69 UINT16
70 EFIAPI
71 MmioRead16Internal (
72 IN UINTN Address
73 );
74
75 /**
76 Writes a 16-bit MMIO register.
77
78 Writes the 16-bit MMIO register specified by Address with the value specified
79 by Value and returns Value. This function must guarantee that all MMIO read
80 and write operations are serialized.
81
82 @param Address The MMIO register to write.
83 @param Value The value to write to the MMIO register.
84
85 **/
86 VOID
87 EFIAPI
88 MmioWrite16Internal (
89 IN UINTN Address,
90 IN UINT16 Value
91 );
92
93 /**
94 Reads a 32-bit MMIO register.
95
96 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
97 returned. This function must guarantee that all MMIO read and write
98 operations are serialized.
99
100 @param Address The MMIO register to read.
101
102 @return The value read.
103
104 **/
105 UINT32
106 EFIAPI
107 MmioRead32Internal (
108 IN UINTN Address
109 );
110
111 /**
112 Writes a 32-bit MMIO register.
113
114 Writes the 32-bit MMIO register specified by Address with the value specified
115 by Value and returns Value. This function must guarantee that all MMIO read
116 and write operations are serialized.
117
118 @param Address The MMIO register to write.
119 @param Value The value to write to the MMIO register.
120
121 **/
122 VOID
123 EFIAPI
124 MmioWrite32Internal (
125 IN UINTN Address,
126 IN UINT32 Value
127 );
128
129 /**
130 Reads a 64-bit MMIO register.
131
132 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
133 returned. This function must guarantee that all MMIO read and write
134 operations are serialized.
135
136 @param Address The MMIO register to read.
137
138 @return The value read.
139
140 **/
141 UINT64
142 EFIAPI
143 MmioRead64Internal (
144 IN UINTN Address
145 );
146
147 /**
148 Writes a 64-bit MMIO register.
149
150 Writes the 64-bit MMIO register specified by Address with the value specified
151 by Value and returns Value. This function must guarantee that all MMIO read
152 and write operations are serialized.
153
154 @param Address The MMIO register to write.
155 @param Value The value to write to the MMIO register.
156
157 **/
158 VOID
159 EFIAPI
160 MmioWrite64Internal (
161 IN UINTN Address,
162 IN UINT64 Value
163 );
164
165 /**
166 Reads an 8-bit I/O port.
167
168 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
169 This function must guarantee that all I/O read and write operations are
170 serialized.
171
172 If 8-bit I/O port operations are not supported, then ASSERT().
173
174 @param Port The I/O port to read.
175
176 @return The value read.
177
178 **/
179 UINT8
180 EFIAPI
181 IoRead8 (
182 IN UINTN Port
183 )
184 {
185 ASSERT (FALSE);
186 return 0;
187 }
188
189 /**
190 Writes an 8-bit I/O port.
191
192 Writes the 8-bit I/O port specified by Port with the value specified by Value
193 and returns Value. This function must guarantee that all I/O read and write
194 operations are serialized.
195
196 If 8-bit I/O port operations are not supported, then ASSERT().
197
198 @param Port The I/O port to write.
199 @param Value The value to write to the I/O port.
200
201 @return The value written the I/O port.
202
203 **/
204 UINT8
205 EFIAPI
206 IoWrite8 (
207 IN UINTN Port,
208 IN UINT8 Value
209 )
210 {
211 ASSERT (FALSE);
212 return Value;
213 }
214
215 /**
216 Reads a 16-bit I/O port.
217
218 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
219 This function must guarantee that all I/O read and write operations are
220 serialized.
221
222 If 16-bit I/O port operations are not supported, then ASSERT().
223
224 @param Port The I/O port to read.
225
226 @return The value read.
227
228 **/
229 UINT16
230 EFIAPI
231 IoRead16 (
232 IN UINTN Port
233 )
234 {
235 ASSERT (FALSE);
236 return 0;
237 }
238
239 /**
240 Writes a 16-bit I/O port.
241
242 Writes the 16-bit I/O port specified by Port with the value specified by Value
243 and returns Value. This function must guarantee that all I/O read and write
244 operations are serialized.
245
246 If 16-bit I/O port operations are not supported, then ASSERT().
247
248 @param Port The I/O port to write.
249 @param Value The value to write to the I/O port.
250
251 @return The value written the I/O port.
252
253 **/
254 UINT16
255 EFIAPI
256 IoWrite16 (
257 IN UINTN Port,
258 IN UINT16 Value
259 )
260 {
261 ASSERT (FALSE);
262 return Value;
263 }
264
265 /**
266 Reads a 32-bit I/O port.
267
268 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
269 This function must guarantee that all I/O read and write operations are
270 serialized.
271
272 If 32-bit I/O port operations are not supported, then ASSERT().
273
274 @param Port The I/O port to read.
275
276 @return The value read.
277
278 **/
279 UINT32
280 EFIAPI
281 IoRead32 (
282 IN UINTN Port
283 )
284 {
285 ASSERT (FALSE);
286 return 0;
287 }
288
289 /**
290 Writes a 32-bit I/O port.
291
292 Writes the 32-bit I/O port specified by Port with the value specified by Value
293 and returns Value. This function must guarantee that all I/O read and write
294 operations are serialized.
295
296 If 32-bit I/O port operations are not supported, then ASSERT().
297
298 @param Port The I/O port to write.
299 @param Value The value to write to the I/O port.
300
301 @return The value written the I/O port.
302
303 **/
304 UINT32
305 EFIAPI
306 IoWrite32 (
307 IN UINTN Port,
308 IN UINT32 Value
309 )
310 {
311 ASSERT (FALSE);
312 return Value;
313 }
314
315 /**
316 Reads a 64-bit I/O port.
317
318 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
319 This function must guarantee that all I/O read and write operations are
320 serialized.
321
322 If 64-bit I/O port operations are not supported, then ASSERT().
323 If Port is not aligned on a 64-bit boundary, then ASSERT().
324
325 @param Port The I/O port to read.
326
327 @return The value read.
328
329 **/
330 UINT64
331 EFIAPI
332 IoRead64 (
333 IN UINTN Port
334 )
335 {
336 ASSERT (FALSE);
337 return 0;
338 }
339
340 /**
341 Writes a 64-bit I/O port.
342
343 Writes the 64-bit I/O port specified by Port with the value specified by Value
344 and returns Value. This function must guarantee that all I/O read and write
345 operations are serialized.
346
347 If 64-bit I/O port operations are not supported, then ASSERT().
348 If Port is not aligned on a 64-bit boundary, then ASSERT().
349
350 @param Port The I/O port to write.
351 @param Value The value to write to the I/O port.
352
353 @return The value written to the I/O port.
354
355 **/
356 UINT64
357 EFIAPI
358 IoWrite64 (
359 IN UINTN Port,
360 IN UINT64 Value
361 )
362 {
363 ASSERT (FALSE);
364 return 0;
365 }
366
367 /**
368 Reads an 8-bit I/O port fifo into a block of memory.
369
370 Reads the 8-bit I/O fifo port specified by Port.
371 The port is read Count times, and the read data is
372 stored in the provided Buffer.
373
374 This function must guarantee that all I/O read and write operations are
375 serialized.
376
377 If 8-bit I/O port operations are not supported, then ASSERT().
378
379 @param Port The I/O port to read.
380 @param Count The number of times to read I/O port.
381 @param Buffer The buffer to store the read data into.
382
383 **/
384 VOID
385 EFIAPI
386 IoReadFifo8 (
387 IN UINTN Port,
388 IN UINTN Count,
389 OUT VOID *Buffer
390 )
391 {
392 ASSERT (FALSE);
393 }
394
395 /**
396 Writes a block of memory into an 8-bit I/O port fifo.
397
398 Writes the 8-bit I/O fifo port specified by Port.
399 The port is written Count times, and the write data is
400 retrieved from the provided Buffer.
401
402 This function must guarantee that all I/O write and write operations are
403 serialized.
404
405 If 8-bit I/O port operations are not supported, then ASSERT().
406
407 @param Port The I/O port to write.
408 @param Count The number of times to write I/O port.
409 @param Buffer The buffer to retrieve the write data from.
410
411 **/
412 VOID
413 EFIAPI
414 IoWriteFifo8 (
415 IN UINTN Port,
416 IN UINTN Count,
417 IN VOID *Buffer
418 )
419 {
420 ASSERT (FALSE);
421 }
422
423 /**
424 Reads a 16-bit I/O port fifo into a block of memory.
425
426 Reads the 16-bit I/O fifo port specified by Port.
427 The port is read Count times, and the read data is
428 stored in the provided Buffer.
429
430 This function must guarantee that all I/O read and write operations are
431 serialized.
432
433 If 16-bit I/O port operations are not supported, then ASSERT().
434
435 @param Port The I/O port to read.
436 @param Count The number of times to read I/O port.
437 @param Buffer The buffer to store the read data into.
438
439 **/
440 VOID
441 EFIAPI
442 IoReadFifo16 (
443 IN UINTN Port,
444 IN UINTN Count,
445 OUT VOID *Buffer
446 )
447 {
448 ASSERT (FALSE);
449 }
450
451 /**
452 Writes a block of memory into a 16-bit I/O port fifo.
453
454 Writes the 16-bit I/O fifo port specified by Port.
455 The port is written Count times, and the write data is
456 retrieved from the provided Buffer.
457
458 This function must guarantee that all I/O write and write operations are
459 serialized.
460
461 If 16-bit I/O port operations are not supported, then ASSERT().
462
463 @param Port The I/O port to write.
464 @param Count The number of times to write I/O port.
465 @param Buffer The buffer to retrieve the write data from.
466
467 **/
468 VOID
469 EFIAPI
470 IoWriteFifo16 (
471 IN UINTN Port,
472 IN UINTN Count,
473 IN VOID *Buffer
474 )
475 {
476 ASSERT (FALSE);
477 }
478
479 /**
480 Reads a 32-bit I/O port fifo into a block of memory.
481
482 Reads the 32-bit I/O fifo port specified by Port.
483 The port is read Count times, and the read data is
484 stored in the provided Buffer.
485
486 This function must guarantee that all I/O read and write operations are
487 serialized.
488
489 If 32-bit I/O port operations are not supported, then ASSERT().
490
491 @param Port The I/O port to read.
492 @param Count The number of times to read I/O port.
493 @param Buffer The buffer to store the read data into.
494
495 **/
496 VOID
497 EFIAPI
498 IoReadFifo32 (
499 IN UINTN Port,
500 IN UINTN Count,
501 OUT VOID *Buffer
502 )
503 {
504 ASSERT (FALSE);
505 }
506
507 /**
508 Writes a block of memory into a 32-bit I/O port fifo.
509
510 Writes the 32-bit I/O fifo port specified by Port.
511 The port is written Count times, and the write data is
512 retrieved from the provided Buffer.
513
514 This function must guarantee that all I/O write and write operations are
515 serialized.
516
517 If 32-bit I/O port operations are not supported, then ASSERT().
518
519 @param Port The I/O port to write.
520 @param Count The number of times to write I/O port.
521 @param Buffer The buffer to retrieve the write data from.
522
523 **/
524 VOID
525 EFIAPI
526 IoWriteFifo32 (
527 IN UINTN Port,
528 IN UINTN Count,
529 IN VOID *Buffer
530 )
531 {
532 ASSERT (FALSE);
533 }
534
535 /**
536 Reads an 8-bit MMIO register.
537
538 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
539 returned. This function must guarantee that all MMIO read and write
540 operations are serialized.
541
542 If 8-bit MMIO register operations are not supported, then ASSERT().
543
544 @param Address The MMIO register to read.
545
546 @return The value read.
547
548 **/
549 UINT8
550 EFIAPI
551 MmioRead8 (
552 IN UINTN Address
553 )
554 {
555 return MmioRead8Internal (Address);
556 }
557
558 /**
559 Writes an 8-bit MMIO register.
560
561 Writes the 8-bit MMIO register specified by Address with the value specified
562 by Value and returns Value. This function must guarantee that all MMIO read
563 and write operations are serialized.
564
565 If 8-bit MMIO register operations are not supported, then ASSERT().
566
567 @param Address The MMIO register to write.
568 @param Value The value to write to the MMIO register.
569
570 **/
571 UINT8
572 EFIAPI
573 MmioWrite8 (
574 IN UINTN Address,
575 IN UINT8 Value
576 )
577 {
578 MmioWrite8Internal (Address, Value);
579 return Value;
580 }
581
582 /**
583 Reads a 16-bit MMIO register.
584
585 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
586 returned. This function must guarantee that all MMIO read and write
587 operations are serialized.
588
589 If 16-bit MMIO register operations are not supported, then ASSERT().
590
591 @param Address The MMIO register to read.
592
593 @return The value read.
594
595 **/
596 UINT16
597 EFIAPI
598 MmioRead16 (
599 IN UINTN Address
600 )
601 {
602 ASSERT ((Address & 1) == 0);
603
604 return MmioRead16Internal (Address);
605 }
606
607 /**
608 Writes a 16-bit MMIO register.
609
610 Writes the 16-bit MMIO register specified by Address with the value specified
611 by Value and returns Value. This function must guarantee that all MMIO read
612 and write operations are serialized.
613
614 If 16-bit MMIO register operations are not supported, then ASSERT().
615
616 @param Address The MMIO register to write.
617 @param Value The value to write to the MMIO register.
618
619 **/
620 UINT16
621 EFIAPI
622 MmioWrite16 (
623 IN UINTN Address,
624 IN UINT16 Value
625 )
626 {
627 ASSERT ((Address & 1) == 0);
628
629 MmioWrite16Internal (Address, Value);
630 return Value;
631 }
632
633 /**
634 Reads a 32-bit MMIO register.
635
636 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
637 returned. This function must guarantee that all MMIO read and write
638 operations are serialized.
639
640 If 32-bit MMIO register operations are not supported, then ASSERT().
641
642 @param Address The MMIO register to read.
643
644 @return The value read.
645
646 **/
647 UINT32
648 EFIAPI
649 MmioRead32 (
650 IN UINTN Address
651 )
652 {
653 ASSERT ((Address & 3) == 0);
654
655 return MmioRead32Internal (Address);
656 }
657
658 /**
659 Writes a 32-bit MMIO register.
660
661 Writes the 32-bit MMIO register specified by Address with the value specified
662 by Value and returns Value. This function must guarantee that all MMIO read
663 and write operations are serialized.
664
665 If 32-bit MMIO register operations are not supported, then ASSERT().
666
667 @param Address The MMIO register to write.
668 @param Value The value to write to the MMIO register.
669
670 **/
671 UINT32
672 EFIAPI
673 MmioWrite32 (
674 IN UINTN Address,
675 IN UINT32 Value
676 )
677 {
678 ASSERT ((Address & 3) == 0);
679
680 MmioWrite32Internal (Address, Value);
681 return Value;
682 }
683
684 /**
685 Reads a 64-bit MMIO register.
686
687 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
688 returned. This function must guarantee that all MMIO read and write
689 operations are serialized.
690
691 If 64-bit MMIO register operations are not supported, then ASSERT().
692
693 @param Address The MMIO register to read.
694
695 @return The value read.
696
697 **/
698 UINT64
699 EFIAPI
700 MmioRead64 (
701 IN UINTN Address
702 )
703 {
704 ASSERT ((Address & 7) == 0);
705
706 return MmioRead64Internal (Address);
707 }
708
709 /**
710 Writes a 64-bit MMIO register.
711
712 Writes the 64-bit MMIO register specified by Address with the value specified
713 by Value and returns Value. This function must guarantee that all MMIO read
714 and write operations are serialized.
715
716 If 64-bit MMIO register operations are not supported, then ASSERT().
717
718 @param Address The MMIO register to write.
719 @param Value The value to write to the MMIO register.
720
721 **/
722 UINT64
723 EFIAPI
724 MmioWrite64 (
725 IN UINTN Address,
726 IN UINT64 Value
727 )
728 {
729 ASSERT ((Address & 7) == 0);
730
731 MmioWrite64Internal (Address, Value);
732 return Value;
733 }