]>
Commit | Line | Data |
---|---|---|
f1ec65ba | 1 | /** @file\r |
2 | \r | |
29874a8c | 3 | Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r |
0dc231c9 | 4 | Copyright (C) 2013, Red Hat, Inc.\r |
f1ec65ba | 5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "Uefi.h"\r | |
17 | #include <Library/BaseLib.h>\r | |
18 | #include <Library/BaseMemoryLib.h>\r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/IoLib.h>\r | |
21 | #include <Library/QemuFwCfgLib.h>\r | |
22 | #include <Library/MemoryAllocationLib.h>\r | |
23 | #include <Library/UefiBootServicesTableLib.h>\r | |
24 | \r | |
f1ec65ba | 25 | \r |
26 | /**\r | |
27 | Reads an 8-bit I/O port fifo into a block of memory.\r | |
28 | \r | |
29 | Reads the 8-bit I/O fifo port specified by Port.\r | |
30 | \r | |
31 | The port is read Count times, and the read data is\r | |
32 | stored in the provided Buffer.\r | |
33 | \r | |
34 | This function must guarantee that all I/O read and write operations are\r | |
35 | serialized.\r | |
36 | \r | |
37 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
38 | \r | |
39 | @param Port The I/O port to read.\r | |
40 | @param Count The number of times to read I/O port.\r | |
41 | @param Buffer The buffer to store the read data into.\r | |
42 | \r | |
43 | **/\r | |
44 | VOID\r | |
45 | EFIAPI\r | |
46 | IoReadFifo8 (\r | |
47 | IN UINTN Port,\r | |
48 | IN UINTN Count,\r | |
49 | OUT VOID *Buffer\r | |
50 | );\r | |
51 | \r | |
29874a8c | 52 | /**\r |
53 | Writes an 8-bit I/O port fifo from a block of memory.\r | |
54 | \r | |
55 | Writes the 8-bit I/O fifo port specified by Port.\r | |
56 | \r | |
57 | The port is written Count times, and the data are obtained\r | |
58 | from the provided Buffer.\r | |
59 | \r | |
60 | This function must guarantee that all I/O read and write operations are\r | |
61 | serialized.\r | |
62 | \r | |
63 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
64 | \r | |
65 | @param Port The I/O port to read.\r | |
66 | @param Count The number of times to read I/O port.\r | |
67 | @param Buffer The buffer to store the read data into.\r | |
68 | \r | |
69 | **/\r | |
70 | VOID\r | |
71 | EFIAPI\r | |
72 | IoWriteFifo8 (\r | |
73 | IN UINTN Port,\r | |
74 | IN UINTN Count,\r | |
75 | OUT VOID *Buffer\r | |
76 | );\r | |
77 | \r | |
f1ec65ba | 78 | \r |
f1ec65ba | 79 | /**\r |
80 | Selects a firmware configuration item for reading.\r | |
81 | \r | |
82 | Following this call, any data read from this item will start from\r | |
83 | the beginning of the configuration item's data.\r | |
84 | \r | |
85 | @param[in] QemuFwCfgItem - Firmware Configuration item to read\r | |
86 | \r | |
87 | **/\r | |
88 | VOID\r | |
89 | EFIAPI\r | |
90 | QemuFwCfgSelectItem (\r | |
91 | IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem\r | |
92 | )\r | |
93 | {\r | |
94 | DEBUG ((EFI_D_INFO, "Select Item: 0x%x\n", (UINT16)(UINTN) QemuFwCfgItem));\r | |
95 | IoWrite16 (0x510, (UINT16)(UINTN) QemuFwCfgItem);\r | |
96 | }\r | |
97 | \r | |
98 | \r | |
99 | /**\r | |
100 | Reads firmware configuration bytes into a buffer\r | |
101 | \r | |
102 | @param[in] Size - Size in bytes to read\r | |
103 | @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0)\r | |
104 | \r | |
105 | **/\r | |
106 | VOID\r | |
107 | EFIAPI\r | |
108 | InternalQemuFwCfgReadBytes (\r | |
109 | IN UINTN Size,\r | |
110 | IN VOID *Buffer OPTIONAL\r | |
111 | )\r | |
112 | {\r | |
113 | IoReadFifo8 (0x511, Size, Buffer);\r | |
114 | }\r | |
115 | \r | |
116 | \r | |
117 | /**\r | |
118 | Reads firmware configuration bytes into a buffer\r | |
119 | \r | |
120 | If called multiple times, then the data read will\r | |
121 | continue at the offset of the firmware configuration\r | |
122 | item where the previous read ended.\r | |
123 | \r | |
124 | @param[in] Size - Size in bytes to read\r | |
125 | @param[in] Buffer - Buffer to store data into\r | |
126 | \r | |
127 | **/\r | |
128 | VOID\r | |
129 | EFIAPI\r | |
130 | QemuFwCfgReadBytes (\r | |
131 | IN UINTN Size,\r | |
132 | IN VOID *Buffer\r | |
133 | )\r | |
134 | {\r | |
0dc231c9 | 135 | if (InternalQemuFwCfgIsAvailable ()) {\r |
f1ec65ba | 136 | InternalQemuFwCfgReadBytes (Size, Buffer);\r |
137 | } else {\r | |
138 | ZeroMem (Buffer, Size);\r | |
139 | }\r | |
140 | }\r | |
141 | \r | |
29874a8c | 142 | /**\r |
143 | Write firmware configuration bytes from a buffer\r | |
144 | \r | |
145 | If called multiple times, then the data written will\r | |
146 | continue at the offset of the firmware configuration\r | |
147 | item where the previous write ended.\r | |
148 | \r | |
149 | @param[in] Size - Size in bytes to write\r | |
150 | @param[in] Buffer - Buffer to read data from\r | |
151 | \r | |
152 | **/\r | |
153 | VOID\r | |
154 | EFIAPI\r | |
155 | QemuFwCfgWriteBytes (\r | |
156 | IN UINTN Size,\r | |
157 | IN VOID *Buffer\r | |
158 | )\r | |
159 | {\r | |
0dc231c9 | 160 | if (InternalQemuFwCfgIsAvailable ()) {\r |
29874a8c | 161 | IoWriteFifo8 (0x511, Size, Buffer);\r |
162 | }\r | |
163 | }\r | |
164 | \r | |
f1ec65ba | 165 | \r |
166 | /**\r | |
167 | Reads a UINT8 firmware configuration value\r | |
168 | \r | |
169 | @return Value of Firmware Configuration item read\r | |
170 | \r | |
171 | **/\r | |
172 | UINT8\r | |
173 | EFIAPI\r | |
174 | QemuFwCfgRead8 (\r | |
175 | VOID\r | |
176 | )\r | |
177 | {\r | |
178 | UINT8 Result;\r | |
179 | \r | |
180 | QemuFwCfgReadBytes (sizeof (Result), &Result);\r | |
181 | \r | |
182 | return Result;\r | |
183 | }\r | |
184 | \r | |
185 | \r | |
186 | /**\r | |
187 | Reads a UINT16 firmware configuration value\r | |
188 | \r | |
189 | @return Value of Firmware Configuration item read\r | |
190 | \r | |
191 | **/\r | |
192 | UINT16\r | |
193 | EFIAPI\r | |
194 | QemuFwCfgRead16 (\r | |
195 | VOID\r | |
196 | )\r | |
197 | {\r | |
198 | UINT16 Result;\r | |
199 | \r | |
200 | QemuFwCfgReadBytes (sizeof (Result), &Result);\r | |
201 | \r | |
202 | return Result;\r | |
203 | }\r | |
204 | \r | |
205 | \r | |
206 | /**\r | |
207 | Reads a UINT32 firmware configuration value\r | |
208 | \r | |
209 | @return Value of Firmware Configuration item read\r | |
210 | \r | |
211 | **/\r | |
212 | UINT32\r | |
213 | EFIAPI\r | |
214 | QemuFwCfgRead32 (\r | |
215 | VOID\r | |
216 | )\r | |
217 | {\r | |
218 | UINT32 Result;\r | |
219 | \r | |
220 | QemuFwCfgReadBytes (sizeof (Result), &Result);\r | |
221 | \r | |
222 | return Result;\r | |
223 | }\r | |
224 | \r | |
225 | \r | |
226 | /**\r | |
227 | Reads a UINT64 firmware configuration value\r | |
228 | \r | |
229 | @return Value of Firmware Configuration item read\r | |
230 | \r | |
231 | **/\r | |
232 | UINT64\r | |
233 | EFIAPI\r | |
234 | QemuFwCfgRead64 (\r | |
235 | VOID\r | |
236 | )\r | |
237 | {\r | |
238 | UINT64 Result;\r | |
239 | \r | |
240 | QemuFwCfgReadBytes (sizeof (Result), &Result);\r | |
241 | \r | |
242 | return Result;\r | |
243 | }\r | |
244 | \r | |
245 | \r | |
0ac9bc9b | 246 | /**\r |
247 | Find the configuration item corresponding to the firmware configuration file.\r | |
248 | \r | |
249 | @param[in] Name - Name of file to look up.\r | |
250 | @param[out] Item - Configuration item corresponding to the file, to be passed\r | |
251 | to QemuFwCfgSelectItem ().\r | |
252 | @param[out] Size - Number of bytes in the file.\r | |
253 | \r | |
254 | @return RETURN_SUCCESS If file is found.\r | |
255 | RETURN_NOT_FOUND If file is not found.\r | |
256 | RETURN_UNSUPPORTED If firmware configuration is unavailable.\r | |
257 | \r | |
258 | **/\r | |
259 | RETURN_STATUS\r | |
260 | EFIAPI\r | |
261 | QemuFwCfgFindFile (\r | |
262 | IN CONST CHAR8 *Name,\r | |
263 | OUT FIRMWARE_CONFIG_ITEM *Item,\r | |
264 | OUT UINTN *Size\r | |
265 | )\r | |
266 | {\r | |
267 | UINT32 Count;\r | |
268 | UINT32 Idx;\r | |
269 | \r | |
0dc231c9 | 270 | if (!InternalQemuFwCfgIsAvailable ()) {\r |
0ac9bc9b | 271 | return RETURN_UNSUPPORTED;\r |
272 | }\r | |
273 | \r | |
274 | QemuFwCfgSelectItem (QemuFwCfgItemFileDir);\r | |
275 | Count = SwapBytes32 (QemuFwCfgRead32 ());\r | |
276 | \r | |
277 | for (Idx = 0; Idx < Count; ++Idx) {\r | |
278 | UINT32 FileSize;\r | |
279 | UINT16 FileSelect;\r | |
280 | UINT16 FileReserved;\r | |
6a904296 | 281 | CHAR8 FName[QEMU_FW_CFG_FNAME_SIZE];\r |
0ac9bc9b | 282 | \r |
283 | FileSize = QemuFwCfgRead32 ();\r | |
284 | FileSelect = QemuFwCfgRead16 ();\r | |
285 | FileReserved = QemuFwCfgRead16 ();\r | |
c6910aed | 286 | (VOID) FileReserved; /* Force a do-nothing reference. */\r |
0ac9bc9b | 287 | InternalQemuFwCfgReadBytes (sizeof (FName), FName);\r |
288 | \r | |
289 | if (AsciiStrCmp (Name, FName) == 0) {\r | |
290 | *Item = SwapBytes16 (FileSelect);\r | |
291 | *Size = SwapBytes32 (FileSize);\r | |
292 | return RETURN_SUCCESS;\r | |
293 | }\r | |
294 | }\r | |
295 | \r | |
296 | return RETURN_NOT_FOUND;\r | |
297 | }\r | |
14eb7a5b LE |
298 | \r |
299 | \r | |
300 | /**\r | |
301 | Determine if S3 support is explicitly enabled.\r | |
302 | \r | |
303 | @retval TRUE if S3 support is explicitly enabled.\r | |
304 | FALSE otherwise. This includes unavailability of the firmware\r | |
305 | configuration interface.\r | |
306 | **/\r | |
307 | BOOLEAN\r | |
308 | EFIAPI\r | |
309 | QemuFwCfgS3Enabled (\r | |
310 | VOID\r | |
311 | )\r | |
312 | {\r | |
313 | RETURN_STATUS Status;\r | |
314 | FIRMWARE_CONFIG_ITEM FwCfgItem;\r | |
315 | UINTN FwCfgSize;\r | |
316 | UINT8 SystemStates[6];\r | |
317 | \r | |
318 | Status = QemuFwCfgFindFile ("etc/system-states", &FwCfgItem, &FwCfgSize);\r | |
319 | if (Status != RETURN_SUCCESS || FwCfgSize != sizeof SystemStates) {\r | |
320 | return FALSE;\r | |
321 | }\r | |
322 | QemuFwCfgSelectItem (FwCfgItem);\r | |
323 | QemuFwCfgReadBytes (sizeof SystemStates, SystemStates);\r | |
324 | return (BOOLEAN) (SystemStates[3] & BIT7);\r | |
325 | }\r |