From patchwork Thu Jun 29 05:50:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9816543 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 66CE1603D7 for ; Thu, 29 Jun 2017 12:00:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E8EA2851A for ; Thu, 29 Jun 2017 12:00:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23702286E1; Thu, 29 Jun 2017 12:00:16 +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.2 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM 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 9BA5E2851A for ; Thu, 29 Jun 2017 12:00:15 +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 1dQY5A-00063K-GA; Thu, 29 Jun 2017 11:58:00 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQY59-00062F-8k for xen-devel@lists.xen.org; Thu, 29 Jun 2017 11:57:59 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 2E/F8-03582-64BE4595; Thu, 29 Jun 2017 11:57:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVywNykWNftdUi kwbynPBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8ap7mamgk0qFVvPPWBpYHwn28XIxSEkMJ1R 4k/LMtYuRk4OCQFeiSPLZkDZARKHjj4Gs4UE2hklPjyJB7HZBNQlTiyeyAhiiwhIS1z7fBnMZ hbYxyjx5rkqiC0s4ChxdeYN9i5GDg4WAVWJ4311IGFeAReJpUd6mSDGK0hMefieGcTmFHCVaL i5hQ1ilYvEp56dzBMYeRcwMqxi1ChOLSpLLdI1tNBLKspMzyjJTczM0TU0MNPLTS0uTkxPzUl MKtZLzs/dxAgMBgYg2MF4c2PAIUZJDiYlUV7D5yGRQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4 T78EygkWpaanVqRl5gDDEiYtwcGjJMLbB9LKW1yQmFucmQ6ROsWoy7GgZ8MXJiGWvPy8VClxX q5XQEUCIEUZpXlwI2AxcolRVkqYlxHoKCGegtSi3MwSVPlXjOIcjErCvE9BLuHJzCuB2/QK6A gmoCOEZ4AdUZKIkJJqYGTtalmSytXyqS8pcsLDAN5sqQbX58miq+MVPasU9LbJnJZcq3Mwxcl hWkh68x3eO25CfvopXz/sbXS41M33u3X337Oqb2Pc6zk3csYoVTayGbc821GcaHj2peg9ri51 /cV7/v/1faQuol3ItXybycOyhpiykg/Me565cPlYH1G9u++dmxyvEktxRqKhFnNRcSIA18mS7 YwCAAA= X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1498737473!47847778!2 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.8 required=7.0 tests=DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57282 invoked from network); 29 Jun 2017 11:57:57 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-6.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 29 Jun 2017 11:57:57 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jun 2017 04:57:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,280,1496127600"; d="scan'208"; a="1166110924" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.74]) by fmsmga001.fm.intel.com with ESMTP; 29 Jun 2017 04:57:55 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 29 Jun 2017 01:50:38 -0400 Message-Id: <1498715457-16565-7-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1498715457-16565-1-git-send-email-tianyu.lan@intel.com> References: <1498715457-16565-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, jbeulich@suse.com, Chao Gao Subject: [Xen-devel] [PATCH 6/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 is to add XEN_DOMCTL_viommu_op hypercall. This hypercall comprise three sub-command: - query capabilities of one specific type vIOMMU emulated by Xen - create vIOMMU in Xen hypervisor with viommu type, register range, capability - 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..b8f4742 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 1629f41..51ceeb9 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 @@ -2491,6 +2492,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, uint32_t dom, + uint64_t type, uint64_t *cap); +int xc_viommu_create(xc_interface *xch, uint32_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, uint32_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..54ed877 --- /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, uint32_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.caps; + return rc; +} + +int xc_viommu_create(xc_interface *xch, uint32_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, uint32_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: + */