From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [20.228.234.168]) by mx.groups.io with SMTP id smtpd.web10.35960.1675064261634224389 for ; Sun, 29 Jan 2023 23:37:42 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: phytium.com.cn, ip: 20.228.234.168, mailfrom: jialing@phytium.com.cn) Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with SMTP id AQAAfwDnie0QdNdjK72SBA--.61759S2; Mon, 30 Jan 2023 15:38:56 +0800 (CST) Received: from localhost.localdomain (unknown [117.136.89.78]) by mail (Coremail) with SMTP id AQAAfwBnZB26c9djDDUAAA--.158S6; Mon, 30 Jan 2023 15:37:38 +0800 (CST) From: "Ling Jia" To: devel@edk2.groups.io Cc: Leif Lindholm , Liming Gao , Michael D Kinney , Yiqi Shu , Peng Xie , Ling Jia Subject: [PATCH v8 4/4] Silicon/Phytium: Added runtime support to spi master Date: Mon, 30 Jan 2023 15:34:20 +0800 Message-Id: <20230130073420.135519-5-jialing@phytium.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230130073420.135519-1-jialing@phytium.com.cn> References: <20230130073420.135519-1-jialing@phytium.com.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAfwBnZB26c9djDDUAAA--.158S6 X-CM-SenderInfo: xmldzxdqj61x51wl3zoofrzhdfq/ Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=jialing@ph ytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxKw15Gw4rGw4kGF1DuFy8Zrb_yoWxtF45pa 18trs0qr4UJr43Z3yrZw1kur95A39xKFyDtrZxWa4ruF4agry0ganxZr1rJF97tr9Fy348 WrnYqw47urZ0yw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj 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 | 11 ++- Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h | 4 +- Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c | 88 +++++++++++++++= ++--- 3 files changed, 86 insertions(+), 17 deletions(-) diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf b/Silico= n/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf index 21d75f268da4..d7ee1999c4ed 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf @@ -1,11 +1,11 @@ -#/** @file=0D +## @file=0D # Phytium Spi Master Drivers.=0D #=0D -# Copyright (C) 2020, Phytium Technology Co, Ltd. All rights reserved.=0D +# Copyright (C) 2020-2023, Phytium Technology Co., Ltd. All rights reserv= ed.
=0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D -#**/=0D +#=0D =0D [Defines]=0D INF_VERSION =3D 0x0001001b=0D @@ -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..80d1db79ebbc 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h @@ -1,7 +1,7 @@ /** @file=0D Phytium Spi Drivers Header=0D =0D - Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
= =0D + Copyright (C) 2020-2023, Phytium Technology Co., Ltd. All rights reserve= d.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -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..6915c95f40b0 100644 --- a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c @@ -1,7 +1,7 @@ /** @file=0D Phytium Spi Master Drivers.=0D =0D - Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
= =0D + Copyright (C) 2020-2023, Phytium Technology Co., Ltd. All rights reserve= d.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -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 @@ -78,7 +79,7 @@ SpiMasterSetConfig ( =0D @param[in] CmdId The id of command.=0D =0D - @param[out] Config The pointer of the config.=0D + @param[out] Config The pointer to the config.=0D =0D @param[in] RegAddr The address of spi registers.=0D =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