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