]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c
OvmfPkg/QemuFwCfgLib: Implement SEV internal function for SEC phase
[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/DebugLib.h>
21 #include <Library/QemuFwCfgLib.h>
22
23 #include "QemuFwCfgLibInternal.h"
24
25 /**
26 Returns a boolean indicating if the firmware configuration interface
27 is available or not.
28
29 This function may change fw_cfg state.
30
31 @retval TRUE The interface is available
32 @retval FALSE The interface is not available
33
34 **/
35 BOOLEAN
36 EFIAPI
37 QemuFwCfgIsAvailable (
38 VOID
39 )
40 {
41 UINT32 Signature;
42 UINT32 Revision;
43
44 QemuFwCfgSelectItem (QemuFwCfgItemSignature);
45 Signature = QemuFwCfgRead32 ();
46 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
47 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
48 Revision = QemuFwCfgRead32 ();
49 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
50 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
51 (Revision < 1)
52 ) {
53 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
54 return FALSE;
55 }
56
57 DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
58 return TRUE;
59 }
60
61
62 /**
63 Returns a boolean indicating if the firmware configuration interface is
64 available for library-internal purposes.
65
66 This function never changes fw_cfg state.
67
68 @retval TRUE The interface is available internally.
69 @retval FALSE The interface is not available internally.
70 **/
71 BOOLEAN
72 InternalQemuFwCfgIsAvailable (
73 VOID
74 )
75 {
76 //
77 // We always return TRUE, because the consumer of this library ought to have
78 // called QemuFwCfgIsAvailable before making other calls which would hit this
79 // path.
80 //
81 return TRUE;
82 }
83
84 /**
85 Returns a boolean indicating whether QEMU provides the DMA-like access method
86 for fw_cfg.
87
88 @retval TRUE The DMA-like access method is available.
89 @retval FALSE The DMA-like access method is unavailable.
90 **/
91 BOOLEAN
92 InternalQemuFwCfgDmaIsAvailable (
93 VOID
94 )
95 {
96 return FALSE;
97 }
98
99 /**
100
101 Returns a boolean indicating whether SEV is enabled
102
103 @retval TRUE SEV is enabled
104 @retval FALSE SEV is disabled
105 **/
106 BOOLEAN
107 InternalQemuFwCfgSevIsEnabled (
108 VOID
109 )
110 {
111 //
112 // DMA is not supported in SEC phase hence SEV support is irrelevant
113 //
114 return FALSE;
115 }
116
117 /**
118 Allocate a bounce buffer for SEV DMA.
119
120 @param[in] NumPage Number of pages.
121 @param[out] Buffer Allocated DMA Buffer pointer
122
123 **/
124 VOID
125 InternalQemuFwCfgSevDmaAllocateBuffer (
126 OUT VOID **Buffer,
127 IN UINT32 NumPages
128 )
129 {
130 //
131 // We should never reach here
132 //
133 ASSERT (FALSE);
134 }
135
136 /**
137 Free the DMA buffer allocated using InternalQemuFwCfgSevDmaAllocateBuffer
138
139 @param[in] NumPage Number of pages.
140 @param[in] Buffer DMA Buffer pointer
141
142 **/
143 VOID
144 InternalQemuFwCfgSevDmaFreeBuffer (
145 IN VOID *Buffer,
146 IN UINT32 NumPages
147 )
148 {
149 //
150 // We should never reach here
151 //
152 ASSERT (FALSE);
153 }