]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c
OvmfPkg: Modify QemuFwCfgLib to use new IoLib class library
[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
10 This program and the accompanying materials are licensed and made available
11 under the terms and conditions of the BSD License which accompanies this
12 distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
14
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
16 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 **/
18
19 #include <Library/DebugLib.h>
20 #include <Library/QemuFwCfgLib.h>
21
22 #include "QemuFwCfgLibInternal.h"
23
24 /**
25 Returns a boolean indicating if the firmware configuration interface
26 is available or not.
27
28 This function may change fw_cfg state.
29
30 @retval TRUE The interface is available
31 @retval FALSE The interface is not available
32
33 **/
34 BOOLEAN
35 EFIAPI
36 QemuFwCfgIsAvailable (
37 VOID
38 )
39 {
40 UINT32 Signature;
41 UINT32 Revision;
42
43 QemuFwCfgSelectItem (QemuFwCfgItemSignature);
44 Signature = QemuFwCfgRead32 ();
45 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
46 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
47 Revision = QemuFwCfgRead32 ();
48 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
49 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
50 (Revision < 1)
51 ) {
52 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
53 return FALSE;
54 }
55
56 DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
57 return TRUE;
58 }
59
60
61 /**
62 Returns a boolean indicating if the firmware configuration interface is
63 available for library-internal purposes.
64
65 This function never changes fw_cfg state.
66
67 @retval TRUE The interface is available internally.
68 @retval FALSE The interface is not available internally.
69 **/
70 BOOLEAN
71 InternalQemuFwCfgIsAvailable (
72 VOID
73 )
74 {
75 //
76 // We always return TRUE, because the consumer of this library ought to have
77 // called QemuFwCfgIsAvailable before making other calls which would hit this
78 // path.
79 //
80 return TRUE;
81 }
82
83 /**
84 Returns a boolean indicating whether QEMU provides the DMA-like access method
85 for fw_cfg.
86
87 @retval TRUE The DMA-like access method is available.
88 @retval FALSE The DMA-like access method is unavailable.
89 **/
90 BOOLEAN
91 InternalQemuFwCfgDmaIsAvailable (
92 VOID
93 )
94 {
95 return FALSE;
96 }