From patchwork Fri Mar 17 11:27:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9630461 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 346AF60249 for ; Fri, 17 Mar 2017 11:37:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DC03284E9 for ; Fri, 17 Mar 2017 11:37:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 126FB2864B; Fri, 17 Mar 2017 11:37:51 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 436D22862B for ; Fri, 17 Mar 2017 11:37:50 +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 1coqAB-0003i5-57; Fri, 17 Mar 2017 11:35:19 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coqA9-0003gO-Hk for xen-devel@lists.xen.org; Fri, 17 Mar 2017 11:35:17 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id DC/DB-15112-4F9CBC85; Fri, 17 Mar 2017 11:35:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42I5YG4Sofvl5Ok Igw0/uC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozFBx6zF/QEVBx9sputgfGVYxcjFweLwC0m iT8XLjOBOEIC0xglLh+8wdrFyMkhIcArcWTZDCjbT+LUrWNsEEX9jBJvP71mA0mwCahLnFg8k RHEFhGQlrj2+TIjSBGzwEZGiR0rFoJ1CwukS6yfegqsgUVAVWLtJYgNvAIuEou/HAaKcwBtUJ CYM8kGJMwp4Cpxt+0BO4gtBFRyr+sKywRGvgWMDKsYNYpTi8pSi3QNTfSSijLTM0pyEzNzdA0 NzPRyU4uLE9NTcxKTivWS83M3MQJDhQEIdjBe3xhwiFGSg0lJlFdF8ESEEF9SfkplRmJxRnxR aU5q8SFGGQ4OJQneJZFAOcGi1PTUirTMHGDQwqQlOHiURHhLQdK8xQWJucWZ6RCpU4y6HIv+7 X7DJMSSl5+XKiXOew+kSACkKKM0D24ELIIuMcpKCfMyAh0lxFOQWpSbWYIq/4pRnINRSZj3Pc gUnsy8ErhNr4COYAI6IvHnEZAjShIRUlINjBuZDHaaWU240/Js+ts9t2ZdsVDITv3UpVjQdDq w50hBy90oieu/mbzNzq2/8H/Gwl3CGXKWZ+cEKT23nhSz5JvrJZanne9PL7xikFP4cMtDt/OV k/pnnA/9VR/IWlTdFly6ueOhRoL70xVscoaV1/cvesBadurInyOfZ8zXXeBUlzozRazckVWJp Tgj0VCLuag4EQDwGLdemwIAAA== X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1489750513!81993610!1 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46879 invoked from network); 17 Mar 2017 11:35:15 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Mar 2017 11:35:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489750515; x=1521286515; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=xke/rRyYLUkETIA01JJTOVbHNv4lyeRGRuQrIN8aNAE=; b=bF8TGBKtqQGx6/VyB+8fT+YJAyQuL4+mIdGj/bOckUs0vlXD0MJAKt4p WtSG03GzLgndSGLW3NiP1ZyG1z2WfA==; Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Mar 2017 04:35:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,176,1486454400"; d="scan'208";a="61627810" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.159.159]) by orsmga002.jf.intel.com with ESMTP; 17 Mar 2017 04:35:01 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Fri, 17 Mar 2017 19:27:01 +0800 Message-Id: <1489750043-17260-2-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1489750043-17260-1-git-send-email-tianyu.lan@intel.com> References: <1489750043-17260-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , kevin.tian@intel.com, sstabellini@kernel.org, andrew.cooper3@citrix.com, julien.grall@arm.com, jbeulich@suse.com, chao.gao@intel.com Subject: [Xen-devel] [RFC PATCH 1/23] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities 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 introduct an abstract layer for arch vIOMMU implementation to deal with requests from dom0. Arch vIOMMU code needs to provide callback to perform create, destroy and query capabilities operation. Signed-off-by: Lan Tianyu --- xen/common/Makefile | 1 + xen/common/domain.c | 3 ++ xen/common/viommu.c | 97 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/viommu.h | 30 ++++++++++++++ xen/include/asm-x86/viommu.h | 31 ++++++++++++++ xen/include/public/viommu.h | 38 +++++++++++++++++ xen/include/xen/sched.h | 2 + xen/include/xen/viommu.h | 62 ++++++++++++++++++++++++++++ 8 files changed, 264 insertions(+) create mode 100644 xen/common/viommu.c create mode 100644 xen/include/asm-arm/viommu.h create mode 100644 xen/include/asm-x86/viommu.h create mode 100644 xen/include/public/viommu.h create mode 100644 xen/include/xen/viommu.h diff --git a/xen/common/Makefile b/xen/common/Makefile index 0fed30b..b58de63 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -60,6 +60,7 @@ obj-y += vm_event.o obj-y += vmap.o obj-y += vsprintf.o obj-y += wait.o +obj-y += viommu.o obj-bin-y += warning.init.o obj-$(CONFIG_XENOPROF) += xenoprof.o obj-y += xmalloc_tlsf.o diff --git a/xen/common/domain.c b/xen/common/domain.c index 4492c9c..aafc740 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -398,6 +398,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags, spin_unlock(&domlist_update_lock); } + if ( (err = viommu_init_domain(d)) != 0) + goto fail; + return d; fail: diff --git a/xen/common/viommu.c b/xen/common/viommu.c new file mode 100644 index 0000000..4c1c788 --- /dev/null +++ b/xen/common/viommu.c @@ -0,0 +1,97 @@ +/* + * common/viommu.c + * + * Copyright (c) 2017 Intel Corporation + * Author: Lan Tianyu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + * + */ + +#include +#include + +int viommu_init_domain(struct domain *d) +{ + d->viommu.nr_viommu = 0; + d->viommu.ops = viommu_get_ops(); + + return 0; +} + +int viommu_create(struct domain *d, u64 base_address, u64 length, u64 caps) +{ + struct viommu_info *info = &d->viommu; + struct viommu *viommu; + int rc; + + if ( !info || !info->ops || !info->ops->create + || info->nr_viommu >= NR_VIOMMU_PER_DOMAIN ) + return -EINVAL; + + viommu = xzalloc(struct viommu); + if ( !viommu ) + return -EFAULT; + + viommu->base_address = base_address; + viommu->length = length; + viommu->caps = caps; + viommu->viommu_id = info->nr_viommu; + + info->viommu[info->nr_viommu] = viommu; + info->nr_viommu++; + + rc = info->ops->create(d, viommu); + if ( rc < 0 ) { + xfree(viommu); + return rc; + } + + return viommu->viommu_id; +} + +int viommu_destroy(struct domain *d, u32 viommu_id) +{ + struct viommu_info *info = &d->viommu; + + if ( !info || !info->ops || !info->ops->destroy) + return -EINVAL; + + if ( viommu_id > info->nr_viommu || !info->viommu[viommu_id] ) + return -EINVAL; + + if ( info->ops->destroy(info->viommu[viommu_id]) ) + return -EFAULT; + + info->viommu[viommu_id] = NULL; + return 0; +} + +u64 viommu_query_caps(struct domain *d) +{ + struct viommu_info *info = &d->viommu; + + if ( !info || !info->ops || !info->ops->query_caps) + return -EINVAL; + + return info->ops->query_caps(d); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * End: + */ diff --git a/xen/include/asm-arm/viommu.h b/xen/include/asm-arm/viommu.h new file mode 100644 index 0000000..ef6a60b --- /dev/null +++ b/xen/include/asm-arm/viommu.h @@ -0,0 +1,30 @@ +/* + * include/asm-arm/viommu.h + * + * Copyright (c) 2017 Intel Corporation + * Author: Lan Tianyu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + * + */ +#ifndef __ARCH_ARM_VIOMMU_H__ +#define __ARCH_ARM_VIOMMU_H__ + +#include + +static inline const struct viommu_ops *viommu_get_ops(void) +{ + return NULL; +} + +#endif /* __ARCH_ARM_VIOMMU_H__ */ diff --git a/xen/include/asm-x86/viommu.h b/xen/include/asm-x86/viommu.h new file mode 100644 index 0000000..efb435f --- /dev/null +++ b/xen/include/asm-x86/viommu.h @@ -0,0 +1,31 @@ +/* + * include/asm-arm/viommu.h + * + * Copyright (c) 2017 Intel Corporation. + * Author: Lan Tianyu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + * + */ +#ifndef __ARCH_X86_VIOMMU_H__ +#define __ARCH_X86_VIOMMU_H__ + +#include +#include + +static inline const struct viommu_ops *viommu_get_ops(void) +{ + return NULL; +} + +#endif /* __ARCH_X86_VIOMMU_H__ */ diff --git a/xen/include/public/viommu.h b/xen/include/public/viommu.h new file mode 100644 index 0000000..ca2419b --- /dev/null +++ b/xen/include/public/viommu.h @@ -0,0 +1,38 @@ +/* + * include/public/viommu.h + * + * Copyright (c) 2017 Intel Corporation + * Author: Lan Tianyu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + * + */ + +#ifndef __XEN_PUBLIC_VIOMMU_H__ +#define __XEN_PUBLIC_VIOMMU_H__ + +/* VIOMMU capabilities*/ +#define VIOMMU_CAP_IRQ_REMAPPING (1 << 0) + +#endif /* __XEN_PUBLIC_VIOMMU_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ + diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 0929c0b..a2e9cdc 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -481,6 +482,7 @@ struct domain /* vNUMA topology accesses are protected by rwlock. */ rwlock_t vnuma_rwlock; struct vnuma_info *vnuma; + struct viommu_info viommu; /* Common monitor options */ struct { diff --git a/xen/include/xen/viommu.h b/xen/include/xen/viommu.h new file mode 100644 index 0000000..a0abbdf --- /dev/null +++ b/xen/include/xen/viommu.h @@ -0,0 +1,62 @@ +/* + * include/xen/viommu.h + * + * Copyright (c) 2017, Intel Corporation + * Author: Lan Tianyu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + * + */ +#ifndef __XEN_VIOMMU_H__ +#define __XEN_VIOMMU_H__ + +#include + +#define NR_VIOMMU_PER_DOMAIN 1 + +struct viommu { + u64 base_address; + u64 length; + u64 caps; + u32 viommu_id; + void *priv; +}; + +struct viommu_ops { + u64 (*query_caps)(struct domain *d); + int (*create)(struct domain *d, struct viommu *viommu); + int (*destroy)(struct viommu *viommu); +}; + +struct viommu_info { + u32 nr_viommu; + struct viommu *viommu[NR_VIOMMU_PER_DOMAIN]; /* viommu array*/ + const struct viommu_ops *ops; /* viommu_ops */ +}; + +int viommu_init_domain(struct domain *d); +int viommu_create(struct domain *d, u64 base_address, u64 length, u64 caps); +int viommu_destroy(struct domain *d, u32 viommu_id); +u64 viommu_query_caps(struct domain *d); + +#endif /* __XEN_VIOMMU_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */