From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from zg8tmja5ljk3lje4mi4ymjia.icoremail.net (zg8tmja5ljk3lje4mi4ymjia.icoremail.net [209.97.182.222]) by mx.groups.io with SMTP id smtpd.web10.10128.1660040757438377308 for ; Tue, 09 Aug 2022 03:25:58 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: phytium.com.cn, ip: 209.97.182.222, mailfrom: jialing@phytium.com.cn) Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-2 (Coremail) with SMTP id AQAAfwCnCxUyNvJiu3RpCg--.10860S2; Tue, 09 Aug 2022 18:25:54 +0800 (CST) Received: from localhost.localdomain (unknown [2409:8950:e10:f89b:1c5d:a7af:8f34:8a1e]) by mail (Coremail) with SMTP id AQAAfwD3HyEtNvJi9S4AAA--.164S4; Tue, 09 Aug 2022 18:25:51 +0800 (CST) From: "Ling Jia" To: devel@edk2.groups.io Cc: Ling Jia Subject: [PATCH v8 4/4] Silicon/Phytium: Added runtime support to spi master Date: Tue, 9 Aug 2022 18:25:45 +0800 Message-Id: <20220809102545.380410-3-jialing@phytium.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220809102545.380410-1-jialing@phytium.com.cn> References: <20220809102545.380410-1-jialing@phytium.com.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAfwD3HyEtNvJi9S4AAA--.164S4 X-CM-SenderInfo: xmldzxdqj61x51wl3zoofrzhdfq/ Authentication-Results: hzbj-icmmx-2; spf=neutral smtp.mail=jialing@ph ytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxKw15Gw4UZFyxGr4DJF43KFg_yoW7KF1fpa 1Utr4aqF4UJr4avw1rZw18ur95A390ka4DJrW7WF9YkF1agryjqa13Zr1rGa4xtr9Fya48 XrnYqw48urZ0yw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Content-Transfer-Encoding: quoted-printable From: Ling Jia Solved the problem of virtual address translation in runtime access under OS. Signed-off-by: Ling Jia --- 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 21d75f268da4..0b23821c6523 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf @@ -27,18 +27,23 @@ [Packages] [LibraryClasses]=0D BaseLib=0D DebugLib=0D + DxeServicesTableLib=0D IoLib=0D UefiLib=0D UefiBootServicesTableLib=0D UefiDriverEntryPoint=0D + UefiRuntimeLib=0D + UefiRuntimeServicesTableLib=0D =0D [Guids]=0D + gEfiEventVirtualAddressChangeGuid=0D =0D [Protocols]=0D gSpiMasterProtocolGuid=0D =0D [FixedPcd]=0D gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase=0D + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerSize=0D =0D [Depex]=0D TRUE=0D diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h b/Silicon/= Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h index 8795ea238d83..842d0c3d1861 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_=0D #define SPI_DXE_H_=0D =0D +#include =0D +#include =0D #include =0D =0D #define SPI_MASTER_SIGNATURE SIGNATURE_32 ('M', 'S', 'P', 'I')=0D diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c b/Silicon/= Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c index 7602a3e0cd63..5358ff6090dd 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c @@ -13,8 +13,9 @@ #include =0D #include "SpiDxe.h"=0D =0D -PHYT_SPI_MASTER *pSpiMasterInstance;=0D -static UINTN mSpiControlBase;=0D +STATIC EFI_EVENT mSpiMasterVirtualAddrChangeEvent;=0D +STATIC UINTN mSpiMasterControlBase;=0D +PHYT_SPI_MASTER *mSpiMasterInstance;=0D =0D /**=0D This function inited a spi driver.=0D @@ -66,7 +67,7 @@ SpiMasterSetConfig ( Value =3D Config;=0D }=0D =0D - SpiAddr =3D mSpiControlBase + RegAddr;=0D + SpiAddr =3D mSpiMasterControlBase + RegAddr;=0D MmioWrite32 (SpiAddr, Value);=0D =0D return EFI_SUCCESS;=0D @@ -99,7 +100,7 @@ SpiMasterGetConfig ( SpiAddr =3D 0;=0D Value =3D 0;=0D =0D - SpiAddr =3D mSpiControlBase + RegAddr;=0D + SpiAddr =3D mSpiMasterControlBase + RegAddr;=0D Value =3D MmioRead32 (SpiAddr);=0D =0D if (CmdId !=3D 0) {=0D @@ -157,6 +158,34 @@ SpiMasterInitProtocol ( return EFI_SUCCESS;=0D }=0D =0D +/**=0D + Fixup internal data so that EFI can be call in virtual mode.=0D + Call the passed in Child Notify event and convert any pointers=0D + in lib to virtual mode.=0D +=0D + @param[in] Event The Event that is being processed.=0D +=0D + @param[in] Context Event Context.=0D +=0D + @retval None.=0D +=0D +**/=0D +STATIC=0D +VOID=0D +EFIAPI=0D +SpiMasterVirtualNotifyEvent (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterControlBase));=0D + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance->SpiMasterProtocol= .SpiGetConfig));=0D + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance->SpiMasterProtocol= .SpiSetConfig));=0D + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance->SpiMasterProtocol= ));=0D + EfiConvertPointer (0x0, (VOID **)&(mSpiMasterInstance));=0D +=0D + return;=0D +}=0D =0D /**=0D This function is the entrypoint of the spi driver.=0D @@ -178,25 +207,58 @@ SpiMasterDrvEntryPoint ( )=0D {=0D EFI_STATUS Status;=0D + UINTN SpiMasterControlSize;=0D =0D - pSpiMasterInstance =3D AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER)= );=0D - if (pSpiMasterInstance =3D=3D NULL) {=0D + mSpiMasterControlBase =3D FixedPcdGet64 (PcdSpiControllerBase);=0D + SpiMasterControlSize =3D FixedPcdGet64 (PcdSpiControllerSize);=0D +=0D + mSpiMasterInstance =3D AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER)= );=0D + if (mSpiMasterInstance =3D=3D NULL) {=0D return EFI_OUT_OF_RESOURCES;=0D }=0D =0D - mSpiControlBase =3D FixedPcdGet64 (PcdSpiControllerBase);=0D + mSpiMasterControlBase =3D FixedPcdGet64 (PcdSpiControllerBase);=0D =0D - SpiMasterInitProtocol (&pSpiMasterInstance->SpiMasterProtocol);=0D + SpiMasterInitProtocol (&mSpiMasterInstance->SpiMasterProtocol);=0D =0D - pSpiMasterInstance->Signature =3D SPI_MASTER_SIGNATURE;=0D + mSpiMasterInstance->Signature =3D SPI_MASTER_SIGNATURE;=0D =0D Status =3D gBS->InstallMultipleProtocolInterfaces (=0D - &(pSpiMasterInstance->Handle),=0D + &(mSpiMasterInstance->Handle),=0D &gSpiMasterProtocolGuid,=0D - &(pSpiMasterInstance->SpiMasterProtocol),=0D + &(mSpiMasterInstance->SpiMasterProtocol),=0D NULL=0D );=0D ASSERT_EFI_ERROR (Status);=0D =0D + //=0D + // Declare the SPI Controller Space as EFI_MEMORY_RUNTIME=0D + //=0D + Status =3D gDS->AddMemorySpace (=0D + EfiGcdMemoryTypeMemoryMappedIo,=0D + (mSpiMasterControlBase >> EFI_PAGE_SHIFT) << EFI_PAGE_SH= IFT, EFI_PAGES_TO_SIZE(EFI_SIZE_TO_PAGES(SpiMasterControlSize)),=0D + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D gDS->SetMemorySpaceAttributes (=0D + (mSpiMasterControlBase >> EFI_PAGE_SHIFT) << EFI_PAGE_SH= IFT, EFI_PAGES_TO_SIZE(EFI_SIZE_TO_PAGES(SpiMasterControlSize)),=0D + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + //=0D + // Register for the virtual address change event=0D + //=0D + Status =3D gBS->CreateEventEx (=0D + EVT_NOTIFY_SIGNAL,=0D + TPL_NOTIFY,=0D + SpiMasterVirtualNotifyEvent,=0D + NULL,=0D + &gEfiEventVirtualAddressChangeGuid,=0D + &mSpiMasterVirtualAddrChangeEvent=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D return EFI_SUCCESS;=0D }=0D --=20 2.25.1