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   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
IoRead8(IN UINTN Port)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
IoWrite8(IN UINTN Port,IN UINT8 Value)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
IoRead16(IN UINTN Port)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
IoWrite16(IN UINTN Port,IN UINT16 Value)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
IoRead32(IN UINTN Port)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
IoWrite32(IN UINTN Port,IN UINT32 Value)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
IoRead64(IN UINTN Port)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
IoWrite64(IN UINTN Port,IN UINT64 Value)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
IoReadFifo8(IN UINTN Port,IN UINTN Count,OUT VOID * Buffer)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
IoWriteFifo8(IN UINTN Port,IN UINTN Count,IN VOID * Buffer)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
IoReadFifo16(IN UINTN Port,IN UINTN Count,OUT VOID * Buffer)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
IoWriteFifo16(IN UINTN Port,IN UINTN Count,IN VOID * Buffer)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
IoReadFifo32(IN UINTN Port,IN UINTN Count,OUT VOID * Buffer)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
IoWriteFifo32(IN UINTN Port,IN UINTN Count,IN VOID * Buffer)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
MmioRead8(IN UINTN Address)545 MmioRead8 (
546   IN      UINTN                     Address
547   )
548 {
549   return MmioRead8Internal (Address);
550 }
551 
552 /**
553   Writes an 8-bit MMIO register.
554 
555   Writes the 8-bit MMIO register specified by Address with the value specified
556   by Value and returns Value. This function must guarantee that all MMIO read
557   and write operations are serialized.
558 
559   If 8-bit MMIO register operations are not supported, then ASSERT().
560 
561   @param  Address The MMIO register to write.
562   @param  Value   The value to write to the MMIO register.
563 
564 **/
565 UINT8
566 EFIAPI
MmioWrite8(IN UINTN Address,IN UINT8 Value)567 MmioWrite8 (
568   IN      UINTN                     Address,
569   IN      UINT8                     Value
570   )
571 {
572   MmioWrite8Internal (Address, Value);
573   return Value;
574 }
575 
576 /**
577   Reads a 16-bit MMIO register.
578 
579   Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
580   returned. This function must guarantee that all MMIO read and write
581   operations are serialized.
582 
583   If 16-bit MMIO register operations are not supported, then ASSERT().
584 
585   @param  Address The MMIO register to read.
586 
587   @return The value read.
588 
589 **/
590 UINT16
591 EFIAPI
MmioRead16(IN UINTN Address)592 MmioRead16 (
593   IN      UINTN                     Address
594   )
595 {
596   ASSERT ((Address & 1) == 0);
597 
598   return MmioRead16Internal (Address);
599 }
600 
601 /**
602   Writes a 16-bit MMIO register.
603 
604   Writes the 16-bit MMIO register specified by Address with the value specified
605   by Value and returns Value. This function must guarantee that all MMIO read
606   and write operations are serialized.
607 
608   If 16-bit MMIO register operations are not supported, then ASSERT().
609 
610   @param  Address The MMIO register to write.
611   @param  Value   The value to write to the MMIO register.
612 
613 **/
614 UINT16
615 EFIAPI
MmioWrite16(IN UINTN Address,IN UINT16 Value)616 MmioWrite16 (
617   IN      UINTN                     Address,
618   IN      UINT16                    Value
619   )
620 {
621   ASSERT ((Address & 1) == 0);
622 
623   MmioWrite16Internal (Address, Value);
624   return Value;
625 }
626 
627 /**
628   Reads a 32-bit MMIO register.
629 
630   Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
631   returned. This function must guarantee that all MMIO read and write
632   operations are serialized.
633 
634   If 32-bit MMIO register operations are not supported, then ASSERT().
635 
636   @param  Address The MMIO register to read.
637 
638   @return The value read.
639 
640 **/
641 UINT32
642 EFIAPI
MmioRead32(IN UINTN Address)643 MmioRead32 (
644   IN      UINTN                     Address
645   )
646 {
647   ASSERT ((Address & 3) == 0);
648 
649   return MmioRead32Internal (Address);
650 }
651 
652 /**
653   Writes a 32-bit MMIO register.
654 
655   Writes the 32-bit MMIO register specified by Address with the value specified
656   by Value and returns Value. This function must guarantee that all MMIO read
657   and write operations are serialized.
658 
659   If 32-bit MMIO register operations are not supported, then ASSERT().
660 
661   @param  Address The MMIO register to write.
662   @param  Value   The value to write to the MMIO register.
663 
664 **/
665 UINT32
666 EFIAPI
MmioWrite32(IN UINTN Address,IN UINT32 Value)667 MmioWrite32 (
668   IN      UINTN                     Address,
669   IN      UINT32                    Value
670   )
671 {
672   ASSERT ((Address & 3) == 0);
673 
674   MmioWrite32Internal (Address, Value);
675   return Value;
676 }
677 
678 /**
679   Reads a 64-bit MMIO register.
680 
681   Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
682   returned. This function must guarantee that all MMIO read and write
683   operations are serialized.
684 
685   If 64-bit MMIO register operations are not supported, then ASSERT().
686 
687   @param  Address The MMIO register to read.
688 
689   @return The value read.
690 
691 **/
692 UINT64
693 EFIAPI
MmioRead64(IN UINTN Address)694 MmioRead64 (
695   IN      UINTN                     Address
696   )
697 {
698   ASSERT ((Address & 7) == 0);
699 
700   return MmioRead64Internal (Address);
701 }
702 
703 /**
704   Writes a 64-bit MMIO register.
705 
706   Writes the 64-bit MMIO register specified by Address with the value specified
707   by Value and returns Value. This function must guarantee that all MMIO read
708   and write operations are serialized.
709 
710   If 64-bit MMIO register operations are not supported, then ASSERT().
711 
712   @param  Address The MMIO register to write.
713   @param  Value   The value to write to the MMIO register.
714 
715 **/
716 UINT64
717 EFIAPI
MmioWrite64(IN UINTN Address,IN UINT64 Value)718 MmioWrite64 (
719   IN      UINTN                     Address,
720   IN      UINT64                    Value
721   )
722 {
723   ASSERT ((Address & 7) == 0);
724 
725   MmioWrite64Internal (Address, Value);
726   return Value;
727 }
728