3 Copyright (c) 2011 - 2013, 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.
54 Writes an 8-bit I/O port fifo from a block of memory.
56 Writes the 8-bit I/O fifo port specified by Port.
58 The port is written Count times, and the data are obtained
59 from the provided Buffer.
61 This function must guarantee that all I/O read and write operations are
64 If 8-bit I/O port operations are not supported, then ASSERT().
66 @param Port The I/O port to read.
67 @param Count The number of times to read I/O port.
68 @param Buffer The buffer to store the read data into.
81 Returns a boolean indicating if the firmware configuration interface
84 @retval TRUE The interface is available
85 @retval FALSE The interface is not available
90 QemuFwCfgIsAvailable (
94 return mQemuFwCfgSupported
;
99 Selects a firmware configuration item for reading.
101 Following this call, any data read from this item will start from
102 the beginning of the configuration item's data.
104 @param[in] QemuFwCfgItem - Firmware Configuration item to read
109 QemuFwCfgSelectItem (
110 IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
113 DEBUG ((EFI_D_INFO
, "Select Item: 0x%x\n", (UINT16
)(UINTN
) QemuFwCfgItem
));
114 IoWrite16 (0x510, (UINT16
)(UINTN
) QemuFwCfgItem
);
119 Reads firmware configuration bytes into a buffer
121 @param[in] Size - Size in bytes to read
122 @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0)
127 InternalQemuFwCfgReadBytes (
129 IN VOID
*Buffer OPTIONAL
132 IoReadFifo8 (0x511, Size
, Buffer
);
137 Reads firmware configuration bytes into a buffer
139 If called multiple times, then the data read will
140 continue at the offset of the firmware configuration
141 item where the previous read ended.
143 @param[in] Size - Size in bytes to read
144 @param[in] Buffer - Buffer to store data into
154 if (mQemuFwCfgSupported
) {
155 InternalQemuFwCfgReadBytes (Size
, Buffer
);
157 ZeroMem (Buffer
, Size
);
162 Write firmware configuration bytes from a buffer
164 If called multiple times, then the data written will
165 continue at the offset of the firmware configuration
166 item where the previous write ended.
168 @param[in] Size - Size in bytes to write
169 @param[in] Buffer - Buffer to read data from
174 QemuFwCfgWriteBytes (
179 if (mQemuFwCfgSupported
) {
180 IoWriteFifo8 (0x511, Size
, Buffer
);
186 Reads a UINT8 firmware configuration value
188 @return Value of Firmware Configuration item read
199 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
206 Reads a UINT16 firmware configuration value
208 @return Value of Firmware Configuration item read
219 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
226 Reads a UINT32 firmware configuration value
228 @return Value of Firmware Configuration item read
239 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
246 Reads a UINT64 firmware configuration value
248 @return Value of Firmware Configuration item read
259 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
267 QemuFwCfgInitialize (
275 // Enable the access routines while probing to see if it is supported.
277 mQemuFwCfgSupported
= TRUE
;
279 QemuFwCfgSelectItem (QemuFwCfgItemSignature
);
280 Signature
= QemuFwCfgRead32 ();
281 DEBUG ((EFI_D_INFO
, "FW CFG Signature: 0x%x\n", Signature
));
282 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion
);
283 Revision
= QemuFwCfgRead32 ();
284 DEBUG ((EFI_D_INFO
, "FW CFG Revision: 0x%x\n", Revision
));
285 if ((Signature
!= SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
288 DEBUG ((EFI_D_INFO
, "QemuFwCfg interface not supported.\n"));
289 mQemuFwCfgSupported
= FALSE
;
290 return RETURN_SUCCESS
;
293 DEBUG ((EFI_D_INFO
, "QemuFwCfg interface is supported.\n"));
294 return RETURN_SUCCESS
;
299 Find the configuration item corresponding to the firmware configuration file.
301 @param[in] Name - Name of file to look up.
302 @param[out] Item - Configuration item corresponding to the file, to be passed
303 to QemuFwCfgSelectItem ().
304 @param[out] Size - Number of bytes in the file.
306 @return RETURN_SUCCESS If file is found.
307 RETURN_NOT_FOUND If file is not found.
308 RETURN_UNSUPPORTED If firmware configuration is unavailable.
314 IN CONST CHAR8
*Name
,
315 OUT FIRMWARE_CONFIG_ITEM
*Item
,
322 if (!mQemuFwCfgSupported
) {
323 return RETURN_UNSUPPORTED
;
326 QemuFwCfgSelectItem (QemuFwCfgItemFileDir
);
327 Count
= SwapBytes32 (QemuFwCfgRead32 ());
329 for (Idx
= 0; Idx
< Count
; ++Idx
) {
335 FileSize
= QemuFwCfgRead32 ();
336 FileSelect
= QemuFwCfgRead16 ();
337 FileReserved
= QemuFwCfgRead16 ();
338 InternalQemuFwCfgReadBytes (sizeof (FName
), FName
);
340 if (AsciiStrCmp (Name
, FName
) == 0) {
341 *Item
= SwapBytes16 (FileSelect
);
342 *Size
= SwapBytes32 (FileSize
);
343 return RETURN_SUCCESS
;
347 return RETURN_NOT_FOUND
;