From patchwork Tue Mar 11 15:49:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 26032 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f198.google.com (mail-ig0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2FC7C20068 for ; Tue, 11 Mar 2014 15:51:26 +0000 (UTC) Received: by mail-ig0-f198.google.com with SMTP id uq10sf20590332igb.1 for ; Tue, 11 Mar 2014 08:51:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=IX1JjBujaE1RXvEtdxkxPFFx0QALtZBEXpDXLLi6+YE=; b=TNeP+swtuvym3TdPv+XD6WFEW5wrchsYwfs3D4u25yUJGtfiWoB/hOk1UWKEOmWPb9 W94LCFkyeoC6ATM2VSqI9LVolcl9kqydI4Ztc6l4KNDGAhVjoiE3/TvsuCzPI0g5Y2d0 QqjRuvcWsXBdg7LInPNolbuWNgz86FVO39iwPuChXRHUZfq7CiGKniKAYAh2WJEp1JdB dfYQDbgZmjEmDVo+aYQa9l82rAmJIZ0vrGZWf5JTqY/WB9JUC+qfoA2bBJeYtJhfM+KI inOdJxjMCtR5W36sTHeX+vBq9+inpulUQ4PVFRgucKwZOfVBf996D2u1jtjK1cTVGjZN y1ag== X-Gm-Message-State: ALoCoQnh7NGBxvwtxYGvj3QVyAs5QbHPjnYAD/1BbWb5GgzT4lo1s2PC/skUB3KYvdZYcCgCx+6F X-Received: by 10.182.34.169 with SMTP id a9mr3758533obj.49.1394553085642; Tue, 11 Mar 2014 08:51:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.22.7 with SMTP id 7ls2407965qgm.46.gmail; Tue, 11 Mar 2014 08:51:25 -0700 (PDT) X-Received: by 10.221.39.196 with SMTP id tn4mr120947vcb.51.1394553085499; Tue, 11 Mar 2014 08:51:25 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id y6si5879412veb.101.2014.03.11.08.51.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Mar 2014 08:51:25 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jx11so8883866veb.31 for ; Tue, 11 Mar 2014 08:51:25 -0700 (PDT) X-Received: by 10.52.240.207 with SMTP id wc15mr1180512vdc.14.1394553085378; Tue, 11 Mar 2014 08:51:25 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp215033vck; Tue, 11 Mar 2014 08:51:24 -0700 (PDT) X-Received: by 10.224.88.130 with SMTP id a2mr39106173qam.55.1394553084691; Tue, 11 Mar 2014 08:51:24 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id g52si8898783qge.33.2014.03.11.08.51.24 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 11 Mar 2014 08:51:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WNOwp-0006zc-3O; Tue, 11 Mar 2014 15:50:31 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WNOwo-0006yA-1p for xen-devel@lists.xenproject.org; Tue, 11 Mar 2014 15:50:30 +0000 Received: from [85.158.139.211:11901] by server-7.bemta-5.messagelabs.com id 93/F0-20531-5C03F135; Tue, 11 Mar 2014 15:50:29 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-10.tower-206.messagelabs.com!1394553028!427661!1 X-Originating-IP: [209.85.212.169] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27194 invoked from network); 11 Mar 2014 15:50:28 -0000 Received: from mail-wi0-f169.google.com (HELO mail-wi0-f169.google.com) (209.85.212.169) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 11 Mar 2014 15:50:28 -0000 Received: by mail-wi0-f169.google.com with SMTP id hm4so1003946wib.0 for ; Tue, 11 Mar 2014 08:50:28 -0700 (PDT) X-Received: by 10.180.106.167 with SMTP id gv7mr3768751wib.40.1394553028028; Tue, 11 Mar 2014 08:50:28 -0700 (PDT) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id bm8sm62454537wjc.12.2014.03.11.08.50.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Mar 2014 08:50:26 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 11 Mar 2014 15:49:55 +0000 Message-Id: <1394552999-14171-10-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1394552999-14171-1-git-send-email-julien.grall@linaro.org> References: <1394552999-14171-1-git-send-email-julien.grall@linaro.org> Cc: ian.campbell@citrix.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich , Xiantao Zhang Subject: [Xen-devel] [PATCH v3 09/13] xen/passthrough: Introduce IOMMU ARM architecture X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This patch contains the architecture to use IOMMUs on ARM. There is no IOMMU drivers on this patch. In this implementation, IOMMU page table will be shared with the P2M. The code will run through the device tree and will initialize every IOMMU. It's possible to have multiple IOMMUs on the same platform, but they must be handled with the same driver. For now, there is no support for using multiple iommu drivers at runtime. Each new IOMMU drivers should contain: static const char * const myiommu_dt_compat[] __initconst = { /* list of device compatible with the drivers. Will be matched with * the "compatible" property on the device tree */ NULL, }; DT_DEVICE_START(myiommu, "MY IOMMU", DEVICE_IOMMU) .compatible = myiommu_compatible, .init = myiommu_init, DT_DEVICE_END Signed-off-by: Julien Grall Cc: Xiantao Zhang Cc: Jan Beulich --- Changes in v3: - Call iommu_dt_domain_{init,destroy} function in arch code Changes in v2: - Fix typoes in commit message - Remove useless comment in arch/arm/setup.c - Update copyright date to 2014 - Move iommu_dom0_init earlier - Call iommu_assign_dt_device in map_device when the device is protected by an IOMMU --- xen/arch/arm/Rules.mk | 1 + xen/arch/arm/domain.c | 7 ++++ xen/arch/arm/domain_build.c | 19 +++++++-- xen/arch/arm/p2m.c | 4 ++ xen/arch/arm/setup.c | 2 + xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/arm/Makefile | 1 + xen/drivers/passthrough/arm/iommu.c | 70 ++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 3 +- xen/include/asm-arm/domain.h | 2 + xen/include/asm-arm/hvm/iommu.h | 10 +++++ xen/include/asm-arm/iommu.h | 36 +++++++++++++++++ 12 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 xen/drivers/passthrough/arm/Makefile create mode 100644 xen/drivers/passthrough/arm/iommu.c create mode 100644 xen/include/asm-arm/hvm/iommu.h create mode 100644 xen/include/asm-arm/iommu.h diff --git a/xen/arch/arm/Rules.mk b/xen/arch/arm/Rules.mk index 57f2eb1..1703551 100644 --- a/xen/arch/arm/Rules.mk +++ b/xen/arch/arm/Rules.mk @@ -9,6 +9,7 @@ HAS_DEVICE_TREE := y HAS_VIDEO := y HAS_ARM_HDLCD := y +HAS_PASSTHROUGH := y CFLAGS += -I$(BASEDIR)/include diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 8f20fdf..c42a1c6 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -550,6 +550,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags) if ( (d->domain_id == 0) && (rc = domain_vuart_init(d)) ) goto fail; + if ( (rc = iommu_domain_init(d)) != 0 ) + goto fail; + return 0; fail: @@ -561,6 +564,10 @@ fail: void arch_domain_destroy(struct domain *d) { + /* IOMMU page table is shared with P2M, always call + * iommu_domain_destroy() before p2m_teardown(). + */ + iommu_domain_destroy(d); p2m_teardown(d); domain_vgic_free(d); domain_vuart_free(d); diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 32861aa..229954b 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -669,7 +669,7 @@ static int make_timer_node(const struct domain *d, void *fdt, } /* Map the device in the domain */ -static int map_device(struct domain *d, const struct dt_device_node *dev) +static int map_device(struct domain *d, struct dt_device_node *dev) { unsigned int nirq; unsigned int naddr; @@ -684,6 +684,18 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) DPRINT("%s nirq = %d naddr = %u\n", dt_node_full_name(dev), nirq, naddr); + if ( dt_device_is_protected(dev) ) + { + DPRINT("%s setup iommu\n", dt_node_full_name(dev)); + res = iommu_assign_dt_device(d, dev); + if ( res ) + { + printk(XENLOG_ERR "Failed to setup the IOMMU for %s\n", + dt_node_full_name(dev)); + return res; + } + } + /* Map IRQs */ for ( i = 0; i < nirq; i++ ) { @@ -754,7 +766,7 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) } static int handle_node(struct domain *d, struct kernel_info *kinfo, - const struct dt_device_node *node) + struct dt_device_node *node) { static const struct dt_device_match skip_matches[] __initconst = { @@ -775,7 +787,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo, DT_MATCH_TIMER, { /* sentinel */ }, }; - const struct dt_device_node *child; + struct dt_device_node *child; int res; const char *name; const char *path; @@ -1008,6 +1020,7 @@ int construct_dom0(struct domain *d) kinfo.unassigned_mem = dom0_mem; allocate_memory(d, &kinfo); + iommu_dom0_init(d); rc = kernel_prepare(&kinfo); if ( rc < 0 ) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index d00c882..d8ed0de 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -412,12 +412,16 @@ static int apply_p2m_changes(struct domain *d, if ( flush ) { + unsigned long sgfn = paddr_to_pfn(start_gpaddr); + unsigned long egfn = paddr_to_pfn(end_gpaddr); + /* At the beginning of the function, Xen is updating VTTBR * with the domain where the mappings are created. In this * case it's only necessary to flush TLBs on every CPUs with * the current VMID (our domain). */ flush_tlb(); + iommu_iotlb_flush(d, sgfn, egfn - sgfn); } if ( op == ALLOCATE || op == INSERT ) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 1f6d713..a771c30 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -725,6 +725,8 @@ void __init start_xen(unsigned long boot_phys_offset, local_irq_enable(); local_abort_enable(); + iommu_setup(); + smp_prepare_cpus(cpus); initialize_keytable(); diff --git a/xen/drivers/passthrough/Makefile b/xen/drivers/passthrough/Makefile index 5a0a35e..16e9027 100644 --- a/xen/drivers/passthrough/Makefile +++ b/xen/drivers/passthrough/Makefile @@ -1,6 +1,7 @@ subdir-$(x86) += vtd subdir-$(x86) += amd subdir-$(x86_64) += x86 +subdir-$(arm) += arm obj-y += iommu.o obj-$(x86) += io.o diff --git a/xen/drivers/passthrough/arm/Makefile b/xen/drivers/passthrough/arm/Makefile new file mode 100644 index 0000000..0484b79 --- /dev/null +++ b/xen/drivers/passthrough/arm/Makefile @@ -0,0 +1 @@ +obj-y += iommu.o diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c new file mode 100644 index 0000000..b0bd71d --- /dev/null +++ b/xen/drivers/passthrough/arm/iommu.c @@ -0,0 +1,70 @@ +/* + * xen/drivers/passthrough/arm/iommu.c + * + * Generic IOMMU framework via the device tree + * + * Julien Grall + * Copyright (c) 2014 Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + */ + +#include +#include +#include +#include + +static const struct iommu_ops *iommu_ops; + +const struct iommu_ops *iommu_get_ops(void) +{ + return iommu_ops; +} + +void __init iommu_set_ops(const struct iommu_ops *ops) +{ + BUG_ON(ops == NULL); + + if ( iommu_ops && iommu_ops != ops ) + printk("WARNING: IOMMU ops already set to a different value\n"); + + iommu_ops = ops; +} + +int __init iommu_hardware_setup(void) +{ + struct dt_device_node *np; + int rc; + unsigned int num_iommus = 0; + + dt_for_each_device_node(dt_host, np) + { + rc = device_init(np, DEVICE_IOMMU, NULL); + if ( !rc ) + num_iommus++; + } + + return ( num_iommus > 0 ) ? 0 : -ENODEV; +} + +int arch_iommu_domain_init(struct domain *d) +{ + int ret; + + ret = iommu_dt_domain_init(d); + + return ret; +} + +void arch_iommu_domain_destroy(struct domain *d) +{ + iommu_dt_domain_destroy(d); +} diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 9e47ca6..ed04344 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -6,7 +6,8 @@ enum device_type { - DEVICE_SERIAL + DEVICE_SERIAL, + DEVICE_IOMMU, }; struct device_desc { diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index bc20a15..ad6587a 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -9,6 +9,7 @@ #include #include #include +#include /* Represents state corresponding to a block of 32 interrupts */ struct vgic_irq_rank { @@ -72,6 +73,7 @@ struct pending_irq struct hvm_domain { uint64_t params[HVM_NR_PARAMS]; + struct hvm_iommu hvm_iommu; } __cacheline_aligned; #ifdef CONFIG_ARM_64 diff --git a/xen/include/asm-arm/hvm/iommu.h b/xen/include/asm-arm/hvm/iommu.h new file mode 100644 index 0000000..461c8cf --- /dev/null +++ b/xen/include/asm-arm/hvm/iommu.h @@ -0,0 +1,10 @@ +#ifndef __ASM_ARM_HVM_IOMMU_H_ +#define __ASM_ARM_HVM_IOMMU_H_ + +struct arch_hvm_iommu +{ + /* Private information for the IOMMU drivers */ + void *priv; +}; + +#endif /* __ASM_ARM_HVM_IOMMU_H_ */ diff --git a/xen/include/asm-arm/iommu.h b/xen/include/asm-arm/iommu.h new file mode 100644 index 0000000..81eec83 --- /dev/null +++ b/xen/include/asm-arm/iommu.h @@ -0,0 +1,36 @@ +/* + * 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, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. +*/ +#ifndef __ARCH_ARM_IOMMU_H__ +#define __ARCH_ARM_IOMMU_H__ + +/* Always share P2M Table between the CPU and the IOMMU */ +#define iommu_use_hap_pt(d) (1) +#define domain_hvm_iommu(d) (&d->arch.hvm_domain.hvm_iommu) + +const struct iommu_ops *iommu_get_ops(void); +void __init iommu_set_ops(const struct iommu_ops *ops); + +int __init iommu_hardware_setup(void); + +#endif /* __ARCH_ARM_IOMMU_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */