From patchwork Tue Feb 16 15:49:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 8328461 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 708EFC02AA for ; Tue, 16 Feb 2016 15:51:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94860202B8 for ; Tue, 16 Feb 2016 15:51:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ACB26202A1 for ; Tue, 16 Feb 2016 15:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755429AbcBPPve (ORCPT ); Tue, 16 Feb 2016 10:51:34 -0500 Received: from foss.arm.com ([217.140.101.70]:54462 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755420AbcBPPvd (ORCPT ); Tue, 16 Feb 2016 10:51:33 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4BF5F3A1; Tue, 16 Feb 2016 07:50:43 -0800 (PST) Received: from melchizedek.cambridge.arm.com (melchizedek.cambridge.arm.com [10.1.209.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D36D83F213; Tue, 16 Feb 2016 07:51:30 -0800 (PST) From: James Morse To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Sudeep Holla , Geoff Levand , Catalin Marinas , Lorenzo Pieralisi , Mark Rutland , AKASHI Takahiro , Marc Zyngier , "Rafael J . Wysocki" , Pavel Machek , linux-pm@vger.kernel.org, James Morse Subject: [PATCH v5 04/15] arm64: Add new hcall HVC_CALL_FUNC Date: Tue, 16 Feb 2016 15:49:16 +0000 Message-Id: <1455637767-31561-5-git-send-email-james.morse@arm.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1455637767-31561-1-git-send-email-james.morse@arm.com> References: <1455637767-31561-1-git-send-email-james.morse@arm.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Geoff Levand Add the new hcall HVC_CALL_FUNC that allows execution of a function at EL2. During CPU reset the CPU must be brought to the exception level it had on entry to the kernel. The HVC_CALL_FUNC hcall will provide the mechanism needed for this exception level switch. To allow the HVC_CALL_FUNC exception vector to work without a stack, which is needed to support an hcall at CPU reset, this implementation uses register x18 to store the link register across the caller provided function. This dictates that the caller provided function must preserve the contents of register x18. Signed-off-by: Geoff Levand [Renumbered labels in el1_sync()] Signed-off-by: James Morse --- This patch comes from v13 of kexec arch/arm64/include/asm/virt.h | 13 +++++++++++++ arch/arm64/kernel/hyp-stub.S | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index eb10368c329e..30700961f28c 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -45,6 +45,19 @@ #define HVC_SET_VECTORS 2 +/* + * HVC_CALL_FUNC - Execute a function at EL2. + * + * @x0: Physical address of the function to be executed. + * @x1: Passed as the first argument to the function. + * @x2: Passed as the second argument to the function. + * @x3: Passed as the third argument to the function. + * + * The called function must preserve the contents of register x18. + */ + +#define HVC_CALL_FUNC 3 + #define BOOT_CPU_MODE_EL1 (0xe11) #define BOOT_CPU_MODE_EL2 (0xe12) diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S index 017ab519aaf1..cfacfe55e3ef 100644 --- a/arch/arm64/kernel/hyp-stub.S +++ b/arch/arm64/kernel/hyp-stub.S @@ -59,18 +59,29 @@ el1_sync: and x18, x18, #ESR_ELx_ISS_MASK cmp x17, #ESR_ELx_EC_HVC64 - b.ne 2f // Not an HVC trap + b.ne 9f // Not an HVC trap cmp x18, #HVC_GET_VECTORS b.ne 1f mrs x0, vbar_el2 - b 2f + b 9f 1: cmp x18, #HVC_SET_VECTORS b.ne 2f msr vbar_el2, x0 - -2: eret + b 9f + +2: cmp x18, #HVC_CALL_FUNC + b.ne 9f + mov x18, lr + mov lr, x0 + mov x0, x1 + mov x1, x2 + mov x2, x3 + blr lr + mov lr, x18 + +9: eret ENDPROC(el1_sync) .macro invalid_vector label