3 Stateful and implicitly initialized fw_cfg library implementation.
5 Copyright (C) 2013, Red Hat, Inc.
6 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugLib.h>
18 #include <Library/QemuFwCfgLib.h>
20 #include "QemuFwCfgLibInternal.h"
22 STATIC BOOLEAN mQemuFwCfgSupported
= FALSE
;
23 STATIC BOOLEAN mQemuFwCfgDmaSupported
;
27 Returns a boolean indicating if the firmware configuration interface
30 This function may change fw_cfg state.
32 @retval TRUE The interface is available
33 @retval FALSE The interface is not available
38 QemuFwCfgIsAvailable (
42 return InternalQemuFwCfgIsAvailable ();
56 // Enable the access routines while probing to see if it is supported.
57 // For probing we always use the IO Port (IoReadFifo8()) access method.
59 mQemuFwCfgSupported
= TRUE
;
60 mQemuFwCfgDmaSupported
= FALSE
;
62 QemuFwCfgSelectItem (QemuFwCfgItemSignature
);
63 Signature
= QemuFwCfgRead32 ();
64 DEBUG ((EFI_D_INFO
, "FW CFG Signature: 0x%x\n", Signature
));
65 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion
);
66 Revision
= QemuFwCfgRead32 ();
67 DEBUG ((EFI_D_INFO
, "FW CFG Revision: 0x%x\n", Revision
));
68 if ((Signature
!= SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
71 DEBUG ((EFI_D_INFO
, "QemuFwCfg interface not supported.\n"));
72 mQemuFwCfgSupported
= FALSE
;
73 return RETURN_SUCCESS
;
76 if ((Revision
& FW_CFG_F_DMA
) == 0) {
77 DEBUG ((DEBUG_INFO
, "QemuFwCfg interface (IO Port) is supported.\n"));
79 mQemuFwCfgDmaSupported
= TRUE
;
80 DEBUG ((DEBUG_INFO
, "QemuFwCfg interface (DMA) is supported.\n"));
82 return RETURN_SUCCESS
;
87 Returns a boolean indicating if the firmware configuration interface is
88 available for library-internal purposes.
90 This function never changes fw_cfg state.
92 @retval TRUE The interface is available internally.
93 @retval FALSE The interface is not available internally.
96 InternalQemuFwCfgIsAvailable (
100 return mQemuFwCfgSupported
;
104 Returns a boolean indicating whether QEMU provides the DMA-like access method
107 @retval TRUE The DMA-like access method is available.
108 @retval FALSE The DMA-like access method is unavailable.
111 InternalQemuFwCfgDmaIsAvailable (
115 return mQemuFwCfgDmaSupported
;