From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4010:c07::244; helo=mail-lf0-x244.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x244.google.com (mail-lf0-x244.google.com [IPv6:2a00:1450:4010:c07::244]) (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 8B18421BADAB9 for ; Sun, 3 Jun 2018 22:30:01 -0700 (PDT) Received: by mail-lf0-x244.google.com with SMTP id j13-v6so18704425lfb.13 for ; Sun, 03 Jun 2018 22:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=apT0rkGm9TGHDH8OfyKbvdoCZR+5zYfHniJf5vT0kJQ=; b=U34RE6Uzdvnl3KYLmFx9og5EIDTuiFJtE9EUwqcw4KWMVCAGbgOuRfsZhjRGoOD4UW tTLK0f06BTQB0kw2RpBmwuXJbPmrfMn/gyRSuXLFFAY0witqiziOwHJl96vFQ6t1OVsH qBrNEVK4OAAjmXPc/ZfFnocbGs78M5IPjxqmqOSMVFgjdg9xPZzrg2RkQqj0n1/f0JYq oVLWpH80cbcRY3pYzGUxVHpPOjhxanR9L4efG/f/WrF0oE/+Irs254XxX3TOyD6H7y/a +/Y5tTuNoBWqfAH2Wpqd19zDOVOXPQx+OffsKwelse1/4AOMwhfiywGptKDvqMKKsrtN z49Q== 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=apT0rkGm9TGHDH8OfyKbvdoCZR+5zYfHniJf5vT0kJQ=; b=Pax8lujnCu/E3B1s9G7cOnVjwpvpN+CgxKLWhHWiTxBv8xe3HwTLdSJR2z2f2BGHgq L7rL+Hg0mzC8zQhaCbFE+QgMeJ14DoVC/k+7usxBjlqDDEKY15IPeqZP9QwOwrxHHcCX inbHL+xOeNW+ZETE333yiz1ChC2qCLw2m/VnZwWL89Br5KglDDYBQKX+QVjIw2rp19sg Sijyyv/492Iv3li/VH2KlrqGWhtrYgmxSSC1V5emrXJNl2Iht4njroF7DPB8n5dUv1K3 b3pPG7SkSOUvUvHX6oilaG3LqkpxLOfZvdJ5woh016PRW7cnrn3MpWy40bXiaBd7P8PH ZN9Q== X-Gm-Message-State: ALKqPwcfyLjTUR6/Jw0XOyLc0av8AqWL/U5pDWjUgyPL5wgJ8eG6pZqa vVcvSzA6wsfRgxaTcWuNHNLPu6BAlG8= X-Google-Smtp-Source: ADUXVKIYb+irM8rG1Pde+W6Cbi31YVGclO/XpHs3bZxslrVDr8hsRQvRTKZAMyDjWZeSkQCHfhTN4w== X-Received: by 2002:a19:1b11:: with SMTP id b17-v6mr11549363lfb.50.1528090199586; Sun, 03 Jun 2018 22:29:59 -0700 (PDT) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id v1-v6sm9677204ljg.58.2018.06.03.22.29.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Jun 2018 22:29:58 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, mw@semihalf.com, jsd@semihalf.com, jinghua@marvell.com, jaz@semihalf.com, davidsn@marvell.com Date: Mon, 4 Jun 2018 07:29:33 +0200 Message-Id: <1528090175-15791-4-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528090175-15791-1-git-send-email-mw@semihalf.com> References: <1528090175-15791-1-git-send-email-mw@semihalf.com> Subject: [platforms PATCH v2 3/5] Marvell/Drivers: MvSpiFlashDxe: Add progress API X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jun 2018 05:30:02 -0000 In order to support new API of the PlatformFlashAccessLib, which passes and optional Progress() function, introduce new callback for updating data in the SPI flash, that can utilize it. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c | 60 ++++++++++++++++++++ Silicon/Marvell/Include/Protocol/SpiFlash.h | 14 +++++ 2 files changed, 74 insertions(+) diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c index a2ce975..d81f6e3 100755 --- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c +++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c @@ -397,6 +397,65 @@ MvSpiFlashUpdate ( } EFI_STATUS +MvSpiFlashUpdateWithProgress ( + IN SPI_DEVICE *Slave, + IN UINT32 Offset, + IN UINTN ByteCount, + IN UINT8 *Buffer, + IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL + IN UINTN StartPercentage, + IN UINTN EndPercentage + ) +{ + EFI_STATUS Status; + UINTN SectorSize; + UINTN SectorNum; + UINTN ToUpdate; + UINTN Index; + UINT8 *TmpBuf; + + SectorSize = Slave->Info->SectorSize; + SectorNum = ByteCount / SectorSize; + ToUpdate = SectorSize; + + TmpBuf = (UINT8 *)AllocateZeroPool (SectorSize); + if (TmpBuf == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + for (Index = 0; Index < SectorNum; Index++) { + if (Progress != NULL) { + Progress (StartPercentage + + ((Index * (EndPercentage - StartPercentage)) / SectorNum)); + } + + // In the last chunk update only an actual number of remaining bytes. + if (Index + 1 == SectorNum) { + ToUpdate = ByteCount % SectorSize; + } + + Status = MvSpiFlashUpdateBlock (Slave, + Offset + Index * SectorSize, + ToUpdate, + Buffer + Index * SectorSize, + TmpBuf, + SectorSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Error while updating\n", __FUNCTION__)); + return Status; + } + } + FreePool (TmpBuf); + + if (Progress != NULL) { + Progress (EndPercentage); + } + + return EFI_SUCCESS; +} + +EFI_STATUS EFIAPI MvSpiFlashReadId ( IN SPI_DEVICE *SpiDev, @@ -500,6 +559,7 @@ MvSpiFlashInitProtocol ( SpiFlashProtocol->Write = MvSpiFlashWrite; SpiFlashProtocol->Erase = MvSpiFlashErase; SpiFlashProtocol->Update = MvSpiFlashUpdate; + SpiFlashProtocol->UpdateWithProgress = MvSpiFlashUpdateWithProgress; return EFI_SUCCESS; } diff --git a/Silicon/Marvell/Include/Protocol/SpiFlash.h b/Silicon/Marvell/Include/Protocol/SpiFlash.h index 4ba29ba..e703330 100644 --- a/Silicon/Marvell/Include/Protocol/SpiFlash.h +++ b/Silicon/Marvell/Include/Protocol/SpiFlash.h @@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef __MV_SPI_FLASH__ #define __MV_SPI_FLASH__ +#include #include extern EFI_GUID gMarvellSpiFlashProtocolGuid; @@ -89,6 +90,18 @@ EFI_STATUS IN UINT8 *Buffer ); +typedef +EFI_STATUS +(EFIAPI *MV_SPI_FLASH_UPDATE_WITH_PROGRESS) ( + IN SPI_DEVICE *Slave, + IN UINT32 Offset, + IN UINTN ByteCount, + IN UINT8 *Buffer, + IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL + IN UINTN StartPercentage, + IN UINTN EndPercentage + ); + struct _MARVELL_SPI_FLASH_PROTOCOL { MV_SPI_FLASH_INIT Init; MV_SPI_FLASH_READ_ID ReadId; @@ -96,6 +109,7 @@ struct _MARVELL_SPI_FLASH_PROTOCOL { MV_SPI_FLASH_WRITE Write; MV_SPI_FLASH_ERASE Erase; MV_SPI_FLASH_UPDATE Update; + MV_SPI_FLASH_UPDATE_WITH_PROGRESS UpdateWithProgress; }; #endif // __MV_SPI_FLASH__ -- 2.7.4