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 CDDB77803DB for ; Thu, 23 May 2024 10:55:54 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=oDI0N0NqV7MxkwPoNKEXGwDBcpqnmc1EAAOUwRvTSVY=; 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=1716461753; v=1; b=4t2lzssRcBiSnE0Tp5nNOBhl975Y0Iy1iw4A3JfMuPb735Ec2kzo3TPxocIRgMO1eHQ3KzR2 5rzduLscgdJQJQ8AtHn4CefehpA0WlyKwD1Kcwb0FMcT4cf6ey3HG26e5AbmHcXTzWpRHJRPwFn lP/CfELrdcu4HCZJKJJMCh4JbvxYaq4+/WmdokZRjkB/Y52OPpFcir2NVmuqEjQsgwkptfqBF5k tasXHWTscL6c+16dKarKKsvW+aqE4XTm9AiJ31VQubIfeMSzUJ4NocaRaZ8Vh5LRop8mVVCvp7T CrtiIiiZa+i7d0U0c+bLC+hn/Obd/O/UenOyVvSATt37w== X-Received: by 127.0.0.2 with SMTP id bI6HYY7687511xgHMNxYdpKq; Thu, 23 May 2024 03:55:53 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.14080.1716461752365679667 for ; Thu, 23 May 2024 03:55:52 -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 18182DA7; Thu, 23 May 2024 03:56:16 -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 5531A3F766; Thu, 23 May 2024 03:55:50 -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 01/17] Platform/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c Date: Thu, 23 May 2024 16:24:55 +0530 Message-Id: <20240523105511.13189-2-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:55:52 -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: YlpLf9D5X6Q2ZtPBzFRNOzfux7686176AA= 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=4t2lzssR; 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 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/Dri= vers/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;=0D }=0D =0D -/*=0D - Although DiskIoDxe will automatically install the DiskIO protocol whenev= er=0D - we install the BlockIO protocol, its implementation is sub-optimal as it= reads=0D - and writes entire blocks using the BlockIO protocol. In fact we can acce= ss=0D - NOR flash with a finer granularity than that, so we can improve performa= nce=0D - by directly producing the DiskIO protocol.=0D -*/=0D -=0D -/**=0D - Read BufferSize bytes from Offset into Buffer.=0D -=0D - @param This Protocol instance pointer.=0D - @param MediaId Id of the media, changes every time the me= dia is replaced.=0D - @param Offset The starting byte offset to read from=0D - @param BufferSize Size of Buffer=0D - @param Buffer Buffer containing read data=0D -=0D - @retval EFI_SUCCESS The data was read correctly from the devic= e.=0D - @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the read.=0D - @retval EFI_NO_MEDIA There is no media in the device.=0D - @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice.=0D - @retval EFI_INVALID_PARAMETER The read request contains device addresses= that are not=0D - valid for the device.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashDiskIoReadDisk (=0D - IN EFI_DISK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN UINT64 DiskOffset,=0D - IN UINTN BufferSize,=0D - OUT VOID *Buffer=0D - )=0D -{=0D - NOR_FLASH_INSTANCE *Instance;=0D - UINT32 BlockSize;=0D - UINT32 BlockOffset;=0D - EFI_LBA Lba;=0D -=0D - Instance =3D INSTANCE_FROM_DISKIO_THIS (This);=0D -=0D - if (MediaId !=3D Instance->Media.MediaId) {=0D - return EFI_MEDIA_CHANGED;=0D - }=0D -=0D - BlockSize =3D Instance->Media.BlockSize;=0D - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset);=0D -=0D - return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer);=0D -}=0D -=0D -/**=0D - Writes a specified number of bytes to a device.=0D -=0D - @param This Indicates a pointer to the calling context.=0D - @param MediaId ID of the medium to be written.=0D - @param Offset The starting byte offset on the logical block I/O dev= ice to write.=0D - @param BufferSize The size in bytes of Buffer. The number of bytes to w= rite to the device.=0D - @param Buffer A pointer to the buffer containing the data to be wri= tten.=0D -=0D - @retval EFI_SUCCESS The data was written correctly to the devi= ce.=0D - @retval EFI_WRITE_PROTECTED The device can not be written to.=0D - @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the write.=0D - @retval EFI_NO_MEDIA There is no media in the device.=0D - @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice.=0D - @retval EFI_INVALID_PARAMETER The write request contains device addresse= s that are not=0D - valid for the device.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashDiskIoWriteDisk (=0D - IN EFI_DISK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN UINT64 DiskOffset,=0D - IN UINTN BufferSize,=0D - IN VOID *Buffer=0D - )=0D -{=0D - NOR_FLASH_INSTANCE *Instance;=0D - UINT32 BlockSize;=0D - UINT32 BlockOffset;=0D - EFI_LBA Lba;=0D - UINTN RemainingBytes;=0D - UINTN WriteSize;=0D - EFI_STATUS Status;=0D -=0D - Instance =3D INSTANCE_FROM_DISKIO_THIS (This);=0D -=0D - if (MediaId !=3D Instance->Media.MediaId) {=0D - return EFI_MEDIA_CHANGED;=0D - }=0D -=0D - BlockSize =3D Instance->Media.BlockSize;=0D - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset);=0D -=0D - RemainingBytes =3D BufferSize;=0D -=0D - // Write either all the remaining bytes, or the number of bytes that bri= ng=0D - // us up to a block boundary, whichever is less.=0D - // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next= =0D - // block boundary (even if it is already on one).=0D - WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) = - DiskOffset);=0D -=0D - do {=0D - if (WriteSize =3D=3D BlockSize) {=0D - // Write a full block=0D - Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize = / sizeof (UINT32));=0D - } else {=0D - // Write a partial block=0D - Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &Wr= iteSize, Buffer);=0D - }=0D -=0D - if (EFI_ERROR (Status)) {=0D - return Status;=0D - }=0D -=0D - // Now continue writing either all the remaining bytes or single block= s.=0D - RemainingBytes -=3D WriteSize;=0D - Buffer =3D (UINT8 *)Buffer + WriteSize;=0D - Lba++;=0D - BlockOffset =3D 0;=0D - WriteSize =3D MIN (RemainingBytes, BlockSize);=0D - } while (RemainingBytes);=0D -=0D - return Status;=0D -}=0D -=0D EFI_STATUS=0D NorFlashReset (=0D IN NOR_FLASH_INSTANCE *Instance=0D diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/Platfo= rm/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=0D return EFI_SUCCESS;=0D }=0D +=0D +/*=0D + Although DiskIoDxe will automatically install the DiskIO protocol whenev= er=0D + we install the BlockIO protocol, its implementation is sub-optimal as it= reads=0D + and writes entire blocks using the BlockIO protocol. In fact we can acce= ss=0D + NOR flash with a finer granularity than that, so we can improve performa= nce=0D + by directly producing the DiskIO protocol.=0D +*/=0D +=0D +/**=0D + Read BufferSize bytes from Offset into Buffer.=0D +=0D + @param This Protocol instance pointer.=0D + @param MediaId Id of the media, changes every time the me= dia is replaced.=0D + @param Offset The starting byte offset to read from=0D + @param BufferSize Size of Buffer=0D + @param Buffer Buffer containing read data=0D +=0D + @retval EFI_SUCCESS The data was read correctly from the devic= e.=0D + @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the read.=0D + @retval EFI_NO_MEDIA There is no media in the device.=0D + @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice.=0D + @retval EFI_INVALID_PARAMETER The read request contains device addresses= that are not=0D + valid for the device.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +NorFlashDiskIoReadDisk (=0D + IN EFI_DISK_IO_PROTOCOL *This,=0D + IN UINT32 MediaId,=0D + IN UINT64 DiskOffset,=0D + IN UINTN BufferSize,=0D + OUT VOID *Buffer=0D + )=0D +{=0D + NOR_FLASH_INSTANCE *Instance;=0D + UINT32 BlockSize;=0D + UINT32 BlockOffset;=0D + EFI_LBA Lba;=0D +=0D + Instance =3D INSTANCE_FROM_DISKIO_THIS (This);=0D +=0D + if (MediaId !=3D Instance->Media.MediaId) {=0D + return EFI_MEDIA_CHANGED;=0D + }=0D +=0D + BlockSize =3D Instance->Media.BlockSize;=0D + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset);=0D +=0D + return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer);=0D +}=0D +=0D +/**=0D + Writes a specified number of bytes to a device.=0D +=0D + @param This Indicates a pointer to the calling context.=0D + @param MediaId ID of the medium to be written.=0D + @param Offset The starting byte offset on the logical block I/O dev= ice to write.=0D + @param BufferSize The size in bytes of Buffer. The number of bytes to w= rite to the device.=0D + @param Buffer A pointer to the buffer containing the data to be wri= tten.=0D +=0D + @retval EFI_SUCCESS The data was written correctly to the devi= ce.=0D + @retval EFI_WRITE_PROTECTED The device can not be written to.=0D + @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the write.=0D + @retval EFI_NO_MEDIA There is no media in the device.=0D + @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice.=0D + @retval EFI_INVALID_PARAMETER The write request contains device addresse= s that are not=0D + valid for the device.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +NorFlashDiskIoWriteDisk (=0D + IN EFI_DISK_IO_PROTOCOL *This,=0D + IN UINT32 MediaId,=0D + IN UINT64 DiskOffset,=0D + IN UINTN BufferSize,=0D + IN VOID *Buffer=0D + )=0D +{=0D + NOR_FLASH_INSTANCE *Instance;=0D + UINT32 BlockSize;=0D + UINT32 BlockOffset;=0D + EFI_LBA Lba;=0D + UINTN RemainingBytes;=0D + UINTN WriteSize;=0D + EFI_STATUS Status;=0D +=0D + Instance =3D INSTANCE_FROM_DISKIO_THIS (This);=0D +=0D + if (MediaId !=3D Instance->Media.MediaId) {=0D + return EFI_MEDIA_CHANGED;=0D + }=0D +=0D + BlockSize =3D Instance->Media.BlockSize;=0D + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset);=0D +=0D + RemainingBytes =3D BufferSize;=0D +=0D + // Write either all the remaining bytes, or the number of bytes that bri= ng=0D + // us up to a block boundary, whichever is less.=0D + // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next= =0D + // block boundary (even if it is already on one).=0D + WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) = - DiskOffset);=0D +=0D + do {=0D + if (WriteSize =3D=3D BlockSize) {=0D + // Write a full block=0D + Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize = / sizeof (UINT32));=0D + } else {=0D + // Write a partial block=0D + Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &Wr= iteSize, Buffer);=0D + }=0D +=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + // Now continue writing either all the remaining bytes or single block= s.=0D + RemainingBytes -=3D WriteSize;=0D + Buffer =3D (UINT8 *)Buffer + WriteSize;=0D + Lba++;=0D + BlockOffset =3D 0;=0D + WriteSize =3D MIN (RemainingBytes, BlockSize);=0D + } while (RemainingBytes);=0D +=0D + return Status;=0D +}=0D --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119143): https://edk2.groups.io/g/devel/message/119143 Mute This Topic: https://groups.io/mt/106260138/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-