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 6BBC5AC0F35 for ; Wed, 29 May 2024 08:55:44 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=h212NDAWyBq2CMFO+CzVuFtoMl3/dFqVTf/58P1v9p8=; 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=1716972944; v=1; b=jh38y9GgXTv7mELIw5n0XaV0dK1HQH2MRlZj8+/0EJuGfRDkJOA+Ka3VwS69eKxz7xNltaMb XbU43X+oQIo+KnGDTEfJZuxZx+5WkTudAN0hcWyxSRaHUqoZjK6yIfzj4/+SFAKcIWHm5sGHjpH wi4AJcoDV33POtgyq6o1dkIfWfheIt5DoKoBuvRzCM6pK1zgZ+cnLDuDY/8b3Pp9wWCKXgj3ITO /Wqv6ckwgGDrq3e7+8abCeJCqSPpc6N9z/XQ1AbHOwcwCTxT8gOEJRXPSYJBcokENt4Ms5aYm1G vd0rrtRN+aEhrt89sFPENU7NcAU4hecaVUW1eiWu+JSiw== X-Received: by 127.0.0.2 with SMTP id zR3iYY7687511xcG2jTaaUWS; Wed, 29 May 2024 01:55:42 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9176.1716972942387338006 for ; Wed, 29 May 2024 01:55:42 -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 51CA12F4; Wed, 29 May 2024 01:56:06 -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 6D5BF3F762; Wed, 29 May 2024 01:55:40 -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 V4 07/17] Platform/ARM: Create NorFlashDeviceLib library interface for flash specific functions Date: Wed, 29 May 2024 14:25:07 +0530 Message-Id: <20240529085517.1074417-8-Sahil.Kaushal@arm.com> In-Reply-To: <20240529085517.1074417-1-Sahil.Kaushal@arm.com> References: <20240529085517.1074417-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: Wed, 29 May 2024 01:55:42 -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: GFnoGsqaoU3BWyFWYXITd2Vlx7686176AA= 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=jh38y9Gg; 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 @@ [Includes] =20 [LibraryClasses] BdsLib|Include/Library/BdsLib.h + NorFlashDeviceLib|Include/Library/NorFlashDeviceLib.h NorFlashPlatformLib|Include/Library/NorFlashPlatformLib.h =20 [Guids] diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h b/Platform/ARM/D= rivers/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 @@ =20 #include #include +#include =20 #define NOR_FLASH_ERASE_RETRY 10 =20 @@ -40,7 +41,6 @@ #define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr) ((BaseAddr) + ((O= ffsetAddr) << 2)) #define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | = ( Cmd & LOW_16_BITS) ) #define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd) MmioWrite32 (CREA= TE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd)) -#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UIN= TN)((Lba) * LbaSize) ) =20 // Status Register Bits #define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7) @@ -105,107 +105,4 @@ #define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060 #define P30_CMD_READ_CONFIGURATION_REGISTER 0x0003 =20 -typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE; - -#pragma pack (1) -typedef struct { - VENDOR_DEVICE_PATH Vendor; - UINT8 Index; - EFI_DEVICE_PATH_PROTOCOL End; -} NOR_FLASH_DEVICE_PATH; -#pragma pack () - -struct _NOR_FLASH_INSTANCE { - UINT32 Signature; - EFI_HANDLE Handle; - - UINTN DeviceBaseAddress; - UINTN RegionBaseAddress; - UINTN Size; - EFI_LBA StartLba; - - EFI_BLOCK_IO_PROTOCOL BlockIoProtocol; - EFI_BLOCK_IO_MEDIA Media; - EFI_DISK_IO_PROTOCOL DiskIoProtocol; - - EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; - VOID *ShadowBuffer; - - NOR_FLASH_DEVICE_PATH DevicePath; -}; - -// -// NorFlash.c -// -EFI_STATUS -NorFlashWriteSingleBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN EFI_LBA Lba, - IN UINTN Offset, - IN OUT UINTN *NumBytes, - IN UINT8 *Buffer - ); - -EFI_STATUS -NorFlashWriteBlocks ( - IN NOR_FLASH_INSTANCE *Instance, - IN EFI_LBA Lba, - IN UINTN BufferSizeInBytes, - IN VOID *Buffer - ); - -EFI_STATUS -NorFlashReadBlocks ( - IN NOR_FLASH_INSTANCE *Instance, - IN EFI_LBA Lba, - IN UINTN BufferSizeInBytes, - OUT VOID *Buffer - ); - -EFI_STATUS -NorFlashRead ( - IN NOR_FLASH_INSTANCE *Instance, - IN EFI_LBA Lba, - IN UINTN Offset, - IN UINTN BufferSizeInBytes, - OUT VOID *Buffer - ); - -EFI_STATUS -NorFlashReset ( - IN NOR_FLASH_INSTANCE *Instance - ); - -EFI_STATUS -NorFlashEraseSingleBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN UINTN BlockAddress - ); - -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 - ); - -VOID -EFIAPI -NorFlashLock ( - IN EFI_TPL *OriginalTPL - ); - -VOID -EFIAPI -NorFlashUnlock ( - IN EFI_TPL OriginalTPL - ); - #endif /* __NOR_FLASH_H__ */ diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h b/Platform= /ARM/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 =20 #include +#include #include #include #include diff --git a/Platform/ARM/Include/Library/NorFlashDeviceLib.h b/Platform/= ARM/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 + + Copyright (c) 2011 - 2024, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef NOR_FLASH_DEVICE_LIB_H_ +#define NOR_FLASH_DEVICE_LIB_H_ + +#include +#include +#include + +typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE; + +#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UIN= TN)((Lba) * LbaSize) ) + +/** + This structure describes the device path for a NOR flash device instan= ce. +**/ +#pragma pack (1) +typedef struct { + VENDOR_DEVICE_PATH Vendor; ///< Vendor specific device path = node. + UINT8 Index; ///< Index of a NOR flash device = instance. + EFI_DEVICE_PATH_PROTOCOL End; ///< End node of a hardware devic= e path. +} NOR_FLASH_DEVICE_PATH; +#pragma pack () + +/** + NOR Flash instance structure used to identify different flash + or regions within a flash. +**/ +struct _NOR_FLASH_INSTANCE { + UINT32 Signature; ///< NOR Flash insta= nce signature. + EFI_HANDLE Handle; ///< NOR Flash insta= nce handle. + + UINTN DeviceBaseAddress; ///< NOR Fla= sh device base address. + UINTN RegionBaseAddress; ///< NOR Fla= sh region base address. + UINTN Size; ///< NOR Fla= sh region size. + EFI_LBA StartLba; ///< Region = start LBA. + + EFI_BLOCK_IO_PROTOCOL BlockIoProtocol; ///< Instance'= s Block IO protocol handle. + EFI_BLOCK_IO_MEDIA Media; ///< Instance'= s Media information. + EFI_DISK_IO_PROTOCOL DiskIoProtocol; ///< Instance'= s Disk IO protocol handle. + + EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; ///< Instance's = FVB protocol handle. + VOID *ShadowBuffer; ///< Instance's = shadow buffer. + + NOR_FLASH_DEVICE_PATH DevicePath; ///< Instance's de= vice path. +}; + +/** + Write a full block to a given location. + + @param[in] Instance NOR flash Instance. + @param[in] Lba The logical block address in NOR = flash. + @param[in] DataBuffer The data to write into NOR flash = location. + @param[in] BlockSizeInWords The number of bytes to write. + + @retval EFI_SUCCESS Write is complete. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_WRITE_PROTECTED The block is write protected. + @retval EFI_INVALID_PARAMETER Invalid parameters passed. + @retval EFI_BUFFER_TOO_SMALL Insufficient buffer size. + @retval EFI_BAD_BUFFER_SIZE Invalid buffer size. +**/ +EFI_STATUS +NorFlashWriteFullBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINT32 *DataBuffer, + IN UINT32 BlockSizeInWords + ); + +/** + This function unlocks and erases an entire NOR Flash block. + + @param[in] Instance NOR flash Instance. + @param[in] BlockAddress Block address to unlock and erase. + + @retval EFI_SUCCESS Erase and unlock successfully comp= leted. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_WRITE_PROTECTED The block is write protected. +**/ +EFI_STATUS +NorFlashUnlockAndEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ); + +/** + Write a full or portion of a block. + + @param[in] Instance NOR flash Instance. + @param[in] Lba The starting logical block inde= x to write to. + @param[in] Offset Offset into the block at which = to begin writing. + @param[in, out] NumBytes The total size of the buffer. + @param[in] Buffer The pointer to a caller-allocat= ed buffer that + contains the source for the wri= te. + + @retval EFI_SUCCESS Write is complete. + @retval EFI_OUT_OF_RESOURCES Invalid Buffer passed. + @retval EFI_BAD_BUFFER_SIZE Buffer size not enough. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_ACCESS_DENIED Device is in write disabled mod= e. +**/ +EFI_STATUS +NorFlashWriteSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ); + +/** + Write multiple blocks. + + @param[in] Instance NOR flash Instance. + @param[in] Lba The starting logical block index. + @param[in] BufferSizeInBytes The number of bytes to write. + @param[in] Buffer The pointer to a caller-allocated= buffer that + contains the source for the write= . + + @retval EFI_SUCCESS Write is complete. + @retval EFI_INVALID_PARAMETER Invalid parameters passed. + @retval EFI_BAD_BUFFER_SIZE Invalid buffer size passed. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_WRITE_PROTECTED The block is write protected. + @retval EFI_BUFFER_TOO_SMALL Insufficient buffer size. +**/ +EFI_STATUS +NorFlashWriteBlocks ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + IN VOID *Buffer + ); + +/** + Read multiple blocks. + + @param[in] Instance NOR flash Instance. + @param[in] Lba The starting logical block index= to read from. + @param[in] BufferSizeInBytes The number of bytes to read. + @param[out] Buffer The pointer to a caller-allocate= d buffer that + should be copied with read data. + + @retval EFI_SUCCESS Read is complete. + @retval EFI_INVALID_PARAMETER Invalid parameters passed. + @retval EFI_BAD_BUFFER_SIZE Invalid buffer size passed. +**/ +EFI_STATUS +NorFlashReadBlocks ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ); + +/** + Read from NOR flash. + + @param[in] Instance NOR flash Instance. + @param[in] Lba The starting logical block index= to read from. + @param[in] Offset Offset into the block at which t= o begin reading. + @param[in] BufferSizeInBytes The number of bytes to read. + @param[out] Buffer The pointer to a caller-allocate= d buffer that + should be copied with read data. + + @retval EFI_SUCCESS Read is complete. + @retval EFI_INVALID_PARAMETER Invalid parameters passed. +**/ +EFI_STATUS +NorFlashRead ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN UINTN BufferSizeInBytes, + OUT VOID *Buffer + ); + +/** + NOR Flash Reset. + + @param[in] Instance NOR flash instance. + + @retval EFI_SUCCESS Return success on successful reset. + @retval EFI_DEVICE_ERROR The device reported an error. +**/ +EFI_STATUS +NorFlashReset ( + IN NOR_FLASH_INSTANCE *Instance + ); + +/** + The following function presumes that the block has already been unlock= ed. + + @param[in] Instance NOR flash instance. + @param[in] BlockAddress Block address to erase. + + @retval EFI_SUCCESS Request is executed successfully. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_WRITE_PROTECTED The block is write protected. + **/ +EFI_STATUS +NorFlashEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ); + +/** + Lock all pending read/write to NOR flash device. + + @param[in] OriginalTPL Pointer to NOR flash device Original TP= L. +**/ +VOID +EFIAPI +NorFlashLock ( + IN EFI_TPL *OriginalTPL + ); + +/** + Unlock all pending read/write to NOR flash device. + + @param[in] OriginalTPL NOR flash device Original TPL. +**/ +VOID +EFIAPI +NorFlashUnlock ( + IN EFI_TPL OriginalTPL + ); + +#endif /* NOR_FLASH_DEVICE_LIB_H_ */ --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119322): https://edk2.groups.io/g/devel/message/119322 Mute This Topic: https://groups.io/mt/106365457/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-