TianoCore EDK2 master
Loading...
Searching...
No Matches
QemuFwCfgLib.c
Go to the documentation of this file.
1
11#include "Uefi.h"
12#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15#include <Library/IoLib.h>
19
21
31VOID
32EFIAPI
34 IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem
35 )
36{
37 DEBUG ((DEBUG_INFO, "Select Item: 0x%x\n", (UINT16)(UINTN)QemuFwCfgItem));
38 IoWrite16 (FW_CFG_IO_SELECTOR, (UINT16)(UINTN)QemuFwCfgItem);
39}
40
48VOID
49EFIAPI
50InternalQemuFwCfgReadBytes (
51 IN UINTN Size,
52 IN VOID *Buffer OPTIONAL
53 )
54{
55 if (InternalQemuFwCfgDmaIsAvailable () && (Size <= MAX_UINT32)) {
56 InternalQemuFwCfgDmaBytes ((UINT32)Size, Buffer, FW_CFG_DMA_CTL_READ);
57 return;
58 }
59
60 IoReadFifo8 (FW_CFG_IO_DATA, Size, Buffer);
61}
62
74VOID
75EFIAPI
77 IN UINTN Size,
78 IN VOID *Buffer
79 )
80{
82 InternalQemuFwCfgReadBytes (Size, Buffer);
83 } else {
84 ZeroMem (Buffer, Size);
85 }
86}
87
99VOID
100EFIAPI
102 IN UINTN Size,
103 IN VOID *Buffer
104 )
105{
107 if (InternalQemuFwCfgDmaIsAvailable () && (Size <= MAX_UINT32)) {
108 InternalQemuFwCfgDmaBytes ((UINT32)Size, Buffer, FW_CFG_DMA_CTL_WRITE);
109 return;
110 }
111
112 IoWriteFifo8 (FW_CFG_IO_DATA, Size, Buffer);
113 }
114}
115
125VOID
126EFIAPI
128 IN UINTN Size
129 )
130{
131 UINTN ChunkSize;
132 UINT8 SkipBuffer[256];
133
135 return;
136 }
137
138 if (InternalQemuFwCfgDmaIsAvailable () && (Size <= MAX_UINT32)) {
139 InternalQemuFwCfgDmaBytes ((UINT32)Size, NULL, FW_CFG_DMA_CTL_SKIP);
140 return;
141 }
142
143 //
144 // Emulate the skip by reading data in chunks, and throwing it away. The
145 // implementation below is suitable even for phases where RAM or dynamic
146 // allocation is not available or appropriate. It also doesn't affect the
147 // static data footprint for client modules. Large skips are not expected,
148 // therefore this fallback is not performance critical. The size of
149 // SkipBuffer is thought not to exert a large pressure on the stack in any
150 // phase.
151 //
152 while (Size > 0) {
153 ChunkSize = MIN (Size, sizeof SkipBuffer);
154 IoReadFifo8 (FW_CFG_IO_DATA, ChunkSize, SkipBuffer);
155 Size -= ChunkSize;
156 }
157}
158
165UINT8
166EFIAPI
168 VOID
169 )
170{
171 UINT8 Result;
172
173 QemuFwCfgReadBytes (sizeof (Result), &Result);
174
175 return Result;
176}
177
184UINT16
185EFIAPI
187 VOID
188 )
189{
190 UINT16 Result;
191
192 QemuFwCfgReadBytes (sizeof (Result), &Result);
193
194 return Result;
195}
196
203UINT32
204EFIAPI
206 VOID
207 )
208{
209 UINT32 Result;
210
211 QemuFwCfgReadBytes (sizeof (Result), &Result);
212
213 return Result;
214}
215
222UINT64
223EFIAPI
225 VOID
226 )
227{
228 UINT64 Result;
229
230 QemuFwCfgReadBytes (sizeof (Result), &Result);
231
232 return Result;
233}
234
248RETURN_STATUS
249EFIAPI
251 IN CONST CHAR8 *Name,
252 OUT FIRMWARE_CONFIG_ITEM *Item,
253 OUT UINTN *Size
254 )
255{
256 UINT32 Count;
257 UINT32 Idx;
258
260 return RETURN_UNSUPPORTED;
261 }
262
263 QemuFwCfgSelectItem (QemuFwCfgItemFileDir);
264 Count = SwapBytes32 (QemuFwCfgRead32 ());
265
266 for (Idx = 0; Idx < Count; ++Idx) {
267 UINT32 FileSize;
268 UINT16 FileSelect;
269 UINT16 FileReserved;
270 CHAR8 FName[QEMU_FW_CFG_FNAME_SIZE];
271
272 FileSize = QemuFwCfgRead32 ();
273 FileSelect = QemuFwCfgRead16 ();
274 FileReserved = QemuFwCfgRead16 ();
275 (VOID)FileReserved; /* Force a do-nothing reference. */
276 InternalQemuFwCfgReadBytes (sizeof (FName), FName);
277
278 if (AsciiStrCmp (Name, FName) == 0) {
279 *Item = SwapBytes16 (FileSelect);
280 *Size = SwapBytes32 (FileSize);
281 return RETURN_SUCCESS;
282 }
283 }
284
285 return RETURN_NOT_FOUND;
286}
UINT64 UINTN
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
Definition: String.c:716
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI IoReadFifo8(IN UINTN Port, IN UINTN Count, OUT VOID *Buffer)
Definition: IoLibArmVirt.c:380
VOID EFIAPI IoWriteFifo8(IN UINTN Port, IN UINTN Count, IN VOID *Buffer)
Definition: IoLibArmVirt.c:408
UINT16 EFIAPI IoWrite16(IN UINTN Port, IN UINT16 Value)
Definition: IoLibArmVirt.c:250
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_NOT_FOUND
Definition: Base.h:1142
#define MIN(a, b)
Definition: Base.h:1007
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
BOOLEAN InternalQemuFwCfgIsAvailable(VOID)
Definition: QemuFwCfgDxe.c:126
VOID InternalQemuFwCfgDmaBytes(IN UINT32 Size, IN OUT VOID *Buffer OPTIONAL, IN UINT32 Control)
Definition: QemuFwCfgDxe.c:387
BOOLEAN InternalQemuFwCfgDmaIsAvailable(VOID)
Definition: QemuFwCfgDxe.c:141
UINT32 EFIAPI QemuFwCfgRead32(VOID)
Definition: QemuFwCfgLib.c:205
VOID EFIAPI QemuFwCfgWriteBytes(IN UINTN Size, IN VOID *Buffer)
Definition: QemuFwCfgLib.c:101
UINT16 EFIAPI QemuFwCfgRead16(VOID)
Definition: QemuFwCfgLib.c:186
UINT8 EFIAPI QemuFwCfgRead8(VOID)
Definition: QemuFwCfgLib.c:167
RETURN_STATUS EFIAPI QemuFwCfgFindFile(IN CONST CHAR8 *Name, OUT FIRMWARE_CONFIG_ITEM *Item, OUT UINTN *Size)
Definition: QemuFwCfgLib.c:250
UINT64 EFIAPI QemuFwCfgRead64(VOID)
Definition: QemuFwCfgLib.c:224
VOID EFIAPI QemuFwCfgSelectItem(IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem)
Definition: QemuFwCfgLib.c:33
VOID EFIAPI QemuFwCfgSkipBytes(IN UINTN Size)
Definition: QemuFwCfgLib.c:127
VOID EFIAPI QemuFwCfgReadBytes(IN UINTN Size, IN VOID *Buffer)
Definition: QemuFwCfgLib.c:76