From: "Ling Jia" <jialing@phytium.com.cn>
To: devel@edk2.groups.io
Cc: Leif Lindholm <quic_llindhol@quicinc.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Michael D Kinney <michael.d.kinney@intel.com>,
Yiqi Shu <shuyiqi@phytium.com.cn>,
Peng Xie <xiepeng@phytium.com.cn>,
Ling Jia <jialing@phytium.com.cn>
Subject: [PATCH v8 4/4] Silicon/Phytium: Added runtime support to spi master
Date: Mon, 30 Jan 2023 15:34:20 +0800 [thread overview]
Message-ID: <20230130073420.135519-5-jialing@phytium.com.cn> (raw)
In-Reply-To: <20230130073420.135519-1-jialing@phytium.com.cn>
From: Ling Jia <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>
---
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/Silicon/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
+## @file
# Phytium Spi Master Drivers.
#
-# Copyright (C) 2020, Phytium Technology Co, Ltd. All rights reserved.<BR>
+# Copyright (C) 2020-2023, Phytium Technology Co., Ltd. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
-#**/
+#
[Defines]
INF_VERSION = 0x0001001b
@@ -27,18 +27,23 @@ [Packages]
[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 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
Phytium Spi Drivers Header
- Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.<BR>
+ Copyright (C) 2020-2023, Phytium Technology Co., Ltd. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -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 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
Phytium Spi Master Drivers.
- Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.<BR>
+ Copyright (C) 2020-2023, Phytium Technology Co., Ltd. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -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;
@@ -78,7 +79,7 @@ SpiMasterSetConfig (
@param[in] CmdId The id of command.
- @param[out] Config The pointer of the config.
+ @param[out] Config The pointer to the config.
@param[in] RegAddr The address of spi registers.
@@ -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
next prev parent reply other threads:[~2023-01-30 7:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-30 7:34 [PATCH v8 0/4] Improved supports for FT-2000/4 chip Ling Jia
2023-01-30 7:34 ` [PATCH v8 1/4] Platform/Phytium: Solved problems during boot Ling Jia
2023-01-30 7:34 ` [PATCH v8 2/4] Silicon/Phytium: Added flash driver support for flash operation Ling Jia
2023-01-30 7:34 ` [PATCH v8 3/4] Silicon/Phytium: Added fvb driver for flash Ling Jia
2023-01-30 7:34 ` Ling Jia [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-08-09 10:25 [PATCH v8 2/4] Silicon/Phytium: Added flash driver support for flash operation Ling Jia
2022-08-09 10:25 ` [PATCH v8 4/4] Silicon/Phytium: Added runtime support to spi master Ling Jia
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=20230130073420.135519-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