From patchwork Tue Oct 10 15:52:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9996671 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 4C05060216 for ; Tue, 10 Oct 2017 16:00:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 323CA286B0 for ; Tue, 10 Oct 2017 16:00:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F9B12871A; Tue, 10 Oct 2017 16:00:30 +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 6F791286B0 for ; Tue, 10 Oct 2017 16:00:16 +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 1e1wuj-0003Xx-VL; Tue, 10 Oct 2017 15:57:49 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e1wui-0003Wg-57 for xen-devel@lists.xen.org; Tue, 10 Oct 2017 15:57:48 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id E9/DB-20448-BFDECD95; Tue, 10 Oct 2017 15:57:47 +0000 X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-Msg-Ref: server-4.tower-31.messagelabs.com!1507651060!51565016!1 X-Originating-IP: [40.107.1.40] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12021 invoked from network); 10 Oct 2017 15:57:40 -0000 Received: from mail-eopbgr10040.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.107.1.40) by server-4.tower-31.messagelabs.com with AES256-SHA256 encrypted SMTP; 10 Oct 2017 15:57:40 -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=nrq3fwnd//SYPHwioWlSK8bSERVcTpU7/dn2vD5VziA=; b=Ron/AdBP9pRpf1eLk6JlB8Z8krGdklXRCghEfC+cwmYX1zaPU564D1V8BRKb+5WawF8XzWwVv1+qumft35QDV47gBBerpA5a1srIosMDcyf8DH3XZRRBZyK4yeWx4wnUd3yZ7aMgZGmZV939pd4Qz+GY9cquLmJlnJPl3pQBx7A= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by AM4PR0301MB2131.eurprd03.prod.outlook.com (2603:10a6:200:4d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Tue, 10 Oct 2017 15:57:37 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Tue, 10 Oct 2017 18:57:34 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Tue, 10 Oct 2017 18:52:48 +0300 Message-Id: <1507650771-16631-9-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507650771-16631-1-git-send-email-volodymyr_babchuk@epam.com> References: <1507650771-16631-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: AM5PR0602CA0016.eurprd06.prod.outlook.com (2603:10a6:203:a3::26) To AM4PR0301MB2131.eurprd03.prod.outlook.com (2603:10a6:200:4d::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9e424b83-c328-4880-a6cd-08d50ff7a141 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:AM4PR0301MB2131; X-Microsoft-Exchange-Diagnostics: 1; AM4PR0301MB2131; 3:wudWICpyiF0mnlAitIk/BJsZ4098kmCXBXg+fQ5Fi1rBUsblvfJwtATL5OyGyTOoQP3O9aRJXRhEj4VWxYL88sxpPFKHB+YxbLHhlDQucwuy0AntrKUbzCfdoiEd+gh5Ui30gy8iLmGaIfhZe6k8aXE+2vJkOjp4QPJUrd7Js656ZK/bjAuMsRVFb4+HgTl/nWxOyct6Z7zS19ks07bMH4H6BXx5m1lJ46gFQZpnfho3UxXj3S+rr/TbTq4A+S7C; 25:mOd6d7CNDr8/616HCHRivaWra/AgVVvBD7StuKJQRBjW0W0TPQQgcX3pf5LqkaMZstZpn7J8oFKXCihEvVXUxwEaFyARpB9vMOmXekcbKtjDKP4oo5zKggjM48Q1cUjyqUWcpZAG/gHgDnx+BAYIO7QC+AfLVLNE5wuwMGl+8FSNEp1uCrbCbSlmBlSjgpig99VNs9RUsXwByDB5FsbYFBDqqhl/yfst/59oRQDjM+NjGsvV8YNKHVTn9BIAkFYJbXt0KomzpiFilcWyn209SwmqhOD6Hdza5+uTNlpSgelq32X4huiiUYkzZaNl33pwgWOo/n5SDG38j5kaU72BfQ==; 31:5Y4tzfU227706lyvy9QRJzYmUsBaOpV+mrYEsImvqyASxU529iMUMSNOHMjpBRvrhVqkOwRywp768cvRyKYQts9tqhUscW4sMzg69F1UjcrITfXCoa9nmKSVZ8/N1+YXk/Tqq7iO3+SJD0aGsLAjEZWg3G3RaMM8W+cAHdaxZ2aLTXxyet0nqOgOngeNzEnq13ulEiNPOlILiWRm+Glt//zKiEjSeaJUb7SkNA4M93E= X-MS-TrafficTypeDiagnostic: AM4PR0301MB2131: X-Microsoft-Exchange-Diagnostics: 1; AM4PR0301MB2131; 20:FstgVKPG8JCB+tqg6xla7vbaBqpNqgbs9wPDypTvHcpeT1ATdFYkvP4uTQ66QUGMudXE19Vq+m+udmYJbVRAVgf/pd8zyf3heQ8PAYnrsWskQX0+UeEMz3S5DglTt4vQqLfyVNvG2RYx7xD7lBZZMDRcOLdPWpnlL6z1yP8pUAq0VAQmYZcnfufgVQyqU8SLsPvPYHMoq3rlgPX2lJ84PQRodZcmtH64biXRFyvaSdX+Msdya8eRSLpGkfl2EIz2PudIz6XrYLsFxhJTBXOSsXAQ2DGQ8Ymnz9clGhASmHj/ubNSj+hKOKiFbNRvYVjwfvK2RG19w6ChN90TUH0MHZKy1RwwU7eoV/uQS0g5uGxxZxcN4fou+QFIPBy+cI4Z4Bmy/UpOvy6+qGZstb2RH9Y8QXLc0/K4+9qVUIJ0CN0ijxvywwZIZkdEP3hQ6g38qY5iUjhqof5W6Ts7xsfKB4oaCefANzwOM4rmLdHaGyNLZl1nrjM1PparbE2mZq1p; 4:QIePNAFODOpMz2y1zs1IL1MrEaDotuBmscHM9OoiqGNyvqPHnwHoAcjP0+S0vquR6LdU0ArcB/bgFt/H1S9yB7Fh+n4PTqCrQT1pLKPsu5shP9HYWw2l/Rm6jnf6dK4Mp4LuNjvW31ASw8wp/mh/RkEKCF7CIZLf+y0PQnqbEQ2pFeM220jHqHKgC2IMwupqH/CEKBSrRe4Uz2GDtqjuSrF+xXWRyns6SokdVVIAdFe50g/krYaRe3TuO39K4uv47etXnaeWIbM4ehU4pg0Zo6coNtDwXVEQ3FgbpNAGY8cRZTWTrsmjSiUBYQAUZKIZJuq3Y/c8wqbr5IR21xzy+oJirP4o2g8fHGg+cTFtVs0= X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(4114951738403)(17755550239193); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(10201501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(20161123560025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR0301MB2131; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR0301MB2131; X-Forefront-PRVS: 04569283F9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(199003)(189002)(86362001)(575784001)(4326008)(81156014)(6666003)(36756003)(68736007)(101416001)(48376002)(5660300001)(54906003)(5003940100001)(478600001)(42186006)(2906002)(50466002)(72206003)(316002)(16586007)(97736004)(2351001)(66066001)(8676002)(3846002)(6116002)(8656003)(80792005)(76176999)(122856001)(50986999)(81166006)(53936002)(8936002)(189998001)(8666007)(7736002)(105586002)(2361001)(33646002)(6916009)(2950100002)(50226002)(47776003)(106356001)(305945005)(81973001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0301MB2131; H:EPUAKYIW2556.kyiv.epam.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; AM4PR0301MB2131; 23:KYtScrreYLHqx3W/T+pT4LkMqO+LE2W6V6k6QOQ?= =?us-ascii?Q?s02xi1EkQ/15PyHiiA51U40wYeksoOrAGv9+TBY0YJcylI0dzgW7uDA5bHCG?= =?us-ascii?Q?O8lj4EHbmHzZmuRI+jtLsQ+XXspaIwnew6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1MX+DWVAu2BBMQmhTICemwj+yE4+HrG6YmUBeRsiI0xkyFdX7wdoK9pzo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2017 15:57:37.6284 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0301MB2131 Cc: "Edgar E . Iglesias" , Julien Grall , Stefano Stabellini , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v8 08/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 moves PSCI handler calls from `traps.c` to `vsmc.c`. Also it corrects coding style of the PSCI handler functions. Older PSCI 0.1 uses SMC function identifiers in range that is reserved for existing APIs (ARM DEN 0028B, page 16), while newer PSCI 0.2 and later is defined as "standard secure service" with its own ranges (ARM DEN 0028B, page 18). Signed-off-by: Volodymyr Babchuk Reviewed-by: Oleksandr Andrushchenko Reviewed-by: Oleksandr Tyshchenko Acked-by: Julien Grall --- * PSCI_ARG32 replaced with (uint32_t)get_user_reg(regs, 0) in handle_sssc() function. --- xen/arch/arm/traps.c | 117 +---------------------- xen/arch/arm/vsmc.c | 183 +++++++++++++++++++++++++++++++++++- xen/include/asm-arm/traps.h | 1 + xen/include/public/arch-arm/smccc.h | 8 ++ 4 files changed, 190 insertions(+), 119 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 6ea0090..f6f6de3 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1452,119 +1452,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) -#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, uint32_t fid) -{ - return !( is_64bit_domain(d)^( (fid & PSCI_0_2_64BIT) >> 30 ) ); -} - -static void do_trap_psci(struct cpu_user_regs *regs) -{ - uint32_t fid = PSCI_ARG32(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 @@ -2291,7 +2178,7 @@ 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 @@ -2303,7 +2190,7 @@ 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 38df821..b20ba6f 100644 --- a/xen/arch/arm/vsmc.c +++ b/xen/arch/arm/vsmc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,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 bool fill_uid(struct cpu_user_regs *regs, xen_uuid_t uuid) { int n; @@ -94,6 +98,148 @@ static bool handle_hypervisor(struct cpu_user_regs *regs) } } +#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)) +#else +#define PSCI_ARG32(reg, n) PSCI_ARG(reg, n) +#endif + +/* Existing (pre SMCCC) APIs. This includes PSCI 0.1 interface */ +static bool handle_existing_apis(struct cpu_user_regs *regs) +{ + /* Only least 32 bits are significant (ARM DEN 0028B, page 12) */ + switch ( (uint32_t)get_user_reg(regs, 0) ) + { + 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; + } + default: + return false; + } +} + +/* helper function for checking arm mode 32/64 bit */ +static inline int psci_mode_check(struct domain *d, uint32_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) +{ + uint32_t fid = (uint32_t)get_user_reg(regs, 0); + + switch ( fid ) + { + case PSCI_0_2_FN_PSCI_VERSION: + perfc_incr(vpsci_version); + PSCI_SET_RESULT(regs, do_psci_0_2_version()); + return true; + + case PSCI_0_2_FN_CPU_OFF: + perfc_incr(vpsci_cpu_off); + PSCI_SET_RESULT(regs, do_psci_0_2_cpu_off()); + return true; + + 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()); + return true; + + case 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 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 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 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 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 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 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: + return fill_function_call_count(regs, SSSC_SMCCC_FUNCTION_COUNT); + + case ARM_SMCCC_FUNC_CALL_UID: + return fill_uid(regs, SSSC_SMCCC_UID); + + case ARM_SMCCC_FUNC_CALL_REVISION: + return fill_revision(regs, SSSC_SMCCC_MAJOR_REVISION, + SSSC_SMCCC_MINOR_REVISION); + + default: + 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 @@ -133,11 +279,26 @@ static bool vsmccc_handle_call(struct cpu_user_regs *regs) return true; } - switch ( smccc_get_owner(funcid) ) + /* + * 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 ( funcid >= ARM_SMCCC_RESERVED_RANGE_START && + funcid <= ARM_SMCCC_RESERVED_RANGE_END ) + handled = handle_existing_apis(regs); + else { - case ARM_SMCCC_OWNER_HYPERVISOR: - handled = handle_hypervisor(regs); - break; + switch ( smccc_get_owner(funcid) ) + { + case ARM_SMCCC_OWNER_HYPERVISOR: + handled = handle_hypervisor(regs); + break; + case ARM_SMCCC_OWNER_STANDARD: + handled = handle_sssc(regs); + break; + } } if ( !handled ) @@ -181,6 +342,20 @@ void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) inject_undef_exception(regs, hsr); } +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 compatible (e.g. 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/traps.h b/xen/include/asm-arm/traps.h index 325c15f..a0e5e92 100644 --- a/xen/include/asm-arm/traps.h +++ b/xen/include/asm-arm/traps.h @@ -37,6 +37,7 @@ void do_cp(struct cpu_user_regs *regs, const union hsr hsr); /* SMCCC handling */ 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_TRAPS__ */ /* diff --git a/xen/include/public/arch-arm/smccc.h b/xen/include/public/arch-arm/smccc.h index 2bee5b3..17dc6d8 100644 --- a/xen/include/public/arch-arm/smccc.h +++ b/xen/include/public/arch-arm/smccc.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_SMCCC_H__ */ /*