mirror of https://github.com/acidanthera/audk.git
OvmfPkg/QemuFwCfgLib: add QemuFwCfgSkipBytes()
Introduce the new public API QemuFwCfgSkipBytes(), for advancing over bytes in the selected firmware configuration item without transferring data between the item and the caller. When the DMA interface is available (the common case), the operation is instantaneous. As a fallback, provide a loop of chunked reads into a small stack-allocated scratch buffer. This patch enables OvmfPkg/QemuFwCfgLib to overwrite part of a writeable fw_cfg file, which will be particularly useful for the upcoming QEMU_LOADER_WRITE_POINTER command in OvmfPkg/AcpiPlatformDxe. Cc: Jordan Justen <jordan.l.justen@intel.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=359 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
parent
d055601ea7
commit
fcca9f67fb
|
@ -158,6 +158,22 @@ QemuFwCfgWriteBytes (
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Skip bytes in the firmware configuration item.
|
||||||
|
|
||||||
|
Increase the offset of the firmware configuration item without transferring
|
||||||
|
bytes between the item and a caller-provided buffer. Subsequent read, write
|
||||||
|
or skip operations will commence at the increased offset.
|
||||||
|
|
||||||
|
@param[in] Size Number of bytes to skip.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
EFIAPI
|
||||||
|
QemuFwCfgSkipBytes (
|
||||||
|
IN UINTN Size
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reads a UINT8 firmware configuration value
|
Reads a UINT8 firmware configuration value
|
||||||
|
|
||||||
|
|
|
@ -192,6 +192,50 @@ QemuFwCfgWriteBytes (
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Skip bytes in the firmware configuration item.
|
||||||
|
|
||||||
|
Increase the offset of the firmware configuration item without transferring
|
||||||
|
bytes between the item and a caller-provided buffer. Subsequent read, write
|
||||||
|
or skip operations will commence at the increased offset.
|
||||||
|
|
||||||
|
@param[in] Size Number of bytes to skip.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
EFIAPI
|
||||||
|
QemuFwCfgSkipBytes (
|
||||||
|
IN UINTN Size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN ChunkSize;
|
||||||
|
UINT8 SkipBuffer[256];
|
||||||
|
|
||||||
|
if (!InternalQemuFwCfgIsAvailable ()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (InternalQemuFwCfgDmaIsAvailable () && Size <= MAX_UINT32) {
|
||||||
|
InternalQemuFwCfgDmaBytes ((UINT32)Size, NULL, FW_CFG_DMA_CTL_SKIP);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Emulate the skip by reading data in chunks, and throwing it away. The
|
||||||
|
// implementation below is suitable even for phases where RAM or dynamic
|
||||||
|
// allocation is not available or appropriate. It also doesn't affect the
|
||||||
|
// static data footprint for client modules. Large skips are not expected,
|
||||||
|
// therefore this fallback is not performance critical. The size of
|
||||||
|
// SkipBuffer is thought not to exert a large pressure on the stack in any
|
||||||
|
// phase.
|
||||||
|
//
|
||||||
|
while (Size > 0) {
|
||||||
|
ChunkSize = MIN (Size, sizeof SkipBuffer);
|
||||||
|
IoReadFifo8 (0x511, ChunkSize, SkipBuffer);
|
||||||
|
Size -= ChunkSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reads a UINT8 firmware configuration value
|
Reads a UINT8 firmware configuration value
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue