2 I/O Library basic function implementation and worker functions.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this 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 "DxeIoLibEsalInternal.h"
20 Reads registers in the EFI CPU I/O space.
22 Reads the I/O port specified by Port with registers width specified by Width.
23 The read value is returned.
25 This function must guarantee that all I/O read and write operations are serialized.
26 If such operations are not supported, then ASSERT().
28 @param Port The base address of the I/O operation.
29 The caller is responsible for aligning the Address if required.
30 @param Width The width of the I/O operation.
32 @return Data read from registers in the EFI CPU I/O space.
39 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
42 SAL_RETURN_REGS ReturnReg
;
47 ReturnReg
= EsalCall (
48 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
49 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
59 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
64 Writes registers in the EFI CPU I/O space.
66 Writes the I/O port specified by Port with registers width and value specified by Width
67 and Data respectively. Data is returned.
69 This function must guarantee that all I/O read and write operations are serialized.
70 If such operations are not supported, then ASSERT().
72 @param Port The base address of the I/O operation.
73 The caller is responsible for aligning the Address if required.
74 @param Width The width of the I/O operation.
75 @param Data The value to write to the I/O port.
77 @return The parameter of Data.
84 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
88 SAL_RETURN_REGS ReturnReg
;
90 ReturnReg
= EsalCall (
91 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
92 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
102 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
107 Reads registers in the EFI CPU I/O space.
109 Reads the I/O port specified by Port with registers width specified by Width.
110 The port is read Count times, and the read data is stored in the provided Buffer.
112 This function must guarantee that all I/O read and write operations are serialized.
113 If such operations are not supported, then ASSERT().
115 @param Port The base address of the I/O operation.
116 The caller is responsible for aligning the Address if required.
117 @param Width The width of the I/O operation.
118 @param Count The number of times to read I/O port.
119 @param Buffer The buffer to store the read data into.
126 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
131 SAL_RETURN_REGS ReturnReg
;
133 ReturnReg
= EsalCall (
134 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
135 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
145 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
149 Writes registers in the EFI CPU I/O space.
151 Writes the I/O port specified by Port with registers width specified by Width.
152 The port is written Count times, and the write data is retrieved from the provided Buffer.
154 This function must guarantee that all I/O read and write operations are serialized.
155 If such operations are not supported, then ASSERT().
157 @param Port The base address of the I/O operation.
158 The caller is responsible for aligning the Address if required.
159 @param Width The width of the I/O operation.
160 @param Count The number of times to write I/O port.
161 @param Buffer The buffer to store the read data into.
168 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
173 SAL_RETURN_REGS ReturnReg
;
175 ReturnReg
= EsalCall (
176 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
177 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
187 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
191 Reads memory-mapped registers in the EFI system memory space.
193 Reads the MMIO registers specified by Address with registers width specified by Width.
194 The read value is returned. If such operations are not supported, then ASSERT().
195 This function must guarantee that all MMIO read and write operations are serialized.
197 @param Address The MMIO register to read.
198 The caller is responsible for aligning the Address if required.
199 @param Width The width of the I/O operation.
201 @return Data read from registers in the EFI system memory space.
208 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
211 SAL_RETURN_REGS ReturnReg
;
216 ReturnReg
= EsalCall (
217 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
218 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
228 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
233 Writes memory-mapped registers in the EFI system memory space.
235 Writes the MMIO registers specified by Address with registers width and value specified by Width
236 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
237 This function must guarantee that all MMIO read and write operations are serialized.
239 @param Address The MMIO register to read.
240 The caller is responsible for aligning the Address if required.
241 @param Width The width of the I/O operation.
242 @param Data The value to write to memory-mapped registers
244 @return Data read from registers in the EFI system memory space.
251 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
255 SAL_RETURN_REGS ReturnReg
;
257 ReturnReg
= EsalCall (
258 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
259 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
269 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
274 Reads an 8-bit I/O port.
276 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
277 This function must guarantee that all I/O read and write operations are
280 If 8-bit I/O port operations are not supported, then ASSERT().
282 @param Port The I/O port to read.
284 @return The value read.
293 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
297 Writes an 8-bit I/O port.
299 Writes the 8-bit I/O port specified by Port with the value specified by Value
300 and returns Value. This function must guarantee that all I/O read and write
301 operations are serialized.
303 If 8-bit I/O port operations are not supported, then ASSERT().
305 @param Port The I/O port to write.
306 @param Value The value to write to the I/O port.
308 @return The value written the I/O port.
318 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
322 Reads a 16-bit I/O port.
324 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
325 This function must guarantee that all I/O read and write operations are
328 If 16-bit I/O port operations are not supported, then ASSERT().
330 @param Port The I/O port to read.
332 @return The value read.
342 // Make sure Port is aligned on a 16-bit boundary.
344 ASSERT ((Port
& 1) == 0);
345 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
349 Writes a 16-bit I/O port.
351 Writes the 16-bit I/O port specified by Port with the value specified by Value
352 and returns Value. This function must guarantee that all I/O read and write
353 operations are serialized.
355 If 16-bit I/O port operations are not supported, then ASSERT().
357 @param Port The I/O port to write.
358 @param Value The value to write to the I/O port.
360 @return The value written the I/O port.
371 // Make sure Port is aligned on a 16-bit boundary.
373 ASSERT ((Port
& 1) == 0);
374 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
378 Reads a 32-bit I/O port.
380 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
381 This function must guarantee that all I/O read and write operations are
384 If 32-bit I/O port operations are not supported, then ASSERT().
386 @param Port The I/O port to read.
388 @return The value read.
398 // Make sure Port is aligned on a 32-bit boundary.
400 ASSERT ((Port
& 3) == 0);
401 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
405 Writes a 32-bit I/O port.
407 Writes the 32-bit I/O port specified by Port with the value specified by Value
408 and returns Value. This function must guarantee that all I/O read and write
409 operations are serialized.
411 If 32-bit I/O port operations are not supported, then ASSERT().
413 @param Port The I/O port to write.
414 @param Value The value to write to the I/O port.
416 @return The value written the I/O port.
427 // Make sure Port is aligned on a 32-bit boundary.
429 ASSERT ((Port
& 3) == 0);
430 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
434 Reads a 64-bit I/O port.
436 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
437 This function must guarantee that all I/O read and write operations are
440 If 64-bit I/O port operations are not supported, then ASSERT().
442 @param Port The I/O port to read.
444 @return The value read.
454 // Make sure Port is aligned on a 64-bit boundary.
456 ASSERT ((Port
& 7) == 0);
457 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
461 Writes a 64-bit I/O port.
463 Writes the 64-bit I/O port specified by Port with the value specified by Value
464 and returns Value. This function must guarantee that all I/O read and write
465 operations are serialized.
467 If 64-bit I/O port operations are not supported, then ASSERT().
469 @param Port The I/O port to write.
470 @param Value The value to write to the I/O port.
472 @return The value written the I/O port.
483 // Make sure Port is aligned on a 64-bit boundary.
485 ASSERT ((Port
& 7) == 0);
486 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
490 Reads an 8-bit I/O port fifo into a block of memory.
492 Reads the 8-bit I/O fifo port specified by Port.
493 The port is read Count times, and the read data is
494 stored in the provided Buffer.
496 This function must guarantee that all I/O read and write operations are
499 If 8-bit I/O port operations are not supported, then ASSERT().
501 @param Port The I/O port to read.
502 @param Count The number of times to read I/O port.
503 @param Buffer The buffer to store the read data into.
514 IoReadFifoWorker (Port
, EfiCpuIoWidthFifoUint8
, Count
, Buffer
);
518 Writes a block of memory into an 8-bit I/O port fifo.
520 Writes the 8-bit I/O fifo port specified by Port.
521 The port is written Count times, and the write data is
522 retrieved from the provided Buffer.
524 This function must guarantee that all I/O write and write operations are
527 If 8-bit I/O port operations are not supported, then ASSERT().
529 @param Port The I/O port to write.
530 @param Count The number of times to write I/O port.
531 @param Buffer The buffer to retrieve the write data from.
542 IoWriteFifoWorker (Port
, EfiCpuIoWidthFifoUint8
, Count
, Buffer
);
546 Reads a 16-bit I/O port fifo into a block of memory.
548 Reads the 16-bit I/O fifo port specified by Port.
549 The port is read Count times, and the read data is
550 stored in the provided Buffer.
552 This function must guarantee that all I/O read and write operations are
555 If 16-bit I/O port operations are not supported, then ASSERT().
557 @param Port The I/O port to read.
558 @param Count The number of times to read I/O port.
559 @param Buffer The buffer to store the read data into.
571 // Make sure Port is aligned on a 16-bit boundary.
573 ASSERT ((Port
& 1) == 0);
574 IoReadFifoWorker (Port
, EfiCpuIoWidthFifoUint16
, Count
, Buffer
);
578 Writes a block of memory into a 16-bit I/O port fifo.
580 Writes the 16-bit I/O fifo port specified by Port.
581 The port is written Count times, and the write data is
582 retrieved from the provided Buffer.
584 This function must guarantee that all I/O write and write operations are
587 If 16-bit I/O port operations are not supported, then ASSERT().
589 @param Port The I/O port to write.
590 @param Count The number of times to write I/O port.
591 @param Buffer The buffer to retrieve the write data from.
603 // Make sure Port is aligned on a 16-bit boundary.
605 ASSERT ((Port
& 1) == 0);
606 IoWriteFifoWorker (Port
, EfiCpuIoWidthFifoUint16
, Count
, Buffer
);
610 Reads a 32-bit I/O port fifo into a block of memory.
612 Reads the 32-bit I/O fifo port specified by Port.
613 The port is read Count times, and the read data is
614 stored in the provided Buffer.
616 This function must guarantee that all I/O read and write operations are
619 If 32-bit I/O port operations are not supported, then ASSERT().
621 @param Port The I/O port to read.
622 @param Count The number of times to read I/O port.
623 @param Buffer The buffer to store the read data into.
635 // Make sure Port is aligned on a 32-bit boundary.
637 ASSERT ((Port
& 3) == 0);
638 IoReadFifoWorker (Port
, EfiCpuIoWidthFifoUint32
, Count
, Buffer
);
642 Writes a block of memory into a 32-bit I/O port fifo.
644 Writes the 32-bit I/O fifo port specified by Port.
645 The port is written Count times, and the write data is
646 retrieved from the provided Buffer.
648 This function must guarantee that all I/O write and write operations are
651 If 32-bit I/O port operations are not supported, then ASSERT().
653 @param Port The I/O port to write.
654 @param Count The number of times to write I/O port.
655 @param Buffer The buffer to retrieve the write data from.
667 // Make sure Port is aligned on a 32-bit boundary.
669 ASSERT ((Port
& 3) == 0);
670 IoWriteFifoWorker (Port
, EfiCpuIoWidthFifoUint32
, Count
, Buffer
);
674 Reads an 8-bit MMIO register.
676 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
677 returned. This function must guarantee that all MMIO read and write
678 operations are serialized.
680 If 8-bit MMIO register operations are not supported, then ASSERT().
682 @param Address The MMIO register to read.
684 @return The value read.
693 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
697 Writes an 8-bit MMIO register.
699 Writes the 8-bit MMIO register specified by Address with the value specified
700 by Value and returns Value. This function must guarantee that all MMIO read
701 and write operations are serialized.
703 If 8-bit MMIO register operations are not supported, then ASSERT().
705 @param Address The MMIO register to write.
706 @param Value The value to write to the MMIO register.
716 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
720 Reads a 16-bit MMIO register.
722 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
723 returned. This function must guarantee that all MMIO read and write
724 operations are serialized.
726 If 16-bit MMIO register operations are not supported, then ASSERT().
728 @param Address The MMIO register to read.
730 @return The value read.
740 // Make sure Address is aligned on a 16-bit boundary.
742 ASSERT ((Address
& 1) == 0);
743 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
747 Writes a 16-bit MMIO register.
749 Writes the 16-bit MMIO register specified by Address with the value specified
750 by Value and returns Value. This function must guarantee that all MMIO read
751 and write operations are serialized.
753 If 16-bit MMIO register operations are not supported, then ASSERT().
755 @param Address The MMIO register to write.
756 @param Value The value to write to the MMIO register.
767 // Make sure Address is aligned on a 16-bit boundary.
769 ASSERT ((Address
& 1) == 0);
770 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
774 Reads a 32-bit MMIO register.
776 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
777 returned. This function must guarantee that all MMIO read and write
778 operations are serialized.
780 If 32-bit MMIO register operations are not supported, then ASSERT().
782 @param Address The MMIO register to read.
784 @return The value read.
794 // Make sure Address is aligned on a 32-bit boundary.
796 ASSERT ((Address
& 3) == 0);
797 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
801 Writes a 32-bit MMIO register.
803 Writes the 32-bit MMIO register specified by Address with the value specified
804 by Value and returns Value. This function must guarantee that all MMIO read
805 and write operations are serialized.
807 If 32-bit MMIO register operations are not supported, then ASSERT().
809 @param Address The MMIO register to write.
810 @param Value The value to write to the MMIO register.
821 // Make sure Address is aligned on a 32-bit boundary.
823 ASSERT ((Address
& 3) == 0);
824 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
828 Reads a 64-bit MMIO register.
830 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
831 returned. This function must guarantee that all MMIO read and write
832 operations are serialized.
834 If 64-bit MMIO register operations are not supported, then ASSERT().
836 @param Address The MMIO register to read.
838 @return The value read.
848 // Make sure Address is aligned on a 64-bit boundary.
850 ASSERT ((Address
& 7) == 0);
851 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
855 Writes a 64-bit MMIO register.
857 Writes the 64-bit MMIO register specified by Address with the value specified
858 by Value and returns Value. This function must guarantee that all MMIO read
859 and write operations are serialized.
861 If 64-bit MMIO register operations are not supported, then ASSERT().
863 @param Address The MMIO register to write.
864 @param Value The value to write to the MMIO register.
875 // Make sure Address is aligned on a 64-bit boundary.
877 ASSERT ((Address
& 7) == 0);
878 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);