--*/\r
\r
#include "CpuIo.h"\r
-#include "CpuIoAccess.h"\r
\r
#define IA32_MAX_IO_ADDRESS 0xFFFF\r
\r
switch (Width) {\r
case EfiCpuIoWidthUint8:\r
for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- *Buffer.ui8 = CpuIoRead8 ((UINT16) Address);\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 = CpuIoRead16 ((UINT16) Address);\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 = CpuIoRead32 ((UINT16) Address);\r
+ *Buffer.ui32 = IoRead32 ((UINTN) Address);\r
}\r
break;\r
\r
switch (Width) {\r
case EfiCpuIoWidthUint8:\r
for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- CpuIoWrite8 ((UINT16) Address, *Buffer.ui8);\r
+ IoWrite8 ((UINTN) Address, *Buffer.ui8);\r
}\r
break;\r
\r
case EfiCpuIoWidthUint16:\r
for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- CpuIoWrite16 ((UINT16) Address, *Buffer.ui16);\r
+ IoWrite16 ((UINTN) Address, *Buffer.ui16);\r
}\r
break;\r
\r
case EfiCpuIoWidthUint32:\r
for (; Count > 0; Count--, Buffer.buf += OutStride, Address += InStride) {\r
- CpuIoWrite32 ((UINT16) Address, *Buffer.ui32);\r
+ IoWrite32 ((UINTN) Address, *Buffer.ui32);\r
}\r
break;\r
\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
[Sources.common]\r
CpuIo.c\r
CpuIo.h\r
- CpuIoAccess.h\r
-\r
-[Sources.IA32]\r
- Ia32/CpuIoAccess.asm | MSFT\r
- Ia32/CpuIoAccess.asm | INTEL\r
- Ia32/CpuIoAccessGNU.c | GCC\r
- \r
-[Sources.X64]\r
- X64/CpuIoAccess.asm\r
\r
[Protocols]\r
gEfiCpuIoProtocolGuid\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
-\r
-Module Name:\r
-\r
- CpuIoAccess.h\r
-\r
-Abstract:\r
-\r
---*/\r
-\r
-#ifndef _CPU_IO_ACCESS_H\r
-#define _CPU_IO_ACCESS_H\r
-\r
-\r
-UINT8\r
-EFIAPI\r
-CpuIoRead8 (\r
- IN UINT16 Port\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Port - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-/*++ \r
-Routine Description: \r
- Cpu I/O read port\r
-Arguments: \r
- Port: - Port number to read \r
-Returns: \r
- Return read 8 bit value \r
---*/\r
-UINT16\r
-EFIAPI\r
-CpuIoRead16 (\r
- IN UINT16 Port\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Port - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-/*++ \r
-Routine Description: \r
- Cpu I/O read port\r
-Arguments: \r
- Port: - Port number to read \r
-Returns: \r
- Return read 16 bit value \r
---*/\r
-UINT32\r
-EFIAPI\r
-CpuIoRead32 (\r
- IN UINT16 Port\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Port - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-/*++ \r
-Routine Description: \r
- Cpu I/O read port\r
-Arguments: \r
- Port: - Port number to read \r
-Returns: \r
- Return read 32 bit value \r
---*/\r
-VOID\r
-EFIAPI\r
-CpuIoWrite8 (\r
- IN UINT16 Port,\r
- IN UINT32 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Port - GC_TODO: add argument description\r
- Data - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-/*++ \r
-Routine Description: \r
- Cpu I/O write 8 bit data to port\r
-Arguments: \r
- Port: - Port number to read \r
- Data: - Data to write to the Port \r
-Returns: \r
- None \r
---*/\r
-VOID\r
-EFIAPI\r
-CpuIoWrite16 (\r
- IN UINT16 Port,\r
- IN UINT32 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Port - GC_TODO: add argument description\r
- Data - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-/*++ \r
-Routine Description: \r
- Cpu I/O write 16 bit data to port\r
-Arguments: \r
- Port: - Port number to read \r
- Data: - Data to write to the Port \r
-Returns: \r
- None \r
---*/\r
-VOID\r
-EFIAPI\r
-CpuIoWrite32 (\r
- IN UINT16 Port,\r
- IN UINT32 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Port - GC_TODO: add argument description\r
- Data - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-/*++ \r
-Routine Description: \r
- Cpu I/O write 32 bit data to port\r
-Arguments: \r
- Port: - Port number to read \r
- Data: - Data to write to the Port \r
-Returns: \r
- None \r
---*/\r
-#endif\r
+++ /dev/null
- title CpuIoAccess.asm\r
-;------------------------------------------------------------------------------\r
-;*\r
-;* Copyright (c) 2005, 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
-;* CpuIoAccess.asm\r
-;* \r
-;* Abstract: \r
-;* Supports IA32 CPU IO operation\r
-;* \r
-;------------------------------------------------------------------------------\r
-;\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .686\r
- .MODEL FLAT,C\r
- .CODE\r
-\r
-\r
-UINT8 TYPEDEF BYTE\r
-UINT16 TYPEDEF WORD\r
-UINT32 TYPEDEF DWORD\r
-UINT64 TYPEDEF QWORD\r
-UINTN TYPEDEF UINT32\r
-\r
-\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT8\r
-; CpuIoRead8 (\r
-; IN UINT16 Port\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoRead8 PROC PUBLIC Port:UINT16\r
- mov dx, Port\r
- in al, dx\r
- ret\r
-CpuIoRead8 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT16\r
-; CpuIoRead16 (\r
-; IN UINT16 Port\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoRead16 PROC PUBLIC Port:UINT16\r
- mov dx, Port\r
- in ax, dx\r
- ret\r
-CpuIoRead16 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT32\r
-; CpuIoRead32 (\r
-; IN UINT16 Port\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoRead32 PROC PUBLIC Port:UINT16\r
- mov dx, Port\r
- in eax, dx\r
- ret\r
-CpuIoRead32 ENDP\r
-\r
-\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; CpuIoWrite8 (\r
-; IN UINT16 Port,\r
-; IN UINT32 Data\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoWrite8 PROC PUBLIC Port:UINT16, Data:UINT32\r
- mov eax, Data\r
- mov dx, Port\r
- out dx, al\r
- ret\r
-CpuIoWrite8 ENDP\r
-\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; CpuIoWrite16 (\r
-; IN UINT16 Port,\r
-; IN UINT32 Data\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoWrite16 PROC PUBLIC Port:UINT16, Data:UINT32\r
- mov eax, Data\r
- mov dx, Port\r
- out dx, ax\r
- ret\r
-CpuIoWrite16 ENDP\r
-\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; CpuIoWrite32 (\r
-; IN UINT16 Port,\r
-; IN UINT32 Data\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoWrite32 PROC PUBLIC Port:UINT16, Data:UINT32\r
- mov eax, Data\r
- mov dx, Port\r
- out dx, eax\r
- ret\r
-CpuIoWrite32 ENDP\r
-\r
-\r
-END
\ No newline at end of file
+++ /dev/null
-/* This file is only used when not able to compile the MASM CpuIoAccess.asm\r
- NOTE: Compiling with -fomit-frame-pointer would get you to roughly the exact\r
- same code as the MASM file although GCC will typically include movzbl %al, %eax\r
- or movzwl %ax, %eax instructions on the read functions such that the entire\r
- eax result register will be valid, not just the lowest 8 or 16 bits.\r
- */\r
-#ifdef __GNUC__\r
-\r
-/* A quick note about GCC inline asm and the GNU assembler:\r
- When gas encounters an instruction with a suffix (e.g. inb, inw, or inl vs. just in) it will\r
- warn if the operand corresponding to the suffix is not of the correct size and will assume you\r
- meant what you said when you specified the suffix.\r
-\r
- Because GCC does not enable us to see whether it is replacing %0 with %al, %ax, or %eax it is\r
- helpful to have the assembler warn us that GCC is making an incorrect assumption. The actual\r
- in or out instruction will always be generated correctly in this case since the assembler is\r
- correct in assuming we meant what we said when we specified the suffix. However, GCC might\r
- generate incorrect surrounding code. For example, if we were to incorrectly specify the\r
- output size of an in instruction as UINT32, GCC would potentially fail to issue movz(b|w)l after\r
- it under the assumption that the in instruction filled the entire eax register and not just\r
- the al or ax portion.\r
-\r
- GCC determines which size of register to use based on the C data type. So for in instructions\r
- the interesting type is that of the automatic variable named Data which is specified as an\r
- output operand to the inline assembly statement. For example:\r
-\r
- UINT8 Data;\r
- asm ( "inb %1, %0"\r
- : "=a"(Data)\r
- : "d"(Port)\r
- );\r
- return Data;\r
-\r
- In this case, GCC will replace %0 with %al. If Data had been specified as UINT16, it would replace\r
- %0 with %ax, and for UINT32 with %eax.\r
-\r
- Likewise in the case of IA32 out instructions, GCC will replace %0 with the appropriately sized\r
- register based on the size of the input operand. There is one gotcha though. The CpuIoWrite\r
- series of functions all use UINT32 as the type of the second (Data) argument. This means that\r
- for GCC to output the correct register size we must cast it appropriately.\r
-\r
- The Port number is always a UINT16 so GCC will always ouput %dx.\r
- */\r
-\r
-#include "CpuIoAccess.h"\r
-\r
-UINT8\r
-EFIAPI\r
-CpuIoRead8 (\r
- IN UINT16 Port\r
- )\r
-{\r
- UINT8 Data;\r
- asm ( "inb %1, %0"\r
- : "=a"(Data)\r
- : "d"(Port)\r
- );\r
- return Data;\r
-}\r
-\r
-UINT16\r
-EFIAPI\r
-CpuIoRead16 (\r
- IN UINT16 Port\r
- )\r
-{\r
- UINT16 Data;\r
- asm ( "inw %1, %0"\r
- : "=a"(Data)\r
- : "d"(Port)\r
- );\r
- return Data;\r
-}\r
-\r
-UINT32\r
-EFIAPI\r
-CpuIoRead32 (\r
- IN UINT16 Port\r
- )\r
-{\r
- UINT32 Data;\r
- asm ( "inl %1, %0"\r
- : "=a"(Data)\r
- : "d"(Port)\r
- );\r
- return Data;\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-CpuIoWrite8 (\r
- IN UINT16 Port,\r
- IN UINT32 Data\r
- )\r
-{\r
- asm ( "outb %1, %0"\r
- : /* No outputs */\r
- : "d"(Port)\r
- , "a"((UINT8)Data)\r
- );\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-CpuIoWrite16 (\r
- IN UINT16 Port,\r
- IN UINT32 Data\r
- )\r
-{\r
- asm ( "outw %1, %0"\r
- : /* No outputs */\r
- : "d"(Port)\r
- , "a"((UINT16)Data)\r
- );\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-CpuIoWrite32 (\r
- IN UINT16 Port,\r
- IN UINT32 Data\r
- )\r
-{\r
- asm ( "outl %1, %0"\r
- : /* No outputs */\r
- : "d"(Port)\r
- /* NOTE: Cast is technically unnecessary but we use it to illustrate\r
- that we always want to output a UINT32 and never anything else.\r
- */\r
- , "a"((UINT32)Data) \r
- );\r
-}\r
-\r
-#endif /* def __GNUC__ */\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
- Ia32CpuIo.dxs\r
-\r
-Abstract:\r
-\r
- Dependency expression source file.\r
- \r
---*/ \r
-\r
-#include "EfiDepex.h"\r
-\r
-\r
-DEPENDENCY_START\r
- TRUE \r
-DEPENDENCY_END\r
+++ /dev/null
- title CpuIoAccess.asm\r
-\r
-;------------------------------------------------------------------------------\r
-;*\r
-;* Copyright (c) 2005 - 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
-;* CpuIoAccess.asm\r
-;* \r
-;* Abstract:\r
-;* Supports x64 CPU IO operation\r
-;*\r
-;------------------------------------------------------------------------------\r
-;\r
-; \r
-; \r
-; Abstract:\r
-; \r
-; \r
-;------------------------------------------------------------------------------\r
-\r
-.CODE\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT8\r
-; CpuIoRead8 (\r
-; UINT16 Port // rcx\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoRead8 PROC PUBLIC\r
- xor eax, eax\r
- mov dx, cx\r
- in al, dx\r
- ret\r
-CpuIoRead8 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; CpuIoWrite8 (\r
-; UINT16 Port, // rcx\r
-; UINT32 Data // rdx\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoWrite8 PROC PUBLIC\r
- mov eax, edx\r
- mov dx, cx\r
- out dx, al\r
- ret\r
-CpuIoWrite8 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT16\r
-; CpuIoRead16 (\r
-; UINT16 Port // rcx\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoRead16 PROC PUBLIC\r
- xor eax, eax\r
- mov dx, cx\r
- in ax, dx\r
- ret\r
-CpuIoRead16 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; CpuIoWrite16 (\r
-; UINT16 Port, // rcx\r
-; UINT32 Data // rdx\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoWrite16 PROC PUBLIC\r
- mov eax, edx\r
- mov dx, cx\r
- out dx, ax\r
- ret\r
-CpuIoWrite16 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT32\r
-; CpuIoRead32 (\r
-; UINT16 Port // rcx\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoRead32 PROC PUBLIC\r
- mov dx, cx\r
- in eax, dx\r
- ret\r
-CpuIoRead32 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; CpuIoWrite32 (\r
-; UINT16 Port, // rcx\r
-; UINT32 Data // rdx\r
-; )\r
-;------------------------------------------------------------------------------\r
-CpuIoWrite32 PROC PUBLIC\r
- mov eax, edx\r
- mov dx, cx\r
- out dx, eax\r
- ret\r
-CpuIoWrite32 ENDP\r
-\r
-END\r