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