From patchwork Thu Aug 28 14:14:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36224 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 137EA202DD for ; Thu, 28 Aug 2014 14:15:14 +0000 (UTC) Received: by mail-oi0-f72.google.com with SMTP id e131sf5662668oig.3 for ; Thu, 28 Aug 2014 07:15:13 -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: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=mcBMNTpFn7T00Q4b1FNgFvdsCE/BGJFrOcVgsvdliGE=; b=jy9rcPk6/6EBjYgnbIrenYOdRMuhAlTBTEWN+rS6P+z2iWM0w/un6CN8yWa1oe9pQc bsOYLM1CQqXZMjWu1Wx1GmmbzKEF2NggLlv/xH3tCQQ1SLnpBusf0EO7DCiGnKNVtyFu IEsN1CPX1a9K5e4S9r1Z5wLbvbzdG5cgYDVvDz32UGgsXQf1qsGRnRFXXu/o7KTHDOCr edNo2l3B3faRl7RF/OwIiYE5UgdIwiW7uRDTale4+Nx1DfJkLnYJ8MbdAz61WYs00Mxh 2Ln+33jjKEWVGD3R+EvU2YD+22cJ4pBsRDM9CrbIPdzPuHqqVgyoUX2gGXXBykh9gyqn ZSIQ== X-Gm-Message-State: ALoCoQm0EjL69Y4l6tJZh1s2zu5nMgeD119rmsa55NComDuEq37FgAD14kwxd1ZuCWrmdsGuqRRd X-Received: by 10.43.28.197 with SMTP id rv5mr2858297icb.23.1409235313689; Thu, 28 Aug 2014 07:15:13 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.168 with SMTP id p37ls528425qgp.12.gmail; Thu, 28 Aug 2014 07:15:13 -0700 (PDT) X-Received: by 10.220.46.5 with SMTP id h5mr942995vcf.55.1409235313556; Thu, 28 Aug 2014 07:15:13 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id bx5si3586860vcb.24.2014.08.28.07.15.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:15:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ij19so871516vcb.12 for ; Thu, 28 Aug 2014 07:15:13 -0700 (PDT) X-Received: by 10.52.3.40 with SMTP id 8mr2895677vdz.24.1409235313451; Thu, 28 Aug 2014 07:15:13 -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 uj3csp243538vcb; Thu, 28 Aug 2014 07:15:12 -0700 (PDT) X-Received: by 10.43.140.4 with SMTP id iy4mr4768873icc.23.1409235312736; Thu, 28 Aug 2014 07:15:12 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id vt3si4224985igc.43.2014.08.28.07.15.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:15:12 -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-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XN0Tg-0002xG-2S; Thu, 28 Aug 2014 14:15:04 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XN0Te-0002wb-Dt for edk2-devel@lists.sourceforge.net; Thu, 28 Aug 2014 14:15:02 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.171 as permitted sender) client-ip=209.85.212.171; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f171.google.com; Received: from mail-wi0-f171.google.com ([209.85.212.171]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XN0TW-0000pW-HE for edk2-devel@lists.sourceforge.net; Thu, 28 Aug 2014 14:15:00 +0000 Received: by mail-wi0-f171.google.com with SMTP id hi2so7555855wib.4 for ; Thu, 28 Aug 2014 07:14:47 -0700 (PDT) X-Received: by 10.194.187.101 with SMTP id fr5mr5823630wjc.10.1409235287867; Thu, 28 Aug 2014 07:14:47 -0700 (PDT) Received: from ards-macbook-pro.local (BSN-61-108-214.dial-up.dsl.siol.net. [86.61.108.214]) by mx.google.com with ESMTPSA id bk6sm10278657wjb.26.2014.08.28.07.14.44 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:14:47 -0700 (PDT) From: Ard Biesheuvel To: lersek@redhat.com, olivier.martin@arm.com, edk2-devel@lists.sourceforge.net, peter.maydell@linaro.org, christoffer.dall@linaro.org, drjones@redhat.com, ilias.biris@linaro.org, leif.lindholm@linaro.org Date: Thu, 28 Aug 2014 16:14:02 +0200 Message-Id: <1409235244-25783-15-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409235244-25783-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409235244-25783-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: 1XN0TW-0000pW-HE Subject: [edk2] [PATCH v4 14/16] ArmVirtualizationPkg: add ResetSystemLib library 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.181 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 adds an implementation of EfiResetSystemLib that uses PSCI hypervisor calls to reboot and/or shutdown the system. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Casadevall Acked-by: Laszlo Ersek Signed-off-by: Ard Biesheuvel --- .../ResetSystemLib/AARCH64/ResetSystemPsci.S | 40 +++++++++ .../Library/ResetSystemLib/ARM/ResetSystemPsci.S | 41 +++++++++ .../Library/ResetSystemLib/ResetSystemLib.c | 97 ++++++++++++++++++++++ .../Library/ResetSystemLib/ResetSystemLib.inf | 41 +++++++++ 4 files changed, 219 insertions(+) create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/AARCH64/ResetSystemPsci.S create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ARM/ResetSystemPsci.S create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.inf diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/AARCH64/ResetSystemPsci.S b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/AARCH64/ResetSystemPsci.S new file mode 100644 index 000000000000..988b0fdc41e4 --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/AARCH64/ResetSystemPsci.S @@ -0,0 +1,40 @@ +/** @file + Support ResetSystem Runtime call using PSCI hvc calls + + 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 + +#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) + +.text +.align 2 + +GCC_ASM_EXPORT(ArmPsciSystemOff) +GCC_ASM_EXPORT(ArmPsciSystemReset) + +ASM_PFX(ArmPsciSystemOff): + ldr w0, =PSCI_0_2_FN_SYSTEM_OFF + hvc #0 + ret + +ASM_PFX(ArmPsciSystemReset): + ldr w0, =PSCI_0_2_FN_SYSTEM_RESET + hvc #0 + ret diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ARM/ResetSystemPsci.S b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ARM/ResetSystemPsci.S new file mode 100644 index 000000000000..9e126c6627a7 --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ARM/ResetSystemPsci.S @@ -0,0 +1,41 @@ +/** @file + Support ResetSystem Runtime call using PSCI hvc calls + + 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 + +#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) + +.text +.align 2 +.arch_extension virt + +GCC_ASM_EXPORT(ArmPsciSystemOff) +GCC_ASM_EXPORT(ArmPsciSystemReset) + +ASM_PFX(ArmPsciSystemOff): + ldr r0, =PSCI_0_2_FN_SYSTEM_OFF + hvc #0 + bx lr + +ASM_PFX(ArmPsciSystemReset): + ldr r0, =PSCI_0_2_FN_SYSTEM_RESET + hvc #0 + bx lr diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.c new file mode 100644 index 000000000000..a420591a8e9c --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.c @@ -0,0 +1,97 @@ +/** @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 + +VOID +ArmPsciSystemReset ( + VOID + ); + +VOID +ArmPsciSystemOff ( + VOID + ); + +/** + 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 + ) +{ + 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 + ArmPsciSystemReset (); + break; + case EfiResetShutdown: + // Send a PSCI 0.2 SYSTEM_OFF command + ArmPsciSystemOff (); + break; + + default: + ASSERT (FALSE); + 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/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 000000000000..e50c134620b7 --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ResetSystemLib/ResetSystemLib.inf @@ -0,0 +1,41 @@ +#/** @file +# Reset System lib to make it easy to port new platforms +# +# Copyright (c) 2008, Apple Inc. 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 = ResetSystemLib + FILE_GUID = DC9CCFDD-2638-474B-8F5D-031B758C12FC + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = EfiResetSystemLib + +[Sources.common] + ResetSystemLib.c + +[Sources.AARCH64] + AARCH64/ResetSystemPsci.S | GCC + +[Sources.ARM] + ARM/ResetSystemPsci.S | GCC + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + IoLib + DebugLib + BaseLib