]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
ac05f4c347f38986ad474373dfa19bef3512b0ca
[mirror_edk2.git] / OvmfPkg / Library / QemuFwCfgLib / QemuFwCfgPei.c
1 /** @file
2
3 Stateful and implicitly initialized fw_cfg library implementation.
4
5 Copyright (C) 2013, Red Hat, Inc.
6 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
7
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 **/
16
17 #include <Library/DebugLib.h>
18 #include <Library/QemuFwCfgLib.h>
19
20 #include "QemuFwCfgLibInternal.h"
21
22 STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
23 STATIC BOOLEAN mQemuFwCfgDmaSupported;
24
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 return InternalQemuFwCfgIsAvailable ();
43 }
44
45
46 RETURN_STATUS
47 EFIAPI
48 QemuFwCfgInitialize (
49 VOID
50 )
51 {
52 UINT32 Signature;
53 UINT32 Revision;
54
55 //
56 // Enable the access routines while probing to see if it is supported.
57 // For probing we always use the IO Port (IoReadFifo8()) access method.
58 //
59 mQemuFwCfgSupported = TRUE;
60 mQemuFwCfgDmaSupported = FALSE;
61
62 QemuFwCfgSelectItem (QemuFwCfgItemSignature);
63 Signature = QemuFwCfgRead32 ();
64 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
65 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
66 Revision = QemuFwCfgRead32 ();
67 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
68 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
69 (Revision < 1)
70 ) {
71 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
72 mQemuFwCfgSupported = FALSE;
73 return RETURN_SUCCESS;
74 }
75
76 if ((Revision & FW_CFG_F_DMA) == 0) {
77 DEBUG ((DEBUG_INFO, "QemuFwCfg interface (IO Port) is supported.\n"));
78 } else {
79 mQemuFwCfgDmaSupported = TRUE;
80 DEBUG ((DEBUG_INFO, "QemuFwCfg interface (DMA) is supported.\n"));
81 }
82 return RETURN_SUCCESS;
83 }
84
85
86 /**
87 Returns a boolean indicating if the firmware configuration interface is
88 available for library-internal purposes.
89
90 This function never changes fw_cfg state.
91
92 @retval TRUE The interface is available internally.
93 @retval FALSE The interface is not available internally.
94 **/
95 BOOLEAN
96 InternalQemuFwCfgIsAvailable (
97 VOID
98 )
99 {
100 return mQemuFwCfgSupported;
101 }
102
103 /**
104 Returns a boolean indicating whether QEMU provides the DMA-like access method
105 for fw_cfg.
106
107 @retval TRUE The DMA-like access method is available.
108 @retval FALSE The DMA-like access method is unavailable.
109 **/
110 BOOLEAN
111 InternalQemuFwCfgDmaIsAvailable (
112 VOID
113 )
114 {
115 return mQemuFwCfgDmaSupported;
116 }