From patchwork Tue Aug 8 20:08:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9889031 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 A379C60352 for ; Tue, 8 Aug 2017 20:11:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94B37287C0 for ; Tue, 8 Aug 2017 20:11:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 894AA287D7; Tue, 8 Aug 2017 20:11:58 +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 85592287C0 for ; Tue, 8 Aug 2017 20:11:57 +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 1dfAoi-0000ev-JD; Tue, 08 Aug 2017 20:09:28 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfAog-0000eC-F5 for xen-devel@lists.xen.org; Tue, 08 Aug 2017 20:09:26 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id 97/52-02962-57A1A895; Tue, 08 Aug 2017 20:09:25 +0000 X-Brightmail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am.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1502222963!106329487!1 X-Originating-IP: [104.47.0.49] 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 33238 invoked from network); 8 Aug 2017 20:09:24 -0000 Received: from mail-he1eur01on0049.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.49) by server-7.tower-27.messagelabs.com with AES256-SHA256 encrypted SMTP; 8 Aug 2017 20:09:24 -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=eMcNJJb25GZEJMNL9koeiZBCF7AgjG4iHYd7vDgqg3g=; b=N9gi8+yrp6Rws0RnoDEtf1dFc/2YRaWSp/AQTZUye3ub1ViGpChunsJtcfc3+iwDUVQjFmvDsF/ULyFToe5tp+6YqcaHhKkLXhja2NTPZjkBaD6rpmib68UzdogFoUUfLyAuKHmcD63pYhQEy7AFkbPpTO+JEtn+APIq76wESHY= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.58) by VI1PR0301MB2141.eurprd03.prod.outlook.com (2603:10a6:800:26::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1320.16; Tue, 8 Aug 2017 20:09:21 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Tue, 08 Aug 2017 23:09:16 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Tue, 8 Aug 2017 23:08:39 +0300 Message-Id: <1502222922-25821-5-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502222922-25821-1-git-send-email-volodymyr_babchuk@epam.com> References: <1502222922-25821-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.58] X-ClientProxiedBy: VI1PR08CA0217.eurprd08.prod.outlook.com (2603:10a6:802:15::26) To VI1PR0301MB2141.eurprd03.prod.outlook.com (2603:10a6:800:26::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 359c4b81-cd74-4356-209c-08d4de995b9b 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:VI1PR0301MB2141; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0301MB2141; 3:8OBphTFlJjeUI5mtLvtERx5LWWeUnEr4YbWCHozLEpnNpUwoacMRaRoxb5PGHc6Pu/99R9yk5B8BVpJSKuL/3QB/oKgHXz+G14saEVoPa3XyYkn/tAL0cAWLFZf6gPtkZyyk5bS5aiH270ZgDM0Ag0492KbrULBWH0h5e5EnsMOYEiCyOZn3Qk/qC7l6e0pMxYc7/F91JzQy4J0C4EQaLep57LotbCea0kWu3ia5JJMGwHXfvBdkMt4/nfaiWBeQ; 25:E7ch2Gl25aRmwaZIV91HvXVlxFot4WovK1gf8QaSZ0Z/SeAkfNJrssdYM/gfwBNZB1pj45G+Guv5cOQtCh9RrhuFXYad1KaRHeL1znMZ83mMgzVXolI/axXoXjB6GMuJDfQaDCsGzRD1oaOm6lwHfq+Lm0pNXRfe9RKF7KhKE7DbVCXuhJzsdgdr2BOUWY6LLM3h1L9jCJqi+FvwQIsoVgrbTNwVWpwxekZ22vctAn24S5cNHcRevtlrktBkWIuOQy/6Isv8IFq5MD04t92p3tCik4Pz1wEhXeIeWIHBet/25blrCRIJ8ES2SDClDgGw59rf14u2+NCAI816/D5hyA==; 31:Dn3wz9QwofrKuXkqvvM0hBflSWUgByPdY6y2QtmrWXyDXimP7hDX89uT47iR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Ea+pkDnRcK7MYA== 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)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123558100)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0301MB2141; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0301MB2141; X-Forefront-PRVS: 03932714EB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39450400003)(39850400002)(39410400002)(39400400002)(39840400002)(199003)(189002)(36756003)(48376002)(50226002)(80792005)(478600001)(6306002)(101416001)(50466002)(5003940100001)(3846002)(6116002)(5660300001)(8666007)(966005)(81156014)(6666003)(54906002)(2361001)(2950100002)(122856001)(72206003)(81166006)(189998001)(2351001)(2906002)(6916009)(97736004)(347745004)(33646002)(50986999)(8676002)(42186005)(76176999)(4326008)(105586002)(68736007)(53936002)(106356001)(38730400002)(66066001)(110136004)(86362001)(7736002)(7350300001)(8656003)(305945005)(107886003)(47776003)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0301MB2141; 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; VI1PR0301MB2141; 23:YR5MvCqur+cxgiPzuTmJYAKwzf+QRsbMjm8TmoA?= =?us-ascii?Q?t0pB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ZS1+M7Cv1Ml+Vye1ntx5o6mfnz4qqmu5XKBZludTYTX5GS93ayRGhU54TktHN1KswreAyuB6y4TjkFcOw339QiaiRNptHh/wkCVnbGxfXh2OpwqQ==; 24:iu1elExC/A3vrKqnJNlAytrPydlW+0USzWgtt6jL1Nah+MLfQ7lk6g4JaiqXHhh/Z7XFSj0GcGKxJLEgNrwH1pbCvUu/cyi1jxLdJXMlwXs=; 7:eL0fVv4SfP/3PIPA8v7RD1IeHKZjldWEQkAsZIgXqxBVgR8t+kDthduO0KmwRoNeo81ifKRfzBBx1MdtvyQyAl2Gh35k7JxHkn5gUyHTfFozGYfQeF3Irandoj9ewVxOfllTMu7IUGk7D3IwHEL4/6u1cvjy/nhjelczrA7RtXfPtBoy7qAgsJNK8awg/Ln6hIAN8PtgCXFiJJk5FmCABcYcncV4f/i+gRjN8kWfuRA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2017 20:09:21.0900 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0301MB2141 Cc: "Edgar E . Iglesias" , Julien Grall , Stefano Stabellini , Volodymyr Babchuk Subject: [Xen-devel] [PATCH 4/7] 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 a 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, UID and number of functions provided by service provider. This patch adds new file `vsmc.c`, which handles both generic SMCs and HVC according to SMC. At this moment it implements only one service: Standard Hypervisor Service. 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 --- - Updated description to indicate that this patch affects only SMC call path. - added "xen_" prefix to definitions in include/public/arch-arm/smc.h - moved do_trap_smc() into vsmc.c from traps.c - replaced all tabs with spaces --- xen/arch/arm/Makefile | 1 + xen/arch/arm/traps.c | 19 +----- xen/arch/arm/vsmc.c | 139 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vsmc.h | 94 ++++++++++++++++++++++++++ xen/include/public/arch-arm/smc.h | 68 +++++++++++++++++++ 5 files changed, 303 insertions(+), 18 deletions(-) create mode 100644 xen/arch/arm/vsmc.c create mode 100644 xen/include/asm-arm/vsmc.h create mode 100644 xen/include/public/arch-arm/smc.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 49e1fb2..4efd01c 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -50,6 +50,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 e14e7c0..b119dc0 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include "decode.h" #include "vtimer.h" @@ -2769,23 +2769,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..5ef6167 --- /dev/null +++ b/xen/arch/arm/vsmc.c @@ -0,0 +1,139 @@ +/* + * 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 + +/* Number of functions currently supported by Hypervisor Service. */ +#define XEN_SMCCC_FUNCTION_COUNT 3 + +/* SMCCC interface for hypervisor. Tell about itself. */ +static bool handle_hypervisor(struct cpu_user_regs *regs) +{ + switch ( ARM_SMCCC_FUNC_NUM(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: + set_user_reg(regs, 0, XEN_SMCCC_UID.a[0]); + set_user_reg(regs, 1, XEN_SMCCC_UID.a[1]); + set_user_reg(regs, 2, XEN_SMCCC_UID.a[2]); + set_user_reg(regs, 3, XEN_SMCCC_UID.a[3]); + 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; + } + return false; +} + +/* + * vsmc_handle_call() - handle SMC/HVC call according to ARM SMCCC. + * returns true if that was valid SMCCC call (even if function number + * was unkown). + */ +static bool vsmc_handle_call(struct cpu_user_regs *regs) +{ + bool handled = false; + const union hsr hsr = { .bits = regs->hsr }; + + /* + * 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 dissasemble 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 & 0xFF) != 0) + return false; + break; + case HSR_EC_SMC32: + break; + default: + return false; + } + + /* 64 bit calls are allowed only from 64 bit domains */ + if ( ARM_SMCCC_IS_64(get_user_reg(regs, 0)) && + is_32bit_domain(current->domain) ) + { + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + return true; + } + + switch ( ARM_SMCCC_OWNER_NUM(get_user_reg(regs, 0)) ) + { + case ARM_SMCCC_OWNER_HYPERVISOR: + handled = handle_hypervisor(regs); + break; + } + + if ( !handled ) + { + gprintk(XENLOG_INFO, "Unhandled SMC/HVC: %08"PRIregister"\n", + get_user_reg(regs, 0)); + /* Inform caller that function is not supported */ + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + } + + return true; +} + +/* This function will be called from traps.c */ +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 */ + if ( vsmc_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/vsmc.h b/xen/include/asm-arm/vsmc.h new file mode 100644 index 0000000..7baabef --- /dev/null +++ b/xen/include/asm-arm/vsmc.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017, EPAM Systems + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ +#ifndef __ASM_ARM_VSMC_H__ +#define __ASM_ARM_VSMC_H__ + +#include + +/* + * This file provides common defines for ARM SMC Calling Convention as + * specified in + * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html + */ + +#define ARM_SMCCC_STD_CALL 0U +#define ARM_SMCCC_FAST_CALL 1U +#define ARM_SMCCC_TYPE_SHIFT 31 + +#define ARM_SMCCC_SMC_32 0U +#define ARM_SMCCC_SMC_64 1U +#define ARM_SMCCC_CALL_CONV_SHIFT 30 + +#define ARM_SMCCC_OWNER_MASK 0x3F +#define ARM_SMCCC_OWNER_SHIFT 24 + +#define ARM_SMCCC_FUNC_MASK 0xFFFF + +/* Check if this is fast call */ +#define ARM_SMCCC_IS_FAST_CALL(smc_val) \ + ((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT)) + +/* Check if this is 64 bit call */ +#define ARM_SMCCC_IS_64(smc_val) \ + ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT)) + +/* Get function number from function identifier */ +#define ARM_SMCCC_FUNC_NUM(smc_val) ((smc_val) & ARM_SMCCC_FUNC_MASK) + +/* Get service owner number from function identifier */ +#define ARM_SMCCC_OWNER_NUM(smc_val) \ + (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK) + +/* + * Construct function identifier from call type (fast or standard), + * calling convention (32 or 64 bit), service owner and function number + */ +#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \ + (((type) << ARM_SMCCC_TYPE_SHIFT) | \ + ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \ + (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \ + ((func_num) & ARM_SMCCC_FUNC_MASK)) + +/* List of known service owners */ +#define ARM_SMCCC_OWNER_ARCH 0 +#define ARM_SMCCC_OWNER_CPU 1 +#define ARM_SMCCC_OWNER_SIP 2 +#define ARM_SMCCC_OWNER_OEM 3 +#define ARM_SMCCC_OWNER_STANDARD 4 +#define ARM_SMCCC_OWNER_HYPERVISOR 5 +#define ARM_SMCCC_OWNER_TRUSTED_APP 48 +#define ARM_SMCCC_OWNER_TRUSTED_APP_END 49 +#define ARM_SMCCC_OWNER_TRUSTED_OS 50 +#define ARM_SMCCC_OWNER_TRUSTED_OS_END 63 + +/* List of generic function numbers */ +#define ARM_SMCCC_FUNC_CALL_COUNT 0xFF00 +#define ARM_SMCCC_FUNC_CALL_UID 0xFF01 +#define ARM_SMCCC_FUNC_CALL_REVISION 0xFF03 + +/* Only one error code defined in SMCCC */ +#define ARM_SMCCC_ERR_UNKNOWN_FUNCTION (-1) + +void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr); + +#endif /* __ASM_ARM_VSMC_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End:b + */ diff --git a/xen/include/public/arch-arm/smc.h b/xen/include/public/arch-arm/smc.h new file mode 100644 index 0000000..42f3165 --- /dev/null +++ b/xen/include/public/arch-arm/smc.h @@ -0,0 +1,68 @@ +/* + * smc.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_SMC_H__ +#define __XEN_PUBLIC_ARCH_ARM_SMC_H__ + +typedef struct { + uint32_t a[4]; +} xen_arm_smccc_uid; + +#define XEN_ARM_SMCCC_UID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ + ((xen_arm_smccc_uid) {{(a), ((b) << 16 | (c) ), \ + ((d0) << 24 | (d1) << 16 | (d2) << 8 | (d3) << 0), \ + ((d4) << 24 | (d5) << 16 | (d6) << 8 | (d7) << 0)}}) + +/* + * 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. + * They should not be stored in public/asm-arm/smc.h because they should + * be queried by guest using SMC/HVC interface. + */ +#define XEN_SMCCC_MAJOR_REVISION 0 +#define XEN_SMCCC_MINOR_REVISION 1 + +/* Hypervisor Service UID. Randomly generated with 3rd party tool. */ +#define XEN_SMCCC_UID XEN_ARM_SMCCC_UID(0xa71812dc, 0xc698, 0x4369, \ + 0x9a, 0xcf, 0x79, 0xd1, \ + 0x8d, 0xde, 0xe6, 0x67) + +#endif /* __XEN_PUBLIC_ARCH_ARM_SMC_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End:b + */