From patchwork Fri Jan 4 14:43:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 154775 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp690608ljp; Fri, 4 Jan 2019 06:43:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN4k6f6pGtDbJAfOH+z1dyxvK7LMvRaoRheYQLRXba06VwmYGsLeHpGOZhRR/nR12kAEbZji X-Received: by 2002:a63:a16:: with SMTP id 22mr1898811pgk.318.1546613027031; Fri, 04 Jan 2019 06:43:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546613027; cv=none; d=google.com; s=arc-20160816; b=JU3oltZQ86cFLLbAEhtGLwbwXvfO9xosVzFG6A/y/dk7ivZZQkn1tAjjI5v7yfklta uU1UH+1ODus4pi7Cf5SbFHfgq677gCdixCXMGSfji+lpxkAy1h3z59e6ZLrqzaa2IKK8 aSWIaH30l6+PtOmuzTIxm3dw4VOFko65c2xkwI+6yLDNp5C2TbIe7k91d5OBoCF715iB vUc6hOyZ4l//HsP3fe3LDOKETw2BMXOzfuqmUy69yY2G1jj4f2BHyJIb3Sc/alB8kF/y qiSt70WnRxLYprzKCnXiemrg1VSVf35vik7CYchfCGiMR0CP6ij0vfOvhT6vtMt1KTyy D2+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=O1tFBQejlGug+L1Li2BQE3l6Ymda/5tRCqnNEAFca1o=; b=vFeJePJdgaJSH6tZ2GB/LGWDAp0nlSaJP7geEzRiacMIo0f23yqbqib32UWaYMNbBA mgkzAHEOlgu6xH+CtO9RvcVjf4JdFJLH7YyxUr5U4EArzPurmOTFmhSSc41n2EcTeY5i iOvUNxLEFhtydu1fPe5NnPn7g18ze6o7eWwFVjdI/JTOaesCRx7kuzCiCXCC6/AB3Z1U cgksSkicn9S5g0aCxIjwygRU23QQTPEYYhCthAOyswgeN9LiYm0KEcvlnDs91nW1qMRf Q/6MZIU2CJx/3cqhmKqgSlDNvwdtSXDf0EEfNSY0JcVrgyipMyR9uDF1g/WxLuXwv4V6 m2mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Mlq1VQf3; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 11si55021569pgy.408.2019.01.04.06.43.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 06:43:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Mlq1VQf3; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9EF51211AE8DA; Fri, 4 Jan 2019 06:43:46 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::544; helo=mail-ed1-x544.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 62FAF211AE8D5 for ; Fri, 4 Jan 2019 06:43:44 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id p6so32060093eds.0 for ; Fri, 04 Jan 2019 06:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CWC3daYCrVWTYRSYZjqS9OgQNzT+MURl0YKhbXboxEM=; b=Mlq1VQf3kaU77ddhY8qSKerjvEwx7FUz1ukqGMeu/VTctwy2Xd8mgW17sn54HXKIV8 cz0oYBz880F6aRWR4z80Ecr9JbUGMRpvwQdIfdpHQBKDf/x0VYxjLofpiuq0+hlgAp/5 m0AVp4PUBwrPKV9wigxB3fYrqd1YcijYXGPMc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CWC3daYCrVWTYRSYZjqS9OgQNzT+MURl0YKhbXboxEM=; b=V7HBRlF3F4kFL2dBw8GV/B+M3WhxccjgVENAvLBVaLxE4CMr9f+9JqBkkS1AXWrQI9 f8Q81Zc4gvzsVC5tKDYn7G1cLMlyWPlfBuWzL/WB2iUPWJeeYBYmOqfgR3cE0/qy5JL8 9z6WMyi5ZVO9vN1rm3Xra66c5ZvKtBbnwA646la2jWMnYpTYCtFrJzySPxMmP/51BWi0 EZAtvOrHJxfLWs+Fuk83ZewTp/n3ycrdic4nU85zHr6BXuPjjghqMA5NM9N/xmxlLSOW i590u/TjbvjJAs6IW5nXYKah6A6frcvpnIjT4JGRqYgypqBvvpS7Z9R3f33Lrz3TYz6q qnrg== X-Gm-Message-State: AA+aEWYd2DUVkdpV5EgMayYdCA9VLfdEue+bg1z/dVQU8Se53FAec5sm 8U4NatBKR1Ivtig8pEO0B8jUT8MhmY/7GQ== X-Received: by 2002:a17:906:72c5:: with SMTP id m5-v6mr39260476ejl.135.1546613022045; Fri, 04 Jan 2019 06:43:42 -0800 (PST) Received: from dogfood.home ([2a01:cb1d:112:6f00:183a:9013:d5a3:37a8]) by smtp.gmail.com with ESMTPSA id q16sm21608226eds.60.2019.01.04.06.43.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 06:43:41 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 4 Jan 2019 15:43:30 +0100 Message-Id: <20190104144336.8941-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190104144336.8941-1-ard.biesheuvel@linaro.org> References: <20190104144336.8941-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms 1/7] Silicon/SynQuacer/Fip006Dxe: drop block I/O and disk I/O routines X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The FIP006 NOR flash driver contains implementations of the block I/O and disk I/O protocols, but never exposes them to other drivers (i.e., it never installs the protocol interfaces). So let's drop this code altogether: the NOR flash is for code and variables, not for arbitrary files. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/Fip006Dxe.inf | 3 - Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashBlockIoDxe.c | 138 ------------ Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.c | 229 ++------------------ Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.h | 51 +---- Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashFvbDxe.c | 40 ++-- 5 files changed, 37 insertions(+), 424 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/Fip006Dxe.inf b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/Fip006Dxe.inf index bddb052c2dcc..b939aa689eef 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/Fip006Dxe.inf +++ b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/Fip006Dxe.inf @@ -24,7 +24,6 @@ [Defines] ENTRY_POINT = NorFlashInitialise [Sources] - NorFlashBlockIoDxe.c NorFlashDxe.c NorFlashFvbDxe.c @@ -60,9 +59,7 @@ [Guids] gEfiVariableGuid [Protocols] - gEfiBlockIoProtocolGuid gEfiDevicePathProtocolGuid - gEfiDiskIoProtocolGuid gEfiFirmwareVolumeBlockProtocolGuid [FixedPcd] diff --git a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashBlockIoDxe.c b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashBlockIoDxe.c deleted file mode 100644 index b41f5003217c..000000000000 --- a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashBlockIoDxe.c +++ /dev/null @@ -1,138 +0,0 @@ -/** @file NorFlashBlockIoDxe.c - - Copyright (c) 2011-2013, ARM Ltd. All rights reserved.
- Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
- Copyright (c) 2017, Linaro, Ltd. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include - -#include "NorFlashDxe.h" - -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset -// -EFI_STATUS -EFIAPI -NorFlashBlockIoReset ( - IN EFI_BLOCK_IO_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ) -{ - NOR_FLASH_INSTANCE *Instance; - - Instance = INSTANCE_FROM_BLKIO_THIS(This); - - DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", - This->Media->MediaId)); - - return NorFlashReset (Instance); -} - -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks -// -EFI_STATUS -EFIAPI -NorFlashBlockIoReadBlocks ( - IN EFI_BLOCK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN EFI_LBA Lba, - IN UINTN BufferSizeInBytes, - OUT VOID *Buffer - ) -{ - NOR_FLASH_INSTANCE *Instance; - EFI_STATUS Status; - EFI_BLOCK_IO_MEDIA *Media; - - if (This == NULL) { - return EFI_INVALID_PARAMETER; - } - - Instance = INSTANCE_FROM_BLKIO_THIS(This); - Media = This->Media; - - DEBUG ((DEBUG_BLKIO, - "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes " - "(%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer)); - - if (!Media) { - Status = EFI_INVALID_PARAMETER; - } else if (!Media->MediaPresent) { - Status = EFI_NO_MEDIA; - } else if (Media->MediaId != MediaId) { - Status = EFI_MEDIA_CHANGED; - } else if ((Media->IoAlign > 2) && - (((UINTN)Buffer & (Media->IoAlign - 1)) != 0)) { - Status = EFI_INVALID_PARAMETER; - } else { - Status = NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer); - } - - return Status; -} - -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks -// -EFI_STATUS -EFIAPI -NorFlashBlockIoWriteBlocks ( - IN EFI_BLOCK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN EFI_LBA Lba, - IN UINTN BufferSizeInBytes, - IN VOID *Buffer - ) -{ - NOR_FLASH_INSTANCE *Instance; - EFI_STATUS Status; - - Instance = INSTANCE_FROM_BLKIO_THIS(This); - - DEBUG ((DEBUG_BLKIO, - "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes " - "(%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer)); - - if( !This->Media->MediaPresent ) { - Status = EFI_NO_MEDIA; - } else if( This->Media->MediaId != MediaId ) { - Status = EFI_MEDIA_CHANGED; - } else if( This->Media->ReadOnly ) { - Status = EFI_WRITE_PROTECTED; - } else { - Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer); - } - - return Status; -} - -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks -// -EFI_STATUS -EFIAPI -NorFlashBlockIoFlushBlocks ( - IN EFI_BLOCK_IO_PROTOCOL *This - ) -{ - // No Flush required for the NOR Flash driver - // because cache operations are not permitted. - - DEBUG ((DEBUG_BLKIO, - "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n")); - - // Nothing to do so just return without error - return EFI_SUCCESS; -} diff --git a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.c b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.c index 98f3e4d5a012..e52ab52d8cf7 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.c @@ -338,7 +338,7 @@ NorFlashEraseSingleBlock ( // if (EfiAtRuntime()) { BlockAddress -= Instance->RegionBaseAddress; - BlockAddress += Instance->OffsetLba * Instance->Media.BlockSize; + BlockAddress += Instance->OffsetLba * Instance->BlockSize; } NorFlashSetHostCSDC (Instance, TRUE, mFip006NullCmdSeq); @@ -520,10 +520,6 @@ NorFlashWriteBlocks ( return EFI_INVALID_PARAMETER; } - if (Instance->Media.ReadOnly == TRUE) { - return EFI_WRITE_PROTECTED; - } - // We must have some bytes to read DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes)); @@ -533,19 +529,19 @@ NorFlashWriteBlocks ( // The size of the buffer must be a multiple of the block size DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", - Instance->Media.BlockSize)); - if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) { + Instance->BlockSize)); + if ((BufferSizeInBytes % Instance->BlockSize) != 0) { return EFI_BAD_BUFFER_SIZE; } // All blocks must be within the device - NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ; + NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->BlockSize ; DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, - Instance->Media.LastBlock, Lba)); + Instance->LastBlock, Lba)); - if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) { + if ((Lba + NumBlocks) > (Instance->LastBlock + 1)) { DEBUG ((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n")); return EFI_INVALID_PARAMETER; @@ -553,7 +549,7 @@ NorFlashWriteBlocks ( ASSERT (((UINTN)Buffer % sizeof (UINT32)) == 0); - BlockSizeInWords = Instance->Media.BlockSize / 4; + BlockSizeInWords = Instance->BlockSize / 4; // Because the target *Buffer is a pointer to VOID, we must put // all the data into a pointer to a proper data type, so use *ReadBuffer @@ -592,7 +588,7 @@ NorFlashReadBlocks ( DEBUG ((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n", - BufferSizeInBytes, Instance->Media.BlockSize, Instance->Media.LastBlock, + BufferSizeInBytes, Instance->BlockSize, Instance->LastBlock, Lba)); // The buffer must be valid @@ -606,14 +602,14 @@ NorFlashReadBlocks ( } // The size of the buffer must be a multiple of the block size - if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) { + if ((BufferSizeInBytes % Instance->BlockSize) != 0) { return EFI_BAD_BUFFER_SIZE; } // All blocks must be within the device - NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ; + NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->BlockSize ; - if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) { + if ((Lba + NumBlocks) > (Instance->LastBlock + 1)) { DEBUG ((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n")); return EFI_INVALID_PARAMETER; @@ -621,7 +617,7 @@ NorFlashReadBlocks ( // Get the address to start reading from StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, - Instance->Media.BlockSize); + Instance->BlockSize); // Put the device into Read Array mode NorFlashSetHostCommand (Instance, SPINOR_OP_READ_4B); @@ -654,7 +650,7 @@ NorFlashRead ( return EFI_SUCCESS; } - if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > + if (((Lba * Instance->BlockSize) + Offset + BufferSizeInBytes) > Instance->Size) { DEBUG ((DEBUG_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n")); @@ -663,7 +659,7 @@ NorFlashRead ( // Get the address to start reading from StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, - Instance->Media.BlockSize); + Instance->BlockSize); // Put the device into Read Array mode NorFlashSetHostCommand (Instance, SPINOR_OP_READ_4B); @@ -677,7 +673,7 @@ NorFlashRead ( /* Write a full or portion of a block. It must not span block boundaries; - that is, Offset + *NumBytes <= Instance->Media.BlockSize. + that is, Offset + *NumBytes <= Instance->BlockSize. */ EFI_STATUS NorFlashWriteSingleBlock ( @@ -711,16 +707,8 @@ NorFlashWriteSingleBlock ( "NorFlashWriteSingleBlock(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes, Buffer)); - // Detect WriteDisabled state - if (Instance->Media.ReadOnly == TRUE) { - DEBUG ((DEBUG_ERROR, - "NorFlashWriteSingleBlock: ERROR - Can not write: Device is in WriteDisabled state.\n")); - // It is in WriteDisabled state, return an error right away - return EFI_ACCESS_DENIED; - } - // Cache the block size to avoid de-referencing pointers all the time - BlockSize = Instance->Media.BlockSize; + BlockSize = Instance->BlockSize; // The write must not span block boundaries. // We need to check each variable individually because adding two large @@ -896,143 +884,6 @@ NorFlashWriteSingleBlock ( return EFI_SUCCESS; } -/* - Although DiskIoDxe will automatically install the DiskIO protocol whenever - 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 access - NOR flash with a finer granularity than that, so we can improve performance - 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 device. - @retval EFI_DEVICE_ERROR The device reported an error while performing - the read. - @retval EFI_NO_MEDIA There is no media in the device. - @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device. - @retval EFI_INVALID_PARAMETER The read request contains device addresses that - are not valid for the device. - -**/ -STATIC -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 = INSTANCE_FROM_DISKIO_THIS(This); - - if (MediaId != Instance->Media.MediaId) { - return EFI_MEDIA_CHANGED; - } - - BlockSize = Instance->Media.BlockSize; - Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset); - - 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 device 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 written. - - @retval EFI_SUCCESS The data was written correctly to the device. - @retval EFI_WRITE_PROTECTED The device can not be written to. - @retval EFI_DEVICE_ERROR The device reported an error while performing - the write. - @retval EFI_NO_MEDIA There is no media in the device. - @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device. - @retval EFI_INVALID_PARAMETER The write request contains device addresses that - are not valid for the device. - -**/ -STATIC -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 = INSTANCE_FROM_DISKIO_THIS(This); - - if (MediaId != Instance->Media.MediaId) { - return EFI_MEDIA_CHANGED; - } - - BlockSize = Instance->Media.BlockSize; - Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset); - - RemainingBytes = BufferSize; - - // Write either all the remaining bytes, or the number of bytes that bring - // us up to a block boundary, whichever is less. - // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next - // block boundary (even if it is already on one). - WriteSize = MIN (RemainingBytes, - ((DiskOffset | (BlockSize - 1)) + 1) - DiskOffset); - - do { - if (WriteSize == BlockSize) { - // Write a full block - Status = NorFlashWriteFullBlock (Instance, Lba, Buffer, - BlockSize / sizeof (UINT32)); - } else { - // Write a partial block - Status = NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &WriteSize, - Buffer); - } - if (EFI_ERROR (Status)) { - return Status; - } - // Now continue writing either all the remaining bytes or single blocks. - RemainingBytes -= WriteSize; - Buffer = (UINT8 *) Buffer + WriteSize; - Lba++; - BlockOffset = 0; - WriteSize = MIN (RemainingBytes, BlockSize); - } while (RemainingBytes); - - return Status; -} - STATIC CONST NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = { NOR_FLASH_SIGNATURE, // Signature NULL, // Handle ... NEED TO BE FILLED @@ -1044,37 +895,11 @@ STATIC CONST NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = { 0, // DeviceBaseAddress ... NEED TO BE FILLED 0, // RegionBaseAddress ... NEED TO BE FILLED 0, // Size ... NEED TO BE FILLED + 0, // BlockSize + 0, // LastBlock 0, // StartLba 0, // OffsetLba - { - EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision - NULL, // Media ... NEED TO BE FILLED - NorFlashBlockIoReset, // Reset; - NorFlashBlockIoReadBlocks, // ReadBlocks - NorFlashBlockIoWriteBlocks, // WriteBlocks - NorFlashBlockIoFlushBlocks // FlushBlocks - }, // BlockIoProtocol - - { - 0, // MediaId ... NEED TO BE FILLED - FALSE, // RemovableMedia - TRUE, // MediaPresent - FALSE, // LogicalPartition - FALSE, // ReadOnly - FALSE, // WriteCaching; - 0, // BlockSize ... NEED TO BE FILLED - 4, // IoAlign - 0, // LastBlock ... NEED TO BE FILLED - 0, // LowestAlignedLba - 1, // LogicalBlocksPerPhysicalBlock - }, //Media; - - { - EFI_DISK_IO_PROTOCOL_REVISION, // Revision - NorFlashDiskIoReadDisk, // ReadDisk - NorFlashDiskIoWriteDisk // WriteDisk - }, { FvbGetAttributes, // GetAttributes FvbSetAttributes, // SetAttributes @@ -1143,12 +968,10 @@ NorFlashCreateInstance ( Instance->HostRegisterBaseAddress = HostRegisterBase; Instance->DeviceBaseAddress = NorFlashDeviceBase; Instance->RegionBaseAddress = NorFlashRegionBase; - Instance->Size = NorFlashSize; + Instance->Size = NorFlashSize; + Instance->BlockSize = BlockSize; + Instance->LastBlock = (NorFlashSize / BlockSize) - 1; - Instance->BlockIoProtocol.Media = &Instance->Media; - Instance->Media.MediaId = Index; - Instance->Media.BlockSize = BlockSize; - Instance->Media.LastBlock = (NorFlashSize / BlockSize) - 1; Instance->OffsetLba = (NorFlashRegionBase - NorFlashDeviceBase) / BlockSize; CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid); @@ -1263,16 +1086,6 @@ NorFlashVirtualNotifyEvent ( EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->RegionBaseAddress); - // Convert BlockIo protocol - EfiConvertPointer (0x0, - (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks); - EfiConvertPointer (0x0, - (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks); - EfiConvertPointer (0x0, - (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.Reset); - EfiConvertPointer (0x0, - (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks); - // Convert Fvb EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks); diff --git a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.h b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.h index ef1257a64904..20e74b0320ce 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.h +++ b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashDxe.h @@ -102,13 +102,11 @@ struct _NOR_FLASH_INSTANCE { UINTN DeviceBaseAddress; UINTN RegionBaseAddress; UINTN Size; + UINTN BlockSize; + UINTN LastBlock; EFI_LBA StartLba; EFI_LBA OffsetLba; - EFI_BLOCK_IO_PROTOCOL BlockIoProtocol; - EFI_BLOCK_IO_MEDIA Media; - EFI_DISK_IO_PROTOCOL DiskIoProtocol; - EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; VOID* ShadowBuffer; @@ -137,51 +135,6 @@ NorFlashWriteBuffer ( IN UINT32 *Buffer ); -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset -// -EFI_STATUS -EFIAPI -NorFlashBlockIoReset ( - IN EFI_BLOCK_IO_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ); - -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks -// -EFI_STATUS -EFIAPI -NorFlashBlockIoReadBlocks ( - IN EFI_BLOCK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN EFI_LBA Lba, - IN UINTN BufferSizeInBytes, - OUT VOID *Buffer -); - -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks -// -EFI_STATUS -EFIAPI -NorFlashBlockIoWriteBlocks ( - IN EFI_BLOCK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN EFI_LBA Lba, - IN UINTN BufferSizeInBytes, - IN VOID *Buffer -); - -// -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks -// -EFI_STATUS -EFIAPI -NorFlashBlockIoFlushBlocks ( - IN EFI_BLOCK_IO_PROTOCOL *This -); - // // NorFlashFvbDxe.c // diff --git a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashFvbDxe.c b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashFvbDxe.c index ca3b1b5c34f8..776ec8a5437c 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashFvbDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/Fip006Dxe/NorFlashFvbDxe.c @@ -91,8 +91,8 @@ InitializeFvAndVariableStoreHeaders ( FirmwareVolumeHeader->HeaderLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY); FirmwareVolumeHeader->Revision = EFI_FVH_REVISION; - FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1; - FirmwareVolumeHeader->BlockMap[0].Length = Instance->Media.BlockSize; + FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->LastBlock + 1; + FirmwareVolumeHeader->BlockMap[0].Length = Instance->BlockSize; FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0; FirmwareVolumeHeader->BlockMap[1].Length = 0; FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ( @@ -223,14 +223,10 @@ FvbGetAttributes( Instance = INSTANCE_FROM_FVB_THIS(This); FlashFvbAttributes = EFI_FVB2_READ_ENABLED_CAP | EFI_FVB2_READ_STATUS | + EFI_FVB2_WRITE_ENABLED_CAP | EFI_FVB2_WRITE_STATUS | EFI_FVB2_STICKY_WRITE | EFI_FVB2_MEMORY_MAPPED | EFI_FVB2_ERASE_POLARITY; - // Check if it is write protected - if (!Instance->Media.ReadOnly) { - FlashFvbAttributes |= EFI_FVB2_WRITE_STATUS | EFI_FVB2_WRITE_ENABLED_CAP; - } - *Attributes = FlashFvbAttributes; DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes)); @@ -349,17 +345,17 @@ FvbGetBlockSize ( DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, - Instance->Media.BlockSize, Instance->Media.LastBlock)); + Instance->BlockSize, Instance->LastBlock)); - if (Lba > Instance->Media.LastBlock) { + if (Lba > Instance->LastBlock) { DEBUG ((DEBUG_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is beyond the last Lba (%ld).\n", - Lba, Instance->Media.LastBlock)); + Lba, Instance->LastBlock)); Status = EFI_INVALID_PARAMETER; } else { // This is easy because in this platform each NorFlash device has equal sized blocks. - *BlockSize = (UINTN) Instance->Media.BlockSize; - *NumberOfBlocks = (UINTN) (Instance->Media.LastBlock - Lba + 1); + *BlockSize = (UINTN) Instance->BlockSize; + *NumberOfBlocks = (UINTN) (Instance->LastBlock - Lba + 1); DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, @@ -442,7 +438,7 @@ FvbRead ( TempStatus = EFI_SUCCESS; // Cache the block size to avoid de-referencing pointers all the time - BlockSize = Instance->Media.BlockSize; + BlockSize = Instance->BlockSize; DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", @@ -626,14 +622,6 @@ FvbEraseBlocks ( Status = EFI_SUCCESS; - // Detect WriteDisabled state - if (Instance->Media.ReadOnly) { - // Firmware volume is in WriteDisabled state - DEBUG ((DEBUG_ERROR, - "FvbEraseBlocks: ERROR - Device is in WriteDisabled state.\n")); - return EFI_ACCESS_DENIED; - } - // Before erasing, check the entire list of parameters to ensure // all specified blocks are valid @@ -654,10 +642,10 @@ FvbEraseBlocks ( // All blocks must be within range DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Check if: ( StartingLba=%ld + NumOfLba=%d - 1 ) > LastBlock=%ld.\n", - Instance->StartLba + StartingLba, NumOfLba, Instance->Media.LastBlock)); + Instance->StartLba + StartingLba, NumOfLba, Instance->LastBlock)); if (NumOfLba == 0 || (Instance->StartLba + StartingLba + NumOfLba - 1) > - Instance->Media.LastBlock) { + Instance->LastBlock) { VA_END (Args); DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past the last Lba.\n")); @@ -690,7 +678,7 @@ FvbEraseBlocks ( // Get the physical address of Lba to erase BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Instance->StartLba + StartingLba, - Instance->Media.BlockSize); + Instance->BlockSize); // Erase it DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=%ld @ 0x%08x.\n", @@ -747,7 +735,7 @@ NorFlashFvbInitialize ( DEBUG ((DEBUG_BLKIO,"NorFlashFvbInitialize\n")); - BlockSize = Instance->Media.BlockSize; + BlockSize = Instance->BlockSize; // FirmwareVolumeHeader->FvLength is declared to have the Variable area // AND the FTW working area AND the FTW Spare contiguous. @@ -798,7 +786,7 @@ NorFlashFvbInitialize ( FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / - Instance->Media.BlockSize; + Instance->BlockSize; Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);