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 A28FDAC1199 for ; Tue, 23 Apr 2024 14:55:55 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=yTeW1/hVJddaRAQG4eCIFjf3IGbhiWicodyMbkseeQc=; 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=1713884154; v=1; b=mcqd1Lp1x0AVHfzUQBJ2SRGQHgcyYE4/OAef1kHDRP7+qFTTPr0LG2T80XqxPBo0XSUkrWJk Q6neR70mki4LQWV8SRRu6Z6QG5+oq2DHlfmIVmzHg9Rilz4wZIdAiHVaTZrfAfJRfSRnbXpCDXj 1Gg5i/O2kF4pKm/J3/ryQD8hWw2fUujGipQxIOEEEW9qCHBdznHrNtqRa5qwDYhNYkzsMi6Rhhg K/kZEkHbTl/xTx4JYw1z5+7H7znfjqsciQPJ7neT25WSp/LDlVhaYrsdiBubLjFwKPx3iik3MHj MqSOW8bMYjm//fzOUnzw45iStpTQLWOdrt4VwbzWjhuRQ== X-Received: by 127.0.0.2 with SMTP id xzBrYY7687511xPgHC4KfeQN; Tue, 23 Apr 2024 07:55:54 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.11900.1713851812645916059 for ; Mon, 22 Apr 2024 22:56: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 6B9021063; Mon, 22 Apr 2024 22:57:20 -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 B1D613F7BD; Mon, 22 Apr 2024 22:56: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] [PATCH RESEND edk2-platforms][PATCH V2 01/14] Platform/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c Date: Tue, 23 Apr 2024 11:26:25 +0530 Message-Id: <20240423055638.1271531-2-Sahil.Kaushal@arm.com> In-Reply-To: <20240423055638.1271531-1-Sahil.Kaushal@arm.com> References: <20240423055638.1271531-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: Tue, 23 Apr 2024 07:55:50 -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: 605G7OJuCOcLzJLAiEu6UJIAx7686176AA= 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=mcqd1Lp1; 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 (#118151): https://edk2.groups.io/g/devel/message/118151 Mute This Topic: https://groups.io/mt/105690936/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-