From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.625.1666630902188528156 for ; Mon, 24 Oct 2022 10:01:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a3FO0Q61; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A4B696148D; Mon, 24 Oct 2022 17:01:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BECACC433D7; Mon, 24 Oct 2022 17:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666630901; bh=EJ71AgzKW27DqQTYZ2akSjrlAel6AYo+9/PIwQeQD10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a3FO0Q61X8tU8S4Xo9O0nB5NyA3gR6vAWc+/+hwNOcjapgQygg8hxOEhMZvqGyzw/ L3ElZ5IipXfkg65GUv702gT4KjiyCOdn0hPCckP7Z9wBdQzRb0QTwHMRySQtWNiSuN T+q5vx786POaGXIwPaAZ+805JYrZSwQMGyLT4QcE0PowPQV3WQHRPlkXP0V78y36Ox s/15z5ytBo3td4spDoeOkUKiQdMM47bqtvFXNDPEySOLVVV1oR/+ciKyd3jJ2gVv1V wJLoT4wk1zvDf3kQ5rcer5Ycz8X5eyfu606o47IKdWfwBGkcZGm22ozxun3WB3c9x+ VDR7iMZsHHu1Q== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Gerd Hoffmann , Sunil V L , Sami Mujawar , Leif Lindholm Subject: [PATCH 04/11] OvmfPkg/VirtNorFlashDxe: remove disk I/O protocol implementation Date: Mon, 24 Oct 2022 19:01:15 +0200 Message-Id: <20221024170122.594577-5-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221024170122.594577-1-ardb@kernel.org> References: <20221024170122.594577-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable We only use NOR flash for firmware volumes, either for executable images or for the variable store. So we have no need for exposing disk I/O on top of the NOR flash partitions so let's remove it. Signed-off-by: Ard Biesheuvel --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 129 -------------------- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h | 29 ----- OvmfPkg/VirtNorFlashDxe/VirtNorFlashBlockIoDxe.c | 123 ------------------- OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c | 8 -- 4 files changed, 289 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 59a562efdf36..1094d48f7de4 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -788,135 +788,6 @@ NorFlashWriteSingleBlock ( return EFI_SUCCESS;=0D }=0D =0D -/*=0D - Although DiskIoDxe will automatically install the DiskIO protocol whenev= er=0D - we install the BlockIO protocol, its implementation is sub-optimal as it= reads=0D - and writes entire blocks using the BlockIO protocol. In fact we can acce= ss=0D - NOR flash with a finer granularity than that, so we can improve performa= nce=0D - by directly producing the DiskIO protocol.=0D -*/=0D -=0D -/**=0D - Read BufferSize bytes from Offset into Buffer.=0D -=0D - @param This Protocol instance pointer.=0D - @param MediaId Id of the media, changes every time the me= dia is replaced.=0D - @param Offset The starting byte offset to read from=0D - @param BufferSize Size of Buffer=0D - @param Buffer Buffer containing read data=0D -=0D - @retval EFI_SUCCESS The data was read correctly from the devic= e.=0D - @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the read.=0D - @retval EFI_NO_MEDIA There is no media in the device.=0D - @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice.=0D - @retval EFI_INVALID_PARAMETER The read request contains device addresses= that are not=0D - valid for the device.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashDiskIoReadDisk (=0D - IN EFI_DISK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN UINT64 DiskOffset,=0D - IN UINTN BufferSize,=0D - OUT VOID *Buffer=0D - )=0D -{=0D - NOR_FLASH_INSTANCE *Instance;=0D - UINT32 BlockSize;=0D - UINT32 BlockOffset;=0D - EFI_LBA Lba;=0D -=0D - Instance =3D INSTANCE_FROM_DISKIO_THIS (This);=0D -=0D - if (MediaId !=3D Instance->Media.MediaId) {=0D - return EFI_MEDIA_CHANGED;=0D - }=0D -=0D - BlockSize =3D Instance->Media.BlockSize;=0D - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset);=0D -=0D - return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer);=0D -}=0D -=0D -/**=0D - Writes a specified number of bytes to a device.=0D -=0D - @param This Indicates a pointer to the calling context.=0D - @param MediaId ID of the medium to be written.=0D - @param Offset The starting byte offset on the logical block I/O dev= ice to write.=0D - @param BufferSize The size in bytes of Buffer. The number of bytes to w= rite to the device.=0D - @param Buffer A pointer to the buffer containing the data to be wri= tten.=0D -=0D - @retval EFI_SUCCESS The data was written correctly to the devi= ce.=0D - @retval EFI_WRITE_PROTECTED The device can not be written to.=0D - @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the write.=0D - @retval EFI_NO_MEDIA There is no media in the device.=0D - @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice.=0D - @retval EFI_INVALID_PARAMETER The write request contains device addresse= s that are not=0D - valid for the device.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashDiskIoWriteDisk (=0D - IN EFI_DISK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN UINT64 DiskOffset,=0D - IN UINTN BufferSize,=0D - IN VOID *Buffer=0D - )=0D -{=0D - NOR_FLASH_INSTANCE *Instance;=0D - UINT32 BlockSize;=0D - UINT32 BlockOffset;=0D - EFI_LBA Lba;=0D - UINTN RemainingBytes;=0D - UINTN WriteSize;=0D - EFI_STATUS Status;=0D -=0D - Instance =3D INSTANCE_FROM_DISKIO_THIS (This);=0D -=0D - if (MediaId !=3D Instance->Media.MediaId) {=0D - return EFI_MEDIA_CHANGED;=0D - }=0D -=0D - BlockSize =3D Instance->Media.BlockSize;=0D - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset);=0D -=0D - RemainingBytes =3D BufferSize;=0D -=0D - // Write either all the remaining bytes, or the number of bytes that bri= ng=0D - // us up to a block boundary, whichever is less.=0D - // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next= =0D - // block boundary (even if it is already on one).=0D - WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) = - DiskOffset);=0D -=0D - do {=0D - if (WriteSize =3D=3D BlockSize) {=0D - // Write a full block=0D - Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize = / sizeof (UINT32));=0D - } else {=0D - // Write a partial block=0D - Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &Wr= iteSize, Buffer);=0D - }=0D -=0D - if (EFI_ERROR (Status)) {=0D - return Status;=0D - }=0D -=0D - // Now continue writing either all the remaining bytes or single block= s.=0D - RemainingBytes -=3D WriteSize;=0D - Buffer =3D (UINT8 *)Buffer + WriteSize;=0D - Lba++;=0D - BlockOffset =3D 0;=0D - WriteSize =3D MIN (RemainingBytes, BlockSize);=0D - } while (RemainingBytes);=0D -=0D - return Status;=0D -}=0D -=0D EFI_STATUS=0D NorFlashReset (=0D IN NOR_FLASH_INSTANCE *Instance=0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.h index c1e5f2ca3131..71af755e8366 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h @@ -15,7 +15,6 @@ #include =0D =0D #include =0D -#include =0D #include =0D =0D #include =0D @@ -111,7 +110,6 @@ #define NOR_FLASH_SIGNATURE SIGNATURE_32('n', 'o', 'r', '0')=0D #define INSTANCE_FROM_FVB_THIS(a) CR(a, NOR_FLASH_INSTANCE, FvbProtoco= l, NOR_FLASH_SIGNATURE)=0D #define INSTANCE_FROM_BLKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, BlockIoPro= tocol, NOR_FLASH_SIGNATURE)=0D -#define INSTANCE_FROM_DISKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, DiskIoProt= ocol, NOR_FLASH_SIGNATURE)=0D =0D typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;=0D =0D @@ -134,7 +132,6 @@ struct _NOR_FLASH_INSTANCE { =0D EFI_BLOCK_IO_PROTOCOL BlockIoProtocol;=0D EFI_BLOCK_IO_MEDIA Media;=0D - EFI_DISK_IO_PROTOCOL DiskIoProtocol;=0D =0D EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;=0D VOID *ShadowBuffer;=0D @@ -203,32 +200,6 @@ NorFlashBlockIoFlushBlocks ( IN EFI_BLOCK_IO_PROTOCOL *This=0D );=0D =0D -//=0D -// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashDiskIoReadDisk (=0D - IN EFI_DISK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN UINT64 Offset,=0D - IN UINTN BufferSize,=0D - OUT VOID *Buffer=0D - );=0D -=0D -//=0D -// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.WriteDisk=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashDiskIoWriteDisk (=0D - IN EFI_DISK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN UINT64 Offset,=0D - IN UINTN BufferSize,=0D - IN VOID *Buffer=0D - );=0D -=0D //=0D // NorFlashFvbDxe.c=0D //=0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashBlockIoDxe.c b/OvmfPkg/Vir= tNorFlashDxe/VirtNorFlashBlockIoDxe.c deleted file mode 100644 index ecf152e35539..000000000000 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashBlockIoDxe.c +++ /dev/null @@ -1,123 +0,0 @@ -/** @file NorFlashBlockIoDxe.c=0D -=0D - Copyright (c) 2011-2013, ARM Ltd. All rights reserved.
=0D -=0D - SPDX-License-Identifier: BSD-2-Clause-Patent=0D -=0D -**/=0D -=0D -#include =0D -#include =0D -=0D -#include "VirtNorFlash.h"=0D -=0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoReset (=0D - IN EFI_BLOCK_IO_PROTOCOL *This,=0D - IN BOOLEAN ExtendedVerification=0D - )=0D -{=0D - NOR_FLASH_INSTANCE *Instance;=0D -=0D - Instance =3D INSTANCE_FROM_BLKIO_THIS (This);=0D -=0D - DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=3D0x%x)\n", This->Med= ia->MediaId));=0D -=0D - return NorFlashReset (Instance);=0D -}=0D -=0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoReadBlocks (=0D - IN EFI_BLOCK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN EFI_LBA Lba,=0D - IN UINTN BufferSizeInBytes,=0D - OUT VOID *Buffer=0D - )=0D -{=0D - NOR_FLASH_INSTANCE *Instance;=0D - EFI_STATUS Status;=0D - EFI_BLOCK_IO_MEDIA *Media;=0D -=0D - if (This =3D=3D NULL) {=0D - return EFI_INVALID_PARAMETER;=0D - }=0D -=0D - Instance =3D INSTANCE_FROM_BLKIO_THIS (This);=0D - Media =3D This->Media;=0D -=0D - DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=3D0x%x, Lba=3D%l= d, BufferSize=3D0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, B= ufferSizeInBytes, BufferSizeInBytes, Buffer));=0D -=0D - if (!Media) {=0D - Status =3D EFI_INVALID_PARAMETER;=0D - } else if (!Media->MediaPresent) {=0D - Status =3D EFI_NO_MEDIA;=0D - } else if (Media->MediaId !=3D MediaId) {=0D - Status =3D EFI_MEDIA_CHANGED;=0D - } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1= )) !=3D 0)) {=0D - Status =3D EFI_INVALID_PARAMETER;=0D - } else {=0D - Status =3D NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffe= r);=0D - }=0D -=0D - return Status;=0D -}=0D -=0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoWriteBlocks (=0D - IN EFI_BLOCK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN EFI_LBA Lba,=0D - IN UINTN BufferSizeInBytes,=0D - IN VOID *Buffer=0D - )=0D -{=0D - NOR_FLASH_INSTANCE *Instance;=0D - EFI_STATUS Status;=0D -=0D - Instance =3D INSTANCE_FROM_BLKIO_THIS (This);=0D -=0D - DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=3D0x%x, Lba=3D%= ld, BufferSize=3D0x%x bytes, BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSi= zeInBytes, Buffer));=0D -=0D - if ( !This->Media->MediaPresent ) {=0D - Status =3D EFI_NO_MEDIA;=0D - } else if ( This->Media->MediaId !=3D MediaId ) {=0D - Status =3D EFI_MEDIA_CHANGED;=0D - } else if ( This->Media->ReadOnly ) {=0D - Status =3D EFI_WRITE_PROTECTED;=0D - } else {=0D - Status =3D NorFlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buff= er);=0D - }=0D -=0D - return Status;=0D -}=0D -=0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoFlushBlocks (=0D - IN EFI_BLOCK_IO_PROTOCOL *This=0D - )=0D -{=0D - // No Flush required for the NOR Flash driver=0D - // because cache operations are not permitted.=0D -=0D - DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENT= ED (not required).\n"));=0D -=0D - // Nothing to do so just return without error=0D - return EFI_SUCCESS;=0D -}=0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFla= shDxe/VirtNorFlashDxe.c index 819425545e46..4875b057d5e2 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c @@ -58,12 +58,6 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate =3D { 1, // LogicalBlocksPerPhysicalBlock=0D }, // Media;=0D =0D - {=0D - EFI_DISK_IO_PROTOCOL_REVISION, // Revision=0D - NorFlashDiskIoReadDisk, // ReadDisk=0D - NorFlashDiskIoWriteDisk // WriteDisk=0D - },=0D -=0D {=0D FvbGetAttributes, // GetAttributes=0D FvbSetAttributes, // SetAttributes=0D @@ -159,8 +153,6 @@ NorFlashCreateInstance ( &Instance->DevicePath,=0D &gEfiBlockIoProtocolGuid,=0D &Instance->BlockIoProtocol,=0D - &gEfiDiskIoProtocolGuid,=0D - &Instance->DiskIoProtocol,=0D NULL=0D );=0D if (EFI_ERROR (Status)) {=0D --=20 2.35.1