3 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
4 Copyright (C) 2013, Red Hat, Inc.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/IoLib.h>
21 #include <Library/QemuFwCfgLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
27 Reads an 8-bit I/O port fifo into a block of memory.
29 Reads the 8-bit I/O fifo port specified by Port.
31 The port is read Count times, and the read data is
32 stored in the provided Buffer.
34 This function must guarantee that all I/O read and write operations are
37 If 8-bit I/O port operations are not supported, then ASSERT().
39 @param Port The I/O port to read.
40 @param Count The number of times to read I/O port.
41 @param Buffer The buffer to store the read data into.
53 Writes an 8-bit I/O port fifo from a block of memory.
55 Writes the 8-bit I/O fifo port specified by Port.
57 The port is written Count times, and the data are obtained
58 from the provided Buffer.
60 This function must guarantee that all I/O read and write operations are
63 If 8-bit I/O port operations are not supported, then ASSERT().
65 @param Port The I/O port to read.
66 @param Count The number of times to read I/O port.
67 @param Buffer The buffer to store the read data into.
80 Selects a firmware configuration item for reading.
82 Following this call, any data read from this item will start from
83 the beginning of the configuration item's data.
85 @param[in] QemuFwCfgItem - Firmware Configuration item to read
91 IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
94 DEBUG ((EFI_D_INFO
, "Select Item: 0x%x\n", (UINT16
)(UINTN
) QemuFwCfgItem
));
95 IoWrite16 (0x510, (UINT16
)(UINTN
) QemuFwCfgItem
);
100 Reads firmware configuration bytes into a buffer
102 @param[in] Size - Size in bytes to read
103 @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0)
108 InternalQemuFwCfgReadBytes (
110 IN VOID
*Buffer OPTIONAL
113 IoReadFifo8 (0x511, Size
, Buffer
);
118 Reads firmware configuration bytes into a buffer
120 If called multiple times, then the data read will
121 continue at the offset of the firmware configuration
122 item where the previous read ended.
124 @param[in] Size - Size in bytes to read
125 @param[in] Buffer - Buffer to store data into
135 if (InternalQemuFwCfgIsAvailable ()) {
136 InternalQemuFwCfgReadBytes (Size
, Buffer
);
138 ZeroMem (Buffer
, Size
);
143 Write firmware configuration bytes from a buffer
145 If called multiple times, then the data written will
146 continue at the offset of the firmware configuration
147 item where the previous write ended.
149 @param[in] Size - Size in bytes to write
150 @param[in] Buffer - Buffer to read data from
155 QemuFwCfgWriteBytes (
160 if (InternalQemuFwCfgIsAvailable ()) {
161 IoWriteFifo8 (0x511, Size
, Buffer
);
167 Reads a UINT8 firmware configuration value
169 @return Value of Firmware Configuration item read
180 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
187 Reads a UINT16 firmware configuration value
189 @return Value of Firmware Configuration item read
200 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
207 Reads a UINT32 firmware configuration value
209 @return Value of Firmware Configuration item read
220 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
227 Reads a UINT64 firmware configuration value
229 @return Value of Firmware Configuration item read
240 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
247 Find the configuration item corresponding to the firmware configuration file.
249 @param[in] Name - Name of file to look up.
250 @param[out] Item - Configuration item corresponding to the file, to be passed
251 to QemuFwCfgSelectItem ().
252 @param[out] Size - Number of bytes in the file.
254 @return RETURN_SUCCESS If file is found.
255 RETURN_NOT_FOUND If file is not found.
256 RETURN_UNSUPPORTED If firmware configuration is unavailable.
262 IN CONST CHAR8
*Name
,
263 OUT FIRMWARE_CONFIG_ITEM
*Item
,
270 if (!InternalQemuFwCfgIsAvailable ()) {
271 return RETURN_UNSUPPORTED
;
274 QemuFwCfgSelectItem (QemuFwCfgItemFileDir
);
275 Count
= SwapBytes32 (QemuFwCfgRead32 ());
277 for (Idx
= 0; Idx
< Count
; ++Idx
) {
281 CHAR8 FName
[QEMU_FW_CFG_FNAME_SIZE
];
283 FileSize
= QemuFwCfgRead32 ();
284 FileSelect
= QemuFwCfgRead16 ();
285 FileReserved
= QemuFwCfgRead16 ();
286 (VOID
) FileReserved
; /* Force a do-nothing reference. */
287 InternalQemuFwCfgReadBytes (sizeof (FName
), FName
);
289 if (AsciiStrCmp (Name
, FName
) == 0) {
290 *Item
= SwapBytes16 (FileSelect
);
291 *Size
= SwapBytes32 (FileSize
);
292 return RETURN_SUCCESS
;
296 return RETURN_NOT_FOUND
;
301 Determine if S3 support is explicitly enabled.
303 @retval TRUE if S3 support is explicitly enabled.
304 FALSE otherwise. This includes unavailability of the firmware
305 configuration interface.
313 RETURN_STATUS Status
;
314 FIRMWARE_CONFIG_ITEM FwCfgItem
;
316 UINT8 SystemStates
[6];
318 Status
= QemuFwCfgFindFile ("etc/system-states", &FwCfgItem
, &FwCfgSize
);
319 if (Status
!= RETURN_SUCCESS
|| FwCfgSize
!= sizeof SystemStates
) {
322 QemuFwCfgSelectItem (FwCfgItem
);
323 QemuFwCfgReadBytes (sizeof SystemStates
, SystemStates
);
324 return (BOOLEAN
) (SystemStates
[3] & BIT7
);