--- /dev/null
+/** @file\r
+ QEMU/KVM Firmware Configuration access\r
+\r
+ Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
+ 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 __FW_CFG_LIB__\r
+#define __FW_CFG_LIB__\r
+\r
+typedef enum {\r
+ QemuFwCfgItemSignature = 0x0000,\r
+ QemuFwCfgItemInterfaceVersion = 0x0001,\r
+ QemuFwCfgItemSystemUuid = 0x0002,\r
+ QemuFwCfgItemRamSize = 0x0003,\r
+ QemuFwCfgItemGraphicsEnabled = 0x0004,\r
+ QemuFwCfgItemSmpCpuCount = 0x0005,\r
+ QemuFwCfgItemMachineId = 0x0006,\r
+ QemuFwCfgItemKernelAddress = 0x0007,\r
+ QemuFwCfgItemKernelSize = 0x0008,\r
+ QemuFwCfgItemKernelCommandLine = 0x0009,\r
+ QemuFwCfgItemInitrdAddress = 0x000a,\r
+ QemuFwCfgItemInitrdSize = 0x000b,\r
+ QemuFwCfgItemBootDevice = 0x000c,\r
+ QemuFwCfgItemNumaData = 0x000d,\r
+ QemuFwCfgItemBootMenu = 0x000e,\r
+ QemuFwCfgItemMaximumCpuCount = 0x000f,\r
+ QemuFwCfgItemKernelEntry = 0x0010,\r
+ QemuFwCfgItemKernelData = 0x0011,\r
+ QemuFwCfgItemInitrdData = 0x0012,\r
+ QemuFwCfgItemCommandLineAddress = 0x0013,\r
+ QemuFwCfgItemCommandLineSize = 0x0014,\r
+ QemuFwCfgItemCommandLineData = 0x0015,\r
+ QemuFwCfgItemKernelSetupAddress = 0x0016,\r
+ QemuFwCfgItemKernelSetupSize = 0x0017,\r
+ QemuFwCfgItemKernelSetupData = 0x0018,\r
+\r
+ QemuFwCfgItemX86AcpiTables = 0x8000,\r
+ QemuFwCfgItemX86SmbiosTables = 0x8001,\r
+ QemuFwCfgItemX86Irq0Override = 0x8002,\r
+ QemuFwCfgItemX86E820Table = 0x8003,\r
+ QemuFwCfgItemX86HpetData = 0x8004,\r
+\r
+} FIRMWARE_CONFIG_ITEM;\r
+\r
+\r
+/**\r
+ Returns a boolean indicating if the firmware configuration interface\r
+ is available or not.\r
+\r
+ @retval TRUE The interface is available\r
+ @retval FALSE The interface is not available\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+QemuFwCfgIsAvailable (\r
+ VOID\r
+ );\r
+\r
+\r
+/**\r
+ Selects a firmware configuration item for reading.\r
+\r
+ Following this call, any data read from this item will start from\r
+ the beginning of the configuration item's data.\r
+\r
+ @param[in] QemuFwCfgItem - Firmware Configuration item to read\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+QemuFwCfgSelectItem (\r
+ IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem\r
+ );\r
+\r
+\r
+/**\r
+ Reads firmware configuration bytes into a buffer\r
+\r
+ If called multiple times, then the data read will\r
+ continue at the offset of the firmware configuration\r
+ item where the previous read ended.\r
+\r
+ @param[in] Size - Size in bytes to read\r
+ @param[in] Buffer - Buffer to store data into\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+QemuFwCfgReadBytes (\r
+ IN UINTN Size,\r
+ IN VOID *Buffer OPTIONAL\r
+ );\r
+\r
+\r
+/**\r
+ Reads a UINT8 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+QemuFwCfgRead8 (\r
+ VOID\r
+ );\r
+\r
+\r
+/**\r
+ Reads a UINT16 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+QemuFwCfgRead16 (\r
+ VOID\r
+ );\r
+\r
+\r
+/**\r
+ Reads a UINT32 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+QemuFwCfgRead32 (\r
+ VOID\r
+ );\r
+\r
+\r
+/**\r
+ Reads a UINT64 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+QemuFwCfgRead64 (\r
+ VOID\r
+ );\r
+\r
+\r
+#endif\r
+\r
--- /dev/null
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+# 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
+#------------------------------------------------------------------------------\r
+# VOID\r
+# EFIAPI\r
+# IoReadFifo8 (\r
+# IN UINTN Port,\r
+# IN UINTN Size,\r
+# IN VOID *Buffer\r
+# );\r
+#------------------------------------------------------------------------------\r
+ASM_GLOBAL ASM_PFX(IoReadFifo8)\r
+ASM_PFX(IoReadFifo8):\r
+ movw 4(%esp), %dx\r
+ movl 8(%esp), %ecx\r
+ pushl %edi\r
+ movl 16(%esp), %edi\r
+rep insb\r
+ popl %edi\r
+ ret\r
+\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+; 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
+ .586P\r
+ .model flat,C\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; IoReadFifo8 (\r
+; IN UINTN Port,\r
+; IN UINTN Size,\r
+; IN VOID *Buffer\r
+; );\r
+;------------------------------------------------------------------------------\r
+IoReadFifo8 PROC\r
+\r
+ mov dx, [esp + 4]\r
+ mov ecx, [esp + 8]\r
+ push edi\r
+ mov edx, [esp + 16]\r
+rep insb\r
+ pop edi\r
+ ret\r
+\r
+IoReadFifo8 ENDP\r
+\r
+ END\r
+\r
--- /dev/null
+/** @file\r
+\r
+ Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
+\r
+ 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 "Uefi.h"\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/QemuFwCfgLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+STATIC BOOLEAN mQemuFwCfgSupported = FALSE;\r
+\r
+\r
+/**\r
+ Reads an 8-bit I/O port fifo into a block of memory.\r
+\r
+ Reads the 8-bit I/O fifo port specified by Port.\r
+\r
+ The port is read Count times, and the read data is\r
+ stored in the provided Buffer.\r
+\r
+ This function must guarantee that all I/O read and write operations are\r
+ serialized.\r
+\r
+ If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+ @param Port The I/O port to read.\r
+ @param Count The number of times to read I/O port.\r
+ @param Buffer The buffer to store the read data into.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IoReadFifo8 (\r
+ IN UINTN Port,\r
+ IN UINTN Count,\r
+ OUT VOID *Buffer\r
+ );\r
+\r
+\r
+/**\r
+ Returns a boolean indicating if the firmware configuration interface\r
+ is available or not.\r
+\r
+ @retval TRUE The interface is available\r
+ @retval FALSE The interface is not available\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+QemuFwCfgIsAvailable (\r
+ VOID\r
+ )\r
+{\r
+ return mQemuFwCfgSupported;\r
+}\r
+\r
+\r
+/**\r
+ Selects a firmware configuration item for reading.\r
+ \r
+ Following this call, any data read from this item will start from\r
+ the beginning of the configuration item's data.\r
+\r
+ @param[in] QemuFwCfgItem - Firmware Configuration item to read\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+QemuFwCfgSelectItem (\r
+ IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem\r
+ )\r
+{\r
+ DEBUG ((EFI_D_INFO, "Select Item: 0x%x\n", (UINT16)(UINTN) QemuFwCfgItem));\r
+ IoWrite16 (0x510, (UINT16)(UINTN) QemuFwCfgItem);\r
+}\r
+\r
+\r
+/**\r
+ Reads firmware configuration bytes into a buffer\r
+\r
+ @param[in] Size - Size in bytes to read\r
+ @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0)\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InternalQemuFwCfgReadBytes (\r
+ IN UINTN Size,\r
+ IN VOID *Buffer OPTIONAL\r
+ )\r
+{\r
+ IoReadFifo8 (0x511, Size, Buffer);\r
+}\r
+\r
+\r
+/**\r
+ Reads firmware configuration bytes into a buffer\r
+\r
+ If called multiple times, then the data read will\r
+ continue at the offset of the firmware configuration\r
+ item where the previous read ended.\r
+\r
+ @param[in] Size - Size in bytes to read\r
+ @param[in] Buffer - Buffer to store data into\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+QemuFwCfgReadBytes (\r
+ IN UINTN Size,\r
+ IN VOID *Buffer\r
+ )\r
+{\r
+ if (mQemuFwCfgSupported) {\r
+ InternalQemuFwCfgReadBytes (Size, Buffer);\r
+ } else {\r
+ ZeroMem (Buffer, Size);\r
+ }\r
+}\r
+\r
+\r
+/**\r
+ Reads a UINT8 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+QemuFwCfgRead8 (\r
+ VOID\r
+ )\r
+{\r
+ UINT8 Result;\r
+\r
+ QemuFwCfgReadBytes (sizeof (Result), &Result);\r
+\r
+ return Result;\r
+}\r
+\r
+\r
+/**\r
+ Reads a UINT16 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+QemuFwCfgRead16 (\r
+ VOID\r
+ )\r
+{\r
+ UINT16 Result;\r
+\r
+ QemuFwCfgReadBytes (sizeof (Result), &Result);\r
+\r
+ return Result;\r
+}\r
+\r
+\r
+/**\r
+ Reads a UINT32 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+QemuFwCfgRead32 (\r
+ VOID\r
+ )\r
+{\r
+ UINT32 Result;\r
+\r
+ QemuFwCfgReadBytes (sizeof (Result), &Result);\r
+\r
+ return Result;\r
+}\r
+\r
+\r
+/**\r
+ Reads a UINT64 firmware configuration value\r
+\r
+ @return Value of Firmware Configuration item read\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+QemuFwCfgRead64 (\r
+ VOID\r
+ )\r
+{\r
+ UINT64 Result;\r
+\r
+ QemuFwCfgReadBytes (sizeof (Result), &Result);\r
+\r
+ return Result;\r
+}\r
+\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+QemuFwCfgInitialize (\r
+ VOID\r
+ )\r
+{\r
+ UINT32 Signature;\r
+ UINT32 Revision;\r
+\r
+ //\r
+ // Enable the access routines while probing to see if it is supported.\r
+ //\r
+ mQemuFwCfgSupported = TRUE;\r
+\r
+ QemuFwCfgSelectItem (QemuFwCfgItemSignature);\r
+ Signature = QemuFwCfgRead32 ();\r
+ DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));\r
+ QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);\r
+ Revision = QemuFwCfgRead32 ();\r
+ DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));\r
+ if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||\r
+ (Revision < 1)\r
+ ) {\r
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));\r
+ mQemuFwCfgSupported = FALSE;\r
+ return RETURN_SUCCESS;\r
+ }\r
+\r
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));\r
+ return RETURN_SUCCESS;\r
+}\r
--- /dev/null
+## @file\r
+#\r
+# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# 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 = QemuFwCfgLib\r
+ FILE_GUID = fdd53716-31e1-4acc-9007-8bd5d877c96f\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = QemuFwCfgLib\r
+\r
+ CONSTRUCTOR = QemuFwCfgInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64\r
+#\r
+\r
+[Sources]\r
+ QemuFwCfgLib.c\r
+\r
+[Sources.IA32]\r
+ Ia32/IoLibExAsm.asm\r
+ Ia32/IoLibExAsm.S\r
+\r
+[Sources.X64]\r
+ X64/IoLibExAsm.asm\r
+ X64/IoLibExAsm.S\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ IoLib\r
+ MemoryAllocationLib\r
+ UefiBootServicesTableLib\r
+\r
--- /dev/null
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+# 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
+#------------------------------------------------------------------------------\r
+# VOID\r
+# EFIAPI\r
+# IoReadFifo8 (\r
+# IN UINTN Port, // rcx\r
+# IN UINTN Size, // rdx\r
+# IN VOID *Buffer // r8\r
+# );\r
+#------------------------------------------------------------------------------\r
+ASM_GLOBAL ASM_PFX(IoReadFifo8)\r
+ASM_PFX(IoReadFifo8):\r
+ xchg %rcx, %rdx\r
+ xchg %r8, %rdi # rdi: buffer address; r8: save rdi\r
+rep insb\r
+ mov %r8, %rdi # restore rdi\r
+ ret\r
+\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+; 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
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; IoReadFifo8 (\r
+; IN UINTN Port, // rcx\r
+; IN UINTN Size, // rdx\r
+; IN VOID *Buffer // r8\r
+; );\r
+;------------------------------------------------------------------------------\r
+IoReadFifo8 PROC\r
+\r
+ xchg rcx, rdx\r
+ xchg rdi, r8 ; rdi: buffer address; r8: save rdi\r
+rep insb\r
+ mov rdi, r8 ; restore rdi\r
+ ret\r
+\r
+IoReadFifo8 ENDP\r
+\r
+ END\r
+\r
## @file\r
# EFI/Framework Open Virtual Machine Firmware (OVMF) platform\r
#\r
-# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
#\r
NvVarsFileLib|Include/Library/NvVarsFileLib.h\r
\r
+ ## @libraryclass Access QEMU's firmware configuration interface\r
+ #\r
+ QemuFwCfgLib|Include/Library/QemuFwCfgLib.h\r
+\r
## @libraryclass Serialize (and deserialize) variables\r
#\r
SerializeVariablesLib|Include/Library/SerializeVariablesLib.h\r
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf\r
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf\r
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf\r
+ LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf\r
\r
!ifdef $(SOURCE_DEBUG_ENABLE)\r
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf\r
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf\r
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf\r
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf\r
LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf\r
\r
!ifdef $(SOURCE_DEBUG_ENABLE)\r
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf\r
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf\r
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf\r
LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf\r
\r
!ifdef $(SOURCE_DEBUG_ENABLE)\r