Hi Sahil,

Thank you for this patch.

These changes look good to me.

Reviewed-by: Sami Mujawar <sami.muja...@arm.com>

Regards,

Sami Mujawar

On 23/04/2024 06:56 am, Sahil Kaushal wrote:
From: sahil <sa...@arm.com>

This patch splits NorFlash.h and adds NorFlashCommon.h which
will have all the flash independent functions and macros.
Whereas all the flash specific functions will be in NorFlash.h
header file.

Signed-off-by: sahil <sa...@arm.com>
---
  Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf          |   1 +
  Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf |   1 +
  Platform/ARM/Drivers/NorFlashDxe/NorFlash.h               | 199 
------------------
  Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h         | 221 
++++++++++++++++++++
  Platform/ARM/Drivers/NorFlashDxe/NorFlash.c               |   1 +
  Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c     |   1 +
  Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c            |   1 +
  Platform/ARM/Drivers/NorFlashDxe/NorFlashFvb.c            |   1 +
  Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c   |   1 +
  9 files changed, 228 insertions(+), 199 deletions(-)

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
index cdf1f5c27f35..18e99bac8888 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
@@ -21,6 +21,7 @@
    NorFlash.h

    NorFlashBlockIoDxe.c

    NorFlashDxe.c

+  NorFlashCommon.h

    NorFlashFvb.c

  [Packages]

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
index 001f281220f2..69c40ccf9c27 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
@@ -22,6 +22,7 @@
    NorFlash.c

    NorFlash.h

    NorFlashFvb.c

+  NorFlashCommon.h

    NorFlashStandaloneMm.c

  [Packages]

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
index d4d97bd22cc5..e0ebb1e2fd35 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
@@ -20,9 +20,6 @@
  #include <Library/DebugLib.h>

  #include <Library/IoLib.h>

-#include <Library/NorFlashPlatformLib.h>

-#include <Library/UefiLib.h>

-#include <Library/UefiRuntimeLib.h>

  #define NOR_FLASH_ERASE_RETRY  10

@@ -108,11 +105,6 @@
  #define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP  0x0060

  #define P30_CMD_READ_CONFIGURATION_REGISTER        0x0003

-#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)

-#define INSTANCE_FROM_DISKIO_THIS(a)  CR(a, NOR_FLASH_INSTANCE, 
DiskIoProtocol, NOR_FLASH_SIGNATURE)

-

  typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;

  #pragma pack (1)

@@ -158,197 +150,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

-  );

-

-//

-// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk

-//

-EFI_STATUS

-EFIAPI

-NorFlashDiskIoReadDisk (

-  IN EFI_DISK_IO_PROTOCOL  *This,

-  IN UINT32                MediaId,

-  IN UINT64                Offset,

-  IN UINTN                 BufferSize,

-  OUT VOID                 *Buffer

-  );

-

-//

-// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.WriteDisk

-//

-EFI_STATUS

-EFIAPI

-NorFlashDiskIoWriteDisk (

-  IN EFI_DISK_IO_PROTOCOL  *This,

-  IN UINT32                MediaId,

-  IN UINT64                Offset,

-  IN UINTN                 BufferSize,

-  IN VOID                  *Buffer

-  );

-

-//

-// NorFlashFvbDxe.c

-//

-

-EFI_STATUS

-EFIAPI

-FvbGetAttributes (

-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

-  OUT       EFI_FVB_ATTRIBUTES_2                 *Attributes

-  );

-

-EFI_STATUS

-EFIAPI

-FvbSetAttributes (

-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

-  IN OUT    EFI_FVB_ATTRIBUTES_2                 *Attributes

-  );

-

-EFI_STATUS

-EFIAPI

-FvbGetPhysicalAddress (

-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

-  OUT       EFI_PHYSICAL_ADDRESS                 *Address

-  );

-

-EFI_STATUS

-EFIAPI

-FvbGetBlockSize (

-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

-  IN        EFI_LBA                              Lba,

-  OUT       UINTN                                *BlockSize,

-  OUT       UINTN                                *NumberOfBlocks

-  );

-

-EFI_STATUS

-EFIAPI

-FvbRead (

-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

-  IN        EFI_LBA                              Lba,

-  IN        UINTN                                Offset,

-  IN OUT    UINTN                                *NumBytes,

-  IN OUT    UINT8                                *Buffer

-  );

-

-EFI_STATUS

-EFIAPI

-FvbWrite (

-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

-  IN        EFI_LBA                              Lba,

-  IN        UINTN                                Offset,

-  IN OUT    UINTN                                *NumBytes,

-  IN        UINT8                                *Buffer

-  );

-

-EFI_STATUS

-EFIAPI

-FvbEraseBlocks (

-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

-  ...

-  );

-

-EFI_STATUS

-ValidateFvHeader (

-  IN  NOR_FLASH_INSTANCE  *Instance

-  );

-

-EFI_STATUS

-InitializeFvAndVariableStoreHeaders (

-  IN NOR_FLASH_INSTANCE  *Instance

-  );

-

-VOID

-EFIAPI

-FvbVirtualNotifyEvent (

-  IN EFI_EVENT  Event,

-  IN VOID       *Context

-  );

-

-//

-// NorFlashDxe.c

-//

-

-EFI_STATUS

-NorFlashWriteFullBlock (

-  IN NOR_FLASH_INSTANCE  *Instance,

-  IN EFI_LBA             Lba,

-  IN UINT32              *DataBuffer,

-  IN UINT32              BlockSizeInWords

-  );

-

-EFI_STATUS

-NorFlashUnlockAndEraseSingleBlock (

-  IN NOR_FLASH_INSTANCE  *Instance,

-  IN UINTN               BlockAddress

-  );

-

-EFI_STATUS

-NorFlashCreateInstance (

-  IN UINTN                NorFlashDeviceBase,

-  IN UINTN                NorFlashRegionBase,

-  IN UINTN                NorFlashSize,

-  IN UINT32               Index,

-  IN UINT32               BlockSize,

-  IN BOOLEAN              SupportFvb,

-  OUT NOR_FLASH_INSTANCE  **NorFlashInstance

-  );

-

-EFI_STATUS

-EFIAPI

-NorFlashFvbInitialize (

-  IN NOR_FLASH_INSTANCE  *Instance

-  );

-

-VOID

-EFIAPI

-NorFlashVirtualNotifyEvent (

-  IN EFI_EVENT  Event,

-  IN VOID       *Context

-  );

-

  //

  // NorFlash.c

  //

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
new file mode 100644
index 000000000000..e329e0727617
--- /dev/null
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
@@ -0,0 +1,221 @@
+/** @file

+

+ Copyright (c) 2011-2024, Arm Limited. All rights reserved.<BR>

+

+ SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#ifndef NOR_FLASH_COMMON_H_

+#define NOR_FLASH_COMMON_H_

+

+#include <Base.h>

+#include <PiDxe.h>

+

+#include <Guid/EventGroup.h>

+

+#include <Protocol/BlockIo.h>

+#include <Protocol/DiskIo.h>

+#include <Protocol/FirmwareVolumeBlock.h>

+

+#include <Library/DebugLib.h>

+#include <Library/NorFlashPlatformLib.h>

+#include <Library/UefiLib.h>

+#include <Library/UefiRuntimeLib.h>

+

+#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)

+#define INSTANCE_FROM_DISKIO_THIS(a)  CR(a, NOR_FLASH_INSTANCE, 
DiskIoProtocol, NOR_FLASH_SIGNATURE)

+

+//

+// NorFlashDxe.c

+//

+EFI_STATUS

+NorFlashWriteFullBlock (

+  IN NOR_FLASH_INSTANCE  *Instance,

+  IN EFI_LBA             Lba,

+  IN UINT32              *DataBuffer,

+  IN UINT32              BlockSizeInWords

+  );

+

+EFI_STATUS

+NorFlashUnlockAndEraseSingleBlock (

+  IN NOR_FLASH_INSTANCE  *Instance,

+  IN UINTN               BlockAddress

+  );

+

+EFI_STATUS

+NorFlashCreateInstance (

+  IN UINTN                NorFlashDeviceBase,

+  IN UINTN                NorFlashRegionBase,

+  IN UINTN                NorFlashSize,

+  IN UINT32               Index,

+  IN UINT32               BlockSize,

+  IN BOOLEAN              SupportFvb,

+  OUT NOR_FLASH_INSTANCE  **NorFlashInstance

+  );

+

+EFI_STATUS

+EFIAPI

+NorFlashFvbInitialize (

+  IN NOR_FLASH_INSTANCE  *Instance

+  );

+

+VOID

+EFIAPI

+NorFlashVirtualNotifyEvent (

+  IN EFI_EVENT  Event,

+  IN VOID       *Context

+  );

+

+//

+// 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

+  );

+

+//

+// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk

+//

+EFI_STATUS

+EFIAPI

+NorFlashDiskIoReadDisk (

+  IN EFI_DISK_IO_PROTOCOL  *This,

+  IN UINT32                MediaId,

+  IN UINT64                Offset,

+  IN UINTN                 BufferSize,

+  OUT VOID                 *Buffer

+  );

+

+//

+// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.WriteDisk

+//

+EFI_STATUS

+EFIAPI

+NorFlashDiskIoWriteDisk (

+  IN EFI_DISK_IO_PROTOCOL  *This,

+  IN UINT32                MediaId,

+  IN UINT64                Offset,

+  IN UINTN                 BufferSize,

+  IN VOID                  *Buffer

+  );

+

+//

+// NorFlashFvbDxe.c

+//

+

+EFI_STATUS

+EFIAPI

+FvbGetAttributes (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  OUT       EFI_FVB_ATTRIBUTES_2                 *Attributes

+  );

+

+EFI_STATUS

+EFIAPI

+FvbSetAttributes (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  IN OUT    EFI_FVB_ATTRIBUTES_2                 *Attributes

+  );

+

+EFI_STATUS

+EFIAPI

+FvbGetPhysicalAddress (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  OUT       EFI_PHYSICAL_ADDRESS                 *Address

+  );

+

+EFI_STATUS

+EFIAPI

+FvbGetBlockSize (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  IN        EFI_LBA                              Lba,

+  OUT       UINTN                                *BlockSize,

+  OUT       UINTN                                *NumberOfBlocks

+  );

+

+EFI_STATUS

+EFIAPI

+FvbRead (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  IN        EFI_LBA                              Lba,

+  IN        UINTN                                Offset,

+  IN OUT    UINTN                                *NumBytes,

+  IN OUT    UINT8                                *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+FvbWrite (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  IN        EFI_LBA                              Lba,

+  IN        UINTN                                Offset,

+  IN OUT    UINTN                                *NumBytes,

+  IN        UINT8                                *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+FvbEraseBlocks (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  ...

+  );

+

+EFI_STATUS

+ValidateFvHeader (

+  IN  NOR_FLASH_INSTANCE  *Instance

+  );

+

+EFI_STATUS

+InitializeFvAndVariableStoreHeaders (

+  IN NOR_FLASH_INSTANCE  *Instance

+  );

+

+VOID

+EFIAPI

+FvbVirtualNotifyEvent (

+  IN EFI_EVENT  Event,

+  IN VOID       *Context

+  );

+

+#endif /* NOR_FLASH_COMMON_H_ */

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
index 55f6abd0eef3..4e5a97c83c7b 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
@@ -10,6 +10,7 @@
  #include <Library/BaseMemoryLib.h>

  #include "NorFlash.h"

+#include "NorFlashCommon.h"

  //

  // Global variable declarations

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
index 9b8c76a171d4..a6c73312c596 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
@@ -10,6 +10,7 @@
  #include <Library/UefiBootServicesTableLib.h>

  #include "NorFlash.h"

+#include "NorFlashCommon.h"

  //

  // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
index 963af7dcf435..b1e01169c24e 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
@@ -15,6 +15,7 @@
  #include <Library/DxeServicesTableLib.h>

  #include "NorFlash.h"

+#include "NorFlashCommon.h"

  STATIC EFI_EVENT  mNorFlashVirtualAddrChangeEvent;

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashFvb.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashFvb.c
index 0767581308d2..f9f2856e0c81 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashFvb.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashFvb.c
@@ -19,6 +19,7 @@
  #include <Guid/NvVarStoreFormatted.h>

  #include "NorFlash.h"

+#include "NorFlashCommon.h"

  extern UINTN  mFlashNvStorageVariableBase;

  ///

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
index b72ad97b0b55..f2919265139b 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
@@ -12,6 +12,7 @@
  #include <Library/MmServicesTableLib.h>

  #include "NorFlash.h"

+#include "NorFlashCommon.h"

  //

  // Global variable declarations



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#118959): https://edk2.groups.io/g/devel/message/118959
Mute This Topic: https://groups.io/mt/105690938/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to