Re: [edk2] [PATCH v2 09/10] StandaloneMmPkg: Add CPU driver suitable for ARM Platforms.

2018-07-23 Thread Supreeth Venkatesh
Sughosh,

My response inline.

Thanks,
Supreeth

-Original Message-
From: Achin Gupta
Sent: Thursday, July 19, 2018 2:05 PM
To: Sughosh Ganu 
Cc: edk2-devel@lists.01.org; Jiewen Yao ; Supreeth 
Venkatesh ; nd 
Subject: Re: [PATCH v2 09/10] StandaloneMmPkg: Add CPU driver suitable for ARM 
Platforms.

Thanks Sughosh.

Reviewed-by: Achin Gupta 


On Fri, Jul 13, 2018 at 08:35:29PM +0530, Sughosh Ganu wrote:
> From: Supreeth Venkatesh 
>
> This patch adds a simple CPU driver that exports the
> EFI_MM_CONFIGURATION_PROTOCOL to allow registration of the Standalone
> MM Foundation entry point. It preserves the existing notification
> mechanism for the configuration protocol.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Sughosh Ganu 
> Signed-off-by: Achin Gupta 
> Signed-off-by: Supreeth Venkatesh 
> ---
>  .../Drivers/StandaloneMmCpu/AArch64/EventHandle.c  | 220 +++
>  .../StandaloneMmCpu/AArch64/StandaloneMmCpu.c  | 232 
> +
>  .../StandaloneMmCpu/AArch64/StandaloneMmCpu.h  |  64 ++
>  .../StandaloneMmCpu/AArch64/StandaloneMmCpu.inf|  59 ++
>  StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
>  5 files changed, 616 insertions(+)
>  create mode 100644
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>  create mode 100644
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c
>  create mode 100644
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.h
>  create mode 100644
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf
>  create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h
>
> diff --git
> a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
> new file mode 100644
> index ..2814577b3fcc
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
> @@ -0,0 +1,220 @@
> +/** @file
> +
> +  Copyright (c) 2016 HP Development Company, L.P.
> +  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
> +
> +  This program and the accompanying materials  are licensed and made
> + available under the terms and conditions of the BSD License  which
> + accompanies this distribution.  The full text of the license may be
> + found at  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> + BASIS,  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS 
> OR IMPLIED.
> +
> +**/
> +
> +#include 
> +#include 
> +
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include  // for EFI_SYSTEM_CONTEXT
> +
> +#include 
> +#include 
> +
> +#include 
> +
> +#include "StandaloneMmCpu.h"
> +
> +EFI_STATUS
> +EFIAPI
> +MmFoundationEntryRegister (
> +  IN CONST EFI_MM_CONFIGURATION_PROTOCOL  *This,
> +  IN EFI_MM_ENTRY_POINTMmEntryPoint
> +  );
> +
> +//
> +// On ARM platforms every event is expected to have a GUID associated
> +with // it. It will be used by the MM Entry point to find the handler
> +for the // event. It will either be populated in a
> +EFI_MM_COMMUNICATE_HEADER by the // caller of the event (e.g.
> +MM_COMMUNICATE SMC) or by the CPU driver // (e.g. during an
> +asynchronous event). In either case, this context is // maintained in
> +an array which has an entry for each CPU. The pointer to this //
> +array is held in PerCpuGuidedEventContext. Memory is allocated once
> +the // number of CPUs in the system are made known through the // 
> MP_INFORMATION_HOB_DATA.
> +//
> +EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL;
> +
> +// Descriptor with whereabouts of memory used for communication with
> +the normal world EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
> +
> +MP_INFORMATION_HOB_DATA *mMpInformationHobData;
> +
> +EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
> +  0,
> +  MmFoundationEntryRegister
> +};
> +
> +STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
> +
> +EFI_STATUS
> +PiMmStandloneArmTfCpuDriverEntry (
> +  IN UINTN EventId,
> +  IN UINTN CpuNumber,
> +  IN UINTN NsCommBufferAddr
> +  )
> +{
> +  EFI_MM_COMMUNICATE_HEADER *GuidedEventContext = NULL;
> +  EFI_MM_ENTRY_CONTEXTMmEntryPointContext = {0};
> +  EFI_STATUS  Status;
> +  UINTN   NsCommBufferSize;
> +
> +  DEBUG ((DEBUG_INFO, "Received event - 0x%x on cpu %d\n", EventId,
> + CpuNumber));
> +
> +  Status = EFI_SUCCESS;
> +  //
> +  // ARM TF passes SMC FID of the MM_COMMUNICATE interface as the
> + Event ID upon  // receipt of a synchronous MM request. Use the Event
> + ID to distinguish  // between synchronous and asynchronous events.
> +  //
> +  if (ARM_SMC_ID_MM_COMMUNICATE_AARCH64 != EventId) {
> +DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId));
> +return EFI_INVALID_PARAMETER;
> +  }
> +
> +  // Perform parameter validation of NsCommBufferAddr  if
> + 

Re: [edk2] [PATCH v2 09/10] StandaloneMmPkg: Add CPU driver suitable for ARM Platforms.

2018-07-19 Thread Achin Gupta
Thanks Sughosh.

Reviewed-by: Achin Gupta 


On Fri, Jul 13, 2018 at 08:35:29PM +0530, Sughosh Ganu wrote:
> From: Supreeth Venkatesh 
> 
> This patch adds a simple CPU driver that exports the
> EFI_MM_CONFIGURATION_PROTOCOL to allow registration of the Standalone
> MM Foundation entry point. It preserves the existing notification
> mechanism for the configuration protocol.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Sughosh Ganu 
> Signed-off-by: Achin Gupta 
> Signed-off-by: Supreeth Venkatesh 
> ---
>  .../Drivers/StandaloneMmCpu/AArch64/EventHandle.c  | 220 +++
>  .../StandaloneMmCpu/AArch64/StandaloneMmCpu.c  | 232 
> +
>  .../StandaloneMmCpu/AArch64/StandaloneMmCpu.h  |  64 ++
>  .../StandaloneMmCpu/AArch64/StandaloneMmCpu.inf|  59 ++
>  StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
>  5 files changed, 616 insertions(+)
>  create mode 100644 
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>  create mode 100644 
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c
>  create mode 100644 
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.h
>  create mode 100644 
> StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf
>  create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h
> 
> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c 
> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
> new file mode 100644
> index ..2814577b3fcc
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
> @@ -0,0 +1,220 @@
> +/** @file
> +
> +  Copyright (c) 2016 HP Development Company, L.P.
> +  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD 
> License
> +  which accompanies this distribution.  The full text of the license may be 
> found at
> +  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
> IMPLIED.
> +
> +**/
> +
> +#include 
> +#include 
> +
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include  // for EFI_SYSTEM_CONTEXT
> +
> +#include 
> +#include 
> +
> +#include 
> +
> +#include "StandaloneMmCpu.h"
> +
> +EFI_STATUS
> +EFIAPI
> +MmFoundationEntryRegister (
> +  IN CONST EFI_MM_CONFIGURATION_PROTOCOL  *This,
> +  IN EFI_MM_ENTRY_POINTMmEntryPoint
> +  );
> +
> +//
> +// On ARM platforms every event is expected to have a GUID associated with
> +// it. It will be used by the MM Entry point to find the handler for the
> +// event. It will either be populated in a EFI_MM_COMMUNICATE_HEADER by the
> +// caller of the event (e.g. MM_COMMUNICATE SMC) or by the CPU driver
> +// (e.g. during an asynchronous event). In either case, this context is
> +// maintained in an array which has an entry for each CPU. The pointer to 
> this
> +// array is held in PerCpuGuidedEventContext. Memory is allocated once the
> +// number of CPUs in the system are made known through the
> +// MP_INFORMATION_HOB_DATA.
> +//
> +EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL;
> +
> +// Descriptor with whereabouts of memory used for communication with the 
> normal world
> +EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
> +
> +MP_INFORMATION_HOB_DATA *mMpInformationHobData;
> +
> +EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
> +  0,
> +  MmFoundationEntryRegister
> +};
> +
> +STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
> +
> +EFI_STATUS
> +PiMmStandloneArmTfCpuDriverEntry (
> +  IN UINTN EventId,
> +  IN UINTN CpuNumber,
> +  IN UINTN NsCommBufferAddr
> +  )
> +{
> +  EFI_MM_COMMUNICATE_HEADER *GuidedEventContext = NULL;
> +  EFI_MM_ENTRY_CONTEXTMmEntryPointContext = {0};
> +  EFI_STATUS  Status;
> +  UINTN   NsCommBufferSize;
> +
> +  DEBUG ((DEBUG_INFO, "Received event - 0x%x on cpu %d\n", EventId, 
> CpuNumber));
> +
> +  Status = EFI_SUCCESS;
> +  //
> +  // ARM TF passes SMC FID of the MM_COMMUNICATE interface as the Event ID 
> upon
> +  // receipt of a synchronous MM request. Use the Event ID to distinguish
> +  // between synchronous and asynchronous events.
> +  //
> +  if (ARM_SMC_ID_MM_COMMUNICATE_AARCH64 != EventId) {
> +DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId));
> +return EFI_INVALID_PARAMETER;
> +  }
> +
> +  // Perform parameter validation of NsCommBufferAddr
> +  if (NsCommBufferAddr && (NsCommBufferAddr < mNsCommBuffer.PhysicalStart))
> +return EFI_ACCESS_DENIED;
> +
> +  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
> +  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize))
> +return EFI_INVALID_PARAMETER;
> +
> +  // 

[edk2] [PATCH v2 09/10] StandaloneMmPkg: Add CPU driver suitable for ARM Platforms.

2018-07-13 Thread Sughosh Ganu
From: Supreeth Venkatesh 

This patch adds a simple CPU driver that exports the
EFI_MM_CONFIGURATION_PROTOCOL to allow registration of the Standalone
MM Foundation entry point. It preserves the existing notification
mechanism for the configuration protocol.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sughosh Ganu 
Signed-off-by: Achin Gupta 
Signed-off-by: Supreeth Venkatesh 
---
 .../Drivers/StandaloneMmCpu/AArch64/EventHandle.c  | 220 +++
 .../StandaloneMmCpu/AArch64/StandaloneMmCpu.c  | 232 +
 .../StandaloneMmCpu/AArch64/StandaloneMmCpu.h  |  64 ++
 .../StandaloneMmCpu/AArch64/StandaloneMmCpu.inf|  59 ++
 StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
 5 files changed, 616 insertions(+)
 create mode 100644 
StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
 create mode 100644 
StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c
 create mode 100644 
StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.h
 create mode 100644 
StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf
 create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
new file mode 100644
index ..2814577b3fcc
--- /dev/null
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
@@ -0,0 +1,220 @@
+/** @file
+
+  Copyright (c) 2016 HP Development Company, L.P.
+  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include 
+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include  // for EFI_SYSTEM_CONTEXT
+
+#include 
+#include 
+
+#include 
+
+#include "StandaloneMmCpu.h"
+
+EFI_STATUS
+EFIAPI
+MmFoundationEntryRegister (
+  IN CONST EFI_MM_CONFIGURATION_PROTOCOL  *This,
+  IN EFI_MM_ENTRY_POINTMmEntryPoint
+  );
+
+//
+// On ARM platforms every event is expected to have a GUID associated with
+// it. It will be used by the MM Entry point to find the handler for the
+// event. It will either be populated in a EFI_MM_COMMUNICATE_HEADER by the
+// caller of the event (e.g. MM_COMMUNICATE SMC) or by the CPU driver
+// (e.g. during an asynchronous event). In either case, this context is
+// maintained in an array which has an entry for each CPU. The pointer to this
+// array is held in PerCpuGuidedEventContext. Memory is allocated once the
+// number of CPUs in the system are made known through the
+// MP_INFORMATION_HOB_DATA.
+//
+EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL;
+
+// Descriptor with whereabouts of memory used for communication with the 
normal world
+EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
+
+MP_INFORMATION_HOB_DATA *mMpInformationHobData;
+
+EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
+  0,
+  MmFoundationEntryRegister
+};
+
+STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
+
+EFI_STATUS
+PiMmStandloneArmTfCpuDriverEntry (
+  IN UINTN EventId,
+  IN UINTN CpuNumber,
+  IN UINTN NsCommBufferAddr
+  )
+{
+  EFI_MM_COMMUNICATE_HEADER *GuidedEventContext = NULL;
+  EFI_MM_ENTRY_CONTEXTMmEntryPointContext = {0};
+  EFI_STATUS  Status;
+  UINTN   NsCommBufferSize;
+
+  DEBUG ((DEBUG_INFO, "Received event - 0x%x on cpu %d\n", EventId, 
CpuNumber));
+
+  Status = EFI_SUCCESS;
+  //
+  // ARM TF passes SMC FID of the MM_COMMUNICATE interface as the Event ID upon
+  // receipt of a synchronous MM request. Use the Event ID to distinguish
+  // between synchronous and asynchronous events.
+  //
+  if (ARM_SMC_ID_MM_COMMUNICATE_AARCH64 != EventId) {
+DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId));
+return EFI_INVALID_PARAMETER;
+  }
+
+  // Perform parameter validation of NsCommBufferAddr
+  if (NsCommBufferAddr && (NsCommBufferAddr < mNsCommBuffer.PhysicalStart))
+return EFI_ACCESS_DENIED;
+
+  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
+  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize))
+return EFI_INVALID_PARAMETER;
+
+  // Find out the size of the buffer passed
+  NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
NsCommBufferAddr)->MessageLength +
+sizeof (EFI_MM_COMMUNICATE_HEADER);
+
+  // perform bounds check.
+  if (NsCommBufferAddr + NsCommBufferSize >=
+  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)
+return EFI_ACCESS_DENIED;
+
+
+  // Now that the secure world can see the normal