From patchwork Fri Sep 22 03:01:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9965569 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 4F237600C5 for ; Fri, 22 Sep 2017 09:12:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4954829701 for ; Fri, 22 Sep 2017 09:12:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D87829806; Fri, 22 Sep 2017 09:12:02 +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 D0D7A2970F for ; Fri, 22 Sep 2017 09:12:01 +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 1dvJxt-0003Dh-U4; Fri, 22 Sep 2017 09:09:41 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvJxt-0003D8-1n for xen-devel@lists.xen.org; Fri, 22 Sep 2017 09:09:41 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id EF/24-03454-453D4C95; Fri, 22 Sep 2017 09:09:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42I5YG5SoRt8+Ui kwdwjphZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8atOV/ZCm6qVjyfto+tgfGGdBcjF4eQwDRG iXUT9jN3MXJySAjwShxZNoO1i5EdyPaXmMgIUdLBKLGs/z0jSAmbgLrEicUTwWwRAWmJa58vg xUxC6xgklj5eAlYQlggUGLV1DlgM1kEVCW6pr9kB7F5BVwk5v7YygaxS0FiysP3YDWcAq4Sv/ q2M4HYQkA1rUv3M01g5F3AyLCKUaM4tagstUjX0EIvqSgzPaMkNzEzR9fQwEwvN7W4ODE9NSc xqVgvOT93EyMwHBiAYAfjzY0BhxglOZiURHnfnz8SKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC t/0SUE6wKDU9tSItMwcYmDBpCQ4eJRFeNZA0b3FBYm5xZjpE6hSjJUfHzbt/mDg2gckN3x/8Y RJiycvPS5US59UDaRAAacgozYMbB4ueS4yyUsK8jEAHCvEUpBblZpagyr9iFOdgVBLm/XgRaA pPZl4J3NZXQAcxAR1UvhrsoJJEhJRUA6ON1tVLC2ce/Hi54qtHRxBb2OsDgj+29GT6XF4WfNz rTG2czdzcc8+Xf3b86XHs2KK7fClL1669zRg8R2DyhK78n5WBXMIpB9b+PqEneMdFlSd+rpVB xlLjY0+dP11I5U/tv5fY8dxyu8m6WsNE8WtPLmwQunDQ5sXFjamLG9IZsjWmnfjEamWqxFKck WioxVxUnAgAxMNBmpkCAAA= X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1506071377!94816750!1 X-Originating-IP: [192.55.52.120] X-SpamReason: No, hits=1.3 required=7.0 tests=BODY_RANDOM_LONG, DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37492 invoked from network); 22 Sep 2017 09:09:39 -0000 Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by server-10.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2017 09:09:39 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Sep 2017 02:09:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,427,1500966000"; d="scan'208";a="138241124" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.141]) by orsmga002.jf.intel.com with ESMTP; 22 Sep 2017 02:09:35 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 23:01:44 -0400 Message-Id: <1506049330-11196-4-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> References: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , kevin.tian@intel.com, sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com, roger.pau@citrix.com, chao.gao@intel.com Subject: [Xen-devel] [PATCH V3 3/29] DOMCTL: Introduce new DOMCTL commands for vIOMMU support 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 This patch is to introduce create, destroy and query capabilities command for vIOMMU. vIOMMU layer will deal with requests and call arch vIOMMU ops. Signed-off-by: Lan Tianyu --- xen/common/domctl.c | 6 ++++++ xen/common/viommu.c | 30 ++++++++++++++++++++++++++++++ xen/include/public/domctl.h | 42 ++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 2 ++ 4 files changed, 80 insertions(+) diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 42658e5..7e28237 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -1149,6 +1149,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) copyback = 1; break; +#ifdef CONFIG_VIOMMU + case XEN_DOMCTL_viommu_op: + ret = viommu_domctl(d, &op->u.viommu_op, ©back); + break; +#endif + default: ret = arch_do_domctl(op, d, u_domctl); break; diff --git a/xen/common/viommu.c b/xen/common/viommu.c index 64d91e6..55feb5d 100644 --- a/xen/common/viommu.c +++ b/xen/common/viommu.c @@ -133,6 +133,36 @@ static int viommu_create(struct domain *d, uint64_t type, return 0; } +int viommu_domctl(struct domain *d, struct xen_domctl_viommu_op *op, + bool *need_copy) +{ + int rc = -EINVAL; + + if ( !viommu_enabled() ) + return -ENODEV; + + switch ( op->cmd ) + { + case XEN_DOMCTL_create_viommu: + rc = viommu_create(d, op->u.create.viommu_type, + op->u.create.base_address, + op->u.create.capabilities, + &op->u.create.viommu_id); + if ( !rc ) + *need_copy = true; + break; + + case XEN_DOMCTL_destroy_viommu: + rc = viommu_destroy_domain(d); + break; + + default: + return -ENOSYS; + } + + return rc; +} + /* * Local variables: * mode: C diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 50ff58f..68854b6 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1163,6 +1163,46 @@ struct xen_domctl_psr_cat_op { typedef struct xen_domctl_psr_cat_op xen_domctl_psr_cat_op_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cat_op_t); +/* vIOMMU helper + * + * vIOMMU interface can be used to create/destroy vIOMMU and + * query vIOMMU capabilities. + */ + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD 0 + +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address. + */ + uint64_t base_address; + /* IN - Capabilities with which we want to create */ + uint64_t capabilities; + /* OUT - vIOMMU identity */ + uint32_t viommu_id; + } create; + + struct { + /* IN - vIOMMU identity */ + uint32_t viommu_id; + } destroy; + } u; +}; +typedef struct xen_domctl_viommu_op xen_domctl_viommu_op; +DEFINE_XEN_GUEST_HANDLE(xen_domctl_viommu_op); + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1240,6 +1280,7 @@ struct xen_domctl { #define XEN_DOMCTL_monitor_op 77 #define XEN_DOMCTL_psr_cat_op 78 #define XEN_DOMCTL_soft_reset 79 +#define XEN_DOMCTL_viommu_op 80 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1302,6 +1343,7 @@ struct xen_domctl { struct xen_domctl_psr_cmt_op psr_cmt_op; struct xen_domctl_monitor_op monitor_op; struct xen_domctl_psr_cat_op psr_cat_op; + struct xen_domctl_viommu_op viommu_op; uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/viommu.h b/xen/include/xen/viommu.h index 636a2a3..baa8ab7 100644 --- a/xen/include/xen/viommu.h +++ b/xen/include/xen/viommu.h @@ -43,6 +43,8 @@ static inline bool viommu_enabled(void) int viommu_register_type(uint64_t type, struct viommu_ops *ops); int viommu_destroy_domain(struct domain *d); +int viommu_domctl(struct domain *d, struct xen_domctl_viommu_op *op, + bool_t *need_copy); #else static inline int viommu_register_type(uint64_t type, struct viommu_ops *ops) {