From patchwork Thu Aug 31 20:09:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9932799 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 B335560362 for ; Thu, 31 Aug 2017 20:12:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A79B81FEB1 for ; Thu, 31 Aug 2017 20:12:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C5941FF1D; Thu, 31 Aug 2017 20:12:43 +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 A482F1FF13 for ; Thu, 31 Aug 2017 20:12:42 +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 1dnVnQ-0000KW-HV; Thu, 31 Aug 2017 20:10:36 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dnVnP-0000Jo-FI for xen-devel@lists.xen.org; Thu, 31 Aug 2017 20:10:35 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 4D/90-01782-A3D68A95; Thu, 31 Aug 2017 20:10:34 +0000 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.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1504210232!95793298!1 X-Originating-IP: [104.47.1.54] 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 15459 invoked from network); 31 Aug 2017 20:10:33 -0000 Received: from mail-ve1eur01on0054.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.54) by server-15.tower-206.messagelabs.com with AES256-SHA256 encrypted SMTP; 31 Aug 2017 20:10:33 -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=SXOTvvSd5aKvYrr0bv44+fiEzVhtFU0JtR9oPeBeRuI=; b=e33zlrSiTys6Q4d8OYKv1qKo//XMURXbHbWjdMKtvpZZ5UwBnSzEj6eU+J+U57z6sml5bHvS4eq86uvGHwHiKH8sXecsPxChKvZBZ35K+6MRAt07hGtq+4a5G3xKqh16fkZZl+w6G8DbcKUQajTYswyAseBm4TMvdX/wX5owKX0= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.51) by HE1PR0301MB2138.eurprd03.prod.outlook.com (2603:10a6:3:21::15) 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:28 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 31 Aug 2017 23:10:23 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Thu, 31 Aug 2017 23:09:28 +0300 Message-Id: <1504210172-27234-7-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: HE1PR09CA0087.eurprd09.prod.outlook.com (2603:10a6:7:3d::31) To HE1PR0301MB2138.eurprd03.prod.outlook.com (2603:10a6:3:21::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e7bd23b1-4ddd-4d82-2954-08d4f0ac539b 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:HE1PR0301MB2138; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0301MB2138; 3:Wg6Ac1v+PdPw8KsDsuFznvELP9P6OaFoKNaCGxql4OsWALuw8gCje5a+8Sv0u4DxpdfOdDhMuslJV0k8TzQpNp1A4VqrB+4zmmVjKRRj5S3WnnsF4DwzFEk/4KuSFVpbM9FT7wlGO0e6LLo1pvUwlYJb8mOtyUPV5jT6ML9exdbPcQQZGqB0sLIaMOiP+rXk7r4jYCACgStcD4NKgHz7tQPHXXd80EhAapnW/hrVv8XbKl8sOM+gzZV9BYMR0N+3; 25:pK6nk/C4TQ8ostd8mTFmlVrkOlMoIpXELj1RuTO04kb2gLFsnw3NkwwVlBd4m5pzIUSD8i8fdslhjEfZyLFzKorjm9KHnYi1MiR56wkE0uO6d2gzR4CepYfCgcDh+EhohQYYEVFFwrtiFdWHiXYAlETGsAkOSDwCP0XFV7vkONcHlCZk6o5xAYBBUlUwJ84YgXq5Cwyk1SbzByfQ++IJS457h4Qjlc2swBiW3bV5UoeW4NZ1XGLQtmCLkZ4+ElwK6Z2Subkbr3UHO/nIaB56SItrR/kmKyqWoOOvEQ4nRwF72ATvUPJEYDcvCAOa0QgtoXFGsue48ghdFqNDhByhhg==; 31:xn57aRPL8oiuL+dYkIARTJPU4AW3AcFmlFy2y8/1m8R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3J9gcI= X-Exchange-Antispam-Report-Test: UriScan:(4114951738403); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123564025)(20161123562025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0301MB2138; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0301MB2138; X-Forefront-PRVS: 04163EF38A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(199003)(189002)(2351001)(76176999)(54906002)(8656003)(6916009)(2950100002)(5003940100001)(478600001)(2361001)(86362001)(189998001)(48376002)(50466002)(122856001)(68736007)(33646002)(97736004)(6116002)(72206003)(8676002)(3846002)(105586002)(5660300001)(7736002)(66066001)(305945005)(81156014)(7350300001)(81166006)(106356001)(2906002)(101416001)(50226002)(50986999)(8666007)(47776003)(36756003)(53936002)(4326008)(80792005)(7416002)(110136004)(42186005)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0301MB2138; 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; HE1PR0301MB2138; 23:LM1WCll4bvFDawdRClXSINGumvOCEuF8hlbd8Cn?= =?us-ascii?Q?bHpqq1fYnbLxRLRHxPlCclCl2E2hye9Mo2+V+9zxjG2imjOAbqsHyDB9zQuT?= =?us-ascii?Q?YNkc+Boy94c0uEjIe8wwjD+12aZ5SUPAIPAlDKoIKbWY2oncNGPRfk21QhHr?= =?us-ascii?Q?yBd3lCmMga7OaBhMhNlhUrNpEXZky6AlLti3/dK77fe4BQbP2+4QX5JPV3qi?= =?us-ascii?Q?tYs+IiFAu2d54UOWcdvB4ZuPmmMZzsl1u6IH0uzbD62MiCHpXmxwS8mSUnki?= =?us-ascii?Q?nH1j0bQnq9rSGJFzwXc291BsxBuptNsd68TaQ47rileCMrFnQd72OfizP9Vd?= =?us-ascii?Q?jvrD2YNbFHe9x49F+b9CgNfNgYnOUiRg80BOD416VlVdOD72uiiBmJW164aO?= =?us-ascii?Q?pwCrAXAnHV/WLFij55n9Zb9eqGuqCtQfGfq0g1hnkS+FvP7fsoWbKPZ+pEub?= =?us-ascii?Q?bMLeBzqfmcyUsLehe6Tue6jHc4a1IVhNR5h0s6EjyQBiwVZ1tMVUTKKniHTT?= =?us-ascii?Q?pYjoPN30f/ZJSATpaYN+AXqbdJRs+vWKDyBzG8P0h42YxUepxZKLYOerdiip?= =?us-ascii?Q?+XOB7crtDJsa/tEO1wBUYt89Q5WrsV79Yb4/J6egVOvmOZpsOXAV+agRApaH?= =?us-ascii?Q?pS7NHB81x+3HQbWm1xCytRF9F0CueITk1msj/mEkUng0MW41R20dHzRkrjWK?= =?us-ascii?Q?TBTFjXUjQKSyTdlmxRd4gREmJukgZ6MsrGEnevLtHs5PFIBZMG4AX80aHXOL?= =?us-ascii?Q?ck7k5LV+9BsC8zkZEUXzF6X83j1o5Zve9Rfywlokp3IINSE6XLYewXrWIati?= =?us-ascii?Q?4bHPMM2JoX5GSXCFEkb4YUlCX+7XVOykXK3AFMC0YHntw/RTNN0ZqQpAWd7r?= =?us-ascii?Q?y8LpAXhZDUEDbkyF/CeP4MTCa09wujAXysG2b/c2eE1oNpeeBFdznkrbd1rj?= =?us-ascii?Q?NYxE625UdvYbQUwiXUmt+8fXM5SRDgfNuD/Oo07dftMK7X0qBbwDSC/2aErQ?= =?us-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keJRg4LUM7iS4GTHTbhyxwf2PBVzdVGLzmFvMezuMQ1tWd2epF0E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2017 20:10:28.5832 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0301MB2138 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 06/10] 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 --- * reworked fill_uuid() function * dropped vsmc.h header. Function prototypes moved to traps.h * public/arch-arm/smc.h header renamed to smccc.h * introduced `register_t funcid` in vsmccc_handle_call()x * spelling fixes * coding style fixes --- xen/arch/arm/Makefile | 1 + xen/arch/arm/traps.c | 17 ---- xen/arch/arm/vsmc.c | 168 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/traps.h | 3 + xen/include/public/arch-arm/smccc.h | 58 +++++++++++++ 5 files changed, 230 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 de00c5e..3d7dde9 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_HAS_GICV3) += vgic-v3.o obj-$(CONFIG_HAS_ITS) += vgic-v3-its.o obj-y += vm_event.o obj-y += vtimer.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 9132fe1..f3b64b4 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2155,23 +2155,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..97a6be3 --- /dev/null +++ b/xen/arch/arm/vsmc.c @@ -0,0 +1,168 @@ +/* + * 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 void fill_uuid(struct cpu_user_regs *regs, const xen_uuid_t *u) +{ + int n; + + /* + * UUIDs are 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 = u->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); + } +} + +/* SMCCC interface for hypervisor. Tell about itself. */ +static bool handle_hypervisor(struct cpu_user_regs *regs) +{ + static const xen_uuid_t xen_uuid = XEN_SMCCC_UID; + + switch ( smccc_get_fn(get_user_reg(regs, 0)) ) + { + case ARM_SMCCC_FUNC_CALL_COUNT: + set_user_reg(regs, 0, XEN_SMCCC_FUNCTION_COUNT); + return true; + case ARM_SMCCC_FUNC_CALL_UID: + fill_uuid(regs, &xen_uuid); + return true; + case ARM_SMCCC_FUNC_CALL_REVISION: + set_user_reg(regs, 0, XEN_SMCCC_MAJOR_REVISION); + set_user_reg(regs, 1, XEN_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 + * 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 f88cbf6..6efd1c5 100644 --- a/xen/include/asm-arm/traps.h +++ b/xen/include/asm-arm/traps.h @@ -31,6 +31,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..a1d00ae --- /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 + */