From patchwork Wed Sep 3 11:17:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36566 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D0FF6202E4 for ; Wed, 3 Sep 2014 11:18:50 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id ft15sf5275684pdb.2 for ; Wed, 03 Sep 2014 04:18:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=tZMYJlQt4EQ9LVreK+6Ho0zosawlYuIdWItbcAMvvK8=; b=M9DqB0QyDbuCGpwLLCyf9wvtHdwtiJvct+73zjil3lmaWuscaHXGhlUIlQjbot+uFe yoY2IMuIZWQMantbeU0xrkXz3qkHxO8jPWNXWL+e8TNhQJGALCuE0gCEQFSiLrK03gac RJ2fJwPxJ8f4Qlo2QTzrEwYBgGEN4UsyOc01G5zBwRVsASp6WyVGZpEcpl/5FY+blPi2 xCOSwxTavaINiRRWGy80Pix1b0CA1xJiVx4AvVghNPpJDJfi1poY5r2pX6xHT1Snb8+b pOJKVTgwlPIR7Otq5uKnV5rKm+YJ/FHlV4lp8+d6+SPM7TTZfx57xj0w9vkLre9/8KZO MWbQ== X-Gm-Message-State: ALoCoQlvZOp+s5Nv/3mIZh0KPBj14AiEzbI4ZmtnjNbOprdj1j90ax7CW5Pu95vpjC81ujhroDyZ X-Received: by 10.66.162.162 with SMTP id yb2mr21722202pab.39.1409743127850; Wed, 03 Sep 2014 04:18:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.87 with SMTP id b81ls2735280qga.19.gmail; Wed, 03 Sep 2014 04:18:47 -0700 (PDT) X-Received: by 10.220.127.17 with SMTP id e17mr37488vcs.56.1409743127731; Wed, 03 Sep 2014 04:18:47 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id g8si695384vdu.82.2014.09.03.04.18.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lf12so8467083vcb.20 for ; Wed, 03 Sep 2014 04:18:47 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr29129916vdb.27.1409743127597; Wed, 03 Sep 2014 04:18:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp663939vcb; Wed, 3 Sep 2014 04:18:47 -0700 (PDT) X-Received: by 10.50.25.105 with SMTP id b9mr35473191igg.46.1409743126418; Wed, 03 Sep 2014 04:18:46 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id fz4si10293284icb.65.2014.09.03.04.18.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:46 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XP8aE-000886-JC; Wed, 03 Sep 2014 11:18:38 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XP8aD-00087w-Ib for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:37 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.170 as permitted sender) client-ip=74.125.82.170; envelope-from=ard.biesheuvel@linaro.org; helo=mail-we0-f170.google.com; Received: from mail-we0-f170.google.com ([74.125.82.170]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XP8aC-0005PF-9P for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:37 +0000 Received: by mail-we0-f170.google.com with SMTP id p10so8405292wes.1 for ; Wed, 03 Sep 2014 04:18:29 -0700 (PDT) X-Received: by 10.180.187.144 with SMTP id fs16mr12306455wic.75.1409743109255; Wed, 03 Sep 2014 04:18:29 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id p1sm15258661wjy.22.2014.09.03.04.18.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:28 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com Date: Wed, 3 Sep 2014 13:17:57 +0200 Message-Id: <1409743096-14919-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409743096-14919-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409743096-14919-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1XP8aC-0005PF-9P Cc: peter.maydell@linaro.org, ilias.biris@linaro.org, christoffer.dall@linaro.org Subject: [edk2] [PATCH v6 04/23] ArmPkg: add ArmPsciResetSystemLib X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This implementation of EfiResetSystemLib uses ARM PSCI calls to perform reboot and poweroff, using either HVC or SMC calls. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/ArmPkg.dec | 8 ++ .../ArmPsciResetSystemLib/ArmPsciResetSystemLib.c | 114 +++++++++++++++++++++ .../ArmPsciResetSystemLib.inf | 41 ++++++++ 3 files changed, 163 insertions(+) create mode 100644 ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.c create mode 100644 ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 45c10cad76d7..e9b33b63343a 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -151,6 +151,14 @@ gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|26|UINT32|0x00000040 gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|27|UINT32|0x00000041 + # + # ARM PSCI function invocations can be done either through hypervisor + # calls (HVC) or secure monitor calls (SMC). + # PcdArmPsciMethod == 1 : use HVC + # PcdArmPsciMethod == 2 : use SMC + # + gArmTokenSpaceGuid.PcdArmPsciMethod|0|UINT32|0x00000042 + [PcdsFixedAtBuild.ARM] # # ARM Security Extension diff --git a/ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.c b/ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.c new file mode 100644 index 000000000000..b9409328a18a --- /dev/null +++ b/ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.c @@ -0,0 +1,114 @@ +/** @file + Support ResetSystem Runtime call using PSCI hvc calls + + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+ Copyright (c) 2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2014, Linaro Ltd. 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 + +#define PSCI_0_2_FN_BASE 0x84000000 +#define PSCI_0_2_FN(n) (PSCI_0_2_FN_BASE + (n)) +#define PSCI_0_2_FN_SYSTEM_OFF PSCI_0_2_FN(8) +#define PSCI_0_2_FN_SYSTEM_RESET PSCI_0_2_FN(9) + +/** + 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; + ARM_HVC_ARGS ArmHvcArgs; + + switch (ResetType) { + + case EfiResetPlatformSpecific: + // Map the platform specific reset as reboot + case EfiResetWarm: + // Map a warm reset into a cold reset + case EfiResetCold: + // Send a PSCI 0.2 SYSTEM_RESET command + ArmSmcArgs.Arg0 = PSCI_0_2_FN_SYSTEM_RESET; + ArmHvcArgs.Arg0 = PSCI_0_2_FN_SYSTEM_RESET; + break; + case EfiResetShutdown: + // Send a PSCI 0.2 SYSTEM_OFF command + ArmSmcArgs.Arg0 = PSCI_0_2_FN_SYSTEM_OFF; + ArmHvcArgs.Arg0 = PSCI_0_2_FN_SYSTEM_OFF; + break; + + default: + ASSERT (FALSE); + return EFI_UNSUPPORTED; + } + + switch (PcdGet32 (PcdArmPsciMethod)) { + + case 1: + ArmCallHvc (&ArmHvcArgs); + break; + + case 2: + ArmCallSmc (&ArmSmcArgs); + break; + + default: + DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + // We should never be here + DEBUG ((EFI_D_ERROR, "%a: PSCI Reset failed\n", __FUNCTION__)); + 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/ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf b/ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf new file mode 100644 index 000000000000..ee690d1360b7 --- /dev/null +++ b/ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf @@ -0,0 +1,41 @@ +#/** @file +# Reset System lib using PSCI hypervisor or secure monitor calls +# +# Copyright (c) 2008, Apple Inc. All rights reserved.
+# Copyright (c) 2014, Linaro Ltd. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ArmPsciResetSystemLib + FILE_GUID = A8F59B69-A105-41C7-8F5A-2C60DD7FD7AA + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = EfiResetSystemLib + +[Sources] + ArmPsciResetSystemLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + IoLib + DebugLib + BaseLib + ArmSmcLib + ArmHvcLib + +[Pcd] + gArmTokenSpaceGuid.PcdArmPsciMethod