2 I/O Library instance based on EFI_CPU_IO2_PROTOCOL.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
7 This program and the accompanying materials are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "DxeCpuIo2LibInternal.h"
20 // Globle varible to cache pointer to CpuIo2 protocol.
22 EFI_CPU_IO2_PROTOCOL
*mCpuIo
= NULL
;
25 The constructor function caches the pointer to CpuIo2 protocol.
27 The constructor function locates CpuIo2 protocol from protocol database.
28 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
30 @param ImageHandle The firmware allocated handle for the EFI image.
31 @param SystemTable A pointer to the EFI System Table.
33 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
39 IN EFI_HANDLE ImageHandle
,
40 IN EFI_SYSTEM_TABLE
*SystemTable
45 Status
= gBS
->LocateProtocol (&gEfiCpuIo2ProtocolGuid
, NULL
, (VOID
**) &mCpuIo
);
46 ASSERT_EFI_ERROR (Status
);
52 Reads registers in the EFI CPU I/O space.
54 Reads the I/O port specified by Port with registers width specified by Width.
55 The read value is returned.
57 This function must guarantee that all I/O read and write operations are serialized.
58 If such operations are not supported, then ASSERT().
60 @param Port The base address of the I/O operation.
61 The caller is responsible for aligning the Address if required.
62 @param Width The width of the I/O operation.
64 @return Data read from registers in the EFI CPU I/O space.
71 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
77 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, 1, &Data
);
78 ASSERT_EFI_ERROR (Status
);
84 Writes registers in the EFI CPU I/O space.
86 Writes the I/O port specified by Port with registers width and value specified by Width
87 and Data respectively. Data is returned.
89 This function must guarantee that all I/O read and write operations are serialized.
90 If such operations are not supported, then ASSERT().
92 @param Port The base address of the I/O operation.
93 The caller is responsible for aligning the Address if required.
94 @param Width The width of the I/O operation.
95 @param Data The value to write to the I/O port.
97 @return The parameter of Data.
104 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
110 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, 1, &Data
);
111 ASSERT_EFI_ERROR (Status
);
117 Reads registers in the EFI CPU I/O space.
119 Reads the I/O port specified by Port with registers width specified by Width.
120 The port is read Count times, and the read data is stored in the provided Buffer.
122 This function must guarantee that all I/O read and write operations are serialized.
123 If such operations are not supported, then ASSERT().
125 @param Port The base address of the I/O operation.
126 The caller is responsible for aligning the Address if required.
127 @param Width The width of the I/O operation.
128 @param Count The number of times to read I/O port.
129 @param Buffer The buffer to store the read data into.
136 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
143 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, Count
, Buffer
);
144 ASSERT_EFI_ERROR (Status
);
148 Writes registers in the EFI CPU I/O space.
150 Writes the I/O port specified by Port with registers width specified by Width.
151 The port is written Count times, and the write data is retrieved from the provided Buffer.
153 This function must guarantee that all I/O read and write operations are serialized.
154 If such operations are not supported, then ASSERT().
156 @param Port The base address of the I/O operation.
157 The caller is responsible for aligning the Address if required.
158 @param Width The width of the I/O operation.
159 @param Count The number of times to write I/O port.
160 @param Buffer The buffer to store the read data into.
167 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
174 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, Count
, Buffer
);
175 ASSERT_EFI_ERROR (Status
);
179 Reads memory-mapped registers in the EFI system memory space.
181 Reads the MMIO registers specified by Address with registers width specified by Width.
182 The read value is returned. If such operations are not supported, then ASSERT().
183 This function must guarantee that all MMIO read and write operations are serialized.
185 @param Address The MMIO register to read.
186 The caller is responsible for aligning the Address if required.
187 @param Width The width of the I/O operation.
189 @return Data read from registers in the EFI system memory space.
196 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
202 Status
= mCpuIo
->Mem
.Read (mCpuIo
, Width
, Address
, 1, &Data
);
203 ASSERT_EFI_ERROR (Status
);
209 Writes memory-mapped registers in the EFI system memory space.
211 Writes the MMIO registers specified by Address with registers width and value specified by Width
212 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
213 This function must guarantee that all MMIO read and write operations are serialized.
215 @param Address The MMIO register to read.
216 The caller is responsible for aligning the Address if required.
217 @param Width The width of the I/O operation.
218 @param Data The value to write to the I/O port.
220 @return Data read from registers in the EFI system memory space.
227 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
233 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
234 ASSERT_EFI_ERROR (Status
);
240 Reads an 8-bit I/O port.
242 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
243 This function must guarantee that all I/O read and write operations are
246 If 8-bit I/O port operations are not supported, then ASSERT().
248 @param Port The I/O port to read.
250 @return The value read.
259 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
263 Writes an 8-bit I/O port.
265 Writes the 8-bit I/O port specified by Port with the value specified by Value
266 and returns Value. This function must guarantee that all I/O read and write
267 operations are serialized.
269 If 8-bit I/O port operations are not supported, then ASSERT().
271 @param Port The I/O port to write.
272 @param Value The value to write to the I/O port.
274 @return The value written the I/O port.
284 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
288 Reads a 16-bit I/O port.
290 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
291 This function must guarantee that all I/O read and write operations are
294 If Port is not aligned on a 16-bit boundary, then ASSERT().
296 If 16-bit I/O port operations are not supported, then ASSERT().
298 @param Port The I/O port to read.
300 @return The value read.
310 // Make sure Port is aligned on a 16-bit boundary.
312 ASSERT ((Port
& 1) == 0);
313 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
317 Writes a 16-bit I/O port.
319 Writes the 16-bit I/O port specified by Port with the value specified by Value
320 and returns Value. This function must guarantee that all I/O read and write
321 operations are serialized.
323 If Port is not aligned on a 16-bit boundary, then ASSERT().
325 If 16-bit I/O port operations are not supported, then ASSERT().
327 @param Port The I/O port to write.
328 @param Value The value to write to the I/O port.
330 @return The value written the I/O port.
341 // Make sure Port is aligned on a 16-bit boundary.
343 ASSERT ((Port
& 1) == 0);
344 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
348 Reads a 32-bit I/O port.
350 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
351 This function must guarantee that all I/O read and write operations are
354 If Port is not aligned on a 32-bit boundary, then ASSERT().
356 If 32-bit I/O port operations are not supported, then ASSERT().
358 @param Port The I/O port to read.
360 @return The value read.
370 // Make sure Port is aligned on a 32-bit boundary.
372 ASSERT ((Port
& 3) == 0);
373 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
377 Writes a 32-bit I/O port.
379 Writes the 32-bit I/O port specified by Port with the value specified by Value
380 and returns Value. This function must guarantee that all I/O read and write
381 operations are serialized.
383 If Port is not aligned on a 32-bit boundary, then ASSERT().
385 If 32-bit I/O port operations are not supported, then ASSERT().
387 @param Port The I/O port to write.
388 @param Value The value to write to the I/O port.
390 @return The value written the I/O port.
401 // Make sure Port is aligned on a 32-bit boundary.
403 ASSERT ((Port
& 3) == 0);
404 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
408 Reads a 64-bit I/O port.
410 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
411 This function must guarantee that all I/O read and write operations are
414 If Port is not aligned on a 64-bit boundary, then ASSERT().
416 If 64-bit I/O port operations are not supported, then ASSERT().
418 @param Port The I/O port to read.
420 @return The value read.
430 // Make sure Port is aligned on a 64-bit boundary.
432 ASSERT ((Port
& 7) == 0);
433 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
437 Writes a 64-bit I/O port.
439 Writes the 64-bit I/O port specified by Port with the value specified by Value
440 and returns Value. This function must guarantee that all I/O read and write
441 operations are serialized.
443 If Port is not aligned on a 64-bit boundary, then ASSERT().
445 If 64-bit I/O port operations are not supported, then ASSERT().
447 @param Port The I/O port to write.
448 @param Value The value to write to the I/O port.
450 @return The value written the I/O port.
461 // Make sure Port is aligned on a 64-bit boundary.
463 ASSERT ((Port
& 7) == 0);
464 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
468 Reads an 8-bit I/O port fifo into a block of memory.
470 Reads the 8-bit I/O fifo port specified by Port.
471 The port is read Count times, and the read data is
472 stored in the provided Buffer.
474 This function must guarantee that all I/O read and write operations are
477 If 8-bit I/O port operations are not supported, then ASSERT().
479 @param Port The I/O port to read.
480 @param Count The number of times to read I/O port.
481 @param Buffer The buffer to store the read data into.
492 IoReadFifoWorker (Port
, EfiCpuIoWidthFifoUint8
, Count
, Buffer
);
496 Writes a block of memory into an 8-bit I/O port fifo.
498 Writes the 8-bit I/O fifo port specified by Port.
499 The port is written Count times, and the write data is
500 retrieved from the provided Buffer.
502 This function must guarantee that all I/O write and write operations are
505 If 8-bit I/O port operations are not supported, then ASSERT().
507 @param Port The I/O port to write.
508 @param Count The number of times to write I/O port.
509 @param Buffer The buffer to retrieve the write data from.
520 IoWriteFifoWorker (Port
, EfiCpuIoWidthFifoUint8
, Count
, Buffer
);
524 Reads a 16-bit I/O port fifo into a block of memory.
526 Reads the 16-bit I/O fifo port specified by Port.
527 The port is read Count times, and the read data is
528 stored in the provided Buffer.
530 This function must guarantee that all I/O read and write operations are
533 If 16-bit I/O port operations are not supported, then ASSERT().
535 @param Port The I/O port to read.
536 @param Count The number of times to read I/O port.
537 @param Buffer The buffer to store the read data into.
549 // Make sure Port is aligned on a 16-bit boundary.
551 ASSERT ((Port
& 1) == 0);
552 IoReadFifoWorker (Port
, EfiCpuIoWidthFifoUint16
, Count
, Buffer
);
556 Writes a block of memory into a 16-bit I/O port fifo.
558 Writes the 16-bit I/O fifo port specified by Port.
559 The port is written Count times, and the write data is
560 retrieved from the provided Buffer.
562 This function must guarantee that all I/O write and write operations are
565 If 16-bit I/O port operations are not supported, then ASSERT().
567 @param Port The I/O port to write.
568 @param Count The number of times to write I/O port.
569 @param Buffer The buffer to retrieve the write data from.
581 // Make sure Port is aligned on a 16-bit boundary.
583 ASSERT ((Port
& 1) == 0);
584 IoWriteFifoWorker (Port
, EfiCpuIoWidthFifoUint16
, Count
, Buffer
);
588 Reads a 32-bit I/O port fifo into a block of memory.
590 Reads the 32-bit I/O fifo port specified by Port.
591 The port is read Count times, and the read data is
592 stored in the provided Buffer.
594 This function must guarantee that all I/O read and write operations are
597 If 32-bit I/O port operations are not supported, then ASSERT().
599 @param Port The I/O port to read.
600 @param Count The number of times to read I/O port.
601 @param Buffer The buffer to store the read data into.
613 // Make sure Port is aligned on a 32-bit boundary.
615 ASSERT ((Port
& 3) == 0);
616 IoReadFifoWorker (Port
, EfiCpuIoWidthFifoUint32
, Count
, Buffer
);
620 Writes a block of memory into a 32-bit I/O port fifo.
622 Writes the 32-bit I/O fifo port specified by Port.
623 The port is written Count times, and the write data is
624 retrieved from the provided Buffer.
626 This function must guarantee that all I/O write and write operations are
629 If 32-bit I/O port operations are not supported, then ASSERT().
631 @param Port The I/O port to write.
632 @param Count The number of times to write I/O port.
633 @param Buffer The buffer to retrieve the write data from.
645 // Make sure Port is aligned on a 32-bit boundary.
647 ASSERT ((Port
& 3) == 0);
648 IoWriteFifoWorker (Port
, EfiCpuIoWidthFifoUint32
, Count
, Buffer
);
652 Reads an 8-bit MMIO register.
654 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
655 returned. This function must guarantee that all MMIO read and write
656 operations are serialized.
658 If 8-bit MMIO register operations are not supported, then ASSERT().
660 @param Address The MMIO register to read.
662 @return The value read.
671 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
675 Writes an 8-bit MMIO register.
677 Writes the 8-bit MMIO register specified by Address with the value specified
678 by Value and returns Value. This function must guarantee that all MMIO read
679 and write operations are serialized.
681 If 8-bit MMIO register operations are not supported, then ASSERT().
683 @param Address The MMIO register to write.
684 @param Value The value to write to the MMIO register.
694 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
698 Reads a 16-bit MMIO register.
700 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
701 returned. This function must guarantee that all MMIO read and write
702 operations are serialized.
704 If Address is not aligned on a 16-bit boundary, then ASSERT().
706 If 16-bit MMIO register operations are not supported, then ASSERT().
708 @param Address The MMIO register to read.
710 @return The value read.
720 // Make sure Address is aligned on a 16-bit boundary.
722 ASSERT ((Address
& 1) == 0);
723 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
727 Writes a 16-bit MMIO register.
729 Writes the 16-bit MMIO register specified by Address with the value specified
730 by Value and returns Value. This function must guarantee that all MMIO read
731 and write operations are serialized.
733 If Address is not aligned on a 16-bit boundary, then ASSERT().
735 If 16-bit MMIO register operations are not supported, then ASSERT().
737 @param Address The MMIO register to write.
738 @param Value The value to write to the MMIO register.
749 // Make sure Address is aligned on a 16-bit boundary.
751 ASSERT ((Address
& 1) == 0);
752 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
756 Reads a 32-bit MMIO register.
758 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
759 returned. This function must guarantee that all MMIO read and write
760 operations are serialized.
762 If Address is not aligned on a 32-bit boundary, then ASSERT().
764 If 32-bit MMIO register operations are not supported, then ASSERT().
766 @param Address The MMIO register to read.
768 @return The value read.
778 // Make sure Address is aligned on a 32-bit boundary.
780 ASSERT ((Address
& 3) == 0);
781 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
785 Writes a 32-bit MMIO register.
787 Writes the 32-bit MMIO register specified by Address with the value specified
788 by Value and returns Value. This function must guarantee that all MMIO read
789 and write operations are serialized.
791 If Address is not aligned on a 32-bit boundary, then ASSERT().
793 If 32-bit MMIO register operations are not supported, then ASSERT().
795 @param Address The MMIO register to write.
796 @param Value The value to write to the MMIO register.
807 // Make sure Address is aligned on a 32-bit boundary.
809 ASSERT ((Address
& 3) == 0);
810 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
814 Reads a 64-bit MMIO register.
816 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
817 returned. This function must guarantee that all MMIO read and write
818 operations are serialized.
820 If Address is not aligned on a 64-bit boundary, then ASSERT().
822 If 64-bit MMIO register operations are not supported, then ASSERT().
824 @param Address The MMIO register to read.
826 @return The value read.
836 // Make sure Address is aligned on a 64-bit boundary.
838 ASSERT ((Address
& 7) == 0);
839 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
843 Writes a 64-bit MMIO register.
845 Writes the 64-bit MMIO register specified by Address with the value specified
846 by Value and returns Value. This function must guarantee that all MMIO read
847 and write operations are serialized.
849 If Address is not aligned on a 64-bit boundary, then ASSERT().
851 If 64-bit MMIO register operations are not supported, then ASSERT().
853 @param Address The MMIO register to write.
854 @param Value The value to write to the MMIO register.
865 // Make sure Address is aligned on a 64-bit boundary.
867 ASSERT ((Address
& 7) == 0);
868 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);