[edk2] [PATCH 02/10] Platform/NXP: Add support for system reset library

Meenakshi Aggarwal posted 10 patches 8 years, 3 months ago
[edk2] [PATCH 02/10] Platform/NXP: Add support for system reset library
Posted by Meenakshi Aggarwal 8 years, 3 months ago
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
---
 .../NXP/Library/ResetSystemLib/ResetSystemLib.c    | 96 ++++++++++++++++++++++
 .../NXP/Library/ResetSystemLib/ResetSystemLib.inf  | 33 ++++++++
 2 files changed, 129 insertions(+)
 create mode 100644 Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
 create mode 100644 Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf

diff --git a/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
new file mode 100644
index 0000000..897324a
--- /dev/null
+++ b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
@@ -0,0 +1,96 @@
+/** ResetSystemLib.c
+  Do a generic Cold Reset
+
+  Based on Reset system library implementation in
+  BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c
+
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
+  Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
+  Copyright 2017 NXP
+
+  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 <Uefi.h>
+#include <IndustryStandard/ArmStdSmc.h>
+#include <Library/ArmLib.h>
+#include <Library/ArmSmcLib.h>
+#include <Library/CacheMaintenanceLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/IoLib.h>
+#include <Library/UefiLib.h>
+
+/**
+  Resets the entire platform.
+
+  @param  ResetType     :     The type of reset to perform.
+  @param  ResetStatus   :     The status code for the reset.
+  @param  DataSize      :     The size, in bytes, of WatchdogData.
+  @param  ResetData     :     For a ResetType of EfiResetCold, EfiResetWarm, or
+                              EfiResetShutdown the data buffer starts with a Null-terminated
+                              Unicode string, optionally followed by additional binary data.
+**/
+EFI_STATUS
+EFIAPI
+LibResetSystem (
+  IN EFI_RESET_TYPE   ResetType,
+  IN EFI_STATUS       ResetStatus,
+  IN UINTN            DataSize,
+  IN CHAR16           *ResetData OPTIONAL
+  )
+{
+  ARM_SMC_ARGS ArmSmcArgs;
+
+  switch (ResetType) {
+  case EfiResetPlatformSpecific:
+  case EfiResetWarm:
+    // Map a warm reset into a cold reset
+  case EfiResetCold:
+    // Send a PSCI 0.2 SYSTEM_RESET command
+    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
+    break;
+  case EfiResetShutdown:
+    // Send a PSCI 0.2 SYSTEM_OFF command
+    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
+    break;
+  default:
+    ASSERT (FALSE);
+    return EFI_UNSUPPORTED;
+  }
+
+  ArmCallSmc (&ArmSmcArgs);
+
+  // We should never be here
+  DEBUG ((DEBUG_VERBOSE, "%a: PSCI failed in performing %d\n",
+                            __FUNCTION__, ArmSmcArgs.Arg0));
+
+  CpuDeadLoop ();
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Initialize any infrastructure required for LibResetSystem () to function.
+
+  @param  ImageHandle  :  The firmware allocated handle for the EFI image.
+  @param  SystemTable  :  A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS  :  The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+LibInitializeResetSystem (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return EFI_SUCCESS;
+}
diff --git a/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
new file mode 100644
index 0000000..c57fff8
--- /dev/null
+++ b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
@@ -0,0 +1,33 @@
+#  @ResetSystemLib.inf
+#  Reset System lib to make it easy to port new platforms
+#
+#  Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
+#  Copyright 2017 NXP
+#
+#  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.
+#
+#
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = ResetSystemLib
+  FILE_GUID                      = 781371a2-3fdd-41d4-96a1-7b34cbc9e895
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = EfiResetSystemLib
+
+[Sources.common]
+  ResetSystemLib.c
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  ArmSmcLib
+  BaseLib
-- 
1.9.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 02/10] Platform/NXP: Add support for system reset library
Posted by Ard Biesheuvel 8 years, 2 months ago
On 7 November 2017 at 14:42, Meenakshi Aggarwal
<meenakshi.aggarwal@nxp.com> wrote:
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> ---
>  .../NXP/Library/ResetSystemLib/ResetSystemLib.c    | 96 ++++++++++++++++++++++
>  .../NXP/Library/ResetSystemLib/ResetSystemLib.inf  | 33 ++++++++
>  2 files changed, 129 insertions(+)
>  create mode 100644 Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
>  create mode 100644 Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
>

Please drop this patch, and move your platform to
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf,
using ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
as your ResetSystemLib implementation.

> diff --git a/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
> new file mode 100644
> index 0000000..897324a
> --- /dev/null
> +++ b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
> @@ -0,0 +1,96 @@
> +/** ResetSystemLib.c
> +  Do a generic Cold Reset
> +
> +  Based on Reset system library implementation in
> +  BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c
> +
> +  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
> +  Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
> +  Copyright 2017 NXP
> +
> +  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 <Uefi.h>
> +#include <IndustryStandard/ArmStdSmc.h>
> +#include <Library/ArmLib.h>
> +#include <Library/ArmSmcLib.h>
> +#include <Library/CacheMaintenanceLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/UefiLib.h>
> +
> +/**
> +  Resets the entire platform.
> +
> +  @param  ResetType     :     The type of reset to perform.
> +  @param  ResetStatus   :     The status code for the reset.
> +  @param  DataSize      :     The size, in bytes, of WatchdogData.
> +  @param  ResetData     :     For a ResetType of EfiResetCold, EfiResetWarm, or
> +                              EfiResetShutdown the data buffer starts with a Null-terminated
> +                              Unicode string, optionally followed by additional binary data.
> +**/
> +EFI_STATUS
> +EFIAPI
> +LibResetSystem (
> +  IN EFI_RESET_TYPE   ResetType,
> +  IN EFI_STATUS       ResetStatus,
> +  IN UINTN            DataSize,
> +  IN CHAR16           *ResetData OPTIONAL
> +  )
> +{
> +  ARM_SMC_ARGS ArmSmcArgs;
> +
> +  switch (ResetType) {
> +  case EfiResetPlatformSpecific:
> +  case EfiResetWarm:
> +    // Map a warm reset into a cold reset
> +  case EfiResetCold:
> +    // Send a PSCI 0.2 SYSTEM_RESET command
> +    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
> +    break;
> +  case EfiResetShutdown:
> +    // Send a PSCI 0.2 SYSTEM_OFF command
> +    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
> +    break;
> +  default:
> +    ASSERT (FALSE);
> +    return EFI_UNSUPPORTED;
> +  }
> +
> +  ArmCallSmc (&ArmSmcArgs);
> +
> +  // We should never be here
> +  DEBUG ((DEBUG_VERBOSE, "%a: PSCI failed in performing %d\n",
> +                            __FUNCTION__, ArmSmcArgs.Arg0));
> +
> +  CpuDeadLoop ();
> +  return EFI_UNSUPPORTED;
> +}
> +
> +/**
> +  Initialize any infrastructure required for LibResetSystem () to function.
> +
> +  @param  ImageHandle  :  The firmware allocated handle for the EFI image.
> +  @param  SystemTable  :  A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS  :  The constructor always returns EFI_SUCCESS.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +LibInitializeResetSystem (
> +  IN EFI_HANDLE        ImageHandle,
> +  IN EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  return EFI_SUCCESS;
> +}
> diff --git a/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
> new file mode 100644
> index 0000000..c57fff8
> --- /dev/null
> +++ b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
> @@ -0,0 +1,33 @@
> +#  @ResetSystemLib.inf
> +#  Reset System lib to make it easy to port new platforms
> +#
> +#  Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
> +#  Copyright 2017 NXP
> +#
> +#  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.
> +#
> +#
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = ResetSystemLib
> +  FILE_GUID                      = 781371a2-3fdd-41d4-96a1-7b34cbc9e895
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = EfiResetSystemLib
> +
> +[Sources.common]
> +  ResetSystemLib.c
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  MdePkg/MdePkg.dec
> +
> +[LibraryClasses]
> +  ArmSmcLib
> +  BaseLib
> --
> 1.9.1
>
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 02/10] Platform/NXP: Add support for system reset library
Posted by Meenakshi Aggarwal 8 years, 2 months ago

> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Monday, November 13, 2017 5:40 PM
> To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> Cc: Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D
> <michael.d.kinney@intel.com>; edk2-devel@lists.01.org; Udit Kumar
> <udit.kumar@nxp.com>; Varun Sethi <V.Sethi@nxp.com>
> Subject: Re: [PATCH 02/10] Platform/NXP: Add support for system reset
> library
> 
> On 7 November 2017 at 14:42, Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com> wrote:
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > ---
> >  .../NXP/Library/ResetSystemLib/ResetSystemLib.c    | 96
> ++++++++++++++++++++++
> >  .../NXP/Library/ResetSystemLib/ResetSystemLib.inf  | 33 ++++++++
> >  2 files changed, 129 insertions(+)
> >  create mode 100644
> > Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
> >  create mode 100644
> > Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
> >
> 
> Please drop this patch, and move your platform to
> MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntime
> Dxe.inf,
> using
> ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
> as your ResetSystemLib implementation.
> 
OK, we will use same as both are based on PSCI calls.

> > diff --git a/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
> > b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
> > new file mode 100644
> > index 0000000..897324a
> > --- /dev/null
> > +++ b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.c
> > @@ -0,0 +1,96 @@
> > +/** ResetSystemLib.c
> > +  Do a generic Cold Reset
> > +
> > +  Based on Reset system library implementation in
> > + BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c
> > +
> > +  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
> > + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
> > +  Copyright 2017 NXP
> > +
> > +  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
> > +
> > +
> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fop
> > + ensource.org%2Flicenses%2Fbsd-
> license.php&data=02%7C01%7Cmeenakshi.a
> > +
> ggarwal%40nxp.com%7C61e0e75526184abb5c3908d52a8f70f9%7C686ea1d3b
> c2b4
> > +
> c6fa92cd99c5c301635%7C0%7C0%7C636461717926249509&sdata=ofvOybKAa
> 64hI
> > + kl0oZuRk0p%2FopCIE0ueBk8yW5OkscQ%3D&reserved=0
> > +
> > +  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 <Uefi.h>
> > +#include <IndustryStandard/ArmStdSmc.h> #include <Library/ArmLib.h>
> > +#include <Library/ArmSmcLib.h> #include
> > +<Library/CacheMaintenanceLib.h> #include <Library/DebugLib.h>
> > +#include <Library/MemoryAllocationLib.h> #include <Library/IoLib.h>
> > +#include <Library/UefiLib.h>
> > +
> > +/**
> > +  Resets the entire platform.
> > +
> > +  @param  ResetType     :     The type of reset to perform.
> > +  @param  ResetStatus   :     The status code for the reset.
> > +  @param  DataSize      :     The size, in bytes, of WatchdogData.
> > +  @param  ResetData     :     For a ResetType of EfiResetCold,
> EfiResetWarm, or
> > +                              EfiResetShutdown the data buffer starts with a Null-
> terminated
> > +                              Unicode string, optionally followed by additional binary
> data.
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +LibResetSystem (
> > +  IN EFI_RESET_TYPE   ResetType,
> > +  IN EFI_STATUS       ResetStatus,
> > +  IN UINTN            DataSize,
> > +  IN CHAR16           *ResetData OPTIONAL
> > +  )
> > +{
> > +  ARM_SMC_ARGS ArmSmcArgs;
> > +
> > +  switch (ResetType) {
> > +  case EfiResetPlatformSpecific:
> > +  case EfiResetWarm:
> > +    // Map a warm reset into a cold reset  case EfiResetCold:
> > +    // Send a PSCI 0.2 SYSTEM_RESET command
> > +    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
> > +    break;
> > +  case EfiResetShutdown:
> > +    // Send a PSCI 0.2 SYSTEM_OFF command
> > +    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
> > +    break;
> > +  default:
> > +    ASSERT (FALSE);
> > +    return EFI_UNSUPPORTED;
> > +  }
> > +
> > +  ArmCallSmc (&ArmSmcArgs);
> > +
> > +  // We should never be here
> > +  DEBUG ((DEBUG_VERBOSE, "%a: PSCI failed in performing %d\n",
> > +                            __FUNCTION__, ArmSmcArgs.Arg0));
> > +
> > +  CpuDeadLoop ();
> > +  return EFI_UNSUPPORTED;
> > +}
> > +
> > +/**
> > +  Initialize any infrastructure required for LibResetSystem () to function.
> > +
> > +  @param  ImageHandle  :  The firmware allocated handle for the EFI
> image.
> > +  @param  SystemTable  :  A pointer to the EFI System Table.
> > +
> > +  @retval EFI_SUCCESS  :  The constructor always returns EFI_SUCCESS.
> > +
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +LibInitializeResetSystem (
> > +  IN EFI_HANDLE        ImageHandle,
> > +  IN EFI_SYSTEM_TABLE  *SystemTable
> > +  )
> > +{
> > +  return EFI_SUCCESS;
> > +}
> > diff --git a/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
> > b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
> > new file mode 100644
> > index 0000000..c57fff8
> > --- /dev/null
> > +++ b/Platform/NXP/Library/ResetSystemLib/ResetSystemLib.inf
> > @@ -0,0 +1,33 @@
> > +#  @ResetSystemLib.inf
> > +#  Reset System lib to make it easy to port new platforms # #
> > +Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
> > +#  Copyright 2017 NXP
> > +#
> > +#  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 #
> >
> +https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fop
> e
> > +nsource.org%2Flicenses%2Fbsd-
> license.php&data=02%7C01%7Cmeenakshi.agg
> >
> +arwal%40nxp.com%7C61e0e75526184abb5c3908d52a8f70f9%7C686ea1d3bc
> 2b4c6f
> >
> +a92cd99c5c301635%7C0%7C0%7C636461717926249509&sdata=ofvOybKAa64
> hIkl0o
> > +ZuRk0p%2FopCIE0ueBk8yW5OkscQ%3D&reserved=0
> > +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > +BASIS, #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR IMPLIED.
> > +#
> > +#
> > +
> > +[Defines]
> > +  INF_VERSION                    = 0x00010005
> > +  BASE_NAME                      = ResetSystemLib
> > +  FILE_GUID                      = 781371a2-3fdd-41d4-96a1-7b34cbc9e895
> > +  MODULE_TYPE                    = BASE
> > +  VERSION_STRING                 = 1.0
> > +  LIBRARY_CLASS                  = EfiResetSystemLib
> > +
> > +[Sources.common]
> > +  ResetSystemLib.c
> > +
> > +[Packages]
> > +  ArmPkg/ArmPkg.dec
> > +  MdePkg/MdePkg.dec
> > +
> > +[LibraryClasses]
> > +  ArmSmcLib
> > +  BaseLib
> > --
> > 1.9.1
> >
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel