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