From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.1247.1689086252921640808 for ; Tue, 11 Jul 2023 07:37:33 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: nishant.sharma@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C96EC2F4; Tue, 11 Jul 2023 07:38:14 -0700 (PDT) Received: from usa.arm.com (iss-desktop02.cambridge.arm.com [10.1.196.79]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C50C73F740; Tue, 11 Jul 2023 07:37:31 -0700 (PDT) From: "Nishant Sharma" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar , Thomas Abraham , Sayanta Pattanayak , Achin Gupta Subject: [edk2-platforms][PATCH V1 17/20] ArmPkg/MmCommunicationDxe: Unmap FF-A RX/TX buffers during ExitBootServices Date: Tue, 11 Jul 2023 15:36:55 +0100 Message-Id: <20230711143658.781597-18-nishant.sharma@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com> References: <20230711143658.781597-1-nishant.sharma@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Achin Gupta An FF-A partition can map only a single RX/TX buffer pair with the framework. The DXE MM communication driver maps its pair before ExitBootServices is called. The OS cannot re-use this pair once it boots subsequently and loads its own FF-A driver. This patch ensures that the DXE MM communication driver unmaps its buffer pair when ExitBootServices is called so that the OS can register its own pair if required. Signed-off-by: Achin Gupta Signed-off-by: Nishant Sharma --- ArmPkg/Include/IndustryStandard/ArmFfaSvc.h | 10 ++++ ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 49 +++++++++++++++= +++++ 2 files changed, 59 insertions(+) diff --git a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h b/ArmPkg/Include= /IndustryStandard/ArmFfaSvc.h index ebdf29e8d69a..f78442a465e1 100644 --- a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h +++ b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h @@ -122,6 +122,16 @@ (((content) & FFA_BOOT_INFO_FLAG_CONTENT_MASK) \ << FFA_BOOT_INFO_FLAG_CONTENT_SHIFT) =20 +/* Fromat SP ID info. */ +#define FFA_PARTITION_ID_SHIFT 16 +#define FFA_PARTITION_ID_WIDTH 16 +#define FFA_PARTITION_ID_MASK \ + (((1U << FFA_PARTITION_ID_WIDTH) - 1) \ + << FFA_PARTITION_ID_SHIFT) +#define FFA_PARTITION_ID(partid) \ + ((partid << FFA_PARTITION_ID_SHIFT) & \ + FFA_PARTITION_ID_MASK) + // Descriptor to pass boot information as per the FF-A v1.1 spec. typedef struct { UINT32 Name[4]; diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg= /Drivers/MmCommunicationDxe/MmCommunication.c index 8a4d46e4f80a..39a1b329b9ea 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -43,6 +43,9 @@ STATIC ARM_MEMORY_REGION_DESCRIPTOR mNsCommBuffMemRegi= on; // Notification event when virtual address map is set. STATIC EFI_EVENT mSetVirtualAddressMapEvent; =20 +// Notification event when exit boot services is called. +STATIC EFI_EVENT mExitBootServicesEvent; + // // Handle to install the MM Communication Protocol // @@ -255,6 +258,39 @@ NotifySetVirtualAddressMap ( } } =20 +/** + Notification callback on ExitBootServices event. + + This function notifies the MM communication protocol interface on + ExitBootServices event and releases the FF-A RX/TX buffer. + + @param Event ExitBootServices event. + @param Context A context when the ExitBootServices triggered. + + @retval EFI_SUCCESS The function executed successfully. + @retval Other Some error occurred when executing this functio= n. + +**/ +STATIC +VOID +EFIAPI +NotifyExitBootServices ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + ARM_SMC_ARGS SmcArgs =3D {0}; + + SmcArgs.Arg0 =3D ARM_SVC_ID_FFA_RXTX_UNMAP_AARCH32; + SmcArgs.Arg1 =3D FFA_PARTITION_ID(mFfaPartId); + ArmCallSmc (&SmcArgs); + + // We do not bother checking the error code of the RXTX_UNMAP invocati= on + // since we did map the buffers and this call must succeed. + return; + +} + STATIC EFI_STATUS GetMmCompatibility ( @@ -452,6 +488,19 @@ MmCommunication2Initialize ( goto CleanAddedMemorySpace; } =20 + // Register notification callback when ExitBootservices is called to + // unregister the FF-A RX/TX buffer pair. This allows the OS to regist= er its + // own buffer pair. + if (FixedPcdGet32 (PcdFfaEnable) !=3D 0) { + Status =3D gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_NOTIFY, + NotifyExitBootServices, + NULL, + &mExitBootServicesEvent + ); + ASSERT_EFI_ERROR (Status); + } // Register notification callback when virtual address is associated // with the physical address. // Create a Set Virtual Address Map event. --=20 2.34.1