From patchwork Wed Oct 4 21:00:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9985465 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 296B5602B8 for ; Wed, 4 Oct 2017 21:04:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 197BE27E5A for ; Wed, 4 Oct 2017 21:04:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CAE128BCC; Wed, 4 Oct 2017 21:04:11 +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 2F87A27E5A for ; Wed, 4 Oct 2017 21:04:10 +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 1dzqnm-0008Iw-KT; Wed, 04 Oct 2017 21:01:58 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzqnl-0008Hy-4v for xen-devel@lists.xen.org; Wed, 04 Oct 2017 21:01:57 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id F6/13-03422-44C45D95; Wed, 04 Oct 2017 21:01:56 +0000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uk@epam.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1507150914!88143221!1 X-Originating-IP: [104.47.1.53] 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 27293 invoked from network); 4 Oct 2017 21:01:54 -0000 Received: from mail-ve1eur01on0053.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.53) by server-11.tower-27.messagelabs.com with AES256-SHA256 encrypted SMTP; 4 Oct 2017 21:01:54 -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=c6IRox0KDvafOILngAQMt83HLKbOBZ365zwUuGOdyRY=; b=Lx4zIThOdaQeJDLnxwSEemBHbG7mwwPPDCl0E4A0RUDk6St54rTwYdTROUJfvZRIu+Ki0G3omM8TfOCL7U2WI81EeNvYfb+8jps0ON7mYvhMoYQvAbetWg6nnwFLzKQTEpAx3augFfRd8REXii19Ow2bGD+MSgpPIAm889ALOgQ= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.53) by AM4PR0301MB2129.eurprd03.prod.outlook.com (2603:10a6:200:4d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 4 Oct 2017 21:01:51 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 05 Oct 2017 00:01:48 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Thu, 5 Oct 2017 00:00:23 +0300 Message-Id: <1507150827-7858-8-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507150827-7858-1-git-send-email-volodymyr_babchuk@epam.com> References: <1507150827-7858-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.53] X-ClientProxiedBy: AM5PR0602CA0002.eurprd06.prod.outlook.com (2603:10a6:203:a3::12) To AM4PR0301MB2129.eurprd03.prod.outlook.com (2603:10a6:200:4d::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db61ddae-2be8-457d-0fae-08d50b6b22f0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:AM4PR0301MB2129; X-Microsoft-Exchange-Diagnostics: 1; AM4PR0301MB2129; 3:QhbQ0h/hYuJxFHuT5rseFNg5Jq/Ry9AOsN3Q66zq8lbilyeVjIVUPy2cfn3CbZUG95jIhu0P9Pixbyc5SYjZc79Zwg0SXjoTUhzQAx9CAd31uYWh1FnPnusbrrY9Detb4Xlq1Yd9XBuZr7e+i9VjJK/6Y2XpOE7v/DzajMYMFyGgYxRLeVgvklWzjguZdSWsJxJ0zjd7qCAOma1RCYz+ewE6ewPbkZd0uSsS48T6LXt+FeSemObxwRaSFYAhLEdv; 25:ZKfWC007/UPHbS4X6GkTy4/MkXiVcSVXWBKoNCUjZw9U5wGXF+MTQksDRjEDEQjFISfh0GeO8kDOE9ff9bQ8NtVQZByXR3F6yKBxgYcAE2BbQsl75F7xXCVaLAehCU8uWCWxGrOt44EHXfGtH1GqpRnYZ5guyllGRHHp5QneBuo9RV334MUDc9IgbiAsnQRtfiVbhQt1k5eGFDnTtEeL9zWm3itGgcCkaNelQdlTQqC9jSy4D0/23CMsyTaMvchZj8RbQ+MFxDpcvbjsVj05wTJOYmKuM0ayUwpoYtKRwcmTr2l5fAbeW8KgSFrIT3H1tEXh8fh0BnpJVDYQUV5ZIg==; 31:0pnhjfSMyTBtVADB34rz2/iqMNKs49rzMUxM1fm5mDwuZ66u0UbKq9/i7tGsIjZOzDpatEs+muzi38crF/rmGzF013/67Q85uwToKYsoN2/L2r4lu9+CjtS7Wfr6sJrJ2lUHz8nZ/uCBGoENMpcRSFr2aBtGe0ef9ROrzvmGeAlt/O9uwzOSU7ItViMFpb+SmG1GvuU1zk86dWIjHjwP8wauzfo/rNp0UCjvTLAmmyw= X-MS-TrafficTypeDiagnostic: AM4PR0301MB2129: X-Microsoft-Exchange-Diagnostics: 1; AM4PR0301MB2129; 20:zCS+S4HzwkSGbcuXIiO9bYc5ohucSgylHZFmwP+aMksatAFcYMYV+ncKLnVRL4qWRrRnqL13MLYoOXhMe0AK66O2fFo97Oh9cVw29jtPlj+uauJGkw/PN74dQ8U/CkgTk/iKaSKxM8t+NVRAFzU2ve35xOU6aUQ3cEpAGX5kd5OCYvFN51HqobRe+o4M6gpFZNw3CsOaaRiKzIig2W4//q9kbAMCRmFU477GgAq+3WbxZZsXfVIcaL8U29BizWLA88M7DsGnu0W17Z6qrKVOuEdsKRRMTWXeHP2DxLuVwj4HiKfoDnPXecrc3K6HAt+dVEOrkqKD8r6z4CeF7mOmDFfSZeMVAvjTMIaptwCxw8tt0PjMtdZ8d62J2OqTeJcYh4qBNSlZ51o1lGs68ZvDaj7v7JMae2FNVXgo0eUhTPPAslKmsosY3zwZuFjh/+hjxHvT5fRKyqf0LSgpn3RfS7v0Ow8o/+3dib5NqSaPh+pevRBlgqbA6fnnJuM86VzB; 4:zfmaY0kROwoTbeieBwMscjOEaPBUkEubnT6Qr48Fyd8YGiS0n1Fj1i2cK8UVcGLNemBVUy6b3Dltrck2AiX7w1o2Zi122YbvJJ3zfmPIAao34qTj5tEkpXiHvIYPSh02hTRVa06llBQ+SHFW2O/Dm1eGXrv/TFcRd2pqSd3ijbKf3kgG9El0TR1phtATkNXw6rnzYs2o4TcXGPIxJ9gThx/p3SSpgrvQYFcQNYmUHDnZarPhehOKRNBs3u0xkfz+UFMtaGXFgZY05/QnICbN7bG7TPPc9OLpIMw3X/ohykdWtvkp5kegSGizg8PBlk918nPniWDA3FF9SuJuer9m1g== X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(4114951738403); 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)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR0301MB2129; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR0301MB2129; X-Forefront-PRVS: 0450A714CB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(39860400002)(189002)(199003)(53936002)(189998001)(8676002)(80792005)(7416002)(2906002)(105586002)(478600001)(8936002)(6666003)(72206003)(86362001)(7736002)(305945005)(50226002)(97736004)(54906003)(101416001)(2950100002)(6916009)(50986999)(4326008)(42186006)(5003940100001)(8656003)(106356001)(3846002)(8666007)(316002)(76176999)(16586007)(68736007)(6116002)(36756003)(47776003)(81166006)(81156014)(66066001)(122856001)(33646002)(2351001)(2361001)(5660300001)(50466002)(48376002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0301MB2129; 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; AM4PR0301MB2129; 23:d91J0Xn3PaN6oVaV7zWrfn3CLaVb/6I3kuVOYfG?= =?us-ascii?Q?BsXpm+Kwmkyr1uGcjIjXfMOM8q2X9wQwHqGVOzNbz2BmF+u9+KGA3OmhvG/B?= =?us-ascii?Q?EnroZILnsE9wkIt7TkRo40D5P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KhGKBt/FG5rH53/yW8upcP1FdAiKFjZfqlDRmfBYn3Yupv4gHDFI/of6c= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2017 21:01:51.2732 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0301MB2129 Cc: "Edgar E . Iglesias" , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v7 07/11] arm: smccc: handle SMCs according to SMCCC 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 SMCCC (SMC Call Convention) describes how to handle both HVCs and SMCs. SMCCC states that both HVC and SMC are valid conduits to call to different firmware functions. Thus, for example, PSCI calls can be made both by SMC or HVC. Also SMCCC defines function number coding for such calls. Besides functional calls there are query calls, which allows underling OS determine version, UUID and number of functions provided by service provider. This patch adds new file `vsmc.c`, which handles both generic SMCs and HVC according to SMCCC. At this moment it implements only one service: Standard Hypervisor Service. At this time Standard Hypervisor Service only supports query calls, so caller can ask about hypervisor UID and determine that it is XEN running. This change allows more generic handling for SMCs and HVCs and it can be easily extended to support new services and functions. But, before SMC is forwarded to standard SMCCC handler, it can be routed to a domain monitor, if one is installed. Signed-off-by: Volodymyr Babchuk Reviewed-by: Oleksandr Andrushchenko Reviewed-by: Oleksandr Tyshchenko Acked-by: Julien Grall --- xen/arch/arm/Makefile | 1 + xen/arch/arm/traps.c | 17 ---- xen/arch/arm/vsmc.c | 191 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/traps.h | 3 + xen/include/public/arch-arm/smccc.h | 58 +++++++++++ 5 files changed, 253 insertions(+), 17 deletions(-) create mode 100644 xen/arch/arm/vsmc.c create mode 100644 xen/include/public/arch-arm/smccc.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 424580b..30a2a65 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_HAS_ITS) += vgic-v3-its.o obj-y += vm_event.o obj-y += vtimer.o obj-$(CONFIG_SBSA_VUART_CONSOLE) += vpl011.o +obj-y += vsmc.o obj-y += vpsci.o obj-y += vuart.o diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 5b91e6c..6ea0090 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2195,23 +2195,6 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, inject_dabt_exception(regs, info.gva, hsr.len); } -static void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) -{ - int rc = 0; - - if ( !check_conditional_instr(regs, hsr) ) - { - advance_pc(regs, hsr); - return; - } - - if ( current->domain->arch.monitor.privileged_call_enabled ) - rc = monitor_smc(); - - if ( rc != 1 ) - inject_undef_exception(regs, hsr); -} - static void enter_hypervisor_head(struct cpu_user_regs *regs) { if ( guest_mode(regs) ) diff --git a/xen/arch/arm/vsmc.c b/xen/arch/arm/vsmc.c new file mode 100644 index 0000000..38df821 --- /dev/null +++ b/xen/arch/arm/vsmc.c @@ -0,0 +1,191 @@ +/* + * xen/arch/arm/vsmc.c + * + * Generic handler for SMC and HVC calls according to + * ARM SMC calling convention + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#include +#include +#include +#include +#include +#include +#include + +/* Number of functions currently supported by Hypervisor Service. */ +#define XEN_SMCCC_FUNCTION_COUNT 3 + +static bool fill_uid(struct cpu_user_regs *regs, xen_uuid_t uuid) +{ + int n; + + /* + * UID is returned in registers r0..r3, four bytes per register, + * first byte is stored in low-order bits of a register. + * (ARM DEN 0028B page 14) + */ + for (n = 0; n < 4; n++) + { + const uint8_t *bytes = uuid.a + n * 4; + uint32_t r; + + r = bytes[0]; + r |= bytes[1] << 8; + r |= bytes[2] << 16; + r |= bytes[3] << 24; + + set_user_reg(regs, n, r); + } + + return true; +} + +static bool fill_revision(struct cpu_user_regs *regs, uint32_t major, + uint32_t minor) +{ + /* + * Revision is returned in registers r0 and r1. + * r0 stores major part of the version + * r1 stores minor part of the version + * (ARM DEN 0028B page 15) + */ + set_user_reg(regs, 0, major); + set_user_reg(regs, 1, minor); + + return true; +} + +static bool fill_function_call_count(struct cpu_user_regs *regs, uint32_t cnt) +{ + /* + * Function call count is retuned as any other return value in register r0 + * (ARM DEN 0028B page 17) + */ + set_user_reg(regs, 0, cnt); + + return true; +} + +/* SMCCC interface for hypervisor. Tell about itself. */ +static bool handle_hypervisor(struct cpu_user_regs *regs) +{ + switch ( smccc_get_fn(get_user_reg(regs, 0)) ) + { + case ARM_SMCCC_FUNC_CALL_COUNT: + return fill_function_call_count(regs, XEN_SMCCC_FUNCTION_COUNT); + case ARM_SMCCC_FUNC_CALL_UID: + return fill_uid(regs, XEN_SMCCC_UID); + case ARM_SMCCC_FUNC_CALL_REVISION: + return fill_revision(regs, XEN_SMCCC_MAJOR_REVISION, + XEN_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 + * was unknown). + */ +static bool vsmccc_handle_call(struct cpu_user_regs *regs) +{ + bool handled = false; + const union hsr hsr = { .bits = regs->hsr }; + register_t funcid = get_user_reg(regs, 0); + + /* + * Check immediate value for HVC32, HVC64 and SMC64. + * It is not so easy to check immediate value for SMC32, + * because it is not stored in HSR.ISS field. To get immediate + * value we need to disassemble instruction at current pc, which + * is expensive. So we will assume that it is 0x0. + */ + switch ( hsr.ec ) + { + case HSR_EC_HVC32: + case HSR_EC_HVC64: + case HSR_EC_SMC64: + if ( (hsr.iss & HSR_XXC_IMM_MASK) != 0) + return false; + break; + case HSR_EC_SMC32: + break; + default: + return false; + } + + /* 64 bit calls are allowed only from 64 bit domains. */ + if ( smccc_is_conv_64(funcid) && is_32bit_domain(current->domain) ) + { + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + return true; + } + + switch ( smccc_get_owner(funcid) ) + { + case ARM_SMCCC_OWNER_HYPERVISOR: + handled = handle_hypervisor(regs); + break; + } + + if ( !handled ) + { + gprintk(XENLOG_INFO, "Unhandled SMC/HVC: %08"PRIregister"\n", funcid); + + /* Inform caller that function is not supported. */ + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + } + + return true; +} + +void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) +{ + int rc = 0; + + if ( !check_conditional_instr(regs, hsr) ) + { + advance_pc(regs, hsr); + return; + } + + /* If monitor is enabled, let it handle the call. */ + if ( current->domain->arch.monitor.privileged_call_enabled ) + rc = monitor_smc(); + + if ( rc == 1 ) + return; + + /* + * Use standard routines to handle the call. + * 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) ) + advance_pc(regs, hsr); + else + inject_undef_exception(regs, hsr); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/traps.h b/xen/include/asm-arm/traps.h index 7508af8..325c15f 100644 --- a/xen/include/asm-arm/traps.h +++ b/xen/include/asm-arm/traps.h @@ -35,6 +35,9 @@ void do_cp14_64(struct cpu_user_regs *regs, const union hsr hsr); void do_cp14_dbg(struct cpu_user_regs *regs, const union hsr hsr); 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); + #endif /* __ASM_ARM_TRAPS__ */ /* * Local variables: diff --git a/xen/include/public/arch-arm/smccc.h b/xen/include/public/arch-arm/smccc.h new file mode 100644 index 0000000..2bee5b3 --- /dev/null +++ b/xen/include/public/arch-arm/smccc.h @@ -0,0 +1,58 @@ +/* + * smccc.h + * + * SMC/HVC interface in accordance with SMC Calling Convention. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Copyright 2017 (C) EPAM Systems + */ + +#ifndef __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ +#define __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ + +#include "public/xen.h" + +/* + * Hypervisor Service version. + * + * We can't use XEN version here, because of SMCCC requirements: + * Major revision should change every time SMC/HVC function is removed. + * Minor revision should change every time SMC/HVC function is added. + * So, it is SMCCC protocol revision code, not XEN version. + * + * Those values are subjected to change, when interface will be extended. + */ +#define XEN_SMCCC_MAJOR_REVISION 0 +#define XEN_SMCCC_MINOR_REVISION 1 + +/* Hypervisor Service UID. Randomly generated with uuidgen. */ +#define XEN_SMCCC_UID XEN_DEFINE_UUID(0xa71812dc, 0xc698, 0x4369, 0x9acf, \ + 0x79, 0xd1, 0x8d, 0xde, 0xe6, 0x67) + +#endif /* __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End:b + */