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::243; helo=mail-lf0-x243.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x243.google.com (mail-lf0-x243.google.com [IPv6:2a00:1450:4010:c07::243]) (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 B7E932034EE2E for ; Sun, 5 Nov 2017 02:52:01 -0800 (PST) Received: by mail-lf0-x243.google.com with SMTP id b190so7539217lfg.9 for ; Sun, 05 Nov 2017 02:55:58 -0800 (PST) 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=Bfvq53C7aJ3wegoqMn4Cp4oI7KkCSdvt9zxLxmKj3Pk=; b=jbZTSmxBtvVUkKi+UPpWAEwiHPr3DRZuSCLQ46alWVhNCgiStiYDXxupkByMbpPehi JlR1VI67m+W3GOogOHNJGNzELh7pVKxkkz+7nvn954OFOHBgqQXlPjSYLBzxVJiBCokg qJT/I5qEyuTJ0nQu1DCh3FMm3UUADRskcvO1Aox5yaSkCXQ5IcfmlmMCnC38T+iZNid9 h7E9SsM9OFwOLwj79y0uoREn2AzsEuA3i178X2GCkpd7wJzRwLzhUNmHMYPUx40HT0JV E6vKTxxWGu56JVP8FlAZEUtAWEVAezN/IzAab1QGPV1o9d6CH+QnwQC1cgQK70Wv3aL9 kJdg== 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=Bfvq53C7aJ3wegoqMn4Cp4oI7KkCSdvt9zxLxmKj3Pk=; b=mm4+v6FEGdbVcgEPAQddpI8NrvNB0sPnRt9f98giHWCly14wF5SMcV6B0No9rV5rQG bfr1MXHTxmYeqUDy4kmwG8dyyXYpNmPaJqsjv9xnvEnyhwEuoRm0YMg8W3hpOmEYtSUK rfh0/9jVTrI9PWcm4ZyLSjJR/7E34PRSkH4NGkv3wvKoag3DHO3lO3RaFFLwAp2L1k35 Q73pAgHcrgs7l4rVSMWjZFreSHsSp+GDd0Ifv+WrJv6j+FxJR70Khnczf4orEaAmAn/2 nd1xOU2/K9MMRuI1sJS8iEf5J9qTvtpSKBwIEwJjWNnhuN+lEUQ9ELEKUBRyAWKFPfEU 0BAg== X-Gm-Message-State: AJaThX56hatN8CcsP4CHtwWiJdM+3YWDgmkgGNvgT47Xu2mHHJ4FGjD2 x4DFaidqNdXzYKyxs1a45u3pJq1qrac= X-Google-Smtp-Source: ABhQp+RkmxsplfjWqKPkOMlJAkCqPaGMpZ0WaPQQUOot58l53JQlBnWXbyt5whht5vxgdKiJVp94Zw== X-Received: by 10.25.89.144 with SMTP id n138mr4232845lfb.161.1509879356981; Sun, 05 Nov 2017 02:55:56 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id a198sm1853649lfb.79.2017.11.05.02.55.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 05 Nov 2017 02:55:56 -0800 (PST) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, neta@marvell.com, kostap@marvell.com, jinghua@marvell.com, mw@semihalf.com, jsd@semihalf.com Date: Sun, 5 Nov 2017 11:55:36 +0100 Message-Id: <1509879339-10516-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509879339-10516-1-git-send-email-mw@semihalf.com> References: <1509879339-10516-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH 1/4] Marvell/Drivers: MvSpiFlash: Enable using driver in RT X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Nov 2017 10:52:02 -0000 This patch applies necessary modifications, which allow to use MvSpiFlash driver in variable support as a runtime service. Its type is modified to DXE_RUNTIME_DRIVER, as well as an event is created, which converts the pointers to the SpiMasterProtocol and its routines. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c | 58 ++++++++++++++++++-- Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h | 1 + Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf | 6 +- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c index 456d9f9..6886d01 100755 --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include "MvSpiFlash.h" +STATIC EFI_EVENT mMvSpiFlashVirtualAddrChangeEvent; MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol; SPI_FLASH_INSTANCE *mSpiFlashInstance; @@ -503,6 +504,33 @@ MvSpiFlashInitProtocol ( return EFI_SUCCESS; } +/** + Fixup internal data so that EFI can be call in virtual mode. + Call the passed in Child Notify event and convert any pointers in + lib to virtual mode. + + @param[in] Event The Event that is being processed + @param[in] Context Event Context +**/ +STATIC +VOID +EFIAPI +MvSpiFlashVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Convert SpiMasterProtocol callbacks in MvSpiFlashErase and + // MvSpiFlashWrite required by runtime variable support. + // + EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol->ReadWrite); + EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol->Transfer); + EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol); + + return; +} + EFI_STATUS EFIAPI MvSpiFlashEntryPoint ( @@ -522,8 +550,7 @@ MvSpiFlashEntryPoint ( return EFI_DEVICE_ERROR; } - mSpiFlashInstance = AllocateZeroPool (sizeof (SPI_FLASH_INSTANCE)); - + mSpiFlashInstance = AllocateRuntimeZeroPool (sizeof (SPI_FLASH_INSTANCE)); if (mSpiFlashInstance == NULL) { DEBUG((DEBUG_ERROR, "SpiFlash: Cannot allocate memory\n")); return EFI_OUT_OF_RESOURCES; @@ -540,10 +567,33 @@ MvSpiFlashEntryPoint ( NULL ); if (EFI_ERROR (Status)) { - FreePool (mSpiFlashInstance); DEBUG((DEBUG_ERROR, "SpiFlash: Cannot install SPI flash protocol\n")); - return EFI_DEVICE_ERROR; + goto ErrorInstallProto; + } + + // + // Register for the virtual address change event + // + Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + MvSpiFlashVirtualNotifyEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mMvSpiFlashVirtualAddrChangeEvent); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to register VA change event\n", __FUNCTION__)); + goto ErrorCreateEvent; } return EFI_SUCCESS; + +ErrorCreateEvent: + gBS->UninstallMultipleProtocolInterfaces (&mSpiFlashInstance->Handle, + &gMarvellSpiFlashProtocolGuid, + NULL); + +ErrorInstallProto: + FreePool (mSpiFlashInstance); + + return EFI_SUCCESS; } diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h index f09ff50..f69c562 100755 --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h @@ -42,6 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf index 6587f69..200a00c 100644 --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf @@ -33,7 +33,7 @@ INF_VERSION = 0x00010005 BASE_NAME = SpiFlashDxe FILE_GUID = 49d7fb74-306d-42bd-94c8-c0c54b181dd7 - MODULE_TYPE = DXE_DRIVER + MODULE_TYPE = DXE_RUNTIME_DRIVER VERSION_STRING = 1.0 ENTRY_POINT = MvSpiFlashEntryPoint @@ -54,6 +54,10 @@ UefiLib DebugLib MemoryAllocationLib + UefiRuntimeLib + +[Guids] + gEfiEventVirtualAddressChangeGuid [Protocols] gMarvellSpiMasterProtocolGuid -- 2.7.4