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>
7 Copyright (c) 2017, Advanced Micro Devices. All rights reserved.<BR>
9 This program and the accompanying materials are licensed and made available
10 under the terms and conditions of the BSD License which accompanies this
11 distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
15 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/QemuFwCfgLib.h>
21 #include <Library/MemEncryptSevLib.h>
23 #include "QemuFwCfgLibInternal.h"
25 STATIC BOOLEAN mQemuFwCfgSupported
= FALSE
;
26 STATIC BOOLEAN mQemuFwCfgDmaSupported
;
30 Returns a boolean indicating if the firmware configuration interface
33 This function may change fw_cfg state.
35 @retval TRUE The interface is available
36 @retval FALSE The interface is not available
41 QemuFwCfgIsAvailable (
45 return InternalQemuFwCfgIsAvailable ();
59 // Enable the access routines while probing to see if it is supported.
60 // For probing we always use the IO Port (IoReadFifo8()) access method.
62 mQemuFwCfgSupported
= TRUE
;
63 mQemuFwCfgDmaSupported
= FALSE
;
65 QemuFwCfgSelectItem (QemuFwCfgItemSignature
);
66 Signature
= QemuFwCfgRead32 ();
67 DEBUG ((EFI_D_INFO
, "FW CFG Signature: 0x%x\n", Signature
));
68 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion
);
69 Revision
= QemuFwCfgRead32 ();
70 DEBUG ((EFI_D_INFO
, "FW CFG Revision: 0x%x\n", Revision
));
71 if ((Signature
!= SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
74 DEBUG ((EFI_D_INFO
, "QemuFwCfg interface not supported.\n"));
75 mQemuFwCfgSupported
= FALSE
;
76 return RETURN_SUCCESS
;
79 if ((Revision
& FW_CFG_F_DMA
) == 0) {
80 DEBUG ((DEBUG_INFO
, "QemuFwCfg interface (IO Port) is supported.\n"));
83 // If SEV is enabled then we do not support DMA operations in PEI phase.
84 // This is mainly because DMA in SEV guest requires using bounce buffer
85 // (which need to allocate dynamic memory and allocating a PAGE size'd
86 // buffer can be challenge in PEI phase)
88 if (InternalQemuFwCfgSevIsEnabled ()) {
89 DEBUG ((DEBUG_INFO
, "SEV: QemuFwCfg fallback to IO Port interface.\n"));
91 mQemuFwCfgDmaSupported
= TRUE
;
92 DEBUG ((DEBUG_INFO
, "QemuFwCfg interface (DMA) is supported.\n"));
95 return RETURN_SUCCESS
;
100 Returns a boolean indicating if the firmware configuration interface is
101 available for library-internal purposes.
103 This function never changes fw_cfg state.
105 @retval TRUE The interface is available internally.
106 @retval FALSE The interface is not available internally.
109 InternalQemuFwCfgIsAvailable (
113 return mQemuFwCfgSupported
;
117 Returns a boolean indicating whether QEMU provides the DMA-like access method
120 @retval TRUE The DMA-like access method is available.
121 @retval FALSE The DMA-like access method is unavailable.
124 InternalQemuFwCfgDmaIsAvailable (
128 return mQemuFwCfgDmaSupported
;
133 Returns a boolean indicating whether SEV is enabled
135 @retval TRUE SEV is enabled
136 @retval FALSE SEV is disabled
139 InternalQemuFwCfgSevIsEnabled (
143 return MemEncryptSevIsEnabled ();
147 Allocate a bounce buffer for SEV DMA.
149 @param[in] NumPage Number of pages.
150 @param[out] Buffer Allocated DMA Buffer pointer
154 InternalQemuFwCfgSevDmaAllocateBuffer (
160 // We should never reach here
167 Free the DMA buffer allocated using InternalQemuFwCfgSevDmaAllocateBuffer
169 @param[in] NumPage Number of pages.
170 @param[in] Buffer DMA Buffer pointer
174 InternalQemuFwCfgSevDmaFreeBuffer (
180 // We should never reach here