]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Moving DuetPkg/CpuIoDxe to UefiCpuPkg.
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Feb 2009 19:56:13 +0000 (19:56 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Feb 2009 19:56:13 +0000 (19:56 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7608 6f19259b-4bc3-4df7-8a09-765794883524

DuetPkg/CpuIoDxe/CpuIo.c [deleted file]
DuetPkg/CpuIoDxe/CpuIo.h [deleted file]
DuetPkg/CpuIoDxe/CpuIo.inf [deleted file]
UefiCpuPkg/CpuIoDxe/CpuIo.c [new file with mode: 0644]
UefiCpuPkg/CpuIoDxe/CpuIo.h [new file with mode: 0644]
UefiCpuPkg/CpuIoDxe/CpuIo.inf [new file with mode: 0644]

diff --git a/DuetPkg/CpuIoDxe/CpuIo.c b/DuetPkg/CpuIoDxe/CpuIo.c
deleted file mode 100644 (file)
index 729f556..0000000
+++ /dev/null
@@ -1,531 +0,0 @@
-/*++\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
diff --git a/DuetPkg/CpuIoDxe/CpuIo.h b/DuetPkg/CpuIoDxe/CpuIo.h
deleted file mode 100644 (file)
index 350d80c..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/*++\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
diff --git a/DuetPkg/CpuIoDxe/CpuIo.inf b/DuetPkg/CpuIoDxe/CpuIo.inf
deleted file mode 100644 (file)
index f9d50f6..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#/*++\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
-  DuetPkg/DuetPkg.dec\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
\ No newline at end of file
diff --git a/UefiCpuPkg/CpuIoDxe/CpuIo.c b/UefiCpuPkg/CpuIoDxe/CpuIo.c
new file mode 100644 (file)
index 0000000..729f556
--- /dev/null
@@ -0,0 +1,531 @@
+/*++\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
diff --git a/UefiCpuPkg/CpuIoDxe/CpuIo.h b/UefiCpuPkg/CpuIoDxe/CpuIo.h
new file mode 100644 (file)
index 0000000..350d80c
--- /dev/null
@@ -0,0 +1,244 @@
+/*++\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
diff --git a/UefiCpuPkg/CpuIoDxe/CpuIo.inf b/UefiCpuPkg/CpuIoDxe/CpuIo.inf
new file mode 100644 (file)
index 0000000..f9d50f6
--- /dev/null
@@ -0,0 +1,52 @@
+#/*++\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
+  DuetPkg/DuetPkg.dec\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
\ No newline at end of file