audk/OvmfPkg/VirtNorFlashDxe
Ard Biesheuvel 25589c4a76 OvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop
Currently, when dealing with small updates that can be written out
directly (i.e., if they only involve clearing bits and not setting bits,
as the latter requires a block level erase), we iterate over the data
one word at a time, read the old value, compare it, write the new value,
and repeat, unless we encountered a value that we cannot write (0->1
transition), in which case we fall back to a block level operation.

This is inefficient for two reasons:
- reading and writing a word at a time involves switching between array
and programming mode for every word of data, which is
disproportionately costly when running under KVM;
- we end up writing some data twice, as we may not notice that a block
erase is needed until after some data has been written to flash.

So replace this sequence with a single read of up to twice the buffered
write maximum size, followed by one or two buffered writes if the data
can be written directly. Otherwise, fall back to the existing block
level sequence, but without writing out part of the data twice.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
2022-10-27 16:52:01 +00:00
..
VirtNorFlash.c OvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop 2022-10-27 16:52:01 +00:00
VirtNorFlash.h OvmfPkg/VirtNorFlashDxe: drop block I/O protocol implementation 2022-10-27 16:52:01 +00:00
VirtNorFlashDxe.c OvmfPkg/VirtNorFlashDxe: avoid array mode switch after each word write 2022-10-27 16:52:01 +00:00
VirtNorFlashDxe.inf OvmfPkg/VirtNorFlashDxe: drop block I/O protocol implementation 2022-10-27 16:52:01 +00:00
VirtNorFlashFvb.c OvmfPkg/VirtNorFlashDxe: drop block I/O protocol implementation 2022-10-27 16:52:01 +00:00