3 The implementation of I/O operation for this library instance
4 are based on EFI_CPU_IO_PROTOCOL.
6 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
7 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "SmmCpuIoLibInternal.h"
16 Reads registers in the EFI CPU I/O space.
18 Reads the I/O port specified by Port with registers width specified by Width.
19 The read value is returned. If such operations are not supported, then ASSERT().
20 This function must guarantee that all I/O read and write operations are serialized.
22 @param Port The base address of the I/O operation.
23 The caller is responsible for aligning the Address if required.
24 @param Width The width of the I/O operation.
26 @return Data read from registers in the EFI CPU I/O space.
33 IN EFI_SMM_IO_WIDTH Width
39 Status
= gSmst
->SmmIo
.Io
.Read (&gSmst
->SmmIo
, Width
, Port
, 1, &Data
);
40 ASSERT_EFI_ERROR (Status
);
46 Writes registers in the EFI CPU I/O space.
48 Writes the I/O port specified by Port with registers width and value specified by Width
49 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
50 This function must guarantee that all I/O read and write operations are serialized.
52 @param Port The base address of the I/O operation.
53 The caller is responsible for aligning the Address if required.
54 @param Width The width of the I/O operation.
55 @param Data The value to write to the I/O port.
57 @return The parameter of Data.
64 IN EFI_SMM_IO_WIDTH Width
,
70 Status
= gSmst
->SmmIo
.Io
.Write (&gSmst
->SmmIo
, Width
, Port
, 1, &Data
);
71 ASSERT_EFI_ERROR (Status
);
77 Reads memory-mapped registers in the EFI system memory space.
79 Reads the MMIO registers specified by Address with registers width specified by Width.
80 The read value is returned. If such operations are not supported, then ASSERT().
81 This function must guarantee that all MMIO read and write operations are serialized.
83 @param Address The MMIO register to read.
84 The caller is responsible for aligning the Address if required.
85 @param Width The width of the I/O operation.
87 @return Data read from registers in the EFI system memory space.
94 IN EFI_SMM_IO_WIDTH Width
100 Status
= gSmst
->SmmIo
.Mem
.Read (&gSmst
->SmmIo
, Width
, Address
, 1, &Data
);
101 ASSERT_EFI_ERROR (Status
);
107 Writes memory-mapped registers in the EFI system memory space.
109 Writes the MMIO registers specified by Address with registers width and value specified by Width
110 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
111 This function must guarantee that all MMIO read and write operations are serialized.
113 @param Address The MMIO register to read.
114 The caller is responsible for aligning the Address if required.
115 @param Width The width of the I/O operation.
116 @param Data The value to write to the I/O port.
118 @return Data read from registers in the EFI system memory space.
125 IN EFI_SMM_IO_WIDTH Width
,
131 Status
= gSmst
->SmmIo
.Mem
.Write (&gSmst
->SmmIo
, Width
, Address
, 1, &Data
);
132 ASSERT_EFI_ERROR (Status
);
138 Reads an 8-bit I/O port.
140 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
141 This function must guarantee that all I/O read and write operations are
144 If 8-bit I/O port operations are not supported, then ASSERT().
146 @param Port The I/O port to read.
148 @return The value read.
157 return (UINT8
)IoReadWorker (Port
, SMM_IO_UINT8
);
161 Writes an 8-bit I/O port.
163 Writes the 8-bit I/O port specified by Port with the value specified by Value
164 and returns Value. This function must guarantee that all I/O read and write
165 operations are serialized.
167 If 8-bit I/O port operations are not supported, then ASSERT().
169 @param Port The I/O port to write.
170 @param Value The value to write to the I/O port.
172 @return The value written the I/O port.
182 return (UINT8
)IoWriteWorker (Port
, SMM_IO_UINT8
, Value
);
186 Reads a 16-bit I/O port.
188 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
189 This function must guarantee that all I/O read and write operations are
192 If Port is not aligned on a 16-bit boundary, then ASSERT().
194 If 16-bit I/O port operations are not supported, then ASSERT().
196 @param Port The I/O port to read.
198 @return The value read.
208 // Make sure Port is aligned on a 16-bit boundary.
210 ASSERT ((Port
& 1) == 0);
211 return (UINT16
)IoReadWorker (Port
, SMM_IO_UINT16
);
215 Writes a 16-bit I/O port.
217 Writes the 16-bit I/O port specified by Port with the value specified by Value
218 and returns Value. This function must guarantee that all I/O read and write
219 operations are serialized.
221 If Port is not aligned on a 16-bit boundary, then ASSERT().
223 If 16-bit I/O port operations are not supported, then ASSERT().
225 @param Port The I/O port to write.
226 @param Value The value to write to the I/O port.
228 @return The value written the I/O port.
239 // Make sure Port is aligned on a 16-bit boundary.
241 ASSERT ((Port
& 1) == 0);
242 return (UINT16
)IoWriteWorker (Port
, SMM_IO_UINT16
, Value
);
246 Reads a 32-bit I/O port.
248 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
249 This function must guarantee that all I/O read and write operations are
252 If Port is not aligned on a 32-bit boundary, then ASSERT().
254 If 32-bit I/O port operations are not supported, then ASSERT().
256 @param Port The I/O port to read.
258 @return The value read.
268 // Make sure Port is aligned on a 32-bit boundary.
270 ASSERT ((Port
& 3) == 0);
271 return (UINT32
)IoReadWorker (Port
, SMM_IO_UINT32
);
275 Writes a 32-bit I/O port.
277 Writes the 32-bit I/O port specified by Port with the value specified by Value
278 and returns Value. This function must guarantee that all I/O read and write
279 operations are serialized.
281 If Port is not aligned on a 32-bit boundary, then ASSERT().
283 If 32-bit I/O port operations are not supported, then ASSERT().
285 @param Port The I/O port to write.
286 @param Value The value to write to the I/O port.
288 @return The value written the I/O port.
299 // Make sure Port is aligned on a 32-bit boundary.
301 ASSERT ((Port
& 3) == 0);
302 return (UINT32
)IoWriteWorker (Port
, SMM_IO_UINT32
, Value
);
306 Reads a 64-bit I/O port.
308 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
309 This function must guarantee that all I/O read and write operations are
312 If Port is not aligned on a 64-bit boundary, then ASSERT().
314 If 64-bit I/O port operations are not supported, then ASSERT().
316 @param Port The I/O port to read.
318 @return The value read.
328 // Make sure Port is aligned on a 64-bit boundary.
330 ASSERT ((Port
& 7) == 0);
331 return IoReadWorker (Port
, SMM_IO_UINT64
);
335 Writes a 64-bit I/O port.
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.
341 If Port is not aligned on a 64-bit boundary, then ASSERT().
343 If 64-bit I/O port operations are not supported, then ASSERT().
345 @param Port The I/O port to write.
346 @param Value The value to write to the I/O port.
348 @return The value written the I/O port.
359 // Make sure Port is aligned on a 64-bit boundary.
361 ASSERT ((Port
& 7) == 0);
362 return IoWriteWorker (Port
, SMM_IO_UINT64
, Value
);
366 Reads an 8-bit I/O port fifo into a block of memory.
368 Reads the 8-bit I/O fifo port specified by Port.
369 The port is read Count times, and the read data is
370 stored in the provided Buffer.
372 This function must guarantee that all I/O read and write operations are
375 If 8-bit I/O port operations are not supported, then ASSERT().
377 @param Port The I/O port to read.
378 @param Count The number of times to read I/O port.
379 @param Buffer The buffer to store the read data into.
392 Buffer8
= (UINT8
*)Buffer
;
393 while (Count
-- > 0) {
394 *Buffer8
++ = IoRead8 (Port
);
399 Writes a block of memory into an 8-bit I/O port fifo.
401 Writes the 8-bit I/O fifo port specified by Port.
402 The port is written Count times, and the write data is
403 retrieved from the provided Buffer.
405 This function must guarantee that all I/O write and write operations are
408 If 8-bit I/O port operations are not supported, then ASSERT().
410 @param Port The I/O port to write.
411 @param Count The number of times to write I/O port.
412 @param Buffer The buffer to retrieve the write data from.
425 Buffer8
= (UINT8
*)Buffer
;
426 while (Count
-- > 0) {
427 IoWrite8 (Port
, *Buffer8
++);
432 Reads a 16-bit I/O port fifo into a block of memory.
434 Reads the 16-bit I/O fifo port specified by Port.
435 The port is read Count times, and the read data is
436 stored in the provided Buffer.
438 This function must guarantee that all I/O read and write operations are
441 If 16-bit I/O port operations are not supported, then ASSERT().
443 @param Port The I/O port to read.
444 @param Count The number of times to read I/O port.
445 @param Buffer The buffer to store the read data into.
459 // Make sure Port is aligned on a 16-bit boundary.
461 ASSERT ((Port
& 1) == 0);
462 Buffer16
= (UINT16
*)Buffer
;
463 while (Count
-- > 0) {
464 *Buffer16
++ = IoRead16 (Port
);
469 Writes a block of memory into a 16-bit I/O port fifo.
471 Writes the 16-bit I/O fifo port specified by Port.
472 The port is written Count times, and the write data is
473 retrieved from the provided Buffer.
475 This function must guarantee that all I/O write and write operations are
478 If 16-bit I/O port operations are not supported, then ASSERT().
480 @param Port The I/O port to write.
481 @param Count The number of times to write I/O port.
482 @param Buffer The buffer to retrieve the write data from.
496 // Make sure Port is aligned on a 16-bit boundary.
498 ASSERT ((Port
& 1) == 0);
499 Buffer16
= (UINT16
*)Buffer
;
500 while (Count
-- > 0) {
501 IoWrite16 (Port
, *Buffer16
++);
506 Reads a 32-bit I/O port fifo into a block of memory.
508 Reads the 32-bit I/O fifo port specified by Port.
509 The port is read Count times, and the read data is
510 stored in the provided Buffer.
512 This function must guarantee that all I/O read and write operations are
515 If 32-bit I/O port operations are not supported, then ASSERT().
517 @param Port The I/O port to read.
518 @param Count The number of times to read I/O port.
519 @param Buffer The buffer to store the read data into.
533 // Make sure Port is aligned on a 32-bit boundary.
535 ASSERT ((Port
& 3) == 0);
536 Buffer32
= (UINT32
*)Buffer
;
537 while (Count
-- > 0) {
538 *Buffer32
++ = IoRead32 (Port
);
543 Writes a block of memory into a 32-bit I/O port fifo.
545 Writes the 32-bit I/O fifo port specified by Port.
546 The port is written Count times, and the write data is
547 retrieved from the provided Buffer.
549 This function must guarantee that all I/O write and write operations are
552 If 32-bit I/O port operations are not supported, then ASSERT().
554 @param Port The I/O port to write.
555 @param Count The number of times to write I/O port.
556 @param Buffer The buffer to retrieve the write data from.
570 // Make sure Port is aligned on a 32-bit boundary.
572 ASSERT ((Port
& 3) == 0);
573 Buffer32
= (UINT32
*)Buffer
;
574 while (Count
-- > 0) {
575 IoWrite32 (Port
, *Buffer32
++);
580 Reads an 8-bit MMIO register.
582 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
583 returned. This function must guarantee that all MMIO read and write
584 operations are serialized.
586 If 8-bit MMIO register operations are not supported, then ASSERT().
588 @param Address The MMIO register to read.
590 @return The value read.
599 return (UINT8
)MmioReadWorker (Address
, SMM_IO_UINT8
);
603 Writes an 8-bit MMIO register.
605 Writes the 8-bit MMIO register specified by Address with the value specified
606 by Value and returns Value. This function must guarantee that all MMIO read
607 and write operations are serialized.
609 If 8-bit MMIO register operations are not supported, then ASSERT().
611 @param Address The MMIO register to write.
612 @param Value The value to write to the MMIO register.
622 return (UINT8
)MmioWriteWorker (Address
, SMM_IO_UINT8
, Value
);
626 Reads a 16-bit MMIO register.
628 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
629 returned. This function must guarantee that all MMIO read and write
630 operations are serialized.
632 If Address is not aligned on a 16-bit boundary, then ASSERT().
634 If 16-bit MMIO register operations are not supported, then ASSERT().
636 @param Address The MMIO register to read.
638 @return The value read.
648 // Make sure Address is aligned on a 16-bit boundary.
650 ASSERT ((Address
& 1) == 0);
651 return (UINT16
)MmioReadWorker (Address
, SMM_IO_UINT16
);
655 Writes a 16-bit MMIO register.
657 Writes the 16-bit MMIO register specified by Address with the value specified
658 by Value and returns Value. This function must guarantee that all MMIO read
659 and write operations are serialized.
661 If Address is not aligned on a 16-bit boundary, then ASSERT().
663 If 16-bit MMIO register operations are not supported, then ASSERT().
665 @param Address The MMIO register to write.
666 @param Value The value to write to the MMIO register.
677 // Make sure Address is aligned on a 16-bit boundary.
679 ASSERT ((Address
& 1) == 0);
680 return (UINT16
)MmioWriteWorker (Address
, SMM_IO_UINT16
, Value
);
684 Reads a 32-bit MMIO register.
686 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
687 returned. This function must guarantee that all MMIO read and write
688 operations are serialized.
690 If Address is not aligned on a 32-bit boundary, then ASSERT().
692 If 32-bit MMIO register operations are not supported, then ASSERT().
694 @param Address The MMIO register to read.
696 @return The value read.
706 // Make sure Address is aligned on a 32-bit boundary.
708 ASSERT ((Address
& 3) == 0);
709 return (UINT32
)MmioReadWorker (Address
, SMM_IO_UINT32
);
713 Writes a 32-bit MMIO register.
715 Writes the 32-bit MMIO register specified by Address with the value specified
716 by Value and returns Value. This function must guarantee that all MMIO read
717 and write operations are serialized.
719 If Address is not aligned on a 32-bit boundary, then ASSERT().
721 If 32-bit MMIO register operations are not supported, then ASSERT().
723 @param Address The MMIO register to write.
724 @param Value The value to write to the MMIO register.
735 // Make sure Address is aligned on a 32-bit boundary.
737 ASSERT ((Address
& 3) == 0);
738 return (UINT32
)MmioWriteWorker (Address
, SMM_IO_UINT32
, Value
);
742 Reads a 64-bit MMIO register.
744 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
745 returned. This function must guarantee that all MMIO read and write
746 operations are serialized.
748 If Address is not aligned on a 64-bit boundary, then ASSERT().
750 If 64-bit MMIO register operations are not supported, then ASSERT().
752 @param Address The MMIO register to read.
754 @return The value read.
764 // Make sure Address is aligned on a 64-bit boundary.
766 ASSERT ((Address
& 7) == 0);
767 return (UINT64
)MmioReadWorker (Address
, SMM_IO_UINT64
);
771 Writes a 64-bit MMIO register.
773 Writes the 64-bit MMIO register specified by Address with the value specified
774 by Value and returns Value. This function must guarantee that all MMIO read
775 and write operations are serialized.
777 If Address is not aligned on a 64-bit boundary, then ASSERT().
779 If 64-bit MMIO register operations are not supported, then ASSERT().
781 @param Address The MMIO register to write.
782 @param Value The value to write to the MMIO register.
793 // Make sure Address is aligned on a 64-bit boundary.
795 ASSERT ((Address
& 7) == 0);
796 return (UINT64
)MmioWriteWorker (Address
, SMM_IO_UINT64
, Value
);