--- /dev/null
+/** @file\r
+ Produces the CPU I/O 2 Protocol.\r
+\r
+Copyright (c) 2009, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "CpuIo2Dxe.h"\r
+\r
+EFI_HANDLE mHandle = NULL;\r
+EFI_CPU_IO2_PROTOCOL mCpuIo = {\r
+ {\r
+ CpuMemoryServiceRead,\r
+ CpuMemoryServiceWrite\r
+ },\r
+ {\r
+ CpuIoServiceRead,\r
+ CpuIoServiceWrite\r
+ }\r
+};\r
+\r
+/**\r
+ Worker function to check the validation of parameters for CPU I/O interface functions.\r
+\r
+ This function check the validation of parameters for CPU I/O interface functions.\r
+\r
+ @param Width Width of the Mmio/Io operation\r
+ @param Address Base address of the Mmio/Io operation\r
+ @param Count Count of the number of accesses to perform\r
+ @param Buffer Pointer to the buffer to read from memory\r
+ @param Limit Maximum address supported\r
+\r
+ @retval EFI_INVALID_PARAMETER Buffer is NULL\r
+ @retval EFI_UNSUPPORTED The address range specified by Width, Address and Count is invalid\r
+ @retval EFI_UNSUPPORTED The memory buffer is not aligned\r
+ @retval EFI_SUCCESS Parameters are valid\r
+\r
+**/\r
+EFI_STATUS\r
+CpuIoCheckParameter (\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN VOID *Buffer,\r
+ IN UINT64 Limit\r
+ )\r
+{\r
+ UINTN AlignMask;\r
+\r
+ if (Buffer == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (Address > Limit) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // For FiFo type, the target address won't increase during the access,\r
+ // so treat count as 1\r
+ //\r
+ if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+ Count = 1;\r
+ }\r
+\r
+ Width = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
+ if (Address - 1 + (UINT32)(1 << Width) * Count > Limit) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ AlignMask = (1 << Width) - 1;\r
+ if ((UINTN) Buffer & AlignMask) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Worker function to update access width and count for access to the unaligned address.\r
+ Unaligned Io/MmIo address access, break up the request into word by word or byte by byte.\r
+\r
+ @param Address Base address of the Mmio/Io operation\r
+ @param PtrWidth Pointer to width of the Mmio/Io operation\r
+ Out, this value will be updated for access to the unaligned address.\r
+ @param PtrCount Pointer to count of the number of accesses to perform\r
+ Out, this value will be updated for access to the unaligned address.\r
+**/\r
+VOID\r
+CpuIoUpdateWidthCount (\r
+ IN UINT64 Address,\r
+ IN OUT EFI_CPU_IO_PROTOCOL_WIDTH *PtrWidth,\r
+ IN OUT UINTN *PtrCount\r
+ )\r
+{\r
+ EFI_CPU_IO_PROTOCOL_WIDTH BufferWidth;\r
+ UINTN BufferCount;\r
+\r
+ BufferWidth = *PtrWidth;\r
+ BufferCount = *PtrCount;\r
+ \r
+ switch (BufferWidth) {\r
+ case EfiCpuIoWidthUint8:\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint16:\r
+ if ((Address & 0x01) == 0) {\r
+ break;\r
+ } else {\r
+ BufferCount = BufferCount * 2;\r
+ BufferWidth = EfiCpuIoWidthUint8;\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint32:\r
+ if ((Address & 0x03) == 0) {\r
+ break;\r
+ } else if ((Address & 0x01) == 0) {\r
+ BufferCount = BufferCount * 2;\r
+ BufferWidth = EfiCpuIoWidthUint16;\r
+ } else {\r
+ BufferCount = BufferCount * 4;\r
+ BufferWidth = EfiCpuIoWidthUint8;\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint64:\r
+ if ((Address & 0x07) == 0) {\r
+ break;\r
+ } else if ((Address & 0x03) == 0) {\r
+ BufferCount = BufferCount * 2;\r
+ BufferWidth = EfiCpuIoWidthUint32;\r
+ } else if ((Address & 0x01) == 0) {\r
+ BufferCount = BufferCount * 4;\r
+ BufferWidth = EfiCpuIoWidthUint16;\r
+ } else {\r
+ BufferCount = BufferCount * 8;\r
+ BufferWidth = EfiCpuIoWidthUint8;\r
+ }\r
+ break;\r
+\r
+ default:\r
+ return;\r
+ }\r
+\r
+ *PtrWidth = BufferWidth;\r
+ *PtrCount = BufferCount;\r
+\r
+ return;\r
+}\r
+\r
+/**\r
+ Worker function to perform memory mapped I/O read/write\r
+\r
+ This function provides private services to perform memory mapped I/O read/write.\r
+\r
+ @param Width Width of the memory mapped I/O operation\r
+ @param Count Count of the number of accesses to perform\r
+ @param DestinationStrideFlag Boolean flag indicates if the destination is to be incremented\r
+ @param Destination Destination of the memory mapped I/O operation\r
+ @param SourceStrideFlag Boolean flag indicates if the source is to be incremented\r
+ @param Source Source of the memory mapped I/O operation\r
+\r
+ @retval EFI_SUCCESS Successful operation\r
+ @retval EFI_INVALID_PARAMETER Width is invalid\r
+\r
+**/\r
+EFI_STATUS\r
+CpuIoMemRW (\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINTN Count,\r
+ IN BOOLEAN DestinationStrideFlag,\r
+ OUT PTR Destination,\r
+ IN BOOLEAN SourceStrideFlag,\r
+ IN PTR Source\r
+ )\r
+{\r
+ UINTN Stride;\r
+ UINTN DestinationStride;\r
+ UINTN SourceStride;\r
+\r
+ Width = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
+ Stride = (UINT32)(1 << Width);\r
+ DestinationStride = DestinationStrideFlag ? Stride : 0;\r
+ SourceStride = SourceStrideFlag ? Stride : 0;\r
+\r
+ //\r
+ // Loop for each iteration and move the data\r
+ //\r
+ switch (Width) {\r
+ case EfiCpuIoWidthUint8:\r
+ for (; Count > 0; Count--, Destination.Buf += DestinationStride, Source.Buf += SourceStride) {\r
+ MmioWrite8((UINTN)Destination.Ui8 , MmioRead8((UINTN)Source.Ui8));\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint16:\r
+ for (; Count > 0; Count--, Destination.Buf += DestinationStride, Source.Buf += SourceStride) {\r
+ MmioWrite16((UINTN)Destination.Ui16 , MmioRead16((UINTN)Source.Ui16));\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint32:\r
+ for (; Count > 0; Count--, Destination.Buf += DestinationStride, Source.Buf += SourceStride) {\r
+ MmioWrite32((UINTN)Destination.Ui32 , MmioRead32((UINTN)Source.Ui32));\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint64:\r
+ for (; Count > 0; Count--, Destination.Buf += DestinationStride, Source.Buf += SourceStride) {\r
+ MmioWrite64((UINTN)Destination.Ui64 , MmioRead64((UINTN)Source.Ui64));\r
+ }\r
+ break;\r
+\r
+ default:\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Enables a driver to read memory-mapped registers in the PI System memory space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the memory operation.\r
+ @param[in] Address The base address of the memory operation.\r
+ @param[in] Count The number of memory operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[out] Buffer The destination buffer to store the results.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ OUT VOID *Buffer\r
+ )\r
+{\r
+ PTR Source;\r
+ PTR Destination;\r
+ EFI_STATUS Status;\r
+ EFI_CPU_IO_PROTOCOL_WIDTH BufferWidth;\r
+\r
+ Status = CpuIoCheckParameter (Width, Address, Count, Buffer, MAX_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Destination.Buf = Buffer;\r
+ Source.Buf = (VOID *) (UINTN) Address;\r
+ \r
+ //\r
+ // Support access to unaligned mmio address.\r
+ // Break up the request into byte by byte\r
+ //\r
+ BufferWidth = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
+ CpuIoUpdateWidthCount (Address, &BufferWidth, &Count);\r
+\r
+ if (Width >= EfiCpuIoWidthUint8 && Width <= EfiCpuIoWidthUint64) {\r
+ return CpuIoMemRW (BufferWidth, Count, TRUE, Destination, TRUE, Source);\r
+ }\r
+\r
+ if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+ return CpuIoMemRW (BufferWidth, Count, TRUE, Destination, FALSE, Source);\r
+ }\r
+\r
+ if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
+ return CpuIoMemRW (BufferWidth, Count, FALSE, Destination, TRUE, Source);\r
+ }\r
+\r
+ return EFI_INVALID_PARAMETER;\r
+}\r
+\r
+/**\r
+ Enables a driver to write memory-mapped registers in the PI System memory space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the memory operation.\r
+ @param[in] Address The base address of the memory operation.\r
+ @param[in] Count The number of memory operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[in] Buffer The source buffer from which to write data.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN VOID *Buffer\r
+ )\r
+{\r
+ PTR Source;\r
+ PTR Destination;\r
+ EFI_STATUS Status;\r
+ EFI_CPU_IO_PROTOCOL_WIDTH BufferWidth;\r
+\r
+ Status = CpuIoCheckParameter (Width, Address, Count, Buffer, MAX_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Destination.Buf = (VOID *) (UINTN) Address;\r
+ Source.Buf = Buffer;\r
+\r
+ //\r
+ // Support access to unaligned mmio address.\r
+ // Break up the request into byte by byte\r
+ //\r
+ BufferWidth = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
+ CpuIoUpdateWidthCount (Address, &BufferWidth, &Count);\r
+\r
+ if (Width >= EfiCpuIoWidthUint8 && Width <= EfiCpuIoWidthUint64) {\r
+ return CpuIoMemRW (BufferWidth, Count, TRUE, Destination, TRUE, Source);\r
+ }\r
+\r
+ if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+ return CpuIoMemRW (BufferWidth, Count, FALSE, Destination, TRUE, Source);\r
+ }\r
+\r
+ if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
+ return CpuIoMemRW (BufferWidth, Count, TRUE, Destination, FALSE, Source);\r
+ }\r
+\r
+ return EFI_INVALID_PARAMETER;\r
+}\r
+\r
+/**\r
+ Enables a driver to read registers in the PI CPU I/O space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the I/O operation.\r
+ @param[in] UserAddress The base address of the I/O operation. The caller is responsible\r
+ for aligning the Address if required. \r
+ @param[in] Count The number of I/O operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[out] UserBuffer The destination buffer to store the results.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ OUT VOID *UserBuffer\r
+ )\r
+{\r
+ UINTN InStride;\r
+ UINTN OutStride;\r
+ UINTN Address;\r
+ PTR Buffer;\r
+ EFI_STATUS Status;\r
+ EFI_CPU_IO_PROTOCOL_WIDTH BufferWidth; \r
+\r
+ Buffer.Buf = (UINT8 *) UserBuffer;\r
+\r
+ if (Width >= EfiCpuIoWidthMaximum) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = CpuIoCheckParameter (Width, UserAddress, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Support access to unaligned IO address.\r
+ // Break up the request into byte by byte\r
+ //\r
+ BufferWidth = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
+ CpuIoUpdateWidthCount (UserAddress, &BufferWidth, &Count);\r
+\r
+ Address = (UINTN) UserAddress;\r
+ InStride = (UINT32)(1 << (BufferWidth & 0x03));\r
+ OutStride = InStride;\r
+ if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+ InStride = 0;\r
+ }\r
+\r
+ if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
+ OutStride = 0;\r
+ }\r
+\r
+ //\r
+ // Loop for each iteration and move the data\r
+ //\r
+ switch (BufferWidth) {\r
+ case EfiCpuIoWidthUint8:\r
+ for (; Count > 0; Count--, Buffer.Buf += OutStride, Address += InStride) {\r
+ *Buffer.Ui8 = IoRead8 (Address);\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint16:\r
+ for (; Count > 0; Count--, Buffer.Buf += OutStride, Address += InStride) {\r
+ *Buffer.Ui16 = IoRead16 (Address);\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint32:\r
+ for (; Count > 0; Count--, Buffer.Buf += OutStride, Address += InStride) {\r
+ *Buffer.Ui32 = IoRead32 (Address);\r
+ }\r
+ break;\r
+\r
+ default:\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Enables a driver to write registers in the PI CPU I/O space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the I/O operation.\r
+ @param[in] UserAddress The base address of the I/O operation. The caller is responsible\r
+ for aligning the Address if required. \r
+ @param[in] Count The number of I/O operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[in] UserBuffer The source buffer from which to write data.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ IN VOID *UserBuffer\r
+ )\r
+{\r
+ UINTN InStride;\r
+ UINTN OutStride;\r
+ UINTN Address;\r
+ PTR Buffer;\r
+ EFI_STATUS Status;\r
+ EFI_CPU_IO_PROTOCOL_WIDTH BufferWidth;\r
+\r
+ Buffer.Buf = (UINT8 *) UserBuffer;\r
+\r
+ if (Width >= EfiCpuIoWidthMaximum) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = CpuIoCheckParameter (Width, UserAddress, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Support access to unaligned IO address.\r
+ // Break up the request into byte by byte\r
+ //\r
+ BufferWidth = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
+ CpuIoUpdateWidthCount (UserAddress, &BufferWidth, &Count);\r
+\r
+ Address = (UINTN) UserAddress;\r
+ InStride = (UINT32)(1 << (BufferWidth & 0x03));\r
+ OutStride = InStride;\r
+ if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+ InStride = 0;\r
+ }\r
+\r
+ if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
+ OutStride = 0;\r
+ }\r
+\r
+ //\r
+ // Loop for each iteration and move the data\r
+ //\r
+ switch (BufferWidth) {\r
+ case EfiCpuIoWidthUint8:\r
+ for (; Count > 0; Count--, Buffer.Buf += OutStride, Address += InStride) {\r
+ IoWrite8 (Address, *Buffer.Ui8);\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint16:\r
+ for (; Count > 0; Count--, Buffer.Buf += OutStride, Address += InStride) {\r
+ IoWrite16 (Address, *Buffer.Ui16);\r
+ }\r
+ break;\r
+\r
+ case EfiCpuIoWidthUint32:\r
+ for (; Count > 0; Count--, Buffer.Buf += OutStride, Address += InStride) {\r
+ IoWrite32 (Address, *Buffer.Ui32);\r
+ }\r
+ break;\r
+\r
+ default:\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Entrypoint of CPU I/O 2 DXE module.\r
+ \r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+ \r
+ @retval EFI_SUCCESS The entry point is executed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIo2Initialize (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = gBS->InstallProtocolInterface (\r
+ &mHandle,\r
+ &gEfiCpuIo2ProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &mCpuIo\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return Status;\r
+}\r
--- /dev/null
+/** @file\r
+ Internal include file for the CPU I/O 2 Protocol implementation.\r
+\r
+Copyright (c) 2009, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _CPU_IO2_H_\r
+#define _CPU_IO2_H_\r
+\r
+#include <Protocol/CpuIo2.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#define IA32_MAX_IO_ADDRESS 0xFFFF\r
+\r
+typedef union {\r
+ UINT8 volatile *Buf;\r
+ UINT8 volatile *Ui8;\r
+ UINT16 volatile *Ui16;\r
+ UINT32 volatile *Ui32;\r
+ UINT64 volatile *Ui64;\r
+ UINTN volatile Ui;\r
+} PTR;\r
+\r
+/**\r
+ Enables a driver to read memory-mapped registers in the PI System memory space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the memory operation.\r
+ @param[in] Address The base address of the memory operation.\r
+ @param[in] Count The number of memory operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[out] Buffer The destination buffer to store the results.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ OUT VOID *Buffer\r
+ );\r
+\r
+/**\r
+ Enables a driver to write memory-mapped registers in the PI System memory space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the memory operation.\r
+ @param[in] Address The base address of the memory operation.\r
+ @param[in] Count The number of memory operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[in] Buffer The source buffer from which to write data.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN VOID *Buffer\r
+ );\r
+\r
+/**\r
+ Enables a driver to read registers in the PI CPU I/O space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the I/O operation.\r
+ @param[in] UserAddress The base address of the I/O operation. The caller is responsible\r
+ for aligning the Address if required. \r
+ @param[in] Count The number of I/O operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[out] UserBuffer The destination buffer to store the results.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ OUT VOID *UserBuffer\r
+ );\r
+\r
+/**\r
+ Enables a driver to write registers in the PI CPU I/O space.\r
+\r
+ @param[in] This A pointer to the EFI_CPU_IO2_PROTOCOL instance.\r
+ @param[in] Width Signifies the width of the I/O operation.\r
+ @param[in] UserAddress The base address of the I/O operation. The caller is responsible\r
+ for aligning the Address if required. \r
+ @param[in] Count The number of I/O operations to perform. The number of bytes moved\r
+ is Width size * Count, starting at Address.\r
+ @param[in] UserBuffer The source buffer from which to write data.\r
+\r
+ @retval EFI_SUCCESS The data was read from or written to the EFI system.\r
+ @retval EFI_INVALID_PARAMETER Width is invalid for this EFI system. Or Buffer is NULL.\r
+ @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
+ Or,The address range specified by Address, Width, and Count is not valid for this EFI system.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+ IN EFI_CPU_IO2_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ IN VOID *UserBuffer\r
+ );\r
+\r
+#endif\r
--- /dev/null
+#/** @file\r
+# Produces the CPU I/O 2 Protocol.\r
+#\r
+# This DXE driver produces of the CPU I/O 2 Protocol, as introduced by PI 1.2.\r
+#\r
+# Copyright (c) 2009, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# \r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = CpuIo2Dxe\r
+ FILE_GUID = A19B1FE7-C1BC-49F8-875F-54A5D542443F\r
+ MODULE_TYPE = DXE_DRIVER\r
+\r
+ ENTRY_POINT = CpuIo2Initialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 EBC\r
+#\r
+\r
+[Sources.common]\r
+ CpuIo2Dxe.h\r
+ CpuIo2Dxe.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+ UefiBootServicesTableLib\r
+ UefiDriverEntryPoint\r
+ IoLib\r
+ DebugLib\r
+\r
+\r
+[Protocols]\r
+ gEfiCpuIo2ProtocolGuid ## PRODUCES\r
+\r
+[Depex]\r
+ TRUE\r
+\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004 - 2007, Intel Corporation \r
-All rights reserved. This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-Module Name:\r
- CpuIo.c\r
-\r
-Abstract:\r
-\r
- This is the code that publishes the CPU I/O Protocol.\r
- The intent herein is to have a single I/O service that can load\r
- as early as possible, extend into runtime, and be layered upon by\r
- the implementations of architectural protocols and the PCI Root\r
- Bridge I/O Protocol.\r
-\r
---*/\r
-\r
-#include "CpuIo.h"\r
-\r
-#define IA32_MAX_IO_ADDRESS 0xFFFF\r
-\r
-EFI_CPU_IO_PROTOCOL mCpuIo = {\r
- {\r
- CpuMemoryServiceRead,\r
- CpuMemoryServiceWrite\r
- },\r
- {\r
- CpuIoServiceRead,\r
- CpuIoServiceWrite\r
- }\r
-};\r
-\r
-EFI_STATUS\r
-CpuIoMemRW (\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINTN Count,\r
- IN BOOLEAN DestinationStrideFlag,\r
- OUT PTR Destination,\r
- IN BOOLEAN SourceStrideFlag,\r
- IN PTR Source\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Private service to perform memory mapped I/O read/write\r
-\r
-Arguments:\r
-\r
- Width - Width of the memory mapped I/O operation\r
- Count - Count of the number of accesses to perform\r
- DestinationStrideFlag - Boolean flag indicates if the destination is to be incremented\r
- Destination - Destination of the memory mapped I/O operation\r
- SourceStrideFlag - Boolean flag indicates if the source is to be incremented\r
- Source - Source of the memory mapped I/O operation\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Successful operation\r
- EFI_INVALID_PARAMETER - Width is invalid\r
-\r
---*/\r
-{\r
- UINTN Stride;\r
- UINTN DestinationStride;\r
- UINTN SourceStride;\r
-\r
- Width = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
- Stride = (UINTN)1 << Width;\r
- DestinationStride = DestinationStrideFlag ? Stride : 0;\r
- SourceStride = SourceStrideFlag ? Stride : 0;\r
-\r
- //\r
- // Loop for each iteration and move the data\r
- //\r
- switch (Width) {\r
- case EfiCpuIoWidthUint8:\r
- for (; Count > 0; Count--, Destination.buf += DestinationStride, Source.buf += SourceStride) {\r
- MemoryFence();\r
- *Destination.ui8 = *Source.ui8;\r
- MemoryFence();\r
- }\r
- break;\r
-\r
- case EfiCpuIoWidthUint16:\r
- for (; Count > 0; Count--, Destination.buf += DestinationStride, Source.buf += SourceStride) {\r
- MemoryFence ();\r
- *Destination.ui16 = *Source.ui16;\r
- MemoryFence ();\r
- }\r
- break;\r
-\r
- case EfiCpuIoWidthUint32:\r
- for (; Count > 0; Count--, Destination.buf += DestinationStride, Source.buf += SourceStride) {\r
- MemoryFence ();\r
- *Destination.ui32 = *Source.ui32;\r
- MemoryFence ();\r
- }\r
- break;\r
-\r
- case EfiCpuIoWidthUint64:\r
- for (; Count > 0; Count--, Destination.buf += DestinationStride, Source.buf += SourceStride) {\r
- MemoryFence ();\r
- *Destination.ui64 = *Source.ui64;\r
- MemoryFence ();\r
- }\r
- break;\r
-\r
- default:\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuMemoryServiceRead (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the memory mapped I/O read service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the memory mapped I/O operation\r
- Address - Base address of the memory mapped I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the destination buffer to store the results\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was read.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-{\r
- PTR Source;\r
- PTR Destination;\r
- EFI_STATUS Status;\r
-\r
- Status = CpuIoCheckParameter (Width, Address, Count, Buffer, MAX_ADDRESS);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Destination.buf = Buffer;\r
- Source.buf = (VOID *) (UINTN) Address;\r
-\r
- if (Width >= EfiCpuIoWidthUint8 && Width <= EfiCpuIoWidthUint64) {\r
- return CpuIoMemRW (Width, Count, TRUE, Destination, TRUE, Source);\r
- }\r
-\r
- if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
- return CpuIoMemRW (Width, Count, TRUE, Destination, FALSE, Source);\r
- }\r
-\r
- if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
- return CpuIoMemRW (Width, Count, FALSE, Destination, TRUE, Source);\r
- }\r
-\r
- return EFI_INVALID_PARAMETER;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuMemoryServiceWrite (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the memory mapped I/O write service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the memory mapped I/O operation\r
- Address - Base address of the memory mapped I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the source buffer from which to write data\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was written.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-{\r
- PTR Source;\r
- PTR Destination;\r
- EFI_STATUS Status;\r
-\r
- Status = CpuIoCheckParameter (Width, Address, Count, Buffer, MAX_ADDRESS);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Destination.buf = (VOID *) (UINTN) Address;\r
- Source.buf = Buffer;\r
-\r
- if (Width >= EfiCpuIoWidthUint8 && Width <= EfiCpuIoWidthUint64) {\r
- return CpuIoMemRW (Width, Count, TRUE, Destination, TRUE, Source);\r
- }\r
-\r
- if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
- return CpuIoMemRW (Width, Count, FALSE, Destination, TRUE, Source);\r
- }\r
-\r
- if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
- return CpuIoMemRW (Width, Count, TRUE, Destination, FALSE, Source);\r
- }\r
-\r
- return EFI_INVALID_PARAMETER;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuIoServiceRead (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 UserAddress,\r
- IN UINTN Count,\r
- OUT VOID *UserBuffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the port I/O read service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the port I/O operation\r
- Address - Base address of the port I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the destination buffer to store the results\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was read.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-{\r
- UINTN InStride;\r
- UINTN OutStride;\r
- UINTN Address;\r
- PTR Buffer;\r
- EFI_STATUS Status;\r
-\r
- Buffer.buf = (UINT8 *) UserBuffer;\r
-\r
- if (Width >= EfiCpuIoWidthMaximum) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = CpuIoCheckParameter (Width, UserAddress, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Address = (UINTN) UserAddress;\r
- InStride = (UINTN)1 << (Width & 0x03);\r
- OutStride = InStride;\r
- if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
- InStride = 0;\r
- }\r
-\r
- if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
- OutStride = 0;\r
- }\r
-\r
- Width = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
-\r
- //\r
- // Loop for each iteration and move the data\r
- //\r
- switch (Width) {\r
- case EfiCpuIoWidthUint8:\r
- for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- *Buffer.ui8 = IoRead8 ((UINTN) Address);\r
- }\r
- break;\r
-\r
- case EfiCpuIoWidthUint16:\r
- for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- *Buffer.ui16 = IoRead16 ((UINTN) Address);\r
- }\r
- break;\r
-\r
- case EfiCpuIoWidthUint32:\r
- for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- *Buffer.ui32 = IoRead32 ((UINTN) Address);\r
- }\r
- break;\r
-\r
- default:\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuIoServiceWrite (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 UserAddress,\r
- IN UINTN Count,\r
- IN VOID *UserBuffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the port I/O write service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the port I/O operation\r
- Address - Base address of the port I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the source buffer from which to write data\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was written.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-{\r
- UINTN InStride;\r
- UINTN OutStride;\r
- UINTN Address;\r
- PTR Buffer;\r
- EFI_STATUS Status;\r
-\r
- Buffer.buf = (UINT8 *) UserBuffer;\r
-\r
- if (Width >= EfiCpuIoWidthMaximum) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = CpuIoCheckParameter (Width, UserAddress, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Address = (UINTN) UserAddress;\r
- InStride = (UINTN)1 << (Width & 0x03);\r
- OutStride = InStride;\r
- if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
- InStride = 0;\r
- }\r
-\r
- if (Width >= EfiCpuIoWidthFillUint8 && Width <= EfiCpuIoWidthFillUint64) {\r
- OutStride = 0;\r
- }\r
-\r
- Width = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
-\r
- //\r
- // Loop for each iteration and move the data\r
- //\r
- switch (Width) {\r
- case EfiCpuIoWidthUint8:\r
- for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- IoWrite8 ((UINTN) Address, *Buffer.ui8);\r
- }\r
- break;\r
-\r
- case EfiCpuIoWidthUint16:\r
- for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- IoWrite16 ((UINTN) Address, *Buffer.ui16);\r
- }\r
- break;\r
-\r
- case EfiCpuIoWidthUint32:\r
- for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- IoWrite32 ((UINTN) Address, *Buffer.ui32);\r
- }\r
- break;\r
-\r
- default:\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuIoInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- CpuIo driver entry point.\r
-\r
-Arguments:\r
-\r
- ImageHandle - The firmware allocated handle for the EFI image.\r
- SystemTable - A pointer to the EFI System Table.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The driver was initialized.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE Handle;\r
-\r
- Handle = NULL;\r
- Status = SystemTable->BootServices->InstallProtocolInterface (\r
- &Handle,\r
- &gEfiCpuIoProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- &mCpuIo\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-CpuIoCheckParameter (\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN VOID *Buffer,\r
- IN UINT64 Limit\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Check the validation of parameters for CPU I/O interface functions.\r
-\r
-Arguments:\r
-\r
- Width - Width of the Memory Access\r
- Address - Address of the Memory access\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the buffer to read from memory\r
- Buffer - Memory buffer for the I/O operation\r
- Limit - Maximum address supported\r
-\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - Buffer is NULL\r
- EFI_UNSUPPORTED - The address range specified by Width, Address and Count is invalid\r
- EFI_UNSUPPORTED - The memory buffer is not aligned\r
- EFI_SUCCESS - Parameters are OK\r
-\r
---*/\r
-{\r
- UINTN AlignMask;\r
-\r
- if (Buffer == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (Address > Limit) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- //\r
- // For FiFo type, the target address won't increase during the access,\r
- // so treat count as 1\r
- //\r
- if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
- Count = 1;\r
- }\r
-\r
- Width = (EFI_CPU_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
- if (Address - 1 + ((UINTN)1 << Width) * Count > Limit) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- AlignMask = ((UINTN)1 << Width) - 1;\r
- if ((UINTN) Buffer & AlignMask) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004, Intel Corporation \r
-All rights reserved. This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-Module Name:\r
- CpuIo.h\r
-\r
-Abstract:\r
- *.h file for the driver\r
-\r
- Note: the EFIAPI on the CpuIo functions is used to glue MASM (assembler) code\r
- into C code. By making the MASM functions EFIAPI it ensures that a standard\r
- C calling convention is assumed by the compiler, reguardless of the compiler\r
- flags.\r
-\r
-\r
---*/\r
-\r
-#ifndef _CPU_IO_H\r
-#define _CPU_IO_H\r
-\r
-#include <PiDxe.h>\r
-\r
-#include <Protocol/CpuIo.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/IoLib.h>\r
-\r
-typedef union {\r
- UINT8 volatile *buf;\r
- UINT8 volatile *ui8;\r
- UINT16 volatile *ui16;\r
- UINT32 volatile *ui32;\r
- UINT64 volatile *ui64;\r
- UINTN volatile ui;\r
-} PTR;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuIoInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- CpuIo driver entry point.\r
-\r
-Arguments:\r
-\r
- ImageHandle - The firmware allocated handle for the EFI image.\r
- SystemTable - A pointer to the EFI System Table.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The driver was initialized.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuMemoryServiceRead (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the memory mapped I/O read service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the memory mapped I/O operation\r
- Address - Base address of the memory mapped I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the destination buffer to store the results\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was read.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuMemoryServiceWrite (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the memory mapped I/O write service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the memory mapped I/O operation\r
- Address - Base address of the memory mapped I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the source buffer from which to write data\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was written.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuIoServiceRead (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 UserAddress,\r
- IN UINTN Count,\r
- OUT VOID *UserBuffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the port I/O read service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the port I/O operation\r
- Address - Base address of the port I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the destination buffer to store the results\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was read.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CpuIoServiceWrite (\r
- IN EFI_CPU_IO_PROTOCOL *This,\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 UserAddress,\r
- IN UINTN Count,\r
- IN VOID *UserBuffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Perform the port I/O write service\r
-\r
-Arguments:\r
-\r
- This - Pointer to an instance of the CPU I/O Protocol\r
- Width - Width of the port I/O operation\r
- Address - Base address of the port I/O operation\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the source buffer from which to write data\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was written.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_INVALID_PARAMETER - Buffer is NULL.\r
- EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
- EFI_UNSUPPORTED - The address range specified by Address, Width,\r
- and Count is not valid.\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-CpuIoCheckParameter (\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN VOID *Buffer,\r
- IN UINT64 Limit\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Check the validation of parameters for CPU I/O interface functions.\r
-\r
-Arguments:\r
-\r
- Width - Width of the Memory Access\r
- Address - Address of the Memory access\r
- Count - Count of the number of accesses to perform\r
- Buffer - Pointer to the buffer to read from memory\r
- Buffer - Memory buffer for the I/O operation\r
- Limit - Maximum address supported\r
-\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - Buffer is NULL\r
- EFI_UNSUPPORTED - The address range specified by Width, Address and Count is invalid\r
- EFI_UNSUPPORTED - The memory buffer is not aligned\r
- EFI_SUCCESS - Parameters are OK\r
-\r
---*/\r
-;\r
-\r
-#endif\r
+++ /dev/null
-#/*++\r
-# \r
-# Copyright (c) 2004, Intel Corporation \r
-# All rights reserved. This program and the accompanying materials \r
-# are licensed and made available under the terms and conditions of the BSD License \r
-# which accompanies this distribution. The full text of the license may be found at \r
-# http://opensource.org/licenses/bsd-license.php \r
-# \r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-#\r
-# Module Name:\r
-#\r
-# CpuIo.inf\r
-#\r
-# Abstract:\r
-#\r
-# Component description file for CpuIo module\r
-#\r
-#--*/\r
-\r
-[Defines]\r
- INF_VERSION = 0x00010005\r
- BASE_NAME = CpuIo\r
- FILE_GUID = BAE7599F-3C6B-43b7-BDF0-9CE07AA91AA6\r
- MODULE_TYPE = DXE_DRIVER\r
- VERSION_STRING = 1.0\r
- EDK_RELEASE_VERSION = 0x00020000\r
- EFI_SPECIFICATION_VERSION = 0x00020000\r
-\r
- ENTRY_POINT = CpuIoInitialize\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- IntelFrameworkPkg/IntelFrameworkPkg.dec\r
-\r
-[LibraryClasses]\r
- BaseLib\r
- DebugLib\r
- UefiDriverEntryPoint\r
- IoLib\r
-\r
-[Sources.common]\r
- CpuIo.c\r
- CpuIo.h\r
-\r
-[Protocols]\r
- gEfiCpuIoProtocolGuid\r
- \r
-[Depex]\r
- TRUE
#\r
\r
[Components.common]\r
- UefiCpuPkg/CpuIoDxe/CpuIo.inf\r
+ UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf\r
UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf\r