]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c
OvmfPkg: Apply uncrustify changes
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
12 **/
13
14 #include <Library/BaseLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/QemuFwCfgLib.h>
17
18 #include "QemuFwCfgLibInternal.h"
19
20 /**
21 Returns a boolean indicating if the firmware configuration interface
22 is available or not.
23
24 This function may change fw_cfg state.
25
26 @retval TRUE The interface is available
27 @retval FALSE The interface is not available
28
29 **/
30 BOOLEAN
31 EFIAPI
32 QemuFwCfgIsAvailable (
33 VOID
34 )
35 {
36 UINT32 Signature;
37 UINT32 Revision;
38
39 QemuFwCfgSelectItem (QemuFwCfgItemSignature);
40 Signature = QemuFwCfgRead32 ();
41 DEBUG ((DEBUG_INFO, "FW CFG Signature: 0x%x\n", Signature));
42 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
43 Revision = QemuFwCfgRead32 ();
44 DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision));
45 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
46 (Revision < 1)
47 )
48 {
49 DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
50 return FALSE;
51 }
52
53 DEBUG ((DEBUG_INFO, "QemuFwCfg interface is supported.\n"));
54 return TRUE;
55 }
56
57 /**
58 Returns a boolean indicating if the firmware configuration interface is
59 available for library-internal purposes.
60
61 This function never changes fw_cfg state.
62
63 @retval TRUE The interface is available internally.
64 @retval FALSE The interface is not available internally.
65 **/
66 BOOLEAN
67 InternalQemuFwCfgIsAvailable (
68 VOID
69 )
70 {
71 //
72 // We always return TRUE, because the consumer of this library ought to have
73 // called QemuFwCfgIsAvailable before making other calls which would hit this
74 // path.
75 //
76 return TRUE;
77 }
78
79 /**
80 Returns a boolean indicating whether QEMU provides the DMA-like access method
81 for fw_cfg.
82
83 @retval TRUE The DMA-like access method is available.
84 @retval FALSE The DMA-like access method is unavailable.
85 **/
86 BOOLEAN
87 InternalQemuFwCfgDmaIsAvailable (
88 VOID
89 )
90 {
91 return FALSE;
92 }
93
94 /**
95 Transfer an array of bytes, or skip a number of bytes, using the DMA
96 interface.
97
98 @param[in] Size Size in bytes to transfer or skip.
99
100 @param[in,out] Buffer Buffer to read data into or write data from. Ignored,
101 and may be NULL, if Size is zero, or Control is
102 FW_CFG_DMA_CTL_SKIP.
103
104 @param[in] Control One of the following:
105 FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buffer.
106 FW_CFG_DMA_CTL_READ - read from fw_cfg into Buffer.
107 FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg.
108 **/
109 VOID
110 InternalQemuFwCfgDmaBytes (
111 IN UINT32 Size,
112 IN OUT VOID *Buffer OPTIONAL,
113 IN UINT32 Control
114 )
115 {
116 //
117 // We should never reach here
118 //
119 ASSERT (FALSE);
120 CpuDeadLoop ();
121 }