From patchwork Thu May 18 05:34:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9733875 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 C1D94601BC for ; Thu, 18 May 2017 11:42:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE4CF20952 for ; Thu, 18 May 2017 11:42:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2F0E2621D; Thu, 18 May 2017 11:42:42 +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 3265720952 for ; Thu, 18 May 2017 11:42:42 +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 1dBJmv-00049R-Hy; Thu, 18 May 2017 11:40:13 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBJmu-00048i-DM for xen-devel@lists.xen.org; Thu, 18 May 2017 11:40:12 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id 5A/E7-26106-B188D195; Thu, 18 May 2017 11:40:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsXS1taRoivVIRt p8HCWhcWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmrH+bmLBb52K7S8+sjQw3lDoYmTnEBKokFgo 3MXIySEhwCtxZNkMVgjbX+LEhz1sXYxcQBUdjBKTH81hA0mwCahLnFg8kRHEFhGQlrj2+TIjS BGzwGZGiVnfVrCDJIQFQiUuv/8P1sAioCrRfHg+WAOvgIvEioZbUBsUJKY8fM8MYnMKuEps23 qLBcQWAqppXNjLOoGRdwEjwypGjeLUorLUIl1DE72kosz0jJLcxMwcXUMDY73c1OLixPTUnMS kYr3k/NxNjMBQYACCHYwrtnseYpTkYFIS5T1cIBspxJeUn1KZkVicEV9UmpNafIhRhoNDSYKX rx0oJ1iUmp5akZaZAwxKmLQEB4+SCG8KSJq3uCAxtzgzHSJ1ilFRSpzXCyQhAJLIKM2Da4NFw iVGWSlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ81aBTOHJzCuBm/4KaDET0OLmB9Igi0sSEVJSDY xVnjduVOcnOjZ+ard6nsK4UdblkaJZmkfqL88/jq1hSrFPJKZej779WlzUQU+w70jfEnnDqvo LaV8WL9pj4vjcYrli3MJTFjYHApJeHz0eFy7MF7RNq87Hu1FSdWfBZKXHjxk+KrJ41/XGGDuK RpipuN2qPtsV/fON88pPCpf2zrNNvDNxkxJLcUaioRZzUXEiAIrN1pt/AgAA X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1495107608!89448371!1 X-Originating-IP: [134.134.136.100] 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 8601 invoked from network); 18 May 2017 11:40:10 -0000 Received: from mga07.intel.com (HELO mga07.intel.com) (134.134.136.100) by server-2.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 18 May 2017 11:40:10 -0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP; 18 May 2017 04:40:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,358,1491289200"; d="scan'208";a="102428860" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.124]) by orsmga005.jf.intel.com with ESMTP; 18 May 2017 04:40:06 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 18 May 2017 01:34:32 -0400 Message-Id: <1495085696-10819-3-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@intel.com Subject: [Xen-devel] [RFC PATCH V2 2/26] 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 | 3 +++ xen/common/viommu.c | 35 +++++++++++++++++++++++++++++++++++ xen/include/public/domctl.h | 40 ++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 8 +++++++- 4 files changed, 85 insertions(+), 1 deletion(-) diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 951a5dc..a178544 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -1141,6 +1141,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) if ( !ret ) copyback = 1; break; + case XEN_DOMCTL_viommu_op: + ret = viommu_domctl(d, &op->u.viommu_op, ©back); + break; default: ret = arch_do_domctl(op, d, u_domctl); diff --git a/xen/common/viommu.c b/xen/common/viommu.c index eadcecb..74afbf5 100644 --- a/xen/common/viommu.c +++ b/xen/common/viommu.c @@ -30,6 +30,41 @@ struct viommu_type { struct list_head node; }; +int viommu_domctl(struct domain *d, struct xen_domctl_viommu_op *op, + bool_t *need_copy) +{ + int rc = -EINVAL; + + switch ( op->cmd ) + { + case XEN_DOMCTL_create_viommu: + rc = viommu_create(d, op->u.create_viommu.viommu_type, + op->u.create_viommu.base_address, + op->u.create_viommu.length, + op->u.create_viommu.capabilities); + if (rc >= 0) { + op->u.create_viommu.viommu_id = rc; + *need_copy = true; + } + break; + + case XEN_DOMCTL_destroy_viommu: + rc = viommu_destroy(d, op->u.destroy_viommu.viommu_id); + break; + + case XEN_DOMCTL_query_viommu_caps: + op->u.query_caps.caps + = viommu_query_caps(d, op->u.query_caps.viommu_type); + *need_copy = true; + break; + + default: + break; + } + + return rc; +} + int viommu_init_domain(struct domain *d) { d->viommu.nr_viommu = 0; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index e6cf211..d499fc6 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1141,6 +1141,44 @@ 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); +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + 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 and length. + */ + uint64_t base_address; + /* IN - Length of MMIO region */ + uint64_t length; + /* IN - Capabilities with which we want to create */ + uint64_t capabilities; + /* OUT - vIOMMU identity */ + uint32_t viommu_id; + } create_viommu; + + struct { + /* IN - vIOMMU identity */ + uint32_t viommu_id; + } destroy_viommu; + + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* OUT - vIOMMU Capabilities */ + uint64_t caps; + } query_caps; + } 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 @@ -1218,6 +1256,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 @@ -1280,6 +1319,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 ae5f6af..5909800 100644 --- a/xen/include/xen/viommu.h +++ b/xen/include/xen/viommu.h @@ -52,6 +52,8 @@ int viommu_destroy(struct domain *d, u32 viommu_id); int viommu_register_type(u64 type, struct viommu_ops * ops); void viommu_unregister_type(u64 type); u64 viommu_query_caps(struct domain *d, u64 viommu_type); +int viommu_domctl(struct domain *d, struct xen_domctl_viommu_op *op, + bool_t *need_copy); int viommu_setup(void); #else static inline int viommu_init_domain(struct domain *d) { return 0 }; @@ -62,8 +64,12 @@ static inline int viommu_register_type(u64 type, struct viommu_ops * ops) { return 0; }; static inline void viommu_unregister_type(u64 type) { }; static inline u64 viommu_query_caps(struct domain *d, u64 viommu_type) - { return -ENODEV }; +{ return -ENODEV }; static inline int __init viommu_setup(void) { return 0 }; +static inline int viommu_domctl(struct domain *d, + struct xen_domctl_viommu_op *op, + bool_t *need_copy) +{ return -ENODEV }; #endif #endif /* __XEN_VIOMMU_H__ */