]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c
OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map
[mirror_edk2.git] / OvmfPkg / Library / QemuFwCfgLib / QemuFwCfgSec.c
1 /** @file
2
3 Stateless fw_cfg library implementation.
4
5 Clients must call QemuFwCfgIsAvailable() first.
6
7 Copyright (C) 2013, Red Hat, Inc.
8 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
9 Copyright (c) 2017, Advanced Micro Devices. All rights reserved.<BR>
10
11 This program and the accompanying materials are licensed and made available
12 under the terms and conditions of the BSD License which accompanies this
13 distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
15
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
17 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 **/
19
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/QemuFwCfgLib.h>
23
24 #include "QemuFwCfgLibInternal.h"
25
26 /**
27 Returns a boolean indicating if the firmware configuration interface
28 is available or not.
29
30 This function may change fw_cfg state.
31
32 @retval TRUE The interface is available
33 @retval FALSE The interface is not available
34
35 **/
36 BOOLEAN
37 EFIAPI
38 QemuFwCfgIsAvailable (
39 VOID
40 )
41 {
42 UINT32 Signature;
43 UINT32 Revision;
44
45 QemuFwCfgSelectItem (QemuFwCfgItemSignature);
46 Signature = QemuFwCfgRead32 ();
47 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
48 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
49 Revision = QemuFwCfgRead32 ();
50 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
51 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
52 (Revision < 1)
53 ) {
54 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
55 return FALSE;
56 }
57
58 DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
59 return TRUE;
60 }
61
62
63 /**
64 Returns a boolean indicating if the firmware configuration interface is
65 available for library-internal purposes.
66
67 This function never changes fw_cfg state.
68
69 @retval TRUE The interface is available internally.
70 @retval FALSE The interface is not available internally.
71 **/
72 BOOLEAN
73 InternalQemuFwCfgIsAvailable (
74 VOID
75 )
76 {
77 //
78 // We always return TRUE, because the consumer of this library ought to have
79 // called QemuFwCfgIsAvailable before making other calls which would hit this
80 // path.
81 //
82 return TRUE;
83 }
84
85 /**
86 Returns a boolean indicating whether QEMU provides the DMA-like access method
87 for fw_cfg.
88
89 @retval TRUE The DMA-like access method is available.
90 @retval FALSE The DMA-like access method is unavailable.
91 **/
92 BOOLEAN
93 InternalQemuFwCfgDmaIsAvailable (
94 VOID
95 )
96 {
97 return FALSE;
98 }
99
100 /**
101 Transfer an array of bytes, or skip a number of bytes, using the DMA
102 interface.
103
104 @param[in] Size Size in bytes to transfer or skip.
105
106 @param[in,out] Buffer Buffer to read data into or write data from. Ignored,
107 and may be NULL, if Size is zero, or Control is
108 FW_CFG_DMA_CTL_SKIP.
109
110 @param[in] Control One of the following:
111 FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buffer.
112 FW_CFG_DMA_CTL_READ - read from fw_cfg into Buffer.
113 FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg.
114 **/
115 VOID
116 InternalQemuFwCfgDmaBytes (
117 IN UINT32 Size,
118 IN OUT VOID *Buffer OPTIONAL,
119 IN UINT32 Control
120 )
121 {
122 //
123 // We should never reach here
124 //
125 ASSERT (FALSE);
126 CpuDeadLoop ();
127 }