Re: [edk2] [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver suitable for ARM Platforms.

2018-05-04 Thread Supreeth Venkatesh
My response inline.

-Original Message-
From: Daniil Egranov <daniil.egra...@arm.com>
Sent: Wednesday, April 18, 2018 5:09 PM
To: Supreeth Venkatesh <supreeth.venkat...@arm.com>; edk2-devel@lists.01.org
Cc: ard.biesheu...@linaro.org; leif.lindh...@linaro.org; jiewen@intel.com; 
liming@intel.com; michael.d.kin...@intel.com
Subject: Re: [edk2] [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver 
suitable for ARM Platforms.

Hi Supreeth,

I am not sure how much it enforced in edk2 but in most of the cases, the 
driver's name matches its directory name.

[Supreeth] Thanks. Renamed it. Please check version 2.

Thanks,
Daniil

On 04/06/2018 09:42 AM, Supreeth Venkatesh wrote:
> 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: Achin Gupta <achin.gu...@arm.com>
> Signed-off-by: Supreeth Venkatesh <supreeth.venkat...@arm.com>
> ---
>   StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S  |  33 +++
>   StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c| 231 
> +
>   StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c   | 229 
> 
>   .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h|  89 
>   .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf  |  60 ++
>   StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c  |  51 +
>   StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
>   7 files changed, 734 insertions(+)
>   create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
>   create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
>   create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c
>   create mode 100644 
> StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h
>   create mode 100644 
> StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf
>   create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c
>   create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h
>
> diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> new file mode 100644
> index 00..0b6e1c330d
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> @@ -0,0 +1,33 @@
> +//
> +//  Copyright (c) 2017, 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 
> +
> +.text
> +.align 3
> +
> +GCC_ASM_IMPORT(PiMmStandloneArmTfCpuDriverEntry)
> +GCC_ASM_EXPORT(_PiMmStandloneArmTfCpuDriverEntry)
> +
> +// Stub entry point to ensure that the stacks are completely unwound
> +before // signalling completion of event handling
> +ASM_PFX(_PiMmStandloneArmTfCpuDriverEntry):
> +  blPiMmStandloneArmTfCpuDriverEntry
> +  mov   x1, x0
> +  mov   x0, #(ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 & 0x)
> +  movk  x0, #((ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 >> 16) & 0x), lsl #16
> +  svc   #0
> +LoopForever:
> +  b LoopForever
> diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> new file mode 100644
> index 00..7b19f53ecb
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> @@ -0,0 +1,231 @@
> +/** @file
> +
> +  Copyright (c) 2016 HP Development Company, L.P.
> +  Copyright (c) 2016 - 2017, 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 
> +

Re: [edk2] [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver suitable for ARM Platforms.

2018-05-04 Thread Supreeth Venkatesh
My response inline.

-Original Message-
From: Achin Gupta
Sent: Monday, April 30, 2018 10:51 AM
To: Supreeth Venkatesh 
Cc: edk2-devel@lists.01.org; michael.d.kin...@intel.com; liming@intel.com; 
jiewen@intel.com; leif.lindh...@linaro.org; ard.biesheu...@linaro.org; nd 

Subject: Re: [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver suitable 
for ARM Platforms.

Hi Supreeth,

Usual comment about copyright years and invalid comments. I also noticed some 
TODOs and have provided comments for them. Please see inline
[Supreeth] Ok.

On Fri, Apr 06, 2018 at 03:42:17PM +0100, Supreeth Venkatesh wrote:
> 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: Achin Gupta 
> Signed-off-by: Supreeth Venkatesh 
> ---
>  StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S  |  33 +++

This file is not used.
[Supreeth] Ok.

>  StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c| 231 
> +
>  StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c   | 229 
>  .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h|  89 
>  .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf  |  60 ++
>  StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c  |  51 +
>  StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
>  7 files changed, 734 insertions(+)
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c
>  create mode 100644
> StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h
>  create mode 100644
> StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c
>  create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h
>
> diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> new file mode 100644
> index 00..0b6e1c330d
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> @@ -0,0 +1,33 @@
> +//
> +//  Copyright (c) 2017, 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 
> +
> +.text
> +.align 3
> +
> +GCC_ASM_IMPORT(PiMmStandloneArmTfCpuDriverEntry)
> +GCC_ASM_EXPORT(_PiMmStandloneArmTfCpuDriverEntry)
> +
> +// Stub entry point to ensure that the stacks are completely unwound
> +before // signalling completion of event handling
> +ASM_PFX(_PiMmStandloneArmTfCpuDriverEntry):
> +  blPiMmStandloneArmTfCpuDriverEntry
> +  mov   x1, x0
> +  mov   x0, #(ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 & 0x)
> +  movk  x0, #((ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 >> 16) & 0x), lsl #16
> +  svc   #0
> +LoopForever:
> +  b LoopForever
> diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> new file mode 100644
> index 00..7b19f53ecb
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> @@ -0,0 +1,231 @@
> +/** @file
> +
> +  Copyright (c) 2016 HP Development Company, L.P.
> +  Copyright (c) 2016 - 2017, 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 "PiMmStandloneArmTfCpuDriver.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
> 

Re: [edk2] [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver suitable for ARM Platforms.

2018-04-30 Thread Achin Gupta
Hi Supreeth,

Usual comment about copyright years and invalid comments. I also noticed some
TODOs and have provided comments for them. Please see inline

On Fri, Apr 06, 2018 at 03:42:17PM +0100, Supreeth Venkatesh wrote:
> 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: Achin Gupta 
> Signed-off-by: Supreeth Venkatesh 
> ---
>  StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S  |  33 +++

This file is not used.

>  StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c| 231 
> +
>  StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c   | 229 
>  .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h|  89 
>  .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf  |  60 ++
>  StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c  |  51 +
>  StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
>  7 files changed, 734 insertions(+)
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c
>  create mode 100644 
> StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h
>  create mode 100644 
> StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf
>  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c
>  create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h
> 
> diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S 
> b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> new file mode 100644
> index 00..0b6e1c330d
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
> @@ -0,0 +1,33 @@
> +//
> +//  Copyright (c) 2017, 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 
> +
> +.text
> +.align 3
> +
> +GCC_ASM_IMPORT(PiMmStandloneArmTfCpuDriverEntry)
> +GCC_ASM_EXPORT(_PiMmStandloneArmTfCpuDriverEntry)
> +
> +// Stub entry point to ensure that the stacks are completely unwound before
> +// signalling completion of event handling
> +ASM_PFX(_PiMmStandloneArmTfCpuDriverEntry):
> +  blPiMmStandloneArmTfCpuDriverEntry
> +  mov   x1, x0
> +  mov   x0, #(ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 & 0x)
> +  movk  x0, #((ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 >> 16) & 0x), lsl #16
> +  svc   #0
> +LoopForever:
> +  b LoopForever
> diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c 
> b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> new file mode 100644
> index 00..7b19f53ecb
> --- /dev/null
> +++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
> @@ -0,0 +1,231 @@
> +/** @file
> +
> +  Copyright (c) 2016 HP Development Company, L.P.
> +  Copyright (c) 2016 - 2017, 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 "PiMmStandloneArmTfCpuDriver.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 

Re: [edk2] [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver suitable for ARM Platforms.

2018-04-18 Thread Daniil Egranov

Hi Supreeth,

I am not sure how much it enforced in edk2 but in most of the cases, the 
driver's name matches its directory name.


Thanks,
Daniil

On 04/06/2018 09:42 AM, Supreeth Venkatesh wrote:

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: Achin Gupta 
Signed-off-by: Supreeth Venkatesh 
---
  StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S  |  33 +++
  StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c| 231 +
  StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c   | 229 
  .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h|  89 
  .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf  |  60 ++
  StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c  |  51 +
  StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
  7 files changed, 734 insertions(+)
  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c
  create mode 100644 
StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h
  create mode 100644 
StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf
  create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c
  create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h

diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S 
b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
new file mode 100644
index 00..0b6e1c330d
--- /dev/null
+++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
@@ -0,0 +1,33 @@
+//
+//  Copyright (c) 2017, 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 
+
+.text
+.align 3
+
+GCC_ASM_IMPORT(PiMmStandloneArmTfCpuDriverEntry)
+GCC_ASM_EXPORT(_PiMmStandloneArmTfCpuDriverEntry)
+
+// Stub entry point to ensure that the stacks are completely unwound before
+// signalling completion of event handling
+ASM_PFX(_PiMmStandloneArmTfCpuDriverEntry):
+  blPiMmStandloneArmTfCpuDriverEntry
+  mov   x1, x0
+  mov   x0, #(ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 & 0x)
+  movk  x0, #((ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 >> 16) & 0x), lsl #16
+  svc   #0
+LoopForever:
+  b LoopForever
diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c 
b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
new file mode 100644
index 00..7b19f53ecb
--- /dev/null
+++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
@@ -0,0 +1,231 @@
+/** @file
+
+  Copyright (c) 2016 HP Development Company, L.P.
+  Copyright (c) 2016 - 2017, 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 "PiMmStandloneArmTfCpuDriver.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;
+
+//
+// When an event is received by the CPU driver, it could correspond to a unique
+// GUID (e.g. interrupt events) or to multiple GUIDs (e.g. MM_COMMUNICATE
+// SMC). A table is used 

[edk2] [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver suitable for ARM Platforms.

2018-04-06 Thread 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: Achin Gupta 
Signed-off-by: Supreeth Venkatesh 
---
 StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S  |  33 +++
 StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c| 231 +
 StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c   | 229 
 .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h|  89 
 .../CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf  |  60 ++
 StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c  |  51 +
 StandaloneMmPkg/Include/Guid/MpInformation.h   |  41 
 7 files changed, 734 insertions(+)
 create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
 create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
 create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/Init.c
 create mode 100644 
StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.h
 create mode 100644 
StandaloneMmPkg/Drivers/CpuMm/Arm/PiMmStandloneArmTfCpuDriver.inf
 create mode 100644 StandaloneMmPkg/Drivers/CpuMm/Arm/StateSave.c
 create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h

diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S 
b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
new file mode 100644
index 00..0b6e1c330d
--- /dev/null
+++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/Entry.S
@@ -0,0 +1,33 @@
+//
+//  Copyright (c) 2017, 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 
+
+.text
+.align 3
+
+GCC_ASM_IMPORT(PiMmStandloneArmTfCpuDriverEntry)
+GCC_ASM_EXPORT(_PiMmStandloneArmTfCpuDriverEntry)
+
+// Stub entry point to ensure that the stacks are completely unwound before
+// signalling completion of event handling
+ASM_PFX(_PiMmStandloneArmTfCpuDriverEntry):
+  blPiMmStandloneArmTfCpuDriverEntry
+  mov   x1, x0
+  mov   x0, #(ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 & 0x)
+  movk  x0, #((ARM_SMC_ID_MM_EVENT_COMPLETE_AARCH64 >> 16) & 0x), lsl #16
+  svc   #0
+LoopForever:
+  b LoopForever
diff --git a/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c 
b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
new file mode 100644
index 00..7b19f53ecb
--- /dev/null
+++ b/StandaloneMmPkg/Drivers/CpuMm/Arm/EventHandle.c
@@ -0,0 +1,231 @@
+/** @file
+
+  Copyright (c) 2016 HP Development Company, L.P.
+  Copyright (c) 2016 - 2017, 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 "PiMmStandloneArmTfCpuDriver.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;
+
+//
+// When an event is received by the CPU driver, it could correspond to a unique
+// GUID (e.g. interrupt events) or to multiple GUIDs (e.g. MM_COMMUNICATE
+// SMC). A table is used by the CPU driver to find the GUID corresponding to 
the
+// event id in case there is a 1:1 mapping between the two. If an event id has
+// multiple GUIDs associated with it then such an entry will not be found in