+/** @file\r
+\r
+ Stateful and implicitly initialized fw_cfg library implementation.\r
+\r
+ Copyright (C) 2013, Red Hat, Inc.\r
+ Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ 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, WITHOUT\r
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/QemuFwCfgLib.h>\r
+\r
+#include "QemuFwCfgLibInternal.h"\r
+\r
+STATIC BOOLEAN mQemuFwCfgSupported = FALSE;\r
+STATIC BOOLEAN mQemuFwCfgDmaSupported;\r
+\r
+\r
+/**\r
+ Returns a boolean indicating if the firmware configuration interface\r
+ is available or not.\r
+\r
+ This function may change fw_cfg state.\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 InternalQemuFwCfgIsAvailable ();\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
+ // For probing we always use the IO Port (IoReadFifo8()) access method.\r
+ //\r
+ mQemuFwCfgSupported = TRUE;\r
+ mQemuFwCfgDmaSupported = FALSE;\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
+ if ((Revision & FW_CFG_F_DMA) == 0) {\r
+ DEBUG ((DEBUG_INFO, "QemuFwCfg interface (IO Port) is supported.\n"));\r
+ } else {\r
+ mQemuFwCfgDmaSupported = TRUE;\r
+ DEBUG ((DEBUG_INFO, "QemuFwCfg interface (DMA) is supported.\n"));\r
+ }\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ Returns a boolean indicating if the firmware configuration interface is\r
+ available for library-internal purposes.\r
+\r
+ This function never changes fw_cfg state.\r
+\r
+ @retval TRUE The interface is available internally.\r
+ @retval FALSE The interface is not available internally.\r
+**/\r
+BOOLEAN\r
+InternalQemuFwCfgIsAvailable (\r
+ VOID\r
+ )\r
+{\r
+ return mQemuFwCfgSupported;\r
+}\r
+\r
+/**\r
+ Returns a boolean indicating whether QEMU provides the DMA-like access method\r
+ for fw_cfg.\r
+\r
+ @retval TRUE The DMA-like access method is available.\r
+ @retval FALSE The DMA-like access method is unavailable.\r
+**/\r
+BOOLEAN\r
+InternalQemuFwCfgDmaIsAvailable (\r
+ VOID\r
+ )\r
+{\r
+ return mQemuFwCfgDmaSupported;\r
+}\r