From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 01E5A740039 for ; Thu, 23 May 2024 10:56:07 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=yii1eu+anEHl8DTW6vHXDi5y9KZpsOHnBPw8HSFuj8Y=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1716461766; v=1; b=3tHJpOHZsIWidpE/HMr+sP/UJaPETkPEOPICLNTYaMU8XOvYHpf/xhnO+MK0CCE0Wt/7eFx6 1N9UPLfWOcEEi9iGHhZI2i0b0SC/KuYNJh8b5D0cyYWWHJjHTVdmVBrHEtL4HlA77wfNiN/Ty9D j9i2Yr1IyUnteM/mzSoRcO0Qs1OoezLyp8wmfa8fXgfMvI3jpF9NmhSPP318zGR0W9n0ga/qV4k i3ijq785y5wrgDDeM1xiYjHJ5zN0XmIB1ElWF339KoJG8KGz8GUhK3IeLfW7T1vQV+pzzY5elg+ xpqVAopJjl2MN1UBoSaNuHc67zo0taEgv1BltnmbHrkjA== X-Received: by 127.0.0.2 with SMTP id bVZuYY7687511xh54QdhADXu; Thu, 23 May 2024 03:56:06 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.12635.1716461765697853620 for ; Thu, 23 May 2024 03:56:05 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5E8F4339; Thu, 23 May 2024 03:56:29 -0700 (PDT) X-Received: from usa.arm.com (a077434.arm.com [10.162.46.143]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9BD453F766; Thu, 23 May 2024 03:56:03 -0700 (PDT) From: "Sahil Kaushal" To: devel@edk2.groups.io Cc: Ard Biesheuvel , =?UTF-8?q?Leif=20Lindholm=20=C2=A0?= , Sami Mujawar , =?UTF-8?q?sahil=20=C2=A0?= Subject: [edk2-devel] [edk2-platforms][PATCH V3 07/17] Platform/ARM: Create NorFlashDeviceLib library interface for flash specific functions Date: Thu, 23 May 2024 16:25:01 +0530 Message-Id: <20240523105511.13189-8-Sahil.Kaushal@arm.com> In-Reply-To: <20240523105511.13189-1-Sahil.Kaushal@arm.com> References: <20240523105511.13189-1-Sahil.Kaushal@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 23 May 2024 03:56:05 -0700 Resent-From: sahil.kaushal@arm.com Reply-To: devel@edk2.groups.io,sahil.kaushal@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ZduTXpYiwuw3iKohXAIs8ztGx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=3tHJpOHZ; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io From: sahil NorFlashDeviceLib can be used to provide implementations of different NOR Flash to NorFlashDxe, i.e. NorFlashDxe links with NorFlashDeviceLib and the platforms can specify their respective NorFlashDeviceLib instances. This patch splits NorFlash.h and moves out the function prototypes and macros that are expected by NorFlashDxe to be implemented by any Nor Flash implementation to NorFlashDeviceLib.h file. Signed-off-by: sahil --- Platform/ARM/ARM.dec | 1 + Platform/ARM/Drivers/NorFlashDxe/NorFlash.h | 105 +-------- Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h | 1 + Platform/ARM/Include/Library/NorFlashDeviceLib.h | 236 ++++++++++++++++++= ++ 4 files changed, 239 insertions(+), 104 deletions(-) diff --git a/Platform/ARM/ARM.dec b/Platform/ARM/ARM.dec index be7e6dc83fde..86d1fcb4878e 100644 --- a/Platform/ARM/ARM.dec +++ b/Platform/ARM/ARM.dec @@ -17,6 +17,7 @@ =0D [LibraryClasses]=0D BdsLib|Include/Library/BdsLib.h=0D + NorFlashDeviceLib|Include/Library/NorFlashDeviceLib.h=0D NorFlashPlatformLib|Include/Library/NorFlashPlatformLib.h=0D =0D [Guids]=0D diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h b/Platform/ARM/Dri= vers/NorFlashDxe/NorFlash.h index f30d499042ed..6cb1f64b9875 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h @@ -20,6 +20,7 @@ =0D #include =0D #include =0D +#include =0D =0D #define NOR_FLASH_ERASE_RETRY 10=0D =0D @@ -40,7 +41,6 @@ #define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr) ((BaseAddr) + ((Off= setAddr) << 2))=0D #define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | ( = Cmd & LOW_16_BITS) )=0D #define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd) MmioWrite32 (CREATE= _NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))=0D -#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UINTN= )((Lba) * LbaSize) )=0D =0D // Status Register Bits=0D #define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7)=0D @@ -105,107 +105,4 @@ #define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060=0D #define P30_CMD_READ_CONFIGURATION_REGISTER 0x0003=0D =0D -typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;=0D -=0D -#pragma pack (1)=0D -typedef struct {=0D - VENDOR_DEVICE_PATH Vendor;=0D - UINT8 Index;=0D - EFI_DEVICE_PATH_PROTOCOL End;=0D -} NOR_FLASH_DEVICE_PATH;=0D -#pragma pack ()=0D -=0D -struct _NOR_FLASH_INSTANCE {=0D - UINT32 Signature;=0D - EFI_HANDLE Handle;=0D -=0D - UINTN DeviceBaseAddress;=0D - UINTN RegionBaseAddress;=0D - UINTN Size;=0D - EFI_LBA StartLba;=0D -=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 -=0D - NOR_FLASH_DEVICE_PATH DevicePath;=0D -};=0D -=0D -//=0D -// NorFlash.c=0D -//=0D -EFI_STATUS=0D -NorFlashWriteSingleBlock (=0D - IN NOR_FLASH_INSTANCE *Instance,=0D - IN EFI_LBA Lba,=0D - IN UINTN Offset,=0D - IN OUT UINTN *NumBytes,=0D - IN UINT8 *Buffer=0D - );=0D -=0D -EFI_STATUS=0D -NorFlashWriteBlocks (=0D - IN NOR_FLASH_INSTANCE *Instance,=0D - IN EFI_LBA Lba,=0D - IN UINTN BufferSizeInBytes,=0D - IN VOID *Buffer=0D - );=0D -=0D -EFI_STATUS=0D -NorFlashReadBlocks (=0D - IN NOR_FLASH_INSTANCE *Instance,=0D - IN EFI_LBA Lba,=0D - IN UINTN BufferSizeInBytes,=0D - OUT VOID *Buffer=0D - );=0D -=0D -EFI_STATUS=0D -NorFlashRead (=0D - IN NOR_FLASH_INSTANCE *Instance,=0D - IN EFI_LBA Lba,=0D - IN UINTN Offset,=0D - IN UINTN BufferSizeInBytes,=0D - OUT VOID *Buffer=0D - );=0D -=0D -EFI_STATUS=0D -NorFlashReset (=0D - IN NOR_FLASH_INSTANCE *Instance=0D - );=0D -=0D -EFI_STATUS=0D -NorFlashEraseSingleBlock (=0D - IN NOR_FLASH_INSTANCE *Instance,=0D - IN UINTN BlockAddress=0D - );=0D -=0D -EFI_STATUS=0D -NorFlashWriteFullBlock (=0D - IN NOR_FLASH_INSTANCE *Instance,=0D - IN EFI_LBA Lba,=0D - IN UINT32 *DataBuffer,=0D - IN UINT32 BlockSizeInWords=0D - );=0D -=0D -EFI_STATUS=0D -NorFlashUnlockAndEraseSingleBlock (=0D - IN NOR_FLASH_INSTANCE *Instance,=0D - IN UINTN BlockAddress=0D - );=0D -=0D -VOID=0D -EFIAPI=0D -NorFlashLock (=0D - IN EFI_TPL *OriginalTPL=0D - );=0D -=0D -VOID=0D -EFIAPI=0D -NorFlashUnlock (=0D - IN EFI_TPL OriginalTPL=0D - );=0D -=0D #endif /* __NOR_FLASH_H__ */=0D diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h b/Platform/A= RM/Drivers/NorFlashDxe/NorFlashCommon.h index c0a3b5861532..7fcb949843e8 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h @@ -19,6 +19,7 @@ #include =0D =0D #include =0D +#include =0D #include =0D #include =0D #include =0D diff --git a/Platform/ARM/Include/Library/NorFlashDeviceLib.h b/Platform/AR= M/Include/Library/NorFlashDeviceLib.h new file mode 100644 index 000000000000..6833c1ddc456 --- /dev/null +++ b/Platform/ARM/Include/Library/NorFlashDeviceLib.h @@ -0,0 +1,236 @@ +/** @file NorFlashDeviceLib.h=0D +=0D + Copyright (c) 2011 - 2024, Arm Limited. All rights reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef NOR_FLASH_DEVICE_LIB_H_=0D +#define NOR_FLASH_DEVICE_LIB_H_=0D +=0D +#include =0D +#include =0D +#include =0D +=0D +typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;=0D +=0D +#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UINTN= )((Lba) * LbaSize) )=0D +=0D +/**=0D + This structure describes the device path for a NOR flash device instance= .=0D +**/=0D +#pragma pack (1)=0D +typedef struct {=0D + VENDOR_DEVICE_PATH Vendor; ///< Vendor specific device path no= de.=0D + UINT8 Index; ///< Index of a NOR flash device in= stance.=0D + EFI_DEVICE_PATH_PROTOCOL End; ///< End node of a hardware device = path.=0D +} NOR_FLASH_DEVICE_PATH;=0D +#pragma pack ()=0D +=0D +/**=0D + NOR Flash instance structure used to identify different flash=0D + or regions within a flash.=0D +**/=0D +struct _NOR_FLASH_INSTANCE {=0D + UINT32 Signature; ///< NOR Flash instanc= e signature.=0D + EFI_HANDLE Handle; ///< NOR Flash instanc= e handle.=0D +=0D + UINTN DeviceBaseAddress; ///< NOR Flash= device base address.=0D + UINTN RegionBaseAddress; ///< NOR Flash= region base address.=0D + UINTN Size; ///< NOR Flash= region size.=0D + EFI_LBA StartLba; ///< Region st= art LBA.=0D +=0D + EFI_BLOCK_IO_PROTOCOL BlockIoProtocol; ///< Instance's = Block IO protocol handle.=0D + EFI_BLOCK_IO_MEDIA Media; ///< Instance's = Media information.=0D + EFI_DISK_IO_PROTOCOL DiskIoProtocol; ///< Instance's = Disk IO protocol handle.=0D +=0D + EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; ///< Instance's FV= B protocol handle.=0D + VOID *ShadowBuffer; ///< Instance's sh= adow buffer.=0D +=0D + NOR_FLASH_DEVICE_PATH DevicePath; ///< Instance's devi= ce path.=0D +};=0D +=0D +/**=0D + Write a full block to a given location.=0D +=0D + @param[in] Instance NOR flash Instance.=0D + @param[in] Lba The logical block address in NOR fl= ash.=0D + @param[in] DataBuffer The data to write into NOR flash lo= cation.=0D + @param[in] BlockSizeInWords The number of bytes to write.=0D +=0D + @retval EFI_SUCCESS Write is complete.=0D + @retval EFI_DEVICE_ERROR The device reported an error.=0D + @retval EFI_WRITE_PROTECTED The block is write protected.=0D + @retval EFI_INVALID_PARAMETER Invalid parameters passed.=0D + @retval EFI_BUFFER_TOO_SMALL Insufficient buffer size.=0D + @retval EFI_BAD_BUFFER_SIZE Invalid buffer size.=0D +**/=0D +EFI_STATUS=0D +NorFlashWriteFullBlock (=0D + IN NOR_FLASH_INSTANCE *Instance,=0D + IN EFI_LBA Lba,=0D + IN UINT32 *DataBuffer,=0D + IN UINT32 BlockSizeInWords=0D + );=0D +=0D +/**=0D + This function unlocks and erases an entire NOR Flash block.=0D +=0D + @param[in] Instance NOR flash Instance.=0D + @param[in] BlockAddress Block address to unlock and erase.=0D +=0D + @retval EFI_SUCCESS Erase and unlock successfully comple= ted.=0D + @retval EFI_DEVICE_ERROR The device reported an error.=0D + @retval EFI_WRITE_PROTECTED The block is write protected.=0D +**/=0D +EFI_STATUS=0D +NorFlashUnlockAndEraseSingleBlock (=0D + IN NOR_FLASH_INSTANCE *Instance,=0D + IN UINTN BlockAddress=0D + );=0D +=0D +/**=0D + Write a full or portion of a block.=0D +=0D + @param[in] Instance NOR flash Instance.=0D + @param[in] Lba The starting logical block index = to write to.=0D + @param[in] Offset Offset into the block at which to= begin writing.=0D + @param[in, out] NumBytes The total size of the buffer.=0D + @param[in] Buffer The pointer to a caller-allocated= buffer that=0D + contains the source for the write= .=0D +=0D + @retval EFI_SUCCESS Write is complete.=0D + @retval EFI_OUT_OF_RESOURCES Invalid Buffer passed.=0D + @retval EFI_BAD_BUFFER_SIZE Buffer size not enough.=0D + @retval EFI_DEVICE_ERROR The device reported an error.=0D + @retval EFI_ACCESS_DENIED Device is in write disabled mode.= =0D +**/=0D +EFI_STATUS=0D +NorFlashWriteSingleBlock (=0D + IN NOR_FLASH_INSTANCE *Instance,=0D + IN EFI_LBA Lba,=0D + IN UINTN Offset,=0D + IN OUT UINTN *NumBytes,=0D + IN UINT8 *Buffer=0D + );=0D +=0D +/**=0D + Write multiple blocks.=0D +=0D + @param[in] Instance NOR flash Instance.=0D + @param[in] Lba The starting logical block index.=0D + @param[in] BufferSizeInBytes The number of bytes to write.=0D + @param[in] Buffer The pointer to a caller-allocated b= uffer that=0D + contains the source for the write.= =0D +=0D + @retval EFI_SUCCESS Write is complete.=0D + @retval EFI_INVALID_PARAMETER Invalid parameters passed.=0D + @retval EFI_BAD_BUFFER_SIZE Invalid buffer size passed.=0D + @retval EFI_DEVICE_ERROR The device reported an error.=0D + @retval EFI_WRITE_PROTECTED The block is write protected.=0D + @retval EFI_BUFFER_TOO_SMALL Insufficient buffer size.=0D +**/=0D +EFI_STATUS=0D +NorFlashWriteBlocks (=0D + IN NOR_FLASH_INSTANCE *Instance,=0D + IN EFI_LBA Lba,=0D + IN UINTN BufferSizeInBytes,=0D + IN VOID *Buffer=0D + );=0D +=0D +/**=0D + Read multiple blocks.=0D +=0D + @param[in] Instance NOR flash Instance.=0D + @param[in] Lba The starting logical block index t= o read from.=0D + @param[in] BufferSizeInBytes The number of bytes to read.=0D + @param[out] Buffer The pointer to a caller-allocated = buffer that=0D + should be copied with read data.=0D +=0D + @retval EFI_SUCCESS Read is complete.=0D + @retval EFI_INVALID_PARAMETER Invalid parameters passed.=0D + @retval EFI_BAD_BUFFER_SIZE Invalid buffer size passed.=0D +**/=0D +EFI_STATUS=0D +NorFlashReadBlocks (=0D + IN NOR_FLASH_INSTANCE *Instance,=0D + IN EFI_LBA Lba,=0D + IN UINTN BufferSizeInBytes,=0D + OUT VOID *Buffer=0D + );=0D +=0D +/**=0D + Read from NOR flash.=0D +=0D + @param[in] Instance NOR flash Instance.=0D + @param[in] Lba The starting logical block index t= o read from.=0D + @param[in] Offset Offset into the block at which to = begin reading.=0D + @param[in] BufferSizeInBytes The number of bytes to read.=0D + @param[out] Buffer The pointer to a caller-allocated = buffer that=0D + should be copied with read data.=0D +=0D + @retval EFI_SUCCESS Read is complete.=0D + @retval EFI_INVALID_PARAMETER Invalid parameters passed.=0D +**/=0D +EFI_STATUS=0D +NorFlashRead (=0D + IN NOR_FLASH_INSTANCE *Instance,=0D + IN EFI_LBA Lba,=0D + IN UINTN Offset,=0D + IN UINTN BufferSizeInBytes,=0D + OUT VOID *Buffer=0D + );=0D +=0D +/**=0D + NOR Flash Reset.=0D +=0D + @param[in] Instance NOR flash instance.=0D +=0D + @retval EFI_SUCCESS Return success on successful reset.=0D + @retval EFI_DEVICE_ERROR The device reported an error.=0D +**/=0D +EFI_STATUS=0D +NorFlashReset (=0D + IN NOR_FLASH_INSTANCE *Instance=0D + );=0D +=0D +/**=0D + The following function presumes that the block has already been unlocked= .=0D +=0D + @param[in] Instance NOR flash instance.=0D + @param[in] BlockAddress Block address to erase.=0D +=0D + @retval EFI_SUCCESS Request is executed successfully.=0D + @retval EFI_DEVICE_ERROR The device reported an error.=0D + @retval EFI_WRITE_PROTECTED The block is write protected.=0D + **/=0D +EFI_STATUS=0D +NorFlashEraseSingleBlock (=0D + IN NOR_FLASH_INSTANCE *Instance,=0D + IN UINTN BlockAddress=0D + );=0D +=0D +/**=0D + Lock all pending read/write to NOR flash device.=0D +=0D + @param[in] OriginalTPL Pointer to NOR flash device Original TPL.= =0D +**/=0D +VOID=0D +EFIAPI=0D +NorFlashLock (=0D + IN EFI_TPL *OriginalTPL=0D + );=0D +=0D +/**=0D + Unlock all pending read/write to NOR flash device.=0D +=0D + @param[in] OriginalTPL NOR flash device Original TPL.=0D +**/=0D +VOID=0D +EFIAPI=0D +NorFlashUnlock (=0D + IN EFI_TPL OriginalTPL=0D + );=0D +=0D +#endif /* NOR_FLASH_DEVICE_LIB_H_ */=0D --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119149): https://edk2.groups.io/g/devel/message/119149 Mute This Topic: https://groups.io/mt/106260145/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-