From patchwork Thu Sep 21 20:00:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9964787 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 9C7526020C for ; Thu, 21 Sep 2017 20:03:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DFC2205A4 for ; Thu, 21 Sep 2017 20:03:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 829F529698; Thu, 21 Sep 2017 20:03:34 +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 A2A69205A4 for ; Thu, 21 Sep 2017 20:03:33 +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 1dv7es-0007hD-AD; Thu, 21 Sep 2017 20:01:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv7er-0007gc-8R for xen-devel@lists.xen.org; Thu, 21 Sep 2017 20:01:13 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id D0/71-03414-88A14C95; Thu, 21 Sep 2017 20:01:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA1WSbUhTURjHPXd321W8cp2aj0sLBymFmlJUIL0 ggWUMJSGyAr3T6zba5rx3mn7KmJVKimkqiqWglKVJiogmvmsyWSYaoaASKeUbkuWHYIrduzvN zqf/Of/fc57/OTyERLEjVRJMjoVhTbRBJfPAdSfd4sPzlSNJkcVjIecaNxvwS+jKaI8DS0C3p HqTJiMnRaqbev5dZq435zx+2oflIeuNIuRB4NQDCTxs/iMrQu4Eou5Ae0chEgwFVYzBdG8pXo QIfpMKTyoUAiOjTkNr3Se5oH2pw/Dl97STl1DdCLptnRLB8KFiwVb1Cwkap47BVtmKU5PUVfh Q3OFsBtQRmJ0odPLuVByMNSziglbwjLXKjom8N9iql5znEgpgcHlZItYGw9fBSWdjoJ4h+Fbw UyYWh0KvY90FBcHox1pc1GpYWRfCCQVLGLx4NIyJG6scZnZ2kUiFQf9SmYt6JYeu/nJX+U143 1+JCX8BlBmmHDKRmZRCZ1sXJjKB0PmjWy4aE1Io2CjBxEwpsLHrcLVrIaGhss7VolAOq3Olkl IUWnPgtTUHXluPsDcolGPYbIYNPxuhYfVancVI6w3hUZFnIowMx9FaxkBruIjUDGM74kfBjV9 dqHo6fggFEJjKjxzJHE5SeGky0nJ1NKdLZrMMDDeEAglCBeSFbN7zZhktk5OuN/DztGcD4any JcsFm+TMtJHTa0VrHIUTBbPz25gCN2WYGKU/aRMgSoB0Wab9K/amcgoFKX1IxIdSeJoZ1qi3/ O+vIn8CqXxIjXCLp95k2e+0yofA+BB33w0IISz0P0uZh7IqUte2e0I89IPGaI3pVPLFJnt0jG KrMsVePzyRYKFLBqpmNJCpHJXn2u63qY9fTgwtjExbGMd6/Vq80l629B86yuai8/awuca6xVk 6xHqtVq1KxioaNt0XtMHpfR7q2Huf7ctx+QGRMU2J5rct6V6vi2+vNc9bctNaU65zKpzT0VEn JCxH/wUoEI+lkAMAAA== X-Env-Sender: Volodymyr_Babchuk@epam.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1506024068!84012677!1 X-Originating-IP: [104.47.0.79] 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 27023 invoked from network); 21 Sep 2017 20:01:08 -0000 Received: from mail-he1eur01on0079.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.79) by server-12.tower-21.messagelabs.com with AES256-SHA256 encrypted SMTP; 21 Sep 2017 20:01:08 -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=lqa0L/QJVRhJZyeTcg/Ak67N+2Uk641GH0Pf1IR9g1Q=; b=dJQ002hvYFhmhdicdJII/W4rfVgovrJa5bPY1hDSD+/5ACLTRvUIe25bHfEMhuAm6YZ5C/fefDQ0RUp/LrVtK58Nar0nNYBHiZOMj7GFr9O259Ttk/k+ckAperCygW0SC4KWTWQZhAuPzD8HSZ0xTqz3LcdUJSF/9dkVVj2TAeA= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by HE1PR0301MB2139.eurprd03.prod.outlook.com (2603:10a6:3:21::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Thu, 21 Sep 2017 20:01:04 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 21 Sep 2017 23:00:57 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 23:00:01 +0300 Message-Id: <1506024004-8615-8-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506024004-8615-1-git-send-email-volodymyr_babchuk@epam.com> References: <1506024004-8615-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: VI1P189CA0017.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::30) To HE1PR0301MB2139.eurprd03.prod.outlook.com (2603:10a6:3:21::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f4f2c4b-a4f9-4650-0f6e-08d5012b7e0a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:HE1PR0301MB2139; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0301MB2139; 3:qdqVsobIJt/4WnhLbx64r7gvH51kWb5RvepdvDyoU2suMt1ltOaNz7euIyDbriZE0jboIOGGRsCvGXicHjDN+79d2dXBi7ZBQvn0rS2ggSkRfQJm0k/90kGKfDTcV5AJVTCtoK+hQgBtyp+VXG9+RtwjCTytex58aHxUcYm+jtpOsn518p0SssPK6XN2QiuU4qr4Js/b7fsry6Sfv0qjzjw/q+A+YblqnK3SH4Qu2d1uyjxubjBaikcY+1vED0ip; 25:/3Zb7ljkbgv8BgJOEXrkoG5rveLfIUIeQUvqYohbgvzSqa9s1Kz1qRoqUz8KC4OOXWtnlcWRD5erVokCFXX21ovW//CWLBxTW4x9sCrx92e++LWdQy06U5D4OQgSNcoTkQ/sjZI/7ex1Uvi1LFoYt3SpJN7lWRJjzqqVTr2hj+RqqCOi0CB/MjArpKNkXlc46ri6nPVpkrENyqRYUP/LAZAda3rVCXrI4K5abBn4XkZx5vGyu7TBZ6f43iF50A+wWyzKXG4/onxYffFMPm03l5IAvC5TgprCr2NRYvqLWMu70ELWFyelDm7XEXTYBuACHtLEGkltNYNjb9YlgtIHPQ==; 31:NMpF+v6NMAX2AhgrJxyEAHCSg6UU28HSRJ7Nofz539PIQ+xMsdGApGDN/XHA32GcNdVXE29jihY44CLmRIwgVSE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naJNMLAXQXLDrVthDnUqGoQ4V+/ZSYq3XHnfubY= X-Exchange-Antispam-Report-Test: UriScan:(788757137089)(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)(93006095)(93001095)(100000703101)(100105400095)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0301MB2139; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0301MB2139; X-Forefront-PRVS: 04371797A5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(6009001)(346002)(376002)(199003)(189002)(81156014)(8676002)(81166006)(5660300001)(76176999)(5003940100001)(80792005)(72206003)(316002)(16586007)(6666003)(42186006)(54906003)(3846002)(101416001)(6916009)(68736007)(305945005)(6116002)(478600001)(2950100002)(86362001)(50466002)(4326008)(189998001)(53936002)(48376002)(2361001)(2351001)(7736002)(8666007)(106356001)(33646002)(105586002)(97736004)(50226002)(47776003)(36756003)(8936002)(122856001)(8656003)(2906002)(50986999)(66066001)(81973001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0301MB2139; 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; HE1PR0301MB2139; 23:OWfupl6M/A9DisnEPXDp3Pwt4qtETQjK6RVIaZW?= =?us-ascii?Q?5DMHk3x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F9B8+7u8nwm8=; 7:2x7KTMzwqtuGXr385/NJLLCx7UmashmjGLzL8hSRdgbT9fTVBIs4TKcv0qi499OTGFGqmNPKTM++b4Nvsx1sROtuJdZJcYRtmtPCh4U3/eWCsaRBItfnYWY+UuOWKblMKENav2uxI6QZhCXphqbqZrVXYDeRkiYGhnolOXFrxe7aEp8PshoD5TgyRWFIMEUZB6ht6ik2ebDbqNZIk1/SgMeK/BfIARodNaI0jh619EI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2017 20:01:04.6196 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0301MB2139 Cc: "Edgar E . Iglesias" , Julien Grall , Stefano Stabellini , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v6 07/10] 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 --- * Fixed aligning of SSSC_SMCCC_UID XEN_DEFINE_UUID() * Fixed compilation bug. Previous version used inlined function smccc_get_fn() in 'case' statement. That was artifact of refactoring, because I was asked to replace macroses in asm-arm/smccc.h to inlined functions. But, apparently, you can't write `case func():`. Next patched fixed this problem anyways. But anyways... * Removed call to PSCI_ARG32() from handle_existing_apis() * Used newly added helper functions --- 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 8397188..61980ea 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, 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 @@ -2270,7 +2157,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 @@ -2282,7 +2169,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..6ab7c55 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) +{ + switch ( 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, 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 ( 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); + return true; + + 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 6efd1c5..0b91aa7 100644 --- a/xen/include/asm-arm/traps.h +++ b/xen/include/asm-arm/traps.h @@ -33,6 +33,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__ */ /*