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 36B7AD8027A for ; Wed, 29 May 2024 08:55:31 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=oIFjll+bJBsAWHvmkQ+Hi+a8ARWMHrBmiXCDcKwB/q8=; 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=1716972930; v=1; b=OwT5mu3LD9tgAo0f+4RoDXczzVHdYjK+C4rok1UQeALXfDvYom5GCg56FfXUb5OBnEt8qV6d 128dBPLB37va6WhtcThSf2gby7tehLAG+FLAKk1ZhSOAM81LHhalkbrwuMwOclvdr9PlbADH0Hg veZ9beYe9v7axhG4JTWq1T9R8WsI/RzxTLjuyQhc/1uNvpreRTGKlcKtVYQjJX1KXZFS7BqL4vx i3znuabYo2vMhGI34qdgKTiKRnE1L1nRJ4Uj2bzW93OKz8uWIjbhrUG+Cic6soQsHnk0camAray 8wAIW400d3UYZa721f31V3lSCNvJ3sAv8mv/qEAWT+G3w== X-Received: by 127.0.0.2 with SMTP id i9Z9YY7687511x3zPuUNojKf; Wed, 29 May 2024 01:55:29 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.9242.1716972929113781446 for ; Wed, 29 May 2024 01:55:29 -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 0A1C51596; Wed, 29 May 2024 01:55:53 -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 261C23F762; Wed, 29 May 2024 01:55:26 -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 01/17] Platform/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c Date: Wed, 29 May 2024 14:25:01 +0530 Message-Id: <20240529085517.1074417-2-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:29 -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: fuUznniWofPJfKxaMjQkkuqtx7686176AA= 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=OwT5mu3L; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none) From: sahil Moving these functions from NorFlash.c to NorFlashBlockIoDxe.c as they are not dependent on any particular flash implementation. Signed-off-by: sahil --- Platform/ARM/Drivers/NorFlashDxe/NorFlash.c | 129 ------------= -------- Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c | 129 ++++++++++++= ++++++++ 2 files changed, 129 insertions(+), 129 deletions(-) diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c b/Platform/ARM/D= rivers/NorFlashDxe/NorFlash.c index 1b431073ee93..60854ef2a7d0 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c @@ -807,135 +807,6 @@ NorFlashWriteSingleBlock ( return EFI_SUCCESS; } =20 -/* - Although DiskIoDxe will automatically install the DiskIO protocol when= ever - we install the BlockIO protocol, its implementation is sub-optimal as = it reads - and writes entire blocks using the BlockIO protocol. In fact we can ac= cess - NOR flash with a finer granularity than that, so we can improve perfor= mance - by directly producing the DiskIO protocol. -*/ - -/** - Read BufferSize bytes from Offset into Buffer. - - @param This Protocol instance pointer. - @param MediaId Id of the media, changes every time the = media is replaced. - @param Offset The starting byte offset to read from - @param BufferSize Size of Buffer - @param Buffer Buffer containing read data - - @retval EFI_SUCCESS The data was read correctly from the dev= ice. - @retval EFI_DEVICE_ERROR The device reported an error while perfo= rming the read. - @retval EFI_NO_MEDIA There is no media in the device. - @retval EFI_MEDIA_CHANGED The MediaId does not match the current d= evice. - @retval EFI_INVALID_PARAMETER The read request contains device address= es that are not - valid for the device. - -**/ -EFI_STATUS -EFIAPI -NorFlashDiskIoReadDisk ( - IN EFI_DISK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN UINT64 DiskOffset, - IN UINTN BufferSize, - OUT VOID *Buffer - ) -{ - NOR_FLASH_INSTANCE *Instance; - UINT32 BlockSize; - UINT32 BlockOffset; - EFI_LBA Lba; - - Instance =3D INSTANCE_FROM_DISKIO_THIS (This); - - if (MediaId !=3D Instance->Media.MediaId) { - return EFI_MEDIA_CHANGED; - } - - BlockSize =3D Instance->Media.BlockSize; - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Blo= ckOffset); - - return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer); -} - -/** - Writes a specified number of bytes to a device. - - @param This Indicates a pointer to the calling context. - @param MediaId ID of the medium to be written. - @param Offset The starting byte offset on the logical block I/O d= evice to write. - @param BufferSize The size in bytes of Buffer. The number of bytes to= write to the device. - @param Buffer A pointer to the buffer containing the data to be w= ritten. - - @retval EFI_SUCCESS The data was written correctly to the de= vice. - @retval EFI_WRITE_PROTECTED The device can not be written to. - @retval EFI_DEVICE_ERROR The device reported an error while perfo= rming the write. - @retval EFI_NO_MEDIA There is no media in the device. - @retval EFI_MEDIA_CHANGED The MediaId does not match the current d= evice. - @retval EFI_INVALID_PARAMETER The write request contains device addres= ses that are not - valid for the device. - -**/ -EFI_STATUS -EFIAPI -NorFlashDiskIoWriteDisk ( - IN EFI_DISK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN UINT64 DiskOffset, - IN UINTN BufferSize, - IN VOID *Buffer - ) -{ - NOR_FLASH_INSTANCE *Instance; - UINT32 BlockSize; - UINT32 BlockOffset; - EFI_LBA Lba; - UINTN RemainingBytes; - UINTN WriteSize; - EFI_STATUS Status; - - Instance =3D INSTANCE_FROM_DISKIO_THIS (This); - - if (MediaId !=3D Instance->Media.MediaId) { - return EFI_MEDIA_CHANGED; - } - - BlockSize =3D Instance->Media.BlockSize; - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Blo= ckOffset); - - RemainingBytes =3D BufferSize; - - // Write either all the remaining bytes, or the number of bytes that b= ring - // us up to a block boundary, whichever is less. - // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the nex= t - // block boundary (even if it is already on one). - WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1= ) - DiskOffset); - - do { - if (WriteSize =3D=3D BlockSize) { - // Write a full block - Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSiz= e / sizeof (UINT32)); - } else { - // Write a partial block - Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &= WriteSize, Buffer); - } - - if (EFI_ERROR (Status)) { - return Status; - } - - // Now continue writing either all the remaining bytes or single blo= cks. - RemainingBytes -=3D WriteSize; - Buffer =3D (UINT8 *)Buffer + WriteSize; - Lba++; - BlockOffset =3D 0; - WriteSize =3D MIN (RemainingBytes, BlockSize); - } while (RemainingBytes); - - return Status; -} - EFI_STATUS NorFlashReset ( IN NOR_FLASH_INSTANCE *Instance diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/Plat= form/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c index 9d4732c6905a..9b8c76a171d4 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c @@ -121,3 +121,132 @@ NorFlashBlockIoFlushBlocks ( // Nothing to do so just return without error return EFI_SUCCESS; } + +/* + Although DiskIoDxe will automatically install the DiskIO protocol when= ever + we install the BlockIO protocol, its implementation is sub-optimal as = it reads + and writes entire blocks using the BlockIO protocol. In fact we can ac= cess + NOR flash with a finer granularity than that, so we can improve perfor= mance + by directly producing the DiskIO protocol. +*/ + +/** + Read BufferSize bytes from Offset into Buffer. + + @param This Protocol instance pointer. + @param MediaId Id of the media, changes every time the = media is replaced. + @param Offset The starting byte offset to read from + @param BufferSize Size of Buffer + @param Buffer Buffer containing read data + + @retval EFI_SUCCESS The data was read correctly from the dev= ice. + @retval EFI_DEVICE_ERROR The device reported an error while perfo= rming the read. + @retval EFI_NO_MEDIA There is no media in the device. + @retval EFI_MEDIA_CHANGED The MediaId does not match the current d= evice. + @retval EFI_INVALID_PARAMETER The read request contains device address= es that are not + valid for the device. + +**/ +EFI_STATUS +EFIAPI +NorFlashDiskIoReadDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 DiskOffset, + IN UINTN BufferSize, + OUT VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + UINT32 BlockSize; + UINT32 BlockOffset; + EFI_LBA Lba; + + Instance =3D INSTANCE_FROM_DISKIO_THIS (This); + + if (MediaId !=3D Instance->Media.MediaId) { + return EFI_MEDIA_CHANGED; + } + + BlockSize =3D Instance->Media.BlockSize; + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Blo= ckOffset); + + return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer); +} + +/** + Writes a specified number of bytes to a device. + + @param This Indicates a pointer to the calling context. + @param MediaId ID of the medium to be written. + @param Offset The starting byte offset on the logical block I/O d= evice to write. + @param BufferSize The size in bytes of Buffer. The number of bytes to= write to the device. + @param Buffer A pointer to the buffer containing the data to be w= ritten. + + @retval EFI_SUCCESS The data was written correctly to the de= vice. + @retval EFI_WRITE_PROTECTED The device can not be written to. + @retval EFI_DEVICE_ERROR The device reported an error while perfo= rming the write. + @retval EFI_NO_MEDIA There is no media in the device. + @retval EFI_MEDIA_CHANGED The MediaId does not match the current d= evice. + @retval EFI_INVALID_PARAMETER The write request contains device addres= ses that are not + valid for the device. + +**/ +EFI_STATUS +EFIAPI +NorFlashDiskIoWriteDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 DiskOffset, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + UINT32 BlockSize; + UINT32 BlockOffset; + EFI_LBA Lba; + UINTN RemainingBytes; + UINTN WriteSize; + EFI_STATUS Status; + + Instance =3D INSTANCE_FROM_DISKIO_THIS (This); + + if (MediaId !=3D Instance->Media.MediaId) { + return EFI_MEDIA_CHANGED; + } + + BlockSize =3D Instance->Media.BlockSize; + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Blo= ckOffset); + + RemainingBytes =3D BufferSize; + + // Write either all the remaining bytes, or the number of bytes that b= ring + // us up to a block boundary, whichever is less. + // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the nex= t + // block boundary (even if it is already on one). + WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1= ) - DiskOffset); + + do { + if (WriteSize =3D=3D BlockSize) { + // Write a full block + Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSiz= e / sizeof (UINT32)); + } else { + // Write a partial block + Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &= WriteSize, Buffer); + } + + if (EFI_ERROR (Status)) { + return Status; + } + + // Now continue writing either all the remaining bytes or single blo= cks. + RemainingBytes -=3D WriteSize; + Buffer =3D (UINT8 *)Buffer + WriteSize; + Lba++; + BlockOffset =3D 0; + WriteSize =3D MIN (RemainingBytes, BlockSize); + } while (RemainingBytes); + + return Status; +} --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119316): https://edk2.groups.io/g/devel/message/119316 Mute This Topic: https://groups.io/mt/106365451/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-