From patchwork Thu Aug 31 20:09:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9932801 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 7BBA960362 for ; Thu, 31 Aug 2017 20:12:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FD361FEB1 for ; Thu, 31 Aug 2017 20:12:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 645641FF1D; Thu, 31 Aug 2017 20:12:48 +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 8C9941FEB1 for ; Thu, 31 Aug 2017 20:12:47 +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 1dnVnX-0000Ou-Uy; Thu, 31 Aug 2017 20:10:43 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dnVnW-0000O2-Gb for xen-devel@lists.xen.org; Thu, 31 Aug 2017 20:10:42 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 30/73-01916-14D68A95; Thu, 31 Aug 2017 20:10:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA1WSa0gUYRSG95vZyyhOjKvhcXUVF6yUVl0rvEA g/amUtKx+GEaOOu4u7kVm1lQUvIJpUV7Dli5aCuIPqy1UFBEFNU0tMsWMyszCzDK1C2FkO85q 9u/9eN73e8+BQ+DyZYmCYLItDGuiDSqps1gXLApSRxmbE0KuDIeGNy7fEUehI/1da9hxdEaiN yWbs5Mkus7lEllGvzm75vcKVoBWTpcjZ0JMFeLw+ftFcTlyIhCVCLaHZYgHcuoyBq01PVIeyK kUeG5t39BSaj+03noi47U75QWTq+MbAZx6jENX+wjOAzfqMDS2FUl4Lab84c3sJOI1SUXDYMf wRhtQPvBirMzuJwgnKgbKG04KXdFQebNaKthdYeja3IYdpwB65+dxIeoHtba7Ur4XqEoEq0W9 jkF3Q/faosOkhP7R646uY9BU3yYRAhMYFM/YkACKZVBxL03Qe6FnrgoXTNUyaJmflgrgKFgvV GGCzoCmvgdiwTQlgQ9z1TIBeMPbj60OU70E6r76CiMlwZf1NUwIDLnA7c73MuFRJoNPQ6+wCr TLum1Z67Zl6xHWgvZwDHueYdWaiKBkVq/VWYy03qDWhOwLMjIcR2sZA53MBaWYjTZkP4V8kQh 1oLXB2D7kSWCqnWRuXHOCfEeyOTVHR3O6c2ymgeH6kDdBqIA8aLAzV5bRMtlpeoP9njYxEC4q d1LFY5LLoI2cXiugYeSn8CB/pdsBxQNdpmkrtnmJz5BS4UYikUgkd8lgWKPe8j9fQB4EUtkd/ PcuepNl6/cFezFmLz4b3cQXW+h/SFGAAnKnChvysdC4irCFb9UpvuHqrIZg3MMnOium8URes1 h93z9VO65riDleHGvOW28ei++MHH0q/1lsfedZu/Tn5UBAum3xh69SHzjrJfK85K/oca47MDL dVBrvEUt2zy1ZJw6F5UQOkC2axKmFU3nKG8OS1+NtJf2+7NXSiJlHLSoxp6M1gTjL0X8Bd4QA 4YQDAAA= X-Env-Sender: Volodymyr_Babchuk@epam.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1504210240!107999887!1 X-Originating-IP: [104.47.0.46] 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 42653 invoked from network); 31 Aug 2017 20:10:40 -0000 Received: from mail-he1eur01on0046.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.46) by server-13.tower-31.messagelabs.com with AES256-SHA256 encrypted SMTP; 31 Aug 2017 20:10: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=drH58f0PS5gxtBLYsl2rt4eSrHn2jJB8tm85R4svkd4=; b=DdxwGvAHuNu4AsMt9KbISEtnGYfcOOzUU4xH68p2dFBm8GboqFJ+KzvX4RA8wjoI48ty+hPT3POkvbbGzlRp/qRpqa9cZn3hE217rc6eKxFcWxbngOLOeGo7uZl6GETyT4Wo34VxylAKRvqDPRcbcqjCRpi9ttaBWKcyA5uihQI= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.51) 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.13.10; Thu, 31 Aug 2017 20:10:36 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 31 Aug 2017 23:10:31 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Thu, 31 Aug 2017 23:09:29 +0300 Message-Id: <1504210172-27234-8-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504210172-27234-1-git-send-email-volodymyr_babchuk@epam.com> References: <1504210172-27234-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.51] X-ClientProxiedBy: AM4PR05CA0027.eurprd05.prod.outlook.com (2603:10a6:205::40) To HE1PR0301MB2139.eurprd03.prod.outlook.com (2603:10a6:3:21::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1c8ccf8-a35f-4e90-124b-08d4f0ac5835 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:HE1PR0301MB2139; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0301MB2139; 3:CsFbc8O0+qBQjVEyIHfeAA846McCM1tDMQiE3/CP7E8r8OV0vitKMkE2bc5w6RBJ+g2dLkyw+SXHXQr79uP7IjLLLFzPuTEZ1vIA/dy6Lf8oRYWlarWv+GFffUbz2TZORF471aQ8rI2P6PdHuDvAHiqz29xPM/YnWPU6/Zifh5ELNl0xFQ+Igg1mJUOT9pQ+TdhVEFTkzP0Q8/eAvlezl1SSFEJT7QkCHZ3m2EWQ+fT0avdBoDCLJY60hVP7Xij6; 25:XuHvXojFK6i7e3YFldBdkGjnE4nKVsWru6aQVmMUQRrjVOC9XNHK7uyi4BehdnFdIowSXmwwAdVnnwxpXjxwV8rBfbLmsg3pNbAVbUZAujh6GRrZ5H/vJz/P4lyLvdyXFjmM7jYNYIofk+3h8gP7xV3XKzfogMK7YLaPyp/7F/U0nhcepXgsUUTuaW1b45lwULhK9WmZn84bXYT4gWgFuY8vCmiLHomm4Sde477TkttB0xbmgLiWfT+XsaXQZXDLY5Wa9dBJ5etX/BIHdqnu4UNvSiWporrdNuil4ab0GFsXiRu1vJwRAWqHuKrZ/qMwd4tYju0gvA6G/GJXGdCjcg==; 31:CVy0iZJw8Ztr9eTkhvdIVEtmVaiQtzEwMULtUIy7Sffc63Fklj3j+5hrCjs1ntwK/hz6gFnx9un7hTQZZ8IQ0XeqXHiUKasruybi9YExPpVreMv+DqIUIgxupSqFqFYYZzyn118In6GONkdpugmwAguzMkwQm2lf83EGQQ5MTh9v76BwSrvjNkHXa6xrJNsrtrcvQQ3VNSs3P9I+0uZXC/2zjTaSN9xSBT9OtZDrJAs= X-MS-TrafficTypeDiagnostic: HE1PR0301MB2139: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0301MB2139; 20:Q3hq1zG+62F1nZ+PB/rSif1hQlLmsVokjST2uiammQ41Touowu2u9CS0NAgpuVNUvALl+vTPo1KMx9Rf+E1cIb3weL5Foy/eXDRUEbnf1e4M23lPPcku88rwV7JX3oqcnLRaUp3YmzIC4k3Lg5CusSlptv2Ft1pvWTtRI3sT2IpjxkbtBJAtoAeixslU1w8cFILHL8EAPxYCNzyM8juN+usnz9zNchw01yvVvwxkVP8/FR2RArHa0JLvFtNO/xd4d9lng4QNS4fOY+1S3jTXNQmLjvXLnpXXf7+adSfvz2bmAszBVSHLN01nWNSH9SC/EL3iPWCgLOCNdVab6MRo+dMIoTubEBEmObG4pSZbqnr4htaA/Mt2OGWHnHTenIiDOaaSmtoyw4zX82365tEe39gw8NnXOs9+Be8MhArJ3BwNaqKFrZ355NgSyGwp5XnB3ZdpyE1D9aU6yvSWpyb9x92MIKJJ69GrOO6PX+9i83AobNnbDZCcn83JukzmPQsI; 4:bNrQooO6vs/mlOezzG8hHgQoMp8DcNV1j5VW+L4PpZaSyKw6BvFfoOVw7a043YlR+qK4ds+ZaZndkpzc996lZzw8bXJTuohaQ4CHzPHX/rcZjPnCMW8/JI4IIf9kAgTpe7re3ohWaqB2Cf/gq7gdKMqfiwye/wcv3bgE12b+LexE1d7U5f9CUIHLoJHO+5JDfbACn5YvOmTjzCXgvxvf99we/aj2Mg+Lp18VhuPIXxTKc886z9MImj5JrQdyd4hGHtRHFGGuAtugCFV8qYma+j5R+QrmtBlr1lCEFv5kY4EUjUyn6eOp4L68qRDXcv8y7vVae6uhH9n7UEvRsklUAA== X-Exchange-Antispam-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)(100000703101)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123564025)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123560025)(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: 04163EF38A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(199003)(189002)(305945005)(8676002)(5660300001)(6916009)(189998001)(42186005)(2361001)(97736004)(105586002)(72206003)(4326008)(86362001)(80792005)(2351001)(7736002)(106356001)(81166006)(5003940100001)(81156014)(7416002)(8666007)(110136004)(2950100002)(50226002)(2906002)(478600001)(36756003)(50986999)(76176999)(122856001)(101416001)(54906002)(8656003)(7350300001)(68736007)(66066001)(53936002)(33646002)(47776003)(6116002)(50466002)(3846002)(48376002)(81973001); 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:rztRCYhFD4HinZrZW1Mclt2tUy3rJhEBknMFnHZ?= =?us-ascii?Q?qSOgyn7laH04B13mj2mKeXIBIXExcXhDXYISdD3Fvh1+GvaPFrwYsI2xSqDF?= =?us-ascii?Q?Ti3ScQV9ZFuz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czvG0Z5OyBk5okOJNsjAPEZt4tySYTYJefZf59rtS/u/PfEq7FvlR1I= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2017 20:10:36.0527 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0301MB2139 Cc: "Edgar E . Iglesias" , Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v5 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 --- * handle_psci_0_x() renamed to handle_existing_apis() * spelling fixes * fixed coding style for moved PSCI code * previously introduced `funcid` moved to previous patch --- xen/arch/arm/traps.c | 117 +--------------------- xen/arch/arm/vsmc.c | 189 +++++++++++++++++++++++++++++++++++- xen/include/asm-arm/traps.h | 1 + xen/include/public/arch-arm/smccc.h | 8 ++ 4 files changed, 196 insertions(+), 119 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index f3b64b4..d00ff36 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1450,119 +1450,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 @@ -2251,7 +2138,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 @@ -2263,7 +2150,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 97a6be3..d3120a5 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 void fill_uuid(struct cpu_user_regs *regs, const xen_uuid_t *u) { int n; @@ -71,6 +75,154 @@ 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 ( PSCI_ARG32(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 ( smccc_get_fn(fid) ) + { + case smccc_get_fn(PSCI_0_2_FN_PSCI_VERSION): + perfc_incr(vpsci_version); + PSCI_SET_RESULT(regs, do_psci_0_2_version()); + return true; + + case smccc_get_fn(PSCI_0_2_FN_CPU_OFF): + perfc_incr(vpsci_cpu_off); + PSCI_SET_RESULT(regs, do_psci_0_2_cpu_off()); + return true; + + case smccc_get_fn(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 smccc_get_fn(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 smccc_get_fn(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 smccc_get_fn(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 smccc_get_fn(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 smccc_get_fn(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 smccc_get_fn(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 smccc_get_fn(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; + + 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 @@ -110,11 +262,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 ) @@ -158,6 +325,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 a1d00ae..caead6e 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__ */ /*