]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
c71f45b22ee8b022ede196b32faf08c8fac303ce
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibNoIo.c
1 /** @file
2 I/O library for non I/O read and write access (memory map I/O read and
3 write only) architecture, such as ARM and RISC-V processor.
4
5 Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
6 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
7 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
8 Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
9
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 //
15 // Include common header file for this module.
16 //
17 #include "BaseIoLibIntrinsicInternal.h"
18
19 /**
20 Reads an 8-bit I/O port.
21
22 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
23 This function must guarantee that all I/O read and write operations are
24 serialized.
25
26 If 8-bit I/O port operations are not supported, then ASSERT().
27
28 @param Port The I/O port to read.
29
30 @return The value read.
31
32 **/
33 UINT8
34 EFIAPI
35 IoRead8 (
36 IN UINTN Port
37 )
38 {
39 ASSERT (FALSE);
40 return 0;
41 }
42
43 /**
44 Writes an 8-bit I/O port.
45
46 Writes the 8-bit I/O port specified by Port with the value specified by Value
47 and returns Value. This function must guarantee that all I/O read and write
48 operations are serialized.
49
50 If 8-bit I/O port operations are not supported, then ASSERT().
51
52 @param Port The I/O port to write.
53 @param Value The value to write to the I/O port.
54
55 @return The value written the I/O port.
56
57 **/
58 UINT8
59 EFIAPI
60 IoWrite8 (
61 IN UINTN Port,
62 IN UINT8 Value
63 )
64 {
65 ASSERT (FALSE);
66 return Value;
67 }
68
69 /**
70 Reads a 16-bit I/O port.
71
72 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
73 This function must guarantee that all I/O read and write operations are
74 serialized.
75
76 If 16-bit I/O port operations are not supported, then ASSERT().
77
78 @param Port The I/O port to read.
79
80 @return The value read.
81
82 **/
83 UINT16
84 EFIAPI
85 IoRead16 (
86 IN UINTN Port
87 )
88 {
89 ASSERT (FALSE);
90 return 0;
91 }
92
93 /**
94 Writes a 16-bit I/O port.
95
96 Writes the 16-bit I/O port specified by Port with the value specified by Value
97 and returns Value. This function must guarantee that all I/O read and write
98 operations are serialized.
99
100 If 16-bit I/O port operations are not supported, then ASSERT().
101
102 @param Port The I/O port to write.
103 @param Value The value to write to the I/O port.
104
105 @return The value written the I/O port.
106
107 **/
108 UINT16
109 EFIAPI
110 IoWrite16 (
111 IN UINTN Port,
112 IN UINT16 Value
113 )
114 {
115 ASSERT (FALSE);
116 return Value;
117 }
118
119 /**
120 Reads a 32-bit I/O port.
121
122 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
123 This function must guarantee that all I/O read and write operations are
124 serialized.
125
126 If 32-bit I/O port operations are not supported, then ASSERT().
127
128 @param Port The I/O port to read.
129
130 @return The value read.
131
132 **/
133 UINT32
134 EFIAPI
135 IoRead32 (
136 IN UINTN Port
137 )
138 {
139 ASSERT (FALSE);
140 return 0;
141 }
142
143 /**
144 Writes a 32-bit I/O port.
145
146 Writes the 32-bit I/O port specified by Port with the value specified by Value
147 and returns Value. This function must guarantee that all I/O read and write
148 operations are serialized.
149
150 If 32-bit I/O port operations are not supported, then ASSERT().
151
152 @param Port The I/O port to write.
153 @param Value The value to write to the I/O port.
154
155 @return The value written the I/O port.
156
157 **/
158 UINT32
159 EFIAPI
160 IoWrite32 (
161 IN UINTN Port,
162 IN UINT32 Value
163 )
164 {
165 ASSERT (FALSE);
166 return Value;
167 }
168
169 /**
170 Reads a 64-bit I/O port.
171
172 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
173 This function must guarantee that all I/O read and write operations are
174 serialized.
175
176 If 64-bit I/O port operations are not supported, then ASSERT().
177 If Port is not aligned on a 64-bit boundary, then ASSERT().
178
179 @param Port The I/O port to read.
180
181 @return The value read.
182
183 **/
184 UINT64
185 EFIAPI
186 IoRead64 (
187 IN UINTN Port
188 )
189 {
190 ASSERT (FALSE);
191 return 0;
192 }
193
194 /**
195 Writes a 64-bit I/O port.
196
197 Writes the 64-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 64-bit I/O port operations are not supported, then ASSERT().
202 If Port is not aligned on a 64-bit boundary, then ASSERT().
203
204 @param Port The I/O port to write.
205 @param Value The value to write to the I/O port.
206
207 @return The value written to the I/O port.
208
209 **/
210 UINT64
211 EFIAPI
212 IoWrite64 (
213 IN UINTN Port,
214 IN UINT64 Value
215 )
216 {
217 ASSERT (FALSE);
218 return 0;
219 }
220
221 /**
222 Reads an 8-bit I/O port fifo into a block of memory.
223
224 Reads the 8-bit I/O fifo port specified by Port.
225 The port is read Count times, and the read data is
226 stored in the provided Buffer.
227
228 This function must guarantee that all I/O read and write operations are
229 serialized.
230
231 If 8-bit I/O port operations are not supported, then ASSERT().
232
233 @param Port The I/O port to read.
234 @param Count The number of times to read I/O port.
235 @param Buffer The buffer to store the read data into.
236
237 **/
238 VOID
239 EFIAPI
240 IoReadFifo8 (
241 IN UINTN Port,
242 IN UINTN Count,
243 OUT VOID *Buffer
244 )
245 {
246 ASSERT (FALSE);
247 }
248
249 /**
250 Writes a block of memory into an 8-bit I/O port fifo.
251
252 Writes the 8-bit I/O fifo port specified by Port.
253 The port is written Count times, and the write data is
254 retrieved from the provided Buffer.
255
256 This function must guarantee that all I/O write and write operations are
257 serialized.
258
259 If 8-bit I/O port operations are not supported, then ASSERT().
260
261 @param Port The I/O port to write.
262 @param Count The number of times to write I/O port.
263 @param Buffer The buffer to retrieve the write data from.
264
265 **/
266 VOID
267 EFIAPI
268 IoWriteFifo8 (
269 IN UINTN Port,
270 IN UINTN Count,
271 IN VOID *Buffer
272 )
273 {
274 ASSERT (FALSE);
275 }
276
277 /**
278 Reads a 16-bit I/O port fifo into a block of memory.
279
280 Reads the 16-bit I/O fifo port specified by Port.
281 The port is read Count times, and the read data is
282 stored in the provided Buffer.
283
284 This function must guarantee that all I/O read and write operations are
285 serialized.
286
287 If 16-bit I/O port operations are not supported, then ASSERT().
288
289 @param Port The I/O port to read.
290 @param Count The number of times to read I/O port.
291 @param Buffer The buffer to store the read data into.
292
293 **/
294 VOID
295 EFIAPI
296 IoReadFifo16 (
297 IN UINTN Port,
298 IN UINTN Count,
299 OUT VOID *Buffer
300 )
301 {
302 ASSERT (FALSE);
303 }
304
305 /**
306 Writes a block of memory into a 16-bit I/O port fifo.
307
308 Writes the 16-bit I/O fifo port specified by Port.
309 The port is written Count times, and the write data is
310 retrieved from the provided Buffer.
311
312 This function must guarantee that all I/O write and write operations are
313 serialized.
314
315 If 16-bit I/O port operations are not supported, then ASSERT().
316
317 @param Port The I/O port to write.
318 @param Count The number of times to write I/O port.
319 @param Buffer The buffer to retrieve the write data from.
320
321 **/
322 VOID
323 EFIAPI
324 IoWriteFifo16 (
325 IN UINTN Port,
326 IN UINTN Count,
327 IN VOID *Buffer
328 )
329 {
330 ASSERT (FALSE);
331 }
332
333 /**
334 Reads a 32-bit I/O port fifo into a block of memory.
335
336 Reads the 32-bit I/O fifo port specified by Port.
337 The port is read Count times, and the read data is
338 stored in the provided Buffer.
339
340 This function must guarantee that all I/O read and write operations are
341 serialized.
342
343 If 32-bit I/O port operations are not supported, then ASSERT().
344
345 @param Port The I/O port to read.
346 @param Count The number of times to read I/O port.
347 @param Buffer The buffer to store the read data into.
348
349 **/
350 VOID
351 EFIAPI
352 IoReadFifo32 (
353 IN UINTN Port,
354 IN UINTN Count,
355 OUT VOID *Buffer
356 )
357 {
358 ASSERT (FALSE);
359 }
360
361 /**
362 Writes a block of memory into a 32-bit I/O port fifo.
363
364 Writes the 32-bit I/O fifo port specified by Port.
365 The port is written Count times, and the write data is
366 retrieved from the provided Buffer.
367
368 This function must guarantee that all I/O write and write operations are
369 serialized.
370
371 If 32-bit I/O port operations are not supported, then ASSERT().
372
373 @param Port The I/O port to write.
374 @param Count The number of times to write I/O port.
375 @param Buffer The buffer to retrieve the write data from.
376
377 **/
378 VOID
379 EFIAPI
380 IoWriteFifo32 (
381 IN UINTN Port,
382 IN UINTN Count,
383 IN VOID *Buffer
384 )
385 {
386 ASSERT (FALSE);
387 }
388
389 /**
390 Reads an 8-bit MMIO register.
391
392 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
393 returned. This function must guarantee that all MMIO read and write
394 operations are serialized.
395
396 If 8-bit MMIO register operations are not supported, then ASSERT().
397
398 @param Address The MMIO register to read.
399
400 @return The value read.
401
402 **/
403 UINT8
404 EFIAPI
405 MmioRead8 (
406 IN UINTN Address
407 )
408 {
409 UINT8 Value;
410 BOOLEAN Flag;
411
412 Flag = FilterBeforeMmIoRead (FilterWidth8, Address, &Value);
413 if (Flag) {
414 Value = *(volatile UINT8 *)Address;
415 }
416
417 FilterAfterMmIoRead (FilterWidth8, Address, &Value);
418
419 return Value;
420 }
421
422 /**
423 Writes an 8-bit MMIO register.
424
425 Writes the 8-bit MMIO register specified by Address with the value specified
426 by Value and returns Value. This function must guarantee that all MMIO read
427 and write operations are serialized.
428
429 If 8-bit MMIO register operations are not supported, then ASSERT().
430
431 @param Address The MMIO register to write.
432 @param Value The value to write to the MMIO register.
433
434 **/
435 UINT8
436 EFIAPI
437 MmioWrite8 (
438 IN UINTN Address,
439 IN UINT8 Value
440 )
441 {
442 BOOLEAN Flag;
443
444 Flag = FilterBeforeMmIoWrite (FilterWidth8, Address, &Value);
445 if (Flag) {
446 *(volatile UINT8 *)Address = Value;
447 }
448
449 FilterAfterMmIoWrite (FilterWidth8, Address, &Value);
450
451 return Value;
452 }
453
454 /**
455 Reads a 16-bit MMIO register.
456
457 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
458 returned. This function must guarantee that all MMIO read and write
459 operations are serialized.
460
461 If 16-bit MMIO register operations are not supported, then ASSERT().
462
463 @param Address The MMIO register to read.
464
465 @return The value read.
466
467 **/
468 UINT16
469 EFIAPI
470 MmioRead16 (
471 IN UINTN Address
472 )
473 {
474 UINT16 Value;
475 BOOLEAN Flag;
476
477 ASSERT ((Address & 1) == 0);
478
479 Flag = FilterBeforeMmIoRead (FilterWidth16, Address, &Value);
480 if (Flag) {
481 Value = *(volatile UINT16 *)Address;
482 }
483
484 FilterAfterMmIoRead (FilterWidth16, Address, &Value);
485
486 return Value;
487 }
488
489 /**
490 Writes a 16-bit MMIO register.
491
492 Writes the 16-bit MMIO register specified by Address with the value specified
493 by Value and returns Value. This function must guarantee that all MMIO read
494 and write operations are serialized.
495
496 If 16-bit MMIO register operations are not supported, then ASSERT().
497
498 @param Address The MMIO register to write.
499 @param Value The value to write to the MMIO register.
500
501 **/
502 UINT16
503 EFIAPI
504 MmioWrite16 (
505 IN UINTN Address,
506 IN UINT16 Value
507 )
508 {
509 BOOLEAN Flag;
510
511 ASSERT ((Address & 1) == 0);
512
513 Flag = FilterBeforeMmIoWrite (FilterWidth16, Address, &Value);
514 if (Flag) {
515 *(volatile UINT16 *)Address = Value;
516 }
517
518 FilterAfterMmIoWrite (FilterWidth16, Address, &Value);
519
520 return Value;
521 }
522
523 /**
524 Reads a 32-bit MMIO register.
525
526 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
527 returned. This function must guarantee that all MMIO read and write
528 operations are serialized.
529
530 If 32-bit MMIO register operations are not supported, then ASSERT().
531
532 @param Address The MMIO register to read.
533
534 @return The value read.
535
536 **/
537 UINT32
538 EFIAPI
539 MmioRead32 (
540 IN UINTN Address
541 )
542 {
543 UINT32 Value;
544 BOOLEAN Flag;
545
546 ASSERT ((Address & 3) == 0);
547
548 Flag = FilterBeforeMmIoRead (FilterWidth32, Address, &Value);
549 if (Flag) {
550 Value = *(volatile UINT32 *)Address;
551 }
552
553 FilterAfterMmIoRead (FilterWidth32, Address, &Value);
554
555 return Value;
556 }
557
558 /**
559 Writes a 32-bit MMIO register.
560
561 Writes the 32-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 32-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 UINT32
572 EFIAPI
573 MmioWrite32 (
574 IN UINTN Address,
575 IN UINT32 Value
576 )
577 {
578 BOOLEAN Flag;
579
580 ASSERT ((Address & 3) == 0);
581
582 Flag = FilterBeforeMmIoWrite (FilterWidth32, Address, &Value);
583 if (Flag) {
584 *(volatile UINT32 *)Address = Value;
585 }
586
587 FilterAfterMmIoWrite (FilterWidth32, Address, &Value);
588
589 return Value;
590 }
591
592 /**
593 Reads a 64-bit MMIO register.
594
595 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
596 returned. This function must guarantee that all MMIO read and write
597 operations are serialized.
598
599 If 64-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 UINT64
607 EFIAPI
608 MmioRead64 (
609 IN UINTN Address
610 )
611 {
612 UINT64 Value;
613 BOOLEAN Flag;
614
615 ASSERT ((Address & 7) == 0);
616
617 Flag = FilterBeforeMmIoRead (FilterWidth64, Address, &Value);
618 if (Flag) {
619 Value = *(volatile UINT64 *)Address;
620 }
621
622 FilterAfterMmIoRead (FilterWidth64, Address, &Value);
623
624 return Value;
625 }
626
627 /**
628 Writes a 64-bit MMIO register.
629
630 Writes the 64-bit MMIO register specified by Address with the value specified
631 by Value and returns Value. This function must guarantee that all MMIO read
632 and write operations are serialized.
633
634 If 64-bit MMIO register operations are not supported, then ASSERT().
635
636 @param Address The MMIO register to write.
637 @param Value The value to write to the MMIO register.
638
639 **/
640 UINT64
641 EFIAPI
642 MmioWrite64 (
643 IN UINTN Address,
644 IN UINT64 Value
645 )
646 {
647 BOOLEAN Flag;
648
649 ASSERT ((Address & 7) == 0);
650
651 Flag = FilterBeforeMmIoWrite (FilterWidth64, Address, &Value);
652 if (Flag) {
653 *(volatile UINT64 *)Address = Value;
654 }
655
656 FilterAfterMmIoWrite (FilterWidth64, Address, &Value);
657
658 return Value;
659 }