From patchwork Mon Aug 21 20:27:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9913701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 66256602A0 for ; Mon, 21 Aug 2017 20:31:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 593A128813 for ; Mon, 21 Aug 2017 20:31:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D3921FE8D; Mon, 21 Aug 2017 20:31:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3772627F85 for ; Mon, 21 Aug 2017 20:31:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djtKB-0003x3-U2; Mon, 21 Aug 2017 20:29:27 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djtKA-0003vq-DK for xen-devel@lists.xen.org; Mon, 21 Aug 2017 20:29:26 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id C8/60-03937-5A24B995; Mon, 21 Aug 2017 20:29:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCKsWRWlGSWpSXmKPExsWSoc/krbvEaXa kwd5ORYslHxezODB6HN39mymAMYo1My8pvyKBNePJi38sBV+qKrZffMHawDg5vouRi4NFoJFZ 4s/9D8xdjJwcjAIxEpu2dDKCJIQEJjJJbLjymwkkISSQLPHu4iswm03ARGLd/PPsILaIgLTEt c+XwRqYBXYySizY8o0FJCEs4C7RemQWK4jNIqAq0Tx9A1icV8BL4nPbIjBbQkBO4ua5TrDNnA LeEmf3tDFCLPOS+PZnL1S9oMTJmU/AbGYBCYmDL14wQ/QqShz4PZMZZLGEwExGiTsXIRYLCah L7P39BqpIVuLo2TlQy3wlpmzdxg7RcJVJ4sLVKUwQTjO7xOnvK9ghqnQkerq/MEIkJrNLHLy0 mQki4Skxq2MSlF0gcamhH2rUDVaJl5NmQu2QkfizfD5U92pWiXtzd0B9lCDx7v9vqH23eSS+/ tgP5XSyS3xadJ9tAqPaLCTvzkLy7gJGplWMGsWpRWWpRbpGlnpJRZnpGSW5iZk5uoYGZnq5qc XFiempOYlJxXrJ+bmbGIGpgQEIdjAeWBR4iFGSg0lJlHdD6qxIIb6k/JTKjMTijPii0pzU4kO MMhwcShK8jo6zI4UEi1LTUyvSMnOASQomLcHBoyTC2wiS5i0uSMwtzkyHSJ1iVJQS53UGSQiA JDJK8+DaYInxEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5d4JM4cnMK4Gb/gpoMRPQYsPWa SCLSxIRUlINjPsP3zg0QZJJZLd7zXm52myHBwylKS67byvt08gX25pb53lwj29fX+MDiWWXlV +n/P65eVVZ+Yz6p64fGC586z55+FJYiYmWX++uikwVDfO/5ZcOsLqY3vi+6AU708WNX/PO71g pxCx3+gb/Hr9fDe/lr8y+bii09bKy65+V+tueOfnlGvGev6HEUpyRaKjFXFScCAB5RLalhwMA AA== X-Env-Sender: Volodymyr_Babchuk@epam.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1503347364!70907515!1 X-Originating-IP: [104.47.2.75] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3919 invoked from network); 21 Aug 2017 20:29:24 -0000 Received: from mail-db5eur01on0075.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (104.47.2.75) by server-5.tower-21.messagelabs.com with AES256-SHA256 encrypted SMTP; 21 Aug 2017 20:29:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=EPAM.onmicrosoft.com; s=selector1-epam-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=jBMB73i7/tWWdZZKPr6VGGNThLneP4jYhgcq4AmYNFs=; b=Q0ZviHSW87h3co0YdLLSFwyrb6KqGOAQPUVw0MwXEszbihU+QYjdghSEp6hYYN3fnbGnw1rMnkcy58gNu0jQLTw1+esu/3v054e3H3ooToNykGCfHK4CPe/O8NFSVb8cYk3NA40UqpfX7++Qn0yIjHNlsz5Ek4m12lnk9wcFltU= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.58) by VI1PR0301MB2144.eurprd03.prod.outlook.com (2603:10a6:800:26::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1362.18; Mon, 21 Aug 2017 20:29:21 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Mon, 21 Aug 2017 23:29:18 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Mon, 21 Aug 2017 23:27:51 +0300 Message-Id: <1503347275-13039-8-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503347275-13039-1-git-send-email-volodymyr_babchuk@epam.com> References: <1503347275-13039-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.58] X-ClientProxiedBy: AM5PR0402CA0005.eurprd04.prod.outlook.com (2603:10a6:203:90::15) To VI1PR0301MB2144.eurprd03.prod.outlook.com (2603:10a6:800:26::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ba39610b-d5b5-4e8e-00e9-08d4e8d34e92 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:VI1PR0301MB2144; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0301MB2144; 3:SKvYkhHsDdmenZs6zEW0BYk/afGNHDqwUtuaQk83ddl1U8EXFDCq2ChnGj/4Pcx9o6SelHEaUecv9AzPUE7hgGOGmDRuMdtqT0vMrIPo37LR/aAROS2z2Tx+85d5zMHWIv3kcQuDUxYFR2qq6dEKqmdXLuTLsFOsicj0K55c21XW7IbIBIRaob1oV/5aJ00/eUq4/Kq3S4ufn86YsKZc08IkuxnRSNeez3t+k7dNDUb2FRbuAMsM36DBAmC8zWy5; 25:RGOUbuq8zaqtRiGUKrvk9h8swAwRULPhRSRydRkGSwkalIYxP/8d4lcn1qSS0IPn15HUK2CGeJHGSg0YjJq+mwxRZlTe9rc4V+I2VI/DTS7JD8dhDFDm8RRCV43+amd+FHqVWBYXMGYVi4FgxrYsb9lwavfIl7xixbeZW/lguuQi5H0TOju/xGbKXV6n0dCrsSyVZOHDeDugLPQoqHrtF3c3qqz35LrV+WXRpNOioj7Z1HGuyVTfYg36DX6yVNYTcMzeYF81Rs7Xnk0oAXdIHupM4HMbHP4GLgxl4+dZlhihjO+aEC7AK+JwhUc69dye5rYeDOXzG/rerFrLt3f2yg==; 31:13uZXltVCgaMzgn2RUiOzw61UvS02qe5Te/QlhpFedL3roybuRxchJZ5jCFh2Rxd82/G7+rYTcU8bwJPTDwqPXcfocXPuJ1paY9YwcdZ5E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ispam-Report-Test: UriScan:(4114951738403)(17755550239193); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6041248)(20161123562025)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0301MB2144; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0301MB2144; X-Forefront-PRVS: 040655413E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(189002)(199003)(7736002)(6916009)(7350300001)(2950100002)(81156014)(106356001)(42186005)(50986999)(81166006)(105586002)(80792005)(33646002)(6666003)(305945005)(5003940100001)(50226002)(2351001)(3846002)(8676002)(6116002)(76176999)(2361001)(101416001)(2906002)(50466002)(8656003)(110136004)(189998001)(107886003)(478600001)(66066001)(48376002)(97736004)(47776003)(72206003)(68736007)(4326008)(54906002)(86362001)(8666007)(122856001)(5660300001)(53936002)(36756003)(81973001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0301MB2144; H:EPUAKYIW2556.kyiv.epam.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: epam.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0301MB2144; 23:dH6Q9F7WY0XWX9av6dDOrFBDEJ/J5StZWPlLBTN?= =?us-ascii?Q?m0o2qlx51v4bh2BLlx8Jks7r5lJMkEVPQjpMVEqilZcCZLBY2kfbX+rTVZo4?= =?us-ascii?Q?kCkC7tE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IoZT79xae1TXM0XE+CLcVpv9wglIIQEovc5E5Y4LNFYBOjI4ZXtrfxoZ1JrPI3zLtvqxbgAY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2017 20:29:21.5329 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0301MB2144 Cc: "Edgar E . Iglesias" , Julien Grall , Stefano Stabellini , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v4 07/11] arm: traps: handle PSCI calls inside `vsmc.c` X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP PSCI is part of HVC/SMC interface, so it should be handled in appropriate place: `vsmc.c`. This patch just moves PSCI handler calls from `traps.c` to `vsmc.c`. Older PSCI 0.1 uses SMC function identifiers in range that is resereved for exisings APIs (ARM DEN 0028B, page 16), while newer PSCI 0.2 is defined as "standard secure service" with own ranges (ARM DEN 0028B, page 18). Signed-off-by: Volodymyr Babchuk Reviewed-by: Oleksandr Andrushchenko Reviewed-by: Oleksandr Tyshchenko --- * Fixed mistakes about non-existant PSCI 2.0 * Added special SMC function number handling for PSCI 0.1 * Fixed coding style in handle_psci_0_1() * Changed how return do_trap_hvc_smccc() is called from traps.c * Renamed SSC to SSSC (Standard Secure Service Calls) --- xen/arch/arm/traps.c | 117 +------------------------ xen/arch/arm/vsmc.c | 175 ++++++++++++++++++++++++++++++++++++-- xen/include/asm-arm/smccc.h | 4 + xen/include/asm-arm/vsmc.h | 1 + xen/include/public/arch-arm/smc.h | 8 ++ 5 files changed, 183 insertions(+), 122 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 4141a89..517e013 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1451,119 +1451,6 @@ static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) } #endif -#define PSCI_SET_RESULT(reg, val) set_user_reg(reg, 0, val) -#define PSCI_ARG(reg, n) get_user_reg(reg, n) - -#ifdef CONFIG_ARM_64 -#define PSCI_ARG32(reg, n) (uint32_t)(get_user_reg(reg, n) & 0xFFFFFFFF) -#else -#define PSCI_ARG32(reg, n) PSCI_ARG(reg, n) -#endif - -/* helper function for checking arm mode 32/64 bit */ -static inline int psci_mode_check(struct domain *d, register_t fid) -{ - return !( is_64bit_domain(d)^( (fid & PSCI_0_2_64BIT) >> 30 ) ); -} - -static void do_trap_psci(struct cpu_user_regs *regs) -{ - register_t fid = PSCI_ARG(regs,0); - - /* preloading in case psci_mode_check fails */ - PSCI_SET_RESULT(regs, PSCI_INVALID_PARAMETERS); - switch( fid ) - { - case PSCI_cpu_off: - { - uint32_t pstate = PSCI_ARG32(regs,1); - perfc_incr(vpsci_cpu_off); - PSCI_SET_RESULT(regs, do_psci_cpu_off(pstate)); - } - break; - case PSCI_cpu_on: - { - uint32_t vcpuid = PSCI_ARG32(regs,1); - register_t epoint = PSCI_ARG(regs,2); - perfc_incr(vpsci_cpu_on); - PSCI_SET_RESULT(regs, do_psci_cpu_on(vcpuid, epoint)); - } - break; - case PSCI_0_2_FN_PSCI_VERSION: - perfc_incr(vpsci_version); - PSCI_SET_RESULT(regs, do_psci_0_2_version()); - break; - case PSCI_0_2_FN_CPU_OFF: - perfc_incr(vpsci_cpu_off); - PSCI_SET_RESULT(regs, do_psci_0_2_cpu_off()); - break; - case PSCI_0_2_FN_MIGRATE_INFO_TYPE: - perfc_incr(vpsci_migrate_info_type); - PSCI_SET_RESULT(regs, do_psci_0_2_migrate_info_type()); - break; - case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU: - case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU: - perfc_incr(vpsci_migrate_info_up_cpu); - if ( psci_mode_check(current->domain, fid) ) - PSCI_SET_RESULT(regs, do_psci_0_2_migrate_info_up_cpu()); - break; - case PSCI_0_2_FN_SYSTEM_OFF: - perfc_incr(vpsci_system_off); - do_psci_0_2_system_off(); - PSCI_SET_RESULT(regs, PSCI_INTERNAL_FAILURE); - break; - case PSCI_0_2_FN_SYSTEM_RESET: - perfc_incr(vpsci_system_reset); - do_psci_0_2_system_reset(); - PSCI_SET_RESULT(regs, PSCI_INTERNAL_FAILURE); - break; - case PSCI_0_2_FN_CPU_ON: - case PSCI_0_2_FN64_CPU_ON: - perfc_incr(vpsci_cpu_on); - if ( psci_mode_check(current->domain, fid) ) - { - register_t vcpuid = PSCI_ARG(regs,1); - register_t epoint = PSCI_ARG(regs,2); - register_t cid = PSCI_ARG(regs,3); - PSCI_SET_RESULT(regs, do_psci_0_2_cpu_on(vcpuid, epoint, cid)); - } - break; - case PSCI_0_2_FN_CPU_SUSPEND: - case PSCI_0_2_FN64_CPU_SUSPEND: - perfc_incr(vpsci_cpu_suspend); - if ( psci_mode_check(current->domain, fid) ) - { - uint32_t pstate = PSCI_ARG32(regs,1); - register_t epoint = PSCI_ARG(regs,2); - register_t cid = PSCI_ARG(regs,3); - PSCI_SET_RESULT(regs, do_psci_0_2_cpu_suspend(pstate, epoint, cid)); - } - break; - case PSCI_0_2_FN_AFFINITY_INFO: - case PSCI_0_2_FN64_AFFINITY_INFO: - perfc_incr(vpsci_cpu_affinity_info); - if ( psci_mode_check(current->domain, fid) ) - { - register_t taff = PSCI_ARG(regs,1); - uint32_t laff = PSCI_ARG32(regs,2); - PSCI_SET_RESULT(regs, do_psci_0_2_affinity_info(taff, laff)); - } - break; - case PSCI_0_2_FN_MIGRATE: - case PSCI_0_2_FN64_MIGRATE: - perfc_incr(vpsci_cpu_migrate); - if ( psci_mode_check(current->domain, fid) ) - { - uint32_t tcpu = PSCI_ARG32(regs,1); - PSCI_SET_RESULT(regs, do_psci_0_2_migrate(tcpu)); - } - break; - default: - domain_crash_synchronous(); - return; - } -} - #ifdef CONFIG_ARM_64 #define HYPERCALL_RESULT_REG(r) (r)->x0 #define HYPERCALL_ARG1(r) (r)->x0 @@ -2252,7 +2139,7 @@ asmlinkage void do_trap_guest_sync(struct cpu_user_regs *regs) return do_debug_trap(regs, hsr.iss & 0x00ff); #endif if ( hsr.iss == 0 ) - return do_trap_psci(regs); + return do_trap_hvc_smccc(regs); do_trap_hypercall(regs, (register_t *)®s->r12, hsr.iss); break; #ifdef CONFIG_ARM_64 @@ -2264,7 +2151,7 @@ asmlinkage void do_trap_guest_sync(struct cpu_user_regs *regs) return do_debug_trap(regs, hsr.iss & 0x00ff); #endif if ( hsr.iss == 0 ) - return do_trap_psci(regs); + return do_trap_hvc_smccc(regs); do_trap_hypercall(regs, ®s->x16, hsr.iss); break; case HSR_EC_SMC64: diff --git a/xen/arch/arm/vsmc.c b/xen/arch/arm/vsmc.c index 0a81294..956d4ef 100644 --- a/xen/arch/arm/vsmc.c +++ b/xen/arch/arm/vsmc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,9 @@ /* Number of functions currently supported by Hypervisor Service. */ #define XEN_SMCCC_FUNCTION_COUNT 3 +/* Number of functions currently supported by Standard Service Service Calls. */ +#define SSSC_SMCCC_FUNCTION_COUNT 13 + static void fill_uuid(struct cpu_user_regs *regs, const xen_uuid_t u) { #define FILL_UUID(n) \ @@ -62,6 +66,133 @@ static bool handle_hypervisor(struct cpu_user_regs *regs) return false; } +#define PSCI_SET_RESULT(reg, val) set_user_reg(reg, 0, val) +#define PSCI_ARG(reg, n) get_user_reg(reg, n) + +#ifdef CONFIG_ARM_64 +#define PSCI_ARG32(reg, n) (uint32_t)(get_user_reg(reg, n) & 0xFFFFFFFF) +#else +#define PSCI_ARG32(reg, n) PSCI_ARG(reg, n) +#endif + +/* PSCI 0.1 interface */ +static bool handle_psci_0_1(struct cpu_user_regs *regs) +{ + switch ( get_user_reg(regs,0) & 0xFFFFFFFF ) + { + case PSCI_cpu_off: + { + uint32_t pstate = PSCI_ARG32(regs, 1); + perfc_incr(vpsci_cpu_off); + PSCI_SET_RESULT(regs, do_psci_cpu_off(pstate)); + return true; + } + case PSCI_cpu_on: + { + uint32_t vcpuid = PSCI_ARG32(regs, 1); + register_t epoint = PSCI_ARG(regs, 2); + perfc_incr(vpsci_cpu_on); + PSCI_SET_RESULT(regs, do_psci_cpu_on(vcpuid, epoint)); + return true; + } + } + return false; +} + +/* helper function for checking arm mode 32/64 bit */ +static inline int psci_mode_check(struct domain *d, register_t fid) +{ + return !( is_64bit_domain(d)^( (fid & PSCI_0_2_64BIT) >> 30 ) ); +} + +/* PSCI 0.2 interface and other Standard Secure Calls */ +static bool handle_sssc(struct cpu_user_regs *regs) +{ + register_t fid = PSCI_ARG(regs, 0); + + switch ( ARM_SMCCC_FUNC_NUM(fid) ) + { + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_PSCI_VERSION): + perfc_incr(vpsci_version); + PSCI_SET_RESULT(regs, do_psci_0_2_version()); + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_CPU_OFF): + perfc_incr(vpsci_cpu_off); + PSCI_SET_RESULT(regs, do_psci_0_2_cpu_off()); + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_MIGRATE_INFO_TYPE): + perfc_incr(vpsci_migrate_info_type); + PSCI_SET_RESULT(regs, do_psci_0_2_migrate_info_type()); + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_MIGRATE_INFO_UP_CPU): + perfc_incr(vpsci_migrate_info_up_cpu); + if ( psci_mode_check(current->domain, fid) ) + PSCI_SET_RESULT(regs, do_psci_0_2_migrate_info_up_cpu()); + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_SYSTEM_OFF): + perfc_incr(vpsci_system_off); + do_psci_0_2_system_off(); + PSCI_SET_RESULT(regs, PSCI_INTERNAL_FAILURE); + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_SYSTEM_RESET): + perfc_incr(vpsci_system_reset); + do_psci_0_2_system_reset(); + PSCI_SET_RESULT(regs, PSCI_INTERNAL_FAILURE); + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_CPU_ON): + perfc_incr(vpsci_cpu_on); + if ( psci_mode_check(current->domain, fid) ) + { + register_t vcpuid = PSCI_ARG(regs, 1); + register_t epoint = PSCI_ARG(regs, 2); + register_t cid = PSCI_ARG(regs, 3); + PSCI_SET_RESULT(regs, do_psci_0_2_cpu_on(vcpuid, epoint, cid)); + } + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_CPU_SUSPEND): + perfc_incr(vpsci_cpu_suspend); + if ( psci_mode_check(current->domain, fid) ) + { + uint32_t pstate = PSCI_ARG32(regs, 1); + register_t epoint = PSCI_ARG(regs, 2); + register_t cid = PSCI_ARG(regs, 3); + PSCI_SET_RESULT(regs, do_psci_0_2_cpu_suspend(pstate, epoint, cid)); + } + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_AFFINITY_INFO): + perfc_incr(vpsci_cpu_affinity_info); + if ( psci_mode_check(current->domain, fid) ) + { + register_t taff = PSCI_ARG(regs, 1); + uint32_t laff = PSCI_ARG32(regs, 2); + PSCI_SET_RESULT(regs, do_psci_0_2_affinity_info(taff, laff)); + } + return true; + case ARM_SMCCC_FUNC_NUM(PSCI_0_2_FN_MIGRATE): + perfc_incr(vpsci_cpu_migrate); + if ( psci_mode_check(current->domain, fid) ) + { + uint32_t tcpu = PSCI_ARG32(regs, 1); + PSCI_SET_RESULT(regs, do_psci_0_2_migrate(tcpu)); + } + return true; + case ARM_SMCCC_FUNC_CALL_COUNT: + set_user_reg(regs, 0, SSSC_SMCCC_FUNCTION_COUNT); + return true; + case ARM_SMCCC_FUNC_CALL_UID: + { + static const xen_uuid_t psci_uuid = SSSC_SMCCC_UID; + fill_uuid(regs, psci_uuid); + return true; + } + case ARM_SMCCC_FUNC_CALL_REVISION: + set_user_reg(regs, 0, SSSC_SMCCC_MAJOR_REVISION); + set_user_reg(regs, 1, SSSC_SMCCC_MINOR_REVISION); + return true; + } + return false; +} + /* * vsmccc_handle_call() - handle SMC/HVC call according to ARM SMCCC. * returns true if that was valid SMCCC call (even if function number @@ -71,6 +202,7 @@ static bool vsmccc_handle_call(struct cpu_user_regs *regs) { bool handled = false; const union hsr hsr = { .bits = regs->hsr }; + register_t func_id = get_user_reg(regs, 0); /* * Check immediate value for HVC32, HVC64 and SMC64. @@ -94,24 +226,38 @@ static bool vsmccc_handle_call(struct cpu_user_regs *regs) } /* 64 bit calls are allowed only from 64 bit domains. */ - if ( ARM_SMCCC_IS_64(get_user_reg(regs, 0)) && + if ( ARM_SMCCC_IS_64(func_id) && is_32bit_domain(current->domain) ) { set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); return true; } - switch ( ARM_SMCCC_OWNER_NUM(get_user_reg(regs, 0)) ) + /* + * Special case: identifier range for existing APIs. + * This range is described in SMCCC (ARM DEN 0028B, page 16), + * but it does not conforms to standard function identifier + * encoding. + */ + if ( func_id >= ARM_SMCCC_RESERVED_RANGE_START && + func_id <= ARM_SMCCC_RESERVED_RANGE_END ) + handled = handle_psci_0_1(regs); + else { - case ARM_SMCCC_OWNER_HYPERVISOR: - handled = handle_hypervisor(regs); - break; + switch ( ARM_SMCCC_OWNER_NUM(func_id) ) + { + case ARM_SMCCC_OWNER_HYPERVISOR: + handled = handle_hypervisor(regs); + break; + case ARM_SMCCC_OWNER_STANDARD: + handled = handle_sssc(regs); + break; + } } if ( !handled ) { - gprintk(XENLOG_INFO, "Unhandled SMC/HVC: %08"PRIregister"\n", - get_user_reg(regs, 0)); + gprintk(XENLOG_INFO, "Unhandled SMC/HVC: %08"PRIregister"\n", func_id); /* Inform caller that function is not supported. */ set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); } @@ -150,6 +296,21 @@ void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) inject_undef_exception(regs, hsr); } +/* This function will be called from traps.c */ +void do_trap_hvc_smccc(struct cpu_user_regs *regs) +{ + const union hsr hsr = { .bits = regs->hsr }; + + /* + * vsmccc_handle_call() will return false if this call is not + * SMCCC compatbile (i.e. immediate value != 0). As it is not + * compatible, we can't be sure that guest will understand + * ARM_SMCCC_ERR_UNKNOWN_FUNCTION. + */ + if ( !vsmccc_handle_call(regs) ) + inject_undef_exception(regs, hsr); +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/smccc.h b/xen/include/asm-arm/smccc.h index 67da3fb..7c0003c 100644 --- a/xen/include/asm-arm/smccc.h +++ b/xen/include/asm-arm/smccc.h @@ -80,6 +80,10 @@ /* Only one error code defined in SMCCC */ #define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1) +/* SMCCC function identifier range which is reserved for existing APIs */ +#define ARM_SMCCC_RESERVED_RANGE_START 0x0 +#define ARM_SMCCC_RESERVED_RANGE_END 0x0100FFFF + #endif /* __ASM_ARM_SMCCC_H__ */ /* diff --git a/xen/include/asm-arm/vsmc.h b/xen/include/asm-arm/vsmc.h index 31aaa55..90ff610 100644 --- a/xen/include/asm-arm/vsmc.h +++ b/xen/include/asm-arm/vsmc.h @@ -17,6 +17,7 @@ #include void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr); +void do_trap_hvc_smccc(struct cpu_user_regs *regs); #endif /* __ASM_ARM_VSMC_H__ */ diff --git a/xen/include/public/arch-arm/smc.h b/xen/include/public/arch-arm/smc.h index 3d3cd90..c5327e3 100644 --- a/xen/include/public/arch-arm/smc.h +++ b/xen/include/public/arch-arm/smc.h @@ -46,6 +46,14 @@ #define XEN_SMCCC_UID XEN_DEFINE_UUID(0xa71812dc, 0xc698, 0x4369, 0x9acf, \ 0x79, 0xd1, 0x8d, 0xde, 0xe6, 0x67) +/* Standard Service Service Call version. */ +#define SSSC_SMCCC_MAJOR_REVISION 0 +#define SSSC_SMCCC_MINOR_REVISION 1 + +/* Standard Service Call UID. Randomly generated with uuidgen. */ +#define SSSC_SMCCC_UID XEN_DEFINE_UUID(0xf863386f, 0x4b39, 0x4cbd, 0x9220,\ + 0xce, 0x16, 0x41, 0xe5, 0x9f, 0x6f) + #endif /* __XEN_PUBLIC_ARCH_ARM_SMC_H__ */ /*