From nobody Mon Feb 9 22:20:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+88904+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88904+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1649916229; cv=none; d=zohomail.com; s=zohoarc; b=d21SvFunNfkdoMrSkGUn7tDPWsJCGwHzFJLwyoiveq0sjjdFqt3/+o8VGT7VKNbUsem9q0FGQ6isgem6USdQuWf6oivMKEDnITmmfrLG71GeWFkFagm1ZmuqePkjAJ/vNYR+h/M3IiA4qP4MsaGDByfKKfWwoRFxqP9IdRQ+wsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649916229; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=NC7heF0Vx+I/6sYlo1pLnE9+xfK/2yOJy4lxoD/dIfc=; b=NXWcneyj73AGwywVeuFa6juxQChKrTu6SjjWCqKwL2656Dzsb8zI+9ONqmIWNSStSkUEobbbFgLTnPHSN5EPcpMjArppya72WLhqIvGJCL6JvvSpW8x+kCn6kk8cfWX6o2L5GtGhcTcdiJmYfBECs6z9bWDErbV1Icirfx3gtWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88904+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1649916229769822.7745679026456; Wed, 13 Apr 2022 23:03:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pl87YY1788612x0tD4i3zENI; Wed, 13 Apr 2022 23:03:49 -0700 X-Received: from zg8tmty3ljk5ljewns4xndka.icoremail.net (zg8tmty3ljk5ljewns4xndka.icoremail.net [167.99.105.149]) by mx.groups.io with SMTP id smtpd.web09.8413.1649916223397099165 for ; Wed, 13 Apr 2022 23:03:45 -0700 X-Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-2 (Coremail) with SMTP id AQAAfwBH5cxcuVdiwbCVAA--.48050S2; Thu, 14 Apr 2022 14:04:12 +0800 (CST) X-Received: from localhost.localdomain (unknown [2409:8950:e30:b22b:2796:3ef3:5bba:2229]) by mail (Coremail) with SMTP id AQAAfwD3qpswuVdisSEAAA--.705S6; Thu, 14 Apr 2022 14:03:39 +0800 (CST) From: "Ling Jia" To: devel@edk2.groups.io Cc: Leif Lindholm , Ling Jia Subject: [edk2-devel] [PATCH v7 4/4] Silicon/Phytium: Added runtime support to spi master. Date: Thu, 14 Apr 2022 14:03:09 +0800 Message-Id: <20220414060309.30298-5-jialing@phytium.com.cn> In-Reply-To: <20220414060309.30298-1-jialing@phytium.com.cn> References: <20220414060309.30298-1-jialing@phytium.com.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAfwD3qpswuVdisSEAAA--.705S6 X-CM-SenderInfo: xmldzxdqj61x51wl3zoofrzhdfq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxKw15Gw4UZFyxGr4DJF43KFg_yoW7KrW8pa 1Utr4aqF4UJr43Zw1rZw18urn5A390ka4DJrW3WF9YkF1agryjqa13Zr1rKa4xtr9Fya48 XrnYqw48urZ0yw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jialing@phytium.com.cn X-Gm-Message-State: ihlhInIeJPmS6qIaWF8gL6NOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1649916229; bh=L2BIvbENASwwEKCCzCUBePU9yg9RZZgLfMkaJy/gcKU=; h=Cc:Date:From:Reply-To:Subject:To; b=LSCJQE+7Zal+2kQ5uOrtZ658pBnaBc/Q0PyORJzTBM36tPM/ToHUugwo4cWVwq8JU+W qfx/rDmMCWKOewPACdmcYQ4BK9MsRsADfK7zlPv/L3Xz/AtC2r2yquizxNA0K0zxibAkK yLJP6g8eFoV2++SU+fSt32Gi9LX5ibjUo0w= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1649916231643100008 Content-Type: text/plain; charset="utf-8" Solved the problem of virtual address translation in runtime access under OS Signed-off-by: Ling Jia Reviewed-by: leif Lindholm --- Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf | 5 ++ Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h | 2 + Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c | 84 +++++++++++++++= ++--- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf b/Silico= n/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf index 21d75f268d..0b23821c65 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf @@ -27,18 +27,23 @@ [LibraryClasses] BaseLib DebugLib + DxeServicesTableLib IoLib UefiLib UefiBootServicesTableLib UefiDriverEntryPoint + UefiRuntimeLib + UefiRuntimeServicesTableLib =20 [Guids] + gEfiEventVirtualAddressChangeGuid =20 [Protocols] gSpiMasterProtocolGuid =20 [FixedPcd] gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerSize =20 [Depex] TRUE diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h b/Silicon/= Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h index 8795ea238d..842d0c3d18 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h @@ -10,6 +10,8 @@ #ifndef SPI_DXE_H_ #define SPI_DXE_H_ =20 +#include +#include #include =20 #define SPI_MASTER_SIGNATURE SIGNATURE_32 ('M', 'S', 'P', 'I') diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c b/Silicon/= Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c index 7602a3e0cd..5358ff6090 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c @@ -13,8 +13,9 @@ #include #include "SpiDxe.h" =20 -PHYT_SPI_MASTER *pSpiMasterInstance; -static UINTN mSpiControlBase; +STATIC EFI_EVENT mSpiMasterVirtualAddrChangeEvent; +STATIC UINTN mSpiMasterControlBase; +PHYT_SPI_MASTER *mSpiMasterInstance; =20 /** This function inited a spi driver. @@ -66,7 +67,7 @@ SpiMasterSetConfig ( Value =3D Config; } =20 - SpiAddr =3D mSpiControlBase + RegAddr; + SpiAddr =3D mSpiMasterControlBase + RegAddr; MmioWrite32 (SpiAddr, Value); =20 return EFI_SUCCESS; @@ -99,7 +100,7 @@ SpiMasterGetConfig ( SpiAddr =3D 0; Value =3D 0; =20 - SpiAddr =3D mSpiControlBase + RegAddr; + SpiAddr =3D mSpiMasterControlBase + RegAddr; Value =3D MmioRead32 (SpiAddr); =20 if (CmdId !=3D 0) { @@ -157,6 +158,34 @@ SpiMasterInitProtocol ( return EFI_SUCCESS; } =20 +/** + 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. + + @retval None. + +**/ +STATIC +VOID +EFIAPI +SpiMasterVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterControlBase)); + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance->SpiMasterProtocol= .SpiGetConfig)); + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance->SpiMasterProtocol= .SpiSetConfig)); + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance->SpiMasterProtocol= )); + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance)); + + return; +} =20 /** This function is the entrypoint of the spi driver. @@ -178,25 +207,58 @@ SpiMasterDrvEntryPoint ( ) { EFI_STATUS Status; + UINTN SpiMasterControlSize; =20 - pSpiMasterInstance =3D AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER)= ); - if (pSpiMasterInstance =3D=3D NULL) { + mSpiMasterControlBase =3D FixedPcdGet64 (PcdSpiControllerBase); + SpiMasterControlSize =3D FixedPcdGet64 (PcdSpiControllerSize); + + mSpiMasterInstance =3D AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER)= ); + if (mSpiMasterInstance =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 - mSpiControlBase =3D FixedPcdGet64 (PcdSpiControllerBase); + mSpiMasterControlBase =3D FixedPcdGet64 (PcdSpiControllerBase); =20 - SpiMasterInitProtocol (&pSpiMasterInstance->SpiMasterProtocol); + SpiMasterInitProtocol (&mSpiMasterInstance->SpiMasterProtocol); =20 - pSpiMasterInstance->Signature =3D SPI_MASTER_SIGNATURE; + mSpiMasterInstance->Signature =3D SPI_MASTER_SIGNATURE; =20 Status =3D gBS->InstallMultipleProtocolInterfaces ( - &(pSpiMasterInstance->Handle), + &(mSpiMasterInstance->Handle), &gSpiMasterProtocolGuid, - &(pSpiMasterInstance->SpiMasterProtocol), + &(mSpiMasterInstance->SpiMasterProtocol), NULL ); ASSERT_EFI_ERROR (Status); =20 + // + // Declare the SPI Controller Space as EFI_MEMORY_RUNTIME + // + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + (mSpiMasterControlBase >> EFI_PAGE_SHIFT) << EFI_PAGE_SH= IFT, EFI_PAGES_TO_SIZE(EFI_SIZE_TO_PAGES(SpiMasterControlSize)), + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + ASSERT_EFI_ERROR (Status); + + Status =3D gDS->SetMemorySpaceAttributes ( + (mSpiMasterControlBase >> EFI_PAGE_SHIFT) << EFI_PAGE_SH= IFT, EFI_PAGES_TO_SIZE(EFI_SIZE_TO_PAGES(SpiMasterControlSize)), + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + ASSERT_EFI_ERROR (Status); + + // + // Register for the virtual address change event + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + SpiMasterVirtualNotifyEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mSpiMasterVirtualAddrChangeEvent + ); + ASSERT_EFI_ERROR (Status); + return EFI_SUCCESS; } --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88904): https://edk2.groups.io/g/devel/message/88904 Mute This Topic: https://groups.io/mt/90458876/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-