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>
25 #include "QemuFwCfgLibInternal.h"
29 Reads an 8-bit I/O port fifo into a block of memory.
31 Reads the 8-bit I/O fifo port specified by Port.
33 The port is read Count times, and the read data is
34 stored in the provided Buffer.
36 This function must guarantee that all I/O read and write operations are
39 If 8-bit I/O port operations are not supported, then ASSERT().
41 @param Port The I/O port to read.
42 @param Count The number of times to read I/O port.
43 @param Buffer The buffer to store the read data into.
55 Writes an 8-bit I/O port fifo from a block of memory.
57 Writes the 8-bit I/O fifo port specified by Port.
59 The port is written Count times, and the data are obtained
60 from the provided Buffer.
62 This function must guarantee that all I/O read and write operations are
65 If 8-bit I/O port operations are not supported, then ASSERT().
67 @param Port The I/O port to read.
68 @param Count The number of times to read I/O port.
69 @param Buffer The buffer to store the read data into.
82 Selects a firmware configuration item for reading.
84 Following this call, any data read from this item will start from
85 the beginning of the configuration item's data.
87 @param[in] QemuFwCfgItem - Firmware Configuration item to read
93 IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
96 DEBUG ((EFI_D_INFO
, "Select Item: 0x%x\n", (UINT16
)(UINTN
) QemuFwCfgItem
));
97 IoWrite16 (0x510, (UINT16
)(UINTN
) QemuFwCfgItem
);
102 Reads firmware configuration bytes into a buffer
104 @param[in] Size - Size in bytes to read
105 @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0)
110 InternalQemuFwCfgReadBytes (
112 IN VOID
*Buffer OPTIONAL
115 IoReadFifo8 (0x511, Size
, Buffer
);
120 Reads firmware configuration bytes into a buffer
122 If called multiple times, then the data read will
123 continue at the offset of the firmware configuration
124 item where the previous read ended.
126 @param[in] Size - Size in bytes to read
127 @param[in] Buffer - Buffer to store data into
137 if (InternalQemuFwCfgIsAvailable ()) {
138 InternalQemuFwCfgReadBytes (Size
, Buffer
);
140 ZeroMem (Buffer
, Size
);
145 Write firmware configuration bytes from a buffer
147 If called multiple times, then the data written will
148 continue at the offset of the firmware configuration
149 item where the previous write ended.
151 @param[in] Size - Size in bytes to write
152 @param[in] Buffer - Buffer to read data from
157 QemuFwCfgWriteBytes (
162 if (InternalQemuFwCfgIsAvailable ()) {
163 IoWriteFifo8 (0x511, Size
, Buffer
);
169 Reads a UINT8 firmware configuration value
171 @return Value of Firmware Configuration item read
182 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
189 Reads a UINT16 firmware configuration value
191 @return Value of Firmware Configuration item read
202 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
209 Reads a UINT32 firmware configuration value
211 @return Value of Firmware Configuration item read
222 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
229 Reads a UINT64 firmware configuration value
231 @return Value of Firmware Configuration item read
242 QemuFwCfgReadBytes (sizeof (Result
), &Result
);
249 Find the configuration item corresponding to the firmware configuration file.
251 @param[in] Name - Name of file to look up.
252 @param[out] Item - Configuration item corresponding to the file, to be passed
253 to QemuFwCfgSelectItem ().
254 @param[out] Size - Number of bytes in the file.
256 @return RETURN_SUCCESS If file is found.
257 RETURN_NOT_FOUND If file is not found.
258 RETURN_UNSUPPORTED If firmware configuration is unavailable.
264 IN CONST CHAR8
*Name
,
265 OUT FIRMWARE_CONFIG_ITEM
*Item
,
272 if (!InternalQemuFwCfgIsAvailable ()) {
273 return RETURN_UNSUPPORTED
;
276 QemuFwCfgSelectItem (QemuFwCfgItemFileDir
);
277 Count
= SwapBytes32 (QemuFwCfgRead32 ());
279 for (Idx
= 0; Idx
< Count
; ++Idx
) {
283 CHAR8 FName
[QEMU_FW_CFG_FNAME_SIZE
];
285 FileSize
= QemuFwCfgRead32 ();
286 FileSelect
= QemuFwCfgRead16 ();
287 FileReserved
= QemuFwCfgRead16 ();
288 (VOID
) FileReserved
; /* Force a do-nothing reference. */
289 InternalQemuFwCfgReadBytes (sizeof (FName
), FName
);
291 if (AsciiStrCmp (Name
, FName
) == 0) {
292 *Item
= SwapBytes16 (FileSelect
);
293 *Size
= SwapBytes32 (FileSize
);
294 return RETURN_SUCCESS
;
298 return RETURN_NOT_FOUND
;
303 Determine if S3 support is explicitly enabled.
305 @retval TRUE if S3 support is explicitly enabled.
306 FALSE otherwise. This includes unavailability of the firmware
307 configuration interface.
315 RETURN_STATUS Status
;
316 FIRMWARE_CONFIG_ITEM FwCfgItem
;
318 UINT8 SystemStates
[6];
320 Status
= QemuFwCfgFindFile ("etc/system-states", &FwCfgItem
, &FwCfgSize
);
321 if (Status
!= RETURN_SUCCESS
|| FwCfgSize
!= sizeof SystemStates
) {
324 QemuFwCfgSelectItem (FwCfgItem
);
325 QemuFwCfgReadBytes (sizeof SystemStates
, SystemStates
);
326 return (BOOLEAN
) (SystemStates
[3] & BIT7
);