From: "Ling Jia" <jialing@phytium.com.cn>
To: devel@edk2.groups.io
Cc: Leif Lindholm <leif@nuviainc.com>, Ling Jia <jialing@phytium.com.cn>
Subject: [PATCH v7 4/4] Silicon/Phytium: Added runtime support to spi master.
Date: Thu, 14 Apr 2022 14:03:09 +0800 [thread overview]
Message-ID: <20220414060309.30298-5-jialing@phytium.com.cn> (raw)
In-Reply-To: <20220414060309.30298-1-jialing@phytium.com.cn>
Solved the problem of virtual address translation
in runtime access under OS
Signed-off-by: Ling Jia <jialing@phytium.com.cn>
Reviewed-by: leif Lindholm <leif@nuviainc.com>
---
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/Silicon/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
[Guids]
+ gEfiEventVirtualAddressChangeGuid
[Protocols]
gSpiMasterProtocolGuid
[FixedPcd]
gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase
+ gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerSize
[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_
+#include <Library/DxeServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
#include <Protocol/SpiProtocol.h>
#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 <Uefi/UefiBaseType.h>
#include "SpiDxe.h"
-PHYT_SPI_MASTER *pSpiMasterInstance;
-static UINTN mSpiControlBase;
+STATIC EFI_EVENT mSpiMasterVirtualAddrChangeEvent;
+STATIC UINTN mSpiMasterControlBase;
+PHYT_SPI_MASTER *mSpiMasterInstance;
/**
This function inited a spi driver.
@@ -66,7 +67,7 @@ SpiMasterSetConfig (
Value = Config;
}
- SpiAddr = mSpiControlBase + RegAddr;
+ SpiAddr = mSpiMasterControlBase + RegAddr;
MmioWrite32 (SpiAddr, Value);
return EFI_SUCCESS;
@@ -99,7 +100,7 @@ SpiMasterGetConfig (
SpiAddr = 0;
Value = 0;
- SpiAddr = mSpiControlBase + RegAddr;
+ SpiAddr = mSpiMasterControlBase + RegAddr;
Value = MmioRead32 (SpiAddr);
if (CmdId != 0) {
@@ -157,6 +158,34 @@ SpiMasterInitProtocol (
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.
+
+ @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;
+}
/**
This function is the entrypoint of the spi driver.
@@ -178,25 +207,58 @@ SpiMasterDrvEntryPoint (
)
{
EFI_STATUS Status;
+ UINTN SpiMasterControlSize;
- pSpiMasterInstance = AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER));
- if (pSpiMasterInstance == NULL) {
+ mSpiMasterControlBase = FixedPcdGet64 (PcdSpiControllerBase);
+ SpiMasterControlSize = FixedPcdGet64 (PcdSpiControllerSize);
+
+ mSpiMasterInstance = AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER));
+ if (mSpiMasterInstance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
- mSpiControlBase = FixedPcdGet64 (PcdSpiControllerBase);
+ mSpiMasterControlBase = FixedPcdGet64 (PcdSpiControllerBase);
- SpiMasterInitProtocol (&pSpiMasterInstance->SpiMasterProtocol);
+ SpiMasterInitProtocol (&mSpiMasterInstance->SpiMasterProtocol);
- pSpiMasterInstance->Signature = SPI_MASTER_SIGNATURE;
+ mSpiMasterInstance->Signature = SPI_MASTER_SIGNATURE;
Status = gBS->InstallMultipleProtocolInterfaces (
- &(pSpiMasterInstance->Handle),
+ &(mSpiMasterInstance->Handle),
&gSpiMasterProtocolGuid,
- &(pSpiMasterInstance->SpiMasterProtocol),
+ &(mSpiMasterInstance->SpiMasterProtocol),
NULL
);
ASSERT_EFI_ERROR (Status);
+ //
+ // Declare the SPI Controller Space as EFI_MEMORY_RUNTIME
+ //
+ Status = gDS->AddMemorySpace (
+ EfiGcdMemoryTypeMemoryMappedIo,
+ (mSpiMasterControlBase >> EFI_PAGE_SHIFT) << EFI_PAGE_SHIFT, EFI_PAGES_TO_SIZE(EFI_SIZE_TO_PAGES(SpiMasterControlSize)),
+ EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Status = gDS->SetMemorySpaceAttributes (
+ (mSpiMasterControlBase >> EFI_PAGE_SHIFT) << EFI_PAGE_SHIFT, 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 = gBS->CreateEventEx (
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ SpiMasterVirtualNotifyEvent,
+ NULL,
+ &gEfiEventVirtualAddressChangeGuid,
+ &mSpiMasterVirtualAddrChangeEvent
+ );
+ ASSERT_EFI_ERROR (Status);
+
return EFI_SUCCESS;
}
--
2.25.1
prev parent reply other threads:[~2022-04-14 6:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-14 6:03 [PATCH v7 0/4] Improved support for FT2004/4 chip Ling Jia
2022-04-14 6:03 ` [PATCH v7 1/4] Platform/Phytium: Solved problems during boot Ling Jia
2022-04-14 6:03 ` [PATCH v7 2/4] Silicon/Phytium: Added flash driver support to Phytium Silicon Ling Jia
2022-04-14 6:03 ` [PATCH v7 3/4] Silicon/Phytium: Added fvb driver for flash Ling Jia
2022-04-14 6:03 ` Ling Jia [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220414060309.30298-5-jialing@phytium.com.cn \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox