public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb@kernel.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Sunil V L <sunilvl@ventanamicro.com>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>
Subject: [PATCH 05/11] OvmfPkg/VirtNorFlashDxe: drop block I/O protocol implementation
Date: Mon, 24 Oct 2022 19:01:16 +0200	[thread overview]
Message-ID: <20221024170122.594577-6-ardb@kernel.org> (raw)
In-Reply-To: <20221024170122.594577-1-ardb@kernel.org>

We never boot from NOR flash, and generally rely on the firmware volume
PI protocols to expose the contents. So drop the block I/O protocol
implementation from VirtNorFlashDxe.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c      | 49 ++++++------------
 OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h      | 52 +-------------------
 OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c   | 40 +++------------
 OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf |  1 -
 OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c   | 52 ++++++++------------
 5 files changed, 44 insertions(+), 150 deletions(-)

diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
index 1094d48f7de4..f41d9d372f49 100644
--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
+++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
@@ -366,10 +366,6 @@ NorFlashWriteBlocks (
     return EFI_INVALID_PARAMETER;
   }
 
-  if (Instance->Media.ReadOnly == TRUE) {
-    return EFI_WRITE_PROTECTED;
-  }
-
   // We must have some bytes to read
   DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes));
   if (BufferSizeInBytes == 0) {
@@ -377,22 +373,22 @@ NorFlashWriteBlocks (
   }
 
   // The size of the buffer must be a multiple of the block size
-  DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize));
-  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {
+  DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->BlockSize));
+  if ((BufferSizeInBytes % Instance->BlockSize) != 0) {
     return EFI_BAD_BUFFER_SIZE;
   }
 
   // All blocks must be within the device
-  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;
+  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->BlockSize;
 
-  DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));
+  DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->LastBlock, Lba));
 
-  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
+  if ((Lba + NumBlocks) > (Instance->LastBlock + 1)) {
     DEBUG ((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));
     return EFI_INVALID_PARAMETER;
   }
 
-  BlockSizeInWords = Instance->Media.BlockSize / 4;
+  BlockSizeInWords = Instance->BlockSize / 4;
 
   // Because the target *Buffer is a pointer to VOID, we must put all the data into a pointer
   // to a proper data type, so use *ReadBuffer
@@ -489,8 +485,8 @@ NorFlashReadBlocks (
     DEBUG_BLKIO,
     "NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n",
     BufferSizeInBytes,
-    Instance->Media.BlockSize,
-    Instance->Media.LastBlock,
+    Instance->BlockSize,
+    Instance->LastBlock,
     Lba
     ));
 
@@ -505,14 +501,14 @@ NorFlashReadBlocks (
   }
 
   // The size of the buffer must be a multiple of the block size
-  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {
+  if ((BufferSizeInBytes % Instance->BlockSize) != 0) {
     return EFI_BAD_BUFFER_SIZE;
   }
 
   // All blocks must be within the device
-  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;
+  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->BlockSize;
 
-  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
+  if ((Lba + NumBlocks) > (Instance->LastBlock + 1)) {
     DEBUG ((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));
     return EFI_INVALID_PARAMETER;
   }
@@ -521,7 +517,7 @@ NorFlashReadBlocks (
   StartAddress = GET_NOR_BLOCK_ADDRESS (
                    Instance->RegionBaseAddress,
                    Lba,
-                   Instance->Media.BlockSize
+                   Instance->BlockSize
                    );
 
   // Put the device into Read Array mode
@@ -554,7 +550,7 @@ NorFlashRead (
     return EFI_SUCCESS;
   }
 
-  if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > Instance->Size) {
+  if (((Lba * Instance->BlockSize) + Offset + BufferSizeInBytes) > Instance->Size) {
     DEBUG ((DEBUG_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n"));
     return EFI_INVALID_PARAMETER;
   }
@@ -563,7 +559,7 @@ NorFlashRead (
   StartAddress = GET_NOR_BLOCK_ADDRESS (
                    Instance->RegionBaseAddress,
                    Lba,
-                   Instance->Media.BlockSize
+                   Instance->BlockSize
                    );
 
   // Put the device into Read Array mode
@@ -577,7 +573,7 @@ NorFlashRead (
 
 /*
   Write a full or portion of a block. It must not span block boundaries; that is,
-  Offset + *NumBytes <= Instance->Media.BlockSize.
+  Offset + *NumBytes <= Instance->BlockSize.
 */
 EFI_STATUS
 NorFlashWriteSingleBlock (
@@ -605,15 +601,8 @@ NorFlashWriteSingleBlock (
 
   DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes, Buffer));
 
-  // Detect WriteDisabled state
-  if (Instance->Media.ReadOnly == TRUE) {
-    DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - Can not write: Device is in WriteDisabled state.\n"));
-    // It is in WriteDisabled state, return an error right away
-    return EFI_ACCESS_DENIED;
-  }
-
   // Cache the block size to avoid de-referencing pointers all the time
-  BlockSize = Instance->Media.BlockSize;
+  BlockSize = Instance->BlockSize;
 
   // The write must not span block boundaries.
   // We need to check each variable individually because adding two large values together overflows.
@@ -819,12 +808,6 @@ NorFlashVirtualNotifyEvent (
     EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->DeviceBaseAddress);
     EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->RegionBaseAddress);
 
-    // Convert BlockIo protocol
-    EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks);
-    EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks);
-    EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.Reset);
-    EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks);
-
     // Convert Fvb
     EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks);
     EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes);
diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h
index 71af755e8366..df3cdb05d065 100644
--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h
+++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h
@@ -14,7 +14,6 @@
 
 #include <Guid/EventGroup.h>
 
-#include <Protocol/BlockIo.h>
 #include <Protocol/FirmwareVolumeBlock.h>
 
 #include <Library/DebugLib.h>
@@ -109,7 +108,6 @@
 
 #define NOR_FLASH_SIGNATURE  SIGNATURE_32('n', 'o', 'r', '0')
 #define INSTANCE_FROM_FVB_THIS(a)     CR(a, NOR_FLASH_INSTANCE, FvbProtocol, NOR_FLASH_SIGNATURE)
-#define INSTANCE_FROM_BLKIO_THIS(a)   CR(a, NOR_FLASH_INSTANCE, BlockIoProtocol, NOR_FLASH_SIGNATURE)
 
 typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;
 
@@ -129,9 +127,8 @@ struct _NOR_FLASH_INSTANCE {
   UINTN                                  RegionBaseAddress;
   UINTN                                  Size;
   EFI_LBA                                StartLba;
-
-  EFI_BLOCK_IO_PROTOCOL                  BlockIoProtocol;
-  EFI_BLOCK_IO_MEDIA                     Media;
+  EFI_LBA                                LastBlock;
+  UINT32                                 BlockSize;
 
   EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL    FvbProtocol;
   VOID                                   *ShadowBuffer;
@@ -155,51 +152,6 @@ NorFlashWriteBuffer (
   IN UINT32              *Buffer
   );
 
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReset (
-  IN EFI_BLOCK_IO_PROTOCOL  *This,
-  IN BOOLEAN                ExtendedVerification
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReadBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL  *This,
-  IN  UINT32                 MediaId,
-  IN  EFI_LBA                Lba,
-  IN  UINTN                  BufferSizeInBytes,
-  OUT VOID                   *Buffer
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoWriteBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL  *This,
-  IN  UINT32                 MediaId,
-  IN  EFI_LBA                Lba,
-  IN  UINTN                  BufferSizeInBytes,
-  IN  VOID                   *Buffer
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoFlushBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL  *This
-  );
-
 //
 // NorFlashFvbDxe.c
 //
diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
index 4875b057d5e2..2ceda226359c 100644
--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
+++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c
@@ -34,29 +34,8 @@ NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {
   0, // RegionBaseAddress ... NEED TO BE FILLED
   0, // Size ... NEED TO BE FILLED
   0, // StartLba
-
-  {
-    EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision
-    NULL,                            // Media ... NEED TO BE FILLED
-    NorFlashBlockIoReset,            // Reset;
-    NorFlashBlockIoReadBlocks,       // ReadBlocks
-    NorFlashBlockIoWriteBlocks,      // WriteBlocks
-    NorFlashBlockIoFlushBlocks       // FlushBlocks
-  }, // BlockIoProtocol
-
-  {
-    0,     // MediaId ... NEED TO BE FILLED
-    FALSE, // RemovableMedia
-    TRUE,  // MediaPresent
-    FALSE, // LogicalPartition
-    FALSE, // ReadOnly
-    FALSE, // WriteCaching;
-    0,     // BlockSize ... NEED TO BE FILLED
-    4,     //  IoAlign
-    0,     // LastBlock ... NEED TO BE FILLED
-    0,     // LowestAlignedLba
-    1,     // LogicalBlocksPerPhysicalBlock
-  }, // Media;
+  0, // LastBlock
+  0, // BlockSize
 
   {
     FvbGetAttributes,      // GetAttributes
@@ -115,11 +94,8 @@ NorFlashCreateInstance (
   Instance->DeviceBaseAddress = NorFlashDeviceBase;
   Instance->RegionBaseAddress = NorFlashRegionBase;
   Instance->Size              = NorFlashSize;
-
-  Instance->BlockIoProtocol.Media = &Instance->Media;
-  Instance->Media.MediaId         = Index;
-  Instance->Media.BlockSize       = BlockSize;
-  Instance->Media.LastBlock       = (NorFlashSize / BlockSize)-1;
+  Instance->BlockSize         = BlockSize;
+  Instance->LastBlock         = (NorFlashSize / BlockSize) - 1;
 
   CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);
   Instance->DevicePath.Index = (UINT8)Index;
@@ -136,8 +112,6 @@ NorFlashCreateInstance (
                     &Instance->Handle,
                     &gEfiDevicePathProtocolGuid,
                     &Instance->DevicePath,
-                    &gEfiBlockIoProtocolGuid,
-                    &Instance->BlockIoProtocol,
                     &gEfiFirmwareVolumeBlockProtocolGuid,
                     &Instance->FvbProtocol,
                     NULL
@@ -151,8 +125,6 @@ NorFlashCreateInstance (
                     &Instance->Handle,
                     &gEfiDevicePathProtocolGuid,
                     &Instance->DevicePath,
-                    &gEfiBlockIoProtocolGuid,
-                    &Instance->BlockIoProtocol,
                     NULL
                     );
     if (EFI_ERROR (Status)) {
@@ -434,7 +406,7 @@ NorFlashFvbInitialize (
                                 PcdGet64 (PcdFlashNvStorageVariableBase64) : PcdGet32 (PcdFlashNvStorageVariableBase);
 
   // Set the index of the first LBA for the FVB
-  Instance->StartLba = (mFlashNvStorageVariableBase - Instance->RegionBaseAddress) / Instance->Media.BlockSize;
+  Instance->StartLba = (mFlashNvStorageVariableBase - Instance->RegionBaseAddress) / Instance->BlockSize;
 
   BootMode = GetBootModeHob ();
   if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
@@ -455,7 +427,7 @@ NorFlashFvbInitialize (
       ));
 
     // Erase all the NorFlash that is reserved for variable storage
-    FvbNumLba = (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
+    FvbNumLba = (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / Instance->BlockSize;
 
     Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);
     if (EFI_ERROR (Status)) {
diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf
index 53e9d5820488..2a3d4a218e61 100644
--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf
+++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf
@@ -19,7 +19,6 @@ [Defines]
 [Sources.common]
   VirtNorFlash.c
   VirtNorFlash.h
-  VirtNorFlashBlockIoDxe.c
   VirtNorFlashDxe.c
   VirtNorFlashFvb.c
 
diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c
index c824e0a0fbad..eefa71fa1e20 100644
--- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c
+++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c
@@ -89,7 +89,7 @@ InitializeFvAndVariableStoreHeaders (
   }
 
   // Check if the size of the area is at least one block size
-  if ((NvStorageVariableSize <= 0) || (NvStorageVariableSize / Instance->Media.BlockSize <= 0)) {
+  if ((NvStorageVariableSize <= 0) || (NvStorageVariableSize / Instance->BlockSize <= 0)) {
     DEBUG ((
       DEBUG_ERROR,
       "%a: NvStorageVariableSize is 0x%x, should be atleast one block size\n",
@@ -99,7 +99,7 @@ InitializeFvAndVariableStoreHeaders (
     return EFI_INVALID_PARAMETER;
   }
 
-  if ((NvStorageFtwWorkingSize <= 0) || (NvStorageFtwWorkingSize / Instance->Media.BlockSize <= 0)) {
+  if ((NvStorageFtwWorkingSize <= 0) || (NvStorageFtwWorkingSize / Instance->BlockSize <= 0)) {
     DEBUG ((
       DEBUG_ERROR,
       "%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block size\n",
@@ -109,7 +109,7 @@ InitializeFvAndVariableStoreHeaders (
     return EFI_INVALID_PARAMETER;
   }
 
-  if ((NvStorageFtwSpareSize <= 0) || (NvStorageFtwSpareSize / Instance->Media.BlockSize <= 0)) {
+  if ((NvStorageFtwSpareSize <= 0) || (NvStorageFtwSpareSize / Instance->BlockSize <= 0)) {
     DEBUG ((
       DEBUG_ERROR,
       "%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size\n",
@@ -120,9 +120,9 @@ InitializeFvAndVariableStoreHeaders (
   }
 
   // Ensure the Variable area Base Addresses are aligned on a block size boundaries
-  if ((NvStorageVariableBase % Instance->Media.BlockSize != 0) ||
-      (NvStorageFtwWorkingBase % Instance->Media.BlockSize != 0) ||
-      (NvStorageFtwSpareBase % Instance->Media.BlockSize != 0))
+  if ((NvStorageVariableBase % Instance->BlockSize != 0) ||
+      (NvStorageFtwWorkingBase % Instance->BlockSize != 0) ||
+      (NvStorageFtwSpareBase % Instance->BlockSize != 0))
   {
     DEBUG ((DEBUG_ERROR, "%a: NvStorage Base addresses must be aligned to block size boundaries", __FUNCTION__));
     return EFI_INVALID_PARAMETER;
@@ -149,8 +149,8 @@ InitializeFvAndVariableStoreHeaders (
                                                             );
   FirmwareVolumeHeader->HeaderLength          = sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY);
   FirmwareVolumeHeader->Revision              = EFI_FVH_REVISION;
-  FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1;
-  FirmwareVolumeHeader->BlockMap[0].Length    = Instance->Media.BlockSize;
+  FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->LastBlock + 1;
+  FirmwareVolumeHeader->BlockMap[0].Length    = Instance->BlockSize;
   FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;
   FirmwareVolumeHeader->BlockMap[1].Length    = 0;
   FirmwareVolumeHeader->Checksum              = CalculateCheckSum16 ((UINT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength);
@@ -294,17 +294,12 @@ FvbGetAttributes (
                                               EFI_FVB2_READ_STATUS      | // Reads are currently enabled
                                               EFI_FVB2_STICKY_WRITE     | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
                                               EFI_FVB2_MEMORY_MAPPED    | // It is memory mapped
-                                              EFI_FVB2_ERASE_POLARITY     // After erasure all bits take this value (i.e. '1')
+                                              EFI_FVB2_ERASE_POLARITY   | // After erasure all bits take this value (i.e. '1')
+                                              EFI_FVB2_WRITE_STATUS     | // Writes are currently enabled
+                                              EFI_FVB2_WRITE_ENABLED_CAP  // Writes may be enabled
 
                                               );
 
-  // Check if it is write protected
-  if (Instance->Media.ReadOnly != TRUE) {
-    FlashFvbAttributes = FlashFvbAttributes         |
-                         EFI_FVB2_WRITE_STATUS      | // Writes are currently enabled
-                         EFI_FVB2_WRITE_ENABLED_CAP;  // Writes may be enabled
-  }
-
   *Attributes = FlashFvbAttributes;
 
   DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes));
@@ -418,15 +413,15 @@ FvbGetBlockSize (
 
   Instance = INSTANCE_FROM_FVB_THIS (This);
 
-  DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock));
+  DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->BlockSize, Instance->LastBlock));
 
-  if (Lba > Instance->Media.LastBlock) {
-    DEBUG ((DEBUG_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is beyond the last Lba (%ld).\n", Lba, Instance->Media.LastBlock));
+  if (Lba > Instance->LastBlock) {
+    DEBUG ((DEBUG_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is beyond the last Lba (%ld).\n", Lba, Instance->LastBlock));
     Status = EFI_INVALID_PARAMETER;
   } else {
     // This is easy because in this platform each NorFlash device has equal sized blocks.
-    *BlockSize      = (UINTN)Instance->Media.BlockSize;
-    *NumberOfBlocks = (UINTN)(Instance->Media.LastBlock - Lba + 1);
+    *BlockSize      = (UINTN)Instance->BlockSize;
+    *NumberOfBlocks = (UINTN)(Instance->LastBlock - Lba + 1);
 
     DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, *NumberOfBlocks));
 
@@ -498,7 +493,7 @@ FvbRead (
   TempStatus = EFI_SUCCESS;
 
   // Cache the block size to avoid de-referencing pointers all the time
-  BlockSize = Instance->Media.BlockSize;
+  BlockSize = Instance->BlockSize;
 
   DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
 
@@ -669,13 +664,6 @@ FvbEraseBlocks (
 
   Status = EFI_SUCCESS;
 
-  // Detect WriteDisabled state
-  if (Instance->Media.ReadOnly == TRUE) {
-    // Firmware volume is in WriteDisabled state
-    DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Device is in WriteDisabled state.\n"));
-    return EFI_ACCESS_DENIED;
-  }
-
   // Before erasing, check the entire list of parameters to ensure all specified blocks are valid
 
   VA_START (Args, This);
@@ -698,9 +686,9 @@ FvbEraseBlocks (
       "FvbEraseBlocks: Check if: ( StartingLba=%ld + NumOfLba=%Lu - 1 ) > LastBlock=%ld.\n",
       Instance->StartLba + StartingLba,
       (UINT64)NumOfLba,
-      Instance->Media.LastBlock
+      Instance->LastBlock
       ));
-    if ((NumOfLba == 0) || ((Instance->StartLba + StartingLba + NumOfLba - 1) > Instance->Media.LastBlock)) {
+    if ((NumOfLba == 0) || ((Instance->StartLba + StartingLba + NumOfLba - 1) > Instance->LastBlock)) {
       VA_END (Args);
       DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past the last Lba.\n"));
       Status = EFI_INVALID_PARAMETER;
@@ -733,7 +721,7 @@ FvbEraseBlocks (
       BlockAddress = GET_NOR_BLOCK_ADDRESS (
                        Instance->RegionBaseAddress,
                        Instance->StartLba + StartingLba,
-                       Instance->Media.BlockSize
+                       Instance->BlockSize
                        );
 
       // Erase it
-- 
2.35.1


  parent reply	other threads:[~2022-10-24 17:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24 17:01 [PATCH 00/11] ArmVirtPkg: introduce VirtNorFlashDxe Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 01/11] OvmfPkg: clone NorFlashPlatformLib into VirtNorFlashPlatformLib Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 02/11] OvmfPkg/VirtNorFlashDxe: clone ArmPlatformPkg's NOR flash driver Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 03/11] OvmfPkg/VirtNorFlashDxe: remove CheckBlockLocked feature Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 04/11] OvmfPkg/VirtNorFlashDxe: remove disk I/O protocol implementation Ard Biesheuvel
2022-10-24 17:01 ` Ard Biesheuvel [this message]
2022-10-24 17:01 ` [PATCH 06/11] OvmfPkg/VirtNorFlashDxe: avoid array mode switch after each word write Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 07/11] OvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 08/11] OvmfPkg/VirtNorFlashDxe: use EFI_MEMORY_WC and drop AlignedCopyMem() Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 09/11] ArmVirtPkg/ArmVirtQemu: migrate to OVMF's VirtNorFlashDxe Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 10/11] ArmVirtPkg/ArmVirtKvmTool: Migrate " Ard Biesheuvel
2022-10-24 17:01 ` [PATCH 11/11] ArmPlatformPkg: Retire NorFlashDxe driver Ard Biesheuvel
2022-10-25 16:32   ` Leif Lindholm
2022-10-27  4:47 ` [PATCH 00/11] ArmVirtPkg: introduce VirtNorFlashDxe Sunil V L
2022-10-27 16:56   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221024170122.594577-6-ardb@kernel.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox