From patchwork Wed Aug 9 20:34:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9892645 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 7339E60236 for ; Thu, 10 Aug 2017 02:43:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 593BA268AE for ; Thu, 10 Aug 2017 02:43:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D72128173; Thu, 10 Aug 2017 02:43:55 +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=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_MED 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 D3F2B268AE for ; Thu, 10 Aug 2017 02:43:54 +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 1dfdPW-00011l-Fi; Thu, 10 Aug 2017 02:41:22 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfdPU-00011P-Rn for xen-devel@lists.xen.org; Thu, 10 Aug 2017 02:41:20 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id D9/13-27137-0D7CB895; Thu, 10 Aug 2017 02:41:20 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42Jpa+sQ0T1/vDv S4MVmGYslHxezODB6HN39mymAMYo1My8pvyKBNePA1leMBQdUKp62P2ZrYPwt28XIxSEkMJ1R ouPFFLYuRk4OCQFeiSPLZrBC2P4Sy8/eYIMo6mCUeNi+CCzBJqAucWLxREYQW0RAWuLa58uMI EXMAlcZJU5vm88MkhAWcJE4eXYx2FQWAVWJjvO7wJp5geJHv29hh9igIDHl4Xuwek4BV4mpW7 YygdhCQDXrlk9jnMDIu4CRYRWjRnFqUVlqka6hmV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJ SsV5yfu4mRmBIMADBDsb7GwMOMUpyMCmJ8nY0dEcK8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuBl AYaYkGBRanpqRVpmDjA4YdISHDxKIrzvjwGleYsLEnOLM9MhUqcYLTk2rF7/hYljQc8GIPlqw v9vTEIsefl5qVLivEtAGgRAGjJK8+DGwSLoEqOslDAvI9CBQjwFqUW5mSWo8q8YxTkYlYR5t4 BM4cnMK4Hb+groICaggyJ8O0EOKklESEk1MHb1OZ65EtzG+ttYfrZi/AKNzTvufDh8esEFH6/ 9G9d0TnbUNd/0/19moonm06M755cb7Vjb3+rQqxebeDasMvCt/OZO5sJrR2c2aXkcfLiKb1XI 4uK8Hb/fb+v1lqkV/RWxUUj7qH7/z78X/26oTWVXSsxTbnW4kaZlduf1nPrprxll1pjEZyixF GckGmoxFxUnAgAUnXuEmwIAAA== X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1502332877!69247215!1 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29446 invoked from network); 10 Aug 2017 02:41:19 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-5.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Aug 2017 02:41:19 -0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Aug 2017 19:41:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,349,1498546800"; d="scan'208";a="888413674" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.141]) by FMSMGA003.fm.intel.com with ESMTP; 09 Aug 2017 19:41:14 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Wed, 9 Aug 2017 16:34:06 -0400 Message-Id: <1502310866-10450-6-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1502310866-10450-1-git-send-email-tianyu.lan@intel.com> References: <1502310866-10450-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , kevin.tian@intel.com, wei.liu2@citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, julien.grall@arm.com, jbeulich@suse.com, Chao Gao Subject: [Xen-devel] [PATCH V2 5/25] tools/libxc: Add viommu operations in libxc 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Chao Gao This patch adds XEN_DOMCTL_viommu_op hypercall. This hypercall comprises three sub-command: - query capabilities of one specific type vIOMMU emulated by Xen - create vIOMMU in Xen hypervisor, given viommu type, register-set location and capabilities - destroy vIOMMU specified by viommu_id Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- tools/libxc/Makefile | 1 + tools/libxc/include/xenctrl.h | 8 +++++ tools/libxc/xc_viommu.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 tools/libxc/xc_viommu.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 28b1857..8724df5 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -51,6 +51,7 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c CTRL_SRCS-y += xc_evtchn_compat.c CTRL_SRCS-y += xc_gnttab_compat.c CTRL_SRCS-y += xc_devicemodel_compat.c +CTRL_SRCS-y += xc_viommu.c GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index bde8313..dfaa9d5 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -27,6 +27,7 @@ #define __XEN_TOOLS__ 1 #endif +#include #include #include #include @@ -2499,6 +2500,13 @@ enum xc_static_cpu_featuremask { const uint32_t *xc_get_static_cpu_featuremask(enum xc_static_cpu_featuremask); const uint32_t *xc_get_feature_deep_deps(uint32_t feature); +int xc_viommu_query_cap(xc_interface *xch, domid_t dom, + uint64_t type, uint64_t *cap); +int xc_viommu_create(xc_interface *xch, domid_t dom, uint64_t type, + uint64_t base_addr, uint64_t length, uint64_t cap, + uint32_t *viommu_id); +int xc_viommu_destroy(xc_interface *xch, domid_t dom, uint32_t viommu_id); + #endif int xc_livepatch_upload(xc_interface *xch, diff --git a/tools/libxc/xc_viommu.c b/tools/libxc/xc_viommu.c new file mode 100644 index 0000000..04aae96 --- /dev/null +++ b/tools/libxc/xc_viommu.c @@ -0,0 +1,81 @@ +/* + * xc_viommu.c + * + * viommu related API functions. + * + * Copyright (C) 2017 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License, version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" + +int xc_viommu_query_cap(xc_interface *xch, domid_t dom, + uint64_t type, uint64_t *cap) +{ + int rc; + DECLARE_DOMCTL; + + domctl.cmd = XEN_DOMCTL_viommu_op; + domctl.domain = (domid_t)dom; + domctl.u.viommu_op.cmd = XEN_DOMCTL_query_viommu_caps; + domctl.u.viommu_op.u.query_caps.viommu_type = type; + + rc = do_domctl(xch, &domctl); + if ( !rc ) + *cap = domctl.u.viommu_op.u.query_caps.capabilities; + return rc; +} + +int xc_viommu_create(xc_interface *xch, domid_t dom, uint64_t type, + uint64_t base_addr, uint64_t length, uint64_t cap, + uint32_t *viommu_id) +{ + int rc; + DECLARE_DOMCTL; + + domctl.cmd = XEN_DOMCTL_viommu_op; + domctl.domain = (domid_t)dom; + domctl.u.viommu_op.cmd = XEN_DOMCTL_create_viommu; + domctl.u.viommu_op.u.create_viommu.viommu_type = type; + domctl.u.viommu_op.u.create_viommu.base_address = base_addr; + domctl.u.viommu_op.u.create_viommu.length = length; + domctl.u.viommu_op.u.create_viommu.capabilities = cap; + + rc = do_domctl(xch, &domctl); + if ( !rc ) + *viommu_id = domctl.u.viommu_op.u.create_viommu.viommu_id; + return rc; +} + +int xc_viommu_destroy(xc_interface *xch, domid_t dom, uint32_t viommu_id) +{ + DECLARE_DOMCTL; + + domctl.cmd = XEN_DOMCTL_viommu_op; + domctl.domain = (domid_t)dom; + domctl.u.viommu_op.cmd = XEN_DOMCTL_destroy_viommu; + domctl.u.viommu_op.u.destroy_viommu.viommu_id = viommu_id; + + return do_domctl(xch, &domctl); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */