From patchwork Thu May 18 05:34:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9733893 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 BE8EE601BC for ; Thu, 18 May 2017 11:42:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC137287AE for ; Thu, 18 May 2017 11:42:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F0FF269DA; Thu, 18 May 2017 11:42:52 +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 0330920952 for ; Thu, 18 May 2017 11:42:52 +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 1dBJnF-0004Q5-8F; Thu, 18 May 2017 11:40:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBJnE-0004OY-2t for xen-devel@lists.xen.org; Thu, 18 May 2017 11:40:32 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id F7/7A-02006-F288D195; Thu, 18 May 2017 11:40:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsXS1tbhqKvRIRt p0HhR1mLJx8UsDoweR3f/ZgpgjGLNzEvKr0hgzZg7+TlLwQPlinVvDBsYt8t2MXJxCAlMZ5SY /vIaexcjJ4eEAK/EkWUzWCHsAInzUzcxQxR1MEq07lkIVsQmoC5xYvFERhBbREBa4trny2A2s 8A+Rok3z1VBbGEBD4mrG2cxg9gsAqoSzde/sHQxcnDwCrhInH4rDDFfQWLKw/dgJZwCrhLbtt 5iAbGFgEoaF/ayTmDkXcDIsIpRozi1qCy1SNfIVC+pKDM9oyQ3MTNH19DAVC83tbg4MT01JzG pWC85P3cTIzAY6hkYGHcw7mr3O8QoycGkJMp7uEA2UogvKT+lMiOxOCO+qDQntfgQowwHh5IE 74Y2oJxgUWp6akVaZg4wLGHSEhw8SiK8Ou1Aad7igsTc4sx0iNQpRl2OK60f3zMJseTl56VKi fNuBJkhAFKUUZoHNwIWI5cYZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCfOygqziycwrgdv0Cu gIJqAjmh9IgxxRkoiQkmpgLNRf1PBJ/rZc/+SL5r+v5YtZ/2X5s7UqaaH9c2+VequsVH+n9o0 Bx13suKulck5UPmvbJP8yWutngZkoW+Aiwd+fDy1NFn4VusTNa7uSlqLaF83QexPjzgYalTxd xZS+Sfx55MG/7z5NMpxSouUuKL3h39Q4Rb89oo/nuv9Ofm7171azxY09SizFGYmGWsxFxYkAG hcsgIwCAAA= X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1495107621!83088355!1 X-Originating-IP: [134.134.136.65] X-SpamReason: No, hits=0.8 required=7.0 tests=DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6185 invoked from network); 18 May 2017 11:40:24 -0000 Received: from mga03.intel.com (HELO mga03.intel.com) (134.134.136.65) by server-16.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 18 May 2017 11:40:24 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 May 2017 04:40:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.38,358,1491289200"; d="scan'208"; a="1149659954" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.124]) by fmsmga001.fm.intel.com with ESMTP; 18 May 2017 04:40:19 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 18 May 2017 01:34:36 -0400 Message-Id: <1495085696-10819-7-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1495085696-10819-1-git-send-email-tianyu.lan@intel.com> References: <1495085696-10819-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] [RFC PATCH V2 6/26] 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 | 7 ++++ tools/libxc/xc_viommu.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 tools/libxc/xc_viommu.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 8ae552f..c982571 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -42,6 +42,7 @@ CTRL_SRCS-y += xc_kexec.c CTRL_SRCS-y += xc_resource.c CTRL_SRCS-$(CONFIG_X86) += xc_psr.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c +CTRL_SRCS-$(CONFIG_X86) += xc_viommu.c CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 1629f41..6c8110c 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2491,6 +2491,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: + */