3 Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/QemuFwCfgLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
24 STATIC BOOLEAN mQemuFwCfgSupported
= FALSE
;
28 Reads an 8-bit I/O port fifo into a block of memory.
30 Reads the 8-bit I/O fifo port specified by Port.
32 The port is read Count times, and the read data is
33 stored in the provided Buffer.
35 This function must guarantee that all I/O read and write operations are
38 If 8-bit I/O port operations are not supported, then ASSERT().
40 @param Port The I/O port to read.
41 @param Count The number of times to read I/O port.
42 @param Buffer The buffer to store the read data into.
55 Returns a boolean indicating if the firmware configuration interface
58 @retval TRUE The interface is available
59 @retval FALSE The interface is not available
64 QemuFwCfgIsAvailable (
68 return mQemuFwCfgSupported
;
73 Selects a firmware configuration item for reading.
75 Following this call, any data read from this item will start from
76 the beginning of the configuration item's data.
78 @param[in] QemuFwCfgItem - Firmware Configuration item to read
84 IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
87 DEBUG ((EFI_D_INFO
, "Select Item: 0x%x\n", (UINT16
)(UINTN
) QemuFwCfgItem
));
88 IoWrite16 (0x510, (UINT16
)(UINTN
) QemuFwCfgItem
);
93 Reads firmware configuration bytes into a buffer
95 @param[in] Size - Size in bytes to read
96 @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0)
101 InternalQemuFwCfgReadBytes (
103 IN VOID
*Buffer OPTIONAL
106 IoReadFifo8 (0x511, Size
, Buffer
);
111 Reads firmware configuration bytes into a buffer
113 If called multiple times, then the data read will
114 continue at the offset of the firmware configuration
115 item where the previous read ended.
117 @param[in] Size - Size in bytes to read
118 @param[in] Buffer - Buffer to store data into
128 if (mQemuFwCfgSupported
) {
129 InternalQemuFwCfgReadBytes (Size
, Buffer
);
131 ZeroMem (Buffer
, Size
);
137 Reads a UINT8 firmware configuration value
139 @return Value of Firmware Configuration item read
150 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
157 Reads a UINT16 firmware configuration value
159 @return Value of Firmware Configuration item read
170 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
177 Reads a UINT32 firmware configuration value
179 @return Value of Firmware Configuration item read
190 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
197 Reads a UINT64 firmware configuration value
199 @return Value of Firmware Configuration item read
210 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
218 QemuFwCfgInitialize (
226 // Enable the access routines while probing to see if it is supported.
228 mQemuFwCfgSupported
= TRUE
;
230 QemuFwCfgSelectItem (QemuFwCfgItemSignature
);
231 Signature
= QemuFwCfgRead32 ();
232 DEBUG ((EFI_D_INFO
, "FW CFG Signature: 0x%x\n", Signature
));
233 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion
);
234 Revision
= QemuFwCfgRead32 ();
235 DEBUG ((EFI_D_INFO
, "FW CFG Revision: 0x%x\n", Revision
));
236 if ((Signature
!= SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
239 DEBUG ((EFI_D_INFO
, "QemuFwCfg interface not supported.\n"));
240 mQemuFwCfgSupported
= FALSE
;
241 return RETURN_SUCCESS
;
244 DEBUG ((EFI_D_INFO
, "QemuFwCfg interface is supported.\n"));
245 return RETURN_SUCCESS
;