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 ADBEC21B00DD6 for ; Mon, 20 Nov 2017 22:42:53 -0800 (PST) Received: by mail-lf0-x243.google.com with SMTP id m1so12801442lfj.9 for ; Mon, 20 Nov 2017 22:47:08 -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=Kk9qHpGpSnhfNRSv4Ql5+8vbpOKFCQhcJztpYvToKsE=; b=gOgG1+vzVjZ5g8c7mjBSUuOWrhis1WNNH615DGgB8bpkmT1lE9OV3IGrKOw/sdJ6EI Y84aBFHyzggPjZy+fIQ7eyNhB+scxEg9ez93An8ypfEq6Im/wZRbsBAacpt0G7kIoJqN oVOcBQyT/PSskS12nZ06WE1z8zTr1F2lRcSyB0/EgVbijYTEG09b96zWAsGo6+vxB09n kXHMgyn++GAgJMu6C5+KCJ5AixEZENm4FC+kbKLewbFEgJpM9e5US+/d5odOSq+Jc+CK t0LPkql6RWLZVbewvghFZCMyr+1iBCRGFhU80rZIPwxfbBrqGtmjWp3uGRnn3RydZX2l 2JEg== 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=Kk9qHpGpSnhfNRSv4Ql5+8vbpOKFCQhcJztpYvToKsE=; b=KJ3mS0RMbtOCyRCgnJuTrs/DKnLejA8xn/srHBjR5EF8orWMeF3NCUlSrwvYQrMjAY OztwUKWcdOad1pgpSKTxT8IxCGArZbqln4+1bY1oaCOpPDoTER2OXArZ1pfKZTG01WmK xQEWhC/3XuATHbMIqA2T8lPAfMSxP86nS+pDMFDow0I+FEXjYPBKKWekIemWKZTOo9L8 3IpkJ9ZVrZbGscVKPbK1TJCb5dCBqpTHV5HfZxHzf6CLUTpmy8NszP3Tk+ISPDr9Hhb4 iHwmtoUKUR9aMg743ZMPZDbZ1jzFOKjs2iQS/iySFs8T/7L1uf2GDmCkZoqjqhI0wBbE PRVw== X-Gm-Message-State: AJaThX4j7X9VMsGJuppUD8xYQyFycf4yicFGhhFjWCH5yqCDYuRii1ch f3VQkza0OjbLBX2MH8uRK1/2UH1MP6o= X-Google-Smtp-Source: AGs4zMbbWkJr7MhQTPDLx7jkwUZQEmRzvVrEc9FRCkG8ZiWg0mYOVW7ecO84vhcKUnIeu8vPLa5m9w== X-Received: by 10.25.84.90 with SMTP id i87mr2688093lfb.35.1511246826561; Mon, 20 Nov 2017 22:47:06 -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 f79sm2267015lfk.57.2017.11.20.22.47.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Nov 2017 22:47:05 -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: Tue, 21 Nov 2017 07:46:19 +0100 Message-Id: <1511246781-7073-3-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511246781-7073-1-git-send-email-mw@semihalf.com> References: <1511246781-7073-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH v2 2/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: Tue, 21 Nov 2017 06:42:54 -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. In order to ensure proper execution of the MvFvbDxe driver, configure initialization order with Depex entry. 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 | 11 +++- Platform/Marvell/Marvell.dec | 2 + 4 files changed, 66 insertions(+), 6 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..c6bbe5e 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,10 +54,17 @@ UefiLib DebugLib MemoryAllocationLib + UefiRuntimeLib + +[Guids] + gEfiEventVirtualAddressChangeGuid [Protocols] gMarvellSpiMasterProtocolGuid gMarvellSpiFlashProtocolGuid [Depex] - TRUE + # + # MvSpiFlashDxe must be loaded prior to variables driver MvFvbDxe + # + BEFORE gMarvellFvbDxeGuid diff --git a/Platform/Marvell/Marvell.dec b/Platform/Marvell/Marvell.dec index 6aa2a8d..e40771b 100644 --- a/Platform/Marvell/Marvell.dec +++ b/Platform/Marvell/Marvell.dec @@ -56,6 +56,8 @@ gShellFUpdateHiiGuid = { 0x9b5d2176, 0x590a, 0x49db, { 0x89, 0x5d, 0x4a, 0x70, 0xfe, 0xad, 0xbe, 0x24 } } gShellSfHiiGuid = { 0x03a67756, 0x8cde, 0x4638, { 0x82, 0x34, 0x4a, 0x0f, 0x6d, 0x58, 0x81, 0x39 } } + gMarvellFvbDxeGuid = { 0x42903750, 0x7e61, 0x4aaf, { 0x83, 0x29, 0xbf, 0x42, 0x36, 0x4e, 0x24, 0x85 } } + [Protocols] # installed as a protocol by PlatInitDxe to force ordering between DXE drivers # that depend on the lowlevel platform initialization having been completed -- 2.7.4